fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / sd / source / ui / toolpanel / ToolPanelViewShell.cxx
blob8765c89456665490bdc5377f976a09699d0e99ab
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "taskpane/ToolPanelViewShell.hxx"
23 #include "TaskPaneShellManager.hxx"
24 #include "TaskPaneFocusManager.hxx"
25 #include "taskpane/TaskPaneControlFactory.hxx"
26 #include "controls/MasterPagesPanel.hxx"
27 #include "LayoutMenu.hxx"
28 #include "DrawDocShell.hxx"
29 #include "controls/TableDesignPanel.hxx"
30 #include "controls/CustomAnimationPanel.hxx"
31 #include "controls/SlideTransitionPanel.hxx"
32 #include "controls/MasterPagesSelector.hxx"
33 #include "ToolPanel.hxx"
34 #include "ToolPanelUIElement.hxx"
35 #include "PaneDockingWindow.hxx"
36 #include "FrameView.hxx"
37 #include "Window.hxx"
38 #include "sdmod.hxx"
39 #include "app.hrc"
40 #include "glob.hrc"
41 #include "res_bmp.hrc"
42 #include "helpids.h"
43 #include "strings.hrc"
44 #include "sdresid.hxx"
45 #include "framework/FrameworkHelper.hxx"
47 #include <com/sun/star/drawing/framework/XResourceId.hpp>
48 #include <com/sun/star/drawing/framework/ResourceActivationMode.hpp>
49 #include <com/sun/star/drawing/framework/AnchorBindingMode.hpp>
50 #include <com/sun/star/drawing/XDrawSubController.hpp>
52 #include <svtools/toolpanel/toolpanel.hxx>
53 #include <svtools/toolpanel/toolpaneldeck.hxx>
54 #include <svx/dlgctrl.hxx>
55 #include <sfx2/taskpane.hxx>
56 #include <sfx2/imagemgr.hxx>
57 #include <sfx2/bindings.hxx>
58 #include <sfx2/dispatch.hxx>
59 #include <sfx2/viewfrm.hxx>
60 #include <sfx2/msg.hxx>
61 #include <sfx2/objface.hxx>
62 #include <svx/colrctrl.hxx>
63 #include <svx/xtable.hxx>
64 #include <vcl/dockwin.hxx>
65 #include "sdtreelb.hxx"
66 #include "DrawViewShell.hxx"
67 #include "drawdoc.hxx"
68 #include "ViewShellBase.hxx"
69 #include <svx/ruler.hxx>
70 #include <vcl/svapp.hxx>
71 #include <vcl/toolbox.hxx>
72 #include <tools/diagnose_ex.h>
73 #include <unotools/confignode.hxx>
74 #include <comphelper/processfactory.hxx>
75 #include <comphelper/componentcontext.hxx>
76 #include <cppuhelper/implbase1.hxx>
77 #include <cppuhelper/basemutex.hxx>
79 #include <vector>
81 using namespace ::sd::toolpanel;
83 #define ToolPanelViewShell
84 #include "sdslots.hxx"
86 using ::com::sun::star::uno::Reference;
87 using ::com::sun::star::uno::XInterface;
88 using ::com::sun::star::uno::UNO_QUERY;
89 using ::com::sun::star::uno::UNO_QUERY_THROW;
90 using ::com::sun::star::uno::UNO_SET_THROW;
91 using ::com::sun::star::uno::Exception;
92 using ::com::sun::star::uno::RuntimeException;
93 using ::com::sun::star::uno::Any;
94 using ::com::sun::star::uno::makeAny;
95 using ::com::sun::star::uno::Sequence;
96 using ::com::sun::star::uno::Type;
97 using ::com::sun::star::accessibility::XAccessible;
98 using ::com::sun::star::drawing::XDrawSubController;
99 using ::com::sun::star::frame::XFrame;
100 using ::com::sun::star::drawing::framework::XResourceId;
101 using ::com::sun::star::drawing::framework::XConfigurationChangeListener;
102 using ::com::sun::star::drawing::framework::ConfigurationChangeEvent;
103 using ::com::sun::star::lang::EventObject;
104 using ::com::sun::star::lang::DisposedException;
105 using ::com::sun::star::drawing::framework::XConfigurationControllerBroadcaster;
106 using ::com::sun::star::drawing::framework::XConfigurationController;
107 using ::com::sun::star::drawing::framework::XConfiguration;
108 using ::com::sun::star::drawing::framework::AnchorBindingMode_DIRECT;
109 using ::com::sun::star::ui::XUIElement;
110 using ::com::sun::star::ui::XToolPanel;
111 using ::com::sun::star::drawing::framework::ResourceActivationMode_REPLACE;
113 using ::sd::framework::FrameworkHelper;
115 namespace sd { namespace toolpanel {
117 // =====================================================================================================================
118 // = misc helper
119 // =====================================================================================================================
120 // ---------------------------------------------------------------------------------------------------------------------
121 PanelId GetStandardPanelId( const OUString& i_rTaskPanelResourceURL, const bool i_bIgnoreUnknown )
123 PanelId ePanelId( PID_UNKNOWN );
125 if ( i_rTaskPanelResourceURL.equals( FrameworkHelper::msMasterPagesTaskPanelURL ) )
127 ePanelId = PID_MASTER_PAGES;
129 else if ( i_rTaskPanelResourceURL.equals( FrameworkHelper::msLayoutTaskPanelURL ) )
131 ePanelId = PID_LAYOUT;
133 else if ( i_rTaskPanelResourceURL.equals( FrameworkHelper::msTableDesignPanelURL ) )
135 ePanelId = PID_TABLE_DESIGN;
137 else if ( i_rTaskPanelResourceURL.equals( FrameworkHelper::msCustomAnimationTaskPanelURL ) )
139 ePanelId = PID_CUSTOM_ANIMATION;
141 else if ( i_rTaskPanelResourceURL.equals( FrameworkHelper::msSlideTransitionTaskPanelURL ) )
143 ePanelId = PID_SLIDE_TRANSITION;
145 else
147 OSL_ENSURE( i_bIgnoreUnknown, "GetStandardPanelId: cannot translate the given resource URL!" );
148 (void)i_bIgnoreUnknown;
151 return ePanelId;
154 // ---------------------------------------------------------------------------------------------------------------------
155 PanelId GetStandardPanelId( const OUString& i_rTaskPanelResourceURL )
157 return GetStandardPanelId( i_rTaskPanelResourceURL, false );
160 // =====================================================================================================================
161 // = ConfigurationListener - declaration
162 // =====================================================================================================================
163 typedef ::cppu::WeakImplHelper1 < XConfigurationChangeListener
164 > ConfigurationListener_Base;
166 class ConfigurationListener :public ::cppu::BaseMutex
167 ,public ConfigurationListener_Base
169 public:
170 ConfigurationListener( ToolPanelViewShell_Impl& i_rShellImpl );
172 // XConfigurationChangeListener
173 virtual void SAL_CALL notifyConfigurationChange( const ConfigurationChangeEvent& aEvent ) throw (RuntimeException);
175 // XEventListener
176 virtual void SAL_CALL disposing( const EventObject& Source ) throw (RuntimeException);
178 // XComponent equivalents (not available per UNO interface)
179 void dispose();
181 protected:
182 ~ConfigurationListener();
184 void impl_checkDisposed_throw()
186 if ( !m_pShellImpl )
187 throw DisposedException( OUString(), *this );
190 private:
191 ToolPanelViewShell_Impl* m_pShellImpl;
194 // =====================================================================================================================
195 // = ToolPanelViewShell_Impl - declaration
196 // =====================================================================================================================
197 /** Inner implementation class of ToolPanelViewShell.
199 class ToolPanelViewShell_Impl :public ::boost::noncopyable
200 ,public ::svt::IToolPanelDeckListener
201 ,public ::sfx2::IToolPanelCompare
203 public:
204 static const size_t mnInvalidId = static_cast< size_t >( -1 );
206 ToolPanelViewShell_Impl( ToolPanelViewShell& i_rPanelViewShell, ::Window& i_rPanelDeckParent );
207 virtual ~ToolPanelViewShell_Impl();
209 ToolPanelViewShell& GetAntiImpl() { return m_rPanelViewShell; }
211 /** Here the panels are created that are shown in the task pane.
213 void Setup();
215 /** clean up the instance
217 void Cleanup();
219 /** activates the panel which has the given resource URL
221 void ActivatePanelByResource( const OUString& i_rPanelResourceURL );
223 /** de-activates the panel given by its resource URL, bypassing the configuration controller
225 If the panel is not active currently, nothing happens.
227 void DeactivatePanelByResource( const OUString& i_rPanelResourceURL );
229 /** provides access to the VCL window of the panel deck
231 ::sfx2::ModuleTaskPane& GetTaskPane() { return *m_pTaskPane; }
232 const ::sfx2::ModuleTaskPane& GetTaskPane() const { return *m_pTaskPane; }
234 ::svt::ToolPanelDeck& GetToolPanelDeck() { return GetTaskPane().GetPanelDeck(); }
235 const ::svt::ToolPanelDeck& GetToolPanelDeck() const { return GetTaskPane().GetPanelDeck(); }
237 Reference< XAccessible >
238 CreateAccessible( ::sd::Window& i_rWindow );
240 void ConnectToDockingWindow();
242 private:
243 // IToolPanelDeckListener overridables
244 virtual void PanelInserted( const ::svt::PToolPanel& i_pPanel, const size_t i_nPosition );
245 virtual void PanelRemoved( const size_t i_nPosition );
246 virtual void ActivePanelChanged( const ::boost::optional< size_t >& i_rOldActive, const ::boost::optional< size_t >& i_rNewActive );
247 virtual void LayouterChanged( const ::svt::PDeckLayouter& i_rNewLayouter );
248 virtual void Dying();
250 // IToolPanelCompare overridables
251 virtual short compareToolPanelsURLs( const OUString& i_rLHS, const OUString& i_rRHS ) const;
253 private:
254 struct InitialPanel
256 OUString sPanelResourceURL;
257 bool bActivateDirectly;
258 InitialPanel()
259 :sPanelResourceURL()
260 ,bActivateDirectly( true )
264 InitialPanel impl_determineInitialPanel();
265 OUString impl_getPanelURL( const ::boost::optional< size_t >& i_rPanel );
267 private:
268 ToolPanelViewShell& m_rPanelViewShell;
269 ::boost::scoped_ptr< ::sfx2::ModuleTaskPane > m_pTaskPane;
270 SAL_WNODEPRECATED_DECLARATIONS_PUSH
271 ::std::auto_ptr< ::sfx2::TaskPaneController > m_pTaskPaneController;
272 SAL_WNODEPRECATED_DECLARATIONS_POP
273 ::rtl::Reference< ConfigurationListener > m_pConfigListener;
274 bool m_bInitialized;
277 // =====================================================================================================================
278 // = ConfigurationListener - implementation
279 // =====================================================================================================================
280 // ---------------------------------------------------------------------------------------------------------------------
281 ConfigurationListener::ConfigurationListener( ToolPanelViewShell_Impl& i_rShellImpl )
282 :m_pShellImpl( &i_rShellImpl )
284 ::boost::shared_ptr< FrameworkHelper > pFrameworkHelper( FrameworkHelper::Instance( i_rShellImpl.GetAntiImpl().GetViewShellBase() ) );
285 Reference< XConfigurationControllerBroadcaster > xBroadcaster;
286 if ( pFrameworkHelper.get() )
287 xBroadcaster.set( pFrameworkHelper->GetConfigurationController().get() );
288 ENSURE_OR_THROW( pFrameworkHelper.get(), "no access to the config controller" );
290 osl_atomic_increment( &m_refCount );
292 xBroadcaster->addConfigurationChangeListener( this, OUString(), Any() );
294 osl_atomic_decrement( &m_refCount );
297 // ---------------------------------------------------------------------------------------------------------------------
298 ConfigurationListener::~ConfigurationListener()
302 // ---------------------------------------------------------------------------------------------------------------------
303 void SAL_CALL ConfigurationListener::notifyConfigurationChange( const ConfigurationChangeEvent& i_rEvent ) throw (RuntimeException)
305 ::osl::MutexGuard aGuard( m_aMutex );
306 impl_checkDisposed_throw();
308 // is this an event we're interested in?
309 if ( i_rEvent.Type != FrameworkHelper::msResourceActivationEvent )
310 return;
312 // is this a resource we're interested in? Must be anchored in the task pane ...
313 Reference< XResourceId > xAnchorId;
314 if ( i_rEvent.ResourceId.is() )
315 xAnchorId = i_rEvent.ResourceId->getAnchor();
316 if ( !xAnchorId.is() )
317 return;
318 const OUString sAnchorURL( xAnchorId->getResourceURL() );
319 if ( sAnchorURL != FrameworkHelper::msTaskPaneURL )
320 return;
322 m_pShellImpl->ActivatePanelByResource( i_rEvent.ResourceId->getResourceURL() );
325 // ---------------------------------------------------------------------------------------------------------------------
326 void SAL_CALL ConfigurationListener::disposing( const EventObject& i_rEvent ) throw (RuntimeException)
328 (void)i_rEvent;
330 ::osl::MutexGuard aGuard( m_aMutex );
331 impl_checkDisposed_throw();
334 dispose();
337 // ---------------------------------------------------------------------------------------------------------------------
338 void ConfigurationListener::dispose()
340 ::osl::MutexGuard aGuard( m_aMutex );
341 m_pShellImpl = NULL;
344 // =====================================================================================================================
345 // = ToolPanelViewShell
346 // =====================================================================================================================
347 // ---------------------------------------------------------------------------------------------------------------------
348 SFX_IMPL_INTERFACE(ToolPanelViewShell, SfxShell, SdResId(STR_TASKPANEVIEWSHELL))
352 // ---------------------------------------------------------------------------------------------------------------------
353 TYPEINIT1(ToolPanelViewShell, ViewShell);
355 // ---------------------------------------------------------------------------------------------------------------------
356 ToolPanelViewShell_Impl::InitialPanel ToolPanelViewShell_Impl::impl_determineInitialPanel()
358 InitialPanel aPanelToActivate;
359 if ( GetAntiImpl().GetViewShellBase().GetDocShell()->GetDocumentType() == DOCUMENT_TYPE_DRAW )
360 // for Draw, rely on SFX's default handling, which is to activate the previously active panel
361 return aPanelToActivate;
363 // Default to Layout panel, but check whether the requested configuration already contains a tool panel, in this case,
364 // use that one.
365 aPanelToActivate.sPanelResourceURL = FrameworkHelper::msLayoutTaskPanelURL;
366 aPanelToActivate.bActivateDirectly = false;
369 ::boost::shared_ptr< FrameworkHelper > pFrameworkHelper( FrameworkHelper::Instance( m_rPanelViewShell.GetViewShellBase() ) );
370 const Reference< XResourceId > xToolPanelId( pFrameworkHelper->CreateResourceId( FrameworkHelper::msTaskPaneURL, FrameworkHelper::msRightPaneURL ) );
371 Reference< XConfigurationController > xCC( pFrameworkHelper->GetConfigurationController(), UNO_QUERY_THROW );
372 Reference< XConfiguration > xConfiguration( xCC->getRequestedConfiguration(), UNO_QUERY_THROW );
373 Sequence< Reference< XResourceId > > aViewIds( xConfiguration->getResources(
374 FrameworkHelper::CreateResourceId( FrameworkHelper::msTaskPaneURL, FrameworkHelper::msRightPaneURL ),
375 FrameworkHelper::msTaskPanelURLPrefix, AnchorBindingMode_DIRECT ) );
377 if ( aViewIds.getLength() > 0 )
379 const OUString sResourceURL( aViewIds[0]->getResourceURL() );
380 PanelId nRequestedPanel = GetStandardPanelId( sResourceURL );
381 if ( nRequestedPanel != PID_UNKNOWN )
383 aPanelToActivate.sPanelResourceURL = sResourceURL;
384 aPanelToActivate.bActivateDirectly = true;
388 catch( const Exception& )
390 DBG_UNHANDLED_EXCEPTION();
392 return aPanelToActivate;
395 // ---------------------------------------------------------------------------------------------------------------------
396 void ToolPanelViewShell_Impl::Setup()
398 if ( m_bInitialized )
399 return;
400 m_bInitialized = true;
402 // initially activate a panel
403 const InitialPanel aInitialPanel = impl_determineInitialPanel();
404 if ( !aInitialPanel.sPanelResourceURL.isEmpty() )
406 if ( aInitialPanel.bActivateDirectly )
408 ActivatePanelByResource( aInitialPanel.sPanelResourceURL );
410 else
412 ::boost::shared_ptr< FrameworkHelper > pFrameworkHelper( FrameworkHelper::Instance( GetAntiImpl().GetViewShellBase() ) );
413 pFrameworkHelper->RequestSidebarPanel( aInitialPanel.sPanelResourceURL );
417 // listen at the configuration
418 m_pConfigListener.set( new ConfigurationListener( *this ) );
420 m_pTaskPane->Show();
423 // ---------------------------------------------------------------------------------------------------------------------
424 void ToolPanelViewShell_Impl::Cleanup()
426 if ( m_bInitialized )
428 if ( m_pConfigListener.is() )
429 m_pConfigListener->dispose();
431 GetToolPanelDeck().RemoveListener( *this );
432 m_pTaskPaneController.reset();
433 m_pTaskPane.reset();
436 // ---------------------------------------------------------------------------------------------------------------------
437 void ToolPanelViewShell_Impl::ActivatePanelByResource( const OUString& i_rResourceURL )
439 // determine position of the requested panel
440 ::boost::optional< size_t > aPanelPos = GetTaskPane().GetPanelPos( i_rResourceURL );
441 OSL_ENSURE( !!aPanelPos, "ToolPanelViewShell_Impl::ActivatePanelByResource: illegal panel resource, or illegal panel deck setup!" );
442 if ( !!aPanelPos )
443 GetToolPanelDeck().ActivatePanel( *aPanelPos );
446 // ---------------------------------------------------------------------------------------------------------------------
447 void ToolPanelViewShell_Impl::DeactivatePanelByResource( const OUString& i_rPanelResourceURL )
449 // determine position of the requested panel
450 ::boost::optional< size_t > aPanelPos = GetTaskPane().GetPanelPos( i_rPanelResourceURL );
451 OSL_ENSURE( !!aPanelPos, "ToolPanelViewShell_Impl::DeactivatePanelByResource: illegal panel resource, or illegal panel deck setup!" );
452 if ( !!aPanelPos )
454 if ( GetToolPanelDeck().GetActivePanel() == *aPanelPos )
455 GetToolPanelDeck().ActivatePanel( ::boost::optional< size_t >() );
459 // ---------------------------------------------------------------------------------------------------------------------
460 void ToolPanelViewShell::Initialize()
462 mpImpl->Setup();
465 // ---------------------------------------------------------------------------------------------------------------------
466 ToolPanelViewShell::ToolPanelViewShell( SfxViewFrame* pFrame, ViewShellBase& rViewShellBase, ::Window* pParentWindow,
467 FrameView* pFrameViewArgument )
468 :ViewShell(pFrame, pParentWindow, rViewShellBase)
469 ,mpImpl( new ToolPanelViewShell_Impl( *this, *mpContentWindow.get() ) )
470 ,mpSubShellManager()
471 ,mnMenuId(0)
473 doShow();
475 meShellType = ST_TASK_PANE;
477 mpContentWindow->SetCenterAllowed( false );
478 pParentWindow->SetStyle( pParentWindow->GetStyle() | WB_DIALOGCONTROL );
480 GetParentWindow()->SetBackground( Wallpaper() );
481 mpContentWindow->SetBackground( Wallpaper() );
483 GetParentWindow()->SetHelpId(HID_SD_TASK_PANE);
485 mpImpl->ConnectToDockingWindow();
487 SetPool( &GetDoc()->GetPool() );
489 if ( pFrameViewArgument )
490 mpFrameView = pFrameViewArgument;
491 else
492 mpFrameView = new FrameView( GetDoc() );
493 GetFrameView()->Connect();
495 // Hide or delete unused controls that we have inherited from the
496 // ViewShell base class.
497 mpHorizontalScrollBar.reset();
498 mpVerticalScrollBar.reset();
499 mpScrollBarBox.reset();
500 mpHorizontalRuler.reset();
501 mpVerticalRuler.reset();
503 SetName( OUString( "ToolPanelViewShell" ) );
505 // enforce the creation of the Accessible object here.
506 // In some not-always-to-reproduce situations, creating the accessible on demand only leads to some
507 // cycliy parenthood references between the involved objects, which make some AT tools (accerciser, in particular)
508 // loop (which is /not/ a bug in the tool, of course).
509 // However, since those situations were not reproducible anymore, we deliberately leave the Accessible creation
510 // (which originally was intended as a workaround) herein. Better to be safe ...
511 // Note that this is not a performance problem: The implementation of the ToolPanelDeck's Accessible
512 // is separated from the implementation of its AccessibleContext (which even is in a separate library) - we only
513 // create the former here, the latter is still created on demand, when somebody requests it.
514 // #i113671# / 2010-09-17 / frank.schoenheit@oracle.com
515 if (mpContentWindow.get())
516 mpContentWindow->GetAccessible( sal_True );
518 // For accessibility we have to shortly hide the content window. This
519 // triggers the construction of a new accessibility object for the new
520 // view shell. (One is created earlier while the construtor of the base
521 // class is executed. At that time the correct accessibility object can
522 // not be constructed.)
523 if (mpContentWindow.get())
525 mpContentWindow->Hide();
526 mpContentWindow->Show();
529 // Register the shell manager as factory at the ViewShellManager.
530 mpSubShellManager.reset( new TaskPaneShellManager(
531 GetViewShellBase().GetViewShellManager(),
532 *this
533 ) );
534 GetViewShellBase().GetViewShellManager()->AddSubShellFactory( this, mpSubShellManager );
537 // ---------------------------------------------------------------------------------------------------------------------
538 ToolPanelViewShell::~ToolPanelViewShell()
540 mpImpl->Cleanup();
542 // reset our impl before destroying the panel deck, to ensure the hidden panels are properly
543 // disposed/destroyed, too
544 mpImpl.reset();
545 GetViewShellBase().GetViewShellManager()->RemoveSubShellFactory(this, mpSubShellManager);
546 GetFrameView()->Disconnect();
549 // ---------------------------------------------------------------------------------------------------------------------
550 // static
551 void ToolPanelViewShell::RegisterControls()
553 SfxModule* pModule = SD_MOD();
554 controls::MasterPagesSelector::RegisterInterface( pModule );
555 LayoutMenu::RegisterInterface( pModule );
558 // ---------------------------------------------------------------------------------------------------------------------
559 void ToolPanelViewShell::ArrangeGUIElements()
561 ViewShell::ArrangeGUIElements();
563 Initialize();
565 mpImpl->GetTaskPane().SetPosSizePixel( Point(), maViewSize );
568 // ---------------------------------------------------------------------------------------------------------------------
569 void ToolPanelViewShell::GetFocus()
571 Invalidate();
574 // ---------------------------------------------------------------------------------------------------------------------
575 void ToolPanelViewShell::LoseFocus()
577 Invalidate();
580 // ---------------------------------------------------------------------------------------------------------------------
581 void ToolPanelViewShell::KeyInput( const KeyEvent& i_rKeyEvent )
583 const KeyCode nCode = i_rKeyEvent.GetKeyCode();
584 if ( nCode == KEY_RETURN )
586 if ( !mpImpl->GetTaskPane().HasChildPathFocus() )
587 mpImpl->GetTaskPane().GrabFocus();
589 else
590 ViewShell::KeyInput( i_rKeyEvent, NULL );
593 // ---------------------------------------------------------------------------------------------------------------------
594 SdPage* ToolPanelViewShell::GetActualPage()
596 return NULL;
599 // ---------------------------------------------------------------------------------------------------------------------
600 SdPage* ToolPanelViewShell::getCurrentPage() const
602 return NULL;
605 // ---------------------------------------------------------------------------------------------------------------------
606 TaskPaneShellManager& ToolPanelViewShell::GetSubShellManager() const
608 return *mpSubShellManager.get();
611 // ---------------------------------------------------------------------------------------------------------------------
612 DockingWindow* ToolPanelViewShell::GetDockingWindow()
614 ::Window* pParentWindow = GetParentWindow();
615 DockingWindow* pDockingWindow = NULL;
616 while (pParentWindow!=NULL && pDockingWindow==NULL)
618 pDockingWindow = dynamic_cast<DockingWindow*>(pParentWindow);
619 pParentWindow = pParentWindow->GetParent();
621 return pDockingWindow;
624 // ---------------------------------------------------------------------------------------------------------------------
625 Reference< XAccessible > ToolPanelViewShell::CreateAccessibleDocumentView( ::sd::Window* i_pWindow )
627 ENSURE_OR_RETURN( i_pWindow, "ToolPanelViewShell::CreateAccessibleDocumentView: illegal window!", NULL );
628 return mpImpl->CreateAccessible( *i_pWindow );
631 // ---------------------------------------------------------------------------------------------------------------------
632 Reference< XDrawSubController > ToolPanelViewShell::CreateSubController()
634 // This view shell is not designed to be the main view shell and thus
635 // does not support a UNO sub controller.
636 return Reference< XDrawSubController >();
639 // ---------------------------------------------------------------------------------------------------------------------
640 bool ToolPanelViewShell::RelocateToParentWindow( ::Window* pParentWindow )
642 ::Window* pOldParentWindow = GetParentWindow();
643 FocusManager::Instance().RemoveLinks( pOldParentWindow, &mpImpl->GetTaskPane() );
644 FocusManager::Instance().RemoveLinks( &mpImpl->GetTaskPane(), pOldParentWindow );
646 PaneDockingWindow* pDockingWindow = dynamic_cast< PaneDockingWindow* >( GetDockingWindow() );
647 if ( pDockingWindow != NULL )
649 pDockingWindow->SetEndDockingHdl( Link() );
652 ViewShell::RelocateToParentWindow(pParentWindow);
654 mpImpl->ConnectToDockingWindow();
656 Resize();
658 return true;
661 //---------------------------------------------------------------------------------------------------------------------
662 bool ToolPanelViewShell::IsPanelAnchorWindow( const ::Window& i_rWindow ) const
664 return &mpImpl->GetToolPanelDeck().GetPanelWindowAnchor() == &i_rWindow;
667 //---------------------------------------------------------------------------------------------------------------------
668 namespace
670 typedef std::auto_ptr< ControlFactory > (*ControlFactoryFactory)( ToolPanelViewShell& i_rToolPanelShell );
672 struct PanelFactory
674 ControlFactoryFactory pFactory;
675 OString sHelpID;
676 PanelFactory( const ControlFactoryFactory i_pFactory, const OString& i_nHelpID )
677 :pFactory( i_pFactory )
678 ,sHelpID( i_nHelpID )
683 const PanelFactory lcl_describePanel( const PanelId i_ePanelId )
685 switch ( i_ePanelId )
687 case PID_MASTER_PAGES:
688 return PanelFactory( &controls::MasterPagesPanel::CreateControlFactory, HID_SD_SLIDE_DESIGNS );
689 case PID_LAYOUT:
690 return PanelFactory( &LayoutMenu::CreateControlFactory, HID_SD_SLIDE_LAYOUTS );
691 case PID_TABLE_DESIGN:
692 return PanelFactory( &controls::TableDesignPanel::CreateControlFactory, HID_SD_TABLE_DESIGN );
693 case PID_CUSTOM_ANIMATION:
694 return PanelFactory( &controls::CustomAnimationPanel::CreateControlFactory, HID_SD_CUSTOM_ANIMATIONS );
695 case PID_SLIDE_TRANSITION:
696 return PanelFactory( &controls::SlideTransitionPanel::CreateControlFactory, HID_SD_SLIDE_TRANSITIONS );
697 default:
698 break;
700 throw RuntimeException( "illegal panel ID" , NULL );
704 //---------------------------------------------------------------------------------------------------------------------
705 Reference< XUIElement > ToolPanelViewShell::CreatePanelUIElement( const Reference< XFrame >& i_rDocFrame, const OUString& i_rPanelResourceURL )
707 const PanelId ePanelId( GetStandardPanelId( i_rPanelResourceURL ) );
708 ENSURE_OR_RETURN( ePanelId != PID_UNKNOWN, "ToolPanelViewShell::CreatePanelUIElement: illegal panel URL!", NULL );
710 // a TreeNode which will resemble the panel
711 const PanelFactory aPanelFactory( lcl_describePanel( ePanelId ) );
712 SAL_WNODEPRECATED_DECLARATIONS_PUSH
713 ::std::auto_ptr< ControlFactory > pControlFactory( (*aPanelFactory.pFactory)( *this ) );
714 ::std::auto_ptr< TreeNode > pNode( pControlFactory->CreateControl( mpImpl->GetToolPanelDeck().GetPanelWindowAnchor() ) );
715 SAL_WNODEPRECATED_DECLARATIONS_POP
716 ENSURE_OR_THROW( ( pNode.get() != NULL ) && ( pNode->GetWindow() != NULL ),
717 "illegal node returned by the control factory" );
718 pNode->GetWindow()->SetHelpId( aPanelFactory.sHelpID );
720 // create an XToolPanel
721 Reference< XToolPanel > xPanel( new ToolPanel( pNode ) );
723 // create an XUIElement providing this panel
724 const Reference< XUIElement > xUIElement( new ToolPanelUIElement( i_rDocFrame, i_rPanelResourceURL, xPanel ) );
726 return xUIElement;
729 // ---------------------------------------------------------------------------------------------------------------------
730 void ToolPanelViewShell::ActivatePanel( const OUString& i_rPanelResourceURL )
732 OSL_ENSURE( i_rPanelResourceURL.indexOf( FrameworkHelper::msTaskPanelURLPrefix ) < 0,
733 "ToolPanelViewShell::ActivatePanel: for drawing-framework-controller panels, please use FrameworkHelper::RequestTaskPanel!" );
734 mpImpl->ActivatePanelByResource( i_rPanelResourceURL );
737 // ---------------------------------------------------------------------------------------------------------------------
738 void ToolPanelViewShell::DeactivatePanel( const OUString& i_rPanelResourceURL )
740 mpImpl->DeactivatePanelByResource( i_rPanelResourceURL );
743 // =====================================================================================================================
744 // = ToolPanelViewShell_Impl - implementation
745 // =====================================================================================================================
746 // ---------------------------------------------------------------------------------------------------------------------
747 ToolPanelViewShell_Impl::ToolPanelViewShell_Impl( ToolPanelViewShell& i_rPanelViewShell, ::Window& i_rPanelDeckParent )
748 :m_rPanelViewShell( i_rPanelViewShell )
749 ,m_pTaskPane( new ::sfx2::ModuleTaskPane( i_rPanelDeckParent, i_rPanelViewShell.GetViewShellBase().GetViewFrame()->GetFrame().GetFrameInterface(), *this ) )
750 ,m_bInitialized( false )
752 const String sPaneTitle( SdResId( STR_RIGHT_PANE_TITLE ) );
753 GetToolPanelDeck().SetAccessibleName( sPaneTitle );
754 GetToolPanelDeck().SetAccessibleDescription( sPaneTitle );
756 GetToolPanelDeck().AddListener( *this );
759 // ---------------------------------------------------------------------------------------------------------------------
760 ToolPanelViewShell_Impl::~ToolPanelViewShell_Impl()
764 // ---------------------------------------------------------------------------------------------------------------------
765 void ToolPanelViewShell_Impl::PanelInserted( const ::svt::PToolPanel& i_pPanel, const size_t i_nPosition )
767 // not interested in
768 (void)i_pPanel;
769 (void)i_nPosition;
772 // ---------------------------------------------------------------------------------------------------------------------
773 void ToolPanelViewShell_Impl::PanelRemoved( const size_t i_nPosition )
775 // not interested in
776 (void)i_nPosition;
779 // ---------------------------------------------------------------------------------------------------------------------
780 OUString ToolPanelViewShell_Impl::impl_getPanelURL( const ::boost::optional< size_t >& i_rPanel )
782 OUString sPanelURL;
783 if ( !!i_rPanel )
785 sPanelURL = GetTaskPane().GetPanelResourceURL( *i_rPanel );
786 const PanelId ePanelId( GetStandardPanelId( sPanelURL, true ) );
787 if ( ePanelId == PID_UNKNOWN )
788 sPanelURL = OUString();
790 return sPanelURL;
793 // ---------------------------------------------------------------------------------------------------------------------
794 void ToolPanelViewShell_Impl::ActivePanelChanged( const ::boost::optional< size_t >& i_rOldActive, const ::boost::optional< size_t >& i_rNewActive )
796 // update the configuration controller, since this change in the active panel might have been triggered by means other
797 // than the drawing framework, so it does not yet know about it.
799 const OUString sOldPanelURL( impl_getPanelURL( i_rOldActive ) );
800 const OUString sNewPanelURL( impl_getPanelURL( i_rNewActive ) );
802 const ::boost::shared_ptr< FrameworkHelper > pFrameworkHelper( FrameworkHelper::Instance( GetAntiImpl().GetViewShellBase() ) );
803 if ( !sNewPanelURL.isEmpty() )
805 // activate the resource belonging to the new panel. This will automatically de-activate the previously active
806 // panel resource (since ResourceActivationMode_REPLACE is used)
807 pFrameworkHelper->RequestSidebarPanel( sNewPanelURL );
809 else if ( !sOldPanelURL.isEmpty() )
811 // there is no new active panel, or it is not one of our standard panels, i.e. it is not covered by the
812 // resource framework. => Deactivate the old resource.
815 Reference< XConfigurationController > xConfigController( pFrameworkHelper->GetConfigurationController(), UNO_QUERY_THROW );
816 xConfigController->requestResourceDeactivation(
817 pFrameworkHelper->CreateResourceId(
818 sOldPanelURL,
819 FrameworkHelper::msTaskPaneURL,
820 FrameworkHelper::msRightPaneURL
824 catch( const Exception& )
826 DBG_UNHANDLED_EXCEPTION();
831 // ---------------------------------------------------------------------------------------------------------------------
832 void ToolPanelViewShell_Impl::LayouterChanged( const ::svt::PDeckLayouter& i_rNewLayouter )
834 // not interested in
835 (void)i_rNewLayouter;
838 // ---------------------------------------------------------------------------------------------------------------------
839 void ToolPanelViewShell_Impl::Dying()
841 // not interested in
844 // ---------------------------------------------------------------------------------------------------------------------
845 short ToolPanelViewShell_Impl::compareToolPanelsURLs( const OUString& i_rLHS, const OUString& i_rRHS ) const
847 const PanelId eLHS( GetStandardPanelId( i_rLHS, true ) );
848 const PanelId eRHS( GetStandardPanelId( i_rRHS, true ) );
849 if ( eLHS < eRHS )
850 return -1;
851 if ( eLHS == eRHS )
852 return 0;
853 return 1;
856 // ---------------------------------------------------------------------------------------------------------------------
857 void ToolPanelViewShell_Impl::ConnectToDockingWindow()
859 m_pTaskPaneController.reset();
860 DockingWindow* pDockingWindow( GetAntiImpl().GetDockingWindow() );
861 if ( pDockingWindow )
863 PaneDockingWindow* pPaneDockingWindow = dynamic_cast< PaneDockingWindow* >( pDockingWindow );
864 OSL_ENSURE( pPaneDockingWindow, "ToolPanelViewShell_Impl::ConnectToDockingWindow: unsupported docking window type!" );
865 if ( pPaneDockingWindow != NULL )
866 m_pTaskPaneController.reset( new ::sfx2::TaskPaneController( GetTaskPane(), *pPaneDockingWindow ) );
869 // Tell the focus manager that we want to pass the focus to our
870 // child.
871 FocusManager::Instance().RegisterDownLink( GetAntiImpl().GetParentWindow(), &GetTaskPane() );
874 // ---------------------------------------------------------------------------------------------------------------------
875 Reference< XAccessible > ToolPanelViewShell_Impl::CreateAccessible( ::sd::Window& i_rWindow )
877 Reference< XAccessible > xAccessible( GetToolPanelDeck().GetAccessible( sal_False ) );
878 if ( !xAccessible.is() )
880 // determine the XAccessible which is the parent of the to-be-created object
881 ::Window* pAccessibleParent = i_rWindow.GetAccessibleParentWindow();
882 OSL_ENSURE( pAccessibleParent, "ToolPanelViewShell_Impl::CreateAccessible: illegal accessible parent provided by the sd::Window!" );
883 GetToolPanelDeck().SetAccessibleParentWindow( pAccessibleParent );
885 xAccessible = GetToolPanelDeck().GetAccessible( sal_True );
886 ENSURE_OR_RETURN( xAccessible.is(), "ToolPanelViewShell_Impl::CreateAccessible: illegal ToolPanelDeck accessible!", NULL );
887 OSL_ENSURE( xAccessible->getAccessibleContext().is()
888 && xAccessible->getAccessibleContext()->getAccessibleParent() == pAccessibleParent->GetAccessible(),
889 "ToolPanelViewShell_Impl::CreateAccessible: illegal parenthood!" );
891 return xAccessible;
894 } } // end of namespace ::sd::toolpanel
896 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */