]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/textwrapper.h
added a note about XRCID() and EVT_*_RANGE macros (see bug #11431)
[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>
7// Licence: wxWindows license
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:
23 @code
24wxString WrapText(wxWindow *win, const wxString& text, int widthMax)
25{
26 class HardBreakWrapper : public wxTextWrapper
27 {
28 public:
29 HardBreakWrapper(wxWindow *win, const wxString& text, int widthMax)
30 {
31 Wrap(win, text, widthMax);
32 }
33
34 wxString const& GetWrapped() const { return m_wrapped; }
35
36 protected:
37 virtual void OnOutputLine(const wxString& line)
38 {
39 m_wrapped += line;
40 }
41
42 virtual void OnNewLine()
43 {
44 m_wrapped += '\n';
45 }
46
47 private:
48 wxString m_wrapped;
49 };
50
51 HardBreakWrapper wrapper(win, text, widthMax);
52 return wrapper.GetWrapped();
53}
54 @endcode
55
56 @library{none}
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};