APLX Help : System Classes : Events and callbacks : Modal Dialogs
|
|
Modal Dialogs |
|
Making your own modal dialogsThe 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 Wait method on it, and you cause your program to wait for the dialog to be closed by calling ∇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 ∇ In this function, line [11] ⍎'R←1 ⋄ MyDlog.Close' which has the effect both of setting the explicit result of the function and closing the dialog. Pre-defined modal dialogsAs 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: ∇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 ∇ |
|
APLX Help : System Classes : Events and callbacks : Modal Dialogs
|
Copyright © 1996-2010 MicroAPL Ltd