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 .
21 #include "DrawViewShell.hxx"
22 #include "ViewShellImplementation.hxx"
24 #include "DrawController.hxx"
25 #include <com/sun/star/embed/EmbedStates.hpp>
27 #include "comphelper/anytostring.hxx"
28 #include "comphelper/scopeguard.hxx"
29 #include "cppuhelper/exc_hlp.hxx"
30 #include "rtl/ref.hxx"
32 #include <svx/svxids.hrc>
33 #include <svx/svdpagv.hxx>
34 #include <sfx2/viewfrm.hxx>
35 #include <sfx2/bindings.hxx>
36 #include <svx/svdoole2.hxx>
37 #include <sfx2/dispatch.hxx>
38 #include <vcl/scrbar.hxx>
39 #include <svx/svdograf.hxx>
40 #include <svx/svdopage.hxx>
41 #include <vcl/msgbox.hxx>
42 #include <sot/storage.hxx>
43 #include <svx/fmshell.hxx>
44 #include <svx/globl3d.hxx>
45 #include <svx/fmglob.hxx>
46 #include <editeng/outliner.hxx>
47 #include <svx/dialogs.hrc>
49 #include "view/viewoverlaymanager.hxx"
53 #include "res_bmp.hrc"
54 #include "strings.hrc"
59 #include "sdresid.hxx"
62 #include "FrameView.hxx"
63 #include "stlpool.hxx"
65 #include "drawview.hxx"
66 #include "drawdoc.hxx"
67 #include "DrawDocShell.hxx"
70 #include "slideshow.hxx"
71 #include "optsitem.hxx"
72 #include "fusearch.hxx"
73 #include "Outliner.hxx"
74 #include "AnimationChildWindow.hxx"
75 #include "SdUnoDrawView.hxx"
76 #include "ToolBarManager.hxx"
77 #include "FormShellManager.hxx"
78 #include "ViewShellBase.hxx"
79 #include "LayerDialogChildWindow.hxx"
80 #include "LayerTabBar.hxx"
81 #include "ViewShellManager.hxx"
82 #include "ViewShellHint.hxx"
84 #include <sfx2/request.hxx>
85 #include <boost/bind.hpp>
87 using namespace com::sun::star
;
91 void DrawViewShell::Activate(sal_Bool bIsMDIActivate
)
93 ViewShell::Activate(bIsMDIActivate
);
96 void DrawViewShell::UIActivating( SfxInPlaceClient
* pCli
)
98 ViewShell::UIActivating(pCli
);
100 // Disable own controls
101 maTabControl
.Disable();
102 if (GetLayerTabControl() != NULL
)
103 GetLayerTabControl()->Disable();
106 void DrawViewShell::UIDeactivated( SfxInPlaceClient
* pCli
)
108 // Enable own controls
109 maTabControl
.Enable();
110 if (GetLayerTabControl() != NULL
)
111 GetLayerTabControl()->Enable();
113 ViewShell::UIDeactivated(pCli
);
117 void DrawViewShell::Deactivate(sal_Bool bIsMDIActivate
)
119 ViewShell::Deactivate(bIsMDIActivate
);
127 void Lock(bool bLock
);
128 SfxViewFrame
*mpFrame
;
130 LockUI(SfxViewFrame
*pFrame
) : mpFrame(pFrame
) { Lock(true); }
131 ~LockUI() { Lock(false); }
135 void LockUI::Lock(bool bLock
)
139 mpFrame
->Enable( !bLock
);
144 * Called, if state of selection of view is changed
147 void DrawViewShell::SelectionHasChanged (void)
151 //Update3DWindow(); // 3D-Controller
152 SfxBoolItem
aItem( SID_3D_STATE
, sal_True
);
153 GetViewFrame()->GetDispatcher()->Execute(
154 SID_3D_STATE
, SFX_CALLMODE_ASYNCHRON
| SFX_CALLMODE_RECORD
, &aItem
, 0L );
156 SdrOle2Obj
* pOleObj
= NULL
;
158 if ( mpDrawView
->AreObjectsMarked() )
160 const SdrMarkList
& rMarkList
= mpDrawView
->GetMarkedObjectList();
162 if (rMarkList
.GetMarkCount() == 1)
164 SdrMark
* pMark
= rMarkList
.GetMark(0);
165 SdrObject
* pObj
= pMark
->GetMarkedSdrObj();
167 sal_uInt32 nInv
= pObj
->GetObjInventor();
168 sal_uInt16 nSdrObjKind
= pObj
->GetObjIdentifier();
170 if (nInv
== SdrInventor
&& nSdrObjKind
== OBJ_OLE2
)
172 pOleObj
= (SdrOle2Obj
*) pObj
;
173 UpdateIMapDlg( pObj
);
175 else if (nSdrObjKind
== OBJ_GRAF
)
176 UpdateIMapDlg( pObj
);
180 ViewShellBase
& rBase
= GetViewShellBase();
181 rBase
.SetVerbs( uno::Sequence
< embed::VerbDescriptor
>() );
185 Client
* pIPClient
= static_cast<Client
*>(rBase
.GetIPClient());
186 if ( pIPClient
&& pIPClient
->IsObjectInPlaceActive() )
188 // as appropriate take ole-objects into account and deactivate
190 // this means we recently deselected an inplace active ole object so
191 // we need to deselect it now
194 //#i47279# disable frame until after object has completed unload
195 LockUI
aUILock(GetViewFrame());
196 pIPClient
->DeactivateObject();
197 //HMHmpDrView->ShowMarkHdl();
201 uno::Reference
< embed::XEmbeddedObject
> xObj
= pOleObj
->GetObjRef();
204 rBase
.SetVerbs( xObj
->getSupportedVerbs() );
208 rBase
.SetVerbs( uno::Sequence
< embed::VerbDescriptor
>() );
216 uno::Reference
< embed::XEmbeddedObject
> xObj
= pOleObj
->GetObjRef();
219 rBase
.SetVerbs( xObj
->getSupportedVerbs() );
223 rBase
.SetVerbs( uno::Sequence
< embed::VerbDescriptor
>() );
228 rBase
.SetVerbs( uno::Sequence
< embed::VerbDescriptor
>() );
232 catch( ::com::sun::star::uno::Exception
& )
235 OString(OString("sd::DrawViewShell::SelectionHasChanged(), "
236 "exception caught: ") +
238 comphelper::anyToString( cppu::getCaughtException() ),
239 RTL_TEXTENCODING_UTF8
)).getStr() );
242 if( HasCurrentFunction() )
244 GetCurrentFunction()->SelectionHasChanged();
248 GetViewShellBase().GetToolBarManager()->SelectionHasChanged(*this,*mpDrawView
);
251 // Invalidate for every subshell
252 GetViewShellBase().GetViewShellManager()->InvalidateAllSubShells(this);
254 mpDrawView
->UpdateSelectionClipboard( sal_False
);
256 GetViewShellBase().GetDrawController().FireSelectionChangeListener();
262 void DrawViewShell::SetZoom( long nZoom
)
264 // Make sure that the zoom factor will not be recalculated on
265 // following window resizings.
266 mbZoomOnPage
= sal_False
;
267 ViewShell::SetZoom( nZoom
);
268 GetViewFrame()->GetBindings().Invalidate( SID_ATTR_ZOOM
);
269 GetViewFrame()->GetBindings().Invalidate( SID_ATTR_ZOOMSLIDER
);
270 mpViewOverlayManager
->onZoomChanged();
274 * Set zoom rectangle for active window
277 void DrawViewShell::SetZoomRect( const Rectangle
& rZoomRect
)
279 ViewShell::SetZoomRect( rZoomRect
);
280 GetViewFrame()->GetBindings().Invalidate( SID_ATTR_ZOOM
);
281 GetViewFrame()->GetBindings().Invalidate( SID_ATTR_ZOOMSLIDER
);
282 mpViewOverlayManager
->onZoomChanged();
286 * PrepareClose, as appropriate end text input, so other viewshells
287 * discover an refreshed text objext.
290 sal_uInt16
DrawViewShell::PrepareClose( sal_Bool bUI
, sal_Bool bForBrowsing
)
292 if ( ViewShell::PrepareClose(bUI
, bForBrowsing
) != sal_True
)
295 sal_Bool bRet
= sal_True
;
297 if( bRet
&& HasCurrentFunction() )
299 sal_uInt16 nID
= GetCurrentFunction()->GetSlotID();
300 if (nID
== SID_TEXTEDIT
|| nID
== SID_ATTR_CHAR
)
302 mpDrawView
->SdrEndTextEdit();
307 maCloseTimer
.SetTimeoutHdl( LINK( this, DrawViewShell
, CloseHdl
) );
308 maCloseTimer
.SetTimeout( 20 );
309 maCloseTimer
.Start();
316 * Set status (enabled/disabled) of menu SfxSlots
319 void DrawViewShell::ChangeEditMode(EditMode eEMode
, bool bIsLayerModeActive
)
321 if (meEditMode
!= eEMode
|| mbIsLayerModeActive
!= bIsLayerModeActive
)
323 ViewShellManager::UpdateLock
aLock (GetViewShellBase().GetViewShellManager());
325 sal_uInt16 nActualPageNum
= 0;
327 GetViewShellBase().GetDrawController().FireChangeEditMode (eEMode
== EM_MASTERPAGE
);
328 GetViewShellBase().GetDrawController().FireChangeLayerMode (bIsLayerModeActive
);
330 if ( mpDrawView
->IsTextEdit() )
332 mpDrawView
->SdrEndTextEdit();
335 LayerTabBar
* pLayerBar
= GetLayerTabControl();
336 if (pLayerBar
!= NULL
)
337 pLayerBar
->EndEditMode();
338 maTabControl
.EndEditMode();
340 if (mePageKind
== PK_HANDOUT
)
342 // at handouts only allow MasterPage
343 eEMode
= EM_MASTERPAGE
;
346 GetViewShellBase().GetDrawController().BroadcastContextChange();
349 mbIsLayerModeActive
= bIsLayerModeActive
;
351 // Determine whether to show the master view toolbar. The master
352 // page mode has to be active and the shell must not be a handout
354 bool bShowMasterViewToolbar (meEditMode
== EM_MASTERPAGE
355 && GetShellType() != ViewShell::ST_HANDOUT
);
357 // If the master view toolbar is not shown we hide it before
358 // switching the edit mode.
359 if (::sd::ViewShell::mpImpl
->mbIsInitialized
361 && ! bShowMasterViewToolbar
)
363 GetViewShellBase().GetToolBarManager()->ResetToolBars(ToolBarManager::TBG_MASTER_MODE
);
366 if (meEditMode
== EM_PAGE
)
368 /******************************************************************
370 ******************************************************************/
372 maTabControl
.Clear();
376 sal_uInt16 nPageCnt
= GetDoc()->GetSdPageCount(mePageKind
);
378 for (sal_uInt16 i
= 0; i
< nPageCnt
; i
++)
380 pPage
= GetDoc()->GetSdPage(i
, mePageKind
);
381 aPageName
= pPage
->GetName();
382 maTabControl
.InsertPage(i
+ 1, aPageName
);
384 if ( pPage
->IsSelected() && nActualPageNum
== 0 )
390 maTabControl
.SetCurPageId(nActualPageNum
+ 1);
392 SwitchPage(nActualPageNum
);
396 /******************************************************************
398 ******************************************************************/
399 GetViewFrame()->SetChildWindow(
400 AnimationChildWindow::GetChildWindowId(), sal_False
);
404 // as long as there is no mpActualPage, take first
405 mpActualPage
= GetDoc()->GetSdPage(0, mePageKind
);
408 maTabControl
.Clear();
409 sal_uInt16 nActualMasterPageNum
= 0;
410 sal_uInt16 nMasterPageCnt
= GetDoc()->GetMasterSdPageCount(mePageKind
);
412 for (sal_uInt16 i
= 0; i
< nMasterPageCnt
; i
++)
414 SdPage
* pMaster
= GetDoc()->GetMasterSdPage(i
, mePageKind
);
415 String
aLayoutName(pMaster
->GetLayoutName());
416 aLayoutName
.Erase(aLayoutName
.SearchAscii(SD_LT_SEPARATOR
));
418 maTabControl
.InsertPage(i
+ 1, aLayoutName
);
420 if (&(mpActualPage
->TRG_GetMasterPage()) == pMaster
)
422 nActualMasterPageNum
= i
;
426 maTabControl
.SetCurPageId(nActualMasterPageNum
+ 1);
427 SwitchPage(nActualMasterPageNum
);
430 // If the master view toolbar is to be shown we turn it on after the
431 // edit mode has been changed.
432 if (::sd::ViewShell::mpImpl
->mbIsInitialized
434 && bShowMasterViewToolbar
)
436 GetViewShellBase().GetToolBarManager()->SetToolBar(
437 ToolBarManager::TBG_MASTER_MODE
,
438 ToolBarManager::msMasterViewToolBar
);
441 if ( ! mbIsLayerModeActive
)
444 // Set the tab control only for draw pages. For master page
445 // this has been done already above.
446 if (meEditMode
== EM_PAGE
)
447 maTabControl
.SetCurPageId (nActualPageNum
+ 1);
452 Invalidate( SID_PAGEMODE
);
453 Invalidate( SID_LAYERMODE
);
454 Invalidate( SID_MASTERPAGE
);
455 Invalidate( SID_DELETE_MASTER_PAGE
);
456 Invalidate( SID_DELETE_PAGE
);
457 Invalidate( SID_SLIDE_MASTERPAGE
);
458 Invalidate( SID_TITLE_MASTERPAGE
);
459 Invalidate( SID_NOTES_MASTERPAGE
);
460 Invalidate( SID_HANDOUT_MASTERPAGE
);
462 SetContextName(GetSidebarContextName());
469 bool DrawViewShell::IsLayerModeActive (void) const
471 return mbIsLayerModeActive
;
476 * Generate horizontal ruler
479 SvxRuler
* DrawViewShell::CreateHRuler (::sd::Window
* pWin
, sal_Bool bIsFirst
)
483 sal_uInt16 nFlags
= SVXRULER_SUPPORT_OBJECT
;
487 aWBits
= WB_HSCROLL
| WB_3DLOOK
| WB_BORDER
| WB_EXTRAFIELD
;
488 nFlags
|= ( SVXRULER_SUPPORT_SET_NULLOFFSET
|
489 SVXRULER_SUPPORT_TABS
|
490 SVXRULER_SUPPORT_PARAGRAPH_MARGINS
); // Neu
493 aWBits
= WB_HSCROLL
| WB_3DLOOK
| WB_BORDER
;
495 pRuler
= new Ruler (*this, GetParentWindow(), pWin
, nFlags
,
496 GetViewFrame()->GetBindings(), aWBits
);
497 pRuler
->SetSourceUnit(pWin
->GetMapMode().GetMapUnit());
500 sal_uInt16 nMetric
= (sal_uInt16
)GetDoc()->GetUIUnit();
502 if( nMetric
== 0xffff )
503 nMetric
= (sal_uInt16
)GetViewShellBase().GetViewFrame()->GetDispatcher()->GetModule()->GetFieldUnit();
505 pRuler
->SetUnit( FieldUnit( nMetric
) );
507 // ... and also set DefTab at the ruler
508 pRuler
->SetDefTabDist( GetDoc()->GetDefaultTabulator() ); // new
510 Fraction
aUIScale(pWin
->GetMapMode().GetScaleX());
511 aUIScale
*= GetDoc()->GetUIScale();
512 pRuler
->SetZoom(aUIScale
);
518 * Generate vertical ruler
521 SvxRuler
* DrawViewShell::CreateVRuler(::sd::Window
* pWin
)
524 WinBits aWBits
= WB_VSCROLL
| WB_3DLOOK
| WB_BORDER
;
525 sal_uInt16 nFlags
= SVXRULER_SUPPORT_OBJECT
;
527 pRuler
= new Ruler(*this, GetParentWindow(), pWin
, nFlags
,
528 GetViewFrame()->GetBindings(), aWBits
);
529 pRuler
->SetSourceUnit(pWin
->GetMapMode().GetMapUnit());
531 // Metric same as HRuler, use document setting
532 sal_uInt16 nMetric
= (sal_uInt16
)GetDoc()->GetUIUnit();
534 if( nMetric
== 0xffff )
535 nMetric
= (sal_uInt16
)GetViewShellBase().GetViewFrame()->GetDispatcher()->GetModule()->GetFieldUnit();
537 pRuler
->SetUnit( FieldUnit( nMetric
) );
539 Fraction
aUIScale(pWin
->GetMapMode().GetScaleY());
540 aUIScale
*= GetDoc()->GetUIScale();
541 pRuler
->SetZoom(aUIScale
);
547 * Refresh horizontal ruler
550 void DrawViewShell::UpdateHRuler()
552 Invalidate( SID_ATTR_LONG_LRSPACE
);
553 Invalidate( SID_RULER_PAGE_POS
);
554 Invalidate( SID_RULER_OBJECT
);
555 Invalidate( SID_RULER_TEXT_RIGHT_TO_LEFT
);
557 if (mpHorizontalRuler
.get() != NULL
)
558 mpHorizontalRuler
->ForceUpdate();
562 * Refresh vertical ruler
565 void DrawViewShell::UpdateVRuler()
567 Invalidate( SID_ATTR_LONG_LRSPACE
);
568 Invalidate( SID_RULER_PAGE_POS
);
569 Invalidate( SID_RULER_OBJECT
);
571 if (mpVerticalRuler
.get() != NULL
)
572 mpVerticalRuler
->ForceUpdate();
579 void DrawViewShell::SetUIUnit(FieldUnit eUnit
)
581 ViewShell::SetUIUnit(eUnit
);
585 * Refresh TabControl on splitter change
588 IMPL_LINK( DrawViewShell
, TabSplitHdl
, TabBar
*, pTab
)
590 const long int nMax
= maViewSize
.Width() - maScrBarWH
.Width()
591 - maTabControl
.GetPosPixel().X() ;
593 Size aTabSize
= maTabControl
.GetSizePixel();
594 aTabSize
.Width() = std::min(pTab
->GetSplitSize(), (long)(nMax
-1));
596 maTabControl
.SetSizePixel(aTabSize
);
597 GetLayerTabControl()->SetSizePixel(aTabSize
);
599 Point aPos
= maTabControl
.GetPosPixel();
600 aPos
.X() += aTabSize
.Width();
602 Size
aScrSize(nMax
- aTabSize
.Width(), maScrBarWH
.Height());
603 mpHorizontalScrollBar
->SetPosSizePixel(aPos
, aScrSize
);
608 /// inherited from sd::ViewShell
609 SdPage
* DrawViewShell::getCurrentPage() const
611 const sal_Int32 nPageCount
= (meEditMode
== EM_PAGE
)?
612 GetDoc()->GetSdPageCount(mePageKind
):
613 GetDoc()->GetMasterSdPageCount(mePageKind
);
615 sal_Int32 nCurrentPage
= maTabControl
.GetCurPageId() - 1;
616 DBG_ASSERT( (nPageCount
>0) && (nCurrentPage
<nPageCount
), "sd::DrawViewShell::getCurrentPage(), illegal page index!" );
617 if( (nPageCount
< 0) || (nCurrentPage
>=nPageCount
) )
618 nCurrentPage
= 0; // play safe here
620 if (meEditMode
== EM_PAGE
)
622 return GetDoc()->GetSdPage((sal_uInt16
)nCurrentPage
, mePageKind
);
624 else // EM_MASTERPAGE
626 return GetDoc()->GetMasterSdPage((sal_uInt16
)nCurrentPage
, mePageKind
);
631 * Select new refreshed page, in case of a page order change (eg. by undo)
634 void DrawViewShell::ResetActualPage()
639 sal_uInt16 nCurrentPage
= maTabControl
.GetCurPageId() - 1;
640 sal_uInt16 nPageCount
= (meEditMode
== EM_PAGE
)?GetDoc()->GetSdPageCount(mePageKind
):GetDoc()->GetMasterSdPageCount(mePageKind
);
642 nCurrentPage
= std::min((sal_uInt16
)(nPageCount
- 1), nCurrentPage
);
646 if (meEditMode
== EM_PAGE
)
649 // Update for TabControl
650 maTabControl
.Clear();
652 SdPage
* pPage
= NULL
;
655 for (sal_uInt16 i
= 0; i
< nPageCount
; i
++)
657 pPage
= GetDoc()->GetSdPage(i
, mePageKind
);
658 aPageName
= pPage
->GetName();
659 maTabControl
.InsertPage(i
+ 1, aPageName
);
661 // correct selection recognition of the pages
662 GetDoc()->SetSelected(pPage
, i
== nCurrentPage
);
665 maTabControl
.SetCurPageId(nCurrentPage
+ 1);
667 else // EM_MASTERPAGE
669 SdPage
* pActualPage
= GetDoc()->GetMasterSdPage(nCurrentPage
, mePageKind
);
670 maTabControl
.Clear();
671 sal_uInt16 nActualMasterPageNum
= 0;
673 sal_uInt16 nMasterPageCnt
= GetDoc()->GetMasterSdPageCount(mePageKind
);
674 for (sal_uInt16 i
= 0; i
< nMasterPageCnt
; i
++)
676 SdPage
* pMaster
= GetDoc()->GetMasterSdPage(i
, mePageKind
);
677 String
aLayoutName(pMaster
->GetLayoutName());
678 aLayoutName
.Erase(aLayoutName
.SearchAscii(SD_LT_SEPARATOR
));
679 maTabControl
.InsertPage(i
+ 1, aLayoutName
);
681 if (pActualPage
== pMaster
)
682 nActualMasterPageNum
= i
;
685 maTabControl
.SetCurPageId(nActualMasterPageNum
+ 1);
686 SwitchPage(nActualMasterPageNum
);
689 GetViewFrame()->GetDispatcher()->Execute(SID_SWITCHPAGE
,
690 SFX_CALLMODE_ASYNCHRON
| SFX_CALLMODE_RECORD
);
694 * Apply "Verb" on OLE-object.
697 ErrCode
DrawViewShell::DoVerb(long nVerb
)
699 if ( mpDrawView
->AreObjectsMarked() )
701 const SdrMarkList
& rMarkList
= mpDrawView
->GetMarkedObjectList();
703 if (rMarkList
.GetMarkCount() == 1)
705 SdrMark
* pMark
= rMarkList
.GetMark(0);
706 SdrObject
* pObj
= pMark
->GetMarkedSdrObj();
708 sal_uInt32 nInv
= pObj
->GetObjInventor();
709 sal_uInt16 nSdrObjKind
= pObj
->GetObjIdentifier();
711 if (nInv
== SdrInventor
&& nSdrObjKind
== OBJ_OLE2
)
713 ActivateObject( (SdrOle2Obj
*) pObj
, nVerb
);
723 * Activate OLE-object
726 sal_Bool
DrawViewShell::ActivateObject(SdrOle2Obj
* pObj
, long nVerb
)
728 sal_Bool bActivated
= sal_False
;
730 if ( !GetDocSh()->IsUIActive() )
732 ToolBarManager::UpdateLock
aLock (GetViewShellBase().GetToolBarManager());
734 bActivated
= ViewShell::ActivateObject(pObj
, nVerb
);
736 OSL_ASSERT(GetViewShell()!=NULL
);
737 Client
* pClient
= static_cast<Client
*>(GetViewShell()->GetIPClient());
739 pClient
->SetSdrGrafObj(NULL
);
746 * Switch to desired page.
747 * nSelectPage refers to the current EditMode
750 void LclResetFlag (bool& rbFlag
) {rbFlag
= false;}
752 sal_Bool
DrawViewShell::SwitchPage(sal_uInt16 nSelectedPage
)
754 /** Under some circumstances there are nested calls to SwitchPage() and
755 may crash the application (activation of form controls when the
756 shell of the edit view is not on top of the shell stack, see issue
757 83888 for details.) Therefore the nested calls are ignored (they
758 would jump to the wrong page anyway.)
760 if (mbIsInSwitchPage
)
762 mbIsInSwitchPage
= true;
763 comphelper::ScopeGuard
aGuard (::boost::bind(LclResetFlag
, ::boost::ref(mbIsInSwitchPage
)));
765 if (GetActiveWindow()->IsInPaint())
767 // Switching the current page while a Paint is being executed is
768 // dangerous. So, post it for later execution and return.
769 maAsynchronousSwitchPageCall
.Post(::boost::bind(
770 ::std::mem_fun(&DrawViewShell::SwitchPage
),
776 sal_Bool bOK
= sal_False
;
778 // With the current implementation of FuSlideShow there is a problem
779 // when it dsplays the show in a window: When the show is stopped it
780 // returns at one point in time SDRPAGE_NOTFOUND as current page index.
781 // Because FuSlideShow is currently being rewritten this bug is fixed
783 // This is not as bad a hack as it may look because making SwitchPage()
784 // more robust with respect to invalid page numbers is a good thing
786 if (nSelectedPage
== SDRPAGE_NOTFOUND
)
792 // Make sure that the given page index points to an existing page. Move
793 // the index into the valid range if necessary.
794 sal_uInt16 nPageCount
= (meEditMode
== EM_PAGE
)
795 ? GetDoc()->GetSdPageCount(mePageKind
)
796 : GetDoc()->GetMasterSdPageCount(mePageKind
);
797 if (nSelectedPage
>= nPageCount
)
798 nSelectedPage
= nPageCount
-1;
801 if (IsSwitchPageAllowed())
803 ModifyGuard
aGuard2( GetDoc() );
809 SdPage
* pNewPage
= NULL
;
811 if (meEditMode
== EM_MASTERPAGE
)
813 if( GetDoc()->GetMasterSdPageCount(mePageKind
) > nSelectedPage
)
814 pNewPage
= GetDoc()->GetMasterSdPage(nSelectedPage
, mePageKind
);
818 SdrPageView
* pPV
= mpDrawView
->GetSdrPageView();
819 OUString
sPageText(pNewPage
->GetLayoutName());
820 sal_Int32 nPos
= sPageText
.indexOf(SD_LT_SEPARATOR
);
822 sPageText
= sPageText
.copy(0, nPos
);
824 && pNewPage
== dynamic_cast< SdPage
* >( pPV
->GetPage() )
825 && sPageText
== maTabControl
.GetPageText(nSelectedPage
+1))
827 // this slide is already visible
834 OSL_ASSERT(mpFrameView
!=NULL
);
835 mpFrameView
->SetSelectedPage(nSelectedPage
);
837 if (GetDoc()->GetSdPageCount(mePageKind
) > nSelectedPage
)
838 pNewPage
= GetDoc()->GetSdPage(nSelectedPage
, mePageKind
);
840 if (mpActualPage
== pNewPage
)
842 SdrPageView
* pPV
= mpDrawView
->GetSdrPageView();
844 SdPage
* pCurrentPage
= dynamic_cast< SdPage
* >( pPV
->GetPage());
846 && pNewPage
== pCurrentPage
847 && maTabControl
.GetPageText(nSelectedPage
+1).equals(pNewPage
->GetName()))
849 // this slide is already visible
857 mpDrawView
->SdrEndTextEdit();
861 if (meEditMode
== EM_PAGE
)
863 mpActualPage
= GetDoc()->GetSdPage(nSelectedPage
, mePageKind
);
867 SdPage
* pMaster
= GetDoc()->GetMasterSdPage(nSelectedPage
, mePageKind
);
869 // does the selected page fit to the masterpage?
870 sal_uInt16 nPageCount
= GetDoc()->GetSdPageCount(mePageKind
);
871 for (sal_uInt16 i
= 0; i
< nPageCount
; i
++)
873 SdPage
* pPage
= GetDoc()->GetSdPage(i
, mePageKind
);
874 if(pPage
&& pPage
->IsSelected() && pMaster
== &(pPage
->TRG_GetMasterPage()))
876 mpActualPage
= pPage
;
883 // take the first page, that fits to the masterpage
884 for (sal_uInt16 i
= 0; i
< nPageCount
; i
++)
886 SdPage
* pPage
= GetDoc()->GetSdPage(i
, mePageKind
);
887 if(pPage
&& pMaster
== &(pPage
->TRG_GetMasterPage()))
889 mpActualPage
= pPage
;
896 for (sal_uInt16 i
= 0; i
< GetDoc()->GetSdPageCount(mePageKind
); i
++)
898 // deselect all pages
899 GetDoc()->SetSelected( GetDoc()->GetSdPage(i
, mePageKind
), sal_False
);
904 // as far as there is no mpActualPage, take the first
905 mpActualPage
= GetDoc()->GetSdPage(0, mePageKind
);
908 // also select this page (mpActualPage always points at a drawing page,
909 // never at a masterpage)
910 GetDoc()->SetSelected(mpActualPage
, sal_True
);
912 rtl::Reference
< sd::SlideShow
> xSlideshow( SlideShow::GetSlideShow( GetDoc() ) );
913 if( !xSlideshow
.is() || !xSlideshow
->isRunning() || ( xSlideshow
->getAnimationMode() != ANIMATIONMODE_SHOW
) )
915 // tighten VisArea, to possibly deactivate objects
916 // !!! only if we are not in presentation mode (#96279) !!!
917 OSL_ASSERT (GetViewShell()!=NULL
);
918 GetViewShell()->DisconnectAllClients();
919 VisAreaChanged(Rectangle(Point(), Size(1, 1)));
922 if (meEditMode
== EM_PAGE
)
924 /**********************************************************************
926 **********************************************************************/
927 GetDoc()->SetSelected(mpActualPage
, sal_True
);
929 SdrPageView
* pPageView
= mpDrawView
->GetSdrPageView();
933 mpFrameView
->SetVisibleLayers( pPageView
->GetVisibleLayers() );
934 mpFrameView
->SetPrintableLayers( pPageView
->GetPrintableLayers() );
935 mpFrameView
->SetLockedLayers( pPageView
->GetLockedLayers() );
937 if (mePageKind
== PK_NOTES
)
939 mpFrameView
->SetNotesHelpLines( pPageView
->GetHelpLines() );
941 else if (mePageKind
== PK_HANDOUT
)
943 mpFrameView
->SetHandoutHelpLines( pPageView
->GetHelpLines() );
947 mpFrameView
->SetStandardHelpLines( pPageView
->GetHelpLines() );
951 mpDrawView
->HideSdrPage();
952 mpDrawView
->ShowSdrPage(mpActualPage
);
953 GetViewShellBase().GetDrawController().FireSwitchCurrentPage(mpActualPage
);
955 SdrPageView
* pNewPageView
= mpDrawView
->GetSdrPageView();
959 pNewPageView
->SetVisibleLayers( mpFrameView
->GetVisibleLayers() );
960 pNewPageView
->SetPrintableLayers( mpFrameView
->GetPrintableLayers() );
961 pNewPageView
->SetLockedLayers( mpFrameView
->GetLockedLayers() );
963 if (mePageKind
== PK_NOTES
)
965 pNewPageView
->SetHelpLines( mpFrameView
->GetNotesHelpLines() );
967 else if (mePageKind
== PK_HANDOUT
)
969 pNewPageView
->SetHelpLines( mpFrameView
->GetHandoutHelpLines() );
973 pNewPageView
->SetHelpLines( mpFrameView
->GetStandardHelpLines() );
977 maTabControl
.SetCurPageId(nSelectedPage
+1);
978 OUString aPageName
= mpActualPage
->GetName();
980 if (maTabControl
.GetPageText(nSelectedPage
+1) != aPageName
)
982 maTabControl
.SetPageText(nSelectedPage
+1, aPageName
);
987 /**********************************************************************
989 **********************************************************************/
990 SdrPageView
* pPageView
= mpDrawView
->GetSdrPageView();
994 mpFrameView
->SetVisibleLayers( pPageView
->GetVisibleLayers() );
995 mpFrameView
->SetPrintableLayers( pPageView
->GetPrintableLayers() );
996 mpFrameView
->SetLockedLayers( pPageView
->GetLockedLayers() );
998 if (mePageKind
== PK_NOTES
)
1000 mpFrameView
->SetNotesHelpLines( pPageView
->GetHelpLines() );
1002 else if (mePageKind
== PK_HANDOUT
)
1004 mpFrameView
->SetHandoutHelpLines( pPageView
->GetHelpLines() );
1008 mpFrameView
->SetStandardHelpLines( pPageView
->GetHelpLines() );
1012 mpDrawView
->HideSdrPage();
1014 SdPage
* pMaster
= GetDoc()->GetMasterSdPage(nSelectedPage
, mePageKind
);
1016 if( !pMaster
) // if this page should not exist
1017 pMaster
= GetDoc()->GetMasterSdPage(0, mePageKind
);
1019 sal_uInt16 nNum
= pMaster
->GetPageNum();
1020 mpDrawView
->ShowSdrPage(mpDrawView
->GetModel()->GetMasterPage(nNum
));
1022 GetViewShellBase().GetDrawController().FireSwitchCurrentPage(pMaster
);
1024 SdrPageView
* pNewPageView
= mpDrawView
->GetSdrPageView();
1028 pNewPageView
->SetVisibleLayers( mpFrameView
->GetVisibleLayers() );
1029 pNewPageView
->SetPrintableLayers( mpFrameView
->GetPrintableLayers() );
1030 pNewPageView
->SetLockedLayers( mpFrameView
->GetLockedLayers() );
1032 if (mePageKind
== PK_NOTES
)
1034 pNewPageView
->SetHelpLines( mpFrameView
->GetNotesHelpLines() );
1036 else if (mePageKind
== PK_HANDOUT
)
1038 pNewPageView
->SetHelpLines( mpFrameView
->GetHandoutHelpLines() );
1042 pNewPageView
->SetHelpLines( mpFrameView
->GetStandardHelpLines() );
1046 OUString
aLayoutName(pMaster
->GetLayoutName());
1047 sal_Int32 nPos
= aLayoutName
.indexOf(SD_LT_SEPARATOR
);
1049 aLayoutName
= aLayoutName
.copy(0, nPos
);
1051 maTabControl
.SetCurPageId(nSelectedPage
+1);
1053 if (maTabControl
.GetPageText(nSelectedPage
+1) != aLayoutName
)
1055 maTabControl
.SetPageText(nSelectedPage
+1, aLayoutName
);
1058 if( mePageKind
== PK_HANDOUT
)
1060 // set pages for all available handout presentation objects
1061 sd::ShapeList
& rShapeList
= pMaster
->GetPresentationShapeList();
1062 SdrObject
* pObj
= 0;
1064 while( (pObj
= rShapeList
.getNextShape(pObj
)) != 0 )
1066 if( pMaster
->GetPresObjKind(pObj
) == PRESOBJ_HANDOUT
)
1068 // #i105146# We want no content to be displayed for PK_HANDOUT,
1069 // so just never set a page as content
1070 static_cast<SdrPageObj
*>(pObj
)->SetReferencedPage(0);
1076 Size aVisSizePixel
= GetActiveWindow()->GetOutputSizePixel();
1077 Rectangle aVisAreaWin
= GetActiveWindow()->PixelToLogic( Rectangle( Point(0,0), aVisSizePixel
) );
1078 VisAreaChanged(aVisAreaWin
);
1079 mpDrawView
->VisAreaChanged(GetActiveWindow());
1081 // so navigator (and effect window) notice that
1082 SfxBindings
& rBindings
= GetViewFrame()->GetBindings();
1083 rBindings
.Invalidate(SID_NAVIGATOR_PAGENAME
, sal_True
, sal_False
);
1084 rBindings
.Invalidate(SID_STATUS_PAGE
, sal_True
, sal_False
);
1085 rBindings
.Invalidate(SID_DELETE_MASTER_PAGE
, sal_True
, sal_False
);
1086 rBindings
.Invalidate(SID_DELETE_PAGE
, sal_True
, sal_False
);
1087 rBindings
.Invalidate(SID_ASSIGN_LAYOUT
,sal_True
,sal_False
);
1088 rBindings
.Invalidate(SID_INSERTPAGE
,sal_True
,sal_False
);
1089 UpdatePreview( mpActualPage
);
1091 mpDrawView
->AdjustMarkHdl();
1099 * Check if page change is allowed
1102 sal_Bool
DrawViewShell::IsSwitchPageAllowed() const
1106 FmFormShell
* pFormShell
= GetViewShellBase().GetFormShellManager()->GetFormShell();
1107 if (pFormShell
!=NULL
&& !pFormShell
->PrepareClose (sal_False
))
1114 * Select new refreshed page, in case of a page order change (eg. by undo)
1117 void DrawViewShell::ResetActualLayer()
1119 LayerTabBar
* pLayerBar
= GetLayerTabControl();
1120 if (pLayerBar
!= NULL
)
1122 // remember old layer cound and current layer id
1123 // this is needed when one layer is renamed to
1124 // restore current layer
1125 sal_uInt16 nOldLayerCnt
= pLayerBar
->GetPageCount();
1126 sal_uInt16 nOldLayerId
= pLayerBar
->GetCurPageId();
1129 * Update for LayerTab
1134 String aActiveLayer
= mpDrawView
->GetActiveLayer();
1135 String
aBackgroundLayer( SdResId(STR_LAYER_BCKGRND
) );
1136 String
aBackgroundObjLayer( SdResId(STR_LAYER_BCKGRNDOBJ
) );
1137 String
aLayoutLayer( SdResId(STR_LAYER_LAYOUT
) );
1138 String
aControlsLayer( SdResId(STR_LAYER_CONTROLS
) );
1139 String
aMeasureLinesLayer( SdResId(STR_LAYER_MEASURELINES
) );
1140 sal_uInt16 nActiveLayer
= SDRLAYER_NOTFOUND
;
1141 SdrLayerAdmin
& rLayerAdmin
= GetDoc()->GetLayerAdmin();
1142 sal_uInt16 nLayerCnt
= rLayerAdmin
.GetLayerCount();
1144 for ( sal_uInt16 nLayer
= 0; nLayer
< nLayerCnt
; nLayer
++ )
1146 aName
= rLayerAdmin
.GetLayer(nLayer
)->GetName();
1148 if ( aName
== aActiveLayer
)
1150 nActiveLayer
= nLayer
;
1153 if ( aName
!= aBackgroundLayer
)
1155 if (meEditMode
== EM_MASTERPAGE
)
1157 // don't show page layer onto the masterpage
1158 if (aName
!= aLayoutLayer
&&
1159 aName
!= aControlsLayer
&&
1160 aName
!= aMeasureLinesLayer
)
1162 pLayerBar
->InsertPage(nLayer
+1, aName
);
1164 TabBarPageBits nBits
= 0;
1165 SdrPageView
* pPV
= mpDrawView
->GetSdrPageView();
1167 if (pPV
&& !pPV
->IsLayerVisible(aName
))
1169 // invisible layers are displayed differently
1170 nBits
= TPB_SPECIAL
;
1173 pLayerBar
->SetPageBits(nLayer
+1, nBits
);
1178 // don't show masterpage layer onto the page
1179 if ( aName
!= aBackgroundObjLayer
)
1181 pLayerBar
->InsertPage(nLayer
+1, aName
);
1183 TabBarPageBits nBits
= 0;
1185 if (!mpDrawView
->GetSdrPageView()->IsLayerVisible(aName
))
1187 // invisible layers are displayed differently
1188 nBits
= TPB_SPECIAL
;
1191 pLayerBar
->SetPageBits(nLayer
+1, nBits
);
1197 if ( nActiveLayer
== SDRLAYER_NOTFOUND
)
1199 if( nOldLayerCnt
== pLayerBar
->GetPageCount() )
1201 nActiveLayer
= nOldLayerId
- 1;
1205 nActiveLayer
= ( meEditMode
== EM_MASTERPAGE
) ? 2 : 0;
1208 mpDrawView
->SetActiveLayer( pLayerBar
->GetPageText(nActiveLayer
+ 1) );
1211 pLayerBar
->SetCurPageId(nActiveLayer
+ 1);
1212 GetViewFrame()->GetBindings().Invalidate( SID_MODIFYLAYER
);
1213 GetViewFrame()->GetBindings().Invalidate( SID_DELETE_LAYER
);
1218 * Execute a delayed close
1221 IMPL_LINK( DrawViewShell
, CloseHdl
, Timer
*, pTimer
)
1224 GetViewFrame()->GetBindings().Execute( SID_CLOSEWIN
);
1232 sal_Int8
DrawViewShell::AcceptDrop (
1233 const AcceptDropEvent
& rEvt
,
1234 DropTargetHelper
& rTargetHelper
,
1235 ::sd::Window
* pTargetWindow
,
1239 if( nPage
!= SDRPAGE_NOTFOUND
)
1240 nPage
= GetDoc()->GetSdPage( nPage
, mePageKind
)->GetPageNum();
1242 if( SlideShow::IsRunning( GetViewShellBase() ) )
1243 return DND_ACTION_NONE
;
1245 return mpDrawView
->AcceptDrop( rEvt
, rTargetHelper
, pTargetWindow
, nPage
, nLayer
);
1252 sal_Int8
DrawViewShell::ExecuteDrop (
1253 const ExecuteDropEvent
& rEvt
,
1254 DropTargetHelper
& rTargetHelper
,
1255 ::sd::Window
* pTargetWindow
,
1259 if( nPage
!= SDRPAGE_NOTFOUND
)
1260 nPage
= GetDoc()->GetSdPage( nPage
, mePageKind
)->GetPageNum();
1262 if( SlideShow::IsRunning( GetViewShellBase() ) )
1263 return DND_ACTION_NONE
;
1265 Broadcast(ViewShellHint(ViewShellHint::HINT_COMPLEX_MODEL_CHANGE_START
));
1266 sal_Int8
nResult (mpDrawView
->ExecuteDrop( rEvt
, rTargetHelper
, pTargetWindow
, nPage
, nLayer
));
1267 Broadcast(ViewShellHint(ViewShellHint::HINT_COMPLEX_MODEL_CHANGE_END
));
1272 } // end of namespace sd
1274 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */