1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/richtext/richtextctrl.cpp
3 // Purpose: A rich edit control
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
21 #include "wx/richtext/richtextctrl.h"
22 #include "wx/richtext/richtextstyles.h"
26 #include "wx/settings.h"
30 #include "wx/textfile.h"
32 #include "wx/filename.h"
33 #include "wx/dcbuffer.h"
34 #include "wx/arrimpl.cpp"
35 #include "wx/fontenum.h"
38 #if defined (__WXGTK__) || defined(__WXX11__) || defined(__WXMOTIF__)
39 #define wxHAVE_PRIMARY_SELECTION 1
41 #define wxHAVE_PRIMARY_SELECTION 0
44 #if wxUSE_CLIPBOARD && wxHAVE_PRIMARY_SELECTION
45 #include "wx/clipbrd.h"
48 // DLL options compatibility check:
50 WX_CHECK_BUILD_OPTIONS("wxRichTextCtrl")
52 wxDEFINE_EVENT( wxEVT_COMMAND_RICHTEXT_LEFT_CLICK
, wxRichTextEvent
);
53 wxDEFINE_EVENT( wxEVT_COMMAND_RICHTEXT_MIDDLE_CLICK
, wxRichTextEvent
);
54 wxDEFINE_EVENT( wxEVT_COMMAND_RICHTEXT_RIGHT_CLICK
, wxRichTextEvent
);
55 wxDEFINE_EVENT( wxEVT_COMMAND_RICHTEXT_LEFT_DCLICK
, wxRichTextEvent
);
56 wxDEFINE_EVENT( wxEVT_COMMAND_RICHTEXT_RETURN
, wxRichTextEvent
);
57 wxDEFINE_EVENT( wxEVT_COMMAND_RICHTEXT_CHARACTER
, wxRichTextEvent
);
58 wxDEFINE_EVENT( wxEVT_COMMAND_RICHTEXT_DELETE
, wxRichTextEvent
);
60 wxDEFINE_EVENT( wxEVT_COMMAND_RICHTEXT_STYLESHEET_REPLACING
, wxRichTextEvent
);
61 wxDEFINE_EVENT( wxEVT_COMMAND_RICHTEXT_STYLESHEET_REPLACED
, wxRichTextEvent
);
62 wxDEFINE_EVENT( wxEVT_COMMAND_RICHTEXT_STYLESHEET_CHANGING
, wxRichTextEvent
);
63 wxDEFINE_EVENT( wxEVT_COMMAND_RICHTEXT_STYLESHEET_CHANGED
, wxRichTextEvent
);
65 wxDEFINE_EVENT( wxEVT_COMMAND_RICHTEXT_CONTENT_INSERTED
, wxRichTextEvent
);
66 wxDEFINE_EVENT( wxEVT_COMMAND_RICHTEXT_CONTENT_DELETED
, wxRichTextEvent
);
67 wxDEFINE_EVENT( wxEVT_COMMAND_RICHTEXT_STYLE_CHANGED
, wxRichTextEvent
);
68 wxDEFINE_EVENT( wxEVT_COMMAND_RICHTEXT_SELECTION_CHANGED
, wxRichTextEvent
);
69 wxDEFINE_EVENT( wxEVT_COMMAND_RICHTEXT_BUFFER_RESET
, wxRichTextEvent
);
70 wxDEFINE_EVENT( wxEVT_COMMAND_RICHTEXT_FOCUS_OBJECT_CHANGED
, wxRichTextEvent
);
72 #if wxRICHTEXT_USE_OWN_CARET
77 * This implements a non-flashing cursor in case there
78 * are platform-specific problems with the generic caret.
79 * wxRICHTEXT_USE_OWN_CARET is set in richtextbuffer.h.
82 class wxRichTextCaret
;
83 class wxRichTextCaretTimer
: public wxTimer
86 wxRichTextCaretTimer(wxRichTextCaret
* caret
)
90 virtual void Notify();
91 wxRichTextCaret
* m_caret
;
94 class wxRichTextCaret
: public wxCaret
99 // default - use Create()
100 wxRichTextCaret(): m_timer(this) { Init(); }
101 // creates a block caret associated with the given window
102 wxRichTextCaret(wxRichTextCtrl
*window
, int width
, int height
)
103 : wxCaret(window
, width
, height
), m_timer(this) { Init(); m_richTextCtrl
= window
; }
104 wxRichTextCaret(wxRichTextCtrl
*window
, const wxSize
& size
)
105 : wxCaret(window
, size
), m_timer(this) { Init(); m_richTextCtrl
= window
; }
107 virtual ~wxRichTextCaret();
112 // called by wxWindow (not using the event tables)
113 virtual void OnSetFocus();
114 virtual void OnKillFocus();
116 // draw the caret on the given DC
117 void DoDraw(wxDC
*dc
);
119 // get the visible count
120 int GetVisibleCount() const { return m_countVisible
; }
122 // delay repositioning
123 bool GetNeedsUpdate() const { return m_needsUpdate
; }
124 void SetNeedsUpdate(bool needsUpdate
= true ) { m_needsUpdate
= needsUpdate
; }
128 bool GetRefreshEnabled() const { return m_refreshEnabled
; }
129 void EnableRefresh(bool b
) { m_refreshEnabled
= b
; }
132 virtual void DoShow();
133 virtual void DoHide();
134 virtual void DoMove();
135 virtual void DoSize();
145 bool m_hasFocus
; // true => our window has focus
146 bool m_needsUpdate
; // must be repositioned
148 wxRichTextCaretTimer m_timer
;
149 wxRichTextCtrl
* m_richTextCtrl
;
150 bool m_refreshEnabled
;
154 IMPLEMENT_DYNAMIC_CLASS( wxRichTextCtrl
, wxControl
)
156 IMPLEMENT_DYNAMIC_CLASS( wxRichTextEvent
, wxNotifyEvent
)
158 BEGIN_EVENT_TABLE( wxRichTextCtrl
, wxControl
)
159 EVT_PAINT(wxRichTextCtrl::OnPaint
)
160 EVT_ERASE_BACKGROUND(wxRichTextCtrl::OnEraseBackground
)
161 EVT_IDLE(wxRichTextCtrl::OnIdle
)
162 EVT_SCROLLWIN(wxRichTextCtrl::OnScroll
)
163 EVT_LEFT_DOWN(wxRichTextCtrl::OnLeftClick
)
164 EVT_MOTION(wxRichTextCtrl::OnMoveMouse
)
165 EVT_LEFT_UP(wxRichTextCtrl::OnLeftUp
)
166 EVT_RIGHT_DOWN(wxRichTextCtrl::OnRightClick
)
167 EVT_MIDDLE_DOWN(wxRichTextCtrl::OnMiddleClick
)
168 EVT_LEFT_DCLICK(wxRichTextCtrl::OnLeftDClick
)
169 EVT_CHAR(wxRichTextCtrl::OnChar
)
170 EVT_KEY_DOWN(wxRichTextCtrl::OnChar
)
171 EVT_SIZE(wxRichTextCtrl::OnSize
)
172 EVT_SET_FOCUS(wxRichTextCtrl::OnSetFocus
)
173 EVT_KILL_FOCUS(wxRichTextCtrl::OnKillFocus
)
174 EVT_MOUSE_CAPTURE_LOST(wxRichTextCtrl::OnCaptureLost
)
175 EVT_CONTEXT_MENU(wxRichTextCtrl::OnContextMenu
)
176 EVT_SYS_COLOUR_CHANGED(wxRichTextCtrl::OnSysColourChanged
)
178 EVT_MENU(wxID_UNDO
, wxRichTextCtrl::OnUndo
)
179 EVT_UPDATE_UI(wxID_UNDO
, wxRichTextCtrl::OnUpdateUndo
)
181 EVT_MENU(wxID_REDO
, wxRichTextCtrl::OnRedo
)
182 EVT_UPDATE_UI(wxID_REDO
, wxRichTextCtrl::OnUpdateRedo
)
184 EVT_MENU(wxID_COPY
, wxRichTextCtrl::OnCopy
)
185 EVT_UPDATE_UI(wxID_COPY
, wxRichTextCtrl::OnUpdateCopy
)
187 EVT_MENU(wxID_PASTE
, wxRichTextCtrl::OnPaste
)
188 EVT_UPDATE_UI(wxID_PASTE
, wxRichTextCtrl::OnUpdatePaste
)
190 EVT_MENU(wxID_CUT
, wxRichTextCtrl::OnCut
)
191 EVT_UPDATE_UI(wxID_CUT
, wxRichTextCtrl::OnUpdateCut
)
193 EVT_MENU(wxID_CLEAR
, wxRichTextCtrl::OnClear
)
194 EVT_UPDATE_UI(wxID_CLEAR
, wxRichTextCtrl::OnUpdateClear
)
196 EVT_MENU(wxID_SELECTALL
, wxRichTextCtrl::OnSelectAll
)
197 EVT_UPDATE_UI(wxID_SELECTALL
, wxRichTextCtrl::OnUpdateSelectAll
)
199 EVT_MENU(wxID_RICHTEXT_PROPERTIES1
, wxRichTextCtrl::OnProperties
)
200 EVT_UPDATE_UI(wxID_RICHTEXT_PROPERTIES1
, wxRichTextCtrl::OnUpdateProperties
)
202 EVT_MENU(wxID_RICHTEXT_PROPERTIES2
, wxRichTextCtrl::OnProperties
)
203 EVT_UPDATE_UI(wxID_RICHTEXT_PROPERTIES2
, wxRichTextCtrl::OnUpdateProperties
)
205 EVT_MENU(wxID_RICHTEXT_PROPERTIES3
, wxRichTextCtrl::OnProperties
)
206 EVT_UPDATE_UI(wxID_RICHTEXT_PROPERTIES3
, wxRichTextCtrl::OnUpdateProperties
)
214 wxArrayString
wxRichTextCtrl::sm_availableFontNames
;
216 wxRichTextCtrl::wxRichTextCtrl()
217 : wxScrollHelper(this)
222 wxRichTextCtrl::wxRichTextCtrl(wxWindow
* parent
,
224 const wxString
& value
,
228 const wxValidator
& validator
,
229 const wxString
& name
)
230 : wxScrollHelper(this)
233 Create(parent
, id
, value
, pos
, size
, style
, validator
, name
);
235 SetDropTarget(new wxRichTextDropTarget(this));
239 bool wxRichTextCtrl::Create( wxWindow
* parent
, wxWindowID id
, const wxString
& value
, const wxPoint
& pos
, const wxSize
& size
, long style
,
240 const wxValidator
& validator
, const wxString
& name
)
244 if (!wxControl::Create(parent
, id
, pos
, size
,
245 style
|wxFULL_REPAINT_ON_RESIZE
,
249 if (!GetFont().IsOk())
251 SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
254 // No physical scrolling, so we can preserve margins
255 EnableScrolling(false, false);
257 if (style
& wxTE_READONLY
)
260 // The base attributes must all have default values
261 wxRichTextAttr attributes
;
262 attributes
.SetFont(GetFont());
263 attributes
.SetTextColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
));
264 attributes
.SetAlignment(wxTEXT_ALIGNMENT_LEFT
);
265 attributes
.SetLineSpacing(10);
266 attributes
.SetParagraphSpacingAfter(10);
267 attributes
.SetParagraphSpacingBefore(0);
269 SetBasicStyle(attributes
);
272 SetMargins(margin
, margin
);
274 // The default attributes will be merged with base attributes, so
275 // can be empty to begin with
276 wxRichTextAttr defaultAttributes
;
277 SetDefaultStyle(defaultAttributes
);
279 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
280 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
283 GetBuffer().SetRichTextCtrl(this);
285 #if wxRICHTEXT_USE_OWN_CARET
286 SetCaret(new wxRichTextCaret(this, wxRICHTEXT_DEFAULT_CARET_WIDTH
, 16));
288 SetCaret(new wxCaret(this, wxRICHTEXT_DEFAULT_CARET_WIDTH
, 16));
291 // Tell the sizers to use the given or best size
292 SetInitialSize(size
);
294 #if wxRICHTEXT_BUFFERED_PAINTING
296 RecreateBuffer(size
);
299 m_textCursor
= wxCursor(wxCURSOR_IBEAM
);
300 m_urlCursor
= wxCursor(wxCURSOR_HAND
);
302 SetCursor(m_textCursor
);
304 if (!value
.IsEmpty())
307 GetBuffer().AddEventHandler(this);
310 wxAcceleratorEntry entries
[6];
312 entries
[0].Set(wxACCEL_CTRL
, (int) 'C', wxID_COPY
);
313 entries
[1].Set(wxACCEL_CTRL
, (int) 'X', wxID_CUT
);
314 entries
[2].Set(wxACCEL_CTRL
, (int) 'V', wxID_PASTE
);
315 entries
[3].Set(wxACCEL_CTRL
, (int) 'A', wxID_SELECTALL
);
316 entries
[4].Set(wxACCEL_CTRL
, (int) 'Z', wxID_UNDO
);
317 entries
[5].Set(wxACCEL_CTRL
, (int) 'Y', wxID_REDO
);
319 wxAcceleratorTable
accel(6, entries
);
320 SetAcceleratorTable(accel
);
322 m_contextMenu
= new wxMenu
;
323 m_contextMenu
->Append(wxID_UNDO
, _("&Undo"));
324 m_contextMenu
->Append(wxID_REDO
, _("&Redo"));
325 m_contextMenu
->AppendSeparator();
326 m_contextMenu
->Append(wxID_CUT
, _("Cu&t"));
327 m_contextMenu
->Append(wxID_COPY
, _("&Copy"));
328 m_contextMenu
->Append(wxID_PASTE
, _("&Paste"));
329 m_contextMenu
->Append(wxID_CLEAR
, _("&Delete"));
330 m_contextMenu
->AppendSeparator();
331 m_contextMenu
->Append(wxID_SELECTALL
, _("Select &All"));
332 m_contextMenu
->AppendSeparator();
333 m_contextMenu
->Append(wxID_RICHTEXT_PROPERTIES1
, _("&Properties"));
338 wxRichTextCtrl::~wxRichTextCtrl()
340 SetFocusObject(& GetBuffer(), false);
341 GetBuffer().RemoveEventHandler(this);
343 delete m_contextMenu
;
346 /// Member initialisation
347 void wxRichTextCtrl::Init()
349 m_contextMenu
= NULL
;
351 m_caretPosition
= -1;
352 m_selectionAnchor
= -2;
353 m_selectionAnchorObject
= NULL
;
354 m_selectionState
= wxRichTextCtrlSelectionState_Normal
;
356 m_caretAtLineStart
= false;
359 m_fullLayoutRequired
= false;
360 m_fullLayoutTime
= 0;
361 m_fullLayoutSavedPosition
= 0;
362 m_delayedLayoutThreshold
= wxRICHTEXT_DEFAULT_DELAYED_LAYOUT_THRESHOLD
;
363 m_caretPositionForDefaultStyle
= -2;
364 m_focusObject
= & m_buffer
;
367 void wxRichTextCtrl::DoThaw()
369 if (GetBuffer().IsDirty())
378 void wxRichTextCtrl::Clear()
380 if (GetFocusObject() == & GetBuffer())
382 m_buffer
.ResetAndClearCommands();
383 m_buffer
.Invalidate(wxRICHTEXT_ALL
);
387 GetFocusObject()->Reset();
390 m_caretPosition
= -1;
391 m_caretPositionForDefaultStyle
= -2;
392 m_caretAtLineStart
= false;
394 m_selectionState
= wxRichTextCtrlSelectionState_Normal
;
404 wxTextCtrl::SendTextUpdatedEvent(this);
408 void wxRichTextCtrl::OnPaint(wxPaintEvent
& WXUNUSED(event
))
410 #if !wxRICHTEXT_USE_OWN_CARET
411 if (GetCaret() && !IsFrozen())
414 // Stop the caret refreshing the control from within the
417 ((wxRichTextCaret
*) GetCaret())->EnableRefresh(false);
421 #if wxRICHTEXT_BUFFERED_PAINTING
422 wxBufferedPaintDC
dc(this, m_bufferBitmap
);
432 dc
.SetFont(GetFont());
434 // Paint the background
437 // wxRect drawingArea(GetLogicalPoint(wxPoint(0, 0)), GetClientSize());
439 wxRect
drawingArea(GetUpdateRegion().GetBox());
440 drawingArea
.SetPosition(GetLogicalPoint(drawingArea
.GetPosition()));
442 wxRect
availableSpace(GetClientSize());
443 if (GetBuffer().IsDirty())
445 GetBuffer().Layout(dc
, availableSpace
, wxRICHTEXT_FIXED_WIDTH
|wxRICHTEXT_VARIABLE_HEIGHT
);
446 GetBuffer().Invalidate(wxRICHTEXT_NONE
);
450 wxRect
clipRect(availableSpace
);
451 clipRect
.x
+= GetBuffer().GetLeftMargin();
452 clipRect
.y
+= GetBuffer().GetTopMargin();
453 clipRect
.width
-= (GetBuffer().GetLeftMargin() + GetBuffer().GetRightMargin());
454 clipRect
.height
-= (GetBuffer().GetTopMargin() + GetBuffer().GetBottomMargin());
455 clipRect
.SetPosition(GetLogicalPoint(clipRect
.GetPosition()));
456 dc
.SetClippingRegion(clipRect
);
459 if ((GetExtraStyle() & wxRICHTEXT_EX_NO_GUIDELINES
) == 0)
460 flags
|= wxRICHTEXT_DRAW_GUIDELINES
;
462 GetBuffer().Draw(dc
, GetBuffer().GetOwnRange(), GetSelection(), drawingArea
, 0 /* descent */, flags
);
464 dc
.DestroyClippingRegion();
466 // Other user defined painting after everything else (i.e. all text) is painted
467 PaintAboveContent(dc
);
469 #if wxRICHTEXT_USE_OWN_CARET
470 if (GetCaret()->IsVisible())
473 ((wxRichTextCaret
*) GetCaret())->DoDraw(& dc
);
478 #if !wxRICHTEXT_USE_OWN_CARET
484 ((wxRichTextCaret
*) GetCaret())->EnableRefresh(true);
488 // Empty implementation, to prevent flicker
489 void wxRichTextCtrl::OnEraseBackground(wxEraseEvent
& WXUNUSED(event
))
493 void wxRichTextCtrl::OnSetFocus(wxFocusEvent
& WXUNUSED(event
))
497 #if !wxRICHTEXT_USE_OWN_CARET
503 #if defined(__WXGTK__) && !wxRICHTEXT_USE_OWN_CARET
504 // Work around dropouts when control is focused
512 void wxRichTextCtrl::OnKillFocus(wxFocusEvent
& WXUNUSED(event
))
517 #if defined(__WXGTK__) && !wxRICHTEXT_USE_OWN_CARET
518 // Work around dropouts when control is focused
526 void wxRichTextCtrl::OnCaptureLost(wxMouseCaptureLostEvent
& WXUNUSED(event
))
531 // Set up the caret for the given position and container, after a mouse click
532 bool wxRichTextCtrl::SetCaretPositionAfterClick(wxRichTextParagraphLayoutBox
* container
, long position
, int hitTestFlags
, bool extendSelection
)
534 bool caretAtLineStart
= false;
536 if (hitTestFlags
& wxRICHTEXT_HITTEST_BEFORE
)
538 // If we're at the start of a line (but not first in para)
539 // then we should keep the caret showing at the start of the line
540 // by showing the m_caretAtLineStart flag.
541 wxRichTextParagraph
* para
= container
->GetParagraphAtPosition(position
);
542 wxRichTextLine
* line
= container
->GetLineAtPosition(position
);
544 if (line
&& para
&& line
->GetAbsoluteRange().GetStart() == position
&& para
->GetRange().GetStart() != position
)
545 caretAtLineStart
= true;
549 if (extendSelection
&& (m_caretPosition
!= position
))
550 ExtendSelection(m_caretPosition
, position
, wxRICHTEXT_SHIFT_DOWN
);
552 MoveCaret(position
, caretAtLineStart
);
553 SetDefaultStyleToCursorStyle();
559 void wxRichTextCtrl::OnLeftClick(wxMouseEvent
& event
)
565 dc
.SetFont(GetFont());
567 // TODO: detect change of focus object
569 wxRichTextObject
* hitObj
= NULL
;
570 wxRichTextObject
* contextObj
= NULL
;
571 int hit
= GetBuffer().HitTest(dc
, event
.GetLogicalPosition(dc
), position
, & hitObj
, & contextObj
);
573 #if wxUSE_DRAG_AND_DROP
574 // If there's no selection, or we're not inside it, this isn't an attempt to initiate Drag'n'Drop
575 if (IsEditable() && HasSelection() && GetSelectionRange().ToInternal().Contains(position
))
577 // This might be an attempt at initiating Drag'n'Drop. So set the time & flags
579 m_dragStartPoint
= event
.GetPosition(); // No need to worry about logical positions etc, we only care about the distance from the original pt
582 m_dragStartTime
= wxDateTime::UNow();
583 #endif // wxUSE_DATETIME
585 // Preserve behaviour of clicking on an object within the selection
586 if (hit
!= wxRICHTEXT_HITTEST_NONE
&& hitObj
)
589 return; // Don't skip the event, else the selection will be lost
591 #endif // wxUSE_DRAG_AND_DROP
593 if (hit
!= wxRICHTEXT_HITTEST_NONE
&& hitObj
)
595 wxRichTextParagraphLayoutBox
* oldFocusObject
= GetFocusObject();
596 wxRichTextParagraphLayoutBox
* container
= wxDynamicCast(contextObj
, wxRichTextParagraphLayoutBox
);
597 if (container
&& container
!= GetFocusObject() && container
->AcceptsFocus())
599 SetFocusObject(container
, false /* don't set caret position yet */);
605 long oldCaretPos
= m_caretPosition
;
607 SetCaretPositionAfterClick(container
, position
, hit
);
609 // For now, don't handle shift-click when we're selecting multiple objects.
610 if (event
.ShiftDown() && GetFocusObject() == oldFocusObject
&& m_selectionState
== wxRichTextCtrlSelectionState_Normal
)
611 ExtendSelection(oldCaretPos
, m_caretPosition
, wxRICHTEXT_SHIFT_DOWN
);
620 void wxRichTextCtrl::OnLeftUp(wxMouseEvent
& event
)
625 if (GetCapture() == this)
628 // See if we clicked on a URL
631 dc
.SetFont(GetFont());
634 wxPoint logicalPt
= event
.GetLogicalPosition(dc
);
635 wxRichTextObject
* hitObj
= NULL
;
636 wxRichTextObject
* contextObj
= NULL
;
637 // Only get objects at this level, not nested, because otherwise we couldn't swipe text at a single level.
638 int hit
= GetFocusObject()->HitTest(dc
, logicalPt
, position
, & hitObj
, & contextObj
, wxRICHTEXT_HITTEST_NO_NESTED_OBJECTS
);
640 #if wxUSE_DRAG_AND_DROP
643 // Preserve the behaviour that would have happened without drag-and-drop detection, in OnLeftClick
644 m_preDrag
= false; // Tell DnD not to happen now: we are processing Left Up ourselves.
646 // Do the actions that would have been done in OnLeftClick if we hadn't tried to drag
648 wxRichTextObject
* hitObj
= NULL
;
649 wxRichTextObject
* contextObj
= NULL
;
650 int hit
= GetBuffer().HitTest(dc
, event
.GetLogicalPosition(dc
), position
, & hitObj
, & contextObj
);
651 wxRichTextParagraphLayoutBox
* oldFocusObject
= GetFocusObject();
652 wxRichTextParagraphLayoutBox
* container
= wxDynamicCast(contextObj
, wxRichTextParagraphLayoutBox
);
653 if (container
&& container
!= GetFocusObject() && container
->AcceptsFocus())
655 SetFocusObject(container
, false /* don't set caret position yet */);
658 long oldCaretPos
= m_caretPosition
;
660 SetCaretPositionAfterClick(container
, position
, hit
);
662 // For now, don't handle shift-click when we're selecting multiple objects.
663 if (event
.ShiftDown() && GetFocusObject() == oldFocusObject
&& m_selectionState
== wxRichTextCtrlSelectionState_Normal
)
664 ExtendSelection(oldCaretPos
, m_caretPosition
, wxRICHTEXT_SHIFT_DOWN
);
670 if ((hit
!= wxRICHTEXT_HITTEST_NONE
) && !(hit
& wxRICHTEXT_HITTEST_OUTSIDE
))
672 wxRichTextEvent
cmdEvent(
673 wxEVT_COMMAND_RICHTEXT_LEFT_CLICK
,
675 cmdEvent
.SetEventObject(this);
676 cmdEvent
.SetPosition(position
);
678 cmdEvent
.SetContainer(hitObj
->GetContainer());
680 if (!GetEventHandler()->ProcessEvent(cmdEvent
))
683 if (GetStyle(position
, attr
))
685 if (attr
.HasFlag(wxTEXT_ATTR_URL
))
687 wxString urlTarget
= attr
.GetURL();
688 if (!urlTarget
.IsEmpty())
690 wxMouseEvent
mouseEvent(event
);
692 long startPos
= 0, endPos
= 0;
693 wxRichTextObject
* obj
= GetFocusObject()->GetLeafObjectAtPosition(position
);
696 startPos
= obj
->GetRange().GetStart();
697 endPos
= obj
->GetRange().GetEnd();
700 wxTextUrlEvent
urlEvent(GetId(), mouseEvent
, startPos
, endPos
);
701 InitCommandEvent(urlEvent
);
703 urlEvent
.SetString(urlTarget
);
705 GetEventHandler()->ProcessEvent(urlEvent
);
713 #if wxUSE_DRAG_AND_DROP
715 #endif // wxUSE_DRAG_AND_DROP
717 #if wxUSE_CLIPBOARD && wxUSE_DATAOBJ && wxHAVE_PRIMARY_SELECTION
718 if (HasSelection() && GetFocusObject() && GetFocusObject()->GetBuffer())
720 // Put the selection in PRIMARY, if it exists
721 wxTheClipboard
->UsePrimarySelection(true);
723 wxRichTextRange range
= GetInternalSelectionRange();
724 GetFocusObject()->GetBuffer()->CopyToClipboard(range
);
726 wxTheClipboard
->UsePrimarySelection(false);
732 void wxRichTextCtrl::OnMoveMouse(wxMouseEvent
& event
)
734 #if wxUSE_DRAG_AND_DROP
735 // See if we're starting Drag'n'Drop
738 int x
= m_dragStartPoint
.x
- event
.GetPosition().x
;
739 int y
= m_dragStartPoint
.y
- event
.GetPosition().y
;
740 size_t distance
= abs(x
) + abs(y
);
742 wxTimeSpan diff
= wxDateTime::UNow() - m_dragStartTime
;
746 && (diff
.GetMilliseconds() > 100)
753 wxRichTextRange range
= GetInternalSelectionRange();
754 if (range
== wxRICHTEXT_NONE
)
756 // Don't try to drag an empty range
761 // Cache the current situation, to be restored if Drag'n'Drop is cancelled
762 long oldPos
= GetCaretPosition();
763 wxRichTextParagraphLayoutBox
* oldFocus
= GetFocusObject();
765 wxDataObjectComposite
* compositeObject
= new wxDataObjectComposite();
766 wxString text
= GetFocusObject()->GetTextForRange(range
);
768 text
= wxTextFile::Translate(text
, wxTextFileType_Dos
);
770 compositeObject
->Add(new wxTextDataObject(text
), false /* not preferred */);
772 wxRichTextBuffer
* richTextBuf
= new wxRichTextBuffer
;
773 GetFocusObject()->CopyFragment(range
, *richTextBuf
);
774 compositeObject
->Add(new wxRichTextBufferDataObject(richTextBuf
), true /* preferred */);
776 wxRichTextDropSource
source(*compositeObject
, this);
777 // Use wxDrag_DefaultMove, not because it's the likelier choice but because pressing Ctrl for Copy obeys the principle of least surprise
778 // The alternative, wxDrag_DefaultCopy, requires the user to know that Move needs the Shift key pressed
779 BeginBatchUndo(_("Drag"));
780 switch (source
.DoDragDrop(wxDrag_AllowMove
| wxDrag_DefaultMove
))
783 case wxDragCopy
: break;
786 wxLogError(wxT("An error occurred during drag and drop operation"));
789 Refresh(); // This is needed in wxMSW, otherwise resetting the position doesn't 'take'
790 SetCaretPosition(oldPos
);
791 SetFocusObject(oldFocus
, false);
800 #endif // wxUSE_DRAG_AND_DROP
804 dc
.SetFont(GetFont());
807 wxPoint logicalPt
= event
.GetLogicalPosition(dc
);
808 wxRichTextObject
* hitObj
= NULL
;
809 wxRichTextObject
* contextObj
= NULL
;
813 // If we're dragging, let's only consider positions at this level; otherwise
814 // selecting a range is not going to work.
815 wxRichTextParagraphLayoutBox
* container
= & GetBuffer();
818 flags
= wxRICHTEXT_HITTEST_NO_NESTED_OBJECTS
;
819 container
= GetFocusObject();
821 int hit
= container
->HitTest(dc
, logicalPt
, position
, & hitObj
, & contextObj
, flags
);
823 // See if we need to change the cursor
826 if (hit
!= wxRICHTEXT_HITTEST_NONE
&& !(hit
& wxRICHTEXT_HITTEST_OUTSIDE
) && hitObj
)
828 wxRichTextParagraphLayoutBox
* actualContainer
= wxDynamicCast(contextObj
, wxRichTextParagraphLayoutBox
);
830 if (actualContainer
&& GetStyle(position
, attr
, actualContainer
))
832 if (attr
.HasFlag(wxTEXT_ATTR_URL
))
834 SetCursor(m_urlCursor
);
836 else if (!attr
.HasFlag(wxTEXT_ATTR_URL
))
838 SetCursor(m_textCursor
);
843 SetCursor(m_textCursor
);
846 if (!event
.Dragging())
853 #if wxUSE_DRAG_AND_DROP
858 wxRichTextParagraphLayoutBox
* commonAncestor
= NULL
;
859 wxRichTextParagraphLayoutBox
* otherContainer
= NULL
;
860 wxRichTextParagraphLayoutBox
* firstContainer
= NULL
;
862 // Check for dragging across multiple containers
864 wxRichTextObject
* hitObj2
= NULL
, *contextObj2
= NULL
;
865 int hit2
= GetBuffer().HitTest(dc
, logicalPt
, position2
, & hitObj2
, & contextObj2
, 0);
866 if (hit2
!= wxRICHTEXT_HITTEST_NONE
&& !(hit2
& wxRICHTEXT_HITTEST_OUTSIDE
) && hitObj2
&& hitObj
!= hitObj2
)
868 // See if we can find a common ancestor
869 if (m_selectionState
== wxRichTextCtrlSelectionState_Normal
)
871 firstContainer
= GetFocusObject();
872 commonAncestor
= wxDynamicCast(firstContainer
->GetParent(), wxRichTextParagraphLayoutBox
);
876 firstContainer
= wxDynamicCast(m_selectionAnchorObject
, wxRichTextParagraphLayoutBox
);
877 //commonAncestor = GetFocusObject(); // when the selection state is not normal, the focus object (e.g. table)
878 // is the common ancestor.
879 commonAncestor
= wxDynamicCast(firstContainer
->GetParent(), wxRichTextParagraphLayoutBox
);
882 if (commonAncestor
&& commonAncestor
->HandlesChildSelections())
884 wxRichTextObject
* p
= hitObj2
;
887 if (p
->GetParent() == commonAncestor
)
889 otherContainer
= wxDynamicCast(p
, wxRichTextParagraphLayoutBox
);
896 if (commonAncestor
&& firstContainer
&& otherContainer
)
898 // We have now got a second container that shares a parent with the current or anchor object.
899 if (m_selectionState
== wxRichTextCtrlSelectionState_Normal
)
901 // Don't go into common-ancestor selection mode if we still have the same
903 if (otherContainer
!= firstContainer
)
905 m_selectionState
= wxRichTextCtrlSelectionState_CommonAncestor
;
906 m_selectionAnchorObject
= firstContainer
;
907 m_selectionAnchor
= firstContainer
->GetRange().GetStart();
909 // The common ancestor, such as a table, returns the cell selection
910 // between the anchor and current position.
911 m_selection
= commonAncestor
->GetSelection(m_selectionAnchor
, otherContainer
->GetRange().GetStart());
916 m_selection
= commonAncestor
->GetSelection(m_selectionAnchor
, otherContainer
->GetRange().GetStart());
921 if (otherContainer
->AcceptsFocus())
922 SetFocusObject(otherContainer
, false /* don't set caret and clear selection */);
923 MoveCaret(-1, false);
924 SetDefaultStyleToCursorStyle();
929 if (hitObj
&& m_dragging
&& hit
!= wxRICHTEXT_HITTEST_NONE
&& m_selectionState
== wxRichTextCtrlSelectionState_Normal
930 #if wxUSE_DRAG_AND_DROP
935 // TODO: test closeness
936 SetCaretPositionAfterClick(container
, position
, hit
, true /* extend selection */);
941 void wxRichTextCtrl::OnRightClick(wxMouseEvent
& event
)
947 dc
.SetFont(GetFont());
950 wxPoint logicalPt
= event
.GetLogicalPosition(dc
);
951 wxRichTextObject
* hitObj
= NULL
;
952 wxRichTextObject
* contextObj
= NULL
;
953 int hit
= GetFocusObject()->HitTest(dc
, logicalPt
, position
, & hitObj
, & contextObj
);
955 if (hitObj
&& hitObj
->GetContainer() != GetFocusObject())
957 wxRichTextParagraphLayoutBox
* actualContainer
= wxDynamicCast(contextObj
, wxRichTextParagraphLayoutBox
);
958 if (actualContainer
&& actualContainer
->AcceptsFocus())
960 SetFocusObject(actualContainer
, false /* don't set caret position yet */);
961 SetCaretPositionAfterClick(actualContainer
, position
, hit
);
965 wxRichTextEvent
cmdEvent(
966 wxEVT_COMMAND_RICHTEXT_RIGHT_CLICK
,
968 cmdEvent
.SetEventObject(this);
969 cmdEvent
.SetPosition(position
);
971 cmdEvent
.SetContainer(hitObj
->GetContainer());
973 if (!GetEventHandler()->ProcessEvent(cmdEvent
))
977 /// Left-double-click
978 void wxRichTextCtrl::OnLeftDClick(wxMouseEvent
& WXUNUSED(event
))
980 wxRichTextEvent
cmdEvent(
981 wxEVT_COMMAND_RICHTEXT_LEFT_DCLICK
,
983 cmdEvent
.SetEventObject(this);
984 cmdEvent
.SetPosition(m_caretPosition
+1);
985 cmdEvent
.SetContainer(GetFocusObject());
987 if (!GetEventHandler()->ProcessEvent(cmdEvent
))
989 SelectWord(GetCaretPosition()+1);
994 void wxRichTextCtrl::OnMiddleClick(wxMouseEvent
& event
)
996 wxRichTextEvent
cmdEvent(
997 wxEVT_COMMAND_RICHTEXT_MIDDLE_CLICK
,
999 cmdEvent
.SetEventObject(this);
1000 cmdEvent
.SetPosition(m_caretPosition
+1);
1001 cmdEvent
.SetContainer(GetFocusObject());
1003 if (!GetEventHandler()->ProcessEvent(cmdEvent
))
1006 #if wxUSE_CLIPBOARD && wxUSE_DATAOBJ && wxHAVE_PRIMARY_SELECTION
1007 // Paste any PRIMARY selection, if it exists
1008 wxTheClipboard
->UsePrimarySelection(true);
1010 wxTheClipboard
->UsePrimarySelection(false);
1015 void wxRichTextCtrl::OnChar(wxKeyEvent
& event
)
1018 if (event
.CmdDown())
1019 flags
|= wxRICHTEXT_CTRL_DOWN
;
1020 if (event
.ShiftDown())
1021 flags
|= wxRICHTEXT_SHIFT_DOWN
;
1022 if (event
.AltDown())
1023 flags
|= wxRICHTEXT_ALT_DOWN
;
1025 if (event
.GetEventType() == wxEVT_KEY_DOWN
)
1027 if (event
.IsKeyInCategory(WXK_CATEGORY_NAVIGATION
))
1029 KeyboardNavigate(event
.GetKeyCode(), flags
);
1033 long keycode
= event
.GetKeyCode();
1093 case WXK_NUMPAD_HOME
:
1094 case WXK_NUMPAD_LEFT
:
1096 case WXK_NUMPAD_RIGHT
:
1097 case WXK_NUMPAD_DOWN
:
1098 case WXK_NUMPAD_PAGEUP
:
1099 case WXK_NUMPAD_PAGEDOWN
:
1100 case WXK_NUMPAD_END
:
1101 case WXK_NUMPAD_BEGIN
:
1102 case WXK_NUMPAD_INSERT
:
1103 case WXK_WINDOWS_LEFT
:
1112 // Must process this before translation, otherwise it's translated into a WXK_DELETE event.
1113 if (event
.CmdDown() && event
.GetKeyCode() == WXK_BACK
)
1115 BeginBatchUndo(_("Delete Text"));
1117 long newPos
= m_caretPosition
;
1119 bool processed
= DeleteSelectedContent(& newPos
);
1121 // Submit range in character positions, which are greater than caret positions,
1122 // so subtract 1 for deleted character and add 1 for conversion to character position.
1125 if (event
.CmdDown())
1127 long pos
= wxRichTextCtrl::FindNextWordPosition(-1);
1130 GetFocusObject()->DeleteRangeWithUndo(wxRichTextRange(pos
+1, newPos
), this, & GetBuffer());
1136 GetFocusObject()->DeleteRangeWithUndo(wxRichTextRange(newPos
, newPos
), this, & GetBuffer());
1141 if (GetLastPosition() == -1)
1143 GetFocusObject()->Reset();
1145 m_caretPosition
= -1;
1147 SetDefaultStyleToCursorStyle();
1150 ScrollIntoView(m_caretPosition
, WXK_LEFT
);
1152 wxRichTextEvent
cmdEvent(
1153 wxEVT_COMMAND_RICHTEXT_DELETE
,
1155 cmdEvent
.SetEventObject(this);
1156 cmdEvent
.SetFlags(flags
);
1157 cmdEvent
.SetPosition(m_caretPosition
+1);
1158 cmdEvent
.SetContainer(GetFocusObject());
1159 GetEventHandler()->ProcessEvent(cmdEvent
);
1169 // all the other keys modify the controls contents which shouldn't be
1170 // possible if we're read-only
1171 if ( !IsEditable() )
1177 if (event
.GetKeyCode() == WXK_RETURN
)
1179 BeginBatchUndo(_("Insert Text"));
1181 long newPos
= m_caretPosition
;
1183 DeleteSelectedContent(& newPos
);
1185 if (event
.ShiftDown())
1188 text
= wxRichTextLineBreakChar
;
1189 GetFocusObject()->InsertTextWithUndo(& GetBuffer(), newPos
+1, text
, this);
1190 m_caretAtLineStart
= true;
1194 GetFocusObject()->InsertNewlineWithUndo(& GetBuffer(), newPos
+1, this, wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE
|wxRICHTEXT_INSERT_INTERACTIVE
);
1197 SetDefaultStyleToCursorStyle();
1199 ScrollIntoView(m_caretPosition
, WXK_RIGHT
);
1201 wxRichTextEvent
cmdEvent(
1202 wxEVT_COMMAND_RICHTEXT_RETURN
,
1204 cmdEvent
.SetEventObject(this);
1205 cmdEvent
.SetFlags(flags
);
1206 cmdEvent
.SetPosition(newPos
+1);
1207 cmdEvent
.SetContainer(GetFocusObject());
1209 if (!GetEventHandler()->ProcessEvent(cmdEvent
))
1211 // Generate conventional event
1212 wxCommandEvent
textEvent(wxEVT_COMMAND_TEXT_ENTER
, GetId());
1213 InitCommandEvent(textEvent
);
1215 GetEventHandler()->ProcessEvent(textEvent
);
1219 else if (event
.GetKeyCode() == WXK_BACK
)
1221 BeginBatchUndo(_("Delete Text"));
1223 long newPos
= m_caretPosition
;
1225 bool processed
= DeleteSelectedContent(& newPos
);
1227 // Submit range in character positions, which are greater than caret positions,
1228 // so subtract 1 for deleted character and add 1 for conversion to character position.
1231 if (event
.CmdDown())
1233 long pos
= wxRichTextCtrl::FindNextWordPosition(-1);
1236 GetFocusObject()->DeleteRangeWithUndo(wxRichTextRange(pos
+1, newPos
), this, & GetBuffer());
1242 GetFocusObject()->DeleteRangeWithUndo(wxRichTextRange(newPos
, newPos
), this, & GetBuffer());
1247 if (GetLastPosition() == -1)
1249 GetFocusObject()->Reset();
1251 m_caretPosition
= -1;
1253 SetDefaultStyleToCursorStyle();
1256 ScrollIntoView(m_caretPosition
, WXK_LEFT
);
1258 wxRichTextEvent
cmdEvent(
1259 wxEVT_COMMAND_RICHTEXT_DELETE
,
1261 cmdEvent
.SetEventObject(this);
1262 cmdEvent
.SetFlags(flags
);
1263 cmdEvent
.SetPosition(m_caretPosition
+1);
1264 cmdEvent
.SetContainer(GetFocusObject());
1265 GetEventHandler()->ProcessEvent(cmdEvent
);
1269 else if (event
.GetKeyCode() == WXK_DELETE
)
1271 BeginBatchUndo(_("Delete Text"));
1273 long newPos
= m_caretPosition
;
1275 bool processed
= DeleteSelectedContent(& newPos
);
1277 // Submit range in character positions, which are greater than caret positions,
1278 if (newPos
< GetFocusObject()->GetOwnRange().GetEnd()+1)
1280 if (event
.CmdDown())
1282 long pos
= wxRichTextCtrl::FindNextWordPosition(1);
1283 if (pos
!= -1 && (pos
> newPos
))
1285 GetFocusObject()->DeleteRangeWithUndo(wxRichTextRange(newPos
+1, pos
), this, & GetBuffer());
1290 if (!processed
&& newPos
< (GetLastPosition()-1))
1291 GetFocusObject()->DeleteRangeWithUndo(wxRichTextRange(newPos
+1, newPos
+1), this, & GetBuffer());
1296 if (GetLastPosition() == -1)
1298 GetFocusObject()->Reset();
1300 m_caretPosition
= -1;
1302 SetDefaultStyleToCursorStyle();
1305 ScrollIntoView(m_caretPosition
, WXK_LEFT
);
1307 wxRichTextEvent
cmdEvent(
1308 wxEVT_COMMAND_RICHTEXT_DELETE
,
1310 cmdEvent
.SetEventObject(this);
1311 cmdEvent
.SetFlags(flags
);
1312 cmdEvent
.SetPosition(m_caretPosition
+1);
1313 cmdEvent
.SetContainer(GetFocusObject());
1314 GetEventHandler()->ProcessEvent(cmdEvent
);
1320 long keycode
= event
.GetKeyCode();
1332 if (event
.CmdDown())
1334 // Fixes AltGr+key with European input languages on Windows
1335 if ((event
.CmdDown() && !event
.AltDown()) || (event
.AltDown() && !event
.CmdDown()))
1342 wxRichTextEvent
cmdEvent(
1343 wxEVT_COMMAND_RICHTEXT_CHARACTER
,
1345 cmdEvent
.SetEventObject(this);
1346 cmdEvent
.SetFlags(flags
);
1348 cmdEvent
.SetCharacter(event
.GetUnicodeKey());
1350 cmdEvent
.SetCharacter((wxChar
) keycode
);
1352 cmdEvent
.SetPosition(m_caretPosition
+1);
1353 cmdEvent
.SetContainer(GetFocusObject());
1355 if (keycode
== wxT('\t'))
1357 // See if we need to promote or demote the selection or paragraph at the cursor
1358 // position, instead of inserting a tab.
1359 long pos
= GetAdjustedCaretPosition(GetCaretPosition());
1360 wxRichTextParagraph
* para
= GetFocusObject()->GetParagraphAtPosition(pos
);
1361 if (para
&& para
->GetRange().GetStart() == pos
&& para
->GetAttributes().HasListStyleName())
1363 wxRichTextRange range
;
1365 range
= GetSelectionRange();
1367 range
= para
->GetRange().FromInternal();
1369 int promoteBy
= event
.ShiftDown() ? 1 : -1;
1371 PromoteList(promoteBy
, range
, NULL
);
1373 GetEventHandler()->ProcessEvent(cmdEvent
);
1379 BeginBatchUndo(_("Insert Text"));
1381 long newPos
= m_caretPosition
;
1382 DeleteSelectedContent(& newPos
);
1385 wxString str
= event
.GetUnicodeKey();
1387 wxString str
= (wxChar
) event
.GetKeyCode();
1389 GetFocusObject()->InsertTextWithUndo(& GetBuffer(), newPos
+1, str
, this, 0);
1393 SetDefaultStyleToCursorStyle();
1394 ScrollIntoView(m_caretPosition
, WXK_RIGHT
);
1396 cmdEvent
.SetPosition(m_caretPosition
);
1397 GetEventHandler()->ProcessEvent(cmdEvent
);
1405 /// Delete content if there is a selection, e.g. when pressing a key.
1406 bool wxRichTextCtrl::DeleteSelectedContent(long* newPos
)
1410 long pos
= m_selection
.GetRange().GetStart();
1411 wxRichTextRange range
= m_selection
.GetRange();
1413 // SelectAll causes more to be selected than doing it interactively,
1414 // and causes a new paragraph to be inserted. So for multiline buffers,
1415 // don't delete the final position.
1416 if (range
.GetEnd() == GetLastPosition() && GetNumberOfLines() > 0)
1417 range
.SetEnd(range
.GetEnd()-1);
1419 GetFocusObject()->DeleteRangeWithUndo(range
, this, & GetBuffer());
1420 m_selection
.Reset();
1421 m_selectionState
= wxRichTextCtrlSelectionState_Normal
;
1431 /// Keyboard navigation
1435 Left: left one character
1436 Right: right one character
1439 Ctrl-Left: left one word
1440 Ctrl-Right: right one word
1441 Ctrl-Up: previous paragraph start
1442 Ctrl-Down: next start of paragraph
1445 Ctrl-Home: start of document
1446 Ctrl-End: end of document
1447 Page-Up: Up a screen
1448 Page-Down: Down a screen
1452 Ctrl-Alt-PgUp: Start of window
1453 Ctrl-Alt-PgDn: End of window
1454 F8: Start selection mode
1455 Esc: End selection mode
1457 Adding Shift does the above but starts/extends selection.
1462 bool wxRichTextCtrl::KeyboardNavigate(int keyCode
, int flags
)
1464 bool success
= false;
1466 if (keyCode
== WXK_RIGHT
|| keyCode
== WXK_NUMPAD_RIGHT
)
1468 if (flags
& wxRICHTEXT_CTRL_DOWN
)
1469 success
= WordRight(1, flags
);
1471 success
= MoveRight(1, flags
);
1473 else if (keyCode
== WXK_LEFT
|| keyCode
== WXK_NUMPAD_LEFT
)
1475 if (flags
& wxRICHTEXT_CTRL_DOWN
)
1476 success
= WordLeft(1, flags
);
1478 success
= MoveLeft(1, flags
);
1480 else if (keyCode
== WXK_UP
|| keyCode
== WXK_NUMPAD_UP
)
1482 if (flags
& wxRICHTEXT_CTRL_DOWN
)
1483 success
= MoveToParagraphStart(flags
);
1485 success
= MoveUp(1, flags
);
1487 else if (keyCode
== WXK_DOWN
|| keyCode
== WXK_NUMPAD_DOWN
)
1489 if (flags
& wxRICHTEXT_CTRL_DOWN
)
1490 success
= MoveToParagraphEnd(flags
);
1492 success
= MoveDown(1, flags
);
1494 else if (keyCode
== WXK_PAGEUP
|| keyCode
== WXK_NUMPAD_PAGEUP
)
1496 success
= PageUp(1, flags
);
1498 else if (keyCode
== WXK_PAGEDOWN
|| keyCode
== WXK_NUMPAD_PAGEDOWN
)
1500 success
= PageDown(1, flags
);
1502 else if (keyCode
== WXK_HOME
|| keyCode
== WXK_NUMPAD_HOME
)
1504 if (flags
& wxRICHTEXT_CTRL_DOWN
)
1505 success
= MoveHome(flags
);
1507 success
= MoveToLineStart(flags
);
1509 else if (keyCode
== WXK_END
|| keyCode
== WXK_NUMPAD_END
)
1511 if (flags
& wxRICHTEXT_CTRL_DOWN
)
1512 success
= MoveEnd(flags
);
1514 success
= MoveToLineEnd(flags
);
1519 ScrollIntoView(m_caretPosition
, keyCode
);
1520 SetDefaultStyleToCursorStyle();
1526 /// Extend the selection. Selections are in caret positions.
1527 bool wxRichTextCtrl::ExtendSelection(long oldPos
, long newPos
, int flags
)
1529 if (flags
& wxRICHTEXT_SHIFT_DOWN
)
1531 if (oldPos
== newPos
)
1534 wxRichTextSelection oldSelection
= m_selection
;
1536 m_selection
.SetContainer(GetFocusObject());
1538 wxRichTextRange oldRange
;
1539 if (m_selection
.IsValid())
1540 oldRange
= m_selection
.GetRange();
1542 oldRange
= wxRICHTEXT_NO_SELECTION
;
1543 wxRichTextRange newRange
;
1545 // If not currently selecting, start selecting
1546 if (oldRange
.GetStart() == -2)
1548 m_selectionAnchor
= oldPos
;
1550 if (oldPos
> newPos
)
1551 newRange
.SetRange(newPos
+1, oldPos
);
1553 newRange
.SetRange(oldPos
+1, newPos
);
1557 // Always ensure that the selection range start is greater than
1559 if (newPos
> m_selectionAnchor
)
1560 newRange
.SetRange(m_selectionAnchor
+1, newPos
);
1561 else if (newPos
== m_selectionAnchor
)
1562 newRange
= wxRichTextRange(-2, -2);
1564 newRange
.SetRange(newPos
+1, m_selectionAnchor
);
1567 m_selection
.SetRange(newRange
);
1569 RefreshForSelectionChange(oldSelection
, m_selection
);
1571 if (newRange
.GetStart() > newRange
.GetEnd())
1573 wxLogDebug(wxT("Strange selection range"));
1582 /// Scroll into view, returning true if we scrolled.
1583 /// This takes a _caret_ position.
1584 bool wxRichTextCtrl::ScrollIntoView(long position
, int keyCode
)
1586 wxRichTextLine
* line
= GetVisibleLineForCaretPosition(position
);
1592 GetScrollPixelsPerUnit(& ppuX
, & ppuY
);
1594 int startXUnits
, startYUnits
;
1595 GetViewStart(& startXUnits
, & startYUnits
);
1596 int startY
= startYUnits
* ppuY
;
1599 GetVirtualSize(& sx
, & sy
);
1605 wxRect rect
= line
->GetRect();
1607 bool scrolled
= false;
1609 wxSize clientSize
= GetClientSize();
1611 int leftMargin
, rightMargin
, topMargin
, bottomMargin
;
1614 wxClientDC
dc(this);
1615 wxRichTextObject::GetTotalMargin(dc
, & GetBuffer(), GetBuffer().GetAttributes(), leftMargin
, rightMargin
,
1616 topMargin
, bottomMargin
);
1618 // clientSize.y -= GetBuffer().GetBottomMargin();
1619 clientSize
.y
-= bottomMargin
;
1621 if (GetWindowStyle() & wxRE_CENTRE_CARET
)
1623 int y
= rect
.y
- GetClientSize().y
/2;
1624 int yUnits
= (int) (0.5 + ((float) y
)/(float) ppuY
);
1625 if (y
>= 0 && (y
+ clientSize
.y
) < GetBuffer().GetCachedSize().y
)
1627 if (startYUnits
!= yUnits
)
1629 SetScrollbars(ppuX
, ppuY
, sxUnits
, syUnits
, 0, yUnits
);
1632 #if !wxRICHTEXT_USE_OWN_CARET
1642 if (keyCode
== WXK_DOWN
|| keyCode
== WXK_NUMPAD_DOWN
||
1643 keyCode
== WXK_RIGHT
|| keyCode
== WXK_NUMPAD_RIGHT
||
1644 keyCode
== WXK_END
|| keyCode
== WXK_NUMPAD_END
||
1645 keyCode
== WXK_PAGEDOWN
|| keyCode
== WXK_NUMPAD_PAGEDOWN
)
1647 if ((rect
.y
+ rect
.height
) > (clientSize
.y
+ startY
))
1649 // Make it scroll so this item is at the bottom
1651 int y
= rect
.y
- (clientSize
.y
- rect
.height
);
1652 int yUnits
= (int) (0.5 + ((float) y
)/(float) ppuY
);
1654 // If we're still off the screen, scroll another line down
1655 if ((rect
.y
+ rect
.height
) > (clientSize
.y
+ (yUnits
*ppuY
)))
1658 if (startYUnits
!= yUnits
)
1660 SetScrollbars(ppuX
, ppuY
, sxUnits
, syUnits
, 0, yUnits
);
1664 else if (rect
.y
< (startY
+ GetBuffer().GetTopMargin()))
1666 // Make it scroll so this item is at the top
1668 int y
= rect
.y
- GetBuffer().GetTopMargin();
1669 int yUnits
= (int) (0.5 + ((float) y
)/(float) ppuY
);
1671 if (startYUnits
!= yUnits
)
1673 SetScrollbars(ppuX
, ppuY
, sxUnits
, syUnits
, 0, yUnits
);
1679 else if (keyCode
== WXK_UP
|| keyCode
== WXK_NUMPAD_UP
||
1680 keyCode
== WXK_LEFT
|| keyCode
== WXK_NUMPAD_LEFT
||
1681 keyCode
== WXK_HOME
|| keyCode
== WXK_NUMPAD_HOME
||
1682 keyCode
== WXK_PAGEUP
|| keyCode
== WXK_NUMPAD_PAGEUP
)
1684 if (rect
.y
< (startY
+ GetBuffer().GetBottomMargin()))
1686 // Make it scroll so this item is at the top
1688 int y
= rect
.y
- GetBuffer().GetTopMargin();
1689 int yUnits
= (int) (0.5 + ((float) y
)/(float) ppuY
);
1691 if (startYUnits
!= yUnits
)
1693 SetScrollbars(ppuX
, ppuY
, sxUnits
, syUnits
, 0, yUnits
);
1697 else if ((rect
.y
+ rect
.height
) > (clientSize
.y
+ startY
))
1699 // Make it scroll so this item is at the bottom
1701 int y
= rect
.y
- (clientSize
.y
- rect
.height
);
1702 int yUnits
= (int) (0.5 + ((float) y
)/(float) ppuY
);
1704 // If we're still off the screen, scroll another line down
1705 if ((rect
.y
+ rect
.height
) > (clientSize
.y
+ (yUnits
*ppuY
)))
1708 if (startYUnits
!= yUnits
)
1710 SetScrollbars(ppuX
, ppuY
, sxUnits
, syUnits
, 0, yUnits
);
1716 #if !wxRICHTEXT_USE_OWN_CARET
1724 /// Is the given position visible on the screen?
1725 bool wxRichTextCtrl::IsPositionVisible(long pos
) const
1727 wxRichTextLine
* line
= GetVisibleLineForCaretPosition(pos
-1);
1733 GetScrollPixelsPerUnit(& ppuX
, & ppuY
);
1736 GetViewStart(& startX
, & startY
);
1738 startY
= startY
* ppuY
;
1740 wxRect rect
= line
->GetRect();
1741 wxSize clientSize
= GetClientSize();
1742 clientSize
.y
-= GetBuffer().GetBottomMargin();
1744 return (rect
.GetTop() >= (startY
+ GetBuffer().GetTopMargin())) && (rect
.GetBottom() <= (startY
+ clientSize
.y
));
1747 void wxRichTextCtrl::SetCaretPosition(long position
, bool showAtLineStart
)
1749 m_caretPosition
= position
;
1750 m_caretAtLineStart
= showAtLineStart
;
1753 /// Move caret one visual step forward: this may mean setting a flag
1754 /// and keeping the same position if we're going from the end of one line
1755 /// to the start of the next, which may be the exact same caret position.
1756 void wxRichTextCtrl::MoveCaretForward(long oldPosition
)
1758 wxRichTextParagraph
* para
= GetFocusObject()->GetParagraphAtPosition(oldPosition
);
1760 // Only do the check if we're not at the end of the paragraph (where things work OK
1762 if (para
&& (oldPosition
!= para
->GetRange().GetEnd() - 1))
1764 wxRichTextLine
* line
= GetFocusObject()->GetLineAtPosition(oldPosition
);
1768 wxRichTextRange lineRange
= line
->GetAbsoluteRange();
1770 // We're at the end of a line. See whether we need to
1771 // stay at the same actual caret position but change visual
1772 // position, or not.
1773 if (oldPosition
== lineRange
.GetEnd())
1775 if (m_caretAtLineStart
)
1777 // We're already at the start of the line, so actually move on now.
1778 m_caretPosition
= oldPosition
+ 1;
1779 m_caretAtLineStart
= false;
1783 // We're showing at the end of the line, so keep to
1784 // the same position but indicate that we're to show
1785 // at the start of the next line.
1786 m_caretPosition
= oldPosition
;
1787 m_caretAtLineStart
= true;
1789 SetDefaultStyleToCursorStyle();
1795 SetDefaultStyleToCursorStyle();
1798 /// Move caret one visual step backward: this may mean setting a flag
1799 /// and keeping the same position if we're going from the end of one line
1800 /// to the start of the next, which may be the exact same caret position.
1801 void wxRichTextCtrl::MoveCaretBack(long oldPosition
)
1803 wxRichTextParagraph
* para
= GetFocusObject()->GetParagraphAtPosition(oldPosition
);
1805 // Only do the check if we're not at the start of the paragraph (where things work OK
1807 if (para
&& (oldPosition
!= para
->GetRange().GetStart()))
1809 wxRichTextLine
* line
= GetFocusObject()->GetLineAtPosition(oldPosition
);
1813 wxRichTextRange lineRange
= line
->GetAbsoluteRange();
1815 // We're at the start of a line. See whether we need to
1816 // stay at the same actual caret position but change visual
1817 // position, or not.
1818 if (oldPosition
== lineRange
.GetStart())
1820 m_caretPosition
= oldPosition
-1;
1821 m_caretAtLineStart
= true;
1824 else if (oldPosition
== lineRange
.GetEnd())
1826 if (m_caretAtLineStart
)
1828 // We're at the start of the line, so keep the same caret position
1829 // but clear the start-of-line flag.
1830 m_caretPosition
= oldPosition
;
1831 m_caretAtLineStart
= false;
1835 // We're showing at the end of the line, so go back
1836 // to the previous character position.
1837 m_caretPosition
= oldPosition
- 1;
1839 SetDefaultStyleToCursorStyle();
1845 SetDefaultStyleToCursorStyle();
1849 bool wxRichTextCtrl::MoveRight(int noPositions
, int flags
)
1851 long endPos
= GetFocusObject()->GetOwnRange().GetEnd();
1853 if (m_caretPosition
+ noPositions
< endPos
)
1855 long oldPos
= m_caretPosition
;
1856 long newPos
= m_caretPosition
+ noPositions
;
1858 bool extendSel
= ExtendSelection(m_caretPosition
, newPos
, flags
);
1862 // Determine by looking at oldPos and m_caretPosition whether
1863 // we moved from the end of a line to the start of the next line, in which case
1864 // we want to adjust the caret position such that it is positioned at the
1865 // start of the next line, rather than jumping past the first character of the
1867 if (noPositions
== 1 && !extendSel
)
1868 MoveCaretForward(oldPos
);
1870 SetCaretPosition(newPos
);
1873 SetDefaultStyleToCursorStyle();
1882 bool wxRichTextCtrl::MoveLeft(int noPositions
, int flags
)
1886 if (m_caretPosition
> startPos
- noPositions
+ 1)
1888 long oldPos
= m_caretPosition
;
1889 long newPos
= m_caretPosition
- noPositions
;
1890 bool extendSel
= ExtendSelection(m_caretPosition
, newPos
, flags
);
1894 if (noPositions
== 1 && !extendSel
)
1895 MoveCaretBack(oldPos
);
1897 SetCaretPosition(newPos
);
1900 SetDefaultStyleToCursorStyle();
1908 // Find the caret position for the combination of hit-test flags and character position.
1909 // Returns the caret position and also an indication of where to place the caret (caretLineStart)
1910 // since this is ambiguous (same position used for end of line and start of next).
1911 long wxRichTextCtrl::FindCaretPositionForCharacterPosition(long position
, int hitTestFlags
, wxRichTextParagraphLayoutBox
* container
,
1912 bool& caretLineStart
)
1914 // If end of previous line, and hitTest is wxRICHTEXT_HITTEST_BEFORE,
1915 // we want to be at the end of the last line but with m_caretAtLineStart set to true,
1916 // so we view the caret at the start of the line.
1917 caretLineStart
= false;
1918 long caretPosition
= position
;
1920 if (hitTestFlags
& wxRICHTEXT_HITTEST_BEFORE
)
1922 wxRichTextLine
* thisLine
= container
->GetLineAtPosition(position
-1);
1923 wxRichTextRange lineRange
;
1925 lineRange
= thisLine
->GetAbsoluteRange();
1927 if (thisLine
&& (position
-1) == lineRange
.GetEnd())
1930 caretLineStart
= true;
1934 wxRichTextParagraph
* para
= container
->GetParagraphAtPosition(position
);
1935 if (para
&& para
->GetRange().GetStart() == position
)
1939 return caretPosition
;
1943 bool wxRichTextCtrl::MoveUp(int noLines
, int flags
)
1945 return MoveDown(- noLines
, flags
);
1949 bool wxRichTextCtrl::MoveDown(int noLines
, int flags
)
1954 long lineNumber
= GetFocusObject()->GetVisibleLineNumber(m_caretPosition
, true, m_caretAtLineStart
);
1955 wxPoint pt
= GetCaret()->GetPosition();
1956 long newLine
= lineNumber
+ noLines
;
1957 bool notInThisObject
= false;
1959 if (lineNumber
!= -1)
1963 long lastLine
= GetFocusObject()->GetVisibleLineNumber(GetFocusObject()->GetOwnRange().GetEnd());
1964 if (newLine
> lastLine
)
1965 notInThisObject
= true;
1970 notInThisObject
= true;
1974 wxRichTextParagraphLayoutBox
* container
= GetFocusObject();
1975 int hitTestFlags
= wxRICHTEXT_HITTEST_NO_NESTED_OBJECTS
|wxRICHTEXT_HITTEST_NO_FLOATING_OBJECTS
;
1977 if (notInThisObject
)
1979 // If we know we're navigating out of the current object,
1980 // try to find an object anywhere in the buffer at the new position (up or down a bit)
1981 container
= & GetBuffer();
1982 hitTestFlags
&= ~wxRICHTEXT_HITTEST_NO_NESTED_OBJECTS
;
1984 if (noLines
> 0) // going down
1986 pt
.y
= GetFocusObject()->GetPosition().y
+ GetFocusObject()->GetCachedSize().y
+ 2;
1990 pt
.y
= GetFocusObject()->GetPosition().y
- 2;
1995 wxRichTextLine
* lineObj
= GetFocusObject()->GetLineForVisibleLineNumber(newLine
);
1997 pt
.y
= lineObj
->GetAbsolutePosition().y
+ 2;
2003 wxClientDC
dc(this);
2005 dc
.SetFont(GetFont());
2007 wxRichTextObject
* hitObj
= NULL
;
2008 wxRichTextObject
* contextObj
= NULL
;
2009 int hitTest
= container
->HitTest(dc
, pt
, newPos
, & hitObj
, & contextObj
, hitTestFlags
);
2012 ((hitTest
& wxRICHTEXT_HITTEST_NONE
) == 0) &&
2013 (! (hitObj
== (& m_buffer
) && ((hitTest
& wxRICHTEXT_HITTEST_OUTSIDE
) != 0))) // outside the buffer counts as 'do nothing'
2016 if (notInThisObject
)
2018 wxRichTextParagraphLayoutBox
* actualContainer
= wxDynamicCast(contextObj
, wxRichTextParagraphLayoutBox
);
2019 if (actualContainer
&& actualContainer
!= GetFocusObject() && actualContainer
->AcceptsFocus())
2021 SetFocusObject(actualContainer
, false /* don't set caret position yet */);
2023 container
= actualContainer
;
2027 bool caretLineStart
= true;
2028 long caretPosition
= FindCaretPositionForCharacterPosition(newPos
, hitTest
, container
, caretLineStart
);
2029 long newSelEnd
= caretPosition
;
2032 if (notInThisObject
)
2035 extendSel
= ExtendSelection(m_caretPosition
, newSelEnd
, flags
);
2040 SetCaretPosition(caretPosition
, caretLineStart
);
2042 SetDefaultStyleToCursorStyle();
2050 /// Move to the end of the paragraph
2051 bool wxRichTextCtrl::MoveToParagraphEnd(int flags
)
2053 wxRichTextParagraph
* para
= GetFocusObject()->GetParagraphAtPosition(m_caretPosition
, true);
2056 long newPos
= para
->GetRange().GetEnd() - 1;
2057 bool extendSel
= ExtendSelection(m_caretPosition
, newPos
, flags
);
2061 SetCaretPosition(newPos
);
2063 SetDefaultStyleToCursorStyle();
2071 /// Move to the start of the paragraph
2072 bool wxRichTextCtrl::MoveToParagraphStart(int flags
)
2074 wxRichTextParagraph
* para
= GetFocusObject()->GetParagraphAtPosition(m_caretPosition
, true);
2077 long newPos
= para
->GetRange().GetStart() - 1;
2078 bool extendSel
= ExtendSelection(m_caretPosition
, newPos
, flags
);
2082 SetCaretPosition(newPos
);
2084 SetDefaultStyleToCursorStyle();
2092 /// Move to the end of the line
2093 bool wxRichTextCtrl::MoveToLineEnd(int flags
)
2095 wxRichTextLine
* line
= GetVisibleLineForCaretPosition(m_caretPosition
);
2099 wxRichTextRange lineRange
= line
->GetAbsoluteRange();
2100 long newPos
= lineRange
.GetEnd();
2101 bool extendSel
= ExtendSelection(m_caretPosition
, newPos
, flags
);
2105 SetCaretPosition(newPos
);
2107 SetDefaultStyleToCursorStyle();
2115 /// Move to the start of the line
2116 bool wxRichTextCtrl::MoveToLineStart(int flags
)
2118 wxRichTextLine
* line
= GetVisibleLineForCaretPosition(m_caretPosition
);
2121 wxRichTextRange lineRange
= line
->GetAbsoluteRange();
2122 long newPos
= lineRange
.GetStart()-1;
2124 bool extendSel
= ExtendSelection(m_caretPosition
, newPos
, flags
);
2128 wxRichTextParagraph
* para
= GetFocusObject()->GetParagraphForLine(line
);
2130 SetCaretPosition(newPos
, para
->GetRange().GetStart() != lineRange
.GetStart());
2132 SetDefaultStyleToCursorStyle();
2140 /// Move to the start of the buffer
2141 bool wxRichTextCtrl::MoveHome(int flags
)
2143 if (m_caretPosition
!= -1)
2145 bool extendSel
= ExtendSelection(m_caretPosition
, -1, flags
);
2149 SetCaretPosition(-1);
2151 SetDefaultStyleToCursorStyle();
2159 /// Move to the end of the buffer
2160 bool wxRichTextCtrl::MoveEnd(int flags
)
2162 long endPos
= GetFocusObject()->GetOwnRange().GetEnd()-1;
2164 if (m_caretPosition
!= endPos
)
2166 bool extendSel
= ExtendSelection(m_caretPosition
, endPos
, flags
);
2170 SetCaretPosition(endPos
);
2172 SetDefaultStyleToCursorStyle();
2180 /// Move noPages pages up
2181 bool wxRichTextCtrl::PageUp(int noPages
, int flags
)
2183 return PageDown(- noPages
, flags
);
2186 /// Move noPages pages down
2187 bool wxRichTextCtrl::PageDown(int noPages
, int flags
)
2189 // Calculate which line occurs noPages * screen height further down.
2190 wxRichTextLine
* line
= GetVisibleLineForCaretPosition(m_caretPosition
);
2193 wxSize clientSize
= GetClientSize();
2194 int newY
= line
->GetAbsolutePosition().y
+ noPages
*clientSize
.y
;
2196 wxRichTextLine
* newLine
= GetFocusObject()->GetLineAtYPosition(newY
);
2199 wxRichTextRange lineRange
= newLine
->GetAbsoluteRange();
2200 long pos
= lineRange
.GetStart()-1;
2201 if (pos
!= m_caretPosition
)
2203 wxRichTextParagraph
* para
= GetFocusObject()->GetParagraphForLine(newLine
);
2205 bool extendSel
= ExtendSelection(m_caretPosition
, pos
, flags
);
2209 SetCaretPosition(pos
, para
->GetRange().GetStart() != lineRange
.GetStart());
2211 SetDefaultStyleToCursorStyle();
2221 static bool wxRichTextCtrlIsWhitespace(const wxString
& str
)
2223 return str
== wxT(" ") || str
== wxT("\t");
2226 // Finds the caret position for the next word
2227 long wxRichTextCtrl::FindNextWordPosition(int direction
) const
2229 long endPos
= GetFocusObject()->GetOwnRange().GetEnd();
2233 long i
= m_caretPosition
+1+direction
; // +1 for conversion to character pos
2235 // First skip current text to space
2236 while (i
< endPos
&& i
> -1)
2238 // i is in character, not caret positions
2239 wxString text
= GetFocusObject()->GetTextForRange(wxRichTextRange(i
, i
));
2240 wxRichTextLine
* line
= GetFocusObject()->GetLineAtPosition(i
, false);
2241 if (line
&& (i
== line
->GetAbsoluteRange().GetEnd()))
2245 else if (!wxRichTextCtrlIsWhitespace(text
) && !text
.empty())
2252 while (i
< endPos
&& i
> -1)
2254 // i is in character, not caret positions
2255 wxString text
= GetFocusObject()->GetTextForRange(wxRichTextRange(i
, i
));
2256 wxRichTextLine
* line
= GetFocusObject()->GetLineAtPosition(i
, false);
2257 if (line
&& (i
== line
->GetAbsoluteRange().GetEnd()))
2258 return wxMax(-1, i
);
2260 if (text
.empty()) // End of paragraph, or maybe an image
2261 return wxMax(-1, i
- 1);
2262 else if (wxRichTextCtrlIsWhitespace(text
) || text
.empty())
2266 // Convert to caret position
2267 return wxMax(-1, i
- 1);
2276 long i
= m_caretPosition
;
2278 // First skip white space
2279 while (i
< endPos
&& i
> -1)
2281 // i is in character, not caret positions
2282 wxString text
= GetFocusObject()->GetTextForRange(wxRichTextRange(i
, i
));
2283 wxRichTextLine
* line
= GetFocusObject()->GetLineAtPosition(i
, false);
2285 if (text
.empty() || (line
&& (i
== line
->GetAbsoluteRange().GetStart()))) // End of paragraph, or maybe an image
2287 else if (wxRichTextCtrlIsWhitespace(text
) || text
.empty())
2292 // Next skip current text to space
2293 while (i
< endPos
&& i
> -1)
2295 // i is in character, not caret positions
2296 wxString text
= GetFocusObject()->GetTextForRange(wxRichTextRange(i
, i
));
2297 wxRichTextLine
* line
= GetFocusObject()->GetLineAtPosition(i
, false);
2298 if (line
&& line
->GetAbsoluteRange().GetStart() == i
)
2301 if (!wxRichTextCtrlIsWhitespace(text
) /* && !text.empty() */)
2314 /// Move n words left
2315 bool wxRichTextCtrl::WordLeft(int WXUNUSED(n
), int flags
)
2317 long pos
= FindNextWordPosition(-1);
2318 if (pos
!= m_caretPosition
)
2320 wxRichTextParagraph
* para
= GetFocusObject()->GetParagraphAtPosition(pos
, true);
2322 bool extendSel
= ExtendSelection(m_caretPosition
, pos
, flags
);
2326 SetCaretPosition(pos
, para
->GetRange().GetStart() != pos
);
2328 SetDefaultStyleToCursorStyle();
2336 /// Move n words right
2337 bool wxRichTextCtrl::WordRight(int WXUNUSED(n
), int flags
)
2339 long pos
= FindNextWordPosition(1);
2340 if (pos
!= m_caretPosition
)
2342 wxRichTextParagraph
* para
= GetFocusObject()->GetParagraphAtPosition(pos
, true);
2344 bool extendSel
= ExtendSelection(m_caretPosition
, pos
, flags
);
2348 SetCaretPosition(pos
, para
->GetRange().GetStart() != pos
);
2350 SetDefaultStyleToCursorStyle();
2359 void wxRichTextCtrl::OnSize(wxSizeEvent
& event
)
2361 // Only do sizing optimization for large buffers
2362 if (GetBuffer().GetOwnRange().GetEnd() > m_delayedLayoutThreshold
)
2364 m_fullLayoutRequired
= true;
2365 m_fullLayoutTime
= wxGetLocalTimeMillis();
2366 m_fullLayoutSavedPosition
= GetFirstVisiblePosition();
2367 LayoutContent(true /* onlyVisibleRect */);
2370 GetBuffer().Invalidate(wxRICHTEXT_ALL
);
2372 #if wxRICHTEXT_BUFFERED_PAINTING
2379 // Force any pending layout due to large buffer
2380 void wxRichTextCtrl::ForceDelayedLayout()
2382 if (m_fullLayoutRequired
)
2384 m_fullLayoutRequired
= false;
2385 m_fullLayoutTime
= 0;
2386 GetBuffer().Invalidate(wxRICHTEXT_ALL
);
2387 ShowPosition(m_fullLayoutSavedPosition
);
2393 /// Idle-time processing
2394 void wxRichTextCtrl::OnIdle(wxIdleEvent
& event
)
2396 #if wxRICHTEXT_USE_OWN_CARET
2397 if (((wxRichTextCaret
*) GetCaret())->GetNeedsUpdate())
2399 ((wxRichTextCaret
*) GetCaret())->SetNeedsUpdate(false);
2405 const int layoutInterval
= wxRICHTEXT_DEFAULT_LAYOUT_INTERVAL
;
2407 if (m_fullLayoutRequired
&& (wxGetLocalTimeMillis() > (m_fullLayoutTime
+ layoutInterval
)))
2409 m_fullLayoutRequired
= false;
2410 m_fullLayoutTime
= 0;
2411 GetBuffer().Invalidate(wxRICHTEXT_ALL
);
2412 ShowPosition(m_fullLayoutSavedPosition
);
2416 if (m_caretPositionForDefaultStyle
!= -2)
2418 // If the caret position has changed, no longer reflect the default style
2420 if (GetCaretPosition() != m_caretPositionForDefaultStyle
)
2421 m_caretPositionForDefaultStyle
= -2;
2428 void wxRichTextCtrl::OnScroll(wxScrollWinEvent
& event
)
2430 #if wxRICHTEXT_USE_OWN_CARET
2431 if (!((wxRichTextCaret
*) GetCaret())->GetNeedsUpdate())
2434 ((wxRichTextCaret
*) GetCaret())->SetNeedsUpdate();
2441 /// Set up scrollbars, e.g. after a resize
2442 void wxRichTextCtrl::SetupScrollbars(bool atTop
)
2447 if (GetBuffer().IsEmpty())
2449 SetScrollbars(0, 0, 0, 0, 0, 0);
2453 // TODO: reimplement scrolling so we scroll by line, not by fixed number
2454 // of pixels. See e.g. wxVScrolledWindow for ideas.
2455 int pixelsPerUnit
= 5;
2456 wxSize clientSize
= GetClientSize();
2458 int maxHeight
= GetBuffer().GetCachedSize().y
+ GetBuffer().GetTopMargin();
2460 // Round up so we have at least maxHeight pixels
2461 int unitsY
= (int) (((float)maxHeight
/(float)pixelsPerUnit
) + 0.5);
2463 int startX
= 0, startY
= 0;
2465 GetViewStart(& startX
, & startY
);
2467 int maxPositionX
= 0;
2468 int maxPositionY
= (int) ((((float)(wxMax((unitsY
*pixelsPerUnit
) - clientSize
.y
, 0)))/((float)pixelsPerUnit
)) + 0.5);
2470 int newStartX
= wxMin(maxPositionX
, startX
);
2471 int newStartY
= wxMin(maxPositionY
, startY
);
2473 int oldPPUX
, oldPPUY
;
2474 int oldStartX
, oldStartY
;
2475 int oldVirtualSizeX
= 0, oldVirtualSizeY
= 0;
2476 GetScrollPixelsPerUnit(& oldPPUX
, & oldPPUY
);
2477 GetViewStart(& oldStartX
, & oldStartY
);
2478 GetVirtualSize(& oldVirtualSizeX
, & oldVirtualSizeY
);
2480 oldVirtualSizeY
/= oldPPUY
;
2482 if (oldPPUX
== 0 && oldPPUY
== pixelsPerUnit
&& oldVirtualSizeY
== unitsY
&& oldStartX
== newStartX
&& oldStartY
== newStartY
)
2485 // Don't set scrollbars if there were none before, and there will be none now.
2486 if (oldPPUY
!= 0 && (oldVirtualSizeY
*oldPPUY
< clientSize
.y
) && (unitsY
*pixelsPerUnit
< clientSize
.y
))
2489 // Move to previous scroll position if
2491 SetScrollbars(0, pixelsPerUnit
, 0, unitsY
, newStartX
, newStartY
);
2494 /// Paint the background
2495 void wxRichTextCtrl::PaintBackground(wxDC
& dc
)
2497 wxColour backgroundColour
= GetBackgroundColour();
2498 if (!backgroundColour
.IsOk())
2499 backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
2501 // Clear the background
2502 dc
.SetBrush(wxBrush(backgroundColour
));
2503 dc
.SetPen(*wxTRANSPARENT_PEN
);
2504 wxRect
windowRect(GetClientSize());
2505 windowRect
.x
-= 2; windowRect
.y
-= 2;
2506 windowRect
.width
+= 4; windowRect
.height
+= 4;
2508 // We need to shift the rectangle to take into account
2509 // scrolling. Converting device to logical coordinates.
2510 CalcUnscrolledPosition(windowRect
.x
, windowRect
.y
, & windowRect
.x
, & windowRect
.y
);
2511 dc
.DrawRectangle(windowRect
);
2514 #if wxRICHTEXT_BUFFERED_PAINTING
2515 /// Recreate buffer bitmap if necessary
2516 bool wxRichTextCtrl::RecreateBuffer(const wxSize
& size
)
2519 if (sz
== wxDefaultSize
)
2520 sz
= GetClientSize();
2522 if (sz
.x
< 1 || sz
.y
< 1)
2525 if (!m_bufferBitmap
.IsOk() || m_bufferBitmap
.GetWidth() < sz
.x
|| m_bufferBitmap
.GetHeight() < sz
.y
)
2526 m_bufferBitmap
= wxBitmap(sz
.x
, sz
.y
);
2527 return m_bufferBitmap
.IsOk();
2531 // ----------------------------------------------------------------------------
2532 // file IO functions
2533 // ----------------------------------------------------------------------------
2535 bool wxRichTextCtrl::DoLoadFile(const wxString
& filename
, int fileType
)
2537 bool success
= GetBuffer().LoadFile(filename
, (wxRichTextFileType
)fileType
);
2539 m_filename
= filename
;
2542 SetInsertionPoint(0);
2545 SetupScrollbars(true);
2547 wxTextCtrl::SendTextUpdatedEvent(this);
2553 wxLogError(_("File couldn't be loaded."));
2559 bool wxRichTextCtrl::DoSaveFile(const wxString
& filename
, int fileType
)
2561 if (GetBuffer().SaveFile(filename
, (wxRichTextFileType
)fileType
))
2563 m_filename
= filename
;
2570 wxLogError(_("The text couldn't be saved."));
2575 // ----------------------------------------------------------------------------
2576 // wxRichTextCtrl specific functionality
2577 // ----------------------------------------------------------------------------
2579 /// Add a new paragraph of text to the end of the buffer
2580 wxRichTextRange
wxRichTextCtrl::AddParagraph(const wxString
& text
)
2582 wxRichTextRange range
= GetFocusObject()->AddParagraph(text
);
2583 GetBuffer().Invalidate();
2589 wxRichTextRange
wxRichTextCtrl::AddImage(const wxImage
& image
)
2591 wxRichTextRange range
= GetFocusObject()->AddImage(image
);
2592 GetBuffer().Invalidate();
2597 // ----------------------------------------------------------------------------
2598 // selection and ranges
2599 // ----------------------------------------------------------------------------
2601 void wxRichTextCtrl::SelectAll()
2603 SetSelection(-1, -1);
2607 void wxRichTextCtrl::SelectNone()
2609 if (m_selection
.IsValid())
2611 wxRichTextSelection oldSelection
= m_selection
;
2613 m_selection
.Reset();
2615 RefreshForSelectionChange(oldSelection
, m_selection
);
2617 m_selectionAnchor
= -2;
2618 m_selectionAnchorObject
= NULL
;
2619 m_selectionState
= wxRichTextCtrlSelectionState_Normal
;
2622 static bool wxIsWordDelimiter(const wxString
& text
)
2624 return !text
.IsEmpty() && !wxIsalnum(text
[0]);
2627 /// Select the word at the given character position
2628 bool wxRichTextCtrl::SelectWord(long position
)
2630 if (position
< 0 || position
> GetFocusObject()->GetOwnRange().GetEnd())
2633 wxRichTextParagraph
* para
= GetFocusObject()->GetParagraphAtPosition(position
);
2637 if (position
== para
->GetRange().GetEnd())
2640 long positionStart
= position
;
2641 long positionEnd
= position
;
2643 for (positionStart
= position
; positionStart
>= para
->GetRange().GetStart(); positionStart
--)
2645 wxString text
= GetFocusObject()->GetTextForRange(wxRichTextRange(positionStart
, positionStart
));
2646 if (wxIsWordDelimiter(text
))
2652 if (positionStart
< para
->GetRange().GetStart())
2653 positionStart
= para
->GetRange().GetStart();
2655 for (positionEnd
= position
; positionEnd
< para
->GetRange().GetEnd(); positionEnd
++)
2657 wxString text
= GetFocusObject()->GetTextForRange(wxRichTextRange(positionEnd
, positionEnd
));
2658 if (wxIsWordDelimiter(text
))
2664 if (positionEnd
>= para
->GetRange().GetEnd())
2665 positionEnd
= para
->GetRange().GetEnd();
2667 if (positionEnd
< positionStart
)
2670 SetSelection(positionStart
, positionEnd
+1);
2672 if (positionStart
>= 0)
2674 MoveCaret(positionStart
-1, true);
2675 SetDefaultStyleToCursorStyle();
2681 wxString
wxRichTextCtrl::GetStringSelection() const
2684 GetSelection(&from
, &to
);
2686 return GetRange(from
, to
);
2689 // ----------------------------------------------------------------------------
2691 // ----------------------------------------------------------------------------
2693 wxTextCtrlHitTestResult
2694 wxRichTextCtrl::HitTest(const wxPoint
& pt
, wxTextCoord
*x
, wxTextCoord
*y
) const
2696 // implement in terms of the other overload as the native ports typically
2697 // can get the position and not (x, y) pair directly (although wxUniv
2698 // directly gets x and y -- and so overrides this method as well)
2700 wxTextCtrlHitTestResult rc
= HitTest(pt
, &pos
);
2702 if ( rc
!= wxTE_HT_UNKNOWN
)
2704 PositionToXY(pos
, x
, y
);
2710 wxTextCtrlHitTestResult
2711 wxRichTextCtrl::HitTest(const wxPoint
& pt
,
2714 wxClientDC
dc((wxRichTextCtrl
*) this);
2715 ((wxRichTextCtrl
*)this)->PrepareDC(dc
);
2717 // Buffer uses logical position (relative to start of buffer)
2719 wxPoint pt2
= GetLogicalPoint(pt
);
2721 wxRichTextObject
* hitObj
= NULL
;
2722 wxRichTextObject
* contextObj
= NULL
;
2723 int hit
= ((wxRichTextCtrl
*)this)->GetFocusObject()->HitTest(dc
, pt2
, *pos
, & hitObj
, & contextObj
, wxRICHTEXT_HITTEST_NO_NESTED_OBJECTS
);
2725 if ((hit
& wxRICHTEXT_HITTEST_BEFORE
) && (hit
& wxRICHTEXT_HITTEST_OUTSIDE
))
2726 return wxTE_HT_BEFORE
;
2727 else if ((hit
& wxRICHTEXT_HITTEST_AFTER
) && (hit
& wxRICHTEXT_HITTEST_OUTSIDE
))
2728 return wxTE_HT_BEYOND
;
2729 else if (hit
& (wxRICHTEXT_HITTEST_BEFORE
|wxRICHTEXT_HITTEST_AFTER
))
2730 return wxTE_HT_ON_TEXT
;
2732 return wxTE_HT_UNKNOWN
;
2735 wxRichTextParagraphLayoutBox
*
2736 wxRichTextCtrl::FindContainerAtPoint(const wxPoint pt
, long& position
, int& hit
, wxRichTextObject
* hitObj
, int flags
/* = 0*/)
2738 wxClientDC
dc(this);
2740 dc
.SetFont(GetFont());
2742 wxPoint logicalPt
= GetLogicalPoint(pt
);
2744 wxRichTextObject
* contextObj
= NULL
;
2745 hit
= GetBuffer().HitTest(dc
, logicalPt
, position
, &hitObj
, &contextObj
, flags
);
2746 wxRichTextParagraphLayoutBox
* container
= wxDynamicCast(contextObj
, wxRichTextParagraphLayoutBox
);
2752 // ----------------------------------------------------------------------------
2753 // set/get the controls text
2754 // ----------------------------------------------------------------------------
2756 wxString
wxRichTextCtrl::DoGetValue() const
2758 return GetBuffer().GetText();
2761 wxString
wxRichTextCtrl::GetRange(long from
, long to
) const
2763 // Public API for range is different from internals
2764 return GetFocusObject()->GetTextForRange(wxRichTextRange(from
, to
-1));
2767 void wxRichTextCtrl::DoSetValue(const wxString
& value
, int flags
)
2769 // Don't call Clear here, since it always sends a text updated event
2770 m_buffer
.ResetAndClearCommands();
2771 m_buffer
.Invalidate(wxRICHTEXT_ALL
);
2772 m_caretPosition
= -1;
2773 m_caretPositionForDefaultStyle
= -2;
2774 m_caretAtLineStart
= false;
2775 m_selection
.Reset();
2776 m_selectionState
= wxRichTextCtrlSelectionState_Normal
;
2786 if (!value
.IsEmpty())
2788 // Remove empty paragraph
2789 GetBuffer().Clear();
2790 DoWriteText(value
, flags
);
2792 // for compatibility, don't move the cursor when doing SetValue()
2793 SetInsertionPoint(0);
2797 // still send an event for consistency
2798 if (flags
& SetValue_SendEvent
)
2799 wxTextCtrl::SendTextUpdatedEvent(this);
2804 void wxRichTextCtrl::WriteText(const wxString
& value
)
2809 void wxRichTextCtrl::DoWriteText(const wxString
& value
, int flags
)
2811 wxString valueUnix
= wxTextFile::Translate(value
, wxTextFileType_Unix
);
2813 GetFocusObject()->InsertTextWithUndo(& GetBuffer(), m_caretPosition
+1, valueUnix
, this, wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE
);
2815 if ( flags
& SetValue_SendEvent
)
2816 wxTextCtrl::SendTextUpdatedEvent(this);
2819 void wxRichTextCtrl::AppendText(const wxString
& text
)
2821 SetInsertionPointEnd();
2826 /// Write an image at the current insertion point
2827 bool wxRichTextCtrl::WriteImage(const wxImage
& image
, wxBitmapType bitmapType
, const wxRichTextAttr
& textAttr
)
2829 wxRichTextImageBlock imageBlock
;
2831 wxImage image2
= image
;
2832 if (imageBlock
.MakeImageBlock(image2
, bitmapType
))
2833 return WriteImage(imageBlock
, textAttr
);
2838 bool wxRichTextCtrl::WriteImage(const wxString
& filename
, wxBitmapType bitmapType
, const wxRichTextAttr
& textAttr
)
2840 wxRichTextImageBlock imageBlock
;
2843 if (imageBlock
.MakeImageBlock(filename
, bitmapType
, image
, false))
2844 return WriteImage(imageBlock
, textAttr
);
2849 bool wxRichTextCtrl::WriteImage(const wxRichTextImageBlock
& imageBlock
, const wxRichTextAttr
& textAttr
)
2851 return GetFocusObject()->InsertImageWithUndo(& GetBuffer(), m_caretPosition
+1, imageBlock
, this, 0, textAttr
);
2854 bool wxRichTextCtrl::WriteImage(const wxBitmap
& bitmap
, wxBitmapType bitmapType
, const wxRichTextAttr
& textAttr
)
2858 wxRichTextImageBlock imageBlock
;
2860 wxImage image
= bitmap
.ConvertToImage();
2861 if (image
.IsOk() && imageBlock
.MakeImageBlock(image
, bitmapType
))
2862 return WriteImage(imageBlock
, textAttr
);
2868 // Write a text box at the current insertion point.
2869 wxRichTextBox
* wxRichTextCtrl::WriteTextBox(const wxRichTextAttr
& textAttr
)
2871 wxRichTextBox
* textBox
= new wxRichTextBox
;
2872 textBox
->SetAttributes(textAttr
);
2873 textBox
->SetParent(& GetBuffer()); // set parent temporarily for AddParagraph to use correct style
2874 textBox
->AddParagraph(wxEmptyString
);
2875 textBox
->SetParent(NULL
);
2877 // The object returned is the one actually inserted into the buffer,
2878 // while the original one is deleted.
2879 wxRichTextObject
* obj
= GetFocusObject()->InsertObjectWithUndo(& GetBuffer(), m_caretPosition
+1, textBox
, this, wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE
);
2880 wxRichTextBox
* box
= wxDynamicCast(obj
, wxRichTextBox
);
2884 // Write a table at the current insertion point, returning the table.
2885 wxRichTextTable
* wxRichTextCtrl::WriteTable(int rows
, int cols
, const wxRichTextAttr
& tableAttr
, const wxRichTextAttr
& cellAttr
)
2887 wxASSERT(rows
> 0 && cols
> 0);
2889 if (rows
<= 0 || cols
<= 0)
2892 wxRichTextTable
* table
= new wxRichTextTable
;
2893 table
->SetAttributes(tableAttr
);
2894 table
->SetParent(& GetBuffer()); // set parent temporarily for AddParagraph to use correct style
2896 table
->CreateTable(rows
, cols
);
2898 table
->SetParent(NULL
);
2901 for (j
= 0; j
< rows
; j
++)
2903 for (i
= 0; i
< cols
; i
++)
2905 table
->GetCell(j
, i
)->GetAttributes() = cellAttr
;
2909 // The object returned is the one actually inserted into the buffer,
2910 // while the original one is deleted.
2911 wxRichTextObject
* obj
= GetFocusObject()->InsertObjectWithUndo(& GetBuffer(), m_caretPosition
+1, table
, this, wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE
);
2912 wxRichTextTable
* tableResult
= wxDynamicCast(obj
, wxRichTextTable
);
2917 /// Insert a newline (actually paragraph) at the current insertion point.
2918 bool wxRichTextCtrl::Newline()
2920 return GetFocusObject()->InsertNewlineWithUndo(& GetBuffer(), m_caretPosition
+1, this, wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE
);
2923 /// Insert a line break at the current insertion point.
2924 bool wxRichTextCtrl::LineBreak()
2927 text
= wxRichTextLineBreakChar
;
2928 return GetFocusObject()->InsertTextWithUndo(& GetBuffer(), m_caretPosition
+1, text
, this);
2931 // ----------------------------------------------------------------------------
2932 // Clipboard operations
2933 // ----------------------------------------------------------------------------
2935 void wxRichTextCtrl::Copy()
2939 wxRichTextRange range
= GetInternalSelectionRange();
2940 GetBuffer().CopyToClipboard(range
);
2944 void wxRichTextCtrl::Cut()
2948 wxRichTextRange range
= GetInternalSelectionRange();
2949 GetBuffer().CopyToClipboard(range
);
2951 DeleteSelectedContent();
2957 void wxRichTextCtrl::Paste()
2961 BeginBatchUndo(_("Paste"));
2963 long newPos
= m_caretPosition
;
2964 DeleteSelectedContent(& newPos
);
2966 GetBuffer().PasteFromClipboard(newPos
);
2972 void wxRichTextCtrl::DeleteSelection()
2974 if (CanDeleteSelection())
2976 DeleteSelectedContent();
2980 bool wxRichTextCtrl::HasSelection() const
2982 return (m_selection
.IsValid() && m_selection
.GetContainer() == GetFocusObject());
2985 bool wxRichTextCtrl::HasUnfocusedSelection() const
2987 return m_selection
.IsValid();
2990 bool wxRichTextCtrl::CanCopy() const
2992 // Can copy if there's a selection
2993 return HasSelection();
2996 bool wxRichTextCtrl::CanCut() const
2998 return HasSelection() && IsEditable();
3001 bool wxRichTextCtrl::CanPaste() const
3003 if ( !IsEditable() )
3006 return GetBuffer().CanPasteFromClipboard();
3009 bool wxRichTextCtrl::CanDeleteSelection() const
3011 return HasSelection() && IsEditable();
3015 // ----------------------------------------------------------------------------
3017 // ----------------------------------------------------------------------------
3019 void wxRichTextCtrl::SetContextMenu(wxMenu
* menu
)
3021 if (m_contextMenu
&& m_contextMenu
!= menu
)
3022 delete m_contextMenu
;
3023 m_contextMenu
= menu
;
3026 void wxRichTextCtrl::SetEditable(bool editable
)
3028 m_editable
= editable
;
3031 void wxRichTextCtrl::SetInsertionPoint(long pos
)
3035 m_caretPosition
= pos
- 1;
3039 SetDefaultStyleToCursorStyle();
3042 void wxRichTextCtrl::SetInsertionPointEnd()
3044 long pos
= GetLastPosition();
3045 SetInsertionPoint(pos
);
3048 long wxRichTextCtrl::GetInsertionPoint() const
3050 return m_caretPosition
+1;
3053 wxTextPos
wxRichTextCtrl::GetLastPosition() const
3055 return GetFocusObject()->GetOwnRange().GetEnd();
3058 // If the return values from and to are the same, there is no
3060 void wxRichTextCtrl::GetSelection(long* from
, long* to
) const
3062 if (m_selection
.IsValid())
3064 *from
= m_selection
.GetRange().GetStart();
3065 *to
= m_selection
.GetRange().GetEnd();
3075 bool wxRichTextCtrl::IsEditable() const
3080 // ----------------------------------------------------------------------------
3082 // ----------------------------------------------------------------------------
3084 void wxRichTextCtrl::SetSelection(long from
, long to
)
3086 // if from and to are both -1, it means (in wxWidgets) that all text should
3088 if ( (from
== -1) && (to
== -1) )
3091 to
= GetLastPosition()+1;
3100 wxRichTextSelection oldSelection
= m_selection
;
3102 m_selectionAnchor
= from
-1;
3103 m_selectionAnchorObject
= NULL
;
3104 m_selection
.Set(wxRichTextRange(from
, to
-1), GetFocusObject());
3106 m_caretPosition
= wxMax(-1, to
-1);
3108 RefreshForSelectionChange(oldSelection
, m_selection
);
3113 // ----------------------------------------------------------------------------
3115 // ----------------------------------------------------------------------------
3117 void wxRichTextCtrl::Replace(long from
, long to
,
3118 const wxString
& value
)
3120 BeginBatchUndo(_("Replace"));
3122 SetSelection(from
, to
);
3124 wxRichTextAttr attr
= GetDefaultStyle();
3126 DeleteSelectedContent();
3128 SetDefaultStyle(attr
);
3130 DoWriteText(value
, SetValue_SelectionOnly
);
3135 void wxRichTextCtrl::Remove(long from
, long to
)
3139 GetFocusObject()->DeleteRangeWithUndo(wxRichTextRange(from
, to
-1), this, & GetBuffer());
3146 bool wxRichTextCtrl::IsModified() const
3148 return m_buffer
.IsModified();
3151 void wxRichTextCtrl::MarkDirty()
3153 m_buffer
.Modify(true);
3156 void wxRichTextCtrl::DiscardEdits()
3158 m_caretPositionForDefaultStyle
= -2;
3159 m_buffer
.Modify(false);
3160 m_buffer
.GetCommandProcessor()->ClearCommands();
3163 int wxRichTextCtrl::GetNumberOfLines() const
3165 return GetFocusObject()->GetParagraphCount();
3168 // ----------------------------------------------------------------------------
3169 // Positions <-> coords
3170 // ----------------------------------------------------------------------------
3172 long wxRichTextCtrl::XYToPosition(long x
, long y
) const
3174 return GetFocusObject()->XYToPosition(x
, y
);
3177 bool wxRichTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
3179 return GetFocusObject()->PositionToXY(pos
, x
, y
);
3182 // ----------------------------------------------------------------------------
3184 // ----------------------------------------------------------------------------
3186 void wxRichTextCtrl::ShowPosition(long pos
)
3188 if (!IsPositionVisible(pos
))
3189 ScrollIntoView(pos
-1, WXK_DOWN
);
3192 int wxRichTextCtrl::GetLineLength(long lineNo
) const
3194 return GetFocusObject()->GetParagraphLength(lineNo
);
3197 wxString
wxRichTextCtrl::GetLineText(long lineNo
) const
3199 return GetFocusObject()->GetParagraphText(lineNo
);
3202 // ----------------------------------------------------------------------------
3204 // ----------------------------------------------------------------------------
3206 void wxRichTextCtrl::Undo()
3210 GetCommandProcessor()->Undo();
3214 void wxRichTextCtrl::Redo()
3218 GetCommandProcessor()->Redo();
3222 bool wxRichTextCtrl::CanUndo() const
3224 return GetCommandProcessor()->CanUndo() && IsEditable();
3227 bool wxRichTextCtrl::CanRedo() const
3229 return GetCommandProcessor()->CanRedo() && IsEditable();
3232 // ----------------------------------------------------------------------------
3233 // implementation details
3234 // ----------------------------------------------------------------------------
3236 void wxRichTextCtrl::Command(wxCommandEvent
& event
)
3238 SetValue(event
.GetString());
3239 GetEventHandler()->ProcessEvent(event
);
3242 void wxRichTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
3244 // By default, load the first file into the text window.
3245 if (event
.GetNumberOfFiles() > 0)
3247 LoadFile(event
.GetFiles()[0]);
3251 wxSize
wxRichTextCtrl::DoGetBestSize() const
3253 return wxSize(10, 10);
3256 // ----------------------------------------------------------------------------
3257 // standard handlers for standard edit menu events
3258 // ----------------------------------------------------------------------------
3260 void wxRichTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
3265 void wxRichTextCtrl::OnClear(wxCommandEvent
& WXUNUSED(event
))
3270 void wxRichTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
3275 void wxRichTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
3280 void wxRichTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
3285 void wxRichTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
3290 void wxRichTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
3292 event
.Enable( CanCut() );
3295 void wxRichTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
3297 event
.Enable( CanCopy() );
3300 void wxRichTextCtrl::OnUpdateClear(wxUpdateUIEvent
& event
)
3302 event
.Enable( CanDeleteSelection() );
3305 void wxRichTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
3307 event
.Enable( CanPaste() );
3310 void wxRichTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
3312 event
.Enable( CanUndo() );
3313 event
.SetText( GetCommandProcessor()->GetUndoMenuLabel() );
3316 void wxRichTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
3318 event
.Enable( CanRedo() );
3319 event
.SetText( GetCommandProcessor()->GetRedoMenuLabel() );
3322 void wxRichTextCtrl::OnSelectAll(wxCommandEvent
& WXUNUSED(event
))
3324 if (GetLastPosition() > 0)
3328 void wxRichTextCtrl::OnUpdateSelectAll(wxUpdateUIEvent
& event
)
3330 event
.Enable(GetLastPosition() > 0);
3333 void wxRichTextCtrl::OnProperties(wxCommandEvent
& event
)
3335 int idx
= event
.GetId() - wxID_RICHTEXT_PROPERTIES1
;
3336 if (idx
>= 0 && idx
< m_contextMenuPropertiesInfo
.GetCount())
3338 wxRichTextObject
* obj
= m_contextMenuPropertiesInfo
.GetObject(idx
);
3339 if (obj
&& obj
->CanEditProperties())
3340 obj
->EditProperties(this, & GetBuffer());
3342 m_contextMenuPropertiesInfo
.Clear();
3346 void wxRichTextCtrl::OnUpdateProperties(wxUpdateUIEvent
& event
)
3348 int idx
= event
.GetId() - wxID_RICHTEXT_PROPERTIES1
;
3349 event
.Enable(idx
>= 0 && idx
< m_contextMenuPropertiesInfo
.GetCount());
3352 void wxRichTextCtrl::OnContextMenu(wxContextMenuEvent
& event
)
3354 if (event
.GetEventObject() != this)
3360 ShowContextMenu(m_contextMenu
, event
.GetPosition());
3363 // Prepares the context menu, adding appropriate property-editing commands.
3364 // Returns the number of property commands added.
3365 int wxRichTextCtrl::PrepareContextMenu(wxMenu
* menu
, const wxPoint
& pt
, bool addPropertyCommands
)
3367 wxClientDC
dc(this);
3369 dc
.SetFont(GetFont());
3371 m_contextMenuPropertiesInfo
.Clear();
3374 wxRichTextObject
* hitObj
= NULL
;
3375 wxRichTextObject
* contextObj
= NULL
;
3376 if (pt
!= wxDefaultPosition
)
3378 wxPoint logicalPt
= GetLogicalPoint(ScreenToClient(pt
));
3379 int hit
= GetBuffer().HitTest(dc
, logicalPt
, position
, & hitObj
, & contextObj
);
3381 if (hit
== wxRICHTEXT_HITTEST_ON
|| hit
== wxRICHTEXT_HITTEST_BEFORE
|| hit
== wxRICHTEXT_HITTEST_AFTER
)
3383 wxRichTextParagraphLayoutBox
* actualContainer
= wxDynamicCast(contextObj
, wxRichTextParagraphLayoutBox
);
3384 if (hitObj
&& actualContainer
)
3386 if (actualContainer
->AcceptsFocus())
3388 SetFocusObject(actualContainer
, false /* don't set caret position yet */);
3389 SetCaretPositionAfterClick(actualContainer
, position
, hit
);
3392 if (addPropertyCommands
)
3393 m_contextMenuPropertiesInfo
.AddItems(actualContainer
, hitObj
);
3397 if (addPropertyCommands
)
3398 m_contextMenuPropertiesInfo
.AddItems(GetFocusObject(), NULL
);
3403 if (addPropertyCommands
)
3404 m_contextMenuPropertiesInfo
.AddItems(GetFocusObject(), NULL
);
3409 // Invoked from the keyboard, so don't set the caret position and don't use the event
3411 hitObj
= GetFocusObject()->GetLeafObjectAtPosition(m_caretPosition
+1);
3413 contextObj
= hitObj
->GetParentContainer();
3415 contextObj
= GetFocusObject();
3417 wxRichTextParagraphLayoutBox
* actualContainer
= wxDynamicCast(contextObj
, wxRichTextParagraphLayoutBox
);
3418 if (hitObj
&& actualContainer
)
3420 if (addPropertyCommands
)
3421 m_contextMenuPropertiesInfo
.AddItems(actualContainer
, hitObj
);
3425 if (addPropertyCommands
)
3426 m_contextMenuPropertiesInfo
.AddItems(GetFocusObject(), NULL
);
3432 if (addPropertyCommands
)
3433 m_contextMenuPropertiesInfo
.AddMenuItems(menu
);
3434 return m_contextMenuPropertiesInfo
.GetCount();
3440 // Shows the context menu, adding appropriate property-editing commands
3441 bool wxRichTextCtrl::ShowContextMenu(wxMenu
* menu
, const wxPoint
& pt
, bool addPropertyCommands
)
3445 PrepareContextMenu(menu
, pt
, addPropertyCommands
);
3453 bool wxRichTextCtrl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
3455 return GetFocusObject()->SetStyle(wxRichTextRange(start
, end
-1), wxRichTextAttr(style
));
3458 bool wxRichTextCtrl::SetStyle(long start
, long end
, const wxRichTextAttr
& style
)
3460 return GetFocusObject()->SetStyle(wxRichTextRange(start
, end
-1), style
);
3463 bool wxRichTextCtrl::SetStyle(const wxRichTextRange
& range
, const wxTextAttr
& style
)
3465 return GetFocusObject()->SetStyle(range
.ToInternal(), wxRichTextAttr(style
));
3468 bool wxRichTextCtrl::SetStyle(const wxRichTextRange
& range
, const wxRichTextAttr
& style
)
3470 return GetFocusObject()->SetStyle(range
.ToInternal(), style
);
3473 void wxRichTextCtrl::SetStyle(wxRichTextObject
*obj
, const wxRichTextAttr
& textAttr
)
3475 GetFocusObject()->SetStyle(obj
, textAttr
);
3478 // extended style setting operation with flags including:
3479 // wxRICHTEXT_SETSTYLE_WITH_UNDO, wxRICHTEXT_SETSTYLE_OPTIMIZE, wxRICHTEXT_SETSTYLE_PARAGRAPHS_ONLY.
3480 // see richtextbuffer.h for more details.
3482 bool wxRichTextCtrl::SetStyleEx(const wxRichTextRange
& range
, const wxRichTextAttr
& style
, int flags
)
3484 return GetFocusObject()->SetStyle(range
.ToInternal(), style
, flags
);
3487 bool wxRichTextCtrl::SetDefaultStyle(const wxTextAttr
& style
)
3489 return GetBuffer().SetDefaultStyle(style
);
3492 bool wxRichTextCtrl::SetDefaultStyle(const wxRichTextAttr
& style
)
3494 wxRichTextAttr
attr1(style
);
3495 attr1
.GetTextBoxAttr().Reset();
3496 return GetBuffer().SetDefaultStyle(attr1
);
3499 const wxRichTextAttr
& wxRichTextCtrl::GetDefaultStyleEx() const
3501 return GetBuffer().GetDefaultStyle();
3504 bool wxRichTextCtrl::GetStyle(long position
, wxTextAttr
& style
)
3506 wxRichTextAttr attr
;
3507 if (GetFocusObject()->GetStyle(position
, attr
))
3516 bool wxRichTextCtrl::GetStyle(long position
, wxRichTextAttr
& style
)
3518 return GetFocusObject()->GetStyle(position
, style
);
3521 bool wxRichTextCtrl::GetStyle(long position
, wxRichTextAttr
& style
, wxRichTextParagraphLayoutBox
* container
)
3523 wxRichTextAttr attr
;
3524 if (container
->GetStyle(position
, attr
))
3533 // get the common set of styles for the range
3534 bool wxRichTextCtrl::GetStyleForRange(const wxRichTextRange
& range
, wxTextAttr
& style
)
3536 wxRichTextAttr attr
;
3537 if (GetFocusObject()->GetStyleForRange(range
.ToInternal(), attr
))
3546 bool wxRichTextCtrl::GetStyleForRange(const wxRichTextRange
& range
, wxRichTextAttr
& style
)
3548 return GetFocusObject()->GetStyleForRange(range
.ToInternal(), style
);
3551 bool wxRichTextCtrl::GetStyleForRange(const wxRichTextRange
& range
, wxRichTextAttr
& style
, wxRichTextParagraphLayoutBox
* container
)
3553 return container
->GetStyleForRange(range
.ToInternal(), style
);
3556 /// Get the content (uncombined) attributes for this position.
3557 bool wxRichTextCtrl::GetUncombinedStyle(long position
, wxRichTextAttr
& style
)
3559 return GetFocusObject()->GetUncombinedStyle(position
, style
);
3562 /// Get the content (uncombined) attributes for this position.
3563 bool wxRichTextCtrl::GetUncombinedStyle(long position
, wxRichTextAttr
& style
, wxRichTextParagraphLayoutBox
* container
)
3565 return container
->GetUncombinedStyle(position
, style
);
3568 /// Set font, and also the buffer attributes
3569 bool wxRichTextCtrl::SetFont(const wxFont
& font
)
3571 wxControl::SetFont(font
);
3573 wxRichTextAttr attr
= GetBuffer().GetAttributes();
3575 GetBuffer().SetBasicStyle(attr
);
3577 GetBuffer().Invalidate(wxRICHTEXT_ALL
);
3583 /// Transform logical to physical
3584 wxPoint
wxRichTextCtrl::GetPhysicalPoint(const wxPoint
& ptLogical
) const
3587 CalcScrolledPosition(ptLogical
.x
, ptLogical
.y
, & pt
.x
, & pt
.y
);
3592 /// Transform physical to logical
3593 wxPoint
wxRichTextCtrl::GetLogicalPoint(const wxPoint
& ptPhysical
) const
3596 CalcUnscrolledPosition(ptPhysical
.x
, ptPhysical
.y
, & pt
.x
, & pt
.y
);
3601 /// Position the caret
3602 void wxRichTextCtrl::PositionCaret(wxRichTextParagraphLayoutBox
* container
)
3607 //wxLogDebug(wxT("PositionCaret"));
3610 if (GetCaretPositionForIndex(GetCaretPosition(), caretRect
, container
))
3612 wxPoint newPt
= caretRect
.GetPosition();
3613 wxSize newSz
= caretRect
.GetSize();
3614 wxPoint pt
= GetPhysicalPoint(newPt
);
3615 if (GetCaret()->GetPosition() != pt
|| GetCaret()->GetSize() != newSz
)
3618 if (GetCaret()->GetSize() != newSz
)
3619 GetCaret()->SetSize(newSz
);
3621 // Adjust size so the caret size and position doesn't appear in the margins
3622 if (((pt
.y
+ newSz
.y
) <= GetBuffer().GetTopMargin()) || (pt
.y
>= (GetClientSize().y
- GetBuffer().GetBottomMargin())))
3627 else if (pt
.y
< GetBuffer().GetTopMargin() && (pt
.y
+ newSz
.y
) > GetBuffer().GetTopMargin())
3629 newSz
.y
-= (GetBuffer().GetTopMargin() - pt
.y
);
3632 pt
.y
= GetBuffer().GetTopMargin();
3633 GetCaret()->SetSize(newSz
);
3636 else if (pt
.y
< (GetClientSize().y
- GetBuffer().GetBottomMargin()) && (pt
.y
+ newSz
.y
) > (GetClientSize().y
- GetBuffer().GetBottomMargin()))
3638 newSz
.y
= GetClientSize().y
- GetBuffer().GetBottomMargin() - pt
.y
;
3639 GetCaret()->SetSize(newSz
);
3642 GetCaret()->Move(pt
);
3648 /// Get the caret height and position for the given character position
3649 bool wxRichTextCtrl::GetCaretPositionForIndex(long position
, wxRect
& rect
, wxRichTextParagraphLayoutBox
* container
)
3651 wxClientDC
dc(this);
3652 dc
.SetFont(GetFont());
3660 container
= GetFocusObject();
3662 if (container
->FindPosition(dc
, position
, pt
, & height
, m_caretAtLineStart
))
3664 // Caret height can't be zero
3666 height
= dc
.GetCharHeight();
3668 rect
= wxRect(pt
, wxSize(wxRICHTEXT_DEFAULT_CARET_WIDTH
, height
));
3675 /// Gets the line for the visible caret position. If the caret is
3676 /// shown at the very end of the line, it means the next character is actually
3677 /// on the following line. So let's get the line we're expecting to find
3678 /// if this is the case.
3679 wxRichTextLine
* wxRichTextCtrl::GetVisibleLineForCaretPosition(long caretPosition
) const
3681 wxRichTextLine
* line
= GetFocusObject()->GetLineAtPosition(caretPosition
, true);
3682 wxRichTextParagraph
* para
= GetFocusObject()->GetParagraphAtPosition(caretPosition
, true);
3685 wxRichTextRange lineRange
= line
->GetAbsoluteRange();
3686 if (caretPosition
== lineRange
.GetStart()-1 &&
3687 (para
->GetRange().GetStart() != lineRange
.GetStart()))
3689 if (!m_caretAtLineStart
)
3690 line
= GetFocusObject()->GetLineAtPosition(caretPosition
-1, true);
3697 /// Move the caret to the given character position
3698 bool wxRichTextCtrl::MoveCaret(long pos
, bool showAtLineStart
, wxRichTextParagraphLayoutBox
* container
)
3700 if (GetBuffer().IsDirty())
3704 container
= GetFocusObject();
3706 if (pos
<= container
->GetOwnRange().GetEnd())
3708 SetCaretPosition(pos
, showAtLineStart
);
3710 PositionCaret(container
);
3718 /// Layout the buffer: which we must do before certain operations, such as
3719 /// setting the caret position.
3720 bool wxRichTextCtrl::LayoutContent(bool onlyVisibleRect
)
3722 if (GetBuffer().IsDirty() || onlyVisibleRect
)
3724 wxRect
availableSpace(GetClientSize());
3725 if (availableSpace
.width
== 0)
3726 availableSpace
.width
= 10;
3727 if (availableSpace
.height
== 0)
3728 availableSpace
.height
= 10;
3730 int flags
= wxRICHTEXT_FIXED_WIDTH
|wxRICHTEXT_VARIABLE_HEIGHT
;
3731 if (onlyVisibleRect
)
3733 flags
|= wxRICHTEXT_LAYOUT_SPECIFIED_RECT
;
3734 availableSpace
.SetPosition(GetLogicalPoint(wxPoint(0, 0)));
3737 wxClientDC
dc(this);
3738 dc
.SetFont(GetFont());
3742 GetBuffer().Defragment();
3743 GetBuffer().UpdateRanges(); // If items were deleted, ranges need recalculation
3744 GetBuffer().Layout(dc
, availableSpace
, flags
);
3745 GetBuffer().Invalidate(wxRICHTEXT_NONE
);
3754 /// Is all of the selection, or the current caret position, bold?
3755 bool wxRichTextCtrl::IsSelectionBold()
3759 wxRichTextAttr attr
;
3760 wxRichTextRange range
= GetSelectionRange();
3761 attr
.SetFlags(wxTEXT_ATTR_FONT_WEIGHT
);
3762 attr
.SetFontWeight(wxFONTWEIGHT_BOLD
);
3764 return HasCharacterAttributes(range
, attr
);
3768 // If no selection, then we need to combine current style with default style
3769 // to see what the effect would be if we started typing.
3770 wxRichTextAttr attr
;
3771 attr
.SetFlags(wxTEXT_ATTR_FONT_WEIGHT
);
3773 long pos
= GetAdjustedCaretPosition(GetCaretPosition());
3774 if (GetStyle(pos
, attr
))
3776 if (IsDefaultStyleShowing())
3777 wxRichTextApplyStyle(attr
, GetDefaultStyleEx());
3778 return attr
.GetFontWeight() == wxFONTWEIGHT_BOLD
;
3784 /// Is all of the selection, or the current caret position, italics?
3785 bool wxRichTextCtrl::IsSelectionItalics()
3789 wxRichTextRange range
= GetSelectionRange();
3790 wxRichTextAttr attr
;
3791 attr
.SetFlags(wxTEXT_ATTR_FONT_ITALIC
);
3792 attr
.SetFontStyle(wxFONTSTYLE_ITALIC
);
3794 return HasCharacterAttributes(range
, attr
);
3798 // If no selection, then we need to combine current style with default style
3799 // to see what the effect would be if we started typing.
3800 wxRichTextAttr attr
;
3801 attr
.SetFlags(wxTEXT_ATTR_FONT_ITALIC
);
3803 long pos
= GetAdjustedCaretPosition(GetCaretPosition());
3804 if (GetStyle(pos
, attr
))
3806 if (IsDefaultStyleShowing())
3807 wxRichTextApplyStyle(attr
, GetDefaultStyleEx());
3808 return attr
.GetFontStyle() == wxFONTSTYLE_ITALIC
;
3814 /// Is all of the selection, or the current caret position, underlined?
3815 bool wxRichTextCtrl::IsSelectionUnderlined()
3819 wxRichTextRange range
= GetSelectionRange();
3820 wxRichTextAttr attr
;
3821 attr
.SetFlags(wxTEXT_ATTR_FONT_UNDERLINE
);
3822 attr
.SetFontUnderlined(true);
3824 return HasCharacterAttributes(range
, attr
);
3828 // If no selection, then we need to combine current style with default style
3829 // to see what the effect would be if we started typing.
3830 wxRichTextAttr attr
;
3831 attr
.SetFlags(wxTEXT_ATTR_FONT_UNDERLINE
);
3832 long pos
= GetAdjustedCaretPosition(GetCaretPosition());
3834 if (GetStyle(pos
, attr
))
3836 if (IsDefaultStyleShowing())
3837 wxRichTextApplyStyle(attr
, GetDefaultStyleEx());
3838 return attr
.GetFontUnderlined();
3844 /// Does all of the selection, or the current caret position, have this wxTextAttrEffects flag(s)?
3845 bool wxRichTextCtrl::DoesSelectionHaveTextEffectFlag(int flag
)
3847 wxRichTextAttr attr
;
3848 attr
.SetFlags(wxTEXT_ATTR_EFFECTS
);
3849 attr
.SetTextEffectFlags(flag
);
3850 attr
.SetTextEffects(flag
);
3854 return HasCharacterAttributes(GetSelectionRange(), attr
);
3858 // If no selection, then we need to combine current style with default style
3859 // to see what the effect would be if we started typing.
3860 long pos
= GetAdjustedCaretPosition(GetCaretPosition());
3861 if (GetStyle(pos
, attr
))
3863 if (IsDefaultStyleShowing())
3864 wxRichTextApplyStyle(attr
, GetDefaultStyleEx());
3865 return (attr
.GetTextEffectFlags() & flag
) != 0;
3871 /// Apply bold to the selection
3872 bool wxRichTextCtrl::ApplyBoldToSelection()
3874 wxRichTextAttr attr
;
3875 attr
.SetFlags(wxTEXT_ATTR_FONT_WEIGHT
);
3876 attr
.SetFontWeight(IsSelectionBold() ? wxFONTWEIGHT_NORMAL
: wxFONTWEIGHT_BOLD
);
3879 return SetStyleEx(GetSelectionRange(), attr
, wxRICHTEXT_SETSTYLE_WITH_UNDO
|wxRICHTEXT_SETSTYLE_OPTIMIZE
|wxRICHTEXT_SETSTYLE_CHARACTERS_ONLY
);
3882 wxRichTextAttr current
= GetDefaultStyleEx();
3883 current
.Apply(attr
);
3884 SetAndShowDefaultStyle(current
);
3889 /// Apply italic to the selection
3890 bool wxRichTextCtrl::ApplyItalicToSelection()
3892 wxRichTextAttr attr
;
3893 attr
.SetFlags(wxTEXT_ATTR_FONT_ITALIC
);
3894 attr
.SetFontStyle(IsSelectionItalics() ? wxFONTSTYLE_NORMAL
: wxFONTSTYLE_ITALIC
);
3897 return SetStyleEx(GetSelectionRange(), attr
, wxRICHTEXT_SETSTYLE_WITH_UNDO
|wxRICHTEXT_SETSTYLE_OPTIMIZE
|wxRICHTEXT_SETSTYLE_CHARACTERS_ONLY
);
3900 wxRichTextAttr current
= GetDefaultStyleEx();
3901 current
.Apply(attr
);
3902 SetAndShowDefaultStyle(current
);
3907 /// Apply underline to the selection
3908 bool wxRichTextCtrl::ApplyUnderlineToSelection()
3910 wxRichTextAttr attr
;
3911 attr
.SetFlags(wxTEXT_ATTR_FONT_UNDERLINE
);
3912 attr
.SetFontUnderlined(!IsSelectionUnderlined());
3915 return SetStyleEx(GetSelectionRange(), attr
, wxRICHTEXT_SETSTYLE_WITH_UNDO
|wxRICHTEXT_SETSTYLE_OPTIMIZE
|wxRICHTEXT_SETSTYLE_CHARACTERS_ONLY
);
3918 wxRichTextAttr current
= GetDefaultStyleEx();
3919 current
.Apply(attr
);
3920 SetAndShowDefaultStyle(current
);
3925 /// Apply the wxTextAttrEffects flag(s) to the selection, or the current caret position if there's no selection
3926 bool wxRichTextCtrl::ApplyTextEffectToSelection(int flags
)
3928 wxRichTextAttr attr
;
3929 attr
.SetFlags(wxTEXT_ATTR_EFFECTS
);
3930 attr
.SetTextEffectFlags(flags
);
3931 if (!DoesSelectionHaveTextEffectFlag(flags
))
3932 attr
.SetTextEffects(flags
);
3934 attr
.SetTextEffects(attr
.GetTextEffectFlags() & ~flags
);
3937 return SetStyleEx(GetSelectionRange(), attr
, wxRICHTEXT_SETSTYLE_WITH_UNDO
|wxRICHTEXT_SETSTYLE_OPTIMIZE
|wxRICHTEXT_SETSTYLE_CHARACTERS_ONLY
);
3940 wxRichTextAttr current
= GetDefaultStyleEx();
3941 current
.Apply(attr
);
3942 SetAndShowDefaultStyle(current
);
3947 /// Is all of the selection aligned according to the specified flag?
3948 bool wxRichTextCtrl::IsSelectionAligned(wxTextAttrAlignment alignment
)
3950 wxRichTextRange range
;
3952 range
= GetSelectionRange();
3954 range
= wxRichTextRange(GetCaretPosition()+1, GetCaretPosition()+2);
3956 wxRichTextAttr attr
;
3957 attr
.SetAlignment(alignment
);
3959 return HasParagraphAttributes(range
, attr
);
3962 /// Apply alignment to the selection
3963 bool wxRichTextCtrl::ApplyAlignmentToSelection(wxTextAttrAlignment alignment
)
3965 wxRichTextAttr attr
;
3966 attr
.SetAlignment(alignment
);
3968 return SetStyle(GetSelectionRange(), attr
);
3971 wxRichTextParagraph
* para
= GetFocusObject()->GetParagraphAtPosition(GetCaretPosition()+1);
3973 return SetStyleEx(para
->GetRange().FromInternal(), attr
, wxRICHTEXT_SETSTYLE_WITH_UNDO
|wxRICHTEXT_SETSTYLE_OPTIMIZE
|wxRICHTEXT_SETSTYLE_PARAGRAPHS_ONLY
);
3978 /// Apply a named style to the selection
3979 bool wxRichTextCtrl::ApplyStyle(wxRichTextStyleDefinition
* def
)
3981 // Flags are defined within each definition, so only certain
3982 // attributes are applied.
3983 wxRichTextAttr
attr(GetStyleSheet() ? def
->GetStyleMergedWithBase(GetStyleSheet()) : def
->GetStyle());
3985 int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
|wxRICHTEXT_SETSTYLE_OPTIMIZE
|wxRICHTEXT_SETSTYLE_RESET
;
3987 if (def
->IsKindOf(CLASSINFO(wxRichTextListStyleDefinition
)))
3989 flags
|= wxRICHTEXT_SETSTYLE_PARAGRAPHS_ONLY
;
3991 wxRichTextRange range
;
3994 range
= GetSelectionRange();
3997 long pos
= GetAdjustedCaretPosition(GetCaretPosition());
3998 range
= wxRichTextRange(pos
, pos
+1);
4001 return SetListStyle(range
, (wxRichTextListStyleDefinition
*) def
, flags
);
4004 bool isPara
= false;
4006 // Make sure the attr has the style name
4007 if (def
->IsKindOf(CLASSINFO(wxRichTextParagraphStyleDefinition
)))
4010 attr
.SetParagraphStyleName(def
->GetName());
4012 // If applying a paragraph style, we only want the paragraph nodes to adopt these
4013 // attributes, and not the leaf nodes. This will allow the content (e.g. text)
4014 // to change its style independently.
4015 flags
|= wxRICHTEXT_SETSTYLE_PARAGRAPHS_ONLY
;
4017 else if (def
->IsKindOf(CLASSINFO(wxRichTextCharacterStyleDefinition
)))
4018 attr
.SetCharacterStyleName(def
->GetName());
4019 else if (def
->IsKindOf(CLASSINFO(wxRichTextBoxStyleDefinition
)))
4020 attr
.GetTextBoxAttr().SetBoxStyleName(def
->GetName());
4022 if (def
->IsKindOf(CLASSINFO(wxRichTextBoxStyleDefinition
)))
4024 if (GetFocusObject() && (GetFocusObject() != & GetBuffer()))
4026 SetStyle(GetFocusObject(), attr
);
4032 else if (HasSelection())
4033 return SetStyleEx(GetSelectionRange(), attr
, flags
);
4036 wxRichTextAttr current
= GetDefaultStyleEx();
4037 wxRichTextAttr
defaultStyle(attr
);
4040 // Don't apply extra character styles since they are already implied
4041 // in the paragraph style
4042 defaultStyle
.SetFlags(defaultStyle
.GetFlags() & ~wxTEXT_ATTR_CHARACTER
);
4044 current
.Apply(defaultStyle
);
4045 SetAndShowDefaultStyle(current
);
4047 // If it's a paragraph style, we want to apply the style to the
4048 // current paragraph even if we didn't select any text.
4051 long pos
= GetAdjustedCaretPosition(GetCaretPosition());
4052 wxRichTextParagraph
* para
= GetFocusObject()->GetParagraphAtPosition(pos
);
4055 return SetStyleEx(para
->GetRange().FromInternal(), attr
, flags
);
4062 /// Apply the style sheet to the buffer, for example if the styles have changed.
4063 bool wxRichTextCtrl::ApplyStyleSheet(wxRichTextStyleSheet
* styleSheet
)
4066 styleSheet
= GetBuffer().GetStyleSheet();
4070 if (GetBuffer().ApplyStyleSheet(styleSheet
))
4072 GetBuffer().Invalidate(wxRICHTEXT_ALL
);
4080 /// Sets the default style to the style under the cursor
4081 bool wxRichTextCtrl::SetDefaultStyleToCursorStyle()
4083 wxRichTextAttr attr
;
4084 attr
.SetFlags(wxTEXT_ATTR_CHARACTER
);
4086 // If at the start of a paragraph, use the next position.
4087 long pos
= GetAdjustedCaretPosition(GetCaretPosition());
4089 wxRichTextObject
* obj
= GetFocusObject()->GetLeafObjectAtPosition(pos
);
4090 if (obj
&& obj
->IsTopLevel())
4092 // Don't use the attributes of a top-level object, since they might apply
4093 // to content of the object, e.g. background colour.
4094 SetDefaultStyle(wxRichTextAttr());
4097 else if (GetUncombinedStyle(pos
, attr
))
4099 SetDefaultStyle(attr
);
4106 /// Returns the first visible position in the current view
4107 long wxRichTextCtrl::GetFirstVisiblePosition() const
4109 wxRichTextLine
* line
= GetFocusObject()->GetLineAtYPosition(GetLogicalPoint(wxPoint(0, 0)).y
);
4111 return line
->GetAbsoluteRange().GetStart();
4116 /// Get the first visible point in the window
4117 wxPoint
wxRichTextCtrl::GetFirstVisiblePoint() const
4120 int startXUnits
, startYUnits
;
4122 GetScrollPixelsPerUnit(& ppuX
, & ppuY
);
4123 GetViewStart(& startXUnits
, & startYUnits
);
4125 return wxPoint(startXUnits
* ppuX
, startYUnits
* ppuY
);
4128 /// The adjusted caret position is the character position adjusted to take
4129 /// into account whether we're at the start of a paragraph, in which case
4130 /// style information should be taken from the next position, not current one.
4131 long wxRichTextCtrl::GetAdjustedCaretPosition(long caretPos
) const
4133 wxRichTextParagraph
* para
= GetFocusObject()->GetParagraphAtPosition(caretPos
+1);
4135 if (para
&& (caretPos
+1 == para
->GetRange().GetStart()))
4140 /// Get/set the selection range in character positions. -1, -1 means no selection.
4141 /// The range is in API convention, i.e. a single character selection is denoted
4143 wxRichTextRange
wxRichTextCtrl::GetSelectionRange() const
4145 wxRichTextRange range
= GetInternalSelectionRange();
4146 if (range
!= wxRichTextRange(-2,-2) && range
!= wxRichTextRange(-1,-1))
4147 range
.SetEnd(range
.GetEnd() + 1);
4151 void wxRichTextCtrl::SetSelectionRange(const wxRichTextRange
& range
)
4153 SetSelection(range
.GetStart(), range
.GetEnd());
4157 bool wxRichTextCtrl::SetListStyle(const wxRichTextRange
& range
, wxRichTextListStyleDefinition
* def
, int flags
, int startFrom
, int specifiedLevel
)
4159 return GetFocusObject()->SetListStyle(range
.ToInternal(), def
, flags
, startFrom
, specifiedLevel
);
4162 bool wxRichTextCtrl::SetListStyle(const wxRichTextRange
& range
, const wxString
& defName
, int flags
, int startFrom
, int specifiedLevel
)
4164 return GetFocusObject()->SetListStyle(range
.ToInternal(), defName
, flags
, startFrom
, specifiedLevel
);
4167 /// Clear list for given range
4168 bool wxRichTextCtrl::ClearListStyle(const wxRichTextRange
& range
, int flags
)
4170 return GetFocusObject()->ClearListStyle(range
.ToInternal(), flags
);
4173 /// Number/renumber any list elements in the given range
4174 bool wxRichTextCtrl::NumberList(const wxRichTextRange
& range
, wxRichTextListStyleDefinition
* def
, int flags
, int startFrom
, int specifiedLevel
)
4176 return GetFocusObject()->NumberList(range
.ToInternal(), def
, flags
, startFrom
, specifiedLevel
);
4179 bool wxRichTextCtrl::NumberList(const wxRichTextRange
& range
, const wxString
& defName
, int flags
, int startFrom
, int specifiedLevel
)
4181 return GetFocusObject()->NumberList(range
.ToInternal(), defName
, flags
, startFrom
, specifiedLevel
);
4184 /// Promote the list items within the given range. promoteBy can be a positive or negative number, e.g. 1 or -1
4185 bool wxRichTextCtrl::PromoteList(int promoteBy
, const wxRichTextRange
& range
, wxRichTextListStyleDefinition
* def
, int flags
, int specifiedLevel
)
4187 return GetFocusObject()->PromoteList(promoteBy
, range
.ToInternal(), def
, flags
, specifiedLevel
);
4190 bool wxRichTextCtrl::PromoteList(int promoteBy
, const wxRichTextRange
& range
, const wxString
& defName
, int flags
, int specifiedLevel
)
4192 return GetFocusObject()->PromoteList(promoteBy
, range
.ToInternal(), defName
, flags
, specifiedLevel
);
4195 /// Deletes the content in the given range
4196 bool wxRichTextCtrl::Delete(const wxRichTextRange
& range
)
4198 return GetFocusObject()->DeleteRangeWithUndo(range
.ToInternal(), this, & GetBuffer());
4201 const wxArrayString
& wxRichTextCtrl::GetAvailableFontNames()
4203 if (sm_availableFontNames
.GetCount() == 0)
4205 sm_availableFontNames
= wxFontEnumerator::GetFacenames();
4206 sm_availableFontNames
.Sort();
4208 return sm_availableFontNames
;
4211 void wxRichTextCtrl::ClearAvailableFontNames()
4213 sm_availableFontNames
.Clear();
4216 void wxRichTextCtrl::OnSysColourChanged(wxSysColourChangedEvent
& WXUNUSED(event
))
4218 //wxLogDebug(wxT("wxRichTextCtrl::OnSysColourChanged"));
4220 wxTextAttrEx basicStyle
= GetBasicStyle();
4221 basicStyle
.SetTextColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
));
4222 SetBasicStyle(basicStyle
);
4223 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
4228 // Refresh the area affected by a selection change
4229 bool wxRichTextCtrl::RefreshForSelectionChange(const wxRichTextSelection
& oldSelection
, const wxRichTextSelection
& newSelection
)
4231 // If the selection is not part of the focus object, or we have multiple ranges, then the chances are that
4232 // the selection contains whole containers rather than just text, so refresh everything
4233 // for now as it would be hard to compute the rectangle bounding all selections.
4234 // TODO: improve on this.
4235 if ((oldSelection
.IsValid() && (oldSelection
.GetContainer() != GetFocusObject() || oldSelection
.GetCount() > 1)) ||
4236 (newSelection
.IsValid() && (newSelection
.GetContainer() != GetFocusObject() || newSelection
.GetCount() > 1)))
4242 wxRichTextRange oldRange
, newRange
;
4243 if (oldSelection
.IsValid())
4244 oldRange
= oldSelection
.GetRange();
4246 oldRange
= wxRICHTEXT_NO_SELECTION
;
4247 if (newSelection
.IsValid())
4248 newRange
= newSelection
.GetRange();
4250 newRange
= wxRICHTEXT_NO_SELECTION
;
4252 // Calculate the refresh rectangle - just the affected lines
4253 long firstPos
, lastPos
;
4254 if (oldRange
.GetStart() == -2 && newRange
.GetStart() != -2)
4256 firstPos
= newRange
.GetStart();
4257 lastPos
= newRange
.GetEnd();
4259 else if (oldRange
.GetStart() != -2 && newRange
.GetStart() == -2)
4261 firstPos
= oldRange
.GetStart();
4262 lastPos
= oldRange
.GetEnd();
4264 else if (oldRange
.GetStart() == -2 && newRange
.GetStart() == -2)
4270 firstPos
= wxMin(oldRange
.GetStart(), newRange
.GetStart());
4271 lastPos
= wxMax(oldRange
.GetEnd(), newRange
.GetEnd());
4274 wxRichTextLine
* firstLine
= GetFocusObject()->GetLineAtPosition(firstPos
);
4275 wxRichTextLine
* lastLine
= GetFocusObject()->GetLineAtPosition(lastPos
);
4277 if (firstLine
&& lastLine
)
4279 wxSize clientSize
= GetClientSize();
4280 wxPoint pt1
= GetPhysicalPoint(firstLine
->GetAbsolutePosition());
4281 wxPoint pt2
= GetPhysicalPoint(lastLine
->GetAbsolutePosition()) + wxPoint(0, lastLine
->GetSize().y
);
4284 pt1
.y
= wxMax(0, pt1
.y
);
4286 pt2
.y
= wxMin(clientSize
.y
, pt2
.y
);
4288 wxRect
rect(pt1
, wxSize(clientSize
.x
, pt2
.y
- pt1
.y
));
4289 RefreshRect(rect
, false);
4297 // margins functions
4298 bool wxRichTextCtrl::DoSetMargins(const wxPoint
& pt
)
4300 GetBuffer().GetAttributes().GetTextBoxAttr().GetMargins().GetLeft().SetValue(pt
.x
, wxTEXT_ATTR_UNITS_PIXELS
);
4301 GetBuffer().GetAttributes().GetTextBoxAttr().GetMargins().GetRight().SetValue(pt
.x
, wxTEXT_ATTR_UNITS_PIXELS
);
4302 GetBuffer().GetAttributes().GetTextBoxAttr().GetMargins().GetTop().SetValue(pt
.y
, wxTEXT_ATTR_UNITS_PIXELS
);
4303 GetBuffer().GetAttributes().GetTextBoxAttr().GetMargins().GetBottom().SetValue(pt
.y
, wxTEXT_ATTR_UNITS_PIXELS
);
4308 wxPoint
wxRichTextCtrl::DoGetMargins() const
4310 return wxPoint(GetBuffer().GetAttributes().GetTextBoxAttr().GetMargins().GetLeft().GetValue(),
4311 GetBuffer().GetAttributes().GetTextBoxAttr().GetMargins().GetTop().GetValue());
4314 bool wxRichTextCtrl::SetFocusObject(wxRichTextParagraphLayoutBox
* obj
, bool setCaretPosition
)
4316 if (obj
&& !obj
->AcceptsFocus())
4319 wxRichTextParagraphLayoutBox
* oldContainer
= GetFocusObject();
4320 bool changingContainer
= (m_focusObject
!= obj
);
4322 if (changingContainer
&& HasSelection())
4325 m_focusObject
= obj
;
4328 m_focusObject
= & m_buffer
;
4330 if (setCaretPosition
&& changingContainer
)
4332 m_selection
.Reset();
4333 m_selectionAnchor
= -2;
4334 m_selectionAnchorObject
= NULL
;
4335 m_selectionState
= wxRichTextCtrlSelectionState_Normal
;
4339 m_caretAtLineStart
= false;
4340 MoveCaret(pos
, m_caretAtLineStart
);
4341 SetDefaultStyleToCursorStyle();
4343 wxRichTextEvent
cmdEvent(
4344 wxEVT_COMMAND_RICHTEXT_FOCUS_OBJECT_CHANGED
,
4346 cmdEvent
.SetEventObject(this);
4347 cmdEvent
.SetPosition(m_caretPosition
+1);
4348 cmdEvent
.SetOldContainer(oldContainer
);
4349 cmdEvent
.SetContainer(m_focusObject
);
4351 GetEventHandler()->ProcessEvent(cmdEvent
);
4356 #if wxUSE_DRAG_AND_DROP
4357 void wxRichTextCtrl::OnDrop(wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
), wxDragResult def
, wxDataObject
* DataObj
)
4361 if ((def
!= wxDragCopy
) && (def
!= wxDragMove
))
4366 if (!GetSelection().IsValid())
4371 wxRichTextParagraphLayoutBox
* originContainer
= GetSelection().GetContainer();
4372 wxRichTextParagraphLayoutBox
* destContainer
= GetFocusObject(); // This will be the drop container, not necessarily the same as the origin one
4375 wxRichTextBuffer
* richTextBuffer
= ((wxRichTextBufferDataObject
*)DataObj
)->GetRichTextBuffer();
4378 long position
= GetCaretPosition();
4379 wxRichTextRange selectionrange
= GetInternalSelectionRange();
4380 if (selectionrange
.Contains(position
) && (def
== wxDragMove
))
4382 // It doesn't make sense to move onto itself
4386 // If we're moving, and the data is being moved forward, we need to drop first, then delete the selection
4387 // If moving backwards, we need to delete then drop. If we're copying (or doing nothing) we don't delete anyway
4388 bool DeleteAfter
= (def
== wxDragMove
) && (position
> selectionrange
.GetEnd());
4389 if ((def
== wxDragMove
) && !DeleteAfter
)
4391 // We can't use e.g. DeleteSelectedContent() as it uses the focus container
4392 originContainer
->DeleteRangeWithUndo(selectionrange
, this, &GetBuffer());
4395 destContainer
->InsertParagraphsWithUndo(&GetBuffer(), position
+1, *richTextBuffer
, this, 0);
4396 ShowPosition(position
+ richTextBuffer
->GetOwnRange().GetEnd());
4398 delete richTextBuffer
;
4402 // We can't use e.g. DeleteSelectedContent() as it uses the focus container
4403 originContainer
->DeleteRangeWithUndo(selectionrange
, this, &GetBuffer());
4411 #endif // wxUSE_DRAG_AND_DROP
4414 #if wxUSE_DRAG_AND_DROP
4415 bool wxRichTextDropSource::GiveFeedback(wxDragResult
WXUNUSED(effect
))
4417 wxCHECK_MSG(m_rtc
, false, wxT("NULL m_rtc"));
4421 wxRichTextObject
* hitObj
= NULL
;
4422 wxRichTextParagraphLayoutBox
* container
= m_rtc
->FindContainerAtPoint(m_rtc
->ScreenToClient(wxGetMousePosition()), position
, hit
, hitObj
);
4424 if (!(hit
& wxRICHTEXT_HITTEST_NONE
) && container
&& container
->AcceptsFocus())
4426 m_rtc
->StoreFocusObject(container
);
4427 m_rtc
->SetCaretPositionAfterClick(container
, position
, hit
);
4430 return false; // so that the base-class sets a cursor
4432 #endif // wxUSE_DRAG_AND_DROP
4435 #if wxRICHTEXT_USE_OWN_CARET
4437 // ----------------------------------------------------------------------------
4438 // initialization and destruction
4439 // ----------------------------------------------------------------------------
4441 void wxRichTextCaret::Init()
4444 m_refreshEnabled
= true;
4448 m_richTextCtrl
= NULL
;
4449 m_needsUpdate
= false;
4453 wxRichTextCaret::~wxRichTextCaret()
4455 if (m_timer
.IsRunning())
4459 // ----------------------------------------------------------------------------
4460 // showing/hiding/moving the caret (base class interface)
4461 // ----------------------------------------------------------------------------
4463 void wxRichTextCaret::DoShow()
4467 if (!m_timer
.IsRunning())
4468 m_timer
.Start(GetBlinkTime());
4473 void wxRichTextCaret::DoHide()
4475 if (m_timer
.IsRunning())
4481 void wxRichTextCaret::DoMove()
4487 if (m_xOld
!= -1 && m_yOld
!= -1)
4489 if (m_richTextCtrl
&& m_refreshEnabled
)
4491 wxRect
rect(GetPosition(), GetSize());
4492 m_richTextCtrl
->RefreshRect(rect
, false);
4501 void wxRichTextCaret::DoSize()
4503 int countVisible
= m_countVisible
;
4504 if (countVisible
> 0)
4510 if (countVisible
> 0)
4512 m_countVisible
= countVisible
;
4517 // ----------------------------------------------------------------------------
4518 // handling the focus
4519 // ----------------------------------------------------------------------------
4521 void wxRichTextCaret::OnSetFocus()
4529 void wxRichTextCaret::OnKillFocus()
4534 // ----------------------------------------------------------------------------
4535 // drawing the caret
4536 // ----------------------------------------------------------------------------
4538 void wxRichTextCaret::Refresh()
4540 if (m_richTextCtrl
&& m_refreshEnabled
)
4542 wxRect
rect(GetPosition(), GetSize());
4543 m_richTextCtrl
->RefreshRect(rect
, false);
4547 void wxRichTextCaret::DoDraw(wxDC
*dc
)
4549 dc
->SetPen( *wxBLACK_PEN
);
4551 dc
->SetBrush(*(m_hasFocus
? wxBLACK_BRUSH
: wxTRANSPARENT_BRUSH
));
4552 dc
->SetPen(*wxBLACK_PEN
);
4554 wxPoint
pt(m_x
, m_y
);
4558 pt
= m_richTextCtrl
->GetLogicalPoint(pt
);
4560 if (IsVisible() && m_flashOn
)
4561 dc
->DrawRectangle(pt
.x
, pt
.y
, m_width
, m_height
);
4564 void wxRichTextCaret::Notify()
4566 m_flashOn
= !m_flashOn
;
4570 void wxRichTextCaretTimer::Notify()
4575 // wxRICHTEXT_USE_OWN_CARET
4578 bool wxRichTextContextMenuPropertiesInfo::AddItem(const wxString
& label
, wxRichTextObject
* obj
)
4582 m_labels
.Add(label
);
4590 // Returns number of menu items were added.
4591 int wxRichTextContextMenuPropertiesInfo::AddMenuItems(wxMenu
* menu
, int startCmd
) const
4593 wxMenuItem
* item
= menu
->FindItem(startCmd
);
4594 // If none of the standard properties identifiers are in the menu, add them if necessary.
4595 // If no items to add, just set the text to something generic
4596 if (GetCount() == 0)
4600 menu
->SetLabel(startCmd
, _("&Properties"));
4602 // Delete the others if necessary
4604 for (i
= startCmd
+1; i
< startCmd
+3; i
++)
4606 if (menu
->FindItem(i
))
4617 // Find the position of the first properties item
4618 for (i
= 0; i
< (int) menu
->GetMenuItemCount(); i
++)
4620 wxMenuItem
* item
= menu
->FindItemByPosition(i
);
4621 if (item
&& item
->GetId() == startCmd
)
4630 int insertBefore
= pos
+1;
4631 for (i
= startCmd
; i
< startCmd
+GetCount(); i
++)
4633 if (menu
->FindItem(i
))
4635 menu
->SetLabel(i
, m_labels
[i
- startCmd
]);
4639 if (insertBefore
>= (int) menu
->GetMenuItemCount())
4640 menu
->Append(i
, m_labels
[i
- startCmd
]);
4642 menu
->Insert(insertBefore
, i
, m_labels
[i
- startCmd
]);
4647 // Delete any old items still left on the menu
4648 for (i
= startCmd
+ GetCount(); i
< startCmd
+3; i
++)
4650 if (menu
->FindItem(i
))
4658 // No existing property identifiers were found, so append to the end of the menu.
4659 menu
->AppendSeparator();
4660 for (i
= startCmd
; i
< startCmd
+GetCount(); i
++)
4662 menu
->Append(i
, m_labels
[i
- startCmd
]);
4670 // Add appropriate menu items for the current container and clicked on object
4671 // (and container's parent, if appropriate).
4672 int wxRichTextContextMenuPropertiesInfo::AddItems(wxRichTextObject
* container
, wxRichTextObject
* obj
)
4675 if (obj
&& obj
->CanEditProperties())
4676 AddItem(obj
->GetPropertiesMenuLabel(), obj
);
4678 if (container
&& container
!= obj
&& container
->CanEditProperties() && m_labels
.Index(container
->GetPropertiesMenuLabel()) == wxNOT_FOUND
)
4679 AddItem(container
->GetPropertiesMenuLabel(), container
);
4681 if (container
&& container
->GetParent() && container
->GetParent()->CanEditProperties() && m_labels
.Index(container
->GetParent()->GetPropertiesMenuLabel()) == wxNOT_FOUND
)
4682 AddItem(container
->GetParent()->GetPropertiesMenuLabel(), container
->GetParent());