2007-01-05 Alp Toker <alp@atoker.com>
[mono.git] / mcs / class / Mono.Cairo / Mono.Cairo / Surface.cs
index 7500119cc0b4ef702082d3fb91e668bc207e8494..527ffe621414ebc3ada331cf46ee694656f082c5 100644 (file)
@@ -1,5 +1,5 @@
 //
-// Mono.Cairo.CairoSurfaceObject.cs
+// Mono.Cairo.Surface.cs
 //
 // Authors:
 //    Duncan Mak
@@ -37,120 +37,6 @@ using System.Collections;
 
 namespace Cairo {
 
-        public class ImageSurface : Surface
-        {
-               public ImageSurface (Format format, int width, int height)
-               {
-                       surface = CairoAPI.cairo_image_surface_create (format, width, height);
-                       lock (surfaces.SyncRoot){
-                               surfaces [surface] = this;
-                       }
-               }
-
-               public ImageSurface (string data, Cairo.Format format, int width, int height, int stride)
-               {
-                       surface = CairoAPI.cairo_image_surface_create_for_data (data, format, width, height, stride);
-                       lock (surfaces.SyncRoot){
-                               surfaces [surface] = this;
-                       }
-               }
-               
-               public ImageSurface (string filename)
-               {
-                       surface = CairoAPI.cairo_image_surface_create_from_png (filename);
-                       lock (surfaces.SyncRoot){
-                               surfaces [surface] = this;
-                       }
-               }
-               
-               public int Width {
-                       get { return CairoAPI.cairo_image_surface_get_width (surface); }
-               }
-               
-               public int Height {
-                       get { return CairoAPI.cairo_image_surface_get_height (surface); }
-               }
-               
-       }
-
-       #if UNSTABLE
-       public class PdfSurface : Surface
-       {
-               public PdfSurface (string filename, double width, double height)
-               {
-                       surface = CairoAPI.cairo_pdf_surface_create (filename, width, height);
-                       lock (surfaces.SyncRoot){
-                               surfaces [surface] = this;
-                       }
-               }
-
-               public void SetDPI (double x_dpi, double y_dpi)
-               {
-                       CairoAPI.cairo_pdf_surface_set_dpi (surface, x_dpi, y_dpi);
-               }
-       }
-
-       public class PostscriptSurface : Surface
-       {
-               public PostscriptSurface (string filename, double width, double height)
-               {
-                       surface = CairoAPI.cairo_ps_surface_create (filename, width, height);
-                       lock (surfaces.SyncRoot){
-                               surfaces [surface] = this;
-                       }
-               }
-
-               public void SetDPI (double x_dpi, double y_dpi)
-               {
-                       CairoAPI.cairo_ps_surface_set_dpi (surface, x_dpi, y_dpi);
-               }
-       }
-       #endif
-
-       public class Win32Surface : Surface
-       {
-               public Win32Surface (IntPtr hdc)
-               {
-                       surface = CairoAPI.cairo_win32_surface_create (hdc);
-                       lock (surfaces.SyncRoot){
-                               surfaces [surface] = this;
-                       }
-               }
-       }
-
-       public class XlibSurface : Surface
-       {
-               public XlibSurface (IntPtr display, IntPtr drawable, IntPtr visual, int width, int height)
-               {
-                       surface = CairoAPI.cairo_xlib_surface_create (display, drawable, visual, width, height);
-                       lock (surfaces.SyncRoot){
-                               surfaces [surface] = this;
-                       }
-               }
-
-               public XlibSurface (IntPtr ptr, bool own) : base (ptr, own)
-               {
-               }
-
-               public static XlibSurface FromBitmap (IntPtr display, IntPtr bitmap, IntPtr screen, int width, int height)
-               {
-                       IntPtr  ptr;
-
-                       ptr = CairoAPI.cairo_xlib_surface_create_for_bitmap (display, bitmap, screen, width, height);
-                       return new XlibSurface(ptr, true);
-               }
-
-               public void SetDrawable (IntPtr drawable, int width, int height)
-               {
-                       CairoAPI.cairo_xlib_surface_set_drawable (surface, drawable, width, height);
-               }
-
-               public void SetSize (int width, int height)
-               {
-                       CairoAPI.cairo_xlib_surface_set_size (surface, width, height);
-               }
-       }
-   
        public class Surface : IDisposable 
         {                                              
                protected static Hashtable surfaces = new Hashtable ();
@@ -180,10 +66,39 @@ namespace Cairo {
                                return (Surface) o;
                        }
                }               
-               
+
+               static internal Surface LookupSurface (IntPtr surface)
+               {
+                               SurfaceType st = CairoAPI.cairo_surface_get_type (surface);
+                               switch (st) {
+                                       case SurfaceType.Image:
+                                               return new ImageSurface (surface, true);
+                                       case SurfaceType.XLib:
+                                               return new XlibSurface (surface, true);
+                                       case SurfaceType.Xcb:
+                                               return new XcbSurface (surface, true);
+                                       case SurfaceType.Glitz:
+                                               return new GlitzSurface (surface, true);
+                                       case SurfaceType.Win32:
+                                               return new Win32Surface (surface, true);
+#if CAIRO_1_2
+                                       case SurfaceType.Pdf:
+                                               return new PdfSurface (surface, true);
+                                       case SurfaceType.PS:
+                                               return new PSSurface (surface, true);
+                                       case SurfaceType.DirectFB:
+                                               return new DirectFBSurface (surface, true);
+                                       case SurfaceType.Svg:
+                                               return new SvgSurface (surface, true);
+#endif
+                                       default:
+                                               return Surface.LookupExternalSurface (surface);
+                               }
+               }
+
                [Obsolete ("Use an ImageSurface constructor instead.")]
                 public static Cairo.Surface CreateForImage (
-                        string data, Cairo.Format format, int width, int height, int stride)
+                        ref byte[] data, Cairo.Format format, int width, int height, int stride)
                 {
                         IntPtr p = CairoAPI.cairo_image_surface_create_for_data (
                                 data, format, width, height, stride);
@@ -216,9 +131,9 @@ namespace Cairo {
                        Dispose (false);
                }
 
-               public void Show (Context gr, int width, int height
+               public void Show (Context gr, double x, double y
                {
-                       CairoAPI.cairo_set_source_surface (gr.Handle, surface, width, height);
+                       CairoAPI.cairo_set_source_surface (gr.Handle, surface, x, y);
                        CairoAPI.cairo_paint (gr.Handle);
                }
 
@@ -268,6 +183,13 @@ namespace Cairo {
                 }
 
                public PointD DeviceOffset {
+#if CAIRO_1_2
+                       get {
+                               double x, y;
+                               CairoAPI.cairo_surface_get_device_offset (surface, out x, out y);
+                               return new PointD (x, y);
+                       }
+#endif
                        set {
                                CairoAPI.cairo_surface_set_device_offset (surface, value.X, value.Y);
                        }
@@ -275,9 +197,16 @@ namespace Cairo {
                
                public void Destroy()
                {
-                       CairoAPI.cairo_surface_destroy (surface);
+                       Dispose (true);
                }
 
+#if CAIRO_1_2
+               public void SetFallbackResolution (double x, double y)
+               {
+                       CairoAPI.cairo_surface_set_fallback_resolution (surface, x, y);
+               }
+#endif
+
                public void WriteToPng (string filename)
                {
                        CairoAPI.cairo_surface_write_to_png (surface, filename);
@@ -294,5 +223,14 @@ namespace Cairo {
                        get { return CairoAPI.cairo_surface_status (surface); }
                }
 
+#if CAIRO_1_2
+               public Content Content {
+                       get { return CairoAPI.cairo_surface_get_content (surface); }
+               }
+
+               public SurfaceType SurfaceType {
+                       get { return CairoAPI.cairo_surface_get_type (surface); }
+               }
+#endif
         }
 }