has a menu and a treeview
authorDana Jansens <danakj@orodu.net>
Sat, 2 Aug 2003 19:19:03 +0000 (19:19 +0000)
committerDana Jansens <danakj@orodu.net>
Sat, 2 Aug 2003 19:19:03 +0000 (19:19 +0000)
tools/obconf/main.c

index a4278d9..594a9d6 100644 (file)
@@ -9,8 +9,23 @@
 #define OB_ICON "openbox-icon"
 
 static GtkWidget *mainwin;
+static GtkWidget *mainlist;
+static GtkListStore *mainstore;
+static GtkWidget *mainnote;
 static GdkPixbuf *ob_icon;
 
+enum {
+    NAME_COLUMN,
+    N_COLUMNS
+};
+
+gboolean on_mainwindow_delete_event(GtkWidget *w, GdkEvent *e, gpointer d);
+void on_quit_activate(GtkMenuItem *item, gpointer d);
+void on_applybutton_clicked(GtkButton *but, gpointer d);
+void on_revertbutton_clicked(GtkButton *but, gpointer d);
+void on_helpbutton_clicked(GtkButton *but, gpointer d);
+void on_selection_changed(GtkTreeSelection *selection, gpointer data);
+
 static void obconf_error(GError *e)
 {
     GtkWidget *d;
@@ -52,8 +67,80 @@ static void load_stock ()
     }
 }
 
+GtkWidget* build_menu(GtkWidget *win, GtkAccelGroup *accel)
+{
+    GtkWidget *menu;
+    GtkWidget *submenu;
+    GtkWidget *item;
+
+    menu = gtk_menu_bar_new();
+
+    /* File menu */
+
+    submenu = gtk_menu_new();
+    gtk_menu_set_accel_group(GTK_MENU(submenu), accel);
+
+    item = gtk_image_menu_item_new_from_stock(GTK_STOCK_QUIT, accel);
+    g_signal_connect(item, "activate", G_CALLBACK(on_quit_activate), NULL);
+    gtk_menu_append(GTK_MENU(submenu), item);
+
+    item = gtk_menu_item_new_with_mnemonic("_File");
+    gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu);
+    gtk_menu_bar_append(GTK_MENU_BAR(menu), item);
+
+    /* About menu */
+
+    submenu = gtk_menu_new();
+    gtk_menu_set_accel_group(GTK_MENU(submenu), accel);
+
+    item = gtk_menu_item_new_with_mnemonic("_About");
+    gtk_menu_append(GTK_MENU(submenu), item);
+
+    item = gtk_menu_item_new_with_mnemonic("_Help");
+    gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu);
+    gtk_menu_bar_append(GTK_MENU_BAR(menu), item);
+
+    gtk_widget_show_all(menu);
+
+    return menu;
+}
+
+GtkWidget* build_list(GtkWidget *parent, GtkListStore **model)
+{
+    GtkWidget *list;
+    GtkListStore *store;
+    GtkCellRenderer *ren;
+    GtkTreeViewColumn *col;
+    GtkTreeSelection *sel;
+
+    store = gtk_list_store_new(N_COLUMNS,
+                               G_TYPE_STRING);
+
+    list = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
+
+    sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(list));
+    gtk_tree_selection_set_mode(sel, GTK_SELECTION_SINGLE);
+    g_signal_connect(sel, "changed", G_CALLBACK(on_selection_changed), NULL);
+    
+    ren = gtk_cell_renderer_text_new();
+    col = gtk_tree_view_column_new_with_attributes("Name",
+                                                   ren,
+                                                   "text",
+                                                   NAME_COLUMN,
+                                                   NULL);
+    gtk_tree_view_append_column(GTK_TREE_VIEW(list), col);
+
+    *model = store;
+    return list;
+}
+
 int main(int argc, char **argv)
 {
+    GtkWidget *menu;
+    GtkWidget *vbox;
+    GtkWidget *hbox;
+    GtkAccelGroup *accel;
+
     gtk_set_locale();
     gtk_init(&argc, &argv);
 
@@ -62,6 +149,27 @@ int main(int argc, char **argv)
     gtk_window_set_wmclass(GTK_WINDOW(mainwin), "obconf", "Obconf");
     gtk_window_set_role(GTK_WINDOW(mainwin), "main window");
 
+    g_signal_connect(mainwin, "delete-event",
+                     G_CALLBACK(on_mainwindow_delete_event), NULL);
+
+    accel = gtk_accel_group_new();
+    gtk_window_add_accel_group(GTK_WINDOW(mainwin), accel);
+
+    vbox = gtk_vbox_new(FALSE, 3);
+    gtk_container_add(GTK_CONTAINER(mainwin), vbox);
+
+    /* Menu */
+
+    menu = build_menu(mainwin, accel);
+    gtk_box_pack_start(GTK_BOX(vbox), menu, FALSE, FALSE, 0);
+
+    hbox = gtk_hbox_new(FALSE, 2);
+    gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0);
+
+    /* List */
+
+    mainlist = build_list(hbox, &mainstore);
+
     gtk_widget_show_all(mainwin);
 
     load_stock();
@@ -84,21 +192,27 @@ void on_quit_activate(GtkMenuItem *item, gpointer d)
 
 void on_applybutton_clicked(GtkButton *but, gpointer d)
 {
-    g_message("apply\n");
+    g_message("apply");
 }
 
 void on_revertbutton_clicked(GtkButton *but, gpointer d)
 {
-    g_message("revert\n");
+    g_message("revert");
 }
 
 void on_helpbutton_clicked(GtkButton *but, gpointer d)
 {
-    g_message("help\n");
+    g_message("help");
 }
 
-void on_sectiontree_row_activated(GtkTreeView *tree, GtkTreePath *path,
-                                  GtkTreeViewColumn *col, gpointer p)
+void on_selection_changed(GtkTreeSelection *sel, gpointer data)
 {
-    g_message("activated\n");
+    GtkTreeIter iter;
+    GtkTreeModel *model;
+
+    if (gtk_tree_selection_get_selected(sel, &model, &iter)) {
+        g_message("activated");
+    } else {
+        g_message("none activated");
+    }
 }