Dialog with tabs - simple

From Vectorlab
Jump to: navigation, search
Underconstruction.png
This vcor page is currently under construction.

By: orso 23:00, 23 February 2007 (PST). Last edit: 2015.12.20 (YYYY.MM.DD)

In the category:Under construction you'll find a list of all pages currently marked as under construction.

Tab example 1 - Dialog with 3 tabs and many buttons. Whenever you click a button, a static text field is set with a sting containing the button pressed and the tab the user is in. This example is 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 simple dialog with 3 tabs
}
PROCEDURE DialogWithTabs;
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;
		cStTab1	= 14;
	
	cTab2 = 20; { tab 2 }
		cButTab2_1 = 21;
		cButTab2_2 = 22;
		cButTab2_3 = 23;
		cStTab2	= 24;
	
	cTab3 = 30; { tab 3 }
		cButTab3_1 = 31;
		cButTab3_2 = 32;
		cButTab3_3 = 33;
		cStTab3	= 34;
		
	c_defString = 'press a button'; { a default string for loading the static text items }
	
VAR
	{ here global variables valid for the whole script, they are prefixed with "g" }
	g_dID, g_dResult  : LONGINT;
	g_tabLoc : INTEGER;
	
	
	{ 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);
			
			CreateStaticText(dID, cStTab1, c_defString, 35);
			SetBelowItem(dID, cButTab1_3, cStTab1, 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);
			
			CreateStaticText(dID, cStTab2, c_defString, 35);
			SetBelowItem(dID, cButTab2_1, cStTab2, 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);
			
			CreateStaticText(dID, cStTab3, c_defString, 35);
			SetBelowItem(dID, cButTab3_3, cStTab3, 0, 0);
		
			{ Create tab control }
			CreateTabControl(dID, cTabControl);
			SetFirstLayoutItem(dID, cTabControl);
		
			{ 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}
		PROCEDURE action(whichButton, whichTab: INTEGER);
			BEGIN
				g_tabLoc := whichTab;
				
				CASE g_tabLoc OF
				1 : SetField(cStTab1, concat('You pressed button ', whichButton, ', tab ', 1));
				2 : SetField(cStTab2, concat('You pressed button ', whichButton, ', tab ', 2));
				3 : SetField(cStTab3, concat('You pressed button ', whichButton, ', tab ', 3));
				END;
			END;

		BEGIN
			CASE item OF
				SetupDialogC:
					BEGIN
						{ initialize some values }
						g_tabLoc := 0;
						{ 
						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.
						}
					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 }	
				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;
					OTHERWISE
						{ this is executed JUST BEFORE leaving the dialog }
						alrtDialog(concat('You are about to quit the dialog from tab ', g_tabLoc));
					END;
			END;
		END;


	{ 
	this is executed when the dialog exits because you pressed OK
	AFTER the dialog quits
	}
	PROCEDURE DoSomething;
		BEGIN
			IF YNDialog(concat('Now you quitted the dialog. That wasn', chr(39), 't much of a dialog, was it?', chr(13), 'Perhaps go ahead to the next dialog example: DialogWithTabsAndPullDownMenu')) 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_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(DialogWithTabs);