bump product version to 4.1.6.2
[LibreOffice.git] / sd / source / ui / func / fuscale.cxx
blob59f67d7038ca761099df1f42ddbe1a7cbcc573bf
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" // because of SidArrayZoom[]
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>
43 namespace sd {
45 TYPEINIT1( FuScale, FuPoor );
47 FuScale::FuScale (
48 ViewShell* pViewSh,
49 ::sd::Window* pWin,
50 ::sd::View* pView,
51 SdDrawDocument* pDoc,
52 SfxRequest& rReq)
53 : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
57 FunctionReference FuScale::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
59 FunctionReference xFunc( new FuScale( pViewSh, pWin, pView, pDoc, rReq ) );
60 xFunc->DoExecute(rReq);
61 return xFunc;
64 void FuScale::DoExecute( SfxRequest& rReq )
66 sal_Int16 nValue;
68 const SfxItemSet* pArgs = rReq.GetArgs();
70 if( !pArgs )
72 SfxItemSet aNewAttr( mpDoc->GetPool(), SID_ATTR_ZOOM, SID_ATTR_ZOOM );
73 SvxZoomItem* pZoomItem;
74 sal_uInt16 nZoomValues = SVX_ZOOM_ENABLE_ALL;
76 nValue = (sal_Int16) mpWindow->GetZoom();
78 // zoom on page size?
79 if( mpViewShell && mpViewShell->ISA( DrawViewShell ) &&
80 static_cast<DrawViewShell*>(mpViewShell)->IsZoomOnPage() )
82 pZoomItem = new SvxZoomItem( SVX_ZOOM_WHOLEPAGE, nValue );
84 else
86 pZoomItem = new SvxZoomItem( SVX_ZOOM_PERCENT, nValue );
89 // limit range
90 if( mpViewShell )
92 if( mpViewShell->ISA( DrawViewShell ) )
94 SdrPageView* pPageView = mpView->GetSdrPageView();
95 if( ( pPageView && pPageView->GetObjList()->GetObjCount() == 0 ) )
96 // || ( mpView->GetMarkedObjectList().GetMarkCount() == 0 ) )
98 nZoomValues &= ~SVX_ZOOM_ENABLE_OPTIMAL;
101 else if( mpViewShell->ISA( OutlineViewShell ) )
103 nZoomValues &= ~SVX_ZOOM_ENABLE_OPTIMAL;
104 nZoomValues &= ~SVX_ZOOM_ENABLE_WHOLEPAGE;
105 nZoomValues &= ~SVX_ZOOM_ENABLE_PAGEWIDTH;
109 pZoomItem->SetValueSet( nZoomValues );
110 aNewAttr.Put( *pZoomItem );
112 AbstractSvxZoomDialog* pDlg=NULL;
113 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
114 if(pFact)
116 pDlg = pFact->CreateSvxZoomDialog(NULL, aNewAttr);
119 if( pDlg )
121 pDlg->SetLimits( (sal_uInt16)mpWindow->GetMinZoom(), (sal_uInt16)mpWindow->GetMaxZoom() );
122 sal_uInt16 nResult = pDlg->Execute();
123 switch( nResult )
125 case RET_CANCEL:
127 delete pDlg;
128 delete pZoomItem;
129 rReq.Ignore ();
130 return; // Cancel
132 default:
134 rReq.Ignore ();
136 rReq.Done( *( pDlg->GetOutputItemSet() ) );
137 pArgs = rReq.GetArgs();*/
139 break;
142 const SfxItemSet aArgs (*(pDlg->GetOutputItemSet ()));
144 delete pDlg;
146 switch (((const SvxZoomItem &) aArgs.Get (SID_ATTR_ZOOM)).GetType ())
148 case SVX_ZOOM_PERCENT:
150 nValue = ((const SvxZoomItem &) aArgs.Get (SID_ATTR_ZOOM)).GetValue ();
152 mpViewShell->SetZoom( nValue );
154 mpViewShell->GetViewFrame()->GetBindings().Invalidate( SidArrayZoom );
156 break;
158 case SVX_ZOOM_OPTIMAL:
160 if( mpViewShell->ISA( DrawViewShell ) )
162 // name confusion: SID_SIZE_ALL -> zoom onto all objects
163 // --> the program offers it as optimal
164 mpViewShell->GetViewFrame()->GetDispatcher()->Execute( SID_SIZE_ALL, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD);
167 break;
169 case SVX_ZOOM_PAGEWIDTH:
170 mpViewShell->GetViewFrame()->GetDispatcher()->Execute( SID_SIZE_PAGE_WIDTH, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD);
171 break;
173 case SVX_ZOOM_WHOLEPAGE:
174 mpViewShell->GetViewFrame()->GetDispatcher()->Execute(SID_SIZE_PAGE, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD);
175 break;
176 default:
177 break;
181 delete pZoomItem;
183 else if(mpViewShell && (pArgs->Count () == 1))
185 SFX_REQUEST_ARG (rReq, pScale, SfxUInt32Item, ID_VAL_ZOOM, sal_False);
186 mpViewShell->SetZoom (pScale->GetValue ());
188 mpViewShell->GetViewFrame()->GetBindings().Invalidate( SidArrayZoom );
193 } // end of namespace sd
195 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */