ColorSelection bug fixes (was Re: [Gtk-sharp-list] problem marshalling struct data)

Pablo Baena pbaena@uol.com.ar
13 Apr 2003 19:32:53 +0000


--=-I9Ip3j2fPypWeGN0M7Jh
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

I now see why you use unsafe.

You can change 

parsedColors = (IntPtr) ((int)parsedColors + sizeof(Gdk.Color));

with 

parsedColors = (IntPtr) ((int)parsedColors + Marshal.SizeOf(colors[i]));

then you can get rid of unsafe code.



On Sat, 2003-04-12 at 13:08, Lee Mallabone wrote:

> On Sat, 2003-04-12 at 03:24, Mike Kestner wrote:
> 
> > Only thing I can think of is to return an IntPtr, and in a .custom,
> > increment the pointer while iterating on n_color using Gdk.Color.New to
> > marshal the individual Colors. May need to go into unsafe mode to
> > increment the IntPtr, but I'm not sure off the top of my head.
> 
> I was trying to do that originally, but in a way that didn't actually
> manipulate the IntPtr, so it didn't work.
> 
> It works now (though PaletteFromString is unsafe).
> 
> I've attached patches that fix up bugs in ColorSelection. They make
> PaletteFromString() and PaletteToString have good method signatures as
> well as making PreviousColor a single property. This resolves bugs
> #27835 & #38672.
> 
> Okay to commit?
> 
> I've also attached ColorSample.cs which is actually a visual test that
> things work. I could probably turn this into an NUnit test without too
> much trouble. Does Gtk# have a framework/suite setup for NUnit tests? If
> not, is this worth putting on cvs anywhere, (it crashes without my
> patches, works correctly with them).
> 
> Regards,
> 
> Lee.

-- 
Pablo Baena <pbaena@uol.com.ar>

--=-I9Ip3j2fPypWeGN0M7Jh
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: 7bit

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
  <META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
  <META NAME="GENERATOR" CONTENT="GtkHTML/1.1.7">
</HEAD>
<BODY>
I now see why you use unsafe.<BR>
<BR>
You can change <BR>
<FONT SIZE="3"><TT><BR>
parsedColors = (IntPtr) ((int)parsedColors + sizeof(Gdk.Color));</TT></FONT><BR>
<BR>
with <BR>
<BR>
<FONT SIZE="3"><TT>parsedColors = (IntPtr) ((int)parsedColors + Marshal.SizeOf(colors[i]));<BR>
<BR>
then you can get rid of unsafe code.<BR>
<BR>
</TT></FONT><BR>
<BR>
On Sat, 2003-04-12 at 13:08, Lee Mallabone wrote:
<BLOCKQUOTE TYPE=CITE>
<PRE><FONT COLOR="#737373" SIZE="3"><I>On Sat, 2003-04-12 at 03:24, Mike Kestner wrote:

&gt; Only thing I can think of is to return an IntPtr, and in a .custom,
&gt; increment the pointer while iterating on n_color using Gdk.Color.New to
&gt; marshal the individual Colors. May need to go into unsafe mode to
&gt; increment the IntPtr, but I'm not sure off the top of my head.

I was trying to do that originally, but in a way that didn't actually
manipulate the IntPtr, so it didn't work.

It works now (though PaletteFromString is unsafe).

I've attached patches that fix up bugs in ColorSelection. They make
PaletteFromString() and PaletteToString have good method signatures as
well as making PreviousColor a single property. This resolves bugs
#27835 &amp; #38672.

Okay to commit?

I've also attached ColorSample.cs which is actually a visual test that
things work. I could probably turn this into an NUnit test without too
much trouble. Does Gtk# have a framework/suite setup for NUnit tests? If
not, is this worth putting on cvs anywhere, (it crashes without my
patches, works correctly with them).

Regards,

Lee.</I></FONT></PRE>
</BLOCKQUOTE>
<PRE><TABLE CELLSPACING="0" CELLPADDING="0" WIDTH="100%">
<TR>
<TD>
-- <BR>
Pablo Baena &lt;<A HREF="mailto:pbaena@uol.com.ar">pbaena@uol.com.ar</A>&gt;
</TD>
</TR>
</TABLE>
</PRE>
</BODY>
</HTML>

--=-I9Ip3j2fPypWeGN0M7Jh--