Version 7.1.7.1, tag libreoffice-7.1.7.1
[LibreOffice.git] / sfx2 / source / sidebar / UnoDeck.cxx
blob122afbe018a226783077787acbdf71b4c772b675
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 */
11 #include <sidebar/UnoDeck.hxx>
13 #include <sidebar/UnoPanels.hxx>
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>
21 #include <vcl/svapp.hxx>
23 using namespace css;
24 using namespace ::sfx2::sidebar;
26 SfxUnoDeck::SfxUnoDeck(const uno::Reference<frame::XFrame>& rFrame, const OUString& deckId):
27 xFrame(rFrame),
28 mDeckId(deckId)
32 SidebarController* SfxUnoDeck::getSidebarController()
34 return SidebarController::GetSidebarControllerForFrame(xFrame);
37 OUString SAL_CALL SfxUnoDeck::getId()
39 SolarMutexGuard aGuard;
41 return mDeckId;
44 OUString SAL_CALL SfxUnoDeck::getTitle()
46 SolarMutexGuard aGuard;
48 SidebarController* pSidebarController = getSidebarController();
49 VclPtr<Deck> pDeck = pSidebarController->GetResourceManager()->GetDeckDescriptor(mDeckId)->mpDeck;
51 if (!pDeck)
53 pSidebarController->CreateDeck(mDeckId);
54 pDeck = pSidebarController->GetResourceManager()->GetDeckDescriptor(mDeckId)->mpDeck;
57 VclPtr<DeckTitleBar> pTitleBar = pDeck->GetTitleBar();
58 return pTitleBar->GetTitle();
61 void SAL_CALL SfxUnoDeck::setTitle( const OUString& newTitle )
63 SolarMutexGuard aGuard;
65 SidebarController* pSidebarController = getSidebarController();
66 pSidebarController->CreateDeck(mDeckId);
68 std::shared_ptr<DeckDescriptor> xDeckDescriptor = pSidebarController->GetResourceManager()->GetDeckDescriptor(mDeckId);
70 if (xDeckDescriptor)
72 Deck* pDeck = xDeckDescriptor->mpDeck;
73 const VclPtr<DeckTitleBar>& pTitleBar = pDeck->GetTitleBar();
74 pTitleBar->SetTitle(newTitle);
76 xDeckDescriptor->msTitle = newTitle;
77 xDeckDescriptor->msHelpText = newTitle;
79 pSidebarController->notifyDeckTitle(mDeckId);
83 sal_Bool SAL_CALL SfxUnoDeck::isActive()
85 SolarMutexGuard aGuard;
87 SidebarController* pSidebarController = getSidebarController();
88 return pSidebarController->IsDeckVisible(mDeckId);
92 void SAL_CALL SfxUnoDeck::activate( const sal_Bool bActivate )
94 SolarMutexGuard aGuard;
96 SidebarController* pSidebarController = getSidebarController();
98 if (bActivate)
99 pSidebarController->SwitchToDeck(mDeckId);
100 else
101 pSidebarController->SwitchToDefaultDeck();
103 // update the sidebar
104 pSidebarController->NotifyResize();
107 uno::Reference<ui::XPanels> SAL_CALL SfxUnoDeck::getPanels()
109 SolarMutexGuard aGuard;
111 uno::Reference<ui::XPanels> panels = new SfxUnoPanels(xFrame, mDeckId);
112 return panels;
115 sal_Int32 SAL_CALL SfxUnoDeck::getOrderIndex()
117 SolarMutexGuard aGuard;
118 SidebarController* pSidebarController = getSidebarController();
120 sal_Int32 index = pSidebarController->GetResourceManager()->GetDeckDescriptor(mDeckId)->mnOrderIndex;
121 return index;
124 void SAL_CALL SfxUnoDeck::setOrderIndex( const sal_Int32 newOrderIndex )
126 SolarMutexGuard aGuard;
127 SidebarController* pSidebarController = getSidebarController();
129 std::shared_ptr<DeckDescriptor> xDeckDescriptor = pSidebarController->GetResourceManager()->GetDeckDescriptor(mDeckId);
131 if (xDeckDescriptor)
133 xDeckDescriptor->mnOrderIndex = newOrderIndex;
134 // update the sidebar
135 pSidebarController->NotifyResize();
139 void SAL_CALL SfxUnoDeck::moveFirst()
141 SolarMutexGuard aGuard;
142 SidebarController* pSidebarController = getSidebarController();
144 ResourceManager::DeckContextDescriptorContainer aDecks = pSidebarController->GetMatchingDecks();
146 sal_Int32 minIndex = GetMinOrderIndex(aDecks);
147 sal_Int32 curOrderIndex = getOrderIndex();
149 if (curOrderIndex != minIndex) // is deck already in place ?
151 minIndex -= 1;
152 std::shared_ptr<DeckDescriptor> xDeckDescriptor = pSidebarController->GetResourceManager()->GetDeckDescriptor(mDeckId);
153 if (xDeckDescriptor)
155 xDeckDescriptor->mnOrderIndex = minIndex;
156 // update the sidebar
157 pSidebarController->NotifyResize();
162 void SAL_CALL SfxUnoDeck::moveLast()
164 SolarMutexGuard aGuard;
165 SidebarController* pSidebarController = getSidebarController();
167 ResourceManager::DeckContextDescriptorContainer aDecks = pSidebarController->GetMatchingDecks();
169 sal_Int32 maxIndex = GetMaxOrderIndex(aDecks);
170 sal_Int32 curOrderIndex = getOrderIndex();
172 if (curOrderIndex != maxIndex) // is deck already in place ?
174 maxIndex += 1;
175 std::shared_ptr<DeckDescriptor> xDeckDescriptor = pSidebarController->GetResourceManager()->GetDeckDescriptor(mDeckId);
176 if (xDeckDescriptor)
178 xDeckDescriptor->mnOrderIndex = maxIndex;
179 // update the sidebar
180 pSidebarController->NotifyResize();
185 void SAL_CALL SfxUnoDeck::moveUp()
187 SolarMutexGuard aGuard;
188 SidebarController* pSidebarController = getSidebarController();
190 // Search for previous deck OrderIndex
191 ResourceManager::DeckContextDescriptorContainer aDecks = pSidebarController->GetMatchingDecks();
193 sal_Int32 curOrderIndex = getOrderIndex();
194 sal_Int32 previousIndex = GetMinOrderIndex(aDecks);
196 for (auto const& deck : aDecks)
198 sal_Int32 index = pSidebarController->GetResourceManager()->GetDeckDescriptor(deck.msId)->mnOrderIndex;
199 if( index < curOrderIndex && index > previousIndex)
200 previousIndex = index;
203 if (curOrderIndex != previousIndex) // is deck already in place ?
205 previousIndex -= 1;
206 std::shared_ptr<DeckDescriptor> xDeckDescriptor = pSidebarController->GetResourceManager()->GetDeckDescriptor(mDeckId);
207 if (xDeckDescriptor)
209 xDeckDescriptor->mnOrderIndex = previousIndex;
210 // update the sidebar
211 pSidebarController->NotifyResize();
216 void SAL_CALL SfxUnoDeck::moveDown()
218 SolarMutexGuard aGuard;
219 SidebarController* pSidebarController = getSidebarController();
221 ResourceManager::DeckContextDescriptorContainer aDecks = pSidebarController->GetMatchingDecks();
223 // Search for next deck OrderIndex
224 sal_Int32 curOrderIndex = getOrderIndex();
225 sal_Int32 nextIndex = GetMaxOrderIndex(aDecks);
227 for (auto const& deck : aDecks)
229 sal_Int32 index = pSidebarController->GetResourceManager()->GetDeckDescriptor(deck.msId)->mnOrderIndex;
230 if( index > curOrderIndex && index < nextIndex)
231 nextIndex = index;
234 if (curOrderIndex != nextIndex) // is deck already in place ?
236 nextIndex += 1;
237 std::shared_ptr<DeckDescriptor> xDeckDescriptor = pSidebarController->GetResourceManager()->GetDeckDescriptor(mDeckId);
238 if (xDeckDescriptor)
240 xDeckDescriptor->mnOrderIndex = nextIndex;
241 // update the sidebar
242 pSidebarController->NotifyResize();
247 sal_Int32 SfxUnoDeck::GetMinOrderIndex(ResourceManager::DeckContextDescriptorContainer aDecks)
249 SidebarController* pSidebarController = getSidebarController();
251 ResourceManager::DeckContextDescriptorContainer::const_iterator iDeck = aDecks.begin();
252 sal_Int32 minIndex = pSidebarController->GetResourceManager()->GetDeckDescriptor(iDeck->msId)->mnOrderIndex;
254 for (auto const& deck : aDecks)
256 sal_Int32 index = pSidebarController->GetResourceManager()->GetDeckDescriptor(deck.msId)->mnOrderIndex;
257 if(minIndex > index)
258 minIndex = index;
260 return minIndex;
263 sal_Int32 SfxUnoDeck::GetMaxOrderIndex(ResourceManager::DeckContextDescriptorContainer aDecks)
265 SidebarController* pSidebarController = getSidebarController();
267 sal_Int32 maxIndex = pSidebarController->GetResourceManager()->GetDeckDescriptor(aDecks.begin()->msId)->mnOrderIndex;
269 for (auto const& deck : aDecks)
271 sal_Int32 index = pSidebarController->GetResourceManager()->GetDeckDescriptor(deck.msId)->mnOrderIndex;
272 if(maxIndex < index)
273 maxIndex = index;
275 return maxIndex;
278 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */