|
Fixed Container故名之意就是固定容器,它容许把控件放到一个固定容器中,并能随意到移动到某个位置[相对于窗口的左上方]。虽然它能随意移动,但有很多弊端,比如容器的大小它会随字体的大小的改变而改变,从而可能会出现控件覆盖控件的现象;又如在多语言中,我们都知道阿拉伯语到单词大部分都比E文单词都要长,如果从E语切换到阿拉伯语或其它语言时,固定容器的在水平方向将会发生伸缩等现象明显是用户所不能接受的。所以不推荐使用fixed container。下面是一个对Fixed Container的简单实例:/**********************************
**
**FILE: fixedgtk+.c
**DATE: 20090508 20:49
**AUTHOR: LAMMY
**VERSION: 0.1
**
**********************************/
#include<gtk/gtk.h>
typedef struct ComButton_s
{
GtkWidget *m_pParentWidget;
GtkWidget *m_pSelfWidget;
guint32 m_nPox;
guint32 m_nPoy;
}ComButton_t;
gboolean _CallBackMove(GtkWidget *pHwidget, ComButton_t *pComButton)
{
static guint32 nPox = 0;
static guint32 nPoy = 0;
nPox += 5;
nPoy += 5;
pComButton->m_nPox = nPox;
pComButton->m_nPoy = nPoy;
gtk_fixed_move(GTK_FIXED(pComButton->m_pParentWidget), pComButton->m_pSelfWidget, pComButton->m_nPox, pComButton->m_nPoy);
return 0;
}
int main(int argc, char *argv[])
{
GtkWidget *pHwindow, *pHfixed, *pHbuttonOne, *pHbuttonTWO;
ComButton_t ComButton;
gtk_init(&argc, &argv);
pHwindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(pHwindow), "gtkfixedgtk+");
gtk_widget_set_size_request(pHwindow, 200, 250);
gtk_container_set_border_width(GTK_WINDOW(pHwindow), 10);
pHfixed = gtk_fixed_new();
pHbuttonOne = gtk_button_new_with_label("ButtonOne");
pHbuttonTWO = gtk_button_new_with_label("ButtonTwo");
gtk_fixed_put(GTK_FIXED(pHfixed), pHbuttonOne, 0,0);
gtk_fixed_put(GTK_FIXED(pHfixed), pHbuttonTWO, 80, 150);
ComButton.m_pParentWidget = pHfixed;
ComButton.m_pSelfWidget = pHbuttonOne;
g_signal_connect(pHbuttonOne, "clicked", G_CALLBACK(_CallBackMove), &ComButton);
gtk_container_add(GTK_WINDOW(pHwindow), pHfixed);
gtk_widget_show_all(pHwindow);
gtk_main();
return 0;
}Exapnder有扩展之意,expander容器只允许有一个子控件,通过点击expander容器可以伸展或隐藏其子控件。以下是一个对Expander的简单实例:
/**********************************
**
**FILE: expandergtk+.c
**DATE: 200905010 22:49
**AUTHOR: LAMMY
**VERSION: 0.0
**
**********************************/
#include<gtk/gtk.h>
int main(int argc, char *argv)
{
GtkWidget *pHwindow, *pHexpander, *pHlabel;
gtk_init(&argc, &argv) ;
pHwindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(pHwindow), "expandergtk+");
gtk_widget_set_size_request(pHwindow, 150, 250);
gtk_container_set_border_width(GTK_CONTAINER(pHwindow), 10);
pHexpander = gtk_expander_new_with_mnemonic("Click _Me For More");
pHlabel = gtk_label_new_with_mnemonic("Hide or Show Label");
gtk_container_add(GTK_EXPANDER(pHexpander), pHlabel);
//g_signal_connect();
gtk_container_add(GTK_WINDOW(pHwindow), pHexpander);
gtk_widget_show_all(pHwindow);
gtk_main();
return 0;
}
|
|