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