调节界面求
#include <gtk_api.h>#include <core.h>
/* [url=http://library.]http://library.[/url] */
/* [url=http://library.]http://library.[/url] */
static void toolwin_create(GtkWidget *vbox);
static void textwin_create(GtkWidget *vbox);
static void topwin_create(GtkWidget *vbox);
static void midwin_create(GtkWidget *vbox);
static void bottomwin_create(GtkWidget *vbox);
static void add_widget_to_window(GtkWidget *window, GtkWidget *widget);
/* core */
static GtkWidget *build_window(void);
static GtkWidget *build_main_vbox(void);
/* others api */
static void unfocus_combo_arrow(GtkWidget *widget, gpointer data);
static void unfocus_combo_arrow(GtkWidget *widget, gpointer data)
{
if (!GTK_IS_ENTRY(widget))
GTK_WIDGET_UNSET_FLAGS(widget, GTK_CAN_FOCUS);
}
GtkWidget *ListWin_Create(void)
{
GtkCellRenderer *renderer;
GtkTreeViewColumn *column;
GtkTreeSelection *selection;
GtkWidget *scrolledwindow;
GtkListStore *list_model;
GtkTreeView *treeview_;
list_model = gtk_list_store_new (1, G_TYPE_STRING);
treeview_ = GTK_TREE_VIEW(gtk_tree_view_new_with_model(GTK_TREE_MODEL(list_model)));
gtk_widget_show(GTK_WIDGET(treeview_));
gtk_tree_view_set_rules_hint(treeview_, TRUE);
gtk_tree_view_set_headers_visible(treeview_, FALSE);
renderer = gtk_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes ("word", renderer,
"text", 0, NULL);
gtk_tree_view_append_column(treeview_, column);
selection = gtk_tree_view_get_selection(treeview_);
scrolledwindow = gtk_scrolled_window_new(NULL, NULL);
gtk_widget_show(scrolledwindow);
gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW (scrolledwindow),
GTK_SHADOW_ETCHED_IN);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwindow),
GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
gtk_container_add(GTK_CONTAINER(scrolledwindow), GTK_WIDGET(treeview_));
return scrolledwindow;
}
/* Widget Sequence:
* clear_button,
* WordCombo
*/
static void topwin_create(GtkWidget *vbox)
{
GtkWidget *hbox = gtk_hbox_new(FALSE, FALSE);
GtkWidget *button, *WordCombo;
GtkListStore *list_store;
gtk_widget_show(hbox);
gtk_box_pack_start(GTK_BOX(vbox),hbox,0,0,3);
/* first - clear */
button = gtk_button_new();
gtk_container_add(GTK_CONTAINER(button),gtk_image_new_from_stock(GTK_STOCK_UNDO,GTK_ICON_SIZE_BUTTON));
gtk_widget_show_all(button);
gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
GTK_WIDGET_UNSET_FLAGS (button, GTK_CAN_FOCUS);
gtk_box_pack_start(GTK_BOX(hbox), button, 0, 0, 0);
/* second - input and .. */
list_store = gtk_list_store_new(1, G_TYPE_STRING);
WordCombo = gtk_combo_box_entry_new_with_model(GTK_TREE_MODEL(list_store), 0);
g_object_unref(G_OBJECT(list_store));
gtk_combo_box_set_focus_on_click(GTK_COMBO_BOX(WordCombo), FALSE);
gtk_container_forall(GTK_CONTAINER(WordCombo), unfocus_combo_arrow, NULL);
gtk_widget_set_size_request(WordCombo, 60, -1);
gtk_widget_show(WordCombo);
gtk_entry_set_max_length(GTK_ENTRY(GTK_BIN(WordCombo)->child), 255);
g_signal_connect(G_OBJECT(GTK_BIN(WordCombo)->child), "changed",
G_CALLBACK(input_words), NULL);
gtk_box_pack_start(GTK_BOX(hbox),WordCombo, TRUE, TRUE, 3);
/* third */
button = gtk_button_new();
gtk_container_add(GTK_CONTAINER(button),gtk_image_new_from_stock(GTK_STOCK_HOME,GTK_ICON_SIZE_BUTTON));
gtk_widget_show_all(button);
gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
GTK_WIDGET_UNSET_FLAGS (button, GTK_CAN_FOCUS);
gtk_box_pack_start(GTK_BOX(hbox),button,0,0,0);
}
static void midwin_create(GtkWidget *vbox)
{
GtkWidget *vbox1, *hbox, *hpaned;
hbox = gtk_hbox_new(FALSE, 2);
hpaned = gtk_hpaned_new();
gtk_widget_show(hpaned);
gtk_box_pack_start(GTK_BOX(vbox), hpaned, TRUE, TRUE, 0);
/**/
indexwin_create(hpaned);
vbox1 = gtk_vbox_new(FALSE, 0);
gtk_widget_show(vbox1);
textwin_create(vbox1);
gtk_paned_pack2(GTK_PANED(hpaned), vbox1, TRUE, FALSE);
}
static void bottomwin_create(GtkWidget *vbox)
{
topwin_create(vbox);
}
static GtkWidget *build_window(void)
{
GtkWidget *window = NULL;
/* FIXME: here need check SUCCESS? */
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), soft_prog);
gtk_window_set_default_size(GTK_WINDOW(window),
GRAH_DEFAULT_WIN_WIDTH, GRAH_DEFAULT_WIN_HEIGTH);
g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);
return window;
}
static void add_widget_to_window(GtkWidget *window, GtkWidget *widget)
{
gtk_container_add(GTK_CONTAINER(window), widget);
}
/* Our main vbox has 3 parts: Top / Mid / Bottom.
* main vbox is belong to main window.
*/
static GtkWidget *build_main_vbox(void)
{
GtkWidget *box;
box = gtk_vbox_new(FALSE,0);
topwin_create(box);
midwin_create(box);
bottomwin_create(box);
return box;
}
/* Build a core window with default setting the vbox. */
GtkWidget *build_main_window(void)
{
GtkWidget *vbox, *window;
vbox = build_main_vbox();
window = build_window();
assert(window && vbox);
add_widget_to_window(window, vbox);
return window;
} 界面就这一个文件。 调用最下面的 build_main_window 就可以了