1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #include "precompiled_sd.hxx"
29 
30 #include "ViewTabBarModule.hxx"
31 
32 #include "framework/FrameworkHelper.hxx"
33 #include "framework/ConfigurationController.hxx"
34 #include <com/sun/star/drawing/framework/XControllerManager.hpp>
35 #include <com/sun/star/drawing/framework/XTabBar.hpp>
36 
37 #include "strings.hrc"
38 #include "sdresid.hxx"
39 
40 
41 using namespace ::com::sun::star;
42 using namespace ::com::sun::star::uno;
43 using namespace ::com::sun::star::drawing::framework;
44 
45 using ::rtl::OUString;
46 using ::sd::framework::FrameworkHelper;
47 
48 namespace {
49 
50 static const sal_Int32 ResourceActivationRequestEvent = 0;
51 static const sal_Int32 ResourceDeactivationRequestEvent = 1;
52 static const sal_Int32 ResourceActivationEvent = 2;
53 
54 }
55 
56 namespace sd { namespace framework {
57 
58 //===== ViewTabBarModule ==================================================
59 
60 ViewTabBarModule::ViewTabBarModule (
61     const Reference<frame::XController>& rxController,
62     const Reference<XResourceId>& rxViewTabBarId)
63     : ViewTabBarModuleInterfaceBase(MutexOwner::maMutex),
64       mxConfigurationController(),
65       mxViewTabBarId(rxViewTabBarId)
66 {
67     Reference<XControllerManager> xControllerManager (rxController, UNO_QUERY);
68 
69     if (xControllerManager.is())
70     {
71         mxConfigurationController = xControllerManager->getConfigurationController();
72         if (mxConfigurationController.is())
73         {
74             mxConfigurationController->addConfigurationChangeListener(
75                 this,
76                 FrameworkHelper::msResourceActivationRequestEvent,
77                 makeAny(ResourceActivationRequestEvent));
78             mxConfigurationController->addConfigurationChangeListener(
79                 this,
80                 FrameworkHelper::msResourceDeactivationRequestEvent,
81                 makeAny(ResourceDeactivationRequestEvent));
82 
83             UpdateViewTabBar(NULL);
84             mxConfigurationController->addConfigurationChangeListener(
85                 this,
86                 FrameworkHelper::msResourceActivationEvent,
87                 makeAny(ResourceActivationEvent));
88         }
89     }
90 }
91 
92 
93 
94 
95 ViewTabBarModule::~ViewTabBarModule (void)
96 {
97 }
98 
99 
100 
101 
102 void SAL_CALL ViewTabBarModule::disposing (void)
103 {
104     if (mxConfigurationController.is())
105         mxConfigurationController->removeConfigurationChangeListener(this);
106 
107     mxConfigurationController = NULL;
108 }
109 
110 
111 
112 
113 void SAL_CALL ViewTabBarModule::notifyConfigurationChange (
114     const ConfigurationChangeEvent& rEvent)
115     throw (RuntimeException)
116 {
117     if (mxConfigurationController.is())
118     {
119         sal_Int32 nEventType = 0;
120         rEvent.UserData >>= nEventType;
121         switch (nEventType)
122         {
123             case ResourceActivationRequestEvent:
124                 if (mxViewTabBarId->isBoundTo(rEvent.ResourceId, AnchorBindingMode_DIRECT))
125                 {
126                     mxConfigurationController->requestResourceActivation(
127                         mxViewTabBarId,
128                         ResourceActivationMode_ADD);
129                 }
130                 break;
131 
132             case ResourceDeactivationRequestEvent:
133                 if (mxViewTabBarId->isBoundTo(rEvent.ResourceId, AnchorBindingMode_DIRECT))
134                 {
135                     mxConfigurationController->requestResourceDeactivation(mxViewTabBarId);
136                 }
137                 break;
138 
139             case ResourceActivationEvent:
140                 if (rEvent.ResourceId->compareTo(mxViewTabBarId) == 0)
141                 {
142                     UpdateViewTabBar(Reference<XTabBar>(rEvent.ResourceObject,UNO_QUERY));
143                 }
144         }
145     }
146 }
147 
148 
149 
150 
151 void SAL_CALL ViewTabBarModule::disposing (
152     const lang::EventObject& rEvent)
153     throw (RuntimeException)
154 {
155     if (mxConfigurationController.is()
156         && rEvent.Source == mxConfigurationController)
157     {
158         // Without the configuration controller this class can do nothing.
159         mxConfigurationController = NULL;
160         disposing();
161     }
162 }
163 
164 
165 
166 
167 void ViewTabBarModule::UpdateViewTabBar (const Reference<XTabBar>& rxTabBar)
168 {
169     if (mxConfigurationController.is())
170     {
171         Reference<XTabBar> xBar (rxTabBar);
172         if ( ! xBar.is())
173             xBar = Reference<XTabBar>(
174                 mxConfigurationController->getResource(mxViewTabBarId), UNO_QUERY);
175 
176         if (xBar.is())
177         {
178             TabBarButton aEmptyButton;
179 
180             Reference<XResourceId> xAnchor (mxViewTabBarId->getAnchor());
181 
182             TabBarButton aImpressViewButton;
183             aImpressViewButton.ResourceId = FrameworkHelper::CreateResourceId(
184                 FrameworkHelper::msImpressViewURL,
185                 xAnchor);
186             aImpressViewButton.ButtonLabel = String(SdResId(STR_DRAW_MODE));
187             if ( ! xBar->hasTabBarButton(aImpressViewButton))
188                 xBar->addTabBarButtonAfter(aImpressViewButton, aEmptyButton);
189 
190             TabBarButton aOutlineViewButton;
191             aOutlineViewButton.ResourceId = FrameworkHelper::CreateResourceId(
192                 FrameworkHelper::msOutlineViewURL,
193                 xAnchor);
194             aOutlineViewButton.ButtonLabel = String(SdResId(STR_OUTLINE_MODE));
195             if ( ! xBar->hasTabBarButton(aOutlineViewButton))
196                 xBar->addTabBarButtonAfter(aOutlineViewButton, aImpressViewButton);
197 
198             TabBarButton aNotesViewButton;
199             aNotesViewButton.ResourceId = FrameworkHelper::CreateResourceId(
200                 FrameworkHelper::msNotesViewURL,
201                 xAnchor);
202             aNotesViewButton.ButtonLabel = String(SdResId(STR_NOTES_MODE));
203             if ( ! xBar->hasTabBarButton(aNotesViewButton))
204                 xBar->addTabBarButtonAfter(aNotesViewButton, aOutlineViewButton);
205 
206             TabBarButton aHandoutViewButton;
207             aHandoutViewButton.ResourceId = FrameworkHelper::CreateResourceId(
208                 FrameworkHelper::msHandoutViewURL,
209                 xAnchor);
210             aHandoutViewButton.ButtonLabel = String(SdResId(STR_HANDOUT_MODE));
211             if ( ! xBar->hasTabBarButton(aHandoutViewButton))
212                 xBar->addTabBarButtonAfter(aHandoutViewButton, aNotesViewButton);
213         }
214     }
215 }
216 
217 
218 
219 
220 } } // end of namespace sd::framework
221