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 <comphelper/processfactory.hxx>
22 #include <com/sun/star/frame/UnknownModuleException.hpp>
23 #include <com/sun/star/frame/ModuleManager.hpp>
24 #include <com/sun/star/container/XNameAccess.hpp>
25 #include <com/sun/star/beans/PropertyValue.hpp>
26 #include <com/sun/star/frame/theUICommandDescription.hpp>
28 #include "ViewShellBase.hxx"
30 #include "EventMultiplexer.hxx"
31 #include "cache/SlsPageCacheManager.hxx"
32 #include "sdresid.hxx"
34 #include "strings.hrc"
36 #include "unokywds.hxx"
37 #include <svx/svxids.hrc>
38 #include "DrawDocShell.hxx"
39 #include <sfx2/app.hxx>
40 #include "PaneChildWindows.hxx"
41 #include "ViewShellManager.hxx"
42 #include "DrawController.hxx"
43 #include "FrameView.hxx"
44 #include "ViewTabBar.hxx"
45 #include <sfx2/event.hxx>
46 #include "drawdoc.hxx"
47 #include <sfx2/dispatch.hxx>
48 #include <sfx2/request.hxx>
49 #include <sfx2/printer.hxx>
50 #include "DrawViewShell.hxx"
51 #include "GraphicViewShell.hxx"
52 #include "OutlineViewShell.hxx"
53 #include "SlideSorterViewShell.hxx"
54 #include "PresentationViewShell.hxx"
55 #include "FormShellManager.hxx"
56 #include "ToolBarManager.hxx"
57 #include "SidebarPanelId.hxx"
59 #include "framework/ConfigurationController.hxx"
60 #include "DocumentRenderer.hxx"
62 #include <com/sun/star/frame/XFrame.hpp>
63 #include <com/sun/star/awt/XWindow.hpp>
64 #include <com/sun/star/frame/XController.hpp>
65 #include <com/sun/star/frame/XModel.hpp>
66 #include <com/sun/star/document/XViewDataSupplier.hpp>
67 #include <com/sun/star/container/XIndexAccess.hpp>
68 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
69 #include <com/sun/star/drawing/XMasterPagesSupplier.hpp>
70 #include <com/sun/star/drawing/framework/XControllerManager.hpp>
71 #include <com/sun/star/drawing/framework/XConfigurationController.hpp>
72 #include <com/sun/star/drawing/framework/ResourceId.hpp>
73 #include "framework/FrameworkHelper.hxx"
75 #include <rtl/ref.hxx>
76 #include <sfx2/msg.hxx>
77 #include <sfx2/objface.hxx>
78 #include <sfx2/viewfrm.hxx>
79 #include <svl/whiter.hxx>
80 #include <vcl/msgbox.hxx>
81 #include <vcl/settings.hxx>
83 #include <tools/diagnose_ex.h>
85 #include "fubullet.hxx"
89 #include "sdslots.hxx"
91 using ::sd::framework::FrameworkHelper
;
92 using namespace com::sun::star::uno
;
93 using namespace com::sun::star::frame
;
94 using namespace com::sun::star::container
;
95 using namespace com::sun::star::lang
;
96 using namespace com::sun::star::beans
;
100 class CurrentPageSetter
103 CurrentPageSetter (ViewShellBase
& rBase
);
104 void operator () (bool);
106 ViewShellBase
& mrBase
;
109 } // end of anonymous namespace
111 using namespace ::com::sun::star
;
112 using namespace ::com::sun::star::uno
;
113 using namespace ::com::sun::star::drawing::framework
;
114 using ::sd::framework::FrameworkHelper
;
118 class ViewShellBase::Implementation
121 /** Main controller of the view shell. During the switching from one
122 stacked shell to another this pointer may be NULL.
124 ::rtl::Reference
<DrawController
> mpController
;
126 /** The view tab bar is the control for switching between different
129 ::rtl::Reference
<ViewTabBar
> mpViewTabBar
;
131 // contains the complete area of the current view relative to the frame window
132 Rectangle maClientArea
;
134 // This is set to true when PrepareClose() is called.
137 /** The view window is the parent of all UI elements that belong to the
138 view or ViewShell. This comprises the rulers, the scroll bars, and
140 It does not include the ViewTabBar.
142 VclPtr
<vcl::Window
> mpViewWindow
;
143 ::boost::shared_ptr
<ToolBarManager
> mpToolBarManager
;
144 ::boost::shared_ptr
<ViewShellManager
> mpViewShellManager
;
145 ::boost::shared_ptr
<tools::EventMultiplexer
> mpEventMultiplexer
;
146 ::boost::shared_ptr
<FormShellManager
> mpFormShellManager
;
148 Implementation (ViewShellBase
& rBase
);
153 /** Show or hide the ViewTabBar.
155 When <TRUE/> then the ViewTabBar is shown, otherwise it is hidden.
157 void ShowViewTabBar (bool bShow
);
159 /** Common code of ViewShellBase::OuterResizePixel() and
160 ViewShellBase::InnerResizePixel().
163 const Point
& rOrigin
,
167 /** Show or hide the specified pane. The visibility state is taken
168 fromthe given request.
170 The request determines the new visibility state. The state can
171 either be toggled or be set to a given value.
173 This URL specifies the pane whose visibility state to set.
175 When the pane becomes visible then this view URL specifies which
176 type of view to show in it.
178 void SetPaneVisibility (
179 const SfxRequest
& rRequest
,
180 const OUString
& rsPaneURL
,
181 const OUString
& rsViewURL
);
183 void GetSlotState (SfxItemSet
& rSet
);
185 void ProcessRestoreEditingViewSlot();
188 ViewShellBase
& mrBase
;
190 /** Hold a reference to the page cache manager of the slide sorter in
191 order to ensure that it stays alive while the ViewShellBase is
194 ::boost::shared_ptr
<slidesorter::cache::PageCacheManager
> mpPageCacheManager
;
198 /** The only task of this window is to forward key presses to the content
199 window of the main view shell. With the key press it forwards the focus
200 so that it is not called very often.
202 class FocusForwardingWindow
: public vcl::Window
205 FocusForwardingWindow (vcl::Window
& rParentWindow
, ViewShellBase
& rBase
);
206 virtual ~FocusForwardingWindow();
207 virtual void dispose() SAL_OVERRIDE
;
208 virtual void KeyInput (const KeyEvent
& rEvent
) SAL_OVERRIDE
;
209 virtual void Command (const CommandEvent
& rEvent
) SAL_OVERRIDE
;
212 ViewShellBase
& mrBase
;
214 } // end of anonymous namespace
216 //===== ViewShellBase =========================================================
218 TYPEINIT1(ViewShellBase
, SfxViewShell
);
220 // We have to expand the SFX_IMPL_VIEWFACTORY macro to call LateInit() after a
221 // new ViewShellBase object has been constructed.
223 SfxViewFactory
* ViewShellBase::pFactory
;
225 SFX_IMPL_SUPERCLASS_INTERFACE(ViewShellBase
, SfxViewShell
)
227 void ViewShellBase::InitInterface_Impl()
231 ViewShellBase::ViewShellBase (
232 SfxViewFrame
* _pFrame
,
234 : SfxViewShell (_pFrame
,
235 SfxViewShellFlags::CAN_PRINT
236 | SfxViewShellFlags::HAS_PRINTOPTIONS
),
242 mpImpl
.reset(new Implementation(*this));
243 mpImpl
->mpViewWindow
= VclPtr
<FocusForwardingWindow
>::Create(_pFrame
->GetWindow(),*this);
244 mpImpl
->mpViewWindow
->SetBackground(Wallpaper());
246 _pFrame
->GetWindow().SetBackground(Application::GetSettings().GetStyleSettings().GetLightColor());
248 // Set up the members in the correct order.
249 if (GetViewFrame()->GetObjectShell()->ISA(DrawDocShell
))
250 mpDocShell
= static_cast<DrawDocShell
*>(
251 GetViewFrame()->GetObjectShell());
252 if (mpDocShell
!= NULL
)
253 mpDocument
= mpDocShell
->GetDoc();
254 mpImpl
->mpViewShellManager
.reset(new ViewShellManager(*this));
256 SetWindow(mpImpl
->mpViewWindow
.get());
258 // Hide the window to avoid complaints from Sfx...SwitchViewShell...
259 _pFrame
->GetWindow().Hide();
262 /** In this destructor the order in which some of the members are destroyed
263 (and/or being prepared to being destroyed) is important. Change it only
264 when you know what you are doing.
266 ViewShellBase::~ViewShellBase()
268 // Tell the controller that the ViewShellBase is not available anymore.
269 if (mpImpl
->mpController
.get() != NULL
)
270 mpImpl
->mpController
->ReleaseViewShellBase();
272 // We have to hide the main window to prevent SFX complaining after a
273 // reload about it being already visible.
274 ViewShell
* pShell
= GetMainViewShell().get();
276 && pShell
->GetActiveWindow()!=NULL
277 && pShell
->GetActiveWindow()->GetParent()!=NULL
)
279 pShell
->GetActiveWindow()->GetParent()->Hide();
282 mpImpl
->mpToolBarManager
->Shutdown();
283 mpImpl
->mpViewShellManager
->Shutdown();
285 EndListening(*GetViewFrame());
286 EndListening(*GetDocShell());
291 void ViewShellBase::LateInit (const OUString
& rsDefaultView
)
293 StartListening(*GetViewFrame(),true);
294 StartListening(*GetDocShell(),true);
296 InitializeFramework();
298 mpImpl
->mpEventMultiplexer
.reset(new tools::EventMultiplexer (*this));
300 mpImpl
->mpFormShellManager
.reset(new FormShellManager(*this));
302 mpImpl
->mpToolBarManager
= ToolBarManager::Create(
304 mpImpl
->mpEventMultiplexer
,
305 mpImpl
->mpViewShellManager
);
309 Reference
<XControllerManager
> xControllerManager (GetDrawController(), UNO_QUERY_THROW
);
310 Reference
<XConfigurationController
> xConfigurationController (
311 xControllerManager
->getConfigurationController());
312 if (xConfigurationController
.is())
314 OUString
sView (rsDefaultView
);
316 sView
= GetInitialViewShellType();
318 ::boost::shared_ptr
<FrameworkHelper
> pHelper (FrameworkHelper::Instance(*this));
320 // Create the resource ids for the center pane and view.
321 const Reference
<drawing::framework::XResourceId
> xCenterPaneId (
322 FrameworkHelper::CreateResourceId(FrameworkHelper::msCenterPaneURL
));
323 const Reference
<drawing::framework::XResourceId
> xCenterViewId (
324 FrameworkHelper::CreateResourceId(sView
, xCenterPaneId
));
326 // Request center pane and view.
327 xConfigurationController
->requestResourceActivation(xCenterPaneId
, ResourceActivationMode_ADD
);
328 xConfigurationController
->requestResourceActivation(xCenterViewId
, ResourceActivationMode_REPLACE
);
330 // Process configuration events synchronously until the center view
332 sd::framework::ConfigurationController
* pConfigurationController
333 = dynamic_cast<sd::framework::ConfigurationController
*>(xConfigurationController
.get());
334 if (pConfigurationController
!= NULL
)
337 ! pConfigurationController
->getResource(xCenterViewId
).is()
338 && pConfigurationController
->hasPendingRequests())
340 pConfigurationController
->ProcessEvent();
345 catch (const RuntimeException
&)
349 // AutoLayouts have to be ready.
350 GetDocument()->StopWorkStartupDelay();
354 // Remember the type of the current main view shell in the frame view.
355 ViewShell
* pViewShell
= GetMainViewShell().get();
356 if (pViewShell
!= NULL
)
358 FrameView
* pFrameView
= pViewShell
->GetFrameView();
359 if (pFrameView
!= NULL
)
360 pFrameView
->SetViewShellTypeOnLoad(pViewShell
->GetShellType());
364 ::boost::shared_ptr
<ViewShellManager
> ViewShellBase::GetViewShellManager() const
366 return mpImpl
->mpViewShellManager
;
369 ::boost::shared_ptr
<ViewShell
> ViewShellBase::GetMainViewShell() const
371 ::boost::shared_ptr
<ViewShell
> pMainViewShell (
372 framework::FrameworkHelper::Instance(*const_cast<ViewShellBase
*>(this))
373 ->GetViewShell(framework::FrameworkHelper::msCenterPaneURL
));
374 if (pMainViewShell
.get() == NULL
)
375 pMainViewShell
= framework::FrameworkHelper::Instance(*const_cast<ViewShellBase
*>(this))
376 ->GetViewShell(framework::FrameworkHelper::msFullScreenPaneURL
);
377 return pMainViewShell
;
380 ViewShellBase
* ViewShellBase::GetViewShellBase (SfxViewFrame
* pViewFrame
)
382 ViewShellBase
* pBase
= NULL
;
384 if (pViewFrame
!= NULL
)
386 // Get the view shell for the frame and cast it to
387 // sd::ViewShellBase.
388 SfxViewShell
* pSfxViewShell
= pViewFrame
->GetViewShell();
389 if (pSfxViewShell
!=NULL
&& pSfxViewShell
->ISA(::sd::ViewShellBase
))
390 pBase
= static_cast<ViewShellBase
*>(pSfxViewShell
);
396 void ViewShellBase::Notify(SfxBroadcaster
& rBC
, const SfxHint
& rHint
)
398 SfxViewShell::Notify(rBC
, rHint
);
400 const SfxEventHint
* pEventHint
= dynamic_cast<const SfxEventHint
*>(&rHint
);
403 switch (pEventHint
->GetEventId())
405 case SFX_EVENT_OPENDOC
:
406 if( GetDocument() && GetDocument()->IsStartWithPresentation() )
410 GetViewFrame()->GetDispatcher()->Execute(
411 SID_PRESENTATION
, SfxCallMode::ASYNCHRON
);
422 void ViewShellBase::InitializeFramework()
426 OUString
ViewShellBase::GetSelectionText(bool bCompleteWords
)
428 ::boost::shared_ptr
<ViewShell
> const pMainShell(GetMainViewShell());
429 DrawViewShell
*const pDrawViewShell(
430 dynamic_cast<DrawViewShell
*>(pMainShell
.get()));
431 return (pDrawViewShell
)
432 ? pDrawViewShell
->GetSelectionText(bCompleteWords
)
433 : SfxViewShell::GetSelectionText(bCompleteWords
);
436 bool ViewShellBase::HasSelection(bool bText
) const
438 ::boost::shared_ptr
<ViewShell
> const pMainShell(GetMainViewShell());
439 DrawViewShell
*const pDrawViewShell(
440 dynamic_cast<DrawViewShell
*>(pMainShell
.get()));
441 return (pDrawViewShell
)
442 ? pDrawViewShell
->HasSelection(bText
)
443 : SfxViewShell::HasSelection(bText
);
446 void ViewShellBase::InnerResizePixel (const Point
& rOrigin
, const Size
&rSize
)
448 Size aObjSize
= GetObjectShell()->GetVisArea().GetSize();
449 if ( aObjSize
.Width() > 0 && aObjSize
.Height() > 0 )
451 SvBorder
aBorder( GetBorderPixel() );
453 aSize
.Width() -= (aBorder
.Left() + aBorder
.Right());
454 aSize
.Height() -= (aBorder
.Top() + aBorder
.Bottom());
455 Size aObjSizePixel
= mpImpl
->mpViewWindow
->LogicToPixel( aObjSize
, MAP_100TH_MM
);
456 SfxViewShell::SetZoomFactor(
457 Fraction( aSize
.Width(), std::max( aObjSizePixel
.Width(), (long int)1 ) ),
458 Fraction( aSize
.Height(), std::max( aObjSizePixel
.Height(), (long int)1) ) );
461 mpImpl
->ResizePixel(rOrigin
, rSize
, false);
464 void ViewShellBase::OuterResizePixel (const Point
& rOrigin
, const Size
&rSize
)
466 mpImpl
->ResizePixel (rOrigin
, rSize
, true);
469 void ViewShellBase::Rearrange()
471 OSL_ASSERT(GetViewFrame()!=NULL
);
473 // There is a bug in the communication between embedded objects and the
474 // framework::LayoutManager that leads to missing resize updates. The
475 // following workaround enforces such an update by cycling the border to
476 // zero and back to the current value.
477 if (GetWindow() != NULL
)
479 SetBorderPixel(SvBorder());
484 OSL_TRACE("Rearrange: window missing");
487 GetViewFrame()->Resize(true);
490 ErrCode
ViewShellBase::DoVerb (long nVerb
)
492 ErrCode aResult
= ERRCODE_NONE
;
494 ::sd::ViewShell
* pShell
= GetMainViewShell().get();
496 aResult
= pShell
->DoVerb (nVerb
);
501 Reference
<view::XRenderable
> ViewShellBase::GetRenderable()
503 // Create a new DocumentRenderer on every call. It observes the life
504 // time of this ViewShellBase object.
505 return Reference
<view::XRenderable
>(new DocumentRenderer(*this));
508 SfxPrinter
* ViewShellBase::GetPrinter (bool bCreate
)
510 OSL_ASSERT(mpImpl
.get()!=NULL
);
512 return GetDocShell()->GetPrinter (bCreate
);
515 sal_uInt16
ViewShellBase::SetPrinter (
516 SfxPrinter
* pNewPrinter
,
517 SfxPrinterChangeFlags nDiffFlags
,
520 OSL_ASSERT(mpImpl
.get()!=NULL
);
522 GetDocShell()->SetPrinter(pNewPrinter
);
524 if ( (nDiffFlags
& SfxPrinterChangeFlags::CHG_ORIENTATION
||
525 nDiffFlags
& SfxPrinterChangeFlags::CHG_SIZE
) && pNewPrinter
)
527 MapMode aMap
= pNewPrinter
->GetMapMode();
528 aMap
.SetMapUnit(MAP_100TH_MM
);
529 MapMode aOldMap
= pNewPrinter
->GetMapMode();
530 pNewPrinter
->SetMapMode(aMap
);
531 Size aNewSize
= pNewPrinter
->GetOutputSize();
533 bool bScaleAll
= false;
536 ScopedVclPtrInstance
<WarningBox
> aWarnBox (
538 (WinBits
)(WB_YES_NO
| WB_DEF_YES
),
539 SD_RESSTR(STR_SCALE_OBJS_TO_PAGE
));
540 bScaleAll
= (aWarnBox
->Execute() == RET_YES
);
543 ::boost::shared_ptr
<DrawViewShell
> pDrawViewShell (
544 ::boost::dynamic_pointer_cast
<DrawViewShell
>(GetMainViewShell()));
547 SdPage
* pPage
= GetDocument()->GetSdPage(
549 pDrawViewShell
->SetPageSizeAndBorder (
550 pDrawViewShell
->GetPageKind(),
554 pNewPrinter
->GetOrientation(),
555 pPage
->GetPaperBin(),
556 pPage
->IsBackgroundFullSize());
559 pNewPrinter
->SetMapMode(aOldMap
);
565 void ViewShellBase::UIActivating( SfxInPlaceClient
* pClient
)
567 mpImpl
->ShowViewTabBar(false);
569 ViewShell
* pViewShell
= GetMainViewShell().get();
571 pViewShell
->UIActivating( pClient
);
573 SfxViewShell::UIActivating( pClient
);
576 void ViewShellBase::UIDeactivated( SfxInPlaceClient
* pClient
)
578 SfxViewShell::UIDeactivated( pClient
);
580 mpImpl
->ShowViewTabBar(true);
582 ViewShell
* pViewShell
= GetMainViewShell().get();
584 pViewShell
->UIDeactivated( pClient
);
587 SvBorder
ViewShellBase::GetBorder (bool )
590 if (mpImpl
->mpViewTabBar
.is() && mpImpl
->mpViewTabBar
->GetTabControl()->IsVisible())
591 nTop
= mpImpl
->mpViewTabBar
->GetHeight();
592 return SvBorder(0,nTop
,0,0);
595 void ViewShellBase::Execute (SfxRequest
& rRequest
)
597 sal_uInt16 nSlotId
= rRequest
.GetSlot();
601 case SID_SWITCH_SHELL
:
603 Reference
<XControllerManager
> xControllerManager (GetController(), UNO_QUERY
);
604 if (xControllerManager
.is())
606 Reference
<XConfigurationController
> xConfigurationController (
607 xControllerManager
->getConfigurationController());
608 if (xConfigurationController
.is())
609 xConfigurationController
->update();
614 case SID_LEFT_PANE_DRAW
:
615 mpImpl
->SetPaneVisibility(
617 framework::FrameworkHelper::msLeftDrawPaneURL
,
618 framework::FrameworkHelper::msSlideSorterURL
);
621 case SID_LEFT_PANE_IMPRESS
:
622 mpImpl
->SetPaneVisibility(
624 framework::FrameworkHelper::msLeftImpressPaneURL
,
625 framework::FrameworkHelper::msSlideSorterURL
);
628 case SID_NORMAL_MULTI_PANE_GUI
:
629 case SID_SLIDE_SORTER_MULTI_PANE_GUI
:
630 case SID_DRAWINGMODE
:
632 case SID_OUTLINEMODE
:
634 case SID_HANDOUTMODE
:
635 framework::FrameworkHelper::Instance(*this)->HandleModeChangeSlot(nSlotId
, rRequest
);
638 case SID_WIN_FULLSCREEN
:
639 // The full screen mode is not supported. Ignore the request.
642 case SID_RESTORE_EDITING_VIEW
:
643 mpImpl
->ProcessRestoreEditingViewSlot();
647 // Ignore any other slot.
653 void ViewShellBase::GetState (SfxItemSet
& rSet
)
655 mpImpl
->GetSlotState(rSet
);
657 FuBullet::GetSlotState( rSet
, 0, GetViewFrame() );
660 void ViewShellBase::WriteUserDataSequence (
661 ::com::sun::star::uno::Sequence
<
662 ::com::sun::star::beans::PropertyValue
>& rSequence
,
665 // Forward call to main sub shell.
666 ViewShell
* pShell
= GetMainViewShell().get();
668 pShell
->WriteUserDataSequence (rSequence
, bBrowse
);
671 void ViewShellBase::ReadUserDataSequence (
672 const ::com::sun::star::uno::Sequence
<
673 ::com::sun::star::beans::PropertyValue
>& rSequence
,
676 // Forward call to main sub shell.
677 ViewShell
* pShell
= GetMainViewShell().get();
680 pShell
->ReadUserDataSequence (rSequence
, bBrowse
);
682 // For certain shell types ReadUserDataSequence may have changed the
683 // type to another one. Make sure that the center pane shows the
685 switch (pShell
->GetShellType())
687 case ViewShell::ST_IMPRESS
:
688 case ViewShell::ST_NOTES
:
689 case ViewShell::ST_HANDOUT
:
692 switch (PTR_CAST(DrawViewShell
, pShell
)->GetPageKind())
696 sViewURL
= framework::FrameworkHelper::msImpressViewURL
;
699 sViewURL
= framework::FrameworkHelper::msNotesViewURL
;
702 sViewURL
= framework::FrameworkHelper::msHandoutViewURL
;
705 if (!sViewURL
.isEmpty())
706 framework::FrameworkHelper::Instance(*this)->RequestView(
708 framework::FrameworkHelper::msCenterPaneURL
);
718 void ViewShellBase::Activate (bool bIsMDIActivate
)
720 SfxViewShell::Activate(bIsMDIActivate
);
722 Reference
<XControllerManager
> xControllerManager (GetController(), UNO_QUERY
);
723 if (xControllerManager
.is())
725 Reference
<XConfigurationController
> xConfigurationController (
726 xControllerManager
->getConfigurationController());
727 if (xConfigurationController
.is())
728 xConfigurationController
->update();
730 GetToolBarManager()->RequestUpdate();
733 void ViewShellBase::Deactivate (bool bIsMDIActivate
)
735 SfxViewShell::Deactivate(bIsMDIActivate
);
738 void ViewShellBase::SetZoomFactor (
739 const Fraction
&rZoomX
,
740 const Fraction
&rZoomY
)
742 SfxViewShell::SetZoomFactor (rZoomX
, rZoomY
);
743 // Forward call to main sub shell.
744 ViewShell
* pShell
= GetMainViewShell().get();
746 pShell
->SetZoomFactor (rZoomX
, rZoomY
);
749 bool ViewShellBase::PrepareClose (bool bUI
)
751 bool nResult
= SfxViewShell::PrepareClose (bUI
);
755 mpImpl
->mbIsClosing
= true;
757 // Forward call to main sub shell.
758 ViewShell
* pShell
= GetMainViewShell().get();
760 nResult
= pShell
->PrepareClose (bUI
);
766 void ViewShellBase::WriteUserData (OUString
& rString
, bool bBrowse
)
768 SfxViewShell::WriteUserData (rString
, bBrowse
);
770 // Forward call to main sub shell.
771 ViewShell
* pShell
= GetMainViewShell().get();
773 pShell
->WriteUserData (rString
);
776 void ViewShellBase::ReadUserData (const OUString
& rString
, bool bBrowse
)
778 SfxViewShell::ReadUserData (rString
, bBrowse
);
780 // Forward call to main sub shell.
781 ViewShell
* pShell
= GetMainViewShell().get();
783 pShell
->ReadUserData (rString
);
786 SdrView
* ViewShellBase::GetDrawView() const
788 // Forward call to main sub shell.
789 ViewShell
* pShell
= GetMainViewShell().get();
791 return pShell
->GetDrawView ();
793 return SfxViewShell::GetDrawView();
796 void ViewShellBase::AdjustPosSizePixel (const Point
&rOfs
, const Size
&rSize
)
798 SfxViewShell::AdjustPosSizePixel (rOfs
, rSize
);
801 void ViewShellBase::SetBusyState (bool bBusy
)
803 if (GetDocShell() != NULL
)
804 GetDocShell()->SetWaitCursor (bBusy
);
807 void ViewShellBase::UpdateBorder ( bool bForce
/* = false */ )
809 // The following calls to SetBorderPixel() and InvalidateBorder() are
810 // made only for the main view shell. This not only avoids unnecessary
811 // calls for the views in side panes but prevents calling an already
812 // dying SfxViewShell base class.
813 // We have to check the existence of the window, too.
814 // The SfxViewFrame accesses the window without checking it.
815 ViewShell
* pMainViewShell
= GetMainViewShell().get();
816 if (pMainViewShell
!= NULL
&& GetWindow()!=NULL
)
818 SvBorder
aCurrentBorder (GetBorderPixel());
819 bool bOuterResize ( ! GetDocShell()->IsInPlaceActive());
820 SvBorder
aBorder (GetBorder(bOuterResize
));
821 aBorder
+= pMainViewShell
->GetBorder(bOuterResize
);
823 if (bForce
|| (aBorder
!= aCurrentBorder
))
825 SetBorderPixel (aBorder
);
831 void ViewShellBase::ShowUIControls (bool bVisible
)
833 if (mpImpl
->mpViewTabBar
.is())
834 mpImpl
->mpViewTabBar
->GetTabControl()->Show(bVisible
);
836 ViewShell
* pMainViewShell
= GetMainViewShell().get();
837 if (pMainViewShell
!= NULL
)
838 pMainViewShell
->ShowUIControls (bVisible
);
845 OUString
ViewShellBase::GetInitialViewShellType()
847 OUString
sRequestedView (FrameworkHelper::msImpressViewURL
);
851 Reference
<document::XViewDataSupplier
> xViewDataSupplier (
852 GetDocShell()->GetModel(), UNO_QUERY
);
853 if ( ! xViewDataSupplier
.is())
856 Reference
<container::XIndexAccess
> xViewData (xViewDataSupplier
->getViewData());
857 if ( ! xViewData
.is())
859 if (xViewData
->getCount() == 0)
863 ::com::sun::star::uno::Any aAny
= xViewData
->getByIndex(nView
);
864 Sequence
<beans::PropertyValue
> aProperties
;
865 if ( ! (aAny
>>= aProperties
))
868 // Search the properties for the one that tells us what page kind to
870 for (sal_Int32 n
=0; n
<aProperties
.getLength(); n
++)
872 const beans::PropertyValue
& rProperty (aProperties
[n
]);
873 if (rProperty
.Name
== sUNO_View_PageKind
)
875 sal_Int16 nPageKind
= 0;
876 rProperty
.Value
>>= nPageKind
;
877 switch ((PageKind
)nPageKind
)
880 sRequestedView
= FrameworkHelper::msImpressViewURL
;
884 sRequestedView
= FrameworkHelper::msHandoutViewURL
;
888 sRequestedView
= FrameworkHelper::msNotesViewURL
;
892 // The page kind is invalid. This is probably an
893 // error by the caller. We use the standard type to
894 // keep things going.
895 DBG_ASSERT(false, "ViewShellBase::GetInitialViewShellType: invalid page kind");
896 sRequestedView
= FrameworkHelper::msImpressViewURL
;
905 return sRequestedView
;
908 /** this method starts the presentation by
909 executing the slot SID_PRESENTATION asynchronous */
910 void ViewShellBase::StartPresentation()
912 if( GetViewFrame() && GetViewFrame()->GetDispatcher() )
913 GetViewFrame()->GetDispatcher()->Execute(SID_PRESENTATION
, SfxCallMode::ASYNCHRON
| SfxCallMode::RECORD
);
916 ::boost::shared_ptr
<tools::EventMultiplexer
> ViewShellBase::GetEventMultiplexer()
918 OSL_ASSERT(mpImpl
.get()!=NULL
);
919 OSL_ASSERT(mpImpl
->mpEventMultiplexer
.get()!=NULL
);
921 return mpImpl
->mpEventMultiplexer
;
924 const Rectangle
& ViewShellBase::getClientRectangle() const
926 return mpImpl
->maClientArea
;
929 ::boost::shared_ptr
<ToolBarManager
> ViewShellBase::GetToolBarManager() const
931 OSL_ASSERT(mpImpl
.get()!=NULL
);
932 OSL_ASSERT(mpImpl
->mpToolBarManager
.get()!=NULL
);
934 return mpImpl
->mpToolBarManager
;
937 ::boost::shared_ptr
<FormShellManager
> ViewShellBase::GetFormShellManager() const
939 OSL_ASSERT(mpImpl
.get()!=NULL
);
940 OSL_ASSERT(mpImpl
->mpFormShellManager
.get()!=NULL
);
942 return mpImpl
->mpFormShellManager
;
945 DrawController
& ViewShellBase::GetDrawController() const
947 OSL_ASSERT(mpImpl
.get()!=NULL
);
949 return *mpImpl
->mpController
;
952 void ViewShellBase::SetViewTabBar (const ::rtl::Reference
<ViewTabBar
>& rViewTabBar
)
954 OSL_ASSERT(mpImpl
.get()!=NULL
);
956 mpImpl
->mpViewTabBar
= rViewTabBar
;
959 vcl::Window
* ViewShellBase::GetViewWindow()
961 OSL_ASSERT(mpImpl
.get()!=NULL
);
963 return mpImpl
->mpViewWindow
.get();
966 OUString
ImplRetrieveLabelFromCommand( const Reference
< XFrame
>& xFrame
, const OUString
& aCmdURL
)
970 if ( !aCmdURL
.isEmpty() ) try
972 Reference
< XComponentContext
> xContext( ::comphelper::getProcessComponentContext(), UNO_QUERY_THROW
);
974 Reference
< XModuleManager2
> xModuleManager( ModuleManager::create(xContext
) );
976 OUString
aModuleIdentifier( xModuleManager
->identify( Reference
<XInterface
>( xFrame
, UNO_QUERY_THROW
) ) );
978 if( !aModuleIdentifier
.isEmpty() )
980 Reference
< XNameAccess
> const xNameAccess(
981 frame::theUICommandDescription::get(xContext
) );
982 Reference
< ::com::sun::star::container::XNameAccess
> m_xUICommandLabels( xNameAccess
->getByName( aModuleIdentifier
), UNO_QUERY_THROW
);
983 Sequence
< PropertyValue
> aPropSeq
;
984 if( m_xUICommandLabels
->getByName( aCmdURL
) >>= aPropSeq
)
986 for( sal_Int32 i
= 0; i
< aPropSeq
.getLength(); i
++ )
988 if ( aPropSeq
[i
].Name
== "Name" )
990 aPropSeq
[i
].Value
>>= aLabel
;
997 catch (const Exception
&)
1004 OUString
ViewShellBase::RetrieveLabelFromCommand( const OUString
& aCmdURL
) const
1006 Reference
< XFrame
> xFrame( GetMainViewShell()->GetViewFrame()->GetFrame().GetFrameInterface(), UNO_QUERY
);
1007 return ImplRetrieveLabelFromCommand( xFrame
, aCmdURL
);
1010 //===== ViewShellBase::Implementation =========================================
1012 ViewShellBase::Implementation::Implementation (ViewShellBase
& rBase
)
1019 mpViewShellManager(),
1020 mpEventMultiplexer(),
1021 mpFormShellManager(),
1023 mpPageCacheManager(slidesorter::cache::PageCacheManager::Instance())
1027 ViewShellBase::Implementation::~Implementation()
1029 mpController
= NULL
;
1030 mpViewTabBar
= NULL
;
1031 mpViewWindow
.disposeAndClear();
1032 mpToolBarManager
.reset();
1035 void ViewShellBase::Implementation::LateInit()
1037 mpController
= new DrawController(mrBase
);
1040 void ViewShellBase::Implementation::ProcessRestoreEditingViewSlot()
1042 ViewShell
* pViewShell
= mrBase
.GetMainViewShell().get();
1043 if (pViewShell
!= NULL
)
1045 FrameView
* pFrameView
= pViewShell
->GetFrameView();
1046 if (pFrameView
!= NULL
)
1048 // Set view shell, edit mode, and page kind.
1049 pFrameView
->SetViewShEditMode(
1050 pFrameView
->GetViewShEditModeOnLoad(),
1051 pFrameView
->GetPageKindOnLoad());
1052 pFrameView
->SetPageKind(
1053 pFrameView
->GetPageKindOnLoad());
1054 ::boost::shared_ptr
<FrameworkHelper
> pHelper (FrameworkHelper::Instance(mrBase
));
1055 pHelper
->RequestView(
1056 FrameworkHelper::GetViewURL(pFrameView
->GetViewShellTypeOnLoad()),
1057 FrameworkHelper::msCenterPaneURL
);
1058 pHelper
->RunOnConfigurationEvent("ConfigurationUpdateEnd", CurrentPageSetter(mrBase
));
1063 void ViewShellBase::Implementation::ShowViewTabBar (bool bShow
)
1065 if (mpViewTabBar
.is()
1066 && mpViewTabBar
->GetTabControl()->IsVisible() != bShow
)
1068 mpViewTabBar
->GetTabControl()->Show(bShow
);
1073 void ViewShellBase::Implementation::ResizePixel (
1074 const Point
& rOrigin
,
1081 // Forward the call to both the base class and the main stacked sub
1082 // shell only when main sub shell exists.
1083 ViewShell
* pMainViewShell
= mrBase
.GetMainViewShell().get();
1085 // Set the ViewTabBar temporarily to full size so that, when asked
1086 // later, it can return its true height.
1087 mrBase
.SetWindow (mpViewWindow
.get());
1088 if (mpViewTabBar
.is() && mpViewTabBar
->GetTabControl()->IsVisible())
1089 mpViewTabBar
->GetTabControl()->SetPosSizePixel (rOrigin
, rSize
);
1091 // Calculate and set the border before the controls are placed.
1093 if (pMainViewShell
!= NULL
)
1094 aBorder
= pMainViewShell
->GetBorder(bOuterResize
);
1095 aBorder
+= mrBase
.GetBorder(bOuterResize
);
1096 if (mrBase
.GetBorderPixel() != aBorder
)
1097 mrBase
.SetBorderPixel(aBorder
);
1099 // Place the ViewTabBar at the top. It is part of the border.
1100 SvBorder aBaseBorder
;
1101 if (mpViewTabBar
.is() && mpViewTabBar
->GetTabControl()->IsVisible())
1103 aBaseBorder
.Top() = mpViewTabBar
->GetHeight();
1104 mpViewTabBar
->GetTabControl()->SetPosSizePixel(
1105 rOrigin
, Size(rSize
.Width(),aBaseBorder
.Top()));
1108 // The view window gets the remaining space.
1109 Point
aViewWindowPosition (
1110 rOrigin
.X()+aBaseBorder
.Left(),
1111 rOrigin
.Y()+aBaseBorder
.Top());
1113 Size
aViewWindowSize (
1114 rSize
.Width() - aBaseBorder
.Left() - aBaseBorder
.Right(),
1115 rSize
.Height() - aBaseBorder
.Top() - aBaseBorder
.Bottom());
1116 mpViewWindow
->SetPosSizePixel(aViewWindowPosition
, aViewWindowSize
);
1118 maClientArea
= Rectangle(Point(0,0), aViewWindowSize
);
1121 void ViewShellBase::Implementation::SetPaneVisibility (
1122 const SfxRequest
& rRequest
,
1123 const OUString
& rsPaneURL
,
1124 const OUString
& rsViewURL
)
1128 Reference
<XControllerManager
> xControllerManager (mrBase
.GetController(), UNO_QUERY_THROW
);
1130 const Reference
< XComponentContext
> xContext(
1131 ::comphelper::getProcessComponentContext() );
1132 Reference
<XResourceId
> xPaneId (ResourceId::create(
1133 xContext
, rsPaneURL
));
1134 Reference
<XResourceId
> xViewId (ResourceId::createWithAnchorURL(
1135 xContext
, rsViewURL
, rsPaneURL
));
1137 // Determine the new visibility state.
1138 const SfxItemSet
* pArguments
= rRequest
.GetArgs();
1139 bool bShowChildWindow
;
1140 sal_uInt16 nSlotId
= rRequest
.GetSlot();
1141 if (pArguments
!= NULL
)
1142 bShowChildWindow
= static_cast<const SfxBoolItem
&>(
1143 pArguments
->Get(nSlotId
)).GetValue();
1146 Reference
<XConfigurationController
> xConfigurationController (
1147 xControllerManager
->getConfigurationController());
1148 if ( ! xConfigurationController
.is())
1149 throw RuntimeException();
1150 Reference
<XConfiguration
> xConfiguration (
1151 xConfigurationController
->getRequestedConfiguration());
1152 if ( ! xConfiguration
.is())
1153 throw RuntimeException();
1155 bShowChildWindow
= ! xConfiguration
->hasResource(xPaneId
);
1158 // Set the desired visibility state at the current configuration
1159 // and update it accordingly.
1160 Reference
<XConfigurationController
> xConfigurationController (
1161 xControllerManager
->getConfigurationController());
1162 if ( ! xConfigurationController
.is())
1163 throw RuntimeException();
1164 if (bShowChildWindow
)
1166 xConfigurationController
->requestResourceActivation(
1168 ResourceActivationMode_ADD
);
1169 xConfigurationController
->requestResourceActivation(
1171 ResourceActivationMode_REPLACE
);
1174 xConfigurationController
->requestResourceDeactivation(
1177 catch (const Exception
&)
1179 DBG_UNHANDLED_EXCEPTION();
1183 void ViewShellBase::Implementation::GetSlotState (SfxItemSet
& rSet
)
1187 // Get some frequently used values.
1188 Reference
<XControllerManager
> xControllerManager (mrBase
.GetController(), UNO_QUERY_THROW
);
1189 Reference
<XConfigurationController
> xConfigurationController (
1190 xControllerManager
->getConfigurationController());
1191 if ( ! xConfigurationController
.is())
1192 throw RuntimeException();
1193 Reference
<XConfiguration
> xConfiguration (
1194 xConfigurationController
->getRequestedConfiguration());
1195 if ( ! xConfiguration
.is())
1196 throw RuntimeException();
1198 const Reference
< XComponentContext
> xContext(
1199 ::comphelper::getProcessComponentContext() );
1200 SfxWhichIter
aSetIterator (rSet
);
1201 sal_uInt16
nItemId (aSetIterator
.FirstWhich());
1204 bool bState (false);
1205 Reference
<XResourceId
> xResourceId
;
1210 case SID_LEFT_PANE_IMPRESS
:
1211 xResourceId
= ResourceId::create(
1212 xContext
, FrameworkHelper::msLeftImpressPaneURL
);
1215 case SID_LEFT_PANE_DRAW
:
1216 xResourceId
= ResourceId::create(
1217 xContext
, FrameworkHelper::msLeftDrawPaneURL
);
1220 case SID_NORMAL_MULTI_PANE_GUI
:
1221 xResourceId
= ResourceId::createWithAnchorURL(
1223 FrameworkHelper::msImpressViewURL
,
1224 FrameworkHelper::msCenterPaneURL
);
1227 case SID_SLIDE_SORTER_MULTI_PANE_GUI
:
1229 xResourceId
= ResourceId::createWithAnchorURL(
1231 FrameworkHelper::msSlideSorterURL
,
1232 FrameworkHelper::msCenterPaneURL
);
1235 case SID_OUTLINEMODE
:
1236 xResourceId
= ResourceId::createWithAnchorURL(
1238 FrameworkHelper::msOutlineViewURL
,
1239 FrameworkHelper::msCenterPaneURL
);
1242 case SID_HANDOUTMODE
:
1243 // There is only the master page mode for the handout
1244 // view so ignore the master page flag.
1245 xResourceId
= ResourceId::createWithAnchorURL(
1247 FrameworkHelper::msHandoutViewURL
,
1248 FrameworkHelper::msCenterPaneURL
);
1252 xResourceId
= ResourceId::createWithAnchorURL(
1254 FrameworkHelper::msNotesViewURL
,
1255 FrameworkHelper::msCenterPaneURL
);
1259 // Ignore all other items. They are not meant to be
1264 catch (const DeploymentException
&)
1268 // Determine the state for the resource.
1269 bState
= xConfiguration
->hasResource(xResourceId
);
1271 // Take the master page mode into account.
1274 case SID_NORMAL_MULTI_PANE_GUI
:
1277 // Determine the master page mode.
1278 ViewShell
* pCenterViewShell
= FrameworkHelper::Instance(mrBase
)->GetViewShell(
1279 FrameworkHelper::msCenterPaneURL
).get();
1280 bool bMasterPageMode (false);
1281 if (pCenterViewShell
!=NULL
&& pCenterViewShell
->ISA(DrawViewShell
))
1282 if (PTR_CAST(DrawViewShell
,pCenterViewShell
)->GetEditMode()
1285 bMasterPageMode
= true;
1288 bState
&= !bMasterPageMode
;
1292 case SID_HANDOUTMODE
:
1293 // There is only the master page mode for the handout
1294 // view so ignore the master page flag.
1298 // And finally set the state.
1299 rSet
.Put(SfxBoolItem(nItemId
, bState
));
1301 nItemId
= aSetIterator
.NextWhich();
1304 catch (const RuntimeException
&)
1306 DBG_UNHANDLED_EXCEPTION();
1311 } // end of namespace sd
1313 //===== CurrentPageSetter ===========================================
1317 CurrentPageSetter::CurrentPageSetter (ViewShellBase
& rBase
)
1322 void CurrentPageSetter::operator() (bool)
1324 FrameView
* pFrameView
= NULL
;
1326 if (mrBase
.GetMainViewShell() != 0)
1328 pFrameView
= mrBase
.GetMainViewShell()->GetFrameView();
1331 if (pFrameView
!=NULL
)
1335 // Get the current page either from the DrawPagesSupplier or the
1336 // MasterPagesSupplier.
1338 if (pFrameView
->GetViewShEditModeOnLoad() == EM_PAGE
)
1340 Reference
<drawing::XDrawPagesSupplier
> xPagesSupplier (
1341 mrBase
.GetController()->getModel(), UNO_QUERY_THROW
);
1342 Reference
<container::XIndexAccess
> xPages (
1343 xPagesSupplier
->getDrawPages(), UNO_QUERY_THROW
);
1344 aPage
= xPages
->getByIndex(pFrameView
->GetSelectedPageOnLoad());
1348 Reference
<drawing::XMasterPagesSupplier
> xPagesSupplier (
1349 mrBase
.GetController()->getModel(), UNO_QUERY_THROW
);
1350 Reference
<container::XIndexAccess
> xPages (
1351 xPagesSupplier
->getMasterPages(), UNO_QUERY_THROW
);
1352 aPage
= xPages
->getByIndex(pFrameView
->GetSelectedPageOnLoad());
1354 // Switch to the page last edited by setting the CurrentPage
1356 Reference
<beans::XPropertySet
> xSet (mrBase
.GetController(), UNO_QUERY_THROW
);
1357 xSet
->setPropertyValue ("CurrentPage", aPage
);
1359 catch (const RuntimeException
&)
1361 // We have not been able to set the current page at the main view.
1362 // This is sad but still leaves us in a valid state. Therefore,
1363 // this exception is silently ignored.
1365 catch (const beans::UnknownPropertyException
&)
1367 DBG_ASSERT(false,"CurrentPage property unknown");
1372 } // end of anonymouse namespace
1374 //===== FocusForwardingWindow =================================================
1376 namespace sd
{ namespace {
1378 FocusForwardingWindow::FocusForwardingWindow (
1379 vcl::Window
& rParentWindow
,
1380 ViewShellBase
& rBase
)
1381 : vcl::Window(&rParentWindow
, WinBits(WB_CLIPCHILDREN
| WB_DIALOGCONTROL
)),
1384 SAL_INFO("sd.view", "created FocusForwardingWindow at " << this);
1387 FocusForwardingWindow::~FocusForwardingWindow()
1392 void FocusForwardingWindow::dispose()
1394 SAL_INFO("sd.view", "destroyed FocusForwardingWindow at " << this);
1395 vcl::Window::dispose();
1398 void FocusForwardingWindow::KeyInput (const KeyEvent
& rKEvt
)
1400 ::boost::shared_ptr
<ViewShell
> pViewShell
= mrBase
.GetMainViewShell();
1401 if (pViewShell
.get() != NULL
)
1403 vcl::Window
* pWindow
= pViewShell
->GetActiveWindow();
1404 if (pWindow
!= NULL
)
1406 // Forward the focus so that the window is called directly the
1408 pWindow
->GrabFocus();
1409 // Forward the key press as well.
1410 pWindow
->KeyInput(rKEvt
);
1415 void FocusForwardingWindow::Command (const CommandEvent
& rEvent
)
1417 ::boost::shared_ptr
<ViewShell
> pViewShell
= mrBase
.GetMainViewShell();
1418 if (pViewShell
.get() != NULL
)
1420 vcl::Window
* pWindow
= pViewShell
->GetActiveWindow();
1421 if (pWindow
!= NULL
)
1423 pWindow
->Command(rEvent
);
1428 } // end of anonymouse namespace
1430 } // end of namespace sd
1432 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */