]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/ui/backend/cocoa/cocoa.factor
Updating code to use with-out-parameters
[factor.git] / basis / ui / backend / cocoa / cocoa.factor
old mode 100755 (executable)
new mode 100644 (file)
index aa84ee4..72a9abc
@@ -1,14 +1,14 @@
 ! Copyright (C) 2006, 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien.c-types arrays assocs classes cocoa
-cocoa.application cocoa.classes cocoa.messages cocoa.nibs
+USING: accessors alien.c-types alien.data arrays assocs classes
+cocoa cocoa.application cocoa.classes cocoa.messages cocoa.nibs
 cocoa.pasteboard cocoa.runtime cocoa.subclassing cocoa.types
 cocoa.views cocoa.windows combinators command-line
 core-foundation core-foundation.run-loop core-graphics
 core-graphics.types destructors fry generalizations io.thread
-kernel libc literals locals math math.rectangles memory
-namespaces sequences specialized-arrays.int threads ui
-ui.backend ui.backend.cocoa.views ui.clipboards ui.gadgets
+kernel libc literals locals math math.bitwise math.rectangles
+memory namespaces sequences threads ui colors ui.backend
+ui.backend.cocoa.views ui.clipboards ui.gadgets
 ui.gadgets.worlds ui.pixel-formats ui.pixel-formats.private
 ui.private words.symbol ;
 IN: ui.backend.cocoa
@@ -55,8 +55,11 @@ M: cocoa-ui-backend (free-pixel-format)
 M: cocoa-ui-backend (pixel-format-attribute)
     [ handle>> ] [ >NSOpenGLPFA ] bi*
     [ drop f ]
-    [ first 0 <int> [ swap 0 -> getValues:forAttribute:forVirtualScreen: ] keep *int ]
-    if-empty ;
+    [
+        first
+        { int } [ swap 0 -> getValues:forAttribute:forVirtualScreen: ] [ ]
+        with-out-parameters
+    ] if-empty ;
 
 TUPLE: pasteboard handle ;
 
@@ -109,16 +112,36 @@ M: cocoa-ui-backend (set-fullscreen) ( world ? -- )
 M: cocoa-ui-backend (fullscreen?) ( world -- ? )
     handle>> view>> -> isInFullScreenMode zero? not ;
 
+CONSTANT: window-control>styleMask
+    H{
+        { close-button $ NSClosableWindowMask }
+        { minimize-button $ NSMiniaturizableWindowMask }
+        { maximize-button 0 }
+        { resize-handles $ NSResizableWindowMask }
+        { small-title-bar $[ NSTitledWindowMask NSUtilityWindowMask bitor ] }
+        { normal-title-bar $ NSTitledWindowMask }
+        { textured-background $ NSTexturedBackgroundWindowMask }
+    }
+
+: world>styleMask ( world -- n )
+    window-controls>> window-control>styleMask symbols>flags ;
+
+: make-context-transparent ( view -- )
+    -> openGLContext
+    0 <int> NSOpenGLCPSurfaceOpacity -> setValues:forParameter: ;
+
 M:: cocoa-ui-backend (open-window) ( world -- )
     world [ [ dim>> ] dip <FactorView> ]
     with-world-pixel-format :> view
-    view world world>NSRect <ViewWindow> :> window
+    world window-controls>> textured-background swap member-eq?
+    [ view make-context-transparent ] when
+    view world [ world>NSRect ] [ world>styleMask ] bi <ViewWindow> :> window
     view -> release
     world view register-window
     window world window-loc>> auto-position
     world window save-position
     window install-window-delegate
-    view window <window-handle> world (>>handle)
+    view window <window-handle> world handle<<
     window f -> makeKeyAndOrderFront: ;
 
 M: cocoa-ui-backend (close-window) ( handle -- )
@@ -145,7 +168,7 @@ M: cocoa-ui-backend (ungrab-input) ( handle -- )
 M: cocoa-ui-backend close-window ( gadget -- )
     find-world [
         handle>> [
-            window>> f -> performClose:
+            window>> -> close
         ] when*
     ] when* ;
 
@@ -193,21 +216,33 @@ M: cocoa-ui-backend offscreen-pixels ( world -- alien w h )
 M: cocoa-ui-backend beep ( -- )
     NSBeep ;
 
+M: cocoa-ui-backend system-alert
+    invalidate-run-loop-timers
+    NSAlert -> alloc -> init -> autorelease [
+        {
+            [ swap <NSString> -> setInformativeText: ]
+            [ swap <NSString> -> setMessageText: ]
+            [ "OK" <NSString> -> addButtonWithTitle: drop ]
+            [ -> runModal drop ]
+        } cleave
+    ] [ 2drop ] if*
+    init-thread-timer ;
+
 CLASS: {
     { +superclass+ "NSObject" }
     { +name+ "FactorApplicationDelegate" }
 }
 
-{  "applicationDidUpdate:" "void" { "id" "SEL" "id" }
+{ "applicationDidUpdate:" void { id SEL id }
     [ 3drop reset-run-loop ]
 } ;
 
 : install-app-delegate ( -- )
     NSApp FactorApplicationDelegate install-delegate ;
 
-SYMBOL: cocoa-init-hook
+SYMBOL: cocoa-startup-hook
 
-cocoa-init-hook [
+cocoa-startup-hook [
     [ "MiniFactor.nib" load-nib install-app-delegate ]
 ] initialize
 
@@ -215,7 +250,7 @@ M: cocoa-ui-backend (with-ui)
     "UI" assert.app [
         [
             init-clipboard
-            cocoa-init-hook get call( -- )
+            cocoa-startup-hook get call( -- )
             start-ui
             f io-thread-running? set-global
             init-thread-timer