1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
5 * Copyright 2007 Novell, Inc. (http://www.novell.com)
7 * See the LICENSE file included with the distribution for details.
13 #include "usercontrol.h"
14 #include "collection.h"
17 UserControl::UserControl ()
19 SetObjectType (Type::USERCONTROL
);
23 UserControl::~UserControl ()
28 user_control_get_content (UserControl
*user_control
)
30 Value
* v
=user_control
-> GetValue (UserControl::ContentProperty
);
33 return v
->AsUIElement ();
37 UserControl::OnPropertyChanged (PropertyChangedEventArgs
*args
, MoonError
*error
)
39 if (args
->GetProperty ()->GetOwnerType() != Type::USERCONTROL
) {
40 Control::OnPropertyChanged (args
, error
);
44 if (args
->GetId () == UserControl::ContentProperty
){
45 if (args
->GetOldValue()) {
46 if (args
->GetOldValue()->Is(GetDeployment (), Type::FRAMEWORKELEMENT
)) {
47 args
->GetOldValue()->AsFrameworkElement()->SetLogicalParent (NULL
, error
);
51 ElementRemoved (args
->GetOldValue()->AsUIElement ());
53 if (args
->GetNewValue()) {
54 if (args
->GetNewValue()->Is(GetDeployment (), Type::FRAMEWORKELEMENT
)) {
55 args
->GetNewValue()->AsFrameworkElement()->SetLogicalParent (this, error
);
59 ElementAdded (args
->GetNewValue()->AsUIElement ());
64 NotifyListenersOfPropertyChange (args
, error
);
68 UserControl::MeasureOverride (Size availableSize
)
70 Size desired
= Size (0,0);
72 Thickness border
= *GetPadding () + *GetBorderThickness ();
74 // Get the desired size of our child, and include any margins we set
75 VisualTreeWalker walker
= VisualTreeWalker (this);
76 while (UIElement
*child
= walker
.Step ()) {
77 child
->Measure (availableSize
.GrowBy (-border
));
78 desired
= child
->GetDesiredSize ();
81 desired
= desired
.GrowBy (border
);
87 UserControl::ArrangeOverride (Size finalSize
)
89 Thickness border
= *GetPadding () + *GetBorderThickness ();
91 Size arranged
= finalSize
;
93 VisualTreeWalker walker
= VisualTreeWalker (this);
94 while (UIElement
*child
= walker
.Step ()) {
95 Size desired
= child
->GetDesiredSize ();
96 Rect
childRect (0,0,finalSize
.width
,finalSize
.height
);
98 childRect
= childRect
.GrowBy (-border
);
100 child
->Arrange (childRect
);
102 arranged
= Size (childRect
.width
, childRect
.height
).GrowBy (border
);