2009-12-03 Jeffrey Stedfast <fejj@novell.com>
[moon.git] / src / contentcontrol.cpp
blobe28d92496fc0159d1e9a9f8471d42011457591ed
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"
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 ()
36 UIElement *
37 ContentControl::GetDefaultTemplate ()
39 Value *content = GetValue (ContentControl::ContentProperty);
40 if (!content || content->GetIsNull ())
41 return NULL;
43 if (content->Is (GetDeployment (), Type::UIELEMENT))
44 return content->AsUIElement ();
46 return Control::GetDefaultTemplate ();
49 void
50 ContentControl::OnPropertyChanged (PropertyChangedEventArgs *args, MoonError *error)
52 bool clearTemplate = false;
53 if (args->GetProperty ()->GetOwnerType () != Type::CONTENTCONTROL) {
54 Control::OnPropertyChanged (args, error);
55 return;
58 if (args->GetId () == ContentControl::ContentProperty) {
59 if (args->GetOldValue() && args->GetOldValue()->Is(GetDeployment (), Type::FRAMEWORKELEMENT)) {
60 clearTemplate = true;
61 if (GetContentSetsParent ()) {
62 args->GetOldValue()->AsFrameworkElement()->SetLogicalParent (NULL, error);
63 if (error->number)
64 return;
67 if (args->GetNewValue() && args->GetNewValue()->Is(GetDeployment (), Type::FRAMEWORKELEMENT)) {
68 clearTemplate = true;
69 if (GetContentSetsParent ()) {
70 args->GetNewValue()->AsFrameworkElement()->SetLogicalParent (this, error);
71 if (error->number)
72 return;
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, "");
80 // return;
81 //}
83 if (clearTemplate && GetSubtreeObject ())
84 ElementRemoved ((UIElement *) GetSubtreeObject ());
86 Emit (ContentControl::ContentChangedEvent, new ContentChangedEventArgs (args->GetOldValue(), args->GetNewValue()));
87 InvalidateMeasure ();
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 ()
105 Value*
106 ContentChangedEventArgs::GetOldContent ()
108 return old_content;
111 Value*
112 ContentChangedEventArgs::GetNewContent ()
114 return new_content;