+// 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_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->GetUnscaledPoint(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();
+}
+
+void wxRichTextCtrl::SetFontScale(double fontScale, bool refresh)
+{
+ GetBuffer().SetFontScale(fontScale);
+ if (refresh)
+ {
+ GetBuffer().Invalidate(wxRICHTEXT_ALL);
+ Refresh();
+ }
+}
+
+void wxRichTextCtrl::SetDimensionScale(double dimScale, bool refresh)
+{
+ GetBuffer().SetDimensionScale(dimScale);
+ if (refresh)
+ {
+ GetBuffer().Invalidate(wxRICHTEXT_ALL);
+ Refresh();
+ }
+}
+
+// Sets an overall scale factor for displaying and editing the content.
+void wxRichTextCtrl::SetScale(double scale, bool refresh)
+{
+ m_scale = scale;
+ if (refresh)
+ {
+ GetBuffer().Invalidate(wxRICHTEXT_ALL);
+ Refresh();
+ }
+}
+
+// Get an unscaled point
+wxPoint wxRichTextCtrl::GetUnscaledPoint(const wxPoint& pt) const
+{
+ if (GetScale() == 1.0)
+ return pt;
+ else
+ return wxPoint((int) (0.5 + double(pt.x) / GetScale()), (int) (0.5 + double(pt.y) / GetScale()));
+}
+
+// Get a scaled point
+wxPoint wxRichTextCtrl::GetScaledPoint(const wxPoint& pt) const
+{
+ if (GetScale() == 1.0)
+ return pt;
+ else
+ return wxPoint((int) (0.5 + double(pt.x) * GetScale()), (int) (0.5 + double(pt.y) * GetScale()));
+}
+
+// Get an unscaled size
+wxSize wxRichTextCtrl::GetUnscaledSize(const wxSize& sz) const
+{
+ if (GetScale() == 1.0)
+ return sz;
+ else
+ return wxSize((int) (0.5 + double(sz.x) / GetScale()), (int) (0.5 + double(sz.y) / GetScale()));
+}
+
+// Get a scaled size
+wxSize wxRichTextCtrl::GetScaledSize(const wxSize& sz) const
+{
+ if (GetScale() == 1.0)
+ return sz;
+ else
+ return wxSize((int) (0.5 + double(sz.x) * GetScale()), (int) (0.5 + double(sz.y) * GetScale()));
+}
+
+// Get an unscaled rect
+wxRect wxRichTextCtrl::GetUnscaledRect(const wxRect& rect) const
+{
+ if (GetScale() == 1.0)
+ return rect;
+ else
+ return wxRect((int) (0.5 + double(rect.x) / GetScale()), (int) (0.5 + double(rect.y) / GetScale()),
+ (int) (0.5 + double(rect.width) / GetScale()), (int) (0.5 + double(rect.height) / GetScale()));
+}
+
+// Get a scaled rect
+wxRect wxRichTextCtrl::GetScaledRect(const wxRect& rect) const
+{
+ if (GetScale() == 1.0)
+ return rect;
+ else
+ return wxRect((int) (0.5 + double(rect.x) * GetScale()), (int) (0.5 + double(rect.y) * GetScale()),
+ (int) (0.5 + double(rect.width) * GetScale()), (int) (0.5 + double(rect.height) * GetScale()));
+}
+