1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ViewTabBarModule.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "precompiled_sd.hxx"
33 #include "ViewTabBarModule.hxx"
35 #include "framework/FrameworkHelper.hxx"
36 #include "framework/ConfigurationController.hxx"
37 #include <com/sun/star/drawing/framework/XControllerManager.hpp>
38 #include <com/sun/star/drawing/framework/XTabBar.hpp>
40 #include "strings.hrc"
41 #include "sdresid.hxx"
44 using namespace ::com::sun::star
;
45 using namespace ::com::sun::star::uno
;
46 using namespace ::com::sun::star::drawing::framework
;
48 using ::rtl::OUString
;
49 using ::sd::framework::FrameworkHelper
;
53 static const sal_Int32 ResourceActivationRequestEvent
= 0;
54 static const sal_Int32 ResourceDeactivationRequestEvent
= 1;
55 static const sal_Int32 ResourceActivationEvent
= 2;
59 namespace sd
{ namespace framework
{
61 //===== ViewTabBarModule ==================================================
63 ViewTabBarModule::ViewTabBarModule (
64 const Reference
<frame::XController
>& rxController
,
65 const Reference
<XResourceId
>& rxViewTabBarId
)
66 : ViewTabBarModuleInterfaceBase(MutexOwner::maMutex
),
67 mxConfigurationController(),
68 mxViewTabBarId(rxViewTabBarId
)
70 Reference
<XControllerManager
> xControllerManager (rxController
, UNO_QUERY
);
72 if (xControllerManager
.is())
74 mxConfigurationController
= xControllerManager
->getConfigurationController();
75 if (mxConfigurationController
.is())
77 mxConfigurationController
->addConfigurationChangeListener(
79 FrameworkHelper::msResourceActivationRequestEvent
,
80 makeAny(ResourceActivationRequestEvent
));
81 mxConfigurationController
->addConfigurationChangeListener(
83 FrameworkHelper::msResourceDeactivationRequestEvent
,
84 makeAny(ResourceDeactivationRequestEvent
));
86 UpdateViewTabBar(NULL
);
87 mxConfigurationController
->addConfigurationChangeListener(
89 FrameworkHelper::msResourceActivationEvent
,
90 makeAny(ResourceActivationEvent
));
98 ViewTabBarModule::~ViewTabBarModule (void)
105 void SAL_CALL
ViewTabBarModule::disposing (void)
107 if (mxConfigurationController
.is())
108 mxConfigurationController
->removeConfigurationChangeListener(this);
110 mxConfigurationController
= NULL
;
116 void SAL_CALL
ViewTabBarModule::notifyConfigurationChange (
117 const ConfigurationChangeEvent
& rEvent
)
118 throw (RuntimeException
)
120 if (mxConfigurationController
.is())
122 sal_Int32 nEventType
= 0;
123 rEvent
.UserData
>>= nEventType
;
126 case ResourceActivationRequestEvent
:
127 if (mxViewTabBarId
->isBoundTo(rEvent
.ResourceId
, AnchorBindingMode_DIRECT
))
129 mxConfigurationController
->requestResourceActivation(
131 ResourceActivationMode_ADD
);
135 case ResourceDeactivationRequestEvent
:
136 if (mxViewTabBarId
->isBoundTo(rEvent
.ResourceId
, AnchorBindingMode_DIRECT
))
138 mxConfigurationController
->requestResourceDeactivation(mxViewTabBarId
);
142 case ResourceActivationEvent
:
143 if (rEvent
.ResourceId
->compareTo(mxViewTabBarId
) == 0)
145 UpdateViewTabBar(Reference
<XTabBar
>(rEvent
.ResourceObject
,UNO_QUERY
));
154 void SAL_CALL
ViewTabBarModule::disposing (
155 const lang::EventObject
& rEvent
)
156 throw (RuntimeException
)
158 if (mxConfigurationController
.is()
159 && rEvent
.Source
== mxConfigurationController
)
161 // Without the configuration controller this class can do nothing.
162 mxConfigurationController
= NULL
;
170 void ViewTabBarModule::UpdateViewTabBar (const Reference
<XTabBar
>& rxTabBar
)
172 if (mxConfigurationController
.is())
174 Reference
<XTabBar
> xBar (rxTabBar
);
176 xBar
= Reference
<XTabBar
>(
177 mxConfigurationController
->getResource(mxViewTabBarId
), UNO_QUERY
);
181 TabBarButton aEmptyButton
;
183 Reference
<XResourceId
> xAnchor (mxViewTabBarId
->getAnchor());
185 TabBarButton aImpressViewButton
;
186 aImpressViewButton
.ResourceId
= FrameworkHelper::CreateResourceId(
187 FrameworkHelper::msImpressViewURL
,
189 aImpressViewButton
.ButtonLabel
= String(SdResId(STR_DRAW_MODE
));
190 if ( ! xBar
->hasTabBarButton(aImpressViewButton
))
191 xBar
->addTabBarButtonAfter(aImpressViewButton
, aEmptyButton
);
193 TabBarButton aOutlineViewButton
;
194 aOutlineViewButton
.ResourceId
= FrameworkHelper::CreateResourceId(
195 FrameworkHelper::msOutlineViewURL
,
197 aOutlineViewButton
.ButtonLabel
= String(SdResId(STR_OUTLINE_MODE
));
198 if ( ! xBar
->hasTabBarButton(aOutlineViewButton
))
199 xBar
->addTabBarButtonAfter(aOutlineViewButton
, aImpressViewButton
);
201 TabBarButton aNotesViewButton
;
202 aNotesViewButton
.ResourceId
= FrameworkHelper::CreateResourceId(
203 FrameworkHelper::msNotesViewURL
,
205 aNotesViewButton
.ButtonLabel
= String(SdResId(STR_NOTES_MODE
));
206 if ( ! xBar
->hasTabBarButton(aNotesViewButton
))
207 xBar
->addTabBarButtonAfter(aNotesViewButton
, aOutlineViewButton
);
209 TabBarButton aHandoutViewButton
;
210 aHandoutViewButton
.ResourceId
= FrameworkHelper::CreateResourceId(
211 FrameworkHelper::msHandoutViewURL
,
213 aHandoutViewButton
.ButtonLabel
= String(SdResId(STR_HANDOUT_MODE
));
214 if ( ! xBar
->hasTabBarButton(aHandoutViewButton
))
215 xBar
->addTabBarButtonAfter(aHandoutViewButton
, aNotesViewButton
);
223 } } // end of namespace sd::framework