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 #if wxUSE_DRAG_AND_DROP
236 SetDropTarget(new wxRichTextDropTarget(this));
241 bool wxRichTextCtrl::Create( wxWindow
* parent
, wxWindowID id
, const wxString
& value
, const wxPoint
& pos
, const wxSize
& size
, long style
,
242 const wxValidator
& validator
, const wxString
& name
)
246 if (!wxControl::Create(parent
, id
, pos
, size
,
247 style
|wxFULL_REPAINT_ON_RESIZE
,
251 if (!GetFont().IsOk())
253 SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
256 // No physical scrolling, so we can preserve margins
257 EnableScrolling(false, false);
259 if (style
& wxTE_READONLY
)
262 // The base attributes must all have default values
263 wxRichTextAttr attributes
;
264 attributes
.SetFont(GetFont());
265 attributes
.SetTextColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
));
266 attributes
.SetAlignment(wxTEXT_ALIGNMENT_LEFT
);
267 attributes
.SetLineSpacing(10);
268 attributes
.SetParagraphSpacingAfter(10);
269 attributes
.SetParagraphSpacingBefore(0);
271 SetBasicStyle(attributes
);
274 SetMargins(margin
, margin
);
276 // The default attributes will be merged with base attributes, so
277 // can be empty to begin with
278 wxRichTextAttr defaultAttributes
;
279 SetDefaultStyle(defaultAttributes
);
281 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
282 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
285 GetBuffer().SetRichTextCtrl(this);
287 #if wxRICHTEXT_USE_OWN_CARET
288 SetCaret(new wxRichTextCaret(this, wxRICHTEXT_DEFAULT_CARET_WIDTH
, 16));
290 SetCaret(new wxCaret(this, wxRICHTEXT_DEFAULT_CARET_WIDTH
, 16));
293 // Tell the sizers to use the given or best size
294 SetInitialSize(size
);
296 #if wxRICHTEXT_BUFFERED_PAINTING
298 RecreateBuffer(size
);
301 m_textCursor
= wxCursor(wxCURSOR_IBEAM
);
302 m_urlCursor
= wxCursor(wxCURSOR_HAND
);
304 SetCursor(m_textCursor
);
306 if (!value
.IsEmpty())
309 GetBuffer().AddEventHandler(this);
312 wxAcceleratorEntry entries
[6];
314 entries
[0].Set(wxACCEL_CTRL
, (int) 'C', wxID_COPY
);
315 entries
[1].Set(wxACCEL_CTRL
, (int) 'X', wxID_CUT
);
316 entries
[2].Set(wxACCEL_CTRL
, (int) 'V', wxID_PASTE
);
317 entries
[3].Set(wxACCEL_CTRL
, (int) 'A', wxID_SELECTALL
);
318 entries
[4].Set(wxACCEL_CTRL
, (int) 'Z', wxID_UNDO
);
319 entries
[5].Set(wxACCEL_CTRL
, (int) 'Y', wxID_REDO
);
321 wxAcceleratorTable
accel(6, entries
);
322 SetAcceleratorTable(accel
);
324 m_contextMenu
= new wxMenu
;
325 m_contextMenu
->Append(wxID_UNDO
, _("&Undo"));
326 m_contextMenu
->Append(wxID_REDO
, _("&Redo"));
327 m_contextMenu
->AppendSeparator();
328 m_contextMenu
->Append(wxID_CUT
, _("Cu&t"));
329 m_contextMenu
->Append(wxID_COPY
, _("&Copy"));
330 m_contextMenu
->Append(wxID_PASTE
, _("&Paste"));
331 m_contextMenu
->Append(wxID_CLEAR
, _("&Delete"));
332 m_contextMenu
->AppendSeparator();
333 m_contextMenu
->Append(wxID_SELECTALL
, _("Select &All"));
334 m_contextMenu
->AppendSeparator();
335 m_contextMenu
->Append(wxID_RICHTEXT_PROPERTIES1
, _("&Properties"));
340 wxRichTextCtrl::~wxRichTextCtrl()
342 SetFocusObject(& GetBuffer(), false);
343 GetBuffer().RemoveEventHandler(this);
345 delete m_contextMenu
;
348 /// Member initialisation
349 void wxRichTextCtrl::Init()
351 m_contextMenu
= NULL
;
353 m_caretPosition
= -1;
354 m_selectionAnchor
= -2;
355 m_selectionAnchorObject
= NULL
;
356 m_selectionState
= wxRichTextCtrlSelectionState_Normal
;
358 m_caretAtLineStart
= false;
360 #if wxUSE_DRAG_AND_DROP
363 m_fullLayoutRequired
= false;
364 m_fullLayoutTime
= 0;
365 m_fullLayoutSavedPosition
= 0;
366 m_delayedLayoutThreshold
= wxRICHTEXT_DEFAULT_DELAYED_LAYOUT_THRESHOLD
;
367 m_caretPositionForDefaultStyle
= -2;
368 m_focusObject
= & m_buffer
;
371 void wxRichTextCtrl::DoThaw()
373 if (GetBuffer().IsDirty())
382 void wxRichTextCtrl::Clear()
384 if (GetFocusObject() == & GetBuffer())
386 m_buffer
.ResetAndClearCommands();
387 m_buffer
.Invalidate(wxRICHTEXT_ALL
);
391 GetFocusObject()->Reset();
394 m_caretPosition
= -1;
395 m_caretPositionForDefaultStyle
= -2;
396 m_caretAtLineStart
= false;
398 m_selectionState
= wxRichTextCtrlSelectionState_Normal
;
408 wxTextCtrl::SendTextUpdatedEvent(this);
412 void wxRichTextCtrl::OnPaint(wxPaintEvent
& WXUNUSED(event
))
414 #if !wxRICHTEXT_USE_OWN_CARET
415 if (GetCaret() && !IsFrozen())
418 // Stop the caret refreshing the control from within the
421 ((wxRichTextCaret
*) GetCaret())->EnableRefresh(false);
425 #if wxRICHTEXT_BUFFERED_PAINTING
426 wxBufferedPaintDC
dc(this, m_bufferBitmap
);
436 dc
.SetFont(GetFont());
438 // Paint the background
441 // wxRect drawingArea(GetLogicalPoint(wxPoint(0, 0)), GetClientSize());
443 wxRect
drawingArea(GetUpdateRegion().GetBox());
444 drawingArea
.SetPosition(GetLogicalPoint(drawingArea
.GetPosition()));
446 wxRect
availableSpace(GetClientSize());
447 if (GetBuffer().IsDirty())
449 GetBuffer().Layout(dc
, availableSpace
, availableSpace
, wxRICHTEXT_FIXED_WIDTH
|wxRICHTEXT_VARIABLE_HEIGHT
);
450 GetBuffer().Invalidate(wxRICHTEXT_NONE
);
454 wxRect
clipRect(availableSpace
);
455 clipRect
.x
+= GetBuffer().GetLeftMargin();
456 clipRect
.y
+= GetBuffer().GetTopMargin();
457 clipRect
.width
-= (GetBuffer().GetLeftMargin() + GetBuffer().GetRightMargin());
458 clipRect
.height
-= (GetBuffer().GetTopMargin() + GetBuffer().GetBottomMargin());
459 clipRect
.SetPosition(GetLogicalPoint(clipRect
.GetPosition()));
460 dc
.SetClippingRegion(clipRect
);
463 if ((GetExtraStyle() & wxRICHTEXT_EX_NO_GUIDELINES
) == 0)
464 flags
|= wxRICHTEXT_DRAW_GUIDELINES
;
466 GetBuffer().Draw(dc
, GetBuffer().GetOwnRange(), GetSelection(), drawingArea
, 0 /* descent */, flags
);
468 dc
.DestroyClippingRegion();
470 // Other user defined painting after everything else (i.e. all text) is painted
471 PaintAboveContent(dc
);
473 #if wxRICHTEXT_USE_OWN_CARET
474 if (GetCaret()->IsVisible())
477 ((wxRichTextCaret
*) GetCaret())->DoDraw(& dc
);
482 #if !wxRICHTEXT_USE_OWN_CARET
488 ((wxRichTextCaret
*) GetCaret())->EnableRefresh(true);
492 // Empty implementation, to prevent flicker
493 void wxRichTextCtrl::OnEraseBackground(wxEraseEvent
& WXUNUSED(event
))
497 void wxRichTextCtrl::OnSetFocus(wxFocusEvent
& WXUNUSED(event
))
501 #if !wxRICHTEXT_USE_OWN_CARET
507 #if defined(__WXGTK__) && !wxRICHTEXT_USE_OWN_CARET
508 // Work around dropouts when control is focused
516 void wxRichTextCtrl::OnKillFocus(wxFocusEvent
& WXUNUSED(event
))
521 #if defined(__WXGTK__) && !wxRICHTEXT_USE_OWN_CARET
522 // Work around dropouts when control is focused
530 void wxRichTextCtrl::OnCaptureLost(wxMouseCaptureLostEvent
& WXUNUSED(event
))
535 // Set up the caret for the given position and container, after a mouse click
536 bool wxRichTextCtrl::SetCaretPositionAfterClick(wxRichTextParagraphLayoutBox
* container
, long position
, int hitTestFlags
, bool extendSelection
)
538 bool caretAtLineStart
= false;
540 if (hitTestFlags
& wxRICHTEXT_HITTEST_BEFORE
)
542 // If we're at the start of a line (but not first in para)
543 // then we should keep the caret showing at the start of the line
544 // by showing the m_caretAtLineStart flag.
545 wxRichTextParagraph
* para
= container
->GetParagraphAtPosition(position
);
546 wxRichTextLine
* line
= container
->GetLineAtPosition(position
);
548 if (line
&& para
&& line
->GetAbsoluteRange().GetStart() == position
&& para
->GetRange().GetStart() != position
)
549 caretAtLineStart
= true;
553 if (extendSelection
&& (m_caretPosition
!= position
))
554 ExtendSelection(m_caretPosition
, position
, wxRICHTEXT_SHIFT_DOWN
);
556 MoveCaret(position
, caretAtLineStart
);
557 SetDefaultStyleToCursorStyle();
563 void wxRichTextCtrl::OnLeftClick(wxMouseEvent
& event
)
569 dc
.SetFont(GetFont());
571 // TODO: detect change of focus object
573 wxRichTextObject
* hitObj
= NULL
;
574 wxRichTextObject
* contextObj
= NULL
;
575 int hit
= GetBuffer().HitTest(dc
, event
.GetLogicalPosition(dc
), position
, & hitObj
, & contextObj
);
577 #if wxUSE_DRAG_AND_DROP
578 // If there's no selection, or we're not inside it, this isn't an attempt to initiate Drag'n'Drop
579 if (IsEditable() && HasSelection() && GetSelectionRange().ToInternal().Contains(position
))
581 // This might be an attempt at initiating Drag'n'Drop. So set the time & flags
583 m_dragStartPoint
= event
.GetPosition(); // No need to worry about logical positions etc, we only care about the distance from the original pt
586 m_dragStartTime
= wxDateTime::UNow();
587 #endif // wxUSE_DATETIME
589 // Preserve behaviour of clicking on an object within the selection
590 if (hit
!= wxRICHTEXT_HITTEST_NONE
&& hitObj
)
593 return; // Don't skip the event, else the selection will be lost
595 #endif // wxUSE_DRAG_AND_DROP
597 if (hit
!= wxRICHTEXT_HITTEST_NONE
&& hitObj
)
599 wxRichTextParagraphLayoutBox
* oldFocusObject
= GetFocusObject();
600 wxRichTextParagraphLayoutBox
* container
= wxDynamicCast(contextObj
, wxRichTextParagraphLayoutBox
);
601 if (container
&& container
!= GetFocusObject() && container
->AcceptsFocus())
603 SetFocusObject(container
, false /* don't set caret position yet */);
609 long oldCaretPos
= m_caretPosition
;
611 SetCaretPositionAfterClick(container
, position
, hit
);
613 // For now, don't handle shift-click when we're selecting multiple objects.
614 if (event
.ShiftDown() && GetFocusObject() == oldFocusObject
&& m_selectionState
== wxRichTextCtrlSelectionState_Normal
)
615 ExtendSelection(oldCaretPos
, m_caretPosition
, wxRICHTEXT_SHIFT_DOWN
);
624 void wxRichTextCtrl::OnLeftUp(wxMouseEvent
& event
)
629 if (GetCapture() == this)
632 // See if we clicked on a URL
635 dc
.SetFont(GetFont());
638 wxPoint logicalPt
= event
.GetLogicalPosition(dc
);
639 wxRichTextObject
* hitObj
= NULL
;
640 wxRichTextObject
* contextObj
= NULL
;
641 // Only get objects at this level, not nested, because otherwise we couldn't swipe text at a single level.
642 int hit
= GetFocusObject()->HitTest(dc
, logicalPt
, position
, & hitObj
, & contextObj
, wxRICHTEXT_HITTEST_NO_NESTED_OBJECTS
);
644 #if wxUSE_DRAG_AND_DROP
647 // Preserve the behaviour that would have happened without drag-and-drop detection, in OnLeftClick
648 m_preDrag
= false; // Tell DnD not to happen now: we are processing Left Up ourselves.
650 // Do the actions that would have been done in OnLeftClick if we hadn't tried to drag
652 wxRichTextObject
* hitObj
= NULL
;
653 wxRichTextObject
* contextObj
= NULL
;
654 int hit
= GetBuffer().HitTest(dc
, event
.GetLogicalPosition(dc
), position
, & hitObj
, & contextObj
);
655 wxRichTextParagraphLayoutBox
* oldFocusObject
= GetFocusObject();
656 wxRichTextParagraphLayoutBox
* container
= wxDynamicCast(contextObj
, wxRichTextParagraphLayoutBox
);
657 if (container
&& container
!= GetFocusObject() && container
->AcceptsFocus())
659 SetFocusObject(container
, false /* don't set caret position yet */);
662 long oldCaretPos
= m_caretPosition
;
664 SetCaretPositionAfterClick(container
, position
, hit
);
666 // For now, don't handle shift-click when we're selecting multiple objects.
667 if (event
.ShiftDown() && GetFocusObject() == oldFocusObject
&& m_selectionState
== wxRichTextCtrlSelectionState_Normal
)
668 ExtendSelection(oldCaretPos
, m_caretPosition
, wxRICHTEXT_SHIFT_DOWN
);
674 if ((hit
!= wxRICHTEXT_HITTEST_NONE
) && !(hit
& wxRICHTEXT_HITTEST_OUTSIDE
))
676 wxRichTextEvent
cmdEvent(
677 wxEVT_COMMAND_RICHTEXT_LEFT_CLICK
,
679 cmdEvent
.SetEventObject(this);
680 cmdEvent
.SetPosition(position
);
682 cmdEvent
.SetContainer(hitObj
->GetContainer());
684 if (!GetEventHandler()->ProcessEvent(cmdEvent
))
687 if (GetStyle(position
, attr
))
689 if (attr
.HasFlag(wxTEXT_ATTR_URL
))
691 wxString urlTarget
= attr
.GetURL();
692 if (!urlTarget
.IsEmpty())
694 wxMouseEvent
mouseEvent(event
);
696 long startPos
= 0, endPos
= 0;
697 wxRichTextObject
* obj
= GetFocusObject()->GetLeafObjectAtPosition(position
);
700 startPos
= obj
->GetRange().GetStart();
701 endPos
= obj
->GetRange().GetEnd();
704 wxTextUrlEvent
urlEvent(GetId(), mouseEvent
, startPos
, endPos
);
705 InitCommandEvent(urlEvent
);
707 urlEvent
.SetString(urlTarget
);
709 GetEventHandler()->ProcessEvent(urlEvent
);
717 #if wxUSE_DRAG_AND_DROP
719 #endif // wxUSE_DRAG_AND_DROP
721 #if wxUSE_CLIPBOARD && wxUSE_DATAOBJ && wxHAVE_PRIMARY_SELECTION
722 if (HasSelection() && GetFocusObject() && GetFocusObject()->GetBuffer())
724 // Put the selection in PRIMARY, if it exists
725 wxTheClipboard
->UsePrimarySelection(true);
727 wxRichTextRange range
= GetInternalSelectionRange();
728 GetFocusObject()->GetBuffer()->CopyToClipboard(range
);
730 wxTheClipboard
->UsePrimarySelection(false);
736 void wxRichTextCtrl::OnMoveMouse(wxMouseEvent
& event
)
738 #if wxUSE_DRAG_AND_DROP
739 // See if we're starting Drag'n'Drop
742 int x
= m_dragStartPoint
.x
- event
.GetPosition().x
;
743 int y
= m_dragStartPoint
.y
- event
.GetPosition().y
;
744 size_t distance
= abs(x
) + abs(y
);
746 wxTimeSpan diff
= wxDateTime::UNow() - m_dragStartTime
;
750 && (diff
.GetMilliseconds() > 100)
757 wxRichTextRange range
= GetInternalSelectionRange();
758 if (range
== wxRICHTEXT_NONE
)
760 // Don't try to drag an empty range
765 // Cache the current situation, to be restored if Drag'n'Drop is cancelled
766 long oldPos
= GetCaretPosition();
767 wxRichTextParagraphLayoutBox
* oldFocus
= GetFocusObject();
769 wxDataObjectComposite
* compositeObject
= new wxDataObjectComposite();
770 wxString text
= GetFocusObject()->GetTextForRange(range
);
772 text
= wxTextFile::Translate(text
, wxTextFileType_Dos
);
774 compositeObject
->Add(new wxTextDataObject(text
), false /* not preferred */);
776 wxRichTextBuffer
* richTextBuf
= new wxRichTextBuffer
;
777 GetFocusObject()->CopyFragment(range
, *richTextBuf
);
778 compositeObject
->Add(new wxRichTextBufferDataObject(richTextBuf
), true /* preferred */);
780 wxRichTextDropSource
source(*compositeObject
, this);
781 // Use wxDrag_DefaultMove, not because it's the likelier choice but because pressing Ctrl for Copy obeys the principle of least surprise
782 // The alternative, wxDrag_DefaultCopy, requires the user to know that Move needs the Shift key pressed
783 BeginBatchUndo(_("Drag"));
784 switch (source
.DoDragDrop(wxDrag_AllowMove
| wxDrag_DefaultMove
))
787 case wxDragCopy
: break;
790 wxLogError(wxT("An error occurred during drag and drop operation"));
793 Refresh(); // This is needed in wxMSW, otherwise resetting the position doesn't 'take'
794 SetCaretPosition(oldPos
);
795 SetFocusObject(oldFocus
, false);
804 #endif // wxUSE_DRAG_AND_DROP
808 dc
.SetFont(GetFont());
811 wxPoint logicalPt
= event
.GetLogicalPosition(dc
);
812 wxRichTextObject
* hitObj
= NULL
;
813 wxRichTextObject
* contextObj
= NULL
;
817 // If we're dragging, let's only consider positions at this level; otherwise
818 // selecting a range is not going to work.
819 wxRichTextParagraphLayoutBox
* container
= & GetBuffer();
822 flags
= wxRICHTEXT_HITTEST_NO_NESTED_OBJECTS
;
823 container
= GetFocusObject();
825 int hit
= container
->HitTest(dc
, logicalPt
, position
, & hitObj
, & contextObj
, flags
);
827 // See if we need to change the cursor
830 if (hit
!= wxRICHTEXT_HITTEST_NONE
&& !(hit
& wxRICHTEXT_HITTEST_OUTSIDE
) && hitObj
)
832 wxRichTextParagraphLayoutBox
* actualContainer
= wxDynamicCast(contextObj
, wxRichTextParagraphLayoutBox
);
834 if (actualContainer
&& GetStyle(position
, attr
, actualContainer
))
836 if (attr
.HasFlag(wxTEXT_ATTR_URL
))
838 SetCursor(m_urlCursor
);
840 else if (!attr
.HasFlag(wxTEXT_ATTR_URL
))
842 SetCursor(m_textCursor
);
847 SetCursor(m_textCursor
);
850 if (!event
.Dragging())
857 #if wxUSE_DRAG_AND_DROP
862 wxRichTextParagraphLayoutBox
* commonAncestor
= NULL
;
863 wxRichTextParagraphLayoutBox
* otherContainer
= NULL
;
864 wxRichTextParagraphLayoutBox
* firstContainer
= NULL
;
866 // Check for dragging across multiple containers
868 wxRichTextObject
* hitObj2
= NULL
, *contextObj2
= NULL
;
869 int hit2
= GetBuffer().HitTest(dc
, logicalPt
, position2
, & hitObj2
, & contextObj2
, 0);
870 if (hit2
!= wxRICHTEXT_HITTEST_NONE
&& !(hit2
& wxRICHTEXT_HITTEST_OUTSIDE
) && hitObj2
&& hitObj
!= hitObj2
)
872 // See if we can find a common ancestor
873 if (m_selectionState
== wxRichTextCtrlSelectionState_Normal
)
875 firstContainer
= GetFocusObject();
876 commonAncestor
= wxDynamicCast(firstContainer
->GetParent(), wxRichTextParagraphLayoutBox
);
880 firstContainer
= wxDynamicCast(m_selectionAnchorObject
, wxRichTextParagraphLayoutBox
);
881 //commonAncestor = GetFocusObject(); // when the selection state is not normal, the focus object (e.g. table)
882 // is the common ancestor.
883 commonAncestor
= wxDynamicCast(firstContainer
->GetParent(), wxRichTextParagraphLayoutBox
);
886 if (commonAncestor
&& commonAncestor
->HandlesChildSelections())
888 wxRichTextObject
* p
= hitObj2
;
891 if (p
->GetParent() == commonAncestor
)
893 otherContainer
= wxDynamicCast(p
, wxRichTextParagraphLayoutBox
);
900 if (commonAncestor
&& firstContainer
&& otherContainer
)
902 // We have now got a second container that shares a parent with the current or anchor object.
903 if (m_selectionState
== wxRichTextCtrlSelectionState_Normal
)
905 // Don't go into common-ancestor selection mode if we still have the same
907 if (otherContainer
!= firstContainer
)
909 m_selectionState
= wxRichTextCtrlSelectionState_CommonAncestor
;
910 m_selectionAnchorObject
= firstContainer
;
911 m_selectionAnchor
= firstContainer
->GetRange().GetStart();
913 // The common ancestor, such as a table, returns the cell selection
914 // between the anchor and current position.
915 m_selection
= commonAncestor
->GetSelection(m_selectionAnchor
, otherContainer
->GetRange().GetStart());
920 m_selection
= commonAncestor
->GetSelection(m_selectionAnchor
, otherContainer
->GetRange().GetStart());
925 if (otherContainer
->AcceptsFocus())
926 SetFocusObject(otherContainer
, false /* don't set caret and clear selection */);
927 MoveCaret(-1, false);
928 SetDefaultStyleToCursorStyle();
933 if (hitObj
&& m_dragging
&& hit
!= wxRICHTEXT_HITTEST_NONE
&& m_selectionState
== wxRichTextCtrlSelectionState_Normal
934 #if wxUSE_DRAG_AND_DROP
939 // TODO: test closeness
940 SetCaretPositionAfterClick(container
, position
, hit
, true /* extend selection */);
945 void wxRichTextCtrl::OnRightClick(wxMouseEvent
& event
)
951 dc
.SetFont(GetFont());
954 wxPoint logicalPt
= event
.GetLogicalPosition(dc
);
955 wxRichTextObject
* hitObj
= NULL
;
956 wxRichTextObject
* contextObj
= NULL
;
957 int hit
= GetFocusObject()->HitTest(dc
, logicalPt
, position
, & hitObj
, & contextObj
);
959 if (hitObj
&& hitObj
->GetContainer() != GetFocusObject())
961 wxRichTextParagraphLayoutBox
* actualContainer
= wxDynamicCast(contextObj
, wxRichTextParagraphLayoutBox
);
962 if (actualContainer
&& actualContainer
->AcceptsFocus())
964 SetFocusObject(actualContainer
, false /* don't set caret position yet */);
965 SetCaretPositionAfterClick(actualContainer
, position
, hit
);
969 wxRichTextEvent
cmdEvent(
970 wxEVT_COMMAND_RICHTEXT_RIGHT_CLICK
,
972 cmdEvent
.SetEventObject(this);
973 cmdEvent
.SetPosition(position
);
975 cmdEvent
.SetContainer(hitObj
->GetContainer());
977 if (!GetEventHandler()->ProcessEvent(cmdEvent
))
981 /// Left-double-click
982 void wxRichTextCtrl::OnLeftDClick(wxMouseEvent
& WXUNUSED(event
))
984 wxRichTextEvent
cmdEvent(
985 wxEVT_COMMAND_RICHTEXT_LEFT_DCLICK
,
987 cmdEvent
.SetEventObject(this);
988 cmdEvent
.SetPosition(m_caretPosition
+1);
989 cmdEvent
.SetContainer(GetFocusObject());
991 if (!GetEventHandler()->ProcessEvent(cmdEvent
))
993 SelectWord(GetCaretPosition()+1);
998 void wxRichTextCtrl::OnMiddleClick(wxMouseEvent
& event
)
1000 wxRichTextEvent
cmdEvent(
1001 wxEVT_COMMAND_RICHTEXT_MIDDLE_CLICK
,
1003 cmdEvent
.SetEventObject(this);
1004 cmdEvent
.SetPosition(m_caretPosition
+1);
1005 cmdEvent
.SetContainer(GetFocusObject());
1007 if (!GetEventHandler()->ProcessEvent(cmdEvent
))
1010 #if wxUSE_CLIPBOARD && wxUSE_DATAOBJ && wxHAVE_PRIMARY_SELECTION
1011 // Paste any PRIMARY selection, if it exists
1012 wxTheClipboard
->UsePrimarySelection(true);
1014 wxTheClipboard
->UsePrimarySelection(false);
1019 void wxRichTextCtrl::OnChar(wxKeyEvent
& event
)
1022 if (event
.CmdDown())
1023 flags
|= wxRICHTEXT_CTRL_DOWN
;
1024 if (event
.ShiftDown())
1025 flags
|= wxRICHTEXT_SHIFT_DOWN
;
1026 if (event
.AltDown())
1027 flags
|= wxRICHTEXT_ALT_DOWN
;
1029 if (event
.GetEventType() == wxEVT_KEY_DOWN
)
1031 if (event
.IsKeyInCategory(WXK_CATEGORY_NAVIGATION
))
1033 KeyboardNavigate(event
.GetKeyCode(), flags
);
1037 long keycode
= event
.GetKeyCode();
1097 case WXK_NUMPAD_HOME
:
1098 case WXK_NUMPAD_LEFT
:
1100 case WXK_NUMPAD_RIGHT
:
1101 case WXK_NUMPAD_DOWN
:
1102 case WXK_NUMPAD_PAGEUP
:
1103 case WXK_NUMPAD_PAGEDOWN
:
1104 case WXK_NUMPAD_END
:
1105 case WXK_NUMPAD_BEGIN
:
1106 case WXK_NUMPAD_INSERT
:
1107 case WXK_WINDOWS_LEFT
:
1116 // Must process this before translation, otherwise it's translated into a WXK_DELETE event.
1117 if (event
.CmdDown() && event
.GetKeyCode() == WXK_BACK
)
1119 BeginBatchUndo(_("Delete Text"));
1121 long newPos
= m_caretPosition
;
1123 bool processed
= DeleteSelectedContent(& newPos
);
1125 // Submit range in character positions, which are greater than caret positions,
1126 // so subtract 1 for deleted character and add 1 for conversion to character position.
1129 if (event
.CmdDown())
1131 long pos
= wxRichTextCtrl::FindNextWordPosition(-1);
1134 GetFocusObject()->DeleteRangeWithUndo(wxRichTextRange(pos
+1, newPos
), this, & GetBuffer());
1140 GetFocusObject()->DeleteRangeWithUndo(wxRichTextRange(newPos
, newPos
), this, & GetBuffer());
1145 if (GetLastPosition() == -1)
1147 GetFocusObject()->Reset();
1149 m_caretPosition
= -1;
1151 SetDefaultStyleToCursorStyle();
1154 ScrollIntoView(m_caretPosition
, WXK_LEFT
);
1156 wxRichTextEvent
cmdEvent(
1157 wxEVT_COMMAND_RICHTEXT_DELETE
,
1159 cmdEvent
.SetEventObject(this);
1160 cmdEvent
.SetFlags(flags
);
1161 cmdEvent
.SetPosition(m_caretPosition
+1);
1162 cmdEvent
.SetContainer(GetFocusObject());
1163 GetEventHandler()->ProcessEvent(cmdEvent
);
1173 // all the other keys modify the controls contents which shouldn't be
1174 // possible if we're read-only
1175 if ( !IsEditable() )
1181 if (event
.GetKeyCode() == WXK_RETURN
)
1183 BeginBatchUndo(_("Insert Text"));
1185 long newPos
= m_caretPosition
;
1187 DeleteSelectedContent(& newPos
);
1189 if (event
.ShiftDown())
1192 text
= wxRichTextLineBreakChar
;
1193 GetFocusObject()->InsertTextWithUndo(& GetBuffer(), newPos
+1, text
, this);
1194 m_caretAtLineStart
= true;
1198 GetFocusObject()->InsertNewlineWithUndo(& GetBuffer(), newPos
+1, this, wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE
|wxRICHTEXT_INSERT_INTERACTIVE
);
1201 SetDefaultStyleToCursorStyle();
1203 ScrollIntoView(m_caretPosition
, WXK_RIGHT
);
1205 wxRichTextEvent
cmdEvent(
1206 wxEVT_COMMAND_RICHTEXT_RETURN
,
1208 cmdEvent
.SetEventObject(this);
1209 cmdEvent
.SetFlags(flags
);
1210 cmdEvent
.SetPosition(newPos
+1);
1211 cmdEvent
.SetContainer(GetFocusObject());
1213 if (!GetEventHandler()->ProcessEvent(cmdEvent
))
1215 // Generate conventional event
1216 wxCommandEvent
textEvent(wxEVT_COMMAND_TEXT_ENTER
, GetId());
1217 InitCommandEvent(textEvent
);
1219 GetEventHandler()->ProcessEvent(textEvent
);
1223 else if (event
.GetKeyCode() == WXK_BACK
)
1225 BeginBatchUndo(_("Delete Text"));
1227 long newPos
= m_caretPosition
;
1229 bool processed
= DeleteSelectedContent(& newPos
);
1231 // Submit range in character positions, which are greater than caret positions,
1232 // so subtract 1 for deleted character and add 1 for conversion to character position.
1235 if (event
.CmdDown())
1237 long pos
= wxRichTextCtrl::FindNextWordPosition(-1);
1240 GetFocusObject()->DeleteRangeWithUndo(wxRichTextRange(pos
+1, newPos
), this, & GetBuffer());
1246 GetFocusObject()->DeleteRangeWithUndo(wxRichTextRange(newPos
, newPos
), this, & GetBuffer());
1251 if (GetLastPosition() == -1)
1253 GetFocusObject()->Reset();
1255 m_caretPosition
= -1;
1257 SetDefaultStyleToCursorStyle();
1260 ScrollIntoView(m_caretPosition
, WXK_LEFT
);
1262 wxRichTextEvent
cmdEvent(
1263 wxEVT_COMMAND_RICHTEXT_DELETE
,
1265 cmdEvent
.SetEventObject(this);
1266 cmdEvent
.SetFlags(flags
);
1267 cmdEvent
.SetPosition(m_caretPosition
+1);
1268 cmdEvent
.SetContainer(GetFocusObject());
1269 GetEventHandler()->ProcessEvent(cmdEvent
);
1273 else if (event
.GetKeyCode() == WXK_DELETE
)
1275 BeginBatchUndo(_("Delete Text"));
1277 long newPos
= m_caretPosition
;
1279 bool processed
= DeleteSelectedContent(& newPos
);
1281 // Submit range in character positions, which are greater than caret positions,
1282 if (newPos
< GetFocusObject()->GetOwnRange().GetEnd()+1)
1284 if (event
.CmdDown())
1286 long pos
= wxRichTextCtrl::FindNextWordPosition(1);
1287 if (pos
!= -1 && (pos
> newPos
))
1289 GetFocusObject()->DeleteRangeWithUndo(wxRichTextRange(newPos
+1, pos
), this, & GetBuffer());
1294 if (!processed
&& newPos
< (GetLastPosition()-1))
1295 GetFocusObject()->DeleteRangeWithUndo(wxRichTextRange(newPos
+1, newPos
+1), this, & GetBuffer());
1300 if (GetLastPosition() == -1)
1302 GetFocusObject()->Reset();
1304 m_caretPosition
= -1;
1306 SetDefaultStyleToCursorStyle();
1309 ScrollIntoView(m_caretPosition
, WXK_LEFT
);
1311 wxRichTextEvent
cmdEvent(
1312 wxEVT_COMMAND_RICHTEXT_DELETE
,
1314 cmdEvent
.SetEventObject(this);
1315 cmdEvent
.SetFlags(flags
);
1316 cmdEvent
.SetPosition(m_caretPosition
+1);
1317 cmdEvent
.SetContainer(GetFocusObject());
1318 GetEventHandler()->ProcessEvent(cmdEvent
);
1324 long keycode
= event
.GetKeyCode();
1336 if (event
.CmdDown())
1338 // Fixes AltGr+key with European input languages on Windows
1339 if ((event
.CmdDown() && !event
.AltDown()) || (event
.AltDown() && !event
.CmdDown()))
1346 wxRichTextEvent
cmdEvent(
1347 wxEVT_COMMAND_RICHTEXT_CHARACTER
,
1349 cmdEvent
.SetEventObject(this);
1350 cmdEvent
.SetFlags(flags
);
1352 cmdEvent
.SetCharacter(event
.GetUnicodeKey());
1354 cmdEvent
.SetCharacter((wxChar
) keycode
);
1356 cmdEvent
.SetPosition(m_caretPosition
+1);
1357 cmdEvent
.SetContainer(GetFocusObject());
1359 if (keycode
== wxT('\t'))
1361 // See if we need to promote or demote the selection or paragraph at the cursor
1362 // position, instead of inserting a tab.
1363 long pos
= GetAdjustedCaretPosition(GetCaretPosition());
1364 wxRichTextParagraph
* para
= GetFocusObject()->GetParagraphAtPosition(pos
);
1365 if (para
&& para
->GetRange().GetStart() == pos
&& para
->GetAttributes().HasListStyleName())
1367 wxRichTextRange range
;
1369 range
= GetSelectionRange();
1371 range
= para
->GetRange().FromInternal();
1373 int promoteBy
= event
.ShiftDown() ? 1 : -1;
1375 PromoteList(promoteBy
, range
, NULL
);
1377 GetEventHandler()->ProcessEvent(cmdEvent
);
1383 BeginBatchUndo(_("Insert Text"));
1385 long newPos
= m_caretPosition
;
1386 DeleteSelectedContent(& newPos
);
1389 wxString str
= event
.GetUnicodeKey();
1391 wxString str
= (wxChar
) event
.GetKeyCode();
1393 GetFocusObject()->InsertTextWithUndo(& GetBuffer(), newPos
+1, str
, this, 0);
1397 SetDefaultStyleToCursorStyle();
1398 ScrollIntoView(m_caretPosition
, WXK_RIGHT
);
1400 cmdEvent
.SetPosition(m_caretPosition
);
1401 GetEventHandler()->ProcessEvent(cmdEvent
);
1409 /// Delete content if there is a selection, e.g. when pressing a key.
1410 bool wxRichTextCtrl::DeleteSelectedContent(long* newPos
)
1414 long pos
= m_selection
.GetRange().GetStart();
1415 wxRichTextRange range
= m_selection
.GetRange();
1417 // SelectAll causes more to be selected than doing it interactively,
1418 // and causes a new paragraph to be inserted. So for multiline buffers,
1419 // don't delete the final position.
1420 if (range
.GetEnd() == GetLastPosition() && GetNumberOfLines() > 0)
1421 range
.SetEnd(range
.GetEnd()-1);
1423 GetFocusObject()->DeleteRangeWithUndo(range
, this, & GetBuffer());
1424 m_selection
.Reset();
1425 m_selectionState
= wxRichTextCtrlSelectionState_Normal
;
1435 /// Keyboard navigation
1439 Left: left one character
1440 Right: right one character
1443 Ctrl-Left: left one word
1444 Ctrl-Right: right one word
1445 Ctrl-Up: previous paragraph start
1446 Ctrl-Down: next start of paragraph
1449 Ctrl-Home: start of document
1450 Ctrl-End: end of document
1451 Page-Up: Up a screen
1452 Page-Down: Down a screen
1456 Ctrl-Alt-PgUp: Start of window
1457 Ctrl-Alt-PgDn: End of window
1458 F8: Start selection mode
1459 Esc: End selection mode
1461 Adding Shift does the above but starts/extends selection.
1466 bool wxRichTextCtrl::KeyboardNavigate(int keyCode
, int flags
)
1468 bool success
= false;
1470 if (keyCode
== WXK_RIGHT
|| keyCode
== WXK_NUMPAD_RIGHT
)
1472 if (flags
& wxRICHTEXT_CTRL_DOWN
)
1473 success
= WordRight(1, flags
);
1475 success
= MoveRight(1, flags
);
1477 else if (keyCode
== WXK_LEFT
|| keyCode
== WXK_NUMPAD_LEFT
)
1479 if (flags
& wxRICHTEXT_CTRL_DOWN
)
1480 success
= WordLeft(1, flags
);
1482 success
= MoveLeft(1, flags
);
1484 else if (keyCode
== WXK_UP
|| keyCode
== WXK_NUMPAD_UP
)
1486 if (flags
& wxRICHTEXT_CTRL_DOWN
)
1487 success
= MoveToParagraphStart(flags
);
1489 success
= MoveUp(1, flags
);
1491 else if (keyCode
== WXK_DOWN
|| keyCode
== WXK_NUMPAD_DOWN
)
1493 if (flags
& wxRICHTEXT_CTRL_DOWN
)
1494 success
= MoveToParagraphEnd(flags
);
1496 success
= MoveDown(1, flags
);
1498 else if (keyCode
== WXK_PAGEUP
|| keyCode
== WXK_NUMPAD_PAGEUP
)
1500 success
= PageUp(1, flags
);
1502 else if (keyCode
== WXK_PAGEDOWN
|| keyCode
== WXK_NUMPAD_PAGEDOWN
)
1504 success
= PageDown(1, flags
);
1506 else if (keyCode
== WXK_HOME
|| keyCode
== WXK_NUMPAD_HOME
)
1508 if (flags
& wxRICHTEXT_CTRL_DOWN
)
1509 success
= MoveHome(flags
);
1511 success
= MoveToLineStart(flags
);
1513 else if (keyCode
== WXK_END
|| keyCode
== WXK_NUMPAD_END
)
1515 if (flags
& wxRICHTEXT_CTRL_DOWN
)
1516 success
= MoveEnd(flags
);
1518 success
= MoveToLineEnd(flags
);
1523 ScrollIntoView(m_caretPosition
, keyCode
);
1524 SetDefaultStyleToCursorStyle();
1530 /// Extend the selection. Selections are in caret positions.
1531 bool wxRichTextCtrl::ExtendSelection(long oldPos
, long newPos
, int flags
)
1533 if (flags
& wxRICHTEXT_SHIFT_DOWN
)
1535 if (oldPos
== newPos
)
1538 wxRichTextSelection oldSelection
= m_selection
;
1540 m_selection
.SetContainer(GetFocusObject());
1542 wxRichTextRange oldRange
;
1543 if (m_selection
.IsValid())
1544 oldRange
= m_selection
.GetRange();
1546 oldRange
= wxRICHTEXT_NO_SELECTION
;
1547 wxRichTextRange newRange
;
1549 // If not currently selecting, start selecting
1550 if (oldRange
.GetStart() == -2)
1552 m_selectionAnchor
= oldPos
;
1554 if (oldPos
> newPos
)
1555 newRange
.SetRange(newPos
+1, oldPos
);
1557 newRange
.SetRange(oldPos
+1, newPos
);
1561 // Always ensure that the selection range start is greater than
1563 if (newPos
> m_selectionAnchor
)
1564 newRange
.SetRange(m_selectionAnchor
+1, newPos
);
1565 else if (newPos
== m_selectionAnchor
)
1566 newRange
= wxRichTextRange(-2, -2);
1568 newRange
.SetRange(newPos
+1, m_selectionAnchor
);
1571 m_selection
.SetRange(newRange
);
1573 RefreshForSelectionChange(oldSelection
, m_selection
);
1575 if (newRange
.GetStart() > newRange
.GetEnd())
1577 wxLogDebug(wxT("Strange selection range"));
1586 /// Scroll into view, returning true if we scrolled.
1587 /// This takes a _caret_ position.
1588 bool wxRichTextCtrl::ScrollIntoView(long position
, int keyCode
)
1590 wxRichTextLine
* line
= GetVisibleLineForCaretPosition(position
);
1596 GetScrollPixelsPerUnit(& ppuX
, & ppuY
);
1598 int startXUnits
, startYUnits
;
1599 GetViewStart(& startXUnits
, & startYUnits
);
1600 int startY
= startYUnits
* ppuY
;
1603 GetVirtualSize(& sx
, & sy
);
1609 wxRect rect
= line
->GetRect();
1611 bool scrolled
= false;
1613 wxSize clientSize
= GetClientSize();
1615 int leftMargin
, rightMargin
, topMargin
, bottomMargin
;
1618 wxClientDC
dc(this);
1619 wxRichTextObject::GetTotalMargin(dc
, & GetBuffer(), GetBuffer().GetAttributes(), leftMargin
, rightMargin
,
1620 topMargin
, bottomMargin
);
1622 // clientSize.y -= GetBuffer().GetBottomMargin();
1623 clientSize
.y
-= bottomMargin
;
1625 if (GetWindowStyle() & wxRE_CENTRE_CARET
)
1627 int y
= rect
.y
- GetClientSize().y
/2;
1628 int yUnits
= (int) (0.5 + ((float) y
)/(float) ppuY
);
1629 if (y
>= 0 && (y
+ clientSize
.y
) < GetBuffer().GetCachedSize().y
)
1631 if (startYUnits
!= yUnits
)
1633 SetScrollbars(ppuX
, ppuY
, sxUnits
, syUnits
, 0, yUnits
);
1636 #if !wxRICHTEXT_USE_OWN_CARET
1646 if (keyCode
== WXK_DOWN
|| keyCode
== WXK_NUMPAD_DOWN
||
1647 keyCode
== WXK_RIGHT
|| keyCode
== WXK_NUMPAD_RIGHT
||
1648 keyCode
== WXK_END
|| keyCode
== WXK_NUMPAD_END
||
1649 keyCode
== WXK_PAGEDOWN
|| keyCode
== WXK_NUMPAD_PAGEDOWN
)
1651 if ((rect
.y
+ rect
.height
) > (clientSize
.y
+ startY
))
1653 // Make it scroll so this item is at the bottom
1655 int y
= rect
.y
- (clientSize
.y
- rect
.height
);
1656 int yUnits
= (int) (0.5 + ((float) y
)/(float) ppuY
);
1658 // If we're still off the screen, scroll another line down
1659 if ((rect
.y
+ rect
.height
) > (clientSize
.y
+ (yUnits
*ppuY
)))
1662 if (startYUnits
!= yUnits
)
1664 SetScrollbars(ppuX
, ppuY
, sxUnits
, syUnits
, 0, yUnits
);
1668 else if (rect
.y
< (startY
+ GetBuffer().GetTopMargin()))
1670 // Make it scroll so this item is at the top
1672 int y
= rect
.y
- GetBuffer().GetTopMargin();
1673 int yUnits
= (int) (0.5 + ((float) y
)/(float) ppuY
);
1675 if (startYUnits
!= yUnits
)
1677 SetScrollbars(ppuX
, ppuY
, sxUnits
, syUnits
, 0, yUnits
);
1683 else if (keyCode
== WXK_UP
|| keyCode
== WXK_NUMPAD_UP
||
1684 keyCode
== WXK_LEFT
|| keyCode
== WXK_NUMPAD_LEFT
||
1685 keyCode
== WXK_HOME
|| keyCode
== WXK_NUMPAD_HOME
||
1686 keyCode
== WXK_PAGEUP
|| keyCode
== WXK_NUMPAD_PAGEUP
)
1688 if (rect
.y
< (startY
+ GetBuffer().GetBottomMargin()))
1690 // Make it scroll so this item is at the top
1692 int y
= rect
.y
- GetBuffer().GetTopMargin();
1693 int yUnits
= (int) (0.5 + ((float) y
)/(float) ppuY
);
1695 if (startYUnits
!= yUnits
)
1697 SetScrollbars(ppuX
, ppuY
, sxUnits
, syUnits
, 0, yUnits
);
1701 else if ((rect
.y
+ rect
.height
) > (clientSize
.y
+ startY
))
1703 // Make it scroll so this item is at the bottom
1705 int y
= rect
.y
- (clientSize
.y
- rect
.height
);
1706 int yUnits
= (int) (0.5 + ((float) y
)/(float) ppuY
);
1708 // If we're still off the screen, scroll another line down
1709 if ((rect
.y
+ rect
.height
) > (clientSize
.y
+ (yUnits
*ppuY
)))
1712 if (startYUnits
!= yUnits
)
1714 SetScrollbars(ppuX
, ppuY
, sxUnits
, syUnits
, 0, yUnits
);
1720 #if !wxRICHTEXT_USE_OWN_CARET
1728 /// Is the given position visible on the screen?
1729 bool wxRichTextCtrl::IsPositionVisible(long pos
) const
1731 wxRichTextLine
* line
= GetVisibleLineForCaretPosition(pos
-1);
1737 GetScrollPixelsPerUnit(& ppuX
, & ppuY
);
1740 GetViewStart(& startX
, & startY
);
1742 startY
= startY
* ppuY
;
1744 wxRect rect
= line
->GetRect();
1745 wxSize clientSize
= GetClientSize();
1746 clientSize
.y
-= GetBuffer().GetBottomMargin();
1748 return (rect
.GetTop() >= (startY
+ GetBuffer().GetTopMargin())) && (rect
.GetBottom() <= (startY
+ clientSize
.y
));
1751 void wxRichTextCtrl::SetCaretPosition(long position
, bool showAtLineStart
)
1753 m_caretPosition
= position
;
1754 m_caretAtLineStart
= showAtLineStart
;
1757 /// Move caret one visual step forward: this may mean setting a flag
1758 /// and keeping the same position if we're going from the end of one line
1759 /// to the start of the next, which may be the exact same caret position.
1760 void wxRichTextCtrl::MoveCaretForward(long oldPosition
)
1762 wxRichTextParagraph
* para
= GetFocusObject()->GetParagraphAtPosition(oldPosition
);
1764 // Only do the check if we're not at the end of the paragraph (where things work OK
1766 if (para
&& (oldPosition
!= para
->GetRange().GetEnd() - 1))
1768 wxRichTextLine
* line
= GetFocusObject()->GetLineAtPosition(oldPosition
);
1772 wxRichTextRange lineRange
= line
->GetAbsoluteRange();
1774 // We're at the end of a line. See whether we need to
1775 // stay at the same actual caret position but change visual
1776 // position, or not.
1777 if (oldPosition
== lineRange
.GetEnd())
1779 if (m_caretAtLineStart
)
1781 // We're already at the start of the line, so actually move on now.
1782 m_caretPosition
= oldPosition
+ 1;
1783 m_caretAtLineStart
= false;
1787 // We're showing at the end of the line, so keep to
1788 // the same position but indicate that we're to show
1789 // at the start of the next line.
1790 m_caretPosition
= oldPosition
;
1791 m_caretAtLineStart
= true;
1793 SetDefaultStyleToCursorStyle();
1799 SetDefaultStyleToCursorStyle();
1802 /// Move caret one visual step backward: this may mean setting a flag
1803 /// and keeping the same position if we're going from the end of one line
1804 /// to the start of the next, which may be the exact same caret position.
1805 void wxRichTextCtrl::MoveCaretBack(long oldPosition
)
1807 wxRichTextParagraph
* para
= GetFocusObject()->GetParagraphAtPosition(oldPosition
);
1809 // Only do the check if we're not at the start of the paragraph (where things work OK
1811 if (para
&& (oldPosition
!= para
->GetRange().GetStart()))
1813 wxRichTextLine
* line
= GetFocusObject()->GetLineAtPosition(oldPosition
);
1817 wxRichTextRange lineRange
= line
->GetAbsoluteRange();
1819 // We're at the start of a line. See whether we need to
1820 // stay at the same actual caret position but change visual
1821 // position, or not.
1822 if (oldPosition
== lineRange
.GetStart())
1824 m_caretPosition
= oldPosition
-1;
1825 m_caretAtLineStart
= true;
1828 else if (oldPosition
== lineRange
.GetEnd())
1830 if (m_caretAtLineStart
)
1832 // We're at the start of the line, so keep the same caret position
1833 // but clear the start-of-line flag.
1834 m_caretPosition
= oldPosition
;
1835 m_caretAtLineStart
= false;
1839 // We're showing at the end of the line, so go back
1840 // to the previous character position.
1841 m_caretPosition
= oldPosition
- 1;
1843 SetDefaultStyleToCursorStyle();
1849 SetDefaultStyleToCursorStyle();
1853 bool wxRichTextCtrl::MoveRight(int noPositions
, int flags
)
1855 long endPos
= GetFocusObject()->GetOwnRange().GetEnd();
1857 if (m_caretPosition
+ noPositions
< endPos
)
1859 long oldPos
= m_caretPosition
;
1860 long newPos
= m_caretPosition
+ noPositions
;
1862 bool extendSel
= ExtendSelection(m_caretPosition
, newPos
, flags
);
1866 // Determine by looking at oldPos and m_caretPosition whether
1867 // we moved from the end of a line to the start of the next line, in which case
1868 // we want to adjust the caret position such that it is positioned at the
1869 // start of the next line, rather than jumping past the first character of the
1871 if (noPositions
== 1 && !extendSel
)
1872 MoveCaretForward(oldPos
);
1874 SetCaretPosition(newPos
);
1877 SetDefaultStyleToCursorStyle();
1886 bool wxRichTextCtrl::MoveLeft(int noPositions
, int flags
)
1890 if (m_caretPosition
> startPos
- noPositions
+ 1)
1892 long oldPos
= m_caretPosition
;
1893 long newPos
= m_caretPosition
- noPositions
;
1894 bool extendSel
= ExtendSelection(m_caretPosition
, newPos
, flags
);
1898 if (noPositions
== 1 && !extendSel
)
1899 MoveCaretBack(oldPos
);
1901 SetCaretPosition(newPos
);
1904 SetDefaultStyleToCursorStyle();
1912 // Find the caret position for the combination of hit-test flags and character position.
1913 // Returns the caret position and also an indication of where to place the caret (caretLineStart)
1914 // since this is ambiguous (same position used for end of line and start of next).
1915 long wxRichTextCtrl::FindCaretPositionForCharacterPosition(long position
, int hitTestFlags
, wxRichTextParagraphLayoutBox
* container
,
1916 bool& caretLineStart
)
1918 // If end of previous line, and hitTest is wxRICHTEXT_HITTEST_BEFORE,
1919 // we want to be at the end of the last line but with m_caretAtLineStart set to true,
1920 // so we view the caret at the start of the line.
1921 caretLineStart
= false;
1922 long caretPosition
= position
;
1924 if (hitTestFlags
& wxRICHTEXT_HITTEST_BEFORE
)
1926 wxRichTextLine
* thisLine
= container
->GetLineAtPosition(position
-1);
1927 wxRichTextRange lineRange
;
1929 lineRange
= thisLine
->GetAbsoluteRange();
1931 if (thisLine
&& (position
-1) == lineRange
.GetEnd())
1934 caretLineStart
= true;
1938 wxRichTextParagraph
* para
= container
->GetParagraphAtPosition(position
);
1939 if (para
&& para
->GetRange().GetStart() == position
)
1943 return caretPosition
;
1947 bool wxRichTextCtrl::MoveUp(int noLines
, int flags
)
1949 return MoveDown(- noLines
, flags
);
1953 bool wxRichTextCtrl::MoveDown(int noLines
, int flags
)
1958 long lineNumber
= GetFocusObject()->GetVisibleLineNumber(m_caretPosition
, true, m_caretAtLineStart
);
1959 wxPoint pt
= GetCaret()->GetPosition();
1960 long newLine
= lineNumber
+ noLines
;
1961 bool notInThisObject
= false;
1963 if (lineNumber
!= -1)
1967 long lastLine
= GetFocusObject()->GetVisibleLineNumber(GetFocusObject()->GetOwnRange().GetEnd());
1968 if (newLine
> lastLine
)
1969 notInThisObject
= true;
1974 notInThisObject
= true;
1978 wxRichTextParagraphLayoutBox
* container
= GetFocusObject();
1979 int hitTestFlags
= wxRICHTEXT_HITTEST_NO_NESTED_OBJECTS
|wxRICHTEXT_HITTEST_NO_FLOATING_OBJECTS
;
1981 if (notInThisObject
)
1983 // If we know we're navigating out of the current object,
1984 // try to find an object anywhere in the buffer at the new position (up or down a bit)
1985 container
= & GetBuffer();
1986 hitTestFlags
&= ~wxRICHTEXT_HITTEST_NO_NESTED_OBJECTS
;
1988 if (noLines
> 0) // going down
1990 pt
.y
= GetFocusObject()->GetPosition().y
+ GetFocusObject()->GetCachedSize().y
+ 2;
1994 pt
.y
= GetFocusObject()->GetPosition().y
- 2;
1999 wxRichTextLine
* lineObj
= GetFocusObject()->GetLineForVisibleLineNumber(newLine
);
2001 pt
.y
= lineObj
->GetAbsolutePosition().y
+ 2;
2007 wxClientDC
dc(this);
2009 dc
.SetFont(GetFont());
2011 wxRichTextObject
* hitObj
= NULL
;
2012 wxRichTextObject
* contextObj
= NULL
;
2013 int hitTest
= container
->HitTest(dc
, pt
, newPos
, & hitObj
, & contextObj
, hitTestFlags
);
2016 ((hitTest
& wxRICHTEXT_HITTEST_NONE
) == 0) &&
2017 (! (hitObj
== (& m_buffer
) && ((hitTest
& wxRICHTEXT_HITTEST_OUTSIDE
) != 0))) // outside the buffer counts as 'do nothing'
2020 if (notInThisObject
)
2022 wxRichTextParagraphLayoutBox
* actualContainer
= wxDynamicCast(contextObj
, wxRichTextParagraphLayoutBox
);
2023 if (actualContainer
&& actualContainer
!= GetFocusObject() && actualContainer
->AcceptsFocus())
2025 SetFocusObject(actualContainer
, false /* don't set caret position yet */);
2027 container
= actualContainer
;
2031 bool caretLineStart
= true;
2032 long caretPosition
= FindCaretPositionForCharacterPosition(newPos
, hitTest
, container
, caretLineStart
);
2033 long newSelEnd
= caretPosition
;
2036 if (notInThisObject
)
2039 extendSel
= ExtendSelection(m_caretPosition
, newSelEnd
, flags
);
2044 SetCaretPosition(caretPosition
, caretLineStart
);
2046 SetDefaultStyleToCursorStyle();
2054 /// Move to the end of the paragraph
2055 bool wxRichTextCtrl::MoveToParagraphEnd(int flags
)
2057 wxRichTextParagraph
* para
= GetFocusObject()->GetParagraphAtPosition(m_caretPosition
, true);
2060 long newPos
= para
->GetRange().GetEnd() - 1;
2061 bool extendSel
= ExtendSelection(m_caretPosition
, newPos
, flags
);
2065 SetCaretPosition(newPos
);
2067 SetDefaultStyleToCursorStyle();
2075 /// Move to the start of the paragraph
2076 bool wxRichTextCtrl::MoveToParagraphStart(int flags
)
2078 wxRichTextParagraph
* para
= GetFocusObject()->GetParagraphAtPosition(m_caretPosition
, true);
2081 long newPos
= para
->GetRange().GetStart() - 1;
2082 bool extendSel
= ExtendSelection(m_caretPosition
, newPos
, flags
);
2086 SetCaretPosition(newPos
);
2088 SetDefaultStyleToCursorStyle();
2096 /// Move to the end of the line
2097 bool wxRichTextCtrl::MoveToLineEnd(int flags
)
2099 wxRichTextLine
* line
= GetVisibleLineForCaretPosition(m_caretPosition
);
2103 wxRichTextRange lineRange
= line
->GetAbsoluteRange();
2104 long newPos
= lineRange
.GetEnd();
2105 bool extendSel
= ExtendSelection(m_caretPosition
, newPos
, flags
);
2109 SetCaretPosition(newPos
);
2111 SetDefaultStyleToCursorStyle();
2119 /// Move to the start of the line
2120 bool wxRichTextCtrl::MoveToLineStart(int flags
)
2122 wxRichTextLine
* line
= GetVisibleLineForCaretPosition(m_caretPosition
);
2125 wxRichTextRange lineRange
= line
->GetAbsoluteRange();
2126 long newPos
= lineRange
.GetStart()-1;
2128 bool extendSel
= ExtendSelection(m_caretPosition
, newPos
, flags
);
2132 wxRichTextParagraph
* para
= GetFocusObject()->GetParagraphForLine(line
);
2134 SetCaretPosition(newPos
, para
->GetRange().GetStart() != lineRange
.GetStart());
2136 SetDefaultStyleToCursorStyle();
2144 /// Move to the start of the buffer
2145 bool wxRichTextCtrl::MoveHome(int flags
)
2147 if (m_caretPosition
!= -1)
2149 bool extendSel
= ExtendSelection(m_caretPosition
, -1, flags
);
2153 SetCaretPosition(-1);
2155 SetDefaultStyleToCursorStyle();
2163 /// Move to the end of the buffer
2164 bool wxRichTextCtrl::MoveEnd(int flags
)
2166 long endPos
= GetFocusObject()->GetOwnRange().GetEnd()-1;
2168 if (m_caretPosition
!= endPos
)
2170 bool extendSel
= ExtendSelection(m_caretPosition
, endPos
, flags
);
2174 SetCaretPosition(endPos
);
2176 SetDefaultStyleToCursorStyle();
2184 /// Move noPages pages up
2185 bool wxRichTextCtrl::PageUp(int noPages
, int flags
)
2187 return PageDown(- noPages
, flags
);
2190 /// Move noPages pages down
2191 bool wxRichTextCtrl::PageDown(int noPages
, int flags
)
2193 // Calculate which line occurs noPages * screen height further down.
2194 wxRichTextLine
* line
= GetVisibleLineForCaretPosition(m_caretPosition
);
2197 wxSize clientSize
= GetClientSize();
2198 int newY
= line
->GetAbsolutePosition().y
+ noPages
*clientSize
.y
;
2200 wxRichTextLine
* newLine
= GetFocusObject()->GetLineAtYPosition(newY
);
2203 wxRichTextRange lineRange
= newLine
->GetAbsoluteRange();
2204 long pos
= lineRange
.GetStart()-1;
2205 if (pos
!= m_caretPosition
)
2207 wxRichTextParagraph
* para
= GetFocusObject()->GetParagraphForLine(newLine
);
2209 bool extendSel
= ExtendSelection(m_caretPosition
, pos
, flags
);
2213 SetCaretPosition(pos
, para
->GetRange().GetStart() != lineRange
.GetStart());
2215 SetDefaultStyleToCursorStyle();
2225 static bool wxRichTextCtrlIsWhitespace(const wxString
& str
)
2227 return str
== wxT(" ") || str
== wxT("\t");
2230 // Finds the caret position for the next word
2231 long wxRichTextCtrl::FindNextWordPosition(int direction
) const
2233 long endPos
= GetFocusObject()->GetOwnRange().GetEnd();
2237 long i
= m_caretPosition
+1+direction
; // +1 for conversion to character pos
2239 // First skip current text to space
2240 while (i
< endPos
&& i
> -1)
2242 // i is in character, not caret positions
2243 wxString text
= GetFocusObject()->GetTextForRange(wxRichTextRange(i
, i
));
2244 wxRichTextLine
* line
= GetFocusObject()->GetLineAtPosition(i
, false);
2245 if (line
&& (i
== line
->GetAbsoluteRange().GetEnd()))
2249 else if (!wxRichTextCtrlIsWhitespace(text
) && !text
.empty())
2256 while (i
< endPos
&& i
> -1)
2258 // i is in character, not caret positions
2259 wxString text
= GetFocusObject()->GetTextForRange(wxRichTextRange(i
, i
));
2260 wxRichTextLine
* line
= GetFocusObject()->GetLineAtPosition(i
, false);
2261 if (line
&& (i
== line
->GetAbsoluteRange().GetEnd()))
2262 return wxMax(-1, i
);
2264 if (text
.empty()) // End of paragraph, or maybe an image
2265 return wxMax(-1, i
- 1);
2266 else if (wxRichTextCtrlIsWhitespace(text
) || text
.empty())
2270 // Convert to caret position
2271 return wxMax(-1, i
- 1);
2280 long i
= m_caretPosition
;
2282 // First skip white space
2283 while (i
< endPos
&& i
> -1)
2285 // i is in character, not caret positions
2286 wxString text
= GetFocusObject()->GetTextForRange(wxRichTextRange(i
, i
));
2287 wxRichTextLine
* line
= GetFocusObject()->GetLineAtPosition(i
, false);
2289 if (text
.empty() || (line
&& (i
== line
->GetAbsoluteRange().GetStart()))) // End of paragraph, or maybe an image
2291 else if (wxRichTextCtrlIsWhitespace(text
) || text
.empty())
2296 // Next skip current text to space
2297 while (i
< endPos
&& i
> -1)
2299 // i is in character, not caret positions
2300 wxString text
= GetFocusObject()->GetTextForRange(wxRichTextRange(i
, i
));
2301 wxRichTextLine
* line
= GetFocusObject()->GetLineAtPosition(i
, false);
2302 if (line
&& line
->GetAbsoluteRange().GetStart() == i
)
2305 if (!wxRichTextCtrlIsWhitespace(text
) /* && !text.empty() */)
2318 /// Move n words left
2319 bool wxRichTextCtrl::WordLeft(int WXUNUSED(n
), int flags
)
2321 long pos
= FindNextWordPosition(-1);
2322 if (pos
!= m_caretPosition
)
2324 wxRichTextParagraph
* para
= GetFocusObject()->GetParagraphAtPosition(pos
, true);
2326 bool extendSel
= ExtendSelection(m_caretPosition
, pos
, flags
);
2330 SetCaretPosition(pos
, para
->GetRange().GetStart() != pos
);
2332 SetDefaultStyleToCursorStyle();
2340 /// Move n words right
2341 bool wxRichTextCtrl::WordRight(int WXUNUSED(n
), int flags
)
2343 long pos
= FindNextWordPosition(1);
2344 if (pos
!= m_caretPosition
)
2346 wxRichTextParagraph
* para
= GetFocusObject()->GetParagraphAtPosition(pos
, true);
2348 bool extendSel
= ExtendSelection(m_caretPosition
, pos
, flags
);
2352 SetCaretPosition(pos
, para
->GetRange().GetStart() != pos
);
2354 SetDefaultStyleToCursorStyle();
2363 void wxRichTextCtrl::OnSize(wxSizeEvent
& event
)
2365 // Only do sizing optimization for large buffers
2366 if (GetBuffer().GetOwnRange().GetEnd() > m_delayedLayoutThreshold
)
2368 m_fullLayoutRequired
= true;
2369 m_fullLayoutTime
= wxGetLocalTimeMillis();
2370 m_fullLayoutSavedPosition
= GetFirstVisiblePosition();
2371 LayoutContent(true /* onlyVisibleRect */);
2374 GetBuffer().Invalidate(wxRICHTEXT_ALL
);
2376 #if wxRICHTEXT_BUFFERED_PAINTING
2383 // Force any pending layout due to large buffer
2384 void wxRichTextCtrl::ForceDelayedLayout()
2386 if (m_fullLayoutRequired
)
2388 m_fullLayoutRequired
= false;
2389 m_fullLayoutTime
= 0;
2390 GetBuffer().Invalidate(wxRICHTEXT_ALL
);
2391 ShowPosition(m_fullLayoutSavedPosition
);
2397 /// Idle-time processing
2398 void wxRichTextCtrl::OnIdle(wxIdleEvent
& event
)
2400 #if wxRICHTEXT_USE_OWN_CARET
2401 if (((wxRichTextCaret
*) GetCaret())->GetNeedsUpdate())
2403 ((wxRichTextCaret
*) GetCaret())->SetNeedsUpdate(false);
2409 const int layoutInterval
= wxRICHTEXT_DEFAULT_LAYOUT_INTERVAL
;
2411 if (m_fullLayoutRequired
&& (wxGetLocalTimeMillis() > (m_fullLayoutTime
+ layoutInterval
)))
2413 m_fullLayoutRequired
= false;
2414 m_fullLayoutTime
= 0;
2415 GetBuffer().Invalidate(wxRICHTEXT_ALL
);
2416 ShowPosition(m_fullLayoutSavedPosition
);
2420 if (m_caretPositionForDefaultStyle
!= -2)
2422 // If the caret position has changed, no longer reflect the default style
2424 if (GetCaretPosition() != m_caretPositionForDefaultStyle
)
2425 m_caretPositionForDefaultStyle
= -2;
2432 void wxRichTextCtrl::OnScroll(wxScrollWinEvent
& event
)
2434 #if wxRICHTEXT_USE_OWN_CARET
2435 if (!((wxRichTextCaret
*) GetCaret())->GetNeedsUpdate())
2438 ((wxRichTextCaret
*) GetCaret())->SetNeedsUpdate();
2445 /// Set up scrollbars, e.g. after a resize
2446 void wxRichTextCtrl::SetupScrollbars(bool atTop
)
2451 if (GetBuffer().IsEmpty())
2453 SetScrollbars(0, 0, 0, 0, 0, 0);
2457 // TODO: reimplement scrolling so we scroll by line, not by fixed number
2458 // of pixels. See e.g. wxVScrolledWindow for ideas.
2459 int pixelsPerUnit
= 5;
2460 wxSize clientSize
= GetClientSize();
2462 int maxHeight
= GetBuffer().GetCachedSize().y
+ GetBuffer().GetTopMargin();
2464 // Round up so we have at least maxHeight pixels
2465 int unitsY
= (int) (((float)maxHeight
/(float)pixelsPerUnit
) + 0.5);
2467 int startX
= 0, startY
= 0;
2469 GetViewStart(& startX
, & startY
);
2471 int maxPositionX
= 0;
2472 int maxPositionY
= (int) ((((float)(wxMax((unitsY
*pixelsPerUnit
) - clientSize
.y
, 0)))/((float)pixelsPerUnit
)) + 0.5);
2474 int newStartX
= wxMin(maxPositionX
, startX
);
2475 int newStartY
= wxMin(maxPositionY
, startY
);
2477 int oldPPUX
, oldPPUY
;
2478 int oldStartX
, oldStartY
;
2479 int oldVirtualSizeX
= 0, oldVirtualSizeY
= 0;
2480 GetScrollPixelsPerUnit(& oldPPUX
, & oldPPUY
);
2481 GetViewStart(& oldStartX
, & oldStartY
);
2482 GetVirtualSize(& oldVirtualSizeX
, & oldVirtualSizeY
);
2484 oldVirtualSizeY
/= oldPPUY
;
2486 if (oldPPUX
== 0 && oldPPUY
== pixelsPerUnit
&& oldVirtualSizeY
== unitsY
&& oldStartX
== newStartX
&& oldStartY
== newStartY
)
2489 // Don't set scrollbars if there were none before, and there will be none now.
2490 if (oldPPUY
!= 0 && (oldVirtualSizeY
*oldPPUY
< clientSize
.y
) && (unitsY
*pixelsPerUnit
< clientSize
.y
))
2493 // Move to previous scroll position if
2495 SetScrollbars(0, pixelsPerUnit
, 0, unitsY
, newStartX
, newStartY
);
2498 /// Paint the background
2499 void wxRichTextCtrl::PaintBackground(wxDC
& dc
)
2501 wxColour backgroundColour
= GetBackgroundColour();
2502 if (!backgroundColour
.IsOk())
2503 backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
2505 // Clear the background
2506 dc
.SetBrush(wxBrush(backgroundColour
));
2507 dc
.SetPen(*wxTRANSPARENT_PEN
);
2508 wxRect
windowRect(GetClientSize());
2509 windowRect
.x
-= 2; windowRect
.y
-= 2;
2510 windowRect
.width
+= 4; windowRect
.height
+= 4;
2512 // We need to shift the rectangle to take into account
2513 // scrolling. Converting device to logical coordinates.
2514 CalcUnscrolledPosition(windowRect
.x
, windowRect
.y
, & windowRect
.x
, & windowRect
.y
);
2515 dc
.DrawRectangle(windowRect
);
2518 #if wxRICHTEXT_BUFFERED_PAINTING
2519 /// Recreate buffer bitmap if necessary
2520 bool wxRichTextCtrl::RecreateBuffer(const wxSize
& size
)
2523 if (sz
== wxDefaultSize
)
2524 sz
= GetClientSize();
2526 if (sz
.x
< 1 || sz
.y
< 1)
2529 if (!m_bufferBitmap
.IsOk() || m_bufferBitmap
.GetWidth() < sz
.x
|| m_bufferBitmap
.GetHeight() < sz
.y
)
2530 m_bufferBitmap
= wxBitmap(sz
.x
, sz
.y
);
2531 return m_bufferBitmap
.IsOk();
2535 // ----------------------------------------------------------------------------
2536 // file IO functions
2537 // ----------------------------------------------------------------------------
2539 bool wxRichTextCtrl::DoLoadFile(const wxString
& filename
, int fileType
)
2541 bool success
= GetBuffer().LoadFile(filename
, (wxRichTextFileType
)fileType
);
2543 m_filename
= filename
;
2546 SetInsertionPoint(0);
2549 SetupScrollbars(true);
2551 wxTextCtrl::SendTextUpdatedEvent(this);
2557 wxLogError(_("File couldn't be loaded."));
2563 bool wxRichTextCtrl::DoSaveFile(const wxString
& filename
, int fileType
)
2565 if (GetBuffer().SaveFile(filename
, (wxRichTextFileType
)fileType
))
2567 m_filename
= filename
;
2574 wxLogError(_("The text couldn't be saved."));
2579 // ----------------------------------------------------------------------------
2580 // wxRichTextCtrl specific functionality
2581 // ----------------------------------------------------------------------------
2583 /// Add a new paragraph of text to the end of the buffer
2584 wxRichTextRange
wxRichTextCtrl::AddParagraph(const wxString
& text
)
2586 wxRichTextRange range
= GetFocusObject()->AddParagraph(text
);
2587 GetBuffer().Invalidate();
2593 wxRichTextRange
wxRichTextCtrl::AddImage(const wxImage
& image
)
2595 wxRichTextRange range
= GetFocusObject()->AddImage(image
);
2596 GetBuffer().Invalidate();
2601 // ----------------------------------------------------------------------------
2602 // selection and ranges
2603 // ----------------------------------------------------------------------------
2605 void wxRichTextCtrl::SelectAll()
2607 SetSelection(-1, -1);
2611 void wxRichTextCtrl::SelectNone()
2613 if (m_selection
.IsValid())
2615 wxRichTextSelection oldSelection
= m_selection
;
2617 m_selection
.Reset();
2619 RefreshForSelectionChange(oldSelection
, m_selection
);
2621 m_selectionAnchor
= -2;
2622 m_selectionAnchorObject
= NULL
;
2623 m_selectionState
= wxRichTextCtrlSelectionState_Normal
;
2626 static bool wxIsWordDelimiter(const wxString
& text
)
2628 return !text
.IsEmpty() && !wxIsalnum(text
[0]);
2631 /// Select the word at the given character position
2632 bool wxRichTextCtrl::SelectWord(long position
)
2634 if (position
< 0 || position
> GetFocusObject()->GetOwnRange().GetEnd())
2637 wxRichTextParagraph
* para
= GetFocusObject()->GetParagraphAtPosition(position
);
2641 if (position
== para
->GetRange().GetEnd())
2644 long positionStart
= position
;
2645 long positionEnd
= position
;
2647 for (positionStart
= position
; positionStart
>= para
->GetRange().GetStart(); positionStart
--)
2649 wxString text
= GetFocusObject()->GetTextForRange(wxRichTextRange(positionStart
, positionStart
));
2650 if (wxIsWordDelimiter(text
))
2656 if (positionStart
< para
->GetRange().GetStart())
2657 positionStart
= para
->GetRange().GetStart();
2659 for (positionEnd
= position
; positionEnd
< para
->GetRange().GetEnd(); positionEnd
++)
2661 wxString text
= GetFocusObject()->GetTextForRange(wxRichTextRange(positionEnd
, positionEnd
));
2662 if (wxIsWordDelimiter(text
))
2668 if (positionEnd
>= para
->GetRange().GetEnd())
2669 positionEnd
= para
->GetRange().GetEnd();
2671 if (positionEnd
< positionStart
)
2674 SetSelection(positionStart
, positionEnd
+1);
2676 if (positionStart
>= 0)
2678 MoveCaret(positionStart
-1, true);
2679 SetDefaultStyleToCursorStyle();
2685 wxString
wxRichTextCtrl::GetStringSelection() const
2688 GetSelection(&from
, &to
);
2690 return GetRange(from
, to
);
2693 // ----------------------------------------------------------------------------
2695 // ----------------------------------------------------------------------------
2697 wxTextCtrlHitTestResult
2698 wxRichTextCtrl::HitTest(const wxPoint
& pt
, wxTextCoord
*x
, wxTextCoord
*y
) const
2700 // implement in terms of the other overload as the native ports typically
2701 // can get the position and not (x, y) pair directly (although wxUniv
2702 // directly gets x and y -- and so overrides this method as well)
2704 wxTextCtrlHitTestResult rc
= HitTest(pt
, &pos
);
2706 if ( rc
!= wxTE_HT_UNKNOWN
)
2708 PositionToXY(pos
, x
, y
);
2714 wxTextCtrlHitTestResult
2715 wxRichTextCtrl::HitTest(const wxPoint
& pt
,
2718 wxClientDC
dc((wxRichTextCtrl
*) this);
2719 ((wxRichTextCtrl
*)this)->PrepareDC(dc
);
2721 // Buffer uses logical position (relative to start of buffer)
2723 wxPoint pt2
= GetLogicalPoint(pt
);
2725 wxRichTextObject
* hitObj
= NULL
;
2726 wxRichTextObject
* contextObj
= NULL
;
2727 int hit
= ((wxRichTextCtrl
*)this)->GetFocusObject()->HitTest(dc
, pt2
, *pos
, & hitObj
, & contextObj
, wxRICHTEXT_HITTEST_NO_NESTED_OBJECTS
);
2729 if ((hit
& wxRICHTEXT_HITTEST_BEFORE
) && (hit
& wxRICHTEXT_HITTEST_OUTSIDE
))
2730 return wxTE_HT_BEFORE
;
2731 else if ((hit
& wxRICHTEXT_HITTEST_AFTER
) && (hit
& wxRICHTEXT_HITTEST_OUTSIDE
))
2732 return wxTE_HT_BEYOND
;
2733 else if (hit
& (wxRICHTEXT_HITTEST_BEFORE
|wxRICHTEXT_HITTEST_AFTER
))
2734 return wxTE_HT_ON_TEXT
;
2736 return wxTE_HT_UNKNOWN
;
2739 wxRichTextParagraphLayoutBox
*
2740 wxRichTextCtrl::FindContainerAtPoint(const wxPoint pt
, long& position
, int& hit
, wxRichTextObject
* hitObj
, int flags
/* = 0*/)
2742 wxClientDC
dc(this);
2744 dc
.SetFont(GetFont());
2746 wxPoint logicalPt
= GetLogicalPoint(pt
);
2748 wxRichTextObject
* contextObj
= NULL
;
2749 hit
= GetBuffer().HitTest(dc
, logicalPt
, position
, &hitObj
, &contextObj
, flags
);
2750 wxRichTextParagraphLayoutBox
* container
= wxDynamicCast(contextObj
, wxRichTextParagraphLayoutBox
);
2756 // ----------------------------------------------------------------------------
2757 // set/get the controls text
2758 // ----------------------------------------------------------------------------
2760 wxString
wxRichTextCtrl::DoGetValue() const
2762 return GetBuffer().GetText();
2765 wxString
wxRichTextCtrl::GetRange(long from
, long to
) const
2767 // Public API for range is different from internals
2768 return GetFocusObject()->GetTextForRange(wxRichTextRange(from
, to
-1));
2771 void wxRichTextCtrl::DoSetValue(const wxString
& value
, int flags
)
2773 // Don't call Clear here, since it always sends a text updated event
2774 m_buffer
.ResetAndClearCommands();
2775 m_buffer
.Invalidate(wxRICHTEXT_ALL
);
2776 m_caretPosition
= -1;
2777 m_caretPositionForDefaultStyle
= -2;
2778 m_caretAtLineStart
= false;
2779 m_selection
.Reset();
2780 m_selectionState
= wxRichTextCtrlSelectionState_Normal
;
2790 if (!value
.IsEmpty())
2792 // Remove empty paragraph
2793 GetBuffer().Clear();
2794 DoWriteText(value
, flags
);
2796 // for compatibility, don't move the cursor when doing SetValue()
2797 SetInsertionPoint(0);
2801 // still send an event for consistency
2802 if (flags
& SetValue_SendEvent
)
2803 wxTextCtrl::SendTextUpdatedEvent(this);
2808 void wxRichTextCtrl::WriteText(const wxString
& value
)
2813 void wxRichTextCtrl::DoWriteText(const wxString
& value
, int flags
)
2815 wxString valueUnix
= wxTextFile::Translate(value
, wxTextFileType_Unix
);
2817 GetFocusObject()->InsertTextWithUndo(& GetBuffer(), m_caretPosition
+1, valueUnix
, this, wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE
);
2819 if ( flags
& SetValue_SendEvent
)
2820 wxTextCtrl::SendTextUpdatedEvent(this);
2823 void wxRichTextCtrl::AppendText(const wxString
& text
)
2825 SetInsertionPointEnd();
2830 /// Write an image at the current insertion point
2831 bool wxRichTextCtrl::WriteImage(const wxImage
& image
, wxBitmapType bitmapType
, const wxRichTextAttr
& textAttr
)
2833 wxRichTextImageBlock imageBlock
;
2835 wxImage image2
= image
;
2836 if (imageBlock
.MakeImageBlock(image2
, bitmapType
))
2837 return WriteImage(imageBlock
, textAttr
);
2842 bool wxRichTextCtrl::WriteImage(const wxString
& filename
, wxBitmapType bitmapType
, const wxRichTextAttr
& textAttr
)
2844 wxRichTextImageBlock imageBlock
;
2847 if (imageBlock
.MakeImageBlock(filename
, bitmapType
, image
, false))
2848 return WriteImage(imageBlock
, textAttr
);
2853 bool wxRichTextCtrl::WriteImage(const wxRichTextImageBlock
& imageBlock
, const wxRichTextAttr
& textAttr
)
2855 return GetFocusObject()->InsertImageWithUndo(& GetBuffer(), m_caretPosition
+1, imageBlock
, this, 0, textAttr
);
2858 bool wxRichTextCtrl::WriteImage(const wxBitmap
& bitmap
, wxBitmapType bitmapType
, const wxRichTextAttr
& textAttr
)
2862 wxRichTextImageBlock imageBlock
;
2864 wxImage image
= bitmap
.ConvertToImage();
2865 if (image
.IsOk() && imageBlock
.MakeImageBlock(image
, bitmapType
))
2866 return WriteImage(imageBlock
, textAttr
);
2872 // Write a text box at the current insertion point.
2873 wxRichTextBox
* wxRichTextCtrl::WriteTextBox(const wxRichTextAttr
& textAttr
)
2875 wxRichTextBox
* textBox
= new wxRichTextBox
;
2876 textBox
->SetAttributes(textAttr
);
2877 textBox
->SetParent(& GetBuffer()); // set parent temporarily for AddParagraph to use correct style
2878 textBox
->AddParagraph(wxEmptyString
);
2879 textBox
->SetParent(NULL
);
2881 // The object returned is the one actually inserted into the buffer,
2882 // while the original one is deleted.
2883 wxRichTextObject
* obj
= GetFocusObject()->InsertObjectWithUndo(& GetBuffer(), m_caretPosition
+1, textBox
, this, wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE
);
2884 wxRichTextBox
* box
= wxDynamicCast(obj
, wxRichTextBox
);
2888 // Write a table at the current insertion point, returning the table.
2889 wxRichTextTable
* wxRichTextCtrl::WriteTable(int rows
, int cols
, const wxRichTextAttr
& tableAttr
, const wxRichTextAttr
& cellAttr
)
2891 wxASSERT(rows
> 0 && cols
> 0);
2893 if (rows
<= 0 || cols
<= 0)
2896 wxRichTextTable
* table
= new wxRichTextTable
;
2897 table
->SetAttributes(tableAttr
);
2898 table
->SetParent(& GetBuffer()); // set parent temporarily for AddParagraph to use correct style
2900 table
->CreateTable(rows
, cols
);
2902 table
->SetParent(NULL
);
2905 for (j
= 0; j
< rows
; j
++)
2907 for (i
= 0; i
< cols
; i
++)
2909 table
->GetCell(j
, i
)->GetAttributes() = cellAttr
;
2913 // The object returned is the one actually inserted into the buffer,
2914 // while the original one is deleted.
2915 wxRichTextObject
* obj
= GetFocusObject()->InsertObjectWithUndo(& GetBuffer(), m_caretPosition
+1, table
, this, wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE
);
2916 wxRichTextTable
* tableResult
= wxDynamicCast(obj
, wxRichTextTable
);
2921 /// Insert a newline (actually paragraph) at the current insertion point.
2922 bool wxRichTextCtrl::Newline()
2924 return GetFocusObject()->InsertNewlineWithUndo(& GetBuffer(), m_caretPosition
+1, this, wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE
);
2927 /// Insert a line break at the current insertion point.
2928 bool wxRichTextCtrl::LineBreak()
2931 text
= wxRichTextLineBreakChar
;
2932 return GetFocusObject()->InsertTextWithUndo(& GetBuffer(), m_caretPosition
+1, text
, this);
2935 // ----------------------------------------------------------------------------
2936 // Clipboard operations
2937 // ----------------------------------------------------------------------------
2939 void wxRichTextCtrl::Copy()
2943 wxRichTextRange range
= GetInternalSelectionRange();
2944 GetBuffer().CopyToClipboard(range
);
2948 void wxRichTextCtrl::Cut()
2952 wxRichTextRange range
= GetInternalSelectionRange();
2953 GetBuffer().CopyToClipboard(range
);
2955 DeleteSelectedContent();
2961 void wxRichTextCtrl::Paste()
2965 BeginBatchUndo(_("Paste"));
2967 long newPos
= m_caretPosition
;
2968 DeleteSelectedContent(& newPos
);
2970 GetBuffer().PasteFromClipboard(newPos
);
2976 void wxRichTextCtrl::DeleteSelection()
2978 if (CanDeleteSelection())
2980 DeleteSelectedContent();
2984 bool wxRichTextCtrl::HasSelection() const
2986 return (m_selection
.IsValid() && m_selection
.GetContainer() == GetFocusObject());
2989 bool wxRichTextCtrl::HasUnfocusedSelection() const
2991 return m_selection
.IsValid();
2994 bool wxRichTextCtrl::CanCopy() const
2996 // Can copy if there's a selection
2997 return HasSelection();
3000 bool wxRichTextCtrl::CanCut() const
3002 return HasSelection() && IsEditable();
3005 bool wxRichTextCtrl::CanPaste() const
3007 if ( !IsEditable() )
3010 return GetBuffer().CanPasteFromClipboard();
3013 bool wxRichTextCtrl::CanDeleteSelection() const
3015 return HasSelection() && IsEditable();
3019 // ----------------------------------------------------------------------------
3021 // ----------------------------------------------------------------------------
3023 void wxRichTextCtrl::SetContextMenu(wxMenu
* menu
)
3025 if (m_contextMenu
&& m_contextMenu
!= menu
)
3026 delete m_contextMenu
;
3027 m_contextMenu
= menu
;
3030 void wxRichTextCtrl::SetEditable(bool editable
)
3032 m_editable
= editable
;
3035 void wxRichTextCtrl::SetInsertionPoint(long pos
)
3039 m_caretPosition
= pos
- 1;
3043 SetDefaultStyleToCursorStyle();
3046 void wxRichTextCtrl::SetInsertionPointEnd()
3048 long pos
= GetLastPosition();
3049 SetInsertionPoint(pos
);
3052 long wxRichTextCtrl::GetInsertionPoint() const
3054 return m_caretPosition
+1;
3057 wxTextPos
wxRichTextCtrl::GetLastPosition() const
3059 return GetFocusObject()->GetOwnRange().GetEnd();
3062 // If the return values from and to are the same, there is no
3064 void wxRichTextCtrl::GetSelection(long* from
, long* to
) const
3066 if (m_selection
.IsValid())
3068 *from
= m_selection
.GetRange().GetStart();
3069 *to
= m_selection
.GetRange().GetEnd();
3079 bool wxRichTextCtrl::IsEditable() const
3084 // ----------------------------------------------------------------------------
3086 // ----------------------------------------------------------------------------
3088 void wxRichTextCtrl::SetSelection(long from
, long to
)
3090 // if from and to are both -1, it means (in wxWidgets) that all text should
3092 if ( (from
== -1) && (to
== -1) )
3095 to
= GetLastPosition()+1;
3104 wxRichTextSelection oldSelection
= m_selection
;
3106 m_selectionAnchor
= from
-1;
3107 m_selectionAnchorObject
= NULL
;
3108 m_selection
.Set(wxRichTextRange(from
, to
-1), GetFocusObject());
3110 m_caretPosition
= wxMax(-1, to
-1);
3112 RefreshForSelectionChange(oldSelection
, m_selection
);
3117 // ----------------------------------------------------------------------------
3119 // ----------------------------------------------------------------------------
3121 void wxRichTextCtrl::Replace(long from
, long to
,
3122 const wxString
& value
)
3124 BeginBatchUndo(_("Replace"));
3126 SetSelection(from
, to
);
3128 wxRichTextAttr attr
= GetDefaultStyle();
3130 DeleteSelectedContent();
3132 SetDefaultStyle(attr
);
3134 DoWriteText(value
, SetValue_SelectionOnly
);
3139 void wxRichTextCtrl::Remove(long from
, long to
)
3143 GetFocusObject()->DeleteRangeWithUndo(wxRichTextRange(from
, to
-1), this, & GetBuffer());
3150 bool wxRichTextCtrl::IsModified() const
3152 return m_buffer
.IsModified();
3155 void wxRichTextCtrl::MarkDirty()
3157 m_buffer
.Modify(true);
3160 void wxRichTextCtrl::DiscardEdits()
3162 m_caretPositionForDefaultStyle
= -2;
3163 m_buffer
.Modify(false);
3164 m_buffer
.GetCommandProcessor()->ClearCommands();
3167 int wxRichTextCtrl::GetNumberOfLines() const
3169 return GetFocusObject()->GetParagraphCount();
3172 // ----------------------------------------------------------------------------
3173 // Positions <-> coords
3174 // ----------------------------------------------------------------------------
3176 long wxRichTextCtrl::XYToPosition(long x
, long y
) const
3178 return GetFocusObject()->XYToPosition(x
, y
);
3181 bool wxRichTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
3183 return GetFocusObject()->PositionToXY(pos
, x
, y
);
3186 // ----------------------------------------------------------------------------
3188 // ----------------------------------------------------------------------------
3190 void wxRichTextCtrl::ShowPosition(long pos
)
3192 if (!IsPositionVisible(pos
))
3193 ScrollIntoView(pos
-1, WXK_DOWN
);
3196 int wxRichTextCtrl::GetLineLength(long lineNo
) const
3198 return GetFocusObject()->GetParagraphLength(lineNo
);
3201 wxString
wxRichTextCtrl::GetLineText(long lineNo
) const
3203 return GetFocusObject()->GetParagraphText(lineNo
);
3206 // ----------------------------------------------------------------------------
3208 // ----------------------------------------------------------------------------
3210 void wxRichTextCtrl::Undo()
3214 GetCommandProcessor()->Undo();
3218 void wxRichTextCtrl::Redo()
3222 GetCommandProcessor()->Redo();
3226 bool wxRichTextCtrl::CanUndo() const
3228 return GetCommandProcessor()->CanUndo() && IsEditable();
3231 bool wxRichTextCtrl::CanRedo() const
3233 return GetCommandProcessor()->CanRedo() && IsEditable();
3236 // ----------------------------------------------------------------------------
3237 // implementation details
3238 // ----------------------------------------------------------------------------
3240 void wxRichTextCtrl::Command(wxCommandEvent
& event
)
3242 SetValue(event
.GetString());
3243 GetEventHandler()->ProcessEvent(event
);
3246 void wxRichTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
3248 // By default, load the first file into the text window.
3249 if (event
.GetNumberOfFiles() > 0)
3251 LoadFile(event
.GetFiles()[0]);
3255 wxSize
wxRichTextCtrl::DoGetBestSize() const
3257 return wxSize(10, 10);
3260 // ----------------------------------------------------------------------------
3261 // standard handlers for standard edit menu events
3262 // ----------------------------------------------------------------------------
3264 void wxRichTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
3269 void wxRichTextCtrl::OnClear(wxCommandEvent
& WXUNUSED(event
))
3274 void wxRichTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
3279 void wxRichTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
3284 void wxRichTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
3289 void wxRichTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
3294 void wxRichTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
3296 event
.Enable( CanCut() );
3299 void wxRichTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
3301 event
.Enable( CanCopy() );
3304 void wxRichTextCtrl::OnUpdateClear(wxUpdateUIEvent
& event
)
3306 event
.Enable( CanDeleteSelection() );
3309 void wxRichTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
3311 event
.Enable( CanPaste() );
3314 void wxRichTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
3316 event
.Enable( CanUndo() );
3317 event
.SetText( GetCommandProcessor()->GetUndoMenuLabel() );
3320 void wxRichTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
3322 event
.Enable( CanRedo() );
3323 event
.SetText( GetCommandProcessor()->GetRedoMenuLabel() );
3326 void wxRichTextCtrl::OnSelectAll(wxCommandEvent
& WXUNUSED(event
))
3328 if (GetLastPosition() > 0)
3332 void wxRichTextCtrl::OnUpdateSelectAll(wxUpdateUIEvent
& event
)
3334 event
.Enable(GetLastPosition() > 0);
3337 void wxRichTextCtrl::OnProperties(wxCommandEvent
& event
)
3339 int idx
= event
.GetId() - wxID_RICHTEXT_PROPERTIES1
;
3340 if (idx
>= 0 && idx
< m_contextMenuPropertiesInfo
.GetCount())
3342 wxRichTextObject
* obj
= m_contextMenuPropertiesInfo
.GetObject(idx
);
3343 if (obj
&& CanEditProperties(obj
))
3344 EditProperties(obj
, this);
3346 m_contextMenuPropertiesInfo
.Clear();
3350 void wxRichTextCtrl::OnUpdateProperties(wxUpdateUIEvent
& event
)
3352 int idx
= event
.GetId() - wxID_RICHTEXT_PROPERTIES1
;
3353 event
.Enable(idx
>= 0 && idx
< m_contextMenuPropertiesInfo
.GetCount());
3356 void wxRichTextCtrl::OnContextMenu(wxContextMenuEvent
& event
)
3358 if (event
.GetEventObject() != this)
3364 ShowContextMenu(m_contextMenu
, event
.GetPosition());
3367 // Prepares the context menu, adding appropriate property-editing commands.
3368 // Returns the number of property commands added.
3369 int wxRichTextCtrl::PrepareContextMenu(wxMenu
* menu
, const wxPoint
& pt
, bool addPropertyCommands
)
3371 wxClientDC
dc(this);
3373 dc
.SetFont(GetFont());
3375 m_contextMenuPropertiesInfo
.Clear();
3378 wxRichTextObject
* hitObj
= NULL
;
3379 wxRichTextObject
* contextObj
= NULL
;
3380 if (pt
!= wxDefaultPosition
)
3382 wxPoint logicalPt
= GetLogicalPoint(ScreenToClient(pt
));
3383 int hit
= GetBuffer().HitTest(dc
, logicalPt
, position
, & hitObj
, & contextObj
);
3385 if (hit
== wxRICHTEXT_HITTEST_ON
|| hit
== wxRICHTEXT_HITTEST_BEFORE
|| hit
== wxRICHTEXT_HITTEST_AFTER
)
3387 wxRichTextParagraphLayoutBox
* actualContainer
= wxDynamicCast(contextObj
, wxRichTextParagraphLayoutBox
);
3388 if (hitObj
&& actualContainer
)
3390 if (actualContainer
->AcceptsFocus())
3392 SetFocusObject(actualContainer
, false /* don't set caret position yet */);
3393 SetCaretPositionAfterClick(actualContainer
, position
, hit
);
3396 if (addPropertyCommands
)
3397 m_contextMenuPropertiesInfo
.AddItems(this, actualContainer
, hitObj
);
3401 if (addPropertyCommands
)
3402 m_contextMenuPropertiesInfo
.AddItems(this, GetFocusObject(), NULL
);
3407 if (addPropertyCommands
)
3408 m_contextMenuPropertiesInfo
.AddItems(this, GetFocusObject(), NULL
);
3413 // Invoked from the keyboard, so don't set the caret position and don't use the event
3415 hitObj
= GetFocusObject()->GetLeafObjectAtPosition(m_caretPosition
+1);
3417 contextObj
= hitObj
->GetParentContainer();
3419 contextObj
= GetFocusObject();
3421 wxRichTextParagraphLayoutBox
* actualContainer
= wxDynamicCast(contextObj
, wxRichTextParagraphLayoutBox
);
3422 if (hitObj
&& actualContainer
)
3424 if (addPropertyCommands
)
3425 m_contextMenuPropertiesInfo
.AddItems(this, actualContainer
, hitObj
);
3429 if (addPropertyCommands
)
3430 m_contextMenuPropertiesInfo
.AddItems(this, GetFocusObject(), NULL
);
3436 if (addPropertyCommands
)
3437 m_contextMenuPropertiesInfo
.AddMenuItems(menu
);
3438 return m_contextMenuPropertiesInfo
.GetCount();
3444 // Shows the context menu, adding appropriate property-editing commands
3445 bool wxRichTextCtrl::ShowContextMenu(wxMenu
* menu
, const wxPoint
& pt
, bool addPropertyCommands
)
3449 PrepareContextMenu(menu
, pt
, addPropertyCommands
);
3457 bool wxRichTextCtrl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
3459 return GetFocusObject()->SetStyle(wxRichTextRange(start
, end
-1), wxRichTextAttr(style
));
3462 bool wxRichTextCtrl::SetStyle(long start
, long end
, const wxRichTextAttr
& style
)
3464 return GetFocusObject()->SetStyle(wxRichTextRange(start
, end
-1), style
);
3467 bool wxRichTextCtrl::SetStyle(const wxRichTextRange
& range
, const wxTextAttr
& style
)
3469 return GetFocusObject()->SetStyle(range
.ToInternal(), wxRichTextAttr(style
));
3472 bool wxRichTextCtrl::SetStyle(const wxRichTextRange
& range
, const wxRichTextAttr
& style
)
3474 return GetFocusObject()->SetStyle(range
.ToInternal(), style
);
3477 void wxRichTextCtrl::SetStyle(wxRichTextObject
*obj
, const wxRichTextAttr
& textAttr
)
3479 GetFocusObject()->SetStyle(obj
, textAttr
);
3482 // extended style setting operation with flags including:
3483 // wxRICHTEXT_SETSTYLE_WITH_UNDO, wxRICHTEXT_SETSTYLE_OPTIMIZE, wxRICHTEXT_SETSTYLE_PARAGRAPHS_ONLY.
3484 // see richtextbuffer.h for more details.
3486 bool wxRichTextCtrl::SetStyleEx(const wxRichTextRange
& range
, const wxRichTextAttr
& style
, int flags
)
3488 return GetFocusObject()->SetStyle(range
.ToInternal(), style
, flags
);
3491 bool wxRichTextCtrl::SetDefaultStyle(const wxTextAttr
& style
)
3493 return GetBuffer().SetDefaultStyle(style
);
3496 bool wxRichTextCtrl::SetDefaultStyle(const wxRichTextAttr
& style
)
3498 wxRichTextAttr
attr1(style
);
3499 attr1
.GetTextBoxAttr().Reset();
3500 return GetBuffer().SetDefaultStyle(attr1
);
3503 const wxRichTextAttr
& wxRichTextCtrl::GetDefaultStyleEx() const
3505 return GetBuffer().GetDefaultStyle();
3508 bool wxRichTextCtrl::GetStyle(long position
, wxTextAttr
& style
)
3510 wxRichTextAttr attr
;
3511 if (GetFocusObject()->GetStyle(position
, attr
))
3520 bool wxRichTextCtrl::GetStyle(long position
, wxRichTextAttr
& style
)
3522 return GetFocusObject()->GetStyle(position
, style
);
3525 bool wxRichTextCtrl::GetStyle(long position
, wxRichTextAttr
& style
, wxRichTextParagraphLayoutBox
* container
)
3527 wxRichTextAttr attr
;
3528 if (container
->GetStyle(position
, attr
))
3537 // get the common set of styles for the range
3538 bool wxRichTextCtrl::GetStyleForRange(const wxRichTextRange
& range
, wxTextAttr
& style
)
3540 wxRichTextAttr attr
;
3541 if (GetFocusObject()->GetStyleForRange(range
.ToInternal(), attr
))
3550 bool wxRichTextCtrl::GetStyleForRange(const wxRichTextRange
& range
, wxRichTextAttr
& style
)
3552 return GetFocusObject()->GetStyleForRange(range
.ToInternal(), style
);
3555 bool wxRichTextCtrl::GetStyleForRange(const wxRichTextRange
& range
, wxRichTextAttr
& style
, wxRichTextParagraphLayoutBox
* container
)
3557 return container
->GetStyleForRange(range
.ToInternal(), style
);
3560 /// Get the content (uncombined) attributes for this position.
3561 bool wxRichTextCtrl::GetUncombinedStyle(long position
, wxRichTextAttr
& style
)
3563 return GetFocusObject()->GetUncombinedStyle(position
, style
);
3566 /// Get the content (uncombined) attributes for this position.
3567 bool wxRichTextCtrl::GetUncombinedStyle(long position
, wxRichTextAttr
& style
, wxRichTextParagraphLayoutBox
* container
)
3569 return container
->GetUncombinedStyle(position
, style
);
3572 /// Set font, and also the buffer attributes
3573 bool wxRichTextCtrl::SetFont(const wxFont
& font
)
3575 wxControl::SetFont(font
);
3577 wxRichTextAttr attr
= GetBuffer().GetAttributes();
3579 GetBuffer().SetBasicStyle(attr
);
3581 GetBuffer().Invalidate(wxRICHTEXT_ALL
);
3587 /// Transform logical to physical
3588 wxPoint
wxRichTextCtrl::GetPhysicalPoint(const wxPoint
& ptLogical
) const
3591 CalcScrolledPosition(ptLogical
.x
, ptLogical
.y
, & pt
.x
, & pt
.y
);
3596 /// Transform physical to logical
3597 wxPoint
wxRichTextCtrl::GetLogicalPoint(const wxPoint
& ptPhysical
) const
3600 CalcUnscrolledPosition(ptPhysical
.x
, ptPhysical
.y
, & pt
.x
, & pt
.y
);
3605 /// Position the caret
3606 void wxRichTextCtrl::PositionCaret(wxRichTextParagraphLayoutBox
* container
)
3611 //wxLogDebug(wxT("PositionCaret"));
3614 if (GetCaretPositionForIndex(GetCaretPosition(), caretRect
, container
))
3616 wxPoint newPt
= caretRect
.GetPosition();
3617 wxSize newSz
= caretRect
.GetSize();
3618 wxPoint pt
= GetPhysicalPoint(newPt
);
3619 if (GetCaret()->GetPosition() != pt
|| GetCaret()->GetSize() != newSz
)
3622 if (GetCaret()->GetSize() != newSz
)
3623 GetCaret()->SetSize(newSz
);
3625 // Adjust size so the caret size and position doesn't appear in the margins
3626 if (((pt
.y
+ newSz
.y
) <= GetBuffer().GetTopMargin()) || (pt
.y
>= (GetClientSize().y
- GetBuffer().GetBottomMargin())))
3631 else if (pt
.y
< GetBuffer().GetTopMargin() && (pt
.y
+ newSz
.y
) > GetBuffer().GetTopMargin())
3633 newSz
.y
-= (GetBuffer().GetTopMargin() - pt
.y
);
3636 pt
.y
= GetBuffer().GetTopMargin();
3637 GetCaret()->SetSize(newSz
);
3640 else if (pt
.y
< (GetClientSize().y
- GetBuffer().GetBottomMargin()) && (pt
.y
+ newSz
.y
) > (GetClientSize().y
- GetBuffer().GetBottomMargin()))
3642 newSz
.y
= GetClientSize().y
- GetBuffer().GetBottomMargin() - pt
.y
;
3643 GetCaret()->SetSize(newSz
);
3646 GetCaret()->Move(pt
);
3652 /// Get the caret height and position for the given character position
3653 bool wxRichTextCtrl::GetCaretPositionForIndex(long position
, wxRect
& rect
, wxRichTextParagraphLayoutBox
* container
)
3655 wxClientDC
dc(this);
3656 dc
.SetFont(GetFont());
3664 container
= GetFocusObject();
3666 if (container
->FindPosition(dc
, position
, pt
, & height
, m_caretAtLineStart
))
3668 // Caret height can't be zero
3670 height
= dc
.GetCharHeight();
3672 rect
= wxRect(pt
, wxSize(wxRICHTEXT_DEFAULT_CARET_WIDTH
, height
));
3679 /// Gets the line for the visible caret position. If the caret is
3680 /// shown at the very end of the line, it means the next character is actually
3681 /// on the following line. So let's get the line we're expecting to find
3682 /// if this is the case.
3683 wxRichTextLine
* wxRichTextCtrl::GetVisibleLineForCaretPosition(long caretPosition
) const
3685 wxRichTextLine
* line
= GetFocusObject()->GetLineAtPosition(caretPosition
, true);
3686 wxRichTextParagraph
* para
= GetFocusObject()->GetParagraphAtPosition(caretPosition
, true);
3689 wxRichTextRange lineRange
= line
->GetAbsoluteRange();
3690 if (caretPosition
== lineRange
.GetStart()-1 &&
3691 (para
->GetRange().GetStart() != lineRange
.GetStart()))
3693 if (!m_caretAtLineStart
)
3694 line
= GetFocusObject()->GetLineAtPosition(caretPosition
-1, true);
3701 /// Move the caret to the given character position
3702 bool wxRichTextCtrl::MoveCaret(long pos
, bool showAtLineStart
, wxRichTextParagraphLayoutBox
* container
)
3704 if (GetBuffer().IsDirty())
3708 container
= GetFocusObject();
3710 if (pos
<= container
->GetOwnRange().GetEnd())
3712 SetCaretPosition(pos
, showAtLineStart
);
3714 PositionCaret(container
);
3722 /// Layout the buffer: which we must do before certain operations, such as
3723 /// setting the caret position.
3724 bool wxRichTextCtrl::LayoutContent(bool onlyVisibleRect
)
3726 if (GetBuffer().IsDirty() || onlyVisibleRect
)
3728 wxRect
availableSpace(GetClientSize());
3729 if (availableSpace
.width
== 0)
3730 availableSpace
.width
= 10;
3731 if (availableSpace
.height
== 0)
3732 availableSpace
.height
= 10;
3734 int flags
= wxRICHTEXT_FIXED_WIDTH
|wxRICHTEXT_VARIABLE_HEIGHT
;
3735 if (onlyVisibleRect
)
3737 flags
|= wxRICHTEXT_LAYOUT_SPECIFIED_RECT
;
3738 availableSpace
.SetPosition(GetLogicalPoint(wxPoint(0, 0)));
3741 wxClientDC
dc(this);
3742 dc
.SetFont(GetFont());
3746 GetBuffer().Defragment();
3747 GetBuffer().UpdateRanges(); // If items were deleted, ranges need recalculation
3748 GetBuffer().Layout(dc
, availableSpace
, availableSpace
, flags
);
3749 GetBuffer().Invalidate(wxRICHTEXT_NONE
);
3758 /// Is all of the selection, or the current caret position, bold?
3759 bool wxRichTextCtrl::IsSelectionBold()
3763 wxRichTextAttr attr
;
3764 wxRichTextRange range
= GetSelectionRange();
3765 attr
.SetFlags(wxTEXT_ATTR_FONT_WEIGHT
);
3766 attr
.SetFontWeight(wxFONTWEIGHT_BOLD
);
3768 return HasCharacterAttributes(range
, attr
);
3772 // If no selection, then we need to combine current style with default style
3773 // to see what the effect would be if we started typing.
3774 wxRichTextAttr attr
;
3775 attr
.SetFlags(wxTEXT_ATTR_FONT_WEIGHT
);
3777 long pos
= GetAdjustedCaretPosition(GetCaretPosition());
3778 if (GetStyle(pos
, attr
))
3780 if (IsDefaultStyleShowing())
3781 wxRichTextApplyStyle(attr
, GetDefaultStyleEx());
3782 return attr
.GetFontWeight() == wxFONTWEIGHT_BOLD
;
3788 /// Is all of the selection, or the current caret position, italics?
3789 bool wxRichTextCtrl::IsSelectionItalics()
3793 wxRichTextRange range
= GetSelectionRange();
3794 wxRichTextAttr attr
;
3795 attr
.SetFlags(wxTEXT_ATTR_FONT_ITALIC
);
3796 attr
.SetFontStyle(wxFONTSTYLE_ITALIC
);
3798 return HasCharacterAttributes(range
, attr
);
3802 // If no selection, then we need to combine current style with default style
3803 // to see what the effect would be if we started typing.
3804 wxRichTextAttr attr
;
3805 attr
.SetFlags(wxTEXT_ATTR_FONT_ITALIC
);
3807 long pos
= GetAdjustedCaretPosition(GetCaretPosition());
3808 if (GetStyle(pos
, attr
))
3810 if (IsDefaultStyleShowing())
3811 wxRichTextApplyStyle(attr
, GetDefaultStyleEx());
3812 return attr
.GetFontStyle() == wxFONTSTYLE_ITALIC
;
3818 /// Is all of the selection, or the current caret position, underlined?
3819 bool wxRichTextCtrl::IsSelectionUnderlined()
3823 wxRichTextRange range
= GetSelectionRange();
3824 wxRichTextAttr attr
;
3825 attr
.SetFlags(wxTEXT_ATTR_FONT_UNDERLINE
);
3826 attr
.SetFontUnderlined(true);
3828 return HasCharacterAttributes(range
, attr
);
3832 // If no selection, then we need to combine current style with default style
3833 // to see what the effect would be if we started typing.
3834 wxRichTextAttr attr
;
3835 attr
.SetFlags(wxTEXT_ATTR_FONT_UNDERLINE
);
3836 long pos
= GetAdjustedCaretPosition(GetCaretPosition());
3838 if (GetStyle(pos
, attr
))
3840 if (IsDefaultStyleShowing())
3841 wxRichTextApplyStyle(attr
, GetDefaultStyleEx());
3842 return attr
.GetFontUnderlined();
3848 /// Does all of the selection, or the current caret position, have this wxTextAttrEffects flag(s)?
3849 bool wxRichTextCtrl::DoesSelectionHaveTextEffectFlag(int flag
)
3851 wxRichTextAttr attr
;
3852 attr
.SetFlags(wxTEXT_ATTR_EFFECTS
);
3853 attr
.SetTextEffectFlags(flag
);
3854 attr
.SetTextEffects(flag
);
3858 return HasCharacterAttributes(GetSelectionRange(), attr
);
3862 // If no selection, then we need to combine current style with default style
3863 // to see what the effect would be if we started typing.
3864 long pos
= GetAdjustedCaretPosition(GetCaretPosition());
3865 if (GetStyle(pos
, attr
))
3867 if (IsDefaultStyleShowing())
3868 wxRichTextApplyStyle(attr
, GetDefaultStyleEx());
3869 return (attr
.GetTextEffectFlags() & flag
) != 0;
3875 /// Apply bold to the selection
3876 bool wxRichTextCtrl::ApplyBoldToSelection()
3878 wxRichTextAttr attr
;
3879 attr
.SetFlags(wxTEXT_ATTR_FONT_WEIGHT
);
3880 attr
.SetFontWeight(IsSelectionBold() ? wxFONTWEIGHT_NORMAL
: wxFONTWEIGHT_BOLD
);
3883 return SetStyleEx(GetSelectionRange(), attr
, wxRICHTEXT_SETSTYLE_WITH_UNDO
|wxRICHTEXT_SETSTYLE_OPTIMIZE
|wxRICHTEXT_SETSTYLE_CHARACTERS_ONLY
);
3886 wxRichTextAttr current
= GetDefaultStyleEx();
3887 current
.Apply(attr
);
3888 SetAndShowDefaultStyle(current
);
3893 /// Apply italic to the selection
3894 bool wxRichTextCtrl::ApplyItalicToSelection()
3896 wxRichTextAttr attr
;
3897 attr
.SetFlags(wxTEXT_ATTR_FONT_ITALIC
);
3898 attr
.SetFontStyle(IsSelectionItalics() ? wxFONTSTYLE_NORMAL
: wxFONTSTYLE_ITALIC
);
3901 return SetStyleEx(GetSelectionRange(), attr
, wxRICHTEXT_SETSTYLE_WITH_UNDO
|wxRICHTEXT_SETSTYLE_OPTIMIZE
|wxRICHTEXT_SETSTYLE_CHARACTERS_ONLY
);
3904 wxRichTextAttr current
= GetDefaultStyleEx();
3905 current
.Apply(attr
);
3906 SetAndShowDefaultStyle(current
);
3911 /// Apply underline to the selection
3912 bool wxRichTextCtrl::ApplyUnderlineToSelection()
3914 wxRichTextAttr attr
;
3915 attr
.SetFlags(wxTEXT_ATTR_FONT_UNDERLINE
);
3916 attr
.SetFontUnderlined(!IsSelectionUnderlined());
3919 return SetStyleEx(GetSelectionRange(), attr
, wxRICHTEXT_SETSTYLE_WITH_UNDO
|wxRICHTEXT_SETSTYLE_OPTIMIZE
|wxRICHTEXT_SETSTYLE_CHARACTERS_ONLY
);
3922 wxRichTextAttr current
= GetDefaultStyleEx();
3923 current
.Apply(attr
);
3924 SetAndShowDefaultStyle(current
);
3929 /// Apply the wxTextAttrEffects flag(s) to the selection, or the current caret position if there's no selection
3930 bool wxRichTextCtrl::ApplyTextEffectToSelection(int flags
)
3932 wxRichTextAttr attr
;
3933 attr
.SetFlags(wxTEXT_ATTR_EFFECTS
);
3934 attr
.SetTextEffectFlags(flags
);
3935 if (!DoesSelectionHaveTextEffectFlag(flags
))
3936 attr
.SetTextEffects(flags
);
3938 attr
.SetTextEffects(attr
.GetTextEffectFlags() & ~flags
);
3941 return SetStyleEx(GetSelectionRange(), attr
, wxRICHTEXT_SETSTYLE_WITH_UNDO
|wxRICHTEXT_SETSTYLE_OPTIMIZE
|wxRICHTEXT_SETSTYLE_CHARACTERS_ONLY
);
3944 wxRichTextAttr current
= GetDefaultStyleEx();
3945 current
.Apply(attr
);
3946 SetAndShowDefaultStyle(current
);
3951 /// Is all of the selection aligned according to the specified flag?
3952 bool wxRichTextCtrl::IsSelectionAligned(wxTextAttrAlignment alignment
)
3954 wxRichTextRange range
;
3956 range
= GetSelectionRange();
3958 range
= wxRichTextRange(GetCaretPosition()+1, GetCaretPosition()+2);
3960 wxRichTextAttr attr
;
3961 attr
.SetAlignment(alignment
);
3963 return HasParagraphAttributes(range
, attr
);
3966 /// Apply alignment to the selection
3967 bool wxRichTextCtrl::ApplyAlignmentToSelection(wxTextAttrAlignment alignment
)
3969 wxRichTextAttr attr
;
3970 attr
.SetAlignment(alignment
);
3972 return SetStyle(GetSelectionRange(), attr
);
3975 wxRichTextParagraph
* para
= GetFocusObject()->GetParagraphAtPosition(GetCaretPosition()+1);
3977 return SetStyleEx(para
->GetRange().FromInternal(), attr
, wxRICHTEXT_SETSTYLE_WITH_UNDO
|wxRICHTEXT_SETSTYLE_OPTIMIZE
|wxRICHTEXT_SETSTYLE_PARAGRAPHS_ONLY
);
3982 /// Apply a named style to the selection
3983 bool wxRichTextCtrl::ApplyStyle(wxRichTextStyleDefinition
* def
)
3985 // Flags are defined within each definition, so only certain
3986 // attributes are applied.
3987 wxRichTextAttr
attr(GetStyleSheet() ? def
->GetStyleMergedWithBase(GetStyleSheet()) : def
->GetStyle());
3989 int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
|wxRICHTEXT_SETSTYLE_OPTIMIZE
|wxRICHTEXT_SETSTYLE_RESET
;
3991 if (def
->IsKindOf(CLASSINFO(wxRichTextListStyleDefinition
)))
3993 flags
|= wxRICHTEXT_SETSTYLE_PARAGRAPHS_ONLY
;
3995 wxRichTextRange range
;
3998 range
= GetSelectionRange();
4001 long pos
= GetAdjustedCaretPosition(GetCaretPosition());
4002 range
= wxRichTextRange(pos
, pos
+1);
4005 return SetListStyle(range
, (wxRichTextListStyleDefinition
*) def
, flags
);
4008 bool isPara
= false;
4010 // Make sure the attr has the style name
4011 if (def
->IsKindOf(CLASSINFO(wxRichTextParagraphStyleDefinition
)))
4014 attr
.SetParagraphStyleName(def
->GetName());
4016 // If applying a paragraph style, we only want the paragraph nodes to adopt these
4017 // attributes, and not the leaf nodes. This will allow the content (e.g. text)
4018 // to change its style independently.
4019 flags
|= wxRICHTEXT_SETSTYLE_PARAGRAPHS_ONLY
;
4021 else if (def
->IsKindOf(CLASSINFO(wxRichTextCharacterStyleDefinition
)))
4022 attr
.SetCharacterStyleName(def
->GetName());
4023 else if (def
->IsKindOf(CLASSINFO(wxRichTextBoxStyleDefinition
)))
4024 attr
.GetTextBoxAttr().SetBoxStyleName(def
->GetName());
4026 if (def
->IsKindOf(CLASSINFO(wxRichTextBoxStyleDefinition
)))
4028 if (GetFocusObject() && (GetFocusObject() != & GetBuffer()))
4030 SetStyle(GetFocusObject(), attr
);
4036 else if (HasSelection())
4037 return SetStyleEx(GetSelectionRange(), attr
, flags
);
4040 wxRichTextAttr current
= GetDefaultStyleEx();
4041 wxRichTextAttr
defaultStyle(attr
);
4044 // Don't apply extra character styles since they are already implied
4045 // in the paragraph style
4046 defaultStyle
.SetFlags(defaultStyle
.GetFlags() & ~wxTEXT_ATTR_CHARACTER
);
4048 current
.Apply(defaultStyle
);
4049 SetAndShowDefaultStyle(current
);
4051 // If it's a paragraph style, we want to apply the style to the
4052 // current paragraph even if we didn't select any text.
4055 long pos
= GetAdjustedCaretPosition(GetCaretPosition());
4056 wxRichTextParagraph
* para
= GetFocusObject()->GetParagraphAtPosition(pos
);
4059 return SetStyleEx(para
->GetRange().FromInternal(), attr
, flags
);
4066 /// Apply the style sheet to the buffer, for example if the styles have changed.
4067 bool wxRichTextCtrl::ApplyStyleSheet(wxRichTextStyleSheet
* styleSheet
)
4070 styleSheet
= GetBuffer().GetStyleSheet();
4074 if (GetBuffer().ApplyStyleSheet(styleSheet
))
4076 GetBuffer().Invalidate(wxRICHTEXT_ALL
);
4084 /// Sets the default style to the style under the cursor
4085 bool wxRichTextCtrl::SetDefaultStyleToCursorStyle()
4087 wxRichTextAttr attr
;
4088 attr
.SetFlags(wxTEXT_ATTR_CHARACTER
);
4090 // If at the start of a paragraph, use the next position.
4091 long pos
= GetAdjustedCaretPosition(GetCaretPosition());
4093 wxRichTextObject
* obj
= GetFocusObject()->GetLeafObjectAtPosition(pos
);
4094 if (obj
&& obj
->IsTopLevel())
4096 // Don't use the attributes of a top-level object, since they might apply
4097 // to content of the object, e.g. background colour.
4098 SetDefaultStyle(wxRichTextAttr());
4101 else if (GetUncombinedStyle(pos
, attr
))
4103 SetDefaultStyle(attr
);
4110 /// Returns the first visible position in the current view
4111 long wxRichTextCtrl::GetFirstVisiblePosition() const
4113 wxRichTextLine
* line
= GetFocusObject()->GetLineAtYPosition(GetLogicalPoint(wxPoint(0, 0)).y
);
4115 return line
->GetAbsoluteRange().GetStart();
4120 /// Get the first visible point in the window
4121 wxPoint
wxRichTextCtrl::GetFirstVisiblePoint() const
4124 int startXUnits
, startYUnits
;
4126 GetScrollPixelsPerUnit(& ppuX
, & ppuY
);
4127 GetViewStart(& startXUnits
, & startYUnits
);
4129 return wxPoint(startXUnits
* ppuX
, startYUnits
* ppuY
);
4132 /// The adjusted caret position is the character position adjusted to take
4133 /// into account whether we're at the start of a paragraph, in which case
4134 /// style information should be taken from the next position, not current one.
4135 long wxRichTextCtrl::GetAdjustedCaretPosition(long caretPos
) const
4137 wxRichTextParagraph
* para
= GetFocusObject()->GetParagraphAtPosition(caretPos
+1);
4139 if (para
&& (caretPos
+1 == para
->GetRange().GetStart()))
4144 /// Get/set the selection range in character positions. -1, -1 means no selection.
4145 /// The range is in API convention, i.e. a single character selection is denoted
4147 wxRichTextRange
wxRichTextCtrl::GetSelectionRange() const
4149 wxRichTextRange range
= GetInternalSelectionRange();
4150 if (range
!= wxRichTextRange(-2,-2) && range
!= wxRichTextRange(-1,-1))
4151 range
.SetEnd(range
.GetEnd() + 1);
4155 void wxRichTextCtrl::SetSelectionRange(const wxRichTextRange
& range
)
4157 SetSelection(range
.GetStart(), range
.GetEnd());
4161 bool wxRichTextCtrl::SetListStyle(const wxRichTextRange
& range
, wxRichTextListStyleDefinition
* def
, int flags
, int startFrom
, int specifiedLevel
)
4163 return GetFocusObject()->SetListStyle(range
.ToInternal(), def
, flags
, startFrom
, specifiedLevel
);
4166 bool wxRichTextCtrl::SetListStyle(const wxRichTextRange
& range
, const wxString
& defName
, int flags
, int startFrom
, int specifiedLevel
)
4168 return GetFocusObject()->SetListStyle(range
.ToInternal(), defName
, flags
, startFrom
, specifiedLevel
);
4171 /// Clear list for given range
4172 bool wxRichTextCtrl::ClearListStyle(const wxRichTextRange
& range
, int flags
)
4174 return GetFocusObject()->ClearListStyle(range
.ToInternal(), flags
);
4177 /// Number/renumber any list elements in the given range
4178 bool wxRichTextCtrl::NumberList(const wxRichTextRange
& range
, wxRichTextListStyleDefinition
* def
, int flags
, int startFrom
, int specifiedLevel
)
4180 return GetFocusObject()->NumberList(range
.ToInternal(), def
, flags
, startFrom
, specifiedLevel
);
4183 bool wxRichTextCtrl::NumberList(const wxRichTextRange
& range
, const wxString
& defName
, int flags
, int startFrom
, int specifiedLevel
)
4185 return GetFocusObject()->NumberList(range
.ToInternal(), defName
, flags
, startFrom
, specifiedLevel
);
4188 /// Promote the list items within the given range. promoteBy can be a positive or negative number, e.g. 1 or -1
4189 bool wxRichTextCtrl::PromoteList(int promoteBy
, const wxRichTextRange
& range
, wxRichTextListStyleDefinition
* def
, int flags
, int specifiedLevel
)
4191 return GetFocusObject()->PromoteList(promoteBy
, range
.ToInternal(), def
, flags
, specifiedLevel
);
4194 bool wxRichTextCtrl::PromoteList(int promoteBy
, const wxRichTextRange
& range
, const wxString
& defName
, int flags
, int specifiedLevel
)
4196 return GetFocusObject()->PromoteList(promoteBy
, range
.ToInternal(), defName
, flags
, specifiedLevel
);
4199 /// Deletes the content in the given range
4200 bool wxRichTextCtrl::Delete(const wxRichTextRange
& range
)
4202 return GetFocusObject()->DeleteRangeWithUndo(range
.ToInternal(), this, & GetBuffer());
4205 const wxArrayString
& wxRichTextCtrl::GetAvailableFontNames()
4207 if (sm_availableFontNames
.GetCount() == 0)
4209 sm_availableFontNames
= wxFontEnumerator::GetFacenames();
4210 sm_availableFontNames
.Sort();
4212 return sm_availableFontNames
;
4215 void wxRichTextCtrl::ClearAvailableFontNames()
4217 sm_availableFontNames
.Clear();
4220 void wxRichTextCtrl::OnSysColourChanged(wxSysColourChangedEvent
& WXUNUSED(event
))
4222 //wxLogDebug(wxT("wxRichTextCtrl::OnSysColourChanged"));
4224 wxTextAttrEx basicStyle
= GetBasicStyle();
4225 basicStyle
.SetTextColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
));
4226 SetBasicStyle(basicStyle
);
4227 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
4232 // Refresh the area affected by a selection change
4233 bool wxRichTextCtrl::RefreshForSelectionChange(const wxRichTextSelection
& oldSelection
, const wxRichTextSelection
& newSelection
)
4235 // If the selection is not part of the focus object, or we have multiple ranges, then the chances are that
4236 // the selection contains whole containers rather than just text, so refresh everything
4237 // for now as it would be hard to compute the rectangle bounding all selections.
4238 // TODO: improve on this.
4239 if ((oldSelection
.IsValid() && (oldSelection
.GetContainer() != GetFocusObject() || oldSelection
.GetCount() > 1)) ||
4240 (newSelection
.IsValid() && (newSelection
.GetContainer() != GetFocusObject() || newSelection
.GetCount() > 1)))
4246 wxRichTextRange oldRange
, newRange
;
4247 if (oldSelection
.IsValid())
4248 oldRange
= oldSelection
.GetRange();
4250 oldRange
= wxRICHTEXT_NO_SELECTION
;
4251 if (newSelection
.IsValid())
4252 newRange
= newSelection
.GetRange();
4254 newRange
= wxRICHTEXT_NO_SELECTION
;
4256 // Calculate the refresh rectangle - just the affected lines
4257 long firstPos
, lastPos
;
4258 if (oldRange
.GetStart() == -2 && newRange
.GetStart() != -2)
4260 firstPos
= newRange
.GetStart();
4261 lastPos
= newRange
.GetEnd();
4263 else if (oldRange
.GetStart() != -2 && newRange
.GetStart() == -2)
4265 firstPos
= oldRange
.GetStart();
4266 lastPos
= oldRange
.GetEnd();
4268 else if (oldRange
.GetStart() == -2 && newRange
.GetStart() == -2)
4274 firstPos
= wxMin(oldRange
.GetStart(), newRange
.GetStart());
4275 lastPos
= wxMax(oldRange
.GetEnd(), newRange
.GetEnd());
4278 wxRichTextLine
* firstLine
= GetFocusObject()->GetLineAtPosition(firstPos
);
4279 wxRichTextLine
* lastLine
= GetFocusObject()->GetLineAtPosition(lastPos
);
4281 if (firstLine
&& lastLine
)
4283 wxSize clientSize
= GetClientSize();
4284 wxPoint pt1
= GetPhysicalPoint(firstLine
->GetAbsolutePosition());
4285 wxPoint pt2
= GetPhysicalPoint(lastLine
->GetAbsolutePosition()) + wxPoint(0, lastLine
->GetSize().y
);
4288 pt1
.y
= wxMax(0, pt1
.y
);
4290 pt2
.y
= wxMin(clientSize
.y
, pt2
.y
);
4292 wxRect
rect(pt1
, wxSize(clientSize
.x
, pt2
.y
- pt1
.y
));
4293 RefreshRect(rect
, false);
4301 // margins functions
4302 bool wxRichTextCtrl::DoSetMargins(const wxPoint
& pt
)
4304 GetBuffer().GetAttributes().GetTextBoxAttr().GetMargins().GetLeft().SetValue(pt
.x
, wxTEXT_ATTR_UNITS_PIXELS
);
4305 GetBuffer().GetAttributes().GetTextBoxAttr().GetMargins().GetRight().SetValue(pt
.x
, wxTEXT_ATTR_UNITS_PIXELS
);
4306 GetBuffer().GetAttributes().GetTextBoxAttr().GetMargins().GetTop().SetValue(pt
.y
, wxTEXT_ATTR_UNITS_PIXELS
);
4307 GetBuffer().GetAttributes().GetTextBoxAttr().GetMargins().GetBottom().SetValue(pt
.y
, wxTEXT_ATTR_UNITS_PIXELS
);
4312 wxPoint
wxRichTextCtrl::DoGetMargins() const
4314 return wxPoint(GetBuffer().GetAttributes().GetTextBoxAttr().GetMargins().GetLeft().GetValue(),
4315 GetBuffer().GetAttributes().GetTextBoxAttr().GetMargins().GetTop().GetValue());
4318 bool wxRichTextCtrl::SetFocusObject(wxRichTextParagraphLayoutBox
* obj
, bool setCaretPosition
)
4320 if (obj
&& !obj
->AcceptsFocus())
4323 wxRichTextParagraphLayoutBox
* oldContainer
= GetFocusObject();
4324 bool changingContainer
= (m_focusObject
!= obj
);
4326 if (changingContainer
&& HasSelection())
4329 m_focusObject
= obj
;
4332 m_focusObject
= & m_buffer
;
4334 if (setCaretPosition
&& changingContainer
)
4336 m_selection
.Reset();
4337 m_selectionAnchor
= -2;
4338 m_selectionAnchorObject
= NULL
;
4339 m_selectionState
= wxRichTextCtrlSelectionState_Normal
;
4343 m_caretAtLineStart
= false;
4344 MoveCaret(pos
, m_caretAtLineStart
);
4345 SetDefaultStyleToCursorStyle();
4347 wxRichTextEvent
cmdEvent(
4348 wxEVT_COMMAND_RICHTEXT_FOCUS_OBJECT_CHANGED
,
4350 cmdEvent
.SetEventObject(this);
4351 cmdEvent
.SetPosition(m_caretPosition
+1);
4352 cmdEvent
.SetOldContainer(oldContainer
);
4353 cmdEvent
.SetContainer(m_focusObject
);
4355 GetEventHandler()->ProcessEvent(cmdEvent
);
4360 #if wxUSE_DRAG_AND_DROP
4361 void wxRichTextCtrl::OnDrop(wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
), wxDragResult def
, wxDataObject
* DataObj
)
4365 if ((def
!= wxDragCopy
) && (def
!= wxDragMove
))
4370 if (!GetSelection().IsValid())
4375 wxRichTextParagraphLayoutBox
* originContainer
= GetSelection().GetContainer();
4376 wxRichTextParagraphLayoutBox
* destContainer
= GetFocusObject(); // This will be the drop container, not necessarily the same as the origin one
4378 wxRichTextBuffer
* richTextBuffer
= ((wxRichTextBufferDataObject
*)DataObj
)->GetRichTextBuffer();
4381 long position
= GetCaretPosition();
4382 wxRichTextRange selectionrange
= GetInternalSelectionRange();
4383 if (selectionrange
.Contains(position
) && (def
== wxDragMove
))
4385 // It doesn't make sense to move onto itself
4389 // If we're moving, and the data is being moved forward, we need to drop first, then delete the selection
4390 // If moving backwards, we need to delete then drop. If we're copying (or doing nothing) we don't delete anyway
4391 bool DeleteAfter
= (def
== wxDragMove
) && (position
> selectionrange
.GetEnd());
4392 if ((def
== wxDragMove
) && !DeleteAfter
)
4394 // We can't use e.g. DeleteSelectedContent() as it uses the focus container
4395 originContainer
->DeleteRangeWithUndo(selectionrange
, this, &GetBuffer());
4398 destContainer
->InsertParagraphsWithUndo(&GetBuffer(), position
+1, *richTextBuffer
, this, 0);
4399 ShowPosition(position
+ richTextBuffer
->GetOwnRange().GetEnd());
4401 delete richTextBuffer
;
4405 // We can't use e.g. DeleteSelectedContent() as it uses the focus container
4406 originContainer
->DeleteRangeWithUndo(selectionrange
, this, &GetBuffer());
4413 #endif // wxUSE_DRAG_AND_DROP
4416 #if wxUSE_DRAG_AND_DROP
4417 bool wxRichTextDropSource::GiveFeedback(wxDragResult
WXUNUSED(effect
))
4419 wxCHECK_MSG(m_rtc
, false, wxT("NULL m_rtc"));
4423 wxRichTextObject
* hitObj
= NULL
;
4424 wxRichTextParagraphLayoutBox
* container
= m_rtc
->FindContainerAtPoint(m_rtc
->ScreenToClient(wxGetMousePosition()), position
, hit
, hitObj
);
4426 if (!(hit
& wxRICHTEXT_HITTEST_NONE
) && container
&& container
->AcceptsFocus())
4428 m_rtc
->StoreFocusObject(container
);
4429 m_rtc
->SetCaretPositionAfterClick(container
, position
, hit
);
4432 return false; // so that the base-class sets a cursor
4434 #endif // wxUSE_DRAG_AND_DROP
4437 #if wxRICHTEXT_USE_OWN_CARET
4439 // ----------------------------------------------------------------------------
4440 // initialization and destruction
4441 // ----------------------------------------------------------------------------
4443 void wxRichTextCaret::Init()
4446 m_refreshEnabled
= true;
4450 m_richTextCtrl
= NULL
;
4451 m_needsUpdate
= false;
4455 wxRichTextCaret::~wxRichTextCaret()
4457 if (m_timer
.IsRunning())
4461 // ----------------------------------------------------------------------------
4462 // showing/hiding/moving the caret (base class interface)
4463 // ----------------------------------------------------------------------------
4465 void wxRichTextCaret::DoShow()
4469 if (!m_timer
.IsRunning())
4470 m_timer
.Start(GetBlinkTime());
4475 void wxRichTextCaret::DoHide()
4477 if (m_timer
.IsRunning())
4483 void wxRichTextCaret::DoMove()
4489 if (m_xOld
!= -1 && m_yOld
!= -1)
4491 if (m_richTextCtrl
&& m_refreshEnabled
)
4493 wxRect
rect(GetPosition(), GetSize());
4494 m_richTextCtrl
->RefreshRect(rect
, false);
4503 void wxRichTextCaret::DoSize()
4505 int countVisible
= m_countVisible
;
4506 if (countVisible
> 0)
4512 if (countVisible
> 0)
4514 m_countVisible
= countVisible
;
4519 // ----------------------------------------------------------------------------
4520 // handling the focus
4521 // ----------------------------------------------------------------------------
4523 void wxRichTextCaret::OnSetFocus()
4531 void wxRichTextCaret::OnKillFocus()
4536 // ----------------------------------------------------------------------------
4537 // drawing the caret
4538 // ----------------------------------------------------------------------------
4540 void wxRichTextCaret::Refresh()
4542 if (m_richTextCtrl
&& m_refreshEnabled
)
4544 wxRect
rect(GetPosition(), GetSize());
4545 m_richTextCtrl
->RefreshRect(rect
, false);
4549 void wxRichTextCaret::DoDraw(wxDC
*dc
)
4551 dc
->SetPen( *wxBLACK_PEN
);
4553 dc
->SetBrush(*(m_hasFocus
? wxBLACK_BRUSH
: wxTRANSPARENT_BRUSH
));
4554 dc
->SetPen(*wxBLACK_PEN
);
4556 wxPoint
pt(m_x
, m_y
);
4560 pt
= m_richTextCtrl
->GetLogicalPoint(pt
);
4562 if (IsVisible() && m_flashOn
)
4563 dc
->DrawRectangle(pt
.x
, pt
.y
, m_width
, m_height
);
4566 void wxRichTextCaret::Notify()
4568 m_flashOn
= !m_flashOn
;
4572 void wxRichTextCaretTimer::Notify()
4577 // wxRICHTEXT_USE_OWN_CARET
4580 bool wxRichTextContextMenuPropertiesInfo::AddItem(const wxString
& label
, wxRichTextObject
* obj
)
4584 m_labels
.Add(label
);
4592 // Returns number of menu items were added.
4593 int wxRichTextContextMenuPropertiesInfo::AddMenuItems(wxMenu
* menu
, int startCmd
) const
4595 wxMenuItem
* item
= menu
->FindItem(startCmd
);
4596 // If none of the standard properties identifiers are in the menu, add them if necessary.
4597 // If no items to add, just set the text to something generic
4598 if (GetCount() == 0)
4602 menu
->SetLabel(startCmd
, _("&Properties"));
4604 // Delete the others if necessary
4606 for (i
= startCmd
+1; i
< startCmd
+3; i
++)
4608 if (menu
->FindItem(i
))
4619 // Find the position of the first properties item
4620 for (i
= 0; i
< (int) menu
->GetMenuItemCount(); i
++)
4622 wxMenuItem
* item
= menu
->FindItemByPosition(i
);
4623 if (item
&& item
->GetId() == startCmd
)
4632 int insertBefore
= pos
+1;
4633 for (i
= startCmd
; i
< startCmd
+GetCount(); i
++)
4635 if (menu
->FindItem(i
))
4637 menu
->SetLabel(i
, m_labels
[i
- startCmd
]);
4641 if (insertBefore
>= (int) menu
->GetMenuItemCount())
4642 menu
->Append(i
, m_labels
[i
- startCmd
]);
4644 menu
->Insert(insertBefore
, i
, m_labels
[i
- startCmd
]);
4649 // Delete any old items still left on the menu
4650 for (i
= startCmd
+ GetCount(); i
< startCmd
+3; i
++)
4652 if (menu
->FindItem(i
))
4660 // No existing property identifiers were found, so append to the end of the menu.
4661 menu
->AppendSeparator();
4662 for (i
= startCmd
; i
< startCmd
+GetCount(); i
++)
4664 menu
->Append(i
, m_labels
[i
- startCmd
]);
4672 // Add appropriate menu items for the current container and clicked on object
4673 // (and container's parent, if appropriate).
4674 int wxRichTextContextMenuPropertiesInfo::AddItems(wxRichTextCtrl
* ctrl
, wxRichTextObject
* container
, wxRichTextObject
* obj
)
4677 if (obj
&& ctrl
->CanEditProperties(obj
))
4678 AddItem(obj
->GetPropertiesMenuLabel(), obj
);
4680 if (container
&& container
!= obj
&& ctrl
->CanEditProperties(container
) && m_labels
.Index(container
->GetPropertiesMenuLabel()) == wxNOT_FOUND
)
4681 AddItem(container
->GetPropertiesMenuLabel(), container
);
4683 if (container
&& container
->GetParent() && ctrl
->CanEditProperties(container
->GetParent()) && m_labels
.Index(container
->GetParent()->GetPropertiesMenuLabel()) == wxNOT_FOUND
)
4684 AddItem(container
->GetParent()->GetPropertiesMenuLabel(), container
->GetParent());