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 // RAII wrapper for the two methods above.
77 MeasuringGuard(wxTextMeasureBase
& tm
) : m_tm(tm
)
79 m_tm
.BeginMeasuring();
88 wxTextMeasureBase
& m_tm
;
92 // The main function of this class, to be implemented in platform-specific
93 // way used by all our public methods except GetLargestStringExtents().
95 // The width and height pointers here are never NULL and the input string
97 virtual void DoGetTextExtent(const wxString
& string
,
100 wxCoord
*descent
= NULL
,
101 wxCoord
*externalLeading
= NULL
) = 0;
103 // The real implementation of GetPartialTextExtents().
105 // On input, widths array contains text.length() zero elements and the text
106 // is guaranteed to be non-empty.
107 virtual bool DoGetPartialTextExtents(const wxString
& text
,
112 // Exactly one of m_dc and m_win is non-NULL for any given object of this
114 const wxDC
* const m_dc
;
115 const wxWindow
* const m_win
;
117 // This one can be NULL or not.
118 const wxFont
* const m_font
;
120 wxDECLARE_NO_COPY_CLASS(wxTextMeasureBase
);
123 // Include the platform dependant class declaration, if any.
124 #if defined(__WXGTK20__)
125 #include "wx/gtk/private/textmeasure.h"
126 #elif defined(__WXMSW__)
127 #include "wx/msw/private/textmeasure.h"
128 #else // no platform-specific implementation of wxTextMeasure yet
129 #include "wx/generic/private/textmeasure.h"
131 #define wxUSE_GENERIC_TEXTMEASURE 1
134 #ifndef wxUSE_GENERIC_TEXTMEASURE
135 #define wxUSE_GENERIC_TEXTMEASURE 0
138 #endif // _WX_PRIVATE_TEXTMEASURE_H_