just kick off another build
[moon.git] / src / contentcontrol.cpp
blobb20d4ad678bf59924edff0dbdd1cde4ace66fba1
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3 * contentcontrol.cpp:
5 * Contact:
6 * Moonlight List (moonlight-list@lists.ximian.com)
8 * Copyright 2007-2009 Novell, Inc. (http://www.novell.com)
10 * See the LICENSE file included with the distribution for details.
14 #include <config.h>
16 #include "application.h"
17 #include "contentcontrol.h"
20 ContentControl::ContentControl ()
22 ManagedTypeInfo *type_info = new ManagedTypeInfo ("System.Windows", "System.Windows.Controls.ContentControl");
24 SetContentSetsParent (true);
25 SetObjectType (Type::CONTENTCONTROL);
26 SetDefaultStyleKey (type_info);
29 ContentControl::~ContentControl ()
33 bool
34 ContentControl::ApplyTemplate ()
36 // If the Template has been applied (or already applied) we will get a
37 // return code of TemplateStatusApplied or TemplateStatusAlreadyApplied.
38 // Otherwise we get TemplateStatusNotApplied and we should apply the
39 // default root
40 TemplateStatus status = Control::ApplyTemplate (GetTemplate ());
41 if (status != TemplateStatusNotApplied) {
42 // Return 'true' if the template was actually applied. If it was
43 // already there, we return false.
44 return status == TemplateStatusApplied;
46 Value *content = GetValue (ContentControl::ContentProperty);
47 if (!content || content->GetIsNull ())
48 return false;
50 status = ApplyTemplateRoot (Application::GetCurrent ()->GetDefaultTemplateRoot (this));
51 return status == TemplateStatusApplied;
54 void
55 ContentControl::OnPropertyChanged (PropertyChangedEventArgs *args, MoonError *error)
57 bool clearTemplate = false;
58 if (args->GetProperty ()->GetOwnerType () != Type::CONTENTCONTROL) {
59 Control::OnPropertyChanged (args, error);
60 return;
63 if (args->GetId () == ContentControl::ContentProperty) {
64 if (args->GetOldValue() && args->GetOldValue()->Is(Type::FRAMEWORKELEMENT)) {
65 clearTemplate = true;
66 if (GetContentSetsParent ()) {
67 args->GetOldValue()->AsFrameworkElement()->SetLogicalParent (NULL, error);
68 if (error->number)
69 return;
72 if (args->GetNewValue() && args->GetNewValue()->Is(Type::FRAMEWORKELEMENT)) {
73 clearTemplate = true;
74 if (GetContentSetsParent ()) {
75 args->GetNewValue()->AsFrameworkElement()->SetLogicalParent (this, error);
76 if (error->number)
77 return;
80 if (!GetContentSetsParent () && args->GetNewValue () && args->GetNewValue()->Is (Type::DEPENDENCY_OBJECT) && !args->GetNewValue ()->Is (Type::FRAMEWORKELEMENT)) {
81 MoonError::FillIn (error, MoonError::ARGUMENT, "");
82 return;
85 if (clearTemplate)
86 ClearTemplate ();
88 Emit (ContentControl::ContentChangedEvent, new ContentChangedEventArgs (args->GetOldValue(), args->GetNewValue()));
91 NotifyListenersOfPropertyChange (args, error);
94 ContentChangedEventArgs::ContentChangedEventArgs (Value *old_content, Value *new_content)
96 SetObjectType (Type::CONTENTCHANGEDEVENTARGS);
98 this->old_content = old_content;
99 this->new_content = new_content;
102 ContentChangedEventArgs::~ContentChangedEventArgs ()
106 Value*
107 ContentChangedEventArgs::GetOldContent ()
109 return old_content;
112 Value*
113 ContentChangedEventArgs::GetNewContent ()
115 return new_content;