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