Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "ViewTabBarModule.hxx"
21 :
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>
26 :
27 : #include "strings.hrc"
28 : #include "sdresid.hxx"
29 :
30 : using namespace ::com::sun::star;
31 : using namespace ::com::sun::star::uno;
32 : using namespace ::com::sun::star::drawing::framework;
33 :
34 : using ::sd::framework::FrameworkHelper;
35 :
36 : namespace {
37 :
38 : static const sal_Int32 ResourceActivationRequestEvent = 0;
39 : static const sal_Int32 ResourceDeactivationRequestEvent = 1;
40 : static const sal_Int32 ResourceActivationEvent = 2;
41 :
42 : }
43 :
44 : namespace sd { namespace framework {
45 :
46 : //===== ViewTabBarModule ==================================================
47 :
48 41 : ViewTabBarModule::ViewTabBarModule (
49 : const Reference<frame::XController>& rxController,
50 : const Reference<XResourceId>& rxViewTabBarId)
51 : : ViewTabBarModuleInterfaceBase(MutexOwner::maMutex),
52 : mxConfigurationController(),
53 41 : mxViewTabBarId(rxViewTabBarId)
54 : {
55 41 : Reference<XControllerManager> xControllerManager (rxController, UNO_QUERY);
56 :
57 41 : if (xControllerManager.is())
58 : {
59 41 : mxConfigurationController = xControllerManager->getConfigurationController();
60 41 : if (mxConfigurationController.is())
61 : {
62 41 : mxConfigurationController->addConfigurationChangeListener(
63 : this,
64 : FrameworkHelper::msResourceActivationRequestEvent,
65 41 : makeAny(ResourceActivationRequestEvent));
66 41 : mxConfigurationController->addConfigurationChangeListener(
67 : this,
68 : FrameworkHelper::msResourceDeactivationRequestEvent,
69 41 : makeAny(ResourceDeactivationRequestEvent));
70 :
71 41 : UpdateViewTabBar(NULL);
72 41 : mxConfigurationController->addConfigurationChangeListener(
73 : this,
74 : FrameworkHelper::msResourceActivationEvent,
75 41 : makeAny(ResourceActivationEvent));
76 : }
77 41 : }
78 41 : }
79 :
80 82 : ViewTabBarModule::~ViewTabBarModule()
81 : {
82 82 : }
83 :
84 82 : void SAL_CALL ViewTabBarModule::disposing()
85 : {
86 82 : if (mxConfigurationController.is())
87 0 : mxConfigurationController->removeConfigurationChangeListener(this);
88 :
89 82 : mxConfigurationController = NULL;
90 82 : }
91 :
92 789 : void SAL_CALL ViewTabBarModule::notifyConfigurationChange (
93 : const ConfigurationChangeEvent& rEvent)
94 : throw (RuntimeException, std::exception)
95 : {
96 789 : if (mxConfigurationController.is())
97 : {
98 789 : sal_Int32 nEventType = 0;
99 789 : rEvent.UserData >>= nEventType;
100 789 : switch (nEventType)
101 : {
102 : case ResourceActivationRequestEvent:
103 295 : if (mxViewTabBarId->isBoundTo(rEvent.ResourceId, AnchorBindingMode_DIRECT))
104 : {
105 41 : mxConfigurationController->requestResourceActivation(
106 : mxViewTabBarId,
107 41 : ResourceActivationMode_ADD);
108 : }
109 295 : break;
110 :
111 : case ResourceDeactivationRequestEvent:
112 295 : if (mxViewTabBarId->isBoundTo(rEvent.ResourceId, AnchorBindingMode_DIRECT))
113 : {
114 41 : mxConfigurationController->requestResourceDeactivation(mxViewTabBarId);
115 : }
116 295 : break;
117 :
118 : case ResourceActivationEvent:
119 199 : if (rEvent.ResourceId->compareTo(mxViewTabBarId) == 0)
120 : {
121 41 : UpdateViewTabBar(Reference<XTabBar>(rEvent.ResourceObject,UNO_QUERY));
122 : }
123 : }
124 : }
125 789 : }
126 :
127 82 : void SAL_CALL ViewTabBarModule::disposing (
128 : const lang::EventObject& rEvent)
129 : throw (RuntimeException, std::exception)
130 : {
131 164 : if (mxConfigurationController.is()
132 82 : && rEvent.Source == mxConfigurationController)
133 : {
134 : // Without the configuration controller this class can do nothing.
135 41 : mxConfigurationController = NULL;
136 41 : disposing();
137 : }
138 82 : }
139 :
140 82 : void ViewTabBarModule::UpdateViewTabBar (const Reference<XTabBar>& rxTabBar)
141 : {
142 82 : if (mxConfigurationController.is())
143 : {
144 82 : Reference<XTabBar> xBar (rxTabBar);
145 82 : if ( ! xBar.is())
146 82 : xBar = Reference<XTabBar>(
147 82 : mxConfigurationController->getResource(mxViewTabBarId), UNO_QUERY);
148 :
149 82 : if (xBar.is())
150 : {
151 41 : TabBarButton aEmptyButton;
152 :
153 82 : Reference<XResourceId> xAnchor (mxViewTabBarId->getAnchor());
154 :
155 82 : TabBarButton aImpressViewButton;
156 82 : aImpressViewButton.ResourceId = FrameworkHelper::CreateResourceId(
157 : FrameworkHelper::msImpressViewURL,
158 41 : xAnchor);
159 41 : aImpressViewButton.ButtonLabel = SD_RESSTR(STR_DRAW_MODE);
160 41 : if ( ! xBar->hasTabBarButton(aImpressViewButton))
161 41 : xBar->addTabBarButtonAfter(aImpressViewButton, aEmptyButton);
162 :
163 82 : TabBarButton aOutlineViewButton;
164 82 : aOutlineViewButton.ResourceId = FrameworkHelper::CreateResourceId(
165 : FrameworkHelper::msOutlineViewURL,
166 41 : xAnchor);
167 41 : aOutlineViewButton.ButtonLabel = SD_RESSTR(STR_OUTLINE_MODE);
168 41 : if ( ! xBar->hasTabBarButton(aOutlineViewButton))
169 41 : xBar->addTabBarButtonAfter(aOutlineViewButton, aImpressViewButton);
170 :
171 82 : TabBarButton aNotesViewButton;
172 82 : aNotesViewButton.ResourceId = FrameworkHelper::CreateResourceId(
173 : FrameworkHelper::msNotesViewURL,
174 41 : xAnchor);
175 41 : aNotesViewButton.ButtonLabel = SD_RESSTR(STR_NOTES_MODE);
176 41 : if ( ! xBar->hasTabBarButton(aNotesViewButton))
177 41 : xBar->addTabBarButtonAfter(aNotesViewButton, aOutlineViewButton);
178 :
179 82 : TabBarButton aHandoutViewButton;
180 82 : aHandoutViewButton.ResourceId = FrameworkHelper::CreateResourceId(
181 : FrameworkHelper::msHandoutViewURL,
182 41 : xAnchor);
183 41 : aHandoutViewButton.ButtonLabel = SD_RESSTR(STR_HANDOUT_MODE);
184 41 : if ( ! xBar->hasTabBarButton(aHandoutViewButton))
185 82 : xBar->addTabBarButtonAfter(aHandoutViewButton, aNotesViewButton);
186 82 : }
187 : }
188 82 : }
189 :
190 66 : } } // end of namespace sd::framework
191 :
192 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|