+
+ // Now delete the temporary in-memory images
+ htmlHandler.DeleteTemporaryImages();
+}
+
+// Demonstrates how you can change the style sheets and have the changes
+// reflected in the control content without wiping out character formatting.
+
+void MyFrame::OnSwitchStyleSheets(wxCommandEvent& WXUNUSED(event))
+{
+ static wxRichTextStyleSheet* gs_AlternateStyleSheet = NULL;
+
+ wxRichTextStyleListCtrl *styleList = (wxRichTextStyleListCtrl*) FindWindow(ID_RICHTEXT_STYLE_LIST);
+ wxRichTextStyleComboCtrl* styleCombo = (wxRichTextStyleComboCtrl*) FindWindow(ID_RICHTEXT_STYLE_COMBO);
+
+ wxRichTextStyleSheet* sheet = m_richTextCtrl->GetStyleSheet();
+
+ // One-time creation of an alternate style sheet
+ if (!gs_AlternateStyleSheet)
+ {
+ gs_AlternateStyleSheet = new wxRichTextStyleSheet(*sheet);
+
+ // Make some modifications
+ for (int i = 0; i < (int) gs_AlternateStyleSheet->GetParagraphStyleCount(); i++)
+ {
+ wxRichTextParagraphStyleDefinition* def = gs_AlternateStyleSheet->GetParagraphStyle(i);
+
+ if (def->GetStyle().HasTextColour())
+ def->GetStyle().SetTextColour(*wxBLUE);
+
+ if (def->GetStyle().HasAlignment())
+ {
+ if (def->GetStyle().GetAlignment() == wxTEXT_ALIGNMENT_CENTRE)
+ def->GetStyle().SetAlignment(wxTEXT_ALIGNMENT_RIGHT);
+ else if (def->GetStyle().GetAlignment() == wxTEXT_ALIGNMENT_LEFT)
+ def->GetStyle().SetAlignment(wxTEXT_ALIGNMENT_CENTRE);
+ }
+ if (def->GetStyle().HasLeftIndent())
+ {
+ def->GetStyle().SetLeftIndent(def->GetStyle().GetLeftIndent() * 2);
+ }
+ }
+ }
+
+ // Switch sheets
+ wxRichTextStyleSheet* tmp = gs_AlternateStyleSheet;
+ gs_AlternateStyleSheet = sheet;
+ sheet = tmp;
+
+ m_richTextCtrl->SetStyleSheet(sheet);
+ m_richTextCtrl->ApplyStyleSheet(sheet); // Makes the control reflect the new style definitions
+
+ styleList->SetStyleSheet(sheet);
+ styleList->UpdateStyles();
+
+ styleCombo->SetStyleSheet(sheet);
+ styleCombo->UpdateStyles();
+}
+
+void MyFrame::OnManageStyles(wxCommandEvent& WXUNUSED(event))
+{
+ wxRichTextStyleSheet* sheet = m_richTextCtrl->GetStyleSheet();
+
+ int flags = wxRICHTEXT_ORGANISER_CREATE_STYLES|wxRICHTEXT_ORGANISER_EDIT_STYLES;
+
+ wxRichTextStyleOrganiserDialog dlg(flags, sheet, NULL, this, wxID_ANY, _("Style Manager"));
+ dlg.ShowModal();
+}
+
+void MyFrame::OnInsertSymbol(wxCommandEvent& WXUNUSED(event))
+{
+ wxTextAttrEx attr;
+ attr.SetFlags(wxTEXT_ATTR_FONT);
+ m_richTextCtrl->GetStyle(m_richTextCtrl->GetInsertionPoint(), attr);
+
+ wxString currentFontName;
+ if (attr.HasFont() && attr.GetFont().Ok())
+ currentFontName = attr.GetFont().GetFaceName();
+
+ // Don't set the initial font in the dialog (so the user is choosing
+ // 'normal text', i.e. the current font) but do tell the dialog
+ // what 'normal text' is.
+
+ wxSymbolPickerDialog dlg(wxT("*"), wxEmptyString, currentFontName, this);
+
+ if (dlg.ShowModal() == wxID_OK)
+ {
+ if (dlg.HasSelection())
+ {
+ long insertionPoint = m_richTextCtrl->GetInsertionPoint();
+
+ m_richTextCtrl->WriteText(dlg.GetSymbol());
+
+ if (!dlg.UseNormalFont())
+ {
+ wxFont font(attr.GetFont());
+ font.SetFaceName(dlg.GetFontName());
+ attr.SetFont(font);
+ m_richTextCtrl->SetStyle(insertionPoint, insertionPoint+1, attr);
+ }
+ }
+ }
+}
+
+void MyFrame::OnNumberList(wxCommandEvent& WXUNUSED(event))
+{
+ if (m_richTextCtrl->HasSelection())
+ {
+ wxRichTextRange range = m_richTextCtrl->GetSelectionRange();
+ m_richTextCtrl->SetListStyle(range, wxT("Numbered List 1"), wxRICHTEXT_SETSTYLE_WITH_UNDO|wxRICHTEXT_SETSTYLE_RENUMBER);
+ }
+}
+
+void MyFrame::OnBulletsAndNumbering(wxCommandEvent& WXUNUSED(event))
+{
+ wxRichTextStyleSheet* sheet = m_richTextCtrl->GetStyleSheet();
+
+ int flags = wxRICHTEXT_ORGANISER_BROWSE_NUMBERING;
+
+ wxRichTextStyleOrganiserDialog dlg(flags, sheet, m_richTextCtrl, this, wxID_ANY, _("Bullets and Numbering"));
+ if (dlg.ShowModal() == wxID_OK)
+ {
+ if (dlg.GetSelectedStyleDefinition())
+ dlg.ApplyStyle();
+ }
+}
+
+void MyFrame::OnItemizeList(wxCommandEvent& WXUNUSED(event))
+{
+ if (m_richTextCtrl->HasSelection())
+ {
+ wxRichTextRange range = m_richTextCtrl->GetSelectionRange();
+ m_richTextCtrl->SetListStyle(range, wxT("Bullet List 1"));
+ }
+}
+
+void MyFrame::OnRenumberList(wxCommandEvent& WXUNUSED(event))
+{
+ if (m_richTextCtrl->HasSelection())
+ {
+ wxRichTextRange range = m_richTextCtrl->GetSelectionRange();
+ m_richTextCtrl->NumberList(range, NULL, wxRICHTEXT_SETSTYLE_WITH_UNDO|wxRICHTEXT_SETSTYLE_RENUMBER);
+ }
+}
+
+void MyFrame::OnPromoteList(wxCommandEvent& WXUNUSED(event))
+{
+ if (m_richTextCtrl->HasSelection())
+ {
+ wxRichTextRange range = m_richTextCtrl->GetSelectionRange();
+ m_richTextCtrl->PromoteList(1, range, NULL);
+ }