home *** CD-ROM | disk | FTP | other *** search
-
- /* CODE EXAMPLE #1 */
- // An example illustrating the use of the List Manager
- // Clicking a list element causes it to be highlighted
- // Double-clicking a list element causes it to beep.
-
- // Taken from THINK Reference, with modifications for my icl8 LDEF
- // Nov 14 95
-
- // ---------------------------------------------------------------------------
-
- #include "icl8 LDEF.h"
-
- // ---------------------------------------------------------------------------
-
- void ToolBoxInit(void);
-
- void ToolBoxInit() {
- InitGraf(&qd.thePort);
- InitFonts();
- InitWindows();
- TEInit();
- InitDialogs(nil);
- InitCursor();
- }
-
- // ---------------------------------------------------------------------------
-
- enum {
- kCellSize = 56,
- kIconBegin = 128,
- kIconEnd = 134,
- kNumIcons = kIconEnd - kIconBegin + 1
- };
-
- // ---------------------------------------------------------------------------
-
- void main() {
- ListHandle myList;
- WindowPtr myWindow;
- Rect listR, dataBounds;
- Point cSize;
- short selType, j, dummy;
- Str255 s;
- Boolean done;
- EventRecord theEvent;
- WindowPtr whichWindow;
- long windSize;
- short thePart;
- Rect sizeRect;
- GrafPtr oldPort;
- Boolean beep;
- short hGrow, vGrow;
- long gestInfo;
- IconListData theIcon;
-
- ToolBoxInit();
- InitCursor();
-
- // Color or not?
- Gestalt(gestaltQuickdrawVersion, &gestInfo);
- if (gestInfo > gestaltOriginalQD)
- myWindow = GetNewCWindow(128, NULL, (WindowPtr)-1);
- else
- myWindow = GetNewWindow(128, NULL, (WindowPtr)-1);
- SetPort((GrafPtr)myWindow);
-
- // --------------------------------------
- // Setting up list stuff here
- // --------------------------------------
- SetRect(&dataBounds, 0, 0, 0, 0);
- SetPt(&cSize, kCellSize, kCellSize);
- SetRect (&listR, 0, 0, (kCellSize * 7), (kCellSize * 7));
-
- myList = LNew(&listR, &dataBounds, cSize, 1972,
- (WindowPtr)myWindow,true, true, true, true);
- HLock((Handle)myList);
- cSize = (**myList).cellSize; // Save cellSize so we can use
- // it later to resize the cells
-
- // Set icon parameters here.
- theIcon.iconSize = kIconBasedOnCellSize;
- theIcon.frameWidth = 2; // Used only if kSelectByFramingBW or kSelectByFramingHilite set
- theIcon.drawName = true;
-
- dummy = LAddRow(5, 0, myList);
- dummy = LAddColumn(kSelectByDarkenIcon+1, kSelectByInvertBW, myList);
-
- theIcon.id = kIconBegin;
- for (selType = kSelectByInvertBW; selType <= kSelectByDarkenIcon; selType++) {
- theIcon.selType = selType;
- for (j = 0; j < 5; j++) {
- SetPt(&cSize, selType, j);
- LAddToCell(&theIcon, sizeof(IconListData), cSize, myList);
- LDraw(cSize, myList);
- if (theIcon.id < kIconEnd)
- theIcon.id++;
- else
- theIcon.id = kIconBegin;
- }
- }
-
- // --------------------------
- // Event loop
- // --------------------------
- done = false;
- SetRect (&sizeRect, 50, 50,
- qd.screenBits.bounds.bottom - qd.screenBits.bounds.top,
- qd.screenBits.bounds.right - qd.screenBits.bounds.left);
-
- done = FALSE;
- while (!done)
- if (WaitNextEvent(everyEvent, &theEvent, 30, nil )) {
- switch (theEvent.what) {
- case mouseDown:
- thePart = FindWindow (theEvent.where,
- &whichWindow);
-
- switch (thePart) {
- case inContent:
- GlobalToLocal(&theEvent.where);
- beep = LClick(theEvent.where,
- theEvent.modifiers, myList);
- if (beep)
- SysBeep (10);
- break;
-
- case inGrow:
- windSize = GrowWindow (whichWindow,
- theEvent.where, &sizeRect);
- if (windSize) {
- GetPort (&oldPort);
- SetPort (whichWindow);
- hGrow = (LoWord(windSize) / kCellSize) * kCellSize + 15;
- vGrow = (HiWord(windSize) / kCellSize) * kCellSize + 15;
- SizeWindow (whichWindow, hGrow, vGrow, true);
- LSize (whichWindow->portRect.right - 15,
- whichWindow->portRect.bottom - 15, myList);
- SetPt(&cSize, kCellSize, kCellSize);
- DrawGrowIcon((GrafPtr)myWindow);
- InvalRect (&whichWindow->portRect);
- SetPort (oldPort);
- }
- break;
-
- case inGoAway:
- done = TRUE;
- break;
- }
- break;
-
- case updateEvt:
- if ((WindowPtr) theEvent.message == myWindow) {
- BeginUpdate ((WindowPtr) theEvent.message);
- EraseRect(&myWindow->portRect);
- DrawGrowIcon ((WindowPtr) myWindow);
- LUpdate(myWindow->visRgn, myList);
- EndUpdate ((WindowPtr) theEvent.message);
- }
- break;
- }
- }
-
- HUnlock((Handle) myList);
- LDispose(myList);
- DisposeWindow((WindowPtr)myWindow);
- }
-
-