[hyena] Hyena.Gui: Remove various cairo, pango and gdk custom interop methods



commit 878111f683697a6c2ea904e67bc2c3e17d1b1525
Author: Bertrand Lorentz <bertrand lorentz gmail com>
Date:   Mon Nov 18 21:00:23 2013 +0100

    Hyena.Gui: Remove various cairo, pango and gdk custom interop methods
    
    All of those methods are now provided directly by the standard bindings,
    so we don't need to do our own thing anymore.

 Hyena.Gui/Hyena.Data.Gui/ColumnCellText.cs |    2 +-
 Hyena.Gui/Hyena.Gui.Canvas/TextBlock.cs    |    6 +-
 Hyena.Gui/Hyena.Gui.csproj                 |    1 -
 Hyena.Gui/Hyena.Gui/CairoExtensions.cs     |   81 +--------------------------
 Hyena.Gui/Hyena.Gui/CompositeUtils.cs      |   41 --------------
 Hyena.Gui/Hyena.Gui/PangoCairoHelper.cs    |   81 ----------------------------
 Hyena.Gui/Hyena.Gui/PangoExtensions.cs     |   16 ------
 Hyena.Gui/Hyena.Gui/ShadingTestWindow.cs   |    2 +-
 Hyena.Gui/Hyena.Widgets/SegmentedBar.cs    |    8 ++--
 Hyena.Gui/Makefile.am                      |    1 -
 10 files changed, 12 insertions(+), 227 deletions(-)
---
diff --git a/Hyena.Gui/Hyena.Data.Gui/ColumnCellText.cs b/Hyena.Gui/Hyena.Data.Gui/ColumnCellText.cs
index ec0df02..27bd4e7 100644
--- a/Hyena.Gui/Hyena.Data.Gui/ColumnCellText.cs
+++ b/Hyena.Gui/Hyena.Data.Gui/ColumnCellText.cs
@@ -113,7 +113,7 @@ namespace Hyena.Data.Gui
             color.A = Alpha ?? (context.Opaque ? 1.0 : 0.5);
             context.Context.SetSourceColor (color);
 
-            PangoCairoHelper.ShowLayout (context.Context, context.Layout);
+            Pango.CairoHelper.ShowLayout (context.Context, context.Layout);
             //context.Context.ResetClip ();
         }
 
diff --git a/Hyena.Gui/Hyena.Gui.Canvas/TextBlock.cs b/Hyena.Gui/Hyena.Gui.Canvas/TextBlock.cs
index 43c9788..e0f8cf6 100644
--- a/Hyena.Gui/Hyena.Gui.Canvas/TextBlock.cs
+++ b/Hyena.Gui/Hyena.Gui.Canvas/TextBlock.cs
@@ -103,7 +103,7 @@ namespace Hyena.Gui.Canvas
             layout.Width = wrap != TextWrap.None || forceWidth ? (int)(Pango.Scale.PangoScale * width) : -1;
             layout.Wrap = GetPangoWrapMode (wrap);
             if (height != null && wrap != TextWrap.None) {
-                layout.SetHeight ((int)(Pango.Scale.PangoScale * height.Value));
+                layout.Height = (int)(Pango.Scale.PangoScale * height.Value);
             }
             font_desc.Weight = GetPangoFontWeight (FontWeight);
             layout.SingleParagraphMode = wrap == TextWrap.None;
@@ -206,9 +206,9 @@ namespace Hyena.Gui.Canvas
               // FIXME windows; working around some unknown issue with ShowLayout; bgo#644311
 
               cr.Antialias = Cairo.Antialias.None;
-              PangoCairoHelper.LayoutPath (cr, layout, true);
+              Pango.CairoHelper.LayoutPath (cr, layout);
             } else {
-              PangoCairoHelper.ShowLayout (cr, layout);
+              Pango.CairoHelper.ShowLayout (cr, layout);
             }
 
             TooltipMarkup = layout.IsEllipsized ? last_formatted_text : null;
