]>
Commit | Line | Data |
---|---|---|
fe45b493 RD |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: _richtextbuffer.i | |
3 | // Purpose: wxRichTextAttr | |
4 | // | |
5 | // Author: Robin Dunn | |
6 | // | |
7 | // Created: 11-April-2006 | |
8 | // RCS-ID: $Id$ | |
9 | // Copyright: (c) 2006 by Total Control Software | |
10 | // Licence: wxWindows license | |
11 | ///////////////////////////////////////////////////////////////////////////// | |
12 | ||
13 | // Not a %module | |
14 | ||
15 | ||
16 | //--------------------------------------------------------------------------- | |
17 | ||
18 | %{ | |
19 | #include <wx/sstream.h> | |
20 | #include "wx/wxPython/pyistream.h" | |
21 | %} | |
22 | ||
23 | //--------------------------------------------------------------------------- | |
24 | %newgroup | |
25 | ||
26 | enum { | |
27 | /*! | |
28 | * File types | |
29 | */ | |
30 | wxRICHTEXT_TYPE_ANY, | |
31 | wxRICHTEXT_TYPE_TEXT, | |
32 | wxRICHTEXT_TYPE_XML, | |
33 | wxRICHTEXT_TYPE_HTML, | |
34 | wxRICHTEXT_TYPE_RTF, | |
35 | wxRICHTEXT_TYPE_PDF, | |
36 | ||
37 | /*! | |
38 | * Flags determining the available space, passed to Layout | |
39 | */ | |
40 | wxRICHTEXT_FIXED_WIDTH, | |
41 | wxRICHTEXT_FIXED_HEIGHT, | |
42 | wxRICHTEXT_VARIABLE_WIDTH, | |
43 | wxRICHTEXT_VARIABLE_HEIGHT, | |
44 | ||
45 | ||
46 | wxRICHTEXT_LAYOUT_SPECIFIED_RECT, | |
47 | wxRICHTEXT_DRAW_IGNORE_CACHE, | |
48 | ||
49 | ||
50 | /*! | |
51 | * Flags returned from hit-testing | |
52 | */ | |
53 | wxRICHTEXT_HITTEST_NONE, | |
54 | wxRICHTEXT_HITTEST_BEFORE, | |
55 | wxRICHTEXT_HITTEST_AFTER, | |
56 | wxRICHTEXT_HITTEST_ON, | |
57 | wxRICHTEXT_HITTEST_OUTSIDE, | |
58 | ||
59 | /*! | |
60 | * Flags for GetRangeSize | |
61 | */ | |
62 | wxRICHTEXT_FORMATTED, | |
63 | wxRICHTEXT_UNFORMATTED, | |
64 | ||
65 | /*! | |
66 | * Flags for SetStyle/SetListStyle | |
67 | */ | |
68 | wxRICHTEXT_SETSTYLE_NONE, | |
69 | wxRICHTEXT_SETSTYLE_WITH_UNDO, | |
70 | wxRICHTEXT_SETSTYLE_OPTIMIZE, | |
71 | wxRICHTEXT_SETSTYLE_PARAGRAPHS_ONLY, | |
72 | wxRICHTEXT_SETSTYLE_CHARACTERS_ONLY, | |
73 | wxRICHTEXT_SETSTYLE_RENUMBER, | |
74 | wxRICHTEXT_SETSTYLE_SPECIFY_LEVEL, | |
75 | wxRICHTEXT_SETSTYLE_RESET, | |
76 | wxRICHTEXT_SETSTYLE_REMOVE, | |
77 | ||
78 | /*! | |
79 | * Flags for text insertion | |
80 | */ | |
81 | wxRICHTEXT_INSERT_NONE, | |
82 | wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE, | |
83 | ||
84 | ||
85 | // TODO: Rename these to be wxRICHTEXT_* ?? | |
86 | ||
87 | wxTEXT_ATTR_TEXT_COLOUR, | |
88 | wxTEXT_ATTR_BACKGROUND_COLOUR, | |
89 | wxTEXT_ATTR_FONT_FACE, | |
90 | wxTEXT_ATTR_FONT_SIZE, | |
91 | wxTEXT_ATTR_FONT_WEIGHT, | |
92 | wxTEXT_ATTR_FONT_ITALIC, | |
93 | wxTEXT_ATTR_FONT_UNDERLINE, | |
94 | wxTEXT_ATTR_FONT, | |
95 | wxTEXT_ATTR_ALIGNMENT, | |
96 | wxTEXT_ATTR_LEFT_INDENT, | |
97 | wxTEXT_ATTR_RIGHT_INDENT, | |
98 | wxTEXT_ATTR_TABS, | |
99 | ||
100 | wxTEXT_ATTR_PARA_SPACING_AFTER, | |
101 | wxTEXT_ATTR_PARA_SPACING_BEFORE, | |
102 | wxTEXT_ATTR_LINE_SPACING, | |
103 | wxTEXT_ATTR_CHARACTER_STYLE_NAME, | |
104 | wxTEXT_ATTR_PARAGRAPH_STYLE_NAME, | |
105 | wxTEXT_ATTR_BULLET_STYLE, | |
106 | wxTEXT_ATTR_BULLET_NUMBER, | |
107 | wxTEXT_ATTR_BULLET_TEXT, | |
108 | wxTEXT_ATTR_BULLET_NAME, | |
109 | wxTEXT_ATTR_URL, | |
110 | wxTEXT_ATTR_PAGE_BREAK, | |
111 | wxTEXT_ATTR_EFFECTS, | |
112 | wxTEXT_ATTR_OUTLINE_LEVEL, | |
113 | ||
114 | /*! | |
115 | * Styles for wxTextAttrEx::SetBulletStyle | |
116 | */ | |
117 | wxTEXT_ATTR_BULLET_STYLE_NONE, | |
118 | wxTEXT_ATTR_BULLET_STYLE_ARABIC, | |
119 | wxTEXT_ATTR_BULLET_STYLE_LETTERS_UPPER, | |
120 | wxTEXT_ATTR_BULLET_STYLE_LETTERS_LOWER, | |
121 | wxTEXT_ATTR_BULLET_STYLE_ROMAN_UPPER, | |
122 | wxTEXT_ATTR_BULLET_STYLE_ROMAN_LOWER, | |
123 | wxTEXT_ATTR_BULLET_STYLE_SYMBOL, | |
124 | wxTEXT_ATTR_BULLET_STYLE_BITMAP, | |
125 | wxTEXT_ATTR_BULLET_STYLE_PARENTHESES, | |
126 | wxTEXT_ATTR_BULLET_STYLE_PERIOD, | |
127 | wxTEXT_ATTR_BULLET_STYLE_STANDARD, | |
128 | wxTEXT_ATTR_BULLET_STYLE_RIGHT_PARENTHESIS, | |
129 | wxTEXT_ATTR_BULLET_STYLE_OUTLINE, | |
130 | ||
131 | wxTEXT_ATTR_BULLET_STYLE_ALIGN_LEFT, | |
132 | wxTEXT_ATTR_BULLET_STYLE_ALIGN_RIGHT, | |
133 | wxTEXT_ATTR_BULLET_STYLE_ALIGN_CENTRE, | |
134 | ||
135 | /*! | |
136 | * Styles for wxTextAttrEx::SetTextEffects | |
137 | */ | |
138 | wxTEXT_ATTR_EFFECT_NONE, | |
139 | wxTEXT_ATTR_EFFECT_CAPITALS, | |
140 | wxTEXT_ATTR_EFFECT_SMALL_CAPITALS, | |
141 | wxTEXT_ATTR_EFFECT_STRIKETHROUGH, | |
142 | wxTEXT_ATTR_EFFECT_DOUBLE_STRIKETHROUGH, | |
143 | wxTEXT_ATTR_EFFECT_SHADOW, | |
144 | wxTEXT_ATTR_EFFECT_EMBOSS, | |
145 | wxTEXT_ATTR_EFFECT_OUTLINE, | |
146 | wxTEXT_ATTR_EFFECT_ENGRAVE, | |
147 | wxTEXT_ATTR_EFFECT_SUPERSCRIPT, | |
148 | wxTEXT_ATTR_EFFECT_SUBSCRIPT, | |
149 | ||
150 | /*! | |
151 | * Line spacing values | |
152 | */ | |
153 | wxTEXT_ATTR_LINE_SPACING_NORMAL, | |
154 | wxTEXT_ATTR_LINE_SPACING_HALF, | |
155 | wxTEXT_ATTR_LINE_SPACING_TWICE, | |
156 | ||
157 | /*! | |
158 | * Character and paragraph combined styles | |
159 | */ | |
160 | wxTEXT_ATTR_CHARACTER, | |
161 | wxTEXT_ATTR_PARAGRAPH, | |
162 | wxTEXT_ATTR_ALL, | |
163 | ||
164 | }; | |
165 | ||
166 | ||
167 | //--------------------------------------------------------------------------- | |
168 | %newgroup | |
169 | ||
170 | ||
171 | ||
172 | %typemap(in) wxRichTextRange& (wxRichTextRange temp) { | |
173 | $1 = &temp; | |
174 | if ( ! wxRichTextRange_helper($input, &$1)) SWIG_fail; | |
175 | } | |
176 | %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxRichTextRange& { | |
177 | $1 = wxPySimple_typecheck($input, wxT("wxRichTextRange"), 2); | |
178 | } | |
179 | ||
180 | ||
181 | %{ | |
182 | bool wxRichTextRange_helper(PyObject* source, wxRichTextRange** obj) | |
183 | { | |
184 | if (source == Py_None) { | |
185 | **obj = wxRICHTEXT_NONE; | |
186 | return true; | |
187 | } | |
188 | return wxPyTwoIntItem_helper(source, obj, wxT("wxRichTextRange")); | |
189 | } | |
190 | %} | |
191 | ||
192 | ||
193 | ||
194 | DocStr(wxRichTextRange, | |
195 | "RichTextRange is a data structure that represents a range of text | |
196 | within a `RichTextCtrl`. It simply contains integer ``start`` and | |
197 | ``end`` properties and a few operations useful for dealing with | |
198 | ranges. In most places in wxPython where a RichTextRange is expected a | |
199 | 2-tuple containing (start, end) can be used instead.", ""); | |
200 | ||
201 | // Turn off the generation of code that aquires the Global Interpreter Lock | |
202 | %threadWrapperOff | |
203 | ||
204 | class wxRichTextRange | |
205 | { | |
206 | public: | |
207 | DocCtorStr( | |
208 | wxRichTextRange(long start=0, long end=0), | |
209 | "Creates a new range object.", ""); | |
210 | ||
211 | ~wxRichTextRange(); | |
212 | ||
213 | %extend { | |
214 | DocStr(__eq__, "Test for equality of RichTextRange objects.", ""); | |
215 | bool __eq__(PyObject* other) { | |
216 | wxRichTextRange temp, *obj = &temp; | |
217 | if ( other == Py_None ) return false; | |
218 | if ( ! wxRichTextRange_helper(other, &obj) ) { | |
219 | PyErr_Clear(); | |
220 | return false; | |
221 | } | |
222 | return self->operator==(*obj); | |
223 | } | |
224 | } | |
225 | ||
226 | ||
227 | DocDeclStr( | |
228 | wxRichTextRange , operator -(const wxRichTextRange& range) const, | |
229 | "", ""); | |
230 | ||
231 | DocDeclStr( | |
232 | wxRichTextRange , operator +(const wxRichTextRange& range) const, | |
233 | "", ""); | |
234 | ||
235 | ||
236 | DocDeclStr( | |
237 | void , SetRange(long start, long end), | |
238 | "", ""); | |
239 | ||
240 | ||
241 | DocDeclStr( | |
242 | void , SetStart(long start), | |
243 | "", ""); | |
244 | DocDeclStr( | |
245 | long , GetStart() const, | |
246 | "", ""); | |
247 | %pythoncode { start = property(GetStart, SetStart) } | |
248 | ||
249 | ||
250 | DocDeclStr( | |
251 | void , SetEnd(long end), | |
252 | "", ""); | |
253 | DocDeclStr( | |
254 | long , GetEnd() const, | |
255 | "", ""); | |
256 | %pythoncode { end = property(GetEnd, SetEnd) } | |
257 | ||
258 | ||
259 | DocDeclStr( | |
260 | bool , IsOutside(const wxRichTextRange& range) const, | |
261 | "Returns true if this range is completely outside 'range'", ""); | |
262 | ||
263 | ||
264 | DocDeclStr( | |
265 | bool , IsWithin(const wxRichTextRange& range) const, | |
266 | "Returns true if this range is completely within 'range'", ""); | |
267 | ||
268 | ||
269 | DocDeclStr( | |
270 | bool , Contains(long pos) const, | |
271 | "Returns true if the given position is within this range. Allow for the | |
272 | possibility of an empty range - assume the position is within this | |
273 | empty range.", ""); | |
274 | ||
275 | ||
276 | DocDeclStr( | |
277 | bool , LimitTo(const wxRichTextRange& range) , | |
278 | "Limit this range to be within 'range'", ""); | |
279 | ||
280 | ||
281 | DocDeclStr( | |
282 | long , GetLength() const, | |
283 | "Gets the length of the range", ""); | |
284 | ||
285 | ||
286 | DocDeclStr( | |
287 | void , Swap(), | |
288 | "Swaps the start and end", ""); | |
289 | ||
290 | ||
291 | DocDeclStr( | |
292 | wxRichTextRange , ToInternal() const, | |
293 | "Convert to internal form: (n, n) is the range of a single character.", ""); | |
294 | ||
295 | ||
296 | DocDeclStr( | |
297 | wxRichTextRange , FromInternal() const, | |
298 | "Convert from internal to public API form: (n, n+1) is the range of a | |
299 | single character.", ""); | |
300 | ||
301 | ||
302 | %extend { | |
303 | DocAStr(Get, | |
304 | "Get() -> (start,end)", | |
305 | "Returns the start and end properties as a tuple.", ""); | |
306 | PyObject* Get() { | |
307 | PyObject* tup = PyTuple_New(2); | |
308 | PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->GetStart())); | |
309 | PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->GetEnd())); | |
310 | return tup; | |
311 | } | |
312 | } | |
313 | %pythoncode { | |
314 | def __str__(self): return str(self.Get()) | |
315 | def __repr__(self): return 'RichTextRange'+str(self.Get()) | |
316 | def __len__(self): return len(self.Get()) | |
317 | def __getitem__(self, index): return self.Get()[index] | |
318 | def __setitem__(self, index, val): | |
319 | if index == 0: self.start = val | |
320 | elif index == 1: self.end = val | |
321 | else: raise IndexError | |
322 | def __nonzero__(self): return self.Get() != (0,0) | |
323 | __safe_for_unpickling__ = True | |
324 | def __reduce__(self): return (RichTextRange, self.Get()) | |
325 | } | |
326 | ||
327 | %property(End, GetEnd, SetEnd, doc="See `GetEnd` and `SetEnd`"); | |
328 | %property(Length, GetLength, doc="See `GetLength`"); | |
329 | %property(Start, GetStart, SetStart, doc="See `GetStart` and `SetStart`"); | |
330 | }; | |
331 | ||
332 | ||
333 | ||
334 | %{ | |
335 | wxRichTextRange wxPy_RTR_ALL(wxRICHTEXT_ALL); | |
336 | wxRichTextRange wxPy_RTR_NONE(wxRICHTEXT_NONE); | |
337 | %} | |
338 | ||
339 | %rename(RICHTEXT_ALL) wxPy_RTR_ALL; | |
340 | %rename(RICHTEXT_NONE) wxPy_RTR_NONE; | |
341 | ||
342 | %immutable; | |
343 | wxRichTextRange wxPy_RTR_ALL; | |
344 | wxRichTextRange wxPy_RTR_NONE; | |
345 | %mutable; | |
346 | ||
347 | // Turn back on the generation of code that aquires the Global Interpreter Lock | |
348 | %threadWrapperOn | |
349 | ||
350 | ||
351 | ||
352 | ||
353 | //--------------------------------------------------------------------------- | |
354 | %newgroup | |
355 | ||
356 | ||
357 | DocStr(wxRichTextAttr, | |
358 | "The RichTextAttr class stores information about the various attributes | |
359 | for a block of text, including font, colour, indents, alignments, and | |
360 | etc.", ""); | |
361 | ||
362 | class wxRichTextAttr | |
363 | { | |
364 | public: | |
365 | ||
366 | wxRichTextAttr(const wxColour& colText = wxNullColour, | |
367 | const wxColour& colBack = wxNullColour, | |
368 | wxTextAttrAlignment alignment = wxTEXT_ALIGNMENT_DEFAULT); | |
369 | ||
370 | ~wxRichTextAttr(); | |
371 | ||
372 | // // Making a wxTextAttrEx object. | |
373 | // operator wxTextAttrEx () const ; | |
374 | ||
375 | // // Copy to a wxTextAttr | |
376 | // void CopyTo(wxTextAttrEx& attr) const; | |
377 | ||
378 | ||
379 | DocDeclStr( | |
380 | void , Init(), | |
381 | "Initialise this object.", ""); | |
382 | ||
383 | ||
384 | DocDeclStr( | |
385 | void , Copy(const wxRichTextAttr& attr), | |
386 | "Copy from attr to self.", ""); | |
387 | ||
388 | ||
389 | // Equality test | |
390 | bool operator== (const wxRichTextAttr& attr) const; | |
391 | ||
392 | ||
393 | ||
394 | DocDeclStr( | |
395 | wxFont , CreateFont() const, | |
396 | "Create font from the font attributes in this attr object.", ""); | |
397 | ||
398 | ||
399 | DocDeclStr( | |
400 | bool , GetFontAttributes(const wxFont& font), | |
401 | "Set our font attributes from the font.", ""); | |
402 | ||
403 | ||
404 | %pythoncode { | |
405 | def GetFont(self): | |
406 | return self.CreateFont() | |
407 | def SetFont(self, font): | |
408 | return self.GetFontAttributes(font) | |
409 | } | |
410 | ||
411 | // setters | |
412 | void SetTextColour(const wxColour& colText); | |
413 | void SetBackgroundColour(const wxColour& colBack); | |
414 | void SetAlignment(wxTextAttrAlignment alignment); | |
415 | void SetTabs(const wxArrayInt& tabs); | |
416 | void SetLeftIndent(int indent, int subIndent = 0); | |
417 | void SetRightIndent(int indent); | |
418 | ||
419 | void SetFontSize(int pointSize); | |
420 | void SetFontStyle(int fontStyle); | |
421 | void SetFontWeight(int fontWeight); | |
422 | void SetFontFaceName(const wxString& faceName); | |
423 | void SetFontUnderlined(bool underlined); | |
424 | ||
425 | void SetFlags(long flags); | |
426 | ||
427 | void SetCharacterStyleName(const wxString& name); | |
428 | void SetParagraphStyleName(const wxString& name); | |
429 | void SetListStyleName(const wxString& name); | |
430 | void SetParagraphSpacingAfter(int spacing); | |
431 | void SetParagraphSpacingBefore(int spacing); | |
432 | void SetLineSpacing(int spacing); | |
433 | void SetBulletStyle(int style); | |
434 | void SetBulletNumber(int n); | |
435 | void SetBulletText(wxChar symbol); | |
436 | void SetBulletFont(const wxString& bulletFont); | |
437 | void SetBulletName(const wxString& name); | |
438 | void SetURL(const wxString& url); | |
439 | void SetPageBreak(bool pageBreak = true); | |
440 | void SetTextEffects(int effects); | |
441 | void SetTextEffectFlags(int effects); | |
442 | void SetOutlineLevel(int level); | |
443 | ||
444 | const wxColour& GetTextColour() const; | |
445 | const wxColour& GetBackgroundColour() const; | |
446 | wxTextAttrAlignment GetAlignment() const; | |
447 | const wxArrayInt& GetTabs() const; | |
448 | long GetLeftIndent() const; | |
449 | long GetLeftSubIndent() const; | |
450 | long GetRightIndent() const; | |
451 | long GetFlags() const; | |
452 | ||
453 | int GetFontSize() const; | |
454 | int GetFontStyle() const; | |
455 | int GetFontWeight() const; | |
456 | bool GetFontUnderlined() const; | |
457 | const wxString& GetFontFaceName() const; | |
458 | ||
459 | const wxString& GetCharacterStyleName() const; | |
460 | const wxString& GetParagraphStyleName() const; | |
461 | const wxString& GetListStyleName() const; | |
462 | int GetParagraphSpacingAfter() const; | |
463 | int GetParagraphSpacingBefore() const; | |
464 | int GetLineSpacing() const; | |
465 | int GetBulletStyle() const; | |
466 | int GetBulletNumber() const; | |
467 | const wxString& GetBulletText() const; | |
468 | const wxString& GetBulletFont() const; | |
469 | const wxString& GetBulletName() const; | |
470 | const wxString& GetURL() const; | |
471 | int GetTextEffects() const; | |
472 | int GetTextEffectFlags() const; | |
473 | int GetOutlineLevel() const; | |
474 | ||
475 | // accessors | |
476 | bool HasTextColour() const; | |
477 | bool HasBackgroundColour() const; | |
478 | bool HasAlignment() const; | |
479 | bool HasTabs() const; | |
480 | bool HasLeftIndent() const; | |
481 | bool HasRightIndent() const; | |
482 | bool HasFontWeight() const; | |
483 | bool HasFontSize() const; | |
484 | bool HasFontItalic() const; | |
485 | bool HasFontUnderlined() const; | |
486 | bool HasFontFaceName() const; | |
487 | bool HasFont() const; | |
488 | ||
489 | bool HasParagraphSpacingAfter() const; | |
490 | bool HasParagraphSpacingBefore() const; | |
491 | bool HasLineSpacing() const; | |
492 | bool HasCharacterStyleName() const; | |
493 | bool HasParagraphStyleName() const; | |
494 | bool HasListStyleName() const; | |
495 | bool HasBulletStyle() const; | |
496 | bool HasBulletNumber() const; | |
497 | bool HasBulletText() const; | |
498 | bool HasBulletName() const; | |
499 | bool HasURL() const; | |
500 | bool HasPageBreak() const; | |
501 | bool HasTextEffects() const; | |
502 | bool HasTextEffect(int effect) const; | |
503 | bool HasOutlineLevel() const; | |
504 | ||
505 | bool HasFlag(long flag) const; | |
506 | ||
507 | bool IsCharacterStyle() const; | |
508 | bool IsParagraphStyle() const; | |
509 | ||
510 | ||
511 | DocDeclStr( | |
512 | bool , IsDefault() const, | |
513 | "Returns false if we have any attributes set, true otherwise", ""); | |
514 | ||
515 | ||
516 | DocDeclStr( | |
517 | bool , Apply(const wxRichTextAttr& style, const wxRichTextAttr* compareWith = NULL), | |
518 | "Merges the given attributes. Does not affect self. If compareWith is | |
519 | not None, then it will be used to mask out those attributes that are | |
520 | the same in style and compareWith, for situations where we don't want | |
521 | to explicitly set inherited attributes. | |
522 | ", ""); | |
523 | ||
524 | ||
525 | DocDeclStr( | |
526 | wxRichTextAttr , Combine(const wxRichTextAttr& style, const wxRichTextAttr* compareWith = NULL) const, | |
527 | "Merges the given attributes and returns the result. Does not affect | |
528 | self. If compareWith is not None, then it will be used to mask out | |
529 | those attributes that are the same in style and compareWith, for | |
530 | situations where we don't want to explicitly set inherited attributes. | |
531 | ", ""); | |
532 | ||
533 | ||
534 | ||
535 | %property(Alignment, GetAlignment, SetAlignment); | |
536 | %property(BackgroundColour, GetBackgroundColour, SetBackgroundColour); | |
537 | %property(BulletFont, GetBulletFont, SetBulletFont); | |
538 | %property(BulletNumber, GetBulletNumber, SetBulletNumber); | |
539 | %property(BulletStyle, GetBulletStyle, SetBulletStyle); | |
540 | %property(BulletText, GetBulletText, SetBulletText); | |
541 | %property(CharacterStyleName, GetCharacterStyleName, SetCharacterStyleName); | |
542 | %property(Flags, GetFlags, SetFlags); | |
543 | %property(Font, GetFont, SetFont); | |
544 | %property(FontAttributes, GetFontAttributes); | |
545 | %property(FontFaceName, GetFontFaceName, SetFontFaceName); | |
546 | %property(FontSize, GetFontSize, SetFontSize); | |
547 | %property(FontStyle, GetFontStyle, SetFontStyle); | |
548 | %property(FontUnderlined, GetFontUnderlined, SetFontUnderlined); | |
549 | %property(FontWeight, GetFontWeight, SetFontWeight); | |
550 | %property(LeftIndent, GetLeftIndent, SetLeftIndent); | |
551 | %property(LeftSubIndent, GetLeftSubIndent); | |
552 | %property(LineSpacing, GetLineSpacing, SetLineSpacing); | |
553 | %property(ParagraphSpacingAfter, GetParagraphSpacingAfter, SetParagraphSpacingAfter); | |
554 | %property(ParagraphSpacingBefore, GetParagraphSpacingBefore, SetParagraphSpacingBefore); | |
555 | %property(ParagraphStyleName, GetParagraphStyleName, SetParagraphStyleName); | |
556 | %property(RightIndent, GetRightIndent, SetRightIndent); | |
557 | %property(Tabs, GetTabs, SetTabs); | |
558 | %property(TextColour, GetTextColour, SetTextColour); | |
559 | ||
560 | %property(ListStyleName, GetListStyleName, SetListStyleName); | |
561 | %property(BulletName, GetBulletName, SetBulletName); | |
562 | %property(URL, GetURL, SetURL); | |
563 | %property(TextEffects, GetTextEffects, SetTextEffects); | |
564 | %property(TextEffectFlags, GetTextEffectFlags, SetTextEffectFlags); | |
565 | %property(OutlineLevel, GetOutlineLevel, SetOutlineLevel); | |
566 | }; | |
567 | ||
568 | ||
569 | ||
570 | //--------------------------------------------------------------------------- | |
571 | //--------------------------------------------------------------------------- | |
572 | ||
573 | ||
574 | // TODO TODO TODO | |
575 | // There's still lots to do for these classes... | |
576 | // | |
577 | // 1. Decide how to coalesce overloaded methods and ctors | |
578 | // 2. correctly set disown flags and re-ownership as needed | |
579 | // 3. Implement PyRichTextObject | |
580 | // 4. Decide how to typemap and tweak the virtuals that pass back | |
581 | // values in their parameters (yuck! damn C++) | |
582 | // 5. better handling of streams | |
583 | // 6. list-like wrapper for C++ wxLists | |
584 | // 7. wrappers for wxTextAttrEx --> wxRichTextAttr (as needed) | |
585 | // 8. Add more properties | |
586 | ||
587 | ||
588 | ||
589 | DocStr(wxRichTextObject, | |
590 | "This is the base class for all drawable objects in a `RichTextCtrl`. | |
591 | ||
592 | The data displayed in a `RichTextCtrl` is handled by `RichTextBuffer`, | |
593 | and a `RichTextCtrl` always has one such buffer. | |
594 | ||
595 | The content is represented by a hierarchy of objects, all derived from | |
596 | `RichTextObject`. An object might be an image, a fragment of text, a | |
597 | paragraph, or a whole buffer. Objects store a an attribute object | |
598 | containing style information; a paragraph object can contain both | |
599 | paragraph and character information, but content objects such as text | |
600 | can only store character information. The final style displayed in the | |
601 | control or in a printout is a combination of base style, paragraph | |
602 | style and content (character) style. | |
603 | ||
604 | The top of the hierarchy is the buffer, a kind of | |
605 | `RichTextParagraphLayoutBox`. containing further `RichTextParagraph` | |
606 | objects, each of which can include text, images and potentially other | |
607 | types of objects. | |
608 | ||
609 | Each object maintains a range (start and end position) measured from | |
610 | the start of the main parent object. | |
611 | ||
612 | When Layout is called on an object, it is given a size which the | |
613 | object must limit itself to, or one or more flexible directions | |
614 | (vertical or horizontal). So, for example, a centred paragraph is | |
615 | given the page width to play with (minus any margins), but can extend | |
616 | indefinitely in the vertical direction. The implementation of Layout | |
617 | caches the calculated size and position. | |
618 | ||
619 | When the buffer is modified, a range is invalidated (marked as | |
620 | requiring layout), so that only the minimum amount of layout is | |
621 | performed. | |
622 | ||
623 | A paragraph of pure text with the same style contains just one further | |
624 | object, a `RichTextPlainText` object. When styling is applied to part | |
625 | of this object, the object is decomposed into separate objects, one | |
626 | object for each different character style. So each object within a | |
627 | paragraph always has just one attribute object to denote its character | |
628 | style. Of course, this can lead to fragmentation after a lot of edit | |
629 | operations, potentially leading to several objects with the same style | |
630 | where just one would do. So a Defragment function is called when | |
631 | updating the control's display, to ensure that the minimum number of | |
632 | objects is used. | |
633 | ||
634 | To implement your own RichTextObjects in Python you must derive a | |
635 | class from `PyRichTextObject`, which has been instrumented to forward | |
636 | the virtual C++ method calls to the Python methods in the derived | |
637 | class. (This class hasn't been implemented yet!)", ""); | |
638 | ||
639 | // argout typemap for wxPoint | |
640 | %typemap(in, numinputs=0, noblock=1) wxPoint& OUTPUT (wxPoint temp) { | |
641 | $1 = &temp; | |
642 | } | |
643 | %typemap(argout, noblock=1) wxPoint& OUTPUT { | |
644 | %append_output(SWIG_NewPointerObj((void*)new wxPoint(*$1), $1_descriptor, SWIG_POINTER_OWN)); | |
645 | } | |
646 | ||
647 | // argout typemap for wxSize | |
648 | %typemap(in, numinputs=0, noblock=1) wxSize& OUTPUT (wxSize temp) { | |
649 | $1 = &temp; | |
650 | } | |
651 | %typemap(argout, noblock=1) wxSize& OUTPUT { | |
652 | %append_output(SWIG_NewPointerObj((void*)new wxSize(*$1), $1_descriptor, SWIG_POINTER_OWN)); | |
653 | } | |
654 | ||
655 | ||
656 | class wxRichTextObject: public wxObject | |
657 | { | |
658 | public: | |
659 | // wxRichTextObject(wxRichTextObject* parent = NULL); // **** This is an ABC | |
660 | virtual ~wxRichTextObject(); | |
661 | ||
662 | ||
663 | // Overrideables | |
664 | ||
665 | /// Draw the item, within the given range. Some objects may ignore the range (for | |
666 | /// example paragraphs) while others must obey it (lines, to implement wrapping) | |
667 | virtual bool Draw(wxDC& dc, const wxRichTextRange& range, | |
668 | const wxRichTextRange& selectionRange, const wxRect& rect, | |
669 | int descent, int style); | |
670 | ||
671 | /// Lay the item out at the specified position with the given size constraint. | |
672 | /// Layout must set the cached size. | |
673 | virtual bool Layout(wxDC& dc, const wxRect& rect, int style); | |
674 | ||
675 | /// Hit-testing: returns a flag indicating hit test details, plus | |
676 | /// information about position | |
677 | virtual int HitTest(wxDC& dc, const wxPoint& pt, long& OUTPUT /*textPosition*/); | |
678 | ||
679 | /// Finds the absolute position and row height for the given character position | |
680 | virtual bool FindPosition(wxDC& dc, long index, wxPoint& OUTPUT /*pt*/, | |
681 | int* OUTPUT /*height*/, bool forceLineStart); | |
682 | ||
683 | ||
684 | /// Get the best size, i.e. the ideal starting size for this object irrespective | |
685 | /// of available space. For a short text string, it will be the size that exactly encloses | |
686 | /// the text. For a longer string, it might use the parent width for example. | |
687 | virtual wxSize GetBestSize() const; | |
688 | ||
689 | /// Get the object size for the given range. Returns false if the range | |
690 | /// is invalid for this object. | |
691 | virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& OUTPUT /*size*/, | |
692 | int& OUTPUT /*descent*/, wxDC& dc, int flags, | |
693 | wxPoint position = wxPoint(0,0)) const; | |
694 | ||
695 | /// Do a split, returning an object containing the second part, and setting | |
696 | /// the first part in 'this'. | |
697 | virtual wxRichTextObject* DoSplit(long pos); | |
698 | ||
699 | /// Calculate range. By default, guess that the object is 1 unit long. | |
700 | virtual void CalculateRange(long start, long& OUTPUT /*end*/); | |
701 | ||
702 | /// Delete range | |
703 | virtual bool DeleteRange(const wxRichTextRange& range); | |
704 | ||
705 | /// Returns true if the object is empty | |
706 | virtual bool IsEmpty() const; | |
707 | ||
708 | /// Get any text in this object for the given range | |
709 | virtual wxString GetTextForRange(const wxRichTextRange& range) const; | |
710 | ||
711 | /// Returns true if this object can merge itself with the given one. | |
712 | virtual bool CanMerge(wxRichTextObject* object) const; | |
713 | ||
714 | /// Returns true if this object merged itself with the given one. | |
715 | /// The calling code will then delete the given object. | |
716 | virtual bool Merge(wxRichTextObject* object); | |
717 | ||
718 | /// Dump to output stream for debugging | |
719 | //virtual void Dump(wxTextOutputStream& stream); | |
720 | %extend { | |
721 | wxString Dump() { | |
722 | wxStringOutputStream strstream; | |
723 | wxTextOutputStream txtstream(strstream); | |
724 | self->Dump(txtstream); | |
725 | return strstream.GetString(); | |
726 | } | |
727 | } | |
728 | ||
729 | // Accessors | |
730 | ||
731 | /// Get/set the cached object size as calculated by Layout. | |
732 | virtual wxSize GetCachedSize() const; | |
733 | virtual void SetCachedSize(const wxSize& sz); | |
734 | %property(CachedSize, GetCachedSize, SetCachedSize); | |
735 | ||
736 | /// Get/set the object position | |
737 | virtual wxPoint GetPosition() const; | |
738 | virtual void SetPosition(const wxPoint& pos); | |
739 | %property(Position, GetPosition, SetPosition); | |
740 | ||
741 | /// Get the rectangle enclosing the object | |
742 | virtual wxRect GetRect() const; | |
743 | %property(Rect, GetRect); | |
744 | ||
745 | ||
746 | /// Set the range | |
747 | void SetRange(const wxRichTextRange& range); | |
748 | /// Get the range | |
749 | wxRichTextRange GetRange(); | |
750 | %property(Range, GetRange, SetRange); | |
751 | ||
752 | ||
753 | /// Get/set dirty flag (whether the object needs Layout to be called) | |
754 | virtual bool GetDirty() const; | |
755 | virtual void SetDirty(bool dirty); | |
756 | %property(Dirty, GetDirty, SetDirty); | |
757 | ||
758 | ||
759 | /// Is this composite? | |
760 | virtual bool IsComposite() const; | |
761 | ||
762 | /// Get/set the parent. | |
763 | virtual wxRichTextObject* GetParent() const; | |
764 | virtual void SetParent(wxRichTextObject* parent); | |
765 | %property(Parent, GetParent, SetParent); | |
766 | ||
767 | ||
768 | // TODO: Morph these into SetLeftMargin and etc. for wxPython so | |
769 | // there can be proper properties | |
770 | ||
771 | /// Set the margin around the object | |
772 | %Rename(SetSameMargins, | |
773 | virtual void , SetMargins(int margin)); | |
774 | virtual void SetMargins(int leftMargin, int rightMargin, int topMargin, int bottomMargin); | |
775 | virtual int GetLeftMargin() const; | |
776 | virtual int GetRightMargin() const; | |
777 | virtual int GetTopMargin() const; | |
778 | virtual int GetBottomMargin() const; | |
779 | ||
780 | ||
781 | /// Set attributes object | |
782 | void SetAttributes(const wxRichTextAttr& attr); | |
783 | wxRichTextAttr GetAttributes(); | |
784 | %property(Attributes, GetAttributes, SetAttributes); | |
785 | ||
786 | /// Set/get stored descent | |
787 | void SetDescent(int descent); | |
788 | int GetDescent() const; | |
789 | %property(Descent, GetDescent, SetDescent); | |
790 | ||
791 | /// Gets the containing buffer | |
792 | wxRichTextBuffer* GetBuffer() const; | |
793 | ||
794 | // Operations | |
795 | ||
796 | /// Clone the object | |
797 | virtual wxRichTextObject* Clone() const; | |
798 | ||
799 | /// Copy | |
800 | void Copy(const wxRichTextObject& obj); | |
801 | ||
802 | /// Reference-counting allows us to use the same object in multiple | |
803 | /// lists (not yet used) | |
804 | void Reference(); | |
805 | void Dereference(); | |
806 | ||
807 | /// Convert units in tenths of a millimetre to device units | |
808 | %Rename(ConvertTenthsMMToPixelsDC, | |
809 | int, ConvertTenthsMMToPixels(wxDC& dc, int units)); | |
810 | static int ConvertTenthsMMToPixels(int ppi, int units); | |
811 | ||
812 | }; | |
813 | ||
814 | ||
815 | ||
816 | ||
817 | wxLIST_WRAPPER(wxRichTextObjectList, wxRichTextObject); | |
818 | ||
819 | ||
820 | DocStr(wxRichTextCompositeObject, | |
821 | "Objects of this class can contain other rich text objects.", ""); | |
822 | ||
823 | ||
824 | class wxRichTextCompositeObject: public wxRichTextObject | |
825 | { | |
826 | public: | |
827 | // wxRichTextCompositeObject(wxRichTextObject* parent = NULL); **** This is an ABC | |
828 | virtual ~wxRichTextCompositeObject(); | |
829 | ||
830 | // Accessors | |
831 | ||
832 | /// Get the children | |
833 | wxRichTextObjectList& GetChildren(); | |
834 | ||
835 | /// Get the child count | |
836 | size_t GetChildCount() const ; | |
837 | ||
838 | /// Get the nth child | |
839 | wxRichTextObject* GetChild(size_t n) const ; | |
840 | ||
841 | // Operations | |
842 | ||
843 | /// Copy | |
844 | void Copy(const wxRichTextCompositeObject& obj); | |
845 | ||
846 | %disownarg(wxRichTextObject* child); | |
847 | ||
848 | /// Append a child, returning the position | |
849 | size_t AppendChild(wxRichTextObject* child) ; | |
850 | ||
851 | /// Insert the child in front of the given object, or at the beginning | |
852 | bool InsertChild(wxRichTextObject* child, wxRichTextObject* inFrontOf) ; | |
853 | ||
854 | %cleardisown(wxRichTextObject* child); | |
855 | ||
856 | ||
857 | /// Delete the child | |
858 | %feature("shadow") RemoveChild %{ | |
859 | def RemoveChild(self, child, deleteChild=False): | |
860 | val = _richtext.RichTextCompositeObject_RemoveChild(self, child, deleteChild) | |
861 | self.this.own(not deleteChild) | |
862 | return val | |
863 | %} | |
864 | bool RemoveChild(wxRichTextObject* child, bool deleteChild = false) ; | |
865 | ||
866 | /// Delete all children | |
867 | bool DeleteChildren(); | |
868 | ||
869 | /// Recursively merge all pieces that can be merged. | |
870 | bool Defragment(); | |
871 | }; | |
872 | ||
873 | ||
874 | ||
875 | ||
876 | ||
877 | ||
878 | DocStr(wxRichTextBox, | |
879 | "This defines a 2D space to lay out objects.", ""); | |
880 | ||
881 | class wxRichTextBox: public wxRichTextCompositeObject | |
882 | { | |
883 | public: | |
884 | wxRichTextBox(wxRichTextObject* parent = NULL); | |
885 | ||
886 | virtual wxRichTextObject* Clone() const; | |
887 | void Copy(const wxRichTextBox& obj); | |
888 | }; | |
889 | ||
890 | ||
891 | ||
892 | ||
893 | ||
894 | ||
895 | DocStr(wxRichTextParagraphBox, | |
896 | "This box knows how to lay out paragraphs.", ""); | |
897 | ||
898 | class wxRichTextParagraphLayoutBox: public wxRichTextBox | |
899 | { | |
900 | public: | |
901 | ||
902 | wxRichTextParagraphLayoutBox(wxRichTextObject* parent = NULL); | |
903 | ||
904 | // Accessors | |
905 | ||
906 | /// Associate a control with the buffer, for operations that for example require refreshing the window. | |
907 | void SetRichTextCtrl(wxRichTextCtrl* ctrl); | |
908 | ||
909 | /// Get the associated control. | |
910 | wxRichTextCtrl* GetRichTextCtrl() const; | |
911 | ||
912 | /// Get/set whether the last paragraph is partial or complete | |
913 | void SetPartialParagraph(bool partialPara); | |
914 | bool GetPartialParagraph() const; | |
915 | ||
916 | /// If this is a buffer, returns the current style sheet. The base layout box | |
917 | /// class doesn't have an associated style sheet. | |
918 | virtual wxRichTextStyleSheet* GetStyleSheet() const; | |
919 | ||
920 | // Operations | |
921 | ||
922 | /// Initialize the object. | |
923 | void Init(); | |
924 | ||
925 | /// Clear all children | |
926 | virtual void Clear(); | |
927 | ||
928 | /// Clear and initialize with one blank paragraph | |
929 | virtual void Reset(); | |
930 | ||
931 | /// Convenience function to add a paragraph of text | |
932 | virtual wxRichTextRange AddParagraph(const wxString& text, wxTextAttrEx* paraStyle = NULL); | |
933 | ||
934 | /// Convenience function to add an image | |
935 | virtual wxRichTextRange AddImage(const wxImage& image, wxTextAttrEx* paraStyle = NULL); | |
936 | ||
937 | /// Adds multiple paragraphs, based on newlines. | |
938 | virtual wxRichTextRange AddParagraphs(const wxString& text, wxTextAttrEx* paraStyle = NULL); | |
939 | ||
940 | /// Get the line at the given position. If caretPosition is true, the position is | |
941 | /// a caret position, which is normally a smaller number. | |
942 | virtual wxRichTextLine* GetLineAtPosition(long pos, bool caretPosition = false) const; | |
943 | ||
944 | /// Get the line at the given y pixel position, or the last line. | |
945 | virtual wxRichTextLine* GetLineAtYPosition(int y) const; | |
946 | ||
947 | /// Get the paragraph at the given character or caret position | |
948 | virtual wxRichTextParagraph* GetParagraphAtPosition(long pos, bool caretPosition = false) const; | |
949 | ||
950 | /// Get the line size at the given position | |
951 | virtual wxSize GetLineSizeAtPosition(long pos, bool caretPosition = false) const; | |
952 | ||
953 | /// Given a position, get the number of the visible line (potentially many to a paragraph), | |
954 | /// starting from zero at the start of the buffer. We also have to pass a bool (startOfLine) | |
955 | /// that indicates whether the caret is being shown at the end of the previous line or at the start | |
956 | /// of the next, since the caret can be shown at 2 visible positions for the same underlying | |
957 | /// position. | |
958 | virtual long GetVisibleLineNumber(long pos, bool caretPosition = false, bool startOfLine = false) const; | |
959 | ||
960 | /// Given a line number, get the corresponding wxRichTextLine object. | |
961 | virtual wxRichTextLine* GetLineForVisibleLineNumber(long lineNumber) const; | |
962 | ||
963 | /// Get the leaf object in a paragraph at this position. | |
964 | /// Given a line number, get the corresponding wxRichTextLine object. | |
965 | virtual wxRichTextObject* GetLeafObjectAtPosition(long position) const; | |
966 | ||
967 | /// Get the paragraph by number | |
968 | virtual wxRichTextParagraph* GetParagraphAtLine(long paragraphNumber) const; | |
969 | ||
970 | /// Get the paragraph for a given line | |
971 | virtual wxRichTextParagraph* GetParagraphForLine(wxRichTextLine* line) const; | |
972 | ||
973 | /// Get the length of the paragraph | |
974 | virtual int GetParagraphLength(long paragraphNumber) const; | |
975 | ||
976 | /// Get the number of paragraphs | |
977 | virtual int GetParagraphCount() const { return GetChildCount(); } | |
978 | ||
979 | /// Get the number of visible lines | |
980 | virtual int GetLineCount() const; | |
981 | ||
982 | /// Get the text of the paragraph | |
983 | virtual wxString GetParagraphText(long paragraphNumber) const; | |
984 | ||
985 | /// Convert zero-based line column and paragraph number to a position. | |
986 | virtual long XYToPosition(long x, long y) const; | |
987 | ||
988 | /// Convert zero-based position to line column and paragraph number | |
989 | virtual bool PositionToXY(long pos, long* x, long* y) const; | |
990 | ||
991 | /// Set text attributes: character and/or paragraph styles. | |
992 | virtual bool SetStyle(const wxRichTextRange& range, | |
993 | const wxRichTextAttr& style, | |
994 | int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO); | |
995 | // virtual bool SetStyle(const wxRichTextRange& range, | |
996 | // const wxTextAttrEx& style, | |
997 | // int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO); | |
998 | ||
999 | /// Get the conbined text attributes for this position. | |
1000 | // virtual bool GetStyle(long position, wxTextAttrEx& style); | |
1001 | virtual bool GetStyle(long position, wxRichTextAttr& style); | |
1002 | ||
1003 | /// Get the content (uncombined) attributes for this position. | |
1004 | // virtual bool GetUncombinedStyle(long position, wxTextAttrEx& style); | |
1005 | virtual bool GetUncombinedStyle(long position, wxRichTextAttr& style); | |
1006 | ||
1007 | // /// Implementation helper for GetStyle. If combineStyles is true, combine base, paragraph and | |
1008 | // /// context attributes. | |
1009 | // virtual bool DoGetStyle(long position, wxTextAttrEx& style, bool combineStyles = true); | |
1010 | ||
1011 | /// Get the combined style for a range - if any attribute is different within the range, | |
1012 | /// that attribute is not present within the flags | |
1013 | virtual bool GetStyleForRange(const wxRichTextRange& range, wxTextAttrEx& style); | |
1014 | ||
1015 | /// Combines 'style' with 'currentStyle' for the purpose of summarising the attributes of a range of | |
1016 | /// content. | |
1017 | bool CollectStyle(wxTextAttrEx& currentStyle, const wxTextAttrEx& style, long& multipleStyleAttributes, int& multipleTextEffectAttributes); | |
1018 | ||
1019 | /// Set list style | |
1020 | //virtual bool SetListStyle(const wxRichTextRange& range, wxRichTextListStyleDefinition* def, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int startFrom = 1, int specifiedLevel = -1); | |
1021 | virtual bool SetListStyle(const wxRichTextRange& range, const wxString& defName, | |
1022 | int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, | |
1023 | int startFrom = 1, int specifiedLevel = -1); | |
1024 | ||
1025 | /// Clear list for given range | |
1026 | virtual bool ClearListStyle(const wxRichTextRange& range, | |
1027 | int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO); | |
1028 | ||
1029 | /// Number/renumber any list elements in the given range. | |
1030 | /// def/defName can be NULL/empty to indicate that the existing list style should be used. | |
1031 | //virtual bool NumberList(const wxRichTextRange& range, wxRichTextListStyleDefinition* def = NULL, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int startFrom = 1, int specifiedLevel = -1); | |
1032 | virtual bool NumberList(const wxRichTextRange& range, const wxString& defName, | |
1033 | int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, | |
1034 | int startFrom = 1, int specifiedLevel = -1); | |
1035 | ||
1036 | /// Promote the list items within the given range. promoteBy can be a positive or negative number, e.g. 1 or -1 | |
1037 | /// def/defName can be NULL/empty to indicate that the existing list style should be used. | |
1038 | //virtual bool PromoteList(int promoteBy, const wxRichTextRange& range, wxRichTextListStyleDefinition* def = NULL, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int specifiedLevel = -1); | |
1039 | virtual bool PromoteList(int promoteBy, const wxRichTextRange& range, | |
1040 | const wxString& defName, | |
1041 | int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, | |
1042 | int specifiedLevel = -1); | |
1043 | ||
1044 | /// Helper for NumberList and PromoteList, that does renumbering and promotion simultaneously | |
1045 | /// def/defName can be NULL/empty to indicate that the existing list style should be used. | |
1046 | virtual bool DoNumberList(const wxRichTextRange& range, const wxRichTextRange& promotionRange, int promoteBy, wxRichTextListStyleDefinition* def, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int startFrom = 1, int specifiedLevel = -1); | |
1047 | ||
1048 | /// Fills in the attributes for numbering a paragraph after previousParagraph. | |
1049 | virtual bool FindNextParagraphNumber(wxRichTextParagraph* previousParagraph, wxRichTextAttr& attr) const; | |
1050 | ||
1051 | /// Test if this whole range has character attributes of the specified kind. If any | |
1052 | /// of the attributes are different within the range, the test fails. You | |
1053 | /// can use this to implement, for example, bold button updating. style must have | |
1054 | /// flags indicating which attributes are of interest. | |
1055 | //virtual bool HasCharacterAttributes(const wxRichTextRange& range, const wxTextAttrEx& style) const; | |
1056 | virtual bool HasCharacterAttributes(const wxRichTextRange& range, const wxRichTextAttr& style) const; | |
1057 | ||
1058 | /// Test if this whole range has paragraph attributes of the specified kind. If any | |
1059 | /// of the attributes are different within the range, the test fails. You | |
1060 | /// can use this to implement, for example, centering button updating. style must have | |
1061 | /// flags indicating which attributes are of interest. | |
1062 | //virtual bool HasParagraphAttributes(const wxRichTextRange& range, const wxTextAttrEx& style) const; | |
1063 | virtual bool HasParagraphAttributes(const wxRichTextRange& range, const wxRichTextAttr& style) const; | |
1064 | ||
1065 | /// Clone | |
1066 | virtual wxRichTextObject* Clone() const { return new wxRichTextParagraphLayoutBox(*this); } | |
1067 | ||
1068 | /// Insert fragment into this box at the given position. If partialParagraph is true, | |
1069 | /// it is assumed that the last (or only) paragraph is just a piece of data with no paragraph | |
1070 | /// marker. | |
1071 | virtual bool InsertFragment(long position, wxRichTextParagraphLayoutBox& fragment); | |
1072 | ||
1073 | /// Make a copy of the fragment corresponding to the given range, putting it in 'fragment'. | |
1074 | virtual bool CopyFragment(const wxRichTextRange& range, wxRichTextParagraphLayoutBox& fragment); | |
1075 | ||
1076 | /// Apply the style sheet to the buffer, for example if the styles have changed. | |
1077 | virtual bool ApplyStyleSheet(wxRichTextStyleSheet* styleSheet); | |
1078 | ||
1079 | /// Copy | |
1080 | void Copy(const wxRichTextParagraphLayoutBox& obj); | |
1081 | ||
1082 | /// Calculate ranges | |
1083 | virtual void UpdateRanges(); | |
1084 | ||
1085 | /// Get all the text | |
1086 | virtual wxString GetText() const; | |
1087 | ||
1088 | /// Set default style for new content. Setting it to a default attribute | |
1089 | /// makes new content take on the 'basic' style. | |
1090 | virtual bool SetDefaultStyle(const wxTextAttrEx& style); | |
1091 | ||
1092 | /// Get default style | |
1093 | virtual const wxTextAttrEx& GetDefaultStyle() const; | |
1094 | ||
1095 | /// Set basic (overall) style | |
1096 | //virtual void SetBasicStyle(const wxTextAttrEx& style); | |
1097 | virtual void SetBasicStyle(const wxRichTextAttr& style); | |
1098 | ||
1099 | /// Get basic (overall) style | |
1100 | virtual const wxTextAttrEx& GetBasicStyle() const; | |
1101 | ||
1102 | /// Invalidate the buffer. With no argument, invalidates whole buffer. | |
1103 | void Invalidate(const wxRichTextRange& invalidRange = wxRICHTEXT_ALL); | |
1104 | ||
1105 | /// Get invalid range, rounding to entire paragraphs if argument is true. | |
1106 | wxRichTextRange GetInvalidRange(bool wholeParagraphs = false) const; | |
1107 | ||
1108 | }; | |
1109 | ||
1110 | ||
1111 | ||
1112 | ||
1113 | ||
1114 | DocStr(wxRichTextLine, | |
1115 | "This object represents a line in a paragraph, and stores offsets from | |
1116 | the start of the paragraph representing the start and end positions of | |
1117 | the line.", ""); | |
1118 | ||
1119 | class wxRichTextLine | |
1120 | { | |
1121 | public: | |
1122 | wxRichTextLine(wxRichTextParagraph* parent); | |
1123 | virtual ~wxRichTextLine(); | |
1124 | ||
1125 | /// Set the range | |
1126 | void SetRange(const wxRichTextRange& range); | |
1127 | ||
1128 | /// Get the parent paragraph | |
1129 | wxRichTextParagraph* GetParent(); | |
1130 | ||
1131 | /// Get the range | |
1132 | wxRichTextRange GetRange(); | |
1133 | ||
1134 | /// Get the absolute range | |
1135 | wxRichTextRange GetAbsoluteRange() const; | |
1136 | ||
1137 | /// Get/set the line size as calculated by Layout. | |
1138 | virtual wxSize GetSize() const; | |
1139 | virtual void SetSize(const wxSize& sz); | |
1140 | ||
1141 | /// Get/set the object position relative to the parent | |
1142 | virtual wxPoint GetPosition() const; | |
1143 | virtual void SetPosition(const wxPoint& pos); | |
1144 | ||
1145 | /// Get the absolute object position | |
1146 | virtual wxPoint GetAbsolutePosition() const; | |
1147 | ||
1148 | /// Get the rectangle enclosing the line | |
1149 | virtual wxRect GetRect() const; | |
1150 | ||
1151 | /// Set/get stored descent | |
1152 | void SetDescent(int descent); | |
1153 | int GetDescent() const; | |
1154 | ||
1155 | // Operations | |
1156 | ||
1157 | /// Initialisation | |
1158 | void Init(wxRichTextParagraph* parent); | |
1159 | ||
1160 | /// Copy | |
1161 | void Copy(const wxRichTextLine& obj); | |
1162 | ||
1163 | /// Clone | |
1164 | virtual wxRichTextLine* Clone() const; | |
1165 | }; | |
1166 | ||
1167 | ||
1168 | ||
1169 | ||
1170 | ||
1171 | ||
1172 | DocStr(wxRichTextParagraph, | |
1173 | "This object represents a single paragraph (or in a straight text | |
1174 | editor, a line).", ""); | |
1175 | ||
1176 | class wxRichTextParagraph: public wxRichTextBox | |
1177 | { | |
1178 | public: | |
1179 | %extend { | |
1180 | wxRichTextParagraph(const wxString& text = wxPyEmptyString, | |
1181 | wxRichTextObject* parent = NULL, | |
1182 | wxRichTextAttr* paraStyle = NULL, | |
1183 | wxRichTextAttr* charStyle = NULL) | |
1184 | { | |
1185 | wxTextAttrEx* psAttr = NULL; | |
1186 | wxTextAttrEx* csAttr = NULL; | |
1187 | wxTextAttrEx psAttr_v; | |
1188 | wxTextAttrEx csAttr_v; | |
1189 | if (paraStyle) { | |
1190 | psAttr_v = *paraStyle; | |
1191 | psAttr = &psAttr_v; | |
1192 | } | |
1193 | if (charStyle) { | |
1194 | csAttr_v = *charStyle; | |
1195 | csAttr = &csAttr_v; | |
1196 | } | |
1197 | return new wxRichTextParagraph(text, parent, psAttr, csAttr); | |
1198 | } | |
1199 | } | |
1200 | virtual ~wxRichTextParagraph(); | |
1201 | ||
1202 | ||
1203 | // Accessors | |
1204 | ||
1205 | /// Get the cached lines | |
1206 | wxRichTextLineList& GetLines(); | |
1207 | ||
1208 | // Operations | |
1209 | ||
1210 | /// Copy | |
1211 | void Copy(const wxRichTextParagraph& obj); | |
1212 | ||
1213 | /// Clone | |
1214 | virtual wxRichTextObject* Clone() const; | |
1215 | ||
1216 | /// Clear the cached lines | |
1217 | void ClearLines(); | |
1218 | ||
1219 | // Implementation | |
1220 | ||
1221 | /// Apply paragraph styles such as centering to the wrapped lines | |
1222 | virtual void ApplyParagraphStyle(const wxTextAttrEx& attr, const wxRect& rect); | |
1223 | ||
1224 | /// Insert text at the given position | |
1225 | virtual bool InsertText(long pos, const wxString& text); | |
1226 | ||
1227 | /// Split an object at this position if necessary, and return | |
1228 | /// the previous object, or NULL if inserting at beginning. | |
1229 | virtual wxRichTextObject* SplitAt(long pos, wxRichTextObject** previousObject = NULL); | |
1230 | ||
1231 | /// Move content to a list from this point | |
1232 | virtual void MoveToList(wxRichTextObject* obj, wxList& list); | |
1233 | ||
1234 | /// Add content back from list | |
1235 | virtual void MoveFromList(wxList& list); | |
1236 | ||
1237 | /// Get the plain text searching from the start or end of the range. | |
1238 | /// The resulting string may be shorter than the range given. | |
1239 | bool GetContiguousPlainText(wxString& text, const wxRichTextRange& range, bool fromStart = true); | |
1240 | ||
1241 | /// Find a suitable wrap position. wrapPosition is the last position in the line to the left | |
1242 | /// of the split. | |
1243 | bool FindWrapPosition(const wxRichTextRange& range, wxDC& dc, int availableSpace, long& wrapPosition); | |
1244 | ||
1245 | /// Find the object at the given position | |
1246 | wxRichTextObject* FindObjectAtPosition(long position); | |
1247 | ||
1248 | /// Get the bullet text for this paragraph. | |
1249 | wxString GetBulletText(); | |
1250 | ||
1251 | /// Allocate or reuse a line object | |
1252 | wxRichTextLine* AllocateLine(int pos); | |
1253 | ||
1254 | /// Clear remaining unused line objects, if any | |
1255 | bool ClearUnusedLines(int lineCount); | |
1256 | ||
1257 | /// Get combined attributes of the base style, paragraph style and character style. We use this to dynamically | |
1258 | /// retrieve the actual style. | |
1259 | // wxTextAttrEx GetCombinedAttributes(const wxTextAttrEx& contentStyle) const; | |
1260 | ||
1261 | /// Get combined attributes of the base style and paragraph style. | |
1262 | wxTextAttrEx GetCombinedAttributes() const; | |
1263 | ||
1264 | /// Get the first position from pos that has a line break character. | |
1265 | long GetFirstLineBreakPosition(long pos); | |
1266 | ||
1267 | /// Create default tabstop array | |
1268 | static void InitDefaultTabs(); | |
1269 | ||
1270 | /// Clear default tabstop array | |
1271 | static void ClearDefaultTabs(); | |
1272 | ||
1273 | /// Get default tabstop array | |
1274 | static const wxArrayInt& GetDefaultTabs() { return sm_defaultTabs; } | |
1275 | }; | |
1276 | ||
1277 | ||
1278 | ||
1279 | ||
1280 | ||
1281 | ||
1282 | ||
1283 | DocStr(wxRichTextPlainText, | |
1284 | "This object represents a single piece of text.", ""); | |
1285 | ||
1286 | class wxRichTextPlainText: public wxRichTextObject | |
1287 | { | |
1288 | public: | |
1289 | wxRichTextPlainText(const wxString& text = wxEmptyString, wxRichTextObject* parent = NULL, wxTextAttrEx* style = NULL); | |
1290 | ||
1291 | /// Get the first position from pos that has a line break character. | |
1292 | long GetFirstLineBreakPosition(long pos); | |
1293 | ||
1294 | /// Get the text | |
1295 | const wxString& GetText() const; | |
1296 | ||
1297 | /// Set the text | |
1298 | void SetText(const wxString& text); | |
1299 | ||
1300 | // Operations | |
1301 | ||
1302 | /// Copy | |
1303 | void Copy(const wxRichTextPlainText& obj); | |
1304 | ||
1305 | /// Clone | |
1306 | virtual wxRichTextObject* Clone() const; | |
1307 | ||
1308 | }; | |
1309 | ||
1310 | ||
1311 | ||
1312 | ||
1313 | ||
1314 | ||
1315 | #if 0 | |
1316 | // TODO: we may not even need wrappers for this class. It looks to me | |
1317 | // like wxRichTextImage might be enough... | |
1318 | DocStr(wxRichTextImageBlock, | |
1319 | "Stores information about an image, in binary in-memory form.", ""); | |
1320 | ||
1321 | class wxRichTextImageBlock: public wxObject | |
1322 | { | |
1323 | public: | |
1324 | wxRichTextImageBlock(); | |
1325 | virtual ~wxRichTextImageBlock(); | |
1326 | ||
1327 | void Init(); | |
1328 | void Clear(); | |
1329 | ||
1330 | // Load the original image into a memory block. | |
1331 | // If the image is not a JPEG, we must convert it into a JPEG | |
1332 | // to conserve space. | |
1333 | // If it's not a JPEG we can make use of 'image', already scaled, so we don't have to | |
1334 | // load the image a 2nd time. | |
1335 | virtual bool MakeImageBlock(const wxString& filename, int imageType, wxImage& image, bool convertToJPEG = true); | |
1336 | ||
1337 | // Make an image block from the wxImage in the given | |
1338 | // format. | |
1339 | virtual bool MakeImageBlock(wxImage& image, int imageType, int quality = 80); | |
1340 | ||
1341 | // Write to a file | |
1342 | bool Write(const wxString& filename); | |
1343 | ||
1344 | // Write data in hex to a stream | |
1345 | bool WriteHex(wxOutputStream& stream); | |
1346 | ||
1347 | // Read data in hex from a stream | |
1348 | bool ReadHex(wxInputStream& stream, int length, int imageType); | |
1349 | ||
1350 | // Copy from 'block' | |
1351 | void Copy(const wxRichTextImageBlock& block); | |
1352 | ||
1353 | // Load a wxImage from the block | |
1354 | bool Load(wxImage& image); | |
1355 | ||
1356 | ||
1357 | //// Accessors | |
1358 | ||
1359 | unsigned char* GetData() const; | |
1360 | size_t GetDataSize() const; | |
1361 | int GetImageType() const; | |
1362 | ||
1363 | void SetData(unsigned char* image); | |
1364 | void SetDataSize(size_t size); | |
1365 | void SetImageType(int imageType); | |
1366 | ||
1367 | bool IsOk() const; | |
1368 | ||
1369 | // Gets the extension for the block's type | |
1370 | wxString GetExtension() const; | |
1371 | ||
1372 | /// Implementation | |
1373 | ||
1374 | // Allocate and read from stream as a block of memory | |
1375 | static unsigned char* ReadBlock(wxInputStream& stream, size_t size); | |
1376 | static unsigned char* ReadBlock(const wxString& filename, size_t size); | |
1377 | ||
1378 | // Write memory block to stream | |
1379 | static bool WriteBlock(wxOutputStream& stream, unsigned char* block, size_t size); | |
1380 | ||
1381 | // Write memory block to file | |
1382 | static bool WriteBlock(const wxString& filename, unsigned char* block, size_t size); | |
1383 | }; | |
1384 | #endif | |
1385 | ||
1386 | ||
1387 | ||
1388 | ||
1389 | ||
1390 | ||
1391 | DocStr(wxRichTextImage, | |
1392 | "This object represents an image.", ""); | |
1393 | ||
1394 | class wxRichTextImage: public wxRichTextObject | |
1395 | { | |
1396 | public: | |
1397 | // TODO: Which of these constructors? | |
1398 | wxRichTextImage(wxRichTextObject* parent = NULL); | |
1399 | //wxRichTextImage(const wxImage& image, wxRichTextObject* parent = NULL, wxTextAttrEx* charStyle = NULL); | |
1400 | //wxRichTextImage(const wxRichTextImageBlock& imageBlock, wxRichTextObject* parent = NULL, wxTextAttrEx* charStyle = NULL); | |
1401 | ||
1402 | ||
1403 | // Accessors | |
1404 | ||
1405 | /// Get the image | |
1406 | const wxImage& GetImage() const; | |
1407 | ||
1408 | /// Set the image | |
1409 | void SetImage(const wxImage& image); | |
1410 | ||
1411 | /// Get the image block containing the raw data | |
1412 | wxRichTextImageBlock& GetImageBlock(); | |
1413 | ||
1414 | // Operations | |
1415 | ||
1416 | /// Copy | |
1417 | void Copy(const wxRichTextImage& obj); | |
1418 | ||
1419 | /// Clone | |
1420 | virtual wxRichTextObject* Clone() const; | |
1421 | ||
1422 | /// Load wxImage from the block | |
1423 | virtual bool LoadFromBlock(); | |
1424 | ||
1425 | /// Make block from the wxImage | |
1426 | virtual bool MakeBlock(); | |
1427 | }; | |
1428 | ||
1429 | ||
1430 | ||
1431 | ||
1432 | ||
1433 | ||
1434 | %typemap(out) wxRichTextFileHandler* { $result = wxPyMake_wxObject($1, (bool)$owner); } | |
1435 | wxUNTYPED_LIST_WRAPPER(wxRichTextFileHandlerList, wxRichTextFileHandler); | |
1436 | ||
1437 | DocStr(wxRichTextBuffer, | |
1438 | "This is a kind of box, used to represent the whole buffer.", ""); | |
1439 | ||
1440 | class wxRichTextCommand; | |
1441 | class wxRichTextAction; | |
1442 | ||
1443 | class wxRichTextBuffer: public wxRichTextParagraphLayoutBox | |
1444 | { | |
1445 | public: | |
1446 | wxRichTextBuffer(); | |
1447 | virtual ~wxRichTextBuffer() ; | |
1448 | ||
1449 | // Accessors | |
1450 | ||
1451 | /// Gets the command processor | |
1452 | wxCommandProcessor* GetCommandProcessor() const; | |
1453 | ||
1454 | /// Set style sheet, if any. | |
1455 | void SetStyleSheet(wxRichTextStyleSheet* styleSheet); | |
1456 | virtual wxRichTextStyleSheet* GetStyleSheet() const; | |
1457 | ||
1458 | /// Set style sheet and notify of the change | |
1459 | bool SetStyleSheetAndNotify(wxRichTextStyleSheet* sheet); | |
1460 | ||
1461 | /// Push style sheet to top of stack | |
1462 | bool PushStyleSheet(wxRichTextStyleSheet* styleSheet); | |
1463 | ||
1464 | /// Pop style sheet from top of stack | |
1465 | wxRichTextStyleSheet* PopStyleSheet(); | |
1466 | ||
1467 | // Operations | |
1468 | ||
1469 | /// Initialisation | |
1470 | void Init(); | |
1471 | ||
1472 | /// Clears the buffer, adds an empty paragraph, and clears the command processor. | |
1473 | virtual void ResetAndClearCommands(); | |
1474 | ||
1475 | /// Load a file | |
1476 | virtual bool LoadFile(const wxString& filename, int type = wxRICHTEXT_TYPE_ANY); | |
1477 | ||
1478 | /// Save a file | |
1479 | virtual bool SaveFile(const wxString& filename, int type = wxRICHTEXT_TYPE_ANY); | |
1480 | ||
1481 | /// Load from a stream | |
1482 | %Rename(LoadStream, | |
1483 | virtual bool , LoadFile(wxInputStream& stream, int type = wxRICHTEXT_TYPE_ANY)); | |
1484 | ||
1485 | /// Save to a stream | |
1486 | %Rename(SaveStream, | |
1487 | virtual bool , SaveFile(wxOutputStream& stream, int type = wxRICHTEXT_TYPE_ANY)); | |
1488 | ||
1489 | /// Set the handler flags, controlling loading and saving | |
1490 | void SetHandlerFlags(int flags) { m_handlerFlags = flags; } | |
1491 | ||
1492 | /// Get the handler flags, controlling loading and saving | |
1493 | int GetHandlerFlags() const { return m_handlerFlags; } | |
1494 | ||
1495 | /// Convenience function to add a paragraph of text | |
1496 | virtual wxRichTextRange AddParagraph(const wxString& text, wxTextAttrEx* paraStyle = NULL) { Modify(); return wxRichTextParagraphLayoutBox::AddParagraph(text, paraStyle); } | |
1497 | ||
1498 | /// Begin collapsing undo/redo commands. Note that this may not work properly | |
1499 | /// if combining commands that delete or insert content, changing ranges for | |
1500 | /// subsequent actions. | |
1501 | virtual bool BeginBatchUndo(const wxString& cmdName); | |
1502 | ||
1503 | /// End collapsing undo/redo commands | |
1504 | virtual bool EndBatchUndo(); | |
1505 | ||
1506 | /// Collapsing commands? | |
1507 | virtual bool BatchingUndo() const; | |
1508 | ||
1509 | /// Submit immediately, or delay according to whether collapsing is on | |
1510 | virtual bool SubmitAction(wxRichTextAction* action); | |
1511 | ||
1512 | /// Get collapsed command | |
1513 | virtual wxRichTextCommand* GetBatchedCommand() const; | |
1514 | ||
1515 | /// Begin suppressing undo/redo commands. The way undo is suppressed may be implemented | |
1516 | /// differently by each command. If not dealt with by a command implementation, then | |
1517 | /// it will be implemented automatically by not storing the command in the undo history | |
1518 | /// when the action is submitted to the command processor. | |
1519 | virtual bool BeginSuppressUndo(); | |
1520 | ||
1521 | /// End suppressing undo/redo commands. | |
1522 | virtual bool EndSuppressUndo(); | |
1523 | ||
1524 | /// Collapsing commands? | |
1525 | virtual bool SuppressingUndo() const; | |
1526 | ||
1527 | /// Copy the range to the clipboard | |
1528 | virtual bool CopyToClipboard(const wxRichTextRange& range); | |
1529 | ||
1530 | /// Paste the clipboard content to the buffer | |
1531 | virtual bool PasteFromClipboard(long position); | |
1532 | ||
1533 | /// Can we paste from the clipboard? | |
1534 | virtual bool CanPasteFromClipboard() const; | |
1535 | ||
1536 | /// Begin using a style | |
1537 | virtual bool BeginStyle(const wxTextAttrEx& style); | |
1538 | ||
1539 | /// End the style | |
1540 | virtual bool EndStyle(); | |
1541 | ||
1542 | /// End all styles | |
1543 | virtual bool EndAllStyles(); | |
1544 | ||
1545 | /// Clear the style stack | |
1546 | virtual void ClearStyleStack(); | |
1547 | ||
1548 | /// Get the size of the style stack, for example to check correct nesting | |
1549 | virtual size_t GetStyleStackSize() const; | |
1550 | ||
1551 | /// Begin using bold | |
1552 | bool BeginBold(); | |
1553 | ||
1554 | /// End using bold | |
1555 | bool EndBold(); | |
1556 | ||
1557 | /// Begin using italic | |
1558 | bool BeginItalic(); | |
1559 | ||
1560 | /// End using italic | |
1561 | bool EndItalic(); | |
1562 | ||
1563 | /// Begin using underline | |
1564 | bool BeginUnderline(); | |
1565 | ||
1566 | /// End using underline | |
1567 | bool EndUnderline(); | |
1568 | ||
1569 | /// Begin using point size | |
1570 | bool BeginFontSize(int pointSize); | |
1571 | ||
1572 | /// End using point size | |
1573 | bool EndFontSize(); | |
1574 | ||
1575 | /// Begin using this font | |
1576 | bool BeginFont(const wxFont& font); | |
1577 | ||
1578 | /// End using a font | |
1579 | bool EndFont(); | |
1580 | ||
1581 | /// Begin using this colour | |
1582 | bool BeginTextColour(const wxColour& colour); | |
1583 | ||
1584 | /// End using a colour | |
1585 | bool EndTextColour(); | |
1586 | ||
1587 | /// Begin using alignment | |
1588 | bool BeginAlignment(wxTextAttrAlignment alignment); | |
1589 | ||
1590 | /// End alignment | |
1591 | bool EndAlignment(); | |
1592 | ||
1593 | /// Begin left indent | |
1594 | bool BeginLeftIndent(int leftIndent, int leftSubIndent = 0); | |
1595 | ||
1596 | /// End left indent | |
1597 | bool EndLeftIndent(); | |
1598 | ||
1599 | /// Begin right indent | |
1600 | bool BeginRightIndent(int rightIndent); | |
1601 | ||
1602 | /// End right indent | |
1603 | bool EndRightIndent(); | |
1604 | ||
1605 | /// Begin paragraph spacing | |
1606 | bool BeginParagraphSpacing(int before, int after); | |
1607 | ||
1608 | /// End paragraph spacing | |
1609 | bool EndParagraphSpacing(); | |
1610 | ||
1611 | /// Begin line spacing | |
1612 | bool BeginLineSpacing(int lineSpacing); | |
1613 | ||
1614 | /// End line spacing | |
1615 | bool EndLineSpacing(); | |
1616 | ||
1617 | /// Begin numbered bullet | |
1618 | bool BeginNumberedBullet(int bulletNumber, int leftIndent, int leftSubIndent, int bulletStyle = wxTEXT_ATTR_BULLET_STYLE_ARABIC|wxTEXT_ATTR_BULLET_STYLE_PERIOD); | |
1619 | ||
1620 | /// End numbered bullet | |
1621 | bool EndNumberedBullet(); | |
1622 | ||
1623 | /// Begin symbol bullet | |
1624 | bool BeginSymbolBullet(const wxString& symbol, int leftIndent, int leftSubIndent, int bulletStyle = wxTEXT_ATTR_BULLET_STYLE_SYMBOL); | |
1625 | ||
1626 | /// End symbol bullet | |
1627 | bool EndSymbolBullet(); | |
1628 | ||
1629 | /// Begin standard bullet | |
1630 | bool BeginStandardBullet(const wxString& bulletName, int leftIndent, int leftSubIndent, int bulletStyle = wxTEXT_ATTR_BULLET_STYLE_STANDARD); | |
1631 | ||
1632 | /// End standard bullet | |
1633 | bool EndStandardBullet(); | |
1634 | ||
1635 | /// Begin named character style | |
1636 | bool BeginCharacterStyle(const wxString& characterStyle); | |
1637 | ||
1638 | /// End named character style | |
1639 | bool EndCharacterStyle(); | |
1640 | ||
1641 | /// Begin named paragraph style | |
1642 | bool BeginParagraphStyle(const wxString& paragraphStyle); | |
1643 | ||
1644 | /// End named character style | |
1645 | bool EndParagraphStyle(); | |
1646 | ||
1647 | /// Begin named list style | |
1648 | bool BeginListStyle(const wxString& listStyle, int level = 1, int number = 1); | |
1649 | ||
1650 | /// End named character style | |
1651 | bool EndListStyle(); | |
1652 | ||
1653 | /// Begin URL | |
1654 | bool BeginURL(const wxString& url, const wxString& characterStyle = wxEmptyString); | |
1655 | ||
1656 | /// End URL | |
1657 | bool EndURL(); | |
1658 | ||
1659 | // Event handling | |
1660 | ||
1661 | /// Add an event handler | |
1662 | bool AddEventHandler(wxEvtHandler* handler); | |
1663 | ||
1664 | /// Remove an event handler | |
1665 | bool RemoveEventHandler(wxEvtHandler* handler, bool deleteHandler = false); | |
1666 | ||
1667 | /// Clear event handlers | |
1668 | void ClearEventHandlers(); | |
1669 | ||
1670 | /// Send event to event handlers. If sendToAll is true, will send to all event handlers, | |
1671 | /// otherwise will stop at the first successful one. | |
1672 | bool SendEvent(wxEvent& event, bool sendToAll = true); | |
1673 | ||
1674 | // Implementation | |
1675 | ||
1676 | /// Copy | |
1677 | void Copy(const wxRichTextBuffer& obj); | |
1678 | ||
1679 | /// Clone | |
1680 | virtual wxRichTextObject* Clone() const; | |
1681 | ||
1682 | /// Submit command to insert paragraphs | |
1683 | bool InsertParagraphsWithUndo(long pos, const wxRichTextParagraphLayoutBox& paragraphs, wxRichTextCtrl* ctrl, int flags = 0); | |
1684 | ||
1685 | /// Submit command to insert the given text | |
1686 | bool InsertTextWithUndo(long pos, const wxString& text, wxRichTextCtrl* ctrl, int flags = 0); | |
1687 | ||
1688 | /// Submit command to insert a newline | |
1689 | bool InsertNewlineWithUndo(long pos, wxRichTextCtrl* ctrl, int flags = 0); | |
1690 | ||
1691 | /// Submit command to insert the given image | |
1692 | bool InsertImageWithUndo(long pos, const wxRichTextImageBlock& imageBlock, wxRichTextCtrl* ctrl, int flags = 0); | |
1693 | ||
1694 | /// Submit command to delete this range | |
1695 | bool DeleteRangeWithUndo(const wxRichTextRange& range, wxRichTextCtrl* ctrl); | |
1696 | ||
1697 | /// Mark modified | |
1698 | void Modify(bool modify = true); | |
1699 | bool IsModified() const; | |
1700 | ||
1701 | /// Get the style that is appropriate for a new paragraph at this position. | |
1702 | /// If the previous paragraph has a paragraph style name, look up the next-paragraph | |
1703 | /// style. | |
1704 | wxRichTextAttr GetStyleForNewParagraph(long pos, bool caretPosition = false, bool lookUpNewParaStyle=false) const; | |
1705 | ||
1706 | ||
1707 | /// Returns the file handlers | |
1708 | static wxRichTextFileHandlerList_t& GetHandlers(); | |
1709 | ||
1710 | %disownarg(wxRichTextFileHandler *handler); | |
1711 | ||
1712 | /// Adds a handler to the end | |
1713 | static void AddHandler(wxRichTextFileHandler *handler); | |
1714 | ||
1715 | /// Inserts a handler at the front | |
1716 | static void InsertHandler(wxRichTextFileHandler *handler); | |
1717 | ||
1718 | %cleardisown(wxRichTextFileHandler *handler); | |
1719 | ||
1720 | ||
1721 | /// Removes a handler | |
1722 | static bool RemoveHandler(const wxString& name); | |
1723 | ||
1724 | /// Finds a handler by name | |
1725 | %Rename(FindHandlerByName, | |
1726 | static wxRichTextFileHandler* , FindHandler(const wxString& name)); | |
1727 | ||
1728 | /// Finds a handler by extension and type | |
1729 | %Rename(FindHandlerByExtension, | |
1730 | static wxRichTextFileHandler*, FindHandler(const wxString& extension, int imageType)); | |
1731 | ||
1732 | /// Finds a handler by filename or, if supplied, type | |
1733 | %Rename(FindHandlerByFilename, | |
1734 | static wxRichTextFileHandler* , FindHandlerFilenameOrType(const wxString& filename, int imageType)); | |
1735 | ||
1736 | /// Finds a handler by type | |
1737 | %Rename(FindHandlerByType, | |
1738 | static wxRichTextFileHandler* , FindHandler(int imageType)); | |
1739 | ||
1740 | ||
1741 | // TODO: Handle returning the types array? | |
1742 | ||
1743 | /// Gets a wildcard incorporating all visible handlers. If 'types' is present, | |
1744 | /// will be filled with the file type corresponding to each filter. This can be | |
1745 | /// used to determine the type to pass to LoadFile given a selected filter. | |
1746 | //static wxString GetExtWildcard(bool combine = false, bool save = false, | |
1747 | // wxArrayInt* types = NULL); | |
1748 | %extend { | |
1749 | KeepGIL(GetExtWildcard); | |
1750 | DocAStr(GetExtWildcard, | |
1751 | "GetExtWildcard(self, bool combine=False, bool save=False) --> (wildcards, types)", | |
1752 | "Gets a wildcard string for the file dialog based on all the currently | |
1753 | loaded richtext file handlers, and a list that can be used to map | |
1754 | those filter types to the file handler type.", ""); | |
1755 | static PyObject* GetExtWildcard(bool combine = false, bool save = false) { | |
1756 | wxString wildcards; | |
1757 | wxArrayInt types; | |
1758 | wildcards = wxRichTextBuffer::GetExtWildcard(combine, save, &types); | |
1759 | PyObject* tup = PyTuple_New(2); | |
1760 | PyTuple_SET_ITEM(tup, 0, wx2PyString(wildcards)); | |
1761 | PyTuple_SET_ITEM(tup, 1, wxArrayInt2PyList_helper(types)); | |
1762 | return tup; | |
1763 | } | |
1764 | } | |
1765 | ||
1766 | /// Clean up handlers | |
1767 | static void CleanUpHandlers(); | |
1768 | ||
1769 | /// Initialise the standard handlers | |
1770 | static void InitStandardHandlers(); | |
1771 | ||
1772 | /// Get renderer | |
1773 | static wxRichTextRenderer* GetRenderer(); | |
1774 | ||
1775 | /// Set renderer, deleting old one | |
1776 | static void SetRenderer(wxRichTextRenderer* renderer); | |
1777 | ||
1778 | /// Minimum margin between bullet and paragraph in 10ths of a mm | |
1779 | static int GetBulletRightMargin(); | |
1780 | static void SetBulletRightMargin(int margin); | |
1781 | ||
1782 | /// Factor to multiply by character height to get a reasonable bullet size | |
1783 | static float GetBulletProportion(); | |
1784 | static void SetBulletProportion(float prop); | |
1785 | ||
1786 | /// Scale factor for calculating dimensions | |
1787 | double GetScale() const; | |
1788 | void SetScale(double scale); | |
1789 | }; | |
1790 | ||
1791 | ||
1792 | ||
1793 | ||
1794 | ||
1795 | ||
1796 | // TODO: Do we need wrappers for the command processor, undo/redo, etc.? | |
1797 | // | |
1798 | // enum wxRichTextCommandId | |
1799 | // { | |
1800 | // wxRICHTEXT_INSERT, | |
1801 | // wxRICHTEXT_DELETE, | |
1802 | // wxRICHTEXT_CHANGE_STYLE | |
1803 | // }; | |
1804 | // class WXDLLIMPEXP_RICHTEXT wxRichTextCommand: public wxCommand | |
1805 | // class WXDLLIMPEXP_RICHTEXT wxRichTextAction: public wxObject | |
1806 | ||
1807 | ||
1808 | ||
1809 | ||
1810 | //--------------------------------------------------------------------------- | |
1811 | %newgroup | |
1812 | ||
1813 | ||
1814 | /*! | |
1815 | * Handler flags | |
1816 | */ | |
1817 | ||
1818 | enum { | |
1819 | // Include style sheet when loading and saving | |
1820 | wxRICHTEXT_HANDLER_INCLUDE_STYLESHEET, | |
1821 | ||
1822 | // Save images to memory file system in HTML handler | |
1823 | wxRICHTEXT_HANDLER_SAVE_IMAGES_TO_MEMORY, | |
1824 | ||
1825 | // Save images to files in HTML handler | |
1826 | wxRICHTEXT_HANDLER_SAVE_IMAGES_TO_FILES, | |
1827 | ||
1828 | // Save images as inline base64 data in HTML handler | |
1829 | wxRICHTEXT_HANDLER_SAVE_IMAGES_TO_BASE64, | |
1830 | ||
1831 | // Don't write header and footer (or BODY), so we can include the | |
1832 | // fragment in a larger document | |
1833 | wxRICHTEXT_HANDLER_NO_HEADER_FOOTER, | |
1834 | }; | |
1835 | ||
1836 | ||
1837 | ||
1838 | ||
1839 | DocStr(wxRichTextFileHandler, | |
1840 | "Base class for file handlers", ""); | |
1841 | ||
1842 | class wxRichTextFileHandler: public wxObject | |
1843 | { | |
1844 | public: | |
1845 | //wxRichTextFileHandler(const wxString& name = wxEmptyString, **** This is an ABC | |
1846 | // const wxString& ext = wxEmptyString, | |
1847 | // int type = 0); | |
1848 | ||
1849 | ~wxRichTextFileHandler(); | |
1850 | ||
1851 | %Rename(LoadStream, | |
1852 | bool, LoadFile(wxRichTextBuffer *buffer, wxInputStream& stream)); | |
1853 | %Rename(SaveStream, | |
1854 | bool, SaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream)); | |
1855 | ||
1856 | bool LoadFile(wxRichTextBuffer *buffer, const wxString& filename); | |
1857 | bool SaveFile(wxRichTextBuffer *buffer, const wxString& filename); | |
1858 | ||
1859 | /// Can we handle this filename (if using files)? By default, checks the extension. | |
1860 | virtual bool CanHandle(const wxString& filename) const; | |
1861 | ||
1862 | /// Can we save using this handler? | |
1863 | virtual bool CanSave() const; | |
1864 | ||
1865 | /// Can we load using this handler? | |
1866 | virtual bool CanLoad() const; | |
1867 | ||
1868 | /// Should this handler be visible to the user? | |
1869 | virtual bool IsVisible() const; | |
1870 | virtual void SetVisible(bool visible); | |
1871 | ||
1872 | /// The name of the nandler | |
1873 | void SetName(const wxString& name); | |
1874 | wxString GetName() const; | |
1875 | %property(Name, GetName, SetName) | |
1876 | ||
1877 | /// The default extension to recognise | |
1878 | void SetExtension(const wxString& ext); | |
1879 | wxString GetExtension() const; | |
1880 | %property(Extension, GetExtension, SetExtension) | |
1881 | ||
1882 | /// The handler type | |
1883 | void SetType(int type); | |
1884 | int GetType() const; | |
1885 | %property(Type, GetType, SetType) | |
1886 | ||
1887 | /// Flags controlling how loading and saving is done | |
1888 | void SetFlags(int flags); | |
1889 | int GetFlags() const; | |
1890 | %property(Flags, GetFlags, SetFlags) | |
1891 | ||
1892 | /// Encoding to use when saving a file. If empty, a suitable encoding is chosen | |
1893 | void SetEncoding(const wxString& encoding); | |
1894 | const wxString& GetEncoding() const; | |
1895 | %property(Encoding, GetEncoding, SetEncoding) | |
1896 | }; | |
1897 | ||
1898 | ||
1899 | ||
1900 | MAKE_CONST_WXSTRING2(TextName, wxT("Text")); | |
1901 | MAKE_CONST_WXSTRING2(TextExt, wxT("txt")); | |
1902 | ||
1903 | class wxRichTextPlainTextHandler: public wxRichTextFileHandler | |
1904 | { | |
1905 | public: | |
1906 | wxRichTextPlainTextHandler(const wxString& name = wxPyTextName, | |
1907 | const wxString& ext = wxPyTextExt, | |
1908 | int type = wxRICHTEXT_TYPE_TEXT); | |
1909 | }; | |
1910 | ||
1911 | ||
1912 | ||
1913 | ||
1914 | ||
1915 | //--------------------------------------------------------------------------- | |
1916 | %newgroup | |
1917 | ||
1918 | ||
1919 | // TODO: Make a PyRichTextRenderer class | |
1920 | ||
1921 | ||
1922 | /*! | |
1923 | * wxRichTextRenderer isolates common drawing functionality | |
1924 | */ | |
1925 | ||
1926 | class wxRichTextRenderer: public wxObject | |
1927 | { | |
1928 | public: | |
1929 | wxRichTextRenderer() {} | |
1930 | virtual ~wxRichTextRenderer() {} | |
1931 | ||
1932 | /// Draw a standard bullet, as specified by the value of GetBulletName | |
1933 | virtual bool DrawStandardBullet(wxRichTextParagraph* paragraph, wxDC& dc, const wxTextAttrEx& attr, const wxRect& rect) = 0; | |
1934 | ||
1935 | /// Draw a bullet that can be described by text, such as numbered or symbol bullets | |
1936 | virtual bool DrawTextBullet(wxRichTextParagraph* paragraph, wxDC& dc, const wxTextAttrEx& attr, const wxRect& rect, const wxString& text) = 0; | |
1937 | ||
1938 | /// Draw a bitmap bullet, where the bullet bitmap is specified by the value of GetBulletName | |
1939 | virtual bool DrawBitmapBullet(wxRichTextParagraph* paragraph, wxDC& dc, const wxTextAttrEx& attr, const wxRect& rect) = 0; | |
1940 | ||
1941 | /// Enumerate the standard bullet names currently supported | |
1942 | virtual bool EnumerateStandardBulletNames(wxArrayString& bulletNames) = 0; | |
1943 | }; | |
1944 | ||
1945 | /*! | |
1946 | * wxRichTextStdRenderer: standard renderer | |
1947 | */ | |
1948 | ||
1949 | class wxRichTextStdRenderer: public wxRichTextRenderer | |
1950 | { | |
1951 | public: | |
1952 | wxRichTextStdRenderer() {} | |
1953 | ||
1954 | /// Draw a standard bullet, as specified by the value of GetBulletName | |
1955 | virtual bool DrawStandardBullet(wxRichTextParagraph* paragraph, wxDC& dc, const wxTextAttrEx& attr, const wxRect& rect); | |
1956 | ||
1957 | /// Draw a bullet that can be described by text, such as numbered or symbol bullets | |
1958 | virtual bool DrawTextBullet(wxRichTextParagraph* paragraph, wxDC& dc, const wxTextAttrEx& attr, const wxRect& rect, const wxString& text); | |
1959 | ||
1960 | /// Draw a bitmap bullet, where the bullet bitmap is specified by the value of GetBulletName | |
1961 | virtual bool DrawBitmapBullet(wxRichTextParagraph* paragraph, wxDC& dc, const wxTextAttrEx& attr, const wxRect& rect); | |
1962 | ||
1963 | /// Enumerate the standard bullet names currently supported | |
1964 | virtual bool EnumerateStandardBulletNames(wxArrayString& bulletNames); | |
1965 | }; | |
1966 | ||
1967 | //--------------------------------------------------------------------------- | |
1968 | //--------------------------------------------------------------------------- |