1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
|
/* This file is part of the KDE libraries
Copyright (C) 2003 Hamish Rodda <[email protected]>
Copyright (C) 2001 Christoph Cullmann <[email protected]>
Copyright (C) 2001 Joseph Wenninger <[email protected]>
Copyright (C) 1999 Jochen Wilhelmy <[email protected]>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef __KATE_RENDERER_H__
#define __KATE_RENDERER_H__
#include "katecursor.h"
#include "kateattribute.h"
#include "katetextline.h"
#include <tqfont.h>
#include <tqfontmetrics.h>
class KateDocument;
class KateView;
class KateLineRange;
class KateRendererConfig;
/**
* Handles all of the work of rendering the text
* (used for the views and printing)
*
**/
class KateRenderer
{
public:
/**
* Style of Caret (Insert or Replace mode)
*/
enum caretStyles {
Insert,
Replace
};
/**
* Constructor
* @param doc document to render
* @param view view which is output (0 for example for rendering to print)
*/
KateRenderer(KateDocument* doc, KateView *view = 0);
/**
* Destructor
*/
~KateRenderer();
/**
* update the highlighting attributes
* (for example after an hl change or after hl config changed)
*/
void updateAttributes ();
/**
* Determine whether the caret (text cursor) will be drawn.
* @return should it be drawn?
*/
inline bool drawCaret() const { return m_drawCaret; }
/**
* Set whether the caret (text cursor) will be drawn.
* @param drawCaret should caret be drawn?
*/
void setDrawCaret(bool drawCaret);
/**
* The style of the caret (text cursor) to be painted.
* @return caretStyle
*/
inline KateRenderer::caretStyles caretStyle() const { return m_caretStyle; }
/**
* Set the style of caret to be painted.
* @param style style to set
*/
void setCaretStyle(KateRenderer::caretStyles style);
/**
* @returns whether tabs should be shown (ie. a small mark
* drawn to identify a tab)
* @return tabs should be shown
*/
inline bool showTabs() const { return m_showTabs; }
/**
* Set whether a mark should be painted to help identifying tabs.
* @param showTabs show the tabs?
*/
void setShowTabs(bool showTabs);
/**
* Sets the width of the tab. Helps performance.
* @param tabWidth new tab width
*/
void setTabWidth(int tabWidth);
/**
* @returns whether indent lines should be shown
* @return indent lines should be shown
*/
bool showIndentLines() const;
/**
* Set whether a guide should be painted to help identifying indent lines.
* @param showLines show the indent lines?
*/
void setShowIndentLines(bool showLines);
/**
* Sets the width of the tab. Helps performance.
* @param indentWidth new indent width
*/
void setIndentWidth(int indentWidth);
/**
* Show the view's selection?
* @return show sels?
*/
inline bool showSelections() const { return m_showSelections; }
/**
* Set whether the view's selections should be shown.
* The default is true.
* @param showSelections show the selections?
*/
void setShowSelections(bool showSelections);
/**
* Change to a different font (soon to be font set?)
*/
void increaseFontSizes();
void decreaseFontSizes();
const TQFont* currentFont();
const TQFontMetrics* currentFontMetrics();
/**
* @return whether the renderer is configured to paint in a
* printer-friendly fashion.
*/
bool isPrinterFriendly() const;
/**
* Configure this renderer to paint in a printer-friendly fashion.
*
* Sets the other options appropriately if true.
*/
void setPrinterFriendly(bool printerFriendly);
/**
* Text width & height calculation functions...
*/
// Width calculators
uint spaceWidth();
uint textWidth(const KateTextLine::Ptr &, int cursorCol);
uint textWidth(const KateTextLine::Ptr &textLine, uint startcol, uint maxwidth, bool *needWrap, int *endX = 0);
uint textWidth(const KateTextCursor &cursor);
// Cursor constrainer
uint textWidth(KateTextCursor &cursor, int xPos, uint startCol = 0);
// Column calculators
/**
* @return the index of the character at the horixontal position @p xpos
* in @p line.
*
* If @p nearest is true, the character starting nearest to
* @p xPos is returned. If @p nearest is false, the index of the character
* containing @p xPos is returned.
**/
uint textPos(uint line, int xPos, uint startCol = 0, bool nearest=true);
/**
* @overload
*/
uint textPos(const KateTextLine::Ptr &, int xPos, uint startCol = 0, bool nearest=true);
// Font height
uint fontHeight();
// Document height
uint documentHeight();
// Selection boundaries
bool getSelectionBounds(uint line, uint lineLength, uint &start, uint &end);
/**
* This is the ultimate function to perform painting of a text line.
* (supports startcol/endcol, startx/endx)
*
* The text line is painted from the upper limit of (0,0). To move that,
* apply a transform to your painter.
*/
void paintTextLine(TQPainter& paint, const KateLineRange* range, int xStart, int xEnd, const KateTextCursor* cursor = 0L, const KateBracketRange* bracketmark = 0L);
/**
* Paint the background of a line
*
* Split off from the main @ref paintTextLine method to make it smaller. As it's being
* called only once per line it shouldn't noticably affect performance and it
* helps readability a LOT.
*
* @return whether the selection has been painted or not
*/
bool paintTextLineBackground(TQPainter& paint, int line, bool isCurrentLine, int xStart, int xEnd);
/**
* This takes an in index, and returns all the attributes for it.
* For example, if you have a ktextline, and want the KateAttribute
* for a given position, do:
*
* attribute(myktextline->attribute(position));
*/
KateAttribute* attribute(uint pos);
private:
/**
* Paint a whitespace marker on position (x, y).
*
* Currently only used by the tabs, but it will also be used for highlighting trailing whitespace
*/
void paintWhitespaceMarker(TQPainter &paint, uint x, uint y);
/** Paint a SciTE-like indent marker. */
void paintIndentMarker(TQPainter &paint, uint x, uint y);
KateDocument* m_doc;
KateView *m_view;
// cache of config values
int m_tabWidth;
int m_indentWidth;
uint m_schema;
// some internal flags
KateRenderer::caretStyles m_caretStyle;
bool m_drawCaret;
bool m_showSelections;
bool m_showTabs;
bool m_printerFriendly;
TQMemArray<KateAttribute> *m_attributes;
/**
* Configuration
*/
public:
inline KateRendererConfig *config () { return m_config; };
void updateConfig ();
private:
KateRendererConfig *m_config;
};
#endif
|