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