Re: How to simulate window close button (what I'm really trying to do...)
- From: Toralf Lund <toralf procaptura com>
- To: GTK-- Mailing List <gtkmm-list gnome org>
- Subject: Re: How to simulate window close button (what I'm really trying to do...)
- Date: Mon, 17 Dec 2007 13:17:40 +0100
Murray Cumming wrote:
On Mon, 2007-12-17 at 11:37 +0100, Toralf Lund wrote:
OK, maybe I should tell people what I'm really trying to do - see my
other post. [ ... ]
In any case, I'm on to something that has sort of bugged me for years;
in all my Gtk/Gtkmm window I generally have a button called "Close" or
"Cancel", or a "Close" menu item, depending on the context, that is
supposed to do *exactly* what a window manager close or "window delete"
will do. It seems to me that this isn't exactly uncommon, so why is
there no way of telling Gtk(mm) exactly what I want? I mean, why can't I
just say, "please let this button do a window delete", and forget about
the rest? Or can I do this? [ ... ]
You already need to connect a signal handler for delete_event so you
can, for instance, show your do-you-really-want-to-close dialog. If you
also have a [Close] button then I'd just connect that to the same signal
handler.
The only reason that this is not quite so simple is that delete_event
uses the nasty return-true/false-to-do-something system. But you can
still abstract that out quite easily to a separate function, so you
have
void on_button_close()
{
if(ask_for_confirmation())
hide();
}
bool on_delete_event()
{
return ask_for_confirmation();
}
or similar.
Yeah, I know, but like I said, it's always bugged me that I have to do
something like this. It seems to me there ought to be a simple and
direct way of saying "this button should delete the window", and/or "do
a window delete now"...
Or maybe I don't care that much, but it has at least surprised me that
I've never been able to find a ready-made setup for the close behaviour,
and I've been thinking I must have overlooked something. So thought I
might ask after this came up again recently because I had made a mistake
and called hide() directly for a Close button where the delete event
setup had other stuff...
Emmitting signals directly, for a class that you didn't implement, seems
like messing with the internals of that class.
Well, perhaps it's not so much the signal emit as such I want, but
rather simulation of a user action, i.e. a way of saying something like
"pretend this button was pressed" or "execute the button press logic
now". Which is not the same thing as duplicating the calls that will
actually be done...
- Toralf
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]