Child Dialog Boxes

 

Whether modal or modeless, a typical dialog box displays as a pop-up on top of the main application until dismissed. A child dialog box, however, is embedded directly into the worksheet.

 

The @child option with a value of 1 specifies a child dialog box. Child dialog boxes usually also specify the @modeless option.

 

// child.pan - child dialog box

@dialog

 

// location in pixels - upper left corner

@xd 10

@yd 10

 

// modeless

@modeless 1

 

// child - embedded worksheet

@child 1

 

// default values

{defvar("dist", 0);defvar("len", 100);defvar("dx", 0.01)}

 

Generate Random Data

Distribution <r n>~dist = <{dist}>~<Uniform><Normal>

Length:      <w=20>~len = <{len}>~input(2)

Delta X:     <w=20>~dx  = <{dx}>~input(1)

<L>

~if(dist==0, gfunc = "Grandom", gfunc = "Gnormal")

~eval(sprintf("W0 := %s(%d, %g)", gfunc, len, dx))

~menureturn

 

 

Obviously, the worksheet width must be adjusted to properly display the embedded dialog box. By obtaining the menu handle to determine the width of the child dialog, the worksheet coordinates can be set to automatically accommodate the embedded dialog.

 

m=menufile("child.pan");setwsx(getmenucoords(m)+10, -1)

 

 

If the worksheet is saved as a DWK file, an external worksheet, the menu file can be saved along with the worksheet.  First save the worksheet as a DWK.

 

File -> Save As -> External Worksheet

 

Next, add the menu file to the saved  DWK worksheet.

 

Tools -> Add to Worksheet Document

 

Browse to and select the child.pan menu file. To force the worksheet to invoke and properly display the dialog box when loaded, define the $INITWKS macro. If defined, $INIWKS executes when the worksheet is loaded.

 

#define $initwks m=menufile("child.pan");setwsx(getmenucoords(m)+10, -1)

 

Re-save the worksheet to include the macro. Now when the worksheet is loaded, the child dialog box automatically displays properly independent of the current worksheet size. Pressing the OK button generates a noise waveform in the current window.