LibreOffice Module sw (master) 1
numberingtypelistbox.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
21#include <com/sun/star/style/NumberingType.hpp>
22#include <com/sun/star/text/DefaultNumberingProvider.hpp>
23#include <com/sun/star/text/XDefaultNumberingProvider.hpp>
25#include <com/sun/star/text/XNumberingTypeInfo.hpp>
26#include <editeng/numitem.hxx>
27#include <svx/strarray.hxx>
28#include <osl/diagnose.h>
29
30using namespace com::sun::star;
31
33{
34 uno::Reference<text::XNumberingTypeInfo> xInfo;
35};
36
37SwNumberingTypeListBox::SwNumberingTypeListBox(std::unique_ptr<weld::ComboBox> pWidget)
38 : m_xWidget(std::move(pWidget))
39 , m_xImpl(new SwNumberingTypeListBox_Impl)
40{
41 uno::Reference<uno::XComponentContext> xContext(::comphelper::getProcessComponentContext());
42 uno::Reference<text::XDefaultNumberingProvider> xDefNum
43 = text::DefaultNumberingProvider::create(xContext);
44 m_xImpl->xInfo.set(xDefNum, uno::UNO_QUERY);
45}
46
48
50{
51 m_xWidget->clear();
52 uno::Sequence<sal_Int16> aTypes;
53 if (nTypeFlags & SwInsertNumTypes::Extended)
54 {
55 if (m_xImpl->xInfo.is())
56 aTypes = m_xImpl->xInfo->getSupportedNumberingTypes();
57 }
58
59 for (size_t i = 0; i < SvxNumberingTypeTable::Count(); i++)
60 {
62 bool bInsert = true;
63 int nPos = -1;
64 switch (nValue)
65 {
66 case style::NumberingType::NUMBER_NONE:
67 bInsert = bool(nTypeFlags & SwInsertNumTypes::NoNumbering);
68 nPos = 0;
69
70 break;
71 case style::NumberingType::CHAR_SPECIAL:
72 bInsert = false;
73
74 break;
75 case style::NumberingType::PAGE_DESCRIPTOR:
76 bInsert = false;
77
78 break;
79 case style::NumberingType::BITMAP:
80 bInsert = false;
81
82 break;
83 case style::NumberingType::BITMAP | LINK_TOKEN:
84 bInsert = false;
85
86 break;
87 default:
88 if (nValue > style::NumberingType::CHARS_LOWER_LETTER_N)
89 {
90 // Insert only if offered by i18n framework per configuration.
91 bInsert = std::find(std::cbegin(aTypes), std::cend(aTypes), nValue)
92 != std::cend(aTypes);
93 }
94 }
95 if (bInsert)
96 {
97 OUString sId(OUString::number(nValue));
98 m_xWidget->insert(nPos, SvxNumberingTypeTable::GetString(i), &sId, nullptr, nullptr);
99 }
100 }
101 if (!(nTypeFlags & SwInsertNumTypes::Extended))
102 return;
103
104 for (sal_Int16 nCurrent : std::as_const(aTypes))
105 {
106 if (nCurrent > style::NumberingType::CHARS_LOWER_LETTER_N)
107 {
108 if (m_xWidget->find_id(OUString::number(nCurrent)) == -1)
109 {
110 m_xWidget->append(OUString::number(nCurrent),
111 m_xImpl->xInfo->getNumberingIdentifier(nCurrent));
112 }
113 }
114 }
115 m_xWidget->set_active(0);
116}
117
119{
121 int nSelPos = m_xWidget->get_active();
122 if (nSelPos != -1)
123 nRet = static_cast<SvxNumType>(m_xWidget->get_id(nSelPos).toInt32());
124#if OSL_DEBUG_LEVEL > 0
125 else
126 OSL_FAIL("NumberingTypeListBox not selected");
127#endif
128 return nRet;
129}
130
132{
133 int nPos = m_xWidget->find_id(OUString::number(nType));
134 m_xWidget->set_active(nPos);
135 return nPos != -1;
136}
137
138/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< weld::Image > m_xWidget
static int GetValue(sal_uInt32 i)
static sal_uInt32 Count()
static OUString GetString(sal_uInt32 i)
void Reload(SwInsertNumTypes nTypeFlags)
SvxNumType GetSelectedNumberingType() const
SwNumberingTypeListBox(std::unique_ptr< weld::ComboBox > pWidget)
std::unique_ptr< weld::ComboBox > m_xWidget
bool SelectNumberingType(SvxNumType nType)
std::unique_ptr< SwNumberingTypeListBox_Impl > m_xImpl
sal_Int16 nValue
sal_uInt16 nPos
int i
#define LINK_TOKEN
QPRO_FUNC_TYPE nType
uno::Reference< text::XNumberingTypeInfo > xInfo
SvxNumType
SVX_NUM_CHARS_UPPER_LETTER
OUString sId
const SvXMLTokenMapEntry aTypes[]