xref: /AOO41X/main/vcl/source/control/tabctrl.cxx (revision ad3a95a388ca181114ec1bc6cb467fb7f4c38a0c)
19f62ea84SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
39f62ea84SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
49f62ea84SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
59f62ea84SAndrew Rist  * distributed with this work for additional information
69f62ea84SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
79f62ea84SAndrew Rist  * to you under the Apache License, Version 2.0 (the
89f62ea84SAndrew Rist  * "License"); you may not use this file except in compliance
99f62ea84SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
119f62ea84SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
139f62ea84SAndrew Rist  * Unless required by applicable law or agreed to in writing,
149f62ea84SAndrew Rist  * software distributed under the License is distributed on an
159f62ea84SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
169f62ea84SAndrew Rist  * KIND, either express or implied.  See the License for the
179f62ea84SAndrew Rist  * specific language governing permissions and limitations
189f62ea84SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
209f62ea84SAndrew Rist  *************************************************************/
219f62ea84SAndrew Rist 
229f62ea84SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_vcl.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "tools/debug.hxx"
28cdf0e10cSrcweir #include "tools/rc.h"
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include "vcl/svapp.hxx"
31cdf0e10cSrcweir #include "vcl/help.hxx"
32cdf0e10cSrcweir #include "vcl/event.hxx"
33cdf0e10cSrcweir #include "vcl/menu.hxx"
34cdf0e10cSrcweir #include "vcl/button.hxx"
35cdf0e10cSrcweir #include "vcl/tabpage.hxx"
36cdf0e10cSrcweir #include "vcl/tabctrl.hxx"
37cdf0e10cSrcweir #include "vcl/controllayout.hxx"
38cdf0e10cSrcweir #include "vcl/sound.hxx"
39cdf0e10cSrcweir #include "vcl/lstbox.hxx"
40cdf0e10cSrcweir 
41cdf0e10cSrcweir #include "controldata.hxx"
42cdf0e10cSrcweir #include "svdata.hxx"
43cdf0e10cSrcweir #include "window.h"
44cdf0e10cSrcweir 
45cdf0e10cSrcweir #include <hash_map>
46cdf0e10cSrcweir #include <vector>
47cdf0e10cSrcweir 
48cdf0e10cSrcweir // =======================================================================
49cdf0e10cSrcweir 
50cdf0e10cSrcweir struct ImplTabItem
51cdf0e10cSrcweir {
52cdf0e10cSrcweir     sal_uInt16              mnId;
53cdf0e10cSrcweir     sal_uInt16              mnTabPageResId;
54cdf0e10cSrcweir     TabPage*            mpTabPage;
55cdf0e10cSrcweir     String              maText;
56cdf0e10cSrcweir     String              maFormatText;
57cdf0e10cSrcweir     String              maHelpText;
58cdf0e10cSrcweir     rtl::OString        maHelpId;
59cdf0e10cSrcweir     Rectangle           maRect;
60cdf0e10cSrcweir     sal_uInt16              mnLine;
61cdf0e10cSrcweir     bool                mbFullVisible;
62cdf0e10cSrcweir     bool                mbEnabled;
63cdf0e10cSrcweir     Image               maTabImage;
64cdf0e10cSrcweir 
65cdf0e10cSrcweir     ImplTabItem()
66cdf0e10cSrcweir     : mnId( 0 ), mnTabPageResId( 0 ), mpTabPage( NULL ),
67cdf0e10cSrcweir       mnLine( 0 ), mbFullVisible( sal_False ), mbEnabled( true )
68cdf0e10cSrcweir     {}
69cdf0e10cSrcweir };
70cdf0e10cSrcweir 
71cdf0e10cSrcweir // -----------------------------------------------------------------------
72cdf0e10cSrcweir 
73cdf0e10cSrcweir struct ImplTabCtrlData
74cdf0e10cSrcweir {
75cdf0e10cSrcweir     std::hash_map< int, int >		maLayoutPageIdToLine;
76cdf0e10cSrcweir     std::hash_map< int, int >		maLayoutLineToPageId;
77cdf0e10cSrcweir     std::vector< Rectangle >		maTabRectangles;
78cdf0e10cSrcweir     Point                           maItemsOffset;       // offset of the tabitems
79cdf0e10cSrcweir     std::vector< ImplTabItem >      maItemList;
80cdf0e10cSrcweir     ListBox*                        mpListBox;
81cdf0e10cSrcweir     Size                            maMinSize;
82cdf0e10cSrcweir };
83cdf0e10cSrcweir 
84cdf0e10cSrcweir // -----------------------------------------------------------------------
85cdf0e10cSrcweir 
86cdf0e10cSrcweir #define TAB_OFFSET          3
87cdf0e10cSrcweir #define TAB_TABOFFSET_X     3
88cdf0e10cSrcweir #define TAB_TABOFFSET_Y     3
89cdf0e10cSrcweir #define TAB_EXTRASPACE_X    6
90cdf0e10cSrcweir #define TAB_BORDER_LEFT     1
91cdf0e10cSrcweir #define TAB_BORDER_TOP      1
92cdf0e10cSrcweir #define TAB_BORDER_RIGHT    2
93cdf0e10cSrcweir #define TAB_BORDER_BOTTOM   2
94cdf0e10cSrcweir 
95cdf0e10cSrcweir // Fuer die Ermittlung von den Tab-Positionen
96cdf0e10cSrcweir #define TAB_PAGERECT        0xFFFF
97cdf0e10cSrcweir 
98cdf0e10cSrcweir // =======================================================================
99cdf0e10cSrcweir 
100cdf0e10cSrcweir void TabControl::ImplInit( Window* pParent, WinBits nStyle )
101cdf0e10cSrcweir {
102cdf0e10cSrcweir     if ( !(nStyle & WB_NOTABSTOP) )
103cdf0e10cSrcweir         nStyle |= WB_TABSTOP;
104cdf0e10cSrcweir     if ( !(nStyle & WB_NOGROUP) )
105cdf0e10cSrcweir         nStyle |= WB_GROUP;
106cdf0e10cSrcweir     if ( !(nStyle & WB_NODIALOGCONTROL) )
107cdf0e10cSrcweir         nStyle |= WB_DIALOGCONTROL;
108cdf0e10cSrcweir 
109cdf0e10cSrcweir     Control::ImplInit( pParent, nStyle, NULL );
110cdf0e10cSrcweir 
111cdf0e10cSrcweir     mnLastWidth         		= 0;
112cdf0e10cSrcweir     mnLastHeight        		= 0;
113cdf0e10cSrcweir     mnBtnSize           		= 0;
114cdf0e10cSrcweir     mnMaxPageWidth      		= 0;
115cdf0e10cSrcweir     mnActPageId         		= 0;
116cdf0e10cSrcweir     mnCurPageId         		= 0;
117cdf0e10cSrcweir     mbFormat            		= sal_True;
118cdf0e10cSrcweir     mbRestoreHelpId     		= sal_False;
119cdf0e10cSrcweir     mbRestoreUnqId      		= sal_False;
120cdf0e10cSrcweir     mbSmallInvalidate   		= sal_False;
121cdf0e10cSrcweir     mbExtraSpace        		= sal_False;
122cdf0e10cSrcweir     mpTabCtrlData               = new ImplTabCtrlData;
123cdf0e10cSrcweir     mpTabCtrlData->mpListBox    = NULL;
124cdf0e10cSrcweir 
125cdf0e10cSrcweir 
126cdf0e10cSrcweir     ImplInitSettings( sal_True, sal_True, sal_True );
127cdf0e10cSrcweir 
128cdf0e10cSrcweir     if( (nStyle & WB_DROPDOWN) )
129cdf0e10cSrcweir     {
130cdf0e10cSrcweir         mpTabCtrlData->mpListBox = new ListBox( this, WB_DROPDOWN );
131cdf0e10cSrcweir         mpTabCtrlData->mpListBox->SetPosSizePixel( Point( 0, 0 ), Size( 200, 20 ) );
132cdf0e10cSrcweir         mpTabCtrlData->mpListBox->SetSelectHdl( LINK( this, TabControl, ImplListBoxSelectHdl ) );
133cdf0e10cSrcweir         mpTabCtrlData->mpListBox->Show();
134cdf0e10cSrcweir     }
135cdf0e10cSrcweir 
136cdf0e10cSrcweir     // if the tabcontrol is drawn (ie filled) by a native widget, make sure all contols will have transparent background
137cdf0e10cSrcweir     // otherwise they will paint with a wrong background
138cdf0e10cSrcweir     if( IsNativeControlSupported(CTRL_TAB_PANE, PART_ENTIRE_CONTROL) )
139cdf0e10cSrcweir         EnableChildTransparentMode( sal_True );
140cdf0e10cSrcweir 
141cdf0e10cSrcweir     if ( pParent->IsDialog() )
142cdf0e10cSrcweir         pParent->AddChildEventListener( LINK( this, TabControl, ImplWindowEventListener ) );
143cdf0e10cSrcweir }
144cdf0e10cSrcweir 
145cdf0e10cSrcweir // -----------------------------------------------------------------
146cdf0e10cSrcweir 
147cdf0e10cSrcweir const Font& TabControl::GetCanonicalFont( const StyleSettings& _rStyle ) const
148cdf0e10cSrcweir {
149cdf0e10cSrcweir     return _rStyle.GetAppFont();
150cdf0e10cSrcweir }
151cdf0e10cSrcweir 
152cdf0e10cSrcweir // -----------------------------------------------------------------
153cdf0e10cSrcweir const Color& TabControl::GetCanonicalTextColor( const StyleSettings& _rStyle ) const
154cdf0e10cSrcweir {
155cdf0e10cSrcweir     return _rStyle.GetButtonTextColor();
156cdf0e10cSrcweir }
157cdf0e10cSrcweir 
158cdf0e10cSrcweir // -----------------------------------------------------------------------
159cdf0e10cSrcweir 
160cdf0e10cSrcweir void TabControl::ImplInitSettings( sal_Bool bFont,
161cdf0e10cSrcweir                                    sal_Bool bForeground, sal_Bool bBackground )
162cdf0e10cSrcweir {
163cdf0e10cSrcweir     Control::ImplInitSettings( bFont, bForeground );
164cdf0e10cSrcweir 
165cdf0e10cSrcweir     if ( bBackground )
166cdf0e10cSrcweir     {
167cdf0e10cSrcweir         Window* pParent = GetParent();
168cdf0e10cSrcweir         if ( !IsControlBackground() &&
169cdf0e10cSrcweir             (pParent->IsChildTransparentModeEnabled()
170cdf0e10cSrcweir             || IsNativeControlSupported(CTRL_TAB_PANE, PART_ENTIRE_CONTROL)
171cdf0e10cSrcweir             || IsNativeControlSupported(CTRL_TAB_ITEM, PART_ENTIRE_CONTROL) ) )
172cdf0e10cSrcweir 
173cdf0e10cSrcweir         {
174cdf0e10cSrcweir             // set transparent mode for NWF tabcontrols to have
175cdf0e10cSrcweir             // the background always cleared properly
176cdf0e10cSrcweir             EnableChildTransparentMode( sal_True );
177cdf0e10cSrcweir             SetParentClipMode( PARENTCLIPMODE_NOCLIP );
178cdf0e10cSrcweir             SetPaintTransparent( sal_True );
179cdf0e10cSrcweir             SetBackground();
180cdf0e10cSrcweir             ImplGetWindowImpl()->mbUseNativeFocus = ImplGetSVData()->maNWFData.mbNoFocusRects;
181cdf0e10cSrcweir         }
182cdf0e10cSrcweir         else
183cdf0e10cSrcweir         {
184cdf0e10cSrcweir             EnableChildTransparentMode( sal_False );
185cdf0e10cSrcweir             SetParentClipMode( 0 );
186cdf0e10cSrcweir             SetPaintTransparent( sal_False );
187cdf0e10cSrcweir 
188cdf0e10cSrcweir             if ( IsControlBackground() )
189cdf0e10cSrcweir                 SetBackground( GetControlBackground() );
190cdf0e10cSrcweir             else
191cdf0e10cSrcweir                 SetBackground( pParent->GetBackground() );
192cdf0e10cSrcweir         }
193cdf0e10cSrcweir     }
194cdf0e10cSrcweir }
195cdf0e10cSrcweir 
196cdf0e10cSrcweir // -----------------------------------------------------------------------
197cdf0e10cSrcweir 
198cdf0e10cSrcweir void TabControl::ImplFreeLayoutData()
199cdf0e10cSrcweir {
200cdf0e10cSrcweir     if( HasLayoutData() )
201cdf0e10cSrcweir     {
202cdf0e10cSrcweir         ImplClearLayoutData();
203cdf0e10cSrcweir         mpTabCtrlData->maLayoutPageIdToLine.clear();
204cdf0e10cSrcweir         mpTabCtrlData->maLayoutLineToPageId.clear();
205cdf0e10cSrcweir     }
206cdf0e10cSrcweir }
207cdf0e10cSrcweir 
208cdf0e10cSrcweir // -----------------------------------------------------------------------
209cdf0e10cSrcweir 
210cdf0e10cSrcweir TabControl::TabControl( Window* pParent, WinBits nStyle ) :
211cdf0e10cSrcweir     Control( WINDOW_TABCONTROL )
212cdf0e10cSrcweir {
213cdf0e10cSrcweir     ImplInit( pParent, nStyle );
214cdf0e10cSrcweir }
215cdf0e10cSrcweir 
216cdf0e10cSrcweir // -----------------------------------------------------------------------
217cdf0e10cSrcweir 
218cdf0e10cSrcweir TabControl::TabControl( Window* pParent, const ResId& rResId ) :
219cdf0e10cSrcweir     Control( WINDOW_TABCONTROL )
220cdf0e10cSrcweir {
221cdf0e10cSrcweir     rResId.SetRT( RSC_TABCONTROL );
222cdf0e10cSrcweir     WinBits nStyle = ImplInitRes( rResId );
223cdf0e10cSrcweir     ImplInit( pParent, nStyle );
224cdf0e10cSrcweir     ImplLoadRes( rResId );
225cdf0e10cSrcweir 
226cdf0e10cSrcweir     if ( !(nStyle & WB_HIDE) )
227cdf0e10cSrcweir         Show();
228cdf0e10cSrcweir }
229cdf0e10cSrcweir 
230cdf0e10cSrcweir // -----------------------------------------------------------------------
231cdf0e10cSrcweir 
232cdf0e10cSrcweir void TabControl::ImplLoadRes( const ResId& rResId )
233cdf0e10cSrcweir {
234cdf0e10cSrcweir     Control::ImplLoadRes( rResId );
235cdf0e10cSrcweir 
236cdf0e10cSrcweir     sal_uLong nObjMask = ReadLongRes();
237cdf0e10cSrcweir 
238cdf0e10cSrcweir     if ( nObjMask & RSC_TABCONTROL_ITEMLIST )
239cdf0e10cSrcweir     {
240cdf0e10cSrcweir         sal_uLong nEle = ReadLongRes();
241cdf0e10cSrcweir 
242cdf0e10cSrcweir         // Item hinzufuegen
243cdf0e10cSrcweir         for( sal_uLong i = 0; i < nEle; i++ )
244cdf0e10cSrcweir         {
245cdf0e10cSrcweir             InsertPage( ResId( (RSHEADER_TYPE *)GetClassRes(), *rResId.GetResMgr() ) );
246cdf0e10cSrcweir             IncrementRes( GetObjSizeRes( (RSHEADER_TYPE *)GetClassRes() ) );
247cdf0e10cSrcweir         }
248cdf0e10cSrcweir     }
249cdf0e10cSrcweir }
250cdf0e10cSrcweir 
251cdf0e10cSrcweir // -----------------------------------------------------------------------
252cdf0e10cSrcweir 
253cdf0e10cSrcweir TabControl::~TabControl()
254cdf0e10cSrcweir {
255cdf0e10cSrcweir     if ( GetParent()->IsDialog() )
256cdf0e10cSrcweir         GetParent()->RemoveChildEventListener( LINK( this, TabControl, ImplWindowEventListener ) );
257cdf0e10cSrcweir 
258cdf0e10cSrcweir     ImplFreeLayoutData();
259cdf0e10cSrcweir 
260cdf0e10cSrcweir     // TabCtrl-Daten loeschen
261cdf0e10cSrcweir     if ( mpTabCtrlData )
262cdf0e10cSrcweir     {
263cdf0e10cSrcweir         if( mpTabCtrlData->mpListBox )
264cdf0e10cSrcweir             delete mpTabCtrlData->mpListBox;
265cdf0e10cSrcweir         delete mpTabCtrlData;
266cdf0e10cSrcweir     }
267cdf0e10cSrcweir }
268cdf0e10cSrcweir 
269cdf0e10cSrcweir // -----------------------------------------------------------------------
270cdf0e10cSrcweir 
271cdf0e10cSrcweir ImplTabItem* TabControl::ImplGetItem( sal_uInt16 nId ) const
272cdf0e10cSrcweir {
273cdf0e10cSrcweir     for( std::vector< ImplTabItem >::iterator it = mpTabCtrlData->maItemList.begin();
274cdf0e10cSrcweir          it != mpTabCtrlData->maItemList.end(); ++it )
275cdf0e10cSrcweir     {
276cdf0e10cSrcweir         if( it->mnId == nId )
277cdf0e10cSrcweir             return &(*it);
278cdf0e10cSrcweir     }
279cdf0e10cSrcweir 
280cdf0e10cSrcweir     return NULL;
281cdf0e10cSrcweir }
282cdf0e10cSrcweir 
283cdf0e10cSrcweir // -----------------------------------------------------------------------
284cdf0e10cSrcweir 
285cdf0e10cSrcweir Size TabControl::ImplGetItemSize( ImplTabItem* pItem, long nMaxWidth )
286cdf0e10cSrcweir {
287cdf0e10cSrcweir     pItem->maFormatText = pItem->maText;
288cdf0e10cSrcweir     Size aSize( GetCtrlTextWidth( pItem->maFormatText ), GetTextHeight() );
289cdf0e10cSrcweir     Size aImageSize( 0, 0 );
290cdf0e10cSrcweir     if( !!pItem->maTabImage )
291cdf0e10cSrcweir     {
292cdf0e10cSrcweir         aImageSize = pItem->maTabImage.GetSizePixel();
293cdf0e10cSrcweir         if( pItem->maFormatText.Len() )
294cdf0e10cSrcweir             aImageSize.Width() += GetTextHeight()/4;
295cdf0e10cSrcweir     }
296cdf0e10cSrcweir     aSize.Width() += aImageSize.Width();
297cdf0e10cSrcweir     if( aImageSize.Height() > aSize.Height() )
298cdf0e10cSrcweir         aSize.Height() = aImageSize.Height();
299cdf0e10cSrcweir 
300cdf0e10cSrcweir     aSize.Width()  += TAB_TABOFFSET_X*2;
301cdf0e10cSrcweir     aSize.Height() += TAB_TABOFFSET_Y*2;
302cdf0e10cSrcweir 
303cdf0e10cSrcweir     Rectangle aCtrlRegion( Point( 0, 0 ), aSize );
304cdf0e10cSrcweir     Rectangle aBoundingRgn, aContentRgn;
305cdf0e10cSrcweir     const ImplControlValue aControlValue;
306cdf0e10cSrcweir     if(GetNativeControlRegion( CTRL_TAB_ITEM, PART_ENTIRE_CONTROL, aCtrlRegion,
307cdf0e10cSrcweir                                            CTRL_STATE_ENABLED, aControlValue, rtl::OUString(),
308cdf0e10cSrcweir                                            aBoundingRgn, aContentRgn ) )
309cdf0e10cSrcweir     {
310cdf0e10cSrcweir         return aContentRgn.GetSize();
311cdf0e10cSrcweir     }
312cdf0e10cSrcweir 
313cdf0e10cSrcweir     // For systems without synthetic bold support
314cdf0e10cSrcweir     if ( mbExtraSpace )
315cdf0e10cSrcweir         aSize.Width() += TAB_EXTRASPACE_X;
316cdf0e10cSrcweir     // For languages with short names (e.g. Chinese), because the space is
317cdf0e10cSrcweir     // normally only one pixel per char
318cdf0e10cSrcweir     else if ( pItem->maFormatText.Len() < TAB_EXTRASPACE_X )
319cdf0e10cSrcweir         aSize.Width() += TAB_EXTRASPACE_X-pItem->maFormatText.Len();
320cdf0e10cSrcweir 
321cdf0e10cSrcweir     // Evt. den Text kuerzen
322cdf0e10cSrcweir     if ( aSize.Width()+4 >= nMaxWidth )
323cdf0e10cSrcweir     {
324cdf0e10cSrcweir         XubString aAppendStr( RTL_CONSTASCII_USTRINGPARAM( "..." ) );
325cdf0e10cSrcweir         pItem->maFormatText += aAppendStr;
326cdf0e10cSrcweir         do
327cdf0e10cSrcweir         {
328cdf0e10cSrcweir             pItem->maFormatText.Erase( pItem->maFormatText.Len()-aAppendStr.Len()-1, 1 );
329cdf0e10cSrcweir             aSize.Width() = GetCtrlTextWidth( pItem->maFormatText );
330cdf0e10cSrcweir             aSize.Width() += aImageSize.Width();
331cdf0e10cSrcweir             aSize.Width() += TAB_TABOFFSET_X*2;
332cdf0e10cSrcweir         }
333cdf0e10cSrcweir         while ( (aSize.Width()+4 >= nMaxWidth) && (pItem->maFormatText.Len() > aAppendStr.Len()) );
334cdf0e10cSrcweir         if ( aSize.Width()+4 >= nMaxWidth )
335cdf0e10cSrcweir         {
336cdf0e10cSrcweir             pItem->maFormatText.Assign( '.' );
337cdf0e10cSrcweir             aSize.Width() = 1;
338cdf0e10cSrcweir         }
339cdf0e10cSrcweir     }
340cdf0e10cSrcweir 
341cdf0e10cSrcweir     if( pItem->maFormatText.Len() == 0 )
342cdf0e10cSrcweir     {
343cdf0e10cSrcweir         if( aSize.Height() < aImageSize.Height()+4 ) //leave space for focus rect
344cdf0e10cSrcweir             aSize.Height() = aImageSize.Height()+4;
345cdf0e10cSrcweir     }
346cdf0e10cSrcweir 
347cdf0e10cSrcweir     return aSize;
348cdf0e10cSrcweir }
349cdf0e10cSrcweir 
350cdf0e10cSrcweir // -----------------------------------------------------------------------
351cdf0e10cSrcweir 
352cdf0e10cSrcweir Rectangle TabControl::ImplGetTabRect( sal_uInt16 nItemPos, long nWidth, long nHeight )
353cdf0e10cSrcweir {
354cdf0e10cSrcweir     Size aWinSize = Control::GetOutputSizePixel();
355cdf0e10cSrcweir     if ( nWidth < 0 )
356cdf0e10cSrcweir         nWidth = aWinSize.Width();
357cdf0e10cSrcweir     if ( nHeight < 0 )
358cdf0e10cSrcweir         nHeight = aWinSize.Height();
359cdf0e10cSrcweir 
360cdf0e10cSrcweir     if ( mpTabCtrlData->maItemList.empty() )
361cdf0e10cSrcweir     {
362cdf0e10cSrcweir         long nW = nWidth-TAB_OFFSET*2;
363cdf0e10cSrcweir         long nH = nHeight-TAB_OFFSET*2;
364cdf0e10cSrcweir         return (nW > 0 && nH > 0)
365cdf0e10cSrcweir         ? Rectangle( Point( TAB_OFFSET, TAB_OFFSET ), Size( nW, nH ) )
366cdf0e10cSrcweir         : Rectangle();
367cdf0e10cSrcweir     }
368cdf0e10cSrcweir 
369cdf0e10cSrcweir     if ( nItemPos == TAB_PAGERECT )
370cdf0e10cSrcweir     {
371cdf0e10cSrcweir         sal_uInt16 nLastPos;
372cdf0e10cSrcweir         if ( mnCurPageId )
373cdf0e10cSrcweir             nLastPos = GetPagePos( mnCurPageId );
374cdf0e10cSrcweir         else
375cdf0e10cSrcweir             nLastPos = 0;
376cdf0e10cSrcweir 
377cdf0e10cSrcweir         Rectangle aRect = ImplGetTabRect( nLastPos, nWidth, nHeight );
378cdf0e10cSrcweir         long nW = nWidth-TAB_OFFSET*2;
379cdf0e10cSrcweir         long nH = nHeight-aRect.Bottom()-TAB_OFFSET*2;
380cdf0e10cSrcweir         aRect = (nW > 0 && nH > 0)
381cdf0e10cSrcweir         ? Rectangle( Point( TAB_OFFSET, aRect.Bottom()+TAB_OFFSET ), Size( nW, nH ) )
382cdf0e10cSrcweir         : Rectangle();
383cdf0e10cSrcweir         return aRect;
384cdf0e10cSrcweir     }
385cdf0e10cSrcweir 
386cdf0e10cSrcweir     nWidth -= 1;
387cdf0e10cSrcweir 
388cdf0e10cSrcweir     if ( (nWidth <= 0) || (nHeight <= 0) )
389cdf0e10cSrcweir         return Rectangle();
390cdf0e10cSrcweir 
391cdf0e10cSrcweir     if ( mbFormat || (mnLastWidth != nWidth) || (mnLastHeight != nHeight) )
392cdf0e10cSrcweir     {
393cdf0e10cSrcweir         Font aFont( GetFont() );
394cdf0e10cSrcweir         Font aLightFont = aFont;
395cdf0e10cSrcweir         aFont.SetTransparent( sal_True );
396cdf0e10cSrcweir         aFont.SetWeight( (!ImplGetSVData()->maNWFData.mbNoBoldTabFocus) ? WEIGHT_BOLD : WEIGHT_LIGHT );
397cdf0e10cSrcweir         aLightFont.SetTransparent( sal_True );
398cdf0e10cSrcweir         aLightFont.SetWeight( WEIGHT_LIGHT );
399cdf0e10cSrcweir 
400cdf0e10cSrcweir         // If Bold and none Bold strings have the same width, we
401cdf0e10cSrcweir         // add in the calcultion extra space, so that the tabs
402cdf0e10cSrcweir         // looks better. The could be the case on systems without
403cdf0e10cSrcweir         // an bold UI font and without synthetic bold support
404cdf0e10cSrcweir         XubString aTestStr( RTL_CONSTASCII_USTRINGPARAM( "Abc." ) );
405cdf0e10cSrcweir         SetFont( aLightFont );
406cdf0e10cSrcweir         long nTextWidth1 = GetTextWidth( aTestStr );
407cdf0e10cSrcweir         SetFont( aFont );
408cdf0e10cSrcweir         long nTextWidth2 = GetTextWidth( aTestStr );
409cdf0e10cSrcweir         mbExtraSpace = (nTextWidth1 == nTextWidth2);
410cdf0e10cSrcweir 
411cdf0e10cSrcweir         Size            aSize;
412cdf0e10cSrcweir         const long      nOffsetX = 2 + GetItemsOffset().X();
413cdf0e10cSrcweir         const long      nOffsetY = 2 + GetItemsOffset().Y();
414cdf0e10cSrcweir         long            nX = nOffsetX;
415cdf0e10cSrcweir         long            nY = nOffsetY;
416cdf0e10cSrcweir         long            nMaxWidth = nWidth;
417cdf0e10cSrcweir         sal_uInt16          nPos = 0;
418cdf0e10cSrcweir 
419cdf0e10cSrcweir         if ( (mnMaxPageWidth > 0) && (mnMaxPageWidth < nMaxWidth) )
420cdf0e10cSrcweir             nMaxWidth = mnMaxPageWidth;
421cdf0e10cSrcweir         nMaxWidth -= GetItemsOffset().X();
422cdf0e10cSrcweir 
423cdf0e10cSrcweir         sal_uInt16          nLines = 0;
424cdf0e10cSrcweir         sal_uInt16          nCurLine = 0;
425cdf0e10cSrcweir         long            nLineWidthAry[100];
426cdf0e10cSrcweir         sal_uInt16          nLinePosAry[101];
427cdf0e10cSrcweir 
428cdf0e10cSrcweir         nLineWidthAry[0] = 0;
429cdf0e10cSrcweir         nLinePosAry[0] = 0;
430cdf0e10cSrcweir         for( std::vector<ImplTabItem>::iterator it = mpTabCtrlData->maItemList.begin();
431cdf0e10cSrcweir              it != mpTabCtrlData->maItemList.end(); ++it )
432cdf0e10cSrcweir         {
433cdf0e10cSrcweir             aSize = ImplGetItemSize( &(*it), nMaxWidth );
434cdf0e10cSrcweir 
435cdf0e10cSrcweir             if ( ((nX+aSize.Width()) > nWidth - 2) && (nWidth > 2+nOffsetX) )
436cdf0e10cSrcweir             {
437cdf0e10cSrcweir                 if ( nLines == 99 )
438cdf0e10cSrcweir                     break;
439cdf0e10cSrcweir 
440cdf0e10cSrcweir                 nX  = nOffsetX;
441cdf0e10cSrcweir                 nY += aSize.Height();
442cdf0e10cSrcweir                 nLines++;
443cdf0e10cSrcweir                 nLineWidthAry[nLines] = 0;
444cdf0e10cSrcweir                 nLinePosAry[nLines] = nPos;
445cdf0e10cSrcweir             }
446cdf0e10cSrcweir 
447cdf0e10cSrcweir             Rectangle aNewRect( Point( nX, nY ), aSize );
448cdf0e10cSrcweir             if ( mbSmallInvalidate && (it->maRect != aNewRect) )
449cdf0e10cSrcweir                 mbSmallInvalidate = sal_False;
450cdf0e10cSrcweir             it->maRect = aNewRect;
451cdf0e10cSrcweir             it->mnLine = nLines;
452cdf0e10cSrcweir             it->mbFullVisible = sal_True;
453cdf0e10cSrcweir 
454cdf0e10cSrcweir             nLineWidthAry[nLines] += aSize.Width();
455cdf0e10cSrcweir             nX += aSize.Width();
456cdf0e10cSrcweir 
457cdf0e10cSrcweir             if ( it->mnId == mnCurPageId )
458cdf0e10cSrcweir                 nCurLine = nLines;
459cdf0e10cSrcweir 
460cdf0e10cSrcweir             nPos++;
461cdf0e10cSrcweir         }
462cdf0e10cSrcweir 
463cdf0e10cSrcweir         if ( nLines && !mpTabCtrlData->maItemList.empty() )
464cdf0e10cSrcweir         {
465cdf0e10cSrcweir             long    nDX = 0;
466cdf0e10cSrcweir             long    nModDX = 0;
467cdf0e10cSrcweir             long    nIDX = 0;
468cdf0e10cSrcweir             sal_uInt16  i;
469cdf0e10cSrcweir             sal_uInt16  n;
470cdf0e10cSrcweir             long    nLineHeightAry[100];
471cdf0e10cSrcweir             long    nIH = mpTabCtrlData->maItemList[0].maRect.Bottom()-2;
472cdf0e10cSrcweir 
473cdf0e10cSrcweir             i = 0;
474cdf0e10cSrcweir             while ( i < nLines+1 )
475cdf0e10cSrcweir             {
476cdf0e10cSrcweir                 if ( i <= nCurLine )
477cdf0e10cSrcweir                     nLineHeightAry[i] = nIH*(nLines-(nCurLine-i)) + GetItemsOffset().Y();
478cdf0e10cSrcweir                 else
479cdf0e10cSrcweir                     nLineHeightAry[i] = nIH*(i-nCurLine-1) + GetItemsOffset().Y();
480cdf0e10cSrcweir                 i++;
481cdf0e10cSrcweir             }
482cdf0e10cSrcweir 
483cdf0e10cSrcweir             i = 0;
484cdf0e10cSrcweir             n = 0;
485cdf0e10cSrcweir             nLinePosAry[nLines+1] = (sal_uInt16)mpTabCtrlData->maItemList.size();
486cdf0e10cSrcweir             for( std::vector< ImplTabItem >::iterator it = mpTabCtrlData->maItemList.begin();
487cdf0e10cSrcweir                  it != mpTabCtrlData->maItemList.end(); ++it )
488cdf0e10cSrcweir             {
489cdf0e10cSrcweir                 if ( i == nLinePosAry[n] )
490cdf0e10cSrcweir                 {
491cdf0e10cSrcweir                     if ( n == nLines+1 )
492cdf0e10cSrcweir                         break;
493cdf0e10cSrcweir 
494cdf0e10cSrcweir                     nIDX = 0;
495cdf0e10cSrcweir                     if( nLinePosAry[n+1]-i > 0 )
496cdf0e10cSrcweir                     {
497cdf0e10cSrcweir                         nDX = (nWidth-nOffsetX-nLineWidthAry[n]) / (nLinePosAry[n+1]-i);
498cdf0e10cSrcweir                         nModDX = (nWidth-nOffsetX-nLineWidthAry[n]) % (nLinePosAry[n+1]-i);
499cdf0e10cSrcweir                     }
500cdf0e10cSrcweir                     else
501cdf0e10cSrcweir                     {
502cdf0e10cSrcweir                         // FIXME: this is a bad case of tabctrl way too small
503cdf0e10cSrcweir                         nDX = 0;
504cdf0e10cSrcweir                         nModDX = 0;
505cdf0e10cSrcweir                     }
506cdf0e10cSrcweir                     n++;
507cdf0e10cSrcweir                 }
508cdf0e10cSrcweir 
509cdf0e10cSrcweir                 it->maRect.Left()   += nIDX;
510cdf0e10cSrcweir                 it->maRect.Right()  += nIDX+nDX;
511cdf0e10cSrcweir                 it->maRect.Top()     = nLineHeightAry[n-1];
512cdf0e10cSrcweir                 it->maRect.Bottom()  = nLineHeightAry[n-1]+nIH;
513cdf0e10cSrcweir                 nIDX += nDX;
514cdf0e10cSrcweir 
515cdf0e10cSrcweir                 if ( nModDX )
516cdf0e10cSrcweir                 {
517cdf0e10cSrcweir                     nIDX++;
518cdf0e10cSrcweir                     it->maRect.Right()++;
519cdf0e10cSrcweir                     nModDX--;
520cdf0e10cSrcweir                 }
521cdf0e10cSrcweir 
522cdf0e10cSrcweir                 i++;
523cdf0e10cSrcweir             }
524cdf0e10cSrcweir         }
525cdf0e10cSrcweir         else
526cdf0e10cSrcweir         {//only one line
527cdf0e10cSrcweir             if(ImplGetSVData()->maNWFData.mbCenteredTabs)
528cdf0e10cSrcweir             {
529cdf0e10cSrcweir                 int nRightSpace=nMaxWidth;//space left on the right by the tabs
530cdf0e10cSrcweir                 for( std::vector< ImplTabItem >::iterator it = mpTabCtrlData->maItemList.begin();
531cdf0e10cSrcweir                      it != mpTabCtrlData->maItemList.end(); ++it )
532cdf0e10cSrcweir                 {
533cdf0e10cSrcweir                     nRightSpace-=it->maRect.Right()-it->maRect.Left();
534cdf0e10cSrcweir                 }
535cdf0e10cSrcweir                 for( std::vector< ImplTabItem >::iterator it = mpTabCtrlData->maItemList.begin();
536cdf0e10cSrcweir                      it != mpTabCtrlData->maItemList.end(); ++it )
537cdf0e10cSrcweir                 {
538cdf0e10cSrcweir                     it->maRect.Left()+=(int) (nRightSpace/2);
539cdf0e10cSrcweir                     it->maRect.Right()+=(int) (nRightSpace/2);
540cdf0e10cSrcweir                 }
541cdf0e10cSrcweir             }
542cdf0e10cSrcweir         }
543cdf0e10cSrcweir 
544cdf0e10cSrcweir         mnLastWidth     = nWidth;
545cdf0e10cSrcweir         mnLastHeight    = nHeight;
546cdf0e10cSrcweir         mbFormat        = sal_False;
547cdf0e10cSrcweir     }
548cdf0e10cSrcweir 
549cdf0e10cSrcweir     return size_t(nItemPos) < mpTabCtrlData->maItemList.size() ? mpTabCtrlData->maItemList[nItemPos].maRect : Rectangle();
550cdf0e10cSrcweir }
551cdf0e10cSrcweir 
552cdf0e10cSrcweir // -----------------------------------------------------------------------
553cdf0e10cSrcweir 
554cdf0e10cSrcweir void TabControl::ImplChangeTabPage( sal_uInt16 nId, sal_uInt16 nOldId )
555cdf0e10cSrcweir {
556cdf0e10cSrcweir     ImplFreeLayoutData();
557cdf0e10cSrcweir 
558cdf0e10cSrcweir     ImplTabItem*    pOldItem = ImplGetItem( nOldId );
559cdf0e10cSrcweir     ImplTabItem*    pItem = ImplGetItem( nId );
560cdf0e10cSrcweir     TabPage*        pOldPage = (pOldItem) ? pOldItem->mpTabPage : NULL;
561cdf0e10cSrcweir     TabPage*        pPage = (pItem) ? pItem->mpTabPage : NULL;
562cdf0e10cSrcweir     Window*         pCtrlParent = GetParent();
563cdf0e10cSrcweir 
564cdf0e10cSrcweir     if ( IsReallyVisible() && IsUpdateMode() )
565cdf0e10cSrcweir     {
566cdf0e10cSrcweir         sal_uInt16 nPos = GetPagePos( nId );
567cdf0e10cSrcweir         Rectangle aRect = ImplGetTabRect( nPos );
568cdf0e10cSrcweir 
569cdf0e10cSrcweir         if ( !pOldItem || (pOldItem->mnLine != pItem->mnLine) )
570cdf0e10cSrcweir         {
571cdf0e10cSrcweir             aRect.Left() = 0;
572cdf0e10cSrcweir             aRect.Top() = 0;
573cdf0e10cSrcweir             aRect.Right() = Control::GetOutputSizePixel().Width();
574cdf0e10cSrcweir         }
575cdf0e10cSrcweir         else
576cdf0e10cSrcweir         {
577cdf0e10cSrcweir             aRect.Left()    -= 3;
578cdf0e10cSrcweir             aRect.Top()     -= 2;
579cdf0e10cSrcweir             aRect.Right()   += 3;
580cdf0e10cSrcweir             Invalidate( aRect );
581cdf0e10cSrcweir             nPos = GetPagePos( nOldId );
582cdf0e10cSrcweir             aRect = ImplGetTabRect( nPos );
583cdf0e10cSrcweir             aRect.Left()    -= 3;
584cdf0e10cSrcweir             aRect.Top()     -= 2;
585cdf0e10cSrcweir             aRect.Right()   += 3;
586cdf0e10cSrcweir         }
587cdf0e10cSrcweir         Invalidate( aRect );
588cdf0e10cSrcweir     }
589cdf0e10cSrcweir 
590cdf0e10cSrcweir     if ( pOldPage == pPage )
591cdf0e10cSrcweir         return;
592cdf0e10cSrcweir 
593cdf0e10cSrcweir     Rectangle aRect = ImplGetTabRect( TAB_PAGERECT );
594cdf0e10cSrcweir 
595cdf0e10cSrcweir     if ( pOldPage )
596cdf0e10cSrcweir     {
597cdf0e10cSrcweir         if ( mbRestoreHelpId )
598cdf0e10cSrcweir             pCtrlParent->SetHelpId( rtl::OString() );
599cdf0e10cSrcweir         if ( mbRestoreUnqId )
600cdf0e10cSrcweir             pCtrlParent->SetUniqueId( rtl::OString() );
601cdf0e10cSrcweir         pOldPage->DeactivatePage();
602cdf0e10cSrcweir     }
603cdf0e10cSrcweir 
604cdf0e10cSrcweir     if ( pPage )
605cdf0e10cSrcweir     {
606cdf0e10cSrcweir         pPage->SetPosSizePixel( aRect.TopLeft(), aRect.GetSize() );
607cdf0e10cSrcweir 
608cdf0e10cSrcweir         // activate page here so the conbtrols can be switched
609cdf0e10cSrcweir         // also set the help id of the parent window to that of the tab page
610cdf0e10cSrcweir         if ( !GetHelpId().getLength() )
611cdf0e10cSrcweir         {
612cdf0e10cSrcweir             mbRestoreHelpId = sal_True;
613cdf0e10cSrcweir             pCtrlParent->SetHelpId( pPage->GetHelpId() );
614cdf0e10cSrcweir         }
615cdf0e10cSrcweir         if ( !pCtrlParent->GetUniqueId().getLength() )
616cdf0e10cSrcweir         {
617cdf0e10cSrcweir             mbRestoreUnqId = sal_True;
618cdf0e10cSrcweir             pCtrlParent->SetUniqueId( pPage->GetUniqueId() );
619cdf0e10cSrcweir         }
620cdf0e10cSrcweir 
621cdf0e10cSrcweir         pPage->ActivatePage();
622*ad3a95a3SSteve Yin //IAccessibility2 Implementation 2009-----
623*ad3a95a3SSteve Yin 		pPage->Show();
624*ad3a95a3SSteve Yin //-----IAccessibility2 Implementation 2009
625cdf0e10cSrcweir 
626cdf0e10cSrcweir         if ( pOldPage && pOldPage->HasChildPathFocus() )
627cdf0e10cSrcweir         {
628cdf0e10cSrcweir             sal_uInt16  n = 0;
629cdf0e10cSrcweir             Window* pFirstChild = pPage->ImplGetDlgWindow( n, DLGWINDOW_FIRST );
630cdf0e10cSrcweir             if ( pFirstChild )
631cdf0e10cSrcweir                 pFirstChild->ImplControlFocus( GETFOCUS_INIT );
632cdf0e10cSrcweir             else
633cdf0e10cSrcweir                 GrabFocus();
634cdf0e10cSrcweir         }
635cdf0e10cSrcweir 
636*ad3a95a3SSteve Yin //IAccessibility2 Implementation 2009-----
637*ad3a95a3SSteve Yin         // pPage->Show();
638*ad3a95a3SSteve Yin //-----IAccessibility2 Implementation 2009
639cdf0e10cSrcweir     }
640cdf0e10cSrcweir 
641cdf0e10cSrcweir     if ( pOldPage )
642cdf0e10cSrcweir         pOldPage->Hide();
643cdf0e10cSrcweir 
644cdf0e10cSrcweir     // Invalidate the same region that will be send to NWF
645cdf0e10cSrcweir     // to always allow for bitmap caching
646cdf0e10cSrcweir     // see Window::DrawNativeControl()
647cdf0e10cSrcweir     if( IsNativeControlSupported( CTRL_TAB_PANE, PART_ENTIRE_CONTROL ) )
648cdf0e10cSrcweir     {
649cdf0e10cSrcweir         aRect.Left()   -= TAB_OFFSET;
650cdf0e10cSrcweir         aRect.Top()    -= TAB_OFFSET;
651cdf0e10cSrcweir         aRect.Right()  += TAB_OFFSET;
652cdf0e10cSrcweir         aRect.Bottom() += TAB_OFFSET;
653cdf0e10cSrcweir     }
654cdf0e10cSrcweir 
655cdf0e10cSrcweir     Invalidate( aRect );
656cdf0e10cSrcweir }
657cdf0e10cSrcweir 
658cdf0e10cSrcweir // -----------------------------------------------------------------------
659cdf0e10cSrcweir 
660cdf0e10cSrcweir sal_Bool TabControl::ImplPosCurTabPage()
661cdf0e10cSrcweir {
662cdf0e10cSrcweir     // Aktuelle TabPage resizen/positionieren
663cdf0e10cSrcweir     ImplTabItem* pItem = ImplGetItem( GetCurPageId() );
664cdf0e10cSrcweir     if ( pItem && pItem->mpTabPage )
665cdf0e10cSrcweir     {
666cdf0e10cSrcweir         Rectangle aRect = ImplGetTabRect( TAB_PAGERECT );
667cdf0e10cSrcweir         pItem->mpTabPage->SetPosSizePixel( aRect.TopLeft(), aRect.GetSize() );
668cdf0e10cSrcweir         return sal_True;
669cdf0e10cSrcweir     }
670cdf0e10cSrcweir 
671cdf0e10cSrcweir     return sal_False;
672cdf0e10cSrcweir }
673cdf0e10cSrcweir 
674cdf0e10cSrcweir // -----------------------------------------------------------------------
675cdf0e10cSrcweir 
676cdf0e10cSrcweir void TabControl::ImplActivateTabPage( sal_Bool bNext )
677cdf0e10cSrcweir {
678cdf0e10cSrcweir     sal_uInt16 nCurPos = GetPagePos( GetCurPageId() );
679cdf0e10cSrcweir 
680cdf0e10cSrcweir     if ( bNext )
681cdf0e10cSrcweir         nCurPos = (nCurPos + 1) % GetPageCount();
682cdf0e10cSrcweir     else
683cdf0e10cSrcweir     {
684cdf0e10cSrcweir         if ( !nCurPos )
685cdf0e10cSrcweir             nCurPos = GetPageCount()-1;
686cdf0e10cSrcweir         else
687cdf0e10cSrcweir             nCurPos--;
688cdf0e10cSrcweir     }
689cdf0e10cSrcweir 
690cdf0e10cSrcweir     SelectTabPage( GetPageId( nCurPos ) );
691cdf0e10cSrcweir }
692cdf0e10cSrcweir 
693cdf0e10cSrcweir // -----------------------------------------------------------------------
694cdf0e10cSrcweir 
695cdf0e10cSrcweir void TabControl::ImplShowFocus()
696cdf0e10cSrcweir {
697cdf0e10cSrcweir     if ( !GetPageCount() || mpTabCtrlData->mpListBox )
698cdf0e10cSrcweir         return;
699cdf0e10cSrcweir 
700cdf0e10cSrcweir     // make sure the focussed item rect is computed using a bold font
701cdf0e10cSrcweir     // the font may have changed meanwhile due to mouse over
702cdf0e10cSrcweir 
703cdf0e10cSrcweir     Font aOldFont( GetFont() );
704cdf0e10cSrcweir     Font aFont( aOldFont );
705cdf0e10cSrcweir     aFont.SetWeight( (!ImplGetSVData()->maNWFData.mbNoBoldTabFocus) ? WEIGHT_BOLD : WEIGHT_LIGHT );
706cdf0e10cSrcweir     SetFont( aFont );
707cdf0e10cSrcweir 
708cdf0e10cSrcweir     sal_uInt16                   nCurPos     = GetPagePos( mnCurPageId );
709cdf0e10cSrcweir     Rectangle                aRect       = ImplGetTabRect( nCurPos );
710cdf0e10cSrcweir     const ImplTabItem&       rItem       = mpTabCtrlData->maItemList[ nCurPos ];
711cdf0e10cSrcweir     Size                     aTabSize    = aRect.GetSize();
712cdf0e10cSrcweir     Size aImageSize( 0, 0 );
713cdf0e10cSrcweir     long                     nTextHeight = GetTextHeight();
714cdf0e10cSrcweir     long                     nTextWidth  = GetCtrlTextWidth( rItem.maFormatText );
715cdf0e10cSrcweir     sal_uInt16                   nOff;
716cdf0e10cSrcweir 
717cdf0e10cSrcweir     if ( !(GetSettings().GetStyleSettings().GetOptions() & STYLE_OPTION_MONO) )
718cdf0e10cSrcweir         nOff = 1;
719cdf0e10cSrcweir     else
720cdf0e10cSrcweir         nOff = 0;
721cdf0e10cSrcweir 
722cdf0e10cSrcweir     if( !! rItem.maTabImage )
723cdf0e10cSrcweir     {
724cdf0e10cSrcweir         aImageSize = rItem.maTabImage.GetSizePixel();
725cdf0e10cSrcweir         if( rItem.maFormatText.Len() )
726cdf0e10cSrcweir             aImageSize.Width() += GetTextHeight()/4;
727cdf0e10cSrcweir     }
728cdf0e10cSrcweir 
729cdf0e10cSrcweir     if( rItem.maFormatText.Len() )
730cdf0e10cSrcweir     {
731cdf0e10cSrcweir         // show focus around text
732cdf0e10cSrcweir         aRect.Left()   = aRect.Left()+aImageSize.Width()+((aTabSize.Width()-nTextWidth-aImageSize.Width())/2)-nOff-1-1;
733cdf0e10cSrcweir         aRect.Top()    = aRect.Top()+((aTabSize.Height()-nTextHeight)/2)-1-1;
734cdf0e10cSrcweir         aRect.Right()  = aRect.Left()+nTextWidth+2;
735cdf0e10cSrcweir         aRect.Bottom() = aRect.Top()+nTextHeight+2;
736cdf0e10cSrcweir     }
737cdf0e10cSrcweir     else
738cdf0e10cSrcweir     {
739cdf0e10cSrcweir         // show focus around image
740cdf0e10cSrcweir         long nXPos = aRect.Left()+((aTabSize.Width()-nTextWidth-aImageSize.Width())/2)-nOff-1;
741cdf0e10cSrcweir         long nYPos = aRect.Top();
742cdf0e10cSrcweir         if( aImageSize.Height() < aRect.GetHeight() )
743cdf0e10cSrcweir             nYPos += (aRect.GetHeight() - aImageSize.Height())/2;
744cdf0e10cSrcweir 
745cdf0e10cSrcweir         aRect.Left() = nXPos - 2;
746cdf0e10cSrcweir         aRect.Top() = nYPos - 2;
747cdf0e10cSrcweir         aRect.Right() = aRect.Left() + aImageSize.Width() + 4;
748cdf0e10cSrcweir         aRect.Bottom() = aRect.Top() + aImageSize.Height() + 4;
749cdf0e10cSrcweir     }
750cdf0e10cSrcweir     ShowFocus( aRect );
751cdf0e10cSrcweir 
752cdf0e10cSrcweir     SetFont( aOldFont );
753cdf0e10cSrcweir }
754cdf0e10cSrcweir 
755cdf0e10cSrcweir // -----------------------------------------------------------------------
756cdf0e10cSrcweir 
757cdf0e10cSrcweir void TabControl::ImplDrawItem( ImplTabItem* pItem, const Rectangle& rCurRect, bool bLayout, bool bFirstInGroup, bool bLastInGroup, bool bIsCurrentItem )
758cdf0e10cSrcweir {
759cdf0e10cSrcweir     if ( pItem->maRect.IsEmpty() )
760cdf0e10cSrcweir         return;
761cdf0e10cSrcweir 
762cdf0e10cSrcweir     if( bLayout )
763cdf0e10cSrcweir     {
764cdf0e10cSrcweir         if( !HasLayoutData() )
765cdf0e10cSrcweir         {
766cdf0e10cSrcweir             mpControlData->mpLayoutData = new vcl::ControlLayoutData();
767cdf0e10cSrcweir             mpTabCtrlData->maLayoutLineToPageId.clear();
768cdf0e10cSrcweir             mpTabCtrlData->maLayoutPageIdToLine.clear();
769cdf0e10cSrcweir             mpTabCtrlData->maTabRectangles.clear();
770cdf0e10cSrcweir         }
771cdf0e10cSrcweir     }
772cdf0e10cSrcweir 
773cdf0e10cSrcweir     const StyleSettings&    rStyleSettings  = GetSettings().GetStyleSettings();
774cdf0e10cSrcweir     Rectangle               aRect = pItem->maRect;
775cdf0e10cSrcweir     long                    nLeftBottom = aRect.Bottom();
776cdf0e10cSrcweir     long                    nRightBottom = aRect.Bottom();
777cdf0e10cSrcweir     sal_Bool                    bLeftBorder = sal_True;
778cdf0e10cSrcweir     sal_Bool                    bRightBorder = sal_True;
779cdf0e10cSrcweir     sal_uInt16                  nOff;
780cdf0e10cSrcweir     sal_Bool                    bNativeOK = sal_False;
781cdf0e10cSrcweir 
782cdf0e10cSrcweir     sal_uInt16 nOff2 = 0;
783cdf0e10cSrcweir     sal_uInt16 nOff3 = 0;
784cdf0e10cSrcweir 
785cdf0e10cSrcweir     if ( !(rStyleSettings.GetOptions() & STYLE_OPTION_MONO) )
786cdf0e10cSrcweir         nOff = 1;
787cdf0e10cSrcweir     else
788cdf0e10cSrcweir         nOff = 0;
789cdf0e10cSrcweir 
790cdf0e10cSrcweir     // Wenn wir die aktuelle Page sind, muessen wir etwas mehr zeichnen
791cdf0e10cSrcweir     if ( pItem->mnId == mnCurPageId )
792cdf0e10cSrcweir     {
793cdf0e10cSrcweir         nOff2 = 2;
794cdf0e10cSrcweir         if( ! ImplGetSVData()->maNWFData.mbNoActiveTabTextRaise )
795cdf0e10cSrcweir             nOff3 = 1;
796cdf0e10cSrcweir     }
797cdf0e10cSrcweir     else
798cdf0e10cSrcweir     {
799cdf0e10cSrcweir         Point aLeftTestPos = aRect.BottomLeft();
800cdf0e10cSrcweir         Point aRightTestPos = aRect.BottomRight();
801cdf0e10cSrcweir         if ( aLeftTestPos.Y() == rCurRect.Bottom() )
802cdf0e10cSrcweir         {
803cdf0e10cSrcweir             aLeftTestPos.X() -= 2;
804cdf0e10cSrcweir             if ( rCurRect.IsInside( aLeftTestPos ) )
805cdf0e10cSrcweir                 bLeftBorder = sal_False;
806cdf0e10cSrcweir             aRightTestPos.X() += 2;
807cdf0e10cSrcweir             if ( rCurRect.IsInside( aRightTestPos ) )
808cdf0e10cSrcweir                 bRightBorder = sal_False;
809cdf0e10cSrcweir         }
810cdf0e10cSrcweir         else
811cdf0e10cSrcweir         {
812cdf0e10cSrcweir             if ( rCurRect.IsInside( aLeftTestPos ) )
813cdf0e10cSrcweir                 nLeftBottom -= 2;
814cdf0e10cSrcweir             if ( rCurRect.IsInside( aRightTestPos ) )
815cdf0e10cSrcweir                 nRightBottom -= 2;
816cdf0e10cSrcweir         }
817cdf0e10cSrcweir     }
818cdf0e10cSrcweir 
819cdf0e10cSrcweir     if( !bLayout && (bNativeOK = IsNativeControlSupported(CTRL_TAB_ITEM, PART_ENTIRE_CONTROL)) == sal_True )
820cdf0e10cSrcweir     {
821cdf0e10cSrcweir         Rectangle           aCtrlRegion( pItem->maRect );
822cdf0e10cSrcweir         ControlState		nState = 0;
823cdf0e10cSrcweir 
824cdf0e10cSrcweir         if( pItem->mnId == mnCurPageId )
825cdf0e10cSrcweir         {
826cdf0e10cSrcweir             nState |= CTRL_STATE_SELECTED;
827cdf0e10cSrcweir             // only the selected item can be focussed
828cdf0e10cSrcweir             if ( HasFocus() )
829cdf0e10cSrcweir                 nState |= CTRL_STATE_FOCUSED;
830cdf0e10cSrcweir         }
831cdf0e10cSrcweir         if ( IsEnabled() )
832cdf0e10cSrcweir             nState |= CTRL_STATE_ENABLED;
833cdf0e10cSrcweir         if( IsMouseOver() && pItem->maRect.IsInside( GetPointerPosPixel() ) )
834cdf0e10cSrcweir         {
835cdf0e10cSrcweir             nState |= CTRL_STATE_ROLLOVER;
836cdf0e10cSrcweir             for( std::vector< ImplTabItem >::iterator it = mpTabCtrlData->maItemList.begin();
837cdf0e10cSrcweir                  it != mpTabCtrlData->maItemList.end(); ++it )
838cdf0e10cSrcweir             {
839cdf0e10cSrcweir                 if( (&(*it) != pItem) && (it->maRect.IsInside( GetPointerPosPixel() ) ) )
840cdf0e10cSrcweir                 {
841cdf0e10cSrcweir                     nState &= ~CTRL_STATE_ROLLOVER; // avoid multiple highlighted tabs
842cdf0e10cSrcweir                     break;
843cdf0e10cSrcweir                 }
844cdf0e10cSrcweir             }
845cdf0e10cSrcweir         }
846cdf0e10cSrcweir 
847cdf0e10cSrcweir         TabitemValue tiValue;
848cdf0e10cSrcweir         if(pItem->maRect.Left() < 5)
849cdf0e10cSrcweir             tiValue.mnAlignment |= TABITEM_LEFTALIGNED;
850cdf0e10cSrcweir         if(pItem->maRect.Right() > mnLastWidth - 5)
851cdf0e10cSrcweir             tiValue.mnAlignment |= TABITEM_RIGHTALIGNED;
852cdf0e10cSrcweir         if ( bFirstInGroup )
853cdf0e10cSrcweir             tiValue.mnAlignment |= TABITEM_FIRST_IN_GROUP;
854cdf0e10cSrcweir         if ( bLastInGroup )
855cdf0e10cSrcweir             tiValue.mnAlignment |= TABITEM_LAST_IN_GROUP;
856cdf0e10cSrcweir 
857cdf0e10cSrcweir         bNativeOK = DrawNativeControl( CTRL_TAB_ITEM, PART_ENTIRE_CONTROL, aCtrlRegion, nState,
858cdf0e10cSrcweir                     tiValue, rtl::OUString() );
859cdf0e10cSrcweir     }
860cdf0e10cSrcweir 
861cdf0e10cSrcweir     if( ! bLayout && !bNativeOK )
862cdf0e10cSrcweir     {
863cdf0e10cSrcweir         if ( !(rStyleSettings.GetOptions() & STYLE_OPTION_MONO) )
864cdf0e10cSrcweir         {
865cdf0e10cSrcweir             SetLineColor( rStyleSettings.GetLightColor() );
866cdf0e10cSrcweir             DrawPixel( Point( aRect.Left()+1-nOff2, aRect.Top()+1-nOff2 ) );    // diagonally indented top-left pixel
867cdf0e10cSrcweir             if ( bLeftBorder )
868cdf0e10cSrcweir             {
869cdf0e10cSrcweir                 DrawLine( Point( aRect.Left()-nOff2, aRect.Top()+2-nOff2 ),
870cdf0e10cSrcweir                           Point( aRect.Left()-nOff2, nLeftBottom-1 ) );
871cdf0e10cSrcweir             }
872cdf0e10cSrcweir             DrawLine( Point( aRect.Left()+2-nOff2, aRect.Top()-nOff2 ),         // top line starting 2px from left border
873cdf0e10cSrcweir                       Point( aRect.Right()+nOff2-3, aRect.Top()-nOff2 ) );      // ending 3px from right border
874cdf0e10cSrcweir 
875cdf0e10cSrcweir             if ( bRightBorder )
876cdf0e10cSrcweir             {
877cdf0e10cSrcweir                 SetLineColor( rStyleSettings.GetShadowColor() );
878cdf0e10cSrcweir                 DrawLine( Point( aRect.Right()+nOff2-2, aRect.Top()+1-nOff2 ),
879cdf0e10cSrcweir                           Point( aRect.Right()+nOff2-2, nRightBottom-1 ) );
880cdf0e10cSrcweir 
881cdf0e10cSrcweir                 SetLineColor( rStyleSettings.GetDarkShadowColor() );
882cdf0e10cSrcweir                 DrawLine( Point( aRect.Right()+nOff2-1, aRect.Top()+3-nOff2 ),
883cdf0e10cSrcweir                           Point( aRect.Right()+nOff2-1, nRightBottom-1 ) );
884cdf0e10cSrcweir             }
885cdf0e10cSrcweir         }
886cdf0e10cSrcweir         else
887cdf0e10cSrcweir         {
888cdf0e10cSrcweir             SetLineColor( Color( COL_BLACK ) );
889cdf0e10cSrcweir             DrawPixel( Point( aRect.Left()+1-nOff2, aRect.Top()+1-nOff2 ) );
890cdf0e10cSrcweir             DrawPixel( Point( aRect.Right()+nOff2-2, aRect.Top()+1-nOff2 ) );
891cdf0e10cSrcweir             if ( bLeftBorder )
892cdf0e10cSrcweir             {
893cdf0e10cSrcweir                 DrawLine( Point( aRect.Left()-nOff2, aRect.Top()+2-nOff2 ),
894cdf0e10cSrcweir                           Point( aRect.Left()-nOff2, nLeftBottom-1 ) );
895cdf0e10cSrcweir             }
896cdf0e10cSrcweir             DrawLine( Point( aRect.Left()+2-nOff2, aRect.Top()-nOff2 ),
897cdf0e10cSrcweir                       Point( aRect.Right()-3, aRect.Top()-nOff2 ) );
898cdf0e10cSrcweir             if ( bRightBorder )
899cdf0e10cSrcweir             {
900cdf0e10cSrcweir             DrawLine( Point( aRect.Right()+nOff2-1, aRect.Top()+2-nOff2 ),
901cdf0e10cSrcweir                       Point( aRect.Right()+nOff2-1, nRightBottom-1 ) );
902cdf0e10cSrcweir             }
903cdf0e10cSrcweir         }
904cdf0e10cSrcweir     }
905cdf0e10cSrcweir 
906cdf0e10cSrcweir     if( bLayout )
907cdf0e10cSrcweir     {
908cdf0e10cSrcweir         int nLine = mpControlData->mpLayoutData->m_aLineIndices.size();
909cdf0e10cSrcweir         mpControlData->mpLayoutData->m_aLineIndices.push_back( mpControlData->mpLayoutData->m_aDisplayText.Len() );
910cdf0e10cSrcweir         mpTabCtrlData->maLayoutPageIdToLine[ (int)pItem->mnId ] = nLine;
911cdf0e10cSrcweir         mpTabCtrlData->maLayoutLineToPageId[ nLine ] = (int)pItem->mnId;
912cdf0e10cSrcweir         mpTabCtrlData->maTabRectangles.push_back( aRect );
913cdf0e10cSrcweir     }
914cdf0e10cSrcweir 
915cdf0e10cSrcweir     // set font accordingly, current item is painted bold
916cdf0e10cSrcweir     // we set the font attributes always before drawing to be re-entrant (DrawNativeControl may trigger additional paints)
917cdf0e10cSrcweir     Font aFont( GetFont() );
918cdf0e10cSrcweir     aFont.SetTransparent( sal_True );
919cdf0e10cSrcweir     aFont.SetWeight( ((bIsCurrentItem) && (!ImplGetSVData()->maNWFData.mbNoBoldTabFocus)) ? WEIGHT_BOLD : WEIGHT_LIGHT );
920cdf0e10cSrcweir     SetFont( aFont );
921cdf0e10cSrcweir 
922cdf0e10cSrcweir     Size aTabSize = aRect.GetSize();
923cdf0e10cSrcweir     Size aImageSize( 0, 0 );
924cdf0e10cSrcweir     long nTextHeight = GetTextHeight();
925cdf0e10cSrcweir     long nTextWidth = GetCtrlTextWidth( pItem->maFormatText );
926cdf0e10cSrcweir     if( !! pItem->maTabImage )
927cdf0e10cSrcweir     {
928cdf0e10cSrcweir         aImageSize = pItem->maTabImage.GetSizePixel();
929cdf0e10cSrcweir         if( pItem->maFormatText.Len() )
930cdf0e10cSrcweir             aImageSize.Width() += GetTextHeight()/4;
931cdf0e10cSrcweir     }
932cdf0e10cSrcweir     long nXPos = aRect.Left()+((aTabSize.Width()-nTextWidth-aImageSize.Width())/2)-nOff-nOff3;
933cdf0e10cSrcweir     long nYPos = aRect.Top()+((aTabSize.Height()-nTextHeight)/2)-nOff3;
934cdf0e10cSrcweir     if( pItem->maFormatText.Len() )
935cdf0e10cSrcweir     {
936cdf0e10cSrcweir         sal_uInt16 nStyle = TEXT_DRAW_MNEMONIC;
937cdf0e10cSrcweir         if( ! pItem->mbEnabled )
938cdf0e10cSrcweir             nStyle |= TEXT_DRAW_DISABLE;
939cdf0e10cSrcweir         DrawCtrlText( Point( nXPos + aImageSize.Width(), nYPos ),
940cdf0e10cSrcweir                       pItem->maFormatText,
941cdf0e10cSrcweir                       0, STRING_LEN, nStyle,
942cdf0e10cSrcweir                       bLayout ? &mpControlData->mpLayoutData->m_aUnicodeBoundRects : NULL,
943cdf0e10cSrcweir                       bLayout ? &mpControlData->mpLayoutData->m_aDisplayText : NULL
944cdf0e10cSrcweir                       );
945cdf0e10cSrcweir     }
946cdf0e10cSrcweir 
947cdf0e10cSrcweir     if( !! pItem->maTabImage )
948cdf0e10cSrcweir     {
949cdf0e10cSrcweir         Point aImgTL( nXPos, aRect.Top() );
950cdf0e10cSrcweir         if( aImageSize.Height() < aRect.GetHeight() )
951cdf0e10cSrcweir             aImgTL.Y() += (aRect.GetHeight() - aImageSize.Height())/2;
952cdf0e10cSrcweir         DrawImage( aImgTL, pItem->maTabImage, pItem->mbEnabled ? 0 : IMAGE_DRAW_DISABLE );
953cdf0e10cSrcweir     }
954cdf0e10cSrcweir }
955cdf0e10cSrcweir 
956cdf0e10cSrcweir // -----------------------------------------------------------------------
957cdf0e10cSrcweir 
958cdf0e10cSrcweir long TabControl::ImplHandleKeyEvent( const KeyEvent& rKeyEvent )
959cdf0e10cSrcweir {
960cdf0e10cSrcweir     long nRet = 0;
961cdf0e10cSrcweir 
962cdf0e10cSrcweir     if ( GetPageCount() > 1 )
963cdf0e10cSrcweir     {
964cdf0e10cSrcweir         KeyCode         aKeyCode = rKeyEvent.GetKeyCode();
965cdf0e10cSrcweir         sal_uInt16          nKeyCode = aKeyCode.GetCode();
966cdf0e10cSrcweir 
967cdf0e10cSrcweir         if ( aKeyCode.IsMod1() )
968cdf0e10cSrcweir         {
969cdf0e10cSrcweir             if ( aKeyCode.IsShift() || (nKeyCode == KEY_PAGEUP) )
970cdf0e10cSrcweir             {
971cdf0e10cSrcweir                 if ( (nKeyCode == KEY_TAB) || (nKeyCode == KEY_PAGEUP) )
972cdf0e10cSrcweir                 {
973cdf0e10cSrcweir                     ImplActivateTabPage( sal_False );
974cdf0e10cSrcweir                     nRet = 1;
975cdf0e10cSrcweir                 }
976cdf0e10cSrcweir             }
977cdf0e10cSrcweir             else
978cdf0e10cSrcweir             {
979cdf0e10cSrcweir                 if ( (nKeyCode == KEY_TAB) || (nKeyCode == KEY_PAGEDOWN) )
980cdf0e10cSrcweir                 {
981cdf0e10cSrcweir                     ImplActivateTabPage( sal_True );
982cdf0e10cSrcweir                     nRet = 1;
983cdf0e10cSrcweir                 }
984cdf0e10cSrcweir             }
985cdf0e10cSrcweir         }
986cdf0e10cSrcweir     }
987cdf0e10cSrcweir 
988cdf0e10cSrcweir     return nRet;
989cdf0e10cSrcweir }
990cdf0e10cSrcweir 
991cdf0e10cSrcweir 
992cdf0e10cSrcweir // -----------------------------------------------------------------------
993cdf0e10cSrcweir 
994cdf0e10cSrcweir IMPL_LINK( TabControl, ImplListBoxSelectHdl, ListBox*, EMPTYARG )
995cdf0e10cSrcweir {
996cdf0e10cSrcweir     SelectTabPage( GetPageId( mpTabCtrlData->mpListBox->GetSelectEntryPos() ) );
997cdf0e10cSrcweir     return 0;
998cdf0e10cSrcweir }
999cdf0e10cSrcweir 
1000cdf0e10cSrcweir // -----------------------------------------------------------------------
1001cdf0e10cSrcweir 
1002cdf0e10cSrcweir IMPL_LINK( TabControl, ImplWindowEventListener, VclSimpleEvent*, pEvent )
1003cdf0e10cSrcweir {
1004cdf0e10cSrcweir 	if ( pEvent && pEvent->ISA( VclWindowEvent ) && (pEvent->GetId() == VCLEVENT_WINDOW_KEYINPUT) )
1005cdf0e10cSrcweir 	{
1006cdf0e10cSrcweir 	    VclWindowEvent* pWindowEvent = static_cast< VclWindowEvent* >(pEvent);
1007cdf0e10cSrcweir 	    // Do not handle events from TabControl or it's children, which is done in Notify(), where the events can be consumed.
1008cdf0e10cSrcweir 	    if ( !IsWindowOrChild( pWindowEvent->GetWindow() ) )
1009cdf0e10cSrcweir 	    {
1010cdf0e10cSrcweir             KeyEvent* pKeyEvent = static_cast< KeyEvent* >(pWindowEvent->GetData());
1011cdf0e10cSrcweir 	        ImplHandleKeyEvent( *pKeyEvent );
1012cdf0e10cSrcweir 	    }
1013cdf0e10cSrcweir 	}
1014cdf0e10cSrcweir 	return 0;
1015cdf0e10cSrcweir }
1016cdf0e10cSrcweir 
1017cdf0e10cSrcweir 
1018cdf0e10cSrcweir // -----------------------------------------------------------------------
1019cdf0e10cSrcweir 
1020cdf0e10cSrcweir void TabControl::MouseButtonDown( const MouseEvent& rMEvt )
1021cdf0e10cSrcweir {
1022cdf0e10cSrcweir     if( mpTabCtrlData->mpListBox == NULL )
1023cdf0e10cSrcweir     {
1024cdf0e10cSrcweir         if( rMEvt.IsLeft() )
1025cdf0e10cSrcweir         {
1026cdf0e10cSrcweir             sal_uInt16 nPageId = GetPageId( rMEvt.GetPosPixel() );
1027cdf0e10cSrcweir             ImplTabItem* pItem = ImplGetItem( nPageId );
1028cdf0e10cSrcweir             if( pItem && pItem->mbEnabled )
1029cdf0e10cSrcweir                 SelectTabPage( nPageId );
1030cdf0e10cSrcweir         }
1031cdf0e10cSrcweir     }
1032cdf0e10cSrcweir }
1033cdf0e10cSrcweir 
1034cdf0e10cSrcweir // -----------------------------------------------------------------------
1035cdf0e10cSrcweir 
1036cdf0e10cSrcweir void TabControl::KeyInput( const KeyEvent& rKEvt )
1037cdf0e10cSrcweir {
1038cdf0e10cSrcweir     if( mpTabCtrlData->mpListBox )
1039cdf0e10cSrcweir         mpTabCtrlData->mpListBox->KeyInput( rKEvt );
1040cdf0e10cSrcweir     else if ( GetPageCount() > 1 )
1041cdf0e10cSrcweir     {
1042cdf0e10cSrcweir         KeyCode aKeyCode = rKEvt.GetKeyCode();
1043cdf0e10cSrcweir         sal_uInt16  nKeyCode = aKeyCode.GetCode();
1044cdf0e10cSrcweir 
1045cdf0e10cSrcweir         if ( (nKeyCode == KEY_LEFT) || (nKeyCode == KEY_RIGHT) )
1046cdf0e10cSrcweir         {
1047cdf0e10cSrcweir             sal_Bool bNext = (nKeyCode == KEY_RIGHT);
1048cdf0e10cSrcweir             ImplActivateTabPage( bNext );
1049cdf0e10cSrcweir         }
1050cdf0e10cSrcweir     }
1051cdf0e10cSrcweir 
1052cdf0e10cSrcweir     Control::KeyInput( rKEvt );
1053cdf0e10cSrcweir }
1054cdf0e10cSrcweir 
1055cdf0e10cSrcweir // -----------------------------------------------------------------------
1056cdf0e10cSrcweir 
1057cdf0e10cSrcweir void TabControl::Paint( const Rectangle& rRect )
1058cdf0e10cSrcweir {
1059cdf0e10cSrcweir     ImplPaint( rRect, false );
1060cdf0e10cSrcweir }
1061cdf0e10cSrcweir 
1062cdf0e10cSrcweir // -----------------------------------------------------------------------
1063cdf0e10cSrcweir 
1064cdf0e10cSrcweir void TabControl::ImplPaint( const Rectangle& rRect, bool bLayout )
1065cdf0e10cSrcweir {
1066cdf0e10cSrcweir     if( ! bLayout )
1067cdf0e10cSrcweir         HideFocus();
1068cdf0e10cSrcweir 
1069cdf0e10cSrcweir     // Hier wird gegebenenfalls auch neu formatiert
1070cdf0e10cSrcweir     Rectangle aRect = ImplGetTabRect( TAB_PAGERECT );
1071cdf0e10cSrcweir 
1072cdf0e10cSrcweir     // find current item
1073cdf0e10cSrcweir     ImplTabItem* pCurItem = NULL;
1074cdf0e10cSrcweir     for( std::vector< ImplTabItem >::iterator it = mpTabCtrlData->maItemList.begin();
1075cdf0e10cSrcweir          it != mpTabCtrlData->maItemList.end(); ++it )
1076cdf0e10cSrcweir     {
1077cdf0e10cSrcweir         if ( it->mnId == mnCurPageId )
1078cdf0e10cSrcweir         {
1079cdf0e10cSrcweir             pCurItem = &(*it);
1080cdf0e10cSrcweir             break;
1081cdf0e10cSrcweir         }
1082cdf0e10cSrcweir     }
1083cdf0e10cSrcweir 
1084cdf0e10cSrcweir     // Draw the TabPage border
1085cdf0e10cSrcweir     const StyleSettings&    rStyleSettings  = GetSettings().GetStyleSettings();
1086cdf0e10cSrcweir     Rectangle               aCurRect;
1087cdf0e10cSrcweir     long                    nTopOff = 1;
1088cdf0e10cSrcweir     aRect.Left()   -= TAB_OFFSET;
1089cdf0e10cSrcweir     aRect.Top()    -= TAB_OFFSET;
1090cdf0e10cSrcweir     aRect.Right()  += TAB_OFFSET;
1091cdf0e10cSrcweir     aRect.Bottom() += TAB_OFFSET;
1092cdf0e10cSrcweir 
1093cdf0e10cSrcweir     // if we have an invisible tabpage or no tabpage at all the tabpage rect should be
1094cdf0e10cSrcweir     // increased to avoid round corners that might be drawn by a theme
1095cdf0e10cSrcweir     // in this case we're only interested in the top border of the tabpage because the tabitems are used
1096cdf0e10cSrcweir     // standalone (eg impress)
1097cdf0e10cSrcweir     sal_Bool bNoTabPage = sal_False;
1098cdf0e10cSrcweir     TabPage*        pCurPage = (pCurItem) ? pCurItem->mpTabPage : NULL;
1099cdf0e10cSrcweir     if( !pCurPage || !pCurPage->IsVisible() )
1100cdf0e10cSrcweir     {
1101cdf0e10cSrcweir         bNoTabPage = sal_True;
1102cdf0e10cSrcweir         aRect.Left()-=10;
1103cdf0e10cSrcweir         aRect.Right()+=10;
1104cdf0e10cSrcweir     }
1105cdf0e10cSrcweir 
1106cdf0e10cSrcweir     sal_Bool bNativeOK = sal_False;
1107cdf0e10cSrcweir     if( ! bLayout && (bNativeOK = IsNativeControlSupported( CTRL_TAB_PANE, PART_ENTIRE_CONTROL) ) == sal_True )
1108cdf0e10cSrcweir     {
1109cdf0e10cSrcweir         const ImplControlValue aControlValue;
1110cdf0e10cSrcweir 
1111cdf0e10cSrcweir         ControlState nState = CTRL_STATE_ENABLED;
1112cdf0e10cSrcweir         int part = PART_ENTIRE_CONTROL;
1113cdf0e10cSrcweir         if ( !IsEnabled() )
1114cdf0e10cSrcweir             nState &= ~CTRL_STATE_ENABLED;
1115cdf0e10cSrcweir         if ( HasFocus() )
1116cdf0e10cSrcweir             nState |= CTRL_STATE_FOCUSED;
1117cdf0e10cSrcweir 
1118cdf0e10cSrcweir         Region aClipRgn( GetActiveClipRegion() );
1119cdf0e10cSrcweir         aClipRgn.Intersect( aRect );
1120cdf0e10cSrcweir         if( !rRect.IsEmpty() )
1121cdf0e10cSrcweir             aClipRgn.Intersect( rRect );
1122cdf0e10cSrcweir 
1123cdf0e10cSrcweir         if( !aClipRgn.IsEmpty() )
1124cdf0e10cSrcweir             bNativeOK = DrawNativeControl( CTRL_TAB_PANE, part, aRect, nState,
1125cdf0e10cSrcweir                 aControlValue, rtl::OUString() );
1126cdf0e10cSrcweir     }
1127cdf0e10cSrcweir     else
1128cdf0e10cSrcweir     {
1129cdf0e10cSrcweir         if ( !(rStyleSettings.GetOptions() & STYLE_OPTION_MONO) )
1130cdf0e10cSrcweir             SetLineColor( rStyleSettings.GetLightColor() );
1131cdf0e10cSrcweir         else
1132cdf0e10cSrcweir             SetLineColor( Color( COL_BLACK ) );
1133cdf0e10cSrcweir         if ( pCurItem && !pCurItem->maRect.IsEmpty() )
1134cdf0e10cSrcweir         {
1135cdf0e10cSrcweir             aCurRect = pCurItem->maRect;
1136cdf0e10cSrcweir             if( ! bLayout )
1137cdf0e10cSrcweir                 DrawLine( aRect.TopLeft(), Point( aCurRect.Left()-2, aRect.Top() ) );
1138cdf0e10cSrcweir             if ( aCurRect.Right()+1 < aRect.Right() )
1139cdf0e10cSrcweir             {
1140cdf0e10cSrcweir                 if( ! bLayout )
1141cdf0e10cSrcweir                     DrawLine( Point( aCurRect.Right(), aRect.Top() ), aRect.TopRight() );
1142cdf0e10cSrcweir             }
1143cdf0e10cSrcweir             else
1144cdf0e10cSrcweir                 nTopOff = 0;
1145cdf0e10cSrcweir         }
1146cdf0e10cSrcweir         else
1147cdf0e10cSrcweir             if( ! bLayout )
1148cdf0e10cSrcweir                 DrawLine( aRect.TopLeft(), aRect.TopRight() );
1149cdf0e10cSrcweir 
1150cdf0e10cSrcweir         if( ! bLayout )
1151cdf0e10cSrcweir         {
1152cdf0e10cSrcweir             DrawLine( aRect.TopLeft(), aRect.BottomLeft() );
1153cdf0e10cSrcweir 
1154cdf0e10cSrcweir             if ( !(rStyleSettings.GetOptions() & STYLE_OPTION_MONO) )
1155cdf0e10cSrcweir             {
1156cdf0e10cSrcweir                 // if we have not tab page the bottom line of the tab page
1157cdf0e10cSrcweir                 // directly touches the tab items, so choose a color that fits seamlessly
1158cdf0e10cSrcweir                 if( bNoTabPage )
1159cdf0e10cSrcweir                     SetLineColor( rStyleSettings.GetDialogColor() );
1160cdf0e10cSrcweir                 else
1161cdf0e10cSrcweir                     SetLineColor( rStyleSettings.GetShadowColor() );
1162cdf0e10cSrcweir                 DrawLine( Point( 1, aRect.Bottom()-1 ),
1163cdf0e10cSrcweir                         Point( aRect.Right()-1, aRect.Bottom()-1 ) );
1164cdf0e10cSrcweir                 DrawLine( Point( aRect.Right()-1, aRect.Top()+nTopOff ),
1165cdf0e10cSrcweir                         Point( aRect.Right()-1, aRect.Bottom()-1 ) );
1166cdf0e10cSrcweir                 if( bNoTabPage )
1167cdf0e10cSrcweir                     SetLineColor( rStyleSettings.GetDialogColor() );
1168cdf0e10cSrcweir                 else
1169cdf0e10cSrcweir                     SetLineColor( rStyleSettings.GetDarkShadowColor() );
1170cdf0e10cSrcweir                 DrawLine( Point( 0, aRect.Bottom() ),
1171cdf0e10cSrcweir                         Point( aRect.Right(), aRect.Bottom() ) );
1172cdf0e10cSrcweir                 DrawLine( Point( aRect.Right(), aRect.Top()+nTopOff ),
1173cdf0e10cSrcweir                         Point( aRect.Right(), aRect.Bottom() ) );
1174cdf0e10cSrcweir             }
1175cdf0e10cSrcweir             else
1176cdf0e10cSrcweir             {
1177cdf0e10cSrcweir                 DrawLine( aRect.TopRight(), aRect.BottomRight() );
1178cdf0e10cSrcweir                 DrawLine( aRect.BottomLeft(), aRect.BottomRight() );
1179cdf0e10cSrcweir             }
1180cdf0e10cSrcweir         }
1181cdf0e10cSrcweir     }
1182cdf0e10cSrcweir 
1183cdf0e10cSrcweir     if ( !mpTabCtrlData->maItemList.empty() && mpTabCtrlData->mpListBox == NULL )
1184cdf0e10cSrcweir     {
1185cdf0e10cSrcweir         // Some native toolkits (GTK+) draw tabs right-to-left, with an
1186cdf0e10cSrcweir         // overlap between adjacent tabs
1187cdf0e10cSrcweir         bool			bDrawTabsRTL = IsNativeControlSupported( CTRL_TAB_ITEM, PART_TABS_DRAW_RTL );
1188cdf0e10cSrcweir         ImplTabItem *	pFirstTab = NULL;
1189cdf0e10cSrcweir         ImplTabItem *	pLastTab = NULL;
1190cdf0e10cSrcweir         size_t idx;
1191cdf0e10cSrcweir 
1192cdf0e10cSrcweir         // Event though there is a tab overlap with GTK+, the first tab is not
1193cdf0e10cSrcweir         // overlapped on the left side.  Other tookits ignore this option.
1194cdf0e10cSrcweir         if ( bDrawTabsRTL )
1195cdf0e10cSrcweir         {
1196cdf0e10cSrcweir             pFirstTab = &mpTabCtrlData->maItemList.front();
1197cdf0e10cSrcweir             pLastTab = &mpTabCtrlData->maItemList.back();
1198cdf0e10cSrcweir             idx = mpTabCtrlData->maItemList.size()-1;
1199cdf0e10cSrcweir         }
1200cdf0e10cSrcweir         else
1201cdf0e10cSrcweir         {
1202cdf0e10cSrcweir             pLastTab = &mpTabCtrlData->maItemList.back();
1203cdf0e10cSrcweir             pFirstTab = &mpTabCtrlData->maItemList.front();
1204cdf0e10cSrcweir             idx = 0;
1205cdf0e10cSrcweir         }
1206cdf0e10cSrcweir 
1207cdf0e10cSrcweir         while ( idx < mpTabCtrlData->maItemList.size() )
1208cdf0e10cSrcweir         {
1209cdf0e10cSrcweir             ImplTabItem* pItem = &mpTabCtrlData->maItemList[idx];
1210cdf0e10cSrcweir             if ( pItem != pCurItem )
1211cdf0e10cSrcweir             {
1212cdf0e10cSrcweir                 Region aClipRgn( GetActiveClipRegion() );
1213cdf0e10cSrcweir                 aClipRgn.Intersect( pItem->maRect );
1214cdf0e10cSrcweir                 if( !rRect.IsEmpty() )
1215cdf0e10cSrcweir                     aClipRgn.Intersect( rRect );
1216cdf0e10cSrcweir                 if( bLayout || !aClipRgn.IsEmpty() )
1217cdf0e10cSrcweir                     ImplDrawItem( pItem, aCurRect, bLayout, (pItem==pFirstTab), (pItem==pLastTab), sal_False );
1218cdf0e10cSrcweir             }
1219cdf0e10cSrcweir 
1220cdf0e10cSrcweir             if ( bDrawTabsRTL )
1221cdf0e10cSrcweir                 idx--;
1222cdf0e10cSrcweir             else
1223cdf0e10cSrcweir                 idx++;
1224cdf0e10cSrcweir         }
1225cdf0e10cSrcweir 
1226cdf0e10cSrcweir         if ( pCurItem )
1227cdf0e10cSrcweir         {
1228cdf0e10cSrcweir             Region aClipRgn( GetActiveClipRegion() );
1229cdf0e10cSrcweir             aClipRgn.Intersect( pCurItem->maRect );
1230cdf0e10cSrcweir             if( !rRect.IsEmpty() )
1231cdf0e10cSrcweir                 aClipRgn.Intersect( rRect );
1232cdf0e10cSrcweir             if( bLayout || !aClipRgn.IsEmpty() )
1233cdf0e10cSrcweir                 ImplDrawItem( pCurItem, aCurRect, bLayout, (pCurItem==pFirstTab), (pCurItem==pLastTab), sal_True );
1234cdf0e10cSrcweir         }
1235cdf0e10cSrcweir     }
1236cdf0e10cSrcweir 
1237cdf0e10cSrcweir     if ( !bLayout && HasFocus() )
1238cdf0e10cSrcweir         ImplShowFocus();
1239cdf0e10cSrcweir 
1240cdf0e10cSrcweir     if( ! bLayout )
1241cdf0e10cSrcweir         mbSmallInvalidate = sal_True;
1242cdf0e10cSrcweir }
1243cdf0e10cSrcweir 
1244cdf0e10cSrcweir // -----------------------------------------------------------------------
1245cdf0e10cSrcweir 
1246cdf0e10cSrcweir void TabControl::Resize()
1247cdf0e10cSrcweir {
1248cdf0e10cSrcweir     ImplFreeLayoutData();
1249cdf0e10cSrcweir 
1250cdf0e10cSrcweir     if ( !IsReallyShown() )
1251cdf0e10cSrcweir         return;
1252cdf0e10cSrcweir 
1253cdf0e10cSrcweir     if( mpTabCtrlData->mpListBox )
1254cdf0e10cSrcweir     {
1255cdf0e10cSrcweir         // get the listbox' preferred size
1256cdf0e10cSrcweir         Size aTabCtrlSize( GetSizePixel() );
1257cdf0e10cSrcweir         long nPrefWidth = mpTabCtrlData->mpListBox->GetOptimalSize( WINDOWSIZE_PREFERRED ).Width();
1258cdf0e10cSrcweir         if( nPrefWidth > aTabCtrlSize.Width() )
1259cdf0e10cSrcweir             nPrefWidth = aTabCtrlSize.Width();
1260cdf0e10cSrcweir         Size aNewSize( nPrefWidth, LogicToPixel( Size( 12, 12 ), MapMode( MAP_APPFONT ) ).Height() );
1261cdf0e10cSrcweir         Point aNewPos( (aTabCtrlSize.Width() - nPrefWidth) / 2, 0 );
1262cdf0e10cSrcweir         mpTabCtrlData->mpListBox->SetPosSizePixel( aNewPos, aNewSize );
1263cdf0e10cSrcweir     }
1264cdf0e10cSrcweir 
1265cdf0e10cSrcweir     mbFormat = sal_True;
1266cdf0e10cSrcweir 
1267cdf0e10cSrcweir     // Aktuelle TabPage resizen/positionieren
1268cdf0e10cSrcweir     sal_Bool bTabPage = ImplPosCurTabPage();
1269cdf0e10cSrcweir     // Feststellen, was invalidiert werden muss
1270cdf0e10cSrcweir     Size aNewSize = Control::GetOutputSizePixel();
1271cdf0e10cSrcweir     long nNewWidth = aNewSize.Width();
1272cdf0e10cSrcweir     for( std::vector< ImplTabItem >::iterator it = mpTabCtrlData->maItemList.begin();
1273cdf0e10cSrcweir          it != mpTabCtrlData->maItemList.end(); ++it )
1274cdf0e10cSrcweir     {
1275cdf0e10cSrcweir         if ( !it->mbFullVisible ||
1276cdf0e10cSrcweir              (it->maRect.Right()-2 >= nNewWidth) )
1277cdf0e10cSrcweir         {
1278cdf0e10cSrcweir             mbSmallInvalidate = sal_False;
1279cdf0e10cSrcweir             break;
1280cdf0e10cSrcweir         }
1281cdf0e10cSrcweir     }
1282cdf0e10cSrcweir 
1283cdf0e10cSrcweir     if ( mbSmallInvalidate )
1284cdf0e10cSrcweir     {
1285cdf0e10cSrcweir         Rectangle aRect = ImplGetTabRect( TAB_PAGERECT );
1286cdf0e10cSrcweir         aRect.Left()   -= TAB_OFFSET+TAB_BORDER_LEFT;
1287cdf0e10cSrcweir         aRect.Top()    -= TAB_OFFSET+TAB_BORDER_TOP;
1288cdf0e10cSrcweir         aRect.Right()  += TAB_OFFSET+TAB_BORDER_RIGHT;
1289cdf0e10cSrcweir         aRect.Bottom() += TAB_OFFSET+TAB_BORDER_BOTTOM;
1290cdf0e10cSrcweir         if ( bTabPage )
1291cdf0e10cSrcweir             Invalidate( aRect, INVALIDATE_NOCHILDREN );
1292cdf0e10cSrcweir         else
1293cdf0e10cSrcweir             Invalidate( aRect );
1294cdf0e10cSrcweir 
1295cdf0e10cSrcweir     }
1296cdf0e10cSrcweir     else
1297cdf0e10cSrcweir     {
1298cdf0e10cSrcweir         if ( bTabPage )
1299cdf0e10cSrcweir             Invalidate( INVALIDATE_NOCHILDREN );
1300cdf0e10cSrcweir         else
1301cdf0e10cSrcweir             Invalidate();
1302cdf0e10cSrcweir     }
1303cdf0e10cSrcweir }
1304cdf0e10cSrcweir 
1305cdf0e10cSrcweir // -----------------------------------------------------------------------
1306cdf0e10cSrcweir 
1307cdf0e10cSrcweir void TabControl::GetFocus()
1308cdf0e10cSrcweir {
1309cdf0e10cSrcweir     if( ! mpTabCtrlData->mpListBox )
1310cdf0e10cSrcweir     {
1311cdf0e10cSrcweir         ImplShowFocus();
1312cdf0e10cSrcweir         SetInputContext( InputContext( GetFont() ) );
1313cdf0e10cSrcweir     }
1314cdf0e10cSrcweir     else
1315cdf0e10cSrcweir     {
1316cdf0e10cSrcweir         if( mpTabCtrlData->mpListBox->IsReallyVisible() )
1317cdf0e10cSrcweir             mpTabCtrlData->mpListBox->GrabFocus();
1318cdf0e10cSrcweir     }
1319cdf0e10cSrcweir     Control::GetFocus();
1320cdf0e10cSrcweir }
1321cdf0e10cSrcweir 
1322cdf0e10cSrcweir // -----------------------------------------------------------------------
1323cdf0e10cSrcweir 
1324cdf0e10cSrcweir void TabControl::LoseFocus()
1325cdf0e10cSrcweir {
1326cdf0e10cSrcweir     if( ! mpTabCtrlData->mpListBox )
1327cdf0e10cSrcweir         HideFocus();
1328cdf0e10cSrcweir     Control::LoseFocus();
1329cdf0e10cSrcweir }
1330cdf0e10cSrcweir 
1331cdf0e10cSrcweir // -----------------------------------------------------------------------
1332cdf0e10cSrcweir 
1333cdf0e10cSrcweir void TabControl::RequestHelp( const HelpEvent& rHEvt )
1334cdf0e10cSrcweir {
1335cdf0e10cSrcweir     sal_uInt16 nItemId = rHEvt.KeyboardActivated() ? mnCurPageId : GetPageId( ScreenToOutputPixel( rHEvt.GetMousePosPixel() ) );
1336cdf0e10cSrcweir 
1337cdf0e10cSrcweir     if ( nItemId )
1338cdf0e10cSrcweir     {
1339cdf0e10cSrcweir         if ( rHEvt.GetMode() & HELPMODE_BALLOON )
1340cdf0e10cSrcweir         {
1341cdf0e10cSrcweir             XubString aStr = GetHelpText( nItemId );
1342cdf0e10cSrcweir             if ( aStr.Len() )
1343cdf0e10cSrcweir             {
1344cdf0e10cSrcweir                 Rectangle aItemRect = ImplGetTabRect( GetPagePos( nItemId ) );
1345cdf0e10cSrcweir                 Point aPt = OutputToScreenPixel( aItemRect.TopLeft() );
1346cdf0e10cSrcweir                 aItemRect.Left()   = aPt.X();
1347cdf0e10cSrcweir                 aItemRect.Top()    = aPt.Y();
1348cdf0e10cSrcweir                 aPt = OutputToScreenPixel( aItemRect.BottomRight() );
1349cdf0e10cSrcweir                 aItemRect.Right()  = aPt.X();
1350cdf0e10cSrcweir                 aItemRect.Bottom() = aPt.Y();
1351cdf0e10cSrcweir                 Help::ShowBalloon( this, aItemRect.Center(), aItemRect, aStr );
1352cdf0e10cSrcweir                 return;
1353cdf0e10cSrcweir             }
1354cdf0e10cSrcweir         }
1355cdf0e10cSrcweir         else if ( rHEvt.GetMode() & HELPMODE_EXTENDED )
1356cdf0e10cSrcweir         {
1357cdf0e10cSrcweir             rtl::OUString aHelpId( rtl::OStringToOUString( GetHelpId( nItemId ), RTL_TEXTENCODING_UTF8 ) );
1358cdf0e10cSrcweir             if ( aHelpId.getLength() )
1359cdf0e10cSrcweir             {
1360cdf0e10cSrcweir                 // Wenn eine Hilfe existiert, dann ausloesen
1361cdf0e10cSrcweir                 Help* pHelp = Application::GetHelp();
1362cdf0e10cSrcweir                 if ( pHelp )
1363cdf0e10cSrcweir                     pHelp->Start( aHelpId, this );
1364cdf0e10cSrcweir                 return;
1365cdf0e10cSrcweir             }
1366cdf0e10cSrcweir         }
1367cdf0e10cSrcweir 
1368cdf0e10cSrcweir         // Bei Quick- oder Balloon-Help zeigen wir den Text an,
1369cdf0e10cSrcweir         // wenn dieser abgeschnitten ist
1370cdf0e10cSrcweir         if ( rHEvt.GetMode() & (HELPMODE_QUICK | HELPMODE_BALLOON) )
1371cdf0e10cSrcweir         {
1372cdf0e10cSrcweir             ImplTabItem* pItem = ImplGetItem( nItemId );
1373cdf0e10cSrcweir             const XubString& rStr = pItem->maText;
1374cdf0e10cSrcweir             if ( rStr != pItem->maFormatText )
1375cdf0e10cSrcweir             {
1376cdf0e10cSrcweir                 Rectangle aItemRect = ImplGetTabRect( GetPagePos( nItemId ) );
1377cdf0e10cSrcweir                 Point aPt = OutputToScreenPixel( aItemRect.TopLeft() );
1378cdf0e10cSrcweir                 aItemRect.Left()   = aPt.X();
1379cdf0e10cSrcweir                 aItemRect.Top()    = aPt.Y();
1380cdf0e10cSrcweir                 aPt = OutputToScreenPixel( aItemRect.BottomRight() );
1381cdf0e10cSrcweir                 aItemRect.Right()  = aPt.X();
1382cdf0e10cSrcweir                 aItemRect.Bottom() = aPt.Y();
1383cdf0e10cSrcweir                 if ( rStr.Len() )
1384cdf0e10cSrcweir                 {
1385cdf0e10cSrcweir                     if ( rHEvt.GetMode() & HELPMODE_BALLOON )
1386cdf0e10cSrcweir                         Help::ShowBalloon( this, aItemRect.Center(), aItemRect, rStr );
1387cdf0e10cSrcweir                     else
1388cdf0e10cSrcweir                         Help::ShowQuickHelp( this, aItemRect, rStr );
1389cdf0e10cSrcweir                     return;
1390cdf0e10cSrcweir                 }
1391cdf0e10cSrcweir             }
1392cdf0e10cSrcweir         }
1393cdf0e10cSrcweir 
1394cdf0e10cSrcweir         if ( rHEvt.GetMode() & HELPMODE_QUICK )
1395cdf0e10cSrcweir         {
1396cdf0e10cSrcweir             ImplTabItem* pItem = ImplGetItem( nItemId );
1397cdf0e10cSrcweir             const XubString& rHelpText = pItem->maHelpText;
1398cdf0e10cSrcweir             // show tooltip if not text but image is set and helptext is available
1399cdf0e10cSrcweir             if ( rHelpText.Len() > 0 && pItem->maText.Len() == 0 && !!pItem->maTabImage )
1400cdf0e10cSrcweir             {
1401cdf0e10cSrcweir                 Rectangle aItemRect = ImplGetTabRect( GetPagePos( nItemId ) );
1402cdf0e10cSrcweir                 Point aPt = OutputToScreenPixel( aItemRect.TopLeft() );
1403cdf0e10cSrcweir                 aItemRect.Left()   = aPt.X();
1404cdf0e10cSrcweir                 aItemRect.Top()    = aPt.Y();
1405cdf0e10cSrcweir                 aPt = OutputToScreenPixel( aItemRect.BottomRight() );
1406cdf0e10cSrcweir                 aItemRect.Right()  = aPt.X();
1407cdf0e10cSrcweir                 aItemRect.Bottom() = aPt.Y();
1408cdf0e10cSrcweir                 Help::ShowQuickHelp( this, aItemRect, rHelpText );
1409cdf0e10cSrcweir                 return;
1410cdf0e10cSrcweir             }
1411cdf0e10cSrcweir         }
1412cdf0e10cSrcweir     }
1413cdf0e10cSrcweir 
1414cdf0e10cSrcweir     Control::RequestHelp( rHEvt );
1415cdf0e10cSrcweir }
1416cdf0e10cSrcweir 
1417cdf0e10cSrcweir // -----------------------------------------------------------------------
1418cdf0e10cSrcweir 
1419cdf0e10cSrcweir void TabControl::Command( const CommandEvent& rCEvt )
1420cdf0e10cSrcweir {
1421cdf0e10cSrcweir     if( (mpTabCtrlData->mpListBox == NULL) && (rCEvt.GetCommand() == COMMAND_CONTEXTMENU) && (GetPageCount() > 1) )
1422cdf0e10cSrcweir     {
1423cdf0e10cSrcweir         Point   aMenuPos;
1424cdf0e10cSrcweir         sal_Bool    bMenu;
1425cdf0e10cSrcweir         if ( rCEvt.IsMouseEvent() )
1426cdf0e10cSrcweir         {
1427cdf0e10cSrcweir             aMenuPos = rCEvt.GetMousePosPixel();
1428cdf0e10cSrcweir             bMenu = GetPageId( aMenuPos ) != 0;
1429cdf0e10cSrcweir         }
1430cdf0e10cSrcweir         else
1431cdf0e10cSrcweir         {
1432cdf0e10cSrcweir             aMenuPos = ImplGetTabRect( GetPagePos( mnCurPageId ) ).Center();
1433cdf0e10cSrcweir             bMenu = sal_True;
1434cdf0e10cSrcweir         }
1435cdf0e10cSrcweir 
1436cdf0e10cSrcweir         if ( bMenu )
1437cdf0e10cSrcweir         {
1438cdf0e10cSrcweir             PopupMenu aMenu;
1439cdf0e10cSrcweir             for( std::vector< ImplTabItem >::iterator it = mpTabCtrlData->maItemList.begin();
1440cdf0e10cSrcweir                  it != mpTabCtrlData->maItemList.end(); ++it )
1441cdf0e10cSrcweir             {
1442cdf0e10cSrcweir                 aMenu.InsertItem( it->mnId, it->maText, MIB_CHECKABLE | MIB_RADIOCHECK );
1443cdf0e10cSrcweir                 if ( it->mnId == mnCurPageId )
1444cdf0e10cSrcweir                     aMenu.CheckItem( it->mnId );
1445cdf0e10cSrcweir                 aMenu.SetHelpId( it->mnId, it->maHelpId );
1446cdf0e10cSrcweir             }
1447cdf0e10cSrcweir 
1448cdf0e10cSrcweir             sal_uInt16 nId = aMenu.Execute( this, aMenuPos );
1449cdf0e10cSrcweir             if ( nId && (nId != mnCurPageId) )
1450cdf0e10cSrcweir                 SelectTabPage( nId );
1451cdf0e10cSrcweir             return;
1452cdf0e10cSrcweir         }
1453cdf0e10cSrcweir     }
1454cdf0e10cSrcweir 
1455cdf0e10cSrcweir     Control::Command( rCEvt );
1456cdf0e10cSrcweir }
1457cdf0e10cSrcweir 
1458cdf0e10cSrcweir // -----------------------------------------------------------------------
1459cdf0e10cSrcweir 
1460cdf0e10cSrcweir void TabControl::StateChanged( StateChangedType nType )
1461cdf0e10cSrcweir {
1462cdf0e10cSrcweir     Control::StateChanged( nType );
1463cdf0e10cSrcweir 
1464cdf0e10cSrcweir     if ( nType == STATE_CHANGE_INITSHOW )
1465cdf0e10cSrcweir     {
1466cdf0e10cSrcweir         ImplPosCurTabPage();
1467cdf0e10cSrcweir         if( mpTabCtrlData->mpListBox )
1468cdf0e10cSrcweir             Resize();
1469cdf0e10cSrcweir     }
1470cdf0e10cSrcweir     else if ( nType == STATE_CHANGE_UPDATEMODE )
1471cdf0e10cSrcweir     {
1472cdf0e10cSrcweir         if ( IsUpdateMode() )
1473cdf0e10cSrcweir             Invalidate();
1474cdf0e10cSrcweir     }
1475cdf0e10cSrcweir     else if ( (nType == STATE_CHANGE_ZOOM)  ||
1476cdf0e10cSrcweir               (nType == STATE_CHANGE_CONTROLFONT) )
1477cdf0e10cSrcweir     {
1478cdf0e10cSrcweir         ImplInitSettings( sal_True, sal_False, sal_False );
1479cdf0e10cSrcweir         Invalidate();
1480cdf0e10cSrcweir     }
1481cdf0e10cSrcweir     else if ( nType == STATE_CHANGE_CONTROLFOREGROUND )
1482cdf0e10cSrcweir     {
1483cdf0e10cSrcweir         ImplInitSettings( sal_False, sal_True, sal_False );
1484cdf0e10cSrcweir         Invalidate();
1485cdf0e10cSrcweir     }
1486cdf0e10cSrcweir     else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
1487cdf0e10cSrcweir     {
1488cdf0e10cSrcweir         ImplInitSettings( sal_False, sal_False, sal_True );
1489cdf0e10cSrcweir         Invalidate();
1490cdf0e10cSrcweir     }
1491cdf0e10cSrcweir }
1492cdf0e10cSrcweir 
1493cdf0e10cSrcweir // -----------------------------------------------------------------------
1494cdf0e10cSrcweir 
1495cdf0e10cSrcweir void TabControl::DataChanged( const DataChangedEvent& rDCEvt )
1496cdf0e10cSrcweir {
1497cdf0e10cSrcweir     Control::DataChanged( rDCEvt );
1498cdf0e10cSrcweir 
1499cdf0e10cSrcweir     if ( (rDCEvt.GetType() == DATACHANGED_FONTS) ||
1500cdf0e10cSrcweir          (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) ||
1501cdf0e10cSrcweir          ((rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
1502cdf0e10cSrcweir           (rDCEvt.GetFlags() & SETTINGS_STYLE)) )
1503cdf0e10cSrcweir     {
1504cdf0e10cSrcweir         ImplInitSettings( sal_True, sal_True, sal_True );
1505cdf0e10cSrcweir         Invalidate();
1506cdf0e10cSrcweir     }
1507cdf0e10cSrcweir }
1508cdf0e10cSrcweir 
1509cdf0e10cSrcweir // -----------------------------------------------------------------------
1510cdf0e10cSrcweir 
1511cdf0e10cSrcweir Rectangle* TabControl::ImplFindPartRect( const Point& rPt )
1512cdf0e10cSrcweir {
1513cdf0e10cSrcweir     ImplTabItem* pFoundItem = NULL;
1514cdf0e10cSrcweir     int nFound = 0;
1515cdf0e10cSrcweir     for( std::vector< ImplTabItem >::iterator it = mpTabCtrlData->maItemList.begin();
1516cdf0e10cSrcweir          it != mpTabCtrlData->maItemList.end(); ++it )
1517cdf0e10cSrcweir     {
1518cdf0e10cSrcweir         if ( it->maRect.IsInside( rPt ) )
1519cdf0e10cSrcweir         {
1520cdf0e10cSrcweir             // assure that only one tab is highlighted at a time
1521cdf0e10cSrcweir             nFound++;
1522cdf0e10cSrcweir             pFoundItem = &(*it);
1523cdf0e10cSrcweir         }
1524cdf0e10cSrcweir     }
1525cdf0e10cSrcweir     // assure that only one tab is highlighted at a time
1526cdf0e10cSrcweir     return nFound == 1 ? &pFoundItem->maRect : NULL;
1527cdf0e10cSrcweir }
1528cdf0e10cSrcweir 
1529cdf0e10cSrcweir long TabControl::PreNotify( NotifyEvent& rNEvt )
1530cdf0e10cSrcweir {
1531cdf0e10cSrcweir     long nDone = 0;
1532cdf0e10cSrcweir     const MouseEvent* pMouseEvt = NULL;
1533cdf0e10cSrcweir 
1534cdf0e10cSrcweir     if( (rNEvt.GetType() == EVENT_MOUSEMOVE) && (pMouseEvt = rNEvt.GetMouseEvent()) != NULL )
1535cdf0e10cSrcweir     {
1536cdf0e10cSrcweir         if( !pMouseEvt->GetButtons() && !pMouseEvt->IsSynthetic() && !pMouseEvt->IsModifierChanged() )
1537cdf0e10cSrcweir         {
1538cdf0e10cSrcweir             // trigger redraw if mouse over state has changed
1539cdf0e10cSrcweir             if( IsNativeControlSupported(CTRL_TAB_ITEM, PART_ENTIRE_CONTROL) )
1540cdf0e10cSrcweir             {
1541cdf0e10cSrcweir                 Rectangle* pRect = ImplFindPartRect( GetPointerPosPixel() );
1542cdf0e10cSrcweir                 Rectangle* pLastRect = ImplFindPartRect( GetLastPointerPosPixel() );
1543cdf0e10cSrcweir                 if( pRect != pLastRect || (pMouseEvt->IsLeaveWindow() || pMouseEvt->IsEnterWindow()) )
1544cdf0e10cSrcweir                 {
1545cdf0e10cSrcweir                     Region aClipRgn;
1546cdf0e10cSrcweir                     if( pLastRect )
1547cdf0e10cSrcweir                     {
1548cdf0e10cSrcweir                         // allow for slightly bigger tabitems
1549cdf0e10cSrcweir                         // as used by gtk
1550cdf0e10cSrcweir                         // TODO: query for the correct sizes
1551cdf0e10cSrcweir                         Rectangle aRect(*pLastRect);
1552cdf0e10cSrcweir                         aRect.nLeft-=2;
1553cdf0e10cSrcweir                         aRect.nRight+=2;
1554cdf0e10cSrcweir                         aRect.nTop-=3;
1555cdf0e10cSrcweir                         aClipRgn.Union( aRect );
1556cdf0e10cSrcweir                     }
1557cdf0e10cSrcweir                     if( pRect )
1558cdf0e10cSrcweir                     {
1559cdf0e10cSrcweir                         // allow for slightly bigger tabitems
1560cdf0e10cSrcweir                         // as used by gtk
1561cdf0e10cSrcweir                         // TODO: query for the correct sizes
1562cdf0e10cSrcweir                         Rectangle aRect(*pRect);
1563cdf0e10cSrcweir                         aRect.nLeft-=2;
1564cdf0e10cSrcweir                         aRect.nRight+=2;
1565cdf0e10cSrcweir                         aRect.nTop-=3;
1566cdf0e10cSrcweir                         aClipRgn.Union( aRect );
1567cdf0e10cSrcweir                     }
1568cdf0e10cSrcweir                     if( !aClipRgn.IsEmpty() )
1569cdf0e10cSrcweir                         Invalidate( aClipRgn );
1570cdf0e10cSrcweir                 }
1571cdf0e10cSrcweir             }
1572cdf0e10cSrcweir         }
1573cdf0e10cSrcweir     }
1574cdf0e10cSrcweir 
1575cdf0e10cSrcweir     return nDone ? nDone : Control::PreNotify(rNEvt);
1576cdf0e10cSrcweir }
1577cdf0e10cSrcweir 
1578cdf0e10cSrcweir // -----------------------------------------------------------------------
1579cdf0e10cSrcweir 
1580cdf0e10cSrcweir long TabControl::Notify( NotifyEvent& rNEvt )
1581cdf0e10cSrcweir {
1582cdf0e10cSrcweir     long nRet = 0;
1583cdf0e10cSrcweir 
1584cdf0e10cSrcweir     if ( rNEvt.GetType() == EVENT_KEYINPUT )
1585cdf0e10cSrcweir         nRet = ImplHandleKeyEvent( *rNEvt.GetKeyEvent() );
1586cdf0e10cSrcweir 
1587cdf0e10cSrcweir     return nRet ? nRet : Control::Notify( rNEvt );
1588cdf0e10cSrcweir }
1589cdf0e10cSrcweir 
1590cdf0e10cSrcweir // -----------------------------------------------------------------------
1591cdf0e10cSrcweir 
1592cdf0e10cSrcweir void TabControl::ActivatePage()
1593cdf0e10cSrcweir {
1594cdf0e10cSrcweir     maActivateHdl.Call( this );
1595cdf0e10cSrcweir }
1596cdf0e10cSrcweir 
1597cdf0e10cSrcweir // -----------------------------------------------------------------------
1598cdf0e10cSrcweir 
1599cdf0e10cSrcweir long TabControl::DeactivatePage()
1600cdf0e10cSrcweir {
1601cdf0e10cSrcweir     if ( maDeactivateHdl.IsSet() )
1602cdf0e10cSrcweir         return maDeactivateHdl.Call( this );
1603cdf0e10cSrcweir     else
1604cdf0e10cSrcweir         return sal_True;
1605cdf0e10cSrcweir }
1606cdf0e10cSrcweir 
1607cdf0e10cSrcweir // -----------------------------------------------------------------------
1608cdf0e10cSrcweir 
1609cdf0e10cSrcweir void TabControl::SetTabPageSizePixel( const Size& rSize )
1610cdf0e10cSrcweir {
1611cdf0e10cSrcweir     ImplFreeLayoutData();
1612cdf0e10cSrcweir 
1613cdf0e10cSrcweir     Size aNewSize( rSize );
1614cdf0e10cSrcweir     aNewSize.Width() += TAB_OFFSET*2;
1615cdf0e10cSrcweir     Rectangle aRect = ImplGetTabRect( TAB_PAGERECT,
1616cdf0e10cSrcweir                                       aNewSize.Width(), aNewSize.Height() );
1617cdf0e10cSrcweir     aNewSize.Height() += aRect.Top()+TAB_OFFSET;
1618cdf0e10cSrcweir     Window::SetOutputSizePixel( aNewSize );
1619cdf0e10cSrcweir }
1620cdf0e10cSrcweir 
1621cdf0e10cSrcweir // -----------------------------------------------------------------------
1622cdf0e10cSrcweir 
1623cdf0e10cSrcweir Size TabControl::GetTabPageSizePixel() const
1624cdf0e10cSrcweir {
1625cdf0e10cSrcweir     Rectangle aRect = ((TabControl*)this)->ImplGetTabRect( TAB_PAGERECT );
1626cdf0e10cSrcweir     return aRect.GetSize();
1627cdf0e10cSrcweir }
1628cdf0e10cSrcweir 
1629cdf0e10cSrcweir // -----------------------------------------------------------------------
1630cdf0e10cSrcweir 
1631cdf0e10cSrcweir void TabControl::InsertPage( const ResId& rResId, sal_uInt16 nPos )
1632cdf0e10cSrcweir {
1633cdf0e10cSrcweir     GetRes( rResId.SetRT( RSC_TABCONTROLITEM ) );
1634cdf0e10cSrcweir 
1635cdf0e10cSrcweir     sal_uLong nObjMask = ReadLongRes();
1636cdf0e10cSrcweir     sal_uInt16 nItemId  = 1;
1637cdf0e10cSrcweir 
1638cdf0e10cSrcweir     // ID
1639cdf0e10cSrcweir     if ( nObjMask & RSC_TABCONTROLITEM_ID )
1640cdf0e10cSrcweir         nItemId = sal::static_int_cast<sal_uInt16>(ReadLongRes());
1641cdf0e10cSrcweir 
1642cdf0e10cSrcweir     // Text
1643cdf0e10cSrcweir     XubString aTmpStr;
1644cdf0e10cSrcweir     if( nObjMask & RSC_TABCONTROLITEM_TEXT )
1645cdf0e10cSrcweir         aTmpStr = ReadStringRes();
1646cdf0e10cSrcweir     InsertPage( nItemId, aTmpStr, nPos );
1647cdf0e10cSrcweir 
1648cdf0e10cSrcweir     // PageResID
1649cdf0e10cSrcweir     if ( nObjMask & RSC_TABCONTROLITEM_PAGERESID )
1650cdf0e10cSrcweir     {
1651cdf0e10cSrcweir         ImplTabItem& rItem = mpTabCtrlData->maItemList[ GetPagePos( nItemId ) ];
1652cdf0e10cSrcweir         rItem.mnTabPageResId = sal::static_int_cast<sal_uInt16>(ReadLongRes());
1653cdf0e10cSrcweir     }
1654cdf0e10cSrcweir }
1655cdf0e10cSrcweir 
1656cdf0e10cSrcweir // -----------------------------------------------------------------------
1657cdf0e10cSrcweir 
1658cdf0e10cSrcweir void TabControl::InsertPage( sal_uInt16 nPageId, const XubString& rText,
1659cdf0e10cSrcweir                              sal_uInt16 nPos )
1660cdf0e10cSrcweir {
1661cdf0e10cSrcweir     DBG_ASSERT( nPageId, "TabControl::InsertPage(): PageId == 0" );
1662cdf0e10cSrcweir     DBG_ASSERT( GetPagePos( nPageId ) == TAB_PAGE_NOTFOUND,
1663cdf0e10cSrcweir                 "TabControl::InsertPage(): PageId already exists" );
1664cdf0e10cSrcweir 
1665cdf0e10cSrcweir     // insert new page item
1666cdf0e10cSrcweir     ImplTabItem* pItem = NULL;
1667cdf0e10cSrcweir     if( nPos == TAB_APPEND || size_t(nPos) >= mpTabCtrlData->maItemList.size() )
1668cdf0e10cSrcweir     {
1669cdf0e10cSrcweir         mpTabCtrlData->maItemList.push_back( ImplTabItem() );
1670cdf0e10cSrcweir         pItem = &mpTabCtrlData->maItemList.back();
1671cdf0e10cSrcweir         if( mpTabCtrlData->mpListBox )
1672cdf0e10cSrcweir             mpTabCtrlData->mpListBox->InsertEntry( rText );
1673cdf0e10cSrcweir     }
1674cdf0e10cSrcweir     else
1675cdf0e10cSrcweir     {
1676cdf0e10cSrcweir         std::vector< ImplTabItem >::iterator new_it =
1677cdf0e10cSrcweir             mpTabCtrlData->maItemList.insert( mpTabCtrlData->maItemList.begin() + nPos, ImplTabItem() );
1678cdf0e10cSrcweir         pItem = &(*new_it);
1679cdf0e10cSrcweir         if( mpTabCtrlData->mpListBox )
1680cdf0e10cSrcweir             mpTabCtrlData->mpListBox->InsertEntry( rText, nPos);
1681cdf0e10cSrcweir     }
1682cdf0e10cSrcweir     if( mpTabCtrlData->mpListBox )
1683cdf0e10cSrcweir     {
1684cdf0e10cSrcweir         if( ! mnCurPageId )
1685cdf0e10cSrcweir             mpTabCtrlData->mpListBox->SelectEntryPos( 0 );
1686cdf0e10cSrcweir         mpTabCtrlData->mpListBox->SetDropDownLineCount( mpTabCtrlData->mpListBox->GetEntryCount() );
1687cdf0e10cSrcweir     }
1688cdf0e10cSrcweir 
1689cdf0e10cSrcweir     // set current page id
1690cdf0e10cSrcweir     if ( !mnCurPageId )
1691cdf0e10cSrcweir         mnCurPageId = nPageId;
1692cdf0e10cSrcweir 
1693cdf0e10cSrcweir     // init new page item
1694cdf0e10cSrcweir     pItem->mnId             = nPageId;
1695cdf0e10cSrcweir     pItem->mpTabPage        = NULL;
1696cdf0e10cSrcweir     pItem->mnTabPageResId   = 0;
1697cdf0e10cSrcweir     pItem->maText           = rText;
1698cdf0e10cSrcweir     pItem->mbFullVisible    = sal_False;
1699cdf0e10cSrcweir 
1700cdf0e10cSrcweir     mbFormat = sal_True;
1701cdf0e10cSrcweir     if ( IsUpdateMode() )
1702cdf0e10cSrcweir         Invalidate();
1703cdf0e10cSrcweir 
1704cdf0e10cSrcweir     ImplFreeLayoutData();
1705cdf0e10cSrcweir     if( mpTabCtrlData->mpListBox ) // reposition/resize listbox
1706cdf0e10cSrcweir         Resize();
1707cdf0e10cSrcweir 
1708cdf0e10cSrcweir 	ImplCallEventListeners( VCLEVENT_TABPAGE_INSERTED, (void*) (sal_uLong)nPageId );
1709cdf0e10cSrcweir }
1710cdf0e10cSrcweir 
1711cdf0e10cSrcweir // -----------------------------------------------------------------------
1712cdf0e10cSrcweir 
1713cdf0e10cSrcweir void TabControl::RemovePage( sal_uInt16 nPageId )
1714cdf0e10cSrcweir {
1715cdf0e10cSrcweir     sal_uInt16 nPos = GetPagePos( nPageId );
1716cdf0e10cSrcweir 
1717cdf0e10cSrcweir     // does the item exist ?
1718cdf0e10cSrcweir     if ( nPos != TAB_PAGE_NOTFOUND )
1719cdf0e10cSrcweir     {
1720cdf0e10cSrcweir         //remove page item
1721cdf0e10cSrcweir         std::vector< ImplTabItem >::iterator it = mpTabCtrlData->maItemList.begin() + nPos;
1722cdf0e10cSrcweir         bool bIsCurrentPage = (it->mnId == mnCurPageId);
1723cdf0e10cSrcweir         mpTabCtrlData->maItemList.erase( it );
1724cdf0e10cSrcweir         if( mpTabCtrlData->mpListBox )
1725cdf0e10cSrcweir         {
1726cdf0e10cSrcweir             mpTabCtrlData->mpListBox->RemoveEntry( nPos );
1727cdf0e10cSrcweir             mpTabCtrlData->mpListBox->SetDropDownLineCount( mpTabCtrlData->mpListBox->GetEntryCount() );
1728cdf0e10cSrcweir         }
1729cdf0e10cSrcweir 
1730cdf0e10cSrcweir         // If current page is removed, than first page gets the current page
1731cdf0e10cSrcweir         if ( bIsCurrentPage  )
1732cdf0e10cSrcweir         {
1733cdf0e10cSrcweir             mnCurPageId = 0;
1734cdf0e10cSrcweir 
1735cdf0e10cSrcweir             if( ! mpTabCtrlData->maItemList.empty() )
1736cdf0e10cSrcweir             {
1737cdf0e10cSrcweir                 // don't do this by simply setting mnCurPageId to pFirstItem->mnId
1738cdf0e10cSrcweir                 // this leaves a lot of stuff (such trivias as _showing_ the new current page) undone
1739cdf0e10cSrcweir                 // instead, call SetCurPageId
1740cdf0e10cSrcweir                 // without this, the next (outside) call to SetCurPageId with the id of the first page
1741cdf0e10cSrcweir                 // will result in doing nothing (as we assume that nothing changed, then), and the page
1742cdf0e10cSrcweir                 // will never be shown.
1743cdf0e10cSrcweir                 // 86875 - 05/11/2001 - frank.schoenheit@germany.sun.com
1744cdf0e10cSrcweir 
1745cdf0e10cSrcweir                 SetCurPageId( mpTabCtrlData->maItemList[0].mnId );
1746cdf0e10cSrcweir             }
1747cdf0e10cSrcweir         }
1748cdf0e10cSrcweir 
1749cdf0e10cSrcweir         mbFormat = sal_True;
1750cdf0e10cSrcweir         if ( IsUpdateMode() )
1751cdf0e10cSrcweir             Invalidate();
1752cdf0e10cSrcweir 
1753cdf0e10cSrcweir         ImplFreeLayoutData();
1754cdf0e10cSrcweir 
1755cdf0e10cSrcweir 		ImplCallEventListeners( VCLEVENT_TABPAGE_REMOVED, (void*) (sal_uLong) nPageId );
1756cdf0e10cSrcweir     }
1757cdf0e10cSrcweir }
1758cdf0e10cSrcweir 
1759cdf0e10cSrcweir // -----------------------------------------------------------------------
1760cdf0e10cSrcweir 
1761cdf0e10cSrcweir void TabControl::Clear()
1762cdf0e10cSrcweir {
1763cdf0e10cSrcweir     // clear item list
1764cdf0e10cSrcweir     mpTabCtrlData->maItemList.clear();
1765cdf0e10cSrcweir     mnCurPageId = 0;
1766cdf0e10cSrcweir     if( mpTabCtrlData->mpListBox )
1767cdf0e10cSrcweir         mpTabCtrlData->mpListBox->Clear();
1768cdf0e10cSrcweir 
1769cdf0e10cSrcweir     ImplFreeLayoutData();
1770cdf0e10cSrcweir 
1771cdf0e10cSrcweir     mbFormat = sal_True;
1772cdf0e10cSrcweir     if ( IsUpdateMode() )
1773cdf0e10cSrcweir         Invalidate();
1774cdf0e10cSrcweir 
1775cdf0e10cSrcweir 	ImplCallEventListeners( VCLEVENT_TABPAGE_REMOVEDALL );
1776cdf0e10cSrcweir }
1777cdf0e10cSrcweir 
1778cdf0e10cSrcweir // -----------------------------------------------------------------------
1779cdf0e10cSrcweir 
1780cdf0e10cSrcweir void TabControl::EnablePage( sal_uInt16 i_nPageId, bool i_bEnable )
1781cdf0e10cSrcweir {
1782cdf0e10cSrcweir     ImplTabItem* pItem = ImplGetItem( i_nPageId );
1783cdf0e10cSrcweir 
1784cdf0e10cSrcweir     if ( pItem && pItem->mbEnabled != i_bEnable )
1785cdf0e10cSrcweir     {
1786cdf0e10cSrcweir         pItem->mbEnabled = i_bEnable;
1787cdf0e10cSrcweir         mbFormat = sal_True;
1788cdf0e10cSrcweir         if( mpTabCtrlData->mpListBox )
1789cdf0e10cSrcweir             mpTabCtrlData->mpListBox->SetEntryFlags( GetPagePos( i_nPageId ),
1790cdf0e10cSrcweir                                                      i_bEnable ? 0 : (LISTBOX_ENTRY_FLAG_DISABLE_SELECTION | LISTBOX_ENTRY_FLAG_DRAW_DISABLED) );
1791cdf0e10cSrcweir         if( pItem->mnId == mnCurPageId )
1792cdf0e10cSrcweir         {
1793cdf0e10cSrcweir              // SetCurPageId will change to an enabled page
1794cdf0e10cSrcweir             SetCurPageId( mnCurPageId );
1795cdf0e10cSrcweir         }
1796cdf0e10cSrcweir         else if ( IsUpdateMode() )
1797cdf0e10cSrcweir             Invalidate();
1798cdf0e10cSrcweir     }
1799cdf0e10cSrcweir }
1800cdf0e10cSrcweir 
1801cdf0e10cSrcweir // -----------------------------------------------------------------------
1802cdf0e10cSrcweir 
1803cdf0e10cSrcweir sal_uInt16 TabControl::GetPageCount() const
1804cdf0e10cSrcweir {
1805cdf0e10cSrcweir     return (sal_uInt16)mpTabCtrlData->maItemList.size();
1806cdf0e10cSrcweir }
1807cdf0e10cSrcweir 
1808cdf0e10cSrcweir // -----------------------------------------------------------------------
1809cdf0e10cSrcweir 
1810cdf0e10cSrcweir sal_uInt16 TabControl::GetPageId( sal_uInt16 nPos ) const
1811cdf0e10cSrcweir {
1812cdf0e10cSrcweir     if( size_t(nPos) < mpTabCtrlData->maItemList.size() )
1813cdf0e10cSrcweir         return mpTabCtrlData->maItemList[ nPos ].mnId;
1814cdf0e10cSrcweir     return 0;
1815cdf0e10cSrcweir }
1816cdf0e10cSrcweir 
1817cdf0e10cSrcweir // -----------------------------------------------------------------------
1818cdf0e10cSrcweir 
1819cdf0e10cSrcweir sal_uInt16 TabControl::GetPagePos( sal_uInt16 nPageId ) const
1820cdf0e10cSrcweir {
1821cdf0e10cSrcweir     for( std::vector< ImplTabItem >::const_iterator it = mpTabCtrlData->maItemList.begin();
1822cdf0e10cSrcweir          it != mpTabCtrlData->maItemList.end(); ++it )
1823cdf0e10cSrcweir     {
1824cdf0e10cSrcweir         if ( it->mnId == nPageId )
1825cdf0e10cSrcweir             return (sal_uInt16)(it - mpTabCtrlData->maItemList.begin());
1826cdf0e10cSrcweir     }
1827cdf0e10cSrcweir 
1828cdf0e10cSrcweir     return TAB_PAGE_NOTFOUND;
1829cdf0e10cSrcweir }
1830cdf0e10cSrcweir 
1831cdf0e10cSrcweir // -----------------------------------------------------------------------
1832cdf0e10cSrcweir 
1833cdf0e10cSrcweir sal_uInt16 TabControl::GetPageId( const Point& rPos ) const
1834cdf0e10cSrcweir {
1835cdf0e10cSrcweir     for( size_t i = 0; i < mpTabCtrlData->maItemList.size(); ++i )
1836cdf0e10cSrcweir     {
1837cdf0e10cSrcweir         if ( ((TabControl*)this)->ImplGetTabRect( static_cast<sal_uInt16>(i) ).IsInside( rPos ) )
1838cdf0e10cSrcweir             return mpTabCtrlData->maItemList[ i ].mnId;
1839cdf0e10cSrcweir     }
1840cdf0e10cSrcweir 
1841cdf0e10cSrcweir     return 0;
1842cdf0e10cSrcweir }
1843cdf0e10cSrcweir 
1844cdf0e10cSrcweir // -----------------------------------------------------------------------
1845cdf0e10cSrcweir 
1846cdf0e10cSrcweir void TabControl::SetCurPageId( sal_uInt16 nPageId )
1847cdf0e10cSrcweir {
1848cdf0e10cSrcweir     sal_uInt16 nPos = GetPagePos( nPageId );
1849cdf0e10cSrcweir     while( nPos != TAB_PAGE_NOTFOUND &&
1850cdf0e10cSrcweir            ! mpTabCtrlData->maItemList[nPos].mbEnabled )
1851cdf0e10cSrcweir     {
1852cdf0e10cSrcweir         nPos++;
1853cdf0e10cSrcweir         if( size_t(nPos) >= mpTabCtrlData->maItemList.size() )
1854cdf0e10cSrcweir             nPos = 0;
1855cdf0e10cSrcweir         if( mpTabCtrlData->maItemList[nPos].mnId == nPageId )
1856cdf0e10cSrcweir             break;
1857cdf0e10cSrcweir     }
1858cdf0e10cSrcweir 
1859cdf0e10cSrcweir     if( nPos != TAB_PAGE_NOTFOUND )
1860cdf0e10cSrcweir     {
1861cdf0e10cSrcweir         nPageId = mpTabCtrlData->maItemList[nPos].mnId;
1862cdf0e10cSrcweir         if ( nPageId == mnCurPageId )
1863cdf0e10cSrcweir         {
1864cdf0e10cSrcweir             if ( mnActPageId )
1865cdf0e10cSrcweir                 mnActPageId = nPageId;
1866cdf0e10cSrcweir             return;
1867cdf0e10cSrcweir         }
1868cdf0e10cSrcweir 
1869cdf0e10cSrcweir         if ( mnActPageId )
1870cdf0e10cSrcweir             mnActPageId = nPageId;
1871cdf0e10cSrcweir         else
1872cdf0e10cSrcweir         {
1873cdf0e10cSrcweir             mbFormat = sal_True;
1874cdf0e10cSrcweir             sal_uInt16 nOldId = mnCurPageId;
1875cdf0e10cSrcweir             mnCurPageId = nPageId;
1876cdf0e10cSrcweir             ImplChangeTabPage( nPageId, nOldId );
1877cdf0e10cSrcweir         }
1878cdf0e10cSrcweir     }
1879cdf0e10cSrcweir }
1880cdf0e10cSrcweir 
1881cdf0e10cSrcweir // -----------------------------------------------------------------------
1882cdf0e10cSrcweir 
1883cdf0e10cSrcweir sal_uInt16 TabControl::GetCurPageId() const
1884cdf0e10cSrcweir {
1885cdf0e10cSrcweir     if ( mnActPageId )
1886cdf0e10cSrcweir         return mnActPageId;
1887cdf0e10cSrcweir     else
1888cdf0e10cSrcweir         return mnCurPageId;
1889cdf0e10cSrcweir }
1890cdf0e10cSrcweir 
1891cdf0e10cSrcweir // -----------------------------------------------------------------------
1892cdf0e10cSrcweir 
1893cdf0e10cSrcweir void TabControl::SelectTabPage( sal_uInt16 nPageId )
1894cdf0e10cSrcweir {
1895cdf0e10cSrcweir     if ( nPageId && (nPageId != mnCurPageId) )
1896cdf0e10cSrcweir     {
1897cdf0e10cSrcweir         ImplFreeLayoutData();
1898cdf0e10cSrcweir 
1899cdf0e10cSrcweir 		ImplCallEventListeners( VCLEVENT_TABPAGE_DEACTIVATE, (void*) (sal_uLong) mnCurPageId );
1900cdf0e10cSrcweir         if ( DeactivatePage() )
1901cdf0e10cSrcweir         {
1902cdf0e10cSrcweir             mnActPageId = nPageId;
1903cdf0e10cSrcweir             ActivatePage();
1904cdf0e10cSrcweir             // Page koennte im Activate-Handler umgeschaltet wurden sein
1905cdf0e10cSrcweir             nPageId = mnActPageId;
1906cdf0e10cSrcweir             mnActPageId = 0;
1907cdf0e10cSrcweir             SetCurPageId( nPageId );
1908cdf0e10cSrcweir             if( mpTabCtrlData->mpListBox )
1909cdf0e10cSrcweir                 mpTabCtrlData->mpListBox->SelectEntryPos( GetPagePos( nPageId ) );
1910cdf0e10cSrcweir 			ImplCallEventListeners( VCLEVENT_TABPAGE_ACTIVATE, (void*) (sal_uLong) nPageId );
1911cdf0e10cSrcweir         }
1912cdf0e10cSrcweir     }
1913cdf0e10cSrcweir }
1914cdf0e10cSrcweir 
1915cdf0e10cSrcweir // -----------------------------------------------------------------------
1916cdf0e10cSrcweir 
1917cdf0e10cSrcweir void TabControl::SetTabPage( sal_uInt16 nPageId, TabPage* pTabPage )
1918cdf0e10cSrcweir {
1919cdf0e10cSrcweir     ImplTabItem* pItem = ImplGetItem( nPageId );
1920cdf0e10cSrcweir 
1921cdf0e10cSrcweir     if ( pItem && (pItem->mpTabPage != pTabPage) )
1922cdf0e10cSrcweir     {
1923cdf0e10cSrcweir         if ( pTabPage )
1924cdf0e10cSrcweir         {
1925cdf0e10cSrcweir             DBG_ASSERT( !pTabPage->IsVisible(), "TabControl::SetTabPage() - Page is visible" );
1926cdf0e10cSrcweir 
1927cdf0e10cSrcweir             if ( IsDefaultSize() )
1928cdf0e10cSrcweir                 SetTabPageSizePixel( pTabPage->GetSizePixel() );
1929cdf0e10cSrcweir 
1930cdf0e10cSrcweir             // Erst hier setzen, damit Resize nicht TabPage umpositioniert
1931cdf0e10cSrcweir             pItem->mpTabPage = pTabPage;
1932cdf0e10cSrcweir             if ( pItem->mnId == mnCurPageId )
1933cdf0e10cSrcweir                 ImplChangeTabPage( pItem->mnId, 0 );
1934cdf0e10cSrcweir         }
1935cdf0e10cSrcweir         else
1936cdf0e10cSrcweir             pItem->mpTabPage = NULL;
1937cdf0e10cSrcweir     }
1938cdf0e10cSrcweir }
1939cdf0e10cSrcweir 
1940cdf0e10cSrcweir // -----------------------------------------------------------------------
1941cdf0e10cSrcweir 
1942cdf0e10cSrcweir TabPage* TabControl::GetTabPage( sal_uInt16 nPageId ) const
1943cdf0e10cSrcweir {
1944cdf0e10cSrcweir     ImplTabItem* pItem = ImplGetItem( nPageId );
1945cdf0e10cSrcweir 
1946cdf0e10cSrcweir     if ( pItem )
1947cdf0e10cSrcweir         return pItem->mpTabPage;
1948cdf0e10cSrcweir     else
1949cdf0e10cSrcweir         return NULL;
1950cdf0e10cSrcweir }
1951cdf0e10cSrcweir 
1952cdf0e10cSrcweir // -----------------------------------------------------------------------
1953cdf0e10cSrcweir 
1954cdf0e10cSrcweir sal_uInt16 TabControl::GetTabPageResId( sal_uInt16 nPageId ) const
1955cdf0e10cSrcweir {
1956cdf0e10cSrcweir     ImplTabItem* pItem = ImplGetItem( nPageId );
1957cdf0e10cSrcweir 
1958cdf0e10cSrcweir     if ( pItem )
1959cdf0e10cSrcweir         return pItem->mnTabPageResId;
1960cdf0e10cSrcweir     else
1961cdf0e10cSrcweir         return 0;
1962cdf0e10cSrcweir }
1963cdf0e10cSrcweir 
1964cdf0e10cSrcweir // -----------------------------------------------------------------------
1965cdf0e10cSrcweir 
1966cdf0e10cSrcweir void TabControl::SetPageText( sal_uInt16 nPageId, const XubString& rText )
1967cdf0e10cSrcweir {
1968cdf0e10cSrcweir     ImplTabItem* pItem = ImplGetItem( nPageId );
1969cdf0e10cSrcweir 
1970cdf0e10cSrcweir     if ( pItem && pItem->maText != rText )
1971cdf0e10cSrcweir     {
1972cdf0e10cSrcweir         pItem->maText = rText;
1973cdf0e10cSrcweir         mbFormat = sal_True;
1974cdf0e10cSrcweir         if( mpTabCtrlData->mpListBox )
1975cdf0e10cSrcweir         {
1976cdf0e10cSrcweir             sal_uInt16 nPos = GetPagePos( nPageId );
1977cdf0e10cSrcweir             mpTabCtrlData->mpListBox->RemoveEntry( nPos );
1978cdf0e10cSrcweir             mpTabCtrlData->mpListBox->InsertEntry( rText, nPos );
1979cdf0e10cSrcweir         }
1980cdf0e10cSrcweir         if ( IsUpdateMode() )
1981cdf0e10cSrcweir             Invalidate();
1982cdf0e10cSrcweir         ImplFreeLayoutData();
1983cdf0e10cSrcweir 		ImplCallEventListeners( VCLEVENT_TABPAGE_PAGETEXTCHANGED, (void*) (sal_uLong) nPageId );
1984cdf0e10cSrcweir     }
1985cdf0e10cSrcweir }
1986cdf0e10cSrcweir 
1987cdf0e10cSrcweir // -----------------------------------------------------------------------
1988cdf0e10cSrcweir 
1989cdf0e10cSrcweir XubString TabControl::GetPageText( sal_uInt16 nPageId ) const
1990cdf0e10cSrcweir {
1991cdf0e10cSrcweir     ImplTabItem* pItem = ImplGetItem( nPageId );
1992cdf0e10cSrcweir 
1993cdf0e10cSrcweir     if ( pItem )
1994cdf0e10cSrcweir         return pItem->maText;
1995cdf0e10cSrcweir     else
1996cdf0e10cSrcweir         return ImplGetSVEmptyStr();
1997cdf0e10cSrcweir }
1998cdf0e10cSrcweir 
1999cdf0e10cSrcweir // -----------------------------------------------------------------------
2000cdf0e10cSrcweir 
2001cdf0e10cSrcweir void TabControl::SetHelpText( sal_uInt16 nPageId, const XubString& rText )
2002cdf0e10cSrcweir {
2003cdf0e10cSrcweir     ImplTabItem* pItem = ImplGetItem( nPageId );
2004cdf0e10cSrcweir 
2005cdf0e10cSrcweir     if ( pItem )
2006cdf0e10cSrcweir         pItem->maHelpText = rText;
2007cdf0e10cSrcweir }
2008cdf0e10cSrcweir 
2009cdf0e10cSrcweir // -----------------------------------------------------------------------
2010cdf0e10cSrcweir 
2011cdf0e10cSrcweir const XubString& TabControl::GetHelpText( sal_uInt16 nPageId ) const
2012cdf0e10cSrcweir {
2013cdf0e10cSrcweir     ImplTabItem* pItem = ImplGetItem( nPageId );
2014cdf0e10cSrcweir 
2015cdf0e10cSrcweir     if ( pItem )
2016cdf0e10cSrcweir     {
2017cdf0e10cSrcweir         if ( !pItem->maHelpText.Len() && pItem->maHelpId.getLength() )
2018cdf0e10cSrcweir         {
2019cdf0e10cSrcweir             Help* pHelp = Application::GetHelp();
2020cdf0e10cSrcweir             if ( pHelp )
2021cdf0e10cSrcweir                 pItem->maHelpText = pHelp->GetHelpText( rtl::OStringToOUString( pItem->maHelpId, RTL_TEXTENCODING_UTF8 ), this );
2022cdf0e10cSrcweir         }
2023cdf0e10cSrcweir 
2024cdf0e10cSrcweir         return pItem->maHelpText;
2025cdf0e10cSrcweir     }
2026cdf0e10cSrcweir     else
2027cdf0e10cSrcweir         return ImplGetSVEmptyStr();
2028cdf0e10cSrcweir }
2029cdf0e10cSrcweir 
2030cdf0e10cSrcweir // -----------------------------------------------------------------------
2031cdf0e10cSrcweir 
2032cdf0e10cSrcweir void TabControl::SetHelpId( sal_uInt16 nPageId, const rtl::OString& rHelpId )
2033cdf0e10cSrcweir {
2034cdf0e10cSrcweir     ImplTabItem* pItem = ImplGetItem( nPageId );
2035cdf0e10cSrcweir 
2036cdf0e10cSrcweir     if ( pItem )
2037cdf0e10cSrcweir         pItem->maHelpId = rHelpId;
2038cdf0e10cSrcweir }
2039cdf0e10cSrcweir 
2040cdf0e10cSrcweir // -----------------------------------------------------------------------
2041cdf0e10cSrcweir 
2042cdf0e10cSrcweir rtl::OString TabControl::GetHelpId( sal_uInt16 nPageId ) const
2043cdf0e10cSrcweir {
2044cdf0e10cSrcweir     rtl::OString aRet;
2045cdf0e10cSrcweir     ImplTabItem* pItem = ImplGetItem( nPageId );
2046cdf0e10cSrcweir 
2047cdf0e10cSrcweir     if ( pItem )
2048cdf0e10cSrcweir         aRet = pItem->maHelpId;
2049cdf0e10cSrcweir 
2050cdf0e10cSrcweir     return aRet;
2051cdf0e10cSrcweir }
2052cdf0e10cSrcweir 
2053cdf0e10cSrcweir // -----------------------------------------------------------------------
2054cdf0e10cSrcweir 
2055cdf0e10cSrcweir void TabControl::SetPageImage( sal_uInt16 i_nPageId, const Image& i_rImage )
2056cdf0e10cSrcweir {
2057cdf0e10cSrcweir     ImplTabItem* pItem = ImplGetItem( i_nPageId );
2058cdf0e10cSrcweir 
2059cdf0e10cSrcweir     if ( pItem )
2060cdf0e10cSrcweir     {
2061cdf0e10cSrcweir         pItem->maTabImage = i_rImage;
2062cdf0e10cSrcweir         mbFormat = sal_True;
2063cdf0e10cSrcweir         if ( IsUpdateMode() )
2064cdf0e10cSrcweir             Invalidate();
2065cdf0e10cSrcweir     }
2066cdf0e10cSrcweir }
2067cdf0e10cSrcweir 
2068cdf0e10cSrcweir // -----------------------------------------------------------------------
2069cdf0e10cSrcweir 
2070cdf0e10cSrcweir const Image* TabControl::GetPageImage( sal_uInt16 i_nPageId ) const
2071cdf0e10cSrcweir {
2072cdf0e10cSrcweir     const ImplTabItem* pItem = ImplGetItem( i_nPageId );
2073cdf0e10cSrcweir     return pItem ? &pItem->maTabImage : NULL;
2074cdf0e10cSrcweir }
2075cdf0e10cSrcweir 
2076cdf0e10cSrcweir // -----------------------------------------------------------------------
2077cdf0e10cSrcweir 
2078cdf0e10cSrcweir Rectangle TabControl::GetCharacterBounds( sal_uInt16 nPageId, long nIndex ) const
2079cdf0e10cSrcweir {
2080cdf0e10cSrcweir     Rectangle aRet;
2081cdf0e10cSrcweir 
2082cdf0e10cSrcweir     if( !HasLayoutData() || ! mpTabCtrlData->maLayoutPageIdToLine.size() )
2083cdf0e10cSrcweir         FillLayoutData();
2084cdf0e10cSrcweir 
2085cdf0e10cSrcweir     if( HasLayoutData() )
2086cdf0e10cSrcweir     {
2087cdf0e10cSrcweir         std::hash_map< int, int >::const_iterator it = mpTabCtrlData->maLayoutPageIdToLine.find( (int)nPageId );
2088cdf0e10cSrcweir         if( it != mpTabCtrlData->maLayoutPageIdToLine.end() )
2089cdf0e10cSrcweir         {
2090cdf0e10cSrcweir             Pair aPair = mpControlData->mpLayoutData->GetLineStartEnd( it->second );
2091cdf0e10cSrcweir             if( (aPair.B() - aPair.A()) >= nIndex )
2092cdf0e10cSrcweir                 aRet = mpControlData->mpLayoutData->GetCharacterBounds( aPair.A() + nIndex );
2093cdf0e10cSrcweir         }
2094cdf0e10cSrcweir     }
2095cdf0e10cSrcweir 
2096cdf0e10cSrcweir     return aRet;
2097cdf0e10cSrcweir }
2098cdf0e10cSrcweir 
2099cdf0e10cSrcweir // -----------------------------------------------------------------------
2100cdf0e10cSrcweir 
2101cdf0e10cSrcweir long TabControl::GetIndexForPoint( const Point& rPoint, sal_uInt16& rPageId ) const
2102cdf0e10cSrcweir {
2103cdf0e10cSrcweir     long nRet = -1;
2104cdf0e10cSrcweir 
2105cdf0e10cSrcweir     if( !HasLayoutData() || ! mpTabCtrlData->maLayoutPageIdToLine.size() )
2106cdf0e10cSrcweir         FillLayoutData();
2107cdf0e10cSrcweir 
2108cdf0e10cSrcweir     if( HasLayoutData() )
2109cdf0e10cSrcweir     {
2110cdf0e10cSrcweir         int nIndex = mpControlData->mpLayoutData->GetIndexForPoint( rPoint );
2111cdf0e10cSrcweir         if( nIndex != -1 )
2112cdf0e10cSrcweir         {
2113cdf0e10cSrcweir             // what line (->pageid) is this index in ?
2114cdf0e10cSrcweir             int nLines = mpControlData->mpLayoutData->GetLineCount();
2115cdf0e10cSrcweir             int nLine = -1;
2116cdf0e10cSrcweir             while( ++nLine < nLines )
2117cdf0e10cSrcweir             {
2118cdf0e10cSrcweir                 Pair aPair = mpControlData->mpLayoutData->GetLineStartEnd( nLine );
2119cdf0e10cSrcweir                 if( aPair.A() <= nIndex && aPair.B() >= nIndex )
2120cdf0e10cSrcweir                 {
2121cdf0e10cSrcweir                     nRet = nIndex - aPair.A();
2122cdf0e10cSrcweir                     rPageId = (sal_uInt16)mpTabCtrlData->maLayoutLineToPageId[ nLine ];
2123cdf0e10cSrcweir                     break;
2124cdf0e10cSrcweir                 }
2125cdf0e10cSrcweir             }
2126cdf0e10cSrcweir         }
2127cdf0e10cSrcweir     }
2128cdf0e10cSrcweir 
2129cdf0e10cSrcweir     return nRet;
2130cdf0e10cSrcweir }
2131cdf0e10cSrcweir 
2132cdf0e10cSrcweir // -----------------------------------------------------------------------
2133cdf0e10cSrcweir 
2134cdf0e10cSrcweir void TabControl::FillLayoutData() const
2135cdf0e10cSrcweir {
2136cdf0e10cSrcweir     mpTabCtrlData->maLayoutLineToPageId.clear();
2137cdf0e10cSrcweir     mpTabCtrlData->maLayoutPageIdToLine.clear();
2138cdf0e10cSrcweir     const_cast<TabControl*>(this)->ImplPaint( Rectangle(), true );
2139cdf0e10cSrcweir }
2140cdf0e10cSrcweir 
2141cdf0e10cSrcweir // -----------------------------------------------------------------------
2142cdf0e10cSrcweir 
2143cdf0e10cSrcweir Rectangle TabControl::GetTabPageBounds( sal_uInt16 nPage ) const
2144cdf0e10cSrcweir {
2145cdf0e10cSrcweir     Rectangle aRet;
2146cdf0e10cSrcweir 
2147cdf0e10cSrcweir     if( !HasLayoutData() || ! mpTabCtrlData->maLayoutPageIdToLine.size() )
2148cdf0e10cSrcweir         FillLayoutData();
2149cdf0e10cSrcweir 
2150cdf0e10cSrcweir     if( HasLayoutData() )
2151cdf0e10cSrcweir     {
2152cdf0e10cSrcweir         std::hash_map< int, int >::const_iterator it = mpTabCtrlData->maLayoutPageIdToLine.find( (int)nPage );
2153cdf0e10cSrcweir         if( it != mpTabCtrlData->maLayoutPageIdToLine.end() )
2154cdf0e10cSrcweir         {
2155cdf0e10cSrcweir             if( it->second >= 0 && it->second < static_cast<int>(mpTabCtrlData->maTabRectangles.size()) )
2156cdf0e10cSrcweir             {
2157cdf0e10cSrcweir                 aRet = mpTabCtrlData->maTabRectangles[ it->second ];
2158cdf0e10cSrcweir                 aRet.Union( const_cast<TabControl*>(this)->ImplGetTabRect( TAB_PAGERECT ) );
2159cdf0e10cSrcweir             }
2160cdf0e10cSrcweir         }
2161cdf0e10cSrcweir     }
2162cdf0e10cSrcweir 
2163cdf0e10cSrcweir     return aRet;
2164cdf0e10cSrcweir }
2165cdf0e10cSrcweir 
2166cdf0e10cSrcweir // -----------------------------------------------------------------------
2167cdf0e10cSrcweir 
2168cdf0e10cSrcweir Rectangle TabControl::GetTabBounds( sal_uInt16 nPageId ) const
2169cdf0e10cSrcweir {
2170cdf0e10cSrcweir     Rectangle aRet;
2171cdf0e10cSrcweir 
2172cdf0e10cSrcweir     ImplTabItem* pItem = ImplGetItem( nPageId );
2173cdf0e10cSrcweir     if(pItem)
2174cdf0e10cSrcweir         aRet = pItem->maRect;
2175cdf0e10cSrcweir 
2176cdf0e10cSrcweir     return aRet;
2177cdf0e10cSrcweir }
2178cdf0e10cSrcweir 
2179cdf0e10cSrcweir // -----------------------------------------------------------------------
2180cdf0e10cSrcweir 
2181cdf0e10cSrcweir void TabControl::SetItemsOffset( const Point& rOffs )
2182cdf0e10cSrcweir {
2183cdf0e10cSrcweir     if( mpTabCtrlData )
2184cdf0e10cSrcweir         mpTabCtrlData->maItemsOffset = rOffs;
2185cdf0e10cSrcweir }
2186cdf0e10cSrcweir 
2187cdf0e10cSrcweir Point TabControl::GetItemsOffset() const
2188cdf0e10cSrcweir {
2189cdf0e10cSrcweir     if( mpTabCtrlData )
2190cdf0e10cSrcweir         return mpTabCtrlData->maItemsOffset;
2191cdf0e10cSrcweir     else
2192cdf0e10cSrcweir         return Point();
2193cdf0e10cSrcweir }
2194cdf0e10cSrcweir 
2195cdf0e10cSrcweir // -----------------------------------------------------------------------
2196cdf0e10cSrcweir 
2197cdf0e10cSrcweir Size TabControl::GetOptimalSize(WindowSizeType eType) const
2198cdf0e10cSrcweir {
2199cdf0e10cSrcweir     switch (eType) {
2200cdf0e10cSrcweir     case WINDOWSIZE_MINIMUM:
2201cdf0e10cSrcweir         return mpTabCtrlData ? mpTabCtrlData->maMinSize : Size();
2202cdf0e10cSrcweir     default:
2203cdf0e10cSrcweir         return Control::GetOptimalSize( eType );
2204cdf0e10cSrcweir     }
2205cdf0e10cSrcweir }
2206cdf0e10cSrcweir 
2207cdf0e10cSrcweir // -----------------------------------------------------------------------
2208cdf0e10cSrcweir 
2209cdf0e10cSrcweir void TabControl::SetMinimumSizePixel( const Size& i_rSize )
2210cdf0e10cSrcweir {
2211cdf0e10cSrcweir     if( mpTabCtrlData )
2212cdf0e10cSrcweir         mpTabCtrlData->maMinSize = i_rSize;
2213cdf0e10cSrcweir }
2214cdf0e10cSrcweir 
2215cdf0e10cSrcweir // -----------------------------------------------------------------------
2216cdf0e10cSrcweir 
2217cdf0e10cSrcweir 
2218