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 <cnttab.hxx>
22 #include <com/sun/star/style/NumberingType.hpp>
23 #include <com/sun/star/text/DefaultNumberingProvider.hpp>
24 #include <com/sun/star/text/XDefaultNumberingProvider.hpp>
26 #include <com/sun/star/text/XNumberingTypeInfo.hpp>
27 #include <editeng/numitem.hxx>
28 #include <svx/dialogs.hrc>
29 #include <svx/strarray.hxx>
30 #include <osl/diagnose.h>
31 
32 #include <unomid.h>
33 
34 using namespace com::sun::star;
35 
37 {
38  uno::Reference<text::XNumberingTypeInfo> xInfo;
39 };
40 
41 SwNumberingTypeListBox::SwNumberingTypeListBox(std::unique_ptr<weld::ComboBox> pWidget)
42  : m_xWidget(std::move(pWidget))
43  , m_xImpl(new SwNumberingTypeListBox_Impl)
44 {
45  uno::Reference<uno::XComponentContext> xContext( ::comphelper::getProcessComponentContext() );
46  uno::Reference<text::XDefaultNumberingProvider> xDefNum = text::DefaultNumberingProvider::create(xContext);
47  m_xImpl->xInfo.set(xDefNum, uno::UNO_QUERY);
48 }
49 
51 {
52 }
53 
55 {
56  m_xWidget->clear();
57  uno::Sequence<sal_Int16> aTypes;
58  if (nTypeFlags & SwInsertNumTypes::Extended)
59  {
60  if (m_xImpl->xInfo.is())
61  aTypes = m_xImpl->xInfo->getSupportedNumberingTypes();
62  }
63 
64  for(size_t i = 0; i < SvxNumberingTypeTable::Count(); i++)
65  {
66  sal_IntPtr nValue = SvxNumberingTypeTable::GetValue(i);
67  bool bInsert = true;
68  int nPos = -1;
69  switch(nValue)
70  {
71  case style::NumberingType::NUMBER_NONE:
72  bInsert = bool(nTypeFlags & SwInsertNumTypes::NoNumbering);
73  nPos = 0;
74 
75  break;
76  case style::NumberingType::CHAR_SPECIAL:
77  bInsert = false;
78 
79  break;
80  case style::NumberingType::PAGE_DESCRIPTOR:
81  bInsert = false;
82 
83  break;
85  bInsert = false;
86 
87  break;
89  bInsert = false;
90 
91  break;
92  default:
93  if (nValue > style::NumberingType::CHARS_LOWER_LETTER_N)
94  {
95  // Insert only if offered by i18n framework per configuration.
96  bInsert = std::find(aTypes.begin(), aTypes.end(), nValue) != aTypes.end();
97  }
98  }
99  if (bInsert)
100  {
101  OUString sId(OUString::number(nValue));
102  m_xWidget->insert(nPos, SvxNumberingTypeTable::GetString(i), &sId, nullptr, nullptr);
103  }
104  }
105  if (nTypeFlags & SwInsertNumTypes::Extended)
106  {
107  for (sal_Int16 nCurrent : aTypes)
108  {
109  if (nCurrent > style::NumberingType::CHARS_LOWER_LETTER_N)
110  {
111  if (m_xWidget->find_id(OUString::number(nCurrent)) == -1)
112  {
113  m_xWidget->append(OUString::number(nCurrent), m_xImpl->xInfo->getNumberingIdentifier(nCurrent));
114  }
115  }
116  }
117  m_xWidget->set_active(0);
118  }
119 }
120 
122 {
124  int nSelPos = m_xWidget->get_active();
125  if (nSelPos != -1)
126  nRet = static_cast<SvxNumType>(m_xWidget->get_id(nSelPos).toInt32());
127 #if OSL_DEBUG_LEVEL > 0
128  else
129  OSL_FAIL("NumberingTypeListBox not selected");
130 #endif
131  return nRet;
132 }
133 
135 {
136  int nPos = m_xWidget->find_id(OUString::number(nType));
137  m_xWidget->set_active(nPos);
138  return nPos != -1;
139 }
140 
141 /* 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()
std::unique_ptr< weld::ComboBox > m_xWidget
sal_Int32 nPos
OUString sId