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