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     throw (RuntimeException)
112 {
113     if (mxConfigurationController.is())
114     {
115         sal_Int32 nEventType = 0;
116         rEvent.UserData >>= nEventType;
117         switch (nEventType)
118         {
119             case ResourceActivationRequestEvent:
120                 if (mxViewTabBarId->isBoundTo(rEvent.ResourceId, AnchorBindingMode_DIRECT))
121                 {
122                     mxConfigurationController->requestResourceActivation(
123                         mxViewTabBarId,
124                         ResourceActivationMode_ADD);
125                 }
126                 break;
127 
128             case ResourceDeactivationRequestEvent:
129                 if (mxViewTabBarId->isBoundTo(rEvent.ResourceId, AnchorBindingMode_DIRECT))
130                 {
131                     mxConfigurationController->requestResourceDeactivation(mxViewTabBarId);
132                 }
133                 break;
134 
135             case ResourceActivationEvent:
136                 if (rEvent.ResourceId->compareTo(mxViewTabBarId) == 0)
137                 {
138                     UpdateViewTabBar(Reference<XTabBar>(rEvent.ResourceObject,UNO_QUERY));
139                 }
140         }
141     }
142 }
143 
144 
145 
146 
disposing(const lang::EventObject & rEvent)147 void SAL_CALL ViewTabBarModule::disposing (
148     const lang::EventObject& rEvent)
149     throw (RuntimeException)
150 {
151     if (mxConfigurationController.is()
152         && rEvent.Source == mxConfigurationController)
153     {
154         // Without the configuration controller this class can do nothing.
155         mxConfigurationController = NULL;
156         disposing();
157     }
158 }
159 
160 
161 
162 
UpdateViewTabBar(const Reference<XTabBar> & rxTabBar)163 void ViewTabBarModule::UpdateViewTabBar (const Reference<XTabBar>& rxTabBar)
164 {
165     if (mxConfigurationController.is())
166     {
167         Reference<XTabBar> xBar (rxTabBar);
168         if ( ! xBar.is())
169             xBar = Reference<XTabBar>(
170                 mxConfigurationController->getResource(mxViewTabBarId), UNO_QUERY);
171 
172         if (xBar.is())
173         {
174             TabBarButton aEmptyButton;
175 
176             Reference<XResourceId> xAnchor (mxViewTabBarId->getAnchor());
177 
178             TabBarButton aImpressViewButton;
179             aImpressViewButton.ResourceId = FrameworkHelper::CreateResourceId(
180                 FrameworkHelper::msImpressViewURL,
181                 xAnchor);
182             aImpressViewButton.ButtonLabel = String(SdResId(STR_DRAW_MODE));
183             if ( ! xBar->hasTabBarButton(aImpressViewButton))
184                 xBar->addTabBarButtonAfter(aImpressViewButton, aEmptyButton);
185 
186             TabBarButton aOutlineViewButton;
187             aOutlineViewButton.ResourceId = FrameworkHelper::CreateResourceId(
188                 FrameworkHelper::msOutlineViewURL,
189                 xAnchor);
190             aOutlineViewButton.ButtonLabel = String(SdResId(STR_OUTLINE_MODE));
191             if ( ! xBar->hasTabBarButton(aOutlineViewButton))
192                 xBar->addTabBarButtonAfter(aOutlineViewButton, aImpressViewButton);
193 
194             TabBarButton aNotesViewButton;
195             aNotesViewButton.ResourceId = FrameworkHelper::CreateResourceId(
196                 FrameworkHelper::msNotesViewURL,
197                 xAnchor);
198             aNotesViewButton.ButtonLabel = String(SdResId(STR_NOTES_MODE));
199             if ( ! xBar->hasTabBarButton(aNotesViewButton))
200                 xBar->addTabBarButtonAfter(aNotesViewButton, aOutlineViewButton);
201 
202             TabBarButton aHandoutViewButton;
203             aHandoutViewButton.ResourceId = FrameworkHelper::CreateResourceId(
204                 FrameworkHelper::msHandoutViewURL,
205                 xAnchor);
206             aHandoutViewButton.ButtonLabel = String(SdResId(STR_HANDOUT_MODE));
207             if ( ! xBar->hasTabBarButton(aHandoutViewButton))
208                 xBar->addTabBarButtonAfter(aHandoutViewButton, aNotesViewButton);
209         }
210     }
211 }
212 
213 
214 
215 
216 } } // end of namespace sd::framework
217