2002-08-03 22:24:37 +00:00
|
|
|
//
|
|
|
|
// Gtk.Widget.custom - Gtk Widget class customizations
|
|
|
|
//
|
|
|
|
// Author: Rachel Hestilow <hestilow@ximian.com>
|
|
|
|
//
|
|
|
|
// Copyright (C) 2002 Rachel Hestilow
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
2004-11-09 14:22:39 +00:00
|
|
|
[Obsolete]
|
|
|
|
protected Widget (GLib.GType gtype) : base(gtype)
|
|
|
|
{
|
2005-05-11 13:12:09 +00:00
|
|
|
IntPtr name = GLib.Marshaller.StringToPtrGStrdup ("parent-set");
|
|
|
|
g_signal_connect_data (Handle, name, NativeParentSetHandler, IntPtr.Zero, IntPtr.Zero, 0);
|
|
|
|
GLib.Marshaller.Free (name);
|
2004-11-09 14:22:39 +00:00
|
|
|
}
|
|
|
|
|
2004-12-17 23:21:53 +00:00
|
|
|
[DllImport("libgtk-win32-2.0-0.dll")]
|
|
|
|
static extern void gtk_widget_destroy (IntPtr raw);
|
|
|
|
|
|
|
|
public override void Destroy ()
|
|
|
|
{
|
2005-05-11 13:12:09 +00:00
|
|
|
base.Destroy ();
|
2004-12-17 23:21:53 +00:00
|
|
|
}
|
|
|
|
|
2005-05-11 13:12:09 +00:00
|
|
|
delegate void NativeParentSetDelegate (IntPtr obj, IntPtr prev, IntPtr data);
|
|
|
|
|
|
|
|
[DllImport("libgobject-2.0-0.dll")]
|
|
|
|
static extern int g_signal_connect_data (IntPtr raw, IntPtr name, NativeParentSetDelegate hndlr, IntPtr data, IntPtr notify, int flags);
|
|
|
|
|
2004-11-09 14:22:39 +00:00
|
|
|
protected override void CreateNativeObject (string[] names, GLib.Value[] vals)
|
|
|
|
{
|
|
|
|
base.CreateNativeObject (names, vals);
|
2005-05-11 13:12:09 +00:00
|
|
|
IntPtr name = GLib.Marshaller.StringToPtrGStrdup ("parent-set");
|
|
|
|
g_signal_connect_data (Handle, name, NativeParentSetHandler, IntPtr.Zero, IntPtr.Zero, 0);
|
|
|
|
GLib.Marshaller.Free (name);
|
2004-11-09 14:22:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private static Hashtable ParentedWidgets = new Hashtable ();
|
|
|
|
|
2005-05-11 13:12:09 +00:00
|
|
|
private static NativeParentSetDelegate native_parent_set_handler;
|
|
|
|
private static NativeParentSetDelegate NativeParentSetHandler {
|
|
|
|
get {
|
|
|
|
if (native_parent_set_handler == null)
|
|
|
|
native_parent_set_handler = new NativeParentSetDelegate (Widget_ParentSet);
|
|
|
|
return native_parent_set_handler;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void Widget_ParentSet (IntPtr raw, IntPtr prev, IntPtr data)
|
2004-11-09 14:22:39 +00:00
|
|
|
{
|
2005-05-11 13:12:09 +00:00
|
|
|
Widget w = GLib.Object.GetObject (raw) as Widget;
|
|
|
|
if (w.Parent == null)
|
2005-02-09 18:11:31 +00:00
|
|
|
ParentedWidgets.Remove (w);
|
2005-05-11 13:12:09 +00:00
|
|
|
else
|
|
|
|
ParentedWidgets[w] = w;
|
|
|
|
Console.WriteLine ("Parenting " + w + " at " + raw);
|
2004-11-09 14:22:39 +00:00
|
|
|
}
|
|
|
|
|
2004-12-07 19:03:55 +00:00
|
|
|
[DllImport("gtksharpglue-2")]
|
2002-08-03 22:24:37 +00:00
|
|
|
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)); }
|
2005-03-30 20:47:56 +00:00
|
|
|
set { SizeAllocate (value); }
|
2002-08-03 22:24:37 +00:00
|
|
|
}
|
|
|
|
|
2002-09-24 03:21:37 +00:00
|
|
|
|
2004-12-07 19:03:55 +00:00
|
|
|
[DllImport ("gtksharpglue-2")]
|
2002-09-24 03:21:37 +00:00
|
|
|
static extern IntPtr gtksharp_gtk_widget_get_window (IntPtr widget);
|
2004-12-07 19:03:55 +00:00
|
|
|
[DllImport ("gtksharpglue-2")]
|
2004-05-31 18:48:25 +00:00
|
|
|
static extern void gtksharp_gtk_widget_set_window (IntPtr widget, IntPtr window);
|
2002-09-24 03:21:37 +00:00
|
|
|
public Gdk.Window GdkWindow {
|
|
|
|
get {
|
|
|
|
IntPtr raw_ret = gtksharp_gtk_widget_get_window (Handle);
|
|
|
|
|
|
|
|
if (raw_ret != (IntPtr) 0){
|
2003-07-23 17:19:21 +00:00
|
|
|
Gdk.Window ret = (Gdk.Window) GLib.Object.GetObject(raw_ret, false);
|
2002-09-24 03:21:37 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2004-05-31 18:48:25 +00:00
|
|
|
set {
|
|
|
|
Gdk.Window window = value as Gdk.Window;
|
|
|
|
gtksharp_gtk_widget_set_window (Handle, window.Handle);
|
|
|
|
}
|
2003-01-30 02:56:49 +00:00
|
|
|
}
|
|
|
|
|
2004-01-28 04:08:29 +00:00
|
|
|
public void AddAccelerator (string accel_signal, AccelGroup accel_group, AccelKey accel_key)
|
|
|
|
{
|
2004-02-10 16:04:50 +00:00
|
|
|
this.AddAccelerator (accel_signal, accel_group, (uint) accel_key.Key, accel_key.AccelMods, accel_key.AccelFlags);
|
2004-01-28 04:08:29 +00:00
|
|
|
|
|
|
|
}
|
2004-02-14 17:28:11 +00:00
|
|
|
|
|
|
|
[DllImport("libgtk-win32-2.0-0.dll")]
|
|
|
|
static extern void gtk_widget_set_state (IntPtr raw, int state);
|
|
|
|
|
2004-12-07 19:03:55 +00:00
|
|
|
[DllImport("gtksharpglue-2")]
|
2004-02-14 17:28:11 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2004-05-31 18:48:25 +00:00
|
|
|
|
2004-12-07 19:03:55 +00:00
|
|
|
[DllImport("gtksharpglue-2")]
|
2004-05-31 18:48:25 +00:00
|
|
|
static extern int gtksharp_gtk_widget_get_flags (IntPtr raw);
|
|
|
|
|
2004-12-07 19:03:55 +00:00
|
|
|
[DllImport("gtksharpglue-2")]
|
2004-05-31 18:48:25 +00:00
|
|
|
static extern void gtksharp_gtk_widget_set_flags (IntPtr raw, int flags);
|
|
|
|
|
2004-12-17 21:44:47 +00:00
|
|
|
[Obsolete]
|
2004-05-31 18:48:25 +00:00
|
|
|
public int Flags {
|
|
|
|
get {
|
|
|
|
return gtksharp_gtk_widget_get_flags (Handle);
|
|
|
|
}
|
|
|
|
set {
|
|
|
|
gtksharp_gtk_widget_set_flags (Handle, (int) value);
|
|
|
|
}
|
|
|
|
}
|
2004-06-07 14:26:08 +00:00
|
|
|
|
2004-12-17 21:44:47 +00:00
|
|
|
public WidgetFlags WidgetFlags {
|
|
|
|
get {
|
|
|
|
return (WidgetFlags) gtksharp_gtk_widget_get_flags (Handle);
|
|
|
|
}
|
|
|
|
set {
|
|
|
|
gtksharp_gtk_widget_set_flags (Handle, (int) value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-06-10 18:37:05 +00:00
|
|
|
public void SetFlag (WidgetFlags flag)
|
|
|
|
{
|
|
|
|
Flags |= (int)flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void ClearFlag (WidgetFlags flag)
|
|
|
|
{
|
|
|
|
Flags &= ~((int)flag);
|
|
|
|
}
|
|
|
|
|
2004-06-07 17:14:35 +00:00
|
|
|
public bool IsMapped {
|
|
|
|
get {
|
|
|
|
return ((Flags & (int)Gtk.WidgetFlags.Mapped) != 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool IsRealized {
|
|
|
|
get {
|
|
|
|
return ((Flags & (int)Gtk.WidgetFlags.Realized) != 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-06-10 18:37:05 +00:00
|
|
|
public bool IsNoWindow {
|
2004-06-07 17:14:35 +00:00
|
|
|
get {
|
|
|
|
return ((Flags & (int)Gtk.WidgetFlags.NoWindow) != 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-06-10 18:37:05 +00:00
|
|
|
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 {
|
2004-06-07 17:14:35 +00:00
|
|
|
get {
|
|
|
|
return (Visible && IsMapped);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-12-07 19:03:55 +00:00
|
|
|
[DllImport("gtksharpglue-2")]
|
2005-03-09 20:32:24 +00:00
|
|
|
static extern int gtksharp_gtk_widget_style_get_int (IntPtr raw, IntPtr name);
|
2004-06-07 14:26:08 +00:00
|
|
|
|
|
|
|
public int FocusLineWidth {
|
|
|
|
get {
|
2005-03-09 20:32:24 +00:00
|
|
|
IntPtr name = GLib.Marshaller.StringToPtrGStrdup ("focus-line-width");
|
|
|
|
int result = gtksharp_gtk_widget_style_get_int (Handle, name);
|
|
|
|
GLib.Marshaller.Free (name);
|
|
|
|
return result;
|
2004-06-07 14:26:08 +00:00
|
|
|
}
|
|
|
|
}
|
2004-09-23 16:50:18 +00:00
|
|
|
|
2004-12-07 19:03:55 +00:00
|
|
|
[DllImport("gtksharpglue-2")]
|
2004-09-23 16:50:18 +00:00
|
|
|
static extern int gtksharp_widget_connect_set_scroll_adjustments_signal (IntPtr gtype, SetScrollAdjustmentsDelegate cb);
|
|
|
|
|
2005-03-25 17:57:15 +00:00
|
|
|
[GLib.CDeclCallback]
|
2004-09-23 16:50:18 +00:00
|
|
|
delegate void SetScrollAdjustmentsDelegate (IntPtr widget, IntPtr hadj, IntPtr vadj);
|
|
|
|
|
|
|
|
static SetScrollAdjustmentsDelegate SetScrollAdjustmentsCallback;
|
|
|
|
|
|
|
|
static void SetScrollAdjustments_cb (IntPtr widget, IntPtr hadj, IntPtr vadj)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2004-12-23 22:59:59 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-03-25 17:57:15 +00:00
|
|
|
[GLib.CDeclCallback]
|
2004-12-23 22:59:59 +00:00
|
|
|
private delegate void BindingHandler (IntPtr handle, IntPtr user_data);
|
|
|
|
|
|
|
|
private static void BindingCallback (IntPtr handle, IntPtr user_data)
|
|
|
|
{
|
|
|
|
Widget w = GLib.Object.GetObject (handle, false) as Widget;
|
|
|
|
BindingInvoker invoker = ((GCHandle) user_data).Target as BindingInvoker;
|
|
|
|
invoker.Invoke (w);
|
|
|
|
}
|
|
|
|
|
|
|
|
static BindingHandler binding_delegate;
|
|
|
|
static BindingHandler BindingDelegate {
|
|
|
|
get {
|
|
|
|
if (binding_delegate == null)
|
|
|
|
binding_delegate = new BindingHandler (BindingCallback);
|
|
|
|
return binding_delegate;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[DllImport ("gtksharpglue-2")]
|
2005-03-09 20:32:24 +00:00
|
|
|
static extern void gtksharp_widget_add_binding_signal (IntPtr gvalue, IntPtr name, BindingHandler handler);
|
2004-12-23 22:59:59 +00:00
|
|
|
|
|
|
|
[DllImport ("gtksharpglue-2")]
|
2005-03-09 20:32:24 +00:00
|
|
|
static extern void gtksharp_widget_register_binding (IntPtr gvalue, IntPtr name, uint key, int mod, IntPtr data);
|
2004-12-23 22:59:59 +00:00
|
|
|
|
|
|
|
[GLib.ClassInitializer]
|
|
|
|
static void ClassInit (GLib.GType gtype, Type t)
|
|
|
|
{
|
|
|
|
object[] attrs = t.GetCustomAttributes (typeof (BindingAttribute), true);
|
|
|
|
|
|
|
|
if (attrs.Length == 0)
|
|
|
|
return;
|
|
|
|
|
2005-03-09 20:32:24 +00:00
|
|
|
IntPtr signame = GLib.Marshaller.StringToPtrGStrdup (t.Name.Replace (".", "_") + "_bindings");
|
2004-12-23 22:59:59 +00:00
|
|
|
|
|
|
|
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));
|
|
|
|
}
|
2005-03-09 20:32:24 +00:00
|
|
|
GLib.Marshaller.Free (signame);
|
2004-12-23 22:59:59 +00:00
|
|
|
}
|
|
|
|
|
2005-02-11 15:59:22 +00:00
|
|
|
[DllImport("gtksharpglue-2")]
|
2005-03-09 20:32:24 +00:00
|
|
|
static extern void gtksharp_widget_style_get_property (IntPtr widget, IntPtr property, ref GLib.Value value);
|
2005-02-11 15:59:22 +00:00
|
|
|
|
|
|
|
public object StyleGetProperty (string property_name) {
|
|
|
|
GLib.Value value = new GLib.Value ();
|
|
|
|
object ret;
|
|
|
|
|
2005-03-09 20:32:24 +00:00
|
|
|
IntPtr name = GLib.Marshaller.StringToPtrGStrdup (property_name);
|
|
|
|
gtksharp_widget_style_get_property (Handle, name, ref value);
|
|
|
|
GLib.Marshaller.Free (name);
|
2005-02-11 15:59:22 +00:00
|
|
|
ret = value.Val;
|
|
|
|
value.Dispose ();
|
|
|
|
return ret;
|
|
|
|
}
|