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