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