Lisp HUG Maillist Archive

lose focus callback?

How do you guys do input validation on text input panes?  I see a 
change callback and a callback that gets called when the user presses
return but not a 'lose focus' callback.  What I'd like is a callback when 
the pane loses focus so I can see what they typed when they think they 
are done and badger them about it if it is not appropriate.  (This is for 
numeric entry so I could do it with the change callback, but I now suspect 
I am missing something).

(win32 and linux, lwpro 4.4)

thanks,

BM


Re: lose focus callback?

Hi!

I've already asked this question. You should to implement it by hand.

In my recent project I set "on change" callback function which
starts a thread with delay to check if pane lost focus then call validate
function.

My code (not optimal but it works):

(let ((waiting-iface nil)
      (has-focus t))

(defun text-input-pane-focus-wait (pane)
  (when pane
    (capi:apply-in-pane-process pane
       #'(lambda (pane)
         (setf has-focus (capi:pane-has-focus-p pane))) pane)
   (not has-focus)))

(defun text-input-pane-verify-value (iface)
  (with-slots (scroll-pane input-pane start end step range) iface
    (setf has-focus t)
    (capi:apply-in-pane-process input-pane
         #'(lambda (pane)
             (setf has-focus (capi:pane-has-focus-p pane))) input-pane)
    (mp:process-wait "Awaiting defocusing" 'text-input-pane-focus-wait
input-pane)

    (let ((text (text-input-pane-text input-pane)))
    ;; HERE YOU CAN VALIDATE NEW VALUE)

  (setf waiting-iface nil))

(defun text-input-pane-focus-callback (iface text)
  (declare (ignorable text))
  (unless waiting-iface
    (setf waiting-iface iface)
    (mp:process-run-function "focus-callback-proc" '(:priority 0)
                'text-input-pane-verify-value iface)))
) ;; let waiting-iface

Add to pane declaration:
:change-callback 'text-input-pane-focus-callback
:change-callback-type :interface-data

Regards
Lisper

----- Original Message -----
From: "Bulent Murtezaoglu" <bm@acm.org>
To: <lisp-hug@lispworks.com>
Sent: Wednesday, January 19, 2005 3:13 AM
Subject: lose focus callback?


>
> How do you guys do input validation on text input panes?  I see a
> change callback and a callback that gets called when the user presses
> return but not a 'lose focus' callback.  What I'd like is a callback when
> the pane loses focus so I can see what they typed when they think they
> are done and badger them about it if it is not appropriate.  (This is for
> numeric entry so I could do it with the change callback, but I now suspect
> I am missing something).
>
> (win32 and linux, lwpro 4.4)
>
> thanks,
>
> BM
>
>


Re: lose focus callback?

Excuse me...please ignore/change/remove line in my previous message:

(with-slots (scroll-pane input-pane start end step range) iface

That slots were declared in my specific interface. You don't have to declare
them. Note that the IFACE argument is interface which is owner of text input
pane.

Regards
Lisper



----- Original Message -----
From: "Bulent Murtezaoglu" <bm@acm.org>
To: <lisp-hug@lispworks.com>
Sent: Wednesday, January 19, 2005 3:13 AM
Subject: lose focus callback?


>
> How do you guys do input validation on text input panes?  I see a
> change callback and a callback that gets called when the user presses
> return but not a 'lose focus' callback.  What I'd like is a callback when
> the pane loses focus so I can see what they typed when they think they
> are done and badger them about it if it is not appropriate.  (This is for
> numeric entry so I could do it with the change callback, but I now suspect
> I am missing something).
>
> (win32 and linux, lwpro 4.4)
>
> thanks,
>
> BM
>
>


Re: lose focus callback?

hey,

In case it's helpful, there's another way to accomplish the kind of validation
you are looking for, and in a portable way.  The idea is to use a
text-input-pane that's not enabled (:enabled nil) along with a button to `Add'
or `Edit', etc. where the button pops up a window using capi:prompt-for-string
along with the `:ok-check' option:

 (make-instance 'capi:text-input-pane :enabled nil)

so you can't write into it, but then a button (e.g. "Add", or "Edit") which
then pops up a window that allows you to enter the text, e.g.:

 (capi:prompt-for-string "Enter some text:"
                         :ok-check #'text-valid-p)

then, upon entering the text, you simply set the capi:text-input-pane-text of
the text pane to that string:

 (setf (capi:text-input-pane-text my-text-pane) result-string)

What's nice about this is that it generalizes to having Add/Edit buttons on
most capi collection items.

I hope that helps.

dave

--- Bulent Murtezaoglu <bm@acm.org> wrote:

> How do you guys do input validation on text input panes?  I see a 
> change callback and a callback that gets called when the user presses
> return but not a 'lose focus' callback.  What I'd like is a callback when 
> the pane loses focus so I can see what they typed when they think they 
> are done and badger them about it if it is not appropriate.  (This is for 
> numeric entry so I could do it with the change callback, but I now suspect 
> I am missing something).
> 
> (win32 and linux, lwpro 4.4)
> 
> thanks,
> 
> BM
> 
> 


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