home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / YellowBox / Kits / MiscTableScroll-138.1 / Palettes / MiscTableScroll / Framework / MiscLineWrapper.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-03-31  |  4.1 KB  |  132 lines

  1. #ifndef __MiscLineWrapper_h
  2. #define __MiscLineWrapper_h
  3. #ifdef __GNUC__
  4. #pragma interface
  5. #endif
  6. //=============================================================================
  7. //
  8. //    Copyright (C) 1996-1997 by Paul S. McCarthy and Eric Sunshine.
  9. //        Written by Paul S. McCarthy and Eric Sunshine.
  10. //                All Rights Reserved.
  11. //
  12. //    This notice may not be removed from this source code.
  13. //
  14. //    This object is included in the MiscKit by permission from the authors
  15. //    and its use is governed by the MiscKit license, found in the file
  16. //    "License.rtf" in the MiscKit distribution.  Please refer to that file
  17. //    for a list of all applicable permissions and restrictions.
  18. //    
  19. //=============================================================================
  20. //-----------------------------------------------------------------------------
  21. // MiscLineWrapper.h
  22. //
  23. //    A C++ object for calculating line breaks in text.
  24. //
  25. // NOTE *PARTIAL*
  26. //    "Partial" lines are lines that do not fit completely within the 
  27. //    height of the drawing rectangle.  For example, if you have 3 lines 
  28. //    of text, but the drawing rectangle is only 2.5 lines tall, the 
  29. //    third line of text is a partial line.  The caller can decide 
  30. //    whether or not to draw these partial lines.  Default behavior draws 
  31. //    partial lines.  
  32. //-----------------------------------------------------------------------------
  33. //-----------------------------------------------------------------------------
  34. // $Id: MiscLineWrapper.h,v 1.2 96/12/30 03:11:26 sunshine Exp $
  35. // $Log:    MiscLineWrapper.h,v $
  36. // Revision 1.2  96/12/30  03:11:26  sunshine
  37. // v104.1: Ported to OPENSTEP 4.1 (gamma).
  38. // 
  39. // Revision 1.1  96/08/30  14:56:41  sunshine
  40. // A C++ object for calculating line breaks in text.
  41. //-----------------------------------------------------------------------------
  42. #include <bool.h>
  43. extern "Objective-C" {
  44. #import    <AppKit/NSFont.h>
  45. #import    <Foundation/NSGeometry.h>    // NSRect
  46. }
  47. extern "C" {
  48. #include <limits.h>        // INT_MAX
  49. }
  50.  
  51.  
  52. class MiscLineWrapper
  53.     {
  54. public:
  55.     int const    MAX_TEXT_LENGTH        = (INT_MAX / 2);
  56. static    float const    DEFAULT_LEFT_MARGIN;
  57. static    float const    DEFAULT_TOP_MARGIN;
  58. static    float const    DEFAULT_RIGHT_MARGIN;
  59. static    float const    DEFAULT_BOTTOM_MARGIN;
  60.     struct Line
  61.         {
  62.         float    width;
  63.         int    start;
  64.         int    len;
  65.         };
  66. private:
  67.     int    text_len;
  68.     int    text_max;
  69.     char*    text;
  70.     NSFont*    font;
  71.     int    alignment;
  72.     int    num_lines;
  73.     int    max_lines;
  74.     Line*    lines;
  75.     NSRect    rect;
  76.     float    left_margin;
  77.     float    top_margin;
  78.     float    right_margin;
  79.     float    bottom_margin;
  80.     float    ascender;
  81.     float    descender;
  82.     float    line_height;
  83.     bool    char_wrap;
  84.     bool    no_partial;                // NOTE *PARTIAL*
  85.     bool    needs_wrap;
  86.  
  87.     MiscLineWrapper( MiscLineWrapper const& ) {}    // No copy constructor.
  88.     void operator=( MiscLineWrapper const& ) {}    // No assign operator.
  89.     void do_wrap();
  90.     void wrap_segment( int seg_start, int seg_end );
  91.     float calc_width( int start_pos, int lim ) const;
  92.     bool width_check() const;
  93.     bool has_tabs( Line const& line ) const;
  94.     void draw( float x, float y, int start, int len );
  95.     void draw_tabs( float x, float y, Line const& line );
  96. public:
  97.     MiscLineWrapper();
  98.     ~MiscLineWrapper();
  99.  
  100.     void        setText( NSString* );
  101.     void        setFont( NSFont* );
  102.     void        setRect( NSRect );
  103.     void        setLeftMargin( float );
  104.     void        setTopMargin( float );
  105.     void        setRightMargin( float );
  106.     void        setBottomMargin( float );
  107.     void        setAlignment( int );
  108.     void        setCharWrap( bool );
  109.     void        setNoPartialLines( bool b ) { no_partial = b; }
  110.  
  111.     char const*    getText() const        { return text; }
  112.     NSFont*        getFont() const        { return font; }
  113.     NSRect const&    getRect() const        { return rect; }
  114.     float        getLeftMargin() const    { return left_margin; }
  115.     float        getTopMargin() const    { return top_margin; }
  116.     float        getRightMargin() const    { return right_margin; }
  117.     float        getBottomMargin() const    { return bottom_margin; }
  118.     int        getAlignment() const    { return alignment; }
  119.     bool        getCharWrap() const    { return char_wrap; }
  120.     bool        getNoPartialLines() const { return no_partial; }
  121.  
  122.     bool        needsWrap() const    { return needs_wrap; }
  123.     int        numLines() const    { return num_lines; }
  124.     Line const&    lineAt( int i ) const    { return lines[i]; }
  125.  
  126.     void        wrap();
  127.     void         draw();
  128.     void        dump() const;
  129.     };
  130.  
  131. #endif // __MiscLineWrapper_h
  132.