home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Code Resources / Cursor LDEF / CursorLDEF.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-24  |  2.5 KB  |  115 lines  |  [TEXT/KAHL]

  1. /* *****************************************************************************
  2.     FILE:             CursorLDEF.c
  3.     
  4.     DESCRIPTION:     LDEF unit in C.
  5.  
  6.     AUTHOR:            Michael J. Conrad
  7.         
  8.     Copyright © 1994 Michael J. Conrad, All Rights Reserved.
  9.  
  10.     
  11.     Revision History:
  12.     ==========================================================
  13.     04.24.94    -    Original draft.
  14.     ==========================================================
  15.     
  16.     Here is an LDEF I wrote which displays cursors. It will display the cursor
  17.     and, if its available, text.
  18.     
  19.     If you find a purpose for it, use it freely!
  20.  
  21.    ***************************************************************************** */
  22.  
  23. #include "CursorLDEF.h"
  24.  
  25. #define    cellsPtr    (*(*theList)->cells)
  26. #define listPtr        (*theList)
  27.  
  28. pascal void    main(    short         message,
  29.                     Boolean     select,
  30.                     Rect         *rect,
  31.                     Cell         cell,
  32.                     short         dataOffset,
  33.                     short         dataLen,
  34.                     ListHandle     theList        )
  35. {
  36.     FontInfo     fontInfo;
  37.     SignedByte     listState, cellState;
  38.     Ptr         theCursor;
  39.     short         leftDraw, topDraw;
  40.     
  41.     listState = HGetState(theList);
  42.     HLock(theList);
  43.     
  44.     cellState = HGetState((*theList)->cells);
  45.     HLock((*theList)->cells);
  46.     
  47.     switch (message) 
  48.     {
  49.         case lInitMsg:
  50.               break;
  51.  
  52.         case lDrawMsg:
  53.             EraseRect(rect);
  54.         
  55.               if (dataLen > 0) 
  56.               {
  57.                   leftDraw = rect->left + listPtr->indent.h + kLeftOffset;
  58.                   topDraw  = rect->top + listPtr->indent.v + kTopOffset;
  59.                             
  60.               if (dataLen >= sizeof(Cursor)) 
  61.               {
  62.                   theCursor = cellsPtr + dataOffset;
  63.                   DrawCursor(theCursor, leftDraw, topDraw, listPtr->port);
  64.                   
  65.                   dataOffset += sizeof(Cursor);
  66.                   dataLen -= sizeof(Cursor);
  67.               }
  68.               
  69.               leftDraw += 16 + kCursorSpace;
  70.                             
  71.             GetFontInfo(&fontInfo);
  72.             MoveTo(leftDraw, topDraw + fontInfo.ascent);
  73.                         
  74.             TextFace(0);
  75.             if (TextWidth(cellsPtr, dataOffset, dataLen) > (rect->right - leftDraw))
  76.                 TextFace(condense);
  77.  
  78.             DrawText(cellsPtr, dataOffset, dataLen);
  79.           }
  80.  
  81.         if (!select)    break;
  82.         
  83.         case lHiliteMsg:
  84.             BitClr(&HiliteMode, pHiliteBit);
  85.             InvertRect(rect);
  86.               break;
  87.  
  88.         case lCloseMsg:
  89.               break;
  90.           
  91.         default:
  92.             break;
  93.     }
  94.     
  95.     HSetState(listPtr->cells, cellState);
  96.     HSetState(theList, listState);
  97. }
  98.  
  99.  
  100. void DrawCursor(Ptr theCursor, short left, short top, GrafPtr drawPort)
  101. {
  102.     BitMap     curMap;
  103.     Rect     destRect;
  104.  
  105.     curMap.baseAddr = (&((CursPtr)theCursor)->data);
  106.     curMap.rowBytes = 2;
  107.     
  108.     SetRect(&curMap.bounds,0,0,16,16);
  109.     
  110.     SetRect(&destRect,0,0,16,16);
  111.     OffsetRect(&destRect,left,top);
  112.     
  113.     CopyBits(&curMap, &drawPort->portBits, &curMap.bounds, &destRect, srcCopy, NULL);
  114. }
  115.