(trunk gtk) #3847 "GTK+ 3 transition: Use accessor functions instead direct access" -- don't directly access GtkCellRenderer.xpad, GtkCellRenderer.ypad, or GtkWidget.window.

This commit is contained in:
Charles Kerr 2010-12-24 09:04:52 +00:00
parent ae84dc70dd
commit f5b13c46dc
5 changed files with 60 additions and 22 deletions

View File

@ -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 );

View File

@ -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;

View File

@ -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 )

View File

@ -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 )
{

View File

@ -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 );