]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/richtext.i
Some tweaks to reflect changes in wxWidgets
[wxWidgets.git] / wxPython / src / richtext.i
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: richtext.i
3 // Purpose: Classes for wxRichTExtCtrl and support classes
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 %define DOCSTRING
14 ""
15 %enddef
16
17 %module(package="wx", docstring=DOCSTRING) richtext
18
19 %{
20 #include "wx/wxPython/wxPython.h"
21 #include "wx/wxPython/pyclasses.h"
22 #include "wx/wxPython/printfw.h"
23 #include "wx/wxPython/twoitem.h"
24
25 #include <wx/richtext/richtextctrl.h>
26
27
28 class wxEffects;
29 class wxBufferedDC;
30 class wxBufferedPaintDC;
31 class wxMetaFile;
32 class wxMetaFileDC;
33 class wxPrinterDC;
34
35 %}
36
37 #define USE_TEXTATTREX 0
38
39 //----------------------------------------------------------------------
40
41 %import windows.i
42 %import gdi.i
43
44 %pythoncode { wx = _core }
45 %pythoncode { __docfilter__ = wx.__DocFilter(globals()) }
46
47 MAKE_CONST_WXSTRING_NOSWIG(EmptyString);
48
49 //----------------------------------------------------------------------
50
51 enum {
52 wxRE_READONLY,
53 wxRE_MULTILINE,
54
55 wxRICHTEXT_SHIFT_DOWN,
56 wxRICHTEXT_CTRL_DOWN,
57 wxRICHTEXT_ALT_DOWN,
58
59 wxRICHTEXT_SELECTED,
60 wxRICHTEXT_TAGGED,
61 wxRICHTEXT_FOCUSSED,
62 wxRICHTEXT_IS_FOCUS,
63
64 wxRICHTEXT_TYPE_ANY,
65 wxRICHTEXT_TYPE_TEXT,
66 wxRICHTEXT_TYPE_XML,
67 wxRICHTEXT_TYPE_HTML,
68 wxRICHTEXT_TYPE_RTF,
69 wxRICHTEXT_TYPE_PDF,
70
71 wxRICHTEXT_FIXED_WIDTH,
72 wxRICHTEXT_FIXED_HEIGHT,
73 wxRICHTEXT_VARIABLE_WIDTH,
74 wxRICHTEXT_VARIABLE_HEIGHT,
75
76
77 wxRICHTEXT_HITTEST_NONE,
78 wxRICHTEXT_HITTEST_BEFORE,
79 wxRICHTEXT_HITTEST_AFTER,
80 wxRICHTEXT_HITTEST_ON,
81
82 wxRICHTEXT_FORMATTED,
83 wxRICHTEXT_UNFORMATTED,
84
85
86 // TODO: Rename these to be wxRICHTEXT_* ??
87
88 wxTEXT_ATTR_TEXT_COLOUR,
89 wxTEXT_ATTR_BACKGROUND_COLOUR,
90 wxTEXT_ATTR_FONT_FACE,
91 wxTEXT_ATTR_FONT_SIZE,
92 wxTEXT_ATTR_FONT_WEIGHT,
93 wxTEXT_ATTR_FONT_ITALIC,
94 wxTEXT_ATTR_FONT_UNDERLINE,
95 wxTEXT_ATTR_FONT,
96 wxTEXT_ATTR_ALIGNMENT,
97 wxTEXT_ATTR_LEFT_INDENT,
98 wxTEXT_ATTR_RIGHT_INDENT,
99 wxTEXT_ATTR_TABS,
100
101 wxTEXT_ATTR_PARA_SPACING_AFTER,
102 wxTEXT_ATTR_PARA_SPACING_BEFORE,
103 wxTEXT_ATTR_LINE_SPACING,
104 wxTEXT_ATTR_CHARACTER_STYLE_NAME,
105 wxTEXT_ATTR_PARAGRAPH_STYLE_NAME,
106 wxTEXT_ATTR_BULLET_STYLE,
107 wxTEXT_ATTR_BULLET_NUMBER,
108 wxTEXT_ATTR_BULLET_SYMBOL,
109
110 wxTEXT_ATTR_BULLET_STYLE_NONE,
111 wxTEXT_ATTR_BULLET_STYLE_ARABIC,
112 wxTEXT_ATTR_BULLET_STYLE_LETTERS_UPPER,
113 wxTEXT_ATTR_BULLET_STYLE_LETTERS_LOWER,
114 wxTEXT_ATTR_BULLET_STYLE_ROMAN_UPPER,
115 wxTEXT_ATTR_BULLET_STYLE_ROMAN_LOWER,
116 wxTEXT_ATTR_BULLET_STYLE_SYMBOL,
117 wxTEXT_ATTR_BULLET_STYLE_BITMAP,
118 wxTEXT_ATTR_BULLET_STYLE_PARENTHESES,
119 wxTEXT_ATTR_BULLET_STYLE_PERIOD,
120
121 wxTEXT_ATTR_LINE_SPACING_NORMAL,
122 wxTEXT_ATTR_LINE_SPACING_HALF,
123 wxTEXT_ATTR_LINE_SPACING_TWICE,
124
125 };
126
127 enum wxTextAttrAlignment
128 {
129 wxTEXT_ALIGNMENT_DEFAULT,
130 wxTEXT_ALIGNMENT_LEFT,
131 wxTEXT_ALIGNMENT_CENTRE,
132 wxTEXT_ALIGNMENT_CENTER = wxTEXT_ALIGNMENT_CENTRE,
133 wxTEXT_ALIGNMENT_RIGHT,
134 wxTEXT_ALIGNMENT_JUSTIFIED
135 };
136
137 //----------------------------------------------------------------------
138
139 %typemap(in) wxRichTextRange& (wxRichTextRange temp) {
140 $1 = &temp;
141 if ( ! wxRichTextRange_helper($input, &$1)) SWIG_fail;
142 }
143 %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxRichTextRange& {
144 $1 = wxPySimple_typecheck($input, wxT("wxRichTextRange"), 2);
145 }
146
147
148 %{
149
150 bool wxRichTextRange_helper(PyObject* source, wxRichTextRange** obj)
151 {
152 if (source == Py_None) {
153 **obj = wxRICHTEXT_NONE;
154 return true;
155 }
156 return wxPyTwoIntItem_helper(source, obj, wxT("wxRichTextRange"));
157 }
158 %}
159
160
161
162 DocStr(wxRichTextRange,
163 "RichTextRange is a data structure that represents a range of text
164 within a `RichTextCtrl`. It simply contains integer ``start`` and
165 ``end`` properties and a few operations useful for dealing with
166 ranges. In most places in wxPython where a RichTextRange is expected a
167 2-tuple containing (start, end) can be used instead.", "");
168
169 class wxRichTextRange
170 {
171 public:
172 DocCtorStr(
173 wxRichTextRange(long start=0, long end=0),
174 "Creates a new range object.", "");
175
176 ~wxRichTextRange();
177
178 %extend {
179 KeepGIL(__eq__);
180 DocStr(__eq__, "Test for equality of RichTextRange objects.", "");
181 bool __eq__(PyObject* other) {
182 wxRichTextRange temp, *obj = &temp;
183 if ( other == Py_None ) return false;
184 if ( ! wxRichTextRange_helper(other, &obj) ) {
185 PyErr_Clear();
186 return false;
187 }
188 return self->operator==(*obj);
189 }
190 }
191
192
193 DocDeclStr(
194 wxRichTextRange , operator -(const wxRichTextRange& range) const,
195 "", "");
196
197 DocDeclStr(
198 wxRichTextRange , operator +(const wxRichTextRange& range) const,
199 "", "");
200
201
202 DocDeclStr(
203 void , SetRange(long start, long end),
204 "", "");
205
206
207 DocDeclStr(
208 void , SetStart(long start),
209 "", "");
210
211 DocDeclStr(
212 long , GetStart() const,
213 "", "");
214
215 %pythoncode { start = property(GetStart, SetStart) }
216
217 DocDeclStr(
218 void , SetEnd(long end),
219 "", "");
220
221 DocDeclStr(
222 long , GetEnd() const,
223 "", "");
224
225 %pythoncode { end = property(GetEnd, SetEnd) }
226
227
228 DocDeclStr(
229 bool , IsOutside(const wxRichTextRange& range) const,
230 "Returns true if this range is completely outside 'range'", "");
231
232
233 DocDeclStr(
234 bool , IsWithin(const wxRichTextRange& range) const,
235 "Returns true if this range is completely within 'range'", "");
236
237
238 DocDeclStr(
239 bool , Contains(long pos) const,
240 "Returns true if the given position is within this range. Allow for the
241 possibility of an empty range - assume the position is within this
242 empty range.", "");
243
244
245 DocDeclStr(
246 bool , LimitTo(const wxRichTextRange& range) ,
247 "Limit this range to be within 'range'", "");
248
249
250 DocDeclStr(
251 long , GetLength() const,
252 "Gets the length of the range", "");
253
254
255 DocDeclStr(
256 void , Swap(),
257 "Swaps the start and end", "");
258
259
260 %extend {
261 DocAStr(Get,
262 "Get() -> (start,end)",
263 "Returns the start and end properties as a tuple.", "");
264 PyObject* Get() {
265 wxPyBlock_t blocked = wxPyBeginBlockThreads();
266 PyObject* tup = PyTuple_New(2);
267 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->GetStart()));
268 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->GetEnd()));
269 wxPyEndBlockThreads(blocked);
270 return tup;
271 }
272 }
273 %pythoncode {
274 def __str__(self): return str(self.Get())
275 def __repr__(self): return 'RichTextRange'+str(self.Get())
276 def __len__(self): return len(self.Get())
277 def __getitem__(self, index): return self.Get()[index]
278 def __setitem__(self, index, val):
279 if index == 0: self.start = val
280 elif index == 1: self.end = val
281 else: raise IndexError
282 def __nonzero__(self): return self.Get() != (0,0)
283 __safe_for_unpickling__ = True
284 def __reduce__(self): return (RichTextRange, self.Get())
285 }
286 };
287
288
289
290 %{
291 wxRichTextRange wxPy_RTR_ALL(wxRICHTEXT_ALL);
292 wxRichTextRange wxPy_RTR_NONE(wxRICHTEXT_NONE);
293 %}
294
295 %rename(RICHTEXT_ALL) wxPy_RTR_ALL;
296 %rename(RICHTEXT_NONE) wxPy_RTR_NONE;
297
298 %immutable;
299 wxRichTextRange wxPy_RTR_ALL;
300 wxRichTextRange wxPy_RTR_NONE;
301 %mutable;
302
303 //----------------------------------------------------------------------
304
305 DocStr(wxRichTextAttr,
306 "The RichTextAttr class stored information about the various attributes
307 for a block of text, including font, colour, indents, alignments, and
308 etc.", "");
309
310 class wxRichTextAttr
311 {
312 public:
313
314 wxRichTextAttr(const wxColour& colText = wxNullColour,
315 const wxColour& colBack = wxNullColour,
316 wxTextAttrAlignment alignment = wxTEXT_ALIGNMENT_DEFAULT);
317
318 ~wxRichTextAttr();
319
320 // // Making a wxTextAttrEx object.
321 // operator wxTextAttrEx () const ;
322
323 // // Copy to a wxTextAttr
324 // void CopyTo(wxTextAttrEx& attr) const;
325
326
327
328 // Create font from font attributes.
329 DocDeclStr(
330 wxFont , CreateFont() const,
331 "", "");
332
333
334 // Get attributes from font.
335 bool GetFontAttributes(const wxFont& font);
336
337 %pythoncode {
338 def GetFont(self):
339 return self.CreateFont()
340 def SetFont(self, font):
341 return self.GetFontAttributes(font)
342 }
343
344 // setters
345 void SetTextColour(const wxColour& colText);
346 void SetBackgroundColour(const wxColour& colBack);
347 void SetAlignment(wxTextAttrAlignment alignment);
348 void SetTabs(const wxArrayInt& tabs);
349 void SetLeftIndent(int indent, int subIndent = 0);
350 void SetRightIndent(int indent);
351
352 void SetFontSize(int pointSize);
353 void SetFontStyle(int fontStyle);
354 void SetFontWeight(int fontWeight);
355 void SetFontFaceName(const wxString& faceName);
356 void SetFontUnderlined(bool underlined);
357
358 void SetFlags(long flags);
359
360 void SetCharacterStyleName(const wxString& name);
361 void SetParagraphStyleName(const wxString& name);
362 void SetParagraphSpacingAfter(int spacing);
363 void SetParagraphSpacingBefore(int spacing);
364 void SetLineSpacing(int spacing);
365 void SetBulletStyle(int style);
366 void SetBulletNumber(int n);
367 void SetBulletSymbol(wxChar symbol);
368
369 const wxColour& GetTextColour() const;
370 const wxColour& GetBackgroundColour() const;
371 wxTextAttrAlignment GetAlignment() const;
372 const wxArrayInt& GetTabs() const;
373 long GetLeftIndent() const;
374 long GetLeftSubIndent() const;
375 long GetRightIndent() const;
376 long GetFlags() const;
377
378 int GetFontSize() const;
379 int GetFontStyle() const;
380 int GetFontWeight() const;
381 bool GetFontUnderlined() const;
382 const wxString& GetFontFaceName() const;
383
384 const wxString& GetCharacterStyleName() const;
385 const wxString& GetParagraphStyleName() const;
386 int GetParagraphSpacingAfter() const;
387 int GetParagraphSpacingBefore() const;
388 int GetLineSpacing() const;
389 int GetBulletStyle() const;
390 int GetBulletNumber() const { return m_bulletNumber; }
391 wxChar GetBulletSymbol() const;
392
393 // accessors
394 bool HasTextColour() const;
395 bool HasBackgroundColour() const;
396 bool HasAlignment() const;
397 bool HasTabs() const;
398 bool HasLeftIndent() const;
399 bool HasRightIndent() const;
400 bool HasWeight() const;
401 bool HasSize() const;
402 bool HasItalic() const;
403 bool HasUnderlined() const;
404 bool HasFaceName() const;
405 bool HasFont() const;
406
407 bool HasParagraphSpacingAfter() const;
408 bool HasParagraphSpacingBefore() const;
409 bool HasLineSpacing() const;
410 bool HasCharacterStyleName() const;
411 bool HasParagraphStyleName() const;
412 bool HasBulletStyle() const;
413 bool HasBulletNumber() const;
414 bool HasBulletSymbol() const;
415
416 bool HasFlag(long flag) const;
417
418 // Is this a character style?
419 bool IsCharacterStyle() const;
420 bool IsParagraphStyle() const;
421
422 // returns false if we have any attributes set, true otherwise
423 bool IsDefault() const;
424
425 };
426
427
428 enum {
429 wxTEXT_ATTR_CHARACTER,
430 wxTEXT_ATTR_PARAGRAPH,
431 wxTEXT_ATTR_ALL
432 };
433
434
435 //----------------------------------------------------------------------
436 //----------------------------------------------------------------------
437
438 MustHaveApp(wxRichTextCtrl);
439 DocStr(wxRichTextCtrl,
440 "", "");
441
442 class wxRichTextCtrl : public wxScrolledWindow
443 {
444 public:
445 %pythonAppend wxRichTextCtrl "self._setOORInfo(self)"
446 %pythonAppend wxRichTextCtrl() ""
447
448 wxRichTextCtrl( wxWindow* parent,
449 wxWindowID id = -1,
450 const wxPoint& pos = wxDefaultPosition,
451 const wxSize& size = wxDefaultSize,
452 long style = wxRE_MULTILINE );
453 %RenameCtor(PreRichTextCtrl, wxRichTextCtrl());
454
455
456 bool Create( wxWindow* parent,
457 wxWindowID id = -1,
458 const wxPoint& pos = wxDefaultPosition,
459 const wxSize& size = wxDefaultSize,
460 long style = wxRE_MULTILINE );
461
462
463 DocDeclStr(
464 virtual wxString , GetValue() const,
465 "", "");
466
467 DocDeclStr(
468 virtual void , SetValue(const wxString& value),
469 "", "");
470
471
472 DocDeclStr(
473 virtual wxString , GetRange(long from, long to) const,
474 "", "");
475
476
477 DocDeclStr(
478 virtual int , GetLineLength(long lineNo) const ,
479 "", "");
480
481 DocDeclStr(
482 virtual wxString , GetLineText(long lineNo) const ,
483 "", "");
484
485 DocDeclStr(
486 virtual int , GetNumberOfLines() const ,
487 "", "");
488
489
490 DocDeclStr(
491 virtual bool , IsModified() const ,
492 "", "");
493
494 DocDeclStr(
495 virtual bool , IsEditable() const ,
496 "", "");
497
498
499 // more readable flag testing methods
500 DocDeclStr(
501 bool , IsSingleLine() const,
502 "", "");
503
504 DocDeclStr(
505 bool , IsMultiLine() const,
506 "", "");
507
508
509 DocDeclAStr(
510 virtual void , GetSelection(long* OUTPUT, long* OUTPUT) const,
511 "GetSelection() --> (start, end)",
512 "Returns the start and end positions of the current selection. If the
513 values are the same then there is no selection.", "");
514
515
516 DocDeclStr(
517 virtual wxString , GetStringSelection() const,
518 "", "");
519
520
521 DocDeclStr(
522 wxString , GetFilename() const,
523 "", "");
524
525
526 DocDeclStr(
527 void , SetFilename(const wxString& filename),
528 "", "");
529
530
531 DocDeclStr(
532 void , SetDelayedLayoutThreshold(long threshold),
533 "Set the threshold in character positions for doing layout optimization
534 during sizing.", "");
535
536
537 DocDeclStr(
538 long , GetDelayedLayoutThreshold() const,
539 "Get the threshold in character positions for doing layout optimization
540 during sizing.", "");
541
542
543
544 DocDeclStr(
545 virtual void , Clear(),
546 "", "");
547
548 DocDeclStr(
549 virtual void , Replace(long from, long to, const wxString& value),
550 "", "");
551
552 DocDeclStr(
553 virtual void , Remove(long from, long to),
554 "", "");
555
556
557 DocDeclStr(
558 virtual bool , LoadFile(const wxString& file, int type = wxRICHTEXT_TYPE_ANY),
559 "Load the contents of the document from the given filename.", "");
560
561 DocDeclStr(
562 virtual bool , SaveFile(const wxString& file = wxPyEmptyString,
563 int type = wxRICHTEXT_TYPE_ANY),
564 "Save the contents of the document to the given filename, or if the
565 empty string is passed then to the filename set with `SetFileName`.", "");
566
567
568 // sets/clears the dirty flag
569 DocDeclStr(
570 virtual void , MarkDirty(),
571 "Sets the dirty flag, meaning that the contents of the control have
572 changed and need to be saved.", "");
573
574 DocDeclStr(
575 virtual void , DiscardEdits(),
576 "Clears the dirty flag.
577 :see: `MarkDirty`", "");
578
579
580 DocDeclStr(
581 virtual void , SetMaxLength(unsigned long len),
582 "Set the max number of characters which may be entered in a single line
583 text control.", "");
584
585
586 DocDeclStr(
587 virtual void , WriteText(const wxString& text),
588 "Insert text at the current position.", "");
589
590 DocDeclStr(
591 virtual void , AppendText(const wxString& text),
592 "Append text to the end of the document.", "");
593
594
595 DocDeclStr(
596 virtual bool , SetStyle(const wxRichTextRange& range, const wxRichTextAttr& style),
597 "Set the style for the text in ``range`` to ``style``", "");
598
599 DocDeclStr(
600 virtual bool , GetStyle(long position, wxRichTextAttr& style) const,
601 "Retrieve the style used at the given position. Copies the style
602 values at ``position`` into the ``style`` parameter returns ``True``
603 if successful. Returns ``False`` otherwise.", "");
604
605
606 DocDeclStr(
607 virtual bool , SetDefaultStyle(const wxRichTextAttr& style),
608 "Set the style used by default for the rich text document.", "");
609
610
611 DocDeclStrName(
612 virtual const wxRichTextAttr , GetDefaultStyleEx() const,
613 "Retrieves a copy of the default style object.", "",
614 GetDefaultStyle);
615
616
617 DocDeclStr(
618 virtual long , XYToPosition(long x, long y) const,
619 "Translate a col,row coordinants into a document position.", "");
620
621 DocDeclAStr(
622 virtual void , PositionToXY(long pos, long *OUTPUT, long *OUTPUT) const,
623 "PositionToXY(self, long pos) --> (x, y)",
624 "Retrieves the col,row for the given position within the document", "");
625
626
627 DocDeclStr(
628 virtual void , ShowPosition(long position),
629 "Ensure that the given position in the document is visible.", "");
630
631
632 DocDeclAStr(
633 virtual wxTextCtrlHitTestResult , HitTest(const wxPoint& pt, long *OUTPUT) const,
634 "HitTest(self, Point pt) --> (result, pos)",
635 "Returns the character position at the given point in pixels. Note
636 that ``pt`` should be given in device coordinates, and not be adjusted
637 for the client area origin nor for scrolling. The return value is a
638 tuple of the hit test result and the position.", "
639
640 Possible result values are a bitmask of these flags:
641
642 ========================= ====================================
643 RICHTEXT_HITTEST_NONE The point was not on this object.
644 RICHTEXT_HITTEST_BEFORE The point was before the position
645 returned from HitTest.
646 RICHTEXT_HITTEST_AFTER The point was after the position
647 returned from HitTest.
648 RICHTEXT_HITTEST_ON The point was on the position
649 returned from HitTest
650 ========================= ====================================
651 ");
652
653 DocDeclAStrName(
654 virtual wxTextCtrlHitTestResult , HitTest(const wxPoint& pt,
655 wxTextCoord *OUTPUT,
656 wxTextCoord *OUTPUT) const,
657 "HitTestRC(self, Point pt) --> (result, col, row)",
658 "Returns the column and row of the given point in pixels. Note that
659 ``pt`` should be given in device coordinates, and not be adjusted for
660 the client area origin nor for scrolling. The return value is a tuple
661 of the hit test result and the column and row values.", "
662 :see: `HitTest`",
663 HitTestXY);
664
665
666 // Clipboard operations
667 DocDeclStr(
668 virtual void , Copy(),
669 "Copies the selected text to the clipboard.", "");
670
671 DocDeclStr(
672 virtual void , Cut(),
673 "Copies the selected text to the clipboard and removes the selection.", "");
674
675 DocDeclStr(
676 virtual void , Paste(),
677 "Pastes text from the clipboard into the document at the current
678 insertion point.", "");
679
680 DocDeclStr(
681 virtual void , DeleteSelection(),
682 "Remove the current selection.", "");
683
684
685 DocDeclStr(
686 virtual bool , CanCopy() const,
687 "Returns ``True`` if the selection can be copied to the clipboard.", "");
688
689 DocDeclStr(
690 virtual bool , CanCut() const,
691 "Returns ``True`` if the selection can be cut to the clipboard.", "");
692
693 DocDeclStr(
694 virtual bool , CanPaste() const,
695 "Returns ``True`` if the current contents of the clipboard can be
696 pasted into the document.", "");
697
698 DocDeclStr(
699 virtual bool , CanDeleteSelection() const,
700 "Returns ``True`` if the selection can be removed from the document.", "");
701
702
703 // Undo/redo
704 DocDeclStr(
705 virtual void , Undo(),
706 "If the last operation can be undone, undoes the last operation.", "");
707
708 DocDeclStr(
709 virtual void , Redo(),
710 "If the last operation can be redone, redoes the last operation.", "");
711
712
713 DocDeclStr(
714 virtual bool , CanUndo() const,
715 "Returns ``True`` if the last operation can be undone.", "");
716
717 DocDeclStr(
718 virtual bool , CanRedo() const,
719 "Returns ``True`` if the last operation can be redone.", "");
720
721
722 // Insertion point
723 DocDeclStr(
724 virtual void , SetInsertionPoint(long pos),
725 "Sets the insertion point at the given position.", "");
726
727 DocDeclStr(
728 virtual void , SetInsertionPointEnd(),
729 "Moves the insertion point to the end of the document.", "");
730
731 DocDeclStr(
732 virtual long , GetInsertionPoint() const,
733 "Returns the insertion point. This is defined as the zero based index
734 of the character position to the right of the insertion point.", "");
735
736 DocDeclStr(
737 virtual long , GetLastPosition() const,
738 "Returns the zero based index of the last position in the document.", "");
739
740
741 DocDeclStr(
742 virtual void , SetSelection(long from, long to),
743 "Selects the text starting at the first position up to (but not
744 including) the character at the last position. If both parameters are
745 equal to -1 then all text in the control is selected.", "");
746
747 DocDeclStr(
748 virtual void , SelectAll(),
749 "Select all text in the document.", "");
750
751 DocDeclStr(
752 virtual void , SetEditable(bool editable),
753 "Makes the document editable or read-only, overriding the RE_READONLY
754 flag.", "");
755
756
757 // /// Call Freeze to prevent refresh
758 // virtual void Freeze();
759
760 // /// Call Thaw to refresh
761 // virtual void Thaw();
762
763 // /// Call Thaw to refresh
764 // DocDeclStr(
765 // virtual bool , IsFrozen() const,
766 // "", "");
767
768
769 DocDeclStr(
770 virtual bool , HasSelection() const,
771 "", "");
772
773
774 ///// Functionality specific to wxRichTextCtrl
775
776 /// Write an image at the current insertion point. Supply optional type to use
777 /// for internal and file storage of the raw data.
778 DocDeclStr(
779 virtual bool , WriteImage(const wxImage& image, int bitmapType = wxBITMAP_TYPE_PNG),
780 "", "");
781
782
783 /// Write a bitmap at the current insertion point. Supply optional type to use
784 /// for internal and file storage of the raw data.
785 DocDeclStrName(
786 virtual bool , WriteImage(const wxBitmap& bitmap, int bitmapType = wxBITMAP_TYPE_PNG),
787 "", "",
788 WriteBitmap);
789
790
791 /// Load an image from file and write at the current insertion point.
792 DocDeclStrName(
793 virtual bool , WriteImage(const wxString& filename, int bitmapType),
794 "", "",
795 WriteImageFile);
796
797
798 /// Write an image block at the current insertion point.
799 DocDeclStrName(
800 virtual bool , WriteImage(const wxRichTextImageBlock& imageBlock),
801 "", "",
802 WriteImageBlock);
803
804
805 /// Insert a newline (actually paragraph) at the current insertion point.
806 DocDeclStr(
807 virtual bool , Newline(),
808 "", "");
809
810
811 #if USE_TEXTATTREX
812 /// Set basic (overall) style
813 DocDeclStr(
814 virtual void , SetBasicStyle(const wxTextAttrEx& style),
815 "", "");
816 #endif
817
818 DocDeclStr(
819 virtual void , SetBasicStyle(const wxRichTextAttr& style),
820 "", "");
821
822
823 #if USE_TEXTATTREX
824 /// Get basic (overall) style
825 DocDeclStr(
826 virtual const wxTextAttrEx& , GetBasicStyle() const,
827 "", "");
828
829
830 /// Begin using a style
831 DocDeclStr(
832 virtual bool , BeginStyle(const wxTextAttrEx& style),
833 "", "");
834 #endif
835
836 /// End the style
837 DocDeclStr(
838 virtual bool , EndStyle(),
839 "", "");
840
841
842 /// End all styles
843 DocDeclStr(
844 virtual bool , EndAllStyles(),
845 "", "");
846
847
848 /// Begin using bold
849 DocDeclStr(
850 bool , BeginBold(),
851 "", "");
852
853
854 /// End using bold
855 DocDeclStr(
856 bool , EndBold(),
857 "", "");
858
859
860 /// Begin using italic
861 DocDeclStr(
862 bool , BeginItalic(),
863 "", "");
864
865
866 /// End using italic
867 DocDeclStr(
868 bool , EndItalic(),
869 "", "");
870
871
872 /// Begin using underline
873 DocDeclStr(
874 bool , BeginUnderline(),
875 "", "");
876
877
878 /// End using underline
879 DocDeclStr(
880 bool , EndUnderline(),
881 "", "");
882
883
884 /// Begin using point size
885 DocDeclStr(
886 bool , BeginFontSize(int pointSize),
887 "", "");
888
889
890 /// End using point size
891 DocDeclStr(
892 bool , EndFontSize(),
893 "", "");
894
895
896 /// Begin using this font
897 DocDeclStr(
898 bool , BeginFont(const wxFont& font),
899 "", "");
900
901
902 /// End using a font
903 DocDeclStr(
904 bool , EndFont(),
905 "", "");
906
907
908 /// Begin using this colour
909 DocDeclStr(
910 bool , BeginTextColour(const wxColour& colour),
911 "", "");
912
913
914 /// End using a colour
915 DocDeclStr(
916 bool , EndTextColour(),
917 "", "");
918
919
920 /// Begin using alignment
921 DocDeclStr(
922 bool , BeginAlignment(wxTextAttrAlignment alignment),
923 "", "");
924
925
926 /// End alignment
927 DocDeclStr(
928 bool , EndAlignment(),
929 "", "");
930
931
932 /// Begin left indent
933 DocDeclStr(
934 bool , BeginLeftIndent(int leftIndent, int leftSubIndent = 0),
935 "", "");
936
937
938 /// End left indent
939 DocDeclStr(
940 bool , EndLeftIndent(),
941 "", "");
942
943
944 /// Begin right indent
945 DocDeclStr(
946 bool , BeginRightIndent(int rightIndent),
947 "", "");
948
949
950 /// End right indent
951 DocDeclStr(
952 bool , EndRightIndent(),
953 "", "");
954
955
956 /// Begin paragraph spacing
957 DocDeclStr(
958 bool , BeginParagraphSpacing(int before, int after),
959 "", "");
960
961
962 /// End paragraph spacing
963 DocDeclStr(
964 bool , EndParagraphSpacing(),
965 "", "");
966
967
968 /// Begin line spacing
969 DocDeclStr(
970 bool , BeginLineSpacing(int lineSpacing),
971 "", "");
972
973
974 /// End line spacing
975 DocDeclStr(
976 bool , EndLineSpacing(),
977 "", "");
978
979
980 /// Begin numbered bullet
981 DocDeclStr(
982 bool , BeginNumberedBullet(int bulletNumber,
983 int leftIndent,
984 int leftSubIndent,
985 int bulletStyle = wxTEXT_ATTR_BULLET_STYLE_ARABIC|wxTEXT_ATTR_BULLET_STYLE_PERIOD),
986 "", "");
987
988
989 /// End numbered bullet
990 DocDeclStr(
991 bool , EndNumberedBullet(),
992 "", "");
993
994
995 /// Begin symbol bullet
996 DocDeclStr(
997 bool , BeginSymbolBullet(char symbol,
998 int leftIndent,
999 int leftSubIndent,
1000 int bulletStyle = wxTEXT_ATTR_BULLET_STYLE_SYMBOL),
1001 "", "");
1002
1003
1004 /// End symbol bullet
1005 DocDeclStr(
1006 bool , EndSymbolBullet(),
1007 "", "");
1008
1009
1010 /// Begin named character style
1011 DocDeclStr(
1012 bool , BeginCharacterStyle(const wxString& characterStyle),
1013 "", "");
1014
1015
1016 /// End named character style
1017 DocDeclStr(
1018 bool , EndCharacterStyle(),
1019 "", "");
1020
1021
1022 /// Begin named paragraph style
1023 DocDeclStr(
1024 bool , BeginParagraphStyle(const wxString& paragraphStyle),
1025 "", "");
1026
1027
1028 /// End named character style
1029 DocDeclStr(
1030 bool , EndParagraphStyle(),
1031 "", "");
1032
1033
1034 /// Sets the default style to the style under the cursor
1035 DocDeclStr(
1036 bool , SetDefaultStyleToCursorStyle(),
1037 "", "");
1038
1039
1040 /// Clear the selection
1041 DocDeclStr(
1042 virtual void , SelectNone(),
1043 "", "");
1044
1045
1046 /// Get/set the selection range in character positions. -1, -1 means no selection.
1047 DocDeclStr(
1048 const wxRichTextRange& , GetSelectionRange() const,
1049 "", "");
1050
1051 DocDeclStr(
1052 void , SetSelectionRange(const wxRichTextRange& range),
1053 "", "");
1054
1055
1056 /// Add a new paragraph of text to the end of the buffer
1057 DocDeclStr(
1058 virtual wxRichTextRange , AddParagraph(const wxString& text),
1059 "", "");
1060
1061
1062 /// Add an image
1063 DocDeclStr(
1064 virtual wxRichTextRange , AddImage(const wxImage& image),
1065 "", "");
1066
1067
1068 /// Layout the buffer: which we must do before certain operations, such as
1069 /// setting the caret position.
1070 DocDeclStr(
1071 virtual bool , LayoutContent(bool onlyVisibleRect = false),
1072 "", "");
1073
1074
1075 /// Move the caret to the given character position
1076 DocDeclStr(
1077 virtual bool , MoveCaret(long pos, bool showAtLineStart = false),
1078 "", "");
1079
1080
1081 /// Move right
1082 DocDeclStr(
1083 virtual bool , MoveRight(int noPositions = 1, int flags = 0),
1084 "", "");
1085
1086
1087 /// Move left
1088 DocDeclStr(
1089 virtual bool , MoveLeft(int noPositions = 1, int flags = 0),
1090 "", "");
1091
1092
1093 /// Move up
1094 DocDeclStr(
1095 virtual bool , MoveUp(int noLines = 1, int flags = 0),
1096 "", "");
1097
1098
1099 /// Move up
1100 DocDeclStr(
1101 virtual bool , MoveDown(int noLines = 1, int flags = 0),
1102 "", "");
1103
1104
1105 /// Move to the end of the line
1106 DocDeclStr(
1107 virtual bool , MoveToLineEnd(int flags = 0),
1108 "", "");
1109
1110
1111 /// Move to the start of the line
1112 DocDeclStr(
1113 virtual bool , MoveToLineStart(int flags = 0),
1114 "", "");
1115
1116
1117 /// Move to the end of the paragraph
1118 DocDeclStr(
1119 virtual bool , MoveToParagraphEnd(int flags = 0),
1120 "", "");
1121
1122
1123 /// Move to the start of the paragraph
1124 DocDeclStr(
1125 virtual bool , MoveToParagraphStart(int flags = 0),
1126 "", "");
1127
1128
1129 /// Move to the start of the buffer
1130 DocDeclStr(
1131 virtual bool , MoveHome(int flags = 0),
1132 "", "");
1133
1134
1135 /// Move to the end of the buffer
1136 DocDeclStr(
1137 virtual bool , MoveEnd(int flags = 0),
1138 "", "");
1139
1140
1141 /// Move n pages up
1142 DocDeclStr(
1143 virtual bool , PageUp(int noPages = 1, int flags = 0),
1144 "", "");
1145
1146
1147 /// Move n pages down
1148 DocDeclStr(
1149 virtual bool , PageDown(int noPages = 1, int flags = 0),
1150 "", "");
1151
1152
1153 /// Move n words left
1154 DocDeclStr(
1155 virtual bool , WordLeft(int noPages = 1, int flags = 0),
1156 "", "");
1157
1158
1159 /// Move n words right
1160 DocDeclStr(
1161 virtual bool , WordRight(int noPages = 1, int flags = 0),
1162 "", "");
1163
1164
1165 /// Returns the buffer associated with the control.
1166 // wxRichTextBuffer& GetBuffer();
1167 DocDeclStr(
1168 const wxRichTextBuffer& , GetBuffer() const,
1169 "", "");
1170
1171
1172 /// Start batching undo history for commands.
1173 DocDeclStr(
1174 virtual bool , BeginBatchUndo(const wxString& cmdName),
1175 "", "");
1176
1177
1178 /// End batching undo history for commands.
1179 DocDeclStr(
1180 virtual bool , EndBatchUndo(),
1181 "", "");
1182
1183
1184 /// Are we batching undo history for commands?
1185 DocDeclStr(
1186 virtual bool , BatchingUndo() const,
1187 "", "");
1188
1189
1190 /// Start suppressing undo history for commands.
1191 DocDeclStr(
1192 virtual bool , BeginSuppressUndo(),
1193 "", "");
1194
1195
1196 /// End suppressing undo history for commands.
1197 DocDeclStr(
1198 virtual bool , EndSuppressUndo(),
1199 "", "");
1200
1201
1202 /// Are we suppressing undo history for commands?
1203 DocDeclStr(
1204 virtual bool , SuppressingUndo() const,
1205 "", "");
1206
1207
1208 /// Test if this whole range has character attributes of the specified kind. If any
1209 /// of the attributes are different within the range, the test fails. You
1210 /// can use this to implement, for example, bold button updating. style must have
1211 /// flags indicating which attributes are of interest.
1212 #if USE_TEXTATTREX
1213 DocDeclStr(
1214 virtual bool , HasCharacterAttributes(const wxRichTextRange& range,
1215 const wxTextAttrEx& style) const,
1216 "", "");
1217 #endif
1218
1219 DocDeclStr(
1220 virtual bool , HasCharacterAttributes(const wxRichTextRange& range,
1221 const wxRichTextAttr& style) const,
1222 "", "");
1223
1224
1225
1226 /// Test if this whole range has paragraph attributes of the specified kind. If any
1227 /// of the attributes are different within the range, the test fails. You
1228 /// can use this to implement, for example, centering button updating. style must have
1229 /// flags indicating which attributes are of interest.
1230 #if USE_TEXTATTREX
1231 DocDeclStr(
1232 virtual bool , HasParagraphAttributes(const wxRichTextRange& range,
1233 const wxTextAttrEx& style) const,
1234 "", "");
1235 #endif
1236
1237 DocDeclStr(
1238 virtual bool , HasParagraphAttributes(const wxRichTextRange& range,
1239 const wxRichTextAttr& style) const,
1240 "", "");
1241
1242
1243
1244 /// Is all of the selection bold?
1245 DocDeclStr(
1246 virtual bool , IsSelectionBold() const,
1247 "", "");
1248
1249
1250 /// Is all of the selection italics?
1251 DocDeclStr(
1252 virtual bool , IsSelectionItalics() const,
1253 "", "");
1254
1255
1256 /// Is all of the selection underlined?
1257 DocDeclStr(
1258 virtual bool , IsSelectionUnderlined() const,
1259 "", "");
1260
1261
1262 /// Is all of the selection aligned according to the specified flag?
1263 DocDeclStr(
1264 virtual bool , IsSelectionAligned(wxTextAttrAlignment alignment) const,
1265 "", "");
1266
1267
1268 /// Apply bold to the selection
1269 DocDeclStr(
1270 virtual bool , ApplyBoldToSelection(),
1271 "", "");
1272
1273
1274 /// Apply italic to the selection
1275 DocDeclStr(
1276 virtual bool , ApplyItalicToSelection(),
1277 "", "");
1278
1279
1280 /// Apply underline to the selection
1281 DocDeclStr(
1282 virtual bool , ApplyUnderlineToSelection(),
1283 "", "");
1284
1285
1286 /// Apply alignment to the selection
1287 DocDeclStr(
1288 virtual bool , ApplyAlignmentToSelection(wxTextAttrAlignment alignment),
1289 "", "");
1290
1291
1292 /// Set style sheet, if any.
1293 DocDeclStr(
1294 void , SetStyleSheet(wxRichTextStyleSheet* styleSheet),
1295 "", "");
1296
1297 DocDeclStr(
1298 wxRichTextStyleSheet* , GetStyleSheet() const,
1299 "", "");
1300
1301
1302
1303 // Implementation
1304 // TODO: Which of these should be exposed to Python?
1305
1306 // /// Set font, and also default attributes
1307 // virtual bool SetFont(const wxFont& font);
1308
1309 // /// Set up scrollbars, e.g. after a resize
1310 // virtual void SetupScrollbars(bool atTop = false);
1311
1312 // /// Keyboard navigation
1313 // virtual bool KeyboardNavigate(int keyCode, int flags);
1314
1315 // /// Paint the background
1316 // virtual void PaintBackground(wxDC& dc);
1317
1318 // /// Recreate buffer bitmap if necessary
1319 // virtual bool RecreateBuffer(const wxSize& size = wxDefaultSize);
1320
1321 // /// Set the selection
1322 // virtual void DoSetSelection(long from, long to, bool scrollCaret = true);
1323
1324 // /// Write text
1325 // virtual void DoWriteText(const wxString& value, bool selectionOnly = true);
1326
1327 // /// Send an update event
1328 // virtual bool SendUpdateEvent();
1329
1330 // /// Init command event
1331 // void InitCommandEvent(wxCommandEvent& event) const;
1332
1333 // /// do the window-specific processing after processing the update event
1334 // // (duplicated code from wxTextCtrlBase)
1335 // #if !wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE
1336 // virtual void DoUpdateWindowUI(wxUpdateUIEvent& event);
1337 // #endif
1338
1339 // /// Should we inherit colours?
1340 // virtual bool ShouldInheritColours() const;
1341
1342 // /// Position the caret
1343 // virtual void PositionCaret();
1344
1345 // /// Extend the selection, returning true if the selection was
1346 // /// changed. Selections are in caret positions.
1347 // virtual bool ExtendSelection(long oldPosition, long newPosition, int flags);
1348
1349 // /// Scroll into view. This takes a _caret_ position.
1350 // virtual bool ScrollIntoView(long position, int keyCode);
1351
1352 // /// The caret position is the character position just before the caret.
1353 // /// A value of -1 means the caret is at the start of the buffer.
1354 // void SetCaretPosition(long position, bool showAtLineStart = false) ;
1355 // long GetCaretPosition() const;
1356
1357 // /// Move caret one visual step forward: this may mean setting a flag
1358 // /// and keeping the same position if we're going from the end of one line
1359 // /// to the start of the next, which may be the exact same caret position.
1360 // void MoveCaretForward(long oldPosition) ;
1361
1362 // /// Move caret one visual step forward: this may mean setting a flag
1363 // /// and keeping the same position if we're going from the end of one line
1364 // /// to the start of the next, which may be the exact same caret position.
1365 // void MoveCaretBack(long oldPosition) ;
1366
1367 // /// Get the caret height and position for the given character position
1368 // bool GetCaretPositionForIndex(long position, wxRect& rect);
1369
1370 // /// Gets the line for the visible caret position. If the caret is
1371 // /// shown at the very end of the line, it means the next character is actually
1372 // /// on the following line. So let's get the line we're expecting to find
1373 // /// if this is the case.
1374 // wxRichTextLine* GetVisibleLineForCaretPosition(long caretPosition) const;
1375
1376 // /// Gets the command processor
1377 // wxCommandProcessor* GetCommandProcessor() const;
1378
1379 // /// Delete content if there is a selection, e.g. when pressing a key.
1380 // /// Returns the new caret position in newPos, or leaves it if there
1381 // /// was no action.
1382 // bool DeleteSelectedContent(long* newPos= NULL);
1383
1384 // /// Transform logical to physical
1385 // wxPoint GetPhysicalPoint(const wxPoint& ptLogical) const;
1386
1387 // /// Transform physical to logical
1388 // wxPoint GetLogicalPoint(const wxPoint& ptPhysical) const;
1389
1390 // /// Finds the caret position for the next word. Direction
1391 // /// is 1 (forward) or -1 (backwards).
1392 // virtual long FindNextWordPosition(int direction = 1) const;
1393
1394 // /// Is the given position visible on the screen?
1395 // bool IsPositionVisible(long pos) const;
1396
1397 // /// Returns the first visible position in the current view
1398 // long GetFirstVisiblePosition() const;
1399 };
1400
1401
1402 //----------------------------------------------------------------------
1403
1404
1405 %constant wxEventType wxEVT_COMMAND_RICHTEXT_ITEM_SELECTED;
1406 %constant wxEventType wxEVT_COMMAND_RICHTEXT_ITEM_DESELECTED;
1407 %constant wxEventType wxEVT_COMMAND_RICHTEXT_LEFT_CLICK;
1408 %constant wxEventType wxEVT_COMMAND_RICHTEXT_RIGHT_CLICK;
1409 %constant wxEventType wxEVT_COMMAND_RICHTEXT_MIDDLE_CLICK;
1410 %constant wxEventType wxEVT_COMMAND_RICHTEXT_LEFT_DCLICK;
1411 %constant wxEventType wxEVT_COMMAND_RICHTEXT_RETURN;
1412
1413
1414 %pythoncode {
1415 EVT_RICHTEXT_ITEM_SELECTED = wx.PyEventBinder(wxEVT_COMMAND_RICHTEXT_ITEM_SELECTED, 1)
1416 EVT_RICHTEXT_ITEM_DESELECTED = wx.PyEventBinder(wxEVT_COMMAND_RICHTEXT_ITEM_DESELECTED, 1)
1417 EVT_RICHTEXT_LEFT_CLICK = wx.PyEventBinder(wxEVT_COMMAND_RICHTEXT_LEFT_CLICK, 1)
1418 EVT_RICHTEXT_RIGHT_CLICK = wx.PyEventBinder(wxEVT_COMMAND_RICHTEXT_RIGHT_CLICK, 1)
1419 EVT_RICHTEXT_MIDDLE_CLICK = wx.PyEventBinder(wxEVT_COMMAND_RICHTEXT_MIDDLE_CLICK, 1)
1420 EVT_RICHTEXT_LEFT_DCLICK = wx.PyEventBinder(wxEVT_COMMAND_RICHTEXT_LEFT_DCLICK, 1)
1421 EVT_RICHTEXT_RETURN = wx.PyEventBinder( wxEVT_COMMAND_RICHTEXT_RETURN, 1)
1422 }
1423
1424
1425 class wxRichTextEvent : public wxNotifyEvent
1426 {
1427 public:
1428 wxRichTextEvent(wxEventType commandType = wxEVT_NULL, int winid = 0);
1429
1430 int GetIndex() const;
1431 void SetIndex(int n);
1432
1433 int GetFlags() const;
1434 void SetFlags(int flags);
1435 };
1436
1437 //----------------------------------------------------------------------
1438
1439 %init %{
1440 %}
1441
1442 //----------------------------------------------------------------------