~ubuntu-branches/ubuntu/vivid/nip2/vivid-proposed

« back to all changes in this revision

Viewing changes to src/boxes.c

  • Committer: Bazaar Package Importer
  • Author(s): Jay Berkenbilt
  • Date: 2010-12-27 14:53:08 UTC
  • mfrom: (2.1.12 sid)
  • Revision ID: james.westby@ubuntu.com-20101227145308-vampjbuuft281j3l
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
228
228
 
229
229
/* Pop up a `save'/`don't save'/`cancel' dialog.
230
230
 */
231
 
/*VARARGS3*/
232
231
void
233
232
box_savenosave( GtkWidget *par, 
234
233
        iWindowFn save, iWindowFn nosave, void *client,   /* Call client */
1467
1466
static void
1468
1467
infobar_init( Infobar *infobar )
1469
1468
{
1470
 
        infobar->label = NULL;
 
1469
        infobar->top = NULL;
 
1470
        infobar->sub = NULL;
1471
1471
        infobar->close_timeout = 0;
1472
1472
        infobar->close_animation_timeout = 0;
1473
1473
        infobar->height = 0;
1499
1499
}
1500
1500
 
1501
1501
static void
 
1502
infobar_cancel_close( Infobar *infobar )
 
1503
{
 
1504
        IM_FREEF( g_source_remove, infobar->close_timeout );
 
1505
        IM_FREEF( g_source_remove, infobar->close_animation_timeout );
 
1506
        gtk_widget_set_size_request( GTK_WIDGET( infobar ), -1, -1 );
 
1507
}
 
1508
 
 
1509
static void
1502
1510
infobar_hide( Infobar *infobar )
1503
1511
{
1504
 
        IM_FREEF( g_source_remove, infobar->close_animation_timeout );
1505
 
        IM_FREEF( g_source_remove, infobar->close_timeout );
1506
 
 
 
1512
        infobar_cancel_close( infobar );
1507
1513
        gtk_widget_hide( GTK_WIDGET( infobar ) );
1508
 
        gtk_widget_set_size_request( GTK_WIDGET( infobar ), -1, -1 );
 
1514
        gtk_widget_hide( GTK_WIDGET( infobar->sub ) );
 
1515
        gtk_widget_set_sensitive( GTK_WIDGET( infobar->info ), TRUE );
1509
1516
}
1510
1517
 
1511
1518
static gboolean
1525
1532
static void
1526
1533
infobar_start_close( Infobar *infobar )
1527
1534
{
1528
 
        IM_FREEF( g_source_remove, infobar->close_timeout );
1529
 
        IM_FREEF( g_source_remove, infobar->close_animation_timeout );
1530
 
        gtk_widget_set_size_request( GTK_WIDGET( infobar ), -1, -1 );
 
1535
        infobar_cancel_close( infobar );
1531
1536
 
1532
1537
        infobar->height = GTK_WIDGET( infobar )->allocation.height;
1533
1538
        infobar->close_animation_timeout = g_timeout_add( 50, 
1545
1550
static void
1546
1551
infobar_show( Infobar *infobar )
1547
1552
{
1548
 
        IM_FREEF( g_source_remove, infobar->close_timeout );
1549
 
        IM_FREEF( g_source_remove, infobar->close_animation_timeout );
 
1553
        infobar_cancel_close( infobar );
1550
1554
 
1551
 
        gtk_widget_set_size_request( GTK_WIDGET( infobar ), -1, -1 );
1552
1555
        infobar->close_timeout = g_timeout_add( 5000, 
1553
1556
                (GSourceFunc) infobar_close_timeout, infobar );
1554
1557
 
1556
1559
}
1557
1560
 
1558
1561
static void                
1559
 
infobar_response_cb( GtkInfoBar *info_bar, 
1560
 
        gint response_id, gpointer user_data )  
1561
 
{
1562
 
        infobar_start_close( INFOBAR( info_bar ) );
 
1562
infobar_info_cb( GtkWidget *button, Infobar *infobar )
 
1563
{
 
1564
        infobar_cancel_close( infobar );
 
1565
        gtk_widget_show( GTK_WIDGET( infobar->sub ) );
 
1566
        gtk_widget_set_sensitive( GTK_WIDGET( infobar->info ), FALSE );
 
1567
}
 
1568
 
 
1569
static void                
 
1570
infobar_close_cb( GtkWidget *button, Infobar *infobar )
 
1571
{
 
1572
        infobar_start_close( infobar );
1563
1573
}
1564
1574
 
1565
1575
Infobar *
1566
1576
infobar_new( void )
1567
1577
{
1568
1578
        Infobar *infobar;
 
1579
        GtkWidget *vbox;
1569
1580
        GtkWidget *content_area;
 
1581
        GtkWidget *hbox;
 
1582
        GtkWidget *action_area;
 
1583
        GtkWidget *button;
1570
1584
 
1571
1585
        infobar = g_object_new( TYPE_INFOBAR, NULL );
1572
 
        infobar->label = gtk_label_new( "" );
1573
 
        gtk_label_set_justify( GTK_LABEL( infobar->label ), GTK_JUSTIFY_LEFT );
1574
 
        gtk_label_set_selectable( GTK_LABEL( infobar->label ), TRUE );
1575
 
        gtk_label_set_line_wrap( GTK_LABEL( infobar->label ), TRUE );
 
1586
 
 
1587
        vbox = gtk_vbox_new( FALSE, 10 );
1576
1588
        content_area = gtk_info_bar_get_content_area( GTK_INFO_BAR( infobar ) );
1577
 
        gtk_container_add( GTK_CONTAINER( content_area ), infobar->label );
1578
 
        gtk_widget_show( infobar->label );
1579
 
        gtk_info_bar_add_button( GTK_INFO_BAR( infobar ),
1580
 
                 GTK_STOCK_OK, GTK_RESPONSE_OK );
1581
 
        g_signal_connect( infobar, "response",
1582
 
                G_CALLBACK( infobar_response_cb ), NULL );
 
1589
        gtk_container_add( GTK_CONTAINER( content_area ), vbox );
 
1590
        gtk_widget_show( vbox );
 
1591
 
 
1592
        infobar->top = gtk_label_new( "" );
 
1593
        gtk_label_set_justify( GTK_LABEL( infobar->top ), GTK_JUSTIFY_LEFT );
 
1594
        gtk_label_set_selectable( GTK_LABEL( infobar->top ), TRUE );
 
1595
        gtk_label_set_line_wrap( GTK_LABEL( infobar->top ), TRUE );
 
1596
        gtk_container_add( GTK_CONTAINER( vbox ), infobar->top );
 
1597
        gtk_widget_show( infobar->top );
 
1598
 
 
1599
        infobar->sub = gtk_label_new( "" );
 
1600
        gtk_label_set_justify( GTK_LABEL( infobar->sub ), GTK_JUSTIFY_LEFT );
 
1601
        gtk_label_set_selectable( GTK_LABEL( infobar->sub ), TRUE );
 
1602
        gtk_label_set_line_wrap( GTK_LABEL( infobar->sub ), TRUE );
 
1603
        gtk_container_add( GTK_CONTAINER( vbox ), infobar->sub );
 
1604
 
 
1605
        /* We can't use gtk_info_bar_add_button(), we need the buttons
 
1606
         * horizontally.
 
1607
         */
 
1608
 
 
1609
        hbox = gtk_hbox_new( FALSE, 2 );
 
1610
        action_area = gtk_info_bar_get_action_area( GTK_INFO_BAR( infobar ) );
 
1611
        gtk_container_add( GTK_CONTAINER( action_area ), hbox );
 
1612
        gtk_widget_show( hbox );
 
1613
 
 
1614
        button = gtk_button_new_from_stock( GTK_STOCK_CLOSE );
 
1615
        gtk_box_pack_end( GTK_BOX( hbox ), button, TRUE, TRUE, 2 );
 
1616
        g_signal_connect( button, "clicked",
 
1617
                G_CALLBACK( infobar_close_cb ), infobar );
 
1618
        gtk_widget_show( button );
 
1619
 
 
1620
        infobar->info = gtk_button_new_from_stock( GTK_STOCK_INFO );
 
1621
        gtk_box_pack_end( GTK_BOX( hbox ), infobar->info, TRUE, TRUE, 2 );
 
1622
        g_signal_connect( infobar->info, "clicked",
 
1623
                G_CALLBACK( infobar_info_cb ), infobar );
 
1624
        gtk_widget_show( infobar->info );
1583
1625
 
1584
1626
        return( infobar );
1585
1627
}
1594
1636
 
1595
1637
#endif /*USE_INFOBAR*/
1596
1638
 
 
1639
/* Set the label on an infobar to some marked-up text.
 
1640
 */
 
1641
void
 
1642
infobar_vset( Infobar *infobar, GtkMessageType type, 
 
1643
        const char *top, const char *sub, va_list ap )
 
1644
{
1597
1645
#ifdef USE_INFOBAR
1598
 
/* Mark up a top/sub pair for an infobar.
1599
 
 */
1600
 
static void
1601
 
box_vmarkup_infobar( char *out, const char *top, const char *sub, va_list ap )
1602
 
{
1603
1646
        char buf1[MAX_DIALOG_TEXT];
1604
1647
        char buf2[MAX_DIALOG_TEXT];
1605
 
        char buf3[MAX_DIALOG_TEXT];
1606
1648
        char *p;
1607
1649
 
1608
1650
        escape_markup( top, buf1, MAX_DIALOG_TEXT );
1609
 
        (void) im_vsnprintf( buf2, MAX_DIALOG_TEXT, sub, ap );
1610
 
        escape_markup( buf2, buf3, MAX_DIALOG_TEXT );
1611
 
 
1612
 
        (void) im_snprintf( out, MAX_DIALOG_TEXT, 
1613
 
                "<b>%s</b>", buf1 );
1614
 
        if( strcmp( buf3, "" ) != 0 ) {
1615
 
                int len = strlen( out );
1616
 
 
1617
 
                (void) im_snprintf( out + len, MAX_DIALOG_TEXT - len, 
1618
 
                        "\n%s", buf3 );
1619
 
        }
 
1651
        im_snprintf( buf2, MAX_DIALOG_TEXT, "<b>%s</b>", buf1 );
 
1652
        gtk_label_set_markup( GTK_LABEL( infobar->top ), buf2 );
 
1653
 
 
1654
        (void) im_vsnprintf( buf1, MAX_DIALOG_TEXT, sub, ap );
 
1655
        escape_markup( buf1, buf2, MAX_DIALOG_TEXT );
1620
1656
 
1621
1657
        /* Remove any trailing newlines, they make infobars rather large.
1622
1658
         */
1623
 
        while( (p = out + strlen( out )) > out && p[-1] == '\n' )
 
1659
        while( (p = buf2 + strlen( buf2 )) > buf2 && p[-1] == '\n' )
1624
1660
                p[-1] = '\0';
1625
 
}
1626
 
#endif /*USE_INFOBAR*/
1627
 
 
1628
 
/* Set the label on an infobar to some marked-up text.
1629
 
 */
1630
 
void
1631
 
infobar_vset( Infobar *infobar, GtkMessageType type, 
1632
 
        const char *top, const char *sub, va_list ap )
1633
 
{
1634
 
#ifdef USE_INFOBAR
1635
 
        char buf[MAX_DIALOG_TEXT];
1636
 
 
1637
 
        box_vmarkup_infobar( buf, top, sub, ap );
1638
 
        gtk_label_set_markup( GTK_LABEL( infobar->label ), buf );
 
1661
 
 
1662
        gtk_label_set_markup( GTK_LABEL( infobar->sub ), buf2 );
 
1663
 
1639
1664
        gtk_info_bar_set_message_type( GTK_INFO_BAR( infobar ), type );
1640
1665
 
1641
1666
        infobar_show( infobar );