Linux中国 Linux中国门户站!
设为主页 设为主页
收藏本站 收藏本站
 
当前位置 :首页 ->Linux技术 ->系统管理 ->正文

GTK v1.2 Tutorial(英文)

来源:Linux-cn.com 作者:Webmaster 时间:2007-05-05 点击: [收藏] [投稿]


/* now, let's make our radio buttons group... */
iconw = gtk_pixmap_new ( icon, mask );
icon_button = gtk_toolbar_append_element(
GTK_TOOLBAR(toolbar),
GTK_TOOLBAR_CHILD_RADIOBUTTON, /* a type of element */
NULL,/* pointer to widget */
"Icon",/* label */
"Only icons in toolbar", /* tooltip */
"Private", /* tooltip private string */
iconw, /* icon */
GTK_SIGNAL_FUNC (radio_event), /* signal */
toolbar);/* data for signal */
gtk_toolbar_append_space ( GTK_TOOLBAR ( toolbar ) );

  Here we begin creating a radio buttons group. To do this we use gtk_toolbar_append_element. In fact, using this function one can also +add simple items or even spaces (type = GTK_TOOLBAR_CHILD_SPACE or +GTK_TOOLBAR_CHILD_BUTTON). In the above case we start creating a radio group. In creating other radio buttons for this group a pointer to the previous button in the group is required, so that a list of buttons can be easily constructed (see the section on Radio Buttons earlier in this tutorial).


/* following radio buttons refer to previous ones */
iconw = gtk_pixmap_new ( icon, mask );
text_button = 
gtk_toolbar_append_element(GTK_TOOLBAR(toolbar),
 GTK_TOOLBAR_CHILD_RADIOBUTTON,
 icon_button,
 "Text",
 "Only texts in toolbar",
 "Private",
 iconw,
 GTK_SIGNAL_FUNC (radio_event),
 toolbar);
gtk_toolbar_append_space ( GTK_TOOLBAR ( toolbar ) );
iconw = gtk_pixmap_new ( icon, mask );
both_button = 
gtk_toolbar_append_element(GTK_TOOLBAR(toolbar),
 GTK_TOOLBAR_CHILD_RADIOBUTTON,
 text_button,
 "Both",
 "Icons and text in toolbar",
 "Private",
 iconw,
 GTK_SIGNAL_FUNC (radio_event),
 toolbar);
gtk_toolbar_append_space ( GTK_TOOLBAR ( toolbar ) );
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(both_button),TRUE);

  In the end we have to set the state of one of the buttons manually (otherwise they all stay in active state, preventing us from switching between them).


/* here we have just a simple toggle button */
iconw = gtk_pixmap_new ( icon, mask );
tooltips_button = 
gtk_toolbar_append_element(GTK_TOOLBAR(toolbar),
 GTK_TOOLBAR_CHILD_TOGGLEBUTTON,
 NULL,
 "Tooltips",
 "Toolbar with or without tips",
 "Private",
 iconw,
 GTK_SIGNAL_FUNC (toggle_event),
 toolbar);
gtk_toolbar_append_space ( GTK_TOOLBAR ( toolbar ) );
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(tooltips_button),TRUE);

  A toggle button can be created in the obvious way (if one knows how to create radio buttons already).


/* to pack a widget into toolbar, we only have to 
 * create it and append it with an appropriate tooltip */
entry = gtk_entry_new ();
gtk_toolbar_append_widget( GTK_TOOLBAR (toolbar), 
 entry, 
 "This is just an entry", 
 "Private" );
/* well, it isn't created within thetoolbar, so we must still show it */
gtk_widget_show ( entry );

  As you see, adding any kind of widget to a toolbar is simple. The one thing you have to remember is that this widget must be shown manually (contrary to other items which will be shown together with the toolbar).


/* that's it ! let's show everything. */
gtk_widget_show ( toolbar );
gtk_widget_show (handlebox);
gtk_widget_show ( dialog );
/* rest in gtk_main and wait for the fun to begin! */
gtk_main ();
return 0;
}

  So, here we are at the end of toolbar tutorial. Of course, to appreciate it in full you need also this nice XPM icon, so here it is:


/* XPM */
static char * gtk_xpm[] = {
"32 39 5 1",
".c none",
"+c black",
"@c #3070E0",
"#c #F05050",
"$c #35E035",
"................+...............",
"..............+++++.............",
"............+++++@@++...........",
"..........+++++@@@@@@++.........",
"........++++@@@@@@@@@@++........",
"......++++@@++++++++@@@++.......",
".....+++@@@+++++++++++@@@++.....",
"...+++@@@@+++@@@@@@++++@@@@+....",
"..+++@@@@+++@@@@@@@@+++@@@@@++..",
".++@@@@@@+++@@@@@@@@@@@@@@@@@@++",
".+#+@@@@@@++@@@@+++@@@@@@@@@@@@+",
".+##++@@@@+++@@@+++++@@@@@@@@$@.",
".+###++@@@@+++@@@+++@@@@@++$$$@.",
".+####+++@@@+++++++@@@@@+@$$$$@.",
".+#####+++@@@@+++@@@@++@$$$$$$+.",
".+######++++@@@@@@@++@$$$$$$$$+.",
".+#######+##+@@@@+++$$$$$$@@$$+.",
".+###+++##+##+@@++@$$$$$$++$$$+.",
".+###++++##+##+@@$$$$$$$@+@$$@+.",
".+###++++++#+++@$$@+@$$@++$$$@+.",
".+####+++++++#++$$@+@$$++$$$$+..",
".++####++++++#++$$@+@$++@$$$$+..",
".+#####+++++##++$$++@+++$$$$$+..",
".++####+++##+#++$$+++++@$$$$$+..",
".++####+++####++$$++++++@$$$@+..",
".+#####++#####++$$+++@++++@$@+..",
".+#####++#####++$$++@$$@+++$@@..",
".++####++#####++$$++$$$$$+@$@++.",
".++####++#####++$$++$$$$$$$$+++.",
".+++####+#####++$$++$$$$$$$@+++.",
"..+++#########+@$$+@$$$$$$+++...",
"...+++########+@$$$$$$$$@+++....",
".....+++######+@$$$$$$$+++......",
"......+++#####+@$$$$$@++........",
".......+++####+@$$$$+++.........",
".........++###+$$$@++...........",
"..........++##+$@+++............",
"...........+++++++..............",
".............++++..............."};


 如果您对本文有任何疑问或者建议,请到讨论区发表您的意见: >> 论坛入口 <<



上一篇:GTK入门导引   下一篇:GDK Reference Manual

文章评论】 【收藏本文】 【推荐好友】 【打印本文】 【我要投稿】 【论坛讨论
更多相关文章