#define SCROLL_LINE_FACT 0.05///< factor for line scrolling #define SCROLL_PAGE_FACT 0.5///< factor for page scrolling #define SCROLL_SENSITIVE 20///< sensitive area in pixel #define ZOOM_MULTIPLICATOR 10000///< multiplier to avoid rounding errors #define MIN_ZOOM 5///< minimal zoom factor #define MAX_ZOOM 3000///< maximal zoom factor
Window::Window(vcl::Window* pParent)
: vcl::DocWindow(pParent, WinBits(WB_CLIPCHILDREN | WB_DIALOGCONTROL)),
DropTargetHelper( this ),
maWinPos(0, 0), // precautionary; but the values should be set
maViewOrigin(0, 0), // again from the owner of the window
maViewSize(1000, 1000),
maPrevSize(-1,-1),
mnMinZoom(MIN_ZOOM),
mnMaxZoom(MAX_ZOOM),
mbMinZoomAutoCalc(false),
mbCenterAllowed(true),
mnTicks (0),
mpViewShell(nullptr),
mbUseDropScroll (true)
{
SetDialogControlFlags( DialogControlFlags::Return | DialogControlFlags::WantFocus );
void Window::SetViewShell (ViewShell* pViewSh)
{
WindowUpdater* pWindowUpdater = nullptr; // Unregister at device updater of old view shell. if (mpViewShell != nullptr)
{
pWindowUpdater = mpViewShell->GetWindowUpdater(); if (pWindowUpdater != nullptr)
pWindowUpdater->UnregisterWindow (this);
}
mpViewShell = pViewSh;
// Register at device updater of new view shell if (mpViewShell != nullptr)
{
pWindowUpdater = mpViewShell->GetWindowUpdater(); if (pWindowUpdater != nullptr)
pWindowUpdater->RegisterWindow (this);
}
}
void Window::CalcMinZoom()
{ // Are we entitled to change the minimal zoom factor? if ( !mbMinZoomAutoCalc ) return;
// Get current zoom factor.
::tools::Long nZoom = GetZoom();
// Get the rectangle of the output area in logical coordinates // and calculate the scaling factors that would lead to the view // area (also called application area) to completely fill the // window.
Size aWinSize = PixelToLogic(GetOutputSizePixel());
sal_uLong nX = static_cast<sal_uLong>(static_cast<double>(aWinSize.Width())
* double(ZOOM_MULTIPLICATOR) / static_cast<double>(maViewSize.Width()));
sal_uLong nY = static_cast<sal_uLong>(static_cast<double>(aWinSize.Height())
* double(ZOOM_MULTIPLICATOR) / static_cast<double>(maViewSize.Height()));
// Decide whether to take the larger or the smaller factor.
sal_uLong nFact = std::min(nX, nY);
// The factor is transformed according to the current zoom factor.
nFact = nFact * nZoom / ZOOM_MULTIPLICATOR;
mnMinZoom = std::max(sal_uInt16(MIN_ZOOM), static_cast<sal_uInt16>(nFact));
// If the current zoom factor is smaller than the calculated minimal // zoom factor then set the new minimal factor as the current zoom // factor. if ( nZoom < static_cast<::tools::Long>(mnMinZoom) )
SetZoomFactor(mnMinZoom);
}
if ( mpViewShell )
mpViewShell->MouseButtonUp(rMEvt, this);
}
void Window::Command(const CommandEvent& rCEvt)
{ if (mpViewShell)
mpViewShell->Command(rCEvt, this); //pass at least alt press/release to parent impl if (rCEvt.GetCommand() == CommandEventId::ModKeyChange)
vcl::Window::Command(rCEvt); //show the text edit outliner view cursor elseif (mpViewShell && !HasFocus() && rCEvt.GetCommand() == CommandEventId::CursorPos)
{ // tdf#138855 Getting Focus may destroy TextEditOutlinerView so Grab if // text editing active, but fetch the TextEditOutlinerView post-grab if (mpViewShell->GetView()->IsTextEdit())
{
GrabFocus();
OutlinerView* pOLV = mpViewShell->GetView()->GetTextEditOutlinerView(); if (pOLV && this == pOLV->GetWindow())
pOLV->ShowCursor();
}
}
}
::tools::Long Window::SetZoomFactor(::tools::Long nZoom)
{ // Clip the zoom factor to the valid range marked by nMinZoom as // calculated by CalcMinZoom() and the constant MAX_ZOOM. if ( nZoom > MAX_ZOOM )
nZoom = MAX_ZOOM; if ( nZoom < static_cast<::tools::Long>(mnMinZoom) )
nZoom = mnMinZoom;
// Set the zoom factor at the window's map mode. if (!comphelper::LibreOfficeKit::isActive())
{
MapMode aMap(GetMapMode());
aMap.SetScaleX(Fraction(nZoom, 100));
aMap.SetScaleY(Fraction(nZoom, 100));
SetMapMode(aMap);
}
// invalidate previous size - it was relative to the old scaling
maPrevSize = Size(-1,-1);
// Update the map mode's origin (to what effect?).
UpdateMapOrigin();
// Update the view's snapping to the new zoom factor. if ( auto pDrawViewShell = dynamic_cast< DrawViewShell *>( mpViewShell ) )
pDrawViewShell->GetView()->RecalcLogicSnapMagnetic(*GetOutDev());
// Return the zoom factor just in case it has been changed above to lie // inside the valid range. return nZoom;
}
void Window::SetZoomIntegral(::tools::Long nZoom)
{ // Clip the zoom factor to the valid range marked by nMinZoom as // previously calculated by <member>CalcMinZoom()</member> and the // MAX_ZOOM constant. if ( nZoom > MAX_ZOOM )
nZoom = MAX_ZOOM; if ( nZoom < static_cast<::tools::Long>(mnMinZoom) )
nZoom = mnMinZoom;
if( (rZoomRect.GetWidth() != 0) && (rZoomRect.GetHeight() != 0))
{ // Calculate the scale factors which will lead to the given // rectangle being fully visible (when translated accordingly) as // large as possible in the output area independently in both // coordinate directions .
sal_uLong nX(0);
sal_uLong nY(0);
if(rZoomRect.GetWidth())
{
nY = static_cast<sal_uLong>(static_cast<double>(aWinSize.Width())
* double(ZOOM_MULTIPLICATOR) / static_cast<double>(rZoomRect.GetWidth()));
}
// Use the smaller one of both so that the zoom rectangle will be // fully visible with respect to both coordinate directions.
sal_uLong nFact = std::min(nX, nY);
// Transform the current zoom factor so that it leads to the desired // scaling.
nRetZoom = nFact * GetZoom() / ZOOM_MULTIPLICATOR;
// Calculate the new origin. if ( nFact == 0 )
{ // Don't change anything if the scale factor is degenerate.
nRetZoom = GetZoom();
} else
{ // Clip the zoom factor to the valid range marked by nMinZoom as // previously calculated by <member>CalcMinZoom()</member> and the // MAX_ZOOM constant. if ( nRetZoom > MAX_ZOOM )
nRetZoom = MAX_ZOOM; if ( nRetZoom < static_cast<::tools::Long>(mnMinZoom) )
nRetZoom = mnMinZoom;
}
}
return nRetZoom;
}
/** Recalculate the zoom factor and translation so that the given rectangle isdisplayedcenteredandaslargeaspossiblewhilestillbeingfully visibleinthewindow.
*/
::tools::Long Window::SetZoomRect (const ::tools::Rectangle& rZoomRect)
{
::tools::Long nNewZoom = 100;
if (rZoomRect.GetWidth() == 0 || rZoomRect.GetHeight() == 0)
{ // The given rectangle is degenerate. Use the default zoom factor // (above) of 100%.
SetZoomIntegral(nNewZoom);
} else
{
Point aPos = rZoomRect.TopLeft(); // Transform the output area from pixel coordinates into logical // coordinates.
Size aWinSize = PixelToLogic(GetOutputSizePixel()); // Paranoia! The degenerate case of zero width or height has been // taken care of above.
DBG_ASSERT(rZoomRect.GetWidth(), "ZoomRect-Width = 0!");
DBG_ASSERT(rZoomRect.GetHeight(), "ZoomRect-Height = 0!");
// Calculate the scale factors which will lead to the given // rectangle being fully visible (when translated accordingly) as // large as possible in the output area independently in both // coordinate directions .
sal_uLong nX(0);
sal_uLong nY(0);
if(rZoomRect.GetWidth())
{
nY = static_cast<sal_uLong>(static_cast<double>(aWinSize.Width())
* double(ZOOM_MULTIPLICATOR) / static_cast<double>(rZoomRect.GetWidth()));
}
// Use the smaller one of both so that the zoom rectangle will be // fully visible with respect to both coordinate directions.
sal_uLong nFact = std::min(nX, nY);
// Transform the current zoom factor so that it leads to the desired // scaling.
::tools::Long nZoom = nFact * GetZoom() / ZOOM_MULTIPLICATOR;
// Calculate the new origin. if ( nFact == 0 )
{ // Don't change anything if the scale factor is degenerate.
nNewZoom = GetZoom();
} else
{ // Calculate the new window position that centers the given // rectangle on the screen. if ( nZoom > MAX_ZOOM )
nFact = nFact * MAX_ZOOM / nZoom;
// When tiled rendering, the above UpdateMapMode() call doesn't touch the map mode. if (bChanged && bInvalidate && !comphelper::LibreOfficeKit::isActive())
Invalidate();
}
void Window::UpdateMapMode()
{
maWinPos -= maViewOrigin;
Size aPix(maWinPos.X(), maWinPos.Y());
aPix = LogicToPixel(aPix); // Size has to be a multiple of BRUSH_SIZE due to the correct depiction of // pattern // #i2237# // removed old stuff here which still forced zoom to be // %BRUSH_SIZE which is outdated now
if (dynamic_cast< DrawViewShell *>( mpViewShell ))
{ // page should not "stick" to the window border if (aPix.Width() == 0)
{ // #i2237# // Since BRUSH_SIZE alignment is outdated now, i use the // former constant here directly
aPix.AdjustWidth( -8 );
} if (aPix.Height() == 0)
{ // #i2237# // Since BRUSH_SIZE alignment is outdated now, i use the // former constant here directly
aPix.AdjustHeight( -8 );
}
}
/* Omit PRINTER by all documents which are not using a printer. OmitFONTSandFONTSUBSTITUTIONifnotextoutputisavailableorifthe
document does not allow text. */
if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
(rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
{ /* Rearrange or initiate Resize for scroll bars since the size of thescrollbarsmyhavechanged.Withinthis,insidetheresize- handler,thesizeofthescrollbarswillbeaskedfromthe
Settings. */
Resize();
/* Re-set data, which are from system control or from Settings. May havetore-setmoredatasincetheresolutionmayalsohas
changed. */ if( mpViewShell )
{ const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
DrawModeFlags nOutputMode;
sal_uInt16 nPreviewSlot;
// re-create handles to show new outfit if(dynamic_cast< DrawViewShell *>( mpViewShell ) != nullptr)
{
mpViewShell->GetView()->AdjustMarkHdl();
}
}
}
if ( (rDCEvt.GetType() == DataChangedEventType::DISPLAY) ||
((rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
(rDCEvt.GetFlags() & AllSettingsFlags::STYLE)) )
{ /* Virtual devices, which also depends on the resolution or the systemcontrol,shouldbeupdated.Otherwise,weshouldupdate thevirtualdevicesatleastatDataChangedEventType::DISPLAYsincesome systemsallowtochangetheresolutionandcolordepthduring runtime.Orthevirtualdeviceshavetobeupdatedwhenthecolor palettehaschangedsinceadifferentcolormatchingcanbeused
when outputting. */
}
if ( rDCEvt.GetType() == DataChangedEventType::FONTS )
{ /* If the document provides font choose boxes, we have to update them.Idon'tknowhowthislookslike(alsonotreallyme,I onlytranslatedthecomment;).Wemaycanhandleitglobal.We havetodiscussitwithPB,butheisillatthemoment.
Before we handle it here, discuss it with PB and me. */
}
if ( (rDCEvt.GetType() == DataChangedEventType::FONTS) ||
(rDCEvt.GetType() == DataChangedEventType::FONTSUBSTITUTION) )
{ /* Do reformatting since the fonts of the document may no longer
exist, or exist now, or are replaced with others. */ if( mpViewShell )
{
DrawDocShell* pDocSh = mpViewShell->GetDocSh(); if( pDocSh )
pDocSh->SetPrinter( pDocSh->GetPrinter( true ) );
}
}
if ( rDCEvt.GetType() == DataChangedEventType::PRINTER )
{ /* I don't know how the handling should look like. Maybe we delete a printerandlookwhatwehavetodo.MaybeIhavetoadd somethingtotheVCL,incasetheusedprinterisdeleted. OtherwiseImayrecalculatetheformattinghereifthecurrent
printer is destroyed. */ if( mpViewShell )
{
DrawDocShell* pDocSh = mpViewShell->GetDocSh(); if( pDocSh )
pDocSh->SetPrinter( pDocSh->GetPrinter( true ) );
}
}
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.