+void wxRichTextCtrl::OnSysColourChanged(wxSysColourChangedEvent& WXUNUSED(event))
+{
+ //wxLogDebug(wxT("wxRichTextCtrl::OnSysColourChanged"));
+
+ wxTextAttrEx basicStyle = GetBasicStyle();
+ basicStyle.SetTextColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
+ SetBasicStyle(basicStyle);
+ SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
+
+ Refresh();
+}
+
+// Refresh the area affected by a selection change
+bool wxRichTextCtrl::RefreshForSelectionChange(const wxRichTextSelection& oldSelection, const wxRichTextSelection& newSelection)
+{
+ // If the selection is not part of the focus object, or we have multiple ranges, then the chances are that
+ // the selection contains whole containers rather than just text, so refresh everything
+ // for now as it would be hard to compute the rectangle bounding all selections.
+ // TODO: improve on this.
+ if ((oldSelection.IsValid() && (oldSelection.GetContainer() != GetFocusObject() || oldSelection.GetCount() > 1)) ||
+ (newSelection.IsValid() && (newSelection.GetContainer() != GetFocusObject() || newSelection.GetCount() > 1)))
+ {
+ Refresh(false);
+ return true;
+ }
+
+ wxRichTextRange oldRange, newRange;
+ if (oldSelection.IsValid())
+ oldRange = oldSelection.GetRange();
+ else
+ oldRange = wxRICHTEXT_NO_SELECTION;
+ if (newSelection.IsValid())
+ newRange = newSelection.GetRange();
+ else
+ newRange = wxRICHTEXT_NO_SELECTION;
+
+ // Calculate the refresh rectangle - just the affected lines
+ long firstPos, lastPos;
+ if (oldRange.GetStart() == -2 && newRange.GetStart() != -2)
+ {
+ firstPos = newRange.GetStart();
+ lastPos = newRange.GetEnd();
+ }
+ else if (oldRange.GetStart() != -2 && newRange.GetStart() == -2)
+ {
+ firstPos = oldRange.GetStart();
+ lastPos = oldRange.GetEnd();
+ }
+ else if (oldRange.GetStart() == -2 && newRange.GetStart() == -2)
+ {
+ return false;
+ }
+ else
+ {
+ firstPos = wxMin(oldRange.GetStart(), newRange.GetStart());
+ lastPos = wxMax(oldRange.GetEnd(), newRange.GetEnd());
+ }
+
+ wxRichTextLine* firstLine = GetFocusObject()->GetLineAtPosition(firstPos);
+ wxRichTextLine* lastLine = GetFocusObject()->GetLineAtPosition(lastPos);
+
+ if (firstLine && lastLine)
+ {
+ wxSize clientSize = GetClientSize();
+ wxPoint pt1 = GetPhysicalPoint(firstLine->GetAbsolutePosition());
+ wxPoint pt2 = GetPhysicalPoint(lastLine->GetAbsolutePosition()) + wxPoint(0, lastLine->GetSize().y);
+
+ pt1.x = 0;
+ pt1.y = wxMax(0, pt1.y);
+ pt2.x = 0;
+ pt2.y = wxMin(clientSize.y, pt2.y);
+
+ wxRect rect(pt1, wxSize(clientSize.x, pt2.y - pt1.y));
+ RefreshRect(rect, false);
+ }
+ else
+ Refresh(false);
+
+ return true;
+}
+
+// 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();
+}
+