]>
git.saurik.com Git - wxWidgets.git/blob - interface/wx/textwrapper.h
067ff781f9202ccd4d0f80df5a5e7a34e8799b1c
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/textwrapper.h
3 // Purpose: documentation of wxTextWrapper interface
4 // Author: Vadim Zeitlin
6 // Copyright: (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
13 Helps wrap lines of text to given width.
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
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:
25 wxString WrapText(wxWindow *win, const wxString& text, int widthMax)
27 class HardBreakWrapper : public wxTextWrapper
30 HardBreakWrapper(wxWindow *win, const wxString& text, int widthMax)
32 Wrap(win, text, widthMax);
35 wxString const& GetWrapped() const { return m_wrapped; }
38 virtual void OnOutputLine(const wxString& line)
43 virtual void OnNewLine()
52 HardBreakWrapper wrapper(win, text, widthMax);
53 return wrapper.GetWrapped();
64 Trivial default constructor.
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).
77 A non-@NULL window used for measuring the text extents.
81 Maximal width of each line of text or @c -1 to disable wrapping.
83 void Wrap(wxWindow
*win
, const wxString
& text
, int widthMax
);
87 Called by Wrap() for each wrapped line of text.
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.
92 virtual void OnOutputLine(const wxString
& line
) = 0;
95 Called at the start of each subsequent line of text by Wrap().
97 This method may not be called at all if the entire text passed to
98 Wrap() fits into the specified width.
100 virtual void OnNewLine();