1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #include "vclxsplitter.hxx" 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir #include <assert.h> 31*cdf0e10cSrcweir #include <com/sun/star/awt/PosSize.hpp> 32*cdf0e10cSrcweir #include <sal/macros.h> 33*cdf0e10cSrcweir #include <toolkit/helper/property.hxx> 34*cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx> 35*cdf0e10cSrcweir #include <vcl/split.hxx> 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir #include "forward.hxx" 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir namespace layoutimpl 40*cdf0e10cSrcweir { 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 43*cdf0e10cSrcweir using namespace ::com::sun::star::awt; 44*cdf0e10cSrcweir using namespace ::com::sun::star::lang; 45*cdf0e10cSrcweir using namespace ::com::sun::star::beans; 46*cdf0e10cSrcweir using namespace ::com::sun::star; 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir VCLXSplitter::ChildProps::ChildProps( VCLXSplitter::ChildData *pData ) 49*cdf0e10cSrcweir { 50*cdf0e10cSrcweir addProp( RTL_CONSTASCII_USTRINGPARAM( "Shrink" ), 51*cdf0e10cSrcweir ::getCppuType( static_cast< const rtl::OUString* >( NULL ) ), 52*cdf0e10cSrcweir &(pData->mbShrink) ); 53*cdf0e10cSrcweir } 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir VCLXSplitter::ChildData::ChildData( uno::Reference< awt::XLayoutConstrains > const& xChild ) 56*cdf0e10cSrcweir : Box_Base::ChildData( xChild ) 57*cdf0e10cSrcweir , mbShrink( false ) 58*cdf0e10cSrcweir { 59*cdf0e10cSrcweir } 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir VCLXSplitter::ChildData* 62*cdf0e10cSrcweir VCLXSplitter::createChild( uno::Reference< awt::XLayoutConstrains > const& xChild ) 63*cdf0e10cSrcweir { 64*cdf0e10cSrcweir return new ChildData( xChild ); 65*cdf0e10cSrcweir } 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir VCLXSplitter::ChildProps* 68*cdf0e10cSrcweir VCLXSplitter::createChildProps( Box_Base::ChildData *pData ) 69*cdf0e10cSrcweir { 70*cdf0e10cSrcweir return new ChildProps( static_cast<VCLXSplitter::ChildData*> ( pData ) ); 71*cdf0e10cSrcweir } 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir DBG_NAME( VCLXSplitter ); 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir VCLXSplitter::VCLXSplitter( bool bHorizontal ) 77*cdf0e10cSrcweir : VCLXWindow() 78*cdf0e10cSrcweir , Box_Base() 79*cdf0e10cSrcweir { 80*cdf0e10cSrcweir DBG_CTOR( VCLXSplitter, NULL ); 81*cdf0e10cSrcweir mnHandleRatio = 0.5; 82*cdf0e10cSrcweir mbHandlePressed = false; 83*cdf0e10cSrcweir mbHorizontal = bHorizontal; 84*cdf0e10cSrcweir mpSplitter = NULL; 85*cdf0e10cSrcweir } 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir VCLXSplitter::~VCLXSplitter() 88*cdf0e10cSrcweir { 89*cdf0e10cSrcweir DBG_DTOR( VCLXSplitter, NULL ); 90*cdf0e10cSrcweir } 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir IMPLEMENT_2_FORWARD_XINTERFACE1( VCLXSplitter, VCLXWindow, Container ); 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir IMPLEMENT_FORWARD_XTYPEPROVIDER1( VCLXSplitter, VCLXWindow ); 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir VCLXSplitter::ChildData* 97*cdf0e10cSrcweir VCLXSplitter::getChild( int i ) 98*cdf0e10cSrcweir { 99*cdf0e10cSrcweir if ( maChildren.size() && i == 0 ) 100*cdf0e10cSrcweir return static_cast<VCLXSplitter::ChildData*>( maChildren.front() ); 101*cdf0e10cSrcweir else if ( maChildren.size() > 1 && i == 1 ) 102*cdf0e10cSrcweir return static_cast<VCLXSplitter::ChildData*>( maChildren.back() ); 103*cdf0e10cSrcweir return 0; 104*cdf0e10cSrcweir } 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir void SAL_CALL VCLXSplitter::dispose() throw(RuntimeException) 107*cdf0e10cSrcweir { 108*cdf0e10cSrcweir { 109*cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() ); 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir EventObject aDisposeEvent; 112*cdf0e10cSrcweir aDisposeEvent.Source = W3K_EXPLICIT_CAST (*this); 113*cdf0e10cSrcweir // maTabListeners.disposeAndClear( aDisposeEvent ); 114*cdf0e10cSrcweir } 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir VCLXWindow::dispose(); 117*cdf0e10cSrcweir } 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir void VCLXSplitter::ensureSplitter() 120*cdf0e10cSrcweir { 121*cdf0e10cSrcweir if ( !mpSplitter ) 122*cdf0e10cSrcweir { 123*cdf0e10cSrcweir mpSplitter = new Splitter( GetWindow() , mbHorizontal ? WB_HORZ : WB_VERT ); 124*cdf0e10cSrcweir mpSplitter->Show(); 125*cdf0e10cSrcweir mpSplitter->SetEndSplitHdl( LINK( this, VCLXSplitter, HandleMovedHdl ) ); 126*cdf0e10cSrcweir } 127*cdf0e10cSrcweir } 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir void SAL_CALL VCLXSplitter::addChild( 130*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XLayoutConstrains > &xChild ) 131*cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::awt::MaxChildrenException) 132*cdf0e10cSrcweir { 133*cdf0e10cSrcweir if ( maChildren.size() == 2 ) 134*cdf0e10cSrcweir throw css::awt::MaxChildrenException(); 135*cdf0e10cSrcweir Box_Base::addChild( xChild ); 136*cdf0e10cSrcweir } 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir void SAL_CALL VCLXSplitter::allocateArea( 139*cdf0e10cSrcweir const ::com::sun::star::awt::Rectangle &rArea ) 140*cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException) 141*cdf0e10cSrcweir { 142*cdf0e10cSrcweir ensureSplitter(); // shouldn't be needed... 143*cdf0e10cSrcweir getMinimumSize(); 144*cdf0e10cSrcweir int splitDiff; 145*cdf0e10cSrcweir if ( mbHorizontal ) 146*cdf0e10cSrcweir splitDiff = rArea.Width - maAllocation.Width; 147*cdf0e10cSrcweir else 148*cdf0e10cSrcweir splitDiff = rArea.Height - maAllocation.Height; 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir assert( mpSplitter ); 151*cdf0e10cSrcweir if ( splitDiff ) 152*cdf0e10cSrcweir mpSplitter->SetSplitPosPixel( mpSplitter->GetSplitPosPixel() + splitDiff/2 ); 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir maAllocation = rArea; 155*cdf0e10cSrcweir int width = mbHorizontal ? rArea.Width : rArea.Height; 156*cdf0e10cSrcweir int splitLen = 2; 157*cdf0e10cSrcweir int splitPos = mpSplitter->GetSplitPosPixel(); 158*cdf0e10cSrcweir setPosSize( rArea.X, rArea.Y, rArea.Width, rArea.Height, PosSize::POSSIZE ); 159*cdf0e10cSrcweir if ( mbHorizontal ) 160*cdf0e10cSrcweir mpSplitter->SetPosSizePixel( splitPos, 0, splitLen, rArea.Height, PosSize::POSSIZE ); 161*cdf0e10cSrcweir else 162*cdf0e10cSrcweir mpSplitter->SetPosSizePixel( 0, splitPos, rArea.Width, splitLen, PosSize::POSSIZE ); 163*cdf0e10cSrcweir mpSplitter->SetDragRectPixel( ::Rectangle( 0, 0, rArea.Width, rArea.Height ) ); 164*cdf0e10cSrcweir int leftWidth = splitPos; 165*cdf0e10cSrcweir int rightWidth = width - splitPos; 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir if ( getChild( 0 ) && getChild( 0 )->mxChild.is() ) 168*cdf0e10cSrcweir { 169*cdf0e10cSrcweir awt::Rectangle childRect( 0, 0, rArea.Width, rArea.Height ); 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir if ( mbHorizontal ) 172*cdf0e10cSrcweir childRect.Width = leftWidth - 2; 173*cdf0e10cSrcweir else 174*cdf0e10cSrcweir childRect.Height = leftWidth - 2; 175*cdf0e10cSrcweir allocateChildAt( getChild( 0 )->mxChild, childRect ); 176*cdf0e10cSrcweir } 177*cdf0e10cSrcweir if ( getChild( 0 ) && getChild( 0 )->mxChild.is() ) 178*cdf0e10cSrcweir { 179*cdf0e10cSrcweir awt::Rectangle childRect( 0, 0, rArea.Width, rArea.Height ); 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir if ( mbHorizontal ) 182*cdf0e10cSrcweir { 183*cdf0e10cSrcweir childRect.X += leftWidth + splitLen + 2; 184*cdf0e10cSrcweir childRect.Width = rightWidth; 185*cdf0e10cSrcweir } 186*cdf0e10cSrcweir else 187*cdf0e10cSrcweir { 188*cdf0e10cSrcweir childRect.Y += leftWidth + splitLen + 2; 189*cdf0e10cSrcweir childRect.Height = rightWidth; 190*cdf0e10cSrcweir } 191*cdf0e10cSrcweir allocateChildAt( getChild( 1 )->mxChild, childRect ); 192*cdf0e10cSrcweir } 193*cdf0e10cSrcweir } 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir ::com::sun::star::awt::Size SAL_CALL VCLXSplitter::getMinimumSize() 196*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 197*cdf0e10cSrcweir { 198*cdf0e10cSrcweir ensureSplitter(); 199*cdf0e10cSrcweir 200*cdf0e10cSrcweir awt::Size size( mbHorizontal ? 2 : 0, mbHorizontal ? 0 : 2 ); 201*cdf0e10cSrcweir for ( unsigned int i = 0; i < 2; i++ ) 202*cdf0e10cSrcweir { 203*cdf0e10cSrcweir if ( getChild( i ) && getChild( i )->mxChild.is() ) 204*cdf0e10cSrcweir { 205*cdf0e10cSrcweir awt::Size childSize = getChild( i )->mxChild->getMinimumSize(); 206*cdf0e10cSrcweir if ( mbHorizontal ) 207*cdf0e10cSrcweir { 208*cdf0e10cSrcweir size.Width += childSize.Width; 209*cdf0e10cSrcweir size.Height = SAL_MAX( size.Height, childSize.Height ); 210*cdf0e10cSrcweir } 211*cdf0e10cSrcweir else 212*cdf0e10cSrcweir { 213*cdf0e10cSrcweir size.Width = SAL_MAX( size.Width, childSize.Width ); 214*cdf0e10cSrcweir size.Height += childSize.Height; 215*cdf0e10cSrcweir } 216*cdf0e10cSrcweir } 217*cdf0e10cSrcweir } 218*cdf0e10cSrcweir 219*cdf0e10cSrcweir maRequisition = size; 220*cdf0e10cSrcweir return size; 221*cdf0e10cSrcweir } 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir void VCLXSplitter::ProcessWindowEvent( const VclWindowEvent& _rVclWindowEvent ) 224*cdf0e10cSrcweir { 225*cdf0e10cSrcweir VCLXWindow::ProcessWindowEvent( _rVclWindowEvent ); 226*cdf0e10cSrcweir } 227*cdf0e10cSrcweir 228*cdf0e10cSrcweir void SAL_CALL VCLXSplitter::setProperty( const ::rtl::OUString& PropertyName, const Any &Value ) throw(RuntimeException) 229*cdf0e10cSrcweir { 230*cdf0e10cSrcweir VCLXWindow::setProperty( PropertyName, Value ); 231*cdf0e10cSrcweir } 232*cdf0e10cSrcweir 233*cdf0e10cSrcweir Any SAL_CALL VCLXSplitter::getProperty( const ::rtl::OUString& PropertyName ) throw(RuntimeException) 234*cdf0e10cSrcweir { 235*cdf0e10cSrcweir return VCLXWindow::getProperty( PropertyName ); 236*cdf0e10cSrcweir } 237*cdf0e10cSrcweir 238*cdf0e10cSrcweir IMPL_LINK( VCLXSplitter, HandleMovedHdl, Splitter *, pSplitter ) 239*cdf0e10cSrcweir { 240*cdf0e10cSrcweir (void) pSplitter; 241*cdf0e10cSrcweir forceRecalc(); 242*cdf0e10cSrcweir return 0; 243*cdf0e10cSrcweir } 244*cdf0e10cSrcweir 245*cdf0e10cSrcweir } // namespace layoutimpl 246