]> gitweb.factorcode.org Git - factor.git/blob - library/ui/cocoa/ui.factor
0b06024e6d5f449eca71967b4ad6b54f59866d91
[factor.git] / library / ui / cocoa / ui.factor
1 ! Copyright (C) 2006 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 IN: objc-classes
4 DEFER: FactorApplicationDelegate
5
6 IN: cocoa
7 USING: arrays gadgets gadgets-listener gadgets-workspace
8 hashtables kernel memory namespaces objc sequences errors freetype ;
9
10 : finder-run-files ( alien -- )
11     #! We filter out the image name since that might be there on
12     #! first launch.
13     CF>string-array [ image = not ] subset listener-run-files
14     NSApp NSApplicationDelegateReplySuccess
15     -> replyToOpenOrPrint: ;
16
17 ! Handle Open events from the Finder
18 "NSObject" "FactorApplicationDelegate" {
19     { "application:openFiles:" "void" { "id" "SEL" "id" "id" }
20         [ >r 3drop r> finder-run-files ]
21     }
22 } define-objc-class
23
24 : install-app-delegate ( -- )
25     NSApp FactorApplicationDelegate install-delegate ;
26
27 : init-cocoa ( -- )
28     reset-callbacks
29     install-app-delegate
30     register-services
31     init-clipboard ;
32
33 : rect>NSRect
34     dup world-loc first2 rot rect-dim first2 <NSRect> ;
35
36 : gadget-window ( world -- )
37     [
38         dup <FactorView>
39         dup rot rect>NSRect <ViewWindow>
40         dup install-window-delegate
41         over -> release
42         2array
43     ] keep set-world-handle ;
44
45 IN: gadgets
46
47 : set-title ( string world -- )
48     world-handle second swap <NSString> -> setTitle: ;
49
50 : open-window* ( world -- )
51     dup gadget-window
52     dup start-world
53     world-handle second f -> makeKeyAndOrderFront: ;
54
55 : raise-window ( world -- )
56     world-handle second dup f -> orderFront: -> makeKeyWindow ;
57
58 : select-gl-context ( handle -- )
59     first -> openGLContext -> makeCurrentContext ;
60
61 : flush-gl-context ( handle -- )
62     first -> openGLContext -> flushBuffer ;
63
64 : running.app? ( -- ? )
65     #! Test if we're running Factor.app.
66     "Factor.app"
67     NSBundle -> mainBundle -> bundlePath CF>string
68     subseq? ;
69
70 IN: shells
71
72 : ui
73     running.app? [
74         "The Factor UI requires you to run the supplied Factor.app." throw
75     ] unless
76     [
77         [
78             init-timers
79             init-cocoa
80             restore-windows? [
81                 restore-windows
82             ] [
83                 init-ui
84                 workspace-window
85                 drop
86             ] if
87             finish-launching
88             event-loop
89         ] with-cocoa
90     ] with-freetype ;
91
92 IN: command-line
93
94 : default-shell running.app? "ui" "tty" ? ;