bump product version to 6.3.0.0.beta1
[LibreOffice.git] / sd / source / ui / func / fuscale.cxx
blob9bcca7f95b3bff732534817ff97eda3c175c8a7f
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/svxids.hrc>
24 #include <app.hrc>
25 #include <View.hxx>
26 #include <Window.hxx>
27 #include <OutlineViewShell.hxx>
28 #include <drawdoc.hxx>
29 #include <DrawViewShell.hxx>
30 #include <ViewShell.hxx>
31 #include <fuzoom.hxx>
33 #include <svx/svdpagv.hxx>
34 #include <sfx2/viewfrm.hxx>
35 #include <sfx2/dispatch.hxx>
36 #include <sfx2/zoomitem.hxx>
37 #include <sfx2/request.hxx>
38 #include <svx/svxdlg.hxx>
39 #include <memory>
41 namespace sd {
44 FuScale::FuScale (
45 ViewShell* pViewSh,
46 ::sd::Window* pWin,
47 ::sd::View* pView,
48 SdDrawDocument* pDoc,
49 SfxRequest& rReq)
50 : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
54 rtl::Reference<FuPoor> FuScale::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
56 rtl::Reference<FuPoor> xFunc( new FuScale( pViewSh, pWin, pView, pDoc, rReq ) );
57 xFunc->DoExecute(rReq);
58 return xFunc;
61 void FuScale::DoExecute( SfxRequest& rReq )
63 sal_Int16 nValue;
65 const SfxItemSet* pArgs = rReq.GetArgs();
67 if( !pArgs )
69 SfxItemSet aNewAttr( mpDoc->GetPool(), svl::Items<SID_ATTR_ZOOM, SID_ATTR_ZOOM>{} );
70 std::unique_ptr<SvxZoomItem> pZoomItem;
71 SvxZoomEnableFlags nZoomValues = SvxZoomEnableFlags::ALL;
73 nValue = static_cast<sal_Int16>(mpWindow->GetZoom());
75 // zoom on page size?
76 if( dynamic_cast< DrawViewShell *>( mpViewShell ) &&
77 static_cast<DrawViewShell*>(mpViewShell)->IsZoomOnPage() )
79 pZoomItem.reset(new SvxZoomItem( SvxZoomType::WHOLEPAGE, nValue ));
81 else
83 pZoomItem.reset(new SvxZoomItem( SvxZoomType::PERCENT, nValue ));
86 // limit range
87 if( mpViewShell )
89 if( dynamic_cast< DrawViewShell *>( mpViewShell ) != nullptr )
91 SdrPageView* pPageView = mpView->GetSdrPageView();
92 if( pPageView && pPageView->GetObjList()->GetObjCount() == 0 )
94 nZoomValues &= ~SvxZoomEnableFlags::OPTIMAL;
97 else if( dynamic_cast< OutlineViewShell *>( mpViewShell ) != nullptr )
99 nZoomValues &= ~SvxZoomEnableFlags::OPTIMAL;
100 nZoomValues &= ~SvxZoomEnableFlags::WHOLEPAGE;
101 nZoomValues &= ~SvxZoomEnableFlags::PAGEWIDTH;
105 pZoomItem->SetValueSet( nZoomValues );
106 aNewAttr.Put( *pZoomItem );
108 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
109 ScopedVclPtr<AbstractSvxZoomDialog> pDlg(pFact->CreateSvxZoomDialog(rReq.GetFrameWeld(), aNewAttr));
110 pDlg->SetLimits( static_cast<sal_uInt16>(mpWindow->GetMinZoom()), static_cast<sal_uInt16>(mpWindow->GetMaxZoom()) );
111 sal_uInt16 nResult = pDlg->Execute();
112 switch( nResult )
114 case RET_CANCEL:
116 rReq.Ignore ();
117 return; // Cancel
119 default:
121 rReq.Ignore ();
123 break;
126 const SfxItemSet aArgs (*(pDlg->GetOutputItemSet ()));
128 pDlg.disposeAndClear();
130 if (!mpViewShell)
131 return;
133 switch ( aArgs.Get (SID_ATTR_ZOOM).GetType ())
135 case SvxZoomType::PERCENT:
137 nValue = aArgs.Get (SID_ATTR_ZOOM).GetValue ();
139 mpViewShell->SetZoom( nValue );
141 mpViewShell->GetViewFrame()->GetBindings().Invalidate( SidArrayZoom );
143 break;
145 case SvxZoomType::OPTIMAL:
147 if( dynamic_cast< DrawViewShell *>( mpViewShell ) != nullptr )
149 // name confusion: SID_SIZE_ALL -> zoom onto all objects
150 // --> the program offers it as optimal
151 mpViewShell->GetViewFrame()->GetDispatcher()->Execute( SID_SIZE_ALL, SfxCallMode::ASYNCHRON | SfxCallMode::RECORD);
154 break;
156 case SvxZoomType::PAGEWIDTH:
157 mpViewShell->GetViewFrame()->GetDispatcher()->Execute( SID_SIZE_PAGE_WIDTH, SfxCallMode::ASYNCHRON | SfxCallMode::RECORD);
158 break;
160 case SvxZoomType::WHOLEPAGE:
161 mpViewShell->GetViewFrame()->GetDispatcher()->Execute(SID_SIZE_PAGE, SfxCallMode::ASYNCHRON | SfxCallMode::RECORD);
162 break;
163 default:
164 break;
167 else if(mpViewShell && (pArgs->Count () == 1))
169 const SfxUInt32Item* pScale = rReq.GetArg<SfxUInt32Item>(ID_VAL_ZOOM);
170 mpViewShell->SetZoom (pScale->GetValue ());
172 mpViewShell->GetViewFrame()->GetBindings().Invalidate( SidArrayZoom );
177 } // end of namespace sd
179 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */