X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9a173d48f7669836759c922644b451bc4e8db503..67a083dd38d1ad1df8c6a25a58bb2f0ec4f3a936:/samples/richtext/richtext.cpp diff --git a/samples/richtext/richtext.cpp b/samples/richtext/richtext.cpp index 115d7106a4..e0a9968d1e 100644 --- a/samples/richtext/richtext.cpp +++ b/samples/richtext/richtext.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: richedit.cpp +// Name: samples/richtext/richtext.cpp // Purpose: wxWidgets rich text editor sample // Author: Julian Smart // Modified by: @@ -35,7 +35,10 @@ #include "wx/sstream.h" #include "wx/html/htmlwin.h" -#include "bitmaps/sample.xpm" +#ifndef __WXMSW__ + #include "../sample.xpm" +#endif + #include "bitmaps/smiley.xpm" // #include "bitmaps/idea.xpm" #include "bitmaps/zebra.xpm" @@ -61,6 +64,7 @@ #include "wx/richtext/richtextctrl.h" #include "wx/richtext/richtextstyles.h" #include "wx/richtext/richtextxml.h" +#include "wx/richtext/richtexthtml.h" // ---------------------------------------------------------------------------- // resources @@ -263,7 +267,7 @@ bool MyApp::OnInit() #endif // create the main application window - MyFrame *frame = new MyFrame(_T("wxRichTextCtrl Sample"), wxID_ANY, wxDefaultPosition, wxSize(600, 500)); + MyFrame *frame = new MyFrame(_T("wxRichTextCtrl Sample"), wxID_ANY, wxDefaultPosition, wxSize(700, 600)); // and show it (the frames, unlike simple controls, are not shown when // created initially) @@ -311,6 +315,20 @@ void MyApp::CreateStyles() m_styleSheet->AddParagraphStyle(indentedPara); + wxRichTextParagraphStyleDefinition* indentedPara2 = new wxRichTextParagraphStyleDefinition(wxT("Red Bold Indented")); + wxRichTextAttr indentedAttr2; + indentedAttr2.SetFontFaceName(romanFont.GetFaceName()); + indentedAttr2.SetFontSize(12); + indentedAttr2.SetFontWeight(wxBOLD); + indentedAttr2.SetTextColour(*wxRED); + indentedAttr2.SetFontSize(12); + indentedAttr2.SetLeftIndent(100, 0); + // We want to affect indentation, font and text colour + indentedAttr2.SetFlags(wxTEXT_ATTR_LEFT_INDENT|wxTEXT_ATTR_RIGHT_INDENT|wxTEXT_ATTR_FONT|wxTEXT_ATTR_TEXT_COLOUR); + indentedPara2->SetStyle(indentedAttr2); + + m_styleSheet->AddParagraphStyle(indentedPara2); + wxRichTextParagraphStyleDefinition* flIndentedPara = new wxRichTextParagraphStyleDefinition(wxT("First Line Indented")); wxRichTextAttr flIndentedAttr; flIndentedAttr.SetFontFaceName(swissFont.GetFaceName()); @@ -369,7 +387,7 @@ MyFrame::MyFrame(const wxString& title, wxWindowID id, const wxPoint& pos, : wxFrame(NULL, id, title, pos, size, style) { // set the frame icon - SetIcon(sample_xpm); + SetIcon(wxICON(sample)); // create a menu bar wxMenu *fileMenu = new wxMenu; @@ -436,9 +454,15 @@ MyFrame::MyFrame(const wxString& title, wxWindowID id, const wxPoint& pos, SetMenuBar(menuBar); // create a status bar just for fun (by default with 1 pane only) + // but don't create it on limited screen space (WinCE) + bool is_pda = wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA; + #if wxUSE_STATUSBAR - CreateStatusBar(2); - SetStatusText(_T("Welcome to wxRichTextCtrl!")); + if ( !is_pda ) + { + CreateStatusBar(2); + SetStatusText(_T("Welcome to wxRichTextCtrl!")); + } #endif wxToolBar* toolBar = CreateToolBar(); @@ -466,6 +490,9 @@ MyFrame::MyFrame(const wxString& title, wxWindowID id, const wxPoint& pos, toolBar->AddSeparator(); toolBar->AddTool(ID_FORMAT_FONT, wxBitmap(font_xpm), wxNullBitmap, false, -1, -1, (wxObject *) NULL, _("Font")); + wxRichTextStyleComboCtrl* combo = new wxRichTextStyleComboCtrl(toolBar, wxID_ANY, wxDefaultPosition, wxSize(200, -1)); + toolBar->AddControl(combo); + toolBar->Realize(); wxSplitterWindow* splitter = new wxSplitterWindow(this, wxID_ANY, wxDefaultPosition, GetClientSize(), wxSP_NO_XP_THEME|wxSP_3D|wxSP_LIVE_UPDATE); @@ -474,16 +501,26 @@ MyFrame::MyFrame(const wxString& title, wxWindowID id, const wxPoint& pos, wxFont boldFont = wxFont(12, wxROMAN, wxNORMAL, wxBOLD); wxFont italicFont = wxFont(12, wxROMAN, wxITALIC, wxNORMAL); - m_richTextCtrl = new wxRichTextCtrl(splitter, wxID_ANY, wxDefaultPosition, wxSize(200, 200), wxVSCROLL|wxHSCROLL|wxNO_BORDER); + m_richTextCtrl = new wxRichTextCtrl(splitter, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(200, 200), wxVSCROLL|wxHSCROLL|wxNO_BORDER|wxWANTS_CHARS); wxFont font(12, wxROMAN, wxNORMAL, wxNORMAL); -#ifdef __WXMAC__ - font.SetNoAntiAliasing(true); -#endif m_richTextCtrl->SetFont(font); + combo->SetStyleSheet(wxGetApp().GetStyleSheet()); + combo->SetRichTextCtrl(m_richTextCtrl); + combo->UpdateStyles(); + wxRichTextStyleListBox* styleListBox = new wxRichTextStyleListBox(splitter, wxID_ANY); - splitter->SplitVertically(m_richTextCtrl, styleListBox, 400); + + wxSize display = wxGetDisplaySize(); + if ( is_pda && ( display.GetWidth() < display.GetHeight() ) ) + { + splitter->SplitHorizontally(m_richTextCtrl, styleListBox); + } + else + { + splitter->SplitVertically(m_richTextCtrl, styleListBox, 500); + } splitter->UpdateSize(); @@ -602,6 +639,19 @@ MyFrame::MyFrame(const wxString& title, wxWindowID id, const wxPoint& pos, r.EndLineSpacing(); r.EndAlignment(); + wxArrayInt tabs; + tabs.Add(400); + tabs.Add(600); + tabs.Add(800); + tabs.Add(1000); + 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:")); @@ -720,7 +770,7 @@ void MyFrame::OnOpen(wxCommandEvent& WXUNUSED(event)) path, filename, filter, - wxOPEN); + wxFD_OPEN); if (dialog.ShowModal() == wxID_OK) { @@ -728,12 +778,10 @@ void MyFrame::OnOpen(wxCommandEvent& WXUNUSED(event)) if (!path.empty()) { - int fileType = 0; int filterIndex = dialog.GetFilterIndex(); - if (filterIndex < (int) fileTypes.GetCount()) - fileType = fileTypes[filterIndex]; - else - fileType = wxRICHTEXT_TYPE_TEXT; + int fileType = (filterIndex < (int) fileTypes.GetCount()) + ? fileTypes[filterIndex] + : wxRICHTEXT_TYPE_TEXT; m_richTextCtrl->LoadFile(path, fileType); } } @@ -760,7 +808,7 @@ void MyFrame::OnSaveAs(wxCommandEvent& WXUNUSED(event)) path, filename, filter, - wxSAVE); + wxFD_SAVE); if (dialog.ShowModal() == wxID_OK) {