home *** CD-ROM | disk | FTP | other *** search
- PICKLISTS
- -----------------------------------------------------------
-
- There are three steps to creating a picklist.
-
- 1. Create the pick list pointer.
- 2. Add items to the pick list.
- 3. Attach the pick list to a frame.
-
- Function CreatePickList(Fonttype:Pointer):OptionMPtr;
-
- Creates the initial picklist pointer. Note that a picklist is built
- up from the same list as a menu.
-
-
- Procedure DefinePickItem(OM:OptionMptr; EntryStr:String; EntryCallProc:callproc; var pickitem:string);
-
- Adds an item to the pick list.
-
- The OM is the picklist previously created with a call to CreatePickList.
- EntryStr is the next item to be added to the pick list. EntryCallProc is an
- event-handler to call when the item is `picked'. Note that you must define
- a this event-handler EVEN IF IT DOES NOTHING. Do not use NilUnitProc here.
-
- Pickitem is a string where a copy of the EntryStr is put. Generally all the
- entries for a given pick list would use the PickItem.
-
- procedure DefinePicklistArea(fs:imagestkptr; x,y,oeselect,displaynum:word; om:optionmptr);
-
- Attaches and displays a pick list on a frame.
-
- The fs is the frame the picklist is being attached to. x,y are the coordinates
- of the upper left corner of the pick list. These are relative to the frame.
-
- OESelect is the item to show as selected on entry to the picklist. If OESelect
- is greater that the number of entries in the picklist then no item is
- selected.
-
- DisplayNum is the number of items to display on the picklist. DisplayNum must
- be greater than 0. 1 is a special instance for the picklist, when used the
- picklist is converted to a Drop-Down pick list. That is, only the selected
- entry is shown with a button to the right. When the button is pressed the
- pick list is dropped-down. If DisplayNum is less that the total number of
- picklist items then a scroll bar is displayed on the picklist, both regular
- and drop-down picklists.
-
- Here is a simple program that displays a pick list.
-
- BEGINFILE> pick1.pas
- {-- Pick1.pas}
- {$F+}
- USES
- teglfont, teglintr, teglunit, teglmain, teglmenu, teglpick;
-
-
- VAR
- ispicked : String;
-
-
- Function WasPicked(ifs: ImageStkPtr; ms : MsClickPtr): Word;
- BEGIN
-
- WasPicked := 1;
- END;
-
-
- Procedure CreatePickFrame;
-
- VAR pom : OptionMPtr;
- ifs : ImageStkPtr;
- BEGIN
- QuickFrame(ifs,100,100,100,100);
- pom := CreatePickList(@f8x8bold);
- SetPickListMargin(pom,12);
- DefinePickItem(pom,'Item 1',WasPicked,ispicked);
- DefinePickItem(pom,'Item 2',WasPicked,ispicked);
- DefinePickItem(pom,'Item 3',WasPicked,ispicked);
- DefinePickListArea(ifs,10,10,2,5,pom);
- END;
-
- BEGIN
- easytegl;
- easyout;
- CreatePickFrame;
-
- TeglSupervisor;
-
- END.
- ENDFILE>
-
- Of course a real program would do something with the result of the
- pick. It's easy to tie in the pick event to another event that will
- look after the result.
-
- BEGINFILE> pick2.pas
- {-- Pick2.pas}
- {$F+}
- USES
- teglfont, tgraph, teglintr, teglunit, teglmain, teglmenu, teglpick;
-
-
- VAR
- ispicked : String;
-
-
- Function WasPicked(ifs: ImageStkPtr; ms : MsClickPtr): Word;
- VAR locfs : ImageStkPtr;
- BEGIN
- dropstackimage(ifs);
- quickframe(ifs,200,200,100,100);
- setcolor(black);
- OutTextXY(210,210,ispicked);
- END;
-
-
- Procedure CreatePickFrame;
-
- VAR pom : OptionMPtr;
- ifs : ImageStkPtr;
- BEGIN
- QuickFrame(ifs,100,100,100,100);
- pom := CreatePickList(@f8x8bold);
- SetPickListMargin(pom,12);
- DefinePickItem(pom,'Item 1',WasPicked,ispicked);
- DefinePickItem(pom,'Item 2',WasPicked,ispicked);
- DefinePickItem(pom,'Item 3',WasPicked,ispicked);
- DefinePickListArea(ifs,10,10,2,5,pom);
- END;
-
- BEGIN
- easytegl;
- easyout;
- CreatePickFrame;
-
- TeglSupervisor;
-
- END.
- ENDFILE>
-
- Here is a fairly complete and useful example of a picklist reading the
- directory and displaying it. It also shows how to handle it when a
- file is double clicked on. A more comprehensive routine would sort
- the filenames before sending them to the picklist and some mechanism
- would enable the user to move through directories.
-
- BEGINFILE> pick3.pas
- {-- pick3.pas }
-
- uses dos,
-
- teglfont, fastgrph, tgraph,
- teglintr, teglunit, teglmain, teglmenu, teglpick;
-
- {$F+}
-
- VAR
- ispicked : String; {-- stores the picked file name }
-
- {-- drops the picklist when the frame is disposed of }
-
- function droppicklist(fs:ImageStkPtr; Userkey:word; Var DataArea):Word;
- var picklist : optionmptr absolute DataArea;
- begin
- dropoptionmenu(picklist);
- droppicklist := 0;
- END;
-
- {-- simple, but handy }
-
- Procedure SetViewPortToFrame(ifs: ImageStkPtr);
- BEGIN
- SetViewPort(ifs^.x,ifs^.y,ifs^.x1,ifs^.y1,clipon);
- END;
-
- {-- this event is called whenever a an item is clicked on }
-
- Function WasPicked(ifs: ImageStkPtr; ms : MsClickPtr): Word;
- BEGIN
- SetViewPortToFrame(ifs); {-- set relative to frame }
- SetFillStyle(solidfill,white); {-- usual colors }
- bar(10,10,140,20); {-- bar out old file name }
- SetColor(BLACK); {-- black letters }
- OutTextXY(10,10,ispicked); {-- show selection }
- {-- left double click just checks to see if the left mouse button }
- {-- was pressed again (within the double click delay) after entering }
- {-- this function. If so then it means the file was selected and we }
- {-- should exit. }
-
- if LeftDoubleClick then dropstackimage(ifs);
- WasPicked := 0;
- END;
-
- {-- just tidy up the files name to make it more acceptable in the pick }
- {-- list view. }
-
- Function FmtFileName(s : String): String;
- VAR
- s1,s2 : String[20];
- BEGIN
- if Pos('.',s) > 0 then
- begin
- s1 := copy(s,1,pos('.',s)-1);
- s2 := copy(s,pos('.',s),255);
- while length(s1) < 8 do s1 := s1 + ' ';
- s := s1 + s2;
- end
- else
- while length(s) < 12 do s := s + ' ';
- fmtFileName := s + ' ';
- END;
-
- {-- searchrec, findfirst etc. are in your TURBO manual }
-
- Procedure GetFileName(Path : PathStr;FileArg: PathStr; Attr : Word);
-
- VAR
- dd : SearchRec; {-- store directory entries }
- pom : OptionMPtr;
- ifs :ImageStkPtr;
- BEGIN
- if path[length(path)] <> '\' then path := path + '\';
- QuickFrame(ifs,100,100,200,200);
- SetProportional(FALSE);
- pom := CreatePickList(@f8x8bold);
- SetUserDataArea(StackPtr,5432,pom,droppicklist);
- SetViewPortToFrame(ifs);
- SetTEGLFont(@f8x8bold);
- SetColor(BLACK);
- Rectangle(5,5,150,23);
- OutTextXY(10,10,FileArg);
- OutTextXY(10,35,Path);
- FindFirst(path+FileArg,attr,dd);
- WHILE (DosError <> 18) DO
- BEGIN
- definePickItem(pom,fmtfilename(dd.name),WasPicked,ispicked);
- FindNext(dd);
- END;
- {-- attach it }
- DefinePickListArea(ifs,10,60,0,12,pom);
-
- END;
-
-
- VAR curDir : String;
- BEGIN
- easytegl;
- easyout;
- GetDir(0,curdir); {-- for example just load the names }
- GetFileName(curdir,'*.*', Archive); {-- of all the files in the current }
- {-- directory. }
- TeglSupervisor;
-
- END.
- ENDFILE>
- procedure ClearPickList(OM:OptionMptr);
-
- Resets a pick list. All the entries are disposed of but the picklist is
- not. After ClearPickList is the same as having just created a picklist
- using CreatePickList.
-
- procedure SetPickListWidth(om: Optionmptr; maxwidth:word);
-
- Set the maximum width of the picklist.
-
- OM is a pickllist previously created with CreatePickList. MaxWidth is the
- maximim width of the picklist in pixels.
-
- Procedure detachpicklist(OM:OptionMPtr);
-
- procedure attachpicklist(om:optionmptr; oeselect:word);
-
- procedure SetPickListMargin(om:optionmptr; marginw:word);
-
- Sets the margin around the text of the picklist.
-
- OM is a picklist previously created with CreatePickList. MarginW is the margin,
- in pixels, on the left and right side of the text.
-
- ---------
- Picklists can be disposed of with a call to DropOptionMenu since they use
- the same data structure and list mechanism as option menus.
-
- DropOptionMenu(OM : OptionMPtr);
-
- ---- END picklist.txt
-