2009-06-17 Jeffrey Stedfast <fejj@novell.com>
[moon.git] / src / type.h.in
blobef19bfeeb93782e3cc8df08d8ee86e4ed63dcc1a
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 DependencyObject;
20 class DependencyProperty;
21 class Surface;
22 class Types;
24 /* @CBindingRequisite */
25 typedef gint64 TimeSpan;
26 typedef DependencyObject *create_inst_func (void);
28 class Type {
29 public:
30 enum Kind {
31 // START_MANAGED_MAPPING
32 INVALID,
33 /*DO_KINDS*/
34 LASTTYPE,
35 // END_MANAGED_MAPPING
38 static Type *Find (const char *name);
39 static Type *Find (Type::Kind type);
40 static Type *Find (const char *name, bool ignore_case);
42 bool IsSubclassOf (Type::Kind super);
43 static bool IsSubclassOf (Type::Kind type, Type::Kind super);
45 bool IsAssignableFrom (Type::Kind type);
46 static bool IsAssignableFrom (Type::Kind assignable, Type::Kind type);
48 int LookupEvent (const char *event_name);
49 const char *LookupEventName (int id);
50 DependencyObject *CreateInstance ();
51 const char *GetContentPropertyName ();
53 DependencyProperty *LookupProperty (const char *name);
54 void AddProperty (DependencyProperty *property);
56 GHashTable *CopyProperties (bool inherited);
58 Type::Kind GetKind () { return type; }
59 void SetKind (Type::Kind value) { type = value; }
60 Type::Kind GetParent () { return parent; }
61 bool IsValueType () { return is_value_type; }
62 bool IsInterface () { return is_interface; }
63 bool IsCustomType () { return type > LASTTYPE; }
64 const char *GetName () { return name; }
65 int GetEventCount () { return total_event_count; }
66 int GetInterfaceCount () { return interface_count; }
67 Type::Kind GetInterface (int i) { return i >= 0 && i < interface_count ? interfaces[i] : Type::INVALID; }
69 bool IsCtorVisible () { return ctor_visible; }
71 ~Type ();
72 Type (Type::Kind type, Type::Kind parent, bool is_value_type, bool is_interface,
73 const char *name,
74 int event_count, int total_event_count, const char **events,
75 int interface_count, const Type::Kind *interfaces, bool ctor_visible,
76 create_inst_func *create_inst, const char *content_property);
78 private:
79 Type () {}
81 Type::Kind type; // this type
82 Type::Kind parent; // parent type, INVALID if no parent
83 bool is_value_type; // if this type is a value type
84 bool is_interface; // if this type is a value type
86 const char *name; // The name as it appears in code.
88 int interface_count;
89 Type::Kind *interfaces;
91 int event_count; // number of events in this class
92 int total_event_count; // number of events in this class and all base classes
93 const char **events; // the events this class has
95 bool ctor_visible; // if the type is instantiable in xaml, basically if the managed type has a public default ctor.
96 create_inst_func *create_inst; // a function pointer to create an instance of this type
98 const char *content_property;
100 // The catch here is that SL allows us to register several DPs with the same name,
101 // and when looking up DP on name they seem to return the latest DP registered
102 // with that name.
103 GHashTable *properties; // Registered DependencyProperties for this type
106 class Types {
107 friend class Type;
109 private:
110 ArrayList types;
111 ArrayList properties;
112 bool disposed;
114 void RegisterNativeTypes ();
115 void RegisterNativeProperties ();
117 public:
118 /* @GenerateCBinding,GeneratePInvoke,Version=2.0 */
119 Types ();
120 /* @GenerateCBinding,GeneratePInvoke,Version=2.0 */
121 ~Types ();
123 /* @GenerateCBinding,Version=2.0 */
124 Type::Kind RegisterType (const char *name, void *gc_handle, Type::Kind parent, bool is_interface, bool ctor_visible, Type::Kind *interfaces, int interface_count);
126 void AddProperty (DependencyProperty *property);
127 DependencyProperty *GetProperty (int id);
129 /* @GenerateCBinding,GeneratePInvoke,Version=2.0 */
130 Type *Find (Type::Kind type);
131 Type *Find (const char *name);
132 Type *Find (const char *name, bool ignore_case);
134 bool IsSubclassOf (Type::Kind type, Type::Kind super);
135 bool IsSubclassOrSuperclassOf (Type::Kind unknown, Type::Kind known);
136 static bool IsSubclassOrSuperclassOf (Types *types, Type::Kind unknown, Type::Kind known);
138 bool IsAssignableFrom (Type::Kind destination, Type::Kind type);
140 void Initialize ();
141 void Dispose ();
144 G_BEGIN_DECLS
146 /* @GeneratePInvoke */
147 bool type_get_value_type (Type::Kind type);
148 DependencyObject *type_create_instance (Type *type);
149 DependencyObject *type_create_instance_from_kind (Type::Kind kind);
151 void types_init (void);
152 const char *type_get_name (Type::Kind type);
153 /* @GeneratePInvoke */
154 bool type_is_dependency_object (Type::Kind type);
156 /* @IncludeInKinds */
157 struct ManagedTypeInfo {
158 char *assembly_name;
159 char *full_name;
161 ManagedTypeInfo (const char *assembly_name, const char *full_name)
163 this->assembly_name = g_strdup (assembly_name);
164 this->full_name = g_strdup (full_name);
168 G_END_DECLS
170 #endif