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
144
145
146
147
148
149
150
151
152
153
154
155
156
|
/* -*- 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 <cppuhelper/implbase.hxx>
#include <svtools/toolboxcontroller.hxx>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/uno/XComponentContext.hpp>
#include <com/sun/star/frame/XFrame.hpp>
#include <vcl/vclptr.hxx>
#include <vcl/lstbox.hxx>
#include <vcl/svapp.hxx>
#include <toolkit/helper/vclunohelper.hxx>
#include <vcl/toolbox.hxx>
#include <sfx2/viewfrm.hxx>
#include <sfx2/classificationhelper.hxx>
#include <cppuhelper/supportsservice.hxx>
#include <comphelper/propertysequence.hxx>
#include <comphelper/dispatchcommand.hxx>
using namespace com::sun::star;
namespace sfx2
{
using ClassificationCategoriesControllerBase = cppu::ImplInheritanceHelper<svt::ToolboxController, lang::XServiceInfo>;
/// Controller for .uno:ClassificationApply.
class ClassificationCategoriesController : public ClassificationCategoriesControllerBase
{
VclPtr<ListBox> m_pCategories;
DECL_LINK_TYPED(SelectHdl, ListBox&, void);
public:
ClassificationCategoriesController(const uno::Reference<uno::XComponentContext>& rContext);
virtual ~ClassificationCategoriesController();
// XServiceInfo
virtual OUString SAL_CALL getImplementationName() throw (uno::RuntimeException, std::exception) override;
virtual sal_Bool SAL_CALL supportsService(const OUString& rServiceName) throw (uno::RuntimeException, std::exception) override;
virtual uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() throw (uno::RuntimeException, std::exception) override;
// XComponent
virtual void SAL_CALL dispose() throw (uno::RuntimeException, std::exception) override;
// XToolbarController
virtual uno::Reference<awt::XWindow> SAL_CALL createItemWindow(const uno::Reference<awt::XWindow>& rParent) throw (uno::RuntimeException, std::exception) override;
// XStatusListener
virtual void SAL_CALL statusChanged(const frame::FeatureStateEvent& rEvent) throw (uno::RuntimeException, std::exception) override;
};
ClassificationCategoriesController::ClassificationCategoriesController(const uno::Reference<uno::XComponentContext>& rContext)
: ClassificationCategoriesControllerBase(rContext, uno::Reference<frame::XFrame>(), OUString(".uno:ClassificationApply"))
, m_pCategories(nullptr)
{
}
ClassificationCategoriesController::~ClassificationCategoriesController()
{
}
OUString ClassificationCategoriesController::getImplementationName() throw (uno::RuntimeException, std::exception)
{
return OUString("com.sun.star.comp.sfx2.ClassificationCategoriesController");
}
sal_Bool ClassificationCategoriesController::supportsService(const OUString& rServiceName) throw (uno::RuntimeException, std::exception)
{
return cppu::supportsService(this, rServiceName);
}
uno::Sequence<OUString> ClassificationCategoriesController::getSupportedServiceNames() throw (uno::RuntimeException, std::exception)
{
uno::Sequence<OUString> aServices
{
"com.sun.star.frame.ToolbarController"
};
return aServices;
}
void ClassificationCategoriesController::dispose() throw (uno::RuntimeException, std::exception)
{
SolarMutexGuard aSolarMutexGuard;
svt::ToolboxController::dispose();
m_pCategories.disposeAndClear();
}
uno::Reference<awt::XWindow> ClassificationCategoriesController::createItemWindow(const uno::Reference<awt::XWindow>& rParent) throw (uno::RuntimeException, std::exception)
{
vcl::Window* pParent = VCLUnoHelper::GetWindow(rParent);
ToolBox* pToolbar = dynamic_cast<ToolBox*>(pParent);
if (pToolbar)
{
m_pCategories = VclPtr<ListBox>::Create(pToolbar, WB_CLIPCHILDREN|WB_LEFT|WB_VCENTER|WB_3DLOOK|WB_DROPDOWN|WB_SIMPLEMODE);
m_pCategories->SetSelectHdl(LINK(this, ClassificationCategoriesController, SelectHdl));
// Same as SvxFontNameBox_Impl.
m_pCategories->SetSizePixel(m_pCategories->LogicToPixel(Size(60, 160), MAP_APPFONT));
}
return uno::Reference<awt::XWindow>(VCLUnoHelper::GetInterface(m_pCategories));
}
IMPL_LINK_NOARG_TYPED(ClassificationCategoriesController, SelectHdl, ListBox&, void)
{
OUString aEntry = m_pCategories->GetSelectEntry();
uno::Sequence<beans::PropertyValue> aPropertyValues(comphelper::InitPropertySequence(
{
{"Name", uno::makeAny(aEntry)},
}));
comphelper::dispatchCommand(".uno:ClassificationApply", aPropertyValues);
}
void ClassificationCategoriesController::statusChanged(const frame::FeatureStateEvent& /*rEvent*/) throw (uno::RuntimeException, std::exception)
{
if (!m_pCategories)
return;
SfxObjectShell* pObjectShell = SfxObjectShell::Current();
if (!pObjectShell)
return;
SfxClassificationHelper aHelper(*pObjectShell);
if (m_pCategories->GetEntryCount() == 0)
{
std::vector<OUString> aNames = aHelper.GetBACNames();
for (const OUString& rName : aNames)
m_pCategories->InsertEntry(rName);
// Normally VclBuilder::makeObject() does this.
m_pCategories->EnableAutoSize(true);
m_pCategories->SetSizePixel(m_pCategories->GetOptimalSize());
}
// Restore state based on the doc. model.
const OUString& rCategoryName = aHelper.GetBACName();
if (!rCategoryName.isEmpty())
m_pCategories->SelectEntry(rCategoryName);
}
} // namespace sfx2
extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface* SAL_CALL com_sun_star_sfx2_ClassificationCategoriesController_get_implementation(uno::XComponentContext* pContext, const uno::Sequence<uno::Any>&)
{
return cppu::acquire(new sfx2::ClassificationCategoriesController(pContext));
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|