home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection 1998 Fall: Game Toolkit / Disc.iso / SDKs / PCI Driver Development Kit / • Tools / Utility / DisplayNameRegistry 950412 / Src / DisplayWindowManager.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-27  |  7.4 KB  |  291 lines  |  [TEXT/MPCC]

  1. /*                                DisplayWindowManager.c                            */
  2. /*
  3.  * Copyright © 1993-94 Apple Computer Inc. All rights reserved.
  4.  */
  5. #include "DisplayNameRegistry.h"
  6. #include "IntlResources.h"
  7. #include "Script.h"
  8. #include "TextUtils.h"
  9. #include "SegLoad.h"
  10. #include "FixMath.h"
  11. #include "ToolUtils.h"
  12. #include "Gestalt.h"
  13.  
  14. #define LIST    (**BROWSER.theList)
  15.  
  16.  
  17. /*
  18.  * MakeNameRegistryBrowserWindow
  19.  * Create a window, the twist-down list, and fill it with file names.
  20.  */
  21. OSErr
  22. MakeNameRegistryBrowserWindow(void)
  23. {
  24.         OSErr                    status;
  25.         register BrowserPtr        browserPtr;
  26.         WindowPtr                theWindow;
  27.         Rect                    viewRect;
  28.         long                    response;
  29.         Boolean                    hasColorQuickDraw;
  30.         long                    fontSize;
  31.         Str255                    work;
  32.  
  33.         status = noErr;
  34.         hasColorQuickDraw = FALSE;
  35.         if (Gestalt(gestaltQuickdrawVersion, &response) == noErr
  36.          && response >= gestalt8BitQD)
  37.              hasColorQuickDraw = TRUE;
  38.         viewRect = qd.screenBits.bounds;
  39.         InsetRect(&viewRect, 4, 4);
  40.         viewRect.top += (GetMBarHeight() * 2);
  41.         //** To do: adjust the viewRect so the window starts off with an
  42.         //** integral number of text lines.
  43.         browserPtr = (BrowserPtr) NewPtrClear(sizeof (BrowserRecord));
  44.         if (browserPtr == NULL)
  45.             status = MemError();
  46.         if (status == noErr) {
  47.             if (hasColorQuickDraw) {
  48.                 theWindow = NewCWindow(
  49.                             (Ptr) browserPtr,        /* Our data storage            */
  50.                             &viewRect,                /* Screen bounds            */
  51.                             "\pName Registry",        /* Window title                */
  52.                             FALSE,                    /* Initially invisible        */
  53.                             zoomDocProc,            /* Normal document            */
  54.                             (WindowPtr) -1L,        /* Put in front                */
  55.                             TRUE,                    /* Has go away                */
  56.                             0                        /* No refCon                */
  57.                         );
  58.             }
  59.             else {
  60.                 theWindow = NewWindow(
  61.                             (Ptr) browserPtr,        /* Our data storage            */
  62.                             &viewRect,                /* Screen bounds            */
  63.                             "\pName Registry",        /* Window title                */
  64.                             FALSE,                    /* Initially invisible        */
  65.                             zoomDocProc,            /* Simple document            */
  66.                             (WindowPtr) -1L,        /* Put in front                */
  67.                             TRUE,                    /* Has go away                */
  68.                             0                        /* No refCon                */
  69.                         );
  70.             }
  71.             if (theWindow == NULL)
  72.                 status = memFullErr;
  73.         }
  74.         if (status == noErr) {
  75.             SetPort(theWindow);                        /* Do this first, or else    */
  76.             viewRect = theWindow->portRect;
  77.             viewRect.right -= (kScrollBarWidth - 1);
  78.             viewRect.bottom -= (kScrollBarWidth - 1);
  79.             GetIndString(BROWSER.fontNameText, STRN_Options, kOptionFontName);
  80.             GetIndString(work, STRN_Options, kOptionFontSize);
  81.             GetFNum(BROWSER.fontNameText, &BROWSER.fontNumber);
  82.             StringToNum(work, &fontSize);
  83.             BROWSER.fontSize = fontSize;
  84.             TextFont(BROWSER.fontNumber);
  85.             TextSize(BROWSER.fontSize);
  86.             BROWSER.theList = NewTwistDownList(
  87.                         &viewRect,                    /* Where it will be seen    */
  88.                         DisplayListDrawProc,        /* Our private drawing func    */
  89.                         CharWidth('n'),                /* Tab indentation amount    */
  90.                         FALSE,                        /* Hilite selections?        */
  91.                         (GetSysDirection() == 0),    /* Current system just.        */
  92.                         TRUE                        /* Has Grow Box                */
  93.                     );
  94.             if (BROWSER.theList == NULL)
  95.                 status = memFullErr;                    /* Oops                            */
  96.         }
  97.         if (status == noErr) {
  98.             gCurrentBrowserPtr = browserPtr;
  99.             BROWSER.sortByName = TRUE;
  100.             ShowWindow(theWindow);
  101.             SelectWindow(theWindow);
  102.             gUpdateMenusNeeded = TRUE;
  103.             ++gOpenWindowCount;
  104.             DoEnumerateNameRegistry(browserPtr);
  105.         }
  106.         return (status);
  107. }
  108.  
  109. void
  110. DoRefreshDisplay(
  111.         BrowserPtr                browserPtr
  112.     )
  113. {
  114.         InitializeDisplayList(browserPtr);
  115.         DisposeTwistDownHdl(REG.firstElement, NULL, NULL);
  116.         NewTwistDownSiblingSet(®);
  117.         LDelRow(0, 0, BROWSER.theList);
  118.         DoEnumerateNameRegistry(browserPtr);
  119. }
  120.  
  121. void
  122. DoEnumerateNameRegistry(
  123.         BrowserPtr                browserPtr
  124.     )
  125. {
  126.         Ptr                        privateStash;
  127.         Str255                    work;
  128.  
  129.         SetCursor(*GetCursor(watchCursor));
  130.         /*
  131.          * Because the enumerator can absorb all available memory, we grab a chunk
  132.          * of memory that we restore before building and displaying the visible.
  133.          * list. This isn't a really great solution, but it will do for now.
  134.          */
  135.         privateStash = NewPtr(32768L);
  136.         if (privateStash != NULL) {
  137.             EnumerateNameRegistry(browserPtr);
  138.             DisposePtr(privateStash);
  139.         }
  140.         /*
  141.          * The registry has been enumerated and the list of names, properties,
  142.          * and values constructed. Display the number of things found in the
  143.          * Window title and display the initial list.
  144.          */
  145.         NumToString(CountListElements(REG.firstElement), work);
  146.         pstrcat(work, "\p - total names, properties, and values found");
  147.         SetWTitle((WindowPtr) &BROWSER.theWindow, work);
  148.         SortAndDisplayBrowserWindow(browserPtr);
  149. }
  150.  
  151. /*
  152.  * DisposeBrowser
  153.  * The user clicked on the closer. Dispose of the window and its contents.
  154.  */
  155. void
  156. DisposeBrowser(
  157.         register BrowserPtr        browserPtr
  158.     )
  159. {
  160.         InitializeDisplayList(browserPtr);
  161.         DisposeTwistDownList(BROWSER.theList);
  162.         DisposeTwistDownHdl(REG.firstElement, NULL, 0);
  163.         CloseWindow((WindowPtr) &BROWSER.theWindow);
  164.         DisposePtr((Ptr) browserPtr);
  165.         gUpdateMenusNeeded = TRUE;
  166.         --gOpenWindowCount;
  167. }
  168.  
  169. /*
  170.  * ActivateBrowser
  171.  * This is called on activate and deactivate (or suspend/resume) events to enable
  172.  * or disable the window content.
  173.  */
  174. void
  175. ActivateBrowser(
  176.         register BrowserPtr        browserPtr,
  177.         Boolean                    activating
  178.     )
  179. {
  180.         LActivate(activating, BROWSER.theList);
  181. }
  182.  
  183. /*
  184.  * DoWindowKeyDown
  185.  */
  186. void
  187. DoWindowKeyDown(
  188.         register BrowserPtr        browserPtr
  189.     )
  190. {
  191.         UNUSED(browserPtr);
  192.         /* Nothing happens here */
  193. }
  194.  
  195. /*
  196.  * DoContentClick
  197.  * Click in the window. This function decides which element received the click and
  198.  * calls the requisite click handler. In this example, we need only deal with
  199.  * the twist-down list.
  200.  */
  201. void
  202. DoContentClick(
  203.         register BrowserPtr        browserPtr,
  204.         const EventRecord        *eventRecordPtr
  205.     )
  206. {
  207.         Cell                    theCell;
  208.         TwistDownClickState        clickState;
  209.         
  210.         clickState = DoTwistDownClick(BROWSER.theList, eventRecordPtr, &theCell);
  211.         switch (clickState) {
  212.         case kTwistDownNotInList:            /* Not in list view rectangle        */
  213.         case kTwistDownNoClick:                /* Scroll bar or user changed mind    */
  214.             break;                            /* Ignore this click                */
  215.         case kTwistDownButtonClick:            /* Clicked on expansion button        */
  216.             break;                            /* Done for us                        */
  217.         case kTwistDownClick:                /* Single-click on list datum        */
  218.         case kTwistDownDoubleClick:            /* Double-click on list datum        */
  219.             break;                            /* Ignore these clicks                */
  220.         }
  221. }
  222.  
  223. /*
  224.  * UpdateBrowserWinow
  225.  * Process an update event in this window.
  226.  */
  227. void
  228. UpdateBrowserWindow(
  229.         register BrowserPtr        browserPtr,
  230.         RgnHandle                updateRgn
  231.     )
  232. {
  233.         Rect                    viewRect;
  234.         
  235.         viewRect = (**(BROWSER.theList)).rView;
  236.         InsetRect(&viewRect, -1, -1);
  237.         FrameRect(&viewRect);
  238.         LUpdate(updateRgn, BROWSER.theList);
  239. }
  240.  
  241. void
  242. DecorateBrowserWindow(
  243.         register BrowserPtr        browserPtr
  244.     )
  245. {
  246.         Rect                    listRect;
  247.  
  248.         listRect = ((WindowPtr) &BROWSER.theWindow)->portRect;
  249.         listRect.bottom -= kScrollBarWidth;
  250.         listRect.right -= kScrollBarWidth;
  251.         SizeTwistDownList(
  252.             BROWSER.theList,
  253.             width(listRect),
  254.             height(listRect)
  255.         );
  256. }
  257.  
  258. void
  259. PrintBrowserWindow(
  260.         register BrowserPtr        browserPtr
  261.     )
  262. {
  263.         OSErr                    status;
  264.         
  265.         status = PrintTwistDownList(
  266.             BROWSER.theList,
  267.             &gPrintHandle,
  268.             FALSE,
  269.             NULL,                        /* No setup callback function    */
  270.             //** DisplayListPrintImageProc,    /* Our print page function        */
  271.             NULL,                        /* Use default print image proc    */
  272.             NULL,                        /* No exit callback function    */
  273.             browserPtr                    /* Refcon - for font info        */
  274.         );
  275.         if (status != noErr)
  276.             NonFatalError(status, "\pPrinting failed");
  277. }
  278.  
  279. void
  280. DoSetFontInfo(
  281.         register BrowserPtr        browserPtr
  282.     )
  283. {
  284.         SetTwistDownListFont(
  285.             BROWSER.theList,
  286.             BROWSER.fontNumber,
  287.             BROWSER.fontSize
  288.         );
  289. }
  290.  
  291.