1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 #include "precompiled_sd.hxx"
25
26 #include "ViewTabBarModule.hxx"
27
28 #include "framework/FrameworkHelper.hxx"
29 #include "framework/ConfigurationController.hxx"
30 #include <com/sun/star/drawing/framework/XControllerManager.hpp>
31 #include <com/sun/star/drawing/framework/XTabBar.hpp>
32
33 #include "strings.hrc"
34 #include "sdresid.hxx"
35
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 ::rtl::OUString;
42 using ::sd::framework::FrameworkHelper;
43
44 namespace {
45
46 static const sal_Int32 ResourceActivationRequestEvent = 0;
47 static const sal_Int32 ResourceDeactivationRequestEvent = 1;
48 static const sal_Int32 ResourceActivationEvent = 2;
49
50 }
51
52 namespace sd { namespace framework {
53
54 //===== ViewTabBarModule ==================================================
55
ViewTabBarModule(const Reference<frame::XController> & rxController,const Reference<XResourceId> & rxViewTabBarId)56 ViewTabBarModule::ViewTabBarModule (
57 const Reference<frame::XController>& rxController,
58 const Reference<XResourceId>& rxViewTabBarId)
59 : ViewTabBarModuleInterfaceBase(MutexOwner::maMutex),
60 mxConfigurationController(),
61 mxViewTabBarId(rxViewTabBarId)
62 {
63 Reference<XControllerManager> xControllerManager (rxController, UNO_QUERY);
64
65 if (xControllerManager.is())
66 {
67 mxConfigurationController = xControllerManager->getConfigurationController();
68 if (mxConfigurationController.is())
69 {
70 mxConfigurationController->addConfigurationChangeListener(
71 this,
72 FrameworkHelper::msResourceActivationRequestEvent,
73 makeAny(ResourceActivationRequestEvent));
74 mxConfigurationController->addConfigurationChangeListener(
75 this,
76 FrameworkHelper::msResourceDeactivationRequestEvent,
77 makeAny(ResourceDeactivationRequestEvent));
78
79 UpdateViewTabBar(NULL);
80 mxConfigurationController->addConfigurationChangeListener(
81 this,
82 FrameworkHelper::msResourceActivationEvent,
83 makeAny(ResourceActivationEvent));
84 }
85 }
86 }
87
88
89
90
~ViewTabBarModule(void)91 ViewTabBarModule::~ViewTabBarModule (void)
92 {
93 }
94
95
96
97
disposing(void)98 void SAL_CALL ViewTabBarModule::disposing (void)
99 {
100 if (mxConfigurationController.is())
101 mxConfigurationController->removeConfigurationChangeListener(this);
102
103 mxConfigurationController = NULL;
104 }
105
106
107
108
notifyConfigurationChange(const ConfigurationChangeEvent & rEvent)109 void SAL_CALL ViewTabBarModule::notifyConfigurationChange (
110 const ConfigurationChangeEvent& rEvent)
111 {
112 if (mxConfigurationController.is())
113 {
114 sal_Int32 nEventType = 0;
115 rEvent.UserData >>= nEventType;
116 switch (nEventType)
117 {
118 case ResourceActivationRequestEvent:
119 if (mxViewTabBarId->isBoundTo(rEvent.ResourceId, AnchorBindingMode_DIRECT))
120 {
121 mxConfigurationController->requestResourceActivation(
122 mxViewTabBarId,
123 ResourceActivationMode_ADD);
124 }
125 break;
126
127 case ResourceDeactivationRequestEvent:
128 if (mxViewTabBarId->isBoundTo(rEvent.ResourceId, AnchorBindingMode_DIRECT))
129 {
130 mxConfigurationController->requestResourceDeactivation(mxViewTabBarId);
131 }
132 break;
133
134 case ResourceActivationEvent:
135 if (rEvent.ResourceId->compareTo(mxViewTabBarId) == 0)
136 {
137 UpdateViewTabBar(Reference<XTabBar>(rEvent.ResourceObject,UNO_QUERY));
138 }
139 }
140 }
141 }
142
143
144
145
disposing(const lang::EventObject & rEvent)146 void SAL_CALL ViewTabBarModule::disposing (
147 const lang::EventObject& rEvent)
148 {
149 if (mxConfigurationController.is()
150 && rEvent.Source == mxConfigurationController)
151 {
152 // Without the configuration controller this class can do nothing.
153 mxConfigurationController = NULL;
154 disposing();
155 }
156 }
157
158
159
160
UpdateViewTabBar(const Reference<XTabBar> & rxTabBar)161 void ViewTabBarModule::UpdateViewTabBar (const Reference<XTabBar>& rxTabBar)
162 {
163 if (mxConfigurationController.is())
164 {
165 Reference<XTabBar> xBar (rxTabBar);
166 if ( ! xBar.is())
167 xBar = Reference<XTabBar>(
168 mxConfigurationController->getResource(mxViewTabBarId), UNO_QUERY);
169
170 if (xBar.is())
171 {
172 TabBarButton aEmptyButton;
173
174 Reference<XResourceId> xAnchor (mxViewTabBarId->getAnchor());
175
176 TabBarButton aImpressViewButton;
177 aImpressViewButton.ResourceId = FrameworkHelper::CreateResourceId(
178 FrameworkHelper::msImpressViewURL,
179 xAnchor);
180 aImpressViewButton.ButtonLabel = String(SdResId(STR_DRAW_MODE));
181 if ( ! xBar->hasTabBarButton(aImpressViewButton))
182 xBar->addTabBarButtonAfter(aImpressViewButton, aEmptyButton);
183
184 TabBarButton aOutlineViewButton;
185 aOutlineViewButton.ResourceId = FrameworkHelper::CreateResourceId(
186 FrameworkHelper::msOutlineViewURL,
187 xAnchor);
188 aOutlineViewButton.ButtonLabel = String(SdResId(STR_OUTLINE_MODE));
189 if ( ! xBar->hasTabBarButton(aOutlineViewButton))
190 xBar->addTabBarButtonAfter(aOutlineViewButton, aImpressViewButton);
191
192 TabBarButton aNotesViewButton;
193 aNotesViewButton.ResourceId = FrameworkHelper::CreateResourceId(
194 FrameworkHelper::msNotesViewURL,
195 xAnchor);
196 aNotesViewButton.ButtonLabel = String(SdResId(STR_NOTES_MODE));
197 if ( ! xBar->hasTabBarButton(aNotesViewButton))
198 xBar->addTabBarButtonAfter(aNotesViewButton, aOutlineViewButton);
199
200 TabBarButton aHandoutViewButton;
201 aHandoutViewButton.ResourceId = FrameworkHelper::CreateResourceId(
202 FrameworkHelper::msHandoutViewURL,
203 xAnchor);
204 aHandoutViewButton.ButtonLabel = String(SdResId(STR_HANDOUT_MODE));
205 if ( ! xBar->hasTabBarButton(aHandoutViewButton))
206 xBar->addTabBarButtonAfter(aHandoutViewButton, aNotesViewButton);
207 }
208 }
209 }
210
211
212
213
214 } } // end of namespace sd::framework
215