]> git.saurik.com Git - wxWidgets.git/blame - include/wx/textwrapper.h
Return the old file descriptor/pointer from wx(F)File::Detach().
[wxWidgets.git] / include / wx / textwrapper.h
CommitLineData
255c07b4
VZ
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)
255c07b4
VZ
6// Copyright: (c) 1999, 2009 Vadim Zeitlin <vadim@wxwidgets.org>
7// Licence: wxWindows licence
8///////////////////////////////////////////////////////////////////////////////
9
10#ifndef _WX_TEXTWRAPPER_H_
11#define _WX_TEXTWRAPPER_H_
12
715c9810
RR
13#include "wx/window.h"
14
255c07b4
VZ
15// ----------------------------------------------------------------------------
16// wxTextWrapper
17// ----------------------------------------------------------------------------
18
19// this class is used to wrap the text on word boundary: wrapping is done by
20// calling OnStartLine() and OnOutputLine() functions
ed703645 21class WXDLLIMPEXP_CORE wxTextWrapper
255c07b4
VZ
22{
23public:
24 wxTextWrapper() { m_eol = false; }
25
26 // win is used for getting the font, text is the text to wrap, width is the
27 // max line width or -1 to disable wrapping
28 void Wrap(wxWindow *win, const wxString& text, int widthMax);
29
30 // we don't need it, but just to avoid compiler warnings
31 virtual ~wxTextWrapper() { }
32
33protected:
34 // line may be empty
35 virtual void OnOutputLine(const wxString& line) = 0;
36
37 // called at the start of every new line (except the very first one)
38 virtual void OnNewLine() { }
39
40private:
41 // call OnOutputLine() and set m_eol to true
42 void DoOutputLine(const wxString& line)
43 {
44 OnOutputLine(line);
45
46 m_eol = true;
47 }
48
49 // this function is a destructive inspector: when it returns true it also
50 // resets the flag to false so calling it again wouldn't return true any
51 // more
52 bool IsStartOfNewLine()
53 {
54 if ( !m_eol )
55 return false;
56
57 m_eol = false;
58
59 return true;
60 }
61
62
63 bool m_eol;
64
65 wxDECLARE_NO_COPY_CLASS(wxTextWrapper);
66};
67
c79510ca
VZ
68#if wxUSE_STATTEXT
69
70#include "wx/sizer.h"
71#include "wx/stattext.h"
72
73// A class creating a sizer with one static text per line of text. Creation of
74// the controls used for each line can be customized by overriding
75// OnCreateLine() function.
76//
77// This class is currently private to wxWidgets and used only by wxDialog
78// itself. We may make it public later if there is sufficient interest.
79class wxTextSizerWrapper : public wxTextWrapper
80{
81public:
82 wxTextSizerWrapper(wxWindow *win)
83 {
84 m_win = win;
85 m_hLine = 0;
86 }
87
88 wxSizer *CreateSizer(const wxString& text, int widthMax)
89 {
90 m_sizer = new wxBoxSizer(wxVERTICAL);
91 Wrap(m_win, text, widthMax);
92 return m_sizer;
93 }
94
95 wxWindow *GetParent() const { return m_win; }
96
97protected:
98 virtual wxWindow *OnCreateLine(const wxString& line)
99 {
7e57c904
VZ
100 return new wxStaticText(m_win, wxID_ANY,
101 wxControl::EscapeMnemonics(line));
c79510ca
VZ
102 }
103
104 virtual void OnOutputLine(const wxString& line)
105 {
106 if ( !line.empty() )
107 {
108 m_sizer->Add(OnCreateLine(line));
109 }
110 else // empty line, no need to create a control for it
111 {
112 if ( !m_hLine )
113 m_hLine = m_win->GetCharHeight();
114
115 m_sizer->Add(5, m_hLine);
116 }
117 }
118
119private:
120 wxWindow *m_win;
121 wxSizer *m_sizer;
122 int m_hLine;
123};
124
125#endif // wxUSE_STATTEXT
126
255c07b4
VZ
127#endif // _WX_TEXTWRAPPER_H_
128