Branch data 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 : 130 : CenterViewFocusModule::CenterViewFocusModule (Reference<frame::XController>& rxController)
51 : : : CenterViewFocusModuleInterfaceBase(MutexOwner::maMutex),
52 : : mbValid(false),
53 : : mxConfigurationController(),
54 : : mpBase(NULL),
55 : 130 : mbNewViewCreated(false)
56 : : {
57 [ + - ]: 130 : Reference<XControllerManager> xControllerManager (rxController, UNO_QUERY);
58 [ + - ]: 130 : if (xControllerManager.is())
59 : : {
60 [ + - ][ + - ]: 130 : mxConfigurationController = xControllerManager->getConfigurationController();
[ + - ]
61 : :
62 : : // Tunnel through the controller to obtain a ViewShellBase.
63 [ + - ]: 130 : Reference<lang::XUnoTunnel> xTunnel (rxController, UNO_QUERY);
64 [ + - ]: 130 : if (xTunnel.is())
65 : : {
66 : : ::sd::DrawController* pController = reinterpret_cast<sd::DrawController*>(
67 [ + - ][ + - ]: 130 : xTunnel->getSomething(sd::DrawController::getUnoTunnelId()));
[ + - ]
68 [ + - ]: 130 : if (pController != NULL)
69 [ + - ]: 130 : mpBase = pController->GetViewShellBase();
70 : : }
71 : :
72 : : // Check, if all required objects do exist.
73 [ + - ][ + - ]: 130 : if (mxConfigurationController.is() && mpBase!=NULL)
[ + - ]
74 : : {
75 : 130 : mbValid = true;
76 : 130 : }
77 : : }
78 : :
79 [ + - ]: 130 : if (mbValid)
80 : : {
81 [ + - ]: 130 : mxConfigurationController->addConfigurationChangeListener(
82 : : this,
83 : : FrameworkHelper::msConfigurationUpdateEndEvent,
84 [ + - ][ + - ]: 130 : Any());
85 [ + - ]: 130 : mxConfigurationController->addConfigurationChangeListener(
86 : : this,
87 : : FrameworkHelper::msResourceActivationEvent,
88 [ + - ][ + - ]: 130 : Any());
89 : 130 : }
90 : 130 : }
91 : :
92 : :
93 : :
94 : :
95 [ + - ]: 130 : CenterViewFocusModule::~CenterViewFocusModule (void)
96 : : {
97 [ - + ]: 260 : }
98 : :
99 : :
100 : :
101 : :
102 : 130 : void SAL_CALL CenterViewFocusModule::disposing (void)
103 : : {
104 [ - + ]: 130 : if (mxConfigurationController.is())
105 [ # # ]: 0 : mxConfigurationController->removeConfigurationChangeListener(this);
106 : :
107 : 130 : mbValid = false;
108 : 130 : mxConfigurationController = NULL;
109 : 130 : mpBase = NULL;
110 : 130 : }
111 : :
112 : :
113 : :
114 : :
115 : 1188 : void SAL_CALL CenterViewFocusModule::notifyConfigurationChange (
116 : : const ConfigurationChangeEvent& rEvent)
117 : : throw (RuntimeException)
118 : : {
119 [ + - ]: 1188 : if (mbValid)
120 : : {
121 [ + + ]: 1188 : if (rEvent.Type.equals(FrameworkHelper::msConfigurationUpdateEndEvent))
122 : : {
123 : 412 : HandleNewView(rEvent.Configuration);
124 : : }
125 [ + - ]: 776 : else if (rEvent.Type.equals(FrameworkHelper::msResourceActivationEvent))
126 : : {
127 [ + + ]: 776 : if (rEvent.ResourceId->getResourceURL().match(FrameworkHelper::msViewURLPrefix))
128 : 286 : mbNewViewCreated = true;
129 : : }
130 : : }
131 : 1188 : }
132 : :
133 : :
134 : :
135 : :
136 : 412 : void CenterViewFocusModule::HandleNewView (
137 : : const Reference<XConfiguration>& rxConfiguration)
138 : : {
139 [ + + ]: 412 : if (mbNewViewCreated)
140 : : {
141 : 260 : mbNewViewCreated = false;
142 : : // Make the center pane the active one. Tunnel through the
143 : : // controller to obtain a ViewShell pointer.
144 : :
145 [ + - ]: 260 : Sequence<Reference<XResourceId> > xViewIds (rxConfiguration->getResources(
146 : : FrameworkHelper::CreateResourceId(FrameworkHelper::msCenterPaneURL),
147 : : FrameworkHelper::msViewURLPrefix,
148 [ + - ][ + - ]: 260 : AnchorBindingMode_DIRECT));
149 : 260 : Reference<XView> xView;
150 [ + - ]: 260 : if (xViewIds.getLength() > 0)
151 : : xView = Reference<XView>(
152 [ + - ][ + - ]: 260 : mxConfigurationController->getResource(xViewIds[0]),UNO_QUERY);
[ + - ][ + - ]
[ + - ]
153 [ + - ]: 260 : Reference<lang::XUnoTunnel> xTunnel (xView, UNO_QUERY);
154 [ + - ][ + - ]: 260 : if (xTunnel.is() && mpBase!=NULL)
[ + - ]
155 : : {
156 : : ViewShellWrapper* pViewShellWrapper = reinterpret_cast<ViewShellWrapper*>(
157 [ + - ][ + - ]: 260 : xTunnel->getSomething(ViewShellWrapper::getUnoTunnelId()));
[ + - ]
158 [ + - ]: 260 : if (pViewShellWrapper != NULL)
159 : : {
160 [ + - ]: 260 : ::boost::shared_ptr<ViewShell> pViewShell = pViewShellWrapper->GetViewShell();
161 [ + - ]: 260 : if (pViewShell.get() != NULL)
162 [ + - ][ + - ]: 260 : mpBase->GetViewShellManager()->MoveToTop(*pViewShell);
[ + - ][ + - ]
163 : : }
164 [ + - ]: 260 : }
165 : : }
166 : 412 : }
167 : :
168 : :
169 : :
170 : :
171 : 130 : void SAL_CALL CenterViewFocusModule::disposing (
172 : : const lang::EventObject& rEvent)
173 : : throw (RuntimeException)
174 : : {
175 [ + - ]: 130 : if (mxConfigurationController.is())
176 [ + - ]: 130 : if (rEvent.Source == mxConfigurationController)
177 : : {
178 : 130 : mbValid = false;
179 : 130 : mxConfigurationController = NULL;
180 : 130 : mpBase = NULL;
181 : : }
182 : 130 : }
183 : :
184 : :
185 : :
186 : : } } // end of namespace sd::framework
187 : :
188 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|