1.2.3 Adding Custom Button on Dialog

Adding Custom Button on Dialog

The following example shows how to add two custom buttons: the Reset button and the Apply button, to an X-Function dialog, as well as an event1 function to catch what button is being clicked.

  1. Press F10 to open X-Function Builder. Type "CustomButton" into the X-Function edit box as the X-Function name.
  2. Click the Ocguide xf treeview button.png button to switch to the Tree View panel, and type "Reset|Apply" in the GetN Dialog Custom Buttons edit box. Click Save to save this X-Function.
  3. Open the X-Function in Code Builder, and put the following code in the CustomButton_event1 function, then click the Ocguide XF Compile Button.PNG button.
    if( nEventID == GETNE_ON_CUSTOM_BUTTON1 )
    {
    	out_str("Reset click");
    }
    
    if( nEventID == GETNE_ON_APPLY )
    {
    	out_str("Apply click");
    }
    
    if( nEventID == GETNE_ON_OK )
    {
    	out_str("OK click");
    }
  4. Run CustomButton -d in the Command window to open the dialog of this X-Function. There should be four buttons: Reset, Apply, OK and Cancel.
  5. Click the Reset button, and "Reset click" gets printed in the Command window. If you click the Apply button, "Apply click" is printed and the Cancel button is changed to a Close button. Click OK, and "OK click" is printed and the dialog is closed.

Show Preview Button on Graph Preview GetN Dialog

X-Function framework supports a Show Preview button and an Auto Preview check box on the Graph Preview GetN dialog. These two controls are used to update the preview automatically (keep the Auto Preview check box checked) or manually (click the Preview button). The following steps demonstrate how to add the two controls.

The following five steps illustrate the process to add Preview button controls.

  1. Press F10 to open X-Function Builder. Type "PreviewButtons" into the X-Function edit box as the X-Function name.
  2. In the Variables table, set up a variable as below and then click the Save button to save this X-Function.
    Name: gp
    Label: Graph
    Input/Output: Input
    Data Type: string
    Control: ...Graph
    
  3. Run the command PreviewButtons -d to open this X-Function dialog. There are only two buttons: OK and Cancel. Click Cancel to close the dialog.
  4. In X-Function Builder, click the Ocguide xf treeview button.png button to switch to the Tree View panel, set Usage Context -> Menus -> Auto GetN Dialog as GetNGraphBox with Preview, and check the Show Preview Button check box. Save this X-Function.
  5. Run PreviewButtons -d to open the dialog again. Now there are two more controls displayed on the dialog: an Auto Preview check box and a Preview button.

The steps below show how to auto-update the dialog's preview graph according to the selection of the gp variable. For more details about the GetN Graph Preview Dialog, see Creating Graph Preview GetN Dialog.

  1. Open this X-Function in Code Builder, copy the following code, and paste it into the GetNGraphPreview_OnChange function.
    //include the bit to call GetNGraphPreview_OnUpdateGraph to update graph
    if( !(dwUpdateGraph & UPDATE_GRAPH_CHANGED) )
    	dwUpdateGraph |= UPDATE_GRAPH_CHANGED;
  2. Copy the codes below into the GetNGraphPreview_OnUpdateGraph function.
    string strGraph = trGetN.gp.strVal;
    GraphPage gpSource(strGraph);
    GraphPage gpDest(pgTemp);	
    page_clone(gpSource, gpDest);
  3. Click the Ocguide XF Compile Button.PNG button. Then run PreviewButtons -d in the Command window to open the dialog.
  4. In the dialog, type the graph page name into the Graph control, or click the OCguide xf 3dots button.png button to choose one graph page via the Graph Browser dialog. Click the Auto Preview check box or the Preview button, and the specified graph will display on the preview panel. See the picture below.
    OCguide xf graph preview dlg.png