mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Refactor check mark code from reconcile list so it can be used elsewhere.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@3651 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
4d81a44a14
commit
a26a55428a
@ -37,7 +37,7 @@
|
||||
|
||||
|
||||
/* This static indicates the debugging module that this .o belongs to. */
|
||||
/* static short module = MOD_GUI; */
|
||||
static short module = MOD_GUI;
|
||||
|
||||
|
||||
/********************************************************************\
|
||||
@ -434,3 +434,176 @@ gnc_window_adjust_for_screen(GtkWindow * window)
|
||||
gdk_window_resize(GTK_WIDGET(window)->window, width, height);
|
||||
gtk_widget_queue_resize(GTK_WIDGET(window));
|
||||
}
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GdkPixmap *on_pixmap;
|
||||
GdkPixmap *off_pixmap;
|
||||
GdkBitmap *mask;
|
||||
|
||||
GNCUpdateCheck update_cb;
|
||||
gpointer user_data;
|
||||
} GNCCListCheckInfo;
|
||||
|
||||
static void
|
||||
check_realize (GtkWidget *widget, gpointer user_data)
|
||||
{
|
||||
GNCCListCheckInfo *check_info = user_data;
|
||||
GdkGCValues gc_values;
|
||||
GtkCList *clist;
|
||||
gint font_height;
|
||||
gint check_size;
|
||||
GdkColormap *cm;
|
||||
GtkStyle *style;
|
||||
GdkGC *gc;
|
||||
gint i;
|
||||
|
||||
if (check_info->mask)
|
||||
return;
|
||||
|
||||
style = gtk_widget_get_style (widget);
|
||||
|
||||
font_height = style->font->ascent + style->font->descent;
|
||||
check_size = (font_height > 0) ? font_height - 3 : 9;
|
||||
|
||||
check_info->mask = gdk_pixmap_new (NULL, check_size, check_size, 1);
|
||||
|
||||
check_info->on_pixmap = gdk_pixmap_new (widget->window,
|
||||
check_size, check_size, -1);
|
||||
|
||||
check_info->off_pixmap = gdk_pixmap_new (widget->window,
|
||||
check_size, check_size, -1);
|
||||
|
||||
gc_values.foreground = style->white;
|
||||
gc = gtk_gc_get (1, gtk_widget_get_colormap (widget),
|
||||
&gc_values, GDK_GC_FOREGROUND);
|
||||
|
||||
gdk_draw_rectangle (check_info->mask, gc, TRUE,
|
||||
0, 0, check_size, check_size);
|
||||
|
||||
gtk_gc_release (gc);
|
||||
|
||||
gc = style->base_gc[GTK_STATE_NORMAL];
|
||||
|
||||
gdk_draw_rectangle (check_info->on_pixmap, gc, TRUE,
|
||||
0, 0, check_size, check_size);
|
||||
gdk_draw_rectangle (check_info->off_pixmap, gc, TRUE,
|
||||
0, 0, check_size, check_size);
|
||||
|
||||
cm = gtk_widget_get_colormap (widget);
|
||||
|
||||
gc_values.foreground.red = 0;
|
||||
gc_values.foreground.green = 65535 / 2;
|
||||
gc_values.foreground.blue = 0;
|
||||
|
||||
gdk_colormap_alloc_color (cm, &gc_values.foreground, FALSE, TRUE);
|
||||
|
||||
gc = gdk_gc_new_with_values (widget->window, &gc_values, GDK_GC_FOREGROUND);
|
||||
|
||||
gdk_draw_line (check_info->on_pixmap, gc,
|
||||
1, check_size / 2,
|
||||
check_size / 3, check_size - 5);
|
||||
gdk_draw_line (check_info->on_pixmap, gc,
|
||||
1, check_size / 2 + 1,
|
||||
check_size / 3, check_size - 4);
|
||||
|
||||
gdk_draw_line (check_info->on_pixmap, gc,
|
||||
check_size / 3, check_size - 5,
|
||||
check_size - 3, 2);
|
||||
gdk_draw_line (check_info->on_pixmap, gc,
|
||||
check_size / 3, check_size - 4,
|
||||
check_size - 3, 1);
|
||||
|
||||
gdk_gc_unref (gc);
|
||||
|
||||
clist = GTK_CLIST (widget);
|
||||
|
||||
for (i = 0; i < clist->rows; i++)
|
||||
check_info->update_cb (clist, i);
|
||||
}
|
||||
|
||||
static void
|
||||
check_unrealize (GtkWidget *widget, gpointer user_data)
|
||||
{
|
||||
GNCCListCheckInfo *check_info = user_data;
|
||||
|
||||
if (check_info->mask)
|
||||
gdk_bitmap_unref (check_info->mask);
|
||||
|
||||
if (check_info->on_pixmap)
|
||||
gdk_pixmap_unref (check_info->on_pixmap);
|
||||
|
||||
if (check_info->off_pixmap)
|
||||
gdk_pixmap_unref (check_info->off_pixmap);
|
||||
|
||||
check_info->mask = NULL;
|
||||
check_info->on_pixmap = NULL;
|
||||
check_info->off_pixmap = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
check_destroy (GtkWidget *widget, gpointer user_data)
|
||||
{
|
||||
GNCCListCheckInfo *check_info = user_data;
|
||||
|
||||
g_free (check_info);
|
||||
}
|
||||
|
||||
void
|
||||
gnc_clist_add_check (GtkCList *list, GNCUpdateCheck update_cb,
|
||||
gpointer user_data)
|
||||
{
|
||||
GNCCListCheckInfo *check_info;
|
||||
GtkObject *object;
|
||||
|
||||
g_return_if_fail (GTK_IS_CLIST (list));
|
||||
g_return_if_fail (update_cb != NULL);
|
||||
|
||||
object = GTK_OBJECT (list);
|
||||
|
||||
check_info = gtk_object_get_data (object, "gnc-check-info");
|
||||
if (check_info)
|
||||
{
|
||||
PWARN ("clist already has check");
|
||||
return;
|
||||
}
|
||||
|
||||
check_info = g_new0 (GNCCListCheckInfo, 1);
|
||||
|
||||
check_info->update_cb = update_cb;
|
||||
check_info->user_data = user_data;
|
||||
|
||||
gtk_object_set_data (object, "gnc-check_info", check_info);
|
||||
|
||||
gtk_signal_connect (object, "realize",
|
||||
GTK_SIGNAL_FUNC (check_realize), check_info);
|
||||
gtk_signal_connect (object, "unrealize",
|
||||
GTK_SIGNAL_FUNC (check_unrealize), check_info);
|
||||
gtk_signal_connect (object, "destroy",
|
||||
GTK_SIGNAL_FUNC (check_destroy), check_info);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
gnc_clist_set_check (GtkCList *list, int row, int col, gboolean checked)
|
||||
{
|
||||
GNCCListCheckInfo *check_info;
|
||||
GdkPixmap *pixmap;
|
||||
|
||||
g_return_if_fail (GTK_IS_CLIST (list));
|
||||
|
||||
if (!GTK_WIDGET_REALIZED (GTK_WIDGET (list)))
|
||||
return;
|
||||
|
||||
check_info = gtk_object_get_data (GTK_OBJECT (list), "gnc-check_info");
|
||||
if (!check_info)
|
||||
{
|
||||
PWARN ("you need to call gnc_clist_add_check first");
|
||||
return;
|
||||
}
|
||||
|
||||
pixmap = checked ? check_info->on_pixmap : check_info->off_pixmap;
|
||||
|
||||
gtk_clist_set_pixmap (list, row, 4, pixmap, check_info->mask);
|
||||
}
|
||||
|
@ -66,4 +66,12 @@ int gnc_option_menu_get_active (GtkWidget * option_menu);
|
||||
|
||||
void gnc_window_adjust_for_screen (GtkWindow * window);
|
||||
|
||||
|
||||
/*** Using checks with clists ************************************/
|
||||
typedef void (*GNCUpdateCheck) (GtkCList *list, int row);
|
||||
|
||||
void gnc_clist_add_check (GtkCList *list, GNCUpdateCheck update_cb,
|
||||
gpointer user_data);
|
||||
void gnc_clist_set_check (GtkCList *list, int row, int col, gboolean checked);
|
||||
|
||||
#endif
|
||||
|
@ -124,12 +124,24 @@ gnc_reconcile_list_new(Account *account, GNCReconcileListType type)
|
||||
return GTK_WIDGET(list);
|
||||
}
|
||||
|
||||
static void
|
||||
update_toggle (GtkCList *list, gint row)
|
||||
{
|
||||
GNCReconcileList *rlist = GNC_RECONCILE_LIST (list);
|
||||
gboolean reconciled;
|
||||
Split *split;
|
||||
|
||||
split = gtk_clist_get_row_data (list, row);
|
||||
reconciled = g_hash_table_lookup (rlist->reconciled, split) != NULL;
|
||||
|
||||
gnc_clist_set_check (list, row, 4, reconciled);
|
||||
}
|
||||
|
||||
static void
|
||||
gnc_reconcile_list_init (GNCReconcileList *list)
|
||||
{
|
||||
GtkCList *clist = GTK_CLIST (list);
|
||||
GtkStyle *style;
|
||||
gint font_height;
|
||||
gchar * titles[] =
|
||||
{
|
||||
_("Date"),
|
||||
@ -172,133 +184,16 @@ gnc_reconcile_list_init (GNCReconcileList *list)
|
||||
for (i = 0; i < list->num_columns; i++)
|
||||
{
|
||||
width = gdk_string_width (font, titles[i]);
|
||||
gtk_clist_set_column_min_width (GTK_CLIST(list), i, width + 5);
|
||||
gtk_clist_set_column_min_width (clist, i, width + 5);
|
||||
if (i == 4)
|
||||
gtk_clist_set_column_max_width (GTK_CLIST(list), i, width + 5);
|
||||
gtk_clist_set_column_max_width (clist, i, width + 5);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
font_height = font->ascent + font->descent;
|
||||
}
|
||||
else
|
||||
font_height = 0;
|
||||
}
|
||||
|
||||
list->check_size = (font_height > 0) ? font_height - 3 : 9;
|
||||
|
||||
list->mask = NULL;
|
||||
list->off_pixmap = NULL;
|
||||
list->on_pixmap = NULL;
|
||||
gnc_clist_add_check (clist, update_toggle, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
set_toggle (GNCReconcileList *list, gint row)
|
||||
{
|
||||
gboolean reconciled;
|
||||
GdkPixmap *pixmap;
|
||||
Split *split;
|
||||
|
||||
if (!GTK_WIDGET_REALIZED (GTK_WIDGET (list)))
|
||||
return;
|
||||
|
||||
split = gtk_clist_get_row_data (GTK_CLIST (list), row);
|
||||
reconciled = g_hash_table_lookup (list->reconciled, split) != NULL;
|
||||
|
||||
pixmap = reconciled ? list->on_pixmap : list->off_pixmap;
|
||||
|
||||
gtk_clist_set_pixmap (GTK_CLIST (list), row, 4, pixmap, list->mask);
|
||||
}
|
||||
|
||||
static void
|
||||
widget_realize (GtkWidget *widget)
|
||||
{
|
||||
GNCReconcileList *list = GNC_RECONCILE_LIST (widget);
|
||||
GdkGCValues gc_values;
|
||||
GdkColormap *cm;
|
||||
GtkStyle *style;
|
||||
GdkGC *gc;
|
||||
gint i;
|
||||
|
||||
if (GTK_WIDGET_CLASS (parent_class)->realize)
|
||||
(GTK_WIDGET_CLASS (parent_class)->realize) (widget);
|
||||
|
||||
if (list->mask)
|
||||
return;
|
||||
|
||||
style = gtk_widget_get_style (widget);
|
||||
|
||||
list->mask = gdk_pixmap_new (NULL, list->check_size, list->check_size, 1);
|
||||
list->on_pixmap = gdk_pixmap_new (widget->window,
|
||||
list->check_size, list->check_size, -1);
|
||||
list->off_pixmap = gdk_pixmap_new (widget->window,
|
||||
list->check_size, list->check_size, -1);
|
||||
|
||||
gc_values.foreground = style->white;
|
||||
gc = gtk_gc_get (1, gtk_widget_get_colormap (widget),
|
||||
&gc_values, GDK_GC_FOREGROUND);
|
||||
|
||||
gdk_draw_rectangle (list->mask, gc, TRUE, 0, 0,
|
||||
list->check_size, list->check_size);
|
||||
|
||||
gtk_gc_release (gc);
|
||||
|
||||
gc = style->base_gc[GTK_STATE_NORMAL];
|
||||
|
||||
gdk_draw_rectangle (list->on_pixmap, gc, TRUE, 0, 0,
|
||||
list->check_size, list->check_size);
|
||||
gdk_draw_rectangle (list->off_pixmap, gc, TRUE, 0, 0,
|
||||
list->check_size, list->check_size);
|
||||
|
||||
cm = gtk_widget_get_colormap (widget);
|
||||
|
||||
gc_values.foreground.red = 0;
|
||||
gc_values.foreground.green = 65535 / 2;
|
||||
gc_values.foreground.blue = 0;
|
||||
|
||||
gdk_colormap_alloc_color (cm, &gc_values.foreground, FALSE, TRUE);
|
||||
|
||||
gc = gdk_gc_new_with_values (widget->window, &gc_values, GDK_GC_FOREGROUND);
|
||||
|
||||
gdk_draw_line (list->on_pixmap, gc,
|
||||
1, list->check_size / 2,
|
||||
list->check_size / 3, list->check_size - 5);
|
||||
gdk_draw_line (list->on_pixmap, gc,
|
||||
1, list->check_size / 2 + 1,
|
||||
list->check_size / 3, list->check_size - 4);
|
||||
|
||||
gdk_draw_line (list->on_pixmap, gc,
|
||||
list->check_size / 3, list->check_size - 5,
|
||||
list->check_size - 3, 2);
|
||||
gdk_draw_line (list->on_pixmap, gc,
|
||||
list->check_size / 3, list->check_size - 4,
|
||||
list->check_size - 3, 1);
|
||||
|
||||
gdk_gc_unref (gc);
|
||||
|
||||
for (i = 0; i < GTK_CLIST (list)->rows; i++)
|
||||
set_toggle (list, i);
|
||||
}
|
||||
|
||||
static void
|
||||
widget_unrealize (GtkWidget *widget)
|
||||
{
|
||||
GNCReconcileList *list = GNC_RECONCILE_LIST (widget);
|
||||
|
||||
if (list->mask)
|
||||
gdk_bitmap_unref (list->mask);
|
||||
|
||||
if (list->on_pixmap)
|
||||
gdk_pixmap_unref (list->on_pixmap);
|
||||
|
||||
if (list->off_pixmap)
|
||||
gdk_pixmap_unref (list->off_pixmap);
|
||||
|
||||
list->mask = NULL;
|
||||
list->on_pixmap = NULL;
|
||||
list->off_pixmap = NULL;
|
||||
|
||||
if (GTK_WIDGET_CLASS (parent_class)->unrealize)
|
||||
(GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
|
||||
}
|
||||
|
||||
static void
|
||||
gnc_reconcile_list_class_init (GNCReconcileListClass *klass)
|
||||
@ -341,9 +236,6 @@ gnc_reconcile_list_class_init (GNCReconcileListClass *klass)
|
||||
|
||||
object_class->destroy = gnc_reconcile_list_destroy;
|
||||
|
||||
widget_class->realize = widget_realize;
|
||||
widget_class->unrealize = widget_unrealize;
|
||||
|
||||
clist_class->select_row = gnc_reconcile_list_select_row;
|
||||
clist_class->unselect_row = gnc_reconcile_list_unselect_row;
|
||||
|
||||
@ -374,7 +266,7 @@ gnc_reconcile_list_toggle (GNCReconcileList *list)
|
||||
else
|
||||
g_hash_table_remove (list->reconciled, split);
|
||||
|
||||
set_toggle (list, row);
|
||||
update_toggle (GTK_CLIST (list), row);
|
||||
|
||||
gtk_signal_emit (GTK_OBJECT (list),
|
||||
reconcile_list_signals[TOGGLE_RECONCILED], split);
|
||||
@ -794,7 +686,7 @@ gnc_reconcile_list_fill(GNCReconcileList *list)
|
||||
row = gtk_clist_append (GTK_CLIST(list), (gchar **) strings);
|
||||
gtk_clist_set_row_data (GTK_CLIST(list), row, split);
|
||||
|
||||
set_toggle (list, row);
|
||||
update_toggle (GTK_CLIST (list), row);
|
||||
|
||||
list->num_splits++;
|
||||
}
|
||||
|
@ -67,12 +67,6 @@ struct _GNCReconcileList
|
||||
|
||||
Account *account;
|
||||
Query *query;
|
||||
|
||||
gint check_size;
|
||||
|
||||
GdkPixmap *on_pixmap;
|
||||
GdkPixmap *off_pixmap;
|
||||
GdkBitmap *mask;
|
||||
};
|
||||
|
||||
struct _GNCReconcileListClass
|
||||
|
Loading…
Reference in New Issue
Block a user