Files
libreoffice/sd/source/ui/func/fuscale.cxx

186 lines
6.0 KiB
C++
Raw Normal View History

/* -*- 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 .
*/
2000-09-18 16:07:07 +00:00
#include <fuscale.hxx>
2000-09-18 16:07:07 +00:00
#include <svx/dialogs.hrc>
#include <app.hrc>
#include <View.hxx>
#include <Window.hxx>
#include <OutlineViewShell.hxx>
#include <drawview.hxx>
#include <drawdoc.hxx>
#include <DrawViewShell.hxx>
#include <ViewShell.hxx>
#include <fuzoom.hxx>
2000-09-18 16:07:07 +00:00
#include <vcl/msgbox.hxx>
#include <svx/svdpagv.hxx>
#include <sfx2/viewfrm.hxx>
#include <sfx2/dispatch.hxx>
#include <svx/zoom_def.hxx>
#include <sfx2/zoomitem.hxx>
2000-09-18 16:07:07 +00:00
#include <sfx2/request.hxx>
#include <svx/svxdlg.hxx>
#include <memory>
2000-09-18 16:07:07 +00:00
namespace sd {
2000-09-18 16:07:07 +00:00
FuScale::FuScale (
ViewShell* pViewSh,
::sd::Window* pWin,
::sd::View* pView,
SdDrawDocument* pDoc,
SfxRequest& rReq)
: FuPoor(pViewSh, pWin, pView, pDoc, rReq)
{
}
rtl::Reference<FuPoor> FuScale::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
{
rtl::Reference<FuPoor> xFunc( new FuScale( pViewSh, pWin, pView, pDoc, rReq ) );
xFunc->DoExecute(rReq);
return xFunc;
}
void FuScale::DoExecute( SfxRequest& rReq )
2000-09-18 16:07:07 +00:00
{
sal_Int16 nValue;
2000-09-18 16:07:07 +00:00
const SfxItemSet* pArgs = rReq.GetArgs();
if( !pArgs )
{
Make SfxItemSet ranges correct by construction This is a follow-up to 45a7f5b62d0b1b21763c1c94255ef2309ea4280b "Keep WID ranges sorted, and join adjacent ones". While SfxItemSet::MergeRange relies on the m_pWhichRanges being sorted (and, under DBG_UTIL, asserts if they are not), the various SfxItemSet constructors curiously only check (via assert or DBG_ASSERT) that each individual range has an upper bound not smaller than its lower bound. Arguably, all SfxItemSet instances should fulfill the stronger guarantees required and checked by MergeRange. And in many cases the ranges are statically known, so that the checking can happen at compile time. Therefore, replace the two SfxItemSet ctors taking explicit ranges with two other ctors that actually do proper checking. The (templated) overload taking an svl::Items struct should be used in all cases where the range values are statically known at compile time, while the overload taking a std::initializer_list<Pair> is for the remaining cases (that can only do runtime checking via assert). Most of those latter cases are simple cases with a single range covering a single item, but a few are more complex. (At least some of the uses of the existing SfxItemSet overload taking a const sal_uInt16* pWhichPairTable can probably also be strengthened, but that is left for another day.) This commit is the first in a series of two. Apart from the manual changes to compilerplugins/clang/store/sfxitemsetrewrite.cxx, include/svl/itemset.hxx, and svl/source/items/itemset.cxx, it only consists of automatic rewriting of the relevant SfxItemSet ctor calls (plus a few required manual fixes, see next). But it does not yet check that the individual ranges are properly sorted (see the TODO in svl::detail::validGap). That check will be enabled, and the ensuing manual fixes will be made in a follow-up commit, to reduce the likelyhood of accidents. There were three cases of necessary manual intervention: * sw/source/core/unocore/unostyle.cxx uses eAtr of enum type RES_FRMATR in braced-init-list syntax now, so needs explicit narrowing conversion to sal_uInt16. * In sw/source/uibase/uiview/formatclipboard.cxx, the trailiing comma in the definition of macro FORMAT_PAINTBRUSH_FRAME_IDS needed to be removed manually. * In svx/source/svdraw/svdoashp.cxx, svx/source/svdraw/svdotext.cxx, sw/source/uibase/app/docstyle.cxx, sw/source/uibase/shells/frmsh.cxx, sw/source/uibase/shells/grfsh.cxx, and sw/source/uibase/shells/textsh1.cxx, some comments had to be put back (see "TODO: the replaced range can contain relevant comments" in compilerplugins/clang/store/sfxitemsetrewrite.cxx). A few uses of the variadic form erroneously used nullptr instead of 0 for termination. But this should have been harmless even if promoted std::nullptr_t is larger than promoted sal_uInt16, assuming that the part of the nullptr value that was interpreted as sal_uInt16/promoted int was all-zero bits. Similarly, some uses made the harmless error of using 0L instead of 0. Change-Id: I2afea97282803cb311b9321a99bb627520ef5e35 Reviewed-on: https://gerrit.libreoffice.org/38861 Reviewed-by: Stephan Bergmann <sbergman@redhat.com> Tested-by: Stephan Bergmann <sbergman@redhat.com>
2017-06-16 09:58:13 +02:00
SfxItemSet aNewAttr( mpDoc->GetPool(), svl::Items<SID_ATTR_ZOOM, SID_ATTR_ZOOM>{} );
std::unique_ptr<SvxZoomItem> pZoomItem;
SvxZoomEnableFlags nZoomValues = SvxZoomEnableFlags::ALL;
2000-09-18 16:07:07 +00:00
nValue = (sal_Int16) mpWindow->GetZoom();
2000-09-18 16:07:07 +00:00
// zoom on page size?
if( mpViewShell && dynamic_cast< DrawViewShell *>( mpViewShell ) != nullptr &&
static_cast<DrawViewShell*>(mpViewShell)->IsZoomOnPage() )
2000-09-18 16:07:07 +00:00
{
pZoomItem.reset(new SvxZoomItem( SvxZoomType::WHOLEPAGE, nValue ));
2000-09-18 16:07:07 +00:00
}
else
{
pZoomItem.reset(new SvxZoomItem( SvxZoomType::PERCENT, nValue ));
2000-09-18 16:07:07 +00:00
}
// limit range
if( mpViewShell )
2000-09-18 16:07:07 +00:00
{
if( dynamic_cast< DrawViewShell *>( mpViewShell ) != nullptr )
{
SdrPageView* pPageView = mpView->GetSdrPageView();
if( pPageView && pPageView->GetObjList()->GetObjCount() == 0 )
{
nZoomValues &= ~SvxZoomEnableFlags::OPTIMAL;
}
}
else if( dynamic_cast< OutlineViewShell *>( mpViewShell ) != nullptr )
2000-09-18 16:07:07 +00:00
{
nZoomValues &= ~SvxZoomEnableFlags::OPTIMAL;
nZoomValues &= ~SvxZoomEnableFlags::WHOLEPAGE;
nZoomValues &= ~SvxZoomEnableFlags::PAGEWIDTH;
}
2000-09-18 16:07:07 +00:00
}
pZoomItem->SetValueSet( nZoomValues );
aNewAttr.Put( *pZoomItem );
SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
ScopedVclPtr<AbstractSvxZoomDialog> pDlg(pFact ? pFact->CreateSvxZoomDialog(nullptr, aNewAttr) : nullptr);
if (pDlg)
2000-09-18 16:07:07 +00:00
{
pDlg->SetLimits( (sal_uInt16)mpWindow->GetMinZoom(), (sal_uInt16)mpWindow->GetMaxZoom() );
sal_uInt16 nResult = pDlg->Execute();
switch( nResult )
2000-09-18 16:07:07 +00:00
{
case RET_CANCEL:
{
rReq.Ignore ();
return; // Cancel
}
default:
{
rReq.Ignore ();
}
break;
2000-09-18 16:07:07 +00:00
}
const SfxItemSet aArgs (*(pDlg->GetOutputItemSet ()));
2000-09-18 16:07:07 +00:00
pDlg.disposeAndClear();
if (!mpViewShell)
return;
switch (static_cast<const SvxZoomItem &>( aArgs.Get (SID_ATTR_ZOOM)).GetType ())
2000-09-18 16:07:07 +00:00
{
case SvxZoomType::PERCENT:
{
nValue = static_cast<const SvxZoomItem &>( aArgs.Get (SID_ATTR_ZOOM)).GetValue ();
2000-09-18 16:07:07 +00:00
mpViewShell->SetZoom( nValue );
2000-09-18 16:07:07 +00:00
mpViewShell->GetViewFrame()->GetBindings().Invalidate( SidArrayZoom );
}
break;
2000-09-18 16:07:07 +00:00
case SvxZoomType::OPTIMAL:
2000-09-18 16:07:07 +00:00
{
if( dynamic_cast< DrawViewShell *>( mpViewShell ) != nullptr )
{
// name confusion: SID_SIZE_ALL -> zoom onto all objects
// --> the program offers it as optimal
mpViewShell->GetViewFrame()->GetDispatcher()->Execute( SID_SIZE_ALL, SfxCallMode::ASYNCHRON | SfxCallMode::RECORD);
}
2000-09-18 16:07:07 +00:00
}
break;
case SvxZoomType::PAGEWIDTH:
mpViewShell->GetViewFrame()->GetDispatcher()->Execute( SID_SIZE_PAGE_WIDTH, SfxCallMode::ASYNCHRON | SfxCallMode::RECORD);
break;
case SvxZoomType::WHOLEPAGE:
mpViewShell->GetViewFrame()->GetDispatcher()->Execute(SID_SIZE_PAGE, SfxCallMode::ASYNCHRON | SfxCallMode::RECORD);
break;
default:
break;
}
2000-09-18 16:07:07 +00:00
}
}
else if(mpViewShell && (pArgs->Count () == 1))
2000-09-18 16:07:07 +00:00
{
const SfxUInt32Item* pScale = rReq.GetArg<SfxUInt32Item>(ID_VAL_ZOOM);
mpViewShell->SetZoom (pScale->GetValue ());
2000-09-18 16:07:07 +00:00
mpViewShell->GetViewFrame()->GetBindings().Invalidate( SidArrayZoom );
2000-09-18 16:07:07 +00:00
}
}
} // end of namespace sd
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */