1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Classes for wxRichTExtCtrl and support classes
7 // Created: 11-April-2006
9 // Copyright: (c) 2006 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
17 %module(package="wx", docstring=DOCSTRING) richtext
20 #include "wx/wxPython/wxPython.h"
21 #include "wx/wxPython/pyclasses.h"
22 #include "wx/wxPython/printfw.h"
23 #include "wx/wxPython/twoitem.h"
25 #include <wx/richtext/richtextctrl.h>
30 class wxBufferedPaintDC;
37 #define USE_TEXTATTREX 0
39 //----------------------------------------------------------------------
44 %pythoncode { wx = _core }
45 %pythoncode { __docfilter__ = wx.__DocFilter(globals()) }
47 MAKE_CONST_WXSTRING_NOSWIG(EmptyString);
49 //----------------------------------------------------------------------
55 wxRICHTEXT_SHIFT_DOWN,
71 wxRICHTEXT_FIXED_WIDTH,
72 wxRICHTEXT_FIXED_HEIGHT,
73 wxRICHTEXT_VARIABLE_WIDTH,
74 wxRICHTEXT_VARIABLE_HEIGHT,
77 wxRICHTEXT_HITTEST_NONE,
78 wxRICHTEXT_HITTEST_BEFORE,
79 wxRICHTEXT_HITTEST_AFTER,
80 wxRICHTEXT_HITTEST_ON,
83 wxRICHTEXT_UNFORMATTED,
85 wxRICHTEXT_SETSTYLE_NONE,
86 wxRICHTEXT_SETSTYLE_WITH_UNDO,
87 wxRICHTEXT_SETSTYLE_OPTIMIZE,
88 wxRICHTEXT_SETSTYLE_PARAGRAPHS_ONLY,
89 wxRICHTEXT_SETSTYLE_CHARACTERS_ONLY,
91 wxRICHTEXT_INSERT_NONE,
92 wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE,
96 // TODO: Rename these to be wxRICHTEXT_* ??
98 wxTEXT_ATTR_TEXT_COLOUR,
99 wxTEXT_ATTR_BACKGROUND_COLOUR,
100 wxTEXT_ATTR_FONT_FACE,
101 wxTEXT_ATTR_FONT_SIZE,
102 wxTEXT_ATTR_FONT_WEIGHT,
103 wxTEXT_ATTR_FONT_ITALIC,
104 wxTEXT_ATTR_FONT_UNDERLINE,
106 wxTEXT_ATTR_ALIGNMENT,
107 wxTEXT_ATTR_LEFT_INDENT,
108 wxTEXT_ATTR_RIGHT_INDENT,
111 wxTEXT_ATTR_PARA_SPACING_AFTER,
112 wxTEXT_ATTR_PARA_SPACING_BEFORE,
113 wxTEXT_ATTR_LINE_SPACING,
114 wxTEXT_ATTR_CHARACTER_STYLE_NAME,
115 wxTEXT_ATTR_PARAGRAPH_STYLE_NAME,
116 wxTEXT_ATTR_BULLET_STYLE,
117 wxTEXT_ATTR_BULLET_NUMBER,
119 wxTEXT_ATTR_BULLET_STYLE_NONE,
120 wxTEXT_ATTR_BULLET_STYLE_ARABIC,
121 wxTEXT_ATTR_BULLET_STYLE_LETTERS_UPPER,
122 wxTEXT_ATTR_BULLET_STYLE_LETTERS_LOWER,
123 wxTEXT_ATTR_BULLET_STYLE_ROMAN_UPPER,
124 wxTEXT_ATTR_BULLET_STYLE_ROMAN_LOWER,
125 wxTEXT_ATTR_BULLET_STYLE_SYMBOL,
126 wxTEXT_ATTR_BULLET_STYLE_BITMAP,
127 wxTEXT_ATTR_BULLET_STYLE_PARENTHESES,
128 wxTEXT_ATTR_BULLET_STYLE_PERIOD,
130 wxTEXT_ATTR_LINE_SPACING_NORMAL,
131 wxTEXT_ATTR_LINE_SPACING_HALF,
132 wxTEXT_ATTR_LINE_SPACING_TWICE,
136 enum wxTextAttrAlignment
138 wxTEXT_ALIGNMENT_DEFAULT,
139 wxTEXT_ALIGNMENT_LEFT,
140 wxTEXT_ALIGNMENT_CENTRE,
141 wxTEXT_ALIGNMENT_CENTER = wxTEXT_ALIGNMENT_CENTRE,
142 wxTEXT_ALIGNMENT_RIGHT,
143 wxTEXT_ALIGNMENT_JUSTIFIED
146 //----------------------------------------------------------------------
148 %typemap(in) wxRichTextRange& (wxRichTextRange temp) {
150 if ( ! wxRichTextRange_helper($input, &$1)) SWIG_fail;
152 %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxRichTextRange& {
153 $1 = wxPySimple_typecheck($input, wxT("wxRichTextRange"), 2);
159 bool wxRichTextRange_helper(PyObject* source, wxRichTextRange** obj)
161 if (source == Py_None) {
162 **obj = wxRICHTEXT_NONE;
165 return wxPyTwoIntItem_helper(source, obj, wxT("wxRichTextRange"));
171 DocStr(wxRichTextRange,
172 "RichTextRange is a data structure that represents a range of text
173 within a `RichTextCtrl`. It simply contains integer ``start`` and
174 ``end`` properties and a few operations useful for dealing with
175 ranges. In most places in wxPython where a RichTextRange is expected a
176 2-tuple containing (start, end) can be used instead.", "");
178 class wxRichTextRange
182 wxRichTextRange(long start=0, long end=0),
183 "Creates a new range object.", "");
189 DocStr(__eq__, "Test for equality of RichTextRange objects.", "");
190 bool __eq__(PyObject* other) {
191 wxRichTextRange temp, *obj = &temp;
192 if ( other == Py_None ) return false;
193 if ( ! wxRichTextRange_helper(other, &obj) ) {
197 return self->operator==(*obj);
203 wxRichTextRange , operator -(const wxRichTextRange& range) const,
207 wxRichTextRange , operator +(const wxRichTextRange& range) const,
212 void , SetRange(long start, long end),
217 void , SetStart(long start),
221 long , GetStart() const,
224 %pythoncode { start = property(GetStart, SetStart) }
227 void , SetEnd(long end),
231 long , GetEnd() const,
234 %pythoncode { end = property(GetEnd, SetEnd) }
238 bool , IsOutside(const wxRichTextRange& range) const,
239 "Returns true if this range is completely outside 'range'", "");
243 bool , IsWithin(const wxRichTextRange& range) const,
244 "Returns true if this range is completely within 'range'", "");
248 bool , Contains(long pos) const,
249 "Returns true if the given position is within this range. Allow for the
250 possibility of an empty range - assume the position is within this
255 bool , LimitTo(const wxRichTextRange& range) ,
256 "Limit this range to be within 'range'", "");
260 long , GetLength() const,
261 "Gets the length of the range", "");
266 "Swaps the start and end", "");
271 "Get() -> (start,end)",
272 "Returns the start and end properties as a tuple.", "");
274 wxPyBlock_t blocked = wxPyBeginBlockThreads();
275 PyObject* tup = PyTuple_New(2);
276 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->GetStart()));
277 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->GetEnd()));
278 wxPyEndBlockThreads(blocked);
283 def __str__(self): return str(self.Get())
284 def __repr__(self): return 'RichTextRange'+str(self.Get())
285 def __len__(self): return len(self.Get())
286 def __getitem__(self, index): return self.Get()[index]
287 def __setitem__(self, index, val):
288 if index == 0: self.start = val
289 elif index == 1: self.end = val
290 else: raise IndexError
291 def __nonzero__(self): return self.Get() != (0,0)
292 __safe_for_unpickling__ = True
293 def __reduce__(self): return (RichTextRange, self.Get())
296 %property(End, GetEnd, SetEnd, doc="See `GetEnd` and `SetEnd`");
297 %property(Length, GetLength, doc="See `GetLength`");
298 %property(Start, GetStart, SetStart, doc="See `GetStart` and `SetStart`");
304 wxRichTextRange wxPy_RTR_ALL(wxRICHTEXT_ALL);
305 wxRichTextRange wxPy_RTR_NONE(wxRICHTEXT_NONE);
308 %rename(RICHTEXT_ALL) wxPy_RTR_ALL;
309 %rename(RICHTEXT_NONE) wxPy_RTR_NONE;
312 wxRichTextRange wxPy_RTR_ALL;
313 wxRichTextRange wxPy_RTR_NONE;
316 //----------------------------------------------------------------------
318 DocStr(wxRichTextAttr,
319 "The RichTextAttr class stored information about the various attributes
320 for a block of text, including font, colour, indents, alignments, and
327 wxRichTextAttr(const wxColour& colText = wxNullColour,
328 const wxColour& colBack = wxNullColour,
329 wxTextAttrAlignment alignment = wxTEXT_ALIGNMENT_DEFAULT);
333 // // Making a wxTextAttrEx object.
334 // operator wxTextAttrEx () const ;
336 // // Copy to a wxTextAttr
337 // void CopyTo(wxTextAttrEx& attr) const;
341 // Create font from font attributes.
343 wxFont , CreateFont() const,
347 // Get attributes from font.
348 bool GetFontAttributes(const wxFont& font);
352 return self.CreateFont()
353 def SetFont(self, font):
354 return self.GetFontAttributes(font)
358 void SetTextColour(const wxColour& colText);
359 void SetBackgroundColour(const wxColour& colBack);
360 void SetAlignment(wxTextAttrAlignment alignment);
361 void SetTabs(const wxArrayInt& tabs);
362 void SetLeftIndent(int indent, int subIndent = 0);
363 void SetRightIndent(int indent);
365 void SetFontSize(int pointSize);
366 void SetFontStyle(int fontStyle);
367 void SetFontWeight(int fontWeight);
368 void SetFontFaceName(const wxString& faceName);
369 void SetFontUnderlined(bool underlined);
371 void SetFlags(long flags);
373 void SetCharacterStyleName(const wxString& name);
374 void SetParagraphStyleName(const wxString& name);
375 void SetParagraphSpacingAfter(int spacing);
376 void SetParagraphSpacingBefore(int spacing);
377 void SetLineSpacing(int spacing);
378 void SetBulletStyle(int style);
379 void SetBulletNumber(int n);
380 void SetBulletText(wxChar symbol);
381 void SetBulletFont(const wxString& bulletFont);
383 const wxColour& GetTextColour() const;
384 const wxColour& GetBackgroundColour() const;
385 wxTextAttrAlignment GetAlignment() const;
386 const wxArrayInt& GetTabs() const;
387 long GetLeftIndent() const;
388 long GetLeftSubIndent() const;
389 long GetRightIndent() const;
390 long GetFlags() const;
392 int GetFontSize() const;
393 int GetFontStyle() const;
394 int GetFontWeight() const;
395 bool GetFontUnderlined() const;
396 const wxString& GetFontFaceName() const;
398 const wxString& GetCharacterStyleName() const;
399 const wxString& GetParagraphStyleName() const;
400 int GetParagraphSpacingAfter() const;
401 int GetParagraphSpacingBefore() const;
402 int GetLineSpacing() const;
403 int GetBulletStyle() const;
404 int GetBulletNumber() const;
405 const wxString& GetBulletText() const;
406 const wxString& GetBulletFont() const;
409 bool HasTextColour() const;
410 bool HasBackgroundColour() const;
411 bool HasAlignment() const;
412 bool HasTabs() const;
413 bool HasLeftIndent() const;
414 bool HasRightIndent() const;
415 // bool HasWeight() const;
416 // bool HasSize() const;
417 // bool HasItalic() const;
418 // bool HasUnderlined() const;
419 // bool HasFaceName() const;
420 bool HasFont() const;
422 bool HasParagraphSpacingAfter() const;
423 bool HasParagraphSpacingBefore() const;
424 bool HasLineSpacing() const;
425 bool HasCharacterStyleName() const;
426 bool HasParagraphStyleName() const;
427 bool HasBulletStyle() const;
428 bool HasBulletNumber() const;
429 bool HasBulletText() const;
431 bool HasFlag(long flag) const;
433 // Is this a character style?
434 bool IsCharacterStyle() const;
435 bool IsParagraphStyle() const;
437 // returns false if we have any attributes set, true otherwise
438 bool IsDefault() const;
441 // // return the attribute having the valid font and colours: it uses the
442 // // attributes set in attr and falls back first to attrDefault and then to
443 // // the text control font/colours for those attributes which are not set
444 // static wxRichTextAttr Combine(const wxRichTextAttr& attr,
445 // const wxRichTextAttr& attrDef,
446 // const wxTextCtrlBase *text);
449 %property(Alignment, GetAlignment, SetAlignment, doc="See `GetAlignment` and `SetAlignment`");
450 %property(BackgroundColour, GetBackgroundColour, SetBackgroundColour, doc="See `GetBackgroundColour` and `SetBackgroundColour`");
451 %property(BulletFont, GetBulletFont, SetBulletFont, doc="See `GetBulletFont` and `SetBulletFont`");
452 %property(BulletNumber, GetBulletNumber, SetBulletNumber, doc="See `GetBulletNumber` and `SetBulletNumber`");
453 %property(BulletStyle, GetBulletStyle, SetBulletStyle, doc="See `GetBulletStyle` and `SetBulletStyle`");
454 %property(BulletText, GetBulletText, SetBulletText, doc="See `GetBulletText` and `SetBulletText`");
455 %property(CharacterStyleName, GetCharacterStyleName, SetCharacterStyleName, doc="See `GetCharacterStyleName` and `SetCharacterStyleName`");
456 %property(Flags, GetFlags, SetFlags, doc="See `GetFlags` and `SetFlags`");
457 %property(Font, GetFont, SetFont, doc="See `GetFont` and `SetFont`");
458 %property(FontAttributes, GetFontAttributes, doc="See `GetFontAttributes`");
459 %property(FontFaceName, GetFontFaceName, SetFontFaceName, doc="See `GetFontFaceName` and `SetFontFaceName`");
460 %property(FontSize, GetFontSize, SetFontSize, doc="See `GetFontSize` and `SetFontSize`");
461 %property(FontStyle, GetFontStyle, SetFontStyle, doc="See `GetFontStyle` and `SetFontStyle`");
462 %property(FontUnderlined, GetFontUnderlined, SetFontUnderlined, doc="See `GetFontUnderlined` and `SetFontUnderlined`");
463 %property(FontWeight, GetFontWeight, SetFontWeight, doc="See `GetFontWeight` and `SetFontWeight`");
464 %property(LeftIndent, GetLeftIndent, SetLeftIndent, doc="See `GetLeftIndent` and `SetLeftIndent`");
465 %property(LeftSubIndent, GetLeftSubIndent, doc="See `GetLeftSubIndent`");
466 %property(LineSpacing, GetLineSpacing, SetLineSpacing, doc="See `GetLineSpacing` and `SetLineSpacing`");
467 %property(ParagraphSpacingAfter, GetParagraphSpacingAfter, SetParagraphSpacingAfter, doc="See `GetParagraphSpacingAfter` and `SetParagraphSpacingAfter`");
468 %property(ParagraphSpacingBefore, GetParagraphSpacingBefore, SetParagraphSpacingBefore, doc="See `GetParagraphSpacingBefore` and `SetParagraphSpacingBefore`");
469 %property(ParagraphStyleName, GetParagraphStyleName, SetParagraphStyleName, doc="See `GetParagraphStyleName` and `SetParagraphStyleName`");
470 %property(RightIndent, GetRightIndent, SetRightIndent, doc="See `GetRightIndent` and `SetRightIndent`");
471 %property(Tabs, GetTabs, SetTabs, doc="See `GetTabs` and `SetTabs`");
472 %property(TextColour, GetTextColour, SetTextColour, doc="See `GetTextColour` and `SetTextColour`");
477 wxTEXT_ATTR_CHARACTER,
478 wxTEXT_ATTR_PARAGRAPH,
483 //----------------------------------------------------------------------
484 //----------------------------------------------------------------------
486 MustHaveApp(wxRichTextCtrl);
487 DocStr(wxRichTextCtrl,
490 class wxRichTextCtrl : public wxScrolledWindow
493 %pythonAppend wxRichTextCtrl "self._setOORInfo(self)"
494 %pythonAppend wxRichTextCtrl() ""
496 wxRichTextCtrl( wxWindow* parent,
498 const wxString& value = wxPyEmptyString,
499 const wxPoint& pos = wxDefaultPosition,
500 const wxSize& size = wxDefaultSize,
501 long style = wxRE_MULTILINE );
502 %RenameCtor(PreRichTextCtrl, wxRichTextCtrl());
505 bool Create( wxWindow* parent,
507 const wxString& value = wxPyEmptyString,
508 const wxPoint& pos = wxDefaultPosition,
509 const wxSize& size = wxDefaultSize,
510 long style = wxRE_MULTILINE );
514 virtual wxString , GetValue() const,
518 virtual void , SetValue(const wxString& value),
523 virtual wxString , GetRange(long from, long to) const,
528 virtual int , GetLineLength(long lineNo) const ,
532 virtual wxString , GetLineText(long lineNo) const ,
536 virtual int , GetNumberOfLines() const ,
541 virtual bool , IsModified() const ,
545 virtual bool , IsEditable() const ,
549 // more readable flag testing methods
551 bool , IsSingleLine() const,
555 bool , IsMultiLine() const,
560 virtual void , GetSelection(long* OUTPUT, long* OUTPUT) const,
561 "GetSelection() --> (start, end)",
562 "Returns the start and end positions of the current selection. If the
563 values are the same then there is no selection.", "");
567 virtual wxString , GetStringSelection() const,
572 wxString , GetFilename() const,
577 void , SetFilename(const wxString& filename),
582 void , SetDelayedLayoutThreshold(long threshold),
583 "Set the threshold in character positions for doing layout optimization
584 during sizing.", "");
588 long , GetDelayedLayoutThreshold() const,
589 "Get the threshold in character positions for doing layout optimization
590 during sizing.", "");
595 virtual void , Clear(),
599 virtual void , Replace(long from, long to, const wxString& value),
603 virtual void , Remove(long from, long to),
608 virtual bool , LoadFile(const wxString& file, int type = wxRICHTEXT_TYPE_ANY),
609 "Load the contents of the document from the given filename.", "");
612 virtual bool , SaveFile(const wxString& file = wxPyEmptyString,
613 int type = wxRICHTEXT_TYPE_ANY),
614 "Save the contents of the document to the given filename, or if the
615 empty string is passed then to the filename set with `SetFilename`.", "");
619 void , SetHandlerFlags(int flags),
620 "Set the handler flags, controlling loading and saving.", "");
623 int , GetHandlerFlags() const,
624 "Get the handler flags, controlling loading and saving.", "");
626 // sets/clears the dirty flag
628 virtual void , MarkDirty(),
629 "Sets the dirty flag, meaning that the contents of the control have
630 changed and need to be saved.", "");
633 virtual void , DiscardEdits(),
634 "Clears the dirty flag.
635 :see: `MarkDirty`", "");
639 virtual void , SetMaxLength(unsigned long len),
640 "Set the max number of characters which may be entered in a single line
645 virtual void , WriteText(const wxString& text),
646 "Insert text at the current position.", "");
649 virtual void , AppendText(const wxString& text),
650 "Append text to the end of the document.", "");
654 virtual bool , SetStyle(const wxRichTextRange& range, const wxRichTextAttr& style),
655 "Set the style for the text in ``range`` to ``style``", "");
658 virtual bool , SetStyleEx(const wxRichTextRange& range, const wxRichTextAttr& style,
659 int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO),
660 "Extended style setting operation with flags including:
661 RICHTEXT_SETSTYLE_WITH_UNDO, RICHTEXT_SETSTYLE_OPTIMIZE,
662 RICHTEXT_SETSTYLE_PARAGRAPHS_ONLY, RICHTEXT_SETSTYLE_CHARACTERS_ONLY", "");
667 virtual bool , GetStyle(long position, wxRichTextAttr& style),
668 "Retrieve the style used at the given position. Copies the style
669 values at ``position`` into the ``style`` parameter and returns ``True``
670 if successful. Returns ``False`` otherwise.", "");
673 virtual bool , GetUncombinedStyle(long position, wxRichTextAttr& style),
674 "Get the content (uncombined) attributes for this position. Copies the
675 style values at ``position`` into the ``style`` parameter and returns
676 ``True`` if successful. Returns ``False`` otherwise.", "");
680 virtual bool , SetDefaultStyle(const wxRichTextAttr& style),
681 "Set the style used by default for the rich text document.", "");
685 virtual const wxRichTextAttr , GetDefaultStyleEx() const,
686 "Retrieves a copy of the default style object.", "",
691 virtual long , XYToPosition(long x, long y) const,
692 "Translate a col,row coordinants into a document position.", "");
695 virtual void , PositionToXY(long pos, long *OUTPUT, long *OUTPUT) const,
696 "PositionToXY(self, long pos) --> (x, y)",
697 "Retrieves the col,row for the given position within the document", "");
701 virtual void , ShowPosition(long position),
702 "Ensure that the given position in the document is visible.", "");
706 virtual wxTextCtrlHitTestResult , HitTest(const wxPoint& pt, long *OUTPUT) const,
707 "HitTest(self, Point pt) --> (result, pos)",
708 "Returns the character position at the given point in pixels. Note
709 that ``pt`` should be given in device coordinates, and not be adjusted
710 for the client area origin nor for scrolling. The return value is a
711 tuple of the hit test result and the position.", "
713 Possible result values are a bitmask of these flags:
715 ========================= ====================================
716 RICHTEXT_HITTEST_NONE The point was not on this object.
717 RICHTEXT_HITTEST_BEFORE The point was before the position
718 returned from HitTest.
719 RICHTEXT_HITTEST_AFTER The point was after the position
720 returned from HitTest.
721 RICHTEXT_HITTEST_ON The point was on the position
722 returned from HitTest
723 ========================= ====================================
727 virtual wxTextCtrlHitTestResult , HitTest(const wxPoint& pt,
729 wxTextCoord *OUTPUT) const,
730 "HitTestRC(self, Point pt) --> (result, col, row)",
731 "Returns the column and row of the given point in pixels. Note that
732 ``pt`` should be given in device coordinates, and not be adjusted for
733 the client area origin nor for scrolling. The return value is a tuple
734 of the hit test result and the column and row values.", "
739 // Clipboard operations
741 virtual void , Copy(),
742 "Copies the selected text to the clipboard.", "");
745 virtual void , Cut(),
746 "Copies the selected text to the clipboard and removes the selection.", "");
749 virtual void , Paste(),
750 "Pastes text from the clipboard into the document at the current
751 insertion point.", "");
754 virtual void , DeleteSelection(),
755 "Remove the current selection.", "");
759 virtual bool , CanCopy() const,
760 "Returns ``True`` if the selection can be copied to the clipboard.", "");
763 virtual bool , CanCut() const,
764 "Returns ``True`` if the selection can be cut to the clipboard.", "");
767 virtual bool , CanPaste() const,
768 "Returns ``True`` if the current contents of the clipboard can be
769 pasted into the document.", "");
772 virtual bool , CanDeleteSelection() const,
773 "Returns ``True`` if the selection can be removed from the document.", "");
778 virtual void , Undo(),
779 "If the last operation can be undone, undoes the last operation.", "");
782 virtual void , Redo(),
783 "If the last operation can be redone, redoes the last operation.", "");
787 virtual bool , CanUndo() const,
788 "Returns ``True`` if the last operation can be undone.", "");
791 virtual bool , CanRedo() const,
792 "Returns ``True`` if the last operation can be redone.", "");
797 virtual void , SetInsertionPoint(long pos),
798 "Sets the insertion point at the given position.", "");
801 virtual void , SetInsertionPointEnd(),
802 "Moves the insertion point to the end of the document.", "");
805 virtual long , GetInsertionPoint() const,
806 "Returns the insertion point. This is defined as the zero based index
807 of the character position to the right of the insertion point.", "");
810 virtual long , GetLastPosition() const,
811 "Returns the zero based index of the last position in the document.", "");
815 virtual void , SetSelection(long from, long to),
816 "Selects the text starting at the first position up to (but not
817 including) the character at the last position. If both parameters are
818 equal to -1 then all text in the control is selected.", "");
821 virtual void , SelectAll(),
822 "Select all text in the document.", "");
825 virtual void , SetEditable(bool editable),
826 "Makes the document editable or read-only, overriding the RE_READONLY
830 // /// Call Freeze to prevent refresh
831 // virtual void Freeze();
833 // /// Call Thaw to refresh
834 // virtual void Thaw();
836 // /// Call Thaw to refresh
838 // virtual bool , IsFrozen() const,
843 virtual bool , HasSelection() const,
847 ///// Functionality specific to wxRichTextCtrl
849 /// Write an image at the current insertion point. Supply optional type to use
850 /// for internal and file storage of the raw data.
852 virtual bool , WriteImage(const wxImage& image, int bitmapType = wxBITMAP_TYPE_PNG),
856 /// Write a bitmap at the current insertion point. Supply optional type to use
857 /// for internal and file storage of the raw data.
859 virtual bool , WriteImage(const wxBitmap& bitmap, int bitmapType = wxBITMAP_TYPE_PNG),
864 /// Load an image from file and write at the current insertion point.
866 virtual bool , WriteImage(const wxString& filename, int bitmapType),
871 /// Write an image block at the current insertion point.
873 virtual bool , WriteImage(const wxRichTextImageBlock& imageBlock),
878 /// Insert a newline (actually paragraph) at the current insertion point.
880 virtual bool , Newline(),
885 /// Set basic (overall) style
887 virtual void , SetBasicStyle(const wxTextAttrEx& style),
892 virtual void , SetBasicStyle(const wxRichTextAttr& style),
897 /// Get basic (overall) style
899 virtual const wxTextAttrEx& , GetBasicStyle() const,
903 /// Begin using a style
905 virtual bool , BeginStyle(const wxTextAttrEx& style),
911 virtual bool , EndStyle(),
917 virtual bool , EndAllStyles(),
933 /// Begin using italic
935 bool , BeginItalic(),
945 /// Begin using underline
947 bool , BeginUnderline(),
951 /// End using underline
953 bool , EndUnderline(),
957 /// Begin using point size
959 bool , BeginFontSize(int pointSize),
963 /// End using point size
965 bool , EndFontSize(),
969 /// Begin using this font
971 bool , BeginFont(const wxFont& font),
981 /// Begin using this colour
983 bool , BeginTextColour(const wxColour& colour),
987 /// End using a colour
989 bool , EndTextColour(),
993 /// Begin using alignment
995 bool , BeginAlignment(wxTextAttrAlignment alignment),
1001 bool , EndAlignment(),
1005 /// Begin left indent
1007 bool , BeginLeftIndent(int leftIndent, int leftSubIndent = 0),
1013 bool , EndLeftIndent(),
1017 /// Begin right indent
1019 bool , BeginRightIndent(int rightIndent),
1023 /// End right indent
1025 bool , EndRightIndent(),
1029 /// Begin paragraph spacing
1031 bool , BeginParagraphSpacing(int before, int after),
1035 /// End paragraph spacing
1037 bool , EndParagraphSpacing(),
1041 /// Begin line spacing
1043 bool , BeginLineSpacing(int lineSpacing),
1047 /// End line spacing
1049 bool , EndLineSpacing(),
1053 /// Begin numbered bullet
1055 bool , BeginNumberedBullet(int bulletNumber,
1058 int bulletStyle = wxTEXT_ATTR_BULLET_STYLE_ARABIC|wxTEXT_ATTR_BULLET_STYLE_PERIOD),
1062 /// End numbered bullet
1064 bool , EndNumberedBullet(),
1068 /// Begin symbol bullet
1070 bool , BeginSymbolBullet(const wxString& symbol,
1073 int bulletStyle = wxTEXT_ATTR_BULLET_STYLE_SYMBOL),
1077 /// End symbol bullet
1079 bool , EndSymbolBullet(),
1083 /// Begin named character style
1085 bool , BeginCharacterStyle(const wxString& characterStyle),
1089 /// End named character style
1091 bool , EndCharacterStyle(),
1095 /// Begin named paragraph style
1097 bool , BeginParagraphStyle(const wxString& paragraphStyle),
1101 /// End named character style
1103 bool , EndParagraphStyle(),
1108 bool , BeginListStyle(const wxString& listStyle, int level = 1, int number = 1),
1109 "Begin named list style.", "");
1112 bool , EndListStyle(), "End named list style.", "");
1115 bool , BeginURL(const wxString& url, const wxString& characterStyle = wxEmptyString),
1119 bool , EndURL(), "End URL.", "");
1121 /// Sets the default style to the style under the cursor
1123 bool , SetDefaultStyleToCursorStyle(),
1127 /// Clear the selection
1129 virtual void , SelectNone(),
1132 /// Select the word at the given character position
1134 virtual bool , SelectWord(long position),
1138 /// Get/set the selection range in character positions. -1, -1 means no selection.
1140 wxRichTextRange , GetSelectionRange() const,
1144 void , SetSelectionRange(const wxRichTextRange& range),
1147 /// Get/set the selection range in character positions. -1, -1 means no selection.
1148 /// The range is in internal format, i.e. a single character selection is denoted
1151 const wxRichTextRange& , GetInternalSelectionRange() const,
1155 void , SetInternalSelectionRange(const wxRichTextRange& range),
1160 /// Add a new paragraph of text to the end of the buffer
1162 virtual wxRichTextRange , AddParagraph(const wxString& text),
1168 virtual wxRichTextRange , AddImage(const wxImage& image),
1172 /// Layout the buffer: which we must do before certain operations, such as
1173 /// setting the caret position.
1175 virtual bool , LayoutContent(bool onlyVisibleRect = false),
1179 /// Move the caret to the given character position
1181 virtual bool , MoveCaret(long pos, bool showAtLineStart = false),
1187 virtual bool , MoveRight(int noPositions = 1, int flags = 0),
1193 virtual bool , MoveLeft(int noPositions = 1, int flags = 0),
1199 virtual bool , MoveUp(int noLines = 1, int flags = 0),
1205 virtual bool , MoveDown(int noLines = 1, int flags = 0),
1209 /// Move to the end of the line
1211 virtual bool , MoveToLineEnd(int flags = 0),
1215 /// Move to the start of the line
1217 virtual bool , MoveToLineStart(int flags = 0),
1221 /// Move to the end of the paragraph
1223 virtual bool , MoveToParagraphEnd(int flags = 0),
1227 /// Move to the start of the paragraph
1229 virtual bool , MoveToParagraphStart(int flags = 0),
1233 /// Move to the start of the buffer
1235 virtual bool , MoveHome(int flags = 0),
1239 /// Move to the end of the buffer
1241 virtual bool , MoveEnd(int flags = 0),
1247 virtual bool , PageUp(int noPages = 1, int flags = 0),
1251 /// Move n pages down
1253 virtual bool , PageDown(int noPages = 1, int flags = 0),
1257 /// Move n words left
1259 virtual bool , WordLeft(int noPages = 1, int flags = 0),
1263 /// Move n words right
1265 virtual bool , WordRight(int noPages = 1, int flags = 0),
1269 /// Returns the buffer associated with the control.
1270 // wxRichTextBuffer& GetBuffer();
1272 const wxRichTextBuffer& , GetBuffer() const,
1276 /// Start batching undo history for commands.
1278 virtual bool , BeginBatchUndo(const wxString& cmdName),
1282 /// End batching undo history for commands.
1284 virtual bool , EndBatchUndo(),
1288 /// Are we batching undo history for commands?
1290 virtual bool , BatchingUndo() const,
1294 /// Start suppressing undo history for commands.
1296 virtual bool , BeginSuppressUndo(),
1300 /// End suppressing undo history for commands.
1302 virtual bool , EndSuppressUndo(),
1306 /// Are we suppressing undo history for commands?
1308 virtual bool , SuppressingUndo() const,
1312 /// Test if this whole range has character attributes of the specified kind. If any
1313 /// of the attributes are different within the range, the test fails. You
1314 /// can use this to implement, for example, bold button updating. style must have
1315 /// flags indicating which attributes are of interest.
1318 virtual bool , HasCharacterAttributes(const wxRichTextRange& range,
1319 const wxTextAttrEx& style) const,
1324 virtual bool , HasCharacterAttributes(const wxRichTextRange& range,
1325 const wxRichTextAttr& style) const,
1330 /// Test if this whole range has paragraph attributes of the specified kind. If any
1331 /// of the attributes are different within the range, the test fails. You
1332 /// can use this to implement, for example, centering button updating. style must have
1333 /// flags indicating which attributes are of interest.
1336 virtual bool , HasParagraphAttributes(const wxRichTextRange& range,
1337 const wxTextAttrEx& style) const,
1342 virtual bool , HasParagraphAttributes(const wxRichTextRange& range,
1343 const wxRichTextAttr& style) const,
1348 /// Is all of the selection bold?
1350 virtual bool , IsSelectionBold(),
1354 /// Is all of the selection italics?
1356 virtual bool , IsSelectionItalics(),
1360 /// Is all of the selection underlined?
1362 virtual bool , IsSelectionUnderlined(),
1366 /// Is all of the selection aligned according to the specified flag?
1368 virtual bool , IsSelectionAligned(wxTextAttrAlignment alignment),
1372 /// Apply bold to the selection
1374 virtual bool , ApplyBoldToSelection(),
1378 /// Apply italic to the selection
1380 virtual bool , ApplyItalicToSelection(),
1384 /// Apply underline to the selection
1386 virtual bool , ApplyUnderlineToSelection(),
1390 /// Apply alignment to the selection
1392 virtual bool , ApplyAlignmentToSelection(wxTextAttrAlignment alignment),
1396 /// Set style sheet, if any.
1398 void , SetStyleSheet(wxRichTextStyleSheet* styleSheet),
1402 wxRichTextStyleSheet* , GetStyleSheet() const,
1405 /// Apply the style sheet to the buffer, for example if the styles have changed.
1407 bool , ApplyStyleSheet(wxRichTextStyleSheet* styleSheet = NULL),
1412 %property(Buffer, GetBuffer, doc="See `GetBuffer`");
1413 %property(DefaultStyle, GetDefaultStyle, SetDefaultStyle, doc="See `GetDefaultStyle` and `SetDefaultStyle`");
1414 %property(DelayedLayoutThreshold, GetDelayedLayoutThreshold, SetDelayedLayoutThreshold, doc="See `GetDelayedLayoutThreshold` and `SetDelayedLayoutThreshold`");
1415 %property(Filename, GetFilename, SetFilename, doc="See `GetFilename` and `SetFilename`");
1416 %property(InsertionPoint, GetInsertionPoint, SetInsertionPoint, doc="See `GetInsertionPoint` and `SetInsertionPoint`");
1417 %property(InternalSelectionRange, GetInternalSelectionRange, SetInternalSelectionRange, doc="See `GetInternalSelectionRange` and `SetInternalSelectionRange`");
1418 %property(LastPosition, GetLastPosition, doc="See `GetLastPosition`");
1419 %property(NumberOfLines, GetNumberOfLines, doc="See `GetNumberOfLines`");
1420 %property(Selection, GetSelection, SetSelection, doc="See `GetSelection` and `SetSelection`");
1421 %property(SelectionRange, GetSelectionRange, SetSelectionRange, doc="See `GetSelectionRange` and `SetSelectionRange`");
1422 %property(StringSelection, GetStringSelection, doc="See `GetStringSelection`");
1423 %property(StyleSheet, GetStyleSheet, SetStyleSheet, doc="See `GetStyleSheet` and `SetStyleSheet`");
1424 %property(Value, GetValue, SetValue, doc="See `GetValue` and `SetValue`");
1427 // TODO: Which of these should be exposed to Python?
1429 // /// Set font, and also default attributes
1430 // virtual bool SetFont(const wxFont& font);
1432 // /// Set up scrollbars, e.g. after a resize
1433 // virtual void SetupScrollbars(bool atTop = false);
1435 // /// Keyboard navigation
1436 // virtual bool KeyboardNavigate(int keyCode, int flags);
1438 // /// Paint the background
1439 // virtual void PaintBackground(wxDC& dc);
1441 // /// Recreate buffer bitmap if necessary
1442 // virtual bool RecreateBuffer(const wxSize& size = wxDefaultSize);
1444 // /// Set the selection
1445 // virtual void DoSetSelection(long from, long to, bool scrollCaret = true);
1448 // virtual void DoWriteText(const wxString& value, bool selectionOnly = true);
1450 // /// Send an update event
1451 // virtual bool SendUpdateEvent();
1453 // /// Init command event
1454 // void InitCommandEvent(wxCommandEvent& event) const;
1456 // /// do the window-specific processing after processing the update event
1457 // // (duplicated code from wxTextCtrlBase)
1458 // #if !wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE
1459 // virtual void DoUpdateWindowUI(wxUpdateUIEvent& event);
1462 // /// Should we inherit colours?
1463 // virtual bool ShouldInheritColours() const;
1465 // /// Position the caret
1466 // virtual void PositionCaret();
1468 // /// Extend the selection, returning true if the selection was
1469 // /// changed. Selections are in caret positions.
1470 // virtual bool ExtendSelection(long oldPosition, long newPosition, int flags);
1472 // /// Scroll into view. This takes a _caret_ position.
1473 // virtual bool ScrollIntoView(long position, int keyCode);
1475 // /// The caret position is the character position just before the caret.
1476 // /// A value of -1 means the caret is at the start of the buffer.
1477 // void SetCaretPosition(long position, bool showAtLineStart = false) ;
1478 // long GetCaretPosition() const;
1480 // /// Move caret one visual step forward: this may mean setting a flag
1481 // /// and keeping the same position if we're going from the end of one line
1482 // /// to the start of the next, which may be the exact same caret position.
1483 // void MoveCaretForward(long oldPosition) ;
1485 // /// Move caret one visual step forward: this may mean setting a flag
1486 // /// and keeping the same position if we're going from the end of one line
1487 // /// to the start of the next, which may be the exact same caret position.
1488 // void MoveCaretBack(long oldPosition) ;
1490 // /// Get the caret height and position for the given character position
1491 // bool GetCaretPositionForIndex(long position, wxRect& rect);
1493 // /// Gets the line for the visible caret position. If the caret is
1494 // /// shown at the very end of the line, it means the next character is actually
1495 // /// on the following line. So let's get the line we're expecting to find
1496 // /// if this is the case.
1497 // wxRichTextLine* GetVisibleLineForCaretPosition(long caretPosition) const;
1499 // /// Gets the command processor
1500 // wxCommandProcessor* GetCommandProcessor() const;
1502 // /// Delete content if there is a selection, e.g. when pressing a key.
1503 // /// Returns the new caret position in newPos, or leaves it if there
1504 // /// was no action.
1505 // bool DeleteSelectedContent(long* newPos= NULL);
1507 // /// Transform logical to physical
1508 // wxPoint GetPhysicalPoint(const wxPoint& ptLogical) const;
1510 // /// Transform physical to logical
1511 // wxPoint GetLogicalPoint(const wxPoint& ptPhysical) const;
1513 // /// Finds the caret position for the next word. Direction
1514 // /// is 1 (forward) or -1 (backwards).
1515 // virtual long FindNextWordPosition(int direction = 1) const;
1517 // /// Is the given position visible on the screen?
1518 // bool IsPositionVisible(long pos) const;
1520 // /// Returns the first visible position in the current view
1521 // long GetFirstVisiblePosition() const;
1525 //----------------------------------------------------------------------
1528 %constant wxEventType wxEVT_COMMAND_RICHTEXT_LEFT_CLICK;
1529 %constant wxEventType wxEVT_COMMAND_RICHTEXT_RIGHT_CLICK;
1530 %constant wxEventType wxEVT_COMMAND_RICHTEXT_MIDDLE_CLICK;
1531 %constant wxEventType wxEVT_COMMAND_RICHTEXT_LEFT_DCLICK;
1532 %constant wxEventType wxEVT_COMMAND_RICHTEXT_RETURN;
1533 %constant wxEventType wxEVT_COMMAND_RICHTEXT_STYLESHEET_CHANGING;
1534 %constant wxEventType wxEVT_COMMAND_RICHTEXT_STYLESHEET_CHANGED;
1535 %constant wxEventType wxEVT_COMMAND_RICHTEXT_STYLESHEET_REPLACING;
1536 %constant wxEventType wxEVT_COMMAND_RICHTEXT_STYLESHEET_REPLACED;
1537 %constant wxEventType wxEVT_COMMAND_RICHTEXT_CHARACTER;
1538 %constant wxEventType wxEVT_COMMAND_RICHTEXT_DELETE;
1541 EVT_RICHTEXT_LEFT_CLICK = wx.PyEventBinder(wxEVT_COMMAND_RICHTEXT_LEFT_CLICK, 1)
1542 EVT_RICHTEXT_RIGHT_CLICK = wx.PyEventBinder(wxEVT_COMMAND_RICHTEXT_RIGHT_CLICK, 1)
1543 EVT_RICHTEXT_MIDDLE_CLICK = wx.PyEventBinder(wxEVT_COMMAND_RICHTEXT_MIDDLE_CLICK, 1)
1544 EVT_RICHTEXT_LEFT_DCLICK = wx.PyEventBinder(wxEVT_COMMAND_RICHTEXT_LEFT_DCLICK, 1)
1545 EVT_RICHTEXT_RETURN = wx.PyEventBinder( wxEVT_COMMAND_RICHTEXT_RETURN, 1)
1546 EVT_RICHTEXT_STYLESHEET_CHANGING = wx.PyEventBinder( wxEVT_COMMAND_RICHTEXT_STYLESHEET_CHANGING, 1)
1547 EVT_RICHTEXT_STYLESHEET_CHANGED = wx.PyEventBinder( wxEVT_COMMAND_RICHTEXT_STYLESHEET_CHANGED, 1)
1548 EVT_RICHTEXT_STYLESHEET_REPLACING = wx.PyEventBinder( wxEVT_COMMAND_RICHTEXT_STYLESHEET_REPLACING, 1)
1549 EVT_RICHTEXT_STYLESHEET_REPLACED = wx.PyEventBinder( wxEVT_COMMAND_RICHTEXT_STYLESHEET_REPLACED, 1)
1550 EVT_RICHTEXT_CHARACTER = wx.PyEventBinder( wxEVT_COMMAND_RICHTEXT_CHARACTER, 1)
1551 EVT_RICHTEXT_DELETE = wx.PyEventBinder( wxEVT_COMMAND_RICHTEXT_DELETE, 1)
1555 class wxRichTextEvent : public wxNotifyEvent
1558 wxRichTextEvent(wxEventType commandType = wxEVT_NULL, int winid = 0);
1560 int GetPosition() const;
1561 void SetPosition(int n);
1563 int GetFlags() const;
1564 void SetFlags(int flags);
1566 %property(Flags, GetFlags, SetFlags, doc="See `GetFlags` and `SetFlags`");
1567 %property(Index, GetPosition, SetPosition, doc="See `GetPosition` and `SetPosition`");
1570 //----------------------------------------------------------------------
1573 wxRichTextModuleInit();
1576 //----------------------------------------------------------------------