home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Libraries / WASTE 1.3a5 / Extras / Experimental / WEExtraHooks.c next >
Encoding:
C/C++ Source or Header  |  1997-05-11  |  3.9 KB  |  145 lines  |  [TEXT/CWIE]

  1. /*
  2.  *    WEExtraHooks.c
  3.  *
  4.  *    Hooks for adding no-wrap behavior and "show invisibles" to WASTE
  5.  *    Written by Jonathan Kew
  6.  *
  7.  */
  8.  
  9. #include "WEExtraHooks.h"
  10.  
  11. static const Point kOneToOneScaling = { 1, 1 } ;
  12.  
  13. pascal StyledLineBreakCode _WENoWrapLineBreak
  14.     (
  15.         Ptr pText ,
  16.         SInt32 textLength ,
  17.         SInt32 textStart ,
  18.         SInt32 textEnd ,
  19.         Fixed * textWidth ,
  20.         SInt32 * textOffset ,
  21.         WEReference we
  22.     )
  23. {
  24. #pragma unused ( textLength, textWidth, we )
  25.  
  26.     SInt32 ii ;
  27.     StyledLineBreakCode breakCode = smBreakOverflow ;
  28.  
  29.     for ( ii = textStart ; ii < textEnd ; ii ++ )
  30.     {
  31.         if ( pText [ ii ] == kEOL )
  32.         {
  33.             breakCode = smBreakWord ;
  34.             *textOffset = ii + 1 ;
  35.             break ;
  36.         }
  37.     }
  38.  
  39.     if ( breakCode == smBreakOverflow )
  40.     {
  41.         * textOffset = ii ;
  42.     }
  43.  
  44.     return breakCode ;
  45. }
  46.  
  47. // This "show invisibles" hook is *not* ready for prime time -- it's inefficient and not
  48. // compatible with other features such as RL text. This is just an experiment!
  49. pascal void _WEShowInvisiblesDrawText
  50.     (
  51.         Ptr pText ,
  52.         SInt32 textLength ,
  53.         Fixed slop ,
  54.         JustStyleCode styleRunPosition ,
  55.         WEReference we
  56.     )
  57. {
  58.     // these are "static" to avoid the overhead of setting them up on the fly
  59.     static char tabIcon [ ] = { 0x00, 0x08, 0x0c, 0x7e, 0x7f, 0x7e, 0x0c, 0x08 } ;
  60.     static BitMap tabBitMap = { tabIcon, 1, { 0, 0, 8, 8 } } ;
  61.     static char parIcon [ ] = { 0x3f, 0x65, 0x65, 0x65, 0x3d, 0x05, 0x05, 0x05 } ;
  62.     static BitMap parBitMap = { parIcon, 1, { 0, 0, 8, 8 } } ;
  63.     extern WEDrawTextUPP _weShowInvisiblesOldDrawTextProc ;    // WEExtras.c stashes the previous routine here
  64.     GrafPtr port ;
  65.     Point startPt ;
  66.     SInt32 i, width, halfSpaceWidth = 0x80000000 ;
  67.     RGBColor color ;
  68.     Rect dstRect ;
  69.     WECharToPixelUPP charToPixelProc = nil ;
  70.  
  71.     GetPort ( & port ) ;
  72.     GetPen ( & startPt ) ;
  73.  
  74.     //    first draw the text using the original draw hook
  75.     CallWEDrawTextProc ( pText, textLength, slop, styleRunPosition, we, _weShowInvisiblesOldDrawTextProc ) ;
  76.  
  77.     if ( IsColorPort ( port ) )
  78.     {
  79.         SInt32 temp ;
  80.  
  81.         //    default invisibles color is light gray
  82.         color . red = 0xAAAA ;
  83.         color . green = 0xAAAA ;
  84.         color . blue = 0xAAAA ;
  85.  
  86.         if ( WEGetUserInfo ( kInvisiblesColorRedGreenTag , & temp, we ) == noErr )
  87.         {
  88.             * ( SInt32 * ) & color = temp ;
  89.         }
  90.         if ( WEGetUserInfo ( kInvisiblesColorBlueTag, & temp, we ) == noErr )
  91.         {
  92.             color . blue = temp ;
  93.         }
  94.         RGBForeColor ( & color ) ;
  95.     }
  96.  
  97.     //    retrieve CharToPixel hook
  98.     if ( WEGetInfo ( weCharToPixelHook, & charToPixelProc, we ) != noErr )
  99.     {
  100.         return ;
  101.     }
  102.  
  103.     for ( i = 0 ; i < textLength ; ++ i )
  104.     {
  105.         if ( pText [ i ] == ' ' )
  106.         {
  107.             width = CallWECharToPixelProc ( pText, textLength, slop, i, leftCaret,
  108.                 styleRunPosition, startPt . h, we, charToPixelProc ) ;
  109.             if ( halfSpaceWidth == 0x80000000 )
  110.             {
  111.                 halfSpaceWidth = CallWECharToPixelProc ( pText, textLength, slop, i + 1, leftCaret,
  112.                     styleRunPosition, startPt . h, we, charToPixelProc ) ;
  113.                 halfSpaceWidth = ( halfSpaceWidth - width ) >> 1 ;
  114.             }
  115.             dstRect . left = startPt . h + width + halfSpaceWidth ;
  116.             dstRect . right = dstRect . left + 1 ;
  117.             dstRect . top = startPt . v - 3 ;
  118.             dstRect . bottom = startPt . v - 2 ;
  119.             PaintRect ( & dstRect ) ;
  120.         }
  121.         else if ( pText [ i ] == '\t' )
  122.         {
  123.             width = CallWECharToPixelProc ( pText, textLength, slop, i, leftCaret,
  124.                 styleRunPosition, startPt . h, we, charToPixelProc ) ;
  125.             dstRect . left = startPt . h + width ;
  126.             dstRect . right = dstRect . left + 8 ;
  127.             dstRect . top = startPt . v - 8 ;
  128.             dstRect . bottom = startPt . v ;
  129.             CopyBits ( & tabBitMap, & port -> portBits, & tabBitMap . bounds, & dstRect, srcCopy, nil ) ;
  130.         }
  131.     }
  132.  
  133.     if ( ( textLength > 0 ) &&
  134.          ( pText + textLength <= * WEGetText ( we ) + WEGetTextLength ( we ) ) &&
  135.          ( pText [ textLength - 1 ] == kEOL ) )
  136.     {
  137.         GetPen ( & startPt ) ;        // that's really the endpoint now!
  138.         dstRect . left = startPt.h ;
  139.         dstRect . right = dstRect.left + 8 ;
  140.         dstRect . top = startPt.v - 8 ;
  141.         dstRect . bottom = startPt.v ;
  142.         CopyBits ( & parBitMap, & port -> portBits, & parBitMap . bounds, & dstRect, srcCopy, nil ) ;
  143.     }
  144. }
  145.