GtkSharp/gtk/Widget.custom
Mike Kestner c2230278b3 2007-09-06 Mike Kestner <mkestner@novell.com>
* AssemblyInfo.cs.in : add IgnoreClassInitializers attr to all.
 	* generator/ObjectGen.cs : add custom-attr generation for objects.
 	* glib/ClassInitializerAttribute.cs : obsolete
 	* glib/IgnoreClassInitializersAttribute.cs : new assembly attr
 	to avoid a blind GetMethods reflection.
 	* glib/Makefile.am : add files
 	* glib/TypeInitializerAttribute.cs : new attr to specify init
 	method to be run at type registration.
 	* gtk/Widget.custom : remove the ClassInitializerAttr.
 	* gtk/Gtk.metadata : add a custom-attr node to GtkWidget.
 	* sample/Subclass.cs : use the IgnoreClassInitializers attr.

svn path=/trunk/gtk-sharp/; revision=85480
2007-09-07 14:40:46 +00:00

380 lines
9.9 KiB
Plaintext

//
// Gtk.Widget.custom - Gtk Widget class customizations
//
// Authors: Rachel Hestilow <hestilow@ximian.com>,
// Brad Taylor <brad@getcoded.net>
//
// Copyright (C) 2007 Brad Taylor
// Copyright (C) 2002 Rachel Hestilow
//
// This code is inserted after the automatically generated code.
//
//
// 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.
[Obsolete]
protected Widget (GLib.GType gtype) : base(gtype)
{
}
public override void Destroy ()
{
base.Destroy ();
}
protected override void CreateNativeObject (string[] names, GLib.Value[] vals)
{
base.CreateNativeObject (names, vals);
}
[DllImport("gtksharpglue-2")]
static extern IntPtr gtksharp_gtk_widget_get_allocation (IntPtr style);
public Gdk.Rectangle Allocation {
get { return Gdk.Rectangle.New (gtksharp_gtk_widget_get_allocation (Handle)); }
set { SizeAllocate (value); }
}
[DllImport ("gtksharpglue-2")]
static extern IntPtr gtksharp_gtk_widget_get_window (IntPtr widget);
[DllImport ("gtksharpglue-2")]
static extern void gtksharp_gtk_widget_set_window (IntPtr widget, IntPtr window);
public Gdk.Window GdkWindow {
get {
IntPtr raw_ret = gtksharp_gtk_widget_get_window (Handle);
if (raw_ret != (IntPtr) 0){
Gdk.Window ret = (Gdk.Window) GLib.Object.GetObject(raw_ret, false);
return ret;
}
return null;
}
set {
Gdk.Window window = value as Gdk.Window;
gtksharp_gtk_widget_set_window (Handle, window.Handle);
}
}
public void AddAccelerator (string accel_signal, AccelGroup accel_group, AccelKey accel_key)
{
this.AddAccelerator (accel_signal, accel_group, (uint) accel_key.Key, accel_key.AccelMods, accel_key.AccelFlags);
}
[DllImport("libgtk-win32-2.0-0.dll")]
static extern void gtk_widget_set_state (IntPtr raw, int state);
[DllImport("gtksharpglue-2")]
static extern int gtksharp_gtk_widget_get_state (IntPtr raw);
public Gtk.StateType State {
set {
gtk_widget_set_state (Handle, (int) value);
}
get {
return (Gtk.StateType) gtksharp_gtk_widget_get_state (Handle);
}
}
[DllImport("gtksharpglue-2")]
static extern int gtksharp_gtk_widget_get_flags (IntPtr raw);
[DllImport("gtksharpglue-2")]
static extern void gtksharp_gtk_widget_set_flags (IntPtr raw, int flags);
[Obsolete]
public int Flags {
get {
return gtksharp_gtk_widget_get_flags (Handle);
}
set {
gtksharp_gtk_widget_set_flags (Handle, (int) value);
}
}
public WidgetFlags WidgetFlags {
get {
return (WidgetFlags) gtksharp_gtk_widget_get_flags (Handle);
}
set {
gtksharp_gtk_widget_set_flags (Handle, (int) value);
}
}
public void SetFlag (WidgetFlags flag)
{
Flags |= (int)flag;
}
public void ClearFlag (WidgetFlags flag)
{
Flags &= ~((int)flag);
}
public bool IsMapped {
get {
return ((Flags & (int)Gtk.WidgetFlags.Mapped) != 0);
}
}
public bool IsRealized {
get {
return ((Flags & (int)Gtk.WidgetFlags.Realized) != 0);
}
}
public bool IsNoWindow {
get {
return ((Flags & (int)Gtk.WidgetFlags.NoWindow) != 0);
}
}
public bool IsTopLevel {
get {
return ((Flags & (int)Gtk.WidgetFlags.Toplevel) != 0);
}
}
public bool HasGrab {
get {
return ((Flags & (int)Gtk.WidgetFlags.HasGrab) != 0);
}
}
public bool IsCompositeChild {
get {
return ((Flags & (int)Gtk.WidgetFlags.CompositeChild) != 0);
}
}
public bool IsAppPaintable {
get {
return ((Flags & (int)Gtk.WidgetFlags.AppPaintable) != 0);
}
}
public bool IsDoubleBuffered {
get {
return ((Flags & (int)Gtk.WidgetFlags.DoubleBuffered) != 0);
}
}
public bool IsDrawable {
get {
return (Visible && IsMapped);
}
}
[DllImport("gtksharpglue-2")]
static extern int gtksharp_gtk_widget_style_get_int (IntPtr raw, IntPtr name);
public int FocusLineWidth {
get {
IntPtr name = GLib.Marshaller.StringToPtrGStrdup ("focus-line-width");
int result = gtksharp_gtk_widget_style_get_int (Handle, name);
GLib.Marshaller.Free (name);
return result;
}
}
[DllImport("gtksharpglue-2")]
static extern int gtksharp_widget_connect_set_scroll_adjustments_signal (IntPtr gtype, SetScrollAdjustmentsDelegate cb);
[GLib.CDeclCallback]
delegate void SetScrollAdjustmentsDelegate (IntPtr widget, IntPtr hadj, IntPtr vadj);
static SetScrollAdjustmentsDelegate SetScrollAdjustmentsCallback;
static void SetScrollAdjustments_cb (IntPtr widget, IntPtr hadj, IntPtr vadj)
{
try {
Widget obj = GLib.Object.GetObject (widget, false) as Widget;
Gtk.Adjustment h = GLib.Object.GetObject (hadj, false) as Gtk.Adjustment;
Gtk.Adjustment v = GLib.Object.GetObject (vadj, false) as Gtk.Adjustment;
obj.OnSetScrollAdjustments (h, v);
} catch (Exception e) {
GLib.ExceptionManager.RaiseUnhandledException (e, false);
}
}
static void ConnectSetScrollAdjustments (GLib.GType gtype)
{
if (SetScrollAdjustmentsCallback == null)
SetScrollAdjustmentsCallback = new SetScrollAdjustmentsDelegate (SetScrollAdjustments_cb);
gtksharp_widget_connect_set_scroll_adjustments_signal (gtype.Val, SetScrollAdjustmentsCallback);
}
[GLib.DefaultSignalHandler (Type=typeof (Gtk.Widget), ConnectionMethod="ConnectSetScrollAdjustments")]
protected virtual void OnSetScrollAdjustments (Gtk.Adjustment hadj, Gtk.Adjustment vadj)
{
}
[DllImport("gtksharpglue-2")]
static extern int gtksharp_widget_connect_activate_signal (IntPtr gtype, ActivateDelegate cb);
[GLib.CDeclCallback]
delegate void ActivateDelegate (IntPtr widget);
static ActivateDelegate ActivateCallback;
static void Activate_cb (IntPtr widget)
{
Widget obj = GLib.Object.GetObject (widget, false) as Widget;
obj.OnActivate ();
}
static void ConnectActivate (GLib.GType gtype)
{
if (ActivateCallback == null)
ActivateCallback = new ActivateDelegate (Activate_cb);
gtksharp_widget_connect_activate_signal (gtype.Val, ActivateCallback);
}
[GLib.DefaultSignalHandler (Type=typeof (Gtk.Widget), ConnectionMethod="ConnectActivate")]
protected virtual void OnActivate ()
{
}
private class BindingInvoker {
System.Reflection.MethodInfo mi;
object[] parms;
public BindingInvoker (System.Reflection.MethodInfo mi, object[] parms)
{
this.mi = mi;
this.parms = parms;
}
public void Invoke (Widget w)
{
mi.Invoke (w, parms);
}
}
[GLib.CDeclCallback]
private delegate void BindingHandler (IntPtr handle, IntPtr user_data);
private static void BindingCallback (IntPtr handle, IntPtr user_data)
{
try {
Widget w = GLib.Object.GetObject (handle, false) as Widget;
BindingInvoker invoker = ((GCHandle) user_data).Target as BindingInvoker;
invoker.Invoke (w);
} catch (Exception e) {
GLib.ExceptionManager.RaiseUnhandledException (e, false);
}
}
static BindingHandler binding_delegate;
static BindingHandler BindingDelegate {
get {
if (binding_delegate == null)
binding_delegate = new BindingHandler (BindingCallback);
return binding_delegate;
}
}
[DllImport ("gtksharpglue-2")]
static extern void gtksharp_widget_add_binding_signal (IntPtr gvalue, IntPtr name, BindingHandler handler);
[DllImport ("gtksharpglue-2")]
static extern void gtksharp_widget_register_binding (IntPtr gvalue, IntPtr name, uint key, int mod, IntPtr data);
static void ClassInit (GLib.GType gtype, Type t)
{
object[] attrs = t.GetCustomAttributes (typeof (BindingAttribute), true);
if (attrs.Length == 0)
return;
IntPtr signame = GLib.Marshaller.StringToPtrGStrdup (t.Name.Replace (".", "_") + "_bindings");
gtksharp_widget_add_binding_signal (gtype.Val, signame, BindingDelegate);
foreach (BindingAttribute attr in attrs) {
System.Reflection.MethodInfo mi = t.GetMethod (attr.Handler, System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public);
if (mi == null)
throw new Exception ("Instance method " + attr.Handler + " not found in " + t);
BindingInvoker inv = new BindingInvoker (mi, attr.Parms);
gtksharp_widget_register_binding (gtype.Val, signame, (uint) attr.Key, (int) attr.Mod, (IntPtr) GCHandle.Alloc (inv));
}
GLib.Marshaller.Free (signame);
}
[DllImport("gtksharpglue-2")]
static extern bool gtksharp_widget_style_get_property (IntPtr widget, IntPtr property, ref GLib.Value value);
public object StyleGetProperty (string property_name) {
GLib.Value value = new GLib.Value ();
IntPtr name = GLib.Marshaller.StringToPtrGStrdup (property_name);
bool success = gtksharp_widget_style_get_property (Handle, name, ref value);
GLib.Marshaller.Free (name);
if(success) {
object ret = value.Val;
value.Dispose ();
return ret;
}
return null;
}
internal GLib.Value StyleGetPropertyValue (string property_name) {
GLib.Value value = new GLib.Value ();
IntPtr name = GLib.Marshaller.StringToPtrGStrdup (property_name);
gtksharp_widget_style_get_property (Handle, name, ref value);
GLib.Marshaller.Free (name);
return value;
}
[DllImport("libgtk-win32-2.0-0.dll")]
static extern IntPtr gtk_widget_list_mnemonic_labels (IntPtr raw);
public Widget[] ListMnemonicLabels ()
{
IntPtr raw_ret = gtk_widget_list_mnemonic_labels (Handle);
if (raw_ret == IntPtr.Zero)
return new Widget [0];
GLib.List list = new GLib.List(raw_ret);
Widget[] result = new Widget [list.Count];
for (int i = 0; i < list.Count; i++)
result [i] = list [i] as Widget;
return result;
}
public void ModifyBase (Gtk.StateType state)
{
gtk_widget_modify_base (Handle, (int) state, IntPtr.Zero);
}
public void ModifyBg (Gtk.StateType state)
{
gtk_widget_modify_bg (Handle, (int) state, IntPtr.Zero);
}
public void ModifyFg (Gtk.StateType state)
{
gtk_widget_modify_fg (Handle, (int) state, IntPtr.Zero);
}
public void ModifyText (Gtk.StateType state)
{
gtk_widget_modify_text (Handle, (int) state, IntPtr.Zero);
}