extracted wxTextWrapper in its own header and made it public
[wxWidgets.git] / include / wx / textwrapper.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/textwrapper.h
3 // Purpose: declaration of wxTextWrapper class
4 // Author: Vadim Zeitlin
5 // Created: 2009-05-31 (extracted from dlgcmn.cpp via wx/private/stattext.h)
6 // RCS-ID: $Id$
7 // Copyright: (c) 1999, 2009 Vadim Zeitlin <vadim@wxwidgets.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_TEXTWRAPPER_H_
12 #define _WX_TEXTWRAPPER_H_
13
14 // ----------------------------------------------------------------------------
15 // wxTextWrapper
16 // ----------------------------------------------------------------------------
17
18 // this class is used to wrap the text on word boundary: wrapping is done by
19 // calling OnStartLine() and OnOutputLine() functions
20 class wxTextWrapper
21 {
22 public:
23 wxTextWrapper() { m_eol = false; }
24
25 // win is used for getting the font, text is the text to wrap, width is the
26 // max line width or -1 to disable wrapping
27 void Wrap(wxWindow *win, const wxString& text, int widthMax);
28
29 // we don't need it, but just to avoid compiler warnings
30 virtual ~wxTextWrapper() { }
31
32 protected:
33 // line may be empty
34 virtual void OnOutputLine(const wxString& line) = 0;
35
36 // called at the start of every new line (except the very first one)
37 virtual void OnNewLine() { }
38
39 private:
40 // call OnOutputLine() and set m_eol to true
41 void DoOutputLine(const wxString& line)
42 {
43 OnOutputLine(line);
44
45 m_eol = true;
46 }
47
48 // this function is a destructive inspector: when it returns true it also
49 // resets the flag to false so calling it again wouldn't return true any
50 // more
51 bool IsStartOfNewLine()
52 {
53 if ( !m_eol )
54 return false;
55
56 m_eol = false;
57
58 return true;
59 }
60
61
62 bool m_eol;
63
64 wxDECLARE_NO_COPY_CLASS(wxTextWrapper);
65 };
66
67 #endif // _WX_TEXTWRAPPER_H_
68