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 throw (css::uno::RuntimeException); 56 static css::uno::Sequence< css::uno::Reference< css::awt::XLayoutConstrains > > 57 getSingleChild (const css::uno::Reference< css::awt::XLayoutConstrains > &xChildOrNil); 58 void setChildParent( const css::uno::Reference< css::awt::XLayoutConstrains >& xChild ); 59 void unsetChildParent( const css::uno::Reference< css::awt::XLayoutConstrains >& xChild ); 60 61 void queueResize(); forceRecalc()62 void forceRecalc() { allocateArea( maAllocation ); } 63 64 public: 65 Container(); ~Container()66 virtual ~Container() {} 67 68 virtual bool emptyVisible (); 69 70 // XInterface acquire()71 virtual void SAL_CALL acquire() throw() { PropHelper::acquire(); } release()72 virtual void SAL_CALL release() throw() { PropHelper::release(); } 73 virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException); 74 75 // css::awt::XLayoutContainer 76 virtual void SAL_CALL addChild( const css::uno::Reference< css::awt::XLayoutConstrains >& Child ) 77 throw (css::uno::RuntimeException, css::awt::MaxChildrenException) = 0; 78 virtual void SAL_CALL removeChild( const css::uno::Reference< css::awt::XLayoutConstrains >& Child ) 79 throw (css::uno::RuntimeException) = 0; 80 81 virtual css::uno::Sequence< css::uno::Reference 82 < css::awt::XLayoutConstrains > > SAL_CALL getChildren() 83 throw (css::uno::RuntimeException) = 0; 84 85 virtual css::uno::Reference< css::beans::XPropertySet > SAL_CALL getChildProperties( 86 const css::uno::Reference< css::awt::XLayoutConstrains >& Child ) 87 throw (css::uno::RuntimeException) = 0; 88 89 virtual void SAL_CALL allocateArea( const css::awt::Rectangle &rArea ) 90 throw (css::uno::RuntimeException) = 0; 91 setLayoutUnit(const css::uno::Reference<css::awt::XLayoutUnit> & xUnit)92 void SAL_CALL setLayoutUnit( const css::uno::Reference< css::awt::XLayoutUnit > &xUnit ) 93 throw(css::uno::RuntimeException) 94 { mxLayoutUnit = xUnit; } getLayoutUnit()95 css::uno::Reference< css::awt::XLayoutUnit > SAL_CALL getLayoutUnit() 96 throw(css::uno::RuntimeException) 97 { return mxLayoutUnit; } 98 getRequestedSize()99 css::awt::Size SAL_CALL getRequestedSize() throw(css::uno::RuntimeException) 100 { return maRequisition; } getAllocatedArea()101 com::sun::star::awt::Rectangle SAL_CALL getAllocatedArea() throw(css::uno::RuntimeException) 102 { return maAllocation; } 103 104 virtual sal_Bool SAL_CALL hasHeightForWidth() 105 throw(css::uno::RuntimeException) = 0; 106 virtual sal_Int32 SAL_CALL getHeightForWidth( sal_Int32 nWidth ) 107 throw(css::uno::RuntimeException) = 0; 108 109 // css::awt::XLayoutContainer: css::container::XChild getParent()110 css::uno::Reference< css::uno::XInterface > SAL_CALL getParent() 111 throw (css::uno::RuntimeException) 112 { return mxParent; } setParent(const css::uno::Reference<css::uno::XInterface> & xParent)113 void SAL_CALL setParent( const css::uno::Reference< css::uno::XInterface > &xParent ) 114 throw (css::uno::RuntimeException) 115 { mxParent = css::uno::Reference< css::awt::XLayoutContainer >( xParent, css::uno::UNO_QUERY ); } 116 117 // css::awt::XLayoutConstrains 118 virtual css::awt::Size SAL_CALL getMinimumSize() 119 throw(css::uno::RuntimeException) = 0; 120 // (not properly implemented in toolkit, ignore it.) getPreferredSize()121 css::awt::Size SAL_CALL getPreferredSize() 122 throw(css::uno::RuntimeException) { return getMinimumSize(); } // TODO: use this for flow? calcAdjustedSize(const css::awt::Size & rNewSize)123 css::awt::Size SAL_CALL calcAdjustedSize( const css::awt::Size& rNewSize ) 124 throw(css::uno::RuntimeException) { return rNewSize; } 125 126 protected: 127 void propertiesChanged(); 128 }; 129 130 } // namespace layoutimpl 131 132 #endif /* LAYOUT_CORE_CONTAINER_HXX */ 133