; Module/File: Button_BoxImageToggle_gtk3.pb ; Function: Adding ButtonBox with ImageTogglebButtons - Linux gtk3 ; Author: Omi ; Date: Aug. 27, 2017 ; Version: 0.1 ; Target Compiler: PureBasic 5.22/5.3/5.4/5.5/5.6 ; Target OS: Linux: (X/K/L)ubuntu, Mint, 32/64, Ascii/Uni ;-------------------------------------------------------------- EnableExplicit ImportC "" g_signal_connect(*instance, detailed_signal.p-utf8, *c_handler, *data, destroy= 0, flags= 0) As "g_signal_connect_data" gtk_button_box_new(orientation) ; gtk_toggle_button_new_with_label(label.p-utf8) gtk_toggle_button_new() gtk_box_pack_start(*box.GtkBox, *child.GtkWidget, expand, fill, padding) gtk_box_set_spacing(*box.GtkBox, spacing) gtk_button_box_set_layout(*widget.GtkButtonBox, layout_style) gtk_button_box_set_child_secondary(*widget.GtkButtonBox, *child.GtkWidget, is_secondary) gtk_toggle_button_set_active(*toggle_button.GtkToggleButton, is_active) gtk_image_new_from_icon_name(icon_name.p-utf8, size) gtk_button_set_image(*button.GtkButton, *image.GtkWidget) EndImport ; Object constants #Win_Main = 0 #BBut1 = 0 #BBut2 = 1 #BBut3 = 2 #GTK_BUTTONBOX_CENTER= 5 Global.i gEvent, gEventGadget, gQuit Global *gButtonBox ProcedureC Callback_ButtonBoxResetSelection(*button.GtkButton, user_data) gtk_toggle_button_set_active(*button, #False) EndProcedure ProcedureC Callback_ButtonPressed(*widget.GtkWidget, *event.GdkEventButton, user_data) gtk_container_foreach_(*gButtonBox, @Callback_ButtonBoxResetSelection(), 0) If user_data = #BBut1 PostEvent(#PB_Event_Gadget, #Win_Main, #BBut1) ElseIf user_data = #BBut2 PostEvent(#PB_Event_Gadget, #Win_Main, #BBut2) ElseIf user_data = #BBut3 PostEvent(#PB_Event_Gadget, #Win_Main, #BBut3) EndIf EndProcedure Procedure.i ButtonBox(Gadget, x, y, w, h) Protected.i Container= ContainerGadget(Gadget, x, y, w, h, #PB_Container_BorderLess) Protected.GtkButtonBox *bbox = gtk_button_box_new(#GTK_ORIENTATION_HORIZONTAL) Protected.GtkButton *button1, *button2, *button3 Protected.GtkImage *image gtk_container_add_(GadgetID(Container), *bbox) ; gtk_button_box_set_layout(*bbox, #GTK_BUTTONBOX_CENTER) gtk_box_set_spacing(*bbox, -5) *button1= gtk_toggle_button_new() *image= gtk_image_new_from_icon_name("format-justify-left", #GTK_ICON_SIZE_MENU) gtk_button_set_image(*button1, *image) gtk_button_set_focus_on_click_(*button1, #False) gtk_box_pack_start(*bbox, *button1, #False, #False, 0) gtk_button_box_set_child_secondary(*bbox, *button1, #False) *button2= gtk_toggle_button_new() *image= gtk_image_new_from_icon_name("format-justify-center", #GTK_ICON_SIZE_MENU) gtk_button_set_image(*button2, *image) gtk_button_set_focus_on_click_(*button2, #False) gtk_box_pack_start(*bbox, *button2, #False, #False, 0) gtk_button_box_set_child_secondary(*bbox, *button2, #False) *button3= gtk_toggle_button_new() *image= gtk_image_new_from_icon_name("format-justify-right", #GTK_ICON_SIZE_MENU) gtk_button_set_image(*button3, *image) gtk_button_set_focus_on_click_(*button3, #False) gtk_box_pack_start(*bbox, *button3, #False, #False, 0) gtk_button_box_set_child_secondary(*bbox, *button3, #False) gtk_widget_show_all_(GadgetID(Container)) g_signal_connect(*button1, "button-press-event", @Callback_ButtonPressed(), #BBut1) g_signal_connect(*button2, "button-press-event", @Callback_ButtonPressed(), #BBut2) g_signal_connect(*button3, "button-press-event", @Callback_ButtonPressed(), #BBut3) CloseGadgetList() ProcedureReturn *bbox EndProcedure Procedure Create_WinMain() If OpenWindow(#Win_Main, 300, 200, 500, 200, "ButtonBox-ToggleButtons gtk3", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) *gButtonBox= ButtonBox(#PB_Any, 10, 10, 250, 32) EndIf EndProcedure Create_WinMain() Repeat gEvent= WaitWindowEvent() Select gEvent Case #PB_Event_CloseWindow gQuit= #True Case #PB_Event_Gadget gEventGadget= EventGadget() Select gEventGadget Case #BBut1 To #BBut3 Debug "ButtonBox-Button " + gEventGadget + " clicked" EndSelect EndSelect Until gQuit ; IDE Options = PureBasic 5.46 LTS Beta 1 (Linux - x86) ; CursorPosition = 14 ; Folding = - ; EnableUnicode ; EnableXP