]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/richtext.i
reSWIGged
[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 // // return the attribute having the valid font and colours: it uses the
427 // // attributes set in attr and falls back first to attrDefault and then to
428 // // the text control font/colours for those attributes which are not set
429 // static wxRichTextAttr Combine(const wxRichTextAttr& attr,
430 // const wxRichTextAttr& attrDef,
431 // const wxTextCtrlBase *text);
432 };
433
434
435 enum {
436 wxTEXT_ATTR_CHARACTER,
437 wxTEXT_ATTR_PARAGRAPH,
438 wxTEXT_ATTR_ALL
439 };
440
441
442 //----------------------------------------------------------------------
443 //----------------------------------------------------------------------
444
445 MustHaveApp(wxRichTextCtrl);
446 DocStr(wxRichTextCtrl,
447 "", "");
448
449 class wxRichTextCtrl : public wxScrolledWindow
450 {
451 public:
452 %pythonAppend wxRichTextCtrl "self._setOORInfo(self)"
453 %pythonAppend wxRichTextCtrl() ""
454
455 wxRichTextCtrl( wxWindow* parent,
456 wxWindowID id = -1,
457 const wxPoint& pos = wxDefaultPosition,
458 const wxSize& size = wxDefaultSize,
459 long style = wxRE_MULTILINE );
460 %RenameCtor(PreRichTextCtrl, wxRichTextCtrl());
461
462
463 bool Create( wxWindow* parent,
464 wxWindowID id = -1,
465 const wxPoint& pos = wxDefaultPosition,
466 const wxSize& size = wxDefaultSize,
467 long style = wxRE_MULTILINE );
468
469
470 DocDeclStr(
471 virtual wxString , GetValue() const,
472 "", "");
473
474 DocDeclStr(
475 virtual void , SetValue(const wxString& value),
476 "", "");
477
478
479 DocDeclStr(
480 virtual wxString , GetRange(long from, long to) const,
481 "", "");
482
483
484 DocDeclStr(
485 virtual int , GetLineLength(long lineNo) const ,
486 "", "");
487
488 DocDeclStr(
489 virtual wxString , GetLineText(long lineNo) const ,
490 "", "");
491
492 DocDeclStr(
493 virtual int , GetNumberOfLines() const ,
494 "", "");
495
496
497 DocDeclStr(
498 virtual bool , IsModified() const ,
499 "", "");
500
501 DocDeclStr(
502 virtual bool , IsEditable() const ,
503 "", "");
504
505
506 // more readable flag testing methods
507 DocDeclStr(
508 bool , IsSingleLine() const,
509 "", "");
510
511 DocDeclStr(
512 bool , IsMultiLine() const,
513 "", "");
514
515
516 DocDeclAStr(
517 virtual void , GetSelection(long* OUTPUT, long* OUTPUT) const,
518 "GetSelection() --> (start, end)",
519 "Returns the start and end positions of the current selection. If the
520 values are the same then there is no selection.", "");
521
522
523 DocDeclStr(
524 virtual wxString , GetStringSelection() const,
525 "", "");
526
527
528 DocDeclStr(
529 wxString , GetFilename() const,
530 "", "");
531
532
533 DocDeclStr(
534 void , SetFilename(const wxString& filename),
535 "", "");
536
537
538 DocDeclStr(
539 void , SetDelayedLayoutThreshold(long threshold),
540 "Set the threshold in character positions for doing layout optimization
541 during sizing.", "");
542
543
544 DocDeclStr(
545 long , GetDelayedLayoutThreshold() const,
546 "Get the threshold in character positions for doing layout optimization
547 during sizing.", "");
548
549
550
551 DocDeclStr(
552 virtual void , Clear(),
553 "", "");
554
555 DocDeclStr(
556 virtual void , Replace(long from, long to, const wxString& value),
557 "", "");
558
559 DocDeclStr(
560 virtual void , Remove(long from, long to),
561 "", "");
562
563
564 DocDeclStr(
565 virtual bool , LoadFile(const wxString& file, int type = wxRICHTEXT_TYPE_ANY),
566 "Load the contents of the document from the given filename.", "");
567
568 DocDeclStr(
569 virtual bool , SaveFile(const wxString& file = wxPyEmptyString,
570 int type = wxRICHTEXT_TYPE_ANY),
571 "Save the contents of the document to the given filename, or if the
572 empty string is passed then to the filename set with `SetFileName`.", "");
573
574
575 // sets/clears the dirty flag
576 DocDeclStr(
577 virtual void , MarkDirty(),
578 "Sets the dirty flag, meaning that the contents of the control have
579 changed and need to be saved.", "");
580
581 DocDeclStr(
582 virtual void , DiscardEdits(),
583 "Clears the dirty flag.
584 :see: `MarkDirty`", "");
585
586
587 DocDeclStr(
588 virtual void , SetMaxLength(unsigned long len),
589 "Set the max number of characters which may be entered in a single line
590 text control.", "");
591
592
593 DocDeclStr(
594 virtual void , WriteText(const wxString& text),
595 "Insert text at the current position.", "");
596
597 DocDeclStr(
598 virtual void , AppendText(const wxString& text),
599 "Append text to the end of the document.", "");
600
601
602 DocDeclStr(
603 virtual bool , SetStyle(const wxRichTextRange& range, const wxRichTextAttr& style),
604 "Set the style for the text in ``range`` to ``style``", "");
605
606 DocDeclStr(
607 virtual bool , GetStyle(long position, wxRichTextAttr& style) const,
608 "Retrieve the style used at the given position. Copies the style
609 values at ``position`` into the ``style`` parameter returns ``True``
610 if successful. Returns ``False`` otherwise.", "");
611
612
613 DocDeclStr(
614 virtual bool , SetDefaultStyle(const wxRichTextAttr& style),
615 "Set the style used by default for the rich text document.", "");
616
617
618 DocDeclStrName(
619 virtual const wxRichTextAttr , GetDefaultStyleEx() const,
620 "Retrieves a copy of the default style object.", "",
621 GetDefaultStyle);
622
623
624 DocDeclStr(
625 virtual long , XYToPosition(long x, long y) const,
626 "Translate a col,row coordinants into a document position.", "");
627
628 DocDeclAStr(
629 virtual void , PositionToXY(long pos, long *OUTPUT, long *OUTPUT) const,
630 "PositionToXY(self, long pos) --> (x, y)",
631 "Retrieves the col,row for the given position within the document", "");
632
633
634 DocDeclStr(
635 virtual void , ShowPosition(long position),
636 "Ensure that the given position in the document is visible.", "");
637
638
639 DocDeclAStr(
640 virtual wxTextCtrlHitTestResult , HitTest(const wxPoint& pt, long *OUTPUT) const,
641 "HitTest(self, Point pt) --> (result, pos)",
642 "Returns the character position at the given point in pixels. Note
643 that ``pt`` should be given in device coordinates, and not be adjusted
644 for the client area origin nor for scrolling. The return value is a
645 tuple of the hit test result and the position.", "
646
647 Possible result values are a bitmask of these flags:
648
649 ========================= ====================================
650 RICHTEXT_HITTEST_NONE The point was not on this object.
651 RICHTEXT_HITTEST_BEFORE The point was before the position
652 returned from HitTest.
653 RICHTEXT_HITTEST_AFTER The point was after the position
654 returned from HitTest.
655 RICHTEXT_HITTEST_ON The point was on the position
656 returned from HitTest
657 ========================= ====================================
658 ");
659
660 DocDeclAStrName(
661 virtual wxTextCtrlHitTestResult , HitTest(const wxPoint& pt,
662 wxTextCoord *OUTPUT,
663 wxTextCoord *OUTPUT) const,
664 "HitTestRC(self, Point pt) --> (result, col, row)",
665 "Returns the column and row of the given point in pixels. Note that
666 ``pt`` should be given in device coordinates, and not be adjusted for
667 the client area origin nor for scrolling. The return value is a tuple
668 of the hit test result and the column and row values.", "
669 :see: `HitTest`",
670 HitTestXY);
671
672
673 // Clipboard operations
674 DocDeclStr(
675 virtual void , Copy(),
676 "Copies the selected text to the clipboard.", "");
677
678 DocDeclStr(
679 virtual void , Cut(),
680 "Copies the selected text to the clipboard and removes the selection.", "");
681
682 DocDeclStr(
683 virtual void , Paste(),
684 "Pastes text from the clipboard into the document at the current
685 insertion point.", "");
686
687 DocDeclStr(
688 virtual void , DeleteSelection(),
689 "Remove the current selection.", "");
690
691
692 DocDeclStr(
693 virtual bool , CanCopy() const,
694 "Returns ``True`` if the selection can be copied to the clipboard.", "");
695
696 DocDeclStr(
697 virtual bool , CanCut() const,
698 "Returns ``True`` if the selection can be cut to the clipboard.", "");
699
700 DocDeclStr(
701 virtual bool , CanPaste() const,
702 "Returns ``True`` if the current contents of the clipboard can be
703 pasted into the document.", "");
704
705 DocDeclStr(
706 virtual bool , CanDeleteSelection() const,
707 "Returns ``True`` if the selection can be removed from the document.", "");
708
709
710 // Undo/redo
711 DocDeclStr(
712 virtual void , Undo(),
713 "If the last operation can be undone, undoes the last operation.", "");
714
715 DocDeclStr(
716 virtual void , Redo(),
717 "If the last operation can be redone, redoes the last operation.", "");
718
719
720 DocDeclStr(
721 virtual bool , CanUndo() const,
722 "Returns ``True`` if the last operation can be undone.", "");
723
724 DocDeclStr(
725 virtual bool , CanRedo() const,
726 "Returns ``True`` if the last operation can be redone.", "");
727
728
729 // Insertion point
730 DocDeclStr(
731 virtual void , SetInsertionPoint(long pos),
732 "Sets the insertion point at the given position.", "");
733
734 DocDeclStr(
735 virtual void , SetInsertionPointEnd(),
736 "Moves the insertion point to the end of the document.", "");
737
738 DocDeclStr(
739 virtual long , GetInsertionPoint() const,
740 "Returns the insertion point. This is defined as the zero based index
741 of the character position to the right of the insertion point.", "");
742
743 DocDeclStr(
744 virtual long , GetLastPosition() const,
745 "Returns the zero based index of the last position in the document.", "");
746
747
748 DocDeclStr(
749 virtual void , SetSelection(long from, long to),
750 "Selects the text starting at the first position up to (but not
751 including) the character at the last position. If both parameters are
752 equal to -1 then all text in the control is selected.", "");
753
754 DocDeclStr(
755 virtual void , SelectAll(),
756 "Select all text in the document.", "");
757
758 DocDeclStr(
759 virtual void , SetEditable(bool editable),
760 "Makes the document editable or read-only, overriding the RE_READONLY
761 flag.", "");
762
763
764 // /// Call Freeze to prevent refresh
765 // virtual void Freeze();
766
767 // /// Call Thaw to refresh
768 // virtual void Thaw();
769
770 // /// Call Thaw to refresh
771 // DocDeclStr(
772 // virtual bool , IsFrozen() const,
773 // "", "");
774
775
776 DocDeclStr(
777 virtual bool , HasSelection() const,
778 "", "");
779
780
781 ///// Functionality specific to wxRichTextCtrl
782
783 /// Write an image at the current insertion point. Supply optional type to use
784 /// for internal and file storage of the raw data.
785 DocDeclStr(
786 virtual bool , WriteImage(const wxImage& image, int bitmapType = wxBITMAP_TYPE_PNG),
787 "", "");
788
789
790 /// Write a bitmap at the current insertion point. Supply optional type to use
791 /// for internal and file storage of the raw data.
792 DocDeclStrName(
793 virtual bool , WriteImage(const wxBitmap& bitmap, int bitmapType = wxBITMAP_TYPE_PNG),
794 "", "",
795 WriteBitmap);
796
797
798 /// Load an image from file and write at the current insertion point.
799 DocDeclStrName(
800 virtual bool , WriteImage(const wxString& filename, int bitmapType),
801 "", "",
802 WriteImageFile);
803
804
805 /// Write an image block at the current insertion point.
806 DocDeclStrName(
807 virtual bool , WriteImage(const wxRichTextImageBlock& imageBlock),
808 "", "",
809 WriteImageBlock);
810
811
812 /// Insert a newline (actually paragraph) at the current insertion point.
813 DocDeclStr(
814 virtual bool , Newline(),
815 "", "");
816
817
818 #if USE_TEXTATTREX
819 /// Set basic (overall) style
820 DocDeclStr(
821 virtual void , SetBasicStyle(const wxTextAttrEx& style),
822 "", "");
823 #endif
824
825 DocDeclStr(
826 virtual void , SetBasicStyle(const wxRichTextAttr& style),
827 "", "");
828
829
830 #if USE_TEXTATTREX
831 /// Get basic (overall) style
832 DocDeclStr(
833 virtual const wxTextAttrEx& , GetBasicStyle() const,
834 "", "");
835
836
837 /// Begin using a style
838 DocDeclStr(
839 virtual bool , BeginStyle(const wxTextAttrEx& style),
840 "", "");
841 #endif
842
843 /// End the style
844 DocDeclStr(
845 virtual bool , EndStyle(),
846 "", "");
847
848
849 /// End all styles
850 DocDeclStr(
851 virtual bool , EndAllStyles(),
852 "", "");
853
854
855 /// Begin using bold
856 DocDeclStr(
857 bool , BeginBold(),
858 "", "");
859
860
861 /// End using bold
862 DocDeclStr(
863 bool , EndBold(),
864 "", "");
865
866
867 /// Begin using italic
868 DocDeclStr(
869 bool , BeginItalic(),
870 "", "");
871
872
873 /// End using italic
874 DocDeclStr(
875 bool , EndItalic(),
876 "", "");
877
878
879 /// Begin using underline
880 DocDeclStr(
881 bool , BeginUnderline(),
882 "", "");
883
884
885 /// End using underline
886 DocDeclStr(
887 bool , EndUnderline(),
888 "", "");
889
890
891 /// Begin using point size
892 DocDeclStr(
893 bool , BeginFontSize(int pointSize),
894 "", "");
895
896
897 /// End using point size
898 DocDeclStr(
899 bool , EndFontSize(),
900 "", "");
901
902
903 /// Begin using this font
904 DocDeclStr(
905 bool , BeginFont(const wxFont& font),
906 "", "");
907
908
909 /// End using a font
910 DocDeclStr(
911 bool , EndFont(),
912 "", "");
913
914
915 /// Begin using this colour
916 DocDeclStr(
917 bool , BeginTextColour(const wxColour& colour),
918 "", "");
919
920
921 /// End using a colour
922 DocDeclStr(
923 bool , EndTextColour(),
924 "", "");
925
926
927 /// Begin using alignment
928 DocDeclStr(
929 bool , BeginAlignment(wxTextAttrAlignment alignment),
930 "", "");
931
932
933 /// End alignment
934 DocDeclStr(
935 bool , EndAlignment(),
936 "", "");
937
938
939 /// Begin left indent
940 DocDeclStr(
941 bool , BeginLeftIndent(int leftIndent, int leftSubIndent = 0),
942 "", "");
943
944
945 /// End left indent
946 DocDeclStr(
947 bool , EndLeftIndent(),
948 "", "");
949
950
951 /// Begin right indent
952 DocDeclStr(
953 bool , BeginRightIndent(int rightIndent),
954 "", "");
955
956
957 /// End right indent
958 DocDeclStr(
959 bool , EndRightIndent(),
960 "", "");
961
962
963 /// Begin paragraph spacing
964 DocDeclStr(
965 bool , BeginParagraphSpacing(int before, int after),
966 "", "");
967
968
969 /// End paragraph spacing
970 DocDeclStr(
971 bool , EndParagraphSpacing(),
972 "", "");
973
974
975 /// Begin line spacing
976 DocDeclStr(
977 bool , BeginLineSpacing(int lineSpacing),
978 "", "");
979
980
981 /// End line spacing
982 DocDeclStr(
983 bool , EndLineSpacing(),
984 "", "");
985
986
987 /// Begin numbered bullet
988 DocDeclStr(
989 bool , BeginNumberedBullet(int bulletNumber,
990 int leftIndent,
991 int leftSubIndent,
992 int bulletStyle = wxTEXT_ATTR_BULLET_STYLE_ARABIC|wxTEXT_ATTR_BULLET_STYLE_PERIOD),
993 "", "");
994
995
996 /// End numbered bullet
997 DocDeclStr(
998 bool , EndNumberedBullet(),
999 "", "");
1000
1001
1002 /// Begin symbol bullet
1003 DocDeclStr(
1004 bool , BeginSymbolBullet(char symbol,
1005 int leftIndent,
1006 int leftSubIndent,
1007 int bulletStyle = wxTEXT_ATTR_BULLET_STYLE_SYMBOL),
1008 "", "");
1009
1010
1011 /// End symbol bullet
1012 DocDeclStr(
1013 bool , EndSymbolBullet(),
1014 "", "");
1015
1016
1017 /// Begin named character style
1018 DocDeclStr(
1019 bool , BeginCharacterStyle(const wxString& characterStyle),
1020 "", "");
1021
1022
1023 /// End named character style
1024 DocDeclStr(
1025 bool , EndCharacterStyle(),
1026 "", "");
1027
1028
1029 /// Begin named paragraph style
1030 DocDeclStr(
1031 bool , BeginParagraphStyle(const wxString& paragraphStyle),
1032 "", "");
1033
1034
1035 /// End named character style
1036 DocDeclStr(
1037 bool , EndParagraphStyle(),
1038 "", "");
1039
1040
1041 /// Sets the default style to the style under the cursor
1042 DocDeclStr(
1043 bool , SetDefaultStyleToCursorStyle(),
1044 "", "");
1045
1046
1047 /// Clear the selection
1048 DocDeclStr(
1049 virtual void , SelectNone(),
1050 "", "");
1051
1052
1053 /// Get/set the selection range in character positions. -1, -1 means no selection.
1054 DocDeclStr(
1055 const wxRichTextRange& , GetSelectionRange() const,
1056 "", "");
1057
1058 DocDeclStr(
1059 void , SetSelectionRange(const wxRichTextRange& range),
1060 "", "");
1061
1062
1063 /// Add a new paragraph of text to the end of the buffer
1064 DocDeclStr(
1065 virtual wxRichTextRange , AddParagraph(const wxString& text),
1066 "", "");
1067
1068
1069 /// Add an image
1070 DocDeclStr(
1071 virtual wxRichTextRange , AddImage(const wxImage& image),
1072 "", "");
1073
1074
1075 /// Layout the buffer: which we must do before certain operations, such as
1076 /// setting the caret position.
1077 DocDeclStr(
1078 virtual bool , LayoutContent(bool onlyVisibleRect = false),
1079 "", "");
1080
1081
1082 /// Move the caret to the given character position
1083 DocDeclStr(
1084 virtual bool , MoveCaret(long pos, bool showAtLineStart = false),
1085 "", "");
1086
1087
1088 /// Move right
1089 DocDeclStr(
1090 virtual bool , MoveRight(int noPositions = 1, int flags = 0),
1091 "", "");
1092
1093
1094 /// Move left
1095 DocDeclStr(
1096 virtual bool , MoveLeft(int noPositions = 1, int flags = 0),
1097 "", "");
1098
1099
1100 /// Move up
1101 DocDeclStr(
1102 virtual bool , MoveUp(int noLines = 1, int flags = 0),
1103 "", "");
1104
1105
1106 /// Move up
1107 DocDeclStr(
1108 virtual bool , MoveDown(int noLines = 1, int flags = 0),
1109 "", "");
1110
1111
1112 /// Move to the end of the line
1113 DocDeclStr(
1114 virtual bool , MoveToLineEnd(int flags = 0),
1115 "", "");
1116
1117
1118 /// Move to the start of the line
1119 DocDeclStr(
1120 virtual bool , MoveToLineStart(int flags = 0),
1121 "", "");
1122
1123
1124 /// Move to the end of the paragraph
1125 DocDeclStr(
1126 virtual bool , MoveToParagraphEnd(int flags = 0),
1127 "", "");
1128
1129
1130 /// Move to the start of the paragraph
1131 DocDeclStr(
1132 virtual bool , MoveToParagraphStart(int flags = 0),
1133 "", "");
1134
1135
1136 /// Move to the start of the buffer
1137 DocDeclStr(
1138 virtual bool , MoveHome(int flags = 0),
1139 "", "");
1140
1141
1142 /// Move to the end of the buffer
1143 DocDeclStr(
1144 virtual bool , MoveEnd(int flags = 0),
1145 "", "");
1146
1147
1148 /// Move n pages up
1149 DocDeclStr(
1150 virtual bool , PageUp(int noPages = 1, int flags = 0),
1151 "", "");
1152
1153
1154 /// Move n pages down
1155 DocDeclStr(
1156 virtual bool , PageDown(int noPages = 1, int flags = 0),
1157 "", "");
1158
1159
1160 /// Move n words left
1161 DocDeclStr(
1162 virtual bool , WordLeft(int noPages = 1, int flags = 0),
1163 "", "");
1164
1165
1166 /// Move n words right
1167 DocDeclStr(
1168 virtual bool , WordRight(int noPages = 1, int flags = 0),
1169 "", "");
1170
1171
1172 /// Returns the buffer associated with the control.
1173 // wxRichTextBuffer& GetBuffer();
1174 DocDeclStr(
1175 const wxRichTextBuffer& , GetBuffer() const,
1176 "", "");
1177
1178
1179 /// Start batching undo history for commands.
1180 DocDeclStr(
1181 virtual bool , BeginBatchUndo(const wxString& cmdName),
1182 "", "");
1183
1184
1185 /// End batching undo history for commands.
1186 DocDeclStr(
1187 virtual bool , EndBatchUndo(),
1188 "", "");
1189
1190
1191 /// Are we batching undo history for commands?
1192 DocDeclStr(
1193 virtual bool , BatchingUndo() const,
1194 "", "");
1195
1196
1197 /// Start suppressing undo history for commands.
1198 DocDeclStr(
1199 virtual bool , BeginSuppressUndo(),
1200 "", "");
1201
1202
1203 /// End suppressing undo history for commands.
1204 DocDeclStr(
1205 virtual bool , EndSuppressUndo(),
1206 "", "");
1207
1208
1209 /// Are we suppressing undo history for commands?
1210 DocDeclStr(
1211 virtual bool , SuppressingUndo() const,
1212 "", "");
1213
1214
1215 /// Test if this whole range has character attributes of the specified kind. If any
1216 /// of the attributes are different within the range, the test fails. You
1217 /// can use this to implement, for example, bold button updating. style must have
1218 /// flags indicating which attributes are of interest.
1219 #if USE_TEXTATTREX
1220 DocDeclStr(
1221 virtual bool , HasCharacterAttributes(const wxRichTextRange& range,
1222 const wxTextAttrEx& style) const,
1223 "", "");
1224 #endif
1225
1226 DocDeclStr(
1227 virtual bool , HasCharacterAttributes(const wxRichTextRange& range,
1228 const wxRichTextAttr& style) const,
1229 "", "");
1230
1231
1232
1233 /// Test if this whole range has paragraph attributes of the specified kind. If any
1234 /// of the attributes are different within the range, the test fails. You
1235 /// can use this to implement, for example, centering button updating. style must have
1236 /// flags indicating which attributes are of interest.
1237 #if USE_TEXTATTREX
1238 DocDeclStr(
1239 virtual bool , HasParagraphAttributes(const wxRichTextRange& range,
1240 const wxTextAttrEx& style) const,
1241 "", "");
1242 #endif
1243
1244 DocDeclStr(
1245 virtual bool , HasParagraphAttributes(const wxRichTextRange& range,
1246 const wxRichTextAttr& style) const,
1247 "", "");
1248
1249
1250
1251 /// Is all of the selection bold?
1252 DocDeclStr(
1253 virtual bool , IsSelectionBold() const,
1254 "", "");
1255
1256
1257 /// Is all of the selection italics?
1258 DocDeclStr(
1259 virtual bool , IsSelectionItalics() const,
1260 "", "");
1261
1262
1263 /// Is all of the selection underlined?
1264 DocDeclStr(
1265 virtual bool , IsSelectionUnderlined() const,
1266 "", "");
1267
1268
1269 /// Is all of the selection aligned according to the specified flag?
1270 DocDeclStr(
1271 virtual bool , IsSelectionAligned(wxTextAttrAlignment alignment) const,
1272 "", "");
1273
1274
1275 /// Apply bold to the selection
1276 DocDeclStr(
1277 virtual bool , ApplyBoldToSelection(),
1278 "", "");
1279
1280
1281 /// Apply italic to the selection
1282 DocDeclStr(
1283 virtual bool , ApplyItalicToSelection(),
1284 "", "");
1285
1286
1287 /// Apply underline to the selection
1288 DocDeclStr(
1289 virtual bool , ApplyUnderlineToSelection(),
1290 "", "");
1291
1292
1293 /// Apply alignment to the selection
1294 DocDeclStr(
1295 virtual bool , ApplyAlignmentToSelection(wxTextAttrAlignment alignment),
1296 "", "");
1297
1298
1299 /// Set style sheet, if any.
1300 DocDeclStr(
1301 void , SetStyleSheet(wxRichTextStyleSheet* styleSheet),
1302 "", "");
1303
1304 DocDeclStr(
1305 wxRichTextStyleSheet* , GetStyleSheet() const,
1306 "", "");
1307
1308
1309
1310 // Implementation
1311 // TODO: Which of these should be exposed to Python?
1312
1313 // /// Set font, and also default attributes
1314 // virtual bool SetFont(const wxFont& font);
1315
1316 // /// Set up scrollbars, e.g. after a resize
1317 // virtual void SetupScrollbars(bool atTop = false);
1318
1319 // /// Keyboard navigation
1320 // virtual bool KeyboardNavigate(int keyCode, int flags);
1321
1322 // /// Paint the background
1323 // virtual void PaintBackground(wxDC& dc);
1324
1325 // /// Recreate buffer bitmap if necessary
1326 // virtual bool RecreateBuffer(const wxSize& size = wxDefaultSize);
1327
1328 // /// Set the selection
1329 // virtual void DoSetSelection(long from, long to, bool scrollCaret = true);
1330
1331 // /// Write text
1332 // virtual void DoWriteText(const wxString& value, bool selectionOnly = true);
1333
1334 // /// Send an update event
1335 // virtual bool SendUpdateEvent();
1336
1337 // /// Init command event
1338 // void InitCommandEvent(wxCommandEvent& event) const;
1339
1340 // /// do the window-specific processing after processing the update event
1341 // // (duplicated code from wxTextCtrlBase)
1342 // #if !wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE
1343 // virtual void DoUpdateWindowUI(wxUpdateUIEvent& event);
1344 // #endif
1345
1346 // /// Should we inherit colours?
1347 // virtual bool ShouldInheritColours() const;
1348
1349 // /// Position the caret
1350 // virtual void PositionCaret();
1351
1352 // /// Extend the selection, returning true if the selection was
1353 // /// changed. Selections are in caret positions.
1354 // virtual bool ExtendSelection(long oldPosition, long newPosition, int flags);
1355
1356 // /// Scroll into view. This takes a _caret_ position.
1357 // virtual bool ScrollIntoView(long position, int keyCode);
1358
1359 // /// The caret position is the character position just before the caret.
1360 // /// A value of -1 means the caret is at the start of the buffer.
1361 // void SetCaretPosition(long position, bool showAtLineStart = false) ;
1362 // long GetCaretPosition() const;
1363
1364 // /// Move caret one visual step forward: this may mean setting a flag
1365 // /// and keeping the same position if we're going from the end of one line
1366 // /// to the start of the next, which may be the exact same caret position.
1367 // void MoveCaretForward(long oldPosition) ;
1368
1369 // /// Move caret one visual step forward: this may mean setting a flag
1370 // /// and keeping the same position if we're going from the end of one line
1371 // /// to the start of the next, which may be the exact same caret position.
1372 // void MoveCaretBack(long oldPosition) ;
1373
1374 // /// Get the caret height and position for the given character position
1375 // bool GetCaretPositionForIndex(long position, wxRect& rect);
1376
1377 // /// Gets the line for the visible caret position. If the caret is
1378 // /// shown at the very end of the line, it means the next character is actually
1379 // /// on the following line. So let's get the line we're expecting to find
1380 // /// if this is the case.
1381 // wxRichTextLine* GetVisibleLineForCaretPosition(long caretPosition) const;
1382
1383 // /// Gets the command processor
1384 // wxCommandProcessor* GetCommandProcessor() const;
1385
1386 // /// Delete content if there is a selection, e.g. when pressing a key.
1387 // /// Returns the new caret position in newPos, or leaves it if there
1388 // /// was no action.
1389 // bool DeleteSelectedContent(long* newPos= NULL);
1390
1391 // /// Transform logical to physical
1392 // wxPoint GetPhysicalPoint(const wxPoint& ptLogical) const;
1393
1394 // /// Transform physical to logical
1395 // wxPoint GetLogicalPoint(const wxPoint& ptPhysical) const;
1396
1397 // /// Finds the caret position for the next word. Direction
1398 // /// is 1 (forward) or -1 (backwards).
1399 // virtual long FindNextWordPosition(int direction = 1) const;
1400
1401 // /// Is the given position visible on the screen?
1402 // bool IsPositionVisible(long pos) const;
1403
1404 // /// Returns the first visible position in the current view
1405 // long GetFirstVisiblePosition() const;
1406 };
1407
1408
1409 //----------------------------------------------------------------------
1410
1411
1412 %constant wxEventType wxEVT_COMMAND_RICHTEXT_ITEM_SELECTED;
1413 %constant wxEventType wxEVT_COMMAND_RICHTEXT_ITEM_DESELECTED;
1414 %constant wxEventType wxEVT_COMMAND_RICHTEXT_LEFT_CLICK;
1415 %constant wxEventType wxEVT_COMMAND_RICHTEXT_RIGHT_CLICK;
1416 %constant wxEventType wxEVT_COMMAND_RICHTEXT_MIDDLE_CLICK;
1417 %constant wxEventType wxEVT_COMMAND_RICHTEXT_LEFT_DCLICK;
1418 %constant wxEventType wxEVT_COMMAND_RICHTEXT_RETURN;
1419
1420
1421 %pythoncode {
1422 EVT_RICHTEXT_ITEM_SELECTED = wx.PyEventBinder(wxEVT_COMMAND_RICHTEXT_ITEM_SELECTED, 1)
1423 EVT_RICHTEXT_ITEM_DESELECTED = wx.PyEventBinder(wxEVT_COMMAND_RICHTEXT_ITEM_DESELECTED, 1)
1424 EVT_RICHTEXT_LEFT_CLICK = wx.PyEventBinder(wxEVT_COMMAND_RICHTEXT_LEFT_CLICK, 1)
1425 EVT_RICHTEXT_RIGHT_CLICK = wx.PyEventBinder(wxEVT_COMMAND_RICHTEXT_RIGHT_CLICK, 1)
1426 EVT_RICHTEXT_MIDDLE_CLICK = wx.PyEventBinder(wxEVT_COMMAND_RICHTEXT_MIDDLE_CLICK, 1)
1427 EVT_RICHTEXT_LEFT_DCLICK = wx.PyEventBinder(wxEVT_COMMAND_RICHTEXT_LEFT_DCLICK, 1)
1428 EVT_RICHTEXT_RETURN = wx.PyEventBinder( wxEVT_COMMAND_RICHTEXT_RETURN, 1)
1429 }
1430
1431
1432 class wxRichTextEvent : public wxNotifyEvent
1433 {
1434 public:
1435 wxRichTextEvent(wxEventType commandType = wxEVT_NULL, int winid = 0);
1436
1437 int GetIndex() const;
1438 void SetIndex(int n);
1439
1440 int GetFlags() const;
1441 void SetFlags(int flags);
1442 };
1443
1444 //----------------------------------------------------------------------
1445
1446 %init %{
1447 %}
1448
1449 //----------------------------------------------------------------------