Line data Source code
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 <misc.hrc>
22 : #include <cnttab.hxx>
23 : #include <com/sun/star/style/NumberingType.hpp>
24 : #include <com/sun/star/text/DefaultNumberingProvider.hpp>
25 : #include <com/sun/star/text/XDefaultNumberingProvider.hpp>
26 : #include <comphelper/processfactory.hxx>
27 : #include <com/sun/star/text/XNumberingTypeInfo.hpp>
28 : #include <vcl/builderfactory.hxx>
29 :
30 : #include <unomid.h>
31 :
32 : using namespace com::sun::star;
33 :
34 0 : struct SwNumberingTypeListBox_Impl
35 : {
36 : uno::Reference<text::XNumberingTypeInfo> xInfo;
37 : };
38 :
39 0 : SwNumberingTypeListBox::SwNumberingTypeListBox( vcl::Window* pWin, WinBits nStyle ) :
40 : ListBox(pWin, nStyle),
41 0 : pImpl(new SwNumberingTypeListBox_Impl)
42 : {
43 0 : uno::Reference<uno::XComponentContext> xContext( ::comphelper::getProcessComponentContext() );
44 0 : uno::Reference<text::XDefaultNumberingProvider> xDefNum = text::DefaultNumberingProvider::create(xContext);
45 :
46 0 : pImpl->xInfo = uno::Reference<text::XNumberingTypeInfo>(xDefNum, uno::UNO_QUERY);
47 0 : }
48 :
49 0 : bool SwNumberingTypeListBox::set_property(const OString &rKey, const OString &rValue)
50 : {
51 0 : if (rKey == "type")
52 0 : Reload(rValue.toInt32());
53 : else
54 0 : return ListBox::set_property(rKey, rValue);
55 0 : return true;
56 : }
57 :
58 0 : VCL_BUILDER_DECL_FACTORY(SwNumberingTypeListBox)
59 : {
60 : (void)rMap;
61 0 : VclPtrInstance<SwNumberingTypeListBox> pListBox(pParent, WB_LEFT|WB_DROPDOWN|WB_VCENTER|WB_3DLOOK|WB_TABSTOP);
62 0 : pListBox->EnableAutoSize(true);
63 0 : rRet = pListBox;
64 0 : }
65 :
66 0 : SwNumberingTypeListBox::~SwNumberingTypeListBox()
67 : {
68 0 : disposeOnce();
69 0 : }
70 :
71 0 : void SwNumberingTypeListBox::dispose()
72 : {
73 0 : delete pImpl;
74 0 : ListBox::dispose();
75 0 : }
76 :
77 0 : void SwNumberingTypeListBox::Reload(sal_uInt16 nTypeFlags)
78 : {
79 0 : Clear();
80 0 : uno::Sequence<sal_Int16> aTypes;
81 0 : const sal_Int16* pTypes = NULL;
82 0 : if(0 != (nTypeFlags&INSERT_NUM_EXTENDED_TYPES) )
83 : {
84 0 : if(pImpl->xInfo.is())
85 : {
86 0 : aTypes = pImpl->xInfo->getSupportedNumberingTypes();
87 0 : pTypes = aTypes.getConstArray();
88 : }
89 : }
90 0 : SwOLENames aNames(SW_RES(STRRES_NUMTYPES));
91 0 : ResStringArray& rNames = aNames.GetNames();
92 0 : for(size_t i = 0; i < rNames.Count(); i++)
93 : {
94 0 : sal_IntPtr nValue = rNames.GetValue(i);
95 0 : bool bInsert = true;
96 0 : sal_Int32 nPos = LISTBOX_APPEND;
97 0 : switch(nValue)
98 : {
99 : case style::NumberingType::NUMBER_NONE:
100 0 : bInsert = 0 != (nTypeFlags&INSERT_NUM_TYPE_NO_NUMBERING);
101 0 : nPos = 0;
102 :
103 0 : break;
104 : case style::NumberingType::CHAR_SPECIAL:
105 0 : bInsert = 0 != (nTypeFlags&INSERT_NUM_TYPE_BULLET);
106 :
107 0 : break;
108 : case style::NumberingType::PAGE_DESCRIPTOR:
109 0 : bInsert = 0 != (nTypeFlags&INSERT_NUM_TYPE_PAGE_STYLE_NUMBERING);
110 :
111 0 : break;
112 : case style::NumberingType::BITMAP:
113 0 : bInsert = 0 != (nTypeFlags&INSERT_NUM_TYPE_BITMAP );
114 :
115 0 : break;
116 : default:
117 0 : if (nValue > style::NumberingType::CHARS_LOWER_LETTER_N)
118 : {
119 : // Insert only if offered by i18n framework per configuration.
120 0 : bInsert = false;
121 0 : if (pTypes)
122 : {
123 0 : for(sal_Int32 nType = 0; nType < aTypes.getLength(); nType++)
124 : {
125 0 : if (pTypes[nType] == nValue)
126 : {
127 0 : bInsert = true;
128 0 : break; // for
129 : }
130 : }
131 : }
132 : }
133 : }
134 0 : if(bInsert)
135 : {
136 0 : sal_Int32 nEntry = InsertEntry(rNames.GetString(i), nPos);
137 0 : SetEntryData( nEntry, reinterpret_cast<void*>(nValue) );
138 : }
139 : }
140 0 : if(0 != (nTypeFlags&INSERT_NUM_EXTENDED_TYPES) )
141 : {
142 0 : if(pTypes)
143 : {
144 0 : for(sal_Int32 nType = 0; nType < aTypes.getLength(); nType++)
145 : {
146 0 : sal_Int16 nCurrent = pTypes[nType];
147 0 : if(nCurrent > style::NumberingType::CHARS_LOWER_LETTER_N)
148 : {
149 0 : if(LISTBOX_ENTRY_NOTFOUND == GetEntryPos(reinterpret_cast<void*>((sal_uLong)nCurrent)))
150 : {
151 0 : OUString aIdent = pImpl->xInfo->getNumberingIdentifier( nCurrent );
152 0 : sal_Int32 nPos = InsertEntry(aIdent);
153 0 : SetEntryData(nPos, reinterpret_cast<void*>((sal_uLong)nCurrent));
154 : }
155 : }
156 : }
157 : }
158 0 : SelectEntryPos(0);
159 0 : }
160 0 : }
161 :
162 0 : sal_Int16 SwNumberingTypeListBox::GetSelectedNumberingType()
163 : {
164 0 : sal_Int16 nRet = 0;
165 0 : sal_Int32 nSelPos = GetSelectEntryPos();
166 0 : if(LISTBOX_ENTRY_NOTFOUND != nSelPos)
167 0 : nRet = (sal_Int16)reinterpret_cast<sal_uLong>(GetEntryData(nSelPos));
168 : #if OSL_DEBUG_LEVEL > 0
169 : else
170 : OSL_FAIL("SwNumberingTypeListBox not selected");
171 : #endif
172 0 : return nRet;
173 : }
174 :
175 0 : bool SwNumberingTypeListBox::SelectNumberingType(sal_Int16 nType)
176 : {
177 0 : sal_Int32 nPos = GetEntryPos(reinterpret_cast<void*>((sal_uLong)nType));
178 0 : SelectEntryPos( nPos );
179 0 : return LISTBOX_ENTRY_NOTFOUND != nPos;
180 177 : }
181 :
182 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|