; Module/File: MenuButton_Widget.pb ; Function: Add GtkMenuButton widget - Linux gtk3.6+ ; Author: Omi ; Date: Oct. 30, 2015 ; Version: 0.1 ; Target Compiler: PureBasic 5.22/5.31/5.40 ; Target OS: Linux: (X/K/L)ubuntu, Mint, 32/64, Ascii/Uni ;-------------------------------------------------------------- EnableExplicit ImportC "" gtk_menu_button_new() gtk_menu_button_set_popup(*menu_button, *popup.GtkWidget) gtk_menu_button_set_direction(*menu_button, direction) EndImport ; Object constants #Win_Main = 0 #But1 = 0 #But2 = 1 Enumeration GtkArrowType ; #GTK_ARROW_UP ; #GTK_ARROW_DOWN; default ; #GTK_ARROW_LEFT ; #GTK_ARROW_RIGHT #GTK_ARROW_NONE; no arrow, behaviour like #GTK_ARROW_DOWN EndEnumeration ;example popup items Enumeration PU1 #PU1_Main #PU1_1 #PU1_2 #PU1_3 #PU1_4 #PU1_5 EndEnumeration Enumeration PU2 #PB_Compiler_EnumerationValue #PU2_Main #PU2_1 #PU2_2 #PU2_3 #PU2_4 #PU2_5 EndEnumeration Global.i gEvent, gQuit ;example popups If CreatePopupMenu(#PU1_Main) MenuItem(#PU1_1, "Cut") MenuItem(#PU1_2, "Copy") MenuItem(#PU1_3, "Paste") MenuBar() MenuItem(#PU1_5, "Quit") EndIf If CreatePopupMenu(#PU2_Main) MenuItem(#PU2_1, "New") MenuItem(#PU2_2, "Open") MenuItem(#PU2_3, "Save") MenuBar() MenuItem(#PU2_5, "Cancel") EndIf Procedure.i MenuButtonGadget(Gadget, x, y, w, h, Menu, Direction= #GTK_ARROW_DOWN) Protected.i Container= ContainerGadget(Gadget, x, y, w, h, #PB_Container_BorderLess) Protected *mbutton= gtk_menu_button_new() If Gadget <> #PB_Any : Container= Gadget : EndIf gtk_menu_button_set_popup(*mbutton, MenuID(Menu)) gtk_menu_button_set_direction(*mbutton, Direction) gtk_container_add_(GadgetID(Container), *mbutton) gtk_widget_show_(*mbutton) CloseGadgetList() ProcedureReturn *mbutton EndProcedure If OpenWindow(#Win_Main, 0, 0, 400, 300, "MenuButton demo for gtk3.6+", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) MenuButtonGadget(#But1, 5, 5, 36, 30, #PU1_Main) MenuButtonGadget(#But2, 40, 5, 36, 30, #PU2_Main, #GTK_ARROW_RIGHT) Repeat gEvent= WaitWindowEvent() Select gEvent Case #PB_Event_CloseWindow gQuit= #True Case #PB_Event_Menu Debug EventMenu() EndSelect Until gQuit EndIf ; IDE Options = PureBasic 5.46 LTS Beta 1 (Linux - x86) ; CursorPosition = 23 ; Folding = - ; EnableUnicode ; EnableXP