home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / Apps / DevTools / eText5 / Source / Divider.subproj / Divider.m next >
Encoding:
Text File  |  1995-02-04  |  3.3 KB  |  114 lines

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //    FILENAME:    Divider.m
  3. //    SUMMARY:    a trivial annotation denoting a logical/graphical divider.
  4. //    SUPERCLASS:    Object
  5. //    INTERFACE:    None
  6. //    PROTOCOLS:    <Annotation, Tool, ASCIISupport, HTMDSupport>
  7. //    AUTHOR:        Rohit Khare
  8. //    COPYRIGHT:    (c) 1994 California Institure of Technology, eText Project
  9. ///////////////////////////////////////////////////////////////////////////////
  10. //    DESCRIPTION
  11. //        Does its job by displaying a horizontal image the width of the window.
  12. ///////////////////////////////////////////////////////////////////////////////
  13. //    HISTORY
  14. //  06/17/94:    HTMD protocol added. RK and TRZ
  15. //    05/13/94:    Created. First actual implementation.
  16. ///////////////////////////////////////////////////////////////////////////////
  17.  
  18. #import "../eTextKernel.h"
  19. #define    _DividerVERSION    10
  20.  
  21. @interface Divider:Object <Annotation, Tool, ASCIISupport, HTMDSupport,LaTeXSupport>
  22. {    id    theImage;
  23.     id  theText;
  24.     int    highlighted;
  25.     NXCoord lMargin;
  26. }
  27. @end
  28. @implementation Divider
  29. + toolAwake:theApp
  30. {
  31.     [theApp   registerAnnotation: [Divider class] 
  32.                             name: "Divider"
  33.                     RTFDirective: "Divider"
  34.                        menuLabel: "Insert Divider..."
  35.                          menuKey: '\0'
  36.                         menuIcon: (NXImage *) nil];
  37.     return self;
  38. }
  39. - init {[super init]; theImage = theText = nil; highlighted = 0; lMargin = 0.0; return self;}
  40. - initFromPboard:thePB inDoc:theDoc linked:(BOOL) linked {return [self init];}
  41. - calcCellSize:(NXSize *)theSize {
  42.     NXCoord r,t,b;
  43.     NXRect bounds;
  44.     
  45.     if (theText) {
  46.         [theText getMarginLeft:&lMargin right:&r top:&t bottom:&b];
  47.         [theText getBounds:&bounds];
  48.         theSize->width = NX_WIDTH(&bounds) - lMargin - r; 
  49.     } else 
  50.         theSize->width = 1024.0;
  51.     theSize->height = 6.0; 
  52.     return self;
  53. }
  54. - drawSelf:(const NXRect *)rect inView:view
  55.     {    NXRect tmpRect,bounds;
  56.     
  57.         theText = view;
  58.         tmpRect.origin.x = lMargin;
  59.         tmpRect.origin.y = NX_Y(rect) - NX_HEIGHT(rect);
  60.         tmpRect.size.height = NX_HEIGHT(rect);
  61.         tmpRect.size.width = NX_WIDTH(rect);
  62.         [view getBounds:&bounds];
  63.         NXDrawButton(&tmpRect, &bounds);
  64.         PSsetgray(NX_BLACK);
  65.         //PSsetgray(highlighted ? NX_DKGRAY : NX_BLACK);
  66.         //PSmoveto(lMargin, NX_Y(rect) + (NX_HEIGHT(rect)/2));
  67.         //PSsetlinewidth(2.0);
  68.         //PSrlineto(NX_WIDTH(rect),0);
  69.         //PSstroke();
  70.         return self;
  71.     }
  72. - highlight:(const NXRect *)rect inView:view lit:(BOOL)flag
  73.     {highlighted = !highlighted; NXHighlightRect(rect);return self;}
  74. - (BOOL)    trackMouse:(NXEvent *)theEvent
  75.             inRect:(const NXRect *)rect
  76.             ofView:view
  77.     {return NO;}
  78. - readRichText:(NXStream *)stream forView:view 
  79. {    
  80.     int        i;
  81.     char     c;
  82.     
  83.     if(c=NXGetc(stream)=='}') //version 0
  84.         NXUngetc(stream);
  85.     else {
  86.         NXUngetc(stream);
  87.         NXScanf(stream, "%d ", &i);
  88.         if (i != _DividerVERSION) {
  89.             // bad version block.
  90.             NXLogError("Divider found unparseable version %d at position %d", i, NXTell(stream));
  91.         return nil;
  92.         }
  93.     }
  94.     return self;
  95. }
  96.  
  97. - writeRichText:(NXStream *)stream forView:view
  98.     { NXPrintf(stream,"%d ",_DividerVERSION);return self;}
  99. - writeASCII:(NXStream *)stream forView:view
  100. {
  101.     NXPrintf(stream, "\n------------------------------------------------------------\n");
  102.     return self;
  103. }
  104. - writeLaTeX:(NXStream *) stream forView:view
  105. {
  106.     NXPrintf(stream,"\n\\hrule\n");
  107.     return self;
  108. }
  109. - writeHTML:(NXStream *)stream forView:view
  110. {
  111.     NXPrintf(stream,"\n<HR>\n");
  112.     return self;
  113. }
  114. @end