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/dialogs.hrc>
27 #include <OutlineViewShell.hxx>
28 #include <drawview.hxx>
29 #include <drawdoc.hxx>
30 #include <DrawViewShell.hxx>
31 #include <ViewShell.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>
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
);
63 void FuScale::DoExecute( SfxRequest
& rReq
)
67 const SfxItemSet
* pArgs
= rReq
.GetArgs();
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());
78 if( mpViewShell
&& dynamic_cast< DrawViewShell
*>( mpViewShell
) != nullptr &&
79 static_cast<DrawViewShell
*>(mpViewShell
)->IsZoomOnPage() )
81 pZoomItem
.reset(new SvxZoomItem( SvxZoomType::WHOLEPAGE
, nValue
));
85 pZoomItem
.reset(new SvxZoomItem( SvxZoomType::PERCENT
, nValue
));
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);
114 pDlg
->SetLimits( static_cast<sal_uInt16
>(mpWindow
->GetMinZoom()), static_cast<sal_uInt16
>(mpWindow
->GetMaxZoom()) );
115 sal_uInt16 nResult
= pDlg
->Execute();
130 const SfxItemSet
aArgs (*(pDlg
->GetOutputItemSet ()));
132 pDlg
.disposeAndClear();
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
);
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
);
160 case SvxZoomType::PAGEWIDTH
:
161 mpViewShell
->GetViewFrame()->GetDispatcher()->Execute( SID_SIZE_PAGE_WIDTH
, SfxCallMode::ASYNCHRON
| SfxCallMode::RECORD
);
164 case SvxZoomType::WHOLEPAGE
:
165 mpViewShell
->GetViewFrame()->GetDispatcher()->Execute(SID_SIZE_PAGE
, SfxCallMode::ASYNCHRON
| SfxCallMode::RECORD
);
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: */