X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a9f1207c1bbff188c5b258040560dc63276f79af..2a45803fc3877afd0ae3ce356dfe216505165882:/include/wx/private/textmeasure.h?ds=inline diff --git a/include/wx/private/textmeasure.h b/include/wx/private/textmeasure.h index a543214366..393946e7bf 100644 --- a/include/wx/private/textmeasure.h +++ b/include/wx/private/textmeasure.h @@ -23,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); @@ -61,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: @@ -121,6 +131,10 @@ protected: 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.