]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/dcclient.cpp
removed Classic files from the manifest after removing them from the cvs
[wxWidgets.git] / src / gtk / dcclient.cpp
index 77ed883565f1571ac859aac074e45af788dd08e4..4d69ff1d0fec9c576af001ee5a14e943bf8b27a1 100644 (file)
@@ -324,7 +324,7 @@ wxWindowDC::wxWindowDC( wxWindow *window )
        standard (as e.g. wxStatusBar) */
 
     m_owner = window;
-    
+
     if (m_owner && m_owner->m_wxwindow && (m_owner->GetLayoutDirection() == wxLayout_RightToLeft))
     {
         // reverse sense
@@ -392,6 +392,8 @@ void wxWindowDC::SetUpDC()
 
     gdk_gc_set_fill( m_textGC, GDK_SOLID );
 
+    gdk_gc_set_colormap( m_textGC, m_cmap );
+
     /* m_penGC */
     m_pen.GetColour().CalcPixel( m_cmap );
     gdk_gc_set_foreground( m_penGC, m_pen.GetColour().GetColor() );
@@ -860,7 +862,7 @@ void wxWindowDC::DoDrawRectangle( wxCoord x, wxCoord y, wxCoord width, wxCoord h
                     gdk_draw_rectangle( m_window, m_penGC, FALSE, xx, yy, ww-2, hh-2 );
                     gdk_draw_rectangle( m_window, m_penGC, FALSE, xx-1, yy-1, ww, hh );
                 }
-                
+
                 // reset
                 gdk_gc_set_line_attributes( m_penGC, 2, GDK_LINE_SOLID, GDK_CAP_ROUND, GDK_JOIN_ROUND );
             }
@@ -1081,10 +1083,10 @@ void wxWindowDC::DoDrawBitmap( const wxBitmap &bitmap,
 
     int w = bitmap.GetWidth();
     int h = bitmap.GetHeight();
-    
+
     if (m_owner && m_owner->GetLayoutDirection() == wxLayout_RightToLeft)
         xx -= w;
-        
+
     CalcBoundingBox( x, y );
     CalcBoundingBox( x + w, y + h );
 
@@ -1217,7 +1219,7 @@ bool wxWindowDC::DoBlit( wxCoord xdest, wxCoord ydest,
 
     wxMemoryDC *memDC = wxDynamicCast(source, wxMemoryDC);
     wxBitmap selected = source->GetSelectedBitmap();
-    
+
     bool use_bitmap_method = false;
     bool is_mono = false;
 
@@ -1228,7 +1230,7 @@ bool wxWindowDC::DoBlit( wxCoord xdest, wxCoord ydest,
     }
 
     if (memDC && !selected.Ok()) return false;
-    
+
     if (selected.Ok())
     {
         is_mono = (selected.GetDepth() == 1);
@@ -1426,7 +1428,7 @@ bool wxWindowDC::DoBlit( wxCoord xdest, wxCoord ydest,
             GdkWindow* window = source->GetGDKWindow();
             if ( !window )
                 return false;
-            
+
             // copy including child window contents
             gdk_gc_set_subwindow( m_penGC, GDK_INCLUDE_INFERIORS );
             gdk_draw_drawable( m_window, m_penGC,
@@ -1577,7 +1579,7 @@ void wxWindowDC::DoDrawText( const wxString &text, wxCoord x, wxCoord y )
             gdk_draw_rectangle(m_window, m_textGC, TRUE, x, y, w, h);
             gdk_gc_set_foreground(m_textGC, m_textForegroundColour.GetColor());
         }
-        
+
         // Draw layout.
         if (m_owner && m_owner->GetLayoutDirection() == wxLayout_RightToLeft)
             gdk_draw_layout( m_window, m_textGC, x-w, y, m_layout );
@@ -1769,10 +1771,54 @@ void wxWindowDC::DoGetTextExtent(const wxString &string,
     }
 
     // Reset old font description
-    if (theFont)
+    if (theFont->IsOk())
         pango_layout_set_font_description( m_layout, m_fontdesc );
 }
 
+
+bool wxWindowDC::DoGetPartialTextExtents(const wxString& text,
+                                         wxArrayInt& widths) const
+{
+    const size_t len = text.length();
+    widths.Empty();
+    widths.Add(0, len);
+
+    if (text.empty())
+        return true;
+
+    // Set layout's text
+    const wxCharBuffer dataUTF8 = wxGTK_CONV_FONT(text, m_font);
+    if ( !dataUTF8 )
+    {
+        // hardly ideal, but what else can we do if conversion failed?
+        wxLogLastError(wxT("DoGetPartialTextExtents"));
+        return false;
+    }
+
+    pango_layout_set_text( m_layout, dataUTF8, strlen(dataUTF8) );
+
+    // Calculate the position of each character based on the widths of
+    // the previous characters
+
+    // Code borrowed from Scintilla's PlatGTK
+    PangoLayoutIter *iter = pango_layout_get_iter(m_layout);
+    PangoRectangle pos;
+    pango_layout_iter_get_cluster_extents(iter, NULL, &pos);
+    size_t i = 0;
+    while (pango_layout_iter_next_cluster(iter))
+    {
+        pango_layout_iter_get_cluster_extents(iter, NULL, &pos);
+        int position = PANGO_PIXELS(pos.x);
+        widths[i++] = position;
+    }
+    while (i < len)
+        widths[i++] = PANGO_PIXELS(pos.x + pos.width);
+    pango_layout_iter_free(iter);
+
+    return true;
+}
+
+
 wxCoord wxWindowDC::GetCharWidth() const
 {
     pango_layout_set_text( m_layout, "H", 1 );
@@ -2322,7 +2368,7 @@ void wxWindowDC::SetDeviceOrigin( wxCoord x, wxCoord y )
 {
     m_deviceOriginX = x;
     m_deviceOriginY = y;
-    
+
     ComputeScaleAndOrigin();
 }
 
@@ -2330,10 +2376,10 @@ void wxWindowDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp )
 {
     m_signX = (xLeftRight ?  1 : -1);
     m_signY = (yBottomUp  ? -1 :  1);
-    
+
     if (m_owner && m_owner->m_wxwindow && (m_owner->GetLayoutDirection() == wxLayout_RightToLeft))
-        m_signX = -m_signX;        
-        
+        m_signX = -m_signX;
+
     ComputeScaleAndOrigin();
 }