1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: vclxsplitter.cxx,v $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 #include "vclxsplitter.hxx"
35 #include <com/sun/star/awt/PosSize.hpp>
36 #include <sal/macros.h>
37 #include <toolkit/helper/property.hxx>
38 #include <toolkit/helper/vclunohelper.hxx>
39 #include <vcl/split.hxx>
41 #include "forward.hxx"
46 using namespace ::com::sun::star::uno
;
47 using namespace ::com::sun::star::awt
;
48 using namespace ::com::sun::star::lang
;
49 using namespace ::com::sun::star::beans
;
50 using namespace ::com::sun::star
;
52 VCLXSplitter::ChildProps::ChildProps( VCLXSplitter::ChildData
*pData
)
54 addProp( RTL_CONSTASCII_USTRINGPARAM( "Shrink" ),
55 ::getCppuType( static_cast< const rtl::OUString
* >( NULL
) ),
59 VCLXSplitter::ChildData::ChildData( uno::Reference
< awt::XLayoutConstrains
> const& xChild
)
60 : Box_Base::ChildData( xChild
)
65 VCLXSplitter::ChildData
*
66 VCLXSplitter::createChild( uno::Reference
< awt::XLayoutConstrains
> const& xChild
)
68 return new ChildData( xChild
);
71 VCLXSplitter::ChildProps
*
72 VCLXSplitter::createChildProps( Box_Base::ChildData
*pData
)
74 return new ChildProps( static_cast<VCLXSplitter::ChildData
*> ( pData
) );
78 DBG_NAME( VCLXSplitter
);
80 VCLXSplitter::VCLXSplitter( bool bHorizontal
)
84 DBG_CTOR( VCLXSplitter
, NULL
);
86 mbHandlePressed
= false;
87 mbHorizontal
= bHorizontal
;
91 VCLXSplitter::~VCLXSplitter()
93 DBG_DTOR( VCLXSplitter
, NULL
);
96 IMPLEMENT_2_FORWARD_XINTERFACE1( VCLXSplitter
, VCLXWindow
, Container
);
98 IMPLEMENT_FORWARD_XTYPEPROVIDER1( VCLXSplitter
, VCLXWindow
);
100 VCLXSplitter::ChildData
*
101 VCLXSplitter::getChild( int i
)
103 if ( maChildren
.size() && i
== 0 )
104 return static_cast<VCLXSplitter::ChildData
*>( maChildren
.front() );
105 else if ( maChildren
.size() > 1 && i
== 1 )
106 return static_cast<VCLXSplitter::ChildData
*>( maChildren
.back() );
110 void SAL_CALL
VCLXSplitter::dispose() throw(RuntimeException
)
113 ::vos::OGuard
aGuard( GetMutex() );
115 EventObject aDisposeEvent
;
116 aDisposeEvent
.Source
= W3K_EXPLICIT_CAST (*this);
117 // maTabListeners.disposeAndClear( aDisposeEvent );
120 VCLXWindow::dispose();
123 void VCLXSplitter::ensureSplitter()
127 mpSplitter
= new Splitter( GetWindow() , mbHorizontal
? WB_HORZ
: WB_VERT
);
129 mpSplitter
->SetEndSplitHdl( LINK( this, VCLXSplitter
, HandleMovedHdl
) );
133 void SAL_CALL
VCLXSplitter::addChild(
134 const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XLayoutConstrains
> &xChild
)
135 throw (::com::sun::star::uno::RuntimeException
, ::com::sun::star::awt::MaxChildrenException
)
137 if ( maChildren
.size() == 2 )
138 throw css::awt::MaxChildrenException();
139 Box_Base::addChild( xChild
);
142 void SAL_CALL
VCLXSplitter::allocateArea(
143 const ::com::sun::star::awt::Rectangle
&rArea
)
144 throw (::com::sun::star::uno::RuntimeException
)
146 ensureSplitter(); // shouldn't be needed...
150 splitDiff
= rArea
.Width
- maAllocation
.Width
;
152 splitDiff
= rArea
.Height
- maAllocation
.Height
;
154 assert( mpSplitter
);
156 mpSplitter
->SetSplitPosPixel( mpSplitter
->GetSplitPosPixel() + splitDiff
/2 );
158 maAllocation
= rArea
;
159 int width
= mbHorizontal
? rArea
.Width
: rArea
.Height
;
161 int splitPos
= mpSplitter
->GetSplitPosPixel();
162 setPosSize( rArea
.X
, rArea
.Y
, rArea
.Width
, rArea
.Height
, PosSize::POSSIZE
);
164 mpSplitter
->SetPosSizePixel( splitPos
, 0, splitLen
, rArea
.Height
, PosSize::POSSIZE
);
166 mpSplitter
->SetPosSizePixel( 0, splitPos
, rArea
.Width
, splitLen
, PosSize::POSSIZE
);
167 mpSplitter
->SetDragRectPixel( ::Rectangle( 0, 0, rArea
.Width
, rArea
.Height
) );
168 int leftWidth
= splitPos
;
169 int rightWidth
= width
- splitPos
;
171 if ( getChild( 0 ) && getChild( 0 )->mxChild
.is() )
173 awt::Rectangle
childRect( 0, 0, rArea
.Width
, rArea
.Height
);
176 childRect
.Width
= leftWidth
- 2;
178 childRect
.Height
= leftWidth
- 2;
179 allocateChildAt( getChild( 0 )->mxChild
, childRect
);
181 if ( getChild( 0 ) && getChild( 0 )->mxChild
.is() )
183 awt::Rectangle
childRect( 0, 0, rArea
.Width
, rArea
.Height
);
187 childRect
.X
+= leftWidth
+ splitLen
+ 2;
188 childRect
.Width
= rightWidth
;
192 childRect
.Y
+= leftWidth
+ splitLen
+ 2;
193 childRect
.Height
= rightWidth
;
195 allocateChildAt( getChild( 1 )->mxChild
, childRect
);
199 ::com::sun::star::awt::Size SAL_CALL
VCLXSplitter::getMinimumSize()
200 throw(::com::sun::star::uno::RuntimeException
)
204 awt::Size
size( mbHorizontal
? 2 : 0, mbHorizontal
? 0 : 2 );
205 for ( unsigned int i
= 0; i
< 2; i
++ )
207 if ( getChild( i
) && getChild( i
)->mxChild
.is() )
209 awt::Size childSize
= getChild( i
)->mxChild
->getMinimumSize();
212 size
.Width
+= childSize
.Width
;
213 size
.Height
= SAL_MAX( size
.Height
, childSize
.Height
);
217 size
.Width
= SAL_MAX( size
.Width
, childSize
.Width
);
218 size
.Height
+= childSize
.Height
;
223 maRequisition
= size
;
227 void VCLXSplitter::ProcessWindowEvent( const VclWindowEvent
& _rVclWindowEvent
)
229 VCLXWindow::ProcessWindowEvent( _rVclWindowEvent
);
232 void SAL_CALL
VCLXSplitter::setProperty( const ::rtl::OUString
& PropertyName
, const Any
&Value
) throw(RuntimeException
)
234 VCLXWindow::setProperty( PropertyName
, Value
);
237 Any SAL_CALL
VCLXSplitter::getProperty( const ::rtl::OUString
& PropertyName
) throw(RuntimeException
)
239 return VCLXWindow::getProperty( PropertyName
);
242 IMPL_LINK( VCLXSplitter
, HandleMovedHdl
, Splitter
*, pSplitter
)
249 } // namespace layoutimpl