home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1995 August / NEBULA.mdf / Apps / DevTools / ClassEditor.0.3 / Source / Text_MiscExtensions.m < prev    next >
Encoding:
Text File  |  1995-02-11  |  3.2 KB  |  176 lines

  1. /* Text_MiscExtensions.m                 
  2.  *
  3.  * This category makes dealing with the Text object easier. 
  4.  * See the docu for details.
  5.  *
  6.  * For interface-info see the header file. The comments in this file mostly
  7.  * cover only the real implementation details.
  8.  *
  9.  * Written by:         Thomas Engel
  10.  * Created:            30.01.1995 (Copyleft)
  11.  * Last modified:     30.01.1995
  12.  */
  13.  
  14. // The following define is a fake. Looks like NeXT...but it is a cheatmode
  15. // action.
  16. // We don't have a RTFD paste type. But I really need one !
  17.  
  18. #define NXRTFDPboardType NXUniqueString("NeXT RTFD pasteboard type")
  19.  
  20.  
  21. #import "Text_MiscExtensions.h"
  22. #import <misckit/MiscTextExtensions.h>
  23.  
  24. @implementation Text(MoreMiscExtensions)
  25.  
  26. - copyTo:aPasteboard
  27. {
  28.     NXAtom textTypes[5];
  29.  
  30.     if( [self isMonoFont] )
  31.     {
  32.         textTypes[0] = NXAsciiPboardType;
  33.         textTypes[1] = NULL;
  34.     }
  35.     // In the other case we will cheat. The RTFD type was NEVER defined by
  36.     // NeXT. But we will use it...it works. (see the define)
  37.  
  38.     else
  39.     {
  40.         textTypes[0] = NXRTFDPboardType;
  41.         textTypes[1] = NXTIFFPboardType;
  42.         textTypes[2] = NXRTFPboardType;
  43.         textTypes[3] = NXAsciiPboardType;
  44.         textTypes[4] = NULL;
  45.     }
  46.     [self writeSelectionToPasteboard:aPasteboard types:textTypes];
  47.     return self;
  48. }
  49.  
  50. - cutTo:aPasteboard
  51. {
  52.     [self copyTo:aPasteboard];
  53.     [self delete:self];
  54.     return self;
  55. }
  56.  
  57. - pasteFrom:aPasteboard
  58. {
  59.     [self readSelectionFromPasteboard:aPasteboard];
  60.     return self;
  61. }
  62.  
  63. - (BOOL)hasEmptySelection
  64. {
  65.     NXSelPt    start;
  66.     NXSelPt    end;
  67.  
  68.     [self getSel:&start :&end];
  69.     
  70.     if( start.cp == end.cp || 
  71.         start.cp < 0 )
  72.         return YES;
  73.     
  74.     return NO;
  75. }
  76.  
  77. - findPerviousWord
  78. {
  79.     return self;
  80. }
  81.  
  82. - findNextWord
  83. {
  84.     return self;
  85. }
  86.  
  87. - (BOOL)findText:(const char *)string ignoreCase:(BOOL)ignoreCaseflag backwards:(BOOL)backwardsflag wrap:(BOOL)wrapflag font:aSharedFont
  88. {
  89.     BOOL        gotIt;
  90.     NXSelPt    fromPos;
  91.     NXSelPt    toPos;
  92.     int        firstHit;
  93.  
  94.     firstHit = -2;
  95.     gotIt = NO;
  96.  
  97.     while( !gotIt )
  98.     {
  99.         gotIt = [self findText:string ignoreCase:ignoreCaseflag
  100.                      backwards:NO wrap:NO];
  101.     
  102.         // Now we should get the position of the found seleection.
  103.         // we have to remember the first place where we have found something to
  104.         // trace down inf-loops when we are allowed to do wraps!
  105.  
  106.         [self getSel:&fromPos :&toPos];
  107.  
  108.         if( !gotIt ||
  109.             fromPos.cp == firstHit ) return NO;
  110.         
  111.         firstHit = fromPos.cp;
  112.  
  113.         // Now it seems like we have found the right string but
  114.         // still this does not have to be the right font
  115.  
  116.         if( [self fontAtPosition:fromPos.cp] != aSharedFont ) gotIt = NO;
  117.     }
  118.     return YES;
  119. }
  120.  
  121. - substringFromLine:(int)line
  122. {
  123.     int    from;
  124.     int    length;
  125.  
  126.     from = [self positionFromLine:line];
  127.     length = [self positionFromLine:line+1] - from;
  128.  
  129.     return [self getSubstringStringStart:from length:length];
  130. }
  131.  
  132. // Working with Text runs and their information
  133.  
  134. - (NXRun *)textRunForPosition:(int)position
  135. {
  136.     BOOL     found;
  137.     int    i;
  138.     int    currentOffset;
  139.     
  140.     currentOffset = 0;
  141.     found = NO;
  142.  
  143.     for( i=0; i<theRuns->chunk.used; i++ )
  144.     {
  145.         if( currentOffset >= position )
  146.         {
  147.             found = YES;
  148.             break;
  149.         }
  150.         currentOffset += theRuns->runs[i].chars;
  151.     }
  152.  
  153.     return &(theRuns->runs[i]);
  154. }
  155.  
  156. - fontsInsideSelection
  157. {
  158.     return self;
  159. }
  160.  
  161. - fontAtPosition:(int)position
  162. {
  163.     NXRun *aRun;
  164.  
  165.     aRun = [self textRunForPosition:position];
  166.     return aRun->font;
  167. }
  168.  
  169. @end
  170.  
  171. /*
  172.  * History: 30.01.95 Buh
  173.  *            
  174.  *
  175.  * Bugs: - ...
  176.  */