GtkSharp/gtk/CellRenderer.custom
Todd Berman e474eaca89 2004-05-14 Todd Berman <tberman@sevenl.net>
* glib/Object.cs: make static GLib.Object.LookupGType protected for now.        * gtk/CellRenderer.custom: code to allow for subclassing and
        implementing a custom cell renderer.
        * gtk/Makefile.am: add custom to build.
        * gtk/glue/Makefile.am: add glue to build.
        * gtk/glue/cellrenderer.c: glue code to override get_size and render
        from cellrenderer.
        * sample/CustomCellRenderer.cs: new sample to show how to implement a
        custom cell renderer.
        * sample/Makefile.am: add CustomCellRenderer sample.

svn path=/trunk/gtk-sharp/; revision=27426
2004-05-14 20:25:57 +00:00

90 lines
3.9 KiB
Plaintext

//
// CellRenderer.custom - Gtk CellRenderer class customizations
//
// Author: Todd Berman <tberman@sevenl.net>
//
// Copyright (C) 2004 Todd Berman
//
// This code is inserted after the automatically generated code.
//
public CellRenderer () : base (IntPtr.Zero)
{
if (GetType () != typeof (CellRenderer)) {
CreateNativeObject (new string[0], new GLib.Value[0]);
return;
}
throw new InvalidOperationException ("You MUST subclass this class");
}
[DllImport("gtksharpglue")]
static extern void gtksharp_cellrenderer_base_get_size (IntPtr handle, IntPtr widget, Gdk.Rectangle cell_area, out int x_offset, out int y_offset, out int width, out int height);
[DllImport("gtksharpglue")]
static extern void gtksharp_cellrenderer_override_get_size (GLib.GType gtype, GetSizeDelegate cb);
delegate void GetSizeDelegate (IntPtr item, IntPtr widget, ref Gdk.Rectangle cell_area, IntPtr x_offset, IntPtr y_offset, IntPtr width, IntPtr height);
static GetSizeDelegate GetSizeCallback;
static void GetSize_cb (IntPtr item, IntPtr widget, ref Gdk.Rectangle cell_area, IntPtr x_offset, IntPtr y_offset, IntPtr width, IntPtr height)
{
CellRenderer obj = GLib.Object.GetObject (item, false) as CellRenderer;
Gtk.Widget widg = GLib.Object.GetObject (widget, false) as Gtk.Widget;
int a, b, c, d;
obj.OnGetSize (widg, 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 (!(cell_area.Equals (Gdk.Rectangle.Zero))) {
if (width != IntPtr.Zero)
Marshal.WriteInt32 (width, c);
if (height != IntPtr.Zero)
Marshal.WriteInt32 (height, d);
}
}
protected static void OverrideGetSize (GLib.GType gtype)
{
if (GetSizeCallback == null)
GetSizeCallback = new GetSizeDelegate (GetSize_cb);
gtksharp_cellrenderer_override_get_size (gtype, GetSizeCallback);
}
protected virtual void OnGetSize (Gtk.Widget widget, Gdk.Rectangle cell_area, out int x_offset, out int y_offset, out int width, out int height)
{
gtksharp_cellrenderer_base_get_size (Handle, widget.Handle, cell_area, out x_offset, out y_offset, out width, out height);
}
[DllImport("gtksharpglue")]
static extern void gtksharp_cellrenderer_base_render (IntPtr handle, IntPtr window, IntPtr widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gdk.Rectangle expose_area, Gtk.CellRendererState flags);
[DllImport("gtksharpglue")]
static extern void gtksharp_cellrenderer_override_render (GLib.GType gtype, RenderDelegate cb);
delegate void RenderDelegate (IntPtr item, IntPtr window, IntPtr widget, ref Gdk.Rectangle background_area, ref Gdk.Rectangle cell_area, ref Gdk.Rectangle expose_area, Gtk.CellRendererState flags);
static RenderDelegate RenderCallback;
static void Render_cb (IntPtr item, IntPtr window, IntPtr widget, ref Gdk.Rectangle background_area, ref Gdk.Rectangle cell_area, ref Gdk.Rectangle expose_area, Gtk.CellRendererState flags)
{
CellRenderer obj = GLib.Object.GetObject (item, false) as CellRenderer;
Gdk.Drawable wind = GLib.Object.GetObject (window, false) as Gdk.Drawable;
Gtk.Widget widg = GLib.Object.GetObject (widget, false) as Gtk.Widget;
obj.OnRender (wind, widg, background_area, cell_area, expose_area, flags);
}
protected static void OverrideRender (GLib.GType gtype)
{
if (RenderCallback == null)
RenderCallback = new RenderDelegate (Render_cb);
gtksharp_cellrenderer_override_render (gtype, RenderCallback);
}
protected virtual void OnRender (Gdk.Drawable window, Gtk.Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gdk.Rectangle expose_area, Gtk.CellRendererState flags)
{
gtksharp_cellrenderer_base_render (Handle, window.Handle, widget.Handle, background_area, cell_area, expose_area, flags);
}