]>
Commit | Line | Data |
---|---|---|
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 | ||
b01ca8b6 | 15 | #include "wx/richtext/richtextbuffer.h" |
5d7836c4 JS |
16 | |
17 | #if wxUSE_RICHTEXT | |
18 | ||
19 | #include "wx/scrolwin.h" | |
20 | #include "wx/caret.h" | |
21 | ||
b01ca8b6 | 22 | #include "wx/textctrl.h" |
b01ca8b6 | 23 | |
3e3a754f JS |
24 | #if !defined(__WXGTK__) && !defined(__WXMAC__) |
25 | #define wxRICHTEXT_BUFFERED_PAINTING 1 | |
26 | #else | |
27 | #define wxRICHTEXT_BUFFERED_PAINTING 0 | |
28 | #endif | |
29 | ||
b5dbe15d | 30 | class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextStyleDefinition; |
ab14c7aa | 31 | |
5d7836c4 JS |
32 | /*! |
33 | * Styles and flags | |
34 | */ | |
35 | ||
36 | /* Styles | |
37 | */ | |
38 | ||
39 | #define wxRE_READONLY 0x0010 | |
40 | #define wxRE_MULTILINE 0x0020 | |
e9f10004 JS |
41 | #define wxRE_CENTRE_CARET 0x8000 |
42 | #define wxRE_CENTER_CARET wxRE_CENTRE_CARET | |
5d7836c4 JS |
43 | |
44 | /* Flags | |
45 | */ | |
46 | ||
47 | #define wxRICHTEXT_SHIFT_DOWN 0x01 | |
48 | #define wxRICHTEXT_CTRL_DOWN 0x02 | |
49 | #define wxRICHTEXT_ALT_DOWN 0x04 | |
50 | ||
603f702b JS |
51 | /* Extra flags |
52 | */ | |
53 | ||
54 | // Don't draw guide lines around boxes and tables | |
55 | #define wxRICHTEXT_EX_NO_GUIDELINES 0x00000100 | |
56 | ||
57 | ||
5d7836c4 JS |
58 | /* Defaults |
59 | */ | |
60 | ||
61 | #define wxRICHTEXT_DEFAULT_OVERALL_SIZE wxSize(-1, -1) | |
62 | #define wxRICHTEXT_DEFAULT_IMAGE_SIZE wxSize(80, 80) | |
63 | #define wxRICHTEXT_DEFAULT_SPACING 3 | |
64 | #define wxRICHTEXT_DEFAULT_MARGIN 3 | |
65 | #define wxRICHTEXT_DEFAULT_UNFOCUSSED_BACKGROUND wxColour(175, 175, 175) | |
66 | #define wxRICHTEXT_DEFAULT_FOCUSSED_BACKGROUND wxColour(140, 140, 140) | |
67 | #define wxRICHTEXT_DEFAULT_UNSELECTED_BACKGROUND wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE) | |
68 | #define wxRICHTEXT_DEFAULT_TYPE_COLOUR wxColour(0, 0, 200) | |
69 | #define wxRICHTEXT_DEFAULT_FOCUS_RECT_COLOUR wxColour(100, 80, 80) | |
70 | #define wxRICHTEXT_DEFAULT_CARET_WIDTH 2 | |
4d551ad5 JS |
71 | // Minimum buffer size before delayed layout kicks in |
72 | #define wxRICHTEXT_DEFAULT_DELAYED_LAYOUT_THRESHOLD 20000 | |
73 | // Milliseconds before layout occurs after resize | |
74 | #define wxRICHTEXT_DEFAULT_LAYOUT_INTERVAL 50 | |
5d7836c4 | 75 | |
603f702b | 76 | /* Identifiers |
5d7836c4 | 77 | */ |
603f702b JS |
78 | #define wxID_RICHTEXT_PROPERTIES1 (wxID_HIGHEST + 1) |
79 | #define wxID_RICHTEXT_PROPERTIES2 (wxID_HIGHEST + 2) | |
80 | #define wxID_RICHTEXT_PROPERTIES3 (wxID_HIGHEST + 3) | |
5d7836c4 JS |
81 | |
82 | /*! | |
603f702b | 83 | * Forward declarations |
5d7836c4 JS |
84 | */ |
85 | ||
603f702b | 86 | #if 0 |
5d7836c4 JS |
87 | // Drawing styles/states |
88 | #define wxRICHTEXT_SELECTED 0x01 | |
89 | #define wxRICHTEXT_TAGGED 0x02 | |
90 | // The control is focussed | |
91 | #define wxRICHTEXT_FOCUSSED 0x04 | |
92 | // The item itself has the focus | |
93 | #define wxRICHTEXT_IS_FOCUS 0x08 | |
603f702b JS |
94 | #endif |
95 | ||
96 | // Normal selection occurs initially and as user drags within one container. | |
97 | // Common ancestor selection occurs when the user starts dragging across containers | |
98 | // that have a common ancestor, for example the cells in a table. | |
99 | enum wxRichTextCtrlSelectionState | |
100 | { | |
101 | wxRichTextCtrlSelectionState_Normal, | |
102 | wxRichTextCtrlSelectionState_CommonAncestor | |
103 | }; | |
104 | ||
105 | /*! | |
106 | * wxRichTextContextMenuPropertiesInfo keeps track of objects that appear in the context menu, | |
107 | * whose properties are available to be edited. | |
108 | */ | |
109 | ||
110 | class WXDLLIMPEXP_RICHTEXT wxRichTextContextMenuPropertiesInfo | |
111 | { | |
112 | public: | |
113 | wxRichTextContextMenuPropertiesInfo() { Init(); } | |
114 | ||
115 | // Operations | |
116 | ||
117 | /// Initialisation | |
118 | void Init() {} | |
119 | ||
120 | /// Add an item | |
121 | bool AddItem(const wxString& label, wxRichTextObject* obj); | |
122 | ||
123 | /// Returns number of menu items were added. | |
124 | int AddMenuItems(wxMenu* menu, int startCmd = wxID_RICHTEXT_PROPERTIES1) const; | |
125 | ||
126 | /// Add appropriate menu items for the current container and clicked on object | |
127 | /// (and container's parent, if appropriate). | |
128 | int AddItems(wxRichTextObject* container, wxRichTextObject* obj); | |
129 | ||
130 | /// Clear the items | |
131 | void Clear() { m_objects.Clear(); m_labels.Clear(); } | |
132 | ||
133 | // Accessors | |
134 | /// Gets the nth label | |
135 | wxString GetLabel(int n) const { return m_labels[n]; } | |
136 | ||
137 | /// Gets the nth object | |
138 | wxRichTextObject* GetObject(int n) const { return m_objects[n]; } | |
139 | ||
140 | /// Get objects | |
141 | wxRichTextObjectPtrArray& GetObjects() { return m_objects; } | |
142 | const wxRichTextObjectPtrArray& GetObjects() const { return m_objects; } | |
143 | ||
144 | /// Get labels | |
145 | wxArrayString& GetLabels() { return m_labels; } | |
146 | const wxArrayString& GetLabels() const { return m_labels; } | |
147 | ||
148 | /// Get number of items | |
149 | int GetCount() const { return m_objects.GetCount(); } | |
150 | ||
151 | //wxArrayInt m_ids; | |
152 | wxRichTextObjectPtrArray m_objects; | |
153 | wxArrayString m_labels; | |
154 | }; | |
5d7836c4 JS |
155 | |
156 | /*! | |
157 | * wxRichTextCtrl class declaration | |
158 | */ | |
159 | ||
24777478 JS |
160 | class WXDLLIMPEXP_RICHTEXT wxRichTextCtrl : public wxControl, |
161 | public wxTextCtrlIface, | |
343ae70d | 162 | public wxScrollHelper |
7fe8059f | 163 | { |
5d7836c4 JS |
164 | DECLARE_CLASS( wxRichTextCtrl ) |
165 | DECLARE_EVENT_TABLE() | |
166 | ||
167 | public: | |
168 | // Constructors | |
169 | ||
170 | wxRichTextCtrl( ); | |
27e20452 | 171 | wxRichTextCtrl( wxWindow* parent, wxWindowID id = -1, const wxString& value = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, |
4e8d9558 JS |
172 | long style = wxRE_MULTILINE, const wxValidator& validator = wxDefaultValidator, const wxString& name = wxTextCtrlNameStr); |
173 | ||
d3c7fc99 | 174 | virtual ~wxRichTextCtrl( ); |
5d7836c4 JS |
175 | |
176 | // Operations | |
177 | ||
178 | /// Creation | |
27e20452 | 179 | bool Create( wxWindow* parent, wxWindowID id = -1, const wxString& value = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, |
4e8d9558 | 180 | long style = wxRE_MULTILINE, const wxValidator& validator = wxDefaultValidator, const wxString& name = wxTextCtrlNameStr ); |
5d7836c4 JS |
181 | |
182 | /// Member initialisation | |
183 | void Init(); | |
184 | ||
185 | ///// wxTextCtrl compatibility | |
186 | ||
187 | // Accessors | |
188 | ||
5d7836c4 JS |
189 | virtual wxString GetRange(long from, long to) const; |
190 | ||
191 | virtual int GetLineLength(long lineNo) const ; | |
192 | virtual wxString GetLineText(long lineNo) const ; | |
193 | virtual int GetNumberOfLines() const ; | |
194 | ||
195 | virtual bool IsModified() const ; | |
196 | virtual bool IsEditable() const ; | |
197 | ||
198 | // more readable flag testing methods | |
199 | bool IsSingleLine() const { return !HasFlag(wxRE_MULTILINE); } | |
200 | bool IsMultiLine() const { return !IsSingleLine(); } | |
201 | ||
202 | // If the return values from and to are the same, there is no selection. | |
203 | virtual void GetSelection(long* from, long* to) const; | |
204 | ||
205 | virtual wxString GetStringSelection() const; | |
603f702b JS |
206 | |
207 | const wxRichTextSelection& GetSelection() const { return m_selection; } | |
208 | wxRichTextSelection& GetSelection() { return m_selection; } | |
209 | void SetSelection(const wxRichTextSelection& sel) { m_selection = sel; } | |
210 | ||
5d7836c4 JS |
211 | |
212 | /// Get filename | |
213 | wxString GetFilename() const { return m_filename; } | |
214 | ||
215 | /// Set filename | |
216 | void SetFilename(const wxString& filename) { m_filename = filename; } | |
217 | ||
4d551ad5 JS |
218 | /// Set the threshold in character positions for doing layout optimization during sizing |
219 | void SetDelayedLayoutThreshold(long threshold) { m_delayedLayoutThreshold = threshold; } | |
220 | ||
221 | /// Get the threshold in character positions for doing layout optimization during sizing | |
222 | long GetDelayedLayoutThreshold() const { return m_delayedLayoutThreshold; } | |
223 | ||
c2a4fabb JS |
224 | /// Set text cursor |
225 | void SetTextCursor(const wxCursor& cursor ) { m_textCursor = cursor; } | |
226 | ||
227 | /// Get text cursor | |
228 | wxCursor GetTextCursor() const { return m_textCursor; } | |
229 | ||
230 | /// Set URL cursor | |
231 | void SetURLCursor(const wxCursor& cursor ) { m_urlCursor = cursor; } | |
232 | ||
233 | /// Get URL cursor | |
234 | wxCursor GetURLCursor() const { return m_urlCursor; } | |
235 | ||
2f0baf97 JS |
236 | /// Are we showing the caret position at the start of a line |
237 | /// instead of at the end of the previous one? | |
238 | bool GetCaretAtLineStart() const { return m_caretAtLineStart; } | |
239 | void SetCaretAtLineStart(bool atStart) { m_caretAtLineStart = atStart; } | |
240 | ||
241 | /// Are we dragging a selection? | |
242 | bool GetDragging() const { return m_dragging; } | |
243 | void SetDragging(bool dragging) { m_dragging = dragging; } | |
244 | ||
245 | /// Get/set drag start position | |
246 | const wxPoint& GetDragStart() const { return m_dragStart; } | |
247 | void SetDragStart(const wxPoint& pt) { m_dragStart = pt; } | |
248 | ||
c631741b | 249 | #if wxRICHTEXT_BUFFERED_PAINTING |
2f0baf97 JS |
250 | /// Get the buffer bitmap |
251 | const wxBitmap& GetBufferBitmap() const { return m_bufferBitmap; } | |
252 | wxBitmap& GetBufferBitmap() { return m_bufferBitmap; } | |
c631741b | 253 | #endif |
2f0baf97 JS |
254 | |
255 | /// Get/set context menu | |
256 | wxMenu* GetContextMenu() const { return m_contextMenu; } | |
8e43fc77 | 257 | void SetContextMenu(wxMenu* menu); |
2f0baf97 JS |
258 | |
259 | /// Anchor so we know how to extend the selection | |
260 | /// It's a caret position since it's between two characters. | |
261 | long GetSelectionAnchor() const { return m_selectionAnchor; } | |
262 | void SetSelectionAnchor(long anchor) { m_selectionAnchor = anchor; } | |
263 | ||
603f702b JS |
264 | /// Anchor object if selecting multiple containers. |
265 | wxRichTextObject* GetSelectionAnchorObject() const { return m_selectionAnchorObject; } | |
266 | void SetSelectionAnchorObject(wxRichTextObject* anchor) { m_selectionAnchorObject = anchor; } | |
267 | ||
268 | wxRichTextContextMenuPropertiesInfo& GetContextMenuPropertiesInfo() { return m_contextMenuPropertiesInfo; } | |
269 | const wxRichTextContextMenuPropertiesInfo& GetContextMenuPropertiesInfo() const { return m_contextMenuPropertiesInfo; } | |
270 | ||
271 | /// The wxRichTextObject object that currently has the editing focus | |
272 | wxRichTextParagraphLayoutBox* GetFocusObject() const { return m_focusObject; } | |
273 | bool SetFocusObject(wxRichTextParagraphLayoutBox* obj, bool setCaretPosition = true); | |
cdaed652 | 274 | |
5d7836c4 JS |
275 | // Operations |
276 | ||
603f702b JS |
277 | void Invalidate() { GetBuffer().Invalidate(wxRICHTEXT_ALL); } |
278 | ||
5d7836c4 JS |
279 | // editing |
280 | virtual void Clear(); | |
281 | virtual void Replace(long from, long to, const wxString& value); | |
282 | virtual void Remove(long from, long to); | |
283 | ||
284 | // load/save the controls contents from/to the file | |
3306aec1 | 285 | virtual bool DoLoadFile(const wxString& file, int fileType); |
d75a69e8 FM |
286 | virtual bool DoSaveFile(const wxString& file = wxEmptyString, |
287 | int fileType = wxRICHTEXT_TYPE_ANY); | |
5d7836c4 | 288 | |
d2d0adc7 JS |
289 | /// Set the handler flags, controlling loading and saving |
290 | void SetHandlerFlags(int flags) { GetBuffer().SetHandlerFlags(flags); } | |
291 | ||
292 | /// Get the handler flags, controlling loading and saving | |
293 | int GetHandlerFlags() const { return GetBuffer().GetHandlerFlags(); } | |
294 | ||
5d7836c4 JS |
295 | // sets/clears the dirty flag |
296 | virtual void MarkDirty(); | |
297 | virtual void DiscardEdits(); | |
298 | ||
299 | // set the max number of characters which may be entered in a single line | |
300 | // text control | |
301 | virtual void SetMaxLength(unsigned long WXUNUSED(len)) { } | |
302 | ||
303 | // writing text inserts it at the current position, appending always | |
304 | // inserts it at the end | |
305 | virtual void WriteText(const wxString& text); | |
306 | virtual void AppendText(const wxString& text); | |
307 | ||
308 | // text control under some platforms supports the text styles: these | |
309 | // methods allow to apply the given text style to the given selection or to | |
310 | // set/get the style which will be used for all appended text | |
27e20452 | 311 | virtual bool SetStyle(long start, long end, const wxTextAttr& style); |
24777478 | 312 | virtual bool SetStyle(long start, long end, const wxRichTextAttr& style); |
44cc96a8 | 313 | virtual bool SetStyle(const wxRichTextRange& range, const wxTextAttr& style); |
24777478 | 314 | virtual bool SetStyle(const wxRichTextRange& range, const wxRichTextAttr& style); |
3966a9f4 | 315 | virtual bool GetStyle(long position, wxTextAttr& style); |
24777478 | 316 | virtual bool GetStyle(long position, wxRichTextAttr& style); |
603f702b | 317 | virtual bool GetStyle(long position, wxRichTextAttr& style, wxRichTextParagraphLayoutBox* container); |
fe5aa22c | 318 | |
603f702b JS |
319 | // Set the style for a single object |
320 | virtual void SetStyle(wxRichTextObject *obj, const wxRichTextAttr& textAttr); | |
cdaed652 | 321 | |
a7ed48a5 | 322 | // get the common set of styles for the range |
44cc96a8 | 323 | virtual bool GetStyleForRange(const wxRichTextRange& range, wxTextAttr& style); |
24777478 | 324 | virtual bool GetStyleForRange(const wxRichTextRange& range, wxRichTextAttr& style); |
603f702b | 325 | virtual bool GetStyleForRange(const wxRichTextRange& range, wxRichTextAttr& style, wxRichTextParagraphLayoutBox* container); |
3e3a754f JS |
326 | // extended style setting operation with flags including: |
327 | // wxRICHTEXT_SETSTYLE_WITH_UNDO, wxRICHTEXT_SETSTYLE_OPTIMIZE, wxRICHTEXT_SETSTYLE_PARAGRAPHS_ONLY, wxRICHTEXT_SETSTYLE_CHARACTERS_ONLY | |
328 | // see richtextbuffer.h for more details. | |
24777478 | 329 | virtual bool SetStyleEx(const wxRichTextRange& range, const wxRichTextAttr& style, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO); |
3e3a754f | 330 | |
fe5aa22c | 331 | /// Get the content (uncombined) attributes for this position. |
24777478 | 332 | virtual bool GetUncombinedStyle(long position, wxRichTextAttr& style); |
603f702b | 333 | virtual bool GetUncombinedStyle(long position, wxRichTextAttr& style, wxRichTextParagraphLayoutBox* container); |
fe5aa22c | 334 | |
27e20452 | 335 | virtual bool SetDefaultStyle(const wxTextAttr& style); |
24777478 | 336 | virtual bool SetDefaultStyle(const wxRichTextAttr& style); |
5d7836c4 | 337 | |
24777478 | 338 | virtual const wxRichTextAttr& GetDefaultStyleEx() const; |
44cc96a8 | 339 | |
24777478 | 340 | //virtual const wxTextAttr& GetDefaultStyle() const; |
5d7836c4 | 341 | |
38f833b1 JS |
342 | /// Set list style |
343 | virtual bool SetListStyle(const wxRichTextRange& range, wxRichTextListStyleDefinition* def, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int startFrom = 1, int specifiedLevel = -1); | |
344 | virtual bool SetListStyle(const wxRichTextRange& range, const wxString& defName, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int startFrom = 1, int specifiedLevel = -1); | |
345 | ||
346 | /// Clear list for given range | |
347 | virtual bool ClearListStyle(const wxRichTextRange& range, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO); | |
348 | ||
349 | /// Number/renumber any list elements in the given range | |
350 | /// def/defName can be NULL/empty to indicate that the existing list style should be used. | |
dadd4f55 | 351 | virtual bool NumberList(const wxRichTextRange& range, wxRichTextListStyleDefinition* def = NULL, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int startFrom = 1, int specifiedLevel = -1); |
38f833b1 JS |
352 | virtual bool NumberList(const wxRichTextRange& range, const wxString& defName, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int startFrom = 1, int specifiedLevel = -1); |
353 | ||
354 | /// Promote the list items within the given range. promoteBy can be a positive or negative number, e.g. 1 or -1 | |
355 | /// def/defName can be NULL/empty to indicate that the existing list style should be used. | |
dadd4f55 | 356 | virtual bool PromoteList(int promoteBy, const wxRichTextRange& range, wxRichTextListStyleDefinition* def = NULL, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int specifiedLevel = -1); |
38f833b1 JS |
357 | virtual bool PromoteList(int promoteBy, const wxRichTextRange& range, const wxString& defName, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int specifiedLevel = -1); |
358 | ||
12cc29c5 JS |
359 | /// Deletes the content in the given range |
360 | virtual bool Delete(const wxRichTextRange& range); | |
361 | ||
5d7836c4 JS |
362 | // translate between the position (which is just an index in the text ctrl |
363 | // considering all its contents as a single strings) and (x, y) coordinates | |
364 | // which represent column and line. | |
365 | virtual long XYToPosition(long x, long y) const; | |
366 | virtual bool PositionToXY(long pos, long *x, long *y) const; | |
367 | ||
368 | virtual void ShowPosition(long pos); | |
369 | ||
370 | // find the character at position given in pixels | |
371 | // | |
372 | // NB: pt is in device coords (not adjusted for the client area origin nor | |
373 | // scrolling) | |
374 | virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt, long *pos) const; | |
375 | virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt, | |
376 | wxTextCoord *col, | |
377 | wxTextCoord *row) const; | |
378 | ||
379 | // Clipboard operations | |
380 | virtual void Copy(); | |
381 | virtual void Cut(); | |
382 | virtual void Paste(); | |
383 | virtual void DeleteSelection(); | |
384 | ||
385 | virtual bool CanCopy() const; | |
386 | virtual bool CanCut() const; | |
387 | virtual bool CanPaste() const; | |
388 | virtual bool CanDeleteSelection() const; | |
389 | ||
390 | // Undo/redo | |
391 | virtual void Undo(); | |
392 | virtual void Redo(); | |
393 | ||
394 | virtual bool CanUndo() const; | |
395 | virtual bool CanRedo() const; | |
396 | ||
397 | // Insertion point | |
398 | virtual void SetInsertionPoint(long pos); | |
399 | virtual void SetInsertionPointEnd(); | |
400 | virtual long GetInsertionPoint() const; | |
401 | virtual wxTextPos GetLastPosition() const; | |
402 | ||
403 | virtual void SetSelection(long from, long to); | |
404 | virtual void SelectAll(); | |
405 | virtual void SetEditable(bool editable); | |
406 | ||
603f702b JS |
407 | /// Returns true if there was a selection and the object containing the selection |
408 | /// was the same as the current focus object. | |
5d7836c4 JS |
409 | virtual bool HasSelection() const; |
410 | ||
603f702b JS |
411 | /// Returns true if there was a selection, whether or not the current focus object |
412 | /// is the same as the selection's container object. | |
413 | virtual bool HasUnfocusedSelection() const; | |
414 | ||
5d7836c4 JS |
415 | ///// Functionality specific to wxRichTextCtrl |
416 | ||
417 | /// Write an image at the current insertion point. Supply optional type to use | |
418 | /// for internal and file storage of the raw data. | |
24777478 JS |
419 | virtual bool WriteImage(const wxImage& image, wxBitmapType bitmapType = wxBITMAP_TYPE_PNG, |
420 | const wxRichTextAttr& textAttr = wxRichTextAttr()); | |
5d7836c4 JS |
421 | |
422 | /// Write a bitmap at the current insertion point. Supply optional type to use | |
423 | /// for internal and file storage of the raw data. | |
24777478 JS |
424 | virtual bool WriteImage(const wxBitmap& bitmap, wxBitmapType bitmapType = wxBITMAP_TYPE_PNG, |
425 | const wxRichTextAttr& textAttr = wxRichTextAttr()); | |
5d7836c4 JS |
426 | |
427 | /// Load an image from file and write at the current insertion point. | |
24777478 JS |
428 | virtual bool WriteImage(const wxString& filename, wxBitmapType bitmapType, |
429 | const wxRichTextAttr& textAttr = wxRichTextAttr()); | |
5d7836c4 JS |
430 | |
431 | /// Write an image block at the current insertion point. | |
24777478 JS |
432 | virtual bool WriteImage(const wxRichTextImageBlock& imageBlock, |
433 | const wxRichTextAttr& textAttr = wxRichTextAttr()); | |
5d7836c4 | 434 | |
603f702b JS |
435 | /// Write a text box at the current insertion point, returning the text box. |
436 | /// You can then call SetFocusObject() to set the focus to the new object. | |
437 | virtual wxRichTextBox* WriteTextBox(const wxRichTextAttr& textAttr = wxRichTextAttr()); | |
438 | ||
439 | /// Write a table at the current insertion point, returning the table. | |
440 | /// You can then call SetFocusObject() to set the focus to the new object. | |
441 | virtual wxRichTextTable* WriteTable(int rows, int cols, const wxRichTextAttr& tableAttr = wxRichTextAttr(), const wxRichTextAttr& cellAttr = wxRichTextAttr()); | |
442 | ||
5d7836c4 JS |
443 | /// Insert a newline (actually paragraph) at the current insertion point. |
444 | virtual bool Newline(); | |
445 | ||
ff76711f JS |
446 | /// Insert a line break at the current insertion point. |
447 | virtual bool LineBreak(); | |
448 | ||
5d7836c4 | 449 | /// Set basic (overall) style |
24777478 | 450 | virtual void SetBasicStyle(const wxRichTextAttr& style) { GetBuffer().SetBasicStyle(style); } |
5d7836c4 JS |
451 | |
452 | /// Get basic (overall) style | |
24777478 | 453 | virtual const wxRichTextAttr& GetBasicStyle() const { return GetBuffer().GetBasicStyle(); } |
5d7836c4 | 454 | |
24777478 | 455 | virtual bool BeginStyle(const wxRichTextAttr& style) { return GetBuffer().BeginStyle(style); } |
5d7836c4 JS |
456 | |
457 | /// End the style | |
458 | virtual bool EndStyle() { return GetBuffer().EndStyle(); } | |
459 | ||
460 | /// End all styles | |
461 | virtual bool EndAllStyles() { return GetBuffer().EndAllStyles(); } | |
462 | ||
463 | /// Begin using bold | |
464 | bool BeginBold() { return GetBuffer().BeginBold(); } | |
465 | ||
466 | /// End using bold | |
467 | bool EndBold() { return GetBuffer().EndBold(); } | |
468 | ||
469 | /// Begin using italic | |
470 | bool BeginItalic() { return GetBuffer().BeginItalic(); } | |
471 | ||
472 | /// End using italic | |
473 | bool EndItalic() { return GetBuffer().EndItalic(); } | |
474 | ||
475 | /// Begin using underline | |
476 | bool BeginUnderline() { return GetBuffer().BeginUnderline(); } | |
477 | ||
478 | /// End using underline | |
479 | bool EndUnderline() { return GetBuffer().EndUnderline(); } | |
480 | ||
481 | /// Begin using point size | |
482 | bool BeginFontSize(int pointSize) { return GetBuffer().BeginFontSize(pointSize); } | |
483 | ||
484 | /// End using point size | |
485 | bool EndFontSize() { return GetBuffer().EndFontSize(); } | |
486 | ||
487 | /// Begin using this font | |
488 | bool BeginFont(const wxFont& font) { return GetBuffer().BeginFont(font); } | |
489 | ||
490 | /// End using a font | |
491 | bool EndFont() { return GetBuffer().EndFont(); } | |
492 | ||
493 | /// Begin using this colour | |
494 | bool BeginTextColour(const wxColour& colour) { return GetBuffer().BeginTextColour(colour); } | |
495 | ||
496 | /// End using a colour | |
497 | bool EndTextColour() { return GetBuffer().EndTextColour(); } | |
498 | ||
499 | /// Begin using alignment | |
500 | bool BeginAlignment(wxTextAttrAlignment alignment) { return GetBuffer().BeginAlignment(alignment); } | |
501 | ||
502 | /// End alignment | |
503 | bool EndAlignment() { return GetBuffer().EndAlignment(); } | |
504 | ||
505 | /// Begin left indent | |
506 | bool BeginLeftIndent(int leftIndent, int leftSubIndent = 0) { return GetBuffer().BeginLeftIndent(leftIndent, leftSubIndent); } | |
507 | ||
508 | /// End left indent | |
509 | bool EndLeftIndent() { return GetBuffer().EndLeftIndent(); } | |
510 | ||
511 | /// Begin right indent | |
512 | bool BeginRightIndent(int rightIndent) { return GetBuffer().BeginRightIndent(rightIndent); } | |
513 | ||
514 | /// End right indent | |
515 | bool EndRightIndent() { return GetBuffer().EndRightIndent(); } | |
516 | ||
517 | /// Begin paragraph spacing | |
518 | bool BeginParagraphSpacing(int before, int after) { return GetBuffer().BeginParagraphSpacing(before, after); } | |
519 | ||
520 | /// End paragraph spacing | |
521 | bool EndParagraphSpacing() { return GetBuffer().EndParagraphSpacing(); } | |
522 | ||
523 | /// Begin line spacing | |
524 | bool BeginLineSpacing(int lineSpacing) { return GetBuffer().BeginLineSpacing(lineSpacing); } | |
525 | ||
526 | /// End line spacing | |
527 | bool EndLineSpacing() { return GetBuffer().EndLineSpacing(); } | |
528 | ||
529 | /// Begin numbered bullet | |
530 | bool BeginNumberedBullet(int bulletNumber, int leftIndent, int leftSubIndent, int bulletStyle = wxTEXT_ATTR_BULLET_STYLE_ARABIC|wxTEXT_ATTR_BULLET_STYLE_PERIOD) | |
531 | { return GetBuffer().BeginNumberedBullet(bulletNumber, leftIndent, leftSubIndent, bulletStyle); } | |
532 | ||
533 | /// End numbered bullet | |
534 | bool EndNumberedBullet() { return GetBuffer().EndNumberedBullet(); } | |
535 | ||
536 | /// Begin symbol bullet | |
d2d0adc7 | 537 | bool BeginSymbolBullet(const wxString& symbol, int leftIndent, int leftSubIndent, int bulletStyle = wxTEXT_ATTR_BULLET_STYLE_SYMBOL) |
5d7836c4 JS |
538 | { return GetBuffer().BeginSymbolBullet(symbol, leftIndent, leftSubIndent, bulletStyle); } |
539 | ||
540 | /// End symbol bullet | |
541 | bool EndSymbolBullet() { return GetBuffer().EndSymbolBullet(); } | |
542 | ||
f089713f JS |
543 | /// Begin standard bullet |
544 | bool BeginStandardBullet(const wxString& bulletName, int leftIndent, int leftSubIndent, int bulletStyle = wxTEXT_ATTR_BULLET_STYLE_STANDARD) | |
545 | { return GetBuffer().BeginStandardBullet(bulletName, leftIndent, leftSubIndent, bulletStyle); } | |
546 | ||
547 | /// End standard bullet | |
548 | bool EndStandardBullet() { return GetBuffer().EndStandardBullet(); } | |
549 | ||
5d7836c4 JS |
550 | /// Begin named character style |
551 | bool BeginCharacterStyle(const wxString& characterStyle) { return GetBuffer().BeginCharacterStyle(characterStyle); } | |
552 | ||
553 | /// End named character style | |
554 | bool EndCharacterStyle() { return GetBuffer().EndCharacterStyle(); } | |
555 | ||
556 | /// Begin named paragraph style | |
557 | bool BeginParagraphStyle(const wxString& paragraphStyle) { return GetBuffer().BeginParagraphStyle(paragraphStyle); } | |
558 | ||
559 | /// End named character style | |
560 | bool EndParagraphStyle() { return GetBuffer().EndParagraphStyle(); } | |
561 | ||
f089713f JS |
562 | /// Begin named list style |
563 | bool BeginListStyle(const wxString& listStyle, int level = 1, int number = 1) { return GetBuffer().BeginListStyle(listStyle, level, number); } | |
564 | ||
565 | /// End named character style | |
566 | bool EndListStyle() { return GetBuffer().EndListStyle(); } | |
567 | ||
d2d0adc7 JS |
568 | /// Begin URL |
569 | bool BeginURL(const wxString& url, const wxString& characterStyle = wxEmptyString) { return GetBuffer().BeginURL(url, characterStyle); } | |
570 | ||
571 | /// End URL | |
572 | bool EndURL() { return GetBuffer().EndURL(); } | |
573 | ||
5d7836c4 JS |
574 | /// Sets the default style to the style under the cursor |
575 | bool SetDefaultStyleToCursorStyle(); | |
576 | ||
577 | /// Clear the selection | |
578 | virtual void SelectNone(); | |
579 | ||
0ca07313 JS |
580 | /// Select the word at the given character position |
581 | virtual bool SelectWord(long position); | |
582 | ||
5d7836c4 | 583 | /// Get/set the selection range in character positions. -1, -1 means no selection. |
96c9f0f6 JS |
584 | /// The range is in API convention, i.e. a single character selection is denoted |
585 | /// by (n, n+1) | |
586 | wxRichTextRange GetSelectionRange() const; | |
587 | void SetSelectionRange(const wxRichTextRange& range); | |
588 | ||
603f702b JS |
589 | /// Get/set the selection range in character positions. -2, -2 means no selection |
590 | /// -1, -1 means select everything. | |
96c9f0f6 JS |
591 | /// The range is in internal format, i.e. a single character selection is denoted |
592 | /// by (n, n) | |
603f702b JS |
593 | wxRichTextRange GetInternalSelectionRange() const { return m_selection.GetRange(); } |
594 | void SetInternalSelectionRange(const wxRichTextRange& range) { m_selection.Set(range, GetFocusObject()); } | |
5d7836c4 JS |
595 | |
596 | /// Add a new paragraph of text to the end of the buffer | |
597 | virtual wxRichTextRange AddParagraph(const wxString& text); | |
598 | ||
599 | /// Add an image | |
600 | virtual wxRichTextRange AddImage(const wxImage& image); | |
601 | ||
602 | /// Layout the buffer: which we must do before certain operations, such as | |
603 | /// setting the caret position. | |
2f36e8dc | 604 | virtual bool LayoutContent(bool onlyVisibleRect = false); |
5d7836c4 JS |
605 | |
606 | /// Move the caret to the given character position | |
603f702b | 607 | virtual bool MoveCaret(long pos, bool showAtLineStart = false, wxRichTextParagraphLayoutBox* container = NULL); |
5d7836c4 JS |
608 | |
609 | /// Move right | |
610 | virtual bool MoveRight(int noPositions = 1, int flags = 0); | |
611 | ||
612 | /// Move left | |
613 | virtual bool MoveLeft(int noPositions = 1, int flags = 0); | |
614 | ||
615 | /// Move up | |
616 | virtual bool MoveUp(int noLines = 1, int flags = 0); | |
617 | ||
618 | /// Move up | |
619 | virtual bool MoveDown(int noLines = 1, int flags = 0); | |
620 | ||
621 | /// Move to the end of the line | |
622 | virtual bool MoveToLineEnd(int flags = 0); | |
623 | ||
624 | /// Move to the start of the line | |
625 | virtual bool MoveToLineStart(int flags = 0); | |
626 | ||
627 | /// Move to the end of the paragraph | |
628 | virtual bool MoveToParagraphEnd(int flags = 0); | |
629 | ||
630 | /// Move to the start of the paragraph | |
631 | virtual bool MoveToParagraphStart(int flags = 0); | |
632 | ||
633 | /// Move to the start of the buffer | |
634 | virtual bool MoveHome(int flags = 0); | |
635 | ||
636 | /// Move to the end of the buffer | |
637 | virtual bool MoveEnd(int flags = 0); | |
638 | ||
639 | /// Move n pages up | |
640 | virtual bool PageUp(int noPages = 1, int flags = 0); | |
641 | ||
642 | /// Move n pages down | |
643 | virtual bool PageDown(int noPages = 1, int flags = 0); | |
644 | ||
645 | /// Move n words left | |
646 | virtual bool WordLeft(int noPages = 1, int flags = 0); | |
647 | ||
648 | /// Move n words right | |
649 | virtual bool WordRight(int noPages = 1, int flags = 0); | |
650 | ||
651 | /// Returns the buffer associated with the control. | |
652 | wxRichTextBuffer& GetBuffer() { return m_buffer; } | |
653 | const wxRichTextBuffer& GetBuffer() const { return m_buffer; } | |
654 | ||
655 | /// Start batching undo history for commands. | |
656 | virtual bool BeginBatchUndo(const wxString& cmdName) { return m_buffer.BeginBatchUndo(cmdName); } | |
657 | ||
658 | /// End batching undo history for commands. | |
659 | virtual bool EndBatchUndo() { return m_buffer.EndBatchUndo(); } | |
660 | ||
661 | /// Are we batching undo history for commands? | |
662 | virtual bool BatchingUndo() const { return m_buffer.BatchingUndo(); } | |
663 | ||
664 | /// Start suppressing undo history for commands. | |
665 | virtual bool BeginSuppressUndo() { return m_buffer.BeginSuppressUndo(); } | |
666 | ||
667 | /// End suppressing undo history for commands. | |
668 | virtual bool EndSuppressUndo() { return m_buffer.EndSuppressUndo(); } | |
669 | ||
670 | /// Are we suppressing undo history for commands? | |
671 | virtual bool SuppressingUndo() const { return m_buffer.SuppressingUndo(); } | |
672 | ||
673 | /// Test if this whole range has character attributes of the specified kind. If any | |
674 | /// of the attributes are different within the range, the test fails. You | |
675 | /// can use this to implement, for example, bold button updating. style must have | |
676 | /// flags indicating which attributes are of interest. | |
24777478 | 677 | virtual bool HasCharacterAttributes(const wxRichTextRange& range, const wxRichTextAttr& style) const |
5d7836c4 | 678 | { |
a7ed48a5 | 679 | return GetBuffer().HasCharacterAttributes(range.ToInternal(), style); |
5d7836c4 JS |
680 | } |
681 | ||
682 | /// Test if this whole range has paragraph attributes of the specified kind. If any | |
683 | /// of the attributes are different within the range, the test fails. You | |
684 | /// can use this to implement, for example, centering button updating. style must have | |
685 | /// flags indicating which attributes are of interest. | |
24777478 | 686 | virtual bool HasParagraphAttributes(const wxRichTextRange& range, const wxRichTextAttr& style) const |
5d7836c4 | 687 | { |
a7ed48a5 | 688 | return GetBuffer().HasParagraphAttributes(range.ToInternal(), style); |
5d7836c4 JS |
689 | } |
690 | ||
691 | /// Is all of the selection bold? | |
3966a9f4 | 692 | virtual bool IsSelectionBold(); |
5d7836c4 JS |
693 | |
694 | /// Is all of the selection italics? | |
3966a9f4 | 695 | virtual bool IsSelectionItalics(); |
5d7836c4 JS |
696 | |
697 | /// Is all of the selection underlined? | |
3966a9f4 | 698 | virtual bool IsSelectionUnderlined(); |
5d7836c4 JS |
699 | |
700 | /// Is all of the selection aligned according to the specified flag? | |
3966a9f4 | 701 | virtual bool IsSelectionAligned(wxTextAttrAlignment alignment); |
5d7836c4 JS |
702 | |
703 | /// Apply bold to the selection | |
704 | virtual bool ApplyBoldToSelection(); | |
705 | ||
706 | /// Apply italic to the selection | |
707 | virtual bool ApplyItalicToSelection(); | |
708 | ||
709 | /// Apply underline to the selection | |
710 | virtual bool ApplyUnderlineToSelection(); | |
711 | ||
712 | /// Apply alignment to the selection | |
713 | virtual bool ApplyAlignmentToSelection(wxTextAttrAlignment alignment); | |
714 | ||
ab14c7aa | 715 | /// Apply a named style to the selection |
1807a1f3 | 716 | virtual bool ApplyStyle(wxRichTextStyleDefinition* def); |
ab14c7aa | 717 | |
38f833b1 | 718 | /// Set style sheet, if any |
5d7836c4 JS |
719 | void SetStyleSheet(wxRichTextStyleSheet* styleSheet) { GetBuffer().SetStyleSheet(styleSheet); } |
720 | wxRichTextStyleSheet* GetStyleSheet() const { return GetBuffer().GetStyleSheet(); } | |
721 | ||
38f833b1 JS |
722 | /// Push style sheet to top of stack |
723 | bool PushStyleSheet(wxRichTextStyleSheet* styleSheet) { return GetBuffer().PushStyleSheet(styleSheet); } | |
724 | ||
725 | /// Pop style sheet from top of stack | |
726 | wxRichTextStyleSheet* PopStyleSheet() { return GetBuffer().PopStyleSheet(); } | |
727 | ||
fe5aa22c JS |
728 | /// Apply the style sheet to the buffer, for example if the styles have changed. |
729 | bool ApplyStyleSheet(wxRichTextStyleSheet* styleSheet = NULL); | |
730 | ||
5d7836c4 JS |
731 | // Command handlers |
732 | ||
c9f3a6a8 | 733 | void Command(wxCommandEvent& event); |
5d7836c4 | 734 | void OnDropFiles(wxDropFilesEvent& event); |
61f84e24 | 735 | void OnCaptureLost(wxMouseCaptureLostEvent& event); |
52170c5b | 736 | void OnSysColourChanged(wxSysColourChangedEvent& event); |
5d7836c4 JS |
737 | |
738 | void OnCut(wxCommandEvent& event); | |
739 | void OnCopy(wxCommandEvent& event); | |
740 | void OnPaste(wxCommandEvent& event); | |
741 | void OnUndo(wxCommandEvent& event); | |
742 | void OnRedo(wxCommandEvent& event); | |
743 | void OnSelectAll(wxCommandEvent& event); | |
603f702b | 744 | void OnProperties(wxCommandEvent& event); |
5d7836c4 JS |
745 | void OnClear(wxCommandEvent& event); |
746 | ||
747 | void OnUpdateCut(wxUpdateUIEvent& event); | |
748 | void OnUpdateCopy(wxUpdateUIEvent& event); | |
749 | void OnUpdatePaste(wxUpdateUIEvent& event); | |
750 | void OnUpdateUndo(wxUpdateUIEvent& event); | |
751 | void OnUpdateRedo(wxUpdateUIEvent& event); | |
752 | void OnUpdateSelectAll(wxUpdateUIEvent& event); | |
603f702b | 753 | void OnUpdateProperties(wxUpdateUIEvent& event); |
5d7836c4 JS |
754 | void OnUpdateClear(wxUpdateUIEvent& event); |
755 | ||
756 | // Show a context menu for Rich Edit controls (the standard | |
757 | // EDIT control has one already) | |
758 | void OnContextMenu(wxContextMenuEvent& event); | |
7fe8059f | 759 | |
5d7836c4 JS |
760 | // Event handlers |
761 | ||
762 | /// Painting | |
763 | void OnPaint(wxPaintEvent& event); | |
764 | void OnEraseBackground(wxEraseEvent& event); | |
765 | ||
766 | /// Left-click | |
767 | void OnLeftClick(wxMouseEvent& event); | |
768 | ||
769 | /// Left-up | |
770 | void OnLeftUp(wxMouseEvent& event); | |
771 | ||
772 | /// Motion | |
773 | void OnMoveMouse(wxMouseEvent& event); | |
774 | ||
775 | /// Left-double-click | |
776 | void OnLeftDClick(wxMouseEvent& event); | |
777 | ||
778 | /// Middle-click | |
779 | void OnMiddleClick(wxMouseEvent& event); | |
780 | ||
781 | /// Right-click | |
782 | void OnRightClick(wxMouseEvent& event); | |
783 | ||
784 | /// Key press | |
785 | void OnChar(wxKeyEvent& event); | |
786 | ||
787 | /// Sizing | |
788 | void OnSize(wxSizeEvent& event); | |
789 | ||
790 | /// Setting/losing focus | |
791 | void OnSetFocus(wxFocusEvent& event); | |
792 | void OnKillFocus(wxFocusEvent& event); | |
793 | ||
4d551ad5 JS |
794 | /// Idle-time processing |
795 | void OnIdle(wxIdleEvent& event); | |
796 | ||
c59f6793 JS |
797 | /// Scrolling |
798 | void OnScroll(wxScrollWinEvent& event); | |
799 | ||
5d7836c4 JS |
800 | /// Set font, and also default attributes |
801 | virtual bool SetFont(const wxFont& font); | |
802 | ||
803 | /// Set up scrollbars, e.g. after a resize | |
169adfa9 | 804 | virtual void SetupScrollbars(bool atTop = false); |
5d7836c4 JS |
805 | |
806 | /// Keyboard navigation | |
0bab774b | 807 | virtual bool KeyboardNavigate(int keyCode, int flags); |
5d7836c4 JS |
808 | |
809 | /// Paint the background | |
810 | virtual void PaintBackground(wxDC& dc); | |
7fe8059f | 811 | |
35bdbae5 | 812 | /// Other user defined painting after everything else (i.e. all text) is painted |
6dc6bcd8 | 813 | virtual void PaintAboveContent(wxDC& WXUNUSED(dc)) {} |
35bdbae5 | 814 | |
3e3a754f | 815 | #if wxRICHTEXT_BUFFERED_PAINTING |
5d7836c4 JS |
816 | /// Recreate buffer bitmap if necessary |
817 | virtual bool RecreateBuffer(const wxSize& size = wxDefaultSize); | |
3e3a754f | 818 | #endif |
5d7836c4 | 819 | |
5d7836c4 | 820 | /// Write text |
343ae70d | 821 | virtual void DoWriteText(const wxString& value, int flags = 0); |
5d7836c4 JS |
822 | |
823 | /// Should we inherit colours? | |
824 | virtual bool ShouldInheritColours() const { return false; } | |
825 | ||
826 | /// Position the caret | |
603f702b | 827 | virtual void PositionCaret(wxRichTextParagraphLayoutBox* container = NULL); |
5d7836c4 JS |
828 | |
829 | /// Extend the selection, returning true if the selection was | |
830 | /// changed. Selections are in caret positions. | |
831 | virtual bool ExtendSelection(long oldPosition, long newPosition, int flags); | |
832 | ||
833 | /// Scroll into view. This takes a _caret_ position. | |
834 | virtual bool ScrollIntoView(long position, int keyCode); | |
835 | ||
7051fa41 | 836 | /// Refresh the area affected by a selection change |
603f702b | 837 | bool RefreshForSelectionChange(const wxRichTextSelection& oldSelection, const wxRichTextSelection& newSelection); |
7051fa41 | 838 | |
5d7836c4 JS |
839 | /// The caret position is the character position just before the caret. |
840 | /// A value of -1 means the caret is at the start of the buffer. | |
841 | void SetCaretPosition(long position, bool showAtLineStart = false) ; | |
842 | long GetCaretPosition() const { return m_caretPosition; } | |
843 | ||
ab14c7aa JS |
844 | /// The adjusted caret position is the character position adjusted to take |
845 | /// into account whether we're at the start of a paragraph, in which case | |
846 | /// style information should be taken from the next position, not current one. | |
847 | long GetAdjustedCaretPosition(long caretPos) const; | |
848 | ||
5d7836c4 JS |
849 | /// Move caret one visual step forward: this may mean setting a flag |
850 | /// and keeping the same position if we're going from the end of one line | |
851 | /// to the start of the next, which may be the exact same caret position. | |
852 | void MoveCaretForward(long oldPosition) ; | |
853 | ||
854 | /// Move caret one visual step forward: this may mean setting a flag | |
855 | /// and keeping the same position if we're going from the end of one line | |
856 | /// to the start of the next, which may be the exact same caret position. | |
857 | void MoveCaretBack(long oldPosition) ; | |
858 | ||
603f702b JS |
859 | /// Get the caret height and position for the given character position. If container is null, |
860 | /// the current focus object will be used. | |
861 | bool GetCaretPositionForIndex(long position, wxRect& rect, wxRichTextParagraphLayoutBox* container = NULL); | |
5d7836c4 JS |
862 | |
863 | /// Gets the line for the visible caret position. If the caret is | |
864 | /// shown at the very end of the line, it means the next character is actually | |
865 | /// on the following line. So let's get the line we're expecting to find | |
866 | /// if this is the case. | |
867 | wxRichTextLine* GetVisibleLineForCaretPosition(long caretPosition) const; | |
868 | ||
869 | /// Gets the command processor | |
870 | wxCommandProcessor* GetCommandProcessor() const { return GetBuffer().GetCommandProcessor(); } | |
871 | ||
872 | /// Delete content if there is a selection, e.g. when pressing a key. | |
873 | /// Returns the new caret position in newPos, or leaves it if there | |
874 | /// was no action. | |
875 | bool DeleteSelectedContent(long* newPos= NULL); | |
876 | ||
877 | /// Transform logical to physical | |
4d551ad5 | 878 | wxPoint GetPhysicalPoint(const wxPoint& ptLogical) const; |
5d7836c4 JS |
879 | |
880 | /// Transform physical to logical | |
4d551ad5 | 881 | wxPoint GetLogicalPoint(const wxPoint& ptPhysical) const; |
5d7836c4 JS |
882 | |
883 | /// Finds the caret position for the next word. Direction | |
884 | /// is 1 (forward) or -1 (backwards). | |
885 | virtual long FindNextWordPosition(int direction = 1) const; | |
886 | ||
887 | /// Is the given position visible on the screen? | |
888 | bool IsPositionVisible(long pos) const; | |
889 | ||
4d551ad5 JS |
890 | /// Returns the first visible position in the current view |
891 | long GetFirstVisiblePosition() const; | |
892 | ||
ab14c7aa JS |
893 | /// Returns the caret position since the default formatting was changed. As |
894 | /// soon as this position changes, we no longer reflect the default style | |
895 | /// in the UI. A value of -2 means that we should only reflect the style of the | |
896 | /// content under the caret. | |
897 | long GetCaretPositionForDefaultStyle() const { return m_caretPositionForDefaultStyle; } | |
898 | ||
899 | /// Set the caret position for the default style that the user is selecting. | |
900 | void SetCaretPositionForDefaultStyle(long pos) { m_caretPositionForDefaultStyle = pos; } | |
901 | ||
902 | /// Should the UI reflect the default style chosen by the user, rather than the style under | |
903 | /// the caret? | |
904 | bool IsDefaultStyleShowing() const { return m_caretPositionForDefaultStyle != -2; } | |
905 | ||
906 | /// Convenience function that tells the control to start reflecting the default | |
907 | /// style, since the user is changing it. | |
24777478 | 908 | void SetAndShowDefaultStyle(const wxRichTextAttr& attr) |
ab14c7aa JS |
909 | { |
910 | SetDefaultStyle(attr); | |
911 | SetCaretPositionForDefaultStyle(GetCaretPosition()); | |
912 | } | |
913 | ||
ea160b2e JS |
914 | /// Get the first visible point in the window |
915 | wxPoint GetFirstVisiblePoint() const; | |
916 | ||
fe5aa22c JS |
917 | // Implementation |
918 | ||
603f702b JS |
919 | /// Set up the caret for the given position and container, after a mouse click |
920 | bool SetCaretPositionAfterClick(wxRichTextParagraphLayoutBox* container, long position, int hitTestFlags, bool extendSelection = false); | |
921 | ||
922 | /// Find the caret position for the combination of hit-test flags and character position. | |
923 | /// Returns the caret position and also an indication of where to place the caret (caretLineStart) | |
924 | /// since this is ambiguous (same position used for end of line and start of next). | |
925 | long FindCaretPositionForCharacterPosition(long position, int hitTestFlags, wxRichTextParagraphLayoutBox* container, | |
926 | bool& caretLineStart); | |
927 | ||
928 | /// Font names take a long time to retrieve, so cache them (on demand) | |
929 | static const wxArrayString& GetAvailableFontNames(); | |
930 | static void ClearAvailableFontNames(); | |
dadd4f55 | 931 | |
603f702b | 932 | WX_FORWARD_TO_SCROLL_HELPER() |
805c8d92 | 933 | |
603f702b JS |
934 | // implement wxTextEntry methods |
935 | virtual wxString DoGetValue() const; | |
805c8d92 VZ |
936 | |
937 | protected: | |
f5b7586b JS |
938 | // implement the wxTextEntry pure virtual method |
939 | virtual wxWindow *GetEditableWindow() { return this; } | |
940 | ||
603f702b JS |
941 | // margins functions |
942 | virtual bool DoSetMargins(const wxPoint& pt); | |
943 | virtual wxPoint DoGetMargins() const; | |
944 | ||
63f7d502 VZ |
945 | // FIXME: this does not work, it allows this code to compile but will fail |
946 | // during run-time | |
2cd36ea0 | 947 | #ifndef __WXUNIVERSAL__ |
f5172305 JS |
948 | #ifdef __WXMSW__ |
949 | virtual WXHWND GetEditHWND() const { return GetHWND(); } | |
128fae46 | 950 | #endif |
5eb34e9e VZ |
951 | #ifdef __WXMOTIF__ |
952 | virtual WXWidget GetTextWidget() const { return NULL; } | |
953 | #endif | |
954 | #ifdef __WXGTK20__ | |
128fae46 | 955 | virtual GtkEditable *GetEditable() const { return NULL; } |
0847e36e | 956 | virtual GtkEntry *GetEntry() const { return NULL; } |
f5172305 | 957 | #endif |
2cd36ea0 | 958 | #endif // !__WXUNIVERSAL__ |
f5172305 | 959 | |
5d7836c4 | 960 | // Overrides |
6f02a879 | 961 | protected: |
5d7836c4 JS |
962 | |
963 | virtual wxSize DoGetBestSize() const ; | |
964 | ||
343ae70d VZ |
965 | virtual void DoSetValue(const wxString& value, int flags = 0); |
966 | ||
17808a75 VZ |
967 | virtual void DoThaw(); |
968 | ||
343ae70d | 969 | |
5d7836c4 JS |
970 | // Data members |
971 | private: | |
3e3a754f | 972 | #if wxRICHTEXT_BUFFERED_PAINTING |
5d7836c4 JS |
973 | /// Buffer bitmap |
974 | wxBitmap m_bufferBitmap; | |
3e3a754f | 975 | #endif |
5d7836c4 JS |
976 | |
977 | /// Text buffer | |
978 | wxRichTextBuffer m_buffer; | |
979 | ||
5d7836c4 JS |
980 | wxMenu* m_contextMenu; |
981 | ||
982 | /// Caret position (1 less than the character position, so -1 is the | |
983 | /// first caret position). | |
984 | long m_caretPosition; | |
985 | ||
ab14c7aa JS |
986 | /// Caret position when the default formatting has been changed. As |
987 | /// soon as this position changes, we no longer reflect the default style | |
988 | /// in the UI. | |
989 | long m_caretPositionForDefaultStyle; | |
990 | ||
5d7836c4 | 991 | /// Selection range in character positions. -2, -2 means no selection. |
603f702b JS |
992 | wxRichTextSelection m_selection; |
993 | ||
994 | wxRichTextCtrlSelectionState m_selectionState; | |
5d7836c4 JS |
995 | |
996 | /// Anchor so we know how to extend the selection | |
997 | /// It's a caret position since it's between two characters. | |
998 | long m_selectionAnchor; | |
999 | ||
603f702b JS |
1000 | /// Anchor object if selecting multiple container objects, such as grid cells. |
1001 | wxRichTextObject* m_selectionAnchorObject; | |
1002 | ||
5d7836c4 JS |
1003 | /// Are we editable? |
1004 | bool m_editable; | |
1005 | ||
1006 | /// Are we showing the caret position at the start of a line | |
1007 | /// instead of at the end of the previous one? | |
1008 | bool m_caretAtLineStart; | |
1009 | ||
1010 | /// Are we dragging a selection? | |
1011 | bool m_dragging; | |
1012 | ||
1013 | /// Start position for drag | |
1014 | wxPoint m_dragStart; | |
4d551ad5 JS |
1015 | |
1016 | /// Do we need full layout in idle? | |
1017 | bool m_fullLayoutRequired; | |
1018 | wxLongLong m_fullLayoutTime; | |
1019 | long m_fullLayoutSavedPosition; | |
1020 | ||
1021 | /// Threshold for doing delayed layout | |
1022 | long m_delayedLayoutThreshold; | |
dadd4f55 | 1023 | |
d2d0adc7 JS |
1024 | /// Cursors |
1025 | wxCursor m_textCursor; | |
1026 | wxCursor m_urlCursor; | |
1027 | ||
dadd4f55 | 1028 | static wxArrayString sm_availableFontNames; |
603f702b JS |
1029 | |
1030 | wxRichTextContextMenuPropertiesInfo m_contextMenuPropertiesInfo; | |
1031 | ||
1032 | /// The object that currently has the editing focus | |
1033 | wxRichTextParagraphLayoutBox* m_focusObject; | |
5d7836c4 JS |
1034 | }; |
1035 | ||
1036 | /*! | |
1037 | * wxRichTextEvent - the event class for wxRichTextCtrl notifications | |
1038 | */ | |
1039 | ||
3b2cb431 | 1040 | class WXDLLIMPEXP_RICHTEXT wxRichTextEvent : public wxNotifyEvent |
5d7836c4 JS |
1041 | { |
1042 | public: | |
1043 | wxRichTextEvent(wxEventType commandType = wxEVT_NULL, int winid = 0) | |
1044 | : wxNotifyEvent(commandType, winid), | |
5912d19e | 1045 | m_flags(0), m_position(-1), m_oldStyleSheet(NULL), m_newStyleSheet(NULL), |
603f702b | 1046 | m_char((wxChar) 0), m_container(NULL), m_oldContainer(NULL) |
5d7836c4 JS |
1047 | { } |
1048 | ||
1049 | wxRichTextEvent(const wxRichTextEvent& event) | |
1050 | : wxNotifyEvent(event), | |
5912d19e JS |
1051 | m_flags(event.m_flags), m_position(-1), |
1052 | m_oldStyleSheet(event.m_oldStyleSheet), m_newStyleSheet(event.m_newStyleSheet), | |
603f702b | 1053 | m_char((wxChar) 0), m_container(event.m_container), m_oldContainer(event.m_oldContainer) |
5d7836c4 JS |
1054 | { } |
1055 | ||
5912d19e JS |
1056 | long GetPosition() const { return m_position; } |
1057 | void SetPosition(long pos) { m_position = pos; } | |
5d7836c4 JS |
1058 | |
1059 | int GetFlags() const { return m_flags; } | |
1060 | void SetFlags(int flags) { m_flags = flags; } | |
1061 | ||
d2d0adc7 JS |
1062 | wxRichTextStyleSheet* GetOldStyleSheet() const { return m_oldStyleSheet; } |
1063 | void SetOldStyleSheet(wxRichTextStyleSheet* sheet) { m_oldStyleSheet = sheet; } | |
1064 | ||
1065 | wxRichTextStyleSheet* GetNewStyleSheet() const { return m_newStyleSheet; } | |
1066 | void SetNewStyleSheet(wxRichTextStyleSheet* sheet) { m_newStyleSheet = sheet; } | |
1067 | ||
5912d19e JS |
1068 | const wxRichTextRange& GetRange() const { return m_range; } |
1069 | void SetRange(const wxRichTextRange& range) { m_range = range; } | |
1070 | ||
1071 | wxChar GetCharacter() const { return m_char; } | |
1072 | void SetCharacter(wxChar ch) { m_char = ch; } | |
1073 | ||
603f702b JS |
1074 | wxRichTextParagraphLayoutBox* GetContainer() const { return m_container; } |
1075 | void SetContainer(wxRichTextParagraphLayoutBox* container) { m_container = container; } | |
1076 | ||
1077 | wxRichTextParagraphLayoutBox* GetOldContainer() const { return m_oldContainer; } | |
1078 | void SetOldContainer(wxRichTextParagraphLayoutBox* container) { m_oldContainer = container; } | |
1079 | ||
5d7836c4 JS |
1080 | virtual wxEvent *Clone() const { return new wxRichTextEvent(*this); } |
1081 | ||
1082 | protected: | |
603f702b JS |
1083 | int m_flags; |
1084 | long m_position; | |
1085 | wxRichTextStyleSheet* m_oldStyleSheet; | |
1086 | wxRichTextStyleSheet* m_newStyleSheet; | |
1087 | wxRichTextRange m_range; | |
1088 | wxChar m_char; | |
1089 | wxRichTextParagraphLayoutBox* m_container; | |
1090 | wxRichTextParagraphLayoutBox* m_oldContainer; | |
5d7836c4 JS |
1091 | |
1092 | private: | |
1093 | DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxRichTextEvent) | |
1094 | }; | |
1095 | ||
1096 | /*! | |
c058cafa | 1097 | * wxRichTextCtrl events |
5d7836c4 | 1098 | */ |
9b11752c VZ |
1099 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_LEFT_CLICK, wxRichTextEvent ); |
1100 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_RIGHT_CLICK, wxRichTextEvent ); | |
1101 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_MIDDLE_CLICK, wxRichTextEvent ); | |
1102 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_LEFT_DCLICK, wxRichTextEvent ); | |
1103 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_RETURN, wxRichTextEvent ); | |
1104 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_CHARACTER, wxRichTextEvent ); | |
1105 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_DELETE, wxRichTextEvent ); | |
1106 | ||
1107 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_STYLESHEET_CHANGING, wxRichTextEvent ); | |
1108 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_STYLESHEET_CHANGED, wxRichTextEvent ); | |
1109 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_STYLESHEET_REPLACING, wxRichTextEvent ); | |
1110 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_STYLESHEET_REPLACED, wxRichTextEvent ); | |
1111 | ||
1112 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_CONTENT_INSERTED, wxRichTextEvent ); | |
1113 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_CONTENT_DELETED, wxRichTextEvent ); | |
1114 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_STYLE_CHANGED, wxRichTextEvent ); | |
1115 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_SELECTION_CHANGED, wxRichTextEvent ); | |
1116 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_BUFFER_RESET, wxRichTextEvent ); | |
603f702b | 1117 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_FOCUS_OBJECT_CHANGED, wxRichTextEvent ); |
5d7836c4 JS |
1118 | |
1119 | typedef void (wxEvtHandler::*wxRichTextEventFunction)(wxRichTextEvent&); | |
1120 | ||
97f3b1e9 | 1121 | #define wxRichTextEventHandler(func) \ |
3c778901 VZ |
1122 | wxEVENT_HANDLER_CAST(wxRichTextEventFunction, func) |
1123 | ||
a0e9a5df FM |
1124 | #define EVT_RICHTEXT_LEFT_CLICK(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_LEFT_CLICK, id, -1, wxRichTextEventHandler( fn ), NULL ), |
1125 | #define EVT_RICHTEXT_RIGHT_CLICK(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_RIGHT_CLICK, id, -1, wxRichTextEventHandler( fn ), NULL ), | |
1126 | #define EVT_RICHTEXT_MIDDLE_CLICK(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_MIDDLE_CLICK, id, -1, wxRichTextEventHandler( fn ), NULL ), | |
1127 | #define EVT_RICHTEXT_LEFT_DCLICK(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_LEFT_DCLICK, id, -1, wxRichTextEventHandler( fn ), NULL ), | |
1128 | #define EVT_RICHTEXT_RETURN(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_RETURN, id, -1, wxRichTextEventHandler( fn ), NULL ), | |
1129 | #define EVT_RICHTEXT_CHARACTER(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_CHARACTER, id, -1, wxRichTextEventHandler( fn ), NULL ), | |
1130 | #define EVT_RICHTEXT_DELETE(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_DELETE, id, -1, wxRichTextEventHandler( fn ), NULL ), | |
1131 | ||
1132 | #define EVT_RICHTEXT_STYLESHEET_CHANGING(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_STYLESHEET_CHANGING, id, -1, wxRichTextEventHandler( fn ), NULL ), | |
1133 | #define EVT_RICHTEXT_STYLESHEET_CHANGED(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_STYLESHEET_CHANGED, id, -1, wxRichTextEventHandler( fn ), NULL ), | |
1134 | #define EVT_RICHTEXT_STYLESHEET_REPLACING(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_STYLESHEET_REPLACING, id, -1, wxRichTextEventHandler( fn ), NULL ), | |
1135 | #define EVT_RICHTEXT_STYLESHEET_REPLACED(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_STYLESHEET_REPLACED, id, -1, wxRichTextEventHandler( fn ), NULL ), | |
1136 | ||
1137 | #define EVT_RICHTEXT_CONTENT_INSERTED(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_CONTENT_INSERTED, id, -1, wxRichTextEventHandler( fn ), NULL ), | |
1138 | #define EVT_RICHTEXT_CONTENT_DELETED(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_CONTENT_DELETED, id, -1, wxRichTextEventHandler( fn ), NULL ), | |
1139 | #define EVT_RICHTEXT_STYLE_CHANGED(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_STYLE_CHANGED, id, -1, wxRichTextEventHandler( fn ), NULL ), | |
1140 | #define EVT_RICHTEXT_SELECTION_CHANGED(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_SELECTION_CHANGED, id, -1, wxRichTextEventHandler( fn ), NULL ), | |
1141 | #define EVT_RICHTEXT_BUFFER_RESET(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_BUFFER_RESET, id, -1, wxRichTextEventHandler( fn ), NULL ), | |
5912d19e | 1142 | |
5d7836c4 JS |
1143 | #endif |
1144 | // wxUSE_RICHTEXT | |
1145 | ||
1146 | #endif | |
1147 | // _WX_RICHTEXTCTRL_H_ |