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