1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * canvas.cpp: canvas definitions.
6 * Moonlight List (moonlight-list@lists.ximian.com)
8 * Copyright 2007 Novell, Inc. (http://www.novell.com)
10 * See the LICENSE file included with the distribution for details.
21 #include "namescope.h"
22 #include "collection.h"
23 #include "deployment.h"
27 SetObjectType (Type::CANVAS
);
31 Canvas::ComputeBounds ()
33 Surface
*surface
= GetSurface ();
34 Panel::ComputeBounds ();
35 if (surface
&& surface
->IsTopLevel (this)) {
36 // toplevel canvas don't subscribe to the same bounds computation as others
37 bounds
= Rect (0, 0, surface
->GetWindow()->GetWidth(), surface
->GetWindow()->GetHeight());
38 bounds_with_children
= Rect (0, 0, surface
->GetWindow()->GetWidth(), surface
->GetWindow()->GetHeight());
43 Canvas::ShiftPosition (Point p
)
45 Surface
*surface
= GetSurface ();
46 if (surface
&& surface
->IsTopLevel (this)) {
49 Panel::ShiftPosition (p
);
54 Canvas::OnPropertyChanged (PropertyChangedEventArgs
*args
, MoonError
*error
)
56 if (args
->GetProperty ()->GetOwnerType() != Type::CANVAS
) {
57 Panel::OnPropertyChanged (args
, error
);
61 if (args
->GetId () == Canvas::TopProperty
62 || args
->GetId () == Canvas::LeftProperty
) {
63 if (GetVisualParent () == NULL
) {
68 NotifyListenersOfPropertyChange (args
, error
);
72 Canvas::IsLayoutContainer ()
74 Types
*types
= Deployment::GetCurrent ()->GetTypes ();
76 DeepTreeWalker walker
= DeepTreeWalker (this);
77 while (UIElement
*child
= walker
.Step ()) {
78 if (!types
->IsSubclassOf (child
->GetObjectType (), Type::CANVAS
) && child
->IsLayoutContainer ())
86 Canvas::MeasureOverride (Size availableSize
)
88 Size childSize
= Size (INFINITY
, INFINITY
);
90 VisualTreeWalker walker
= VisualTreeWalker (this);
91 while (UIElement
*child
= walker
.Step ()) {
92 child
->Measure (childSize
);
95 Size desired
= Size (0,0);
101 Canvas::ArrangeOverride (Size finalSize
)
103 VisualTreeWalker walker
= VisualTreeWalker (this);
104 while (FrameworkElement
*child
= (FrameworkElement
*)walker
.Step ()) {
105 Size desired
= child
->GetDesiredSize ();
106 Rect child_final
= Rect (GetLeft (child
), GetTop (child
),
107 desired
.width
, desired
.height
);
108 child
->Arrange (child_final
);
109 //child->ClearValue (LayoutInformation::LayoutClipProperty);
116 Canvas::OnCollectionItemChanged (Collection
*col
, DependencyObject
*obj
, PropertyChangedEventArgs
*args
)
118 if (col
== GetChildren()) {
119 // this used to contain ZIndex property checking, but
120 // it has been moved to Panel's implementation, since
121 // all panels allow ZIndex sorting of children.
122 if (args
->GetId () == Canvas::TopProperty
||
123 args
->GetId () == Canvas::LeftProperty
) {
124 UIElement
*ui
= (UIElement
*) obj
;
126 ui
->InvalidateSubtreePaint ();
127 InvalidateArrange ();
133 Panel::OnCollectionItemChanged (col
, obj
, args
);