bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / func / fuscale.cxx
blob9729951fd721fb67000ce094494029321a19cf44
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 <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>
44 namespace sd {
46 TYPEINIT1( FuScale, FuPoor );
48 FuScale::FuScale (
49 ViewShell* pViewSh,
50 ::sd::Window* pWin,
51 ::sd::View* pView,
52 SdDrawDocument* pDoc,
53 SfxRequest& rReq)
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);
62 return xFunc;
65 void FuScale::DoExecute( SfxRequest& rReq )
67 sal_Int16 nValue;
69 const SfxItemSet* pArgs = rReq.GetArgs();
71 if( !pArgs )
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();
79 // zoom on page size?
80 if( mpViewShell && mpViewShell->ISA( DrawViewShell ) &&
81 static_cast<DrawViewShell*>(mpViewShell)->IsZoomOnPage() )
83 pZoomItem.reset(new SvxZoomItem( SvxZoomType::WHOLEPAGE, nValue ));
85 else
87 pZoomItem.reset(new SvxZoomItem( SvxZoomType::PERCENT, nValue ));
90 // limit range
91 if( mpViewShell )
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();
115 if(pFact)
117 pDlg.reset(pFact->CreateSvxZoomDialog(NULL, aNewAttr));
120 if( pDlg )
122 pDlg->SetLimits( (sal_uInt16)mpWindow->GetMinZoom(), (sal_uInt16)mpWindow->GetMaxZoom() );
123 sal_uInt16 nResult = pDlg->Execute();
124 switch( nResult )
126 case RET_CANCEL:
128 rReq.Ignore ();
129 return; // Cancel
131 default:
133 rReq.Ignore ();
135 break;
138 const SfxItemSet aArgs (*(pDlg->GetOutputItemSet ()));
140 pDlg.reset();
142 if (!mpViewShell)
143 return;
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 );
155 break;
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);
166 break;
168 case SvxZoomType::PAGEWIDTH:
169 mpViewShell->GetViewFrame()->GetDispatcher()->Execute( SID_SIZE_PAGE_WIDTH, SfxCallMode::ASYNCHRON | SfxCallMode::RECORD);
170 break;
172 case SvxZoomType::WHOLEPAGE:
173 mpViewShell->GetViewFrame()->GetDispatcher()->Execute(SID_SIZE_PAGE, SfxCallMode::ASYNCHRON | SfxCallMode::RECORD);
174 break;
175 default:
176 break;
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: */