Index: scconfig/Rev.h =================================================================== --- scconfig/Rev.h (revision 6734) +++ scconfig/Rev.h (revision 6735) @@ -1 +1 @@ -static const int myrev = 6718; +static const int myrev = 6735; Index: scconfig/Rev.tab =================================================================== --- scconfig/Rev.tab (revision 6734) +++ scconfig/Rev.tab (revision 6735) @@ -1,4 +1,4 @@ -6718 configure gtk splitup +6735 configure gtk splitup 6392 configure draw cross section plugin (gtk and lesstif depend on it) 6365 configure gtk splitup 6111 configure layer vs. layer group code split Index: src/Makefile.dep =================================================================== --- src/Makefile.dep (revision 6734) +++ src/Makefile.dep (revision 6735) @@ -819,38 +819,6 @@ ../src_plugins/lib_gtk_common/bu_cursor_pos.h \ ../src_plugins/lib_gtk_common/ui_zoompan.h unit.h pcb_bool.h \ ../src_plugins/lib_gtk_common/dlg_propedit.h -../src_plugins/hid_gtk/ghid-cell-renderer-visibility.o: \ - ../src_plugins/hid_gtk/ghid-cell-renderer-visibility.c ../config.h \ - ../src_plugins/hid_gtk/gui.h board.h const.h macro.h global_typedefs.h \ - pcb_bool.h unit.h vtroutestyle.h attrib.h \ - ../src_3rd/genvector/genvector_impl.h \ - ../src_3rd/genvector/genvector_undef.h layer.h globalconst.h \ - obj_all_list.h obj_arc_list.h obj_common.h \ - ../src_3rd/liblihata/genht/hash.h ../src_3rd/genlist/gendlist.h flag.h \ - obj_arc.h ../src_3rd/genlist/gentdlist_impl.h \ - ../src_3rd/genlist/gendlist.h ../src_3rd/genlist/gentdlist_undef.h \ - obj_elem_list.h obj_elem.h obj_line_list.h obj_line.h obj_pad_list.h \ - obj_pad.h obj_pinvia_list.h obj_pinvia.h obj_text.h ht_element.h \ - ../src_3rd/liblihata/genht/ht.h ../src_3rd/liblihata/genht/ht_inlines.h \ - obj_poly_list.h obj_poly.h polyarea.h obj_text_list.h obj_rat_list.h \ - obj_rat.h layer_grp.h library.h rats_patch.h board.h font.h box.h \ - math_helper.h move.h misc_util.h hid.h error.h drc.h hid_cfg.h \ - ../src_3rd/liblihata/dom.h ../src_3rd/liblihata/lihata.h \ - ../src_3rd/liblihata/parser.h ../src_3rd/liblihata/genht/htsp.h \ - ../src_3rd/liblihata/genht/ht.h hid_cfg_input.h \ - ../src_3rd/liblihata/genht/htip.h hid_cfg.h data.h crosshair.h \ - vtonpoint.h hid.h buffer.h ../src_plugins/hid_gtk/ghid-main-menu.h \ - ../src_plugins/lib_gtk_common/wt_layer_selector.h \ - ../src_plugins/lib_gtk_common/wt_route_style.h route_style.h conf_core.h \ - conf.h pcb-printf.h ../src_3rd/genvector/gds_char.h \ - ../src_3rd/liblihata/lihata.h ../src_3rd/genvector/vtp0.h list_conf.h \ - event.h compat_misc.h ../src_plugins/hid_gtk/colors.h \ - ../src_plugins/hid_gtk/hid_gtk_conf.h conf.h \ - ../src_plugins/lib_gtk_common/bu_cursor_pos.h \ - ../src_plugins/lib_gtk_common/ui_zoompan.h unit.h pcb_bool.h \ - ../src_plugins/lib_gtk_common/dlg_propedit.h compat_nls.h \ - ../src_plugins/hid_gtk/ghid-cell-renderer-visibility.h \ - ../src_plugins/lib_gtk_common/util_str.h ../src_plugins/hid_gtk/ghid-main-menu.o: \ ../src_plugins/hid_gtk/ghid-main-menu.c ../src_3rd/liblihata/tree.h \ ../src_3rd/liblihata/dom.h ../src_3rd/liblihata/lihata.h \ @@ -2275,7 +2243,7 @@ ../src_3rd/liblihata/dom.h ../src_3rd/liblihata/lihata.h \ ../src_3rd/liblihata/parser.h ../src_3rd/liblihata/genht/htsp.h \ ../src_3rd/liblihata/genht/ht.h ../src_3rd/genvector/vtp0.h list_conf.h \ - ../src_plugins/lib_gtk_common/dlg_route_style.h \ + error.h ../src_plugins/lib_gtk_common/dlg_route_style.h \ ../src_plugins/lib_gtk_common/wt_route_style.h route_style.h \ ../src_plugins/lib_gtk_common/wt_coord_entry.h unit.h ../src_plugins/lib_gtk_common/dlg_search.o: \ @@ -2444,36 +2412,14 @@ ../src_3rd/genvector/genvector_undef.h unit.h compat_nls.h ../src_plugins/lib_gtk_common/wt_layer_selector.o: \ ../src_plugins/lib_gtk_common/wt_layer_selector.c ../config.h \ - ../src_plugins/lib_gtk_common/wt_layer_selector.h \ - ../src_plugins/hid_gtk/ghid-cell-renderer-visibility.h \ - ../src_plugins/hid_gtk/gui.h board.h const.h macro.h global_typedefs.h \ - pcb_bool.h unit.h vtroutestyle.h attrib.h \ - ../src_3rd/genvector/genvector_impl.h \ - ../src_3rd/genvector/genvector_undef.h layer.h globalconst.h \ - obj_all_list.h obj_arc_list.h obj_common.h \ - ../src_3rd/liblihata/genht/hash.h ../src_3rd/genlist/gendlist.h flag.h \ - obj_arc.h ../src_3rd/genlist/gentdlist_impl.h \ - ../src_3rd/genlist/gendlist.h ../src_3rd/genlist/gentdlist_undef.h \ - obj_elem_list.h obj_elem.h obj_line_list.h obj_line.h obj_pad_list.h \ - obj_pad.h obj_pinvia_list.h obj_pinvia.h obj_text.h ht_element.h \ - ../src_3rd/liblihata/genht/ht.h ../src_3rd/liblihata/genht/ht_inlines.h \ - obj_poly_list.h obj_poly.h polyarea.h obj_text_list.h obj_rat_list.h \ - obj_rat.h layer_grp.h library.h rats_patch.h board.h font.h box.h \ - math_helper.h move.h misc_util.h hid.h error.h drc.h hid_cfg.h \ - ../src_3rd/liblihata/dom.h ../src_3rd/liblihata/lihata.h \ - ../src_3rd/liblihata/parser.h ../src_3rd/liblihata/genht/htsp.h \ - ../src_3rd/liblihata/genht/ht.h hid_cfg_input.h \ - ../src_3rd/liblihata/genht/htip.h hid_cfg.h data.h crosshair.h \ - vtonpoint.h hid.h buffer.h ../src_plugins/hid_gtk/ghid-main-menu.h \ - ../src_plugins/lib_gtk_common/wt_layer_selector.h \ - ../src_plugins/lib_gtk_common/wt_route_style.h route_style.h conf_core.h \ - conf.h pcb-printf.h ../src_3rd/genvector/gds_char.h \ - ../src_3rd/liblihata/lihata.h ../src_3rd/genvector/vtp0.h list_conf.h \ - event.h compat_misc.h ../src_plugins/hid_gtk/colors.h \ - ../src_plugins/hid_gtk/hid_gtk_conf.h conf.h \ - ../src_plugins/lib_gtk_common/bu_cursor_pos.h \ - ../src_plugins/lib_gtk_common/ui_zoompan.h unit.h pcb_bool.h \ - ../src_plugins/lib_gtk_common/dlg_propedit.h pcb-printf.h + ../src_plugins/lib_gtk_common/wt_layer_selector.h pcb-printf.h \ + ../src_3rd/genvector/gds_char.h ../src_3rd/genvector/genvector_impl.h \ + ../src_3rd/genvector/genvector_undef.h unit.h \ + ../src_plugins/lib_gtk_common/wt_layer_selector_cr.h +../src_plugins/lib_gtk_common/wt_layer_selector_cr.o: \ + ../src_plugins/lib_gtk_common/wt_layer_selector_cr.c ../config.h \ + compat_nls.h ../src_plugins/lib_gtk_common/wt_layer_selector_cr.h \ + ../src_plugins/lib_gtk_common/util_str.h ../src_plugins/lib_gtk_common/wt_preview.o: \ ../src_plugins/lib_gtk_common/wt_preview.c ../config.h conf_core.h \ conf.h global_typedefs.h pcb_bool.h unit.h pcb-printf.h \ Index: src_plugins/hid_gtk/ghid-cell-renderer-visibility.h =================================================================== --- src_plugins/hid_gtk/ghid-cell-renderer-visibility.h (revision 6734) +++ src_plugins/hid_gtk/ghid-cell-renderer-visibility.h (nonexistent) @@ -1,21 +0,0 @@ -#ifndef GHID_CELL_RENDERER_VISIBILITY_H__ -#define GHID_CELL_RENDERER_VISIBILITY_H__ - -#include -#include - -G_BEGIN_DECLS /* keep c++ happy */ -#define VISIBILITY_TOGGLE_SIZE 16 -#define GHID_CELL_RENDERER_VISIBILITY_TYPE (ghid_cell_renderer_visibility_get_type ()) -#define GHID_CELL_RENDERER_VISIBILITY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GHID_CELL_RENDERER_VISIBILITY_TYPE, GHidCellRendererVisibility)) -#define GHID_CELL_RENDERER_VISIBILITY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GHID_CELL_RENDERER_VISIBILITY_TYPE, GHidCellRendererVisibilityClass)) -#define IS_GHID_CELL_RENDERER_VISIBILITY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GHID_CELL_RENDERER_VISIBILITY_TYPE)) -#define IS_GHID_CELL_RENDERER_VISIBILITY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GHID_CELL_RENDERER_VISIBILITY_TYPE)) -typedef struct _GHidCellRendererVisibility GHidCellRendererVisibility; -typedef struct _GHidCellRendererVisibilityClass GHidCellRendererVisibilityClass; - -GType ghid_cell_renderer_visibility_get_type(void); -GtkCellRenderer *ghid_cell_renderer_visibility_new(void); - -G_END_DECLS /* keep c++ happy */ -#endif Index: src_plugins/hid_gtk/ghid-cell-renderer-visibility.c =================================================================== --- src_plugins/hid_gtk/ghid-cell-renderer-visibility.c (revision 6734) +++ src_plugins/hid_gtk/ghid-cell-renderer-visibility.c (nonexistent) @@ -1,259 +0,0 @@ -/*! \file - * \brief Implementation of GtkCellRenderer for layer visibility toggler - * \par More Information - * For details on the functions implemented here, see the Gtk - * documentation for the GtkCellRenderer object, which defines - * the interface we are implementing. - */ - -#include -#include -#include - -#include "config.h" -#include "gui.h" -#include "compat_nls.h" - -#include "ghid-cell-renderer-visibility.h" - -#include "../src_plugins/lib_gtk_common/util_str.h" - - -enum { - TOGGLED, - LAST_SIGNAL -}; -static guint toggle_cell_signals[LAST_SIGNAL] = { 0 }; - -enum { - PROP_ACTIVE = 1, - PROP_COLOR -}; - -struct _GHidCellRendererVisibility { - GtkCellRenderer parent; - - gboolean active; - gchar *color; -}; - -struct _GHidCellRendererVisibilityClass { - GtkCellRendererClass parent_class; - - void (*toggled) (GHidCellRendererVisibility * cell, const gchar * path); -}; - -/* RENDERER FUNCTIONS */ -/*! \brief Calculates the window area the renderer will use */ -static void -ghid_cell_renderer_visibility_get_size(GtkCellRenderer * cell, - GtkWidget * widget, - GdkRectangle * cell_area, gint * x_offset, gint * y_offset, gint * width, gint * height) -{ - GtkStyle *style = gtk_widget_get_style(widget); - gint w, h; - gint xpad, ypad; - gfloat xalign, yalign; - - gtk_cell_renderer_get_padding(cell, &xpad, &ypad); - gtk_cell_renderer_get_alignment(cell, &xalign, &yalign); - - w = VISIBILITY_TOGGLE_SIZE + 2 * (xpad + style->xthickness); - h = VISIBILITY_TOGGLE_SIZE + 2 * (ypad + style->ythickness); - - if (width) - *width = w; - if (height) - *height = h; - - if (cell_area) { - if (x_offset) { - if (gtk_widget_get_direction(widget) == GTK_TEXT_DIR_RTL) - xalign = 1. - xalign; - *x_offset = MAX(0, xalign * (cell_area->width - w)); - } - if (y_offset) - *y_offset = MAX(0, yalign * (cell_area->height - h)); - } -} - -/*! \brief Actually renders the swatch */ -static void -ghid_cell_renderer_visibility_render(GtkCellRenderer * cell, - GdkWindow * window, - GtkWidget * widget, - GdkRectangle * background_area, - GdkRectangle * cell_area, GdkRectangle * expose_area, GtkCellRendererState flags) -{ - GHidCellRendererVisibility *pcb_cell; - GdkRectangle toggle_rect; - GdkRectangle draw_rect; - gint xpad, ypad; - - pcb_cell = GHID_CELL_RENDERER_VISIBILITY(cell); - ghid_cell_renderer_visibility_get_size(cell, widget, cell_area, - &toggle_rect.x, &toggle_rect.y, &toggle_rect.width, &toggle_rect.height); - gtk_cell_renderer_get_padding(cell, &xpad, &ypad); - - toggle_rect.x += cell_area->x + xpad; - toggle_rect.y += cell_area->y + ypad; - toggle_rect.width -= xpad * 2; - toggle_rect.height -= ypad * 2; - - if (toggle_rect.width <= 0 || toggle_rect.height <= 0) - return; - - if (gdk_rectangle_intersect(expose_area, cell_area, &draw_rect)) { - GdkColor color; - cairo_t *cr = gdk_cairo_create(window); - if (expose_area) { - gdk_cairo_rectangle(cr, expose_area); - cairo_clip(cr); - } - cairo_set_line_width(cr, 1); - - cairo_rectangle(cr, toggle_rect.x + 0.5, toggle_rect.y + 0.5, toggle_rect.width - 1, toggle_rect.height - 1); - cairo_set_source_rgb(cr, 1, 1, 1); - cairo_fill_preserve(cr); - cairo_set_source_rgb(cr, 0, 0, 0); - cairo_stroke(cr); - - gdk_color_parse(pcb_cell->color, &color); - if (flags & GTK_CELL_RENDERER_PRELIT) { - color.red = (4 * color.red + 65535) / 5; - color.green = (4 * color.green + 65535) / 5; - color.blue = (4 * color.blue + 65535) / 5; - } - gdk_cairo_set_source_color(cr, &color); - if (pcb_cell->active) - cairo_rectangle(cr, toggle_rect.x + 0.5, toggle_rect.y + 0.5, toggle_rect.width - 1, toggle_rect.height - 1); - else { - cairo_move_to(cr, toggle_rect.x + 1, toggle_rect.y + 1); - cairo_rel_line_to(cr, toggle_rect.width / 2, 0); - cairo_rel_line_to(cr, -toggle_rect.width / 2, toggle_rect.width / 2); - cairo_close_path(cr); - } - cairo_fill(cr); - - cairo_destroy(cr); - } -} - -/*! \brief Toggless the swatch */ -static gint -ghid_cell_renderer_visibility_activate(GtkCellRenderer * cell, - GdkEvent * event, - GtkWidget * widget, - const gchar * path, - GdkRectangle * background_area, GdkRectangle * cell_area, GtkCellRendererState flags) -{ - g_signal_emit(cell, toggle_cell_signals[TOGGLED], 0, path); - return TRUE; -} - -/* Setter/Getter */ -static void ghid_cell_renderer_visibility_get_property(GObject * object, guint param_id, GValue * value, GParamSpec * pspec) -{ - GHidCellRendererVisibility *pcb_cell = GHID_CELL_RENDERER_VISIBILITY(object); - - switch (param_id) { - case PROP_ACTIVE: - g_value_set_boolean(value, pcb_cell->active); - break; - case PROP_COLOR: - g_value_set_string(value, pcb_cell->color); - break; - } -} - -static void -ghid_cell_renderer_visibility_set_property(GObject * object, guint param_id, const GValue * value, GParamSpec * pspec) -{ - GHidCellRendererVisibility *pcb_cell = GHID_CELL_RENDERER_VISIBILITY(object); - - switch (param_id) { - case PROP_ACTIVE: - pcb_cell->active = g_value_get_boolean(value); - break; - case PROP_COLOR: - g_free(pcb_cell->color); - pcb_cell->color = g_value_dup_string(value); - break; - } -} - - -/* CONSTRUCTOR */ -static void ghid_cell_renderer_visibility_init(GHidCellRendererVisibility * ls) -{ - g_object_set(ls, "mode", GTK_CELL_RENDERER_MODE_ACTIVATABLE, NULL); -} - -static void ghid_cell_renderer_visibility_class_init(GHidCellRendererVisibilityClass * klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS(klass); - GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS(klass); - - object_class->get_property = ghid_cell_renderer_visibility_get_property; - object_class->set_property = ghid_cell_renderer_visibility_set_property; - - cell_class->get_size = ghid_cell_renderer_visibility_get_size; - cell_class->render = ghid_cell_renderer_visibility_render; - cell_class->activate = ghid_cell_renderer_visibility_activate; - - g_object_class_install_property(object_class, PROP_ACTIVE, - g_param_spec_boolean("active", - _("Visibility state"), - _("Visibility of the layer"), FALSE, G_PARAM_READWRITE)); - g_object_class_install_property(object_class, PROP_COLOR, - g_param_spec_string("color", _("Layer color"), _("Layer color"), FALSE, G_PARAM_READWRITE)); - - - /** - * GHidCellRendererVisibility::toggled: - * @cell_renderer: the object which received the signal - * @path: string representation of #GtkTreePath describing the - * event location - * - * The ::toggled signal is emitted when the cell is toggled. - **/ - toggle_cell_signals[TOGGLED] = - g_signal_new(_("toggled"), - G_OBJECT_CLASS_TYPE(object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET(GHidCellRendererVisibilityClass, toggled), - NULL, NULL, g_cclosure_marshal_VOID__STRING, G_TYPE_NONE, 1, G_TYPE_STRING); -} - -/* PUBLIC FUNCTIONS */ -GType ghid_cell_renderer_visibility_get_type(void) -{ - static GType ls_type = 0; - - if (!ls_type) { - const GTypeInfo ls_info = { - sizeof(GHidCellRendererVisibilityClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) ghid_cell_renderer_visibility_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof(GHidCellRendererVisibility), - 0, /* n_preallocs */ - (GInstanceInitFunc) ghid_cell_renderer_visibility_init, - }; - - ls_type = g_type_register_static(GTK_TYPE_CELL_RENDERER, "GHidCellRendererVisibility", &ls_info, 0); - } - - return ls_type; -} - -GtkCellRenderer *ghid_cell_renderer_visibility_new(void) -{ - GHidCellRendererVisibility *rv = g_object_new(GHID_CELL_RENDERER_VISIBILITY_TYPE, NULL); - - rv->active = FALSE; - - return GTK_CELL_RENDERER(rv); -} Index: src_plugins/hid_gtk/Plug.tmpasm =================================================================== --- src_plugins/hid_gtk/Plug.tmpasm (revision 6734) +++ src_plugins/hid_gtk/Plug.tmpasm (revision 6735) @@ -1,7 +1,6 @@ put /local/pcb/mod {hid_gtk} put /local/pcb/mod/OBJS_C99 [@ $(PLUGDIR)/hid_gtk/colors.o - $(PLUGDIR)/hid_gtk/ghid-cell-renderer-visibility.o $(PLUGDIR)/hid_gtk/ghid-main-menu.o $(PLUGDIR)/hid_gtk/gtkhid-main.o $(PLUGDIR)/hid_gtk/gui-command-window.o Index: src_plugins/lib_gtk_common/Plug.tmpasm =================================================================== --- src_plugins/lib_gtk_common/Plug.tmpasm (revision 6734) +++ src_plugins/lib_gtk_common/Plug.tmpasm (revision 6735) @@ -40,6 +40,7 @@ $(PLUGDIR)/lib_gtk_common/win_place.o $(PLUGDIR)/lib_gtk_common/wt_coord_entry.o $(PLUGDIR)/lib_gtk_common/wt_layer_selector.o + $(PLUGDIR)/lib_gtk_common/wt_layer_selector_cr.o $(PLUGDIR)/lib_gtk_common/wt_preview.o $(PLUGDIR)/lib_gtk_common/wt_route_style.o @] Index: src_plugins/lib_gtk_common/wt_layer_selector.c =================================================================== --- src_plugins/lib_gtk_common/wt_layer_selector.c (revision 6734) +++ src_plugins/lib_gtk_common/wt_layer_selector.c (revision 6735) @@ -36,12 +36,11 @@ #include "wt_layer_selector.h" -#warning TODO: move this too: -#include "../src_plugins/hid_gtk/ghid-cell-renderer-visibility.h" - #include "pcb-printf.h" +#include "wt_layer_selector_cr.h" + #define INITIAL_ACTION_MAX 40 /* Forward dec'ls */ Index: src_plugins/lib_gtk_common/wt_layer_selector_cr.c =================================================================== --- src_plugins/lib_gtk_common/wt_layer_selector_cr.c (nonexistent) +++ src_plugins/lib_gtk_common/wt_layer_selector_cr.c (revision 6735) @@ -0,0 +1,258 @@ +/*! \file + * \brief Implementation of GtkCellRenderer for layer visibility toggler + * \par More Information + * For details on the functions implemented here, see the Gtk + * documentation for the GtkCellRenderer object, which defines + * the interface we are implementing. + */ + +#include +#include +#include + +#include "config.h" +#include "compat_nls.h" + +#include "wt_layer_selector_cr.h" + +#include "util_str.h" + + +enum { + TOGGLED, + LAST_SIGNAL +}; +static guint toggle_cell_signals[LAST_SIGNAL] = { 0 }; + +enum { + PROP_ACTIVE = 1, + PROP_COLOR +}; + +struct _GHidCellRendererVisibility { + GtkCellRenderer parent; + + gboolean active; + gchar *color; +}; + +struct _GHidCellRendererVisibilityClass { + GtkCellRendererClass parent_class; + + void (*toggled) (GHidCellRendererVisibility * cell, const gchar * path); +}; + +/* RENDERER FUNCTIONS */ +/*! \brief Calculates the window area the renderer will use */ +static void +ghid_cell_renderer_visibility_get_size(GtkCellRenderer * cell, + GtkWidget * widget, + GdkRectangle * cell_area, gint * x_offset, gint * y_offset, gint * width, gint * height) +{ + GtkStyle *style = gtk_widget_get_style(widget); + gint w, h; + gint xpad, ypad; + gfloat xalign, yalign; + + gtk_cell_renderer_get_padding(cell, &xpad, &ypad); + gtk_cell_renderer_get_alignment(cell, &xalign, &yalign); + + w = VISIBILITY_TOGGLE_SIZE + 2 * (xpad + style->xthickness); + h = VISIBILITY_TOGGLE_SIZE + 2 * (ypad + style->ythickness); + + if (width) + *width = w; + if (height) + *height = h; + + if (cell_area) { + if (x_offset) { + if (gtk_widget_get_direction(widget) == GTK_TEXT_DIR_RTL) + xalign = 1. - xalign; + *x_offset = MAX(0, xalign * (cell_area->width - w)); + } + if (y_offset) + *y_offset = MAX(0, yalign * (cell_area->height - h)); + } +} + +/*! \brief Actually renders the swatch */ +static void +ghid_cell_renderer_visibility_render(GtkCellRenderer * cell, + GdkWindow * window, + GtkWidget * widget, + GdkRectangle * background_area, + GdkRectangle * cell_area, GdkRectangle * expose_area, GtkCellRendererState flags) +{ + GHidCellRendererVisibility *pcb_cell; + GdkRectangle toggle_rect; + GdkRectangle draw_rect; + gint xpad, ypad; + + pcb_cell = GHID_CELL_RENDERER_VISIBILITY(cell); + ghid_cell_renderer_visibility_get_size(cell, widget, cell_area, + &toggle_rect.x, &toggle_rect.y, &toggle_rect.width, &toggle_rect.height); + gtk_cell_renderer_get_padding(cell, &xpad, &ypad); + + toggle_rect.x += cell_area->x + xpad; + toggle_rect.y += cell_area->y + ypad; + toggle_rect.width -= xpad * 2; + toggle_rect.height -= ypad * 2; + + if (toggle_rect.width <= 0 || toggle_rect.height <= 0) + return; + + if (gdk_rectangle_intersect(expose_area, cell_area, &draw_rect)) { + GdkColor color; + cairo_t *cr = gdk_cairo_create(window); + if (expose_area) { + gdk_cairo_rectangle(cr, expose_area); + cairo_clip(cr); + } + cairo_set_line_width(cr, 1); + + cairo_rectangle(cr, toggle_rect.x + 0.5, toggle_rect.y + 0.5, toggle_rect.width - 1, toggle_rect.height - 1); + cairo_set_source_rgb(cr, 1, 1, 1); + cairo_fill_preserve(cr); + cairo_set_source_rgb(cr, 0, 0, 0); + cairo_stroke(cr); + + gdk_color_parse(pcb_cell->color, &color); + if (flags & GTK_CELL_RENDERER_PRELIT) { + color.red = (4 * color.red + 65535) / 5; + color.green = (4 * color.green + 65535) / 5; + color.blue = (4 * color.blue + 65535) / 5; + } + gdk_cairo_set_source_color(cr, &color); + if (pcb_cell->active) + cairo_rectangle(cr, toggle_rect.x + 0.5, toggle_rect.y + 0.5, toggle_rect.width - 1, toggle_rect.height - 1); + else { + cairo_move_to(cr, toggle_rect.x + 1, toggle_rect.y + 1); + cairo_rel_line_to(cr, toggle_rect.width / 2, 0); + cairo_rel_line_to(cr, -toggle_rect.width / 2, toggle_rect.width / 2); + cairo_close_path(cr); + } + cairo_fill(cr); + + cairo_destroy(cr); + } +} + +/*! \brief Toggless the swatch */ +static gint +ghid_cell_renderer_visibility_activate(GtkCellRenderer * cell, + GdkEvent * event, + GtkWidget * widget, + const gchar * path, + GdkRectangle * background_area, GdkRectangle * cell_area, GtkCellRendererState flags) +{ + g_signal_emit(cell, toggle_cell_signals[TOGGLED], 0, path); + return TRUE; +} + +/* Setter/Getter */ +static void ghid_cell_renderer_visibility_get_property(GObject * object, guint param_id, GValue * value, GParamSpec * pspec) +{ + GHidCellRendererVisibility *pcb_cell = GHID_CELL_RENDERER_VISIBILITY(object); + + switch (param_id) { + case PROP_ACTIVE: + g_value_set_boolean(value, pcb_cell->active); + break; + case PROP_COLOR: + g_value_set_string(value, pcb_cell->color); + break; + } +} + +static void +ghid_cell_renderer_visibility_set_property(GObject * object, guint param_id, const GValue * value, GParamSpec * pspec) +{ + GHidCellRendererVisibility *pcb_cell = GHID_CELL_RENDERER_VISIBILITY(object); + + switch (param_id) { + case PROP_ACTIVE: + pcb_cell->active = g_value_get_boolean(value); + break; + case PROP_COLOR: + g_free(pcb_cell->color); + pcb_cell->color = g_value_dup_string(value); + break; + } +} + + +/* CONSTRUCTOR */ +static void ghid_cell_renderer_visibility_init(GHidCellRendererVisibility * ls) +{ + g_object_set(ls, "mode", GTK_CELL_RENDERER_MODE_ACTIVATABLE, NULL); +} + +static void ghid_cell_renderer_visibility_class_init(GHidCellRendererVisibilityClass * klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS(klass); + GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS(klass); + + object_class->get_property = ghid_cell_renderer_visibility_get_property; + object_class->set_property = ghid_cell_renderer_visibility_set_property; + + cell_class->get_size = ghid_cell_renderer_visibility_get_size; + cell_class->render = ghid_cell_renderer_visibility_render; + cell_class->activate = ghid_cell_renderer_visibility_activate; + + g_object_class_install_property(object_class, PROP_ACTIVE, + g_param_spec_boolean("active", + _("Visibility state"), + _("Visibility of the layer"), FALSE, G_PARAM_READWRITE)); + g_object_class_install_property(object_class, PROP_COLOR, + g_param_spec_string("color", _("Layer color"), _("Layer color"), FALSE, G_PARAM_READWRITE)); + + + /** + * GHidCellRendererVisibility::toggled: + * @cell_renderer: the object which received the signal + * @path: string representation of #GtkTreePath describing the + * event location + * + * The ::toggled signal is emitted when the cell is toggled. + **/ + toggle_cell_signals[TOGGLED] = + g_signal_new(_("toggled"), + G_OBJECT_CLASS_TYPE(object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET(GHidCellRendererVisibilityClass, toggled), + NULL, NULL, g_cclosure_marshal_VOID__STRING, G_TYPE_NONE, 1, G_TYPE_STRING); +} + +/* PUBLIC FUNCTIONS */ +GType ghid_cell_renderer_visibility_get_type(void) +{ + static GType ls_type = 0; + + if (!ls_type) { + const GTypeInfo ls_info = { + sizeof(GHidCellRendererVisibilityClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc) ghid_cell_renderer_visibility_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof(GHidCellRendererVisibility), + 0, /* n_preallocs */ + (GInstanceInitFunc) ghid_cell_renderer_visibility_init, + }; + + ls_type = g_type_register_static(GTK_TYPE_CELL_RENDERER, "GHidCellRendererVisibility", &ls_info, 0); + } + + return ls_type; +} + +GtkCellRenderer *ghid_cell_renderer_visibility_new(void) +{ + GHidCellRendererVisibility *rv = g_object_new(GHID_CELL_RENDERER_VISIBILITY_TYPE, NULL); + + rv->active = FALSE; + + return GTK_CELL_RENDERER(rv); +} Index: src_plugins/lib_gtk_common/wt_layer_selector_cr.h =================================================================== --- src_plugins/lib_gtk_common/wt_layer_selector_cr.h (nonexistent) +++ src_plugins/lib_gtk_common/wt_layer_selector_cr.h (revision 6735) @@ -0,0 +1,21 @@ +#ifndef GHID_CELL_RENDERER_VISIBILITY_H__ +#define GHID_CELL_RENDERER_VISIBILITY_H__ + +#include +#include + +G_BEGIN_DECLS /* keep c++ happy */ +#define VISIBILITY_TOGGLE_SIZE 16 +#define GHID_CELL_RENDERER_VISIBILITY_TYPE (ghid_cell_renderer_visibility_get_type ()) +#define GHID_CELL_RENDERER_VISIBILITY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GHID_CELL_RENDERER_VISIBILITY_TYPE, GHidCellRendererVisibility)) +#define GHID_CELL_RENDERER_VISIBILITY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GHID_CELL_RENDERER_VISIBILITY_TYPE, GHidCellRendererVisibilityClass)) +#define IS_GHID_CELL_RENDERER_VISIBILITY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GHID_CELL_RENDERER_VISIBILITY_TYPE)) +#define IS_GHID_CELL_RENDERER_VISIBILITY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GHID_CELL_RENDERER_VISIBILITY_TYPE)) +typedef struct _GHidCellRendererVisibility GHidCellRendererVisibility; +typedef struct _GHidCellRendererVisibilityClass GHidCellRendererVisibilityClass; + +GType ghid_cell_renderer_visibility_get_type(void); +GtkCellRenderer *ghid_cell_renderer_visibility_new(void); + +G_END_DECLS /* keep c++ happy */ +#endif