[Gtk-sharp-list] ColorSelection fixes/custom
Lee Mallabone
gnome@fonicmonkey.net
26 Mar 2003 09:15:52 +0000
--=-dH3EyKFLbKazoFUb5ojY
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
Hi all,
As report in bug #38672, a couple of methods in ColorSelection are
broken.
I've tried to fix them with the attached patch - PaletteToString now
work as expected.
However, PaletteFromString crashes with a NullReferenceException. I
assume this is something to do with the way I've wrapped the C method
signature:
gboolean gtk_color_selection_palette_from_string
(const gchar *str,
GdkColor **colors,
gint *n_colors);
as this:
[DllImport("libgtk-win32-2.0-0.dll")]
static extern bool gtk_color_selection_palette_from_string(string str, out Gdk.Color[] colors, out int n_colors);
I've attached my new ColorSelection.custom file, and a sample that crashes on the PaletteFromString method... Does anyone have any insight?
I assume it's crashing because the output 'colors' can not be allocated by the C library. However, I'm unsure how to fix it further, so any help would be appreciated.
I've also attached the metadata changes needed to suppress the default generation for these methods.
Regards,
Lee.
--=-dH3EyKFLbKazoFUb5ojY
Content-Disposition: attachment; filename=ColorSelection.custom
Content-Type: text/plain; name=ColorSelection.custom; charset=ANSI_X3.4-1968
Content-Transfer-Encoding: 7bit
// Gtk.ColorSelection.custom - customizations and corrections for ColorSelection
// Author: Lee Mallabone <gnome@fonicmonkey.net>
[DllImport("libgtk-win32-2.0-0.dll")]
static extern string gtk_color_selection_palette_to_string(Gdk.Color[] colors, int n_colors);
/// <summary> PaletteToString Method </summary>
public static string PaletteToString(Gdk.Color[] colors) {
int n_colors = colors.Length;
string raw_ret = gtk_color_selection_palette_to_string(colors, n_colors);
string ret = raw_ret;
return ret;
}
[DllImport("libgtk-win32-2.0-0.dll")]
static extern bool gtk_color_selection_palette_from_string(string str, out Gdk.Color[] colors, out int n_colors);
/// <summary> PaletteFromString Method </summary>
public static Gdk.Color[] PaletteFromString(string str) {
Gdk.Color[] parsedColors;
int n_colors;
bool raw_ret = gtk_color_selection_palette_from_string(str, out parsedColors, out n_colors);
// If things failed, return silently
if (!raw_ret)
{
return null;
}
return parsedColors;
}
--=-dH3EyKFLbKazoFUb5ojY
Content-Disposition: attachment; filename=ColorSample.cs
Content-Type: text/plain; name=ColorSample.cs; charset=ANSI_X3.4-1968
Content-Transfer-Encoding: 7bit
using Gtk;
using Gdk;
using System;
public class ColorSample {
public static void Main()
{
Gtk.Application.Init();
// Setup simple colors
Gdk.Color black = new Gdk.Color(0x00, 0x00, 0x00);
Gdk.Color white = new Gdk.Color(0xFF, 0xFF, 0xFF);
Gdk.Color[] colors = new Gdk.Color[] { black, white };
Console.WriteLine("------ PaletteToString test ------");
string parsedPalette = ColorSelection.PaletteToString(colors);
Console.WriteLine("Got palette as: " + parsedPalette);
Console.WriteLine("------ PaletteFromString test ------");
Gdk.Color[] parsedColors = ColorSelection.PaletteFromString(parsedPalette);
if (parsedColors == null)
{
Console.WriteLine("Parsed palette array is null");
}
else
{
Console.WriteLine("Parsed palette array is: " + parsedColors);
}
}
}
--=-dH3EyKFLbKazoFUb5ojY
Content-Disposition: attachment; filename=colorsel.diff
Content-Type: text/x-patch; name=colorsel.diff; charset=ANSI_X3.4-1968
Content-Transfer-Encoding: 7bit
Index: Gtk.metadata
===================================================================
RCS file: /cvs/public/gtk-sharp/sources/Gtk.metadata,v
retrieving revision 1.46
diff -u -r1.46 Gtk.metadata
--- Gtk.metadata 25 Mar 2003 19:05:40 -0000 1.46
+++ Gtk.metadata 26 Mar 2003 09:22:11 -0000
@@ -1508,6 +1508,18 @@
</data>
</rule>
<rule>
+ <class name="GtkColorSelection">
+ <method>PaletteToString</method>
+ <method>PaletteFromString</method>
+ </class>
+ <data>
+ <attribute target="method">
+ <name>hidden</name>
+ <value>1</value>
+ </attribute>
+ </data>
+</rule>
+<rule>
<class name="GtkWidget">
<method>ListAccelClosures</method>
</class>
--=-dH3EyKFLbKazoFUb5ojY--