Restore window event not firing

Mac OSX specific forum
coco2
Enthusiast
Enthusiast
Posts: 461
Joined: Mon Nov 25, 2013 5:38 am
Location: Australia

Restore window event not firing

Post by coco2 »

Why doesn't restore event fire on Mac? In the below code, it doesn't show in debug "Restore" even when you restore the window.

Code: Select all

OpenWindow(0, 0, 0, 600, 600, "Restore", #PB_Window_SystemMenu | #PB_Window_MaximizeGadget| #PB_Window_ScreenCentered)
Repeat
  Event = WaitWindowEvent(10)
  Select Event
    Case #PB_Event_MaximizeWindow
      Debug "Maximise"
    Case #PB_Event_RestoreWindow
      Debug "Restore"
      ; This is not displayed when restoring
  EndSelect
Until Event = #PB_Event_CloseWindow
User avatar
mk-soft
Always Here
Always Here
Posts: 6245
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Restore window event not firing

Post by mk-soft »

Missing observer for full screen ...

Found this on my templates

Code: Select all

;-TOP by mk-soft, v1.02, 29.10.2022

; PB intern function to get window PB_ID (Only on macOS) 
Import ""
  PB_Window_GetID(Object)
EndImport

Enumeration CustomEvent #PB_Event_FirstCustomValue
  #MyEvent_ResizeDone
  #MyEvent_EnterFullScreen
  #MyEvent_ExitFullScreen
EndEnumeration

Procedure InitApplication()
  Global notificationCenter = CocoaMessage(0, 0, "NSNotificationCenter defaultCenter")
  Global appDelegate = CocoaMessage(0, CocoaMessage(0, 0, "NSApplication sharedApplication"), "delegate")
  Global delegateClass = CocoaMessage(0, appDelegate, "class")
EndProcedure : InitApplication()

; Common observer callbacks

ProcedureC Notification_ResizeDoneCB(obj, sel, notification)
  Protected object, window
  object = CocoaMessage(0, notification, "object")
  window = PB_Window_GetID(object)
  PostEvent(#MyEvent_ResizeDone, window, 0)
EndProcedure

ProcedureC Notification_EnterFullScreenCB(obj, sel, notification)
  object = CocoaMessage(0, notification, "object")
  window = PB_Window_GetID(object)
  PostEvent(#MyEvent_EnterFullScreen, window, 0)
EndProcedure

ProcedureC Notification_ExitFullScreenCB(obj, sel, notification)
  object = CocoaMessage(0, notification, "object")
  window = PB_Window_GetID(object)
  PostEvent(#MyEvent_ExitFullScreen, window, 0)
EndProcedure

; Add observer to window object

Procedure AddObserver(Window)
  Protected selector
  
  selector = sel_registerName_("windowResizeDone:")
  If Not class_getInstanceMethod_(delegateClass, selector)
    class_addMethod_(delegateClass, selector, @Notification_ResizeDoneCB(), "v@:@")
  EndIf
  CocoaMessage(0, notificationCenter, "addObserver:", appDelegate, "selector:", selector, "name:$", @"NSWindowDidEndLiveResizeNotification", "object:", WindowID(Window))
  
  selector = sel_registerName_("windowDidEnterFullScreen:")
  If Not class_getInstanceMethod_(delegateClass, selector)
    class_addMethod_(delegateClass, selector, @Notification_EnterFullScreenCB(), "v@:@")
  EndIf
  CocoaMessage(0, notificationCenter, "addObserver:", appDelegate, "selector:", selector, "name:$", @"NSWindowDidEnterFullScreenNotification", "object:", WindowID(Window))
  
  selector = sel_registerName_("windowDidExitFullScreen:")
  If Not class_getInstanceMethod_(delegateClass, selector)
    class_addMethod_(delegateClass, selector, @Notification_ExitFullScreenCB(), "v@:@")
  EndIf
  CocoaMessage(0, notificationCenter, "addObserver:", appDelegate, "selector:", selector, "name:$", @"NSWindowDidExitFullScreenNotification", "object:", WindowID(Window))
  
EndProcedure

; Remove observer from window object

Procedure RemoveObserver(Window)
  CocoaMessage(0, notificationCenter, "removeObserver:", appDelegate, "name:$", @"NSWindowDidEndLiveResizeNotification", "object:", WindowID(Window))
  CocoaMessage(0, notificationCenter, "removeObserver:", appDelegate, "name:$", @"NSWindowDidEnterFullScreenNotification", "object:", WindowID(Window))
  CocoaMessage(0, notificationCenter, "removeObserver:", appDelegate, "name:$", @"NSWindowDidExitFullScreenNotification", "object:", WindowID(Window))
EndProcedure

; ****

Procedure SizeInfo(Text.s)
  Protected window, dx, dy
  window = EventWindow()
  dx = WindowWidth(window)
  dy = WindowHeight(window)
  AddGadgetItem(0, -1, Text + " / Window = " + window + " / DX = " + dx + " / DY = " + dy)
EndProcedure

; ----

Procedure UpdateWindow()
  Protected dx, dy
  dx = WindowWidth(0)
  dy = WindowHeight(0) - StatusBarHeight(0) - MenuHeight()
  ; Resize Gadgets
  ResizeGadget(0, 0, 0, dx, dy)
EndProcedure

Procedure MyWindow()
  #WinStyle = #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget
  OpenWindow(1, 200, 200, 300, 200, "Window 2", #WinStyle)
EndProcedure

Procedure Main()
  Protected dx, dy
  
  #WinStyle = #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget
  
  If OpenWindow(0, #PB_Ignore, #PB_Ignore, 600, 400, "Window 1", #WinStyle)
    ; MenuBar
    CreateMenu(0, WindowID(0))
    MenuTitle("File")
    
    ; StatusBar
    CreateStatusBar(0, WindowID(0))
    AddStatusBarField(#PB_Ignore)
    
    ; Gadgets
    dx = WindowWidth(0)
    dy = WindowHeight(0) - StatusBarHeight(0) - MenuHeight()
    ListViewGadget(0, 0, 0, dx, dy)
    
    ; Bind Events
    BindEvent(#PB_Event_SizeWindow, @UpdateWindow(), 0)
    
    MyWindow()
    
    AddObserver(0)
    AddObserver(1)
    
    ; Main Loop
    Repeat
      Select WaitWindowEvent()
        Case #PB_Event_CloseWindow
          Select EventWindow()
            Case 0
              Break
          EndSelect
          
        Case #PB_Event_Menu
          Select EventMenu()
            
          EndSelect
          
        Case #PB_Event_Gadget
          Select EventGadget()
              
          EndSelect
          
        Case #PB_Event_MinimizeWindow
          SizeInfo("Minimize")
          
        Case #PB_Event_MaximizeWindow
          SizeInfo("Maximize")
          
        Case #PB_Event_RestoreWindow
          SizeInfo("Restore")
          
        Case #MyEvent_ResizeDone
          SizeInfo("ResizeDone")
          
        Case #MyEvent_EnterFullScreen
          SizeInfo("EnterFullScreen")
          
        Case #MyEvent_ExitFullScreen
          SizeInfo("ExitFullScreen")
        
      EndSelect
    ForEver
    
    RemoveObserver(0)
    RemoveObserver(1)
    
  EndIf
  
EndProcedure : Main() : End
Last edited by mk-soft on Sat Dec 30, 2023 4:09 am, edited 1 time in total.
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
coco2
Enthusiast
Enthusiast
Posts: 461
Joined: Mon Nov 25, 2013 5:38 am
Location: Australia

Re: Restore window event not firing

Post by coco2 »

Does that mean it's a bug? My bug report trigger finger is itching
User avatar
mk-soft
Always Here
Always Here
Posts: 6245
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Restore window event not firing

Post by mk-soft »

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
Post Reply