1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/private/textmeasure.h
3 // Purpose: declaration of wxTextMeasure class
4 // Author: Manuel Martin
6 // Copyright: (c) 1997-2012 wxWidgets team
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
10 #ifndef _WX_PRIVATE_TEXTMEASURE_H_
11 #define _WX_PRIVATE_TEXTMEASURE_H_
13 #include "wx/vector.h"
15 class WXDLLIMPEXP_FWD_CORE wxDC
;
16 class WXDLLIMPEXP_FWD_CORE wxFont
;
17 class WXDLLIMPEXP_FWD_CORE wxWindow
;
19 // ----------------------------------------------------------------------------
20 // wxTextMeasure: class used to measure text extent.
21 // ----------------------------------------------------------------------------
23 class wxTextMeasureBase
26 // The first ctor argument must be non-NULL, i.e. each object of this class
27 // is associated with either a valid wxDC or a valid wxWindow.
28 wxTextMeasureBase(const wxDC
*dc
, const wxFont
*theFont
);
29 wxTextMeasureBase(const wxWindow
*win
, const wxFont
*theFont
);
31 // Even though this class is not supposed to be used polymorphically, give
32 // it a virtual dtor to avoid compiler warnings.
33 virtual ~wxTextMeasureBase() { }
36 // Return the extent of a single line string.
37 void GetTextExtent(const wxString
& string
,
40 wxCoord
*descent
= NULL
,
41 wxCoord
*externalLeading
= NULL
);
43 // The same for a multiline (with '\n') string.
44 void GetMultiLineTextExtent(const wxString
& text
,
47 wxCoord
*heightOneLine
= NULL
);
49 // Find the dimensions of the largest string.
50 void GetLargestStringExtent(const wxVector
<wxString
>& strings
,
54 // Fill the array with the widths for each "0..N" substrings for N from 1
57 // The scaleX argument is the horizontal scale used by wxDC and is only
58 // used in the generic implementation.
59 bool GetPartialTextExtents(const wxString
& text
,
64 // These functions are called by our public methods before and after each
65 // call to DoGetTextExtent(). Derived classes may override them to prepare
66 // for -- possibly several -- subsequent calls to DoGetTextExtent().
68 // As these calls must be always paired, they're never called directly but
69 // only by our friend MeasuringGuard class.
70 virtual void BeginMeasuring() { }
71 virtual void EndMeasuring() { }
73 friend class MeasuringGuard
;
75 // RAII wrapper for the two methods above.
79 MeasuringGuard(wxTextMeasureBase
& tm
) : m_tm(tm
)
81 m_tm
.BeginMeasuring();
90 wxTextMeasureBase
& m_tm
;
94 // The main function of this class, to be implemented in platform-specific
95 // way used by all our public methods except GetLargestStringExtents().
97 // The width and height pointers here are never NULL and the input string
99 virtual void DoGetTextExtent(const wxString
& string
,
102 wxCoord
*descent
= NULL
,
103 wxCoord
*externalLeading
= NULL
) = 0;
105 // The real implementation of GetPartialTextExtents().
107 // On input, widths array contains text.length() zero elements and the text
108 // is guaranteed to be non-empty.
109 virtual bool DoGetPartialTextExtents(const wxString
& text
,
114 // Exactly one of m_dc and m_win is non-NULL for any given object of this
116 const wxDC
* const m_dc
;
117 const wxWindow
* const m_win
;
119 // This one can be NULL or not.
120 const wxFont
* const m_font
;
122 wxDECLARE_NO_COPY_CLASS(wxTextMeasureBase
);
125 // Include the platform dependant class declaration, if any.
126 #if defined(__WXGTK20__)
127 #include "wx/gtk/private/textmeasure.h"
128 #elif defined(__WXMSW__)
129 #include "wx/msw/private/textmeasure.h"
130 #else // no platform-specific implementation of wxTextMeasure yet
131 #include "wx/generic/private/textmeasure.h"
133 #define wxUSE_GENERIC_TEXTMEASURE 1
136 #ifndef wxUSE_GENERIC_TEXTMEASURE
137 #define wxUSE_GENERIC_TEXTMEASURE 0
140 #endif // _WX_PRIVATE_TEXTMEASURE_H_