home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / online / source / c / compilers / Tickle-4.0.sit.hqx / Tickle-4.0 / src / GetDirectory.c < prev    next >
Text File  |  1993-11-18  |  11KB  |  486 lines

  1.  
  2.  
  3. /*
  4. ** This source code was written by Tim Endres
  5. ** Email: time@ice.com.
  6. ** USMail: 8840 Main Street, Whitmore Lake, MI  48189
  7. **
  8. ** Some portions of this application utilize sources
  9. ** that are copyrighted by ICE Engineering, Inc., and
  10. ** ICE Engineering retains all rights to those sources.
  11. **
  12. ** Neither ICE Engineering, Inc., nor Tim Endres, 
  13. ** warrants this source code for any reason, and neither
  14. ** party assumes any responsbility for the use of these
  15. ** sources, libraries, or applications. The user of these
  16. ** sources and binaries assumes all responsbilities for
  17. ** any resulting consequences.
  18. */
  19.  
  20. #pragma segment GetDirectory
  21.  
  22. #include "tickle.h"
  23. #include "tge.h"
  24. #include <DiskInit.h>
  25. #include <OSEvents.h>
  26.  
  27.  
  28. #define GETDIRECT_DIALOG    6767
  29. #define GETDIRNEW_DIALOG    6766
  30. #define GETDIRHLP_DIALOG    6765
  31. #define prompt_item            11
  32. #define select_item            12
  33. #define help_item            13
  34. #define new_folder_btn        15        /* New Directory Button */
  35.  
  36. #define new_folder_name_item    4
  37.  
  38. #define getInit                -1        /* Initialize */
  39. #define sfHookStay            0
  40.  
  41. static SFReply                getDir_Reply;
  42. static char                    getDir_prompt[256];
  43. /* static short                need_check = 0; */
  44. static char                    save_fName0;
  45. static OSType                save_fType;
  46.  
  47. /* static FILE                *gdhfp = NULL; */
  48.  
  49. #define cm_connect_msg_item        4
  50.  
  51. void
  52. show_getdir_help(parent)
  53. DialogPtr    parent;
  54.     {
  55.     short        itemhit, done;
  56.     DialogPtr    mydialog;
  57.     GrafPtr        saveport;
  58.     Handle        dlogrsrc;
  59.     Rect        *rect_ptr;
  60.     Point        mypt;
  61.     extern pascal Boolean UniversalFilter();
  62.     
  63.     GetPort(&saveport);
  64.     
  65.     InitCursor();
  66.     dlogrsrc = GetResource((ResType)'DLOG', (short)GETDIRHLP_DIALOG);
  67.     if (dlogrsrc != NULL) {
  68.         LoadResource(dlogrsrc);
  69.         rect_ptr = (Rect *) *dlogrsrc;
  70.         mypt.v = parent->portRect.bottom - (8 + (rect_ptr->bottom - rect_ptr->top));
  71.         mypt.h = parent->portRect.left + 8;
  72.         LocalToGlobal(&mypt);
  73.         OffsetRect(rect_ptr, (mypt.h - rect_ptr->left), (mypt.v - rect_ptr->top));
  74.         }
  75.     mydialog = GetNewDialog(GETDIRHLP_DIALOG, NULL, inFront);
  76.     if (mydialog == NULL)
  77.         {
  78.         SysBeep(0);
  79.         return;
  80.         }
  81.     
  82.     SetPort(mydialog);
  83.     TextFont(geneva);
  84.     TextSize(9);
  85.  
  86.     for (done=0; ! done; )    {
  87.         SetPort(mydialog);
  88.         /* FrameButton(mydialog, ok); */
  89.         ModalDialog((ModalFilterProcPtr)UniversalFilter, &itemhit);
  90.         switch (itemhit) {
  91.             case ok:
  92.                 done = 1;
  93.                 break;
  94.             }
  95.         }
  96.     
  97.     DisposDialog(mydialog);
  98.     SetPort(saveport);
  99.     return;
  100.     }
  101.  
  102. void
  103. getdir_new_folder(parent)
  104. DialogPtr    parent;
  105.     {
  106.     short            itemhit, vrefnum, done, create_it = 0, result;
  107.     long            dirid;
  108.     DialogPtr        mydialog;
  109.     GrafPtr            saveport;
  110.     Handle            dlogrsrc;
  111.     Rect            *rect_ptr;
  112.     Point            mypt;
  113.     HParamBlockRec    pb;
  114.     char            pascal_name[256];
  115.  
  116.     extern pascal Boolean UniversalFilter();
  117.     
  118.     GetPort(&saveport);
  119.     
  120.     InitCursor();
  121.     dlogrsrc = GetResource((ResType)'DLOG', (short)GETDIRNEW_DIALOG);
  122.     if (dlogrsrc != NULL)
  123.         {
  124.         LoadResource(dlogrsrc);
  125.         rect_ptr = (Rect *) *dlogrsrc;
  126.         mypt.v = parent->portRect.bottom - (8 + (rect_ptr->bottom - rect_ptr->top));
  127.         mypt.h = parent->portRect.left + 8;
  128.         LocalToGlobal(&mypt);
  129.         OffsetRect(rect_ptr, (mypt.h - rect_ptr->left), (mypt.v - rect_ptr->top));
  130.         }
  131.     mydialog = GetNewDialog(GETDIRNEW_DIALOG, NULL, inFront);
  132.     if (mydialog == NULL)
  133.         {
  134.         SysBeep(0);
  135.         return;
  136.         }
  137.     
  138.     SelIText(mydialog, new_folder_name_item, 0, 1024);
  139.     
  140.     for (done=0; ! done; )
  141.         {
  142.         SetPort(mydialog);
  143.         FrameButton(mydialog, ok);
  144.         ModalDialog((ModalFilterProcPtr)UniversalFilter, &itemhit);
  145.         switch (itemhit)
  146.             {
  147.             case ok:
  148.                 done = 1; create_it = 1;
  149.                 break;
  150.             case cancel:
  151.                 done = 1; create_it = 0;
  152.                 break;
  153.             }
  154.         }
  155.     
  156.     if (create_it)
  157.         {
  158.         SFGetDefault(&dirid, &vrefnum);
  159.  
  160.         MyGetText(mydialog, new_folder_name_item, pascal_name);
  161.         c2pstr(pascal_name);
  162.         
  163.         pb.fileParam.ioCompletion = 0;
  164.         pb.fileParam.ioNamePtr = pascal_name;
  165.         pb.fileParam.ioVRefNum = vrefnum;
  166.         pb.fileParam.ioDirID = dirid;
  167.         
  168.         result = PBDirCreate( (HParmBlkPtr)&pb, FALSE );
  169.         if (result != noErr)
  170.             SysBeep(0);
  171.         }
  172.     
  173.     DisposDialog(mydialog);
  174.     SetPort(saveport);
  175.     
  176.     return;
  177.     }
  178.  
  179. pascal short GetDirHook(item, dialog)
  180. short         item;
  181. DialogPtr    dialog;
  182. {
  183. int        need_check = 0;
  184.  
  185.     switch (item) {
  186.         case getInit:
  187.             /*
  188.             gdhfp = fopen("GETDIR", "a");
  189.             if (gdhfp) {
  190.                 fprintf(gdhfp, "################################################\n");
  191.                 fprintf(gdhfp, "getInit: dialog x%08lX item %d.\n", dialog, item);
  192.                 }
  193.             */
  194.             need_check = 0;
  195.             save_fName0 = getDir_Reply.fName[0];
  196.             save_fType  = getDir_Reply.fType;
  197.             MySetText(dialog, prompt_item, getDir_prompt);
  198.             MyHiliteControl(dialog, select_item, 255);
  199.             break;
  200.         case getOpen:                /* Open or DoubleClick with selected file... */
  201.             /*
  202.             if (gdhfp)
  203.                 fprintf(gdhfp, "getOpen: dialog x%08lX item %d.\n", dialog, item);
  204.             */
  205.             item = sfHookStay;
  206.             need_check = 1;
  207.             break;
  208.         case sfHookOpenFolder:        /* Open or DoubleClick with selected folder... */
  209.             /*
  210.             if (gdhfp)
  211.                 fprintf(gdhfp, "sfHookOpenFolder: dialog x%08lX item %d.\n", dialog, item);
  212.             */
  213.             need_check = 1;
  214.             break;
  215.         case select_item:
  216.             /*
  217.             if (gdhfp)
  218.                 fprintf(gdhfp, "selectItem: dialog x%08lX item %d.\n", dialog, item);
  219.             */
  220.             item = getOpen;
  221.             break;
  222.         case new_folder_btn:
  223.             /*
  224.             if (gdhfp)
  225.                 fprintf(gdhfp, "helpItem: dialog x%08lX item %d.\n", dialog, item);
  226.             */
  227.             getdir_new_folder(dialog);
  228.             item = sfHookRebuildList;
  229.             need_check = 1;
  230.             break;
  231.         case help_item:
  232.             /*
  233.             if (gdhfp)
  234.                 fprintf(gdhfp, "helpItem: dialog x%08lX item %d.\n", dialog, item);
  235.             */
  236.             show_getdir_help(dialog);
  237.             item = sfHookStay;
  238.             break;
  239.         case getCancel:
  240.             /*
  241.             if (gdhfp)
  242.                 fprintf(gdhfp, "getCancel: dialog x%08lX item %d.\n", dialog, item);
  243.             */
  244.             break;
  245.         case sfHookFolderPopUp:
  246.         case getNmList:
  247.         case getScroll:
  248.             /*
  249.             if (gdhfp)
  250.                 fprintf(gdhfp, "sfHookFolderPopUp,NmList,Scroll: dialog x%08lX item %d.\n", dialog, item);
  251.             */
  252.             need_check = 1;
  253.             break;
  254.         case sfHookNullEvent:
  255. #ifdef NEVER_DEFINED
  256.             if (need_check) {
  257.  
  258.                 if (gdhfp)
  259.                     fprintf(gdhfp,
  260.                             "sfHookNullEvent: dialog x%08lX item %d fName [%d]<%.*s> fType '%-4.4s'[%d].\n",
  261.                             dialog, item,
  262.                             getDir_Reply.fName[0], getDir_Reply.fName[0], &getDir_Reply.fName[1],
  263.                             &getDir_Reply.fType, getDir_Reply.fType);
  264.  
  265.                 if (getDir_Reply.fName[0] == '\0' && getDir_Reply.fType == 0)
  266.                     {
  267.                         /* NOTHING Selected... */
  268.                     MyHiliteControl(dialog, select_item, 0);
  269.                     }
  270.                 else if (getDir_Reply.fName[0] == '\0')
  271.                     {
  272.                         /* DIRECTORY */
  273.                     MyHiliteControl(dialog, select_item, 0);
  274.                     }
  275.                 else
  276.                     {
  277.                         /* FILE */
  278.                     MyHiliteControl(dialog, select_item, 255);
  279.                     item = sfHookStay;
  280.                     }
  281.                 
  282.                 save_fName0 = getDir_Reply.fName[0];
  283.                 save_fType  = getDir_Reply.fType;
  284.                 
  285.                 need_check = 0;
  286.                 }
  287.             else
  288.                 {
  289.                 if (save_fName0 != getDir_Reply.fName[0]
  290.                     || save_fType != getDir_Reply.fType)
  291.                     need_check = 1;
  292.                 }
  293. #endif
  294.             break;
  295.         default:    /* Key down's are 1000 + ASCII-code */
  296.             /*
  297.             if (gdhfp)
  298.                 fprintf(gdhfp, "default: dialog x%08lX item %d.\n", dialog, item);
  299.             */
  300.             need_check = 1;
  301.             break;
  302.         }
  303.     
  304.     if (! need_check)
  305.         {
  306.         if (save_fName0 != getDir_Reply.fName[0]
  307.             || save_fType != getDir_Reply.fType)
  308.             need_check = 1;
  309.         }
  310.     if (need_check)
  311.         {
  312.         if (getDir_Reply.fName[0] == '\0' && getDir_Reply.fType == 0)
  313.             {
  314.                 /* NOTHING Selected... */
  315.             MyHiliteControl(dialog, select_item, 0);
  316.             }
  317.         else if (getDir_Reply.fName[0] == '\0')
  318.             {
  319.                 /* DIRECTORY */
  320.             MyHiliteControl(dialog, select_item, 0);
  321.             }
  322.         else
  323.             {
  324.                 /* FILE */
  325.             MyHiliteControl(dialog, select_item, 255);
  326.             /* item = sfHookStay; */
  327.             }
  328.         
  329.         save_fName0 = getDir_Reply.fName[0];
  330.         save_fType  = getDir_Reply.fType;
  331.         need_check = 0;
  332.         }
  333.     
  334.     return item;
  335.     }
  336.  
  337. pascal Boolean NoFiles(pb)
  338. FileParam *pb;
  339. {
  340. #pragma unused (pb)
  341.  
  342.     return false;
  343.     }
  344.  
  345. GetFolderPathName(prompt, path_name, volref, dirid)
  346. char    *prompt;
  347. char    *path_name;
  348. short    *volref;
  349. long    *dirid;
  350. {
  351. #ifdef TCLAPPL
  352. SFTypeList        mytypes;
  353. Point            mypoint;
  354. int                len;
  355. WindowPtr        myWindow;
  356.  
  357.     strcpy(getDir_prompt, prompt);
  358.  
  359.     myWindow = FrontWindow();
  360.     if (WPeek->windowKind == tgeWKind)
  361.         tge_activate(myWindow, 0);
  362.  
  363.     /* gdhfp = (FILE *)0; */
  364.  
  365.     mypoint.h = mypoint.v = 75;
  366.     SFPGetFile(mypoint, "\p", NoFiles, -1, mytypes, GetDirHook,
  367.                     &getDir_Reply, GETDIRECT_DIALOG, (ModalFilterProcPtr)0);
  368.     /*
  369.     if (gdhfp) {
  370.         fclose(gdhfp);
  371.         gdhfp = (FILE *)0;
  372.         }
  373.     */
  374.     if (getDir_Reply.good) {
  375.  
  376.         /*
  377.         Feedback("GOOD: fName '%.*s' fType '%-4.4s'[%ld] vRef %d V %d D %ld  ",
  378.             getDir_Reply.fName[0], &getDir_Reply.fName[1],
  379.             &getDir_Reply.fType, getDir_Reply.fType,
  380.             getDir_Reply.vRefNum, WDVolRef(getDir_Reply.vRefNum), WDDirID(getDir_Reply.vRefNum));
  381.         */
  382.         
  383.         if (getDir_Reply.fName[0] != '\0'/*getDir_Reply.fType == 0*/) {
  384.             *volref = WDVolRef(getDir_Reply.vRefNum);
  385.             *dirid = WDDirID(getDir_Reply.vRefNum);
  386.             pathname(path_name, getDir_Reply.vRefNum);
  387.             }
  388.         else {
  389.             dirpathname(path_name, getDir_Reply.vRefNum, getDir_Reply.fType/*cpb.dirInfo.ioDrParID*/);
  390.             *volref = getDir_Reply.vRefNum;
  391.             *dirid = getDir_Reply.fType/*cpb.dirInfo.ioDrParID*/;
  392.             }
  393.  
  394.         len = strlen(path_name);
  395.         if (path_name[len - 1] == ':')
  396.             path_name[len - 1] = '\0';    /* Drop Colon */
  397.                 
  398.         return 1;
  399.         }
  400.     else
  401.         return 0;
  402. #else
  403. #pragma unused (prompt, path_name, volref, dirid)
  404.  
  405.         return 0;
  406. #endif
  407.     }
  408.  
  409. #ifdef NEVER_DEFINED
  410.  
  411.  
  412. #define getInit        -1        /* Initialize */
  413. #define getMenu        102        /* Folder Menu Mouse */
  414. #define getFolder    103        /* Open Folder */
  415. #define getUseDir    11        /* Use This Directory Button */
  416.  
  417.  
  418. pascal short DHook(item, dialog)
  419. short item;
  420. DialogPtr dialog;
  421. {
  422. #pragma unused (dialog)
  423.  
  424.     if (item == getUseDir)
  425.         return getOpen;
  426.     
  427.     return item;
  428.     }
  429.  
  430. pascal Boolean NoFiles(pb)
  431. FileParam *pb;
  432. {
  433. #pragma unused (pb)
  434.  
  435.     return true;
  436.     }
  437.  
  438. GetFolderPathName(path_name, volref, dirid)
  439. char    *path_name;
  440. short    *volref;
  441. long    *dirid;
  442. {
  443. SFReply            myreply;
  444. SFTypeList        mytypes;
  445. CInfoPBRec        cpb;
  446. Point            mypoint;
  447. int                len;
  448. WindowPtr        myWindow;
  449.  
  450.     myWindow = FrontWindow();
  451.     if (WPeek->windowKind == tgeWKind)
  452.         tge_activate(myWindow, 0);
  453.  
  454.     mypoint.h = mypoint.v = 75;
  455.     SFPGetFile(mypoint, "\p", NoFiles, -1, mytypes, DHook,
  456.                 &myreply, get_folder_dialog, (ModalFilterProcPtr)0);
  457.     
  458.     if (myreply.good) {
  459.         if (myreply.fType == 0) {
  460.             *volref = WDVolRef(myreply.vRefNum);
  461.             *dirid = WDDirID(myreply.vRefNum);
  462.             pathname(path_name, myreply.vRefNum);
  463.             }
  464.         else {
  465.             cpb.dirInfo.ioVRefNum = myreply.vRefNum;
  466.             cpb.dirInfo.ioNamePtr = NULL;
  467.             cpb.dirInfo.ioDrDirID = myreply.fType;
  468.             cpb.dirInfo.ioFDirIndex = -1;
  469.             PBGetCatInfo(&cpb, FALSE);            
  470.             dirpathname(path_name, myreply.vRefNum, cpb.dirInfo.ioDrParID);
  471.             *volref = myreply.vRefNum;
  472.             *dirid = cpb.dirInfo.ioDrParID;
  473.             }
  474.  
  475.         len = strlen(path_name);
  476.         if (path_name[len - 1] == ':')
  477.             path_name[len - 1] = '\0';    /* Drop Colon */
  478.         
  479.         return 1;
  480.         }
  481.     else
  482.         return 0;
  483.     }
  484.  
  485. #endif
  486.