WideStudio Programming Guide

| WideStudio Programming Guide | WideStudio Index Table of contents

> ## How to indicate a dialog on the EXIT event procedure

> There is the case to need to save data indicate a dialog whether to finish the application, when the application is finished by closing the window. In such a case it is convenient to use the WSEV_EXIT event procedure of the WSCwindow/WSCmainWindow class.
> The WSCwindow/WSCmainWindow class generates the "exit" trigger when the window is disappeared before finishing the application.
> At first set True to the property "exit" of a WSCwindow/WSCmainWindow instance which is used as main window in the application, and put an event procedure to it with WSEV_EXIT trigger.
> We will try to make an event procedure to have the following facility.
> - Indicates the dialog whether exit or continue.
> - If [OK] is selected,execute some procedure and exit the application.
> - If [NO] is selected,exit the application with no process.
> - If [CANCEL] is selected,do nothing and does not exit the application.

>     #----------------------------------------------------------
>     #Function for the event procedure
>     #----------------------------------------------------------
>     # The timer procedure which redisplay the window.
>     use mpfc;

>     $timer = 0;
>     $target = 0;
>     sub delayproc {
>       my ($object) = @_;

>       if ($target != 0){
>         $target->setVisible($mpfc::True);
>       }
>       return;
>     }

>     # EXIT event procedure
>     # Indicates a dialog.
>     sub exit_ep {
>       my ($object) = @_;
>       if ($object->getVisible() != $mpfc::False){
>         return;
>       }
>       $msg = mpfc::WSGIappMessageDialog(); #A
>       $msg->setProperty("width",500);
>       $msg->setProperty("no",$mpfc::True);
>       $msg->setProperty("defaultPosition",$mpfc::True);
>       $msg->setProperty("labelString",
>         "Exit and save data?\n If you do not want to save and exit,push NO...");

>       # Indicates the dialog.
>       $ret = $msg->popup(); #B

>       # saving some data ...
>       if ($timer == 0){
>         $timer = new mpfc::WSCvtimer($object,"objname");
>         $timer->init();
>         $timer->setProperty("interval",250);
>         $timer->setProperty("cont",$mpfc::False);
>         $timer->addProcedure("delay-popup","delayproc",$mpfc::WSEV_ACTIVATE);
>       }
>       if ($ret == $mpfc::WS_DIALOG_OK){         # When OK is selected.. C
>         # saving some data ...
>         exit(0);
>       }elsif ($ret == $mpfc::WS_DIALOG_NO){       # When NO is selected.. D
>         exit(0);
>       }elsif ($ret == $mpfc::WS_DIALOG_CANCEL){   # When CANCEL is selected.. E
>         $target = $object;
>         $timer->setProperty("running",$mpfc::True);
>       }
>       return;
>     }
>     1;

> Get the instance of the message dialog (A),indicate it (B). Check the result of the dialog (C)(D)(E). It need to execute delayed procedure to redisplay the window, because it is required that the exit event is done before the window be redisplayed.

> [The exit dialog]

Document Release 3.70 for WideStudio ver 3.70, Feb 2004

WideStudio documents index | Table of contents

Copyright(C) T. Hirabayashi, 2000-2004 | Last modified: Feb 25, 2004