From: <kr_...@us...> - 2003-07-10 19:51:32
|
Update of /cvsroot/htoolkit/port/src/cbits/GTK In directory sc8-pr-cvs1:/tmp/cvs-serv2409/src/cbits/GTK Modified Files: ListBox.c Log Message: Complete implementation for ListBox for GTK/Gnome. Index: ListBox.c =================================================================== RCS file: /cvsroot/htoolkit/port/src/cbits/GTK/ListBox.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** ListBox.c 29 Mar 2003 08:12:18 -0000 1.5 --- ListBox.c 10 Jul 2003 19:39:56 -0000 1.6 *************** *** 1,142 **** ! #include "ListBox.h" ! #include "Internals.h" ! #include "Handlers_stub.h" ! ! static void h1(GtkWidget *w) ! { ! printf("1\n"); ! handleControlCommand(w); ! } ! ! static void h2(GtkWidget *w1, GtkWidget *w2) ! { ! printf("2 -> %08X %08X\n", w1, w2); ! handleControlCommand(w1); ! } ! ! static void h3(GtkWidget *w1, GtkWidget *w2) ! { ! printf("3 -> %08X %08X\n", w1, w2); ! handleControlCommand(w1); ! } ! ! WindowHandle osCreateListBox(WindowHandle window, BOOL multisel) ! { ! GtkWidget *lbox; ! ! lbox = gtk_list_new(); ! if (!multisel) ! { ! gtk_signal_connect (GTK_OBJECT(lbox), "selection-changed", ! GTK_SIGNAL_FUNC(h1 /*handleListBoxClick*/), ! NULL); ! } ! else ! { ! #if 0 ! gtk_signal_connect (GTK_OBJECT(lbox), "select-child", ! GTK_SIGNAL_FUNC(h2 /*handleListBoxClick*/), ! NULL); ! gtk_signal_connect (GTK_OBJECT(lbox), "unselect-child", ! GTK_SIGNAL_FUNC(h3 /*handleListBoxClick*/), ! NULL); ! #endif ! } ! ! gtk_fixed_put(GTK_FIXED(GTK_BIN(GTK_BIN(window)->child)->child), lbox, 0, 0); ! gtk_list_set_selection_mode (GTK_LIST(lbox), multisel ? GTK_SELECTION_MULTIPLE : GTK_SELECTION_SINGLE); ! gtk_widget_show(lbox); ! return lbox; ! }; ! ! static void hh(GtkItem *item, gpointer user_data) ! { ! printf("hh\n"); ! handleControlCommand((GtkWidget *) user_data); ! }; ! ! void osAppendListBoxItem(WindowHandle listbox, char *title) ! { ! GtkWidget *li; ! ! li = gtk_list_item_new_with_label(title); ! if (GTK_LIST(listbox)->selection_mode == GTK_SELECTION_MULTIPLE) ! { ! gtk_signal_connect (GTK_OBJECT(li), "select", ! GTK_SIGNAL_FUNC(hh), ! listbox); ! gtk_signal_connect (GTK_OBJECT(li), "deselect", ! GTK_SIGNAL_FUNC(hh), ! listbox); ! } ! ! gtk_list_append_items(GTK_LIST(listbox), g_list_append(NULL,li)); ! gtk_widget_show(li); ! }; ! ! void osInsertListBoxItem(WindowHandle listbox, int index, char *title) ! { ! GtkWidget *li; ! ! li = gtk_list_item_new_with_label(title); ! if (GTK_LIST(listbox)->selection_mode == GTK_SELECTION_MULTIPLE) ! { ! gtk_signal_connect (GTK_OBJECT(li), "select", ! GTK_SIGNAL_FUNC(hh), ! listbox); ! gtk_signal_connect (GTK_OBJECT(li), "deselect", ! GTK_SIGNAL_FUNC(hh), ! listbox); ! } ! ! gtk_list_insert_items(GTK_LIST(listbox), g_list_append(NULL,li), index); ! gtk_widget_show(li); ! }; ! ! void osRemoveListBoxItem(WindowHandle listbox, int index) ! { ! GList *tmp_list = g_list_append(NULL, g_list_nth(GTK_LIST(listbox)->children, index)->data); ! gtk_list_remove_items (GTK_LIST(listbox),tmp_list); ! g_list_free(tmp_list); ! }; ! ! void osRemoveAllListBoxItems(WindowHandle listbox) ! { ! gtk_list_remove_items (GTK_LIST(listbox),GTK_LIST(listbox)->children); ! }; ! ! void osGetListBoxReqSize(WindowHandle listbox, int *res) ! { ! res[0] = 100; ! res[1] = 100; ! }; ! ! int osGetListBoxSingleSelection(WindowHandle listbox) ! { ! if (!GTK_LIST(listbox)->selection) ! return -1; ! ! return gtk_list_child_position(GTK_LIST(listbox), (GtkWidget *) GTK_LIST(listbox)->selection->data); ! }; ! ! BOOL osGetListBoxItemSelectState(WindowHandle listbox, int index) ! { ! GtkWidget *item = (GtkWidget *) g_list_nth(GTK_LIST(listbox)->children, index)->data; ! return (item->state == GTK_STATE_SELECTED); ! } ! ! void osSetListBoxSingleSelection(WindowHandle listbox, int index) ! { ! if (index > 0) ! gtk_list_select_item(GTK_LIST(listbox),index); ! else ! gtk_list_unselect_all(GTK_LIST(listbox)); ! }; ! ! void osSetListBoxItemSelectState(WindowHandle listbox, int index, BOOL state) ! { ! if (state) ! gtk_list_select_item(GTK_LIST(listbox),index); ! else ! gtk_list_unselect_item(GTK_LIST(listbox),index); ! }; --- 1,172 ---- ! #include "ListBox.h" ! #include "Internals.h" ! #include "Handlers_stub.h" ! ! static void tree_view_selection_chanded(GtkWidget *w, gpointer user_data) ! { ! handleControlCommand((WindowHandle) user_data); ! } ! ! WindowHandle osCreateListBox(WindowHandle window, BOOL multisel) ! { ! GtkListStore *store; ! GtkWidget *lbox, *sw; ! GtkTreeViewColumn *column; ! ! /* create scrolled window */ ! sw = gtk_scrolled_window_new (NULL, NULL); ! gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_ETCHED_IN); ! gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), ! GTK_POLICY_AUTOMATIC, ! GTK_POLICY_AUTOMATIC); ! ! /* create list store */ ! store = gtk_list_store_new (1, G_TYPE_STRING); ! ! /* create tree view */ ! lbox = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); ! gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(lbox), FALSE); ! gtk_tree_view_set_enable_search (GTK_TREE_VIEW(lbox), TRUE); ! gtk_tree_selection_set_mode(gtk_tree_view_get_selection(GTK_TREE_VIEW(lbox)), ! multisel ? GTK_SELECTION_MULTIPLE : GTK_SELECTION_SINGLE); ! g_object_unref (store); ! ! /* add column to the tree view */ ! column = gtk_tree_view_column_new_with_attributes ("", ! gtk_cell_renderer_text_new (), ! "text", ! 0, ! NULL); ! gtk_tree_view_append_column (GTK_TREE_VIEW(lbox), column); ! ! gtk_container_add(GTK_CONTAINER(sw), lbox); ! ! g_signal_connect (G_OBJECT(gtk_tree_view_get_selection(GTK_TREE_VIEW(lbox))), "changed", ! GTK_SIGNAL_FUNC(tree_view_selection_chanded), ! sw); ! ! gtk_fixed_put(GTK_FIXED(GTK_BIN(GTK_BIN(window)->child)->child), sw, 0, 0); ! gtk_widget_show_all(sw); ! return sw; ! }; ! ! void osAppendListBoxItem(WindowHandle listbox, char *title) ! { ! GtkTreeIter iter; ! GtkWidget *lbox = GTK_BIN(listbox)->child; ! GtkListStore *store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(lbox))); ! gtk_list_store_append(store, &iter); ! gtk_list_store_set(store, &iter, 0, title, -1); ! }; ! ! void osInsertListBoxItem(WindowHandle listbox, int index, char *title) ! { ! /* GtkWidget *li; ! GtkWidget *lbox = GTK_BIN(listbox)->child; ! ! li = gtk_list_item_new_with_label(title); ! if (GTK_LIST(listbox)->selection_mode == GTK_SELECTION_MULTIPLE) ! { ! gtk_signal_connect (GTK_OBJECT(li), "select", ! GTK_SIGNAL_FUNC(hh), ! listbox); ! gtk_signal_connect (GTK_OBJECT(li), "deselect", ! GTK_SIGNAL_FUNC(hh), ! listbox); ! } ! ! gtk_list_insert_items(GTK_LIST(listbox), g_list_append(NULL,li), index); ! gtk_widget_show(li); ! */ ! }; ! ! void osRemoveListBoxItem(WindowHandle listbox, int index) ! { ! GList *tmp_list = g_list_append(NULL, g_list_nth(GTK_LIST(listbox)->children, index)->data); ! gtk_list_remove_items (GTK_LIST(listbox),tmp_list); ! g_list_free(tmp_list); ! }; ! ! void osRemoveAllListBoxItems(WindowHandle listbox) ! { ! gtk_list_store_clear(GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(GTK_BIN(listbox)->child)))); ! }; ! ! void osGetListBoxReqSize(WindowHandle listbox, int *res) ! { ! res[0] = 80; ! res[1] = 60; ! }; ! ! int osGetListBoxSingleSelection(WindowHandle listbox) ! { ! GtkTreeIter iter; ! GtkTreePath *path; ! GtkTreeModel *model = NULL; ! GtkWidget *lbox = GTK_BIN(listbox)->child; ! int index = -1; ! ! if (gtk_tree_selection_get_selected (gtk_tree_view_get_selection(GTK_TREE_VIEW(lbox)), &model, &iter)) ! { ! path = gtk_tree_model_get_path(model, &iter); ! if (gtk_tree_path_get_depth(path) >= 1) ! index = gtk_tree_path_get_indices(path)[0]; ! gtk_tree_path_free(path); ! } ! ! return index; ! }; ! ! BOOL osGetListBoxItemSelectState(WindowHandle listbox, int index) ! { ! BOOL result; ! GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(GTK_BIN(listbox)->child)); ! GtkTreePath *path = gtk_tree_path_new_from_indices (index, -1); ! ! result = gtk_tree_selection_path_is_selected(selection, path); ! ! gtk_tree_path_free(path); ! return result; ! } ! ! void osSetListBoxSingleSelection(WindowHandle listbox, int index) ! { ! GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(GTK_BIN(listbox)->child)); ! ! if (index > 0) ! { ! GtkTreePath *path = gtk_tree_path_new_from_indices (index, -1); ! gtk_tree_selection_select_path(selection, path); ! gtk_tree_path_free(path); ! } ! else ! gtk_tree_selection_unselect_all (selection); ! }; ! ! void osSetListBoxItemSelectState(WindowHandle listbox, int index, BOOL state) ! { ! GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(GTK_BIN(listbox)->child)); ! ! if (index > 0) ! { ! GtkTreePath *path = gtk_tree_path_new_from_indices (index, -1); ! if (state) ! gtk_tree_selection_select_path(selection, path); ! else ! gtk_tree_selection_unselect_path(selection, path); ! ! gtk_tree_path_free(path); ! } ! }; ! ! int osGetListBoxCurrentItem(WindowHandle listbox) ! { ! GtkTreePath *path; ! GtkWidget *lbox = GTK_BIN(listbox)->child; ! ! gtk_tree_view_get_cursor(GTK_TREE_VIEW(lbox), &path, NULL); ! if (path != NULL && gtk_tree_path_get_depth(path) >= 1) ! return gtk_tree_path_get_indices(path)[0]; ! else ! return -1; ! } \ No newline at end of file |