bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / framework / module / ViewTabBarModule.cxx
blobccf08fbabe472226d614ef508919b4581ab74f77
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include "ViewTabBarModule.hxx"
22 #include "framework/FrameworkHelper.hxx"
23 #include "framework/ConfigurationController.hxx"
24 #include <com/sun/star/drawing/framework/XControllerManager.hpp>
25 #include <com/sun/star/drawing/framework/XTabBar.hpp>
27 #include "strings.hrc"
28 #include "sdresid.hxx"
30 using namespace ::com::sun::star;
31 using namespace ::com::sun::star::uno;
32 using namespace ::com::sun::star::drawing::framework;
34 using ::sd::framework::FrameworkHelper;
36 namespace {
38 static const sal_Int32 ResourceActivationRequestEvent = 0;
39 static const sal_Int32 ResourceDeactivationRequestEvent = 1;
40 static const sal_Int32 ResourceActivationEvent = 2;
44 namespace sd { namespace framework {
46 //===== ViewTabBarModule ==================================================
48 ViewTabBarModule::ViewTabBarModule (
49 const Reference<frame::XController>& rxController,
50 const Reference<XResourceId>& rxViewTabBarId)
51 : ViewTabBarModuleInterfaceBase(MutexOwner::maMutex),
52 mxConfigurationController(),
53 mxViewTabBarId(rxViewTabBarId)
55 Reference<XControllerManager> xControllerManager (rxController, UNO_QUERY);
57 if (xControllerManager.is())
59 mxConfigurationController = xControllerManager->getConfigurationController();
60 if (mxConfigurationController.is())
62 mxConfigurationController->addConfigurationChangeListener(
63 this,
64 FrameworkHelper::msResourceActivationRequestEvent,
65 makeAny(ResourceActivationRequestEvent));
66 mxConfigurationController->addConfigurationChangeListener(
67 this,
68 FrameworkHelper::msResourceDeactivationRequestEvent,
69 makeAny(ResourceDeactivationRequestEvent));
71 UpdateViewTabBar(NULL);
72 mxConfigurationController->addConfigurationChangeListener(
73 this,
74 FrameworkHelper::msResourceActivationEvent,
75 makeAny(ResourceActivationEvent));
80 ViewTabBarModule::~ViewTabBarModule()
84 void SAL_CALL ViewTabBarModule::disposing()
86 if (mxConfigurationController.is())
87 mxConfigurationController->removeConfigurationChangeListener(this);
89 mxConfigurationController = NULL;
92 void SAL_CALL ViewTabBarModule::notifyConfigurationChange (
93 const ConfigurationChangeEvent& rEvent)
94 throw (RuntimeException, std::exception)
96 if (mxConfigurationController.is())
98 sal_Int32 nEventType = 0;
99 rEvent.UserData >>= nEventType;
100 switch (nEventType)
102 case ResourceActivationRequestEvent:
103 if (mxViewTabBarId->isBoundTo(rEvent.ResourceId, AnchorBindingMode_DIRECT))
105 mxConfigurationController->requestResourceActivation(
106 mxViewTabBarId,
107 ResourceActivationMode_ADD);
109 break;
111 case ResourceDeactivationRequestEvent:
112 if (mxViewTabBarId->isBoundTo(rEvent.ResourceId, AnchorBindingMode_DIRECT))
114 mxConfigurationController->requestResourceDeactivation(mxViewTabBarId);
116 break;
118 case ResourceActivationEvent:
119 if (rEvent.ResourceId->compareTo(mxViewTabBarId) == 0)
121 UpdateViewTabBar(Reference<XTabBar>(rEvent.ResourceObject,UNO_QUERY));
127 void SAL_CALL ViewTabBarModule::disposing (
128 const lang::EventObject& rEvent)
129 throw (RuntimeException, std::exception)
131 if (mxConfigurationController.is()
132 && rEvent.Source == mxConfigurationController)
134 // Without the configuration controller this class can do nothing.
135 mxConfigurationController = NULL;
136 disposing();
140 void ViewTabBarModule::UpdateViewTabBar (const Reference<XTabBar>& rxTabBar)
142 if (mxConfigurationController.is())
144 Reference<XTabBar> xBar (rxTabBar);
145 if ( ! xBar.is())
146 xBar = Reference<XTabBar>(
147 mxConfigurationController->getResource(mxViewTabBarId), UNO_QUERY);
149 if (xBar.is())
151 TabBarButton aEmptyButton;
153 Reference<XResourceId> xAnchor (mxViewTabBarId->getAnchor());
155 TabBarButton aImpressViewButton;
156 aImpressViewButton.ResourceId = FrameworkHelper::CreateResourceId(
157 FrameworkHelper::msImpressViewURL,
158 xAnchor);
159 aImpressViewButton.ButtonLabel = SD_RESSTR(STR_DRAW_MODE);
160 if ( ! xBar->hasTabBarButton(aImpressViewButton))
161 xBar->addTabBarButtonAfter(aImpressViewButton, aEmptyButton);
163 TabBarButton aOutlineViewButton;
164 aOutlineViewButton.ResourceId = FrameworkHelper::CreateResourceId(
165 FrameworkHelper::msOutlineViewURL,
166 xAnchor);
167 aOutlineViewButton.ButtonLabel = SD_RESSTR(STR_OUTLINE_MODE);
168 if ( ! xBar->hasTabBarButton(aOutlineViewButton))
169 xBar->addTabBarButtonAfter(aOutlineViewButton, aImpressViewButton);
171 TabBarButton aNotesViewButton;
172 aNotesViewButton.ResourceId = FrameworkHelper::CreateResourceId(
173 FrameworkHelper::msNotesViewURL,
174 xAnchor);
175 aNotesViewButton.ButtonLabel = SD_RESSTR(STR_NOTES_MODE);
176 if ( ! xBar->hasTabBarButton(aNotesViewButton))
177 xBar->addTabBarButtonAfter(aNotesViewButton, aOutlineViewButton);
179 TabBarButton aHandoutViewButton;
180 aHandoutViewButton.ResourceId = FrameworkHelper::CreateResourceId(
181 FrameworkHelper::msHandoutViewURL,
182 xAnchor);
183 aHandoutViewButton.ButtonLabel = SD_RESSTR(STR_HANDOUT_MODE);
184 if ( ! xBar->hasTabBarButton(aHandoutViewButton))
185 xBar->addTabBarButtonAfter(aHandoutViewButton, aNotesViewButton);
190 } } // end of namespace sd::framework
192 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */