+ ShowContextMenu(m_contextMenu, event.GetPosition());
+}
+
+// Prepares the context menu, adding appropriate property-editing commands.
+// Returns the number of property commands added.
+int wxRichTextCtrl::PrepareContextMenu(wxMenu* menu, const wxPoint& pt, bool addPropertyCommands)
+{
+ wxClientDC dc(this);
+ PrepareDC(dc);
+ dc.SetFont(GetFont());
+
+ m_contextMenuPropertiesInfo.Clear();
+
+ long position = 0;
+ wxRichTextObject* hitObj = NULL;
+ wxRichTextObject* contextObj = NULL;
+ if (pt != wxDefaultPosition)
+ {
+ wxPoint logicalPt = GetLogicalPoint(ScreenToClient(pt));
+ wxRichTextDrawingContext context(& GetBuffer());
+ int hit = GetBuffer().HitTest(dc, context, logicalPt, position, & hitObj, & contextObj);
+
+ if (hit == wxRICHTEXT_HITTEST_ON || hit == wxRICHTEXT_HITTEST_BEFORE || hit == wxRICHTEXT_HITTEST_AFTER)
+ {
+ wxRichTextParagraphLayoutBox* actualContainer = wxDynamicCast(contextObj, wxRichTextParagraphLayoutBox);
+ if (hitObj && actualContainer)
+ {
+ if (actualContainer->AcceptsFocus())
+ {
+ SetFocusObject(actualContainer, false /* don't set caret position yet */);
+ SetCaretPositionAfterClick(actualContainer, position, hit);
+ }
+
+ if (addPropertyCommands)
+ m_contextMenuPropertiesInfo.AddItems(this, actualContainer, hitObj);
+ }
+ else
+ {
+ if (addPropertyCommands)
+ m_contextMenuPropertiesInfo.AddItems(this, GetFocusObject(), NULL);
+ }
+ }
+ else
+ {
+ if (addPropertyCommands)
+ m_contextMenuPropertiesInfo.AddItems(this, GetFocusObject(), NULL);
+ }
+ }
+ else
+ {
+ // Invoked from the keyboard, so don't set the caret position and don't use the event
+ // position
+ hitObj = GetFocusObject()->GetLeafObjectAtPosition(m_caretPosition+1);
+ if (hitObj)
+ contextObj = hitObj->GetParentContainer();
+ else
+ contextObj = GetFocusObject();
+
+ wxRichTextParagraphLayoutBox* actualContainer = wxDynamicCast(contextObj, wxRichTextParagraphLayoutBox);
+ if (hitObj && actualContainer)
+ {
+ if (addPropertyCommands)
+ m_contextMenuPropertiesInfo.AddItems(this, actualContainer, hitObj);
+ }
+ else
+ {
+ if (addPropertyCommands)
+ m_contextMenuPropertiesInfo.AddItems(this, GetFocusObject(), NULL);
+ }
+ }
+
+ if (menu)
+ {
+ if (addPropertyCommands)
+ m_contextMenuPropertiesInfo.AddMenuItems(menu);
+ return m_contextMenuPropertiesInfo.GetCount();
+ }
+ else
+ return 0;
+}
+
+// Shows the context menu, adding appropriate property-editing commands
+bool wxRichTextCtrl::ShowContextMenu(wxMenu* menu, const wxPoint& pt, bool addPropertyCommands)
+{
+ if (menu)
+ {
+ PrepareContextMenu(menu, pt, addPropertyCommands);
+ PopupMenu(menu);
+ return true;
+ }
+ else
+ return false;
+}
+
+bool wxRichTextCtrl::SetStyle(long start, long end, const wxTextAttr& style)
+{
+ return GetFocusObject()->SetStyle(wxRichTextRange(start, end-1), wxRichTextAttr(style));
+}
+
+bool wxRichTextCtrl::SetStyle(long start, long end, const wxRichTextAttr& style)
+{
+ return GetFocusObject()->SetStyle(wxRichTextRange(start, end-1), style);
+}
+
+bool wxRichTextCtrl::SetStyle(const wxRichTextRange& range, const wxTextAttr& style)
+{
+ return GetFocusObject()->SetStyle(range.ToInternal(), wxRichTextAttr(style));
+}
+
+bool wxRichTextCtrl::SetStyle(const wxRichTextRange& range, const wxRichTextAttr& style)
+{
+ return GetFocusObject()->SetStyle(range.ToInternal(), style);
+}
+
+void wxRichTextCtrl::SetStyle(wxRichTextObject *obj, const wxRichTextAttr& textAttr)
+{
+ GetFocusObject()->SetStyle(obj, textAttr);
+}
+
+// extended style setting operation with flags including:
+// wxRICHTEXT_SETSTYLE_WITH_UNDO, wxRICHTEXT_SETSTYLE_OPTIMIZE, wxRICHTEXT_SETSTYLE_PARAGRAPHS_ONLY.
+// see richtextbuffer.h for more details.
+
+bool wxRichTextCtrl::SetStyleEx(const wxRichTextRange& range, const wxRichTextAttr& style, int flags)
+{
+ return GetFocusObject()->SetStyle(range.ToInternal(), style, flags);
+}
+
+bool wxRichTextCtrl::SetDefaultStyle(const wxTextAttr& style)
+{
+ return GetBuffer().SetDefaultStyle(style);
+}
+
+bool wxRichTextCtrl::SetDefaultStyle(const wxRichTextAttr& style)
+{
+ wxRichTextAttr attr1(style);
+ attr1.GetTextBoxAttr().Reset();
+ return GetBuffer().SetDefaultStyle(attr1);
+}
+
+const wxRichTextAttr& wxRichTextCtrl::GetDefaultStyleEx() const
+{
+ return GetBuffer().GetDefaultStyle();
+}
+
+bool wxRichTextCtrl::GetStyle(long position, wxTextAttr& style)
+{
+ wxRichTextAttr attr;
+ if (GetFocusObject()->GetStyle(position, attr))