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 "ViewTabBarModule.hxx"
22 : :
23 : : #include "framework/FrameworkHelper.hxx"
24 : : #include "framework/ConfigurationController.hxx"
25 : : #include <com/sun/star/drawing/framework/XControllerManager.hpp>
26 : : #include <com/sun/star/drawing/framework/XTabBar.hpp>
27 : :
28 : : #include "strings.hrc"
29 : : #include "sdresid.hxx"
30 : :
31 : :
32 : : using namespace ::com::sun::star;
33 : : using namespace ::com::sun::star::uno;
34 : : using namespace ::com::sun::star::drawing::framework;
35 : :
36 : : using ::rtl::OUString;
37 : : using ::sd::framework::FrameworkHelper;
38 : :
39 : : namespace {
40 : :
41 : : static const sal_Int32 ResourceActivationRequestEvent = 0;
42 : : static const sal_Int32 ResourceDeactivationRequestEvent = 1;
43 : : static const sal_Int32 ResourceActivationEvent = 2;
44 : :
45 : : }
46 : :
47 : : namespace sd { namespace framework {
48 : :
49 : : //===== ViewTabBarModule ==================================================
50 : :
51 : 26 : ViewTabBarModule::ViewTabBarModule (
52 : : const Reference<frame::XController>& rxController,
53 : : const Reference<XResourceId>& rxViewTabBarId)
54 : : : ViewTabBarModuleInterfaceBase(MutexOwner::maMutex),
55 : : mxConfigurationController(),
56 : 26 : mxViewTabBarId(rxViewTabBarId)
57 : : {
58 [ + - ]: 26 : Reference<XControllerManager> xControllerManager (rxController, UNO_QUERY);
59 : :
60 [ + - ]: 26 : if (xControllerManager.is())
61 : : {
62 [ + - ][ + - ]: 26 : mxConfigurationController = xControllerManager->getConfigurationController();
[ + - ]
63 [ + - ]: 26 : if (mxConfigurationController.is())
64 : : {
65 [ + - ]: 26 : mxConfigurationController->addConfigurationChangeListener(
66 : : this,
67 : : FrameworkHelper::msResourceActivationRequestEvent,
68 [ + - ][ + - ]: 26 : makeAny(ResourceActivationRequestEvent));
[ + - ]
69 [ + - ]: 26 : mxConfigurationController->addConfigurationChangeListener(
70 : : this,
71 : : FrameworkHelper::msResourceDeactivationRequestEvent,
72 [ + - ][ + - ]: 26 : makeAny(ResourceDeactivationRequestEvent));
[ + - ]
73 : :
74 [ + - ][ + - ]: 26 : UpdateViewTabBar(NULL);
75 [ + - ]: 26 : mxConfigurationController->addConfigurationChangeListener(
76 : : this,
77 : : FrameworkHelper::msResourceActivationEvent,
78 [ + - ][ + - ]: 26 : makeAny(ResourceActivationEvent));
[ + - ]
79 : : }
80 : 26 : }
81 : 26 : }
82 : :
83 : :
84 : :
85 : :
86 [ + - ]: 26 : ViewTabBarModule::~ViewTabBarModule (void)
87 : : {
88 [ - + ]: 52 : }
89 : :
90 : :
91 : :
92 : :
93 : 52 : void SAL_CALL ViewTabBarModule::disposing (void)
94 : : {
95 [ - + ]: 52 : if (mxConfigurationController.is())
96 [ # # ]: 0 : mxConfigurationController->removeConfigurationChangeListener(this);
97 : :
98 : 52 : mxConfigurationController = NULL;
99 : 52 : }
100 : :
101 : :
102 : :
103 : :
104 : 664 : void SAL_CALL ViewTabBarModule::notifyConfigurationChange (
105 : : const ConfigurationChangeEvent& rEvent)
106 : : throw (RuntimeException)
107 : : {
108 [ + - ]: 664 : if (mxConfigurationController.is())
109 : : {
110 : 664 : sal_Int32 nEventType = 0;
111 : 664 : rEvent.UserData >>= nEventType;
112 [ + + + - ]: 664 : switch (nEventType)
113 : : {
114 : : case ResourceActivationRequestEvent:
115 [ + - ][ + - ]: 204 : if (mxViewTabBarId->isBoundTo(rEvent.ResourceId, AnchorBindingMode_DIRECT))
[ + + ]
116 : : {
117 [ + - ]: 26 : mxConfigurationController->requestResourceActivation(
118 : : mxViewTabBarId,
119 [ + - ]: 26 : ResourceActivationMode_ADD);
120 : : }
121 : 204 : break;
122 : :
123 : : case ResourceDeactivationRequestEvent:
124 [ + - ][ + - ]: 204 : if (mxViewTabBarId->isBoundTo(rEvent.ResourceId, AnchorBindingMode_DIRECT))
[ + + ]
125 : : {
126 [ + - ][ + - ]: 26 : mxConfigurationController->requestResourceDeactivation(mxViewTabBarId);
127 : : }
128 : 204 : break;
129 : :
130 : : case ResourceActivationEvent:
131 [ + - ][ + - ]: 256 : if (rEvent.ResourceId->compareTo(mxViewTabBarId) == 0)
[ + + ]
132 : : {
133 [ + - ][ + - ]: 664 : UpdateViewTabBar(Reference<XTabBar>(rEvent.ResourceObject,UNO_QUERY));
134 : : }
135 : : }
136 : : }
137 : 664 : }
138 : :
139 : :
140 : :
141 : :
142 : 52 : void SAL_CALL ViewTabBarModule::disposing (
143 : : const lang::EventObject& rEvent)
144 : : throw (RuntimeException)
145 : : {
146 [ + + + - ]: 78 : if (mxConfigurationController.is()
[ + + ]
147 : 26 : && rEvent.Source == mxConfigurationController)
148 : : {
149 : : // Without the configuration controller this class can do nothing.
150 : 26 : mxConfigurationController = NULL;
151 : 26 : disposing();
152 : : }
153 : 52 : }
154 : :
155 : :
156 : :
157 : :
158 : 52 : void ViewTabBarModule::UpdateViewTabBar (const Reference<XTabBar>& rxTabBar)
159 : : {
160 [ + - ]: 52 : if (mxConfigurationController.is())
161 : : {
162 : 52 : Reference<XTabBar> xBar (rxTabBar);
163 [ + + ]: 52 : if ( ! xBar.is())
164 : : xBar = Reference<XTabBar>(
165 [ + - ][ + - ]: 26 : mxConfigurationController->getResource(mxViewTabBarId), UNO_QUERY);
[ + - ][ + - ]
166 : :
167 [ + + ]: 52 : if (xBar.is())
168 : : {
169 [ + - ]: 26 : TabBarButton aEmptyButton;
170 : :
171 [ + - ][ + - ]: 26 : Reference<XResourceId> xAnchor (mxViewTabBarId->getAnchor());
172 : :
173 [ + - ]: 26 : TabBarButton aImpressViewButton;
174 : : aImpressViewButton.ResourceId = FrameworkHelper::CreateResourceId(
175 : : FrameworkHelper::msImpressViewURL,
176 [ + - ][ + - ]: 26 : xAnchor);
177 [ + - ][ + - ]: 26 : aImpressViewButton.ButtonLabel = String(SdResId(STR_DRAW_MODE));
[ + - ][ + - ]
178 [ + - ][ + - ]: 26 : if ( ! xBar->hasTabBarButton(aImpressViewButton))
[ + - ]
179 [ + - ][ + - ]: 26 : xBar->addTabBarButtonAfter(aImpressViewButton, aEmptyButton);
180 : :
181 [ + - ]: 26 : TabBarButton aOutlineViewButton;
182 : : aOutlineViewButton.ResourceId = FrameworkHelper::CreateResourceId(
183 : : FrameworkHelper::msOutlineViewURL,
184 [ + - ][ + - ]: 26 : xAnchor);
185 [ + - ][ + - ]: 26 : aOutlineViewButton.ButtonLabel = String(SdResId(STR_OUTLINE_MODE));
[ + - ][ + - ]
186 [ + - ][ + - ]: 26 : if ( ! xBar->hasTabBarButton(aOutlineViewButton))
[ + - ]
187 [ + - ][ + - ]: 26 : xBar->addTabBarButtonAfter(aOutlineViewButton, aImpressViewButton);
188 : :
189 [ + - ]: 26 : TabBarButton aNotesViewButton;
190 : : aNotesViewButton.ResourceId = FrameworkHelper::CreateResourceId(
191 : : FrameworkHelper::msNotesViewURL,
192 [ + - ][ + - ]: 26 : xAnchor);
193 [ + - ][ + - ]: 26 : aNotesViewButton.ButtonLabel = String(SdResId(STR_NOTES_MODE));
[ + - ][ + - ]
194 [ + - ][ + - ]: 26 : if ( ! xBar->hasTabBarButton(aNotesViewButton))
[ + - ]
195 [ + - ][ + - ]: 26 : xBar->addTabBarButtonAfter(aNotesViewButton, aOutlineViewButton);
196 : :
197 [ + - ]: 26 : TabBarButton aHandoutViewButton;
198 : : aHandoutViewButton.ResourceId = FrameworkHelper::CreateResourceId(
199 : : FrameworkHelper::msHandoutViewURL,
200 [ + - ][ + - ]: 26 : xAnchor);
201 [ + - ][ + - ]: 26 : aHandoutViewButton.ButtonLabel = String(SdResId(STR_HANDOUT_MODE));
[ + - ][ + - ]
202 [ + - ][ + - ]: 26 : if ( ! xBar->hasTabBarButton(aHandoutViewButton))
[ + - ]
203 [ + - ][ + - ]: 26 : xBar->addTabBarButtonAfter(aHandoutViewButton, aNotesViewButton);
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
204 : 52 : }
205 : : }
206 : 52 : }
207 : :
208 : :
209 : :
210 : :
211 : : } } // end of namespace sd::framework
212 : :
213 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|