]> git.saurik.com Git - wxWidgets.git/blob - include/wx/richtext/richtextctrl.h
Fixed bug introduced by compiler compatibility fix
[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_ADV 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 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 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 wxTextAttrEx& style);
179 virtual bool SetStyle(const wxRichTextRange& range, const wxRichTextAttr& style);
180 virtual bool GetStyle(long position, wxTextAttrEx& style) const;
181 virtual bool GetStyle(long position, wxRichTextAttr& style) const;
182 virtual bool SetDefaultStyle(const wxTextAttrEx& style);
183
184 // TODO: change to GetDefaultStyle if we merge wxTextAttr and wxTextAttrEx
185 virtual const wxTextAttrEx& GetDefaultStyleEx() const;
186
187 // translate between the position (which is just an index in the text ctrl
188 // considering all its contents as a single strings) and (x, y) coordinates
189 // which represent column and line.
190 virtual long XYToPosition(long x, long y) const;
191 virtual bool PositionToXY(long pos, long *x, long *y) const;
192
193 virtual void ShowPosition(long pos);
194
195 // find the character at position given in pixels
196 //
197 // NB: pt is in device coords (not adjusted for the client area origin nor
198 // scrolling)
199 virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt, long *pos) const;
200 virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt,
201 wxTextCoord *col,
202 wxTextCoord *row) const;
203
204 // Clipboard operations
205 virtual void Copy();
206 virtual void Cut();
207 virtual void Paste();
208 virtual void DeleteSelection();
209
210 virtual bool CanCopy() const;
211 virtual bool CanCut() const;
212 virtual bool CanPaste() const;
213 virtual bool CanDeleteSelection() const;
214
215 // Undo/redo
216 virtual void Undo();
217 virtual void Redo();
218
219 virtual bool CanUndo() const;
220 virtual bool CanRedo() const;
221
222 // Insertion point
223 virtual void SetInsertionPoint(long pos);
224 virtual void SetInsertionPointEnd();
225 virtual long GetInsertionPoint() const;
226 virtual wxTextPos GetLastPosition() const;
227
228 virtual void SetSelection(long from, long to);
229 virtual void SelectAll();
230 virtual void SetEditable(bool editable);
231
232 /// Call Freeze to prevent refresh
233 virtual void Freeze();
234
235 /// Call Thaw to refresh
236 virtual void Thaw();
237
238 /// Call Thaw to refresh
239 virtual bool IsFrozen() const { return m_freezeCount > 0; }
240
241 virtual bool HasSelection() const;
242
243 ///// Functionality specific to wxRichTextCtrl
244
245 /// Write an image at the current insertion point. Supply optional type to use
246 /// for internal and file storage of the raw data.
247 virtual bool WriteImage(const wxImage& image, int bitmapType = wxBITMAP_TYPE_PNG);
248
249 /// Write a bitmap 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 wxBitmap& bitmap, int bitmapType = wxBITMAP_TYPE_PNG);
252
253 /// Load an image from file and write at the current insertion point.
254 virtual bool WriteImage(const wxString& filename, int bitmapType);
255
256 /// Write an image block at the current insertion point.
257 virtual bool WriteImage(const wxRichTextImageBlock& imageBlock);
258
259 /// Insert a newline (actually paragraph) at the current insertion point.
260 virtual bool Newline();
261
262 /// Set basic (overall) style
263 virtual void SetBasicStyle(const wxTextAttrEx& style) { GetBuffer().SetBasicStyle(style); }
264 virtual void SetBasicStyle(const wxRichTextAttr& style) { GetBuffer().SetBasicStyle(style); }
265
266 /// Get basic (overall) style
267 virtual const wxTextAttrEx& GetBasicStyle() const { return GetBuffer().GetBasicStyle(); }
268
269 /// Begin using a style
270 virtual bool BeginStyle(const wxTextAttrEx& style) { return GetBuffer().BeginStyle(style); }
271
272 /// End the style
273 virtual bool EndStyle() { return GetBuffer().EndStyle(); }
274
275 /// End all styles
276 virtual bool EndAllStyles() { return GetBuffer().EndAllStyles(); }
277
278 /// Begin using bold
279 bool BeginBold() { return GetBuffer().BeginBold(); }
280
281 /// End using bold
282 bool EndBold() { return GetBuffer().EndBold(); }
283
284 /// Begin using italic
285 bool BeginItalic() { return GetBuffer().BeginItalic(); }
286
287 /// End using italic
288 bool EndItalic() { return GetBuffer().EndItalic(); }
289
290 /// Begin using underline
291 bool BeginUnderline() { return GetBuffer().BeginUnderline(); }
292
293 /// End using underline
294 bool EndUnderline() { return GetBuffer().EndUnderline(); }
295
296 /// Begin using point size
297 bool BeginFontSize(int pointSize) { return GetBuffer().BeginFontSize(pointSize); }
298
299 /// End using point size
300 bool EndFontSize() { return GetBuffer().EndFontSize(); }
301
302 /// Begin using this font
303 bool BeginFont(const wxFont& font) { return GetBuffer().BeginFont(font); }
304
305 /// End using a font
306 bool EndFont() { return GetBuffer().EndFont(); }
307
308 /// Begin using this colour
309 bool BeginTextColour(const wxColour& colour) { return GetBuffer().BeginTextColour(colour); }
310
311 /// End using a colour
312 bool EndTextColour() { return GetBuffer().EndTextColour(); }
313
314 /// Begin using alignment
315 bool BeginAlignment(wxTextAttrAlignment alignment) { return GetBuffer().BeginAlignment(alignment); }
316
317 /// End alignment
318 bool EndAlignment() { return GetBuffer().EndAlignment(); }
319
320 /// Begin left indent
321 bool BeginLeftIndent(int leftIndent, int leftSubIndent = 0) { return GetBuffer().BeginLeftIndent(leftIndent, leftSubIndent); }
322
323 /// End left indent
324 bool EndLeftIndent() { return GetBuffer().EndLeftIndent(); }
325
326 /// Begin right indent
327 bool BeginRightIndent(int rightIndent) { return GetBuffer().BeginRightIndent(rightIndent); }
328
329 /// End right indent
330 bool EndRightIndent() { return GetBuffer().EndRightIndent(); }
331
332 /// Begin paragraph spacing
333 bool BeginParagraphSpacing(int before, int after) { return GetBuffer().BeginParagraphSpacing(before, after); }
334
335 /// End paragraph spacing
336 bool EndParagraphSpacing() { return GetBuffer().EndParagraphSpacing(); }
337
338 /// Begin line spacing
339 bool BeginLineSpacing(int lineSpacing) { return GetBuffer().BeginLineSpacing(lineSpacing); }
340
341 /// End line spacing
342 bool EndLineSpacing() { return GetBuffer().EndLineSpacing(); }
343
344 /// Begin numbered bullet
345 bool BeginNumberedBullet(int bulletNumber, int leftIndent, int leftSubIndent, int bulletStyle = wxTEXT_ATTR_BULLET_STYLE_ARABIC|wxTEXT_ATTR_BULLET_STYLE_PERIOD)
346 { return GetBuffer().BeginNumberedBullet(bulletNumber, leftIndent, leftSubIndent, bulletStyle); }
347
348 /// End numbered bullet
349 bool EndNumberedBullet() { return GetBuffer().EndNumberedBullet(); }
350
351 /// Begin symbol bullet
352 bool BeginSymbolBullet(wxChar symbol, int leftIndent, int leftSubIndent, int bulletStyle = wxTEXT_ATTR_BULLET_STYLE_SYMBOL)
353 { return GetBuffer().BeginSymbolBullet(symbol, leftIndent, leftSubIndent, bulletStyle); }
354
355 /// End symbol bullet
356 bool EndSymbolBullet() { return GetBuffer().EndSymbolBullet(); }
357
358 /// Begin named character style
359 bool BeginCharacterStyle(const wxString& characterStyle) { return GetBuffer().BeginCharacterStyle(characterStyle); }
360
361 /// End named character style
362 bool EndCharacterStyle() { return GetBuffer().EndCharacterStyle(); }
363
364 /// Begin named paragraph style
365 bool BeginParagraphStyle(const wxString& paragraphStyle) { return GetBuffer().BeginParagraphStyle(paragraphStyle); }
366
367 /// End named character style
368 bool EndParagraphStyle() { return GetBuffer().EndParagraphStyle(); }
369
370 /// Sets the default style to the style under the cursor
371 bool SetDefaultStyleToCursorStyle();
372
373 /// Clear the selection
374 virtual void SelectNone();
375
376 /// Get/set the selection range in character positions. -1, -1 means no selection.
377 const wxRichTextRange& GetSelectionRange() const { return m_selectionRange; }
378 void SetSelectionRange(const wxRichTextRange& range) { m_selectionRange = range; }
379
380 /// Add a new paragraph of text to the end of the buffer
381 virtual wxRichTextRange AddParagraph(const wxString& text);
382
383 /// Add an image
384 virtual wxRichTextRange AddImage(const wxImage& image);
385
386 /// Layout the buffer: which we must do before certain operations, such as
387 /// setting the caret position.
388 virtual bool LayoutContent(bool onlyVisibleRect = false);
389
390 /// Move the caret to the given character position
391 virtual bool MoveCaret(long pos, bool showAtLineStart = false);
392
393 /// Move right
394 virtual bool MoveRight(int noPositions = 1, int flags = 0);
395
396 /// Move left
397 virtual bool MoveLeft(int noPositions = 1, int flags = 0);
398
399 /// Move up
400 virtual bool MoveUp(int noLines = 1, int flags = 0);
401
402 /// Move up
403 virtual bool MoveDown(int noLines = 1, int flags = 0);
404
405 /// Move to the end of the line
406 virtual bool MoveToLineEnd(int flags = 0);
407
408 /// Move to the start of the line
409 virtual bool MoveToLineStart(int flags = 0);
410
411 /// Move to the end of the paragraph
412 virtual bool MoveToParagraphEnd(int flags = 0);
413
414 /// Move to the start of the paragraph
415 virtual bool MoveToParagraphStart(int flags = 0);
416
417 /// Move to the start of the buffer
418 virtual bool MoveHome(int flags = 0);
419
420 /// Move to the end of the buffer
421 virtual bool MoveEnd(int flags = 0);
422
423 /// Move n pages up
424 virtual bool PageUp(int noPages = 1, int flags = 0);
425
426 /// Move n pages down
427 virtual bool PageDown(int noPages = 1, int flags = 0);
428
429 /// Move n words left
430 virtual bool WordLeft(int noPages = 1, int flags = 0);
431
432 /// Move n words right
433 virtual bool WordRight(int noPages = 1, int flags = 0);
434
435 /// Returns the buffer associated with the control.
436 wxRichTextBuffer& GetBuffer() { return m_buffer; }
437 const wxRichTextBuffer& GetBuffer() const { return m_buffer; }
438
439 /// Start batching undo history for commands.
440 virtual bool BeginBatchUndo(const wxString& cmdName) { return m_buffer.BeginBatchUndo(cmdName); }
441
442 /// End batching undo history for commands.
443 virtual bool EndBatchUndo() { return m_buffer.EndBatchUndo(); }
444
445 /// Are we batching undo history for commands?
446 virtual bool BatchingUndo() const { return m_buffer.BatchingUndo(); }
447
448 /// Start suppressing undo history for commands.
449 virtual bool BeginSuppressUndo() { return m_buffer.BeginSuppressUndo(); }
450
451 /// End suppressing undo history for commands.
452 virtual bool EndSuppressUndo() { return m_buffer.EndSuppressUndo(); }
453
454 /// Are we suppressing undo history for commands?
455 virtual bool SuppressingUndo() const { return m_buffer.SuppressingUndo(); }
456
457 /// Test if this whole range has character attributes of the specified kind. If any
458 /// of the attributes are different within the range, the test fails. You
459 /// can use this to implement, for example, bold button updating. style must have
460 /// flags indicating which attributes are of interest.
461 virtual bool HasCharacterAttributes(const wxRichTextRange& range, const wxTextAttrEx& style) const
462 {
463 return GetBuffer().HasCharacterAttributes(range, style);
464 }
465 virtual bool HasCharacterAttributes(const wxRichTextRange& range, const wxRichTextAttr& style) const
466 {
467 return GetBuffer().HasCharacterAttributes(range, style);
468 }
469
470 /// Test if this whole range has paragraph attributes of the specified kind. If any
471 /// of the attributes are different within the range, the test fails. You
472 /// can use this to implement, for example, centering button updating. style must have
473 /// flags indicating which attributes are of interest.
474 virtual bool HasParagraphAttributes(const wxRichTextRange& range, const wxTextAttrEx& style) const
475 {
476 return GetBuffer().HasParagraphAttributes(range, style);
477 }
478 virtual bool HasParagraphAttributes(const wxRichTextRange& range, const wxRichTextAttr& style) const
479 {
480 return GetBuffer().HasParagraphAttributes(range, style);
481 }
482
483 /// Is all of the selection bold?
484 virtual bool IsSelectionBold() const;
485
486 /// Is all of the selection italics?
487 virtual bool IsSelectionItalics() const;
488
489 /// Is all of the selection underlined?
490 virtual bool IsSelectionUnderlined() const;
491
492 /// Is all of the selection aligned according to the specified flag?
493 virtual bool IsSelectionAligned(wxTextAttrAlignment alignment) const;
494
495 /// Apply bold to the selection
496 virtual bool ApplyBoldToSelection();
497
498 /// Apply italic to the selection
499 virtual bool ApplyItalicToSelection();
500
501 /// Apply underline to the selection
502 virtual bool ApplyUnderlineToSelection();
503
504 /// Apply alignment to the selection
505 virtual bool ApplyAlignmentToSelection(wxTextAttrAlignment alignment);
506
507 /// Set style sheet, if any.
508 void SetStyleSheet(wxRichTextStyleSheet* styleSheet) { GetBuffer().SetStyleSheet(styleSheet); }
509 wxRichTextStyleSheet* GetStyleSheet() const { return GetBuffer().GetStyleSheet(); }
510
511 // Command handlers
512
513 void Command(wxCommandEvent & event);
514 void OnDropFiles(wxDropFilesEvent& event);
515
516 void OnCut(wxCommandEvent& event);
517 void OnCopy(wxCommandEvent& event);
518 void OnPaste(wxCommandEvent& event);
519 void OnUndo(wxCommandEvent& event);
520 void OnRedo(wxCommandEvent& event);
521 void OnSelectAll(wxCommandEvent& event);
522 void OnClear(wxCommandEvent& event);
523
524 void OnUpdateCut(wxUpdateUIEvent& event);
525 void OnUpdateCopy(wxUpdateUIEvent& event);
526 void OnUpdatePaste(wxUpdateUIEvent& event);
527 void OnUpdateUndo(wxUpdateUIEvent& event);
528 void OnUpdateRedo(wxUpdateUIEvent& event);
529 void OnUpdateSelectAll(wxUpdateUIEvent& event);
530 void OnUpdateClear(wxUpdateUIEvent& event);
531
532 // Show a context menu for Rich Edit controls (the standard
533 // EDIT control has one already)
534 void OnContextMenu(wxContextMenuEvent& event);
535
536 // Event handlers
537
538 /// Painting
539 void OnPaint(wxPaintEvent& event);
540 void OnEraseBackground(wxEraseEvent& event);
541
542 /// Left-click
543 void OnLeftClick(wxMouseEvent& event);
544
545 /// Left-up
546 void OnLeftUp(wxMouseEvent& event);
547
548 /// Motion
549 void OnMoveMouse(wxMouseEvent& event);
550
551 /// Left-double-click
552 void OnLeftDClick(wxMouseEvent& event);
553
554 /// Middle-click
555 void OnMiddleClick(wxMouseEvent& event);
556
557 /// Right-click
558 void OnRightClick(wxMouseEvent& event);
559
560 /// Key press
561 void OnChar(wxKeyEvent& event);
562
563 /// Sizing
564 void OnSize(wxSizeEvent& event);
565
566 /// Setting/losing focus
567 void OnSetFocus(wxFocusEvent& event);
568 void OnKillFocus(wxFocusEvent& event);
569
570 /// Idle-time processing
571 void OnIdle(wxIdleEvent& event);
572
573 /// Scrolling
574 void OnScroll(wxScrollWinEvent& event);
575
576 // Implementation
577
578 #if wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE
579 WX_FORWARD_TO_SCROLL_HELPER()
580 #endif
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 virtual void DoUpdateWindowUI(wxUpdateUIEvent& event);
611
612 /// Should we inherit colours?
613 virtual bool ShouldInheritColours() const { return false; }
614
615 /// Position the caret
616 virtual void PositionCaret();
617
618 /// Extend the selection, returning true if the selection was
619 /// changed. Selections are in caret positions.
620 virtual bool ExtendSelection(long oldPosition, long newPosition, int flags);
621
622 /// Scroll into view. This takes a _caret_ position.
623 virtual bool ScrollIntoView(long position, int keyCode);
624
625 /// The caret position is the character position just before the caret.
626 /// A value of -1 means the caret is at the start of the buffer.
627 void SetCaretPosition(long position, bool showAtLineStart = false) ;
628 long GetCaretPosition() const { return m_caretPosition; }
629
630 /// Move caret one visual step forward: this may mean setting a flag
631 /// and keeping the same position if we're going from the end of one line
632 /// to the start of the next, which may be the exact same caret position.
633 void MoveCaretForward(long oldPosition) ;
634
635 /// Move caret one visual step forward: this may mean setting a flag
636 /// and keeping the same position if we're going from the end of one line
637 /// to the start of the next, which may be the exact same caret position.
638 void MoveCaretBack(long oldPosition) ;
639
640 /// Get the caret height and position for the given character position
641 bool GetCaretPositionForIndex(long position, wxRect& rect);
642
643 /// Gets the line for the visible caret position. If the caret is
644 /// shown at the very end of the line, it means the next character is actually
645 /// on the following line. So let's get the line we're expecting to find
646 /// if this is the case.
647 wxRichTextLine* GetVisibleLineForCaretPosition(long caretPosition) const;
648
649 /// Gets the command processor
650 wxCommandProcessor* GetCommandProcessor() const { return GetBuffer().GetCommandProcessor(); }
651
652 /// Delete content if there is a selection, e.g. when pressing a key.
653 /// Returns the new caret position in newPos, or leaves it if there
654 /// was no action.
655 bool DeleteSelectedContent(long* newPos= NULL);
656
657 /// Transform logical to physical
658 wxPoint GetPhysicalPoint(const wxPoint& ptLogical) const;
659
660 /// Transform physical to logical
661 wxPoint GetLogicalPoint(const wxPoint& ptPhysical) const;
662
663 /// Finds the caret position for the next word. Direction
664 /// is 1 (forward) or -1 (backwards).
665 virtual long FindNextWordPosition(int direction = 1) const;
666
667 /// Is the given position visible on the screen?
668 bool IsPositionVisible(long pos) const;
669
670 /// Returns the first visible position in the current view
671 long GetFirstVisiblePosition() const;
672
673 // Overrides
674
675 virtual wxSize DoGetBestSize() const ;
676
677 // Data members
678 private:
679
680 /// Allows nested Freeze/Thaw
681 int m_freezeCount;
682
683 /// Buffer bitmap
684 wxBitmap m_bufferBitmap;
685
686 /// Text buffer
687 wxRichTextBuffer m_buffer;
688
689 /// Filename
690 wxString m_filename;
691
692 wxMenu* m_contextMenu;
693
694 /// Caret position (1 less than the character position, so -1 is the
695 /// first caret position).
696 long m_caretPosition;
697
698 /// Selection range in character positions. -2, -2 means no selection.
699 wxRichTextRange m_selectionRange;
700
701 /// Anchor so we know how to extend the selection
702 /// It's a caret position since it's between two characters.
703 long m_selectionAnchor;
704
705 /// Are we editable?
706 bool m_editable;
707
708 /// Are we showing the caret position at the start of a line
709 /// instead of at the end of the previous one?
710 bool m_caretAtLineStart;
711
712 /// Are we dragging a selection?
713 bool m_dragging;
714
715 /// Start position for drag
716 wxPoint m_dragStart;
717
718 /// Do we need full layout in idle?
719 bool m_fullLayoutRequired;
720 wxLongLong m_fullLayoutTime;
721 long m_fullLayoutSavedPosition;
722
723 /// Threshold for doing delayed layout
724 long m_delayedLayoutThreshold;
725 };
726
727 /*!
728 * wxRichTextEvent - the event class for wxRichTextCtrl notifications
729 */
730
731 class WXDLLIMPEXP_ADV wxRichTextEvent : public wxNotifyEvent
732 {
733 public:
734 wxRichTextEvent(wxEventType commandType = wxEVT_NULL, int winid = 0)
735 : wxNotifyEvent(commandType, winid),
736 m_itemIndex(-1), m_flags(0)
737 { }
738
739 wxRichTextEvent(const wxRichTextEvent& event)
740 : wxNotifyEvent(event),
741 m_itemIndex(event.m_itemIndex), m_flags(event.m_flags)
742 { }
743
744 int GetIndex() const { return m_itemIndex; }
745 void SetIndex(int n) { m_itemIndex = n; }
746
747 int GetFlags() const { return m_flags; }
748 void SetFlags(int flags) { m_flags = flags; }
749
750 virtual wxEvent *Clone() const { return new wxRichTextEvent(*this); }
751
752 protected:
753 int m_itemIndex;
754 int m_flags;
755
756 private:
757 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxRichTextEvent)
758 };
759
760 /*!
761 * wxRichTextCtrl event macros
762 */
763
764 BEGIN_DECLARE_EVENT_TYPES()
765 DECLARE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_ITEM_SELECTED, 2600)
766 DECLARE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_ITEM_DESELECTED, 2601)
767 DECLARE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_LEFT_CLICK, 2602)
768 DECLARE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_RIGHT_CLICK, 2603)
769 DECLARE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_MIDDLE_CLICK, 2604)
770 DECLARE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_LEFT_DCLICK, 2605)
771 DECLARE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_RETURN, 2606)
772 END_DECLARE_EVENT_TYPES()
773
774 typedef void (wxEvtHandler::*wxRichTextEventFunction)(wxRichTextEvent&);
775
776 #define EVT_RICHTEXT_ITEM_SELECTED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_ITEM_SELECTED, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxRichTextEventFunction, & fn ), NULL ),
777 #define EVT_RICHTEXT_ITEM_DESELECTED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_ITEM_DESELECTED, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxRichTextEventFunction, & fn ), NULL ),
778 #define EVT_RICHTEXT_LEFT_CLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_LEFT_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxRichTextEventFunction, & fn ), NULL ),
779 #define EVT_RICHTEXT_RIGHT_CLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_RIGHT_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxRichTextEventFunction, & fn ), NULL ),
780 #define EVT_RICHTEXT_MIDDLE_CLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_MIDDLE_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxRichTextEventFunction, & fn ), NULL ),
781 #define EVT_RICHTEXT_LEFT_DCLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_LEFT_DCLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxRichTextEventFunction, & fn ), NULL ),
782 #define EVT_RICHTEXT_RETURN(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_RETURN, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxRichTextEventFunction, & fn ), NULL ),
783
784 #endif
785 // wxUSE_RICHTEXT
786
787 #endif
788 // _WX_RICHTEXTCTRL_H_
789