Update ooo320-m1
[ooovba.git] / sd / source / ui / view / drviews8.cxx
blob43f7d8a346e819e776158afc3ff69113b0abfebf
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: drviews8.cxx,v $
10 * $Revision: 1.21 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
34 #include "DrawViewShell.hxx"
36 #include "ViewShellHint.hxx"
38 #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
39 #include <toolkit/unohlp.hxx>
40 #endif
41 #include <sfx2/dispatch.hxx>
42 #ifndef _SVXIDS_HXX
43 #include <svx/svxids.hrc>
44 #endif
45 #include <vcl/msgbox.hxx>
46 #include <svx/svddef.hxx>
47 #include <sfx2/bindings.hxx>
48 #include <sfx2/request.hxx>
49 #include <sfx2/viewfrm.hxx>
50 #include <svx/svdograf.hxx>
51 #include <svx/svdpagv.hxx>
53 #include "app.hrc"
54 #include "strings.hrc"
56 #include "misc.hxx"
57 #include "fuzoom.hxx"
58 #include "fudspord.hxx"
59 #include "futransf.hxx"
60 #include "fuline.hxx"
61 #include "fuarea.hxx"
62 #include "fuchar.hxx"
63 #include "fuparagr.hxx"
64 #include "fubullet.hxx"
65 #include "futempl.hxx"
66 #include "fuinsert.hxx"
67 #include "fuprlout.hxx"
68 #include "fupage.hxx"
69 #ifndef SD_FU_OBJECT_ANIMATION_PARAMETERS_HXX
70 #include "fuoaprms.hxx"
71 #endif
72 #include "fucopy.hxx"
73 #ifndef SD_FU_LINE_END_HXX
74 #include "fulinend.hxx"
75 #endif
76 #include "fusnapln.hxx"
77 #include "fuolbull.hxx"
78 #include "fuinsfil.hxx"
79 #include "fulink.hxx"
80 #include "futhes.hxx"
81 #include "futxtatt.hxx"
82 #include "fumeasur.hxx"
83 #include "fuconnct.hxx"
84 #include "fumorph.hxx"
85 #include "fuvect.hxx"
86 #include "sdresid.hxx"
87 #include "Window.hxx"
88 #include "drawview.hxx"
89 #include "zoomlist.hxx"
90 #include <vos/mutex.hxx>
91 #include <vcl/salbtype.hxx> // FRound
92 #include <vcl/svapp.hxx>
94 namespace sd {
96 /*************************************************************************
98 |* SfxRequests fuer temporaere Funktionen
100 \************************************************************************/
102 void DrawViewShell::FuTemp01(SfxRequest& rReq)
104 switch(rReq.GetSlot())
106 case SID_ATTRIBUTES_LINE: // BASIC
108 SetCurrentFunction( FuLine::Create( this, GetActiveWindow(), mpDrawView, GetDoc(), rReq ) );
109 Cancel();
111 break;
113 case SID_ATTRIBUTES_AREA: // BASIC
115 SetCurrentFunction( FuArea::Create( this, GetActiveWindow(), mpDrawView, GetDoc(), rReq ) );
116 Cancel();
118 break;
120 case SID_ATTR_TRANSFORM:
122 SetCurrentFunction( FuTransform::Create( this, GetActiveWindow(), mpDrawView, GetDoc(), rReq ) );
123 Invalidate(SID_RULER_OBJECT);
124 Cancel();
126 break;
128 case SID_CHAR_DLG: // BASIC
130 SetCurrentFunction( FuChar::Create( this, GetActiveWindow(), mpDrawView, GetDoc(), rReq ) );
131 Cancel();
133 break;
135 case SID_PARA_DLG:
137 SetCurrentFunction( FuParagraph::Create( this, GetActiveWindow(), mpDrawView, GetDoc(), rReq ) );
138 Cancel();
140 break;
142 case SID_OUTLINE_BULLET:
144 SetCurrentFunction( FuOutlineBullet::Create( this, GetActiveWindow(), mpDrawView, GetDoc(), rReq ) );
145 Cancel();
147 break;
149 case FN_INSERT_SOFT_HYPHEN:
150 case FN_INSERT_HARDHYPHEN:
151 case FN_INSERT_HARD_SPACE:
152 case SID_INSERT_RLM :
153 case SID_INSERT_LRM :
154 case SID_INSERT_ZWNBSP :
155 case SID_INSERT_ZWSP:
156 case SID_CHARMAP:
158 SetCurrentFunction( FuBullet::Create( this, GetActiveWindow(), mpDrawView, GetDoc(), rReq ) );
159 Cancel();
161 break;
163 case SID_PRESENTATION_LAYOUT:
165 SetCurrentFunction( FuPresentationLayout::Create(this, GetActiveWindow(), mpDrawView, GetDoc(), rReq) );
166 Cancel();
168 break;
170 case SID_PASTE_SPECIAL:
172 SetCurrentFunction( FuInsertClipboard::Create( this, GetActiveWindow(), mpDrawView, GetDoc(), rReq ) );
173 Cancel();
174 rReq.Ignore ();
176 break;
178 case SID_INSERT_GRAPHIC:
180 SetCurrentFunction( FuInsertGraphic::Create( this, GetActiveWindow(), mpDrawView, GetDoc(), rReq ) );
181 Cancel();
182 rReq.Ignore ();
183 Invalidate(SID_DRAWTBX_INSERT);
185 break;
187 case SID_INSERT_AVMEDIA:
189 SetCurrentFunction( FuInsertAVMedia::Create( this, GetActiveWindow(), mpDrawView, GetDoc(), rReq ) );
191 Cancel();
192 rReq.Ignore ();
194 Invalidate(SID_DRAWTBX_INSERT);
196 break;
198 case SID_INSERT_OBJECT:
199 case SID_INSERT_PLUGIN:
200 case SID_INSERT_SOUND:
201 case SID_INSERT_VIDEO:
202 case SID_INSERT_APPLET:
203 case SID_INSERT_FLOATINGFRAME:
204 case SID_INSERT_MATH:
205 case SID_INSERT_DIAGRAM:
206 case SID_ATTR_TABLE:
208 SetCurrentFunction( FuInsertOLE::Create( this, GetActiveWindow(), mpDrawView, GetDoc(), rReq ) );
210 Cancel();
211 rReq.Ignore ();
213 Invalidate(SID_DRAWTBX_INSERT);
215 break;
217 case SID_COPYOBJECTS:
219 if ( mpDrawView->IsPresObjSelected(FALSE, TRUE) )
221 ::sd::Window* pWindow = GetActiveWindow();
222 InfoBox(pWindow, String(SdResId(STR_ACTION_NOTPOSSIBLE) ) ).Execute();
224 else
226 if ( mpDrawView->IsTextEdit() )
228 mpDrawView->SdrEndTextEdit();
231 SetCurrentFunction( FuCopy::Create( this, GetActiveWindow(), mpDrawView, GetDoc(), rReq ) );
233 Cancel();
234 rReq.Ignore ();
236 break;
238 case SID_INSERTFILE: // BASIC
240 Broadcast (ViewShellHint(ViewShellHint::HINT_COMPLEX_MODEL_CHANGE_START));
241 SetCurrentFunction( FuInsertFile::Create( this, GetActiveWindow(), mpDrawView, GetDoc(), rReq ) );
242 Broadcast (ViewShellHint(ViewShellHint::HINT_COMPLEX_MODEL_CHANGE_END));
243 Cancel();
244 rReq.Done ();
246 Invalidate(SID_DRAWTBX_INSERT);
248 break;
250 case SID_SELECT_BACKGROUND:
251 case SID_PAGESETUP: // BASIC ??
253 SetCurrentFunction( FuPage::Create( this, GetActiveWindow(), mpDrawView, GetDoc(), rReq ) );
254 Cancel();
255 rReq.Ignore (); // es werden eigenstaendige macros generiert !!
257 break;
259 case SID_ZOOM_OUT:
260 case SID_ZOOM_PANNING:
262 mbZoomOnPage = FALSE;
263 SetCurrentFunction( FuZoom::Create(this, GetActiveWindow(), mpDrawView, GetDoc(), rReq) );
264 // Beendet sich selbst, kein Cancel() notwendig!
265 Invalidate( SID_ZOOM_TOOLBOX );
266 rReq.Ignore ();
268 break;
270 case SID_BEFORE_OBJ:
271 case SID_BEHIND_OBJ:
273 SetCurrentFunction( FuDisplayOrder::Create(this, GetActiveWindow(), mpDrawView, GetDoc(), rReq) );
274 Invalidate( SID_POSITION );
275 rReq.Ignore ();
276 // Beendet sich selbst, kein Cancel() notwendig!
278 break;
280 case SID_REVERSE_ORDER: // BASIC
282 mpDrawView->ReverseOrderOfMarked();
283 Invalidate( SID_POSITION );
284 Cancel();
285 rReq.Done ();
287 break;
289 case SID_ANIMATION_EFFECTS:
291 SetCurrentFunction( FuObjectAnimationParameters::Create( this, GetActiveWindow(), mpDrawView, GetDoc(), rReq) );
292 Cancel();
294 break;
296 case SID_LINEEND_POLYGON:
298 SetCurrentFunction( FuLineEnd::Create( this, GetActiveWindow(), mpDrawView, GetDoc(), rReq ) );
299 Cancel();
301 break;
303 case SID_CAPTUREPOINT:
304 // negative Werte um Aufruf aus Menue zu signalisieren
305 maMousePos = Point(-1,-1);
306 case SID_SET_SNAPITEM:
308 SetCurrentFunction( FuSnapLine::Create(this, GetActiveWindow(), mpDrawView, GetDoc(), rReq) );
309 Cancel();
311 break;
313 case SID_MANAGE_LINKS:
315 SetCurrentFunction( FuLink::Create( this, GetActiveWindow(), mpDrawView, GetDoc(), rReq ) );
316 Cancel();
317 rReq.Ignore ();
319 break;
321 case SID_THESAURUS:
323 SetCurrentFunction( FuThesaurus::Create( this, GetActiveWindow(), mpDrawView, GetDoc(), rReq ) );
324 Cancel();
325 rReq.Ignore ();
327 break;
329 case SID_TEXTATTR_DLG:
331 SetCurrentFunction( FuTextAttrDlg::Create( this, GetActiveWindow(), mpDrawView, GetDoc(), rReq ) );
332 Cancel();
333 rReq.Ignore ();
335 break;
337 case SID_MEASURE_DLG:
339 SetCurrentFunction( FuMeasureDlg::Create( this, GetActiveWindow(), mpDrawView, GetDoc(), rReq ) );
340 Cancel();
341 rReq.Ignore ();
343 break;
345 case SID_CONNECTION_DLG:
347 SetCurrentFunction( FuConnectionDlg::Create( this, GetActiveWindow(), mpDrawView, GetDoc(), rReq ) );
348 Cancel();
349 rReq.Done();
351 break;
353 case SID_CONNECTION_NEW_ROUTING:
355 SfxItemSet aDefAttr( GetPool(), SDRATTR_EDGELINE1DELTA, SDRATTR_EDGELINE3DELTA );
356 GetView()->SetAttributes( aDefAttr, TRUE ); // (ReplaceAll)
358 Cancel();
359 rReq.Done();
361 break;
363 case SID_TWAIN_SELECT:
365 BOOL bDone = FALSE;
367 if( mxScannerManager.is() )
371 const ::com::sun::star::uno::Sequence< ::com::sun::star::scanner::ScannerContext >
372 aContexts( mxScannerManager->getAvailableScanners() );
374 if( aContexts.getLength() )
376 ::com::sun::star::scanner::ScannerContext aContext( aContexts.getConstArray()[ 0 ] );
377 bDone = mxScannerManager->configureScanner( aContext );
380 catch(...)
385 Cancel();
386 rReq.Done();
388 break;
390 case SID_TWAIN_TRANSFER:
392 BOOL bDone = FALSE;
394 if( mxScannerManager.is() )
398 const ::com::sun::star::uno::Sequence< ::com::sun::star::scanner::ScannerContext > aContexts( mxScannerManager->getAvailableScanners() );
400 if( aContexts.getLength() )
402 mxScannerManager->startScan( aContexts.getConstArray()[ 0 ], mxScannerListener );
403 bDone = TRUE;
406 catch( ... )
411 if( !bDone )
413 #ifndef UNX
414 const USHORT nId = STR_TWAIN_NO_SOURCE;
415 #else
416 const USHORT nId = STR_TWAIN_NO_SOURCE_UNX;
417 #endif
419 ::sd::Window* pWindow = GetActiveWindow();
420 InfoBox(pWindow, String( SdResId( nId ) ) ).Execute();
422 else
424 SfxBindings& rBindings = GetViewFrame()->GetBindings();
425 rBindings.Invalidate( SID_TWAIN_SELECT );
426 rBindings.Invalidate( SID_TWAIN_TRANSFER );
429 Cancel();
430 rReq.Done();
432 break;
434 case SID_POLYGON_MORPHING:
436 SetCurrentFunction( FuMorph::Create( this, GetActiveWindow(), mpDrawView, GetDoc(), rReq ) );
437 Cancel();
439 break;
441 case SID_VECTORIZE:
443 SetCurrentFunction( FuVectorize::Create( this, GetActiveWindow(), mpDrawView, GetDoc(), rReq ) );
444 Cancel();
446 break;
448 default:
450 // switch Anweisung wegen CLOOKS aufgeteilt. Alle case-Anweisungen die
451 // eine Fu???? -Funktion aufrufen, sind in die Methode FuTemp01 (drviews8),
452 // FuTemp02 (drviewsb) gewandert.
453 FuTemp02(rReq);
455 break;
459 /*************************************************************************
461 |* Scanner-Event
463 \************************************************************************/
465 void DrawViewShell::ScannerEvent( const ::com::sun::star::lang::EventObject& )
467 if( mxScannerManager.is() )
469 const ::com::sun::star::scanner::ScannerContext aContext( mxScannerManager->getAvailableScanners().getConstArray()[ 0 ] );
470 const ::com::sun::star::scanner::ScanError eError = mxScannerManager->getError( aContext );
472 if( ::com::sun::star::scanner::ScanError_ScanErrorNone == eError )
474 const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XBitmap > xBitmap( mxScannerManager->getBitmap( aContext ) );
476 if( xBitmap.is() )
478 const BitmapEx aScanBmp( VCLUnoHelper::GetBitmap( xBitmap ) );
480 if( !!aScanBmp )
482 const ::vos::OGuard aGuard( Application::GetSolarMutex() );
483 SdrPage* pPage = mpDrawView->GetSdrPageView()->GetPage();
484 Size aBmpSize( aScanBmp.GetPrefSize() ), aPageSize( pPage->GetSize() );
485 const MapMode aMap100( MAP_100TH_MM );
487 if( !aBmpSize.Width() || !aBmpSize.Height() )
488 aBmpSize = aScanBmp.GetSizePixel();
490 if( aScanBmp.GetPrefMapMode().GetMapUnit() == MAP_PIXEL )
491 aBmpSize = GetActiveWindow()->PixelToLogic( aBmpSize, aMap100 );
492 else
493 aBmpSize = OutputDevice::LogicToLogic( aBmpSize, aScanBmp.GetPrefMapMode(), aMap100 );
495 aPageSize.Width() -= pPage->GetLftBorder() + pPage->GetRgtBorder();
496 aPageSize.Height() -= pPage->GetUppBorder() + pPage->GetLwrBorder();
498 if( ( ( aBmpSize.Height() > aPageSize.Height() ) || ( aBmpSize.Width() > aPageSize.Width() ) ) && aBmpSize.Height() && aPageSize.Height() )
500 double fGrfWH = (double) aBmpSize.Width() / aBmpSize.Height();
501 double fWinWH = (double) aPageSize.Width() / aPageSize.Height();
503 if( fGrfWH < fWinWH )
505 aBmpSize.Width() = FRound( aPageSize.Height() * fGrfWH );
506 aBmpSize.Height()= aPageSize.Height();
508 else if( fGrfWH > 0.F )
510 aBmpSize.Width() = aPageSize.Width();
511 aBmpSize.Height()= FRound( aPageSize.Width() / fGrfWH );
515 Point aPnt ( ( aPageSize.Width() - aBmpSize.Width() ) >> 1, ( aPageSize.Height() - aBmpSize.Height() ) >> 1 );
516 aPnt += Point( pPage->GetLftBorder(), pPage->GetUppBorder() );
517 Rectangle aRect( aPnt, aBmpSize );
518 SdrGrafObj* pGrafObj = NULL;
519 BOOL bInsertNewObject = TRUE;
521 if( GetView()->AreObjectsMarked() )
523 const SdrMarkList& rMarkList = mpDrawView->GetMarkedObjectList();
525 if( rMarkList.GetMarkCount() == 1 )
527 SdrMark* pMark = rMarkList.GetMark(0);
528 SdrObject* pObj = pMark->GetMarkedSdrObj();
530 if( pObj->ISA( SdrGrafObj ) )
532 pGrafObj = static_cast< SdrGrafObj* >( pObj );
534 if( pGrafObj->IsEmptyPresObj() )
536 bInsertNewObject = FALSE;
537 pGrafObj->SetEmptyPresObj(FALSE);
538 pGrafObj->SetOutlinerParaObject(NULL);
539 pGrafObj->SetGraphic( Graphic( aScanBmp ) );
545 if( bInsertNewObject )
547 pGrafObj = new SdrGrafObj( Graphic( aScanBmp ), aRect );
548 SdrPageView* pPV = GetView()->GetSdrPageView();
549 GetView()->InsertObjectAtView( pGrafObj, *pPV, SDRINSERT_SETDEFLAYER );
556 SfxBindings& rBindings = GetViewFrame()->GetBindings();
557 rBindings.Invalidate( SID_TWAIN_SELECT );
558 rBindings.Invalidate( SID_TWAIN_TRANSFER );
561 } // end of namespace sd