Version 4.2.0.1, tag libreoffice-4.2.0.1
[LibreOffice.git] / vcl / source / window / status.cxx
blobdd35e90d29f7d7a3e96d15f583d016a6b2167b59
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 .
21 #include <tools/debug.hxx>
22 #include <tools/rc.h>
24 #include <vcl/event.hxx>
25 #include <vcl/decoview.hxx>
26 #include <vcl/svapp.hxx>
27 #include <vcl/help.hxx>
28 #include <vcl/status.hxx>
29 #include <vcl/virdev.hxx>
31 #include <svdata.hxx>
32 #include <window.h>
34 // =======================================================================
36 #define STATUSBAR_OFFSET_X STATUSBAR_OFFSET
37 #define STATUSBAR_OFFSET_Y 2
38 #define STATUSBAR_OFFSET_TEXTY 3
40 #define STATUSBAR_PRGS_OFFSET 3
41 #define STATUSBAR_PRGS_COUNT 100
42 #define STATUSBAR_PRGS_MIN 5
44 // -----------------------------------------------------------------------
46 class StatusBar::ImplData
48 public:
49 ImplData();
50 ~ImplData();
52 VirtualDevice* mpVirDev;
53 long mnItemBorderWidth;
54 bool mbDrawItemFrames:1;
57 StatusBar::ImplData::ImplData()
59 mpVirDev = NULL;
60 mbDrawItemFrames = false;
61 mnItemBorderWidth = 0;
64 StatusBar::ImplData::~ImplData()
68 struct ImplStatusItem
70 sal_uInt16 mnId;
71 StatusBarItemBits mnBits;
72 long mnWidth;
73 long mnOffset;
74 long mnExtraWidth;
75 long mnX;
76 OUString maText;
77 OUString maHelpText;
78 OUString maQuickHelpText;
79 OString maHelpId;
80 void* mpUserData;
81 sal_Bool mbVisible;
82 OUString maAccessibleName;
83 OUString maCommand;
86 // =======================================================================
88 inline long ImplCalcProgessWidth( sal_uInt16 nMax, long nSize )
90 return ((nMax*(nSize+(nSize/2)))-(nSize/2)+(STATUSBAR_PRGS_OFFSET*2));
93 // -----------------------------------------------------------------------
95 static Point ImplGetItemTextPos( const Size& rRectSize, const Size& rTextSize,
96 sal_uInt16 nStyle )
98 long nX;
99 long nY;
100 long delta = (rTextSize.Height()/4) + 1;
101 if( delta + rTextSize.Width() > rRectSize.Width() )
102 delta = 0;
104 if ( nStyle & SIB_LEFT )
105 nX = delta;
106 else if ( nStyle & SIB_RIGHT )
107 nX = rRectSize.Width()-rTextSize.Width()-delta;
108 else // SIB_CENTER
109 nX = (rRectSize.Width()-rTextSize.Width())/2;
110 nY = (rRectSize.Height()-rTextSize.Height())/2 + 1;
111 return Point( nX, nY );
114 // -----------------------------------------------------------------------
116 sal_Bool StatusBar::ImplIsItemUpdate()
118 if ( !mbProgressMode && mbVisibleItems && IsReallyVisible() && IsUpdateMode() )
119 return sal_True;
120 else
121 return sal_False;
124 // -----------------------------------------------------------------------
126 void StatusBar::ImplInit( Window* pParent, WinBits nStyle )
128 mpImplData = new ImplData;
130 // Default ist RightAlign
131 if ( !(nStyle & (WB_LEFT | WB_RIGHT)) )
132 nStyle |= WB_RIGHT;
134 Window::ImplInit( pParent, nStyle & ~WB_BORDER, NULL );
136 // WinBits merken
137 mpItemList = new ImplStatusItemList;
138 mpImplData->mpVirDev = new VirtualDevice( *this );
139 mnCurItemId = 0;
140 mbFormat = sal_True;
141 mbVisibleItems = sal_True;
142 mbProgressMode = sal_False;
143 mbInUserDraw = sal_False;
144 mnItemsWidth = STATUSBAR_OFFSET_X;
145 mnDX = 0;
146 mnDY = 0;
147 mnCalcHeight = 0;
148 mnItemY = STATUSBAR_OFFSET_Y;
149 mnTextY = STATUSBAR_OFFSET_TEXTY;
151 ImplInitSettings( sal_True, sal_True, sal_True );
152 SetLineColor();
154 SetOutputSizePixel( CalcWindowSizePixel() );
157 // -----------------------------------------------------------------------
159 StatusBar::StatusBar( Window* pParent, WinBits nStyle ) :
160 Window( WINDOW_STATUSBAR )
162 ImplInit( pParent, nStyle );
165 // -----------------------------------------------------------------------
167 StatusBar::~StatusBar()
169 // Alle Items loeschen
170 for ( size_t i = 0, n = mpItemList->size(); i < n; ++i ) {
171 delete (*mpItemList)[ i ];
173 delete mpItemList;
175 // VirtualDevice loeschen
176 delete mpImplData->mpVirDev;
177 delete mpImplData;
180 // -----------------------------------------------------------------------
182 void StatusBar::ImplInitSettings( sal_Bool bFont,
183 sal_Bool bForeground, sal_Bool bBackground )
185 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
187 if ( bFont )
189 Font aFont = rStyleSettings.GetToolFont();
190 if ( IsControlFont() )
191 aFont.Merge( GetControlFont() );
192 SetZoomedPointFont( aFont );
195 if ( bForeground || bFont )
197 Color aColor;
198 if ( IsControlForeground() )
199 aColor = GetControlForeground();
200 else if ( GetStyle() & WB_3DLOOK )
201 aColor = rStyleSettings.GetButtonTextColor();
202 else
203 aColor = rStyleSettings.GetWindowTextColor();
204 SetTextColor( aColor );
205 SetTextFillColor();
207 mpImplData->mpVirDev->SetFont( GetFont() );
208 mpImplData->mpVirDev->SetTextColor( GetTextColor() );
209 mpImplData->mpVirDev->SetTextAlign( GetTextAlign() );
210 mpImplData->mpVirDev->SetTextFillColor();
213 if ( bBackground )
215 Color aColor;
216 if ( IsControlBackground() )
217 aColor = GetControlBackground();
218 else if ( GetStyle() & WB_3DLOOK )
219 aColor = rStyleSettings.GetFaceColor();
220 else
221 aColor = rStyleSettings.GetWindowColor();
222 SetBackground( aColor );
223 mpImplData->mpVirDev->SetBackground( GetBackground() );
225 // NWF background
226 if( ! IsControlBackground() &&
227 IsNativeControlSupported( CTRL_WINDOW_BACKGROUND, PART_BACKGROUND_WINDOW ) )
229 ImplGetWindowImpl()->mnNativeBackground = PART_BACKGROUND_WINDOW;
230 EnableChildTransparentMode( sal_True );
235 // -----------------------------------------------------------------------
237 void StatusBar::ImplFormat()
239 ImplStatusItem* pItem;
240 long nExtraWidth;
241 long nExtraWidth2;
242 long nX;
243 sal_uInt16 nAutoSizeItems = 0;
245 // Breiten zusammenrechnen
246 mnItemsWidth = STATUSBAR_OFFSET_X;
247 long nOffset = 0;
248 for ( size_t i = 0, n = mpItemList->size(); i < n; ++i ) {
249 pItem = (*mpItemList)[ i ];
250 if ( pItem->mbVisible )
252 if ( pItem->mnBits & SIB_AUTOSIZE ) {
253 nAutoSizeItems++;
256 mnItemsWidth += pItem->mnWidth + nOffset;
257 nOffset = pItem->mnOffset;
261 if ( GetStyle() & WB_RIGHT )
263 // Bei rechtsbuendiger Ausrichtung wird kein AutoSize ausgewertet,
264 // da wir links den Text anzeigen, der mit SetText gesetzt wird
265 nX = mnDX - mnItemsWidth;
266 nExtraWidth = 0;
267 nExtraWidth2 = 0;
269 else
271 mnItemsWidth += STATUSBAR_OFFSET_X;
273 // Bei linksbuendiger Ausrichtung muessen wir gegebenenfalls noch
274 // AutoSize auswerten
275 if ( nAutoSizeItems && (mnDX > (mnItemsWidth - STATUSBAR_OFFSET)) )
277 nExtraWidth = (mnDX - mnItemsWidth - 1) / nAutoSizeItems;
278 nExtraWidth2 = (mnDX - mnItemsWidth - 1) % nAutoSizeItems;
280 else
282 nExtraWidth = 0;
283 nExtraWidth2 = 0;
285 nX = STATUSBAR_OFFSET_X;
286 if( ImplHasMirroredGraphics() && IsRTLEnabled() )
287 nX += ImplGetSVData()->maNWFData.mnStatusBarLowerRightOffset;
290 for ( size_t i = 0, n = mpItemList->size(); i < n; ++i ) {
291 pItem = (*mpItemList)[ i ];
292 if ( pItem->mbVisible ) {
293 if ( pItem->mnBits & SIB_AUTOSIZE ) {
294 pItem->mnExtraWidth = nExtraWidth;
295 if ( nExtraWidth2 ) {
296 pItem->mnExtraWidth++;
297 nExtraWidth2--;
299 } else {
300 pItem->mnExtraWidth = 0;
303 pItem->mnX = nX;
304 nX += pItem->mnWidth + pItem->mnExtraWidth + pItem->mnOffset;
308 mbFormat = sal_False;
311 // -----------------------------------------------------------------------
313 Rectangle StatusBar::ImplGetItemRectPos( sal_uInt16 nPos ) const
315 Rectangle aRect;
316 ImplStatusItem* pItem;
317 pItem = ( nPos < mpItemList->size() ) ? (*mpItemList)[ nPos ] : NULL;
318 if ( pItem )
320 if ( pItem->mbVisible )
322 aRect.Left() = pItem->mnX;
323 aRect.Right() = aRect.Left() + pItem->mnWidth + pItem->mnExtraWidth;
324 aRect.Top() = mnItemY;
325 aRect.Bottom() = mnCalcHeight - STATUSBAR_OFFSET_Y;
329 return aRect;
332 // -----------------------------------------------------------------------
334 sal_uInt16 StatusBar::ImplGetFirstVisiblePos() const
336 ImplStatusItem* pItem;
338 for( size_t nPos = 0; nPos < mpItemList->size(); nPos++ )
340 pItem = (*mpItemList)[ nPos ];
341 if ( pItem )
343 if ( pItem->mbVisible )
344 return sal_uInt16(nPos);
348 return ~0;
351 // -----------------------------------------------------------------------
353 void StatusBar::ImplDrawText( sal_Bool bOffScreen, long nOldTextWidth )
355 // Das ueberschreiben der Item-Box verhindern
356 Rectangle aTextRect;
357 aTextRect.Left() = STATUSBAR_OFFSET_X+1;
358 aTextRect.Top() = mnTextY;
359 if ( mbVisibleItems && (GetStyle() & WB_RIGHT) )
360 aTextRect.Right() = mnDX - mnItemsWidth - 1;
361 else
362 aTextRect.Right() = mnDX - 1;
363 if ( aTextRect.Right() > aTextRect.Left() )
365 // Position ermitteln
366 OUString aStr = GetText();
367 sal_Int32 nPos = aStr.indexOf('\n');
368 if (nPos != -1)
369 aStr = aStr.copy(0, nPos);
371 aTextRect.Bottom() = aTextRect.Top()+GetTextHeight()+1;
373 if ( bOffScreen )
375 long nMaxWidth = std::max( nOldTextWidth, GetTextWidth( aStr ) );
376 Size aVirDevSize( nMaxWidth, aTextRect.GetHeight() );
377 mpImplData->mpVirDev->SetOutputSizePixel( aVirDevSize );
378 Rectangle aTempRect = aTextRect;
379 aTempRect.SetPos( Point( 0, 0 ) );
380 mpImplData->mpVirDev->DrawText( aTempRect, aStr, TEXT_DRAW_LEFT | TEXT_DRAW_TOP | TEXT_DRAW_CLIP | TEXT_DRAW_ENDELLIPSIS );
381 DrawOutDev( aTextRect.TopLeft(), aVirDevSize, Point(), aVirDevSize, *mpImplData->mpVirDev );
383 else
384 DrawText( aTextRect, aStr, TEXT_DRAW_LEFT | TEXT_DRAW_TOP | TEXT_DRAW_CLIP | TEXT_DRAW_ENDELLIPSIS );
388 // -----------------------------------------------------------------------
390 void StatusBar::ImplDrawItem( sal_Bool bOffScreen, sal_uInt16 nPos, sal_Bool bDrawText, sal_Bool bDrawFrame )
392 Rectangle aRect = ImplGetItemRectPos( nPos );
394 if ( aRect.IsEmpty() )
395 return;
397 // Ausgabebereich berechnen
398 ImplStatusItem* pItem = (*mpItemList)[ nPos ];
399 long nW = mpImplData->mnItemBorderWidth + 1;
400 Rectangle aTextRect( aRect.Left()+nW, aRect.Top()+nW,
401 aRect.Right()-nW, aRect.Bottom()-nW );
402 Size aTextRectSize( aTextRect.GetSize() );
404 if ( bOffScreen )
405 mpImplData->mpVirDev->SetOutputSizePixel( aTextRectSize );
406 else
408 Region aRegion( aTextRect );
409 SetClipRegion( aRegion );
412 // Text ausgeben
413 if ( bDrawText )
415 Size aTextSize( GetTextWidth( pItem->maText ), GetTextHeight() );
416 Point aTextPos = ImplGetItemTextPos( aTextRectSize, aTextSize, pItem->mnBits );
417 if ( bOffScreen )
418 mpImplData->mpVirDev->DrawText( aTextPos, pItem->maText );
419 else
421 aTextPos.X() += aTextRect.Left();
422 aTextPos.Y() += aTextRect.Top();
423 DrawText( aTextPos, pItem->maText );
427 // Gegebenenfalls auch DrawItem aufrufen
428 if ( pItem->mnBits & SIB_USERDRAW )
430 if ( bOffScreen )
432 mbInUserDraw = sal_True;
433 mpImplData->mpVirDev->EnableRTL( IsRTLEnabled() );
434 UserDrawEvent aODEvt( mpImplData->mpVirDev, Rectangle( Point(), aTextRectSize ), pItem->mnId );
435 UserDraw( aODEvt );
436 mpImplData->mpVirDev->EnableRTL( sal_False );
437 mbInUserDraw = sal_False;
439 else
441 UserDrawEvent aODEvt( this, aTextRect, pItem->mnId );
442 UserDraw( aODEvt );
446 if ( bOffScreen )
447 DrawOutDev( aTextRect.TopLeft(), aTextRectSize, Point(), aTextRectSize, *mpImplData->mpVirDev );
448 else
449 SetClipRegion();
451 // Frame ausgeben
452 if ( bDrawFrame )
454 if( mpImplData->mbDrawItemFrames )
456 if( !(pItem->mnBits & SIB_FLAT) )
458 sal_uInt16 nStyle;
460 if ( pItem->mnBits & SIB_IN )
461 nStyle = FRAME_DRAW_IN;
462 else
463 nStyle = FRAME_DRAW_OUT;
465 DecorationView aDecoView( this );
466 aDecoView.DrawFrame( aRect, nStyle );
469 else if( nPos != ImplGetFirstVisiblePos() )
471 // draw separator
472 Point aFrom( aRect.TopLeft() );
473 aFrom.X()-=4;
474 aFrom.Y()++;
475 Point aTo( aRect.BottomLeft() );
476 aTo.X()-=4;
477 aTo.Y()--;
479 DecorationView aDecoView( this );
480 aDecoView.DrawSeparator( aFrom, aTo );
484 if ( !ImplIsRecordLayout() )
485 ImplCallEventListeners( VCLEVENT_STATUSBAR_DRAWITEM, (void*) sal_IntPtr(pItem->mnId) );
488 // -----------------------------------------------------------------------
490 void DrawProgress( Window* pWindow, const Point& rPos,
491 long nOffset, long nPrgsWidth, long nPrgsHeight,
492 sal_uInt16 nPercent1, sal_uInt16 nPercent2, sal_uInt16 nPercentCount,
493 const Rectangle& rFramePosSize
496 if( pWindow->IsNativeControlSupported( CTRL_PROGRESS, PART_ENTIRE_CONTROL ) )
498 bool bNeedErase = ImplGetSVData()->maNWFData.mbProgressNeedsErase;
500 long nFullWidth = (nPrgsWidth + nOffset) * (10000 / nPercentCount);
501 long nPerc = (nPercent2 > 10000) ? 10000 : nPercent2;
502 ImplControlValue aValue( nFullWidth * (long)nPerc / 10000 );
503 Rectangle aDrawRect( rPos, Size( nFullWidth, nPrgsHeight ) );
504 Rectangle aControlRegion( aDrawRect );
505 if( bNeedErase )
507 Window* pEraseWindow = pWindow;
508 while( pEraseWindow->IsPaintTransparent() &&
509 ! pEraseWindow->ImplGetWindowImpl()->mbFrame )
511 pEraseWindow = pEraseWindow->ImplGetWindowImpl()->mpParent;
513 if( pEraseWindow == pWindow )
514 // restore background of pWindow
515 pEraseWindow->Erase( rFramePosSize );
516 else
518 // restore transparent background
519 Point aTL( pWindow->OutputToAbsoluteScreenPixel( rFramePosSize.TopLeft() ) );
520 aTL = pEraseWindow->AbsoluteScreenToOutputPixel( aTL );
521 Rectangle aRect( aTL, rFramePosSize.GetSize() );
522 pEraseWindow->Invalidate( aRect, INVALIDATE_NOCHILDREN |
523 INVALIDATE_NOCLIPCHILDREN |
524 INVALIDATE_TRANSPARENT );
525 pEraseWindow->Update();
527 pWindow->Push( PUSH_CLIPREGION );
528 pWindow->IntersectClipRegion( rFramePosSize );
530 sal_Bool bNativeOK = pWindow->DrawNativeControl( CTRL_PROGRESS, PART_ENTIRE_CONTROL, aControlRegion,
531 CTRL_STATE_ENABLED, aValue, OUString() );
532 if( bNeedErase )
533 pWindow->Pop();
534 if( bNativeOK )
536 pWindow->Flush();
537 return;
541 // Werte vorberechnen
542 sal_uInt16 nPerc1 = nPercent1 / nPercentCount;
543 sal_uInt16 nPerc2 = nPercent2 / nPercentCount;
545 if ( nPerc1 > nPerc2 )
547 // Support progress that can also decrease
549 // Rechteck berechnen
550 long nDX = nPrgsWidth + nOffset;
551 long nLeft = rPos.X()+((nPerc1-1)*nDX);
552 Rectangle aRect( nLeft, rPos.Y(), nLeft+nPrgsWidth, rPos.Y()+nPrgsHeight );
556 pWindow->Erase( aRect );
557 aRect.Left() -= nDX;
558 aRect.Right() -= nDX;
559 nPerc1--;
561 while ( nPerc1 > nPerc2 );
563 pWindow->Flush();
565 else if ( nPerc1 < nPerc2 )
567 // Percent-Rechtecke malen
568 // Wenn Percent2 ueber 100%, Werte anpassen
569 if ( nPercent2 > 10000 )
571 nPerc2 = 10000 / nPercentCount;
572 if ( nPerc1 >= nPerc2 )
573 nPerc1 = nPerc2-1;
576 // Rechteck berechnen
577 long nDX = nPrgsWidth + nOffset;
578 long nLeft = rPos.X()+(nPerc1*nDX);
579 Rectangle aRect( nLeft, rPos.Y(), nLeft+nPrgsWidth, rPos.Y()+nPrgsHeight );
583 pWindow->DrawRect( aRect );
584 aRect.Left() += nDX;
585 aRect.Right() += nDX;
586 nPerc1++;
588 while ( nPerc1 < nPerc2 );
590 // Bei mehr als 100%, lassen wir das Rechteck blinken
591 if ( nPercent2 > 10000 )
593 // an/aus-Status festlegen
594 if ( ((nPercent2 / nPercentCount) & 0x01) == (nPercentCount & 0x01) )
596 aRect.Left() -= nDX;
597 aRect.Right() -= nDX;
598 pWindow->Erase( aRect );
602 pWindow->Flush();
606 // -----------------------------------------------------------------------
608 void StatusBar::ImplDrawProgress( sal_Bool bPaint,
609 sal_uInt16 nPercent1, sal_uInt16 nPercent2 )
611 bool bNative = IsNativeControlSupported( CTRL_PROGRESS, PART_ENTIRE_CONTROL );
612 // bPaint: draw text also, else only update progress
613 if ( bPaint )
615 DrawText( maPrgsTxtPos, maPrgsTxt );
616 if( ! bNative )
618 DecorationView aDecoView( this );
619 aDecoView.DrawFrame( maPrgsFrameRect, FRAME_DRAW_IN );
623 Point aPos( maPrgsFrameRect.Left()+STATUSBAR_PRGS_OFFSET,
624 maPrgsFrameRect.Top()+STATUSBAR_PRGS_OFFSET );
625 long nPrgsHeight = mnPrgsSize;
626 if( bNative )
628 aPos = maPrgsFrameRect.TopLeft();
629 nPrgsHeight = maPrgsFrameRect.GetHeight();
631 DrawProgress( this, aPos, mnPrgsSize/2, mnPrgsSize, nPrgsHeight,
632 nPercent1*100, nPercent2*100, mnPercentCount, maPrgsFrameRect );
635 // -----------------------------------------------------------------------
637 void StatusBar::ImplCalcProgressRect()
639 // calculate text size
640 Size aPrgsTxtSize( GetTextWidth( maPrgsTxt ), GetTextHeight() );
641 maPrgsTxtPos.X() = STATUSBAR_OFFSET_X+1;
643 // calculate progress frame
644 maPrgsFrameRect.Left() = maPrgsTxtPos.X()+aPrgsTxtSize.Width()+STATUSBAR_OFFSET;
645 maPrgsFrameRect.Top() = mnItemY;
646 maPrgsFrameRect.Bottom() = mnCalcHeight - STATUSBAR_OFFSET_Y;
648 // calculate size of progress rects
649 mnPrgsSize = maPrgsFrameRect.Bottom()-maPrgsFrameRect.Top()-(STATUSBAR_PRGS_OFFSET*2);
650 sal_uInt16 nMaxPercent = STATUSBAR_PRGS_COUNT;
652 long nMaxWidth = mnDX-STATUSBAR_OFFSET-1;
654 // make smaller if there are too many rects
655 while ( maPrgsFrameRect.Left()+ImplCalcProgessWidth( nMaxPercent, mnPrgsSize ) > nMaxWidth )
657 nMaxPercent--;
658 if ( nMaxPercent <= STATUSBAR_PRGS_MIN )
659 break;
661 maPrgsFrameRect.Right() = maPrgsFrameRect.Left() + ImplCalcProgessWidth( nMaxPercent, mnPrgsSize );
663 // save the divisor for later
664 mnPercentCount = 10000 / nMaxPercent;
665 sal_Bool bNativeOK = sal_False;
666 if( IsNativeControlSupported( CTRL_PROGRESS, PART_ENTIRE_CONTROL ) )
668 ImplControlValue aValue;
669 Rectangle aControlRegion( Rectangle( (const Point&)Point(), maPrgsFrameRect.GetSize() ) );
670 Rectangle aNativeControlRegion, aNativeContentRegion;
671 if( (bNativeOK = GetNativeControlRegion( CTRL_PROGRESS, PART_ENTIRE_CONTROL, aControlRegion,
672 CTRL_STATE_ENABLED, aValue, OUString(),
673 aNativeControlRegion, aNativeContentRegion ) ) != sal_False )
675 long nProgressHeight = aNativeControlRegion.GetHeight();
676 if( nProgressHeight > maPrgsFrameRect.GetHeight() )
678 long nDelta = nProgressHeight - maPrgsFrameRect.GetHeight();
679 maPrgsFrameRect.Top() -= (nDelta - nDelta/2);
680 maPrgsFrameRect.Bottom() += nDelta/2;
682 maPrgsTxtPos.Y() = maPrgsFrameRect.Top() + (nProgressHeight - GetTextHeight())/2;
685 if( ! bNativeOK )
686 maPrgsTxtPos.Y() = mnTextY;
689 // -----------------------------------------------------------------------
691 void StatusBar::MouseButtonDown( const MouseEvent& rMEvt )
693 // Nur bei linker Maustaste ToolBox ausloesen
694 if ( rMEvt.IsLeft() )
696 if ( mbVisibleItems )
698 Point aMousePos = rMEvt.GetPosPixel();
700 // Item suchen, das geklickt wurde
701 for ( size_t i = 0; i < mpItemList->size(); ++i )
703 ImplStatusItem* pItem = (*mpItemList)[ i ];
704 // Ist es dieses Item
705 if ( ImplGetItemRectPos( sal_uInt16(i) ).IsInside( aMousePos ) )
707 mnCurItemId = pItem->mnId;
708 if ( rMEvt.GetClicks() == 2 )
709 DoubleClick();
710 else
711 Click();
712 mnCurItemId = 0;
714 // Item wurde gefunden
715 return;
720 // Kein Item, dann nur Click oder DoubleClick
721 if ( rMEvt.GetClicks() == 2 )
722 DoubleClick();
723 else
724 Click();
728 // -----------------------------------------------------------------------
730 void StatusBar::Paint( const Rectangle& )
732 if ( mbFormat )
733 ImplFormat();
735 sal_uInt16 nItemCount = sal_uInt16( mpItemList->size() );
737 if ( mbProgressMode )
738 ImplDrawProgress( sal_True, 0, mnPercent );
739 else
741 // Text zeichen
742 if ( !mbVisibleItems || (GetStyle() & WB_RIGHT) )
743 ImplDrawText( sal_False, 0 );
745 // Items zeichnen
746 if ( mbVisibleItems )
748 // Items zeichnen
749 for ( sal_uInt16 i = 0; i < nItemCount; i++ )
750 ImplDrawItem( sal_False, i, sal_True, sal_True );
754 // draw line at the top of the status bar (to visually distinguish it from
755 // shell / docking area)
756 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
757 SetLineColor( rStyleSettings.GetShadowColor() );
758 DrawLine( Point( 0, 0 ), Point( mnDX-1, 0 ) );
761 // -----------------------------------------------------------------------
763 void StatusBar::Move()
765 Window::Move();
768 // -----------------------------------------------------------------------
770 void StatusBar::Resize()
772 // Breite und Hoehe abfragen und merken
773 Size aSize = GetOutputSizePixel();
774 mnDX = aSize.Width() - ImplGetSVData()->maNWFData.mnStatusBarLowerRightOffset;
775 mnDY = aSize.Height();
776 mnCalcHeight = mnDY;
778 mnItemY = STATUSBAR_OFFSET_Y;
779 mnTextY = (mnCalcHeight-GetTextHeight())/2;
781 // Formatierung neu ausloesen
782 mbFormat = sal_True;
784 if ( mbProgressMode )
785 ImplCalcProgressRect();
787 Invalidate();
790 // -----------------------------------------------------------------------
792 void StatusBar::RequestHelp( const HelpEvent& rHEvt )
794 // no keyboard help in status bar
795 if( rHEvt.KeyboardActivated() )
796 return;
798 sal_uInt16 nItemId = GetItemId( ScreenToOutputPixel( rHEvt.GetMousePosPixel() ) );
800 if ( nItemId )
802 Rectangle aItemRect = GetItemRect( nItemId );
803 Point aPt = OutputToScreenPixel( aItemRect.TopLeft() );
804 aItemRect.Left() = aPt.X();
805 aItemRect.Top() = aPt.Y();
806 aPt = OutputToScreenPixel( aItemRect.BottomRight() );
807 aItemRect.Right() = aPt.X();
808 aItemRect.Bottom() = aPt.Y();
810 if ( rHEvt.GetMode() & HELPMODE_BALLOON )
812 OUString aStr = GetHelpText( nItemId );
813 Help::ShowBalloon( this, aItemRect.Center(), aItemRect, aStr );
814 return;
816 else if ( rHEvt.GetMode() & HELPMODE_QUICK )
818 OUString aStr(GetQuickHelpText(nItemId));
819 // Show quickhelp if available
820 if (!aStr.isEmpty())
822 Help::ShowQuickHelp( this, aItemRect, aStr );
823 return;
825 aStr = GetItemText( nItemId );
826 // show a quick help if item text doesn't fit
827 if ( GetTextWidth( aStr ) > aItemRect.GetWidth() )
829 Help::ShowQuickHelp( this, aItemRect, aStr );
830 return;
833 else if ( rHEvt.GetMode() & HELPMODE_EXTENDED )
835 OUString aCommand = GetItemCommand( nItemId );
836 OString aHelpId( GetHelpId( nItemId ) );
838 if ( !aCommand.isEmpty() || !aHelpId.isEmpty() )
840 // Wenn eine Hilfe existiert, dann ausloesen
841 Help* pHelp = Application::GetHelp();
842 if ( pHelp )
844 if ( !aCommand.isEmpty() )
845 pHelp->Start( aCommand, this );
846 else if ( !aHelpId.isEmpty() )
847 pHelp->Start( OStringToOUString( aHelpId, RTL_TEXTENCODING_UTF8 ), this );
849 return;
854 Window::RequestHelp( rHEvt );
857 // -----------------------------------------------------------------------
859 void StatusBar::StateChanged( StateChangedType nType )
861 Window::StateChanged( nType );
863 if ( nType == STATE_CHANGE_INITSHOW )
864 ImplFormat();
865 else if ( nType == STATE_CHANGE_UPDATEMODE )
866 Invalidate();
867 else if ( (nType == STATE_CHANGE_ZOOM) ||
868 (nType == STATE_CHANGE_CONTROLFONT) )
870 mbFormat = sal_True;
871 ImplInitSettings( sal_True, sal_False, sal_False );
872 Invalidate();
874 else if ( nType == STATE_CHANGE_CONTROLFOREGROUND )
876 ImplInitSettings( sal_False, sal_True, sal_False );
877 Invalidate();
879 else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
881 ImplInitSettings( sal_False, sal_False, sal_True );
882 Invalidate();
886 // -----------------------------------------------------------------------
888 void StatusBar::DataChanged( const DataChangedEvent& rDCEvt )
890 Window::DataChanged( rDCEvt );
892 if ( (rDCEvt.GetType() == DATACHANGED_DISPLAY )
893 || (rDCEvt.GetType() == DATACHANGED_FONTS )
894 || (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION)
895 || ( (rDCEvt.GetType() == DATACHANGED_SETTINGS)
896 && (rDCEvt.GetFlags() & SETTINGS_STYLE )
900 mbFormat = sal_True;
901 ImplInitSettings( sal_True, sal_True, sal_True );
902 long nFudge = GetTextHeight() / 4;
903 for ( size_t i = 0, n = mpItemList->size(); i < n; ++i )
905 ImplStatusItem* pItem = (*mpItemList)[ i ];
906 long nWidth = GetTextWidth( pItem->maText ) + nFudge;
907 if( nWidth > pItem->mnWidth + STATUSBAR_OFFSET )
908 pItem->mnWidth = nWidth + STATUSBAR_OFFSET;
910 Size aSize = GetSizePixel();
911 // do not disturb current width, since
912 // CalcWindowSizePixel calculates a minimum width
913 aSize.Height() = CalcWindowSizePixel().Height();
914 SetSizePixel( aSize );
915 Invalidate();
919 // -----------------------------------------------------------------------
921 void StatusBar::Click()
923 ImplCallEventListeners( VCLEVENT_STATUSBAR_CLICK );
924 maClickHdl.Call( this );
927 // -----------------------------------------------------------------------
929 void StatusBar::DoubleClick()
931 ImplCallEventListeners( VCLEVENT_STATUSBAR_DOUBLECLICK );
932 maDoubleClickHdl.Call( this );
935 // -----------------------------------------------------------------------
937 void StatusBar::UserDraw( const UserDrawEvent& )
941 // -----------------------------------------------------------------------
943 void StatusBar::InsertItem( sal_uInt16 nItemId, sal_uLong nWidth,
944 StatusBarItemBits nBits,
945 long nOffset, sal_uInt16 nPos )
947 DBG_ASSERT( nItemId, "StatusBar::InsertItem(): ItemId == 0" );
948 DBG_ASSERT( GetItemPos( nItemId ) == STATUSBAR_ITEM_NOTFOUND,
949 "StatusBar::InsertItem(): ItemId already exists" );
951 // IN und CENTER sind Default
952 if ( !(nBits & (SIB_IN | SIB_OUT | SIB_FLAT)) )
953 nBits |= SIB_IN;
954 if ( !(nBits & (SIB_LEFT | SIB_RIGHT | SIB_CENTER)) )
955 nBits |= SIB_CENTER;
957 // Item anlegen
958 long nFudge = GetTextHeight()/4;
959 ImplStatusItem* pItem = new ImplStatusItem;
960 pItem->mnId = nItemId;
961 pItem->mnBits = nBits;
962 pItem->mnWidth = (long)nWidth+nFudge+STATUSBAR_OFFSET;
963 pItem->mnOffset = nOffset;
964 pItem->mpUserData = 0;
965 pItem->mbVisible = sal_True;
967 // Item in die Liste einfuegen
968 if ( nPos < mpItemList->size() ) {
969 mpItemList->insert( mpItemList->begin() + nPos, pItem );
970 } else {
971 mpItemList->push_back( pItem );
974 mbFormat = sal_True;
975 if ( ImplIsItemUpdate() )
976 Invalidate();
978 ImplCallEventListeners( VCLEVENT_STATUSBAR_ITEMADDED, (void*) sal_IntPtr(nItemId) );
981 // -----------------------------------------------------------------------
983 void StatusBar::RemoveItem( sal_uInt16 nItemId )
985 sal_uInt16 nPos = GetItemPos( nItemId );
986 if ( nPos != STATUSBAR_ITEM_NOTFOUND )
988 delete (*mpItemList)[ nPos ];
989 mpItemList->erase( mpItemList->begin() + nPos );
991 mbFormat = sal_True;
992 if ( ImplIsItemUpdate() )
993 Invalidate();
995 ImplCallEventListeners( VCLEVENT_STATUSBAR_ITEMREMOVED, (void*) sal_IntPtr(nItemId) );
999 // -----------------------------------------------------------------------
1001 void StatusBar::ShowItem( sal_uInt16 nItemId )
1003 sal_uInt16 nPos = GetItemPos( nItemId );
1005 if ( nPos != STATUSBAR_ITEM_NOTFOUND )
1007 ImplStatusItem* pItem = (*mpItemList)[ nPos ];
1008 if ( !pItem->mbVisible )
1010 pItem->mbVisible = sal_True;
1012 mbFormat = sal_True;
1013 if ( ImplIsItemUpdate() )
1014 Invalidate();
1016 ImplCallEventListeners( VCLEVENT_STATUSBAR_SHOWITEM, (void*) sal_IntPtr(nItemId) );
1021 // -----------------------------------------------------------------------
1023 void StatusBar::HideItem( sal_uInt16 nItemId )
1025 sal_uInt16 nPos = GetItemPos( nItemId );
1027 if ( nPos != STATUSBAR_ITEM_NOTFOUND )
1029 ImplStatusItem* pItem = (*mpItemList)[ nPos ];
1030 if ( pItem->mbVisible )
1032 pItem->mbVisible = sal_False;
1034 mbFormat = sal_True;
1035 if ( ImplIsItemUpdate() )
1036 Invalidate();
1038 ImplCallEventListeners( VCLEVENT_STATUSBAR_HIDEITEM, (void*) sal_IntPtr(nItemId) );
1043 // -----------------------------------------------------------------------
1045 sal_Bool StatusBar::IsItemVisible( sal_uInt16 nItemId ) const
1047 sal_uInt16 nPos = GetItemPos( nItemId );
1049 if ( nPos != STATUSBAR_ITEM_NOTFOUND )
1050 return (*mpItemList)[ nPos ]->mbVisible;
1051 else
1052 return sal_False;
1055 void StatusBar::Clear()
1057 // Alle Item loeschen
1058 for ( size_t i = 0, n = mpItemList->size(); i < n; ++i ) {
1059 delete (*mpItemList)[ i ];
1061 mpItemList->clear();
1063 mbFormat = sal_True;
1064 if ( ImplIsItemUpdate() )
1065 Invalidate();
1067 ImplCallEventListeners( VCLEVENT_STATUSBAR_ALLITEMSREMOVED );
1070 // -----------------------------------------------------------------------
1072 sal_uInt16 StatusBar::GetItemCount() const
1074 return (sal_uInt16)mpItemList->size();
1077 // -----------------------------------------------------------------------
1079 sal_uInt16 StatusBar::GetItemId( sal_uInt16 nPos ) const
1081 if ( nPos < mpItemList->size() )
1082 return (*mpItemList)[ nPos ]->mnId;
1083 return 0;
1086 // -----------------------------------------------------------------------
1088 sal_uInt16 StatusBar::GetItemPos( sal_uInt16 nItemId ) const
1090 for ( size_t i = 0, n = mpItemList->size(); i < n; ++i ) {
1091 if ( (*mpItemList)[ i ]->mnId == nItemId ) {
1092 return sal_uInt16( i );
1096 return STATUSBAR_ITEM_NOTFOUND;
1099 // -----------------------------------------------------------------------
1101 sal_uInt16 StatusBar::GetItemId( const Point& rPos ) const
1103 if ( AreItemsVisible() && !mbFormat )
1105 sal_uInt16 nItemCount = GetItemCount();
1106 sal_uInt16 nPos;
1107 for ( nPos = 0; nPos < nItemCount; nPos++ )
1109 // Rechteck holen
1110 Rectangle aRect = ImplGetItemRectPos( nPos );
1111 if ( aRect.IsInside( rPos ) )
1112 return (*mpItemList)[ nPos ]->mnId;
1116 return 0;
1119 // -----------------------------------------------------------------------
1121 Rectangle StatusBar::GetItemRect( sal_uInt16 nItemId ) const
1123 Rectangle aRect;
1125 if ( AreItemsVisible() && !mbFormat )
1127 sal_uInt16 nPos = GetItemPos( nItemId );
1128 if ( nPos != STATUSBAR_ITEM_NOTFOUND )
1130 // Rechteck holen und Rahmen abziehen
1131 aRect = ImplGetItemRectPos( nPos );
1132 long nW = mpImplData->mnItemBorderWidth+1;
1133 aRect.Top() += nW-1;
1134 aRect.Bottom() -= nW-1;
1135 aRect.Left() += nW;
1136 aRect.Right() -= nW;
1137 return aRect;
1141 return aRect;
1144 // -----------------------------------------------------------------------
1146 Point StatusBar::GetItemTextPos( sal_uInt16 nItemId ) const
1148 if ( !mbFormat )
1150 sal_uInt16 nPos = GetItemPos( nItemId );
1151 if ( nPos != STATUSBAR_ITEM_NOTFOUND )
1153 // Rechteck holen
1154 ImplStatusItem* pItem = (*mpItemList)[ nPos ];
1155 Rectangle aRect = ImplGetItemRectPos( nPos );
1156 long nW = mpImplData->mnItemBorderWidth + 1;
1157 Rectangle aTextRect( aRect.Left()+nW, aRect.Top()+nW,
1158 aRect.Right()-nW, aRect.Bottom()-nW );
1159 Point aPos = ImplGetItemTextPos( aTextRect.GetSize(),
1160 Size( GetTextWidth( pItem->maText ), GetTextHeight() ),
1161 pItem->mnBits );
1162 if ( !mbInUserDraw )
1164 aPos.X() += aTextRect.Left();
1165 aPos.Y() += aTextRect.Top();
1167 return aPos;
1171 return Point();
1174 // -----------------------------------------------------------------------
1176 sal_uLong StatusBar::GetItemWidth( sal_uInt16 nItemId ) const
1178 sal_uInt16 nPos = GetItemPos( nItemId );
1180 if ( nPos != STATUSBAR_ITEM_NOTFOUND )
1181 return (*mpItemList)[ nPos ]->mnWidth;
1183 return 0;
1186 // -----------------------------------------------------------------------
1188 StatusBarItemBits StatusBar::GetItemBits( sal_uInt16 nItemId ) const
1190 sal_uInt16 nPos = GetItemPos( nItemId );
1192 if ( nPos != STATUSBAR_ITEM_NOTFOUND )
1193 return (*mpItemList)[ nPos ]->mnBits;
1195 return 0;
1198 // -----------------------------------------------------------------------
1200 long StatusBar::GetItemOffset( sal_uInt16 nItemId ) const
1202 sal_uInt16 nPos = GetItemPos( nItemId );
1204 if ( nPos != STATUSBAR_ITEM_NOTFOUND )
1205 return (*mpItemList)[ nPos ]->mnOffset;
1207 return 0;
1210 // -----------------------------------------------------------------------
1212 void StatusBar::SetItemText( sal_uInt16 nItemId, const OUString& rText )
1214 sal_uInt16 nPos = GetItemPos( nItemId );
1216 if ( nPos != STATUSBAR_ITEM_NOTFOUND )
1218 ImplStatusItem* pItem = (*mpItemList)[ nPos ];
1220 if ( pItem->maText != rText )
1222 pItem->maText = rText;
1224 // adjust item width - see also DataChanged()
1225 long nFudge = GetTextHeight()/4;
1226 long nWidth = GetTextWidth( pItem->maText ) + nFudge;
1227 if( (nWidth > pItem->mnWidth + STATUSBAR_OFFSET) ||
1228 ((nWidth < pItem->mnWidth) && (mnDX - STATUSBAR_OFFSET) < mnItemsWidth ))
1230 pItem->mnWidth = nWidth + STATUSBAR_OFFSET;
1231 ImplFormat();
1232 Invalidate();
1235 // Item neu Zeichen, wenn StatusBar sichtbar und
1236 // UpdateMode gesetzt ist
1237 if ( pItem->mbVisible && !mbFormat && ImplIsItemUpdate() )
1239 Update();
1240 ImplDrawItem( sal_True, nPos, sal_True, sal_False );
1241 Flush();
1247 // -----------------------------------------------------------------------
1249 const OUString& StatusBar::GetItemText( sal_uInt16 nItemId ) const
1251 sal_uInt16 nPos = GetItemPos( nItemId );
1253 assert( nPos != STATUSBAR_ITEM_NOTFOUND );
1255 return (*mpItemList)[ nPos ]->maText;
1258 // -----------------------------------------------------------------------
1260 void StatusBar::SetItemCommand( sal_uInt16 nItemId, const OUString& rCommand )
1262 sal_uInt16 nPos = GetItemPos( nItemId );
1264 if ( nPos != STATUSBAR_ITEM_NOTFOUND )
1266 ImplStatusItem* pItem = (*mpItemList)[ nPos ];
1268 if ( pItem->maCommand != rCommand )
1269 pItem->maCommand = rCommand;
1273 // -----------------------------------------------------------------------
1275 const OUString StatusBar::GetItemCommand( sal_uInt16 nItemId )
1277 sal_uInt16 nPos = GetItemPos( nItemId );
1279 if ( nPos != STATUSBAR_ITEM_NOTFOUND )
1280 return (*mpItemList)[ nPos ]->maCommand;
1282 return OUString();
1285 // -----------------------------------------------------------------------
1287 void StatusBar::SetItemData( sal_uInt16 nItemId, void* pNewData )
1289 sal_uInt16 nPos = GetItemPos( nItemId );
1291 if ( nPos != STATUSBAR_ITEM_NOTFOUND )
1293 ImplStatusItem* pItem = (*mpItemList)[ nPos ];
1294 pItem->mpUserData = pNewData;
1296 // Wenn es ein User-Item ist, DrawItem-Aufrufen
1297 if ( (pItem->mnBits & SIB_USERDRAW) && pItem->mbVisible &&
1298 !mbFormat && ImplIsItemUpdate() )
1300 Update();
1301 ImplDrawItem( sal_True, nPos, sal_False, sal_False );
1302 Flush();
1307 void* StatusBar::GetItemData( sal_uInt16 nItemId ) const
1309 sal_uInt16 nPos = GetItemPos( nItemId );
1311 if ( nPos != STATUSBAR_ITEM_NOTFOUND )
1312 return (*mpItemList)[ nPos ]->mpUserData;
1314 return NULL;
1317 void StatusBar::RedrawItem( sal_uInt16 nItemId )
1319 if ( mbFormat )
1320 return;
1322 sal_uInt16 nPos = GetItemPos( nItemId );
1323 if ( nPos == STATUSBAR_ITEM_NOTFOUND )
1324 return;
1326 ImplStatusItem* pItem = (*mpItemList)[ nPos ];
1327 if ( pItem && (pItem->mnBits & SIB_USERDRAW) &&
1328 pItem->mbVisible && ImplIsItemUpdate() )
1330 Update();
1331 ImplDrawItem( sal_True, nPos, sal_False, sal_False );
1332 Flush();
1336 // -----------------------------------------------------------------------
1338 void StatusBar::SetHelpText( sal_uInt16 nItemId, const OUString& rText )
1340 sal_uInt16 nPos = GetItemPos( nItemId );
1342 if ( nPos != STATUSBAR_ITEM_NOTFOUND )
1343 (*mpItemList)[ nPos ]->maHelpText = rText;
1346 // -----------------------------------------------------------------------
1348 const OUString& StatusBar::GetHelpText( sal_uInt16 nItemId ) const
1350 sal_uInt16 nPos = GetItemPos( nItemId );
1352 assert ( nPos != STATUSBAR_ITEM_NOTFOUND );
1354 ImplStatusItem* pItem = (*mpItemList)[ nPos ];
1355 if ( pItem->maHelpText.isEmpty() && ( !pItem->maHelpId.isEmpty() || !pItem->maCommand.isEmpty() ))
1357 Help* pHelp = Application::GetHelp();
1358 if ( pHelp )
1360 if ( !pItem->maCommand.isEmpty() )
1361 pItem->maHelpText = pHelp->GetHelpText( pItem->maCommand, this );
1362 if ( pItem->maHelpText.isEmpty() && !pItem->maHelpId.isEmpty() )
1363 pItem->maHelpText = pHelp->GetHelpText( OStringToOUString( pItem->maHelpId, RTL_TEXTENCODING_UTF8 ), this );
1367 return pItem->maHelpText;
1370 // -----------------------------------------------------------------------
1372 void StatusBar::SetQuickHelpText( sal_uInt16 nItemId, const OUString& rText )
1374 sal_uInt16 nPos = GetItemPos( nItemId );
1376 if ( nPos != STATUSBAR_ITEM_NOTFOUND )
1377 (*mpItemList)[ nPos ]->maQuickHelpText = rText;
1380 // -----------------------------------------------------------------------
1382 const OUString& StatusBar::GetQuickHelpText( sal_uInt16 nItemId ) const
1384 sal_uInt16 nPos = GetItemPos( nItemId );
1386 assert ( nPos != STATUSBAR_ITEM_NOTFOUND );
1388 ImplStatusItem* pItem = (*mpItemList)[ nPos ];
1389 return pItem->maQuickHelpText;
1392 // -----------------------------------------------------------------------
1394 void StatusBar::SetHelpId( sal_uInt16 nItemId, const OString& rHelpId )
1396 sal_uInt16 nPos = GetItemPos( nItemId );
1398 if ( nPos != STATUSBAR_ITEM_NOTFOUND )
1399 (*mpItemList)[ nPos ]->maHelpId = rHelpId;
1402 // -----------------------------------------------------------------------
1404 OString StatusBar::GetHelpId( sal_uInt16 nItemId ) const
1406 sal_uInt16 nPos = GetItemPos( nItemId );
1408 OString aRet;
1409 if ( nPos != STATUSBAR_ITEM_NOTFOUND )
1411 ImplStatusItem* pItem = (*mpItemList)[ nPos ];
1412 if ( !pItem->maHelpId.isEmpty() )
1413 aRet = pItem->maHelpId;
1414 else
1415 aRet = OUStringToOString( pItem->maCommand, RTL_TEXTENCODING_UTF8 );
1418 return aRet;
1421 void StatusBar::StartProgressMode( const OUString& rText )
1423 DBG_ASSERT( !mbProgressMode, "StatusBar::StartProgressMode(): progress mode is active" );
1425 mbProgressMode = sal_True;
1426 mnPercent = 0;
1427 maPrgsTxt = rText;
1429 // Groessen berechnen
1430 ImplCalcProgressRect();
1432 // Paint ausloesen (dort wird der Text und der Frame gemalt)
1433 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
1434 Color aPrgsColor = rStyleSettings.GetHighlightColor();
1435 if ( aPrgsColor == rStyleSettings.GetFaceColor() )
1436 aPrgsColor = rStyleSettings.GetDarkShadowColor();
1437 SetLineColor();
1438 SetFillColor( aPrgsColor );
1439 if ( IsReallyVisible() )
1441 Invalidate();
1442 Update();
1443 Flush();
1447 // -----------------------------------------------------------------------
1449 void StatusBar::SetProgressValue( sal_uInt16 nNewPercent )
1451 DBG_ASSERT( mbProgressMode, "StatusBar::SetProgressValue(): no progrss mode" );
1452 DBG_ASSERTWARNING( nNewPercent <= 100, "StatusBar::SetProgressValue(): nPercent > 100" );
1454 if ( mbProgressMode
1455 && IsReallyVisible()
1456 && (!mnPercent || (mnPercent != nNewPercent)) )
1458 Update();
1459 SetLineColor();
1460 ImplDrawProgress( sal_False, mnPercent, nNewPercent );
1461 Flush();
1463 mnPercent = nNewPercent;
1466 // -----------------------------------------------------------------------
1468 void StatusBar::EndProgressMode()
1470 DBG_ASSERT( mbProgressMode, "StatusBar::EndProgressMode(): no progress mode" );
1472 mbProgressMode = sal_False;
1473 maPrgsTxt = "";
1475 // Paint neu ausloesen um StatusBar wieder herzustellen
1476 SetFillColor( GetSettings().GetStyleSettings().GetFaceColor() );
1477 if ( IsReallyVisible() )
1479 Invalidate();
1480 Update();
1481 Flush();
1485 // -----------------------------------------------------------------------
1487 void StatusBar::SetText( const OUString& rText )
1489 if ( (!mbVisibleItems || (GetStyle() & WB_RIGHT)) && !mbProgressMode &&
1490 IsReallyVisible() && IsUpdateMode() )
1492 if ( mbFormat )
1494 Invalidate();
1495 Window::SetText( rText );
1497 else
1499 Update();
1500 long nOldTextWidth = GetTextWidth( GetText() );
1501 Window::SetText( rText );
1502 ImplDrawText( sal_True, nOldTextWidth );
1503 Flush();
1506 else if ( mbProgressMode )
1508 maPrgsTxt = rText;
1509 if ( IsReallyVisible() )
1511 Invalidate();
1512 Update();
1513 Flush();
1516 else
1517 Window::SetText( rText );
1520 // -----------------------------------------------------------------------
1522 Size StatusBar::CalcWindowSizePixel() const
1524 size_t i = 0;
1525 size_t nCount = mpItemList->size();
1526 long nOffset = 0;
1527 long nCalcWidth = (STATUSBAR_OFFSET_X*2);
1528 long nCalcHeight;
1530 while ( i < nCount )
1532 ImplStatusItem* pItem = (*mpItemList)[ i ];
1533 nCalcWidth += pItem->mnWidth + nOffset;
1534 nOffset = pItem->mnOffset;
1535 i++;
1538 long nMinHeight = GetTextHeight();
1539 const long nBarTextOffset = STATUSBAR_OFFSET_TEXTY*2;
1540 long nProgressHeight = nMinHeight + nBarTextOffset;
1542 if( IsNativeControlSupported( CTRL_PROGRESS, PART_ENTIRE_CONTROL ) )
1544 ImplControlValue aValue;
1545 Rectangle aControlRegion( (const Point&)Point(), Size( nCalcWidth, nMinHeight ) );
1546 Rectangle aNativeControlRegion, aNativeContentRegion;
1547 if( GetNativeControlRegion( CTRL_PROGRESS, PART_ENTIRE_CONTROL,
1548 aControlRegion, CTRL_STATE_ENABLED, aValue, OUString(),
1549 aNativeControlRegion, aNativeContentRegion ) )
1551 nProgressHeight = aNativeControlRegion.GetHeight();
1555 if( mpImplData->mbDrawItemFrames &&
1556 IsNativeControlSupported( CTRL_FRAME, PART_BORDER ) )
1558 ImplControlValue aControlValue( FRAME_DRAW_NODRAW );
1559 Rectangle aBound, aContent;
1560 Rectangle aNatRgn( Point( 0, 0 ), Size( 150, 50 ) );
1561 if( GetNativeControlRegion(CTRL_FRAME, PART_BORDER,
1562 aNatRgn, 0, aControlValue, OUString(), aBound, aContent) )
1564 mpImplData->mnItemBorderWidth =
1565 ( aBound.GetHeight() - aContent.GetHeight() ) / 2;
1569 nCalcHeight = nMinHeight+nBarTextOffset + 2*mpImplData->mnItemBorderWidth;
1570 if( nCalcHeight < nProgressHeight+2 )
1571 nCalcHeight = nProgressHeight+2;
1573 return Size( nCalcWidth, nCalcHeight );
1577 // -----------------------------------------------------------------------
1579 void StatusBar::SetAccessibleName( sal_uInt16 nItemId, const OUString& rName )
1581 sal_uInt16 nPos = GetItemPos( nItemId );
1583 if ( nPos != STATUSBAR_ITEM_NOTFOUND )
1585 ImplStatusItem* pItem = (*mpItemList)[ nPos ];
1587 if ( pItem->maAccessibleName != rName )
1589 pItem->maAccessibleName = rName;
1590 ImplCallEventListeners( VCLEVENT_STATUSBAR_NAMECHANGED, (void*) sal_IntPtr(pItem->mnId) );
1595 // -----------------------------------------------------------------------
1597 const OUString& StatusBar::GetAccessibleName( sal_uInt16 nItemId ) const
1599 sal_uInt16 nPos = GetItemPos( nItemId );
1601 assert ( nPos != STATUSBAR_ITEM_NOTFOUND );
1603 return (*mpItemList)[ nPos ]->maAccessibleName;
1606 // -----------------------------------------------------------------------
1608 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */