Page 1 of 1
Problem with window styleMask
Posted: Thu Mar 12, 2020 3:43 pm
by Wolfram
If I change the styleMask of the window it changes the gadget too.
Why and how can I change this behavior?
Code: Select all
#NSWindowStyleMaskTexturedBackground = 1 << 8
#NSWindowStyleMaskFullSizeContentView = 1 << 15
Global Window_0, Button_0
Procedure OpenWindow_0(x = 0, y = 0, width = 450, height = 160)
Window_0 = OpenWindow(#PB_Any, x, y, width, width, "", #PB_Window_ScreenCentered | #PB_Window_SystemMenu )
Button_0 = ButtonGadget(#PB_Any, 160, 50, 130, 25, "OK")
view = CocoaMessage(0, GadgetID(Button_0), "superview")
NSWindow = CocoaMessage(0, GadgetID(Button_0), "window")
mask = CocoaMessage(0, NSWindow, "styleMask")
mask | #NSWindowStyleMaskFullSizeContentView ;-< changes the button height too
CocoaMessage(0, NSWindow, "setStyleMask:@", @mask)
CocoaMessage(0, NSWindow, "setTitlebarAppearsTransparent:", #True)
CreateImage(0, width, 22)
ImageGadget(#PB_Any, 0, 0, width, 22, ImageID(0))
EndProcedure
Procedure Window_0_Events(event)
Select event
Case #PB_Event_CloseWindow
ProcedureReturn #False
Case #PB_Event_Menu
Select EventMenu()
Case #PB_Menu_Quit
ProcedureReturn #False
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
Case Button_0
EndSelect
EndSelect
ProcedureReturn #True
EndProcedure
OpenWindow_0()
Repeat
event = WaitWindowEvent()
Until Window_0_Events(event) = #False
End
Re: Problem with window styleMask
Posted: Thu Mar 12, 2020 8:31 pm
by mk-soft
With me the style of the button changes.
It is only stupid that in DarkMode the NS-Controls are always transparent.
Code: Select all
#NSWindowStyleMaskTexturedBackground = 1 << 8
#NSWindowStyleMaskFullSizeContentView = 1 << 15
Global Window_0, Button_0
Procedure OpenWindow_0(x = 0, y = 0, width = 450, height = 160)
Window_0 = OpenWindow(#PB_Any, x, y, width, width, "", #PB_Window_ScreenCentered | #PB_Window_SystemMenu )
Button_0 = ButtonGadget(#PB_Any, 160, 50, 130, 30, "OK")
SetWindowColor(Window_0, #Green)
CocoaMessage(0, GadgetID(Button_0), "setBackgroundColor:", CocoaMessage(0, 0, "NSColor systemRedColor"))
;view = CocoaMessage(0, GadgetID(Button_0), "superview")
NSWindow = CocoaMessage(0, GadgetID(Button_0), "window")
mask = CocoaMessage(0, NSWindow, "styleMask")
mask | #NSWindowStyleMaskFullSizeContentView ;-< changes the button height too
CocoaMessage(0, NSWindow, "setStyleMask:@", @mask)
CocoaMessage(0, NSWindow, "setTitlebarAppearsTransparent:", #True)
CreateImage(0, width, 22, 32, #Blue)
ImageGadget(#PB_Any, 0, 0, width, 22, ImageID(0))
EndProcedure
Procedure Window_0_Events(event)
Select event
Case #PB_Event_CloseWindow
ProcedureReturn #False
Case #PB_Event_Menu
Select EventMenu()
Case #PB_Menu_Quit
ProcedureReturn #False
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
Case Button_0
EndSelect
EndSelect
ProcedureReturn #True
EndProcedure
OpenWindow_0()
Repeat
event = WaitWindowEvent()
Until Window_0_Events(event) = #False
End
Re: Problem with window styleMask
Posted: Fri Mar 13, 2020 12:35 am
by Wolfram
I think it is not the style that change. It looks more as the controlSize, but it is't it either.
I tried to reproduce this behavior in Xcode, but no luck.
The same problem is if you use a layer.
Code: Select all
#regular = 0
#small = 1
#mini = 2
Global Window_0, Button_0, view
Procedure OpenWindow_0(x = 0, y = 0, width = 450, height = 160)
Window_0 = OpenWindow(#PB_Any, x, y, width, height, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
view = CocoaMessage(0,WindowID(Window_0),"contentView")
Button_0 = ButtonGadget(#PB_Any, 160, 50, 130, 25, "OK")
buttonID = GadgetID(Button_0)
cell = CocoaMessage(0, buttonID, "cell")
size.i
CocoaMessage(@size, cell, "controlSize")
Debug size
; size = #small
; CocoaMessage(0, cell, "setControlSize:@", @size)
EndProcedure
Procedure Window_0_Events(event)
Static state
Select event
Case #PB_Event_CloseWindow
ProcedureReturn #False
Case #PB_Event_Menu
Select EventMenu()
Case #PB_Menu_Quit
ProcedureReturn #False
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
Case Button_0
state ! 1
CocoaMessage(0, view, "setWantsLayer:", state)
EndSelect
EndSelect
ProcedureReturn #True
EndProcedure
OpenWindow_0()
Repeat
event = WaitWindowEvent()
Until Window_0_Events(event) = #False
Re: Problem with window styleMask
Posted: Sat Mar 14, 2020 9:17 am
by wilbert
Wolfram wrote:If I change the styleMask of the window it changes the gadget too.
Why and how can I change this behavior?
I don't see any change in button size (macOS 10.15.3)
The controlSize mentioned in your other post, should be applied to the control itself I believe, not the cell.
This does seem to make a difference in size for me.
Code: Select all
CocoaMessage(0, GadgetID(Button_0), "setControlSize:", #mini)
Re: Problem with window styleMask
Posted: Sat Mar 14, 2020 12:09 pm
by Wolfram
Thanks for testing Wilbert.
Here is how it looks on maxOSX 13.6. And as I told if I use same code in Xcode these problem is not happened.

Re: Problem with window styleMask
Posted: Sat Mar 14, 2020 3:46 pm
by wilbert
Maybe it's a bug in older macOS versions.
Anyway, I can't help out with this one since both with or without a layer, on my computer it looks like the left one ("normal").
Re: Problem with window styleMask
Posted: Sat Mar 14, 2020 9:46 pm
by Wolfram
wilbert wrote:Maybe it's a bug in older macOS versions.
I don't think it is an bug in macOS because with Xcode everything is fine.
I't seams to be more a PB bug. :-/
Re: Problem with window styleMask - Fixed
Posted: Mon Mar 16, 2020 8:03 pm
by Wolfram
I fixed. I have no idea why the cell height must be 32, but ist must and the bezelStyle seams to get lost.
This works also if the view has a layer.
Code: Select all
#NSWindowStyleMaskTexturedBackground = 1 << 8
#NSWindowStyleMaskFullSizeContentView = 1 << 15
#NSBezelStyleRounded = 1 ;default
Global Window_0, Button_0
Procedure OpenWindow_0(x = 0, y = 0, width = 450, height = 160)
Window_0 = OpenWindow(#PB_Any, x, y, width, height, "", #PB_Window_ScreenCentered | #PB_Window_SystemMenu )
Button_0 = ButtonGadget(#PB_Any, 160, 50, 130, 25, "OK")
buttonID = GadgetID(Button_0)
view = CocoaMessage(0, GadgetID(Button_0), "superview")
NSWindow = CocoaMessage(0, GadgetID(Button_0), "window")
mask = CocoaMessage(0, NSWindow, "styleMask")
mask | #NSWindowStyleMaskFullSizeContentView
CocoaMessage(0, NSWindow, "setStyleMask:@", @mask)
CocoaMessage(0, NSWindow, "setTitlebarAppearsTransparent:", #True)
;//fixing the button high
rect.nsrect
CocoaMessage(@rect, buttonID, "frame")
rect\size\height = 32
CocoaMessage(0, buttonID, "setFrame:@", @rect)
CocoaMessage(0, buttonID, "setBezelStyle:", #NSBezelStyleRounded)
CreateImage(0, width, 22)
ImageGadget(#PB_Any, 0, 0, width, 22, ImageID(0))
EndProcedure
Procedure Window_0_Events(event)
Select event
Case #PB_Event_CloseWindow
ProcedureReturn #False
Case #PB_Event_Menu
Select EventMenu()
Case #PB_Menu_Quit
ProcedureReturn #False
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
Case Button_0
EndSelect
EndSelect
ProcedureReturn #True
EndProcedure
OpenWindow_0()
Repeat
event = WaitWindowEvent()
Until Window_0_Events(event) = #False