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