update credits
[LibreOffice.git] / svtools / source / control / headbar.cxx
blob0cf073032f564f2ca206b36ff6dad870c85c2a77
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <svtools/headbar.hxx>
21 #include <tools/debug.hxx>
23 #include <vcl/svapp.hxx>
24 #include <vcl/help.hxx>
25 #include <vcl/image.hxx>
26 #include <vcl/salnativewidgets.hxx>
27 #include <com/sun/star/accessibility/XAccessible.hpp>
29 // =======================================================================
31 class ImplHeadItem
33 public:
34 sal_uInt16 mnId;
35 HeaderBarItemBits mnBits;
36 long mnSize;
37 OString maHelpId;
38 Image maImage;
39 XubString maOutText;
40 XubString maText;
41 XubString maHelpText;
44 // =======================================================================
46 #define HEAD_ARROWSIZE1 4
47 #define HEAD_ARROWSIZE2 7
49 #define HEADERBAR_TEXTOFF 2
50 #define HEADERBAR_ARROWOFF 5
51 #define HEADERBAR_SPLITOFF 3
53 #define HEADERBAR_DRAGOUTOFF 15
55 #define HEAD_HITTEST_ITEM ((sal_uInt16)0x0001)
56 #define HEAD_HITTEST_DIVIDER ((sal_uInt16)0x0002)
58 // =======================================================================
60 void HeaderBar::ImplInit( WinBits nWinStyle )
62 mpItemList = new ImplHeadItemList;
63 mnBorderOff1 = 0;
64 mnBorderOff2 = 0;
65 mnOffset = 0;
66 mnDX = 0;
67 mnDY = 0;
68 mnDragSize = 0;
69 mnStartPos = 0;
70 mnDragPos = 0;
71 mnMouseOff = 0;
72 mnCurItemId = 0;
73 mnItemDragPos = HEADERBAR_ITEM_NOTFOUND;
74 mbDrag = sal_False;
75 mbItemDrag = sal_False;
76 mbOutDrag = sal_False;
77 mbItemMode = sal_False;
79 // StyleBits auswerten
80 if ( nWinStyle & WB_DRAG )
81 mbDragable = sal_True;
82 else
83 mbDragable = sal_False;
84 if ( nWinStyle & WB_BUTTONSTYLE )
85 mbButtonStyle = sal_True;
86 else
87 mbButtonStyle = sal_False;
88 if ( nWinStyle & WB_BORDER )
90 mnBorderOff1 = 1;
91 mnBorderOff2 = 1;
93 else
95 if ( nWinStyle & WB_BOTTOMBORDER )
96 mnBorderOff2 = 1;
99 ImplInitSettings( sal_True, sal_True, sal_True );
102 // -----------------------------------------------------------------------
104 HeaderBar::HeaderBar( Window* pParent, WinBits nWinStyle ) :
105 Window( pParent, nWinStyle & WB_3DLOOK )
107 ImplInit( nWinStyle );
108 SetSizePixel( CalcWindowSizePixel() );
111 // -----------------------------------------------------------------------
113 HeaderBar::HeaderBar( Window* pParent, const ResId& rResId ) :
114 Window( pParent, rResId )
116 ImplInit( rResId.GetWinBits() );
119 // -----------------------------------------------------------------------
121 HeaderBar::~HeaderBar()
123 // Alle Items loeschen
124 for ( size_t i = 0, n = mpItemList->size(); i < n; ++i ) {
125 delete (*mpItemList)[ i ];
127 mpItemList->clear();
128 delete mpItemList;
131 // -----------------------------------------------------------------------
133 void HeaderBar::ImplInitSettings( sal_Bool bFont,
134 sal_Bool bForeground, sal_Bool bBackground )
136 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
138 if ( bFont )
140 Font aFont;
141 aFont = rStyleSettings.GetToolFont();
142 if ( IsControlFont() )
143 aFont.Merge( GetControlFont() );
144 SetZoomedPointFont( aFont );
147 if ( bForeground || bFont )
149 Color aColor;
150 if ( IsControlForeground() )
151 aColor = GetControlForeground();
152 else
153 aColor = rStyleSettings.GetButtonTextColor();
154 SetTextColor( aColor );
155 SetTextFillColor();
158 if ( bBackground )
160 Color aColor;
161 if ( IsControlBackground() )
162 aColor = GetControlBackground();
163 else
164 aColor = rStyleSettings.GetFaceColor();
165 SetBackground( aColor );
169 // -----------------------------------------------------------------------
171 long HeaderBar::ImplGetItemPos( sal_uInt16 nPos ) const
173 long nX = -mnOffset;
174 for ( size_t i = 0; i < nPos; i++ )
175 nX += (*mpItemList)[ i ]->mnSize;
176 return nX;
179 // -----------------------------------------------------------------------
181 Rectangle HeaderBar::ImplGetItemRect( sal_uInt16 nPos ) const
183 Rectangle aRect( ImplGetItemPos( nPos ), 0, 0, mnDY-1 );
184 aRect.Right() = aRect.Left() + (*mpItemList)[ nPos ]->mnSize - 1;
185 // Gegen Ueberlauf auf einigen Systemen testen
186 if ( aRect.Right() > 16000 )
187 aRect.Right() = 16000;
188 return aRect;
191 // -----------------------------------------------------------------------
193 sal_uInt16 HeaderBar::ImplHitTest( const Point& rPos,
194 long& nMouseOff, sal_uInt16& nPos ) const
196 ImplHeadItem* pItem;
197 size_t nCount = (sal_uInt16)mpItemList->size();
198 sal_Bool bLastFixed = sal_True;
199 long nX = -mnOffset;
201 for ( size_t i = 0; i < nCount; i++ )
203 pItem = (*mpItemList)[ i ];
205 if ( rPos.X() < (nX+pItem->mnSize) )
207 sal_uInt16 nMode;
209 if ( !bLastFixed && (rPos.X() < (nX+HEADERBAR_SPLITOFF)) )
211 nMode = HEAD_HITTEST_DIVIDER;
212 nPos = i-1;
213 nMouseOff = rPos.X()-nX+1;
215 else
217 nPos = i;
219 if ( !(pItem->mnBits & HIB_FIXED) && (rPos.X() >= (nX+pItem->mnSize-HEADERBAR_SPLITOFF)) )
221 nMode = HEAD_HITTEST_DIVIDER;
222 nMouseOff = rPos.X()-(nX+pItem->mnSize);
224 else
226 nMode = HEAD_HITTEST_ITEM;
227 nMouseOff = rPos.X()-nX;
231 return nMode;
234 if ( pItem->mnBits & HIB_FIXED )
235 bLastFixed = sal_True;
236 else
237 bLastFixed = sal_False;
239 nX += pItem->mnSize;
242 if ( !bLastFixed )
244 pItem = (*mpItemList)[ nCount-1 ];
245 if ( (pItem->mnSize < 4) && (rPos.X() < (nX+HEADERBAR_SPLITOFF)) )
247 nPos = nCount-1;
248 nMouseOff = rPos.X()-nX+1;
249 return HEAD_HITTEST_DIVIDER;
253 return 0;
256 // -----------------------------------------------------------------------
258 void HeaderBar::ImplInvertDrag( sal_uInt16 nStartPos, sal_uInt16 nEndPos )
260 Rectangle aRect1 = ImplGetItemRect( nStartPos );
261 Rectangle aRect2 = ImplGetItemRect( nEndPos );
262 Point aStartPos = aRect1.Center();
263 Point aEndPos = aStartPos;
264 Rectangle aStartRect( aStartPos.X()-2, aStartPos.Y()-2,
265 aStartPos.X()+2, aStartPos.Y()+2 );
267 if ( nEndPos > nStartPos )
269 aStartPos.X() += 3;
270 aEndPos.X() = aRect2.Right()-6;
272 else
274 aStartPos.X() -= 3;
275 aEndPos.X() = aRect2.Left()+6;
278 SetRasterOp( ROP_INVERT );
279 DrawRect( aStartRect );
280 DrawLine( aStartPos, aEndPos );
281 if ( nEndPos > nStartPos )
283 DrawLine( Point( aEndPos.X()+1, aEndPos.Y()-3 ),
284 Point( aEndPos.X()+1, aEndPos.Y()+3 ) );
285 DrawLine( Point( aEndPos.X()+2, aEndPos.Y()-2 ),
286 Point( aEndPos.X()+2, aEndPos.Y()+2 ) );
287 DrawLine( Point( aEndPos.X()+3, aEndPos.Y()-1 ),
288 Point( aEndPos.X()+3, aEndPos.Y()+1 ) );
289 DrawPixel( Point( aEndPos.X()+4, aEndPos.Y() ) );
291 else
293 DrawLine( Point( aEndPos.X()-1, aEndPos.Y()-3 ),
294 Point( aEndPos.X()-1, aEndPos.Y()+3 ) );
295 DrawLine( Point( aEndPos.X()-2, aEndPos.Y()-2 ),
296 Point( aEndPos.X()-2, aEndPos.Y()+2 ) );
297 DrawLine( Point( aEndPos.X()-3, aEndPos.Y()-1 ),
298 Point( aEndPos.X()-3, aEndPos.Y()+1 ) );
299 DrawPixel( Point( aEndPos.X()-4, aEndPos.Y() ) );
301 SetRasterOp( ROP_OVERPAINT );
304 // -----------------------------------------------------------------------
306 void HeaderBar::ImplDrawItem( OutputDevice* pDev,
307 sal_uInt16 nPos, sal_Bool bHigh, sal_Bool bDrag,
308 const Rectangle& rItemRect,
309 const Rectangle* pRect,
310 sal_uLong )
312 Window *const pWin = (pDev->GetOutDevType()==OUTDEV_WINDOW) ? (Window*) pDev : NULL;
313 ImplControlValue aControlValue(0);
314 Rectangle aCtrlRegion;
315 ControlState nState(0);
317 Rectangle aRect = rItemRect;
319 // Wenn kein Platz, dann brauchen wir auch nichts ausgeben
320 if ( aRect.GetWidth() <= 1 )
321 return;
323 // Feststellen, ob Rectangle ueberhaupt sichtbar
324 if ( pRect )
326 if ( aRect.Right() < pRect->Left() )
327 return;
328 else if ( aRect.Left() > pRect->Right() )
329 return;
331 else
333 if ( aRect.Right() < 0 )
334 return;
335 else if ( aRect.Left() > mnDX )
336 return;
339 ImplHeadItem* pItem = (*mpItemList)[ nPos ];
340 HeaderBarItemBits nBits = pItem->mnBits;
341 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
343 if( pWin && pWin->IsNativeControlSupported(CTRL_WINDOW_BACKGROUND, PART_ENTIRE_CONTROL) )
345 aCtrlRegion=aRect;
346 pWin->DrawNativeControl( CTRL_WINDOW_BACKGROUND, PART_ENTIRE_CONTROL,
347 aCtrlRegion, nState, aControlValue,
348 OUString() );
351 else
353 // Border muss nicht gemalt werden
354 aRect.Top() += mnBorderOff1;
355 aRect.Bottom() -= mnBorderOff2;
357 // Hintergrund loeschen
358 if ( !pRect || bDrag )
360 if ( bDrag )
362 pDev->SetLineColor();
363 pDev->SetFillColor( rStyleSettings.GetCheckedColor() );
364 pDev->DrawRect( aRect );
366 else
367 pDev->DrawWallpaper( aRect, GetBackground() );
371 Color aSelectionTextColor( COL_TRANSPARENT );
373 if( pWin && pWin->IsNativeControlSupported(CTRL_LISTHEADER, PART_BUTTON) )
375 aCtrlRegion=aRect;
376 aControlValue.setTristateVal(BUTTONVALUE_ON);
377 nState|=CTRL_STATE_ENABLED;
378 if(bHigh)
379 nState|=CTRL_STATE_PRESSED;
380 pWin->DrawNativeControl( CTRL_LISTHEADER, PART_BUTTON,
381 aCtrlRegion, nState, aControlValue,
382 OUString() );
384 else
386 // Trennlinie malen
387 pDev->SetLineColor( rStyleSettings.GetDarkShadowColor() );
388 pDev->DrawLine( Point( aRect.Right(), aRect.Top() ),
389 Point( aRect.Right(), aRect.Bottom() ) );
391 // ButtonStyle malen
392 // avoid 3D borders
393 if( bHigh )
394 DrawSelectionBackground( aRect, 1, sal_True, sal_False, sal_False, &aSelectionTextColor );
395 else if ( !mbButtonStyle || (nBits & HIB_FLAT) )
396 DrawSelectionBackground( aRect, 0, sal_True, sal_False, sal_False, &aSelectionTextColor );
399 // Wenn kein Platz, dann brauchen wir auch nichts ausgeben
400 if ( aRect.GetWidth() < 1 )
401 return;
403 // Positionen und Groessen berechnen und Inhalt ausgeben
404 pItem->maOutText = pItem->maText;
405 Size aImageSize = pItem->maImage.GetSizePixel();
406 Size aTxtSize( pDev->GetTextWidth( pItem->maOutText ), 0 );
407 if ( pItem->maOutText.Len() )
408 aTxtSize.Height() = pDev->GetTextHeight();
409 long nArrowWidth = 0;
410 if ( nBits & (HIB_UPARROW | HIB_DOWNARROW) )
411 nArrowWidth = HEAD_ARROWSIZE2+HEADERBAR_ARROWOFF;
413 // Wenn kein Platz fuer Image, dann nicht ausgeben
414 long nTestHeight = aImageSize.Height();
415 if ( !(nBits & (HIB_LEFTIMAGE | HIB_RIGHTIMAGE)) )
416 nTestHeight += aTxtSize.Height();
417 if ( (aImageSize.Width() > aRect.GetWidth()) || (nTestHeight > aRect.GetHeight()) )
419 aImageSize.Width() = 0;
420 aImageSize.Height() = 0;
423 // Text auf entsprechende Laenge kuerzen
424 sal_Bool bLeftText = sal_False;
425 long nMaxTxtWidth = aRect.GetWidth()-(HEADERBAR_TEXTOFF*2)-nArrowWidth;
426 if ( nBits & (HIB_LEFTIMAGE | HIB_RIGHTIMAGE) )
427 nMaxTxtWidth -= aImageSize.Width();
428 long nTxtWidth = aTxtSize.Width();
429 if ( nTxtWidth > nMaxTxtWidth )
431 bLeftText = sal_True;
432 // 3 == Len of "..."
433 pItem->maOutText.AppendAscii( "..." );
436 pItem->maOutText.Erase( pItem->maOutText.Len()-3-1, 1 );
437 nTxtWidth = pDev->GetTextWidth( pItem->maOutText );
439 while ( (nTxtWidth > nMaxTxtWidth) && (pItem->maOutText.Len() > 3) );
440 if ( pItem->maOutText.Len() == 3 )
442 nTxtWidth = 0;
443 pItem->maOutText.Erase();
447 // Text/Imageposition berechnen
448 long nTxtPos;
449 if ( !bLeftText && (nBits & HIB_RIGHT) )
451 nTxtPos = aRect.Right()-nTxtWidth-HEADERBAR_TEXTOFF;
452 if ( nBits & HIB_RIGHTIMAGE )
453 nTxtPos -= aImageSize.Width();
455 else if ( !bLeftText && (nBits & HIB_CENTER) )
457 long nTempWidth = nTxtWidth;
458 if ( nBits & (HIB_LEFTIMAGE | HIB_RIGHTIMAGE) )
459 nTempWidth += aImageSize.Width();
460 nTxtPos = aRect.Left()+(aRect.GetWidth()-nTempWidth)/2;
461 if ( nBits & HIB_LEFTIMAGE )
462 nTxtPos += aImageSize.Width();
463 if ( nArrowWidth )
465 if ( nTxtPos+nTxtWidth+nArrowWidth >= aRect.Right() )
467 nTxtPos = aRect.Left()+HEADERBAR_TEXTOFF;
468 if ( nBits & HIB_LEFTIMAGE )
469 nTxtPos += aImageSize.Width();
473 else
475 nTxtPos = aRect.Left()+HEADERBAR_TEXTOFF;
476 if ( nBits & HIB_LEFTIMAGE )
477 nTxtPos += aImageSize.Width();
478 if ( nBits & HIB_RIGHT )
479 nTxtPos += nArrowWidth;
482 // TextPosition berechnen
483 long nTxtPosY = 0;
484 if ( pItem->maOutText.Len() || (nArrowWidth && aTxtSize.Height()) )
486 if ( nBits & HIB_TOP )
488 nTxtPosY = aRect.Top();
489 if ( !(nBits & (HIB_LEFTIMAGE | HIB_RIGHTIMAGE)) )
490 nTxtPosY += aImageSize.Height();
492 else if ( nBits & HIB_BOTTOM )
493 nTxtPosY = aRect.Bottom()-aTxtSize.Height();
494 else
496 long nTempHeight = aTxtSize.Height();
497 if ( !(nBits & (HIB_LEFTIMAGE | HIB_RIGHTIMAGE)) )
498 nTempHeight += aImageSize.Height();
499 nTxtPosY = aRect.Top()+((aRect.GetHeight()-nTempHeight)/2);
500 if ( !(nBits & (HIB_LEFTIMAGE | HIB_RIGHTIMAGE)) )
501 nTxtPosY += aImageSize.Height();
505 // Text ausgebeben
506 if ( pItem->maOutText.Len() )
508 if( aSelectionTextColor != Color( COL_TRANSPARENT ) )
510 pDev->Push( PUSH_TEXTCOLOR );
511 pDev->SetTextColor( aSelectionTextColor );
513 if ( IsEnabled() )
514 pDev->DrawText( Point( nTxtPos, nTxtPosY ), pItem->maOutText );
515 else
516 pDev->DrawCtrlText( Point( nTxtPos, nTxtPosY ), pItem->maOutText, 0, STRING_LEN, TEXT_DRAW_DISABLE );
517 if( aSelectionTextColor != Color( COL_TRANSPARENT ) )
518 pDev->Pop();
521 // Wenn Image vorhanden, Position berechnen und ausgeben
522 long nImagePosY = 0;
523 if ( aImageSize.Width() && aImageSize.Height() )
525 long nImagePos = nTxtPos;
526 if ( nBits & HIB_LEFTIMAGE )
528 nImagePos -= aImageSize.Width();
529 if ( nBits & HIB_RIGHT )
530 nImagePos -= nArrowWidth;
532 else if ( nBits & HIB_RIGHTIMAGE )
534 nImagePos += nTxtWidth;
535 if ( !(nBits & HIB_RIGHT) )
536 nImagePos += nArrowWidth;
538 else
540 if ( nBits & HIB_RIGHT )
541 nImagePos = aRect.Right()-aImageSize.Width();
542 else if ( nBits & HIB_CENTER )
543 nImagePos = aRect.Left()+(aRect.GetWidth()-aImageSize.Width())/2;
544 else
545 nImagePos = aRect.Left()+HEADERBAR_TEXTOFF;
548 if ( nBits & HIB_TOP )
549 nImagePosY = aRect.Top();
550 else if ( nBits & HIB_BOTTOM )
552 nImagePosY = aRect.Bottom()-aImageSize.Height();
553 if ( !(nBits & (HIB_LEFTIMAGE | HIB_RIGHTIMAGE)) )
554 nImagePosY -= aTxtSize.Height();
556 else
558 long nTempHeight = aImageSize.Height();
559 if ( !(nBits & (HIB_LEFTIMAGE | HIB_RIGHTIMAGE)) )
560 nTempHeight += aTxtSize.Height();
561 nImagePosY = aRect.Top()+((aRect.GetHeight()-nTempHeight)/2);
563 if ( nImagePos+aImageSize.Width() <= aRect.Right() )
565 sal_uInt16 nStyle = 0;
566 if ( !IsEnabled() )
567 nStyle |= IMAGE_DRAW_DISABLE;
568 pDev->DrawImage( Point( nImagePos, nImagePosY ), pItem->maImage, nStyle );
572 if ( nBits & (HIB_UPARROW | HIB_DOWNARROW) )
574 long nArrowX = nTxtPos;
575 if ( nBits & HIB_RIGHT )
576 nArrowX -= nArrowWidth;
577 else
578 nArrowX += nTxtWidth+HEADERBAR_ARROWOFF;
579 if ( !(nBits & (HIB_LEFTIMAGE | HIB_RIGHTIMAGE)) && !pItem->maText.Len() )
581 if ( nBits & HIB_RIGHT )
582 nArrowX -= aImageSize.Width();
583 else
584 nArrowX += aImageSize.Width();
587 // Feststellen, ob Platz genug ist, das Item zu malen
588 sal_Bool bDraw = sal_True;
589 if ( nArrowX < aRect.Left()+HEADERBAR_TEXTOFF )
590 bDraw = sal_False;
591 else if ( nArrowX+HEAD_ARROWSIZE2 > aRect.Right() )
592 bDraw = sal_False;
594 if ( bDraw )
596 if( pWin && pWin->IsNativeControlSupported(CTRL_LISTHEADER, PART_ARROW) )
598 aCtrlRegion=Rectangle(Point(nArrowX,aRect.Top()),Size(nArrowWidth,aRect.GetHeight()));
599 // control value passes 1 if arrow points down, 0 otherwise
600 aControlValue.setNumericVal((nBits&HIB_DOWNARROW)?1:0);
601 nState|=CTRL_STATE_ENABLED;
602 if(bHigh)
603 nState|=CTRL_STATE_PRESSED;
604 pWin->DrawNativeControl( CTRL_LISTHEADER, PART_ARROW,
605 aCtrlRegion, nState, aControlValue,
606 OUString() );
608 else
610 long nArrowY;
611 if ( aTxtSize.Height() )
612 nArrowY = nTxtPosY+(aTxtSize.Height()/2);
613 else if ( aImageSize.Width() && aImageSize.Height() )
614 nArrowY = nImagePosY+(aImageSize.Height()/2);
615 else
617 if ( nBits & HIB_TOP )
618 nArrowY = aRect.Top()+1;
619 else if ( nBits & HIB_BOTTOM )
620 nArrowY = aRect.Bottom()-HEAD_ARROWSIZE2-1;
621 else
622 nArrowY = aRect.Top()+((aRect.GetHeight()-HEAD_ARROWSIZE2)/2);
624 nArrowY -= HEAD_ARROWSIZE1-1;
625 if ( nBits & HIB_DOWNARROW )
627 pDev->SetLineColor( rStyleSettings.GetLightColor() );
628 pDev->DrawLine( Point( nArrowX, nArrowY ),
629 Point( nArrowX+HEAD_ARROWSIZE2, nArrowY ) );
630 pDev->DrawLine( Point( nArrowX, nArrowY ),
631 Point( nArrowX+HEAD_ARROWSIZE1, nArrowY+HEAD_ARROWSIZE2 ) );
632 pDev->SetLineColor( rStyleSettings.GetShadowColor() );
633 pDev->DrawLine( Point( nArrowX+HEAD_ARROWSIZE1, nArrowY+HEAD_ARROWSIZE2 ),
634 Point( nArrowX+HEAD_ARROWSIZE2, nArrowY ) );
636 else
638 pDev->SetLineColor( rStyleSettings.GetLightColor() );
639 pDev->DrawLine( Point( nArrowX, nArrowY+HEAD_ARROWSIZE2 ),
640 Point( nArrowX+HEAD_ARROWSIZE1, nArrowY ) );
641 pDev->SetLineColor( rStyleSettings.GetShadowColor() );
642 pDev->DrawLine( Point( nArrowX, nArrowY+HEAD_ARROWSIZE2 ),
643 Point( nArrowX+HEAD_ARROWSIZE2, nArrowY+HEAD_ARROWSIZE2 ) );
644 pDev->DrawLine( Point( nArrowX+HEAD_ARROWSIZE2, nArrowY+HEAD_ARROWSIZE2 ),
645 Point( nArrowX+HEAD_ARROWSIZE1, nArrowY ) );
651 // Gegebenenfalls auch UserDraw aufrufen
652 if ( nBits & HIB_USERDRAW )
654 Region aRegion( aRect );
655 if ( pRect )
656 aRegion.Intersect( *pRect );
657 pDev->SetClipRegion( aRegion );
658 UserDrawEvent aODEvt( pDev, aRect, pItem->mnId );
659 UserDraw( aODEvt );
660 pDev->SetClipRegion();
664 // -----------------------------------------------------------------------
666 void HeaderBar::ImplDrawItem( sal_uInt16 nPos, sal_Bool bHigh, sal_Bool bDrag,
667 const Rectangle* pRect )
669 Rectangle aRect = ImplGetItemRect( nPos );
670 ImplDrawItem( this, nPos, bHigh, bDrag, aRect, pRect, 0 );
673 // -----------------------------------------------------------------------
675 void HeaderBar::ImplUpdate( sal_uInt16 nPos, sal_Bool bEnd, sal_Bool bDirect )
677 if ( IsVisible() && IsUpdateMode() )
679 if ( !bDirect )
681 Rectangle aRect;
682 size_t nItemCount = mpItemList->size();
683 if ( nPos < nItemCount )
684 aRect = ImplGetItemRect( nPos );
685 else
687 aRect.Bottom() = mnDY-1;
688 if ( nItemCount )
689 aRect.Left() = ImplGetItemRect( nItemCount-1 ).Right();
691 if ( bEnd )
692 aRect.Right() = mnDX-1;
693 aRect.Top() += mnBorderOff1;
694 aRect.Bottom() -= mnBorderOff2;
695 Invalidate( aRect );
697 else
699 for ( size_t i = nPos; i < mpItemList->size(); i++ )
700 ImplDrawItem( i );
701 if ( bEnd )
703 Rectangle aRect = ImplGetItemRect( (sal_uInt16)mpItemList->size() );
704 aRect.Left() = aRect.Right();
705 aRect.Right() = mnDX-1;
706 if ( aRect.Left() < aRect.Right() )
708 aRect.Top() += mnBorderOff1;
709 aRect.Bottom() -= mnBorderOff2;
710 Erase( aRect );
717 // -----------------------------------------------------------------------
719 void HeaderBar::ImplStartDrag( const Point& rMousePos, sal_Bool bCommand )
721 sal_uInt16 nPos;
722 sal_uInt16 nHitTest = ImplHitTest( rMousePos, mnMouseOff, nPos );
723 if ( nHitTest )
725 mbDrag = sal_False;
726 ImplHeadItem* pItem = (*mpItemList)[ nPos ];
727 if ( nHitTest & HEAD_HITTEST_DIVIDER )
728 mbDrag = sal_True;
729 else
731 if ( ((pItem->mnBits & HIB_CLICKABLE) && !(pItem->mnBits & HIB_FLAT)) ||
732 (mbDragable && !(pItem->mnBits & HIB_FIXEDPOS)) )
734 mbItemMode = sal_True;
735 mbDrag = sal_True;
736 if ( bCommand )
738 if ( mbDragable )
739 mbItemDrag = sal_True;
740 else
742 mbItemMode = sal_False;
743 mbDrag = sal_False;
747 else
749 if ( !bCommand )
751 mnCurItemId = pItem->mnId;
752 Select();
753 mnCurItemId = 0;
758 if ( mbDrag )
760 mbOutDrag = sal_False;
761 mnCurItemId = pItem->mnId;
762 mnItemDragPos = nPos;
763 StartTracking();
764 mnStartPos = rMousePos.X()-mnMouseOff;
765 mnDragPos = mnStartPos;
766 StartDrag();
767 if ( mbItemMode )
768 ImplDrawItem( nPos, sal_True, mbItemDrag );
769 else
771 Rectangle aSizeRect( mnDragPos, 0, mnDragPos, mnDragSize+mnDY );
772 ShowTracking( aSizeRect, SHOWTRACK_SPLIT );
775 else
776 mnMouseOff = 0;
780 // -----------------------------------------------------------------------
782 void HeaderBar::ImplDrag( const Point& rMousePos )
784 sal_Bool bNewOutDrag;
785 sal_uInt16 nPos = GetItemPos( mnCurItemId );
787 mnDragPos = rMousePos.X()-mnMouseOff;
788 if ( mbItemMode )
790 Rectangle aItemRect = ImplGetItemRect( nPos );
791 if ( aItemRect.IsInside( rMousePos ) )
792 bNewOutDrag = sal_False;
793 else
794 bNewOutDrag = sal_True;
796 // Evt. ItemDrag anschalten
797 if ( bNewOutDrag && mbDragable && !mbItemDrag &&
798 !((*mpItemList)[ nPos ]->mnBits & HIB_FIXEDPOS) )
800 if ( (rMousePos.Y() >= aItemRect.Top()) && (rMousePos.Y() <= aItemRect.Bottom()) )
802 mbItemDrag = sal_True;
803 ImplDrawItem( nPos, sal_True, mbItemDrag );
807 sal_uInt16 nOldItemDragPos = mnItemDragPos;
808 if ( mbItemDrag )
810 if ( (rMousePos.Y() < -HEADERBAR_DRAGOUTOFF) || (rMousePos.Y() > mnDY+HEADERBAR_DRAGOUTOFF) )
811 bNewOutDrag = sal_True;
812 else
813 bNewOutDrag = sal_False;
815 if ( bNewOutDrag )
816 mnItemDragPos = HEADERBAR_ITEM_NOTFOUND;
817 else
819 sal_uInt16 nTempId = GetItemId( Point( rMousePos.X(), 2 ) );
820 if ( nTempId )
821 mnItemDragPos = GetItemPos( nTempId );
822 else
824 if ( rMousePos.X() <= 0 )
825 mnItemDragPos = 0;
826 else
827 mnItemDragPos = GetItemCount()-1;
830 // Nicht verschiebbare Items aussparen
831 if ( mnItemDragPos < nPos )
833 while ( ((*mpItemList)[ mnItemDragPos ]->mnBits & HIB_FIXEDPOS) &&
834 (mnItemDragPos < nPos) )
835 mnItemDragPos++;
837 else if ( mnItemDragPos > nPos )
839 while ( ((*mpItemList)[ mnItemDragPos ]->mnBits & HIB_FIXEDPOS) &&
840 (mnItemDragPos > nPos) )
841 mnItemDragPos--;
845 if ( (mnItemDragPos != nOldItemDragPos) &&
846 (nOldItemDragPos != nPos) &&
847 (nOldItemDragPos != HEADERBAR_ITEM_NOTFOUND) )
849 ImplInvertDrag( nPos, nOldItemDragPos );
850 ImplDrawItem( nOldItemDragPos );
854 if ( bNewOutDrag != mbOutDrag )
855 ImplDrawItem( nPos, !bNewOutDrag, mbItemDrag );
857 if ( mbItemDrag )
859 if ( (mnItemDragPos != nOldItemDragPos) &&
860 (mnItemDragPos != nPos) &&
861 (mnItemDragPos != HEADERBAR_ITEM_NOTFOUND) )
863 ImplDrawItem( mnItemDragPos, sal_False, sal_True );
864 ImplInvertDrag( nPos, mnItemDragPos );
868 mbOutDrag = bNewOutDrag;
870 else
872 Rectangle aItemRect = ImplGetItemRect( nPos );
873 if ( mnDragPos < aItemRect.Left() )
874 mnDragPos = aItemRect.Left();
875 if ( (mnDragPos < 0) || (mnDragPos > mnDX-1) )
876 HideTracking();
877 else
879 Rectangle aSizeRect( mnDragPos, 0, mnDragPos, mnDragSize+mnDY );
880 ShowTracking( aSizeRect, SHOWTRACK_SPLIT );
884 Drag();
887 // -----------------------------------------------------------------------
889 void HeaderBar::ImplEndDrag( sal_Bool bCancel )
891 HideTracking();
893 if ( bCancel || mbOutDrag )
895 if ( mbItemMode && (!mbOutDrag || mbItemDrag) )
897 sal_uInt16 nPos = GetItemPos( mnCurItemId );
898 ImplDrawItem( nPos );
901 mnCurItemId = 0;
903 else
905 sal_uInt16 nPos = GetItemPos( mnCurItemId );
906 if ( mbItemMode )
908 if ( mbItemDrag )
910 Pointer aPointer( POINTER_ARROW );
911 SetPointer( aPointer );
912 if ( (mnItemDragPos != nPos) &&
913 (mnItemDragPos != HEADERBAR_ITEM_NOTFOUND) )
915 ImplInvertDrag( nPos, mnItemDragPos );
916 MoveItem( mnCurItemId, mnItemDragPos );
918 else
919 ImplDrawItem( nPos );
921 else
923 Select();
924 ImplUpdate( nPos );
927 else
929 long nDelta = mnDragPos - mnStartPos;
930 if ( nDelta )
932 ImplHeadItem* pItem = (*mpItemList)[ nPos ];
933 pItem->mnSize += nDelta;
934 ImplUpdate( nPos, sal_True );
939 mbDrag = sal_False;
940 EndDrag();
941 mnCurItemId = 0;
942 mnItemDragPos = HEADERBAR_ITEM_NOTFOUND;
943 mbOutDrag = sal_False;
944 mbItemMode = sal_False;
945 mbItemDrag = sal_False;
948 // -----------------------------------------------------------------------
950 void HeaderBar::MouseButtonDown( const MouseEvent& rMEvt )
952 if ( rMEvt.IsLeft() )
954 if ( rMEvt.GetClicks() == 2 )
956 long nTemp;
957 sal_uInt16 nPos;
958 sal_uInt16 nHitTest = ImplHitTest( rMEvt.GetPosPixel(), nTemp, nPos );
959 if ( nHitTest )
961 ImplHeadItem* pItem = (*mpItemList)[ nPos ];
962 if ( nHitTest & HEAD_HITTEST_DIVIDER )
963 mbItemMode = sal_False;
964 else
965 mbItemMode = sal_True;
966 mnCurItemId = pItem->mnId;
967 DoubleClick();
968 mbItemMode = sal_False;
969 mnCurItemId = 0;
972 else
973 ImplStartDrag( rMEvt.GetPosPixel(), sal_False );
977 // -----------------------------------------------------------------------
979 void HeaderBar::MouseMove( const MouseEvent& rMEvt )
981 long nTemp1;
982 sal_uInt16 nTemp2;
983 PointerStyle eStyle = POINTER_ARROW;
984 sal_uInt16 nHitTest = ImplHitTest( rMEvt.GetPosPixel(), nTemp1, nTemp2 );
986 if ( nHitTest & HEAD_HITTEST_DIVIDER )
987 eStyle = POINTER_HSIZEBAR;
988 Pointer aPtr( eStyle );
989 SetPointer( aPtr );
992 // -----------------------------------------------------------------------
994 void HeaderBar::Tracking( const TrackingEvent& rTEvt )
996 Point aMousePos = rTEvt.GetMouseEvent().GetPosPixel();
998 if ( rTEvt.IsTrackingEnded() )
999 ImplEndDrag( rTEvt.IsTrackingCanceled() );
1000 else
1001 ImplDrag( aMousePos );
1004 // -----------------------------------------------------------------------
1006 void HeaderBar::Paint( const Rectangle& rRect )
1008 if ( mnBorderOff1 || mnBorderOff2 )
1010 SetLineColor( GetSettings().GetStyleSettings().GetDarkShadowColor() );
1011 if ( mnBorderOff1 )
1012 DrawLine( Point( 0, 0 ), Point( mnDX-1, 0 ) );
1013 if ( mnBorderOff2 )
1014 DrawLine( Point( 0, mnDY-1 ), Point( mnDX-1, mnDY-1 ) );
1015 // #i40393# draw left and right border, if WB_BORDER was set in ImplInit()
1016 if ( mnBorderOff1 && mnBorderOff2 )
1018 DrawLine( Point( 0, 0 ), Point( 0, mnDY-1 ) );
1019 DrawLine( Point( mnDX-1, 0 ), Point( mnDX-1, mnDY-1 ) );
1023 sal_uInt16 nCurItemPos;
1024 if ( mbDrag )
1025 nCurItemPos = GetItemPos( mnCurItemId );
1026 else
1027 nCurItemPos = HEADERBAR_ITEM_NOTFOUND;
1028 sal_uInt16 nItemCount = (sal_uInt16)mpItemList->size();
1029 for ( sal_uInt16 i = 0; i < nItemCount; i++ )
1030 ImplDrawItem( i, (i == nCurItemPos) ? sal_True : sal_False, sal_False, &rRect );
1033 // -----------------------------------------------------------------------
1035 void HeaderBar::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize,
1036 sal_uLong nFlags )
1038 Point aPos = pDev->LogicToPixel( rPos );
1039 Size aSize = pDev->LogicToPixel( rSize );
1040 Rectangle aRect( aPos, aSize );
1041 Font aFont = GetDrawPixelFont( pDev );
1043 pDev->Push();
1044 pDev->SetMapMode();
1045 pDev->SetFont( aFont );
1046 if ( nFlags & WINDOW_DRAW_MONO )
1047 pDev->SetTextColor( Color( COL_BLACK ) );
1048 else
1049 pDev->SetTextColor( GetTextColor() );
1050 pDev->SetTextFillColor();
1052 if ( !(nFlags & WINDOW_DRAW_NOBACKGROUND) )
1054 pDev->DrawWallpaper( aRect, GetBackground() );
1055 if ( mnBorderOff1 || mnBorderOff2 )
1057 pDev->SetLineColor( GetSettings().GetStyleSettings().GetDarkShadowColor() );
1058 if ( mnBorderOff1 )
1059 pDev->DrawLine( aRect.TopLeft(), Point( aRect.Right(), aRect.Top() ) );
1060 if ( mnBorderOff2 )
1061 pDev->DrawLine( Point( aRect.Left(), aRect.Bottom() ), Point( aRect.Right(), aRect.Bottom() ) );
1062 // #i40393# draw left and right border, if WB_BORDER was set in ImplInit()
1063 if ( mnBorderOff1 && mnBorderOff2 )
1065 pDev->DrawLine( aRect.TopLeft(), Point( aRect.Left(), aRect.Bottom() ) );
1066 pDev->DrawLine( Point( aRect.Right(), aRect.Top() ), Point( aRect.Right(), aRect.Bottom() ) );
1071 Rectangle aItemRect( aRect );
1072 size_t nItemCount = mpItemList->size();
1073 for ( size_t i = 0; i < nItemCount; i++ )
1075 aItemRect.Left() = aRect.Left()+ImplGetItemPos( i );
1076 aItemRect.Right() = aItemRect.Left() + (*mpItemList)[ i ]->mnSize - 1;
1077 // Gegen Ueberlauf auf einigen Systemen testen
1078 if ( aItemRect.Right() > 16000 )
1079 aItemRect.Right() = 16000;
1080 Region aRegion( aRect );
1081 pDev->SetClipRegion( aRegion );
1082 ImplDrawItem( pDev, i, sal_False, sal_False, aItemRect, &aRect, nFlags );
1083 pDev->SetClipRegion();
1086 pDev->Pop();
1089 // -----------------------------------------------------------------------
1091 void HeaderBar::Resize()
1093 Size aSize = GetOutputSizePixel();
1094 if ( IsVisible() && (mnDY != aSize.Height()) )
1095 Invalidate();
1096 mnDX = aSize.Width();
1097 mnDY = aSize.Height();
1100 // -----------------------------------------------------------------------
1102 void HeaderBar::Command( const CommandEvent& rCEvt )
1104 if ( rCEvt.IsMouseEvent() && (rCEvt.GetCommand() == COMMAND_STARTDRAG) && !mbDrag )
1106 ImplStartDrag( rCEvt.GetMousePosPixel(), sal_True );
1107 return;
1110 Window::Command( rCEvt );
1113 // -----------------------------------------------------------------------
1115 void HeaderBar::RequestHelp( const HelpEvent& rHEvt )
1117 sal_uInt16 nItemId = GetItemId( ScreenToOutputPixel( rHEvt.GetMousePosPixel() ) );
1118 if ( nItemId )
1120 if ( rHEvt.GetMode() & (HELPMODE_QUICK | HELPMODE_BALLOON) )
1122 Rectangle aItemRect = GetItemRect( nItemId );
1123 Point aPt = OutputToScreenPixel( aItemRect.TopLeft() );
1124 aItemRect.Left() = aPt.X();
1125 aItemRect.Top() = aPt.Y();
1126 aPt = OutputToScreenPixel( aItemRect.BottomRight() );
1127 aItemRect.Right() = aPt.X();
1128 aItemRect.Bottom() = aPt.Y();
1130 XubString aStr = GetHelpText( nItemId );
1131 if ( !aStr.Len() || !(rHEvt.GetMode() & HELPMODE_BALLOON) )
1133 ImplHeadItem* pItem = (*mpItemList)[ GetItemPos( nItemId ) ];
1134 // Wir zeigen die Quick-Hilfe nur an, wenn Text nicht
1135 // vollstaendig sichtbar, ansonsten zeigen wir den Hilfetext
1136 // an, wenn das Item keinen Text besitzt
1137 if ( pItem->maOutText != pItem->maText )
1138 aStr = pItem->maText;
1139 else if ( pItem->maText.Len() )
1140 aStr.Erase();
1143 if ( aStr.Len() )
1145 if ( rHEvt.GetMode() & HELPMODE_BALLOON )
1146 Help::ShowBalloon( this, aItemRect.Center(), aItemRect, aStr );
1147 else
1148 Help::ShowQuickHelp( this, aItemRect, aStr );
1149 return;
1152 else if ( rHEvt.GetMode() & HELPMODE_EXTENDED )
1154 OUString aHelpId( OStringToOUString( GetHelpId( nItemId ), RTL_TEXTENCODING_UTF8 ) );
1155 if ( !aHelpId.isEmpty() )
1157 // Wenn eine Hilfe existiert, dann ausloesen
1158 Help* pHelp = Application::GetHelp();
1159 if ( pHelp )
1160 pHelp->Start( aHelpId, this );
1161 return;
1166 Window::RequestHelp( rHEvt );
1169 // -----------------------------------------------------------------------
1171 void HeaderBar::StateChanged( StateChangedType nType )
1173 Window::StateChanged( nType );
1175 if ( nType == STATE_CHANGE_ENABLE )
1176 Invalidate();
1177 else if ( (nType == STATE_CHANGE_ZOOM) ||
1178 (nType == STATE_CHANGE_CONTROLFONT) )
1180 ImplInitSettings( sal_True, sal_False, sal_False );
1181 Invalidate();
1183 else if ( nType == STATE_CHANGE_CONTROLFOREGROUND )
1185 ImplInitSettings( sal_False, sal_True, sal_False );
1186 Invalidate();
1188 else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
1190 ImplInitSettings( sal_False, sal_False, sal_True );
1191 Invalidate();
1195 // -----------------------------------------------------------------------
1197 void HeaderBar::DataChanged( const DataChangedEvent& rDCEvt )
1199 Window::DataChanged( rDCEvt );
1201 if ( (rDCEvt.GetType() == DATACHANGED_FONTS) ||
1202 (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) ||
1203 ((rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
1204 (rDCEvt.GetFlags() & SETTINGS_STYLE)) )
1206 ImplInitSettings( sal_True, sal_True, sal_True );
1207 Invalidate();
1211 // -----------------------------------------------------------------------
1213 void HeaderBar::UserDraw( const UserDrawEvent& )
1217 // -----------------------------------------------------------------------
1219 void HeaderBar::StartDrag()
1221 maStartDragHdl.Call( this );
1224 // -----------------------------------------------------------------------
1226 void HeaderBar::Drag()
1228 maDragHdl.Call( this );
1231 // -----------------------------------------------------------------------
1233 void HeaderBar::EndDrag()
1235 maEndDragHdl.Call( this );
1238 // -----------------------------------------------------------------------
1240 void HeaderBar::Select()
1242 maSelectHdl.Call( this );
1245 // -----------------------------------------------------------------------
1247 void HeaderBar::DoubleClick()
1249 maDoubleClickHdl.Call( this );
1252 // -----------------------------------------------------------------------
1254 void HeaderBar::InsertItem( sal_uInt16 nItemId, const XubString& rText,
1255 long nSize, HeaderBarItemBits nBits, sal_uInt16 nPos )
1257 DBG_ASSERT( nItemId, "HeaderBar::InsertItem(): ItemId == 0" );
1258 DBG_ASSERT( GetItemPos( nItemId ) == HEADERBAR_ITEM_NOTFOUND,
1259 "HeaderBar::InsertItem(): ItemId already exists" );
1261 // Item anlegen und in die Liste einfuegen
1262 ImplHeadItem* pItem = new ImplHeadItem;
1263 pItem->mnId = nItemId;
1264 pItem->mnBits = nBits;
1265 pItem->mnSize = nSize;
1266 pItem->maText = rText;
1267 if ( nPos < mpItemList->size() ) {
1268 ImplHeadItemList::iterator it = mpItemList->begin();
1269 ::std::advance( it, nPos );
1270 mpItemList->insert( it, pItem );
1271 } else {
1272 mpItemList->push_back( pItem );
1275 // Ausgabe updaten
1276 ImplUpdate( nPos, sal_True );
1279 // -----------------------------------------------------------------------
1281 void HeaderBar::RemoveItem( sal_uInt16 nItemId )
1283 sal_uInt16 nPos = GetItemPos( nItemId );
1284 if ( nPos != HEADERBAR_ITEM_NOTFOUND )
1286 if ( nPos < mpItemList->size() ) {
1287 ImplHeadItemList::iterator it = mpItemList->begin();
1288 ::std::advance( it, nPos );
1289 delete *it;
1290 mpItemList->erase( it );
1295 // -----------------------------------------------------------------------
1297 void HeaderBar::MoveItem( sal_uInt16 nItemId, sal_uInt16 nNewPos )
1299 sal_uInt16 nPos = GetItemPos( nItemId );
1300 if ( nPos != HEADERBAR_ITEM_NOTFOUND )
1302 if ( nPos != nNewPos )
1304 ImplHeadItemList::iterator it = mpItemList->begin();
1305 ::std::advance( it, nPos );
1306 ImplHeadItem* pItem = *it;
1307 mpItemList->erase( it );
1308 if ( nNewPos < nPos )
1309 nPos = nNewPos;
1310 it = mpItemList->begin();
1311 ::std::advance( it, nPos );
1312 mpItemList->insert( it, pItem );
1317 // -----------------------------------------------------------------------
1319 void HeaderBar::Clear()
1321 // Alle Items loeschen
1322 for ( size_t i = 0, n = mpItemList->size(); i < n; ++i ) {
1323 delete (*mpItemList)[ i ];
1325 mpItemList->clear();
1327 ImplUpdate( 0, sal_True );
1330 // -----------------------------------------------------------------------
1332 void HeaderBar::SetOffset( long nNewOffset )
1334 // Bereich verschieben
1335 Rectangle aRect( 0, mnBorderOff1, mnDX-1, mnDY-mnBorderOff1-mnBorderOff2-1 );
1336 long nDelta = mnOffset-nNewOffset;
1337 mnOffset = nNewOffset;
1338 Scroll( nDelta, 0, aRect );
1341 // -----------------------------------------------------------------------
1343 sal_uInt16 HeaderBar::GetItemCount() const
1345 return (sal_uInt16)mpItemList->size();
1348 // -----------------------------------------------------------------------
1350 sal_uInt16 HeaderBar::GetItemPos( sal_uInt16 nItemId ) const
1352 for ( size_t i = 0, n = mpItemList->size(); i < n; ++i ) {
1353 ImplHeadItem* pItem = (*mpItemList)[ i ];
1354 if ( pItem->mnId == nItemId )
1355 return (sal_uInt16)i;
1357 return HEADERBAR_ITEM_NOTFOUND;
1360 // -----------------------------------------------------------------------
1362 sal_uInt16 HeaderBar::GetItemId( sal_uInt16 nPos ) const
1364 ImplHeadItem* pItem = (nPos < mpItemList->size() ) ? (*mpItemList)[ nPos ] : NULL;
1365 if ( pItem )
1366 return pItem->mnId;
1367 else
1368 return 0;
1371 // -----------------------------------------------------------------------
1373 sal_uInt16 HeaderBar::GetItemId( const Point& rPos ) const
1375 for ( size_t i = 0, n = mpItemList->size(); i < n; ++i ) {
1376 if ( ImplGetItemRect( i ).IsInside( rPos ) ) {
1377 return GetItemId( i );
1380 return 0;
1383 // -----------------------------------------------------------------------
1385 Rectangle HeaderBar::GetItemRect( sal_uInt16 nItemId ) const
1387 Rectangle aRect;
1388 sal_uInt16 nPos = GetItemPos( nItemId );
1389 if ( nPos != HEADERBAR_ITEM_NOTFOUND )
1390 aRect = ImplGetItemRect( nPos );
1391 return aRect;
1394 // -----------------------------------------------------------------------
1396 void HeaderBar::SetItemSize( sal_uInt16 nItemId, long nNewSize )
1398 sal_uInt16 nPos = GetItemPos( nItemId );
1399 if ( nPos != HEADERBAR_ITEM_NOTFOUND )
1401 ImplHeadItem* pItem = (*mpItemList)[ nPos ];
1402 if ( pItem->mnSize != nNewSize )
1404 pItem->mnSize = nNewSize;
1405 ImplUpdate( nPos, sal_True );
1410 // -----------------------------------------------------------------------
1412 long HeaderBar::GetItemSize( sal_uInt16 nItemId ) const
1414 sal_uInt16 nPos = GetItemPos( nItemId );
1415 if ( nPos != HEADERBAR_ITEM_NOTFOUND )
1416 return (*mpItemList)[ nPos ]->mnSize;
1417 else
1418 return 0;
1421 // -----------------------------------------------------------------------
1423 void HeaderBar::SetItemBits( sal_uInt16 nItemId, HeaderBarItemBits nNewBits )
1425 sal_uInt16 nPos = GetItemPos( nItemId );
1426 if ( nPos != HEADERBAR_ITEM_NOTFOUND )
1428 ImplHeadItem* pItem = (*mpItemList)[ nPos ];
1429 if ( pItem->mnBits != nNewBits )
1431 pItem->mnBits = nNewBits;
1432 ImplUpdate( nPos );
1437 // -----------------------------------------------------------------------
1439 HeaderBarItemBits HeaderBar::GetItemBits( sal_uInt16 nItemId ) const
1441 sal_uInt16 nPos = GetItemPos( nItemId );
1442 if ( nPos != HEADERBAR_ITEM_NOTFOUND )
1443 return (*mpItemList)[ nPos ]->mnBits;
1444 else
1445 return 0;
1448 // -----------------------------------------------------------------------
1450 void HeaderBar::SetItemText( sal_uInt16 nItemId, const XubString& rText )
1452 sal_uInt16 nPos = GetItemPos( nItemId );
1453 if ( nPos != HEADERBAR_ITEM_NOTFOUND )
1455 (*mpItemList)[ nPos ]->maText = rText;
1456 ImplUpdate( nPos );
1460 // -----------------------------------------------------------------------
1462 XubString HeaderBar::GetItemText( sal_uInt16 nItemId ) const
1464 sal_uInt16 nPos = GetItemPos( nItemId );
1465 if ( nPos != HEADERBAR_ITEM_NOTFOUND )
1466 return (*mpItemList)[ nPos ]->maText;
1467 else
1468 return String();
1471 // -----------------------------------------------------------------------
1473 XubString HeaderBar::GetHelpText( sal_uInt16 nItemId ) const
1475 sal_uInt16 nPos = GetItemPos( nItemId );
1476 if ( nPos != HEADERBAR_ITEM_NOTFOUND )
1478 ImplHeadItem* pItem = (*mpItemList)[ nPos ];
1479 if ( !pItem->maHelpText.Len() && !pItem->maHelpId.isEmpty() )
1481 Help* pHelp = Application::GetHelp();
1482 if ( pHelp )
1483 pItem->maHelpText = pHelp->GetHelpText( OStringToOUString( pItem->maHelpId, RTL_TEXTENCODING_UTF8 ), this );
1486 return pItem->maHelpText;
1488 else
1489 return XubString();
1492 // -----------------------------------------------------------------------
1494 OString HeaderBar::GetHelpId( sal_uInt16 nItemId ) const
1496 sal_uInt16 nPos = GetItemPos( nItemId );
1497 OString aRet;
1498 if ( nPos != HEADERBAR_ITEM_NOTFOUND )
1499 return (*mpItemList)[ nPos ]->maHelpId;
1500 return aRet;
1503 // -----------------------------------------------------------------------
1505 Size HeaderBar::CalcWindowSizePixel() const
1507 long nMaxImageSize = 0;
1508 Size aSize( 0, GetTextHeight() );
1510 for ( size_t i = 0, n = mpItemList->size(); i < n; ++i )
1512 ImplHeadItem* pItem = (*mpItemList)[ i ];
1513 // Image-Groessen beruecksichtigen
1514 long nImageHeight = pItem->maImage.GetSizePixel().Height();
1515 if ( !(pItem->mnBits & (HIB_LEFTIMAGE | HIB_RIGHTIMAGE)) && pItem->maText.Len() )
1516 nImageHeight += aSize.Height();
1517 if ( nImageHeight > nMaxImageSize )
1518 nMaxImageSize = nImageHeight;
1520 // Breite aufaddieren
1521 aSize.Width() += pItem->mnSize;
1524 if ( nMaxImageSize > aSize.Height() )
1525 aSize.Height() = nMaxImageSize;
1527 // Border aufaddieren
1528 if ( mbButtonStyle )
1529 aSize.Height() += 4;
1530 else
1531 aSize.Height() += 2;
1532 aSize.Height() += mnBorderOff1+mnBorderOff2;
1534 return aSize;
1537 ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > HeaderBar::CreateAccessible()
1539 if ( !mxAccessible.is() )
1541 if ( maCreateAccessibleHdl.IsSet() )
1542 maCreateAccessibleHdl.Call( this );
1544 if ( !mxAccessible.is() )
1545 mxAccessible = Window::CreateAccessible();
1548 return mxAccessible;
1551 void HeaderBar::SetAccessible( ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > _xAccessible )
1553 mxAccessible = _xAccessible;
1556 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */