~ubuntu-branches/ubuntu/maverick/wxwidgets2.8/maverick-proposed

« back to all changes in this revision

Viewing changes to samples/richtext/richtext.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Devid Filoni
  • Date: 2008-06-30 22:02:17 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20080630220217-vag3tkfp91t0453d
Tags: 2.8.8.0-0ubuntu1
* New upstream version, based on the upstream tarball
  wxPython-src-2.8.8.0.tar.bz2, remove upstream debian dir (LP: #244355).
* Add debian/watch file, LP: #242164.
* Edit get-orig-source target to provide a .orig.tar.gz with the same md5 for
  each .orig.tar.gz generated.
* debian/rules: remove get-orig-source from .PHONY target.
* debian/control.in: add python-wxtools in python-wxgtk=V=U Suggests field.
* Do not apply fix_from_upstream_svn_r52465 patch, not needed.
* Regenerate octave_oct, tcl_tk_tcl patches for the new version.
* Fix spelling-error-in-description lintian warning.
* Fix depends-on-obsolete-package lintian error.
* Fix executable-not-elf-or-script lintian warnings.
* Fix script-not-executable lintian warnings.
* Fix missing-dependency-on-libc lintian error.
* Fix dbg-package-missing-depends lintian warnings.
* Fix package-contains-empty-directory lintian warnings.
* Fix manpage-has-errors-from-man lintian warning.
* Fix image-file-in-usr-lib lintian warnings:
  - add editra_pixmaps patch
  - add xrced_bitmaps patch
* Fix unused-override lintian info.
* Fix malformed-override lintian errors.
* Fix extra-license-file lintian warnings.
* Install upstream wx.pth instead of generated file links (LP: #211553).
* Add editra.png, pyshell.png (encoded using uuencode) icons, LP: #236876:
  - debian/rules: use uudecode to decode .png icons.
* Add a new pyshell.xpm icon.
* Fix doc-base-file-references-missing-file lintian error.
* Fix doc-base-unknown-section lintian warning.
* Fix ruby-script-but-no-ruby-dep lintian errors.
* Fix wish-script-but-no-wish-dep lintian errors.
* Fix missing-dep-for-interpreter errors.
* Bump Standards-Version to 3.8.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
// Author:      Julian Smart
5
5
// Modified by:
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);
168
168
 
 
169
    void OnReload(wxCommandEvent& event);
 
170
 
169
171
    void OnViewHTML(wxCommandEvent& event);
170
172
 
171
173
    void OnSwitchStyleSheets(wxCommandEvent& event);
182
184
    // Forward command events to the current rich text control, if any
183
185
    bool ProcessEvent(wxEvent& event);
184
186
 
 
187
    // Write text
 
188
    void WriteInitialText();
 
189
 
185
190
private:
186
191
    // any class wishing to process wxWidgets events must use this macro
187
192
    DECLARE_EVENT_TABLE()
207
212
    ID_FORMAT_PARAGRAPH,
208
213
    ID_FORMAT_CONTENT,
209
214
 
 
215
    ID_RELOAD,
 
216
 
210
217
    ID_INSERT_SYMBOL,
211
218
    ID_INSERT_URL,
212
219
 
292
299
    EVT_MENU(ID_FORMAT_PARAGRAPH_SPACING_MORE,  MyFrame::OnParagraphSpacingMore)
293
300
    EVT_MENU(ID_FORMAT_PARAGRAPH_SPACING_LESS,  MyFrame::OnParagraphSpacingLess)
294
301
 
 
302
    EVT_MENU(ID_RELOAD,  MyFrame::OnReload)
 
303
 
295
304
    EVT_MENU(ID_INSERT_SYMBOL,  MyFrame::OnInsertSymbol)
296
305
    EVT_MENU(ID_INSERT_URL,  MyFrame::OnInsertURL)
297
306
 
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();
716
727
 
 
728
    WriteInitialText();
 
729
}
 
730
 
 
731
// Write text
 
732
void MyFrame::WriteInitialText()
 
