xref: /AOO41X/main/sw/source/ui/misc/numberingtypelistbox.cxx (revision efeef26f81c84063fb0a91bde3856d4a51172d90)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26 #include <numberingtypelistbox.hxx>
27 #ifndef _MISC_HRC
28 #include <misc.hrc>
29 #endif
30 #include <cnttab.hxx>
31 #include <com/sun/star/style/NumberingType.hpp>
32 #include <com/sun/star/text/XDefaultNumberingProvider.hpp>
33 #include <comphelper/processfactory.hxx>
34 #include <com/sun/star/text/XNumberingTypeInfo.hpp>
35 
36 #include <unomid.h>
37 
38 using namespace com::sun::star;
39 using namespace rtl;
40 
41 /* -----------------------------01.03.01 16:04--------------------------------
42 
43  ---------------------------------------------------------------------------*/
44 struct SwNumberingTypeListBox_Impl
45 {
46     uno::Reference<text::XNumberingTypeInfo> xInfo;
47 };
48 /* -----------------------------01.03.01 14:46--------------------------------
49 
50  ---------------------------------------------------------------------------*/
SwNumberingTypeListBox(Window * pWin,const ResId & rResId,sal_uInt16 nTypeFlags)51 SwNumberingTypeListBox::SwNumberingTypeListBox( Window* pWin, const ResId& rResId,
52         sal_uInt16 nTypeFlags ) :
53     ListBox(pWin, rResId),
54     pImpl(new SwNumberingTypeListBox_Impl)
55 {
56     uno::Reference< lang::XMultiServiceFactory > xMSF = ::comphelper::getProcessServiceFactory();
57     uno::Reference < uno::XInterface > xI = xMSF->createInstance(
58         ::rtl::OUString::createFromAscii( "com.sun.star.text.DefaultNumberingProvider" ) );
59     uno::Reference<text::XDefaultNumberingProvider> xDefNum(xI, uno::UNO_QUERY);
60     DBG_ASSERT(xDefNum.is(), "service missing: \"com.sun.star.text.DefaultNumberingProvider\"");
61 
62     pImpl->xInfo = uno::Reference<text::XNumberingTypeInfo>(xDefNum, uno::UNO_QUERY);
63     Reload(nTypeFlags);
64 }
65 /* -----------------------------01.03.01 14:46--------------------------------
66 
67  ---------------------------------------------------------------------------*/
~SwNumberingTypeListBox()68 SwNumberingTypeListBox::~SwNumberingTypeListBox()
69 {
70     delete pImpl;
71 }
72 /* -----------------------------01.03.01 16:02--------------------------------
73 
74  ---------------------------------------------------------------------------*/
Reload(sal_uInt16 nTypeFlags)75 void SwNumberingTypeListBox::Reload(sal_uInt16 nTypeFlags)
76 {
77     Clear();
78     uno::Sequence<sal_Int16> aTypes;
79     const sal_Int16* pTypes = NULL;
80     if(0 != (nTypeFlags&INSERT_NUM_EXTENDED_TYPES) )
81     {
82         if(pImpl->xInfo.is())
83         {
84             aTypes = pImpl->xInfo->getSupportedNumberingTypes();
85             pTypes = aTypes.getConstArray();
86         }
87     }
88     SwOLENames aNames(SW_RES(STRRES_NUMTYPES));
89     ResStringArray& rNames = aNames.GetNames();
90     for(sal_uInt16 i = 0; i < rNames.Count(); i++)
91     {
92         long nValue = rNames.GetValue(i);
93         sal_Bool bInsert = sal_True;
94         sal_uInt16 nPos = LISTBOX_APPEND;
95         switch(nValue)
96         {
97             case  style::NumberingType::NUMBER_NONE:
98                 bInsert = 0 != (nTypeFlags&INSERT_NUM_TYPE_NO_NUMBERING);
99                 nPos = 0;
100              break;
101             case  style::NumberingType::CHAR_SPECIAL:   bInsert = 0 != (nTypeFlags&INSERT_NUM_TYPE_BULLET); break;
102             case  style::NumberingType::PAGE_DESCRIPTOR:bInsert = 0 != (nTypeFlags&INSERT_NUM_TYPE_PAGE_STYLE_NUMBERING); break;
103             case  style::NumberingType::BITMAP:bInsert = 0 != (nTypeFlags&INSERT_NUM_TYPE_BITMAP ); break;
104             default:
105                 if (nValue >  style::NumberingType::CHARS_LOWER_LETTER_N)
106                 {
107                     // Insert only if offered by i18n framework per configuration.
108                     bInsert = sal_False;
109                     if (pTypes)
110                     {
111                         for(sal_Int32 nType = 0; nType < aTypes.getLength(); nType++)
112                         {
113                             if (pTypes[nType] == nValue)
114                             {
115                                 bInsert = sal_True;
116                                 break;  // for
117                             }
118                         }
119                     }
120                 }
121         }
122         if(bInsert)
123         {
124             sal_uInt16 nEntry = InsertEntry(rNames.GetString(i), nPos);
125             SetEntryData( nEntry, (void*)nValue );
126         }
127     }
128     if(0 != (nTypeFlags&INSERT_NUM_EXTENDED_TYPES) )
129     {
130         if(pTypes)
131         {
132             for(sal_Int32 nType = 0; nType < aTypes.getLength(); nType++)
133             {
134                 sal_Int16 nCurrent = pTypes[nType];
135                 if(nCurrent > style::NumberingType::CHARS_LOWER_LETTER_N)
136                 {
137                     if(LISTBOX_ENTRY_NOTFOUND == GetEntryPos((void*)(sal_uLong)nCurrent))
138                     {
139                         OUString aIdent = pImpl->xInfo->getNumberingIdentifier( nCurrent );
140                         sal_uInt16 nPos = InsertEntry(aIdent);
141                         SetEntryData(nPos,(void*)(sal_uLong)nCurrent);
142                     }
143                 }
144             }
145         }
146         SelectEntryPos(0);
147     }
148 }
149 /* -----------------------------01.03.01 14:46--------------------------------
150 
151  ---------------------------------------------------------------------------*/
GetSelectedNumberingType()152 sal_Int16   SwNumberingTypeListBox::GetSelectedNumberingType()
153 {
154     sal_Int16 nRet = 0;
155     sal_uInt16 nSelPos = GetSelectEntryPos();
156     if(LISTBOX_ENTRY_NOTFOUND != nSelPos)
157         nRet = (sal_Int16)(sal_uLong)GetEntryData(nSelPos);
158 #ifdef DBG_UTIL
159     else
160         DBG_ERROR("SwNumberingTypeListBox not selected");
161 #endif
162     return nRet;
163 }
164 /* -----------------------------01.03.01 14:46--------------------------------
165 
166  ---------------------------------------------------------------------------*/
SelectNumberingType(sal_Int16 nType)167 sal_Bool    SwNumberingTypeListBox::SelectNumberingType(sal_Int16 nType)
168 {
169     sal_uInt16 nPos = GetEntryPos((void*)(sal_uLong)nType);
170     SelectEntryPos( nPos );
171     return LISTBOX_ENTRY_NOTFOUND != nPos;
172 }
173 
174