[wxMSW,WXGTK] Modeless dialog, how to handle OK event

[wxMSW,WXGTK] Modeless dialog, how to handle OK event

Post by Carsten A. » Mon, 01 Oct 2007 07:12:46


Hi,

I have a dialog which is always modeless

MyDialog* dialog = new MyDialog(this);
dialog->Show();

During creation this dialog calls CreateButtons(wxOK|wxCANCEL);
to create an OK and a Cancel button

What is the proper way to handle OK being pushed, so a different action from
what happens when Cancel is pushed can be taken?

I have done this in MyDialog
Connect(wxID_OK,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&MyDialog::OnOk);

And it seems to work. But I wonder if this is the proper way.

--
Carsten A. Arnholm
http://www.yqcomputer.com/
N59.776 E10.457
 
 
 

[wxMSW,WXGTK] Modeless dialog, how to handle OK event

Post by vadi » Mon, 01 Oct 2007 07:18:42


CAA> What is the proper way to handle OK being pushed, so a different action from
CAA> what happens when Cancel is pushed can be taken?
CAA>
CAA> I have done this in MyDialog
CAA> Connect(wxID_OK,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&MyDialog::OnOk);
CAA>
CAA> And it seems to work. But I wonder if this is the proper way.

I'm afraid I don't understand what exactly you're looking for. You can, of
course, handle the events from the button like above (although you should
use wxCommandEventHandler macro instead of casting to wxObjectEventFunction
like this). Or you can use an event table in the dialog class, which may be
more usual.

Regards,
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
http://www.yqcomputer.com/


---------------------------------------------------------------------
To unsubscribe, e-mail: XXXX@XXXXX.COM
For additional commands, e-mail: XXXX@XXXXX.COM

 
 
 

[wxMSW,WXGTK] Modeless dialog, how to handle OK event

Post by Carsten A. » Mon, 01 Oct 2007 08:40:48


Thank you for replying, Vadim.

I am trying to understand how to best handle some common patterns, in this
case modeless dialogs. Such patterns are probably obvious to seasoned
wxWidgets programmers, but I am still learning. Most things in wxWidgets
appear very clear & concise, and fairly easy to understand. But I have been
confused about some simple things, e.g. how to handle OK and Cancel in
dialogs, but it is getting a bit clearer now.

I followed your advice and fund I could do
Connect(wxID_OK,wxEVT_COMMAND_BUTTON_CLICKED,wxCommandEventHandler(MyDialog::OnOk));
and similar using wxMouseEventHandler for mouse events. I had not seen this
before, so thank you. I agree it is much cleaner. I did the casting, because
that is what wxSmith does in Code::Blocks.

Now, based on your comment I also found I could do

BEGIN_EVENT_TABLE(...)
EVT_COMMAND(wxID_OK,wxEVT_COMMAND_BUTTON_CLICKED,MyDialog::OnOk)
END_EVENT_TABLE()

After looking at it, it seems obvious. Part of the problem here is pieceing
together all the available information. I knew about event tables, I have
read the wxWidgets book etc.. Still, somehow it was not obvious to me what
to do with a call like CreateButtons(wxOK|wxCANCEL); wrt. handling the
event. You have to understand that wxOK isn't wxID_OK of example, it took me
a while.

So I think your replied to my concrete question was useful, the best would
here be to use the event table I guess. But it was also useful to learn
about better ways of using Connect(...), since it is sometimes necessary to
install events at runtime (I have seen it with some mouse events).

Still learning, thanks for your time :-)

--
Carsten A. Arnholm
http://www.yqcomputer.com/
N59.776 E10.457