news |
info |
people |
software |
stuff |
Dialog XCMD. Version 1.1d3, by Sam Deane. Copyright ©1994 ULTRALAB. Compiled 11:28:19, 21/03/95. Debugging code included.
This XCMD allows you to create and display your own custom dialogs. They can contain colour pictures, icons, editable and locked text, checkboxes, radio and standard buttons. Currently only modal dialogs are supported, but the XCMD may be extended in the future to allow modeless dialogs.
The dialog definitions are stored in DLOG/DITL resources, which you can create with a resource editor such as ResEdit. The positions, names, contents and states of any dialog item can also be modified at runtime, allowing you to change the name of a button dynamically, or put some appropriate default text into an editable field.
When the user dismisses the dialog, the external commands returns full information about the state of every dialog item, allowing you to find out which button was pressed, what text was entered into any text fields, etc.
How the options are interpreted for each item depends upon the type of the item - a checkbox has a different set of options from those for an editable text field. Below is a list of each item type, the options that it accepts, and what they do:
name <name> This option sets the name of the button to word <name>.
labelThis option takes the remaining text in the item, and sets the name of the button to it.
defaultThis option makes the button the default item. This means that the button gets a thick border, and it gets clicked if the return or enter keys are pressed.
cancelThis option makes the button the cancel item, which gets clicked if the escape key is pressed.
name <name> This option sets the name of the checkbox to word <name>.
labelThis option takes the remaining text in the item, and sets the name of the checkbox to it.
onThis option makes the checkbox start hilited.
offThis option makes the checkbox start unhilited.
name <name> This option sets the name of the radio button to word <name>.
labelThis option takes the remaining text in the item, and sets the name of the radio button to it.
onThis option makes the radio button start hilited.
offThis option makes the radio button start unhilited.
group <group>This option sets the group of the radio button to <group>. Radio buttons with the same group are mutually exclusive - if one is hilited the rest are automatically unhilited. This option allows you to have more than one group of radio buttons.
from <var>This option tells the XCMD to take the text for the item from the global variable called <var>.
from <var>This option tells the XCMD to take the text for the item from the global variable called <var>.
pict <name>This option gives the name or id of the PICT resource to use.
icon <name>This option gives the name or id of the ICON resource to use.
on mouseUp -- ÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐ -- Setting up the dialog: -- -- Information about the contents and layout of the dialog is -- stored in the DLOG and DITL resources called "Simple Test", -- which are stored in this stack. -- -- However, some information needs to be set up dynamically -- at the time that the dialog is going to be displayed. This -- information is passed to the XCMD in its third parameter. -- -- In this example the third parameter is stored in the -- variable called "modifiers". Each item of "modifiers" can contain -- messages which modify the corresponding item in the dialog. -- If an item of "modifiers" is left empty, the dialog item is -- displayed exactly as it was specified in the DITL resource. -- make item 8 the default button put "default" into item 8 of modifiers -- make item 9 the cancel button (chosen if you press escape) put "cancel" into item 9 of modifiers -- set the top radio button to be hilited put "on" into item 3 of modifiers -- put some default text into the editable field global item7text put "It's now " & the long time into item7text put "from item7text" into item 7 of modifiers -- ÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐ -- ÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐ -- Showing the dialog: -- -- To show the dialog we simply call the "Dialog" XCMD, with -- the command "modal", the name of the DLOG resource to use, -- and the modifiers variable -- -- The XCMD returns control to us when the user presses on one -- of the standard buttons (in this case "OK" or "KO") Dialog modal,"Simple Test",modifiers -- ÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐ -- ÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐ -- Interpreting the results: -- -- The result returned by the dialog is similar to the setup -- string that we passed in the variable "modifiers". -- Each item in the result corresponds to the final state of -- an item in the dialog. get the result answer radioState(it) && checkState(it) && buttonPressed(it) Â & return & return & "Ò" & textEntered(it) & "Ó" -- ÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐ end mouseUp function buttonPressed state -- look at the state returned by the XCMD to see which of -- the buttons was clicked on if item 8 of state then return "You pressed OK" else return "You pressed KO" end if end buttonPressed function radioState state -- look at the state returned by the XCMD to see which of -- the radio buttons was hilited if item 3 of state then return "Boring..." else if item 4 of state then return "Hmmm..." else if item 5 of state then return "Wow!" end if end radioState function checkState state -- look at the state returned by the XCMD to see -- whether the checkbox was hilited if item 6 of state then return "Impressed eh?" else return "Not impressed eh?" end if end checkState function textEntered state -- get the text entered into the editable field -- we know that this will be in the global "item7text", -- since we know that the editable field is item 7 in the dialog global item7text return item7text end textEntered
The syntax is:
Dialog modal,<name> {,<modifiers>}
The <name> parameter should be the name or id of the DLOG/DITL resource pair that you want to display.
The <modifiers> parameter is optional. You can use it to alter the appearance of the dialog items defined in the DITL resource. See the section "Using Modifiers to Customise a Dialog" for more details.
The XCMD will keep displaying the modal dialog until the user clicks one of the active buttons, icons or pictures in the dialog (make sure you include at least one active button, picture or icon, otherwise the XCMD will never return!). It won't return when the user clicks on text, checkboxes or radio buttons - it handles these itself.
When the user clicks on something to dismiss the dialog, the XCMD disposes it, and sends back the state of the dialog in the result.
The result will be a list of states, one for each item in the dialog. What the state for an item means will depend on the type of the item.
For a button, the state will be true if the button was clicked on, false if not.
For a checkbox or radio button, the state will be true if the button was hilited, false if not.
For an editable text field, the state will contain the name of the global variable containing the contents of the field.
For all other items the state will be empty.
on mouseUp -- ÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐ -- Setting up the dialog: -- -- Information about the contents and layout of the dialog is -- stored in the DLOG and DITL resources called "Simple Test", -- which are stored in this stack. -- -- However, some information needs to be set up dynamically -- at the time that the dialog is going to be displayed. This -- information is passed to the XCMD in its third parameter. -- -- In this example the third parameter is stored in the -- variable called "modifiers". Each item of "modifiers" can contain -- messages which modify the corresponding item in the dialog. -- If an item of "modifiers" is left empty, the dialog item is -- displayed exactly as it was specified in the DITL resource. -- make item 8 the default button put "default" into item 8 of modifiers -- make item 9 the cancel button (chosen if you press escape) put "cancel" into item 9 of modifiers -- set the top radio button to be hilited put "on" into item 3 of modifiers -- put some default text into the editable field global item7text put "It's now " & the long time into item7text put "from item7text" into item 7 of modifiers -- ÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐ -- ÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐ -- Showing the dialog: -- -- To show the dialog we simply call the "Dialog" XCMD, with -- the command "modal", the name of the DLOG resource to use, -- and the modifiers variable -- -- The XCMD returns control to us when the user presses on one -- of the standard buttons (in this case "OK" or "KO") Dialog modal,"Simple Test",modifiers -- ÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐ -- ÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐ -- Interpreting the results: -- -- The result returned by the dialog is similar to the setup -- string that we passed in the variable "modifiers". -- Each item in the result corresponds to the final state of -- an item in the dialog. get the result answer radioState(it) && checkState(it) && buttonPressed(it) Â & return & return & "Ò" & textEntered(it) & "Ó" -- ÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐ end mouseUp function buttonPressed state -- look at the state returned by the XCMD to see which of -- the buttons was clicked on if item 8 of state then return "You pressed OK" else return "You pressed KO" end if end buttonPressed function radioState state -- look at the state returned by the XCMD to see which of -- the radio buttons was hilited if item 3 of state then return "Boring..." else if item 4 of state then return "Hmmm..." else if item 5 of state then return "Wow!" end if end radioState function checkState state -- look at the state returned by the XCMD to see -- whether the checkbox was hilited if item 6 of state then return "Impressed eh?" else return "Not impressed eh?" end if end checkState function textEntered state -- get the text entered into the editable field -- we know that this will be in the global "item7text", -- since we know that the editable field is item 7 in the dialog global item7text return item7text end textEntered