xref: /aoo42x/main/vcl/source/control/tabctrl.cxx (revision 9f62ea84)
1*9f62ea84SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*9f62ea84SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*9f62ea84SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*9f62ea84SAndrew Rist  * distributed with this work for additional information
6*9f62ea84SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*9f62ea84SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*9f62ea84SAndrew Rist  * "License"); you may not use this file except in compliance
9*9f62ea84SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*9f62ea84SAndrew Rist  *
11*9f62ea84SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*9f62ea84SAndrew Rist  *
13*9f62ea84SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*9f62ea84SAndrew Rist  * software distributed under the License is distributed on an
15*9f62ea84SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9f62ea84SAndrew Rist  * KIND, either express or implied.  See the License for the
17*9f62ea84SAndrew Rist  * specific language governing permissions and limitations
18*9f62ea84SAndrew Rist  * under the License.
19*9f62ea84SAndrew Rist  *
20*9f62ea84SAndrew Rist  *************************************************************/
21*9f62ea84SAndrew Rist 
22*9f62ea84SAndrew 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();
622cdf0e10cSrcweir 
623cdf0e10cSrcweir         if ( pOldPage && pOldPage->HasChildPathFocus() )
624cdf0e10cSrcweir         {
625cdf0e10cSrcweir             sal_uInt16  n = 0;
626cdf0e10cSrcweir             Window* pFirstChild = pPage->ImplGetDlgWindow( n, DLGWINDOW_FIRST );
627cdf0e10cSrcweir             if ( pFirstChild )
628cdf0e10cSrcweir                 pFirstChild->ImplControlFocus( GETFOCUS_INIT );
629cdf0e10cSrcweir             else
630cdf0e10cSrcweir                 GrabFocus();
631cdf0e10cSrcweir         }
632cdf0e10cSrcweir 
633cdf0e10cSrcweir         pPage->Show();
634cdf0e10cSrcweir     }
635cdf0e10cSrcweir 
636cdf0e10cSrcweir     if ( pOldPage )
637cdf0e10cSrcweir         pOldPage->Hide();
638cdf0e10cSrcweir 
639cdf0e10cSrcweir     // Invalidate the same region that will be send to NWF
640cdf0e10cSrcweir     // to always allow for bitmap caching
641cdf0e10cSrcweir     // see Window::DrawNativeControl()
642cdf0e10cSrcweir     if( IsNativeControlSupported( CTRL_TAB_PANE, PART_ENTIRE_CONTROL ) )
643cdf0e10cSrcweir     {
644cdf0e10cSrcweir         aRect.Left()   -= TAB_OFFSET;
645cdf0e10cSrcweir         aRect.Top()    -= TAB_OFFSET;
646cdf0e10cSrcweir         aRect.Right()  += TAB_OFFSET;
647cdf0e10cSrcweir         aRect.Bottom() += TAB_OFFSET;
648cdf0e10cSrcweir     }
649cdf0e10cSrcweir 
650cdf0e10cSrcweir     Invalidate( aRect );
651cdf0e10cSrcweir }
652cdf0e10cSrcweir 
653cdf0e10cSrcweir // -----------------------------------------------------------------------
654cdf0e10cSrcweir 
655cdf0e10cSrcweir sal_Bool TabControl::ImplPosCurTabPage()
656cdf0e10cSrcweir {
657cdf0e10cSrcweir     // Aktuelle TabPage resizen/positionieren
658cdf0e10cSrcweir     ImplTabItem* pItem = ImplGetItem( GetCurPageId() );
659cdf0e10cSrcweir     if ( pItem && pItem->mpTabPage )
660cdf0e10cSrcweir     {
661cdf0e10cSrcweir         Rectangle aRect = ImplGetTabRect( TAB_PAGERECT );
662cdf0e10cSrcweir         pItem->mpTabPage->SetPosSizePixel( aRect.TopLeft(), aRect.GetSize() );
663cdf0e10cSrcweir         return sal_True;
664cdf0e10cSrcweir     }
665cdf0e10cSrcweir 
666cdf0e10cSrcweir     return sal_False;
667cdf0e10cSrcweir }
668cdf0e10cSrcweir 
669cdf0e10cSrcweir // -----------------------------------------------------------------------
670cdf0e10cSrcweir 
671cdf0e10cSrcweir void TabControl::ImplActivateTabPage( sal_Bool bNext )
672cdf0e10cSrcweir {
673cdf0e10cSrcweir     sal_uInt16 nCurPos = GetPagePos( GetCurPageId() );
674cdf0e10cSrcweir 
675cdf0e10cSrcweir     if ( bNext )
676cdf0e10cSrcweir         nCurPos = (nCurPos + 1) % GetPageCount();
677cdf0e10cSrcweir     else
678cdf0e10cSrcweir     {
679cdf0e10cSrcweir         if ( !nCurPos )
680cdf0e10cSrcweir             nCurPos = GetPageCount()-1;
681cdf0e10cSrcweir         else
682cdf0e10cSrcweir             nCurPos--;
683cdf0e10cSrcweir     }
684cdf0e10cSrcweir 
685cdf0e10cSrcweir     SelectTabPage( GetPageId( nCurPos ) );
686cdf0e10cSrcweir }
687cdf0e10cSrcweir 
688cdf0e10cSrcweir // -----------------------------------------------------------------------
689cdf0e10cSrcweir 
690cdf0e10cSrcweir void TabControl::ImplShowFocus()
691cdf0e10cSrcweir {
692cdf0e10cSrcweir     if ( !GetPageCount() || mpTabCtrlData->mpListBox )
693cdf0e10cSrcweir         return;
694cdf0e10cSrcweir 
695cdf0e10cSrcweir     // make sure the focussed item rect is computed using a bold font
696cdf0e10cSrcweir     // the font may have changed meanwhile due to mouse over
697cdf0e10cSrcweir 
698cdf0e10cSrcweir     Font aOldFont( GetFont() );
699cdf0e10cSrcweir     Font aFont( aOldFont );
700cdf0e10cSrcweir     aFont.SetWeight( (!ImplGetSVData()->maNWFData.mbNoBoldTabFocus) ? WEIGHT_BOLD : WEIGHT_LIGHT );
701cdf0e10cSrcweir     SetFont( aFont );
702cdf0e10cSrcweir 
703cdf0e10cSrcweir     sal_uInt16                   nCurPos     = GetPagePos( mnCurPageId );
704cdf0e10cSrcweir     Rectangle                aRect       = ImplGetTabRect( nCurPos );
705cdf0e10cSrcweir     const ImplTabItem&       rItem       = mpTabCtrlData->maItemList[ nCurPos ];
706cdf0e10cSrcweir     Size                     aTabSize    = aRect.GetSize();
707cdf0e10cSrcweir     Size aImageSize( 0, 0 );
708cdf0e10cSrcweir     long                     nTextHeight = GetTextHeight();
709cdf0e10cSrcweir     long                     nTextWidth  = GetCtrlTextWidth( rItem.maFormatText );
710cdf0e10cSrcweir     sal_uInt16                   nOff;
711cdf0e10cSrcweir 
712cdf0e10cSrcweir     if ( !(GetSettings().GetStyleSettings().GetOptions() & STYLE_OPTION_MONO) )
713cdf0e10cSrcweir         nOff = 1;
714cdf0e10cSrcweir     else
715cdf0e10cSrcweir         nOff = 0;
716cdf0e10cSrcweir 
717cdf0e10cSrcweir     if( !! rItem.maTabImage )
718cdf0e10cSrcweir     {
719cdf0e10cSrcweir         aImageSize = rItem.maTabImage.GetSizePixel();
720cdf0e10cSrcweir         if( rItem.maFormatText.Len() )
721cdf0e10cSrcweir             aImageSize.Width() += GetTextHeight()/4;
722cdf0e10cSrcweir     }
723cdf0e10cSrcweir 
724cdf0e10cSrcweir     if( rItem.maFormatText.Len() )
725cdf0e10cSrcweir     {
726cdf0e10cSrcweir         // show focus around text
727cdf0e10cSrcweir         aRect.Left()   = aRect.Left()+aImageSize.Width()+((aTabSize.Width()-nTextWidth-aImageSize.Width())/2)-nOff-1-1;
728cdf0e10cSrcweir         aRect.Top()    = aRect.Top()+((aTabSize.Height()-nTextHeight)/2)-1-1;
729cdf0e10cSrcweir         aRect.Right()  = aRect.Left()+nTextWidth+2;
730cdf0e10cSrcweir         aRect.Bottom() = aRect.Top()+nTextHeight+2;
731cdf0e10cSrcweir     }
732cdf0e10cSrcweir     else
733cdf0e10cSrcweir     {
734cdf0e10cSrcweir         // show focus around image
735cdf0e10cSrcweir         long nXPos = aRect.Left()+((aTabSize.Width()-nTextWidth-aImageSize.Width())/2)-nOff-1;
736cdf0e10cSrcweir         long nYPos = aRect.Top();
737cdf0e10cSrcweir         if( aImageSize.Height() < aRect.GetHeight() )
738cdf0e10cSrcweir             nYPos += (aRect.GetHeight() - aImageSize.Height())/2;
739cdf0e10cSrcweir 
740cdf0e10cSrcweir         aRect.Left() = nXPos - 2;
741cdf0e10cSrcweir         aRect.Top() = nYPos - 2;
742cdf0e10cSrcweir         aRect.Right() = aRect.Left() + aImageSize.Width() + 4;
743cdf0e10cSrcweir         aRect.Bottom() = aRect.Top() + aImageSize.Height() + 4;
744cdf0e10cSrcweir     }
745cdf0e10cSrcweir     ShowFocus( aRect );
746cdf0e10cSrcweir 
747cdf0e10cSrcweir     SetFont( aOldFont );
748cdf0e10cSrcweir }
749cdf0e10cSrcweir 
750cdf0e10cSrcweir // -----------------------------------------------------------------------
751cdf0e10cSrcweir 
752cdf0e10cSrcweir void TabControl::ImplDrawItem( ImplTabItem* pItem, const Rectangle& rCurRect, bool bLayout, bool bFirstInGroup, bool bLastInGroup, bool bIsCurrentItem )
753cdf0e10cSrcweir {
754cdf0e10cSrcweir     if ( pItem->maRect.IsEmpty() )
755cdf0e10cSrcweir         return;
756cdf0e10cSrcweir 
757cdf0e10cSrcweir     if( bLayout )
758cdf0e10cSrcweir     {
759cdf0e10cSrcweir         if( !HasLayoutData() )
760cdf0e10cSrcweir         {
761cdf0e10cSrcweir             mpControlData->mpLayoutData = new vcl::ControlLayoutData();
762cdf0e10cSrcweir             mpTabCtrlData->maLayoutLineToPageId.clear();
763cdf0e10cSrcweir             mpTabCtrlData->maLayoutPageIdToLine.clear();
764cdf0e10cSrcweir             mpTabCtrlData->maTabRectangles.clear();
765cdf0e10cSrcweir         }
766cdf0e10cSrcweir     }
767cdf0e10cSrcweir 
768cdf0e10cSrcweir     const StyleSettings&    rStyleSettings  = GetSettings().GetStyleSettings();
769cdf0e10cSrcweir     Rectangle               aRect = pItem->maRect;
770cdf0e10cSrcweir     long                    nLeftBottom = aRect.Bottom();
771cdf0e10cSrcweir     long                    nRightBottom = aRect.Bottom();
772cdf0e10cSrcweir     sal_Bool                    bLeftBorder = sal_True;
773cdf0e10cSrcweir     sal_Bool                    bRightBorder = sal_True;
774cdf0e10cSrcweir     sal_uInt16                  nOff;
775cdf0e10cSrcweir     sal_Bool                    bNativeOK = sal_False;
776cdf0e10cSrcweir 
777cdf0e10cSrcweir     sal_uInt16 nOff2 = 0;
778cdf0e10cSrcweir     sal_uInt16 nOff3 = 0;
779cdf0e10cSrcweir 
780cdf0e10cSrcweir     if ( !(rStyleSettings.GetOptions() & STYLE_OPTION_MONO) )
781cdf0e10cSrcweir         nOff = 1;
782cdf0e10cSrcweir     else
783cdf0e10cSrcweir         nOff = 0;
784cdf0e10cSrcweir 
785cdf0e10cSrcweir     // Wenn wir die aktuelle Page sind, muessen wir etwas mehr zeichnen
786cdf0e10cSrcweir     if ( pItem->mnId == mnCurPageId )
787cdf0e10cSrcweir     {
788cdf0e10cSrcweir         nOff2 = 2;
789cdf0e10cSrcweir         if( ! ImplGetSVData()->maNWFData.mbNoActiveTabTextRaise )
790cdf0e10cSrcweir             nOff3 = 1;
791cdf0e10cSrcweir     }
792cdf0e10cSrcweir     else
793cdf0e10cSrcweir     {
794cdf0e10cSrcweir         Point aLeftTestPos = aRect.BottomLeft();
795cdf0e10cSrcweir         Point aRightTestPos = aRect.BottomRight();
796cdf0e10cSrcweir         if ( aLeftTestPos.Y() == rCurRect.Bottom() )
797cdf0e10cSrcweir         {
798cdf0e10cSrcweir             aLeftTestPos.X() -= 2;
799cdf0e10cSrcweir             if ( rCurRect.IsInside( aLeftTestPos ) )
800cdf0e10cSrcweir                 bLeftBorder = sal_False;
801cdf0e10cSrcweir             aRightTestPos.X() += 2;
802cdf0e10cSrcweir             if ( rCurRect.IsInside( aRightTestPos ) )
803cdf0e10cSrcweir                 bRightBorder = sal_False;
804cdf0e10cSrcweir         }
805cdf0e10cSrcweir         else
806cdf0e10cSrcweir         {
807cdf0e10cSrcweir             if ( rCurRect.IsInside( aLeftTestPos ) )
808cdf0e10cSrcweir                 nLeftBottom -= 2;
809cdf0e10cSrcweir             if ( rCurRect.IsInside( aRightTestPos ) )
810cdf0e10cSrcweir                 nRightBottom -= 2;
811cdf0e10cSrcweir         }
812cdf0e10cSrcweir     }
813cdf0e10cSrcweir 
814cdf0e10cSrcweir     if( !bLayout && (bNativeOK = IsNativeControlSupported(CTRL_TAB_ITEM, PART_ENTIRE_CONTROL)) == sal_True )
815cdf0e10cSrcweir     {
816cdf0e10cSrcweir         Rectangle           aCtrlRegion( pItem->maRect );
817cdf0e10cSrcweir         ControlState		nState = 0;
818cdf0e10cSrcweir 
819cdf0e10cSrcweir         if( pItem->mnId == mnCurPageId )
820cdf0e10cSrcweir         {
821cdf0e10cSrcweir             nState |= CTRL_STATE_SELECTED;
822cdf0e10cSrcweir             // only the selected item can be focussed
823cdf0e10cSrcweir             if ( HasFocus() )
824cdf0e10cSrcweir                 nState |= CTRL_STATE_FOCUSED;
825cdf0e10cSrcweir         }
826cdf0e10cSrcweir         if ( IsEnabled() )
827cdf0e10cSrcweir             nState |= CTRL_STATE_ENABLED;
828cdf0e10cSrcweir         if( IsMouseOver() && pItem->maRect.IsInside( GetPointerPosPixel() ) )
829cdf0e10cSrcweir         {
830cdf0e10cSrcweir             nState |= CTRL_STATE_ROLLOVER;
831cdf0e10cSrcweir             for( std::vector< ImplTabItem >::iterator it = mpTabCtrlData->maItemList.begin();
832cdf0e10cSrcweir                  it != mpTabCtrlData->maItemList.end(); ++it )
833cdf0e10cSrcweir             {
834cdf0e10cSrcweir                 if( (&(*it) != pItem) && (it->maRect.IsInside( GetPointerPosPixel() ) ) )
835cdf0e10cSrcweir                 {
836cdf0e10cSrcweir                     nState &= ~CTRL_STATE_ROLLOVER; // avoid multiple highlighted tabs
837cdf0e10cSrcweir                     break;
838cdf0e10cSrcweir                 }
839cdf0e10cSrcweir             }
840cdf0e10cSrcweir         }
841cdf0e10cSrcweir 
842cdf0e10cSrcweir         TabitemValue tiValue;
843cdf0e10cSrcweir         if(pItem->maRect.Left() < 5)
844cdf0e10cSrcweir             tiValue.mnAlignment |= TABITEM_LEFTALIGNED;
845cdf0e10cSrcweir         if(pItem->maRect.Right() > mnLastWidth - 5)
846cdf0e10cSrcweir             tiValue.mnAlignment |= TABITEM_RIGHTALIGNED;
847cdf0e10cSrcweir         if ( bFirstInGroup )
848cdf0e10cSrcweir             tiValue.mnAlignment |= TABITEM_FIRST_IN_GROUP;
849cdf0e10cSrcweir         if ( bLastInGroup )
850cdf0e10cSrcweir             tiValue.mnAlignment |= TABITEM_LAST_IN_GROUP;
851cdf0e10cSrcweir 
852cdf0e10cSrcweir         bNativeOK = DrawNativeControl( CTRL_TAB_ITEM, PART_ENTIRE_CONTROL, aCtrlRegion, nState,
853cdf0e10cSrcweir                     tiValue, rtl::OUString() );
854cdf0e10cSrcweir     }
855cdf0e10cSrcweir 
856cdf0e10cSrcweir     if( ! bLayout && !bNativeOK )
857cdf0e10cSrcweir     {
858cdf0e10cSrcweir         if ( !(rStyleSettings.GetOptions() & STYLE_OPTION_MONO) )
859cdf0e10cSrcweir         {
860cdf0e10cSrcweir             SetLineColor( rStyleSettings.GetLightColor() );
861cdf0e10cSrcweir             DrawPixel( Point( aRect.Left()+1-nOff2, aRect.Top()+1-nOff2 ) );    // diagonally indented top-left pixel
862cdf0e10cSrcweir             if ( bLeftBorder )
863cdf0e10cSrcweir             {
864cdf0e10cSrcweir                 DrawLine( Point( aRect.Left()-nOff2, aRect.Top()+2-nOff2 ),
865cdf0e10cSrcweir                           Point( aRect.Left()-nOff2, nLeftBottom-1 ) );
866cdf0e10cSrcweir             }
867cdf0e10cSrcweir             DrawLine( Point( aRect.Left()+2-nOff2, aRect.Top()-nOff2 ),         // top line starting 2px from left border
868cdf0e10cSrcweir                       Point( aRect.Right()+nOff2-3, aRect.Top()-nOff2 ) );      // ending 3px from right border
869cdf0e10cSrcweir 
870cdf0e10cSrcweir             if ( bRightBorder )
871cdf0e10cSrcweir             {
872cdf0e10cSrcweir                 SetLineColor( rStyleSettings.GetShadowColor() );
873cdf0e10cSrcweir                 DrawLine( Point( aRect.Right()+nOff2-2, aRect.Top()+1-nOff2 ),
874cdf0e10cSrcweir                           Point( aRect.Right()+nOff2-2, nRightBottom-1 ) );
875cdf0e10cSrcweir 
876cdf0e10cSrcweir                 SetLineColor( rStyleSettings.GetDarkShadowColor() );
877cdf0e10cSrcweir                 DrawLine( Point( aRect.Right()+nOff2-1, aRect.Top()+3-nOff2 ),
878cdf0e10cSrcweir                           Point( aRect.Right()+nOff2-1, nRightBottom-1 ) );
879cdf0e10cSrcweir             }
880cdf0e10cSrcweir         }
881cdf0e10cSrcweir         else
882cdf0e10cSrcweir         {
883cdf0e10cSrcweir             SetLineColor( Color( COL_BLACK ) );
884cdf0e10cSrcweir             DrawPixel( Point( aRect.Left()+1-nOff2, aRect.Top()+1-nOff2 ) );
885cdf0e10cSrcweir             DrawPixel( Point( aRect.Right()+nOff2-2, aRect.Top()+1-nOff2 ) );
886cdf0e10cSrcweir             if ( bLeftBorder )
887cdf0e10cSrcweir             {
888cdf0e10cSrcweir                 DrawLine( Point( aRect.Left()-nOff2, aRect.Top()+2-nOff2 ),
889cdf0e10cSrcweir                           Point( aRect.Left()-nOff2, nLeftBottom-1 ) );
890cdf0e10cSrcweir             }
891cdf0e10cSrcweir             DrawLine( Point( aRect.Left()+2-nOff2, aRect.Top()-nOff2 ),
892cdf0e10cSrcweir                       Point( aRect.Right()-3, aRect.Top()-nOff2 ) );
893cdf0e10cSrcweir             if ( bRightBorder )
894cdf0e10cSrcweir             {
895cdf0e10cSrcweir             DrawLine( Point( aRect.Right()+nOff2-1, aRect.Top()+2-nOff2 ),
896cdf0e10cSrcweir                       Point( aRect.Right()+nOff2-1, nRightBottom-1 ) );
897cdf0e10cSrcweir             }
898cdf0e10cSrcweir         }
899cdf0e10cSrcweir     }
900cdf0e10cSrcweir 
901cdf0e10cSrcweir     if( bLayout )
902cdf0e10cSrcweir     {
903cdf0e10cSrcweir         int nLine = mpControlData->mpLayoutData->m_aLineIndices.size();
904cdf0e10cSrcweir         mpControlData->mpLayoutData->m_aLineIndices.push_back( mpControlData->mpLayoutData->m_aDisplayText.Len() );
905cdf0e10cSrcweir         mpTabCtrlData->maLayoutPageIdToLine[ (int)pItem->mnId ] = nLine;
906cdf0e10cSrcweir         mpTabCtrlData->maLayoutLineToPageId[ nLine ] = (int)pItem->mnId;
907cdf0e10cSrcweir         mpTabCtrlData->maTabRectangles.push_back( aRect );
908cdf0e10cSrcweir     }
909cdf0e10cSrcweir 
910cdf0e10cSrcweir     // set font accordingly, current item is painted bold
911cdf0e10cSrcweir     // we set the font attributes always before drawing to be re-entrant (DrawNativeControl may trigger additional paints)
912cdf0e10cSrcweir     Font aFont( GetFont() );
913cdf0e10cSrcweir     aFont.SetTransparent( sal_True );
914cdf0e10cSrcweir     aFont.SetWeight( ((bIsCurrentItem) && (!ImplGetSVData()->maNWFData.mbNoBoldTabFocus)) ? WEIGHT_BOLD : WEIGHT_LIGHT );
915cdf0e10cSrcweir     SetFont( aFont );
916cdf0e10cSrcweir 
917cdf0e10cSrcweir     Size aTabSize = aRect.GetSize();
918cdf0e10cSrcweir     Size aImageSize( 0, 0 );
919cdf0e10cSrcweir     long nTextHeight = GetTextHeight();
920cdf0e10cSrcweir     long nTextWidth = GetCtrlTextWidth( pItem->maFormatText );
921cdf0e10cSrcweir     if( !! pItem->maTabImage )
922cdf0e10cSrcweir     {
923cdf0e10cSrcweir         aImageSize = pItem->maTabImage.GetSizePixel();
924cdf0e10cSrcweir         if( pItem->maFormatText.Len() )
925cdf0e10cSrcweir             aImageSize.Width() += GetTextHeight()/4;
926cdf0e10cSrcweir     }
927cdf0e10cSrcweir     long nXPos = aRect.Left()+((aTabSize.Width()-nTextWidth-aImageSize.Width())/2)-nOff-nOff3;
928cdf0e10cSrcweir     long nYPos = aRect.Top()+((aTabSize.Height()-nTextHeight)/2)-nOff3;
929cdf0e10cSrcweir     if( pItem->maFormatText.Len() )
930cdf0e10cSrcweir     {
931cdf0e10cSrcweir         sal_uInt16 nStyle = TEXT_DRAW_MNEMONIC;
932cdf0e10cSrcweir         if( ! pItem->mbEnabled )
933cdf0e10cSrcweir             nStyle |= TEXT_DRAW_DISABLE;
934cdf0e10cSrcweir         DrawCtrlText( Point( nXPos + aImageSize.Width(), nYPos ),
935cdf0e10cSrcweir                       pItem->maFormatText,
936cdf0e10cSrcweir                       0, STRING_LEN, nStyle,
937cdf0e10cSrcweir                       bLayout ? &mpControlData->mpLayoutData->m_aUnicodeBoundRects : NULL,
938cdf0e10cSrcweir                       bLayout ? &mpControlData->mpLayoutData->m_aDisplayText : NULL
939cdf0e10cSrcweir                       );
940cdf0e10cSrcweir     }
941cdf0e10cSrcweir 
942cdf0e10cSrcweir     if( !! pItem->maTabImage )
943cdf0e10cSrcweir     {
944cdf0e10cSrcweir         Point aImgTL( nXPos, aRect.Top() );
945cdf0e10cSrcweir         if( aImageSize.Height() < aRect.GetHeight() )
946cdf0e10cSrcweir             aImgTL.Y() += (aRect.GetHeight() - aImageSize.Height())/2;
947cdf0e10cSrcweir         DrawImage( aImgTL, pItem->maTabImage, pItem->mbEnabled ? 0 : IMAGE_DRAW_DISABLE );
948cdf0e10cSrcweir     }
949cdf0e10cSrcweir }
950cdf0e10cSrcweir 
951cdf0e10cSrcweir // -----------------------------------------------------------------------
952cdf0e10cSrcweir 
953cdf0e10cSrcweir long TabControl::ImplHandleKeyEvent( const KeyEvent& rKeyEvent )
954cdf0e10cSrcweir {
955cdf0e10cSrcweir     long nRet = 0;
956cdf0e10cSrcweir 
957cdf0e10cSrcweir     if ( GetPageCount() > 1 )
958cdf0e10cSrcweir     {
959cdf0e10cSrcweir         KeyCode         aKeyCode = rKeyEvent.GetKeyCode();
960cdf0e10cSrcweir         sal_uInt16          nKeyCode = aKeyCode.GetCode();
961cdf0e10cSrcweir 
962cdf0e10cSrcweir         if ( aKeyCode.IsMod1() )
963cdf0e10cSrcweir         {
964cdf0e10cSrcweir             if ( aKeyCode.IsShift() || (nKeyCode == KEY_PAGEUP) )
965cdf0e10cSrcweir             {
966cdf0e10cSrcweir                 if ( (nKeyCode == KEY_TAB) || (nKeyCode == KEY_PAGEUP) )
967cdf0e10cSrcweir                 {
968cdf0e10cSrcweir                     ImplActivateTabPage( sal_False );
969cdf0e10cSrcweir                     nRet = 1;
970cdf0e10cSrcweir                 }
971cdf0e10cSrcweir             }
972cdf0e10cSrcweir             else
973cdf0e10cSrcweir             {
974cdf0e10cSrcweir                 if ( (nKeyCode == KEY_TAB) || (nKeyCode == KEY_PAGEDOWN) )
975cdf0e10cSrcweir                 {
976cdf0e10cSrcweir                     ImplActivateTabPage( sal_True );
977cdf0e10cSrcweir                     nRet = 1;
978cdf0e10cSrcweir                 }
979cdf0e10cSrcweir             }
980cdf0e10cSrcweir         }
981cdf0e10cSrcweir     }
982cdf0e10cSrcweir 
983cdf0e10cSrcweir     return nRet;
984cdf0e10cSrcweir }
985cdf0e10cSrcweir 
986cdf0e10cSrcweir 
987cdf0e10cSrcweir // -----------------------------------------------------------------------
988cdf0e10cSrcweir 
989cdf0e10cSrcweir IMPL_LINK( TabControl, ImplListBoxSelectHdl, ListBox*, EMPTYARG )
990cdf0e10cSrcweir {
991cdf0e10cSrcweir     SelectTabPage( GetPageId( mpTabCtrlData->mpListBox->GetSelectEntryPos() ) );
992cdf0e10cSrcweir     return 0;
993cdf0e10cSrcweir }
994cdf0e10cSrcweir 
995cdf0e10cSrcweir // -----------------------------------------------------------------------
996cdf0e10cSrcweir 
997cdf0e10cSrcweir IMPL_LINK( TabControl, ImplWindowEventListener, VclSimpleEvent*, pEvent )
998cdf0e10cSrcweir {
999cdf0e10cSrcweir 	if ( pEvent && pEvent->ISA( VclWindowEvent ) && (pEvent->GetId() == VCLEVENT_WINDOW_KEYINPUT) )
1000cdf0e10cSrcweir 	{
1001cdf0e10cSrcweir 	    VclWindowEvent* pWindowEvent = static_cast< VclWindowEvent* >(pEvent);
1002cdf0e10cSrcweir 	    // Do not handle events from TabControl or it's children, which is done in Notify(), where the events can be consumed.
1003cdf0e10cSrcweir 	    if ( !IsWindowOrChild( pWindowEvent->GetWindow() ) )
1004cdf0e10cSrcweir 	    {
1005cdf0e10cSrcweir             KeyEvent* pKeyEvent = static_cast< KeyEvent* >(pWindowEvent->GetData());
1006cdf0e10cSrcweir 	        ImplHandleKeyEvent( *pKeyEvent );
1007cdf0e10cSrcweir 	    }
1008cdf0e10cSrcweir 	}
1009cdf0e10cSrcweir 	return 0;
1010cdf0e10cSrcweir }
1011cdf0e10cSrcweir 
1012cdf0e10cSrcweir 
1013cdf0e10cSrcweir // -----------------------------------------------------------------------
1014cdf0e10cSrcweir 
1015cdf0e10cSrcweir void TabControl::MouseButtonDown( const MouseEvent& rMEvt )
1016cdf0e10cSrcweir {
1017cdf0e10cSrcweir     if( mpTabCtrlData->mpListBox == NULL )
1018cdf0e10cSrcweir     {
1019cdf0e10cSrcweir         if( rMEvt.IsLeft() )
1020cdf0e10cSrcweir         {
1021cdf0e10cSrcweir             sal_uInt16 nPageId = GetPageId( rMEvt.GetPosPixel() );
1022cdf0e10cSrcweir             ImplTabItem* pItem = ImplGetItem( nPageId );
1023cdf0e10cSrcweir             if( pItem && pItem->mbEnabled )
1024cdf0e10cSrcweir                 SelectTabPage( nPageId );
1025cdf0e10cSrcweir         }
1026cdf0e10cSrcweir     }
1027cdf0e10cSrcweir }
1028cdf0e10cSrcweir 
1029cdf0e10cSrcweir // -----------------------------------------------------------------------
1030cdf0e10cSrcweir 
1031cdf0e10cSrcweir void TabControl::KeyInput( const KeyEvent& rKEvt )
1032cdf0e10cSrcweir {
1033cdf0e10cSrcweir     if( mpTabCtrlData->mpListBox )
1034cdf0e10cSrcweir         mpTabCtrlData->mpListBox->KeyInput( rKEvt );
1035cdf0e10cSrcweir     else if ( GetPageCount() > 1 )
1036cdf0e10cSrcweir     {
1037cdf0e10cSrcweir         KeyCode aKeyCode = rKEvt.GetKeyCode();
1038cdf0e10cSrcweir         sal_uInt16  nKeyCode = aKeyCode.GetCode();
1039cdf0e10cSrcweir 
1040cdf0e10cSrcweir         if ( (nKeyCode == KEY_LEFT) || (nKeyCode == KEY_RIGHT) )
1041cdf0e10cSrcweir         {
1042cdf0e10cSrcweir             sal_Bool bNext = (nKeyCode == KEY_RIGHT);
1043cdf0e10cSrcweir             ImplActivateTabPage( bNext );
1044cdf0e10cSrcweir         }
1045cdf0e10cSrcweir     }
1046cdf0e10cSrcweir 
1047cdf0e10cSrcweir     Control::KeyInput( rKEvt );
1048cdf0e10cSrcweir }
1049cdf0e10cSrcweir 
1050cdf0e10cSrcweir // -----------------------------------------------------------------------
1051cdf0e10cSrcweir 
1052cdf0e10cSrcweir void TabControl::Paint( const Rectangle& rRect )
1053cdf0e10cSrcweir {
1054cdf0e10cSrcweir     ImplPaint( rRect, false );
1055cdf0e10cSrcweir }
1056cdf0e10cSrcweir 
1057cdf0e10cSrcweir // -----------------------------------------------------------------------
1058cdf0e10cSrcweir 
1059cdf0e10cSrcweir void TabControl::ImplPaint( const Rectangle& rRect, bool bLayout )
1060cdf0e10cSrcweir {
1061cdf0e10cSrcweir     if( ! bLayout )
1062cdf0e10cSrcweir         HideFocus();
1063cdf0e10cSrcweir 
1064cdf0e10cSrcweir     // Hier wird gegebenenfalls auch neu formatiert
1065cdf0e10cSrcweir     Rectangle aRect = ImplGetTabRect( TAB_PAGERECT );
1066cdf0e10cSrcweir 
1067cdf0e10cSrcweir     // find current item
1068cdf0e10cSrcweir     ImplTabItem* pCurItem = NULL;
1069cdf0e10cSrcweir     for( std::vector< ImplTabItem >::iterator it = mpTabCtrlData->maItemList.begin();
1070cdf0e10cSrcweir          it != mpTabCtrlData->maItemList.end(); ++it )
1071cdf0e10cSrcweir     {
1072cdf0e10cSrcweir         if ( it->mnId == mnCurPageId )
1073cdf0e10cSrcweir         {
1074cdf0e10cSrcweir             pCurItem = &(*it);
1075cdf0e10cSrcweir             break;
1076cdf0e10cSrcweir         }
1077cdf0e10cSrcweir     }
1078cdf0e10cSrcweir 
1079cdf0e10cSrcweir     // Draw the TabPage border
1080cdf0e10cSrcweir     const StyleSettings&    rStyleSettings  = GetSettings().GetStyleSettings();
1081cdf0e10cSrcweir     Rectangle               aCurRect;
1082cdf0e10cSrcweir     long                    nTopOff = 1;
1083cdf0e10cSrcweir     aRect.Left()   -= TAB_OFFSET;
1084cdf0e10cSrcweir     aRect.Top()    -= TAB_OFFSET;
1085cdf0e10cSrcweir     aRect.Right()  += TAB_OFFSET;
1086cdf0e10cSrcweir     aRect.Bottom() += TAB_OFFSET;
1087cdf0e10cSrcweir 
1088cdf0e10cSrcweir     // if we have an invisible tabpage or no tabpage at all the tabpage rect should be
1089cdf0e10cSrcweir     // increased to avoid round corners that might be drawn by a theme
1090cdf0e10cSrcweir     // in this case we're only interested in the top border of the tabpage because the tabitems are used
1091cdf0e10cSrcweir     // standalone (eg impress)
1092cdf0e10cSrcweir     sal_Bool bNoTabPage = sal_False;
1093cdf0e10cSrcweir     TabPage*        pCurPage = (pCurItem) ? pCurItem->mpTabPage : NULL;
1094cdf0e10cSrcweir     if( !pCurPage || !pCurPage->IsVisible() )
1095cdf0e10cSrcweir     {
1096cdf0e10cSrcweir         bNoTabPage = sal_True;
1097cdf0e10cSrcweir         aRect.Left()-=10;
1098cdf0e10cSrcweir         aRect.Right()+=10;
1099cdf0e10cSrcweir     }
1100cdf0e10cSrcweir 
1101cdf0e10cSrcweir     sal_Bool bNativeOK = sal_False;
1102cdf0e10cSrcweir     if( ! bLayout && (bNativeOK = IsNativeControlSupported( CTRL_TAB_PANE, PART_ENTIRE_CONTROL) ) == sal_True )
1103cdf0e10cSrcweir     {
1104cdf0e10cSrcweir         const ImplControlValue aControlValue;
1105cdf0e10cSrcweir 
1106cdf0e10cSrcweir         ControlState nState = CTRL_STATE_ENABLED;
1107cdf0e10cSrcweir         int part = PART_ENTIRE_CONTROL;
1108cdf0e10cSrcweir         if ( !IsEnabled() )
1109cdf0e10cSrcweir             nState &= ~CTRL_STATE_ENABLED;
1110cdf0e10cSrcweir         if ( HasFocus() )
1111cdf0e10cSrcweir             nState |= CTRL_STATE_FOCUSED;
1112cdf0e10cSrcweir 
1113cdf0e10cSrcweir         Region aClipRgn( GetActiveClipRegion() );
1114cdf0e10cSrcweir         aClipRgn.Intersect( aRect );
1115cdf0e10cSrcweir         if( !rRect.IsEmpty() )
1116cdf0e10cSrcweir             aClipRgn.Intersect( rRect );
1117cdf0e10cSrcweir 
1118cdf0e10cSrcweir         if( !aClipRgn.IsEmpty() )
1119cdf0e10cSrcweir             bNativeOK = DrawNativeControl( CTRL_TAB_PANE, part, aRect, nState,
1120cdf0e10cSrcweir                 aControlValue, rtl::OUString() );
1121cdf0e10cSrcweir     }
1122cdf0e10cSrcweir     else
1123cdf0e10cSrcweir     {
1124cdf0e10cSrcweir         if ( !(rStyleSettings.GetOptions() & STYLE_OPTION_MONO) )
1125cdf0e10cSrcweir             SetLineColor( rStyleSettings.GetLightColor() );
1126cdf0e10cSrcweir         else
1127cdf0e10cSrcweir             SetLineColor( Color( COL_BLACK ) );
1128cdf0e10cSrcweir         if ( pCurItem && !pCurItem->maRect.IsEmpty() )
1129cdf0e10cSrcweir         {
1130cdf0e10cSrcweir             aCurRect = pCurItem->maRect;
1131cdf0e10cSrcweir             if( ! bLayout )
1132cdf0e10cSrcweir                 DrawLine( aRect.TopLeft(), Point( aCurRect.Left()-2, aRect.Top() ) );
1133cdf0e10cSrcweir             if ( aCurRect.Right()+1 < aRect.Right() )
1134cdf0e10cSrcweir             {
1135cdf0e10cSrcweir                 if( ! bLayout )
1136cdf0e10cSrcweir                     DrawLine( Point( aCurRect.Right(), aRect.Top() ), aRect.TopRight() );
1137cdf0e10cSrcweir             }
1138cdf0e10cSrcweir             else
1139cdf0e10cSrcweir                 nTopOff = 0;
1140cdf0e10cSrcweir         }
1141cdf0e10cSrcweir         else
1142cdf0e10cSrcweir             if( ! bLayout )
1143cdf0e10cSrcweir                 DrawLine( aRect.TopLeft(), aRect.TopRight() );
1144cdf0e10cSrcweir 
1145cdf0e10cSrcweir         if( ! bLayout )
1146cdf0e10cSrcweir         {
1147cdf0e10cSrcweir             DrawLine( aRect.TopLeft(), aRect.BottomLeft() );
1148cdf0e10cSrcweir 
1149cdf0e10cSrcweir             if ( !(rStyleSettings.GetOptions() & STYLE_OPTION_MONO) )
1150cdf0e10cSrcweir             {
1151cdf0e10cSrcweir                 // if we have not tab page the bottom line of the tab page
1152cdf0e10cSrcweir                 // directly touches the tab items, so choose a color that fits seamlessly
1153cdf0e10cSrcweir                 if( bNoTabPage )
1154cdf0e10cSrcweir                     SetLineColor( rStyleSettings.GetDialogColor() );
1155cdf0e10cSrcweir                 else
1156cdf0e10cSrcweir                     SetLineColor( rStyleSettings.GetShadowColor() );
1157cdf0e10cSrcweir                 DrawLine( Point( 1, aRect.Bottom()-1 ),
1158cdf0e10cSrcweir                         Point( aRect.Right()-1, aRect.Bottom()-1 ) );
1159cdf0e10cSrcweir                 DrawLine( Point( aRect.Right()-1, aRect.Top()+nTopOff ),
1160cdf0e10cSrcweir                         Point( aRect.Right()-1, aRect.Bottom()-1 ) );
1161cdf0e10cSrcweir                 if( bNoTabPage )
1162cdf0e10cSrcweir                     SetLineColor( rStyleSettings.GetDialogColor() );
1163cdf0e10cSrcweir                 else
1164cdf0e10cSrcweir                     SetLineColor( rStyleSettings.GetDarkShadowColor() );
1165cdf0e10cSrcweir                 DrawLine( Point( 0, aRect.Bottom() ),
1166cdf0e10cSrcweir                         Point( aRect.Right(), aRect.Bottom() ) );
1167cdf0e10cSrcweir                 DrawLine( Point( aRect.Right(), aRect.Top()+nTopOff ),
1168cdf0e10cSrcweir                         Point( aRect.Right(), aRect.Bottom() ) );
1169cdf0e10cSrcweir             }
1170cdf0e10cSrcweir             else
1171cdf0e10cSrcweir             {
1172cdf0e10cSrcweir                 DrawLine( aRect.TopRight(), aRect.BottomRight() );
1173cdf0e10cSrcweir                 DrawLine( aRect.BottomLeft(), aRect.BottomRight() );
1174cdf0e10cSrcweir             }
1175cdf0e10cSrcweir         }
1176cdf0e10cSrcweir     }
1177cdf0e10cSrcweir 
1178cdf0e10cSrcweir     if ( !mpTabCtrlData->maItemList.empty() && mpTabCtrlData->mpListBox == NULL )
1179cdf0e10cSrcweir     {
1180cdf0e10cSrcweir         // Some native toolkits (GTK+) draw tabs right-to-left, with an
1181cdf0e10cSrcweir         // overlap between adjacent tabs
1182cdf0e10cSrcweir         bool			bDrawTabsRTL = IsNativeControlSupported( CTRL_TAB_ITEM, PART_TABS_DRAW_RTL );
1183cdf0e10cSrcweir         ImplTabItem *	pFirstTab = NULL;
1184cdf0e10cSrcweir         ImplTabItem *	pLastTab = NULL;
1185cdf0e10cSrcweir         size_t idx;
1186cdf0e10cSrcweir 
1187cdf0e10cSrcweir         // Event though there is a tab overlap with GTK+, the first tab is not
1188cdf0e10cSrcweir         // overlapped on the left side.  Other tookits ignore this option.
1189cdf0e10cSrcweir         if ( bDrawTabsRTL )
1190cdf0e10cSrcweir         {
1191cdf0e10cSrcweir             pFirstTab = &mpTabCtrlData->maItemList.front();
1192cdf0e10cSrcweir             pLastTab = &mpTabCtrlData->maItemList.back();
1193cdf0e10cSrcweir             idx = mpTabCtrlData->maItemList.size()-1;
1194cdf0e10cSrcweir         }
1195cdf0e10cSrcweir         else
1196cdf0e10cSrcweir         {
1197cdf0e10cSrcweir             pLastTab = &mpTabCtrlData->maItemList.back();
1198cdf0e10cSrcweir             pFirstTab = &mpTabCtrlData->maItemList.front();
1199cdf0e10cSrcweir             idx = 0;
1200cdf0e10cSrcweir         }
1201cdf0e10cSrcweir 
1202cdf0e10cSrcweir         while ( idx < mpTabCtrlData->maItemList.size() )
1203cdf0e10cSrcweir         {
1204cdf0e10cSrcweir             ImplTabItem* pItem = &mpTabCtrlData->maItemList[idx];
1205cdf0e10cSrcweir             if ( pItem != pCurItem )
1206cdf0e10cSrcweir             {
1207cdf0e10cSrcweir                 Region aClipRgn( GetActiveClipRegion() );
1208cdf0e10cSrcweir                 aClipRgn.Intersect( pItem->maRect );
1209cdf0e10cSrcweir                 if( !rRect.IsEmpty() )
1210cdf0e10cSrcweir                     aClipRgn.Intersect( rRect );
1211cdf0e10cSrcweir                 if( bLayout || !aClipRgn.IsEmpty() )
1212cdf0e10cSrcweir                     ImplDrawItem( pItem, aCurRect, bLayout, (pItem==pFirstTab), (pItem==pLastTab), sal_False );
1213cdf0e10cSrcweir             }
1214cdf0e10cSrcweir 
1215cdf0e10cSrcweir             if ( bDrawTabsRTL )
1216cdf0e10cSrcweir                 idx--;
1217cdf0e10cSrcweir             else
1218cdf0e10cSrcweir                 idx++;
1219cdf0e10cSrcweir         }
1220cdf0e10cSrcweir 
1221cdf0e10cSrcweir         if ( pCurItem )
1222cdf0e10cSrcweir         {
1223cdf0e10cSrcweir             Region aClipRgn( GetActiveClipRegion() );
1224cdf0e10cSrcweir             aClipRgn.Intersect( pCurItem->maRect );
1225cdf0e10cSrcweir             if( !rRect.IsEmpty() )
1226cdf0e10cSrcweir                 aClipRgn.Intersect( rRect );
1227cdf0e10cSrcweir             if( bLayout || !aClipRgn.IsEmpty() )
1228cdf0e10cSrcweir                 ImplDrawItem( pCurItem, aCurRect, bLayout, (pCurItem==pFirstTab), (pCurItem==pLastTab), sal_True );
1229cdf0e10cSrcweir         }
1230cdf0e10cSrcweir     }
1231cdf0e10cSrcweir 
1232cdf0e10cSrcweir     if ( !bLayout && HasFocus() )
1233cdf0e10cSrcweir         ImplShowFocus();
1234cdf0e10cSrcweir 
1235cdf0e10cSrcweir     if( ! bLayout )
1236cdf0e10cSrcweir         mbSmallInvalidate = sal_True;
1237cdf0e10cSrcweir }
1238cdf0e10cSrcweir 
1239cdf0e10cSrcweir // -----------------------------------------------------------------------
1240cdf0e10cSrcweir 
1241cdf0e10cSrcweir void TabControl::Resize()
1242cdf0e10cSrcweir {
1243cdf0e10cSrcweir     ImplFreeLayoutData();
1244cdf0e10cSrcweir 
1245cdf0e10cSrcweir     if ( !IsReallyShown() )
1246cdf0e10cSrcweir         return;
1247cdf0e10cSrcweir 
1248cdf0e10cSrcweir     if( mpTabCtrlData->mpListBox )
1249cdf0e10cSrcweir     {
1250cdf0e10cSrcweir         // get the listbox' preferred size
1251cdf0e10cSrcweir         Size aTabCtrlSize( GetSizePixel() );
1252cdf0e10cSrcweir         long nPrefWidth = mpTabCtrlData->mpListBox->GetOptimalSize( WINDOWSIZE_PREFERRED ).Width();
1253cdf0e10cSrcweir         if( nPrefWidth > aTabCtrlSize.Width() )
1254cdf0e10cSrcweir             nPrefWidth = aTabCtrlSize.Width();
1255cdf0e10cSrcweir         Size aNewSize( nPrefWidth, LogicToPixel( Size( 12, 12 ), MapMode( MAP_APPFONT ) ).Height() );
1256cdf0e10cSrcweir         Point aNewPos( (aTabCtrlSize.Width() - nPrefWidth) / 2, 0 );
1257cdf0e10cSrcweir         mpTabCtrlData->mpListBox->SetPosSizePixel( aNewPos, aNewSize );
1258cdf0e10cSrcweir     }
1259cdf0e10cSrcweir 
1260cdf0e10cSrcweir     mbFormat = sal_True;
1261cdf0e10cSrcweir 
1262cdf0e10cSrcweir     // Aktuelle TabPage resizen/positionieren
1263cdf0e10cSrcweir     sal_Bool bTabPage = ImplPosCurTabPage();
1264cdf0e10cSrcweir     // Feststellen, was invalidiert werden muss
1265cdf0e10cSrcweir     Size aNewSize = Control::GetOutputSizePixel();
1266cdf0e10cSrcweir     long nNewWidth = aNewSize.Width();
1267cdf0e10cSrcweir     for( std::vector< ImplTabItem >::iterator it = mpTabCtrlData->maItemList.begin();
1268cdf0e10cSrcweir          it != mpTabCtrlData->maItemList.end(); ++it )
1269cdf0e10cSrcweir     {
1270cdf0e10cSrcweir         if ( !it->mbFullVisible ||
1271cdf0e10cSrcweir              (it->maRect.Right()-2 >= nNewWidth) )
1272cdf0e10cSrcweir         {
1273cdf0e10cSrcweir             mbSmallInvalidate = sal_False;
1274cdf0e10cSrcweir             break;
1275cdf0e10cSrcweir         }
1276cdf0e10cSrcweir     }
1277cdf0e10cSrcweir 
1278cdf0e10cSrcweir     if ( mbSmallInvalidate )
1279cdf0e10cSrcweir     {
1280cdf0e10cSrcweir         Rectangle aRect = ImplGetTabRect( TAB_PAGERECT );
1281cdf0e10cSrcweir         aRect.Left()   -= TAB_OFFSET+TAB_BORDER_LEFT;
1282cdf0e10cSrcweir         aRect.Top()    -= TAB_OFFSET+TAB_BORDER_TOP;
1283cdf0e10cSrcweir         aRect.Right()  += TAB_OFFSET+TAB_BORDER_RIGHT;
1284cdf0e10cSrcweir         aRect.Bottom() += TAB_OFFSET+TAB_BORDER_BOTTOM;
1285cdf0e10cSrcweir         if ( bTabPage )
1286cdf0e10cSrcweir             Invalidate( aRect, INVALIDATE_NOCHILDREN );
1287cdf0e10cSrcweir         else
1288cdf0e10cSrcweir             Invalidate( aRect );
1289cdf0e10cSrcweir 
1290cdf0e10cSrcweir     }
1291cdf0e10cSrcweir     else
1292cdf0e10cSrcweir     {
1293cdf0e10cSrcweir         if ( bTabPage )
1294cdf0e10cSrcweir             Invalidate( INVALIDATE_NOCHILDREN );
1295cdf0e10cSrcweir         else
1296cdf0e10cSrcweir             Invalidate();
1297cdf0e10cSrcweir     }
1298cdf0e10cSrcweir }
1299cdf0e10cSrcweir 
1300cdf0e10cSrcweir // -----------------------------------------------------------------------
1301cdf0e10cSrcweir 
1302cdf0e10cSrcweir void TabControl::GetFocus()
1303cdf0e10cSrcweir {
1304cdf0e10cSrcweir     if( ! mpTabCtrlData->mpListBox )
1305cdf0e10cSrcweir     {
1306cdf0e10cSrcweir         ImplShowFocus();
1307cdf0e10cSrcweir         SetInputContext( InputContext( GetFont() ) );
1308cdf0e10cSrcweir     }
1309cdf0e10cSrcweir     else
1310cdf0e10cSrcweir     {
1311cdf0e10cSrcweir         if( mpTabCtrlData->mpListBox->IsReallyVisible() )
1312cdf0e10cSrcweir             mpTabCtrlData->mpListBox->GrabFocus();
1313cdf0e10cSrcweir     }
1314cdf0e10cSrcweir     Control::GetFocus();
1315cdf0e10cSrcweir }
1316cdf0e10cSrcweir 
1317cdf0e10cSrcweir // -----------------------------------------------------------------------
1318cdf0e10cSrcweir 
1319cdf0e10cSrcweir void TabControl::LoseFocus()
1320cdf0e10cSrcweir {
1321cdf0e10cSrcweir     if( ! mpTabCtrlData->mpListBox )
1322cdf0e10cSrcweir         HideFocus();
1323cdf0e10cSrcweir     Control::LoseFocus();
1324cdf0e10cSrcweir }
1325cdf0e10cSrcweir 
1326cdf0e10cSrcweir // -----------------------------------------------------------------------
1327cdf0e10cSrcweir 
1328cdf0e10cSrcweir void TabControl::RequestHelp( const HelpEvent& rHEvt )
1329cdf0e10cSrcweir {
1330cdf0e10cSrcweir     sal_uInt16 nItemId = rHEvt.KeyboardActivated() ? mnCurPageId : GetPageId( ScreenToOutputPixel( rHEvt.GetMousePosPixel() ) );
1331cdf0e10cSrcweir 
1332cdf0e10cSrcweir     if ( nItemId )
1333cdf0e10cSrcweir     {
1334cdf0e10cSrcweir         if ( rHEvt.GetMode() & HELPMODE_BALLOON )
1335cdf0e10cSrcweir         {
1336cdf0e10cSrcweir             XubString aStr = GetHelpText( nItemId );
1337cdf0e10cSrcweir             if ( aStr.Len() )
1338cdf0e10cSrcweir             {
1339cdf0e10cSrcweir                 Rectangle aItemRect = ImplGetTabRect( GetPagePos( nItemId ) );
1340cdf0e10cSrcweir                 Point aPt = OutputToScreenPixel( aItemRect.TopLeft() );
1341cdf0e10cSrcweir                 aItemRect.Left()   = aPt.X();
1342cdf0e10cSrcweir                 aItemRect.Top()    = aPt.Y();
1343cdf0e10cSrcweir                 aPt = OutputToScreenPixel( aItemRect.BottomRight() );
1344cdf0e10cSrcweir                 aItemRect.Right()  = aPt.X();
1345cdf0e10cSrcweir                 aItemRect.Bottom() = aPt.Y();
1346cdf0e10cSrcweir                 Help::ShowBalloon( this, aItemRect.Center(), aItemRect, aStr );
1347cdf0e10cSrcweir                 return;
1348cdf0e10cSrcweir             }
1349cdf0e10cSrcweir         }
1350cdf0e10cSrcweir         else if ( rHEvt.GetMode() & HELPMODE_EXTENDED )
1351cdf0e10cSrcweir         {
1352cdf0e10cSrcweir             rtl::OUString aHelpId( rtl::OStringToOUString( GetHelpId( nItemId ), RTL_TEXTENCODING_UTF8 ) );
1353cdf0e10cSrcweir             if ( aHelpId.getLength() )
1354cdf0e10cSrcweir             {
1355cdf0e10cSrcweir                 // Wenn eine Hilfe existiert, dann ausloesen
1356cdf0e10cSrcweir                 Help* pHelp = Application::GetHelp();
1357cdf0e10cSrcweir                 if ( pHelp )
1358cdf0e10cSrcweir                     pHelp->Start( aHelpId, this );
1359cdf0e10cSrcweir                 return;
1360cdf0e10cSrcweir             }
1361cdf0e10cSrcweir         }
1362cdf0e10cSrcweir 
1363cdf0e10cSrcweir         // Bei Quick- oder Balloon-Help zeigen wir den Text an,
1364cdf0e10cSrcweir         // wenn dieser abgeschnitten ist
1365cdf0e10cSrcweir         if ( rHEvt.GetMode() & (HELPMODE_QUICK | HELPMODE_BALLOON) )
1366cdf0e10cSrcweir         {
1367cdf0e10cSrcweir             ImplTabItem* pItem = ImplGetItem( nItemId );
1368cdf0e10cSrcweir             const XubString& rStr = pItem->maText;
1369cdf0e10cSrcweir             if ( rStr != pItem->maFormatText )
1370cdf0e10cSrcweir             {
1371cdf0e10cSrcweir                 Rectangle aItemRect = ImplGetTabRect( GetPagePos( nItemId ) );
1372cdf0e10cSrcweir                 Point aPt = OutputToScreenPixel( aItemRect.TopLeft() );
1373cdf0e10cSrcweir                 aItemRect.Left()   = aPt.X();
1374cdf0e10cSrcweir                 aItemRect.Top()    = aPt.Y();
1375cdf0e10cSrcweir                 aPt = OutputToScreenPixel( aItemRect.BottomRight() );
1376cdf0e10cSrcweir                 aItemRect.Right()  = aPt.X();
1377cdf0e10cSrcweir                 aItemRect.Bottom() = aPt.Y();
1378cdf0e10cSrcweir                 if ( rStr.Len() )
1379cdf0e10cSrcweir                 {
1380cdf0e10cSrcweir                     if ( rHEvt.GetMode() & HELPMODE_BALLOON )
1381cdf0e10cSrcweir                         Help::ShowBalloon( this, aItemRect.Center(), aItemRect, rStr );
1382cdf0e10cSrcweir                     else
1383cdf0e10cSrcweir                         Help::ShowQuickHelp( this, aItemRect, rStr );
1384cdf0e10cSrcweir                     return;
1385cdf0e10cSrcweir                 }
1386cdf0e10cSrcweir             }
1387cdf0e10cSrcweir         }
1388cdf0e10cSrcweir 
1389cdf0e10cSrcweir         if ( rHEvt.GetMode() & HELPMODE_QUICK )
1390cdf0e10cSrcweir         {
1391cdf0e10cSrcweir             ImplTabItem* pItem = ImplGetItem( nItemId );
1392cdf0e10cSrcweir             const XubString& rHelpText = pItem->maHelpText;
1393cdf0e10cSrcweir             // show tooltip if not text but image is set and helptext is available
1394cdf0e10cSrcweir             if ( rHelpText.Len() > 0 && pItem->maText.Len() == 0 && !!pItem->maTabImage )
1395cdf0e10cSrcweir             {
1396cdf0e10cSrcweir                 Rectangle aItemRect = ImplGetTabRect( GetPagePos( nItemId ) );
1397cdf0e10cSrcweir                 Point aPt = OutputToScreenPixel( aItemRect.TopLeft() );
1398cdf0e10cSrcweir                 aItemRect.Left()   = aPt.X();
1399cdf0e10cSrcweir                 aItemRect.Top()    = aPt.Y();
1400cdf0e10cSrcweir                 aPt = OutputToScreenPixel( aItemRect.BottomRight() );
1401cdf0e10cSrcweir                 aItemRect.Right()  = aPt.X();
1402cdf0e10cSrcweir                 aItemRect.Bottom() = aPt.Y();
1403cdf0e10cSrcweir                 Help::ShowQuickHelp( this, aItemRect, rHelpText );
1404cdf0e10cSrcweir                 return;
1405cdf0e10cSrcweir             }
1406cdf0e10cSrcweir         }
1407cdf0e10cSrcweir     }
1408cdf0e10cSrcweir 
1409cdf0e10cSrcweir     Control::RequestHelp( rHEvt );
1410cdf0e10cSrcweir }
1411cdf0e10cSrcweir 
1412cdf0e10cSrcweir // -----------------------------------------------------------------------
1413cdf0e10cSrcweir 
1414cdf0e10cSrcweir void TabControl::Command( const CommandEvent& rCEvt )
1415cdf0e10cSrcweir {
1416cdf0e10cSrcweir     if( (mpTabCtrlData->mpListBox == NULL) && (rCEvt.GetCommand() == COMMAND_CONTEXTMENU) && (GetPageCount() > 1) )
1417cdf0e10cSrcweir     {
1418cdf0e10cSrcweir         Point   aMenuPos;
1419cdf0e10cSrcweir         sal_Bool    bMenu;
1420cdf0e10cSrcweir         if ( rCEvt.IsMouseEvent() )
1421cdf0e10cSrcweir         {
1422cdf0e10cSrcweir             aMenuPos = rCEvt.GetMousePosPixel();
1423cdf0e10cSrcweir             bMenu = GetPageId( aMenuPos ) != 0;
1424cdf0e10cSrcweir         }
1425cdf0e10cSrcweir         else
1426cdf0e10cSrcweir         {
1427cdf0e10cSrcweir             aMenuPos = ImplGetTabRect( GetPagePos( mnCurPageId ) ).Center();
1428cdf0e10cSrcweir             bMenu = sal_True;
1429cdf0e10cSrcweir         }
1430cdf0e10cSrcweir 
1431cdf0e10cSrcweir         if ( bMenu )
1432cdf0e10cSrcweir         {
1433cdf0e10cSrcweir             PopupMenu aMenu;
1434cdf0e10cSrcweir             for( std::vector< ImplTabItem >::iterator it = mpTabCtrlData->maItemList.begin();
1435cdf0e10cSrcweir                  it != mpTabCtrlData->maItemList.end(); ++it )
1436cdf0e10cSrcweir             {
1437cdf0e10cSrcweir                 aMenu.InsertItem( it->mnId, it->maText, MIB_CHECKABLE | MIB_RADIOCHECK );
1438cdf0e10cSrcweir                 if ( it->mnId == mnCurPageId )
1439cdf0e10cSrcweir                     aMenu.CheckItem( it->mnId );
1440cdf0e10cSrcweir                 aMenu.SetHelpId( it->mnId, it->maHelpId );
1441cdf0e10cSrcweir             }
1442cdf0e10cSrcweir 
1443cdf0e10cSrcweir             sal_uInt16 nId = aMenu.Execute( this, aMenuPos );
1444cdf0e10cSrcweir             if ( nId && (nId != mnCurPageId) )
1445cdf0e10cSrcweir                 SelectTabPage( nId );
1446cdf0e10cSrcweir             return;
1447cdf0e10cSrcweir         }
1448cdf0e10cSrcweir     }
1449cdf0e10cSrcweir 
1450cdf0e10cSrcweir     Control::Command( rCEvt );
1451cdf0e10cSrcweir }
1452cdf0e10cSrcweir 
1453cdf0e10cSrcweir // -----------------------------------------------------------------------
1454cdf0e10cSrcweir 
1455cdf0e10cSrcweir void TabControl::StateChanged( StateChangedType nType )
1456cdf0e10cSrcweir {
1457cdf0e10cSrcweir     Control::StateChanged( nType );
1458cdf0e10cSrcweir 
1459cdf0e10cSrcweir     if ( nType == STATE_CHANGE_INITSHOW )
1460cdf0e10cSrcweir     {
1461cdf0e10cSrcweir         ImplPosCurTabPage();
1462cdf0e10cSrcweir         if( mpTabCtrlData->mpListBox )
1463cdf0e10cSrcweir             Resize();
1464cdf0e10cSrcweir     }
1465cdf0e10cSrcweir     else if ( nType == STATE_CHANGE_UPDATEMODE )
1466cdf0e10cSrcweir     {
1467cdf0e10cSrcweir         if ( IsUpdateMode() )
1468cdf0e10cSrcweir             Invalidate();
1469cdf0e10cSrcweir     }
1470cdf0e10cSrcweir     else if ( (nType == STATE_CHANGE_ZOOM)  ||
1471cdf0e10cSrcweir               (nType == STATE_CHANGE_CONTROLFONT) )
1472cdf0e10cSrcweir     {
1473cdf0e10cSrcweir         ImplInitSettings( sal_True, sal_False, sal_False );
1474cdf0e10cSrcweir         Invalidate();
1475cdf0e10cSrcweir     }
1476cdf0e10cSrcweir     else if ( nType == STATE_CHANGE_CONTROLFOREGROUND )
1477cdf0e10cSrcweir     {
1478cdf0e10cSrcweir         ImplInitSettings( sal_False, sal_True, sal_False );
1479cdf0e10cSrcweir         Invalidate();
1480cdf0e10cSrcweir     }
1481cdf0e10cSrcweir     else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
1482cdf0e10cSrcweir     {
1483cdf0e10cSrcweir         ImplInitSettings( sal_False, sal_False, sal_True );
1484cdf0e10cSrcweir         Invalidate();
1485cdf0e10cSrcweir     }
1486cdf0e10cSrcweir }
1487cdf0e10cSrcweir 
1488cdf0e10cSrcweir // -----------------------------------------------------------------------
1489cdf0e10cSrcweir 
1490cdf0e10cSrcweir void TabControl::DataChanged( const DataChangedEvent& rDCEvt )
1491cdf0e10cSrcweir {
1492cdf0e10cSrcweir     Control::DataChanged( rDCEvt );
1493cdf0e10cSrcweir 
1494cdf0e10cSrcweir     if ( (rDCEvt.GetType() == DATACHANGED_FONTS) ||
1495cdf0e10cSrcweir          (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) ||
1496cdf0e10cSrcweir          ((rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
1497cdf0e10cSrcweir           (rDCEvt.GetFlags() & SETTINGS_STYLE)) )
1498cdf0e10cSrcweir     {
1499cdf0e10cSrcweir         ImplInitSettings( sal_True, sal_True, sal_True );
1500cdf0e10cSrcweir         Invalidate();
1501cdf0e10cSrcweir     }
1502cdf0e10cSrcweir }
1503cdf0e10cSrcweir 
1504cdf0e10cSrcweir // -----------------------------------------------------------------------
1505cdf0e10cSrcweir 
1506cdf0e10cSrcweir Rectangle* TabControl::ImplFindPartRect( const Point& rPt )
1507cdf0e10cSrcweir {
1508cdf0e10cSrcweir     ImplTabItem* pFoundItem = NULL;
1509cdf0e10cSrcweir     int nFound = 0;
1510cdf0e10cSrcweir     for( std::vector< ImplTabItem >::iterator it = mpTabCtrlData->maItemList.begin();
1511cdf0e10cSrcweir          it != mpTabCtrlData->maItemList.end(); ++it )
1512cdf0e10cSrcweir     {
1513cdf0e10cSrcweir         if ( it->maRect.IsInside( rPt ) )
1514cdf0e10cSrcweir         {
1515cdf0e10cSrcweir             // assure that only one tab is highlighted at a time
1516cdf0e10cSrcweir             nFound++;
1517cdf0e10cSrcweir             pFoundItem = &(*it);
1518cdf0e10cSrcweir         }
1519cdf0e10cSrcweir     }
1520cdf0e10cSrcweir     // assure that only one tab is highlighted at a time
1521cdf0e10cSrcweir     return nFound == 1 ? &pFoundItem->maRect : NULL;
1522cdf0e10cSrcweir }
1523cdf0e10cSrcweir 
1524cdf0e10cSrcweir long TabControl::PreNotify( NotifyEvent& rNEvt )
1525cdf0e10cSrcweir {
1526cdf0e10cSrcweir     long nDone = 0;
1527cdf0e10cSrcweir     const MouseEvent* pMouseEvt = NULL;
1528cdf0e10cSrcweir 
1529cdf0e10cSrcweir     if( (rNEvt.GetType() == EVENT_MOUSEMOVE) && (pMouseEvt = rNEvt.GetMouseEvent()) != NULL )
1530cdf0e10cSrcweir     {
1531cdf0e10cSrcweir         if( !pMouseEvt->GetButtons() && !pMouseEvt->IsSynthetic() && !pMouseEvt->IsModifierChanged() )
1532cdf0e10cSrcweir         {
1533cdf0e10cSrcweir             // trigger redraw if mouse over state has changed
1534cdf0e10cSrcweir             if( IsNativeControlSupported(CTRL_TAB_ITEM, PART_ENTIRE_CONTROL) )
1535cdf0e10cSrcweir             {
1536cdf0e10cSrcweir                 Rectangle* pRect = ImplFindPartRect( GetPointerPosPixel() );
1537cdf0e10cSrcweir                 Rectangle* pLastRect = ImplFindPartRect( GetLastPointerPosPixel() );
1538cdf0e10cSrcweir                 if( pRect != pLastRect || (pMouseEvt->IsLeaveWindow() || pMouseEvt->IsEnterWindow()) )
1539cdf0e10cSrcweir                 {
1540cdf0e10cSrcweir                     Region aClipRgn;
1541cdf0e10cSrcweir                     if( pLastRect )
1542cdf0e10cSrcweir                     {
1543cdf0e10cSrcweir                         // allow for slightly bigger tabitems
1544cdf0e10cSrcweir                         // as used by gtk
1545cdf0e10cSrcweir                         // TODO: query for the correct sizes
1546cdf0e10cSrcweir                         Rectangle aRect(*pLastRect);
1547cdf0e10cSrcweir                         aRect.nLeft-=2;
1548cdf0e10cSrcweir                         aRect.nRight+=2;
1549cdf0e10cSrcweir                         aRect.nTop-=3;
1550cdf0e10cSrcweir                         aClipRgn.Union( aRect );
1551cdf0e10cSrcweir                     }
1552cdf0e10cSrcweir                     if( pRect )
1553cdf0e10cSrcweir                     {
1554cdf0e10cSrcweir                         // allow for slightly bigger tabitems
1555cdf0e10cSrcweir                         // as used by gtk
1556cdf0e10cSrcweir                         // TODO: query for the correct sizes
1557cdf0e10cSrcweir                         Rectangle aRect(*pRect);
1558cdf0e10cSrcweir                         aRect.nLeft-=2;
1559cdf0e10cSrcweir                         aRect.nRight+=2;
1560cdf0e10cSrcweir                         aRect.nTop-=3;
1561cdf0e10cSrcweir                         aClipRgn.Union( aRect );
1562cdf0e10cSrcweir                     }
1563cdf0e10cSrcweir                     if( !aClipRgn.IsEmpty() )
1564cdf0e10cSrcweir                         Invalidate( aClipRgn );
1565cdf0e10cSrcweir                 }
1566cdf0e10cSrcweir             }
1567cdf0e10cSrcweir         }
1568cdf0e10cSrcweir     }
1569cdf0e10cSrcweir 
1570cdf0e10cSrcweir     return nDone ? nDone : Control::PreNotify(rNEvt);
1571cdf0e10cSrcweir }
1572cdf0e10cSrcweir 
1573cdf0e10cSrcweir // -----------------------------------------------------------------------
1574cdf0e10cSrcweir 
1575cdf0e10cSrcweir long TabControl::Notify( NotifyEvent& rNEvt )
1576cdf0e10cSrcweir {
1577cdf0e10cSrcweir     long nRet = 0;
1578cdf0e10cSrcweir 
1579cdf0e10cSrcweir     if ( rNEvt.GetType() == EVENT_KEYINPUT )
1580cdf0e10cSrcweir         nRet = ImplHandleKeyEvent( *rNEvt.GetKeyEvent() );
1581cdf0e10cSrcweir 
1582cdf0e10cSrcweir     return nRet ? nRet : Control::Notify( rNEvt );
1583cdf0e10cSrcweir }
1584cdf0e10cSrcweir 
1585cdf0e10cSrcweir // -----------------------------------------------------------------------
1586cdf0e10cSrcweir 
1587cdf0e10cSrcweir void TabControl::ActivatePage()
1588cdf0e10cSrcweir {
1589cdf0e10cSrcweir     maActivateHdl.Call( this );
1590cdf0e10cSrcweir }
1591cdf0e10cSrcweir 
1592cdf0e10cSrcweir // -----------------------------------------------------------------------
1593cdf0e10cSrcweir 
1594cdf0e10cSrcweir long TabControl::DeactivatePage()
1595cdf0e10cSrcweir {
1596cdf0e10cSrcweir     if ( maDeactivateHdl.IsSet() )
1597cdf0e10cSrcweir         return maDeactivateHdl.Call( this );
1598cdf0e10cSrcweir     else
1599cdf0e10cSrcweir         return sal_True;
1600cdf0e10cSrcweir }
1601cdf0e10cSrcweir 
1602cdf0e10cSrcweir // -----------------------------------------------------------------------
1603cdf0e10cSrcweir 
1604cdf0e10cSrcweir void TabControl::SetTabPageSizePixel( const Size& rSize )
1605cdf0e10cSrcweir {
1606cdf0e10cSrcweir     ImplFreeLayoutData();
1607cdf0e10cSrcweir 
1608cdf0e10cSrcweir     Size aNewSize( rSize );
1609cdf0e10cSrcweir     aNewSize.Width() += TAB_OFFSET*2;
1610cdf0e10cSrcweir     Rectangle aRect = ImplGetTabRect( TAB_PAGERECT,
1611cdf0e10cSrcweir                                       aNewSize.Width(), aNewSize.Height() );
1612cdf0e10cSrcweir     aNewSize.Height() += aRect.Top()+TAB_OFFSET;
1613cdf0e10cSrcweir     Window::SetOutputSizePixel( aNewSize );
1614cdf0e10cSrcweir }
1615cdf0e10cSrcweir 
1616cdf0e10cSrcweir // -----------------------------------------------------------------------
1617cdf0e10cSrcweir 
1618cdf0e10cSrcweir Size TabControl::GetTabPageSizePixel() const
1619cdf0e10cSrcweir {
1620cdf0e10cSrcweir     Rectangle aRect = ((TabControl*)this)->ImplGetTabRect( TAB_PAGERECT );
1621cdf0e10cSrcweir     return aRect.GetSize();
1622cdf0e10cSrcweir }
1623cdf0e10cSrcweir 
1624cdf0e10cSrcweir // -----------------------------------------------------------------------
1625cdf0e10cSrcweir 
1626cdf0e10cSrcweir void TabControl::InsertPage( const ResId& rResId, sal_uInt16 nPos )
1627cdf0e10cSrcweir {
1628cdf0e10cSrcweir     GetRes( rResId.SetRT( RSC_TABCONTROLITEM ) );
1629cdf0e10cSrcweir 
1630cdf0e10cSrcweir     sal_uLong nObjMask = ReadLongRes();
1631cdf0e10cSrcweir     sal_uInt16 nItemId  = 1;
1632cdf0e10cSrcweir 
1633cdf0e10cSrcweir     // ID
1634cdf0e10cSrcweir     if ( nObjMask & RSC_TABCONTROLITEM_ID )
1635cdf0e10cSrcweir         nItemId = sal::static_int_cast<sal_uInt16>(ReadLongRes());
1636cdf0e10cSrcweir 
1637cdf0e10cSrcweir     // Text
1638cdf0e10cSrcweir     XubString aTmpStr;
1639cdf0e10cSrcweir     if( nObjMask & RSC_TABCONTROLITEM_TEXT )
1640cdf0e10cSrcweir         aTmpStr = ReadStringRes();
1641cdf0e10cSrcweir     InsertPage( nItemId, aTmpStr, nPos );
1642cdf0e10cSrcweir 
1643cdf0e10cSrcweir     // PageResID
1644cdf0e10cSrcweir     if ( nObjMask & RSC_TABCONTROLITEM_PAGERESID )
1645cdf0e10cSrcweir     {
1646cdf0e10cSrcweir         ImplTabItem& rItem = mpTabCtrlData->maItemList[ GetPagePos( nItemId ) ];
1647cdf0e10cSrcweir         rItem.mnTabPageResId = sal::static_int_cast<sal_uInt16>(ReadLongRes());
1648cdf0e10cSrcweir     }
1649cdf0e10cSrcweir }
1650cdf0e10cSrcweir 
1651cdf0e10cSrcweir // -----------------------------------------------------------------------
1652cdf0e10cSrcweir 
1653cdf0e10cSrcweir void TabControl::InsertPage( sal_uInt16 nPageId, const XubString& rText,
1654cdf0e10cSrcweir                              sal_uInt16 nPos )
1655cdf0e10cSrcweir {
1656cdf0e10cSrcweir     DBG_ASSERT( nPageId, "TabControl::InsertPage(): PageId == 0" );
1657cdf0e10cSrcweir     DBG_ASSERT( GetPagePos( nPageId ) == TAB_PAGE_NOTFOUND,
1658cdf0e10cSrcweir                 "TabControl::InsertPage(): PageId already exists" );
1659cdf0e10cSrcweir 
1660cdf0e10cSrcweir     // insert new page item
1661cdf0e10cSrcweir     ImplTabItem* pItem = NULL;
1662cdf0e10cSrcweir     if( nPos == TAB_APPEND || size_t(nPos) >= mpTabCtrlData->maItemList.size() )
1663cdf0e10cSrcweir     {
1664cdf0e10cSrcweir         mpTabCtrlData->maItemList.push_back( ImplTabItem() );
1665cdf0e10cSrcweir         pItem = &mpTabCtrlData->maItemList.back();
1666cdf0e10cSrcweir         if( mpTabCtrlData->mpListBox )
1667cdf0e10cSrcweir             mpTabCtrlData->mpListBox->InsertEntry( rText );
1668cdf0e10cSrcweir     }
1669cdf0e10cSrcweir     else
1670cdf0e10cSrcweir     {
1671cdf0e10cSrcweir         std::vector< ImplTabItem >::iterator new_it =
1672cdf0e10cSrcweir             mpTabCtrlData->maItemList.insert( mpTabCtrlData->maItemList.begin() + nPos, ImplTabItem() );
1673cdf0e10cSrcweir         pItem = &(*new_it);
1674cdf0e10cSrcweir         if( mpTabCtrlData->mpListBox )
1675cdf0e10cSrcweir             mpTabCtrlData->mpListBox->InsertEntry( rText, nPos);
1676cdf0e10cSrcweir     }
1677cdf0e10cSrcweir     if( mpTabCtrlData->mpListBox )
1678cdf0e10cSrcweir     {
1679cdf0e10cSrcweir         if( ! mnCurPageId )
1680cdf0e10cSrcweir             mpTabCtrlData->mpListBox->SelectEntryPos( 0 );
1681cdf0e10cSrcweir         mpTabCtrlData->mpListBox->SetDropDownLineCount( mpTabCtrlData->mpListBox->GetEntryCount() );
1682cdf0e10cSrcweir     }
1683cdf0e10cSrcweir 
1684cdf0e10cSrcweir     // set current page id
1685cdf0e10cSrcweir     if ( !mnCurPageId )
1686cdf0e10cSrcweir         mnCurPageId = nPageId;
1687cdf0e10cSrcweir 
1688cdf0e10cSrcweir     // init new page item
1689cdf0e10cSrcweir     pItem->mnId             = nPageId;
1690cdf0e10cSrcweir     pItem->mpTabPage        = NULL;
1691cdf0e10cSrcweir     pItem->mnTabPageResId   = 0;
1692cdf0e10cSrcweir     pItem->maText           = rText;
1693cdf0e10cSrcweir     pItem->mbFullVisible    = sal_False;
1694cdf0e10cSrcweir 
1695cdf0e10cSrcweir     mbFormat = sal_True;
1696cdf0e10cSrcweir     if ( IsUpdateMode() )
1697cdf0e10cSrcweir         Invalidate();
1698cdf0e10cSrcweir 
1699cdf0e10cSrcweir     ImplFreeLayoutData();
1700cdf0e10cSrcweir     if( mpTabCtrlData->mpListBox ) // reposition/resize listbox
1701cdf0e10cSrcweir         Resize();
1702cdf0e10cSrcweir 
1703cdf0e10cSrcweir 	ImplCallEventListeners( VCLEVENT_TABPAGE_INSERTED, (void*) (sal_uLong)nPageId );
1704cdf0e10cSrcweir }
1705cdf0e10cSrcweir 
1706cdf0e10cSrcweir // -----------------------------------------------------------------------
1707cdf0e10cSrcweir 
1708cdf0e10cSrcweir void TabControl::RemovePage( sal_uInt16 nPageId )
1709cdf0e10cSrcweir {
1710cdf0e10cSrcweir     sal_uInt16 nPos = GetPagePos( nPageId );
1711cdf0e10cSrcweir 
1712cdf0e10cSrcweir     // does the item exist ?
1713cdf0e10cSrcweir     if ( nPos != TAB_PAGE_NOTFOUND )
1714cdf0e10cSrcweir     {
1715cdf0e10cSrcweir         //remove page item
1716cdf0e10cSrcweir         std::vector< ImplTabItem >::iterator it = mpTabCtrlData->maItemList.begin() + nPos;
1717cdf0e10cSrcweir         bool bIsCurrentPage = (it->mnId == mnCurPageId);
1718cdf0e10cSrcweir         mpTabCtrlData->maItemList.erase( it );
1719cdf0e10cSrcweir         if( mpTabCtrlData->mpListBox )
1720cdf0e10cSrcweir         {
1721cdf0e10cSrcweir             mpTabCtrlData->mpListBox->RemoveEntry( nPos );
1722cdf0e10cSrcweir             mpTabCtrlData->mpListBox->SetDropDownLineCount( mpTabCtrlData->mpListBox->GetEntryCount() );
1723cdf0e10cSrcweir         }
1724cdf0e10cSrcweir 
1725cdf0e10cSrcweir         // If current page is removed, than first page gets the current page
1726cdf0e10cSrcweir         if ( bIsCurrentPage  )
1727cdf0e10cSrcweir         {
1728cdf0e10cSrcweir             mnCurPageId = 0;
1729cdf0e10cSrcweir 
1730cdf0e10cSrcweir             if( ! mpTabCtrlData->maItemList.empty() )
1731cdf0e10cSrcweir             {
1732cdf0e10cSrcweir                 // don't do this by simply setting mnCurPageId to pFirstItem->mnId
1733cdf0e10cSrcweir                 // this leaves a lot of stuff (such trivias as _showing_ the new current page) undone
1734cdf0e10cSrcweir                 // instead, call SetCurPageId
1735cdf0e10cSrcweir                 // without this, the next (outside) call to SetCurPageId with the id of the first page
1736cdf0e10cSrcweir                 // will result in doing nothing (as we assume that nothing changed, then), and the page
1737cdf0e10cSrcweir                 // will never be shown.
1738cdf0e10cSrcweir                 // 86875 - 05/11/2001 - frank.schoenheit@germany.sun.com
1739cdf0e10cSrcweir 
1740cdf0e10cSrcweir                 SetCurPageId( mpTabCtrlData->maItemList[0].mnId );
1741cdf0e10cSrcweir             }
1742cdf0e10cSrcweir         }
1743cdf0e10cSrcweir 
1744cdf0e10cSrcweir         mbFormat = sal_True;
1745cdf0e10cSrcweir         if ( IsUpdateMode() )
1746cdf0e10cSrcweir             Invalidate();
1747cdf0e10cSrcweir 
1748cdf0e10cSrcweir         ImplFreeLayoutData();
1749cdf0e10cSrcweir 
1750cdf0e10cSrcweir 		ImplCallEventListeners( VCLEVENT_TABPAGE_REMOVED, (void*) (sal_uLong) nPageId );
1751cdf0e10cSrcweir     }
1752cdf0e10cSrcweir }
1753cdf0e10cSrcweir 
1754cdf0e10cSrcweir // -----------------------------------------------------------------------
1755cdf0e10cSrcweir 
1756cdf0e10cSrcweir void TabControl::Clear()
1757cdf0e10cSrcweir {
1758cdf0e10cSrcweir     // clear item list
1759cdf0e10cSrcweir     mpTabCtrlData->maItemList.clear();
1760cdf0e10cSrcweir     mnCurPageId = 0;
1761cdf0e10cSrcweir     if( mpTabCtrlData->mpListBox )
1762cdf0e10cSrcweir         mpTabCtrlData->mpListBox->Clear();
1763cdf0e10cSrcweir 
1764cdf0e10cSrcweir     ImplFreeLayoutData();
1765cdf0e10cSrcweir 
1766cdf0e10cSrcweir     mbFormat = sal_True;
1767cdf0e10cSrcweir     if ( IsUpdateMode() )
1768cdf0e10cSrcweir         Invalidate();
1769cdf0e10cSrcweir 
1770cdf0e10cSrcweir 	ImplCallEventListeners( VCLEVENT_TABPAGE_REMOVEDALL );
1771cdf0e10cSrcweir }
1772cdf0e10cSrcweir 
1773cdf0e10cSrcweir // -----------------------------------------------------------------------
1774cdf0e10cSrcweir 
1775cdf0e10cSrcweir void TabControl::EnablePage( sal_uInt16 i_nPageId, bool i_bEnable )
1776cdf0e10cSrcweir {
1777cdf0e10cSrcweir     ImplTabItem* pItem = ImplGetItem( i_nPageId );
1778cdf0e10cSrcweir 
1779cdf0e10cSrcweir     if ( pItem && pItem->mbEnabled != i_bEnable )
1780cdf0e10cSrcweir     {
1781cdf0e10cSrcweir         pItem->mbEnabled = i_bEnable;
1782cdf0e10cSrcweir         mbFormat = sal_True;
1783cdf0e10cSrcweir         if( mpTabCtrlData->mpListBox )
1784cdf0e10cSrcweir             mpTabCtrlData->mpListBox->SetEntryFlags( GetPagePos( i_nPageId ),
1785cdf0e10cSrcweir                                                      i_bEnable ? 0 : (LISTBOX_ENTRY_FLAG_DISABLE_SELECTION | LISTBOX_ENTRY_FLAG_DRAW_DISABLED) );
1786cdf0e10cSrcweir         if( pItem->mnId == mnCurPageId )
1787cdf0e10cSrcweir         {
1788cdf0e10cSrcweir              // SetCurPageId will change to an enabled page
1789cdf0e10cSrcweir             SetCurPageId( mnCurPageId );
1790cdf0e10cSrcweir         }
1791cdf0e10cSrcweir         else if ( IsUpdateMode() )
1792cdf0e10cSrcweir             Invalidate();
1793cdf0e10cSrcweir     }
1794cdf0e10cSrcweir }
1795cdf0e10cSrcweir 
1796cdf0e10cSrcweir // -----------------------------------------------------------------------
1797cdf0e10cSrcweir 
1798cdf0e10cSrcweir sal_uInt16 TabControl::GetPageCount() const
1799cdf0e10cSrcweir {
1800cdf0e10cSrcweir     return (sal_uInt16)mpTabCtrlData->maItemList.size();
1801cdf0e10cSrcweir }
1802cdf0e10cSrcweir 
1803cdf0e10cSrcweir // -----------------------------------------------------------------------
1804cdf0e10cSrcweir 
1805cdf0e10cSrcweir sal_uInt16 TabControl::GetPageId( sal_uInt16 nPos ) const
1806cdf0e10cSrcweir {
1807cdf0e10cSrcweir     if( size_t(nPos) < mpTabCtrlData->maItemList.size() )
1808cdf0e10cSrcweir         return mpTabCtrlData->maItemList[ nPos ].mnId;
1809cdf0e10cSrcweir     return 0;
1810cdf0e10cSrcweir }
1811cdf0e10cSrcweir 
1812cdf0e10cSrcweir // -----------------------------------------------------------------------
1813cdf0e10cSrcweir 
1814cdf0e10cSrcweir sal_uInt16 TabControl::GetPagePos( sal_uInt16 nPageId ) const
1815cdf0e10cSrcweir {
1816cdf0e10cSrcweir     for( std::vector< ImplTabItem >::const_iterator it = mpTabCtrlData->maItemList.begin();
1817cdf0e10cSrcweir          it != mpTabCtrlData->maItemList.end(); ++it )
1818cdf0e10cSrcweir     {
1819cdf0e10cSrcweir         if ( it->mnId == nPageId )
1820cdf0e10cSrcweir             return (sal_uInt16)(it - mpTabCtrlData->maItemList.begin());
1821cdf0e10cSrcweir     }
1822cdf0e10cSrcweir 
1823cdf0e10cSrcweir     return TAB_PAGE_NOTFOUND;
1824cdf0e10cSrcweir }
1825cdf0e10cSrcweir 
1826cdf0e10cSrcweir // -----------------------------------------------------------------------
1827cdf0e10cSrcweir 
1828cdf0e10cSrcweir sal_uInt16 TabControl::GetPageId( const Point& rPos ) const
1829cdf0e10cSrcweir {
1830cdf0e10cSrcweir     for( size_t i = 0; i < mpTabCtrlData->maItemList.size(); ++i )
1831cdf0e10cSrcweir     {
1832cdf0e10cSrcweir         if ( ((TabControl*)this)->ImplGetTabRect( static_cast<sal_uInt16>(i) ).IsInside( rPos ) )
1833cdf0e10cSrcweir             return mpTabCtrlData->maItemList[ i ].mnId;
1834cdf0e10cSrcweir     }
1835cdf0e10cSrcweir 
1836cdf0e10cSrcweir     return 0;
1837cdf0e10cSrcweir }
1838cdf0e10cSrcweir 
1839cdf0e10cSrcweir // -----------------------------------------------------------------------
1840cdf0e10cSrcweir 
1841cdf0e10cSrcweir void TabControl::SetCurPageId( sal_uInt16 nPageId )
1842cdf0e10cSrcweir {
1843cdf0e10cSrcweir     sal_uInt16 nPos = GetPagePos( nPageId );
1844cdf0e10cSrcweir     while( nPos != TAB_PAGE_NOTFOUND &&
1845cdf0e10cSrcweir            ! mpTabCtrlData->maItemList[nPos].mbEnabled )
1846cdf0e10cSrcweir     {
1847cdf0e10cSrcweir         nPos++;
1848cdf0e10cSrcweir         if( size_t(nPos) >= mpTabCtrlData->maItemList.size() )
1849cdf0e10cSrcweir             nPos = 0;
1850cdf0e10cSrcweir         if( mpTabCtrlData->maItemList[nPos].mnId == nPageId )
1851cdf0e10cSrcweir             break;
1852cdf0e10cSrcweir     }
1853cdf0e10cSrcweir 
1854cdf0e10cSrcweir     if( nPos != TAB_PAGE_NOTFOUND )
1855cdf0e10cSrcweir     {
1856cdf0e10cSrcweir         nPageId = mpTabCtrlData->maItemList[nPos].mnId;
1857cdf0e10cSrcweir         if ( nPageId == mnCurPageId )
1858cdf0e10cSrcweir         {
1859cdf0e10cSrcweir             if ( mnActPageId )
1860cdf0e10cSrcweir                 mnActPageId = nPageId;
1861cdf0e10cSrcweir             return;
1862cdf0e10cSrcweir         }
1863cdf0e10cSrcweir 
1864cdf0e10cSrcweir         if ( mnActPageId )
1865cdf0e10cSrcweir             mnActPageId = nPageId;
1866cdf0e10cSrcweir         else
1867cdf0e10cSrcweir         {
1868cdf0e10cSrcweir             mbFormat = sal_True;
1869cdf0e10cSrcweir             sal_uInt16 nOldId = mnCurPageId;
1870cdf0e10cSrcweir             mnCurPageId = nPageId;
1871cdf0e10cSrcweir             ImplChangeTabPage( nPageId, nOldId );
1872cdf0e10cSrcweir         }
1873cdf0e10cSrcweir     }
1874cdf0e10cSrcweir }
1875cdf0e10cSrcweir 
1876cdf0e10cSrcweir // -----------------------------------------------------------------------
1877cdf0e10cSrcweir 
1878cdf0e10cSrcweir sal_uInt16 TabControl::GetCurPageId() const
1879cdf0e10cSrcweir {
1880cdf0e10cSrcweir     if ( mnActPageId )
1881cdf0e10cSrcweir         return mnActPageId;
1882cdf0e10cSrcweir     else
1883cdf0e10cSrcweir         return mnCurPageId;
1884cdf0e10cSrcweir }
1885cdf0e10cSrcweir 
1886cdf0e10cSrcweir // -----------------------------------------------------------------------
1887cdf0e10cSrcweir 
1888cdf0e10cSrcweir void TabControl::SelectTabPage( sal_uInt16 nPageId )
1889cdf0e10cSrcweir {
1890cdf0e10cSrcweir     if ( nPageId && (nPageId != mnCurPageId) )
1891cdf0e10cSrcweir     {
1892cdf0e10cSrcweir         ImplFreeLayoutData();
1893cdf0e10cSrcweir 
1894cdf0e10cSrcweir 		ImplCallEventListeners( VCLEVENT_TABPAGE_DEACTIVATE, (void*) (sal_uLong) mnCurPageId );
1895cdf0e10cSrcweir         if ( DeactivatePage() )
1896cdf0e10cSrcweir         {
1897cdf0e10cSrcweir             mnActPageId = nPageId;
1898cdf0e10cSrcweir             ActivatePage();
1899cdf0e10cSrcweir             // Page koennte im Activate-Handler umgeschaltet wurden sein
1900cdf0e10cSrcweir             nPageId = mnActPageId;
1901cdf0e10cSrcweir             mnActPageId = 0;
1902cdf0e10cSrcweir             SetCurPageId( nPageId );
1903cdf0e10cSrcweir             if( mpTabCtrlData->mpListBox )
1904cdf0e10cSrcweir                 mpTabCtrlData->mpListBox->SelectEntryPos( GetPagePos( nPageId ) );
1905cdf0e10cSrcweir 			ImplCallEventListeners( VCLEVENT_TABPAGE_ACTIVATE, (void*) (sal_uLong) nPageId );
1906cdf0e10cSrcweir         }
1907cdf0e10cSrcweir     }
1908cdf0e10cSrcweir }
1909cdf0e10cSrcweir 
1910cdf0e10cSrcweir // -----------------------------------------------------------------------
1911cdf0e10cSrcweir 
1912cdf0e10cSrcweir void TabControl::SetTabPage( sal_uInt16 nPageId, TabPage* pTabPage )
1913cdf0e10cSrcweir {
1914cdf0e10cSrcweir     ImplTabItem* pItem = ImplGetItem( nPageId );
1915cdf0e10cSrcweir 
1916cdf0e10cSrcweir     if ( pItem && (pItem->mpTabPage != pTabPage) )
1917cdf0e10cSrcweir     {
1918cdf0e10cSrcweir         if ( pTabPage )
1919cdf0e10cSrcweir         {
1920cdf0e10cSrcweir             DBG_ASSERT( !pTabPage->IsVisible(), "TabControl::SetTabPage() - Page is visible" );
1921cdf0e10cSrcweir 
1922cdf0e10cSrcweir             if ( IsDefaultSize() )
1923cdf0e10cSrcweir                 SetTabPageSizePixel( pTabPage->GetSizePixel() );
1924cdf0e10cSrcweir 
1925cdf0e10cSrcweir             // Erst hier setzen, damit Resize nicht TabPage umpositioniert
1926cdf0e10cSrcweir             pItem->mpTabPage = pTabPage;
1927cdf0e10cSrcweir             if ( pItem->mnId == mnCurPageId )
1928cdf0e10cSrcweir                 ImplChangeTabPage( pItem->mnId, 0 );
1929cdf0e10cSrcweir         }
1930cdf0e10cSrcweir         else
1931cdf0e10cSrcweir             pItem->mpTabPage = NULL;
1932cdf0e10cSrcweir     }
1933cdf0e10cSrcweir }
1934cdf0e10cSrcweir 
1935cdf0e10cSrcweir // -----------------------------------------------------------------------
1936cdf0e10cSrcweir 
1937cdf0e10cSrcweir TabPage* TabControl::GetTabPage( sal_uInt16 nPageId ) const
1938cdf0e10cSrcweir {
1939cdf0e10cSrcweir     ImplTabItem* pItem = ImplGetItem( nPageId );
1940cdf0e10cSrcweir 
1941cdf0e10cSrcweir     if ( pItem )
1942cdf0e10cSrcweir         return pItem->mpTabPage;
1943cdf0e10cSrcweir     else
1944cdf0e10cSrcweir         return NULL;
1945cdf0e10cSrcweir }
1946cdf0e10cSrcweir 
1947cdf0e10cSrcweir // -----------------------------------------------------------------------
1948cdf0e10cSrcweir 
1949cdf0e10cSrcweir sal_uInt16 TabControl::GetTabPageResId( sal_uInt16 nPageId ) const
1950cdf0e10cSrcweir {
1951cdf0e10cSrcweir     ImplTabItem* pItem = ImplGetItem( nPageId );
1952cdf0e10cSrcweir 
1953cdf0e10cSrcweir     if ( pItem )
1954cdf0e10cSrcweir         return pItem->mnTabPageResId;
1955cdf0e10cSrcweir     else
1956cdf0e10cSrcweir         return 0;
1957cdf0e10cSrcweir }
1958cdf0e10cSrcweir 
1959cdf0e10cSrcweir // -----------------------------------------------------------------------
1960cdf0e10cSrcweir 
1961cdf0e10cSrcweir void TabControl::SetPageText( sal_uInt16 nPageId, const XubString& rText )
1962cdf0e10cSrcweir {
1963cdf0e10cSrcweir     ImplTabItem* pItem = ImplGetItem( nPageId );
1964cdf0e10cSrcweir 
1965cdf0e10cSrcweir     if ( pItem && pItem->maText != rText )
1966cdf0e10cSrcweir     {
1967cdf0e10cSrcweir         pItem->maText = rText;
1968cdf0e10cSrcweir         mbFormat = sal_True;
1969cdf0e10cSrcweir         if( mpTabCtrlData->mpListBox )
1970cdf0e10cSrcweir         {
1971cdf0e10cSrcweir             sal_uInt16 nPos = GetPagePos( nPageId );
1972cdf0e10cSrcweir             mpTabCtrlData->mpListBox->RemoveEntry( nPos );
1973cdf0e10cSrcweir             mpTabCtrlData->mpListBox->InsertEntry( rText, nPos );
1974cdf0e10cSrcweir         }
1975cdf0e10cSrcweir         if ( IsUpdateMode() )
1976cdf0e10cSrcweir             Invalidate();
1977cdf0e10cSrcweir         ImplFreeLayoutData();
1978cdf0e10cSrcweir 		ImplCallEventListeners( VCLEVENT_TABPAGE_PAGETEXTCHANGED, (void*) (sal_uLong) nPageId );
1979cdf0e10cSrcweir     }
1980cdf0e10cSrcweir }
1981cdf0e10cSrcweir 
1982cdf0e10cSrcweir // -----------------------------------------------------------------------
1983cdf0e10cSrcweir 
1984cdf0e10cSrcweir XubString TabControl::GetPageText( sal_uInt16 nPageId ) const
1985cdf0e10cSrcweir {
1986cdf0e10cSrcweir     ImplTabItem* pItem = ImplGetItem( nPageId );
1987cdf0e10cSrcweir 
1988cdf0e10cSrcweir     if ( pItem )
1989cdf0e10cSrcweir         return pItem->maText;
1990cdf0e10cSrcweir     else
1991cdf0e10cSrcweir         return ImplGetSVEmptyStr();
1992cdf0e10cSrcweir }
1993cdf0e10cSrcweir 
1994cdf0e10cSrcweir // -----------------------------------------------------------------------
1995cdf0e10cSrcweir 
1996cdf0e10cSrcweir void TabControl::SetHelpText( sal_uInt16 nPageId, const XubString& rText )
1997cdf0e10cSrcweir {
1998cdf0e10cSrcweir     ImplTabItem* pItem = ImplGetItem( nPageId );
1999cdf0e10cSrcweir 
2000cdf0e10cSrcweir     if ( pItem )
2001cdf0e10cSrcweir         pItem->maHelpText = rText;
2002cdf0e10cSrcweir }
2003cdf0e10cSrcweir 
2004cdf0e10cSrcweir // -----------------------------------------------------------------------
2005cdf0e10cSrcweir 
2006cdf0e10cSrcweir const XubString& TabControl::GetHelpText( sal_uInt16 nPageId ) const
2007cdf0e10cSrcweir {
2008cdf0e10cSrcweir     ImplTabItem* pItem = ImplGetItem( nPageId );
2009cdf0e10cSrcweir 
2010cdf0e10cSrcweir     if ( pItem )
2011cdf0e10cSrcweir     {
2012cdf0e10cSrcweir         if ( !pItem->maHelpText.Len() && pItem->maHelpId.getLength() )
2013cdf0e10cSrcweir         {
2014cdf0e10cSrcweir             Help* pHelp = Application::GetHelp();
2015cdf0e10cSrcweir             if ( pHelp )
2016cdf0e10cSrcweir                 pItem->maHelpText = pHelp->GetHelpText( rtl::OStringToOUString( pItem->maHelpId, RTL_TEXTENCODING_UTF8 ), this );
2017cdf0e10cSrcweir         }
2018cdf0e10cSrcweir 
2019cdf0e10cSrcweir         return pItem->maHelpText;
2020cdf0e10cSrcweir     }
2021cdf0e10cSrcweir     else
2022cdf0e10cSrcweir         return ImplGetSVEmptyStr();
2023cdf0e10cSrcweir }
2024cdf0e10cSrcweir 
2025cdf0e10cSrcweir // -----------------------------------------------------------------------
2026cdf0e10cSrcweir 
2027cdf0e10cSrcweir void TabControl::SetHelpId( sal_uInt16 nPageId, const rtl::OString& rHelpId )
2028cdf0e10cSrcweir {
2029cdf0e10cSrcweir     ImplTabItem* pItem = ImplGetItem( nPageId );
2030cdf0e10cSrcweir 
2031cdf0e10cSrcweir     if ( pItem )
2032cdf0e10cSrcweir         pItem->maHelpId = rHelpId;
2033cdf0e10cSrcweir }
2034cdf0e10cSrcweir 
2035cdf0e10cSrcweir // -----------------------------------------------------------------------
2036cdf0e10cSrcweir 
2037cdf0e10cSrcweir rtl::OString TabControl::GetHelpId( sal_uInt16 nPageId ) const
2038cdf0e10cSrcweir {
2039cdf0e10cSrcweir     rtl::OString aRet;
2040cdf0e10cSrcweir     ImplTabItem* pItem = ImplGetItem( nPageId );
2041cdf0e10cSrcweir 
2042cdf0e10cSrcweir     if ( pItem )
2043cdf0e10cSrcweir         aRet = pItem->maHelpId;
2044cdf0e10cSrcweir 
2045cdf0e10cSrcweir     return aRet;
2046cdf0e10cSrcweir }
2047cdf0e10cSrcweir 
2048cdf0e10cSrcweir // -----------------------------------------------------------------------
2049cdf0e10cSrcweir 
2050cdf0e10cSrcweir void TabControl::SetPageImage( sal_uInt16 i_nPageId, const Image& i_rImage )
2051cdf0e10cSrcweir {
2052cdf0e10cSrcweir     ImplTabItem* pItem = ImplGetItem( i_nPageId );
2053cdf0e10cSrcweir 
2054cdf0e10cSrcweir     if ( pItem )
2055cdf0e10cSrcweir     {
2056cdf0e10cSrcweir         pItem->maTabImage = i_rImage;
2057cdf0e10cSrcweir         mbFormat = sal_True;
2058cdf0e10cSrcweir         if ( IsUpdateMode() )
2059cdf0e10cSrcweir             Invalidate();
2060cdf0e10cSrcweir     }
2061cdf0e10cSrcweir }
2062cdf0e10cSrcweir 
2063cdf0e10cSrcweir // -----------------------------------------------------------------------
2064cdf0e10cSrcweir 
2065cdf0e10cSrcweir const Image* TabControl::GetPageImage( sal_uInt16 i_nPageId ) const
2066cdf0e10cSrcweir {
2067cdf0e10cSrcweir     const ImplTabItem* pItem = ImplGetItem( i_nPageId );
2068cdf0e10cSrcweir     return pItem ? &pItem->maTabImage : NULL;
2069cdf0e10cSrcweir }
2070cdf0e10cSrcweir 
2071cdf0e10cSrcweir // -----------------------------------------------------------------------
2072cdf0e10cSrcweir 
2073cdf0e10cSrcweir Rectangle TabControl::GetCharacterBounds( sal_uInt16 nPageId, long nIndex ) const
2074cdf0e10cSrcweir {
2075cdf0e10cSrcweir     Rectangle aRet;
2076cdf0e10cSrcweir 
2077cdf0e10cSrcweir     if( !HasLayoutData() || ! mpTabCtrlData->maLayoutPageIdToLine.size() )
2078cdf0e10cSrcweir         FillLayoutData();
2079cdf0e10cSrcweir 
2080cdf0e10cSrcweir     if( HasLayoutData() )
2081cdf0e10cSrcweir     {
2082cdf0e10cSrcweir         std::hash_map< int, int >::const_iterator it = mpTabCtrlData->maLayoutPageIdToLine.find( (int)nPageId );
2083cdf0e10cSrcweir         if( it != mpTabCtrlData->maLayoutPageIdToLine.end() )
2084cdf0e10cSrcweir         {
2085cdf0e10cSrcweir             Pair aPair = mpControlData->mpLayoutData->GetLineStartEnd( it->second );
2086cdf0e10cSrcweir             if( (aPair.B() - aPair.A()) >= nIndex )
2087cdf0e10cSrcweir                 aRet = mpControlData->mpLayoutData->GetCharacterBounds( aPair.A() + nIndex );
2088cdf0e10cSrcweir         }
2089cdf0e10cSrcweir     }
2090cdf0e10cSrcweir 
2091cdf0e10cSrcweir     return aRet;
2092cdf0e10cSrcweir }
2093cdf0e10cSrcweir 
2094cdf0e10cSrcweir // -----------------------------------------------------------------------
2095cdf0e10cSrcweir 
2096cdf0e10cSrcweir long TabControl::GetIndexForPoint( const Point& rPoint, sal_uInt16& rPageId ) const
2097cdf0e10cSrcweir {
2098cdf0e10cSrcweir     long nRet = -1;
2099cdf0e10cSrcweir 
2100cdf0e10cSrcweir     if( !HasLayoutData() || ! mpTabCtrlData->maLayoutPageIdToLine.size() )
2101cdf0e10cSrcweir         FillLayoutData();
2102cdf0e10cSrcweir 
2103cdf0e10cSrcweir     if( HasLayoutData() )
2104cdf0e10cSrcweir     {
2105cdf0e10cSrcweir         int nIndex = mpControlData->mpLayoutData->GetIndexForPoint( rPoint );
2106cdf0e10cSrcweir         if( nIndex != -1 )
2107cdf0e10cSrcweir         {
2108cdf0e10cSrcweir             // what line (->pageid) is this index in ?
2109cdf0e10cSrcweir             int nLines = mpControlData->mpLayoutData->GetLineCount();
2110cdf0e10cSrcweir             int nLine = -1;
2111cdf0e10cSrcweir             while( ++nLine < nLines )
2112cdf0e10cSrcweir             {
2113cdf0e10cSrcweir                 Pair aPair = mpControlData->mpLayoutData->GetLineStartEnd( nLine );
2114cdf0e10cSrcweir                 if( aPair.A() <= nIndex && aPair.B() >= nIndex )
2115cdf0e10cSrcweir                 {
2116cdf0e10cSrcweir                     nRet = nIndex - aPair.A();
2117cdf0e10cSrcweir                     rPageId = (sal_uInt16)mpTabCtrlData->maLayoutLineToPageId[ nLine ];
2118cdf0e10cSrcweir                     break;
2119cdf0e10cSrcweir                 }
2120cdf0e10cSrcweir             }
2121cdf0e10cSrcweir         }
2122cdf0e10cSrcweir     }
2123cdf0e10cSrcweir 
2124cdf0e10cSrcweir     return nRet;
2125cdf0e10cSrcweir }
2126cdf0e10cSrcweir 
2127cdf0e10cSrcweir // -----------------------------------------------------------------------
2128cdf0e10cSrcweir 
2129cdf0e10cSrcweir void TabControl::FillLayoutData() const
2130cdf0e10cSrcweir {
2131cdf0e10cSrcweir     mpTabCtrlData->maLayoutLineToPageId.clear();
2132cdf0e10cSrcweir     mpTabCtrlData->maLayoutPageIdToLine.clear();
2133cdf0e10cSrcweir     const_cast<TabControl*>(this)->ImplPaint( Rectangle(), true );
2134cdf0e10cSrcweir }
2135cdf0e10cSrcweir 
2136cdf0e10cSrcweir // -----------------------------------------------------------------------
2137cdf0e10cSrcweir 
2138cdf0e10cSrcweir Rectangle TabControl::GetTabPageBounds( sal_uInt16 nPage ) const
2139cdf0e10cSrcweir {
2140cdf0e10cSrcweir     Rectangle aRet;
2141cdf0e10cSrcweir 
2142cdf0e10cSrcweir     if( !HasLayoutData() || ! mpTabCtrlData->maLayoutPageIdToLine.size() )
2143cdf0e10cSrcweir         FillLayoutData();
2144cdf0e10cSrcweir 
2145cdf0e10cSrcweir     if( HasLayoutData() )
2146cdf0e10cSrcweir     {
2147cdf0e10cSrcweir         std::hash_map< int, int >::const_iterator it = mpTabCtrlData->maLayoutPageIdToLine.find( (int)nPage );
2148cdf0e10cSrcweir         if( it != mpTabCtrlData->maLayoutPageIdToLine.end() )
2149cdf0e10cSrcweir         {
2150cdf0e10cSrcweir             if( it->second >= 0 && it->second < static_cast<int>(mpTabCtrlData->maTabRectangles.size()) )
2151cdf0e10cSrcweir             {
2152cdf0e10cSrcweir                 aRet = mpTabCtrlData->maTabRectangles[ it->second ];
2153cdf0e10cSrcweir                 aRet.Union( const_cast<TabControl*>(this)->ImplGetTabRect( TAB_PAGERECT ) );
2154cdf0e10cSrcweir             }
2155cdf0e10cSrcweir         }
2156cdf0e10cSrcweir     }
2157cdf0e10cSrcweir 
2158cdf0e10cSrcweir     return aRet;
2159cdf0e10cSrcweir }
2160cdf0e10cSrcweir 
2161cdf0e10cSrcweir // -----------------------------------------------------------------------
2162cdf0e10cSrcweir 
2163cdf0e10cSrcweir Rectangle TabControl::GetTabBounds( sal_uInt16 nPageId ) const
2164cdf0e10cSrcweir {
2165cdf0e10cSrcweir     Rectangle aRet;
2166cdf0e10cSrcweir 
2167cdf0e10cSrcweir     ImplTabItem* pItem = ImplGetItem( nPageId );
2168cdf0e10cSrcweir     if(pItem)
2169cdf0e10cSrcweir         aRet = pItem->maRect;
2170cdf0e10cSrcweir 
2171cdf0e10cSrcweir     return aRet;
2172cdf0e10cSrcweir }
2173cdf0e10cSrcweir 
2174cdf0e10cSrcweir // -----------------------------------------------------------------------
2175cdf0e10cSrcweir 
2176cdf0e10cSrcweir void TabControl::SetItemsOffset( const Point& rOffs )
2177cdf0e10cSrcweir {
2178cdf0e10cSrcweir     if( mpTabCtrlData )
2179cdf0e10cSrcweir         mpTabCtrlData->maItemsOffset = rOffs;
2180cdf0e10cSrcweir }
2181cdf0e10cSrcweir 
2182cdf0e10cSrcweir Point TabControl::GetItemsOffset() const
2183cdf0e10cSrcweir {
2184cdf0e10cSrcweir     if( mpTabCtrlData )
2185cdf0e10cSrcweir         return mpTabCtrlData->maItemsOffset;
2186cdf0e10cSrcweir     else
2187cdf0e10cSrcweir         return Point();
2188cdf0e10cSrcweir }
2189cdf0e10cSrcweir 
2190cdf0e10cSrcweir // -----------------------------------------------------------------------
2191cdf0e10cSrcweir 
2192cdf0e10cSrcweir Size TabControl::GetOptimalSize(WindowSizeType eType) const
2193cdf0e10cSrcweir {
2194cdf0e10cSrcweir     switch (eType) {
2195cdf0e10cSrcweir     case WINDOWSIZE_MINIMUM:
2196cdf0e10cSrcweir         return mpTabCtrlData ? mpTabCtrlData->maMinSize : Size();
2197cdf0e10cSrcweir     default:
2198cdf0e10cSrcweir         return Control::GetOptimalSize( eType );
2199cdf0e10cSrcweir     }
2200cdf0e10cSrcweir }
2201cdf0e10cSrcweir 
2202cdf0e10cSrcweir // -----------------------------------------------------------------------
2203cdf0e10cSrcweir 
2204cdf0e10cSrcweir void TabControl::SetMinimumSizePixel( const Size& i_rSize )
2205cdf0e10cSrcweir {
2206cdf0e10cSrcweir     if( mpTabCtrlData )
2207cdf0e10cSrcweir         mpTabCtrlData->maMinSize = i_rSize;
2208cdf0e10cSrcweir }
2209cdf0e10cSrcweir 
2210cdf0e10cSrcweir // -----------------------------------------------------------------------
2211cdf0e10cSrcweir 
2212cdf0e10cSrcweir 
2213