Re: [gtkmm] Automatically destroying a dialog



Marc Canaleta <mcanaleta telefonica net> writes:

> I want a dialog to be deleted when it is closed (similar to widgets
> created with manage()). The problem is that it isn't modal and I can
> have various of them simultanelly, so I must create it using new, and
> I don't know where to delete it when it is closed.
>
> I thinked using a thread for each dialog, is it the correct solution?

In most cases, the dialog has a purpose: it asks a question, such as
"which file should I load/save", requests input or informs you of some
problem or result.  These are all tied to particular events, and so in
my code these are all created and destroyed within the same signal
handler:

myclass::some_action()
{
   if (some_action_fails)
   {
     AlertDialog dialog (*this,
                         error_text,
                         message_text.str(),
                         Gtk::MESSAGE_ERROR,
                         Gtk::BUTTONS_OK,
                         true);
     dialog.run();
   }
   return;
}

This creates a new dialog (this is a custom dialog derived from
Gtk::Dialog) and runs it.  On closing, it goes out of scope and is
destroyed.

If it's owned by a particular window (a good idea, generally) then you
could clean them up in the destructor, or at a convenient point.

If you really don't want it to be destroyed deterministically: With
plain C, there's no cleaning up to do: closing the window -> "delete"
-> "destroy" -> widget destruction by default, IIRC.  However, I guess
with Gtkmm you also need to take care to deleting the C++ wrapper
object, too, and so this probably won't work unless this is taken care
of automatically by Gtkmm if the GObject destruction can trigger
destruction of the C++ wrapper (if so, I'm well impressed).  If not, I
guess you should have a handler in your dialog class that deletes
itself when called, and tie that to the delete event (I may be
massively wrong here, and would be glad to be proved wrong).


Regards,
Roger

-- 
Roger Leigh

                Printing on GNU/Linux?  http://gimp-print.sourceforge.net/
                GPG Public Key: 0x25BFB848.  Please sign and encrypt your mail.



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