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 #ifdef SW_DLLIMPLEMENTATION 32 #undef SW_DLLIMPLEMENTATION 33 #endif 34 35 36 37 #include "swtypes.hxx" 38 #include <view.hxx> 39 #include <IMark.hxx> 40 #include <expfld.hxx> 41 #include <swmodule.hxx> 42 #ifndef _FLDREF_HXX 43 #include <fldref.hxx> 44 #endif 45 #include <reffld.hxx> 46 #include <wrtsh.hxx> 47 48 #ifndef _FLDUI_HRC 49 #include <fldui.hrc> 50 #endif 51 #ifndef _FLDTDLG_HRC 52 #include <fldtdlg.hrc> 53 #endif 54 #ifndef _GLOBALS_HRC 55 #include <globals.hrc> 56 #endif 57 // --> OD 2007-11-14 #i83479# 58 #include <SwNodeNum.hxx> 59 #include <IDocumentMarkAccess.hxx> 60 #include <ndtxt.hxx> 61 // <-- 62 63 // sw/inc/expfld.hxx 64 SV_IMPL_PTRARR( _SwSeqFldList, _SeqFldLstElem* ) 65 66 #define REFFLDFLAG 0x4000 67 #define REFFLDFLAG_BOOKMARK 0x4800 68 #define REFFLDFLAG_FOOTNOTE 0x5000 69 #define REFFLDFLAG_ENDNOTE 0x6000 70 // --> OD 2007-11-09 #i83479# 71 #define REFFLDFLAG_HEADING 0x7100 72 #define REFFLDFLAG_NUMITEM 0x7200 73 // <-- 74 75 sal_uInt16 nFldDlgFmtSel = 0; 76 77 #define USER_DATA_VERSION_1 "1" 78 #define USER_DATA_VERSION USER_DATA_VERSION_1 79 80 81 /*-------------------------------------------------------------------- 82 Beschreibung: 83 --------------------------------------------------------------------*/ 84 85 SwFldRefPage::SwFldRefPage(Window* pParent, const SfxItemSet& rCoreSet ) : 86 SwFldPage( pParent, SW_RES( TP_FLD_REF ), rCoreSet ), 87 88 aTypeFT (this, SW_RES(FT_REFTYPE)), 89 aTypeLB (this, SW_RES(LB_REFTYPE)), 90 aSelectionFT (this, SW_RES(FT_REFSELECTION)), 91 aSelectionLB (this, SW_RES(LB_REFSELECTION)), 92 // --> OD 2007-11-21 #i83479# 93 aSelectionToolTipLB( this, SW_RES(LB_REFSELECTION_TOOLTIP) ), 94 // <-- 95 aFormatFT (this, SW_RES(FT_REFFORMAT)), 96 aFormatLB (this, SW_RES(LB_REFFORMAT)), 97 aNameFT (this, SW_RES(FT_REFNAME)), 98 aNameED (this, SW_RES(ED_REFNAME)), 99 aValueFT (this, SW_RES(FT_REFVALUE)), 100 aValueED (this, SW_RES(ED_REFVALUE)), 101 102 sBookmarkTxt (SW_RES(STR_REFBOOKMARK)), 103 sFootnoteTxt (SW_RES(STR_REFFOOTNOTE)), 104 sEndnoteTxt (SW_RES(STR_REFENDNOTE)), 105 // --> OD 2007-11-09 #i83479# 106 sHeadingTxt (SW_RES(STR_REFHEADING)), 107 sNumItemTxt (SW_RES(STR_REFNUMITEM)), 108 maOutlineNodes(), 109 maNumItems(), 110 mpSavedSelectedTxtNode( 0 ), 111 mnSavedSelectedPos( 0 ) 112 // <-- 113 { 114 FreeResource(); 115 116 aNameED.SetModifyHdl(LINK(this, SwFldRefPage, ModifyHdl)); 117 118 aTypeLB.SetDoubleClickHdl (LINK(this, SwFldRefPage, InsertHdl)); 119 aTypeLB.SetSelectHdl (LINK(this, SwFldRefPage, TypeHdl)); 120 aSelectionLB.SetSelectHdl (LINK(this, SwFldRefPage, SubTypeHdl)); 121 aSelectionLB.SetDoubleClickHdl (LINK(this, SwFldRefPage, InsertHdl)); 122 aFormatLB.SetDoubleClickHdl (LINK(this, SwFldRefPage, InsertHdl)); 123 124 // --> OD 2007-11-21 #i83479# 125 aSelectionToolTipLB.SetSelectHdl( LINK(this, SwFldRefPage, SubTypeHdl) ); 126 aSelectionToolTipLB.SetDoubleClickHdl( LINK(this, SwFldRefPage, InsertHdl) ); 127 aSelectionToolTipLB.SetStyle( aSelectionToolTipLB.GetStyle() | WB_HSCROLL ); 128 aSelectionToolTipLB.SetSpaceBetweenEntries(1); 129 aSelectionToolTipLB.SetHighlightRange(); 130 // <-- 131 } 132 133 /*-------------------------------------------------------------------- 134 Beschreibung: 135 --------------------------------------------------------------------*/ 136 137 SwFldRefPage::~SwFldRefPage() 138 { 139 } 140 141 // --> OD 2007-11-22 #i83479# 142 void SwFldRefPage::SaveSelectedTxtNode() 143 { 144 mpSavedSelectedTxtNode = 0; 145 mnSavedSelectedPos = 0; 146 if ( aSelectionToolTipLB.IsVisible() ) 147 { 148 SvLBoxEntry* pEntry = aSelectionToolTipLB.GetCurEntry(); 149 if ( pEntry ) 150 { 151 const sal_uInt16 nTypeId = (sal_uInt16)(sal_uLong)aTypeLB.GetEntryData(GetTypeSel()); 152 SwWrtShell *pSh = GetWrtShell(); 153 if ( !pSh ) 154 { 155 pSh = ::GetActiveWrtShell(); 156 } 157 if ( nTypeId == REFFLDFLAG_HEADING ) 158 { 159 mnSavedSelectedPos = static_cast<sal_uInt16>(reinterpret_cast<sal_uLong>(pEntry->GetUserData())); 160 if ( mnSavedSelectedPos < maOutlineNodes.size() ) 161 { 162 mpSavedSelectedTxtNode = maOutlineNodes[mnSavedSelectedPos]; 163 } 164 } 165 else if ( nTypeId == REFFLDFLAG_NUMITEM ) 166 { 167 mnSavedSelectedPos = static_cast<sal_uInt16>(reinterpret_cast<sal_uLong>(pEntry->GetUserData())); 168 if ( mnSavedSelectedPos < maNumItems.size() ) 169 { 170 mpSavedSelectedTxtNode = maNumItems[mnSavedSelectedPos]->GetTxtNode(); 171 } 172 } 173 } 174 } 175 } 176 177 const SwTxtNode* SwFldRefPage::GetSavedSelectedTxtNode() const 178 { 179 return mpSavedSelectedTxtNode; 180 } 181 182 sal_uInt16 SwFldRefPage::GetSavedSelectedPos() const 183 { 184 return mnSavedSelectedPos; 185 } 186 187 // <-- 188 189 /*-------------------------------------------------------------------- 190 Beschreibung: 191 --------------------------------------------------------------------*/ 192 193 void SwFldRefPage::Reset(const SfxItemSet& ) 194 { 195 if (!IsFldEdit()) 196 { 197 SavePos(&aTypeLB); 198 // --> OD 2007-11-22 #i83479# 199 SaveSelectedTxtNode(); 200 // <-- 201 } 202 SetSelectionSel(LISTBOX_ENTRY_NOTFOUND); 203 SetTypeSel(LISTBOX_ENTRY_NOTFOUND); 204 Init(); // Allgemeine initialisierung 205 206 // TypeListBox initialisieren 207 aTypeLB.SetUpdateMode(sal_False); 208 aTypeLB.Clear(); 209 210 // Typ-Listbox fuellen 211 212 sal_uInt16 nPos; 213 // Referenz setzen / einfuegen 214 const SwFldGroupRgn& rRg = GetFldMgr().GetGroupRange(IsFldDlgHtmlMode(), GetGroup()); 215 216 for (short i = rRg.nStart; i < rRg.nEnd; ++i) 217 { 218 const sal_uInt16 nTypeId = GetFldMgr().GetTypeId(i); 219 220 if (!IsFldEdit() || nTypeId != TYP_SETREFFLD) 221 { 222 nPos = aTypeLB.InsertEntry(GetFldMgr().GetTypeStr(i), i - rRg.nStart); 223 aTypeLB.SetEntryData(nPos, reinterpret_cast<void*>(nTypeId)); 224 } 225 } 226 227 // --> OD 2007-11-09 #i83479# 228 // entries for headings and numbered items 229 nPos = aTypeLB.InsertEntry(sHeadingTxt); 230 aTypeLB.SetEntryData(nPos, (void*)REFFLDFLAG_HEADING); 231 nPos = aTypeLB.InsertEntry(sNumItemTxt); 232 aTypeLB.SetEntryData(nPos, (void*)REFFLDFLAG_NUMITEM); 233 // <-- 234 235 // mit den Sequence-Typen auffuellen 236 SwWrtShell *pSh = GetWrtShell(); 237 if(!pSh) 238 pSh = ::GetActiveWrtShell(); 239 240 sal_uInt16 nFldTypeCnt = pSh->GetFldTypeCount(RES_SETEXPFLD); 241 242 for (sal_uInt16 n = 0; n < nFldTypeCnt; ++n) 243 { 244 SwSetExpFieldType* pType = (SwSetExpFieldType*)pSh->GetFldType(n, RES_SETEXPFLD); 245 246 if ((nsSwGetSetExpType::GSE_SEQ & pType->GetType()) && pType->GetDepends() && pSh->IsUsed(*pType)) 247 { 248 nPos = aTypeLB.InsertEntry(pType->GetName()); 249 aTypeLB.SetEntryData(nPos, (void*)(REFFLDFLAG | n)); 250 } 251 } 252 253 // Textmarken - jetzt immer (wegen Globaldokumenten) 254 nPos = aTypeLB.InsertEntry(sBookmarkTxt); 255 aTypeLB.SetEntryData(nPos, (void*)REFFLDFLAG_BOOKMARK); 256 257 // Fussnoten: 258 if( pSh->HasFtns() ) 259 { 260 nPos = aTypeLB.InsertEntry(sFootnoteTxt); 261 aTypeLB.SetEntryData(nPos, (void*)REFFLDFLAG_FOOTNOTE); 262 } 263 264 // Endnoten: 265 if ( pSh->HasFtns(true) ) 266 { 267 nPos = aTypeLB.InsertEntry(sEndnoteTxt); 268 aTypeLB.SetEntryData(nPos, (void*)REFFLDFLAG_ENDNOTE); 269 } 270 271 // alte Pos selektieren 272 if (!IsFldEdit()) 273 RestorePos(&aTypeLB); 274 275 aTypeLB.SetUpdateMode(sal_True); 276 277 nFldDlgFmtSel = 0; 278 279 if( !IsRefresh() ) 280 { 281 String sUserData = GetUserData(); 282 if(!IsRefresh() && sUserData.GetToken(0, ';'). 283 EqualsIgnoreCaseAscii(USER_DATA_VERSION_1)) 284 { 285 String sVal = sUserData.GetToken(1, ';'); 286 sal_uInt16 nVal = static_cast< sal_uInt16 >(sVal.ToInt32()); 287 if(nVal != USHRT_MAX) 288 { 289 for(sal_uInt16 i = 0; i < aTypeLB.GetEntryCount(); i++) 290 if(nVal == (sal_uInt16)(sal_uLong)aTypeLB.GetEntryData(i)) 291 { 292 aTypeLB.SelectEntryPos(i); 293 break; 294 } 295 } 296 } 297 } 298 TypeHdl(0); 299 300 if (IsFldEdit()) 301 { 302 aTypeLB.SaveValue(); 303 aSelectionLB.SaveValue(); 304 aFormatLB.SaveValue(); 305 aNameED.SaveValue(); 306 aValueED.SaveValue(); 307 } 308 } 309 310 /*-------------------------------------------------------------------- 311 Beschreibung: 312 --------------------------------------------------------------------*/ 313 314 IMPL_LINK( SwFldRefPage, TypeHdl, ListBox *, EMPTYARG ) 315 { 316 // Alte ListBoxPos sichern 317 const sal_uInt16 nOld = GetTypeSel(); 318 319 // Aktuelle ListBoxPos 320 SetTypeSel(aTypeLB.GetSelectEntryPos()); 321 322 if(GetTypeSel() == LISTBOX_ENTRY_NOTFOUND) 323 { 324 if (IsFldEdit()) 325 { 326 // Positionen selektieren 327 String sName; 328 sal_uInt16 nFlag = 0; 329 330 switch( GetCurField()->GetSubType() ) 331 { 332 case REF_BOOKMARK: 333 { 334 // --> OD 2007-11-14 #i83479# 335 // sName = sBookmarkTxt; 336 // nFlag = REFFLDFLAG_BOOKMARK; 337 SwGetRefField* pRefFld = dynamic_cast<SwGetRefField*>(GetCurField()); 338 if ( pRefFld && 339 pRefFld->IsRefToHeadingCrossRefBookmark() ) 340 { 341 sName = sHeadingTxt; 342 nFlag = REFFLDFLAG_HEADING; 343 } 344 else if ( pRefFld && 345 pRefFld->IsRefToNumItemCrossRefBookmark() ) 346 { 347 sName = sNumItemTxt; 348 nFlag = REFFLDFLAG_NUMITEM; 349 } 350 else 351 { 352 sName = sBookmarkTxt; 353 nFlag = REFFLDFLAG_BOOKMARK; 354 } 355 // <-- 356 } 357 break; 358 359 case REF_FOOTNOTE: 360 sName = sFootnoteTxt; 361 nFlag = REFFLDFLAG_FOOTNOTE; 362 break; 363 364 case REF_ENDNOTE: 365 sName = sEndnoteTxt; 366 nFlag = REFFLDFLAG_ENDNOTE; 367 break; 368 369 case REF_SETREFATTR: 370 sName = SW_RESSTR(STR_GETREFFLD); 371 nFlag = REF_SETREFATTR; 372 break; 373 374 case REF_SEQUENCEFLD: 375 sName = ((SwGetRefField*)GetCurField())->GetSetRefName(); 376 nFlag = REFFLDFLAG; 377 break; 378 } 379 380 if (aTypeLB.GetEntryPos(sName) == LISTBOX_ENTRY_NOTFOUND) // Referenz zu gel?schter Marke 381 { 382 sal_uInt16 nPos = aTypeLB.InsertEntry(sName); 383 aTypeLB.SetEntryData(nPos, reinterpret_cast<void*>(nFlag)); 384 } 385 386 aTypeLB.SelectEntry(sName); 387 SetTypeSel(aTypeLB.GetSelectEntryPos()); 388 } 389 else 390 { 391 SetTypeSel(0); 392 aTypeLB.SelectEntryPos(0); 393 } 394 } 395 396 if (nOld != GetTypeSel()) 397 { 398 sal_uInt16 nTypeId = (sal_uInt16)(sal_uLong)aTypeLB.GetEntryData(GetTypeSel()); 399 400 // Auswahl-Listbox fuellen 401 UpdateSubType(); 402 403 sal_Bool bName = sal_False; nFldDlgFmtSel = 0; 404 405 if ( ( !IsFldEdit() || aSelectionLB.GetEntryCount() ) && 406 nOld != LISTBOX_ENTRY_NOTFOUND ) 407 { 408 aNameED.SetText(aEmptyStr); 409 aValueED.SetText(aEmptyStr); 410 } 411 412 switch (nTypeId) 413 { 414 case TYP_GETREFFLD: 415 if (REFFLDFLAG & (sal_uInt16)(sal_uLong)aTypeLB.GetEntryData(nOld)) 416 // dann bleibt die alte bestehen 417 nFldDlgFmtSel = aFormatLB.GetSelectEntryPos(); 418 bName = sal_True; 419 break; 420 421 case TYP_SETREFFLD: 422 bName = sal_True; 423 break; 424 425 case REFFLDFLAG_BOOKMARK: 426 bName = sal_True; 427 // kein break!!! 428 default: 429 if( REFFLDFLAG & nTypeId ) 430 { 431 sal_uInt16 nOldId = (sal_uInt16)(sal_uLong)aTypeLB.GetEntryData(nOld); 432 if( nOldId & REFFLDFLAG || nOldId == TYP_GETREFFLD ) 433 // dann bleibt die alte bestehen 434 nFldDlgFmtSel = aFormatLB.GetSelectEntryPos(); 435 } 436 break; 437 } 438 439 aNameED.Enable(bName); 440 aNameFT.Enable(bName); 441 442 // Format-Listbox fuellen 443 sal_uInt16 nSize = FillFormatLB(nTypeId); 444 sal_Bool bFormat = nSize != 0; 445 aFormatLB.Enable(bFormat); 446 aFormatFT.Enable(bFormat); 447 448 SubTypeHdl(); 449 ModifyHdl(); 450 } 451 452 return 0; 453 } 454 455 /*-------------------------------------------------------------------- 456 Beschreibung: 457 --------------------------------------------------------------------*/ 458 459 IMPL_LINK( SwFldRefPage, SubTypeHdl, ListBox *, EMPTYARG ) 460 { 461 sal_uInt16 nTypeId = (sal_uInt16)(sal_uLong)aTypeLB.GetEntryData(GetTypeSel()); 462 463 switch(nTypeId) 464 { 465 case TYP_GETREFFLD: 466 if (!IsFldEdit() || aSelectionLB.GetSelectEntryCount()) 467 { 468 aNameED.SetText(aSelectionLB.GetSelectEntry()); 469 ModifyHdl(&aNameED); 470 } 471 break; 472 473 case TYP_SETREFFLD: 474 { 475 SwWrtShell *pSh = GetWrtShell(); 476 if(!pSh) 477 pSh = ::GetActiveWrtShell(); 478 if(pSh) 479 { 480 aValueED.SetText(pSh->GetSelTxt()); 481 } 482 483 } 484 break; 485 // --> OD 2007-11-21 #i83479# 486 case REFFLDFLAG_HEADING: 487 case REFFLDFLAG_NUMITEM: 488 { 489 if ( aSelectionToolTipLB.GetCurEntry() ) 490 { 491 aNameED.SetText( aSelectionToolTipLB.GetEntryText( 492 aSelectionToolTipLB.GetCurEntry() ) ); 493 } 494 } 495 break; 496 // <-- 497 498 default: 499 if (!IsFldEdit() || aSelectionLB.GetSelectEntryCount()) 500 aNameED.SetText(aSelectionLB.GetSelectEntry()); 501 break; 502 } 503 504 return 0; 505 } 506 507 /*-------------------------------------------------------------------- 508 Beschreibung: Typen in SelectionLB erneuern 509 --------------------------------------------------------------------*/ 510 511 void SwFldRefPage::UpdateSubType() 512 { 513 SwWrtShell *pSh = GetWrtShell(); 514 if(!pSh) 515 pSh = ::GetActiveWrtShell(); 516 SwGetRefField* pRefFld = (SwGetRefField*)GetCurField(); 517 const sal_uInt16 nTypeId = (sal_uInt16)(sal_uLong)aTypeLB.GetEntryData(GetTypeSel()); 518 519 String sOldSel; 520 // --> OD 2007-11-22 #i83479# 521 if ( aSelectionLB.IsVisible() ) 522 { 523 const sal_uInt16 nSelectionSel = aSelectionLB.GetSelectEntryPos(); 524 if (nSelectionSel != LISTBOX_ENTRY_NOTFOUND) 525 { 526 sOldSel = aSelectionLB.GetEntry(nSelectionSel); 527 } 528 } 529 // <-- 530 if (IsFldEdit() && !sOldSel.Len()) 531 sOldSel = String::CreateFromInt32( pRefFld->GetSeqNo() + 1 ); 532 533 aSelectionLB.SetUpdateMode(sal_False); 534 aSelectionLB.Clear(); 535 // --> OD 2007-11-21 #i83479# 536 aSelectionToolTipLB.SetUpdateMode(sal_False); 537 aSelectionToolTipLB.Clear(); 538 bool bShowSelectionToolTipLB( false ); 539 // <-- 540 541 if( REFFLDFLAG & nTypeId ) 542 { 543 if (nTypeId == REFFLDFLAG_BOOKMARK) // TextMarken! 544 { 545 aSelectionLB.SetStyle(aSelectionLB.GetStyle()|WB_SORT); 546 // alle Textmarken besorgen 547 IDocumentMarkAccess* const pMarkAccess = pSh->getIDocumentMarkAccess(); 548 for(IDocumentMarkAccess::const_iterator_t ppMark = pMarkAccess->getBookmarksBegin(); 549 ppMark != pMarkAccess->getBookmarksEnd(); 550 ppMark++) 551 { 552 const ::sw::mark::IMark* pBkmk = ppMark->get(); 553 if(IDocumentMarkAccess::BOOKMARK == IDocumentMarkAccess::GetType(*pBkmk)) 554 aSelectionLB.InsertEntry( pBkmk->GetName() ); 555 } 556 if (IsFldEdit()) 557 sOldSel = pRefFld->GetSetRefName(); 558 } 559 else if (nTypeId == REFFLDFLAG_FOOTNOTE) 560 { 561 aSelectionLB.SetStyle(aSelectionLB.GetStyle() & ~WB_SORT); 562 SwSeqFldList aArr; 563 sal_uInt16 nCnt = pSh->GetSeqFtnList( aArr ); 564 565 for( sal_uInt16 n = 0; n < nCnt; ++n ) 566 { 567 aSelectionLB.InsertEntry( aArr[ n ]->sDlgEntry ); 568 if (IsFldEdit() && pRefFld->GetSeqNo() == aArr[ n ]->nSeqNo) 569 sOldSel = aArr[n]->sDlgEntry; 570 } 571 } 572 else if (nTypeId == REFFLDFLAG_ENDNOTE) 573 { 574 aSelectionLB.SetStyle(aSelectionLB.GetStyle() & ~WB_SORT); 575 SwSeqFldList aArr; 576 sal_uInt16 nCnt = pSh->GetSeqFtnList( aArr, true ); 577 578 for( sal_uInt16 n = 0; n < nCnt; ++n ) 579 { 580 aSelectionLB.InsertEntry( aArr[ n ]->sDlgEntry ); 581 if (IsFldEdit() && pRefFld->GetSeqNo() == aArr[ n ]->nSeqNo) 582 sOldSel = aArr[n]->sDlgEntry; 583 } 584 } 585 // --> OD 2007-11-14 #i83479# 586 else if ( nTypeId == REFFLDFLAG_HEADING ) 587 { 588 bShowSelectionToolTipLB = true; 589 590 const IDocumentOutlineNodes* pIDoc( pSh->getIDocumentOutlineNodesAccess() ); 591 pIDoc->getOutlineNodes( maOutlineNodes ); 592 bool bCertainTxtNodeSelected( false ); 593 SvLBoxEntry* pEntry = 0; 594 sal_uInt16 nOutlIdx = 0; 595 for ( nOutlIdx = 0; nOutlIdx < maOutlineNodes.size(); ++nOutlIdx ) 596 { 597 pEntry = aSelectionToolTipLB.InsertEntry( 598 pIDoc->getOutlineText( nOutlIdx, true, true ) ); 599 pEntry->SetUserData( reinterpret_cast<void*>(nOutlIdx) ); 600 if ( ( IsFldEdit() && 601 pRefFld->GetReferencedTxtNode() == maOutlineNodes[nOutlIdx] ) || 602 GetSavedSelectedTxtNode() == maOutlineNodes[nOutlIdx] ) 603 { 604 aSelectionToolTipLB.Select( pEntry ); 605 sOldSel.Erase(); 606 bCertainTxtNodeSelected = true; 607 } 608 else if ( !bCertainTxtNodeSelected && 609 GetSavedSelectedPos() == nOutlIdx ) 610 { 611 aSelectionToolTipLB.Select( pEntry ); 612 sOldSel.Erase(); 613 } 614 } 615 } 616 else if ( nTypeId == REFFLDFLAG_NUMITEM ) 617 { 618 bShowSelectionToolTipLB = true; 619 620 const IDocumentListItems* pIDoc( pSh->getIDocumentListItemsAccess() ); 621 pIDoc->getNumItems( maNumItems ); 622 bool bCertainTxtNodeSelected( false ); 623 SvLBoxEntry* pEntry = 0; 624 sal_uInt16 nNumItemIdx = 0; 625 for ( nNumItemIdx = 0; nNumItemIdx < maNumItems.size(); ++nNumItemIdx ) 626 { 627 pEntry = aSelectionToolTipLB.InsertEntry( 628 pIDoc->getListItemText( *maNumItems[nNumItemIdx], true, true ) ); 629 pEntry->SetUserData( reinterpret_cast<void*>(nNumItemIdx) ); 630 if ( ( IsFldEdit() && 631 pRefFld->GetReferencedTxtNode() == maNumItems[nNumItemIdx]->GetTxtNode() ) || 632 GetSavedSelectedTxtNode() == maNumItems[nNumItemIdx]->GetTxtNode() ) 633 { 634 aSelectionToolTipLB.Select( pEntry ); 635 sOldSel.Erase(); 636 bCertainTxtNodeSelected = true; 637 } 638 else if ( !bCertainTxtNodeSelected && 639 GetSavedSelectedPos() == nNumItemIdx ) 640 { 641 aSelectionToolTipLB.Select( pEntry ); 642 sOldSel.Erase(); 643 } 644 } 645 } 646 // <-- 647 else 648 { 649 aSelectionLB.SetStyle(aSelectionLB.GetStyle()|WB_SORT); 650 // zum Seq-FeldTyp die Felder besorgen: 651 652 SwSetExpFieldType* pType = (SwSetExpFieldType*)pSh->GetFldType( 653 nTypeId & ~REFFLDFLAG, RES_SETEXPFLD ); 654 if( pType ) 655 { 656 SwSeqFldList aArr; 657 // old selection should be kept in non-edit mode 658 if(IsFldEdit()) 659 sOldSel.Erase(); 660 661 sal_uInt16 nCnt = pType->GetSeqFldList( aArr ); 662 for( sal_uInt16 n = 0; n < nCnt; ++n ) 663 { 664 aSelectionLB.InsertEntry( aArr[ n ]->sDlgEntry ); 665 if (IsFldEdit() && !sOldSel.Len() && 666 aArr[ n ]->nSeqNo == pRefFld->GetSeqNo()) 667 sOldSel = aArr[ n ]->sDlgEntry; 668 } 669 670 if (IsFldEdit() && !sOldSel.Len()) 671 sOldSel = String::CreateFromInt32( pRefFld->GetSeqNo() + 1); 672 } 673 } 674 } 675 else 676 { 677 SvStringsDtor aLst; 678 GetFldMgr().GetSubTypes(nTypeId, aLst); 679 for (sal_uInt16 i = 0; i < aLst.Count(); ++i) 680 aSelectionLB.InsertEntry(*aLst[i]); 681 682 if (IsFldEdit()) 683 sOldSel = pRefFld->GetSetRefName(); 684 } 685 686 // --> OD 2007-11-21 #i83479# 687 aSelectionToolTipLB.Show( bShowSelectionToolTipLB ); 688 aSelectionLB.Show( !bShowSelectionToolTipLB ); 689 if ( bShowSelectionToolTipLB ) 690 { 691 aSelectionToolTipLB.SetUpdateMode(sal_True); 692 693 sal_Bool bEnable = aSelectionToolTipLB.GetEntryCount() != 0; 694 aSelectionToolTipLB.Enable( bEnable ); 695 aSelectionFT.Enable( bEnable ); 696 697 if ( aSelectionToolTipLB.GetCurEntry() != 0 ) 698 { 699 aSelectionToolTipLB.MakeVisible( aSelectionToolTipLB.GetCurEntry() ); 700 } 701 702 if ( IsFldEdit() && aSelectionToolTipLB.GetCurEntry() == 0 ) 703 { 704 aNameED.SetText(sOldSel); 705 } 706 } 707 else 708 { 709 aSelectionLB.SetUpdateMode(sal_True); 710 711 // Enable oder Disable 712 sal_Bool bEnable = aSelectionLB.GetEntryCount() != 0; 713 aSelectionLB.Enable( bEnable ); 714 aSelectionFT.Enable( bEnable ); 715 716 if ( bEnable ) 717 { 718 aSelectionLB.SelectEntry(sOldSel); 719 if (!aSelectionLB.GetSelectEntryCount() && !IsFldEdit()) 720 aSelectionLB.SelectEntryPos(0); 721 } 722 723 if (IsFldEdit() && !aSelectionLB.GetSelectEntryCount()) // Falls die Referenz schon geloescht wurde... 724 aNameED.SetText(sOldSel); 725 } 726 // <-- 727 } 728 729 /*-------------------------------------------------------------------- 730 Beschreibung: 731 --------------------------------------------------------------------*/ 732 733 sal_uInt16 SwFldRefPage::FillFormatLB(sal_uInt16 nTypeId) 734 { 735 String sOldSel; 736 737 sal_uInt16 nFormatSel = aFormatLB.GetSelectEntryPos(); 738 if (nFormatSel != LISTBOX_ENTRY_NOTFOUND) 739 sOldSel = aFormatLB.GetEntry(nFormatSel); 740 741 // Format-Listbox fuellen 742 aFormatLB.Clear(); 743 744 // Referenz hat weniger als die Beschriftung 745 sal_uInt16 nSize( 0 ); 746 bool bAddCrossRefFormats( false ); 747 switch (nTypeId) 748 { 749 // --> OD 2007-11-16 #i83479# 750 case REFFLDFLAG_HEADING: 751 case REFFLDFLAG_NUMITEM: 752 bAddCrossRefFormats = true; 753 // intentional no break here 754 // <-- 755 756 case TYP_GETREFFLD: 757 case REFFLDFLAG_BOOKMARK: 758 case REFFLDFLAG_FOOTNOTE: 759 case REFFLDFLAG_ENDNOTE: 760 nSize = FMT_REF_PAGE_PGDSC - FMT_REF_BEGIN + 1; 761 break; 762 763 default: 764 // --> OD 2007-11-16 #i83479# 765 // nSize = GetFldMgr().GetFormatCount( (REFFLDFLAG & nTypeId) 766 // ? (sal_uInt16)TYP_GETREFFLD : nTypeId, 767 // sal_False, IsFldDlgHtmlMode() ); 768 if ( REFFLDFLAG & nTypeId ) 769 { 770 nSize = FMT_REF_ONLYSEQNO - FMT_REF_BEGIN + 1; 771 } 772 else 773 { 774 nSize = GetFldMgr().GetFormatCount( nTypeId, sal_False, IsFldDlgHtmlMode() ); 775 } 776 break; 777 } 778 779 if (REFFLDFLAG & nTypeId) 780 nTypeId = TYP_GETREFFLD; 781 782 for (sal_uInt16 i = 0; i < nSize; i++) 783 { 784 sal_uInt16 nPos = aFormatLB.InsertEntry(GetFldMgr().GetFormatStr( nTypeId, i )); 785 aFormatLB.SetEntryData( nPos, reinterpret_cast<void*>(GetFldMgr().GetFormatId( nTypeId, i ))); 786 } 787 // --> OD 2007-11-16 #i83479# 788 if ( bAddCrossRefFormats ) 789 { 790 sal_uInt16 nFormat = FMT_REF_NUMBER - FMT_REF_BEGIN; 791 sal_uInt16 nPos = aFormatLB.InsertEntry(GetFldMgr().GetFormatStr( nTypeId, nFormat )); 792 aFormatLB.SetEntryData( nPos, reinterpret_cast<void*>(GetFldMgr().GetFormatId( nTypeId, nFormat ))); 793 nFormat = FMT_REF_NUMBER_NO_CONTEXT - FMT_REF_BEGIN; 794 nPos = aFormatLB.InsertEntry(GetFldMgr().GetFormatStr( nTypeId, nFormat )); 795 aFormatLB.SetEntryData( nPos, reinterpret_cast<void*>(GetFldMgr().GetFormatId( nTypeId, nFormat ))); 796 nFormat = FMT_REF_NUMBER_FULL_CONTEXT - FMT_REF_BEGIN; 797 nPos = aFormatLB.InsertEntry(GetFldMgr().GetFormatStr( nTypeId, nFormat )); 798 aFormatLB.SetEntryData( nPos, reinterpret_cast<void*>(GetFldMgr().GetFormatId( nTypeId, nFormat ))); 799 nSize += 3; 800 } 801 // <-- 802 803 // select a certain entry 804 if (nSize) 805 { 806 if (!IsFldEdit()) 807 aFormatLB.SelectEntry(sOldSel); 808 else 809 aFormatLB.SelectEntry(SW_RESSTR(FMT_REF_BEGIN + (sal_uInt16)GetCurField()->GetFormat())); 810 811 if (!aFormatLB.GetSelectEntryCount()) 812 { 813 aFormatLB.SelectEntryPos(nFldDlgFmtSel); 814 if (!aFormatLB.GetSelectEntryCount()) 815 aFormatLB.SelectEntryPos(0); 816 } 817 } 818 819 return nSize; 820 } 821 822 /*-------------------------------------------------------------------- 823 Beschreibung: Modify 824 --------------------------------------------------------------------*/ 825 826 IMPL_LINK( SwFldRefPage, ModifyHdl, Edit *, EMPTYARG ) 827 { 828 String aName(aNameED.GetText()); 829 const sal_uInt16 nLen = aName.Len(); 830 831 sal_Bool bEnable = sal_True; 832 sal_uInt16 nTypeId = (sal_uInt16)(sal_uLong)aTypeLB.GetEntryData(GetTypeSel()); 833 834 if ((nTypeId == TYP_SETREFFLD && !GetFldMgr().CanInsertRefMark(aName)) || 835 (nLen == 0 && (nTypeId == TYP_GETREFFLD || nTypeId == TYP_SETREFFLD || 836 nTypeId == REFFLDFLAG_BOOKMARK))) 837 bEnable = sal_False; 838 839 EnableInsert(bEnable); 840 841 aSelectionLB.SelectEntry(aName); 842 843 return 0; 844 } 845 846 /*-------------------------------------------------------------------- 847 Beschreibung: 848 --------------------------------------------------------------------*/ 849 850 sal_Bool SwFldRefPage::FillItemSet(SfxItemSet& ) 851 { 852 sal_Bool bModified = sal_False; 853 sal_uInt16 nTypeId = (sal_uInt16)(sal_uLong)aTypeLB.GetEntryData(GetTypeSel()); 854 855 sal_uInt16 nSubType = 0; 856 sal_uLong nFormat; 857 858 nFormat = aFormatLB.GetSelectEntryPos(); 859 860 if(nFormat == LISTBOX_ENTRY_NOTFOUND) 861 nFormat = 0; 862 else 863 nFormat = (sal_uLong)aFormatLB.GetEntryData((sal_uInt16)nFormat); 864 865 String aVal(aValueED.GetText()); 866 String aName(aNameED.GetText()); 867 868 switch(nTypeId) 869 { 870 case TYP_GETREFFLD: 871 // aName = aSelectionLB.GetSelectEntry(); 872 nSubType = REF_SETREFATTR; 873 break; 874 875 case TYP_SETREFFLD: 876 { 877 SwFieldType* pType = GetFldMgr().GetFldType(RES_SETEXPFLD, aName); 878 879 if(!pType) // Nur einfuegen, wenn es den Namen noch nicht gibt 880 { 881 aSelectionLB.InsertEntry(aName); 882 aSelectionLB.Enable(); 883 aSelectionFT.Enable(); 884 } 885 break; 886 } 887 } 888 889 SwGetRefField* pRefFld = (SwGetRefField*)GetCurField(); 890 891 if (REFFLDFLAG & nTypeId) 892 { 893 SwWrtShell *pSh = GetWrtShell(); 894 if(!pSh) 895 { 896 pSh = ::GetActiveWrtShell(); 897 } 898 if (nTypeId == REFFLDFLAG_BOOKMARK) // TextMarken! 899 { 900 aName = aNameED.GetText(); 901 nTypeId = TYP_GETREFFLD; 902 nSubType = REF_BOOKMARK; 903 } 904 else if (REFFLDFLAG_FOOTNOTE == nTypeId) // Fussnoten 905 { 906 SwSeqFldList aArr; 907 _SeqFldLstElem aElem( aSelectionLB.GetSelectEntry(), 0 ); 908 909 sal_uInt16 nPos; 910 911 nTypeId = TYP_GETREFFLD; 912 nSubType = REF_FOOTNOTE; 913 aName.Erase(); 914 915 if (pSh->GetSeqFtnList(aArr) && aArr.SeekEntry(aElem, &nPos)) 916 { 917 aVal = String::CreateFromInt32( aArr[nPos]->nSeqNo ); 918 919 if (IsFldEdit() && aArr[nPos]->nSeqNo == pRefFld->GetSeqNo()) 920 bModified = sal_True; // Kann bei Feldern passieren, deren Referenz geloescht wurde 921 } 922 else if (IsFldEdit()) 923 aVal = String::CreateFromInt32( pRefFld->GetSeqNo() ); 924 } 925 else if (REFFLDFLAG_ENDNOTE == nTypeId) // Endnoten 926 { 927 SwSeqFldList aArr; 928 _SeqFldLstElem aElem( aSelectionLB.GetSelectEntry(), 0 ); 929 930 sal_uInt16 nPos; 931 932 nTypeId = TYP_GETREFFLD; 933 nSubType = REF_ENDNOTE; 934 aName.Erase(); 935 936 if (pSh->GetSeqFtnList(aArr, true) && aArr.SeekEntry(aElem, &nPos)) 937 { 938 aVal = String::CreateFromInt32( aArr[nPos]->nSeqNo ); 939 940 if (IsFldEdit() && aArr[nPos]->nSeqNo == pRefFld->GetSeqNo()) 941 bModified = sal_True; // Kann bei Feldern passieren, deren Referenz geloescht wurde 942 } 943 else if (IsFldEdit()) 944 aVal = String::CreateFromInt32( pRefFld->GetSeqNo() ); 945 } 946 // --> OD 2007-11-16 #i83479# 947 else if ( nTypeId == REFFLDFLAG_HEADING ) 948 { 949 SvLBoxEntry* pEntry = aSelectionToolTipLB.GetCurEntry(); 950 ASSERT( pEntry, 951 "<SwFldRefPage::FillItemSet(..)> - no entry selected in selection tool tip listbox!" ); 952 if ( pEntry ) 953 { 954 const sal_uInt16 nOutlIdx( static_cast<sal_uInt16>(reinterpret_cast<sal_uLong>(pEntry->GetUserData())) ); 955 pSh->getIDocumentOutlineNodesAccess()->getOutlineNodes( maOutlineNodes ); 956 if ( nOutlIdx < maOutlineNodes.size() ) 957 { 958 ::sw::mark::IMark const * const pMark = pSh->getIDocumentMarkAccess()->getMarkForTxtNode( 959 *(maOutlineNodes[nOutlIdx]), 960 IDocumentMarkAccess::CROSSREF_HEADING_BOOKMARK); 961 aName = pMark->GetName(); 962 nTypeId = TYP_GETREFFLD; 963 nSubType = REF_BOOKMARK; 964 } 965 } 966 } 967 else if ( nTypeId == REFFLDFLAG_NUMITEM ) 968 { 969 SvLBoxEntry* pEntry = aSelectionToolTipLB.GetCurEntry(); 970 ASSERT( pEntry, 971 "<SwFldRefPage::FillItemSet(..)> - no entry selected in selection tool tip listbox!" ); 972 if ( pEntry ) 973 { 974 const sal_uInt16 nNumItemIdx( static_cast<sal_uInt16>(reinterpret_cast<sal_uLong>(pEntry->GetUserData())) ); 975 pSh->getIDocumentListItemsAccess()->getNumItems( maNumItems ); 976 if ( nNumItemIdx < maNumItems.size() ) 977 { 978 ::sw::mark::IMark const * const pMark = pSh->getIDocumentMarkAccess()->getMarkForTxtNode( 979 *(maNumItems[nNumItemIdx]->GetTxtNode()), 980 IDocumentMarkAccess::CROSSREF_NUMITEM_BOOKMARK); 981 aName = pMark->GetName(); 982 nTypeId = TYP_GETREFFLD; 983 nSubType = REF_BOOKMARK; 984 } 985 } 986 } 987 // <-- 988 else // SeqenceFelder 989 { 990 // zum Seq-FeldTyp die Felder besorgen: 991 SwSetExpFieldType* pType = (SwSetExpFieldType*)pSh->GetFldType( 992 nTypeId & ~REFFLDFLAG, RES_SETEXPFLD ); 993 if( pType ) 994 { 995 SwSeqFldList aArr; 996 _SeqFldLstElem aElem( aSelectionLB.GetSelectEntry(), 0 ); 997 998 sal_uInt16 nPos; 999 1000 nTypeId = TYP_GETREFFLD; 1001 nSubType = REF_SEQUENCEFLD; 1002 aName = pType->GetName(); 1003 1004 if (pType->GetSeqFldList(aArr) && aArr.SeekEntry(aElem, &nPos)) 1005 { 1006 aVal = String::CreateFromInt32( aArr[nPos]->nSeqNo ); 1007 1008 if (IsFldEdit() && aArr[nPos]->nSeqNo == pRefFld->GetSeqNo()) 1009 bModified = sal_True; // Kann bei Feldern passieren, deren Referenz geloescht wurde 1010 } 1011 else if (IsFldEdit()) 1012 aVal = String::CreateFromInt32( pRefFld->GetSeqNo() ); 1013 } 1014 } 1015 } 1016 1017 if (IsFldEdit() && nTypeId == TYP_GETREFFLD) 1018 { 1019 aVal.Insert('|', 0); 1020 aVal.Insert(String::CreateFromInt32(nSubType), 0); 1021 } 1022 1023 if (!IsFldEdit() || bModified || 1024 aNameED.GetSavedValue() != aNameED.GetText() || 1025 aValueED.GetSavedValue() != aValueED.GetText() || 1026 aTypeLB.GetSavedValue() != aTypeLB.GetSelectEntryPos() || 1027 aSelectionLB.GetSavedValue() != aSelectionLB.GetSelectEntryPos() || 1028 aFormatLB.GetSavedValue() != aFormatLB.GetSelectEntryPos()) 1029 { 1030 InsertFld( nTypeId, nSubType, aName, aVal, nFormat ); 1031 } 1032 1033 ModifyHdl(); // Insert ggf enablen/disablen 1034 1035 return sal_False; 1036 } 1037 1038 /*-------------------------------------------------------------------- 1039 Beschreibung: 1040 --------------------------------------------------------------------*/ 1041 1042 SfxTabPage* SwFldRefPage::Create( Window* pParent, 1043 const SfxItemSet& rAttrSet ) 1044 { 1045 return ( new SwFldRefPage( pParent, rAttrSet ) ); 1046 } 1047 1048 /*-------------------------------------------------------------------- 1049 Beschreibung: 1050 --------------------------------------------------------------------*/ 1051 1052 sal_uInt16 SwFldRefPage::GetGroup() 1053 { 1054 return GRP_REF; 1055 } 1056 1057 /* -----------------12.01.99 10:09------------------- 1058 * 1059 * --------------------------------------------------*/ 1060 void SwFldRefPage::FillUserData() 1061 { 1062 String sData( String::CreateFromAscii( 1063 RTL_CONSTASCII_STRINGPARAM( USER_DATA_VERSION ))); 1064 sData += ';'; 1065 sal_uInt16 nTypeSel = aTypeLB.GetSelectEntryPos(); 1066 if( LISTBOX_ENTRY_NOTFOUND == nTypeSel ) 1067 nTypeSel = USHRT_MAX; 1068 else 1069 nTypeSel = sal::static_int_cast< sal_uInt16 >(reinterpret_cast< sal_uIntPtr >(aTypeLB.GetEntryData( nTypeSel ))); 1070 sData += String::CreateFromInt32( nTypeSel ); 1071 SetUserData(sData); 1072 } 1073 1074