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 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
);
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();
99 pSidebarController
->SwitchToDeck(mDeckId
);
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
);
115 sal_Int32 SAL_CALL
SfxUnoDeck::getOrderIndex()
117 SolarMutexGuard aGuard
;
118 SidebarController
* pSidebarController
= getSidebarController();
120 sal_Int32 index
= pSidebarController
->GetResourceManager()->GetDeckDescriptor(mDeckId
)->mnOrderIndex
;
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
);
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 ?
152 std::shared_ptr
<DeckDescriptor
> xDeckDescriptor
= pSidebarController
->GetResourceManager()->GetDeckDescriptor(mDeckId
);
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 ?
175 std::shared_ptr
<DeckDescriptor
> xDeckDescriptor
= pSidebarController
->GetResourceManager()->GetDeckDescriptor(mDeckId
);
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 ?
206 std::shared_ptr
<DeckDescriptor
> xDeckDescriptor
= pSidebarController
->GetResourceManager()->GetDeckDescriptor(mDeckId
);
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
)
234 if (curOrderIndex
!= nextIndex
) // is deck already in place ?
237 std::shared_ptr
<DeckDescriptor
> xDeckDescriptor
= pSidebarController
->GetResourceManager()->GetDeckDescriptor(mDeckId
);
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
;
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
;
278 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */