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