"NSOpenGLPixelFormat"
"NSOpenGLView"
"NSOpenPanel"
+ "NSPanel"
"NSPasteboard"
"NSPropertyListSerialization"
"NSResponder"
sequences math.bitwise ;
IN: cocoa.windows
+! Window styles
CONSTANT: NSBorderlessWindowMask 0
CONSTANT: NSTitledWindowMask 1
CONSTANT: NSClosableWindowMask 2
CONSTANT: NSMiniaturizableWindowMask 4
CONSTANT: NSResizableWindowMask 8
+! Additional panel-only styles
+CONSTANT: NSUtilityWindowMask 16
+CONSTANT: NSDocModalWindowMask 64
+CONSTANT: NSNonactivatingPanelMask 128
+CONSTANT: NSHUDWindowMask HEX: 1000
+
CONSTANT: NSBackingStoreRetained 0
CONSTANT: NSBackingStoreNonretained 1
CONSTANT: NSBackingStoreBuffered 2
-: standard-window-type ( -- n )
- {
- NSTitledWindowMask
- NSClosableWindowMask
- NSMiniaturizableWindowMask
- NSResizableWindowMask
- } flags ; inline
-
-: <NSWindow> ( rect -- window )
- NSWindow -> alloc swap
- standard-window-type NSBackingStoreBuffered 1
+: <NSWindow> ( rect style class -- window )
+ [ -> alloc ] curry 2dip NSBackingStoreBuffered 1
-> initWithContentRect:styleMask:backing:defer: ;
-: <ViewWindow> ( view rect -- window )
- <NSWindow> [ swap -> setContentView: ] keep
+: class-for-style ( style -- NSWindow/NSPanel )
+ HEX: 1ff0 bitand zero? NSWindow NSPanel ? ;
+
+: <ViewWindow> ( view rect style -- window )
+ dup class-for-style <NSWindow> [ swap -> setContentView: ] keep
dup dup -> contentView -> setInitialFirstResponder:
dup 1 -> setAcceptsMouseMovedEvents:
dup 0 -> setReleasedWhenClosed: ;
: window-content-rect ( window -- rect )
- [ NSWindow ] dip
+ dup -> class swap
[ -> frame ] [ -> styleMask ] bi
-> contentRectForFrameRect:styleMask: ;
M: cocoa-ui-backend (fullscreen?) ( world -- ? )
handle>> view>> -> isInFullScreenMode zero? not ;
+CONSTANT: window-control>styleMask
+ H{
+ { close-button $ NSClosableWindowMask }
+ { minimize-button $ NSMiniaturizableWindowMask }
+ { maximize-button 0 }
+ { resize-handles $ NSResizableWindowMask }
+ { small-title-bar $[ NSTitledWindowMask NSUtilityWindowMask bitor ] }
+ { normal-title-bar $ NSTitledWindowMask }
+ }
+
+: world>styleMask ( world -- n )
+ window-controls>> [ window-control>styleMask at ] map 0 [ bitor ] reduce ;
+
M:: cocoa-ui-backend (open-window) ( world -- )
world [ [ dim>> ] dip <FactorView> ]
with-world-pixel-format :> view
- view world world>NSRect <ViewWindow> :> window
+ view world [ world>NSRect ] [ world>styleMask ] bi <ViewWindow> :> window
view -> release
world view register-window
window world window-loc>> auto-position
ui.pixel-formats destructors literals strings ;
IN: ui.gadgets.worlds
+SYMBOLS:
+ close-button
+ minimize-button
+ maximize-button
+ resize-handles
+ small-title-bar
+ normal-title-bar ;
+
CONSTANT: default-world-pixel-format-attributes
{ windowed double-buffered T{ depth-bits { value 16 } } }
+CONSTANT: default-world-window-controls
+ {
+ normal-title-bar
+ close-button
+ minimize-button
+ maximize-button
+ resize-handles
+ }
+
TUPLE: world < track
active? focused? grab-input?
layers
title status status-owner
text-handle handle images
window-loc
- pixel-format-attributes ;
+ pixel-format-attributes
+ window-controls ;
TUPLE: world-attributes
{ world-class initial: world }
{ title string initial: "Factor Window" }
status
gadgets
- { pixel-format-attributes initial: $ default-world-pixel-format-attributes } ;
+ { pixel-format-attributes initial: $ default-world-pixel-format-attributes }
+ { window-controls initial: $ default-world-window-controls } ;
: <world-attributes> ( -- world-attributes )
world-attributes new ; inline
[ title>> >>title ]
[ status>> >>status ]
[ pixel-format-attributes>> >>pixel-format-attributes ]
+ [ window-controls>> >>window-controls ]
[ grab-input?>> >>grab-input? ]
[ gadgets>> [ 1 track-add ] each ]
} cleave ;