+ wxDialog dialog(this, wxID_ANY, wxT("Testing"), wxPoint(10, 10), wxSize(400, 300), wxDEFAULT_DIALOG_STYLE);
+
+ wxNotebook* nb = new wxNotebook(& dialog, wxID_ANY, wxPoint(5, 5), wxSize(300, 250));
+ wxPanel* panel = new wxPanel(nb, wxID_ANY, wxDefaultPosition, wxDefaultSize);
+ wxPanel* panel2 = new wxPanel(nb, wxID_ANY, wxDefaultPosition, wxDefaultSize);
+
+ new wxRichTextCtrl(panel, wxID_ANY, wxEmptyString, wxPoint(5, 5), wxSize(200, 150), wxVSCROLL|wxTE_READONLY);
+ nb->AddPage(panel, wxT("Page 1"));
+
+ new wxRichTextCtrl(panel2, wxID_ANY, wxEmptyString, wxPoint(5, 5), wxSize(200, 150), wxVSCROLL|wxTE_READONLY);
+ nb->AddPage(panel2, wxT("Page 2"));
+
+ new wxButton(& dialog, wxID_OK, wxT("OK"), wxPoint(5, 180));
+
+ dialog.ShowModal();
+
+// wxGetApp().GetPrinting()->PageSetup();
+}
+
+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);