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