Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
21 : #include "CenterViewFocusModule.hxx"
22 :
23 : #include "framework/ConfigurationController.hxx"
24 : #include "framework/FrameworkHelper.hxx"
25 : #include "framework/ViewShellWrapper.hxx"
26 :
27 : #include "DrawController.hxx"
28 : #include "ViewShellBase.hxx"
29 : #include "ViewShellManager.hxx"
30 : #include "strings.hrc"
31 : #include "sdresid.hxx"
32 : #include <com/sun/star/drawing/framework/XControllerManager.hpp>
33 : #include <com/sun/star/drawing/framework/XConfigurationController.hpp>
34 :
35 : #include <toolkit/awt/vclxdevice.hxx>
36 : #include <sfx2/viewfrm.hxx>
37 :
38 : using namespace ::com::sun::star;
39 : using namespace ::com::sun::star::uno;
40 : using namespace ::com::sun::star::drawing::framework;
41 :
42 : using ::rtl::OUString;
43 : using ::sd::framework::FrameworkHelper;
44 :
45 :
46 : namespace sd { namespace framework {
47 :
48 : //===== CenterViewFocusModule ====================================================
49 :
50 0 : CenterViewFocusModule::CenterViewFocusModule (Reference<frame::XController>& rxController)
51 : : CenterViewFocusModuleInterfaceBase(MutexOwner::maMutex),
52 : mbValid(false),
53 : mxConfigurationController(),
54 : mpBase(NULL),
55 0 : mbNewViewCreated(false)
56 : {
57 0 : Reference<XControllerManager> xControllerManager (rxController, UNO_QUERY);
58 0 : if (xControllerManager.is())
59 : {
60 0 : mxConfigurationController = xControllerManager->getConfigurationController();
61 :
62 : // Tunnel through the controller to obtain a ViewShellBase.
63 0 : Reference<lang::XUnoTunnel> xTunnel (rxController, UNO_QUERY);
64 0 : if (xTunnel.is())
65 : {
66 : ::sd::DrawController* pController = reinterpret_cast<sd::DrawController*>(
67 0 : xTunnel->getSomething(sd::DrawController::getUnoTunnelId()));
68 0 : if (pController != NULL)
69 0 : mpBase = pController->GetViewShellBase();
70 : }
71 :
72 : // Check, if all required objects do exist.
73 0 : if (mxConfigurationController.is() && mpBase!=NULL)
74 : {
75 0 : mbValid = true;
76 0 : }
77 : }
78 :
79 0 : if (mbValid)
80 : {
81 0 : mxConfigurationController->addConfigurationChangeListener(
82 : this,
83 : FrameworkHelper::msConfigurationUpdateEndEvent,
84 0 : Any());
85 0 : mxConfigurationController->addConfigurationChangeListener(
86 : this,
87 : FrameworkHelper::msResourceActivationEvent,
88 0 : Any());
89 0 : }
90 0 : }
91 :
92 :
93 :
94 :
95 0 : CenterViewFocusModule::~CenterViewFocusModule (void)
96 : {
97 0 : }
98 :
99 :
100 :
101 :
102 0 : void SAL_CALL CenterViewFocusModule::disposing (void)
103 : {
104 0 : if (mxConfigurationController.is())
105 0 : mxConfigurationController->removeConfigurationChangeListener(this);
106 :
107 0 : mbValid = false;
108 0 : mxConfigurationController = NULL;
109 0 : mpBase = NULL;
110 0 : }
111 :
112 :
113 :
114 :
115 0 : void SAL_CALL CenterViewFocusModule::notifyConfigurationChange (
116 : const ConfigurationChangeEvent& rEvent)
117 : throw (RuntimeException)
118 : {
119 0 : if (mbValid)
120 : {
121 0 : if (rEvent.Type.equals(FrameworkHelper::msConfigurationUpdateEndEvent))
122 : {
123 0 : HandleNewView(rEvent.Configuration);
124 : }
125 0 : else if (rEvent.Type.equals(FrameworkHelper::msResourceActivationEvent))
126 : {
127 0 : if (rEvent.ResourceId->getResourceURL().match(FrameworkHelper::msViewURLPrefix))
128 0 : mbNewViewCreated = true;
129 : }
130 : }
131 0 : }
132 :
133 :
134 :
135 :
136 0 : void CenterViewFocusModule::HandleNewView (
137 : const Reference<XConfiguration>& rxConfiguration)
138 : {
139 0 : if (mbNewViewCreated)
140 : {
141 0 : mbNewViewCreated = false;
142 : // Make the center pane the active one. Tunnel through the
143 : // controller to obtain a ViewShell pointer.
144 :
145 0 : Sequence<Reference<XResourceId> > xViewIds (rxConfiguration->getResources(
146 : FrameworkHelper::CreateResourceId(FrameworkHelper::msCenterPaneURL),
147 : FrameworkHelper::msViewURLPrefix,
148 0 : AnchorBindingMode_DIRECT));
149 0 : Reference<XView> xView;
150 0 : if (xViewIds.getLength() > 0)
151 : xView = Reference<XView>(
152 0 : mxConfigurationController->getResource(xViewIds[0]),UNO_QUERY);
153 0 : Reference<lang::XUnoTunnel> xTunnel (xView, UNO_QUERY);
154 0 : if (xTunnel.is() && mpBase!=NULL)
155 : {
156 : ViewShellWrapper* pViewShellWrapper = reinterpret_cast<ViewShellWrapper*>(
157 0 : xTunnel->getSomething(ViewShellWrapper::getUnoTunnelId()));
158 0 : if (pViewShellWrapper != NULL)
159 : {
160 0 : ::boost::shared_ptr<ViewShell> pViewShell = pViewShellWrapper->GetViewShell();
161 0 : if (pViewShell.get() != NULL)
162 0 : mpBase->GetViewShellManager()->MoveToTop(*pViewShell);
163 : }
164 0 : }
165 : }
166 0 : }
167 :
168 :
169 :
170 :
171 0 : void SAL_CALL CenterViewFocusModule::disposing (
172 : const lang::EventObject& rEvent)
173 : throw (RuntimeException)
174 : {
175 0 : if (mxConfigurationController.is())
176 0 : if (rEvent.Source == mxConfigurationController)
177 : {
178 0 : mbValid = false;
179 0 : mxConfigurationController = NULL;
180 0 : mpBase = NULL;
181 : }
182 0 : }
183 :
184 :
185 :
186 : } } // end of namespace sd::framework
187 :
188 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|