/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
// document height // determine number of rows needed for <nPages> in preview layout // use method <GetRowOfPage(..)>. const sal_uInt16 nDocRows = GetRowOfPage( mnPages );
aDocSize.setHeight( nDocRows * maMaxPageSize.Height() +
(nDocRows+1) * gnYFree );
maPreviewDocRect.SetPos( Point( 0, 0 ) );
maPreviewDocRect.SetSize( aDocSize );
}
}
/** init page preview layout
initialize the page preview settings for a given layout.
side effects: (1) If parameter <_bCalcScale> is true, mapping mode with calculated scaling is set at the output device and the zoom at the view options of the given view shell is set with the calculated scaling.
*/ void SwPagePreviewLayout::Init( const sal_uInt16 _nCols, const sal_uInt16 _nRows, const Size& _rPxWinSize
)
{ // check environment and parameters
{ bool bColsRowsValid = (_nCols != 0) && (_nRows != 0);
OSL_ENSURE( bColsRowsValid, "preview layout parameters not correct - preview layout can *not* be initialized" ); if ( !bColsRowsValid ) return;
bool bPxWinSizeValid = (_rPxWinSize.Width() >= 0) &&
(_rPxWinSize.Height() >= 0);
OSL_ENSURE( bPxWinSizeValid, "no window size - preview layout can *not* be initialized" ); if ( !bPxWinSizeValid ) return;
}
// environment and parameters ok
// clear existing preview settings
Clear_();
// set layout information columns and rows
mnCols = _nCols;
mnRows = _nRows;
CalcPreviewLayoutSizes();
// validate layout information
mbLayoutInfoValid = true;
bool bStartPageRangeValid = nProposedStartPageNum <= mnPages;
OSL_ENSURE( bStartPageRangeValid, "proposed start page not existing - no prepare of preview paint"); if ( !bStartPageRangeValid ) returnfalse;
bool bStartPosRangeValid =
rProposedStartPos.X() >= 0 && rProposedStartPos.Y() >= 0 &&
rProposedStartPos.X() <= maPreviewDocRect.Right() &&
rProposedStartPos.Y() <= maPreviewDocRect.Bottom();
OSL_ENSURE( bStartPosRangeValid, "proposed start position out of range - no prepare of preview paint"); if ( !bStartPosRangeValid ) returnfalse;
bool bWinSizeValid = !_rPxWinSize.IsEmpty();
OSL_ENSURE( bWinSizeValid, "no window size - no prepare of preview paint"); if ( !bWinSizeValid ) returnfalse;
// determine additional paint offset, if preview layout fits into window.
CalcAdditionalPaintOffset();
// determine rectangle to be painted from document preview
CalcDocPreviewPaintRect();
_orDocPreviewPaintRect = maPaintedPreviewDocRect;
// shift visible preview document area to the left, // if on the right is an area left blank. if ( !mbDoesLayoutColsFitIntoWindow &&
maPaintedPreviewDocRect.GetWidth() < maWinSize.Width() )
{
maPaintedPreviewDocRect.Move(
-(maWinSize.Width() - maPaintedPreviewDocRect.GetWidth()), 0 );
Prepare( 0, maPaintedPreviewDocRect.TopLeft(),
_rPxWinSize, _onStartPageNum,
_orDocPreviewPaintRect, _bStartWithPageAtFirstCol );
}
// shift visible preview document area to the top, // if on the bottom is an area left blank. if ( mbBookPreviewModeToggled &&
maPaintedPreviewDocRect.Bottom() == maPreviewDocRect.Bottom() &&
maPaintedPreviewDocRect.GetHeight() < maWinSize.Height() )
{ if ( mbDoesLayoutRowsFitIntoWindow )
{ if ( maPaintedPreviewDocRect.GetHeight() < mnPreviewLayoutHeight)
{
maPaintedPreviewDocRect.Move(
0, -(mnPreviewLayoutHeight - maPaintedPreviewDocRect.GetHeight()) );
Prepare( 0, maPaintedPreviewDocRect.TopLeft(),
_rPxWinSize, _onStartPageNum,
_orDocPreviewPaintRect, _bStartWithPageAtFirstCol );
}
} else
{
maPaintedPreviewDocRect.Move(
0, -(maWinSize.Height() - maPaintedPreviewDocRect.GetHeight()) );
Prepare( 0, maPaintedPreviewDocRect.TopLeft(),
_rPxWinSize, _onStartPageNum,
_orDocPreviewPaintRect, _bStartWithPageAtFirstCol );
}
}
// determine preview pages - visible pages with needed data for paint and // accessible pages with needed data.
CalcPreviewPages();
// OD 07.11.2003 #i22014# - indicate new layout, if print preview is in paint if ( mbInPaint )
{
mbNewLayoutDuringPaint = true;
}
auto aFoundPreviewPageIter =
std::find_if( maPreviewPages.begin(), maPreviewPages.end(),
PreviewPosInsidePagePred( rPreviewPos ) );
if ( aFoundPreviewPageIter != maPreviewPages.end() )
{ // given preview position is inside a document page.
_onPageNum = (*aFoundPreviewPageIter)->pPage->GetPhyPageNum();
_obPosInEmptyPage = (*aFoundPreviewPageIter)->pPage->IsEmptyPage(); if ( !_obPosInEmptyPage )
{ // given preview position inside a normal page
_orDocPos = rPreviewPos -
(*aFoundPreviewPageIter)->aPreviewWinPos +
(*aFoundPreviewPageIter)->aLogicPos; returntrue;
}
}
// check, if preview layout size values are valid. // If not, the checks for an adjustment of the scroll amount aren't useful. if ( mbLayoutSizesValid )
{ if ( (maPaintedPreviewDocRect.Top() + nScrollAmount) <= 0 )
nScrollAmount = -maPaintedPreviewDocRect.Top();
namespace
{ /// Similar to RenderContextGuard, but does not touch the draw view. class PreviewRenderContextGuard
{
VclPtr<vcl::RenderContext> m_pOriginalValue;
SwViewShell& m_rShell;
// --> OD 2007-08-15 #i80691# // paint page border and shadow
{
SwRect aPageBorderRect;
SwPageFrame::GetBorderAndShadowBoundRect( SwRect( aPageRect ), &mrParentViewShell, &rRenderContext, aPageBorderRect,
bIsLeftShadowed, bIsRightShadowed, true ); const vcl::Region aDLRegion(aPageBorderRect.SVRect());
mrParentViewShell.DLPrePaint2(aDLRegion);
SwPageFrame::PaintBorderAndShadow( SwRect(aPageRect), &mrParentViewShell, true, false, true );
mrParentViewShell.DLPostPaint2(true);
} // <--
} // OD 07.11.2003 #i22014# - stop painting, because new print // preview layout is created during paint. if ( mbNewLayoutDuringPaint )
{ break;
}
if (pPage->GetPhyPageNum() == mnSelectedPageNum)
{
PaintSelectMarkAtPage(rRenderContext, rpPreviewPage.get());
}
}
}
// OD 17.11.2003 #i22014# - no update of accessible preview, if a new // print preview layout is created during paint. #if !ENABLE_WASM_STRIP_ACCESSIBILITY if ( !mbNewLayoutDuringPaint )
{ // update at accessibility interface
mrParentViewShell.Imp()->UpdateAccessiblePreview(
maPreviewPages,
aMapMode.GetScaleX(),
mrLayoutRootFrame.GetPageByPageNum( mnSelectedPageNum ),
maWinSize );
} #endif
// invalidate visible pages, which overlap the invalid core rectangle for ( auto & rpPreviewPage : maPreviewPages )
{ if ( !rpPreviewPage->bVisible ) continue;
OD 17.12.2002 #103492#
*/ void SwPagePreviewLayout::PaintSelectMarkAtPage(vcl::RenderContext& rRenderContext, const PreviewPage* _aSelectedPreviewPage ) const
{
OutputDevice* pOutputDev = &rRenderContext;
MapMode aMapMode( pOutputDev->GetMapMode() ); // save fill and line color and mapping mode of output device
pOutputDev->Push(vcl::PushFlags::FILLCOLOR | vcl::PushFlags::LINECOLOR | vcl::PushFlags::MAPMODE);
// determine selection mark color
Color aSelPgLineColor(117, 114, 106); const StyleSettings& rSettings =
mrParentViewShell.GetWin()->GetSettings().GetStyleSettings(); if ( rSettings.GetHighContrastMode() )
aSelPgLineColor = rSettings.GetHighlightTextColor();
// set needed mapping mode at output device
aMapMode.SetOrigin( _aSelectedPreviewPage->aMapOffset );
pOutputDev->SetMapMode( aMapMode );
// calculate page rectangle in pixel coordinates
SwRect aPageRect( _aSelectedPreviewPage->aLogicPos,
_aSelectedPreviewPage->aPageSize ); // OD 19.02.2003 #107369# - use aligned page rectangle, as it is used for // page border and shadow paint - see <SwPageFrame::PaintBorderAndShadow(..)>
::SwAlignRect( aPageRect, &mrParentViewShell, pOutputDev );
tools::Rectangle aPxPageRect = pOutputDev->LogicToPixel( aPageRect.SVRect() );
// draw two rectangle // OD 19.02.2003 #107369# - adjust position of select mark rectangle
tools::Rectangle aRect( aPxPageRect.Left(), aPxPageRect.Top(),
aPxPageRect.Right(), aPxPageRect.Bottom() );
aRect = pOutputDev->PixelToLogic( aRect );
pOutputDev->SetFillColor(); // OD 20.02.2003 #107369# - no fill color
pOutputDev->SetLineColor( aSelPgLineColor );
pOutputDev->DrawRect( aRect ); // OD 19.02.2003 #107369# - adjust position of select mark rectangle
aRect = tools::Rectangle( aPxPageRect.Left()+1, aPxPageRect.Top()+1,
aPxPageRect.Right()-1, aPxPageRect.Bottom()-1 );
aRect = pOutputDev->PixelToLogic( aRect );
pOutputDev->DrawRect( aRect );
// reset fill and line color and mapping mode of output device
pOutputDev->Pop();
}
/** paint to mark new selected page
OD 17.12.2002 #103492# Perform paint for current selected page in order to unmark it. Set new selected page and perform paint to mark this page.
// re-paint for current selected page in order to unmark it. const PreviewPage* pOldSelectedPreviewPage = GetPreviewPageByPageNum( nOldSelectedPageNum );
OutputDevice* pOutputDev = mrParentViewShell.GetOut(); if ( pOldSelectedPreviewPage && pOldSelectedPreviewPage->bVisible )
{ // OD 20.02.2003 #107369# - invalidate only areas of selection mark.
SwRect aPageRect( pOldSelectedPreviewPage->aPreviewWinPos,
pOldSelectedPreviewPage->aPageSize );
::SwAlignRect( aPageRect, &mrParentViewShell, pOutputDev );
tools::Rectangle aPxPageRect = pOutputDev->LogicToPixel( aPageRect.SVRect() ); // invalidate top mark line
tools::Rectangle aInvalPxRect( aPxPageRect.Left(), aPxPageRect.Top(),
aPxPageRect.Right(), aPxPageRect.Top()+1 );
mrParentViewShell.GetWin()->Invalidate( pOutputDev->PixelToLogic( aInvalPxRect ) ); // invalidate right mark line
aInvalPxRect = tools::Rectangle( aPxPageRect.Right()-1, aPxPageRect.Top(),
aPxPageRect.Right(), aPxPageRect.Bottom() );
mrParentViewShell.GetWin()->Invalidate( pOutputDev->PixelToLogic( aInvalPxRect ) ); // invalidate bottom mark line
aInvalPxRect = tools::Rectangle( aPxPageRect.Left(), aPxPageRect.Bottom()-1,
aPxPageRect.Right(), aPxPageRect.Bottom() );
mrParentViewShell.GetWin()->Invalidate( pOutputDev->PixelToLogic( aInvalPxRect ) ); // invalidate left mark line
aInvalPxRect = tools::Rectangle( aPxPageRect.Left(), aPxPageRect.Top(),
aPxPageRect.Left()+1, aPxPageRect.Bottom() );
mrParentViewShell.GetWin()->Invalidate( pOutputDev->PixelToLogic( aInvalPxRect ) );
}
// re-paint for new selected page in order to mark it. const PreviewPage* pNewSelectedPreviewPage = GetPreviewPageByPageNum( _nSelectedPage ); if ( pNewSelectedPreviewPage && pNewSelectedPreviewPage->bVisible )
{ const PreviewPage* pSelectedPreviewPage = GetPreviewPageByPageNum(mnSelectedPageNum);
SwRect aPageRect(pSelectedPreviewPage->aPreviewWinPos, pSelectedPreviewPage->aPageSize);
::SwAlignRect(aPageRect, &mrParentViewShell, pOutputDev);
mrParentViewShell.GetWin()->Invalidate(aPageRect.SVRect());
}
}
if ( aFoundPreviewPageIter == maPreviewPages.end() ) return nullptr;
return aFoundPreviewPageIter->get();
}
/** determine row the page with the given number is in
OD 17.01.2003 #103492#
@note _nPageNum is relative
*/
sal_uInt16 SwPagePreviewLayout::GetRowOfPage( sal_uInt16 _nPageNum ) const
{ // OD 19.02.2003 #107369# - leaving left-top-corner blank is controlled // by <mbBookPreview>. if ( mbBookPreview )
{ // Note: increase given physical page number by one, because left-top-corner // in the preview layout is left blank.
++_nPageNum;
}
/** determine column the page with the given number is in
OD 17.01.2003 #103492#
@note _nPageNum is relative
*/
sal_uInt16 SwPagePreviewLayout::GetColOfPage( sal_uInt16 _nPageNum ) const
{ // OD 19.02.2003 #107369# - leaving left-top-corner blank is controlled // by <mbBookPreview>. if ( mbBookPreview )
{ // Note: increase given physical page number by one, because left-top-corner // in the preview layout is left blank.
++_nPageNum;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.