Changeset 6748
- Timestamp:
- Jun 16, 2007, 7:18:58 PM (17 years ago)
- File:
-
- 1 edited
-
branches/ide-1.0/ccl/examples/cocoa-defaults.lisp (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/ide-1.0/ccl/examples/cocoa-defaults.lisp
r6733 r6748 29 29 value ; the "standard" initial value 30 30 doc ; a doc string 31 c onstraint ; an optional type constraint.31 change-hook ; an optional hook function 32 32 ) 33 33 … … 43 43 (defun %clear-cocoa-defaults () (setq cocoa-defaults nil))) 44 44 45 (defun set-cocoa-default (name string type value doc &optional c onstraint)45 (defun set-cocoa-default (name string type value doc &optional change-hook) 46 46 (check-type name symbol) 47 47 (check-type string objc-constant-string) … … 54 54 :value value 55 55 :doc doc 56 :c onstraint constraint))56 :change-hook change-hook)) 57 57 value) 58 58 … … 62 62 63 63 64 (defun %define-cocoa-default (name type value doc &optional c onstraint)64 (defun %define-cocoa-default (name type value doc &optional change-hook) 65 65 (proclaim `(special ,name)) 66 66 ;; Make the variable "GLOBAL": its value can be changed, but it can't … … 70 70 (record-source-file name 'variable) 71 71 (setf (documentation name 'variable) doc) 72 (set name (set-cocoa-default name (objc-default-key name) type value doc c onstraint))72 (set name (set-cocoa-default name (objc-default-key name) type value doc change-hook)) 73 73 name) 74 74 75 75 76 76 77 (defmacro def-cocoa-default (name type value doc &optional c onstraint&environment env)77 (defmacro def-cocoa-default (name type value doc &optional change-hook &environment env) 78 78 `(progn 79 79 (eval-when (:compile-toplevel) 80 80 (note-variable-info ',name :global ,env)) 81 81 (declaim (special ,name)) 82 (%define-cocoa-default ',name ',type ,value ',doc ,@(when constraint `((specifier-type ',constraint)))))) 82 (defloadvar ,name nil) 83 (%define-cocoa-default ',name ',type ,value ',doc ,change-hook))) 83 84 84 85 … … 94 95 (key (objc-constant-string-nsstringptr (cocoa-default-string d)))) 95 96 (if (%null-ptr-p (#/objectForKey: domain key)) 96 (progn 97 (#/setObject:forKey: domain 98 (case (cocoa-default-type d) 99 (:color (#/archivedDataWithRootObject: 97 (let* ((value (cocoa-default-value d))) 98 (case (cocoa-default-type d) 99 (:int (#/setInteger:forKey: domain value key)) 100 (:float (#/setFloat:forKey: domain value key)) 101 (:bool (#/setBool:forKey: domain value key)) 102 (:color (#/setObject:forKey: domain 103 (#/archivedDataWithRootObject: 100 104 ns:ns-archiver 101 (cocoa-default-value d))) 102 (t 103 (%make-nsstring (format nil "~a" (cocoa-default-value d))))) 104 key) 105 value) 106 key)) 107 (t 108 (#/setObject:forKey: domain 109 (%make-nsstring (format nil "~a" (cocoa-default-value d))) 110 111 key))) 105 112 (setq need-synch t)) 106 (case (cocoa-default-type d) 107 (:int 108 (set name (#/integerForKey: domain key))) 109 (:float 110 (set name (#/floatForKey: domain key))) 111 (:string 112 (let* ((nsstring (#/stringForKey: domain key))) 113 (unless (%null-ptr-p nsstring) 114 (set name (lisp-string-from-nsstring nsstring))))) 115 (:color 116 (let* ((data (#/dataForKey: domain key))) 117 (unless (%null-ptr-p data) 118 (set name (#/retain (#/unarchiveObjectWithData: ns:ns-unarchiver data)))))))))) 113 (let* ((hook (cocoa-default-change-hook d)) 114 (old-value (symbol-value name))) 115 (case (cocoa-default-type d) 116 (:int 117 (set name (#/integerForKey: domain key))) 118 (:float 119 (set name (#/floatForKey: domain key))) 120 (:bool 121 (set name (#/boolForKey: domain key))) 122 (:string 123 (let* ((nsstring (#/stringForKey: domain key))) 124 (unless (%null-ptr-p nsstring) 125 (set name (lisp-string-from-nsstring nsstring))))) 126 (:color 127 (let* ((data (#/dataForKey: domain key))) 128 (unless (%null-ptr-p data) 129 (set name (#/retain (#/unarchiveObjectWithData: ns:ns-unarchiver data))))))) 130 (when hook (funcall hook old-value (symbol-value name))))))) 119 131 (when need-synch (#/synchronize domain)))) 120 132 … … 125 137 (:int 126 138 (set name (#/intValue newval))) 139 (:bool 140 (#_NSLog #@"newvalue = %@" :id newval) 141 (set name (coerce-from-bool (#/intValue newval)))) 127 142 (:float 128 143 (set name (#/floatValue newval))) … … 140 155 :with-capacity (length defaults)))) 141 156 (dolist (d defaults dict) 157 (let* ((value (cocoa-default-value d))) 142 158 (#/setObject:forKey: dict 143 159 (case (cocoa-default-type d) 144 160 (:color (#/archivedDataWithRootObject: 145 161 ns:ns-archiver 146 (cocoa-default-value d))) 162 value)) 163 (:int (make-instance 'ns:ns-number 164 :with-int value)) 165 (:float (make-instance 'ns:ns-number 166 :with-float value)) 167 (:bool (make-instance 'ns:ns-number 168 :with-bool (coerce-to-bool value))) 147 169 (t 148 170 (%make-nsstring (format nil "~a" (cocoa-default-value d))))) 149 (objc-constant-string-nsstringptr (cocoa-default-string d)))))) 171 (objc-constant-string-nsstringptr (cocoa-default-string d)))))))
Note:
See TracChangeset
for help on using the changeset viewer.
