Page 1 of 1
PB 5.40b6 - You can't just hide a parent window
Posted: Sun Sep 20, 2015 3:59 pm
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
Re: You can't just hide a parent window
Posted: Sun Sep 20, 2015 4:07 pm
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.
Re: You can't just hide a parent window
Posted: Sun Sep 20, 2015 4:16 pm
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.
Re: PB 5.40b6 - You can't just hide a parent window
Posted: Sun Sep 20, 2015 4:31 pm
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 ?
Re: PB 5.40b6 - You can't just hide a parent window
Posted: Sun Sep 20, 2015 6:19 pm
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.
Re: PB 5.40b6 - You can't just hide a parent window
Posted: Sun Sep 20, 2015 6:44 pm
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
Re: PB 5.40b6 - You can't just hide a parent window
Posted: Sun Sep 20, 2015 7:28 pm
by Fred
I also think it's not a good idea to workaround such behavior, it could lead to more problems.
Re: PB 5.40b6 - You can't just hide a parent window
Posted: Sun Sep 20, 2015 7:32 pm
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 ? )