xref: /AOO41X/main/toolkit/source/awt/vclxtabcontrol.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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 "vclxtabcontrol.hxx"
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir #include <com/sun/star/awt/PosSize.hpp>
31*cdf0e10cSrcweir #include <sal/macros.h>
32*cdf0e10cSrcweir #include <toolkit/helper/property.hxx>
33*cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx>
34*cdf0e10cSrcweir #include <vcl/tabctrl.hxx>
35*cdf0e10cSrcweir #include <vcl/tabpage.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::lang;
43*cdf0e10cSrcweir using namespace ::com::sun::star::beans;
44*cdf0e10cSrcweir using namespace ::com::sun::star;
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir VCLXTabControl::ChildProps::ChildProps( VCLXTabControl::ChildData *pData )
47*cdf0e10cSrcweir {
48*cdf0e10cSrcweir     addProp( RTL_CONSTASCII_USTRINGPARAM( "Title" ),
49*cdf0e10cSrcweir              ::getCppuType( static_cast< const rtl::OUString* >( NULL ) ),
50*cdf0e10cSrcweir              &(pData->maTitle) );
51*cdf0e10cSrcweir }
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir VCLXTabControl::ChildData::ChildData( uno::Reference< awt::XLayoutConstrains > const& xChild )
54*cdf0e10cSrcweir     : Box_Base::ChildData( xChild )
55*cdf0e10cSrcweir     , maTitle()
56*cdf0e10cSrcweir {
57*cdf0e10cSrcweir }
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir VCLXTabControl::ChildData*
60*cdf0e10cSrcweir VCLXTabControl::createChild( uno::Reference< awt::XLayoutConstrains > const& xChild )
61*cdf0e10cSrcweir {
62*cdf0e10cSrcweir     return new ChildData( xChild );
63*cdf0e10cSrcweir }
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir VCLXTabControl::ChildProps*
66*cdf0e10cSrcweir VCLXTabControl::createChildProps( Box_Base::ChildData *pData )
67*cdf0e10cSrcweir {
68*cdf0e10cSrcweir     return new ChildProps( static_cast<VCLXTabControl::ChildData*> ( pData ) );
69*cdf0e10cSrcweir }
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir DBG_NAME( VCLXTabControl );
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir #if !defined (__GNUC__)
74*cdf0e10cSrcweir #define __PRETTY_FUNCTION__ __FUNCTION__
75*cdf0e10cSrcweir #endif /* !__GNUC__ */
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir VCLXTabControl::VCLXTabControl()
78*cdf0e10cSrcweir   : VCLXWindow()
79*cdf0e10cSrcweir   , VCLXTabControl_Base()
80*cdf0e10cSrcweir   , Box_Base()
81*cdf0e10cSrcweir   , mTabId (1)
82*cdf0e10cSrcweir   , bRealized (false)
83*cdf0e10cSrcweir {
84*cdf0e10cSrcweir #ifndef __SUNPRO_CC
85*cdf0e10cSrcweir     OSL_TRACE ("\n********%s:%x", __PRETTY_FUNCTION__, this);
86*cdf0e10cSrcweir #endif
87*cdf0e10cSrcweir     DBG_CTOR( VCLXTabControl, NULL );
88*cdf0e10cSrcweir }
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir VCLXTabControl::~VCLXTabControl()
91*cdf0e10cSrcweir {
92*cdf0e10cSrcweir     DBG_DTOR( VCLXTabControl, NULL );
93*cdf0e10cSrcweir }
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir IMPLEMENT_2_FORWARD_XINTERFACE2( VCLXTabControl, VCLXWindow, Container, VCLXTabControl_Base );
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXTabControl, VCLXWindow, VCLXTabControl_Base );
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir void SAL_CALL VCLXTabControl::dispose( ) throw(uno::RuntimeException)
100*cdf0e10cSrcweir {
101*cdf0e10cSrcweir     {
102*cdf0e10cSrcweir         ::vos::OGuard aGuard( GetMutex() );
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir         EventObject aDisposeEvent;
105*cdf0e10cSrcweir         aDisposeEvent.Source = W3K_EXPLICIT_CAST (*this);
106*cdf0e10cSrcweir //            maTabListeners.disposeAndClear( aDisposeEvent );
107*cdf0e10cSrcweir     }
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir     VCLXWindow::dispose();
110*cdf0e10cSrcweir }
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir #if 0
113*cdf0e10cSrcweir void SAL_CALL VCLXTabControl::addTabListener( const Reference< XTabListener >& listener ) throw (uno::RuntimeException)
114*cdf0e10cSrcweir {
115*cdf0e10cSrcweir     if ( listener.is() )
116*cdf0e10cSrcweir         maTabListeners.addInterface( listener );
117*cdf0e10cSrcweir }
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir void SAL_CALL VCLXTabControl::removeTabListener( const Reference< XTabListener >& listener ) throw (uno::RuntimeException)
120*cdf0e10cSrcweir {
121*cdf0e10cSrcweir     if ( listener.is() )
122*cdf0e10cSrcweir         maTabListeners.removeInterface( listener );
123*cdf0e10cSrcweir }
124*cdf0e10cSrcweir #endif
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir TabControl *VCLXTabControl::getTabControl() const throw (uno::RuntimeException)
127*cdf0e10cSrcweir {
128*cdf0e10cSrcweir     TabControl *pTabControl = static_cast< TabControl* >( GetWindow() );
129*cdf0e10cSrcweir     if ( pTabControl )
130*cdf0e10cSrcweir         return pTabControl;
131*cdf0e10cSrcweir     throw uno::RuntimeException();
132*cdf0e10cSrcweir }
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir sal_Int32 SAL_CALL VCLXTabControl::insertTab() throw (uno::RuntimeException)
135*cdf0e10cSrcweir {
136*cdf0e10cSrcweir     TabControl *pTabControl = getTabControl();
137*cdf0e10cSrcweir     sal_uInt16 id = sal::static_int_cast< sal_uInt16 >( mTabId++ );
138*cdf0e10cSrcweir     rtl::OUString title (RTL_CONSTASCII_USTRINGPARAM( "" ) );
139*cdf0e10cSrcweir     pTabControl->InsertPage( id, title.getStr(), TAB_APPEND );
140*cdf0e10cSrcweir     pTabControl->SetTabPage( id, new TabPage( pTabControl ) );
141*cdf0e10cSrcweir     return id;
142*cdf0e10cSrcweir }
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir void SAL_CALL VCLXTabControl::removeTab( sal_Int32 ID ) throw (uno::RuntimeException, IndexOutOfBoundsException)
145*cdf0e10cSrcweir {
146*cdf0e10cSrcweir     TabControl *pTabControl = getTabControl();
147*cdf0e10cSrcweir     if ( pTabControl->GetTabPage( sal::static_int_cast< sal_uInt16 >( ID ) ) == NULL )
148*cdf0e10cSrcweir         throw IndexOutOfBoundsException();
149*cdf0e10cSrcweir     pTabControl->RemovePage( sal::static_int_cast< sal_uInt16 >( ID ) );
150*cdf0e10cSrcweir }
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir void SAL_CALL VCLXTabControl::activateTab( sal_Int32 ID ) throw (uno::RuntimeException, IndexOutOfBoundsException)
153*cdf0e10cSrcweir {
154*cdf0e10cSrcweir     TabControl *pTabControl = getTabControl();
155*cdf0e10cSrcweir     if ( pTabControl->GetTabPage( sal::static_int_cast< sal_uInt16 >( ID ) ) == NULL )
156*cdf0e10cSrcweir         throw IndexOutOfBoundsException();
157*cdf0e10cSrcweir     pTabControl->SelectTabPage( sal::static_int_cast< sal_uInt16 >( ID ) );
158*cdf0e10cSrcweir }
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir sal_Int32 SAL_CALL VCLXTabControl::getActiveTabID() throw (uno::RuntimeException)
161*cdf0e10cSrcweir {
162*cdf0e10cSrcweir     return getTabControl()->GetCurPageId( );
163*cdf0e10cSrcweir }
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir void SAL_CALL VCLXTabControl::addTabListener( const uno::Reference< awt::XTabListener >& xListener ) throw (uno::RuntimeException)
166*cdf0e10cSrcweir {
167*cdf0e10cSrcweir     for ( std::list< uno::Reference
168*cdf0e10cSrcweir               < awt::XTabListener > >::const_iterator it
169*cdf0e10cSrcweir               = mxTabListeners.begin(); it != mxTabListeners.end(); it++ )
170*cdf0e10cSrcweir     {
171*cdf0e10cSrcweir         if ( *it == xListener )
172*cdf0e10cSrcweir             // already added
173*cdf0e10cSrcweir             return;
174*cdf0e10cSrcweir     }
175*cdf0e10cSrcweir     mxTabListeners.push_back( xListener );
176*cdf0e10cSrcweir }
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir void SAL_CALL VCLXTabControl::removeTabListener( const uno::Reference< awt::XTabListener >& xListener ) throw (uno::RuntimeException)
179*cdf0e10cSrcweir {
180*cdf0e10cSrcweir     for ( std::list< uno::Reference
181*cdf0e10cSrcweir               < awt::XTabListener > >::iterator it
182*cdf0e10cSrcweir               = mxTabListeners.begin(); it != mxTabListeners.end(); it++ )
183*cdf0e10cSrcweir     {
184*cdf0e10cSrcweir         if ( *it == xListener )
185*cdf0e10cSrcweir         {
186*cdf0e10cSrcweir             mxTabListeners.erase( it );
187*cdf0e10cSrcweir             break;
188*cdf0e10cSrcweir         }
189*cdf0e10cSrcweir     }
190*cdf0e10cSrcweir }
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir void SAL_CALL VCLXTabControl::setTabProps( sal_Int32 ID, const uno::Sequence< NamedValue >& Properties ) throw (uno::RuntimeException, IndexOutOfBoundsException)
193*cdf0e10cSrcweir {
194*cdf0e10cSrcweir     TabControl *pTabControl = getTabControl();
195*cdf0e10cSrcweir     if ( pTabControl->GetTabPage( sal::static_int_cast< sal_uInt16 >( ID ) ) == NULL )
196*cdf0e10cSrcweir         throw IndexOutOfBoundsException();
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir     for ( int i = 0; i < Properties.getLength(); i++ )
199*cdf0e10cSrcweir     {
200*cdf0e10cSrcweir         const rtl::OUString &name = Properties[i].Name;
201*cdf0e10cSrcweir         const uno::Any &value = Properties[i].Value;
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir         if ( name  == rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Title" ) ) )
204*cdf0e10cSrcweir         {
205*cdf0e10cSrcweir             rtl::OUString title = value.get<rtl::OUString>();
206*cdf0e10cSrcweir             pTabControl->SetPageText( sal::static_int_cast< sal_uInt16 >( ID ), title.getStr() );
207*cdf0e10cSrcweir         }
208*cdf0e10cSrcweir     }
209*cdf0e10cSrcweir }
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir uno::Sequence< NamedValue > SAL_CALL VCLXTabControl::getTabProps( sal_Int32 ID )
212*cdf0e10cSrcweir     throw (IndexOutOfBoundsException, uno::RuntimeException)
213*cdf0e10cSrcweir {
214*cdf0e10cSrcweir     TabControl *pTabControl = getTabControl();
215*cdf0e10cSrcweir     if ( pTabControl->GetTabPage( sal::static_int_cast< sal_uInt16 >( ID ) ) == NULL )
216*cdf0e10cSrcweir         throw IndexOutOfBoundsException();
217*cdf0e10cSrcweir 
218*cdf0e10cSrcweir #define ADD_PROP( seq, i, name, val ) {                                \
219*cdf0e10cSrcweir         NamedValue value;                                                  \
220*cdf0e10cSrcweir         value.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( name ) ); \
221*cdf0e10cSrcweir         value.Value = uno::makeAny( val );                                      \
222*cdf0e10cSrcweir         seq[i] = value;                                                    \
223*cdf0e10cSrcweir     }
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir     uno::Sequence< NamedValue > props( 2 );
226*cdf0e10cSrcweir     ADD_PROP( props, 0, "Title", rtl::OUString( pTabControl->GetPageText( sal::static_int_cast< sal_uInt16 >( ID ) ) ) );
227*cdf0e10cSrcweir     ADD_PROP( props, 1, "Position", pTabControl->GetPagePos( sal::static_int_cast< sal_uInt16 >( ID ) ) );
228*cdf0e10cSrcweir #undef ADD_PROP
229*cdf0e10cSrcweir     return props;
230*cdf0e10cSrcweir }
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir // TODO: draw tab border here
233*cdf0e10cSrcweir void SAL_CALL VCLXTabControl::draw( sal_Int32 nX, sal_Int32 nY ) throw(uno::RuntimeException)
234*cdf0e10cSrcweir {
235*cdf0e10cSrcweir     ::vos::OGuard aGuard( GetMutex() );
236*cdf0e10cSrcweir 
237*cdf0e10cSrcweir     TabControl *pTabControl = getTabControl();
238*cdf0e10cSrcweir     TabPage *pTabPage = pTabControl->GetTabPage( sal::static_int_cast< sal_uInt16 >(  getActiveTabID() ) );
239*cdf0e10cSrcweir     if ( pTabPage )
240*cdf0e10cSrcweir     {
241*cdf0e10cSrcweir         ::Point aPos( nX, nY );
242*cdf0e10cSrcweir         ::Size  aSize = pTabPage->GetSizePixel();
243*cdf0e10cSrcweir 
244*cdf0e10cSrcweir 		OutputDevice* pDev = VCLUnoHelper::GetOutputDevice( getGraphics() );
245*cdf0e10cSrcweir         aPos  = pDev->PixelToLogic( aPos );
246*cdf0e10cSrcweir         aSize = pDev->PixelToLogic( aSize );
247*cdf0e10cSrcweir 
248*cdf0e10cSrcweir         pTabPage->Draw( pDev, aPos, aSize, 0 );
249*cdf0e10cSrcweir     }
250*cdf0e10cSrcweir 
251*cdf0e10cSrcweir     VCLXWindow::draw( nX, nY );
252*cdf0e10cSrcweir }
253*cdf0e10cSrcweir 
254*cdf0e10cSrcweir void VCLXTabControl::AddChild (uno::Reference< awt::XLayoutConstrains > const& xChild)
255*cdf0e10cSrcweir 
256*cdf0e10cSrcweir {
257*cdf0e10cSrcweir #ifndef __SUNPRO_CC
258*cdf0e10cSrcweir     OSL_TRACE ("%s: children: %d", __PRETTY_FUNCTION__, maChildren.size ());
259*cdf0e10cSrcweir #endif
260*cdf0e10cSrcweir     mIdMap[ xChild ] = mTabId++;
261*cdf0e10cSrcweir     Box_Base::AddChild( xChild );
262*cdf0e10cSrcweir #ifndef __SUNPRO_CC
263*cdf0e10cSrcweir     OSL_TRACE ("%s: children: %d", __PRETTY_FUNCTION__, maChildren.size ());
264*cdf0e10cSrcweir #endif
265*cdf0e10cSrcweir }
266*cdf0e10cSrcweir 
267*cdf0e10cSrcweir void SAL_CALL VCLXTabControl::addChild(
268*cdf0e10cSrcweir     const uno::Reference< awt::XLayoutConstrains > &xChild )
269*cdf0e10cSrcweir     throw (uno::RuntimeException, awt::MaxChildrenException)
270*cdf0e10cSrcweir {
271*cdf0e10cSrcweir     mIdMap[ xChild ] = insertTab();
272*cdf0e10cSrcweir     Box_Base::addChild( xChild );
273*cdf0e10cSrcweir }
274*cdf0e10cSrcweir 
275*cdf0e10cSrcweir void SAL_CALL VCLXTabControl::removeChild( const uno::Reference< awt::XLayoutConstrains > &xChild )
276*cdf0e10cSrcweir     throw (uno::RuntimeException)
277*cdf0e10cSrcweir {
278*cdf0e10cSrcweir     removeTab( mIdMap[xChild] );
279*cdf0e10cSrcweir     mIdMap[ xChild ] = -1;
280*cdf0e10cSrcweir     Box_Base::removeChild( xChild );
281*cdf0e10cSrcweir }
282*cdf0e10cSrcweir 
283*cdf0e10cSrcweir static void setChildrenVisible( uno::Reference < awt::XLayoutConstrains > xChild, bool visible )
284*cdf0e10cSrcweir {
285*cdf0e10cSrcweir     uno::Reference< awt::XWindow > xWin( xChild, uno::UNO_QUERY);
286*cdf0e10cSrcweir     if ( xWin.is() )
287*cdf0e10cSrcweir     {
288*cdf0e10cSrcweir         xWin->setVisible( visible );
289*cdf0e10cSrcweir     }
290*cdf0e10cSrcweir 
291*cdf0e10cSrcweir     uno::Reference < awt::XLayoutContainer > xCont( xChild, uno::UNO_QUERY );
292*cdf0e10cSrcweir     if ( xCont.is())
293*cdf0e10cSrcweir     {
294*cdf0e10cSrcweir         uno::Sequence< uno::Reference < awt::XLayoutConstrains > > children = xCont->getChildren();
295*cdf0e10cSrcweir         for ( int i = 0; i < children.getLength(); i++ )
296*cdf0e10cSrcweir         {
297*cdf0e10cSrcweir             setChildrenVisible( children[i], visible );
298*cdf0e10cSrcweir         }
299*cdf0e10cSrcweir     }
300*cdf0e10cSrcweir }
301*cdf0e10cSrcweir 
302*cdf0e10cSrcweir void SAL_CALL VCLXTabControl::allocateArea (awt::Rectangle const &area)
303*cdf0e10cSrcweir     throw (uno::RuntimeException)
304*cdf0e10cSrcweir {
305*cdf0e10cSrcweir #ifndef __SUNPRO_CC
306*cdf0e10cSrcweir     OSL_TRACE ("\n%s", __PRETTY_FUNCTION__);
307*cdf0e10cSrcweir #endif
308*cdf0e10cSrcweir     maAllocation = area;
309*cdf0e10cSrcweir 
310*cdf0e10cSrcweir     TabControl *pTabControl = getTabControl();
311*cdf0e10cSrcweir 
312*cdf0e10cSrcweir // FIXME: this is wrong. We just want to set tab controls pos/size for
313*cdf0e10cSrcweir // the tabs menu, otherwise, it gets events that should go to children
314*cdf0e10cSrcweir // (I guess we could solve this by making the tabcontrol as the actual
315*cdf0e10cSrcweir // XWindow parent of its children, when importing...)  Not sure about
316*cdf0e10cSrcweir // TabPage drawing... That doesn't work on gtk+; just ignoring that.
317*cdf0e10cSrcweir // LATER: Nah, the proper fix is to get the XWindow hierarchy
318*cdf0e10cSrcweir // straight.
319*cdf0e10cSrcweir 
320*cdf0e10cSrcweir #if 0
321*cdf0e10cSrcweir     setPosSize( area.X, area.Y, area.Width, area.Height, awt::PosSize::POSSIZE );
322*cdf0e10cSrcweir #else
323*cdf0e10cSrcweir     awt::Size currentSize = getSize();
324*cdf0e10cSrcweir     awt::Size requestedSize (area.Width, area.Height);
325*cdf0e10cSrcweir //    requestedSize.Height = getHeightForWidth( area.Width );
326*cdf0e10cSrcweir 
327*cdf0e10cSrcweir     awt::Size minimumSize = getMinimumSize();
328*cdf0e10cSrcweir     if (requestedSize.Width < minimumSize.Width)
329*cdf0e10cSrcweir         requestedSize.Width = minimumSize.Width;
330*cdf0e10cSrcweir     if (requestedSize.Height < minimumSize.Height)
331*cdf0e10cSrcweir         requestedSize.Height = minimumSize.Height;
332*cdf0e10cSrcweir 
333*cdf0e10cSrcweir     Size pageSize = static_cast<TabControl*> (GetWindow ())->GetTabPageSizePixel ();
334*cdf0e10cSrcweir     awt::Size pageBasedSize (0, 0);
335*cdf0e10cSrcweir     pageBasedSize.Width = pageSize.Width ();
336*cdf0e10cSrcweir     pageBasedSize.Height = pageSize.Height ();
337*cdf0e10cSrcweir 
338*cdf0e10cSrcweir     const int wc = 0;
339*cdf0e10cSrcweir     const int hc = 20;
340*cdf0e10cSrcweir     static int pwc = 0;
341*cdf0e10cSrcweir     static int phc = 40;
342*cdf0e10cSrcweir 
343*cdf0e10cSrcweir     if (requestedSize.Width < pageBasedSize.Width)
344*cdf0e10cSrcweir         requestedSize.Width = pageBasedSize.Width + wc;
345*cdf0e10cSrcweir     if (requestedSize.Height < pageBasedSize.Height)
346*cdf0e10cSrcweir         requestedSize.Height = pageBasedSize.Height + hc;
347*cdf0e10cSrcweir 
348*cdf0e10cSrcweir     Size windowSize = GetWindow()->GetSizePixel();
349*cdf0e10cSrcweir     Window *parent = GetWindow()->GetParent();
350*cdf0e10cSrcweir     Size parentSize = parent->GetSizePixel();
351*cdf0e10cSrcweir 
352*cdf0e10cSrcweir #ifndef __SUNPRO_CC
353*cdf0e10cSrcweir #ifdef GCC_MAJOR
354*cdf0e10cSrcweir     OSL_TRACE ("\n%s", __PRETTY_FUNCTION__);
355*cdf0e10cSrcweir #endif /* GCC_MAJOR */
356*cdf0e10cSrcweir     OSL_TRACE ("%s: cursize: %d ,%d", __FUNCTION__, currentSize.Width, currentSize.Height );
357*cdf0e10cSrcweir     OSL_TRACE ("%s: area: %d, %d", __FUNCTION__, area.Width, area.Height );
358*cdf0e10cSrcweir     OSL_TRACE ("%s: minimum: %d, %d", __FUNCTION__, minimumSize.Width, minimumSize.Height );
359*cdf0e10cSrcweir     OSL_TRACE ("%s: requestedSize: %d, %d", __FUNCTION__, requestedSize.Width, requestedSize.Height );
360*cdf0e10cSrcweir     OSL_TRACE ("%s: pageBasedSize: %d, %d", __FUNCTION__, pageBasedSize.Width, pageBasedSize.Height );
361*cdf0e10cSrcweir 
362*cdf0e10cSrcweir     //OSL_TRACE ("%s: parent: %d, %d", __FUNCTION__, parentSize.Width(), parentSize.Height() );
363*cdf0e10cSrcweir     //OSL_TRACE ("%s: window: %d, %d", __FUNCTION__, windowSize.Width(), windowSize.Height() );
364*cdf0e10cSrcweir #endif
365*cdf0e10cSrcweir 
366*cdf0e10cSrcweir 	//bRealized = false;
367*cdf0e10cSrcweir     if (!bRealized)
368*cdf0e10cSrcweir     {
369*cdf0e10cSrcweir         setPosSize( area.X, area.Y, requestedSize.Width, requestedSize.Height, awt::PosSize::POSSIZE );
370*cdf0e10cSrcweir         bRealized = true;
371*cdf0e10cSrcweir     }
372*cdf0e10cSrcweir     else
373*cdf0e10cSrcweir     {
374*cdf0e10cSrcweir         if ( requestedSize.Width > currentSize.Width + 10)
375*cdf0e10cSrcweir             setPosSize( 0, 0, requestedSize.Width, 0, awt::PosSize::WIDTH );
376*cdf0e10cSrcweir         if ( requestedSize.Height > currentSize.Height + 10)
377*cdf0e10cSrcweir             setPosSize( 0, 0, 0, requestedSize.Height, awt::PosSize::HEIGHT );
378*cdf0e10cSrcweir     }
379*cdf0e10cSrcweir #endif
380*cdf0e10cSrcweir 
381*cdf0e10cSrcweir     if (pageBasedSize.Width > parentSize.Width ()
382*cdf0e10cSrcweir         || pageBasedSize.Height > parentSize.Height ())
383*cdf0e10cSrcweir         //parent->SetSizePixel ( Size (pageBasedSize.Width, pageBasedSize.Height));
384*cdf0e10cSrcweir         //parent->SetSizePixel ( Size (pageBasedSize.Width + pwc, pageBasedSize.Height + phc));
385*cdf0e10cSrcweir         parent->SetSizePixel ( Size (requestedSize.Width + pwc, requestedSize.Height + phc));
386*cdf0e10cSrcweir 
387*cdf0e10cSrcweir     // FIXME: we can save cycles by setting visibility more sensibly. Having
388*cdf0e10cSrcweir     // it here does makes it easier when changing tabs (just needs a recalc())
389*cdf0e10cSrcweir     unsigned i = 0;
390*cdf0e10cSrcweir     for ( std::list<Box_Base::ChildData *>::const_iterator it
391*cdf0e10cSrcweir               = maChildren.begin(); it != maChildren.end(); it++, i++ )
392*cdf0e10cSrcweir     {
393*cdf0e10cSrcweir         ChildData *child = static_cast<VCLXTabControl::ChildData*> ( *it );
394*cdf0e10cSrcweir         uno::Reference
395*cdf0e10cSrcweir               < awt::XLayoutConstrains > xChild( child->mxChild );
396*cdf0e10cSrcweir         if ( xChild.is() )
397*cdf0e10cSrcweir         {
398*cdf0e10cSrcweir             uno::Reference< awt::XWindow > xWin( xChild, uno::UNO_QUERY );
399*cdf0e10cSrcweir             bool active = (i+1 == (unsigned) getActiveTabID());
400*cdf0e10cSrcweir 
401*cdf0e10cSrcweir             // HACK: since our layout:: container don't implement XWindow, we have no easy
402*cdf0e10cSrcweir             // way to set them invisible; lets just set all their children as such :P
403*cdf0e10cSrcweir #if 0
404*cdf0e10cSrcweir             if ( xWin.is() )
405*cdf0e10cSrcweir                 xWin->setVisible( active );
406*cdf0e10cSrcweir #else
407*cdf0e10cSrcweir             setChildrenVisible( xChild, active );
408*cdf0e10cSrcweir #endif
409*cdf0e10cSrcweir 
410*cdf0e10cSrcweir             if ( active )
411*cdf0e10cSrcweir             {
412*cdf0e10cSrcweir                 ::Rectangle label_rect = pTabControl->GetTabBounds( sal::static_int_cast< sal_uInt16 >( i+1 ) );
413*cdf0e10cSrcweir                 ::Rectangle page_rect = pTabControl->GetTabPageBounds( sal::static_int_cast< sal_uInt16 >( i+1 ) );
414*cdf0e10cSrcweir 
415*cdf0e10cSrcweir                 awt::Rectangle childRect;
416*cdf0e10cSrcweir                 childRect.X = page_rect.Left();
417*cdf0e10cSrcweir                 childRect.Y = SAL_MAX( label_rect.Bottom(), page_rect.Top() );
418*cdf0e10cSrcweir                 childRect.Width = page_rect.Right() - page_rect.Left();
419*cdf0e10cSrcweir                 childRect.Height = page_rect.Bottom() - childRect.Y;
420*cdf0e10cSrcweir 
421*cdf0e10cSrcweir                 allocateChildAt( xChild, childRect );
422*cdf0e10cSrcweir             }
423*cdf0e10cSrcweir         }
424*cdf0e10cSrcweir     }
425*cdf0e10cSrcweir }
426*cdf0e10cSrcweir 
427*cdf0e10cSrcweir awt::Size SAL_CALL VCLXTabControl::getMinimumSize()
428*cdf0e10cSrcweir     throw(uno::RuntimeException)
429*cdf0e10cSrcweir {
430*cdf0e10cSrcweir     awt::Size requestedSize = VCLXWindow::getMinimumSize();
431*cdf0e10cSrcweir     awt::Size childrenSize( 0, 0 );
432*cdf0e10cSrcweir 
433*cdf0e10cSrcweir     TabControl* pTabControl = static_cast< TabControl* >( GetWindow() );
434*cdf0e10cSrcweir     if ( !pTabControl )
435*cdf0e10cSrcweir         return requestedSize;
436*cdf0e10cSrcweir 
437*cdf0e10cSrcweir     // calculate size to accomodate all children
438*cdf0e10cSrcweir     unsigned i = 0;
439*cdf0e10cSrcweir     for ( std::list<Box_Base::ChildData *>::const_iterator it
440*cdf0e10cSrcweir               = maChildren.begin(); it != maChildren.end(); it++, i++ )
441*cdf0e10cSrcweir     {
442*cdf0e10cSrcweir         ChildData *child = static_cast<VCLXTabControl::ChildData*> ( *it );
443*cdf0e10cSrcweir         if ( child->mxChild.is() )
444*cdf0e10cSrcweir         {
445*cdf0e10cSrcweir             // set the title prop here...
446*cdf0e10cSrcweir             pTabControl->SetPageText( sal::static_int_cast< sal_uInt16 >( i+1 ), child->maTitle.getStr() );
447*cdf0e10cSrcweir 
448*cdf0e10cSrcweir             awt::Size childSize( child->mxChild->getMinimumSize() );
449*cdf0e10cSrcweir             childrenSize.Width = SAL_MAX( childSize.Width, childrenSize.Width );
450*cdf0e10cSrcweir             childrenSize.Height = SAL_MAX( childSize.Height, childrenSize.Height );
451*cdf0e10cSrcweir         }
452*cdf0e10cSrcweir     }
453*cdf0e10cSrcweir 
454*cdf0e10cSrcweir #ifndef __SUNPRO_CC
455*cdf0e10cSrcweir #ifdef GCC_MAJOR
456*cdf0e10cSrcweir     OSL_TRACE ("\n%s", __PRETTY_FUNCTION__);
457*cdf0e10cSrcweir #endif /* GCC_MAJOR */
458*cdf0e10cSrcweir     OSL_TRACE ("%s: children: %d", __FUNCTION__, i);
459*cdf0e10cSrcweir     OSL_TRACE ("%s: childrenSize: %d, %d", __FUNCTION__, childrenSize.Width, childrenSize.Height );
460*cdf0e10cSrcweir #endif
461*cdf0e10cSrcweir 
462*cdf0e10cSrcweir     requestedSize.Width += childrenSize.Width;
463*cdf0e10cSrcweir     requestedSize.Height += childrenSize.Height + 20;
464*cdf0e10cSrcweir 
465*cdf0e10cSrcweir     maRequisition = requestedSize;
466*cdf0e10cSrcweir     return requestedSize;
467*cdf0e10cSrcweir }
468*cdf0e10cSrcweir 
469*cdf0e10cSrcweir void VCLXTabControl::ProcessWindowEvent( const VclWindowEvent& _rVclWindowEvent )
470*cdf0e10cSrcweir {
471*cdf0e10cSrcweir     ::vos::OClearableGuard aGuard( GetMutex() );
472*cdf0e10cSrcweir     TabControl* pTabControl = static_cast< TabControl* >( GetWindow() );
473*cdf0e10cSrcweir     if ( !pTabControl )
474*cdf0e10cSrcweir         return;
475*cdf0e10cSrcweir 
476*cdf0e10cSrcweir     switch ( _rVclWindowEvent.GetId() )
477*cdf0e10cSrcweir     {
478*cdf0e10cSrcweir         case VCLEVENT_TABPAGE_ACTIVATE:
479*cdf0e10cSrcweir             forceRecalc();
480*cdf0e10cSrcweir         case VCLEVENT_TABPAGE_DEACTIVATE:
481*cdf0e10cSrcweir         case VCLEVENT_TABPAGE_INSERTED:
482*cdf0e10cSrcweir         case VCLEVENT_TABPAGE_REMOVED:
483*cdf0e10cSrcweir         case VCLEVENT_TABPAGE_REMOVEDALL:
484*cdf0e10cSrcweir         case VCLEVENT_TABPAGE_PAGETEXTCHANGED:
485*cdf0e10cSrcweir         {
486*cdf0e10cSrcweir             sal_uLong page = (sal_uLong) _rVclWindowEvent.GetData();
487*cdf0e10cSrcweir             for ( std::list< uno::Reference
488*cdf0e10cSrcweir                       < awt::XTabListener > >::iterator it
489*cdf0e10cSrcweir                       = mxTabListeners.begin(); it != mxTabListeners.end(); it++)
490*cdf0e10cSrcweir             {
491*cdf0e10cSrcweir                 uno::Reference
492*cdf0e10cSrcweir                     < awt::XTabListener > listener = *it;
493*cdf0e10cSrcweir 
494*cdf0e10cSrcweir                 switch ( _rVclWindowEvent.GetId() )
495*cdf0e10cSrcweir                 {
496*cdf0e10cSrcweir 
497*cdf0e10cSrcweir                     case VCLEVENT_TABPAGE_ACTIVATE:
498*cdf0e10cSrcweir                         listener->activated( page );
499*cdf0e10cSrcweir                         break;
500*cdf0e10cSrcweir                     case VCLEVENT_TABPAGE_DEACTIVATE:
501*cdf0e10cSrcweir                         listener->deactivated( page );
502*cdf0e10cSrcweir                         break;
503*cdf0e10cSrcweir                     case VCLEVENT_TABPAGE_INSERTED:
504*cdf0e10cSrcweir                         listener->inserted( page );
505*cdf0e10cSrcweir                         break;
506*cdf0e10cSrcweir                     case VCLEVENT_TABPAGE_REMOVED:
507*cdf0e10cSrcweir                         listener->removed( page );
508*cdf0e10cSrcweir                         break;
509*cdf0e10cSrcweir                     case VCLEVENT_TABPAGE_REMOVEDALL:
510*cdf0e10cSrcweir                         for ( int i = 1; i < mTabId; i++)
511*cdf0e10cSrcweir                         {
512*cdf0e10cSrcweir                             if ( pTabControl->GetTabPage( sal::static_int_cast< sal_uInt16 >( i ) ) )
513*cdf0e10cSrcweir                                 listener->removed( i );
514*cdf0e10cSrcweir                         }
515*cdf0e10cSrcweir                         break;
516*cdf0e10cSrcweir                     case VCLEVENT_TABPAGE_PAGETEXTCHANGED:
517*cdf0e10cSrcweir                         listener->changed( page, getTabProps( page ) );
518*cdf0e10cSrcweir                         break;
519*cdf0e10cSrcweir                 }
520*cdf0e10cSrcweir             }
521*cdf0e10cSrcweir             break;
522*cdf0e10cSrcweir         }
523*cdf0e10cSrcweir         default:
524*cdf0e10cSrcweir             aGuard.clear();
525*cdf0e10cSrcweir             VCLXWindow::ProcessWindowEvent( _rVclWindowEvent );
526*cdf0e10cSrcweir             break;
527*cdf0e10cSrcweir     }
528*cdf0e10cSrcweir }
529*cdf0e10cSrcweir 
530*cdf0e10cSrcweir void SAL_CALL VCLXTabControl::setProperty( const ::rtl::OUString& PropertyName, const uno::Any &Value ) throw(uno::RuntimeException)
531*cdf0e10cSrcweir {
532*cdf0e10cSrcweir     VCLXWindow::setProperty( PropertyName, Value );
533*cdf0e10cSrcweir }
534*cdf0e10cSrcweir 
535*cdf0e10cSrcweir uno::Any SAL_CALL VCLXTabControl::getProperty( const ::rtl::OUString& PropertyName ) throw(uno::RuntimeException)
536*cdf0e10cSrcweir {
537*cdf0e10cSrcweir     return VCLXWindow::getProperty( PropertyName );
538*cdf0e10cSrcweir }
539*cdf0e10cSrcweir 
540*cdf0e10cSrcweir } // namespace layoutimpl
541