]> git.saurik.com Git - wxWidgets.git/blobdiff - include/wx/dc.h
Fixed typo.
[wxWidgets.git] / include / wx / dc.h
index aa5110066df80a6335d2fd4432b9f88e6e9f838e..a06217ab45365a51eb772427f9c0bcc31d72a893 100644 (file)
@@ -29,7 +29,7 @@
 #include "wx/dynarray.h"
 #include "wx/math.h"
 #include "wx/image.h"
-#include "wx/cmndata.h"
+#include "wx/region.h"
 
 #define wxUSE_NEW_DC 1
 
@@ -114,6 +114,27 @@ enum wxMappingMode
     wxMM_POINTS
 };
 
+// Description of text characteristics.
+struct wxFontMetrics
+{
+    wxFontMetrics()
+    {
+        height =
+        ascent =
+        descent =
+        internalLeading =
+        externalLeading =
+        averageWidth = 0;
+    }
+
+    int height,             // Total character height.
+        ascent,             // Part of the height above the baseline.
+        descent,            // Part of the height below the baseline.
+        internalLeading,    // Intra-line spacing.
+        externalLeading,    // Inter-line spacing.
+        averageWidth;       // Average font width, a.k.a. "x-width".
+};
+
 #if WXWIN_COMPATIBILITY_2_8
 
 //-----------------------------------------------------------------------------
@@ -375,6 +396,18 @@ public:
 
     virtual wxCoord GetCharHeight() const = 0;
     virtual wxCoord GetCharWidth() const = 0;
+
+    // The derived classes should really override DoGetFontMetrics() to return
+    // the correct values in the future but for now provide a default
+    // implementation in terms of DoGetTextExtent() to avoid breaking the
+    // compilation of all other ports as wxMSW is the only one to implement it.
+    virtual void DoGetFontMetrics(int *height,
+                                  int *ascent,
+                                  int *descent,
+                                  int *internalLeading,
+                                  int *externalLeading,
+                                  int *averageWidth) const;
+
     virtual void DoGetTextExtent(const wxString& string,
                                  wxCoord *x, wxCoord *y,
                                  wxCoord *descent = NULL,
@@ -840,6 +873,15 @@ public:
     wxCoord GetCharWidth() const
         { return m_pimpl->GetCharWidth(); }
 
+    wxFontMetrics GetFontMetrics() const
+    {
+        wxFontMetrics fm;
+        m_pimpl->DoGetFontMetrics(&fm.height, &fm.ascent, &fm.descent,
+                                  &fm.internalLeading, &fm.externalLeading,
+                                  &fm.averageWidth);
+        return fm;
+    }
+
     void GetTextExtent(const wxString& string,
                        wxCoord *x, wxCoord *y,
                        wxCoord *descent = NULL,
@@ -1199,7 +1241,50 @@ public:
 #endif  // WXWIN_COMPATIBILITY_2_8
 
 #ifdef __WXMSW__
+    // GetHDC() is the simplest way to retrieve an HDC From a wxDC but only
+    // works if this wxDC is GDI-based and fails for GDI+ contexts (and
+    // anything else without HDC, e.g. wxPostScriptDC)
     WXHDC GetHDC() const;
+
+    // don't use these methods manually, use GetTempHDC() instead
+    virtual WXHDC AcquireHDC() { return GetHDC(); }
+    virtual void ReleaseHDC(WXHDC WXUNUSED(hdc)) { }
+
+    // helper class holding the result of GetTempHDC() with std::auto_ptr<>-like
+    // semantics, i.e. it is moved when copied
+    class TempHDC
+    {
+    public:
+        TempHDC(wxDC& dc)
+            : m_dc(dc),
+              m_hdc(dc.AcquireHDC())
+        {
+        }
+
+        TempHDC(const TempHDC& thdc)
+            : m_dc(thdc.m_dc),
+              m_hdc(thdc.m_hdc)
+        {
+            const_cast<TempHDC&>(thdc).m_hdc = 0;
+        }
+
+        ~TempHDC()
+        {
+            if ( m_hdc )
+                m_dc.ReleaseHDC(m_hdc);
+        }
+
+        WXHDC GetHDC() const { return m_hdc; }
+
+    private:
+        wxDC& m_dc;
+        WXHDC m_hdc;
+
+        wxDECLARE_NO_ASSIGN_CLASS(TempHDC);
+    };
+
+    // GetTempHDC() also works for wxGCDC (but still not for wxPostScriptDC &c)
+    TempHDC GetTempHDC() { return TempHDC(*this); }
 #endif // __WXMSW__
 
 protected:
@@ -1334,8 +1419,21 @@ private:
 class WXDLLIMPEXP_CORE wxDCFontChanger
 {
 public:
-    wxDCFontChanger(wxDC& dc, const wxFont& font) : m_dc(dc), m_fontOld(dc.GetFont())
+    wxDCFontChanger(wxDC& dc)
+        : m_dc(dc), m_fontOld()
+    {
+    }
+
+    wxDCFontChanger(wxDC& dc, const wxFont& font)
+        : m_dc(dc), m_fontOld(dc.GetFont())
+    {
+        m_dc.SetFont(font);
+    }
+
+    void Set(const wxFont& font)
     {
+        if ( !m_fontOld.Ok() )
+            m_fontOld = m_dc.GetFont();
         m_dc.SetFont(font);
     }