]>
git.saurik.com Git - wxWidgets.git/blob - interface/wx/textwrapper.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/textwrapper.h
3 // Purpose: documentation of wxTextWrapper interface
4 // Author: Vadim Zeitlin
5 // Copyright: (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
12 Helps wrap lines of text to given width.
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
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:
24 wxString WrapText(wxWindow *win, const wxString& text, int widthMax)
26 class HardBreakWrapper : public wxTextWrapper
29 HardBreakWrapper(wxWindow *win, const wxString& text, int widthMax)
31 Wrap(win, text, widthMax);
34 wxString const& GetWrapped() const { return m_wrapped; }
37 virtual void OnOutputLine(const wxString& line)
42 virtual void OnNewLine()
51 HardBreakWrapper wrapper(win, text, widthMax);
52 return wrapper.GetWrapped();
63 Trivial default constructor.
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).
76 A non-@NULL window used for measuring the text extents.
80 Maximal width of each line of text or @c -1 to disable wrapping.
82 void Wrap(wxWindow
*win
, const wxString
& text
, int widthMax
);
86 Called by Wrap() for each wrapped line of text.
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.
91 virtual void OnOutputLine(const wxString
& line
) = 0;
94 Called at the start of each subsequent line of text by Wrap().
96 This method may not be called at all if the entire text passed to
97 Wrap() fits into the specified width.
99 virtual void OnNewLine();