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