2002-11-10 13:36:19 +00:00
|
|
|
// WARNING: This file is in UTF8 format due to the use of ã
|
2002-08-12 19:14:44 +00:00
|
|
|
// XML.custom
|
|
|
|
//
|
2002-11-10 13:36:19 +00:00
|
|
|
// Author: Ricardo Fernández Pascual <ric@users.sourceforge.net>
|
2002-08-12 19:14:44 +00:00
|
|
|
//
|
2004-06-25 18:42:19 +00:00
|
|
|
// Copyright (c) 2002 Ricardo Fernández Pascual
|
2002-08-12 19:14:44 +00:00
|
|
|
//
|
2003-01-01 21:37:45 +00:00
|
|
|
// Field binding code by Rachel Hestilow <hestilow@ximian.com>
|
2004-06-25 18:42:19 +00:00
|
|
|
// Copyright (c) 2003 Rachel Hestilow
|
2003-01-01 21:37:45 +00:00
|
|
|
//
|
2002-08-12 19:14:44 +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.
|
2002-08-12 19:14:44 +00:00
|
|
|
|
2002-10-21 19:42:23 +00:00
|
|
|
// keep this around so it doesn't get GC'd
|
2002-10-27 04:16:45 +00:00
|
|
|
static GladeSharp.XMLCustomWidgetHandlerWrapper callback_wrapper = null;
|
2002-10-21 19:42:23 +00:00
|
|
|
|
2003-05-02 23:06:21 +00:00
|
|
|
[DllImport("libglade-2.0-0.dll")]
|
2002-10-27 04:16:45 +00:00
|
|
|
static extern void glade_set_custom_handler (GladeSharp.XMLCustomWidgetHandlerNative handler, IntPtr user_data);
|
2002-10-21 19:42:23 +00:00
|
|
|
|
|
|
|
static public void SetCustomHandler (Glade.XMLCustomWidgetHandler handler)
|
|
|
|
{
|
2003-04-06 09:21:15 +00:00
|
|
|
callback_wrapper = new GladeSharp.XMLCustomWidgetHandlerWrapper (handler, null);
|
2002-10-21 19:42:23 +00:00
|
|
|
glade_set_custom_handler (callback_wrapper.NativeDelegate, IntPtr.Zero);
|
|
|
|
}
|
2002-08-12 19:14:44 +00:00
|
|
|
|
2004-03-12 21:18:11 +00:00
|
|
|
[DllImport("gladesharpglue")]
|
2003-05-29 Rachel Hestilow <rachel@nullenvoid.com>
* gconf/Value.cs: Update to use new string marshalling.
* generator/StringGen.cs, ConstStringGen.cs: Added.
* generator/IGeneratable.cs: Add new method ToNativeReturn.
* generator/CallbackGen.cs: Implement ToNativeReturn. Call
ToNativeReturn for the return statement. Fix a couple of
places where s_ret was being used incorrectly for m_ret.
* generator/ClassGen.cs, EnumGen.cs, ManualGen.cs,
SimpleGen.cs, StructBase.cs: Implement ToNativeReturn.
* generator/SignalHandler.cs: Call ToNativeReturn for the
return statement, instead of CallByName.
* generator/SymbolTable.cs: Use StringGen for gchar, char,
and gunichar, and ConstStringGen for their const variants.
Add a new method wrapper for ToNativeReturn.
(Trim): Add a special-case for const strings so that the
const is not stripped. Otherwise there is no way of
resolving the const case.
* glade/XML.custom: Update to use new string marshalling.
* glib/Marshaller.cs: Added.
* glib/GException.cs, Markup.cs, ObjectManager.cs,
Value.cs: Update to use new string marshalling.
* glib/Object.cs: Remove old g_type_name DllImport
as it is no longer used.
* glue/fileselection.c (gtksharp_file_selection_get_fileop_entry):
Mark this as const return.
* gtk/ColorSelection.custom, FileSelection.custom,
SelectionData.custom: Update to use new string marshalling.
svn path=/trunk/gtk-sharp/; revision=15286
2003-06-10 18:09:47 +00:00
|
|
|
static extern IntPtr gtksharp_glade_xml_get_filename (IntPtr raw);
|
2002-08-12 19:14:44 +00:00
|
|
|
|
|
|
|
/// <summary>Filename Property</summary>
|
|
|
|
/// <remarks>Gets the filename used to create this GladeXML object
|
|
|
|
/// </remarks>
|
|
|
|
public string Filename {
|
|
|
|
get {
|
2004-01-28 22:28:38 +00:00
|
|
|
string ret;
|
|
|
|
IntPtr ptr = gtksharp_glade_xml_get_filename (Handle);
|
|
|
|
if (ptr == IntPtr.Zero)
|
|
|
|
{
|
|
|
|
// from resource
|
|
|
|
ret = System.Reflection.Assembly.GetCallingAssembly ().Location;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = Marshal.PtrToStringAnsi (ptr);
|
|
|
|
}
|
2002-08-12 19:14:44 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>Indexer of widgets</summary>
|
|
|
|
/// <remarks>Acts like GetWidget</remarks>
|
|
|
|
public Gtk.Widget this [string name] {
|
|
|
|
get {
|
|
|
|
return GetWidget (name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-05-02 23:06:21 +00:00
|
|
|
[DllImport("libglade-2.0-0.dll")]
|
2003-05-29 Rachel Hestilow <rachel@nullenvoid.com>
* gconf/Value.cs: Update to use new string marshalling.
* generator/StringGen.cs, ConstStringGen.cs: Added.
* generator/IGeneratable.cs: Add new method ToNativeReturn.
* generator/CallbackGen.cs: Implement ToNativeReturn. Call
ToNativeReturn for the return statement. Fix a couple of
places where s_ret was being used incorrectly for m_ret.
* generator/ClassGen.cs, EnumGen.cs, ManualGen.cs,
SimpleGen.cs, StructBase.cs: Implement ToNativeReturn.
* generator/SignalHandler.cs: Call ToNativeReturn for the
return statement, instead of CallByName.
* generator/SymbolTable.cs: Use StringGen for gchar, char,
and gunichar, and ConstStringGen for their const variants.
Add a new method wrapper for ToNativeReturn.
(Trim): Add a special-case for const strings so that the
const is not stripped. Otherwise there is no way of
resolving the const case.
* glade/XML.custom: Update to use new string marshalling.
* glib/Marshaller.cs: Added.
* glib/GException.cs, Markup.cs, ObjectManager.cs,
Value.cs: Update to use new string marshalling.
* glib/Object.cs: Remove old g_type_name DllImport
as it is no longer used.
* glue/fileselection.c (gtksharp_file_selection_get_fileop_entry):
Mark this as const return.
* gtk/ColorSelection.custom, FileSelection.custom,
SelectionData.custom: Update to use new string marshalling.
svn path=/trunk/gtk-sharp/; revision=15286
2003-06-10 18:09:47 +00:00
|
|
|
static extern IntPtr glade_get_widget_name (IntPtr widget);
|
2002-08-12 19:14:44 +00:00
|
|
|
|
|
|
|
static public string GetWidgetName (Gtk.Widget w) {
|
2004-01-28 22:28:38 +00:00
|
|
|
string ret;
|
|
|
|
IntPtr ptr = glade_get_widget_name (w.Handle);
|
|
|
|
if (ptr == IntPtr.Zero)
|
|
|
|
ret = "";
|
|
|
|
else
|
|
|
|
ret = Marshal.PtrToStringAnsi (ptr);
|
2002-08-12 19:14:44 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2003-05-02 23:06:21 +00:00
|
|
|
[DllImport("libglade-2.0-0.dll")]
|
2002-08-12 19:14:44 +00:00
|
|
|
static extern IntPtr glade_get_widget_tree (IntPtr widget);
|
|
|
|
|
|
|
|
static public Glade.XML GetWidgetTree (Gtk.Widget w) {
|
|
|
|
IntPtr ret_raw = glade_get_widget_tree (w.Handle);
|
2003-07-23 17:19:21 +00:00
|
|
|
Glade.XML ret = GLib.Object.GetObject (ret_raw, false) as Glade.XML;
|
2002-08-12 19:14:44 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2002-09-15 19:40:46 +00:00
|
|
|
/* a constructor that reads the XML from a Stream */
|
|
|
|
|
2003-05-02 23:06:21 +00:00
|
|
|
[DllImport("libglade-2.0-0.dll")]
|
2002-09-15 19:40:46 +00:00
|
|
|
static extern IntPtr glade_xml_new_from_buffer(byte[] buffer, int size, string root, string domain);
|
|
|
|
|
2003-01-01 21:37:45 +00:00
|
|
|
/// <summary>Creates a Glade.XML object from a Stream</summary>
|
2002-09-15 19:40:46 +00:00
|
|
|
/// <remarks>Reads the contents of the stream and parses it. It must be in
|
|
|
|
/// correct Glade format</remarks>
|
2004-04-07 19:15:01 +00:00
|
|
|
public XML (System.IO.Stream s, string root, string domain) : base (IntPtr.Zero)
|
2002-09-15 19:40:46 +00:00
|
|
|
{
|
2004-04-07 19:15:01 +00:00
|
|
|
if (GetType() != typeof (XML))
|
|
|
|
throw new InvalidOperationException ("Can't chain to this constructor from subclasses.");
|
|
|
|
|
2003-02-10 08:30:59 +00:00
|
|
|
if (s == null)
|
|
|
|
throw new ArgumentNullException ("s");
|
|
|
|
|
2002-09-15 19:40:46 +00:00
|
|
|
int size = (int) s.Length;
|
|
|
|
byte[] buffer = new byte[size];
|
|
|
|
s.Read (buffer, 0, size);
|
|
|
|
Raw = glade_xml_new_from_buffer(buffer, size, root, domain);
|
|
|
|
}
|
|
|
|
|
2003-01-01 21:37:45 +00:00
|
|
|
/// <summary>Creates a Glade.XML object from a resource</summary>
|
2002-09-15 19:40:46 +00:00
|
|
|
/// <remarks>Reads the contents of the resource in the
|
|
|
|
/// given assembly and parses it. If the assembly is null,
|
|
|
|
/// the current assembly will be used. It must be in
|
|
|
|
/// correct Glade format</remarks>
|
2004-04-07 19:15:01 +00:00
|
|
|
public XML (System.Reflection.Assembly assembly, string resource_name, string root, string domain) : base (IntPtr.Zero)
|
2002-09-15 19:40:46 +00:00
|
|
|
{
|
2004-04-07 19:15:01 +00:00
|
|
|
if (GetType() != typeof (XML))
|
|
|
|
throw new InvalidOperationException ("Can't chain to this constructor from subclasses.");
|
|
|
|
|
2002-09-15 19:40:46 +00:00
|
|
|
if (assembly == null)
|
|
|
|
assembly = System.Reflection.Assembly.GetCallingAssembly ();
|
2003-02-10 08:30:59 +00:00
|
|
|
|
2002-09-15 19:40:46 +00:00
|
|
|
System.IO.Stream s = assembly.GetManifestResourceStream (resource_name);
|
2003-02-10 08:30:59 +00:00
|
|
|
if (s == null)
|
|
|
|
throw new ArgumentException ("Cannot get resource file '" + resource_name + "'",
|
|
|
|
"resource_name");
|
|
|
|
|
2002-09-15 19:40:46 +00:00
|
|
|
int size = (int) s.Length;
|
|
|
|
byte[] buffer = new byte[size];
|
|
|
|
s.Read (buffer, 0, size);
|
|
|
|
s.Close ();
|
|
|
|
Raw = glade_xml_new_from_buffer(buffer, size, root, domain);
|
|
|
|
}
|
|
|
|
|
2002-09-13 11:38:36 +00:00
|
|
|
/* signal autoconnection using reflection */
|
|
|
|
|
|
|
|
/// <summary>Automatically connect signals</summary>
|
|
|
|
/// <remarks>Connects the signals defined in the glade file with handler methods
|
|
|
|
/// provided by the given object.</remarks>
|
|
|
|
public void Autoconnect (object handler)
|
|
|
|
{
|
2003-01-01 21:37:45 +00:00
|
|
|
BindFields (handler);
|
2002-09-13 11:38:36 +00:00
|
|
|
SignalConnector sc = new SignalConnector (this, handler);
|
|
|
|
sc.Autoconnect ();
|
|
|
|
}
|
2002-08-12 19:14:44 +00:00
|
|
|
|
2002-09-13 11:38:36 +00:00
|
|
|
/// <summary>Automatically connect signals</summary>
|
|
|
|
/// <remarks>Connects the signals defined in the glade file with static handler
|
|
|
|
/// methods provided by the given type.</remarks>
|
|
|
|
public void Autoconnect (Type handler_class)
|
|
|
|
{
|
2003-01-01 21:37:45 +00:00
|
|
|
BindFields (handler_class);
|
2002-09-13 11:38:36 +00:00
|
|
|
SignalConnector sc = new SignalConnector (this, handler_class);
|
|
|
|
sc.Autoconnect ();
|
|
|
|
}
|
|
|
|
|
|
|
|
class SignalConnector
|
|
|
|
{
|
|
|
|
/* the Glade.XML object whose signals we want to connect */
|
|
|
|
XML gxml;
|
|
|
|
|
|
|
|
/* the object to look for handlers */
|
|
|
|
object handler_object;
|
|
|
|
|
|
|
|
/* the type to look for handlers if no object has been specified */
|
|
|
|
Type handler_type;
|
|
|
|
|
|
|
|
public SignalConnector (XML gxml, object handler)
|
|
|
|
{
|
|
|
|
this.gxml = gxml;
|
|
|
|
this.handler_object = handler;
|
|
|
|
this.handler_type = handler.GetType ();
|
|
|
|
}
|
|
|
|
|
|
|
|
public SignalConnector (XML gxml, Type type)
|
|
|
|
{
|
|
|
|
this.gxml = gxml;
|
|
|
|
this.handler_object = null;
|
|
|
|
this.handler_type = type;
|
|
|
|
}
|
|
|
|
|
|
|
|
delegate void RawXMLConnectFunc (string handler_name, IntPtr objekt,
|
|
|
|
string signal_name, string signal_data,
|
|
|
|
IntPtr connect_object, int after, IntPtr user_data);
|
|
|
|
|
2003-05-02 23:06:21 +00:00
|
|
|
[DllImport("libglade-2.0-0.dll")]
|
2002-09-13 11:38:36 +00:00
|
|
|
static extern void glade_xml_signal_autoconnect_full (IntPtr raw, RawXMLConnectFunc func,
|
|
|
|
IntPtr user_data);
|
|
|
|
|
|
|
|
public void Autoconnect () {
|
|
|
|
RawXMLConnectFunc cf = new RawXMLConnectFunc (ConnectFunc);
|
|
|
|
glade_xml_signal_autoconnect_full (gxml.Handle, cf, IntPtr.Zero);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConnectFunc (string handler_name, IntPtr objekt_ptr,
|
|
|
|
string signal_name, string signal_data,
|
|
|
|
IntPtr connect_object_ptr, int after, IntPtr user_data) {
|
|
|
|
|
2003-07-23 17:19:21 +00:00
|
|
|
GLib.Object objekt = GLib.Object.GetObject (objekt_ptr, false);
|
2002-09-13 11:38:36 +00:00
|
|
|
|
|
|
|
/* if an connect_object_ptr is provided, use that as handler */
|
|
|
|
object connect_object =
|
|
|
|
connect_object_ptr == IntPtr.Zero
|
|
|
|
? handler_object
|
2003-07-23 17:19:21 +00:00
|
|
|
: GLib.Object.GetObject (connect_object_ptr, false);
|
2002-09-13 11:38:36 +00:00
|
|
|
|
|
|
|
/* search for the event to connect */
|
|
|
|
System.Reflection.MemberInfo[] evnts = objekt.GetType ().
|
|
|
|
FindMembers (System.Reflection.MemberTypes.Event,
|
|
|
|
System.Reflection.BindingFlags.Instance
|
|
|
|
| System.Reflection.BindingFlags.Static
|
|
|
|
| System.Reflection.BindingFlags.Public
|
|
|
|
| System.Reflection.BindingFlags.NonPublic,
|
|
|
|
signalFilter, signal_name);
|
|
|
|
foreach (System.Reflection.EventInfo ei in evnts)
|
|
|
|
{
|
|
|
|
bool connected = false;
|
|
|
|
System.Reflection.MethodInfo add = ei.GetAddMethod ();
|
|
|
|
System.Reflection.ParameterInfo[] addpi = add.GetParameters ();
|
|
|
|
if (addpi.Length == 1)
|
|
|
|
{ /* this should be always true, unless there's something broken */
|
|
|
|
Type delegate_type = addpi[0].ParameterType;
|
|
|
|
|
|
|
|
/* look for an instance method */
|
|
|
|
if (connect_object != null) try
|
|
|
|
{
|
|
|
|
Delegate d = Delegate.CreateDelegate
|
|
|
|
(delegate_type, connect_object, handler_name);
|
|
|
|
add.Invoke (objekt, new object[] { d } );
|
|
|
|
connected = true;
|
|
|
|
}
|
|
|
|
catch (ArgumentException)
|
|
|
|
{
|
|
|
|
/* ignore if there is not such instance method */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* look for a static method if no instance method has been found */
|
|
|
|
if (!connected && handler_type != null) try
|
|
|
|
{
|
|
|
|
Delegate d = Delegate.CreateDelegate
|
|
|
|
(delegate_type, handler_type, handler_name);
|
|
|
|
add.Invoke (objekt, new object[] { d } );
|
|
|
|
connected = true;
|
|
|
|
}
|
|
|
|
catch (ArgumentException)
|
|
|
|
{
|
|
|
|
/* ignore if there is not such static method */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!connected)
|
|
|
|
{
|
|
|
|
throw new HandlerNotFoundException (handler_name, signal_name, ei, delegate_type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
System.Reflection.MemberFilter signalFilter = new System.Reflection.MemberFilter (SignalFilter);
|
|
|
|
|
|
|
|
/* matches events to GLib signal names */
|
|
|
|
static bool SignalFilter (System.Reflection.MemberInfo m, object filterCriteria)
|
|
|
|
{
|
|
|
|
string signame = (filterCriteria as string);
|
|
|
|
object[] attrs = m.GetCustomAttributes (typeof (GLib.SignalAttribute), true);
|
|
|
|
if (attrs.Length > 0)
|
|
|
|
{
|
|
|
|
foreach (GLib.SignalAttribute a in attrs)
|
|
|
|
{
|
|
|
|
if (signame == a.CName)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* this tries to match the names when no attibutes are present.
|
|
|
|
It is only a fallback. */
|
|
|
|
signame = signame.ToLower ().Replace ("_", "");
|
|
|
|
string evname = m.Name.ToLower ();
|
|
|
|
return signame == evname;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-01-01 21:37:45 +00:00
|
|
|
|
|
|
|
private void BindFields (object target, Type type)
|
|
|
|
{
|
|
|
|
System.Reflection.BindingFlags flags = System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic;
|
|
|
|
if (target != null)
|
|
|
|
flags |= System.Reflection.BindingFlags.Instance;
|
|
|
|
else
|
|
|
|
flags |= System.Reflection.BindingFlags.Static;
|
|
|
|
|
|
|
|
System.Reflection.FieldInfo[] fields = type.GetFields (flags);
|
|
|
|
if (fields == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
foreach (System.Reflection.FieldInfo field in fields)
|
|
|
|
{
|
2003-03-15 21:02:25 +00:00
|
|
|
object[] attrs = field.GetCustomAttributes (typeof (WidgetAttribute), true);
|
2003-01-01 21:37:45 +00:00
|
|
|
if (attrs == null || attrs.Length == 0)
|
|
|
|
continue;
|
|
|
|
// The widget to field binding must be 1:1, so only check
|
|
|
|
// the first attribute.
|
2003-03-15 21:02:25 +00:00
|
|
|
WidgetAttribute widget = (WidgetAttribute) attrs[0];
|
2003-01-01 23:53:21 +00:00
|
|
|
if (widget.Specified) field.SetValue (target, GetWidget (widget.Name), flags, null, null);
|
|
|
|
else field.SetValue (target, GetWidget (field.Name), flags, null, null);
|
2003-01-01 21:37:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void BindFields (object target)
|
|
|
|
{
|
|
|
|
BindFields (target, target.GetType ());
|
|
|
|
}
|
|
|
|
|
|
|
|
public void BindFields (Type type)
|
|
|
|
{
|
|
|
|
BindFields (null, type);
|
|
|
|
}
|
2003-07-29 00:24:08 +00:00
|
|
|
|
|
|
|
public static Glade.XML FromStream (System.IO.Stream stream, string root, string domain)
|
|
|
|
{
|
|
|
|
return new Glade.XML (stream, root, domain);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Glade.XML FromAssembly (
|
|
|
|
System.Reflection.Assembly assembly, string resource_name, string root, string domain)
|
|
|
|
{
|
|
|
|
return new Glade.XML (assembly, resource_name, root, domain);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Glade.XML FromAssembly (string resource_name, string root, string domain)
|
|
|
|
{
|
|
|
|
return new Glade.XML (
|
|
|
|
System.Reflection.Assembly.GetCallingAssembly (), resource_name, root, domain);
|
|
|
|
}
|
2004-02-12 21:40:01 +00:00
|
|
|
|
|
|
|
[DllImport("libglade-2.0-0.dll")]
|
|
|
|
static extern IntPtr glade_xml_get_widget_prefix(IntPtr raw, string name);
|
|
|
|
|
|
|
|
public Gtk.Widget[] GetWidgetPrefix(string name)
|
|
|
|
{
|
|
|
|
IntPtr raw_ret = glade_xml_get_widget_prefix(Handle, name);
|
|
|
|
if (raw_ret == IntPtr.Zero)
|
|
|
|
return new Gtk.Widget [0];
|
|
|
|
GLib.List list = new GLib.List (raw_ret);
|
|
|
|
Gtk.Widget[] result = new Gtk.Widget [list.Count];
|
|
|
|
int i = 0;
|
|
|
|
foreach (Gtk.Widget w in list)
|
|
|
|
result [i++] = w;
|
|
|
|
return result;
|
|
|
|
}
|