Lisp HUG Maillist Archive

LWW toggling push-button

Does anyone know how to make a push-button that toggles (stays pushed in until you click it again)?  Windows-specific solution OK.

I don't see any capi option that this does this.  When I try to reach around capi and make direct Windows calls (SendMessage BM_SETSTATUS), but this seems to generate an extra callback (when the button is set) when the button loses focus, as in the code below...

I have the code that does this manually, by sub-classing button and manually changing the image, but, creating 30 or so button images (x 2) is killing me.  It would be simpler if I could tell a standard capi button to stay pushed in.  I'm hoping that I've missed something obvious :-).

tia
pt

(defparameter *button* nil)

(defun tbutton ()
  (setq *button*
        (capi:contain
         (make-instance
          'push-button
          :text "Press Me"
          :data '(:some :data)
          :callback #'(lambda (data interface)
                        (capi:display-message
                         "Pressed ~S ~S"
                         data
                         (get-state *button*)))))))
  
(defun set-button ()
  (win32:send-message
   (slot-value
    (slot-value *button* 'capi-internals:representation)
    'win32::hwnd)
   #x00f3 1 0))

(defun clear-button ()
  (win32:send-message
   (slot-value
    (slot-value *button* 'capi-internals:representation)
    'win32::hwnd)
   #x00f3 0 0))

(defun get-state (button)
  (win32:send-message
   (slot-value
    (slot-value button 'capi-internals:representation)
    'win32::hwnd)
   #x00f2
   0
   0))

(defun sel-button ()
  (capi:apply-in-pane-process *button* #'(setf capi:button-selected) t *button*))

(defun unsel-button ()
  (capi:apply-in-pane-process *button* #'(setf capi:button-selected) nil *button*))


Re: LWW toggling push-button

Hi Paul,
I sometimes used a nasty hack: toolbar button. It looks a little  
different from ordinary button (has no outline), but for my things it  
was OK. And maybe if you will play with images, it can be also in  
accordance with HIG.

Here is example:

  (capi:contain
  (make-instance
   'capi:toolbar
   :items
   (list
    (make-instance
     'capi:toolbar-component
     :interaction :multiple-selection
     :items
     (list (make-instance 'capi:toolbar-button
                          :text "abaruka"))
     ))))

Zdenek Eichler

On Jan 17, 2009, at 9:05 PM, Paul Tarvydas wrote:

>
> Does anyone know how to make a push-button that toggles (stays  
> pushed in until you click it again)?  Windows-specific solution OK.
>
> I don't see any capi option that this does this.  When I try to  
> reach around capi and make direct Windows calls (SendMessage  
> BM_SETSTATUS), but this seems to generate an extra callback (when  
> the button is set) when the button loses focus, as in the code  
> below...
>
> I have the code that does this manually, by sub-classing button and  
> manually changing the image, but, creating 30 or so button images (x  
> 2) is killing me.  It would be simpler if I could tell a standard  
> capi button to stay pushed in.  I'm hoping that I've missed  
> something obvious :-).
>
> tia
> pt
>
> (defparameter *button* nil)
>
> (defun tbutton ()
>  (setq *button*
>        (capi:contain
>         (make-instance
>          'push-button
>          :text "Press Me"
>          :data '(:some :data)
>          :callback #'(lambda (data interface)
>                        (capi:display-message
>                         "Pressed ~S ~S"
>                         data
>                         (get-state *button*)))))))
>
> (defun set-button ()
>  (win32:send-message
>   (slot-value
>    (slot-value *button* 'capi-internals:representation)
>    'win32::hwnd)
>   #x00f3 1 0))
>
> (defun clear-button ()
>  (win32:send-message
>   (slot-value
>    (slot-value *button* 'capi-internals:representation)
>    'win32::hwnd)
>   #x00f3 0 0))
>
> (defun get-state (button)
>  (win32:send-message
>   (slot-value
>    (slot-value button 'capi-internals:representation)
>    'win32::hwnd)
>   #x00f2
>   0
>   0))
>
> (defun sel-button ()
>  (capi:apply-in-pane-process *button* #'(setf capi:button-selected)  
> t *button*))
>
> (defun unsel-button ()
>  (capi:apply-in-pane-process *button* #'(setf capi:button-selected)  
> nil *button*))
>


Updated at: 2020-12-10 08:41 UTC