💾 Archived View for blitter.com › apl-books › APLX50 › APLX-manual › www.microapl.com › apl_help › c… captured on 2024-08-18 at 20:33:59.
⬅️ Previous capture (2022-07-17)
-=-=-=-=-=-=-
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE>Modal Dialogs</TITLE> <META NAME="DESCRIPTION" CONTENT="APL language help page: Modal Dialogs"> <META NAME="KEYWORDS" CONTENT="modal,dialog,dialogs,apl,aplx,apl help"> <!-- %%COMMON_HEAD%% --> <META http-equiv="Content-Type" content="text/html; charset=utf-8"> <LINK rel="stylesheet" type="text/css" href="http://www.microapl.com/styles_apl_help.css"> <!-- %%END%%--> </HEAD> <body> <table> <tr> <td width="800" valign="top" colspan="2"> <center>Topic: <A HREF="ch.htm"><code>APLX Help</code></A> : <A HREF="ch_030.htm"><code>System Classes</code></A> : <A HREF="ch_030_050.htm"><code>Events and callbacks</code></A> : <A HREF="ch_030_060.htm"><code>Modal Dialogs</code></A> </center> <center> [ <A HREF="ch_030_055.htm">Previous</A> | <A HREF="ch.htm">Contents</A> | <A HREF="help_index.htm">Index</A> | <A HREF="http://www.microapl.co.uk/apl/index.html">APL Home</A> ]</center> <br></td> </tr> <tr> <td width="120"> <a href="http://www.microapl.co.uk/apl/index.html"><img height="68" border="0" width="119" src="MicroAPL_logo.gif" alt="www.microapl.co.uk"></a> </td> <td align="left" valign="bottom"> <h1>Modal Dialogs</h1> </td> </tr> <tr> <td width="800" valign="top" colspan="2"> <hr> <H2>Making your own modal dialogs</H2> <P>The default behaviour of all windows you create (even Dialog objects) is non-modal, which means that the user can activate other windows and menus. Often, this behaviour is preferred, since it gives the user more control over the application. Sometimes, however, you may wish a dialog to be modal, which means that the user must close the dialog (typically by clicking in an OK or Cancel button) before continuing with other tasks. In addition, you might want your program to wait until the dialog has been closed before proceeding. These two features are logically separate, but often go together. You make the dialog modal by invoking the <tt>Wait</tt> method on it, and you cause your program to wait for the dialog to be closed by calling <code>⎕WE</code> with a right argument which is the name of the window. The following is a complete example of a function which puts up a modal dialog containing a label and two buttons. The function then waits until the user has responded, and returns 1 if the user presses the 'Yes' button or 0 if he presses the 'No' button.</P> <PRE> ∇R←ASK;X;MyDlog [1] ⍝ Example of a modal dialog [2] MyDlog←'⎕' ⎕NEW 'Dialog' ⋄ MyDlog.size←5 34 [3] MyDlog.Label.New 'Label' ⋄ MyDlog.Label.where←0.5 4 1.5 30 [4] MyDlog.Label.caption←'Do you want to erase this file?' [5] MyDlog.No.New 'Button' ⋄ MyDlog.No.where←3 3 1.5 8 ⋄ MyDlog.No.style←2 [6] MyDlog.Yes.New 'Button' ⋄ MyDlog.Yes.where←3 23 1.5 8 ⋄ MyDlog.Yes.style←1 [7] MyDlog.No.onClick←'R←0 ⋄ MyDlog.Close' [8] MyDlog.Yes.onClick←'R←1 ⋄ MyDlog.Close' [9] MyDlog.Wait [10] R←0 [11] X←⎕WE MyDlog ∇ </PRE> <P>In this function, line <code>[9]</code> causes the dialog to be modal, and line <code>[11]</code> causes the function to wait until the Dialog object MyDlog has been closed (or hidden), executing any callbacks which are invoked as a result of events that come in. The Dialog object can be closed under program control, by calling the Close method. In this example, this happens when either of the Yes or No buttons is clicked, which causes the onClick handler to be invoked, as set up in lines <code>[7]</code> and <code>[8].</code> If the user presses the 'Yes' button, the APL function behaves very much as though line <code>[11]</code> was:</P> <pre>[11] ⍎'R←1 ⋄ MyDlog.Close' </pre> <P>which has the effect both of setting the explicit result of the function and closing the dialog.</P> <H2>Pre-defined modal dialogs</H2> <p>As an alternative to creating your own modal dialogs, you can often use one of the pre-defined dialog objects which are built-in to APLX. These include MsgBox, ChooseFont, ChooseDir, ChooseColor, OpenFile and SaveFile. To use these, you create an instance of the object, set the properties you want, and then call the Show method. This displays the dialog modally, and returns an integer indicating which button was used to exit. Where appropriate, you can then read the properties to see what the user selected. The above example can be written more simply as:</p> <pre> ∇R←ASK;MBOX [1] ⍝ Modal dialog using the MsgBox object [2] MBOX←'⎕' ⎕NEW 'MsgBox' ⋄ MBOX.style←3 ⋄ MBOX.icon←1 [3] MBOX.text←'Do you want to erase this file?' [4] R←6=MBOX.Show ∇ </pre> <hr> </td> </tr> <tr> <td width="800" valign="top" colspan="2"> <center>Topic: <A HREF="ch.htm"><code>APLX Help</code></A> : <A HREF="ch_030.htm"><code>System Classes</code></A> : <A HREF="ch_030_050.htm"><code>Events and callbacks</code></A> : <A HREF="ch_030_060.htm"><code>Modal Dialogs</code></A> </center> <center> [ <A HREF="ch_030_055.htm">Previous</A> | <A HREF="ch.htm">Contents</A> | <A HREF="help_index.htm">Index</A> | <A HREF="http://www.microapl.co.uk/apl/index.html">APL Home</A> ]</center> <br></td> </tr> </table> <!-- %%COMMON_BODY_TAIL%% --> <p class="copyright">Copyright © 1996-2010 MicroAPL Ltd</p> <!-- %%END%% --> </body> </html>