.. highlightlang:: us .. index:: DialogBox .. _dialogbox: DialogBox ========= .. us.tag DialogBox ENGLISH DialogBoxes Changed360 Changed420 Changed422 Changed425 Changed540 Changed560 Changed5100 :ref:`DialogBox` creates a dialog box with static text, edit fields, list boxes, combo boxes, check boxes, a report list (list with multiple columns), a property list box, a group box, tree control and buttons.The dialog box can be configured to be resizeable (see Dialog control ``|F @ xxx_callback|``). .. function:: svReturn = DialogBox(svTemplate) svReturn = DialogBox(svTemplate, svInitString) svReturn = DialogBox(svTemplate, svInitString, ssTitle) svReturn = DialogBox(svTemplate, svInitString, ssTitle, ssHelpItem) svReturn = DialogBox(svTemplate, svInitString, ssTitle, ssHelpItem, obj) svReturn = DialogBox(svTemplate, svInitString, ssTitle, ssHelpItem, obj, ssWizard) .. us.return **Return Value** *svReturn* The return value is a string vector containing the user's input, if the user chooses the :guilabel:`OK` button. If the user selects the :guilabel:`Cancel` button, the return value is a scalar string with the value ``"DLG_CANCEL"``. In case of an error, the real number -1 is returned. .. us.params **Parameters** .. uparam:: svTemplate The *svTemplate* parameter is a string vector. Each element of *svTemplate* specifies one row in the dialog box. Each row can have different dialog objects. Each object starts with the character ``"|"`` followed by one or two characters specifying the type of the dialog element. The size of the element is specified by the number of blanks before the ending ``"|"`` sign. For multi-line dialog controls, e.g. a list box, the template must contain enough lines to ensure the list box is completely inside the dialog box. (see examples at the end of this help text.) List of available dialog elements: .. list-table:: :header-rows: 1 * - Value - Meaning * - ``| @ccc|`` - edit field. ``ccc`` is the name of a callback function. The callback function is optional. Is is called when the user updates the text (adds of removes a character). * - ``|x |`` - Password field. * - ``|nn |`` - multi-line edit field. The number nn specifies the number of lines in the edit box. The lines in the initialize text are separated by the string ``\r\n``. * - ``|Bxxx |`` - check box. xxx is the check box string. * - ``|Bxxx @ccc|`` - check box. xxx is the check box string. ccc is the name of an UniScript function. ``ccc`` is the name of a callback function. The function is called when the user checks or unchecks the button. * - ``|BR xxx @ccc|`` - Radio button. ``xxx`` is the button text (do not forget to insert a blank behind ``|BR``). ``ccc`` is the name of a callback function. The function is called when the user clicks a radio button. The callback function is used to clear all other radio buttons of a radio button group. See example 18. * - ``|Lnn |`` - list box. The number nn specifies the number of lines in the list box. * - ``|Lnn @ccc|`` - list box. The number nn specifies the number of lines in the list box. ``ccc`` is the name of a callback function. The function is called when the user changes the selection. * - ``|Mnn |`` - multi-select list box. The number nn specifies the number of lines in the list box. * - ``|Cnn |`` - combo box. The number nn specifies the number of lines in the list box. * - ``|Cnn @ccc|`` - combo box with callback function. ``ccc`` is the name of an UniScript function. The function is called when the user changes the selection. * - ``|CAnn @ccc|`` - Auto-completion combo box with optional callback function. ccc is a UniScript function name which is invoked when the selection has changed. This combo box makes it easy to select an item if the list contains a large number of items. To search for an item type the name. The list box will display all items that match the text typed. If there is no match you cannot leave the combo box. This is indicated by a message beep. * - ``|CSnn @ccc|`` - Symbol combo box to select color, line style, marker style with optional callback function. ccc is a UniScript function name which is invoked when the selection has changed. See example 20. * - ``|+nnn |`` - empty field. This field can be used to format the fields in the dialog box. The field enlarges the space to the following field. nnn is a number in the range 0 to 255. * - ``|-nnn |`` - empty field. This field can be used to format the fields in the dialog box. The field reduces the space to the following field. nnn is a number in the range 0 to 255. * - ``|Pxxx@ccc |`` - push button. xxx is the button text. ccc is the name of an UniScript function. The function is called when the user clicks the button. Example: ``|P Config...@_MY_ConfigDlg|`` * - ``|Oxxx |`` or ``|OSxxx |`` - Changes the text of the OK button. xxx is the new text. Example: ``|O&Continue|``, If O is followed by an S, the Cancel button is not displayed, for example ``|OS Close |``. * - ``|Oxxx@ccc |`` or ``|OSxxx@ccc |`` - OK button with callback function. xxx is the new button text. ccc is the name of an UniScript function. The function is called when the user clicks the button. Example: ``|OOK@_MY_CheckParameter|``. If the function returns TRUE (1) the dialog box will close. If the function returns FALSE (0) the dialog box will not close. The callback function can also return a string vector which will then be returned by DialogBox. Example: If the dialog box contains a list box and you would like to return all elements of the list box, you can create the return string in this callback function. * - ``|S |`` - static text field. This text field must be set in the svInitString. It can be changed in any dialog callback function. * - ``|Sf |`` - static text field with a border. This text field must be set in the svInitString. It can be changed in any dialog callback function. * - ``|Snn |`` - static text field. This text field must be set in the ``svInitString``. It can be changed in any dialog callback function. The number nn specifies the number of lines in the static text field. * - ``|Sfnn |`` - Static text field with a border with nn lines. * - ``|SPnn |`` - UniPlot Page: Static control with multiple lines to display a UniPlot graphic (IPW page). The number ``nn`` sets the number of lines (height of the control). The page handle is passed to the dialog box in the init string. See Example 19 * - ``|E@ccc |`` - Enable. One field in the dialog template can be an Enable field. This field can be used to enable/disable any dialog box field. ccc is the name of a UniPlot callback function. The function is called for the following events: just before the dialog is displayed; every time after a dialog callback function is called; every time a check box is clicked. The callback function will be called with the current init values (string vector). The function returns a real vector with the values 1 (enable) or 0 (disable) for each dialog element. Buttons (except for the OK, Cancel and Help buttons) have to be included. * - ``|Dnn |`` - A control that combines an edit control with a list box. This allows the user to type in an entry or choose one from the list. The number nn specifies the number of lines in the list box. * - ``|Dnn @ccc|`` - combo-edit box with callback function. ccc is the name of an UniScript function. The function is called when the user changes the selection. * - ``|Rnnn,xxx RowTitle1 \t RowTitle... \t @ccc|`` - Report list box (List with multiple columns) with optional callback function. ccc is the name of the optional callback function which will be called when the selected row has been changed. The number nn specifies the number of lines in the report list box. The optional number xxx specifies the control width in dialog box units (number of blanks). If the width is not specified it is calculated from the number of characters until the closing "|" or the first "@" character. The column titles are separated by a tab character (\t). * - ``|RBnnn,xxx RowTitle1 \t RowTitle... \t @ccc|`` - Report list box (list with multiple columns) with a check box for each line and an optional callback function. ccc is the name of the optional callback function which will be called when the selected row has been changed. The number nn specifies the number of lines in the Report list box. The column titles are separated by a tab character (\t). * - ``|RMBnnn,xxx RowTitle1 \t RowTitle... \t @ccc|`` - Report list box with multi- selection. * - ``|Gnnn |`` - Group box. This control displays a rectangle with a caption. The text is passed in the init vector. See example 10. * - ``|Nnnn |`` - Property list box. A two column list box. The left column shows the name of a property, the right column the value. (See example 11 and comment.) * - ``|F @ccc |`` - Dialog box size can be interactively modified. * - ``|Ann @ccc|`` - Tree control. Displays a hierarchical list of items. ``ccc`` has a special meaning for tree controls (see \*\*Tree control\*\* further down). .. uparam:: svInitString *svInitString* is a string vector which contains the initializing string for each dialog element. The initializing string for a check box is either the string ``"1"``, if the check box is checked, or ``"0"``, if the check box is unchecked. For list and combo boxes, the strings are separated by a ``|`` (OR) character or the character ``\x01`` (see example 2). The string that is selected when the dialog box appears on the monitor has to be added at the end of the initializing string, separated by ``@`` or ``\x02`` (see example 2). If ``\x01`` and ``\x02`` is used as the separator, the string must begin with the character ``\x01`` see :ref:`CreateListBoxText`. For the report list box, the string elements of a row are separated by ``\t`` character and the rows are separated by a new line character (``\n``). The strings for combo boxes and list boxes are limited to 1024 characters. No text has to be specified for button controls. .. uparam:: ssTitle *ssTitle* is a scalar string specifying the dialog title. .. uparam:: ssHelpItem *ssHelpItem* is a string of the form ``"helpitem@helpfile"``. Example: ``"DialogBox@d:/Program Files/UniPlot/up-en.chm"`` .. uparam:: obj The *obj* is optional. *obj* is a UniScript-Object created with :ref:`obj_create`. If the parameter is specified it will be passed to all dialog callback functions as the last parameter. .. uparam:: ssWizard The parameter *ssWizard* is optional. The parameter can be used to add a second OK button to a dialog box. The parameter sets the button text and the name of a callback function. The callback function will be invoked when the user presses the button. The button text and callback function name is separated by an @-character for example `` = GetListBoxText(ssText, bSplit) The functions use the separators ``\x01`` and ``\x02``. A complete example can be found at the end of this help topic (Example 16). The return value for an edit report control is the complete content of the control including the selection. Resizable dialog boxes ...................... To enable resizing you must add the string ``"|F @ccc|"`` to the template parameter. ``ccc`` stands for the name of a callback function. The following example shows the callback function for the :ref:`datadataset-list` dialog box: :: def _DatasetListDialog_Resize(rvInit) { nElements = rvInit[6]; nAction = rvInit[5]; if (nAction == 1) { ssI = GetProfileString("DialogSize", "DatasetListDialog"); svI = strtok(ssI, "|"); return strtod(svI); } else if (nAction == 2) { return [2,3; // checkbox 6,6; // Report 5,3; // blank field 5,3; // Button 5,3; // Button 5,3; // Button 5,3]; // Button } else if (nAction == 3) { ssI = smprintf("%d", rvInit[1,2,3,4], "|", "|"); WriteProfileString("DialogSize", "DatasetListDialog", ssI); return 0; } } The function parameter *rvInit* is a real vector with 6 elements: .. list-table:: :header-rows: 1 * - Value - Meaning * - rvInit[1] - Position left. * - rvInit[2] - Position top. * - rvInit[3] - Dialog box width in pixel. * - rvInit[4] - Dialog box height in pixel. * - rvInit[5] - nAction: see Note. * - rvInit[6] - Number of control elements in the dialog box. This information can be used for debugging purposes. **Note** rvInit[5] = 1: The function is called to receive the initial dialog box size The function should return a vector with 4 elements [left, top, right, bottom]. rvInit[5] = 2: The callback function is called by the framework to receive information about horizontal and vertical positions. rvInit[5] = 3: Is called when the user is closing the dialog to save the dialog box size. The function is invoked by UniPlot before the dialog is displayed on the monitor (nAction = 1 and nAction = 2). **Position and Size of dialog elements** By default, a dialog element is proportionally resized to the dialog box size, but you can optionally fix the horizontal and/or vertical dimension/position of a child window. E.g. it's reasonable to fix the height of single line edit controls. In this case return the scalar value 0 if ``nAction`` is 2. To change the default behavior you must return a real matrix. For each element in the dialog box (including text and blank fields which are not enclosed in OR signs) the matrix must contain one row except for the default buttons (OK, Cancel and Help) and the ``|+xxx|`` and ``|-xxx|`` elements. Horizontal Fixing: .. list-table:: :header-rows: 1 * - Name - Value - Meaning * - kNoHFix - 0 - Default Value: Horizontal size proportional to the dialog box size. * - kWidth - 1 - Width fixed. Element is moved proportionally. * - kLeft - 2 - Left fixed. Width proportional to the dialog box size. * - kRight - 4 - Right fixed. Width proportional to the dialog box size. * - kWidthLeft - 3 - Left fixed, width fixed. * - kWidthRight - 5 - Right fixed, width fixed. * - kLeftRight - 6 - Left and right keeps the distance to the edges. Vertical Fixing: .. list-table:: :header-rows: 1 * - Name - Value - Meaning * - kNoVFix - 0 - Default Value: Vertical size proportional to the dialog box size. * - kHeight - 1 - Constant height. Element is moved proportionally. * - kTop - 2 - Top fixed. Height proportional to the dialog box size. * - kBottom - 4 - Bottom fixed. Height proportional to the dialog box size. * - kHeightTop - 3 - Top fixed, height fixed. * - kHeightBottom - 5 - Bottom fixed, height fixed. * - kTopBottom - 6 - Top and bottom keeps the distance to the edges. :: def _MyDialog_Resize(svInfo) { nAction = svInfo[5]; if (nAction == 1) { // Init ssI = GetProfileString("DialogSize", "MyDialog"); svI = strtok(ssI, "|"); return strtod(svI); // return the init size } else if (nAction == 2) { // resize // svInfo[6] tells you how many elements you have return [6,6; // Report control see documentation for DialogBox 5,3; // blank field 5,3; // button1 5,3; // space |+100| 5,3]; // button2 } else if (nAction == 3) { // Exit User pressd OK or cancel ssI = smprintf("%d", svInfo[1,2,3,4], "|", "|"); WriteProfileString("DialogSize", "MyDialog", ssI); return 0; } } def _MyDialog_Dialog() { svTemplate = ["|R10,100 Code Word | |P Button1 @_MyDialog_Button1|", ... "|+100| |P Button2 @_MyDialog_Button2|", ... strempty(1,8), ... "|F @_MyDialog_Resize|"]; svRet = DialogBox(svTemplate, "", "Test"); if (svRet[1] == "DLG_CANCEL") { return svRet[1]; } return svRet; } See also **Example 15**. .. us.example **Example** **Example 1**: .. image:: S:/uniplot-obj/images/DialogBox1-en.* :: DialogBox("Name: | |");. **Example 2**: In the next edit box, comma separated numbers can be specified. The string can be split into tokens using the :ref:`strtok` function. The vector of stings can be converted to numbers using :ref:`strtod`. :: sRet = DialogBox("Please type \"1,2,3,4\":| |") if (sRet != "DLG_CANCEL") { svRet = strtok(sRet, ",") rvData = strtod(svRet) MessageBox(sprintf("%10.5f\n", rvData')) } **Example 3**: .. image:: S:/uniplot-obj/images/DialogBox2-en.* :: svTemplate = ["Power | | kW "; "Engine |C10 |"]; svEngines = ["1.3", "1.6 l", "2.0 l"]; ssEngine = CreateListBoxText(svEngines, svEngines[2]) // Select the second item svInitString = ["127", ssEngine]; ssTitle = "Engine-Selection"; DialogBox(svTemplate, svInitString, ssTitle); **Example 4**: .. image:: S:/uniplot-obj/images/DialogBox3-en.* :: DialogBox(["|L4 |", strempty(1,3)], ... "Line 1|Line 2|Line 3@Line 2", "Dialog 3") **Example 5**: With a file name edit, the user can type a file name directly or pick a file name from a dialog. When the user presses the browse button, a modal file dialog appears. After the user picks a file name from the dialog, the full file name is automatically entered into the edit field. .. image:: S:/uniplot-obj/images/DialogBox4-en.* :: def GetMyFile() { DialogBox("File:| ||P Browse... @PickFile|") } def PickFile(svInit) { ssFilter = "My File (*.myf)|*.myf|All Files (*.*)|*.*|"; ssFileName = GetOpenFileName(svInit[1], ssFilter); if (ssFileName == "") { // User clicked CANCEL return svInit; } svInit[1] = ssFileName; return svInit; } **Example 6**: The following example displays a list box showing the names of all loaded UniScript functions: .. image:: S:/uniplot-obj/images/DialogBox5-en.* :: DialogBox(["|L10 |", strempty(1,9)], CreateListBoxText(symbols(255))) **Example 7**: In the following example, a dialog box with a list of names will be created. New names can by added. The dialog saves the names in the window's registry. :: def __TestAddItemToList(svInit) { svItem = strtok(svInit[1], "@"); if (len(svItem) == 1) { return svInit; } svSel = strtok(svItem[2], "|"); if (len(svSel) == 1) { return svInit; } return svItem[1] + "|" + svSel[2] + "@" + svSel[1]; } def __TEST_Ok(svInit) { // Add last name to list: __TestAddItemToList(svInit); WriteProfileString("MyFiends", "Name", svInit[1]); return TRUE; } def TestDialog() { svInit = _GetProfileStringEx("MyFiends", "Name", "Andy|Georg|Thomas|"); // returns selected Name: return DialogBox("Friends:|D @__TestAddItemToList||O &OK@__TEST_Ok|", svInit); } **Example 8**: The following example is a report with three columns. .. image:: S:/uniplot-obj/images/DialogBox5-Report-en.* :: smMat = ["1.6l 16V", "4", "Otto"; "2.0l 16V", "4", "Otto"; "1.9l","4", "Diesel"]; ssInit = ReportControl_GetInit(smMat, TRUE, 1); DialogBox(["|R4,40 Engine\tCylinder\tType|", strempty(1,3)], .. ssInit, .. "Report-Dialog") **Example 9**: Report with three columns and a check box for each line. .. image:: S:/uniplot-obj/images/DialogBox6-ReportWithCheckbox-en.* :: def TestCallback_OK9(svInit) { return svInit; } def TestDialog_9() { smData = ["1", "1.6l 16V", "4", "Otto"; "0", "2.0l 16V", "4", "Otto"; "0", "1.9l", "4", "Diesel"]; // 5 rows, width=70 svTemplate = ["|RB5,70 " + "Engine\tCylinder\tType|", .. strempty(1, 4), .. "|OOk@TestCallback_OK9|"]; ssTitle = "Report-Dialog"; svInit = ReportControl_GetInit(smData, TRUE, 3); svRet = DialogBox(svTemplate, svInit, ssTitle); if (svRet[1] == "DLG_CANCEL") { return -1; } smMat = ReportControl_GetMatrix(svRet[1]); // Checkboxes, first column: r = strtod(smMat[;1]); return r; } TestDialog_9() **Example 10**: The following example is a dialog box with two group boxes. .. image:: S:/uniplot-obj/images/DialogBox7-Groupbox-en.* :: svTemplate = ["|G3 | |G3 |", .. " x =| ||+6|dx =| |", ... " y =| ||+6|dy =| |",.. "", .. "|B Apply size to all selected elements|"] DialogBox(svTemplate, ["Position","Size", "0","10", "0", "10"], "Move Elements") **Example 11**: The following example is a dialog box with a property list box. The value in the right column can be edited by a combo box (Combo), button (Button) or edit field (Edit). .. image:: S:/uniplot-obj/images/DialogBox8-PropList-en.* :: def PropList_GetMatrix(ssRet) { sv = strtok(ssRet, "\n"); n = len(sv); sm = strempty(n, 3); for (i in 1:len(sv)) { svT = strtok(sv[i], "\t") nn = len(svT); if (nn == 1) { sm[i;1] = svT; } else if (nn == 2) { sm[i;1:2] = svT; } else if (nn == 3) { sm[i;] = svT; } } return sm; } def __PL1_GetFileName(svProp) { ssFileName = GetOpenFileName(svProp[3]); if (ssFileName == "") { return 0; } return [sum(SplitPath(ssFileName)[3,4]), ssFileName]; } def __PL1_ChannelNames(svProp) { return ["Speed|T|Torque|T_Act|be@" + svProp[2], ""]; } def _EngineDialog() { ssInit = "Template Name\tKF.IPW\tButton\t__PL1_GetFileName\tc:/test/kf.ipw\n" + .. "x-Channel\tspeed\tCombo\t__PL1_ChannelNames\n" + .. "y-Channel\tT\tCombo\t__PL1_ChannelNames\n" + .. "z-Kanal\tTorque\tAutoCombo\t__PL1_ChannelNames\n" + .. "Title\tOtto2\tEdit\n" + .. "Operator\tP. Miller" svRet = DialogBox(["|N8 |", strempty(1,7), .. "|B Use Default Values"], .. [ssInit, "0"], "Page Configuration") if (svRet[1] == "DLG_CANCEL") { return svRet[1]; } smMat = PropList_GetMatrix(svRet[1]); // Do something with smMat[;2] } **Example 12**: Multiline edit box. .. image:: S:/uniplot-obj/images/DialogBox9-Multiline-en.* :: DialogBox(["|5 |", strempty(1,4)], .. "This is the first line\nThis is the second line", "Multiline-Edit") ]] **Example 13**: The following example checks if a number in the range 1 to 10 has been typed: .. image:: S:/uniplot-obj/images/DialogBox13-en.* :: def TestCallback(svInit) { = strtod(strtrim(svInit, 3)); if (n < 1 || n > 10 || ssStop != "") { MessageBox("Please type in a number in the range 1 to 10.", ["Error", "ICONSTOP"]); return FALSE; } return TRUE; } def TestDialog() { ssRet = DialogBox("Number between 1 and 10: | ||OOK@TestCallback|", "0", "Edit"); if (ssRet != "DLG_CANCEL") { MessageBox("Ok: You typed in " + ssRet + "!"); } } **Example 14**: The following example displays a list box that showing the names of all loaded UniScript functions. The source file with the definition is displayed for the selected function name. .. image:: S:/uniplot-obj/images/DialogBox14-en.* :: def __ShowSourceName(svInit) { = GetListBoxText(svInit[2]); svInit[1] = source(b); return svInit; } def _ListFunctions() { DialogBox(["|Sf ", .. "|L10 @__ShowSourceName|", strempty(1,9)], .. ["", CreateListBoxText(symbols(255))]); } **Example 15**: The following example displays a tree control showing the directory and files in the UniPlot root directory. The dialog box is resizeable. .. image:: S:/uniplot-obj/images/DialogBox10-Tree-en.* :: def _MyDialogTree_GetImageList(obj) { return GetRootDirectory() + "bitmap/" + ["folder.bmp", "file.bmp"]; } def _MyDialogTree_SelChanged(svInit, svText, nItemID, obj) { svInit[2] = obj.Path +strcat(svText, "/"); return svInit; } def _MyDialogTree_DblClicked(svInit, svText, nItemID, obj) { MessageBox("Path: " + obj.Path +strcat(svText, "/")); } def _MyDialogTree_RClicked(svInit, svText, nItemID, obj) { MessageBox("Path: " + obj.Path +strcat(svText, "/")); } def _MyDialogTree_Expand(svText, rvItemID, obj) { smFiles = FindFiles(obj.Path + strcat(svText, "/") + "/*"); // remove . and .. if (nr(smFiles) < 3) { return ""; } smFiles = strtrim(smFiles[3:nr(smFiles);], 3); nFiles = nr(smFiles); smName = strempty(nFiles, 4); for (i in 1:nFiles) { smName[i;1] = smFiles[i;1]; smName[i;2] = "0"; // sprintf("%d", o.lastid); if (smFiles[i;3] == "16") { smName[i;3] = "1"; smName[i;4] = "1"; } else { smName[i;3] = "0"; smName[i;4] = "2"; } } return smName; } def _MyDialogTree_Resize(svInfo, obj) { nAction = svInfo[5]; if (nAction == 1) { // Init ssI = GetProfileString("DialogSize", "MyDialogTree"); svI = strtok(ssI, "|"); return strtod(svI); // return the init size } else if (nAction == 2) { // resize return [6,6; 6,5]; } else if (nAction == 3) { // Exit User pressd OK or cancel ssI = smprintf("%d", svInfo[1,2,3,4], "|", "|"); WriteProfileString("DialogSize", "MyDialogTree", ssI); return 0; } } def _MyDialogTree_Dialog() { ssTreeSelection = GetProfileString("_MyDialogTree", "TreeSelection"); ssTreeSelection = ssTreeSelection + "\x03select"; svTemplate = ["|A10 @_MyDialogTree_|", ... strempty(1,9), ... "|Sf ||F @_MyDialogTree_Resize|"]; svInit = [ssTreeSelection, ""]; ssHelp = ""; obj = obj_create(); obj.Path = GetRootDirectory(); svRet = DialogBox(svTemplate, svInit, "Browse " + obj.Path, ssHelp, obj); if (svRet[1] == "DLG_CANCEL") { return svRet[1]; } svEle = strtok(svRet[1], "\x02"); svPfad = strtok(svEle[1], "\x01"); WriteProfileString("_MyDialogTree", "TreeSelection", strcat(svPfad, "\x01")); return GetRootDirectory() + strcat(svPfad, "\"); } **Example 16**: The following example shows a report control, in which cells can be edited in. Column width an order can be interactivly altered and will be saved. The dialog box can be resized. Call see function _test_report(). .. image:: S:/uniplot-obj/images/DialogBox11-EditReport-en.* :: def __test_report_Combo(svInit, iControl, iRow, iCol) { =GetListBoxText(svInit[iControl], FALSE); smMat = ReportControl_GetMatrix(ssMat); return CreateListBoxText(["Otto","Diesel","DI-Otto"], smMat[iRow; iCol]); } def __test_report_Button(svInit, iControl, iRow, iCol) { =GetListBoxText(svInit[iControl], FALSE); smMat = ReportControl_GetMatrix(ssMat); ssFile = GetOpenFileName(); if (ssFile != "") { smMat[iRow; iCol] = ssFile; svInit[iControl] = ReportControl_GetInit(smMat, TRUE); } return svInit; } def __test_report_Color(svInit, iControl, iRow, iCol) { svColor = ReportControl_GetColorNames(); =GetListBoxText(svInit[iControl], FALSE); smMat = ReportControl_GetMatrix(ssMat); return CreateListBoxText(svColor, smMat[iRow;iCol]); } def __test_report_GetOption(ssOption) { if (ssOption == "Selection") { return "255"; } else if (ssOption == "EnableColumnDrag") { return "1"; } else if (ssOption == "ColumnType") { return ["ShowButton", ""; "Edit", ""; "Combo", "__test_report_Combo"; "Button", "__test_report_Button"; "Checkbox", ""; "Marker", "__test_report_Color"]; } else if (ssOption == "ColumnWidth") { return _GetProfileStringEx("DialogSize", "_test_props_colwidth", "50,70,50,150,60,140"); } else if (ssOption == "ColumnOrder") { return _GetProfileStringEx("DialogSize", "_test_props_colorder", "1,2,3,4,5,6"); } } def __test_report_SaveOption(ssOption, svVal) { if (ssOption == "ColumnWidth") { WriteProfileString("DialogSize", "_test_props_colwidth", strcat(svVal, ",")); } else if (ssOption == "ColumnOrder") { WriteProfileString("DialogSize", "_test_props_colorder", strcat(svVal, ",")); } } def __test_report_Resize(rvInit) { nElements = rvInit[6]; nAction = rvInit[5]; if (nAction == 1) { ssI = GetProfileString("DialogSize", "_test_report"); svI = strtok(ssI, "|"); return strtod(svI); } else if (nAction == 2) { return [6,6]; } else if (nAction == 3) { ssI = smprintf("%d", rvInit[1,2,3,4], "|", "|"); WriteProfileString("DialogSize", "_test_report", ssI); return 0; } } def _test_report() { svColor = ReportControl_GetColorNames(); svTemplate = ["|R4,60 Engine\tComment\tType\tData File\tShow\tColor @@@__test_report_|", .. strempty(1,2), ... "|F @ __test_report_Resize |"]; smData =["1.6l 16V", "With AGR", "Otto", "","1", svColor[10]; "2.0l 16V", "Without AGR", "Otto", "","0", svColor[11]; "1.9l", "", "Diesel", "","2", svColor[12]; "1.6l 16V", "", "Otto", "","1", svColor[13]; "1.6l 16V", "", "Otto", "","1", svColor[14]]; ssInit = ReportControl_GetInit(smData, TRUE); svRet = DialogBox(svTemplate, ssInit, "Edit-Report-Dialog") if (svRet[1] == "DLG_CANCEL") { return svRet; } smMat = ReportControl_GetMatrix(svRet[1]); rmColor = ReportControl_GetColorRGB(smMat[;6]); return svRet } **Example 17**: The following example shows a Wizard with three dialog boxes. Short function description: In the _TestWizard() function an object is created. The object is used to define the three dialogboxes. For each dialog box a separate object with the indices 1,2 and 3 is created. In these objects the parameters Template, svInit, Title, Back and Help are specified. The object is passed to the WizardDialog() function. The WizardDialog functions invokes the DialogBox function for the obj.dialog_id == 1. For the Next, Back and Finish button a separate callback function is specified. These callback functions save the current settings and set the element obj.dialog_id. obj.dialog_id specifies which dialog box will be displayed next. The template string vector has been filled with empty rows (strempty()) to make all dialogs the same height so that the Next and Back button will be displayed at the same position on the monitor. The user input is saved in the elemenst obj[i].svInit. To test the dialog box, copy the program into an ic file, press F4. and call the _TestWizard() function in the command window. .. image:: S:/uniplot-obj/images/DialogBox17-Wizard-en.* :: def _TestWizard_Next(svInit, obj) { obj[obj.dialog_id].svInit = svInit; obj.dialog_id = obj.dialog_id + 1; return 1; } def _TestWizard_Back(svInit, obj) { obj[obj.dialog_id].svInit = svInit; obj.dialog_id = obj.dialog_id - 1; return 1; } def _TestWizard() { obj = obj_create(); obj[1] = [.]; obj[2] = [.]; obj[3] = [.]; obj.dialog_id = 1; obj[1].Template = [strempty(1,4), .. "File1:| |", .. "File2:| |", .. strempty(1,4),"|OS Next>@_TestWizard_Next"]; // If you remove the S in [[|OS Next>@_TestWizard_Next|]] a \b(Cancel) // button will be displayed. obj[1].svInit = ["c:/test1", "c:/test2"]; obj[1].Title = "Step1: Select Files"; obj[1].Back = ""; // No Back-Button // obj[1].Help = ""; // No Help-Button obj[1].Help = "DialogBox" + "@" + GetHelpFileName(); obj[2].Template = ["Kanäle:|L10 |", .. strempty(1,9),"|OS Next>@_TestWizard_Next"]; obj[2].svInit = CreateListBoxText(["speed","torque","nox"], "nox"); obj[2].Title = "Step2: Select Channels"; obj[2].Back = " = ReportControl_GetMatrix(svInit[1]) if (len(smMatrix) == 1) { return 0; } smMatrix[;1] = "1"; svInit[1] = ReportControl_GetInit(smMatrix, TRUE, rvSelRow); return svInit; } // Callback "Deselect All" def _NC_Channel_Selection_DeselectAll(svInit) { = ReportControl_GetMatrix(svInit[1]) if (len(smMatrix) == 1) { return 0; } smMatrix[;1] = "0"; svInit[1] = ReportControl_GetInit(smMatrix, TRUE, rvSelRow); return svInit; } // Callback "Toggle" def _NC_Channel_Selection_Toggle(svInit) { = ReportControl_GetMatrix(svInit[1]) if (rvSelRow[1] == 0) { MessageBoxError(_s("Select at least one element in the list")); return 0; } ssSel = smMatrix[rvSelRow[1]; 1]; if (ssSel == "1") { ssSel = "0"; } else { ssSel = "1"; } smMatrix[rvSelRow;1] = ssSel; svInit[1] = ReportControl_GetInit(smMatrix, TRUE, rvSelRow); return svInit; } // Callback "OK" button def _NC_Channel_Selection_Dialog_OK(svInit) { smVars = ReportControl_GetMatrix(svInit[1]); idx = find(smVars[;1] == "1"); if (idx[1] == 0) { MessageBoxError(_s("Select at least one element in the list")); return FALSE; } svVars = smVars[idx;2]; return svVars; } // Callback "Dialog Resize" def _NC_Channel_Selection_Resize(rvInit) { nElements = rvInit[6]; nAction = rvInit[5]; if (nAction == 1) { ssI = GetProfileString("DialogSize", "NC_Channel_Selection_Dialog"); svI = strtok(ssI, "|"); return strtod(svI); } else if (nAction == 2) { return [6,6; 5,3; 5,3; 5,3; 5,3]; } else if (nAction == 3) { ssI = smprintf("%d", rvInit[1,2,3,4], "|", "|"); WriteProfileString("DialogSize", "NC_Channel_Selection_Dialog", ssI); return 0; } } // returns "" if Cancel is selected def NC_Channel_Selection_Dialog(ssNCFile) { svVarNames = NC_GetVarNames(ssNCFile); if (svVarNames[1] == "") { MessageBoxError("Ungültige Datendatei: %s", ssNCFile); return ""; } ssTitle = "Channel Selection"; svTemplate = ["|RMB10,65 Name@@ReportControl_Sort| " + ... " |P Select All @ _NC_Channel_Selection_SelectAll |", .. "|+68||P Deselect All @ _NC_Channel_Selection_DeselectAll |", .. "|+68||P Toggle Selection @ _NC_Channel_Selection_Toggle|", .. "|O OK @_NC_Channel_Selection_Dialog_OK||F @_NC_Channel_Selection_Resize|", .. strempty(1, 6)] smVars = strempty(len(svVarNames), 2); smVars[;1] = "0"; // deselect all smVars[;2] = svVarNames' svInit = ReportControl_GetInit(smVars, TRUE); svRet = DialogBox(svTemplate, svInit, ssTitle); if (svRet[1] == "DLG_CANCEL") { return ""; } return svRet; } // Test NC_Channel_Selection_Dialog(GetOpenFileName()) **Example 22**: Property Listbox with color selection, etc.: .. image:: S:/uniplot-obj/images/DialogBox22-en.* :: def _MyProp_Button(svInit, iControl, iRow, iCol) { =GetListBoxText(svInit[iControl], FALSE); smMat = ReportControl_GetMatrix(ssMat); ssFile = GetOpenFileName(); if (ssFile != "") { smMat[iRow; iCol] = ssFile; svInit[iControl] = ReportControl_GetInit(smMat, TRUE); } return svInit; } def _MyProp_Color(svInit, iControl, iRow, iCol) { if (nargsin() == 1) { return ReportControl_GetColorNames(Color_RGB_to_COLORREF(_sty_color_to_number(svInit)), " "); } else if (nargsin() == 2) { rvColor = ReportControl_GetColorRGB(svInit); return _sty_color_print(0, "", _sty_rgb(rvColor), "", FALSE); } else { svColor = [" ", ReportControl_GetColorNames()]; = ReportControl_GetMatrix(svInit[iControl]); return CreateListBoxText(svColor, smMat[iRow;iCol]); } def _MyProp_LineWidth(svInit, iControl, iRow, iCol) { if (nargsin() == 1) { if (svInit == "") { return " "; } nVal = strtod(svInit) if (nVal <= 0) { return "1"; } if (nVal > 50) { return "50"; } return svInit; } else if (nargsin() == 2) { if (svInit == " ") { return ""; } return svInit; } =GetListBoxText(svInit[iControl], FALSE); smMat = ReportControl_GetMatrix(ssMat); return " |" + _CreateComboBoxNumbers(1, 50) + "@" + smMat[iRow; iCol]; } def _MyProp_LineStyle(svInit, iControl, iRow, iCol) { if (nargsin() == 1) { return ReportControl_GetLineStyleNames(_sty_curve_style_to_number(svInit), " "); } else if (nargsin() == 2) { rsLineStyle = ReportControl_GetLineStyle(svInit); return _sty_curve_style_print(0, "", rsLineStyle, "", FALSE); } else { svNames = [" ", ReportControl_GetLineStyleNames()]; = ReportControl_GetMatrix(svInit[iControl]); return CreateListBoxText(svNames, smMat[iRow;iCol]); } } def _MyProp_Marker(svInit, iControl, iRow, iCol) { if (nargsin() == 1) { return ReportControl_GetMarkerStyleNames(_sty_marker_style_to_number(svInit), " "); } else if (nargsin() == 2) { rsVal = ReportControl_GetMarkerStyle(svInit); return _sty_marker_style_print(0, "", rsVal, "", FALSE); } else { svNames = [" ", ReportControl_GetMarkerStyleNames()]; = ReportControl_GetMatrix(svInit[iControl]); return CreateListBoxText(svNames, smMat[iRow;iCol]); } } // callback function to set the cell type // The function name is the name behind the third @ character in dialog template // folloed by the text GetOption def _MyProp_GetOption(ssOption) { if (ssOption == "CellType") { return ["GreyText", "Edit"; "GreyText", "Button@_MyProp_Button"; "GreyText", "Checkbox@_MyProp_OnOff"; "GreyText", "Marker@_MyProp_Color"; "GreyText", "Marker@_MyProp_LineStyle"; "GreyText", "Combo@_MyProp_LineWidth"; "GreyText", "Marker@_MyProp_Marker"]; } } def _Test_Prop_Dialog_Template() { ssTitle = "Property Dialog"; svTemplate = ["|R8,90 Name\tValue @@@_MyProp_|", strempty(1,7)]; // Create an object and return it return [. ssTitle = ssTitle, svTemplate = svTemplate]; } def _MyProp_Dialog() { dlg = _Test_Prop_Dialog_Template(); ssColor = _MyProp_Color("RGB(0,255,0)"); //green sprintf("RGB(%d,%d,%d)", r,b,g); ssLineStyle = _MyProp_LineStyle("1"); ssMarker = _MyProp_Marker("5"); smInit = ["Text", "This is Text"; "File Name", "c:\\b.txt"; "On/Off", "1"; "Color", ssColor; "Line Type", ssLineStyle; "Line Width", "5"; "Marker", ssMarker]; svInit = ReportControl_GetInit(smInit, TRUE); // TRUE is important! svRet = DialogBox(dlg.svTemplate, svInit, dlg.ssTitle); if (svRet[1] == "DLG_CANCEL") { return 0; } smMat = ReportControl_GetMatrix(svRet[1]); obj = [.]; obj.ssText = smMat[1;2]; obj.ssFile = smMat[2;2]; obj.bOnOff = strtod(smMat[3;2]); obj.rvColor = ReportControl_GetColorRGB(smMat[4;2]); obj.nLineWidth = strtod(smMat[6;2]); obj.ssMarker = strtod(_MyProp_Marker(smMat[7;2], 1)); return obj; } **Example 23**: The following example displays a matrix of random numbers. The color depends of the value. .. image:: S:/uniplot-obj/images/DialogBox23-OnCellFillColor-en.* :: def __testdialog_23_OnCellFillColor(iControl, iRow, iCol, ssCellText) { if (iCol == 1) { return Color_RGB_to_COLORREF([250,250,250]); // bright grey } rsVal = strtod(ssCellText); if (rsVal >= -0.2 && rsVal <= 0.2) { return Color_RGB_to_COLORREF(sty_prop_color_to_RGB("lightgreen")); // bright green } else if (rsVal <= -0.2) { return Color_RGB_to_COLORREF(color_html_to_rgb("#fa8072")); // bright red } else { return Color_RGB_to_COLORREF(sty_prop_color_to_RGB("powderblue")); } } def TestCallback_23_OK9(svInit) { return svInit; } def TestDialog_23() { smData = smprintf("%g", rand(10,10)*2-1); svCols = strcat(smprintf("%d", 1:nc(smData)), "\t"); svRows = smprintf("%d", 1:nr(smData))'; svTemplate = ["|R12,100 \t" + svCols + "@@@__testdialog_23_|", .. strempty(1, 11), .. "|OOk@TestCallback_23_OK9|"]; ssTitle = "Report-Dialog"; svInit = ReportControl_GetInit([svRows, smData], TRUE, 3); svRet = DialogBox(svTemplate, svInit, ssTitle); if (svRet[1] == "DLG_CANCEL") { return -1; } smMat = ReportControl_GetMatrix(svRet[1]); return smMat; } TestDialog_23() .. us.history **History** .. list-table:: :header-rows: 1 * - Version - Description * - R2016.1 - Add Callback function for edit fields. * - R2015.4 - New Callback function OnCellFillColor for a ReportControl. * - R2013.12 - New Callback function OnCellActivate for a ReportControl. * - 5.10.0 - Symbol combo box added. * - 5.6.0 - ``"\x03reset"`` added to edit report controls. * - 5.4.0 - Graphic Control added. (See Example 19) * - 4.2.5 - Radio buttons added. * - 4.2.4 - Wizard-Parameter added. * - 4.2.2 - Report control now editable. * - 4.2.0 - Tree control and dialog box resizing added. .. seealso:: :ref:`overview-dialogboxes`, :ref:`MessageBox`, :ref:`GetSaveFileName`, :ref:`GetOpenFileName`, :ref:`GetDirectoryDialog` :sub:`id-2012604`