home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Code Resources / Icon (Sys7) LDEF / Icon LDEF.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-15  |  2.7 KB  |  88 lines  |  [TEXT/KAHL]

  1. // File "Icon LDEF.c" - Icon Suite LDEF Routine  10/16/93
  2. //   Code is shamelessly based on Apple Snippet by Steven Falkenburg 5/23/91
  3. //   This code is placed in the public domain for free use and distribution! MJS
  4.  
  5. #include <GestaltEqu.h>
  6. #include <Icons.h>
  7.  
  8. // * **************************************************************************** * //
  9. // * **************************************************************************** * //
  10.  
  11. pascal void    main(short message, Boolean hilited, Rect *cellRect, Cell theCell,
  12.         short dataOffset, short dataLen, ListHandle theList) {
  13.     long response;
  14.     Point drawPt;
  15.     Rect iconRect, textRect;
  16.     Ptr cellData;
  17.     Handle iconHdl;
  18.     ListPtr theListPtr;
  19.     SignedByte hStateList, hStateCells;
  20.     FontInfo fontInfo;
  21.     
  22.     if (Gestalt(gestaltSystemVersion, &response) || (response < 0x0700)) return;
  23.     
  24.     // Lock down the handles
  25.     hStateList = HGetState((Handle) theList);
  26.     HLock((Handle) theList);
  27.     theListPtr = *theList;
  28.     hStateList = HGetState((Handle) theListPtr->cells);
  29.     HLock((Handle) theListPtr->cells);
  30.     cellData = *(theListPtr->cells);
  31.     
  32.     GetFontInfo(&fontInfo);
  33.     SetRect(&iconRect, cellRect->left + (theListPtr->cellSize.h >> 1) - 16,
  34.             cellRect->top + ((theListPtr->cellSize.v - fontInfo.ascent) >> 1) - 16,
  35.             cellRect->left + (theListPtr->cellSize.h >> 1) + 16,
  36.             cellRect->top + ((theListPtr->cellSize.v - fontInfo.ascent) >> 1) + 16);
  37.     SetPt(&drawPt, (iconRect.left + iconRect.right) >> 1, 
  38.             iconRect.bottom + fontInfo.ascent + 2);
  39.  
  40.     switch (message) {
  41.         case lInitMsg:
  42.               break;
  43.  
  44.         case lDrawMsg:
  45.             EraseRect(cellRect);
  46.         case lHiliteMsg:
  47.             
  48.               if (dataLen > 0) {
  49.                   if (dataLen >= 4) {
  50.                       BlockMove(cellData + dataOffset, &iconHdl, 4);
  51.                       if (iconHdl)
  52.                           PlotIconSuite(&iconRect, 0, (hilited) ? ttSelected : 0, iconHdl);
  53.                         else if (hilited) PaintRect(&iconRect);
  54.                         else EraseRect(&iconRect);
  55.                       dataLen -= 4;
  56.                       dataOffset += 4;
  57.                       }
  58.                 
  59.                 // Condense if the text doesnt fit
  60.                 if (TextWidth(cellData, dataOffset, dataLen) >
  61.                         (cellRect->right - cellRect->left)) TextFace(condense);
  62.         
  63.                 SetRect(&textRect, drawPt.h - (TextWidth(cellData, dataOffset, dataLen) >> 1) - 2,
  64.                         drawPt.v - fontInfo.ascent - 1,
  65.                         drawPt.h + (TextWidth(cellData, dataOffset, dataLen) >> 1) + 2,
  66.                         drawPt.v + 2);
  67.  
  68.                 EraseRect(&textRect);
  69.                   MoveTo(drawPt.h - (TextWidth(cellData, dataOffset, dataLen) >> 1), drawPt.v);
  70.                 DrawText(cellData, dataOffset, dataLen);
  71.  
  72.                 if (hilited) {            
  73.                       (* (char *) HiliteMode) ^= (1 << hiliteBit);
  74.                       InvertRect(&textRect);
  75.                       }
  76.                   }
  77.         
  78.               break;
  79.  
  80.         case lCloseMsg:
  81.               break;
  82.             }
  83.     
  84.     // Restore the Handles
  85.     HSetState((Handle) theListPtr->cells,hStateCells);
  86.     HSetState((Handle) theList, hStateList);
  87.     }
  88.