]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/dcclient.cpp
Correct compilation for GTK < 2.4.
[wxWidgets.git] / src / gtk / dcclient.cpp
index 78269d6bbed548d3b7dde331fc207e1442e717a6..8dd54a51ab9941e70f6c22acd2167ac6f3d44bc7 100644 (file)
@@ -1,5 +1,5 @@
 /////////////////////////////////////////////////////////////////////////////
-// Name:        gtk/dcclient.cpp
+// Name:        src/gtk/dcclient.cpp
 // Purpose:
 // Author:      Robert Roebling
 // RCS-ID:      $Id$
 #endif
 
 #include "wx/dcclient.h"
-#include "wx/dcmemory.h"
+
+#ifndef WX_PRECOMP
+    #include "wx/log.h"
+    #include "wx/dcmemory.h"
+#endif
+
 #include "wx/image.h"
 #include "wx/module.h"
-#include "wx/log.h"
 #include "wx/fontutil.h"
 
 #include "wx/gtk/win_gtk.h"
@@ -172,7 +176,7 @@ static void wxCleanUpGCPool()
     for (int i = 0; i < wxGCPoolSize; i++)
     {
         if (wxGCPool[i].m_gc)
-            g_object_unref (G_OBJECT (wxGCPool[i].m_gc));
+            g_object_unref (wxGCPool[i].m_gc);
     }
 
     free(wxGCPool);
@@ -328,7 +332,7 @@ wxWindowDC::~wxWindowDC()
     Destroy();
 
     if (m_layout)
-        g_object_unref( G_OBJECT( m_layout ) );
+        g_object_unref (m_layout);
     if (m_fontdesc)
         pango_font_description_free( m_fontdesc );
 }
@@ -1126,7 +1130,7 @@ void wxWindowDC::DoDrawBitmap( const wxBitmap &bitmap,
             gdk_gc_set_fill( gc, GDK_OPAQUE_STIPPLED );
             gdk_gc_set_stipple( gc, mask );
             gdk_draw_rectangle( new_mask, gc, TRUE, 0, 0, ww, hh );
-            g_object_unref (G_OBJECT (gc));
+            g_object_unref (gc);
         }
 
         if (is_mono)
@@ -1159,8 +1163,8 @@ void wxWindowDC::DoDrawBitmap( const wxBitmap &bitmap,
 
         gdk_draw_drawable( m_window, m_textGC, bitmap2, 0, 0, xx, yy, -1, -1 );
 
-        g_object_unref (G_OBJECT (bitmap2));
-        g_object_unref (G_OBJECT (gc));
+        g_object_unref (bitmap2);
+        g_object_unref (gc);
     }
     else
     {
@@ -1201,7 +1205,7 @@ void wxWindowDC::DoDrawBitmap( const wxBitmap &bitmap,
     }
 
     if (new_mask)
-        g_object_unref (G_OBJECT (new_mask));
+        g_object_unref (new_mask);
 }
 
 bool wxWindowDC::DoBlit( wxCoord xdest, wxCoord ydest,
@@ -1369,7 +1373,7 @@ bool wxWindowDC::DoBlit( wxCoord xdest, wxCoord ydest,
                 gdk_gc_set_fill( gc, GDK_OPAQUE_STIPPLED );
                 gdk_gc_set_stipple( gc, mask );
                 gdk_draw_rectangle( new_mask, gc, TRUE, 0, 0, bm_ww, bm_hh );
-                g_object_unref (G_OBJECT (gc));
+                g_object_unref (gc);
             }
 
             if (is_mono)
@@ -1413,8 +1417,8 @@ bool wxWindowDC::DoBlit( wxCoord xdest, wxCoord ydest,
 
             gdk_draw_drawable( m_window, m_textGC, bitmap, xsrc, ysrc, cx, cy, cw, ch );
 
-            g_object_unref (G_OBJECT (bitmap));
-            g_object_unref (G_OBJECT (gc));
+            g_object_unref (bitmap);
+            g_object_unref (gc);
         }
         else
         {
@@ -1442,7 +1446,7 @@ bool wxWindowDC::DoBlit( wxCoord xdest, wxCoord ydest,
         }
 
         if (new_mask)
-            g_object_unref (G_OBJECT (new_mask));
+            g_object_unref (new_mask);
     }
     else // use_bitmap_method
     {
@@ -1582,16 +1586,17 @@ void wxWindowDC::DoDrawText( const wxString &text, wxCoord x, wxCoord y )
 
 void wxWindowDC::DoDrawRotatedText( const wxString &text, wxCoord x, wxCoord y, double angle )
 {
+    if (!m_window || text.empty())
+        return;
+
+    wxCHECK_RET( Ok(), wxT("invalid window dc") );
+
     if ( wxIsNullDouble(angle) )
     {
         DrawText(text, x, y);
         return;
     }
 
-    wxCHECK_RET( Ok(), wxT("invalid window dc") );
-
-    if (!m_window) return;
-
     wxCoord w;
     wxCoord h;
 
@@ -1696,16 +1701,24 @@ void wxWindowDC::DoGetTextExtent(const wxString &string,
         *externalLeading = 0;
 
     if (string.empty())
-    {
         return;
-    }
 
-    // Set new font description
-    if (theFont)
-        pango_layout_set_font_description( m_layout, theFont->GetNativeFontInfo()->description );
+    // ensure that theFont is always non-NULL
+    if ( !theFont || !theFont->Ok() )
+        theFont = wx_const_cast(wxFont *, &m_font);
+
+    // and use it if it's valid
+    if ( theFont->Ok() )
+    {
+        pango_layout_set_font_description
+        (
+            m_layout,
+            theFont->GetNativeFontInfo()->description
+        );
+    }
 
     // Set layout's text
-    const wxCharBuffer dataUTF8 = wxGTK_CONV(string);
+    const wxCharBuffer dataUTF8 = wxGTK_CONV_FONT(string, *theFont);
     if ( !dataUTF8 )
     {
         // hardly ideal, but what else can we do if conversion failed?
@@ -1814,7 +1827,7 @@ void wxWindowDC::SetFont( const wxFont &font )
             if (oldContext != m_context)
             {
                 if (m_layout)
-                    g_object_unref( G_OBJECT( m_layout ) );
+                    g_object_unref (m_layout);
 
                 m_layout = pango_layout_new( m_context );
             }