How to detect the close of form window

All graphical and user interfaces problems

How to detect the close of form window

Postby manumart1 » Fri Mar 13, 2015 12:38 pm

Is it possible to detect the event "the user closing the window of a form" (red X in upper right corner)?
I would like to cleanup variables of the module (they may have many information not needed anymore).
When the user open the form again I initialize variables via menu:
"StdCmds.OpenAuxDialog('Priv/Rsrc/A', 'Test'); PrivA.Init()".

If not, is it possible to open the window of the form, with the close button disabled; I would put my own ad hoc button to cleanup and then call "StdCmds.CloseDialog".

Thank you,
Manuel
manumart1
 
Posts: 67
Joined: Tue Sep 17, 2013 6:25 am

Re: How to detect the close of form window

Postby cfbsoftware » Fri Mar 13, 2015 12:59 pm

There was a discussion titled How to disable the window close button started on the Oberon microsystems mailing list on 19th Jun 2014. Although the aim was different to yours I think there should be enough information there to enable you to do what you are trying to do.

Unfortunately the archives at http://blackboxframework.org/archive/ only go up to Sep 2013. However, I have attached a zipped copy of the emails involved in the discussion.
Attachments
Re BLACKBOX How to disable the window close button.zip
(98.42 KiB) Downloaded 230 times
cfbsoftware
 
Posts: 41
Joined: Wed Sep 18, 2013 10:06 pm

Re: How to detect the close of form window

Postby manumart1 » Fri Mar 13, 2015 1:40 pm

Many thanks, Chris.
I will look at your attached code, it seems very interesting.

Finally, I found a way to detect the closing of the window. It is explained in Sql Developer Manual (Sql/Docu/Dev-Man), paragraphs Determining whether the window should be closed and Cleaning up when the window is closed:
  • Via menu SQL — Insert Anchor I put a special control in the form, and link it to a any pointer variable of my module.
  • That anchor control can have a Guard and a Notifier.
  • The purpose of the Guard is to show a message to confirm the closing of the window. If the linked variable is not NIL and Guard puts par.disabled to TRUE then the confirm message is shown. I do not need it now.
  • The Notifier is a parameterless procedure, and is tiggered when the window is closed. I will put here my cleanup code.
  • The linked variable is set to NIL when finally the window is closed.

Regards
manumart1
 
Posts: 67
Joined: Tue Sep 17, 2013 6:25 am

Re: How to detect the close of form window

Postby manumart1 » Mon Mar 16, 2015 4:45 pm

For my problem it is enough to use an Anchor control. That control offers two functionalities:
  1. Alert to the user when he tries to close the window (and the module decides that the message is relevant, putting TRUE in par.disabled via Guard).
  2. Notify the module when the window is being closed (no opportunity no abort).
I only need functionality 2. For that, the Anchor control does not even need a link, only a Notifier.

Thanks to Chris, I learned another way to be notified when the user tries to close the window. I put it here just for the record:

To open the form, instead of
Code: Select all
StdCmds.OpenAuxDialog('Priv/Rsrc/A', 'Test')

you must call to the procedure OpenForm shown below:
Code: Select all
TYPE MyNotifier = POINTER TO RECORD (Sequencers.Notifier) END;

PROCEDURE (n: MyNotifier) Notify (VAR msg: Sequencers.Message);
   VAR res: INTEGER;
BEGIN
   WITH msg: Sequencers.CloseMsg DO
      Dialog.Beep;
      (*
      IF ... THEN
         msg.sticky := TRUE (* This avoid the closing *)
         Dialog.GetOK("You can not close the window because this and this", "", "", "", {Dialog.ok}, res);
      END
      *)
      Dialog.GetOK("Window will close ¿Sure?", "", "", "", {Dialog.yes, Dialog.no}, res);
      IF res # Dialog.yes THEN
         msg.sticky := TRUE (* This avoid the closing *)
      END
   ELSE
   END
END Notify;
..
PROCEDURE OpenForm();
   VAR v: Views.View; n: MyNotifier;
BEGIN
   StdApi.OpenAuxDialog('Priv/Rsrc/A', 'Test', v);
   NEW(n);
   v.Domain().GetSequencer()(Sequencers.Sequencer).InstallNotifier(n)
END OpenForm;

When the user tries to close the window, the method Notify of n will be called, and there msg.sticky can be set to TRUE with the purpose of avoiding the closing.

Regards,
Manuel
manumart1
 
Posts: 67
Joined: Tue Sep 17, 2013 6:25 am


Return to GUI problems

Who is online

Users browsing this forum: No registered users and 1 guest

cron