[6.01] Different behaviour on Windows vs Ubuntu clicking

Post bugreports for the Windows version here
User avatar
marcoagpinto
Addict
Addict
Posts: 1051
Joined: Sun Mar 10, 2013 3:01 pm
Location: Portugal
Contact:

[6.01] Different behaviour on Windows vs Ubuntu clicking

Post by marcoagpinto »

Hello!

My app "About PureBasic" and "About" windows work differently on Windows 10 and Ubuntu 22.04.

Clicking anywhere in them is supposed to close the windows, EXCEPT:
1) clicking in the editor gadget ("About PureBasic");
2) Clicking in the hyperlinks ("About").

This works differently in Ubuntu 22.04.

http://proofingtoolgui.org/_other/Proof ... 230406.zip

Image

Could someone give it a try?

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

Re: [6.01] Different behaviour on Windows vs Ubuntu clicking

Post by mk-soft »

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()
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
Fred
Administrator
Administrator
Posts: 18199
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: [6.01] Different behaviour on Windows vs Ubuntu clicking

Post by Fred »

The code doesn't compile here, could you post a small snippet please ?
Post Reply