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