+
+// 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);
+ wxRichTextStyleListBox* styleList = (wxRichTextStyleListBox*) 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::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);
+ }
+ }
+ }
+}