Dlog-Generic Pulldown dialog by resource list

From Vectorlab
Jump to: navigation, search


Generic dialog with a pulldown menu built from a resource list. You need to pass a list ID built through the built-in routine {{{2}}}. If the user confirms the dialog with "OK", the routine returns true and sets the passed variables to the chosen index and string of the resource list. If the user canceled, the routine returns false. By Orso B. Schmid


{ Orso B. Schmid ************************************************ }
{ outputs a generic dialog with a pull down menu from a list created with BuildResourceList }
{ sets vars with the chosen pull down index and string }
FUNCTION D_GenericListDialog(title, staticTxt: STRING; listID: LONGINT; VAR choiceNum: INTEGER; VAR choiceStr: STRING): BOOLEAN;
	VAR
		listCount: LONGINT;
		
	
	{ Orso B. Schmid ************************************************ }
	FUNCTION Dialog_Layout: INTEGER;
		VAR
			d, longest: INTEGER;
			i : INTEGER;
			
		BEGIN
			d := CreateLayout(title, FALSE, D_GetStr(174, 1), D_GetStr(174, 2));
			
			{ find out longest item }
			i := 1;
			longest := Len(staticTxt);
			WHILE i < listCount + 1 DO BEGIN
				longest := max(longest, Len(GetNameFromResourceList(ListID, i)));
				i := i + 1;
			END;
			
			IF longest > 64 THEN
				longest := 64;
			longest := longest +4;
			
			CreateStaticText(d, 10, staticTxt, longest);
			CreatePullDownMenu(d, 11, longest);
			
			SetFirstLayoutItem(d, 10);
			SetBelowItem(d, 10, 11, 0, 0);
			
			Dialog_Layout := d;
		END;
	
	PROCEDURE Dialog_Driver(VAR item:LONGINT; data:LONGINT);
		VAR
			i : INTEGER;
			
		BEGIN
			CASE item OF
			SetupDialogC: 
				BEGIN
					i := 0;
					WHILE i < listCount DO BEGIN
						i := i + 1;
						InsertChoice(11, i-1, GetNameFromResourceList(ListID, i));
					END;
					
					choiceStr := GetNameFromResourceList(ListID, 1);
				END;
				
			{ user hit OK }
			1:	GetSelChoice(11, 0, choiceNum, choiceStr);
			
			{ user hit Cancel }
			2: 	BEGIN
					choiceNum := -1;
					choiceStr := '';
				END;
			
			END;
		END;
	
	BEGIN
		listCount := ResourceListSize(listID);
		D_GenericListDialog := (RunLayoutDialog(Dialog_Layout, Dialog_Driver) = 1);
		{ dialog confirmed OK }
	END;