1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_sw.hxx" 30 31 #include <cmdid.h> 32 #include <hintids.hxx> 33 #include <svl/stritem.hxx> 34 #include <com/sun/star/lang/XMultiServiceFactory.hpp> 35 #include <com/sun/star/container/XNameAccess.hpp> 36 #include <com/sun/star/text/XDefaultNumberingProvider.hpp> 37 #include <com/sun/star/text/XNumberingTypeInfo.hpp> 38 #include <com/sun/star/style/NumberingType.hpp> 39 #include <com/sun/star/beans/XPropertySet.hpp> 40 #include <com/sun/star/sdbc/XConnection.hpp> 41 #include <com/sun/star/sdbc/XDataSource.hpp> 42 #include <com/sun/star/uri/XUriReferenceFactory.hpp> 43 #include <com/sun/star/uri/XVndSunStarScriptUrl.hpp> 44 #include <comphelper/processfactory.hxx> 45 #include <editeng/unolingu.hxx> 46 #include <unotools/localedatawrapper.hxx> 47 #include <sfx2/dispatch.hxx> 48 #include <sfx2/objsh.hxx> 49 #include <sfx2/linkmgr.hxx> 50 #include <sfx2/app.hxx> 51 #include <basic/basmgr.hxx> 52 #include <editeng/langitem.hxx> 53 #include <svl/macitem.hxx> 54 #include <basic/sbmod.hxx> 55 #include <fmtrfmrk.hxx> 56 #include <basic/sbmeth.hxx> 57 #include <basic/sbx.hxx> 58 #include <svl/zforlist.hxx> 59 #include <svl/zformat.hxx> 60 #include <vcl/mnemonic.hxx> 61 #include <view.hxx> 62 #include <wrtsh.hxx> // Actives Fenster 63 #include <doc.hxx> // Actives Fenster 64 #include <docsh.hxx> // Actives Fenster 65 #include <swmodule.hxx> 66 #include <charatr.hxx> 67 #include <fmtinfmt.hxx> 68 #include <cellatr.hxx> 69 #include <dbmgr.hxx> 70 #include <shellres.hxx> 71 #include <fldbas.hxx> 72 #include <docufld.hxx> 73 #include <chpfld.hxx> 74 #include <ddefld.hxx> 75 #include <expfld.hxx> 76 #include <reffld.hxx> 77 #include <usrfld.hxx> 78 #include <dbfld.hxx> 79 #include <authfld.hxx> 80 #include <flddat.hxx> 81 #include <fldmgr.hxx> 82 #include <crsskip.hxx> 83 #include <flddropdown.hxx> 84 #include <fldui.hrc> 85 #include <tox.hxx> 86 87 using rtl::OUString; 88 using namespace com::sun::star::uno; 89 using namespace com::sun::star::container; 90 using namespace com::sun::star::lang; 91 using namespace com::sun::star::beans; 92 using namespace com::sun::star::text; 93 using namespace com::sun::star::style; 94 using namespace com::sun::star::sdbc; 95 using namespace ::com::sun::star; 96 using namespace nsSwDocInfoSubType; 97 98 /*-------------------------------------------------------------------- 99 Beschreibung: Gruppen der Felder 100 --------------------------------------------------------------------*/ 101 enum 102 { 103 GRP_DOC_BEGIN = 0, 104 GRP_DOC_END = GRP_DOC_BEGIN + 11, 105 106 GRP_FKT_BEGIN = GRP_DOC_END, 107 GRP_FKT_END = GRP_FKT_BEGIN + 8, 108 109 GRP_REF_BEGIN = GRP_FKT_END, 110 GRP_REF_END = GRP_REF_BEGIN + 2, 111 112 GRP_REG_BEGIN = GRP_REF_END, 113 GRP_REG_END = GRP_REG_BEGIN + 1, 114 115 GRP_DB_BEGIN = GRP_REG_END, 116 GRP_DB_END = GRP_DB_BEGIN + 5, 117 118 GRP_VAR_BEGIN = GRP_DB_END, 119 GRP_VAR_END = GRP_VAR_BEGIN + 9 120 }; 121 122 enum 123 { 124 GRP_WEB_DOC_BEGIN = 0, 125 GRP_WEB_DOC_END = GRP_WEB_DOC_BEGIN + 9, 126 127 GRP_WEB_FKT_BEGIN = GRP_WEB_DOC_END + 2, 128 GRP_WEB_FKT_END = GRP_WEB_FKT_BEGIN + 0, // Die Gruppe ist leer! 129 130 GRP_WEB_REF_BEGIN = GRP_WEB_FKT_END + 6, // Die Gruppe ist leer! 131 GRP_WEB_REF_END = GRP_WEB_REF_BEGIN + 0, 132 133 GRP_WEB_REG_BEGIN = GRP_WEB_REF_END + 2, 134 GRP_WEB_REG_END = GRP_WEB_REG_BEGIN + 1, 135 136 GRP_WEB_DB_BEGIN = GRP_WEB_REG_END, // Die Gruppe ist leer! 137 GRP_WEB_DB_END = GRP_WEB_DB_BEGIN + 0, 138 139 GRP_WEB_VAR_BEGIN = GRP_WEB_DB_END + 5, 140 GRP_WEB_VAR_END = GRP_WEB_VAR_BEGIN + 1 141 }; 142 143 /*-------------------------------------------------------------------- 144 Beschreibung: Formate in der richtigen Reihenfolge 145 --------------------------------------------------------------------*/ 146 static const sal_uInt16 __FAR_DATA aSetFmt[] = 147 { 148 // die Reihenfolge muss zu Beginn mit den ResourceIds fuer FMT_SETVAR_??? 149 // uebereinstimmen 150 0, 151 0 152 }; 153 154 static const sal_uInt16 __FAR_DATA aGetFmt[] = 155 { 156 // die Reihenfolge muss zu Beginn mit den ResourceIds fuer FMT_GETVAR_??? 157 // uebereinstimmen 158 0 159 }; 160 161 static const sal_uInt16 __FAR_DATA aUsrFmt[] = 162 { 163 // die Reihenfolge muss zu Beginn mit den ResourceIds fuer FMT_SETVAR_??? 164 // uebereinstimmen 165 0, 166 nsSwExtendedSubType::SUB_CMD 167 }; 168 169 static const sal_uInt16 __FAR_DATA aDBFmt[] = 170 { 171 // die Reihenfolge muss zu Beginn mit den ResourceIds fuer FMT_DBFLD_??? 172 // uebereinstimmen 173 nsSwExtendedSubType::SUB_OWN_FMT 174 }; 175 176 static const sal_uInt16 VF_COUNT = sizeof(aGetFmt) / sizeof(sal_uInt16); 177 static const sal_uInt16 VF_USR_COUNT = sizeof(aUsrFmt) / sizeof(sal_uInt16); 178 static const sal_uInt16 VF_DB_COUNT = sizeof(aDBFmt) / sizeof(sal_uInt16); 179 180 /*-------------------------------------------------------------------- 181 Beschreibung: Feldtypen und Subtypes 182 --------------------------------------------------------------------*/ 183 struct SwFldPack 184 { 185 sal_uInt16 nTypeId; 186 187 sal_uInt16 nSubTypeStart; 188 sal_uInt16 nSubTypeEnd; 189 190 sal_uLong nFmtBegin; 191 sal_uLong nFmtEnd; 192 }; 193 194 /*-------------------------------------------------------------------- 195 Beschreibung: Strings und Formate 196 --------------------------------------------------------------------*/ 197 static const SwFldPack __FAR_DATA aSwFlds[] = 198 { 199 // Dokument 200 { TYP_EXTUSERFLD, FLD_EU_BEGIN, FLD_EU_END, 0, 0 }, 201 { TYP_AUTHORFLD, 0, 0, FMT_AUTHOR_BEGIN, FMT_AUTHOR_END }, 202 { TYP_DATEFLD, FLD_DATE_BEGIN, FLD_DATE_END, 0, 0 }, 203 { TYP_TIMEFLD, FLD_TIME_BEGIN, FLD_TIME_END, 0, 0 }, 204 { TYP_PAGENUMBERFLD, 0, 0, FMT_NUM_BEGIN, FMT_NUM_END-1 }, 205 { TYP_NEXTPAGEFLD, 0, 0, FMT_NUM_BEGIN, FMT_NUM_END }, 206 { TYP_PREVPAGEFLD, 0, 0, FMT_NUM_BEGIN, FMT_NUM_END }, 207 { TYP_FILENAMEFLD, 0, 0, FMT_FF_BEGIN, FMT_FF_END }, 208 { TYP_DOCSTATFLD, FLD_STAT_BEGIN, FLD_STAT_END, FMT_NUM_BEGIN, FMT_NUM_END-1 }, 209 210 { TYP_CHAPTERFLD, 0, 0, FMT_CHAPTER_BEGIN, FMT_CHAPTER_END }, 211 { TYP_TEMPLNAMEFLD, 0, 0, FMT_FF_BEGIN, FMT_FF_END }, 212 213 // Funktion 214 { TYP_CONDTXTFLD, 0, 0, 0, 0 }, 215 { TYP_DROPDOWN, 0, 0, 0, 0 }, 216 { TYP_INPUTFLD, FLD_INPUT_BEGIN, FLD_INPUT_END, 0, 0 }, 217 { TYP_MACROFLD, 0, 0, 0, 0 }, 218 { TYP_JUMPEDITFLD, 0, 0, FMT_MARK_BEGIN, FMT_MARK_END }, 219 { TYP_COMBINED_CHARS, 0, 0, 0, 0 }, 220 { TYP_HIDDENTXTFLD, 0, 0, 0, 0 }, 221 { TYP_HIDDENPARAFLD, 0, 0, 0, 0 }, 222 223 // Referenzen 224 { TYP_SETREFFLD, 0, 0, 0, 0 }, 225 { TYP_GETREFFLD, 0, 0, FMT_REF_BEGIN, FMT_REF_END }, 226 227 // Ablage 228 { TYP_DOCINFOFLD, 0, 0, FMT_REG_BEGIN, FMT_REG_END }, 229 230 // Datenbank 231 { TYP_DBFLD, 0, 0, FMT_DBFLD_BEGIN, FMT_DBFLD_END }, 232 { TYP_DBNEXTSETFLD, 0, 0, 0, 0 }, 233 { TYP_DBNUMSETFLD, 0, 0, 0, 0 }, 234 { TYP_DBSETNUMBERFLD, 0, 0, FMT_NUM_BEGIN, FMT_NUM_END-2 }, 235 { TYP_DBNAMEFLD, 0, 0, 0, 0 }, 236 237 // Variablen 238 { TYP_SETFLD, 0, 0, FMT_SETVAR_BEGIN, FMT_SETVAR_END }, 239 240 { TYP_GETFLD, 0, 0, FMT_GETVAR_BEGIN, FMT_GETVAR_END }, 241 { TYP_DDEFLD, 0, 0, FMT_DDE_BEGIN, FMT_DDE_END }, 242 { TYP_FORMELFLD, 0, 0, FMT_GETVAR_BEGIN, FMT_GETVAR_END }, 243 { TYP_INPUTFLD, FLD_INPUT_BEGIN, FLD_INPUT_END, 0, 0 }, 244 { TYP_SEQFLD, 0, 0, FMT_NUM_BEGIN, FMT_NUM_END-2 }, 245 { TYP_SETREFPAGEFLD, FLD_PAGEREF_BEGIN, FLD_PAGEREF_END,0, 0 }, 246 { TYP_GETREFPAGEFLD, 0, 0, FMT_NUM_BEGIN, FMT_NUM_END-1 }, 247 { TYP_USERFLD, 0, 0, FMT_USERVAR_BEGIN, FMT_USERVAR_END } 248 }; 249 250 /*-------------------------------------------------------------------- 251 Beschreibung: Zugriff auf die Shell 252 --------------------------------------------------------------------*/ 253 254 static SwWrtShell* lcl_GetShell() 255 { 256 SwView* pView; 257 if ( 0 != (pView = ::GetActiveView()) ) 258 return pView->GetWrtShellPtr(); 259 DBG_ERROR("no current shell found!"); 260 return 0; 261 } 262 263 inline sal_uInt16 GetPackCount() { return sizeof(aSwFlds) / sizeof(SwFldPack); } 264 265 /*-------------------------------------------------------------------- 266 Beschreibung: FieldManager regelt das Einfuegen und Updaten 267 von Feldern 268 --------------------------------------------------------------------*/ 269 270 SwFldMgr::SwFldMgr(SwWrtShell* pSh ) : 271 pModule(0), 272 pMacroItem(0), 273 pWrtShell(pSh), 274 bEvalExp(sal_True) 275 { 276 // aktuelles Feld ermitteln falls vorhanden 277 GetCurFld(); 278 } 279 280 281 SwFldMgr::~SwFldMgr() 282 { 283 } 284 285 /*-------------------------------------------------------------------- 286 Beschreibung: RefMark ueber Namen organisieren 287 --------------------------------------------------------------------*/ 288 289 sal_Bool SwFldMgr::CanInsertRefMark( const String& rStr ) 290 { 291 sal_Bool bRet = sal_False; 292 SwWrtShell *pSh = pWrtShell ? pWrtShell : lcl_GetShell(); 293 DBG_ASSERT(pSh, "no SwWrtShell found"); 294 if(pSh) 295 { 296 sal_uInt16 nCnt = pSh->GetCrsrCnt(); 297 298 // der letzte Crsr muss keine aufgespannte Selektion 299 if( 1 < nCnt && !pSh->SwCrsrShell::HasSelection() ) 300 --nCnt; 301 302 bRet = 2 > nCnt && 0 == pSh->GetRefMark( rStr ); 303 } 304 return bRet; 305 } 306 307 /*-------------------------------------------------------------------- 308 Beschreibung: Zugriff ueber ResIds 309 --------------------------------------------------------------------*/ 310 311 void SwFldMgr::RemoveFldType(sal_uInt16 nResId, const String& rName ) 312 { 313 SwWrtShell * pSh = pWrtShell ? pWrtShell : lcl_GetShell(); 314 DBG_ASSERT(pSh, "no SwWrtShell found"); 315 if( pSh ) 316 pSh->RemoveFldType(nResId, rName); 317 } 318 319 sal_uInt16 SwFldMgr::GetFldTypeCount(sal_uInt16 nResId) const 320 { 321 SwWrtShell * pSh = pWrtShell ? pWrtShell : lcl_GetShell(); 322 DBG_ASSERT(pSh, "no SwWrtShell found"); 323 return pSh ? pSh->GetFldTypeCount(nResId) : 0; 324 } 325 326 327 SwFieldType* SwFldMgr::GetFldType(sal_uInt16 nResId, sal_uInt16 nId) const 328 { 329 SwWrtShell * pSh = pWrtShell ? pWrtShell : lcl_GetShell(); 330 DBG_ASSERT(pSh, "no SwWrtShell found"); 331 return pSh ? pSh->GetFldType(nId, nResId) : 0; 332 } 333 334 335 SwFieldType* SwFldMgr::GetFldType(sal_uInt16 nResId, const String& rName) const 336 { 337 SwWrtShell * pSh = pWrtShell ? pWrtShell : lcl_GetShell(); 338 DBG_ASSERT(pSh, "no SwWrtShell found"); 339 return pSh ? pSh->GetFldType(nResId, rName) : 0; 340 } 341 342 343 /*-------------------------------------------------------------------- 344 Beschreibung: Aktuelles Feld ermitteln 345 --------------------------------------------------------------------*/ 346 SwField* SwFldMgr::GetCurFld() 347 { 348 SwWrtShell *pSh = pWrtShell ? pWrtShell : ::lcl_GetShell(); 349 if ( pSh ) 350 pCurFld = pSh->GetCurFld(); 351 else 352 pCurFld = NULL; 353 354 // Strings und Format initialisieren 355 // 356 aCurPar1.Erase(); 357 aCurPar2.Erase(); 358 sCurFrame.Erase(); 359 nCurFmt = 0; 360 361 if(!pCurFld) 362 return 0; 363 364 // Aktuelle Werte aufbereiten Parameter 1 und Parameter 2 365 // als auch das Format ermitteln 366 // 367 const sal_uInt16 nTypeId = pCurFld->GetTypeId(); 368 369 nCurFmt = pCurFld->GetFormat(); 370 aCurPar1 = pCurFld->GetPar1(); 371 aCurPar2 = pCurFld->GetPar2(); 372 373 switch( nTypeId ) 374 { 375 case TYP_PAGENUMBERFLD: 376 case TYP_NEXTPAGEFLD: 377 case TYP_PREVPAGEFLD: 378 case TYP_GETREFPAGEFLD: 379 if( nCurFmt == SVX_NUM_PAGEDESC ) 380 nCurFmt -= 2; 381 break; 382 } 383 return pCurFld; 384 } 385 386 /*-------------------------------------------------------------------- 387 Beschreibung: Gruppen-Bereich liefern 388 --------------------------------------------------------------------*/ 389 390 391 const SwFldGroupRgn& SwFldMgr::GetGroupRange(sal_Bool bHtmlMode, sal_uInt16 nGrpId) const 392 { 393 static SwFldGroupRgn __READONLY_DATA aRanges[] = 394 { 395 { /* Dokument */ GRP_DOC_BEGIN, GRP_DOC_END }, 396 { /* Funktionen */ GRP_FKT_BEGIN, GRP_FKT_END }, 397 { /* Referenzen */ GRP_REF_BEGIN, GRP_REF_END }, 398 { /* Ablage */ GRP_REG_BEGIN, GRP_REG_END }, 399 { /* DB */ GRP_DB_BEGIN, GRP_DB_END }, 400 { /* User */ GRP_VAR_BEGIN, GRP_VAR_END } 401 }; 402 static SwFldGroupRgn __READONLY_DATA aWebRanges[] = 403 { 404 { /* Dokument */ GRP_WEB_DOC_BEGIN, GRP_WEB_DOC_END }, 405 { /* Funktionen */ GRP_WEB_FKT_BEGIN, GRP_WEB_FKT_END }, 406 { /* Referenzen */ GRP_WEB_REF_BEGIN, GRP_WEB_REF_END }, 407 { /* Ablage */ GRP_WEB_REG_BEGIN, GRP_WEB_REG_END }, 408 { /* DB */ GRP_WEB_DB_BEGIN, GRP_WEB_DB_END }, 409 { /* User */ GRP_WEB_VAR_BEGIN, GRP_WEB_VAR_END } 410 }; 411 412 if (bHtmlMode) 413 return aWebRanges[(sal_uInt16)nGrpId]; 414 else 415 return aRanges[(sal_uInt16)nGrpId]; 416 } 417 418 /*-------------------------------------------------------------------- 419 Beschreibung: GroupId bestimmen 420 --------------------------------------------------------------------*/ 421 422 sal_uInt16 SwFldMgr::GetGroup(sal_Bool bHtmlMode, sal_uInt16 nTypeId, sal_uInt16 nSubType) const 423 { 424 if (nTypeId == TYP_SETINPFLD) 425 nTypeId = TYP_SETFLD; 426 427 if (nTypeId == TYP_INPUTFLD && (nSubType & INP_USR)) 428 nTypeId = TYP_USERFLD; 429 430 if (nTypeId == TYP_FIXDATEFLD) 431 nTypeId = TYP_DATEFLD; 432 433 if (nTypeId == TYP_FIXTIMEFLD) 434 nTypeId = TYP_TIMEFLD; 435 436 for (sal_uInt16 i = GRP_DOC; i <= GRP_VAR; i++) 437 { 438 const SwFldGroupRgn& rRange = GetGroupRange(bHtmlMode, i); 439 for (sal_uInt16 nPos = rRange.nStart; nPos < rRange.nEnd; nPos++) 440 { 441 if (aSwFlds[nPos].nTypeId == nTypeId) 442 return i; 443 } 444 } 445 return USHRT_MAX; 446 } 447 448 /*-------------------------------------------------------------------- 449 Beschreibung: Namen zur TypeId ermitteln 450 ZUGRIFF ueber TYP_.... 451 --------------------------------------------------------------------*/ 452 453 454 sal_uInt16 SwFldMgr::GetTypeId(sal_uInt16 nPos) 455 { 456 ASSERT(nPos < ::GetPackCount(), "unzulaessige Pos"); 457 return aSwFlds[ nPos ].nTypeId; 458 } 459 460 461 const String& SwFldMgr::GetTypeStr(sal_uInt16 nPos) 462 { 463 ASSERT(nPos < ::GetPackCount(), "unzulaessige TypeId"); 464 465 sal_uInt16 nFldWh = aSwFlds[ nPos ].nTypeId; 466 467 // Sonderbehandlung fuer Datum/Zeit Felder (ohne var/fix) 468 if( TYP_DATEFLD == nFldWh ) 469 { 470 static String g_aDate( SW_RES( STR_DATEFLD ) ); 471 return g_aDate; 472 } 473 if( TYP_TIMEFLD == nFldWh ) 474 { 475 static String g_aTime( SW_RES( STR_TIMEFLD ) ); 476 return g_aTime; 477 } 478 479 return SwFieldType::GetTypeStr( nFldWh ); 480 } 481 482 /*-------------------------------------------------------------------- 483 Beschreibung: Pos in der Liste bestimmen 484 --------------------------------------------------------------------*/ 485 486 487 sal_uInt16 SwFldMgr::GetPos(sal_uInt16 nTypeId) 488 { 489 switch( nTypeId ) 490 { 491 case TYP_FIXDATEFLD: nTypeId = TYP_DATEFLD; break; 492 case TYP_FIXTIMEFLD: nTypeId = TYP_TIMEFLD; break; 493 case TYP_SETINPFLD: nTypeId = TYP_SETFLD; break; 494 case TYP_USRINPFLD: nTypeId = TYP_USERFLD; break; 495 } 496 497 for(sal_uInt16 i = 0; i < GetPackCount(); i++) 498 if(aSwFlds[i].nTypeId == nTypeId) 499 return i; 500 501 return USHRT_MAX; 502 } 503 504 /*-------------------------------------------------------------------- 505 Beschreibung: Subtypen eines Feldes lokalisieren 506 --------------------------------------------------------------------*/ 507 508 sal_Bool SwFldMgr::GetSubTypes(sal_uInt16 nTypeId, SvStringsDtor& rToFill) 509 { 510 sal_Bool bRet = sal_False; 511 SwWrtShell *pSh = pWrtShell ? pWrtShell : lcl_GetShell(); 512 DBG_ASSERT(pSh, "no SwWrtShell found"); 513 if(pSh) 514 { 515 const sal_uInt16 nPos = GetPos(nTypeId); 516 517 switch(nTypeId) 518 { 519 case TYP_SETREFFLD: 520 case TYP_GETREFFLD: 521 { 522 // Referenzen sind keine Felder 523 pSh->GetRefMarks( &rToFill ); 524 break; 525 } 526 case TYP_MACROFLD: 527 { 528 break; 529 } 530 case TYP_INPUTFLD: 531 { String* pNew = new SW_RESSTR(aSwFlds[nPos].nSubTypeStart); 532 rToFill.Insert(pNew, rToFill.Count()); 533 // Weiter bei generischen Typen 534 } 535 case TYP_DDEFLD: 536 case TYP_SEQFLD: 537 case TYP_FORMELFLD: 538 case TYP_GETFLD: 539 case TYP_SETFLD: 540 case TYP_USERFLD: 541 { 542 543 const sal_uInt16 nCount = pSh->GetFldTypeCount(); 544 for(sal_uInt16 i = 0; i < nCount; ++i) 545 { 546 SwFieldType* pFldType = pSh->GetFldType( i ); 547 const sal_uInt16 nWhich = pFldType->Which(); 548 549 if((nTypeId == TYP_DDEFLD && pFldType->Which() == RES_DDEFLD) || 550 551 (nTypeId == TYP_USERFLD && nWhich == RES_USERFLD) || 552 553 (nTypeId == TYP_GETFLD && nWhich == RES_SETEXPFLD && 554 !(((SwSetExpFieldType*)pFldType)->GetType() & nsSwGetSetExpType::GSE_SEQ)) || 555 556 (nTypeId == TYP_SETFLD && nWhich == RES_SETEXPFLD && 557 !(((SwSetExpFieldType*)pFldType)->GetType() & nsSwGetSetExpType::GSE_SEQ)) || 558 559 (nTypeId == TYP_SEQFLD && nWhich == RES_SETEXPFLD && 560 (((SwSetExpFieldType*)pFldType)->GetType() & nsSwGetSetExpType::GSE_SEQ)) || 561 562 ((nTypeId == TYP_INPUTFLD || nTypeId == TYP_FORMELFLD) && 563 (nWhich == RES_USERFLD || 564 (nWhich == RES_SETEXPFLD && 565 !(((SwSetExpFieldType*)pFldType)->GetType() & nsSwGetSetExpType::GSE_SEQ))) ) ) 566 { 567 String* pNew = new String(pFldType->GetName()); 568 rToFill.Insert(pNew, rToFill.Count()); 569 } 570 } 571 break; 572 } 573 case TYP_DBNEXTSETFLD: 574 case TYP_DBNUMSETFLD: 575 case TYP_DBNAMEFLD: 576 case TYP_DBSETNUMBERFLD: 577 break; 578 579 default: 580 { 581 // statische SubTypes 582 if(nPos != USHRT_MAX) 583 { 584 sal_uInt16 nCount; 585 if (nTypeId == TYP_DOCINFOFLD) 586 nCount = DI_SUBTYPE_END - DI_SUBTYPE_BEGIN; 587 else 588 nCount = aSwFlds[nPos].nSubTypeEnd - aSwFlds[nPos].nSubTypeStart; 589 590 for(sal_uInt16 i = 0; i < nCount; ++i) 591 { 592 String* pNew; 593 if (nTypeId == TYP_DOCINFOFLD) 594 { 595 if ( i == DI_CUSTOM ) 596 pNew = new String( String(SW_RES( STR_CUSTOM )) ); 597 else 598 pNew = new String(*ViewShell::GetShellRes()->aDocInfoLst[i]); 599 } 600 else 601 pNew = new SW_RESSTR(aSwFlds[nPos].nSubTypeStart + i); 602 603 rToFill.Insert(pNew, rToFill.Count()); 604 } 605 } 606 } 607 } 608 bRet = sal_True; 609 } 610 return bRet; 611 } 612 613 /*-------------------------------------------------------------------- 614 Beschreibung: Format ermitteln 615 ZUGRIFF ueber TYP_.... 616 --------------------------------------------------------------------*/ 617 618 619 sal_uInt16 SwFldMgr::GetFormatCount(sal_uInt16 nTypeId, sal_Bool bIsText, sal_Bool bHtmlMode) const 620 { 621 ASSERT(nTypeId < TYP_END, "unzulaessige TypeId"); 622 623 { 624 const sal_uInt16 nPos = GetPos(nTypeId); 625 626 if(nPos == USHRT_MAX || (bHtmlMode && nTypeId == TYP_SETFLD)) 627 return 0; 628 629 sal_uLong nStart = aSwFlds[nPos].nFmtBegin; 630 sal_uLong nEnd = aSwFlds[nPos].nFmtEnd; 631 632 if (bIsText && nEnd - nStart >= 2) 633 return 2; 634 635 if (nTypeId == TYP_FILENAMEFLD) 636 nEnd -= 2; // Kein Bereich oder Vorlage 637 638 switch(nStart) 639 { 640 case FMT_GETVAR_BEGIN: 641 case FMT_SETVAR_BEGIN: return VF_COUNT; 642 case FMT_USERVAR_BEGIN: return VF_USR_COUNT; 643 case FMT_DBFLD_BEGIN: return VF_DB_COUNT; 644 case FMT_NUM_BEGIN: 645 { 646 sal_uInt16 nCount = (sal_uInt16)(nEnd - nStart); 647 GetNumberingInfo(); 648 if(xNumberingInfo.is()) 649 { 650 Sequence<sal_Int16> aTypes = xNumberingInfo->getSupportedNumberingTypes(); 651 const sal_Int16* pTypes = aTypes.getConstArray(); 652 for(sal_Int32 nType = 0; nType < aTypes.getLength(); nType++) 653 { 654 sal_Int16 nCurrent = pTypes[nType]; 655 //skip all values below or equal to CHARS_LOWER_LETTER_N 656 if(nCurrent > NumberingType::CHARS_LOWER_LETTER_N) 657 { 658 // #i28073# it's not necessarily a sorted sequence 659 ++nCount; 660 } 661 } 662 } 663 return nCount; 664 } 665 666 } 667 return (sal_uInt16)(nEnd - nStart); 668 } 669 } 670 671 /*-------------------------------------------------------------------- 672 Beschreibung: FormatString zu einem Typ ermitteln 673 --------------------------------------------------------------------*/ 674 675 676 String SwFldMgr::GetFormatStr(sal_uInt16 nTypeId, sal_uLong nFormatId) const 677 { 678 String aRet; 679 ASSERT(nTypeId < TYP_END, "unzulaessige TypeId"); 680 681 const sal_uInt16 nPos = GetPos(nTypeId); 682 683 if(nPos == USHRT_MAX) 684 return aRet; 685 686 sal_uLong nStart; 687 688 nStart = aSwFlds[nPos].nFmtBegin; 689 690 if (TYP_AUTHORFLD == nTypeId|| TYP_FILENAMEFLD == nTypeId) 691 nFormatId &= ~FF_FIXED; // Fixed-Flag ausmaskieren 692 693 if((nStart + nFormatId) < aSwFlds[nPos].nFmtEnd) 694 aRet = SW_RESSTR((sal_uInt16)(nStart + nFormatId)); 695 else if( FMT_NUM_BEGIN == nStart) 696 { 697 if(xNumberingInfo.is()) 698 { 699 Sequence<sal_Int16> aTypes = xNumberingInfo->getSupportedNumberingTypes(); 700 const sal_Int16* pTypes = aTypes.getConstArray(); 701 sal_Int32 nOffset = aSwFlds[nPos].nFmtEnd - nStart; 702 sal_Int32 nValidEntry = 0; 703 for(sal_Int32 nType = 0; nType < aTypes.getLength(); nType++) 704 { 705 sal_Int16 nCurrent = pTypes[nType]; 706 if(nCurrent > NumberingType::CHARS_LOWER_LETTER_N) 707 { 708 if(nValidEntry == ((sal_Int32)nFormatId) - nOffset) 709 { 710 aRet = xNumberingInfo->getNumberingIdentifier( pTypes[nType] ); 711 break; 712 } 713 ++nValidEntry; 714 } 715 } 716 } 717 } 718 719 return aRet; 720 } 721 722 /*-------------------------------------------------------------------- 723 Beschreibung: FormatId aus Pseudo-ID ermitteln 724 --------------------------------------------------------------------*/ 725 726 sal_uInt16 SwFldMgr::GetFormatId(sal_uInt16 nTypeId, sal_uLong nFormatId) const 727 { 728 sal_uInt16 nId = (sal_uInt16)nFormatId; 729 730 switch( nTypeId ) 731 { 732 case TYP_DOCINFOFLD: 733 switch( aSwFlds[ GetPos( nTypeId ) ].nFmtBegin + nFormatId ) 734 { 735 case FMT_REG_AUTHOR: nId = DI_SUB_AUTHOR; break; 736 case FMT_REG_TIME: nId = DI_SUB_TIME; break; 737 case FMT_REG_DATE: nId = DI_SUB_DATE; break; 738 } 739 break; 740 741 case TYP_PAGENUMBERFLD: 742 case TYP_NEXTPAGEFLD: 743 case TYP_PREVPAGEFLD: 744 case TYP_DOCSTATFLD: 745 case TYP_DBSETNUMBERFLD: 746 case TYP_SEQFLD: 747 case TYP_GETREFPAGEFLD: 748 { 749 sal_uInt16 nPos = GetPos( nTypeId ); 750 sal_uLong nBegin = aSwFlds[ nPos ].nFmtBegin; 751 sal_uLong nEnd = aSwFlds[nPos].nFmtEnd; 752 if((nBegin + nFormatId) < nEnd) 753 { 754 switch( nBegin + nFormatId ) 755 { 756 case FMT_NUM_ABC: nId = SVX_NUM_CHARS_UPPER_LETTER; break; 757 case FMT_NUM_SABC: nId = SVX_NUM_CHARS_LOWER_LETTER; break; 758 case FMT_NUM_ROMAN: nId = SVX_NUM_ROMAN_UPPER; break; 759 case FMT_NUM_SROMAN: nId = SVX_NUM_ROMAN_LOWER; break; 760 case FMT_NUM_ARABIC: nId = SVX_NUM_ARABIC; break; 761 case FMT_NUM_PAGEDESC: nId = SVX_NUM_PAGEDESC; break; 762 case FMT_NUM_PAGESPECIAL: nId = SVX_NUM_CHAR_SPECIAL; break; 763 case FMT_NUM_ABC_N: nId = SVX_NUM_CHARS_UPPER_LETTER_N; break; 764 case FMT_NUM_SABC_N: nId = SVX_NUM_CHARS_LOWER_LETTER_N; break; 765 } 766 } 767 else if(xNumberingInfo.is()) 768 { 769 Sequence<sal_Int16> aTypes = xNumberingInfo->getSupportedNumberingTypes(); 770 const sal_Int16* pTypes = aTypes.getConstArray(); 771 sal_Int32 nOffset = nEnd - nBegin; 772 sal_Int32 nValidEntry = 0; 773 for(sal_Int32 nType = 0; nType < aTypes.getLength(); nType++) 774 { 775 sal_Int16 nCurrent = pTypes[nType]; 776 if(nCurrent > NumberingType::CHARS_LOWER_LETTER_N) 777 { 778 if(nValidEntry == ((sal_Int32)nFormatId) - nOffset) 779 { 780 nId = pTypes[nType]; 781 break; 782 } 783 ++nValidEntry; 784 } 785 } 786 } 787 } 788 break; 789 case TYP_DDEFLD: 790 switch ( aSwFlds[ GetPos( nTypeId ) ].nFmtBegin + nFormatId ) 791 { 792 case FMT_DDE_NORMAL: nId = sfx2::LINKUPDATE_ONCALL; break; 793 case FMT_DDE_HOT: nId = sfx2::LINKUPDATE_ALWAYS; break; 794 } 795 break; 796 } 797 798 return nId; 799 800 } 801 802 /*-------------------------------------------------------------------- 803 Beschreibung: Traveling 804 --------------------------------------------------------------------*/ 805 806 807 sal_Bool SwFldMgr::GoNextPrev( sal_Bool bNext, SwFieldType* pTyp ) 808 { 809 SwWrtShell* pSh = pWrtShell ? pWrtShell : ::lcl_GetShell(); 810 if(!pSh) 811 return sal_False; 812 813 if( !pTyp && pCurFld ) 814 { 815 const sal_uInt16 nTypeId = pCurFld->GetTypeId(); 816 if( TYP_SETINPFLD == nTypeId || TYP_USRINPFLD == nTypeId ) 817 pTyp = pSh->GetFldType( 0, RES_INPUTFLD ); 818 else 819 pTyp = pCurFld->GetTyp(); 820 } 821 822 if (pTyp && pTyp->Which() == RES_DBFLD) 823 { 824 // Fuer Feldbefehl-bearbeiten (alle DB-Felder anspringen) 825 return pSh->MoveFldType( 0, bNext, USHRT_MAX, RES_DBFLD ); 826 } 827 828 return pTyp && pSh ? pSh->MoveFldType( pTyp, bNext ) : sal_False; 829 } 830 831 /*-------------------------------------------------------------------- 832 Beschreibung: Feldtypen einfuegen 833 --------------------------------------------------------------------*/ 834 835 836 void SwFldMgr::InsertFldType(SwFieldType& rType) 837 { 838 SwWrtShell* pSh = pWrtShell ? pWrtShell : ::lcl_GetShell(); 839 DBG_ASSERT(pSh, "no SwWrtShell found"); 840 if(pSh) 841 pSh->InsertFldType(rType); 842 } 843 844 /*-------------------------------------------------------------------- 845 Beschreibung: Aktuelle TypeId ermitteln 846 --------------------------------------------------------------------*/ 847 848 849 sal_uInt16 SwFldMgr::GetCurTypeId() const 850 { 851 return pCurFld ? pCurFld->GetTypeId() : USHRT_MAX; 852 } 853 854 /*-------------------------------------------------------------------- 855 Beschreibung: Ueber String Feld einfuegen oder Update 856 --------------------------------------------------------------------*/ 857 858 859 sal_Bool SwFldMgr::InsertFld( const SwInsertFld_Data& rData ) 860 { 861 SwField* pFld = 0; 862 sal_Bool bExp = sal_False; 863 sal_Bool bTbl = sal_False; 864 sal_Bool bPageVar = sal_False; 865 sal_uLong nFormatId = rData.nFormatId; 866 sal_uInt16 nSubType = rData.nSubType; 867 sal_Unicode cSeparator = rData.cSeparator; 868 SwWrtShell* pCurShell = rData.pSh; 869 if(!pCurShell) 870 pCurShell = pWrtShell ? pWrtShell : ::lcl_GetShell(); 871 DBG_ASSERT(pCurShell, "no SwWrtShell found"); 872 if(!pCurShell) 873 return sal_False; 874 875 switch(rData.nTypeId) 876 { // ACHTUNG dieses Feld wird ueber einen gesonderten Dialog eingefuegt 877 case TYP_POSTITFLD: 878 { 879 SwPostItFieldType* pType = (SwPostItFieldType*)pCurShell->GetFldType(0, RES_POSTITFLD); 880 pFld = new SwPostItField(pType, rData.sPar1, rData.sPar2, DateTime()); 881 break; 882 } 883 case TYP_SCRIPTFLD: 884 { 885 SwScriptFieldType* pType = 886 (SwScriptFieldType*)pCurShell->GetFldType(0, RES_SCRIPTFLD); 887 pFld = new SwScriptField(pType, rData.sPar1, rData.sPar2, (sal_Bool)nFormatId); 888 break; 889 } 890 case TYP_COMBINED_CHARS: 891 { 892 SwCombinedCharFieldType* pType = (SwCombinedCharFieldType*) 893 pCurShell->GetFldType( 0, RES_COMBINED_CHARS ); 894 pFld = new SwCombinedCharField( pType, rData.sPar1 ); 895 } 896 break; 897 case TYP_AUTHORITY: 898 { 899 SwAuthorityFieldType* pType = 900 (SwAuthorityFieldType*)pCurShell->GetFldType(0, RES_AUTHORITY); 901 if(!pType) 902 { 903 pType = 904 (SwAuthorityFieldType*)pCurShell->InsertFldType( 905 SwAuthorityFieldType(pCurShell->GetDoc())); 906 } 907 pFld = new SwAuthorityField(pType, rData.sPar1); 908 } 909 break; 910 case TYP_DATEFLD: 911 case TYP_TIMEFLD: 912 { 913 sal_uInt16 nSub = static_cast< sal_uInt16 >(rData.nTypeId == TYP_DATEFLD ? DATEFLD : TIMEFLD); 914 nSub |= nSubType == DATE_VAR ? 0 : FIXEDFLD; 915 916 SwDateTimeFieldType* pTyp = 917 (SwDateTimeFieldType*)pCurShell->GetFldType(0, RES_DATETIMEFLD); 918 pFld = new SwDateTimeField(pTyp, nSub, nFormatId); 919 pFld->SetPar2(rData.sPar2); 920 break; 921 } 922 case TYP_FILENAMEFLD: 923 { 924 SwFileNameFieldType* pTyp = 925 (SwFileNameFieldType*)pCurShell->GetFldType(0, RES_FILENAMEFLD); 926 pFld = new SwFileNameField(pTyp, nFormatId); 927 break; 928 } 929 case TYP_TEMPLNAMEFLD: 930 { 931 SwTemplNameFieldType* pTyp = 932 (SwTemplNameFieldType*)pCurShell->GetFldType(0, RES_TEMPLNAMEFLD); 933 pFld = new SwTemplNameField(pTyp, nFormatId); 934 break; 935 } 936 case TYP_CHAPTERFLD: 937 { 938 sal_uInt16 nByte = (sal_uInt16)rData.sPar2.ToInt32(); 939 SwChapterFieldType* pTyp = 940 (SwChapterFieldType*)pCurShell->GetFldType(0, RES_CHAPTERFLD); 941 pFld = new SwChapterField(pTyp, nFormatId); 942 nByte = Max(sal_uInt16(1), nByte); 943 nByte = Min(nByte, sal_uInt16(MAXLEVEL)); 944 nByte -= 1; 945 ((SwChapterField*)pFld)->SetLevel((sal_uInt8)nByte); 946 break; 947 } 948 case TYP_NEXTPAGEFLD: 949 case TYP_PREVPAGEFLD: 950 case TYP_PAGENUMBERFLD: 951 { 952 short nOff = (short)rData.sPar2.ToInt32(); 953 954 if(rData.nTypeId == TYP_NEXTPAGEFLD) 955 { 956 if( SVX_NUM_CHAR_SPECIAL == nFormatId ) 957 nOff = 1; 958 else 959 nOff += 1; 960 nSubType = PG_NEXT; 961 } 962 else if(rData.nTypeId == TYP_PREVPAGEFLD) 963 { 964 if( SVX_NUM_CHAR_SPECIAL == nFormatId ) 965 nOff = -1; 966 else 967 nOff -= 1; 968 nSubType = PG_PREV; 969 } 970 else 971 nSubType = PG_RANDOM; 972 973 SwPageNumberFieldType* pTyp = 974 (SwPageNumberFieldType*)pCurShell->GetFldType(0, RES_PAGENUMBERFLD); 975 pFld = new SwPageNumberField(pTyp, nSubType, nFormatId, nOff); 976 977 if( SVX_NUM_CHAR_SPECIAL == nFormatId && 978 ( PG_PREV == nSubType || PG_NEXT == nSubType ) ) 979 ((SwPageNumberField*)pFld)->SetUserString( rData.sPar2 ); 980 break; 981 } 982 case TYP_DOCSTATFLD: 983 { SwDocStatFieldType* pTyp = 984 (SwDocStatFieldType*)pCurShell->GetFldType(0, RES_DOCSTATFLD); 985 pFld = new SwDocStatField(pTyp, nSubType, nFormatId); 986 break; 987 } 988 case TYP_AUTHORFLD: 989 { SwAuthorFieldType* pTyp = 990 (SwAuthorFieldType*)pCurShell->GetFldType(0, RES_AUTHORFLD); 991 pFld = new SwAuthorField(pTyp, nFormatId); 992 break; 993 } 994 case TYP_CONDTXTFLD: 995 case TYP_HIDDENTXTFLD: 996 { 997 SwHiddenTxtFieldType* pTyp = 998 (SwHiddenTxtFieldType*)pCurShell->GetFldType(0, RES_HIDDENTXTFLD); 999 pFld = new SwHiddenTxtField(pTyp, sal_True, rData.sPar1, rData.sPar2, sal_False, rData.nTypeId); 1000 bExp = sal_True; 1001 break; 1002 } 1003 case TYP_HIDDENPARAFLD: 1004 { 1005 SwHiddenParaFieldType* pTyp = 1006 (SwHiddenParaFieldType*)pCurShell->GetFldType(0, RES_HIDDENPARAFLD); 1007 pFld = new SwHiddenParaField(pTyp, rData.sPar1); 1008 bExp = sal_True; 1009 break; 1010 } 1011 case TYP_SETREFFLD: 1012 { 1013 if( rData.sPar1.Len() > 0 && CanInsertRefMark( rData.sPar1 ) ) 1014 { 1015 pCurShell->SetAttr( SwFmtRefMark( rData.sPar1 ) ); 1016 return sal_True; 1017 } 1018 return sal_False; 1019 } 1020 case TYP_GETREFFLD: 1021 { 1022 SwGetRefFieldType* pTyp = 1023 (SwGetRefFieldType*)pCurShell->GetFldType(0, RES_GETREFFLD); 1024 sal_uInt16 nSeqNo = (sal_uInt16)rData.sPar2.ToInt32(); 1025 pFld = new SwGetRefField(pTyp, rData.sPar1, nSubType, nSeqNo, nFormatId); 1026 bExp = sal_True; 1027 break; 1028 } 1029 case TYP_DDEFLD: 1030 { 1031 //JP 28.08.95: DDE-Topics/-Items koennen Blanks in ihren 1032 // Namen haben! Wird hier noch nicht beachtet. 1033 String sCmd( rData.sPar2 ); 1034 sal_uInt16 nTmpPos = sCmd.SearchAndReplace( ' ', sfx2::cTokenSeperator ); 1035 sCmd.SearchAndReplace( ' ', sfx2::cTokenSeperator, nTmpPos ); 1036 1037 SwDDEFieldType aType( rData.sPar1, sCmd, (sal_uInt16) nFormatId ); 1038 SwDDEFieldType* pTyp = (SwDDEFieldType*) pCurShell->InsertFldType( aType ); 1039 pFld = new SwDDEField( pTyp ); 1040 break; 1041 } 1042 case TYP_MACROFLD: 1043 { 1044 SwMacroFieldType* pTyp = 1045 (SwMacroFieldType*)pCurShell->GetFldType(0, RES_MACROFLD); 1046 1047 pFld = new SwMacroField(pTyp, rData.sPar1, rData.sPar2); 1048 1049 break; 1050 } 1051 case TYP_INTERNETFLD: 1052 { 1053 SwFmtINetFmt aFmt( rData.sPar1, sCurFrame ); 1054 if( pMacroItem ) 1055 aFmt.SetMacroTbl( &pMacroItem->GetMacroTable() ); 1056 return pCurShell->InsertURL( aFmt, rData.sPar2 ); 1057 } 1058 case TYP_JUMPEDITFLD: 1059 { 1060 SwJumpEditFieldType* pTyp = 1061 (SwJumpEditFieldType*)pCurShell->GetFldType(0, RES_JUMPEDITFLD); 1062 1063 pFld = new SwJumpEditField(pTyp, nFormatId, rData.sPar1, rData.sPar2 ); 1064 break; 1065 } 1066 case TYP_DOCINFOFLD: 1067 { 1068 SwDocInfoFieldType* pTyp = (SwDocInfoFieldType*)pCurShell->GetFldType( 1069 0, RES_DOCINFOFLD ); 1070 pFld = new SwDocInfoField(pTyp, nSubType, rData.sPar1, nFormatId); 1071 break; 1072 } 1073 case TYP_EXTUSERFLD: 1074 { 1075 SwExtUserFieldType* pTyp = (SwExtUserFieldType*)pCurShell->GetFldType( 1076 0, RES_EXTUSERFLD); 1077 pFld = new SwExtUserField(pTyp, nSubType, nFormatId); 1078 break; 1079 } 1080 case TYP_DBFLD: 1081 { 1082 SwDBData aDBData; 1083 String sPar1; 1084 1085 if (rData.sPar1.Search(DB_DELIM) == STRING_NOTFOUND) 1086 { 1087 aDBData = pCurShell->GetDBData(); 1088 sPar1 = rData.sPar1; 1089 } 1090 else 1091 { 1092 aDBData.sDataSource = rData.sPar1.GetToken(0, DB_DELIM); 1093 aDBData.sCommand = rData.sPar1.GetToken(1, DB_DELIM); 1094 aDBData.nCommandType = rData.sPar1.GetToken(2, DB_DELIM).ToInt32(); 1095 sPar1 = rData.sPar1.GetToken(3, DB_DELIM); 1096 } 1097 1098 if(aDBData.sDataSource.getLength() && pCurShell->GetDBData() != aDBData) 1099 pCurShell->ChgDBData(aDBData); 1100 1101 SwDBFieldType* pTyp = (SwDBFieldType*)pCurShell->InsertFldType( 1102 SwDBFieldType(pCurShell->GetDoc(), sPar1, aDBData) ); 1103 pFld = new SwDBField(pTyp); 1104 pFld->SetSubType(nSubType); 1105 1106 if( !(nSubType & nsSwExtendedSubType::SUB_OWN_FMT) ) // Datenbankformat ermitteln 1107 { 1108 Reference< XDataSource> xSource; 1109 rData.aDBDataSource >>= xSource; 1110 Reference<XConnection> xConnection; 1111 rData.aDBConnection >>= xConnection; 1112 Reference<XPropertySet> xColumn; 1113 rData.aDBColumn >>= xColumn; 1114 if(xColumn.is()) 1115 { 1116 nFormatId = pCurShell->GetNewDBMgr()->GetColumnFmt(xSource, xConnection, xColumn, 1117 pCurShell->GetNumberFormatter(), GetCurrLanguage() ); 1118 } 1119 else 1120 nFormatId = pCurShell->GetNewDBMgr()->GetColumnFmt( 1121 aDBData.sDataSource, aDBData.sCommand, sPar1, 1122 pCurShell->GetNumberFormatter(), GetCurrLanguage() ); 1123 } 1124 pFld->ChangeFormat( nFormatId ); 1125 1126 bExp = sal_True; 1127 break; 1128 } 1129 case TYP_DBSETNUMBERFLD: 1130 case TYP_DBNUMSETFLD: 1131 case TYP_DBNEXTSETFLD: 1132 case TYP_DBNAMEFLD: 1133 { 1134 sal_uInt16 nPos, nTablePos, nCmdTypePos, nExpPos; 1135 String sPar1; 1136 SwDBData aDBData; 1137 1138 // DBName aus rData.sPar1 extrahieren. Format: DBName.TableName.CommandType.ExpStrg 1139 if ((nTablePos = rData.sPar1.Search(DB_DELIM)) != STRING_NOTFOUND) 1140 aDBData.sDataSource = rData.sPar1.Copy(0, nTablePos++); 1141 if ((nCmdTypePos = rData.sPar1.Search(DB_DELIM, nTablePos)) != STRING_NOTFOUND) 1142 { 1143 aDBData.sCommand = rData.sPar1.Copy(nTablePos, nCmdTypePos++ - nTablePos); 1144 } 1145 if ((nExpPos = rData.sPar1.Search(DB_DELIM, nCmdTypePos)) != STRING_NOTFOUND) 1146 { 1147 aDBData.nCommandType = rData.sPar1.Copy(nCmdTypePos, nExpPos++ - nCmdTypePos).ToInt32(); 1148 } 1149 if (nExpPos != STRING_NOTFOUND) 1150 nPos = nExpPos; 1151 else if (nTablePos != STRING_NOTFOUND) 1152 nPos = nTablePos; 1153 else 1154 nPos = 0; 1155 sPar1 = rData.sPar1.Copy(nPos); 1156 1157 if (aDBData.sDataSource.getLength() && pCurShell->GetDBData() != aDBData) 1158 pCurShell->ChgDBData(aDBData); 1159 1160 switch(rData.nTypeId) 1161 { 1162 case TYP_DBNAMEFLD: 1163 { 1164 SwDBNameFieldType* pTyp = 1165 (SwDBNameFieldType*)pCurShell->GetFldType(0, RES_DBNAMEFLD); 1166 pFld = new SwDBNameField(pTyp, aDBData); 1167 1168 break; 1169 } 1170 case TYP_DBNEXTSETFLD: 1171 { 1172 SwDBNextSetFieldType* pTyp = (SwDBNextSetFieldType*)pCurShell->GetFldType( 1173 0, RES_DBNEXTSETFLD); 1174 pFld = new SwDBNextSetField(pTyp, sPar1, rData.sPar2, aDBData); 1175 bExp = sal_True; 1176 break; 1177 } 1178 case TYP_DBNUMSETFLD: 1179 { 1180 SwDBNumSetFieldType* pTyp = (SwDBNumSetFieldType*)pCurShell->GetFldType( 1181 0, RES_DBNUMSETFLD); 1182 pFld = new SwDBNumSetField( pTyp, sPar1, rData.sPar2, aDBData); 1183 bExp = sal_True; 1184 break; 1185 } 1186 case TYP_DBSETNUMBERFLD: 1187 { 1188 SwDBSetNumberFieldType* pTyp = (SwDBSetNumberFieldType*) 1189 pCurShell->GetFldType(0, RES_DBSETNUMBERFLD); 1190 pFld = new SwDBSetNumberField( pTyp, aDBData, nFormatId); 1191 bExp = sal_True; 1192 break; 1193 } 1194 } 1195 break; 1196 } 1197 case TYP_USERFLD: 1198 { 1199 SwUserFieldType* pTyp = 1200 (SwUserFieldType*)pCurShell->GetFldType(RES_USERFLD, rData.sPar1); 1201 1202 // nur wenn vorhanden 1203 if(!pTyp) 1204 { 1205 pTyp = (SwUserFieldType*)pCurShell->InsertFldType( 1206 SwUserFieldType(pCurShell->GetDoc(), rData.sPar1)); 1207 } 1208 if (pTyp->GetContent(nFormatId) != rData.sPar2) 1209 pTyp->SetContent(rData.sPar2, nFormatId); 1210 pFld = new SwUserField(pTyp, 0, nFormatId); 1211 if (pFld->GetSubType() != nSubType) 1212 pFld->SetSubType(nSubType); 1213 bTbl = sal_True; 1214 break; 1215 } 1216 case TYP_INPUTFLD: 1217 { 1218 if ((nSubType & 0x00ff) == INP_VAR) 1219 { 1220 SwSetExpFieldType* pTyp = (SwSetExpFieldType*) 1221 pCurShell->GetFldType(RES_SETEXPFLD, rData.sPar1); 1222 1223 // kein Experssion Type mit dem Namen vorhanden -> anlegen 1224 if(pTyp) 1225 { 1226 SwSetExpField* pExpFld = 1227 new SwSetExpField(pTyp, aEmptyStr, nFormatId); 1228 1229 // Typ vom SwSetExpFieldType nicht veraendern: 1230 sal_uInt16 nOldSubType = pExpFld->GetSubType(); 1231 pExpFld->SetSubType(nOldSubType | (nSubType & 0xff00)); 1232 1233 pExpFld->SetPromptText(rData.sPar2); 1234 pExpFld->SetInputFlag(sal_True) ; 1235 bExp = sal_True; 1236 pFld = pExpFld; 1237 } 1238 else 1239 return sal_False; 1240 } 1241 else 1242 { 1243 SwInputFieldType* pTyp = 1244 (SwInputFieldType*)pCurShell->GetFldType(0, RES_INPUTFLD); 1245 1246 SwInputField* pInpFld = 1247 new SwInputField(pTyp, rData.sPar1, rData.sPar2, nSubType|nsSwExtendedSubType::SUB_INVISIBLE, nFormatId); 1248 pFld = pInpFld; 1249 } 1250 1251 // Dialog starten 1252 // 1253 pCurShell->StartInputFldDlg(pFld, sal_False, rData.pParent); 1254 break; 1255 } 1256 case TYP_SETFLD: 1257 { 1258 if (!rData.sPar2.Len()) // Leere Variablen sind nicht erlaubt 1259 return sal_False; 1260 1261 SwSetExpFieldType* pTyp = (SwSetExpFieldType*)pCurShell->InsertFldType( 1262 SwSetExpFieldType(pCurShell->GetDoc(), rData.sPar1) ); 1263 1264 SwSetExpField* pExpFld = new SwSetExpField( pTyp, rData.sPar2, nFormatId); 1265 pExpFld->SetSubType(nSubType); 1266 pExpFld->SetPar2(rData.sPar2); 1267 bExp = sal_True; 1268 pFld = pExpFld; 1269 break; 1270 } 1271 case TYP_SEQFLD: 1272 { 1273 SwSetExpFieldType* pTyp = (SwSetExpFieldType*)pCurShell->InsertFldType( 1274 SwSetExpFieldType(pCurShell->GetDoc(), rData.sPar1, nsSwGetSetExpType::GSE_SEQ)); 1275 1276 sal_uInt8 nLevel = static_cast< sal_uInt8 >(nSubType & 0xff); 1277 1278 pTyp->SetOutlineLvl(nLevel); 1279 if (nLevel != 0x7f && cSeparator == 0) 1280 cSeparator = '.'; 1281 1282 pTyp->SetDelimiter(cSeparator); 1283 SwSetExpField* pExpFld = new SwSetExpField(pTyp, rData.sPar2, nFormatId); 1284 bExp = sal_True; 1285 pFld = pExpFld; 1286 nSubType = nsSwGetSetExpType::GSE_SEQ; 1287 break; 1288 } 1289 case TYP_GETFLD: 1290 { 1291 // gibt es ein entprechendes SetField 1292 SwSetExpFieldType* pSetTyp = (SwSetExpFieldType*) 1293 pCurShell->GetFldType(RES_SETEXPFLD, rData.sPar1); 1294 1295 if(pSetTyp) 1296 { 1297 SwGetExpFieldType* pTyp = (SwGetExpFieldType*)pCurShell->GetFldType( 1298 0, RES_GETEXPFLD); 1299 pFld = new SwGetExpField(pTyp, rData.sPar1, pSetTyp->GetType(), nFormatId); 1300 pFld->SetSubType(nSubType | pSetTyp->GetType()); 1301 bExp = sal_True; 1302 } 1303 else 1304 return sal_False; 1305 break; 1306 } 1307 case TYP_FORMELFLD: 1308 { 1309 if(pCurShell->GetFrmType(0,sal_False) & FRMTYPE_TABLE) 1310 { 1311 pCurShell->StartAllAction(); 1312 1313 SvNumberFormatter* pFormatter = pCurShell->GetDoc()->GetNumberFormatter(); 1314 const SvNumberformat* pEntry = pFormatter->GetEntry(nFormatId); 1315 1316 if (pEntry) 1317 { 1318 SfxStringItem aFormat(FN_NUMBER_FORMAT, pEntry->GetFormatstring()); 1319 pCurShell->GetView().GetViewFrame()->GetDispatcher()-> 1320 Execute(FN_NUMBER_FORMAT, SFX_CALLMODE_SYNCHRON, &aFormat, 0L); 1321 } 1322 1323 SfxItemSet aBoxSet( pCurShell->GetAttrPool(), 1324 RES_BOXATR_FORMULA, RES_BOXATR_FORMULA ); 1325 1326 String sFml( rData.sPar2 ); 1327 if( sFml.EraseLeadingChars().Len() && 1328 '=' == sFml.GetChar( 0 ) ) 1329 sFml.Erase( 0, 1 ); 1330 1331 aBoxSet.Put( SwTblBoxFormula( sFml )); 1332 pCurShell->SetTblBoxFormulaAttrs( aBoxSet ); 1333 pCurShell->UpdateTable(); 1334 1335 pCurShell->EndAllAction(); 1336 return sal_True; 1337 1338 /* // In der Tabelle Tabellenformeln einfuegen 1339 SwTblFieldType* pTyp = (SwTblFieldType*)pCurShell->GetFldType( 1340 0, RES_TABLEFLD); 1341 pFld = new SwTblField(pTyp, rData.sPar2, nsSwGetSetExpType::GSE_EXPR, nFormatId); 1342 bTbl = sal_True;*/ 1343 } 1344 else 1345 { 1346 SwGetExpFieldType* pTyp = (SwGetExpFieldType*) 1347 pCurShell->GetFldType(0, RES_GETEXPFLD); 1348 pFld = new SwGetExpField(pTyp, rData.sPar2, nsSwGetSetExpType::GSE_FORMULA, nFormatId); 1349 pFld->SetSubType(nSubType); 1350 bExp = sal_True; 1351 } 1352 break; 1353 } 1354 case TYP_SETREFPAGEFLD: 1355 pFld = new SwRefPageSetField( (SwRefPageSetFieldType*) 1356 pCurShell->GetFldType( 0, RES_REFPAGESETFLD ), 1357 (short)rData.sPar2.ToInt32(), 0 != nSubType ); 1358 bPageVar = sal_True; 1359 break; 1360 1361 case TYP_GETREFPAGEFLD: 1362 pFld = new SwRefPageGetField( (SwRefPageGetFieldType*) 1363 pCurShell->GetFldType( 0, RES_REFPAGEGETFLD ), nFormatId ); 1364 bPageVar = sal_True; 1365 break; 1366 case TYP_DROPDOWN : 1367 { 1368 pFld = new SwDropDownField(pCurShell->GetFldType( 0, RES_DROPDOWN )); 1369 xub_StrLen nTokenCount = rData.sPar2.Len() ? rData.sPar2.GetTokenCount(DB_DELIM) : 0; 1370 Sequence<OUString> aEntries(nTokenCount); 1371 OUString* pArray = aEntries.getArray(); 1372 for(xub_StrLen nToken = 0; nToken < nTokenCount; nToken++) 1373 pArray[nToken] = rData.sPar2.GetToken(nToken, DB_DELIM); 1374 ((SwDropDownField*)pFld)->SetItems(aEntries); 1375 ((SwDropDownField*)pFld)->SetName(rData.sPar1); 1376 } 1377 break; 1378 default: 1379 { ASSERT(!this, "Falscher Feldtyp"); 1380 return sal_False; 1381 } 1382 } 1383 ASSERT(pFld, "Feld nicht vorhanden"); 1384 1385 1386 //the auto language flag has to be set prior to the language! 1387 pFld->SetAutomaticLanguage(rData.bIsAutomaticLanguage); 1388 sal_uInt16 nLang = GetCurrLanguage(); 1389 pFld->SetLanguage(nLang); 1390 1391 // Einfuegen 1392 pCurShell->StartAllAction(); 1393 1394 pCurShell->Insert(*pFld); 1395 1396 if(bExp && bEvalExp) 1397 pCurShell->UpdateExpFlds(sal_True); 1398 1399 if(bTbl) 1400 { 1401 pCurShell->Left(CRSR_SKIP_CHARS, sal_False, 1, sal_False ); 1402 pCurShell->UpdateFlds(*pFld); 1403 pCurShell->Right(CRSR_SKIP_CHARS, sal_False, 1, sal_False ); 1404 } 1405 else if( bPageVar ) 1406 ((SwRefPageGetFieldType*)pCurShell->GetFldType( 0, RES_REFPAGEGETFLD ))->UpdateFlds(); 1407 else if( TYP_GETREFFLD == rData.nTypeId ) 1408 pFld->GetTyp()->ModifyNotification( 0, 0 ); 1409 1410 // temporaeres Feld loeschen 1411 delete pFld; 1412 1413 pCurShell->EndAllAction(); 1414 return sal_True; 1415 } 1416 1417 /*-------------------------------------------------------------------- 1418 Beschreibung: Felder Update 1419 --------------------------------------------------------------------*/ 1420 1421 1422 void SwFldMgr::UpdateCurFld(sal_uLong nFormat, 1423 const String& rPar1, 1424 const String& rPar2, 1425 SwField * _pTmpFld) // #111840# 1426 { 1427 // Format aendern 1428 ASSERT(pCurFld, "kein Feld an der CursorPos"); 1429 1430 bool bDelete = false; 1431 SwField *pTmpFld; // mb: fixed memory leak 1432 if (NULL != _pTmpFld) 1433 { 1434 pTmpFld = _pTmpFld; 1435 } 1436 else 1437 { 1438 pTmpFld = pCurFld->CopyField(); 1439 bDelete = true; 1440 } 1441 1442 SwFieldType* pType = pTmpFld->GetTyp(); 1443 const sal_uInt16 nTypeId = pTmpFld->GetTypeId(); 1444 1445 SwWrtShell* pSh = pWrtShell ? pWrtShell : ::lcl_GetShell(); 1446 DBG_ASSERT(pSh, "no SwWrtShell found"); 1447 if(!pSh) 1448 return; 1449 pSh->StartAllAction(); 1450 1451 sal_Bool bSetPar2 = sal_True; 1452 sal_Bool bSetPar1 = sal_True; 1453 String sPar1( rPar1 ); 1454 String sPar2( rPar2 ); 1455 1456 // Order to Format 1457 switch( nTypeId ) 1458 { 1459 case TYP_DDEFLD: 1460 { 1461 //JP 28.08.95: DDE-Topics/-Items koennen Blanks in ihren 1462 // Namen haben! Wird hier noch nicht beachtet. 1463 sal_uInt16 nTmpPos = sPar2.SearchAndReplace( ' ', sfx2::cTokenSeperator ); 1464 sPar2.SearchAndReplace( ' ', sfx2::cTokenSeperator, nTmpPos ); 1465 break; 1466 } 1467 1468 case TYP_CHAPTERFLD: 1469 { 1470 sal_uInt16 nByte = (sal_uInt16)rPar2.ToInt32(); 1471 nByte = Max(sal_uInt16(1), nByte); 1472 nByte = Min(nByte, sal_uInt16(MAXLEVEL)); 1473 nByte -= 1; 1474 ((SwChapterField*)pTmpFld)->SetLevel((sal_uInt8)nByte); 1475 bSetPar2 = sal_False; 1476 break; 1477 } 1478 1479 case TYP_SCRIPTFLD: 1480 ((SwScriptField*)pTmpFld)->SetCodeURL((sal_Bool)nFormat); 1481 break; 1482 1483 case TYP_NEXTPAGEFLD: 1484 if( SVX_NUM_CHAR_SPECIAL == nFormat ) 1485 { 1486 ((SwPageNumberField*)pCurFld)->SetUserString( sPar2 ); 1487 sPar2 = '1'; 1488 } 1489 else 1490 { 1491 if( nFormat + 2 == SVX_NUM_PAGEDESC ) 1492 nFormat = SVX_NUM_PAGEDESC; 1493 short nOff = (short)sPar2.ToInt32(); 1494 nOff += 1; 1495 sPar2 = String::CreateFromInt32(nOff); 1496 } 1497 break; 1498 1499 case TYP_PREVPAGEFLD: 1500 if( SVX_NUM_CHAR_SPECIAL == nFormat ) 1501 { 1502 ((SwPageNumberField*)pCurFld)->SetUserString( sPar2 ); 1503 sPar2 = String::CreateFromAscii( 1504 RTL_CONSTASCII_STRINGPARAM("-1")); 1505 } 1506 else 1507 { 1508 if( nFormat + 2 == SVX_NUM_PAGEDESC ) 1509 nFormat = SVX_NUM_PAGEDESC; 1510 short nOff = (short)sPar2.ToInt32(); 1511 nOff -= 1; 1512 sPar2 = String::CreateFromInt32(nOff); 1513 } 1514 break; 1515 1516 case TYP_PAGENUMBERFLD: 1517 case TYP_GETREFPAGEFLD: 1518 if( nFormat + 2 == SVX_NUM_PAGEDESC ) 1519 nFormat = SVX_NUM_PAGEDESC; 1520 break; 1521 1522 case TYP_GETREFFLD: 1523 { 1524 bSetPar2 = sal_False; 1525 ((SwGetRefField*)pTmpFld)->SetSubType( (sal_uInt16)rPar2.ToInt32() ); 1526 sal_uInt16 nPos = rPar2.Search( '|' ); 1527 if( STRING_NOTFOUND != nPos ) 1528 ((SwGetRefField*)pTmpFld)->SetSeqNo( (sal_uInt16)rPar2.Copy( nPos + 1 ).ToInt32()); 1529 } 1530 break; 1531 case TYP_DROPDOWN: 1532 { 1533 xub_StrLen nTokenCount = sPar2.Len() ? sPar2.GetTokenCount(DB_DELIM) : 0; 1534 Sequence<OUString> aEntries(nTokenCount); 1535 OUString* pArray = aEntries.getArray(); 1536 for(xub_StrLen nToken = 0; nToken < nTokenCount; nToken++) 1537 pArray[nToken] = sPar2.GetToken(nToken, DB_DELIM); 1538 ((SwDropDownField*)pTmpFld)->SetItems(aEntries); 1539 ((SwDropDownField*)pTmpFld)->SetName(sPar1); 1540 bSetPar1 = bSetPar2 = sal_False; 1541 } 1542 break; 1543 case TYP_AUTHORITY : 1544 { 1545 //#i99069# changes to a bibliography field should change the field type 1546 SwAuthorityField* pAuthorityField = static_cast<SwAuthorityField*>(pTmpFld); 1547 SwAuthorityFieldType* pAuthorityType = static_cast<SwAuthorityFieldType*>(pType); 1548 SwAuthEntry aTempEntry; 1549 for( sal_uInt16 i = 0; i < AUTH_FIELD_END; ++i ) 1550 aTempEntry.SetAuthorField( (ToxAuthorityField)i, 1551 rPar1.GetToken( i, TOX_STYLE_DELIMITER )); 1552 if( pAuthorityType->ChangeEntryContent( &aTempEntry ) ) 1553 { 1554 pType->UpdateFlds(); 1555 pSh->SetModified(); 1556 } 1557 1558 if( aTempEntry.GetAuthorField( AUTH_FIELD_IDENTIFIER ) == 1559 pAuthorityField->GetFieldText( AUTH_FIELD_IDENTIFIER ) ) 1560 bSetPar1 = sal_False; //otherwise it's a new or changed entry, the field needs to be updated 1561 bSetPar2 = sal_False; 1562 } 1563 break; 1564 } 1565 1566 // Format setzen 1567 // Format wegen NumberFormatter vor SetPar2 einstellen! 1568 pTmpFld->ChangeFormat(nFormat); 1569 1570 if(bSetPar1) 1571 pTmpFld->SetPar1( sPar1 ); 1572 if( bSetPar2 ) 1573 pTmpFld->SetPar2( sPar2 ); 1574 1575 // Update anschmeissen 1576 if(nTypeId == TYP_DDEFLD || 1577 nTypeId == TYP_USERFLD || 1578 nTypeId == TYP_USRINPFLD) 1579 { 1580 pType->UpdateFlds(); 1581 pSh->SetModified(); 1582 } 1583 else { 1584 // mb: #32157 1585 pSh->SwEditShell::UpdateFlds(*pTmpFld); 1586 GetCurFld(); 1587 } 1588 1589 if (bDelete) 1590 delete pTmpFld; 1591 1592 pSh->EndAllAction(); 1593 } 1594 1595 /*-------------------------------------------------------------------- 1596 Beschreibung: ExpressionFields explizit evaluieren 1597 --------------------------------------------------------------------*/ 1598 void SwFldMgr::EvalExpFlds(SwWrtShell* pSh) 1599 { 1600 if (pSh == NULL) 1601 pSh = pWrtShell ? pWrtShell : ::lcl_GetShell(); 1602 1603 if(pSh) 1604 { 1605 pSh->StartAllAction(); 1606 pSh->UpdateExpFlds(sal_True); 1607 pSh->EndAllAction(); 1608 } 1609 } 1610 sal_uInt16 SwFldMgr::GetCurrLanguage() const 1611 { 1612 SwWrtShell* pSh = pWrtShell ? pWrtShell : ::lcl_GetShell(); 1613 if( pSh ) 1614 return pSh->GetCurLang(); 1615 return SvxLocaleToLanguage( SvtSysLocale().GetLocaleData().getLocale() ); 1616 } 1617 1618 void SwFieldType::_GetFldName() 1619 { 1620 // mba: this is an awful mess; a fix is available, but too much for 3.4 -> applay plaster 1621 static const sal_uInt16 coFldCnt = 43; 1622 1623 static sal_uInt16 __READONLY_DATA coFldNms[ coFldCnt ] = { 1624 FLD_DATE_STD, 1625 FLD_TIME_STD, 1626 STR_FILENAMEFLD, 1627 STR_DBNAMEFLD, 1628 STR_CHAPTERFLD, 1629 STR_PAGENUMBERFLD, 1630 STR_DOCSTATFLD, 1631 STR_AUTHORFLD, 1632 STR_SETFLD, 1633 STR_GETFLD, 1634 STR_FORMELFLD, 1635 STR_HIDDENTXTFLD, 1636 STR_SETREFFLD, 1637 STR_GETREFFLD, 1638 STR_DDEFLD, 1639 STR_MACROFLD, 1640 STR_INPUTFLD, 1641 STR_HIDDENPARAFLD, 1642 STR_DOCINFOFLD, 1643 STR_DBFLD, 1644 STR_USERFLD, 1645 STR_POSTITFLD, 1646 STR_TEMPLNAMEFLD, 1647 STR_SEQFLD, 1648 STR_DBNEXTSETFLD, 1649 STR_DBNUMSETFLD, 1650 STR_DBSETNUMBERFLD, 1651 STR_CONDTXTFLD, 1652 STR_NEXTPAGEFLD, 1653 STR_PREVPAGEFLD, 1654 STR_EXTUSERFLD, 1655 FLD_DATE_FIX, 1656 FLD_TIME_FIX, 1657 STR_SETINPUTFLD, 1658 STR_USRINPUTFLD, 1659 STR_SETREFPAGEFLD, 1660 STR_GETREFPAGEFLD, 1661 STR_INTERNETFLD, 1662 STR_JUMPEDITFLD, 1663 STR_SCRIPTFLD, 1664 STR_AUTHORITY, 1665 STR_COMBINED_CHARS, 1666 STR_DROPDOWN 1667 }; 1668 1669 // Infos fuer Felder einfuegen 1670 SwFieldType::pFldNames = new SvStringsDtor( (sal_uInt8)coFldCnt, 2 ); 1671 for( sal_uInt16 nIdx = 0; nIdx < coFldCnt; ++nIdx ) 1672 { 1673 String* pTmp = new SW_RESSTR( coFldNms[ nIdx ] ); 1674 pTmp->Assign( MnemonicGenerator::EraseAllMnemonicChars( *pTmp ) ); 1675 SwFieldType::pFldNames->Insert(pTmp, nIdx ); 1676 } 1677 } 1678 1679 /*-------------------------------------------------------------------- 1680 Beschreibung: 1681 --------------------------------------------------------------------*/ 1682 1683 sal_Bool SwFldMgr::ChooseMacro(const String&) 1684 { 1685 sal_Bool bRet = sal_False; 1686 1687 // choose script dialog 1688 ::rtl::OUString aScriptURL = SfxApplication::ChooseScript(); 1689 1690 // the script selector dialog returns a valid script URL 1691 if ( aScriptURL.getLength() != 0 ) 1692 { 1693 SetMacroPath( aScriptURL ); 1694 bRet = sal_True; 1695 } 1696 1697 return bRet; 1698 } 1699 1700 void SwFldMgr::SetMacroPath(const String& rPath) 1701 { 1702 sMacroPath = rPath; 1703 sMacroName = rPath; 1704 1705 // try to set sMacroName member variable by parsing the macro path 1706 // using the new URI parsing services 1707 1708 Reference< XMultiServiceFactory > xSMgr = 1709 ::comphelper::getProcessServiceFactory(); 1710 1711 Reference< uri::XUriReferenceFactory > 1712 xFactory( xSMgr->createInstance( 1713 ::rtl::OUString::createFromAscii( 1714 "com.sun.star.uri.UriReferenceFactory" ) ), UNO_QUERY ); 1715 1716 if ( xFactory.is() ) 1717 { 1718 Reference< uri::XVndSunStarScriptUrl > 1719 xUrl( xFactory->parse( sMacroPath ), UNO_QUERY ); 1720 1721 if ( xUrl.is() ) 1722 { 1723 sMacroName = xUrl->getName(); 1724 } 1725 } 1726 } 1727 1728 /*-------------------------------------------------------------------- 1729 Beschreibung: 1730 --------------------------------------------------------------------*/ 1731 1732 sal_uLong SwFldMgr::GetDefaultFormat(sal_uInt16 nTypeId, sal_Bool bIsText, SvNumberFormatter* pFormatter, double* pVal) 1733 { 1734 double fValue; 1735 short nDefFormat; 1736 1737 switch (nTypeId) 1738 { 1739 case TYP_TIMEFLD: 1740 case TYP_DATEFLD: 1741 { 1742 Date aDate; 1743 Date* pNullDate = pFormatter->GetNullDate(); 1744 1745 fValue = aDate - *pNullDate; 1746 1747 Time aTime; 1748 1749 sal_uLong nNumFmtTime = (sal_uLong)aTime.GetSec() + (sal_uLong)aTime.GetMin() * 60L + 1750 (sal_uLong)aTime.GetHour() * 3600L; 1751 1752 fValue += (double)nNumFmtTime / 86400.0; 1753 1754 nDefFormat = (nTypeId == TYP_DATEFLD) ? NUMBERFORMAT_DATE : NUMBERFORMAT_TIME; 1755 } 1756 break; 1757 1758 default: 1759 if (bIsText) 1760 { 1761 fValue = 0.0; 1762 nDefFormat = NUMBERFORMAT_TEXT; 1763 } 1764 else 1765 { 1766 fValue = 0.0; 1767 nDefFormat = NUMBERFORMAT_ALL; 1768 } 1769 break; 1770 } 1771 1772 if (pVal) 1773 *pVal = fValue; 1774 1775 return pFormatter->GetStandardFormat(nDefFormat, GetCurrLanguage()); 1776 } 1777 1778 /* -----------------------------01.03.01 16:46-------------------------------- 1779 1780 ---------------------------------------------------------------------------*/ 1781 Reference<XNumberingTypeInfo> SwFldMgr::GetNumberingInfo() const 1782 { 1783 if(!xNumberingInfo.is()) 1784 { 1785 Reference< XMultiServiceFactory > xMSF = ::comphelper::getProcessServiceFactory(); 1786 Reference < XInterface > xI = xMSF->createInstance( 1787 ::rtl::OUString::createFromAscii( 1788 "com.sun.star.text.DefaultNumberingProvider" )); 1789 Reference<XDefaultNumberingProvider> xDefNum(xI, UNO_QUERY); 1790 DBG_ASSERT(xDefNum.is(), "service missing: \"com.sun.star.text.DefaultNumberingProvider\""); 1791 ((SwFldMgr*)this)->xNumberingInfo = Reference<XNumberingTypeInfo>(xDefNum, UNO_QUERY); 1792 } 1793 return xNumberingInfo; 1794 } 1795