Dlog-Generic Class-Layer dialog

From Vectorlab
Jump to: navigation, search


Generic subroutine to create or chose a class/layer. The routine returns true if the user confirmed the dialog with "OK", then it returns the chosen class/layer name and the index of the pulldown menu choice. Otherwise the routine returns FALSE. There is an example of its basic usage at Generic Class-Layer dialog. By Orso B. Schmid


{ 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;
	
	{ Orso B. Schmid ************************************************ }
	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;