xref: /AOO41X/main/sd/source/ui/view/drviewsa.cxx (revision fe617e93560c0575040cf13b538ba840fa9e2479)
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 #include <cppuhelper/implbase1.hxx>
29 #include <comphelper/processfactory.hxx>
30 #ifndef _SVX_SIZEITEM
31 #include <editeng/sizeitem.hxx>
32 #endif
33 #include <svx/svdlayer.hxx>
34 #ifndef _SVX_ZOOMITEM
35 #include <svx/zoomitem.hxx>
36 #endif
37 #include <svx/svdpagv.hxx>
38 #include <svl/ptitem.hxx>
39 #include <svl/stritem.hxx>
40 #include <sfx2/request.hxx>
41 #include <sfx2/dispatch.hxx>
42 #include <svx/svdopath.hxx>
43 #include <sfx2/docfile.hxx>
44 #include <svx/zoomslideritem.hxx>
45 #include <svl/eitem.hxx>
46 
47 #ifndef _SVX_DIALOGS_HRC
48 #include <svx/dialogs.hrc>
49 #endif
50 #include <svx/extrusionbar.hxx>
51 #include <svx/fontworkbar.hxx>
52 #include <svx/clipfmtitem.hxx>
53 
54 
55 #include <sfx2/viewfrm.hxx>
56 #include <svx/fmshell.hxx>
57 #include <sfx2/dispatch.hxx>
58 #include <svtools/cliplistener.hxx>
59 #include <svx/float3d.hxx>
60 #include <svx/sidebar/SelectionAnalyzer.hxx>
61 #include "helpids.h"
62 
63 #include "view/viewoverlaymanager.hxx"
64 #include "app.hrc"
65 #include "helpids.h"
66 #include "strings.hrc"
67 #include "res_bmp.hrc"
68 #include "sdpage.hxx"
69 #include "FrameView.hxx"
70 #include "drawdoc.hxx"
71 #include "sdresid.hxx"
72 #include "DrawDocShell.hxx"
73 #include "Window.hxx"
74 #include "fupoor.hxx"
75 #include "fusel.hxx"
76 #include "drawview.hxx"
77 #include "SdUnoDrawView.hxx"
78 #include "ViewShellBase.hxx"
79 #include "SdUnoDrawView.hxx"
80 #include "slideshow.hxx"
81 #include "ToolBarManager.hxx"
82 #include "annotationmanager.hxx"
83 
84 #include <boost/bind.hpp>
85 
86 using namespace ::rtl;
87 using namespace ::com::sun::star;
88 using namespace ::com::sun::star::uno;
89 using sfx2::sidebar::EnumContext;
90 
91 namespace {
92 static const ::rtl::OUString MASTER_VIEW_TOOL_BAR_NAME(
93     ::rtl::OUString::createFromAscii("masterviewtoolbar"));
94 }
95 
96 namespace sd {
97 
98 sal_Bool DrawViewShell::mbPipette = sal_False;
99 
100 // ------------------------
101 // - ScannerEventListener -
102 // ------------------------
103 
104 class ScannerEventListener : public ::cppu::WeakImplHelper1< ::com::sun::star::lang::XEventListener >
105 {
106 private:
107 
108     DrawViewShell*      mpParent;
109 
110 public:
111 
112                             ScannerEventListener( DrawViewShell* pParent ) : mpParent( pParent )  {};
113                             ~ScannerEventListener();
114 
115     // XEventListener
116     virtual void SAL_CALL   disposing( const ::com::sun::star::lang::EventObject& rEventObject ) throw (::com::sun::star::uno::RuntimeException);
117 
118     void                    ParentDestroyed() { mpParent = NULL; }
119 };
120 
121 // -----------------------------------------------------------------------------
122 
123 ScannerEventListener::~ScannerEventListener()
124 {
125 }
126 
127 // -----------------------------------------------------------------------------
128 
129 void SAL_CALL ScannerEventListener::disposing( const ::com::sun::star::lang::EventObject& rEventObject ) throw (::com::sun::star::uno::RuntimeException)
130 {
131     if( mpParent )
132         mpParent->ScannerEvent( rEventObject );
133 }
134 
135 /*************************************************************************
136 |*
137 |* Standard-Konstruktor
138 |*
139 \************************************************************************/
140 
141 DrawViewShell::DrawViewShell( SfxViewFrame* pFrame, ViewShellBase& rViewShellBase, ::Window* pParentWindow, PageKind ePageKind, FrameView* pFrameViewArgument )
142 : ViewShell (pFrame, pParentWindow, rViewShellBase)
143 , maTabControl(this, pParentWindow)
144 , mbIsInSwitchPage(false),
145   mpSelectionChangeHandler(new svx::sidebar::SelectionChangeHandler(
146           ::boost::bind(&DrawViewShell::GetContextForSelection, this),
147           uno::Reference<frame::XController>(&rViewShellBase.GetDrawController()),
148           sfx2::sidebar::EnumContext::Context_Default))
149 
150 {
151     if (pFrameViewArgument != NULL)
152         mpFrameView = pFrameViewArgument;
153     else
154         mpFrameView = new FrameView(GetDoc());
155     Construct(GetDocSh(), ePageKind);
156 
157     mpSelectionChangeHandler->Connect();
158 }
159 
160 /*************************************************************************
161 |*
162 |* Destruktor
163 |*
164 \************************************************************************/
165 
166 DrawViewShell::~DrawViewShell()
167 {
168     mpSelectionChangeHandler->Disconnect();
169 
170     mpAnnotationManager.reset();
171     mpViewOverlayManager.reset();
172 
173     OSL_ASSERT (GetViewShell()!=NULL);
174 
175     if( mxScannerListener.is() )
176         static_cast< ScannerEventListener* >( mxScannerListener.get() )->ParentDestroyed();
177 
178     // #96642# Remove references to items within Svx3DWin
179     // (maybe do a listening sometime in Svx3DWin)
180     sal_uInt16 nId = Svx3DChildWindow::GetChildWindowId();
181     SfxChildWindow* pWindow = GetViewFrame() ? GetViewFrame()->GetChildWindow(nId) : NULL;
182     if(pWindow)
183     {
184         Svx3DWin* p3DWin = static_cast< Svx3DWin* > (pWindow->GetWindow());
185         if(p3DWin)
186             p3DWin->DocumentReload();
187     }
188 
189     EndListening (*GetDoc());
190     EndListening (*GetDocSh());
191 
192     if( SlideShow::IsRunning(*this) )
193         StopSlideShow(false);
194 
195     DisposeFunctions();
196 
197     SdPage* pPage;
198     sal_uInt16 aPageCnt = GetDoc()->GetSdPageCount(mePageKind);
199 
200     for (sal_uInt16 i = 0; i < aPageCnt; i++)
201     {
202         pPage = GetDoc()->GetSdPage(i, mePageKind);
203 
204         if (pPage == mpActualPage)
205         {
206             GetDoc()->SetSelected(pPage, sal_True);
207         }
208         else
209         {
210             GetDoc()->SetSelected(pPage, sal_False);
211         }
212     }
213 
214     if ( mpClipEvtLstnr )
215     {
216         mpClipEvtLstnr->AddRemoveListener( GetActiveWindow(), sal_False );
217         mpClipEvtLstnr->ClearCallbackLink();        // #103849# prevent callback if another thread is waiting
218         mpClipEvtLstnr->release();
219     }
220 
221     delete mpDrawView;
222     // Set mpView to NULL so that the destructor of the ViewShell base class
223     // does not access it.
224     mpView = mpDrawView = NULL;
225 
226     mpFrameView->Disconnect();
227     delete [] mpSlotArray;
228 }
229 
230 /*************************************************************************
231 |*
232 |* gemeinsamer Initialisierungsanteil der beiden Konstruktoren
233 |*
234 \************************************************************************/
235 
236 void DrawViewShell::Construct(DrawDocShell* pDocSh, PageKind eInitialPageKind)
237 {
238     mpActualPage = 0;
239     mbMousePosFreezed = sal_False;
240     mbReadOnly = GetDocSh()->IsReadOnly();
241     mpSlotArray = 0;
242     mpClipEvtLstnr = 0;
243     mbPastePossible = sal_False;
244     mbIsLayerModeActive = false;
245 
246     mpFrameView->Connect();
247 
248     OSL_ASSERT (GetViewShell()!=NULL);
249 
250     // Array fuer Slot-/ImageMapping:
251     // Gerader Eintrag: Haupt-/ToolboxSlot
252     // Ungerader Eintrag: gemappter Slot
253     // Achtung: Anpassen von GetIdBySubId() !!!
254     // Reihenfolge (insbesondere Zoom) darf nicht geaendert werden !!!
255     mpSlotArray = new sal_uInt16[ SLOTARRAY_COUNT ];
256     mpSlotArray[ 0 ]  = SID_OBJECT_CHOOSE_MODE;
257     mpSlotArray[ 1 ]  = SID_OBJECT_ROTATE;
258     mpSlotArray[ 2 ]  = SID_OBJECT_ALIGN;
259     mpSlotArray[ 3 ]  = SID_OBJECT_ALIGN_LEFT;
260     mpSlotArray[ 4 ]  = SID_ZOOM_TOOLBOX;
261     mpSlotArray[ 5 ]  = SID_ZOOM_TOOLBOX;
262     mpSlotArray[ 6 ]  = SID_DRAWTBX_TEXT;
263     mpSlotArray[ 7 ]  = SID_ATTR_CHAR;
264     mpSlotArray[ 8 ]  = SID_DRAWTBX_RECTANGLES;
265     mpSlotArray[ 9 ]  = SID_DRAW_RECT;
266     mpSlotArray[ 10 ] = SID_DRAWTBX_ELLIPSES;
267     mpSlotArray[ 11 ] = SID_DRAW_ELLIPSE;
268     mpSlotArray[ 12 ] = SID_DRAWTBX_LINES;
269     mpSlotArray[ 13 ] = SID_DRAW_FREELINE_NOFILL;
270     mpSlotArray[ 14 ] = SID_DRAWTBX_3D_OBJECTS;
271     mpSlotArray[ 15 ] = SID_3D_CUBE;
272     mpSlotArray[ 16 ] = SID_DRAWTBX_INSERT;
273     mpSlotArray[ 17 ] = SID_INSERT_DIAGRAM;
274     mpSlotArray[ 18 ] = SID_POSITION;
275     mpSlotArray[ 19 ] = SID_FRAME_TO_TOP;
276     mpSlotArray[ 20 ] = SID_DRAWTBX_CONNECTORS;
277     mpSlotArray[ 21 ] = SID_TOOL_CONNECTOR;
278     mpSlotArray[ 22 ] = SID_DRAWTBX_ARROWS;
279     mpSlotArray[ 23 ] = SID_LINE_ARROW_END;
280 
281     SetPool( &GetDoc()->GetPool() );
282 
283     GetDoc()->CreateFirstPages();
284 
285     mpDrawView = new DrawView(pDocSh, GetActiveWindow(), this);
286     mpView = mpDrawView;             // Pointer der Basisklasse ViewShell
287     mpDrawView->SetSwapAsynchron(sal_True); // Asynchrones Laden von Graphiken
288 
289     // We do not read the page kind from the frame view anymore so we have
290     // to set it in order to resync frame view and this view.
291     mpFrameView->SetPageKind(eInitialPageKind);
292     mePageKind = eInitialPageKind;
293     meEditMode = EM_PAGE;
294     DocumentType eDocType = GetDoc()->GetDocumentType(); // RTTI fasst hier noch nicht
295     switch (mePageKind)
296     {
297         case PK_STANDARD:
298             meShellType = ST_IMPRESS;
299             break;
300 
301         case PK_NOTES:
302             meShellType = ST_NOTES;
303             break;
304 
305         case PK_HANDOUT:
306             meShellType = ST_HANDOUT;
307             break;
308     }
309 
310     Size aPageSize( GetDoc()->GetSdPage(0, mePageKind)->GetSize() );
311     Point aPageOrg( aPageSize.Width(), aPageSize.Height() / 2);
312     Size aSize(aPageSize.Width() * 3, aPageSize.Height() * 2);
313     InitWindows(aPageOrg, aSize, Point(-1, -1));
314 
315     Point aVisAreaPos;
316 
317     if ( pDocSh->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
318     {
319         aVisAreaPos = pDocSh->GetVisArea(ASPECT_CONTENT).TopLeft();
320     }
321 
322     mpDrawView->SetWorkArea(Rectangle(Point() - aVisAreaPos - aPageOrg, aSize));
323 
324     // Objekte koennen max. so gross wie die ViewSize werden
325     GetDoc()->SetMaxObjSize(aSize);
326 
327     // Split-Handler fuer TabControls
328     maTabControl.SetSplitHdl( LINK( this, DrawViewShell, TabSplitHdl ) );
329 
330     // Damit der richtige EditMode von der FrameView komplett eingestellt
331     // werden kann, wird hier ein aktuell anderer gewaehlt (kleiner Trick)
332     if (mpFrameView->GetViewShEditMode(mePageKind) == EM_PAGE)
333     {
334         meEditMode = EM_MASTERPAGE;
335     }
336     else
337     {
338         meEditMode = EM_PAGE;
339     }
340 
341     // Einstellungen der FrameView uebernehmen
342     ReadFrameViewData(mpFrameView);
343 
344     if( eDocType == DOCUMENT_TYPE_DRAW )
345     {
346         SetHelpId( SD_IF_SDGRAPHICVIEWSHELL );
347         GetActiveWindow()->SetHelpId( HID_SDGRAPHICVIEWSHELL );
348         GetActiveWindow()->SetUniqueId( HID_SDGRAPHICVIEWSHELL );
349     }
350     else
351     {
352         if (mePageKind == PK_NOTES)
353         {
354             SetHelpId( SID_NOTESMODE );
355             GetActiveWindow()->SetHelpId( CMD_SID_NOTESMODE );
356             GetActiveWindow()->SetUniqueId( CMD_SID_NOTESMODE );
357 
358             // AutoLayouts muessen erzeugt sein
359             GetDoc()->StopWorkStartupDelay();
360         }
361         else if (mePageKind == PK_HANDOUT)
362         {
363             SetHelpId( SID_HANDOUTMODE );
364             GetActiveWindow()->SetHelpId( CMD_SID_HANDOUTMODE );
365             GetActiveWindow()->SetUniqueId( CMD_SID_HANDOUTMODE );
366 
367             // AutoLayouts muessen erzeugt sein
368             GetDoc()->StopWorkStartupDelay();
369         }
370         else
371         {
372             SetHelpId( SD_IF_SDDRAWVIEWSHELL );
373             GetActiveWindow()->SetHelpId( HID_SDDRAWVIEWSHELL );
374             GetActiveWindow()->SetUniqueId( HID_SDDRAWVIEWSHELL );
375         }
376     }
377 
378     // Selektionsfunktion starten
379     SfxRequest aReq(SID_OBJECT_SELECT, 0, GetDoc()->GetItemPool());
380     FuPermanent(aReq);
381     mpDrawView->SetFrameDragSingles(sal_True);
382 
383     if (pDocSh->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED)
384     {
385         mbZoomOnPage = sal_False;
386     }
387     else
388     {
389         mbZoomOnPage = sal_True;
390     }
391 
392     mbIsRulerDrag = sal_False;
393 
394     String aName( RTL_CONSTASCII_USTRINGPARAM("DrawViewShell"));
395     SetName (aName);
396 
397     mnLockCount = 0UL;
398 
399     ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xMgr( ::comphelper::getProcessServiceFactory() );
400 
401     if( xMgr.is() )
402     {
403         mxScannerManager = ::com::sun::star::uno::Reference< ::com::sun::star::scanner::XScannerManager >(
404                            xMgr->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.scanner.ScannerManager" ) ),
405                            ::com::sun::star::uno::UNO_QUERY );
406 
407         if( mxScannerManager.is() )
408         {
409             mxScannerListener = ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >(
410                                 static_cast< ::cppu::OWeakObject* >( new ScannerEventListener( this ) ),
411                                 ::com::sun::star::uno::UNO_QUERY );
412         }
413     }
414 
415     mpAnnotationManager.reset( new AnnotationManager( GetViewShellBase() ) );
416     mpViewOverlayManager.reset( new ViewOverlayManager( GetViewShellBase() ) );
417 }
418 
419 
420 
421 
422 void DrawViewShell::Init (bool bIsMainViewShell)
423 {
424     ViewShell::Init(bIsMainViewShell);
425 
426     StartListening (*GetDocSh());
427 }
428 
429 
430 
431 
432 void DrawViewShell::Shutdown (void)
433 {
434     ViewShell::Shutdown();
435 
436     if(SlideShow::IsRunning( GetViewShellBase() ) )
437     {
438         // Turn off effects.
439         GetDrawView()->SetAnimationMode(SDR_ANIMATION_DISABLE);
440     }
441 }
442 
443 
444 
445 
446 css::uno::Reference<css::drawing::XDrawSubController> DrawViewShell::CreateSubController (void)
447 {
448     css::uno::Reference<css::drawing::XDrawSubController> xSubController;
449 
450     if (IsMainViewShell())
451     {
452         // Create uno sub controller for the main view shell.
453         xSubController = css::uno::Reference<css::drawing::XDrawSubController>(
454             new SdUnoDrawView (
455                 GetViewShellBase().GetDrawController(),
456                 *this,
457                 *GetView()));
458     }
459 
460     return xSubController;
461 }
462 
463 
464 
465 
466 bool DrawViewShell::RelocateToParentWindow (::Window* pParentWindow)
467 {
468     // DrawViewShells can not be relocated to a new parent window at the
469     // moment, so return <FALSE/> except when the given parent window is the
470     // parent window that is already in use.
471     return pParentWindow==GetParentWindow();
472 }
473 
474 
475 
476 
477 /*************************************************************************
478 |*
479 |* pruefe ob linienzuege gezeichnet werden muessen
480 |*
481 \************************************************************************/
482 
483 /*
484     linienzuege werden ueber makros als folge von
485         MoveTo (x, y)
486         LineTo (x, y)   [oder BezierTo (x, y)]
487         LineTo (x, y)
488             :
489     dargestellt. einen endbefehl fuer die linienzuege
490     gibt es nicht, also muessen alle befehle in den
491     requests nach LineTo (BezierTo) abgetestet und die
492     punktparameter gesammelt werden.
493     der erste nicht-LineTo fuehrt dann dazu, dass aus
494     den gesammelten punkten der linienzug erzeugt wird
495 */
496 
497 void DrawViewShell::CheckLineTo(SfxRequest& rReq)
498 {
499     (void)rReq;
500 #ifdef DBG_UTIL
501     if(rReq.IsAPI())
502     {
503         if(SID_LINETO == rReq.GetSlot() || SID_BEZIERTO == rReq.GetSlot() || SID_MOVETO == rReq.GetSlot() )
504         {
505             DBG_ERROR("DrawViewShell::CheckLineTo: slots SID_LINETO, SID_BEZIERTO, SID_MOVETO no longer supported.");
506         }
507     }
508 #endif
509 
510     rReq.Ignore ();
511 }
512 
513 /*************************************************************************
514 |*
515 |* veraendere die seitemparameter, wenn SID_PAGESIZE oder SID_PAGEMARGIN
516 |*
517 \************************************************************************/
518 
519 void DrawViewShell::SetupPage (Size &rSize,
520                                  long nLeft,
521                                  long nRight,
522                                  long nUpper,
523                                  long nLower,
524                                  sal_Bool bSize,
525                                  sal_Bool bMargin,
526                                  sal_Bool bScaleAll)
527 {
528     sal_uInt16 nPageCnt = GetDoc()->GetMasterSdPageCount(mePageKind);
529     sal_uInt16 i;
530 
531     for (i = 0; i < nPageCnt; i++)
532     {
533         /**********************************************************************
534         * Erst alle MasterPages bearbeiten
535         **********************************************************************/
536         SdPage *pPage = GetDoc()->GetMasterSdPage(i, mePageKind);
537 
538         if( pPage )
539         {
540             if( bSize )
541             {
542                 Rectangle aBorderRect(nLeft, nUpper, nRight, nLower);
543                 pPage->ScaleObjects(rSize, aBorderRect, bScaleAll);
544                 pPage->SetSize(rSize);
545 
546             }
547             if( bMargin )
548             {
549                 pPage->SetLftBorder(nLeft);
550                 pPage->SetRgtBorder(nRight);
551                 pPage->SetUppBorder(nUpper);
552                 pPage->SetLwrBorder(nLower);
553             }
554 
555             if ( mePageKind == PK_STANDARD )
556             {
557                 GetDoc()->GetMasterSdPage(i, PK_NOTES)->CreateTitleAndLayout();
558             }
559 
560             pPage->CreateTitleAndLayout();
561         }
562     }
563 
564     nPageCnt = GetDoc()->GetSdPageCount(mePageKind);
565 
566     for (i = 0; i < nPageCnt; i++)
567     {
568         /**********************************************************************
569         * Danach alle Pages bearbeiten
570         **********************************************************************/
571         SdPage *pPage = GetDoc()->GetSdPage(i, mePageKind);
572 
573         if( pPage )
574         {
575             if( bSize )
576             {
577                 Rectangle aBorderRect(nLeft, nUpper, nRight, nLower);
578                 pPage->ScaleObjects(rSize, aBorderRect, bScaleAll);
579                 pPage->SetSize(rSize);
580             }
581             if( bMargin )
582             {
583                 pPage->SetLftBorder(nLeft);
584                 pPage->SetRgtBorder(nRight);
585                 pPage->SetUppBorder(nUpper);
586                 pPage->SetLwrBorder(nLower);
587             }
588 
589             if ( mePageKind == PK_STANDARD )
590             {
591                 SdPage* pNotesPage = GetDoc()->GetSdPage(i, PK_NOTES);
592                 pNotesPage->SetAutoLayout( pNotesPage->GetAutoLayout() );
593             }
594 
595             pPage->SetAutoLayout( pPage->GetAutoLayout() );
596         }
597     }
598 
599     if ( mePageKind == PK_STANDARD )
600     {
601         SdPage* pHandoutPage = GetDoc()->GetSdPage(0, PK_HANDOUT);
602         pHandoutPage->CreateTitleAndLayout(sal_True);
603     }
604 
605     long nWidth = mpActualPage->GetSize().Width();
606     long nHeight = mpActualPage->GetSize().Height();
607 
608     Point aPageOrg(nWidth, nHeight / 2);
609     Size aSize( nWidth * 3, nHeight * 2);
610 
611     InitWindows(aPageOrg, aSize, Point(-1, -1), sal_True);
612 
613     Point aVisAreaPos;
614 
615     if ( GetDocSh()->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
616     {
617         aVisAreaPos = GetDocSh()->GetVisArea(ASPECT_CONTENT).TopLeft();
618     }
619 
620     GetView()->SetWorkArea(Rectangle(Point() - aVisAreaPos - aPageOrg, aSize));
621 
622     UpdateScrollBars();
623 
624     Point aNewOrigin(mpActualPage->GetLftBorder(), mpActualPage->GetUppBorder());
625     GetView()->GetSdrPageView()->SetPageOrigin(aNewOrigin);
626 
627     GetViewFrame()->GetBindings().Invalidate(SID_RULER_NULL_OFFSET);
628 
629     // auf (neue) Seitengroesse zoomen
630     GetViewFrame()->GetDispatcher()->Execute(SID_SIZE_PAGE,
631                         SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD);
632 }
633 
634 /*************************************************************************
635 |*
636 |* Statuswerte der Statusbar zurueckgeben
637 |*
638 \************************************************************************/
639 
640 void DrawViewShell::GetStatusBarState(SfxItemSet& rSet)
641 {
642     // Zoom-Item
643     // Hier sollte der entsprechende Wert (Optimal ?, Seitenbreite oder
644     // Seite) mit Hilfe des ZoomItems weitergegeben werden !!!
645     if( SFX_ITEM_AVAILABLE == rSet.GetItemState( SID_ATTR_ZOOM ) )
646     {
647         if (GetDocSh()->IsUIActive() || (SlideShow::IsRunning(GetViewShellBase())) )
648         {
649             rSet.DisableItem( SID_ATTR_ZOOM );
650         }
651         else
652         {
653             SvxZoomItem* pZoomItem;
654             sal_uInt16 nZoom = (sal_uInt16) GetActiveWindow()->GetZoom();
655 
656             if( mbZoomOnPage )
657                 pZoomItem = new SvxZoomItem( SVX_ZOOM_WHOLEPAGE, nZoom );
658             else
659                 pZoomItem = new SvxZoomItem( SVX_ZOOM_PERCENT, nZoom );
660 
661             // Bereich einschraenken
662             sal_uInt16 nZoomValues = SVX_ZOOM_ENABLE_ALL;
663             SdrPageView* pPageView = mpDrawView->GetSdrPageView();
664 
665             if( ( pPageView && pPageView->GetObjList()->GetObjCount() == 0 ) )
666                 // || ( mpDrawView->GetMarkedObjectList().GetMarkCount() == 0 ) )
667             {
668                 nZoomValues &= ~SVX_ZOOM_ENABLE_OPTIMAL;
669             }
670 
671             pZoomItem->SetValueSet( nZoomValues );
672             rSet.Put( *pZoomItem );
673             delete pZoomItem;
674         }
675     }
676     if( SFX_ITEM_AVAILABLE == rSet.GetItemState( SID_ATTR_ZOOMSLIDER ) )
677     {
678         rtl::Reference< sd::SlideShow > xSlideshow( SlideShow::GetSlideShow( GetDoc() ) );
679         if (GetDocSh()->IsUIActive() || (xSlideshow.is() && xSlideshow->isRunning()) || !GetActiveWindow() )
680         {
681             rSet.DisableItem( SID_ATTR_ZOOMSLIDER );
682         }
683         else
684         {
685             sd::Window * pActiveWindow = GetActiveWindow();
686             SvxZoomSliderItem aZoomItem( (sal_uInt16) pActiveWindow->GetZoom(), (sal_uInt16)pActiveWindow->GetMinZoom(), (sal_uInt16)pActiveWindow->GetMaxZoom() ) ;
687 
688             SdrPageView* pPageView = mpDrawView->GetSdrPageView();
689             if( pPageView )
690             {
691                 Point aPagePos(0, 0);
692                 Size aPageSize = pPageView->GetPage()->GetSize();
693 
694                 aPagePos.X() += aPageSize.Width()  / 2;
695                 aPageSize.Width() = (long) (aPageSize.Width() * 1.03);
696 
697                 aPagePos.Y() += aPageSize.Height() / 2;
698                 aPageSize.Height() = (long) (aPageSize.Height() * 1.03);
699                 aPagePos.Y() -= aPageSize.Height() / 2;
700 
701                 aPagePos.X() -= aPageSize.Width()  / 2;
702 
703                 Rectangle aFullPageZoomRect( aPagePos, aPageSize );
704                 aZoomItem.AddSnappingPoint( pActiveWindow->GetZoomForRect( aFullPageZoomRect ) );
705             }
706             aZoomItem.AddSnappingPoint(100);
707             rSet.Put( aZoomItem );
708         }
709     }
710 
711     Point aPos = GetActiveWindow()->PixelToLogic(maMousePos);
712     mpDrawView->GetSdrPageView()->LogicToPagePos(aPos);
713     Fraction aUIScale(GetDoc()->GetUIScale());
714     aPos.X() = Fraction(aPos.X()) / aUIScale;
715     aPos.Y() = Fraction(aPos.Y()) / aUIScale;
716 
717     // Position- und Groesse-Items
718     if ( mpDrawView->IsAction() )
719     {
720         Rectangle aRect;
721         mpDrawView->TakeActionRect( aRect );
722 
723         if ( aRect.IsEmpty() )
724             rSet.Put( SfxPointItem(SID_ATTR_POSITION, aPos) );
725         else
726         {
727             mpDrawView->GetSdrPageView()->LogicToPagePos(aRect);
728             aPos = aRect.TopLeft();
729             aPos.X() = Fraction(aPos.X()) / aUIScale;
730             aPos.Y() = Fraction(aPos.Y()) / aUIScale;
731             rSet.Put( SfxPointItem( SID_ATTR_POSITION, aPos) );
732             Size aSize( aRect.Right() - aRect.Left(), aRect.Bottom() - aRect.Top() );
733             aSize.Height() = Fraction(aSize.Height()) / aUIScale;
734             aSize.Width()  = Fraction(aSize.Width())  / aUIScale;
735             rSet.Put( SvxSizeItem( SID_ATTR_SIZE, aSize) );
736         }
737     }
738     else
739     {
740         if ( mpDrawView->AreObjectsMarked() )
741         {
742             Rectangle aRect = mpDrawView->GetAllMarkedRect();
743             mpDrawView->GetSdrPageView()->LogicToPagePos(aRect);
744 
745             // Show the position of the selected shape(s)
746             Point aShapePosition (aRect.TopLeft());
747             aShapePosition.X() = Fraction(aShapePosition.X()) / aUIScale;
748             aShapePosition.Y() = Fraction(aShapePosition.Y()) / aUIScale;
749             rSet.Put (SfxPointItem(SID_ATTR_POSITION, aShapePosition));
750 
751             Size aSize( aRect.Right() - aRect.Left(), aRect.Bottom() - aRect.Top() );
752             aSize.Height() = Fraction(aSize.Height()) / aUIScale;
753             aSize.Width()  = Fraction(aSize.Width())  / aUIScale;
754             rSet.Put( SvxSizeItem( SID_ATTR_SIZE, aSize) );
755         }
756         else
757         {
758             rSet.Put( SfxPointItem(SID_ATTR_POSITION, aPos) );
759             rSet.Put( SvxSizeItem( SID_ATTR_SIZE, Size( 0, 0 ) ) );
760         }
761     }
762 
763     // Display of current page and layer.
764     if( SFX_ITEM_AVAILABLE == rSet.GetItemState( SID_STATUS_PAGE ) )
765     {
766         // Allways show the slide/page number.
767         String aString (SdResId( STR_SD_PAGE ));
768         aString += sal_Unicode(' ');
769         aString += UniString::CreateFromInt32( maTabControl.GetCurPageId() );
770         aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( " / " ));
771         aString += UniString::CreateFromInt32( GetDoc()->GetSdPageCount( mePageKind ) );
772 
773         // If in layer mode additionally show the layer that contains all
774         // selected shapes of the page.  If the shapes are distributed on
775         // more than one layer, no layer name is shown.
776         if (IsLayerModeActive())
777         {
778             SdrLayerAdmin& rLayerAdmin = GetDoc()->GetLayerAdmin();
779             SdrLayerID nLayer = 0, nOldLayer = 0;
780             SdrLayer*  pLayer = NULL;
781             SdrObject* pObj = NULL;
782             const SdrMarkList& rMarkList = mpDrawView->GetMarkedObjectList();
783             sal_uLong nMarkCount = rMarkList.GetMarkCount();
784             FASTBOOL bOneLayer = sal_True;
785 
786             // Use the first ten selected shapes as a (hopefully
787             // representative) sample of all shapes of the current page.
788             // Detect whether they belong to the same layer.
789             for( sal_uLong j = 0; j < nMarkCount && bOneLayer && j < 10; j++ )
790             {
791                 pObj = rMarkList.GetMark( j )->GetMarkedSdrObj();
792                 if( pObj )
793                 {
794                     nLayer = pObj->GetLayer();
795 
796                     if( j != 0 && nLayer != nOldLayer )
797                         bOneLayer = sal_False;
798 
799                     nOldLayer = nLayer;
800                 }
801             }
802 
803             // Append the layer name to the current page number.
804             if( bOneLayer && nMarkCount )
805             {
806                 pLayer = rLayerAdmin.GetLayerPerID( nLayer );
807                 if( pLayer )
808                 {
809                     aString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( " (" ));
810                     aString += pLayer->GetName();
811                     aString += sal_Unicode(')');
812                 }
813             }
814         }
815 
816         rSet.Put (SfxStringItem (SID_STATUS_PAGE, aString));
817     }
818     // Layout
819     if( SFX_ITEM_AVAILABLE == rSet.GetItemState( SID_STATUS_LAYOUT ) )
820     {
821         String aString = mpActualPage->GetLayoutName();
822         aString.Erase( aString.SearchAscii( SD_LT_SEPARATOR ) );
823         rSet.Put( SfxStringItem( SID_STATUS_LAYOUT, aString ) );
824     }
825 }
826 
827 
828 
829 void DrawViewShell::Notify (SfxBroadcaster&, const SfxHint& rHint)
830 {
831     const SfxSimpleHint* pSimple = dynamic_cast< const SfxSimpleHint* >(&rHint);
832     if (pSimple!=NULL && pSimple->GetId()==SFX_HINT_MODECHANGED)
833     {
834         // Change to selection when turning on read-only mode.
835         if(GetDocSh()->IsReadOnly() && dynamic_cast< FuSelection* >( GetCurrentFunction().get() ) )
836         {
837             SfxRequest aReq(SID_OBJECT_SELECT, 0, GetDoc()->GetItemPool());
838             FuPermanent(aReq);
839         }
840 
841         // Turn on design mode when document is not read-only.
842         if (GetDocSh()->IsReadOnly() != mbReadOnly )
843         {
844             mbReadOnly = GetDocSh()->IsReadOnly();
845 
846             SfxBoolItem aItem( SID_FM_DESIGN_MODE, !mbReadOnly );
847             GetViewFrame()->GetDispatcher()->Execute( SID_FM_DESIGN_MODE,
848                 SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD, &aItem, 0L );
849         }
850     }
851 
852 }
853 
854 void DrawViewShell::ExecuteAnnotation (SfxRequest& rRequest)
855 {
856     if( mpAnnotationManager.get() )
857         mpAnnotationManager->ExecuteAnnotation( rRequest );
858 }
859 
860 // --------------------------------------------------------------------
861 
862 void DrawViewShell::GetAnnotationState (SfxItemSet& rItemSet )
863 {
864     if( mpAnnotationManager.get() )
865         mpAnnotationManager->GetAnnotationState( rItemSet );
866 }
867 
868 
869 EnumContext::Context DrawViewShell::GetContextForSelection (void) const
870 {
871     if (mpDrawView->GetMarkedObjectList().GetMarkCount() == 1)
872         if (mpDrawView->GetTextEditObject() != NULL)
873             if (mpDrawView->GetTextEditOutlinerView() != NULL)
874                 return EnumContext::Context_DrawText;
875 
876     // All other cases are handled by the SelectionAnalyzer.
877     return ::svx::sidebar::SelectionAnalyzer::GetContextForSelection_SD(
878         mpDrawView->GetMarkedObjectList(),
879         meEditMode == EM_MASTERPAGE,
880         mePageKind == PK_HANDOUT,
881         mePageKind == PK_NOTES);
882 }
883 
884 
885 } // end of namespace sd
886