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