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 
20 #include <numberingtypelistbox.hxx>
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 
30 using namespace com::sun::star;
31 
33 {
34  uno::Reference<text::XNumberingTypeInfo> xInfo;
35 };
36 
37 SwNumberingTypeListBox::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(aTypes.begin(), aTypes.end(), nValue) != aTypes.end();
92  }
93  }
94  if (bInsert)
95  {
96  OUString sId(OUString::number(nValue));
97  m_xWidget->insert(nPos, SvxNumberingTypeTable::GetString(i), &sId, nullptr, nullptr);
98  }
99  }
100  if (!(nTypeFlags & SwInsertNumTypes::Extended))
101  return;
102 
103  for (sal_Int16 nCurrent : aTypes)
104  {
105  if (nCurrent > style::NumberingType::CHARS_LOWER_LETTER_N)
106  {
107  if (m_xWidget->find_id(OUString::number(nCurrent)) == -1)
108  {
109  m_xWidget->append(OUString::number(nCurrent),
110  m_xImpl->xInfo->getNumberingIdentifier(nCurrent));
111  }
112  }
113  }
114  m_xWidget->set_active(0);
115 }
116 
118 {
120  int nSelPos = m_xWidget->get_active();
121  if (nSelPos != -1)
122  nRet = static_cast<SvxNumType>(m_xWidget->get_id(nSelPos).toInt32());
123 #if OSL_DEBUG_LEVEL > 0
124  else
125  OSL_FAIL("NumberingTypeListBox not selected");
126 #endif
127  return nRet;
128 }
129 
131 {
132  int nPos = m_xWidget->find_id(OUString::number(nType));
133  m_xWidget->set_active(nPos);
134  return nPos != -1;
135 }
136 
137 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< SwNumberingTypeListBox_Impl > m_xImpl
SVX_NUM_CHARS_UPPER_LETTER
static int GetValue(sal_uInt32 i)
SvxNumType
static OUString GetString(sal_uInt32 i)
uno::Reference< text::XNumberingTypeInfo > xInfo
void Reload(SwInsertNumTypes nTypeFlags)
int i
static sal_uInt32 Count()
bool SelectNumberingType(SvxNumType nType)
const SvXMLTokenMapEntry aTypes[]
SwNumberingTypeListBox(std::unique_ptr< weld::ComboBox > pWidget)
#define LINK_TOKEN
Reference< XComponentContext > getProcessComponentContext()
OUString sId
std::unique_ptr< weld::ComboBox > m_xWidget
SvxNumType GetSelectedNumberingType() const
sal_uInt16 nPos
sal_Int16 nValue