2009-11-08 Chris Toshok <toshok@ximian.com>
[moon.git] / src / type.h.in
blob6015efa7e02300092322cea9c443a29311f0e7da
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3 * type.h: Generated code for the type system.
5 * Contact:
6 * Moonlight List (moonlight-list@lists.ximian.com)
8 * Copyright 2007 Novell, Inc. (http://www.novell.com)
10 * See the LICENSE file included with the distribution for details.
13 #ifndef __TYPE_H__
14 #define __TYPE_H__
16 #include <glib.h>
17 #include "list.h"
19 class Deployment;
20 class DependencyObject;
21 class DependencyProperty;
22 class Surface;
23 class Types;
25 /* @CBindingRequisite */
26 typedef gint64 TimeSpan;
27 typedef DependencyObject *create_inst_func (void);
29 class Type {
30 public:
31 enum Kind {
32 // START_MANAGED_MAPPING
33 INVALID,
34 /*DO_KINDS*/
35 LASTTYPE,
36 // END_MANAGED_MAPPING
39 static Type *Find (Deployment *deployment, const char *name);
40 static Type *Find (const char *name);
41 static Type *Find (Deployment *deployment, Type::Kind type);
42 static Type *Find (Type::Kind type);
43 static Type *Find (Deployment *deployment, const char *name, bool ignore_case);
44 static Type *Find (const char *name, bool ignore_case);
46 bool IsSubclassOf (Type::Kind super);
47 bool IsSubclassOf (Deployment *deployment, Type::Kind super);
48 static bool IsSubclassOf (Deployment *deployment, Type::Kind type, Type::Kind super);
49 static bool IsSubclassOf (Type::Kind type, Type::Kind super);
51 bool IsAssignableFrom (Type::Kind type);
52 bool IsAssignableFrom (Deployment *deployment, Type::Kind type);
53 static bool IsAssignableFrom (Deployment *deployment, Type::Kind assignable, Type::Kind type);
54 static bool IsAssignableFrom (Type::Kind assignable, Type::Kind type);
56 int LookupEvent (Deployment *deployment, const char *event_name);
57 int LookupEvent (const char *event_name);
58 const char *LookupEventName (int id);
59 DependencyObject *CreateInstance ();
60 const char *GetContentPropertyName ();
62 DependencyProperty *LookupProperty (const char *name);
63 void AddProperty (DependencyProperty *property);
65 GHashTable *CopyProperties (bool inherited);
67 Type::Kind GetKind () { return type; }
68 void SetKind (Type::Kind value) { type = value; }
69 Type::Kind GetParent () { return parent; }
70 bool IsValueType () { return is_value_type; }
71 bool IsInterface () { return is_interface; }
72 bool IsCustomType () { return type > LASTTYPE; }
73 const char *GetName () { return name; }
74 int GetEventCount () { return total_event_count; }
75 int GetInterfaceCount () { return interface_count; }
76 Type::Kind GetInterface (int i) { return i >= 0 && i < interface_count ? interfaces[i] : Type::INVALID; }
78 bool IsCtorVisible () { return ctor_visible; }
80 ~Type ();
81 Type (Type::Kind type, Type::Kind parent, bool is_value_type, bool is_interface,
82 const char *name,
83 int event_count, int total_event_count, const char **events,
84 int interface_count, const Type::Kind *interfaces, bool ctor_visible,
85 create_inst_func *create_inst, const char *content_property);
87 private:
88 Type () {}
90 Type::Kind type; // this type
91 Type::Kind parent; // parent type, INVALID if no parent
92 bool is_value_type; // if this type is a value type
93 bool is_interface; // if this type is a value type
95 const char *name; // The name as it appears in code.
97 int interface_count;
98 Type::Kind *interfaces;
100 int event_count; // number of events in this class
101 int total_event_count; // number of events in this class and all base classes
102 const char **events; // the events this class has
104 bool ctor_visible; // if the type is instantiable in xaml, basically if the managed type has a public default ctor.
105 create_inst_func *create_inst; // a function pointer to create an instance of this type
107 const char *content_property;
109 // The catch here is that SL allows us to register several DPs with the same name,
110 // and when looking up DP on name they seem to return the latest DP registered
111 // with that name.
112 GHashTable *properties; // Registered DependencyProperties for this type
115 class Types {
116 friend class Type;
118 private:
119 ArrayList types;
120 ArrayList properties;
122 void RegisterNativeTypes ();
123 void RegisterNativeProperties ();
125 public:
126 /* @GenerateCBinding,GeneratePInvoke,Version=2.0 */
127 Types ();
128 /* @GenerateCBinding,GeneratePInvoke,Version=2.0 */
129 ~Types ();
131 /* @GenerateCBinding,Version=2.0 */
132 Type::Kind RegisterType (const char *name, void *gc_handle, Type::Kind parent, bool is_interface, bool ctor_visible, Type::Kind *interfaces, int interface_count);
134 void AddProperty (DependencyProperty *property);
135 DependencyProperty *GetProperty (int id);
137 /* @GenerateCBinding,GeneratePInvoke,Version=2.0 */
138 Type *Find (Type::Kind type);
139 Type *Find (const char *name);
140 Type *Find (const char *name, bool ignore_case);
142 bool IsSubclassOf (Type::Kind type, Type::Kind super);
143 bool IsSubclassOrSuperclassOf (Type::Kind unknown, Type::Kind known);
144 static bool IsSubclassOrSuperclassOf (Types *types, Type::Kind unknown, Type::Kind known);
146 bool IsAssignableFrom (Type::Kind destination, Type::Kind type);
148 void Initialize ();
149 void Dispose ();
150 void DeleteProperties ();
153 G_BEGIN_DECLS
155 /* @GeneratePInvoke */
156 bool type_get_value_type (Type::Kind type);
157 DependencyObject *type_create_instance (Type *type);
158 DependencyObject *type_create_instance_from_kind (Type::Kind kind);
160 void types_init (void);
161 const char *type_get_name (Type::Kind type);
162 /* @GeneratePInvoke */
163 bool type_is_dependency_object (Type::Kind type);
165 /* @IncludeInKinds */
166 struct ManagedTypeInfo {
167 char *assembly_name;
168 char *full_name;
170 ManagedTypeInfo (const char *assembly_name, const char *full_name)
172 this->assembly_name = g_strdup (assembly_name);
173 this->full_name = g_strdup (full_name);
177 G_END_DECLS
179 #endif