Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <numberingtypelistbox.hxx>
30 : : #include <misc.hrc>
31 : : #include <cnttab.hxx>
32 : : #include <com/sun/star/style/NumberingType.hpp>
33 : : #include <com/sun/star/text/DefaultNumberingProvider.hpp>
34 : : #include <com/sun/star/text/XDefaultNumberingProvider.hpp>
35 : : #include <comphelper/processfactory.hxx>
36 : : #include <com/sun/star/text/XNumberingTypeInfo.hpp>
37 : :
38 : : #include <unomid.h>
39 : :
40 : : using namespace com::sun::star;
41 : :
42 : : using ::rtl::OUString;
43 : :
44 : 0 : struct SwNumberingTypeListBox_Impl
45 : : {
46 : : uno::Reference<text::XNumberingTypeInfo> xInfo;
47 : : };
48 : :
49 : 0 : SwNumberingTypeListBox::SwNumberingTypeListBox( Window* pWin, const ResId& rResId,
50 : : sal_uInt16 nTypeFlags ) :
51 : : ListBox(pWin, rResId),
52 [ # # ][ # # ]: 0 : pImpl(new SwNumberingTypeListBox_Impl)
53 : : {
54 [ # # ]: 0 : uno::Reference<uno::XComponentContext> xContext( ::comphelper::getProcessComponentContext() );
55 [ # # ]: 0 : uno::Reference<text::XDefaultNumberingProvider> xDefNum = text::DefaultNumberingProvider::create(xContext);
56 : :
57 [ # # ][ # # ]: 0 : pImpl->xInfo = uno::Reference<text::XNumberingTypeInfo>(xDefNum, uno::UNO_QUERY);
58 [ # # ]: 0 : Reload(nTypeFlags);
59 : 0 : }
60 : :
61 : 0 : SwNumberingTypeListBox::~SwNumberingTypeListBox()
62 : : {
63 [ # # ][ # # ]: 0 : delete pImpl;
64 [ # # ]: 0 : }
65 : :
66 : 0 : void SwNumberingTypeListBox::Reload(sal_uInt16 nTypeFlags)
67 : : {
68 [ # # ]: 0 : Clear();
69 [ # # ]: 0 : uno::Sequence<sal_Int16> aTypes;
70 : 0 : const sal_Int16* pTypes = NULL;
71 [ # # ]: 0 : if(0 != (nTypeFlags&INSERT_NUM_EXTENDED_TYPES) )
72 : : {
73 [ # # ]: 0 : if(pImpl->xInfo.is())
74 : : {
75 [ # # ][ # # ]: 0 : aTypes = pImpl->xInfo->getSupportedNumberingTypes();
[ # # ][ # # ]
76 : 0 : pTypes = aTypes.getConstArray();
77 : : }
78 : : }
79 [ # # ]: 0 : SwOLENames aNames(SW_RES(STRRES_NUMTYPES));
80 : 0 : ResStringArray& rNames = aNames.GetNames();
81 [ # # ]: 0 : for(sal_uInt16 i = 0; i < rNames.Count(); i++)
82 : : {
83 [ # # ]: 0 : long nValue = rNames.GetValue(i);
84 : 0 : sal_Bool bInsert = sal_True;
85 : 0 : sal_uInt16 nPos = LISTBOX_APPEND;
86 [ # # # # : 0 : switch(nValue)
# ]
87 : : {
88 : : case style::NumberingType::NUMBER_NONE:
89 : 0 : bInsert = 0 != (nTypeFlags&INSERT_NUM_TYPE_NO_NUMBERING);
90 : 0 : nPos = 0;
91 : 0 : break;
92 : 0 : case style::NumberingType::CHAR_SPECIAL: bInsert = 0 != (nTypeFlags&INSERT_NUM_TYPE_BULLET); break;
93 : 0 : case style::NumberingType::PAGE_DESCRIPTOR:bInsert = 0 != (nTypeFlags&INSERT_NUM_TYPE_PAGE_STYLE_NUMBERING); break;
94 : 0 : case style::NumberingType::BITMAP:bInsert = 0 != (nTypeFlags&INSERT_NUM_TYPE_BITMAP ); break;
95 : : default:
96 [ # # ]: 0 : if (nValue > style::NumberingType::CHARS_LOWER_LETTER_N)
97 : : {
98 : : // Insert only if offered by i18n framework per configuration.
99 : 0 : bInsert = sal_False;
100 [ # # ]: 0 : if (pTypes)
101 : : {
102 [ # # ]: 0 : for(sal_Int32 nType = 0; nType < aTypes.getLength(); nType++)
103 : : {
104 [ # # ]: 0 : if (pTypes[nType] == nValue)
105 : : {
106 : 0 : bInsert = sal_True;
107 : 0 : break; // for
108 : : }
109 : : }
110 : : }
111 : : }
112 : : }
113 [ # # ]: 0 : if(bInsert)
114 : : {
115 [ # # ][ # # ]: 0 : sal_uInt16 nEntry = InsertEntry(rNames.GetString(i), nPos);
[ # # ][ # # ]
116 [ # # ]: 0 : SetEntryData( nEntry, (void*)nValue );
117 : : }
118 : : }
119 [ # # ]: 0 : if(0 != (nTypeFlags&INSERT_NUM_EXTENDED_TYPES) )
120 : : {
121 [ # # ]: 0 : if(pTypes)
122 : : {
123 [ # # ]: 0 : for(sal_Int32 nType = 0; nType < aTypes.getLength(); nType++)
124 : : {
125 : 0 : sal_Int16 nCurrent = pTypes[nType];
126 [ # # ]: 0 : if(nCurrent > style::NumberingType::CHARS_LOWER_LETTER_N)
127 : : {
128 [ # # ][ # # ]: 0 : if(LISTBOX_ENTRY_NOTFOUND == GetEntryPos((void*)(sal_uLong)nCurrent))
129 : : {
130 [ # # ][ # # ]: 0 : OUString aIdent = pImpl->xInfo->getNumberingIdentifier( nCurrent );
131 [ # # ][ # # ]: 0 : sal_uInt16 nPos = InsertEntry(aIdent);
[ # # ]
132 [ # # ]: 0 : SetEntryData(nPos,(void*)(sal_uLong)nCurrent);
133 : : }
134 : : }
135 : : }
136 : : }
137 [ # # ]: 0 : SelectEntryPos(0);
138 [ # # ][ # # ]: 0 : }
139 : 0 : }
140 : :
141 : 0 : sal_Int16 SwNumberingTypeListBox::GetSelectedNumberingType()
142 : : {
143 : 0 : sal_Int16 nRet = 0;
144 : 0 : sal_uInt16 nSelPos = GetSelectEntryPos();
145 [ # # ]: 0 : if(LISTBOX_ENTRY_NOTFOUND != nSelPos)
146 : 0 : nRet = (sal_Int16)(sal_uLong)GetEntryData(nSelPos);
147 : : #if OSL_DEBUG_LEVEL > 0
148 : : else
149 : : OSL_FAIL("SwNumberingTypeListBox not selected");
150 : : #endif
151 : 0 : return nRet;
152 : : }
153 : :
154 : 0 : sal_Bool SwNumberingTypeListBox::SelectNumberingType(sal_Int16 nType)
155 : : {
156 : 0 : sal_uInt16 nPos = GetEntryPos((void*)(sal_uLong)nType);
157 : 0 : SelectEntryPos( nPos );
158 : 0 : return LISTBOX_ENTRY_NOTFOUND != nPos;
159 : : }
160 : :
161 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|