]> git.saurik.com Git - wxWidgets.git/blob - include/wx/private/textmeasure.h
Add missing WXK constants for the control keys
[wxWidgets.git] / include / wx / private / textmeasure.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/private/textmeasure.h
3 // Purpose: declaration of wxTextMeasure class
4 // Author: Manuel Martin
5 // Created: 2012-10-05
6 // Copyright: (c) 1997-2012 wxWidgets team
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
9
10 #ifndef _WX_PRIVATE_TEXTMEASURE_H_
11 #define _WX_PRIVATE_TEXTMEASURE_H_
12
13 #include "wx/vector.h"
14
15 class WXDLLIMPEXP_FWD_CORE wxDC;
16 class WXDLLIMPEXP_FWD_CORE wxFont;
17 class WXDLLIMPEXP_FWD_CORE wxWindow;
18
19 // ----------------------------------------------------------------------------
20 // wxTextMeasure: class used to measure text extent.
21 // ----------------------------------------------------------------------------
22
23 class wxTextMeasureBase
24 {
25 public:
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);
30
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() { }
34
35
36 // Return the extent of a single line string.
37 void GetTextExtent(const wxString& string,
38 wxCoord *width,
39 wxCoord *height,
40 wxCoord *descent = NULL,
41 wxCoord *externalLeading = NULL);
42
43 // The same for a multiline (with '\n') string.
44 void GetMultiLineTextExtent(const wxString& text,
45 wxCoord *width,
46 wxCoord *height,
47 wxCoord *heightOneLine = NULL);
48
49 // Find the dimensions of the largest string.
50 void GetLargestStringExtent(const wxVector<wxString>& strings,
51 wxCoord *width,
52 wxCoord *height);
53
54 // Fill the array with the widths for each "0..N" substrings for N from 1
55 // to text.length().
56 //
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,
60 wxArrayInt& widths,
61 double scaleX);
62
63 protected:
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().
67 //
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() { }
72
73 friend class MeasuringGuard;
74
75 // RAII wrapper for the two methods above.
76 class MeasuringGuard
77 {
78 public:
79 MeasuringGuard(wxTextMeasureBase& tm) : m_tm(tm)
80 {
81 m_tm.BeginMeasuring();
82 }
83
84 ~MeasuringGuard()
85 {
86 m_tm.EndMeasuring();
87 }
88
89 private:
90 wxTextMeasureBase& m_tm;
91 };
92
93
94 // The main function of this class, to be implemented in platform-specific
95 // way used by all our public methods except GetLargestStringExtents().
96 //
97 // The width and height pointers here are never NULL and the input string
98 // is not empty.
99 virtual void DoGetTextExtent(const wxString& string,
100 wxCoord *width,
101 wxCoord *height,
102 wxCoord *descent = NULL,
103 wxCoord *externalLeading = NULL) = 0;
104
105 // The real implementation of GetPartialTextExtents().
106 //
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,
110 wxArrayInt& widths,
111 double scaleX) = 0;
112
113
114 // Exactly one of m_dc and m_win is non-NULL for any given object of this
115 // class.
116 const wxDC* const m_dc;
117 const wxWindow* const m_win;
118
119 // This one can be NULL or not.
120 const wxFont* const m_font;
121
122 wxDECLARE_NO_COPY_CLASS(wxTextMeasureBase);
123 };
124
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"
132
133 #define wxUSE_GENERIC_TEXTMEASURE 1
134 #endif
135
136 #ifndef wxUSE_GENERIC_TEXTMEASURE
137 #define wxUSE_GENERIC_TEXTMEASURE 0
138 #endif
139
140 #endif // _WX_PRIVATE_TEXTMEASURE_H_