]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/textwrapper.h
Try native method first in LoadFile() and SaveFile()
[wxWidgets.git] / interface / wx / textwrapper.h
CommitLineData
255c07b4
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: wx/textwrapper.h
3// Purpose: documentation of wxTextWrapper interface
4// Author: Vadim Zeitlin
255c07b4 5// Copyright: (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
526954c5 6// Licence: wxWindows licence
255c07b4
VZ
7/////////////////////////////////////////////////////////////////////////////
8
9/**
10 @class wxTextWrapper
11
12 Helps wrap lines of text to given width.
13
14 This is a generic purpose class which can be used to wrap lines of text to
15 the specified width. It doesn't do anything by itself but simply calls its
16 virtual OnOutputLine() and OnNewLine() methods for each wrapped line of
17 text, you need to implement them in your derived class to actually do
18 something useful.
19
20 Here is an example function using this class which inserts hard line breaks
21 into a string of text at the positions where it would be wrapped:
163bd4f7 22
255c07b4 23 @code
163bd4f7 24 wxString WrapText(wxWindow *win, const wxString& text, int widthMax)
255c07b4 25 {
163bd4f7 26 class HardBreakWrapper : public wxTextWrapper
255c07b4 27 {
163bd4f7
FM
28 public:
29 HardBreakWrapper(wxWindow *win, const wxString& text, int widthMax)
30 {
31 Wrap(win, text, widthMax);
32 }
255c07b4 33
163bd4f7 34 wxString const& GetWrapped() const { return m_wrapped; }
255c07b4 35
163bd4f7
FM
36 protected:
37 virtual void OnOutputLine(const wxString& line)
38 {
39 m_wrapped += line;
40 }
255c07b4 41
163bd4f7
FM
42 virtual void OnNewLine()
43 {
44 m_wrapped += '\n';
45 }
255c07b4 46
163bd4f7
FM
47 private:
48 wxString m_wrapped;
49 };
255c07b4 50
163bd4f7
FM
51 HardBreakWrapper wrapper(win, text, widthMax);
52 return wrapper.GetWrapped();
53 }
255c07b4
VZ
54 @endcode
55
163bd4f7 56 @nolibrary
255c07b4
VZ
57 @category{gdi}
58 */
59class wxTextWrapper
60{
61public:
62 /**
63 Trivial default constructor.
64 */
65 wxTextWrapper();
66
67 /**
68 Wrap the given text.
69
70 This method will call OnOutputLine() for every line of wrapped text and
71 OnNewLine() before the beginning of every new line after the first one
72 (so it might be never called at all if the width of entire @a text is
73 less than @a widthMax).
74
75 @param win
76 A non-@NULL window used for measuring the text extents.
77 @param text
78 The text to wrap.
79 @param widthMax
80 Maximal width of each line of text or @c -1 to disable wrapping.
81 */
82 void Wrap(wxWindow *win, const wxString& text, int widthMax);
83
84protected:
85 /**
86 Called by Wrap() for each wrapped line of text.
87
88 This method will always be called at least once by Wrap(). Notice that
89 @a line may be empty if the text passed to Wrap() was empty itself.
90 */
91 virtual void OnOutputLine(const wxString& line) = 0;
92
93 /**
94 Called at the start of each subsequent line of text by Wrap().
95
96 This method may not be called at all if the entire text passed to
97 Wrap() fits into the specified width.
98 */
99 virtual void OnNewLine();
100};