Re: How to simulate window close button (what I'm really trying to do...)



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.


Emmitting signals directly, for a class that you didn't implement, seems
like messing with the internals of that class.
After looking at my code again, I realised that I should also point out that I'm sort of touching the internals of the class in the sense that I want to implement this in a custom class that derives from Window. Ideally, the Close button/menu item behaviour should be completely internal to that class and/or transparent to the application. The confirmation dialog, on the other hand, is not necessarily "internal", but may instead be added by an application if it thinks it is necessary. So the above solution doesn't really work in the general case; I will either have to provide a separate signal for my applications, or have them connect to the delete event and the close button press/item selection. In both cases everything gets a lot more complicated than I what I think should be necessary ;-(

- T



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