]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk1/dcclient.cpp
static wxFile::Access() added
[wxWidgets.git] / src / gtk1 / dcclient.cpp
index c4b2b3ee143f8f7a5a558b58bfac63c327a7ac26..468db590bc5f647d805dbfc1bf1af3b05f824297 100644 (file)
@@ -87,10 +87,21 @@ IMPLEMENT_DYNAMIC_CLASS(wxPaintDC,wxDC)
 
 wxPaintDC::wxPaintDC(void)
 {
+  m_penGC = NULL;
+  m_brushGC = NULL;
+  m_textGC = NULL;
+  m_bgGC = NULL;
+  m_cmap = NULL;
 };
 
 wxPaintDC::wxPaintDC( wxWindow *window )
 {
+  m_penGC = NULL;
+  m_brushGC = NULL;
+  m_textGC = NULL;
+  m_bgGC = NULL;
+  m_cmap = NULL;
+  
   if (!window) return;
   GtkWidget *widget = window->m_wxwindow;
   if (!widget) return;
@@ -268,16 +279,62 @@ void wxPaintDC::DrawLines( wxList *points, long xoffset, long yoffset )
   };
 };
 
-void wxPaintDC::DrawPolygon( int WXUNUSED(n), wxPoint WXUNUSED(points)[], 
-  long WXUNUSED(xoffset), long WXUNUSED(yoffset), int WXUNUSED(fillStyle) )
-{
-  if (!Ok()) return;
+void wxPaintDC::DrawPolygon( int n, wxPoint points[], 
+  long xoffset, long yoffset, int WXUNUSED(fillStyle) )
+ {
+   if (!Ok()) return;
+   if (!n) return;    // Nothing to draw
+   GdkPoint *gdkpoints = new GdkPoint[n+1];
+   int i;
+   for (i = 0 ; i < n ; i++)
+     {
+       gdkpoints[i].x = XLOG2DEV(points[i].x + xoffset);
+       gdkpoints[i].y = YLOG2DEV(points[i].y + yoffset);
+     }
+   if (m_brush.GetStyle() != wxTRANSPARENT)
+     gdk_draw_polygon (m_window, m_brushGC, TRUE, gdkpoints, n);
+   // To do: Fillstyle
+   if (m_pen.GetStyle() != wxTRANSPARENT)
+     for (i = 0 ; i < n ; i++)
+       gdk_draw_line( m_window, m_penGC, 
+                    gdkpoints[i%n].x,
+                    gdkpoints[i%n].y,
+                    gdkpoints[(i+1)%n].x,
+                    gdkpoints[(i+1)%n].y);
+   delete[] gdkpoints;
 };
 
-void wxPaintDC::DrawPolygon( wxList *WXUNUSED(lines), long WXUNUSED(xoffset), 
-                             long WXUNUSED(yoffset), int WXUNUSED(fillStyle) )
-{
-  if (!Ok()) return;
+void wxPaintDC::DrawPolygon( wxList *lines, long xoffset, 
+                              long yoffset, int WXUNUSED(fillStyle))
+ {
+   int n = lines->Number();
+   if (!Ok()) return;
+   GdkPoint *gdkpoints = new GdkPoint[n];
+   wxNode *node = lines->First();
+   int cnt=0;
+   while (node)
+     {
+       wxPoint *p = (wxPoint *) node->Data();
+       gdkpoints[cnt].x = XLOG2DEV(p->x + xoffset);
+       gdkpoints[cnt].y = YLOG2DEV(p->y + yoffset);
+       node = node->Next();
+       cnt++;
+     }
+   if (m_brush.GetStyle() != wxTRANSPARENT)
+     gdk_draw_polygon (m_window, m_brushGC, TRUE, gdkpoints, n);
+   // To do: Fillstyle
+   if (m_pen.GetStyle() != wxTRANSPARENT)
+     {
+       int i;
+       for (i = 0 ; i < n ; i++)
+       gdk_draw_line( m_window, m_penGC, 
+                      gdkpoints[i%n].x,
+                      gdkpoints[i%n].y,
+                      gdkpoints[(i+1)%n].x,
+                      gdkpoints[(i+1)%n].y);
+     }
+   delete[] gdkpoints;
 };
 
 void wxPaintDC::DrawRectangle( long x, long y, long width, long height )
@@ -534,7 +591,7 @@ void wxPaintDC::Clear(void)
 {
   if (!Ok()) return;
   
-  DestroyClippingRegion();
+//  DestroyClippingRegion();
   
   if (m_isDrawable)
   {
@@ -545,7 +602,7 @@ void wxPaintDC::Clear(void)
     int width = 0;
     int height = 0;
     GetSize( &width, &height );
-    gdk_draw_rectangle( m_window, m_brushGC, TRUE, 0, 0, width, height );
+    gdk_draw_rectangle( m_window, m_bgGC, TRUE, 0, 0, width, height );
   };
 };
 
@@ -649,6 +706,46 @@ void wxPaintDC::SetBrush( const wxBrush &brush )
   };
 };
 
