Code: Select all
;-TOP
; *******************************************************************************
CompilerIf #PB_Compiler_OS = #PB_OS_Linux And #PB_Compiler_Version < 600
; Workaround : GTK3 v3.24.33 (Wayland)
; Author : mk-soft
; Version : v1.03.1
; Update : 03.07.2022
Global IsWayland = Bool(GetEnvironmentVariable("XDG_SESSION_TYPE") = "wayland")
Procedure GTK3_WindowWidth(Window, Flags = #PB_Window_InnerCoordinate)
Protected r1
If IsWayland
gtk_window_get_size_(WindowID(Window), @r1, 0)
If Flags = #PB_Window_FrameCoordinate
r1 + WindowX(Window, #PB_Window_InnerCoordinate) - WindowX(Window, #PB_Window_FrameCoordinate)
EndIf
ProcedureReturn r1
Else
ProcedureReturn WindowWidth(Window)
EndIf
EndProcedure
Procedure GTK3_WindowHeight(Window, Flags = #PB_Window_InnerCoordinate)
Protected r1
If IsWayland
gtk_window_get_size_(WindowID(Window), 0, @r1)
If Flags = #PB_Window_FrameCoordinate
r1 + WindowY(Window, #PB_Window_InnerCoordinate) - WindowY(Window, #PB_Window_FrameCoordinate)
EndIf
ProcedureReturn r1
Else
ProcedureReturn WindowHeight(Window)
EndIf
EndProcedure
Procedure GTK3_OpenWindow(Window, x, y, InnerWidth, InnerHeight, Title$, Flags = 0, ParentID = 0)
Protected r1, win, winID, hints.GdkGeometry
If ParentID
r1 = OpenWindow(Window, x, y, InnerWidth, InnerHeight, Title$, Flags, ParentID)
Else
r1 = OpenWindow(Window, x, y, InnerWidth, InnerHeight, Title$, Flags)
EndIf
If IsWayland
If Window = #PB_Any
win = r1
Else
win = window
EndIf
winID = WindowID(win)
If Not gtk_window_get_resizable_(winID)
hints\max_width = 4096; 4k
hints\max_height = 2160; 4k
gtk_window_set_geometry_hints_(winID, winID, @hints, #GDK_HINT_MAX_SIZE);
gtk_window_resize_(winID, InnerWidth, InnerHeight)
EndIf
gtk_window_move_(winID, x, y)
EndIf
ProcedureReturn r1
EndProcedure
Procedure GTK3_ResizeWindow(Window, x, y, InnerWidth, Innerheight)
Protected winID = WindowID(Window)
If IsWayland
If x = #PB_Ignore
x = WindowX(Window)
EndIf
If y = #PB_Ignore
y = WindowY(Window)
EndIf
gtk_window_resize_(winID, InnerWidth, Innerheight)
gtk_window_move_(winID, x, y)
Else
ResizeWindow(Window, x, y, InnerWidth, Innerheight)
EndIf
EndProcedure
Macro WindowWidth(Window, Flags = #PB_Window_InnerCoordinate)
GTK3_WindowWidth(Window, Flags)
EndMacro
Macro WindowHeight(Window, Flags = #PB_Window_InnerCoordinate)
GTK3_WindowHeight(Window, Flags)
EndMacro
Macro OpenWindow(Window, x, y, InnerWidth, InnerHeight, Title, Flags = 0, ParentID = 0)
GTK3_OpenWindow(Window, x, y, InnerWidth, InnerHeight, Title, Flags, ParentID)
EndMacro
Macro ResizeWindow(Window, x, y, InnerWidth, Innerheight)
GTK3_ResizeWindow(Window, x, y, InnerWidth, Innerheight)
EndMacro
; *******************************************************************************
; Comment : CSS-Style min-height and padding
; Author : mk-soft,
; Version : v1.01.0
; Update :21.05.2022
;- Constants
#GTK_STYLE_PROVIDER_PRIORITY_FALLBACK = 1
#GTK_STYLE_PROVIDER_PRIORITY_THEME = 200
#GTK_STYLE_PROVIDER_PRIORITY_SETTINGS = 400
#GTK_STYLE_PROVIDER_PRIORITY_APPLICATION = 600
#GTK_STYLE_PROVIDER_PRIORITY_USER = 800
ImportC ""
gtk_css_provider_load_from_data(*CSSProvider, CSSData.P-UTF8, Length, *Error.GError)
gtk_css_provider_new()
gtk_style_context_add_provider_for_screen(*Screen.GdkScreen, *StyleProvider, Priority)
EndImport
Procedure _SetLinuxStyle()
Protected CSSProvider, CSSDefault.s, Screen
CSSDefault = "button, entry {min-height: 20px;} "
CSSDefault + "tab {min-height: 20px;} "
CSSDefault + "button, scale {padding-bottom: 2px; padding-left: 2px; padding-right: 2px; padding-top: 2px} "
CSSProvider= gtk_css_provider_new()
gtk_css_provider_load_from_data(CSSProvider, CSSDefault, -1, 0)
Screen = gdk_display_get_default_screen_(gdk_display_get_default_())
gtk_style_context_add_provider_for_screen(Screen, CSSProvider, #GTK_STYLE_PROVIDER_PRIORITY_APPLICATION)
g_object_unref_(CSSProvider)
EndProcedure : _SetLinuxStyle()
CompilerEndIf
; *******************************************************************************
CompilerIf #PB_Compiler_IsMainFile
ImportC ""
gtk_get_major_version()
gtk_get_minor_version()
gtk_get_micro_version()
EndImport
Procedure.s GtkGetVersionString()
Protected major, minor, micro
major = gtk_get_major_version()
minor = gtk_get_minor_version()
micro = gtk_get_micro_version()
ProcedureReturn "" + major + "." + minor + "." + micro
EndProcedure
#WindowWidth = 390
#WindowHeight = 350
If OpenWindow(0, 100, 200, #WindowWidth, #WindowHeight, "PureBasic - Gadget Demonstration", #PB_Window_MinimizeGadget); | #PB_Window_MaximizeGadget)
Top = 10
GadgetHeight = 24
FrameGadget(#PB_Any, 10, Top, 370, 290, "Player...") : Top+20
StringGadget(0, 20, Top, 200, GadgetHeight, "")
ButtonGadget(1, 223, Top, 72, GadgetHeight, "Play")
ButtonGadget(2, 295, Top, 72, GadgetHeight, "Stop") : Top+35
DisableGadget(2,1)
GadgetToolTip(1,"Play the current song")
PanelGadget(3, 20, Top, #WindowWidth-50, #WindowHeight-Top-60)
AddGadgetItem(3, 0, "MP3 PlayList")
ListViewGadget(4, 6, 10, 230, 148)
For k=0 To 30
AddGadgetItem(4, -1, "Music Song n° "+Str(k))
Next
ButtonGadget(5, 250, 10, 80, GadgetHeight, "Add")
ButtonGadget(6, 250, 38, 80, GadgetHeight, "Remove")
ButtonGadget(7, 250, 66, 80, GadgetHeight, "Select")
GadgetToolTip(7, "Select the current song")
TrackBarGadget(17, 10, 168, 310, 25, 0, 100)
AddGadgetItem(3, 1, "Options")
Top = 10
CheckBoxGadget(10, 10, Top, 250, GadgetHeight, "Enable low-pass filter") : Top+30
CheckBoxGadget(11, 10, Top, 250, GadgetHeight, "Enable visual plug-in") : Top+30
ComboBoxGadget(12, 10, Top, 250, 21) : Top+30
AddGadgetItem(12, -1, "FireWorks")
AddGadgetItem(12, -1, "OpenGL spectrum")
AddGadgetItem(12, -1, "Bump bass")
SetGadgetState(12,0)
DisableGadget(12,1)
OptionGadget(13, 10, Top, 80, GadgetHeight, "640*480") : Top+20
OptionGadget(14, 10, Top, 80, GadgetHeight, "800*600") : Top+20
OptionGadget(15, 10, Top, 80, GadgetHeight, "1024*768")
SetGadgetState(13, 1)
ButtonGadget(16, 150, Top, 80, GadgetHeight, "Info")
CloseGadgetList()
TextGadget (9, 10, #WindowHeight-30, 250, 24, "PureBasic - Gadget demonstration")
ButtonGadget(8, #WindowWidth-100, #WindowHeight-36, 80, 24, "Quit")
SetGadgetState(3, 0)
Debug "GTK Version: " + GtkGetVersionString()
Debug "XDG_SESSION_TYPE: " + GetEnvironmentVariable("XDG_SESSION_TYPE")
Debug "InnerWidth: " + WindowWidth(0)
Debug "FrameWidth: " + WindowWidth(0, #PB_Window_FrameCoordinate)
Debug "InnerHeight: " + WindowHeight(0)
Debug "FrameHeight: " + WindowHeight(0, #PB_Window_FrameCoordinate)
;ResizeWindow(0, 200, 200, #WindowWidth, #WindowHeight + 100)
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_Gadget
Select EventGadget()
Case 1 ; Play
DisableGadget(2,0) ; Enable the 'Stop' gadget
DisableGadget(1,1) ; Disable the 'Play' Gadget
Case 2 ; Stop
DisableGadget(1,0) ; Enable the 'Play' gadget
DisableGadget(2,1) ; Disable the 'Stop' Gadget
Case 4
If EventType() = 2
SetGadgetText(0, GetGadgetText(4)) ; Get the current item from the ListView..
EndIf
Case 5 ; Add
AddGadgetItem(4, -1, "New Item Added...")
Case 6 ; Remove
RemoveGadgetItem(4, GetGadgetState(4)) ; Remove the current element of the ListView
Case 7 ; Select
SetGadgetText(0, GetGadgetText(4)) ; Get the current item from the ListView..
Case 8 ; Quit...
Event = #PB_Event_CloseWindow
Case 11 ; Enable PlugIn..
DisableGadget(12, 1-GetGadgetState(11))
Case 16 ;
If GetGadgetState(13) : Result$ = GetGadgetText(13) : EndIf
If GetGadgetState(14) : Result$ = GetGadgetText(14) : EndIf
If GetGadgetState(15) : Result$ = GetGadgetText(15) : EndIf
MessageRequester("Info", "Selected screen mode: "+Result$, 0)
Case 17
SetGadgetText(0, Str(GetGadgetState(17)))
EndSelect
EndIf
Until Event = #PB_Event_CloseWindow
EndIf
End
CompilerEndIf