[Gtk-sharp-list] Custom widgets
Sergio Rubio
sergio.rubio@hispalinux.es
Tue, 17 Aug 2004 00:16:50 +0200
--=-UgAc4rYN2s3y8cKQvtCS
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
Hi,
I'm trying to make a custom widget derived form Gtk.ImageMenuItem.
When I click on the the widget I get the following exception:
Unhandled Exception: GLib.MissingIntPtrCtorException: GLib.Object
subclass Gtk.Ext.ActionMenuItem must provide a protected or public
IntPtr ctor to support wrapping of native object handles.
If I add the IntPtr constructor I get two constructor calls: one when
the custom widget object is created and the other one when the item is
clicked.
public ActionMenuItem (UIAction action) : base (action.Label)
{
// This is called when the object is created
}
public ActionMenuItem (IntPtr ptr) : base (ptr)
{
// This is called when the user clicks the MenuItem
}
So it seems that two diferent instances of ActionMenuItem are created,
and if I use any local variables in the ActionMenuItem class a
System.NullReferenceException is thrown when I click on the menu item
because the second instance variables are not initialized.
The funny thing is that sometimes it works fine, I mean, it doesn't
throw the GLib.MissingIntPtrCtorException.
Am I missing something? What should I do to workaround this?. I
appreciate your help.
Cheers,
Rubio
P.S.: The ActionMenuItem class is attached.
--
::: sergio.rubio@hispalinux.es :::
::: http://mspace.berlios.de :::
::: rubiojr@jabber.org :::
--=-UgAc4rYN2s3y8cKQvtCS
Content-Disposition: attachment; filename=ActionMenuItem.cs
Content-Type: text/x-csharp; name=ActionMenuItem.cs; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
/*
* Copyright (C) 2004 Sergio Rubio <sergio.rubio@hispalinux.es>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
namespace Gtk.Ext {
using Gtk;
using System;
public class ActionMenuItem : ImageMenuItem
{
protected UIAction action;
public ActionMenuItem (UIAction action) : base (action.Label)
{
this.action = action;
Image img = new Image ();
img.SetFromStock(action.StockIcon, IconSize.Menu);
Image = img;
InitComponent ();
}
private void InitComponent ()
{
action.IconSize = IconSize.Menu;
Sensitive = action.Enabled;
}
protected override void OnActivated ()
{
base.OnActivated ();
if (!action.Enabled)
return;
action.ActionPerformed ();
}
}
}
--=-UgAc4rYN2s3y8cKQvtCS--