2009-12-03 Jeffrey Stedfast <fejj@novell.com>
[moon.git] / src / canvas.cpp
blob6c9fc6ec5a8ea2f824fc9265988810a4a43617db
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3 * canvas.cpp: canvas definitions.
5 * Contact:
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.
14 #include <config.h>
16 #include <math.h>
18 #include "rect.h"
19 #include "canvas.h"
20 #include "runtime.h"
21 #include "namescope.h"
22 #include "collection.h"
23 #include "deployment.h"
25 Canvas::Canvas ()
27 SetObjectType (Type::CANVAS);
30 void
31 Canvas::ComputeBounds ()
33 Surface *surface = GetDeployment ()->GetSurface ();
34 Panel::ComputeBounds ();
35 if (surface && IsAttached () && 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());
42 void
43 Canvas::ShiftPosition (Point p)
45 Surface *surface = GetDeployment ()->GetSurface ();
46 if (surface && IsAttached () && surface->IsTopLevel (this)) {
47 ComputeBounds ();
48 } else {
49 Panel::ShiftPosition (p);
53 void
54 Canvas::OnPropertyChanged (PropertyChangedEventArgs *args, MoonError *error)
56 if (args->GetProperty ()->GetOwnerType() != Type::CANVAS) {
57 Panel::OnPropertyChanged (args, error);
58 return;
61 if (args->GetId () == Canvas::TopProperty
62 || args->GetId () == Canvas::LeftProperty) {
63 if (GetVisualParent () == NULL) {
64 UpdateTransform ();
65 InvalidateArrange ();
68 NotifyListenersOfPropertyChange (args, error);
71 bool
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 ())
79 return true;
82 return false;
85 Size
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);
97 return desired;
100 Size
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);
112 return finalSize;
115 void
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 ();
128 UpdateBounds ();
129 return;
133 Panel::OnCollectionItemChanged (col, obj, args);