LibreOffice Module sfx2 (master) 1
UnoDeck.cxx
Go to the documentation of this file.
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 */
10
11#include <sidebar/UnoDeck.hxx>
12
13#include <sidebar/UnoPanels.hxx>
14
18#include <sfx2/sidebar/Deck.hxx>
20
21#include <utility>
22#include <vcl/svapp.hxx>
23
24using namespace css;
25using namespace ::sfx2::sidebar;
26
27SfxUnoDeck::SfxUnoDeck(uno::Reference<frame::XFrame> _xFrame, OUString deckId):
28xFrame(std::move(_xFrame)),
29mDeckId(std::move(deckId))
30{
31
32}
34{
35 return SidebarController::GetSidebarControllerForFrame(xFrame);
36}
37
38OUString SAL_CALL SfxUnoDeck::getId()
39{
40 SolarMutexGuard aGuard;
41
42 return mDeckId;
43}
44
45OUString SAL_CALL SfxUnoDeck::getTitle()
46{
47 SolarMutexGuard aGuard;
48
49 SidebarController* pSidebarController = getSidebarController();
50 VclPtr<Deck> pDeck = pSidebarController->GetResourceManager()->GetDeckDescriptor(mDeckId)->mpDeck;
51
52 if (!pDeck)
53 {
54 pSidebarController->CreateDeck(mDeckId);
55 pDeck = pSidebarController->GetResourceManager()->GetDeckDescriptor(mDeckId)->mpDeck;
56 }
57
58 DeckTitleBar* pTitleBar = pDeck->GetTitleBar();
59 return pTitleBar->GetTitle();
60}
61
62void SAL_CALL SfxUnoDeck::setTitle( const OUString& newTitle )
63{
64 SolarMutexGuard aGuard;
65
66 SidebarController* pSidebarController = getSidebarController();
67 pSidebarController->CreateDeck(mDeckId);
68
69 std::shared_ptr<DeckDescriptor> xDeckDescriptor = pSidebarController->GetResourceManager()->GetDeckDescriptor(mDeckId);
70
71 if (xDeckDescriptor)
72 {
73 Deck* pDeck = xDeckDescriptor->mpDeck;
74 DeckTitleBar* pTitleBar = pDeck->GetTitleBar();
75 pTitleBar->SetTitle(newTitle);
76
77 xDeckDescriptor->msTitle = newTitle;
78 xDeckDescriptor->msHelpText = newTitle;
79
80 pSidebarController->notifyDeckTitle(mDeckId);
81 }
82}
83
85{
86 SolarMutexGuard aGuard;
87
88 SidebarController* pSidebarController = getSidebarController();
89 return pSidebarController->IsDeckVisible(mDeckId);
90}
91
92
93void SAL_CALL SfxUnoDeck::activate( const sal_Bool bActivate )
94{
95 SolarMutexGuard aGuard;
96
97 SidebarController* pSidebarController = getSidebarController();
98
99 // tdf#138160: OpenThenToggleDeck takes care of minimal width
100 if (bActivate)
101 pSidebarController->OpenThenToggleDeck(mDeckId);
102 else
103 {
104 pSidebarController->SwitchToDefaultDeck();
105 // update the sidebar
106 pSidebarController->NotifyResize();
107 }
108
109}
110
111uno::Reference<ui::XPanels> SAL_CALL SfxUnoDeck::getPanels()
112{
113 SolarMutexGuard aGuard;
114
115 uno::Reference<ui::XPanels> panels = new SfxUnoPanels(xFrame, mDeckId);
116 return panels;
117}
118
119sal_Int32 SAL_CALL SfxUnoDeck::getOrderIndex()
120{
121 SolarMutexGuard aGuard;
122 SidebarController* pSidebarController = getSidebarController();
123
124 sal_Int32 index = pSidebarController->GetResourceManager()->GetDeckDescriptor(mDeckId)->mnOrderIndex;
125 return index;
126}
127
128void SAL_CALL SfxUnoDeck::setOrderIndex( const sal_Int32 newOrderIndex )
129{
130 SolarMutexGuard aGuard;
131 SidebarController* pSidebarController = getSidebarController();
132
133 std::shared_ptr<DeckDescriptor> xDeckDescriptor = pSidebarController->GetResourceManager()->GetDeckDescriptor(mDeckId);
134
135 if (xDeckDescriptor)
136 {
137 xDeckDescriptor->mnOrderIndex = newOrderIndex;
138 // update the sidebar
139 pSidebarController->NotifyResize();
140 }
141}
142
144{
145 SolarMutexGuard aGuard;
146 SidebarController* pSidebarController = getSidebarController();
147
148 ResourceManager::DeckContextDescriptorContainer aDecks = pSidebarController->GetMatchingDecks();
149
150 sal_Int32 minIndex = GetMinOrderIndex(aDecks);
151 sal_Int32 curOrderIndex = getOrderIndex();
152
153 if (curOrderIndex != minIndex) // is deck already in place ?
154 {
155 minIndex -= 1;
156 std::shared_ptr<DeckDescriptor> xDeckDescriptor = pSidebarController->GetResourceManager()->GetDeckDescriptor(mDeckId);
157 if (xDeckDescriptor)
158 {
159 xDeckDescriptor->mnOrderIndex = minIndex;
160 // update the sidebar
161 pSidebarController->NotifyResize();
162 }
163 }
164}
165
166void SAL_CALL SfxUnoDeck::moveLast()
167{
168 SolarMutexGuard aGuard;
169 SidebarController* pSidebarController = getSidebarController();
170
171 ResourceManager::DeckContextDescriptorContainer aDecks = pSidebarController->GetMatchingDecks();
172
173 sal_Int32 maxIndex = GetMaxOrderIndex(aDecks);
174 sal_Int32 curOrderIndex = getOrderIndex();
175
176 if (curOrderIndex != maxIndex) // is deck already in place ?
177 {
178 maxIndex += 1;
179 std::shared_ptr<DeckDescriptor> xDeckDescriptor = pSidebarController->GetResourceManager()->GetDeckDescriptor(mDeckId);
180 if (xDeckDescriptor)
181 {
182 xDeckDescriptor->mnOrderIndex = maxIndex;
183 // update the sidebar
184 pSidebarController->NotifyResize();
185 }
186 }
187}
188
189void SAL_CALL SfxUnoDeck::moveUp()
190{
191 SolarMutexGuard aGuard;
192 SidebarController* pSidebarController = getSidebarController();
193
194 // Search for previous deck OrderIndex
195 ResourceManager::DeckContextDescriptorContainer aDecks = pSidebarController->GetMatchingDecks();
196
197 sal_Int32 curOrderIndex = getOrderIndex();
198 sal_Int32 previousIndex = GetMinOrderIndex(aDecks);
199
200 for (auto const& deck : aDecks)
201 {
202 sal_Int32 index = pSidebarController->GetResourceManager()->GetDeckDescriptor(deck.msId)->mnOrderIndex;
203 if( index < curOrderIndex && index > previousIndex)
204 previousIndex = index;
205 }
206
207 if (curOrderIndex != previousIndex) // is deck already in place ?
208 {
209 previousIndex -= 1;
210 std::shared_ptr<DeckDescriptor> xDeckDescriptor = pSidebarController->GetResourceManager()->GetDeckDescriptor(mDeckId);
211 if (xDeckDescriptor)
212 {
213 xDeckDescriptor->mnOrderIndex = previousIndex;
214 // update the sidebar
215 pSidebarController->NotifyResize();
216 }
217 }
218}
219
220void SAL_CALL SfxUnoDeck::moveDown()
221{
222 SolarMutexGuard aGuard;
223 SidebarController* pSidebarController = getSidebarController();
224
225 ResourceManager::DeckContextDescriptorContainer aDecks = pSidebarController->GetMatchingDecks();
226
227 // Search for next deck OrderIndex
228 sal_Int32 curOrderIndex = getOrderIndex();
229 sal_Int32 nextIndex = GetMaxOrderIndex(aDecks);
230
231 for (auto const& deck : aDecks)
232 {
233 sal_Int32 index = pSidebarController->GetResourceManager()->GetDeckDescriptor(deck.msId)->mnOrderIndex;
234 if( index > curOrderIndex && index < nextIndex)
235 nextIndex = index;
236 }
237
238 if (curOrderIndex != nextIndex) // is deck already in place ?
239 {
240 nextIndex += 1;
241 std::shared_ptr<DeckDescriptor> xDeckDescriptor = pSidebarController->GetResourceManager()->GetDeckDescriptor(mDeckId);
242 if (xDeckDescriptor)
243 {
244 xDeckDescriptor->mnOrderIndex = nextIndex;
245 // update the sidebar
246 pSidebarController->NotifyResize();
247 }
248 }
249}
250
251sal_Int32 SfxUnoDeck::GetMinOrderIndex(const ResourceManager::DeckContextDescriptorContainer& rDecks)
252{
253 SidebarController* pSidebarController = getSidebarController();
254
255 ResourceManager::DeckContextDescriptorContainer::const_iterator iDeck = rDecks.begin();
256 sal_Int32 minIndex = pSidebarController->GetResourceManager()->GetDeckDescriptor(iDeck->msId)->mnOrderIndex;
257
258 for (auto const& deck : rDecks)
259 {
260 sal_Int32 index = pSidebarController->GetResourceManager()->GetDeckDescriptor(deck.msId)->mnOrderIndex;
261 if(minIndex > index)
262 minIndex = index;
263 }
264 return minIndex;
265}
266
267sal_Int32 SfxUnoDeck::GetMaxOrderIndex(const ResourceManager::DeckContextDescriptorContainer& rDecks)
268{
269 SidebarController* pSidebarController = getSidebarController();
270
271 sal_Int32 maxIndex = pSidebarController->GetResourceManager()->GetDeckDescriptor(rDecks.begin()->msId)->mnOrderIndex;
272
273 for (auto const& deck : rDecks)
274 {
275 sal_Int32 index = pSidebarController->GetResourceManager()->GetDeckDescriptor(deck.msId)->mnOrderIndex;
276 if(maxIndex < index)
277 maxIndex = index;
278 }
279 return maxIndex;
280}
281
282/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 GetMaxOrderIndex(const sfx2::sidebar::ResourceManager::DeckContextDescriptorContainer &rDecks)
Definition: UnoDeck.cxx:267
virtual void SAL_CALL moveLast() override
Definition: UnoDeck.cxx:166
virtual void SAL_CALL moveDown() override
Definition: UnoDeck.cxx:220
const OUString mDeckId
Definition: UnoDeck.hxx:55
virtual void SAL_CALL activate(const sal_Bool bActivate) override
Definition: UnoDeck.cxx:93
SfxUnoDeck(css::uno::Reference< css::frame::XFrame >, OUString)
Definition: UnoDeck.cxx:27
virtual sal_Int32 SAL_CALL getOrderIndex() override
Definition: UnoDeck.cxx:119
virtual css::uno::Reference< css::ui::XPanels > SAL_CALL getPanels() override
Definition: UnoDeck.cxx:111
virtual OUString SAL_CALL getTitle() override
Definition: UnoDeck.cxx:45
virtual void SAL_CALL setTitle(const OUString &newTitle) override
Definition: UnoDeck.cxx:62
virtual sal_Bool SAL_CALL isActive() override
Definition: UnoDeck.cxx:84
const css::uno::Reference< css::frame::XFrame > xFrame
Definition: UnoDeck.hxx:52
sfx2::sidebar::SidebarController * getSidebarController()
Definition: UnoDeck.cxx:33
virtual void SAL_CALL moveUp() override
Definition: UnoDeck.cxx:189
sal_Int32 GetMinOrderIndex(const sfx2::sidebar::ResourceManager::DeckContextDescriptorContainer &rDecks)
Definition: UnoDeck.cxx:251
virtual void SAL_CALL moveFirst() override
Definition: UnoDeck.cxx:143
virtual OUString SAL_CALL getId() override
Definition: UnoDeck.cxx:38
virtual void SAL_CALL setOrderIndex(const sal_Int32 newOrderIndex) override
Definition: UnoDeck.cxx:128
get the decks
Definition: UnoPanels.hxx:22
index
Reference< XFrame > xFrame
unsigned char sal_Bool