1 ! Copyright (C) 2006, 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors math arrays cocoa cocoa.application
4 command-line kernel memory namespaces cocoa.messages
5 cocoa.runtime cocoa.subclassing cocoa.pasteboard cocoa.types
6 cocoa.windows cocoa.classes cocoa.application sequences system
7 ui ui.backend ui.clipboards ui.gadgets ui.gadgets.worlds
8 ui.cocoa.views core-foundation threads math.geometry.rect ;
11 TUPLE: handle view window ;
15 SINGLETON: cocoa-ui-backend
17 M: cocoa-ui-backend do-events ( -- )
19 [ NSApp [ do-event ] curry loop ui-wait ] ui-try
20 ] with-autorelease-pool ;
22 TUPLE: pasteboard handle ;
24 C: <pasteboard> pasteboard
26 M: pasteboard clipboard-contents
27 handle>> pasteboard-string ;
29 M: pasteboard set-clipboard-contents
30 handle>> set-pasteboard-string ;
32 : init-clipboard ( -- )
33 NSPasteboard -> generalPasteboard <pasteboard>
35 <clipboard> selection set-global ;
37 : world>NSRect ( world -- NSRect )
38 dup window-loc>> first2 rot rect-dim first2 <NSRect> ;
40 : gadget-window ( world -- )
43 dup rot world>NSRect <ViewWindow>
44 dup install-window-delegate
49 M: cocoa-ui-backend set-title ( string world -- )
50 handle>> window>> swap <NSString> -> setTitle: ;
52 : enter-fullscreen ( world -- )
54 NSScreen -> mainScreen
55 f -> enterFullScreenMode:withOptions:
58 : exit-fullscreen ( world -- )
59 handle>> view>> f -> exitFullScreenModeWithOptions: ;
61 M: cocoa-ui-backend set-fullscreen* ( ? world -- )
62 swap [ enter-fullscreen ] [ exit-fullscreen ] if ;
64 M: cocoa-ui-backend fullscreen* ( world -- ? )
65 handle>> view>> -> isInFullScreenMode zero? not ;
67 : auto-position ( world -- )
68 dup window-loc>> { 0 0 } = [
69 handle>> window>> -> center
74 M: cocoa-ui-backend (open-window) ( world -- )
77 handle>> window>> f -> makeKeyAndOrderFront: ;
79 M: cocoa-ui-backend (close-window) ( handle -- )
82 M: cocoa-ui-backend close-window ( gadget -- )
85 window>> f -> performClose:
89 M: cocoa-ui-backend raise-window* ( world -- )
91 window>> dup f -> orderFront: -> makeKeyWindow
92 NSApp 1 -> activateIgnoringOtherApps:
95 M: cocoa-ui-backend select-gl-context ( handle -- )
96 view>> -> openGLContext -> makeCurrentContext ;
98 M: cocoa-ui-backend flush-gl-context ( handle -- )
99 view>> -> openGLContext -> flushBuffer ;
101 M: cocoa-ui-backend beep ( -- )
104 SYMBOL: cocoa-init-hook
106 M: cocoa-ui-backend ui
110 cocoa-init-hook get [ call ] when*
117 cocoa-ui-backend ui-backend set-global
119 [ running.app? "ui" "listener" ? ] main-vocab-hook set-global