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 : #include "CenterViewFocusModule.hxx"
21 :
22 : #include "framework/ConfigurationController.hxx"
23 : #include "framework/FrameworkHelper.hxx"
24 : #include "framework/ViewShellWrapper.hxx"
25 :
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>
33 :
34 : #include <toolkit/awt/vclxdevice.hxx>
35 : #include <sfx2/viewfrm.hxx>
36 :
37 : using namespace ::com::sun::star;
38 : using namespace ::com::sun::star::uno;
39 : using namespace ::com::sun::star::drawing::framework;
40 :
41 : using ::sd::framework::FrameworkHelper;
42 :
43 : namespace sd { namespace framework {
44 :
45 : //===== CenterViewFocusModule ====================================================
46 :
47 127 : CenterViewFocusModule::CenterViewFocusModule (Reference<frame::XController>& rxController)
48 : : CenterViewFocusModuleInterfaceBase(MutexOwner::maMutex),
49 : mbValid(false),
50 : mxConfigurationController(),
51 : mpBase(NULL),
52 127 : mbNewViewCreated(false)
53 : {
54 127 : Reference<XControllerManager> xControllerManager (rxController, UNO_QUERY);
55 127 : if (xControllerManager.is())
56 : {
57 127 : mxConfigurationController = xControllerManager->getConfigurationController();
58 :
59 : // Tunnel through the controller to obtain a ViewShellBase.
60 127 : Reference<lang::XUnoTunnel> xTunnel (rxController, UNO_QUERY);
61 127 : if (xTunnel.is())
62 : {
63 : ::sd::DrawController* pController = reinterpret_cast<sd::DrawController*>(
64 127 : xTunnel->getSomething(sd::DrawController::getUnoTunnelId()));
65 127 : if (pController != NULL)
66 127 : mpBase = pController->GetViewShellBase();
67 : }
68 :
69 : // Check, if all required objects do exist.
70 127 : if (mxConfigurationController.is() && mpBase!=NULL)
71 : {
72 127 : mbValid = true;
73 127 : }
74 : }
75 :
76 127 : if (mbValid)
77 : {
78 127 : mxConfigurationController->addConfigurationChangeListener(
79 : this,
80 : FrameworkHelper::msConfigurationUpdateEndEvent,
81 127 : Any());
82 127 : mxConfigurationController->addConfigurationChangeListener(
83 : this,
84 : FrameworkHelper::msResourceActivationEvent,
85 127 : Any());
86 127 : }
87 127 : }
88 :
89 254 : CenterViewFocusModule::~CenterViewFocusModule()
90 : {
91 254 : }
92 :
93 127 : void SAL_CALL CenterViewFocusModule::disposing()
94 : {
95 127 : if (mxConfigurationController.is())
96 0 : mxConfigurationController->removeConfigurationChangeListener(this);
97 :
98 127 : mbValid = false;
99 127 : mxConfigurationController = NULL;
100 127 : mpBase = NULL;
101 127 : }
102 :
103 914 : void SAL_CALL CenterViewFocusModule::notifyConfigurationChange (
104 : const ConfigurationChangeEvent& rEvent)
105 : throw (RuntimeException, std::exception)
106 : {
107 914 : if (mbValid)
108 : {
109 914 : if (rEvent.Type.equals(FrameworkHelper::msConfigurationUpdateEndEvent))
110 : {
111 355 : HandleNewView(rEvent.Configuration);
112 : }
113 559 : else if (rEvent.Type.equals(FrameworkHelper::msResourceActivationEvent))
114 : {
115 559 : if (rEvent.ResourceId->getResourceURL().match(FrameworkHelper::msViewURLPrefix))
116 199 : mbNewViewCreated = true;
117 : }
118 : }
119 914 : }
120 :
121 355 : void CenterViewFocusModule::HandleNewView (
122 : const Reference<XConfiguration>& rxConfiguration)
123 : {
124 355 : if (mbNewViewCreated)
125 : {
126 196 : mbNewViewCreated = false;
127 : // Make the center pane the active one. Tunnel through the
128 : // controller to obtain a ViewShell pointer.
129 :
130 196 : Sequence<Reference<XResourceId> > xViewIds (rxConfiguration->getResources(
131 : FrameworkHelper::CreateResourceId(FrameworkHelper::msCenterPaneURL),
132 : FrameworkHelper::msViewURLPrefix,
133 196 : AnchorBindingMode_DIRECT));
134 392 : Reference<XView> xView;
135 196 : if (xViewIds.getLength() > 0)
136 392 : xView = Reference<XView>(
137 392 : mxConfigurationController->getResource(xViewIds[0]),UNO_QUERY);
138 392 : Reference<lang::XUnoTunnel> xTunnel (xView, UNO_QUERY);
139 196 : if (xTunnel.is() && mpBase!=NULL)
140 : {
141 : ViewShellWrapper* pViewShellWrapper = reinterpret_cast<ViewShellWrapper*>(
142 196 : xTunnel->getSomething(ViewShellWrapper::getUnoTunnelId()));
143 196 : if (pViewShellWrapper != NULL)
144 : {
145 196 : ::boost::shared_ptr<ViewShell> pViewShell = pViewShellWrapper->GetViewShell();
146 196 : if (pViewShell.get() != NULL)
147 196 : mpBase->GetViewShellManager()->MoveToTop(*pViewShell);
148 : }
149 196 : }
150 : }
151 355 : }
152 :
153 127 : void SAL_CALL CenterViewFocusModule::disposing (
154 : const lang::EventObject& rEvent)
155 : throw (RuntimeException, std::exception)
156 : {
157 127 : if (mxConfigurationController.is())
158 127 : if (rEvent.Source == mxConfigurationController)
159 : {
160 127 : mbValid = false;
161 127 : mxConfigurationController = NULL;
162 127 : mpBase = NULL;
163 : }
164 127 : }
165 :
166 66 : } } // end of namespace sd::framework
167 :
168 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|