Kaydet (Commit) 4c329456 authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl Kaydeden (comit) Jan Holesovsky

refactor ProgressBar to use RenderContext

Change-Id: Idf33332a207736f70809820853dee5ce1e0a3cb1
üst 29b1e671
...@@ -31,12 +31,10 @@ typedef ::std::vector< ImplStatusItem* > ImplStatusItemList; ...@@ -31,12 +31,10 @@ typedef ::std::vector< ImplStatusItem* > ImplStatusItemList;
// - Progress-Ausgabe - // - Progress-Ausgabe -
void VCL_DLLPUBLIC DrawProgress(vcl::Window* pWindow, vcl::RenderContext& rRenderContext, const Point& rPos,
void VCL_DLLPUBLIC DrawProgress( vcl::Window* pWindow, const Point& rPos, long nOffset, long nPrgsWidth, long nPrgsHeight,
long nOffset, long nPrgsWidth, long nPrgsHeight, sal_uInt16 nPercent1, sal_uInt16 nPercent2, sal_uInt16 nPercentCount,
sal_uInt16 nPercent1, sal_uInt16 nPercent2, sal_uInt16 nPercentCount, const Rectangle& rFramePosSize);
const Rectangle& rFramePosSize
);
// - StatusBarItemBits - // - StatusBarItemBits -
......
...@@ -117,33 +117,37 @@ void ProgressBar::ImplInitSettings( bool bFont, ...@@ -117,33 +117,37 @@ void ProgressBar::ImplInitSettings( bool bFont,
} }
} }
void ProgressBar::ImplDrawProgress(vcl::RenderContext& /*rRenderContext*/, sal_uInt16 nOldPerc, sal_uInt16 nNewPerc) void ProgressBar::ImplDrawProgress(vcl::RenderContext& rRenderContext, sal_uInt16 nOldPerc, sal_uInt16 nNewPerc)
{ {
if ( mbCalcNew ) if (mbCalcNew)
{ {
mbCalcNew = false; mbCalcNew = false;
Size aSize = GetOutputSizePixel(); Size aSize = rRenderContext.GetOutputSizePixel();
mnPrgsHeight = aSize.Height()-(PROGRESSBAR_WIN_OFFSET*2); mnPrgsHeight = aSize.Height() - (PROGRESSBAR_WIN_OFFSET * 2);
mnPrgsWidth = (mnPrgsHeight*2)/3; mnPrgsWidth = (mnPrgsHeight * 2) / 3;
maPos.Y() = PROGRESSBAR_WIN_OFFSET; maPos.Y() = PROGRESSBAR_WIN_OFFSET;
long nMaxWidth = (aSize.Width()-(PROGRESSBAR_WIN_OFFSET*2)+PROGRESSBAR_OFFSET); long nMaxWidth = (aSize.Width() - (PROGRESSBAR_WIN_OFFSET * 2) + PROGRESSBAR_OFFSET);
sal_uInt16 nMaxCount = (sal_uInt16)(nMaxWidth / (mnPrgsWidth+PROGRESSBAR_OFFSET)); sal_uInt16 nMaxCount = (sal_uInt16)(nMaxWidth / (mnPrgsWidth+PROGRESSBAR_OFFSET));
if ( nMaxCount <= 1 ) if (nMaxCount <= 1)
{
nMaxCount = 1; nMaxCount = 1;
}
else else
{ {
while ( ((10000/(10000/nMaxCount))*(mnPrgsWidth+PROGRESSBAR_OFFSET)) > nMaxWidth ) while (((10000 / (10000 / nMaxCount)) * (mnPrgsWidth + PROGRESSBAR_OFFSET)) > nMaxWidth)
{
nMaxCount--; nMaxCount--;
}
} }
mnPercentCount = 10000/nMaxCount; mnPercentCount = 10000 / nMaxCount;
nMaxWidth = ((10000/(10000/nMaxCount))*(mnPrgsWidth+PROGRESSBAR_OFFSET))-PROGRESSBAR_OFFSET; nMaxWidth = ((10000 / (10000 / nMaxCount)) * (mnPrgsWidth + PROGRESSBAR_OFFSET)) - PROGRESSBAR_OFFSET;
maPos.X() = (aSize.Width()-nMaxWidth)/2; maPos.X() = (aSize.Width() - nMaxWidth) / 2;
} }
::DrawProgress( this, maPos, PROGRESSBAR_OFFSET, mnPrgsWidth, mnPrgsHeight, ::DrawProgress(this, rRenderContext, maPos, PROGRESSBAR_OFFSET, mnPrgsWidth, mnPrgsHeight,
nOldPerc*100, nNewPerc*100, mnPercentCount, nOldPerc * 100, nNewPerc * 100, mnPercentCount,
Rectangle( Point(), GetSizePixel() ) ); Rectangle(Point(), GetSizePixel()));
} }
void ProgressBar::Paint(vcl::RenderContext& rRenderContext, const Rectangle& /*rRect*/) void ProgressBar::Paint(vcl::RenderContext& rRenderContext, const Rectangle& /*rRect*/)
......
...@@ -468,147 +468,143 @@ void StatusBar::ImplDrawItem(vcl::RenderContext& /*rRenderContext*/, bool bOffSc ...@@ -468,147 +468,143 @@ void StatusBar::ImplDrawItem(vcl::RenderContext& /*rRenderContext*/, bool bOffSc
CallEventListeners( VCLEVENT_STATUSBAR_DRAWITEM, reinterpret_cast<void*>(pItem->mnId) ); CallEventListeners( VCLEVENT_STATUSBAR_DRAWITEM, reinterpret_cast<void*>(pItem->mnId) );
} }
void DrawProgress( vcl::Window* pWindow, const Point& rPos, void DrawProgress(vcl::Window* pWindow, vcl::RenderContext& rRenderContext, const Point& rPos,
long nOffset, long nPrgsWidth, long nPrgsHeight, long nOffset, long nPrgsWidth, long nPrgsHeight,
sal_uInt16 nPercent1, sal_uInt16 nPercent2, sal_uInt16 nPercentCount, sal_uInt16 nPercent1, sal_uInt16 nPercent2, sal_uInt16 nPercentCount,
const Rectangle& rFramePosSize const Rectangle& rFramePosSize)
)
{ {
if( pWindow->IsNativeControlSupported( CTRL_PROGRESS, PART_ENTIRE_CONTROL ) ) if (rRenderContext.IsNativeControlSupported(CTRL_PROGRESS, PART_ENTIRE_CONTROL))
{ {
bool bNeedErase = ImplGetSVData()->maNWFData.mbProgressNeedsErase; bool bNeedErase = ImplGetSVData()->maNWFData.mbProgressNeedsErase;
long nFullWidth = (nPrgsWidth + nOffset) * (10000 / nPercentCount); long nFullWidth = (nPrgsWidth + nOffset) * (10000 / nPercentCount);
long nPerc = (nPercent2 > 10000) ? 10000 : nPercent2; long nPerc = (nPercent2 > 10000) ? 10000 : nPercent2;
ImplControlValue aValue( nFullWidth * (long)nPerc / 10000 ); ImplControlValue aValue(nFullWidth * long(nPerc) / 10000);
Rectangle aDrawRect( rPos, Size( nFullWidth, nPrgsHeight ) ); Rectangle aDrawRect(rPos, Size(nFullWidth, nPrgsHeight));
Rectangle aControlRegion( aDrawRect ); Rectangle aControlRegion(aDrawRect);
if( bNeedErase )
if(bNeedErase)
{ {
vcl::Window* pEraseWindow = pWindow; vcl::Window* pEraseWindow = pWindow;
while( pEraseWindow->IsPaintTransparent() && while (pEraseWindow->IsPaintTransparent() && !pEraseWindow->ImplGetWindowImpl()->mbFrame)
! pEraseWindow->ImplGetWindowImpl()->mbFrame )
{ {
pEraseWindow = pEraseWindow->ImplGetWindowImpl()->mpParent; pEraseWindow = pEraseWindow->ImplGetWindowImpl()->mpParent;
} }
if( pEraseWindow == pWindow )
if (pEraseWindow == pWindow)
{
// restore background of pWindow // restore background of pWindow
pEraseWindow->Erase( rFramePosSize ); rRenderContext.Erase(rFramePosSize);
}
else else
{ {
// restore transparent background // restore transparent background
Point aTL( pWindow->OutputToAbsoluteScreenPixel( rFramePosSize.TopLeft() ) ); Point aTL(pWindow->OutputToAbsoluteScreenPixel(rFramePosSize.TopLeft()));
aTL = pEraseWindow->AbsoluteScreenToOutputPixel( aTL ); aTL = pEraseWindow->AbsoluteScreenToOutputPixel(aTL);
Rectangle aRect( aTL, rFramePosSize.GetSize() ); Rectangle aRect(aTL, rFramePosSize.GetSize());
pEraseWindow->Invalidate( aRect, INVALIDATE_NOCHILDREN | pEraseWindow->Invalidate(aRect, INVALIDATE_NOCHILDREN |
INVALIDATE_NOCLIPCHILDREN | INVALIDATE_NOCLIPCHILDREN |
INVALIDATE_TRANSPARENT ); INVALIDATE_TRANSPARENT);
pEraseWindow->Update(); pEraseWindow->Update();
} }
pWindow->Push( PushFlags::CLIPREGION ); rRenderContext.Push(PushFlags::CLIPREGION);
pWindow->IntersectClipRegion( rFramePosSize ); rRenderContext.IntersectClipRegion(rFramePosSize);
} }
bool bNativeOK = pWindow->DrawNativeControl( CTRL_PROGRESS, PART_ENTIRE_CONTROL, aControlRegion,
ControlState::ENABLED, aValue, OUString() ); bool bNativeOK = rRenderContext.DrawNativeControl(CTRL_PROGRESS, PART_ENTIRE_CONTROL, aControlRegion,
if( bNeedErase ) ControlState::ENABLED, aValue, OUString());
pWindow->Pop(); if (bNeedErase)
if( bNativeOK ) rRenderContext.Pop();
{ if (bNativeOK)
pWindow->Flush();
return; return;
}
} }
// precompute values // precompute values
sal_uInt16 nPerc1 = nPercent1 / nPercentCount; sal_uInt16 nPerc1 = nPercent1 / nPercentCount;
sal_uInt16 nPerc2 = nPercent2 / nPercentCount; sal_uInt16 nPerc2 = nPercent2 / nPercentCount;
if ( nPerc1 > nPerc2 ) if (nPerc1 > nPerc2)
{ {
// support progress that can also decrease // support progress that can also decrease
// compute rectangle // compute rectangle
long nDX = nPrgsWidth + nOffset; long nDX = nPrgsWidth + nOffset;
long nLeft = rPos.X()+((nPerc1-1)*nDX); long nLeft = rPos.X() + ((nPerc1 - 1) * nDX);
Rectangle aRect( nLeft, rPos.Y(), nLeft+nPrgsWidth, rPos.Y()+nPrgsHeight ); Rectangle aRect(nLeft, rPos.Y(), nLeft + nPrgsWidth, rPos.Y() + nPrgsHeight);
do do
{ {
pWindow->Erase( aRect ); rRenderContext.Erase(aRect);
aRect.Left() -= nDX; aRect.Left() -= nDX;
aRect.Right() -= nDX; aRect.Right() -= nDX;
nPerc1--; nPerc1--;
} }
while ( nPerc1 > nPerc2 ); while (nPerc1 > nPerc2);
pWindow->Flush();
} }
else if ( nPerc1 < nPerc2 ) else if (nPerc1 < nPerc2)
{ {
// draw Percent rectangle // draw Percent rectangle
// if Percent2 greater than 100%, adapt values // if Percent2 greater than 100%, adapt values
if ( nPercent2 > 10000 ) if (nPercent2 > 10000)
{ {
nPerc2 = 10000 / nPercentCount; nPerc2 = 10000 / nPercentCount;
if ( nPerc1 >= nPerc2 ) if (nPerc1 >= nPerc2)
nPerc1 = nPerc2-1; nPerc1 = nPerc2 - 1;
} }
// compute rectangle // compute rectangle
long nDX = nPrgsWidth + nOffset; long nDX = nPrgsWidth + nOffset;
long nLeft = rPos.X()+(nPerc1*nDX); long nLeft = rPos.X() + (nPerc1 * nDX);
Rectangle aRect( nLeft, rPos.Y(), nLeft+nPrgsWidth, rPos.Y()+nPrgsHeight ); Rectangle aRect(nLeft, rPos.Y(), nLeft + nPrgsWidth, rPos.Y() + nPrgsHeight);
do do
{ {
pWindow->DrawRect( aRect ); rRenderContext.DrawRect(aRect);
aRect.Left() += nDX; aRect.Left() += nDX;
aRect.Right() += nDX; aRect.Right() += nDX;
nPerc1++; nPerc1++;
} }
while ( nPerc1 < nPerc2 ); while (nPerc1 < nPerc2);
// if greater than 100%, set rectangle to blink // if greater than 100%, set rectangle to blink
if ( nPercent2 > 10000 ) if (nPercent2 > 10000)
{ {
// define on/off status // define on/off status
if ( ((nPercent2 / nPercentCount) & 0x01) == (nPercentCount & 0x01) ) if (((nPercent2 / nPercentCount) & 0x01) == (nPercentCount & 0x01))
{ {
aRect.Left() -= nDX; aRect.Left() -= nDX;
aRect.Right() -= nDX; aRect.Right() -= nDX;
pWindow->Erase( aRect ); rRenderContext.Erase(aRect);
} }
} }
pWindow->Flush();
} }
} }
void StatusBar::ImplDrawProgress(vcl::RenderContext& rRenderContext, bool bPaint, void StatusBar::ImplDrawProgress(vcl::RenderContext& rRenderContext, bool bPaint,
sal_uInt16 nPercent1, sal_uInt16 nPercent2) sal_uInt16 nPercent1, sal_uInt16 nPercent2)
{ {
bool bNative = IsNativeControlSupported( CTRL_PROGRESS, PART_ENTIRE_CONTROL ); bool bNative = rRenderContext.IsNativeControlSupported(CTRL_PROGRESS, PART_ENTIRE_CONTROL);
// bPaint: draw text also, else only update progress // bPaint: draw text also, else only update progress
if (bPaint) if (bPaint)
{ {
DrawText( maPrgsTxtPos, maPrgsTxt ); rRenderContext.DrawText(maPrgsTxtPos, maPrgsTxt);
if( ! bNative ) if (!bNative)
{ {
DecorationView aDecoView(&rRenderContext); DecorationView aDecoView(&rRenderContext);
aDecoView.DrawFrame( maPrgsFrameRect, FRAME_DRAW_IN ); aDecoView.DrawFrame(maPrgsFrameRect, FRAME_DRAW_IN);
} }
} }
Point aPos( maPrgsFrameRect.Left()+STATUSBAR_PRGS_OFFSET, Point aPos(maPrgsFrameRect.Left() + STATUSBAR_PRGS_OFFSET,
maPrgsFrameRect.Top()+STATUSBAR_PRGS_OFFSET ); maPrgsFrameRect.Top() + STATUSBAR_PRGS_OFFSET);
long nPrgsHeight = mnPrgsSize; long nPrgsHeight = mnPrgsSize;
if( bNative ) if (bNative)
{ {
aPos = maPrgsFrameRect.TopLeft(); aPos = maPrgsFrameRect.TopLeft();
nPrgsHeight = maPrgsFrameRect.GetHeight(); nPrgsHeight = maPrgsFrameRect.GetHeight();
} }
DrawProgress( this, aPos, mnPrgsSize / 2, mnPrgsSize, nPrgsHeight, DrawProgress(this, rRenderContext, aPos, mnPrgsSize / 2, mnPrgsSize, nPrgsHeight,
nPercent1 * 100, nPercent2 * 100, mnPercentCount, maPrgsFrameRect ); nPercent1 * 100, nPercent2 * 100, mnPercentCount, maPrgsFrameRect);
} }
void StatusBar::ImplCalcProgressRect() void StatusBar::ImplCalcProgressRect()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment