1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
*/
#include <sal/config.h>
#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
#include <sidebar/UnoDecks.hxx>
#include <sidebar/UnoDeck.hxx>
#include <sfx2/sidebar/ResourceManager.hxx>
#include <sfx2/sidebar/SidebarController.hxx>
#include <vcl/svapp.hxx>
#include <algorithm>
using namespace css;
using namespace ::sfx2::sidebar;
SfxUnoDecks::SfxUnoDecks(const uno::Reference<frame::XFrame>& rFrame):
xFrame(rFrame)
{
}
SidebarController* SfxUnoDecks::getSidebarController()
{
return SidebarController::GetSidebarControllerForFrame(xFrame);
}
// XNameAccess
uno::Any SAL_CALL SfxUnoDecks::getByName( const OUString& aName )
{
SolarMutexGuard aGuard;
if (!hasByName(aName))
throw container::NoSuchElementException();
uno::Reference<ui::XDeck> xDeck = new SfxUnoDeck(xFrame, aName);
return uno::Any(xDeck);
}
uno::Sequence< OUString > SAL_CALL SfxUnoDecks::getElementNames()
{
SolarMutexGuard aGuard;
SidebarController* pSidebarController = getSidebarController();
ResourceManager::DeckContextDescriptorContainer aDecks;
css::uno::Sequence< OUString > deckList(aDecks.size());
if (pSidebarController)
{
pSidebarController->GetResourceManager()->GetMatchingDecks (
aDecks,
pSidebarController->GetCurrentContext(),
pSidebarController->IsDocumentReadOnly(),
xFrame->getController());
deckList.realloc(aDecks.size());
std::transform(aDecks.begin(), aDecks.end(), deckList.getArray(),
[](const auto& rDeck) { return rDeck.msId; });
}
return deckList;
}
sal_Bool SAL_CALL SfxUnoDecks::hasByName( const OUString& aName )
{
SolarMutexGuard aGuard;
SidebarController* pSidebarController = getSidebarController();
bool bFound = false;
if (pSidebarController)
{
ResourceManager::DeckContextDescriptorContainer aDecks;
pSidebarController->GetResourceManager()->GetMatchingDecks (
aDecks,
pSidebarController->GetCurrentContext(),
pSidebarController->IsDocumentReadOnly(),
xFrame->getController());
bFound = std::any_of(aDecks.begin(), aDecks.end(),
[&aName](const ResourceManager::DeckContextDescriptor& rDeck) { return rDeck.msId == aName; });
}
return bFound;
}
// XIndexAccess
sal_Int32 SAL_CALL SfxUnoDecks::getCount()
{
SolarMutexGuard aGuard;
uno::Sequence< OUString > decks = getElementNames();
return decks.getLength();
}
uno::Any SAL_CALL SfxUnoDecks::getByIndex( sal_Int32 Index )
{
SolarMutexGuard aGuard;
uno::Any aRet;
uno::Sequence< OUString > decks = getElementNames();
if (Index > decks.getLength()-1 || Index < 0)
throw lang::IndexOutOfBoundsException();
uno::Reference<ui::XDeck> xDeck = new SfxUnoDeck(xFrame, decks[Index]);
aRet <<= xDeck;
return aRet;
}
// XElementAccess
uno::Type SAL_CALL SfxUnoDecks::getElementType()
{
return uno::Type();
}
sal_Bool SAL_CALL SfxUnoDecks::hasElements()
{
SolarMutexGuard aGuard;
uno::Sequence< OUString > decks = getElementNames();
return decks.hasElements();
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|