1 ! Copyright (C) 2006, 2007 Slava Pestov
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: arrays kernel math cocoa cocoa.messages cocoa.classes
4 sequences math.bitwise ;
8 CONSTANT: NSBorderlessWindowMask 0
9 CONSTANT: NSTitledWindowMask 1
10 CONSTANT: NSClosableWindowMask 2
11 CONSTANT: NSMiniaturizableWindowMask 4
12 CONSTANT: NSResizableWindowMask 8
14 ! Additional panel-only styles
15 CONSTANT: NSUtilityWindowMask 16
16 CONSTANT: NSDocModalWindowMask 64
17 CONSTANT: NSNonactivatingPanelMask 128
18 CONSTANT: NSHUDWindowMask HEX: 1000
20 CONSTANT: NSBackingStoreRetained 0
21 CONSTANT: NSBackingStoreNonretained 1
22 CONSTANT: NSBackingStoreBuffered 2
24 : <NSWindow> ( rect style class -- window )
25 [ -> alloc ] curry 2dip NSBackingStoreBuffered 1
26 -> initWithContentRect:styleMask:backing:defer: ;
28 : class-for-style ( style -- NSWindow/NSPanel )
29 HEX: 1ff0 bitand zero? NSWindow NSPanel ? ;
31 : <ViewWindow> ( view rect style -- window )
32 dup class-for-style <NSWindow> [ swap -> setContentView: ] keep
33 dup dup -> contentView -> setInitialFirstResponder:
34 dup 1 -> setAcceptsMouseMovedEvents:
35 dup 0 -> setReleasedWhenClosed: ;
37 : window-content-rect ( window -- rect )
39 [ -> frame ] [ -> styleMask ] bi
40 -> contentRectForFrameRect:styleMask: ;