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