2009-12-01 Jeffrey Stedfast <fejj@novell.com>
[moon.git] / src / template.cpp
blob6a90f9dc33ae341a74db57891318b56d3a7aee0a
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3 * template.cpp:
5 * Contact:
6 * Moonlight List (moonlight-list@lists.ximian.com)
8 * Copyright 2008 Novell, Inc. (http://www.novell.com)
10 * See the LICENSE file included with the distribution for details.
15 #include <config.h>
16 #include "template.h"
17 #include "namescope.h"
18 #include "deployment.h"
20 FrameworkTemplate::FrameworkTemplate ()
22 SetObjectType (Type::FRAMEWORKTEMPLATE);
24 xaml_buffer = NULL;
25 xaml_context = NULL;
28 FrameworkTemplate::~FrameworkTemplate ()
30 if (xaml_buffer) {
31 g_free (xaml_buffer);
32 xaml_buffer = NULL;
34 delete xaml_context;
35 xaml_context = NULL;
38 void
39 FrameworkTemplate::SetXamlBuffer (XamlContext *xaml_context, const char *xaml_buffer)
41 // printf ("%p setting xaml buffer to %s\n", this, xaml_buffer);
42 this->xaml_buffer = g_strdup (xaml_buffer);
43 this->xaml_context = xaml_context;
46 DependencyObject*
47 FrameworkTemplate::GetVisualTree (FrameworkElement *templateBindingSource)
49 if (xaml_buffer) {
50 XamlLoader *loader = new XamlLoader (GetResourceBase(), NULL, xaml_buffer, GetDeployment ()->GetSurface(), xaml_context);
51 Type::Kind dummy;
53 loader->SetExpandingTemplate (true);
54 loader->SetTemplateOwner (templateBindingSource);
55 loader->SetImportDefaultXmlns (true);
57 xaml_context->SetTemplateBindingSource (templateBindingSource);
59 DependencyObject *result = loader->CreateDependencyObjectFromString (xaml_buffer, true, &dummy);
61 delete loader;
63 if (result)
64 NameScope::GetNameScope (result)->Lock ();
65 return result;
68 return NULL;
71 ControlTemplate::ControlTemplate ()
73 SetObjectType (Type::CONTROLTEMPLATE);
76 DataTemplate::DataTemplate ()
78 SetObjectType (Type::DATATEMPLATE);
81 DependencyObject *
82 DataTemplate::GetVisualTree (FrameworkElement *templateBindingSource)
84 // DataTemplate ignores the source paramater and always uses null
85 return FrameworkTemplate::GetVisualTree (NULL);