diff --git a/Hyena.Gui/Hyena.Gui.csproj b/Hyena.Gui/Hyena.Gui.csproj
index 682186b..d914d26 100644
--- a/Hyena.Gui/Hyena.Gui.csproj
+++ b/Hyena.Gui/Hyena.Gui.csproj
@@ -111,7 +111,6 @@
     <Compile Include="Hyena.Gui.Theming\ThemeEngine.cs" />
     <Compile Include="Hyena.Gui.Theming\GtkTheme.cs" />
     <Compile Include="Hyena.Data.Gui\ListView\ListView_DragAndDrop.cs" />
-    <Compile Include="Hyena.Gui\PangoCairoHelper.cs" />
     <Compile Include="Hyena.Widgets\AnimatedBox.cs" />
     <Compile Include="Hyena.Widgets\AnimatedHBox.cs" />
     <Compile Include="Hyena.Widgets\AnimatedVBox.cs" />
diff --git a/Hyena.Gui/Hyena.Gui/CairoExtensions.cs b/Hyena.Gui/Hyena.Gui/CairoExtensions.cs
index 5b29b3c..2c152f1 100644
--- a/Hyena.Gui/Hyena.Gui/CairoExtensions.cs
+++ b/Hyena.Gui/Hyena.Gui/CairoExtensions.cs
@@ -50,13 +50,13 @@ namespace Hyena.Gui
     {
         public static Pango.Layout CreateLayout (Gtk.Widget widget, Cairo.Context cairo_context)
         {
-            Pango.Layout layout = PangoCairoHelper.CreateLayout (cairo_context);
+            Pango.Layout layout = Pango.CairoHelper.CreateLayout (cairo_context);
             layout.FontDescription = widget.PangoContext.FontDescription;
 
             double resolution = widget.Screen.Resolution;
             if (resolution != -1) {
-                Pango.Context context = PangoCairoHelper.LayoutGetContext (layout);
-                PangoCairoHelper.ContextSetResolution (context, resolution);
+                Pango.Context context = layout.Context;
+                Pango.CairoHelper.ContextSetResolution (context, resolution);
                 context.Dispose ();
             }
 
@@ -328,80 +328,5 @@ namespace Hyena.Gui
             ((IDisposable)cr.GetTarget ()).Dispose ();
             ((IDisposable)cr).Dispose ();
         }
-
-        private struct CairoInteropCall
-        {
-            public string Name;
-            public MethodInfo ManagedMethod;
-            public bool CallNative;
-
-            public CairoInteropCall (string name)
-            {
-                Name = name;
-                ManagedMethod = null;
-                CallNative = false;
-            }
-        }
-
-        private static bool CallCairoMethod (Cairo.Context cr, ref CairoInteropCall call)
-        {
-            if (call.ManagedMethod == null && !call.CallNative) {
-                MemberInfo [] members = typeof (Cairo.Context).GetMember (call.Name, MemberTypes.Method,
-                    BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.Public);
-
-                if (members != null && members.Length > 0 && members[0] is MethodInfo) {
-                    call.ManagedMethod = (MethodInfo)members[0];
-                } else {
-                    call.CallNative = true;
-                }
-            }
-
-            if (call.ManagedMethod != null) {
-                call.ManagedMethod.Invoke (cr, null);
-                return true;
-            }
-
-            return false;
-        }
-
-        private static bool native_push_pop_exists = true;
-
-        [DllImport ("libcairo-2.dll")]
-        private static extern void cairo_push_group (IntPtr ptr);
-        private static CairoInteropCall cairo_push_group_call = new CairoInteropCall ("PushGroup");
-
-        public static void PushGroup (Cairo.Context cr)
-        {
-            if (!native_push_pop_exists) {
-                return;
-            }
-
-            try {
-                if (!CallCairoMethod (cr, ref cairo_push_group_call)) {
-                    cairo_push_group (cr.Handle);
-                }
-            } catch {
-                native_push_pop_exists = false;
-            }
-        }
-
-        [DllImport ("libcairo-2.dll")]
-        private static extern void cairo_pop_group_to_source (IntPtr ptr);
-        private static CairoInteropCall cairo_pop_group_to_source_call = new CairoInteropCall 
("PopGroupToSource");
-
-        public static void PopGroupToSource (Cairo.Context cr)
-        {
-            if (!native_push_pop_exists) {
-                return;
-            }
-
-            try {
-                if (!CallCairoMethod (cr, ref cairo_pop_group_to_source_call)) {
-                    cairo_pop_group_to_source (cr.Handle);
-                }
-            } catch (EntryPointNotFoundException) {
-                native_push_pop_exists = false;
-            }
-        }
     }
 }
