+
+void MyFrame::OnSetFontScale(wxCommandEvent& WXUNUSED(event))
+{
+ wxString value = wxString::Format(wxT("%g"), m_richTextCtrl->GetFontScale());
+ wxString text = wxGetTextFromUser(wxT("Enter a text scale factor:"), wxT("Text Scale Factor"), value, wxGetTopLevelParent(this));
+ if (!text.IsEmpty() && value != text)
+ {
+ double scale = 1.0;
+ wxSscanf(text, wxT("%lf"), & scale);
+ m_richTextCtrl->SetFontScale(scale, true);
+ }
+}
+
+void MyFrame::OnSetDimensionScale(wxCommandEvent& WXUNUSED(event))
+{
+ wxString value = wxString::Format(wxT("%g"), m_richTextCtrl->GetDimensionScale());
+ wxString text = wxGetTextFromUser(wxT("Enter a dimension scale factor:"), wxT("Dimension Scale Factor"), value, wxGetTopLevelParent(this));
+ if (!text.IsEmpty() && value != text)
+ {
+ double scale = 1.0;
+ wxSscanf(text, wxT("%lf"), & scale);
+ m_richTextCtrl->SetDimensionScale(scale, true);
+ }
+}
+
+void MyRichTextCtrl::PrepareContent(wxRichTextParagraphLayoutBox& container)
+{
+ if (IsLocked())
+ {
+ // Lock all content that's about to be added to the control
+ wxRichTextObjectList::compatibility_iterator node = container.GetChildren().GetFirst();
+ while (node)
+ {
+ wxRichTextParagraph* para = wxDynamicCast(node->GetData(), wxRichTextParagraph);
+ if (para)
+ {
+ wxRichTextObjectList::compatibility_iterator childNode = para->GetChildren().GetFirst();
+ while (childNode)
+ {
+ wxRichTextObject* obj = childNode->GetData();
+ obj->GetProperties().SetProperty(wxT("Lock"), m_lockId);
+
+ childNode = childNode->GetNext();
+ }
+ }
+ node = node->GetNext();
+ }
+ }
+}
+
+bool MyRichTextCtrl::CanDeleteRange(wxRichTextParagraphLayoutBox& container, const wxRichTextRange& range) const
+{
+ long i;
+ for (i = range.GetStart(); i < range.GetEnd(); i++)
+ {
+ wxRichTextObject* obj = container.GetLeafObjectAtPosition(i);
+ if (obj && obj->GetProperties().HasProperty(wxT("Lock")))
+ {
+ return false;
+ }
+ }
+ return true;
+}
+
+bool MyRichTextCtrl::CanInsertContent(wxRichTextParagraphLayoutBox& container, long pos) const
+{
+ wxRichTextObject* child1 = container.GetLeafObjectAtPosition(pos);
+ wxRichTextObject* child2 = container.GetLeafObjectAtPosition(pos-1);
+
+ long lock1 = -1, lock2 = -1;
+
+ if (child1 && child1->GetProperties().HasProperty(wxT("Lock")))
+ lock1 = child1->GetProperties().GetPropertyLong(wxT("Lock"));
+ if (child2 && child2->GetProperties().HasProperty(wxT("Lock")))
+ lock2 = child2->GetProperties().GetPropertyLong(wxT("Lock"));
+
+ if (lock1 != -1 && lock1 == lock2)
+ return false;
+
+ // Don't allow insertion before a locked object if it's at the beginning of the buffer.
+ if (pos == 0 && lock1 != -1)
+ return false;
+
+ return true;
+}
+
+
+class wxRichTextEnhancedDrawingHandler: public wxRichTextDrawingHandler
+{
+public:
+ wxRichTextEnhancedDrawingHandler()
+ {
+ SetName(wxT("enhanceddrawing"));
+ m_lockBackgroundColour = wxColour(220, 220, 220);
+ }
+
+ /**
+ Returns @true if this object has virtual attributes that we can provide.
+ */
+ virtual bool HasVirtualAttributes(wxRichTextObject* obj) const;
+
+ /**
+ Provides virtual attributes that we can provide.
+ */
+ virtual bool GetVirtualAttributes(wxRichTextAttr& attr, wxRichTextObject* obj) const;
+
+ wxColour m_lockBackgroundColour;
+};
+
+bool wxRichTextEnhancedDrawingHandler::HasVirtualAttributes(wxRichTextObject* obj) const
+{
+ return obj->GetProperties().HasProperty(wxT("Lock"));
+}
+
+bool wxRichTextEnhancedDrawingHandler::GetVirtualAttributes(wxRichTextAttr& attr, wxRichTextObject* obj) const
+{
+ if (obj->GetProperties().HasProperty(wxT("Lock")))
+ {
+ attr.SetBackgroundColour(m_lockBackgroundColour);
+ return true;
+ }
+ return false;
+}
+
+void MyRichTextCtrl::SetEnhancedDrawingHandler()
+{
+ wxRichTextBuffer::AddDrawingHandler(new wxRichTextEnhancedDrawingHandler);
+}