Re: How to simulate window close button (what I'm really trying to do...)
- From: Murray Cumming <murrayc murrayc com>
- To: Toralf Lund <toralf procaptura com>
- Cc: 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 11:56:30 +0100
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.
>
> Actually, I've been sort of wondering about how one might simulate
> button clicks or manu selections or whatever, but what I was really
> looking for this time was to run the window close-button behaviour, and
> I thought I might try doing it by emitting a fake delete event signal.
> I'm not really sure this is a good idea, but at least it seemed cleaner
> that sending an actual event to myself...
>
> 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?
>
> I know I can just connect the hide() method to my button, but that's not
> really the same thing, as the WM "delete" actually leads to a chain of
> events that may or may not end in hide(). In the particular case I was
> looking at, the application will in fact stop handling the delete before
> it gets that far if certain conditions are met.
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.
Emmitting signals directly, for a class that you didn't implement, seems
like messing with the internals of that class.
--
murrayc murrayc com
www.murrayc.com
www.openismus.com
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]