Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / sd / source / ui / func / fuscale.cxx
blobe1b2dba2a4bc43a6a9582a647b4dcb83e2b8f37d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <fuscale.hxx>
22 #include <svx/dialogs.hrc>
24 #include <app.hrc>
25 #include <View.hxx>
26 #include <Window.hxx>
27 #include <OutlineViewShell.hxx>
28 #include <drawview.hxx>
29 #include <drawdoc.hxx>
30 #include <DrawViewShell.hxx>
31 #include <ViewShell.hxx>
32 #include <fuzoom.hxx>
34 #include <svx/svdpagv.hxx>
35 #include <sfx2/viewfrm.hxx>
36 #include <sfx2/dispatch.hxx>
37 #include <svx/zoom_def.hxx>
38 #include <sfx2/zoomitem.hxx>
39 #include <sfx2/request.hxx>
40 #include <svx/svxdlg.hxx>
41 #include <memory>
43 namespace sd {
46 FuScale::FuScale (
47 ViewShell* pViewSh,
48 ::sd::Window* pWin,
49 ::sd::View* pView,
50 SdDrawDocument* pDoc,
51 SfxRequest& rReq)
52 : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
56 rtl::Reference<FuPoor> FuScale::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
58 rtl::Reference<FuPoor> xFunc( new FuScale( pViewSh, pWin, pView, pDoc, rReq ) );
59 xFunc->DoExecute(rReq);
60 return xFunc;
63 void FuScale::DoExecute( SfxRequest& rReq )
65 sal_Int16 nValue;
67 const SfxItemSet* pArgs = rReq.GetArgs();
69 if( !pArgs )
71 SfxItemSet aNewAttr( mpDoc->GetPool(), svl::Items<SID_ATTR_ZOOM, SID_ATTR_ZOOM>{} );
72 std::unique_ptr<SvxZoomItem> pZoomItem;
73 SvxZoomEnableFlags nZoomValues = SvxZoomEnableFlags::ALL;
75 nValue = static_cast<sal_Int16>(mpWindow->GetZoom());
77 // zoom on page size?
78 if( mpViewShell && dynamic_cast< DrawViewShell *>( mpViewShell ) != nullptr &&
79 static_cast<DrawViewShell*>(mpViewShell)->IsZoomOnPage() )
81 pZoomItem.reset(new SvxZoomItem( SvxZoomType::WHOLEPAGE, nValue ));
83 else
85 pZoomItem.reset(new SvxZoomItem( SvxZoomType::PERCENT, nValue ));
88 // limit range
89 if( mpViewShell )
91 if( dynamic_cast< DrawViewShell *>( mpViewShell ) != nullptr )
93 SdrPageView* pPageView = mpView->GetSdrPageView();
94 if( pPageView && pPageView->GetObjList()->GetObjCount() == 0 )
96 nZoomValues &= ~SvxZoomEnableFlags::OPTIMAL;
99 else if( dynamic_cast< OutlineViewShell *>( mpViewShell ) != nullptr )
101 nZoomValues &= ~SvxZoomEnableFlags::OPTIMAL;
102 nZoomValues &= ~SvxZoomEnableFlags::WHOLEPAGE;
103 nZoomValues &= ~SvxZoomEnableFlags::PAGEWIDTH;
107 pZoomItem->SetValueSet( nZoomValues );
108 aNewAttr.Put( *pZoomItem );
110 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
111 ScopedVclPtr<AbstractSvxZoomDialog> pDlg(pFact ? pFact->CreateSvxZoomDialog(rReq.GetFrameWeld(), aNewAttr) : nullptr);
112 if (pDlg)
114 pDlg->SetLimits( static_cast<sal_uInt16>(mpWindow->GetMinZoom()), static_cast<sal_uInt16>(mpWindow->GetMaxZoom()) );
115 sal_uInt16 nResult = pDlg->Execute();
116 switch( nResult )
118 case RET_CANCEL:
120 rReq.Ignore ();
121 return; // Cancel
123 default:
125 rReq.Ignore ();
127 break;
130 const SfxItemSet aArgs (*(pDlg->GetOutputItemSet ()));
132 pDlg.disposeAndClear();
134 if (!mpViewShell)
135 return;
137 switch ( aArgs.Get (SID_ATTR_ZOOM).GetType ())
139 case SvxZoomType::PERCENT:
141 nValue = aArgs.Get (SID_ATTR_ZOOM).GetValue ();
143 mpViewShell->SetZoom( nValue );
145 mpViewShell->GetViewFrame()->GetBindings().Invalidate( SidArrayZoom );
147 break;
149 case SvxZoomType::OPTIMAL:
151 if( dynamic_cast< DrawViewShell *>( mpViewShell ) != nullptr )
153 // name confusion: SID_SIZE_ALL -> zoom onto all objects
154 // --> the program offers it as optimal
155 mpViewShell->GetViewFrame()->GetDispatcher()->Execute( SID_SIZE_ALL, SfxCallMode::ASYNCHRON | SfxCallMode::RECORD);
158 break;
160 case SvxZoomType::PAGEWIDTH:
161 mpViewShell->GetViewFrame()->GetDispatcher()->Execute( SID_SIZE_PAGE_WIDTH, SfxCallMode::ASYNCHRON | SfxCallMode::RECORD);
162 break;
164 case SvxZoomType::WHOLEPAGE:
165 mpViewShell->GetViewFrame()->GetDispatcher()->Execute(SID_SIZE_PAGE, SfxCallMode::ASYNCHRON | SfxCallMode::RECORD);
166 break;
167 default:
168 break;
172 else if(mpViewShell && (pArgs->Count () == 1))
174 const SfxUInt32Item* pScale = rReq.GetArg<SfxUInt32Item>(ID_VAL_ZOOM);
175 mpViewShell->SetZoom (pScale->GetValue ());
177 mpViewShell->GetViewFrame()->GetBindings().Invalidate( SidArrayZoom );
182 } // end of namespace sd
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */