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-2009 Novell, Inc. (http://www.novell.com)
10 * See the LICENSE file included with the distribution for details.
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 ()
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
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 ())
50 status
= ApplyTemplateRoot (Application::GetCurrent ()->GetDefaultTemplateRoot (this));
51 return status
== TemplateStatusApplied
;
55 ContentControl::OnPropertyChanged (PropertyChangedEventArgs
*args
, MoonError
*error
)
57 bool clearTemplate
= false;
58 if (args
->GetProperty ()->GetOwnerType () != Type::CONTENTCONTROL
) {
59 Control::OnPropertyChanged (args
, error
);
63 if (args
->GetId () == ContentControl::ContentProperty
) {
64 if (args
->GetOldValue() && args
->GetOldValue()->Is(Type::FRAMEWORKELEMENT
)) {
66 if (GetContentSetsParent ()) {
67 args
->GetOldValue()->AsFrameworkElement()->SetLogicalParent (NULL
, error
);
72 if (args
->GetNewValue() && args
->GetNewValue()->Is(Type::FRAMEWORKELEMENT
)) {
74 if (GetContentSetsParent ()) {
75 args
->GetNewValue()->AsFrameworkElement()->SetLogicalParent (this, error
);
80 if (!GetContentSetsParent () && args
->GetNewValue () && args
->GetNewValue()->Is (Type::DEPENDENCY_OBJECT
) && !args
->GetNewValue ()->Is (Type::FRAMEWORKELEMENT
)) {
81 MoonError::FillIn (error
, MoonError::ARGUMENT
, "");
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 ()
107 ContentChangedEventArgs::GetOldContent ()
113 ContentChangedEventArgs::GetNewContent ()