2004-05-14 20:25:57 +00:00
//
// CellRenderer.custom - Gtk CellRenderer class customizations
//
2007-02-16 18:28:37 +00:00
// Author: Todd Berman <tberman@sevenl.net>,
// Peter Johanson <peter@peterjohanson.com>
2004-05-14 20:25:57 +00:00
//
// Copyright (C) 2004 Todd Berman
2007-02-16 18:28:37 +00:00
// Copyright (C) 2007 Peter Johanson
2004-05-14 20:25:57 +00:00
//
// This code is inserted after the automatically generated code.
//
2004-06-25 18:42:19 +00:00
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of version 2 of the Lesser GNU General
// Public License as published by the Free Software Foundation.
//
// 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
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser 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.
2009-09-03 19:50:53 +00:00
[DllImport ("libgtk-win32-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
2009-04-13 17:44:48 +00:00
static extern IntPtr gtk_cell_renderer_start_editing (IntPtr handle, IntPtr evnt, IntPtr widget, IntPtr path, ref Gdk.Rectangle bg_area, ref Gdk.Rectangle cell_area, int flags);
2004-05-14 20:25:57 +00:00
2009-04-13 17:44:48 +00:00
public CellEditable StartEditing (Widget widget, Gdk.Event evnt, string path, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, CellRendererState flags)
{
IntPtr native = GLib.Marshaller.StringToPtrGStrdup (path);
IntPtr raw_ret = gtk_cell_renderer_start_editing (Handle, evnt.Handle, widget.Handle, native, ref background_area, ref cell_area, (int) flags);
GLib.Marshaller.Free (native);
Gtk.CellEditable ret = (Gtk.CellEditable) GLib.Object.GetObject(raw_ret);
return ret;
}
2004-06-04 04:55:48 +00:00
2009-09-03 19:50:53 +00:00
[DllImport ("libgtk-win32-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
2009-04-13 17:44:48 +00:00
static extern void gtk_cell_renderer_render (IntPtr handle, IntPtr drawable, IntPtr widget, ref Gdk.Rectangle bg_area, ref Gdk.Rectangle cell_area, ref Gdk.Rectangle expose_area, int flags);
2004-05-14 20:25:57 +00:00
2009-04-13 17:44:48 +00:00
public void Render (Widget widget, Gdk.Drawable window, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gdk.Rectangle expose_area, CellRendererState flags)
{
gtk_cell_renderer_render (Handle, window == null ? IntPtr.Zero : window.Handle, widget == null ? IntPtr.Zero : widget.Handle, ref background_area, ref cell_area, ref expose_area, (int) flags);
}
// We have to implement this VM manually because x_offset, y_offset, width and height params may be NULL and therefore cannot be treated as "out int"
// TODO: Implement "nullable" attribute for value type parameters in GAPI
2009-09-03 19:50:53 +00:00
[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
2009-04-13 17:44:48 +00:00
delegate void OnGetSizeDelegate (IntPtr item, IntPtr widget, IntPtr cell_area_ptr, IntPtr x_offset, IntPtr y_offset, IntPtr width, IntPtr height);
2004-05-14 20:25:57 +00:00
2009-04-13 17:44:48 +00:00
static void OnGetSize_cb (IntPtr item, IntPtr widget, IntPtr cell_area_ptr, IntPtr x_offset, IntPtr y_offset, IntPtr width, IntPtr height)
2004-05-14 20:25:57 +00:00
{
2007-03-09 14:22:43 +00:00
try {
CellRenderer obj = GLib.Object.GetObject (item, false) as CellRenderer;
Gtk.Widget widg = GLib.Object.GetObject (widget, false) as Gtk.Widget;
Gdk.Rectangle cell_area = Gdk.Rectangle.New (cell_area_ptr);
int a, b, c, d;
2009-04-13 17:44:48 +00:00
obj.OnGetSize (widg, ref cell_area, out a, out b, out c, out d);
2007-03-09 14:22:43 +00:00
if (x_offset != IntPtr.Zero)
Marshal.WriteInt32 (x_offset, a);
if (y_offset != IntPtr.Zero)
Marshal.WriteInt32 (y_offset, b);
if (width != IntPtr.Zero)
Marshal.WriteInt32 (width, c);
if (height != IntPtr.Zero)
Marshal.WriteInt32 (height, d);
} catch (Exception e) {
GLib.ExceptionManager.RaiseUnhandledException (e, false);
}
2004-05-14 20:25:57 +00:00
}
2009-08-30 20:06:33 +00:00
[DllImport("gtksharpglue-3")]
2009-04-13 17:44:48 +00:00
static extern void gtksharp_cellrenderer_override_get_size (IntPtr gtype, OnGetSizeDelegate cb);
static OnGetSizeDelegate OnGetSizeCallback;
static void OverrideOnGetSize (GLib.GType gtype)
2004-05-14 20:25:57 +00:00
{
2009-04-13 17:44:48 +00:00
if (OnGetSizeCallback == null)
OnGetSizeCallback = new OnGetSizeDelegate (OnGetSize_cb);
gtksharp_cellrenderer_override_get_size (gtype.Val, OnGetSizeCallback);
2004-05-14 20:25:57 +00:00
}
2004-06-05 01:01:07 +00:00
2009-04-13 17:44:48 +00:00
[GLib.DefaultSignalHandler (Type=typeof(Gtk.CellRenderer), ConnectionMethod="OverrideOnGetSize")]
protected virtual void OnGetSize (Gtk.Widget widget, ref Gdk.Rectangle cell_area, out int x_offset, out int y_offset, out int width, out int height)
2007-02-16 18:28:37 +00:00
{
2009-04-13 17:44:48 +00:00
InternalOnGetSize (widget, ref cell_area, out x_offset, out y_offset, out width, out height);
2004-05-14 20:25:57 +00:00
}
2009-08-30 20:06:33 +00:00
[DllImport("gtksharpglue-3")]
2009-04-13 17:44:48 +00:00
static extern void gtksharp_cellrenderer_base_get_size (IntPtr cell, IntPtr widget, IntPtr cell_area, out int x_offset, out int y_offset, out int width, out int height);
2007-02-16 18:28:37 +00:00
2009-04-13 17:44:48 +00:00
private void InternalOnGetSize (Gtk.Widget widget, ref Gdk.Rectangle cell_area, out int x_offset, out int y_offset, out int width, out int height)
2007-02-16 18:28:37 +00:00
{
2009-04-13 17:44:48 +00:00
IntPtr native_cell_area = GLib.Marshaller.StructureToPtrAlloc (cell_area);
gtksharp_cellrenderer_base_get_size (Handle, widget == null ? IntPtr.Zero : widget.Handle, native_cell_area, out x_offset, out y_offset, out width, out height);
cell_area = Gdk.Rectangle.New (native_cell_area);
Marshal.FreeHGlobal (native_cell_area);
2007-02-16 18:28:37 +00:00
}
2004-06-04 04:55:48 +00:00
2009-04-13 17:44:48 +00:00
// Compatibility code for old GetSize(..) virtual method
static void ObsoleteGetSize_cb (IntPtr item, IntPtr widget, IntPtr cell_area_ptr, IntPtr x_offset, IntPtr y_offset, IntPtr width, IntPtr height)
2004-05-14 20:25:57 +00:00
{
2007-03-09 14:22:43 +00:00
try {
CellRenderer obj = GLib.Object.GetObject (item, false) as CellRenderer;
Gtk.Widget widg = GLib.Object.GetObject (widget, false) as Gtk.Widget;
2009-04-13 17:44:48 +00:00
Gdk.Rectangle cell_area = Gdk.Rectangle.New (cell_area_ptr);
int a, b, c, d;
obj.GetSize (widg, ref cell_area, out a, out b, out c, out d);
if (x_offset != IntPtr.Zero)
Marshal.WriteInt32 (x_offset, a);
if (y_offset != IntPtr.Zero)
Marshal.WriteInt32 (y_offset, b);
if (width != IntPtr.Zero)
Marshal.WriteInt32 (width, c);
if (height != IntPtr.Zero)
Marshal.WriteInt32 (height, d);
2007-03-09 14:22:43 +00:00
} catch (Exception e) {
GLib.ExceptionManager.RaiseUnhandledException (e, false);
}
2004-05-14 20:25:57 +00:00
}
2009-04-13 17:44:48 +00:00
static void OverrideObsoleteGetSize (GLib.GType gtype)
2004-05-14 20:25:57 +00:00
{
2009-04-13 17:44:48 +00:00
if (OnGetSizeCallback == null)
OnGetSizeCallback = new OnGetSizeDelegate (ObsoleteGetSize_cb);
gtksharp_cellrenderer_override_get_size (gtype.Val, OnGetSizeCallback);
2004-05-14 20:25:57 +00:00
}
2009-04-13 17:44:48 +00:00
[Obsolete ("Replaced by OnGetSize for implementations and GetSize(..., out Gdk.Rectangle bounds) for callers.")]
[GLib.DefaultSignalHandler(Type=typeof(Gtk.CellRenderer), ConnectionMethod="OverrideObsoleteGetSize")]
public virtual void GetSize(Gtk.Widget widget, ref Gdk.Rectangle cell_area, out int x_offset, out int y_offset, out int width, out int height)
2004-05-14 20:25:57 +00:00
{
2009-04-13 17:44:48 +00:00
InternalOnGetSize (widget, ref cell_area, out x_offset, out y_offset, out width, out height);
2004-05-14 20:25:57 +00:00
}
2004-06-04 04:55:48 +00:00
2009-04-13 17:44:48 +00:00
// Compatibility code for old Render(..) virtual method
static void ObsoleteRender_cb (IntPtr cell, IntPtr window, IntPtr widget, IntPtr background_area, IntPtr cell_area, IntPtr expose_area, int flags)
2007-02-16 18:28:37 +00:00
{
2009-04-13 17:44:48 +00:00
try {
Gtk.CellRenderer __obj = GLib.Object.GetObject (cell, false) as Gtk.CellRenderer;
__obj.Render (GLib.Object.GetObject(window) as Gdk.Drawable, GLib.Object.GetObject(widget) as Gtk.Widget, Gdk.Rectangle.New (background_area), Gdk.Rectangle.New (cell_area), Gdk.Rectangle.New (expose_area), (Gtk.CellRendererState) flags);
} catch (Exception e) {
GLib.ExceptionManager.RaiseUnhandledException (e, false);
}
2007-02-16 18:28:37 +00:00
}
2009-04-13 17:44:48 +00:00
static RenderNativeDelegate ObsoleteRenderVMCallback;
static void OverrideObsoleteRender (GLib.GType gtype)
{
if (ObsoleteRenderVMCallback == null)
ObsoleteRenderVMCallback = new RenderNativeDelegate (ObsoleteRender_cb);
OverrideRender (gtype, ObsoleteRenderVMCallback); // -> autogenerated method
}
2004-06-04 04:55:48 +00:00
2009-04-13 17:44:48 +00:00
[Obsolete ("Replaced by OnRender for subclass overrides and Render (Widget ...) for callers.")]
[GLib.DefaultSignalHandler(Type=typeof(Gtk.CellRenderer), ConnectionMethod="OverrideObsoleteRender")]
protected virtual void Render (Gdk.Drawable window, Gtk.Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gdk.Rectangle expose_area, Gtk.CellRendererState flags)
{
InternalRender (window, widget, background_area, cell_area, expose_area, flags);
}
2004-06-04 04:55:48 +00:00
2009-04-13 17:44:48 +00:00
// Compatibility code for old StartEditing(..) virtual method
static IntPtr ObsoleteStartEditing_cb (IntPtr cell, IntPtr evnt, IntPtr widget, IntPtr path, IntPtr background_area, IntPtr cell_area, int flags)
2004-06-04 04:55:48 +00:00
{
2007-03-09 14:22:43 +00:00
try {
2009-04-13 17:44:48 +00:00
Gtk.CellRenderer __obj = GLib.Object.GetObject (cell, false) as Gtk.CellRenderer;
Gtk.CellEditable __result = __obj.StartEditing (Gdk.Event.GetEvent (evnt), GLib.Object.GetObject(widget) as Gtk.Widget, GLib.Marshaller.Utf8PtrToString (path), Gdk.Rectangle.New (background_area), Gdk.Rectangle.New (cell_area), (Gtk.CellRendererState) flags);
return __result == null ? IntPtr.Zero : __result.Handle;
2007-03-09 14:22:43 +00:00
} catch (Exception e) {
2009-04-13 17:44:48 +00:00
GLib.ExceptionManager.RaiseUnhandledException (e, true);
// NOTREACHED: above call does not return.
throw e;
2007-03-09 14:22:43 +00:00
}
2004-06-04 04:55:48 +00:00
}
2009-04-13 17:44:48 +00:00
static StartEditingNativeDelegate ObsoleteStartEditingVMCallback;
static void OverrideObsoleteStartEditing (GLib.GType gtype)
2004-06-04 04:55:48 +00:00
{
2009-04-13 17:44:48 +00:00
if (ObsoleteStartEditingVMCallback == null)
ObsoleteStartEditingVMCallback = new StartEditingNativeDelegate (ObsoleteStartEditing_cb);
OverrideStartEditing (gtype, ObsoleteStartEditingVMCallback);
2004-06-04 04:55:48 +00:00
}
2009-04-13 17:44:48 +00:00
[Obsolete ("Replaced by OnStartEditing for subclass overrides and StartEditing (Gtk.Widget ...) for callers.")]
[GLib.DefaultSignalHandler(Type=typeof(Gtk.CellRenderer), ConnectionMethod="OverrideObsoleteStartEditing")]
2004-06-04 04:55:48 +00:00
public virtual Gtk.CellEditable StartEditing(Gdk.Event evnt, Gtk.Widget widget, string path, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gtk.CellRendererState flags) {
2009-04-13 17:44:48 +00:00
return InternalStartEditing (evnt, widget, path, background_area, cell_area, flags);
2007-02-16 18:28:37 +00:00
}