I have managed to adapt my biggest PB program to Linux so that it works halfway. But the interface works very badly.
I only use BindEvent()-functions in the program and no normal event loop, and now there are problems with that. Because I don't understand why it doesn't work properly, I have written a test program.
If I only use BindEvent() functions, the adjustment of the controls does not work properly when the window is resized, for example. Unless you resize the window very slowly. I also cannot move the horizontal splitter.
If I set the constant #UseBindEvents to zero, for the use of a normal event loop, everything works.
An error like the one I reported here only occurs with BindGagetEvent():
PBv6.20b4 - Panel index is incorrect with BindGadgetEvent()
https://www.purebasic.fr/english/viewtopic.php?t=86213
My program runs its own scripting language, with threads, PostEvent() and BindEvent() functions in modules. I can't imagine changing the program to an event loop, it's not worth the effort.
Does anyone have experience with using BindEvent() functions and Linux? Am I doing something wrong or does it depend on the Linux distro or desktop?
Peter
Code: Select all
EnableExplicit
#UseBindEvents = 1 ; 1 = BindEvent(), 0 = Event Loop
#UseScintillaEditor = 1 ; 1 = ScintillaGadget, 0 = EditorGadget
UsePNGImageDecoder()
;- eWindow
Enumeration eWindow
#eWindowStart
EndEnumeration
;- eMenu
Enumeration eMenu
#eMenu
EndEnumeration
;- eMenuItem
Enumeration eMenuItem
#eMenuItemFileExit
#eMenuItemEditUndo
EndEnumeration
;- eToolbar
Enumeration eToolbar
#eToolbar
EndEnumeration
;- eToolbarButton
Enumeration eToolbarButton
#eToolbarButtonFile
#eToolbarButtonEdit
EndEnumeration
;- eStatusbar
Enumeration eStatusbar
#eStatusbar
EndEnumeration
;. eStatusbarField
Enumeration eStatusbarField
#eStatusbarFieldInfo
EndEnumeration
;- eGadget
Enumeration eGadget
#eSplitterContainer
#eContainerLeft
#ePanelLeft
#eSplitterLeft
#eContainerRight
#ePanelRight
#eSplitterRight
#eEditor1
#eOutput1
#eSplitterEditor1
#eEditor2
#eOutput2
#eSplitterEditor2
EndEnumeration
Procedure EventSizeWindow()
Protected iWindowWidth.i, iWindowHeight.i, iMenuHeight.i, iToolbarHeight.i, iStatusbarHeight.i
Protected iLeft.i, iTop.i, iWidth.i, iHeight.i
iWindowWidth = WindowWidth(#eWindowStart)
iWindowHeight = WindowHeight(#eWindowStart)
iMenuHeight = MenuHeight()
iToolbarHeight = ToolBarHeight(#eToolbar)
iStatusbarHeight = StatusBarHeight(#eStatusbar)
iLeft = 0
iTop = 0
iWidth = iWindowWidth
iHeight = iWindowHeight - iMenuHeight - iToolbarHeight - iStatusbarHeight
ResizeGadget(#eSplitterContainer, iLeft, iTop, iWidth, iHeight)
EndProcedure
Procedure EventResizeContainerLeft()
Protected iLeft.i, iTop.i, iWidth.i, iHeight.i
iLeft = 0
iTop = 0
iWidth = GadgetWidth(#eContainerLeft)
iHeight = GadgetHeight(#eContainerLeft)
ResizeGadget(#ePanelLeft, iLeft, iTop, iWidth, iHeight)
EndProcedure
Procedure EventChangePanelRight()
Protected iLeft.i, iTop.i, iWidth.i, iHeight.i, iIndex.i
iLeft = 0
iTop = 0
; iWidth = GadgetWidth(#ePanelRight)
; iHeight = GadgetHeight(#ePanelRight)
iWidth = GetGadgetAttribute(#ePanelRight, #PB_Panel_ItemWidth)
iHeight = GetGadgetAttribute(#ePanelRight, #PB_Panel_ItemHeight)
Select GetGadgetState(#ePanelRight)
Case 0
ResizeGadget(#eSplitterEditor1, iLeft, iTop, iWidth, iHeight)
Case 1
ResizeGadget(#eSplitterEditor2, iLeft, iTop, iWidth, iHeight)
EndSelect
EndProcedure
Procedure EventResizeContainerRight()
Protected iLeft.i, iTop.i, iWidth.i, iHeight.i
iLeft = 0
iTop = 0
iWidth = GadgetWidth(#eContainerRight)
iHeight = GadgetHeight(#eContainerRight)
ResizeGadget(#ePanelRight, iLeft, iTop, iWidth, iHeight)
EventChangePanelRight()
EndProcedure
Procedure WindowCreateMenu()
CreateMenu(#eMenu, WindowID(#eWindowStart))
MenuTitle("File")
MenuItem(#eMenuItemFileExit, "&Exit")
MenuTitle("Edit")
MenuItem(#eMenuItemEditUndo, "&Undo")
EndProcedure
Procedure WindowCreateToolbar()
Protected sPath.s
sPath = #PB_Compiler_Home + "examples" + #PS$ + "sources" + #PS$ + "Data" + #PS$ + "ToolBar" + #PS$
CreateToolBar(#eToolbar, WindowID(#eWindowStart), #PB_ToolBar_Large)
ToolBarImageButton(#eToolbarButtonFile, LoadImage(0, sPath + "New.png"))
ToolBarImageButton(#eToolbarButtonEdit, LoadImage(1, sPath + "Open.png"))
EndProcedure
Procedure WindowCreateStatusbar()
CreateStatusBar(#eStatusbar, WindowID(#eWindowStart))
AddStatusBarField(#PB_Ignore)
AddStatusBarField(#PB_Ignore)
AddStatusBarField(50)
EndProcedure
Procedure WindowCreateGadgets()
ContainerGadget(#eContainerLeft, 0, 0, 100, 100, #PB_Container_Flat );, #PB_Container_BorderLess)
PanelGadget(#ePanelLeft, 0, 0, 100, 100)
AddGadgetItem(#ePanelLeft, #PB_Default, "Panel 1")
AddGadgetItem(#ePanelLeft, #PB_Default, "Panel 2")
CloseGadgetList()
CloseGadgetList()
ContainerGadget(#eContainerRight, 110, 0, 100, 100, #PB_Container_Flat );, #PB_Container_BorderLess)
PanelGadget(#ePanelRight, 0, 0, 100, 100)
AddGadgetItem(#ePanelRight, -1, "Panel 1")
CompilerIf Not #UseScintillaEditor
EditorGadget(#eEditor1, 0, 0, 100, 50)
EditorGadget(#eOutput1, 0, 50, 100, 50)
CompilerElse
ScintillaGadget(#eEditor1, 0, 0, 100, 50, #Null)
ScintillaGadget(#eOutput1, 0, 50, 100, 50, #Null)
CompilerEndIf
SplitterGadget(#eSplitterEditor1, 0, 0, 100, 100, #eEditor1, #eOutput1)
AddGadgetItem(#ePanelRight, -1, "Panel 2")
CompilerIf Not #UseScintillaEditor
EditorGadget(#eEditor2, 0, 0, 100, 50, #Null)
EditorGadget(#eOutput2, 0, 50, 100, 50, #Null)
CompilerElse
ScintillaGadget(#eEditor2, 0, 0, 100, 50, #Null)
ScintillaGadget(#eOutput2, 0, 50, 100, 50, #Null)
CompilerEndIf
SplitterGadget(#eSplitterEditor2, 0, 0, 100, 100, #eEditor2, #eOutput2)
CloseGadgetList()
CloseGadgetList()
SplitterGadget(#eSplitterContainer, 0, 0, WindowWidth(#eWindowStart), 200, #eContainerLeft, #eContainerRight,
#PB_Splitter_Vertical) ; | #PB_Splitter_FirstFixed) ; | #PB_Splitter_Separator)
SetGadgetState(#eSplitterContainer, WindowWidth(#eWindowStart) / 2)
EndProcedure
Procedure WindowBindEvents()
BindEvent(#PB_Event_SizeWindow, @EventSizeWindow(), #eWindowStart)
BindGadgetEvent(#eContainerLeft, @EventResizeContainerLeft(), #PB_EventType_Resize)
BindGadgetEvent(#eContainerRight, @EventResizeContainerRight(), #PB_EventType_Resize)
BindGadgetEvent(#ePanelRight, @EventChangePanelRight(), #PB_EventType_Change)
EndProcedure
Procedure WindowOpen()
If OpenWindow(#eWindowStart, #PB_Default, #PB_Default, 800, 600, "WindowStart",
#PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget |
#PB_Window_SizeGadget | #PB_Window_ScreenCentered | #PB_Window_Invisible)
WindowCreateMenu()
WindowCreateToolbar()
WindowCreateStatusbar()
WindowCreateGadgets()
CompilerIf #UseBindEvents
WindowBindEvents()
CompilerEndIf
HideWindow(#eWindowStart, #False)
EndIf
EndProcedure
Procedure Main()
Protected iEvent.i
WindowOpen()
PostEvent(#PB_Event_SizeWindow, #eWindowStart, 0)
Repeat
iEvent = WaitWindowEvent()
If iEvent = #PB_Event_CloseWindow
Break
EndIf
CompilerIf Not #UseBindEvents
Select iEvent
Case #PB_Event_SizeWindow
EventSizeWindow()
Case #PB_Event_Gadget
Select EventGadget()
Case #eContainerLeft
Select EventType()
Case #PB_EventType_Resize
EventResizeContainerLeft()
EndSelect
Case #eContainerRight
Select EventType()
Case #PB_EventType_Resize
EventResizeContainerRight()
EndSelect
Case #ePanelRight
Select EventType()
Case #PB_EventType_Change
EventChangePanelRight()
EndSelect
EndSelect
EndSelect
CompilerEndIf
ForEver
EndProcedure
Main()