Fixed several style, paste and undo bugs
Added a reload function to the sample for quickly restoring original text git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@51740 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -166,6 +166,8 @@ public:
|
||||
void OnDemoteList(wxCommandEvent& event);
|
||||
void OnClearList(wxCommandEvent& event);
|
||||
|
||||
void OnReload(wxCommandEvent& event);
|
||||
|
||||
void OnViewHTML(wxCommandEvent& event);
|
||||
|
||||
void OnSwitchStyleSheets(wxCommandEvent& event);
|
||||
@@ -182,6 +184,9 @@ public:
|
||||
// Forward command events to the current rich text control, if any
|
||||
bool ProcessEvent(wxEvent& event);
|
||||
|
||||
// Write text
|
||||
void WriteInitialText();
|
||||
|
||||
private:
|
||||
// any class wishing to process wxWidgets events must use this macro
|
||||
DECLARE_EVENT_TABLE()
|
||||
@@ -207,6 +212,8 @@ enum
|
||||
ID_FORMAT_PARAGRAPH,
|
||||
ID_FORMAT_CONTENT,
|
||||
|
||||
ID_RELOAD,
|
||||
|
||||
ID_INSERT_SYMBOL,
|
||||
ID_INSERT_URL,
|
||||
|
||||
@@ -292,6 +299,8 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
||||
EVT_MENU(ID_FORMAT_PARAGRAPH_SPACING_MORE, MyFrame::OnParagraphSpacingMore)
|
||||
EVT_MENU(ID_FORMAT_PARAGRAPH_SPACING_LESS, MyFrame::OnParagraphSpacingLess)
|
||||
|
||||
EVT_MENU(ID_RELOAD, MyFrame::OnReload)
|
||||
|
||||
EVT_MENU(ID_INSERT_SYMBOL, MyFrame::OnInsertSymbol)
|
||||
EVT_MENU(ID_INSERT_URL, MyFrame::OnInsertURL)
|
||||
|
||||
@@ -564,6 +573,8 @@ MyFrame::MyFrame(const wxString& title, wxWindowID id, const wxPoint& pos,
|
||||
fileMenu->Append(wxID_SAVE, _T("&Save\tCtrl+S"), _T("Save a file"));
|
||||
fileMenu->Append(wxID_SAVEAS, _T("&Save As...\tF12"), _T("Save to a new file"));
|
||||
fileMenu->AppendSeparator();
|
||||
fileMenu->Append(ID_RELOAD, _T("&Reload Text\tF2"), _T("Reload the initial text"));
|
||||
fileMenu->AppendSeparator();
|
||||
fileMenu->Append(ID_PAGE_SETUP, _T("Page Set&up..."), _T("Page setup"));
|
||||
fileMenu->Append(ID_PRINT, _T("&Print...\tCtrl+P"), _T("Print"));
|
||||
fileMenu->Append(ID_PREVIEW, _T("Print Pre&view"), _T("Print preview"));
|
||||
@@ -717,8 +728,16 @@ MyFrame::MyFrame(const wxString& title, wxWindowID id, const wxPoint& pos,
|
||||
styleListCtrl->SetRichTextCtrl(m_richTextCtrl);
|
||||
styleListCtrl->UpdateStyles();
|
||||
|
||||
WriteInitialText();
|
||||
}
|
||||
|
||||
// Write text
|
||||
void MyFrame::WriteInitialText()
|
||||
{
|
||||
wxRichTextCtrl& r = *m_richTextCtrl;
|
||||
|
||||
r.SetDefaultStyle(wxRichTextAttr());
|
||||
|
||||
r.BeginSuppressUndo();
|
||||
|
||||
r.BeginParagraphSpacing(0, 20);
|
||||
@@ -730,9 +749,8 @@ MyFrame::MyFrame(const wxString& title, wxWindowID id, const wxPoint& pos,
|
||||
|
||||
wxString lineBreak = (wxChar) 29;
|
||||
|
||||
r.WriteText(wxString(wxT("Welcome to wxRichTextCtrl, a wxWidgets control")) + lineBreak + wxT("for editing and presenting styled text and images"));
|
||||
r.WriteText(wxString(wxT("Welcome to wxRichTextCtrl, a wxWidgets control")) + lineBreak + wxT("for editing and presenting styled text and images\n"));
|
||||
r.EndFontSize();
|
||||
r.Newline();
|
||||
|
||||
r.BeginItalic();
|
||||
r.WriteText(wxT("by Julian Smart"));
|
||||
@@ -743,10 +761,10 @@ MyFrame::MyFrame(const wxString& title, wxWindowID id, const wxPoint& pos,
|
||||
|
||||
r.WriteImage(wxBitmap(zebra_xpm));
|
||||
|
||||
r.EndAlignment();
|
||||
r.Newline();
|
||||
r.Newline();
|
||||
|
||||
r.Newline();
|
||||
r.Newline();
|
||||
r.EndAlignment();
|
||||
|
||||
r.WriteText(wxT("What can you do with this thing? "));
|
||||
|
||||
@@ -781,57 +799,55 @@ MyFrame::MyFrame(const wxString& title, wxWindowID id, const wxPoint& pos,
|
||||
|
||||
r.WriteText(wxT(" Next we'll show an indented paragraph."));
|
||||
|
||||
r.Newline();
|
||||
|
||||
r.BeginLeftIndent(60);
|
||||
r.Newline();
|
||||
|
||||
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."));
|
||||
r.EndLeftIndent();
|
||||
|
||||
r.Newline();
|
||||
|
||||
r.EndLeftIndent();
|
||||
|
||||
r.WriteText(wxT("Next, we'll show a first-line indent, achieved using BeginLeftIndent(100, -40)."));
|
||||
|
||||
r.BeginLeftIndent(100, -40);
|
||||
r.Newline();
|
||||
|
||||
r.BeginLeftIndent(100, -40);
|
||||
|
||||
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."));
|
||||
r.Newline();
|
||||
|
||||
r.EndLeftIndent();
|
||||
|
||||
r.Newline();
|
||||
|
||||
r.WriteText(wxT("Numbered bullets are possible, again using subindents:"));
|
||||
r.Newline();
|
||||
|
||||
r.BeginNumberedBullet(1, 100, 60);
|
||||
r.Newline();
|
||||
|
||||
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."));
|
||||
r.Newline();
|
||||
r.EndNumberedBullet();
|
||||
|
||||
r.BeginNumberedBullet(2, 100, 60);
|
||||
r.Newline();
|
||||
|
||||
r.WriteText(wxT("This is my second item."));
|
||||
r.Newline();
|
||||
r.EndNumberedBullet();
|
||||
|
||||
r.Newline();
|
||||
|
||||
r.WriteText(wxT("The following paragraph is right-indented:"));
|
||||
r.Newline();
|
||||
|
||||
r.BeginRightIndent(200);
|
||||
r.Newline();
|
||||
|
||||
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."));
|
||||
r.EndRightIndent();
|
||||
|
||||
r.Newline();
|
||||
|
||||
r.EndRightIndent();
|
||||
|
||||
r.WriteText(wxT("The following paragraph is right-aligned with 1.5 line spacing:"));
|
||||
r.Newline();
|
||||
|
||||
r.BeginAlignment(wxTEXT_ALIGNMENT_RIGHT);
|
||||
r.BeginLineSpacing(wxTEXT_ATTR_LINE_SPACING_HALF);
|
||||
r.Newline();
|
||||
|
||||
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."));
|
||||
r.Newline();
|
||||
r.EndLineSpacing();
|
||||
r.EndAlignment();
|
||||
|
||||
@@ -840,53 +856,51 @@ MyFrame::MyFrame(const wxString& title, wxWindowID id, const wxPoint& pos,
|
||||
tabs.Add(600);
|
||||
tabs.Add(800);
|
||||
tabs.Add(1000);
|
||||
wxRichTextAttr attr;
|
||||
wxTextAttrEx attr;
|
||||
attr.SetFlags(wxTEXT_ATTR_TABS);
|
||||
attr.SetTabs(tabs);
|
||||
r.SetDefaultStyle(attr);
|
||||
|
||||
r.Newline();
|
||||
r.WriteText(wxT("This line contains tabs:\tFirst tab\tSecond tab\tThird tab"));
|
||||
|
||||
r.Newline();
|
||||
|
||||
r.WriteText(wxT("Other notable features of wxRichTextCtrl include:"));
|
||||
r.Newline();
|
||||
|
||||
r.BeginSymbolBullet(wxT('*'), 100, 60);
|
||||
r.Newline();
|
||||
r.WriteText(wxT("Compatibility with wxTextCtrl API"));
|
||||
r.Newline();
|
||||
r.EndSymbolBullet();
|
||||
|
||||
r.BeginSymbolBullet(wxT('*'), 100, 60);
|
||||
r.Newline();
|
||||
r.WriteText(wxT("Easy stack-based BeginXXX()...EndXXX() style setting in addition to SetStyle()"));
|
||||
r.Newline();
|
||||
r.EndSymbolBullet();
|
||||
|
||||
r.BeginSymbolBullet(wxT('*'), 100, 60);
|
||||
r.Newline();
|
||||
r.WriteText(wxT("XML loading and saving"));
|
||||
r.Newline();
|
||||
r.EndSymbolBullet();
|
||||
|
||||
r.BeginSymbolBullet(wxT('*'), 100, 60);
|
||||
r.Newline();
|
||||
r.WriteText(wxT("Undo/Redo, with batching option and Undo suppressing"));
|
||||
r.Newline();
|
||||
r.EndSymbolBullet();
|
||||
|
||||
r.BeginSymbolBullet(wxT('*'), 100, 60);
|
||||
r.Newline();
|
||||
r.WriteText(wxT("Clipboard copy and paste"));
|
||||
r.Newline();
|
||||
r.EndSymbolBullet();
|
||||
|
||||
r.BeginSymbolBullet(wxT('*'), 100, 60);
|
||||
r.Newline();
|
||||
r.WriteText(wxT("wxRichTextStyleSheet with named character and paragraph styles, and control for applying named styles"));
|
||||
r.Newline();
|
||||
r.EndSymbolBullet();
|
||||
|
||||
r.BeginSymbolBullet(wxT('*'), 100, 60);
|
||||
r.Newline();
|
||||
r.WriteText(wxT("A design that can easily be extended to other content types, ultimately with text boxes, tables, controls, and so on"));
|
||||
r.EndSymbolBullet();
|
||||
|
||||
r.Newline();
|
||||
r.EndSymbolBullet();
|
||||
|
||||
// Make a style suitable for showing a URL
|
||||
wxRichTextAttr urlStyle;
|
||||
@@ -903,14 +917,13 @@ MyFrame::MyFrame(const wxString& title, wxWindowID id, const wxPoint& pos,
|
||||
|
||||
r.Newline();
|
||||
|
||||
r.WriteText(wxT("Note: this sample content was generated programmatically from within the MyFrame constructor in the demo. The images were loaded from inline XPMs. Enjoy wxRichTextCtrl!"));
|
||||
r.WriteText(wxT("Note: this sample content was generated programmatically from within the MyFrame constructor in the demo. The images were loaded from inline XPMs. Enjoy wxRichTextCtrl!\n"));
|
||||
|
||||
r.EndParagraphSpacing();
|
||||
|
||||
r.EndSuppressUndo();
|
||||
}
|
||||
|
||||
|
||||
// event handlers
|
||||
|
||||
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
|
||||
@@ -1313,6 +1326,12 @@ void MyFrame::OnParagraphSpacingLess(wxCommandEvent& WXUNUSED(event))
|
||||
}
|
||||
}
|
||||
|
||||
void MyFrame::OnReload(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
m_richTextCtrl->Clear();
|
||||
WriteInitialText();
|
||||
}
|
||||
|
||||
void MyFrame::OnViewHTML(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
wxDialog dialog(this, wxID_ANY, _("HTML"), wxDefaultPosition, wxSize(500, 400), wxDEFAULT_DIALOG_STYLE);
|
||||
|
Reference in New Issue
Block a user