So I am trying to create a simple menu in GTK3+ using C. I am trying to recreate the menus found at:
https://web.archive.org/web/20141228062527/https://developer.gnome.org/gtk-tutorial/stable/x743.html
So I copied the code, and have been trying to isolate the parts I need, and covert said pieces to 3+. I have not had much luck with this code segment. First of all, gtk_option_menu is deprecated, and replaced with gtk_combo_box. I tried to find tutorials with that, but nothing came up.
Honestly, I don't even know the theory behind how to create a menu with GTK in the first place, so its very hard for me to do the conversion. I am flying practically blind here.
My code is below:
#include "/usr/include/gtk-3.0/gtk/gtk.h" static void print_stuff( GtkWidget *item, gpointer data) { printf("Hello World!\n"); return; } static GtkWidget *make_menu_item(gchar *name, GCallback callback, gpointer data ){ GtkWidget *item; item = gtk_menu_item_new_with_label (name); g_signal_connect (item, "activate", callback, (gpointer) data); gtk_widget_show (item); return item; } static void create_range_controls( void ){ GtkWidget *window; GtkWidget *box1, *box2, *box3; GtkWidget *button; GtkWidget *scrollbar; GtkWidget *separator; GtkWidget *opt, *menu, *item; GtkWidget *label; GtkWidget *scale; GObject *adj1, *adj2; window = gtk_window_new(GTK_WINDOW_TOPLEVEL); g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL); gtk_window_set_title(GTK_WINDOW(window), "range controls"); box1 = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); gtk_container_add(GTK_CONTAINER (window), box1); gtk_widget_show(box1); opt = gtk_option_menu_new (); menu = gtk_menu_new (); item = make_menu_item ("Top", G_CALLBACK (print_stuff), NULL); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); item = make_menu_item ("Bottom", G_CALLBACK (print_stuff), NULL); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); item = make_menu_item ("Left", G_CALLBACK (print_stuff), NULL); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); item = make_menu_item ("Right", G_CALLBACK (print_stuff), NULL); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); gtk_option_menu_set_menu(GTK_OPTION_MENU(opt), menu); gtk_box_pack_start(GTK_BOX (box1), opt, TRUE, TRUE, 0); gtk_widget_show(opt); gtk_widget_show (window); } int main( int argc, char *argv[] ){ gtk_init (&argc, &argv); create_range_controls (); gtk_main (); return 0; } Can anyone illustrate what I am doing wrong, and why? Are there any tutorials for GTK3+, like the one for GTK2+ that I linked above?
Thanks!
<gtk/gtk.h>and letpkg-configset the include search path correctly when compiling.pkg-config --libswhen building the program executable? The GTK+ 3 tutorial does describe this. (Alternatively you can forego the tutorial and go straight for the reference pages...)