1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "DrawViewShell.hxx"
21 #include "ViewShellImplementation.hxx"
23 #include "DrawController.hxx"
24 #include <com/sun/star/embed/EmbedStates.hpp>
26 #include "comphelper/anytostring.hxx"
27 #include "comphelper/scopeguard.hxx"
28 #include "cppuhelper/exc_hlp.hxx"
29 #include "rtl/ref.hxx"
31 #include <svx/svxids.hrc>
32 #include <svx/svdpagv.hxx>
33 #include <sfx2/viewfrm.hxx>
34 #include <sfx2/bindings.hxx>
35 #include <svx/svdoole2.hxx>
36 #include <sfx2/dispatch.hxx>
37 #include <vcl/scrbar.hxx>
38 #include <svx/svdograf.hxx>
39 #include <svx/svdopage.hxx>
40 #include <vcl/msgbox.hxx>
41 #include <sot/storage.hxx>
42 #include <svx/fmshell.hxx>
43 #include <svx/globl3d.hxx>
44 #include <svx/fmglob.hxx>
45 #include <editeng/outliner.hxx>
46 #include <svx/dialogs.hrc>
48 #include "view/viewoverlaymanager.hxx"
52 #include "res_bmp.hrc"
53 #include "strings.hrc"
58 #include "sdresid.hxx"
61 #include "FrameView.hxx"
62 #include "stlpool.hxx"
64 #include "drawview.hxx"
65 #include "drawdoc.hxx"
66 #include "DrawDocShell.hxx"
69 #include "slideshow.hxx"
70 #include "optsitem.hxx"
71 #include "fusearch.hxx"
72 #include "Outliner.hxx"
73 #include "AnimationChildWindow.hxx"
74 #include "SdUnoDrawView.hxx"
75 #include "ToolBarManager.hxx"
76 #include "FormShellManager.hxx"
77 #include "ViewShellBase.hxx"
78 #include "LayerTabBar.hxx"
79 #include "ViewShellManager.hxx"
80 #include "ViewShellHint.hxx"
82 #include <sfx2/request.hxx>
83 #include <boost/bind.hpp>
85 using namespace com::sun::star
;
89 void DrawViewShell::Activate(bool bIsMDIActivate
)
91 ViewShell::Activate(bIsMDIActivate
);
93 // When the mode is switched to normal the main view shell grabs focus.
94 // This is done for getting cut/copy/paste commands on slides in the left
95 // pane (slide sorter view shell) to work properly.
96 SfxShell
* pTopViewShell
= this->GetViewShellBase().GetViewShellManager()->GetTopViewShell();
97 if (pTopViewShell
&& pTopViewShell
== this)
99 this->GetActiveWindow()->GrabFocus();
103 void DrawViewShell::UIActivating( SfxInPlaceClient
* pCli
)
105 ViewShell::UIActivating(pCli
);
107 // Disable own controls
108 maTabControl
->Disable();
109 if (GetLayerTabControl() != NULL
)
110 GetLayerTabControl()->Disable();
113 void DrawViewShell::UIDeactivated( SfxInPlaceClient
* pCli
)
115 // Enable own controls
116 maTabControl
->Enable();
117 if (GetLayerTabControl() != NULL
)
118 GetLayerTabControl()->Enable();
120 ViewShell::UIDeactivated(pCli
);
123 void DrawViewShell::Deactivate(bool bIsMDIActivate
)
125 // Temporarily disable context broadcasting while the Deactivate()
126 // call is forwarded to our base class.
127 const bool bIsContextBroadcasterEnabled (SfxShell::SetContextBroadcasterEnabled(false));
129 ViewShell::Deactivate(bIsMDIActivate
);
131 SfxShell::SetContextBroadcasterEnabled(bIsContextBroadcasterEnabled
);
139 void Lock(bool bLock
);
140 SfxViewFrame
*mpFrame
;
142 LockUI(SfxViewFrame
*pFrame
) : mpFrame(pFrame
) { Lock(true); }
143 ~LockUI() { Lock(false); }
147 void LockUI::Lock(bool bLock
)
151 mpFrame
->Enable( !bLock
);
156 * Called, if state of selection of view is changed
159 void DrawViewShell::SelectionHasChanged()
163 //Update3DWindow(); // 3D-Controller
164 SfxBoolItem
aItem( SID_3D_STATE
, true );
165 GetViewFrame()->GetDispatcher()->Execute(
166 SID_3D_STATE
, SfxCallMode::ASYNCHRON
| SfxCallMode::RECORD
, &aItem
, 0L );
168 SdrOle2Obj
* pOleObj
= NULL
;
170 if ( mpDrawView
->AreObjectsMarked() )
172 const SdrMarkList
& rMarkList
= mpDrawView
->GetMarkedObjectList();
174 if (rMarkList
.GetMarkCount() == 1)
176 SdrMark
* pMark
= rMarkList
.GetMark(0);
177 SdrObject
* pObj
= pMark
->GetMarkedSdrObj();
179 sal_uInt32 nInv
= pObj
->GetObjInventor();
180 sal_uInt16 nSdrObjKind
= pObj
->GetObjIdentifier();
182 if (nInv
== SdrInventor
&& nSdrObjKind
== OBJ_OLE2
)
184 pOleObj
= static_cast<SdrOle2Obj
*>(pObj
);
185 UpdateIMapDlg( pObj
);
187 else if (nSdrObjKind
== OBJ_GRAF
)
188 UpdateIMapDlg( pObj
);
192 ViewShellBase
& rBase
= GetViewShellBase();
193 rBase
.SetVerbs( uno::Sequence
< embed::VerbDescriptor
>() );
197 Client
* pIPClient
= static_cast<Client
*>(rBase
.GetIPClient());
198 if ( pIPClient
&& pIPClient
->IsObjectInPlaceActive() )
200 // as appropriate take ole-objects into account and deactivate
202 // this means we recently deselected an inplace active ole object so
203 // we need to deselect it now
206 //#i47279# disable frame until after object has completed unload
207 LockUI
aUILock(GetViewFrame());
208 pIPClient
->DeactivateObject();
209 //HMHmpDrView->ShowMarkHdl();
213 uno::Reference
< embed::XEmbeddedObject
> xObj
= pOleObj
->GetObjRef();
216 rBase
.SetVerbs( xObj
->getSupportedVerbs() );
220 rBase
.SetVerbs( uno::Sequence
< embed::VerbDescriptor
>() );
228 uno::Reference
< embed::XEmbeddedObject
> xObj
= pOleObj
->GetObjRef();
231 rBase
.SetVerbs( xObj
->getSupportedVerbs() );
235 rBase
.SetVerbs( uno::Sequence
< embed::VerbDescriptor
>() );
240 rBase
.SetVerbs( uno::Sequence
< embed::VerbDescriptor
>() );
244 catch( ::com::sun::star::uno::Exception
& )
247 OString(OString("sd::DrawViewShell::SelectionHasChanged(), "
248 "exception caught: ") +
250 comphelper::anyToString( cppu::getCaughtException() ),
251 RTL_TEXTENCODING_UTF8
)).getStr() );
254 if( HasCurrentFunction() )
256 GetCurrentFunction()->SelectionHasChanged();
260 GetViewShellBase().GetToolBarManager()->SelectionHasChanged(*this,*mpDrawView
);
263 // Invalidate for every subshell
264 GetViewShellBase().GetViewShellManager()->InvalidateAllSubShells(this);
266 mpDrawView
->UpdateSelectionClipboard( false );
268 GetViewShellBase().GetDrawController().FireSelectionChangeListener();
274 void DrawViewShell::SetZoom( long nZoom
)
276 // Make sure that the zoom factor will not be recalculated on
277 // following window resizings.
278 mbZoomOnPage
= false;
279 ViewShell::SetZoom( nZoom
);
280 GetViewFrame()->GetBindings().Invalidate( SID_ATTR_ZOOM
);
281 GetViewFrame()->GetBindings().Invalidate( SID_ATTR_ZOOMSLIDER
);
282 mpViewOverlayManager
->onZoomChanged();
286 * Set zoom rectangle for active window
289 void DrawViewShell::SetZoomRect( const Rectangle
& rZoomRect
)
291 ViewShell::SetZoomRect( rZoomRect
);
292 GetViewFrame()->GetBindings().Invalidate( SID_ATTR_ZOOM
);
293 GetViewFrame()->GetBindings().Invalidate( SID_ATTR_ZOOMSLIDER
);
294 mpViewOverlayManager
->onZoomChanged();
298 * PrepareClose, as appropriate end text input, so other viewshells
299 * discover an refreshed text objext.
302 bool DrawViewShell::PrepareClose( bool bUI
)
304 if ( !ViewShell::PrepareClose(bUI
) )
307 if( HasCurrentFunction() )
309 sal_uInt16 nID
= GetCurrentFunction()->GetSlotID();
310 if (nID
== SID_TEXTEDIT
|| nID
== SID_ATTR_CHAR
)
312 mpDrawView
->SdrEndTextEdit();
320 * Set status (enabled/disabled) of menu SfxSlots
323 void DrawViewShell::ChangeEditMode(EditMode eEMode
, bool bIsLayerModeActive
)
325 if (meEditMode
!= eEMode
|| mbIsLayerModeActive
!= bIsLayerModeActive
)
327 ViewShellManager::UpdateLock
aLock (GetViewShellBase().GetViewShellManager());
329 sal_uInt16 nActualPageNum
= 0;
331 GetViewShellBase().GetDrawController().FireChangeEditMode (eEMode
== EM_MASTERPAGE
);
332 GetViewShellBase().GetDrawController().FireChangeLayerMode (bIsLayerModeActive
);
334 if ( mpDrawView
->IsTextEdit() )
336 mpDrawView
->SdrEndTextEdit();
339 LayerTabBar
* pLayerBar
= GetLayerTabControl();
340 if (pLayerBar
!= NULL
)
341 pLayerBar
->EndEditMode();
342 maTabControl
->EndEditMode();
344 if (mePageKind
== PK_HANDOUT
)
346 // at handouts only allow MasterPage
347 eEMode
= EM_MASTERPAGE
;
350 GetViewShellBase().GetDrawController().BroadcastContextChange();
356 // #i87182# only switch activation mode of LayerTabBar when there is one,
357 // else it will not get initialized with the current set of Layers as needed
358 mbIsLayerModeActive
= bIsLayerModeActive
;
361 // Determine whether to show the master view toolbar. The master
362 // page mode has to be active and the shell must not be a handout
364 bool bShowMasterViewToolbar (meEditMode
== EM_MASTERPAGE
365 && GetShellType() != ViewShell::ST_HANDOUT
);
366 bool bShowPresentationToolbar (meEditMode
!= EM_MASTERPAGE
367 && GetShellType() != ViewShell::ST_HANDOUT
368 && GetShellType() != ViewShell::ST_DRAW
);
370 // If the master view toolbar is not shown we hide it before
371 // switching the edit mode.
372 if (::sd::ViewShell::mpImpl
->mbIsInitialized
373 && IsMainViewShell())
375 if ( !bShowMasterViewToolbar
)
376 GetViewShellBase().GetToolBarManager()->ResetToolBars(ToolBarManager::TBG_MASTER_MODE
);
377 if ( !bShowPresentationToolbar
)
378 GetViewShellBase().GetToolBarManager()->ResetToolBars(ToolBarManager::TBG_COMMON_TASK
);
381 if (meEditMode
== EM_PAGE
)
383 /******************************************************************
385 ******************************************************************/
387 maTabControl
->Clear();
390 sal_uInt16 nPageCnt
= GetDoc()->GetSdPageCount(mePageKind
);
392 for (sal_uInt16 i
= 0; i
< nPageCnt
; i
++)
394 pPage
= GetDoc()->GetSdPage(i
, mePageKind
);
395 OUString aPageName
= pPage
->GetName();
396 maTabControl
->InsertPage(i
+ 1, aPageName
);
398 if ( pPage
->IsSelected() && nActualPageNum
== 0 )
404 maTabControl
->SetCurPageId(nActualPageNum
+ 1);
406 SwitchPage(nActualPageNum
);
410 /******************************************************************
412 ******************************************************************/
413 GetViewFrame()->SetChildWindow(
414 AnimationChildWindow::GetChildWindowId(), false );
418 // as long as there is no mpActualPage, take first
419 mpActualPage
= GetDoc()->GetSdPage(0, mePageKind
);
422 maTabControl
->Clear();
423 sal_uInt16 nActualMasterPageNum
= 0;
424 sal_uInt16 nMasterPageCnt
= GetDoc()->GetMasterSdPageCount(mePageKind
);
426 for (sal_uInt16 i
= 0; i
< nMasterPageCnt
; i
++)
428 SdPage
* pMaster
= GetDoc()->GetMasterSdPage(i
, mePageKind
);
429 OUString aLayoutName
= pMaster
->GetLayoutName();
430 sal_Int32 nPos
= aLayoutName
.indexOf(SD_LT_SEPARATOR
);
432 aLayoutName
= aLayoutName
.copy(0, nPos
);
434 maTabControl
->InsertPage(i
+ 1, aLayoutName
);
436 if (&(mpActualPage
->TRG_GetMasterPage()) == pMaster
)
438 nActualMasterPageNum
= i
;
442 maTabControl
->SetCurPageId(nActualMasterPageNum
+ 1);
443 SwitchPage(nActualMasterPageNum
);
446 // If the master view toolbar is to be shown we turn it on after the
447 // edit mode has been changed.
448 if (::sd::ViewShell::mpImpl
->mbIsInitialized
449 && IsMainViewShell())
451 if (bShowMasterViewToolbar
)
452 GetViewShellBase().GetToolBarManager()->SetToolBar(
453 ToolBarManager::TBG_MASTER_MODE
,
454 ToolBarManager::msMasterViewToolBar
);
455 if (bShowPresentationToolbar
)
456 GetViewShellBase().GetToolBarManager()->SetToolBar(
457 ToolBarManager::TBG_COMMON_TASK
,
458 ToolBarManager::msCommonTaskToolBar
);
461 if ( ! mbIsLayerModeActive
)
463 maTabControl
->Show();
464 // Set the tab control only for draw pages. For master page
465 // this has been done already above.
466 if (meEditMode
== EM_PAGE
)
467 maTabControl
->SetCurPageId (nActualPageNum
+ 1);
472 Invalidate( SID_PAGEMODE
);
473 Invalidate( SID_LAYERMODE
);
474 Invalidate( SID_MASTERPAGE
);
475 Invalidate( SID_DELETE_MASTER_PAGE
);
476 Invalidate( SID_DELETE_PAGE
);
477 Invalidate( SID_SLIDE_MASTERPAGE
);
478 Invalidate( SID_TITLE_MASTERPAGE
);
479 Invalidate( SID_NOTES_MASTERPAGE
);
480 Invalidate( SID_HANDOUT_MASTERPAGE
);
482 SetContextName(GetSidebarContextName());
487 * Generate horizontal ruler
490 SvxRuler
* DrawViewShell::CreateHRuler (::sd::Window
* pWin
, bool bIsFirst
)
494 SvxRulerSupportFlags nFlags
= SvxRulerSupportFlags::OBJECT
;
498 aWBits
= WB_HSCROLL
| WB_3DLOOK
| WB_BORDER
| WB_EXTRAFIELD
;
499 nFlags
|= ( SvxRulerSupportFlags::SET_NULLOFFSET
|
500 SvxRulerSupportFlags::TABS
|
501 SvxRulerSupportFlags::PARAGRAPH_MARGINS
); // Neu
504 aWBits
= WB_HSCROLL
| WB_3DLOOK
| WB_BORDER
;
506 pRuler
= VclPtr
<Ruler
>::Create(*this, GetParentWindow(), pWin
, nFlags
,
507 GetViewFrame()->GetBindings(), aWBits
);
509 pRuler
->SetSourceUnit(pWin
->GetMapMode().GetMapUnit());
512 sal_uInt16 nMetric
= (sal_uInt16
)GetDoc()->GetUIUnit();
514 if( nMetric
== 0xffff )
515 nMetric
= (sal_uInt16
)GetViewShellBase().GetViewFrame()->GetDispatcher()->GetModule()->GetFieldUnit();
517 pRuler
->SetUnit( FieldUnit( nMetric
) );
519 // ... and also set DefTab at the ruler
520 pRuler
->SetDefTabDist( GetDoc()->GetDefaultTabulator() ); // new
522 Fraction
aUIScale(pWin
->GetMapMode().GetScaleX());
523 aUIScale
*= GetDoc()->GetUIScale();
524 pRuler
->SetZoom(aUIScale
);
530 * Generate vertical ruler
533 SvxRuler
* DrawViewShell::CreateVRuler(::sd::Window
* pWin
)
536 WinBits aWBits
= WB_VSCROLL
| WB_3DLOOK
| WB_BORDER
;
537 SvxRulerSupportFlags nFlags
= SvxRulerSupportFlags::OBJECT
;
539 pRuler
= VclPtr
<Ruler
>::Create(*this, GetParentWindow(), pWin
, nFlags
,
540 GetViewFrame()->GetBindings(), aWBits
);
541 pRuler
->SetSourceUnit(pWin
->GetMapMode().GetMapUnit());
543 // Metric same as HRuler, use document setting
544 sal_uInt16 nMetric
= (sal_uInt16
)GetDoc()->GetUIUnit();
546 if( nMetric
== 0xffff )
547 nMetric
= (sal_uInt16
)GetViewShellBase().GetViewFrame()->GetDispatcher()->GetModule()->GetFieldUnit();
549 pRuler
->SetUnit( FieldUnit( nMetric
) );
551 Fraction
aUIScale(pWin
->GetMapMode().GetScaleY());
552 aUIScale
*= GetDoc()->GetUIScale();
553 pRuler
->SetZoom(aUIScale
);
559 * Refresh horizontal ruler
562 void DrawViewShell::UpdateHRuler()
564 Invalidate( SID_ATTR_LONG_LRSPACE
);
565 Invalidate( SID_RULER_PAGE_POS
);
566 Invalidate( SID_RULER_OBJECT
);
567 Invalidate( SID_RULER_TEXT_RIGHT_TO_LEFT
);
569 if (mpHorizontalRuler
.get() != NULL
)
570 mpHorizontalRuler
->ForceUpdate();
574 * Refresh vertical ruler
577 void DrawViewShell::UpdateVRuler()
579 Invalidate( SID_ATTR_LONG_LRSPACE
);
580 Invalidate( SID_RULER_PAGE_POS
);
581 Invalidate( SID_RULER_OBJECT
);
583 if (mpVerticalRuler
.get() != NULL
)
584 mpVerticalRuler
->ForceUpdate();
591 void DrawViewShell::SetUIUnit(FieldUnit eUnit
)
593 ViewShell::SetUIUnit(eUnit
);
597 * Refresh TabControl on splitter change
600 IMPL_LINK( DrawViewShell
, TabSplitHdl
, TabBar
*, pTab
)
602 const long int nMax
= maViewSize
.Width() - maScrBarWH
.Width()
603 - maTabControl
->GetPosPixel().X() ;
605 Size aTabSize
= maTabControl
->GetSizePixel();
606 aTabSize
.Width() = std::min(pTab
->GetSplitSize(), (long)(nMax
-1));
608 maTabControl
->SetSizePixel(aTabSize
);
610 if(GetLayerTabControl()) // #i87182#
612 GetLayerTabControl()->SetSizePixel(aTabSize
);
615 Point aPos
= maTabControl
->GetPosPixel();
616 aPos
.X() += aTabSize
.Width();
618 Size
aScrSize(nMax
- aTabSize
.Width(), maScrBarWH
.Height());
619 mpHorizontalScrollBar
->SetPosSizePixel(aPos
, aScrSize
);
624 /// inherited from sd::ViewShell
625 SdPage
* DrawViewShell::getCurrentPage() const
627 const sal_Int32 nPageCount
= (meEditMode
== EM_PAGE
)?
628 GetDoc()->GetSdPageCount(mePageKind
):
629 GetDoc()->GetMasterSdPageCount(mePageKind
);
631 sal_Int32 nCurrentPage
= maTabControl
->GetCurPageId() - 1;
632 DBG_ASSERT( (nPageCount
>0) && (nCurrentPage
<nPageCount
), "sd::DrawViewShell::getCurrentPage(), illegal page index!" );
633 if( (nPageCount
< 0) || (nCurrentPage
>=nPageCount
) )
634 nCurrentPage
= 0; // play safe here
636 if (meEditMode
== EM_PAGE
)
638 return GetDoc()->GetSdPage((sal_uInt16
)nCurrentPage
, mePageKind
);
640 else // EM_MASTERPAGE
642 return GetDoc()->GetMasterSdPage((sal_uInt16
)nCurrentPage
, mePageKind
);
647 * Select new refreshed page, in case of a page order change (eg. by undo)
650 void DrawViewShell::ResetActualPage()
655 sal_uInt16 nCurrentPage
= maTabControl
->GetCurPageId() - 1;
656 sal_uInt16 nPageCount
= (meEditMode
== EM_PAGE
)?GetDoc()->GetSdPageCount(mePageKind
):GetDoc()->GetMasterSdPageCount(mePageKind
);
658 nCurrentPage
= std::min((sal_uInt16
)(nPageCount
- 1), nCurrentPage
);
662 if (meEditMode
== EM_PAGE
)
665 // Update for TabControl
666 maTabControl
->Clear();
668 SdPage
* pPage
= NULL
;
670 for (sal_uInt16 i
= 0; i
< nPageCount
; i
++)
672 pPage
= GetDoc()->GetSdPage(i
, mePageKind
);
673 OUString aPageName
= pPage
->GetName();
674 maTabControl
->InsertPage(i
+ 1, aPageName
);
676 // correct selection recognition of the pages
677 GetDoc()->SetSelected(pPage
, i
== nCurrentPage
);
680 maTabControl
->SetCurPageId(nCurrentPage
+ 1);
682 else // EM_MASTERPAGE
684 SdPage
* pActualPage
= GetDoc()->GetMasterSdPage(nCurrentPage
, mePageKind
);
685 maTabControl
->Clear();
686 sal_uInt16 nActualMasterPageNum
= 0;
688 sal_uInt16 nMasterPageCnt
= GetDoc()->GetMasterSdPageCount(mePageKind
);
689 for (sal_uInt16 i
= 0; i
< nMasterPageCnt
; i
++)
691 SdPage
* pMaster
= GetDoc()->GetMasterSdPage(i
, mePageKind
);
692 OUString aLayoutName
= pMaster
->GetLayoutName();
693 sal_Int32 nPos
= aLayoutName
.indexOf(SD_LT_SEPARATOR
);
695 aLayoutName
= aLayoutName
.copy(0, nPos
);
696 maTabControl
->InsertPage(i
+ 1, aLayoutName
);
698 if (pActualPage
== pMaster
)
699 nActualMasterPageNum
= i
;
702 maTabControl
->SetCurPageId(nActualMasterPageNum
+ 1);
703 SwitchPage(nActualMasterPageNum
);
706 GetViewFrame()->GetDispatcher()->Execute(SID_SWITCHPAGE
,
707 SfxCallMode::ASYNCHRON
| SfxCallMode::RECORD
);
711 * Apply "Verb" on OLE-object.
714 ErrCode
DrawViewShell::DoVerb(long nVerb
)
716 if ( mpDrawView
->AreObjectsMarked() )
718 const SdrMarkList
& rMarkList
= mpDrawView
->GetMarkedObjectList();
720 if (rMarkList
.GetMarkCount() == 1)
722 SdrMark
* pMark
= rMarkList
.GetMark(0);
723 SdrObject
* pObj
= pMark
->GetMarkedSdrObj();
725 sal_uInt32 nInv
= pObj
->GetObjInventor();
726 sal_uInt16 nSdrObjKind
= pObj
->GetObjIdentifier();
728 if (nInv
== SdrInventor
&& nSdrObjKind
== OBJ_OLE2
)
730 ActivateObject( static_cast<SdrOle2Obj
*>(pObj
), nVerb
);
739 * Activate OLE-object
742 bool DrawViewShell::ActivateObject(SdrOle2Obj
* pObj
, long nVerb
)
744 bool bActivated
= false;
746 if ( !GetDocSh()->IsUIActive() )
748 ToolBarManager::UpdateLock
aLock (GetViewShellBase().GetToolBarManager());
750 bActivated
= ViewShell::ActivateObject(pObj
, nVerb
);
752 OSL_ASSERT(GetViewShell()!=NULL
);
753 Client
* pClient
= static_cast<Client
*>(GetViewShell()->GetIPClient());
755 pClient
->SetSdrGrafObj(NULL
);
762 * Switch to desired page.
763 * nSelectPage refers to the current EditMode
766 void LclResetFlag (bool& rbFlag
) {rbFlag
= false;}
768 bool DrawViewShell::SwitchPage(sal_uInt16 nSelectedPage
)
770 /** Under some circumstances there are nested calls to SwitchPage() and
771 may crash the application (activation of form controls when the
772 shell of the edit view is not on top of the shell stack, see issue
773 83888 for details.) Therefore the nested calls are ignored (they
774 would jump to the wrong page anyway.)
776 if (mbIsInSwitchPage
)
778 mbIsInSwitchPage
= true;
779 comphelper::ScopeGuard
aGuard (::boost::bind(LclResetFlag
, ::boost::ref(mbIsInSwitchPage
)));
781 if (GetActiveWindow()->IsInPaint())
783 // Switching the current page while a Paint is being executed is
784 // dangerous. So, post it for later execution and return.
785 maAsynchronousSwitchPageCall
.Post(::boost::bind(
786 ::std::mem_fun(&DrawViewShell::SwitchPage
),
794 // With the current implementation of FuSlideShow there is a problem
795 // when it dsplays the show in a window: When the show is stopped it
796 // returns at one point in time SDRPAGE_NOTFOUND as current page index.
797 // Because FuSlideShow is currently being rewritten this bug is fixed
799 // This is not as bad a hack as it may look because making SwitchPage()
800 // more robust with respect to invalid page numbers is a good thing
802 if (nSelectedPage
== SDRPAGE_NOTFOUND
)
808 // Make sure that the given page index points to an existing page. Move
809 // the index into the valid range if necessary.
810 sal_uInt16 nPageCount
= (meEditMode
== EM_PAGE
)
811 ? GetDoc()->GetSdPageCount(mePageKind
)
812 : GetDoc()->GetMasterSdPageCount(mePageKind
);
813 if (nSelectedPage
>= nPageCount
)
814 nSelectedPage
= nPageCount
-1;
817 if (IsSwitchPageAllowed())
819 ModifyGuard
aGuard2( GetDoc() );
825 SdPage
* pNewPage
= NULL
;
827 if (meEditMode
== EM_MASTERPAGE
)
829 if( GetDoc()->GetMasterSdPageCount(mePageKind
) > nSelectedPage
)
830 pNewPage
= GetDoc()->GetMasterSdPage(nSelectedPage
, mePageKind
);
834 SdrPageView
* pPV
= mpDrawView
->GetSdrPageView();
835 OUString
sPageText(pNewPage
->GetLayoutName());
836 sal_Int32 nPos
= sPageText
.indexOf(SD_LT_SEPARATOR
);
838 sPageText
= sPageText
.copy(0, nPos
);
840 && pNewPage
== dynamic_cast< SdPage
* >( pPV
->GetPage() )
841 && sPageText
== maTabControl
->GetPageText(nSelectedPage
+1))
843 // this slide is already visible
850 OSL_ASSERT(mpFrameView
!=NULL
);
851 mpFrameView
->SetSelectedPage(nSelectedPage
);
853 if (GetDoc()->GetSdPageCount(mePageKind
) > nSelectedPage
)
854 pNewPage
= GetDoc()->GetSdPage(nSelectedPage
, mePageKind
);
856 if (mpActualPage
== pNewPage
)
858 SdrPageView
* pPV
= mpDrawView
->GetSdrPageView();
860 SdPage
* pCurrentPage
= pPV
? dynamic_cast<SdPage
*>(pPV
->GetPage()) : NULL
;
862 && pNewPage
== pCurrentPage
863 && maTabControl
->GetPageText(nSelectedPage
+1).equals(pNewPage
->GetName()))
865 // this slide is already visible
872 mpDrawView
->SdrEndTextEdit();
876 if (meEditMode
== EM_PAGE
)
878 mpActualPage
= GetDoc()->GetSdPage(nSelectedPage
, mePageKind
);
882 SdPage
* pMaster
= GetDoc()->GetMasterSdPage(nSelectedPage
, mePageKind
);
884 // does the selected page fit to the masterpage?
885 sal_uInt16 nPageCount
= GetDoc()->GetSdPageCount(mePageKind
);
886 for (sal_uInt16 i
= 0; i
< nPageCount
; i
++)
888 SdPage
* pPage
= GetDoc()->GetSdPage(i
, mePageKind
);
889 if(pPage
&& pPage
->IsSelected() && pMaster
== &(pPage
->TRG_GetMasterPage()))
891 mpActualPage
= pPage
;
898 // take the first page, that fits to the masterpage
899 for (sal_uInt16 i
= 0; i
< nPageCount
; i
++)
901 SdPage
* pPage
= GetDoc()->GetSdPage(i
, mePageKind
);
902 if(pPage
&& pMaster
== &(pPage
->TRG_GetMasterPage()))
904 mpActualPage
= pPage
;
911 for (sal_uInt16 i
= 0; i
< GetDoc()->GetSdPageCount(mePageKind
); i
++)
913 // deselect all pages
914 GetDoc()->SetSelected( GetDoc()->GetSdPage(i
, mePageKind
), false);
919 // as far as there is no mpActualPage, take the first
920 mpActualPage
= GetDoc()->GetSdPage(0, mePageKind
);
923 // also select this page (mpActualPage always points at a drawing page,
924 // never at a masterpage)
925 GetDoc()->SetSelected(mpActualPage
, true);
927 rtl::Reference
< sd::SlideShow
> xSlideshow( SlideShow::GetSlideShow( GetDoc() ) );
928 if( !xSlideshow
.is() || !xSlideshow
->isRunning() || ( xSlideshow
->getAnimationMode() != ANIMATIONMODE_SHOW
) )
930 // tighten VisArea, to possibly deactivate objects
931 // !!! only if we are not in presentation mode (#96279) !!!
932 OSL_ASSERT (GetViewShell()!=NULL
);
933 GetViewShell()->DisconnectAllClients();
934 VisAreaChanged(Rectangle(Point(), Size(1, 1)));
937 if (meEditMode
== EM_PAGE
)
939 /**********************************************************************
941 **********************************************************************/
942 GetDoc()->SetSelected(mpActualPage
, true);
944 SdrPageView
* pPageView
= mpDrawView
->GetSdrPageView();
948 mpFrameView
->SetVisibleLayers( pPageView
->GetVisibleLayers() );
949 mpFrameView
->SetPrintableLayers( pPageView
->GetPrintableLayers() );
950 mpFrameView
->SetLockedLayers( pPageView
->GetLockedLayers() );
952 if (mePageKind
== PK_NOTES
)
954 mpFrameView
->SetNotesHelpLines( pPageView
->GetHelpLines() );
956 else if (mePageKind
== PK_HANDOUT
)
958 mpFrameView
->SetHandoutHelpLines( pPageView
->GetHelpLines() );
962 mpFrameView
->SetStandardHelpLines( pPageView
->GetHelpLines() );
966 mpDrawView
->HideSdrPage();
967 mpDrawView
->ShowSdrPage(mpActualPage
);
968 GetViewShellBase().GetDrawController().FireSwitchCurrentPage(mpActualPage
);
970 SdrPageView
* pNewPageView
= mpDrawView
->GetSdrPageView();
974 pNewPageView
->SetVisibleLayers( mpFrameView
->GetVisibleLayers() );
975 pNewPageView
->SetPrintableLayers( mpFrameView
->GetPrintableLayers() );
976 pNewPageView
->SetLockedLayers( mpFrameView
->GetLockedLayers() );
978 if (mePageKind
== PK_NOTES
)
980 pNewPageView
->SetHelpLines( mpFrameView
->GetNotesHelpLines() );
982 else if (mePageKind
== PK_HANDOUT
)
984 pNewPageView
->SetHelpLines( mpFrameView
->GetHandoutHelpLines() );
988 pNewPageView
->SetHelpLines( mpFrameView
->GetStandardHelpLines() );
992 maTabControl
->SetCurPageId(nSelectedPage
+1);
993 OUString aPageName
= mpActualPage
->GetName();
995 if (maTabControl
->GetPageText(nSelectedPage
+1) != aPageName
)
997 maTabControl
->SetPageText(nSelectedPage
+1, aPageName
);
1002 /**********************************************************************
1004 **********************************************************************/
1005 SdrPageView
* pPageView
= mpDrawView
->GetSdrPageView();
1009 mpFrameView
->SetVisibleLayers( pPageView
->GetVisibleLayers() );
1010 mpFrameView
->SetPrintableLayers( pPageView
->GetPrintableLayers() );
1011 mpFrameView
->SetLockedLayers( pPageView
->GetLockedLayers() );
1013 if (mePageKind
== PK_NOTES
)
1015 mpFrameView
->SetNotesHelpLines( pPageView
->GetHelpLines() );
1017 else if (mePageKind
== PK_HANDOUT
)
1019 mpFrameView
->SetHandoutHelpLines( pPageView
->GetHelpLines() );
1023 mpFrameView
->SetStandardHelpLines( pPageView
->GetHelpLines() );
1027 mpDrawView
->HideSdrPage();
1029 SdPage
* pMaster
= GetDoc()->GetMasterSdPage(nSelectedPage
, mePageKind
);
1031 if( !pMaster
) // if this page should not exist
1032 pMaster
= GetDoc()->GetMasterSdPage(0, mePageKind
);
1034 sal_uInt16 nNum
= pMaster
->GetPageNum();
1035 mpDrawView
->ShowSdrPage(mpDrawView
->GetModel()->GetMasterPage(nNum
));
1037 GetViewShellBase().GetDrawController().FireSwitchCurrentPage(pMaster
);
1039 SdrPageView
* pNewPageView
= mpDrawView
->GetSdrPageView();
1043 pNewPageView
->SetVisibleLayers( mpFrameView
->GetVisibleLayers() );
1044 pNewPageView
->SetPrintableLayers( mpFrameView
->GetPrintableLayers() );
1045 pNewPageView
->SetLockedLayers( mpFrameView
->GetLockedLayers() );
1047 if (mePageKind
== PK_NOTES
)
1049 pNewPageView
->SetHelpLines( mpFrameView
->GetNotesHelpLines() );
1051 else if (mePageKind
== PK_HANDOUT
)
1053 pNewPageView
->SetHelpLines( mpFrameView
->GetHandoutHelpLines() );
1057 pNewPageView
->SetHelpLines( mpFrameView
->GetStandardHelpLines() );
1061 OUString
aLayoutName(pMaster
->GetLayoutName());
1062 sal_Int32 nPos
= aLayoutName
.indexOf(SD_LT_SEPARATOR
);
1064 aLayoutName
= aLayoutName
.copy(0, nPos
);
1066 maTabControl
->SetCurPageId(nSelectedPage
+1);
1068 if (maTabControl
->GetPageText(nSelectedPage
+1) != aLayoutName
)
1070 maTabControl
->SetPageText(nSelectedPage
+1, aLayoutName
);
1073 if( mePageKind
== PK_HANDOUT
)
1075 // set pages for all available handout presentation objects
1076 sd::ShapeList
& rShapeList
= pMaster
->GetPresentationShapeList();
1077 SdrObject
* pObj
= 0;
1078 rShapeList
.seekShape(0);
1080 while( (pObj
= rShapeList
.getNextShape()) )
1082 if( pMaster
->GetPresObjKind(pObj
) == PRESOBJ_HANDOUT
)
1084 // #i105146# We want no content to be displayed for PK_HANDOUT,
1085 // so just never set a page as content
1086 static_cast<SdrPageObj
*>(pObj
)->SetReferencedPage(0);
1092 Size aVisSizePixel
= GetActiveWindow()->GetOutputSizePixel();
1093 Rectangle aVisAreaWin
= GetActiveWindow()->PixelToLogic( Rectangle( Point(0,0), aVisSizePixel
) );
1094 VisAreaChanged(aVisAreaWin
);
1095 mpDrawView
->VisAreaChanged(GetActiveWindow());
1097 // so navigator (and effect window) notice that
1098 SfxBindings
& rBindings
= GetViewFrame()->GetBindings();
1099 rBindings
.Invalidate(SID_NAVIGATOR_PAGENAME
, true, false);
1100 rBindings
.Invalidate(SID_STATUS_PAGE
, true, false);
1101 rBindings
.Invalidate(SID_DELETE_MASTER_PAGE
, true, false);
1102 rBindings
.Invalidate(SID_DELETE_PAGE
, true, false);
1103 rBindings
.Invalidate(SID_ASSIGN_LAYOUT
, true, false);
1104 rBindings
.Invalidate(SID_INSERTPAGE
, true, false);
1105 UpdatePreview( mpActualPage
);
1107 mpDrawView
->AdjustMarkHdl();
1114 * Check if page change is allowed
1117 bool DrawViewShell::IsSwitchPageAllowed() const
1121 FmFormShell
* pFormShell
= GetViewShellBase().GetFormShellManager()->GetFormShell();
1122 if (pFormShell
!= NULL
&& !pFormShell
->PrepareClose(false))
1129 * Select new refreshed page, in case of a page order change (eg. by undo)
1132 void DrawViewShell::ResetActualLayer()
1134 LayerTabBar
* pLayerBar
= GetLayerTabControl();
1135 if (pLayerBar
!= NULL
)
1137 // remember old layer cound and current layer id
1138 // this is needed when one layer is renamed to
1139 // restore current layer
1140 sal_uInt16 nOldLayerCnt
= pLayerBar
->GetPageCount();
1141 sal_uInt16 nOldLayerId
= pLayerBar
->GetCurPageId();
1144 * Update for LayerTab
1149 OUString aActiveLayer
= mpDrawView
->GetActiveLayer();
1150 OUString aBackgroundLayer
= SD_RESSTR(STR_LAYER_BCKGRND
);
1151 OUString aBackgroundObjLayer
= SD_RESSTR(STR_LAYER_BCKGRNDOBJ
);
1152 OUString aLayoutLayer
= SD_RESSTR(STR_LAYER_LAYOUT
);
1153 OUString aControlsLayer
= SD_RESSTR(STR_LAYER_CONTROLS
);
1154 OUString aMeasureLinesLayer
= SD_RESSTR(STR_LAYER_MEASURELINES
);
1155 sal_uInt16 nActiveLayer
= SDRLAYER_NOTFOUND
;
1156 SdrLayerAdmin
& rLayerAdmin
= GetDoc()->GetLayerAdmin();
1157 sal_uInt16 nLayerCnt
= rLayerAdmin
.GetLayerCount();
1159 for ( sal_uInt16 nLayer
= 0; nLayer
< nLayerCnt
; nLayer
++ )
1161 aName
= rLayerAdmin
.GetLayer(nLayer
)->GetName();
1163 if ( aName
== aActiveLayer
)
1165 nActiveLayer
= nLayer
;
1168 if ( aName
!= aBackgroundLayer
)
1170 if (meEditMode
== EM_MASTERPAGE
)
1172 // don't show page layer onto the masterpage
1173 if (aName
!= aLayoutLayer
&&
1174 aName
!= aControlsLayer
&&
1175 aName
!= aMeasureLinesLayer
)
1177 pLayerBar
->InsertPage(nLayer
+1, aName
);
1179 TabBarPageBits nBits
= 0;
1180 SdrPageView
* pPV
= mpDrawView
->GetSdrPageView();
1182 if (pPV
&& !pPV
->IsLayerVisible(aName
))
1184 // invisible layers are displayed differently
1185 nBits
= TPB_SPECIAL
;
1188 pLayerBar
->SetPageBits(nLayer
+1, nBits
);
1193 // don't show masterpage layer onto the page
1194 if ( aName
!= aBackgroundObjLayer
)
1196 pLayerBar
->InsertPage(nLayer
+1, aName
);
1198 TabBarPageBits nBits
= 0;
1200 if (!mpDrawView
->GetSdrPageView()->IsLayerVisible(aName
))
1202 // invisible layers are displayed differently
1203 nBits
= TPB_SPECIAL
;
1206 pLayerBar
->SetPageBits(nLayer
+1, nBits
);
1212 if ( nActiveLayer
== SDRLAYER_NOTFOUND
)
1214 if( nOldLayerCnt
== pLayerBar
->GetPageCount() )
1216 nActiveLayer
= nOldLayerId
- 1;
1220 nActiveLayer
= ( meEditMode
== EM_MASTERPAGE
) ? 2 : 0;
1223 mpDrawView
->SetActiveLayer( pLayerBar
->GetPageText(nActiveLayer
+ 1) );
1226 pLayerBar
->SetCurPageId(nActiveLayer
+ 1);
1227 GetViewFrame()->GetBindings().Invalidate( SID_MODIFYLAYER
);
1228 GetViewFrame()->GetBindings().Invalidate( SID_DELETE_LAYER
);
1236 sal_Int8
DrawViewShell::AcceptDrop (
1237 const AcceptDropEvent
& rEvt
,
1238 DropTargetHelper
& rTargetHelper
,
1239 ::sd::Window
* pTargetWindow
,
1243 if( nPage
!= SDRPAGE_NOTFOUND
)
1244 nPage
= GetDoc()->GetSdPage( nPage
, mePageKind
)->GetPageNum();
1246 if( SlideShow::IsRunning( GetViewShellBase() ) )
1247 return DND_ACTION_NONE
;
1249 return mpDrawView
->AcceptDrop( rEvt
, rTargetHelper
, pTargetWindow
, nPage
, nLayer
);
1256 sal_Int8
DrawViewShell::ExecuteDrop (
1257 const ExecuteDropEvent
& rEvt
,
1258 DropTargetHelper
& rTargetHelper
,
1259 ::sd::Window
* pTargetWindow
,
1263 if( nPage
!= SDRPAGE_NOTFOUND
)
1264 nPage
= GetDoc()->GetSdPage( nPage
, mePageKind
)->GetPageNum();
1266 if( SlideShow::IsRunning( GetViewShellBase() ) )
1267 return DND_ACTION_NONE
;
1269 Broadcast(ViewShellHint(ViewShellHint::HINT_COMPLEX_MODEL_CHANGE_START
));
1270 sal_Int8
nResult (mpDrawView
->ExecuteDrop( rEvt
, rTargetHelper
, pTargetWindow
, nPage
, nLayer
));
1271 Broadcast(ViewShellHint(ViewShellHint::HINT_COMPLEX_MODEL_CHANGE_END
));
1276 } // end of namespace sd
1278 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */