Dialog with tabs and pull down menu
From Vectorlab
| This vcor page is currently under construction.
By: orso. Last edit: 2007.2.24 (YYYY.MM.DD) In the category:Under construction you'll find a list of all pages currently marked as under construction. |
Tab example 2 - Dialog with 3 tabs and a popup menu outside the tabs. Whenever you click a button, the popup will load your action as history. After a certain number of actions, the script will insult you. This example is also valid for VW before 12, when retriving the user's tab position was not handled by VS routines. By Orso
{ 2007 Orso B. Schmid@vcor.net A dialog with 3 tabs and a pull down menu } PROCEDURE DialogWithTabsAndPullDownMenus; CONST { manage dialog items IDs. sorting the items according to the location helps managing them. The numbering must be unique (an ID) for every item. } cTabControl = 9; { the control for all tabs } cTab1 = 10; { tab 1 } cButTab1_1 = 11; cButTab1_2 = 12; cButTab1_3 = 13; cTab2 = 20; { tab 2 } cButTab2_1 = 21; cButTab2_2 = 22; cButTab2_3 = 23; cTab3 = 30; { tab 3 } cButTab3_1 = 31; cButTab3_2 = 32; cButTab3_3 = 33; cSt = 40; { static text: explanation for the pull down menu } cPull = 41; { the pull down menu } VAR { here global variables valid for the whole script, they are prefixed with "g" } g_dID, g_dResult : LONGINT; g_tabLoc, g_howInsane : INTEGER; { some sort of constructor, workaround for lack of obj oriented programming in VS } { 2007 Orso B. Schmid@vcor.net } FUNCTION inc(VAR n : INTEGER): INTEGER; BEGIN n := n + 1; inc := n; END; { set up the dialog display } FUNCTION Define_Dialog: LONGINT; VAR dID : LONGINT; BEGIN dID := CreateLayout('Tab Control Dialog', FALSE, 'OK', 'Cancel'); { Tab Group 1 } CreateGroupBox(dID, cTab1, 'Tab 1', FALSE); CreatePushButton(dID, cButTab1_1, 'Button 1'); SetFirstGroupItem(dID, cTab1, cButTab1_1); CreatePushButton(dID, cButTab1_2, 'Button 2'); SetBelowItem(dID, cButTab1_1, cButTab1_2, 0, 0); CreatePushButton(dID, cButTab1_3, 'Button 3'); SetBelowItem(dID, cButTab1_2, cButTab1_3, 0, 0); { Tab Group 2 } CreateGroupBox(dID, cTab2, 'Tab 2', FALSE); CreatePushButton(dID, cButTab2_1, 'Button 1'); SetFirstGroupItem(dID, cTab2, cButTab2_1); CreatePushButton(dID, cButTab2_2, 'Button 2'); SetRightItem(dID, cButTab2_1, cButTab2_2, 0, 0); CreatePushButton(dID, cButTab2_3, 'Button 3'); SetRightItem(dID, cButTab2_2, cButTab2_3, 0, 0); { Tab Group 3 } CreateGroupBox(dID, cTab3, 'Tab 3', FALSE); CreatePushButton(dID, cButTab3_1, 'Button 1'); SetFirstGroupItem(dID, cTab3, cButTab3_1); CreatePushButton(dID, cButTab3_2, 'Button 2'); SetRightItem(dID, cButTab3_1, cButTab3_2, 0, 0); CreatePushButton(dID, cButTab3_3, 'Button 3'); SetBelowItem(dID, cButTab3_1, cButTab3_3, 0, 0); { Create tab control } CreateTabControl(dID, cTabControl); SetFirstLayoutItem(dID, cTabControl); CreateStaticText(dID, cSt, 'below the history of your actions, click on the pull down menu to view it:', 35); SetBelowItem(dID, cTabControl, cSt, 0, 0); CreatePullDownMenu(dId, cPull, 36); SetBelowItem(dID, cSt, cPull, 0, 0); { Add the tab panes to tab control } CreateTabPane(dID, cTabControl, cTab1); CreateTabPane(dID, cTabControl, cTab2); CreateTabPane(dID, cTabControl, cTab3); { return the dialog ID } Define_Dialog := dID; END; { this is the engine for the dialog } PROCEDURE Drive_Dialog(VAR item: LONGINT; data: LONGINT); { item is a number representing an event: if a user, for example, clicks on button 1 of tab 1, this will set the item to cButTab1_1, which we defined at the beginning with the constant 11 if the user clicks the button 2 of tab 3, this will set the item to cButTab2_3, which we defined at the beginning with the constant 23. if the user clicks on OK, this will set the item to 1. if the user clicks on ESC, this will set the item to 2. if the item number is set during the dialog to -1 the dialog will break, see below how this works. When the dialog exits (it cannot exit with -1) the item will pass to g_dResult := RunLayoutDialog(g_dID, Drive_Dialog); g_dResult is the last value: it can be only 1 or 2. } { This will set the action to be executed by clicking the buttons and set the global value g_tabLoc, needed for actions that occur AFTER THE DIALOG QUITS on VW before 12.00 you don't know in which tab your user is. As workaround every button sets a var with the tab number. If the user does not click a button the number remains set to 0. } PROCEDURE action(whichButton, whichTab: INTEGER); { loads a pull down menu with some string value } PROCEDURE PullLoader(whichPull: INTEGER; whatString: STRING); VAR nChoices : INTEGER; BEGIN nChoices := NumChoices(whichPull); { count how many choices are already loaden } { SetPref(12348, false); } { KevinMoore 2001: this turns off dialog refreshing, in this particular case is not needed, but should you wish to load the popup with LOTs of values, you better use it } IF nChoices >= 5 THEN BEGIN AlrtDialog('That is insane. I refuse to go ahead!'); IF nChoices = 5 THEN InsertChoice(whichPull, nChoices, Concat('I refused to go ahead ', inc(g_howInsane), ' time.')) { We insert a last value at the end of the list } ELSE BEGIN DelChoice(whichPull, nChoices-1); InsertChoice(whichPull, nChoices, Concat('I refused to go ahead ', inc(g_howInsane), ' times.')); { insertChoice always insert between, do not overwrite values, so I am bound to delete the last choice } END; END ELSE InsertChoice(whichPull, nChoices, whatString); { load a pull menu with some string } { pull down menus need index 0-based. We read up the amount of values already stored there with numChoices Since we know we loaded already at least one value, '<no history yet>', we can be sure not to make an error. The pull menu will load at the next position. } { SetPref(12348, true); } SelChoice(whichPull, nChoices, TRUE); { select the last choice } END; { main of "Action" } BEGIN g_tabLoc := whichTab; PullLoader(cPull, Concat('You pressed button ', whichButton, ', tab ', g_tabLoc)); END; BEGIN CASE item OF SetupDialogC: BEGIN { initialize some values } g_tabLoc := 0; { initialize the pull down menu } InsertChoice(cPull, 0, '<no history yet>'); END; { these will be called when in Tab 1 } cButTab1_1: action(1, 1); { the first value is the button clicked, the second sets the global var g_tabLoc } cButTab1_2: action(2, 1); cButTab1_3: action(3, 1); { these will be called when in Tab 2 } cButTab2_1: action(1, 2); cButTab2_2: action(2, 2); cButTab2_3: action(3, 2); { these will be called when in Tab 3 } cButTab3_1: action(1, 3); cButTab3_2: action(2, 3); cButTab3_3: action(3, 3); { this happens if user clicks on OK and is executed JUST BEFORE leaving the dialog } 1: CASE g_tabLoc OF 0: BEGIN AlrtDialog('Come on! You should click something!'); IF YNDialog('Do you want to give it a try?') THEN item := -1; { BREAK THE DIALOG - give the user a chance to retry } END; 1, 2: AlrtDialog(Concat('You are about to quit the dialog from tab ', g_tabLoc)); OTHERWISE AlrtDialog('You proved to be insane!'); END; END; END; { this is executed when the dialog exits because you pressed OK AFTER the dialog quits } PROCEDURE DoSomething; CONST br = Chr(13); VAR complaint : STRING; BEGIN complaint := Concat('That wasn', Chr(39), 't much of a dialog, was it?'); IF g_howInsane > 0 THEN complaint := Concat('You drove me crazy. Clicking those buttons ', g_howInsane + 4, ' times!'); IF YNDialog(Concat('Now you quitted the dialog.', br, br, complaint, Chr(13), br, 'Perhaps go ahead to the next dialog example: DialogWithSwaps')) THEN AlrtDialog('Congratulation, you really wish to learn this damn thing!'); END; PROCEDURE DoSomethingElse; BEGIN AlrtDialog('Not very engaged....'); END; { ******** MAIN ******** } BEGIN g_dID := Define_Dialog; IF VerifyLayout(g_dID) THEN BEGIN g_howInsane := 0; g_dResult := RunLayoutDialog(g_dID, Drive_Dialog); IF (g_dResult = 2) THEN AlrtDialog('You canceled') ELSE IF g_tabLoc > 0 THEN DoSomething ELSE DoSomethingElse; END; END; Run(DialogWithTabsAndPullDownMenus);

