Changeset 12591


Ignore:
Timestamp:
Jul 26, 2011, 1:02:32 AM (10 years ago)
Author:
jordan
Message:

(trunk gtk) #4320 "Port GTK client to GTK 3." -- transmission-gtk now compiles cleanly & runs on GTK 3.

Location:
trunk/gtk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/torrent-cell-renderer.c

    r12464 r12591  
    372372
    373373static void
     374gtr_cell_renderer_get_preferred_size( GtkCellRenderer  * renderer,
     375                                      GtkWidget        * widget,
     376                                      GtkRequisition   * minimum_size,
     377                                      GtkRequisition   * natural_size )
     378{
     379#if GTK_CHECK_VERSION( 3,0,0 )
     380
     381    gtk_cell_renderer_get_preferred_size( renderer, widget, minimum_size, natural_size );
     382
     383#else
     384
     385    GtkRequisition r;
     386    gtk_cell_renderer_get_size( renderer, widget, NULL, NULL, NULL, &r.width, &r.height );
     387    if( minimum_size ) *minimum_size = r;
     388    if( natural_size ) *natural_size = r;
     389
     390#endif
     391}
     392
     393static void
    374394get_size_compact( TorrentCellRenderer * cell,
    375395                  GtkWidget           * widget,
     
    377397                  gint                * height )
    378398{
    379     int w, h;
    380399    int xpad, ypad;
    381     GdkRectangle icon_area;
    382     GdkRectangle name_area;
    383     GdkRectangle stat_area;
     400    GtkRequisition icon_size;
     401    GtkRequisition name_size;
     402    GtkRequisition stat_size;
    384403    const char * name;
    385404    GdkPixbuf * icon;
     
    398417    /* get the idealized cell dimensions */
    399418    g_object_set( p->icon_renderer, "pixbuf", icon, NULL );
    400     gtk_cell_renderer_get_size( p->icon_renderer, widget, NULL, NULL, NULL, &w, &h );
    401     icon_area.width = w;
    402     icon_area.height = h;
     419    gtr_cell_renderer_get_preferred_size( p->icon_renderer, widget, NULL, &icon_size );
    403420    g_object_set( p->text_renderer, "text", name, "ellipsize", PANGO_ELLIPSIZE_NONE,  "scale", 1.0, NULL );
    404     gtk_cell_renderer_get_size( p->text_renderer, widget, NULL, NULL, NULL, &w, &h );
    405     name_area.width = w;
    406     name_area.height = h;
     421    gtr_cell_renderer_get_preferred_size( p->text_renderer, widget, NULL, &name_size );
    407422    g_object_set( p->text_renderer, "text", gstr_stat->str, "scale", SMALL_SCALE, NULL );
    408     gtk_cell_renderer_get_size( p->text_renderer, widget, NULL, NULL, NULL, &w, &h );
    409     stat_area.width = w;
    410     stat_area.height = h;
     423    gtr_cell_renderer_get_preferred_size( p->text_renderer, widget, NULL, &stat_size );
    411424
    412425    /**
     
    416429#define BAR_WIDTH 50
    417430    if( width != NULL )
    418         *width = xpad * 2 + icon_area.width + GUI_PAD + name_area.width + GUI_PAD + BAR_WIDTH + GUI_PAD + stat_area.width;
     431        *width = xpad * 2 + icon_size.width + GUI_PAD + name_size.width + GUI_PAD + BAR_WIDTH + GUI_PAD + stat_size.width;
    419432    if( height != NULL )
    420         *height = ypad * 2 + MAX( name_area.height, p->bar_height );
     433        *height = ypad * 2 + MAX( name_size.height, p->bar_height );
    421434
    422435    /* cleanup */
     
    432445               gint                * height )
    433446{
    434     int w, h;
    435447    int xpad, ypad;
    436     GdkRectangle icon_area;
    437     GdkRectangle name_area;
    438     GdkRectangle stat_area;
    439     GdkRectangle prog_area;
     448    GtkRequisition icon_size;
     449    GtkRequisition name_size;
     450    GtkRequisition stat_size;
     451    GtkRequisition prog_size;
    440452    const char * name;
    441453    GdkPixbuf * icon;
     
    458470    /* get the idealized cell dimensions */
    459471    g_object_set( p->icon_renderer, "pixbuf", icon, NULL );
    460     gtk_cell_renderer_get_size( p->icon_renderer, widget, NULL, NULL, NULL, &w, &h );
    461     icon_area.width = w;
    462     icon_area.height = h;
     472    gtr_cell_renderer_get_preferred_size( p->icon_renderer, widget, NULL, &icon_size );
    463473    g_object_set( p->text_renderer, "text", name, "weight", PANGO_WEIGHT_BOLD, "scale", 1.0, "ellipsize", PANGO_ELLIPSIZE_NONE, NULL );
    464     gtk_cell_renderer_get_size( p->text_renderer, widget, NULL, NULL, NULL, &w, &h );
    465     name_area.width = w;
    466     name_area.height = h;
     474    gtr_cell_renderer_get_preferred_size( p->text_renderer, widget, NULL, &name_size );
    467475    g_object_set( p->text_renderer, "text", gstr_prog->str, "weight", PANGO_WEIGHT_NORMAL, "scale", SMALL_SCALE, NULL );
    468     gtk_cell_renderer_get_size( p->text_renderer, widget, NULL, NULL, NULL, &w, &h );
    469     prog_area.width = w;
    470     prog_area.height = h;
     476    gtr_cell_renderer_get_preferred_size( p->text_renderer, widget, NULL, &prog_size );
    471477    g_object_set( p->text_renderer, "text", gstr_stat->str, NULL );
    472     gtk_cell_renderer_get_size( p->text_renderer, widget, NULL, NULL, NULL, &w, &h );
    473     stat_area.width = w;
    474     stat_area.height = h;
     478    gtr_cell_renderer_get_preferred_size( p->text_renderer, widget, NULL, &stat_size );
    475479
    476480    /**
     
    479483
    480484    if( width != NULL )
    481         *width = xpad * 2 + icon_area.width + GUI_PAD + MAX3( name_area.width, prog_area.width, stat_area.width );
     485        *width = xpad * 2 + icon_size.width + GUI_PAD + MAX3( name_size.width, prog_size.width, stat_size.width );
    482486    if( height != NULL )
    483         *height = ypad * 2 + name_area.height + prog_area.height + GUI_PAD_SMALL + p->bar_height + GUI_PAD_SMALL + stat_area.height;
     487        *height = ypad * 2 + name_size.height + prog_size.height + GUI_PAD_SMALL + p->bar_height + GUI_PAD_SMALL + stat_size.height;
    484488
    485489    /* cleanup */
     
    489493
    490494static void
    491 torrent_cell_renderer_get_size( GtkCellRenderer  * cell,
    492                                 GtkWidget        * widget,
    493                                 GdkRectangle     * cell_area,
    494                                 gint             * x_offset,
    495                                 gint             * y_offset,
    496                                 gint             * width,
    497                                 gint             * height )
     495torrent_cell_renderer_get_size( GtkCellRenderer     * cell,
     496                                GtkWidget           * widget,
     497#if GTK_CHECK_VERSION( 3,0,0 )
     498                                const GdkRectangle  * cell_area,
     499#else
     500                                GdkRectangle        * cell_area,
     501#endif
     502                                gint                * x_offset,
     503                                gint                * y_offset,
     504                                gint                * width,
     505                                gint                * height )
    498506{
    499507    TorrentCellRenderer * self = TORRENT_CELL_RENDERER( cell );
     
    526534}
    527535
    528 static void
    529 get_text_color( GtkWidget * w, const tr_stat * st, GdkColor * setme )
    530 {
     536#if GTK_CHECK_VERSION( 3,0,0 )
     537    typedef GdkRGBA GtrColor;
     538    #define FOREGROUND_COLOR_KEY "foreground-rgba"
     539#else
     540    typedef GdkColor GtrColor;
     541    #define FOREGROUND_COLOR_KEY "foreground-gdk"
     542#endif
     543
     544static void
     545get_text_color( GtkWidget * w, const tr_stat * st, GtrColor * setme )
     546{
     547#if GTK_CHECK_VERSION( 3,0,0 )
     548
     549    static const GdkRGBA red = { 1.0, 0, 0, 0 };
     550    if( st->error )
     551        *setme = red;
     552    else if( st->activity == TR_STATUS_STOPPED )
     553        gtk_style_context_get_color( gtk_widget_get_style_context( w ), GTK_STATE_FLAG_INSENSITIVE, setme );
     554    else
     555        gtk_style_context_get_color( gtk_widget_get_style_context( w ), GTK_STATE_FLAG_NORMAL, setme );
     556
     557#else
     558
    531559    static const GdkColor red = { 0, 65535, 0, 0 };
    532 
    533560    if( st->error )
    534561        *setme = red;
     
    537564    else
    538565        *setme = gtk_widget_get_style(w)->text[GTK_STATE_NORMAL];
    539 }
     566
     567#endif
     568}
     569
    540570
    541571static double
     
    558588}
    559589
     590#if GTK_CHECK_VERSION( 3,0,0 )
     591    typedef cairo_t GtrDrawable;
     592#else
     593    typedef GdkDrawable GtrDrawable;
     594#endif
     595
     596static void
     597gtr_cell_renderer_render( GtkCellRenderer       * renderer,
     598                          GtrDrawable           * drawable,
     599                          GtkWidget             * widget,
     600                          const GdkRectangle    * area,
     601                          GtkCellRendererState    flags)
     602{
     603#if GTK_CHECK_VERSION( 3,0,0 )
     604    gtk_cell_renderer_render( renderer, drawable, widget, area, area, flags );
     605#else
     606    gtk_cell_renderer_render( renderer, drawable, widget, area, area, area, flags );
     607#endif
     608}
     609
    560610static void
    561611render_compact( TorrentCellRenderer   * cell,
    562                 GdkDrawable           * window,
     612                GtrDrawable           * window,
    563613                GtkWidget             * widget,
    564                 GdkRectangle          * background_area,
    565                 GdkRectangle          * cell_area UNUSED,
    566                 GdkRectangle          * expose_area UNUSED,
     614                const GdkRectangle    * background_area,
     615                const GdkRectangle    * cell_area UNUSED,
    567616                GtkCellRendererState    flags )
    568617{
    569618    int xpad, ypad;
     619    GtkRequisition size;
    570620    GdkRectangle icon_area;
    571621    GdkRectangle name_area;
     
    575625    const char * name;
    576626    GdkPixbuf * icon;
    577     GdkColor text_color;
     627    GtrColor text_color;
    578628    bool seed;
    579629
     
    601651
    602652    g_object_set( p->icon_renderer, "pixbuf", icon, NULL );
    603     gtk_cell_renderer_get_size( p->icon_renderer, widget, NULL, NULL, NULL, &icon_area.width, NULL );
     653    gtr_cell_renderer_get_preferred_size( p->icon_renderer, widget, NULL, &size );
     654    icon_area.width = size.width;
    604655    g_object_set( p->text_renderer, "text", name, "ellipsize", PANGO_ELLIPSIZE_NONE, "scale", 1.0, NULL );
    605     gtk_cell_renderer_get_size( p->text_renderer, widget, NULL, NULL, NULL, &name_area.width, NULL );
     656    gtr_cell_renderer_get_preferred_size( p->text_renderer, widget, NULL, &size );
     657    name_area.width = size.width;
    606658    g_object_set( p->text_renderer, "text", gstr_stat->str, "scale", SMALL_SCALE, NULL );
    607     gtk_cell_renderer_get_size( p->text_renderer, widget, NULL, NULL, NULL, &stat_area.width, NULL );
     659    gtr_cell_renderer_get_preferred_size( p->text_renderer, widget, NULL, &size );
     660    stat_area.width = size.width;
    608661
    609662    icon_area.x = fill_area.x;
     
    620673
    621674    g_object_set( p->icon_renderer, "pixbuf", icon, "sensitive", sensitive, NULL );
    622     gtk_cell_renderer_render( p->icon_renderer, window, widget, &icon_area, &icon_area, &icon_area, flags );
     675    gtr_cell_renderer_render( p->icon_renderer, window, widget, &icon_area, flags );
    623676    g_object_set( p->progress_renderer, "value", (int)(percentDone*100.0), "text", NULL, "sensitive", sensitive,
    624677#if GTK_CHECK_VERSION( 3,0,0 )
     
    628681#endif
    629682        NULL );
    630     gtk_cell_renderer_render( p->progress_renderer, window, widget, &prog_area, &prog_area, &prog_area, flags );
    631     g_object_set( p->text_renderer, "text", gstr_stat->str, "scale", SMALL_SCALE, "ellipsize", PANGO_ELLIPSIZE_END, "foreground-gdk", &text_color, NULL );
    632     gtk_cell_renderer_render( p->text_renderer, window, widget, &stat_area, &stat_area, &stat_area, flags );
     683    gtr_cell_renderer_render( p->progress_renderer, window, widget, &prog_area, flags );
     684    g_object_set( p->text_renderer, "text", gstr_stat->str, "scale", SMALL_SCALE, "ellipsize", PANGO_ELLIPSIZE_END, FOREGROUND_COLOR_KEY, &text_color, NULL );
     685    gtr_cell_renderer_render( p->text_renderer, window, widget, &stat_area, flags );
    633686    g_object_set( p->text_renderer, "text", name, "scale", 1.0, NULL );
    634     gtk_cell_renderer_render( p->text_renderer, window, widget, &name_area, &name_area, &name_area, flags );
     687    gtr_cell_renderer_render( p->text_renderer, window, widget, &name_area, flags );
    635688
    636689    /* cleanup */
     
    640693static void
    641694render_full( TorrentCellRenderer   * cell,
    642              GdkDrawable           * window,
     695             GtrDrawable           * window,
    643696             GtkWidget             * widget,
    644              GdkRectangle          * background_area,
    645              GdkRectangle          * cell_area UNUSED,
    646              GdkRectangle          * expose_area UNUSED,
     697             const GdkRectangle    * background_area,
     698             const GdkRectangle    * cell_area UNUSED,
    647699             GtkCellRendererState    flags )
    648700{
    649     int w, h;
    650701    int xpad, ypad;
     702    GtkRequisition size;
    651703    GdkRectangle fill_area;
    652704    GdkRectangle icon_area;
     
    657709    const char * name;
    658710    GdkPixbuf * icon;
    659     GdkColor text_color;
     711    GtrColor text_color;
    660712    bool seed;
    661713
     
    681733    /* get the idealized cell dimensions */
    682734    g_object_set( p->icon_renderer, "pixbuf", icon, NULL );
    683     gtk_cell_renderer_get_size( p->icon_renderer, widget, NULL, NULL, NULL, &w, &h );
    684     icon_area.width = w;
    685     icon_area.height = h;
     735    gtr_cell_renderer_get_preferred_size( p->icon_renderer, widget, NULL, &size );
     736    icon_area.width = size.width;
     737    icon_area.height = size.height;
    686738    g_object_set( p->text_renderer, "text", name, "weight", PANGO_WEIGHT_BOLD, "ellipsize", PANGO_ELLIPSIZE_NONE, "scale", 1.0, NULL );
    687     gtk_cell_renderer_get_size( p->text_renderer, widget, NULL, NULL, NULL, &w, &h );
    688     name_area.width = w;
    689     name_area.height = h;
     739    gtr_cell_renderer_get_preferred_size( p->text_renderer, widget, NULL, &size );
     740    name_area.width = size.width;
     741    name_area.height = size.height;
    690742    g_object_set( p->text_renderer, "text", gstr_prog->str, "weight", PANGO_WEIGHT_NORMAL, "scale", SMALL_SCALE, NULL );
    691     gtk_cell_renderer_get_size( p->text_renderer, widget, NULL, NULL, NULL, &w, &h );
    692     prog_area.width = w;
    693     prog_area.height = h;
     743    gtr_cell_renderer_get_preferred_size( p->text_renderer, widget, NULL, &size );
     744    prog_area.width = size.width;
     745    prog_area.height = size.height;
    694746    g_object_set( p->text_renderer, "text", gstr_stat->str, NULL );
    695     gtk_cell_renderer_get_size( p->text_renderer, widget, NULL, NULL, NULL, &w, &h );
    696     stat_area.width = w;
    697     stat_area.height = h;
     747    gtr_cell_renderer_get_preferred_size( p->text_renderer, widget, NULL, &size );
     748    stat_area.width = size.width;
     749    stat_area.height = size.height;
    698750
    699751    /**
     
    737789
    738790    g_object_set( p->icon_renderer, "pixbuf", icon, "sensitive", sensitive, NULL );
    739     gtk_cell_renderer_render( p->icon_renderer, window, widget, &icon_area, &icon_area, &icon_area, flags );
    740     g_object_set( p->text_renderer, "text", name, "scale", 1.0, "foreground-gdk", &text_color, "ellipsize", PANGO_ELLIPSIZE_END, "weight", PANGO_WEIGHT_BOLD, NULL );
    741     gtk_cell_renderer_render( p->text_renderer, window, widget, &name_area, &name_area, &name_area, flags );
     791    gtr_cell_renderer_render( p->icon_renderer, window, widget, &icon_area, flags );
     792    g_object_set( p->text_renderer, "text", name, "scale", 1.0, FOREGROUND_COLOR_KEY, &text_color, "ellipsize", PANGO_ELLIPSIZE_END, "weight", PANGO_WEIGHT_BOLD, NULL );
     793    gtr_cell_renderer_render( p->text_renderer, window, widget, &name_area, flags );
    742794    g_object_set( p->text_renderer, "text", gstr_prog->str, "scale", SMALL_SCALE, "weight", PANGO_WEIGHT_NORMAL, NULL );
    743     gtk_cell_renderer_render( p->text_renderer, window, widget, &prog_area, &prog_area, &prog_area, flags );
     795    gtr_cell_renderer_render( p->text_renderer, window, widget, &prog_area, flags );
    744796    g_object_set( p->progress_renderer, "value", (int)(percentDone*100.0), "text", "", "sensitive", sensitive,
    745797#if GTK_CHECK_VERSION( 3,0,0 )
     
    749801#endif
    750802        NULL );
    751     gtk_cell_renderer_render( p->progress_renderer, window, widget, &prct_area, &prct_area, &prct_area, flags );
     803    gtr_cell_renderer_render( p->progress_renderer, window, widget, &prct_area, flags );
    752804    g_object_set( p->text_renderer, "text", gstr_stat->str, NULL );
    753     gtk_cell_renderer_render( p->text_renderer, window, widget, &stat_area, &stat_area, &stat_area, flags );
     805    gtr_cell_renderer_render( p->text_renderer, window, widget, &stat_area, flags );
    754806
    755807    /* cleanup */
     
    759811static void
    760812torrent_cell_renderer_render( GtkCellRenderer       * cell,
    761                               GdkDrawable           * window,
     813                              GtrDrawable           * window,
    762814                              GtkWidget             * widget,
     815#if GTK_CHECK_VERSION( 3,0,0 )
     816                              const GdkRectangle    * background_area,
     817                              const GdkRectangle    * cell_area,
     818#else
    763819                              GdkRectangle          * background_area,
    764820                              GdkRectangle          * cell_area,
    765                               GdkRectangle          * expose_area,
     821                              GdkRectangle          * expose_area UNUSED,
     822#endif
    766823                              GtkCellRendererState    flags )
    767824{
     
    777834        struct TorrentCellRendererPrivate * p = self->priv;
    778835        if( p->compact )
    779             render_compact( self, window, widget, background_area, cell_area, expose_area, flags );
     836            render_compact( self, window, widget, background_area, cell_area, flags );
    780837        else
    781             render_full( self, window, widget, background_area, cell_area, expose_area, flags );
     838            render_full( self, window, widget, background_area, cell_area, flags );
    782839    }
    783840
  • trunk/gtk/tr-window.c

    r12412 r12591  
    172172         * its fixed-height mode values. Unfortunately there's not an API call
    173173         * for that, but it *does* revalidate when it thinks the style's been tweaked */
     174#if GTK_CHECK_VERSION( 3,0,0 )
     175        g_signal_emit_by_name( p->view, "style-updated", NULL, NULL );
     176#else
    174177        g_signal_emit_by_name( p->view, "style-set", NULL, NULL );
     178#endif
    175179    }
    176180    else if( !strcmp( key, PREF_KEY_STATUSBAR ) )
Note: See TracChangeset for help on using the changeset viewer.