X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/79275a0dae9a4f29415b4bc57dbebdbb4e203957..51623cc53f350935337e57930eaaf1afe9a48c3b:/include/wx/private/textmeasure.h diff --git a/include/wx/private/textmeasure.h b/include/wx/private/textmeasure.h index ebd6a61214..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); @@ -74,6 +75,9 @@ public: virtual void BeginMeasuring() { } virtual void EndMeasuring() { } + // 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 @@ -81,12 +85,16 @@ protected: 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: @@ -123,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.