xref: /AOO41X/main/svtools/source/control/headbar.cxx (revision 2bfcd321e2172336182a43e6d401b533c4283ceb)
15900e8ecSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
35900e8ecSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
45900e8ecSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
55900e8ecSAndrew Rist  * distributed with this work for additional information
65900e8ecSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
75900e8ecSAndrew Rist  * to you under the Apache License, Version 2.0 (the
85900e8ecSAndrew Rist  * "License"); you may not use this file except in compliance
95900e8ecSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
115900e8ecSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
135900e8ecSAndrew Rist  * Unless required by applicable law or agreed to in writing,
145900e8ecSAndrew Rist  * software distributed under the License is distributed on an
155900e8ecSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
165900e8ecSAndrew Rist  * KIND, either express or implied.  See the License for the
175900e8ecSAndrew Rist  * specific language governing permissions and limitations
185900e8ecSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
205900e8ecSAndrew Rist  *************************************************************/
215900e8ecSAndrew Rist 
225900e8ecSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svtools.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #define _SV_HEADBAR_CXX
28cdf0e10cSrcweir #include <svtools/headbar.hxx>
29cdf0e10cSrcweir #include <tools/debug.hxx>
30cdf0e10cSrcweir #ifndef _TOOLS_LIST_HXX
31cdf0e10cSrcweir #include <tools/list.hxx>
32cdf0e10cSrcweir #endif
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #ifndef _VCL_APP_HXX
35cdf0e10cSrcweir #include <vcl/svapp.hxx>
36cdf0e10cSrcweir #endif
37cdf0e10cSrcweir #ifndef _VCL_HELP_HXX
38cdf0e10cSrcweir #include <vcl/help.hxx>
39cdf0e10cSrcweir #endif
40cdf0e10cSrcweir #ifndef _VCL_IMAGE_HXX
41cdf0e10cSrcweir #include <vcl/image.hxx>
42cdf0e10cSrcweir #endif
43cdf0e10cSrcweir #include <com/sun/star/accessibility/XAccessible.hpp>
44cdf0e10cSrcweir 
45*2bfcd321SSteve Yin //IAccessibility2 Implementation 2009-----
46*2bfcd321SSteve Yin #include <com/sun/star/accessibility/AccessibleRole.hpp>
47*2bfcd321SSteve Yin #include <vclxaccessibleheaderbar.hxx>
48*2bfcd321SSteve Yin //-----IAccessibility2 Implementation 2009
49cdf0e10cSrcweir // =======================================================================
50cdf0e10cSrcweir 
51cdf0e10cSrcweir struct ImplHeadItem
52cdf0e10cSrcweir {
53cdf0e10cSrcweir 	sal_uInt16				mnId;
54cdf0e10cSrcweir 	HeaderBarItemBits	mnBits;
55cdf0e10cSrcweir 	long				mnSize;
56cdf0e10cSrcweir 	rtl::OString		maHelpId;
57cdf0e10cSrcweir 	Image				maImage;
58cdf0e10cSrcweir 	XubString			maOutText;
59cdf0e10cSrcweir 	XubString			maText;
60cdf0e10cSrcweir 	XubString			maHelpText;
61cdf0e10cSrcweir 	void*				mpUserData;
62cdf0e10cSrcweir };
63cdf0e10cSrcweir 
64cdf0e10cSrcweir DECLARE_LIST( ImplHeadItemList, ImplHeadItem* )
65cdf0e10cSrcweir 
66cdf0e10cSrcweir // =======================================================================
67cdf0e10cSrcweir 
68cdf0e10cSrcweir #define HEAD_ARROWSIZE1 			4
69cdf0e10cSrcweir #define HEAD_ARROWSIZE2 			7
70cdf0e10cSrcweir 
71cdf0e10cSrcweir #define HEADERBAR_TEXTOFF			2
72cdf0e10cSrcweir #define HEADERBAR_ARROWOFF			5
73cdf0e10cSrcweir #define HEADERBAR_SPLITOFF			3
74cdf0e10cSrcweir 
75cdf0e10cSrcweir #define HEADERBAR_DRAGOFF			4
76cdf0e10cSrcweir #define HEADERBAR_DRAGOUTOFF		15
77cdf0e10cSrcweir 
78cdf0e10cSrcweir #define HEAD_HITTEST_ITEM			((sal_uInt16)0x0001)
79cdf0e10cSrcweir #define HEAD_HITTEST_DIVIDER		((sal_uInt16)0x0002)
80cdf0e10cSrcweir 
81cdf0e10cSrcweir // =======================================================================
82cdf0e10cSrcweir 
83cdf0e10cSrcweir void HeaderBar::ImplInit( WinBits nWinStyle )
84cdf0e10cSrcweir {
85cdf0e10cSrcweir 	mpItemList		= new ImplHeadItemList;
86cdf0e10cSrcweir 	mnBorderOff1	= 0;
87cdf0e10cSrcweir 	mnBorderOff2	= 0;
88cdf0e10cSrcweir 	mnOffset		= 0;
89cdf0e10cSrcweir 	mnDX			= 0;
90cdf0e10cSrcweir 	mnDY			= 0;
91cdf0e10cSrcweir 	mnDragSize		= 0;
92cdf0e10cSrcweir 	mnStartPos		= 0;
93cdf0e10cSrcweir 	mnDragPos		= 0;
94cdf0e10cSrcweir 	mnMouseOff		= 0;
95cdf0e10cSrcweir 	mnCurItemId 	= 0;
96cdf0e10cSrcweir 	mnItemDragPos	= HEADERBAR_ITEM_NOTFOUND;
97cdf0e10cSrcweir 	mbDrag			= sal_False;
98cdf0e10cSrcweir 	mbItemDrag		= sal_False;
99cdf0e10cSrcweir 	mbOutDrag		= sal_False;
100cdf0e10cSrcweir 	mbItemMode		= sal_False;
101cdf0e10cSrcweir 
102*2bfcd321SSteve Yin 	//IAccessibility2 Implementation 2009-----
103*2bfcd321SSteve Yin 	m_pVCLXHeaderBar = NULL;
104*2bfcd321SSteve Yin 	//-----IAccessibility2 Implementation 2009
105cdf0e10cSrcweir 	// StyleBits auswerten
106cdf0e10cSrcweir 	if ( nWinStyle & WB_DRAG )
107cdf0e10cSrcweir 		mbDragable = sal_True;
108cdf0e10cSrcweir 	else
109cdf0e10cSrcweir 		mbDragable = sal_False;
110cdf0e10cSrcweir 	if ( nWinStyle & WB_BUTTONSTYLE )
111cdf0e10cSrcweir 		mbButtonStyle = sal_True;
112cdf0e10cSrcweir 	else
113cdf0e10cSrcweir 		mbButtonStyle = sal_False;
114cdf0e10cSrcweir 	if ( nWinStyle & WB_BORDER )
115cdf0e10cSrcweir 	{
116cdf0e10cSrcweir 		mnBorderOff1 = 1;
117cdf0e10cSrcweir 		mnBorderOff2 = 1;
118cdf0e10cSrcweir 	}
119cdf0e10cSrcweir 	else
120cdf0e10cSrcweir 	{
121cdf0e10cSrcweir 		if ( nWinStyle & WB_BOTTOMBORDER )
122cdf0e10cSrcweir 			mnBorderOff2 = 1;
123cdf0e10cSrcweir 	}
124cdf0e10cSrcweir 
125cdf0e10cSrcweir 	ImplInitSettings( sal_True, sal_True, sal_True );
126*2bfcd321SSteve Yin 	//IAccessibility2 Implementation 2009-----
127*2bfcd321SSteve Yin 	//SetAccessibleRole(com::sun::star::accessibility::AccessibleRole::COLUMN_HEADER);
128*2bfcd321SSteve Yin 	//-----IAccessibility2 Implementation 2009
129cdf0e10cSrcweir }
130cdf0e10cSrcweir 
131cdf0e10cSrcweir // -----------------------------------------------------------------------
132cdf0e10cSrcweir 
133cdf0e10cSrcweir HeaderBar::HeaderBar( Window* pParent, WinBits nWinStyle ) :
134cdf0e10cSrcweir 	Window( pParent, nWinStyle & WB_3DLOOK )
135cdf0e10cSrcweir {
136cdf0e10cSrcweir 	ImplInit( nWinStyle );
137cdf0e10cSrcweir 	SetSizePixel( CalcWindowSizePixel() );
138cdf0e10cSrcweir }
139cdf0e10cSrcweir 
140cdf0e10cSrcweir // -----------------------------------------------------------------------
141cdf0e10cSrcweir 
142cdf0e10cSrcweir HeaderBar::HeaderBar( Window* pParent, const ResId& rResId ) :
143cdf0e10cSrcweir 	Window( pParent, rResId )
144cdf0e10cSrcweir {
145cdf0e10cSrcweir 	ImplInit( rResId.GetWinBits() );
146cdf0e10cSrcweir }
147cdf0e10cSrcweir 
148cdf0e10cSrcweir // -----------------------------------------------------------------------
149cdf0e10cSrcweir 
150cdf0e10cSrcweir HeaderBar::~HeaderBar()
151cdf0e10cSrcweir {
152cdf0e10cSrcweir 	// Alle Items loeschen
153cdf0e10cSrcweir 	ImplHeadItem* pItem = mpItemList->First();
154cdf0e10cSrcweir 	while ( pItem )
155cdf0e10cSrcweir 	{
156cdf0e10cSrcweir 		delete pItem;
157cdf0e10cSrcweir 		pItem = mpItemList->Next();
158cdf0e10cSrcweir 	}
159cdf0e10cSrcweir 
160cdf0e10cSrcweir 	delete mpItemList;
161cdf0e10cSrcweir }
162cdf0e10cSrcweir 
163cdf0e10cSrcweir // -----------------------------------------------------------------------
164cdf0e10cSrcweir 
165cdf0e10cSrcweir void HeaderBar::ImplInitSettings( sal_Bool bFont,
166cdf0e10cSrcweir 								  sal_Bool bForeground, sal_Bool bBackground )
167cdf0e10cSrcweir {
168cdf0e10cSrcweir 	const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
169cdf0e10cSrcweir 
170cdf0e10cSrcweir 	if ( bFont )
171cdf0e10cSrcweir 	{
172cdf0e10cSrcweir 		Font aFont;
173cdf0e10cSrcweir 		aFont = rStyleSettings.GetToolFont();
174cdf0e10cSrcweir 		if ( IsControlFont() )
175cdf0e10cSrcweir 			aFont.Merge( GetControlFont() );
176cdf0e10cSrcweir 		SetZoomedPointFont( aFont );
177cdf0e10cSrcweir 	}
178cdf0e10cSrcweir 
179cdf0e10cSrcweir 	if ( bForeground || bFont )
180cdf0e10cSrcweir 	{
181cdf0e10cSrcweir 		Color aColor;
182cdf0e10cSrcweir 		if ( IsControlForeground() )
183cdf0e10cSrcweir 			aColor = GetControlForeground();
184cdf0e10cSrcweir 		else
185cdf0e10cSrcweir 			aColor = rStyleSettings.GetButtonTextColor();
186cdf0e10cSrcweir 		SetTextColor( aColor );
187cdf0e10cSrcweir 		SetTextFillColor();
188cdf0e10cSrcweir 	}
189cdf0e10cSrcweir 
190cdf0e10cSrcweir 	if ( bBackground )
191cdf0e10cSrcweir 	{
192cdf0e10cSrcweir 		Color aColor;
193cdf0e10cSrcweir 		if ( IsControlBackground() )
194cdf0e10cSrcweir 			aColor = GetControlBackground();
195cdf0e10cSrcweir 		else
196cdf0e10cSrcweir 			aColor = rStyleSettings.GetFaceColor();
197cdf0e10cSrcweir 		SetBackground( aColor );
198cdf0e10cSrcweir 	}
199cdf0e10cSrcweir }
200cdf0e10cSrcweir 
201cdf0e10cSrcweir // -----------------------------------------------------------------------
202cdf0e10cSrcweir 
203cdf0e10cSrcweir long HeaderBar::ImplGetItemPos( sal_uInt16 nPos ) const
204cdf0e10cSrcweir {
205cdf0e10cSrcweir 	long nX = -mnOffset;
206cdf0e10cSrcweir 	for ( sal_uInt16 i = 0; i < nPos; i++ )
207cdf0e10cSrcweir 		nX += mpItemList->GetObject( i )->mnSize;
208cdf0e10cSrcweir 	return nX;
209cdf0e10cSrcweir }
210cdf0e10cSrcweir 
211cdf0e10cSrcweir // -----------------------------------------------------------------------
212cdf0e10cSrcweir 
213cdf0e10cSrcweir Rectangle HeaderBar::ImplGetItemRect( sal_uInt16 nPos ) const
214cdf0e10cSrcweir {
215cdf0e10cSrcweir 	Rectangle aRect( ImplGetItemPos( nPos ), 0, 0, mnDY-1 );
216cdf0e10cSrcweir 	aRect.Right() = aRect.Left() + mpItemList->GetObject( nPos )->mnSize - 1;
217cdf0e10cSrcweir 	// Gegen Ueberlauf auf einigen Systemen testen
218cdf0e10cSrcweir 	if ( aRect.Right() > 16000 )
219cdf0e10cSrcweir 		aRect.Right() = 16000;
220cdf0e10cSrcweir 	return aRect;
221cdf0e10cSrcweir }
222cdf0e10cSrcweir 
223cdf0e10cSrcweir // -----------------------------------------------------------------------
224cdf0e10cSrcweir 
225cdf0e10cSrcweir sal_uInt16 HeaderBar::ImplHitTest( const Point& rPos,
226cdf0e10cSrcweir 							   long& nMouseOff, sal_uInt16& nPos ) const
227cdf0e10cSrcweir {
228cdf0e10cSrcweir 	ImplHeadItem*	pItem;
229cdf0e10cSrcweir 	sal_uInt16			nCount = (sal_uInt16)mpItemList->Count();
230cdf0e10cSrcweir 	sal_Bool			bLastFixed = sal_True;
231cdf0e10cSrcweir 	long			nX = -mnOffset;
232cdf0e10cSrcweir 
233cdf0e10cSrcweir 	for ( sal_uInt16 i = 0; i < nCount; i++ )
234cdf0e10cSrcweir 	{
235cdf0e10cSrcweir 		pItem = mpItemList->GetObject( i );
236cdf0e10cSrcweir 
237cdf0e10cSrcweir 		if ( rPos.X() < (nX+pItem->mnSize) )
238cdf0e10cSrcweir 		{
239cdf0e10cSrcweir 			sal_uInt16 nMode;
240cdf0e10cSrcweir 
241cdf0e10cSrcweir 			if ( !bLastFixed && (rPos.X() < (nX+HEADERBAR_SPLITOFF)) )
242cdf0e10cSrcweir 			{
243cdf0e10cSrcweir 				nMode = HEAD_HITTEST_DIVIDER;
244cdf0e10cSrcweir 				nPos = i-1;
245cdf0e10cSrcweir 				nMouseOff = rPos.X()-nX+1;
246cdf0e10cSrcweir 			}
247cdf0e10cSrcweir 			else
248cdf0e10cSrcweir 			{
249cdf0e10cSrcweir 				nPos = i;
250cdf0e10cSrcweir 
251cdf0e10cSrcweir 				if ( !(pItem->mnBits & HIB_FIXED) && (rPos.X() >= (nX+pItem->mnSize-HEADERBAR_SPLITOFF)) )
252cdf0e10cSrcweir 				{
253cdf0e10cSrcweir 					nMode = HEAD_HITTEST_DIVIDER;
254cdf0e10cSrcweir 					nMouseOff = rPos.X()-(nX+pItem->mnSize);
255cdf0e10cSrcweir 				}
256cdf0e10cSrcweir 				else
257cdf0e10cSrcweir 				{
258cdf0e10cSrcweir 					nMode = HEAD_HITTEST_ITEM;
259cdf0e10cSrcweir 					nMouseOff = rPos.X()-nX;
260cdf0e10cSrcweir 				}
261cdf0e10cSrcweir 			}
262cdf0e10cSrcweir 
263cdf0e10cSrcweir 			return nMode;
264cdf0e10cSrcweir 		}
265cdf0e10cSrcweir 
266cdf0e10cSrcweir 		if ( pItem->mnBits & HIB_FIXED )
267cdf0e10cSrcweir 			bLastFixed = sal_True;
268cdf0e10cSrcweir 		else
269cdf0e10cSrcweir 			bLastFixed = sal_False;
270cdf0e10cSrcweir 
271cdf0e10cSrcweir 		nX += pItem->mnSize;
272cdf0e10cSrcweir 	}
273cdf0e10cSrcweir 
274cdf0e10cSrcweir 	if ( !bLastFixed )
275cdf0e10cSrcweir 	{
276cdf0e10cSrcweir 		pItem = mpItemList->GetObject( nCount-1 );
277cdf0e10cSrcweir 		if ( (pItem->mnSize < 4)  && (rPos.X() < (nX+HEADERBAR_SPLITOFF)) )
278cdf0e10cSrcweir 		{
279cdf0e10cSrcweir 			nPos = nCount-1;
280cdf0e10cSrcweir 			nMouseOff = rPos.X()-nX+1;
281cdf0e10cSrcweir 			return HEAD_HITTEST_DIVIDER;
282cdf0e10cSrcweir 		}
283cdf0e10cSrcweir 	}
284cdf0e10cSrcweir 
285cdf0e10cSrcweir 	return 0;
286cdf0e10cSrcweir }
287cdf0e10cSrcweir 
288cdf0e10cSrcweir // -----------------------------------------------------------------------
289cdf0e10cSrcweir 
290cdf0e10cSrcweir void HeaderBar::ImplInvertDrag( sal_uInt16 nStartPos, sal_uInt16 nEndPos )
291cdf0e10cSrcweir {
292cdf0e10cSrcweir 	Rectangle aRect1 = ImplGetItemRect( nStartPos );
293cdf0e10cSrcweir 	Rectangle aRect2 = ImplGetItemRect( nEndPos );
294cdf0e10cSrcweir 	Point	  aStartPos = aRect1.Center();
295cdf0e10cSrcweir 	Point	  aEndPos = aStartPos;
296cdf0e10cSrcweir 	Rectangle aStartRect( aStartPos.X()-2, aStartPos.Y()-2,
297cdf0e10cSrcweir 						  aStartPos.X()+2, aStartPos.Y()+2 );
298cdf0e10cSrcweir 
299cdf0e10cSrcweir 	if ( nEndPos > nStartPos )
300cdf0e10cSrcweir 	{
301cdf0e10cSrcweir 		aStartPos.X() += 3;
302cdf0e10cSrcweir 		aEndPos.X() = aRect2.Right()-6;
303cdf0e10cSrcweir 	}
304cdf0e10cSrcweir 	else
305cdf0e10cSrcweir 	{
306cdf0e10cSrcweir 		aStartPos.X() -= 3;
307cdf0e10cSrcweir 		aEndPos.X() = aRect2.Left()+6;
308cdf0e10cSrcweir 	}
309cdf0e10cSrcweir 
310cdf0e10cSrcweir 	SetRasterOp( ROP_INVERT );
311cdf0e10cSrcweir 	DrawRect( aStartRect );
312cdf0e10cSrcweir 	DrawLine( aStartPos, aEndPos );
313cdf0e10cSrcweir 	if ( nEndPos > nStartPos )
314cdf0e10cSrcweir 	{
315cdf0e10cSrcweir 		DrawLine( Point( aEndPos.X()+1, aEndPos.Y()-3 ),
316cdf0e10cSrcweir 				  Point( aEndPos.X()+1, aEndPos.Y()+3 ) );
317cdf0e10cSrcweir 		DrawLine( Point( aEndPos.X()+2, aEndPos.Y()-2 ),
318cdf0e10cSrcweir 				  Point( aEndPos.X()+2, aEndPos.Y()+2 ) );
319cdf0e10cSrcweir 		DrawLine( Point( aEndPos.X()+3, aEndPos.Y()-1 ),
320cdf0e10cSrcweir 				  Point( aEndPos.X()+3, aEndPos.Y()+1 ) );
321cdf0e10cSrcweir 		DrawPixel( Point( aEndPos.X()+4, aEndPos.Y() ) );
322cdf0e10cSrcweir 	}
323cdf0e10cSrcweir 	else
324cdf0e10cSrcweir 	{
325cdf0e10cSrcweir 		DrawLine( Point( aEndPos.X()-1, aEndPos.Y()-3 ),
326cdf0e10cSrcweir 				  Point( aEndPos.X()-1, aEndPos.Y()+3 ) );
327cdf0e10cSrcweir 		DrawLine( Point( aEndPos.X()-2, aEndPos.Y()-2 ),
328cdf0e10cSrcweir 				  Point( aEndPos.X()-2, aEndPos.Y()+2 ) );
329cdf0e10cSrcweir 		DrawLine( Point( aEndPos.X()-3, aEndPos.Y()-1 ),
330cdf0e10cSrcweir 				  Point( aEndPos.X()-3, aEndPos.Y()+1 ) );
331cdf0e10cSrcweir 		DrawPixel( Point( aEndPos.X()-4, aEndPos.Y() ) );
332cdf0e10cSrcweir 	}
333cdf0e10cSrcweir 	SetRasterOp( ROP_OVERPAINT );
334cdf0e10cSrcweir }
335cdf0e10cSrcweir 
336cdf0e10cSrcweir // -----------------------------------------------------------------------
337cdf0e10cSrcweir 
338cdf0e10cSrcweir void HeaderBar::ImplDrawItem( OutputDevice* pDev,
339cdf0e10cSrcweir 							  sal_uInt16 nPos, sal_Bool bHigh, sal_Bool bDrag,
340cdf0e10cSrcweir 							  const Rectangle& rItemRect,
341cdf0e10cSrcweir 							  const Rectangle* pRect,
342cdf0e10cSrcweir 							  sal_uLong )
343cdf0e10cSrcweir {
344cdf0e10cSrcweir 	Rectangle aRect = rItemRect;
345cdf0e10cSrcweir 
346cdf0e10cSrcweir 	// Wenn kein Platz, dann brauchen wir auch nichts ausgeben
347cdf0e10cSrcweir 	if ( aRect.GetWidth() <= 1 )
348cdf0e10cSrcweir 		return;
349cdf0e10cSrcweir 
350cdf0e10cSrcweir 	// Feststellen, ob Rectangle ueberhaupt sichtbar
351cdf0e10cSrcweir 	if ( pRect )
352cdf0e10cSrcweir 	{
353cdf0e10cSrcweir 		if ( aRect.Right() < pRect->Left() )
354cdf0e10cSrcweir 			return;
355cdf0e10cSrcweir 		else if ( aRect.Left() > pRect->Right() )
356cdf0e10cSrcweir 			return;
357cdf0e10cSrcweir 	}
358cdf0e10cSrcweir 	else
359cdf0e10cSrcweir 	{
360cdf0e10cSrcweir 		if ( aRect.Right() < 0 )
361cdf0e10cSrcweir 			return;
362cdf0e10cSrcweir 		else if ( aRect.Left() > mnDX )
363cdf0e10cSrcweir 			return;
364cdf0e10cSrcweir 	}
365cdf0e10cSrcweir 
366cdf0e10cSrcweir 	ImplHeadItem*			pItem  = mpItemList->GetObject( nPos );
367cdf0e10cSrcweir 	HeaderBarItemBits		nBits = pItem->mnBits;
368cdf0e10cSrcweir 	const StyleSettings&	rStyleSettings = GetSettings().GetStyleSettings();
369cdf0e10cSrcweir 
370cdf0e10cSrcweir 	// Border muss nicht gemalt werden
371cdf0e10cSrcweir 	aRect.Top() 	+= mnBorderOff1;
372cdf0e10cSrcweir 	aRect.Bottom()	-= mnBorderOff2;
373cdf0e10cSrcweir 
374cdf0e10cSrcweir 	// Hintergrund loeschen
375cdf0e10cSrcweir 	if ( !pRect || bDrag )
376cdf0e10cSrcweir 	{
377cdf0e10cSrcweir 		if ( bDrag )
378cdf0e10cSrcweir 		{
379cdf0e10cSrcweir 			pDev->SetLineColor();
380cdf0e10cSrcweir 			pDev->SetFillColor( rStyleSettings.GetCheckedColor() );
381cdf0e10cSrcweir 			pDev->DrawRect( aRect );
382cdf0e10cSrcweir 		}
383cdf0e10cSrcweir 		else
384cdf0e10cSrcweir 			pDev->DrawWallpaper( aRect, GetBackground() );
385cdf0e10cSrcweir 	}
386cdf0e10cSrcweir 
387cdf0e10cSrcweir 	// Trennlinie malen
388cdf0e10cSrcweir 	pDev->SetLineColor( rStyleSettings.GetDarkShadowColor() );
389cdf0e10cSrcweir 	pDev->DrawLine( Point( aRect.Right(), aRect.Top() ),
390cdf0e10cSrcweir 					Point( aRect.Right(), aRect.Bottom() ) );
391cdf0e10cSrcweir 
392cdf0e10cSrcweir 	// ButtonStyle malen
393cdf0e10cSrcweir     // avoid 3D borders
394cdf0e10cSrcweir     Color aSelectionTextColor( COL_TRANSPARENT );
395cdf0e10cSrcweir     if( bHigh )
396cdf0e10cSrcweir         DrawSelectionBackground( aRect, 1, sal_True, sal_False, sal_False, &aSelectionTextColor );
397cdf0e10cSrcweir 	else if ( !mbButtonStyle || (nBits & HIB_FLAT) )
398cdf0e10cSrcweir         DrawSelectionBackground( aRect, 0, sal_True, sal_False, sal_False, &aSelectionTextColor );
399cdf0e10cSrcweir 
400cdf0e10cSrcweir 	// Wenn kein Platz, dann brauchen wir auch nichts ausgeben
401cdf0e10cSrcweir 	if ( aRect.GetWidth() < 1 )
402cdf0e10cSrcweir 		return;
403cdf0e10cSrcweir 
404cdf0e10cSrcweir 	// Positionen und Groessen berechnen und Inhalt ausgeben
405cdf0e10cSrcweir 	pItem->maOutText = pItem->maText;
406cdf0e10cSrcweir 	Size aImageSize = pItem->maImage.GetSizePixel();
407cdf0e10cSrcweir 	Size aTxtSize( pDev->GetTextWidth( pItem->maOutText ), 0  );
408cdf0e10cSrcweir 	if ( pItem->maOutText.Len() )
409cdf0e10cSrcweir 		aTxtSize.Height() = pDev->GetTextHeight();
410cdf0e10cSrcweir 	long nArrowWidth = 0;
411cdf0e10cSrcweir 	if ( nBits & (HIB_UPARROW | HIB_DOWNARROW) )
412cdf0e10cSrcweir 		nArrowWidth = HEAD_ARROWSIZE2+HEADERBAR_ARROWOFF;
413cdf0e10cSrcweir 
414cdf0e10cSrcweir 	// Wenn kein Platz fuer Image, dann nicht ausgeben
415cdf0e10cSrcweir 	long nTestHeight = aImageSize.Height();
416cdf0e10cSrcweir 	if ( !(nBits & (HIB_LEFTIMAGE | HIB_RIGHTIMAGE)) )
417cdf0e10cSrcweir 		nTestHeight += aTxtSize.Height();
418cdf0e10cSrcweir 	if ( (aImageSize.Width() > aRect.GetWidth()) || (nTestHeight > aRect.GetHeight()) )
419cdf0e10cSrcweir 	{
420cdf0e10cSrcweir 		aImageSize.Width() = 0;
421cdf0e10cSrcweir 		aImageSize.Height() = 0;
422cdf0e10cSrcweir 	}
423cdf0e10cSrcweir 
424cdf0e10cSrcweir 	// Text auf entsprechende Laenge kuerzen
425cdf0e10cSrcweir 	sal_Bool bLeftText = sal_False;
426cdf0e10cSrcweir 	long nMaxTxtWidth = aRect.GetWidth()-(HEADERBAR_TEXTOFF*2)-nArrowWidth;
427cdf0e10cSrcweir 	if ( nBits & (HIB_LEFTIMAGE | HIB_RIGHTIMAGE) )
428cdf0e10cSrcweir 		nMaxTxtWidth -= aImageSize.Width();
429cdf0e10cSrcweir 	long nTxtWidth = aTxtSize.Width();
430cdf0e10cSrcweir 	if ( nTxtWidth > nMaxTxtWidth )
431cdf0e10cSrcweir 	{
432cdf0e10cSrcweir 		bLeftText = sal_True;
433cdf0e10cSrcweir 		// 3 == Len of "..."
434cdf0e10cSrcweir 		pItem->maOutText.AppendAscii( "..." );
435cdf0e10cSrcweir 		do
436cdf0e10cSrcweir 		{
437cdf0e10cSrcweir 			pItem->maOutText.Erase( pItem->maOutText.Len()-3-1, 1 );
438cdf0e10cSrcweir 			nTxtWidth = pDev->GetTextWidth( pItem->maOutText );
439cdf0e10cSrcweir 		}
440cdf0e10cSrcweir 		while ( (nTxtWidth > nMaxTxtWidth) && (pItem->maOutText.Len() > 3) );
441cdf0e10cSrcweir 		if ( pItem->maOutText.Len() == 3 )
442cdf0e10cSrcweir 		{
443cdf0e10cSrcweir 			nTxtWidth = 0;
444cdf0e10cSrcweir 			pItem->maOutText.Erase();
445cdf0e10cSrcweir 		}
446cdf0e10cSrcweir 	}
447cdf0e10cSrcweir 
448cdf0e10cSrcweir 	// Text/Imageposition berechnen
449cdf0e10cSrcweir 	long nTxtPos;
450cdf0e10cSrcweir 	if ( !bLeftText && (nBits & HIB_RIGHT) )
451cdf0e10cSrcweir 	{
452cdf0e10cSrcweir 		nTxtPos = aRect.Right()-nTxtWidth-HEADERBAR_TEXTOFF;
453cdf0e10cSrcweir 		if ( nBits & HIB_RIGHTIMAGE )
454cdf0e10cSrcweir 			nTxtPos -= aImageSize.Width();
455cdf0e10cSrcweir 	}
456cdf0e10cSrcweir 	else if ( !bLeftText && (nBits & HIB_CENTER) )
457cdf0e10cSrcweir 	{
458cdf0e10cSrcweir 		long nTempWidth = nTxtWidth;
459cdf0e10cSrcweir 		if ( nBits & (HIB_LEFTIMAGE | HIB_RIGHTIMAGE) )
460cdf0e10cSrcweir 			nTempWidth += aImageSize.Width();
461cdf0e10cSrcweir 		nTxtPos = aRect.Left()+(aRect.GetWidth()-nTempWidth)/2;
462cdf0e10cSrcweir 		if ( nBits & HIB_LEFTIMAGE )
463cdf0e10cSrcweir 			nTxtPos += aImageSize.Width();
464cdf0e10cSrcweir 		if ( nArrowWidth )
465cdf0e10cSrcweir 		{
466cdf0e10cSrcweir 			if ( nTxtPos+nTxtWidth+nArrowWidth >= aRect.Right() )
467cdf0e10cSrcweir 			{
468cdf0e10cSrcweir 				nTxtPos = aRect.Left()+HEADERBAR_TEXTOFF;
469cdf0e10cSrcweir 				if ( nBits & HIB_LEFTIMAGE )
470cdf0e10cSrcweir 					nTxtPos += aImageSize.Width();
471cdf0e10cSrcweir 			}
472cdf0e10cSrcweir 		}
473cdf0e10cSrcweir 	}
474cdf0e10cSrcweir 	else
475cdf0e10cSrcweir 	{
476cdf0e10cSrcweir 		nTxtPos = aRect.Left()+HEADERBAR_TEXTOFF;
477cdf0e10cSrcweir 		if ( nBits & HIB_LEFTIMAGE )
478cdf0e10cSrcweir 			nTxtPos += aImageSize.Width();
479cdf0e10cSrcweir 		if ( nBits & HIB_RIGHT )
480cdf0e10cSrcweir 			nTxtPos += nArrowWidth;
481cdf0e10cSrcweir 	}
482cdf0e10cSrcweir 
483cdf0e10cSrcweir 	// TextPosition berechnen
484cdf0e10cSrcweir 	long nTxtPosY = 0;
485cdf0e10cSrcweir 	if ( pItem->maOutText.Len() || (nArrowWidth && aTxtSize.Height()) )
486cdf0e10cSrcweir 	{
487cdf0e10cSrcweir 		if ( nBits & HIB_TOP )
488cdf0e10cSrcweir 		{
489cdf0e10cSrcweir 			nTxtPosY = aRect.Top();
490cdf0e10cSrcweir 			if ( !(nBits & (HIB_LEFTIMAGE | HIB_RIGHTIMAGE)) )
491cdf0e10cSrcweir 				nTxtPosY += aImageSize.Height();
492cdf0e10cSrcweir 		}
493cdf0e10cSrcweir 		else if ( nBits & HIB_BOTTOM )
494cdf0e10cSrcweir 			nTxtPosY = aRect.Bottom()-aTxtSize.Height();
495cdf0e10cSrcweir 		else
496cdf0e10cSrcweir 		{
497cdf0e10cSrcweir 			long nTempHeight = aTxtSize.Height();
498cdf0e10cSrcweir 			if ( !(nBits & (HIB_LEFTIMAGE | HIB_RIGHTIMAGE)) )
499cdf0e10cSrcweir 				nTempHeight += aImageSize.Height();
500cdf0e10cSrcweir 			nTxtPosY = aRect.Top()+((aRect.GetHeight()-nTempHeight)/2);
501cdf0e10cSrcweir 			if ( !(nBits & (HIB_LEFTIMAGE | HIB_RIGHTIMAGE)) )
502cdf0e10cSrcweir 				nTxtPosY += aImageSize.Height();
503cdf0e10cSrcweir 		}
504cdf0e10cSrcweir 	}
505cdf0e10cSrcweir 
506cdf0e10cSrcweir 	// Text ausgebeben
507cdf0e10cSrcweir 	if ( pItem->maOutText.Len() )
508cdf0e10cSrcweir 	{
509cdf0e10cSrcweir         if( aSelectionTextColor != Color( COL_TRANSPARENT ) )
510cdf0e10cSrcweir         {
511cdf0e10cSrcweir             pDev->Push( PUSH_TEXTCOLOR );
512cdf0e10cSrcweir             pDev->SetTextColor( aSelectionTextColor );
513cdf0e10cSrcweir         }
514cdf0e10cSrcweir 		if ( IsEnabled() )
515cdf0e10cSrcweir 			pDev->DrawText( Point( nTxtPos, nTxtPosY ), pItem->maOutText );
516cdf0e10cSrcweir 		else
517cdf0e10cSrcweir 			pDev->DrawCtrlText( Point( nTxtPos, nTxtPosY ), pItem->maOutText, 0, STRING_LEN, TEXT_DRAW_DISABLE );
518cdf0e10cSrcweir         if( aSelectionTextColor != Color( COL_TRANSPARENT ) )
519cdf0e10cSrcweir             pDev->Pop();
520cdf0e10cSrcweir 	}
521cdf0e10cSrcweir 
522cdf0e10cSrcweir 	// Wenn Image vorhanden, Position berechnen und ausgeben
523cdf0e10cSrcweir 	long nImagePosY = 0;
524cdf0e10cSrcweir 	if ( aImageSize.Width() && aImageSize.Height() )
525cdf0e10cSrcweir 	{
526cdf0e10cSrcweir 		long nImagePos = nTxtPos;
527cdf0e10cSrcweir 		if ( nBits & HIB_LEFTIMAGE )
528cdf0e10cSrcweir 		{
529cdf0e10cSrcweir 			nImagePos -= aImageSize.Width();
530cdf0e10cSrcweir 			if ( nBits & HIB_RIGHT )
531cdf0e10cSrcweir 				nImagePos -= nArrowWidth;
532cdf0e10cSrcweir 		}
533cdf0e10cSrcweir 		else if ( nBits & HIB_RIGHTIMAGE )
534cdf0e10cSrcweir 		{
535cdf0e10cSrcweir 			nImagePos += nTxtWidth;
536cdf0e10cSrcweir 			if ( !(nBits & HIB_RIGHT) )
537cdf0e10cSrcweir 				nImagePos += nArrowWidth;
538cdf0e10cSrcweir 		}
539cdf0e10cSrcweir 		else
540cdf0e10cSrcweir 		{
541cdf0e10cSrcweir 			if ( nBits & HIB_RIGHT )
542cdf0e10cSrcweir 				nImagePos = aRect.Right()-aImageSize.Width();
543cdf0e10cSrcweir 			else if ( nBits & HIB_CENTER )
544cdf0e10cSrcweir 				nImagePos = aRect.Left()+(aRect.GetWidth()-aImageSize.Width())/2;
545cdf0e10cSrcweir 			else
546cdf0e10cSrcweir 				nImagePos = aRect.Left()+HEADERBAR_TEXTOFF;
547cdf0e10cSrcweir 		}
548cdf0e10cSrcweir 
549cdf0e10cSrcweir 		if ( nBits & HIB_TOP )
550cdf0e10cSrcweir 			nImagePosY = aRect.Top();
551cdf0e10cSrcweir 		else if ( nBits & HIB_BOTTOM )
552cdf0e10cSrcweir 		{
553cdf0e10cSrcweir 			nImagePosY = aRect.Bottom()-aImageSize.Height();
554cdf0e10cSrcweir 			if ( !(nBits & (HIB_LEFTIMAGE | HIB_RIGHTIMAGE)) )
555cdf0e10cSrcweir 				nImagePosY -= aTxtSize.Height();
556cdf0e10cSrcweir 		}
557cdf0e10cSrcweir 		else
558cdf0e10cSrcweir 		{
559cdf0e10cSrcweir 			long nTempHeight = aImageSize.Height();
560cdf0e10cSrcweir 			if ( !(nBits & (HIB_LEFTIMAGE | HIB_RIGHTIMAGE)) )
561cdf0e10cSrcweir 				nTempHeight += aTxtSize.Height();
562cdf0e10cSrcweir 			nImagePosY = aRect.Top()+((aRect.GetHeight()-nTempHeight)/2);
563cdf0e10cSrcweir 		}
564cdf0e10cSrcweir 		if ( nImagePos+aImageSize.Width() <= aRect.Right() )
565cdf0e10cSrcweir 		{
566cdf0e10cSrcweir 			sal_uInt16 nStyle = 0;
567cdf0e10cSrcweir 			if ( !IsEnabled() )
568cdf0e10cSrcweir 				nStyle |= IMAGE_DRAW_DISABLE;
569cdf0e10cSrcweir 			pDev->DrawImage( Point( nImagePos, nImagePosY ), pItem->maImage, nStyle );
570cdf0e10cSrcweir 		}
571cdf0e10cSrcweir 	}
572cdf0e10cSrcweir 
573cdf0e10cSrcweir 	if ( nBits & (HIB_UPARROW | HIB_DOWNARROW) )
574cdf0e10cSrcweir 	{
575cdf0e10cSrcweir 		long nArrowX = nTxtPos;
576cdf0e10cSrcweir 		if ( nBits & HIB_RIGHT )
577cdf0e10cSrcweir 			nArrowX -= nArrowWidth;
578cdf0e10cSrcweir 		else
579cdf0e10cSrcweir 			nArrowX += nTxtWidth+HEADERBAR_ARROWOFF;
580cdf0e10cSrcweir 		if ( !(nBits & (HIB_LEFTIMAGE | HIB_RIGHTIMAGE)) && !pItem->maText.Len() )
581cdf0e10cSrcweir 		{
582cdf0e10cSrcweir 			if ( nBits & HIB_RIGHT )
583cdf0e10cSrcweir 				nArrowX -= aImageSize.Width();
584cdf0e10cSrcweir 			else
585cdf0e10cSrcweir 				nArrowX += aImageSize.Width();
586cdf0e10cSrcweir 		}
587cdf0e10cSrcweir 
588cdf0e10cSrcweir 		// Feststellen, ob Platz genug ist, das Item zu malen
589cdf0e10cSrcweir 		sal_Bool bDraw = sal_True;
590cdf0e10cSrcweir 		if ( nArrowX < aRect.Left()+HEADERBAR_TEXTOFF )
591cdf0e10cSrcweir 			bDraw = sal_False;
592cdf0e10cSrcweir 		else if ( nArrowX+HEAD_ARROWSIZE2 > aRect.Right() )
593cdf0e10cSrcweir 			bDraw = sal_False;
594cdf0e10cSrcweir 
595cdf0e10cSrcweir 		if ( bDraw )
596cdf0e10cSrcweir 		{
597cdf0e10cSrcweir 			long nArrowY;
598cdf0e10cSrcweir 			if ( aTxtSize.Height() )
599cdf0e10cSrcweir 				nArrowY = nTxtPosY+(aTxtSize.Height()/2);
600cdf0e10cSrcweir 			else if ( aImageSize.Width() && aImageSize.Height() )
601cdf0e10cSrcweir 				nArrowY = nImagePosY+(aImageSize.Height()/2);
602cdf0e10cSrcweir 			else
603cdf0e10cSrcweir 			{
604cdf0e10cSrcweir 				if ( nBits & HIB_TOP )
605cdf0e10cSrcweir 					nArrowY = aRect.Top()+1;
606cdf0e10cSrcweir 				else if ( nBits & HIB_BOTTOM )
607cdf0e10cSrcweir 					nArrowY = aRect.Bottom()-HEAD_ARROWSIZE2-1;
608cdf0e10cSrcweir 				else
609cdf0e10cSrcweir 					nArrowY = aRect.Top()+((aRect.GetHeight()-HEAD_ARROWSIZE2)/2);;
610cdf0e10cSrcweir 			}
611cdf0e10cSrcweir 			nArrowY -= HEAD_ARROWSIZE1-1;
612cdf0e10cSrcweir 			if ( nBits & HIB_DOWNARROW )
613cdf0e10cSrcweir 			{
614cdf0e10cSrcweir 				pDev->SetLineColor( rStyleSettings.GetLightColor() );
615cdf0e10cSrcweir 				pDev->DrawLine( Point( nArrowX, nArrowY ),
616cdf0e10cSrcweir 								Point( nArrowX+HEAD_ARROWSIZE2, nArrowY ) );
617cdf0e10cSrcweir 				pDev->DrawLine( Point( nArrowX, nArrowY ),
618cdf0e10cSrcweir 								Point( nArrowX+HEAD_ARROWSIZE1, nArrowY+HEAD_ARROWSIZE2 ) );
619cdf0e10cSrcweir 				pDev->SetLineColor( rStyleSettings.GetShadowColor() );
620cdf0e10cSrcweir 				pDev->DrawLine( Point( nArrowX+HEAD_ARROWSIZE1, nArrowY+HEAD_ARROWSIZE2 ),
621cdf0e10cSrcweir 								Point( nArrowX+HEAD_ARROWSIZE2, nArrowY ) );
622cdf0e10cSrcweir 			}
623cdf0e10cSrcweir 			else
624cdf0e10cSrcweir 			{
625cdf0e10cSrcweir 				pDev->SetLineColor( rStyleSettings.GetLightColor() );
626cdf0e10cSrcweir 				pDev->DrawLine( Point( nArrowX, nArrowY+HEAD_ARROWSIZE2 ),
627cdf0e10cSrcweir 								Point( nArrowX+HEAD_ARROWSIZE1, nArrowY ) );
628cdf0e10cSrcweir 				pDev->SetLineColor( rStyleSettings.GetShadowColor() );
629cdf0e10cSrcweir 				pDev->DrawLine( Point( nArrowX, nArrowY+HEAD_ARROWSIZE2 ),
630cdf0e10cSrcweir 								Point( nArrowX+HEAD_ARROWSIZE2, nArrowY+HEAD_ARROWSIZE2 ) );
631cdf0e10cSrcweir 				pDev->DrawLine( Point( nArrowX+HEAD_ARROWSIZE2, nArrowY+HEAD_ARROWSIZE2 ),
632cdf0e10cSrcweir 								Point( nArrowX+HEAD_ARROWSIZE1, nArrowY ) );
633cdf0e10cSrcweir 			}
634cdf0e10cSrcweir 		}
635cdf0e10cSrcweir 	}
636cdf0e10cSrcweir 
637cdf0e10cSrcweir 	// Gegebenenfalls auch UserDraw aufrufen
638cdf0e10cSrcweir 	if ( nBits & HIB_USERDRAW )
639cdf0e10cSrcweir 	{
640cdf0e10cSrcweir 		Region aRegion( aRect );
641cdf0e10cSrcweir 		if ( pRect )
642cdf0e10cSrcweir 			aRegion.Intersect( *pRect );
643cdf0e10cSrcweir 		pDev->SetClipRegion( aRegion );
644cdf0e10cSrcweir 		UserDrawEvent aODEvt( pDev, aRect, pItem->mnId );
645cdf0e10cSrcweir 		UserDraw( aODEvt );
646cdf0e10cSrcweir 		pDev->SetClipRegion();
647cdf0e10cSrcweir 	}
648cdf0e10cSrcweir }
649cdf0e10cSrcweir 
650cdf0e10cSrcweir // -----------------------------------------------------------------------
651cdf0e10cSrcweir 
652cdf0e10cSrcweir void HeaderBar::ImplDrawItem( sal_uInt16 nPos, sal_Bool bHigh, sal_Bool bDrag,
653cdf0e10cSrcweir 							  const Rectangle* pRect )
654cdf0e10cSrcweir {
655cdf0e10cSrcweir 	Rectangle aRect = ImplGetItemRect( nPos );
656cdf0e10cSrcweir 	ImplDrawItem( this, nPos, bHigh, bDrag, aRect, pRect, 0 );
657cdf0e10cSrcweir }
658cdf0e10cSrcweir 
659cdf0e10cSrcweir // -----------------------------------------------------------------------
660cdf0e10cSrcweir 
661cdf0e10cSrcweir void HeaderBar::ImplUpdate( sal_uInt16 nPos, sal_Bool bEnd, sal_Bool bDirect )
662cdf0e10cSrcweir {
663cdf0e10cSrcweir 	if ( IsVisible() && IsUpdateMode() )
664cdf0e10cSrcweir 	{
665cdf0e10cSrcweir 		if ( !bDirect )
666cdf0e10cSrcweir 		{
667cdf0e10cSrcweir 			Rectangle	aRect;
668cdf0e10cSrcweir 			sal_uInt16		nItemCount = (sal_uInt16)(mpItemList->Count());
669cdf0e10cSrcweir 			if ( nPos < nItemCount )
670cdf0e10cSrcweir 				aRect = ImplGetItemRect( nPos );
671cdf0e10cSrcweir 			else
672cdf0e10cSrcweir 			{
673cdf0e10cSrcweir 				aRect.Bottom() = mnDY-1;
674cdf0e10cSrcweir 				if ( nItemCount )
675cdf0e10cSrcweir 					aRect.Left() = ImplGetItemRect( nItemCount-1 ).Right();
676cdf0e10cSrcweir 			}
677cdf0e10cSrcweir 			if ( bEnd )
678cdf0e10cSrcweir 				aRect.Right() = mnDX-1;
679cdf0e10cSrcweir 			aRect.Top() 	+= mnBorderOff1;
680cdf0e10cSrcweir 			aRect.Bottom()	-= mnBorderOff2;
681cdf0e10cSrcweir 			Invalidate( aRect );
682cdf0e10cSrcweir 		}
683cdf0e10cSrcweir 		else
684cdf0e10cSrcweir 		{
685cdf0e10cSrcweir 			for ( sal_uInt16 i = nPos; i < mpItemList->Count(); i++ )
686cdf0e10cSrcweir 				ImplDrawItem( i );
687cdf0e10cSrcweir 			if ( bEnd )
688cdf0e10cSrcweir 			{
689cdf0e10cSrcweir 				Rectangle aRect = ImplGetItemRect( (sal_uInt16)mpItemList->Count() );
690cdf0e10cSrcweir 				aRect.Left()  = aRect.Right();
691cdf0e10cSrcweir 				aRect.Right() = mnDX-1;
692cdf0e10cSrcweir 				if ( aRect.Left() < aRect.Right() )
693cdf0e10cSrcweir 				{
694cdf0e10cSrcweir 					aRect.Top() 	+= mnBorderOff1;
695cdf0e10cSrcweir 					aRect.Bottom()	-= mnBorderOff2;
696cdf0e10cSrcweir 					Erase( aRect );
697cdf0e10cSrcweir 				}
698cdf0e10cSrcweir 			}
699cdf0e10cSrcweir 		}
700cdf0e10cSrcweir 	}
701cdf0e10cSrcweir }
702cdf0e10cSrcweir 
703cdf0e10cSrcweir // -----------------------------------------------------------------------
704cdf0e10cSrcweir 
705cdf0e10cSrcweir void HeaderBar::ImplStartDrag( const Point& rMousePos, sal_Bool bCommand )
706cdf0e10cSrcweir {
707cdf0e10cSrcweir 	sal_uInt16	nPos;
708cdf0e10cSrcweir 	sal_uInt16	nHitTest = ImplHitTest( rMousePos, mnMouseOff, nPos );
709cdf0e10cSrcweir 	if ( nHitTest )
710cdf0e10cSrcweir 	{
711cdf0e10cSrcweir 		mbDrag = sal_False;
712cdf0e10cSrcweir 		ImplHeadItem* pItem = mpItemList->GetObject( nPos );
713cdf0e10cSrcweir 		if ( nHitTest & HEAD_HITTEST_DIVIDER )
714cdf0e10cSrcweir 			mbDrag = sal_True;
715cdf0e10cSrcweir 		else
716cdf0e10cSrcweir 		{
717cdf0e10cSrcweir 			if ( ((pItem->mnBits & HIB_CLICKABLE) && !(pItem->mnBits & HIB_FLAT)) ||
718cdf0e10cSrcweir 				 (mbDragable && !(pItem->mnBits & HIB_FIXEDPOS)) )
719cdf0e10cSrcweir 			{
720cdf0e10cSrcweir 				mbItemMode = sal_True;
721cdf0e10cSrcweir 				mbDrag = sal_True;
722cdf0e10cSrcweir 				if ( bCommand )
723cdf0e10cSrcweir 				{
724cdf0e10cSrcweir 					if ( mbDragable )
725cdf0e10cSrcweir 						mbItemDrag = sal_True;
726cdf0e10cSrcweir 					else
727cdf0e10cSrcweir 					{
728cdf0e10cSrcweir 						mbItemMode = sal_False;
729cdf0e10cSrcweir 						mbDrag = sal_False;
730cdf0e10cSrcweir 					}
731cdf0e10cSrcweir 				}
732cdf0e10cSrcweir 			}
733cdf0e10cSrcweir 			else
734cdf0e10cSrcweir 			{
735cdf0e10cSrcweir 				if ( !bCommand )
736cdf0e10cSrcweir 				{
737cdf0e10cSrcweir 					mnCurItemId = pItem->mnId;
738cdf0e10cSrcweir 					Select();
739cdf0e10cSrcweir 					mnCurItemId = 0;
740cdf0e10cSrcweir 				}
741cdf0e10cSrcweir 			}
742cdf0e10cSrcweir 		}
743cdf0e10cSrcweir 
744cdf0e10cSrcweir 		if ( mbDrag )
745cdf0e10cSrcweir 		{
746cdf0e10cSrcweir 			mbOutDrag = sal_False;
747cdf0e10cSrcweir 			mnCurItemId = pItem->mnId;
748cdf0e10cSrcweir 			mnItemDragPos = nPos;
749cdf0e10cSrcweir 			StartTracking();
750cdf0e10cSrcweir 			mnStartPos = rMousePos.X()-mnMouseOff;
751cdf0e10cSrcweir 			mnDragPos = mnStartPos;
752cdf0e10cSrcweir 			StartDrag();
753cdf0e10cSrcweir 			if ( mbItemMode )
754cdf0e10cSrcweir 				ImplDrawItem( nPos, sal_True, mbItemDrag );
755cdf0e10cSrcweir 			else
756cdf0e10cSrcweir 			{
757cdf0e10cSrcweir 				Rectangle aSizeRect( mnDragPos, 0, mnDragPos, mnDragSize+mnDY );
758cdf0e10cSrcweir 				ShowTracking( aSizeRect, SHOWTRACK_SPLIT );
759cdf0e10cSrcweir 			}
760cdf0e10cSrcweir 		}
761cdf0e10cSrcweir 		else
762cdf0e10cSrcweir 			mnMouseOff = 0;
763cdf0e10cSrcweir 	}
764cdf0e10cSrcweir }
765cdf0e10cSrcweir 
766cdf0e10cSrcweir // -----------------------------------------------------------------------
767cdf0e10cSrcweir 
768cdf0e10cSrcweir void HeaderBar::ImplDrag( const Point& rMousePos )
769cdf0e10cSrcweir {
770cdf0e10cSrcweir 	sal_Bool	bNewOutDrag;
771cdf0e10cSrcweir 	sal_uInt16	nPos = GetItemPos( mnCurItemId );
772cdf0e10cSrcweir 
773cdf0e10cSrcweir 	mnDragPos = rMousePos.X()-mnMouseOff;
774cdf0e10cSrcweir 	if ( mbItemMode )
775cdf0e10cSrcweir 	{
776cdf0e10cSrcweir 		Rectangle aItemRect = ImplGetItemRect( nPos );
777cdf0e10cSrcweir 		if ( aItemRect.IsInside( rMousePos ) )
778cdf0e10cSrcweir 			bNewOutDrag = sal_False;
779cdf0e10cSrcweir 		else
780cdf0e10cSrcweir 			bNewOutDrag = sal_True;
781cdf0e10cSrcweir 
782cdf0e10cSrcweir 		// Evt. ItemDrag anschalten
783cdf0e10cSrcweir 		if ( bNewOutDrag && mbDragable && !mbItemDrag &&
784cdf0e10cSrcweir 			 !(mpItemList->GetObject(nPos)->mnBits & HIB_FIXEDPOS) )
785cdf0e10cSrcweir 		{
786cdf0e10cSrcweir 			if ( (rMousePos.Y() >= aItemRect.Top()) && (rMousePos.Y() <= aItemRect.Bottom()) )
787cdf0e10cSrcweir 			{
788cdf0e10cSrcweir 				mbItemDrag = sal_True;
789cdf0e10cSrcweir 				ImplDrawItem( nPos, sal_True, mbItemDrag );
790cdf0e10cSrcweir 			}
791cdf0e10cSrcweir 		}
792cdf0e10cSrcweir 
793cdf0e10cSrcweir 		sal_uInt16 nOldItemDragPos = mnItemDragPos;
794cdf0e10cSrcweir 		if ( mbItemDrag )
795cdf0e10cSrcweir 		{
796cdf0e10cSrcweir 			if ( (rMousePos.Y() < -HEADERBAR_DRAGOUTOFF) || (rMousePos.Y() > mnDY+HEADERBAR_DRAGOUTOFF) )
797cdf0e10cSrcweir 				bNewOutDrag = sal_True;
798cdf0e10cSrcweir 			else
799cdf0e10cSrcweir 				bNewOutDrag = sal_False;
800cdf0e10cSrcweir 
801cdf0e10cSrcweir 			if ( bNewOutDrag )
802cdf0e10cSrcweir 				mnItemDragPos = HEADERBAR_ITEM_NOTFOUND;
803cdf0e10cSrcweir 			else
804cdf0e10cSrcweir 			{
805cdf0e10cSrcweir 				sal_uInt16 nTempId = GetItemId( Point( rMousePos.X(), 2 ) );
806cdf0e10cSrcweir 				if ( nTempId )
807cdf0e10cSrcweir 					mnItemDragPos = GetItemPos( nTempId );
808cdf0e10cSrcweir 				else
809cdf0e10cSrcweir 				{
810cdf0e10cSrcweir 					if ( rMousePos.X() <= 0 )
811cdf0e10cSrcweir 						mnItemDragPos = 0;
812cdf0e10cSrcweir 					else
813cdf0e10cSrcweir 						mnItemDragPos = GetItemCount()-1;
814cdf0e10cSrcweir 				}
815cdf0e10cSrcweir 
816cdf0e10cSrcweir 				// Nicht verschiebbare Items aussparen
817cdf0e10cSrcweir 				if ( mnItemDragPos < nPos )
818cdf0e10cSrcweir 				{
819cdf0e10cSrcweir 					while ( (mpItemList->GetObject(mnItemDragPos)->mnBits & HIB_FIXEDPOS) &&
820cdf0e10cSrcweir 							(mnItemDragPos < nPos) )
821cdf0e10cSrcweir 						mnItemDragPos++;
822cdf0e10cSrcweir 				}
823cdf0e10cSrcweir 				else if ( mnItemDragPos > nPos )
824cdf0e10cSrcweir 				{
825cdf0e10cSrcweir 					while ( (mpItemList->GetObject(mnItemDragPos)->mnBits & HIB_FIXEDPOS) &&
826cdf0e10cSrcweir 							(mnItemDragPos > nPos) )
827cdf0e10cSrcweir 						mnItemDragPos--;
828cdf0e10cSrcweir 				}
829cdf0e10cSrcweir 			}
830cdf0e10cSrcweir 
831cdf0e10cSrcweir 			if ( (mnItemDragPos != nOldItemDragPos) &&
832cdf0e10cSrcweir 				 (nOldItemDragPos != nPos) &&
833cdf0e10cSrcweir 				 (nOldItemDragPos != HEADERBAR_ITEM_NOTFOUND) )
834cdf0e10cSrcweir 			{
835cdf0e10cSrcweir 				ImplInvertDrag( nPos, nOldItemDragPos );
836cdf0e10cSrcweir 				ImplDrawItem( nOldItemDragPos );
837cdf0e10cSrcweir 			}
838cdf0e10cSrcweir 		}
839cdf0e10cSrcweir 
840cdf0e10cSrcweir 		if ( bNewOutDrag != mbOutDrag )
841cdf0e10cSrcweir 			ImplDrawItem( nPos, !bNewOutDrag, mbItemDrag );
842cdf0e10cSrcweir 
843cdf0e10cSrcweir 		if ( mbItemDrag  )
844cdf0e10cSrcweir 		{
845cdf0e10cSrcweir 			if ( (mnItemDragPos != nOldItemDragPos) &&
846cdf0e10cSrcweir 				 (mnItemDragPos != nPos) &&
847cdf0e10cSrcweir 				 (mnItemDragPos != HEADERBAR_ITEM_NOTFOUND) )
848cdf0e10cSrcweir 			{
849cdf0e10cSrcweir 				ImplDrawItem( mnItemDragPos, sal_False, sal_True );
850cdf0e10cSrcweir 				ImplInvertDrag( nPos, mnItemDragPos );
851cdf0e10cSrcweir 			}
852cdf0e10cSrcweir 		}
853cdf0e10cSrcweir 
854cdf0e10cSrcweir 		mbOutDrag = bNewOutDrag;
855cdf0e10cSrcweir 	}
856cdf0e10cSrcweir 	else
857cdf0e10cSrcweir 	{
858cdf0e10cSrcweir 		Rectangle aItemRect = ImplGetItemRect( nPos );
859cdf0e10cSrcweir 		if ( mnDragPos < aItemRect.Left() )
860cdf0e10cSrcweir 			mnDragPos = aItemRect.Left();
861cdf0e10cSrcweir 		if ( (mnDragPos < 0) || (mnDragPos > mnDX-1) )
862cdf0e10cSrcweir 			HideTracking();
863cdf0e10cSrcweir 		else
864cdf0e10cSrcweir 		{
865cdf0e10cSrcweir 			Rectangle aSizeRect( mnDragPos, 0, mnDragPos, mnDragSize+mnDY );
866cdf0e10cSrcweir 			ShowTracking( aSizeRect, SHOWTRACK_SPLIT );
867cdf0e10cSrcweir 		}
868cdf0e10cSrcweir 	}
869cdf0e10cSrcweir 
870cdf0e10cSrcweir 	Drag();
871cdf0e10cSrcweir }
872cdf0e10cSrcweir 
873cdf0e10cSrcweir // -----------------------------------------------------------------------
874cdf0e10cSrcweir 
875cdf0e10cSrcweir void HeaderBar::ImplEndDrag( sal_Bool bCancel )
876cdf0e10cSrcweir {
877cdf0e10cSrcweir 	HideTracking();
878cdf0e10cSrcweir 
879cdf0e10cSrcweir 	if ( bCancel || mbOutDrag )
880cdf0e10cSrcweir 	{
881cdf0e10cSrcweir 		if ( mbItemMode && (!mbOutDrag || mbItemDrag) )
882cdf0e10cSrcweir 		{
883cdf0e10cSrcweir 			sal_uInt16 nPos = GetItemPos( mnCurItemId );
884cdf0e10cSrcweir 			ImplDrawItem( nPos );
885cdf0e10cSrcweir 		}
886cdf0e10cSrcweir 
887cdf0e10cSrcweir 		mnCurItemId = 0;
888cdf0e10cSrcweir 	}
889cdf0e10cSrcweir 	else
890cdf0e10cSrcweir 	{
891cdf0e10cSrcweir 		sal_uInt16 nPos = GetItemPos( mnCurItemId );
892cdf0e10cSrcweir 		if ( mbItemMode )
893cdf0e10cSrcweir 		{
894cdf0e10cSrcweir 			if ( mbItemDrag )
895cdf0e10cSrcweir 			{
896cdf0e10cSrcweir 				Pointer aPointer( POINTER_ARROW );
897cdf0e10cSrcweir 				SetPointer( aPointer );
898cdf0e10cSrcweir 				if ( (mnItemDragPos != nPos) &&
899cdf0e10cSrcweir 					 (mnItemDragPos != HEADERBAR_ITEM_NOTFOUND) )
900cdf0e10cSrcweir 				{
901cdf0e10cSrcweir 					ImplInvertDrag( nPos, mnItemDragPos );
902cdf0e10cSrcweir 					MoveItem( mnCurItemId, mnItemDragPos );
903cdf0e10cSrcweir 				}
904cdf0e10cSrcweir 				else
905cdf0e10cSrcweir 					ImplDrawItem( nPos );
906cdf0e10cSrcweir 			}
907cdf0e10cSrcweir 			else
908cdf0e10cSrcweir 			{
909cdf0e10cSrcweir 				Select();
910cdf0e10cSrcweir 				ImplUpdate( nPos );
911cdf0e10cSrcweir 			}
912cdf0e10cSrcweir 		}
913cdf0e10cSrcweir 		else
914cdf0e10cSrcweir 		{
915cdf0e10cSrcweir 			long nDelta = mnDragPos - mnStartPos;
916cdf0e10cSrcweir 			if ( nDelta )
917cdf0e10cSrcweir 			{
918cdf0e10cSrcweir 				ImplHeadItem* pItem = mpItemList->GetObject( nPos );
919cdf0e10cSrcweir 				pItem->mnSize += nDelta;
920cdf0e10cSrcweir 				ImplUpdate( nPos, sal_True );
921cdf0e10cSrcweir 			}
922cdf0e10cSrcweir 		}
923cdf0e10cSrcweir 	}
924cdf0e10cSrcweir 
925cdf0e10cSrcweir 	mbDrag			= sal_False;
926cdf0e10cSrcweir 	EndDrag();
927cdf0e10cSrcweir 	mnCurItemId 	= 0;
928cdf0e10cSrcweir 	mnItemDragPos	= HEADERBAR_ITEM_NOTFOUND;
929cdf0e10cSrcweir 	mbOutDrag		= sal_False;
930cdf0e10cSrcweir 	mbItemMode		= sal_False;
931cdf0e10cSrcweir 	mbItemDrag		= sal_False;
932cdf0e10cSrcweir }
933cdf0e10cSrcweir 
934cdf0e10cSrcweir // -----------------------------------------------------------------------
935cdf0e10cSrcweir 
936cdf0e10cSrcweir void HeaderBar::MouseButtonDown( const MouseEvent& rMEvt )
937cdf0e10cSrcweir {
938cdf0e10cSrcweir 	if ( rMEvt.IsLeft() )
939cdf0e10cSrcweir 	{
940cdf0e10cSrcweir 		if ( rMEvt.GetClicks() == 2 )
941cdf0e10cSrcweir 		{
942cdf0e10cSrcweir 			long	nTemp;
943cdf0e10cSrcweir 			sal_uInt16	nPos;
944cdf0e10cSrcweir 			sal_uInt16	nHitTest = ImplHitTest( rMEvt.GetPosPixel(), nTemp, nPos );
945cdf0e10cSrcweir 			if ( nHitTest )
946cdf0e10cSrcweir 			{
947cdf0e10cSrcweir 				ImplHeadItem* pItem = mpItemList->GetObject( nPos );
948cdf0e10cSrcweir 				if ( nHitTest & HEAD_HITTEST_DIVIDER )
949cdf0e10cSrcweir 					mbItemMode = sal_False;
950cdf0e10cSrcweir 				else
951cdf0e10cSrcweir 					mbItemMode = sal_True;
952cdf0e10cSrcweir 				mnCurItemId = pItem->mnId;
953cdf0e10cSrcweir 				DoubleClick();
954cdf0e10cSrcweir 				mbItemMode = sal_False;
955cdf0e10cSrcweir 				mnCurItemId = 0;
956cdf0e10cSrcweir 			}
957cdf0e10cSrcweir 		}
958cdf0e10cSrcweir 		else
959cdf0e10cSrcweir 			ImplStartDrag( rMEvt.GetPosPixel(), sal_False );
960cdf0e10cSrcweir 	}
961cdf0e10cSrcweir }
962cdf0e10cSrcweir 
963cdf0e10cSrcweir // -----------------------------------------------------------------------
964cdf0e10cSrcweir 
965cdf0e10cSrcweir void HeaderBar::MouseMove( const MouseEvent& rMEvt )
966cdf0e10cSrcweir {
967cdf0e10cSrcweir 	long			nTemp1;
968cdf0e10cSrcweir 	sal_uInt16			nTemp2;
969cdf0e10cSrcweir 	PointerStyle	eStyle = POINTER_ARROW;
970cdf0e10cSrcweir 	sal_uInt16			nHitTest = ImplHitTest( rMEvt.GetPosPixel(), nTemp1, nTemp2 );
971cdf0e10cSrcweir 
972cdf0e10cSrcweir 	if ( nHitTest & HEAD_HITTEST_DIVIDER )
973cdf0e10cSrcweir 		eStyle = POINTER_HSIZEBAR;
974cdf0e10cSrcweir 	Pointer aPtr( eStyle );
975cdf0e10cSrcweir 	SetPointer( aPtr );
976cdf0e10cSrcweir }
977cdf0e10cSrcweir 
978cdf0e10cSrcweir // -----------------------------------------------------------------------
979cdf0e10cSrcweir 
980cdf0e10cSrcweir void HeaderBar::Tracking( const TrackingEvent& rTEvt )
981cdf0e10cSrcweir {
982cdf0e10cSrcweir 	Point aMousePos = rTEvt.GetMouseEvent().GetPosPixel();
983cdf0e10cSrcweir 
984cdf0e10cSrcweir 	if ( rTEvt.IsTrackingEnded() )
985cdf0e10cSrcweir 		ImplEndDrag( rTEvt.IsTrackingCanceled() );
986cdf0e10cSrcweir 	else
987cdf0e10cSrcweir 		ImplDrag( aMousePos );
988cdf0e10cSrcweir }
989cdf0e10cSrcweir 
990cdf0e10cSrcweir // -----------------------------------------------------------------------
991cdf0e10cSrcweir 
992cdf0e10cSrcweir void HeaderBar::Paint( const Rectangle& rRect )
993cdf0e10cSrcweir {
994cdf0e10cSrcweir 	if ( mnBorderOff1 || mnBorderOff2 )
995cdf0e10cSrcweir 	{
996cdf0e10cSrcweir 		SetLineColor( GetSettings().GetStyleSettings().GetDarkShadowColor() );
997cdf0e10cSrcweir 		if ( mnBorderOff1 )
998cdf0e10cSrcweir 			DrawLine( Point( 0, 0 ), Point( mnDX-1, 0 ) );
999cdf0e10cSrcweir 		if ( mnBorderOff2 )
1000cdf0e10cSrcweir 			DrawLine( Point( 0, mnDY-1 ), Point( mnDX-1, mnDY-1 ) );
1001cdf0e10cSrcweir         // #i40393# draw left and right border, if WB_BORDER was set in ImplInit()
1002cdf0e10cSrcweir         if ( mnBorderOff1 && mnBorderOff2 )
1003cdf0e10cSrcweir         {
1004cdf0e10cSrcweir             DrawLine( Point( 0, 0 ), Point( 0, mnDY-1 ) );
1005cdf0e10cSrcweir             DrawLine( Point( mnDX-1, 0 ), Point( mnDX-1, mnDY-1 ) );
1006cdf0e10cSrcweir         }
1007cdf0e10cSrcweir 	}
1008cdf0e10cSrcweir 
1009cdf0e10cSrcweir 	sal_uInt16 nCurItemPos;
1010cdf0e10cSrcweir 	if ( mbDrag )
1011cdf0e10cSrcweir 		nCurItemPos = GetItemPos( mnCurItemId );
1012cdf0e10cSrcweir 	else
1013cdf0e10cSrcweir 		nCurItemPos = HEADERBAR_ITEM_NOTFOUND;
1014cdf0e10cSrcweir 	sal_uInt16 nItemCount = (sal_uInt16)mpItemList->Count();
1015cdf0e10cSrcweir 	for ( sal_uInt16 i = 0; i < nItemCount; i++ )
1016cdf0e10cSrcweir 		ImplDrawItem( i, (i == nCurItemPos) ? sal_True : sal_False, sal_False, &rRect );
1017cdf0e10cSrcweir }
1018cdf0e10cSrcweir 
1019cdf0e10cSrcweir // -----------------------------------------------------------------------
1020cdf0e10cSrcweir 
1021cdf0e10cSrcweir void HeaderBar::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize,
1022cdf0e10cSrcweir 					  sal_uLong nFlags )
1023cdf0e10cSrcweir {
1024cdf0e10cSrcweir 	Point		aPos  = pDev->LogicToPixel( rPos );
1025cdf0e10cSrcweir 	Size		aSize = pDev->LogicToPixel( rSize );
1026cdf0e10cSrcweir 	Rectangle	aRect( aPos, aSize );
1027cdf0e10cSrcweir 	Font		aFont = GetDrawPixelFont( pDev );
1028cdf0e10cSrcweir 
1029cdf0e10cSrcweir 	pDev->Push();
1030cdf0e10cSrcweir 	pDev->SetMapMode();
1031cdf0e10cSrcweir 	pDev->SetFont( aFont );
1032cdf0e10cSrcweir 	if ( nFlags & WINDOW_DRAW_MONO )
1033cdf0e10cSrcweir 		pDev->SetTextColor( Color( COL_BLACK ) );
1034cdf0e10cSrcweir 	else
1035cdf0e10cSrcweir 		pDev->SetTextColor( GetTextColor() );
1036cdf0e10cSrcweir 	pDev->SetTextFillColor();
1037cdf0e10cSrcweir 
1038cdf0e10cSrcweir 	if ( !(nFlags & WINDOW_DRAW_NOBACKGROUND) )
1039cdf0e10cSrcweir 	{
1040cdf0e10cSrcweir 		pDev->DrawWallpaper( aRect, GetBackground() );
1041cdf0e10cSrcweir 		if ( mnBorderOff1 || mnBorderOff2 )
1042cdf0e10cSrcweir 		{
1043cdf0e10cSrcweir 			pDev->SetLineColor( GetSettings().GetStyleSettings().GetDarkShadowColor() );
1044cdf0e10cSrcweir 			if ( mnBorderOff1 )
1045cdf0e10cSrcweir 				pDev->DrawLine( aRect.TopLeft(), Point( aRect.Right(), aRect.Top() ) );
1046cdf0e10cSrcweir 			if ( mnBorderOff2 )
1047cdf0e10cSrcweir 				pDev->DrawLine( Point( aRect.Left(), aRect.Bottom() ), Point( aRect.Right(), aRect.Bottom() ) );
1048cdf0e10cSrcweir             // #i40393# draw left and right border, if WB_BORDER was set in ImplInit()
1049cdf0e10cSrcweir             if ( mnBorderOff1 && mnBorderOff2 )
1050cdf0e10cSrcweir             {
1051cdf0e10cSrcweir                 pDev->DrawLine( aRect.TopLeft(), Point( aRect.Left(), aRect.Bottom() ) );
1052cdf0e10cSrcweir                 pDev->DrawLine( Point( aRect.Right(), aRect.Top() ), Point( aRect.Right(), aRect.Bottom() ) );
1053cdf0e10cSrcweir             }
1054cdf0e10cSrcweir 		}
1055cdf0e10cSrcweir 	}
1056cdf0e10cSrcweir 
1057cdf0e10cSrcweir 	Rectangle aItemRect( aRect );
1058cdf0e10cSrcweir //	  aItemRect.Bottom()--;
1059cdf0e10cSrcweir 	sal_uInt16 nItemCount = (sal_uInt16)mpItemList->Count();
1060cdf0e10cSrcweir 	for ( sal_uInt16 i = 0; i < nItemCount; i++ )
1061cdf0e10cSrcweir 	{
1062cdf0e10cSrcweir 		aItemRect.Left() = aRect.Left()+ImplGetItemPos( i );
1063cdf0e10cSrcweir 		aItemRect.Right() = aItemRect.Left() + mpItemList->GetObject( i )->mnSize - 1;
1064cdf0e10cSrcweir 		// Gegen Ueberlauf auf einigen Systemen testen
1065cdf0e10cSrcweir 		if ( aItemRect.Right() > 16000 )
1066cdf0e10cSrcweir 			aItemRect.Right() = 16000;
1067cdf0e10cSrcweir 		Region aRegion( aRect );
1068cdf0e10cSrcweir 		pDev->SetClipRegion( aRegion );
1069cdf0e10cSrcweir 		ImplDrawItem( pDev, i, sal_False, sal_False, aItemRect, &aRect, nFlags );
1070cdf0e10cSrcweir 		pDev->SetClipRegion();
1071cdf0e10cSrcweir 	}
1072cdf0e10cSrcweir 
1073cdf0e10cSrcweir 	pDev->Pop();
1074cdf0e10cSrcweir }
1075cdf0e10cSrcweir 
1076cdf0e10cSrcweir // -----------------------------------------------------------------------
1077cdf0e10cSrcweir 
1078cdf0e10cSrcweir void HeaderBar::Resize()
1079cdf0e10cSrcweir {
1080cdf0e10cSrcweir 	Size aSize = GetOutputSizePixel();
1081cdf0e10cSrcweir 	if ( IsVisible() && (mnDY != aSize.Height()) )
1082cdf0e10cSrcweir 		Invalidate();
1083cdf0e10cSrcweir 	mnDX = aSize.Width();
1084cdf0e10cSrcweir 	mnDY = aSize.Height();
1085cdf0e10cSrcweir }
1086cdf0e10cSrcweir 
1087cdf0e10cSrcweir // -----------------------------------------------------------------------
1088cdf0e10cSrcweir 
1089cdf0e10cSrcweir void HeaderBar::Command( const CommandEvent& rCEvt )
1090cdf0e10cSrcweir {
1091cdf0e10cSrcweir 	if ( rCEvt.IsMouseEvent() && (rCEvt.GetCommand() == COMMAND_STARTDRAG) && !mbDrag )
1092cdf0e10cSrcweir 	{
1093cdf0e10cSrcweir 		ImplStartDrag( rCEvt.GetMousePosPixel(), sal_True );
1094cdf0e10cSrcweir 		return;
1095cdf0e10cSrcweir 	}
1096cdf0e10cSrcweir 
1097cdf0e10cSrcweir 	Window::Command( rCEvt );
1098cdf0e10cSrcweir }
1099cdf0e10cSrcweir 
1100cdf0e10cSrcweir // -----------------------------------------------------------------------
1101cdf0e10cSrcweir 
1102cdf0e10cSrcweir void HeaderBar::RequestHelp( const HelpEvent& rHEvt )
1103cdf0e10cSrcweir {
1104cdf0e10cSrcweir 	sal_uInt16 nItemId = GetItemId( ScreenToOutputPixel( rHEvt.GetMousePosPixel() ) );
1105cdf0e10cSrcweir 	if ( nItemId )
1106cdf0e10cSrcweir 	{
1107cdf0e10cSrcweir 		if ( rHEvt.GetMode() & (HELPMODE_QUICK | HELPMODE_BALLOON) )
1108cdf0e10cSrcweir 		{
1109cdf0e10cSrcweir 			Rectangle aItemRect = GetItemRect( nItemId );
1110cdf0e10cSrcweir 			Point aPt = OutputToScreenPixel( aItemRect.TopLeft() );
1111cdf0e10cSrcweir 			aItemRect.Left()   = aPt.X();
1112cdf0e10cSrcweir 			aItemRect.Top()    = aPt.Y();
1113cdf0e10cSrcweir 			aPt = OutputToScreenPixel( aItemRect.BottomRight() );
1114cdf0e10cSrcweir 			aItemRect.Right()  = aPt.X();
1115cdf0e10cSrcweir 			aItemRect.Bottom() = aPt.Y();
1116cdf0e10cSrcweir 
1117cdf0e10cSrcweir 			XubString aStr = GetHelpText( nItemId );
1118cdf0e10cSrcweir 			if ( !aStr.Len() || !(rHEvt.GetMode() & HELPMODE_BALLOON) )
1119cdf0e10cSrcweir 			{
1120cdf0e10cSrcweir 				ImplHeadItem* pItem = mpItemList->GetObject( GetItemPos( nItemId ) );
1121cdf0e10cSrcweir 				// Wir zeigen die Quick-Hilfe nur an, wenn Text nicht
1122cdf0e10cSrcweir 				// vollstaendig sichtbar, ansonsten zeigen wir den Hilfetext
1123cdf0e10cSrcweir 				// an, wenn das Item keinen Text besitzt
1124cdf0e10cSrcweir 				if ( pItem->maOutText != pItem->maText )
1125cdf0e10cSrcweir 					aStr = pItem->maText;
1126cdf0e10cSrcweir 				else if ( pItem->maText.Len() )
1127cdf0e10cSrcweir 					aStr.Erase();
1128cdf0e10cSrcweir 			}
1129cdf0e10cSrcweir 
1130cdf0e10cSrcweir 			if ( aStr.Len() )
1131cdf0e10cSrcweir 			{
1132cdf0e10cSrcweir 				if ( rHEvt.GetMode() & HELPMODE_BALLOON )
1133cdf0e10cSrcweir 					Help::ShowBalloon( this, aItemRect.Center(), aItemRect, aStr );
1134cdf0e10cSrcweir 				else
1135cdf0e10cSrcweir 					Help::ShowQuickHelp( this, aItemRect, aStr );
1136cdf0e10cSrcweir 				return;
1137cdf0e10cSrcweir 			}
1138cdf0e10cSrcweir 		}
1139cdf0e10cSrcweir 		else if ( rHEvt.GetMode() & HELPMODE_EXTENDED )
1140cdf0e10cSrcweir 		{
1141cdf0e10cSrcweir 		    rtl::OUString aHelpId( rtl::OStringToOUString( GetHelpId( nItemId ), RTL_TEXTENCODING_UTF8 ) );
1142cdf0e10cSrcweir 			if ( aHelpId.getLength() )
1143cdf0e10cSrcweir 			{
1144cdf0e10cSrcweir 				// Wenn eine Hilfe existiert, dann ausloesen
1145cdf0e10cSrcweir 				Help* pHelp = Application::GetHelp();
1146cdf0e10cSrcweir 				if ( pHelp )
1147cdf0e10cSrcweir 					pHelp->Start( aHelpId, this );
1148cdf0e10cSrcweir 				return;
1149cdf0e10cSrcweir 			}
1150cdf0e10cSrcweir 		}
1151cdf0e10cSrcweir 	}
1152cdf0e10cSrcweir 
1153cdf0e10cSrcweir 	Window::RequestHelp( rHEvt );
1154cdf0e10cSrcweir }
1155cdf0e10cSrcweir 
1156cdf0e10cSrcweir // -----------------------------------------------------------------------
1157cdf0e10cSrcweir 
1158cdf0e10cSrcweir void HeaderBar::StateChanged( StateChangedType nType )
1159cdf0e10cSrcweir {
1160cdf0e10cSrcweir 	Window::StateChanged( nType );
1161cdf0e10cSrcweir 
1162cdf0e10cSrcweir 	if ( nType == STATE_CHANGE_ENABLE )
1163cdf0e10cSrcweir 		Invalidate();
1164cdf0e10cSrcweir 	else if ( (nType == STATE_CHANGE_ZOOM) ||
1165cdf0e10cSrcweir 			  (nType == STATE_CHANGE_CONTROLFONT) )
1166cdf0e10cSrcweir 	{
1167cdf0e10cSrcweir 		ImplInitSettings( sal_True, sal_False, sal_False );
1168cdf0e10cSrcweir 		Invalidate();
1169cdf0e10cSrcweir 	}
1170cdf0e10cSrcweir 	else if ( nType == STATE_CHANGE_CONTROLFOREGROUND )
1171cdf0e10cSrcweir 	{
1172cdf0e10cSrcweir 		ImplInitSettings( sal_False, sal_True, sal_False );
1173cdf0e10cSrcweir 		Invalidate();
1174cdf0e10cSrcweir 	}
1175cdf0e10cSrcweir 	else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
1176cdf0e10cSrcweir 	{
1177cdf0e10cSrcweir 		ImplInitSettings( sal_False, sal_False, sal_True );
1178cdf0e10cSrcweir 		Invalidate();
1179cdf0e10cSrcweir 	}
1180cdf0e10cSrcweir }
1181cdf0e10cSrcweir 
1182cdf0e10cSrcweir // -----------------------------------------------------------------------
1183cdf0e10cSrcweir 
1184cdf0e10cSrcweir void HeaderBar::DataChanged( const DataChangedEvent& rDCEvt )
1185cdf0e10cSrcweir {
1186cdf0e10cSrcweir 	Window::DataChanged( rDCEvt );
1187cdf0e10cSrcweir 
1188cdf0e10cSrcweir 	if ( (rDCEvt.GetType() == DATACHANGED_FONTS) ||
1189cdf0e10cSrcweir 		 (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) ||
1190cdf0e10cSrcweir 		 ((rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
1191cdf0e10cSrcweir 		  (rDCEvt.GetFlags() & SETTINGS_STYLE)) )
1192cdf0e10cSrcweir 	{
1193cdf0e10cSrcweir 		ImplInitSettings( sal_True, sal_True, sal_True );
1194cdf0e10cSrcweir 		Invalidate();
1195cdf0e10cSrcweir 	}
1196cdf0e10cSrcweir }
1197cdf0e10cSrcweir 
1198cdf0e10cSrcweir // -----------------------------------------------------------------------
1199cdf0e10cSrcweir 
1200cdf0e10cSrcweir void HeaderBar::UserDraw( const UserDrawEvent& )
1201cdf0e10cSrcweir {
1202cdf0e10cSrcweir }
1203cdf0e10cSrcweir 
1204cdf0e10cSrcweir // -----------------------------------------------------------------------
1205cdf0e10cSrcweir 
1206cdf0e10cSrcweir void HeaderBar::StartDrag()
1207cdf0e10cSrcweir {
1208cdf0e10cSrcweir 	maStartDragHdl.Call( this );
1209cdf0e10cSrcweir }
1210cdf0e10cSrcweir 
1211cdf0e10cSrcweir // -----------------------------------------------------------------------
1212cdf0e10cSrcweir 
1213cdf0e10cSrcweir void HeaderBar::Drag()
1214cdf0e10cSrcweir {
1215cdf0e10cSrcweir 	maDragHdl.Call( this );
1216cdf0e10cSrcweir }
1217cdf0e10cSrcweir 
1218cdf0e10cSrcweir // -----------------------------------------------------------------------
1219cdf0e10cSrcweir 
1220cdf0e10cSrcweir void HeaderBar::EndDrag()
1221cdf0e10cSrcweir {
1222cdf0e10cSrcweir 	maEndDragHdl.Call( this );
1223cdf0e10cSrcweir }
1224cdf0e10cSrcweir 
1225cdf0e10cSrcweir // -----------------------------------------------------------------------
1226cdf0e10cSrcweir 
1227cdf0e10cSrcweir void HeaderBar::Select()
1228cdf0e10cSrcweir {
1229cdf0e10cSrcweir 	maSelectHdl.Call( this );
1230cdf0e10cSrcweir }
1231cdf0e10cSrcweir 
1232cdf0e10cSrcweir // -----------------------------------------------------------------------
1233cdf0e10cSrcweir 
1234cdf0e10cSrcweir void HeaderBar::DoubleClick()
1235cdf0e10cSrcweir {
1236cdf0e10cSrcweir 	maDoubleClickHdl.Call( this );
1237cdf0e10cSrcweir }
1238cdf0e10cSrcweir 
1239cdf0e10cSrcweir // -----------------------------------------------------------------------
1240cdf0e10cSrcweir 
1241cdf0e10cSrcweir void HeaderBar::InsertItem( sal_uInt16 nItemId, const Image& rImage,
1242cdf0e10cSrcweir 							long nSize, HeaderBarItemBits nBits, sal_uInt16 nPos )
1243cdf0e10cSrcweir {
1244cdf0e10cSrcweir 	DBG_ASSERT( nItemId, "HeaderBar::InsertItem(): ItemId == 0" );
1245cdf0e10cSrcweir 	DBG_ASSERT( GetItemPos( nItemId ) == HEADERBAR_ITEM_NOTFOUND,
1246cdf0e10cSrcweir 				"HeaderBar::InsertItem(): ItemId already exists" );
1247cdf0e10cSrcweir 
1248cdf0e10cSrcweir 	// Item anlegen und in die Liste einfuegen
1249cdf0e10cSrcweir 	ImplHeadItem* pItem = new ImplHeadItem;
1250cdf0e10cSrcweir 	pItem->mnId 		= nItemId;
1251cdf0e10cSrcweir 	pItem->mnBits		= nBits;
1252cdf0e10cSrcweir 	pItem->mnSize		= nSize;
1253cdf0e10cSrcweir 	pItem->maImage		= rImage;
1254cdf0e10cSrcweir 	pItem->mpUserData	= 0;
1255cdf0e10cSrcweir 	mpItemList->Insert( pItem, nPos );
1256cdf0e10cSrcweir 
1257cdf0e10cSrcweir 	// Ausgabe updaten
1258cdf0e10cSrcweir 	ImplUpdate( nPos, sal_True );
1259cdf0e10cSrcweir }
1260cdf0e10cSrcweir 
1261cdf0e10cSrcweir // -----------------------------------------------------------------------
1262cdf0e10cSrcweir 
1263cdf0e10cSrcweir void HeaderBar::InsertItem( sal_uInt16 nItemId, const XubString& rText,
1264cdf0e10cSrcweir 							long nSize, HeaderBarItemBits nBits, sal_uInt16 nPos )
1265cdf0e10cSrcweir {
1266cdf0e10cSrcweir 	DBG_ASSERT( nItemId, "HeaderBar::InsertItem(): ItemId == 0" );
1267cdf0e10cSrcweir 	DBG_ASSERT( GetItemPos( nItemId ) == HEADERBAR_ITEM_NOTFOUND,
1268cdf0e10cSrcweir 				"HeaderBar::InsertItem(): ItemId already exists" );
1269cdf0e10cSrcweir 
1270cdf0e10cSrcweir 	// Item anlegen und in die Liste einfuegen
1271cdf0e10cSrcweir 	ImplHeadItem* pItem = new ImplHeadItem;
1272cdf0e10cSrcweir 	pItem->mnId 		= nItemId;
1273cdf0e10cSrcweir 	pItem->mnBits		= nBits;
1274cdf0e10cSrcweir 	pItem->mnSize		= nSize;
1275cdf0e10cSrcweir 	pItem->maText		= rText;
1276cdf0e10cSrcweir 	pItem->mpUserData	= 0;
1277cdf0e10cSrcweir 	mpItemList->Insert( pItem, nPos );
1278cdf0e10cSrcweir 
1279cdf0e10cSrcweir 	// Ausgabe updaten
1280cdf0e10cSrcweir 	ImplUpdate( nPos, sal_True );
1281cdf0e10cSrcweir }
1282cdf0e10cSrcweir 
1283cdf0e10cSrcweir // -----------------------------------------------------------------------
1284cdf0e10cSrcweir 
1285cdf0e10cSrcweir void HeaderBar::InsertItem( sal_uInt16 nItemId,
1286cdf0e10cSrcweir 							const Image& rImage, const XubString& rText,
1287cdf0e10cSrcweir 							long nSize, HeaderBarItemBits nBits,
1288cdf0e10cSrcweir 							sal_uInt16 nPos )
1289cdf0e10cSrcweir {
1290cdf0e10cSrcweir 	DBG_ASSERT( nItemId, "HeaderBar::InsertItem(): ItemId == 0" );
1291cdf0e10cSrcweir 	DBG_ASSERT( GetItemPos( nItemId ) == HEADERBAR_ITEM_NOTFOUND,
1292cdf0e10cSrcweir 				"HeaderBar::InsertItem(): ItemId already exists" );
1293cdf0e10cSrcweir 
1294cdf0e10cSrcweir 	// Item anlegen und in die Liste einfuegen
1295cdf0e10cSrcweir 	ImplHeadItem* pItem = new ImplHeadItem;
1296cdf0e10cSrcweir 	pItem->mnId 		= nItemId;
1297cdf0e10cSrcweir 	pItem->mnBits		= nBits;
1298cdf0e10cSrcweir 	pItem->mnSize		= nSize;
1299cdf0e10cSrcweir 	pItem->maImage		= rImage;
1300cdf0e10cSrcweir 	pItem->maText		= rText;
1301cdf0e10cSrcweir 	pItem->mpUserData	= 0;
1302cdf0e10cSrcweir 	mpItemList->Insert( pItem, nPos );
1303cdf0e10cSrcweir 
1304cdf0e10cSrcweir 	// Ausgabe updaten
1305cdf0e10cSrcweir 	ImplUpdate( nPos, sal_True );
1306cdf0e10cSrcweir }
1307cdf0e10cSrcweir 
1308cdf0e10cSrcweir // -----------------------------------------------------------------------
1309cdf0e10cSrcweir 
1310cdf0e10cSrcweir void HeaderBar::RemoveItem( sal_uInt16 nItemId )
1311cdf0e10cSrcweir {
1312cdf0e10cSrcweir 	sal_uInt16 nPos = GetItemPos( nItemId );
1313cdf0e10cSrcweir 	if ( nPos != HEADERBAR_ITEM_NOTFOUND )
1314cdf0e10cSrcweir 	{
1315cdf0e10cSrcweir 		ImplHeadItem* pItem = mpItemList->Remove( nPos );
1316cdf0e10cSrcweir 		delete pItem;
1317cdf0e10cSrcweir 		ImplUpdate( nPos, sal_True );
1318cdf0e10cSrcweir 	}
1319cdf0e10cSrcweir }
1320cdf0e10cSrcweir 
1321cdf0e10cSrcweir // -----------------------------------------------------------------------
1322cdf0e10cSrcweir 
1323cdf0e10cSrcweir void HeaderBar::MoveItem( sal_uInt16 nItemId, sal_uInt16 nNewPos )
1324cdf0e10cSrcweir {
1325cdf0e10cSrcweir 	sal_uInt16 nPos = GetItemPos( nItemId );
1326cdf0e10cSrcweir 	if ( nPos != HEADERBAR_ITEM_NOTFOUND )
1327cdf0e10cSrcweir 	{
1328cdf0e10cSrcweir 		if ( nPos != nNewPos )
1329cdf0e10cSrcweir 		{
1330cdf0e10cSrcweir 			ImplHeadItem* pItem = mpItemList->Remove( nPos );
1331cdf0e10cSrcweir 			if ( nNewPos < nPos )
1332cdf0e10cSrcweir 				nPos = nNewPos;
1333cdf0e10cSrcweir 			mpItemList->Insert( pItem, nNewPos );
1334cdf0e10cSrcweir 			ImplUpdate( nPos, sal_True );
1335cdf0e10cSrcweir 		}
1336cdf0e10cSrcweir 	}
1337cdf0e10cSrcweir }
1338cdf0e10cSrcweir 
1339cdf0e10cSrcweir // -----------------------------------------------------------------------
1340cdf0e10cSrcweir 
1341cdf0e10cSrcweir void HeaderBar::Clear()
1342cdf0e10cSrcweir {
1343cdf0e10cSrcweir 	// Alle Items loeschen
1344cdf0e10cSrcweir 	ImplHeadItem* pItem = mpItemList->First();
1345cdf0e10cSrcweir 	while ( pItem )
1346cdf0e10cSrcweir 	{
1347cdf0e10cSrcweir 		delete pItem;
1348cdf0e10cSrcweir 		pItem = mpItemList->Next();
1349cdf0e10cSrcweir 	}
1350cdf0e10cSrcweir 	mpItemList->Clear();
1351cdf0e10cSrcweir 
1352cdf0e10cSrcweir 	ImplUpdate( 0, sal_True );
1353cdf0e10cSrcweir }
1354cdf0e10cSrcweir 
1355cdf0e10cSrcweir // -----------------------------------------------------------------------
1356cdf0e10cSrcweir 
1357cdf0e10cSrcweir void HeaderBar::SetOffset( long nNewOffset )
1358cdf0e10cSrcweir {
1359cdf0e10cSrcweir 	// Hier erstmal neu zeichnen, damit mit alten Offset noch das
1360cdf0e10cSrcweir 	// richtige gemalt wird
1361cdf0e10cSrcweir 	//Update();
1362cdf0e10cSrcweir 
1363cdf0e10cSrcweir 	// Bereich verschieben
1364cdf0e10cSrcweir 	Rectangle aRect( 0, mnBorderOff1, mnDX-1, mnDY-mnBorderOff1-mnBorderOff2-1 );
1365cdf0e10cSrcweir 	long nDelta = mnOffset-nNewOffset;
1366cdf0e10cSrcweir 	mnOffset = nNewOffset;
1367cdf0e10cSrcweir 	Scroll( nDelta, 0, aRect );
1368cdf0e10cSrcweir }
1369cdf0e10cSrcweir 
1370cdf0e10cSrcweir // -----------------------------------------------------------------------
1371cdf0e10cSrcweir 
1372cdf0e10cSrcweir sal_uInt16 HeaderBar::GetItemCount() const
1373cdf0e10cSrcweir {
1374cdf0e10cSrcweir 	return (sal_uInt16)mpItemList->Count();
1375cdf0e10cSrcweir }
1376cdf0e10cSrcweir 
1377cdf0e10cSrcweir // -----------------------------------------------------------------------
1378cdf0e10cSrcweir 
1379cdf0e10cSrcweir sal_uInt16 HeaderBar::GetItemPos( sal_uInt16 nItemId ) const
1380cdf0e10cSrcweir {
1381cdf0e10cSrcweir 	ImplHeadItem* pItem = mpItemList->First();
1382cdf0e10cSrcweir 	while ( pItem )
1383cdf0e10cSrcweir 	{
1384cdf0e10cSrcweir 		if ( pItem->mnId == nItemId )
1385cdf0e10cSrcweir 			return (sal_uInt16)mpItemList->GetCurPos();
1386cdf0e10cSrcweir 		pItem = mpItemList->Next();
1387cdf0e10cSrcweir 	}
1388cdf0e10cSrcweir 
1389cdf0e10cSrcweir 	return HEADERBAR_ITEM_NOTFOUND;
1390cdf0e10cSrcweir }
1391cdf0e10cSrcweir 
1392cdf0e10cSrcweir // -----------------------------------------------------------------------
1393cdf0e10cSrcweir 
1394cdf0e10cSrcweir sal_uInt16 HeaderBar::GetItemId( sal_uInt16 nPos ) const
1395cdf0e10cSrcweir {
1396cdf0e10cSrcweir 	ImplHeadItem* pItem = mpItemList->GetObject( nPos );
1397cdf0e10cSrcweir 	if ( pItem )
1398cdf0e10cSrcweir 		return pItem->mnId;
1399cdf0e10cSrcweir 	else
1400cdf0e10cSrcweir 		return 0;
1401cdf0e10cSrcweir }
1402cdf0e10cSrcweir 
1403cdf0e10cSrcweir // -----------------------------------------------------------------------
1404cdf0e10cSrcweir 
1405cdf0e10cSrcweir sal_uInt16 HeaderBar::GetItemId( const Point& rPos ) const
1406cdf0e10cSrcweir {
1407cdf0e10cSrcweir 	sal_uInt16 nPos = 0;
1408cdf0e10cSrcweir 	while ( nPos < mpItemList->Count() )
1409cdf0e10cSrcweir 	{
1410cdf0e10cSrcweir 		if ( ImplGetItemRect( nPos ).IsInside( rPos ) )
1411cdf0e10cSrcweir 			return GetItemId( nPos );
1412cdf0e10cSrcweir 
1413cdf0e10cSrcweir 		nPos++;
1414cdf0e10cSrcweir 	}
1415cdf0e10cSrcweir 
1416cdf0e10cSrcweir 	return 0;
1417cdf0e10cSrcweir }
1418cdf0e10cSrcweir 
1419cdf0e10cSrcweir // -----------------------------------------------------------------------
1420cdf0e10cSrcweir 
1421cdf0e10cSrcweir Rectangle HeaderBar::GetItemRect( sal_uInt16 nItemId ) const
1422cdf0e10cSrcweir {
1423cdf0e10cSrcweir 	Rectangle aRect;
1424cdf0e10cSrcweir 	sal_uInt16 nPos = GetItemPos( nItemId );
1425cdf0e10cSrcweir 	if ( nPos != HEADERBAR_ITEM_NOTFOUND )
1426cdf0e10cSrcweir 		aRect = ImplGetItemRect( nPos );
1427cdf0e10cSrcweir 	return aRect;
1428cdf0e10cSrcweir }
1429cdf0e10cSrcweir 
1430cdf0e10cSrcweir // -----------------------------------------------------------------------
1431cdf0e10cSrcweir 
1432cdf0e10cSrcweir void HeaderBar::SetItemSize( sal_uInt16 nItemId, long nNewSize )
1433cdf0e10cSrcweir {
1434cdf0e10cSrcweir 	sal_uInt16 nPos = GetItemPos( nItemId );
1435cdf0e10cSrcweir 	if ( nPos != HEADERBAR_ITEM_NOTFOUND )
1436cdf0e10cSrcweir 	{
1437cdf0e10cSrcweir 		ImplHeadItem* pItem = mpItemList->GetObject( nPos );
1438cdf0e10cSrcweir 		if ( pItem->mnSize != nNewSize )
1439cdf0e10cSrcweir 		{
1440cdf0e10cSrcweir 			pItem->mnSize = nNewSize;
1441cdf0e10cSrcweir 			ImplUpdate( nPos, sal_True );
1442cdf0e10cSrcweir 		}
1443cdf0e10cSrcweir 	}
1444cdf0e10cSrcweir }
1445cdf0e10cSrcweir 
1446cdf0e10cSrcweir // -----------------------------------------------------------------------
1447cdf0e10cSrcweir 
1448cdf0e10cSrcweir long HeaderBar::GetItemSize( sal_uInt16 nItemId ) const
1449cdf0e10cSrcweir {
1450cdf0e10cSrcweir 	sal_uInt16 nPos = GetItemPos( nItemId );
1451cdf0e10cSrcweir 	if ( nPos != HEADERBAR_ITEM_NOTFOUND )
1452cdf0e10cSrcweir 		return mpItemList->GetObject( nPos )->mnSize;
1453cdf0e10cSrcweir 	else
1454cdf0e10cSrcweir 		return 0;
1455cdf0e10cSrcweir }
1456cdf0e10cSrcweir 
1457cdf0e10cSrcweir // -----------------------------------------------------------------------
1458cdf0e10cSrcweir 
1459cdf0e10cSrcweir void HeaderBar::SetItemBits( sal_uInt16 nItemId, HeaderBarItemBits nNewBits )
1460cdf0e10cSrcweir {
1461cdf0e10cSrcweir 	sal_uInt16 nPos = GetItemPos( nItemId );
1462cdf0e10cSrcweir 	if ( nPos != HEADERBAR_ITEM_NOTFOUND )
1463cdf0e10cSrcweir 	{
1464cdf0e10cSrcweir 		ImplHeadItem* pItem = mpItemList->GetObject( nPos );
1465cdf0e10cSrcweir 		if ( pItem->mnBits != nNewBits )
1466cdf0e10cSrcweir 		{
1467cdf0e10cSrcweir 			pItem->mnBits = nNewBits;
1468cdf0e10cSrcweir 			ImplUpdate( nPos );
1469cdf0e10cSrcweir 		}
1470cdf0e10cSrcweir 	}
1471cdf0e10cSrcweir }
1472cdf0e10cSrcweir 
1473cdf0e10cSrcweir // -----------------------------------------------------------------------
1474cdf0e10cSrcweir 
1475cdf0e10cSrcweir HeaderBarItemBits HeaderBar::GetItemBits( sal_uInt16 nItemId ) const
1476cdf0e10cSrcweir {
1477cdf0e10cSrcweir 	sal_uInt16 nPos = GetItemPos( nItemId );
1478cdf0e10cSrcweir 	if ( nPos != HEADERBAR_ITEM_NOTFOUND )
1479cdf0e10cSrcweir 		return mpItemList->GetObject( nPos )->mnBits;
1480cdf0e10cSrcweir 	else
1481cdf0e10cSrcweir 		return 0;
1482cdf0e10cSrcweir }
1483cdf0e10cSrcweir 
1484cdf0e10cSrcweir // -----------------------------------------------------------------------
1485cdf0e10cSrcweir 
1486cdf0e10cSrcweir void HeaderBar::SetItemData( sal_uInt16 nItemId, void* pNewData )
1487cdf0e10cSrcweir {
1488cdf0e10cSrcweir 	sal_uInt16 nPos = GetItemPos( nItemId );
1489cdf0e10cSrcweir 	if ( nPos != HEADERBAR_ITEM_NOTFOUND )
1490cdf0e10cSrcweir 	{
1491cdf0e10cSrcweir 		mpItemList->GetObject( nPos )->mpUserData = pNewData;
1492cdf0e10cSrcweir 		ImplUpdate( nPos );
1493cdf0e10cSrcweir 	}
1494cdf0e10cSrcweir }
1495cdf0e10cSrcweir 
1496cdf0e10cSrcweir // -----------------------------------------------------------------------
1497cdf0e10cSrcweir 
1498cdf0e10cSrcweir void* HeaderBar::GetItemData( sal_uInt16 nItemId ) const
1499cdf0e10cSrcweir {
1500cdf0e10cSrcweir 	sal_uInt16 nPos = GetItemPos( nItemId );
1501cdf0e10cSrcweir 	if ( nPos != HEADERBAR_ITEM_NOTFOUND )
1502cdf0e10cSrcweir 		return mpItemList->GetObject( nPos )->mpUserData;
1503cdf0e10cSrcweir 	else
1504cdf0e10cSrcweir 		return NULL;
1505cdf0e10cSrcweir }
1506cdf0e10cSrcweir 
1507cdf0e10cSrcweir // -----------------------------------------------------------------------
1508cdf0e10cSrcweir 
1509cdf0e10cSrcweir void HeaderBar::SetItemImage( sal_uInt16 nItemId, const Image& rImage )
1510cdf0e10cSrcweir {
1511cdf0e10cSrcweir 	sal_uInt16 nPos = GetItemPos( nItemId );
1512cdf0e10cSrcweir 	if ( nPos != HEADERBAR_ITEM_NOTFOUND )
1513cdf0e10cSrcweir 	{
1514cdf0e10cSrcweir 		mpItemList->GetObject( nPos )->maImage = rImage;
1515cdf0e10cSrcweir 		ImplUpdate( nPos );
1516cdf0e10cSrcweir 	}
1517cdf0e10cSrcweir }
1518cdf0e10cSrcweir 
1519cdf0e10cSrcweir // -----------------------------------------------------------------------
1520cdf0e10cSrcweir 
1521cdf0e10cSrcweir Image HeaderBar::GetItemImage( sal_uInt16 nItemId ) const
1522cdf0e10cSrcweir {
1523cdf0e10cSrcweir 	sal_uInt16 nPos = GetItemPos( nItemId );
1524cdf0e10cSrcweir 	if ( nPos != HEADERBAR_ITEM_NOTFOUND )
1525cdf0e10cSrcweir 		return mpItemList->GetObject( nPos )->maImage;
1526cdf0e10cSrcweir 	else
1527cdf0e10cSrcweir 		return Image();
1528cdf0e10cSrcweir }
1529cdf0e10cSrcweir 
1530cdf0e10cSrcweir // -----------------------------------------------------------------------
1531cdf0e10cSrcweir 
1532cdf0e10cSrcweir void HeaderBar::SetItemText( sal_uInt16 nItemId, const XubString& rText )
1533cdf0e10cSrcweir {
1534cdf0e10cSrcweir 	sal_uInt16 nPos = GetItemPos( nItemId );
1535cdf0e10cSrcweir 	if ( nPos != HEADERBAR_ITEM_NOTFOUND )
1536cdf0e10cSrcweir 	{
1537cdf0e10cSrcweir 		mpItemList->GetObject( nPos )->maText = rText;
1538cdf0e10cSrcweir 		ImplUpdate( nPos );
1539cdf0e10cSrcweir 	}
1540cdf0e10cSrcweir }
1541cdf0e10cSrcweir 
1542cdf0e10cSrcweir // -----------------------------------------------------------------------
1543cdf0e10cSrcweir 
1544cdf0e10cSrcweir XubString HeaderBar::GetItemText( sal_uInt16 nItemId ) const
1545cdf0e10cSrcweir {
1546cdf0e10cSrcweir 	sal_uInt16 nPos = GetItemPos( nItemId );
1547cdf0e10cSrcweir 	if ( nPos != HEADERBAR_ITEM_NOTFOUND )
1548cdf0e10cSrcweir 		return mpItemList->GetObject( nPos )->maText;
1549cdf0e10cSrcweir 	else
1550cdf0e10cSrcweir 		return String();
1551cdf0e10cSrcweir }
1552cdf0e10cSrcweir 
1553cdf0e10cSrcweir // -----------------------------------------------------------------------
1554cdf0e10cSrcweir 
1555cdf0e10cSrcweir void HeaderBar::SetHelpText( sal_uInt16 nItemId, const XubString& rText )
1556cdf0e10cSrcweir {
1557cdf0e10cSrcweir 	sal_uInt16 nPos = GetItemPos( nItemId );
1558cdf0e10cSrcweir 	if ( nPos != HEADERBAR_ITEM_NOTFOUND )
1559cdf0e10cSrcweir 		mpItemList->GetObject( nPos )->maHelpText = rText;
1560cdf0e10cSrcweir }
1561cdf0e10cSrcweir 
1562cdf0e10cSrcweir // -----------------------------------------------------------------------
1563cdf0e10cSrcweir 
1564cdf0e10cSrcweir XubString HeaderBar::GetHelpText( sal_uInt16 nItemId ) const
1565cdf0e10cSrcweir {
1566cdf0e10cSrcweir 	sal_uInt16 nPos = GetItemPos( nItemId );
1567cdf0e10cSrcweir 	if ( nPos != HEADERBAR_ITEM_NOTFOUND )
1568cdf0e10cSrcweir 	{
1569cdf0e10cSrcweir 		ImplHeadItem* pItem = mpItemList->GetObject( nPos );
1570cdf0e10cSrcweir 		if ( !pItem->maHelpText.Len() && pItem->maHelpId.getLength() )
1571cdf0e10cSrcweir 		{
1572cdf0e10cSrcweir 			Help* pHelp = Application::GetHelp();
1573cdf0e10cSrcweir 			if ( pHelp )
1574cdf0e10cSrcweir 				pItem->maHelpText = pHelp->GetHelpText( rtl::OStringToOUString( pItem->maHelpId, RTL_TEXTENCODING_UTF8 ), this );
1575cdf0e10cSrcweir 		}
1576cdf0e10cSrcweir 
1577cdf0e10cSrcweir 		return pItem->maHelpText;
1578cdf0e10cSrcweir 	}
1579cdf0e10cSrcweir 	else
1580cdf0e10cSrcweir 		return XubString();
1581cdf0e10cSrcweir }
1582cdf0e10cSrcweir 
1583cdf0e10cSrcweir // -----------------------------------------------------------------------
1584cdf0e10cSrcweir 
1585cdf0e10cSrcweir void HeaderBar::SetHelpId( sal_uInt16 nItemId, const rtl::OString& rHelpId )
1586cdf0e10cSrcweir {
1587cdf0e10cSrcweir 	sal_uInt16 nPos = GetItemPos( nItemId );
1588cdf0e10cSrcweir 	if ( nPos != HEADERBAR_ITEM_NOTFOUND )
1589cdf0e10cSrcweir 		mpItemList->GetObject( nPos )->maHelpId = rHelpId;
1590cdf0e10cSrcweir }
1591cdf0e10cSrcweir 
1592cdf0e10cSrcweir // -----------------------------------------------------------------------
1593cdf0e10cSrcweir 
1594cdf0e10cSrcweir rtl::OString HeaderBar::GetHelpId( sal_uInt16 nItemId ) const
1595cdf0e10cSrcweir {
1596cdf0e10cSrcweir 	sal_uInt16 nPos = GetItemPos( nItemId );
1597cdf0e10cSrcweir 	rtl::OString aRet;
1598cdf0e10cSrcweir 	if ( nPos != HEADERBAR_ITEM_NOTFOUND )
1599cdf0e10cSrcweir 		aRet = mpItemList->GetObject( nPos )->maHelpId;
1600cdf0e10cSrcweir 	return aRet;
1601cdf0e10cSrcweir }
1602cdf0e10cSrcweir 
1603cdf0e10cSrcweir // -----------------------------------------------------------------------
1604cdf0e10cSrcweir 
1605cdf0e10cSrcweir Size HeaderBar::CalcWindowSizePixel() const
1606cdf0e10cSrcweir {
1607cdf0e10cSrcweir 	long nMaxImageSize = 0;
1608cdf0e10cSrcweir 	Size aSize( 0, GetTextHeight() );
1609cdf0e10cSrcweir 
1610cdf0e10cSrcweir 	ImplHeadItem* pItem = mpItemList->First();
1611cdf0e10cSrcweir 	while ( pItem )
1612cdf0e10cSrcweir 	{
1613cdf0e10cSrcweir 		// Image-Groessen beruecksichtigen
1614cdf0e10cSrcweir 		long nImageHeight = pItem->maImage.GetSizePixel().Height();
1615cdf0e10cSrcweir 		if ( !(pItem->mnBits & (HIB_LEFTIMAGE | HIB_RIGHTIMAGE)) && pItem->maText.Len() )
1616cdf0e10cSrcweir 			nImageHeight += aSize.Height();
1617cdf0e10cSrcweir 		if ( nImageHeight > nMaxImageSize )
1618cdf0e10cSrcweir 			nMaxImageSize = nImageHeight;
1619cdf0e10cSrcweir 
1620cdf0e10cSrcweir 		// Breite aufaddieren
1621cdf0e10cSrcweir 		aSize.Width() += pItem->mnSize;
1622cdf0e10cSrcweir 
1623cdf0e10cSrcweir 		pItem = mpItemList->Next();
1624cdf0e10cSrcweir 	}
1625cdf0e10cSrcweir 
1626cdf0e10cSrcweir 	if ( nMaxImageSize > aSize.Height() )
1627cdf0e10cSrcweir 		aSize.Height() = nMaxImageSize;
1628cdf0e10cSrcweir 
1629cdf0e10cSrcweir 	// Border aufaddieren
1630cdf0e10cSrcweir 	if ( mbButtonStyle )
1631cdf0e10cSrcweir 		aSize.Height() += 4;
1632cdf0e10cSrcweir 	else
1633cdf0e10cSrcweir 		aSize.Height() += 2;
1634cdf0e10cSrcweir 	aSize.Height() += mnBorderOff1+mnBorderOff2;
1635cdf0e10cSrcweir 
1636cdf0e10cSrcweir 	return aSize;
1637cdf0e10cSrcweir }
1638cdf0e10cSrcweir 
1639cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > HeaderBar::CreateAccessible()
1640cdf0e10cSrcweir {
1641cdf0e10cSrcweir 	if ( !mxAccessible.is() )
1642cdf0e10cSrcweir 	{
1643cdf0e10cSrcweir 		if ( maCreateAccessibleHdl.IsSet() )
1644cdf0e10cSrcweir 			maCreateAccessibleHdl.Call( this );
1645cdf0e10cSrcweir 
1646cdf0e10cSrcweir 		if ( !mxAccessible.is() )
1647cdf0e10cSrcweir 			mxAccessible = Window::CreateAccessible();
1648cdf0e10cSrcweir 	}
1649cdf0e10cSrcweir 
1650cdf0e10cSrcweir 	return mxAccessible;
1651cdf0e10cSrcweir }
1652cdf0e10cSrcweir 
1653cdf0e10cSrcweir void HeaderBar::SetAccessible( ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > _xAccessible )
1654cdf0e10cSrcweir {
1655cdf0e10cSrcweir     mxAccessible = _xAccessible;
1656cdf0e10cSrcweir }
1657cdf0e10cSrcweir 
1658*2bfcd321SSteve Yin //IAccessibility2 Implementation 2009-----
1659*2bfcd321SSteve Yin ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > HeaderBar::GetComponentInterface( sal_Bool bCreate )
1660*2bfcd321SSteve Yin {
1661*2bfcd321SSteve Yin     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > xPeer
1662*2bfcd321SSteve Yin 		(Window::GetComponentInterface(false));
1663*2bfcd321SSteve Yin 	if ( !xPeer.is() && bCreate )
1664*2bfcd321SSteve Yin     {
1665*2bfcd321SSteve Yin 		::com::sun::star::awt::XWindowPeer* mxPeer = new VCLXHeaderBar(this);
1666*2bfcd321SSteve Yin 		m_pVCLXHeaderBar = (VCLXHeaderBar*)(mxPeer);
1667*2bfcd321SSteve Yin 		SetComponentInterface(mxPeer);
1668*2bfcd321SSteve Yin 		return mxPeer;
1669*2bfcd321SSteve Yin     }
1670*2bfcd321SSteve Yin 	else
1671*2bfcd321SSteve Yin 		return xPeer;
1672*2bfcd321SSteve Yin }
1673*2bfcd321SSteve Yin //-----IAccessibility2 Implementation 2009
1674*2bfcd321SSteve Yin 
1675