home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Code Resources / Indented LDEF / indent ldef.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-15  |  2.0 KB  |  73 lines  |  [TEXT/KAHL]

  1. // File "indent ldef.c" - Snippet for LDEF that automatically indents text 9/6/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. // * **************************************************************************** * //
  6. // * **************************************************************************** * //
  7. // Spacing Constants
  8.  
  9. #define kLeftOffset       2
  10. #define kTopOffset       0
  11.  
  12. // * **************************************************************************** * //
  13.  
  14. pascal void    main(short message, Boolean hilited, Rect *cellRect, Cell theCell,
  15.         short dataOffset, short dataLen, ListHandle theList) {
  16.     short leftDraw,topDraw;
  17.     Ptr cellData;
  18.     ListPtr theListPtr;
  19.     SignedByte hStateList, hStateCells;
  20.     FontInfo fontInfo;
  21.     
  22.     // Lock down the handles
  23.     hStateList = HGetState((Handle) theList);
  24.     HLock((Handle) theList);
  25.     theListPtr = *theList;
  26.     hStateList = HGetState((Handle) theListPtr->cells);
  27.     HLock((Handle) theListPtr->cells);
  28.     cellData = *(theListPtr->cells);
  29.     
  30.     switch (message) {
  31.       case lInitMsg:
  32.           break;
  33.  
  34.       case lDrawMsg:
  35.         EraseRect(cellRect);
  36.         
  37.           if (dataLen > 0) {
  38.               leftDraw = cellRect->left + theListPtr->indent.h + kLeftOffset;
  39.               topDraw = cellRect->top + theListPtr->indent.v + kTopOffset;
  40.               
  41.               // Determine the indent and add it...
  42.               while (cellData[dataOffset] == '\t') {
  43.                   dataOffset += 1;
  44.                   dataLen -= 1;
  45.                   leftDraw += 12;
  46.                   }
  47.  
  48.             GetFontInfo(&fontInfo);
  49.             MoveTo(leftDraw, topDraw + fontInfo.ascent);
  50.             
  51.             // Condense if the text doesnt fit
  52.             TextFace(0);
  53.             if (TextWidth(cellData, dataOffset, dataLen) > (cellRect->right - leftDraw))
  54.                 TextFace(condense);
  55.  
  56.             DrawText(cellData, dataOffset, dataLen);
  57.               }
  58.  
  59.         if (!hilited) break;
  60.         
  61.       case lHiliteMsg:
  62.           (* (char *) HiliteMode) ^= (1 << hiliteBit);
  63.           InvertRect(cellRect);
  64.           break;
  65.  
  66.       case lCloseMsg:
  67.           break;
  68.         }
  69.     
  70.     HSetState((Handle) theListPtr->cells,hStateCells);
  71.     HSetState((Handle) theList, hStateList);
  72.     }
  73.