]> git.saurik.com Git - wxWidgets.git/blob - include/wx/richtext/richtextctrl.h
Don't use double buffering on platforms that do it automatically.
[wxWidgets.git] / include / wx / richtext / richtextctrl.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/richtext/richtextctrl.h
3 // Purpose: A rich edit control
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 2005-09-30
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_RICHTEXTCTRL_H_
13 #define _WX_RICHTEXTCTRL_H_
14
15 #include "wx/richtext/richtextbuffer.h"
16
17 #if wxUSE_RICHTEXT
18
19 #include "wx/scrolwin.h"
20 #include "wx/caret.h"
21
22 #if wxCHECK_VERSION(2,7,0)
23 #define wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE 1
24 #else
25 #define wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE 0
26 #endif
27
28 #if wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE
29 #include "wx/textctrl.h"
30 #endif
31
32 #if !defined(__WXGTK__) && !defined(__WXMAC__)
33 #define wxRICHTEXT_BUFFERED_PAINTING 1
34 #else
35 #define wxRICHTEXT_BUFFERED_PAINTING 0
36 #endif
37
38 class WXDLLIMPEXP_RICHTEXT wxRichTextStyleDefinition;
39
40 /*!
41 * Styles and flags
42 */
43
44 /* Styles
45 */
46
47 #define wxRE_READONLY 0x0010
48 #define wxRE_MULTILINE 0x0020
49
50 /* Flags
51 */
52
53 #define wxRICHTEXT_SHIFT_DOWN 0x01
54 #define wxRICHTEXT_CTRL_DOWN 0x02
55 #define wxRICHTEXT_ALT_DOWN 0x04
56
57 /* Defaults
58 */
59
60 #define wxRICHTEXT_DEFAULT_OVERALL_SIZE wxSize(-1, -1)
61 #define wxRICHTEXT_DEFAULT_IMAGE_SIZE wxSize(80, 80)
62 #define wxRICHTEXT_DEFAULT_SPACING 3
63 #define wxRICHTEXT_DEFAULT_MARGIN 3
64 #define wxRICHTEXT_DEFAULT_UNFOCUSSED_BACKGROUND wxColour(175, 175, 175)
65 #define wxRICHTEXT_DEFAULT_FOCUSSED_BACKGROUND wxColour(140, 140, 140)
66 #define wxRICHTEXT_DEFAULT_UNSELECTED_BACKGROUND wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)
67 #define wxRICHTEXT_DEFAULT_TYPE_COLOUR wxColour(0, 0, 200)
68 #define wxRICHTEXT_DEFAULT_FOCUS_RECT_COLOUR wxColour(100, 80, 80)
69 #define wxRICHTEXT_DEFAULT_CARET_WIDTH 2
70 // Minimum buffer size before delayed layout kicks in
71 #define wxRICHTEXT_DEFAULT_DELAYED_LAYOUT_THRESHOLD 20000
72 // Milliseconds before layout occurs after resize
73 #define wxRICHTEXT_DEFAULT_LAYOUT_INTERVAL 50
74
75 /*!
76 * Forward declarations
77 */
78
79 /*!
80 * wxRichTextItem class declaration
81 */
82
83 // Drawing styles/states
84 #define wxRICHTEXT_SELECTED 0x01
85 #define wxRICHTEXT_TAGGED 0x02
86 // The control is focussed
87 #define wxRICHTEXT_FOCUSSED 0x04
88 // The item itself has the focus
89 #define wxRICHTEXT_IS_FOCUS 0x08
90
91 /*!
92 * wxRichTextCtrl class declaration
93 */
94
95 class WXDLLIMPEXP_RICHTEXT wxRichTextCtrl:
96 #if wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE
97 public wxTextCtrlBase, public wxScrollHelper
98 #else
99 public wxScrolledWindow
100 #endif
101 {
102 DECLARE_CLASS( wxRichTextCtrl )
103 DECLARE_EVENT_TABLE()
104
105 public:
106 // Constructors
107
108 wxRichTextCtrl( );
109 wxRichTextCtrl( wxWindow* parent, wxWindowID id = -1, const wxString& value = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
110 long style = wxRE_MULTILINE );
111 virtual ~wxRichTextCtrl( );
112
113 // Operations
114
115 /// Creation
116 bool Create( wxWindow* parent, wxWindowID id = -1, const wxString& value = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
117 long style = wxRE_MULTILINE );
118
119 /// Member initialisation
120 void Init();
121
122 ///// wxTextCtrl compatibility
123
124 // Accessors
125
126 virtual wxString GetValue() const;
127 virtual void SetValue(const wxString& value);
128
129 virtual wxString GetRange(long from, long to) const;
130
131 virtual int GetLineLength(long lineNo) const ;
132 virtual wxString GetLineText(long lineNo) const ;
133 virtual int GetNumberOfLines() const ;
134
135 virtual bool IsModified() const ;
136 virtual bool IsEditable() const ;
137
138 // more readable flag testing methods
139 bool IsSingleLine() const { return !HasFlag(wxRE_MULTILINE); }
140 bool IsMultiLine() const { return !IsSingleLine(); }
141
142 // If the return values from and to are the same, there is no selection.
143 virtual void GetSelection(long* from, long* to) const;
144
145 virtual wxString GetStringSelection() const;
146
147 /// Get filename
148 wxString GetFilename() const { return m_filename; }
149
150 /// Set filename
151 void SetFilename(const wxString& filename) { m_filename = filename; }
152
153 /// Set the threshold in character positions for doing layout optimization during sizing
154 void SetDelayedLayoutThreshold(long threshold) { m_delayedLayoutThreshold = threshold; }
155
156 /// Get the threshold in character positions for doing layout optimization during sizing
157 long GetDelayedLayoutThreshold() const { return m_delayedLayoutThreshold; }
158
159 // Operations
160
161 // editing
162 virtual void Clear();
163 virtual void Replace(long from, long to, const wxString& value);
164 virtual void Remove(long from, long to);
165
166 #if !wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE
167 bool LoadFile(const wxString& file, int fileType = wxRICHTEXT_TYPE_ANY);
168 bool SaveFile(const wxString& file = wxEmptyString, int fileType = wxRICHTEXT_TYPE_ANY);
169 #endif
170
171 // load/save the controls contents from/to the file
172 virtual bool DoLoadFile(const wxString& file, int fileType);
173 virtual bool DoSaveFile(const wxString& file = wxEmptyString, int fileType = wxRICHTEXT_TYPE_ANY);
174
175 // sets/clears the dirty flag
176 virtual void MarkDirty();
177 virtual void DiscardEdits();
178
179 // set the max number of characters which may be entered in a single line
180 // text control
181 virtual void SetMaxLength(unsigned long WXUNUSED(len)) { }
182
183 // writing text inserts it at the current position, appending always
184 // inserts it at the end
185 virtual void WriteText(const wxString& text);
186 virtual void AppendText(const wxString& text);
187
188 // text control under some platforms supports the text styles: these
189 // methods allow to apply the given text style to the given selection or to
190 // set/get the style which will be used for all appended text
191 virtual bool SetStyle(long start, long end, const wxTextAttr& style);
192 virtual bool SetStyle(long start, long end, const wxTextAttrEx& style);
193 virtual bool SetStyle(const wxRichTextRange& range, const wxRichTextAttr& style);
194 virtual bool GetStyle(long position, wxTextAttr& style);
195 virtual bool GetStyle(long position, wxTextAttrEx& style);
196 virtual bool GetStyle(long position, wxRichTextAttr& style);
197
198 // extended style setting operation with flags including:
199 // wxRICHTEXT_SETSTYLE_WITH_UNDO, wxRICHTEXT_SETSTYLE_OPTIMIZE, wxRICHTEXT_SETSTYLE_PARAGRAPHS_ONLY, wxRICHTEXT_SETSTYLE_CHARACTERS_ONLY
200 // see richtextbuffer.h for more details.
201 virtual bool SetStyleEx(long start, long end, const wxTextAttrEx& style, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO);
202 virtual bool SetStyleEx(const wxRichTextRange& range, const wxTextAttrEx& style, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO);
203 virtual bool SetStyleEx(const wxRichTextRange& range, const wxRichTextAttr& style, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO);
204
205 /// Get the content (uncombined) attributes for this position.
206 virtual bool GetUncombinedStyle(long position, wxTextAttr& style);
207 virtual bool GetUncombinedStyle(long position, wxTextAttrEx& style);
208 virtual bool GetUncombinedStyle(long position, wxRichTextAttr& style);
209
210 virtual bool SetDefaultStyle(const wxTextAttrEx& style);
211 virtual bool SetDefaultStyle(const wxTextAttr& style);
212
213 // TODO: change to GetDefaultStyle if we merge wxTextAttr and wxTextAttrEx
214 virtual const wxTextAttrEx& GetDefaultStyleEx() const;
215 virtual const wxTextAttr& GetDefaultStyle() const;
216
217 // translate between the position (which is just an index in the text ctrl
218 // considering all its contents as a single strings) and (x, y) coordinates
219 // which represent column and line.
220 virtual long XYToPosition(long x, long y) const;
221 virtual bool PositionToXY(long pos, long *x, long *y) const;
222
223 virtual void ShowPosition(long pos);
224
225 // find the character at position given in pixels
226 //
227 // NB: pt is in device coords (not adjusted for the client area origin nor
228 // scrolling)
229 virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt, long *pos) const;
230 virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt,
231 wxTextCoord *col,
232 wxTextCoord *row) const;
233
234 // Clipboard operations
235 virtual void Copy();
236 virtual void Cut();
237 virtual void Paste();
238 virtual void DeleteSelection();
239
240 virtual bool CanCopy() const;
241 virtual bool CanCut() const;
242 virtual bool CanPaste() const;
243 virtual bool CanDeleteSelection() const;
244
245 // Undo/redo
246 virtual void Undo();
247 virtual void Redo();
248
249 virtual bool CanUndo() const;
250 virtual bool CanRedo() const;
251
252 // Insertion point
253 virtual void SetInsertionPoint(long pos);
254 virtual void SetInsertionPointEnd();
255 virtual long GetInsertionPoint() const;
256 virtual wxTextPos GetLastPosition() const;
257
258 virtual void SetSelection(long from, long to);
259 virtual void SelectAll();
260 virtual void SetEditable(bool editable);
261
262 /// Call Freeze to prevent refresh
263 virtual void Freeze();
264
265 /// Call Thaw to refresh
266 virtual void Thaw();
267
268 /// Call Thaw to refresh
269 virtual bool IsFrozen() const { return m_freezeCount > 0; }
270
271 virtual bool HasSelection() const;
272
273 ///// Functionality specific to wxRichTextCtrl
274
275 /// Write an image at the current insertion point. Supply optional type to use
276 /// for internal and file storage of the raw data.
277 virtual bool WriteImage(const wxImage& image, int bitmapType = wxBITMAP_TYPE_PNG);
278
279 /// Write a bitmap at the current insertion point. Supply optional type to use
280 /// for internal and file storage of the raw data.
281 virtual bool WriteImage(const wxBitmap& bitmap, int bitmapType = wxBITMAP_TYPE_PNG);
282
283 /// Load an image from file and write at the current insertion point.
284 virtual bool WriteImage(const wxString& filename, int bitmapType);
285
286 /// Write an image block at the current insertion point.
287 virtual bool WriteImage(const wxRichTextImageBlock& imageBlock);
288
289 /// Insert a newline (actually paragraph) at the current insertion point.
290 virtual bool Newline();
291
292 /// Set basic (overall) style
293 virtual void SetBasicStyle(const wxTextAttrEx& style) { GetBuffer().SetBasicStyle(style); }
294 virtual void SetBasicStyle(const wxRichTextAttr& style) { GetBuffer().SetBasicStyle(style); }
295
296 /// Get basic (overall) style
297 virtual const wxTextAttrEx& GetBasicStyle() const { return GetBuffer().GetBasicStyle(); }
298
299 /// Begin using a style
300 virtual bool BeginStyle(const wxTextAttrEx& style) { return GetBuffer().BeginStyle(style); }
301
302 /// End the style
303 virtual bool EndStyle() { return GetBuffer().EndStyle(); }
304
305 /// End all styles
306 virtual bool EndAllStyles() { return GetBuffer().EndAllStyles(); }
307
308 /// Begin using bold
309 bool BeginBold() { return GetBuffer().BeginBold(); }
310
311 /// End using bold
312 bool EndBold() { return GetBuffer().EndBold(); }
313
314 /// Begin using italic
315 bool BeginItalic() { return GetBuffer().BeginItalic(); }
316
317 /// End using italic
318 bool EndItalic() { return GetBuffer().EndItalic(); }
319
320 /// Begin using underline
321 bool BeginUnderline() { return GetBuffer().BeginUnderline(); }
322
323 /// End using underline
324 bool EndUnderline() { return GetBuffer().EndUnderline(); }
325
326 /// Begin using point size
327 bool BeginFontSize(int pointSize) { return GetBuffer().BeginFontSize(pointSize); }
328
329 /// End using point size
330 bool EndFontSize() { return GetBuffer().EndFontSize(); }
331
332 /// Begin using this font
333 bool BeginFont(const wxFont& font) { return GetBuffer().BeginFont(font); }
334
335 /// End using a font
336 bool EndFont() { return GetBuffer().EndFont(); }
337
338 /// Begin using this colour
339 bool BeginTextColour(const wxColour& colour) { return GetBuffer().BeginTextColour(colour); }
340
341 /// End using a colour
342 bool EndTextColour() { return GetBuffer().EndTextColour(); }
343
344 /// Begin using alignment
345 bool BeginAlignment(wxTextAttrAlignment alignment) { return GetBuffer().BeginAlignment(alignment); }
346
347 /// End alignment
348 bool EndAlignment() { return GetBuffer().EndAlignment(); }
349
350 /// Begin left indent
351 bool BeginLeftIndent(int leftIndent, int leftSubIndent = 0) { return GetBuffer().BeginLeftIndent(leftIndent, leftSubIndent); }
352
353 /// End left indent
354 bool EndLeftIndent() { return GetBuffer().EndLeftIndent(); }
355
356 /// Begin right indent
357 bool BeginRightIndent(int rightIndent) { return GetBuffer().BeginRightIndent(rightIndent); }
358
359 /// End right indent
360 bool EndRightIndent() { return GetBuffer().EndRightIndent(); }
361
362 /// Begin paragraph spacing
363 bool BeginParagraphSpacing(int before, int after) { return GetBuffer().BeginParagraphSpacing(before, after); }
364
365 /// End paragraph spacing
366 bool EndParagraphSpacing() { return GetBuffer().EndParagraphSpacing(); }
367
368 /// Begin line spacing
369 bool BeginLineSpacing(int lineSpacing) { return GetBuffer().BeginLineSpacing(lineSpacing); }
370
371 /// End line spacing
372 bool EndLineSpacing() { return GetBuffer().EndLineSpacing(); }
373
374 /// Begin numbered bullet
375 bool BeginNumberedBullet(int bulletNumber, int leftIndent, int leftSubIndent, int bulletStyle = wxTEXT_ATTR_BULLET_STYLE_ARABIC|wxTEXT_ATTR_BULLET_STYLE_PERIOD)
376 { return GetBuffer().BeginNumberedBullet(bulletNumber, leftIndent, leftSubIndent, bulletStyle); }
377
378 /// End numbered bullet
379 bool EndNumberedBullet() { return GetBuffer().EndNumberedBullet(); }
380
381 /// Begin symbol bullet
382 bool BeginSymbolBullet(wxChar symbol, int leftIndent, int leftSubIndent, int bulletStyle = wxTEXT_ATTR_BULLET_STYLE_SYMBOL)
383 { return GetBuffer().BeginSymbolBullet(symbol, leftIndent, leftSubIndent, bulletStyle); }
384
385 /// End symbol bullet
386 bool EndSymbolBullet() { return GetBuffer().EndSymbolBullet(); }
387
388 /// Begin named character style
389 bool BeginCharacterStyle(const wxString& characterStyle) { return GetBuffer().BeginCharacterStyle(characterStyle); }
390
391 /// End named character style
392 bool EndCharacterStyle() { return GetBuffer().EndCharacterStyle(); }
393
394 /// Begin named paragraph style
395 bool BeginParagraphStyle(const wxString& paragraphStyle) { return GetBuffer().BeginParagraphStyle(paragraphStyle); }
396
397 /// End named character style
398 bool EndParagraphStyle() { return GetBuffer().EndParagraphStyle(); }
399
400 /// Sets the default style to the style under the cursor
401 bool SetDefaultStyleToCursorStyle();
402
403 /// Clear the selection
404 virtual void SelectNone();
405
406 /// Select the word at the given character position
407 virtual bool SelectWord(long position);
408
409 /// Get/set the selection range in character positions. -1, -1 means no selection.
410 /// The range is in API convention, i.e. a single character selection is denoted
411 /// by (n, n+1)
412 wxRichTextRange GetSelectionRange() const;
413 void SetSelectionRange(const wxRichTextRange& range);
414
415 /// Get/set the selection range in character positions. -1, -1 means no selection.
416 /// The range is in internal format, i.e. a single character selection is denoted
417 /// by (n, n)
418 const wxRichTextRange& GetInternalSelectionRange() const { return m_selectionRange; }
419 void SetInternalSelectionRange(const wxRichTextRange& range) { m_selectionRange = range; }
420
421 /// Add a new paragraph of text to the end of the buffer
422 virtual wxRichTextRange AddParagraph(const wxString& text);
423
424 /// Add an image
425 virtual wxRichTextRange AddImage(const wxImage& image);
426
427 /// Layout the buffer: which we must do before certain operations, such as
428 /// setting the caret position.
429 virtual bool LayoutContent(bool onlyVisibleRect = false);
430
431 /// Move the caret to the given character position
432 virtual bool MoveCaret(long pos, bool showAtLineStart = false);
433
434 /// Move right
435 virtual bool MoveRight(int noPositions = 1, int flags = 0);
436
437 /// Move left
438 virtual bool MoveLeft(int noPositions = 1, int flags = 0);
439
440 /// Move up
441 virtual bool MoveUp(int noLines = 1, int flags = 0);
442
443 /// Move up
444 virtual bool MoveDown(int noLines = 1, int flags = 0);
445
446 /// Move to the end of the line
447 virtual bool MoveToLineEnd(int flags = 0);
448
449 /// Move to the start of the line
450 virtual bool MoveToLineStart(int flags = 0);
451
452 /// Move to the end of the paragraph
453 virtual bool MoveToParagraphEnd(int flags = 0);
454
455 /// Move to the start of the paragraph
456 virtual bool MoveToParagraphStart(int flags = 0);
457
458 /// Move to the start of the buffer
459 virtual bool MoveHome(int flags = 0);
460
461 /// Move to the end of the buffer
462 virtual bool MoveEnd(int flags = 0);
463
464 /// Move n pages up
465 virtual bool PageUp(int noPages = 1, int flags = 0);
466
467 /// Move n pages down
468 virtual bool PageDown(int noPages = 1, int flags = 0);
469
470 /// Move n words left
471 virtual bool WordLeft(int noPages = 1, int flags = 0);
472
473 /// Move n words right
474 virtual bool WordRight(int noPages = 1, int flags = 0);
475
476 /// Returns the buffer associated with the control.
477 wxRichTextBuffer& GetBuffer() { return m_buffer; }
478 const wxRichTextBuffer& GetBuffer() const { return m_buffer; }
479
480 /// Start batching undo history for commands.
481 virtual bool BeginBatchUndo(const wxString& cmdName) { return m_buffer.BeginBatchUndo(cmdName); }
482
483 /// End batching undo history for commands.
484 virtual bool EndBatchUndo() { return m_buffer.EndBatchUndo(); }
485
486 /// Are we batching undo history for commands?
487 virtual bool BatchingUndo() const { return m_buffer.BatchingUndo(); }
488
489 /// Start suppressing undo history for commands.
490 virtual bool BeginSuppressUndo() { return m_buffer.BeginSuppressUndo(); }
491
492 /// End suppressing undo history for commands.
493 virtual bool EndSuppressUndo() { return m_buffer.EndSuppressUndo(); }
494
495 /// Are we suppressing undo history for commands?
496 virtual bool SuppressingUndo() const { return m_buffer.SuppressingUndo(); }
497
498 /// Test if this whole range has character attributes of the specified kind. If any
499 /// of the attributes are different within the range, the test fails. You
500 /// can use this to implement, for example, bold button updating. style must have
501 /// flags indicating which attributes are of interest.
502 virtual bool HasCharacterAttributes(const wxRichTextRange& range, const wxTextAttrEx& style) const
503 {
504 return GetBuffer().HasCharacterAttributes(range, style);
505 }
506 virtual bool HasCharacterAttributes(const wxRichTextRange& range, const wxRichTextAttr& style) const
507 {
508 return GetBuffer().HasCharacterAttributes(range, style);
509 }
510
511 /// Test if this whole range has paragraph attributes of the specified kind. If any
512 /// of the attributes are different within the range, the test fails. You
513 /// can use this to implement, for example, centering button updating. style must have
514 /// flags indicating which attributes are of interest.
515 virtual bool HasParagraphAttributes(const wxRichTextRange& range, const wxTextAttrEx& style) const
516 {
517 return GetBuffer().HasParagraphAttributes(range, style);
518 }
519 virtual bool HasParagraphAttributes(const wxRichTextRange& range, const wxRichTextAttr& style) const
520 {
521 return GetBuffer().HasParagraphAttributes(range, style);
522 }
523
524 /// Is all of the selection bold?
525 virtual bool IsSelectionBold();
526
527 /// Is all of the selection italics?
528 virtual bool IsSelectionItalics();
529
530 /// Is all of the selection underlined?
531 virtual bool IsSelectionUnderlined();
532
533 /// Is all of the selection aligned according to the specified flag?
534 virtual bool IsSelectionAligned(wxTextAttrAlignment alignment);
535
536 /// Apply bold to the selection
537 virtual bool ApplyBoldToSelection();
538
539 /// Apply italic to the selection
540 virtual bool ApplyItalicToSelection();
541
542 /// Apply underline to the selection
543 virtual bool ApplyUnderlineToSelection();
544
545 /// Apply alignment to the selection
546 virtual bool ApplyAlignmentToSelection(wxTextAttrAlignment alignment);
547
548 /// Apply a named style to the selection
549 virtual void ApplyStyle(wxRichTextStyleDefinition* def);
550
551 /// Set style sheet, if any.
552 void SetStyleSheet(wxRichTextStyleSheet* styleSheet) { GetBuffer().SetStyleSheet(styleSheet); }
553 wxRichTextStyleSheet* GetStyleSheet() const { return GetBuffer().GetStyleSheet(); }
554
555 /// Apply the style sheet to the buffer, for example if the styles have changed.
556 bool ApplyStyleSheet(wxRichTextStyleSheet* styleSheet = NULL);
557
558 // Command handlers
559
560 void Command(wxCommandEvent& event);
561 void OnDropFiles(wxDropFilesEvent& event);
562
563 void OnCut(wxCommandEvent& event);
564 void OnCopy(wxCommandEvent& event);
565 void OnPaste(wxCommandEvent& event);
566 void OnUndo(wxCommandEvent& event);
567 void OnRedo(wxCommandEvent& event);
568 void OnSelectAll(wxCommandEvent& event);
569 void OnClear(wxCommandEvent& event);
570
571 void OnUpdateCut(wxUpdateUIEvent& event);
572 void OnUpdateCopy(wxUpdateUIEvent& event);
573 void OnUpdatePaste(wxUpdateUIEvent& event);
574 void OnUpdateUndo(wxUpdateUIEvent& event);
575 void OnUpdateRedo(wxUpdateUIEvent& event);
576 void OnUpdateSelectAll(wxUpdateUIEvent& event);
577 void OnUpdateClear(wxUpdateUIEvent& event);
578
579 // Show a context menu for Rich Edit controls (the standard
580 // EDIT control has one already)
581 void OnContextMenu(wxContextMenuEvent& event);
582
583 // Event handlers
584
585 /// Painting
586 void OnPaint(wxPaintEvent& event);
587 void OnEraseBackground(wxEraseEvent& event);
588
589 /// Left-click
590 void OnLeftClick(wxMouseEvent& event);
591
592 /// Left-up
593 void OnLeftUp(wxMouseEvent& event);
594
595 /// Motion
596 void OnMoveMouse(wxMouseEvent& event);
597
598 /// Left-double-click
599 void OnLeftDClick(wxMouseEvent& event);
600
601 /// Middle-click
602 void OnMiddleClick(wxMouseEvent& event);
603
604 /// Right-click
605 void OnRightClick(wxMouseEvent& event);
606
607 /// Key press
608 void OnChar(wxKeyEvent& event);
609
610 /// Sizing
611 void OnSize(wxSizeEvent& event);
612
613 /// Setting/losing focus
614 void OnSetFocus(wxFocusEvent& event);
615 void OnKillFocus(wxFocusEvent& event);
616
617 /// Idle-time processing
618 void OnIdle(wxIdleEvent& event);
619
620 /// Scrolling
621 void OnScroll(wxScrollWinEvent& event);
622
623 /// Set font, and also default attributes
624 virtual bool SetFont(const wxFont& font);
625
626 /// Set up scrollbars, e.g. after a resize
627 virtual void SetupScrollbars(bool atTop = false);
628
629 /// Keyboard navigation
630 virtual bool KeyboardNavigate(int keyCode, int flags);
631
632 /// Paint the background
633 virtual void PaintBackground(wxDC& dc);
634
635 #if wxRICHTEXT_BUFFERED_PAINTING
636 /// Recreate buffer bitmap if necessary
637 virtual bool RecreateBuffer(const wxSize& size = wxDefaultSize);
638 #endif
639
640 /// Set the selection
641 virtual void DoSetSelection(long from, long to, bool scrollCaret = true);
642
643 /// Write text
644 virtual void DoWriteText(const wxString& value, bool selectionOnly = true);
645
646 /// Send an update event
647 virtual bool SendUpdateEvent();
648
649 /// Init command event
650 void InitCommandEvent(wxCommandEvent& event) const;
651
652 /// do the window-specific processing after processing the update event
653 // (duplicated code from wxTextCtrlBase)
654 #if !wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE
655 virtual void DoUpdateWindowUI(wxUpdateUIEvent& event);
656 #endif
657
658 /// Should we inherit colours?
659 virtual bool ShouldInheritColours() const { return false; }
660
661 /// Position the caret
662 virtual void PositionCaret();
663
664 /// Extend the selection, returning true if the selection was
665 /// changed. Selections are in caret positions.
666 virtual bool ExtendSelection(long oldPosition, long newPosition, int flags);
667
668 /// Scroll into view. This takes a _caret_ position.
669 virtual bool ScrollIntoView(long position, int keyCode);
670
671 /// The caret position is the character position just before the caret.
672 /// A value of -1 means the caret is at the start of the buffer.
673 void SetCaretPosition(long position, bool showAtLineStart = false) ;
674 long GetCaretPosition() const { return m_caretPosition; }
675
676 /// The adjusted caret position is the character position adjusted to take
677 /// into account whether we're at the start of a paragraph, in which case
678 /// style information should be taken from the next position, not current one.
679 long GetAdjustedCaretPosition(long caretPos) const;
680
681 /// Move caret one visual step forward: this may mean setting a flag
682 /// and keeping the same position if we're going from the end of one line
683 /// to the start of the next, which may be the exact same caret position.
684 void MoveCaretForward(long oldPosition) ;
685
686 /// Move caret one visual step forward: this may mean setting a flag
687 /// and keeping the same position if we're going from the end of one line
688 /// to the start of the next, which may be the exact same caret position.
689 void MoveCaretBack(long oldPosition) ;
690
691 /// Get the caret height and position for the given character position
692 bool GetCaretPositionForIndex(long position, wxRect& rect);
693
694 /// Gets the line for the visible caret position. If the caret is
695 /// shown at the very end of the line, it means the next character is actually
696 /// on the following line. So let's get the line we're expecting to find
697 /// if this is the case.
698 wxRichTextLine* GetVisibleLineForCaretPosition(long caretPosition) const;
699
700 /// Gets the command processor
701 wxCommandProcessor* GetCommandProcessor() const { return GetBuffer().GetCommandProcessor(); }
702
703 /// Delete content if there is a selection, e.g. when pressing a key.
704 /// Returns the new caret position in newPos, or leaves it if there
705 /// was no action.
706 bool DeleteSelectedContent(long* newPos= NULL);
707
708 /// Transform logical to physical
709 wxPoint GetPhysicalPoint(const wxPoint& ptLogical) const;
710
711 /// Transform physical to logical
712 wxPoint GetLogicalPoint(const wxPoint& ptPhysical) const;
713
714 /// Finds the caret position for the next word. Direction
715 /// is 1 (forward) or -1 (backwards).
716 virtual long FindNextWordPosition(int direction = 1) const;
717
718 /// Is the given position visible on the screen?
719 bool IsPositionVisible(long pos) const;
720
721 /// Returns the first visible position in the current view
722 long GetFirstVisiblePosition() const;
723
724 /// Returns the caret position since the default formatting was changed. As
725 /// soon as this position changes, we no longer reflect the default style
726 /// in the UI. A value of -2 means that we should only reflect the style of the
727 /// content under the caret.
728 long GetCaretPositionForDefaultStyle() const { return m_caretPositionForDefaultStyle; }
729
730 /// Set the caret position for the default style that the user is selecting.
731 void SetCaretPositionForDefaultStyle(long pos) { m_caretPositionForDefaultStyle = pos; }
732
733 /// Should the UI reflect the default style chosen by the user, rather than the style under
734 /// the caret?
735 bool IsDefaultStyleShowing() const { return m_caretPositionForDefaultStyle != -2; }
736
737 /// Convenience function that tells the control to start reflecting the default
738 /// style, since the user is changing it.
739 void SetAndShowDefaultStyle(const wxRichTextAttr& attr)
740 {
741 SetDefaultStyle(attr);
742 SetCaretPositionForDefaultStyle(GetCaretPosition());
743 }
744
745 // Implementation
746
747 #if wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE
748 WX_FORWARD_TO_SCROLL_HELPER()
749 #endif
750
751 // Overrides
752 protected:
753
754 virtual wxSize DoGetBestSize() const ;
755
756 // Data members
757 private:
758
759 /// Allows nested Freeze/Thaw
760 int m_freezeCount;
761
762 #if wxRICHTEXT_BUFFERED_PAINTING
763 /// Buffer bitmap
764 wxBitmap m_bufferBitmap;
765 #endif
766
767 /// Text buffer
768 wxRichTextBuffer m_buffer;
769
770 #if !wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE
771 /// Filename
772 wxString m_filename;
773 #endif
774
775 wxMenu* m_contextMenu;
776
777 /// Caret position (1 less than the character position, so -1 is the
778 /// first caret position).
779 long m_caretPosition;
780
781 /// Caret position when the default formatting has been changed. As
782 /// soon as this position changes, we no longer reflect the default style
783 /// in the UI.
784 long m_caretPositionForDefaultStyle;
785
786 /// Selection range in character positions. -2, -2 means no selection.
787 wxRichTextRange m_selectionRange;
788
789 /// Anchor so we know how to extend the selection
790 /// It's a caret position since it's between two characters.
791 long m_selectionAnchor;
792
793 /// Are we editable?
794 bool m_editable;
795
796 /// Are we showing the caret position at the start of a line
797 /// instead of at the end of the previous one?
798 bool m_caretAtLineStart;
799
800 /// Are we dragging a selection?
801 bool m_dragging;
802
803 /// Start position for drag
804 wxPoint m_dragStart;
805
806 /// Do we need full layout in idle?
807 bool m_fullLayoutRequired;
808 wxLongLong m_fullLayoutTime;
809 long m_fullLayoutSavedPosition;
810
811 /// Threshold for doing delayed layout
812 long m_delayedLayoutThreshold;
813 };
814
815 /*!
816 * wxRichTextEvent - the event class for wxRichTextCtrl notifications
817 */
818
819 class WXDLLIMPEXP_RICHTEXT wxRichTextEvent : public wxNotifyEvent
820 {
821 public:
822 wxRichTextEvent(wxEventType commandType = wxEVT_NULL, int winid = 0)
823 : wxNotifyEvent(commandType, winid),
824 m_itemIndex(-1), m_flags(0)
825 { }
826
827 wxRichTextEvent(const wxRichTextEvent& event)
828 : wxNotifyEvent(event),
829 m_itemIndex(event.m_itemIndex), m_flags(event.m_flags)
830 { }
831
832 int GetIndex() const { return m_itemIndex; }
833 void SetIndex(int n) { m_itemIndex = n; }
834
835 int GetFlags() const { return m_flags; }
836 void SetFlags(int flags) { m_flags = flags; }
837
838 virtual wxEvent *Clone() const { return new wxRichTextEvent(*this); }
839
840 protected:
841 int m_itemIndex;
842 int m_flags;
843
844 private:
845 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxRichTextEvent)
846 };
847
848 /*!
849 * wxRichTextCtrl event macros
850 */
851
852 BEGIN_DECLARE_EVENT_TYPES()
853 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_ITEM_SELECTED, 2600)
854 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_ITEM_DESELECTED, 2601)
855 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_LEFT_CLICK, 2602)
856 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_RIGHT_CLICK, 2603)
857 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_MIDDLE_CLICK, 2604)
858 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_LEFT_DCLICK, 2605)
859 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_RETURN, 2606)
860 END_DECLARE_EVENT_TYPES()
861
862 typedef void (wxEvtHandler::*wxRichTextEventFunction)(wxRichTextEvent&);
863
864 #define EVT_RICHTEXT_ITEM_SELECTED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_ITEM_SELECTED, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxRichTextEventFunction, & fn ), NULL ),
865 #define EVT_RICHTEXT_ITEM_DESELECTED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_ITEM_DESELECTED, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxRichTextEventFunction, & fn ), NULL ),
866 #define EVT_RICHTEXT_LEFT_CLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_LEFT_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxRichTextEventFunction, & fn ), NULL ),
867 #define EVT_RICHTEXT_RIGHT_CLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_RIGHT_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxRichTextEventFunction, & fn ), NULL ),
868 #define EVT_RICHTEXT_MIDDLE_CLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_MIDDLE_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxRichTextEventFunction, & fn ), NULL ),
869 #define EVT_RICHTEXT_LEFT_DCLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_LEFT_DCLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxRichTextEventFunction, & fn ), NULL ),
870 #define EVT_RICHTEXT_RETURN(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_RETURN, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxRichTextEventFunction, & fn ), NULL ),
871
872 #endif
873 // wxUSE_RICHTEXT
874
875 #endif
876 // _WX_RICHTEXTCTRL_H_
877