1*b0724fc6SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*b0724fc6SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*b0724fc6SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*b0724fc6SAndrew Rist * distributed with this work for additional information 6*b0724fc6SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*b0724fc6SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*b0724fc6SAndrew Rist * "License"); you may not use this file except in compliance 9*b0724fc6SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*b0724fc6SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*b0724fc6SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*b0724fc6SAndrew Rist * software distributed under the License is distributed on an 15*b0724fc6SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*b0724fc6SAndrew Rist * KIND, either express or implied. See the License for the 17*b0724fc6SAndrew Rist * specific language governing permissions and limitations 18*b0724fc6SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*b0724fc6SAndrew Rist *************************************************************/ 21*b0724fc6SAndrew Rist 22*b0724fc6SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #include "vclxsplitter.hxx" 25cdf0e10cSrcweir 26cdf0e10cSrcweir #include <assert.h> 27cdf0e10cSrcweir #include <com/sun/star/awt/PosSize.hpp> 28cdf0e10cSrcweir #include <sal/macros.h> 29cdf0e10cSrcweir #include <toolkit/helper/property.hxx> 30cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx> 31cdf0e10cSrcweir #include <vcl/split.hxx> 32cdf0e10cSrcweir 33cdf0e10cSrcweir #include "forward.hxx" 34cdf0e10cSrcweir 35cdf0e10cSrcweir namespace layoutimpl 36cdf0e10cSrcweir { 37cdf0e10cSrcweir 38cdf0e10cSrcweir using namespace ::com::sun::star::uno; 39cdf0e10cSrcweir using namespace ::com::sun::star::awt; 40cdf0e10cSrcweir using namespace ::com::sun::star::lang; 41cdf0e10cSrcweir using namespace ::com::sun::star::beans; 42cdf0e10cSrcweir using namespace ::com::sun::star; 43cdf0e10cSrcweir 44cdf0e10cSrcweir VCLXSplitter::ChildProps::ChildProps( VCLXSplitter::ChildData *pData ) 45cdf0e10cSrcweir { 46cdf0e10cSrcweir addProp( RTL_CONSTASCII_USTRINGPARAM( "Shrink" ), 47cdf0e10cSrcweir ::getCppuType( static_cast< const rtl::OUString* >( NULL ) ), 48cdf0e10cSrcweir &(pData->mbShrink) ); 49cdf0e10cSrcweir } 50cdf0e10cSrcweir 51cdf0e10cSrcweir VCLXSplitter::ChildData::ChildData( uno::Reference< awt::XLayoutConstrains > const& xChild ) 52cdf0e10cSrcweir : Box_Base::ChildData( xChild ) 53cdf0e10cSrcweir , mbShrink( false ) 54cdf0e10cSrcweir { 55cdf0e10cSrcweir } 56cdf0e10cSrcweir 57cdf0e10cSrcweir VCLXSplitter::ChildData* 58cdf0e10cSrcweir VCLXSplitter::createChild( uno::Reference< awt::XLayoutConstrains > const& xChild ) 59cdf0e10cSrcweir { 60cdf0e10cSrcweir return new ChildData( xChild ); 61cdf0e10cSrcweir } 62cdf0e10cSrcweir 63cdf0e10cSrcweir VCLXSplitter::ChildProps* 64cdf0e10cSrcweir VCLXSplitter::createChildProps( Box_Base::ChildData *pData ) 65cdf0e10cSrcweir { 66cdf0e10cSrcweir return new ChildProps( static_cast<VCLXSplitter::ChildData*> ( pData ) ); 67cdf0e10cSrcweir } 68cdf0e10cSrcweir 69cdf0e10cSrcweir 70cdf0e10cSrcweir DBG_NAME( VCLXSplitter ); 71cdf0e10cSrcweir 72cdf0e10cSrcweir VCLXSplitter::VCLXSplitter( bool bHorizontal ) 73cdf0e10cSrcweir : VCLXWindow() 74cdf0e10cSrcweir , Box_Base() 75cdf0e10cSrcweir { 76cdf0e10cSrcweir DBG_CTOR( VCLXSplitter, NULL ); 77cdf0e10cSrcweir mnHandleRatio = 0.5; 78cdf0e10cSrcweir mbHandlePressed = false; 79cdf0e10cSrcweir mbHorizontal = bHorizontal; 80cdf0e10cSrcweir mpSplitter = NULL; 81cdf0e10cSrcweir } 82cdf0e10cSrcweir 83cdf0e10cSrcweir VCLXSplitter::~VCLXSplitter() 84cdf0e10cSrcweir { 85cdf0e10cSrcweir DBG_DTOR( VCLXSplitter, NULL ); 86cdf0e10cSrcweir } 87cdf0e10cSrcweir 88cdf0e10cSrcweir IMPLEMENT_2_FORWARD_XINTERFACE1( VCLXSplitter, VCLXWindow, Container ); 89cdf0e10cSrcweir 90cdf0e10cSrcweir IMPLEMENT_FORWARD_XTYPEPROVIDER1( VCLXSplitter, VCLXWindow ); 91cdf0e10cSrcweir 92cdf0e10cSrcweir VCLXSplitter::ChildData* 93cdf0e10cSrcweir VCLXSplitter::getChild( int i ) 94cdf0e10cSrcweir { 95cdf0e10cSrcweir if ( maChildren.size() && i == 0 ) 96cdf0e10cSrcweir return static_cast<VCLXSplitter::ChildData*>( maChildren.front() ); 97cdf0e10cSrcweir else if ( maChildren.size() > 1 && i == 1 ) 98cdf0e10cSrcweir return static_cast<VCLXSplitter::ChildData*>( maChildren.back() ); 99cdf0e10cSrcweir return 0; 100cdf0e10cSrcweir } 101cdf0e10cSrcweir 102cdf0e10cSrcweir void SAL_CALL VCLXSplitter::dispose() throw(RuntimeException) 103cdf0e10cSrcweir { 104cdf0e10cSrcweir { 105cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() ); 106cdf0e10cSrcweir 107cdf0e10cSrcweir EventObject aDisposeEvent; 108cdf0e10cSrcweir aDisposeEvent.Source = W3K_EXPLICIT_CAST (*this); 109cdf0e10cSrcweir // maTabListeners.disposeAndClear( aDisposeEvent ); 110cdf0e10cSrcweir } 111cdf0e10cSrcweir 112cdf0e10cSrcweir VCLXWindow::dispose(); 113cdf0e10cSrcweir } 114cdf0e10cSrcweir 115cdf0e10cSrcweir void VCLXSplitter::ensureSplitter() 116cdf0e10cSrcweir { 117cdf0e10cSrcweir if ( !mpSplitter ) 118cdf0e10cSrcweir { 119cdf0e10cSrcweir mpSplitter = new Splitter( GetWindow() , mbHorizontal ? WB_HORZ : WB_VERT ); 120cdf0e10cSrcweir mpSplitter->Show(); 121cdf0e10cSrcweir mpSplitter->SetEndSplitHdl( LINK( this, VCLXSplitter, HandleMovedHdl ) ); 122cdf0e10cSrcweir } 123cdf0e10cSrcweir } 124cdf0e10cSrcweir 125cdf0e10cSrcweir void SAL_CALL VCLXSplitter::addChild( 126cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XLayoutConstrains > &xChild ) 127cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::awt::MaxChildrenException) 128cdf0e10cSrcweir { 129cdf0e10cSrcweir if ( maChildren.size() == 2 ) 130cdf0e10cSrcweir throw css::awt::MaxChildrenException(); 131cdf0e10cSrcweir Box_Base::addChild( xChild ); 132cdf0e10cSrcweir } 133cdf0e10cSrcweir 134cdf0e10cSrcweir void SAL_CALL VCLXSplitter::allocateArea( 135cdf0e10cSrcweir const ::com::sun::star::awt::Rectangle &rArea ) 136cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException) 137cdf0e10cSrcweir { 138cdf0e10cSrcweir ensureSplitter(); // shouldn't be needed... 139cdf0e10cSrcweir getMinimumSize(); 140cdf0e10cSrcweir int splitDiff; 141cdf0e10cSrcweir if ( mbHorizontal ) 142cdf0e10cSrcweir splitDiff = rArea.Width - maAllocation.Width; 143cdf0e10cSrcweir else 144cdf0e10cSrcweir splitDiff = rArea.Height - maAllocation.Height; 145cdf0e10cSrcweir 146cdf0e10cSrcweir assert( mpSplitter ); 147cdf0e10cSrcweir if ( splitDiff ) 148cdf0e10cSrcweir mpSplitter->SetSplitPosPixel( mpSplitter->GetSplitPosPixel() + splitDiff/2 ); 149cdf0e10cSrcweir 150cdf0e10cSrcweir maAllocation = rArea; 151cdf0e10cSrcweir int width = mbHorizontal ? rArea.Width : rArea.Height; 152cdf0e10cSrcweir int splitLen = 2; 153cdf0e10cSrcweir int splitPos = mpSplitter->GetSplitPosPixel(); 154cdf0e10cSrcweir setPosSize( rArea.X, rArea.Y, rArea.Width, rArea.Height, PosSize::POSSIZE ); 155cdf0e10cSrcweir if ( mbHorizontal ) 156cdf0e10cSrcweir mpSplitter->SetPosSizePixel( splitPos, 0, splitLen, rArea.Height, PosSize::POSSIZE ); 157cdf0e10cSrcweir else 158cdf0e10cSrcweir mpSplitter->SetPosSizePixel( 0, splitPos, rArea.Width, splitLen, PosSize::POSSIZE ); 159cdf0e10cSrcweir mpSplitter->SetDragRectPixel( ::Rectangle( 0, 0, rArea.Width, rArea.Height ) ); 160cdf0e10cSrcweir int leftWidth = splitPos; 161cdf0e10cSrcweir int rightWidth = width - splitPos; 162cdf0e10cSrcweir 163cdf0e10cSrcweir if ( getChild( 0 ) && getChild( 0 )->mxChild.is() ) 164cdf0e10cSrcweir { 165cdf0e10cSrcweir awt::Rectangle childRect( 0, 0, rArea.Width, rArea.Height ); 166cdf0e10cSrcweir 167cdf0e10cSrcweir if ( mbHorizontal ) 168cdf0e10cSrcweir childRect.Width = leftWidth - 2; 169cdf0e10cSrcweir else 170cdf0e10cSrcweir childRect.Height = leftWidth - 2; 171cdf0e10cSrcweir allocateChildAt( getChild( 0 )->mxChild, childRect ); 172cdf0e10cSrcweir } 173cdf0e10cSrcweir if ( getChild( 0 ) && getChild( 0 )->mxChild.is() ) 174cdf0e10cSrcweir { 175cdf0e10cSrcweir awt::Rectangle childRect( 0, 0, rArea.Width, rArea.Height ); 176cdf0e10cSrcweir 177cdf0e10cSrcweir if ( mbHorizontal ) 178cdf0e10cSrcweir { 179cdf0e10cSrcweir childRect.X += leftWidth + splitLen + 2; 180cdf0e10cSrcweir childRect.Width = rightWidth; 181cdf0e10cSrcweir } 182cdf0e10cSrcweir else 183cdf0e10cSrcweir { 184cdf0e10cSrcweir childRect.Y += leftWidth + splitLen + 2; 185cdf0e10cSrcweir childRect.Height = rightWidth; 186cdf0e10cSrcweir } 187cdf0e10cSrcweir allocateChildAt( getChild( 1 )->mxChild, childRect ); 188cdf0e10cSrcweir } 189cdf0e10cSrcweir } 190cdf0e10cSrcweir 191cdf0e10cSrcweir ::com::sun::star::awt::Size SAL_CALL VCLXSplitter::getMinimumSize() 192cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 193cdf0e10cSrcweir { 194cdf0e10cSrcweir ensureSplitter(); 195cdf0e10cSrcweir 196cdf0e10cSrcweir awt::Size size( mbHorizontal ? 2 : 0, mbHorizontal ? 0 : 2 ); 197cdf0e10cSrcweir for ( unsigned int i = 0; i < 2; i++ ) 198cdf0e10cSrcweir { 199cdf0e10cSrcweir if ( getChild( i ) && getChild( i )->mxChild.is() ) 200cdf0e10cSrcweir { 201cdf0e10cSrcweir awt::Size childSize = getChild( i )->mxChild->getMinimumSize(); 202cdf0e10cSrcweir if ( mbHorizontal ) 203cdf0e10cSrcweir { 204cdf0e10cSrcweir size.Width += childSize.Width; 205cdf0e10cSrcweir size.Height = SAL_MAX( size.Height, childSize.Height ); 206cdf0e10cSrcweir } 207cdf0e10cSrcweir else 208cdf0e10cSrcweir { 209cdf0e10cSrcweir size.Width = SAL_MAX( size.Width, childSize.Width ); 210cdf0e10cSrcweir size.Height += childSize.Height; 211cdf0e10cSrcweir } 212cdf0e10cSrcweir } 213cdf0e10cSrcweir } 214cdf0e10cSrcweir 215cdf0e10cSrcweir maRequisition = size; 216cdf0e10cSrcweir return size; 217cdf0e10cSrcweir } 218cdf0e10cSrcweir 219cdf0e10cSrcweir void VCLXSplitter::ProcessWindowEvent( const VclWindowEvent& _rVclWindowEvent ) 220cdf0e10cSrcweir { 221cdf0e10cSrcweir VCLXWindow::ProcessWindowEvent( _rVclWindowEvent ); 222cdf0e10cSrcweir } 223cdf0e10cSrcweir 224cdf0e10cSrcweir void SAL_CALL VCLXSplitter::setProperty( const ::rtl::OUString& PropertyName, const Any &Value ) throw(RuntimeException) 225cdf0e10cSrcweir { 226cdf0e10cSrcweir VCLXWindow::setProperty( PropertyName, Value ); 227cdf0e10cSrcweir } 228cdf0e10cSrcweir 229cdf0e10cSrcweir Any SAL_CALL VCLXSplitter::getProperty( const ::rtl::OUString& PropertyName ) throw(RuntimeException) 230cdf0e10cSrcweir { 231cdf0e10cSrcweir return VCLXWindow::getProperty( PropertyName ); 232cdf0e10cSrcweir } 233cdf0e10cSrcweir 234cdf0e10cSrcweir IMPL_LINK( VCLXSplitter, HandleMovedHdl, Splitter *, pSplitter ) 235cdf0e10cSrcweir { 236cdf0e10cSrcweir (void) pSplitter; 237cdf0e10cSrcweir forceRecalc(); 238cdf0e10cSrcweir return 0; 239cdf0e10cSrcweir } 240cdf0e10cSrcweir 241cdf0e10cSrcweir } // namespace layoutimpl 242