1 /*
2  *  Yudit Unicode Editor Source File
3  *
4  *  GNU Copyright (C) 1997-2006  Gaspar Sinai <gaspar@yudit.org>
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License, version 2,
8  *  dated June 1991. See file COPYYING for details.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program; if not, write to the Free Software
17  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */
19 
20 #ifndef STextView_h
21 #define STextView_h
22 
23 #include "stoolkit/STextIndex.h"
24 #include "stoolkit/SCursorIndex.h"
25 #include "stoolkit/STextData.h"
26 #include "stoolkit/STypes.h"
27 #include "swidget/SComponent.h"
28 #include "swindow/SFont.h"
29 #include "swindow/SWindow.h"
30 #include "swindow/SSyntaxColors.h"
31 #include "stoolkit/syntax/SSyntax.h"
32 
33 typedef SBinHashtable<SS_UINT> SH_UINT;
34 
35 /**
36  * Provide a widget view to STextData
37  */
38 class STextView : public SComponent, STextDataListener
39 {
40 public:
41   STextView (void);
42   STextView (const SString& utf8);
43   virtual ~STextView ();
44 
45   /* Every component has this. */
46   virtual void redraw (SCanvas *canvas, int x, int y,
47         unsigned int width, unsigned int height);
48 
49   void setFont (const SString& font, double fontSize=0.0);
50   void setFontSize (double fontSize);
51 
52   void setForeground (const SColor& lrfg, const SColor& rlfg);
53   virtual void setBackground (const SColor& bg);
54 
55   const SColor& getBackground ();
56   const SColor& getForeground (bool lr);
57 
58   void setAlignment (bool align);
59   void setMultiline (bool multiline);
60   bool isMultiline () const;
61 
62   void setViewPort (const SLocation& viewPort);
63   const SLocation& getViewPort();
64 
65   virtual void resize (const SDimension& d);
66 
67   SCursorIndex getCursorIndex (const SLocation& l);
68   SLocation  getCursorLocation (const SCursorIndex& cursorIndex);
69 
70   SCursorIndex leftOf (const SCursorIndex& ci);
71   SCursorIndex rightOf (const SCursorIndex& ci);
72 
73   void setLineEndMark (bool lineend);
74   bool getLineEndMark () const;
75 
76   unsigned int getDocumentHeight () const;
77 
78   void setSyntax (const SString& hlMode);
79   const SString&  getSyntax () const;
80 
81   void setSyntaxColors (const SSyntaxColors& attr);
82   const SSyntaxColors&  getSyntaxColors () const;
83 
84   void setWordWrap (bool lbm);
85   bool getWordWrap () const;
86 
87   STextData textData;
88   unsigned int lineHeight;
89   unsigned int lineAscent;
90 
91   void setUnderlineColor (const SColor& c);
92   void setClippingArea (int x, int y,
93           unsigned int width, unsigned int height);
94 
addSyntaxListener(SSyntaxListener * _listener)95   void addSyntaxListener (SSyntaxListener* _listener)
96      { syntax.addSyntaxListener (_listener); }
97 
98   void setEditable (bool editable);
99   void setText (const SString& text);
100 
getSyntaxName()101   SString getSyntaxName () const
102   {
103      return syntax.getParser ();
104   }
getHighlightName()105   SString getHighlightName () const
106   {
107      return highlightMode;
108   }
109 
setPrinterPageSize(unsigned int _ps)110   void setPrinterPageSize (unsigned int _ps)
111    { printerPageSize = _ps; }
112 
113   void setHideText(bool is);
114   bool isHideText();
115 
116 
117 private:
118   SSyntaxColors     syntaxColors;
119   SString           highlightMode;
120   SSyntax           syntax;
121   bool              isWordWrapOn;
122   bool              isEditable;
123   bool              isHidingText;
124   unsigned int      printerPageSize;
125 
126   SCursorIndex moveCursor (const SCursorIndex& ci, bool up);
127 
128   unsigned int getLineIndex (int locy);
129   void internalRedraw (SCanvas *canvas, int x, int y,
130         unsigned int width, unsigned int height);
131   void setVisible (unsigned int line);
132   SLocation getTextLocation (const STextIndex& textIndex, bool before=true);
133 
134   void setPen();
135   /* STextDataListener */
136   void textChanged (void* src, const STextDataEvent& event);
137   void textChangedInternal (void* src, const STextDataEvent& event);
138 
139   unsigned int drawParagraph (SCanvas* c, bool islr, unsigned int line,
140        const SLocation& l, const SLocation& lb,
141        const SLocation& le, bool iswindow=false);
142 
143 
144   void drawGlyph (SCanvas* c, SLocation& l, unsigned int ext, STextIndex index);
145 
146 
147 
148   void syntaxHighlight(STextIndex index, SPen* pen, bool* isError);
149   bool checktext(STextIndex index, const char* checkstring);
150 
151 
152   void   setReordered();
153   void   wrapAndPosition ();
154   void   wrapAndPosition (unsigned int from, unsigned int until, int addcount);
155   unsigned int  wrapAndPosition (unsigned int line, SH_UINT* cache);
156 
157   SFont                font;
158   SPen                 lrpen;
159   SPen                 rlpen;
160   SLocation            viewPort;
161   SColor               underlineColor;
162 
163   /* per line based arrays */
164   SV_UINT              lineSpan; /* how many lines? */
165   SVector<SV_UINT>     posBefore;  /* glyph locations */
166   SVector<SV_UINT>     posAfter;  /* glyph locations */
167   SVector<SV_UINT>     breaks;   /* linebreaks */
168 
169   double               fontSize;
170 
171   int clipx; int clipy;
172   int clipw; int cliph;
173 
174   bool                 alignment;
175   bool                 multiline;
176   bool                 lineend;
177 };
178 
179 #endif /* STextView_h */
180