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