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 = text::DefaultNumberingProvider::create(xContext);
43  m_xImpl->xInfo.set(xDefNum, uno::UNO_QUERY);
44 }
45 
47 {
48 }
49 
51 {
52  m_xWidget->clear();
53  uno::Sequence<sal_Int16> aTypes;
54  if (nTypeFlags & SwInsertNumTypes::Extended)
55  {
56  if (m_xImpl->xInfo.is())
57  aTypes = m_xImpl->xInfo->getSupportedNumberingTypes();
58  }
59 
60  for(size_t i = 0; i < SvxNumberingTypeTable::Count(); i++)
61  {
63  bool bInsert = true;
64  int nPos = -1;
65  switch(nValue)
66  {
67  case style::NumberingType::NUMBER_NONE:
68  bInsert = bool(nTypeFlags & SwInsertNumTypes::NoNumbering);
69  nPos = 0;
70 
71  break;
72  case style::NumberingType::CHAR_SPECIAL:
73  bInsert = false;
74 
75  break;
76  case style::NumberingType::PAGE_DESCRIPTOR:
77  bInsert = false;
78 
79  break;
80  case style::NumberingType::BITMAP:
81  bInsert = false;
82 
83  break;
84  case style::NumberingType::BITMAP | LINK_TOKEN:
85  bInsert = false;
86 
87  break;
88  default:
89  if (nValue > style::NumberingType::CHARS_LOWER_LETTER_N)
90  {
91  // Insert only if offered by i18n framework per configuration.
92  bInsert = std::find(aTypes.begin(), aTypes.end(), nValue) != aTypes.end();
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  {
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), m_xImpl->xInfo->getNumberingIdentifier(nCurrent));
110  }
111  }
112  }
113  m_xWidget->set_active(0);
114  }
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)
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