X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b93bc51ed9009eba04113a0580e5693fd5021244..8778519200cc317e3ecac677f10298caa7d1729a:/include/wx/private/textmeasure.h?ds=sidebyside diff --git a/include/wx/private/textmeasure.h b/include/wx/private/textmeasure.h index d7986c1589..393946e7bf 100644 --- a/include/wx/private/textmeasure.h +++ b/include/wx/private/textmeasure.h @@ -3,6 +3,7 @@ // Purpose: declaration of wxTextMeasure class // Author: Manuel Martin // Created: 2012-10-05 +// RCS-ID: $Id: // Copyright: (c) 1997-2012 wxWidgets team // Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// @@ -10,8 +11,6 @@ #ifndef _WX_PRIVATE_TEXTMEASURE_H_ #define _WX_PRIVATE_TEXTMEASURE_H_ -#include "wx/vector.h" - class WXDLLIMPEXP_FWD_CORE wxDC; class WXDLLIMPEXP_FWD_CORE wxFont; class WXDLLIMPEXP_FWD_CORE wxWindow; @@ -24,7 +23,8 @@ class wxTextMeasureBase { public: // The first ctor argument must be non-NULL, i.e. each object of this class - // is associated with either a valid wxDC or a valid wxWindow. + // is associated with either a valid wxDC or a valid wxWindow. The font can + // be NULL to use the current DC/window font or can be specified explicitly. wxTextMeasureBase(const wxDC *dc, const wxFont *theFont); wxTextMeasureBase(const wxWindow *win, const wxFont *theFont); @@ -47,9 +47,11 @@ public: wxCoord *heightOneLine = NULL); // Find the dimensions of the largest string. - void GetLargestStringExtent(const wxVector& strings, - wxCoord *width, - wxCoord *height); + wxSize GetLargestStringExtent(size_t n, const wxString* strings); + wxSize GetLargestStringExtent(const wxArrayString& strings) + { + return GetLargestStringExtent(strings.size(), &strings[0]); + } // Fill the array with the widths for each "0..N" substrings for N from 1 // to text.length(). @@ -60,30 +62,39 @@ public: wxArrayInt& widths, double scaleX); -protected: + // These functions are called by our public methods before and after each // call to DoGetTextExtent(). Derived classes may override them to prepare // for -- possibly several -- subsequent calls to DoGetTextExtent(). // // As these calls must be always paired, they're never called directly but // only by our friend MeasuringGuard class. + // + // NB: They're public only to allow VC6 to compile this code, there doesn't + // seem to be any way to give MeasuringGuard access to them (FIXME-VC6) virtual void BeginMeasuring() { } virtual void EndMeasuring() { } - friend class MeasuringGuard; + // This is another method which is only used by MeasuringGuard. + bool IsUsingDCImpl() const { return m_useDCImpl; } +protected: // RAII wrapper for the two methods above. class MeasuringGuard { public: MeasuringGuard(wxTextMeasureBase& tm) : m_tm(tm) { - m_tm.BeginMeasuring(); + // BeginMeasuring() should only be called if we have a native DC, + // so don't call it if we delegate to a DC of unknown type. + if ( !m_tm.IsUsingDCImpl() ) + m_tm.BeginMeasuring(); } ~MeasuringGuard() { - m_tm.EndMeasuring(); + if ( !m_tm.IsUsingDCImpl() ) + m_tm.EndMeasuring(); } private: @@ -92,7 +103,7 @@ protected: // The main function of this class, to be implemented in platform-specific - // way used by all our public methods except GetLargestStringExtents(). + // way used by all our public methods. // // The width and height pointers here are never NULL and the input string // is not empty. @@ -110,12 +121,36 @@ protected: wxArrayInt& widths, double scaleX) = 0; + // Call either DoGetTextExtent() or wxDC::GetTextExtent() depending on the + // value of m_useDCImpl. + // + // This must be always used instead of calling DoGetTextExtent() directly! + void CallGetTextExtent(const wxString& string, + wxCoord *width, + wxCoord *height, + wxCoord *descent = NULL, + wxCoord *externalLeading = NULL); + + // Return a valid font: if one was given to us in the ctor, use this one, + // otherwise use the current font of the associated wxDC or wxWindow. + wxFont GetFont() const; + // Exactly one of m_dc and m_win is non-NULL for any given object of this // class. const wxDC* const m_dc; const wxWindow* const m_win; + // If this is true, simply forward to wxDC::GetTextExtent() from our + // CallGetTextExtent() instead of calling our own DoGetTextExtent(). + // + // We need this because our DoGetTextExtent() typically only works with + // native DCs, i.e. those having an HDC under Windows or using Pango under + // GTK+. However wxTextMeasure object can be constructed for any wxDC, not + // necessarily a native one and in this case we must call back into the DC + // implementation of text measuring itself. + bool m_useDCImpl; + // This one can be NULL or not. const wxFont* const m_font;