4
4
// Author: Julian Smart
6
6
// Created: 2005-10-02
7
// RCS-ID: $Id: richtext.cpp 44612 2007-03-05 15:22:07Z JS $
7
// RCS-ID: $Id: richtext.cpp 51739 2008-02-12 17:05:32Z JS $
8
8
// Copyright: (c) Julian Smart
9
9
// Licence: wxWindows licence
10
10
/////////////////////////////////////////////////////////////////////////////
166
166
void OnDemoteList(wxCommandEvent& event);
167
167
void OnClearList(wxCommandEvent& event);
169
void OnReload(wxCommandEvent& event);
169
171
void OnViewHTML(wxCommandEvent& event);
171
173
void OnSwitchStyleSheets(wxCommandEvent& event);
292
299
EVT_MENU(ID_FORMAT_PARAGRAPH_SPACING_MORE, MyFrame::OnParagraphSpacingMore)
293
300
EVT_MENU(ID_FORMAT_PARAGRAPH_SPACING_LESS, MyFrame::OnParagraphSpacingLess)
302
EVT_MENU(ID_RELOAD, MyFrame::OnReload)
295
304
EVT_MENU(ID_INSERT_SYMBOL, MyFrame::OnInsertSymbol)
296
305
EVT_MENU(ID_INSERT_URL, MyFrame::OnInsertURL)
561
570
fileMenu->Append(wxID_SAVE, _T("&Save\tCtrl+S"), _T("Save a file"));
562
571
fileMenu->Append(wxID_SAVEAS, _T("&Save As...\tF12"), _T("Save to a new file"));
563
572
fileMenu->AppendSeparator();
573
fileMenu->Append(ID_RELOAD, _T("&Reload Text\tF2"), _T("Reload the initial text"));
574
fileMenu->AppendSeparator();
564
575
fileMenu->Append(ID_PAGE_SETUP, _T("Page Set&up..."), _T("Page setup"));
565
576
fileMenu->Append(ID_PRINT, _T("&Print...\tCtrl+P"), _T("Print"));
566
577
fileMenu->Append(ID_PREVIEW, _T("Print Pre&view"), _T("Print preview"));
714
725
styleListCtrl->SetRichTextCtrl(m_richTextCtrl);
715
726
styleListCtrl->UpdateStyles();
732
void MyFrame::WriteInitialText()
717
734
wxRichTextCtrl& r = *m_richTextCtrl;
736
r.SetDefaultStyle(wxRichTextAttr());
719
738
r.BeginSuppressUndo();
721
740
r.BeginParagraphSpacing(0, 20);
728
747
wxString lineBreak = (wxChar) 29;
730
r.WriteText(wxString(wxT("Welcome to wxRichTextCtrl, a wxWidgets control")) + lineBreak + wxT("for editing and presenting styled text and images"));
749
r.WriteText(wxString(wxT("Welcome to wxRichTextCtrl, a wxWidgets control")) + lineBreak + wxT("for editing and presenting styled text and images\n"));
735
754
r.WriteText(wxT("by Julian Smart"));
779
798
r.WriteText(wxT(" Next we'll show an indented paragraph."));
781
802
r.BeginLeftIndent(60);
784
803
r.WriteText(wxT("It was in January, the most down-trodden month of an Edinburgh winter. An attractive woman came into the cafe, which is nothing remarkable."));
785
806
r.EndLeftIndent();
789
808
r.WriteText(wxT("Next, we'll show a first-line indent, achieved using BeginLeftIndent(100, -40)."));
791
812
r.BeginLeftIndent(100, -40);
794
814
r.WriteText(wxT("It was in January, the most down-trodden month of an Edinburgh winter. An attractive woman came into the cafe, which is nothing remarkable."));
795
817
r.EndLeftIndent();
799
819
r.WriteText(wxT("Numbered bullets are possible, again using subindents:"));
801
822
r.BeginNumberedBullet(1, 100, 60);
804
823
r.WriteText(wxT("This is my first item. Note that wxRichTextCtrl can apply numbering and bullets automatically based on list styles, but this list is formatted explicitly by setting indents."));
805
826
r.EndNumberedBullet();
807
828
r.BeginNumberedBullet(2, 100, 60);
810
829
r.WriteText(wxT("This is my second item."));
811
832
r.EndNumberedBullet();
815
834
r.WriteText(wxT("The following paragraph is right-indented:"));
817
837
r.BeginRightIndent(200);
839
r.WriteText(wxT("It was in January, the most down-trodden month of an Edinburgh winter. An attractive woman came into the cafe, which is nothing remarkable."));
820
r.WriteText(wxT("It was in January, the most down-trodden month of an Edinburgh winter. An attractive woman came into the cafe, which is nothing remarkable."));
821
842
r.EndRightIndent();
825
844
r.WriteText(wxT("The following paragraph is right-aligned with 1.5 line spacing:"));
827
847
r.BeginAlignment(wxTEXT_ALIGNMENT_RIGHT);
828
848
r.BeginLineSpacing(wxTEXT_ATTR_LINE_SPACING_HALF);
849
r.WriteText(wxT("It was in January, the most down-trodden month of an Edinburgh winter. An attractive woman came into the cafe, which is nothing remarkable."));
831
r.WriteText(wxT("It was in January, the most down-trodden month of an Edinburgh winter. An attractive woman came into the cafe, which is nothing remarkable."));
832
851
r.EndLineSpacing();
833
852
r.EndAlignment();
842
861
attr.SetTabs(tabs);
843
862
r.SetDefaultStyle(attr);
846
864
r.WriteText(wxT("This line contains tabs:\tFirst tab\tSecond tab\tThird tab"));
849
867
r.WriteText(wxT("Other notable features of wxRichTextCtrl include:"));
851
870
r.BeginSymbolBullet(wxT('*'), 100, 60);
853
871
r.WriteText(wxT("Compatibility with wxTextCtrl API"));
854
873
r.EndSymbolBullet();
856
875
r.BeginSymbolBullet(wxT('*'), 100, 60);
858
876
r.WriteText(wxT("Easy stack-based BeginXXX()...EndXXX() style setting in addition to SetStyle()"));
859
878
r.EndSymbolBullet();
861
880
r.BeginSymbolBullet(wxT('*'), 100, 60);
863
881
r.WriteText(wxT("XML loading and saving"));
864
883
r.EndSymbolBullet();
866
885
r.BeginSymbolBullet(wxT('*'), 100, 60);
868
886
r.WriteText(wxT("Undo/Redo, with batching option and Undo suppressing"));
869
888
r.EndSymbolBullet();
871
890
r.BeginSymbolBullet(wxT('*'), 100, 60);
873
891
r.WriteText(wxT("Clipboard copy and paste"));
874
893
r.EndSymbolBullet();
876
895
r.BeginSymbolBullet(wxT('*'), 100, 60);
878
896
r.WriteText(wxT("wxRichTextStyleSheet with named character and paragraph styles, and control for applying named styles"));
879
898
r.EndSymbolBullet();
881
900
r.BeginSymbolBullet(wxT('*'), 100, 60);
883
901
r.WriteText(wxT("A design that can easily be extended to other content types, ultimately with text boxes, tables, controls, and so on"));
884
903
r.EndSymbolBullet();
888
905
// Make a style suitable for showing a URL
889
906
wxRichTextAttr urlStyle;
890
907
urlStyle.SetTextColour(*wxBLUE);
1332
void MyFrame::OnReload(wxCommandEvent& WXUNUSED(event))
1334
m_richTextCtrl->Clear();
1313
1338
void MyFrame::OnViewHTML(wxCommandEvent& WXUNUSED(event))
1315
1340
wxDialog dialog(this, wxID_ANY, _("HTML"), wxDefaultPosition, wxSize(500, 400), wxDEFAULT_DIALOG_STYLE);