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