kim@amdahl.UUCP (Kim DeVaughn) (08/15/86)
[ "Send lawyers, guns, and money ..." ] Below is a shar archive that I am posting for a friend. It is a file requester routine, and has an example driver. Since he isn't on the net (yet), you can reach him via email to me. Watch out for the signature at the end ... /kim # This is a shell archive. Remove anything before this line, then # unpack it by saving it in a file and typing "sh file". (Files # unpacked will be owned by you and have default permissions.) # # This archive contains: # Makefile README requester.c requester.doc requester.h screen.c screen.h screen1.c echo x - Makefile cat > "Makefile" << '//E*O*F Makefile//' screen: screen.o screen1.o requester.o ln screen.o screen1.o requester.o -lc32 screen.o: screen.c cc screen.c +l -s screen1.o: screen1.c cc screen1.c +l -s requester.o: requester.c cc requester.c +l -s //E*O*F Makefile// echo x - README cat > "README" << '//E*O*F README//' I have just posted two source programs. One is the source for a file name requester that looks like the one used in Deluxe Paint. The other is an example on how to use the requester. To see the requester in action do the following: 1) You must use CLI to run the example. 2) bring up the example driver program by typing "screen". 3) Pull down the "Project" menu and select the "Load" or "Save" item. 4) The requester will be displayed. The requester contains the following gadgets: 1) 8 boolean file selection gadgets. Each gadget contains the name of a file or directory entry in the current directory. 2) 2 boolean gadgets for scrolling up and down in the list of names displayed in the file selection gadgets. 3) A potentiometer gadget for scrolling up and down in the list of file selection gadgets. 4) 2 string gadgets. One for Drawer (directory) names, and the other for file names. 5) 2 boolean gadgets. One is Cancel, the other is Load (Save). These gadgets end the requester. If you selected the Load gadget, the driver will print your file name on the workbench screen. if you selected the Cancel gadget, the driver will print "You punted" on the workbench screen. The screen program allows you to see the requester used in different screen formats. You can change the ViewModes (High Resloution, Interlace, Dual PlayFields...) and the number of bit planes. Use the "Edit" menu to change the settings. Use the "Project" menu's "Use" item to use the new settings. Once you have a new screen ViewMode, or a new number of bit planes, use the "Project" menu's "Load" or "Save" item to redisplay the requester. There is a requester.doc file that shows you the software interface to the requester. It uses the documentation format used in the Amiga Intuition Reference manual. Both programs compile with Manx and work fine under 1.1. They don't seem to work under 1.2 beta6 (anyone want to look into this one?). I haven't compiled them under Lattice. What's next? Well, I thought I'd go on to add the 'zz' baloon anytime a directory is being listed. Also thinking about scolling the names as the potentiometer gadget moves. This should be a performance wonder! Anyone got any other ideas or enhancements? Of course there is the question as to why it doesn't work with 1.2..... Any volunteers? Anyone want to help? I am available by voice during the day at 408-737-5481. Good luck finding me at night! My U.S. mail service address is: Kevin L. Clague 408 Tortolla Way San Jose, CA 95133 Hope you like the programs!! //E*O*F README// echo x - requester.c cat > "requester.c" << '//E*O*F requester.c//' /**************************************************************************** * * FileRequest() - File Name Requester * * By Kevin Lee Clague * 408 Tortolla Way * San Jose, Ca 95033 * 408-258-9891 work 408-737-5481 * * Copyright (C) 1986. All rights reserved. * * This program is freely distributable as long as this copyright notice * is retained. It intended for personal, non-commercial use. * * This file name requester is modeled after Deluxe Paints file name * requester. The dimensions/locations of all borders, gadgets and text were * arrived at empirically. Besides being a great program, Deluxe Paint is a * trade mark of Electronics Arts. * * The knowledge on how to get at the entries in the directories was drawn * from Mike (I'll be melow when I'm dead) Meyer's "Browser". * ***************************************************************************/ /*************************************************************************** * * Things to do: * 1. Dynamically allocate space for file name strings as they are gotten * from the disk, rather than static allocation of them in arrays. * 2. Fence off intuition events while getting file names from disk * directory (and put up the zz sleepy cloud in place of the arrow * mouse cursor.) * 3. Be a little more diligent with my use of RefreshGadgets. * ***************************************************************************/ #include "Requester.h" BOOL IsDir(); BOOL WaitRequester(); struct Requester FileRequester; UBYTE *FullPath; struct Window *window; struct IntuiMessage *message; struct FileInfoBlock FileInfo; USHORT FileCount; /* Number of files in current dir */ UBYTE FileListEntry[MAXFILES][40]; /* File (dir) names in current dir */ USHORT FirstFile; #define PATHNAMELEN 80 /**************************************************************************** * The Gadget String ***************************************************************************/ /****************************** * The File Name Gadget stuff * *****************************/ struct IntuiText FileText = { 0,1, JAM2, /* frontpen, packpen, drawmode */ -46,0, /* left,top */ NULL, /* font */ "File:", /* text */ NULL /* next */ }; UBYTE FileName[40]; UBYTE Backup[40]; struct StringInfo FileString = { &FileName, /* input buffer */ &Backup, /* undo buffer */ 0, /* Buffer position */ 32, /* buffer size */ 0, /* disp position*/ 0,0,0,0,0,NULL,0,NULL /* undo position*/ }; SHORT DrawerPoints[] = { -2, -2, 185,-2, 185,10, -2, 10, -2, -2 }; struct Border DrawerBorder = { 0,0, 0,1,JAM1, 5, &DrawerPoints[0], NULL }; struct Gadget FileGadget = { /* File string */ NULL, /* next gadget */ 67,113, /* location */ 185,8, GADGHCOMP, /* flags */ 0, /* activation */ STRGADGET|REQGADGET, /* type */ (APTR) &DrawerBorder, /* rendering */ NULL, /* rendering */ &FileText, /* text */ 0, /* mutual exlcude */ &FileString, /* string info */ NULL, /* gadget id */ NULL /* special info*/ }; /******************************** * The Drawer Name Gadget stuff * *******************************/ struct IntuiText DrawerText = { 0,1, JAM2, /* frontpen, packpen, drawmode */ -62,0, /* left,top */ NULL, /* font */ "Drawer:", /* text */ NULL /* next */ }; UBYTE DrawerName[40]; struct StringInfo DrawerString = { &DrawerName, /* input buffer */ &Backup, /* undo buffer */ 0, /* Buffer position */ 32, /* buffer size */ 0, /* disp position*/ 0,0,0,0,0,NULL,0,NULL /* undo position*/ }; struct Gadget DrawerGadget = { /* Drawer string */ &FileGadget, /* next gadget */ 67,98, /* location */ 185,8, GADGHCOMP, /* flags */ RELVERIFY, /* activation */ STRGADGET|REQGADGET, /* type */ (APTR) &DrawerBorder, /* rendering */ NULL, /* rendering */ &DrawerText, /* text */ 0, /* mutual exlcude */ &DrawerString, /* string info */ DRAWERGADGET, /* gadget id */ NULL /* special info*/ }; /**************************************** * The File list selection Gadget stuff * ***************************************/ UBYTE PickNames[8][40]; struct IntuiText FileList[] = { { 0,1, JAM2, /* frontpen, packpen, drawmode */ 0,0, /* left,top */ NULL, /* font */ &PickNames[0][0], /* text */ NULL /* next */ }, { 0,1, JAM2, /* frontpen, packpen, drawmode */ 0,0, /* left,top */ NULL, /* font */ &PickNames[1][0], /* text */ NULL /* next */ }, { 0,1, JAM2, /* frontpen, packpen, drawmode */ 0,0, /* left,top */ NULL, /* font */ &PickNames[2][0], /* text */ NULL /* next */ }, { 0,1, JAM2, /* frontpen, packpen, drawmode */ 0,0, /* left,top */ NULL, /* font */ &PickNames[3][0], /* text */ NULL /* next */ }, { 0,1, JAM2, /* frontpen, packpen, drawmode */ 0,0, /* left,top */ NULL, /* font */ &PickNames[4][0], /* text */ NULL /* next */ }, { 0,1, JAM2, /* frontpen, packpen, drawmode */ 0,0, /* left,top */ NULL, /* font */ &PickNames[5][0], /* text */ NULL /* next */ }, { 0,1, JAM2, /* frontpen, packpen, drawmode */ 0,0, /* left,top */ NULL, /* font */ &PickNames[6][0], /* text */ NULL /* next */ }, { 0,1, JAM2, /* frontpen, packpen, drawmode */ 0,0, /* left,top */ NULL, /* font */ &PickNames[7][0], /* text */ NULL /* next */ } }; struct Gadget FileListGadget[] = { { /* File name selection 0 */ &FileListGadget[1], /* next gadget */ 5,14, /* location */ 244,8, GADGHNONE, /* flags */ GADGIMMEDIATE, /* activation */ BOOLGADGET|REQGADGET, /* type */ NULL, /* rendering */ NULL, /* rendering */ &FileList[0], /* text */ 0, /* mutual exlcude */ NULL, /* string info */ FILE0GADGET, /* gadget id */ NULL /* special info*/ }, { /* File name selection 1 */ &FileListGadget[2], /* next gadget */ 5,24, /* location */ 244,8, GADGHNONE, /* flags */ GADGIMMEDIATE, /* activation */ BOOLGADGET|REQGADGET, /* type */ NULL, /* rendering */ NULL, /* rendering */ &FileList[1], /* text */ 0, /* mutual exlcude */ NULL, /* string info */ FILE1GADGET, /* gadget id */ NULL /* special info*/ }, { /* File name selection 2 */ &FileListGadget[3], /* next gadget */ 5,34, /* location */ 244,8, GADGHNONE, /* flags */ GADGIMMEDIATE, /* activation */ BOOLGADGET|REQGADGET, /* type */ NULL, /* rendering */ NULL, /* rendering */ &FileList[2], /* text */ 0, /* mutual exlcude */ NULL, /* string info */ FILE2GADGET, /* gadget id */ NULL /* special info*/ }, { /* File name selection 3 */ &FileListGadget[4], /* next gadget */ 5,44, /* location */ 244,8, GADGHNONE, /* flags */ GADGIMMEDIATE, /* activation */ BOOLGADGET|REQGADGET, /* type */ NULL, /* rendering */ NULL, /* rendering */ &FileList[3], /* text */ 0, /* mutual exlcude */ NULL, /* string info */ FILE3GADGET, /* gadget id */ NULL /* special info*/ }, { /* File name selection 4 */ &FileListGadget[5], /* next gadget */ 5,54, /* location */ 244,8, GADGHNONE, /* flags */ GADGIMMEDIATE, /* activation */ BOOLGADGET|REQGADGET, /* type */ NULL, /* rendering */ NULL, /* rendering */ &FileList[4], /* text */ 0, /* mutual exlcude */ NULL, /* string info */ FILE4GADGET, /* gadget id */ NULL /* special info*/ }, { /* File name selection 5 */ &FileListGadget[6], /* next gadget */ 5,64, /* location */ 244,8, GADGHNONE, /* flags */ GADGIMMEDIATE, /* activation */ BOOLGADGET|REQGADGET, /* type */ NULL, /* rendering */ NULL, /* rendering */ &FileList[5], /* text */ 0, /* mutual exlcude */ NULL, /* string info */ FILE5GADGET, /* gadget id */ NULL /* special info*/ }, { /* File name selection 6 */ &FileListGadget[7], /* next gadget */ 5,74, /* location */ 244,8, GADGHNONE, /* flags */ GADGIMMEDIATE, /* activation */ BOOLGADGET|REQGADGET, /* type */ NULL, /* rendering */ NULL, /* rendering */ &FileList[6], /* text */ 0, /* mutual exlcude */ NULL, /* string info */ FILE6GADGET, /* gadget id */ NULL /* special info*/ }, { /* File name selection 7 */ &DrawerGadget, /* next gadget */ 5,84, /* location */ 244,8, GADGHNONE, /* flags */ GADGIMMEDIATE, /* activation */ BOOLGADGET|REQGADGET, /* type */ NULL, /* rendering */ NULL, /* rendering */ &FileList[7], /* text */ 0, /* mutual exlcude */ NULL, /* string info */ FILE7GADGET, /* gadget id */ NULL /* special info*/ } }; /******************************** * The Load Button gadget stuff * *******************************/ SHORT ButtonPoints1[] = { -4, -4, 66, -4, 66, 12, -4, 12, -4, -4 }; struct Border ButtonBorder1 = { 0,0, 2,1,JAM1, 5, &ButtonPoints1[0], NULL }; SHORT ButtonPoints0[] = { -3, -2, 65, -2, 65, 10, -3, 10, -3, -2 }; struct Border ButtonBorder0 = { 0,0, 0,1,JAM1, 5, &ButtonPoints0[0], &ButtonBorder1 }; struct IntuiText LoadText = { 0,1, JAM2, /* frontpen, packpen, drawmode */ 0,0, /* left,top */ NULL, /* font */ NULL, /* text */ NULL /* next */ }; struct Gadget LoadGadget = { /* Load button */ &FileListGadget[0], /* next gadget */ 14,130, /* location */ 64,8, GADGHCOMP, /* flags */ GADGIMMEDIATE|ENDGADGET, /* activation */ BOOLGADGET|REQGADGET, /* type */ (APTR) &ButtonBorder0, /* rendering */ NULL, /* rendering */ &LoadText, /* text */ 0, /* mutual exlcude */ NULL, /* string info */ LOADGADGET, /* gadget id */ NULL /* special info*/ }; /********************************** * The Cancel Button gadget stuff * *********************************/ struct IntuiText CancelText = { 0,1, JAM2, /* frontpen, packpen, drawmode */ 0,0, /* left,top */ NULL, /* font */ "Cancel", /* text */ NULL /* next */ }; struct Gadget CancelGadget = { /* Cancel button */ &LoadGadget, /* next gadget */ 187,130, /* location */ 64,8, GADGHCOMP, /* flags */ GADGIMMEDIATE|ENDGADGET, /* activation */ BOOLGADGET|REQGADGET, /* type */ (APTR) &ButtonBorder0, /* rendering */ NULL, /* rendering */ &CancelText, /* text */ 0, /* mutual exlcude */ NULL, /* string info */ CANCELGADGET, /* gadget id */ NULL /* special info*/ }; /*********************************************** * The Scroll Selection List up (arrow) gadget * **********************************************/ UWORD UpArrowData[15] = { 0xfffc, 0xfcfc, 0xf87c, 0xf03c, 0xe01c, 0xc00c, 0x8004, 0xfcfc, 0xfcfc, 0xfcfc, 0xfcfc, 0xfcfc, 0xfcfc, 0xfffc }; struct Image UpArrow = { 0,0, 14, 14, 1, &UpArrowData[0], 0x1, 0x0, NULL }; struct Gadget UpGadget = { /* Up a file gadget */ &CancelGadget, /* next gadget */ 247,13, /* location */ 12,15, GADGIMAGE|GADGHNONE, /* flags */ GADGIMMEDIATE, /* activation */ BOOLGADGET|REQGADGET, /* type */ (APTR) &UpArrow, /* rendering */ NULL, /* rendering */ NULL, /* text */ 0, /* mutual exlcude */ NULL, /* string info */ UPGADGET, /* gadget id */ NULL /* special info*/ }; /************************************************* * The Scroll Selection List down (arrow) gadget * ************************************************/ UWORD DownArrowData[15] = { 0xfffc, 0xfcfc, 0xfcfc, 0xfcfc, 0xfcfc, 0xfcfc, 0xfcfc, 0x8004, 0xc00c, 0xe01c, 0xf03c, 0xf87c, 0xfcfc, 0xfffc }; struct Image DownArrow = { 0,0, 14, 14, 1, &DownArrowData[0], 0x1, 0x0, NULL }; struct Gadget DownGadget = { /* Down a file gadget */ &UpGadget, /* next gadget */ 247,79, /* location */ 12,15, GADGIMAGE|GADGHNONE, /* flags */ GADGIMMEDIATE, /* activation */ BOOLGADGET|REQGADGET, /* type */ (APTR) &DownArrow, /* rendering */ NULL, /* rendering */ NULL, /* text */ 0, /* mutual exlcude */ NULL, /* string info */ DOWNGADGET, /* gadget id */ NULL /* special info*/ }; /*************************************************** * The Scroll Selection list up down Potentiometer * **************************************************/ struct PropInfo KnobInfo = { AUTOKNOB | FREEVERT | PROPBORDERLESS, 0, 0, /* VertPot */ 0, 0x7fff, /* VertBody */ 0,0,0,0,0,0 }; struct Image KnobImage = { 0,0, 0,0,0, NULL, 0,0, NULL }; struct Gadget PotGadget = { /* Potentiometer file gadget */ &DownGadget, /* next gadget */ 247,28, /* location */ 14,50, GADGHNONE, /* flags */ RELVERIFY, /* activation */ PROPGADGET|REQGADGET, /* type */ (APTR) &KnobImage, /* rendering */ NULL, /* rendering */ NULL, /* text */ 0, /* mutual exlcude */ &KnobInfo, /* string info */ POTGADGET, /* gadget id */ NULL /* special info*/ }; /*************************************************************************** * Other Requester structures * ***************************************************************************/ struct IntuiText HeadingText = { 2,1, JAM2, /* frontpen, packpen, drawmode */ 4,3, /* left,top */ NULL, /* font */ NULL, /* text */ NULL /* next */ }; SHORT Requester0Points[] = { 2,1, 261,1, 261,144, 2,144, 2,1 }; struct Border Requester0Border = { 0,0, 0,1,JAM1, 5, &Requester0Points[0], NULL }; SHORT Requester1Points[] = { 2,12, 261,12 }; struct Border Requester1Border = { 0,0, 0,1,JAM1, 2, &Requester1Points[0], &Requester0Border }; SHORT Requester2Points[] = { 2,93, 261,93 }; struct Border Requester2Border = { 0,0, 0,1,JAM1, 2, &Requester2Points[0], &Requester1Border }; SHORT Requester3Points[] = { 246,12, 246,93, 246,78, 261,78, 261,27, 247,27 }; struct Border Requester3Border = { 0,0, 0,1,JAM1, 6, &Requester3Points[0], &Requester2Border }; /**************************************************************************** * The Code part of the requester ***************************************************************************/ BOOL FileRequest(FileType,Action,FullName,ReqWindow) UBYTE *FileType; UBYTE *Action; UBYTE *FullName; struct Window *ReqWindow; { UBYTE *StrPtr; BOOL RetCode; window = ReqWindow; /* make pointer to window and name global */ FullPath = FullName; HeadingText.IText = FileType; /* Center requester title */ HeadingText.LeftEdge = (256-IntuiTextLength(&HeadingText))/2; LoadText.IText = Action; InitFNR(); /* Separate the path from the file name. Set the file name in the gadget */ if (StrPtr = rindex(FullName,'/')) { strcpy(FileString.Buffer,StrPtr + 1); *StrPtr = '\0'; } else if (StrPtr = rindex(FullName,':')) { strcpy(FileString.Buffer,StrPtr + 1); *(StrPtr+1) = '\0'; } else { *FileString.Buffer = '\0'; *DrawerString.Buffer = '\0'; *FullName = '\0'; } /* Separate the last dir in path and put it in drawer gadget */ if (StrPtr = rindex(FullName,'/')) strcpy(DrawerString.Buffer,StrPtr + 1); else if (StrPtr = rindex(FullName,':')) if (*(StrPtr+1)) strcpy(DrawerString.Buffer,StrPtr + 1); else strcpy(DrawerString.Buffer,FullName); else *DrawerString.Buffer = '\0'; /* Put up the requester and list the dir into it */ Request(&FileRequester,window); ListDir(FullName); SetNewFile(&FileGadget,FileString.Buffer); /* why do I have to do this? */ SetNewFile(&DrawerGadget,DrawerString.Buffer); RetCode = WaitRequester(); /* do everything till Cancel or Load */ /* Put file name and path back together */ if (FullName[strlen(FullName)-1] != ':') strcat(FullName,"/"); strcat(FullName,FileString.Buffer); return(RetCode); } /* LoadRequest */ /* * Init the file name requester */ InitFNR() { InitRequester(&FileRequester); FileRequester.LeftEdge = 6; FileRequester.TopEdge = 12; FileRequester.Width = 264; FileRequester.Height = 146; FileRequester.ReqGadget = &PotGadget; FileRequester.ReqText = &HeadingText; FileRequester.BackFill = 1; FileRequester.Flags = 0; FileRequester.ReqBorder = &Requester3Border; } /* InitFNR */ /* * WaitRequester - List dirs, scroll, and set drawer and file strings until * one of the LOAD(SAVE) or CANCEL buttons pushed. */ BOOL WaitRequester() { ULONG class = GADGETDOWN; USHORT choice = CANCELGADGET; struct Gadget *gadget; while (class != REQCLEAR) { if ((message=(struct IntuiMessage *) GetMsg(window->UserPort)) == 0L) { Wait(1L<<window->UserPort->mp_SigBit); continue; } class = message->Class; gadget = (struct Gadget *) message->IAddress; ReplyMsg(message); switch (class) { case GADGETDOWN: switch (gadget->GadgetID >> CLASSBITS) { case UPDOWNCLASS: ScrollList(gadget); /* scroll up/down 1 file */ break; case CHOICECLASS: /* set the name in string gads */ if (IsDir(gadget->GadgetText->IText)) SetNewDrawer(&DrawerGadget,gadget->GadgetText->IText); else SetNewFile(&FileGadget,gadget->GadgetText->IText); break; case BUTTONCLASS: /* LOAD or CANCEL */ choice = gadget->GadgetID & GADGETNUM; } case GADGETUP: switch (gadget->GadgetID >> CLASSBITS) { case UPDOWNCLASS: /* Potentiometer scroll */ PotScrollList(gadget); break; case STRINGCLASS: /* They typed drawer name in */ ThrowTrailing(DrawerString.Buffer); strcpy(FullPath,DrawerString.Buffer); SetNewFile(&FileGadget,""); ListDir(DrawerString.Buffer); } } } return(choice==LOAD); } /* WaitRequester */ /* * SetNewDrawer - Used Mouse to pick directory from selection list gadgets. */ SetNewDrawer(Gadget,Text) struct Gadget *Gadget; UBYTE *Text; { SetNewFile(&FileGadget,""); /* clear file name string */ SetNewFile(Gadget,Text); /* set new drawer into gadget */ if (FullPath[strlen(FullPath)-1] != ':') /* make new path */ strncat(FullPath,"/",PATHNAMELEN); strncat(FullPath,Text,PATHNAMELEN); ListDir(FullPath); /* List new files into Sel List */ } /* SetNewDrawer */ /* * SetNewFile - Have to remove gadgets change strings and add them */ SetNewFile(Gadget,Text) struct Gadget *Gadget; UBYTE *Text; { USHORT Pos, RemoveGadget(); if (Text[0] != ' ') { Pos = RemoveGadget(window,Gadget); ThrowTrailing(Text); /* get rid of trailing blanks */ strcpy(Gadget->SpecialInfo->Buffer,Text); AddGadget(window,Gadget,Pos); RefreshGadgets(&DownGadget,window,&FileRequester); } } /* SetNewFile */ /* * ListDir - List the directory into array of string names. */ ListDir(dir) char *dir; { struct FileLock *my_lock, *Lock() ; FileCount = 0; FirstFile = 0; if ((my_lock = Lock(dir, ACCESS_READ)) != NULL) { if (Examine(my_lock, &FileInfo)) { ExNext(my_lock, &FileInfo); while (IoErr() != ERROR_NO_MORE_ENTRIES && FileCount < MAXFILES) { strcpy(&FileListEntry[FileCount][0], FileInfo.fib_FileName); if (FileInfo.fib_DirEntryType > 0) strcat(&FileListEntry[FileCount][0]," (dir)"); FileCount++; ExNext(my_lock, &FileInfo); } UnLock(my_lock) ; } } AttachList(FirstFile); if (FileCount > 8) ModifyProp(&PotGadget,window,&FileRequester,AUTOKNOB|FREEVERT|PROPBORDERLESS,0,0,0,0xffff/(FileCount-6)*8); else ModifyProp(&PotGadget,window,&FileRequester,AUTOKNOB|FREEVERT|PROPBORDERLESS,0,0,0,0xffff); } /* ListDir */ /* * AttachList - Attach list of file (directory) names to Selection gadgets */ AttachList(Start) USHORT Start; { USHORT Gadget; USHORT Pos, RemoveGadget(); for (Gadget = 0; Gadget <= 7 && Gadget+Start < FileCount; Gadget++) { Pos = RemoveGadget(window,&FileListGadget[Gadget]); strcpy(FileList[Gadget].IText,&FileListEntry[Start + Gadget][0]); strncat(FileList[Gadget].IText," ",24-strlen(FileList[Gadget].IText)); AddGadget(window,&FileListGadget[Gadget],Pos); } for (; Gadget <= 7; Gadget++) { Pos = RemoveGadget(window,&FileListGadget[Gadget]); strncpy(FileList[Gadget].IText," ",24); AddGadget(window,&FileListGadget[Gadget],Pos); } RefreshGadgets(&DownGadget,window,&FileRequester); } /* AttachList */ /* * ScrollList - Scroll the list up or down 1 file if possible */ ScrollList(gadget) struct Gadget *gadget; { ULONG VertPot = 0; switch(gadget->GadgetID & GADGETNUM) { case DOWN: if (FileCount > FirstFile + 8) ++FirstFile; break; case UP: if (FirstFile > 0) --FirstFile; } if (FileCount > 8) VertPot = 0xffff/(FileCount-6)*FirstFile; ModifyProp(&PotGadget,window,&FileRequester,AUTOKNOB|FREEVERT|PROPBORDERLESS,0,VertPot,0,KnobInfo.VertBody); AttachList(FirstFile); } /* ScrollList */ /* * PotScrollList - Calculate the file number from Pot value and attach * names to Selector List gadgets. */ PotScrollList(gadget) struct Gadget *gadget; { switch (gadget->GadgetID & GADGETNUM) { case POT: FirstFile = (FileCount-6)*KnobInfo.VertPot >> 16; AttachList(FirstFile); } } /* PotScrollList */ /* * IsDir - Simple minded routine to find " (dir)" in file name */ BOOL IsDir(Name) UBYTE *Name; { UBYTE *Dir; if (Dir = rindex(Name,'(')) if (strcmp(Dir,"(dir)")) { Dir[0] = '\0'; ThrowTrailing(Name); return(TRUE); } else return(FALSE); else return(FALSE); } /* IsDir */ /* * ThrowTrailing - Remove trailing blanks from string */ ThrowTrailing(String) UBYTE *String; { SHORT I; I = strlen(String) - 1; while (String[I] == ' ' && I > 0) String[I--] = '\0'; } /* ThrowTrailing */ //E*O*F requester.c// echo x - requester.doc cat > "requester.doc" << '//E*O*F requester.doc//' NAME FileRequest -- Presents a file name requester in your window. SYNOPSIS BOOL FileRequest(Title, LeftButtonText, FullPath, Window); UBYTE *Title, *LeftButtonText, *FullPath; struct Window *Window; FUNCTION This routine performs the functions of a file name requester: it lists the directory specified by FullPath; it displays up to 8 file or directory names; it allows scrolling up and down the list using boolean or potentiometer gadgets; and it permits directory and file name selection using the mouse or the keyboard. NOTE: The "GADGETDOWN, GADGETUP and REQCLEAR" IDCMP flags must be set in your Window structure for this requester to operate properly. INPUTS Title = pointer to a string that is the title of the requester. LeftButtonText = pointer to a string that indicates the function associated with the left boolean gadget (e.g. Load or Save). (The right mouse button is always associated with the Cancel function.) FullPath = pointer to a string containing the full path of the directory to be listed when requester is displayed. (There must be room in the string for at least 80 bytes - 79 + NULL termination.) Example: UBYTE MyFile[80] = "df0:dir1/dir2/file" Window = pointer to the window in which the requester is to be rendered. RESULT If the right requester (Cancel) button is selected, FALSE is returned. If the left requester button (defined by you) is selected, TRUE is returned. The variable "FullPath" is modified by the user's actions, regardless of which button is selected. BUGS SEE ALSO AutoRequest(), Request(). //E*O*F requester.doc// echo x - requester.h cat > "requester.h" << '//E*O*F requester.h//' /**************************************************************************** * * FileRequest() - File Name Requester * * By Kevin Lee Clague * 408 Tortolla Way * San Jose, Ca 95033 * 408-258-9891 work 408-737-5481 * * Copyright (C) 1986. All rights reserved. * * This program is freely distributable as long as this copyright notice * is retained. It intended for personal, non-commercial use. * * This file name requester is modeled after Deluxe Paints file name * requester. The dimensions/locations of all borders, gadgets and text were * arrived at empirically. Besides being a great program, Deluxe Paint is a * trade mark of Electronics Arts. * * The knowledge on how to get at the entries in the directories was drawn * from Mike (I'll be melow when I'm dead) Meyer's "Browser". * ***************************************************************************/ #include <exec/types.h> #include <graphics/gfxbase.h> #include <libraries/dos.h> #include <libraries/dosextens.h> #include <intuition/intuition.h> #include <intuition/intuitionbase.h> #include <ctype.h> #include <stdio.h> #include <workbench/workbench.h> #define INTUITION_REV 1 #define GRAPHICS_REV 1 #define CHARACTER_WIDTH 8 #define CHARACTER_HEIGHT 8 /* ========================================================================*/ /* File name requester gadget ids */ #define CLASSBITS 8 #define UPDOWNCLASS 1 #define CHOICECLASS 2 #define STRINGCLASS 3 #define BUTTONCLASS 4 #define GADGETNUM 255 #define LOAD 0 #define CANCEL 1 #define DRAWER 0 #define UP 0 #define DOWN 1 #define POT 2 #define FILE0 0 #define FILE1 1 #define FILE2 2 #define FILE3 3 #define FILE4 4 #define FILE5 5 #define FILE6 6 #define FILE7 7 #define LOADGADGET BUTTONCLASS << CLASSBITS | LOAD #define CANCELGADGET BUTTONCLASS << CLASSBITS | CANCEL #define UPGADGET UPDOWNCLASS << CLASSBITS | UP #define DOWNGADGET UPDOWNCLASS << CLASSBITS | DOWN #define POTGADGET UPDOWNCLASS << CLASSBITS | POT #define FILE0GADGET CHOICECLASS << CLASSBITS | FILE0 #define FILE1GADGET CHOICECLASS << CLASSBITS | FILE1 #define FILE2GADGET CHOICECLASS << CLASSBITS | FILE2 #define FILE3GADGET CHOICECLASS << CLASSBITS | FILE3 #define FILE4GADGET CHOICECLASS << CLASSBITS | FILE4 #define FILE5GADGET CHOICECLASS << CLASSBITS | FILE5 #define FILE6GADGET CHOICECLASS << CLASSBITS | FILE6 #define FILE7GADGET CHOICECLASS << CLASSBITS | FILE7 #define DRAWERGADGET STRINGCLASS << CLASSBITS | DRAWER #define MAXFILES 100 //E*O*F requester.h// echo x - screen.c cat > "screen.c" << '//E*O*F screen.c//' /**************************************************************************** * * Screen - Screen Configurator (almost useless example of FileRequest use) * * By Kevin Lee Clague * 408 Tortolla Way * San Jose, Ca 95033 * 408-258-9891 work 408-737-5481 * * Copyright (C) 1986. All rights reserved. * * This program is freely distributable as long as this copyright notice * is retained. It intended for personal, non-commercial use. * ***************************************************************************/ #include "screen.h" struct GfxBase *GfxBase; struct IntuitionBase *IntuitionBase; struct Window *window = NULL; struct Screen *screen = NULL; struct IntuiMessage *message; struct RastPort *rp; struct ViewPort *vp; UBYTE QuitScreen = FALSE; extern struct Menu Menu; struct NewScreen NewScreen = { 0,0, /* start position */ 320, 200, 6, /* width, height, depth */ 0,1, /* detail pen, block pen */ NULL, /* HIRES, INTERLACE, SPRITES, DUAL, HAM */ CUSTOMSCREEN, /* screen type */ NULL, /* font to use */ (UBYTE *) "Screen Configurator", /* default title for screen */ NULL /* pointer to extra gadgets */ }; struct NewWindow NewWindow = { 0,0, /* start position */ 320,200, /* width, height */ 0,1, /* detail pen, block pen */ MENUPICK|GADGETDOWN|GADGETUP|REQCLEAR, /* IDCMP flags */ ACTIVATE|BORDERLESS|BACKDROP, /* window flags */ NULL, /* first gadget */ NULL, /* user checkmark */ NULL, /* window title */ NULL, /* pointer to screen */ NULL, /* pointer to superbitmap */ 0,0,320,200, /* sizing */ CUSTOMSCREEN /* type of screen */ }; UBYTE ScreenName[80] = "df0:"; BOOL FileRequest(); main () { if (OpenLibs() | OpenDisp()) CleanUp(); else { ConfScreen(); CleanUp(); } } /* main */ CleanUp() { CloseDisp(); CloseLibs(); } /* CleanUp */ OpenLibs() { IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library",0); if (IntuitionBase == NULL) { printf("Couldn't get Intuition\n"); return(100); } GfxBase = (struct GfxBase *) OpenLibrary("graphics.library",0); if (GfxBase == NULL) { printf("Couldn't get Graphics\n"); return(100); } return(0); } /* OpenLibs */ CloseLibs() { if (IntuitionBase != NULL) CloseLibrary(IntuitionBase); if (GfxBase != NULL) CloseLibrary(GfxBase); } /* CloseLibs */ OpenDisp() { screen = (struct Screen *) OpenScreen(&NewScreen); if (screen == NULL) { printf("Can't open new screen!\n"); exit(200); } NewWindow.Screen = screen; window = (struct Window *) OpenWindow(&NewWindow); if (window == NULL) { CloseScreen(screen); printf("Can't open backdrop window\n"); exit(201); } SetMenuStrip(window, &Menu); rp = window->RPort; vp = &screen->ViewPort; InitFNR(); return(0); } /* opendisp */ CloseDisp() { if (window) { ClearMenuStrip(window); CloseWindow(window); } if (screen) CloseScreen(screen); } /* CloseDisp */ ConfScreen() { ULONG class; USHORT code = 0; struct MenuItem *Item; while (QuitScreen == FALSE) { if ((message=(struct IntuiMessage *) GetMsg(window->UserPort)) == 0L) { Wait(1L<<window->UserPort->mp_SigBit); continue; } class = message->Class; code = message->Code; ReplyMsg(message); if (class == MENUPICK) while (code != MENUNULL) { switch (MENUNUM(code)) { case PROJECTMENU: ScreenProject(code); break; case EDITMENU: EditScreen(code); break; } Item = ItemAddress(&Menu,code); code = Item->NextSelect; } } } /* ConfScreen */ ScreenProject(code) USHORT code; { switch (ITEMNUM(code)) { case LOADITEM: if (FileRequest("Load NewScreen","Load",&ScreenName,window)) printf("You picked %s\n",&ScreenName); else printf("You punted\n"); break; case SAVEITEM: if (FileRequest("Save NewScreen","Save",&ScreenName,window)) printf("You picked %s\n",&ScreenName); else printf("You punted\n"); break; case USEITEM: CloseDisp(); OpenDisp(); break; case QUITITEM: QuitScreen = TRUE; } } /* DoProjectScreen */ EditScreen(code) USHORT code; { switch (ITEMNUM(code)) { case DEPTHITEM: NewScreen.Depth = SUBNUM(code) + 1; AdjustScreenDepth(); break; case VIEWMODEITEM: EditScreenViewModes(code); break; } } /* EditScreen */ EditScreenViewModes(code) USHORT code; { struct MenuItem *Item; Item = ItemAddress((struct Menu *) &Menu,code); if (Item->Flags & TOGGLED11) Item->Flags ^= CHECKED; Item->Flags = Item->Flags ^ TOGGLED11; switch (SUBNUM(code)) { case HIRESSUB: if (!((NewScreen.ViewModes ^= HIRES) & HIRES)) NewScreen.Width = 320; else { NewScreen.Width = 640; AdjustScreenDepth(); } break; case INTERLACESUB: if ((NewScreen.ViewModes ^= INTERLACE) & INTERLACE) NewScreen.Height = 400; else NewScreen.Height = 200; break; case SPRITESSUB: NewScreen.ViewModes ^= SPRITES; break; case DUALPFSUB: NewScreen.ViewModes ^= DUALPF; break; case HAMSUB: NewScreen.ViewModes ^= HAM; } } /* EditScreenViewMode */ AdjustScreenDepth() { /* Adjust the Number of bit planes to a sane number */ USHORT code; struct MenuItem *Item; if (NewScreen.Depth > 4 && NewScreen.ViewModes & HIRES) { code = SHIFTMENU(EDITMENU)|SHIFTITEM(DEPTHITEM)|SHIFTSUB((NewScreen.Depth - 1)); Item = ItemAddress((struct Menu *) &Menu,code); Item->Flags ^= CHECKED; NewScreen.Depth = 4; code = SHIFTMENU(EDITMENU)|SHIFTITEM(DEPTHITEM)|SHIFTSUB((NewScreen.Depth - 1)); Item = ItemAddress((struct Menu *) &Menu,code); Item->Flags ^= CHECKED; } } /* AdjustScreenDepth */ //E*O*F screen.c// echo x - screen.h cat > "screen.h" << '//E*O*F screen.h//' /**************************************************************************** * * Screen - Screen configurator (almost useless example of LoadRequest use) * * By Kevin Lee Clague * 408 Tortolla Way * San Jose, Ca 95033 * 408-258-9891 work 408-737-5481 * * Copyright (C) 1986. All rights reserved. * * This program is freely distributable as long as this copyright notice * is retained. It intended for personal, non-commercial use. * ***************************************************************************/ #include <exec/types.h> #include <exec/tasks.h> #include <exec/libraries.h> #include <exec/devices.h> #include <exec/memory.h> #include <devices/keymap.h> #include <graphics/copper.h> #include <graphics/display.h> #include <graphics/gfxbase.h> #include <graphics/text.h> #include <graphics/view.h> #include <graphics/gels.h> #include <graphics/regions.h> #include <hardware/blit.h> #include <intuition/intuition.h> #include <intuition/intuitionbase.h> #include <stdio.h> #include <libraries/dos.h> #include <workbench/workbench.h> /* Menu Project's, Items */ #define LOADITEM 0 #define SAVEITEM 1 #define USEITEM 2 #define QUITITEM 3 /* Menu: Edit, Item: ViewMode's, SubItems */ #define HIRESSUB 0 #define INTERLACESUB 1 #define SPRITESSUB 2 #define DUALPFSUB 3 #define HAMSUB 4 /* Menu: Edit, Item: Depth's, SubItems */ #define BITPLANE1SUB 0 #define BITPLANES2SUB 1 #define BITPLANES3SUB 2 #define BITPLANES4SUB 3 #define BITPLANES5SUB 4 #define BITPLANES6SUB 5 /* Menu Edit's, Items */ #define DEPTHITEM 0 #define VIEWMODEITEM 1 /* Menu Entries */ #define PROJECTMENU 0 #define EDITMENU 1 #define TOGGLED11 0x0200 //E*O*F screen.h// echo x - screen1.c cat > "screen1.c" << '//E*O*F screen1.c//' /**************************************************************************** * * Screen - Screen configurator (almost useless example of FileRequest()); * * By Kevin Lee Clague * 408 Tortolla Way * San Jose, Ca 95033 * 408-258-9891 work 408-737-5481 * * Copyright (C) 1986. All rights reserved. * * This program is freely distributable as long as this copyright notice * is retained. It intended for personal, non-commercial use. * ***************************************************************************/ #include "screen.h" struct IntuiText ProjectItemIntui[] = { { 0, 1, 0, 0, 2, NULL, (UBYTE *) "Load", NULL }, { 0, 1, 0, 0, 2, NULL, (UBYTE *) "Save", NULL }, { 0, 1, 0, 0, 2, NULL, (UBYTE *) "Use", NULL }, { 0, 1, 0, 0, 2, NULL, (UBYTE *) "Quit", NULL } }; struct MenuItem ProjectItem[] = { { (struct MenuItem *) &ProjectItem[1], 0, 0, 75, 12, ITEMTEXT|COMMSEQ|ITEMENABLED|HIGHCOMP, 0x0, (APTR) &ProjectItemIntui[0], NULL, 'l', NULL, NULL }, { (struct MenuItem *) &ProjectItem[2], 0, 12, 75, 12, ITEMTEXT|COMMSEQ|ITEMENABLED|HIGHCOMP, 0x0, (APTR) &ProjectItemIntui[1], NULL, 's', NULL, NULL }, { (struct MenuItem *) &ProjectItem[3], 0, 24, 75, 12, ITEMTEXT|COMMSEQ|ITEMENABLED|HIGHCOMP, 0x0, (APTR) &ProjectItemIntui[2], NULL, 'u', NULL, NULL }, { NULL, 0, 36, 75, 12, ITEMTEXT|COMMSEQ|ITEMENABLED|HIGHCOMP, 0x0, (APTR) &ProjectItemIntui[3], NULL, 'q', NULL, NULL } }; struct IntuiText DepthSubIntui[] = { { 0, 1, 0, 19, 2, NULL, (UBYTE *) "1", NULL }, { 0, 1, 0, 19, 2, NULL, (UBYTE *) "2", NULL }, { 0, 1, 0, 19, 2, NULL, (UBYTE *) "3", NULL }, { 0, 1, 0, 19, 2, NULL, (UBYTE *) "4", NULL }, { 0, 1, 0, 19, 2, NULL, (UBYTE *) "5", NULL }, { 0, 1, 0, 19, 2, NULL, (UBYTE *) "6", NULL } }; struct MenuItem DepthSub[] = { { (struct MenuItem *) &DepthSub[1], 47, 11, 70, 12, CHECKIT|ITEMTEXT|COMMSEQ|ITEMENABLED|HIGHBOX, 0x3e, (APTR) &DepthSubIntui[0], NULL, '1', NULL, NULL }, { (struct MenuItem *) &DepthSub[2], 47, 23, 70, 12, CHECKIT|ITEMTEXT|COMMSEQ|ITEMENABLED|HIGHBOX, 0x3d, (APTR) &DepthSubIntui[1], NULL, '2', NULL, NULL }, { (struct MenuItem *) &DepthSub[3], 47, 35, 70, 12, CHECKIT|ITEMTEXT|COMMSEQ|ITEMENABLED|HIGHBOX, 0x3b, (APTR) &DepthSubIntui[2], NULL, '3', NULL, NULL }, { (struct MenuItem *) &DepthSub[4], 121, 11, 70, 12, CHECKIT|CHECKED|ITEMTEXT|COMMSEQ|ITEMENABLED|HIGHBOX, 0x37, (APTR) &DepthSubIntui[3], NULL, '4', NULL, NULL }, { (struct MenuItem *) &DepthSub[5], 121, 23, 70, 12, CHECKIT|ITEMTEXT|COMMSEQ|ITEMENABLED|HIGHBOX, 0x2f, (APTR) &DepthSubIntui[4], NULL, '5', NULL, NULL }, { NULL, 121, 35, 70, 12, CHECKIT|ITEMTEXT|COMMSEQ|ITEMENABLED|HIGHBOX, 0x1f, (APTR) &DepthSubIntui[5], NULL, '6', NULL, NULL } }; struct IntuiText ViewModesSubIntui[] = { { 0, 1, 0, 19, 2, NULL, (UBYTE *) "HIRES", NULL }, { 0, 1, 0, 19, 2, NULL, (UBYTE *) "INTERLACE", NULL }, { 0, 1, 0, 19, 2, NULL, (UBYTE *) "SPRITES", NULL }, { 0, 1, 0, 19, 2, NULL, (UBYTE *) "DUALPF", NULL }, { 0, 1, 0, 19, 2, NULL, (UBYTE *) "HAM", NULL } }; struct MenuItem ViewModesSub[] = { { (struct MenuItem *) &ViewModesSub[1], 48, 11, 91, 12, CHECKIT|CHECKED|ITEMTEXT|ITEMENABLED|HIGHBOX, 0x0, (APTR) &ViewModesSubIntui[0], NULL, '\0x0', NULL, NULL }, { (struct MenuItem *) &ViewModesSub[2], 48, 23, 91, 12, CHECKIT|ITEMTEXT|ITEMENABLED|HIGHBOX, 0x0, (APTR) &ViewModesSubIntui[1], NULL, '\0x0', NULL, NULL }, { (struct MenuItem *) &ViewModesSub[3], 48, 35, 91, 12, CHECKIT|ITEMTEXT|ITEMENABLED|HIGHBOX, 0x0, (APTR) &ViewModesSubIntui[2], NULL, '\0x0', NULL, NULL }, { (struct MenuItem *) &ViewModesSub[4], 48, 47, 91, 12, CHECKIT|ITEMTEXT|ITEMENABLED|HIGHBOX, 0x0, (APTR) &ViewModesSubIntui[3], NULL, '\0x0', NULL, NULL }, { NULL, 48, 59, 91, 12, CHECKIT|ITEMTEXT|ITEMENABLED|HIGHBOX, 0x0, (APTR) &ViewModesSubIntui[4], NULL, '\0x0', NULL, NULL } }; struct IntuiText EditItemIntui[] = { { 0, 1, 0, 0, 2, NULL, (UBYTE *) "Depth", NULL }, { 0, 1, 0, 0, 2, NULL, (UBYTE *) "ViewModes", NULL } }; struct MenuItem EditItem[] = { { (struct MenuItem *) &EditItem[1], 0, 0, 72, 12, ITEMTEXT|ITEMENABLED|HIGHCOMP, 0x0, (APTR) &EditItemIntui[0], NULL, '\0x0', (struct MenuItem *) &DepthSub, NULL }, { NULL, 0, 12, 72, 12, ITEMTEXT|ITEMENABLED|HIGHCOMP, 0x0, (APTR) &EditItemIntui[1], NULL, '\0x0', (struct MenuItem *) &ViewModesSub, NULL } }; struct Menu Menu[] = { { (struct Menu *) &Menu[1], 4, 0, 58, 8, 1, (BYTE *) "Project", (struct MenuItem *) &ProjectItem, }, { NULL, 68, 0, 34, 8, 257, (BYTE *) "Edit", (struct MenuItem *) &EditItem, } }; //E*O*F screen1.c// echo Possible errors detected by \'wc\' [hopefully none]: temp=/tmp/shar$$ trap "rm -f $temp; exit" 0 1 2 3 15 cat > $temp <<\!!! 12 27 244 Makefile 57 443 2679 README 930 2795 27024 requester.c 43 245 1684 requester.doc 89 329 2597 requester.h 255 673 6688 screen.c 69 190 1700 screen.h 472 656 6222 screen1.c 1927 5358 48838 total !!! wc Makefile README requester.c requester.doc requester.h screen.c screen.h screen1.c | sed 's=[^ ]*/==' | diff -b $temp - exit 0 -- UUCP: {ihnp4,hplabs,seismo,sun}!amdahl!kim DDD: 408-746-8462 USPS: Amdahl Corp, 1250 E. Arques Av, Sunnyvale, CA 94086 CIS: 76535,25 [ Opinions expressed herein are the author's and should not be construed to reflect the views of Amdahl Corp. ]