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