diff --git a/Hyena.Gui/Hyena.Gui/CompositeUtils.cs b/Hyena.Gui/Hyena.Gui/CompositeUtils.cs
index d7989df..bd45462 100644
--- a/Hyena.Gui/Hyena.Gui/CompositeUtils.cs
+++ b/Hyena.Gui/Hyena.Gui/CompositeUtils.cs
@@ -46,46 +46,5 @@ namespace Hyena.Gui
 
             return false;
         }
-
-        [DllImport ("libgdk-win32-2.0-0.dll")]
-        private static extern void gdk_property_change (IntPtr window, IntPtr property, IntPtr type,
-            int format, int mode, uint [] data, int nelements);
-
-        [DllImport ("libgdk-win32-2.0-0.dll")]
-        private static extern void gdk_property_change (IntPtr window, IntPtr property, IntPtr type,
-            int format, int mode, byte [] data, int nelements);
-
-        public static void ChangeProperty (Gdk.Window win, Atom property, Atom type, PropMode mode, uint [] 
data)
-        {
-            gdk_property_change (win.Handle, property.Handle, type.Handle, 32, (int)mode,  data, data.Length 
* 4);
-        }
-
-        public static void ChangeProperty (Gdk.Window win, Atom property, Atom type, PropMode mode, byte [] 
data)
-        {
-            gdk_property_change (win.Handle, property.Handle, type.Handle, 8, (int)mode,  data, data.Length);
-        }
-
-        [DllImport ("libgdk-win32-2.0-0.dll")]
-        private static extern bool gdk_x11_screen_supports_net_wm_hint (IntPtr screen, IntPtr property);
-
-        public static bool SupportsHint (Screen screen, string name)
-        {
-            try {
-                Atom atom = Atom.Intern (name, false);
-                return gdk_x11_screen_supports_net_wm_hint (screen.Handle, atom.Handle);
-            } catch {
-                return false;
-            }
-        }
-
-        public static void SetWinOpacity (Gtk.Window win, double opacity)
-        {
-            CompositeUtils.ChangeProperty (win.Window,
-                Atom.Intern ("_NET_WM_WINDOW_OPACITY", false),
-                Atom.Intern ("CARDINAL", false),
-                PropMode.Replace,
-                new uint [] { (uint) (0xffffffff * opacity) }
-            );
-        }
     }
 }
diff --git a/Hyena.Gui/Hyena.Gui/PangoExtensions.cs b/Hyena.Gui/Hyena.Gui/PangoExtensions.cs
index f59757c..e3d056f 100644
--- a/Hyena.Gui/Hyena.Gui/PangoExtensions.cs
+++ b/Hyena.Gui/Hyena.Gui/PangoExtensions.cs
@@ -47,22 +47,6 @@ namespace Hyena.Gui
             }
         }
 
-        [DllImport("libpango-1.0-0.dll")]
-        static extern int pango_layout_get_height(IntPtr raw);
-        public static int GetHeight (this Pango.Layout layout)
-        {
-            int raw_ret = pango_layout_get_height(layout.Handle);
-            int ret = raw_ret;
-            return ret;
-        }
-
-        [DllImport("libpango-1.0-0.dll")]
-        static extern void pango_layout_set_height(IntPtr raw, int height);
-        public static void SetHeight (this Pango.Layout layout, int height)
-        {
-            pango_layout_set_height (layout.Handle, height);
-        }
-
         public static string FormatEscaped (this string format, params object [] args)
         {
             return String.Format (format, args.Select (a => a == null ? "" : GLib.Markup.EscapeText 
(a.ToString ())).ToArray ());
diff --git a/Hyena.Gui/Hyena.Gui/ShadingTestWindow.cs b/Hyena.Gui/Hyena.Gui/ShadingTestWindow.cs
index 35e4b43..f319868 100644
--- a/Hyena.Gui/Hyena.Gui/ShadingTestWindow.cs
+++ b/Hyena.Gui/Hyena.Gui/ShadingTestWindow.cs
@@ -68,7 +68,7 @@ namespace Hyena.Gui
                     cr.Translate (0.5, 0.5);
                     cr.MoveTo (x + (step_width - tw) / 2.0, y + (step_height - th) / 2.0);
                     cr.SetSourceColor (CairoExtensions.ColorFromHsb (h, s, fg_b));
-                    PangoCairoHelper.ShowLayout (cr, layout);
+                    Pango.CairoHelper.ShowLayout (cr, layout);
                     cr.Translate (-0.5, -0.5);
                 }
             }
diff --git a/Hyena.Gui/Hyena.Widgets/SegmentedBar.cs b/Hyena.Gui/Hyena.Widgets/SegmentedBar.cs
index bd69793..9858d4e 100644
--- a/Hyena.Gui/Hyena.Widgets/SegmentedBar.cs
+++ b/Hyena.Gui/Hyena.Widgets/SegmentedBar.cs
@@ -323,7 +323,7 @@ namespace Hyena.Widgets
             }
 
             if (reflect) {
-                CairoExtensions.PushGroup (cr);
+                cr.PushGroup ();
             }
 
             cr.Operator = Operator.Over;
@@ -364,7 +364,7 @@ namespace Hyena.Widgets
 
                     cr.Restore ();
 
-                    CairoExtensions.PopGroupToSource (cr);
+                    cr.PopGroupToSource ();
                     cr.Paint ();
                 }
 
@@ -507,7 +507,7 @@ namespace Hyena.Widgets
                 cr.MoveTo (x, 0);
                 text_color.A = 0.9;
                 cr.SetSourceColor (text_color);
-                PangoCairoHelper.ShowLayout (cr, layout);
+                Pango.CairoHelper.ShowLayout (cr, layout);
                 cr.Fill ();
 
                 layout = CreateAdaptLayout (layout, true, false);
@@ -516,7 +516,7 @@ namespace Hyena.Widgets
                 cr.MoveTo (x, lh);
                 text_color.A = 0.75;
                 cr.SetSourceColor (text_color);
-                PangoCairoHelper.ShowLayout (cr, layout);
+                Pango.CairoHelper.ShowLayout (cr, layout);
                 cr.Fill ();
 
                 x += segment.LayoutWidth + segment_label_spacing;
diff --git a/Hyena.Gui/Makefile.am b/Hyena.Gui/Makefile.am
index 9942835..c856fff 100644
--- a/Hyena.Gui/Makefile.am
+++ b/Hyena.Gui/Makefile.am
@@ -93,7 +93,6 @@ SOURCES =  \
        Hyena.Gui/EditableUndoAdapter.cs \
        Hyena.Gui/GtkUtilities.cs \
        Hyena.Gui/HyenaActionGroup.cs \
-       Hyena.Gui/PangoCairoHelper.cs \
        Hyena.Gui/PangoExtensions.cs \
        Hyena.Gui/PixbufImageSurface.cs \
        Hyena.Gui/RatingRenderer.cs \


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]