+
+// 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;
+
+ wxRichTextCtrl* ctrl = (wxRichTextCtrl*) FindWindow(ID_RICHTEXT_CTRL);
+ wxRichTextStyleListCtrl *styleList = (wxRichTextStyleListCtrl*) FindWindow(ID_RICHTEXT_STYLE_LIST);
+ wxRichTextStyleComboCtrl* styleCombo = (wxRichTextStyleComboCtrl*) FindWindow(ID_RICHTEXT_STYLE_COMBO);
+
+ wxRichTextStyleSheet* sheet = ctrl->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;
+
+ ctrl->SetStyleSheet(sheet);
+ ctrl->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))
+{
+ wxRichTextCtrl* ctrl = (wxRichTextCtrl*) FindWindow(ID_RICHTEXT_CTRL);
+ wxRichTextStyleSheet* sheet = ctrl->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))
+{
+ wxRichTextCtrl* ctrl = (wxRichTextCtrl*) FindWindow(ID_RICHTEXT_CTRL);
+
+ wxTextAttrEx attr;
+ attr.SetFlags(wxTEXT_ATTR_FONT);
+ ctrl->GetStyle(ctrl->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 = ctrl->GetInsertionPoint();
+
+ ctrl->WriteText(dlg.GetSymbol());
+
+ if (!dlg.UseNormalFont())
+ {
+ wxFont font(attr.GetFont());
+ font.SetFaceName(dlg.GetFontName());
+ attr.SetFont(font);
+ ctrl->SetStyle(insertionPoint, insertionPoint+1, attr);
+ }
+ }
+ }
+}
+
+void MyFrame::OnNumberList(wxCommandEvent& WXUNUSED(event))
+{
+ wxRichTextCtrl* ctrl = (wxRichTextCtrl*) FindWindow(ID_RICHTEXT_CTRL);
+
+ if (ctrl->HasSelection())
+ {
+ wxRichTextRange range = ctrl->GetSelectionRange();
+ ctrl->SetListStyle(range, wxT("Numbered List 1"), wxRICHTEXT_SETSTYLE_WITH_UNDO|wxRICHTEXT_SETSTYLE_RENUMBER);
+ }
+}
+
+void MyFrame::OnBulletsAndNumbering(wxCommandEvent& WXUNUSED(event))
+{
+ wxRichTextCtrl* ctrl = (wxRichTextCtrl*) FindWindow(ID_RICHTEXT_CTRL);
+ wxRichTextStyleSheet* sheet = ctrl->GetStyleSheet();
+
+ int flags = wxRICHTEXT_ORGANISER_BROWSE_NUMBERING;
+
+ wxRichTextStyleOrganiserDialog dlg(flags, sheet, ctrl, this, wxID_ANY, _("Bullets and Numbering"));
+ if (dlg.ShowModal() == wxID_OK)
+ {
+ if (dlg.GetSelectedStyleDefinition())
+ dlg.ApplyStyle();
+ }
+}
+
+void MyFrame::OnItemizeList(wxCommandEvent& WXUNUSED(event))
+{
+ wxRichTextCtrl* ctrl = (wxRichTextCtrl*) FindWindow(ID_RICHTEXT_CTRL);
+
+ if (ctrl->HasSelection())
+ {
+ wxRichTextRange range = ctrl->GetSelectionRange();
+ ctrl->SetListStyle(range, wxT("Bullet List 1"));
+ }
+}
+
+void MyFrame::OnRenumberList(wxCommandEvent& WXUNUSED(event))
+{
+ wxRichTextCtrl* ctrl = (wxRichTextCtrl*) FindWindow(ID_RICHTEXT_CTRL);
+
+ if (ctrl->HasSelection())
+ {
+ wxRichTextRange range = ctrl->GetSelectionRange();
+ ctrl->NumberList(range, NULL, wxRICHTEXT_SETSTYLE_WITH_UNDO|wxRICHTEXT_SETSTYLE_RENUMBER);
+ }
+}
+
+void MyFrame::OnPromoteList(wxCommandEvent& WXUNUSED(event))
+{
+ wxRichTextCtrl* ctrl = (wxRichTextCtrl*) FindWindow(ID_RICHTEXT_CTRL);
+
+ if (ctrl->HasSelection())
+ {
+ wxRichTextRange range = ctrl->GetSelectionRange();
+ ctrl->PromoteList(1, range, NULL);
+ }
+}
+
+void MyFrame::OnDemoteList(wxCommandEvent& WXUNUSED(event))
+{
+ wxRichTextCtrl* ctrl = (wxRichTextCtrl*) FindWindow(ID_RICHTEXT_CTRL);
+
+ if (ctrl->HasSelection())
+ {
+ wxRichTextRange range = ctrl->GetSelectionRange();
+ ctrl->PromoteList(-1, range, NULL);
+ }
+}
+
+void MyFrame::OnClearList(wxCommandEvent& WXUNUSED(event))
+{
+ wxRichTextCtrl* ctrl = (wxRichTextCtrl*) FindWindow(ID_RICHTEXT_CTRL);
+
+ if (ctrl->HasSelection())
+ {
+ wxRichTextRange range = ctrl->GetSelectionRange();
+ ctrl->ClearListStyle(range);
+ }
+}
+