Generic Class-Layer dialog

From Vectorlab
Jump to: navigation, search


A generic dialog displaying a pop-up for classes or layers distinguishing among sheet and design layers. By Orso B. Schmid

NOTE
based upon the subroutine D_GenericLayClassDialog


{ Orso. B. Schmid }
PROCEDURE xxxxx;
	VAR
		num	: INTEGER;
		str	: STRING;
		
	{ ************************************************ }
	{ returns a resource string at given index and number }
	FUNCTION D_GetStr(resID, resNr: INTEGER): STRING;
		VAR
			str : STRING;
		BEGIN
			GetResourceString(D_GetStr, resID, resNr);
		END;
	
	{ Orso. B. Schmid ************************************************ }
	{ outputs a generic dialog with a pull down menu from a list of layers or classes }
	{ sets vars with the chosen pull down index and string }
	{ displayType = 0 -> design layers }
	{ displayType = 1 -> sheet layers }
	{ displayType = 2 -> classes }
	FUNCTION D_GenericLayClassDialog(title, staticTxt: STRING; displayType: INTEGER; VAR choiceNum: INTEGER; VAR choiceStr: STRING): BOOLEAN;
		
		{ ************************************************ }
		FUNCTION Dialog_Layout: INTEGER;
			VAR
				d, longest: INTEGER;
				layH : HANDLE;
				
			BEGIN
				d := CreateLayout(title, FALSE, D_GetStr(174, 1), D_GetStr(174, 2));
				
				{ find out longest item }
				layH := FLayer;
				longest := Len(staticTxt);
				WHILE layH <> NIL DO BEGIN
					longest := max(longest, Len(GetLName(layH)));
					layH := NextLayer(layH);
				END;
				
				IF longest > 64 THEN
					longest := 64;
				longest := longest +4;
				
				CreateStaticText(d, 10, staticTxt, longest);
				
				CASE displayType of
				0: CreateDesignLayerPullDownMenu(d, 11, longest);
				1: CreateSheetLayerPullDownMenu(d, 11, longest);
				2: CreateClassPullDownMenu(d, 11, longest);
				END;
				
				SetFirstLayoutItem(d, 10);
				SetBelowItem(d, 10, 11, 0, 0);
				
				Dialog_Layout := d;
			END;
		
		PROCEDURE Dialog_Driver(VAR item:LONGINT; data:LONGINT);
			BEGIN
				CASE item OF
				SetupDialogC: 
					BEGIN
						{ add anything to preset the dialog }
					END;
					
				{ user hit OK }
				1:	GetSelChoice(11, 0, choiceNum, choiceStr);
				
				{ user hit Cancel }
				2: 	BEGIN
						choiceNum := -1;
						choiceStr := '';
					END;
				
				END;
			END;
	
		BEGIN
			D_GenericLayClassDialog := (RunLayoutDialog(Dialog_Layout, Dialog_Driver) = 1);
			{ dialog confirmed OK }
		END;

BEGIN
	IF D_GenericLayClassDialog('My class dialog', 'Chose a class', 2, num, str) THEN
		AlrtDialog(Concat('You chose: ', str));
END;

Run(xxxxx);