Re: [gtk-list] Re: WindowToFront and modal dialogs questions



> hm, i'm not exactly sure what you'd want to have. you can raise a window (put it
> in front of all othe windows) by using
> gdk_window_raise (GTK_WIDGET (dialog)->window);

  Oh, that was what I needed. Just to put window to be visible.

> >      2) When user exits program, I want to close all sheets. Of course, when
> > sheet was changed, it asks before closing, whether to save changes, forget
> > changes or canel operation. If user wants to save sheet which was not yet saved,
> > file selection dialog pops up.
> 
> you need to connect to the "delete_event" of the dialogs, in the callback
> you have the coice of invoking gtk_main_quit() which will end gtk's main loop
> and usually exit the program, or to return FALSE which will just cause your window
> to be destroyed, or - if you encounter unsaved dialog contents - popup a new
> dialog window and return TRUE.

  Yes, I've figured this. The problem is partially solved by doing
gtk_grab_add(). I must only check in the delete event callbacks of other
windows, whether there is modal window and ignore delete event if so.

> >      It would make good sense if both these dialogs were modal. It is much
> > easier to program and it also limits unexpected user operations (trying to close
> > again sheet for which there is pending save dialog etc.) which must be carefully
> > tested for.
> > 
> >      So is it possible somehow to create modal dialogs?
> 
> for the development tree, you can use gtk_window_set_modal(), for the stable
> 1.0.x releases, you need to gtk_grab_add (dialog).
>

  OK, there is even more about modal dialogs: I program a lot in Delphi under
MS Windows. Modal dialogs have nice feature there. The call that shows them
won't return until dialog was closed. (Of course, if any event in other window
happens, your callback gets called.) Why is this nice? Because you don't have to
store local context when window is showing. I'll give you an example:

  Imagine you have some recursive function operating on data. And when you are
N levels in the recursion, recoverable error occurs in the processing. At this
point, you want to ask user whether to ignore error and continue, or to abort
operation.

  In GTK, you would have to somehow (probably in the list) store all (or at
least important) local variables of all levels of recursion somewhere. If user
chooses to abort, you forget them. When he wants to continue, you must restore
all the levels of recursion to jump where you were when the error occured.
Possible but complicated.

  In Delphi, it is simple. You just write something like:
  if (MessageBox('Recoverable error',mtWarning,[mbIgnore,mbAbort],0) == IDABORT)
   Result := FALSE  // Abort
  else begin
    // Recover from error
  end;
  - MessageBox function returns when user closes dialog. And it is not only for
  MessageBoxes, other dialogs (those created by appliaction and called with
  ShowModal, file dialogs, ...) work eactly the same way.

  Maybe there could be function in GTK that would return after given widget was
hidden. In the meantime, messages would be dispatched as usual. Anyway it would
be much easier to program with this behavior implemented.

					Michal Kara alias lemming



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