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 : :
30 : : #include <stdio.h>
31 : :
32 : : #include <threadhelp/resetableguard.hxx>
33 : : #include <xml/statusbardocumenthandler.hxx>
34 : : #include <macros/debug.hxx>
35 : :
36 : : #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
37 : : #include <com/sun/star/ui/ItemStyle.hpp>
38 : : #include <com/sun/star/ui/ItemType.hpp>
39 : : #include <com/sun/star/beans/PropertyValue.hpp>
40 : :
41 : : #include <vcl/svapp.hxx>
42 : : #include <vcl/status.hxx>
43 : :
44 : : #include <comphelper/attributelist.hxx>
45 : :
46 : : using namespace ::com::sun::star::uno;
47 : : using namespace ::com::sun::star::beans;
48 : : using namespace ::com::sun::star::xml::sax;
49 : : using namespace ::com::sun::star::ui;
50 : : using namespace ::com::sun::star::container;
51 : :
52 : : #define XMLNS_STATUSBAR "http://openoffice.org/2001/statusbar"
53 : : #define XMLNS_XLINK "http://www.w3.org/1999/xlink"
54 : : #define XMLNS_STATUSBAR_PREFIX "statusbar:"
55 : : #define XMLNS_XLINK_PREFIX "xlink:"
56 : :
57 : : #define XMLNS_FILTER_SEPARATOR "^"
58 : :
59 : : #define ELEMENT_STATUSBAR "statusbar"
60 : : #define ELEMENT_STATUSBARITEM "statusbaritem"
61 : :
62 : : #define ATTRIBUTE_ALIGN "align"
63 : : #define ATTRIBUTE_STYLE "style"
64 : : #define ATTRIBUTE_URL "href"
65 : : #define ATTRIBUTE_WIDTH "width"
66 : : #define ATTRIBUTE_OFFSET "offset"
67 : : #define ATTRIBUTE_AUTOSIZE "autosize"
68 : : #define ATTRIBUTE_OWNERDRAW "ownerdraw"
69 : : #define ATTRIBUTE_HELPURL "helpid"
70 : :
71 : : #define ELEMENT_NS_STATUSBAR "statusbar:statusbar"
72 : : #define ELEMENT_NS_STATUSBARITEM "statusbar:statusbaritem"
73 : :
74 : : #define ATTRIBUTE_XMLNS_STATUSBAR "xmlns:statusbar"
75 : : #define ATTRIBUTE_XMLNS_XLINK "xmlns:xlink"
76 : :
77 : : #define ATTRIBUTE_TYPE_CDATA "CDATA"
78 : :
79 : : #define ATTRIBUTE_BOOLEAN_TRUE "true"
80 : : #define ATTRIBUTE_BOOLEAN_FALSE "false"
81 : :
82 : : #define ATTRIBUTE_ALIGN_LEFT "left"
83 : : #define ATTRIBUTE_ALIGN_RIGHT "right"
84 : : #define ATTRIBUTE_ALIGN_CENTER "center"
85 : :
86 : : #define ATTRIBUTE_STYLE_IN "in"
87 : : #define ATTRIBUTE_STYLE_OUT "out"
88 : : #define ATTRIBUTE_STYLE_FLAT "flat"
89 : :
90 : : #define STATUSBAR_DOCTYPE "<!DOCTYPE statusbar:statusbar PUBLIC \"-//OpenOffice.org//DTD OfficeDocument 1.0//EN\" \"statusbar.dtd\">"
91 : :
92 : : namespace framework
93 : : {
94 : :
95 : : // Property names of a menu/menu item ItemDescriptor
96 : : static const char ITEM_DESCRIPTOR_COMMANDURL[] = "CommandURL";
97 : : static const char ITEM_DESCRIPTOR_HELPURL[] = "HelpURL";
98 : : static const char ITEM_DESCRIPTOR_OFFSET[] = "Offset";
99 : : static const char ITEM_DESCRIPTOR_STYLE[] = "Style";
100 : : static const char ITEM_DESCRIPTOR_WIDTH[] = "Width";
101 : : static const char ITEM_DESCRIPTOR_TYPE[] = "Type";
102 : :
103 : 0 : static void ExtractStatusbarItemParameters(
104 : : const Sequence< PropertyValue > rProp,
105 : : ::rtl::OUString& rCommandURL,
106 : : ::rtl::OUString& rHelpURL,
107 : : sal_Int16& rOffset,
108 : : sal_Int16& rStyle,
109 : : sal_Int16& rWidth )
110 : : {
111 [ # # ]: 0 : for ( sal_Int32 i = 0; i < rProp.getLength(); i++ )
112 : : {
113 [ # # ]: 0 : if ( rProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_COMMANDURL ))
114 : : {
115 : 0 : rProp[i].Value >>= rCommandURL;
116 : 0 : rCommandURL = rCommandURL.intern();
117 : : }
118 [ # # ]: 0 : else if ( rProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_HELPURL ))
119 : : {
120 : 0 : rProp[i].Value >>= rHelpURL;
121 : : }
122 [ # # ]: 0 : else if ( rProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_OFFSET ))
123 : : {
124 : 0 : rProp[i].Value >>= rOffset;
125 : : }
126 [ # # ]: 0 : else if ( rProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_STYLE ))
127 : : {
128 : 0 : rProp[i].Value >>= rStyle;
129 : : }
130 [ # # ]: 0 : else if ( rProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_WIDTH ))
131 : : {
132 : 0 : rProp[i].Value >>= rWidth;
133 : : }
134 : : }
135 : 0 : }
136 : :
137 : : struct StatusBarEntryProperty
138 : : {
139 : : OReadStatusBarDocumentHandler::StatusBar_XML_Namespace nNamespace;
140 : : char aEntryName[20];
141 : : };
142 : :
143 : : StatusBarEntryProperty StatusBarEntries[OReadStatusBarDocumentHandler::SB_XML_ENTRY_COUNT] =
144 : : {
145 : : { OReadStatusBarDocumentHandler::SB_NS_STATUSBAR, ELEMENT_STATUSBAR },
146 : : { OReadStatusBarDocumentHandler::SB_NS_STATUSBAR, ELEMENT_STATUSBARITEM },
147 : : { OReadStatusBarDocumentHandler::SB_NS_XLINK, ATTRIBUTE_URL },
148 : : { OReadStatusBarDocumentHandler::SB_NS_STATUSBAR, ATTRIBUTE_ALIGN },
149 : : { OReadStatusBarDocumentHandler::SB_NS_STATUSBAR, ATTRIBUTE_STYLE },
150 : : { OReadStatusBarDocumentHandler::SB_NS_STATUSBAR, ATTRIBUTE_AUTOSIZE },
151 : : { OReadStatusBarDocumentHandler::SB_NS_STATUSBAR, ATTRIBUTE_OWNERDRAW },
152 : : { OReadStatusBarDocumentHandler::SB_NS_STATUSBAR, ATTRIBUTE_WIDTH },
153 : : { OReadStatusBarDocumentHandler::SB_NS_STATUSBAR, ATTRIBUTE_OFFSET },
154 : : { OReadStatusBarDocumentHandler::SB_NS_STATUSBAR, ATTRIBUTE_HELPURL }
155 : : };
156 : :
157 : :
158 : 90 : OReadStatusBarDocumentHandler::OReadStatusBarDocumentHandler(
159 : : const Reference< XIndexContainer >& rStatusBarItems ) :
160 : 90 : ThreadHelpBase( &Application::GetSolarMutex() ),
161 [ + - ][ + - ]: 90 : m_aStatusBarItems( rStatusBarItems )
162 : : {
163 [ + - ]: 90 : ::rtl::OUString aNamespaceStatusBar( RTL_CONSTASCII_USTRINGPARAM( XMLNS_STATUSBAR ));
164 [ + - ]: 90 : ::rtl::OUString aNamespaceXLink( RTL_CONSTASCII_USTRINGPARAM( XMLNS_XLINK ));
165 [ + - ]: 90 : ::rtl::OUString aSeparator( RTL_CONSTASCII_USTRINGPARAM( XMLNS_FILTER_SEPARATOR ));
166 : :
167 : : // create hash map
168 [ + + ]: 990 : for ( int i = 0; i < (int)SB_XML_ENTRY_COUNT; i++ )
169 : : {
170 [ + + ]: 900 : if ( StatusBarEntries[i].nNamespace == SB_NS_STATUSBAR )
171 : : {
172 : 810 : ::rtl::OUString temp( aNamespaceStatusBar );
173 : 810 : temp += aSeparator;
174 : 810 : temp += ::rtl::OUString::createFromAscii( StatusBarEntries[i].aEntryName );
175 [ + - ]: 810 : m_aStatusBarMap.insert( StatusBarHashMap::value_type( temp, (StatusBar_XML_Entry)i ) );
176 : : }
177 : : else
178 : : {
179 : 90 : ::rtl::OUString temp( aNamespaceXLink );
180 : 90 : temp += aSeparator;
181 : 90 : temp += ::rtl::OUString::createFromAscii( StatusBarEntries[i].aEntryName );
182 [ + - ]: 90 : m_aStatusBarMap.insert( StatusBarHashMap::value_type( temp, (StatusBar_XML_Entry)i ) );
183 : : }
184 : : }
185 : :
186 : 90 : m_bStatusBarStartFound = sal_False;
187 : 90 : m_bStatusBarEndFound = sal_False;
188 : 90 : m_bStatusBarItemStartFound = sal_False;
189 : 90 : }
190 : :
191 [ + - ][ + - ]: 90 : OReadStatusBarDocumentHandler::~OReadStatusBarDocumentHandler()
192 : : {
193 [ - + ]: 180 : }
194 : :
195 : : // XDocumentHandler
196 : 0 : void SAL_CALL OReadStatusBarDocumentHandler::startDocument(void)
197 : : throw ( SAXException, RuntimeException )
198 : : {
199 : 0 : }
200 : :
201 : 0 : void SAL_CALL OReadStatusBarDocumentHandler::endDocument(void)
202 : : throw( SAXException, RuntimeException )
203 : : {
204 [ # # ]: 0 : ResetableGuard aGuard( m_aLock );
205 : :
206 [ # # ][ # # ]: 0 : if (( m_bStatusBarStartFound && !m_bStatusBarEndFound ) ||
[ # # ][ # # ]
207 : 0 : ( !m_bStatusBarStartFound && m_bStatusBarEndFound ) )
208 : : {
209 [ # # ]: 0 : ::rtl::OUString aErrorMessage = getErrorLineString();
210 [ # # ]: 0 : aErrorMessage += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "No matching start or end element 'statusbar' found!" ));
211 [ # # ]: 0 : throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
212 [ # # ]: 0 : }
213 : 0 : }
214 : :
215 : 944 : void SAL_CALL OReadStatusBarDocumentHandler::startElement(
216 : : const ::rtl::OUString& aName, const Reference< XAttributeList > &xAttribs )
217 : : throw( SAXException, RuntimeException )
218 : : {
219 [ + - ]: 944 : ResetableGuard aGuard( m_aLock );
220 : :
221 [ + - ]: 944 : StatusBarHashMap::const_iterator pStatusBarEntry = m_aStatusBarMap.find( aName ) ;
222 [ + - ][ + - ]: 944 : if ( pStatusBarEntry != m_aStatusBarMap.end() )
223 : : {
224 [ + - ]: 944 : switch ( pStatusBarEntry->second )
[ + + - ]
225 : : {
226 : : case SB_ELEMENT_STATUSBAR:
227 : : {
228 [ - + ]: 90 : if ( m_bStatusBarStartFound )
229 : : {
230 [ # # ]: 0 : ::rtl::OUString aErrorMessage = getErrorLineString();
231 [ # # ]: 0 : aErrorMessage += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Element 'statusbar:statusbar' cannot be embeded into 'statusbar:statusbar'!" ));
232 [ # # ]: 0 : throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
233 : : }
234 : :
235 : 90 : m_bStatusBarStartFound = sal_True;
236 : : }
237 : 90 : break;
238 : :
239 : : case SB_ELEMENT_STATUSBARITEM:
240 : : {
241 [ - + ]: 854 : if ( !m_bStatusBarStartFound )
242 : : {
243 [ # # ]: 0 : ::rtl::OUString aErrorMessage = getErrorLineString();
244 [ # # ]: 0 : aErrorMessage += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Element 'statusbar:statusbaritem' must be embeded into element 'statusbar:statusbar'!" ));
245 [ # # ]: 0 : throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
246 : : }
247 : :
248 [ - + ]: 854 : if ( m_bStatusBarItemStartFound )
249 : : {
250 [ # # ]: 0 : ::rtl::OUString aErrorMessage = getErrorLineString();
251 [ # # ]: 0 : aErrorMessage += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Element statusbar:statusbaritem is not a container!" ));
252 [ # # ]: 0 : throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
253 : : }
254 : :
255 : 854 : ::rtl::OUString aCommandURL;
256 : 854 : ::rtl::OUString aHelpURL;
257 : 854 : sal_Int16 nItemBits( ItemStyle::ALIGN_CENTER|ItemStyle::DRAW_IN3D );
258 : 854 : sal_Int16 nWidth( 0 );
259 : 854 : sal_Int16 nOffset( STATUSBAR_OFFSET );
260 : 854 : sal_Bool bCommandURL( sal_False );
261 : :
262 : 854 : m_bStatusBarItemStartFound = sal_True;
263 [ + - ][ + - ]: 4932 : for ( sal_Int16 n = 0; n < xAttribs->getLength(); n++ )
[ + + ]
264 : : {
265 [ + - ][ + - ]: 4078 : pStatusBarEntry = m_aStatusBarMap.find( xAttribs->getNameByIndex( n ) );
[ + - ]
266 [ + - ][ + - ]: 4078 : if ( pStatusBarEntry != m_aStatusBarMap.end() )
267 : : {
268 [ + - ][ + + : 4078 : switch ( pStatusBarEntry->second )
- + + + -
+ - ]
269 : : {
270 : : case SB_ATTRIBUTE_URL:
271 : : {
272 : 854 : bCommandURL = sal_True;
273 [ + - ][ + - ]: 854 : aCommandURL = xAttribs->getValueByIndex( n );
274 : : }
275 : 854 : break;
276 : :
277 : : case SB_ATTRIBUTE_ALIGN:
278 : : {
279 [ + - ][ + - ]: 854 : if ( xAttribs->getValueByIndex( n ) == ATTRIBUTE_ALIGN_LEFT )
[ + + ]
280 : : {
281 : 274 : nItemBits |= ItemStyle::ALIGN_LEFT;
282 : 274 : nItemBits &= ~ItemStyle::ALIGN_CENTER;
283 : : }
284 [ + - ][ + - ]: 580 : else if ( xAttribs->getValueByIndex( n ) == ATTRIBUTE_ALIGN_CENTER )
[ + - ]
285 : : {
286 : 580 : nItemBits |= ItemStyle::ALIGN_CENTER;
287 : 580 : nItemBits &= ~ItemStyle::ALIGN_LEFT;
288 : : }
289 [ # # ][ # # ]: 0 : else if ( xAttribs->getValueByIndex( n ) == ATTRIBUTE_ALIGN_RIGHT )
[ # # ]
290 : : {
291 : 0 : nItemBits |= ItemStyle::ALIGN_RIGHT;
292 : : }
293 : : else
294 : : {
295 [ # # ]: 0 : ::rtl::OUString aErrorMessage = getErrorLineString();
296 [ # # ]: 0 : aErrorMessage += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Attribute statusbar:align must have one value of 'left','right' or 'center'!" ));
297 [ # # ]: 0 : throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
298 : : }
299 : : }
300 : 854 : break;
301 : :
302 : : case SB_ATTRIBUTE_STYLE:
303 : : {
304 [ # # ][ # # ]: 0 : if ( xAttribs->getValueByIndex( n ) == ATTRIBUTE_STYLE_IN )
[ # # ]
305 : : {
306 : 0 : nItemBits |= ItemStyle::DRAW_IN3D;
307 : 0 : nItemBits &= ~ItemStyle::DRAW_OUT3D;
308 : : }
309 [ # # ][ # # ]: 0 : else if ( xAttribs->getValueByIndex( n ) == ATTRIBUTE_STYLE_OUT )
[ # # ]
310 : : {
311 : 0 : nItemBits |= ItemStyle::DRAW_OUT3D;
312 : 0 : nItemBits &= ~ItemStyle::DRAW_IN3D;
313 : : }
314 [ # # ][ # # ]: 0 : else if ( xAttribs->getValueByIndex( n ) == ATTRIBUTE_STYLE_FLAT )
[ # # ]
315 : : {
316 : 0 : nItemBits |= ItemStyle::DRAW_FLAT;
317 : : }
318 : : else
319 : : {
320 [ # # ]: 0 : ::rtl::OUString aErrorMessage = getErrorLineString();
321 [ # # ]: 0 : aErrorMessage += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Attribute statusbar:autosize must have value 'true' or 'false'!" ));
322 [ # # ]: 0 : throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
323 : : }
324 : : }
325 : 0 : break;
326 : :
327 : : case SB_ATTRIBUTE_AUTOSIZE:
328 : : {
329 [ + - ][ + - ]: 304 : if ( xAttribs->getValueByIndex( n ) == ATTRIBUTE_BOOLEAN_TRUE )
[ + - ]
330 : 304 : nItemBits |= ItemStyle::AUTO_SIZE;
331 [ # # ][ # # ]: 0 : else if ( xAttribs->getValueByIndex( n ) == ATTRIBUTE_BOOLEAN_FALSE )
[ # # ]
332 : 0 : nItemBits &= ~ItemStyle::AUTO_SIZE;
333 : : else
334 : : {
335 [ # # ]: 0 : ::rtl::OUString aErrorMessage = getErrorLineString();
336 [ # # ]: 0 : aErrorMessage += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Attribute statusbar:autosize must have value 'true' or 'false'!" ));
337 [ # # ]: 0 : throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
338 : : }
339 : : }
340 : 304 : break;
341 : :
342 : : case SB_ATTRIBUTE_OWNERDRAW:
343 : : {
344 [ + - ][ + - ]: 436 : if ( xAttribs->getValueByIndex( n ) == ATTRIBUTE_BOOLEAN_TRUE )
[ + - ]
345 : 436 : nItemBits |= ItemStyle::OWNER_DRAW;
346 [ # # ][ # # ]: 0 : else if ( xAttribs->getValueByIndex( n ) == ATTRIBUTE_BOOLEAN_FALSE )
[ # # ]
347 : 0 : nItemBits &= ~ItemStyle::OWNER_DRAW;
348 : : else
349 : : {
350 [ # # ]: 0 : ::rtl::OUString aErrorMessage = getErrorLineString();
351 [ # # ]: 0 : aErrorMessage += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Attribute statusbar:ownerdraw must have value 'true' or 'false'!" ));
352 [ # # ]: 0 : throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
353 : : }
354 : : }
355 : 436 : break;
356 : :
357 : : case SB_ATTRIBUTE_WIDTH:
358 : : {
359 [ + - ][ + - ]: 816 : nWidth = (sal_Int16)(xAttribs->getValueByIndex( n ).toInt32());
360 : : }
361 : 816 : break;
362 : :
363 : : case SB_ATTRIBUTE_OFFSET:
364 : : {
365 [ # # ][ # # ]: 0 : nOffset = (sal_Int16)(xAttribs->getValueByIndex( n ).toInt32());
366 : : }
367 : 0 : break;
368 : :
369 : : case SB_ATTRIBUTE_HELPURL:
370 : : {
371 [ + - ][ + - ]: 814 : aHelpURL = xAttribs->getValueByIndex( n );
372 : : }
373 : 814 : break;
374 : :
375 : : default:
376 : 4078 : break;
377 : : }
378 : : }
379 : : } // for
380 : :
381 [ - + ]: 854 : if ( !bCommandURL )
382 : : {
383 [ # # ]: 0 : ::rtl::OUString aErrorMessage = getErrorLineString();
384 [ # # ]: 0 : aErrorMessage += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Required attribute statusbar:url must have a value!" ));
385 [ # # ]: 0 : throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
386 : : }
387 : : else
388 : : {
389 [ + - ]: 854 : Sequence< PropertyValue > aStatusbarItemProp( 6 );
390 [ + - ][ + - ]: 854 : aStatusbarItemProp[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_COMMANDURL ));
391 [ + - ][ + - ]: 854 : aStatusbarItemProp[1].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_HELPURL ));
392 [ + - ][ + - ]: 854 : aStatusbarItemProp[2].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_OFFSET ));
393 [ + - ][ + - ]: 854 : aStatusbarItemProp[3].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_STYLE ));
394 [ + - ][ + - ]: 854 : aStatusbarItemProp[4].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_WIDTH ));
395 [ + - ][ + - ]: 854 : aStatusbarItemProp[5].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_TYPE ));
396 : :
397 [ + - ][ + - ]: 854 : aStatusbarItemProp[0].Value <<= aCommandURL;
398 [ + - ][ + - ]: 854 : aStatusbarItemProp[1].Value <<= aHelpURL;
399 [ + - ][ + - ]: 854 : aStatusbarItemProp[2].Value <<= nOffset;
400 [ + - ][ + - ]: 854 : aStatusbarItemProp[3].Value <<= nItemBits;
401 [ + - ][ + - ]: 854 : aStatusbarItemProp[4].Value <<= nWidth;
402 [ + - ][ + - ]: 854 : aStatusbarItemProp[5].Value = makeAny( ::com::sun::star::ui::ItemType::DEFAULT );
403 : :
404 [ + - ][ + - ]: 854 : m_aStatusBarItems->insertByIndex( m_aStatusBarItems->getCount(), makeAny( aStatusbarItemProp ) );
[ + - ][ + - ]
[ + - ][ + - ]
405 : 854 : }
406 : : }
407 : 854 : break;
408 : :
409 : : default:
410 : 944 : break;
411 : : }
412 [ + - ]: 944 : }
413 : 944 : }
414 : :
415 : 944 : void SAL_CALL OReadStatusBarDocumentHandler::endElement(const ::rtl::OUString& aName)
416 : : throw( SAXException, RuntimeException )
417 : : {
418 [ + - ]: 944 : ResetableGuard aGuard( m_aLock );
419 : :
420 [ + - ]: 944 : StatusBarHashMap::const_iterator pStatusBarEntry = m_aStatusBarMap.find( aName ) ;
421 [ + - ][ + - ]: 944 : if ( pStatusBarEntry != m_aStatusBarMap.end() )
422 : : {
423 [ + - ]: 944 : switch ( pStatusBarEntry->second )
[ + + - ]
424 : : {
425 : : case SB_ELEMENT_STATUSBAR:
426 : : {
427 [ - + ]: 90 : if ( !m_bStatusBarStartFound )
428 : : {
429 [ # # ]: 0 : ::rtl::OUString aErrorMessage = getErrorLineString();
430 [ # # ]: 0 : aErrorMessage += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "End element 'statusbar' found, but no start element 'statusbar'" ));
431 [ # # ]: 0 : throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
432 : : }
433 : :
434 : 90 : m_bStatusBarStartFound = sal_False;
435 : : }
436 : 90 : break;
437 : :
438 : : case SB_ELEMENT_STATUSBARITEM:
439 : : {
440 [ - + ]: 854 : if ( !m_bStatusBarItemStartFound )
441 : : {
442 [ # # ]: 0 : ::rtl::OUString aErrorMessage = getErrorLineString();
443 [ # # ]: 0 : aErrorMessage += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "End element 'statusbar:statusbaritem' found, but no start element 'statusbar:statusbaritem'" ));
444 [ # # ]: 0 : throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
445 : : }
446 : :
447 : 854 : m_bStatusBarItemStartFound = sal_False;
448 : : }
449 : 854 : break;
450 : :
451 : : default:
452 : 944 : break;
453 : : }
454 [ + - ]: 944 : }
455 : 944 : }
456 : :
457 : 1798 : void SAL_CALL OReadStatusBarDocumentHandler::characters(const ::rtl::OUString&)
458 : : throw( SAXException, RuntimeException )
459 : : {
460 : 1798 : }
461 : :
462 : 0 : void SAL_CALL OReadStatusBarDocumentHandler::ignorableWhitespace(const ::rtl::OUString&)
463 : : throw( SAXException, RuntimeException )
464 : : {
465 : 0 : }
466 : :
467 : 0 : void SAL_CALL OReadStatusBarDocumentHandler::processingInstruction(
468 : : const ::rtl::OUString& /*aTarget*/, const ::rtl::OUString& /*aData*/ )
469 : : throw( SAXException, RuntimeException )
470 : : {
471 : 0 : }
472 : :
473 : 90 : void SAL_CALL OReadStatusBarDocumentHandler::setDocumentLocator(
474 : : const Reference< XLocator > &xLocator)
475 : : throw( SAXException, RuntimeException )
476 : : {
477 [ + - ]: 90 : ResetableGuard aGuard( m_aLock );
478 : :
479 [ + - ][ + - ]: 90 : m_xLocator = xLocator;
480 : 90 : }
481 : :
482 : 0 : ::rtl::OUString OReadStatusBarDocumentHandler::getErrorLineString()
483 : : {
484 [ # # ]: 0 : ResetableGuard aGuard( m_aLock );
485 : :
486 : : char buffer[32];
487 : :
488 [ # # ]: 0 : if ( m_xLocator.is() )
489 : : {
490 [ # # ][ # # ]: 0 : snprintf( buffer, sizeof(buffer), "Line: %ld - ", static_cast<long>( m_xLocator->getLineNumber() ));
491 : 0 : return ::rtl::OUString::createFromAscii( buffer );
492 : : }
493 : : else
494 [ # # ]: 0 : return ::rtl::OUString();
495 : : }
496 : :
497 : :
498 : : //_________________________________________________________________________________________________________________
499 : : // OWriteStatusBarDocumentHandler
500 : : //_________________________________________________________________________________________________________________
501 : :
502 : 0 : OWriteStatusBarDocumentHandler::OWriteStatusBarDocumentHandler(
503 : : const Reference< XIndexAccess >& aStatusBarItems,
504 : : const Reference< XDocumentHandler >& rWriteDocumentHandler ) :
505 : 0 : ThreadHelpBase( &Application::GetSolarMutex() ),
506 : : m_aStatusBarItems( aStatusBarItems ),
507 : 0 : m_xWriteDocumentHandler( rWriteDocumentHandler )
508 : : {
509 [ # # ]: 0 : ::comphelper::AttributeList* pList = new ::comphelper::AttributeList;
510 [ # # ][ # # ]: 0 : m_xEmptyList = Reference< XAttributeList >( (XAttributeList *) pList, UNO_QUERY );
[ # # ]
511 [ # # ]: 0 : m_aAttributeType = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_TYPE_CDATA ));
512 [ # # ]: 0 : m_aXMLXlinkNS = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( XMLNS_XLINK_PREFIX ));
513 [ # # ]: 0 : m_aXMLStatusBarNS = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( XMLNS_STATUSBAR_PREFIX ));
514 : 0 : }
515 : :
516 : 0 : OWriteStatusBarDocumentHandler::~OWriteStatusBarDocumentHandler()
517 : : {
518 [ # # ]: 0 : }
519 : :
520 : 0 : void OWriteStatusBarDocumentHandler::WriteStatusBarDocument() throw
521 : : ( SAXException, RuntimeException )
522 : : {
523 [ # # ]: 0 : ResetableGuard aGuard( m_aLock );
524 : :
525 [ # # ][ # # ]: 0 : m_xWriteDocumentHandler->startDocument();
526 : :
527 : : // write DOCTYPE line!
528 [ # # ]: 0 : Reference< XExtendedDocumentHandler > xExtendedDocHandler( m_xWriteDocumentHandler, UNO_QUERY );
529 [ # # ]: 0 : if ( xExtendedDocHandler.is() )
530 : : {
531 [ # # ][ # # ]: 0 : xExtendedDocHandler->unknown( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( STATUSBAR_DOCTYPE )) );
[ # # ]
532 [ # # ][ # # ]: 0 : m_xWriteDocumentHandler->ignorableWhitespace( ::rtl::OUString() );
533 : : }
534 : :
535 [ # # ]: 0 : ::comphelper::AttributeList* pList = new ::comphelper::AttributeList;
536 [ # # ][ # # ]: 0 : Reference< XAttributeList > xList( (XAttributeList *) pList , UNO_QUERY );
537 : :
538 : : pList->AddAttribute( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_XMLNS_STATUSBAR )),
539 : : m_aAttributeType,
540 [ # # ][ # # ]: 0 : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( XMLNS_STATUSBAR )) );
[ # # ]
541 : :
542 : : pList->AddAttribute( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_XMLNS_XLINK )),
543 : : m_aAttributeType,
544 [ # # ][ # # ]: 0 : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( XMLNS_XLINK )) );
[ # # ]
545 : :
546 [ # # ][ # # ]: 0 : m_xWriteDocumentHandler->startElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_STATUSBAR )), pList );
[ # # ][ # # ]
[ # # ]
547 [ # # ][ # # ]: 0 : m_xWriteDocumentHandler->ignorableWhitespace( ::rtl::OUString() );
548 : :
549 [ # # ][ # # ]: 0 : sal_Int32 nItemCount = m_aStatusBarItems->getCount();
550 : 0 : Any aAny;
551 : :
552 [ # # ]: 0 : for ( sal_Int32 nItemPos = 0; nItemPos < nItemCount; nItemPos++ )
553 : : {
554 [ # # ]: 0 : Sequence< PropertyValue > aProps;
555 [ # # ][ # # ]: 0 : aAny = m_aStatusBarItems->getByIndex( nItemPos );
556 [ # # ][ # # ]: 0 : if ( aAny >>= aProps )
557 : : {
558 : 0 : ::rtl::OUString aCommandURL;
559 : 0 : ::rtl::OUString aHelpURL;
560 : 0 : sal_Int16 nStyle( ItemStyle::ALIGN_CENTER|ItemStyle::DRAW_IN3D );
561 : 0 : sal_Int16 nWidth( 0 );
562 : 0 : sal_Int16 nOffset( STATUSBAR_OFFSET );
563 : :
564 : : ExtractStatusbarItemParameters(
565 : : aProps,
566 : : aCommandURL,
567 : : aHelpURL,
568 : : nOffset,
569 : : nStyle,
570 [ # # ][ # # ]: 0 : nWidth );
[ # # ]
571 : :
572 [ # # ]: 0 : if ( !aCommandURL.isEmpty() )
573 [ # # ]: 0 : WriteStatusBarItem( aCommandURL, aHelpURL, nOffset, nStyle, nWidth );
574 : : }
575 [ # # ]: 0 : }
576 : :
577 [ # # ][ # # ]: 0 : m_xWriteDocumentHandler->ignorableWhitespace( ::rtl::OUString() );
578 [ # # ][ # # ]: 0 : m_xWriteDocumentHandler->endElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_STATUSBAR )) );
[ # # ]
579 [ # # ][ # # ]: 0 : m_xWriteDocumentHandler->ignorableWhitespace( ::rtl::OUString() );
580 [ # # ][ # # ]: 0 : m_xWriteDocumentHandler->endDocument();
[ # # ]
581 : 0 : }
582 : :
583 : : //_________________________________________________________________________________________________________________
584 : : // protected member functions
585 : : //_________________________________________________________________________________________________________________
586 : :
587 : 0 : void OWriteStatusBarDocumentHandler::WriteStatusBarItem(
588 : : const rtl::OUString& rCommandURL,
589 : : const rtl::OUString& /*rHelpURL*/,
590 : : sal_Int16 nOffset,
591 : : sal_Int16 nStyle,
592 : : sal_Int16 nWidth )
593 : : throw ( SAXException, RuntimeException )
594 : : {
595 [ # # ]: 0 : ::comphelper::AttributeList* pList = new ::comphelper::AttributeList;
596 [ # # ][ # # ]: 0 : Reference< XAttributeList > xList( (XAttributeList *) pList , UNO_QUERY );
597 : :
598 [ # # ]: 0 : if (m_aAttributeURL.isEmpty() )
599 : : {
600 : 0 : m_aAttributeURL = m_aXMLXlinkNS;
601 [ # # ]: 0 : m_aAttributeURL += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_URL ));
602 : : }
603 : :
604 : : // save required attribute (URL)
605 [ # # ]: 0 : pList->AddAttribute( m_aAttributeURL, m_aAttributeType, rCommandURL );
606 : :
607 : : // alignment
608 [ # # ]: 0 : if ( nStyle & ItemStyle::ALIGN_RIGHT )
609 : : {
610 : : pList->AddAttribute( m_aXMLStatusBarNS + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_ALIGN )),
611 : : m_aAttributeType,
612 [ # # ][ # # ]: 0 : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_ALIGN_RIGHT )) );
[ # # ]
613 : : }
614 [ # # ]: 0 : else if ( nStyle & ItemStyle::ALIGN_CENTER )
615 : : {
616 : : pList->AddAttribute( m_aXMLStatusBarNS + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_ALIGN )),
617 : : m_aAttributeType,
618 [ # # ][ # # ]: 0 : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_ALIGN_CENTER )) );
[ # # ]
619 : : }
620 : : else
621 : : {
622 : : pList->AddAttribute( m_aXMLStatusBarNS + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_ALIGN )),
623 : : m_aAttributeType,
624 [ # # ][ # # ]: 0 : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_ALIGN_LEFT )) );
[ # # ]
625 : : }
626 : :
627 : : // style ( SIB_IN is default )
628 [ # # ]: 0 : if ( nStyle & ItemStyle::DRAW_FLAT )
629 : : {
630 : : pList->AddAttribute( m_aXMLStatusBarNS + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_STYLE )),
631 : : m_aAttributeType,
632 [ # # ][ # # ]: 0 : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_STYLE_FLAT )) );
[ # # ]
633 : : }
634 [ # # ]: 0 : else if ( nStyle & ItemStyle::DRAW_OUT3D )
635 : : {
636 : : pList->AddAttribute( m_aXMLStatusBarNS + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_STYLE )),
637 : : m_aAttributeType,
638 [ # # ][ # # ]: 0 : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_STYLE_OUT )) );
[ # # ]
639 : : }
640 : :
641 : : // autosize (default sal_False)
642 [ # # ]: 0 : if ( nStyle & ItemStyle::AUTO_SIZE )
643 : : {
644 : : pList->AddAttribute( m_aXMLStatusBarNS + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_AUTOSIZE )),
645 : : m_aAttributeType,
646 [ # # ][ # # ]: 0 : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_BOOLEAN_TRUE )) );
[ # # ]
647 : : }
648 : :
649 : : // ownerdraw (default sal_False)
650 [ # # ]: 0 : if ( nStyle & ItemStyle::OWNER_DRAW )
651 : : {
652 : : pList->AddAttribute( m_aXMLStatusBarNS + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_OWNERDRAW )),
653 : : m_aAttributeType,
654 [ # # ][ # # ]: 0 : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_BOOLEAN_TRUE )) );
[ # # ]
655 : : }
656 : :
657 : : // width (default 0)
658 [ # # ]: 0 : if ( nWidth > 0 )
659 : : {
660 : : pList->AddAttribute( m_aXMLStatusBarNS + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_WIDTH )),
661 : : m_aAttributeType,
662 [ # # ][ # # ]: 0 : ::rtl::OUString::valueOf( (sal_Int32)nWidth ) );
663 : : }
664 : :
665 : : // offset (default STATUSBAR_OFFSET)
666 [ # # ]: 0 : if ( nOffset != STATUSBAR_OFFSET )
667 : : {
668 : : pList->AddAttribute( m_aXMLStatusBarNS + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_OFFSET )),
669 : : m_aAttributeType,
670 [ # # ][ # # ]: 0 : ::rtl::OUString::valueOf( (sal_Int32)nOffset ) );
671 : : }
672 : :
673 [ # # ][ # # ]: 0 : m_xWriteDocumentHandler->ignorableWhitespace( ::rtl::OUString() );
674 [ # # ][ # # ]: 0 : m_xWriteDocumentHandler->startElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_STATUSBARITEM )), xList );
[ # # ]
675 [ # # ][ # # ]: 0 : m_xWriteDocumentHandler->ignorableWhitespace( ::rtl::OUString() );
676 [ # # ][ # # ]: 0 : m_xWriteDocumentHandler->endElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_STATUSBARITEM )) );
[ # # ]
677 : 0 : }
678 : :
679 : : } // namespace framework
680 : :
681 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|