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 #include "PaneChildWindows.hxx"
27 #include "PaneDockingWindow.hrc"
28 #include "PaneDockingWindow.hxx"
29 #include "ViewShellBase.hxx"
30 #include "framework/FrameworkHelper.hxx"
31 #include "taskpane/ToolPanelViewShell.hxx"
32 #include "app.hrc"
33 #include "strings.hrc"
34 #include "sdresid.hxx"
35 
36 #include <com/sun/star/drawing/framework/XConfigurationController.hpp>
37 #include <com/sun/star/drawing/framework/ResourceActivationMode.hpp>
38 
39 #include <sfx2/app.hxx>
40 #include <sfx2/dockwin.hxx>
41 #include <sfx2/bindings.hxx>
42 #include <sfx2/dispatch.hxx>
43 #include <tools/diagnose_ex.h>
44 
45 namespace sd {
46 
47 using ::com::sun::star::uno::Reference;
48 using ::com::sun::star::drawing::framework::XResourceId;
49 using ::com::sun::star::drawing::framework::XConfigurationController;
50 using ::com::sun::star::drawing::framework::ResourceActivationMode_ADD;
51 using ::com::sun::star::drawing::framework::ResourceActivationMode_REPLACE;
52 
53 SFX_IMPL_DOCKINGWINDOW(LeftPaneImpressChildWindow, SID_LEFT_PANE_IMPRESS)
54 SFX_IMPL_DOCKINGWINDOW(LeftPaneDrawChildWindow, SID_LEFT_PANE_DRAW)
55 SFX_IMPL_DOCKINGWINDOW( ToolPanelChildWindow, SID_TASKPANE)
56 
57 //===== PaneChildWindow =======================================================
58 
59 PaneChildWindow::PaneChildWindow (
60     ::Window* pParentWindow,
61     sal_uInt16 nId,
62     SfxBindings* pBindings,
63     SfxChildWinInfo* pInfo,
64     const sal_uInt16 nDockWinTitleResId,
65     const sal_uInt16 nTitleBarResId,
66     SfxChildAlignment eAlignment)
67     : SfxChildWindow (pParentWindow, nId)
68 {
69     pWindow = new PaneDockingWindow (
70         pBindings,
71         this,
72         pParentWindow,
73         SdResId( nDockWinTitleResId ),
74         String( SdResId( nTitleBarResId ) ) );
75     eChildAlignment = eAlignment;
76     static_cast<SfxDockingWindow*>(pWindow)->Initialize(pInfo);
77     SetHideNotDelete(sal_True);
78 
79     ViewShellBase* pBase = ViewShellBase::GetViewShellBase(pBindings->GetDispatcher()->GetFrame());
80     if (pBase != NULL)
81     {
82         framework::FrameworkHelper::Instance(*pBase)->UpdateConfiguration();
83     }
84 }
85 
86 
87 
88 
89 PaneChildWindow::~PaneChildWindow (void)
90 {
91     ViewShellBase* pBase = NULL;
92     PaneDockingWindow* pDockingWindow = dynamic_cast<PaneDockingWindow*>(pWindow);
93     if (pDockingWindow != NULL)
94         pBase = ViewShellBase::GetViewShellBase(
95             pDockingWindow->GetBindings().GetDispatcher()->GetFrame());
96     if (pBase != NULL)
97         framework::FrameworkHelper::Instance(*pBase)->UpdateConfiguration();
98 }
99 
100 
101 
102 
103 
104 
105 //===== LeftPaneImpressChildWindow ============================================
106 
107 LeftPaneImpressChildWindow::LeftPaneImpressChildWindow (
108     ::Window* pParentWindow,
109     sal_uInt16 nId,
110     SfxBindings* pBindings,
111     SfxChildWinInfo* pInfo)
112     : PaneChildWindow(
113         pParentWindow,
114         nId,
115         pBindings,
116         pInfo,
117         FLT_LEFT_PANE_IMPRESS_DOCKING_WINDOW,
118         STR_LEFT_PANE_IMPRESS_TITLE,
119         SFX_ALIGN_LEFT)
120 {
121 }
122 
123 
124 
125 
126 //===== LeftPaneDrawChildWindow ===============================================
127 
128 LeftPaneDrawChildWindow::LeftPaneDrawChildWindow (
129     ::Window* pParentWindow,
130     sal_uInt16 nId,
131     SfxBindings* pBindings,
132     SfxChildWinInfo* pInfo)
133     : PaneChildWindow(
134         pParentWindow,
135         nId,
136         pBindings,
137         pInfo,
138         FLT_LEFT_PANE_DRAW_DOCKING_WINDOW,
139         STR_LEFT_PANE_DRAW_TITLE,
140         SFX_ALIGN_LEFT)
141 {
142 }
143 
144 
145 
146 
147 //======================================================================================================================
148 //= ToolPanelChildWindow
149 //======================================================================================================================
150 //----------------------------------------------------------------------------------------------------------------------
151 ToolPanelChildWindow::ToolPanelChildWindow( ::Window* i_pParentWindow, sal_uInt16 i_nId, SfxBindings* i_pBindings,
152         SfxChildWinInfo* i_pChildWindowInfo )
153     :PaneChildWindow( i_pParentWindow, i_nId, i_pBindings, i_pChildWindowInfo,
154         FLT_TOOL_PANEL_DOCKING_WINDOW, STR_RIGHT_PANE_TITLE, SFX_ALIGN_RIGHT )
155 {
156     // just in case this window has been created by SFX, instead our resource framework: Ensure that the resource framework
157     // activates the task pane, so it is really filled with content (in opposite to the other SFX applications, the
158     // child window registered for SID_TASKPANE is not responsible for its content, but here in SD, it's the ToolPanelViewShell
159     // which has this responsibility. And this view shell is created implicitly via the resource framework.)
160     // #i113788# / 2010-09-03 / frank.schoenheit@oracle.com
161     SfxDockingWindow* pDockingWindow = dynamic_cast< SfxDockingWindow* >( GetWindow() );
162     ViewShellBase* pViewShellBase = ViewShellBase::GetViewShellBase( pDockingWindow->GetBindings().GetDispatcher()->GetFrame() );
163     ENSURE_OR_RETURN_VOID( pViewShellBase != NULL, "ToolPanelChildWindow::ToolPanelChildWindow: no view shell access!" );
164 
165     const ::boost::shared_ptr< framework::FrameworkHelper > pFrameworkHelper( framework::FrameworkHelper::Instance( *pViewShellBase ) );
166     ENSURE_OR_RETURN_VOID( pFrameworkHelper.get(), "ToolPanelChildWindow::ToolPanelChildWindow: no framework helper for the view shell!" );
167     Reference<XConfigurationController> xConfigController( pFrameworkHelper->GetConfigurationController() );
168     ENSURE_OR_RETURN_VOID( xConfigController.is(), "ToolPanelChildWindow::ToolPanelChildWindow: no config controller!" );
169     xConfigController->requestResourceActivation(
170         framework::FrameworkHelper::CreateResourceId( framework::FrameworkHelper::msRightPaneURL ),
171         ResourceActivationMode_ADD );
172     xConfigController->requestResourceActivation(
173         framework::FrameworkHelper::CreateResourceId( framework::FrameworkHelper::msTaskPaneURL, framework::FrameworkHelper::msRightPaneURL ),
174         ResourceActivationMode_REPLACE
175     );
176 }
177 
178 //----------------------------------------------------------------------------------------------------------------------
179 struct DelayedToolPanelActivation
180 {
181     DelayedToolPanelActivation( ToolPanelChildWindow& i_rToolPanelWindow, const ::rtl::OUString& i_rPanelURL )
182         :m_rToolPanelWindow( i_rToolPanelWindow )
183         ,m_sPanelURL( i_rPanelURL )
184     {
185     }
186 
187     void operator() (bool)
188     {
189         m_rToolPanelWindow.ActivateToolPanel( m_sPanelURL );
190     }
191 
192 private:
193     ToolPanelChildWindow&   m_rToolPanelWindow;
194     const ::rtl::OUString   m_sPanelURL;
195 };
196 
197 //----------------------------------------------------------------------------------------------------------------------
198 void ToolPanelChildWindow::ActivateToolPanel( const ::rtl::OUString& i_rPanelURL )
199 {
200     SfxDockingWindow* pDockingWindow = dynamic_cast< SfxDockingWindow* >( GetWindow() );
201     ViewShellBase* pViewShellBase = ViewShellBase::GetViewShellBase( pDockingWindow->GetBindings().GetDispatcher()->GetFrame() );
202     ENSURE_OR_RETURN_VOID( pViewShellBase != NULL, "ToolPanelChildWindow::ActivateToolPanel: no view shell access!" );
203 
204     const ::boost::shared_ptr< framework::FrameworkHelper > pFrameworkHelper( framework::FrameworkHelper::Instance( *pViewShellBase ) );
205 
206     if ( i_rPanelURL.indexOf( framework::FrameworkHelper::msTaskPanelURLPrefix ) == 0 )
207     {
208         // it's one of our standard panels known to the drawing framework
209         pFrameworkHelper->RequestTaskPanel( i_rPanelURL );
210     }
211     else
212     {
213         // TODO: it would be nice if the drawing framework were able to handle non-standard panels, installed by
214         // extensions, too. As long as this is not the case, we need to take the direct way ...
215         ::boost::shared_ptr< ViewShell > pViewShell = pFrameworkHelper->GetViewShell( framework::FrameworkHelper::msRightPaneURL );
216         toolpanel::ToolPanelViewShell* pToolPanelViewShell = dynamic_cast< toolpanel::ToolPanelViewShell* >( pViewShell.get() );
217         if ( pToolPanelViewShell )
218         {
219             pToolPanelViewShell->ActivatePanel( i_rPanelURL );
220         }
221         else
222         {
223             Reference< XResourceId > xTaskPaneResource = pFrameworkHelper->RequestView(
224                 framework::FrameworkHelper::msTaskPaneURL, framework::FrameworkHelper::msRightPaneURL );
225             pFrameworkHelper->RunOnResourceActivation( xTaskPaneResource, DelayedToolPanelActivation( *this, i_rPanelURL ) );
226         }
227     }
228 }
229 
230 } // end of namespace ::sd
231