xref: /trunk/main/toolkit/source/layout/core/box.hxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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 
67     virtual css::awt::Size SAL_CALL getMinimumSize();
68     virtual sal_Bool SAL_CALL hasHeightForWidth();
69     virtual sal_Int32 SAL_CALL getHeightForWidth( sal_Int32 nWidth );
70 
71     // helper: mix of getMinimumSize() and getHeightForWidth()
72     css::awt::Size calculateSize( long nWidth = 0 );
73 
74 private:
75     /* Helpers to deal with the joint Box directions. */
primDim(const css::awt::Size & size)76     inline int primDim (const css::awt::Size &size)
77     { if (mbHorizontal) return size.Width; else return size.Height; }
secDim(const css::awt::Size & size)78     inline int secDim (const css::awt::Size &size)
79     { if (mbHorizontal) return size.Height; else return size.Width; }
primDim(const css::awt::Point & point)80     inline int primDim (const css::awt::Point &point)
81     { if (mbHorizontal) return point.X; else return point.Y; }
secDim(const css::awt::Point & point)82     inline int secDim (const css::awt::Point &point)
83     { if (mbHorizontal) return point.Y; else return point.X; }
84 };
85 
86 struct VBox : public Box
VBoxlayoutimpl::VBox87 { VBox() : Box (false) {} };
88 
89 struct HBox : public Box
HBoxlayoutimpl::HBox90 { HBox() : Box (true) {} };
91 
92 } //  namespace layoutimpl
93 
94 #endif /* LAYOUT_CORE_BOX_HXX */
95