1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
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__
19 #include "uielement.h"
25 struct XamlCallbackData
{
31 XamlCallbackData (void *loader
, void *parser
, Value
*top_level
, int flags
= 0)
33 this->loader
= loader
;
34 this->parser
= parser
;
35 this->top_level
= top_level
;
39 enum XamlCallbackFlagsEnum
{
41 SETTING_DELAYED_PROPERTY
= 2
46 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
);
47 typedef void (*xaml_create_gchandle_callback
) ();
48 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
);
49 typedef bool (*xaml_import_xaml_xmlns_callback
) (XamlCallbackData
*data
, const char* xmlns
, MoonError
*error
);
50 typedef const char* (*xaml_get_content_property_name_callback
) (XamlCallbackData
*data
, Value
*object
, MoonError
*error
);
51 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
);
53 struct XamlLoaderCallbacks
{
55 xaml_lookup_object_callback lookup_object
;
56 xaml_create_gchandle_callback create_gchandle
;
57 xaml_set_property_callback set_property
;
58 xaml_import_xaml_xmlns_callback import_xaml_xmlns
;
59 xaml_get_content_property_name_callback get_content_property_name
;
60 xaml_add_child_callback add_child
;
62 XamlLoaderCallbacks () :
65 import_xaml_xmlns (NULL
),
66 get_content_property_name (NULL
),
74 // Used by the templates
77 class XamlContextInternal
;
82 XamlContextInternal
*internal
;
84 XamlContext (XamlContextInternal
*internal
);
87 void SetTemplateBindingSource (DependencyObject
*source
);
89 /* @GenerateCBinding,GeneratePInvoke */
90 DependencyObject
* GetTemplateBindingSource ();
96 void xaml_init (void);
98 bool xaml_set_property_from_str (DependencyObject
*obj
, DependencyProperty
*prop
, const char *value
, MoonError
*error
);
100 bool time_span_from_str (const char *str
, TimeSpan
*res
);
101 /* @GeneratePInvoke */
102 bool value_from_str_with_typename (const char *type_name
, const char *prop_name
, const char *str
, /* @MarshalAs=IntPtr,IsOut */ Value
**v
);
103 /* @GeneratePInvoke */
104 bool value_from_str (Type::Kind type
, const char *prop_name
, const char *str
, /* @MarshalAs=IntPtr,IsOut */ Value
**v
);
105 bool convert_property_value_to_enum_str (DependencyProperty
*prop
, Value
*v
, const char **s
);
107 void xaml_parse_xmlns (const char *xmlns
, char **type_name
, char **ns
, char **assembly
);
109 bool xaml_is_valid_event_name (Type::Kind kind
, const char *name
, bool allow_desktop_events
);
111 bool xaml_bool_from_str (const char *s
, bool *res
);
113 /* @GeneratePInvoke */
114 XamlLoader
*xaml_loader_new (const char *resourceBase
, const char *filename
, const char *str
, Surface
*surface
);
115 /* @GeneratePInvoke */
116 void xaml_loader_free (XamlLoader
*loader
);
117 /* @GeneratePInvoke */
118 void xaml_loader_set_callbacks (XamlLoader
*loader
, XamlLoaderCallbacks callbacks
);
120 /* @GeneratePInvoke */
121 char* xaml_uri_for_prefix (void *parser
, char* prefix
);
124 /* @GeneratePInvoke */
125 Value
* xaml_lookup_named_item (void *parser
, void *element_instance
, const char* name
);
126 /* @GeneratePInvoke */
127 void* xaml_get_template_parent (void *parser
, void *element_instance
);
128 /* @GeneratePInvoke */
129 char* xaml_get_element_key (void *parser
, void *element_instance
);
130 /* @GeneratePInvoke */
131 char* xaml_get_element_name (void *parser
, void *element_instance
);
132 /* @GeneratePInvoke */
133 bool xaml_is_property_set (void *parser
, void *element_instance
, char *name
);
134 /* @GeneratePInvoke */
135 void xaml_mark_property_as_set (void *parser
, void *element_instance
, char *name
);
136 /* @GeneratePInvoke */
137 void xaml_delay_set_property (void *parser
, void *element_instance
, const char *xmlns
, const char *name
, const Value
*value
);
144 - calls PluginXamlLoader::TryLoad to try to load some xaml.
145 - calls xaml_create_from_*
146 - calls XamlLoader::LookupObject (,) if it encounters xmlns/name
147 - parses the xmlns and name
148 - calls XamlLoader::LoadVM.
149 - PluginXamlLoader::LoadVM will load the vm and create a ManagedXamlLoader (which will set the callbacks in XamlLoader)
150 - calls XamlLoader::CreateObject (,,,) with the parsed xml
151 - calls the create_managed_object callback (if any).
152 - will try to load the assembly, if it fails, it's requested.
153 - if XamlLoader::CreateObject failed, try to download the missing assembly (if any).
154 - if no missing assembly, the xaml load fails.
157 - calls System.Windows.XamlReader::Load
158 - creates a ManagedXamlLoader and a native XamlLoader (setting the callbacks).
159 - calls xaml_create_from_str
160 - calls XamlLoader::CreateObject (,) if it encounters xmlns/name
161 - parses the xmlns and name
162 - calls XamlLoader::LoadVM (which does nothing).
163 - calls XamlLoader::CreateObject (,,,) with the parsed xml
164 - calls the create_managed_object callback (if any).
165 - will try to load the assembly, if it fails, it's requested.
166 - destroy the native/managed XamlLoader. Any requested assemblies are ignored, no retries are done.
171 bool expanding_template
;
176 XamlContext
*context
;
177 bool import_default_xmlns
;
180 void Initialize (const char *resourceBase
, const char *filename
, const char *str
, Surface
*surface
, XamlContext
*context
);
183 enum XamlLoaderFlags
{
185 VALIDATE_TEMPLATES
= 2,
186 IMPORT_DEFAULT_XMLNS
= 4
189 XamlLoader (const char *filename
, const char *str
, Surface
*surface
, XamlContext
*context
= NULL
);
190 XamlLoader (const char *resourceBase
, const char *filename
, const char *str
, Surface
*surface
, XamlContext
*context
= NULL
);
191 virtual ~XamlLoader ();
193 virtual bool LoadVM ();
195 virtual bool LookupObject (void *p
, Value
* top_element
, Value
* parent
, const char* xmlns
, const char* name
, bool create
, bool is_property
, Value
*value
);
196 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
, int flags
= 0);
197 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
);
199 virtual const char *GetContentPropertyName (void *p
, Value
*top_level
, Value
*object
);
201 // Loaders can override to have the default namespace added, this is for things like plugin.CreateFromXaml
202 virtual bool ImportDefaultXmlns () { return import_default_xmlns
; }
203 void SetImportDefaultXmlns (bool v
) { import_default_xmlns
= v
; }
205 char *GetFilename () { return filename
; }
206 char *GetString () { return str
; }
207 Surface
*GetSurface () { return surface
; }
208 char *GetResourceBase () { return resource_base
; }
210 bool GetExpandingTemplate () { return expanding_template
; }
211 void SetExpandingTemplate (bool value
) { expanding_template
= value
; }
213 /* @GenerateCBinding,GeneratePInvoke */
214 XamlContext
*GetContext () { return context
; }
218 DependencyObject
* CreateDependencyObjectFromString (const char *xaml
, bool create_namescope
, Type::Kind
*element_type
);
219 DependencyObject
* CreateDependencyObjectFromFile (const char *xaml
, bool create_namescope
, Type::Kind
*element_type
);
221 Value
* CreateFromFile (const char *xaml
, bool create_namescope
, Type::Kind
*element_type
);
222 Value
* CreateFromString (const char *xaml
, bool create_namescope
, Type::Kind
*element_type
, int flags
);
223 Value
* HydrateFromString (const char *xaml
, Value
*object
, bool create_namescope
, Type::Kind
*element_type
, int flags
);
225 /* @GenerateCBinding,GeneratePInvoke */
226 Value
* CreateFromFileWithError (const char *xaml
, bool create_namescope
, Type::Kind
*element_type
, MoonError
*error
);
227 /* @GenerateCBinding,GeneratePInvoke */
228 Value
* CreateFromStringWithError (const char *xaml
, bool create_namescope
, Type::Kind
*element_type
, int flags
, MoonError
*error
);
229 /* @GenerateCBinding,GeneratePInvoke */
230 Value
* HydrateFromStringWithError (const char *xaml
, Value
*obj
, bool create_namescope
, Type::Kind
*element_type
, int flags
, MoonError
*error
);
232 XamlLoaderCallbacks callbacks
;
233 ParserErrorEventArgs
*error_args
;
237 #endif /* __MOON_XAML_H__ */