Problem with window styleMask

Mac OSX specific forum
Wolfram
Enthusiast
Enthusiast
Posts: 606
Joined: Thu May 30, 2013 4:39 pm

Problem with window styleMask

Post 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
macOS Catalina 10.15.7
User avatar
mk-soft
Always Here
Always Here
Posts: 6246
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Problem with window styleMask

Post 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
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
Wolfram
Enthusiast
Enthusiast
Posts: 606
Joined: Thu May 30, 2013 4:39 pm

Re: Problem with window styleMask

Post 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
macOS Catalina 10.15.7
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Problem with window styleMask

Post 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)
Windows (x64)
Raspberry Pi OS (Arm64)
Wolfram
Enthusiast
Enthusiast
Posts: 606
Joined: Thu May 30, 2013 4:39 pm

Re: Problem with window styleMask

Post 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.
Image
macOS Catalina 10.15.7
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Problem with window styleMask

Post 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").
Windows (x64)
Raspberry Pi OS (Arm64)
Wolfram
Enthusiast
Enthusiast
Posts: 606
Joined: Thu May 30, 2013 4:39 pm

Re: Problem with window styleMask

Post 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. :-/
macOS Catalina 10.15.7
Wolfram
Enthusiast
Enthusiast
Posts: 606
Joined: Thu May 30, 2013 4:39 pm

Re: Problem with window styleMask - Fixed

Post 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
macOS Catalina 10.15.7
Post Reply