merge the formfield patch from ooo-build
[ooovba.git] / svtools / source / control / headbar.cxx
blobfc7d125046805e3bd72008094514407045f7486b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: headbar.cxx,v $
10 * $Revision: 1.15 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
34 #define _SV_HEADBAR_CXX
35 #include <svtools/headbar.hxx>
36 #include <tools/debug.hxx>
37 #ifndef _TOOLS_LIST_HXX
38 #include <tools/list.hxx>
39 #endif
41 #ifndef _VCL_APP_HXX
42 #include <vcl/svapp.hxx>
43 #endif
44 #ifndef _VCL_HELP_HXX
45 #include <vcl/help.hxx>
46 #endif
47 #ifndef _VCL_IMAGE_HXX
48 #include <vcl/image.hxx>
49 #endif
50 #include <com/sun/star/accessibility/XAccessible.hpp>
52 // =======================================================================
54 struct ImplHeadItem
56 USHORT mnId;
57 HeaderBarItemBits mnBits;
58 long mnSize;
59 ULONG mnHelpId;
60 Image maImage;
61 XubString maOutText;
62 XubString maText;
63 XubString maHelpText;
64 void* mpUserData;
67 DECLARE_LIST( ImplHeadItemList, ImplHeadItem* )
69 // =======================================================================
71 #define HEAD_ARROWSIZE1 4
72 #define HEAD_ARROWSIZE2 7
74 #define HEADERBAR_TEXTOFF 2
75 #define HEADERBAR_ARROWOFF 5
76 #define HEADERBAR_SPLITOFF 3
78 #define HEADERBAR_DRAGOFF 4
79 #define HEADERBAR_DRAGOUTOFF 15
81 #define HEAD_HITTEST_ITEM ((USHORT)0x0001)
82 #define HEAD_HITTEST_DIVIDER ((USHORT)0x0002)
84 // =======================================================================
86 void HeaderBar::ImplInit( WinBits nWinStyle )
88 mpItemList = new ImplHeadItemList;
89 mnBorderOff1 = 0;
90 mnBorderOff2 = 0;
91 mnOffset = 0;
92 mnDX = 0;
93 mnDY = 0;
94 mnDragSize = 0;
95 mnStartPos = 0;
96 mnDragPos = 0;
97 mnMouseOff = 0;
98 mnCurItemId = 0;
99 mnItemDragPos = HEADERBAR_ITEM_NOTFOUND;
100 mbDrag = FALSE;
101 mbItemDrag = FALSE;
102 mbOutDrag = FALSE;
103 mbItemMode = FALSE;
105 // StyleBits auswerten
106 if ( nWinStyle & WB_DRAG )
107 mbDragable = TRUE;
108 else
109 mbDragable = FALSE;
110 if ( nWinStyle & WB_BUTTONSTYLE )
111 mbButtonStyle = TRUE;
112 else
113 mbButtonStyle = FALSE;
114 if ( nWinStyle & WB_BORDER )
116 mnBorderOff1 = 1;
117 mnBorderOff2 = 1;
119 else
121 if ( nWinStyle & WB_BOTTOMBORDER )
122 mnBorderOff2 = 1;
125 ImplInitSettings( TRUE, TRUE, TRUE );
128 // -----------------------------------------------------------------------
130 HeaderBar::HeaderBar( Window* pParent, WinBits nWinStyle ) :
131 Window( pParent, nWinStyle & WB_3DLOOK )
133 ImplInit( nWinStyle );
134 SetSizePixel( CalcWindowSizePixel() );
137 // -----------------------------------------------------------------------
139 HeaderBar::HeaderBar( Window* pParent, const ResId& rResId ) :
140 Window( pParent, rResId )
142 ImplInit( rResId.GetWinBits() );
145 // -----------------------------------------------------------------------
147 HeaderBar::~HeaderBar()
149 // Alle Items loeschen
150 ImplHeadItem* pItem = mpItemList->First();
151 while ( pItem )
153 delete pItem;
154 pItem = mpItemList->Next();
157 delete mpItemList;
160 // -----------------------------------------------------------------------
162 void HeaderBar::ImplInitSettings( BOOL bFont,
163 BOOL bForeground, BOOL bBackground )
165 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
167 if ( bFont )
169 Font aFont;
170 aFont = rStyleSettings.GetToolFont();
171 if ( IsControlFont() )
172 aFont.Merge( GetControlFont() );
173 SetZoomedPointFont( aFont );
176 if ( bForeground || bFont )
178 Color aColor;
179 if ( IsControlForeground() )
180 aColor = GetControlForeground();
181 else
182 aColor = rStyleSettings.GetButtonTextColor();
183 SetTextColor( aColor );
184 SetTextFillColor();
187 if ( bBackground )
189 Color aColor;
190 if ( IsControlBackground() )
191 aColor = GetControlBackground();
192 else
193 aColor = rStyleSettings.GetFaceColor();
194 SetBackground( aColor );
198 // -----------------------------------------------------------------------
200 long HeaderBar::ImplGetItemPos( USHORT nPos ) const
202 long nX = -mnOffset;
203 for ( USHORT i = 0; i < nPos; i++ )
204 nX += mpItemList->GetObject( i )->mnSize;
205 return nX;
208 // -----------------------------------------------------------------------
210 Rectangle HeaderBar::ImplGetItemRect( USHORT nPos ) const
212 Rectangle aRect( ImplGetItemPos( nPos ), 0, 0, mnDY-1 );
213 aRect.Right() = aRect.Left() + mpItemList->GetObject( nPos )->mnSize - 1;
214 // Gegen Ueberlauf auf einigen Systemen testen
215 if ( aRect.Right() > 16000 )
216 aRect.Right() = 16000;
217 return aRect;
220 // -----------------------------------------------------------------------
222 USHORT HeaderBar::ImplHitTest( const Point& rPos,
223 long& nMouseOff, USHORT& nPos ) const
225 ImplHeadItem* pItem;
226 USHORT nCount = (USHORT)mpItemList->Count();
227 BOOL bLastFixed = TRUE;
228 long nX = -mnOffset;
230 for ( USHORT i = 0; i < nCount; i++ )
232 pItem = mpItemList->GetObject( i );
234 if ( rPos.X() < (nX+pItem->mnSize) )
236 USHORT nMode;
238 if ( !bLastFixed && (rPos.X() < (nX+HEADERBAR_SPLITOFF)) )
240 nMode = HEAD_HITTEST_DIVIDER;
241 nPos = i-1;
242 nMouseOff = rPos.X()-nX+1;
244 else
246 nPos = i;
248 if ( !(pItem->mnBits & HIB_FIXED) && (rPos.X() >= (nX+pItem->mnSize-HEADERBAR_SPLITOFF)) )
250 nMode = HEAD_HITTEST_DIVIDER;
251 nMouseOff = rPos.X()-(nX+pItem->mnSize);
253 else
255 nMode = HEAD_HITTEST_ITEM;
256 nMouseOff = rPos.X()-nX;
260 return nMode;
263 if ( pItem->mnBits & HIB_FIXED )
264 bLastFixed = TRUE;
265 else
266 bLastFixed = FALSE;
268 nX += pItem->mnSize;
271 if ( !bLastFixed )
273 pItem = mpItemList->GetObject( nCount-1 );
274 if ( (pItem->mnSize < 4) && (rPos.X() < (nX+HEADERBAR_SPLITOFF)) )
276 nPos = nCount-1;
277 nMouseOff = rPos.X()-nX+1;
278 return HEAD_HITTEST_DIVIDER;
282 return 0;
285 // -----------------------------------------------------------------------
287 void HeaderBar::ImplInvertDrag( USHORT nStartPos, USHORT nEndPos )
289 Rectangle aRect1 = ImplGetItemRect( nStartPos );
290 Rectangle aRect2 = ImplGetItemRect( nEndPos );
291 Point aStartPos = aRect1.Center();
292 Point aEndPos = aStartPos;
293 Rectangle aStartRect( aStartPos.X()-2, aStartPos.Y()-2,
294 aStartPos.X()+2, aStartPos.Y()+2 );
296 if ( nEndPos > nStartPos )
298 aStartPos.X() += 3;
299 aEndPos.X() = aRect2.Right()-6;
301 else
303 aStartPos.X() -= 3;
304 aEndPos.X() = aRect2.Left()+6;
307 SetRasterOp( ROP_INVERT );
308 DrawRect( aStartRect );
309 DrawLine( aStartPos, aEndPos );
310 if ( nEndPos > nStartPos )
312 DrawLine( Point( aEndPos.X()+1, aEndPos.Y()-3 ),
313 Point( aEndPos.X()+1, aEndPos.Y()+3 ) );
314 DrawLine( Point( aEndPos.X()+2, aEndPos.Y()-2 ),
315 Point( aEndPos.X()+2, aEndPos.Y()+2 ) );
316 DrawLine( Point( aEndPos.X()+3, aEndPos.Y()-1 ),
317 Point( aEndPos.X()+3, aEndPos.Y()+1 ) );
318 DrawPixel( Point( aEndPos.X()+4, aEndPos.Y() ) );
320 else
322 DrawLine( Point( aEndPos.X()-1, aEndPos.Y()-3 ),
323 Point( aEndPos.X()-1, aEndPos.Y()+3 ) );
324 DrawLine( Point( aEndPos.X()-2, aEndPos.Y()-2 ),
325 Point( aEndPos.X()-2, aEndPos.Y()+2 ) );
326 DrawLine( Point( aEndPos.X()-3, aEndPos.Y()-1 ),
327 Point( aEndPos.X()-3, aEndPos.Y()+1 ) );
328 DrawPixel( Point( aEndPos.X()-4, aEndPos.Y() ) );
330 SetRasterOp( ROP_OVERPAINT );
333 // -----------------------------------------------------------------------
335 void HeaderBar::ImplDrawItem( OutputDevice* pDev,
336 USHORT nPos, BOOL bHigh, BOOL bDrag,
337 const Rectangle& rItemRect,
338 const Rectangle* pRect,
339 ULONG )
341 Rectangle aRect = rItemRect;
343 // Wenn kein Platz, dann brauchen wir auch nichts ausgeben
344 if ( aRect.GetWidth() <= 1 )
345 return;
347 // Feststellen, ob Rectangle ueberhaupt sichtbar
348 if ( pRect )
350 if ( aRect.Right() < pRect->Left() )
351 return;
352 else if ( aRect.Left() > pRect->Right() )
353 return;
355 else
357 if ( aRect.Right() < 0 )
358 return;
359 else if ( aRect.Left() > mnDX )
360 return;
363 ImplHeadItem* pItem = mpItemList->GetObject( nPos );
364 HeaderBarItemBits nBits = pItem->mnBits;
365 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
367 // Border muss nicht gemalt werden
368 aRect.Top() += mnBorderOff1;
369 aRect.Bottom() -= mnBorderOff2;
371 // Hintergrund loeschen
372 if ( !pRect || bDrag )
374 if ( bDrag )
376 pDev->SetLineColor();
377 pDev->SetFillColor( rStyleSettings.GetCheckedColor() );
378 pDev->DrawRect( aRect );
380 else
381 pDev->DrawWallpaper( aRect, GetBackground() );
384 // Trennlinie malen
385 pDev->SetLineColor( rStyleSettings.GetDarkShadowColor() );
386 pDev->DrawLine( Point( aRect.Right(), aRect.Top() ),
387 Point( aRect.Right(), aRect.Bottom() ) );
389 // ButtonStyle malen
390 // avoid 3D borders
391 Color aSelectionTextColor( COL_TRANSPARENT );
392 if( bHigh )
393 DrawSelectionBackground( aRect, 1, TRUE, FALSE, FALSE, &aSelectionTextColor );
394 else if ( !mbButtonStyle || (nBits & HIB_FLAT) )
395 DrawSelectionBackground( aRect, 0, TRUE, FALSE, FALSE, &aSelectionTextColor );
397 // Wenn kein Platz, dann brauchen wir auch nichts ausgeben
398 if ( aRect.GetWidth() < 1 )
399 return;
401 // Positionen und Groessen berechnen und Inhalt ausgeben
402 pItem->maOutText = pItem->maText;
403 Size aImageSize = pItem->maImage.GetSizePixel();
404 Size aTxtSize( pDev->GetTextWidth( pItem->maOutText ), 0 );
405 if ( pItem->maOutText.Len() )
406 aTxtSize.Height() = pDev->GetTextHeight();
407 long nArrowWidth = 0;
408 if ( nBits & (HIB_UPARROW | HIB_DOWNARROW) )
409 nArrowWidth = HEAD_ARROWSIZE2+HEADERBAR_ARROWOFF;
411 // Wenn kein Platz fuer Image, dann nicht ausgeben
412 long nTestHeight = aImageSize.Height();
413 if ( !(nBits & (HIB_LEFTIMAGE | HIB_RIGHTIMAGE)) )
414 nTestHeight += aTxtSize.Height();
415 if ( (aImageSize.Width() > aRect.GetWidth()) || (nTestHeight > aRect.GetHeight()) )
417 aImageSize.Width() = 0;
418 aImageSize.Height() = 0;
421 // Text auf entsprechende Laenge kuerzen
422 BOOL bLeftText = FALSE;
423 long nMaxTxtWidth = aRect.GetWidth()-(HEADERBAR_TEXTOFF*2)-nArrowWidth;
424 if ( nBits & (HIB_LEFTIMAGE | HIB_RIGHTIMAGE) )
425 nMaxTxtWidth -= aImageSize.Width();
426 long nTxtWidth = aTxtSize.Width();
427 if ( nTxtWidth > nMaxTxtWidth )
429 bLeftText = TRUE;
430 // 3 == Len of "..."
431 pItem->maOutText.AppendAscii( "..." );
434 pItem->maOutText.Erase( pItem->maOutText.Len()-3-1, 1 );
435 nTxtWidth = pDev->GetTextWidth( pItem->maOutText );
437 while ( (nTxtWidth > nMaxTxtWidth) && (pItem->maOutText.Len() > 3) );
438 if ( pItem->maOutText.Len() == 3 )
440 nTxtWidth = 0;
441 pItem->maOutText.Erase();
445 // Text/Imageposition berechnen
446 long nTxtPos;
447 if ( !bLeftText && (nBits & HIB_RIGHT) )
449 nTxtPos = aRect.Right()-nTxtWidth-HEADERBAR_TEXTOFF;
450 if ( nBits & HIB_RIGHTIMAGE )
451 nTxtPos -= aImageSize.Width();
453 else if ( !bLeftText && (nBits & HIB_CENTER) )
455 long nTempWidth = nTxtWidth;
456 if ( nBits & (HIB_LEFTIMAGE | HIB_RIGHTIMAGE) )
457 nTempWidth += aImageSize.Width();
458 nTxtPos = aRect.Left()+(aRect.GetWidth()-nTempWidth)/2;
459 if ( nBits & HIB_LEFTIMAGE )
460 nTxtPos += aImageSize.Width();
461 if ( nArrowWidth )
463 if ( nTxtPos+nTxtWidth+nArrowWidth >= aRect.Right() )
465 nTxtPos = aRect.Left()+HEADERBAR_TEXTOFF;
466 if ( nBits & HIB_LEFTIMAGE )
467 nTxtPos += aImageSize.Width();
471 else
473 nTxtPos = aRect.Left()+HEADERBAR_TEXTOFF;
474 if ( nBits & HIB_LEFTIMAGE )
475 nTxtPos += aImageSize.Width();
476 if ( nBits & HIB_RIGHT )
477 nTxtPos += nArrowWidth;
480 // TextPosition berechnen
481 long nTxtPosY = 0;
482 if ( pItem->maOutText.Len() || (nArrowWidth && aTxtSize.Height()) )
484 if ( nBits & HIB_TOP )
486 nTxtPosY = aRect.Top();
487 if ( !(nBits & (HIB_LEFTIMAGE | HIB_RIGHTIMAGE)) )
488 nTxtPosY += aImageSize.Height();
490 else if ( nBits & HIB_BOTTOM )
491 nTxtPosY = aRect.Bottom()-aTxtSize.Height();
492 else
494 long nTempHeight = aTxtSize.Height();
495 if ( !(nBits & (HIB_LEFTIMAGE | HIB_RIGHTIMAGE)) )
496 nTempHeight += aImageSize.Height();
497 nTxtPosY = aRect.Top()+((aRect.GetHeight()-nTempHeight)/2);
498 if ( !(nBits & (HIB_LEFTIMAGE | HIB_RIGHTIMAGE)) )
499 nTxtPosY += aImageSize.Height();
503 // Text ausgebeben
504 if ( pItem->maOutText.Len() )
506 if( aSelectionTextColor != Color( COL_TRANSPARENT ) )
508 pDev->Push( PUSH_TEXTCOLOR );
509 pDev->SetTextColor( aSelectionTextColor );
511 if ( IsEnabled() )
512 pDev->DrawText( Point( nTxtPos, nTxtPosY ), pItem->maOutText );
513 else
514 pDev->DrawCtrlText( Point( nTxtPos, nTxtPosY ), pItem->maOutText, 0, STRING_LEN, TEXT_DRAW_DISABLE );
515 if( aSelectionTextColor != Color( COL_TRANSPARENT ) )
516 pDev->Pop();
519 // Wenn Image vorhanden, Position berechnen und ausgeben
520 long nImagePosY = 0;
521 if ( aImageSize.Width() && aImageSize.Height() )
523 long nImagePos = nTxtPos;
524 if ( nBits & HIB_LEFTIMAGE )
526 nImagePos -= aImageSize.Width();
527 if ( nBits & HIB_RIGHT )
528 nImagePos -= nArrowWidth;
530 else if ( nBits & HIB_RIGHTIMAGE )
532 nImagePos += nTxtWidth;
533 if ( !(nBits & HIB_RIGHT) )
534 nImagePos += nArrowWidth;
536 else
538 if ( nBits & HIB_RIGHT )
539 nImagePos = aRect.Right()-aImageSize.Width();
540 else if ( nBits & HIB_CENTER )
541 nImagePos = aRect.Left()+(aRect.GetWidth()-aImageSize.Width())/2;
542 else
543 nImagePos = aRect.Left()+HEADERBAR_TEXTOFF;
546 if ( nBits & HIB_TOP )
547 nImagePosY = aRect.Top();
548 else if ( nBits & HIB_BOTTOM )
550 nImagePosY = aRect.Bottom()-aImageSize.Height();
551 if ( !(nBits & (HIB_LEFTIMAGE | HIB_RIGHTIMAGE)) )
552 nImagePosY -= aTxtSize.Height();
554 else
556 long nTempHeight = aImageSize.Height();
557 if ( !(nBits & (HIB_LEFTIMAGE | HIB_RIGHTIMAGE)) )
558 nTempHeight += aTxtSize.Height();
559 nImagePosY = aRect.Top()+((aRect.GetHeight()-nTempHeight)/2);
561 if ( nImagePos+aImageSize.Width() <= aRect.Right() )
563 USHORT nStyle = 0;
564 if ( !IsEnabled() )
565 nStyle |= IMAGE_DRAW_DISABLE;
566 pDev->DrawImage( Point( nImagePos, nImagePosY ), pItem->maImage, nStyle );
570 if ( nBits & (HIB_UPARROW | HIB_DOWNARROW) )
572 long nArrowX = nTxtPos;
573 if ( nBits & HIB_RIGHT )
574 nArrowX -= nArrowWidth;
575 else
576 nArrowX += nTxtWidth+HEADERBAR_ARROWOFF;
577 if ( !(nBits & (HIB_LEFTIMAGE | HIB_RIGHTIMAGE)) && !pItem->maText.Len() )
579 if ( nBits & HIB_RIGHT )
580 nArrowX -= aImageSize.Width();
581 else
582 nArrowX += aImageSize.Width();
585 // Feststellen, ob Platz genug ist, das Item zu malen
586 BOOL bDraw = TRUE;
587 if ( nArrowX < aRect.Left()+HEADERBAR_TEXTOFF )
588 bDraw = FALSE;
589 else if ( nArrowX+HEAD_ARROWSIZE2 > aRect.Right() )
590 bDraw = FALSE;
592 if ( bDraw )
594 long nArrowY;
595 if ( aTxtSize.Height() )
596 nArrowY = nTxtPosY+(aTxtSize.Height()/2);
597 else if ( aImageSize.Width() && aImageSize.Height() )
598 nArrowY = nImagePosY+(aImageSize.Height()/2);
599 else
601 if ( nBits & HIB_TOP )
602 nArrowY = aRect.Top()+1;
603 else if ( nBits & HIB_BOTTOM )
604 nArrowY = aRect.Bottom()-HEAD_ARROWSIZE2-1;
605 else
606 nArrowY = aRect.Top()+((aRect.GetHeight()-HEAD_ARROWSIZE2)/2);;
608 nArrowY -= HEAD_ARROWSIZE1-1;
609 if ( nBits & HIB_DOWNARROW )
611 pDev->SetLineColor( rStyleSettings.GetLightColor() );
612 pDev->DrawLine( Point( nArrowX, nArrowY ),
613 Point( nArrowX+HEAD_ARROWSIZE2, nArrowY ) );
614 pDev->DrawLine( Point( nArrowX, nArrowY ),
615 Point( nArrowX+HEAD_ARROWSIZE1, nArrowY+HEAD_ARROWSIZE2 ) );
616 pDev->SetLineColor( rStyleSettings.GetShadowColor() );
617 pDev->DrawLine( Point( nArrowX+HEAD_ARROWSIZE1, nArrowY+HEAD_ARROWSIZE2 ),
618 Point( nArrowX+HEAD_ARROWSIZE2, nArrowY ) );
620 else
622 pDev->SetLineColor( rStyleSettings.GetLightColor() );
623 pDev->DrawLine( Point( nArrowX, nArrowY+HEAD_ARROWSIZE2 ),
624 Point( nArrowX+HEAD_ARROWSIZE1, nArrowY ) );
625 pDev->SetLineColor( rStyleSettings.GetShadowColor() );
626 pDev->DrawLine( Point( nArrowX, nArrowY+HEAD_ARROWSIZE2 ),
627 Point( nArrowX+HEAD_ARROWSIZE2, nArrowY+HEAD_ARROWSIZE2 ) );
628 pDev->DrawLine( Point( nArrowX+HEAD_ARROWSIZE2, nArrowY+HEAD_ARROWSIZE2 ),
629 Point( nArrowX+HEAD_ARROWSIZE1, nArrowY ) );
634 // Gegebenenfalls auch UserDraw aufrufen
635 if ( nBits & HIB_USERDRAW )
637 Region aRegion( aRect );
638 if ( pRect )
639 aRegion.Intersect( *pRect );
640 pDev->SetClipRegion( aRegion );
641 UserDrawEvent aODEvt( pDev, aRect, pItem->mnId );
642 UserDraw( aODEvt );
643 pDev->SetClipRegion();
647 // -----------------------------------------------------------------------
649 void HeaderBar::ImplDrawItem( USHORT nPos, BOOL bHigh, BOOL bDrag,
650 const Rectangle* pRect )
652 Rectangle aRect = ImplGetItemRect( nPos );
653 ImplDrawItem( this, nPos, bHigh, bDrag, aRect, pRect, 0 );
656 // -----------------------------------------------------------------------
658 void HeaderBar::ImplUpdate( USHORT nPos, BOOL bEnd, BOOL bDirect )
660 if ( IsVisible() && IsUpdateMode() )
662 if ( !bDirect )
664 Rectangle aRect;
665 USHORT nItemCount = (USHORT)(mpItemList->Count());
666 if ( nPos < nItemCount )
667 aRect = ImplGetItemRect( nPos );
668 else
670 aRect.Bottom() = mnDY-1;
671 if ( nItemCount )
672 aRect.Left() = ImplGetItemRect( nItemCount-1 ).Right();
674 if ( bEnd )
675 aRect.Right() = mnDX-1;
676 aRect.Top() += mnBorderOff1;
677 aRect.Bottom() -= mnBorderOff2;
678 Invalidate( aRect );
680 else
682 for ( USHORT i = nPos; i < mpItemList->Count(); i++ )
683 ImplDrawItem( i );
684 if ( bEnd )
686 Rectangle aRect = ImplGetItemRect( (USHORT)mpItemList->Count() );
687 aRect.Left() = aRect.Right();
688 aRect.Right() = mnDX-1;
689 if ( aRect.Left() < aRect.Right() )
691 aRect.Top() += mnBorderOff1;
692 aRect.Bottom() -= mnBorderOff2;
693 Erase( aRect );
700 // -----------------------------------------------------------------------
702 void HeaderBar::ImplStartDrag( const Point& rMousePos, BOOL bCommand )
704 USHORT nPos;
705 USHORT nHitTest = ImplHitTest( rMousePos, mnMouseOff, nPos );
706 if ( nHitTest )
708 mbDrag = FALSE;
709 ImplHeadItem* pItem = mpItemList->GetObject( nPos );
710 if ( nHitTest & HEAD_HITTEST_DIVIDER )
711 mbDrag = TRUE;
712 else
714 if ( ((pItem->mnBits & HIB_CLICKABLE) && !(pItem->mnBits & HIB_FLAT)) ||
715 (mbDragable && !(pItem->mnBits & HIB_FIXEDPOS)) )
717 mbItemMode = TRUE;
718 mbDrag = TRUE;
719 if ( bCommand )
721 if ( mbDragable )
722 mbItemDrag = TRUE;
723 else
725 mbItemMode = FALSE;
726 mbDrag = FALSE;
730 else
732 if ( !bCommand )
734 mnCurItemId = pItem->mnId;
735 Select();
736 mnCurItemId = 0;
741 if ( mbDrag )
743 mbOutDrag = FALSE;
744 mnCurItemId = pItem->mnId;
745 mnItemDragPos = nPos;
746 StartTracking();
747 mnStartPos = rMousePos.X()-mnMouseOff;
748 mnDragPos = mnStartPos;
749 StartDrag();
750 if ( mbItemMode )
751 ImplDrawItem( nPos, TRUE, mbItemDrag );
752 else
754 Rectangle aSizeRect( mnDragPos, 0, mnDragPos, mnDragSize+mnDY );
755 ShowTracking( aSizeRect, SHOWTRACK_SPLIT );
758 else
759 mnMouseOff = 0;
763 // -----------------------------------------------------------------------
765 void HeaderBar::ImplDrag( const Point& rMousePos )
767 BOOL bNewOutDrag;
768 USHORT nPos = GetItemPos( mnCurItemId );
770 mnDragPos = rMousePos.X()-mnMouseOff;
771 if ( mbItemMode )
773 Rectangle aItemRect = ImplGetItemRect( nPos );
774 if ( aItemRect.IsInside( rMousePos ) )
775 bNewOutDrag = FALSE;
776 else
777 bNewOutDrag = TRUE;
779 // Evt. ItemDrag anschalten
780 if ( bNewOutDrag && mbDragable && !mbItemDrag &&
781 !(mpItemList->GetObject(nPos)->mnBits & HIB_FIXEDPOS) )
783 if ( (rMousePos.Y() >= aItemRect.Top()) && (rMousePos.Y() <= aItemRect.Bottom()) )
785 mbItemDrag = TRUE;
786 ImplDrawItem( nPos, TRUE, mbItemDrag );
790 USHORT nOldItemDragPos = mnItemDragPos;
791 if ( mbItemDrag )
793 if ( (rMousePos.Y() < -HEADERBAR_DRAGOUTOFF) || (rMousePos.Y() > mnDY+HEADERBAR_DRAGOUTOFF) )
794 bNewOutDrag = TRUE;
795 else
796 bNewOutDrag = FALSE;
798 if ( bNewOutDrag )
799 mnItemDragPos = HEADERBAR_ITEM_NOTFOUND;
800 else
802 USHORT nTempId = GetItemId( Point( rMousePos.X(), 2 ) );
803 if ( nTempId )
804 mnItemDragPos = GetItemPos( nTempId );
805 else
807 if ( rMousePos.X() <= 0 )
808 mnItemDragPos = 0;
809 else
810 mnItemDragPos = GetItemCount()-1;
813 // Nicht verschiebbare Items aussparen
814 if ( mnItemDragPos < nPos )
816 while ( (mpItemList->GetObject(mnItemDragPos)->mnBits & HIB_FIXEDPOS) &&
817 (mnItemDragPos < nPos) )
818 mnItemDragPos++;
820 else if ( mnItemDragPos > nPos )
822 while ( (mpItemList->GetObject(mnItemDragPos)->mnBits & HIB_FIXEDPOS) &&
823 (mnItemDragPos > nPos) )
824 mnItemDragPos--;
828 if ( (mnItemDragPos != nOldItemDragPos) &&
829 (nOldItemDragPos != nPos) &&
830 (nOldItemDragPos != HEADERBAR_ITEM_NOTFOUND) )
832 ImplInvertDrag( nPos, nOldItemDragPos );
833 ImplDrawItem( nOldItemDragPos );
837 if ( bNewOutDrag != mbOutDrag )
838 ImplDrawItem( nPos, !bNewOutDrag, mbItemDrag );
840 if ( mbItemDrag )
842 if ( (mnItemDragPos != nOldItemDragPos) &&
843 (mnItemDragPos != nPos) &&
844 (mnItemDragPos != HEADERBAR_ITEM_NOTFOUND) )
846 ImplDrawItem( mnItemDragPos, FALSE, TRUE );
847 ImplInvertDrag( nPos, mnItemDragPos );
851 mbOutDrag = bNewOutDrag;
853 else
855 Rectangle aItemRect = ImplGetItemRect( nPos );
856 if ( mnDragPos < aItemRect.Left() )
857 mnDragPos = aItemRect.Left();
858 if ( (mnDragPos < 0) || (mnDragPos > mnDX-1) )
859 HideTracking();
860 else
862 Rectangle aSizeRect( mnDragPos, 0, mnDragPos, mnDragSize+mnDY );
863 ShowTracking( aSizeRect, SHOWTRACK_SPLIT );
867 Drag();
870 // -----------------------------------------------------------------------
872 void HeaderBar::ImplEndDrag( BOOL bCancel )
874 HideTracking();
876 if ( bCancel || mbOutDrag )
878 if ( mbItemMode && (!mbOutDrag || mbItemDrag) )
880 USHORT nPos = GetItemPos( mnCurItemId );
881 ImplDrawItem( nPos );
884 mnCurItemId = 0;
886 else
888 USHORT nPos = GetItemPos( mnCurItemId );
889 if ( mbItemMode )
891 if ( mbItemDrag )
893 Pointer aPointer( POINTER_ARROW );
894 SetPointer( aPointer );
895 if ( (mnItemDragPos != nPos) &&
896 (mnItemDragPos != HEADERBAR_ITEM_NOTFOUND) )
898 ImplInvertDrag( nPos, mnItemDragPos );
899 MoveItem( mnCurItemId, mnItemDragPos );
901 else
902 ImplDrawItem( nPos );
904 else
906 Select();
907 ImplUpdate( nPos );
910 else
912 long nDelta = mnDragPos - mnStartPos;
913 if ( nDelta )
915 ImplHeadItem* pItem = mpItemList->GetObject( nPos );
916 pItem->mnSize += nDelta;
917 ImplUpdate( nPos, TRUE );
922 mbDrag = FALSE;
923 EndDrag();
924 mnCurItemId = 0;
925 mnItemDragPos = HEADERBAR_ITEM_NOTFOUND;
926 mbOutDrag = FALSE;
927 mbItemMode = FALSE;
928 mbItemDrag = FALSE;
931 // -----------------------------------------------------------------------
933 void HeaderBar::MouseButtonDown( const MouseEvent& rMEvt )
935 if ( rMEvt.IsLeft() )
937 if ( rMEvt.GetClicks() == 2 )
939 long nTemp;
940 USHORT nPos;
941 USHORT nHitTest = ImplHitTest( rMEvt.GetPosPixel(), nTemp, nPos );
942 if ( nHitTest )
944 ImplHeadItem* pItem = mpItemList->GetObject( nPos );
945 if ( nHitTest & HEAD_HITTEST_DIVIDER )
946 mbItemMode = FALSE;
947 else
948 mbItemMode = TRUE;
949 mnCurItemId = pItem->mnId;
950 DoubleClick();
951 mbItemMode = FALSE;
952 mnCurItemId = 0;
955 else
956 ImplStartDrag( rMEvt.GetPosPixel(), FALSE );
960 // -----------------------------------------------------------------------
962 void HeaderBar::MouseMove( const MouseEvent& rMEvt )
964 long nTemp1;
965 USHORT nTemp2;
966 PointerStyle eStyle = POINTER_ARROW;
967 USHORT nHitTest = ImplHitTest( rMEvt.GetPosPixel(), nTemp1, nTemp2 );
969 if ( nHitTest & HEAD_HITTEST_DIVIDER )
970 eStyle = POINTER_HSIZEBAR;
971 Pointer aPtr( eStyle );
972 SetPointer( aPtr );
975 // -----------------------------------------------------------------------
977 void HeaderBar::Tracking( const TrackingEvent& rTEvt )
979 Point aMousePos = rTEvt.GetMouseEvent().GetPosPixel();
981 if ( rTEvt.IsTrackingEnded() )
982 ImplEndDrag( rTEvt.IsTrackingCanceled() );
983 else
984 ImplDrag( aMousePos );
987 // -----------------------------------------------------------------------
989 void HeaderBar::Paint( const Rectangle& rRect )
991 if ( mnBorderOff1 || mnBorderOff2 )
993 SetLineColor( GetSettings().GetStyleSettings().GetDarkShadowColor() );
994 if ( mnBorderOff1 )
995 DrawLine( Point( 0, 0 ), Point( mnDX-1, 0 ) );
996 if ( mnBorderOff2 )
997 DrawLine( Point( 0, mnDY-1 ), Point( mnDX-1, mnDY-1 ) );
998 // #i40393# draw left and right border, if WB_BORDER was set in ImplInit()
999 if ( mnBorderOff1 && mnBorderOff2 )
1001 DrawLine( Point( 0, 0 ), Point( 0, mnDY-1 ) );
1002 DrawLine( Point( mnDX-1, 0 ), Point( mnDX-1, mnDY-1 ) );
1006 USHORT nCurItemPos;
1007 if ( mbDrag )
1008 nCurItemPos = GetItemPos( mnCurItemId );
1009 else
1010 nCurItemPos = HEADERBAR_ITEM_NOTFOUND;
1011 USHORT nItemCount = (USHORT)mpItemList->Count();
1012 for ( USHORT i = 0; i < nItemCount; i++ )
1013 ImplDrawItem( i, (i == nCurItemPos) ? TRUE : FALSE, FALSE, &rRect );
1016 // -----------------------------------------------------------------------
1018 void HeaderBar::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize,
1019 ULONG nFlags )
1021 Point aPos = pDev->LogicToPixel( rPos );
1022 Size aSize = pDev->LogicToPixel( rSize );
1023 Rectangle aRect( aPos, aSize );
1024 Font aFont = GetDrawPixelFont( pDev );
1026 pDev->Push();
1027 pDev->SetMapMode();
1028 pDev->SetFont( aFont );
1029 if ( nFlags & WINDOW_DRAW_MONO )
1030 pDev->SetTextColor( Color( COL_BLACK ) );
1031 else
1032 pDev->SetTextColor( GetTextColor() );
1033 pDev->SetTextFillColor();
1035 if ( !(nFlags & WINDOW_DRAW_NOBACKGROUND) )
1037 pDev->DrawWallpaper( aRect, GetBackground() );
1038 if ( mnBorderOff1 || mnBorderOff2 )
1040 pDev->SetLineColor( GetSettings().GetStyleSettings().GetDarkShadowColor() );
1041 if ( mnBorderOff1 )
1042 pDev->DrawLine( aRect.TopLeft(), Point( aRect.Right(), aRect.Top() ) );
1043 if ( mnBorderOff2 )
1044 pDev->DrawLine( Point( aRect.Left(), aRect.Bottom() ), Point( aRect.Right(), aRect.Bottom() ) );
1045 // #i40393# draw left and right border, if WB_BORDER was set in ImplInit()
1046 if ( mnBorderOff1 && mnBorderOff2 )
1048 pDev->DrawLine( aRect.TopLeft(), Point( aRect.Left(), aRect.Bottom() ) );
1049 pDev->DrawLine( Point( aRect.Right(), aRect.Top() ), Point( aRect.Right(), aRect.Bottom() ) );
1054 Rectangle aItemRect( aRect );
1055 // aItemRect.Bottom()--;
1056 USHORT nItemCount = (USHORT)mpItemList->Count();
1057 for ( USHORT i = 0; i < nItemCount; i++ )
1059 aItemRect.Left() = aRect.Left()+ImplGetItemPos( i );
1060 aItemRect.Right() = aItemRect.Left() + mpItemList->GetObject( i )->mnSize - 1;
1061 // Gegen Ueberlauf auf einigen Systemen testen
1062 if ( aItemRect.Right() > 16000 )
1063 aItemRect.Right() = 16000;
1064 Region aRegion( aRect );
1065 pDev->SetClipRegion( aRegion );
1066 ImplDrawItem( pDev, i, FALSE, FALSE, aItemRect, &aRect, nFlags );
1067 pDev->SetClipRegion();
1070 pDev->Pop();
1073 // -----------------------------------------------------------------------
1075 void HeaderBar::Resize()
1077 Size aSize = GetOutputSizePixel();
1078 if ( IsVisible() && (mnDY != aSize.Height()) )
1079 Invalidate();
1080 mnDX = aSize.Width();
1081 mnDY = aSize.Height();
1084 // -----------------------------------------------------------------------
1086 void HeaderBar::Command( const CommandEvent& rCEvt )
1088 if ( rCEvt.IsMouseEvent() && (rCEvt.GetCommand() == COMMAND_STARTDRAG) && !mbDrag )
1090 ImplStartDrag( rCEvt.GetMousePosPixel(), TRUE );
1091 return;
1094 Window::Command( rCEvt );
1097 // -----------------------------------------------------------------------
1099 void HeaderBar::RequestHelp( const HelpEvent& rHEvt )
1101 USHORT nItemId = GetItemId( ScreenToOutputPixel( rHEvt.GetMousePosPixel() ) );
1102 if ( nItemId )
1104 if ( rHEvt.GetMode() & (HELPMODE_QUICK | HELPMODE_BALLOON) )
1106 Rectangle aItemRect = GetItemRect( nItemId );
1107 Point aPt = OutputToScreenPixel( aItemRect.TopLeft() );
1108 aItemRect.Left() = aPt.X();
1109 aItemRect.Top() = aPt.Y();
1110 aPt = OutputToScreenPixel( aItemRect.BottomRight() );
1111 aItemRect.Right() = aPt.X();
1112 aItemRect.Bottom() = aPt.Y();
1114 XubString aStr = GetHelpText( nItemId );
1115 if ( !aStr.Len() || !(rHEvt.GetMode() & HELPMODE_BALLOON) )
1117 ImplHeadItem* pItem = mpItemList->GetObject( GetItemPos( nItemId ) );
1118 // Wir zeigen die Quick-Hilfe nur an, wenn Text nicht
1119 // vollstaendig sichtbar, ansonsten zeigen wir den Hilfetext
1120 // an, wenn das Item keinen Text besitzt
1121 if ( pItem->maOutText != pItem->maText )
1122 aStr = pItem->maText;
1123 else if ( pItem->maText.Len() )
1124 aStr.Erase();
1127 if ( aStr.Len() )
1129 if ( rHEvt.GetMode() & HELPMODE_BALLOON )
1130 Help::ShowBalloon( this, aItemRect.Center(), aItemRect, aStr );
1131 else
1132 Help::ShowQuickHelp( this, aItemRect, aStr );
1133 return;
1136 else if ( rHEvt.GetMode() & HELPMODE_EXTENDED )
1138 ULONG nHelpId = GetHelpId( nItemId );
1139 if ( nHelpId )
1141 // Wenn eine Hilfe existiert, dann ausloesen
1142 Help* pHelp = Application::GetHelp();
1143 if ( pHelp )
1144 pHelp->Start( nHelpId, this );
1145 return;
1150 Window::RequestHelp( rHEvt );
1153 // -----------------------------------------------------------------------
1155 void HeaderBar::StateChanged( StateChangedType nType )
1157 Window::StateChanged( nType );
1159 if ( nType == STATE_CHANGE_ENABLE )
1160 Invalidate();
1161 else if ( (nType == STATE_CHANGE_ZOOM) ||
1162 (nType == STATE_CHANGE_CONTROLFONT) )
1164 ImplInitSettings( TRUE, FALSE, FALSE );
1165 Invalidate();
1167 else if ( nType == STATE_CHANGE_CONTROLFOREGROUND )
1169 ImplInitSettings( FALSE, TRUE, FALSE );
1170 Invalidate();
1172 else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
1174 ImplInitSettings( FALSE, FALSE, TRUE );
1175 Invalidate();
1179 // -----------------------------------------------------------------------
1181 void HeaderBar::DataChanged( const DataChangedEvent& rDCEvt )
1183 Window::DataChanged( rDCEvt );
1185 if ( (rDCEvt.GetType() == DATACHANGED_FONTS) ||
1186 (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) ||
1187 ((rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
1188 (rDCEvt.GetFlags() & SETTINGS_STYLE)) )
1190 ImplInitSettings( TRUE, TRUE, TRUE );
1191 Invalidate();
1195 // -----------------------------------------------------------------------
1197 void HeaderBar::UserDraw( const UserDrawEvent& )
1201 // -----------------------------------------------------------------------
1203 void HeaderBar::StartDrag()
1205 maStartDragHdl.Call( this );
1208 // -----------------------------------------------------------------------
1210 void HeaderBar::Drag()
1212 maDragHdl.Call( this );
1215 // -----------------------------------------------------------------------
1217 void HeaderBar::EndDrag()
1219 maEndDragHdl.Call( this );
1222 // -----------------------------------------------------------------------
1224 void HeaderBar::Select()
1226 maSelectHdl.Call( this );
1229 // -----------------------------------------------------------------------
1231 void HeaderBar::DoubleClick()
1233 maDoubleClickHdl.Call( this );
1236 // -----------------------------------------------------------------------
1238 void HeaderBar::InsertItem( USHORT nItemId, const Image& rImage,
1239 long nSize, HeaderBarItemBits nBits, USHORT nPos )
1241 DBG_ASSERT( nItemId, "HeaderBar::InsertItem(): ItemId == 0" );
1242 DBG_ASSERT( GetItemPos( nItemId ) == HEADERBAR_ITEM_NOTFOUND,
1243 "HeaderBar::InsertItem(): ItemId already exists" );
1245 // Item anlegen und in die Liste einfuegen
1246 ImplHeadItem* pItem = new ImplHeadItem;
1247 pItem->mnId = nItemId;
1248 pItem->mnBits = nBits;
1249 pItem->mnSize = nSize;
1250 pItem->maImage = rImage;
1251 pItem->mpUserData = 0;
1252 mpItemList->Insert( pItem, nPos );
1254 // Ausgabe updaten
1255 ImplUpdate( nPos, TRUE );
1258 // -----------------------------------------------------------------------
1260 void HeaderBar::InsertItem( USHORT nItemId, const XubString& rText,
1261 long nSize, HeaderBarItemBits nBits, USHORT nPos )
1263 DBG_ASSERT( nItemId, "HeaderBar::InsertItem(): ItemId == 0" );
1264 DBG_ASSERT( GetItemPos( nItemId ) == HEADERBAR_ITEM_NOTFOUND,
1265 "HeaderBar::InsertItem(): ItemId already exists" );
1267 // Item anlegen und in die Liste einfuegen
1268 ImplHeadItem* pItem = new ImplHeadItem;
1269 pItem->mnId = nItemId;
1270 pItem->mnBits = nBits;
1271 pItem->mnSize = nSize;
1272 pItem->mnHelpId = 0;
1273 pItem->maText = rText;
1274 pItem->mpUserData = 0;
1275 mpItemList->Insert( pItem, nPos );
1277 // Ausgabe updaten
1278 ImplUpdate( nPos, TRUE );
1281 // -----------------------------------------------------------------------
1283 void HeaderBar::InsertItem( USHORT nItemId,
1284 const Image& rImage, const XubString& rText,
1285 long nSize, HeaderBarItemBits nBits,
1286 USHORT nPos )
1288 DBG_ASSERT( nItemId, "HeaderBar::InsertItem(): ItemId == 0" );
1289 DBG_ASSERT( GetItemPos( nItemId ) == HEADERBAR_ITEM_NOTFOUND,
1290 "HeaderBar::InsertItem(): ItemId already exists" );
1292 // Item anlegen und in die Liste einfuegen
1293 ImplHeadItem* pItem = new ImplHeadItem;
1294 pItem->mnId = nItemId;
1295 pItem->mnBits = nBits;
1296 pItem->mnSize = nSize;
1297 pItem->mnHelpId = 0;
1298 pItem->maImage = rImage;
1299 pItem->maText = rText;
1300 pItem->mpUserData = 0;
1301 mpItemList->Insert( pItem, nPos );
1303 // Ausgabe updaten
1304 ImplUpdate( nPos, TRUE );
1307 // -----------------------------------------------------------------------
1309 void HeaderBar::RemoveItem( USHORT nItemId )
1311 USHORT nPos = GetItemPos( nItemId );
1312 if ( nPos != HEADERBAR_ITEM_NOTFOUND )
1314 ImplHeadItem* pItem = mpItemList->Remove( nPos );
1315 delete pItem;
1316 ImplUpdate( nPos, TRUE );
1320 // -----------------------------------------------------------------------
1322 void HeaderBar::MoveItem( USHORT nItemId, USHORT nNewPos )
1324 USHORT nPos = GetItemPos( nItemId );
1325 if ( nPos != HEADERBAR_ITEM_NOTFOUND )
1327 if ( nPos != nNewPos )
1329 ImplHeadItem* pItem = mpItemList->Remove( nPos );
1330 if ( nNewPos < nPos )
1331 nPos = nNewPos;
1332 mpItemList->Insert( pItem, nNewPos );
1333 ImplUpdate( nPos, TRUE );
1338 // -----------------------------------------------------------------------
1340 void HeaderBar::Clear()
1342 // Alle Items loeschen
1343 ImplHeadItem* pItem = mpItemList->First();
1344 while ( pItem )
1346 delete pItem;
1347 pItem = mpItemList->Next();
1349 mpItemList->Clear();
1351 ImplUpdate( 0, TRUE );
1354 // -----------------------------------------------------------------------
1356 void HeaderBar::SetOffset( long nNewOffset )
1358 // Hier erstmal neu zeichnen, damit mit alten Offset noch das
1359 // richtige gemalt wird
1360 //Update();
1362 // Bereich verschieben
1363 Rectangle aRect( 0, mnBorderOff1, mnDX-1, mnDY-mnBorderOff1-mnBorderOff2-1 );
1364 long nDelta = mnOffset-nNewOffset;
1365 mnOffset = nNewOffset;
1366 Scroll( nDelta, 0, aRect );
1369 // -----------------------------------------------------------------------
1371 USHORT HeaderBar::GetItemCount() const
1373 return (USHORT)mpItemList->Count();
1376 // -----------------------------------------------------------------------
1378 USHORT HeaderBar::GetItemPos( USHORT nItemId ) const
1380 ImplHeadItem* pItem = mpItemList->First();
1381 while ( pItem )
1383 if ( pItem->mnId == nItemId )
1384 return (USHORT)mpItemList->GetCurPos();
1385 pItem = mpItemList->Next();
1388 return HEADERBAR_ITEM_NOTFOUND;
1391 // -----------------------------------------------------------------------
1393 USHORT HeaderBar::GetItemId( USHORT nPos ) const
1395 ImplHeadItem* pItem = mpItemList->GetObject( nPos );
1396 if ( pItem )
1397 return pItem->mnId;
1398 else
1399 return 0;
1402 // -----------------------------------------------------------------------
1404 USHORT HeaderBar::GetItemId( const Point& rPos ) const
1406 USHORT nPos = 0;
1407 while ( nPos < mpItemList->Count() )
1409 if ( ImplGetItemRect( nPos ).IsInside( rPos ) )
1410 return GetItemId( nPos );
1412 nPos++;
1415 return 0;
1418 // -----------------------------------------------------------------------
1420 Rectangle HeaderBar::GetItemRect( USHORT nItemId ) const
1422 Rectangle aRect;
1423 USHORT nPos = GetItemPos( nItemId );
1424 if ( nPos != HEADERBAR_ITEM_NOTFOUND )
1425 aRect = ImplGetItemRect( nPos );
1426 return aRect;
1429 // -----------------------------------------------------------------------
1431 void HeaderBar::SetItemSize( USHORT nItemId, long nNewSize )
1433 USHORT nPos = GetItemPos( nItemId );
1434 if ( nPos != HEADERBAR_ITEM_NOTFOUND )
1436 ImplHeadItem* pItem = mpItemList->GetObject( nPos );
1437 if ( pItem->mnSize != nNewSize )
1439 pItem->mnSize = nNewSize;
1440 ImplUpdate( nPos, TRUE );
1445 // -----------------------------------------------------------------------
1447 long HeaderBar::GetItemSize( USHORT nItemId ) const
1449 USHORT nPos = GetItemPos( nItemId );
1450 if ( nPos != HEADERBAR_ITEM_NOTFOUND )
1451 return mpItemList->GetObject( nPos )->mnSize;
1452 else
1453 return 0;
1456 // -----------------------------------------------------------------------
1458 void HeaderBar::SetItemBits( USHORT nItemId, HeaderBarItemBits nNewBits )
1460 USHORT nPos = GetItemPos( nItemId );
1461 if ( nPos != HEADERBAR_ITEM_NOTFOUND )
1463 ImplHeadItem* pItem = mpItemList->GetObject( nPos );
1464 if ( pItem->mnBits != nNewBits )
1466 pItem->mnBits = nNewBits;
1467 ImplUpdate( nPos );
1472 // -----------------------------------------------------------------------
1474 HeaderBarItemBits HeaderBar::GetItemBits( USHORT nItemId ) const
1476 USHORT nPos = GetItemPos( nItemId );
1477 if ( nPos != HEADERBAR_ITEM_NOTFOUND )
1478 return mpItemList->GetObject( nPos )->mnBits;
1479 else
1480 return 0;
1483 // -----------------------------------------------------------------------
1485 void HeaderBar::SetItemData( USHORT nItemId, void* pNewData )
1487 USHORT nPos = GetItemPos( nItemId );
1488 if ( nPos != HEADERBAR_ITEM_NOTFOUND )
1490 mpItemList->GetObject( nPos )->mpUserData = pNewData;
1491 ImplUpdate( nPos );
1495 // -----------------------------------------------------------------------
1497 void* HeaderBar::GetItemData( USHORT nItemId ) const
1499 USHORT nPos = GetItemPos( nItemId );
1500 if ( nPos != HEADERBAR_ITEM_NOTFOUND )
1501 return mpItemList->GetObject( nPos )->mpUserData;
1502 else
1503 return NULL;
1506 // -----------------------------------------------------------------------
1508 void HeaderBar::SetItemImage( USHORT nItemId, const Image& rImage )
1510 USHORT nPos = GetItemPos( nItemId );
1511 if ( nPos != HEADERBAR_ITEM_NOTFOUND )
1513 mpItemList->GetObject( nPos )->maImage = rImage;
1514 ImplUpdate( nPos );
1518 // -----------------------------------------------------------------------
1520 Image HeaderBar::GetItemImage( USHORT nItemId ) const
1522 USHORT nPos = GetItemPos( nItemId );
1523 if ( nPos != HEADERBAR_ITEM_NOTFOUND )
1524 return mpItemList->GetObject( nPos )->maImage;
1525 else
1526 return Image();
1529 // -----------------------------------------------------------------------
1531 void HeaderBar::SetItemText( USHORT nItemId, const XubString& rText )
1533 USHORT nPos = GetItemPos( nItemId );
1534 if ( nPos != HEADERBAR_ITEM_NOTFOUND )
1536 mpItemList->GetObject( nPos )->maText = rText;
1537 ImplUpdate( nPos );
1541 // -----------------------------------------------------------------------
1543 XubString HeaderBar::GetItemText( USHORT nItemId ) const
1545 USHORT nPos = GetItemPos( nItemId );
1546 if ( nPos != HEADERBAR_ITEM_NOTFOUND )
1547 return mpItemList->GetObject( nPos )->maText;
1548 else
1549 return String();
1552 // -----------------------------------------------------------------------
1554 void HeaderBar::SetHelpText( USHORT nItemId, const XubString& rText )
1556 USHORT nPos = GetItemPos( nItemId );
1557 if ( nPos != HEADERBAR_ITEM_NOTFOUND )
1558 mpItemList->GetObject( nPos )->maHelpText = rText;
1561 // -----------------------------------------------------------------------
1563 XubString HeaderBar::GetHelpText( USHORT nItemId ) const
1565 USHORT nPos = GetItemPos( nItemId );
1566 if ( nPos != HEADERBAR_ITEM_NOTFOUND )
1568 ImplHeadItem* pItem = mpItemList->GetObject( nPos );
1569 if ( !pItem->maHelpText.Len() && pItem->mnHelpId )
1571 Help* pHelp = Application::GetHelp();
1572 if ( pHelp )
1573 pItem->maHelpText = pHelp->GetHelpText( pItem->mnHelpId, this );
1576 return pItem->maHelpText;
1578 else
1579 return XubString();
1582 // -----------------------------------------------------------------------
1584 void HeaderBar::SetHelpId( USHORT nItemId, ULONG nHelpId )
1586 USHORT nPos = GetItemPos( nItemId );
1587 if ( nPos != HEADERBAR_ITEM_NOTFOUND )
1588 mpItemList->GetObject( nPos )->mnHelpId = nHelpId;
1591 // -----------------------------------------------------------------------
1593 ULONG HeaderBar::GetHelpId( USHORT nItemId ) const
1595 USHORT nPos = GetItemPos( nItemId );
1596 if ( nPos != HEADERBAR_ITEM_NOTFOUND )
1597 return mpItemList->GetObject( nPos )->mnHelpId;
1598 else
1599 return 0;
1602 // -----------------------------------------------------------------------
1604 Size HeaderBar::CalcWindowSizePixel() const
1606 long nMaxImageSize = 0;
1607 Size aSize( 0, GetTextHeight() );
1609 ImplHeadItem* pItem = mpItemList->First();
1610 while ( pItem )
1612 // Image-Groessen beruecksichtigen
1613 long nImageHeight = pItem->maImage.GetSizePixel().Height();
1614 if ( !(pItem->mnBits & (HIB_LEFTIMAGE | HIB_RIGHTIMAGE)) && pItem->maText.Len() )
1615 nImageHeight += aSize.Height();
1616 if ( nImageHeight > nMaxImageSize )
1617 nMaxImageSize = nImageHeight;
1619 // Breite aufaddieren
1620 aSize.Width() += pItem->mnSize;
1622 pItem = mpItemList->Next();
1625 if ( nMaxImageSize > aSize.Height() )
1626 aSize.Height() = nMaxImageSize;
1628 // Border aufaddieren
1629 if ( mbButtonStyle )
1630 aSize.Height() += 4;
1631 else
1632 aSize.Height() += 2;
1633 aSize.Height() += mnBorderOff1+mnBorderOff2;
1635 return aSize;
1638 ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > HeaderBar::CreateAccessible()
1640 if ( !mxAccessible.is() )
1642 if ( maCreateAccessibleHdl.IsSet() )
1643 maCreateAccessibleHdl.Call( this );
1645 if ( !mxAccessible.is() )
1646 mxAccessible = Window::CreateAccessible();
1649 return mxAccessible;
1652 void HeaderBar::SetAccessible( ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > _xAccessible )
1654 mxAccessible = _xAccessible;