1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
27 #include <OutlineViewShell.hxx>
28 #include <drawdoc.hxx>
29 #include <DrawViewShell.hxx>
30 #include <ViewShell.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>
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
);
61 void FuScale::DoExecute( SfxRequest
& rReq
)
65 const SfxItemSet
* pArgs
= rReq
.GetArgs();
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());
76 if( dynamic_cast< DrawViewShell
*>( mpViewShell
) &&
77 static_cast<DrawViewShell
*>(mpViewShell
)->IsZoomOnPage() )
79 pZoomItem
.reset(new SvxZoomItem( SvxZoomType::WHOLEPAGE
, nValue
));
83 pZoomItem
.reset(new SvxZoomItem( SvxZoomType::PERCENT
, nValue
));
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();
126 const SfxItemSet
aArgs (*(pDlg
->GetOutputItemSet ()));
128 pDlg
.disposeAndClear();
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
);
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
);
156 case SvxZoomType::PAGEWIDTH
:
157 mpViewShell
->GetViewFrame()->GetDispatcher()->Execute( SID_SIZE_PAGE_WIDTH
, SfxCallMode::ASYNCHRON
| SfxCallMode::RECORD
);
160 case SvxZoomType::WHOLEPAGE
:
161 mpViewShell
->GetViewFrame()->GetDispatcher()->Execute(SID_SIZE_PAGE
, SfxCallMode::ASYNCHRON
| SfxCallMode::RECORD
);
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: */