]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/dcclient.cpp
fixed crash in tables deallocation
[wxWidgets.git] / src / gtk / dcclient.cpp
index 93f34e9fe7f078dede0cd09dce8a38dfe79bf600..81bd578de480784d8cff6d4f2905edbe0afd7125 100644 (file)
@@ -110,6 +110,7 @@ wxWindowDC::wxWindowDC( wxWindow *window )
     m_cmap = (GdkColormap *) NULL;
     m_owner = (wxWindow *)NULL;
     m_isMemDC = FALSE;
+    m_font = window->GetFont();
   
     wxASSERT_MSG( window, _T("DC needs a window") );
     
@@ -303,6 +304,7 @@ void wxWindowDC::DoDrawLines( int n, wxPoint points[], long xoffset, long yoffse
         long x2 = XLOG2DEV(points[i+1].x + xoffset);
         long y1 = YLOG2DEV(points[i].y + yoffset);     // oh, what a waste
         long y2 = YLOG2DEV(points[i+1].y + yoffset);
+       
        if (m_window)
             gdk_draw_line( m_window, m_penGC, x1, y1, x2, y2 );
         
@@ -326,7 +328,7 @@ void wxWindowDC::DoDrawPolygon( int n, wxPoint points[], long xoffset, long yoff
         CalcBoundingBox( points[i].x + xoffset, points[i].y + yoffset );
     }
     
-    if (m_brush.GetStyle() != wxTRANSPARENT)
+    if ((m_brush.GetStyle() != wxTRANSPARENT) && m_window)
         gdk_draw_polygon (m_window, m_brushGC, TRUE, gdkpoints, n);
      
     // To do: Fillstyle
@@ -863,9 +865,9 @@ void wxWindowDC::SetPen( const wxPen &pen )
     if (!m_window) return;
     
     gint width = m_pen.GetWidth();
-    // CMB: if width is non-zero scale it with the dc
     if (width <= 0)
     {
+        // CMB: if width is non-zero scale it with the dc
         width = 1;
     }
     else
@@ -876,16 +878,87 @@ void wxWindowDC::SetPen( const wxPen &pen )
         width = (int)w;
     }
   
+    const static char dotted[] = {1, 1};
+    const static char short_dashed[] = {2, 2};
+    const static char long_dashed[] = {2, 4};
+    const static char dotted_dashed[] = {3, 3, 1, 3};
+    
+    // We express dash pattern in pen width unit, so we are
+    // independent of zoom factor and so on...
+    int req_nb_dash;
+    const char *req_dash;
+    
     GdkLineStyle lineStyle = GDK_LINE_SOLID;
     switch (m_pen.GetStyle())
     {
-        case wxSOLID:      { lineStyle = GDK_LINE_SOLID;       break; }
-        case wxDOT:        { lineStyle = GDK_LINE_ON_OFF_DASH; break; }
-        case wxLONG_DASH:  { lineStyle = GDK_LINE_ON_OFF_DASH; break; }
-        case wxSHORT_DASH: { lineStyle = GDK_LINE_ON_OFF_DASH; break; }
-        case wxDOT_DASH:   { lineStyle = GDK_LINE_DOUBLE_DASH; break; }
+        case wxUSER_DASH:
+       {
+           lineStyle = GDK_LINE_ON_OFF_DASH; 
+            req_nb_dash = m_pen.GetDashCount();
+            req_dash = m_pen.GetDash();
+            break;
+       }
+        case wxDOT:        
+       { 
+           lineStyle = GDK_LINE_ON_OFF_DASH; 
+            req_nb_dash = 2;
+            req_dash = dotted;
+           break; 
+       }
+        case wxLONG_DASH:  
+       { 
+           lineStyle = GDK_LINE_ON_OFF_DASH; 
+            req_nb_dash = 2;
+            req_dash = long_dashed;
+           break; 
+       }
+        case wxSHORT_DASH: 
+       { 
+           lineStyle = GDK_LINE_ON_OFF_DASH; 
+            req_nb_dash = 2;
+            req_dash = short_dashed;
+           break; 
+       }
+        case wxDOT_DASH:   
+       { 
+//         lineStyle = GDK_LINE_DOUBLE_DASH; 
+           lineStyle = GDK_LINE_ON_OFF_DASH; 
+            req_nb_dash = 4;
+            req_dash = dotted_dashed;
+           break; 
+       }
+       
+       case wxTRANSPARENT:
+       case wxSTIPPLE:
+        case wxSOLID: 
+       default:     
+       { 
+           lineStyle = GDK_LINE_SOLID;
+            req_dash = (wxDash*)NULL;
+            req_nb_dash = 0;
+           break; 
+       }
     }
   
+#if (GTK_MINOR_VERSION > 0)
+    if (req_dash && req_nb_dash)
+    {
+        char *real_req_dash = new char[req_nb_dash];
+        if (real_req_dash)
+        {
+            for (int i = 0; i < req_nb_dash; i++)
+                real_req_dash[i] = req_dash[i] * width;
+           gdk_gc_set_dashes( m_penGC, 0, real_req_dash, req_nb_dash );
+            delete[] real_req_dash;
+        }
+        else
+        {
+            // No Memory. We use non-scaled dash pattern...
+           gdk_gc_set_dashes( m_penGC, 0, (char*)req_dash, req_nb_dash );
+        }
+    }
+#endif
+       
     GdkCapStyle capStyle = GDK_CAP_ROUND;
     switch (m_pen.GetCap())
     {
@@ -923,28 +996,25 @@ void wxWindowDC::SetBrush( const wxBrush &brush )
     m_brush.GetColour().CalcPixel( m_cmap );
     gdk_gc_set_foreground( m_brushGC, m_brush.GetColour().GetColor() );
   
-    GdkFill fillStyle = GDK_SOLID;
-    switch (m_brush.GetStyle())
-    {
-      case wxSOLID:
-      case wxTRANSPARENT:
-         break;
-      default:
-         fillStyle = GDK_STIPPLED;
-    }
-  
-    gdk_gc_set_fill( m_brushGC, fillStyle );
+    gdk_gc_set_fill( m_brushGC, GDK_SOLID );
   
     if ((m_brush.GetStyle() == wxSTIPPLE) && (m_brush.GetStipple()->Ok()))
     {
         if (m_brush.GetStipple()->GetPixmap())
-            gdk_gc_set_stipple( m_brushGC, m_brush.GetStipple()->GetPixmap() );
+       {
+            gdk_gc_set_fill( m_brushGC, GDK_TILED );
+            gdk_gc_set_tile( m_brushGC, m_brush.GetStipple()->GetPixmap() );
+       }
         else
+       {
+            gdk_gc_set_fill( m_brushGC, GDK_STIPPLED );
             gdk_gc_set_stipple( m_brushGC, m_brush.GetStipple()->GetBitmap() );
+       }
     }
   
     if (IS_HATCH(m_brush.GetStyle()))
     {
+        gdk_gc_set_fill( m_brushGC, GDK_STIPPLED );
         int num = m_brush.GetStyle() - wxBDIAGONAL_HATCH;
         gdk_gc_set_stipple( m_brushGC, hatches[num] );
     }
@@ -970,26 +1040,26 @@ void wxWindowDC::SetBackground( const wxBrush &brush )
     gdk_gc_set_background( m_penGC, m_backgroundBrush.GetColour().GetColor() );
     gdk_gc_set_background( m_bgGC, m_backgroundBrush.GetColour().GetColor() );
     gdk_gc_set_foreground( m_bgGC, m_backgroundBrush.GetColour().GetColor() );
+
+    gdk_gc_set_fill( m_bgGC, GDK_SOLID );
   
-    GdkFill fillStyle = GDK_SOLID;
-    switch (m_backgroundBrush.GetStyle())
-    {
-        case wxSOLID:
-        case wxTRANSPARENT:
-            break;
-        default:
-            fillStyle = GDK_STIPPLED;
-    }
-    gdk_gc_set_fill( m_bgGC, fillStyle );
-  
-    if (m_backgroundBrush.GetStyle() == wxSTIPPLE)
+    if ((m_backgroundBrush.GetStyle() == wxSTIPPLE) && (m_backgroundBrush.GetStipple()->Ok()))
     {
-        gdk_gc_set_stipple( m_bgGC, m_backgroundBrush.GetStipple()->GetPixmap() );
+        if (m_backgroundBrush.GetStipple()->GetPixmap())
+       {
+            gdk_gc_set_fill( m_bgGC, GDK_TILED );
+            gdk_gc_set_tile( m_bgGC, m_backgroundBrush.GetStipple()->GetPixmap() );
+       }
+        else
+       {
+            gdk_gc_set_fill( m_bgGC, GDK_STIPPLED );
+            gdk_gc_set_stipple( m_bgGC, m_backgroundBrush.GetStipple()->GetBitmap() );
+       }
     }
   
     if (IS_HATCH(m_backgroundBrush.GetStyle()))
     {
+        gdk_gc_set_fill( m_bgGC, GDK_STIPPLED );
         int num = m_backgroundBrush.GetStyle() - wxBDIAGONAL_HATCH;
         gdk_gc_set_stipple( m_bgGC, hatches[num] );
     }
@@ -1172,9 +1242,15 @@ void wxWindowDC::SetUpDC()
     m_brush = wxNullBrush;
     SetBrush( tmp_brush );
     
+/*
     tmp_brush = m_backgroundBrush;
     m_backgroundBrush = wxNullBrush;
     SetBackground( tmp_brush );
+*/
+    tmp_brush = m_backgroundBrush;
+    m_backgroundBrush = wxNullBrush;
+    SetBackground( *wxWHITE_BRUSH );
+    m_backgroundBrush = tmp_brush;
   
     if (!hatch_bitmap) 
     {