2 versions of a Menu Bar import.
May 17, 2012 3:00:32 GMT 1
Post by SunBurnt on May 17, 2012 3:00:32 GMT 1
vovchik and I have been talking about this sort of thing.
Here is a standard Bacon way of doing it and a short syntax method.
I can`t get the CallBack "g_signal_connect_swapped" to work, typical for GTK+.
And both have a exit problem I can`t figure out, they just hang.
# This is the "Bacon normal" one:
This method does not have a clear method for doing sub menus.
# This is the "syntax short" one:
Here is a standard Bacon way of doing it and a short syntax method.
I can`t get the CallBack "g_signal_connect_swapped" to work, typical for GTK+.
And both have a exit problem I can`t figure out, they just hang.
# This is the "Bacon normal" one:
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Canned Code START.
CONST gtk$ = "libgtk-x11-2.0.so"
IMPORT "gtk_init(int*,void*)" FROM gtk$ TYPE void
IMPORT "gtk_window_new(int)" FROM gtk$ TYPE long
IMPORT "gtk_window_set_title(long,char*)" FROM gtk$ TYPE void
IMPORT "gtk_window_set_position(long,int)" FROM gtk$ TYPE void
IMPORT "gtk_widget_set_size_request(long,int,int)" FROM gtk$ TYPE void
IMPORT "gtk_vbox_new(int,int)" FROM gtk$ TYPE long
IMPORT "gtk_container_add(long,long)" FROM gtk$ TYPE void
IMPORT "gtk_menu_bar_new" FROM gtk$ TYPE long
IMPORT "gtk_menu_new" FROM gtk$ TYPE long
IMPORT "gtk_menu_item_new_with_label(char*)" FROM gtk$ TYPE long
IMPORT "gtk_menu_shell_append(long,long)" FROM gtk$ TYPE void
IMPORT "gtk_menu_item_set_submenu(long,long)" FROM gtk$ TYPE void
'IMPORT "gtk_separator_menu_item_new()
IMPORT "gtk_box_pack_start(long,long,int,int,int)" FROM gtk$ TYPE void
IMPORT "gtk_widget_show_all(long)" FROM gtk$ TYPE void
IMPORT "gtk_main_quit(void)" FROM gtk$ TYPE void
' *****************************
' SUBS & FUNCTIONS ( INCLUDE )
' *****************************
'SUB Open_CLICK
' PRINT "### Open"
'END SUB
FUNCTION MENU_BAR()
' define entire menu bar
RETURN gtk_menu_bar_new()
END FUNCTION
FUNCTION MENU_LIST(STRING list$, int bar_)
' create a menu list
list_ = gtk_menu_new()
' give it a name that will appear in the menu bar (not really a menu item)
name_ = gtk_menu_item_new_with_label(list$)
' add menu to menubar
gtk_menu_shell_append(bar_, name_)
' add menu to file list
gtk_menu_item_set_submenu(name_, list_)
RETURN list_
END FUNCTION
FUNCTION MENU_ITEM(STRING item$, int list_)
' create a menu item with label
item_ = gtk_menu_item_new_with_label(item$)
' add the item to the list
gtk_menu_shell_append(list_, item_)
RETURN item_
END FUNCTION
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Canned Code END.
'############### This part should be normal Bacon syntax in a separate Bacon file.
' start gtk
gtk_init(0, 0)
' create main window, and get ptr to it
win = gtk_window_new(0)
' set window title
gtk_window_set_title(win, "Menu Demo")
' set window size
gtk_widget_set_size_request(win, 300, 300)
' set window position (centred)
gtk_window_set_position(win, 1)
' make a vertical box with 0 pixel horizontal and 0 pixel vertical spacing
vbox = gtk_vbox_new(0, 0)
' add a vbox to window
gtk_container_add(win, vbox)
'############################### Main Bacon file, gui description data.
mBar_ = MENU_BAR()
mFile_ = MENU_LIST("File", mBar_)
mOpen_ = MENU_ITEM("Open", mFile_)
mSave_ = MENU_ITEM("Save", mFile_)
mSavAs_ = MENU_ITEM("Save As", mFile_)
mQuit_ = MENU_ITEM("Quit", mFile_)
mEdit_ = MENU_LIST("Edit", mBar_)
mCopy_ = MENU_ITEM("Copy", mEdit_)
mCut_ = MENU_ITEM("Cut", mEdit_)
mPaste_ = MENU_ITEM("Paste", mEdit_)
'################################### Part of main Bacon file also.
' add menu bar to top of vbox
gtk_box_pack_start(vbox, mBar_, 0, 0, 1)
' show the whole thing
gtk_widget_show_all(win)
' show gui
gtk_main()
END
This method does not have a clear method for doing sub menus.
# This is the "syntax short" one:
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Canned Code START.
CONST gtk$ = "libgtk-x11-2.0.so"
IMPORT "gtk_init(int*,void*)" FROM gtk$ TYPE void
IMPORT "gtk_window_new(int)" FROM gtk$ TYPE long
IMPORT "gtk_window_set_title(long,char*)" FROM gtk$ TYPE void
IMPORT "gtk_window_set_position(long,int)" FROM gtk$ TYPE void
IMPORT "gtk_widget_set_size_request(long,int,int)" FROM gtk$ TYPE void
IMPORT "gtk_vbox_new(int,int)" FROM gtk$ TYPE long
IMPORT "gtk_container_add(long,long)" FROM gtk$ TYPE void
IMPORT "gtk_menu_bar_new" FROM gtk$ TYPE long
IMPORT "gtk_menu_new" FROM gtk$ TYPE long
IMPORT "gtk_menu_item_new_with_label(char*)" FROM gtk$ TYPE long
IMPORT "gtk_menu_shell_append(long,long)" FROM gtk$ TYPE void
IMPORT "gtk_menu_item_set_submenu(long,long)" FROM gtk$ TYPE void
'IMPORT "gtk_separator_menu_item_new()
IMPORT "gtk_box_pack_start(long,long,int,int,int)" FROM gtk$ TYPE void
IMPORT "gtk_widget_show_all(long)" FROM gtk$ TYPE void
IMPORT "gtk_main_quit(void)" FROM gtk$ TYPE void
IMPORT "gtk_main" FROM gtk$ TYPE void
'===================== Menu(Menu Label) = Widget ID_
GLOBAL Menu ASSOC int
' *****************************
' SUBS & FUNCTIONS ( INCLUDE )
' *****************************
'SUB Open_CLICK
' PRINT "### Open"
'END SUB
SUB MENU(VAR item$ SIZE sz)
' define entire menu bar
IF Mfg = FALSE THEN
Mfg = TRUE
GLOBAL MnuBar_ TYPE int
MnuBar_ = gtk_menu_bar_new()
ELSE
' create menu list
Menu(item$[1]) = gtk_menu_new()
' give it a name that will appear in the menu bar (not really a menu item)
name_ = gtk_menu_item_new_with_label(item$[1])
' add file menu to menubar
gtk_menu_shell_append(MnuBar_, name_)
' add file menu to file list
gtk_menu_item_set_submenu(name_, Menu(item$[1]))
FOR i = 2 TO sz-1
'################## Attempt to get Menu Item Separator to work.
IF item$[i] = "|" THEN
' Menu(item$[i]) = gtk_separator_menu_item_new()
CONTINUE
END IF
' create first menu item
Menu(item$[i]) = gtk_menu_item_new_with_label(item$[i])
' add it as first item in list
gtk_menu_shell_append(Menu(item$[1]), Menu(item$[i]))
'##### Can`t get CallBack to work...
' g_signal_connect_swapped(G_OBJECT (Menu(item$[i])), "clicked",
' G_CALLBACK (CONCAT$(item$[i], "_CLICK")), (gpointer) Menu(item$[1]))
NEXT
END IF
END SUB
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Canned Code END.
'############### This part should be normal Bacon syntax in a separate Bacon file.
' start gtk
gtk_init(0, 0)
' create main window, and get ptr to it
win = gtk_window_new(0)
' set window title
gtk_window_set_title(win, "Menu Demo")
' set window size
gtk_widget_set_size_request(win, 300, 300)
' set window position (centred)
gtk_window_set_position(win, 1)
' make a vertical box with 0 pixel horizontal and 0 pixel vertical spacing
vbox = gtk_vbox_new(0, 0)
' add a vbox to window
gtk_container_add(win, vbox)
'############################### Main Bacon file, gui description data.
Mfg = FALSE
MENU("")
MENU("File", "Open", "Save", "Save As", "|", "Quit")
MENU("Edit", "Copy", "Cut", "Paste")
'################################### Part of main Bacon file also.
' add menu bar to top of vbox
gtk_box_pack_start(vbox, MnuBar_, 0, 0, 1)
' show the whole thing
gtk_widget_show_all(win)
' show gui
gtk_main()
END