+// 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);
+
+ 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 wxRICHTEXT_USE_OWN_CARET
+
+// ----------------------------------------------------------------------------
+// initialization and destruction
+// ----------------------------------------------------------------------------
+
+void wxRichTextCaret::Init()
+{
+ m_hasFocus = true;
+
+ m_xOld =
+ m_yOld = -1;
+ m_richTextCtrl = NULL;
+ m_needsUpdate = false;
+ m_flashOn = true;
+}
+
+wxRichTextCaret::~wxRichTextCaret()
+{
+ if (m_timer.IsRunning())
+ m_timer.Stop();
+}
+
+// ----------------------------------------------------------------------------
+// showing/hiding/moving the caret (base class interface)
+// ----------------------------------------------------------------------------
+
+void wxRichTextCaret::DoShow()
+{
+ m_flashOn = true;
+
+ if (!m_timer.IsRunning())
+ m_timer.Start(GetBlinkTime());
+
+ Refresh();
+}
+
+void wxRichTextCaret::DoHide()
+{
+ if (m_timer.IsRunning())
+ m_timer.Stop();
+
+ Refresh();
+}
+
+void wxRichTextCaret::DoMove()
+{
+ if (IsVisible())
+ {
+ Refresh();
+
+ if (m_xOld != -1 && m_yOld != -1)
+ {
+ if (m_richTextCtrl)
+ {
+ wxRect rect(GetPosition(), GetSize());
+ m_richTextCtrl->RefreshRect(rect, false);
+ }
+ }
+ }
+
+ m_xOld = m_x;
+ m_yOld = m_y;
+}
+
+void wxRichTextCaret::DoSize()
+{
+ int countVisible = m_countVisible;
+ if (countVisible > 0)
+ {
+ m_countVisible = 0;
+ DoHide();
+ }
+
+ if (countVisible > 0)
+ {
+ m_countVisible = countVisible;
+ DoShow();
+ }
+}
+
+// ----------------------------------------------------------------------------
+// handling the focus
+// ----------------------------------------------------------------------------
+
+void wxRichTextCaret::OnSetFocus()
+{
+ m_hasFocus = true;
+
+ if ( IsVisible() )
+ Refresh();
+}
+
+void wxRichTextCaret::OnKillFocus()
+{
+ m_hasFocus = false;
+}
+
+// ----------------------------------------------------------------------------
+// drawing the caret
+// ----------------------------------------------------------------------------
+
+void wxRichTextCaret::Refresh()
+{
+ if (m_richTextCtrl)
+ {
+ wxRect rect(GetPosition(), GetSize());
+ m_richTextCtrl->RefreshRect(rect, false);
+ }
+}
+
+void wxRichTextCaret::DoDraw(wxDC *dc)
+{
+ dc->SetPen( *wxBLACK_PEN );
+
+ dc->SetBrush(*(m_hasFocus ? wxBLACK_BRUSH : wxTRANSPARENT_BRUSH));
+ dc->SetPen(*wxBLACK_PEN);
+
+ wxPoint pt(m_x, m_y);
+
+ if (m_richTextCtrl)
+ {
+ pt = m_richTextCtrl->GetLogicalPoint(pt);
+ }
+ if (IsVisible() && m_flashOn)
+ dc->DrawRectangle(pt.x, pt.y, m_width, m_height);
+}
+
+void wxRichTextCaret::Notify()
+{
+ m_flashOn = !m_flashOn;
+ Refresh();
+}
+
+void wxRichTextCaretTimer::Notify()
+{
+ m_caret->Notify();
+}
+#endif
+ // wxRICHTEXT_USE_OWN_CARET
+
+// Add an item
+bool wxRichTextContextMenuPropertiesInfo::AddItem(const wxString& label, wxRichTextObject* obj)
+{
+ if (GetCount() < 3)
+ {
+ m_labels.Add(label);
+ m_objects.Add(obj);
+ return true;
+ }
+ else
+ return false;
+}
+
+// Returns number of menu items were added.
+int wxRichTextContextMenuPropertiesInfo::AddMenuItems(wxMenu* menu, int startCmd) const
+{
+ wxMenuItem* item = menu->FindItem(startCmd);
+ // If none of the standard properties identifiers are in the menu, assume it's
+ // a custom menu without properties commands, and don't add them.
+ if (item)
+ {
+ // If no items, to add just set the text to something generic
+ if (GetCount() == 0)
+ {
+ menu->SetLabel(startCmd, _("&Properties"));
+
+ // Delete the others if necessary
+ int i;
+ for (i = startCmd+1; i < startCmd+3; i++)
+ {
+ if (menu->FindItem(i))
+ {
+ menu->Delete(i);
+ }
+ }
+ }
+ else
+ {
+ int i;
+ int pos = -1;
+ // Find the position of the first properties item
+ for (i = 0; i < (int) menu->GetMenuItemCount(); i++)
+ {
+ wxMenuItem* item = menu->FindItemByPosition(i);
+ if (item && item->GetId() == startCmd)
+ {
+ pos = i;
+ break;
+ }
+ }
+
+ if (pos != -1)
+ {
+ int insertBefore = pos+1;
+ for (i = startCmd; i < startCmd+GetCount(); i++)
+ {
+ if (menu->FindItem(i))
+ {
+ menu->SetLabel(i, m_labels[i - startCmd]);
+ }
+ else
+ {
+ if (insertBefore >= (int) menu->GetMenuItemCount())
+ menu->Append(i, m_labels[i - startCmd]);
+ else
+ menu->Insert(insertBefore, i, m_labels[i - startCmd]);
+ }
+ insertBefore ++;
+ }
+
+ // Delete any old items still left on the menu
+ for (i = startCmd + GetCount(); i < startCmd+3; i++)
+ {
+ if (menu->FindItem(i))
+ {
+ menu->Delete(i);
+ }
+ }
+ }
+ }
+ }
+
+ return GetCount();
+}
+
+// Add appropriate menu items for the current container and clicked on object
+// (and container's parent, if appropriate).
+int wxRichTextContextMenuPropertiesInfo::AddItems(wxRichTextObject* container, wxRichTextObject* obj)
+{
+ Clear();
+ if (obj && obj->CanEditProperties())
+ AddItem(obj->GetPropertiesMenuLabel(), obj);
+
+ if (container && container != obj && container->CanEditProperties() && m_labels.Index(container->GetPropertiesMenuLabel()) == wxNOT_FOUND)
+ AddItem(container->GetPropertiesMenuLabel(), container);
+
+ if (container && container->GetParent() && container->GetParent()->CanEditProperties() && m_labels.Index(container->GetParent()->GetPropertiesMenuLabel()) == wxNOT_FOUND)
+ AddItem(container->GetParent()->GetPropertiesMenuLabel(), container->GetParent());
+
+ return GetCount();
+}
+