xref: /trunk/main/toolkit/source/layout/core/container.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_CONTAINER_HXX
25 #define LAYOUT_CORE_CONTAINER_HXX
26 
27 #include <layout/core/helper.hxx>
28 
29 #include <cppuhelper/implbase2.hxx>
30 #include <com/sun/star/awt/MaxChildrenException.hpp>
31 
32 namespace layoutimpl
33 {
34 namespace css = ::com::sun::star;
35 
36 typedef ::cppu::WeakImplHelper2< css::awt::XLayoutContainer,
37                                  css::awt::XLayoutConstrains > Container_Base;
38 
39 class TOOLKIT_DLLPUBLIC Container : public Container_Base, public PropHelper, public PropHelper::Listener
40 {
41     friend class ChildProps;
42 protected:
43     // Widget properties
44     css::uno::Reference< css::awt::XLayoutContainer > mxParent;
45     css::uno::Reference< css::awt::XLayoutUnit > mxLayoutUnit;
46     css::awt::Size maRequisition;
47     css::awt::Rectangle maAllocation;
48 
49     // Container properties
50     sal_Int32 mnBorderWidth;
51 
52     // Utilities
53     void allocateChildAt( const css::uno::Reference< css::awt::XLayoutConstrains > &xChild,
54                           const css::awt::Rectangle &rArea );
55     static css::uno::Sequence< css::uno::Reference< css::awt::XLayoutConstrains > >
56     getSingleChild (const css::uno::Reference< css::awt::XLayoutConstrains > &xChildOrNil);
57     void setChildParent( const css::uno::Reference< css::awt::XLayoutConstrains >& xChild );
58     void unsetChildParent( const css::uno::Reference< css::awt::XLayoutConstrains >& xChild );
59 
60     void queueResize();
forceRecalc()61     void forceRecalc() { allocateArea( maAllocation ); }
62 
63 public:
64     Container();
~Container()65     virtual ~Container() {}
66 
67     virtual bool emptyVisible ();
68 
69     // XInterface
acquire()70     virtual void SAL_CALL acquire() throw() { PropHelper::acquire(); }
release()71     virtual void SAL_CALL release() throw() { PropHelper::release(); }
72     virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType );
73 
74     // css::awt::XLayoutContainer
75     virtual void SAL_CALL addChild( const css::uno::Reference< css::awt::XLayoutConstrains >& Child ) = 0;
76     virtual void SAL_CALL removeChild( const css::uno::Reference< css::awt::XLayoutConstrains >& Child ) = 0;
77 
78     virtual css::uno::Sequence< css::uno::Reference
79                                 < css::awt::XLayoutConstrains > > SAL_CALL getChildren() = 0;
80 
81     virtual css::uno::Reference< css::beans::XPropertySet > SAL_CALL getChildProperties(
82         const css::uno::Reference< css::awt::XLayoutConstrains >& Child ) = 0;
83 
84     virtual void SAL_CALL allocateArea( const css::awt::Rectangle &rArea ) = 0;
85 
setLayoutUnit(const css::uno::Reference<css::awt::XLayoutUnit> & xUnit)86     void SAL_CALL setLayoutUnit( const css::uno::Reference< css::awt::XLayoutUnit > &xUnit )
87     { mxLayoutUnit = xUnit; }
getLayoutUnit()88     css::uno::Reference< css::awt::XLayoutUnit > SAL_CALL getLayoutUnit()
89     { return mxLayoutUnit; }
90 
getRequestedSize()91     css::awt::Size SAL_CALL getRequestedSize()
92     { return maRequisition; }
getAllocatedArea()93     com::sun::star::awt::Rectangle SAL_CALL getAllocatedArea()
94     { return maAllocation; }
95 
96     virtual sal_Bool SAL_CALL hasHeightForWidth() = 0;
97     virtual sal_Int32 SAL_CALL getHeightForWidth( sal_Int32 nWidth ) = 0;
98 
99     // css::awt::XLayoutContainer: css::container::XChild
getParent()100     css::uno::Reference< css::uno::XInterface > SAL_CALL getParent()
101     { return mxParent; }
setParent(const css::uno::Reference<css::uno::XInterface> & xParent)102     void SAL_CALL setParent( const css::uno::Reference< css::uno::XInterface > &xParent )
103     { mxParent = css::uno::Reference< css::awt::XLayoutContainer >( xParent, css::uno::UNO_QUERY ); }
104 
105     // css::awt::XLayoutConstrains
106     virtual css::awt::Size SAL_CALL getMinimumSize() = 0;
107     // (not properly implemented in toolkit, ignore it.)
getPreferredSize()108     css::awt::Size SAL_CALL getPreferredSize() { return getMinimumSize(); } // TODO: use this for flow?
calcAdjustedSize(const css::awt::Size & rNewSize)109     css::awt::Size SAL_CALL calcAdjustedSize( const css::awt::Size& rNewSize ) { return rNewSize; }
110 
111 protected:
112     void propertiesChanged();
113 };
114 
115 } //  namespace layoutimpl
116 
117 #endif /* LAYOUT_CORE_CONTAINER_HXX */
118