2
using System.Collections;
3
using System.Reflection;
4
using System.Runtime.InteropServices;
10
public abstract class ClassDescriptor
12
protected string label, category, cname;
13
protected bool deprecated, hexpandable, vexpandable, allowChildren = true;
15
protected ItemGroupCollection groups = new ItemGroupCollection ();
16
protected ItemGroupCollection signals = new ItemGroupCollection ();
18
protected int importantGroups;
19
protected ItemGroup contextMenu;
20
protected ItemGroup internalChildren;
21
protected string baseType;
22
protected bool isInternal;
23
protected string targetGtkVersion;
25
WidgetLibrary library;
26
PropertyDescriptor[] initializationProperties;
27
static PropertyDescriptor[] emptyPropArray = new PropertyDescriptor[0];
31
protected void Load (XmlElement elem)
33
if (elem.HasAttribute ("cname"))
34
cname = elem.GetAttribute ("cname");
35
else if (cname == null)
36
cname = elem.GetAttribute ("type");
38
label = elem.GetAttribute ("label");
40
label = WrappedTypeName;
41
int i = label.LastIndexOf ('.');
43
label = label.Substring (i+1);
46
if (elem.HasAttribute ("allow-children"))
47
allowChildren = elem.GetAttribute ("allow-children") == "yes" || elem.GetAttribute ("allow-children") == "true";
49
category = elem.GetAttribute ("palette-category");
51
if (elem.HasAttribute ("deprecated"))
53
if (elem.HasAttribute ("hexpandable"))
55
if (elem.HasAttribute ("vexpandable"))
57
if (elem.GetAttribute ("internal") == "true")
60
contextMenu = ItemGroup.Empty;
62
baseType = elem.GetAttribute ("base-type");
63
if (baseType.Length > 0) {
64
ClassDescriptor basec = Registry.LookupClassByName (baseType);
66
throw new InvalidOperationException ("Base type '" + baseType + "' not found.");
67
foreach (ItemGroup group in basec.ItemGroups)
69
foreach (ItemGroup group in basec.SignalGroups)
71
contextMenu = basec.ContextMenu;
75
XmlElement groupsElem = elem["itemgroups"];
76
if (groupsElem != null) {
77
foreach (XmlElement groupElem in groupsElem.SelectNodes ("itemgroup")) {
80
if (groupElem.HasAttribute ("ref")) {
81
string refname = groupElem.GetAttribute ("ref");
82
itemgroup = Registry.LookupItemGroup (refname);
84
itemgroup = new ItemGroup (groupElem, this);
85
groups.Add (itemgroup);
87
if (groupElem.HasAttribute ("important")) {
88
if (groupElem.GetAttribute ("important") == "true")
90
} else if (groups.Count == 1)
95
XmlElement signalsElem = elem["signals"];
96
if (signalsElem != null) {
97
foreach (XmlElement groupElem in signalsElem.SelectNodes ("itemgroup")) {
99
if (groupElem.HasAttribute ("ref")) {
100
string refname = groupElem.GetAttribute ("ref");
101
itemgroup = Registry.LookupSignalGroup (refname);
103
itemgroup = new ItemGroup (groupElem, this);
104
signals.Add (itemgroup);
108
XmlElement contextElem = elem["contextmenu"];
109
if (contextElem != null) {
110
if (contextElem.HasAttribute ("ref")) {
111
string refname = contextElem.GetAttribute ("ref");
112
contextMenu = Registry.LookupContextMenu (refname);
114
contextMenu = new ItemGroup (contextElem, this);
117
XmlElement ichildElem = elem["internal-children"];
118
if (ichildElem != null)
119
internalChildren = new ItemGroup (ichildElem, this);
121
internalChildren = ItemGroup.Empty;
123
string initProps = elem.GetAttribute ("init-properties");
124
if (initProps.Length > 0) {
125
string[] props = initProps.Split (' ');
126
ArrayList list = new ArrayList ();
127
foreach (string prop in props) {
128
PropertyDescriptor idesc = this [prop] as PropertyDescriptor;
130
throw new InvalidOperationException ("Initialization property not found: " + prop);
133
initializationProperties = (PropertyDescriptor[]) list.ToArray (typeof(PropertyDescriptor));
135
initializationProperties = emptyPropArray;
137
targetGtkVersion = elem.GetAttribute ("gtk-version");
138
if (targetGtkVersion.Length == 0)
139
targetGtkVersion = null;
142
public virtual string Name {
144
return WrappedTypeName;
148
public virtual bool IsInternal {
149
get { return isInternal; }
152
public abstract string WrappedTypeName {
156
public string CName {
162
public bool Deprecated {
168
public bool HExpandable {
174
public bool VExpandable {
180
public string Label {
186
public abstract Gdk.Pixbuf Icon {
190
public string Category {
196
public virtual string TargetGtkVersion {
198
if (targetGtkVersion == null)
199
return library.TargetGtkVersion;
201
return targetGtkVersion;
205
public bool SupportsGtkVersion (string targetVersion)
207
return WidgetUtils.CompareVersions (TargetGtkVersion, targetVersion) >= 0;
210
public PropertyDescriptor[] InitializationProperties {
211
get { return initializationProperties; }
214
public object NewInstance (IProject proj)
216
return NewInstance (proj, true);
219
public object NewInstance (IProject proj, bool initialize)
221
object ob = CreateInstance (proj);
223
string name = WrappedTypeName.ToLower () + (++counter).ToString ();
224
int i = name.LastIndexOf ('.');
227
name = name.Substring (i+1);
229
name = name.Replace (".", "");
232
foreach (ItemGroup group in groups) {
233
foreach (ItemDescriptor item in group) {
234
PropertyDescriptor prop = item as PropertyDescriptor;
235
if (prop != null && prop.InitWithName)
236
prop.SetValue (ob, name);
240
ObjectWrapper ow = CreateWrapper ();
241
ObjectWrapper.Bind (proj, this, ow, ob, !initialize);
245
// Sets the default values for an instance
246
public virtual void ResetInstance (object obj)
248
foreach (ItemGroup group in groups) {
249
foreach (ItemDescriptor item in group) {
250
PropertyDescriptor prop = item as PropertyDescriptor;
252
prop.ResetValue (obj);
257
public abstract object CreateInstance (IProject proj);
259
public abstract ObjectWrapper CreateWrapper ();
261
public ItemDescriptor this[string name] {
263
if (groups != null) {
264
foreach (ItemGroup group in groups) {
265
ItemDescriptor item = group[name];
275
public ItemGroupCollection ItemGroups {
281
public ItemGroupCollection SignalGroups {
287
public int ImportantGroups {
289
return importantGroups;
293
public ItemGroup ContextMenu {
299
public ItemGroup InternalChildren {
301
return internalChildren;
305
public WidgetLibrary Library {
306
get { return library; }
309
public virtual bool AllowChildren {
310
get { return allowChildren; }
313
internal protected virtual ItemDescriptor CreateItemDescriptor (XmlElement elem, ItemGroup group)
315
if (elem.Name == "command")
316
return new CommandDescriptor (elem, group, this);
318
throw new ApplicationException ("Bad item name " + elem.Name + " in " + WrappedTypeName);
321
internal void SetLibrary (WidgetLibrary library)
323
this.library = library;