733
{
717
734
    wxRichTextCtrl& r = *m_richTextCtrl;
718
735
 
 
736
    r.SetDefaultStyle(wxRichTextAttr());
 
737
 
719
738
    r.BeginSuppressUndo();
720
739
 
721
740
    r.BeginParagraphSpacing(0, 20);
727
746
 
728
747
    wxString lineBreak = (wxChar) 29;
729
748
 
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"));
731
750
    r.EndFontSize();
732
 
    r.Newline();
 
751
    //r.Newline();
733
752
 
734
753
    r.BeginItalic();
735
754
    r.WriteText(wxT("by Julian Smart"));
740
759
 
741
760
    r.WriteImage(wxBitmap(zebra_xpm));
742
761
 
 
762
    r.Newline();
 
763
    r.Newline();
 
764
 
743
765
    r.EndAlignment();
744
766
 
745
 
    r.Newline();
746
 
    r.Newline();
747
 
 
748
767
    r.WriteText(wxT("What can you do with this thing? "));
749
768
 
750
769
    r.WriteImage(wxBitmap(smiley_xpm));
778
797
 
779
798
    r.WriteText(wxT(" Next we'll show an indented paragraph."));
780
799
 
 
800
    r.Newline();
 
801
 
781
802
    r.BeginLeftIndent(60);
782
 
    r.Newline();
783
 
 
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."));
 
804
    r.Newline();
 
805
 
785
806
    r.EndLeftIndent();
786
807
 
787
 
    r.Newline();
788
 
 
789
808
    r.WriteText(wxT("Next, we'll show a first-line indent, achieved using BeginLeftIndent(100, -40)."));
790
809
 
 
810
    r.Newline();
 
811
 
791
812
    r.BeginLeftIndent(100, -40);
792
 
    r.Newline();
793
813
 
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."));
 
815
    r.Newline();
 
816
 
795
817
    r.EndLeftIndent();
796
818
 
797
 
    r.Newline();
798
 
 
799
819
    r.WriteText(wxT("Numbered bullets are possible, again using subindents:"));
 
820
    r.Newline();
800
821
 
801
822
    r.BeginNumberedBullet(1, 100, 60);
802
 
    r.Newline();
803
 
 
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."));
 
824
    r.Newline();
 
825
 
805
826
    r.EndNumberedBullet();
806
827
 
807
828
    r.BeginNumberedBullet(2, 100, 60);
808
 
    r.Newline();
809
 
 
810
829
    r.WriteText(wxT("This is my second item."));
 
830
    r.Newline();
 
831
 
811
832
    r.EndNumberedBullet();
812
833
 
813
 
    r.Newline();
814
 
 
815
834
    r.WriteText(wxT("The following paragraph is right-indented:"));
 
835
    r.Newline();
816
836
 
817
837
    r.BeginRightIndent(200);
 
838
 
 
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."));
818
840
    r.Newline();
819
841
 
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();
822
843
 
823
 
    r.Newline();
824
 
 
825
844
    r.WriteText(wxT("The following paragraph is right-aligned with 1.5 line spacing:"));
 
845
    r.Newline();
826
846
 
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."));
829
850
    r.Newline();
830
 
 
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();
834
853
 
842
861
    attr.SetTabs(tabs);
843
862
    r.SetDefaultStyle(attr);
844
863
 
845
 
    r.Newline();
846
864
    r.WriteText(wxT("This line contains tabs:\tFirst tab\tSecond tab\tThird tab"));
 
865
    r.Newline();
847
866
 
848
 
    r.Newline();
849
867
    r.WriteText(wxT("Other notable features of wxRichTextCtrl include:"));
 
868
    r.Newline();
850
869
 
851
870
    r.BeginSymbolBullet(wxT('*'), 100, 60);
852
 
    r.Newline();
853
871
    r.WriteText(wxT("Compatibility with wxTextCtrl API"));
 
872
    r.Newline();
854
873
    r.EndSymbolBullet();
855
874
 
856
875
    r.BeginSymbolBullet(wxT('*'), 100, 60);
857
 
    r.Newline();
858
876
    r.WriteText(wxT("Easy stack-based BeginXXX()...EndXXX() style setting in addition to SetStyle()"));
 
877
    r.Newline();
859
878
    r.EndSymbolBullet();
860
879
 
861
880
    r.BeginSymbolBullet(wxT('*'), 100, 60);
862
 
    r.Newline();
863
881
    r.WriteText(wxT("XML loading and saving"));
 
882
    r.Newline();
864
883
    r.EndSymbolBullet();
865
884
 
866
885
    r.BeginSymbolBullet(wxT('*'), 100, 60);
867
 
    r.Newline();
868
886
    r.WriteText(wxT("Undo/Redo, with batching option and Undo suppressing"));
 
887
    r.Newline();
869
888
    r.EndSymbolBullet();
870
889
 
871
890
    r.BeginSymbolBullet(wxT('*'), 100, 60);
872
 
    r.Newline();
873
891
    r.WriteText(wxT("Clipboard copy and paste"));
 
892
    r.Newline();
874
893
    r.EndSymbolBullet();
875
894
 
876
895
    r.BeginSymbolBullet(wxT('*'), 100, 60);
877
 
    r.Newline();
878
896
    r.WriteText(wxT("wxRichTextStyleSheet with named character and paragraph styles, and control for applying named styles"));
 
897
    r.Newline();
879
898
    r.EndSymbolBullet();
880
899
 
881
900
    r.BeginSymbolBullet(wxT('*'), 100, 60);
882
 
    r.Newline();
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"));
 
902
    r.Newline();
884
903
    r.EndSymbolBullet();
885
904
 
886
 
    r.Newline();
887
 
 
888
905
    // Make a style suitable for showing a URL
889
906
    wxRichTextAttr urlStyle;
890
907
    urlStyle.SetTextColour(*wxBLUE);
902
919
 
903
920
    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!"));
904
921
 
 
922
    r.Newline();
 
923
 
905
924
    r.EndParagraphSpacing();
906
925
 
907
926
    r.EndSuppressUndo();
1310
1329
    }
1311
1330
}
1312
1331
 
 
1332
void MyFrame::OnReload(wxCommandEvent& WXUNUSED(event))
 
1333
{
 
1334
    m_richTextCtrl->Clear();
 
1335
    WriteInitialText();
 
1336
}
 
1337
 
1313
1338
void MyFrame::OnViewHTML(wxCommandEvent& WXUNUSED(event))
1314
1339
{
1315
1340
    wxDialog dialog(this, wxID_ANY, _("HTML"), wxDefaultPosition, wxSize(500, 400), wxDEFAULT_DIALOG_STYLE);