Update ooo320-m1
[ooovba.git] / vcl / source / window / status.cxx
blobc15909dc54453887cd5f3dd1529ffaafa54f4942
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: status.cxx,v $
10 * $Revision: 1.30 $
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_vcl.hxx"
33 #include <tools/list.hxx>
34 #include <tools/debug.hxx>
36 #ifndef _SV_RC_H
37 #include <tools/rc.h>
38 #endif
39 #include <vcl/svdata.hxx>
40 #include <vcl/event.hxx>
41 #include <vcl/decoview.hxx>
42 #include <vcl/svapp.hxx>
43 #include <vcl/help.hxx>
44 #include <vcl/status.hxx>
45 #include <vcl/virdev.hxx>
46 #include <vcl/window.h>
48 // =======================================================================
50 #define STATUSBAR_OFFSET_X STATUSBAR_OFFSET
51 #define STATUSBAR_OFFSET_Y 2
52 #define STATUSBAR_OFFSET_TEXTY 3
54 #define STATUSBAR_PRGS_OFFSET 3
55 #define STATUSBAR_PRGS_COUNT 100
56 #define STATUSBAR_PRGS_MIN 5
58 // -----------------------------------------------------------------------
60 class StatusBar::ImplData
62 public:
63 ImplData();
64 ~ImplData();
66 VirtualDevice* mpVirDev;
67 BOOL mbTopBorder:1;
70 StatusBar::ImplData::ImplData()
72 mpVirDev = NULL;
73 mbTopBorder = FALSE;
76 StatusBar::ImplData::~ImplData()
80 struct ImplStatusItem
82 USHORT mnId;
83 StatusBarItemBits mnBits;
84 long mnWidth;
85 long mnOffset;
86 long mnExtraWidth;
87 long mnX;
88 XubString maText;
89 XubString maHelpText;
90 XubString maQuickHelpText;
91 ULONG mnHelpId;
92 void* mpUserData;
93 BOOL mbVisible;
94 XubString maAccessibleName;
95 XubString maCommand;
98 DECLARE_LIST( ImplStatusItemList, ImplStatusItem* )
100 // =======================================================================
102 inline long ImplCalcProgessWidth( USHORT nMax, long nSize )
104 return ((nMax*(nSize+(nSize/2)))-(nSize/2)+(STATUSBAR_PRGS_OFFSET*2));
107 // -----------------------------------------------------------------------
109 static Point ImplGetItemTextPos( const Size& rRectSize, const Size& rTextSize,
110 USHORT nStyle )
112 long nX;
113 long nY;
114 long delta = (rTextSize.Height()/4) + 1;
115 if( delta + rTextSize.Width() > rRectSize.Width() )
116 delta = 0;
118 if ( nStyle & SIB_LEFT )
119 nX = delta;
120 else if ( nStyle & SIB_RIGHT )
121 nX = rRectSize.Width()-rTextSize.Width()-delta;
122 else // SIB_CENTER
123 nX = (rRectSize.Width()-rTextSize.Width())/2;
124 nY = (rRectSize.Height()-rTextSize.Height())/2 + 1;
125 return Point( nX, nY );
128 // -----------------------------------------------------------------------
130 BOOL StatusBar::ImplIsItemUpdate()
132 if ( !mbProgressMode && mbVisibleItems && IsReallyVisible() && IsUpdateMode() )
133 return TRUE;
134 else
135 return FALSE;
138 // -----------------------------------------------------------------------
140 void StatusBar::ImplInit( Window* pParent, WinBits nStyle )
142 mpImplData = new ImplData;
144 // Default ist RightAlign
145 if ( !(nStyle & (WB_LEFT | WB_RIGHT)) )
146 nStyle |= WB_RIGHT;
148 Window::ImplInit( pParent, nStyle & ~WB_BORDER, NULL );
150 // WinBits merken
151 mpItemList = new ImplStatusItemList;
152 mpImplData->mpVirDev = new VirtualDevice( *this );
153 mnCurItemId = 0;
154 mbFormat = TRUE;
155 mbVisibleItems = TRUE;
156 mbProgressMode = FALSE;
157 mbInUserDraw = FALSE;
158 mbBottomBorder = FALSE;
159 mnDX = 0;
160 mnDY = 0;
161 mnCalcHeight = 0;
162 mnItemY = STATUSBAR_OFFSET_Y;
163 mnTextY = STATUSBAR_OFFSET_TEXTY;
165 ImplInitSettings( TRUE, TRUE, TRUE );
166 SetLineColor();
168 SetOutputSizePixel( CalcWindowSizePixel() );
171 // -----------------------------------------------------------------------
173 StatusBar::StatusBar( Window* pParent, WinBits nStyle ) :
174 Window( WINDOW_STATUSBAR )
176 ImplInit( pParent, nStyle );
179 // -----------------------------------------------------------------------
181 StatusBar::StatusBar( Window* pParent, const ResId& rResId ) :
182 Window( WINDOW_STATUSBAR )
184 rResId.SetRT( RSC_STATUSBAR );
185 WinBits nStyle = ImplInitRes( rResId );
186 ImplInit( pParent, nStyle );
187 ImplLoadRes( rResId );
189 if ( !(nStyle & WB_HIDE) )
190 Show();
193 // -----------------------------------------------------------------------
195 StatusBar::~StatusBar()
197 // Alle Items loeschen
198 ImplStatusItem* pItem = mpItemList->First();
199 while ( pItem )
201 delete pItem;
202 pItem = mpItemList->Next();
205 delete mpItemList;
207 // VirtualDevice loeschen
208 delete mpImplData->mpVirDev;
210 delete mpImplData;
213 // -----------------------------------------------------------------------
215 void StatusBar::ImplInitSettings( BOOL bFont,
216 BOOL bForeground, BOOL bBackground )
218 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
220 if ( bFont )
222 Font aFont = rStyleSettings.GetToolFont();
223 if ( IsControlFont() )
224 aFont.Merge( GetControlFont() );
225 SetZoomedPointFont( aFont );
228 if ( bForeground || bFont )
230 Color aColor;
231 if ( IsControlForeground() )
232 aColor = GetControlForeground();
233 else if ( GetStyle() & WB_3DLOOK )
234 aColor = rStyleSettings.GetButtonTextColor();
235 else
236 aColor = rStyleSettings.GetWindowTextColor();
237 SetTextColor( aColor );
238 SetTextFillColor();
240 mpImplData->mpVirDev->SetFont( GetFont() );
241 mpImplData->mpVirDev->SetTextColor( GetTextColor() );
242 mpImplData->mpVirDev->SetTextAlign( GetTextAlign() );
243 mpImplData->mpVirDev->SetTextFillColor();
246 if ( bBackground )
248 Color aColor;
249 if ( IsControlBackground() )
250 aColor = GetControlBackground();
251 else if ( GetStyle() & WB_3DLOOK )
252 aColor = rStyleSettings.GetFaceColor();
253 else
254 aColor = rStyleSettings.GetWindowColor();
255 SetBackground( aColor );
256 mpImplData->mpVirDev->SetBackground( GetBackground() );
258 // NWF background
259 if( ! IsControlBackground() &&
260 IsNativeControlSupported( CTRL_WINDOW_BACKGROUND, PART_BACKGROUND_WINDOW ) )
262 ImplGetWindowImpl()->mnNativeBackground = PART_BACKGROUND_WINDOW;
263 EnableChildTransparentMode( TRUE );
268 // -----------------------------------------------------------------------
270 void StatusBar::ImplFormat()
272 ImplStatusItem* pItem;
273 long nExtraWidth;
274 long nExtraWidth2;
275 long nX;
276 USHORT nAutoSizeItems = 0;
278 // Breiten zusammenrechnen
279 mnItemsWidth = STATUSBAR_OFFSET_X;
280 long nOffset = 0;
281 pItem = mpItemList->First();
282 while ( pItem )
284 if ( pItem->mbVisible )
286 if ( pItem->mnBits & SIB_AUTOSIZE )
287 nAutoSizeItems++;
289 mnItemsWidth += pItem->mnWidth + nOffset;
290 nOffset = pItem->mnOffset;
293 pItem = mpItemList->Next();
296 if ( GetStyle() & WB_RIGHT )
298 // Bei rechtsbuendiger Ausrichtung wird kein AutoSize ausgewertet,
299 // da wir links den Text anzeigen, der mit SetText gesetzt wird
300 nX = mnDX - mnItemsWidth;
301 nExtraWidth = 0;
302 nExtraWidth2 = 0;
304 else
306 mnItemsWidth += STATUSBAR_OFFSET_X;
308 // Bei linksbuendiger Ausrichtung muessen wir gegebenenfalls noch
309 // AutoSize auswerten
310 if ( nAutoSizeItems && (mnDX > (mnItemsWidth - STATUSBAR_OFFSET)) )
312 nExtraWidth = (mnDX - mnItemsWidth - 1) / nAutoSizeItems;
313 nExtraWidth2 = (mnDX - mnItemsWidth - 1) % nAutoSizeItems;
315 else
317 nExtraWidth = 0;
318 nExtraWidth2 = 0;
320 nX = STATUSBAR_OFFSET_X;
323 pItem = mpItemList->First();
324 while ( pItem )
326 if ( pItem->mbVisible )
328 if ( pItem->mnBits & SIB_AUTOSIZE )
330 pItem->mnExtraWidth = nExtraWidth;
331 if ( nExtraWidth2 )
333 pItem->mnExtraWidth++;
334 nExtraWidth2--;
337 else
338 pItem->mnExtraWidth = 0;
340 pItem->mnX = nX;
341 nX += pItem->mnWidth + pItem->mnExtraWidth + pItem->mnOffset;
344 pItem = mpItemList->Next();
347 mbFormat = FALSE;
350 // -----------------------------------------------------------------------
352 Rectangle StatusBar::ImplGetItemRectPos( USHORT nPos ) const
354 Rectangle aRect;
355 ImplStatusItem* pItem;
357 pItem = mpItemList->GetObject( nPos );
359 if ( pItem )
361 if ( pItem->mbVisible )
363 aRect.Left() = pItem->mnX;
364 aRect.Right() = aRect.Left() + pItem->mnWidth + pItem->mnExtraWidth;
365 aRect.Top() = mnItemY;
366 aRect.Bottom() = mnCalcHeight - STATUSBAR_OFFSET_Y;
367 if( IsTopBorder() )
368 aRect.Bottom()+=2;
372 return aRect;
375 // -----------------------------------------------------------------------
377 void StatusBar::ImplDrawText( BOOL bOffScreen, long nOldTextWidth )
379 // Das ueberschreiben der Item-Box verhindern
380 Rectangle aTextRect;
381 aTextRect.Left() = STATUSBAR_OFFSET_X+1;
382 aTextRect.Top() = mnTextY;
383 if ( mbVisibleItems && (GetStyle() & WB_RIGHT) )
384 aTextRect.Right() = mnDX - mnItemsWidth - 1;
385 else
386 aTextRect.Right() = mnDX - 1;
387 if ( aTextRect.Right() > aTextRect.Left() )
389 // Position ermitteln
390 XubString aStr = GetText();
391 USHORT nPos = aStr.Search( _LF );
392 if ( nPos != STRING_NOTFOUND )
393 aStr.Erase( nPos );
395 aTextRect.Bottom() = aTextRect.Top()+GetTextHeight()+1;
397 if ( bOffScreen )
399 long nMaxWidth = Max( nOldTextWidth, GetTextWidth( aStr ) );
400 Size aVirDevSize( nMaxWidth, aTextRect.GetHeight() );
401 mpImplData->mpVirDev->SetOutputSizePixel( aVirDevSize );
402 Rectangle aTempRect = aTextRect;
403 aTempRect.SetPos( Point( 0, 0 ) );
404 mpImplData->mpVirDev->DrawText( aTempRect, aStr, TEXT_DRAW_LEFT | TEXT_DRAW_TOP | TEXT_DRAW_CLIP | TEXT_DRAW_ENDELLIPSIS );
405 DrawOutDev( aTextRect.TopLeft(), aVirDevSize, Point(), aVirDevSize, *mpImplData->mpVirDev );
407 else
408 DrawText( aTextRect, aStr, TEXT_DRAW_LEFT | TEXT_DRAW_TOP | TEXT_DRAW_CLIP | TEXT_DRAW_ENDELLIPSIS );
412 // -----------------------------------------------------------------------
414 void StatusBar::ImplDrawItem( BOOL bOffScreen, USHORT nPos, BOOL bDrawText, BOOL bDrawFrame )
416 Rectangle aRect = ImplGetItemRectPos( nPos );
418 if ( aRect.IsEmpty() )
419 return;
421 // Ausgabebereich berechnen
422 ImplStatusItem* pItem = mpItemList->GetObject( nPos );
423 Rectangle aTextRect( aRect.Left()+1, aRect.Top()+1,
424 aRect.Right()-1, aRect.Bottom()-1 );
425 Size aTextRectSize( aTextRect.GetSize() );
427 if ( bOffScreen )
428 mpImplData->mpVirDev->SetOutputSizePixel( aTextRectSize );
429 else
431 Region aRegion( aTextRect );
432 SetClipRegion( aRegion );
435 // Text ausgeben
436 if ( bDrawText )
438 Size aTextSize( GetTextWidth( pItem->maText ), GetTextHeight() );
439 Point aTextPos = ImplGetItemTextPos( aTextRectSize, aTextSize, pItem->mnBits );
440 if ( bOffScreen )
441 mpImplData->mpVirDev->DrawText( aTextPos, pItem->maText );
442 else
444 aTextPos.X() += aTextRect.Left();
445 aTextPos.Y() += aTextRect.Top();
446 DrawText( aTextPos, pItem->maText );
450 // Gegebenenfalls auch DrawItem aufrufen
451 if ( pItem->mnBits & SIB_USERDRAW )
453 if ( bOffScreen )
455 mbInUserDraw = TRUE;
456 mpImplData->mpVirDev->EnableRTL( IsRTLEnabled() );
457 UserDrawEvent aODEvt( mpImplData->mpVirDev, Rectangle( Point(), aTextRectSize ), pItem->mnId );
458 UserDraw( aODEvt );
459 mpImplData->mpVirDev->EnableRTL( FALSE );
460 mbInUserDraw = FALSE;
462 else
464 UserDrawEvent aODEvt( this, aTextRect, pItem->mnId );
465 UserDraw( aODEvt );
469 if ( bOffScreen )
470 DrawOutDev( aTextRect.TopLeft(), aTextRectSize, Point(), aTextRectSize, *mpImplData->mpVirDev );
471 else
472 SetClipRegion();
474 // Frame ausgeben
475 if ( bDrawFrame && !(pItem->mnBits & SIB_FLAT) )
477 USHORT nStyle;
479 if ( pItem->mnBits & SIB_IN )
480 nStyle = FRAME_DRAW_IN;
481 else
482 nStyle = FRAME_DRAW_OUT;
484 DecorationView aDecoView( this );
485 aDecoView.DrawFrame( aRect, nStyle );
488 if ( !ImplIsRecordLayout() )
489 ImplCallEventListeners( VCLEVENT_STATUSBAR_DRAWITEM, (void*) sal_IntPtr(pItem->mnId) );
492 // -----------------------------------------------------------------------
494 void DrawProgress( Window* pWindow, const Point& rPos,
495 long nOffset, long nPrgsWidth, long nPrgsHeight,
496 USHORT nPercent1, USHORT nPercent2, USHORT nPercentCount,
497 const Rectangle& rFramePosSize
500 if( pWindow->IsNativeControlSupported( CTRL_PROGRESS, PART_ENTIRE_CONTROL ) )
502 bool bNeedErase = ImplGetSVData()->maNWFData.mbProgressNeedsErase;
504 long nFullWidth = (nPrgsWidth + nOffset) * (10000 / nPercentCount);
505 long nPerc = (nPercent2 > 10000) ? 10000 : nPercent2;
506 ImplControlValue aValue( nFullWidth * (long)nPerc / 10000 );
507 Rectangle aDrawRect( rPos, Size( nFullWidth, nPrgsHeight ) );
508 Region aControlRegion( aDrawRect );
509 if( bNeedErase )
511 Window* pEraseWindow = pWindow;
512 while( pEraseWindow->IsPaintTransparent() &&
513 ! pEraseWindow->ImplGetWindowImpl()->mbFrame )
515 pEraseWindow = pEraseWindow->ImplGetWindowImpl()->mpParent;
517 if( pEraseWindow == pWindow )
518 // restore background of pWindow
519 pEraseWindow->Erase( rFramePosSize );
520 else
522 // restore transparent background
523 Point aTL( pWindow->OutputToAbsoluteScreenPixel( rFramePosSize.TopLeft() ) );
524 aTL = pEraseWindow->AbsoluteScreenToOutputPixel( aTL );
525 Rectangle aRect( aTL, rFramePosSize.GetSize() );
526 pEraseWindow->Invalidate( aRect, INVALIDATE_NOCHILDREN |
527 INVALIDATE_NOCLIPCHILDREN |
528 INVALIDATE_TRANSPARENT );
529 pEraseWindow->Update();
531 pWindow->Push( PUSH_CLIPREGION );
532 pWindow->IntersectClipRegion( rFramePosSize );
534 BOOL bNativeOK = pWindow->DrawNativeControl( CTRL_PROGRESS, PART_ENTIRE_CONTROL, aControlRegion,
535 CTRL_STATE_ENABLED, aValue, rtl::OUString() );
536 if( bNeedErase )
537 pWindow->Pop();
538 if( bNativeOK )
540 pWindow->Flush();
541 return;
545 // Werte vorberechnen
546 USHORT nPerc1 = nPercent1 / nPercentCount;
547 USHORT nPerc2 = nPercent2 / nPercentCount;
549 if ( nPerc1 > nPerc2 )
551 // Support progress that can also decrease
553 // Rechteck berechnen
554 long nDX = nPrgsWidth + nOffset;
555 long nLeft = rPos.X()+((nPerc1-1)*nDX);
556 Rectangle aRect( nLeft, rPos.Y(), nLeft+nPrgsWidth, rPos.Y()+nPrgsHeight );
560 pWindow->Erase( aRect );
561 aRect.Left() -= nDX;
562 aRect.Right() -= nDX;
563 nPerc1--;
565 while ( nPerc1 > nPerc2 );
567 pWindow->Flush();
569 else if ( nPerc1 < nPerc2 )
571 // Percent-Rechtecke malen
572 // Wenn Percent2 ueber 100%, Werte anpassen
573 if ( nPercent2 > 10000 )
575 nPerc2 = 10000 / nPercentCount;
576 if ( nPerc1 >= nPerc2 )
577 nPerc1 = nPerc2-1;
580 // Rechteck berechnen
581 long nDX = nPrgsWidth + nOffset;
582 long nLeft = rPos.X()+(nPerc1*nDX);
583 Rectangle aRect( nLeft, rPos.Y(), nLeft+nPrgsWidth, rPos.Y()+nPrgsHeight );
587 pWindow->DrawRect( aRect );
588 aRect.Left() += nDX;
589 aRect.Right() += nDX;
590 nPerc1++;
592 while ( nPerc1 < nPerc2 );
594 // Bei mehr als 100%, lassen wir das Rechteck blinken
595 if ( nPercent2 > 10000 )
597 // an/aus-Status festlegen
598 if ( ((nPercent2 / nPercentCount) & 0x01) == (nPercentCount & 0x01) )
600 aRect.Left() -= nDX;
601 aRect.Right() -= nDX;
602 pWindow->Erase( aRect );
606 pWindow->Flush();
610 // -----------------------------------------------------------------------
612 void StatusBar::ImplDrawProgress( BOOL bPaint,
613 USHORT nPercent1, USHORT nPercent2 )
615 bool bNative = IsNativeControlSupported( CTRL_PROGRESS, PART_ENTIRE_CONTROL );
616 // bPaint: draw text also, else only update progress
617 if ( bPaint )
619 DrawText( maPrgsTxtPos, maPrgsTxt );
620 if( ! bNative )
622 DecorationView aDecoView( this );
623 aDecoView.DrawFrame( maPrgsFrameRect, FRAME_DRAW_IN );
627 Point aPos( maPrgsFrameRect.Left()+STATUSBAR_PRGS_OFFSET,
628 maPrgsFrameRect.Top()+STATUSBAR_PRGS_OFFSET );
629 long nPrgsHeight = mnPrgsSize;
630 if( bNative )
632 aPos = maPrgsFrameRect.TopLeft();
633 nPrgsHeight = maPrgsFrameRect.GetHeight();
635 DrawProgress( this, aPos, mnPrgsSize/2, mnPrgsSize, nPrgsHeight,
636 nPercent1*100, nPercent2*100, mnPercentCount, maPrgsFrameRect );
639 // -----------------------------------------------------------------------
641 void StatusBar::ImplCalcProgressRect()
643 // calculate text size
644 Size aPrgsTxtSize( GetTextWidth( maPrgsTxt ), GetTextHeight() );
645 maPrgsTxtPos.X() = STATUSBAR_OFFSET_X+1;
647 // calculate progress frame
648 maPrgsFrameRect.Left() = maPrgsTxtPos.X()+aPrgsTxtSize.Width()+STATUSBAR_OFFSET;
649 maPrgsFrameRect.Top() = mnItemY;
650 maPrgsFrameRect.Bottom() = mnCalcHeight - STATUSBAR_OFFSET_Y;
651 if( IsTopBorder() )
652 maPrgsFrameRect.Bottom()+=2;
654 // calculate size of progress rects
655 mnPrgsSize = maPrgsFrameRect.Bottom()-maPrgsFrameRect.Top()-(STATUSBAR_PRGS_OFFSET*2);
656 USHORT nMaxPercent = STATUSBAR_PRGS_COUNT;
658 long nMaxWidth = mnDX-STATUSBAR_OFFSET-1;
660 // make smaller if there are too many rects
661 while ( maPrgsFrameRect.Left()+ImplCalcProgessWidth( nMaxPercent, mnPrgsSize ) > nMaxWidth )
663 nMaxPercent--;
664 if ( nMaxPercent <= STATUSBAR_PRGS_MIN )
665 break;
667 maPrgsFrameRect.Right() = maPrgsFrameRect.Left() + ImplCalcProgessWidth( nMaxPercent, mnPrgsSize );
669 // save the divisor for later
670 mnPercentCount = 10000 / nMaxPercent;
671 BOOL bNativeOK = FALSE;
672 if( IsNativeControlSupported( CTRL_PROGRESS, PART_ENTIRE_CONTROL ) )
674 ImplControlValue aValue;
675 Region aControlRegion( Rectangle( (const Point&)Point(), maPrgsFrameRect.GetSize() ) );
676 Region aNativeControlRegion, aNativeContentRegion;
677 if( (bNativeOK = GetNativeControlRegion( CTRL_PROGRESS, PART_ENTIRE_CONTROL, aControlRegion,
678 CTRL_STATE_ENABLED, aValue, rtl::OUString(),
679 aNativeControlRegion, aNativeContentRegion ) ) != FALSE )
681 long nProgressHeight = aNativeControlRegion.GetBoundRect().GetHeight();
682 if( nProgressHeight > maPrgsFrameRect.GetHeight() )
684 long nDelta = nProgressHeight - maPrgsFrameRect.GetHeight();
685 maPrgsFrameRect.Top() -= (nDelta - nDelta/2);
686 maPrgsFrameRect.Bottom() += nDelta/2;
688 maPrgsTxtPos.Y() = maPrgsFrameRect.Top() + (nProgressHeight - GetTextHeight())/2;
691 if( ! bNativeOK )
692 maPrgsTxtPos.Y() = mnTextY;
697 // -----------------------------------------------------------------------
699 void StatusBar::MouseButtonDown( const MouseEvent& rMEvt )
701 // Nur bei linker Maustaste ToolBox ausloesen
702 if ( rMEvt.IsLeft() )
704 if ( mbVisibleItems )
706 Point aMousePos = rMEvt.GetPosPixel();
707 USHORT i = 0;
709 // Item suchen, das geklickt wurde
710 ImplStatusItem* pItem = mpItemList->First();
711 while ( pItem )
713 // Ist es dieses Item
714 if ( ImplGetItemRectPos( i ).IsInside( aMousePos ) )
716 mnCurItemId = pItem->mnId;
717 if ( rMEvt.GetClicks() == 2 )
718 DoubleClick();
719 else
720 Click();
721 mnCurItemId = 0;
723 // Item wurde gefunden
724 return;
727 i++;
728 pItem = mpItemList->Next();
732 // Kein Item, dann nur Click oder DoubleClick
733 if ( rMEvt.GetClicks() == 2 )
734 DoubleClick();
735 else
736 Click();
740 // -----------------------------------------------------------------------
742 void StatusBar::Paint( const Rectangle& )
744 if ( mbFormat )
745 ImplFormat();
747 USHORT nItemCount = (USHORT)mpItemList->Count();
749 if ( mbProgressMode )
750 ImplDrawProgress( TRUE, 0, mnPercent );
751 else
753 // Text zeichen
754 if ( !mbVisibleItems || (GetStyle() & WB_RIGHT) )
755 ImplDrawText( FALSE, 0 );
757 // Items zeichnen
758 if ( mbVisibleItems )
760 // Items zeichnen
761 for ( USHORT i = 0; i < nItemCount; i++ )
762 ImplDrawItem( FALSE, i, TRUE, TRUE );
766 // draw borders
767 if( IsTopBorder() )
769 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
770 SetLineColor( rStyleSettings.GetShadowColor() );
771 DrawLine( Point( 0, 0 ), Point( mnDX-1, 0 ) );
772 SetLineColor( rStyleSettings.GetLightColor() );
773 DrawLine( Point( 0, 1 ), Point( mnDX-1, 1 ) );
776 if ( IsBottomBorder() )
778 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
779 SetLineColor( rStyleSettings.GetShadowColor() );
780 DrawLine( Point( 0, mnDY-2 ), Point( mnDX-1, mnDY-2 ) );
781 SetLineColor( rStyleSettings.GetLightColor() );
782 DrawLine( Point( 0, mnDY-1 ), Point( mnDX-1, mnDY-1 ) );
786 // -----------------------------------------------------------------------
788 void StatusBar::Move()
790 Window::Move();
793 // -----------------------------------------------------------------------
795 void StatusBar::Resize()
797 // Breite und Hoehe abfragen und merken
798 Size aSize = GetOutputSizePixel();
799 mnDX = aSize.Width();
800 mnDY = aSize.Height();
801 mnCalcHeight = mnDY;
802 // subtract border
803 if( IsTopBorder() )
804 mnCalcHeight -= 2;
805 if ( IsBottomBorder() )
806 mnCalcHeight -= 2;
808 mnItemY = STATUSBAR_OFFSET_Y;
809 if( IsTopBorder() )
810 mnItemY += 2;
811 mnTextY = (mnCalcHeight-GetTextHeight())/2;
812 if( IsTopBorder() )
813 mnTextY += 2;
815 // Formatierung neu ausloesen
816 mbFormat = TRUE;
818 if ( mbProgressMode )
819 ImplCalcProgressRect();
821 Invalidate();
824 // -----------------------------------------------------------------------
826 void StatusBar::RequestHelp( const HelpEvent& rHEvt )
828 // no keyboard help in status bar
829 if( rHEvt.KeyboardActivated() )
830 return;
832 USHORT nItemId = GetItemId( ScreenToOutputPixel( rHEvt.GetMousePosPixel() ) );
834 if ( nItemId )
836 Rectangle aItemRect = GetItemRect( nItemId );
837 Point aPt = OutputToScreenPixel( aItemRect.TopLeft() );
838 aItemRect.Left() = aPt.X();
839 aItemRect.Top() = aPt.Y();
840 aPt = OutputToScreenPixel( aItemRect.BottomRight() );
841 aItemRect.Right() = aPt.X();
842 aItemRect.Bottom() = aPt.Y();
844 if ( rHEvt.GetMode() & HELPMODE_BALLOON )
846 XubString aStr = GetHelpText( nItemId );
847 Help::ShowBalloon( this, aItemRect.Center(), aItemRect, aStr );
848 return;
850 else if ( rHEvt.GetMode() & HELPMODE_QUICK )
852 XubString aStr = GetQuickHelpText( nItemId );
853 // Show quickhelp if available
854 if( aStr.Len() )
856 Help::ShowQuickHelp( this, aItemRect, aStr );
857 return;
859 aStr = GetItemText( nItemId );
860 // show a quick help if item text doesn't fit
861 if ( GetTextWidth( aStr ) > aItemRect.GetWidth() )
863 Help::ShowQuickHelp( this, aItemRect, aStr );
864 return;
867 else if ( rHEvt.GetMode() & HELPMODE_EXTENDED )
869 String aCommand = GetItemCommand( nItemId );
870 ULONG nHelpId = GetHelpId( nItemId );
872 if ( aCommand.Len() || nHelpId )
874 // Wenn eine Hilfe existiert, dann ausloesen
875 Help* pHelp = Application::GetHelp();
876 if ( pHelp )
878 if ( aCommand.Len() )
879 pHelp->Start( aCommand, this );
880 else if ( nHelpId )
881 pHelp->Start( nHelpId, this );
883 return;
888 Window::RequestHelp( rHEvt );
891 // -----------------------------------------------------------------------
893 void StatusBar::StateChanged( StateChangedType nType )
895 Window::StateChanged( nType );
897 if ( nType == STATE_CHANGE_INITSHOW )
898 ImplFormat();
899 else if ( nType == STATE_CHANGE_UPDATEMODE )
900 Invalidate();
901 else if ( (nType == STATE_CHANGE_ZOOM) ||
902 (nType == STATE_CHANGE_CONTROLFONT) )
904 mbFormat = TRUE;
905 ImplInitSettings( TRUE, FALSE, FALSE );
906 Invalidate();
908 else if ( nType == STATE_CHANGE_CONTROLFOREGROUND )
910 ImplInitSettings( FALSE, TRUE, FALSE );
911 Invalidate();
913 else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
915 ImplInitSettings( FALSE, FALSE, TRUE );
916 Invalidate();
920 // -----------------------------------------------------------------------
922 void StatusBar::DataChanged( const DataChangedEvent& rDCEvt )
924 Window::DataChanged( rDCEvt );
926 if ( (rDCEvt.GetType() == DATACHANGED_DISPLAY) ||
927 (rDCEvt.GetType() == DATACHANGED_FONTS) ||
928 (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) ||
929 ((rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
930 (rDCEvt.GetFlags() & SETTINGS_STYLE)) )
932 mbFormat = TRUE;
933 ImplInitSettings( TRUE, TRUE, TRUE );
934 ImplStatusItem* pItem = mpItemList->First();
935 long nFudge = GetTextHeight() / 4;
936 while ( pItem )
938 long nWidth = GetTextWidth( pItem->maText ) + nFudge;
939 if( nWidth > pItem->mnWidth + STATUSBAR_OFFSET )
940 pItem->mnWidth = nWidth + STATUSBAR_OFFSET;
941 pItem = mpItemList->Next();
943 Size aSize = GetSizePixel();
944 // do not disturb current width, since
945 // CalcWindowSizePixel calculates a minimum width
946 aSize.Height() = CalcWindowSizePixel().Height();
947 SetSizePixel( aSize );
948 Invalidate();
952 // -----------------------------------------------------------------------
954 void StatusBar::Click()
956 ImplCallEventListeners( VCLEVENT_STATUSBAR_CLICK );
957 maClickHdl.Call( this );
960 // -----------------------------------------------------------------------
962 void StatusBar::DoubleClick()
964 ImplCallEventListeners( VCLEVENT_STATUSBAR_DOUBLECLICK );
965 maDoubleClickHdl.Call( this );
968 // -----------------------------------------------------------------------
970 void StatusBar::UserDraw( const UserDrawEvent& )
974 // -----------------------------------------------------------------------
976 void StatusBar::InsertItem( USHORT nItemId, ULONG nWidth,
977 StatusBarItemBits nBits,
978 long nOffset, USHORT nPos )
980 DBG_ASSERT( nItemId, "StatusBar::InsertItem(): ItemId == 0" );
981 DBG_ASSERT( GetItemPos( nItemId ) == STATUSBAR_ITEM_NOTFOUND,
982 "StatusBar::InsertItem(): ItemId already exists" );
984 // IN und CENTER sind Default
985 if ( !(nBits & (SIB_IN | SIB_OUT | SIB_FLAT)) )
986 nBits |= SIB_IN;
987 if ( !(nBits & (SIB_LEFT | SIB_RIGHT | SIB_CENTER)) )
988 nBits |= SIB_CENTER;
990 // Item anlegen
991 long nFudge = GetTextHeight()/4;
992 ImplStatusItem* pItem = new ImplStatusItem;
993 pItem->mnId = nItemId;
994 pItem->mnBits = nBits;
995 pItem->mnWidth = (long)nWidth+nFudge+STATUSBAR_OFFSET;
996 pItem->mnOffset = nOffset;
997 pItem->mnHelpId = 0;
998 pItem->mpUserData = 0;
999 pItem->mbVisible = TRUE;
1001 // Item in die Liste einfuegen
1002 mpItemList->Insert( pItem, nPos );
1004 mbFormat = TRUE;
1005 if ( ImplIsItemUpdate() )
1006 Invalidate();
1008 ImplCallEventListeners( VCLEVENT_STATUSBAR_ITEMADDED, (void*) sal_IntPtr(nItemId) );
1011 // -----------------------------------------------------------------------
1013 void StatusBar::RemoveItem( USHORT nItemId )
1015 USHORT nPos = GetItemPos( nItemId );
1016 if ( nPos != STATUSBAR_ITEM_NOTFOUND )
1018 ImplStatusItem* pItem = mpItemList->Remove( nPos );
1019 delete pItem;
1021 mbFormat = TRUE;
1022 if ( ImplIsItemUpdate() )
1023 Invalidate();
1025 ImplCallEventListeners( VCLEVENT_STATUSBAR_ITEMREMOVED, (void*) sal_IntPtr(nItemId) );
1029 // -----------------------------------------------------------------------
1031 void StatusBar::ShowItem( USHORT nItemId )
1033 USHORT nPos = GetItemPos( nItemId );
1035 if ( nPos != STATUSBAR_ITEM_NOTFOUND )
1037 ImplStatusItem* pItem = mpItemList->GetObject( nPos );
1038 if ( !pItem->mbVisible )
1040 pItem->mbVisible = TRUE;
1042 mbFormat = TRUE;
1043 if ( ImplIsItemUpdate() )
1044 Invalidate();
1046 ImplCallEventListeners( VCLEVENT_STATUSBAR_SHOWITEM, (void*) sal_IntPtr(nItemId) );
1051 // -----------------------------------------------------------------------
1053 void StatusBar::HideItem( USHORT nItemId )
1055 USHORT nPos = GetItemPos( nItemId );
1057 if ( nPos != STATUSBAR_ITEM_NOTFOUND )
1059 ImplStatusItem* pItem = mpItemList->GetObject( nPos );
1060 if ( pItem->mbVisible )
1062 pItem->mbVisible = FALSE;
1064 mbFormat = TRUE;
1065 if ( ImplIsItemUpdate() )
1066 Invalidate();
1068 ImplCallEventListeners( VCLEVENT_STATUSBAR_HIDEITEM, (void*) sal_IntPtr(nItemId) );
1073 // -----------------------------------------------------------------------
1075 BOOL StatusBar::IsItemVisible( USHORT nItemId ) const
1077 USHORT nPos = GetItemPos( nItemId );
1079 if ( nPos != STATUSBAR_ITEM_NOTFOUND )
1080 return mpItemList->GetObject( nPos )->mbVisible;
1081 else
1082 return FALSE;
1085 // -----------------------------------------------------------------------
1087 void StatusBar::ShowItems()
1089 if ( !mbVisibleItems )
1091 mbVisibleItems = TRUE;
1092 if ( !mbProgressMode )
1093 Invalidate();
1095 ImplCallEventListeners( VCLEVENT_STATUSBAR_SHOWALLITEMS );
1099 // -----------------------------------------------------------------------
1101 void StatusBar::HideItems()
1103 if ( mbVisibleItems )
1105 mbVisibleItems = FALSE;
1106 if ( !mbProgressMode )
1107 Invalidate();
1109 ImplCallEventListeners( VCLEVENT_STATUSBAR_HIDEALLITEMS );
1113 // -----------------------------------------------------------------------
1115 void StatusBar::CopyItems( const StatusBar& rStatusBar )
1117 // Alle Items entfernen
1118 ImplStatusItem* pItem = mpItemList->First();
1119 while ( pItem )
1121 delete pItem;
1122 pItem = mpItemList->Next();
1125 // Items aus der Liste loeschen
1126 mpItemList->Clear();
1128 // Items kopieren
1129 ULONG i = 0;
1130 pItem = rStatusBar.mpItemList->GetObject( i );
1131 while ( pItem )
1133 mpItemList->Insert( new ImplStatusItem( *pItem ), LIST_APPEND );
1134 i++;
1135 pItem = rStatusBar.mpItemList->GetObject( i );
1138 mbFormat = TRUE;
1139 if ( ImplIsItemUpdate() )
1140 Invalidate();
1143 // -----------------------------------------------------------------------
1145 void StatusBar::Clear()
1147 // Alle Item loeschen
1148 ImplStatusItem* pItem = mpItemList->First();
1149 while ( pItem )
1151 delete pItem;
1152 pItem = mpItemList->Next();
1155 // Items aus der Liste loeschen
1156 mpItemList->Clear();
1158 mbFormat = TRUE;
1159 if ( ImplIsItemUpdate() )
1160 Invalidate();
1162 ImplCallEventListeners( VCLEVENT_STATUSBAR_ALLITEMSREMOVED );
1165 // -----------------------------------------------------------------------
1167 USHORT StatusBar::GetItemCount() const
1169 return (USHORT)mpItemList->Count();
1172 // -----------------------------------------------------------------------
1174 USHORT StatusBar::GetItemId( USHORT nPos ) const
1176 ImplStatusItem* pItem = mpItemList->GetObject( nPos );
1177 if ( pItem )
1178 return pItem->mnId;
1179 else
1180 return 0;
1183 // -----------------------------------------------------------------------
1185 USHORT StatusBar::GetItemPos( USHORT nItemId ) const
1187 ImplStatusItem* pItem = mpItemList->First();
1188 while ( pItem )
1190 if ( pItem->mnId == nItemId )
1191 return (USHORT)mpItemList->GetCurPos();
1193 pItem = mpItemList->Next();
1196 return STATUSBAR_ITEM_NOTFOUND;
1199 // -----------------------------------------------------------------------
1201 USHORT StatusBar::GetItemId( const Point& rPos ) const
1203 if ( AreItemsVisible() && !mbFormat )
1205 USHORT nItemCount = GetItemCount();
1206 USHORT nPos;
1207 for ( nPos = 0; nPos < nItemCount; nPos++ )
1209 // Rechteck holen
1210 Rectangle aRect = ImplGetItemRectPos( nPos );
1211 if ( aRect.IsInside( rPos ) )
1212 return mpItemList->GetObject( nPos )->mnId;
1216 return 0;
1219 // -----------------------------------------------------------------------
1221 Rectangle StatusBar::GetItemRect( USHORT nItemId ) const
1223 Rectangle aRect;
1225 if ( AreItemsVisible() && !mbFormat )
1227 USHORT nPos = GetItemPos( nItemId );
1228 if ( nPos != STATUSBAR_ITEM_NOTFOUND )
1230 // Rechteck holen und Rahmen abziehen
1231 aRect = ImplGetItemRectPos( nPos );
1232 aRect.Left()++;
1233 aRect.Right()--;
1234 return aRect;
1238 return aRect;
1241 // -----------------------------------------------------------------------
1243 Point StatusBar::GetItemTextPos( USHORT nItemId ) const
1245 if ( !mbFormat )
1247 USHORT nPos = GetItemPos( nItemId );
1248 if ( nPos != STATUSBAR_ITEM_NOTFOUND )
1250 // Rechteck holen
1251 ImplStatusItem* pItem = mpItemList->GetObject( nPos );
1252 Rectangle aRect = ImplGetItemRectPos( nPos );
1253 Rectangle aTextRect( aRect.Left()+1, aRect.Top()+1,
1254 aRect.Right()-1, aRect.Bottom()-1 );
1255 Point aPos = ImplGetItemTextPos( aTextRect.GetSize(),
1256 Size( GetTextWidth( pItem->maText ), GetTextHeight() ),
1257 pItem->mnBits );
1258 if ( !mbInUserDraw )
1260 aPos.X() += aTextRect.Left();
1261 aPos.Y() += aTextRect.Top();
1263 return aPos;
1267 return Point();
1270 // -----------------------------------------------------------------------
1272 ULONG StatusBar::GetItemWidth( USHORT nItemId ) const
1274 USHORT nPos = GetItemPos( nItemId );
1276 if ( nPos != STATUSBAR_ITEM_NOTFOUND )
1277 return mpItemList->GetObject( nPos )->mnWidth;
1278 else
1279 return 0;
1282 // -----------------------------------------------------------------------
1284 StatusBarItemBits StatusBar::GetItemBits( USHORT nItemId ) const
1286 USHORT nPos = GetItemPos( nItemId );
1288 if ( nPos != STATUSBAR_ITEM_NOTFOUND )
1289 return mpItemList->GetObject( nPos )->mnBits;
1290 else
1291 return 0;
1294 // -----------------------------------------------------------------------
1296 long StatusBar::GetItemOffset( USHORT nItemId ) const
1298 USHORT nPos = GetItemPos( nItemId );
1300 if ( nPos != STATUSBAR_ITEM_NOTFOUND )
1301 return mpItemList->GetObject( nPos )->mnOffset;
1302 else
1303 return 0;
1306 // -----------------------------------------------------------------------
1308 void StatusBar::SetItemText( USHORT nItemId, const XubString& rText )
1310 USHORT nPos = GetItemPos( nItemId );
1312 if ( nPos != STATUSBAR_ITEM_NOTFOUND )
1314 ImplStatusItem* pItem = mpItemList->GetObject( nPos );
1316 if ( pItem->maText != rText )
1318 pItem->maText = rText;
1320 // adjust item width - see also DataChanged()
1321 long nFudge = GetTextHeight()/4;
1322 long nWidth = GetTextWidth( pItem->maText ) + nFudge;
1323 if( nWidth > pItem->mnWidth + STATUSBAR_OFFSET )
1324 pItem->mnWidth = nWidth + STATUSBAR_OFFSET;
1326 // Item neu Zeichen, wenn StatusBar sichtbar und
1327 // UpdateMode gesetzt ist
1328 if ( pItem->mbVisible && !mbFormat && ImplIsItemUpdate() )
1330 Update();
1331 ImplDrawItem( TRUE, nPos, TRUE, FALSE );
1332 Flush();
1338 // -----------------------------------------------------------------------
1340 const XubString& StatusBar::GetItemText( USHORT nItemId ) const
1342 USHORT nPos = GetItemPos( nItemId );
1344 if ( nPos != STATUSBAR_ITEM_NOTFOUND )
1345 return mpItemList->GetObject( nPos )->maText;
1346 else
1347 return ImplGetSVEmptyStr();
1350 // -----------------------------------------------------------------------
1352 void StatusBar::SetItemCommand( USHORT nItemId, const XubString& rCommand )
1354 USHORT nPos = GetItemPos( nItemId );
1356 if ( nPos != STATUSBAR_ITEM_NOTFOUND )
1358 ImplStatusItem* pItem = mpItemList->GetObject( nPos );
1360 if ( pItem->maCommand != rCommand )
1361 pItem->maCommand = rCommand;
1365 // -----------------------------------------------------------------------
1367 const XubString& StatusBar::GetItemCommand( USHORT nItemId )
1369 USHORT nPos = GetItemPos( nItemId );
1371 if ( nPos != STATUSBAR_ITEM_NOTFOUND )
1372 return mpItemList->GetObject( nPos )->maCommand;
1373 else
1374 return ImplGetSVEmptyStr();
1377 // -----------------------------------------------------------------------
1379 void StatusBar::SetItemData( USHORT nItemId, void* pNewData )
1381 USHORT nPos = GetItemPos( nItemId );
1383 if ( nPos != STATUSBAR_ITEM_NOTFOUND )
1385 ImplStatusItem* pItem = mpItemList->GetObject( nPos );
1386 pItem->mpUserData = pNewData;
1388 // Wenn es ein User-Item ist, DrawItem-Aufrufen
1389 if ( (pItem->mnBits & SIB_USERDRAW) && pItem->mbVisible &&
1390 !mbFormat && ImplIsItemUpdate() )
1392 Update();
1393 ImplDrawItem( TRUE, nPos, FALSE, FALSE );
1394 Flush();
1399 // -----------------------------------------------------------------------
1401 void* StatusBar::GetItemData( USHORT nItemId ) const
1403 USHORT nPos = GetItemPos( nItemId );
1405 if ( nPos != STATUSBAR_ITEM_NOTFOUND )
1406 return mpItemList->GetObject( nPos )->mpUserData;
1407 else
1408 return NULL;
1411 // -----------------------------------------------------------------------
1413 void StatusBar::SetHelpText( USHORT nItemId, const XubString& rText )
1415 USHORT nPos = GetItemPos( nItemId );
1417 if ( nPos != STATUSBAR_ITEM_NOTFOUND )
1418 mpItemList->GetObject( nPos )->maHelpText = rText;
1421 // -----------------------------------------------------------------------
1423 const XubString& StatusBar::GetHelpText( USHORT nItemId ) const
1425 USHORT nPos = GetItemPos( nItemId );
1427 if ( nPos != STATUSBAR_ITEM_NOTFOUND )
1429 ImplStatusItem* pItem = mpItemList->GetObject( nPos );
1430 if ( !pItem->maHelpText.Len() && ( pItem->mnHelpId || pItem->maCommand.Len() ))
1432 Help* pHelp = Application::GetHelp();
1433 if ( pHelp )
1435 if ( pItem->maCommand.Len() )
1436 pItem->maHelpText = pHelp->GetHelpText( pItem->maCommand, this );
1437 if ( !pItem->maHelpText.Len() && pItem->mnHelpId )
1438 pItem->maHelpText = pHelp->GetHelpText( pItem->mnHelpId, this );
1442 return pItem->maHelpText;
1444 else
1445 return ImplGetSVEmptyStr();
1448 // -----------------------------------------------------------------------
1450 void StatusBar::SetQuickHelpText( USHORT nItemId, const XubString& rText )
1452 USHORT nPos = GetItemPos( nItemId );
1454 if ( nPos != STATUSBAR_ITEM_NOTFOUND )
1455 mpItemList->GetObject( nPos )->maQuickHelpText = rText;
1458 // -----------------------------------------------------------------------
1460 const XubString& StatusBar::GetQuickHelpText( USHORT nItemId ) const
1462 USHORT nPos = GetItemPos( nItemId );
1464 if ( nPos != STATUSBAR_ITEM_NOTFOUND )
1466 ImplStatusItem* pItem = mpItemList->GetObject( nPos );
1467 return pItem->maQuickHelpText;
1469 else
1470 return ImplGetSVEmptyStr();
1473 // -----------------------------------------------------------------------
1475 void StatusBar::SetHelpId( USHORT nItemId, ULONG nHelpId )
1477 USHORT nPos = GetItemPos( nItemId );
1479 if ( nPos != STATUSBAR_ITEM_NOTFOUND )
1480 mpItemList->GetObject( nPos )->mnHelpId = nHelpId;
1483 // -----------------------------------------------------------------------
1485 ULONG StatusBar::GetHelpId( USHORT nItemId ) const
1487 USHORT nPos = GetItemPos( nItemId );
1489 if ( nPos != STATUSBAR_ITEM_NOTFOUND )
1490 return mpItemList->GetObject( nPos )->mnHelpId;
1491 else
1492 return 0;
1495 // -----------------------------------------------------------------------
1497 void StatusBar::ImplCalcBorder( )
1499 mnCalcHeight = mnDY;
1500 // subtract border
1501 if( IsTopBorder() )
1503 mnCalcHeight -= 2;
1504 mnTextY += 2;
1505 mnItemY += 2;
1507 if ( IsBottomBorder() )
1508 mnCalcHeight -= 2;
1509 mbFormat = TRUE;
1510 Invalidate();
1513 void StatusBar::SetBottomBorder( BOOL bBottomBorder )
1515 if ( mbBottomBorder != bBottomBorder )
1517 mbBottomBorder = bBottomBorder;
1518 ImplCalcBorder();
1522 void StatusBar::SetTopBorder( BOOL bTopBorder )
1524 if ( mpImplData->mbTopBorder != bTopBorder )
1526 mpImplData->mbTopBorder = bTopBorder;
1527 ImplCalcBorder();
1531 BOOL StatusBar::IsTopBorder() const
1533 return mpImplData->mbTopBorder;
1536 // -----------------------------------------------------------------------
1538 void StatusBar::StartProgressMode( const XubString& rText )
1540 DBG_ASSERT( !mbProgressMode, "StatusBar::StartProgressMode(): progress mode is active" );
1542 mbProgressMode = TRUE;
1543 mnPercent = 0;
1544 maPrgsTxt = rText;
1546 // Groessen berechnen
1547 ImplCalcProgressRect();
1549 // Paint ausloesen (dort wird der Text und der Frame gemalt)
1550 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
1551 Color aPrgsColor = rStyleSettings.GetHighlightColor();
1552 if ( aPrgsColor == rStyleSettings.GetFaceColor() )
1553 aPrgsColor = rStyleSettings.GetDarkShadowColor();
1554 SetLineColor();
1555 SetFillColor( aPrgsColor );
1556 if ( IsReallyVisible() )
1558 Invalidate();
1559 Update();
1560 Flush();
1564 // -----------------------------------------------------------------------
1566 void StatusBar::SetProgressValue( USHORT nNewPercent )
1568 DBG_ASSERT( mbProgressMode, "StatusBar::SetProgressValue(): no progrss mode" );
1569 DBG_ASSERTWARNING( nNewPercent <= 100, "StatusBar::SetProgressValue(): nPercent > 100" );
1571 if ( mbProgressMode
1572 && IsReallyVisible()
1573 && (!mnPercent || (mnPercent != nNewPercent)) )
1575 Update();
1576 SetLineColor();
1577 ImplDrawProgress( FALSE, mnPercent, nNewPercent );
1578 Flush();
1580 mnPercent = nNewPercent;
1583 // -----------------------------------------------------------------------
1585 void StatusBar::EndProgressMode()
1587 DBG_ASSERT( mbProgressMode, "StatusBar::EndProgressMode(): no progress mode" );
1589 mbProgressMode = FALSE;
1590 maPrgsTxt.Erase();
1592 // Paint neu ausloesen um StatusBar wieder herzustellen
1593 SetFillColor( GetSettings().GetStyleSettings().GetFaceColor() );
1594 if ( IsReallyVisible() )
1596 Invalidate();
1597 Update();
1598 Flush();
1602 // -----------------------------------------------------------------------
1604 void StatusBar::ResetProgressMode()
1606 if ( mbProgressMode )
1608 mnPercent = 0;
1609 maPrgsTxt.Erase();
1610 if ( IsReallyVisible() )
1612 Invalidate();
1613 Update();
1614 Flush();
1619 // -----------------------------------------------------------------------
1621 void StatusBar::SetText( const XubString& rText )
1623 if ( (!mbVisibleItems || (GetStyle() & WB_RIGHT)) && !mbProgressMode &&
1624 IsReallyVisible() && IsUpdateMode() )
1626 if ( mbFormat )
1628 Invalidate();
1629 Window::SetText( rText );
1631 else
1633 Update();
1634 long nOldTextWidth = GetTextWidth( GetText() );
1635 Window::SetText( rText );
1636 ImplDrawText( TRUE, nOldTextWidth );
1637 Flush();
1640 else if ( mbProgressMode )
1642 maPrgsTxt = rText;
1643 if ( IsReallyVisible() )
1645 Invalidate();
1646 Update();
1647 Flush();
1650 else
1651 Window::SetText( rText );
1654 // -----------------------------------------------------------------------
1656 Size StatusBar::CalcWindowSizePixel() const
1658 ULONG i = 0;
1659 ULONG nCount = mpItemList->Count();
1660 long nOffset = 0;
1661 long nCalcWidth = (STATUSBAR_OFFSET_X*2);
1662 long nCalcHeight;
1664 while ( i < nCount )
1666 ImplStatusItem* pItem = mpItemList->GetObject( i );
1667 nCalcWidth += pItem->mnWidth + nOffset;
1668 nOffset = pItem->mnOffset;
1669 i++;
1672 long nMinHeight = GetTextHeight();
1673 const long nBarTextOffset = STATUSBAR_OFFSET_TEXTY*2;
1674 long nProgressHeight = nMinHeight + nBarTextOffset;
1675 // FIXME: IsNativeControlSupported and GetNativeControlRegion should be const ?
1676 StatusBar* pThis = const_cast<StatusBar*>( this );
1677 if( pThis->IsNativeControlSupported( CTRL_PROGRESS, PART_ENTIRE_CONTROL ) )
1679 ImplControlValue aValue;
1680 Region aControlRegion( Rectangle( (const Point&)Point(), Size( nCalcWidth, nMinHeight ) ) );
1681 Region aNativeControlRegion, aNativeContentRegion;
1682 if( pThis->GetNativeControlRegion( CTRL_PROGRESS, PART_ENTIRE_CONTROL, aControlRegion,
1683 CTRL_STATE_ENABLED, aValue, rtl::OUString(),
1684 aNativeControlRegion, aNativeContentRegion ) )
1686 nProgressHeight = aNativeControlRegion.GetBoundRect().GetHeight();
1690 nCalcHeight = nMinHeight+nBarTextOffset;
1691 if( nCalcHeight < nProgressHeight+2 )
1692 nCalcHeight = nProgressHeight+2;
1694 // add border
1695 if( IsTopBorder() )
1696 nCalcHeight += 2;
1697 if ( IsBottomBorder() )
1698 nCalcHeight += 2;
1700 return Size( nCalcWidth, nCalcHeight );
1704 // -----------------------------------------------------------------------
1706 void StatusBar::SetAccessibleName( USHORT nItemId, const XubString& rName )
1708 USHORT nPos = GetItemPos( nItemId );
1710 if ( nPos != STATUSBAR_ITEM_NOTFOUND )
1712 ImplStatusItem* pItem = mpItemList->GetObject( nPos );
1714 if ( pItem->maAccessibleName != rName )
1716 pItem->maAccessibleName = rName;
1717 ImplCallEventListeners( VCLEVENT_STATUSBAR_NAMECHANGED, (void*) sal_IntPtr(pItem->mnId) );
1722 // -----------------------------------------------------------------------
1724 const XubString& StatusBar::GetAccessibleName( USHORT nItemId ) const
1726 USHORT nPos = GetItemPos( nItemId );
1728 if ( nPos != STATUSBAR_ITEM_NOTFOUND )
1729 return mpItemList->GetObject( nPos )->maAccessibleName;
1730 else
1731 return ImplGetSVEmptyStr();
1734 // -----------------------------------------------------------------------