From: <kr_...@us...> - 2003-11-26 22:05:04
|
Update of /cvsroot/htoolkit/port/src/cbits/GTK In directory sc8-pr-cvs1:/tmp/cvs-serv10286/src/cbits/GTK Modified Files: ListBox.c Log Message: Added support for CheckListBox for GNOME Index: ListBox.c =================================================================== RCS file: /cvsroot/htoolkit/port/src/cbits/GTK/ListBox.c,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** ListBox.c 8 Oct 2003 22:21:57 -0000 1.10 --- ListBox.c 26 Nov 2003 22:05:01 -0000 1.11 *************** *** 52,62 **** }; 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); }; --- 52,134 ---- }; + static void checkbox_toggled(GtkCellRendererToggle *cellrenderertoggle, gchar *path_string, gpointer user_data) + { + GtkWidget *sw = (GtkWidget *)user_data; + GtkWidget *listbox = GTK_BIN(sw)->child; + GtkTreeModel *model; + GtkTreeIter iter; + GtkTreePath *path; + gboolean state; + + path = gtk_tree_path_new_from_string (path_string); + model = gtk_tree_view_get_model(GTK_TREE_VIEW(listbox)); + gtk_tree_model_get_iter (model, &iter, path); + + gtk_tree_model_get(model, &iter, 0, &state, -1); + gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, !state, -1); + + handleControlCommand(sw); + }; + + WindowHandle osCreateCheckListBox(WindowHandle window) + { + GtkListStore *store; + GtkWidget *lbox, *sw; + GtkTreeViewColumn *column; + GtkCellRenderer *render; + + /* 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 (2, G_TYPE_BOOLEAN, 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)), GTK_SELECTION_SINGLE); + g_object_unref (store); + + /* add columns to the tree view */ + render = gtk_cell_renderer_toggle_new (); + g_signal_connect (render, "toggled", + G_CALLBACK (checkbox_toggled), sw); + column = gtk_tree_view_column_new_with_attributes ("", + render, + "active", + 0, + NULL); + gtk_tree_view_append_column (GTK_TREE_VIEW(lbox), column); + column = gtk_tree_view_column_new_with_attributes ("", + gtk_cell_renderer_text_new (), + "text", + 1, + NULL); + gtk_tree_view_append_column (GTK_TREE_VIEW(lbox), column); + + gtk_container_add(GTK_CONTAINER(sw), lbox); + gtk_widget_show(lbox); + + port_layout_put(PORT_LAYOUT(GTK_BIN(window)->child), sw); + + return sw; + }; + void osAppendListBoxItem(WindowHandle listbox, char *title) { GtkTreeIter iter; GtkWidget *lbox = GTK_BIN(listbox)->child; ! GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(lbox)); ! gtk_list_store_append(GTK_LIST_STORE(model), &iter); ! ! if (gtk_tree_model_get_n_columns(model) > 1) ! gtk_list_store_set(GTK_LIST_STORE(model), &iter, 0, FALSE, 1, title, -1); ! else ! gtk_list_store_set(GTK_LIST_STORE(model), &iter, 0, title, -1); }; *************** *** 65,71 **** 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_insert(store, &iter, index); ! gtk_list_store_set(store, &iter, 0, title, -1);}; void osRemoveListBoxItem(WindowHandle listbox, int index) --- 137,148 ---- GtkTreeIter iter; GtkWidget *lbox = GTK_BIN(listbox)->child; ! GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(lbox)); ! gtk_list_store_insert(GTK_LIST_STORE(model), &iter, index); ! ! if (gtk_tree_model_get_n_columns(model) > 1) ! gtk_list_store_set(GTK_LIST_STORE(model), &iter, 0, FALSE, 1, title, -1); ! else ! gtk_list_store_set(GTK_LIST_STORE(model), &iter, 0, title, -1); ! }; void osRemoveListBoxItem(WindowHandle listbox, int index) *************** *** 117,124 **** { 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); --- 194,212 ---- { BOOL result; ! GtkWidget *lbox = GTK_BIN(listbox)->child; GtkTreePath *path = gtk_tree_path_new_from_indices (index, -1); + GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(lbox)); ! if (gtk_tree_model_get_n_columns(model) > 1) ! { ! GtkTreeIter iter; ! gtk_tree_model_get_iter (model, &iter, path); ! gtk_tree_model_get(model, &iter, 0, &result, -1); ! } ! else ! { ! GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(lbox)); ! result = gtk_tree_selection_path_is_selected(selection, path); ! } gtk_tree_path_free(path); *************** *** 131,135 **** GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(lbox)); ! if (index > 0) { GtkTreePath *path = gtk_tree_path_new_from_indices (index, -1); --- 219,223 ---- GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(lbox)); ! if (index >= 0) { GtkTreePath *path = gtk_tree_path_new_from_indices (index, -1); *************** *** 144,156 **** 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); --- 232,256 ---- void osSetListBoxItemSelectState(WindowHandle listbox, int index, BOOL state) { ! GtkWidget *lbox = GTK_BIN(listbox)->child; ! GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(lbox)); ! if (index >= 0) { GtkTreePath *path = gtk_tree_path_new_from_indices (index, -1); ! GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(lbox)); ! ! if (gtk_tree_model_get_n_columns(model) > 1) ! { ! GtkTreeIter iter; ! gtk_tree_model_get_iter (model, &iter, path); ! gtk_list_store_set (GTK_LIST_STORE(model), &iter, 0, state, -1); ! } else ! { ! if (state) ! gtk_tree_selection_select_path(selection, path); ! else ! gtk_tree_selection_unselect_path(selection, path); ! } gtk_tree_path_free(path); |