xref: /trunk/main/sd/source/ui/dlg/PaneChildWindows.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sd.hxx"
30 #include "PaneChildWindows.hxx"
31 #include "PaneDockingWindow.hrc"
32 #include "PaneDockingWindow.hxx"
33 #include "ViewShellBase.hxx"
34 #include "framework/FrameworkHelper.hxx"
35 #include "taskpane/ToolPanelViewShell.hxx"
36 #include "app.hrc"
37 #include "strings.hrc"
38 #include "sdresid.hxx"
39 
40 #include <com/sun/star/drawing/framework/XConfigurationController.hpp>
41 #include <com/sun/star/drawing/framework/ResourceActivationMode.hpp>
42 
43 #include <sfx2/app.hxx>
44 #include <sfx2/dockwin.hxx>
45 #include <sfx2/bindings.hxx>
46 #include <sfx2/dispatch.hxx>
47 #include <tools/diagnose_ex.h>
48 
49 namespace sd {
50 
51 using ::com::sun::star::uno::Reference;
52 using ::com::sun::star::drawing::framework::XResourceId;
53 using ::com::sun::star::drawing::framework::XConfigurationController;
54 using ::com::sun::star::drawing::framework::ResourceActivationMode_ADD;
55 using ::com::sun::star::drawing::framework::ResourceActivationMode_REPLACE;
56 
57 SFX_IMPL_DOCKINGWINDOW(LeftPaneImpressChildWindow, SID_LEFT_PANE_IMPRESS)
58 SFX_IMPL_DOCKINGWINDOW(LeftPaneDrawChildWindow, SID_LEFT_PANE_DRAW)
59 SFX_IMPL_DOCKINGWINDOW( ToolPanelChildWindow, SID_TASKPANE)
60 
61 //===== PaneChildWindow =======================================================
62 
63 PaneChildWindow::PaneChildWindow (
64     ::Window* pParentWindow,
65     sal_uInt16 nId,
66     SfxBindings* pBindings,
67     SfxChildWinInfo* pInfo,
68     const sal_uInt16 nDockWinTitleResId,
69     const sal_uInt16 nTitleBarResId,
70     SfxChildAlignment eAlignment)
71     : SfxChildWindow (pParentWindow, nId)
72 {
73     pWindow = new PaneDockingWindow (
74         pBindings,
75         this,
76         pParentWindow,
77         SdResId( nDockWinTitleResId ),
78         String( SdResId( nTitleBarResId ) ) );
79     eChildAlignment = eAlignment;
80     static_cast<SfxDockingWindow*>(pWindow)->Initialize(pInfo);
81     SetHideNotDelete(sal_True);
82 
83     ViewShellBase* pBase = ViewShellBase::GetViewShellBase(pBindings->GetDispatcher()->GetFrame());
84     if (pBase != NULL)
85     {
86         framework::FrameworkHelper::Instance(*pBase)->UpdateConfiguration();
87     }
88 }
89 
90 
91 
92 
93 PaneChildWindow::~PaneChildWindow (void)
94 {
95     ViewShellBase* pBase = NULL;
96     PaneDockingWindow* pDockingWindow = dynamic_cast<PaneDockingWindow*>(pWindow);
97     if (pDockingWindow != NULL)
98         pBase = ViewShellBase::GetViewShellBase(
99             pDockingWindow->GetBindings().GetDispatcher()->GetFrame());
100     if (pBase != NULL)
101         framework::FrameworkHelper::Instance(*pBase)->UpdateConfiguration();
102 }
103 
104 
105 
106 
107 
108 
109 //===== LeftPaneImpressChildWindow ============================================
110 
111 LeftPaneImpressChildWindow::LeftPaneImpressChildWindow (
112     ::Window* pParentWindow,
113     sal_uInt16 nId,
114     SfxBindings* pBindings,
115     SfxChildWinInfo* pInfo)
116     : PaneChildWindow(
117         pParentWindow,
118         nId,
119         pBindings,
120         pInfo,
121         FLT_LEFT_PANE_IMPRESS_DOCKING_WINDOW,
122         STR_LEFT_PANE_IMPRESS_TITLE,
123         SFX_ALIGN_LEFT)
124 {
125 }
126 
127 
128 
129 
130 //===== LeftPaneDrawChildWindow ===============================================
131 
132 LeftPaneDrawChildWindow::LeftPaneDrawChildWindow (
133     ::Window* pParentWindow,
134     sal_uInt16 nId,
135     SfxBindings* pBindings,
136     SfxChildWinInfo* pInfo)
137     : PaneChildWindow(
138         pParentWindow,
139         nId,
140         pBindings,
141         pInfo,
142         FLT_LEFT_PANE_DRAW_DOCKING_WINDOW,
143         STR_LEFT_PANE_DRAW_TITLE,
144         SFX_ALIGN_LEFT)
145 {
146 }
147 
148 
149 
150 
151 //======================================================================================================================
152 //= ToolPanelChildWindow
153 //======================================================================================================================
154 //----------------------------------------------------------------------------------------------------------------------
155 ToolPanelChildWindow::ToolPanelChildWindow( ::Window* i_pParentWindow, sal_uInt16 i_nId, SfxBindings* i_pBindings,
156         SfxChildWinInfo* i_pChildWindowInfo )
157     :PaneChildWindow( i_pParentWindow, i_nId, i_pBindings, i_pChildWindowInfo,
158         FLT_TOOL_PANEL_DOCKING_WINDOW, STR_RIGHT_PANE_TITLE, SFX_ALIGN_RIGHT )
159 {
160     // just in case this window has been created by SFX, instead our resource framework: Ensure that the resource framework
161     // activates the task pane, so it is really filled with content (in opposite to the other SFX applications, the
162     // child window registered for SID_TASKPANE is not responsible for its content, but here in SD, it's the ToolPanelViewShell
163     // which has this responsibility. And this view shell is created implicitly via the resource framework.)
164     // #i113788# / 2010-09-03 / frank.schoenheit@oracle.com
165     SfxDockingWindow* pDockingWindow = dynamic_cast< SfxDockingWindow* >( GetWindow() );
166     ViewShellBase* pViewShellBase = ViewShellBase::GetViewShellBase( pDockingWindow->GetBindings().GetDispatcher()->GetFrame() );
167     ENSURE_OR_RETURN_VOID( pViewShellBase != NULL, "ToolPanelChildWindow::ToolPanelChildWindow: no view shell access!" );
168 
169     const ::boost::shared_ptr< framework::FrameworkHelper > pFrameworkHelper( framework::FrameworkHelper::Instance( *pViewShellBase ) );
170     ENSURE_OR_RETURN_VOID( pFrameworkHelper.get(), "ToolPanelChildWindow::ToolPanelChildWindow: no framework helper for the view shell!" );
171     Reference<XConfigurationController> xConfigController( pFrameworkHelper->GetConfigurationController() );
172     ENSURE_OR_RETURN_VOID( xConfigController.is(), "ToolPanelChildWindow::ToolPanelChildWindow: no config controller!" );
173     xConfigController->requestResourceActivation(
174         framework::FrameworkHelper::CreateResourceId( framework::FrameworkHelper::msRightPaneURL ),
175         ResourceActivationMode_ADD );
176     xConfigController->requestResourceActivation(
177         framework::FrameworkHelper::CreateResourceId( framework::FrameworkHelper::msTaskPaneURL, framework::FrameworkHelper::msRightPaneURL ),
178         ResourceActivationMode_REPLACE
179     );
180 }
181 
182 //----------------------------------------------------------------------------------------------------------------------
183 struct DelayedToolPanelActivation
184 {
185     DelayedToolPanelActivation( ToolPanelChildWindow& i_rToolPanelWindow, const ::rtl::OUString& i_rPanelURL )
186         :m_rToolPanelWindow( i_rToolPanelWindow )
187         ,m_sPanelURL( i_rPanelURL )
188     {
189     }
190 
191     void operator() (bool)
192     {
193         m_rToolPanelWindow.ActivateToolPanel( m_sPanelURL );
194     }
195 
196 private:
197     ToolPanelChildWindow&   m_rToolPanelWindow;
198     const ::rtl::OUString   m_sPanelURL;
199 };
200 
201 //----------------------------------------------------------------------------------------------------------------------
202 void ToolPanelChildWindow::ActivateToolPanel( const ::rtl::OUString& i_rPanelURL )
203 {
204     SfxDockingWindow* pDockingWindow = dynamic_cast< SfxDockingWindow* >( GetWindow() );
205     ViewShellBase* pViewShellBase = ViewShellBase::GetViewShellBase( pDockingWindow->GetBindings().GetDispatcher()->GetFrame() );
206     ENSURE_OR_RETURN_VOID( pViewShellBase != NULL, "ToolPanelChildWindow::ActivateToolPanel: no view shell access!" );
207 
208     const ::boost::shared_ptr< framework::FrameworkHelper > pFrameworkHelper( framework::FrameworkHelper::Instance( *pViewShellBase ) );
209 
210     if ( i_rPanelURL.indexOf( framework::FrameworkHelper::msTaskPanelURLPrefix ) == 0 )
211     {
212         // it's one of our standard panels known to the drawing framework
213         pFrameworkHelper->RequestTaskPanel( i_rPanelURL );
214     }
215     else
216     {
217         // TODO: it would be nice if the drawing framework were able to handle non-standard panels, installed by
218         // extensions, too. As long as this is not the case, we need to take the direct way ...
219         ::boost::shared_ptr< ViewShell > pViewShell = pFrameworkHelper->GetViewShell( framework::FrameworkHelper::msRightPaneURL );
220         toolpanel::ToolPanelViewShell* pToolPanelViewShell = dynamic_cast< toolpanel::ToolPanelViewShell* >( pViewShell.get() );
221         if ( pToolPanelViewShell )
222         {
223             pToolPanelViewShell->ActivatePanel( i_rPanelURL );
224         }
225         else
226         {
227             Reference< XResourceId > xTaskPaneResource = pFrameworkHelper->RequestView(
228                 framework::FrameworkHelper::msTaskPaneURL, framework::FrameworkHelper::msRightPaneURL );
229             pFrameworkHelper->RunOnResourceActivation( xTaskPaneResource, DelayedToolPanelActivation( *this, i_rPanelURL ) );
230         }
231     }
232 }
233 
234 } // end of namespace ::sd
235