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,
118 wxTEXT_ATTR_BULLET_SYMBOL,
120 wxTEXT_ATTR_BULLET_STYLE_NONE,
121 wxTEXT_ATTR_BULLET_STYLE_ARABIC,
122 wxTEXT_ATTR_BULLET_STYLE_LETTERS_UPPER,
123 wxTEXT_ATTR_BULLET_STYLE_LETTERS_LOWER,
124 wxTEXT_ATTR_BULLET_STYLE_ROMAN_UPPER,
125 wxTEXT_ATTR_BULLET_STYLE_ROMAN_LOWER,
126 wxTEXT_ATTR_BULLET_STYLE_SYMBOL,
127 wxTEXT_ATTR_BULLET_STYLE_BITMAP,
128 wxTEXT_ATTR_BULLET_STYLE_PARENTHESES,
129 wxTEXT_ATTR_BULLET_STYLE_PERIOD,
131 wxTEXT_ATTR_LINE_SPACING_NORMAL,
132 wxTEXT_ATTR_LINE_SPACING_HALF,
133 wxTEXT_ATTR_LINE_SPACING_TWICE,
137 enum wxTextAttrAlignment
139 wxTEXT_ALIGNMENT_DEFAULT,
140 wxTEXT_ALIGNMENT_LEFT,
141 wxTEXT_ALIGNMENT_CENTRE,
142 wxTEXT_ALIGNMENT_CENTER = wxTEXT_ALIGNMENT_CENTRE,
143 wxTEXT_ALIGNMENT_RIGHT,
144 wxTEXT_ALIGNMENT_JUSTIFIED
147 //----------------------------------------------------------------------
149 %typemap(in) wxRichTextRange& (wxRichTextRange temp) {
151 if ( ! wxRichTextRange_helper($input, &$1)) SWIG_fail;
153 %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxRichTextRange& {
154 $1 = wxPySimple_typecheck($input, wxT("wxRichTextRange"), 2);
160 bool wxRichTextRange_helper(PyObject* source, wxRichTextRange** obj)
162 if (source == Py_None) {
163 **obj = wxRICHTEXT_NONE;
166 return wxPyTwoIntItem_helper(source, obj, wxT("wxRichTextRange"));
172 DocStr(wxRichTextRange,
173 "RichTextRange is a data structure that represents a range of text
174 within a `RichTextCtrl`. It simply contains integer ``start`` and
175 ``end`` properties and a few operations useful for dealing with
176 ranges. In most places in wxPython where a RichTextRange is expected a
177 2-tuple containing (start, end) can be used instead.", "");
179 class wxRichTextRange
183 wxRichTextRange(long start=0, long end=0),
184 "Creates a new range object.", "");
190 DocStr(__eq__, "Test for equality of RichTextRange objects.", "");
191 bool __eq__(PyObject* other) {
192 wxRichTextRange temp, *obj = &temp;
193 if ( other == Py_None ) return false;
194 if ( ! wxRichTextRange_helper(other, &obj) ) {
198 return self->operator==(*obj);
204 wxRichTextRange , operator -(const wxRichTextRange& range) const,
208 wxRichTextRange , operator +(const wxRichTextRange& range) const,
213 void , SetRange(long start, long end),
218 void , SetStart(long start),
222 long , GetStart() const,
225 %pythoncode { start = property(GetStart, SetStart) }
228 void , SetEnd(long end),
232 long , GetEnd() const,
235 %pythoncode { end = property(GetEnd, SetEnd) }
239 bool , IsOutside(const wxRichTextRange& range) const,
240 "Returns true if this range is completely outside 'range'", "");
244 bool , IsWithin(const wxRichTextRange& range) const,
245 "Returns true if this range is completely within 'range'", "");
249 bool , Contains(long pos) const,
250 "Returns true if the given position is within this range. Allow for the
251 possibility of an empty range - assume the position is within this
256 bool , LimitTo(const wxRichTextRange& range) ,
257 "Limit this range to be within 'range'", "");
261 long , GetLength() const,
262 "Gets the length of the range", "");
267 "Swaps the start and end", "");
272 "Get() -> (start,end)",
273 "Returns the start and end properties as a tuple.", "");
275 wxPyBlock_t blocked = wxPyBeginBlockThreads();
276 PyObject* tup = PyTuple_New(2);
277 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->GetStart()));
278 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->GetEnd()));
279 wxPyEndBlockThreads(blocked);
284 def __str__(self): return str(self.Get())
285 def __repr__(self): return 'RichTextRange'+str(self.Get())
286 def __len__(self): return len(self.Get())
287 def __getitem__(self, index): return self.Get()[index]
288 def __setitem__(self, index, val):
289 if index == 0: self.start = val
290 elif index == 1: self.end = val
291 else: raise IndexError
292 def __nonzero__(self): return self.Get() != (0,0)
293 __safe_for_unpickling__ = True
294 def __reduce__(self): return (RichTextRange, self.Get())
297 %property(End, GetEnd, SetEnd, doc="See `GetEnd` and `SetEnd`");
298 %property(Length, GetLength, doc="See `GetLength`");
299 %property(Start, GetStart, SetStart, doc="See `GetStart` and `SetStart`");
305 wxRichTextRange wxPy_RTR_ALL(wxRICHTEXT_ALL);
306 wxRichTextRange wxPy_RTR_NONE(wxRICHTEXT_NONE);
309 %rename(RICHTEXT_ALL) wxPy_RTR_ALL;
310 %rename(RICHTEXT_NONE) wxPy_RTR_NONE;
313 wxRichTextRange wxPy_RTR_ALL;
314 wxRichTextRange wxPy_RTR_NONE;
317 //----------------------------------------------------------------------
319 DocStr(wxRichTextAttr,
320 "The RichTextAttr class stored information about the various attributes
321 for a block of text, including font, colour, indents, alignments, and
328 wxRichTextAttr(const wxColour& colText = wxNullColour,
329 const wxColour& colBack = wxNullColour,
330 wxTextAttrAlignment alignment = wxTEXT_ALIGNMENT_DEFAULT);
334 // // Making a wxTextAttrEx object.
335 // operator wxTextAttrEx () const ;
337 // // Copy to a wxTextAttr
338 // void CopyTo(wxTextAttrEx& attr) const;
342 // Create font from font attributes.
344 wxFont , CreateFont() const,
348 // Get attributes from font.
349 bool GetFontAttributes(const wxFont& font);
353 return self.CreateFont()
354 def SetFont(self, font):
355 return self.GetFontAttributes(font)
359 void SetTextColour(const wxColour& colText);
360 void SetBackgroundColour(const wxColour& colBack);
361 void SetAlignment(wxTextAttrAlignment alignment);
362 void SetTabs(const wxArrayInt& tabs);
363 void SetLeftIndent(int indent, int subIndent = 0);
364 void SetRightIndent(int indent);
366 void SetFontSize(int pointSize);
367 void SetFontStyle(int fontStyle);
368 void SetFontWeight(int fontWeight);
369 void SetFontFaceName(const wxString& faceName);
370 void SetFontUnderlined(bool underlined);
372 void SetFlags(long flags);
374 void SetCharacterStyleName(const wxString& name);
375 void SetParagraphStyleName(const wxString& name);
376 void SetParagraphSpacingAfter(int spacing);
377 void SetParagraphSpacingBefore(int spacing);
378 void SetLineSpacing(int spacing);
379 void SetBulletStyle(int style);
380 void SetBulletNumber(int n);
381 void SetBulletSymbol(wxChar symbol);
382 void SetBulletFont(const wxString& bulletFont);
384 const wxColour& GetTextColour() const;
385 const wxColour& GetBackgroundColour() const;
386 wxTextAttrAlignment GetAlignment() const;
387 const wxArrayInt& GetTabs() const;
388 long GetLeftIndent() const;
389 long GetLeftSubIndent() const;
390 long GetRightIndent() const;
391 long GetFlags() const;
393 int GetFontSize() const;
394 int GetFontStyle() const;
395 int GetFontWeight() const;
396 bool GetFontUnderlined() const;
397 const wxString& GetFontFaceName() const;
399 const wxString& GetCharacterStyleName() const;
400 const wxString& GetParagraphStyleName() const;
401 int GetParagraphSpacingAfter() const;
402 int GetParagraphSpacingBefore() const;
403 int GetLineSpacing() const;
404 int GetBulletStyle() const;
405 int GetBulletNumber() const;
406 wxChar GetBulletSymbol() const;
407 const wxString& GetBulletFont() const;
410 bool HasTextColour() const;
411 bool HasBackgroundColour() const;
412 bool HasAlignment() const;
413 bool HasTabs() const;
414 bool HasLeftIndent() const;
415 bool HasRightIndent() const;
416 bool HasWeight() const;
417 bool HasSize() const;
418 bool HasItalic() const;
419 bool HasUnderlined() const;
420 bool HasFaceName() const;
421 bool HasFont() const;
423 bool HasParagraphSpacingAfter() const;
424 bool HasParagraphSpacingBefore() const;
425 bool HasLineSpacing() const;
426 bool HasCharacterStyleName() const;
427 bool HasParagraphStyleName() const;
428 bool HasBulletStyle() const;
429 bool HasBulletNumber() const;
430 bool HasBulletSymbol() const;
432 bool HasFlag(long flag) const;
434 // Is this a character style?
435 bool IsCharacterStyle() const;
436 bool IsParagraphStyle() const;
438 // returns false if we have any attributes set, true otherwise
439 bool IsDefault() const;
442 // // return the attribute having the valid font and colours: it uses the
443 // // attributes set in attr and falls back first to attrDefault and then to
444 // // the text control font/colours for those attributes which are not set
445 // static wxRichTextAttr Combine(const wxRichTextAttr& attr,
446 // const wxRichTextAttr& attrDef,
447 // const wxTextCtrlBase *text);
450 %property(Alignment, GetAlignment, SetAlignment, doc="See `GetAlignment` and `SetAlignment`");
451 %property(BackgroundColour, GetBackgroundColour, SetBackgroundColour, doc="See `GetBackgroundColour` and `SetBackgroundColour`");
452 %property(BulletFont, GetBulletFont, SetBulletFont, doc="See `GetBulletFont` and `SetBulletFont`");
453 %property(BulletNumber, GetBulletNumber, SetBulletNumber, doc="See `GetBulletNumber` and `SetBulletNumber`");
454 %property(BulletStyle, GetBulletStyle, SetBulletStyle, doc="See `GetBulletStyle` and `SetBulletStyle`");
455 %property(BulletSymbol, GetBulletSymbol, SetBulletSymbol, doc="See `GetBulletSymbol` and `SetBulletSymbol`");
456 %property(CharacterStyleName, GetCharacterStyleName, SetCharacterStyleName, doc="See `GetCharacterStyleName` and `SetCharacterStyleName`");
457 %property(Flags, GetFlags, SetFlags, doc="See `GetFlags` and `SetFlags`");
458 %property(Font, GetFont, SetFont, doc="See `GetFont` and `SetFont`");
459 %property(FontAttributes, GetFontAttributes, doc="See `GetFontAttributes`");
460 %property(FontFaceName, GetFontFaceName, SetFontFaceName, doc="See `GetFontFaceName` and `SetFontFaceName`");
461 %property(FontSize, GetFontSize, SetFontSize, doc="See `GetFontSize` and `SetFontSize`");
462 %property(FontStyle, GetFontStyle, SetFontStyle, doc="See `GetFontStyle` and `SetFontStyle`");
463 %property(FontUnderlined, GetFontUnderlined, SetFontUnderlined, doc="See `GetFontUnderlined` and `SetFontUnderlined`");
464 %property(FontWeight, GetFontWeight, SetFontWeight, doc="See `GetFontWeight` and `SetFontWeight`");
465 %property(LeftIndent, GetLeftIndent, SetLeftIndent, doc="See `GetLeftIndent` and `SetLeftIndent`");
466 %property(LeftSubIndent, GetLeftSubIndent, doc="See `GetLeftSubIndent`");
467 %property(LineSpacing, GetLineSpacing, SetLineSpacing, doc="See `GetLineSpacing` and `SetLineSpacing`");
468 %property(ParagraphSpacingAfter, GetParagraphSpacingAfter, SetParagraphSpacingAfter, doc="See `GetParagraphSpacingAfter` and `SetParagraphSpacingAfter`");
469 %property(ParagraphSpacingBefore, GetParagraphSpacingBefore, SetParagraphSpacingBefore, doc="See `GetParagraphSpacingBefore` and `SetParagraphSpacingBefore`");
470 %property(ParagraphStyleName, GetParagraphStyleName, SetParagraphStyleName, doc="See `GetParagraphStyleName` and `SetParagraphStyleName`");
471 %property(RightIndent, GetRightIndent, SetRightIndent, doc="See `GetRightIndent` and `SetRightIndent`");
472 %property(Tabs, GetTabs, SetTabs, doc="See `GetTabs` and `SetTabs`");
473 %property(TextColour, GetTextColour, SetTextColour, doc="See `GetTextColour` and `SetTextColour`");
478 wxTEXT_ATTR_CHARACTER,
479 wxTEXT_ATTR_PARAGRAPH,
484 //----------------------------------------------------------------------
485 //----------------------------------------------------------------------
487 MustHaveApp(wxRichTextCtrl);
488 DocStr(wxRichTextCtrl,
491 class wxRichTextCtrl : public wxScrolledWindow
494 %pythonAppend wxRichTextCtrl "self._setOORInfo(self)"
495 %pythonAppend wxRichTextCtrl() ""
497 wxRichTextCtrl( wxWindow* parent,
499 const wxString& value = wxPyEmptyString,
500 const wxPoint& pos = wxDefaultPosition,
501 const wxSize& size = wxDefaultSize,
502 long style = wxRE_MULTILINE );
503 %RenameCtor(PreRichTextCtrl, wxRichTextCtrl());
506 bool Create( wxWindow* parent,
508 const wxString& value = wxPyEmptyString,
509 const wxPoint& pos = wxDefaultPosition,
510 const wxSize& size = wxDefaultSize,
511 long style = wxRE_MULTILINE );
515 virtual wxString , GetValue() const,
519 virtual void , SetValue(const wxString& value),
524 virtual wxString , GetRange(long from, long to) const,
529 virtual int , GetLineLength(long lineNo) const ,
533 virtual wxString , GetLineText(long lineNo) const ,
537 virtual int , GetNumberOfLines() const ,
542 virtual bool , IsModified() const ,
546 virtual bool , IsEditable() const ,
550 // more readable flag testing methods
552 bool , IsSingleLine() const,
556 bool , IsMultiLine() const,
561 virtual void , GetSelection(long* OUTPUT, long* OUTPUT) const,
562 "GetSelection() --> (start, end)",
563 "Returns the start and end positions of the current selection. If the
564 values are the same then there is no selection.", "");
568 virtual wxString , GetStringSelection() const,
573 wxString , GetFilename() const,
578 void , SetFilename(const wxString& filename),
583 void , SetDelayedLayoutThreshold(long threshold),
584 "Set the threshold in character positions for doing layout optimization
585 during sizing.", "");
589 long , GetDelayedLayoutThreshold() const,
590 "Get the threshold in character positions for doing layout optimization
591 during sizing.", "");
596 virtual void , Clear(),
600 virtual void , Replace(long from, long to, const wxString& value),
604 virtual void , Remove(long from, long to),
609 virtual bool , LoadFile(const wxString& file, int type = wxRICHTEXT_TYPE_ANY),
610 "Load the contents of the document from the given filename.", "");
613 virtual bool , SaveFile(const wxString& file = wxPyEmptyString,
614 int type = wxRICHTEXT_TYPE_ANY),
615 "Save the contents of the document to the given filename, or if the
616 empty string is passed then to the filename set with `SetFilename`.", "");
619 // sets/clears the dirty flag
621 virtual void , MarkDirty(),
622 "Sets the dirty flag, meaning that the contents of the control have
623 changed and need to be saved.", "");
626 virtual void , DiscardEdits(),
627 "Clears the dirty flag.
628 :see: `MarkDirty`", "");
632 virtual void , SetMaxLength(unsigned long len),
633 "Set the max number of characters which may be entered in a single line
638 virtual void , WriteText(const wxString& text),
639 "Insert text at the current position.", "");
642 virtual void , AppendText(const wxString& text),
643 "Append text to the end of the document.", "");
647 virtual bool , SetStyle(const wxRichTextRange& range, const wxRichTextAttr& style),
648 "Set the style for the text in ``range`` to ``style``", "");
651 virtual bool , SetStyleEx(const wxRichTextRange& range, const wxRichTextAttr& style,
652 int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO),
653 "Extended style setting operation with flags including:
654 RICHTEXT_SETSTYLE_WITH_UNDO, RICHTEXT_SETSTYLE_OPTIMIZE,
655 RICHTEXT_SETSTYLE_PARAGRAPHS_ONLY, RICHTEXT_SETSTYLE_CHARACTERS_ONLY", "");
660 virtual bool , GetStyle(long position, wxRichTextAttr& style),
661 "Retrieve the style used at the given position. Copies the style
662 values at ``position`` into the ``style`` parameter and returns ``True``
663 if successful. Returns ``False`` otherwise.", "");
666 virtual bool , GetUncombinedStyle(long position, wxRichTextAttr& style),
667 "Get the content (uncombined) attributes for this position. Copies the
668 style values at ``position`` into the ``style`` parameter and returns
669 ``True`` if successful. Returns ``False`` otherwise.", "");
673 virtual bool , SetDefaultStyle(const wxRichTextAttr& style),
674 "Set the style used by default for the rich text document.", "");
678 virtual const wxRichTextAttr , GetDefaultStyleEx() const,
679 "Retrieves a copy of the default style object.", "",
684 virtual long , XYToPosition(long x, long y) const,
685 "Translate a col,row coordinants into a document position.", "");
688 virtual void , PositionToXY(long pos, long *OUTPUT, long *OUTPUT) const,
689 "PositionToXY(self, long pos) --> (x, y)",
690 "Retrieves the col,row for the given position within the document", "");
694 virtual void , ShowPosition(long position),
695 "Ensure that the given position in the document is visible.", "");
699 virtual wxTextCtrlHitTestResult , HitTest(const wxPoint& pt, long *OUTPUT) const,
700 "HitTest(self, Point pt) --> (result, pos)",
701 "Returns the character position at the given point in pixels. Note
702 that ``pt`` should be given in device coordinates, and not be adjusted
703 for the client area origin nor for scrolling. The return value is a
704 tuple of the hit test result and the position.", "
706 Possible result values are a bitmask of these flags:
708 ========================= ====================================
709 RICHTEXT_HITTEST_NONE The point was not on this object.
710 RICHTEXT_HITTEST_BEFORE The point was before the position
711 returned from HitTest.
712 RICHTEXT_HITTEST_AFTER The point was after the position
713 returned from HitTest.
714 RICHTEXT_HITTEST_ON The point was on the position
715 returned from HitTest
716 ========================= ====================================
720 virtual wxTextCtrlHitTestResult , HitTest(const wxPoint& pt,
722 wxTextCoord *OUTPUT) const,
723 "HitTestRC(self, Point pt) --> (result, col, row)",
724 "Returns the column and row of the given point in pixels. Note that
725 ``pt`` should be given in device coordinates, and not be adjusted for
726 the client area origin nor for scrolling. The return value is a tuple
727 of the hit test result and the column and row values.", "
732 // Clipboard operations
734 virtual void , Copy(),
735 "Copies the selected text to the clipboard.", "");
738 virtual void , Cut(),
739 "Copies the selected text to the clipboard and removes the selection.", "");
742 virtual void , Paste(),
743 "Pastes text from the clipboard into the document at the current
744 insertion point.", "");
747 virtual void , DeleteSelection(),
748 "Remove the current selection.", "");
752 virtual bool , CanCopy() const,
753 "Returns ``True`` if the selection can be copied to the clipboard.", "");
756 virtual bool , CanCut() const,
757 "Returns ``True`` if the selection can be cut to the clipboard.", "");
760 virtual bool , CanPaste() const,
761 "Returns ``True`` if the current contents of the clipboard can be
762 pasted into the document.", "");
765 virtual bool , CanDeleteSelection() const,
766 "Returns ``True`` if the selection can be removed from the document.", "");
771 virtual void , Undo(),
772 "If the last operation can be undone, undoes the last operation.", "");
775 virtual void , Redo(),
776 "If the last operation can be redone, redoes the last operation.", "");
780 virtual bool , CanUndo() const,
781 "Returns ``True`` if the last operation can be undone.", "");
784 virtual bool , CanRedo() const,
785 "Returns ``True`` if the last operation can be redone.", "");
790 virtual void , SetInsertionPoint(long pos),
791 "Sets the insertion point at the given position.", "");
794 virtual void , SetInsertionPointEnd(),
795 "Moves the insertion point to the end of the document.", "");
798 virtual long , GetInsertionPoint() const,
799 "Returns the insertion point. This is defined as the zero based index
800 of the character position to the right of the insertion point.", "");
803 virtual long , GetLastPosition() const,
804 "Returns the zero based index of the last position in the document.", "");
808 virtual void , SetSelection(long from, long to),
809 "Selects the text starting at the first position up to (but not
810 including) the character at the last position. If both parameters are
811 equal to -1 then all text in the control is selected.", "");
814 virtual void , SelectAll(),
815 "Select all text in the document.", "");
818 virtual void , SetEditable(bool editable),
819 "Makes the document editable or read-only, overriding the RE_READONLY
823 // /// Call Freeze to prevent refresh
824 // virtual void Freeze();
826 // /// Call Thaw to refresh
827 // virtual void Thaw();
829 // /// Call Thaw to refresh
831 // virtual bool , IsFrozen() const,
836 virtual bool , HasSelection() const,
840 ///// Functionality specific to wxRichTextCtrl
842 /// Write an image at the current insertion point. Supply optional type to use
843 /// for internal and file storage of the raw data.
845 virtual bool , WriteImage(const wxImage& image, int bitmapType = wxBITMAP_TYPE_PNG),
849 /// Write a bitmap 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 wxBitmap& bitmap, int bitmapType = wxBITMAP_TYPE_PNG),
857 /// Load an image from file and write at the current insertion point.
859 virtual bool , WriteImage(const wxString& filename, int bitmapType),
864 /// Write an image block at the current insertion point.
866 virtual bool , WriteImage(const wxRichTextImageBlock& imageBlock),
871 /// Insert a newline (actually paragraph) at the current insertion point.
873 virtual bool , Newline(),
878 /// Set basic (overall) style
880 virtual void , SetBasicStyle(const wxTextAttrEx& style),
885 virtual void , SetBasicStyle(const wxRichTextAttr& style),
890 /// Get basic (overall) style
892 virtual const wxTextAttrEx& , GetBasicStyle() const,
896 /// Begin using a style
898 virtual bool , BeginStyle(const wxTextAttrEx& style),
904 virtual bool , EndStyle(),
910 virtual bool , EndAllStyles(),
926 /// Begin using italic
928 bool , BeginItalic(),
938 /// Begin using underline
940 bool , BeginUnderline(),
944 /// End using underline
946 bool , EndUnderline(),
950 /// Begin using point size
952 bool , BeginFontSize(int pointSize),
956 /// End using point size
958 bool , EndFontSize(),
962 /// Begin using this font
964 bool , BeginFont(const wxFont& font),
974 /// Begin using this colour
976 bool , BeginTextColour(const wxColour& colour),
980 /// End using a colour
982 bool , EndTextColour(),
986 /// Begin using alignment
988 bool , BeginAlignment(wxTextAttrAlignment alignment),
994 bool , EndAlignment(),
998 /// Begin left indent
1000 bool , BeginLeftIndent(int leftIndent, int leftSubIndent = 0),
1006 bool , EndLeftIndent(),
1010 /// Begin right indent
1012 bool , BeginRightIndent(int rightIndent),
1016 /// End right indent
1018 bool , EndRightIndent(),
1022 /// Begin paragraph spacing
1024 bool , BeginParagraphSpacing(int before, int after),
1028 /// End paragraph spacing
1030 bool , EndParagraphSpacing(),
1034 /// Begin line spacing
1036 bool , BeginLineSpacing(int lineSpacing),
1040 /// End line spacing
1042 bool , EndLineSpacing(),
1046 /// Begin numbered bullet
1048 bool , BeginNumberedBullet(int bulletNumber,
1051 int bulletStyle = wxTEXT_ATTR_BULLET_STYLE_ARABIC|wxTEXT_ATTR_BULLET_STYLE_PERIOD),
1055 /// End numbered bullet
1057 bool , EndNumberedBullet(),
1061 /// Begin symbol bullet
1063 bool , BeginSymbolBullet(char symbol,
1066 int bulletStyle = wxTEXT_ATTR_BULLET_STYLE_SYMBOL),
1070 /// End symbol bullet
1072 bool , EndSymbolBullet(),
1076 /// Begin named character style
1078 bool , BeginCharacterStyle(const wxString& characterStyle),
1082 /// End named character style
1084 bool , EndCharacterStyle(),
1088 /// Begin named paragraph style
1090 bool , BeginParagraphStyle(const wxString& paragraphStyle),
1094 /// End named character style
1096 bool , EndParagraphStyle(),
1100 /// Sets the default style to the style under the cursor
1102 bool , SetDefaultStyleToCursorStyle(),
1106 /// Clear the selection
1108 virtual void , SelectNone(),
1111 /// Select the word at the given character position
1113 virtual bool , SelectWord(long position),
1117 /// Get/set the selection range in character positions. -1, -1 means no selection.
1119 wxRichTextRange , GetSelectionRange() const,
1123 void , SetSelectionRange(const wxRichTextRange& range),
1126 /// Get/set the selection range in character positions. -1, -1 means no selection.
1127 /// The range is in internal format, i.e. a single character selection is denoted
1130 const wxRichTextRange& , GetInternalSelectionRange() const,
1134 void , SetInternalSelectionRange(const wxRichTextRange& range),
1139 /// Add a new paragraph of text to the end of the buffer
1141 virtual wxRichTextRange , AddParagraph(const wxString& text),
1147 virtual wxRichTextRange , AddImage(const wxImage& image),
1151 /// Layout the buffer: which we must do before certain operations, such as
1152 /// setting the caret position.
1154 virtual bool , LayoutContent(bool onlyVisibleRect = false),
1158 /// Move the caret to the given character position
1160 virtual bool , MoveCaret(long pos, bool showAtLineStart = false),
1166 virtual bool , MoveRight(int noPositions = 1, int flags = 0),
1172 virtual bool , MoveLeft(int noPositions = 1, int flags = 0),
1178 virtual bool , MoveUp(int noLines = 1, int flags = 0),
1184 virtual bool , MoveDown(int noLines = 1, int flags = 0),
1188 /// Move to the end of the line
1190 virtual bool , MoveToLineEnd(int flags = 0),
1194 /// Move to the start of the line
1196 virtual bool , MoveToLineStart(int flags = 0),
1200 /// Move to the end of the paragraph
1202 virtual bool , MoveToParagraphEnd(int flags = 0),
1206 /// Move to the start of the paragraph
1208 virtual bool , MoveToParagraphStart(int flags = 0),
1212 /// Move to the start of the buffer
1214 virtual bool , MoveHome(int flags = 0),
1218 /// Move to the end of the buffer
1220 virtual bool , MoveEnd(int flags = 0),
1226 virtual bool , PageUp(int noPages = 1, int flags = 0),
1230 /// Move n pages down
1232 virtual bool , PageDown(int noPages = 1, int flags = 0),
1236 /// Move n words left
1238 virtual bool , WordLeft(int noPages = 1, int flags = 0),
1242 /// Move n words right
1244 virtual bool , WordRight(int noPages = 1, int flags = 0),
1248 /// Returns the buffer associated with the control.
1249 // wxRichTextBuffer& GetBuffer();
1251 const wxRichTextBuffer& , GetBuffer() const,
1255 /// Start batching undo history for commands.
1257 virtual bool , BeginBatchUndo(const wxString& cmdName),
1261 /// End batching undo history for commands.
1263 virtual bool , EndBatchUndo(),
1267 /// Are we batching undo history for commands?
1269 virtual bool , BatchingUndo() const,
1273 /// Start suppressing undo history for commands.
1275 virtual bool , BeginSuppressUndo(),
1279 /// End suppressing undo history for commands.
1281 virtual bool , EndSuppressUndo(),
1285 /// Are we suppressing undo history for commands?
1287 virtual bool , SuppressingUndo() const,
1291 /// Test if this whole range has character attributes of the specified kind. If any
1292 /// of the attributes are different within the range, the test fails. You
1293 /// can use this to implement, for example, bold button updating. style must have
1294 /// flags indicating which attributes are of interest.
1297 virtual bool , HasCharacterAttributes(const wxRichTextRange& range,
1298 const wxTextAttrEx& style) const,
1303 virtual bool , HasCharacterAttributes(const wxRichTextRange& range,
1304 const wxRichTextAttr& style) const,
1309 /// Test if this whole range has paragraph attributes of the specified kind. If any
1310 /// of the attributes are different within the range, the test fails. You
1311 /// can use this to implement, for example, centering button updating. style must have
1312 /// flags indicating which attributes are of interest.
1315 virtual bool , HasParagraphAttributes(const wxRichTextRange& range,
1316 const wxTextAttrEx& style) const,
1321 virtual bool , HasParagraphAttributes(const wxRichTextRange& range,
1322 const wxRichTextAttr& style) const,
1327 /// Is all of the selection bold?
1329 virtual bool , IsSelectionBold(),
1333 /// Is all of the selection italics?
1335 virtual bool , IsSelectionItalics(),
1339 /// Is all of the selection underlined?
1341 virtual bool , IsSelectionUnderlined(),
1345 /// Is all of the selection aligned according to the specified flag?
1347 virtual bool , IsSelectionAligned(wxTextAttrAlignment alignment),
1351 /// Apply bold to the selection
1353 virtual bool , ApplyBoldToSelection(),
1357 /// Apply italic to the selection
1359 virtual bool , ApplyItalicToSelection(),
1363 /// Apply underline to the selection
1365 virtual bool , ApplyUnderlineToSelection(),
1369 /// Apply alignment to the selection
1371 virtual bool , ApplyAlignmentToSelection(wxTextAttrAlignment alignment),
1375 /// Set style sheet, if any.
1377 void , SetStyleSheet(wxRichTextStyleSheet* styleSheet),
1381 wxRichTextStyleSheet* , GetStyleSheet() const,
1384 /// Apply the style sheet to the buffer, for example if the styles have changed.
1386 bool , ApplyStyleSheet(wxRichTextStyleSheet* styleSheet = NULL),
1391 %property(Buffer, GetBuffer, doc="See `GetBuffer`");
1392 %property(DefaultStyle, GetDefaultStyle, SetDefaultStyle, doc="See `GetDefaultStyle` and `SetDefaultStyle`");
1393 %property(DelayedLayoutThreshold, GetDelayedLayoutThreshold, SetDelayedLayoutThreshold, doc="See `GetDelayedLayoutThreshold` and `SetDelayedLayoutThreshold`");
1394 %property(Filename, GetFilename, SetFilename, doc="See `GetFilename` and `SetFilename`");
1395 %property(InsertionPoint, GetInsertionPoint, SetInsertionPoint, doc="See `GetInsertionPoint` and `SetInsertionPoint`");
1396 %property(InternalSelectionRange, GetInternalSelectionRange, SetInternalSelectionRange, doc="See `GetInternalSelectionRange` and `SetInternalSelectionRange`");
1397 %property(LastPosition, GetLastPosition, doc="See `GetLastPosition`");
1398 %property(NumberOfLines, GetNumberOfLines, doc="See `GetNumberOfLines`");
1399 %property(Selection, GetSelection, SetSelection, doc="See `GetSelection` and `SetSelection`");
1400 %property(SelectionRange, GetSelectionRange, SetSelectionRange, doc="See `GetSelectionRange` and `SetSelectionRange`");
1401 %property(StringSelection, GetStringSelection, doc="See `GetStringSelection`");
1402 %property(StyleSheet, GetStyleSheet, SetStyleSheet, doc="See `GetStyleSheet` and `SetStyleSheet`");
1403 %property(Value, GetValue, SetValue, doc="See `GetValue` and `SetValue`");
1406 // TODO: Which of these should be exposed to Python?
1408 // /// Set font, and also default attributes
1409 // virtual bool SetFont(const wxFont& font);
1411 // /// Set up scrollbars, e.g. after a resize
1412 // virtual void SetupScrollbars(bool atTop = false);
1414 // /// Keyboard navigation
1415 // virtual bool KeyboardNavigate(int keyCode, int flags);
1417 // /// Paint the background
1418 // virtual void PaintBackground(wxDC& dc);
1420 // /// Recreate buffer bitmap if necessary
1421 // virtual bool RecreateBuffer(const wxSize& size = wxDefaultSize);
1423 // /// Set the selection
1424 // virtual void DoSetSelection(long from, long to, bool scrollCaret = true);
1427 // virtual void DoWriteText(const wxString& value, bool selectionOnly = true);
1429 // /// Send an update event
1430 // virtual bool SendUpdateEvent();
1432 // /// Init command event
1433 // void InitCommandEvent(wxCommandEvent& event) const;
1435 // /// do the window-specific processing after processing the update event
1436 // // (duplicated code from wxTextCtrlBase)
1437 // #if !wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE
1438 // virtual void DoUpdateWindowUI(wxUpdateUIEvent& event);
1441 // /// Should we inherit colours?
1442 // virtual bool ShouldInheritColours() const;
1444 // /// Position the caret
1445 // virtual void PositionCaret();
1447 // /// Extend the selection, returning true if the selection was
1448 // /// changed. Selections are in caret positions.
1449 // virtual bool ExtendSelection(long oldPosition, long newPosition, int flags);
1451 // /// Scroll into view. This takes a _caret_ position.
1452 // virtual bool ScrollIntoView(long position, int keyCode);
1454 // /// The caret position is the character position just before the caret.
1455 // /// A value of -1 means the caret is at the start of the buffer.
1456 // void SetCaretPosition(long position, bool showAtLineStart = false) ;
1457 // long GetCaretPosition() const;
1459 // /// Move caret one visual step forward: this may mean setting a flag
1460 // /// and keeping the same position if we're going from the end of one line
1461 // /// to the start of the next, which may be the exact same caret position.
1462 // void MoveCaretForward(long oldPosition) ;
1464 // /// Move caret one visual step forward: this may mean setting a flag
1465 // /// and keeping the same position if we're going from the end of one line
1466 // /// to the start of the next, which may be the exact same caret position.
1467 // void MoveCaretBack(long oldPosition) ;
1469 // /// Get the caret height and position for the given character position
1470 // bool GetCaretPositionForIndex(long position, wxRect& rect);
1472 // /// Gets the line for the visible caret position. If the caret is
1473 // /// shown at the very end of the line, it means the next character is actually
1474 // /// on the following line. So let's get the line we're expecting to find
1475 // /// if this is the case.
1476 // wxRichTextLine* GetVisibleLineForCaretPosition(long caretPosition) const;
1478 // /// Gets the command processor
1479 // wxCommandProcessor* GetCommandProcessor() const;
1481 // /// Delete content if there is a selection, e.g. when pressing a key.
1482 // /// Returns the new caret position in newPos, or leaves it if there
1483 // /// was no action.
1484 // bool DeleteSelectedContent(long* newPos= NULL);
1486 // /// Transform logical to physical
1487 // wxPoint GetPhysicalPoint(const wxPoint& ptLogical) const;
1489 // /// Transform physical to logical
1490 // wxPoint GetLogicalPoint(const wxPoint& ptPhysical) const;
1492 // /// Finds the caret position for the next word. Direction
1493 // /// is 1 (forward) or -1 (backwards).
1494 // virtual long FindNextWordPosition(int direction = 1) const;
1496 // /// Is the given position visible on the screen?
1497 // bool IsPositionVisible(long pos) const;
1499 // /// Returns the first visible position in the current view
1500 // long GetFirstVisiblePosition() const;
1504 //----------------------------------------------------------------------
1507 %constant wxEventType wxEVT_COMMAND_RICHTEXT_ITEM_SELECTED;
1508 %constant wxEventType wxEVT_COMMAND_RICHTEXT_ITEM_DESELECTED;
1509 %constant wxEventType wxEVT_COMMAND_RICHTEXT_LEFT_CLICK;
1510 %constant wxEventType wxEVT_COMMAND_RICHTEXT_RIGHT_CLICK;
1511 %constant wxEventType wxEVT_COMMAND_RICHTEXT_MIDDLE_CLICK;
1512 %constant wxEventType wxEVT_COMMAND_RICHTEXT_LEFT_DCLICK;
1513 %constant wxEventType wxEVT_COMMAND_RICHTEXT_RETURN;
1517 EVT_RICHTEXT_ITEM_SELECTED = wx.PyEventBinder(wxEVT_COMMAND_RICHTEXT_ITEM_SELECTED, 1)
1518 EVT_RICHTEXT_ITEM_DESELECTED = wx.PyEventBinder(wxEVT_COMMAND_RICHTEXT_ITEM_DESELECTED, 1)
1519 EVT_RICHTEXT_LEFT_CLICK = wx.PyEventBinder(wxEVT_COMMAND_RICHTEXT_LEFT_CLICK, 1)
1520 EVT_RICHTEXT_RIGHT_CLICK = wx.PyEventBinder(wxEVT_COMMAND_RICHTEXT_RIGHT_CLICK, 1)
1521 EVT_RICHTEXT_MIDDLE_CLICK = wx.PyEventBinder(wxEVT_COMMAND_RICHTEXT_MIDDLE_CLICK, 1)
1522 EVT_RICHTEXT_LEFT_DCLICK = wx.PyEventBinder(wxEVT_COMMAND_RICHTEXT_LEFT_DCLICK, 1)
1523 EVT_RICHTEXT_RETURN = wx.PyEventBinder( wxEVT_COMMAND_RICHTEXT_RETURN, 1)
1527 class wxRichTextEvent : public wxNotifyEvent
1530 wxRichTextEvent(wxEventType commandType = wxEVT_NULL, int winid = 0);
1532 int GetIndex() const;
1533 void SetIndex(int n);
1535 int GetFlags() const;
1536 void SetFlags(int flags);
1538 %property(Flags, GetFlags, SetFlags, doc="See `GetFlags` and `SetFlags`");
1539 %property(Index, GetIndex, SetIndex, doc="See `GetIndex` and `SetIndex`");
1542 //----------------------------------------------------------------------
1545 wxRichTextModuleInit();
1548 //----------------------------------------------------------------------