1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
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>
24 using namespace ::sfx2::sidebar
;
26 SfxUnoDeck::SfxUnoDeck(const uno::Reference
<frame::XFrame
>& rFrame
, const OUString
& deckId
):
32 SidebarController
* SfxUnoDeck::getSidebarController()
34 return SidebarController::GetSidebarControllerForFrame(xFrame
);
37 OUString SAL_CALL
SfxUnoDeck::getId()
39 SolarMutexGuard aGuard
;
44 OUString SAL_CALL
SfxUnoDeck::getTitle()
46 SolarMutexGuard aGuard
;
48 SidebarController
* pSidebarController
= getSidebarController();
49 VclPtr
<Deck
> pDeck
= pSidebarController
->GetResourceManager()->GetDeckDescriptor(mDeckId
)->mpDeck
;
53 pSidebarController
->CreateDeck(mDeckId
);
54 pDeck
= pSidebarController
->GetResourceManager()->GetDeckDescriptor(mDeckId
)->mpDeck
;
57 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
);
72 Deck
* pDeck
= xDeckDescriptor
->mpDeck
;
73 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 // tdf#138160: OpenThenToggleDeck takes care of minimal width
100 pSidebarController
->OpenThenToggleDeck(mDeckId
);
103 pSidebarController
->SwitchToDefaultDeck();
104 // update the sidebar
105 pSidebarController
->NotifyResize();
110 uno::Reference
<ui::XPanels
> SAL_CALL
SfxUnoDeck::getPanels()
112 SolarMutexGuard aGuard
;
114 uno::Reference
<ui::XPanels
> panels
= new SfxUnoPanels(xFrame
, mDeckId
);
118 sal_Int32 SAL_CALL
SfxUnoDeck::getOrderIndex()
120 SolarMutexGuard aGuard
;
121 SidebarController
* pSidebarController
= getSidebarController();
123 sal_Int32 index
= pSidebarController
->GetResourceManager()->GetDeckDescriptor(mDeckId
)->mnOrderIndex
;
127 void SAL_CALL
SfxUnoDeck::setOrderIndex( const sal_Int32 newOrderIndex
)
129 SolarMutexGuard aGuard
;
130 SidebarController
* pSidebarController
= getSidebarController();
132 std::shared_ptr
<DeckDescriptor
> xDeckDescriptor
= pSidebarController
->GetResourceManager()->GetDeckDescriptor(mDeckId
);
136 xDeckDescriptor
->mnOrderIndex
= newOrderIndex
;
137 // update the sidebar
138 pSidebarController
->NotifyResize();
142 void SAL_CALL
SfxUnoDeck::moveFirst()
144 SolarMutexGuard aGuard
;
145 SidebarController
* pSidebarController
= getSidebarController();
147 ResourceManager::DeckContextDescriptorContainer aDecks
= pSidebarController
->GetMatchingDecks();
149 sal_Int32 minIndex
= GetMinOrderIndex(aDecks
);
150 sal_Int32 curOrderIndex
= getOrderIndex();
152 if (curOrderIndex
!= minIndex
) // is deck already in place ?
155 std::shared_ptr
<DeckDescriptor
> xDeckDescriptor
= pSidebarController
->GetResourceManager()->GetDeckDescriptor(mDeckId
);
158 xDeckDescriptor
->mnOrderIndex
= minIndex
;
159 // update the sidebar
160 pSidebarController
->NotifyResize();
165 void SAL_CALL
SfxUnoDeck::moveLast()
167 SolarMutexGuard aGuard
;
168 SidebarController
* pSidebarController
= getSidebarController();
170 ResourceManager::DeckContextDescriptorContainer aDecks
= pSidebarController
->GetMatchingDecks();
172 sal_Int32 maxIndex
= GetMaxOrderIndex(aDecks
);
173 sal_Int32 curOrderIndex
= getOrderIndex();
175 if (curOrderIndex
!= maxIndex
) // is deck already in place ?
178 std::shared_ptr
<DeckDescriptor
> xDeckDescriptor
= pSidebarController
->GetResourceManager()->GetDeckDescriptor(mDeckId
);
181 xDeckDescriptor
->mnOrderIndex
= maxIndex
;
182 // update the sidebar
183 pSidebarController
->NotifyResize();
188 void SAL_CALL
SfxUnoDeck::moveUp()
190 SolarMutexGuard aGuard
;
191 SidebarController
* pSidebarController
= getSidebarController();
193 // Search for previous deck OrderIndex
194 ResourceManager::DeckContextDescriptorContainer aDecks
= pSidebarController
->GetMatchingDecks();
196 sal_Int32 curOrderIndex
= getOrderIndex();
197 sal_Int32 previousIndex
= GetMinOrderIndex(aDecks
);
199 for (auto const& deck
: aDecks
)
201 sal_Int32 index
= pSidebarController
->GetResourceManager()->GetDeckDescriptor(deck
.msId
)->mnOrderIndex
;
202 if( index
< curOrderIndex
&& index
> previousIndex
)
203 previousIndex
= index
;
206 if (curOrderIndex
!= previousIndex
) // is deck already in place ?
209 std::shared_ptr
<DeckDescriptor
> xDeckDescriptor
= pSidebarController
->GetResourceManager()->GetDeckDescriptor(mDeckId
);
212 xDeckDescriptor
->mnOrderIndex
= previousIndex
;
213 // update the sidebar
214 pSidebarController
->NotifyResize();
219 void SAL_CALL
SfxUnoDeck::moveDown()
221 SolarMutexGuard aGuard
;
222 SidebarController
* pSidebarController
= getSidebarController();
224 ResourceManager::DeckContextDescriptorContainer aDecks
= pSidebarController
->GetMatchingDecks();
226 // Search for next deck OrderIndex
227 sal_Int32 curOrderIndex
= getOrderIndex();
228 sal_Int32 nextIndex
= GetMaxOrderIndex(aDecks
);
230 for (auto const& deck
: aDecks
)
232 sal_Int32 index
= pSidebarController
->GetResourceManager()->GetDeckDescriptor(deck
.msId
)->mnOrderIndex
;
233 if( index
> curOrderIndex
&& index
< nextIndex
)
237 if (curOrderIndex
!= nextIndex
) // is deck already in place ?
240 std::shared_ptr
<DeckDescriptor
> xDeckDescriptor
= pSidebarController
->GetResourceManager()->GetDeckDescriptor(mDeckId
);
243 xDeckDescriptor
->mnOrderIndex
= nextIndex
;
244 // update the sidebar
245 pSidebarController
->NotifyResize();
250 sal_Int32
SfxUnoDeck::GetMinOrderIndex(ResourceManager::DeckContextDescriptorContainer aDecks
)
252 SidebarController
* pSidebarController
= getSidebarController();
254 ResourceManager::DeckContextDescriptorContainer::const_iterator iDeck
= aDecks
.begin();
255 sal_Int32 minIndex
= pSidebarController
->GetResourceManager()->GetDeckDescriptor(iDeck
->msId
)->mnOrderIndex
;
257 for (auto const& deck
: aDecks
)
259 sal_Int32 index
= pSidebarController
->GetResourceManager()->GetDeckDescriptor(deck
.msId
)->mnOrderIndex
;
266 sal_Int32
SfxUnoDeck::GetMaxOrderIndex(ResourceManager::DeckContextDescriptorContainer aDecks
)
268 SidebarController
* pSidebarController
= getSidebarController();
270 sal_Int32 maxIndex
= pSidebarController
->GetResourceManager()->GetDeckDescriptor(aDecks
.begin()->msId
)->mnOrderIndex
;
272 for (auto const& deck
: aDecks
)
274 sal_Int32 index
= pSidebarController
->GetResourceManager()->GetDeckDescriptor(deck
.msId
)->mnOrderIndex
;
281 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */