]> git.saurik.com Git - wxWidgets.git/blame - include/wx/textwrapper.h
Fix assert when destroying wxDataViewCtrl being edited in wxGTK.
[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)
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
715c9810
RR
14#include "wx/window.h"
15
255c07b4
VZ
16// ----------------------------------------------------------------------------
17// wxTextWrapper
18// ----------------------------------------------------------------------------
19
20// this class is used to wrap the text on word boundary: wrapping is done by
21// calling OnStartLine() and OnOutputLine() functions
ed703645 22class WXDLLIMPEXP_CORE wxTextWrapper
255c07b4
VZ
23{
24public:
25 wxTextWrapper() { m_eol = false; }
26
27 // win is used for getting the font, text is the text to wrap, width is the
28 // max line width or -1 to disable wrapping
29 void Wrap(wxWindow *win, const wxString& text, int widthMax);
30
31 // we don't need it, but just to avoid compiler warnings
32 virtual ~wxTextWrapper() { }
33
34protected:
35 // line may be empty
36 virtual void OnOutputLine(const wxString& line) = 0;
37
38 // called at the start of every new line (except the very first one)
39 virtual void OnNewLine() { }
40
41private:
42 // call OnOutputLine() and set m_eol to true
43 void DoOutputLine(const wxString& line)
44 {
45 OnOutputLine(line);
46
47 m_eol = true;
48 }
49
50 // this function is a destructive inspector: when it returns true it also
51 // resets the flag to false so calling it again wouldn't return true any
52 // more
53 bool IsStartOfNewLine()
54 {
55 if ( !m_eol )
56 return false;
57
58 m_eol = false;
59
60 return true;
61 }
62
63
64 bool m_eol;
65
66 wxDECLARE_NO_COPY_CLASS(wxTextWrapper);
67};
68
c79510ca
VZ
69#if wxUSE_STATTEXT
70
71#include "wx/sizer.h"
72#include "wx/stattext.h"
73
74// A class creating a sizer with one static text per line of text. Creation of
75// the controls used for each line can be customized by overriding
76// OnCreateLine() function.
77//
78// This class is currently private to wxWidgets and used only by wxDialog
79// itself. We may make it public later if there is sufficient interest.
80class wxTextSizerWrapper : public wxTextWrapper
81{
82public:
83 wxTextSizerWrapper(wxWindow *win)
84 {
85 m_win = win;
86 m_hLine = 0;
87 }
88
89 wxSizer *CreateSizer(const wxString& text, int widthMax)
90 {
91 m_sizer = new wxBoxSizer(wxVERTICAL);
92 Wrap(m_win, text, widthMax);
93 return m_sizer;
94 }
95
96 wxWindow *GetParent() const { return m_win; }
97
98protected:
99 virtual wxWindow *OnCreateLine(const wxString& line)
100 {
101 return new wxStaticText(m_win, wxID_ANY, line);
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