The dialog table contains all the necessary information concerning the dialog. This means, the list of controls and their properties. It also contains the size & position of the dialog, dialog title, and display options.
The following table describes a simple dialog containing 3 radio boxes grouped within a frame box, 3 check boxes grouped within a frame box, 1 edit box, and 2 command buttons.
dialog sample {
title "Sample Dialog"
size -1 -1 115 90
option dbu
box "Check Boxes",1,5 5 50 39
check "Check Box 1",2,8 12 40 11
check "Check Box 2",3,8 22 40 11
check "Check Box 3",4,8 32 40 11
box "Radio Boxes",5,60 5 50 39
radio "Radio Box 1",6,63 12 40 11
radio "Radio Box 2",7,63 22 40 11
radio "Radio Box 3",8,63 32 40 11
edit "",10,5 50 105 11,autohs,result
edit "",11,5 62 105 11,autohs
button "Accept",100,48 75 30 11,ok
button "Cancel",101,80 75 30 11,cancel
}
Note: The table must be placed in the Script section, not the Aliases section.
Now, for the sections of the dialog table.
The first item <title> contains the dialog title. The second item <size> contains the size & position of the dialog in the format <x y w h>. Using -1 for x and y centers the dialog on the screen. The third item <option> can have the value dbu (default base units) or pixels, which relay on the display option of the end user. Pixels are the default.
On the other hand, all of the controls have a specific definition format :
control type "Caption Text", ID Number , X Y W H , control properties
Sizing controls should be done on site, reviewing their relation with all other controls on the dialog.
The dialog table must have a control whose properties will contain the switch ok or cancel or both. This allows the dialog to close by clicking on either of that controls.
Finally, the beauty of the dialog table is in it's versatility and ability to be used in an infinite number of various dialogs, by just changing the default control properties.
Lets suppose that you have set several options using some internall variables which reffer to the given dialog table. The variables and the values are :
%sample.checkone On
%sample.checktwo Off
%sample.checkthree Off
%sample.radio 2
%sample.editone Sample Option 1
%sample.edittwo Sample Option 2
If you have set these variables, we can proceed to the initialization event :
On *:DIALOG:sample:init:0:{
if (%sample.checkone == On) { did -c sample 2 }
if (%sample.checktwo == On) { did -c sample 3 }
if (%sample.checkthree == On) { did -c sample 4 }
did -c sample $calc(5 + %sample.radio)
did -a sample 10 %sample.editone
did -a sample 11 %sample.edittwo
}
Note: Even though you can set the text of the Edit Boxes in the table by simply typing the names of the variables, that option has been quite unpractical, because the absence of the specified variable generates an error in the script.
By now, you should have a dialog with one checked Check Box and one checked Radio Box, and then tho Edit Boxes filled with sample text.
After clicking the OK button, follow the sclick event, which saves the values of the variables for further setting.
On *:DIALOG:sample:sclick:100:{
if ($did(sample,2).state == 1) { set %sample.checkone On }
else { set %sample.checkone Off }
if ($did(sample,3).state == 1) { set %sample.checktwo On }
else { set %sample.checktwo Off }
if ($did(sample,4).state == 1) { set %sample.checkthree On }
else { set %sample.checkthree Off }
if ($did(sample,6).state == 1) { set %sample.radio 1 }
elseif ($did(sample,7).state == 1) { set %sample.radio 2 }
else { set %sample.radio 3 }
set %sample.editone $did(sample,10).text
set %sample.edittwo $did(sample,11).text
}
Note: Commands and alias definitions can find their way insides the sclick event, even though you should try to avoid them in order to keep the code clean. You could use the sclick events generated by clicks on Radio & Check Boxes, but they seem to be non-reliable in case the user clicks the Cancel button.
This about finishes this sample options dialog. The full code should look like this :
dialog sample {
title "Sample Dialog"
size -1 -1 115 90
option dbu
box "Check Boxes",1,5 5 50 39
check "Check Box 1",2,8 12 40 11
check "Check Box 2",3,8 22 40 11
check "Check Box 3",4,8 32 40 11
box "Radio Boxes",5,60 5 50 39
radio "Radio Box 1",6,63 12 40 11
radio "Radio Box 2",7,63 22 40 11
radio "Radio Box 3",8,63 32 40 11
edit "",10,5 50 105 11,autohs
edit "",11,5 62 105 11,autohs
button "Accept",100,48 75 30 11,ok
button "Cancel",101,80 75 30 11,cancel
}
On *:DIALOG:sample:init:0:{
if (%sample.checkone == On) { did -c sample 2 }
if (%sample.checktwo == On) { did -c sample 3 }
if (%sample.checkthree == On) { did -c sample 4 }
did -c sample $calc(5 + %sample.radio)
did -a sample 10 %sample.editone
did -a sample 11 %sample.edittwo
}
On *:DIALOG:sample:sclick:100:{
if ($did(sample,2).state == 1) { set %sample.checkone On }
else { set %sample.checkone Off }
if ($did(sample,3).state == 1) { set %sample.checktwo On }
else { set %sample.checktwo Off }
if ($did(sample,4).state == 1) { set %sample.checkthree On }
else { set %sample.checkthree Off }
if ($did(sample,6).state == 1) { set %sample.radio 1 }
elseif ($did(sample,7).state == 1) { set %sample.radio 2 }
else { set %sample.radio 3 }
set %sample.editone $did(sample,10).text
set %sample.edittwo $did(sample,11).text
}