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"
18 #include "managedtypeinfo.h"
20 ContentControl::ContentControl ()
22 ManagedTypeInfo
*type_info
= g_new (ManagedTypeInfo
, 1);
23 type_info
->Initialize ("System.Windows", "System.Windows.Controls.ContentControl");
25 SetContentSetsParent (true);
26 SetObjectType (Type::CONTENTCONTROL
);
27 SetDefaultStyleKey (type_info
);
28 ManagedTypeInfo::Free (type_info
);
32 ContentControl::~ContentControl ()
37 ContentControl::GetDefaultTemplate ()
39 Value
*content
= GetValue (ContentControl::ContentProperty
);
40 if (!content
|| content
->GetIsNull ())
43 if (content
->Is (GetDeployment (), Type::UIELEMENT
))
44 return content
->AsUIElement ();
46 return Control::GetDefaultTemplate ();
50 ContentControl::OnPropertyChanged (PropertyChangedEventArgs
*args
, MoonError
*error
)
52 bool clearTemplate
= false;
53 if (args
->GetProperty ()->GetOwnerType () != Type::CONTENTCONTROL
) {
54 Control::OnPropertyChanged (args
, error
);
58 if (args
->GetId () == ContentControl::ContentProperty
) {
59 if (args
->GetOldValue() && args
->GetOldValue()->Is(GetDeployment (), Type::FRAMEWORKELEMENT
)) {
61 if (GetContentSetsParent ()) {
62 args
->GetOldValue()->AsFrameworkElement()->SetLogicalParent (NULL
, error
);
67 if (args
->GetNewValue() && args
->GetNewValue()->Is(GetDeployment (), Type::FRAMEWORKELEMENT
)) {
69 if (GetContentSetsParent ()) {
70 args
->GetNewValue()->AsFrameworkElement()->SetLogicalParent (this, error
);
75 // I'm not sure why this check is here, but it breaks some Silverlight Toolkit 2.0 (July edition)
76 //tests (databinding a SolidColourBrush from FrameworkElement.Background to ContentControl.Content) and
77 // nothing regresses when I comment this out.
78 //if (!GetContentSetsParent () && args->GetNewValue () && args->GetNewValue()->Is (GetDeployment (), Type::DEPENDENCY_OBJECT) && !args->GetNewValue ()->Is (GetDeployment (), Type::FRAMEWORKELEMENT)) {
79 // MoonError::FillIn (error, MoonError::ARGUMENT, "");
83 if (clearTemplate
&& GetSubtreeObject ())
84 ElementRemoved ((UIElement
*) GetSubtreeObject ());
86 Emit (ContentControl::ContentChangedEvent
, new ContentChangedEventArgs (args
->GetOldValue(), args
->GetNewValue()));
90 NotifyListenersOfPropertyChange (args
, error
);
93 ContentChangedEventArgs::ContentChangedEventArgs (Value
*old_content
, Value
*new_content
)
95 SetObjectType (Type::CONTENTCHANGEDEVENTARGS
);
97 this->old_content
= old_content
;
98 this->new_content
= new_content
;
101 ContentChangedEventArgs::~ContentChangedEventArgs ()
106 ContentChangedEventArgs::GetOldContent ()
112 ContentChangedEventArgs::GetNewContent ()