home *** CD-ROM | disk | FTP | other *** search
- /* DisplayWindowManager.c */
- /*
- * Copyright © 1993-94 Apple Computer Inc. All rights reserved.
- */
- #include "DisplayNameRegistry.h"
- #include "IntlResources.h"
- #include "Script.h"
- #include "TextUtils.h"
- #include "SegLoad.h"
- #include "FixMath.h"
- #include "ToolUtils.h"
- #include "Gestalt.h"
-
- #define LIST (**BROWSER.theList)
-
-
- /*
- * MakeNameRegistryBrowserWindow
- * Create a window, the twist-down list, and fill it with file names.
- */
- OSErr
- MakeNameRegistryBrowserWindow(void)
- {
- OSErr status;
- register BrowserPtr browserPtr;
- WindowPtr theWindow;
- Rect viewRect;
- long response;
- Boolean hasColorQuickDraw;
- long fontSize;
- Str255 work;
-
- status = noErr;
- hasColorQuickDraw = FALSE;
- if (Gestalt(gestaltQuickdrawVersion, &response) == noErr
- && response >= gestalt8BitQD)
- hasColorQuickDraw = TRUE;
- viewRect = qd.screenBits.bounds;
- InsetRect(&viewRect, 4, 4);
- viewRect.top += (GetMBarHeight() * 2);
- //** To do: adjust the viewRect so the window starts off with an
- //** integral number of text lines.
- browserPtr = (BrowserPtr) NewPtrClear(sizeof (BrowserRecord));
- if (browserPtr == NULL)
- status = MemError();
- if (status == noErr) {
- if (hasColorQuickDraw) {
- theWindow = NewCWindow(
- (Ptr) browserPtr, /* Our data storage */
- &viewRect, /* Screen bounds */
- "\pName Registry", /* Window title */
- FALSE, /* Initially invisible */
- zoomDocProc, /* Normal document */
- (WindowPtr) -1L, /* Put in front */
- TRUE, /* Has go away */
- 0 /* No refCon */
- );
- }
- else {
- theWindow = NewWindow(
- (Ptr) browserPtr, /* Our data storage */
- &viewRect, /* Screen bounds */
- "\pName Registry", /* Window title */
- FALSE, /* Initially invisible */
- zoomDocProc, /* Simple document */
- (WindowPtr) -1L, /* Put in front */
- TRUE, /* Has go away */
- 0 /* No refCon */
- );
- }
- if (theWindow == NULL)
- status = memFullErr;
- }
- if (status == noErr) {
- SetPort(theWindow); /* Do this first, or else */
- viewRect = theWindow->portRect;
- viewRect.right -= (kScrollBarWidth - 1);
- viewRect.bottom -= (kScrollBarWidth - 1);
- GetIndString(BROWSER.fontNameText, STRN_Options, kOptionFontName);
- GetIndString(work, STRN_Options, kOptionFontSize);
- GetFNum(BROWSER.fontNameText, &BROWSER.fontNumber);
- StringToNum(work, &fontSize);
- BROWSER.fontSize = fontSize;
- TextFont(BROWSER.fontNumber);
- TextSize(BROWSER.fontSize);
- BROWSER.theList = NewTwistDownList(
- &viewRect, /* Where it will be seen */
- DisplayListDrawProc, /* Our private drawing func */
- CharWidth('n'), /* Tab indentation amount */
- FALSE, /* Hilite selections? */
- (GetSysDirection() == 0), /* Current system just. */
- TRUE /* Has Grow Box */
- );
- if (BROWSER.theList == NULL)
- status = memFullErr; /* Oops */
- }
- if (status == noErr) {
- gCurrentBrowserPtr = browserPtr;
- BROWSER.sortByName = TRUE;
- ShowWindow(theWindow);
- SelectWindow(theWindow);
- gUpdateMenusNeeded = TRUE;
- ++gOpenWindowCount;
- DoEnumerateNameRegistry(browserPtr);
- }
- return (status);
- }
-
- void
- DoRefreshDisplay(
- BrowserPtr browserPtr
- )
- {
- InitializeDisplayList(browserPtr);
- DisposeTwistDownHdl(REG.firstElement, NULL, NULL);
- NewTwistDownSiblingSet(®);
- LDelRow(0, 0, BROWSER.theList);
- DoEnumerateNameRegistry(browserPtr);
- }
-
- void
- DoEnumerateNameRegistry(
- BrowserPtr browserPtr
- )
- {
- Ptr privateStash;
- Str255 work;
-
- SetCursor(*GetCursor(watchCursor));
- /*
- * Because the enumerator can absorb all available memory, we grab a chunk
- * of memory that we restore before building and displaying the visible.
- * list. This isn't a really great solution, but it will do for now.
- */
- privateStash = NewPtr(32768L);
- if (privateStash != NULL) {
- EnumerateNameRegistry(browserPtr);
- DisposePtr(privateStash);
- }
- /*
- * The registry has been enumerated and the list of names, properties,
- * and values constructed. Display the number of things found in the
- * Window title and display the initial list.
- */
- NumToString(CountListElements(REG.firstElement), work);
- pstrcat(work, "\p - total names, properties, and values found");
- SetWTitle((WindowPtr) &BROWSER.theWindow, work);
- SortAndDisplayBrowserWindow(browserPtr);
- }
-
- /*
- * DisposeBrowser
- * The user clicked on the closer. Dispose of the window and its contents.
- */
- void
- DisposeBrowser(
- register BrowserPtr browserPtr
- )
- {
- InitializeDisplayList(browserPtr);
- DisposeTwistDownList(BROWSER.theList);
- DisposeTwistDownHdl(REG.firstElement, NULL, 0);
- CloseWindow((WindowPtr) &BROWSER.theWindow);
- DisposePtr((Ptr) browserPtr);
- gUpdateMenusNeeded = TRUE;
- --gOpenWindowCount;
- }
-
- /*
- * ActivateBrowser
- * This is called on activate and deactivate (or suspend/resume) events to enable
- * or disable the window content.
- */
- void
- ActivateBrowser(
- register BrowserPtr browserPtr,
- Boolean activating
- )
- {
- LActivate(activating, BROWSER.theList);
- }
-
- /*
- * DoWindowKeyDown
- */
- void
- DoWindowKeyDown(
- register BrowserPtr browserPtr
- )
- {
- UNUSED(browserPtr);
- /* Nothing happens here */
- }
-
- /*
- * DoContentClick
- * Click in the window. This function decides which element received the click and
- * calls the requisite click handler. In this example, we need only deal with
- * the twist-down list.
- */
- void
- DoContentClick(
- register BrowserPtr browserPtr,
- const EventRecord *eventRecordPtr
- )
- {
- Cell theCell;
- TwistDownClickState clickState;
-
- clickState = DoTwistDownClick(BROWSER.theList, eventRecordPtr, &theCell);
- switch (clickState) {
- case kTwistDownNotInList: /* Not in list view rectangle */
- case kTwistDownNoClick: /* Scroll bar or user changed mind */
- break; /* Ignore this click */
- case kTwistDownButtonClick: /* Clicked on expansion button */
- break; /* Done for us */
- case kTwistDownClick: /* Single-click on list datum */
- case kTwistDownDoubleClick: /* Double-click on list datum */
- break; /* Ignore these clicks */
- }
- }
-
- /*
- * UpdateBrowserWinow
- * Process an update event in this window.
- */
- void
- UpdateBrowserWindow(
- register BrowserPtr browserPtr,
- RgnHandle updateRgn
- )
- {
- Rect viewRect;
-
- viewRect = (**(BROWSER.theList)).rView;
- InsetRect(&viewRect, -1, -1);
- FrameRect(&viewRect);
- LUpdate(updateRgn, BROWSER.theList);
- }
-
- void
- DecorateBrowserWindow(
- register BrowserPtr browserPtr
- )
- {
- Rect listRect;
-
- listRect = ((WindowPtr) &BROWSER.theWindow)->portRect;
- listRect.bottom -= kScrollBarWidth;
- listRect.right -= kScrollBarWidth;
- SizeTwistDownList(
- BROWSER.theList,
- width(listRect),
- height(listRect)
- );
- }
-
- void
- PrintBrowserWindow(
- register BrowserPtr browserPtr
- )
- {
- OSErr status;
-
- status = PrintTwistDownList(
- BROWSER.theList,
- &gPrintHandle,
- FALSE,
- NULL, /* No setup callback function */
- //** DisplayListPrintImageProc, /* Our print page function */
- NULL, /* Use default print image proc */
- NULL, /* No exit callback function */
- browserPtr /* Refcon - for font info */
- );
- if (status != noErr)
- NonFatalError(status, "\pPrinting failed");
- }
-
- void
- DoSetFontInfo(
- register BrowserPtr browserPtr
- )
- {
- SetTwistDownListFont(
- BROWSER.theList,
- BROWSER.fontNumber,
- BROWSER.fontSize
- );
- }
-
-