+// CMB 21/7/98: Added SetBackground. Sets background brush
+// for Clear() and bg colour for shapes filled with cross-hatch brush
+void wxPaintDC::SetBackground( const wxBrush &brush )
+{
+  if (!Ok()) return;
+  
+  if (m_backgroundBrush == brush) return;
+  
+  m_backgroundBrush = brush;
+  
+  if (!m_backgroundBrush.Ok()) return;
+  
+  m_backgroundBrush.GetColour().CalcPixel( m_cmap );
+  gdk_gc_set_background( m_brushGC, m_backgroundBrush.GetColour().GetColor() );
+  gdk_gc_set_foreground( m_bgGC, m_backgroundBrush.GetColour().GetColor() );
+  
+  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)
+  {
+    gdk_gc_set_stipple( m_bgGC, m_backgroundBrush.GetStipple()->GetPixmap() );
+  };
+  
+  if (IS_HATCH(m_backgroundBrush.GetStyle()))
+  {
+    int num = m_backgroundBrush.GetStyle() - wxBDIAGONAL_HATCH;
+    gdk_gc_set_stipple( m_bgGC, hatches[num] );
+  };
+};
+
 void wxPaintDC::SetLogicalFunction( int function )
 {
   if (m_logicalFunction == function) return;
@@ -693,6 +790,14 @@ void wxPaintDC::SetTextBackground( const wxColour &col )
 void wxPaintDC::SetBackgroundMode( int mode )
 {
   m_backgroundMode = mode;
+
+  // CMB 21/7/98: fill style of cross-hatch brushes is affected by
+  // transparent/solid background mode
+  if (m_brush.GetStyle() != wxSOLID && m_brush.GetStyle() != wxTRANSPARENT)
+  {
+    gdk_gc_set_fill( m_brushGC,
+      (m_backgroundMode == wxTRANSPARENT) ? GDK_STIPPLED : GDK_OPAQUE_STIPPLED);
+  }
 };
 
 void wxPaintDC::SetPalette( const wxPalette& WXUNUSED(palette) )
@@ -729,9 +834,13 @@ void wxPaintDC::SetUpDC(void)
 {
   m_ok = TRUE;
   m_logicalFunction = wxCOPY;
+  if (m_penGC) gdk_gc_unref( m_penGC );
   m_penGC = gdk_gc_new( m_window );
+  if (m_brushGC) gdk_gc_unref( m_brushGC );
   m_brushGC = gdk_gc_new( m_window );
+  if (m_textGC) gdk_gc_unref( m_textGC );
   m_textGC = gdk_gc_new( m_window );
+  if (m_bgGC) gdk_gc_unref( m_bgGC );
   m_bgGC = gdk_gc_new( m_window );
   SetTextForeground( m_textForegroundColour );
   SetTextBackground( m_textBackgroundColour );