Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "DrawViewShell.hxx"
21 : #include <com/sun/star/scanner/ScannerManager.hpp>
22 : #include <cppuhelper/implbase1.hxx>
23 : #include <comphelper/processfactory.hxx>
24 : #include <editeng/sizeitem.hxx>
25 : #include <svx/svdlayer.hxx>
26 : #include <sfx2/zoomitem.hxx>
27 : #include <svx/svdpagv.hxx>
28 : #include <svl/ptitem.hxx>
29 : #include <svl/stritem.hxx>
30 : #include <sfx2/request.hxx>
31 : #include <sfx2/dispatch.hxx>
32 : #include <svx/svdopath.hxx>
33 : #include <sfx2/docfile.hxx>
34 : #include <svx/zoomslideritem.hxx>
35 : #include <svl/eitem.hxx>
36 :
37 : #include <svx/dialogs.hrc>
38 : #include <svx/extrusionbar.hxx>
39 : #include <svx/fontworkbar.hxx>
40 : #include <svx/clipfmtitem.hxx>
41 :
42 : #include <sfx2/viewfrm.hxx>
43 : #include <svx/fmshell.hxx>
44 : #include <svtools/cliplistener.hxx>
45 : #include <svx/float3d.hxx>
46 : #include <svx/extedit.hxx>
47 : #include <svx/sidebar/SelectionAnalyzer.hxx>
48 : #include "helpids.h"
49 :
50 : #include "view/viewoverlaymanager.hxx"
51 : #include "app.hrc"
52 : #include "strings.hrc"
53 : #include "res_bmp.hrc"
54 : #include "sdpage.hxx"
55 : #include "FrameView.hxx"
56 : #include "drawdoc.hxx"
57 : #include "sdresid.hxx"
58 : #include "DrawDocShell.hxx"
59 : #include "Window.hxx"
60 : #include "fupoor.hxx"
61 : #include "fusel.hxx"
62 : #include "drawview.hxx"
63 : #include "SdUnoDrawView.hxx"
64 : #include "ViewShellBase.hxx"
65 : #include "slideshow.hxx"
66 : #include "ToolBarManager.hxx"
67 : #include "annotationmanager.hxx"
68 : #include "DrawController.hxx"
69 :
70 : #include <boost/bind.hpp>
71 : #include <boost/scoped_ptr.hpp>
72 :
73 : using namespace ::com::sun::star;
74 : using namespace ::com::sun::star::uno;
75 : using sfx2::sidebar::EnumContext;
76 :
77 : namespace sd {
78 :
79 : bool DrawViewShell::mbPipette = false;
80 :
81 : // - ScannerEventListener -
82 :
83 : class ScannerEventListener : public ::cppu::WeakImplHelper1< lang::XEventListener >
84 : {
85 : private:
86 :
87 : DrawViewShell* mpParent;
88 :
89 : public:
90 :
91 125 : ScannerEventListener( DrawViewShell* pParent ) : mpParent( pParent ) {};
92 : virtual ~ScannerEventListener();
93 :
94 : // XEventListener
95 : virtual void SAL_CALL disposing( const lang::EventObject& rEventObject ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE;
96 :
97 125 : void ParentDestroyed() { mpParent = NULL; }
98 : };
99 :
100 250 : ScannerEventListener::~ScannerEventListener()
101 : {
102 250 : }
103 :
104 0 : void SAL_CALL ScannerEventListener::disposing( const lang::EventObject& rEventObject ) throw (uno::RuntimeException, std::exception)
105 : {
106 0 : if( mpParent )
107 0 : mpParent->ScannerEvent( rEventObject );
108 0 : }
109 :
110 133 : DrawViewShell::DrawViewShell( SfxViewFrame* pFrame, ViewShellBase& rViewShellBase, vcl::Window* pParentWindow, PageKind ePageKind, FrameView* pFrameViewArgument )
111 : : ViewShell (pFrame, pParentWindow, rViewShellBase)
112 : , maTabControl(VclPtr<sd::TabControl>::Create(this, pParentWindow))
113 : , mbIsLayerModeActive(false)
114 : , mbIsInSwitchPage(false)
115 : , mpSelectionChangeHandler(new svx::sidebar::SelectionChangeHandler(
116 : ::boost::bind(&DrawViewShell::GetSidebarContextName, this),
117 133 : uno::Reference<frame::XController>(&rViewShellBase.GetDrawController()),
118 266 : sfx2::sidebar::EnumContext::Context_Default))
119 : {
120 133 : if (pFrameViewArgument != NULL)
121 6 : mpFrameView = pFrameViewArgument;
122 : else
123 127 : mpFrameView = new FrameView(GetDoc());
124 133 : Construct(GetDocSh(), ePageKind);
125 :
126 133 : mpSelectionChangeHandler->Connect();
127 :
128 133 : SetContextName(GetSidebarContextName());
129 :
130 133 : doShow();
131 133 : }
132 :
133 313 : DrawViewShell::~DrawViewShell()
134 : {
135 133 : mpSelectionChangeHandler->Disconnect();
136 :
137 133 : mpAnnotationManager.reset();
138 133 : mpViewOverlayManager.reset();
139 :
140 : OSL_ASSERT (GetViewShell()!=NULL);
141 :
142 133 : if( mxScannerListener.is() )
143 125 : static_cast< ScannerEventListener* >( mxScannerListener.get() )->ParentDestroyed();
144 :
145 : // Remove references to items within Svx3DWin
146 : // (maybe do a listening sometime in Svx3DWin)
147 133 : sal_uInt16 nId = Svx3DChildWindow::GetChildWindowId();
148 133 : SfxChildWindow* pWindow = GetViewFrame() ? GetViewFrame()->GetChildWindow(nId) : NULL;
149 133 : if(pWindow)
150 : {
151 0 : Svx3DWin* p3DWin = static_cast< Svx3DWin* > (pWindow->GetWindow());
152 0 : if(p3DWin)
153 0 : p3DWin->DocumentReload();
154 : }
155 :
156 133 : EndListening (*GetDoc());
157 133 : EndListening (*GetDocSh());
158 :
159 133 : if( SlideShow::IsRunning(*this) )
160 0 : StopSlideShow(false);
161 :
162 133 : DisposeFunctions();
163 :
164 133 : sal_uInt16 aPageCnt = GetDoc()->GetSdPageCount(mePageKind);
165 :
166 304 : for (sal_uInt16 i = 0; i < aPageCnt; i++)
167 : {
168 171 : SdPage* pPage = GetDoc()->GetSdPage(i, mePageKind);
169 :
170 171 : if (pPage == mpActualPage)
171 : {
172 133 : GetDoc()->SetSelected(pPage, true);
173 : }
174 : else
175 : {
176 38 : GetDoc()->SetSelected(pPage, false);
177 : }
178 : }
179 :
180 133 : if ( mpClipEvtLstnr )
181 : {
182 63 : mpClipEvtLstnr->AddRemoveListener( GetActiveWindow(), false );
183 63 : mpClipEvtLstnr->ClearCallbackLink(); // prevent callback if another thread is waiting
184 63 : mpClipEvtLstnr->release();
185 : }
186 :
187 133 : delete mpDrawView;
188 : // Set mpView to NULL so that the destructor of the ViewShell base class
189 : // does not access it.
190 133 : mpView = mpDrawView = NULL;
191 :
192 133 : mpFrameView->Disconnect();
193 133 : delete [] mpSlotArray;
194 :
195 133 : maTabControl.disposeAndClear();
196 180 : }
197 :
198 : /**
199 : * common part of both constructors
200 : */
201 133 : void DrawViewShell::Construct(DrawDocShell* pDocSh, PageKind eInitialPageKind)
202 : {
203 133 : mpActualPage = 0;
204 133 : mbMousePosFreezed = false;
205 133 : mbReadOnly = GetDocSh()->IsReadOnly();
206 133 : mpSlotArray = 0;
207 133 : mpClipEvtLstnr = 0;
208 133 : mbPastePossible = false;
209 133 : mbIsLayerModeActive = false;
210 :
211 133 : mpFrameView->Connect();
212 :
213 : OSL_ASSERT (GetViewShell()!=NULL);
214 :
215 : /* array for slot-/image mapping:
216 : even entry: main-/toolbox slot
217 : odd entry: mapped slot
218 : Attention: adjust GetIdBySubId() !!!
219 : Do not change order (especial zoom) !!! */
220 133 : mpSlotArray = new sal_uInt16[ SLOTARRAY_COUNT ];
221 133 : mpSlotArray[ 0 ] = SID_OBJECT_CHOOSE_MODE;
222 133 : mpSlotArray[ 1 ] = SID_OBJECT_ROTATE;
223 133 : mpSlotArray[ 2 ] = SID_OBJECT_ALIGN;
224 133 : mpSlotArray[ 3 ] = SID_OBJECT_ALIGN_LEFT;
225 133 : mpSlotArray[ 4 ] = SID_ZOOM_TOOLBOX;
226 133 : mpSlotArray[ 5 ] = SID_ZOOM_TOOLBOX;
227 133 : mpSlotArray[ 6 ] = SID_DRAWTBX_TEXT;
228 133 : mpSlotArray[ 7 ] = SID_ATTR_CHAR;
229 133 : mpSlotArray[ 8 ] = SID_DRAWTBX_RECTANGLES;
230 133 : mpSlotArray[ 9 ] = SID_DRAW_RECT;
231 133 : mpSlotArray[ 10 ] = SID_DRAWTBX_ELLIPSES;
232 133 : mpSlotArray[ 11 ] = SID_DRAW_ELLIPSE;
233 133 : mpSlotArray[ 12 ] = SID_DRAWTBX_LINES;
234 133 : mpSlotArray[ 13 ] = SID_DRAW_FREELINE_NOFILL;
235 133 : mpSlotArray[ 14 ] = SID_DRAWTBX_3D_OBJECTS;
236 133 : mpSlotArray[ 15 ] = SID_3D_CUBE;
237 133 : mpSlotArray[ 16 ] = SID_DRAWTBX_INSERT;
238 133 : mpSlotArray[ 17 ] = SID_INSERT_DIAGRAM;
239 133 : mpSlotArray[ 18 ] = SID_POSITION;
240 133 : mpSlotArray[ 19 ] = SID_FRAME_TO_TOP;
241 133 : mpSlotArray[ 20 ] = SID_DRAWTBX_CONNECTORS;
242 133 : mpSlotArray[ 21 ] = SID_TOOL_CONNECTOR;
243 133 : mpSlotArray[ 22 ] = SID_DRAWTBX_ARROWS;
244 133 : mpSlotArray[ 23 ] = SID_LINE_ARROW_END;
245 :
246 133 : SetPool( &GetDoc()->GetPool() );
247 :
248 133 : GetDoc()->CreateFirstPages();
249 :
250 133 : mpDrawView = new DrawView(pDocSh, GetActiveWindow(), this);
251 133 : mpView = mpDrawView; // Pointer of base class ViewShell
252 133 : mpDrawView->SetSwapAsynchron(true); // Asynchronous load of graphics
253 :
254 : // We do not read the page kind from the frame view anymore so we have
255 : // to set it in order to resync frame view and this view.
256 133 : mpFrameView->SetPageKind(eInitialPageKind);
257 133 : mePageKind = eInitialPageKind;
258 133 : meEditMode = EM_PAGE;
259 133 : DocumentType eDocType = GetDoc()->GetDocumentType(); // RTTI does not work here
260 133 : switch (mePageKind)
261 : {
262 : case PK_STANDARD:
263 129 : meShellType = ST_IMPRESS;
264 129 : break;
265 :
266 : case PK_NOTES:
267 2 : meShellType = ST_NOTES;
268 2 : break;
269 :
270 : case PK_HANDOUT:
271 2 : meShellType = ST_HANDOUT;
272 2 : break;
273 : }
274 :
275 133 : Size aPageSize( GetDoc()->GetSdPage(0, mePageKind)->GetSize() );
276 133 : Point aPageOrg( aPageSize.Width(), aPageSize.Height() / 2);
277 133 : Size aSize(aPageSize.Width() * 3, aPageSize.Height() * 2);
278 133 : InitWindows(aPageOrg, aSize, Point(-1, -1));
279 :
280 133 : Point aVisAreaPos;
281 :
282 133 : if ( pDocSh->GetCreateMode() == SfxObjectCreateMode::EMBEDDED )
283 : {
284 0 : aVisAreaPos = pDocSh->GetVisArea(ASPECT_CONTENT).TopLeft();
285 : }
286 :
287 133 : mpDrawView->SetWorkArea(Rectangle(Point() - aVisAreaPos - aPageOrg, aSize));
288 :
289 : // objects can not grow bigger than ViewSize
290 133 : GetDoc()->SetMaxObjSize(aSize);
291 :
292 : // Split-Handler for TabControls
293 133 : maTabControl->SetSplitHdl( LINK( this, DrawViewShell, TabSplitHdl ) );
294 :
295 : /* In order to set the correct EditMode of the FrameView, we select another
296 : one (small trick). */
297 133 : if (mpFrameView->GetViewShEditMode(mePageKind) == EM_PAGE)
298 : {
299 130 : meEditMode = EM_MASTERPAGE;
300 : }
301 : else
302 : {
303 3 : meEditMode = EM_PAGE;
304 : }
305 :
306 : // Use configuration of FrameView
307 133 : ReadFrameViewData(mpFrameView);
308 :
309 133 : if( eDocType == DOCUMENT_TYPE_DRAW )
310 : {
311 86 : SetHelpId( SD_IF_SDGRAPHICVIEWSHELL );
312 86 : GetActiveWindow()->SetHelpId( HID_SDGRAPHICVIEWSHELL );
313 86 : GetActiveWindow()->SetUniqueId( HID_SDGRAPHICVIEWSHELL );
314 : }
315 : else
316 : {
317 47 : if (mePageKind == PK_NOTES)
318 : {
319 2 : SetHelpId( SID_NOTESMODE );
320 2 : GetActiveWindow()->SetHelpId( CMD_SID_NOTESMODE );
321 2 : GetActiveWindow()->SetUniqueId( CMD_SID_NOTESMODE );
322 :
323 : // AutoLayouts have to be created
324 2 : GetDoc()->StopWorkStartupDelay();
325 : }
326 45 : else if (mePageKind == PK_HANDOUT)
327 : {
328 2 : SetHelpId( SID_HANDOUTMODE );
329 2 : GetActiveWindow()->SetHelpId( CMD_SID_HANDOUTMODE );
330 2 : GetActiveWindow()->SetUniqueId( CMD_SID_HANDOUTMODE );
331 :
332 : // AutoLayouts have to be created
333 2 : GetDoc()->StopWorkStartupDelay();
334 : }
335 : else
336 : {
337 43 : SetHelpId( SD_IF_SDDRAWVIEWSHELL );
338 43 : GetActiveWindow()->SetHelpId( HID_SDDRAWVIEWSHELL );
339 43 : GetActiveWindow()->SetUniqueId( HID_SDDRAWVIEWSHELL );
340 : }
341 : }
342 :
343 : // start selection function
344 133 : SfxRequest aReq(SID_OBJECT_SELECT, SfxCallMode::SLOT, GetDoc()->GetItemPool());
345 133 : FuPermanent(aReq);
346 133 : mpDrawView->SetFrameDragSingles(true);
347 :
348 133 : if (pDocSh->GetCreateMode() == SfxObjectCreateMode::EMBEDDED)
349 : {
350 0 : mbZoomOnPage = false;
351 : }
352 : else
353 : {
354 133 : mbZoomOnPage = true;
355 : }
356 :
357 133 : mbIsRulerDrag = false;
358 :
359 266 : OUString aName( "DrawViewShell" );
360 133 : SetName (aName);
361 :
362 133 : mnLockCount = 0UL;
363 :
364 266 : uno::Reference< uno::XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
365 :
366 : try
367 : {
368 133 : mxScannerManager = scanner::ScannerManager::create( xContext );
369 :
370 375 : mxScannerListener = uno::Reference< lang::XEventListener >(
371 125 : static_cast< ::cppu::OWeakObject* >( new ScannerEventListener( this ) ),
372 125 : uno::UNO_QUERY );
373 : }
374 8 : catch (Exception& exception)
375 : {
376 : // Eat the exception and log it
377 : // We can still continue if scanner manager is not available.
378 : SAL_WARN("sd", "Scanner manager exception: " << exception.Message);
379 : }
380 :
381 133 : mpAnnotationManager.reset( new AnnotationManager( GetViewShellBase() ) );
382 266 : mpViewOverlayManager.reset( new ViewOverlayManager( GetViewShellBase() ) );
383 133 : }
384 :
385 133 : void DrawViewShell::Init (bool bIsMainViewShell)
386 : {
387 133 : ViewShell::Init(bIsMainViewShell);
388 :
389 133 : StartListening (*GetDocSh());
390 133 : }
391 :
392 133 : void DrawViewShell::Shutdown()
393 : {
394 133 : ViewShell::Shutdown();
395 :
396 133 : if(SlideShow::IsRunning( GetViewShellBase() ) )
397 : {
398 : // Turn off effects.
399 0 : GetDrawView()->SetAnimationMode(SDR_ANIMATION_DISABLE);
400 : }
401 133 : }
402 :
403 133 : css::uno::Reference<css::drawing::XDrawSubController> DrawViewShell::CreateSubController()
404 : {
405 133 : css::uno::Reference<css::drawing::XDrawSubController> xSubController;
406 :
407 133 : if (IsMainViewShell())
408 : {
409 : // Create uno sub controller for the main view shell.
410 266 : xSubController = css::uno::Reference<css::drawing::XDrawSubController>(
411 : new SdUnoDrawView (
412 : *this,
413 266 : *GetView()));
414 : }
415 :
416 133 : return xSubController;
417 : }
418 :
419 0 : bool DrawViewShell::RelocateToParentWindow (vcl::Window* pParentWindow)
420 : {
421 : // DrawViewShells can not be relocated to a new parent window at the
422 : // moment, so return <FALSE/> except when the given parent window is the
423 : // parent window that is already in use.
424 0 : return pParentWindow==GetParentWindow();
425 : }
426 :
427 : /**
428 : * check if we have to draw a polyline
429 : */
430 :
431 : /*
432 : Polylines are represented by makros as a sequence of:
433 : MoveTo (x, y)
434 : LineTo (x, y) [or BezierTo (x, y)]
435 : LineTo (x, y)
436 : :
437 : There is no end command for polylines. Therefore, we have to test all
438 : commands in the requests for LineTo (BezierTo) and we have to gather
439 : the point-parameter. The first not-LineTo leads to the creation of the
440 : polyline from the gathered points.
441 : */
442 :
443 937 : void DrawViewShell::CheckLineTo(SfxRequest& rReq)
444 : {
445 : (void)rReq;
446 : #ifdef DBG_UTIL
447 : if(rReq.IsAPI())
448 : {
449 : if(SID_LINETO == rReq.GetSlot() || SID_BEZIERTO == rReq.GetSlot() || SID_MOVETO == rReq.GetSlot() )
450 : {
451 : OSL_FAIL("DrawViewShell::CheckLineTo: slots SID_LINETO, SID_BEZIERTO, SID_MOVETO no longer supported.");
452 : }
453 : }
454 : #endif
455 :
456 937 : rReq.Ignore ();
457 937 : }
458 :
459 : /**
460 : * Change page parameter if SID_PAGESIZE or SID_PAGEMARGIN
461 : */
462 0 : void DrawViewShell::SetupPage (Size &rSize,
463 : long nLeft,
464 : long nRight,
465 : long nUpper,
466 : long nLower,
467 : bool bSize,
468 : bool bMargin,
469 : bool bScaleAll)
470 : {
471 0 : sal_uInt16 nPageCnt = GetDoc()->GetMasterSdPageCount(mePageKind);
472 : sal_uInt16 i;
473 :
474 0 : for (i = 0; i < nPageCnt; i++)
475 : {
476 : // first, handle all master pages
477 0 : SdPage *pPage = GetDoc()->GetMasterSdPage(i, mePageKind);
478 :
479 0 : if( pPage )
480 : {
481 0 : if( bSize )
482 : {
483 0 : Rectangle aBorderRect(nLeft, nUpper, nRight, nLower);
484 0 : pPage->ScaleObjects(rSize, aBorderRect, bScaleAll);
485 0 : pPage->SetSize(rSize);
486 :
487 : }
488 0 : if( bMargin )
489 : {
490 0 : pPage->SetLftBorder(nLeft);
491 0 : pPage->SetRgtBorder(nRight);
492 0 : pPage->SetUppBorder(nUpper);
493 0 : pPage->SetLwrBorder(nLower);
494 : }
495 :
496 0 : if ( mePageKind == PK_STANDARD )
497 : {
498 0 : GetDoc()->GetMasterSdPage(i, PK_NOTES)->CreateTitleAndLayout();
499 : }
500 :
501 0 : pPage->CreateTitleAndLayout();
502 : }
503 : }
504 :
505 0 : nPageCnt = GetDoc()->GetSdPageCount(mePageKind);
506 :
507 0 : for (i = 0; i < nPageCnt; i++)
508 : {
509 : // then, handle all pages
510 0 : SdPage *pPage = GetDoc()->GetSdPage(i, mePageKind);
511 :
512 0 : if( pPage )
513 : {
514 0 : if( bSize )
515 : {
516 0 : Rectangle aBorderRect(nLeft, nUpper, nRight, nLower);
517 0 : pPage->ScaleObjects(rSize, aBorderRect, bScaleAll);
518 0 : pPage->SetSize(rSize);
519 : }
520 0 : if( bMargin )
521 : {
522 0 : pPage->SetLftBorder(nLeft);
523 0 : pPage->SetRgtBorder(nRight);
524 0 : pPage->SetUppBorder(nUpper);
525 0 : pPage->SetLwrBorder(nLower);
526 : }
527 :
528 0 : if ( mePageKind == PK_STANDARD )
529 : {
530 0 : SdPage* pNotesPage = GetDoc()->GetSdPage(i, PK_NOTES);
531 0 : pNotesPage->SetAutoLayout( pNotesPage->GetAutoLayout() );
532 : }
533 :
534 0 : pPage->SetAutoLayout( pPage->GetAutoLayout() );
535 : }
536 : }
537 :
538 0 : if ( mePageKind == PK_STANDARD )
539 : {
540 0 : SdPage* pHandoutPage = GetDoc()->GetSdPage(0, PK_HANDOUT);
541 0 : pHandoutPage->CreateTitleAndLayout(true);
542 : }
543 :
544 0 : long nWidth = mpActualPage->GetSize().Width();
545 0 : long nHeight = mpActualPage->GetSize().Height();
546 :
547 0 : Point aPageOrg(nWidth, nHeight / 2);
548 0 : Size aSize( nWidth * 3, nHeight * 2);
549 :
550 0 : InitWindows(aPageOrg, aSize, Point(-1, -1), true);
551 :
552 0 : Point aVisAreaPos;
553 :
554 0 : if ( GetDocSh()->GetCreateMode() == SfxObjectCreateMode::EMBEDDED )
555 : {
556 0 : aVisAreaPos = GetDocSh()->GetVisArea(ASPECT_CONTENT).TopLeft();
557 : }
558 :
559 0 : GetView()->SetWorkArea(Rectangle(Point() - aVisAreaPos - aPageOrg, aSize));
560 :
561 0 : UpdateScrollBars();
562 :
563 0 : Point aNewOrigin(mpActualPage->GetLftBorder(), mpActualPage->GetUppBorder());
564 0 : GetView()->GetSdrPageView()->SetPageOrigin(aNewOrigin);
565 :
566 0 : GetViewFrame()->GetBindings().Invalidate(SID_RULER_NULL_OFFSET);
567 :
568 : // zoom onto (new) page size
569 : GetViewFrame()->GetDispatcher()->Execute(SID_SIZE_PAGE,
570 0 : SfxCallMode::ASYNCHRON | SfxCallMode::RECORD);
571 0 : }
572 :
573 442 : void DrawViewShell::GetStatusBarState(SfxItemSet& rSet)
574 : {
575 : /* Zoom-Item
576 : Here we should propagate the corresponding value (Optimal ?, page width
577 : or page) with the help of the ZoomItems !!! */
578 442 : if( SfxItemState::DEFAULT == rSet.GetItemState( SID_ATTR_ZOOM ) )
579 : {
580 124 : if (GetDocSh()->IsUIActive() || (SlideShow::IsRunning(GetViewShellBase())) )
581 : {
582 0 : rSet.DisableItem( SID_ATTR_ZOOM );
583 : }
584 : else
585 : {
586 124 : boost::scoped_ptr<SvxZoomItem> pZoomItem;
587 124 : sal_uInt16 nZoom = (sal_uInt16) GetActiveWindow()->GetZoom();
588 :
589 124 : if( mbZoomOnPage )
590 124 : pZoomItem.reset(new SvxZoomItem( SvxZoomType::WHOLEPAGE, nZoom ));
591 : else
592 0 : pZoomItem.reset(new SvxZoomItem( SvxZoomType::PERCENT, nZoom ));
593 :
594 : // constrain area
595 124 : SvxZoomEnableFlags nZoomValues = SvxZoomEnableFlags::ALL;
596 124 : SdrPageView* pPageView = mpDrawView->GetSdrPageView();
597 :
598 124 : if( ( pPageView && pPageView->GetObjList()->GetObjCount() == 0 ) )
599 : // || ( mpDrawView->GetMarkedObjectList().GetMarkCount() == 0 ) )
600 : {
601 83 : nZoomValues &= ~SvxZoomEnableFlags::OPTIMAL;
602 : }
603 :
604 124 : pZoomItem->SetValueSet( nZoomValues );
605 124 : rSet.Put( *pZoomItem );
606 : }
607 : }
608 442 : if( SfxItemState::DEFAULT == rSet.GetItemState( SID_ATTR_ZOOMSLIDER ) )
609 : {
610 124 : rtl::Reference< sd::SlideShow > xSlideshow( SlideShow::GetSlideShow( GetDoc() ) );
611 124 : if (GetDocSh()->IsUIActive() || (xSlideshow.is() && xSlideshow->isRunning()) || !GetActiveWindow() )
612 : {
613 0 : rSet.DisableItem( SID_ATTR_ZOOMSLIDER );
614 : }
615 : else
616 : {
617 124 : sd::Window * pActiveWindow = GetActiveWindow();
618 124 : SvxZoomSliderItem aZoomItem( (sal_uInt16) pActiveWindow->GetZoom(), (sal_uInt16)pActiveWindow->GetMinZoom(), (sal_uInt16)pActiveWindow->GetMaxZoom() ) ;
619 :
620 124 : SdrPageView* pPageView = mpDrawView->GetSdrPageView();
621 124 : if( pPageView )
622 : {
623 124 : Point aPagePos(0, 0);
624 124 : Size aPageSize = pPageView->GetPage()->GetSize();
625 :
626 124 : aPagePos.X() += aPageSize.Width() / 2;
627 124 : aPageSize.Width() = (long) (aPageSize.Width() * 1.03);
628 :
629 124 : aPagePos.Y() += aPageSize.Height() / 2;
630 124 : aPageSize.Height() = (long) (aPageSize.Height() * 1.03);
631 124 : aPagePos.Y() -= aPageSize.Height() / 2;
632 :
633 124 : aPagePos.X() -= aPageSize.Width() / 2;
634 :
635 124 : Rectangle aFullPageZoomRect( aPagePos, aPageSize );
636 124 : aZoomItem.AddSnappingPoint( pActiveWindow->GetZoomForRect( aFullPageZoomRect ) );
637 : }
638 124 : aZoomItem.AddSnappingPoint(100);
639 124 : rSet.Put( aZoomItem );
640 124 : }
641 : }
642 :
643 442 : SdrPageView* pPageView = mpDrawView->GetSdrPageView();
644 442 : if (pPageView)
645 : {
646 442 : Point aPos = GetActiveWindow()->PixelToLogic(maMousePos);
647 442 : pPageView->LogicToPagePos(aPos);
648 442 : Fraction aUIScale(GetDoc()->GetUIScale());
649 442 : aPos.X() = Fraction(aPos.X()) / aUIScale;
650 442 : aPos.Y() = Fraction(aPos.Y()) / aUIScale;
651 :
652 : // position- and size items
653 442 : if ( mpDrawView->IsAction() )
654 : {
655 2 : Rectangle aRect;
656 2 : mpDrawView->TakeActionRect( aRect );
657 :
658 2 : if ( aRect.IsEmpty() )
659 0 : rSet.Put( SfxPointItem(SID_ATTR_POSITION, aPos) );
660 : else
661 : {
662 2 : pPageView->LogicToPagePos(aRect);
663 2 : aPos = aRect.TopLeft();
664 2 : aPos.X() = Fraction(aPos.X()) / aUIScale;
665 2 : aPos.Y() = Fraction(aPos.Y()) / aUIScale;
666 2 : rSet.Put( SfxPointItem( SID_ATTR_POSITION, aPos) );
667 2 : Size aSize( aRect.Right() - aRect.Left(), aRect.Bottom() - aRect.Top() );
668 2 : aSize.Height() = Fraction(aSize.Height()) / aUIScale;
669 2 : aSize.Width() = Fraction(aSize.Width()) / aUIScale;
670 2 : rSet.Put( SvxSizeItem( SID_ATTR_SIZE, aSize) );
671 : }
672 : }
673 : else
674 : {
675 440 : if ( mpDrawView->AreObjectsMarked() )
676 : {
677 0 : Rectangle aRect = mpDrawView->GetAllMarkedRect();
678 0 : pPageView->LogicToPagePos(aRect);
679 :
680 : // Show the position of the selected shape(s)
681 0 : Point aShapePosition (aRect.TopLeft());
682 0 : aShapePosition.X() = Fraction(aShapePosition.X()) / aUIScale;
683 0 : aShapePosition.Y() = Fraction(aShapePosition.Y()) / aUIScale;
684 0 : rSet.Put (SfxPointItem(SID_ATTR_POSITION, aShapePosition));
685 :
686 0 : Size aSize( aRect.Right() - aRect.Left(), aRect.Bottom() - aRect.Top() );
687 0 : aSize.Height() = Fraction(aSize.Height()) / aUIScale;
688 0 : aSize.Width() = Fraction(aSize.Width()) / aUIScale;
689 0 : rSet.Put( SvxSizeItem( SID_ATTR_SIZE, aSize) );
690 : }
691 : else
692 : {
693 440 : rSet.Put( SfxPointItem(SID_ATTR_POSITION, aPos) );
694 440 : rSet.Put( SvxSizeItem( SID_ATTR_SIZE, Size( 0, 0 ) ) );
695 : }
696 442 : }
697 : }
698 :
699 : // Display of current page and layer.
700 442 : if( SfxItemState::DEFAULT == rSet.GetItemState( SID_STATUS_PAGE ) )
701 : {
702 125 : sal_Int32 nPageCount = sal_Int32(GetDoc()->GetSdPageCount(mePageKind));
703 125 : sal_Int32 nActivePageCount = sal_Int32(GetDoc()->GetActiveSdPageCount());
704 : // Always show the slide/page number.
705 125 : OUString aOUString = (nPageCount == nActivePageCount) ? SD_RESSTR(STR_SD_PAGE_COUNT) : SD_RESSTR(STR_SD_PAGE_COUNT_CUSTOM);
706 :
707 125 : aOUString = aOUString.replaceFirst("%1", OUString::number(maTabControl->GetCurPageId()));
708 125 : aOUString = aOUString.replaceFirst("%2", OUString::number(nPageCount));
709 125 : if(nPageCount != nActivePageCount)
710 0 : aOUString = aOUString.replaceFirst("%3", OUString::number(nActivePageCount));
711 :
712 : // If in layer mode additionally show the layer that contains all
713 : // selected shapes of the page. If the shapes are distributed on
714 : // more than one layer, no layer name is shown.
715 125 : if (IsLayerModeActive())
716 : {
717 57 : SdrLayerAdmin& rLayerAdmin = GetDoc()->GetLayerAdmin();
718 57 : SdrLayerID nLayer = 0, nOldLayer = 0;
719 57 : SdrObject* pObj = NULL;
720 57 : const SdrMarkList& rMarkList = mpDrawView->GetMarkedObjectList();
721 57 : const size_t nMarkCount = rMarkList.GetMarkCount();
722 57 : bool bOneLayer = true;
723 :
724 : // Use the first ten selected shapes as a (hopefully
725 : // representative) sample of all shapes of the current page.
726 : // Detect whether they belong to the same layer.
727 57 : for( size_t j = 0; j < nMarkCount && bOneLayer && j < 10; ++j )
728 : {
729 0 : pObj = rMarkList.GetMark( j )->GetMarkedSdrObj();
730 0 : if( pObj )
731 : {
732 0 : nLayer = pObj->GetLayer();
733 :
734 0 : if( j != 0 && nLayer != nOldLayer )
735 0 : bOneLayer = false;
736 :
737 0 : nOldLayer = nLayer;
738 : }
739 : }
740 :
741 : // Append the layer name to the current page number.
742 57 : if( bOneLayer && nMarkCount )
743 : {
744 0 : SdrLayer* pLayer = rLayerAdmin.GetLayerPerID( nLayer );
745 0 : if( pLayer )
746 : {
747 0 : aOUString += " (" ;
748 0 : aOUString += pLayer->GetName();
749 0 : aOUString += ")";
750 : }
751 : }
752 : }
753 :
754 125 : rSet.Put (SfxStringItem (SID_STATUS_PAGE, aOUString));
755 : }
756 : // Layout
757 442 : if( SfxItemState::DEFAULT == rSet.GetItemState( SID_STATUS_LAYOUT ) )
758 : {
759 125 : OUString aString = mpActualPage->GetLayoutName();
760 125 : sal_Int32 nPos = aString.indexOf(SD_LT_SEPARATOR);
761 125 : if (nPos != -1)
762 125 : aString = aString.copy(0, nPos);
763 125 : rSet.Put( SfxStringItem( SID_STATUS_LAYOUT, aString ) );
764 : }
765 442 : }
766 :
767 43101 : void DrawViewShell::Notify (SfxBroadcaster&, const SfxHint& rHint)
768 : {
769 43101 : const SfxSimpleHint* pSimple = dynamic_cast< const SfxSimpleHint* >(&rHint);
770 43101 : if (pSimple!=NULL && pSimple->GetId()==SFX_HINT_MODECHANGED)
771 : {
772 : // Change to selection when turning on read-only mode.
773 2 : if(GetDocSh()->IsReadOnly() && dynamic_cast< FuSelection* >( GetCurrentFunction().get() ) )
774 : {
775 0 : SfxRequest aReq(SID_OBJECT_SELECT, SfxCallMode::SLOT, GetDoc()->GetItemPool());
776 0 : FuPermanent(aReq);
777 : }
778 :
779 : // Turn on design mode when document is not read-only.
780 2 : if (GetDocSh()->IsReadOnly() != mbReadOnly )
781 : {
782 0 : mbReadOnly = GetDocSh()->IsReadOnly();
783 :
784 0 : SfxBoolItem aItem( SID_FM_DESIGN_MODE, !mbReadOnly );
785 : GetViewFrame()->GetDispatcher()->Execute( SID_FM_DESIGN_MODE,
786 0 : SfxCallMode::ASYNCHRON | SfxCallMode::RECORD, &aItem, 0L );
787 : }
788 : }
789 :
790 43101 : }
791 :
792 0 : void DrawViewShell::ExecuteAnnotation (SfxRequest& rRequest)
793 : {
794 0 : if( mpAnnotationManager.get() )
795 0 : mpAnnotationManager->ExecuteAnnotation( rRequest );
796 0 : }
797 :
798 0 : void DrawViewShell::GetAnnotationState (SfxItemSet& rItemSet )
799 : {
800 0 : if( mpAnnotationManager.get() )
801 0 : mpAnnotationManager->GetAnnotationState( rItemSet );
802 0 : }
803 :
804 923 : ::rtl::OUString DrawViewShell::GetSidebarContextName() const
805 : {
806 923 : svx::sidebar::SelectionAnalyzer::ViewType eViewType (svx::sidebar::SelectionAnalyzer::VT_Standard);
807 923 : switch (mePageKind)
808 : {
809 : case PK_HANDOUT:
810 13 : eViewType = svx::sidebar::SelectionAnalyzer::VT_Handout;
811 13 : break;
812 : case PK_NOTES:
813 16 : eViewType = svx::sidebar::SelectionAnalyzer::VT_Notes;
814 16 : break;
815 : case PK_STANDARD:
816 894 : if (meEditMode == EM_MASTERPAGE)
817 8 : eViewType = svx::sidebar::SelectionAnalyzer::VT_Master;
818 : else
819 886 : eViewType = svx::sidebar::SelectionAnalyzer::VT_Standard;
820 894 : break;
821 : }
822 : return EnumContext::GetContextName(
823 : svx::sidebar::SelectionAnalyzer::GetContextForSelection_SD(
824 923 : mpDrawView->GetMarkedObjectList(),
825 923 : eViewType));
826 : }
827 :
828 66 : } // end of namespace sd
829 :
830 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|