]> git.saurik.com Git - wxWidgets.git/commitdiff
use a wxCharBuffer instead of malloc/free for pango underline workaround
authorPaul Cornett <paulcor@bullseye.com>
Mon, 17 Dec 2007 05:58:07 +0000 (05:58 +0000)
committerPaul Cornett <paulcor@bullseye.com>
Mon, 17 Dec 2007 05:58:07 +0000 (05:58 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@50758 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/gtk/dcclient.cpp

index 4a36650e9ed599a5c3d2e0f56ea4785e7edd7637..7278c64129f4b09663b803eee46413ced99bce97 100644 (file)
 #define XCopyPlane XCOPYPLANE
 #endif
 
-#include "wx/dc.h"
-#include "wx/dcclient.h"
+#include "wx/gtk/dcclient.h"
 
 #ifndef WX_PRECOMP
     #include "wx/window.h"
     #include "wx/log.h"
     #include "wx/dcmemory.h"
-    #include "wx/math.h" // for floating-point functions
+    #include "wx/math.h"
     #include "wx/image.h"
     #include "wx/module.h"
 #endif
 
 #include "wx/fontutil.h"
-#include "wx/scrolwin.h"
 
 #include "wx/gtk/private.h"
 
@@ -69,7 +67,7 @@ extern GtkWidget *wxGetRootWindow();
 // constants
 //-----------------------------------------------------------------------------
 
-const double RAD2DEG  = 180.0 / M_PI;
+static const double RAD2DEG  = 180.0 / M_PI;
 
 // ----------------------------------------------------------------------------
 // private functions
@@ -84,8 +82,6 @@ static inline double DegToRad(double deg) { return (deg * M_PI) / 180.0; }
 // temporary implementation of the missing GDK function
 //-----------------------------------------------------------------------------
 
-#include "gdk/gdkprivate.h"
-
 static
 void gdk_wx_draw_bitmap(GdkDrawable  *drawable,
                         GdkGC        *gc,
@@ -1484,7 +1480,7 @@ void wxWindowDCImpl::DoDrawText( const wxString &text, wxCoord x, wxCoord y )
 
     bool underlined = m_font.IsOk() && m_font.GetUnderlined();
 
-    const wxCharBuffer data = wxGTK_CONV( text );
+    wxCharBuffer data = wxGTK_CONV(text);
     if ( !data )
         return;
     size_t datalen = strlen(data);
@@ -1494,7 +1490,6 @@ void wxWindowDCImpl::DoDrawText( const wxString &text, wxCoord x, wxCoord y )
     static bool pangoOk = !wx_pango_version_check(1, 16, 0);
 
     bool needshack = underlined && !pangoOk;
-    char *hackstring = NULL;
 
     if (needshack)
     {
@@ -1506,28 +1501,20 @@ void wxWindowDCImpl::DoDrawText( const wxString &text, wxCoord x, wxCoord y )
         // empty space characters and give them a dummy colour attribute.
         // This will force Pango to underline the leading/trailing spaces, too.
 
-        // need to realloc the string to prepend & append our special characters
-        hackstring = (char*)malloc((datalen+7)*sizeof(char));
-
+        wxCharBuffer data_tmp(datalen + 6);
         // copy the leading U+200C ZERO WIDTH NON-JOINER encoded in UTF8 format
-        strcpy(hackstring, "\342\200\214");
-
+        memcpy(data_tmp.data(), "\342\200\214", 3);
         // copy the user string
-        memcpy(&hackstring[3], data, datalen);
-
+        memcpy(data_tmp.data() + 3, data, datalen);
         // copy the trailing U+200C ZERO WIDTH NON-JOINER encoded in UTF8 format
-        strcpy(&hackstring[datalen+3], "\342\200\214");
+        memcpy(data_tmp.data() + 3 + datalen, "\342\200\214", 3);
 
-        // the special characters that we added require 6 additional bytes:
+        data = data_tmp;
         datalen += 6;
-
-        pango_layout_set_text(m_layout, hackstring, datalen);
-    }
-    else
-    {
-        pango_layout_set_text(m_layout, data, datalen);
     }
 
+    pango_layout_set_text(m_layout, data, datalen);
+
     if (underlined)
     {
         PangoAttrList *attrs = pango_attr_list_new();
@@ -1621,9 +1608,6 @@ void wxWindowDCImpl::DoDrawText( const wxString &text, wxCoord x, wxCoord y )
     height = wxCoord(height / m_scaleY);
     CalcBoundingBox (x + width, y + height);
     CalcBoundingBox (x, y);
-
-    if (hackstring)
-        free(hackstring);
 }