1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
20 #include "CenterViewFocusModule.hxx"
22 #include "framework/ConfigurationController.hxx"
23 #include "framework/FrameworkHelper.hxx"
24 #include "framework/ViewShellWrapper.hxx"
26 #include "DrawController.hxx"
27 #include "ViewShellBase.hxx"
28 #include "ViewShellManager.hxx"
29 #include "strings.hrc"
30 #include "sdresid.hxx"
31 #include <com/sun/star/drawing/framework/XControllerManager.hpp>
32 #include <com/sun/star/drawing/framework/XConfigurationController.hpp>
34 #include <toolkit/awt/vclxdevice.hxx>
35 #include <sfx2/viewfrm.hxx>
37 using namespace ::com::sun::star
;
38 using namespace ::com::sun::star::uno
;
39 using namespace ::com::sun::star::drawing::framework
;
41 using ::sd::framework::FrameworkHelper
;
43 namespace sd
{ namespace framework
{
45 //===== CenterViewFocusModule ====================================================
47 CenterViewFocusModule::CenterViewFocusModule (Reference
<frame::XController
>& rxController
)
48 : CenterViewFocusModuleInterfaceBase(MutexOwner::maMutex
),
50 mxConfigurationController(),
52 mbNewViewCreated(false)
54 Reference
<XControllerManager
> xControllerManager (rxController
, UNO_QUERY
);
55 if (xControllerManager
.is())
57 mxConfigurationController
= xControllerManager
->getConfigurationController();
59 // Tunnel through the controller to obtain a ViewShellBase.
60 Reference
<lang::XUnoTunnel
> xTunnel (rxController
, UNO_QUERY
);
63 ::sd::DrawController
* pController
= reinterpret_cast<sd::DrawController
*>(
64 xTunnel
->getSomething(sd::DrawController::getUnoTunnelId()));
65 if (pController
!= NULL
)
66 mpBase
= pController
->GetViewShellBase();
69 // Check, if all required objects do exist.
70 if (mxConfigurationController
.is() && mpBase
!=NULL
)
78 mxConfigurationController
->addConfigurationChangeListener(
80 FrameworkHelper::msConfigurationUpdateEndEvent
,
82 mxConfigurationController
->addConfigurationChangeListener(
84 FrameworkHelper::msResourceActivationEvent
,
89 CenterViewFocusModule::~CenterViewFocusModule()
93 void SAL_CALL
CenterViewFocusModule::disposing()
95 if (mxConfigurationController
.is())
96 mxConfigurationController
->removeConfigurationChangeListener(this);
99 mxConfigurationController
= NULL
;
103 void SAL_CALL
CenterViewFocusModule::notifyConfigurationChange (
104 const ConfigurationChangeEvent
& rEvent
)
105 throw (RuntimeException
, std::exception
)
109 if (rEvent
.Type
.equals(FrameworkHelper::msConfigurationUpdateEndEvent
))
111 HandleNewView(rEvent
.Configuration
);
113 else if (rEvent
.Type
.equals(FrameworkHelper::msResourceActivationEvent
))
115 if (rEvent
.ResourceId
->getResourceURL().match(FrameworkHelper::msViewURLPrefix
))
116 mbNewViewCreated
= true;
121 void CenterViewFocusModule::HandleNewView (
122 const Reference
<XConfiguration
>& rxConfiguration
)
124 if (mbNewViewCreated
)
126 mbNewViewCreated
= false;
127 // Make the center pane the active one. Tunnel through the
128 // controller to obtain a ViewShell pointer.
130 Sequence
<Reference
<XResourceId
> > xViewIds (rxConfiguration
->getResources(
131 FrameworkHelper::CreateResourceId(FrameworkHelper::msCenterPaneURL
),
132 FrameworkHelper::msViewURLPrefix
,
133 AnchorBindingMode_DIRECT
));
134 Reference
<XView
> xView
;
135 if (xViewIds
.getLength() > 0)
136 xView
= Reference
<XView
>(
137 mxConfigurationController
->getResource(xViewIds
[0]),UNO_QUERY
);
138 Reference
<lang::XUnoTunnel
> xTunnel (xView
, UNO_QUERY
);
139 if (xTunnel
.is() && mpBase
!=NULL
)
141 ViewShellWrapper
* pViewShellWrapper
= reinterpret_cast<ViewShellWrapper
*>(
142 xTunnel
->getSomething(ViewShellWrapper::getUnoTunnelId()));
143 if (pViewShellWrapper
!= NULL
)
145 ::boost::shared_ptr
<ViewShell
> pViewShell
= pViewShellWrapper
->GetViewShell();
146 if (pViewShell
.get() != NULL
)
147 mpBase
->GetViewShellManager()->MoveToTop(*pViewShell
);
153 void SAL_CALL
CenterViewFocusModule::disposing (
154 const lang::EventObject
& rEvent
)
155 throw (RuntimeException
, std::exception
)
157 if (mxConfigurationController
.is())
158 if (rEvent
.Source
== mxConfigurationController
)
161 mxConfigurationController
= NULL
;
166 } } // end of namespace sd::framework
168 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */