Kaydet (Commit) 9b6057dc authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl

refactor SwAddressPreview to use RenderContext

Change-Id: I82d76c28a2326a41fe78a25d3efcea0196775881
üst c24e3097
...@@ -316,51 +316,53 @@ void SwAddressPreview::UpdateScrollBar() ...@@ -316,51 +316,53 @@ void SwAddressPreview::UpdateScrollBar()
} }
} }
void SwAddressPreview::Paint(vcl::RenderContext& /*rRenderContext*/, const Rectangle&) void SwAddressPreview::Paint(vcl::RenderContext& rRenderContext, const Rectangle&)
{ {
const StyleSettings& rSettings = GetSettings().GetStyleSettings(); const StyleSettings& rSettings = rRenderContext.GetSettings().GetStyleSettings();
SetFillColor(rSettings.GetWindowColor()); rRenderContext.SetFillColor(rSettings.GetWindowColor());
SetLineColor( Color(COL_TRANSPARENT) ); rRenderContext.SetLineColor(Color(COL_TRANSPARENT));
DrawRect( Rectangle(Point(0, 0), GetOutputSizePixel()) ); rRenderContext.DrawRect(Rectangle(Point(0, 0), rRenderContext.GetOutputSizePixel()));
Color aPaintColor(IsEnabled() ? rSettings.GetWindowTextColor() : rSettings.GetDisableColor()); Color aPaintColor(IsEnabled() ? rSettings.GetWindowTextColor() : rSettings.GetDisableColor());
SetLineColor(aPaintColor); rRenderContext.SetLineColor(aPaintColor);
vcl::Font aFont(GetFont()); vcl::Font aFont(rRenderContext.GetFont());
aFont.SetColor(aPaintColor); aFont.SetColor(aPaintColor);
SetFont(aFont); rRenderContext.SetFont(aFont);
Size aSize = GetOutputSizePixel(); Size aSize = rRenderContext.GetOutputSizePixel();
sal_uInt16 nStartRow = 0; sal_uInt16 nStartRow = 0;
if(aVScrollBar->IsVisible()) if(aVScrollBar->IsVisible())
{ {
aSize.Width() -= aVScrollBar->GetSizePixel().Width(); aSize.Width() -= aVScrollBar->GetSizePixel().Width();
nStartRow = (sal_uInt16)aVScrollBar->GetThumbPos(); nStartRow = (sal_uInt16)aVScrollBar->GetThumbPos();
} }
Size aPartSize( aSize.Width()/pImpl->nColumns, aSize.Height()/pImpl->nRows ); Size aPartSize(aSize.Width() / pImpl->nColumns,
aSize.Height() / pImpl->nRows);
aPartSize.Width() -= 2; aPartSize.Width() -= 2;
aPartSize.Height() -= 2; aPartSize.Height() -= 2;
sal_uInt16 nAddress = nStartRow * pImpl->nColumns; sal_uInt16 nAddress = nStartRow * pImpl->nColumns;
const sal_uInt16 nNumAddresses = static_cast< sal_uInt16 >(pImpl->aAddresses.size()); const sal_uInt16 nNumAddresses = static_cast<sal_uInt16>(pImpl->aAddresses.size());
for(sal_uInt16 nRow = 0; nRow < pImpl->nRows ; ++nRow) for (sal_uInt16 nRow = 0; nRow < pImpl->nRows ; ++nRow)
{ {
for(sal_uInt16 nCol = 0; nCol < pImpl->nColumns; ++nCol) for (sal_uInt16 nCol = 0; nCol < pImpl->nColumns; ++nCol)
{ {
if(nAddress >= nNumAddresses) if (nAddress >= nNumAddresses)
break; break;
Point aPos(nCol * aPartSize.Width(), (nRow) * aPartSize.Height()); Point aPos(nCol * aPartSize.Width(),
aPos.Move(1,1); nRow * aPartSize.Height());
aPos.Move(1, 1);
bool bIsSelected = nAddress == pImpl->nSelectedAddress; bool bIsSelected = nAddress == pImpl->nSelectedAddress;
if((pImpl->nColumns * pImpl->nRows) == 1) if ((pImpl->nColumns * pImpl->nRows) == 1)
bIsSelected = false; bIsSelected = false;
OUString adr(pImpl->aAddresses[nAddress]); OUString adr(pImpl->aAddresses[nAddress]);
DrawText_Impl(adr,aPos,aPartSize,bIsSelected); DrawText_Impl(rRenderContext, adr, aPos, aPartSize, bIsSelected);
++nAddress; ++nAddress;
} }
} }
SetClipRegion(); rRenderContext.SetClipRegion();
} }
void SwAddressPreview::MouseButtonDown( const MouseEvent& rMEvt ) void SwAddressPreview::MouseButtonDown( const MouseEvent& rMEvt )
{ {
Window::MouseButtonDown(rMEvt); Window::MouseButtonDown(rMEvt);
if (rMEvt.IsLeft() && pImpl->nRows && pImpl->nColumns) if (rMEvt.IsLeft() && pImpl->nRows && pImpl->nColumns)
...@@ -434,30 +436,30 @@ void SwAddressPreview::KeyInput( const KeyEvent& rKEvt ) ...@@ -434,30 +436,30 @@ void SwAddressPreview::KeyInput( const KeyEvent& rKEvt )
void SwAddressPreview::StateChanged( StateChangedType nStateChange ) void SwAddressPreview::StateChanged( StateChangedType nStateChange )
{ {
if(nStateChange == StateChangedType::Enable) if (nStateChange == StateChangedType::Enable)
Invalidate(); Invalidate();
Window::StateChanged(nStateChange); Window::StateChanged(nStateChange);
} }
void SwAddressPreview::DrawText_Impl( void SwAddressPreview::DrawText_Impl(vcl::RenderContext& rRenderContext, const OUString& rAddress,
const OUString& rAddress, const Point& rTopLeft, const Size& rSize, bool bIsSelected) const Point& rTopLeft, const Size& rSize, bool bIsSelected)
{ {
SetClipRegion( vcl::Region( Rectangle(rTopLeft, rSize)) ); rRenderContext.SetClipRegion(vcl::Region(Rectangle(rTopLeft, rSize)));
if(bIsSelected) if (bIsSelected)
{ {
//selection rectangle //selection rectangle
SetFillColor(Color(COL_TRANSPARENT)); rRenderContext.SetFillColor(Color(COL_TRANSPARENT));
DrawRect(Rectangle(rTopLeft, rSize)); rRenderContext.DrawRect(Rectangle(rTopLeft, rSize));
} }
sal_Int32 nHeight = GetTextHeight(); sal_Int32 nHeight = GetTextHeight();
OUString sAddress(rAddress); OUString sAddress(rAddress);
sal_uInt16 nTokens = comphelper::string::getTokenCount(sAddress, '\n'); sal_uInt16 nTokens = comphelper::string::getTokenCount(sAddress, '\n');
Point aStart = rTopLeft; Point aStart = rTopLeft;
//put it away from the border //put it away from the border
aStart.Move( 2, 2); aStart.Move(2, 2);
for(sal_uInt16 nToken = 0; nToken < nTokens; nToken++) for (sal_uInt16 nToken = 0; nToken < nTokens; nToken++)
{ {
DrawText( aStart, sAddress.getToken(nToken, '\n') ); rRenderContext.DrawText(aStart, sAddress.getToken(nToken, '\n'));
aStart.Y() += nHeight; aStart.Y() += nHeight;
} }
} }
......
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