2009-11-13 Jeffrey Stedfast <fejj@novell.com>
[moon.git] / src / layoutinformation.cpp
blob21d6d0ecc79aca525b1cf73f8599d38939e25500
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3 * layoutinformation.cpp
5 * Copyright 2007 Novell, Inc. (http://www.novell.com)
7 * See the LICENSE file included with the distribution for details.
8 *
9 */
10 #include "frameworkelement.h"
11 #include "geometry.h"
12 #include "rect.h"
13 #include "point.h"
15 Geometry *
16 LayoutInformation::GetClip (FrameworkElement *item)
18 FrameworkElement *element = item;
19 Point offset = Point (0,0);
20 Rect composite (0,0,INFINITY, INFINITY);
22 do {
23 Geometry *clip = GetLayoutClip (element);
25 if (clip && clip->Is (Type::RECTANGLEGEOMETRY)) {
26 Rect relative = *((RectangleGeometry *)clip)->GetRect ();
27 relative.x -= offset.x;
28 relative.y -= offset.y;
30 composite = composite.Intersection (relative);
33 Point *local_offset = GetVisualOffset (element);
34 if (local_offset) {
35 offset.x += local_offset->x;
36 offset.y += local_offset->y;
38 } while ((element = (FrameworkElement *)element->GetVisualParent ()));
40 if (isinf (composite.width) || isinf (composite.height))
41 return NULL;
43 RectangleGeometry *geom = new RectangleGeometry ();
44 geom->SetRect (&composite);
46 return geom;