Problems with BindEvent functions

Linux specific forum
PeDe
Enthusiast
Enthusiast
Posts: 284
Joined: Sun Nov 26, 2017 3:13 pm

Problems with BindEvent functions

Post by PeDe »

I'm trying to switch from Windows 7 to Linux Mint 22.1 Cinnamon and at the moment I'm getting by.

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()

User avatar
mk-soft
Always Here
Always Here
Posts: 6245
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Problems with BindEvent functions

Post by mk-soft »

Is somehow a bug with the update order of the client splitter gadgets to be.
If you update them at the very end, it goes ...
So not with BindGadgetEvent.

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
  Debug #PB_Compiler_Procedure
	
	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
  Debug #PB_Compiler_Procedure
	
	iLeft = 0
	iTop = 0
	iWidth = GadgetWidth(#eContainerLeft)
	iHeight = GadgetHeight(#eContainerLeft)
	Debug "dx: " + iWidth + " / dy: " + iHeight
	ResizeGadget(#ePanelLeft, iLeft, iTop, iWidth, iHeight)
EndProcedure


Procedure EventResizePanelRight()
	Protected iLeft.i, iTop.i, iWidth.i, iHeight.i, iIndex.i, item
  Debug #PB_Compiler_Procedure
	
	iLeft = 0
	iTop = 0
; 	iWidth = GadgetWidth(#ePanelRight)
; 	iHeight = GadgetHeight(#ePanelRight)
	iWidth = GetGadgetAttribute(#ePanelRight, #PB_Panel_ItemWidth)
	iHeight = GetGadgetAttribute(#ePanelRight, #PB_Panel_ItemHeight)
	Debug "dx: " + iWidth + " / dy: " + iHeight
	ResizeGadget(#eSplitterEditor1, iLeft, iTop, iWidth, iHeight)
	ResizeGadget(#eSplitterEditor2, iLeft, iTop, iWidth, iHeight)
EndProcedure


Procedure EventResizeContainerRight()
	Protected iLeft.i, iTop.i, iWidth.i, iHeight.i
	Debug #PB_Compiler_Procedure
	
	iLeft = 0
	iTop = 0
	iWidth = GadgetWidth(#eContainerRight)
	iHeight = GadgetHeight(#eContainerRight)
	Debug "dx: " + iWidth + " / dy: " + iHeight
	ResizeGadget(#ePanelRight, iLeft, iTop, iWidth, iHeight)
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)
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(100)
		Select iEvent
		  Case #PB_Event_CloseWindow
		    Break
		  Case #PB_Event_Gadget
		    Select EventGadget()
		      Case #ePanelRight
						Select EventType()
							Case #PB_EventType_Resize
								EventResizePanelRight()
						EndSelect
				EndSelect
				
		EndSelect
		
		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_Resize
								EventResizePanelRight()
						EndSelect
						
				EndSelect
		EndSelect
		CompilerEndIf
	ForEver
EndProcedure


Main()

My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PeDe
Enthusiast
Enthusiast
Posts: 284
Joined: Sun Nov 26, 2017 3:13 pm

Re: Problems with BindEvent functions

Post by PeDe »

Thank you, I will see if I can use a smaller event loop.
It is strange that the procedures are executed in the same order, no matter if BindEvent, Event-Loop or Windows versus Linux.

Peter
PeDe
Enthusiast
Enthusiast
Posts: 284
Joined: Sun Nov 26, 2017 3:13 pm

Re: Problems with BindEvent functions

Post by PeDe »

The test program only works with BindEvent() functions. But only if you move the mouse pointer over the inactive panel tab.
Every time after the start, when the window size is changed or the vertical splitter is moved, you have to move over the inactive panel tab.

The function ResizeGadget(#ePanelRight, ...) also triggers a resize event for the panel, that shouldn't be the case, should it?

Peter

Code: Select all

EnableExplicit

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 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)

EndProcedure


Procedure EventResizePanelRight()
	Protected iLeft.i, iTop.i, iWidth.i, iHeight.i, iIndex.i, item
	Debug #PB_Compiler_Procedure
	
	iLeft = 0
	iTop = 0
	iWidth = GetGadgetAttribute(#ePanelRight, #PB_Panel_ItemWidth)
	iHeight = GetGadgetAttribute(#ePanelRight, #PB_Panel_ItemHeight)
	ResizeGadget(#eSplitterEditor1, iLeft, iTop, iWidth, iHeight)
	ResizeGadget(#eSplitterEditor2, iLeft, iTop, iWidth, iHeight)
	
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")
	ScintillaGadget(#eEditor1, 0, 0, 100, 50, #Null)
	ScintillaGadget(#eOutput1, 0, 50, 100, 50, #Null)
	SplitterGadget(#eSplitterEditor1, 0, 0, 100, 100, #eEditor1, #eOutput1)
	
	AddGadgetItem(#ePanelRight, -1, "Panel 2")
	ScintillaGadget(#eEditor2, 0, 0, 100, 50, #Null)
	ScintillaGadget(#eOutput2, 0, 50, 100, 50, #Null)
	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, @EventResizePanelRight(), #PB_EventType_Resize)

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()
		WindowBindEvents()
		
		HideWindow(#eWindowStart, #False)
	EndIf

EndProcedure


Procedure Main()
	Protected iEvent.i
	
	WindowOpen()
	PostEvent(#PB_Event_SizeWindow)

	Repeat
	Until  WaitWindowEvent() = #PB_Event_CloseWindow
	
EndProcedure


Main()

User avatar
mk-soft
Always Here
Always Here
Posts: 6245
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Problems with BindEvent functions

Post by mk-soft »

I can vaguely remember that there was a problem with the GTK update and not all data from Parent Gadget was ready
Thus, I did the resize of client gadget only a cycle later.

And see. It works ...

Code: Select all

EnableExplicit

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 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)

EndProcedure


Procedure EventResizePanelRight()
	Protected iLeft.i, iTop.i, iWidth.i, iHeight.i, iIndex.i, item
	Debug #PB_Compiler_Procedure
	
	If EventData() = 999
	  ; Is now one cyclus later
  	iLeft = 0
  	iTop = 0
  	iWidth = GetGadgetAttribute(#ePanelRight, #PB_Panel_ItemWidth)
  	iHeight = GetGadgetAttribute(#ePanelRight, #PB_Panel_ItemHeight)
  	ResizeGadget(#eSplitterEditor1, iLeft, iTop, iWidth, iHeight)
  	ResizeGadget(#eSplitterEditor2, iLeft, iTop, iWidth, iHeight)
  Else
    ; Do event one cyclus later
    PostEvent(Event(), EventWindow(), EventGadget(), EventType(), 999)
  EndIf
  	
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")
	ScintillaGadget(#eEditor1, 0, 0, 100, 50, #Null)
	ScintillaGadget(#eOutput1, 0, 50, 100, 50, #Null)
	SplitterGadget(#eSplitterEditor1, 0, 0, 100, 100, #eEditor1, #eOutput1)
	
	AddGadgetItem(#ePanelRight, -1, "Panel 2")
	ScintillaGadget(#eEditor2, 0, 0, 100, 50, #Null)
	ScintillaGadget(#eOutput2, 0, 50, 100, 50, #Null)
	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, @EventResizePanelRight(), #PB_EventType_Resize)
  
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()
		WindowBindEvents()
		
		HideWindow(#eWindowStart, #False)
	EndIf

EndProcedure


Procedure Main()
	Protected iEvent.i
	
	WindowOpen()
	PostEvent(#PB_Event_SizeWindow)

	Repeat
	  Select WaitWindowEvent()
	    Case #PB_Event_CloseWindow
	      Break
	      
	    Case #PB_Event_Gadget
	      Select EventGadget()
	        Case #ePanelRight
	          ;EventResizePanelRight()
	          
	      EndSelect
	      
	  EndSelect
	ForEver
	
EndProcedure


Main()

My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PeDe
Enthusiast
Enthusiast
Posts: 284
Joined: Sun Nov 26, 2017 3:13 pm

Re: Problems with BindEvent functions

Post by PeDe »

Thank you, I have incorporated your changes into my program and it works almost correctly. I still have to change a few things, but that should be the solution.

Peter
Post Reply