]> gitweb.factorcode.org Git - factor.git/blob - library/ui/cocoa/window-utils.factor
Documentation updates, menus fix
[factor.git] / library / ui / cocoa / window-utils.factor
1 ! Copyright (C) 2006 Slava Pestov
2 ! See http://factorcode.org/license.txt for BSD license.
3 IN: objc-classes
4 DEFER: FactorWindowDelegate
5
6 IN: cocoa
7 USING: arrays gadgets kernel math objc sequences ;
8
9 : NSBorderlessWindowMask     0 ; inline
10 : NSTitledWindowMask         1 ; inline
11 : NSClosableWindowMask       2 ; inline
12 : NSMiniaturizableWindowMask 4 ; inline
13 : NSResizableWindowMask      8 ; inline
14
15 : NSBackingStoreRetained    0 ; inline
16 : NSBackingStoreNonretained 1 ; inline
17 : NSBackingStoreBuffered    2 ; inline
18
19 : standard-window-type
20     NSTitledWindowMask
21     NSClosableWindowMask bitor
22     NSMiniaturizableWindowMask bitor
23     NSResizableWindowMask bitor ; inline
24
25 : <NSWindow> ( rect -- window )
26     NSWindow -> alloc swap
27     standard-window-type NSBackingStoreBuffered 1
28     -> initWithContentRect:styleMask:backing:defer: ;
29
30 : <ViewWindow> ( view bounds -- window )
31     <NSWindow> [ swap -> setContentView: ] keep
32     dup dup -> contentView -> setInitialFirstResponder:
33     dup 1 -> setAcceptsMouseMovedEvents: ;
34
35 : window-pref-dim -> contentView window pref-dim ;
36
37 : frame-content-rect ( window rect -- rect )
38     swap -> styleMask NSWindow -rot
39     -> frameRectForContentRect:styleMask: ;
40
41 : window-content-rect ( window -- rect )
42     NSWindow over -> frame rot -> styleMask
43     -> contentRectForFrameRect:styleMask: ;
44
45 "NSObject" "FactorWindowDelegate" {
46     ! Doesn't work on Intel since we don't support struct
47     ! returns yet
48
49     ! {
50     !     "windowWillUseStandardFrame:defaultFrame:" "NSRect"
51     !     { "id" "SEL" "id" "NSRect" }
52     !     [
53     !         drop 2nip
54     !         dup window-content-rect NSRect-x-far-y
55     !         pick window-pref-dim first2 <far-y-NSRect>
56     !         frame-content-rect
57     !     ]
58     ! }
59
60     {
61         "windowDidMove:" "void" { "id" "SEL" "id" } [
62             2nip -> object
63             dup window-content-rect NSRect-x-y 2array
64             swap -> contentView window set-world-loc
65         ]
66     }
67
68     {
69         "windowDidBecomeKey:" "void" { "id" "SEL" "id" } [
70             2nip -> object -> contentView window focus-world
71         ]
72     }
73
74     {
75         "windowDidResignKey:" "void" { "id" "SEL" "id" } [
76             forget-rollover
77             2nip -> object -> contentView window unfocus-world
78         ]
79     }
80 } { } define-objc-class
81
82 : install-window-delegate ( window -- )
83     FactorWindowDelegate install-delegate ;