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 <vcl/msgbox.hxx>
35 #include <svx/svdpagv.hxx>
36 #include <sfx2/viewfrm.hxx>
37 #include <sfx2/dispatch.hxx>
38 #include <svx/zoom_def.hxx>
39 #include <sfx2/zoomitem.hxx>
40 #include <sfx2/request.hxx>
41 #include <svx/svxdlg.hxx>
42 #include <boost/scoped_ptr.hpp>
46 TYPEINIT1( FuScale
, FuPoor
);
54 : FuPoor(pViewSh
, pWin
, pView
, pDoc
, rReq
)
58 rtl::Reference
<FuPoor
> FuScale::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
)
60 rtl::Reference
<FuPoor
> xFunc( new FuScale( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
61 xFunc
->DoExecute(rReq
);
65 void FuScale::DoExecute( SfxRequest
& rReq
)
69 const SfxItemSet
* pArgs
= rReq
.GetArgs();
73 SfxItemSet
aNewAttr( mpDoc
->GetPool(), SID_ATTR_ZOOM
, SID_ATTR_ZOOM
);
74 boost::scoped_ptr
<SvxZoomItem
> pZoomItem
;
75 SvxZoomEnableFlags nZoomValues
= SvxZoomEnableFlags::ALL
;
77 nValue
= (sal_Int16
) mpWindow
->GetZoom();
80 if( mpViewShell
&& mpViewShell
->ISA( DrawViewShell
) &&
81 static_cast<DrawViewShell
*>(mpViewShell
)->IsZoomOnPage() )
83 pZoomItem
.reset(new SvxZoomItem( SvxZoomType::WHOLEPAGE
, nValue
));
87 pZoomItem
.reset(new SvxZoomItem( SvxZoomType::PERCENT
, nValue
));
93 if( mpViewShell
->ISA( DrawViewShell
) )
95 SdrPageView
* pPageView
= mpView
->GetSdrPageView();
96 if( ( pPageView
&& pPageView
->GetObjList()->GetObjCount() == 0 ) )
97 // || ( mpView->GetMarkedObjectList().GetMarkCount() == 0 ) )
99 nZoomValues
&= ~SvxZoomEnableFlags::OPTIMAL
;
102 else if( mpViewShell
->ISA( OutlineViewShell
) )
104 nZoomValues
&= ~SvxZoomEnableFlags::OPTIMAL
;
105 nZoomValues
&= ~SvxZoomEnableFlags::WHOLEPAGE
;
106 nZoomValues
&= ~SvxZoomEnableFlags::PAGEWIDTH
;
110 pZoomItem
->SetValueSet( nZoomValues
);
111 aNewAttr
.Put( *pZoomItem
);
113 boost::scoped_ptr
<AbstractSvxZoomDialog
> pDlg
;
114 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
117 pDlg
.reset(pFact
->CreateSvxZoomDialog(NULL
, aNewAttr
));
122 pDlg
->SetLimits( (sal_uInt16
)mpWindow
->GetMinZoom(), (sal_uInt16
)mpWindow
->GetMaxZoom() );
123 sal_uInt16 nResult
= pDlg
->Execute();
138 const SfxItemSet
aArgs (*(pDlg
->GetOutputItemSet ()));
145 switch (static_cast<const SvxZoomItem
&>( aArgs
.Get (SID_ATTR_ZOOM
)).GetType ())
147 case SvxZoomType::PERCENT
:
149 nValue
= static_cast<const SvxZoomItem
&>( aArgs
.Get (SID_ATTR_ZOOM
)).GetValue ();
151 mpViewShell
->SetZoom( nValue
);
153 mpViewShell
->GetViewFrame()->GetBindings().Invalidate( SidArrayZoom
);
157 case SvxZoomType::OPTIMAL
:
159 if( mpViewShell
->ISA( DrawViewShell
) )
161 // name confusion: SID_SIZE_ALL -> zoom onto all objects
162 // --> the program offers it as optimal
163 mpViewShell
->GetViewFrame()->GetDispatcher()->Execute( SID_SIZE_ALL
, SfxCallMode::ASYNCHRON
| SfxCallMode::RECORD
);
168 case SvxZoomType::PAGEWIDTH
:
169 mpViewShell
->GetViewFrame()->GetDispatcher()->Execute( SID_SIZE_PAGE_WIDTH
, SfxCallMode::ASYNCHRON
| SfxCallMode::RECORD
);
172 case SvxZoomType::WHOLEPAGE
:
173 mpViewShell
->GetViewFrame()->GetDispatcher()->Execute(SID_SIZE_PAGE
, SfxCallMode::ASYNCHRON
| SfxCallMode::RECORD
);
180 else if(mpViewShell
&& (pArgs
->Count () == 1))
182 SFX_REQUEST_ARG (rReq
, pScale
, SfxUInt32Item
, ID_VAL_ZOOM
, false);
183 mpViewShell
->SetZoom (pScale
->GetValue ());
185 mpViewShell
->GetViewFrame()->GetBindings().Invalidate( SidArrayZoom
);
190 } // end of namespace sd
192 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */