1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "ViewTabBarModule.hxx"
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>
28 #include "strings.hrc"
29 #include "sdresid.hxx"
32 using namespace ::com::sun::star
;
33 using namespace ::com::sun::star::uno
;
34 using namespace ::com::sun::star::drawing::framework
;
36 using ::sd::framework::FrameworkHelper
;
40 static const sal_Int32 ResourceActivationRequestEvent
= 0;
41 static const sal_Int32 ResourceDeactivationRequestEvent
= 1;
42 static const sal_Int32 ResourceActivationEvent
= 2;
46 namespace sd
{ namespace framework
{
48 //===== ViewTabBarModule ==================================================
50 ViewTabBarModule::ViewTabBarModule (
51 const Reference
<frame::XController
>& rxController
,
52 const Reference
<XResourceId
>& rxViewTabBarId
)
53 : ViewTabBarModuleInterfaceBase(MutexOwner::maMutex
),
54 mxConfigurationController(),
55 mxViewTabBarId(rxViewTabBarId
)
57 Reference
<XControllerManager
> xControllerManager (rxController
, UNO_QUERY
);
59 if (xControllerManager
.is())
61 mxConfigurationController
= xControllerManager
->getConfigurationController();
62 if (mxConfigurationController
.is())
64 mxConfigurationController
->addConfigurationChangeListener(
66 FrameworkHelper::msResourceActivationRequestEvent
,
67 makeAny(ResourceActivationRequestEvent
));
68 mxConfigurationController
->addConfigurationChangeListener(
70 FrameworkHelper::msResourceDeactivationRequestEvent
,
71 makeAny(ResourceDeactivationRequestEvent
));
73 UpdateViewTabBar(NULL
);
74 mxConfigurationController
->addConfigurationChangeListener(
76 FrameworkHelper::msResourceActivationEvent
,
77 makeAny(ResourceActivationEvent
));
85 ViewTabBarModule::~ViewTabBarModule (void)
92 void SAL_CALL
ViewTabBarModule::disposing (void)
94 if (mxConfigurationController
.is())
95 mxConfigurationController
->removeConfigurationChangeListener(this);
97 mxConfigurationController
= NULL
;
103 void SAL_CALL
ViewTabBarModule::notifyConfigurationChange (
104 const ConfigurationChangeEvent
& rEvent
)
105 throw (RuntimeException
)
107 if (mxConfigurationController
.is())
109 sal_Int32 nEventType
= 0;
110 rEvent
.UserData
>>= nEventType
;
113 case ResourceActivationRequestEvent
:
114 if (mxViewTabBarId
->isBoundTo(rEvent
.ResourceId
, AnchorBindingMode_DIRECT
))
116 mxConfigurationController
->requestResourceActivation(
118 ResourceActivationMode_ADD
);
122 case ResourceDeactivationRequestEvent
:
123 if (mxViewTabBarId
->isBoundTo(rEvent
.ResourceId
, AnchorBindingMode_DIRECT
))
125 mxConfigurationController
->requestResourceDeactivation(mxViewTabBarId
);
129 case ResourceActivationEvent
:
130 if (rEvent
.ResourceId
->compareTo(mxViewTabBarId
) == 0)
132 UpdateViewTabBar(Reference
<XTabBar
>(rEvent
.ResourceObject
,UNO_QUERY
));
141 void SAL_CALL
ViewTabBarModule::disposing (
142 const lang::EventObject
& rEvent
)
143 throw (RuntimeException
)
145 if (mxConfigurationController
.is()
146 && rEvent
.Source
== mxConfigurationController
)
148 // Without the configuration controller this class can do nothing.
149 mxConfigurationController
= NULL
;
157 void ViewTabBarModule::UpdateViewTabBar (const Reference
<XTabBar
>& rxTabBar
)
159 if (mxConfigurationController
.is())
161 Reference
<XTabBar
> xBar (rxTabBar
);
163 xBar
= Reference
<XTabBar
>(
164 mxConfigurationController
->getResource(mxViewTabBarId
), UNO_QUERY
);
168 TabBarButton aEmptyButton
;
170 Reference
<XResourceId
> xAnchor (mxViewTabBarId
->getAnchor());
172 TabBarButton aImpressViewButton
;
173 aImpressViewButton
.ResourceId
= FrameworkHelper::CreateResourceId(
174 FrameworkHelper::msImpressViewURL
,
176 aImpressViewButton
.ButtonLabel
= String(SdResId(STR_DRAW_MODE
));
177 if ( ! xBar
->hasTabBarButton(aImpressViewButton
))
178 xBar
->addTabBarButtonAfter(aImpressViewButton
, aEmptyButton
);
180 TabBarButton aOutlineViewButton
;
181 aOutlineViewButton
.ResourceId
= FrameworkHelper::CreateResourceId(
182 FrameworkHelper::msOutlineViewURL
,
184 aOutlineViewButton
.ButtonLabel
= String(SdResId(STR_OUTLINE_MODE
));
185 if ( ! xBar
->hasTabBarButton(aOutlineViewButton
))
186 xBar
->addTabBarButtonAfter(aOutlineViewButton
, aImpressViewButton
);
188 TabBarButton aNotesViewButton
;
189 aNotesViewButton
.ResourceId
= FrameworkHelper::CreateResourceId(
190 FrameworkHelper::msNotesViewURL
,
192 aNotesViewButton
.ButtonLabel
= String(SdResId(STR_NOTES_MODE
));
193 if ( ! xBar
->hasTabBarButton(aNotesViewButton
))
194 xBar
->addTabBarButtonAfter(aNotesViewButton
, aOutlineViewButton
);
196 TabBarButton aHandoutViewButton
;
197 aHandoutViewButton
.ResourceId
= FrameworkHelper::CreateResourceId(
198 FrameworkHelper::msHandoutViewURL
,
200 aHandoutViewButton
.ButtonLabel
= String(SdResId(STR_HANDOUT_MODE
));
201 if ( ! xBar
->hasTabBarButton(aHandoutViewButton
))
202 xBar
->addTabBarButtonAfter(aHandoutViewButton
, aNotesViewButton
);
210 } } // end of namespace sd::framework
212 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */