xref: /aoo42x/main/sd/source/ui/view/drviews8.cxx (revision 5b190011)
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 #include "DrawViewShell.hxx"
28 
29 #include "ViewShellHint.hxx"
30 
31 #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
32 #include <toolkit/unohlp.hxx>
33 #endif
34 #include <sfx2/dispatch.hxx>
35 #ifndef _SVXIDS_HXX
36 #include <svx/svxids.hrc>
37 #endif
38 #include <vcl/msgbox.hxx>
39 #include <svx/svddef.hxx>
40 #include <sfx2/bindings.hxx>
41 #include <sfx2/request.hxx>
42 #include <sfx2/viewfrm.hxx>
43 #include <svx/svdograf.hxx>
44 #include <svx/svdpagv.hxx>
45 
46 #include "app.hrc"
47 #include "strings.hrc"
48 
49 #include "misc.hxx"
50 #include "fuzoom.hxx"
51 #include "fudspord.hxx"
52 #include "futransf.hxx"
53 #include "fuline.hxx"
54 #include "fuarea.hxx"
55 #include "fuchar.hxx"
56 #include "fuparagr.hxx"
57 #include "fubullet.hxx"
58 #include "futempl.hxx"
59 #include "fuinsert.hxx"
60 #include "fuprlout.hxx"
61 #include "fupage.hxx"
62 #ifndef SD_FU_OBJECT_ANIMATION_PARAMETERS_HXX
63 #include "fuoaprms.hxx"
64 #endif
65 #include "fucopy.hxx"
66 #ifndef SD_FU_LINE_END_HXX
67 #include "fulinend.hxx"
68 #endif
69 #include "fusnapln.hxx"
70 #include "fuolbull.hxx"
71 #include "fuinsfil.hxx"
72 #include "fulink.hxx"
73 #include "futhes.hxx"
74 #include "futxtatt.hxx"
75 #include "fumeasur.hxx"
76 #include "fuconnct.hxx"
77 #include "fumorph.hxx"
78 #include "fuvect.hxx"
79 #include "sdresid.hxx"
80 #include "Window.hxx"
81 #include "drawview.hxx"
82 #include "zoomlist.hxx"
83 #include <vos/mutex.hxx>
84 #include <vcl/salbtype.hxx>		// FRound
85 #include <vcl/svapp.hxx>
86 
87 namespace sd {
88 
89 /*************************************************************************
90 |*
91 |* SfxRequests fuer temporaere Funktionen
92 |*
93 \************************************************************************/
94 
95 void DrawViewShell::FuTemp01(SfxRequest& rReq)
96 {
97 	switch(rReq.GetSlot())
98 	{
99 		case SID_ATTRIBUTES_LINE:  // BASIC
100 		{
101 			SetCurrentFunction( FuLine::Create( this, GetActiveWindow(), mpDrawView, GetDoc(), rReq ) );
102 			Cancel();
103 		}
104 		break;
105 
106 		case SID_ATTRIBUTES_AREA:  // BASIC
107 		{
108 			SetCurrentFunction( FuArea::Create( this, GetActiveWindow(), mpDrawView, GetDoc(), rReq ) );
109 			Cancel();
110 		}
111 		break;
112 
113 		case SID_ATTR_TRANSFORM:
114 		{
115 			SetCurrentFunction( FuTransform::Create( this, GetActiveWindow(), mpDrawView, GetDoc(), rReq ) );
116 			Invalidate(SID_RULER_OBJECT);
117 			Cancel();
118 		}
119 		break;
120 
121 		case SID_CHAR_DLG:	// BASIC
122 		{
123 			SetCurrentFunction( FuChar::Create( this, GetActiveWindow(), mpDrawView, GetDoc(), rReq ) );
124 			Cancel();
125 		}
126 		break;
127 
128 		case SID_PARA_DLG:
129 		{
130 			SetCurrentFunction( FuParagraph::Create( this, GetActiveWindow(), mpDrawView, GetDoc(), rReq ) );
131 			Cancel();
132 		}
133 		break;
134 
135 		case SID_OUTLINE_BULLET:
136 		{
137 			SetCurrentFunction( FuOutlineBullet::Create( this, GetActiveWindow(), mpDrawView, GetDoc(), rReq ) );
138 			Cancel();
139 		}
140 		break;
141 
142 		case FN_INSERT_SOFT_HYPHEN:
143 		case FN_INSERT_HARDHYPHEN:
144 		case FN_INSERT_HARD_SPACE:
145 		case SID_INSERT_RLM :
146 		case SID_INSERT_LRM :
147 		case SID_INSERT_ZWNBSP :
148 		case SID_INSERT_ZWSP:
149 		case SID_CHARMAP:
150 		{
151 			SetCurrentFunction( FuBullet::Create( this, GetActiveWindow(), mpDrawView, GetDoc(), rReq ) );
152 			Cancel();
153 		}
154 		break;
155 
156 		case SID_PRESENTATION_LAYOUT:
157 		{
158 			SetCurrentFunction( FuPresentationLayout::Create(this, GetActiveWindow(), mpDrawView, GetDoc(), rReq) );
159 			Cancel();
160 		}
161 		break;
162 
163         case SID_PASTE_SPECIAL:
164 		{
165 			SetCurrentFunction( FuInsertClipboard::Create( this, GetActiveWindow(), mpDrawView, GetDoc(), rReq ) );
166 			Cancel();
167 			rReq.Ignore ();
168 		}
169 		break;
170 
171 		case SID_INSERT_GRAPHIC:
172 		{
173 			SetCurrentFunction( FuInsertGraphic::Create( this, GetActiveWindow(), mpDrawView, GetDoc(), rReq ) );
174 			Cancel();
175 			rReq.Ignore ();
176 			Invalidate(SID_DRAWTBX_INSERT);
177 		}
178 		break;
179 
180 		case SID_INSERT_AVMEDIA:
181 		{
182 			SetCurrentFunction( FuInsertAVMedia::Create( this, GetActiveWindow(), mpDrawView, GetDoc(), rReq ) );
183 
184 			Cancel();
185 			rReq.Ignore ();
186 
187 			Invalidate(SID_DRAWTBX_INSERT);
188 		}
189 		break;
190 
191 		case SID_INSERT_OBJECT:
192 		case SID_INSERT_PLUGIN:
193 		case SID_INSERT_SOUND:
194 		case SID_INSERT_VIDEO:
195 		case SID_INSERT_FLOATINGFRAME:
196 		case SID_INSERT_MATH:
197 		case SID_INSERT_DIAGRAM:
198 		case SID_ATTR_TABLE:
199 		{
200 			SetCurrentFunction( FuInsertOLE::Create( this, GetActiveWindow(), mpDrawView, GetDoc(), rReq ) );
201 
202 			Cancel();
203 			rReq.Ignore ();
204 
205 			Invalidate(SID_DRAWTBX_INSERT);
206 		}
207 		break;
208 
209 		case SID_COPYOBJECTS:
210 		{
211 			if ( mpDrawView->IsPresObjSelected(sal_False, sal_True) )
212 			{
213                 ::sd::Window* pWindow = GetActiveWindow();
214 				InfoBox(pWindow, String(SdResId(STR_ACTION_NOTPOSSIBLE) ) ).Execute();
215 			}
216 			else
217 			{
218 				if ( mpDrawView->IsTextEdit() )
219 				{
220 					mpDrawView->SdrEndTextEdit();
221 				}
222 
223 				SetCurrentFunction( FuCopy::Create( this, GetActiveWindow(), mpDrawView, GetDoc(), rReq ) );
224 			}
225 			Cancel();
226 			rReq.Ignore ();
227 		}
228 		break;
229 
230 		case SID_INSERTFILE:  // BASIC
231 		{
232             Broadcast (ViewShellHint(ViewShellHint::HINT_COMPLEX_MODEL_CHANGE_START));
233 			SetCurrentFunction( FuInsertFile::Create( this, GetActiveWindow(), mpDrawView, GetDoc(), rReq ) );
234             Broadcast (ViewShellHint(ViewShellHint::HINT_COMPLEX_MODEL_CHANGE_END));
235 			Cancel();
236 			rReq.Done ();
237 
238 			Invalidate(SID_DRAWTBX_INSERT);
239 		}
240 		break;
241 
242 		case SID_SELECT_BACKGROUND:
243 		case SID_PAGESETUP:  // BASIC ??
244 		{
245 			SetCurrentFunction( FuPage::Create( this, GetActiveWindow(), mpDrawView, GetDoc(), rReq ) );
246 			Cancel();
247 			rReq.Ignore (); // es werden eigenstaendige macros generiert !!
248 		}
249 		break;
250 
251 		case SID_ZOOM_OUT:
252 		case SID_ZOOM_PANNING:
253 		{
254 			mbZoomOnPage = sal_False;
255 			SetCurrentFunction( FuZoom::Create(this, GetActiveWindow(), mpDrawView, GetDoc(), rReq) );
256 			// Beendet sich selbst, kein Cancel() notwendig!
257 			Invalidate( SID_ZOOM_TOOLBOX );
258 			rReq.Ignore ();
259 		}
260 		break;
261 
262 		case SID_BEFORE_OBJ:
263 		case SID_BEHIND_OBJ:
264 		{
265 			SetCurrentFunction( FuDisplayOrder::Create(this, GetActiveWindow(), mpDrawView, GetDoc(), rReq) );
266 			Invalidate( SID_POSITION );
267 			rReq.Ignore ();
268 			// Beendet sich selbst, kein Cancel() notwendig!
269 		}
270 		break;
271 
272 		case SID_REVERSE_ORDER:   // BASIC
273 		{
274 			mpDrawView->ReverseOrderOfMarked();
275 			Invalidate( SID_POSITION );
276 			Cancel();
277 			rReq.Done ();
278 		}
279 		break;
280 
281 		case SID_ANIMATION_EFFECTS:
282 		{
283 			SetCurrentFunction( FuObjectAnimationParameters::Create( this, GetActiveWindow(), mpDrawView, GetDoc(), rReq) );
284 			Cancel();
285 		}
286 		break;
287 
288 		case SID_LINEEND_POLYGON:
289 		{
290 			SetCurrentFunction( FuLineEnd::Create( this, GetActiveWindow(), mpDrawView, GetDoc(), rReq ) );
291 			Cancel();
292 		}
293 		break;
294 
295 		case SID_CAPTUREPOINT:
296 			// negative Werte um Aufruf aus Menue zu signalisieren
297 			maMousePos = Point(-1,-1);
298 		case SID_SET_SNAPITEM:
299 		{
300 			SetCurrentFunction( FuSnapLine::Create(this, GetActiveWindow(), mpDrawView, GetDoc(), rReq) );
301 			Cancel();
302 		}
303 		break;
304 
305 		case SID_MANAGE_LINKS:
306 		{
307 			SetCurrentFunction( FuLink::Create( this, GetActiveWindow(), mpDrawView, GetDoc(), rReq ) );
308 			Cancel();
309 			rReq.Ignore ();
310 		}
311 		break;
312 
313         case SID_THESAURUS:
314 		{
315 			SetCurrentFunction( FuThesaurus::Create( this, GetActiveWindow(), mpDrawView, GetDoc(), rReq ) );
316 			Cancel();
317 			rReq.Ignore ();
318 		}
319 		break;
320 
321 		case SID_TEXTATTR_DLG:
322 		{
323 			SetCurrentFunction( FuTextAttrDlg::Create( this, GetActiveWindow(), mpDrawView, GetDoc(), rReq ) );
324 			Cancel();
325 			rReq.Ignore ();
326 		}
327 		break;
328 
329 		case SID_MEASURE_DLG:
330 		{
331 			SetCurrentFunction( FuMeasureDlg::Create( this, GetActiveWindow(), mpDrawView, GetDoc(), rReq ) );
332 			Cancel();
333 			rReq.Ignore ();
334 		}
335 		break;
336 
337 		case SID_CONNECTION_DLG:
338 		{
339 			SetCurrentFunction( FuConnectionDlg::Create( this, GetActiveWindow(), mpDrawView, GetDoc(), rReq ) );
340 			Cancel();
341 			rReq.Done();
342 		}
343 		break;
344 
345 		case SID_CONNECTION_NEW_ROUTING:
346 		{
347 			SfxItemSet aDefAttr( GetPool(), SDRATTR_EDGELINE1DELTA, SDRATTR_EDGELINE3DELTA );
348 			GetView()->SetAttributes( aDefAttr, sal_True ); // (ReplaceAll)
349 
350 			Cancel();
351 			rReq.Done();
352 		}
353 		break;
354 
355         case SID_TWAIN_SELECT:
356 		{
357 			sal_Bool bDone = sal_False;
358 
359 			if( mxScannerManager.is() )
360 			{
361 				try
362 				{
363 					const ::com::sun::star::uno::Sequence< ::com::sun::star::scanner::ScannerContext >
364 						aContexts( mxScannerManager->getAvailableScanners() );
365 
366 					if( aContexts.getLength() )
367 					{
368 						::com::sun::star::scanner::ScannerContext aContext( aContexts.getConstArray()[ 0 ] );
369 						bDone = mxScannerManager->configureScanner( aContext );
370 					}
371 				}
372 				catch(...)
373 				{
374                 }
375 			}
376 
377             Cancel();
378 			rReq.Done();
379 		}
380 		break;
381 
382         case SID_TWAIN_TRANSFER:
383 		{
384 			sal_Bool bDone = sal_False;
385 
386 			if( mxScannerManager.is() )
387 			{
388 				try
389 				{
390 					const ::com::sun::star::uno::Sequence< ::com::sun::star::scanner::ScannerContext > aContexts( mxScannerManager->getAvailableScanners() );
391 
392 					if( aContexts.getLength() )
393 					{
394 						mxScannerManager->startScan( aContexts.getConstArray()[ 0 ], mxScannerListener );
395 						bDone = sal_True;
396 					}
397 				}
398 				catch( ... )
399 				{
400 				}
401 			}
402 
403 			if( !bDone )
404 			{
405 #ifndef UNX
406 				const sal_uInt16 nId = STR_TWAIN_NO_SOURCE;
407 #else
408 				const sal_uInt16 nId = STR_TWAIN_NO_SOURCE_UNX;
409 #endif
410 
411                 ::sd::Window* pWindow = GetActiveWindow();
412 				InfoBox(pWindow, String( SdResId( nId ) ) ).Execute();
413 			}
414 			else
415 			{
416 				SfxBindings& rBindings = GetViewFrame()->GetBindings();
417 				rBindings.Invalidate( SID_TWAIN_SELECT );
418 				rBindings.Invalidate( SID_TWAIN_TRANSFER );
419 			}
420 
421             Cancel();
422 			rReq.Done();
423 		}
424 		break;
425 
426 		case SID_POLYGON_MORPHING:
427 		{
428 			SetCurrentFunction( FuMorph::Create( this, GetActiveWindow(), mpDrawView, GetDoc(), rReq ) );
429 			Cancel();
430 		}
431 		break;
432 
433 		case SID_VECTORIZE:
434 		{
435 			SetCurrentFunction( FuVectorize::Create( this, GetActiveWindow(), mpDrawView, GetDoc(), rReq ) );
436 			Cancel();
437 		}
438 		break;
439 
440 		default:
441 		{
442 			// switch Anweisung wegen CLOOKS aufgeteilt. Alle case-Anweisungen die
443 			// eine Fu???? -Funktion aufrufen, sind in die Methode FuTemp01 (drviews8),
444 			// FuTemp02 (drviewsb) gewandert.
445 			FuTemp02(rReq);
446 		}
447 		break;
448 	}
449 }
450 
451 /*************************************************************************
452 |*
453 |* Scanner-Event
454 |*
455 \************************************************************************/
456 
457 void DrawViewShell::ScannerEvent( const ::com::sun::star::lang::EventObject& )
458 {
459 	if( mxScannerManager.is() )
460 	{
461 		const ::com::sun::star::scanner::ScannerContext	aContext( mxScannerManager->getAvailableScanners().getConstArray()[ 0 ] );
462 		const ::com::sun::star::scanner::ScanError		eError = mxScannerManager->getError( aContext );
463 
464 		if( ::com::sun::star::scanner::ScanError_ScanErrorNone == eError )
465 		{
466 			const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XBitmap > xBitmap( mxScannerManager->getBitmap( aContext ) );
467 
468 			if( xBitmap.is() )
469 			{
470 				const BitmapEx aScanBmp( VCLUnoHelper::GetBitmap( xBitmap ) );
471 
472 				if( !!aScanBmp )
473 				{
474                     const ::vos::OGuard aGuard( Application::GetSolarMutex() );
475 		            SdrPage*            pPage = mpDrawView->GetSdrPageView()->GetPage();
476             		Size                aBmpSize( aScanBmp.GetPrefSize() ), aPageSize( pPage->GetSize() );
477                     const MapMode       aMap100( MAP_100TH_MM );
478 
479 		            if( !aBmpSize.Width() || !aBmpSize.Height() )
480 			            aBmpSize = aScanBmp.GetSizePixel();
481 
482 		            if( aScanBmp.GetPrefMapMode().GetMapUnit() == MAP_PIXEL )
483 			            aBmpSize = GetActiveWindow()->PixelToLogic( aBmpSize, aMap100 );
484 		            else
485 			            aBmpSize = OutputDevice::LogicToLogic( aBmpSize, aScanBmp.GetPrefMapMode(), aMap100 );
486 
487                     aPageSize.Width() -= pPage->GetLftBorder() + pPage->GetRgtBorder();
488 		            aPageSize.Height() -= pPage->GetUppBorder() + pPage->GetLwrBorder();
489 
490 		            if( ( ( aBmpSize.Height() > aPageSize.Height() ) || ( aBmpSize.Width() > aPageSize.Width() ) ) && aBmpSize.Height() && aPageSize.Height() )
491 		            {
492 			            double fGrfWH = (double) aBmpSize.Width() / aBmpSize.Height();
493 			            double fWinWH = (double) aPageSize.Width() / aPageSize.Height();
494 
495 			            if( fGrfWH < fWinWH )
496 			            {
497 				            aBmpSize.Width() = FRound( aPageSize.Height() * fGrfWH );
498 				            aBmpSize.Height()= aPageSize.Height();
499 			            }
500 			            else if( fGrfWH > 0.F )
501 			            {
502 				            aBmpSize.Width() = aPageSize.Width();
503 				            aBmpSize.Height()= FRound( aPageSize.Width() / fGrfWH );
504 			            }
505 		            }
506 
507 		            Point aPnt ( ( aPageSize.Width() - aBmpSize.Width() ) >> 1, ( aPageSize.Height() - aBmpSize.Height() ) >> 1 );
508                     aPnt += Point( pPage->GetLftBorder(), pPage->GetUppBorder() );
509 		            Rectangle   aRect( aPnt, aBmpSize );
510 		            SdrGrafObj* pGrafObj = NULL;
511                     sal_Bool        bInsertNewObject = sal_True;
512 
513 		            if( GetView()->AreObjectsMarked() )
514 		            {
515 			            const SdrMarkList& rMarkList = mpDrawView->GetMarkedObjectList();
516 
517 			            if( rMarkList.GetMarkCount() == 1 )
518 			            {
519 				            SdrMark*    pMark = rMarkList.GetMark(0);
520 				            SdrObject*  pObj = pMark->GetMarkedSdrObj();
521 
522 				            if( pObj->ISA( SdrGrafObj ) )
523 				            {
524 					            pGrafObj = static_cast< SdrGrafObj* >( pObj );
525 
526 					            if( pGrafObj->IsEmptyPresObj() )
527 					            {
528 						            bInsertNewObject = sal_False;
529 						            pGrafObj->SetEmptyPresObj(sal_False);
530 						            pGrafObj->SetOutlinerParaObject(NULL);
531 						            pGrafObj->SetGraphic( Graphic( aScanBmp ) );
532 					            }
533 				            }
534 			            }
535 		            }
536 
537 		            if( bInsertNewObject )
538 		            {
539 			            pGrafObj = new SdrGrafObj( Graphic( aScanBmp ), aRect );
540 			            SdrPageView* pPV = GetView()->GetSdrPageView();
541 			            GetView()->InsertObjectAtView( pGrafObj, *pPV, SDRINSERT_SETDEFLAYER );
542 		            }
543 				}
544 			}
545 		}
546 	}
547 
548 	SfxBindings& rBindings = GetViewFrame()->GetBindings();
549 	rBindings.Invalidate( SID_TWAIN_SELECT );
550 	rBindings.Invalidate( SID_TWAIN_TRANSFER );
551 }
552 
553 } // end of namespace sd
554