]> gitweb.factorcode.org Git - factor.git/blob - basis/cocoa/windows/windows.factor
Merge branch 'tokyo' of git://www.tiodante.com/git/factor
[factor.git] / basis / cocoa / windows / windows.factor
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 ;
5 IN: cocoa.windows
6
7 ! Window styles
8 CONSTANT: NSBorderlessWindowMask     0
9 CONSTANT: NSTitledWindowMask         1
10 CONSTANT: NSClosableWindowMask       2
11 CONSTANT: NSMiniaturizableWindowMask 4
12 CONSTANT: NSResizableWindowMask      8
13
14 ! Additional panel-only styles 
15 CONSTANT: NSUtilityWindowMask       16
16 CONSTANT: NSDocModalWindowMask      64
17 CONSTANT: NSNonactivatingPanelMask 128
18 CONSTANT: NSHUDWindowMask    HEX: 1000
19
20 CONSTANT: NSBackingStoreRetained    0
21 CONSTANT: NSBackingStoreNonretained 1
22 CONSTANT: NSBackingStoreBuffered    2
23
24 : <NSWindow> ( rect style class -- window )
25     [ -> alloc ] curry 2dip NSBackingStoreBuffered 1
26     -> initWithContentRect:styleMask:backing:defer: ;
27
28 : class-for-style ( style -- NSWindow/NSPanel )
29     HEX: 1ff0 bitand zero? NSWindow NSPanel ? ;
30
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: ;
36
37 : window-content-rect ( window -- rect )
38     dup -> class swap
39     [ -> frame ] [ -> styleMask ] bi
40     -> contentRectForFrameRect:styleMask: ;