xref: /aoo41x/main/sd/source/ui/func/fuscale.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sd.hxx"
30 
31 
32 #include "fuscale.hxx"
33 
34 #include <svx/dialogs.hrc>
35 
36 #include "app.hrc"
37 #include "View.hxx"
38 #ifndef SD_WINDOW_SHELL_HXX
39 #include "Window.hxx"
40 #endif
41 #include "OutlineViewShell.hxx"
42 #include "drawview.hxx"
43 #include "drawdoc.hxx"
44 #include "DrawViewShell.hxx"
45 #include "ViewShell.hxx"
46 #include "fuzoom.hxx" // wegen SidArrayZoom[]
47 
48 #ifndef _MSGBOX_HXX //autogen
49 #include <vcl/msgbox.hxx>
50 #endif
51 #include <svx/svdpagv.hxx>
52 #include <sfx2/viewfrm.hxx>
53 #include <sfx2/dispatch.hxx>
54 #include <svx/zoom_def.hxx>
55 #include <svx/zoomitem.hxx>
56 #include <sfx2/request.hxx>
57 #include <svx/svxdlg.hxx>
58 #include <svx/dialogs.hrc>
59 
60 namespace sd {
61 
62 TYPEINIT1( FuScale, FuPoor );
63 
64 /*************************************************************************
65 |*
66 |* Konstruktor
67 |*
68 \************************************************************************/
69 
70 FuScale::FuScale (
71     ViewShell* pViewSh,
72     ::sd::Window* pWin,
73     ::sd::View* pView,
74     SdDrawDocument* pDoc,
75     SfxRequest& rReq)
76     : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
77 {
78 }
79 
80 FunctionReference FuScale::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
81 {
82 	FunctionReference xFunc( new FuScale( pViewSh, pWin, pView, pDoc, rReq ) );
83 	xFunc->DoExecute(rReq);
84 	return xFunc;
85 }
86 
87 void FuScale::DoExecute( SfxRequest& rReq )
88 {
89 	sal_Int16 nValue;
90 
91 	const SfxItemSet* pArgs = rReq.GetArgs();
92 
93 	if( !pArgs )
94 	{
95 		SfxItemSet aNewAttr( mpDoc->GetPool(), SID_ATTR_ZOOM, SID_ATTR_ZOOM );
96 		SvxZoomItem* pZoomItem;
97 		sal_uInt16 nZoomValues = SVX_ZOOM_ENABLE_ALL;
98 
99 		nValue = (sal_Int16) mpWindow->GetZoom();
100 
101 		// Zoom auf Seitengroesse ?
102 		if( mpViewShell && mpViewShell->ISA( DrawViewShell ) &&
103 			static_cast<DrawViewShell*>(mpViewShell)->IsZoomOnPage() )
104 		{
105 			pZoomItem = new SvxZoomItem( SVX_ZOOM_WHOLEPAGE, nValue );
106 		}
107 		else
108 		{
109 			pZoomItem = new SvxZoomItem( SVX_ZOOM_PERCENT, nValue );
110 		}
111 
112 		// Bereich einschraenken
113 		if( mpViewShell )
114 		{
115 			if( mpViewShell->ISA( DrawViewShell ) )
116 			{
117 				SdrPageView* pPageView = mpView->GetSdrPageView();
118 				if( ( pPageView && pPageView->GetObjList()->GetObjCount() == 0 ) )
119 					// || ( mpView->GetMarkedObjectList().GetMarkCount() == 0 ) )
120 				{
121 					nZoomValues &= ~SVX_ZOOM_ENABLE_OPTIMAL;
122 				}
123 			}
124 			else if( mpViewShell->ISA( OutlineViewShell ) )
125 			{
126 				nZoomValues &= ~SVX_ZOOM_ENABLE_OPTIMAL;
127 				nZoomValues &= ~SVX_ZOOM_ENABLE_WHOLEPAGE;
128 				nZoomValues &= ~SVX_ZOOM_ENABLE_PAGEWIDTH;
129 			}
130 		}
131 
132 		pZoomItem->SetValueSet( nZoomValues );
133 		aNewAttr.Put( *pZoomItem );
134 
135 		AbstractSvxZoomDialog* pDlg=NULL;
136 		SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
137 		if(pFact)
138 		{
139 			pDlg = pFact->CreateSvxZoomDialog(NULL, aNewAttr);
140 		}
141 
142 		if( pDlg )
143 		{
144 			pDlg->SetLimits( (sal_uInt16)mpWindow->GetMinZoom(), (sal_uInt16)mpWindow->GetMaxZoom() );
145 			sal_uInt16 nResult = pDlg->Execute();
146 			switch( nResult )
147 			{
148 				case RET_CANCEL:
149 				{
150 					delete pDlg;
151 					delete pZoomItem;
152 					rReq.Ignore ();
153 					return; // Abbruch
154 				}
155 				default:
156 				{
157 					rReq.Ignore ();
158 		/*
159 						rReq.Done( *( pDlg->GetOutputItemSet() ) );
160 						pArgs = rReq.GetArgs();*/
161 				}
162 				break;
163 			}
164 
165 			const SfxItemSet aArgs (*(pDlg->GetOutputItemSet ()));
166 
167 			delete pDlg;
168 
169 			switch (((const SvxZoomItem &) aArgs.Get (SID_ATTR_ZOOM)).GetType ())
170 			{
171 				case SVX_ZOOM_PERCENT:
172 				{
173 					nValue = ((const SvxZoomItem &) aArgs.Get (SID_ATTR_ZOOM)).GetValue ();
174 
175 					mpViewShell->SetZoom( nValue );
176 
177 					mpViewShell->GetViewFrame()->GetBindings().Invalidate( SidArrayZoom );
178 				}
179 				break;
180 
181 				case SVX_ZOOM_OPTIMAL:
182 				{
183 					if( mpViewShell->ISA( DrawViewShell ) )
184 					{
185 						// Namensverwirrung: SID_SIZE_ALL -> Zoom auf alle Objekte
186 						// --> Wird als Optimal im Programm angeboten
187 						mpViewShell->GetViewFrame()->GetDispatcher()->Execute( SID_SIZE_ALL, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD);
188 					}
189 				}
190 				break;
191 
192 				case SVX_ZOOM_PAGEWIDTH:
193 					mpViewShell->GetViewFrame()->GetDispatcher()->Execute( SID_SIZE_PAGE_WIDTH, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD);
194 					break;
195 
196 				case SVX_ZOOM_WHOLEPAGE:
197 					mpViewShell->GetViewFrame()->GetDispatcher()->Execute(SID_SIZE_PAGE, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD);
198 					break;
199 				default:
200 					break;
201 			}
202 		}
203 
204 		delete pZoomItem;
205 	}
206 	else if(mpViewShell && (pArgs->Count () == 1))
207 	{
208 		SFX_REQUEST_ARG (rReq, pScale, SfxUInt32Item, ID_VAL_ZOOM, sal_False);
209 		mpViewShell->SetZoom (pScale->GetValue ());
210 
211 		mpViewShell->GetViewFrame()->GetBindings().Invalidate( SidArrayZoom );
212 	}
213 
214 }
215 
216 } // end of namespace sd
217