1 // Gtk.ColorSelection.cs - customizations and corrections for ColorSelection 2 // Author: Lee Mallabone <gnome@fonicmonkey.net> 3 // Author: Justin Malcolm 4 // 5 // This program is free software; you can redistribute it and/or 6 // modify it under the terms of version 2 of the Lesser GNU General 7 // Public License as published by the Free Software Foundation. 8 // 9 // This program is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 // Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public 15 // License along with this program; if not, write to the 16 // Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 // Boston, MA 02111-1307, USA. 18 19 namespace Gtk { 20 21 using System; 22 using System.Runtime.InteropServices; 23 24 public partial class ColorSelection { 25 26 [DllImport (Global.GtkNativeDll, CallingConvention = CallingConvention.Cdecl)] gtk_color_selection_palette_to_string(Gdk.Color[] colors, int n_colors)27 static extern IntPtr gtk_color_selection_palette_to_string(Gdk.Color[] colors, int n_colors); 28 29 /// <summary> PaletteToString Method </summary> PaletteToString(Gdk.Color[] colors)30 public static string PaletteToString(Gdk.Color[] colors) { 31 int n_colors = colors.Length; 32 IntPtr raw_ret = gtk_color_selection_palette_to_string(colors, n_colors); 33 string ret = GLib.Marshaller.PtrToStringGFree (raw_ret); 34 return ret; 35 } 36 37 [DllImport (Global.GtkNativeDll, CallingConvention = CallingConvention.Cdecl)] gtk_color_selection_palette_from_string(IntPtr str, out IntPtr colors, out int n_colors)38 static extern bool gtk_color_selection_palette_from_string(IntPtr str, out IntPtr colors, out int n_colors); 39 PaletteFromString(string str)40 public static Gdk.Color[] PaletteFromString(string str) { 41 IntPtr parsedColors; 42 int n_colors; 43 IntPtr native = GLib.Marshaller.StringToPtrGStrdup (str); 44 bool raw_ret = gtk_color_selection_palette_from_string(native, out parsedColors, out n_colors); 45 GLib.Marshaller.Free (native); 46 47 // If things failed, return silently 48 if (!raw_ret) 49 { 50 return null; 51 } 52 System.Console.WriteLine("Raw call finished, making " + n_colors + " actual colors"); 53 Gdk.Color[] colors = new Gdk.Color[n_colors]; 54 for (int i=0; i < n_colors; i++) 55 { 56 colors[i] = Gdk.Color.New(parsedColors); 57 parsedColors = (IntPtr) ((int)parsedColors + Marshal.SizeOf(colors[i])); 58 } 59 return colors; 60 } 61 62 [DllImport (Global.GtkNativeDll, CallingConvention = CallingConvention.Cdecl)] gtk_color_selection_set_previous_color(IntPtr raw, ref Gdk.Color color)63 static extern void gtk_color_selection_set_previous_color(IntPtr raw, ref Gdk.Color color); 64 65 [DllImport (Global.GtkNativeDll, CallingConvention = CallingConvention.Cdecl)] gtk_color_selection_get_previous_color(IntPtr raw, out Gdk.Color color)66 static extern void gtk_color_selection_get_previous_color(IntPtr raw, out Gdk.Color color); 67 68 // Create Gtk# property to replace two Gtk+ functions 69 public Gdk.Color PreviousColor 70 { 71 get 72 { 73 Gdk.Color returnColor; 74 gtk_color_selection_get_previous_color(Handle, out returnColor); 75 return returnColor; 76 } 77 set 78 { 79 gtk_color_selection_set_previous_color(Handle, ref value); 80 } 81 } 82 } 83 } 84