xref: /aoo41x/main/sd/source/ui/func/fuscale.cxx (revision 79aad27f)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sd.hxx"
26 
27 
28 #include "fuscale.hxx"
29 
30 #include <svx/dialogs.hrc>
31 
32 #include "app.hrc"
33 #include "View.hxx"
34 #ifndef SD_WINDOW_SHELL_HXX
35 #include "Window.hxx"
36 #endif
37 #include "OutlineViewShell.hxx"
38 #include "drawview.hxx"
39 #include "drawdoc.hxx"
40 #include "DrawViewShell.hxx"
41 #include "ViewShell.hxx"
42 #include "fuzoom.hxx" // wegen SidArrayZoom[]
43 
44 #ifndef _MSGBOX_HXX //autogen
45 #include <vcl/msgbox.hxx>
46 #endif
47 #include <svx/svdpagv.hxx>
48 #include <sfx2/viewfrm.hxx>
49 #include <sfx2/dispatch.hxx>
50 #include <svx/zoom_def.hxx>
51 #include <svx/zoomitem.hxx>
52 #include <sfx2/request.hxx>
53 #include <svx/svxdlg.hxx>
54 #include <svx/dialogs.hrc>
55 
56 namespace sd {
57 
58 TYPEINIT1( FuScale, FuPoor );
59 
60 /*************************************************************************
61 |*
62 |* Konstruktor
63 |*
64 \************************************************************************/
65 
FuScale(ViewShell * pViewSh,::sd::Window * pWin,::sd::View * pView,SdDrawDocument * pDoc,SfxRequest & rReq)66 FuScale::FuScale (
67     ViewShell* pViewSh,
68     ::sd::Window* pWin,
69     ::sd::View* pView,
70     SdDrawDocument* pDoc,
71     SfxRequest& rReq)
72     : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
73 {
74 }
75 
Create(ViewShell * pViewSh,::sd::Window * pWin,::sd::View * pView,SdDrawDocument * pDoc,SfxRequest & rReq)76 FunctionReference FuScale::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
77 {
78 	FunctionReference xFunc( new FuScale( pViewSh, pWin, pView, pDoc, rReq ) );
79 	xFunc->DoExecute(rReq);
80 	return xFunc;
81 }
82 
DoExecute(SfxRequest & rReq)83 void FuScale::DoExecute( SfxRequest& rReq )
84 {
85 	sal_Int16 nValue;
86 
87 	const SfxItemSet* pArgs = rReq.GetArgs();
88 
89 	if( !pArgs )
90 	{
91 		SfxItemSet aNewAttr( mpDoc->GetPool(), SID_ATTR_ZOOM, SID_ATTR_ZOOM );
92 		SvxZoomItem* pZoomItem;
93 		sal_uInt16 nZoomValues = SVX_ZOOM_ENABLE_ALL;
94 
95 		nValue = (sal_Int16) mpWindow->GetZoom();
96 
97 		// Zoom auf Seitengroesse ?
98 		if( mpViewShell && mpViewShell->ISA( DrawViewShell ) &&
99 			static_cast<DrawViewShell*>(mpViewShell)->IsZoomOnPage() )
100 		{
101 			pZoomItem = new SvxZoomItem( SVX_ZOOM_WHOLEPAGE, nValue );
102 		}
103 		else
104 		{
105 			pZoomItem = new SvxZoomItem( SVX_ZOOM_PERCENT, nValue );
106 		}
107 
108 		// Bereich einschraenken
109 		if( mpViewShell )
110 		{
111 			if( mpViewShell->ISA( DrawViewShell ) )
112 			{
113 				SdrPageView* pPageView = mpView->GetSdrPageView();
114 				if( ( pPageView && pPageView->GetObjList()->GetObjCount() == 0 ) )
115 					// || ( mpView->GetMarkedObjectList().GetMarkCount() == 0 ) )
116 				{
117 					nZoomValues &= ~SVX_ZOOM_ENABLE_OPTIMAL;
118 				}
119 			}
120 			else if( mpViewShell->ISA( OutlineViewShell ) )
121 			{
122 				nZoomValues &= ~SVX_ZOOM_ENABLE_OPTIMAL;
123 				nZoomValues &= ~SVX_ZOOM_ENABLE_WHOLEPAGE;
124 				nZoomValues &= ~SVX_ZOOM_ENABLE_PAGEWIDTH;
125 			}
126 		}
127 
128 		pZoomItem->SetValueSet( nZoomValues );
129 		aNewAttr.Put( *pZoomItem );
130 
131 		AbstractSvxZoomDialog* pDlg=NULL;
132 		SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
133 		if(pFact)
134 		{
135 			pDlg = pFact->CreateSvxZoomDialog(NULL, aNewAttr);
136 		}
137 
138 		if( pDlg )
139 		{
140 			pDlg->SetLimits( (sal_uInt16)mpWindow->GetMinZoom(), (sal_uInt16)mpWindow->GetMaxZoom() );
141 			sal_uInt16 nResult = pDlg->Execute();
142 			switch( nResult )
143 			{
144 				case RET_CANCEL:
145 				{
146 					delete pDlg;
147 					delete pZoomItem;
148 					rReq.Ignore ();
149 					return; // Abbruch
150 				}
151 				default:
152 				{
153 					rReq.Ignore ();
154 		/*
155 						rReq.Done( *( pDlg->GetOutputItemSet() ) );
156 						pArgs = rReq.GetArgs();*/
157 				}
158 				break;
159 			}
160 
161 			const SfxItemSet aArgs (*(pDlg->GetOutputItemSet ()));
162 
163 			delete pDlg;
164 
165 			switch (((const SvxZoomItem &) aArgs.Get (SID_ATTR_ZOOM)).GetType ())
166 			{
167 				case SVX_ZOOM_PERCENT:
168 				{
169 					nValue = ((const SvxZoomItem &) aArgs.Get (SID_ATTR_ZOOM)).GetValue ();
170 
171 					mpViewShell->SetZoom( nValue );
172 
173 					mpViewShell->GetViewFrame()->GetBindings().Invalidate( SidArrayZoom );
174 				}
175 				break;
176 
177 				case SVX_ZOOM_OPTIMAL:
178 				{
179 					if( mpViewShell->ISA( DrawViewShell ) )
180 					{
181 						// Namensverwirrung: SID_SIZE_ALL -> Zoom auf alle Objekte
182 						// --> Wird als Optimal im Programm angeboten
183 						mpViewShell->GetViewFrame()->GetDispatcher()->Execute( SID_SIZE_ALL, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD);
184 					}
185 				}
186 				break;
187 
188 				case SVX_ZOOM_PAGEWIDTH:
189 					mpViewShell->GetViewFrame()->GetDispatcher()->Execute( SID_SIZE_PAGE_WIDTH, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD);
190 					break;
191 
192 				case SVX_ZOOM_WHOLEPAGE:
193 					mpViewShell->GetViewFrame()->GetDispatcher()->Execute(SID_SIZE_PAGE, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD);
194 					break;
195 				default:
196 					break;
197 			}
198 		}
199 
200 		delete pZoomItem;
201 	}
202 	else if(mpViewShell && (pArgs->Count () == 1))
203 	{
204 		SFX_REQUEST_ARG (rReq, pScale, SfxUInt32Item, ID_VAL_ZOOM, sal_False);
205 		mpViewShell->SetZoom (pScale->GetValue ());
206 
207 		mpViewShell->GetViewFrame()->GetBindings().Invalidate( SidArrayZoom );
208 	}
209 
210 }
211 
212 } // end of namespace sd
213