xref: /trunk/main/sd/source/ui/view/ViewShellBase.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sd.hxx"
30 
31 #include <comphelper/processfactory.hxx>
32 
33 #include <com/sun/star/frame/UnknownModuleException.hpp>
34 #include <com/sun/star/frame/XModuleManager.hpp>
35 #include <com/sun/star/container/XNameAccess.hpp>
36 #include <com/sun/star/beans/PropertyValue.hpp>
37 
38 #include "ViewShellBase.hxx"
39 #include <algorithm>
40 #include "EventMultiplexer.hxx"
41 #include "cache/SlsPageCacheManager.hxx"
42 #include "sdresid.hxx"
43 #include "app.hrc"
44 #include "strings.hrc"
45 #include "glob.hrc"
46 #include "unokywds.hxx"
47 #include <svx/svxids.hrc>
48 #include "DrawDocShell.hxx"
49 #include <sfx2/app.hxx>
50 #include "PaneChildWindows.hxx"
51 #include "NotesChildWindow.hxx"
52 #include "ViewShellManager.hxx"
53 #include "DrawController.hxx"
54 #include "UpdateLockManager.hxx"
55 #include "FrameView.hxx"
56 #include "ViewTabBar.hxx"
57 #include <sfx2/event.hxx>
58 #include "drawdoc.hxx"
59 #include <sfx2/dispatch.hxx>
60 #include <sfx2/request.hxx>
61 #include <sfx2/printer.hxx>
62 #include "DrawViewShell.hxx"
63 #include "GraphicViewShell.hxx"
64 #include "OutlineViewShell.hxx"
65 #include "SlideSorterViewShell.hxx"
66 #include "PresentationViewShell.hxx"
67 #include "FormShellManager.hxx"
68 #include "ToolBarManager.hxx"
69 #include "taskpane/PanelId.hxx"
70 #include "Window.hxx"
71 #include "framework/ConfigurationController.hxx"
72 #include "DocumentRenderer.hxx"
73 
74 #include <com/sun/star/frame/XFrame.hpp>
75 #include <com/sun/star/awt/XWindow.hpp>
76 #include <com/sun/star/frame/XController.hpp>
77 #include <com/sun/star/frame/XModel.hpp>
78 #include <com/sun/star/document/XViewDataSupplier.hpp>
79 #include <com/sun/star/container/XIndexAccess.hpp>
80 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
81 #include <com/sun/star/drawing/XMasterPagesSupplier.hpp>
82 #include <com/sun/star/drawing/framework/XControllerManager.hpp>
83 #include <com/sun/star/drawing/framework/XConfigurationController.hpp>
84 #include <com/sun/star/drawing/framework/ResourceId.hpp>
85 #include "framework/FrameworkHelper.hxx"
86 
87 #include <rtl/ref.hxx>
88 #include <sfx2/msg.hxx>
89 #include <sfx2/objface.hxx>
90 #include <sfx2/viewfrm.hxx>
91 #include <svl/whiter.hxx>
92 #include <comphelper/processfactory.hxx>
93 #include <vcl/msgbox.hxx>
94 #include <tools/diagnose_ex.h>
95 
96 #include "fubullet.hxx"
97 
98 using namespace sd;
99 #define ViewShellBase
100 #include "sdslots.hxx"
101 
102 using ::sd::framework::FrameworkHelper;
103 using ::rtl::OUString;
104 using namespace com::sun::star::uno;
105 using namespace com::sun::star::frame;
106 using namespace com::sun::star::container;
107 using namespace com::sun::star::lang;
108 using namespace com::sun::star::beans;
109 
110 namespace {
111 
112 class CurrentPageSetter
113 {
114 public:
115     CurrentPageSetter (ViewShellBase& rBase);
116     void operator () (bool);
117 private:
118     ViewShellBase& mrBase;
119 };
120 
121 } // end of anonymous namespace
122 
123 
124 using namespace ::com::sun::star;
125 using namespace ::com::sun::star::uno;
126 using namespace ::com::sun::star::drawing::framework;
127 using ::sd::framework::FrameworkHelper;
128 
129 namespace sd {
130 
131 class ViewShellBase::Implementation
132 {
133 public:
134     /** Main controller of the view shell.  During the switching from one
135         stacked shell to another this pointer may be NULL.
136     */
137     ::rtl::Reference<DrawController> mpController;
138 
139     /** The view tab bar is the control for switching between different
140         views in one pane.
141     */
142     ::rtl::Reference<ViewTabBar> mpViewTabBar;
143 
144 	// contains the complete area of the current view relative to the frame window
145 	Rectangle maClientArea;
146 
147     // This is set to true when PrepareClose() is called.
148     bool mbIsClosing;
149 
150     /** The view window is the parent of all UI elements that belong to the
151         view or ViewShell.  This comprises the rulers, the scroll bars, and
152         the content window.
153         It does not include the ViewTabBar.
154     */
155     ::boost::scoped_ptr< ::Window> mpViewWindow;
156 
157     ::boost::shared_ptr<ToolBarManager> mpToolBarManager;
158 
159     ::boost::shared_ptr<ViewShellManager> mpViewShellManager;
160 
161     ::boost::shared_ptr<tools::EventMultiplexer> mpEventMultiplexer;
162 
163     ::boost::shared_ptr<UpdateLockManager> mpUpdateLockManager;
164 
165     ::boost::shared_ptr<FormShellManager> mpFormShellManager;
166 
167     Implementation (ViewShellBase& rBase);
168     ~Implementation (void);
169 
170     void LateInit (void);
171 
172     /** Show or hide the ViewTabBar.
173         @param bShow
174             When <TRUE/> then the ViewTabBar is shown, otherwise it is hidden.
175     */
176     void ShowViewTabBar (bool bShow);
177 
178     /** Common code of ViewShellBase::OuterResizePixel() and
179         ViewShellBase::InnerResizePixel().
180     */
181     void ResizePixel (
182         const Point& rOrigin,
183         const Size& rSize,
184         bool bOuterResize);
185 
186     /** Show or hide the specified pane.  The visibility state is taken
187         fromthe given request.
188         @param rRequest
189             The request determines the new visibility state.  The state can
190             either be toggled or be set to a given value.
191         @param rsPaneURL
192             This URL specifies the pane whose visibility state to set.
193         @param rsViewURL
194             When the pane becomes visible then this view URL specifies which
195             type of view to show in it.
196     */
197     void SetPaneVisibility (
198         const SfxRequest& rRequest,
199         const ::rtl::OUString& rsPaneURL,
200         const ::rtl::OUString& rsViewURL);
201 
202     void GetSlotState (SfxItemSet& rSet);
203 
204     void ProcessRestoreEditingViewSlot (void);
205     void ProcessTaskPaneSlot (SfxRequest& rRequest);
206 
207 private:
208     ViewShellBase& mrBase;
209 
210     /** Hold a reference to the page cache manager of the slide sorter in
211         order to ensure that it stays alive while the ViewShellBase is
212         alive.
213     */
214     ::boost::shared_ptr<slidesorter::cache::PageCacheManager> mpPageCacheManager;
215 };
216 
217 
218 namespace {
219 /** The only task of this window is to forward key presses to the content
220     window of the main view shell.  With the key press it forwards the focus
221     so that it is not called very often.
222 */
223 class FocusForwardingWindow : public ::Window
224 {
225 public:
226     FocusForwardingWindow (::Window& rParentWindow, ViewShellBase& rBase);
227     virtual ~FocusForwardingWindow (void);
228     virtual void KeyInput (const KeyEvent& rEvent);
229     virtual void Command (const CommandEvent& rEvent);
230 
231 private:
232     ViewShellBase& mrBase;
233 };
234 } // end of anonymous namespace
235 
236 
237 //===== ViewShellBase =========================================================
238 
239 TYPEINIT1(ViewShellBase, SfxViewShell);
240 
241 // We have to expand the SFX_IMPL_VIEWFACTORY macro to call LateInit() after a
242 // new ViewShellBase object has been constructed.
243 
244 SfxViewFactory* ViewShellBase::pFactory;
245 SfxViewShell* __EXPORT ViewShellBase::CreateInstance (
246     SfxViewFrame *pFrame, SfxViewShell *pOldView)
247 {
248     ViewShellBase* pBase = new ViewShellBase(pFrame, pOldView);
249     pBase->LateInit(OUString());
250     return pBase;
251 }
252 void ViewShellBase::RegisterFactory( sal_uInt16 nPrio )
253 {
254     pFactory = new SfxViewFactory(
255         &CreateInstance,&InitFactory,nPrio,"Default");
256     InitFactory();
257 }
258 void ViewShellBase::InitFactory()
259 {
260 	SFX_VIEW_REGISTRATION(DrawDocShell);
261 }
262 
263 
264 
265 SFX_IMPL_INTERFACE(ViewShellBase, SfxViewShell, SdResId(STR_VIEWSHELLBASE))
266 {
267 }
268 
269 
270 
271 
272 ViewShellBase::ViewShellBase (
273     SfxViewFrame* _pFrame,
274     SfxViewShell*)
275     : SfxViewShell (_pFrame,
276           SFX_VIEW_CAN_PRINT
277         | SFX_VIEW_HAS_PRINTOPTIONS),
278       maMutex(),
279       mpImpl(),
280       mpDocShell (NULL),
281       mpDocument (NULL)
282 {
283     mpImpl.reset(new Implementation(*this));
284     mpImpl->mpViewWindow.reset(new FocusForwardingWindow(_pFrame->GetWindow(),*this));
285     mpImpl->mpViewWindow->SetBackground(Wallpaper());
286     mpImpl->mpUpdateLockManager.reset(new UpdateLockManager(*this));
287 
288     _pFrame->GetWindow().SetBackground(Wallpaper());
289 
290     // Set up the members in the correct order.
291     if (GetViewFrame()->GetObjectShell()->ISA(DrawDocShell))
292         mpDocShell = static_cast<DrawDocShell*>(
293             GetViewFrame()->GetObjectShell());
294     if (mpDocShell != NULL)
295         mpDocument = mpDocShell->GetDoc();
296     mpImpl->mpViewShellManager.reset(new ViewShellManager(*this));
297 
298     SetWindow(mpImpl->mpViewWindow.get());
299 
300     // Hide the window to avoid complaints from Sfx...SwitchViewShell...
301     _pFrame->GetWindow().Hide();
302 }
303 
304 
305 
306 
307 /** In this destructor the order in which some of the members are destroyed
308     (and/or being prepared to being destroyed) is important.  Change it only
309     when you know what you are doing.
310 */
311 ViewShellBase::~ViewShellBase (void)
312 {
313     // Tell the controller that the ViewShellBase is not available anymore.
314     if (mpImpl->mpController.get() != NULL)
315         mpImpl->mpController->ReleaseViewShellBase();
316 
317     // We have to hide the main window to prevent SFX complaining after a
318     // reload about it being already visible.
319     ViewShell* pShell = GetMainViewShell().get();
320     if (pShell!=NULL
321         && pShell->GetActiveWindow()!=NULL
322         && pShell->GetActiveWindow()->GetParent()!=NULL)
323     {
324         pShell->GetActiveWindow()->GetParent()->Hide();
325     }
326 
327     mpImpl->mpUpdateLockManager->Disable();
328     mpImpl->mpToolBarManager->Shutdown();
329     mpImpl->mpViewShellManager->Shutdown();
330 
331     EndListening(*GetViewFrame());
332     EndListening(*GetDocShell());
333 
334     SetWindow(NULL);
335 }
336 
337 
338 
339 
340 void ViewShellBase::LateInit (const ::rtl::OUString& rsDefaultView)
341 {
342     StartListening(*GetViewFrame(),sal_True);
343     StartListening(*GetDocShell(),sal_True);
344     mpImpl->LateInit();
345     InitializeFramework();
346 
347     mpImpl->mpEventMultiplexer.reset(new tools::EventMultiplexer (*this));
348 
349     mpImpl->mpFormShellManager.reset(new FormShellManager(*this));
350 
351     mpImpl->mpToolBarManager = ToolBarManager::Create(
352         *this,
353         mpImpl->mpEventMultiplexer,
354         mpImpl->mpViewShellManager);
355 
356     try
357     {
358         Reference<XControllerManager> xControllerManager (GetDrawController(), UNO_QUERY_THROW);
359         Reference<XConfigurationController> xConfigurationController (
360             xControllerManager->getConfigurationController());
361         if (xConfigurationController.is())
362         {
363             OUString sView (rsDefaultView);
364             if (sView.getLength() == 0)
365                 sView = GetInitialViewShellType();
366 
367             ::boost::shared_ptr<FrameworkHelper> pHelper (FrameworkHelper::Instance(*this));
368 
369             // Create the resource ids for the center pane and view.
370             const Reference<drawing::framework::XResourceId> xCenterPaneId (
371                 pHelper->CreateResourceId(FrameworkHelper::msCenterPaneURL));
372             const Reference<drawing::framework::XResourceId> xCenterViewId (
373                 pHelper->CreateResourceId(sView, xCenterPaneId));
374 
375             // Request center pane and view.
376             xConfigurationController->requestResourceActivation(xCenterPaneId, ResourceActivationMode_ADD);
377             xConfigurationController->requestResourceActivation(xCenterViewId, ResourceActivationMode_REPLACE);
378 
379             // Process configuration events synchronously until the center view
380             // has been created.
381             sd::framework::ConfigurationController* pConfigurationController
382                 = dynamic_cast<sd::framework::ConfigurationController*>(xConfigurationController.get());
383             if (pConfigurationController != NULL)
384             {
385                 while (
386                     ! pConfigurationController->getResource(xCenterViewId).is()
387                         && pConfigurationController->hasPendingRequests())
388                 {
389                     pConfigurationController->ProcessEvent();
390                 }
391             }
392         }
393     }
394     catch (RuntimeException&)
395     {}
396 
397     // AutoLayouts have to be ready.
398     GetDocument()->StopWorkStartupDelay();
399 
400     UpdateBorder();
401 
402     // Remember the type of the current main view shell in the frame view.
403     ViewShell* pViewShell = GetMainViewShell().get();
404     if (pViewShell != NULL)
405     {
406         FrameView* pFrameView = pViewShell->GetFrameView();
407         if (pFrameView != NULL)
408             pFrameView->SetViewShellTypeOnLoad(pViewShell->GetShellType());
409     }
410 }
411 
412 
413 
414 
415 ::boost::shared_ptr<ViewShellManager> ViewShellBase::GetViewShellManager (void) const
416 {
417     return mpImpl->mpViewShellManager;
418 }
419 
420 
421 
422 
423 ::boost::shared_ptr<ViewShell> ViewShellBase::GetMainViewShell (void) const
424 {
425     ::boost::shared_ptr<ViewShell> pMainViewShell (
426         framework::FrameworkHelper::Instance(*const_cast<ViewShellBase*>(this))
427             ->GetViewShell(framework::FrameworkHelper::msCenterPaneURL));
428     if (pMainViewShell.get() == NULL)
429         pMainViewShell = framework::FrameworkHelper::Instance(*const_cast<ViewShellBase*>(this))
430             ->GetViewShell(framework::FrameworkHelper::msFullScreenPaneURL);
431     return pMainViewShell;
432 }
433 
434 
435 
436 
437 ViewShellBase* ViewShellBase::GetViewShellBase (SfxViewFrame* pViewFrame)
438 {
439     ViewShellBase* pBase = NULL;
440 
441     if (pViewFrame != NULL)
442     {
443         // Get the view shell for the frame and cast it to
444         // sd::ViewShellBase.
445         SfxViewShell* pSfxViewShell = pViewFrame->GetViewShell();
446         if (pSfxViewShell!=NULL && pSfxViewShell->ISA(::sd::ViewShellBase))
447             pBase = static_cast<ViewShellBase*>(pSfxViewShell);
448     }
449 
450     return pBase;
451 }
452 
453 
454 
455 
456 DrawDocShell* ViewShellBase::GetDocShell (void) const
457 {
458     return mpDocShell;
459 }
460 
461 
462 
463 SdDrawDocument* ViewShellBase::GetDocument (void) const
464 {
465     return mpDocument;
466 }
467 
468 
469 
470 
471 void ViewShellBase::Notify(SfxBroadcaster& rBC, const SfxHint& rHint)
472 {
473     SfxViewShell::Notify(rBC, rHint);
474 
475 	if (rHint.IsA(TYPE(SfxEventHint)))
476 	{
477         switch (static_cast<const SfxEventHint&>(rHint).GetEventId())
478 		{
479             case SFX_EVENT_OPENDOC:
480                 if( GetDocument() && GetDocument()->IsStartWithPresentation() )
481                 {
482                     if( GetViewFrame() )
483                     {
484                         GetDocument()->SetStartWithPresentation( false );
485                         GetViewFrame()->GetDispatcher()->Execute(
486                             SID_PRESENTATION, SFX_CALLMODE_ASYNCHRON );
487                     }
488                 }
489                 else
490                 {
491                     //                    mpPaneManager->InitPanes();
492                 }
493                 break;
494 
495             default:
496                 break;
497         }
498 	}
499 }
500 
501 
502 
503 
504 void ViewShellBase::InitializeFramework (void)
505 {
506 }
507 
508 
509 
510 
511 void ViewShellBase::InnerResizePixel (const Point& rOrigin, const Size &rSize)
512 {
513     Size aObjSize = GetObjectShell()->GetVisArea().GetSize();
514     if ( aObjSize.Width() > 0 && aObjSize.Height() > 0 )
515     {
516         SvBorder aBorder( GetBorderPixel() );
517         Size aSize( rSize );
518         aSize.Width() -= (aBorder.Left() + aBorder.Right());
519         aSize.Height() -= (aBorder.Top() + aBorder.Bottom());
520         Size aObjSizePixel = mpImpl->mpViewWindow->LogicToPixel( aObjSize, MAP_100TH_MM );
521 		SfxViewShell::SetZoomFactor(
522             Fraction( aSize.Width(), std::max( aObjSizePixel.Width(), (long int)1 ) ),
523 			Fraction( aSize.Height(), std::max( aObjSizePixel.Height(), (long int)1) ) );
524     }
525 
526     mpImpl->ResizePixel(rOrigin, rSize, false);
527 }
528 
529 
530 
531 
532 void ViewShellBase::OuterResizePixel (const Point& rOrigin, const Size &rSize)
533 {
534     mpImpl->ResizePixel (rOrigin, rSize, true);
535 }
536 
537 
538 
539 
540 void ViewShellBase::Rearrange (void)
541 {
542     OSL_ASSERT(GetViewFrame()!=NULL);
543 
544     // There is a bug in the communication between embedded objects and the
545     // framework::LayoutManager that leads to missing resize updates.  The
546     // following workaround enforces such an update by cycling the border to
547     // zero and back to the current value.
548     if (GetWindow() != NULL)
549     {
550         SetBorderPixel(SvBorder());
551         UpdateBorder(true);
552     }
553     else
554     {
555         OSL_TRACE("Rearrange: window missing");
556     }
557 
558     GetViewFrame()->Resize(sal_True);
559 }
560 
561 
562 
563 
564 ErrCode ViewShellBase::DoVerb (long nVerb)
565 {
566     ErrCode aResult = ERRCODE_NONE;
567 
568     ::sd::ViewShell* pShell = GetMainViewShell().get();
569     if (pShell != NULL)
570         aResult = pShell->DoVerb (nVerb);
571 
572     return aResult;
573 }
574 
575 
576 
577 
578 Reference<view::XRenderable> ViewShellBase::GetRenderable (void)
579 {
580     // Create a new DocumentRenderer on every call.  It observes the life
581     // time of this ViewShellBase object.
582     return Reference<view::XRenderable>(new DocumentRenderer(*this));
583 }
584 
585 
586 
587 
588 SfxPrinter* ViewShellBase::GetPrinter (sal_Bool bCreate)
589 {
590     OSL_ASSERT(mpImpl.get()!=NULL);
591 
592 	return GetDocShell()->GetPrinter (bCreate);
593 }
594 
595 
596 
597 
598 sal_uInt16 ViewShellBase::SetPrinter (
599     SfxPrinter* pNewPrinter,
600     sal_uInt16 nDiffFlags,
601     bool bIsAPI)
602 {
603     OSL_ASSERT(mpImpl.get()!=NULL);
604 
605 	GetDocShell()->SetPrinter(pNewPrinter);
606 
607 	if ( (nDiffFlags & SFX_PRINTER_CHG_ORIENTATION ||
608 		  nDiffFlags & SFX_PRINTER_CHG_SIZE) && pNewPrinter  )
609 	{
610 		MapMode aMap = pNewPrinter->GetMapMode();
611 		aMap.SetMapUnit(MAP_100TH_MM);
612 		MapMode aOldMap = pNewPrinter->GetMapMode();
613 		pNewPrinter->SetMapMode(aMap);
614 		Size aNewSize = pNewPrinter->GetOutputSize();
615 
616 		sal_Bool bScaleAll = sal_False;
617 		if ( bIsAPI )
618 		{
619 			WarningBox aWarnBox (
620                 GetWindow(),
621                 (WinBits)(WB_YES_NO | WB_DEF_YES),
622                 String(SdResId(STR_SCALE_OBJS_TO_PAGE)));
623 			bScaleAll = (aWarnBox.Execute() == RET_YES);
624 		}
625 
626         ::boost::shared_ptr<DrawViewShell> pDrawViewShell (
627             ::boost::dynamic_pointer_cast<DrawViewShell>(GetMainViewShell()));
628 		if (pDrawViewShell)
629 		{
630 			SdPage* pPage = GetDocument()->GetSdPage(
631                 0, PK_STANDARD );
632 			pDrawViewShell->SetPageSizeAndBorder (
633                 pDrawViewShell->GetPageKind(),
634                 aNewSize,
635                 -1,-1,-1,-1,
636                 bScaleAll,
637                 pNewPrinter->GetOrientation(),
638                 pPage->GetPaperBin(),
639                 pPage->IsBackgroundFullSize());
640 		}
641 
642 		pNewPrinter->SetMapMode(aOldMap);
643     }
644 
645     return 0;
646 }
647 
648 
649 
650 
651 SfxTabPage*  ViewShellBase::CreatePrintOptionsPage(
652     ::Window *pParent,
653     const SfxItemSet &rOptions)
654 {
655     (void)pParent;
656     (void)rOptions;
657     return NULL;
658     //    return mpImpl->mpPrintManager->CreatePrintOptionsPage (pParent, rOptions);
659 }
660 
661 
662 
663 
664 void ViewShellBase::UIActivating( SfxInPlaceClient* pClient )
665 {
666     mpImpl->ShowViewTabBar(false);
667 
668 	ViewShell* pViewShell = GetMainViewShell().get();
669 	if ( pViewShell )
670     	pViewShell->UIActivating( pClient );
671 
672     SfxViewShell::UIActivating( pClient );
673 }
674 
675 
676 
677 
678 void ViewShellBase::UIDeactivated( SfxInPlaceClient* pClient )
679 {
680     SfxViewShell::UIDeactivated( pClient );
681 
682     mpImpl->ShowViewTabBar(true);
683 
684 	ViewShell* pViewShell = GetMainViewShell().get();
685 	if ( pViewShell )
686     	pViewShell->UIDeactivated( pClient );
687 }
688 
689 
690 
691 
692 SvBorder ViewShellBase::GetBorder (bool )
693 {
694     int nTop = 0;
695     if (mpImpl->mpViewTabBar.is() && mpImpl->mpViewTabBar->GetTabControl()->IsVisible())
696         nTop = mpImpl->mpViewTabBar->GetHeight();
697     return SvBorder(0,nTop,0,0);
698 }
699 
700 
701 
702 
703 void ViewShellBase::Execute (SfxRequest& rRequest)
704 {
705 	sal_uInt16 nSlotId = rRequest.GetSlot();
706 
707 	switch (nSlotId)
708     {
709         case SID_SWITCH_SHELL:
710         {
711             Reference<XControllerManager> xControllerManager (GetController(), UNO_QUERY);
712             if (xControllerManager.is())
713             {
714                 Reference<XConfigurationController> xConfigurationController (
715                     xControllerManager->getConfigurationController());
716                 if (xConfigurationController.is())
717                     xConfigurationController->update();
718             }
719         }
720         break;
721 
722         case SID_LEFT_PANE_DRAW:
723             mpImpl->SetPaneVisibility(
724                 rRequest,
725                 framework::FrameworkHelper::msLeftDrawPaneURL,
726                 framework::FrameworkHelper::msSlideSorterURL);
727             break;
728 
729         case SID_LEFT_PANE_IMPRESS:
730             mpImpl->SetPaneVisibility(
731                 rRequest,
732                 framework::FrameworkHelper::msLeftImpressPaneURL,
733                 framework::FrameworkHelper::msSlideSorterURL);
734             break;
735 
736         case SID_TASKPANE:
737             mpImpl->SetPaneVisibility(
738                 rRequest,
739                 framework::FrameworkHelper::msRightPaneURL,
740                 framework::FrameworkHelper::msTaskPaneURL);
741             break;
742 
743         case SID_NORMAL_MULTI_PANE_GUI:
744         case SID_SLIDE_SORTER_MULTI_PANE_GUI:
745         case SID_DRAWINGMODE:
746         case SID_DIAMODE:
747         case SID_OUTLINEMODE:
748         case SID_NOTESMODE:
749         case SID_HANDOUTMODE:
750             framework::FrameworkHelper::Instance(*this)->HandleModeChangeSlot(nSlotId, rRequest);
751             break;
752 
753         case SID_WIN_FULLSCREEN:
754             // The full screen mode is not supported.  Ignore the request.
755             break;
756 
757         case SID_SHOW_TOOL_PANEL:
758             mpImpl->ProcessTaskPaneSlot(rRequest);
759             break;
760 
761         case SID_RESTORE_EDITING_VIEW:
762             mpImpl->ProcessRestoreEditingViewSlot();
763             break;
764 
765         default:
766             // Ignore any other slot.
767 			rRequest.Ignore ();
768             break;
769     }
770 }
771 
772 
773 
774 
775 void ViewShellBase::GetState (SfxItemSet& rSet)
776 {
777     // The full screen mode is not supported.  Disable the the slot so that
778     // it appears grayed out when somebody uses configures the menu to show
779     // an menu item for it.
780     //    if (rSet.GetItemState(SID_WIN_FULLSCREEN) == SFX_ITEM_AVAILABLE)
781     //        rSet.DisableItem(SID_WIN_FULLSCREEN);
782 
783     mpImpl->GetSlotState(rSet);
784 
785 	FuBullet::GetSlotState( rSet, 0, GetViewFrame() );
786 }
787 
788 
789 
790 
791 void ViewShellBase::WriteUserDataSequence (
792     ::com::sun::star::uno::Sequence <
793     ::com::sun::star::beans::PropertyValue >& rSequence,
794     sal_Bool bBrowse)
795 {
796     // Forward call to main sub shell.
797     ViewShell* pShell = GetMainViewShell().get();
798     if (pShell != NULL)
799         pShell->WriteUserDataSequence (rSequence, bBrowse);
800 }
801 
802 
803 
804 
805 void ViewShellBase::ReadUserDataSequence (
806     const ::com::sun::star::uno::Sequence <
807     ::com::sun::star::beans::PropertyValue >& rSequence,
808     sal_Bool bBrowse)
809 {
810     // Forward call to main sub shell.
811     ViewShell* pShell = GetMainViewShell().get();
812     if (pShell != NULL)
813     {
814         pShell->ReadUserDataSequence (rSequence, bBrowse);
815 
816         // For certain shell types ReadUserDataSequence may have changed the
817         // type to another one.  Make sure that the center pane shows the
818         // right view shell.
819         switch (pShell->GetShellType())
820         {
821             case ViewShell::ST_IMPRESS:
822             case ViewShell::ST_NOTES:
823             case ViewShell::ST_HANDOUT:
824             {
825                 ::rtl::OUString sViewURL;
826                 switch (PTR_CAST(DrawViewShell, pShell)->GetPageKind())
827                 {
828                     default:
829                     case PK_STANDARD:
830                         sViewURL = framework::FrameworkHelper::msImpressViewURL;
831                         break;
832                     case PK_NOTES:
833                         sViewURL = framework::FrameworkHelper::msNotesViewURL;
834                         break;
835                     case PK_HANDOUT:
836                         sViewURL = framework::FrameworkHelper::msHandoutViewURL;
837                         break;
838                 }
839                 if (sViewURL.getLength() > 0)
840                     framework::FrameworkHelper::Instance(*this)->RequestView(
841                         sViewURL,
842                         framework::FrameworkHelper::msCenterPaneURL);
843             }
844             break;
845 
846             default:
847                 break;
848         }
849     }
850 }
851 
852 
853 
854 
855 void ViewShellBase::Activate (sal_Bool bIsMDIActivate)
856 {
857     SfxViewShell::Activate(bIsMDIActivate);
858 
859     Reference<XControllerManager> xControllerManager (GetController(), UNO_QUERY);
860     if (xControllerManager.is())
861     {
862         Reference<XConfigurationController> xConfigurationController (
863             xControllerManager->getConfigurationController());
864         if (xConfigurationController.is())
865             xConfigurationController->update();
866     }
867     GetToolBarManager()->RequestUpdate();
868 }
869 
870 
871 
872 
873 void ViewShellBase::Deactivate (sal_Bool bIsMDIActivate)
874 {
875     SfxViewShell::Deactivate(bIsMDIActivate);
876 }
877 
878 
879 
880 
881 void ViewShellBase::SetZoomFactor (
882     const Fraction &rZoomX,
883     const Fraction &rZoomY)
884 {
885     SfxViewShell::SetZoomFactor (rZoomX, rZoomY);
886     // Forward call to main sub shell.
887     ViewShell* pShell = GetMainViewShell().get();
888     if (pShell != NULL)
889         pShell->SetZoomFactor (rZoomX, rZoomY);
890 }
891 
892 
893 
894 
895 sal_uInt16 ViewShellBase::PrepareClose (sal_Bool bUI, sal_Bool bForBrowsing)
896 {
897 	sal_uInt16 nResult = SfxViewShell::PrepareClose (bUI, bForBrowsing);
898 
899 	if (nResult == sal_True)
900     {
901         mpImpl->mbIsClosing = true;
902 
903         // Forward call to main sub shell.
904         ViewShell* pShell = GetMainViewShell().get();
905         if (pShell != NULL)
906             nResult = pShell->PrepareClose (bUI, bForBrowsing);
907     }
908 
909     return nResult;
910 }
911 
912 
913 
914 
915 void ViewShellBase::WriteUserData (String& rString, sal_Bool bBrowse)
916 {
917 	SfxViewShell::WriteUserData (rString, bBrowse);
918 
919     // Forward call to main sub shell.
920     ViewShell* pShell = GetMainViewShell().get();
921     if (pShell != NULL)
922         pShell->WriteUserData (rString);
923 }
924 
925 
926 
927 
928 void ViewShellBase::ReadUserData (const String& rString, sal_Bool bBrowse)
929 {
930 	SfxViewShell::ReadUserData (rString, bBrowse);
931 
932     // Forward call to main sub shell.
933     ViewShell* pShell = GetMainViewShell().get();
934     if (pShell != NULL)
935         pShell->ReadUserData (rString);
936 }
937 
938 
939 
940 
941 SdrView* ViewShellBase::GetDrawView (void) const
942 {
943     // Forward call to main sub shell.
944     ViewShell* pShell = GetMainViewShell().get();
945     if (pShell != NULL)
946         return pShell->GetDrawView ();
947     else
948         return SfxViewShell::GetDrawView();
949 }
950 
951 
952 
953 
954 void ViewShellBase::AdjustPosSizePixel (const Point &rOfs, const Size &rSize)
955 {
956 	SfxViewShell::AdjustPosSizePixel (rOfs, rSize);
957 }
958 
959 
960 
961 
962 void ViewShellBase::SetBusyState (bool bBusy)
963 {
964     if (GetDocShell() != NULL)
965         GetDocShell()->SetWaitCursor (bBusy);
966 }
967 
968 
969 
970 
971 void ViewShellBase::UpdateBorder ( bool bForce /* = false */ )
972 {
973     // The following calls to SetBorderPixel() and InvalidateBorder() are
974     // made only for the main view shell.  This not only avoids unnecessary
975     // calls for the views in side panes but prevents calling an already
976     // dying SfxViewShell base class.
977     // For issue #140703# we have to check the existence of the window,
978     // too.  The SfxViewFrame accesses the window without checking it.
979     ViewShell* pMainViewShell = GetMainViewShell().get();
980     if (pMainViewShell != NULL && GetWindow()!=NULL)
981     {
982         SvBorder aCurrentBorder (GetBorderPixel());
983         bool bOuterResize ( ! GetDocShell()->IsInPlaceActive());
984         SvBorder aBorder (GetBorder(bOuterResize));
985         aBorder += pMainViewShell->GetBorder(bOuterResize);
986 
987         if (bForce || (aBorder != aCurrentBorder))
988         {
989             SetBorderPixel (aBorder);
990             InvalidateBorder();
991         }
992     }
993 }
994 
995 
996 
997 
998 void ViewShellBase::ShowUIControls (bool bVisible)
999 {
1000     if (mpImpl->mpViewTabBar.is())
1001         mpImpl->mpViewTabBar->GetTabControl()->Show(bVisible);
1002 
1003     ViewShell* pMainViewShell = GetMainViewShell().get();
1004     if (pMainViewShell != NULL)
1005         pMainViewShell->ShowUIControls (bVisible);
1006 
1007     UpdateBorder();
1008     if (bVisible)
1009         Rearrange();
1010 }
1011 
1012 
1013 
1014 
1015 OUString ViewShellBase::GetInitialViewShellType (void)
1016 {
1017     OUString sRequestedView (FrameworkHelper::msImpressViewURL);
1018 
1019     do
1020     {
1021         Reference<document::XViewDataSupplier> xViewDataSupplier (
1022             GetDocShell()->GetModel(), UNO_QUERY);
1023         if ( ! xViewDataSupplier.is())
1024             break;
1025 
1026         Reference<container::XIndexAccess> xViewData (xViewDataSupplier->getViewData());
1027         if ( ! xViewData.is())
1028             break;
1029         if (xViewData->getCount() == 0)
1030             break;
1031 
1032         sal_Int32 nView = 0;
1033 		::com::sun::star::uno::Any aAny = xViewData->getByIndex(nView);
1034     	Sequence<beans::PropertyValue> aProperties;
1035 		if ( ! (aAny >>= aProperties))
1036             break;
1037 
1038         // Search the properties for the one that tells us what page kind to
1039         // use.
1040         for (sal_Int32 n=0; n<aProperties.getLength(); n++)
1041         {
1042             const beans::PropertyValue& rProperty (aProperties[n]);
1043             if (rProperty.Name.compareToAscii(sUNO_View_PageKind) == COMPARE_EQUAL)
1044             {
1045 				sal_Int16 nPageKind = 0;
1046                 rProperty.Value >>= nPageKind;
1047                 switch ((PageKind)nPageKind)
1048                 {
1049                     case PK_STANDARD:
1050                         sRequestedView = FrameworkHelper::msImpressViewURL;
1051                         break;
1052 
1053                     case PK_HANDOUT:
1054                         sRequestedView = FrameworkHelper::msHandoutViewURL;
1055                         break;
1056 
1057                     case PK_NOTES:
1058                         sRequestedView = FrameworkHelper::msNotesViewURL;
1059                         break;
1060 
1061                     default:
1062                         // The page kind is invalid.  This is propably an
1063                         // error by the caller.  We use the standard type to
1064                         // keep things going.
1065                         DBG_ASSERT(sal_False, "ViewShellBase::GetInitialViewShellType: invalid page kind");
1066                         sRequestedView = FrameworkHelper::msImpressViewURL;
1067                         break;
1068                 }
1069                 break;
1070             }
1071 		}
1072     }
1073     while (false);
1074 
1075     return sRequestedView;
1076 }
1077 
1078 
1079 
1080 
1081 /** this method starts the presentation by
1082 	executing the slot SID_PRESENTATION asynchronous */
1083 void ViewShellBase::StartPresentation()
1084 {
1085 	if( GetViewFrame() && GetViewFrame()->GetDispatcher() )
1086 		GetViewFrame()->GetDispatcher()->Execute(SID_PRESENTATION, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD );
1087 }
1088 
1089 
1090 
1091 
1092 
1093 ::boost::shared_ptr<tools::EventMultiplexer> ViewShellBase::GetEventMultiplexer (void)
1094 {
1095     OSL_ASSERT(mpImpl.get()!=NULL);
1096     OSL_ASSERT(mpImpl->mpEventMultiplexer.get()!=NULL);
1097 
1098     return mpImpl->mpEventMultiplexer;
1099 }
1100 
1101 
1102 
1103 
1104 const Rectangle& ViewShellBase::getClientRectangle (void) const
1105 {
1106 	return mpImpl->maClientArea;
1107 }
1108 
1109 
1110 
1111 
1112 ::boost::shared_ptr<UpdateLockManager> ViewShellBase::GetUpdateLockManager (void) const
1113 {
1114     OSL_ASSERT(mpImpl.get()!=NULL);
1115     OSL_ASSERT(mpImpl->mpUpdateLockManager.get()!=NULL);
1116 
1117     return mpImpl->mpUpdateLockManager;
1118 }
1119 
1120 
1121 
1122 
1123 ::boost::shared_ptr<ToolBarManager> ViewShellBase::GetToolBarManager (void) const
1124 {
1125     OSL_ASSERT(mpImpl.get()!=NULL);
1126     OSL_ASSERT(mpImpl->mpToolBarManager.get()!=NULL);
1127 
1128     return mpImpl->mpToolBarManager;
1129 }
1130 
1131 
1132 
1133 
1134 ::boost::shared_ptr<FormShellManager> ViewShellBase::GetFormShellManager (void) const
1135 {
1136     OSL_ASSERT(mpImpl.get()!=NULL);
1137     OSL_ASSERT(mpImpl->mpFormShellManager.get()!=NULL);
1138 
1139     return mpImpl->mpFormShellManager;
1140 }
1141 
1142 
1143 
1144 
1145 DrawController& ViewShellBase::GetDrawController (void) const
1146 {
1147     OSL_ASSERT(mpImpl.get()!=NULL);
1148 
1149     return *mpImpl->mpController;
1150 }
1151 
1152 
1153 
1154 
1155 void ViewShellBase::SetViewTabBar (const ::rtl::Reference<ViewTabBar>& rViewTabBar)
1156 {
1157     OSL_ASSERT(mpImpl.get()!=NULL);
1158 
1159     mpImpl->mpViewTabBar = rViewTabBar;
1160 }
1161 
1162 
1163 
1164 
1165 ::Window* ViewShellBase::GetViewWindow (void)
1166 {
1167     OSL_ASSERT(mpImpl.get()!=NULL);
1168 
1169     return mpImpl->mpViewWindow.get();
1170 }
1171 
1172 
1173 ::rtl::OUString ImplRetrieveLabelFromCommand( const Reference< XFrame >& xFrame, const ::rtl::OUString& aCmdURL )
1174 {
1175     ::rtl::OUString aLabel;
1176 
1177     if ( aCmdURL.getLength() > 0 ) try
1178     {
1179 		Reference< XMultiServiceFactory > xServiceManager( ::comphelper::getProcessServiceFactory(), UNO_QUERY_THROW );
1180 
1181 		Reference< XModuleManager > xModuleManager( xServiceManager->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.ModuleManager") ) ), UNO_QUERY_THROW );
1182 		Reference< XInterface > xIfac( xFrame, UNO_QUERY_THROW );
1183 
1184 		::rtl::OUString aModuleIdentifier( xModuleManager->identify( xIfac ) );
1185 
1186         if( aModuleIdentifier.getLength() > 0 )
1187         {
1188 			Reference< XNameAccess > xNameAccess( xServiceManager->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.UICommandDescription" ) ) ), UNO_QUERY );
1189             if( xNameAccess.is() )
1190             {
1191 				Reference< ::com::sun::star::container::XNameAccess > m_xUICommandLabels( xNameAccess->getByName( aModuleIdentifier ), UNO_QUERY_THROW );
1192                 Sequence< PropertyValue > aPropSeq;
1193                 if( m_xUICommandLabels->getByName( aCmdURL ) >>= aPropSeq )
1194                 {
1195                     for( sal_Int32 i = 0; i < aPropSeq.getLength(); i++ )
1196                     {
1197                         if( aPropSeq[i].Name.equalsAscii( "Name" ))
1198                         {
1199                             aPropSeq[i].Value >>= aLabel;
1200                             break;
1201                         }
1202                     }
1203                 }
1204             }
1205         }
1206     }
1207     catch ( Exception& )
1208     {
1209     }
1210 
1211 	return aLabel;
1212 }
1213 
1214 ::rtl::OUString ViewShellBase::RetrieveLabelFromCommand( const ::rtl::OUString& aCmdURL ) const
1215 {
1216 	Reference< XFrame > xFrame( GetMainViewShell()->GetViewFrame()->GetFrame().GetFrameInterface(), UNO_QUERY );
1217 	return ImplRetrieveLabelFromCommand( xFrame, aCmdURL );
1218 }
1219 
1220 
1221 
1222 //===== ViewShellBase::Implementation =========================================
1223 
1224 ViewShellBase::Implementation::Implementation (ViewShellBase& rBase)
1225     : mpController(),
1226       mpViewTabBar(),
1227       maClientArea(),
1228       mbIsClosing(false),
1229       mpViewWindow(),
1230       mpToolBarManager(),
1231       mpViewShellManager(),
1232       mpEventMultiplexer(),
1233       mpUpdateLockManager(),
1234       mpFormShellManager(),
1235       mrBase(rBase),
1236       mpPageCacheManager(slidesorter::cache::PageCacheManager::Instance())
1237 {
1238 }
1239 
1240 
1241 
1242 
1243 ViewShellBase::Implementation::~Implementation (void)
1244 {
1245     mpController = NULL;
1246     mpViewTabBar = NULL;
1247     mpViewWindow.reset();
1248     mpToolBarManager.reset();
1249 }
1250 
1251 
1252 
1253 
1254 void ViewShellBase::Implementation::LateInit (void)
1255 {
1256     mpController = new DrawController(mrBase);
1257 }
1258 
1259 
1260 
1261 
1262 void ViewShellBase::Implementation::ProcessRestoreEditingViewSlot (void)
1263 {
1264     ViewShell* pViewShell = mrBase.GetMainViewShell().get();
1265     if (pViewShell != NULL)
1266     {
1267         FrameView* pFrameView = pViewShell->GetFrameView();
1268         if (pFrameView != NULL)
1269         {
1270             // Set view shell, edit mode, and page kind.
1271             pFrameView->SetViewShEditMode(
1272                 pFrameView->GetViewShEditModeOnLoad(),
1273                 pFrameView->GetPageKindOnLoad());
1274             pFrameView->SetPageKind(
1275                 pFrameView->GetPageKindOnLoad());
1276             ::boost::shared_ptr<FrameworkHelper> pHelper (FrameworkHelper::Instance(mrBase));
1277             pHelper->RequestView(
1278                 pHelper->GetViewURL(pFrameView->GetViewShellTypeOnLoad()),
1279                 FrameworkHelper::msCenterPaneURL);
1280             pHelper->RunOnConfigurationEvent(
1281                 ::rtl::OUString::createFromAscii("ConfigurationUpdateEnd"),
1282                 CurrentPageSetter(mrBase));
1283         }
1284     }
1285 }
1286 
1287 
1288 
1289 
1290 void ViewShellBase::Implementation::ShowViewTabBar (bool bShow)
1291 {
1292     if (mpViewTabBar.is()
1293         && (mpViewTabBar->GetTabControl()->IsVisible()==sal_True) != bShow)
1294     {
1295         mpViewTabBar->GetTabControl()->Show(bShow ? sal_True : sal_False);
1296         mrBase.Rearrange();
1297     }
1298 }
1299 
1300 
1301 
1302 
1303 void ViewShellBase::Implementation::ResizePixel (
1304     const Point& rOrigin,
1305     const Size &rSize,
1306     bool bOuterResize)
1307 {
1308     if (mbIsClosing)
1309         return;
1310 
1311 	// Forward the call to both the base class and the main stacked sub
1312     // shell only when main sub shell exists.
1313     ViewShell* pMainViewShell = mrBase.GetMainViewShell().get();
1314 
1315     // Set the ViewTabBar temporarily to full size so that, when asked
1316     // later, it can return its true height.
1317     mrBase.SetWindow (mpViewWindow.get());
1318     if (mpViewTabBar.is() && mpViewTabBar->GetTabControl()->IsVisible())
1319         mpViewTabBar->GetTabControl()->SetPosSizePixel (rOrigin, rSize);
1320 
1321     // Calculate and set the border before the controls are placed.
1322     SvBorder aBorder;
1323     if (pMainViewShell != NULL)
1324         aBorder = pMainViewShell->GetBorder(bOuterResize);
1325     aBorder += mrBase.GetBorder(bOuterResize);
1326     if (mrBase.GetBorderPixel() != aBorder)
1327         mrBase.SetBorderPixel(aBorder);
1328 
1329     // Place the ViewTabBar at the top.  It is part of the border.
1330     SvBorder aBaseBorder;
1331     if (mpViewTabBar.is() && mpViewTabBar->GetTabControl()->IsVisible())
1332     {
1333         aBaseBorder.Top() = mpViewTabBar->GetHeight();
1334         mpViewTabBar->GetTabControl()->SetPosSizePixel(
1335             rOrigin, Size(rSize.Width(),aBaseBorder.Top()));
1336     }
1337 
1338     // The view window gets the remaining space.
1339     Point aViewWindowPosition (
1340         rOrigin.X()+aBaseBorder.Left(),
1341         rOrigin.Y()+aBaseBorder.Top());
1342     Size aViewWindowSize (
1343         rSize.Width() - aBaseBorder.Left() - aBaseBorder.Right(),
1344         rSize.Height() - aBaseBorder.Top() - aBaseBorder.Bottom());
1345     mpViewWindow->SetPosSizePixel(aViewWindowPosition, aViewWindowSize);
1346 
1347     maClientArea = Rectangle(Point(0,0), aViewWindowSize);
1348 }
1349 
1350 
1351 
1352 
1353 void ViewShellBase::Implementation::SetPaneVisibility (
1354     const SfxRequest& rRequest,
1355     const ::rtl::OUString& rsPaneURL,
1356     const ::rtl::OUString& rsViewURL)
1357 {
1358     try
1359     {
1360         Reference<XControllerManager> xControllerManager (mrBase.GetController(), UNO_QUERY_THROW);
1361 
1362         const Reference< XComponentContext > xContext(
1363             ::comphelper::getProcessComponentContext() );
1364         Reference<XResourceId> xPaneId (ResourceId::create(
1365             xContext, rsPaneURL));
1366         Reference<XResourceId> xViewId (ResourceId::createWithAnchorURL(
1367             xContext, rsViewURL, rsPaneURL));
1368 
1369         // Determine the new visibility state.
1370         const SfxItemSet* pArguments = rRequest.GetArgs();
1371         sal_Bool bShowChildWindow;
1372         sal_uInt16 nSlotId = rRequest.GetSlot();
1373         if (pArguments != NULL)
1374             bShowChildWindow = static_cast<const SfxBoolItem&>(
1375                 pArguments->Get(nSlotId)).GetValue();
1376         else
1377         {
1378             Reference<XConfigurationController> xConfigurationController (
1379                 xControllerManager->getConfigurationController());
1380             if ( ! xConfigurationController.is())
1381                 throw RuntimeException();
1382             Reference<XConfiguration> xConfiguration (
1383                 xConfigurationController->getRequestedConfiguration());
1384             if ( ! xConfiguration.is())
1385                 throw RuntimeException();
1386 
1387             bShowChildWindow = ! xConfiguration->hasResource(xPaneId);
1388         }
1389 
1390         // Set the desired visibility state at the current configuration
1391         // and update it accordingly.
1392         Reference<XConfigurationController> xConfigurationController (
1393             xControllerManager->getConfigurationController());
1394         if ( ! xConfigurationController.is())
1395             throw RuntimeException();
1396         if (bShowChildWindow)
1397         {
1398             xConfigurationController->requestResourceActivation(
1399                 xPaneId,
1400                 ResourceActivationMode_ADD);
1401             xConfigurationController->requestResourceActivation(
1402                 xViewId,
1403                 ResourceActivationMode_REPLACE);
1404         }
1405         else
1406             xConfigurationController->requestResourceDeactivation(
1407                 xPaneId);
1408     }
1409     catch (const Exception &)
1410     {
1411         DBG_UNHANDLED_EXCEPTION();
1412     }
1413 }
1414 
1415 
1416 
1417 
1418 
1419 void ViewShellBase::Implementation::GetSlotState (SfxItemSet& rSet)
1420 {
1421     try
1422     {
1423         // Get some frequently used values.
1424         Reference<XControllerManager> xControllerManager (mrBase.GetController(), UNO_QUERY_THROW);
1425         Reference<XConfigurationController> xConfigurationController (
1426             xControllerManager->getConfigurationController());
1427         if ( ! xConfigurationController.is())
1428             throw RuntimeException();
1429         Reference<XConfiguration> xConfiguration (
1430             xConfigurationController->getRequestedConfiguration());
1431         if ( ! xConfiguration.is())
1432             throw RuntimeException();
1433 
1434         const Reference< XComponentContext > xContext(
1435             ::comphelper::getProcessComponentContext() );
1436         SfxWhichIter aSetIterator (rSet);
1437         sal_uInt16 nItemId (aSetIterator.FirstWhich());
1438         while (nItemId > 0)
1439         {
1440             bool bState (false);
1441             Reference<XResourceId> xResourceId;
1442             try
1443             {
1444                 switch (nItemId)
1445                 {
1446                     case SID_LEFT_PANE_IMPRESS:
1447                         xResourceId = ResourceId::create(
1448                             xContext, FrameworkHelper::msLeftImpressPaneURL);
1449                         break;
1450 
1451                     case SID_LEFT_PANE_DRAW:
1452                         xResourceId = ResourceId::create(
1453                             xContext, FrameworkHelper::msLeftDrawPaneURL);
1454                         break;
1455 
1456                     case SID_TASKPANE:
1457                         xResourceId = ResourceId::create(
1458                             xContext, FrameworkHelper::msRightPaneURL);
1459                         break;
1460 
1461                     case SID_NORMAL_MULTI_PANE_GUI:
1462                         xResourceId = ResourceId::createWithAnchorURL(
1463                             xContext,
1464                             FrameworkHelper::msImpressViewURL,
1465                             FrameworkHelper::msCenterPaneURL);
1466                         break;
1467 
1468                     case SID_SLIDE_SORTER_MULTI_PANE_GUI:
1469                     case SID_DIAMODE:
1470                         xResourceId = ResourceId::createWithAnchorURL(
1471                             xContext,
1472                             FrameworkHelper::msSlideSorterURL,
1473                             FrameworkHelper::msCenterPaneURL);
1474                         break;
1475 
1476                     case SID_OUTLINEMODE:
1477                         xResourceId = ResourceId::createWithAnchorURL(
1478                             xContext,
1479                             FrameworkHelper::msOutlineViewURL,
1480                             FrameworkHelper::msCenterPaneURL);
1481                         break;
1482 
1483                     case SID_HANDOUTMODE:
1484                         // There is only the master page mode for the handout
1485                         // view so ignore the master page flag.
1486                         xResourceId = ResourceId::createWithAnchorURL(
1487                             xContext,
1488                             FrameworkHelper::msHandoutViewURL,
1489                             FrameworkHelper::msCenterPaneURL);
1490                         break;
1491 
1492                     case SID_NOTESMODE:
1493                         xResourceId = ResourceId::createWithAnchorURL(
1494                             xContext,
1495                             FrameworkHelper::msNotesViewURL,
1496                             FrameworkHelper::msCenterPaneURL);
1497                         break;
1498 
1499                     default:
1500                         // Ignore all other items.  They are not meant to be
1501                         // handled by us.
1502                         break;
1503                 }
1504             }
1505             catch (DeploymentException)
1506             {
1507             }
1508 
1509             // Determine the state for the resource.
1510             bState = xConfiguration->hasResource(xResourceId);
1511 
1512             // Take the master page mode into account.
1513             switch (nItemId)
1514             {
1515                 case SID_NORMAL_MULTI_PANE_GUI:
1516                 case SID_NOTESMODE:
1517                 {
1518                     // Determine the master page mode.
1519                     ViewShell* pCenterViewShell = FrameworkHelper::Instance(mrBase)->GetViewShell(
1520                         FrameworkHelper::msCenterPaneURL).get();
1521                     bool bMasterPageMode (false);
1522                     if (pCenterViewShell!=NULL && pCenterViewShell->ISA(DrawViewShell))
1523                         if (PTR_CAST(DrawViewShell,pCenterViewShell)->GetEditMode()
1524                             == EM_MASTERPAGE)
1525                         {
1526                             bMasterPageMode = true;
1527                         }
1528 
1529                     bState &= !bMasterPageMode;
1530                     break;
1531                 }
1532 
1533                 case SID_HANDOUTMODE:
1534                     // There is only the master page mode for the handout
1535                     // view so ignore the master page flag.
1536                     break;
1537             }
1538 
1539             // And finally set the state.
1540             rSet.Put(SfxBoolItem(nItemId, bState));
1541 
1542             nItemId = aSetIterator.NextWhich();
1543         }
1544     }
1545     catch (RuntimeException&)
1546     {
1547         DBG_UNHANDLED_EXCEPTION();
1548     }
1549 
1550 }
1551 
1552 
1553 
1554 
1555 void ViewShellBase::Implementation::ProcessTaskPaneSlot (SfxRequest& rRequest)
1556 {
1557     // Set the visibility state of the toolpanel and one of its top
1558     // level panels.
1559     sal_Bool bShowToolPanel = sal_True;
1560     toolpanel::PanelId nPanelId (
1561         toolpanel::PID_UNKNOWN);
1562     bool bPanelIdGiven = false;
1563 
1564     // Extract the given arguments.
1565 	const SfxItemSet* pArgs = rRequest.GetArgs();
1566     if (pArgs)
1567     {
1568         if ((pArgs->Count() == 1) || (pArgs->Count() == 2))
1569         {
1570             SFX_REQUEST_ARG (rRequest, pIsPanelVisible,
1571                 SfxBoolItem, ID_VAL_ISVISIBLE, sal_False);
1572             if (pIsPanelVisible != NULL)
1573                 bShowToolPanel = pIsPanelVisible->GetValue();
1574         }
1575         if (pArgs->Count() == 2)
1576         {
1577             SFX_REQUEST_ARG (rRequest, pPanelId, SfxUInt32Item,
1578                 ID_VAL_PANEL_INDEX, sal_False);
1579             if (pPanelId != NULL)
1580             {
1581                 nPanelId = static_cast<
1582                     toolpanel::PanelId>(
1583                         pPanelId->GetValue());
1584                 bPanelIdGiven = true;
1585             }
1586         }
1587     }
1588 
1589     // Ignore the request for some combinations of panels and view
1590     // shell types.
1591     if (bPanelIdGiven
1592         && ! (nPanelId==toolpanel::PID_LAYOUT
1593             && mrBase.GetMainViewShell()!=NULL
1594             && mrBase.GetMainViewShell()->GetShellType()==ViewShell::ST_OUTLINE))
1595     {
1596         framework::FrameworkHelper::Instance(mrBase)->RequestTaskPanel(
1597             framework::FrameworkHelper::msLayoutTaskPanelURL);
1598     }
1599 }
1600 
1601 
1602 } // end of namespace sd
1603 
1604 
1605 
1606 
1607 //===== CurrentPageSetter ===========================================
1608 
1609 namespace {
1610 
1611 CurrentPageSetter::CurrentPageSetter (ViewShellBase& rBase)
1612     : mrBase(rBase)
1613 {
1614 }
1615 
1616 
1617 
1618 
1619 
1620 void CurrentPageSetter::operator() (bool)
1621 {
1622     FrameView* pFrameView = NULL;
1623 
1624     if (mrBase.GetMainViewShell() != NULL)
1625     {
1626         pFrameView = mrBase.GetMainViewShell()->GetFrameView();
1627     }
1628 
1629     if (pFrameView!=NULL)
1630     {
1631         try
1632         {
1633             // Get the current page either from the DrawPagesSupplier or the
1634             // MasterPagesSupplier.
1635             Any aPage;
1636             if (pFrameView->GetViewShEditModeOnLoad() == EM_PAGE)
1637             {
1638                 Reference<drawing::XDrawPagesSupplier> xPagesSupplier (
1639                     mrBase.GetController()->getModel(), UNO_QUERY_THROW);
1640                 Reference<container::XIndexAccess> xPages (
1641                     xPagesSupplier->getDrawPages(), UNO_QUERY_THROW);
1642                 aPage = xPages->getByIndex(pFrameView->GetSelectedPageOnLoad());
1643             }
1644             else
1645             {
1646                 Reference<drawing::XMasterPagesSupplier> xPagesSupplier (
1647                     mrBase.GetController()->getModel(), UNO_QUERY_THROW);
1648                 Reference<container::XIndexAccess> xPages (
1649                     xPagesSupplier->getMasterPages(), UNO_QUERY_THROW);
1650                 aPage = xPages->getByIndex(pFrameView->GetSelectedPageOnLoad());
1651             }
1652             // Switch to the page last edited by setting the CurrentPage
1653             // property.
1654             Reference<beans::XPropertySet> xSet (mrBase.GetController(), UNO_QUERY_THROW);
1655             xSet->setPropertyValue (String::CreateFromAscii("CurrentPage"), aPage);
1656         }
1657         catch (RuntimeException aException)
1658         {
1659             // We have not been able to set the current page at the main view.
1660             // This is sad but still leaves us in a valid state.  Therefore,
1661             // this exception is silently ignored.
1662         }
1663         catch (beans::UnknownPropertyException aException)
1664         {
1665             DBG_ASSERT(false,"CurrentPage property unknown");
1666         }
1667     }
1668 }
1669 
1670 } // end of anonymouse namespace
1671 
1672 
1673 
1674 
1675 //===== FocusForwardingWindow =================================================
1676 
1677 namespace sd { namespace {
1678 
1679 FocusForwardingWindow::FocusForwardingWindow (
1680     ::Window& rParentWindow,
1681     ViewShellBase& rBase)
1682     : ::Window(&rParentWindow, WinBits(WB_CLIPCHILDREN | WB_DIALOGCONTROL)),
1683         mrBase(rBase)
1684 {
1685     OSL_TRACE("created FocusForwardingWindow at %x", this);
1686 }
1687 
1688 
1689 
1690 
1691 FocusForwardingWindow::~FocusForwardingWindow (void)
1692 {
1693     OSL_TRACE("destroyed FocusForwardingWindow at %x", this);
1694 }
1695 
1696 
1697 
1698 
1699 void FocusForwardingWindow::KeyInput (const KeyEvent& rKEvt)
1700 {
1701     ::boost::shared_ptr<ViewShell> pViewShell = mrBase.GetMainViewShell();
1702     if (pViewShell.get() != NULL)
1703     {
1704         ::Window* pWindow = pViewShell->GetActiveWindow();
1705         if (pWindow != NULL)
1706         {
1707             // Forward the focus so that the window is called directly the
1708             // next time.
1709             pWindow->GrabFocus();
1710             // Forward the key press as well.
1711             pWindow->KeyInput(rKEvt);
1712         }
1713     }
1714 }
1715 
1716 
1717 
1718 
1719 void FocusForwardingWindow::Command (const CommandEvent& rEvent)
1720 {
1721     ::boost::shared_ptr<ViewShell> pViewShell = mrBase.GetMainViewShell();
1722     if (pViewShell.get() != NULL)
1723     {
1724         ::Window* pWindow = pViewShell->GetActiveWindow();
1725         if (pWindow != NULL)
1726         {
1727             pWindow->Command(rEvent);
1728         }
1729     }
1730 }
1731 
1732 
1733 } // end of anonymouse namespace
1734 
1735 } // end of namespace sd
1736