merge the formfield patch from ooo-build
[ooovba.git] / sd / source / ui / framework / module / CenterViewFocusModule.cxx
bloba5eae0ddd035d1a94fa83d9ff6273c85bb86d7ad
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: CenterViewFocusModule.cxx,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "precompiled_sd.hxx"
33 #include "CenterViewFocusModule.hxx"
35 #include "framework/ConfigurationController.hxx"
36 #include "framework/FrameworkHelper.hxx"
37 #include "framework/ViewShellWrapper.hxx"
39 #include "DrawController.hxx"
40 #include "ViewShellBase.hxx"
41 #include "ViewShellManager.hxx"
42 #include "strings.hrc"
43 #include "sdresid.hxx"
44 #include <com/sun/star/drawing/framework/XControllerManager.hpp>
45 #include <com/sun/star/drawing/framework/XConfigurationController.hpp>
47 #include <toolkit/awt/vclxdevice.hxx>
48 #include <sfx2/viewfrm.hxx>
50 using namespace ::com::sun::star;
51 using namespace ::com::sun::star::uno;
52 using namespace ::com::sun::star::drawing::framework;
54 using ::rtl::OUString;
55 using ::sd::framework::FrameworkHelper;
58 namespace sd { namespace framework {
60 //===== CenterViewFocusModule ====================================================
62 CenterViewFocusModule::CenterViewFocusModule (Reference<frame::XController>& rxController)
63 : CenterViewFocusModuleInterfaceBase(MutexOwner::maMutex),
64 mbValid(false),
65 mxConfigurationController(),
66 mpBase(NULL),
67 mbNewViewCreated(false)
69 Reference<XControllerManager> xControllerManager (rxController, UNO_QUERY);
70 if (xControllerManager.is())
72 mxConfigurationController = xControllerManager->getConfigurationController();
74 // Tunnel through the controller to obtain a ViewShellBase.
75 Reference<lang::XUnoTunnel> xTunnel (rxController, UNO_QUERY);
76 if (xTunnel.is())
78 ::sd::DrawController* pController = reinterpret_cast<sd::DrawController*>(
79 xTunnel->getSomething(sd::DrawController::getUnoTunnelId()));
80 if (pController != NULL)
81 mpBase = pController->GetViewShellBase();
84 // Check, if all required objects do exist.
85 if (mxConfigurationController.is() && mpBase!=NULL)
87 mbValid = true;
91 if (mbValid)
93 mxConfigurationController->addConfigurationChangeListener(
94 this,
95 FrameworkHelper::msConfigurationUpdateEndEvent,
96 Any());
97 mxConfigurationController->addConfigurationChangeListener(
98 this,
99 FrameworkHelper::msResourceActivationEvent,
100 Any());
107 CenterViewFocusModule::~CenterViewFocusModule (void)
114 void SAL_CALL CenterViewFocusModule::disposing (void)
116 if (mxConfigurationController.is())
117 mxConfigurationController->removeConfigurationChangeListener(this);
119 mbValid = false;
120 mxConfigurationController = NULL;
121 mpBase = NULL;
127 void SAL_CALL CenterViewFocusModule::notifyConfigurationChange (
128 const ConfigurationChangeEvent& rEvent)
129 throw (RuntimeException)
131 if (mbValid)
133 if (rEvent.Type.equals(FrameworkHelper::msConfigurationUpdateEndEvent))
135 HandleNewView(rEvent.Configuration);
137 else if (rEvent.Type.equals(FrameworkHelper::msResourceActivationEvent))
139 if (rEvent.ResourceId->getResourceURL().match(FrameworkHelper::msViewURLPrefix))
140 mbNewViewCreated = true;
148 void CenterViewFocusModule::HandleNewView (
149 const Reference<XConfiguration>& rxConfiguration)
151 if (mbNewViewCreated)
153 mbNewViewCreated = false;
154 // Make the center pane the active one. Tunnel through the
155 // controller to obtain a ViewShell pointer.
157 Sequence<Reference<XResourceId> > xViewIds (rxConfiguration->getResources(
158 FrameworkHelper::CreateResourceId(FrameworkHelper::msCenterPaneURL),
159 FrameworkHelper::msViewURLPrefix,
160 AnchorBindingMode_DIRECT));
161 Reference<XView> xView;
162 if (xViewIds.getLength() > 0)
163 xView = Reference<XView>(
164 mxConfigurationController->getResource(xViewIds[0]),UNO_QUERY);
165 Reference<lang::XUnoTunnel> xTunnel (xView, UNO_QUERY);
166 if (xTunnel.is() && mpBase!=NULL)
168 ViewShellWrapper* pViewShellWrapper = reinterpret_cast<ViewShellWrapper*>(
169 xTunnel->getSomething(ViewShellWrapper::getUnoTunnelId()));
170 if (pViewShellWrapper != NULL)
172 ::boost::shared_ptr<ViewShell> pViewShell = pViewShellWrapper->GetViewShell();
173 if (pViewShell.get() != NULL)
174 mpBase->GetViewShellManager()->MoveToTop(*pViewShell);
183 void SAL_CALL CenterViewFocusModule::disposing (
184 const lang::EventObject& rEvent)
185 throw (RuntimeException)
187 if (mxConfigurationController.is())
188 if (rEvent.Source == mxConfigurationController)
190 mbValid = false;
191 mxConfigurationController = NULL;
192 mpBase = NULL;
198 } } // end of namespace sd::framework