LibreOffice Module sd (master) 1
ViewTabBarModule.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 "ViewTabBarModule.hxx"
21
23#include <DrawController.hxx>
24#include <com/sun/star/drawing/framework/XControllerManager.hpp>
25#include <com/sun/star/drawing/framework/XTabBar.hpp>
26#include <com/sun/star/frame/XController.hpp>
27
28#include <strings.hrc>
29#include <sdresid.hxx>
30
31using namespace ::com::sun::star;
32using namespace ::com::sun::star::uno;
34
35using ::sd::framework::FrameworkHelper;
36
37namespace {
38
39const sal_Int32 ResourceActivationRequestEvent = 0;
40const sal_Int32 ResourceDeactivationRequestEvent = 1;
41const sal_Int32 ResourceActivationEvent = 2;
42
43}
44
45namespace sd::framework {
46
47//===== ViewTabBarModule ==================================================
48
50 const rtl::Reference<::sd::DrawController>& rxController,
51 const Reference<XResourceId>& rxViewTabBarId)
52 : mxViewTabBarId(rxViewTabBarId)
53{
54 if (!rxController.is())
55 return;
56
57 mxConfigurationController = rxController->getConfigurationController();
59 return;
60
61 mxConfigurationController->addConfigurationChangeListener(
62 this,
64 Any(ResourceActivationRequestEvent));
65 mxConfigurationController->addConfigurationChangeListener(
66 this,
68 Any(ResourceDeactivationRequestEvent));
69
70 UpdateViewTabBar(nullptr);
71 mxConfigurationController->addConfigurationChangeListener(
72 this,
74 Any(ResourceActivationEvent));
75}
76
78{
79}
80
81void ViewTabBarModule::disposing(std::unique_lock<std::mutex>&)
82{
84 {
85 mxConfigurationController->removeConfigurationChangeListener(this);
87 }
88}
89
91 const ConfigurationChangeEvent& rEvent)
92{
94 return;
95
96 sal_Int32 nEventType = 0;
97 rEvent.UserData >>= nEventType;
98 switch (nEventType)
99 {
100 case ResourceActivationRequestEvent:
101 if (mxViewTabBarId->isBoundTo(rEvent.ResourceId, AnchorBindingMode_DIRECT))
102 {
103 mxConfigurationController->requestResourceActivation(
105 ResourceActivationMode_ADD);
106 }
107 break;
108
109 case ResourceDeactivationRequestEvent:
110 if (mxViewTabBarId->isBoundTo(rEvent.ResourceId, AnchorBindingMode_DIRECT))
111 {
112 mxConfigurationController->requestResourceDeactivation(mxViewTabBarId);
113 }
114 break;
115
116 case ResourceActivationEvent:
117 if (rEvent.ResourceId->compareTo(mxViewTabBarId) == 0)
118 {
119 UpdateViewTabBar(Reference<XTabBar>(rEvent.ResourceObject,UNO_QUERY));
120 }
121 }
122}
123
124void SAL_CALL ViewTabBarModule::disposing (
125 const lang::EventObject& rEvent)
126{
128 && rEvent.Source == mxConfigurationController)
129 {
130 // Without the configuration controller this class can do nothing.
132 dispose();
133 }
134}
135
136void ViewTabBarModule::UpdateViewTabBar (const Reference<XTabBar>& rxTabBar)
137{
139 return;
140
141 Reference<XTabBar> xBar (rxTabBar);
142 if ( ! xBar.is())
143 xBar.set( mxConfigurationController->getResource(mxViewTabBarId), UNO_QUERY);
144
145 if (!xBar.is())
146 return;
147
148 TabBarButton aEmptyButton;
149
150 Reference<XResourceId> xAnchor (mxViewTabBarId->getAnchor());
151
152 TabBarButton aImpressViewButton;
153 aImpressViewButton.ResourceId = FrameworkHelper::CreateResourceId(
155 xAnchor);
156 aImpressViewButton.ButtonLabel = SdResId(STR_NORMAL_MODE);
157 if ( ! xBar->hasTabBarButton(aImpressViewButton))
158 xBar->addTabBarButtonAfter(aImpressViewButton, aEmptyButton);
159
160 TabBarButton aOutlineViewButton;
161 aOutlineViewButton.ResourceId = FrameworkHelper::CreateResourceId(
163 xAnchor);
164 aOutlineViewButton.ButtonLabel = SdResId(STR_OUTLINE_MODE);
165 if ( ! xBar->hasTabBarButton(aOutlineViewButton))
166 xBar->addTabBarButtonAfter(aOutlineViewButton, aImpressViewButton);
167
168 TabBarButton aNotesViewButton;
169 aNotesViewButton.ResourceId = FrameworkHelper::CreateResourceId(
171 xAnchor);
172 aNotesViewButton.ButtonLabel = SdResId(STR_NOTES_MODE);
173 if ( ! xBar->hasTabBarButton(aNotesViewButton))
174 xBar->addTabBarButtonAfter(aNotesViewButton, aOutlineViewButton);
175}
176
177} // end of namespace sd::framework
178
179/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SAL_CALL dispose() noexcept final override
static css::uno::Reference< css::drawing::framework::XResourceId > CreateResourceId(const OUString &rsResourceURL)
Create a new XResourceId object for the given resource URL.
static constexpr OUStringLiteral msResourceActivationRequestEvent
static const OUString msNotesViewURL
static const OUString msOutlineViewURL
static constexpr OUStringLiteral msResourceDeactivationRequestEvent
static constexpr OUStringLiteral msResourceActivationEvent
static const OUString msImpressViewURL
virtual void disposing(std::unique_lock< std::mutex > &) override
css::uno::Reference< css::drawing::framework::XConfigurationController > mxConfigurationController
void UpdateViewTabBar(const css::uno::Reference< css::drawing::framework::XTabBar > &rxTabBar)
This is the place where the view tab bar is filled.
ViewTabBarModule(const rtl::Reference<::sd::DrawController > &rxController, const css::uno::Reference< css::drawing::framework::XResourceId > &rxViewTabBarId)
Create a new module that controls the view tab bar above the view in the specified pane.
css::uno::Reference< css::drawing::framework::XResourceId > mxViewTabBarId
virtual void SAL_CALL notifyConfigurationChange(const css::drawing::framework::ConfigurationChangeEvent &rEvent) override
OUString SdResId(TranslateId aId)
Definition: sdmod.cxx:83