home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 15 / BBS in a box XV-2.iso / Files II / Prog / B-C / CPStyleText.sit / CPStyleText.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-05  |  10.6 KB  |  367 lines  |  [TEXT/KAHL]

  1. /**********************************************
  2.  "CPStyleText.h"
  3.  
  4.  by John A. Love, III [Ph.D. student]
  5.  
  6.  using Symantec's "THINK C / C++", v 6.Ø.1
  7.  based on Christopher R. Wysocki's "CPEditText"
  8.  **********************************************/
  9.  
  10.  
  11.  
  12. #pragma    once                        /* Include this file only once */
  13.  
  14.  
  15. #include <CArray.h>                    /* For line record data           */
  16.  
  17. #include <CScrollBar.h>                /* Superclasses ...               */
  18. #include "CPEditText.h"
  19. #include "CPEditScrollPane.h"
  20. #include "CTextStyleTask.h"
  21. /*
  22.     Miscellaneous constants included
  23.     by CPEditText.h:
  24.     
  25. #include "CPEditTextX.h"
  26. */
  27.  
  28. #include <CDocument.h>                /* For special utilities ...   */
  29. #include <CWindow.h>
  30.  
  31.  
  32. /*
  33.     More than the TCL default
  34.     because of word-wrap:
  35. */
  36. #define MIN_WINDOW_WIDTH    200
  37.  
  38. /*
  39.     More word-wrap stuff ...
  40. */
  41. #define kWillBeRefreshed    TRUE
  42. #define kWontBeRefreshed    FALSE
  43.  
  44.  
  45. /*
  46.     Substitutes for Chris' HorizInset and VertInset macros to
  47.     eliminate his built-in offsets.  Offsets should be controlled
  48.     ONLY via calls to ChangeSize, Offset, Place and similar methods.
  49. */
  50. #define HorizLeftInset()    (frame.left - position.h * hScale)
  51. #define VertTopInset()        (frame.top  - position.v * vScale)
  52.  
  53.  
  54. /*
  55.     Now, the beginning of the 'mother' of all additions ... style info ...
  56.     Before this addition is finished, it'll change many, many times.
  57.     For the moment, this is just a shell for us to chew on ...
  58.     
  59.     For example, we need to decide how we're going to save the style info.
  60.     Are we going to create a CResFile in our supervising CDocument and
  61.     attach it to our CDocument via _AddResource when saving it ...
  62.     or are we going to do repeated calls to CDataFile's WriteSome just as
  63.     John Lengyel does in his CDots code (MacTutor - August 1991)?
  64. */
  65.  
  66. #define MAX_LINES                65535L
  67. #define MAX_STYLES_PER_LINE        255L
  68.  
  69. #define atBeginning                -1L
  70. #define atEnd                    -65535L
  71.  
  72. typedef struct    StyleRecord
  73. {
  74.     short        sStart;                /* Beginning & end of Style Run ...    */
  75.     short        sEnd;
  76.     short        sHeight;
  77.     short        sFont;                /* ... aka TextStyle ...            */
  78.     short        sSize;
  79.     Style        sFace;
  80.     short        sMode;
  81.     RGBColor    sColor;
  82.     short        sMaxCharWidth;
  83.     
  84. }    StyleRecord, *StyleRecordPtr, **StyleRecordHdl;
  85.  
  86. typedef struct    LineRecord
  87. {
  88.     /*
  89.         There is one LineRecord per line and within each
  90.         line lStyles is an ordered array of StyleRecords.
  91.         Just as with TextEdit's TEStyleTable, this array
  92.         may NOT contain any duplicate elements.  Each
  93.         StyleRecord in lStyles corresponds one-to-one
  94.         with the styles in each line.
  95.     */
  96.     
  97.     CArray        *lStyles;
  98.     long        lSpacingCmd;
  99.     short        lHeight;
  100.     Fixed        lJustAmount;
  101.     short        lTabSpaces;
  102.     short        lTabWidth;
  103.     
  104. }    LineRecord, *LineRecordPtr, **LineRecordHdl;
  105.  
  106.  
  107.  
  108. class CPStyleText : public CPEditText
  109. {
  110. public:
  111.  
  112.                 /*
  113.                     An ordered array of LineRecords each of which
  114.                     corresponds one-to-one with the text in each
  115.                     <CR>-delimited line.  This is to say that
  116.                     word-wrapping to margins or to line lengths
  117.                     does NOT affect this array:
  118.                 */
  119.                 
  120.                 CArray        *itsLineInfo;
  121.                     
  122.                     
  123.                                     /** Construction/Destruction **/
  124.             void        IPStyleText (CView *anEnclosure, CBureaucrat *aSupervisor,
  125.                                      short aWidth, short aHeight,
  126.                                      short aHEncl, short aVEncl,
  127.                                      SizingOption aHSizing, SizingOption aVSizing,
  128.                                      short aLineWidth);
  129.     virtual void        IViewTemp (CView *anEnclosure, CBureaucrat *aSupervisor,
  130.                                    Ptr viewData);
  131.     
  132.     virtual void        Dispose (void);
  133.                                     
  134.                                     /** Display **/
  135.     virtual void        Draw (Rect *area);
  136.     virtual void        SetSelection (long selStart, long selEnd, Boolean fRedraw);
  137.  
  138.                                     /** Calibration **/
  139.     virtual void        UpdateMenus (void);
  140.     virtual void        ResizeFrame (Rect *delta);
  141.     virtual void        SetWholeLines (Boolean aWholeLines);
  142.     
  143.                                     /** Accessing **/
  144.     virtual void        SetBounds (LongRect *aBounds);
  145.     
  146.     virtual long        GetHeight (long startLine, long endLine);
  147.     
  148.     virtual long        GetCharOffset (LongPt *aPt);
  149.     virtual void        GetCharPoint (long offset, LongPt *aPt);
  150.  
  151.     virtual void        SetMargins (long leftMargin, long rightMargin);
  152.     virtual void        GetMargins (long *leftMargin, long *rightMargin);
  153.     
  154.                                     /** Mouse and Keystroke **/
  155.     virtual void        DoClick (Point hitPt, short modifierKeys, long when);
  156.     virtual void        DoKeyDown (char theChar, Byte keyCode, EventRecord *macEvent);
  157.     virtual void        TypeChar (char theChar, short theModifiers);
  158.     virtual void        DoArrowKey (char theChar, short theModifiers);
  159.                                     
  160.                                     /** Text Specification **/
  161.     virtual void        SetTextPtr (Ptr textPtr, long numChars);
  162.     virtual void        ReplaceSelection (Ptr replacePtr, long replaceLen);
  163.  
  164.                                     /** Word Wrap **/
  165.     virtual void        SetWordWrap (Boolean doWrap, long lineLengthInChars);
  166.     virtual Boolean        GetWordWrap (void);
  167.     virtual void        DoWordWrap (void);
  168.  
  169.                                     /** Styling **/
  170.     virtual void        SetSpacingCmd (long aSpacingCmd);
  171.     virtual void        SetAlignCmd (long anAlignCmd);
  172.     virtual void        SetAlignment (short anAlignment);
  173.     virtual long        GetAlignCmd (void);
  174.     
  175.     virtual    StScrpHandle    GetStyleScrap (void);
  176.     virtual void        SetStyleScrap (long rangeStart, long rangeEnd,
  177.                                        StScrpHandle styleScrap, Boolean redraw);
  178.     
  179.     virtual void        AddLine (long afterLine);
  180.     virtual void        DeleteLine (long lineNum);
  181.     virtual void        AddStyle (long lineNum, long afterStyleIndex,
  182.                                   StyleRecord *styleInfo);
  183.     virtual void        DeleteStyle (long lineNum, long styleIndex);
  184.     virtual void        GetStyleInfo (long lineNum, long styleIndex,
  185.                                       StyleRecord *styleInfo);
  186.     virtual void        SetStyleInfo (long lineNum, long styleIndex,
  187.                                       StyleRecord *styleInfo);
  188.     virtual Boolean        FindStyle (long startPos, long endPos,
  189.                                    long *startLine, long *endLine,
  190.                                    long *startIndex, long *endIndex);
  191.  
  192.     virtual void        SetFontNumber (short aFontNumber);
  193.     virtual void        SetFontSize (short aSize);
  194.     virtual void        SetFontStyle (short aStyle);
  195.     virtual void        SetTextMode (short aMode);
  196.     
  197.                                     /** Commands **/
  198.     virtual void        DoCommand (long theCommand);
  199.     virtual void        PerformEditCommand (long theCommand);
  200.     
  201.                                     /** One of Chris' Hook Methods **/
  202.     virtual void        CaretHook (const Rect *caretRect);
  203.  
  204.                                     /** Scrolling **/
  205.     virtual void        Scroll (long hDelta, long vDelta, Boolean redraw);
  206.     virtual void        ScrollToSelection (void);
  207.     virtual void        ScrollToOffset (long charOffset);
  208.  
  209.                                     /** Printing **/
  210.     virtual void        PrintPage (short pageNum, short pageWidth,
  211.                                    short pageHeight, CPrinter *aPrinter);
  212.     virtual void        DonePrinting (void);
  213.  
  214.                                 /** end Public Methods **/
  215.     
  216. protected:
  217.  
  218.                 long            itsAlignCmd;            /* Alignment NOW supported */
  219.                 long            itsLeftMargin;            /* Margins in pixels ...   */
  220.                 long            itsRightMargin;
  221.                 LongRect        itsViewRect;            /* For word-wrap ...       */
  222.                 LongRect        itsDestRect;
  223.                 Boolean            fWordWrap;
  224.                 Boolean            fOldEndWrapLineCaret;
  225.                 Boolean            fNewEndWrapLineCaret;
  226.                 Boolean            fEndWrapLine;
  227.                 
  228.                                     /**            Class Variables            **/
  229.                                     
  230.                                     /**        B&W + color cursors ...        **/
  231.                                     /**                                    **/
  232.                                     /** An idea generated from my use    **/
  233.                                     /** of Symantec's "THINK Reference"    **/
  234.                                     /** application.                    **/
  235.                                 
  236.     static CursHandle        cAutoScrollCursor;
  237.     static CCrsrHandle        cAutoScrollCRSR;
  238.     
  239.                                     /**            For styling info        **/
  240.                                     
  241.     static Boolean            cHasTrueType;
  242.  
  243.  
  244.                                     /** Construction/Destruction **/
  245.             void        IPStyleTextX (void);
  246.  
  247.                                     /** Commands **/
  248.     virtual CTextStyleTask    *MakeStyleTask (long styleCmd);
  249.     
  250.                                     /** Display **/
  251.             long        CountRangeSPACEs (long start, long end);
  252.     virtual void        DrawLineRange (long startLine, long endLine,
  253.                                        long startLineOffset, Boolean erase);
  254.     virtual ShortHandle    MeasureTextWidths (long startPos, long endPos,
  255.                                            short maxWidth);
  256.     virtual void        HiliteTextRange (long startChar, long endChar);
  257.     virtual void        CalcLineHeight (void);
  258.     virtual void        RefreshTextAfter (long afterPos, Boolean refreshOnlyLine);
  259.  
  260.                                     /** Word Wrap **/
  261.     virtual void        CalcLineStarts (void);
  262.     virtual void        RecalcLineStarts (void);
  263.     virtual void        WrapLineStarts (register long startLine,
  264.                                         register long endLine,
  265.                                         Boolean willBeRefreshed);
  266.     virtual void        AdjustLineStarts (long startChar, long numCharsDelta,
  267.                                           long numLinesDelta);
  268.     virtual void        CalcPERects (void);
  269.     virtual void        AdjustBounds (void);
  270.  
  271.                                     /**                  Caret Drawing                 **/
  272.                                     /**                                             **/
  273.                                     /** Modified Chris' DrawCaret method for     **/
  274.                                     /** drawing the caret at the end of a         **/
  275.                                     /** "sub-line" of a word-wrapped line.         **/
  276.                                     /** Chris' DrawCaret method is declared         **/
  277.                                     /** NON-virtual within his "CPEditText.h"     **/
  278.                                     /** interface file.  So the most simple! way **/
  279.                                     /** I can override it for both THINK C and     **/
  280.                                     /** Symantec C++ is to declare Chris'         **/
  281.                                     /** DrawCaret a virtual method within that     **/
  282.                                     /** interface file.                             **/
  283.     virtual void        DrawCaret (void);
  284.  
  285.                                 /** end Protected Methods **/
  286.     
  287. };    /* CPStyleText */
  288.  
  289.  
  290. class CPStyleScrollPane : CPEditScrollPane
  291. {
  292. public:
  293.  
  294.                                     /** Construction/Destruction **/
  295.             void        IPStyleScrollPane (CView *anEnclosure,
  296.                                            CBureaucrat *aSupervisor,
  297.                                            short aWidth, short aHeight,
  298.                                            short aHEncl, short aVEncl,
  299.                                            SizingOption aHSizing,
  300.                                            SizingOption aVSizing,
  301.                                            Boolean hasHoriz, Boolean hasVert,
  302.                                            Boolean hasSizeBox);
  303.  
  304.             void        IPStyleScrollPaneX (Boolean hasHoriz, Boolean hasVert,
  305.                                             Boolean hasSizeBox);
  306.  
  307. };    /* CPStyleScrollPane */
  308.  
  309.  
  310. class CPStyleScrollBar : CScrollBar
  311. {
  312. public:
  313.  
  314.                                     /** Contruction/Destruction **/
  315.             void        IPStyleScrollBar (CView *anEnclosure,
  316.                                           CBureaucrat *aSupervisor,
  317.                                           Orientation anOrientation, short aLength,
  318.                                           short aHEncl, short aVEncl);
  319.     
  320.                                     /** Mouse and Keystroke **/
  321.     virtual void        DoClick (Point hitPt, short modifierKeys, long when);
  322.  
  323. };    /* CPStyleScrollBar */
  324.  
  325.  
  326. class CStylePStyleTask : public CTextStyleTask
  327. {
  328.     /*
  329.         Construct a new sub-class for CAbstractText's stylable CTask
  330.         because of the sensitivity of word-wrap to various commands,
  331.         such as a new font size and a new font style.  This new
  332.         sibling looks VERY similar to the TCL's CStyleTEStyleTask
  333.         which is created by the TextEdit class = CStyleText.
  334.     */
  335.                 
  336. public:
  337.  
  338.             void        IStylePStyleTask (CPStyleText *aTextPane,
  339.                                           long aStyleCmd, short firstTaskIndex);
  340.     virtual void        Dispose (void);
  341.             
  342.     virtual void        Do (void);
  343.     virtual void        Undo (void);
  344.     
  345. protected:
  346.  
  347.                 StScrpHandle    oldStyles;
  348.                 long            selStart, selEnd;
  349.             
  350.     virtual void        SaveStyle (void);
  351.     virtual void        RestoreStyle (void);
  352.     
  353. };    /* CStylePStyleTask */
  354.  
  355.  
  356. /****   G E N E R A L   U T I L I T I E S   ****/
  357.  
  358.             void    DirtyWindow (CWindow *theWindow);
  359.             void    DirtyDocument (CDocument *theDocument);
  360.             void    UndirtyWindow (CWindow *theWindow);
  361.             void    UndirtyDocument (CDocument *theDocument);
  362.  
  363.  
  364.  
  365.  
  366. /*    { end file "CPStyleText.h" }  */
  367.