add the 2.1-bootstrap dir to MONO_PATH when running smcs
[moon.git] / src / xaml.h
blob426db0cbfe0897a39ab585142892bdc0b511cf33
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3 * xaml.h: xaml parser
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 __MOON_XAML_H__
14 #define __MOON_XAML_H__
16 #include <glib.h>
18 #include "enums.h"
19 #include "uielement.h"
20 #include "error.h"
21 #include "value.h"
23 class XamlLoader;
25 struct XamlCallbackData {
26 void *loader;
27 void *parser;
28 Value *top_level;
30 XamlCallbackData (void *loader, void *parser, Value *top_level)
32 this->loader = loader;
33 this->parser = parser;
34 this->top_level = top_level;
38 typedef bool (*xaml_lookup_object_callback) (XamlCallbackData *data, Value *parent, const char *xmlns, const char *name, bool create, bool is_property, Value *value, MoonError *error);
39 typedef void (*xaml_create_gchandle_callback) ();
40 typedef bool (*xaml_set_property_callback) (XamlCallbackData *data, const char* xmlns, Value *target, void *target_data, Value *target_parent, const char *prop_xmlns, const char *name, Value *value, void *value_data, MoonError *error);
41 typedef bool (*xaml_import_xaml_xmlns_callback) (XamlCallbackData *data, const char* xmlns, MoonError *error);
42 typedef const char* (*xaml_get_content_property_name_callback) (XamlCallbackData *data, Value *object, MoonError *error);
43 typedef bool (*xaml_add_child_callback) (XamlCallbackData *data, Value *parent_parent, bool parent_is_property, const char* parent_xmlns, Value *parent, void *parent_data, Value *child, void *child_data, MoonError *error);
45 struct XamlLoaderCallbacks {
47 xaml_lookup_object_callback lookup_object;
48 xaml_create_gchandle_callback create_gchandle;
49 xaml_set_property_callback set_property;
50 xaml_import_xaml_xmlns_callback import_xaml_xmlns;
51 xaml_get_content_property_name_callback get_content_property_name;
52 xaml_add_child_callback add_child;
54 XamlLoaderCallbacks () :
55 lookup_object (NULL),
56 set_property (NULL),
57 import_xaml_xmlns (NULL),
58 get_content_property_name (NULL),
59 add_child (NULL)
66 // Used by the templates
69 class XamlContextInternal;
71 class XamlContext {
73 public:
74 XamlContextInternal *internal;
76 XamlContext (XamlContextInternal *internal);
77 ~XamlContext ();
79 void SetTemplateBindingSource (DependencyObject *source);
81 /* @GenerateCBinding,GeneratePInvoke */
82 DependencyObject* GetTemplateBindingSource ();
86 G_BEGIN_DECLS
88 void xaml_init (void);
90 bool xaml_set_property_from_str (DependencyObject *obj, DependencyProperty *prop, const char *value, MoonError *error);
92 bool time_span_from_str (const char *str, TimeSpan *res);
93 /* @GeneratePInvoke */
94 bool value_from_str_with_typename (const char *type_name, const char *prop_name, const char *str, /* @MarshalAs=IntPtr,IsOut */ Value **v);
95 /* @GeneratePInvoke */
96 bool value_from_str (Type::Kind type, const char *prop_name, const char *str, /* @MarshalAs=IntPtr,IsOut */ Value **v);
97 bool convert_property_value_to_enum_str (DependencyProperty *prop, Value *v, const char **s);
99 void xaml_parse_xmlns (const char *xmlns, char **type_name, char **ns, char **assembly);
101 bool xaml_is_valid_event_name (Type::Kind kind, const char *name, bool allow_desktop_events);
103 /* @GeneratePInvoke */
104 XamlLoader *xaml_loader_new (const char *resourceBase, const char *filename, const char *str, Surface *surface);
105 /* @GeneratePInvoke */
106 void xaml_loader_free (XamlLoader *loader);
107 /* @GeneratePInvoke */
108 void xaml_loader_set_callbacks (XamlLoader *loader, XamlLoaderCallbacks callbacks);
110 /* @GeneratePInvoke */
111 char* xaml_uri_for_prefix (void *parser, char* prefix);
114 /* @GeneratePInvoke */
115 Value* xaml_lookup_named_item (void *parser, void *element_instance, const char* name);
116 /* @GeneratePInvoke */
117 void* xaml_get_template_parent (void *parser, void *element_instance);
118 /* @GeneratePInvoke */
119 char* xaml_get_element_key (void *parser, void *element_instance);
120 /* @GeneratePInvoke */
121 char* xaml_get_element_name (void *parser, void *element_instance);
122 /* @GeneratePInvoke */
123 bool xaml_is_property_set (void *parser, void *element_instance, char *name);
124 /* @GeneratePInvoke */
125 void xaml_mark_property_as_set (void *parser, void *element_instance, char *name);
127 G_END_DECLS
131 Plugin:
132 - calls PluginXamlLoader::TryLoad to try to load some xaml.
133 - calls xaml_create_from_*
134 - calls XamlLoader::LookupObject (,) if it encounters xmlns/name
135 - parses the xmlns and name
136 - calls XamlLoader::LoadVM.
137 - PluginXamlLoader::LoadVM will load the vm and create a ManagedXamlLoader (which will set the callbacks in XamlLoader)
138 - calls XamlLoader::CreateObject (,,,) with the parsed xml
139 - calls the create_managed_object callback (if any).
140 - will try to load the assembly, if it fails, it's requested.
141 - if XamlLoader::CreateObject failed, try to download the missing assembly (if any).
142 - if no missing assembly, the xaml load fails.
144 Deskop:
145 - calls System.Windows.XamlReader::Load
146 - creates a ManagedXamlLoader and a native XamlLoader (setting the callbacks).
147 - calls xaml_create_from_str
148 - calls XamlLoader::CreateObject (,) if it encounters xmlns/name
149 - parses the xmlns and name
150 - calls XamlLoader::LoadVM (which does nothing).
151 - calls XamlLoader::CreateObject (,,,) with the parsed xml
152 - calls the create_managed_object callback (if any).
153 - will try to load the assembly, if it fails, it's requested.
154 - destroy the native/managed XamlLoader. Any requested assemblies are ignored, no retries are done.
158 class XamlLoader {
159 bool expanding_template;
160 Surface *surface;
161 char *filename;
162 char *resource_base;
163 char *str;
164 XamlContext *context;
165 bool import_default_xmlns;
167 void Initialize (const char *resourceBase, const char *filename, const char *str, Surface *surface, XamlContext *context);
168 public:
170 XamlLoader (const char *filename, const char *str, Surface *surface, XamlContext *context = NULL);
171 XamlLoader (const char *resourceBase, const char *filename, const char *str, Surface *surface, XamlContext *context = NULL);
172 virtual ~XamlLoader ();
174 virtual bool LoadVM ();
176 virtual bool LookupObject (void *p, Value* top_element, Value* parent, const char* xmlns, const char* name, bool create, bool is_property, Value *value);
177 virtual bool SetProperty (void *p, Value *top_level, const char* xmlns, Value *target, void *target_data, Value *target_parent, const char *prop_xmlns, const char *name, Value *value, void *value_data);
178 virtual bool AddChild (void *p, Value *top_level, Value *parent_parent, bool parent_is_property, const char* parent_xmlns, Value *parent, void *parent_data, Value *child, void *child_data);
180 virtual const char *GetContentPropertyName (void *p, Value *top_level, Value *object);
182 // Loaders can override to have the default namespace added, this is for things like plugin.CreateFromXaml
183 virtual bool ImportDefaultXmlns () { return import_default_xmlns; }
184 void SetImportDefaultXmlns (bool v) { import_default_xmlns = v; }
186 char *GetFilename () { return filename; }
187 char *GetString () { return str; }
188 Surface *GetSurface () { return surface; }
189 char *GetResourceBase () { return resource_base; }
191 bool GetExpandingTemplate () { return expanding_template; }
192 void SetExpandingTemplate (bool value) { expanding_template = value; }
194 /* @GenerateCBinding,GeneratePInvoke */
195 XamlContext *GetContext () { return context; }
197 bool vm_loaded;
199 DependencyObject* CreateDependencyObjectFromString (const char *xaml, bool create_namescope, Type::Kind *element_type);
200 DependencyObject* CreateDependencyObjectFromFile (const char *xaml, bool create_namescope, Type::Kind *element_type);
202 Value* CreateFromFile (const char *xaml, bool create_namescope, Type::Kind *element_type);
203 Value* CreateFromString (const char *xaml, bool create_namescope, bool validate_templates, Type::Kind *element_type);
204 Value* HydrateFromString (const char *xaml, Value *object, bool create_namescope, bool validate_templates, Type::Kind *element_type);
206 /* @GenerateCBinding,GeneratePInvoke */
207 Value* CreateFromFileWithError (const char *xaml, bool create_namescope, Type::Kind *element_type, MoonError *error);
208 /* @GenerateCBinding,GeneratePInvoke */
209 Value* CreateFromStringWithError (const char *xaml, bool create_namescope, bool validate_templates, Type::Kind *element_type, MoonError *error);
210 /* @GenerateCBinding,GeneratePInvoke */
211 Value* HydrateFromStringWithError (const char *xaml, Value *obj, bool create_namescope, bool validate_templates, Type::Kind *element_type, MoonError *error);
213 XamlLoaderCallbacks callbacks;
214 ParserErrorEventArgs *error_args;
218 #endif /* __MOON_XAML_H__ */