PB 5.40b6 - You can't just hide a parent window

Mac OSX specific forum
User avatar
DoubleDutch
Addict
Addict
Posts: 3219
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

PB 5.40b6 - You can't just hide a parent window

Post by DoubleDutch »

If you have a parent and child window then you can hide the parent whilst leaving the child visible on Windows (really useful).

On OSX the parent cannot be hidden. :(

Code: Select all

OpenWindow(1,100,100,400,300,"parent window")
OpenWindow(2,200,200,400,300,"child window",#PB_Window_SystemMenu,WindowID(1))
HideWindow(1,#True)


Repeat
  Event=WaitWindowEvent()
  If Event=#PB_Event_CloseWindow
    Quit=#True
  EndIf
Until Quit
Last edited by DoubleDutch on Sun Sep 20, 2015 4:18 pm, edited 1 time in total.
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
User avatar
DoubleDutch
Addict
Addict
Posts: 3219
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Re: You can't just hide a parent window

Post by DoubleDutch »

It can be simulated by making the alpha 0

Code: Select all

osxAlpha.CGFloat=0
CocoaMessage(0,WindowID(1),"setAlphaValue:@",@osxAlpha)
But I think it should do the same as windows.
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
User avatar
DoubleDutch
Addict
Addict
Posts: 3219
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Re: You can't just hide a parent window

Post by DoubleDutch »

Also on windows you can create both windows as hidden, then unhide just the child. It would be good in OSX could also do this.
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: PB 5.40b6 - You can't just hide a parent window

Post by wilbert »

There's also something like respecting the OS behavior.
When you hide a window on OSX, it's child windows are also hidden. It's like that for all applications.
It's not a bug, it's just the way OSX works.

If you don't want the child window to behave as a child, can't you just create two normal windows so you can do with each window what you want ?
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
DoubleDutch
Addict
Addict
Posts: 3219
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Re: PB 5.40b6 - You can't just hide a parent window

Post by DoubleDutch »

I personally think it should be up to the programmer to respect or not respect convention.

Besides, I reuse the child window in another part of the program (without its parent).

Ideally there should be a way to change the parent window.
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: PB 5.40b6 - You can't just hide a parent window

Post by wilbert »

DoubleDutch wrote:I personally think it should be up to the programmer to respect or not respect convention.
Of course, I just don't think it should be the default setting.

You can add or remove a child window.

Code: Select all

#NSWindowAbove =  1
#NSWindowBelow = -1

OpenWindow(1,100,100,400,300,"parent window")
OpenWindow(2,200,200,400,300,"child window")

CocoaMessage(0, WindowID(1), "addChildWindow:", WindowID(2), "ordered:", #NSWindowAbove)
Debug CocoaMessage(0, WindowID(2), "parentWindow")

CocoaMessage(0, WindowID(1), "removeChildWindow:", WindowID(2))
Debug CocoaMessage(0, WindowID(2), "parentWindow")

CocoaMessage(0, WindowID(1), "addChildWindow:", WindowID(2), "ordered:", #NSWindowAbove)
Debug CocoaMessage(0, WindowID(2), "parentWindow")

Repeat
  Event=WaitWindowEvent()
  If Event=#PB_Event_CloseWindow
    Quit=#True
  EndIf
Until Quit
Second example

Code: Select all

Procedure SetParentWindow(Window, NewParent)
  Protected ID = WindowID(Window)
  Protected OldParent = CocoaMessage(0, ID, "parentWindow")
  If OldParent
    CocoaMessage(0, OldParent, "removeChildWindow:", ID)
  EndIf
  If IsWindow(NewParent)
    CocoaMessage(0, WindowID(NewParent), "addChildWindow:", ID, "ordered:", 1)
  EndIf
EndProcedure
    
  
OpenWindow(1,100,100,400,300,"parent window1")
OpenWindow(2,200,200,400,300,"parent window2")
OpenWindow(3,300,300,400,300,"child window")

SetParentWindow(3, 1); Set parent of window 3 to window 1 
Delay(1000)

SetParentWindow(3, 2); Set parent of window 3 to window 2 
Delay(1000)

SetParentWindow(3, -1); Set parent of window 3 to none (not existing window)
Delay(1000)

Repeat
  Event=WaitWindowEvent()
  If Event=#PB_Event_CloseWindow
    Quit=#True
  EndIf
Until Quit
Windows (x64)
Raspberry Pi OS (Arm64)
Fred
Administrator
Administrator
Posts: 16687
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: PB 5.40b6 - You can't just hide a parent window

Post by Fred »

I also think it's not a good idea to workaround such behavior, it could lead to more problems.
User avatar
DoubleDutch
Addict
Addict
Posts: 3219
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Re: PB 5.40b6 - You can't just hide a parent window

Post by DoubleDutch »

Wilbert: Thanks for the code. :)

So I'll re-order the parent stuff.

Fred: Maybe it might be a good idea to have the SetParent stuff native to Purebasic?
(maybe SetWindowParent and SetGadgetParent ? )
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
Post Reply