[Openmcl-devel] Small contribution plus question

Alexander Repenning ralex at cs.colorado.edu
Wed Dec 17 13:00:19 PST 2008


code below works with no warnings:

The warning is about the "running" variable. You should have declare  
that special but there is actually no need for this variable at all.  
runModalForWindow: does run its own modal event loop. Toss your loop,  
toss your variable.

The only problem left is that the resulting color panel is a modal  
dialog that does not look like one: has close button, does not have  
cancel/OK buttons. Not sure if Cocoa has a real modal color picker.  
You can still use the Carbon one. It will probably still work in 64bit  
mode. Anyway, the recommended approach is not to use a modal dialog at  
all. Create a function with

(defun USER-PICK-COLOR (Responder-Function ...)

This responder function would be called every time the user changes  
the color (use  changeColor: to implement)

For the sake of MCL compatibility implement it both ways: if there is  
a Responder-Function use the dialog non-modal, else modal

Alex




____________________________
(in-package :ccl)


(objc:defmethod (#/NSWindowWillCloseNotification :void)  ((self ns:ns- 
color-panel))
   (#/stopModal (#/sharedApplication ns:ns-application)))


(defun USER-PICK-COLOR (&key color (prompt "Pick a color"))
   (with-autorelease-pool
       (let ((panel (#/sharedColorPanel ns:ns-color-panel)))
         (#/setPickerMode: ns:ns-color-panel #$NSWheelModeColorPanel)
         (#/setTitle: panel prompt)
         (#/addObserver:selector:name:object:                 ;  
observe yourself close but
          (#/defaultCenter ns:ns-notification-center)         ; sadly  
confound OK & CANCEL
          panel
          (objc:\@selector #/NSWindowWillCloseNotification)
          "NSWindowWillCloseNotification"
          panel)
         (when color (#/setColor: panel color))
         (#/runModalForWindow: (#/sharedApplication ns:ns-application)  
panel)
         (#/removeObserver:name:object:                       ;  
prevent pileup
          (#/defaultCenter ns:ns-notification-center)
          panel
          "NSWindowWillCloseNotification"
          panel)
         (#/color panel))))


#| Examples

(user-pick-color)


|#

On Dec 17, 2008, at 9:56 AM, Arthur W Cater wrote:

> In the code below, which principally defines USER-PICK-COLOR for Mac  
> OS X,
> why do I get a warning when compiling the objc:defmethod subform?
> (Commenting out that part confirms it as the source of the warning.)
>
> (in-package :easygui)
>
> (let ((running nil))
>
>   ; Provokes uncomprehended warning
>   ; Undeclared free variable |-[NSColorPanel  
> NSWindowWillCloseNotification]|
>   (objc:defmethod (#/NSWindowWillCloseNotification :void)
>                              ((self ns:ns-color-panel))
>     (setf running nil)
>     (#/stopModal (easygui::application-object)))
>
>   (defun application-object nil
>     (#/sharedApplication ns:ns-application))
>
>   (defun user-pick-color (&key color (prompt "Pick a color") position)
>     "POSITION argument is provided only for Digitool MCL  
> compatibility, it is ignored"
>     (declare (ignore position))
>     (gui::with-autorelease-pool
>         (let* ((panel (#/sharedColorPanel ns:ns-color-panel))) ;  
> find or create the NSColorPanel
>           (#/setPickerMode: ns:ns-color-panel #$NSWheelModeColorPanel)
>           (#/setTitle: panel prompt)
>           (#/addObserver:selector:name:object:                 ;  
> observe yourself close but
>            (#/defaultCenter ns:ns-notification-center)         ;  
> sadly confound OK & CANCEL
>            panel
>            (objc:\@selector #/NSWindowWillCloseNotification)
>            "NSWindowWillCloseNotification"
>            panel)
>           (when color (#/setColor: panel color))
>           (setf running t)
>           (#/runModalForWindow: (easygui::application-object) panel)
>           (do () ((not running)) (sleep 0.1))
>           (#/removeObserver:name:object:                       ;  
> prevent pileup
>            (#/defaultCenter ns:ns-notification-center)
>            panel
>            "NSWindowWillCloseNotification"
>            panel)
>           (#/color panel)))))
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> http://clozure.com/mailman/listinfo/openmcl-devel

Prof. Alexander Repenning

University of Colorado
Computer Science Department
Boulder, CO 80309-430

vCard: http://www.cs.colorado.edu/~ralex/AlexanderRepenning.vcf


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.clozure.com/pipermail/openmcl-devel/attachments/20081217/67daf03e/attachment.htm>


More information about the Openmcl-devel mailing list