The OS behave differently internally in event management.
Here is a solution with MouseOver ...
New bug found. ImageGadget does not work under Windows in the CanvasGadget container.
Code: Select all
;-TOP
#ProgramTitle = "Main Window"
#ProgramVersion = "v1.01.2"
Enumeration Windows
#Main
EndEnumeration
Enumeration MenuBar
#MainMenu
EndEnumeration
Enumeration MenuItems
#MainMenuAbout
#MainMenuExit
EndEnumeration
Enumeration Gadgets
#MainCanvas
#MainImage
#MainLink
EndEnumeration
Enumeration StatusBar
#MainStatusBar
EndEnumeration
; ----
Procedure MouseOver() ; Retval handle
Protected handle, window
window = GetActiveWindow()
If window < 0
ProcedureReturn 0
EndIf
; Get handle under mouse
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Windows
Protected pt.q
GetCursorPos_(@pt)
handle = WindowFromPoint_(pt)
CompilerCase #PB_OS_MacOS
Protected win_id, win_cv, pt.NSPoint
win_id = WindowID(window)
win_cv = CocoaMessage(0, win_id, "contentView")
CocoaMessage(@pt, win_id, "mouseLocationOutsideOfEventStream")
handle = CocoaMessage(0, win_cv, "hitTest:@", @pt)
CompilerCase #PB_OS_Linux
Protected desktop_x, desktop_y, *GdkWindow.GdkWindowObject
*GdkWindow.GdkWindowObject = gdk_window_at_pointer_(@desktop_x,@desktop_y)
If *GdkWindow
gdk_window_get_user_data_(*GdkWindow, @handle)
Else
handle = 0
EndIf
CompilerEndSelect
ProcedureReturn handle
EndProcedure
; ----
Procedure UpdateWindow()
Protected dx, dy
dx = WindowWidth(#Main)
dy = WindowHeight(#Main) - StatusBarHeight(#MainStatusBar) - MenuHeight()
; Resize gadgets
EndProcedure
Procedure Main()
Protected dx, dy, image
#MainStyle = #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget
If OpenWindow(#Main, #PB_Ignore, #PB_Ignore, 800, 600, #ProgramTitle , #MainStyle)
; Menu
CreateMenu(#MainMenu, WindowID(#Main))
MenuTitle("&File")
CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
MenuItem(#PB_Menu_About, "")
CompilerElse
MenuItem(#MainMenuAbout, "About")
CompilerEndIf
; Menu File Items
CompilerIf Not #PB_Compiler_OS = #PB_OS_MacOS
MenuBar()
MenuItem(#MainMenuExit, "E&xit")
CompilerEndIf
; StatusBar
CreateStatusBar(#MainStatusBar, WindowID(#Main))
AddStatusBarField(#PB_Ignore)
; Images
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
image = LoadImage(0, #PB_Compiler_Home + "Examples\Sources\Data\PureBasic.bmp")
CompilerElse
image = LoadImage(0, #PB_Compiler_Home + "examples/sources/Data/PureBasic.bmp")
CompilerEndIf
; Gadgets
dx = WindowWidth(#Main)
dy = WindowHeight(#Main) - StatusBarHeight(#MainStatusBar) - MenuHeight()
CanvasGadget(#MainCanvas, 0, 0, dx, dy/2, #PB_Canvas_Container | #PB_Canvas_Keyboard)
SetGadgetColor(#MainCanvas, #PB_Gadget_BackColor, $8CE6F0)
ImageGadget(#MainImage, 10, 10, ImageWidth(0), ImageHeight(0), ImageID(0))
CloseGadgetList()
HyperLinkGadget(#MainLink, 10, dy/2 + 10, 100, 25, "Hyperlink", #Blue)
; Bind Events
BindEvent(#PB_Event_SizeWindow, @UpdateWindow(), #Main)
Debug (WindowID(#Main))
; Event Loop
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Select EventWindow()
Case #Main
Break
EndSelect
Case #PB_Event_Menu
Select EventMenu()
CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
Case #PB_Menu_About
PostEvent(#PB_Event_Menu, #Main, #MainMenuAbout)
Case #PB_Menu_Preferences
Case #PB_Menu_Quit
PostEvent(#PB_Event_CloseWindow, #Main, #Null)
CompilerEndIf
Case #MainMenuAbout
MessageRequester("About", #ProgramTitle + #LF$ + #ProgramVersion, #PB_MessageRequester_Info)
Case #MainMenuExit
PostEvent(#PB_Event_CloseWindow, #Main, #Null)
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
Case #MainCanvas
Select EventType()
Case #PB_EventType_LeftClick
Debug "Canvas left click"
CompilerIf #PB_Compiler_OS = #PB_OS_Linux
If MouseOver() = GadgetID(#MainCanvas)
Debug "Can be close"
EndIf
CompilerElse
Debug "Can be close"
CompilerEndIf
EndSelect
Case #MainImage
Debug "Image left click"
Case #MainLink
Debug "Link left click"
EndSelect
Case #PB_Event_LeftClick
Debug "Window left click"
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Linux
win_id = gtk_widget_get_parent_(MouseOver())
win_id = gtk_widget_get_parent_(win_id)
If win_id = WindowID(GetActiveWindow())
Debug "Can be close"
EndIf
CompilerCase #PB_OS_MacOS
win_cv = CocoaMessage(0, WindowID(GetActiveWindow()), "contentView")
If MouseOver() = win_cv
Debug "Can be close"
EndIf
CompilerCase #PB_OS_Windows
If MouseOver() = WindowID(GetActiveWindow())
Debug "Can be close"
EndIf
CompilerEndSelect
EndSelect
ForEver
EndIf
EndProcedure : Main()