home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Mac OS SDK / Dev.CD Jul 99 SDK1.toast / Development Kits / Mac OS / Telephone Manager / Stiletto Sources / Sources / ModuleWindow.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-04  |  21.6 KB  |  859 lines  |  [TEXT/MPS ]

  1. /************************************************************************************************/
  2. /*                                                                                                */
  3. /*    Program Name:    Stiletto                                                                    */
  4. /*                                                                                                */
  5. /*    File Name:        ModuleWindow.c                                                                */
  6. /*                                                                                                */
  7. /*    © Apple Computer, Inc. 1991-1995                                                            */
  8. /*    All Rights Reserved                                                                            */
  9. /*                                                                                                */
  10. /*    Revision History:                                                                            */
  11. /*                                                                                                */
  12. /*        Date        Who                    Modification                                            */
  13. /*                                                                                                */
  14. /*        1991-08-17    Chris Halim            Original version                                        */
  15. /*        1995-06-26    Jaakko Railo        Version 2.0                                                */
  16. /*                                                                                                */
  17. /************************************************************************************************/
  18.  
  19. /****************************************** DESCRIPTION ******************************************
  20.  
  21. *************************************************************************************************/
  22.  
  23. /******************************************** HEADERS *******************************************/
  24.  
  25. #include "Errors.h"
  26. #include "Resources.h"
  27. #include "Strings.h"
  28. #include "ToolUtils.h"
  29.  
  30. #include "Constants.h"
  31. #include "LogWindow.h"
  32. #include "ModuleWindow.h"
  33. #include "Preferences.h"
  34. #include "TestModule.h"
  35. #include "Utilities.h"
  36.  
  37. /****************************************** DEFINITIONS *****************************************/
  38.  
  39. /****************************************** PROTOTYPES ******************************************/
  40.  
  41. void    AttachModuleWindowControls (ModuleWindowPtr moduleWindow);
  42.  
  43. Boolean    DoModuleWindowKeyDown (const EventRecord *theEvent);
  44. Boolean    DoModuleWindowMouseDown (const EventRecord *theEvent);
  45. void    DoModuleWindowClick (WindowPtr theWindow, const EventRecord * theEvent);
  46. void    DoModuleWindowActivate (WindowPtr theWindow, Boolean becomingActive);
  47. void    DoModuleWindowUpdate (WindowPtr theWindow);
  48. void    DoModuleWindowOSEvent (const EventRecord *theEvent);
  49. void     DoModuleWindowSuspend (Boolean doClipConvert);
  50. void     DoModuleWindowResume (Boolean doClipConvert);
  51.  
  52. void    ChangeTestDirAlias (FSSpecPtr theFile, ModuleWindowPtr moduleWindow);
  53. OSErr    CreateTestDirAlias (ModuleWindowPtr moduleWindow); 
  54.  
  55. void    DisplaySelectedNames (ModuleWindowPtr moduleWindow);
  56.  
  57. OSErr    GetPathToChild (long * dirID, FSSpecPtr target);
  58. void    BuildNameList (ModuleWindowPtr moduleWindow);
  59.  
  60. void    ExecuteSelectedNames (ModuleWindowPtr moduleWindow);
  61.  
  62. void    DumpModuleRecord (ModuleWindowPtr moduleWindow);
  63.  
  64. /******************************************** GLOBALS *******************************************/
  65.  
  66. extern    LogWindowPtr        gLogWindow;
  67.  
  68. extern    DlgHookYDUPP        gGetDirDialogHookUPP;
  69. extern    ModalFilterYDUPP    gGetDirModalFilterUPP;
  70.  
  71. /************************************************************************************************/
  72. /************************************************************************************************/
  73.  
  74.  
  75. #pragma segment ModuleWindow
  76. short    CreateModuleWindow (ModuleWindowPtr * moduleWindow, const Rect * windowRect)
  77. {
  78.     WindowPtr    savedPort;
  79.     Ptr            tPtr;
  80.     short        height;
  81.     OSErr        errCode;
  82.     RgnHandle    grayRgn;
  83.     
  84.     /**
  85.      **        Create storage for the window record. We will pass this to GetNewWindow().
  86.      **
  87.      **/
  88.      
  89.     tPtr = NewPtrClear (sizeof (ModuleWindowRec));
  90.     if (tPtr == nil) {
  91.         AlertUser ("\pNot enough memory to create module window !", MemError ());
  92.         return (-1);
  93.     }
  94.     
  95.     /**
  96.      **        Get a "WIND" resource for the module window.
  97.      **
  98.      **/
  99.      
  100.      if (HasColorQD())
  101.         *moduleWindow = (ModuleWindowPtr) GetNewCWindow (rModuleWIND, tPtr, (WindowPtr)(-1L));
  102.     else
  103.         *moduleWindow = (ModuleWindowPtr) GetNewWindow (rModuleWIND, tPtr, (WindowPtr)(-1L));
  104.         
  105.     if (*moduleWindow == nil) {
  106.         AlertUser ("\pUnable to get a WIND resource for module window!", ResError ());
  107.         DisposPtr (tPtr);
  108.         tPtr = nil;
  109.         return (-1);
  110.     }
  111.     
  112.     /**
  113.      **        Move and resize the window according to the rect passed in windowRect.
  114.      **        Also make sure that the window is within the screen boundary.
  115.      **
  116.      **/
  117.      
  118.     grayRgn = GetGrayRgn ();
  119.     if (windowRect && !EmptyRect(windowRect) && RectInRgn (windowRect, grayRgn)) {
  120.         MoveWindow ((WindowPtr) *moduleWindow, windowRect->left, windowRect->top, false);
  121.         height = windowRect->bottom - windowRect->top;
  122.         SizeWindow ((WindowPtr) *moduleWindow, windowRect->right - windowRect->left,
  123.                         height, true);
  124.     }
  125.     
  126.     /**
  127.      **        Set the window's characteristics.
  128.      **
  129.      **/
  130.      
  131.     GetPort (&savedPort);
  132.     SetPort ((WindowPtr) *moduleWindow);
  133.     TextSize (9);
  134.     SetPort (savedPort);
  135.     
  136.     AttachModuleWindowControls (*moduleWindow);
  137.  
  138.     ShowWindow ((WindowPtr) *moduleWindow);
  139.     
  140.     if ((errCode = CreateTestDirAlias (*moduleWindow)) != noErr)
  141.         PutLine (gLogWindow, "### Cannot create alias record : %d", errCode);
  142.     
  143.     if (CreateNameList (*moduleWindow) != noErr) 
  144.         PutLine (gLogWindow, "### Cannot create the name list : %d", MemError ());
  145.         
  146.     return (noErr);
  147. }
  148.  
  149.  
  150. #pragma segment ModuleWindow
  151. void    DisposeModuleWindow (ModuleWindowPtr moduleWindow)
  152. {
  153.     if (moduleWindow) {
  154.         if (moduleWindow->fNameList != nil)
  155.             LDispose (moduleWindow->fNameList);
  156.         
  157.         SaveToPrefFile ((Handle) moduleWindow->fTestDirAlias, rAliasType, rTestDirALIS);
  158.         
  159.         if (moduleWindow->fTestDirAlias != nil)
  160.             DisposHandle ((Handle) moduleWindow->fTestDirAlias);
  161.         
  162.         DisposeWindow ((WindowPtr) moduleWindow);
  163.     }
  164. }
  165.  
  166.  
  167. #pragma segment ModuleWindow
  168. void    AttachModuleWindowControls (ModuleWindowPtr moduleWindow)
  169. {
  170. #pragma unused (moduleWindow)
  171. }
  172.  
  173.  
  174. #pragma segment ModuleWindow
  175. Boolean    IsHandledByModuleWindow (ModuleWindowPtr moduleWindow, const EventRecord * theEvent)
  176. {
  177.     WindowPtr        theWindow;
  178.     Boolean            wasHandled = false;
  179.     
  180.     if (moduleWindow != nil) {
  181.         
  182.         switch ( theEvent->what ) {
  183.             case mouseDown:
  184.                 (void) FindWindow(theEvent->where, &theWindow);
  185.                 if (theWindow == (WindowPtr) moduleWindow) {
  186.                     wasHandled = DoModuleWindowMouseDown (theEvent);
  187.                 }
  188.                 break;
  189.                             
  190.             case activateEvt:
  191.                 if ((ModuleWindowPtr) theEvent->message == moduleWindow) {
  192.                     DoModuleWindowActivate ((WindowPtr) moduleWindow, (theEvent->modifiers & activeFlag) != 0);
  193.                     wasHandled = true;
  194.                 }
  195.                 break;
  196.                 
  197.             case updateEvt:
  198.                 if ((ModuleWindowPtr) theEvent->message == moduleWindow) {
  199.                     DoModuleWindowUpdate ((WindowPtr) moduleWindow);
  200.                     wasHandled = true;
  201.                 }
  202.                 break;
  203.                 
  204.             case osEvt:
  205.                 if ((ModuleWindowPtr) FrontWindow () == moduleWindow) {
  206.                     DoModuleWindowOSEvent (theEvent);
  207.                     wasHandled = false;
  208.                 }
  209.                 break;
  210.                 
  211.             case keyDown:
  212.             case autoKey:
  213.                 if ((ModuleWindowPtr) FrontWindow() == moduleWindow)
  214.                     wasHandled = DoModuleWindowKeyDown (theEvent);
  215.                 break;
  216.             
  217.             default :
  218.                 wasHandled = false;
  219.         }        
  220.     }
  221.     
  222.     return (wasHandled);
  223. }
  224.  
  225.  
  226. #pragma segment ModuleWindow
  227. Boolean    DoModuleWindowKeyDown (const EventRecord *theEvent)
  228. {    
  229.     char            key;
  230.     Boolean            wasHandled = false;
  231.     ModuleWindowPtr    moduleWindow = (ModuleWindowPtr) FrontWindow ();
  232.  
  233.     key = theEvent->message & charCodeMask;
  234.     if ( theEvent->modifiers & cmdKey )    {        // Command key is down
  235.         wasHandled = false;
  236.     } else {
  237.         switch (key) {
  238.             case leftArrowKey :
  239.             case upArrowKey :
  240.                 SelectPreviousCell (moduleWindow->fNameList);
  241.                 wasHandled = true;
  242.                 break;
  243.                 
  244.             case rightArrowKey :
  245.             case downArrowKey :
  246.                 SelectNextCell (moduleWindow->fNameList);
  247.                 wasHandled = true;
  248.                 break;
  249.                 
  250.             case crKey :
  251.             case enterKey :
  252.                 ExecuteSelectedNames (moduleWindow);
  253.                 wasHandled = true;
  254.                 break;    
  255.             
  256.             case 'd' :
  257.                 DumpModuleRecord (moduleWindow);
  258.                 wasHandled = true;
  259.                 break;
  260.             
  261.             case 'c' :
  262.                 if (GetNewTestDirAlias (moduleWindow))
  263.                     (void) CreateNameList (moduleWindow);
  264.                 wasHandled = true;
  265.                 break;
  266.             
  267.             case 'r' :
  268.                 (void) CreateNameList (moduleWindow);
  269.                 wasHandled = true;
  270.                 break;
  271.                 
  272.             default :
  273.                 wasHandled = false;
  274.         }
  275.     }
  276.     
  277.     return (wasHandled);
  278. }
  279.  
  280.  
  281. #pragma segment ModuleWindow
  282. Boolean    DoModuleWindowMouseDown (const EventRecord *theEvent)
  283. {
  284.     short        part;
  285.     WindowPtr    theWindow;
  286.     Boolean        wasHandled = false;
  287.     
  288.     part = FindWindow(theEvent->where, &theWindow);
  289.     switch ( part ) {            
  290.         case inContent:
  291.             if ( theWindow != FrontWindow() )
  292.                 SelectWindow(theWindow);
  293.  
  294.             DoModuleWindowClick (theWindow, theEvent);
  295.             
  296.             wasHandled = true;
  297.             break;
  298.         
  299.         default :
  300.             wasHandled = false;
  301.     }
  302.     
  303.     return (wasHandled);
  304. }
  305.  
  306.  
  307. #pragma segment ModuleWindow
  308. void    DoModuleWindowClick (WindowPtr theWindow, const EventRecord * theEvent)
  309. {
  310.     Point            mousePos;
  311.     Boolean            dblClicked;
  312.     WindowPtr        savedPort;
  313.     short            part, value;
  314.     ListHandle        nameList    = ((ModuleWindowPtr) theWindow)->fNameList;
  315.     ControlHandle    theControl;
  316.     
  317.     GetPort    (&savedPort);
  318.     SetPort (theWindow);
  319.     
  320.     mousePos = theEvent->where;
  321.     GlobalToLocal (&mousePos);
  322.  
  323.     if (nameList != nil) {
  324.         dblClicked = LClick (mousePos, theEvent->modifiers, nameList);
  325.         
  326.         if (dblClicked == true) {
  327.             ExecuteSelectedNames ((ModuleWindowPtr) theWindow);
  328.         }
  329.     }
  330.     
  331.     part = FindControl (mousePos, theWindow, &theControl);
  332.     switch (part) {
  333.         case 0 :        // invisible or inactive control was clicked
  334.             break;
  335.         
  336.         case inThumb :
  337.             break;
  338.         
  339.         case inButton :
  340.             part = TrackControl (theControl, mousePos, nil);
  341.             if (part != 0) {
  342.                 switch (GetCRefCon (theControl)) {
  343.                 }
  344.             }
  345.             break;
  346.         
  347.         case inCheckBox:
  348.             part = TrackControl (theControl, mousePos, nil);
  349.             if (part != 0) {
  350.                 value = (GetCtlValue (theControl)) ? false : true;
  351.                 
  352.                 switch (GetCRefCon (theControl)) {
  353.                 }
  354.                 
  355.                 SetCtlValue (theControl, value);
  356.             }
  357.             break;
  358.     }
  359.     
  360.     SetPort (savedPort);
  361. }
  362.  
  363.  
  364. #pragma segment ModuleWindow
  365. void    DoModuleWindowActivate (WindowPtr theWindow, Boolean becomingActive)
  366. {
  367.     WindowPtr        savedPort;
  368.     
  369.     GetPort (&savedPort);
  370.     SetPort (theWindow);
  371.     
  372.     if (((ModuleWindowPtr) theWindow)->fNameList != nil)
  373.         LActivate (becomingActive, ((ModuleWindowPtr) theWindow)->fNameList);
  374.     
  375.     SetPort (savedPort);
  376. }
  377.  
  378.  
  379. #pragma segment ModuleWindow
  380. void    DoModuleWindowUpdate (WindowPtr theWindow)
  381. {
  382.     WindowPtr    savedPort;
  383.     Rect        tRect;
  384.     ListHandle    nameList    = ((ModuleWindowPtr) theWindow)->fNameList;
  385.     
  386.     GetPort (&savedPort);
  387.     SetPort (theWindow);
  388.     
  389.     BeginUpdate (theWindow);    
  390.     if ( ! EmptyRgn (theWindow->visRgn) )
  391.     {
  392. //        EraseRect(&theWindow->portRect);
  393.         UpdtControl (theWindow, theWindow->visRgn);
  394.         
  395.         if (nameList != nil) {
  396.             LUpdate (theWindow->visRgn, nameList);
  397.             
  398.             tRect = (*nameList)->rView;
  399.             InsetRect (&tRect, -1, -1);
  400.             FrameRect (&tRect);
  401.         }
  402.     }
  403.     EndUpdate (theWindow);
  404.     
  405.     SetPort (savedPort);
  406. }
  407.  
  408.  
  409. #pragma segment ModuleWindow
  410. void    DoModuleWindowOSEvent (const EventRecord *theEvent)
  411. {
  412.     Boolean doConvert;
  413.     unsigned char evType;
  414.  
  415.     evType = (unsigned char) (theEvent->message >> 24) & 0x00ff; // Get the high byte.
  416.     switch (evType) {                     // The high byte of message is the type of event.
  417.         case suspendResumeMessage :
  418.             doConvert = (theEvent->message & convertClipboardFlag) != 0;
  419.             
  420.             if ((theEvent->message & resumeFlag) == 0)
  421.               DoModuleWindowSuspend (doConvert);
  422.               
  423.             else DoModuleWindowResume (doConvert);
  424.             break;
  425.     }
  426. }
  427.  
  428.  
  429. #pragma segment ModuleWindow
  430. void     DoModuleWindowSuspend (Boolean doClipConvert)
  431. {
  432. #pragma unused (doClipConvert)
  433.  
  434.     DoModuleWindowActivate (FrontWindow(), false);
  435. }
  436.  
  437.  
  438. #pragma segment ModuleWindow
  439. void     DoModuleWindowResume (Boolean doClipConvert)
  440. {
  441. #pragma unused (doClipConvert)
  442.  
  443.     WindowPtr    theWindow = FrontWindow ();
  444.     CursHandle     watch = GetCursor(watchCursor);
  445.     
  446.     if (watch != nil)
  447.         SetCursor (*watch);
  448.     
  449.     (void) CreateNameList ((ModuleWindowPtr) theWindow);
  450.     DoModuleWindowActivate (theWindow, true);
  451.     
  452.     if (watch != nil)
  453.         ReleaseResource ((Handle) watch);
  454.     
  455.     SetCursor (&qd.arrow);
  456. }
  457.  
  458.  
  459. #pragma segment ModuleWindow
  460. pascal Boolean    GetDirModalFilter (DialogPtr theDialog, EventRecord* theEvent, short* itemHit,  Ptr data)
  461. {
  462. #pragma unused (theDialog, data)
  463.  
  464.     Boolean                wasHandled = false;
  465.     char                key;
  466.             
  467.     switch (theEvent->what) {
  468.         case keyDown :
  469.             key = theEvent->message & charCodeMask;
  470.             if ( theEvent->modifiers & cmdKey )            // Command key is down
  471.                 if (key == downArrowKey) {
  472.                     *itemHit = kOpen;
  473.                     wasHandled = true;
  474.                 }
  475.                 else if (key == upArrowKey) {
  476.                     *itemHit = sfHookGoToParent;
  477.                     wasHandled = true;
  478.                 }
  479.             break;
  480.  
  481.         case mouseDown :
  482.             break;             
  483.     }
  484.  
  485.     return (wasHandled);
  486. }
  487.  
  488.  
  489. #pragma segment ModuleWindow
  490. pascal short    GetDirDialogHook (short item, DialogPtr theDialog, Ptr data)
  491. {
  492. #pragma unused (theDialog)
  493.     
  494.     short                itemType;
  495.     Handle                itemHandle;
  496.     Rect                box;
  497.     StandardFileReply    *theSFRPtr = (StandardFileReply*) data;
  498.     static Boolean        wasFile   = true;
  499.     static Boolean        firstTime;
  500.  
  501.     switch (item) {
  502.         case sfHookNullEvent :
  503.             if (theSFRPtr->sfIsFolder || theSFRPtr->sfIsVolume) {
  504.                 if (wasFile || firstTime) {
  505.                     GetDItem (theDialog, sfItemOpenButton, &itemType, &itemHandle, &box);
  506.                     setctitle((ControlHandle) itemHandle, "Directory"); 
  507.     
  508.                     GetDItem (theDialog, kOpen, &itemType, &itemHandle, &box);
  509.                     HiliteControl ((ControlHandle) itemHandle, 0x0); 
  510.                     
  511.                     wasFile   = false;
  512.                     firstTime = false;
  513.                 }
  514.             } 
  515.             else{
  516.                 if ((! wasFile) || firstTime) {
  517.                     GetDItem (theDialog, sfItemOpenButton, &itemType, &itemHandle, &box);
  518.                     setctitle((ControlHandle) itemHandle, "Open"); 
  519.     
  520.                     GetDItem (theDialog, kOpen, &itemType, &itemHandle, &box);
  521.                     HiliteControl ((ControlHandle) itemHandle, 0xFF); 
  522.                     
  523.                     wasFile   = true;
  524.                     firstTime = false;
  525.                 }
  526.             } 
  527.             break;
  528.             
  529.         case sfHookFirstCall :
  530.             firstTime = true; 
  531.             break;
  532.             
  533.         case sfItemFileListUser :
  534.             break;
  535.             
  536.         case sfHookOpenFolder :
  537.             item = sfItemOpenButton;
  538.             break;
  539.             
  540.         case kOpen :
  541.             item = sfHookOpenFolder;
  542.             break;
  543.     }
  544.     
  545.     return (item);
  546. }
  547.  
  548.  
  549. #pragma segment ModuleWindow
  550. AliasHandle    GetNewTestDirAlias (ModuleWindowPtr moduleWindow)
  551. {
  552.     AliasHandle            aliasHandle = nil;
  553.     StandardFileReply    theSFR;
  554.     SFTypeList            theTypeList;
  555.     Point                where;
  556.     OSErr                errCode;
  557.     
  558.     theTypeList[0] = kModuleType;
  559.     
  560.     SetPt (&where, -1, -1);
  561.     CustomGetFile (nil, 1, theTypeList, &theSFR, rGetDirectoryDLOG, where,
  562.                 gGetDirDialogHookUPP, gGetDirModalFilterUPP, nil, nil, (Ptr) &theSFR);
  563.     
  564.     if (theSFR.sfGood)
  565.     {
  566.         if (! (theSFR.sfIsFolder || theSFR.sfIsVolume)) {  // set up to its parent
  567.             errCode = FSMakeFSSpec (theSFR.sfFile.vRefNum, theSFR.sfFile.parID, "\p", &theSFR.sfFile);
  568.             if ((errCode) != noErr)
  569.                 PutLine (gLogWindow, "### FSMakeFSSpec failed : %d", errCode);
  570.         }
  571.         
  572.         ChangeTestDirAlias (&theSFR.sfFile, moduleWindow);
  573.         aliasHandle = moduleWindow->fTestDirAlias;
  574.     }
  575.         
  576.     return (aliasHandle);
  577. }
  578.  
  579.  
  580. #pragma segment ModuleWindow
  581. void    ChangeTestDirAlias (FSSpecPtr theFile, ModuleWindowPtr moduleWindow)
  582. {
  583.     AliasHandle    aliasHandle = nil;
  584.     OSErr        errCode = noErr;
  585.     
  586.     if (moduleWindow->fTestDirAlias != nil) {
  587.         DisposHandle ((Handle) moduleWindow->fTestDirAlias);
  588.         moduleWindow->fTestDirAlias = nil;
  589.     }
  590.     
  591.     errCode = NewAlias (nil, theFile, &aliasHandle);
  592.     if (aliasHandle == nil)
  593.         PutLine (gLogWindow, "### NewAlias failed : %d", errCode);
  594.         
  595.     moduleWindow->fTestDirAlias = aliasHandle;
  596. }
  597.  
  598.  
  599. #pragma segment ModuleWindow
  600. OSErr    CreateTestDirAlias (ModuleWindowPtr moduleWindow)
  601. {
  602. /**
  603.  **        This function initializes moduleWindow->fTestDirAlias.
  604.  **        First it attempts to get an 'alis' resource from the pref file.
  605.  **        If successful, it will attach it resource handle to fTestDirAlias.
  606.  **        If the resource is not found, it creates a new alias by first
  607.  **        calling GetNewTestDirAlias(). If this calls return zero, it will 
  608.  **        create a new alias record based on the current working directory.
  609.  **
  610.  **/
  611.  
  612.     AliasHandle    aliasHandle;
  613.     FSSpec        target;
  614.     long        dirID, procID = 0;
  615.     short        vRefNum = 0;
  616.     OSErr        errCode = noErr;
  617.     
  618.     if ((aliasHandle = (AliasHandle) GetFromPrefFile (rAliasType, rTestDirALIS)) == nil) {
  619.         aliasHandle = GetNewTestDirAlias (moduleWindow);
  620.         if (aliasHandle == nil) {
  621.             if ((errCode = GetWDInfo (0, &vRefNum, &dirID, &procID)) != noErr)
  622.                 PutLine (gLogWindow, "### GetWDInfo failed : %d", errCode);
  623.                 
  624.             if ((errCode = FSMakeFSSpec (vRefNum, dirID, nil, &target)) != noErr)
  625.                 PutLine (gLogWindow, "### FSMakeFSSpec failed : %d", errCode);
  626.                 
  627.             if ((errCode = NewAlias (nil, &target, &aliasHandle)) != noErr)
  628.                 PutLine (gLogWindow, "### NewAlias failed : %d", errCode);
  629.         }
  630.         AddToPrefFile ((Handle) aliasHandle, rAliasType, rTestDirALIS, "\p");    
  631.     }
  632.  
  633.     moduleWindow->fTestDirAlias = aliasHandle;
  634.     
  635.     return (errCode);
  636. }
  637.  
  638.  
  639. #pragma segment ModuleWindow
  640. OSErr    CreateNameList (ModuleWindowPtr moduleWindow)
  641. {
  642.     Rect        rView, dataBounds;
  643.     Point        cSize;
  644.     GrafPtr        savedPort;
  645.     FontInfo    grafPortFontInfo;
  646.     short        lineHeight, result = noErr;
  647.     Rect        **rectHandle;
  648.     
  649.     if (moduleWindow->fNameList != nil) {
  650.         LDispose (moduleWindow->fNameList);
  651.         moduleWindow->fNameList = nil;
  652.     }
  653.         
  654.     GetPort (&savedPort);
  655.     SetPort ((WindowPtr) moduleWindow);
  656.     
  657.     GetFontInfo (&grafPortFontInfo);
  658.     lineHeight = grafPortFontInfo.ascent
  659.                     + grafPortFontInfo.descent
  660.                     + grafPortFontInfo.leading;
  661.     
  662.     SetRect (&dataBounds, 0, 0, 1, 0);            // one-column list
  663.     
  664.     SetPt (&cSize, 0, 0);                        // use default cell size
  665.  
  666.     rectHandle = (Rect **) Get1Resource ('RECT', rFileListRECT);
  667.     if (rectHandle) {
  668.         rView = **rectHandle;
  669.         rView.right -= 15;
  670.         ReleaseResource ((Handle) rectHandle);
  671.     
  672.         if (moduleWindow->fNameList = lnew (&rView, &dataBounds, &cSize, 0, (WindowPtr)moduleWindow,
  673.                 true, false, false, true)) {        
  674.         
  675.             LActivate (false, moduleWindow->fNameList);
  676.             
  677.             LDoDraw (false, moduleWindow->fNameList);
  678.             BuildNameList (moduleWindow);
  679.             LDoDraw (true, moduleWindow->fNameList);
  680.             
  681.             InvalRect (&rView);
  682.         }
  683.         else
  684.             result = -1;
  685.     }
  686.     else {
  687.         AlertUser ("\pUnable to get a RECT resource for module window!", ResError ());
  688.         result = (-1);
  689.     }
  690.  
  691.     SetPort (savedPort);
  692.     
  693.     return (result);
  694. }
  695.  
  696.  
  697. #pragma segment ModuleWindow
  698. void    DisplaySelectedNames (ModuleWindowPtr moduleWindow)
  699. {
  700.     Cell        tCell;
  701.  
  702.     SetPt (&tCell, 0, 0);
  703.     while (LGetSelect (true, &tCell, moduleWindow->fNameList)) {
  704.     
  705.         PutLine (gLogWindow, "row = %d", tCell.v);
  706.         
  707.         if (! LNextCell (true, true, &tCell, moduleWindow->fNameList))
  708.             break;
  709.     }
  710. }
  711.  
  712.  
  713. #pragma segment ModuleWindow
  714. OSErr    GetPathToChild (long * dirID, FSSpecPtr target)
  715. {
  716.     CInfoPBRec    paramBlock;
  717.     OSErr        errCode;
  718.     
  719.     paramBlock.hFileInfo.ioCompletion    = nil;
  720.     paramBlock.hFileInfo.ioNamePtr        = (StringPtr) &target->name;
  721.     paramBlock.hFileInfo.ioVRefNum        = target->vRefNum;
  722.     paramBlock.hFileInfo.ioFDirIndex    = 0;
  723.     paramBlock.hFileInfo.ioDirID        = target->parID;
  724.     
  725.     errCode = PBGetCatInfo (¶mBlock, false);
  726.     if (errCode == noErr) {
  727.         *dirID = paramBlock.hFileInfo.ioDirID;
  728.     }
  729.     
  730.     return (errCode);
  731. }
  732.  
  733.  
  734. #pragma segment ModuleWindow
  735. void    BuildNameList (ModuleWindowPtr moduleWindow)
  736. {
  737.     short        index = 1, row = 0;
  738.     Cell        tCell;
  739.     OSErr        errCode;
  740.     Boolean        wasChanged, done = false;
  741.     FSSpec        target;
  742.     CInfoPBRec    paramBlock;
  743.     long        dirID;
  744.  
  745.     errCode = ResolveAlias (nil, moduleWindow->fTestDirAlias, &target, &wasChanged);
  746.     if (errCode == noErr)
  747.     {
  748.         if (wasChanged)
  749.             PutLine (gLogWindow, "moduleWindow->fTestDirAlias was changed");
  750.         
  751.         if ((errCode = GetPathToChild (&dirID, &target)) == noErr)
  752.         {
  753.             while (! done)
  754.             {
  755.                 paramBlock.hFileInfo.ioCompletion    = nil;
  756.                 paramBlock.hFileInfo.ioNamePtr        = &target.name;
  757.                 paramBlock.hFileInfo.ioVRefNum        = target.vRefNum;
  758.                 paramBlock.hFileInfo.ioFDirIndex    = index++;
  759.                 paramBlock.hFileInfo.ioDirID        = dirID;
  760.                 
  761.                 errCode = PBGetCatInfo (¶mBlock, false);
  762.                 if (errCode == noErr) {
  763.                     if ((paramBlock.hFileInfo.ioFlAttrib & (1 << 4)) 
  764.                         || (((FInfo*) ¶mBlock.hFileInfo.ioFlFndrInfo)->fdType!=kModuleType))
  765.                         ;
  766.                     else {
  767.                         SetPt (&tCell, 0, row);
  768.                         LAddRow (1, row, moduleWindow->fNameList);
  769.                         LSetCell (&target.name[1], target.name[0], tCell, moduleWindow->fNameList);
  770.                         row++;
  771.                     }
  772.                 }
  773.                 else {
  774.                     if (errCode != fnfErr)
  775.                         PutLine (gLogWindow, "### GetCatInfo failed : %d", errCode);
  776.                     done = true;
  777.                 }
  778.             }
  779.             
  780.             if (row > 0) {            // hilite the first row & column
  781.                 SetPt (&tCell, 0, 0);                        
  782.                 LSetSelect (true, tCell, moduleWindow->fNameList);
  783.             }
  784.         } 
  785.         else
  786.             PutLine (gLogWindow, "### GetPathToChild failed : %d", errCode);
  787.     }
  788.     else
  789.         PutLine (gLogWindow, "### ResolveAlias failed : %d", errCode);
  790. }
  791.  
  792.  
  793. #pragma segment ModuleWindow
  794. void    ExecuteSelectedNames (ModuleWindowPtr moduleWindow)
  795. {
  796.     Cell        tCell;
  797.     FSSpec        target;
  798.     Str63        name;
  799.     short        dataLen;
  800.     OSErr        errCode;
  801.     Boolean        wasChanged, firstTime = true;
  802.     long        dirID;
  803.  
  804.     errCode = ResolveAlias (nil, moduleWindow->fTestDirAlias, &target, &wasChanged);
  805.     if (errCode == noErr)
  806.     {
  807.         SetPt (&tCell, 0, 0);
  808.         while (LGetSelect (true, &tCell, moduleWindow->fNameList)) {
  809.             
  810.             dataLen = 63;
  811.             LGetCell(&name[1], &dataLen, tCell, moduleWindow->fNameList);
  812.             name[0] = dataLen;
  813.             
  814.             if (firstTime) {
  815.                 firstTime = false;
  816.                 
  817.                 if ((errCode = GetPathToChild (&dirID, &target)) != noErr)
  818.                     PutLine (gLogWindow, "### GetPathToChild failed : %d", errCode);
  819.             }
  820.             
  821.             if ((errCode = FSMakeFSSpec (target.vRefNum, dirID, name, &target)) != noErr)
  822.                 PutLine (gLogWindow, "### FSMakeFSSpec failed : %d", errCode);
  823.             else
  824.                 ExecuteModule (&target);
  825.             
  826.             if (! LNextCell (true, true, &tCell, moduleWindow->fNameList))
  827.                 break;
  828.         }
  829.     }
  830. }
  831.  
  832.  
  833. #pragma segment ModuleWindow
  834. void    DumpModuleRecord (ModuleWindowPtr moduleWindow)
  835. {
  836.     AliasHandle    theAlias = moduleWindow->fTestDirAlias;
  837.     Str63        tStr;
  838.     OSErr        errCode;
  839.     
  840.     PutLine (gLogWindow, "====== Module Window ======");
  841.     PutLine (gLogWindow, " fWindowRecord  = 0x%08x", moduleWindow->fWindowRecord);
  842.     PutLine (gLogWindow, " fNameList      = 0x%08x", moduleWindow->fNameList);
  843.     PutLine (gLogWindow, " fTestDirAlias  = 0x%08x", theAlias);
  844.     
  845.     if ((errCode = GetAliasInfo (theAlias, asiVolumeName, tStr)) == noErr)
  846.         PutLine (gLogWindow, "   volume       = %s", p2cstr(tStr));
  847.     else
  848.         PutLine (gLogWindow, "### GetAliasInfo failed : %d", errCode);
  849.     
  850.     if ((errCode = GetAliasInfo (theAlias, asiParentName, tStr)) == noErr)
  851.         PutLine (gLogWindow, "   parent       = %s", p2cstr(tStr));
  852.     else
  853.         PutLine (gLogWindow, "### GetAliasInfo failed : %d", errCode);
  854.     
  855.     if ((errCode = GetAliasInfo (theAlias, asiAliasName, tStr)) == noErr)
  856.         PutLine (gLogWindow, "   target       = %s", p2cstr(tStr));
  857.     else
  858.         PutLine (gLogWindow, "### GetAliasInfo failed : %d", errCode);
  859. }