[dia/dia-next: 16/59] Minor widget tweaks
- From: Zander <zbrown src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dia/dia-next: 16/59] Minor widget tweaks
- Date: Wed, 9 Jan 2019 18:35:38 +0000 (UTC)
commit e03ea0c303cdc7b68a58962d93eb6af35cac1005
Author: Zander Brown <zbrown gnome org>
Date: Sun Dec 23 19:28:16 2018 +0000
Minor widget tweaks
app/diapagelayout.c | 39 ++++++++++++++++++---------------
app/ruler.c | 51 ++++---------------------------------------
app/splash.c | 9 ++++----
lib/diaarrowchooser.c | 6 ++---
lib/diacellrendererproperty.c | 27 +++++++++++++++--------
lib/widgets/dialist.c | 4 +++-
6 files changed, 54 insertions(+), 82 deletions(-)
---
diff --git a/app/diapagelayout.c b/app/diapagelayout.c
index f566707e..2034fb13 100644
--- a/app/diapagelayout.c
+++ b/app/diapagelayout.c
@@ -84,7 +84,7 @@ static GObjectClass *parent_class;
static void dia_page_layout_class_init(DiaPageLayoutClass *class);
static void dia_page_layout_init(DiaPageLayout *self);
-static void dia_page_layout_destroy(GObject *object);
+static void dia_page_layout_destroy(GtkWidget *object);
GType
dia_page_layout_get_type(void)
@@ -112,8 +112,10 @@ static void
dia_page_layout_class_init(DiaPageLayoutClass *class)
{
GObjectClass *object_class;
+ GtkWidgetClass *widget_class;
object_class = (GObjectClass*) class;
+ widget_class = GTK_WIDGET_CLASS (class);
parent_class = g_type_class_peek_parent (class);
pl_signals[CHANGED] =
@@ -128,11 +130,11 @@ dia_page_layout_class_init(DiaPageLayoutClass *class)
g_object_class_add_signals(object_class, pl_signals, LAST_SIGNAL);
#endif
- object_class->destroy = dia_page_layout_destroy;
+ widget_class->destroy = dia_page_layout_destroy;
}
static void darea_size_allocate(DiaPageLayout *self, GtkAllocation *alloc);
-static gint darea_expose_event(DiaPageLayout *self, GdkEventExpose *ev);
+static gint darea_draw(DiaPageLayout *self, cairo_t *ctx);
static void paper_size_change(GtkWidget *widget, DiaPageLayout *self);
static void orient_changed(DiaPageLayout *self);
static void margin_changed(DiaPageLayout *self);
@@ -354,16 +356,13 @@ dia_page_layout_init(DiaPageLayout *self)
g_signal_connect_swapped(G_OBJECT(self->darea), "size_allocate",
G_CALLBACK(darea_size_allocate),
G_OBJECT(self));
- g_signal_connect_swapped(G_OBJECT(self->darea), "expose_event",
- G_CALLBACK(darea_expose_event),
+ g_signal_connect_swapped(G_OBJECT(self->darea), "draw",
+ G_CALLBACK(darea_draw),
G_OBJECT(self));
- gdk_color_white(gtk_widget_get_colormap(GTK_WIDGET(self)), &self->white);
- gdk_color_black(gtk_widget_get_colormap(GTK_WIDGET(self)), &self->black);
self->blue.red = 0;
self->blue.green = 0;
self->blue.blue = 0x7fff;
- gdk_color_alloc(gtk_widget_get_colormap(GTK_WIDGET(self)), &self->blue);
self->block_changed = FALSE;
}
@@ -603,25 +602,23 @@ darea_size_allocate(DiaPageLayout *self, GtkAllocation *allocation)
}
static gint
-darea_expose_event(DiaPageLayout *self, GdkEventExpose *event)
+darea_draw (DiaPageLayout *self, cairo_t *ctx)
{
GdkWindow *window = gtk_widget_get_window(self->darea);
gfloat val;
gint num;
- cairo_t *ctx;
if (!window)
return FALSE;
- ctx = gdk_cairo_create (window);
cairo_set_line_cap (ctx, CAIRO_LINE_CAP_SQUARE);
cairo_set_line_width (ctx, 1);
cairo_set_antialias (ctx, CAIRO_ANTIALIAS_NONE);
cairo_set_source_rgba (ctx, 0, 0, 0, 0);
cairo_rectangle (ctx, 0, 0,
- self->darea->allocation.width,
- self->darea->allocation.height);
+ gtk_widget_get_allocated_width (self->darea),
+ gtk_widget_get_allocated_height (self->darea));
cairo_fill (ctx);
/* draw the page image */
@@ -719,9 +716,12 @@ static void
paper_size_change(GtkWidget *widget, DiaPageLayout *self)
{
gchar buf[512];
+ GtkAllocation alloc;
+
+ gtk_widget_get_allocation (self->darea, &alloc);
self->papernum = dia_option_menu_get_active (widget);
- size_page(self, &self->darea->allocation);
+ size_page(self, &alloc);
gtk_widget_queue_draw(self->darea);
self->block_changed = TRUE;
@@ -766,7 +766,10 @@ paper_size_change(GtkWidget *widget, DiaPageLayout *self)
static void
orient_changed(DiaPageLayout *self)
{
- size_page(self, &self->darea->allocation);
+ GtkAllocation alloc;
+
+ gtk_widget_get_allocation (self->darea, &alloc);
+ size_page(self, &alloc);
gtk_widget_queue_draw(self->darea);
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(self->orient_portrait))) {
@@ -825,10 +828,10 @@ scale_changed(DiaPageLayout *self)
}
static void
-dia_page_layout_destroy(GObject *object)
+dia_page_layout_destroy(GtkWidget *object)
{
- if (parent_class->destroy)
- (* parent_class->destroy)(object);
+ if (GTK_WIDGET_CLASS (parent_class)->destroy)
+ (* GTK_WIDGET_CLASS (parent_class)->destroy)(object);
}
#ifdef PAGELAYOUT_TEST
diff --git a/app/ruler.c b/app/ruler.c
index bc8ea053..44ed29ea 100644
--- a/app/ruler.c
+++ b/app/ruler.c
@@ -62,33 +62,20 @@ dia_ruler_draw (GtkWidget *widget,
{
DiaRuler *ruler = DIA_RULER(widget);
-#if GTK_CHECK_VERSION(2,18,0)
- if (gtk_widget_is_drawable (widget))
-#else
- if (GTK_WIDGET_DRAWABLE (widget))
-#endif
- {
GtkStyle *style = gtk_widget_get_style (widget);
PangoLayout *layout;
int x, y, dx, dy, width, height;
real pos;
layout = gtk_widget_create_pango_layout (widget, "012456789");
-#if GTK_CHECK_VERSION(3,0,0)
+
width = gtk_widget_get_allocated_width (widget);
height = gtk_widget_get_allocated_height (widget);
-#else
- width = widget->allocation.width;
- height = widget->allocation.height;
-#endif
+
dx = (ruler->orientation == GTK_ORIENTATION_VERTICAL) ? width/3 : 0;
dy = (ruler->orientation == GTK_ORIENTATION_HORIZONTAL) ? height/3 : 0;
-#if GTK_CHECK_VERSION(2,18,0)
gdk_cairo_set_source_rgba (cr, &style->text[gtk_widget_get_state(widget)]);
-#else
- gdk_cairo_set_source_rgba (cr, &style->text[GTK_WIDGET_STATE(widget)]);
-#endif
cairo_set_line_width (cr, 1);
pos = ruler->lower;
@@ -154,28 +141,6 @@ dia_ruler_draw (GtkWidget *widget,
cairo_fill (cr);
}
}
- }
- return FALSE;
-}
-
-/* Wrapper can go with Gtk+-3.0 */
-static gboolean
-dia_ruler_expose_event (GtkWidget *widget,
- GdkEventExpose *event)
-{
-#if GTK_CHECK_VERSION(2,18,0)
- if (gtk_widget_is_drawable (widget))
-#else
- if (GTK_WIDGET_DRAWABLE (widget))
-#endif
- {
- GdkWindow *window = gtk_widget_get_window(widget);
- cairo_t *cr = gdk_cairo_create (window);
-
- dia_ruler_draw (widget, cr);
-
- cairo_destroy (cr);
- }
return FALSE;
}
@@ -193,15 +158,9 @@ dia_ruler_motion_notify (GtkWidget *widget,
gdk_event_request_motions (event);
x = event->x;
y = event->y;
-#if GTK_CHECK_VERSION(3,0,0)
+
width = gtk_widget_get_allocated_width (widget);
height = gtk_widget_get_allocated_height (widget);
-#else
- width = widget->allocation.width;
- height = widget->allocation.height;
-#endif
-
- gdk_drawable_get_size (widget->window, &width, &height);
if (ruler->orientation == GTK_ORIENTATION_HORIZONTAL)
{
@@ -248,9 +207,7 @@ dia_ruler_class_init (DiaRulerClass *klass)
{
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
-#if !GTK_CHECK_VERSION(3,0,0)
- widget_class->expose_event = dia_ruler_expose_event;
-#endif
+ widget_class->draw = dia_ruler_draw;
}
static void
diff --git a/app/splash.c b/app/splash.c
index fecf445f..b58f2a99 100644
--- a/app/splash.c
+++ b/app/splash.c
@@ -29,7 +29,7 @@ get_logo_pixmap (void)
static GtkWidget* splash = NULL;
static void
-splash_expose (GtkWidget *widget, GdkEventExpose *event)
+splash_draw (GtkWidget *widget, cairo_t *event)
{
/* this gets called after the splash screen gets exposed ... */
gtk_main_quit();
@@ -71,10 +71,11 @@ app_splash_init (const gchar* fname)
gtk_widget_show_all (splash);
- signal_id = g_signal_connect_after(G_OBJECT(splash), "expose_event",
- G_CALLBACK(splash_expose), NULL);
+ signal_id = g_signal_connect_after(G_OBJECT(splash), "draw",
+ G_CALLBACK(splash_draw), NULL);
- /* splash_expose gets us out of this */
+ /* splash_draw gets us out of this */
+ /* TODO: Why? */
gtk_main();
g_signal_handler_disconnect(G_OBJECT(splash), signal_id);
}
diff --git a/lib/diaarrowchooser.c b/lib/diaarrowchooser.c
index a0c53004..b9530f8a 100644
--- a/lib/diaarrowchooser.c
+++ b/lib/diaarrowchooser.c
@@ -194,7 +194,7 @@ dia_arrow_preview_draw (GtkWidget *widget, cairo_t *ctx)
renderer = g_object_new (dia_cairo_renderer_get_type (), NULL);
renderer->with_alpha = TRUE;
- renderer->cr = ctx;
+ renderer->cr = cairo_reference (ctx);
renderer->surface = NULL;
renderer_ops = DIA_RENDERER_GET_CLASS (renderer);
@@ -346,9 +346,9 @@ dia_arrow_chooser_dialog_new(DiaArrowChooser *chooser)
chooser->dialog = gtk_dialog_new_with_buttons(_("Arrow Properties"),
NULL,
GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_STOCK_CANCEL,
+ _("Cancel"),
GTK_RESPONSE_CANCEL,
- GTK_STOCK_OK,
+ _("Okay"),
GTK_RESPONSE_OK,
NULL);
gtk_dialog_set_default_response(GTK_DIALOG(chooser->dialog),
diff --git a/lib/diacellrendererproperty.c b/lib/diacellrendererproperty.c
index 512cb55d..fc52ed75 100644
--- a/lib/diacellrendererproperty.c
+++ b/lib/diacellrendererproperty.c
@@ -127,7 +127,9 @@ dia_cell_renderer_property_class_init (DiaCellRendererPropertyClass *klass)
static void
dia_cell_renderer_property_init (DiaCellRendererProperty *cellproperty)
{
- GTK_CELL_RENDERER (cellproperty)->mode = GTK_CELL_RENDERER_MODE_ACTIVATABLE;
+ g_object_set (G_OBJECT (cellproperty),
+ "mode", GTK_CELL_RENDERER_MODE_ACTIVATABLE,
+ NULL);
}
static void
@@ -205,6 +207,10 @@ dia_cell_renderer_property_get_size (GtkCellRenderer *cell,
gint view_height = 0;
gint calc_width;
gint calc_height;
+ gint xpad;
+ gint ypad;
+ gfloat xalign;
+ gfloat yalign;
#if 0
cellproperty = DIA_CELL_RENDERER_PROPERTY (cell);
@@ -222,8 +228,11 @@ dia_cell_renderer_property_get_size (GtkCellRenderer *cell,
view_height = 30;
#endif
- calc_width = (gint) cell->xpad * 2 + view_width;
- calc_height = (gint) cell->ypad * 2 + view_height;
+ gtk_cell_renderer_get_padding (cell, &xpad, &ypad);
+ gtk_cell_renderer_get_alignment (cell, &xalign, &yalign);
+
+ calc_width = (gint) xpad * 2 + view_width;
+ calc_height = (gint) ypad * 2 + view_height;
if (x_offset) *x_offset = 0;
if (y_offset) *y_offset = 0;
@@ -233,15 +242,15 @@ dia_cell_renderer_property_get_size (GtkCellRenderer *cell,
if (x_offset)
{
*x_offset = (((gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) ?
- 1.0 - cell->xalign : cell->xalign) *
- (cell_area->width - calc_width - 2 * cell->xpad));
- *x_offset = (MAX (*x_offset, 0) + cell->xpad);
+ 1.0 - xalign : xalign) *
+ (cell_area->width - calc_width - 2 * xpad));
+ *x_offset = (MAX (*x_offset, 0) + xpad);
}
if (y_offset)
{
- *y_offset = (cell->yalign *
- (cell_area->height - calc_height - 2 * cell->ypad));
- *y_offset = (MAX (*y_offset, 0) + cell->ypad);
+ *y_offset = (yalign *
+ (cell_area->height - calc_height - 2 * ypad));
+ *y_offset = (MAX (*y_offset, 0) + ypad);
}
}
diff --git a/lib/widgets/dialist.c b/lib/widgets/dialist.c
index 789b2838..6383ec68 100644
--- a/lib/widgets/dialist.c
+++ b/lib/widgets/dialist.c
@@ -572,7 +572,9 @@ dia_list_item_class_init (DiaListItemClass * klass)
static void
dia_list_item_init (DiaListItem *self)
{
- ((DiaListItemPrivate *) dia_list_item_get_instance_private (self))->label = gtk_label_new (NULL);
+ ((DiaListItemPrivate *) dia_list_item_get_instance_private (self))->label = g_object_new (GTK_TYPE_LABEL,
+ "xalign", 0.0,
+ NULL);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]