From: Jim Evins Date: Sun, 11 Oct 2009 05:06:35 +0000 (-0400) Subject: Use accessor functions instead direct access X-Git-Tag: glabels-2_3_0~161 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=480d31eff113c6a5136f56654bdbed67805c269c;p=glabels Use accessor functions instead direct access Replaced several occurances of directly accessing widget fields with the use of accessor functions. This round hit primarily windows, bin_windows and styles. Still need to address flags and allocations when GTK has the needed accessors. --- diff --git a/src/color-combo-button.c b/src/color-combo-button.c index 65461be2..1c83ac82 100644 --- a/src/color-combo-button.c +++ b/src/color-combo-button.c @@ -303,10 +303,13 @@ menu_position_function (GtkMenu *menu, gpointer user_data) { glColorComboButton *this = GL_COLOR_COMBO_BUTTON (user_data); + GdkWindow *window; gint x1, y1; gint menu_h, menu_w; - gdk_window_get_origin (GTK_WIDGET (this)->window, &x1, &y1); + window = gtk_widget_get_window (GTK_WIDGET (this)); + + gdk_window_get_origin (window, &x1, &y1); *x = x1 + GTK_WIDGET (this)->allocation.x; *y = y1 + GTK_WIDGET (this)->allocation.y + GTK_WIDGET (this)->allocation.height; diff --git a/src/color-combo.c b/src/color-combo.c index 250292d4..a5e99d22 100644 --- a/src/color-combo.c +++ b/src/color-combo.c @@ -245,10 +245,13 @@ menu_position_function (GtkMenu *menu, gpointer user_data) { glColorCombo *this = GL_COLOR_COMBO (user_data); + GdkWindow *window; gint x1, y1; gint menu_h, menu_w; - gdk_window_get_origin (GTK_WIDGET (this)->window, &x1, &y1); + window = gtk_widget_get_window (GTK_WIDGET (this)); + + gdk_window_get_origin (window, &x1, &y1); *x = x1 + GTK_WIDGET (this)->allocation.x; *y = y1 + GTK_WIDGET (this)->allocation.y + GTK_WIDGET (this)->allocation.height; diff --git a/src/color-swatch.c b/src/color-swatch.c index ae71f1a7..d850e528 100644 --- a/src/color-swatch.c +++ b/src/color-swatch.c @@ -169,13 +169,16 @@ style_set_cb (GtkWidget *widget, static void redraw (glColorSwatch *this) { + GdkWindow *window; GdkRegion *region; - if (GTK_WIDGET_REALIZED (GTK_WIDGET (this))) + window = gtk_widget_get_window (GTK_WIDGET (this)); + + if (window) { /* redraw the cairo canvas forcing an expose event */ - region = gdk_drawable_get_clip_region (GTK_WIDGET (this)->window); - gdk_window_invalidate_region (GTK_WIDGET (this)->window, region, TRUE); + region = gdk_drawable_get_clip_region (window); + gdk_window_invalidate_region (window, region, TRUE); gdk_region_destroy (region); } } @@ -188,9 +191,12 @@ static gboolean expose_event_cb (GtkWidget *widget, GdkEventExpose *event) { - cairo_t *cr; + GdkWindow *window; + cairo_t *cr; + + window = gtk_widget_get_window (widget); - cr = gdk_cairo_create (widget->window); + cr = gdk_cairo_create (window); cairo_rectangle (cr, event->area.x, event->area.y, diff --git a/src/font-combo.c b/src/font-combo.c index ffd8877e..d094497d 100644 --- a/src/font-combo.c +++ b/src/font-combo.c @@ -225,11 +225,14 @@ menu_position_function (GtkMenu *menu, gboolean *push_in, gpointer user_data) { - glFontCombo *this = GL_FONT_COMBO (user_data); + glFontCombo *this = GL_FONT_COMBO (user_data); + GdkWindow *window; gint x1, y1; gint menu_h, menu_w; - gdk_window_get_origin (GTK_WIDGET (this)->window, &x1, &y1); + window = gtk_widget_get_window (GTK_WIDGET (this)); + + gdk_window_get_origin (window, &x1, &y1); *x = x1 + GTK_WIDGET (this)->allocation.x; *y = y1 + GTK_WIDGET (this)->allocation.y + GTK_WIDGET (this)->allocation.height; diff --git a/src/font-sample.c b/src/font-sample.c index da2c13aa..ff04ac85 100644 --- a/src/font-sample.c +++ b/src/font-sample.c @@ -163,13 +163,16 @@ style_set_cb (GtkWidget *widget, static void redraw (glFontSample *this) { + GdkWindow *window; GdkRegion *region; - if (GTK_WIDGET_REALIZED (GTK_WIDGET (this))) + window = gtk_widget_get_window (GTK_WIDGET (this)); + + if (window) { /* redraw the cairo canvas forcing an expose event */ - region = gdk_drawable_get_clip_region (GTK_WIDGET (this)->window); - gdk_window_invalidate_region (GTK_WIDGET (this)->window, region, TRUE); + region = gdk_drawable_get_clip_region (window); + gdk_window_invalidate_region (window, region, TRUE); gdk_region_destroy (region); } } @@ -182,9 +185,12 @@ static gboolean expose_event_cb (GtkWidget *widget, GdkEventExpose *event) { - cairo_t *cr; + GdkWindow *window; + cairo_t *cr; + + window = gtk_widget_get_window (widget); - cr = gdk_cairo_create (widget->window); + cr = gdk_cairo_create (window); cairo_rectangle (cr, event->area.x, event->area.y, diff --git a/src/mini-label-preview.c b/src/mini-label-preview.c index e58986fd..e5f21813 100644 --- a/src/mini-label-preview.c +++ b/src/mini-label-preview.c @@ -181,13 +181,16 @@ style_set_cb (GtkWidget *widget, static void redraw (glMiniLabelPreview *this) { + GdkWindow *window; GdkRegion *region; - if (GTK_WIDGET_REALIZED (GTK_WIDGET (this))) + window = gtk_widget_get_window (GTK_WIDGET (this)); + + if (window) { /* redraw the cairo canvas forcing an expose event */ - region = gdk_drawable_get_clip_region (GTK_WIDGET (this)->window); - gdk_window_invalidate_region (GTK_WIDGET (this)->window, region, TRUE); + region = gdk_drawable_get_clip_region (window); + gdk_window_invalidate_region (window, region, TRUE); gdk_region_destroy (region); } } @@ -200,9 +203,12 @@ static gboolean expose_event_cb (GtkWidget *widget, GdkEventExpose *event) { - cairo_t *cr; + GdkWindow *window; + cairo_t *cr; + + window = gtk_widget_get_window (widget); - cr = gdk_cairo_create (widget->window); + cr = gdk_cairo_create (window); cairo_rectangle (cr, event->area.x, event->area.y, diff --git a/src/mini-preview.c b/src/mini-preview.c index 9bcedbff..2d5882a5 100644 --- a/src/mini-preview.c +++ b/src/mini-preview.c @@ -588,6 +588,7 @@ button_press_event_cb (GtkWidget *widget, GdkEventButton *event) { glMiniPreview *this = GL_MINI_PREVIEW (widget); + GdkWindow *window; cairo_t *cr; gdouble scale; gdouble x, y; @@ -597,7 +598,10 @@ button_press_event_cb (GtkWidget *widget, if ( event->button == 1 ) { - cr = gdk_cairo_create (GTK_WIDGET (this->priv->canvas)->window); + + window = gtk_widget_get_window (this->priv->canvas); + + cr = gdk_cairo_create (window); scale = set_transform_and_get_scale (this, cr); @@ -636,16 +640,19 @@ motion_notify_event_cb (GtkWidget *widget, GdkEventMotion *event) { glMiniPreview *this = GL_MINI_PREVIEW (widget); - cairo_t *cr; - gdouble scale; - gdouble x, y; - gint i; + GdkWindow *window; + cairo_t *cr; + gdouble scale; + gdouble x, y; + gint i; gl_debug (DEBUG_MINI_PREVIEW, "START"); if (this->priv->dragging) { - cr = gdk_cairo_create (GTK_WIDGET (this->priv->canvas)->window); + window = gtk_widget_get_window (this->priv->canvas); + + cr = gdk_cairo_create (window); scale = set_transform_and_get_scale (this, cr); @@ -743,13 +750,16 @@ expose_event_cb (GtkWidget *widget, GdkEventExpose *event, glMiniPreview *this) { + GdkWindow *window; cairo_t *cr; gl_debug (DEBUG_MINI_PREVIEW, "START"); this->priv->update_scheduled_flag = FALSE; - cr = gdk_cairo_create (widget->window); + window = gtk_widget_get_window (widget); + + cr = gdk_cairo_create (window); cairo_rectangle (cr, event->area.x, event->area.y, @@ -788,19 +798,22 @@ style_set_cb (GtkWidget *widget, static void redraw (glMiniPreview *this) { + GdkWindow *window; GdkRegion *region; gl_debug (DEBUG_MINI_PREVIEW, "START"); - if (GTK_WIDGET (this->priv->canvas)->window) + window = gtk_widget_get_window (this->priv->canvas); + + if (window) { if ( !this->priv->update_scheduled_flag ) { this->priv->update_scheduled_flag = TRUE; - region = gdk_drawable_get_clip_region (GTK_WIDGET (this->priv->canvas)->window); - gdk_window_invalidate_region (GTK_WIDGET (this->priv->canvas)->window, region, TRUE); + region = gdk_drawable_get_clip_region (window); + gdk_window_invalidate_region (window, region, TRUE); gdk_region_destroy (region); } } diff --git a/src/view.c b/src/view.c index 06e9d310..3ebfbe08 100644 --- a/src/view.c +++ b/src/view.c @@ -551,22 +551,22 @@ get_home_scale (glView *view) void gl_view_update (glView *view) { - GtkWidget *widget; + GdkWindow *window; GdkRegion *region; gl_debug (DEBUG_VIEW, "START"); - widget = GTK_WIDGET (view->canvas); - - if (!widget->window) return; + window = gtk_widget_get_window (GTK_WIDGET (view->canvas)); + + if (!window) return; if ( !view->update_scheduled_flag ) { view->update_scheduled_flag = TRUE; - region = gdk_drawable_get_clip_region (widget->window); + region = gdk_drawable_get_clip_region (window); /* redraw the cairo canvas completely by exposing it */ - gdk_window_invalidate_region (widget->window, region, TRUE); + gdk_window_invalidate_region (window, region, TRUE); gdk_region_destroy (region); } @@ -582,15 +582,15 @@ gl_view_update_region (glView *view, cairo_t *cr, glLabelRegion *region) { - GtkWidget *widget; + GdkWindow *window; GdkRectangle rect; gdouble x, y, w, h; gl_debug (DEBUG_VIEW, "START"); - widget = GTK_WIDGET (view->canvas); + window = gtk_widget_get_window (GTK_WIDGET (view->canvas)); - if (!widget->window) return; + if (!window) return; x = MIN (region->x1, region->x2); y = MIN (region->y1, region->y2); @@ -605,7 +605,7 @@ gl_view_update_region (glView *view, rect.width = w + 6; rect.height = h + 6; - gdk_window_invalidate_rect (widget->window, &rect, TRUE); + gdk_window_invalidate_rect (window, &rect, TRUE); gl_debug (DEBUG_VIEW, "END"); } @@ -618,14 +618,15 @@ static gboolean expose_cb (glView *view, GdkEventExpose *event) { - cairo_t *cr; + GdkWindow *bin_window; + cairo_t *cr; gl_debug (DEBUG_VIEW, "START"); view->update_scheduled_flag = FALSE; - /* get a cairo_t */ - cr = gdk_cairo_create (GTK_LAYOUT (view->canvas)->bin_window); + bin_window = gtk_layout_get_bin_window (GTK_LAYOUT (view->canvas)); + cr = gdk_cairo_create (bin_window); cairo_rectangle (cr, event->area.x, event->area.y, @@ -663,16 +664,22 @@ static void size_allocate_cb (glView *view, GtkAllocation *allocation) { + GtkAdjustment *hadjustment; + GtkAdjustment *vadjustment; + gl_debug (DEBUG_VIEW, "START"); - GTK_LAYOUT (view->canvas)->hadjustment->page_size = allocation->width; - GTK_LAYOUT (view->canvas)->hadjustment->page_increment = allocation->width / 2; - - GTK_LAYOUT (view->canvas)->vadjustment->page_size = allocation->height; - GTK_LAYOUT (view->canvas)->vadjustment->page_increment = allocation->height / 2; + hadjustment = gtk_layout_get_hadjustment(GTK_LAYOUT (view->canvas)); + vadjustment = gtk_layout_get_vadjustment(GTK_LAYOUT (view->canvas)); + + gtk_adjustment_set_page_size( hadjustment, allocation->width); + gtk_adjustment_set_page_increment( hadjustment, allocation->width / 2); + + gtk_adjustment_set_page_size( vadjustment, allocation->height); + gtk_adjustment_set_page_increment( vadjustment, allocation->height / 2); - g_signal_emit_by_name (GTK_LAYOUT (view->canvas)->hadjustment, "changed"); - g_signal_emit_by_name (GTK_LAYOUT (view->canvas)->vadjustment, "changed"); + g_signal_emit_by_name (hadjustment, "changed"); + g_signal_emit_by_name (vadjustment, "changed"); if (view->zoom_to_fit_flag) { /* Maintain best fit zoom */ @@ -727,12 +734,18 @@ label_changed_cb (glView *view) static void label_resized_cb (glView *view) { + GtkAdjustment *hadjustment; + GtkAdjustment *vadjustment; + g_return_if_fail (view && GL_IS_VIEW (view)); gl_debug (DEBUG_VIEW, "START"); - g_signal_emit_by_name (GTK_LAYOUT (view->canvas)->hadjustment, "changed"); - g_signal_emit_by_name (GTK_LAYOUT (view->canvas)->vadjustment, "changed"); + hadjustment = gtk_layout_get_hadjustment(GTK_LAYOUT (view->canvas)); + vadjustment = gtk_layout_get_vadjustment(GTK_LAYOUT (view->canvas)); + + g_signal_emit_by_name (hadjustment, "changed"); + g_signal_emit_by_name (vadjustment, "changed"); gl_view_update (view); @@ -781,6 +794,7 @@ static void draw_layers (glView *view, cairo_t *cr) { + GdkWindow *bin_window; gdouble scale; gdouble w, h; gint canvas_w, canvas_h; @@ -790,6 +804,8 @@ draw_layers (glView *view, gl_debug (DEBUG_VIEW, "START"); + bin_window = gtk_layout_get_bin_window (GTK_LAYOUT (view->canvas)); + scale = view->zoom * view->home_scale; gl_label_get_size (view->label, &w, &h); @@ -797,7 +813,7 @@ draw_layers (glView *view, scale = view->home_scale * view->zoom; gtk_layout_set_size (GTK_LAYOUT (view->canvas), w*scale+8, h*scale+8); - gdk_drawable_get_size (GTK_LAYOUT (view->canvas)->bin_window, &canvas_w, &canvas_h); + gdk_drawable_get_size (bin_window, &canvas_w, &canvas_h); view->x0 = (canvas_w/scale - w) / 2.0; view->y0 = (canvas_h/scale - h) / 2.0; @@ -1118,14 +1134,17 @@ gl_view_hide_markup (glView *view) void gl_view_arrow_mode (glView *view) { + GdkWindow *window; GdkCursor *cursor; gl_debug (DEBUG_VIEW, "START"); g_return_if_fail (view && GL_IS_VIEW (view)); + window = gtk_widget_get_window (view->canvas); + cursor = gdk_cursor_new (GDK_LEFT_PTR); - gdk_window_set_cursor (view->canvas->window, cursor); + gdk_window_set_cursor (window, cursor); gdk_cursor_unref (cursor); view->mode = GL_VIEW_MODE_ARROW; @@ -1142,12 +1161,15 @@ void gl_view_object_create_mode (glView *view, glLabelObjectType type) { + GdkWindow *window; GdkCursor *cursor = NULL; gl_debug (DEBUG_VIEW, "START"); g_return_if_fail (view && GL_IS_VIEW (view)); + window = gtk_widget_get_window (view->canvas); + switch (type) { case GL_LABEL_OBJECT_BOX: @@ -1173,7 +1195,7 @@ gl_view_object_create_mode (glView *view, break; } - gdk_window_set_cursor (view->canvas->window, cursor); + gdk_window_set_cursor (window, cursor); gdk_cursor_unref (cursor); view->mode = GL_VIEW_MODE_OBJECT_CREATE; @@ -2805,7 +2827,7 @@ selection_clear_cb (GtkWidget *widget, /*---------------------------------------------------------------------------*/ static void selection_get_cb (GtkWidget *widget, - GtkSelectionData *selection_data, + GtkSelectionData *sd, guint info, guint time, glView *view) @@ -2821,7 +2843,7 @@ selection_get_cb (GtkWidget *widget, buffer = gl_xml_label_save_buffer (view->selection_data, &status); - gtk_selection_data_set (selection_data, + gtk_selection_data_set (sd, GDK_SELECTION_TYPE_STRING, 8, (guchar *)buffer, strlen (buffer)); g_free (buffer); @@ -2836,7 +2858,7 @@ selection_get_cb (GtkWidget *widget, /*---------------------------------------------------------------------------*/ static void selection_received_cb (GtkWidget *widget, - GtkSelectionData *selection_data, + GtkSelectionData *sd, guint time, glView *view) { @@ -2849,17 +2871,20 @@ selection_received_cb (GtkWidget *widget, g_return_if_fail (view && GL_IS_VIEW (view)); - if (selection_data->length < 0) { + if (gtk_selection_data_get_length (sd) < 0) + { return; } - if (selection_data->type != GDK_SELECTION_TYPE_STRING) { + if (gtk_selection_data_get_data_type (sd) != GDK_SELECTION_TYPE_STRING) + { return; } gl_view_unselect_all (view); - label = gl_xml_label_open_buffer ((gchar *)selection_data->data, &status); - for (p = label->objects; p != NULL; p = p_next) { + label = gl_xml_label_open_buffer ((gchar *)gtk_selection_data_get_data (sd), &status); + for (p = label->objects; p != NULL; p = p_next) + { p_next = p->next; object = (glLabelObject *) p->data; @@ -3266,13 +3291,18 @@ motion_notify_event_cb (glView *view, GdkEventMotion *event) { gboolean return_value = FALSE; + GdkWindow *bin_window; + GdkWindow *window; cairo_t *cr; gdouble scale; gdouble x, y; GdkCursor *cursor; glViewObjectHandle handle; - cr = gdk_cairo_create (GTK_LAYOUT (view->canvas)->bin_window); + bin_window = gtk_layout_get_bin_window (GTK_LAYOUT (view->canvas)); + window = gtk_widget_get_window (view->canvas); + + cr = gdk_cairo_create (bin_window); /* * Translate to label coordinates @@ -3314,7 +3344,7 @@ motion_notify_event_cb (glView *view, { cursor = gdk_cursor_new (GDK_LEFT_PTR); } - gdk_window_set_cursor (view->canvas->window, cursor); + gdk_window_set_cursor (window, cursor); gdk_cursor_unref (cursor); break; @@ -3399,7 +3429,7 @@ motion_notify_event_cb (glView *view, */ if (view->grabbed_flag && !gdk_pointer_is_grabbed ()) { - gdk_pointer_grab (GTK_LAYOUT (view->canvas)->bin_window, + gdk_pointer_grab (bin_window, FALSE, (GDK_BUTTON1_MOTION_MASK | GDK_BUTTON_RELEASE_MASK), NULL, @@ -3419,13 +3449,16 @@ button_press_event_cb (glView *view, GdkEventButton *event) { gboolean return_value = FALSE; + GdkWindow *bin_window; cairo_t *cr; gdouble scale; gdouble x, y; glViewObject *view_object; glViewObjectHandle handle; - cr = gdk_cairo_create (GTK_LAYOUT (view->canvas)->bin_window); + bin_window = gtk_layout_get_bin_window (GTK_LAYOUT (view->canvas)); + + cr = gdk_cairo_create (bin_window); /* * Translate to label coordinates @@ -3538,7 +3571,7 @@ button_press_event_cb (glView *view, } view->grabbed_flag = TRUE; - gdk_pointer_grab (GTK_LAYOUT (view->canvas)->bin_window, + gdk_pointer_grab (bin_window, FALSE, (GDK_BUTTON1_MOTION_MASK | GDK_BUTTON_RELEASE_MASK), NULL, @@ -3569,12 +3602,17 @@ button_release_event_cb (glView *view, GdkEventButton *event) { gboolean return_value = FALSE; + GdkWindow *bin_window; + GdkWindow *window; cairo_t *cr; gdouble scale; gdouble x, y; GdkCursor *cursor; - cr = gdk_cairo_create (GTK_LAYOUT (view->canvas)->bin_window); + bin_window = gtk_layout_get_bin_window (GTK_LAYOUT (view->canvas)); + window = gtk_widget_get_window (view->canvas); + + cr = gdk_cairo_create (bin_window); /* * Translate to label coordinates @@ -3660,7 +3698,7 @@ button_release_event_cb (glView *view, view->mode = GL_VIEW_MODE_ARROW; view->state = GL_VIEW_IDLE; cursor = gdk_cursor_new (GDK_LEFT_PTR); - gdk_window_set_cursor (view->canvas->window, cursor); + gdk_window_set_cursor (window, cursor); gdk_cursor_unref (cursor); break; @@ -3684,10 +3722,13 @@ static gboolean key_press_event_cb (glView *view, GdkEventKey *event) { + GdkWindow *window; GdkCursor *cursor; gl_debug (DEBUG_VIEW, ""); + window = gtk_widget_get_window (view->canvas); + if ( (view->mode == GL_VIEW_MODE_ARROW) && (view->state == GL_VIEW_IDLE) ) { @@ -3713,8 +3754,7 @@ key_press_event_cb (glView *view, case GDK_KP_Delete: gl_view_delete_selection (view); cursor = gdk_cursor_new (GDK_LEFT_PTR); - gdk_window_set_cursor (GTK_WIDGET (view->canvas)->window -, cursor); + gdk_window_set_cursor (window, cursor); gdk_cursor_unref (cursor); break; default: diff --git a/src/wdgt-chain-button.c b/src/wdgt-chain-button.c index e6cfdfe3..be6ab62d 100644 --- a/src/wdgt-chain-button.c +++ b/src/wdgt-chain-button.c @@ -307,8 +307,8 @@ gl_wdgt_chain_button_draw_lines (GtkWidget *widget, points[2] = buf; } - gtk_paint_polygon (widget->style, - widget->window, + gtk_paint_polygon (gtk_widget_get_style (widget), + gtk_widget_get_window (widget), GTK_STATE_NORMAL, shadow, &eevent->area,