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_xmlscript.hxx" 26 #include "imp_share.hxx" 27 28 #include <osl/diagnose.h> 29 #include <tools/diagnose_ex.h> 30 #include <osl/mutex.hxx> 31 32 #include <rtl/ustrbuf.hxx> 33 34 #include <xmlscript/xml_import.hxx> 35 #include <comphelper/processfactory.hxx> 36 37 #include <com/sun/star/awt/CharSet.hpp> 38 #include <com/sun/star/awt/FontFamily.hpp> 39 #include <com/sun/star/awt/FontPitch.hpp> 40 #include <com/sun/star/awt/FontSlant.hpp> 41 #include <com/sun/star/awt/FontStrikeout.hpp> 42 #include <com/sun/star/awt/FontType.hpp> 43 #include <com/sun/star/awt/FontUnderline.hpp> 44 #include <com/sun/star/awt/FontWeight.hpp> 45 #include <com/sun/star/awt/FontWidth.hpp> 46 #include <com/sun/star/awt/ImagePosition.hpp> 47 #include <com/sun/star/awt/LineEndFormat.hpp> 48 #include <com/sun/star/awt/PushButtonType.hpp> 49 #include <com/sun/star/awt/VisualEffect.hpp> 50 #include <com/sun/star/style/VerticalAlignment.hpp> 51 52 #include <com/sun/star/script/XScriptEventsSupplier.hpp> 53 #include <com/sun/star/script/ScriptEventDescriptor.hpp> 54 55 #include <com/sun/star/view/SelectionType.hpp> 56 57 using namespace ::com::sun::star; 58 using namespace ::com::sun::star::uno; 59 using ::rtl::OUString; 60 61 namespace xmlscript 62 { 63 64 //__________________________________________________________________________________________________ 65 void EventElement::endElement() 66 throw (xml::sax::SAXException, RuntimeException) 67 { 68 static_cast< ControlElement * >( _pParent )->_events.push_back( this ); 69 } 70 //__________________________________________________________________________________________________ 71 ControlElement::ControlElement( 72 OUString const & rLocalName, 73 Reference< xml::input::XAttributes > const & xAttributes, 74 ElementBase * pParent, DialogImport * pImport ) 75 SAL_THROW( () ) 76 : ElementBase( 77 pImport->XMLNS_DIALOGS_UID, rLocalName, xAttributes, pParent, pImport ) 78 { 79 if (_pParent) 80 { 81 // inherit position 82 _nBasePosX = static_cast< ControlElement * >( _pParent )->_nBasePosX; 83 _nBasePosY = static_cast< ControlElement * >( _pParent )->_nBasePosY; 84 } 85 else 86 { 87 _nBasePosX = 0; 88 _nBasePosY = 0; 89 } 90 } 91 92 //__________________________________________________________________________________________________ 93 Reference< xml::input::XElement > ControlElement::getStyle( 94 Reference< xml::input::XAttributes > const & xAttributes ) 95 { 96 OUString aStyleId( 97 xAttributes->getValueByUidName( 98 _pImport->XMLNS_DIALOGS_UID, 99 OUString( RTL_CONSTASCII_USTRINGPARAM("style-id") ) ) ); 100 if (aStyleId.getLength()) 101 { 102 return _pImport->getStyle( aStyleId ); 103 } 104 return Reference< xml::input::XElement >(); 105 } 106 //__________________________________________________________________________________________________ 107 OUString ControlElement::getControlId( 108 Reference< xml::input::XAttributes > const & xAttributes ) 109 { 110 OUString aId( 111 xAttributes->getValueByUidName( 112 _pImport->XMLNS_DIALOGS_UID, 113 OUString( RTL_CONSTASCII_USTRINGPARAM("id") ) ) ); 114 if (! aId.getLength()) 115 { 116 throw xml::sax::SAXException( 117 OUString( RTL_CONSTASCII_USTRINGPARAM("missing id attribute!") ), 118 Reference< XInterface >(), Any() ); 119 } 120 return aId; 121 } 122 123 //################################################################################################## 124 125 //__________________________________________________________________________________________________ 126 bool StyleElement::importTextColorStyle( 127 Reference< beans::XPropertySet > const & xProps ) 128 { 129 if ((_inited & 0x2) != 0) 130 { 131 if ((_hasValue & 0x2) != 0) 132 { 133 xProps->setPropertyValue( 134 OUString( RTL_CONSTASCII_USTRINGPARAM("TextColor") ), 135 makeAny( _textColor ) ); 136 return true; 137 } 138 return false; 139 } 140 _inited |= 0x2; 141 142 if (getLongAttr( &_textColor, 143 OUString( RTL_CONSTASCII_USTRINGPARAM("text-color") ), 144 _xAttributes, _pImport->XMLNS_DIALOGS_UID )) 145 { 146 _hasValue |= 0x2; 147 xProps->setPropertyValue( 148 OUString( RTL_CONSTASCII_USTRINGPARAM("TextColor") ), 149 makeAny( _textColor ) ); 150 return true; 151 } 152 return false; 153 } 154 //__________________________________________________________________________________________________ 155 bool StyleElement::importTextLineColorStyle( 156 Reference< beans::XPropertySet > const & xProps ) 157 { 158 if ((_inited & 0x20) != 0) 159 { 160 if ((_hasValue & 0x20) != 0) 161 { 162 xProps->setPropertyValue( 163 OUString( RTL_CONSTASCII_USTRINGPARAM("TextLineColor") ), 164 makeAny( _textLineColor ) ); 165 return true; 166 } 167 return false; 168 } 169 _inited |= 0x20; 170 171 if (getLongAttr( &_textLineColor, 172 OUString( RTL_CONSTASCII_USTRINGPARAM("textline-color") ), 173 _xAttributes, _pImport->XMLNS_DIALOGS_UID )) 174 { 175 _hasValue |= 0x20; 176 xProps->setPropertyValue( 177 OUString( RTL_CONSTASCII_USTRINGPARAM("TextLineColor") ), 178 makeAny( _textLineColor ) ); 179 return true; 180 } 181 return false; 182 } 183 //__________________________________________________________________________________________________ 184 bool StyleElement::importFillColorStyle( 185 Reference< beans::XPropertySet > const & xProps ) 186 { 187 if ((_inited & 0x10) != 0) 188 { 189 if ((_hasValue & 0x10) != 0) 190 { 191 xProps->setPropertyValue( 192 OUString( RTL_CONSTASCII_USTRINGPARAM("FillColor") ), makeAny( _fillColor ) ); 193 return true; 194 } 195 return false; 196 } 197 _inited |= 0x10; 198 199 if (getLongAttr( 200 &_fillColor, 201 OUString( RTL_CONSTASCII_USTRINGPARAM("fill-color") ), 202 _xAttributes, _pImport->XMLNS_DIALOGS_UID )) 203 { 204 _hasValue |= 0x10; 205 xProps->setPropertyValue( 206 OUString( RTL_CONSTASCII_USTRINGPARAM("FillColor") ), 207 makeAny( _fillColor ) ); 208 return true; 209 } 210 return false; 211 } 212 //__________________________________________________________________________________________________ 213 bool StyleElement::importBackgroundColorStyle( 214 Reference< beans::XPropertySet > const & xProps ) 215 { 216 if ((_inited & 0x1) != 0) 217 { 218 if ((_hasValue & 0x1) != 0) 219 { 220 xProps->setPropertyValue( 221 OUString( RTL_CONSTASCII_USTRINGPARAM("BackgroundColor") ), makeAny( _backgroundColor ) ); 222 return true; 223 } 224 return false; 225 } 226 _inited |= 0x1; 227 228 if (getLongAttr( 229 &_backgroundColor, 230 OUString( RTL_CONSTASCII_USTRINGPARAM("background-color") ), 231 _xAttributes, _pImport->XMLNS_DIALOGS_UID )) 232 { 233 _hasValue |= 0x1; 234 xProps->setPropertyValue( 235 OUString( RTL_CONSTASCII_USTRINGPARAM("BackgroundColor") ), makeAny( _backgroundColor ) ); 236 return true; 237 } 238 return false; 239 } 240 241 //__________________________________________________________________________________________________ 242 bool StyleElement::importBorderStyle( 243 Reference< beans::XPropertySet > const & xProps ) 244 { 245 if ((_inited & 0x4) != 0) 246 { 247 if ((_hasValue & 0x4) != 0) 248 { 249 xProps->setPropertyValue( 250 OUSTR("Border"), makeAny( _border == BORDER_SIMPLE_COLOR 251 ? BORDER_SIMPLE : _border ) ); 252 if (_border == BORDER_SIMPLE_COLOR) 253 xProps->setPropertyValue( OUSTR("BorderColor"), 254 makeAny(_borderColor) ); 255 return true; 256 } 257 return false; 258 } 259 _inited |= 0x4; 260 261 OUString aValue; 262 if (getStringAttr( 263 &aValue, OUSTR("border"), 264 _xAttributes, _pImport->XMLNS_DIALOGS_UID )) { 265 if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("none") )) 266 _border = BORDER_NONE; 267 else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("3d") )) 268 _border = BORDER_3D; 269 else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("simple") )) 270 _border = BORDER_SIMPLE; 271 else { 272 _border = BORDER_SIMPLE_COLOR; 273 _borderColor = toInt32(aValue); 274 } 275 276 _hasValue |= 0x4; 277 importBorderStyle(xProps); // write values 278 } 279 return false; 280 } 281 282 //______________________________________________________________________________ 283 bool StyleElement::importVisualEffectStyle( 284 Reference<beans::XPropertySet> const & xProps ) 285 { 286 if ((_inited & 0x40) != 0) 287 { 288 if ((_hasValue & 0x40) != 0) 289 { 290 xProps->setPropertyValue( OUSTR("VisualEffect"), 291 makeAny(_visualEffect) ); 292 return true; 293 } 294 return false; 295 } 296 _inited |= 0x40; 297 298 OUString aValue; 299 if (getStringAttr( &aValue, OUString( RTL_CONSTASCII_USTRINGPARAM("look") ), 300 _xAttributes, _pImport->XMLNS_DIALOGS_UID )) 301 { 302 if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("none") )) 303 { 304 _visualEffect = awt::VisualEffect::NONE; 305 } 306 else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("3d") )) 307 { 308 _visualEffect = awt::VisualEffect::LOOK3D; 309 } 310 else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("simple") )) 311 { 312 _visualEffect = awt::VisualEffect::FLAT; 313 } 314 else 315 OSL_ASSERT( 0 ); 316 317 _hasValue |= 0x40; 318 xProps->setPropertyValue( OUSTR("VisualEffect"), 319 makeAny(_visualEffect) ); 320 } 321 return false; 322 } 323 324 //__________________________________________________________________________________________________ 325 void StyleElement::setFontProperties( 326 Reference< beans::XPropertySet > const & xProps ) 327 { 328 xProps->setPropertyValue( 329 OUString( RTL_CONSTASCII_USTRINGPARAM("FontDescriptor") ), makeAny( _descr ) ); 330 xProps->setPropertyValue( 331 OUString( RTL_CONSTASCII_USTRINGPARAM("FontEmphasisMark") ), makeAny( _fontEmphasisMark ) ); 332 xProps->setPropertyValue( 333 OUString( RTL_CONSTASCII_USTRINGPARAM("FontRelief") ), makeAny( _fontRelief ) ); 334 } 335 //__________________________________________________________________________________________________ 336 bool StyleElement::importFontStyle( 337 Reference< beans::XPropertySet > const & xProps ) 338 { 339 if ((_inited & 0x8) != 0) 340 { 341 if ((_hasValue & 0x8) != 0) 342 { 343 setFontProperties( xProps ); 344 return true; 345 } 346 return false; 347 } 348 _inited |= 0x8; 349 350 OUString aValue; 351 bool bFontImport; 352 353 // dialog:font-name CDATA #IMPLIED 354 bFontImport = getStringAttr( 355 &_descr.Name, OUString( RTL_CONSTASCII_USTRINGPARAM("font-name") ), 356 _xAttributes, _pImport->XMLNS_DIALOGS_UID ); 357 358 // dialog:font-height %numeric; #IMPLIED 359 if (getStringAttr( 360 &aValue, OUString( RTL_CONSTASCII_USTRINGPARAM("font-height") ), 361 _xAttributes, _pImport->XMLNS_DIALOGS_UID )) 362 { 363 _descr.Height = (sal_Int16)toInt32( aValue ); 364 bFontImport = true; 365 } 366 // dialog:font-width %numeric; #IMPLIED 367 if (getStringAttr( 368 &aValue, OUString( RTL_CONSTASCII_USTRINGPARAM("font-width") ), 369 _xAttributes, _pImport->XMLNS_DIALOGS_UID )) 370 { 371 _descr.Width = (sal_Int16)toInt32( aValue ); 372 bFontImport = true; 373 } 374 // dialog:font-stylename CDATA #IMPLIED 375 bFontImport |= getStringAttr( 376 &_descr.StyleName, 377 OUString( RTL_CONSTASCII_USTRINGPARAM("font-stylename") ), 378 _xAttributes, _pImport->XMLNS_DIALOGS_UID ); 379 380 // dialog:font-family "(decorative|modern|roman|script|swiss|system)" #IMPLIED 381 if (getStringAttr( 382 &aValue, OUString( RTL_CONSTASCII_USTRINGPARAM("font-family") ), 383 _xAttributes, _pImport->XMLNS_DIALOGS_UID )) 384 { 385 if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("decorative") )) 386 { 387 _descr.Family = awt::FontFamily::DECORATIVE; 388 } 389 else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("modern") )) 390 { 391 _descr.Family = awt::FontFamily::MODERN; 392 } 393 else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("roman") )) 394 { 395 _descr.Family = awt::FontFamily::ROMAN; 396 } 397 else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("script") )) 398 { 399 _descr.Family = awt::FontFamily::SCRIPT; 400 } 401 else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("swiss") )) 402 { 403 _descr.Family = awt::FontFamily::SWISS; 404 } 405 else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("system") )) 406 { 407 _descr.Family = awt::FontFamily::SYSTEM; 408 } 409 else 410 { 411 throw xml::sax::SAXException( 412 OUString( RTL_CONSTASCII_USTRINGPARAM("invalid font-family style!") ), 413 Reference< XInterface >(), Any() ); 414 } 415 bFontImport = true; 416 } 417 418 // dialog:font-charset "(ansi|mac|ibmpc_437|ibmpc_850|ibmpc_860|ibmpc_861|ibmpc_863|ibmpc_865|system|symbol)" #IMPLIED 419 if (getStringAttr( 420 &aValue, OUString( RTL_CONSTASCII_USTRINGPARAM("font-charset") ), 421 _xAttributes, _pImport->XMLNS_DIALOGS_UID )) 422 { 423 if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("ansi") )) 424 { 425 _descr.CharSet = awt::CharSet::ANSI; 426 } 427 else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("mac") )) 428 { 429 _descr.CharSet = awt::CharSet::MAC; 430 } 431 else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("ibmpc_437") )) 432 { 433 _descr.CharSet = awt::CharSet::IBMPC_437; 434 } 435 else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("ibmpc_850") )) 436 { 437 _descr.CharSet = awt::CharSet::IBMPC_850; 438 } 439 else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("ibmpc_860") )) 440 { 441 _descr.CharSet = awt::CharSet::IBMPC_860; 442 } 443 else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("ibmpc_861") )) 444 { 445 _descr.CharSet = awt::CharSet::IBMPC_861; 446 } 447 else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("ibmpc_863") )) 448 { 449 _descr.CharSet = awt::CharSet::IBMPC_863; 450 } 451 else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("ibmpc_865") )) 452 { 453 _descr.CharSet = awt::CharSet::IBMPC_865; 454 } 455 else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("system") )) 456 { 457 _descr.CharSet = awt::CharSet::SYSTEM; 458 } 459 else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("symbol") )) 460 { 461 _descr.CharSet = awt::CharSet::SYMBOL; 462 } 463 else 464 { 465 throw xml::sax::SAXException( 466 OUString( RTL_CONSTASCII_USTRINGPARAM("invalid font-charset style!") ), 467 Reference< XInterface >(), Any() ); 468 } 469 bFontImport = true; 470 } 471 472 // dialog:font-pitch "(fixed|variable)" #IMPLIED 473 if (getStringAttr( 474 &aValue, OUString( RTL_CONSTASCII_USTRINGPARAM("font-pitch") ), 475 _xAttributes, _pImport->XMLNS_DIALOGS_UID )) 476 { 477 if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("fixed") )) 478 { 479 _descr.Pitch = awt::FontPitch::FIXED; 480 } 481 else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("variable") )) 482 { 483 _descr.Pitch = awt::FontPitch::VARIABLE; 484 } 485 else 486 { 487 throw xml::sax::SAXException( 488 OUString( RTL_CONSTASCII_USTRINGPARAM("invalid font-pitch style!") ), 489 Reference< XInterface >(), Any() ); 490 } 491 bFontImport = true; 492 } 493 494 // dialog:font-charwidth CDATA #IMPLIED 495 if (getStringAttr( 496 &aValue, OUString( RTL_CONSTASCII_USTRINGPARAM("font-charwidth") ), 497 _xAttributes, _pImport->XMLNS_DIALOGS_UID )) 498 { 499 _descr.CharacterWidth = aValue.toFloat(); 500 bFontImport = true; 501 } 502 // dialog:font-weight CDATA #IMPLIED 503 if (getStringAttr( 504 &aValue, OUString( RTL_CONSTASCII_USTRINGPARAM("font-weight") ), 505 _xAttributes, _pImport->XMLNS_DIALOGS_UID )) 506 { 507 _descr.Weight = aValue.toFloat(); 508 bFontImport = true; 509 } 510 511 // dialog:font-slant "(oblique|italic|reverse_oblique|reverse_italic)" #IMPLIED 512 if (getStringAttr( 513 &aValue, OUString( RTL_CONSTASCII_USTRINGPARAM("font-slant") ), 514 _xAttributes, _pImport->XMLNS_DIALOGS_UID )) 515 { 516 if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("oblique") )) 517 { 518 _descr.Slant = awt::FontSlant_OBLIQUE; 519 } 520 else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("italic") )) 521 { 522 _descr.Slant = awt::FontSlant_ITALIC; 523 } 524 else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("reverse_oblique") )) 525 { 526 _descr.Slant = awt::FontSlant_REVERSE_OBLIQUE; 527 } 528 else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("reverse_italic") )) 529 { 530 _descr.Slant = awt::FontSlant_REVERSE_ITALIC; 531 } 532 else 533 { 534 throw xml::sax::SAXException( 535 OUString( RTL_CONSTASCII_USTRINGPARAM("invalid font-slant style!") ), 536 Reference< XInterface >(), Any() ); 537 } 538 bFontImport = true; 539 } 540 541 // dialog:font-underline "(single|double|dotted|dash|longdash|dashdot|dashdotdot|smallwave|wave|doublewave|bold|bolddotted|bolddash|boldlongdash|bolddashdot|bolddashdotdot|boldwave)" #IMPLIED 542 if (getStringAttr( 543 &aValue, OUString( RTL_CONSTASCII_USTRINGPARAM("font-underline") ), 544 _xAttributes, _pImport->XMLNS_DIALOGS_UID )) 545 { 546 if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("single") )) 547 { 548 _descr.Underline = awt::FontUnderline::SINGLE; 549 } 550 else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("double") )) 551 { 552 _descr.Underline = awt::FontUnderline::DOUBLE; 553 } 554 else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("dotted") )) 555 { 556 _descr.Underline = awt::FontUnderline::DOTTED; 557 } 558 else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("dash") )) 559 { 560 _descr.Underline = awt::FontUnderline::DASH; 561 } 562 else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("longdash") )) 563 { 564 _descr.Underline = awt::FontUnderline::LONGDASH; 565 } 566 else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("dashdot") )) 567 { 568 _descr.Underline = awt::FontUnderline::DASHDOT; 569 } 570 else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("dashdotdot") )) 571 { 572 _descr.Underline = awt::FontUnderline::DASHDOTDOT; 573 } 574 else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("smallwave") )) 575 { 576 _descr.Underline = awt::FontUnderline::SMALLWAVE; 577 } 578 else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("wave") )) 579 { 580 _descr.Underline = awt::FontUnderline::WAVE; 581 } 582 else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("doublewave") )) 583 { 584 _descr.Underline = awt::FontUnderline::DOUBLEWAVE; 585 } 586 else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("bold") )) 587 { 588 _descr.Underline = awt::FontUnderline::BOLD; 589 } 590 else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("bolddotted") )) 591 { 592 _descr.Underline = awt::FontUnderline::BOLDDOTTED; 593 } 594 else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("bolddash") )) 595 { 596 _descr.Underline = awt::FontUnderline::BOLDDASH; 597 } 598 else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("boldlongdash") )) 599 { 600 _descr.Underline = awt::FontUnderline::BOLDLONGDASH; 601 } 602 else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("bolddashdot") )) 603 { 604 _descr.Underline = awt::FontUnderline::BOLDDASHDOT; 605 } 606 else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("bolddashdotdot") )) 607 { 608 _descr.Underline = awt::FontUnderline::BOLDDASHDOTDOT; 609 } 610 else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("boldwave") )) 611 { 612 _descr.Underline = awt::FontUnderline::BOLDWAVE; 613 } 614 else 615 { 616 throw xml::sax::SAXException( 617 OUString( RTL_CONSTASCII_USTRINGPARAM("invalid font-underline style!") ), 618 Reference< XInterface >(), Any() ); 619 } 620 bFontImport = true; 621 } 622 623 // dialog:font-strikeout "(single|double|bold|slash|x)" #IMPLIED 624 if (getStringAttr( 625 &aValue, OUString( RTL_CONSTASCII_USTRINGPARAM("font-strikeout") ), 626 _xAttributes, _pImport->XMLNS_DIALOGS_UID )) 627 { 628 if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("single") )) 629 { 630 _descr.Strikeout = awt::FontStrikeout::SINGLE; 631 } 632 else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("double") )) 633 { 634 _descr.Strikeout = awt::FontStrikeout::DOUBLE; 635 } 636 else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("bold") )) 637 { 638 _descr.Strikeout = awt::FontStrikeout::BOLD; 639 } 640 else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("slash") )) 641 { 642 _descr.Strikeout = awt::FontStrikeout::SLASH; 643 } 644 else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("x") )) 645 { 646 _descr.Strikeout = awt::FontStrikeout::X; 647 } 648 else 649 { 650 throw xml::sax::SAXException( 651 OUString( RTL_CONSTASCII_USTRINGPARAM("invalid font-strikeout style!") ), 652 Reference< XInterface >(), Any() ); 653 } 654 bFontImport = true; 655 } 656 657 // dialog:font-orientation CDATA #IMPLIED 658 if (getStringAttr( 659 &aValue, 660 OUString( RTL_CONSTASCII_USTRINGPARAM("font-orientation") ), 661 _xAttributes, _pImport->XMLNS_DIALOGS_UID )) 662 { 663 _descr.Orientation = aValue.toFloat(); 664 bFontImport = true; 665 } 666 // dialog:font-kerning %boolean; #IMPLIED 667 bFontImport |= getBoolAttr( 668 &_descr.Kerning, 669 OUString( RTL_CONSTASCII_USTRINGPARAM("font-kerning") ), 670 _xAttributes, _pImport->XMLNS_DIALOGS_UID ); 671 // dialog:font-wordlinemode %boolean; #IMPLIED 672 bFontImport |= getBoolAttr( 673 &_descr.WordLineMode, 674 OUString( RTL_CONSTASCII_USTRINGPARAM("font-wordlinemode") ), 675 _xAttributes, _pImport->XMLNS_DIALOGS_UID ); 676 677 // dialog:font-type "(raster|device|scalable)" #IMPLIED 678 if (getStringAttr( 679 &aValue, OUString( RTL_CONSTASCII_USTRINGPARAM("font-type") ), 680 _xAttributes, _pImport->XMLNS_DIALOGS_UID )) 681 { 682 if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("raster") )) 683 { 684 _descr.Type = awt::FontType::RASTER; 685 } 686 else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("device") )) 687 { 688 _descr.Type = awt::FontType::DEVICE; 689 } 690 else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("scalable") )) 691 { 692 _descr.Type = awt::FontType::SCALABLE; 693 } 694 else 695 { 696 throw xml::sax::SAXException( 697 OUString( RTL_CONSTASCII_USTRINGPARAM("invalid font-type style!") ), 698 Reference< XInterface >(), Any() ); 699 } 700 bFontImport = true; 701 } 702 703 // additional properties which are not part of the FontDescriptor struct 704 // dialog:font-relief (none|embossed|engraved) #IMPLIED 705 if (getStringAttr( 706 &aValue, OUString( RTL_CONSTASCII_USTRINGPARAM("font-relief") ), 707 _xAttributes, _pImport->XMLNS_DIALOGS_UID )) 708 { 709 if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("none") )) 710 { 711 _fontRelief = awt::FontRelief::NONE; 712 } 713 else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("embossed") )) 714 { 715 _fontRelief = awt::FontRelief::EMBOSSED; 716 } 717 else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("engraved") )) 718 { 719 _fontRelief = awt::FontRelief::ENGRAVED; 720 } 721 else 722 { 723 throw xml::sax::SAXException( 724 OUString( RTL_CONSTASCII_USTRINGPARAM("invalid font-relief style!") ), 725 Reference< XInterface >(), Any() ); 726 } 727 bFontImport = true; 728 } 729 // dialog:font-emphasismark (none|dot|circle|disc|accent|above|below) #IMPLIED 730 if (getStringAttr( 731 &aValue, 732 OUString( RTL_CONSTASCII_USTRINGPARAM("font-emphasismark") ), 733 _xAttributes, _pImport->XMLNS_DIALOGS_UID )) 734 { 735 if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("none") )) 736 { 737 _fontEmphasisMark = awt::FontEmphasisMark::NONE; 738 } 739 else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("dot") )) 740 { 741 _fontEmphasisMark = awt::FontEmphasisMark::DOT; 742 } 743 else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("circle") )) 744 { 745 _fontEmphasisMark = awt::FontEmphasisMark::CIRCLE; 746 } 747 else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("disc") )) 748 { 749 _fontEmphasisMark = awt::FontEmphasisMark::DISC; 750 } 751 else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("accent") )) 752 { 753 _fontEmphasisMark = awt::FontEmphasisMark::ACCENT; 754 } 755 else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("above") )) 756 { 757 _fontEmphasisMark = awt::FontEmphasisMark::ABOVE; 758 } 759 else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("below") )) 760 { 761 _fontEmphasisMark = awt::FontEmphasisMark::BELOW; 762 } 763 else 764 { 765 throw xml::sax::SAXException( 766 OUString( RTL_CONSTASCII_USTRINGPARAM("invalid font-emphasismark style!") ), 767 Reference< XInterface >(), Any() ); 768 } 769 bFontImport = true; 770 } 771 772 // ================================================== 773 if (bFontImport) 774 { 775 _hasValue |= 0x8; 776 setFontProperties( xProps ); 777 } 778 779 return bFontImport; 780 } 781 782 //################################################################################################## 783 784 //__________________________________________________________________________________________________ 785 bool ImportContext::importStringProperty( 786 OUString const & rPropName, OUString const & rAttrName, 787 Reference< xml::input::XAttributes > const & xAttributes ) 788 { 789 OUString aValue( 790 xAttributes->getValueByUidName( 791 _pImport->XMLNS_DIALOGS_UID, rAttrName ) ); 792 if (aValue.getLength()) 793 { 794 _xControlModel->setPropertyValue( rPropName, makeAny( aValue ) ); 795 return true; 796 } 797 return false; 798 } 799 //__________________________________________________________________________________________________ 800 bool ImportContext::importDoubleProperty( 801 OUString const & rPropName, OUString const & rAttrName, 802 Reference< xml::input::XAttributes > const & xAttributes ) 803 { 804 OUString aValue( 805 xAttributes->getValueByUidName( 806 _pImport->XMLNS_DIALOGS_UID, rAttrName ) ); 807 if (aValue.getLength()) 808 { 809 _xControlModel->setPropertyValue( rPropName, makeAny( aValue.toDouble() ) ); 810 return true; 811 } 812 return false; 813 } 814 //__________________________________________________________________________________________________ 815 bool ImportContext::importBooleanProperty( 816 OUString const & rPropName, OUString const & rAttrName, 817 Reference< xml::input::XAttributes > const & xAttributes ) 818 { 819 sal_Bool bBool; 820 if (getBoolAttr( 821 &bBool, rAttrName, xAttributes, _pImport->XMLNS_DIALOGS_UID )) 822 { 823 _xControlModel->setPropertyValue( rPropName, makeAny( bBool ) ); 824 return true; 825 } 826 return false; 827 } 828 //__________________________________________________________________________________________________ 829 bool ImportContext::importLongProperty( 830 OUString const & rPropName, OUString const & rAttrName, 831 Reference< xml::input::XAttributes > const & xAttributes ) 832 { 833 OUString aValue( 834 xAttributes->getValueByUidName( 835 _pImport->XMLNS_DIALOGS_UID, rAttrName ) ); 836 if (aValue.getLength()) 837 { 838 _xControlModel->setPropertyValue( rPropName, makeAny( toInt32( aValue ) ) ); 839 return true; 840 } 841 return false; 842 } 843 //__________________________________________________________________________________________________ 844 bool ImportContext::importLongProperty( 845 sal_Int32 nOffset, 846 OUString const & rPropName, OUString const & rAttrName, 847 Reference< xml::input::XAttributes > const & xAttributes ) 848 { 849 OUString aValue( 850 xAttributes->getValueByUidName( 851 _pImport->XMLNS_DIALOGS_UID, rAttrName ) ); 852 if (aValue.getLength()) 853 { 854 _xControlModel->setPropertyValue( rPropName, makeAny( toInt32( aValue ) + nOffset ) ); 855 return true; 856 } 857 return false; 858 } 859 //__________________________________________________________________________________________________ 860 bool ImportContext::importHexLongProperty( 861 OUString const & rPropName, OUString const & rAttrName, 862 Reference< xml::input::XAttributes > const & xAttributes ) 863 { 864 OUString aValue( 865 xAttributes->getValueByUidName( 866 _pImport->XMLNS_DIALOGS_UID, rAttrName ) ); 867 if (aValue.getLength()) 868 { 869 _xControlModel->setPropertyValue( rPropName, makeAny( toInt32( aValue ) ) ); 870 return true; 871 } 872 return false; 873 } 874 //__________________________________________________________________________________________________ 875 bool ImportContext::importShortProperty( 876 OUString const & rPropName, OUString const & rAttrName, 877 Reference< xml::input::XAttributes > const & xAttributes ) 878 { 879 OUString aValue( 880 xAttributes->getValueByUidName( 881 _pImport->XMLNS_DIALOGS_UID, rAttrName ) ); 882 if (aValue.getLength()) 883 { 884 _xControlModel->setPropertyValue( rPropName, makeAny( (sal_Int16)toInt32( aValue ) ) ); 885 return true; 886 } 887 return false; 888 } 889 //__________________________________________________________________________________________________ 890 bool ImportContext::importAlignProperty( 891 OUString const & rPropName, OUString const & rAttrName, 892 Reference< xml::input::XAttributes > const & xAttributes ) 893 { 894 OUString aAlign( 895 xAttributes->getValueByUidName( 896 _pImport->XMLNS_DIALOGS_UID, rAttrName ) ); 897 if (aAlign.getLength()) 898 { 899 sal_Int16 nAlign; 900 if (aAlign.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("left") )) 901 { 902 nAlign = 0; 903 } 904 else if (aAlign.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("center") )) 905 { 906 nAlign = 1; 907 } 908 else if (aAlign.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("right") )) 909 { 910 nAlign = 2; 911 } 912 else if (aAlign.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("none") )) 913 { 914 nAlign = 0; // default 915 } 916 else 917 { 918 throw xml::sax::SAXException( 919 OUString( RTL_CONSTASCII_USTRINGPARAM("invalid align value!") ), 920 Reference< XInterface >(), Any() ); 921 } 922 923 _xControlModel->setPropertyValue( rPropName, makeAny( nAlign ) ); 924 return true; 925 } 926 return false; 927 } 928 //__________________________________________________________________________________________________ 929 bool ImportContext::importVerticalAlignProperty( 930 OUString const & rPropName, OUString const & rAttrName, 931 Reference< xml::input::XAttributes > const & xAttributes ) 932 { 933 OUString aAlign( 934 xAttributes->getValueByUidName( 935 _pImport->XMLNS_DIALOGS_UID, rAttrName ) ); 936 if (aAlign.getLength()) 937 { 938 style::VerticalAlignment eAlign; 939 940 if (aAlign.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("top") )) 941 { 942 eAlign = style::VerticalAlignment_TOP; 943 } 944 else if (aAlign.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("center") )) 945 { 946 eAlign = style::VerticalAlignment_MIDDLE; 947 } 948 else if (aAlign.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("bottom") )) 949 { 950 eAlign = style::VerticalAlignment_BOTTOM; 951 } 952 else 953 { 954 throw xml::sax::SAXException( 955 OUString( RTL_CONSTASCII_USTRINGPARAM("invalid vertical align value!") ), 956 Reference< XInterface >(), Any() ); 957 } 958 959 _xControlModel->setPropertyValue( rPropName, makeAny( eAlign ) ); 960 return true; 961 } 962 return false; 963 } 964 //__________________________________________________________________________________________________ 965 bool ImportContext::importImageAlignProperty( 966 OUString const & rPropName, OUString const & rAttrName, 967 Reference< xml::input::XAttributes > const & xAttributes ) 968 { 969 OUString aAlign( 970 xAttributes->getValueByUidName( 971 _pImport->XMLNS_DIALOGS_UID, rAttrName ) ); 972 if (aAlign.getLength()) 973 { 974 sal_Int16 nAlign; 975 if (aAlign.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("left") )) 976 { 977 nAlign = 0; 978 } 979 else if (aAlign.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("top") )) 980 { 981 nAlign = 1; 982 } 983 else if (aAlign.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("right") )) 984 { 985 nAlign = 2; 986 } 987 else if (aAlign.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("bottom") )) 988 { 989 nAlign = 3; 990 } 991 else 992 { 993 throw xml::sax::SAXException( 994 OUString( RTL_CONSTASCII_USTRINGPARAM("invalid image align value!") ), 995 Reference< XInterface >(), Any() ); 996 } 997 998 _xControlModel->setPropertyValue( rPropName, makeAny( nAlign ) ); 999 return true; 1000 } 1001 return false; 1002 } 1003 //__________________________________________________________________________________________________ 1004 bool ImportContext::importImagePositionProperty( 1005 OUString const & rPropName, OUString const & rAttrName, 1006 Reference< xml::input::XAttributes > const & xAttributes ) 1007 { 1008 OUString aPosition( 1009 xAttributes->getValueByUidName( 1010 _pImport->XMLNS_DIALOGS_UID, rAttrName ) ); 1011 if (aPosition.getLength()) 1012 { 1013 sal_Int16 nPosition; 1014 if (aPosition.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("left-top") )) 1015 { 1016 nPosition = awt::ImagePosition::LeftTop; 1017 } 1018 else if (aPosition.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("left-center") )) 1019 { 1020 nPosition = awt::ImagePosition::LeftCenter; 1021 } 1022 else if (aPosition.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("left-bottom") )) 1023 { 1024 nPosition = awt::ImagePosition::LeftBottom; 1025 } 1026 else if (aPosition.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("right-top") )) 1027 { 1028 nPosition = awt::ImagePosition::RightTop; 1029 } 1030 else if (aPosition.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("right-center") )) 1031 { 1032 nPosition = awt::ImagePosition::RightCenter; 1033 } 1034 else if (aPosition.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("right-bottom") )) 1035 { 1036 nPosition = awt::ImagePosition::RightBottom; 1037 } 1038 else if (aPosition.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("top-left") )) 1039 { 1040 nPosition = awt::ImagePosition::AboveLeft; 1041 } 1042 else if (aPosition.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("top-center") )) 1043 { 1044 nPosition = awt::ImagePosition::AboveCenter; 1045 } 1046 else if (aPosition.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("top-right") )) 1047 { 1048 nPosition = awt::ImagePosition::AboveRight; 1049 } 1050 else if (aPosition.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("bottom-left") )) 1051 { 1052 nPosition = awt::ImagePosition::BelowLeft; 1053 } 1054 else if (aPosition.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("bottom-center") )) 1055 { 1056 nPosition = awt::ImagePosition::BelowCenter; 1057 } 1058 else if (aPosition.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("bottom-right") )) 1059 { 1060 nPosition = awt::ImagePosition::BelowRight; 1061 } 1062 else if (aPosition.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("center") )) 1063 { 1064 nPosition = awt::ImagePosition::Centered; 1065 } 1066 else 1067 { 1068 throw xml::sax::SAXException( 1069 OUString( RTL_CONSTASCII_USTRINGPARAM("invalid image position value!") ), 1070 Reference< XInterface >(), Any() ); 1071 } 1072 1073 _xControlModel->setPropertyValue( rPropName, makeAny( nPosition ) ); 1074 return true; 1075 } 1076 return false; 1077 } 1078 //__________________________________________________________________________________________________ 1079 bool ImportContext::importButtonTypeProperty( 1080 OUString const & rPropName, OUString const & rAttrName, 1081 Reference< xml::input::XAttributes > const & xAttributes ) 1082 { 1083 OUString buttonType( 1084 xAttributes->getValueByUidName( 1085 _pImport->XMLNS_DIALOGS_UID, rAttrName ) ); 1086 if (buttonType.getLength()) 1087 { 1088 sal_Int16 nButtonType; 1089 if (buttonType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("standard") )) 1090 { 1091 nButtonType = awt::PushButtonType_STANDARD; 1092 } 1093 else if (buttonType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("ok") )) 1094 { 1095 nButtonType = awt::PushButtonType_OK; 1096 } 1097 else if (buttonType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("cancel") )) 1098 { 1099 nButtonType = awt::PushButtonType_CANCEL; 1100 } 1101 else if (buttonType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("help") )) 1102 { 1103 nButtonType = awt::PushButtonType_HELP; 1104 } 1105 else 1106 { 1107 throw xml::sax::SAXException( 1108 OUString( RTL_CONSTASCII_USTRINGPARAM("invalid button-type value!") ), 1109 Reference< XInterface >(), Any() ); 1110 } 1111 1112 _xControlModel->setPropertyValue( rPropName, makeAny( nButtonType ) ); 1113 return true; 1114 } 1115 return false; 1116 } 1117 //__________________________________________________________________________________________________ 1118 bool ImportContext::importDateFormatProperty( 1119 OUString const & rPropName, OUString const & rAttrName, 1120 Reference< xml::input::XAttributes > const & xAttributes ) 1121 { 1122 OUString aFormat( 1123 xAttributes->getValueByUidName( 1124 _pImport->XMLNS_DIALOGS_UID, rAttrName ) ); 1125 if (aFormat.getLength()) 1126 { 1127 sal_Int16 nFormat; 1128 if (aFormat.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("system_short") )) 1129 { 1130 nFormat = 0; 1131 } 1132 else if (aFormat.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("system_short_YY") )) 1133 { 1134 nFormat = 1; 1135 } 1136 else if (aFormat.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("system_short_YYYY") )) 1137 { 1138 nFormat = 2; 1139 } 1140 else if (aFormat.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("system_long") )) 1141 { 1142 nFormat = 3; 1143 } 1144 else if (aFormat.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("short_DDMMYY") )) 1145 { 1146 nFormat = 4; 1147 } 1148 else if (aFormat.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("short_MMDDYY") )) 1149 { 1150 nFormat = 5; 1151 } 1152 else if (aFormat.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("short_YYMMDD") )) 1153 { 1154 nFormat = 6; 1155 } 1156 else if (aFormat.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("short_DDMMYYYY") )) 1157 { 1158 nFormat = 7; 1159 } 1160 else if (aFormat.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("short_MMDDYYYY") )) 1161 { 1162 nFormat = 8; 1163 } 1164 else if (aFormat.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("short_YYYYMMDD") )) 1165 { 1166 nFormat = 9; 1167 } 1168 else if (aFormat.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("short_YYMMDD_DIN5008") )) 1169 { 1170 nFormat = 10; 1171 } 1172 else if (aFormat.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("short_YYYYMMDD_DIN5008") )) 1173 { 1174 nFormat = 11; 1175 } 1176 else 1177 { 1178 throw xml::sax::SAXException( 1179 OUString( RTL_CONSTASCII_USTRINGPARAM("invalid date-format value!") ), 1180 Reference< XInterface >(), Any() ); 1181 } 1182 1183 _xControlModel->setPropertyValue( rPropName, makeAny( nFormat ) ); 1184 return true; 1185 } 1186 return false; 1187 } 1188 //__________________________________________________________________________________________________ 1189 bool ImportContext::importTimeFormatProperty( 1190 OUString const & rPropName, OUString const & rAttrName, 1191 Reference< xml::input::XAttributes > const & xAttributes ) 1192 { 1193 OUString aFormat( 1194 xAttributes->getValueByUidName( 1195 _pImport->XMLNS_DIALOGS_UID, rAttrName ) ); 1196 if (aFormat.getLength()) 1197 { 1198 sal_Int16 nFormat; 1199 if (aFormat.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("24h_short") )) 1200 { 1201 nFormat = 0; 1202 } 1203 else if (aFormat.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("24h_long") )) 1204 { 1205 nFormat = 1; 1206 } 1207 else if (aFormat.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("12h_short") )) 1208 { 1209 nFormat = 2; 1210 } 1211 else if (aFormat.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("12h_long") )) 1212 { 1213 nFormat = 3; 1214 } 1215 else if (aFormat.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("Duration_short") )) 1216 { 1217 nFormat = 4; 1218 } 1219 else if (aFormat.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("Duration_long") )) 1220 { 1221 nFormat = 5; 1222 } 1223 else 1224 { 1225 throw xml::sax::SAXException( 1226 OUString( RTL_CONSTASCII_USTRINGPARAM("invalid time-format value!") ), 1227 Reference< XInterface >(), Any() ); 1228 } 1229 1230 _xControlModel->setPropertyValue( rPropName, makeAny( nFormat ) ); 1231 return true; 1232 } 1233 return false; 1234 } 1235 //__________________________________________________________________________________________________ 1236 bool ImportContext::importOrientationProperty( 1237 OUString const & rPropName, OUString const & rAttrName, 1238 Reference< xml::input::XAttributes > const & xAttributes ) 1239 { 1240 OUString aOrient( 1241 xAttributes->getValueByUidName( 1242 _pImport->XMLNS_DIALOGS_UID, rAttrName ) ); 1243 if (aOrient.getLength()) 1244 { 1245 sal_Int32 nOrient; 1246 if (aOrient.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("horizontal") )) 1247 { 1248 nOrient = 0; 1249 } 1250 else if (aOrient.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("vertical") )) 1251 { 1252 nOrient = 1; 1253 } 1254 else 1255 { 1256 throw xml::sax::SAXException( 1257 OUString( RTL_CONSTASCII_USTRINGPARAM("invalid orientation value!") ), 1258 Reference< XInterface >(), Any() ); 1259 } 1260 1261 _xControlModel->setPropertyValue( rPropName, makeAny( nOrient ) ); 1262 return true; 1263 } 1264 return false; 1265 } 1266 //__________________________________________________________________________________________________ 1267 bool ImportContext::importLineEndFormatProperty( 1268 OUString const & rPropName, OUString const & rAttrName, 1269 Reference< xml::input::XAttributes > const & xAttributes ) 1270 { 1271 OUString aFormat( 1272 xAttributes->getValueByUidName( 1273 _pImport->XMLNS_DIALOGS_UID, rAttrName ) ); 1274 if (aFormat.getLength()) 1275 { 1276 sal_Int16 nFormat; 1277 if (aFormat.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("carriage-return") )) 1278 { 1279 nFormat = awt::LineEndFormat::CARRIAGE_RETURN; 1280 } 1281 else if (aFormat.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("line-feed") )) 1282 { 1283 nFormat = awt::LineEndFormat::LINE_FEED; 1284 } 1285 else if (aFormat.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("carriage-return-line-feed") )) 1286 { 1287 nFormat = awt::LineEndFormat::CARRIAGE_RETURN_LINE_FEED; 1288 } 1289 else 1290 { 1291 throw xml::sax::SAXException( 1292 OUString( RTL_CONSTASCII_USTRINGPARAM("invalid line end format value!") ), 1293 Reference< XInterface >(), Any() ); 1294 } 1295 1296 _xControlModel->setPropertyValue( rPropName, makeAny( nFormat ) ); 1297 return true; 1298 } 1299 return false; 1300 } 1301 //__________________________________________________________________________________________________ 1302 bool ImportContext::importSelectionTypeProperty( 1303 OUString const & rPropName, OUString const & rAttrName, 1304 Reference< xml::input::XAttributes > const & xAttributes ) 1305 { 1306 OUString aSelectionType( 1307 xAttributes->getValueByUidName( 1308 _pImport->XMLNS_DIALOGS_UID, rAttrName ) ); 1309 if (aSelectionType.getLength()) 1310 { 1311 view::SelectionType eSelectionType; 1312 1313 if (aSelectionType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("none") )) 1314 { 1315 eSelectionType = view::SelectionType_NONE; 1316 } 1317 else if (aSelectionType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("single") )) 1318 { 1319 eSelectionType = view::SelectionType_SINGLE; 1320 } 1321 else if (aSelectionType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("multi") )) 1322 { 1323 eSelectionType = view::SelectionType_MULTI; 1324 } 1325 else if (aSelectionType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("range") )) 1326 { 1327 eSelectionType = view::SelectionType_RANGE; 1328 } 1329 else 1330 { 1331 throw xml::sax::SAXException( 1332 OUString( RTL_CONSTASCII_USTRINGPARAM("invalid selection type value!") ), 1333 Reference< XInterface >(), Any() ); 1334 } 1335 1336 _xControlModel->setPropertyValue( rPropName, makeAny( eSelectionType ) ); 1337 return true; 1338 } 1339 return false; 1340 } 1341 1342 //================================================================================================== 1343 struct StringTriple 1344 { 1345 char const * first; 1346 char const * second; 1347 char const * third; 1348 }; 1349 static StringTriple const s_aEventTranslations[] = 1350 { 1351 // from xmloff/source/forms/formevents.cxx 1352 // 28.09.2001 tbe added on-adjustmentvaluechange 1353 { "com.sun.star.form.XApproveActionListener", "approveAction", "on-approveaction" }, 1354 { "com.sun.star.awt.XActionListener", "actionPerformed", "on-performaction" }, 1355 { "com.sun.star.form.XChangeListener", "changed", "on-change" }, 1356 { "com.sun.star.awt.XTextListener", "textChanged", "on-textchange" }, 1357 { "com.sun.star.awt.XItemListener", "itemStateChanged", "on-itemstatechange" }, 1358 { "com.sun.star.awt.XFocusListener", "focusGained", "on-focus" }, 1359 { "com.sun.star.awt.XFocusListener", "focusLost", "on-blur" }, 1360 { "com.sun.star.awt.XKeyListener", "keyPressed", "on-keydown" }, 1361 { "com.sun.star.awt.XKeyListener", "keyReleased", "on-keyup" }, 1362 { "com.sun.star.awt.XMouseListener", "mouseEntered", "on-mouseover" }, 1363 { "com.sun.star.awt.XMouseMotionListener", "mouseDragged", "on-mousedrag" }, 1364 { "com.sun.star.awt.XMouseMotionListener", "mouseMoved", "on-mousemove" }, 1365 { "com.sun.star.awt.XMouseListener", "mousePressed", "on-mousedown" }, 1366 { "com.sun.star.awt.XMouseListener", "mouseReleased", "on-mouseup" }, 1367 { "com.sun.star.awt.XMouseListener", "mouseExited", "on-mouseout" }, 1368 { "com.sun.star.form.XResetListener", "approveReset", "on-approvereset" }, 1369 { "com.sun.star.form.XResetListener", "resetted", "on-reset" }, 1370 { "com.sun.star.form.XSubmitListener", "approveSubmit", "on-submit" }, 1371 { "com.sun.star.form.XUpdateListener", "approveUpdate", "on-approveupdate" }, 1372 { "com.sun.star.form.XUpdateListener", "updated", "on-update" }, 1373 { "com.sun.star.form.XLoadListener", "loaded", "on-load" }, 1374 { "com.sun.star.form.XLoadListener", "reloading", "on-startreload" }, 1375 { "com.sun.star.form.XLoadListener", "reloaded", "on-reload" }, 1376 { "com.sun.star.form.XLoadListener", "unloading", "on-startunload" }, 1377 { "com.sun.star.form.XLoadListener", "unloaded", "on-unload" }, 1378 { "com.sun.star.form.XConfirmDeleteListener", "confirmDelete", "on-confirmdelete" }, 1379 { "com.sun.star.sdb.XRowSetApproveListener", "approveRowChange", "on-approverowchange" }, 1380 { "com.sun.star.sdbc.XRowSetListener", "rowChanged", "on-rowchange" }, 1381 { "com.sun.star.sdb.XRowSetApproveListener", "approveCursorMove", "on-approvecursormove" }, 1382 { "com.sun.star.sdbc.XRowSetListener", "cursorMoved", "on-cursormove" }, 1383 { "com.sun.star.form.XDatabaseParameterListener", "approveParameter", "on-supplyparameter" }, 1384 { "com.sun.star.sdb.XSQLErrorListener", "errorOccured", "on-error" }, 1385 { "com.sun.star.awt.XAdjustmentListener", "adjustmentValueChanged", "on-adjustmentvaluechange" }, 1386 { 0, 0, 0 } 1387 }; 1388 extern StringTriple const * const g_pEventTranslations; 1389 StringTriple const * const g_pEventTranslations = s_aEventTranslations; 1390 1391 //__________________________________________________________________________________________________ 1392 void ImportContext::importEvents( 1393 ::std::vector< Reference< xml::input::XElement > > const & rEvents ) 1394 { 1395 Reference< script::XScriptEventsSupplier > xSupplier( 1396 _xControlModel, UNO_QUERY ); 1397 if (xSupplier.is()) 1398 { 1399 Reference< container::XNameContainer > xEvents( xSupplier->getEvents() ); 1400 if (xEvents.is()) 1401 { 1402 for ( size_t nPos = 0; nPos < rEvents.size(); ++nPos ) 1403 { 1404 script::ScriptEventDescriptor descr; 1405 1406 EventElement * pEventElement = static_cast< EventElement * >( rEvents[ nPos ].get() ); 1407 sal_Int32 nUid = pEventElement->getUid(); 1408 OUString aLocalName( pEventElement->getLocalName() ); 1409 Reference< xml::input::XAttributes > xAttributes( 1410 pEventElement->getAttributes() ); 1411 1412 // nowadays script events 1413 if (_pImport->XMLNS_SCRIPT_UID == nUid) 1414 { 1415 if (!getStringAttr( &descr.ScriptType, 1416 OUString( RTL_CONSTASCII_USTRINGPARAM( 1417 "language") ), 1418 xAttributes, 1419 _pImport->XMLNS_SCRIPT_UID ) || 1420 !getStringAttr( &descr.ScriptCode, 1421 OUString( RTL_CONSTASCII_USTRINGPARAM( 1422 "macro-name") ), 1423 xAttributes, 1424 _pImport->XMLNS_SCRIPT_UID )) 1425 { 1426 throw xml::sax::SAXException( 1427 OUString( RTL_CONSTASCII_USTRINGPARAM( 1428 "missing language or macro-name " 1429 "attribute(s) of event!") ), 1430 Reference< XInterface >(), Any() ); 1431 } 1432 if ( descr.ScriptType.equals( OUString( RTL_CONSTASCII_USTRINGPARAM( "StarBasic" ) ) ) ) 1433 { 1434 OUString aLocation; 1435 if (getStringAttr( &aLocation, 1436 OUString( RTL_CONSTASCII_USTRINGPARAM( 1437 "location") ), 1438 xAttributes, 1439 _pImport->XMLNS_SCRIPT_UID )) 1440 { 1441 // prepend location 1442 ::rtl::OUStringBuffer buf; 1443 buf.append( aLocation ); 1444 buf.append( (sal_Unicode)':' ); 1445 buf.append( descr.ScriptCode ); 1446 descr.ScriptCode = buf.makeStringAndClear(); 1447 } 1448 } 1449 else if ( descr.ScriptType.equals( OUString( RTL_CONSTASCII_USTRINGPARAM( "Script" ) ) ) ) 1450 { 1451 // Check if there is a protocol, if not assume 1452 // this is an early scripting framework url ( without 1453 // the protocol ) and fix it up!! 1454 if ( descr.ScriptCode.indexOf( ':' ) == -1 ) 1455 { 1456 ::rtl::OUStringBuffer buf; 1457 buf.append( OUString( RTL_CONSTASCII_USTRINGPARAM( "vnd.sun.star.script:" ) ) ); 1458 buf.append( descr.ScriptCode ); 1459 descr.ScriptCode = buf.makeStringAndClear(); 1460 } 1461 } 1462 1463 // script:event element 1464 if (aLocalName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("event") )) 1465 { 1466 OUString aEventName; 1467 if (! getStringAttr( 1468 &aEventName, 1469 OUString( 1470 RTL_CONSTASCII_USTRINGPARAM("event-name") ), 1471 xAttributes, 1472 _pImport->XMLNS_SCRIPT_UID )) 1473 { 1474 throw xml::sax::SAXException( 1475 OUString( 1476 RTL_CONSTASCII_USTRINGPARAM( 1477 "missing event-name attribute!") ), 1478 Reference< XInterface >(), Any() ); 1479 } 1480 1481 // lookup in table 1482 ::rtl::OString str( 1483 ::rtl::OUStringToOString( 1484 aEventName, RTL_TEXTENCODING_ASCII_US ) ); 1485 StringTriple const * p = g_pEventTranslations; 1486 while (p->first) 1487 { 1488 if (0 == ::rtl_str_compare( p->third, str.getStr() )) 1489 { 1490 descr.ListenerType = OUString( 1491 p->first, ::rtl_str_getLength( p->first ), 1492 RTL_TEXTENCODING_ASCII_US ); 1493 descr.EventMethod = OUString( 1494 p->second, ::rtl_str_getLength( p->second ), 1495 RTL_TEXTENCODING_ASCII_US ); 1496 break; 1497 } 1498 ++p; 1499 } 1500 1501 if (! p->first) 1502 { 1503 throw xml::sax::SAXException( 1504 OUString( RTL_CONSTASCII_USTRINGPARAM("no matching event-name found!") ), 1505 Reference< XInterface >(), Any() ); 1506 } 1507 } 1508 else // script:listener-event element 1509 { 1510 OSL_ASSERT( aLocalName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("listener-event") ) ); 1511 1512 if (!getStringAttr( 1513 &descr.ListenerType, 1514 OUString( RTL_CONSTASCII_USTRINGPARAM( 1515 "listener-type") ), 1516 xAttributes, 1517 _pImport->XMLNS_SCRIPT_UID ) || 1518 !getStringAttr( 1519 &descr.EventMethod, 1520 OUString( RTL_CONSTASCII_USTRINGPARAM( 1521 "listener-method") ), 1522 xAttributes, _pImport->XMLNS_SCRIPT_UID )) 1523 { 1524 throw xml::sax::SAXException( 1525 OUString( 1526 RTL_CONSTASCII_USTRINGPARAM( 1527 "missing listener-type or " 1528 "listener-method attribute(s)!") ), 1529 Reference< XInterface >(), Any() ); 1530 } 1531 // optional listener param 1532 getStringAttr( 1533 &descr.AddListenerParam, 1534 OUString( RTL_CONSTASCII_USTRINGPARAM( 1535 "listener-param") ), 1536 xAttributes, _pImport->XMLNS_SCRIPT_UID ); 1537 } 1538 } 1539 else // deprecated dlg:event element 1540 { 1541 OSL_ASSERT( 1542 _pImport->XMLNS_DIALOGS_UID == nUid && 1543 aLocalName.equalsAsciiL( 1544 RTL_CONSTASCII_STRINGPARAM("event") ) ); 1545 1546 if (!getStringAttr( &descr.ListenerType, 1547 OUString( RTL_CONSTASCII_USTRINGPARAM( 1548 "listener-type") ), 1549 xAttributes, 1550 _pImport->XMLNS_DIALOGS_UID ) || 1551 !getStringAttr( &descr.EventMethod, 1552 OUString( RTL_CONSTASCII_USTRINGPARAM( 1553 "event-method") ), 1554 xAttributes, 1555 _pImport->XMLNS_DIALOGS_UID )) 1556 { 1557 throw xml::sax::SAXException( 1558 OUString( RTL_CONSTASCII_USTRINGPARAM("missing listener-type or event-method attribute(s)!") ), 1559 Reference< XInterface >(), Any() ); 1560 } 1561 1562 getStringAttr( 1563 &descr.ScriptType, 1564 OUString( RTL_CONSTASCII_USTRINGPARAM("script-type") ), 1565 xAttributes, _pImport->XMLNS_DIALOGS_UID ); 1566 getStringAttr( 1567 &descr.ScriptCode, 1568 OUString( RTL_CONSTASCII_USTRINGPARAM("script-code") ), 1569 xAttributes, _pImport->XMLNS_DIALOGS_UID ); 1570 getStringAttr( 1571 &descr.AddListenerParam, 1572 OUString( RTL_CONSTASCII_USTRINGPARAM("param") ), 1573 xAttributes, _pImport->XMLNS_DIALOGS_UID ); 1574 } 1575 1576 ::rtl::OUStringBuffer buf; 1577 buf.append( descr.ListenerType ); 1578 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("::") ); 1579 buf.append( descr.EventMethod ); 1580 xEvents->insertByName( buf.makeStringAndClear(), makeAny( descr ) ); 1581 } 1582 } 1583 } 1584 } 1585 //__________________________________________________________________________________________________ 1586 void ImportContext::importDefaults( 1587 sal_Int32 nBaseX, sal_Int32 nBaseY, 1588 Reference< xml::input::XAttributes > const & xAttributes, 1589 bool supportPrintable ) 1590 { 1591 _xControlModel->setPropertyValue( 1592 OUString( RTL_CONSTASCII_USTRINGPARAM("Name") ), 1593 makeAny( _aId ) ); 1594 1595 importShortProperty( OUString( RTL_CONSTASCII_USTRINGPARAM("TabIndex") ), 1596 OUString( RTL_CONSTASCII_USTRINGPARAM("tab-index") ), 1597 xAttributes ); 1598 1599 sal_Bool bDisable = sal_False; 1600 if (getBoolAttr( 1601 &bDisable, OUString( RTL_CONSTASCII_USTRINGPARAM("disabled") ), 1602 xAttributes, _pImport->XMLNS_DIALOGS_UID ) && 1603 bDisable) 1604 { 1605 _xControlModel->setPropertyValue( 1606 OUString( RTL_CONSTASCII_USTRINGPARAM("Enabled") ), makeAny( sal_False ) ); 1607 } 1608 1609 sal_Bool bVisible = sal_True; 1610 if (getBoolAttr( 1611 &bVisible, OUString( RTL_CONSTASCII_USTRINGPARAM("visible") ), 1612 xAttributes, _pImport->XMLNS_DIALOGS_UID ) && !bVisible) 1613 { 1614 try 1615 { 1616 1617 _xControlModel->setPropertyValue( 1618 OUString( RTL_CONSTASCII_USTRINGPARAM("EnableVisible") ), makeAny( sal_False ) ); 1619 } 1620 catch( Exception& ) 1621 { 1622 DBG_UNHANDLED_EXCEPTION(); 1623 } 1624 } 1625 1626 if (!importLongProperty( nBaseX, 1627 OUString( RTL_CONSTASCII_USTRINGPARAM("PositionX") ), 1628 OUString( RTL_CONSTASCII_USTRINGPARAM("left") ), 1629 xAttributes ) || 1630 !importLongProperty( nBaseY, 1631 OUString( RTL_CONSTASCII_USTRINGPARAM("PositionY") ), 1632 OUString( RTL_CONSTASCII_USTRINGPARAM("top") ), 1633 xAttributes ) || 1634 !importLongProperty( OUString( RTL_CONSTASCII_USTRINGPARAM("Width") ), 1635 OUString( RTL_CONSTASCII_USTRINGPARAM("width") ), 1636 xAttributes ) || 1637 !importLongProperty( OUString( RTL_CONSTASCII_USTRINGPARAM("Height") ), 1638 OUString( RTL_CONSTASCII_USTRINGPARAM("height") ), 1639 xAttributes )) 1640 { 1641 throw xml::sax::SAXException( 1642 OUString( RTL_CONSTASCII_USTRINGPARAM("missing pos size attribute(s)!") ), 1643 Reference< XInterface >(), Any() ); 1644 } 1645 1646 if (supportPrintable) 1647 { 1648 importBooleanProperty( 1649 OUString( RTL_CONSTASCII_USTRINGPARAM("Printable") ), 1650 OUString( RTL_CONSTASCII_USTRINGPARAM("printable") ), 1651 xAttributes ); 1652 } 1653 1654 sal_Int32 nLong; 1655 if (! getLongAttr( 1656 &nLong, 1657 OUString( RTL_CONSTASCII_USTRINGPARAM("page") ), 1658 xAttributes, _pImport->XMLNS_DIALOGS_UID )) 1659 { 1660 nLong = 0; 1661 } 1662 _xControlModel->setPropertyValue( 1663 OUString( RTL_CONSTASCII_USTRINGPARAM("Step") ), 1664 makeAny( nLong ) ); 1665 1666 importStringProperty( OUString( RTL_CONSTASCII_USTRINGPARAM("Tag") ), 1667 OUString( RTL_CONSTASCII_USTRINGPARAM("tag") ), 1668 xAttributes ); 1669 importStringProperty( OUString( RTL_CONSTASCII_USTRINGPARAM("HelpText") ), 1670 OUString( RTL_CONSTASCII_USTRINGPARAM("help-text") ), 1671 xAttributes ); 1672 importStringProperty( OUString( RTL_CONSTASCII_USTRINGPARAM("HelpURL") ), 1673 OUString( RTL_CONSTASCII_USTRINGPARAM("help-url") ), 1674 xAttributes ); 1675 } 1676 1677 //################################################################################################## 1678 1679 //__________________________________________________________________________________________________ 1680 Reference< xml::input::XElement > ElementBase::getParent() 1681 throw (RuntimeException) 1682 { 1683 return static_cast< xml::input::XElement * >( _pParent ); 1684 } 1685 //__________________________________________________________________________________________________ 1686 OUString ElementBase::getLocalName() 1687 throw (RuntimeException) 1688 { 1689 return _aLocalName; 1690 } 1691 //__________________________________________________________________________________________________ 1692 sal_Int32 ElementBase::getUid() 1693 throw (RuntimeException) 1694 { 1695 return _nUid; 1696 } 1697 //__________________________________________________________________________________________________ 1698 Reference< xml::input::XAttributes > ElementBase::getAttributes() 1699 throw (RuntimeException) 1700 { 1701 return _xAttributes; 1702 } 1703 //__________________________________________________________________________________________________ 1704 void ElementBase::ignorableWhitespace( 1705 OUString const & /*rWhitespaces*/ ) 1706 throw (xml::sax::SAXException, RuntimeException) 1707 { 1708 // not used 1709 } 1710 //__________________________________________________________________________________________________ 1711 void ElementBase::characters( OUString const & /*rChars*/ ) 1712 throw (xml::sax::SAXException, RuntimeException) 1713 { 1714 // not used, all characters ignored 1715 } 1716 //__________________________________________________________________________________________________ 1717 void ElementBase::endElement() 1718 throw (xml::sax::SAXException, RuntimeException) 1719 { 1720 } 1721 //______________________________________________________________________________ 1722 void ElementBase::processingInstruction( 1723 OUString const & /*Target*/, OUString const & /*Data*/ ) 1724 throw (xml::sax::SAXException, RuntimeException) 1725 { 1726 } 1727 //__________________________________________________________________________________________________ 1728 Reference< xml::input::XElement > ElementBase::startChildElement( 1729 sal_Int32 /*nUid*/, OUString const & /*rLocalName*/, 1730 Reference< xml::input::XAttributes > const & /*xAttributes*/ ) 1731 throw (xml::sax::SAXException, RuntimeException) 1732 { 1733 throw xml::sax::SAXException( 1734 OUString( RTL_CONSTASCII_USTRINGPARAM("unexpected element!") ), 1735 Reference< XInterface >(), Any() ); 1736 } 1737 1738 //__________________________________________________________________________________________________ 1739 ElementBase::ElementBase( 1740 sal_Int32 nUid, OUString const & rLocalName, 1741 Reference< xml::input::XAttributes > const & xAttributes, 1742 ElementBase * pParent, DialogImport * pImport ) 1743 SAL_THROW( () ) 1744 : _pImport( pImport ) 1745 , _pParent( pParent ) 1746 , _nUid( nUid ) 1747 , _aLocalName( rLocalName ) 1748 , _xAttributes( xAttributes ) 1749 { 1750 _pImport->acquire(); 1751 1752 if (_pParent) 1753 { 1754 _pParent->acquire(); 1755 } 1756 } 1757 //__________________________________________________________________________________________________ 1758 ElementBase::~ElementBase() 1759 SAL_THROW( () ) 1760 { 1761 _pImport->release(); 1762 1763 if (_pParent) 1764 { 1765 _pParent->release(); 1766 } 1767 1768 #if OSL_DEBUG_LEVEL > 1 1769 ::rtl::OString aStr( ::rtl::OUStringToOString( 1770 _aLocalName, RTL_TEXTENCODING_ASCII_US ) ); 1771 OSL_TRACE( "ElementBase::~ElementBase(): %s\n", aStr.getStr() ); 1772 #endif 1773 } 1774 1775 //################################################################################################## 1776 1777 // XRoot 1778 // 1779 1780 //______________________________________________________________________________ 1781 void DialogImport::startDocument( 1782 Reference< xml::input::XNamespaceMapping > const & xNamespaceMapping ) 1783 throw (xml::sax::SAXException, RuntimeException) 1784 { 1785 XMLNS_DIALOGS_UID = xNamespaceMapping->getUidByUri( 1786 OUSTR(XMLNS_DIALOGS_URI) ); 1787 XMLNS_SCRIPT_UID = xNamespaceMapping->getUidByUri( 1788 OUSTR(XMLNS_SCRIPT_URI) ); 1789 } 1790 //__________________________________________________________________________________________________ 1791 void DialogImport::endDocument() 1792 throw (xml::sax::SAXException, RuntimeException) 1793 { 1794 // ignored 1795 } 1796 //__________________________________________________________________________________________________ 1797 void DialogImport::processingInstruction( 1798 OUString const & /*rTarget*/, OUString const & /*rData*/ ) 1799 throw (xml::sax::SAXException, RuntimeException) 1800 { 1801 // ignored for now: xxx todo 1802 } 1803 //__________________________________________________________________________________________________ 1804 void DialogImport::setDocumentLocator( 1805 Reference< xml::sax::XLocator > const & /*xLocator*/ ) 1806 throw (xml::sax::SAXException, RuntimeException) 1807 { 1808 // ignored for now: xxx todo 1809 } 1810 //__________________________________________________________________________________________________ 1811 Reference< xml::input::XElement > DialogImport::startRootElement( 1812 sal_Int32 nUid, OUString const & rLocalName, 1813 Reference< xml::input::XAttributes > const & xAttributes ) 1814 throw (xml::sax::SAXException, RuntimeException) 1815 { 1816 if (XMLNS_DIALOGS_UID != nUid) 1817 { 1818 throw xml::sax::SAXException( 1819 OUString( RTL_CONSTASCII_USTRINGPARAM("illegal namespace!") ), 1820 Reference< XInterface >(), Any() ); 1821 } 1822 // window 1823 else if (rLocalName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("window") )) 1824 { 1825 return new WindowElement( rLocalName, xAttributes, 0, this ); 1826 } 1827 else 1828 { 1829 throw xml::sax::SAXException( 1830 OUString( RTL_CONSTASCII_USTRINGPARAM( 1831 "illegal root element (expected window) given: ") ) + 1832 rLocalName, Reference< XInterface >(), Any() ); 1833 } 1834 } 1835 //__________________________________________________________________________________________________ 1836 DialogImport::~DialogImport() 1837 SAL_THROW( () ) 1838 { 1839 #if OSL_DEBUG_LEVEL > 1 1840 OSL_TRACE( "DialogImport::~DialogImport().\n" ); 1841 #endif 1842 } 1843 //__________________________________________________________________________________________________ 1844 Reference< util::XNumberFormatsSupplier > const & DialogImport::getNumberFormatsSupplier() 1845 { 1846 if (! _xSupplier.is()) 1847 { 1848 Reference< XComponentContext > xContext( getComponentContext() ); 1849 Reference< util::XNumberFormatsSupplier > xSupplier( 1850 xContext->getServiceManager()->createInstanceWithContext( 1851 OUString( RTL_CONSTASCII_USTRINGPARAM( 1852 "com.sun.star.util.NumberFormatsSupplier") ), 1853 xContext ), UNO_QUERY ); 1854 1855 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); 1856 if (! _xSupplier.is()) 1857 { 1858 _xSupplier = xSupplier; 1859 } 1860 } 1861 return _xSupplier; 1862 } 1863 1864 //__________________________________________________________________________________________________ 1865 void DialogImport::addStyle( 1866 OUString const & rStyleId, 1867 Reference< xml::input::XElement > const & xStyle ) 1868 SAL_THROW( () ) 1869 { 1870 _styleNames.push_back( rStyleId ); 1871 _styles.push_back( xStyle ); 1872 } 1873 //__________________________________________________________________________________________________ 1874 Reference< xml::input::XElement > DialogImport::getStyle( 1875 OUString const & rStyleId ) const 1876 SAL_THROW( () ) 1877 { 1878 for ( size_t nPos = 0; nPos < _styleNames.size(); ++nPos ) 1879 { 1880 if (_styleNames[ nPos ] == rStyleId) 1881 { 1882 return _styles[ nPos ]; 1883 } 1884 } 1885 return 0; 1886 } 1887 1888 //################################################################################################## 1889 1890 //================================================================================================== 1891 Reference< xml::sax::XDocumentHandler > SAL_CALL importDialogModel( 1892 Reference< container::XNameContainer > const & xDialogModel, 1893 Reference< XComponentContext > const & xContext ) 1894 SAL_THROW( (Exception) ) 1895 { 1896 return ::xmlscript::createDocumentHandler( 1897 static_cast< xml::input::XRoot * >( 1898 new DialogImport( xContext, xDialogModel ) ) ); 1899 } 1900 1901 } 1902