+// margins functions
+bool wxRichTextCtrl::DoSetMargins(const wxPoint& pt)
+{
+ GetBuffer().GetAttributes().GetTextBoxAttr().GetMargins().GetLeft().SetValue(pt.x, wxTEXT_ATTR_UNITS_PIXELS);
+ GetBuffer().GetAttributes().GetTextBoxAttr().GetMargins().GetRight().SetValue(pt.x, wxTEXT_ATTR_UNITS_PIXELS);
+ GetBuffer().GetAttributes().GetTextBoxAttr().GetMargins().GetTop().SetValue(pt.y, wxTEXT_ATTR_UNITS_PIXELS);
+ GetBuffer().GetAttributes().GetTextBoxAttr().GetMargins().GetBottom().SetValue(pt.y, wxTEXT_ATTR_UNITS_PIXELS);
+
+ return true;
+}
+
+wxPoint wxRichTextCtrl::DoGetMargins() const
+{
+ return wxPoint(GetBuffer().GetAttributes().GetTextBoxAttr().GetMargins().GetLeft().GetValue(),
+ GetBuffer().GetAttributes().GetTextBoxAttr().GetMargins().GetTop().GetValue());
+}
+
+bool wxRichTextCtrl::SetFocusObject(wxRichTextParagraphLayoutBox* obj, bool setCaretPosition)
+{
+ if (obj && !obj->AcceptsFocus())
+ return false;
+
+ wxRichTextParagraphLayoutBox* oldContainer = GetFocusObject();
+ bool changingContainer = (m_focusObject != obj);
+
+ if (changingContainer && HasSelection())
+ SelectNone();
+
+ m_focusObject = obj;
+
+ if (!obj)
+ m_focusObject = & m_buffer;
+
+ if (setCaretPosition && changingContainer)
+ {
+ m_selection.Reset();
+ m_selectionAnchor = -2;
+ m_selectionAnchorObject = NULL;
+ m_selectionState = wxRichTextCtrlSelectionState_Normal;
+
+ long pos = -1;
+
+ m_caretAtLineStart = false;
+ MoveCaret(pos, m_caretAtLineStart);
+ SetDefaultStyleToCursorStyle();
+
+ wxRichTextEvent cmdEvent(
+ wxEVT_COMMAND_RICHTEXT_FOCUS_OBJECT_CHANGED,
+ GetId());
+ cmdEvent.SetEventObject(this);
+ cmdEvent.SetPosition(m_caretPosition+1);
+ cmdEvent.SetOldContainer(oldContainer);
+ cmdEvent.SetContainer(m_focusObject);
+
+ GetEventHandler()->ProcessEvent(cmdEvent);
+ }
+ return true;
+}
+
+#if wxUSE_DRAG_AND_DROP
+void wxRichTextCtrl::OnDrop(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y), wxDragResult def, wxDataObject* DataObj)
+{
+ m_preDrag = false;
+
+ if ((def != wxDragCopy) && (def != wxDragMove))
+ {
+ return;
+ }
+
+ if (!GetSelection().IsValid())
+ {
+ return;
+ }
+
+ wxRichTextParagraphLayoutBox* originContainer = GetSelection().GetContainer();
+ wxRichTextParagraphLayoutBox* destContainer = GetFocusObject(); // This will be the drop container, not necessarily the same as the origin one
+
+ wxRichTextBuffer* richTextBuffer = ((wxRichTextBufferDataObject*)DataObj)->GetRichTextBuffer();
+ if (richTextBuffer)
+ {
+ long position = GetCaretPosition();
+ wxRichTextRange selectionrange = GetInternalSelectionRange();
+ if (selectionrange.Contains(position) && (def == wxDragMove))
+ {
+ // It doesn't make sense to move onto itself
+ return;
+ }
+
+ // If we're moving, and the data is being moved forward, we need to drop first, then delete the selection
+ // If moving backwards, we need to delete then drop. If we're copying (or doing nothing) we don't delete anyway
+ bool DeleteAfter = (def == wxDragMove) && (position > selectionrange.GetEnd());
+ if ((def == wxDragMove) && !DeleteAfter)
+ {
+ // We can't use e.g. DeleteSelectedContent() as it uses the focus container
+ originContainer->DeleteRangeWithUndo(selectionrange, this, &GetBuffer());
+ }
+
+ destContainer->InsertParagraphsWithUndo(&GetBuffer(), position+1, *richTextBuffer, this, 0);
+ ShowPosition(position + richTextBuffer->GetOwnRange().GetEnd());
+
+ delete richTextBuffer;
+
+ if (DeleteAfter)
+ {
+ // We can't use e.g. DeleteSelectedContent() as it uses the focus container
+ originContainer->DeleteRangeWithUndo(selectionrange, this, &GetBuffer());
+ }
+
+ SelectNone();
+ Refresh();
+ }
+}
+#endif // wxUSE_DRAG_AND_DROP
+
+
+#if wxUSE_DRAG_AND_DROP
+bool wxRichTextDropSource::GiveFeedback(wxDragResult WXUNUSED(effect))
+{
+ wxCHECK_MSG(m_rtc, false, wxT("NULL m_rtc"));
+
+ long position = 0;
+ int hit = 0;
+ wxRichTextObject* hitObj = NULL;
+ wxRichTextParagraphLayoutBox* container = m_rtc->FindContainerAtPoint(m_rtc->ScreenToClient(wxGetMousePosition()), position, hit, hitObj);
+
+ if (!(hit & wxRICHTEXT_HITTEST_NONE) && container && container->AcceptsFocus())
+ {
+ m_rtc->StoreFocusObject(container);
+ m_rtc->SetCaretPositionAfterClick(container, position, hit);
+ }
+
+ return false; // so that the base-class sets a cursor
+}
+#endif // wxUSE_DRAG_AND_DROP
+
+bool wxRichTextCtrl::CanDeleteRange(wxRichTextParagraphLayoutBox& WXUNUSED(container), const wxRichTextRange& WXUNUSED(range)) const
+{
+ return true;
+}
+
+bool wxRichTextCtrl::CanInsertContent(wxRichTextParagraphLayoutBox& WXUNUSED(container), long WXUNUSED(pos)) const
+{
+ return true;
+}
+
+void wxRichTextCtrl::EnableVerticalScrollbar(bool enable)
+{
+ m_verticalScrollbarEnabled = enable;
+ SetupScrollbars();
+}
+
+