xref: /aoo41x/main/toolkit/source/layout/core/box.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef LAYOUT_CORE_BOX_HXX
29 #define LAYOUT_CORE_BOX_HXX
30 
31 #include <layout/core/box-base.hxx>
32 
33 #include <com/sun/star/awt/Point.hpp>
34 
35 namespace layoutimpl
36 {
37 
38 class Box : public Box_Base
39 {
40 protected:
41     // Box properties (i.e. affect all children)
42     sal_Int32 mnSpacing;
43     sal_Bool mbHomogeneous;
44     sal_Bool mbHorizontal;  // false for Vertical
45     bool mbHasFlowChildren;
46 
47 public:
48     // Children properties
49     struct ChildData : public Box_Base::ChildData
50     {
51         sal_Int32 mnPadding;
52         sal_Bool mbExpand;
53         sal_Bool mbFill;
54         ChildData( css::uno::Reference< css::awt::XLayoutConstrains > const& xChild );
55     };
56 
57     struct ChildProps : public Box_Base::ChildProps
58     {
59         ChildProps( ChildData *pData );
60     };
61 
62 protected:
63     ChildData *createChild( css::uno::Reference< css::awt::XLayoutConstrains > const& xChild );
64     ChildProps *createChildProps( Box_Base::ChildData* pData );
65 
66 public:
67     Box( bool horizontal );
68 
69     virtual void SAL_CALL allocateArea( const css::awt::Rectangle &rArea )
70         throw (css::uno::RuntimeException);
71 
72     virtual css::awt::Size SAL_CALL getMinimumSize()
73         throw(css::uno::RuntimeException);
74     virtual sal_Bool SAL_CALL hasHeightForWidth()
75         throw(css::uno::RuntimeException);
76     virtual sal_Int32 SAL_CALL getHeightForWidth( sal_Int32 nWidth )
77         throw(css::uno::RuntimeException);
78 
79     // helper: mix of getMinimumSize() and getHeightForWidth()
80     css::awt::Size calculateSize( long nWidth = 0 );
81 
82 private:
83     /* Helpers to deal with the joint Box directions. */
84     inline int primDim (const css::awt::Size &size)
85     { if (mbHorizontal) return size.Width; else return size.Height; }
86     inline int secDim (const css::awt::Size &size)
87     { if (mbHorizontal) return size.Height; else return size.Width; }
88     inline int primDim (const css::awt::Point &point)
89     { if (mbHorizontal) return point.X; else return point.Y; }
90     inline int secDim (const css::awt::Point &point)
91     { if (mbHorizontal) return point.Y; else return point.X; }
92 };
93 
94 struct VBox : public Box
95 { VBox() : Box (false) {} };
96 
97 struct HBox : public Box
98 { HBox() : Box (true) {} };
99 
100 } //  namespace layoutimpl
101 
102 #endif /* LAYOUT_CORE_BOX_HXX */
103