Re: best way to use multiple windows



Well, it is heap vs stack - I am not sure which is really better for "normal" gui applications. But I have always created my dialogs as pointers - it just seems more traditional c++.

MyPopupDialog *dlg = new MyPopupDialog(...) {
//set dialog to modal (but it can sometimes get hidden by other
// dialog which is annoying
// set up dialog display here
// let okay/cancel buttons set return variable flag and hide dialog
onokaybutton() {
returnFlag = 1;
dlg->hide();
}
// if flag true can have code engine or main dialog still read
// values from popup dlg here
delete dlg;

I find it is not too difficult to match the delete with the new.


Armin Burgmeier wrote:
Hi,

my approach to this is to derive such windows from Gtk::Dialog and to
add two buttons with Gtk::RESPONSE_OK and Gtk::RESPONSE_CANCEL. To show
the dialog, simply do

MyDialog dialog(*this, foo, bar);
if(dialog.run() == Gtk::RESPONSE_OK)
{
  // Take settings into main app
}

Gtk::Dialog::run blocks in a main loop until the user closes the window
by either pressing one of the buttons or closing the window (which fits
perfectly if you want modal windows). After your function returns, the
dialog will be destroyed automatically as it runs out of scope, so you
do not have to worry about memory management.

 - Armin
_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
http://mail.gnome.org/mailman/listinfo/gtkmm-list





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]