xref: /aoo41x/main/toolkit/source/layout/core/box.hxx (revision 50e6b072)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef LAYOUT_CORE_BOX_HXX
25 #define LAYOUT_CORE_BOX_HXX
26 
27 #include <layout/core/box-base.hxx>
28 
29 #include <com/sun/star/awt/Point.hpp>
30 
31 namespace layoutimpl
32 {
33 
34 class Box : public Box_Base
35 {
36 protected:
37     // Box properties (i.e. affect all children)
38     sal_Int32 mnSpacing;
39     sal_Bool mbHomogeneous;
40     sal_Bool mbHorizontal;  // false for Vertical
41     bool mbHasFlowChildren;
42 
43 public:
44     // Children properties
45     struct ChildData : public Box_Base::ChildData
46     {
47         sal_Int32 mnPadding;
48         sal_Bool mbExpand;
49         sal_Bool mbFill;
50         ChildData( css::uno::Reference< css::awt::XLayoutConstrains > const& xChild );
51     };
52 
53     struct ChildProps : public Box_Base::ChildProps
54     {
55         ChildProps( ChildData *pData );
56     };
57 
58 protected:
59     ChildData *createChild( css::uno::Reference< css::awt::XLayoutConstrains > const& xChild );
60     ChildProps *createChildProps( Box_Base::ChildData* pData );
61 
62 public:
63     Box( bool horizontal );
64 
65     virtual void SAL_CALL allocateArea( const css::awt::Rectangle &rArea )
66         throw (css::uno::RuntimeException);
67 
68     virtual css::awt::Size SAL_CALL getMinimumSize()
69         throw(css::uno::RuntimeException);
70     virtual sal_Bool SAL_CALL hasHeightForWidth()
71         throw(css::uno::RuntimeException);
72     virtual sal_Int32 SAL_CALL getHeightForWidth( sal_Int32 nWidth )
73         throw(css::uno::RuntimeException);
74 
75     // helper: mix of getMinimumSize() and getHeightForWidth()
76     css::awt::Size calculateSize( long nWidth = 0 );
77 
78 private:
79     /* Helpers to deal with the joint Box directions. */
primDim(const css::awt::Size & size)80     inline int primDim (const css::awt::Size &size)
81     { if (mbHorizontal) return size.Width; else return size.Height; }
secDim(const css::awt::Size & size)82     inline int secDim (const css::awt::Size &size)
83     { if (mbHorizontal) return size.Height; else return size.Width; }
primDim(const css::awt::Point & point)84     inline int primDim (const css::awt::Point &point)
85     { if (mbHorizontal) return point.X; else return point.Y; }
secDim(const css::awt::Point & point)86     inline int secDim (const css::awt::Point &point)
87     { if (mbHorizontal) return point.Y; else return point.X; }
88 };
89 
90 struct VBox : public Box
VBoxlayoutimpl::VBox91 { VBox() : Box (false) {} };
92 
93 struct HBox : public Box
HBoxlayoutimpl::HBox94 { HBox() : Box (true) {} };
95 
96 } //  namespace layoutimpl
97 
98 #endif /* LAYOUT_CORE_BOX_HXX */
99