LibreOffice Module sd (master) 1
SlideSorterModule.cxx
Go to the documentation of this file.
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 "SlideSorterModule.hxx"
21
24#include <DrawController.hxx>
25#include <com/sun/star/drawing/framework/XTabBar.hpp>
26#include <com/sun/star/drawing/framework/TabBarButton.hpp>
27#include <com/sun/star/drawing/framework/XControllerManager.hpp>
28#include <com/sun/star/frame/XController.hpp>
29
30#include <strings.hrc>
31#include <sdresid.hxx>
33
34using namespace ::com::sun::star;
35using namespace ::com::sun::star::uno;
37
38using ::sd::framework::FrameworkHelper;
39
40namespace {
41 const sal_Int32 ResourceActivationRequestEvent = 0;
42 const sal_Int32 ResourceDeactivationRequestEvent = 1;
43}
44
45namespace sd::framework {
46
47//===== SlideSorterModule ==================================================
48
50 const rtl::Reference<::sd::DrawController>& rxController,
51 const OUString& rsLeftPaneURL)
52 : mxResourceId(FrameworkHelper::CreateResourceId(FrameworkHelper::msSlideSorterURL, rsLeftPaneURL)),
53 mxMainViewAnchorId(FrameworkHelper::CreateResourceId(FrameworkHelper::msCenterPaneURL)),
54 mxViewTabBarId(FrameworkHelper::CreateResourceId(
55 FrameworkHelper::msViewTabBarURL,
56 FrameworkHelper::msCenterPaneURL)),
57 mxControllerManager(rxController)
58{
59 if (mxControllerManager.is())
60 {
61 mxConfigurationController = mxControllerManager->getConfigurationController();
62
64 {
65 uno::Reference<lang::XComponent> const xComppnent(
66 mxConfigurationController, UNO_QUERY_THROW);
67 xComppnent->addEventListener(this);
68 mxConfigurationController->addConfigurationChangeListener(
69 this,
71 Any(ResourceActivationRequestEvent));
72 mxConfigurationController->addConfigurationChangeListener(
73 this,
75 Any(ResourceDeactivationRequestEvent));
76 }
77 }
79 return;
80
81 UpdateViewTabBar(nullptr);
82
83 if (SvtSlideSorterBarOptions().GetVisibleImpressView())
85 if (SvtSlideSorterBarOptions().GetVisibleOutlineView())
87 if (SvtSlideSorterBarOptions().GetVisibleNotesView())
89 if (SvtSlideSorterBarOptions().GetVisibleHandoutView())
91 if (SvtSlideSorterBarOptions().GetVisibleSlideSorterView())
93 if (SvtSlideSorterBarOptions().GetVisibleDrawView())
95
96 mxConfigurationController->addConfigurationChangeListener(
97 this,
99 Any());
100}
101
103{
104}
105
107{
114}
115
117 const ConfigurationChangeEvent& rEvent)
118{
120 {
121 if (rEvent.ResourceId->compareTo(mxViewTabBarId) == 0)
122 {
123 // Update the view tab bar because the view tab bar has just
124 // become active.
125 UpdateViewTabBar(Reference<XTabBar>(rEvent.ResourceObject,UNO_QUERY));
126 }
127 else if (rEvent.ResourceId->getResourceTypePrefix() ==
129 && rEvent.ResourceId->isBoundTo(
131 AnchorBindingMode_DIRECT))
132 {
133 // Update the view tab bar because the view in the center pane
134 // has changed.
135 UpdateViewTabBar(nullptr);
136 }
137 return;
138 }
139
140 OSL_ASSERT(rEvent.ResourceId.is());
141 sal_Int32 nEventType = 0;
142 rEvent.UserData >>= nEventType;
143 switch (nEventType)
144 {
145 case ResourceActivationRequestEvent:
146 if (rEvent.ResourceId->isBoundToURL(
148 AnchorBindingMode_DIRECT))
149 {
150 // A resource directly bound to the center pane has been
151 // requested.
152 if (rEvent.ResourceId->getResourceTypePrefix() ==
154 {
155 // The requested resource is a view. Show or hide the
156 // resource managed by this ResourceManager accordingly.
158 rEvent.ResourceId->getResourceURL(),
159 true);
160 }
161 }
162 else if (rEvent.ResourceId->compareTo(mxResourceId) == 0)
163 {
164 // The resource managed by this ResourceManager has been
165 // explicitly been requested (maybe by us). Remember this
166 // setting.
167 HandleResourceRequest(true, rEvent.Configuration);
168 }
169 break;
170
171 case ResourceDeactivationRequestEvent:
172 if (rEvent.ResourceId->compareTo(mxMainViewAnchorId) == 0)
173 {
175 OUString(),
176 false);
177 }
178 else if (rEvent.ResourceId->compareTo(mxResourceId) == 0)
179 {
180 // The resource managed by this ResourceManager has been
181 // explicitly been requested to be hidden (maybe by us).
182 // Remember this setting.
183 HandleResourceRequest(false, rEvent.Configuration);
184 }
185 break;
186 }
187}
188
189void SlideSorterModule::UpdateViewTabBar (const Reference<XTabBar>& rxTabBar)
190{
191 if ( ! mxControllerManager.is())
192 return;
193
194 Reference<XTabBar> xBar (rxTabBar);
195 if ( ! xBar.is())
196 {
197 Reference<XConfigurationController> xCC (
198 mxControllerManager->getConfigurationController());
199 if (xCC.is())
200 xBar.set(xCC->getResource(mxViewTabBarId), UNO_QUERY);
201 }
202
203 if (!xBar.is())
204 return;
205
206 TabBarButton aButtonA;
207 aButtonA.ResourceId = FrameworkHelper::CreateResourceId(
210 aButtonA.ButtonLabel = SdResId(STR_SLIDE_SORTER_MODE);
211
212 TabBarButton aButtonB;
213 aButtonB.ResourceId = FrameworkHelper::CreateResourceId(
216
217 if ( ! xBar->hasTabBarButton(aButtonA))
218 xBar->addTabBarButtonAfter(aButtonA, aButtonB);
219}
220
222 const OUString& rsMainViewURL)
223{
224 maActiveMainViewContainer.insert(rsMainViewURL);
225}
226
228 const OUString& rsMainViewURL)
229{
230 return (maActiveMainViewContainer.find(rsMainViewURL) != maActiveMainViewContainer.end());
231}
232
233void SlideSorterModule::disposing(std::unique_lock<std::mutex>&)
234{
236 {
237 uno::Reference<lang::XComponent> const xComponent(mxConfigurationController, UNO_QUERY);
238 if (xComponent.is())
239 xComponent->removeEventListener(this);
240
241 mxConfigurationController->removeConfigurationChangeListener(this);
243 }
244}
245
247 const OUString& rsViewURL,
248 const bool bIsActivated)
249{
250 if (bIsActivated)
251 msCurrentMainViewURL = rsViewURL;
252 else
253 msCurrentMainViewURL.clear();
254
256 return;
257
259
262 {
263 // Activate resource.
264 mxConfigurationController->requestResourceActivation(
265 mxResourceId->getAnchor(),
266 ResourceActivationMode_ADD);
267 mxConfigurationController->requestResourceActivation(
269 ResourceActivationMode_REPLACE);
270 }
271 else
272 {
273 mxConfigurationController->requestResourceDeactivation(mxResourceId);
274 }
275}
276
278 bool bActivation,
279 const Reference<XConfiguration>& rxConfiguration)
280{
281 Sequence<Reference<XResourceId> > aCenterViews = rxConfiguration->getResources(
284 AnchorBindingMode_DIRECT);
285 if (aCenterViews.getLength() == 1)
286 {
287 if (bActivation)
288 {
289 maActiveMainViewContainer.insert(aCenterViews[0]->getResourceURL());
290 }
291 else
292 {
293 maActiveMainViewContainer.erase(aCenterViews[0]->getResourceURL());
294 }
295 }
296}
297
298void SAL_CALL SlideSorterModule::disposing (
299 const lang::EventObject& rEvent)
300{
302 && rEvent.Source == mxConfigurationController)
303 {
305 // Without the configuration controller this class can do nothing.
307 dispose();
308 }
309}
310
311} // end of namespace sd::framework
312
313/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XResourceId > mxResourceId
void SetVisibleSlideSorterView(bool bVisible)
void SetVisibleImpressView(bool bVisible)
void SetVisibleHandoutView(bool bVisible)
void SetVisibleDrawView(bool bVisible)
void SetVisibleOutlineView(bool bVisible)
void SetVisibleNotesView(bool bVisible)
virtual void SAL_CALL dispose() noexcept final override
Use this class instead of calling lock() and unlock() directly in order to be exception safe.
The FrameworkHelper is a convenience class that simplifies the access to the drawing framework.
static css::uno::Reference< css::drawing::framework::XResourceId > CreateResourceId(const OUString &rsResourceURL)
Create a new XResourceId object for the given resource URL.
static const OUString msHandoutViewURL
static const OUString msCenterPaneURL
static constexpr OUStringLiteral msResourceActivationRequestEvent
static const OUString msNotesViewURL
static const OUString msOutlineViewURL
static const OUString msSlideSorterURL
static constexpr OUStringLiteral msResourceDeactivationRequestEvent
static const OUString msDrawViewURL
static constexpr OUStringLiteral msResourceActivationEvent
static constexpr OUStringLiteral msViewURLPrefix
static const OUString msImpressViewURL
virtual void disposing(std::unique_lock< std::mutex > &) override
css::uno::Reference< css::drawing::framework::XResourceId > mxMainViewAnchorId
The anchor of the main view.
rtl::Reference<::sd::DrawController > mxControllerManager
css::uno::Reference< css::drawing::framework::XConfigurationController > mxConfigurationController
css::uno::Reference< css::drawing::framework::XResourceId > mxResourceId
The resource managed by this class.
virtual void SAL_CALL notifyConfigurationChange(const css::drawing::framework::ConfigurationChangeEvent &rEvent) override
void AddActiveMainView(const OUString &rsMainViewURL)
Remember the given URL as one of a center pane view for which to activate the resource managed by the...
SlideSorterModule(const rtl::Reference<::sd::DrawController > &rxController, const OUString &rsLeftPaneURL)
void HandleMainViewSwitch(const OUString &rsViewURL, const bool bIsActivated)
css::uno::Reference< css::drawing::framework::XResourceId > mxViewTabBarId
bool IsResourceActive(const OUString &rsMainViewURL)
void HandleResourceRequest(bool bActivation, const css::uno::Reference< css::drawing::framework::XConfiguration > &rxConfiguration)
::std::set< OUString > maActiveMainViewContainer
void UpdateViewTabBar(const css::uno::Reference< css::drawing::framework::XTabBar > &rxViewTabBar)
OUString SdResId(TranslateId aId)
Definition: sdmod.cxx:83