Initial focus in dialog box

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Initial focus in dialog box

Keith Alcock
Has anyone worked out a way to set the initial focus in a dialog box?

Doing so in the presenter's onViewOpened method has no effect.  This is
presumably because Windows refuses to carry out setFocus requests for
some time after it gets a true back from Dolphin's wmInitDialog and
onInitDialog methods for the DialogView.  It does not seem possible to
return false from MyDialogView so that the focus can be applied later.
Windows (Win2000 at least) chokes on this.  I can't trigger something in
the presenter during wmInitDialog so that focus can be changed right
away because Dolphin's views aren't set up yet and there is nothing to
send setFocus to.

Furthermore, I can't change the tab order so that what I want focused
comes first.

Any suggestions?


-----------------------------------------------------------------------------

onInitDialog
 "Default handler for dialog initialization."

 "Since the dialog is loaded from a resource template the window styles
 will not match those set for the receiver. Transfer our styles across
 here"
 self styles: self styles.

 "Similarly, Windows always creates dialog as a child of the desktop.
 Force the required parent here"
 UserLibrary default setParent: self asParameter hWndNewParent:
creationParent asParameter.

 "Tell Windows to set the focus."
 ^true
------------------------------------------------------------------------------

wmInitDialog: message wParam: wParam lParam: lParam
 "A WM_INITDIALOG message was sent by the dialog proc. Answer false if
the focus has been set,
 or true if leaving that to Windows.

 N.B. This message is received before the contents of a Dolphin dialog
view have been established
 so would consequently be of little use. To avoid confusion we do not
send the event on to the
 presenter but, as the event may be useful to fully defined dialogs
(i.e. those loaded from a template),
 we do send it to the receiver as #onInitDialog."

 "Cache the initialize default button."
 self defaultButtonId: self getDefId.

 "A 'feature' of Windows dialogs is that that default button may be
IDOK, even if there is no such
 button so we clear the non-existant button down to prevent confusion
later."
 self defaultButtonId isNil ifTrue: [self setDefId: 0].

 ^self onInitDialog


Reply | Threaded
Open this post in threaded view
|

Re: Initial focus in dialog box

Ian Bartholomew
Keith,

"Keith Alcock" <[hidden email]> wrote in message
news:[hidden email]...
> Has anyone worked out a way to set the initial focus in a dialog box?
>
> Doing so in the presenter's onViewOpened method has no effect.

How about just making it wait until the view has been opened ...

onViewOpened
    super onViewOpened.
    SessionManager inputState
        queueDeferredAction: (MessageSend
            receiver: (self view viewNamed: 'whatever')
            selector: #setFocus)

... seems to work for me. Forking a block that sets the focus after a short
delay also seems to work but the above seems a bit less "nasty".

Ian


Reply | Threaded
Open this post in threaded view
|

Re: Initial focus in dialog box

Keith Alcock
Ian,

Thanks a bundle.  It would have taken me days to find queueDeferredAction, not
knowing that anything like it existed.

It works great for edit boxes.  If I try to use it on the only button in a
dialog (and only tab stop), the button does not appear to be focused.  It
doesn't have the text outlined and won't respond to the space bar, etc.  In a
different dialog with multiple buttons, it does seem to work, though.

I'm content charging this one to the vagaries of Windows, unless anyone happens
to recognize these symptoms.

Thanks again.

Keith


Ian Bartholomew wrote:

> Keith,
>
> "Keith Alcock" <[hidden email]> wrote in message
> news:[hidden email]...
> > Has anyone worked out a way to set the initial focus in a dialog box?
> >
> > Doing so in the presenter's onViewOpened method has no effect.
>
> How about just making it wait until the view has been opened ...
>
> onViewOpened
>     super onViewOpened.
>     SessionManager inputState
>         queueDeferredAction: (MessageSend
>             receiver: (self view viewNamed: 'whatever')
>             selector: #setFocus)
>
> ... seems to work for me. Forking a block that sets the focus after a short
> delay also seems to work but the above seems a bit less "nasty".
>
> Ian


Reply | Threaded
Open this post in threaded view
|

Re: Initial focus in dialog box

Ian Bartholomew-3
Keith,

> It works great for edit boxes.  If I try to use it on the only button in a
> dialog (and only tab stop), the button does not appear to be focused.  It
> doesn't have the text outlined and won't respond to the space bar, etc.
In a
> different dialog with multiple buttons, it does seem to work, though.

Have you set the button's #isDefault property to true? This could make a
difference for a Dialog with a single button and mean you might not need the
#setFocus.

Ian