From f5b13c46dc6eaf762db2910460033fdfde14f4ec Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 24 Dec 2010 09:04:52 +0000 Subject: [PATCH] (trunk gtk) #3847 "GTK+ 3 transition: Use accessor functions instead direct access" -- don't directly access GtkCellRenderer.xpad, GtkCellRenderer.ypad, or GtkWidget.window. --- gtk/main.c | 12 +++++------ gtk/torrent-cell-renderer.c | 41 +++++++++++++++++++++++-------------- gtk/tr-window.c | 2 +- gtk/util.c | 21 +++++++++++++++++++ gtk/util.h | 6 ++++++ 5 files changed, 60 insertions(+), 22 deletions(-) diff --git a/gtk/main.c b/gtk/main.c index 67e4210f7..31542da33 100644 --- a/gtk/main.c +++ b/gtk/main.c @@ -400,21 +400,21 @@ registerMagnetLinkHandler( void ) } static void -onMainWindowSizeAllocated( GtkWidget * window, +onMainWindowSizeAllocated( GtkWidget * gtk_window, GtkAllocation * alloc UNUSED, gpointer gdata UNUSED ) { - const gboolean isMaximized = window->window - && ( gdk_window_get_state( window->window ) - & GDK_WINDOW_STATE_MAXIMIZED ); + GdkWindow * gdk_window = gtr_widget_get_window( gtk_window ); + const gboolean isMaximized = ( gdk_window != NULL ) + && ( gdk_window_get_state( gdk_window ) & GDK_WINDOW_STATE_MAXIMIZED ); gtr_pref_int_set( PREF_KEY_MAIN_WINDOW_IS_MAXIMIZED, isMaximized ); if( !isMaximized ) { int x, y, w, h; - gtk_window_get_position( GTK_WINDOW( window ), &x, &y ); - gtk_window_get_size( GTK_WINDOW( window ), &w, &h ); + gtk_window_get_position( GTK_WINDOW( gtk_window ), &x, &y ); + gtk_window_get_size( GTK_WINDOW( gtk_window ), &w, &h ); gtr_pref_int_set( PREF_KEY_MAIN_WINDOW_X, x ); gtr_pref_int_set( PREF_KEY_MAIN_WINDOW_Y, y ); gtr_pref_int_set( PREF_KEY_MAIN_WINDOW_WIDTH, w ); diff --git a/gtk/torrent-cell-renderer.c b/gtk/torrent-cell-renderer.c index 002bb1573..94ef0064c 100644 --- a/gtk/torrent-cell-renderer.c +++ b/gtk/torrent-cell-renderer.c @@ -383,6 +383,7 @@ get_size_compact( TorrentCellRenderer * cell, gint * height ) { int w, h; + int xpad, ypad; GdkRectangle icon_area; GdkRectangle name_area; GdkRectangle stat_area; @@ -398,6 +399,7 @@ get_size_compact( TorrentCellRenderer * cell, icon = get_icon( tor, COMPACT_ICON_SIZE, widget ); name = tr_torrentInfo( tor )->name; status = getShortStatusString( tor, st, p->upload_speed_KBps, p->download_speed_KBps ); + gtr_cell_renderer_get_padding( &cell->parent, &xpad, &ypad ); /* get the idealized cell dimensions */ g_object_set( p->icon_renderer, "pixbuf", icon, NULL ); @@ -420,9 +422,9 @@ get_size_compact( TorrentCellRenderer * cell, #define BAR_WIDTH 50 if( width != NULL ) - *width = cell->parent.xpad * 2 + icon_area.width + GUI_PAD + name_area.width + GUI_PAD + BAR_WIDTH + GUI_PAD + stat_area.width; + *width = xpad * 2 + icon_area.width + GUI_PAD + name_area.width + GUI_PAD + BAR_WIDTH + GUI_PAD + stat_area.width; if( height != NULL ) - *height = cell->parent.ypad * 2 + MAX( name_area.height, p->bar_height ); + *height = ypad * 2 + MAX( name_area.height, p->bar_height ); /* cleanup */ g_free( status ); @@ -438,6 +440,7 @@ get_size_full( TorrentCellRenderer * cell, gint * height ) { int w, h; + int xpad, ypad; GdkRectangle icon_area; GdkRectangle name_area; GdkRectangle stat_area; @@ -457,6 +460,7 @@ get_size_full( TorrentCellRenderer * cell, name = inf->name; status = getStatusString( tor, st, p->upload_speed_KBps, p->download_speed_KBps ); progress = getProgressString( tor, inf, st ); + gtr_cell_renderer_get_padding( &cell->parent, &xpad, &ypad ); /* get the idealized cell dimensions */ g_object_set( p->icon_renderer, "pixbuf", icon, NULL ); @@ -482,9 +486,9 @@ get_size_full( TorrentCellRenderer * cell, **/ if( width != NULL ) - *width = cell->parent.xpad * 2 + icon_area.width + GUI_PAD + MAX3( name_area.width, prog_area.width, stat_area.width ); + *width = xpad * 2 + icon_area.width + GUI_PAD + MAX3( name_area.width, prog_area.width, stat_area.width ); if( height != NULL ) - *height = cell->parent.ypad * 2 + name_area.height + prog_area.height + GUI_PAD_SMALL + p->bar_height + GUI_PAD_SMALL + stat_area.height; + *height = ypad * 2 + name_area.height + prog_area.height + GUI_PAD_SMALL + p->bar_height + GUI_PAD_SMALL + stat_area.height; /* cleanup */ g_free( status ); @@ -506,8 +510,8 @@ torrent_cell_renderer_get_size( GtkCellRenderer * cell, if( self && self->priv->tor ) { - struct TorrentCellRendererPrivate * p = self->priv; int w, h; + struct TorrentCellRendererPrivate * p = self->priv; if( p->compact ) get_size_compact( TORRENT_CELL_RENDERER( cell ), widget, &w, &h ); @@ -523,8 +527,11 @@ torrent_cell_renderer_get_size( GtkCellRenderer * cell, if( x_offset ) *x_offset = cell_area ? cell_area->x : 0; - if( y_offset ) - *y_offset = cell_area ? (int)((cell_area->height - (cell->ypad*2 +h)) / 2.0) : 0; + if( y_offset ) { + int xpad, ypad; + gtr_cell_renderer_get_padding( cell, &xpad, &ypad ); + *y_offset = cell_area ? (int)((cell_area->height - (ypad*2 +h)) / 2.0) : 0; + } } } @@ -537,6 +544,7 @@ render_compact( TorrentCellRenderer * cell, GdkRectangle * expose_area UNUSED, GtkCellRendererState flags ) { + int xpad, ypad; GdkRectangle icon_area; GdkRectangle name_area; GdkRectangle stat_area; @@ -557,12 +565,13 @@ render_compact( TorrentCellRenderer * cell, icon = get_icon( tor, COMPACT_ICON_SIZE, widget ); name = tr_torrentInfo( tor )->name; status = getShortStatusString( tor, st, p->upload_speed_KBps, p->download_speed_KBps ); + gtr_cell_renderer_get_padding( &cell->parent, &xpad, &ypad ); fill_area = *background_area; - fill_area.x += cell->parent.xpad; - fill_area.y += cell->parent.ypad; - fill_area.width -= cell->parent.xpad * 2; - fill_area.height -= cell->parent.ypad * 2; + fill_area.x += xpad; + fill_area.y += ypad; + fill_area.width -= xpad * 2; + fill_area.height -= ypad * 2; icon_area = name_area = stat_area = prog_area = fill_area; g_object_set( p->icon_renderer, "pixbuf", icon, NULL ); @@ -609,6 +618,7 @@ render_full( TorrentCellRenderer * cell, GtkCellRendererState flags ) { int w, h; + int xpad, ypad; GdkRectangle fill_area; GdkRectangle icon_area; GdkRectangle name_area; @@ -633,6 +643,7 @@ render_full( TorrentCellRenderer * cell, name = inf->name; status = getStatusString( tor, st, p->upload_speed_KBps, p->download_speed_KBps ); progress = getProgressString( tor, inf, st ); + gtr_cell_renderer_get_padding( &cell->parent, &xpad, &ypad ); /* get the idealized cell dimensions */ g_object_set( p->icon_renderer, "pixbuf", icon, NULL ); @@ -658,10 +669,10 @@ render_full( TorrentCellRenderer * cell, **/ fill_area = *background_area; - fill_area.x += cell->parent.xpad; - fill_area.y += cell->parent.ypad; - fill_area.width -= cell->parent.xpad * 2; - fill_area.height -= cell->parent.ypad * 2; + fill_area.x += xpad; + fill_area.y += ypad; + fill_area.width -= xpad * 2; + fill_area.height -= ypad * 2; /* icon */ icon_area.x = fill_area.x; diff --git a/gtk/tr-window.c b/gtk/tr-window.c index a3a0a4e28..289834dc8 100644 --- a/gtk/tr-window.c +++ b/gtk/tr-window.c @@ -869,7 +869,7 @@ gtr_window_set_busy( TrWindow * w, gboolean isBusy ) GdkDisplay * display = gtk_widget_get_display( GTK_WIDGET( w ) ); GdkCursor * cursor = isBusy ? gdk_cursor_new_for_display( display, GDK_WATCH ) : NULL; - gdk_window_set_cursor( GTK_WIDGET(w)->window, cursor ); + gdk_window_set_cursor( gtr_widget_get_window( GTK_WIDGET( w ) ), cursor ); gdk_display_flush( display ); if( cursor ) diff --git a/gtk/util.c b/gtk/util.c index 62fdd8a40..bdc21d2ed 100644 --- a/gtk/util.c +++ b/gtk/util.c @@ -715,6 +715,16 @@ gtr_widget_set_tooltip_text( GtkWidget * w, const char * tip ) #endif } +GdkWindow* +gtr_widget_get_window( GtkWidget * w ) +{ +#if GTK_CHECK_VERSION( 2,14,0 ) + return gtk_widget_get_window( w ); +#else + return w->window; +#endif +} + gboolean gtr_widget_get_realized( GtkWidget * w ) { @@ -753,6 +763,17 @@ gtr_widget_set_visible( GtkWidget * w, gboolean b ) #endif } +void +gtr_cell_renderer_get_padding( GtkCellRenderer * cell, gint * xpad, gint * ypad ) +{ +#if GTK_CHECK_VERSION( 2,18,0 ) + gtk_cell_renderer_get_padding( cell, xpad, ypad ); +#else + if( xpad != NULL ) *xpad = cell->xpad; + if( ypad != NULL ) *ypad = cell->ypad; +#endif +} + static GtkWidget* gtr_dialog_get_content_area( GtkDialog * dialog ) { diff --git a/gtk/util.h b/gtk/util.h index 06ca86ff2..33f89dcfe 100644 --- a/gtk/util.h +++ b/gtk/util.h @@ -136,12 +136,18 @@ guint gtr_idle_add( GSourceFunc func, gpointer data ); /* backwards-compatible wrapper around gtk_widget_set_tooltip_text() */ void gtr_widget_set_tooltip_text( GtkWidget * w, const char * tip ); +/* backwards-compatible wrapper around gtk_widget_get_window() */ +GdkWindow* gtr_widget_get_window( GtkWidget * w ); + /* backwards-compatible wrapper around gtk_widget_get_realized() */ gboolean gtr_widget_get_realized( GtkWidget * w ); /* backwards-compatible wrapper around gtk_widget_set_visible() */ void gtr_widget_set_visible( GtkWidget *, gboolean ); +/* backwards-compatible wrapper around gtk_cell_renderer_get_padding() */ +void gtr_cell_renderer_get_padding( GtkCellRenderer *, gint * xpad, gint * ypad ); + /* backwards-compatible wrapper around g_object_ref_sink() */ gpointer gtr_object_ref_sink( gpointer object );