diff options
Diffstat (limited to 'src/ui/themewidget.c')
-rw-r--r-- | src/ui/themewidget.c | 129 |
1 files changed, 126 insertions, 3 deletions
diff --git a/src/ui/themewidget.c b/src/ui/themewidget.c index 3489618a..938248bd 100644 --- a/src/ui/themewidget.c +++ b/src/ui/themewidget.c @@ -34,11 +34,28 @@ static void meta_area_class_init (MetaAreaClass *klass); static void meta_area_init (MetaArea *area); static void meta_area_size_request (GtkWidget *widget, GtkRequisition *req); +#if GTK_CHECK_VERSION(3, 0, 0) +static gboolean meta_area_draw (GtkWidget *widget, + cairo_t *cr); +static void meta_area_get_preferred_height (GtkWidget *widget, + gint *minimal, + gint *natural); +static void meta_area_get_preferred_width (GtkWidget *widget, + gint *minimal, + gint *natural); +#else static gint meta_area_expose (GtkWidget *widget, GdkEventExpose *event); +#endif static void meta_area_finalize (GObject *object); +#if GTK_CHECK_VERSION(3, 0, 0) + +G_DEFINE_TYPE (MetaArea, meta_area, GTK_TYPE_MISC); + +#else + static GtkMiscClass *parent_class; GType @@ -66,35 +83,49 @@ meta_area_get_type (void) return area_type; } +#endif + static void meta_area_class_init (MetaAreaClass *class) { GObjectClass *gobject_class = G_OBJECT_CLASS (class); - GtkObjectClass UNUSED_VARIABLE *object_class; GtkWidgetClass *widget_class; - object_class = (GtkObjectClass*) class; widget_class = (GtkWidgetClass*) class; parent_class = g_type_class_peek (gtk_misc_get_type ()); gobject_class->finalize = meta_area_finalize; + #if GTK_CHECK_VERSION(3, 0, 0) + widget_class->draw = meta_area_draw; + widget_class->get_preferred_width = meta_area_get_preferred_width; + widget_class->get_preferred_height = meta_area_get_preferred_height; + #else widget_class->expose_event = meta_area_expose; widget_class->size_request = meta_area_size_request; + #endif } static void meta_area_init (MetaArea *area) { + #if GTK_CHECK_VERSION(3, 0, 0) + gtk_widget_set_has_window (GTK_WIDGET(area), FALSE); + #else GTK_WIDGET_SET_FLAGS (area, GTK_NO_WINDOW); + #endif } GtkWidget* meta_area_new (void) { MetaArea *area; - + + #if GTK_CHECK_VERSION(3, 0, 0) + area = g_object_new (META_TYPE_AREA, NULL); + #else area = gtk_type_new (META_TYPE_AREA); + #endif return GTK_WIDGET (area); } @@ -112,6 +143,60 @@ meta_area_finalize (GObject *object) G_OBJECT_CLASS (parent_class)->finalize (object); } +#if GTK_CHECK_VERSION(3, 0, 0) + +static gboolean +meta_area_draw (GtkWidget *widget, + cairo_t *cr) +{ + MetaArea *area; + GtkMisc *misc; + gint x, y; + gfloat xalign, yalign; + gint xpad, ypad; + GtkAllocation allocation; + GtkRequisition req; + + g_return_val_if_fail (META_IS_AREA (widget), FALSE); + + if (gtk_widget_is_drawable (widget)) + { + area = META_AREA (widget); + misc = GTK_MISC (widget); + + gtk_widget_get_allocation(widget, &allocation); + gtk_widget_get_requisition(widget, &req); + + if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR) + gtk_misc_get_alignment(misc, &xalign, &yalign); + else + { + gtk_misc_get_alignment(misc, &xalign, &yalign); + xalign = 1.0 - xalign; + } + + gtk_misc_get_padding(misc, &xpad, &ypad); + + + x = floor (allocation.x + xpad + + ((allocation.width - req.width) * xalign) + + 0.5); + y = floor (allocation.y + ypad + + ((allocation.height - req.height) * yalign) + + 0.5); + + if (area->draw_func) + { + (* area->draw_func) (area, cr, + area->user_data); + } + } + + return FALSE; +} + +#else + static gint meta_area_expose (GtkWidget *widget, GdkEventExpose *event) @@ -151,6 +236,8 @@ meta_area_expose (GtkWidget *widget, return FALSE; } +#endif + static void meta_area_size_request (GtkWidget *widget, GtkRequisition *req) @@ -169,10 +256,42 @@ meta_area_size_request (GtkWidget *widget, } } +#if GTK_CHECK_VERSION(3, 0, 0) + +static void +meta_area_get_preferred_width (GtkWidget *widget, + gint *minimal, + gint *natural) +{ + GtkRequisition requisition; + + meta_area_size_request (widget, &requisition); + + *minimal = *natural = requisition.width; +} + +static void +meta_area_get_preferred_height (GtkWidget *widget, + gint *minimal, + gint *natural) +{ + GtkRequisition requisition; + + meta_area_size_request (widget, &requisition); + + *minimal = *natural = requisition.height; +} + +#endif + void meta_area_setup (MetaArea *area, MetaAreaSizeFunc size_func, + #if GTK_CHECK_VERSION(3, 0, 0) + MetaAreaDrawFunc draw_func, + #else MetaAreaExposeFunc expose_func, + #endif void *user_data, GDestroyNotify dnotify) { @@ -180,7 +299,11 @@ meta_area_setup (MetaArea *area, (* area->dnotify) (area->user_data); area->size_func = size_func; + #if GTK_CHECK_VERSION(3, 0, 0) + area->draw_func = draw_func; + #else area->expose_func = expose_func; + #endif area->user_data = user_data; area->dnotify = dnotify; |