Changeset 1647


Ignore:
Timestamp:
Apr 3, 2007, 8:18:53 AM (15 years ago)
Author:
joshe
Message:

Make evil initial window sizing magic a bit less evil and a bit less magic.

Location:
trunk/gtk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/dialogs.c

    r1633 r1647  
    9090stylekludge( GObject * obj, GParamSpec * spec, gpointer data );
    9191static void
    92 setscroll( void * arg );
    93 static void
    94 fileswindresp( GtkWidget * widget, gint resp, gpointer data );
     92fileswinddead( GtkWidget * widget, gpointer data );
    9593static void
    9694filestorclosed( gpointer data, GObject * tor );
     
    428426    int                 ii;
    429427    GtkWidget         * view, * scroll, * frame, * wind;
    430     GtkCellRenderer   * rend;
     428    GtkCellRenderer   * rend, * elip;
    431429    GtkTreeViewColumn * col;
    432430    GtkTreeSelection  * sel;
     
    452450    /* add file column */
    453451    col = gtk_tree_view_column_new();
     452    gtk_tree_view_column_set_expand( col, TRUE );
     453    gtk_tree_view_column_set_sizing( col, GTK_TREE_VIEW_COLUMN_AUTOSIZE );
    454454    gtk_tree_view_column_set_title( col, _("File") );
    455455    /* add icon renderer */
     
    459459    /* add text renderer */
    460460    rend = gtk_cell_renderer_text_new();
     461    elip = rend;
    461462    gtk_tree_view_column_pack_start( col, rend, TRUE );
    462463    gtk_tree_view_column_add_attribute( col, rend, "markup", FC_LABEL );
     
    484485    /* create the scrolled window and stick the view in it */
    485486    scroll = gtk_scrolled_window_new( NULL, NULL );
    486     gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scroll ),
    487                                     GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC );
    488487    gtk_container_add( GTK_CONTAINER( scroll ), view );
    489488    gtk_widget_show( scroll );
     
    517516
    518517    g_object_weak_ref( G_OBJECT( tor ), filestorclosed, fw );
    519     g_signal_connect( wind, "response", G_CALLBACK( fileswindresp ), fw );
     518    g_signal_connect( wind, "destroy", G_CALLBACK( fileswinddead ), fw );
     519    g_signal_connect( wind, "response", G_CALLBACK( gtk_widget_destroy ), 0 );
    520520    fileswindupdate( fw );
    521521
    522     /* show the window with a nice initial size */
    523     windowsizehack( wind, scroll, view, setscroll, scroll );
     522    sizingmagic( GTK_WINDOW( wind ), GTK_SCROLLED_WINDOW( scroll ),
     523                 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC );
     524    g_object_set( elip, "ellipsize", PANGO_ELLIPSIZE_END, NULL );
     525    gtk_widget_show( wind );
    524526}
    525527
     
    538540
    539541static void
    540 setscroll( void * arg )
    541 {
    542     gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( arg ),
    543         GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC );
    544 }
    545 
    546 static void
    547 fileswindresp( GtkWidget * widget SHUTUP, gint resp SHUTUP, gpointer data )
     542fileswinddead( GtkWidget * widget SHUTUP, gpointer data )
    548543{
    549544    struct fileswind * fw = data;
  • trunk/gtk/main.c

    r1615 r1647  
    424424    updatemodel( cbdata );
    425425
    426     /* this shows the window */
    427     tr_window_size_hack( wind );
    428 
    429426    /* set up the ipc socket now that we're ready to get torrents from it */
    430427    ipc_socket_setup( GTK_WINDOW( wind ), addtorrents, wannaquit, cbdata );
     428
     429    /* show the window */
     430    tr_window_show( wind );
    431431}
    432432
     
    470470    win = tr_window_new();
    471471    winsetup( cbdata, TR_WINDOW( win ) );
    472 
    473     /* this shows the window */
    474     tr_window_size_hack( TR_WINDOW( win ) );
     472    tr_window_show( TR_WINDOW( win ) );
    475473}
    476474
  • trunk/gtk/tr_window.c

    r1587 r1647  
    4040{
    4141    PROP_MODEL = 1,
    42     PROP_ELLIPSIZE,
    4342    PROP_SELECTION,
    4443    PROP_DOUBLECLICK,
     
    133132    g_object_class_install_property( gobject_class, PROP_MODEL, pspec );
    134133
    135     pspec = g_param_spec_boolean( "ellipsize", _("Ellipsize"),
    136                                  _("Ellipsize torrent names."),
    137                                  FALSE, G_PARAM_READWRITE );
    138     g_object_class_install_property( gobject_class, PROP_ELLIPSIZE, pspec );
    139 
    140134    pspec = g_param_spec_object( "selection", _("Selection"),
    141135                                 _("The GtkTreeSelection for the list view."),
     
    200194                        FALSE, FALSE, 0 );
    201195
    202     gtk_scrolled_window_set_policy( self->scroll,
    203                                     GTK_POLICY_NEVER, GTK_POLICY_ALWAYS );
    204196    gtk_container_add( GTK_CONTAINER( scroll ), GTK_WIDGET( self->view ) );
    205197    gtk_box_pack_start( GTK_BOX( vbox ), scroll, TRUE, TRUE, 0 );
     
    221213{
    222214    TrWindow         * self = ( TrWindow * )object;
    223     PangoEllipsizeMode elip;
    224215
    225216    if( self->disposed )
     
    232223        case PROP_MODEL:
    233224            gtk_tree_view_set_model( self->view, g_value_get_object( value ) );
    234             break;
    235         case PROP_ELLIPSIZE:
    236             g_assert( NULL != self->namerend );
    237             elip = ( g_value_get_boolean( value ) ?
    238                      PANGO_ELLIPSIZE_END : PANGO_ELLIPSIZE_NONE );
    239             g_object_set( self->namerend, "ellipsize", elip, NULL );
    240225            break;
    241226        case PROP_DOUBLECLICK:
     
    253238{
    254239    TrWindow         * self = ( TrWindow * )object;
    255     PangoEllipsizeMode elip;
    256240
    257241    if( self->disposed )
     
    264248        case PROP_MODEL:
    265249            g_value_set_object( value, gtk_tree_view_get_model( self->view ) );
    266             break;
    267         case PROP_ELLIPSIZE:
    268             g_assert( NULL != self->namerend );
    269             g_object_get( self->namerend, "ellipsize", &elip, NULL);
    270             g_value_set_boolean( value, ( PANGO_ELLIPSIZE_NONE != elip ) );
    271250            break;
    272251        case PROP_SELECTION:
     
    386365}
    387366
    388 static void
    389 setelip( void * arg )
    390 {
    391     g_object_set( arg, "ellipsize", TRUE, NULL );
    392 }
    393 
    394367void
    395 tr_window_size_hack( TrWindow * self )
     368tr_window_show( TrWindow * self )
    396369{
    397370    TR_IS_WINDOW( self );
    398371
    399     windowsizehack( GTK_WIDGET( self ), GTK_WIDGET( self->scroll ),
    400                     GTK_WIDGET( self->view ), setelip, self );
     372    sizingmagic( GTK_WINDOW( self ), self->scroll,
     373                 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS );
     374    g_object_set( self->namerend, "ellipsize", PANGO_ELLIPSIZE_END, NULL );
     375    gtk_widget_show( GTK_WIDGET( self ) );
    401376}
    402377
  • trunk/gtk/tr_window.h

    r1515 r1647  
    8585tr_window_update( TrWindow * wind, float downspeed, float upspeed );
    8686
    87 /* some evil magic to show the window with a nice initial window size */
    88 /* note that the gtk main loop runs in this function */
     87/* some magic to show the window with a nice initial size */
    8988void
    90 tr_window_size_hack( TrWindow * wind );
     89tr_window_show( TrWindow * wind );
    9190
    9291#endif
  • trunk/gtk/util.c

    r1605 r1647  
    318318
    319319void
    320 windowsizehack( GtkWidget * wind, GtkWidget * scroll, GtkWidget * view,
    321                 callbackfunc_t func, void * arg )
     320sizingmagic( GtkWindow * wind, GtkScrolledWindow * scroll,
     321             GtkPolicyType hscroll, GtkPolicyType vscroll )
    322322{
    323323    GtkRequisition req;
    324     gint           width, height;
    325324    GdkScreen    * screen;
    326 
    327     gtk_widget_realize( wind );
    328     gtk_widget_size_request( view, &req );
    329     height = req.height;
    330     gtk_widget_size_request( scroll, &req );
    331     height -= req.height;
    332     gtk_widget_size_request( wind, &req );
    333     height += req.height;
    334     screen  = gtk_widget_get_screen( wind );
    335     width   = MIN( req.width, gdk_screen_get_width( screen  ) / 2 );
    336     height  = MIN( height,    gdk_screen_get_height( screen ) / 5 * 4 );
    337     if( height > req.width )
    338     {
    339         height = MIN( height, width * 8 / 5 );
    340     }
    341     else
    342     {
    343         height = MAX( height, width * 5 / 8 );
    344     }
    345     if( height > req.width )
    346     {
    347         height = MIN( height, width * 8 / 5 );
    348     }
    349     else
    350     {
    351         height = MAX( height, width * 5 / 8 );
    352     }
    353     if( NULL != func )
    354     {
    355         func( arg );
    356     }
    357     gtk_widget_show_now( wind  );
    358     gtk_window_resize( GTK_WINDOW( wind ), width, height );
    359     gtk_window_set_focus( GTK_WINDOW( wind ), NULL );
     325    int            width, height;
     326
     327    screen = gtk_widget_get_screen( GTK_WIDGET( wind ) );
     328
     329    gtk_scrolled_window_set_policy( scroll, GTK_POLICY_NEVER,
     330                                    GTK_POLICY_NEVER );
     331
     332    gtk_widget_size_request( GTK_WIDGET( wind ), &req );
     333    height = MIN( req.height, gdk_screen_get_height( screen ) / 5 * 4 );
     334
     335    gtk_scrolled_window_set_policy( scroll, GTK_POLICY_NEVER, vscroll );
     336
     337    gtk_widget_size_request( GTK_WIDGET( wind ), &req );
     338    width = MIN( req.width, gdk_screen_get_width( screen ) / 2 );
     339
     340    gtk_window_set_default_size( wind, width, height );
     341
     342    gtk_scrolled_window_set_policy( scroll, hscroll, vscroll );
    360343}
    361344
  • trunk/gtk/util.h

    r1605 r1647  
    154154/* here there be dragons */
    155155void
    156 windowsizehack( GtkWidget * wind, GtkWidget * scroll, GtkWidget * view,
    157                 callbackfunc_t func, void * arg );
     156sizingmagic( GtkWindow * wind, GtkScrolledWindow * scroll,
     157             GtkPolicyType hscroll, GtkPolicyType vscroll );
    158158
    159159/* create an error dialog, if wind is NULL or mapped then show dialog now,
Note: See TracChangeset for help on using the changeset viewer.