Discussion:
[Foxgui-users] FXMessageBox : is it possible to move the focus to the NO button (instead of YES) ?
pof
2017-01-09 21:54:47 UTC
Permalink
Dear all,

I have got a FXMessageBox that runs modally using the following code line:
if
(MBOX_CLICKED_YES==FXMessageBox::question(this,MBOX_YES_NO,"Information",""Connection
failed!\nDo you want to remove the network access from the settings?"))
m_bIsNetworkAccessAuthorized = false;

The focus defaults to the YES button and I would like to set the default
to the NO button.
Is there an easy way to do that?
Thanks
JD
JVZ
2017-01-09 22:35:26 UTC
Permalink
On Mon, 9 Jan 2017 22:54:47 +0100
Post by pof
Dear all,
if
(MBOX_CLICKED_YES==FXMessageBox::question(this,MBOX_YES_NO,"Information",""Connection
failed!\nDo you want to remove the network access from the settings?"))
m_bIsNetworkAccessAuthorized = false;
The focus defaults to the YES button and I would like to set the default
to the NO button.
Is there an easy way to do that?
Well,

If you use the convenience functions, like:

if(FXMessageBox::question()==ID_CLICKED_YES){
}

then of course its all canned, and you can't change anything.

If you subclass FXMessageBox, your subclass's constructor could obtain the
pointers to the children, and set the focos on a different child.

In the case of MBOX_YES_NO, you're looking at:

// horizontal frame containing buttons is last child of FXMessageBox
FXWindow* buttons=getLast();

// No-button is last child of FXHorizontalFrame
FXWindow *nobutton=buttons->getLast();

// Set focus on it
nobutton->setFocus();


Hope this helps,


-- JVZ





+----------------------------------------------------------------------------+
| Copyright (C) 16:00 01/ 9/2017 Jeroen van der Zijp. All Rights Reserved. |
+----------------------------------------------------------------------------+
pof
2017-01-10 20:44:16 UTC
Permalink
Post by JVZ
On Mon, 9 Jan 2017 22:54:47 +0100
Post by pof
Dear all,
if
(MBOX_CLICKED_YES==FXMessageBox::question(this,MBOX_YES_NO,"Information",""Connection
failed!\nDo you want to remove the network access from the settings?"))
m_bIsNetworkAccessAuthorized = false;
The focus defaults to the YES button and I would like to set the default
to the NO button.
Is there an easy way to do that?
Well,
if(FXMessageBox::question()==ID_CLICKED_YES){
}
then of course its all canned, and you can't change anything.
If you subclass FXMessageBox, your subclass's constructor could obtain the
pointers to the children, and set the focos on a different child.
// horizontal frame containing buttons is last child of FXMessageBox
FXWindow* buttons=getLast();
// No-button is last child of FXHorizontalFrame
FXWindow *nobutton=buttons->getLast();
// Set focus on it
nobutton->setFocus();
Hope this helps,
-- JVZ
+----------------------------------------------------------------------------+
| Copyright (C) 16:00 01/ 9/2017 Jeroen van der Zijp. All Rights Reserved. |
+----------------------------------------------------------------------------+
Dear Jeroen,
this is exactly what I was looking for.
Still I am wondering whether there would be a possibility to modify the
FXMessageBox API in order to add such possibility in the original class.
Thanks anyway.
JD

Loading...