add the 2.1-bootstrap dir to MONO_PATH when running smcs
[moon.git] / src / template.cpp
blob5768aabc23173d950dc8678d2e4941452fe6d023
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"
19 FrameworkTemplate::FrameworkTemplate ()
21 SetObjectType (Type::FRAMEWORKTEMPLATE);
23 xaml_buffer = NULL;
24 xaml_context = NULL;
27 FrameworkTemplate::~FrameworkTemplate ()
29 if (xaml_buffer) {
30 g_free (xaml_buffer);
31 xaml_buffer = NULL;
33 delete xaml_context;
34 xaml_context = NULL;
37 void
38 FrameworkTemplate::SetXamlBuffer (XamlContext *xaml_context, const char *xaml_buffer)
40 // printf ("%p setting xaml buffer to %s\n", this, xaml_buffer);
41 this->xaml_buffer = g_strdup (xaml_buffer);
42 this->xaml_context = xaml_context;
45 DependencyObject*
46 FrameworkTemplate::GetVisualTree (FrameworkElement *templateBindingSource)
48 if (xaml_buffer) {
49 XamlLoader *loader = new XamlLoader (GetResourceBase(), NULL, xaml_buffer, GetSurface(), xaml_context);
50 Type::Kind dummy;
52 loader->SetExpandingTemplate (true);
53 loader->SetImportDefaultXmlns (true);
55 xaml_context->SetTemplateBindingSource (templateBindingSource);
57 DependencyObject *result = loader->CreateDependencyObjectFromString (xaml_buffer, true, &dummy);
59 delete loader;
61 return result;
64 return NULL;
67 ControlTemplate::ControlTemplate ()
69 SetObjectType (Type::CONTROLTEMPLATE);
72 FrameworkElement *
73 ControlTemplate::Apply (Control *control)
75 return (FrameworkElement*)GetVisualTree (control);
78 DataTemplate::DataTemplate ()
80 SetObjectType (Type::DATATEMPLATE);
83 DependencyObject*
84 DataTemplate::LoadContentWithError (MoonError *error)
86 printf ("%p: LoadContentWithError (buffer = %s)\n", this, xaml_buffer);
88 return GetVisualTree (NULL);