update dev300-m58
[ooovba.git] / sw / source / ui / fldui / fldref.cxx
blob886ea2704c472e8e352f6d3ee0a2ccbc400004ad
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fldref.cxx,v $
10 * $Revision: 1.12.214.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
34 #ifdef SW_DLLIMPLEMENTATION
35 #undef SW_DLLIMPLEMENTATION
36 #endif
40 #include "swtypes.hxx"
41 #include <view.hxx>
42 #include <IMark.hxx>
43 #include <expfld.hxx>
44 #include <swmodule.hxx>
45 #ifndef _FLDREF_HXX
46 #include <fldref.hxx>
47 #endif
48 #include <reffld.hxx>
49 #include <wrtsh.hxx>
51 #ifndef _FLDUI_HRC
52 #include <fldui.hrc>
53 #endif
54 #ifndef _FLDTDLG_HRC
55 #include <fldtdlg.hrc>
56 #endif
57 #ifndef _GLOBALS_HRC
58 #include <globals.hrc>
59 #endif
60 // --> OD 2007-11-14 #i83479#
61 #include <SwNodeNum.hxx>
62 #include <IDocumentMarkAccess.hxx>
63 #include <ndtxt.hxx>
64 // <--
66 // sw/inc/expfld.hxx
67 SV_IMPL_PTRARR( _SwSeqFldList, _SeqFldLstElem* )
69 #define REFFLDFLAG 0x4000
70 #define REFFLDFLAG_BOOKMARK 0x4800
71 #define REFFLDFLAG_FOOTNOTE 0x5000
72 #define REFFLDFLAG_ENDNOTE 0x6000
73 // --> OD 2007-11-09 #i83479#
74 #define REFFLDFLAG_HEADING 0x7100
75 #define REFFLDFLAG_NUMITEM 0x7200
76 // <--
78 USHORT nFldDlgFmtSel = 0;
80 #define USER_DATA_VERSION_1 "1"
81 #define USER_DATA_VERSION USER_DATA_VERSION_1
84 /*--------------------------------------------------------------------
85 Beschreibung:
86 --------------------------------------------------------------------*/
88 SwFldRefPage::SwFldRefPage(Window* pParent, const SfxItemSet& rCoreSet ) :
89 SwFldPage( pParent, SW_RES( TP_FLD_REF ), rCoreSet ),
91 aTypeFT (this, SW_RES(FT_REFTYPE)),
92 aTypeLB (this, SW_RES(LB_REFTYPE)),
93 aSelectionFT (this, SW_RES(FT_REFSELECTION)),
94 aSelectionLB (this, SW_RES(LB_REFSELECTION)),
95 // --> OD 2007-11-21 #i83479#
96 aSelectionToolTipLB( this, SW_RES(LB_REFSELECTION_TOOLTIP) ),
97 // <--
98 aFormatFT (this, SW_RES(FT_REFFORMAT)),
99 aFormatLB (this, SW_RES(LB_REFFORMAT)),
100 aNameFT (this, SW_RES(FT_REFNAME)),
101 aNameED (this, SW_RES(ED_REFNAME)),
102 aValueFT (this, SW_RES(FT_REFVALUE)),
103 aValueED (this, SW_RES(ED_REFVALUE)),
105 sBookmarkTxt (SW_RES(STR_REFBOOKMARK)),
106 sFootnoteTxt (SW_RES(STR_REFFOOTNOTE)),
107 sEndnoteTxt (SW_RES(STR_REFENDNOTE)),
108 // --> OD 2007-11-09 #i83479#
109 sHeadingTxt (SW_RES(STR_REFHEADING)),
110 sNumItemTxt (SW_RES(STR_REFNUMITEM)),
111 maOutlineNodes(),
112 maNumItems(),
113 mpSavedSelectedTxtNode( 0 ),
114 mnSavedSelectedPos( 0 )
115 // <--
117 FreeResource();
119 aNameED.SetModifyHdl(LINK(this, SwFldRefPage, ModifyHdl));
121 aTypeLB.SetDoubleClickHdl (LINK(this, SwFldRefPage, InsertHdl));
122 aTypeLB.SetSelectHdl (LINK(this, SwFldRefPage, TypeHdl));
123 aSelectionLB.SetSelectHdl (LINK(this, SwFldRefPage, SubTypeHdl));
124 aSelectionLB.SetDoubleClickHdl (LINK(this, SwFldRefPage, InsertHdl));
125 aFormatLB.SetDoubleClickHdl (LINK(this, SwFldRefPage, InsertHdl));
127 // --> OD 2007-11-21 #i83479#
128 aSelectionToolTipLB.SetSelectHdl( LINK(this, SwFldRefPage, SubTypeHdl) );
129 aSelectionToolTipLB.SetDoubleClickHdl( LINK(this, SwFldRefPage, InsertHdl) );
130 aSelectionToolTipLB.SetWindowBits( aSelectionToolTipLB.GetWindowBits() | WB_HSCROLL );
131 aSelectionToolTipLB.SetSpaceBetweenEntries(1);
132 aSelectionToolTipLB.SetHighlightRange();
133 // <--
136 /*--------------------------------------------------------------------
137 Beschreibung:
138 --------------------------------------------------------------------*/
140 SwFldRefPage::~SwFldRefPage()
144 // --> OD 2007-11-22 #i83479#
145 void SwFldRefPage::SaveSelectedTxtNode()
147 mpSavedSelectedTxtNode = 0;
148 mnSavedSelectedPos = 0;
149 if ( aSelectionToolTipLB.IsVisible() )
151 SvLBoxEntry* pEntry = aSelectionToolTipLB.GetCurEntry();
152 if ( pEntry )
154 const USHORT nTypeId = (USHORT)(ULONG)aTypeLB.GetEntryData(GetTypeSel());
155 SwWrtShell *pSh = GetWrtShell();
156 if ( !pSh )
158 pSh = ::GetActiveWrtShell();
160 if ( nTypeId == REFFLDFLAG_HEADING )
162 mnSavedSelectedPos = static_cast<sal_uInt16>(reinterpret_cast<ULONG>(pEntry->GetUserData()));
163 if ( mnSavedSelectedPos < maOutlineNodes.size() )
165 mpSavedSelectedTxtNode = maOutlineNodes[mnSavedSelectedPos];
168 else if ( nTypeId == REFFLDFLAG_NUMITEM )
170 mnSavedSelectedPos = static_cast<sal_uInt16>(reinterpret_cast<ULONG>(pEntry->GetUserData()));
171 if ( mnSavedSelectedPos < maNumItems.size() )
173 mpSavedSelectedTxtNode = maNumItems[mnSavedSelectedPos]->GetTxtNode();
180 const SwTxtNode* SwFldRefPage::GetSavedSelectedTxtNode() const
182 return mpSavedSelectedTxtNode;
185 sal_uInt16 SwFldRefPage::GetSavedSelectedPos() const
187 return mnSavedSelectedPos;
190 // <--
192 /*--------------------------------------------------------------------
193 Beschreibung:
194 --------------------------------------------------------------------*/
196 void SwFldRefPage::Reset(const SfxItemSet& )
198 if (!IsFldEdit())
200 SavePos(&aTypeLB);
201 // --> OD 2007-11-22 #i83479#
202 SaveSelectedTxtNode();
203 // <--
205 SetSelectionSel(LISTBOX_ENTRY_NOTFOUND);
206 SetTypeSel(LISTBOX_ENTRY_NOTFOUND);
207 Init(); // Allgemeine initialisierung
209 // TypeListBox initialisieren
210 aTypeLB.SetUpdateMode(FALSE);
211 aTypeLB.Clear();
213 // Typ-Listbox fuellen
215 USHORT nPos;
216 // Referenz setzen / einfuegen
217 const SwFldGroupRgn& rRg = GetFldMgr().GetGroupRange(IsFldDlgHtmlMode(), GetGroup());
219 for (short i = rRg.nStart; i < rRg.nEnd; ++i)
221 const USHORT nTypeId = GetFldMgr().GetTypeId(i);
223 if (!IsFldEdit() || nTypeId != TYP_SETREFFLD)
225 nPos = aTypeLB.InsertEntry(GetFldMgr().GetTypeStr(i), i - rRg.nStart);
226 aTypeLB.SetEntryData(nPos, reinterpret_cast<void*>(nTypeId));
230 // --> OD 2007-11-09 #i83479#
231 // entries for headings and numbered items
232 nPos = aTypeLB.InsertEntry(sHeadingTxt);
233 aTypeLB.SetEntryData(nPos, (void*)REFFLDFLAG_HEADING);
234 nPos = aTypeLB.InsertEntry(sNumItemTxt);
235 aTypeLB.SetEntryData(nPos, (void*)REFFLDFLAG_NUMITEM);
236 // <--
238 // mit den Sequence-Typen auffuellen
239 SwWrtShell *pSh = GetWrtShell();
240 if(!pSh)
241 pSh = ::GetActiveWrtShell();
243 USHORT nFldTypeCnt = pSh->GetFldTypeCount(RES_SETEXPFLD);
245 for (USHORT n = 0; n < nFldTypeCnt; ++n)
247 SwSetExpFieldType* pType = (SwSetExpFieldType*)pSh->GetFldType(n, RES_SETEXPFLD);
249 if ((nsSwGetSetExpType::GSE_SEQ & pType->GetType()) && pType->GetDepends() && pSh->IsUsed(*pType))
251 nPos = aTypeLB.InsertEntry(pType->GetName());
252 aTypeLB.SetEntryData(nPos, (void*)(REFFLDFLAG | n));
256 // Textmarken - jetzt immer (wegen Globaldokumenten)
257 nPos = aTypeLB.InsertEntry(sBookmarkTxt);
258 aTypeLB.SetEntryData(nPos, (void*)REFFLDFLAG_BOOKMARK);
260 // Fussnoten:
261 if( pSh->HasFtns() )
263 nPos = aTypeLB.InsertEntry(sFootnoteTxt);
264 aTypeLB.SetEntryData(nPos, (void*)REFFLDFLAG_FOOTNOTE);
267 // Endnoten:
268 if ( pSh->HasFtns(true) )
270 nPos = aTypeLB.InsertEntry(sEndnoteTxt);
271 aTypeLB.SetEntryData(nPos, (void*)REFFLDFLAG_ENDNOTE);
274 // alte Pos selektieren
275 if (!IsFldEdit())
276 RestorePos(&aTypeLB);
278 aTypeLB.SetUpdateMode(TRUE);
280 nFldDlgFmtSel = 0;
282 if( !IsRefresh() )
284 String sUserData = GetUserData();
285 if(!IsRefresh() && sUserData.GetToken(0, ';').
286 EqualsIgnoreCaseAscii(USER_DATA_VERSION_1))
288 String sVal = sUserData.GetToken(1, ';');
289 USHORT nVal = static_cast< USHORT >(sVal.ToInt32());
290 if(nVal != USHRT_MAX)
292 for(USHORT i = 0; i < aTypeLB.GetEntryCount(); i++)
293 if(nVal == (USHORT)(ULONG)aTypeLB.GetEntryData(i))
295 aTypeLB.SelectEntryPos(i);
296 break;
301 TypeHdl(0);
303 if (IsFldEdit())
305 aTypeLB.SaveValue();
306 aSelectionLB.SaveValue();
307 aFormatLB.SaveValue();
308 aNameED.SaveValue();
309 aValueED.SaveValue();
313 /*--------------------------------------------------------------------
314 Beschreibung:
315 --------------------------------------------------------------------*/
317 IMPL_LINK( SwFldRefPage, TypeHdl, ListBox *, EMPTYARG )
319 // Alte ListBoxPos sichern
320 const USHORT nOld = GetTypeSel();
322 // Aktuelle ListBoxPos
323 SetTypeSel(aTypeLB.GetSelectEntryPos());
325 if(GetTypeSel() == LISTBOX_ENTRY_NOTFOUND)
327 if (IsFldEdit())
329 // Positionen selektieren
330 String sName;
331 USHORT nFlag = 0;
333 switch( GetCurField()->GetSubType() )
335 case REF_BOOKMARK:
337 // --> OD 2007-11-14 #i83479#
338 // sName = sBookmarkTxt;
339 // nFlag = REFFLDFLAG_BOOKMARK;
340 SwGetRefField* pRefFld = dynamic_cast<SwGetRefField*>(GetCurField());
341 if ( pRefFld &&
342 pRefFld->IsRefToHeadingCrossRefBookmark() )
344 sName = sHeadingTxt;
345 nFlag = REFFLDFLAG_HEADING;
347 else if ( pRefFld &&
348 pRefFld->IsRefToNumItemCrossRefBookmark() )
350 sName = sNumItemTxt;
351 nFlag = REFFLDFLAG_NUMITEM;
353 else
355 sName = sBookmarkTxt;
356 nFlag = REFFLDFLAG_BOOKMARK;
358 // <--
360 break;
362 case REF_FOOTNOTE:
363 sName = sFootnoteTxt;
364 nFlag = REFFLDFLAG_FOOTNOTE;
365 break;
367 case REF_ENDNOTE:
368 sName = sEndnoteTxt;
369 nFlag = REFFLDFLAG_ENDNOTE;
370 break;
372 case REF_SETREFATTR:
373 sName = SW_RESSTR(STR_GETREFFLD);
374 nFlag = REF_SETREFATTR;
375 break;
377 case REF_SEQUENCEFLD:
378 sName = ((SwGetRefField*)GetCurField())->GetSetRefName();
379 nFlag = REFFLDFLAG;
380 break;
383 if (aTypeLB.GetEntryPos(sName) == LISTBOX_ENTRY_NOTFOUND) // Referenz zu gel?schter Marke
385 USHORT nPos = aTypeLB.InsertEntry(sName);
386 aTypeLB.SetEntryData(nPos, reinterpret_cast<void*>(nFlag));
389 aTypeLB.SelectEntry(sName);
390 SetTypeSel(aTypeLB.GetSelectEntryPos());
392 else
394 SetTypeSel(0);
395 aTypeLB.SelectEntryPos(0);
399 if (nOld != GetTypeSel())
401 USHORT nTypeId = (USHORT)(ULONG)aTypeLB.GetEntryData(GetTypeSel());
403 // Auswahl-Listbox fuellen
404 UpdateSubType();
406 BOOL bName = FALSE; nFldDlgFmtSel = 0;
408 if ( ( !IsFldEdit() || aSelectionLB.GetEntryCount() ) &&
409 nOld != LISTBOX_ENTRY_NOTFOUND )
411 aNameED.SetText(aEmptyStr);
412 aValueED.SetText(aEmptyStr);
415 switch (nTypeId)
417 case TYP_GETREFFLD:
418 if (REFFLDFLAG & (USHORT)(ULONG)aTypeLB.GetEntryData(nOld))
419 // dann bleibt die alte bestehen
420 nFldDlgFmtSel = aFormatLB.GetSelectEntryPos();
421 bName = TRUE;
422 break;
424 case TYP_SETREFFLD:
425 bName = TRUE;
426 break;
428 case REFFLDFLAG_BOOKMARK:
429 bName = TRUE;
430 // kein break!!!
431 default:
432 if( REFFLDFLAG & nTypeId )
434 USHORT nOldId = (USHORT)(ULONG)aTypeLB.GetEntryData(nOld);
435 if( nOldId & REFFLDFLAG || nOldId == TYP_GETREFFLD )
436 // dann bleibt die alte bestehen
437 nFldDlgFmtSel = aFormatLB.GetSelectEntryPos();
439 break;
442 aNameED.Enable(bName);
443 aNameFT.Enable(bName);
445 // Format-Listbox fuellen
446 USHORT nSize = FillFormatLB(nTypeId);
447 BOOL bFormat = nSize != 0;
448 aFormatLB.Enable(bFormat);
449 aFormatFT.Enable(bFormat);
451 SubTypeHdl();
452 ModifyHdl();
455 return 0;
458 /*--------------------------------------------------------------------
459 Beschreibung:
460 --------------------------------------------------------------------*/
462 IMPL_LINK( SwFldRefPage, SubTypeHdl, ListBox *, EMPTYARG )
464 USHORT nTypeId = (USHORT)(ULONG)aTypeLB.GetEntryData(GetTypeSel());
466 switch(nTypeId)
468 case TYP_GETREFFLD:
469 if (!IsFldEdit() || aSelectionLB.GetSelectEntryCount())
471 aNameED.SetText(aSelectionLB.GetSelectEntry());
472 ModifyHdl(&aNameED);
474 break;
476 case TYP_SETREFFLD:
478 SwWrtShell *pSh = GetWrtShell();
479 if(!pSh)
480 pSh = ::GetActiveWrtShell();
481 if(pSh)
483 aValueED.SetText(pSh->GetSelTxt());
487 break;
488 // --> OD 2007-11-21 #i83479#
489 case REFFLDFLAG_HEADING:
490 case REFFLDFLAG_NUMITEM:
492 if ( aSelectionToolTipLB.GetCurEntry() )
494 aNameED.SetText( aSelectionToolTipLB.GetEntryText(
495 aSelectionToolTipLB.GetCurEntry() ) );
498 break;
499 // <--
501 default:
502 if (!IsFldEdit() || aSelectionLB.GetSelectEntryCount())
503 aNameED.SetText(aSelectionLB.GetSelectEntry());
504 break;
507 return 0;
510 /*--------------------------------------------------------------------
511 Beschreibung: Typen in SelectionLB erneuern
512 --------------------------------------------------------------------*/
514 void SwFldRefPage::UpdateSubType()
516 SwWrtShell *pSh = GetWrtShell();
517 if(!pSh)
518 pSh = ::GetActiveWrtShell();
519 SwGetRefField* pRefFld = (SwGetRefField*)GetCurField();
520 const USHORT nTypeId = (USHORT)(ULONG)aTypeLB.GetEntryData(GetTypeSel());
522 String sOldSel;
523 // --> OD 2007-11-22 #i83479#
524 if ( aSelectionLB.IsVisible() )
526 const USHORT nSelectionSel = aSelectionLB.GetSelectEntryPos();
527 if (nSelectionSel != LISTBOX_ENTRY_NOTFOUND)
529 sOldSel = aSelectionLB.GetEntry(nSelectionSel);
532 // <--
533 if (IsFldEdit() && !sOldSel.Len())
534 sOldSel = String::CreateFromInt32( pRefFld->GetSeqNo() + 1 );
536 aSelectionLB.SetUpdateMode(FALSE);
537 aSelectionLB.Clear();
538 // --> OD 2007-11-21 #i83479#
539 aSelectionToolTipLB.SetUpdateMode(FALSE);
540 aSelectionToolTipLB.Clear();
541 bool bShowSelectionToolTipLB( false );
542 // <--
544 if( REFFLDFLAG & nTypeId )
546 if (nTypeId == REFFLDFLAG_BOOKMARK) // TextMarken!
548 aSelectionLB.SetStyle(aSelectionLB.GetStyle()|WB_SORT);
549 // alle Textmarken besorgen
550 IDocumentMarkAccess* const pMarkAccess = pSh->getIDocumentMarkAccess();
551 for(IDocumentMarkAccess::const_iterator_t ppMark = pMarkAccess->getBookmarksBegin();
552 ppMark != pMarkAccess->getBookmarksEnd();
553 ppMark++)
555 const ::sw::mark::IMark* pBkmk = ppMark->get();
556 if(IDocumentMarkAccess::BOOKMARK == IDocumentMarkAccess::GetType(*pBkmk))
557 aSelectionLB.InsertEntry( pBkmk->GetName() );
559 if (IsFldEdit())
560 sOldSel = pRefFld->GetSetRefName();
562 else if (nTypeId == REFFLDFLAG_FOOTNOTE)
564 aSelectionLB.SetStyle(aSelectionLB.GetStyle() & ~WB_SORT);
565 SwSeqFldList aArr;
566 USHORT nCnt = pSh->GetSeqFtnList( aArr );
568 for( USHORT n = 0; n < nCnt; ++n )
570 aSelectionLB.InsertEntry( aArr[ n ]->sDlgEntry );
571 if (IsFldEdit() && pRefFld->GetSeqNo() == aArr[ n ]->nSeqNo)
572 sOldSel = aArr[n]->sDlgEntry;
575 else if (nTypeId == REFFLDFLAG_ENDNOTE)
577 aSelectionLB.SetStyle(aSelectionLB.GetStyle() & ~WB_SORT);
578 SwSeqFldList aArr;
579 USHORT nCnt = pSh->GetSeqFtnList( aArr, true );
581 for( USHORT n = 0; n < nCnt; ++n )
583 aSelectionLB.InsertEntry( aArr[ n ]->sDlgEntry );
584 if (IsFldEdit() && pRefFld->GetSeqNo() == aArr[ n ]->nSeqNo)
585 sOldSel = aArr[n]->sDlgEntry;
588 // --> OD 2007-11-14 #i83479#
589 else if ( nTypeId == REFFLDFLAG_HEADING )
591 bShowSelectionToolTipLB = true;
593 const IDocumentOutlineNodes* pIDoc( pSh->getIDocumentOutlineNodesAccess() );
594 pIDoc->getOutlineNodes( maOutlineNodes );
595 bool bCertainTxtNodeSelected( false );
596 SvLBoxEntry* pEntry = 0;
597 sal_uInt16 nOutlIdx = 0;
598 for ( nOutlIdx = 0; nOutlIdx < maOutlineNodes.size(); ++nOutlIdx )
600 pEntry = aSelectionToolTipLB.InsertEntry(
601 pIDoc->getOutlineText( nOutlIdx, true, true ) );
602 pEntry->SetUserData( reinterpret_cast<void*>(nOutlIdx) );
603 if ( ( IsFldEdit() &&
604 pRefFld->GetReferencedTxtNode() == maOutlineNodes[nOutlIdx] ) ||
605 GetSavedSelectedTxtNode() == maOutlineNodes[nOutlIdx] )
607 aSelectionToolTipLB.Select( pEntry );
608 sOldSel.Erase();
609 bCertainTxtNodeSelected = true;
611 else if ( !bCertainTxtNodeSelected &&
612 GetSavedSelectedPos() == nOutlIdx )
614 aSelectionToolTipLB.Select( pEntry );
615 sOldSel.Erase();
619 else if ( nTypeId == REFFLDFLAG_NUMITEM )
621 bShowSelectionToolTipLB = true;
623 const IDocumentListItems* pIDoc( pSh->getIDocumentListItemsAccess() );
624 pIDoc->getNumItems( maNumItems );
625 bool bCertainTxtNodeSelected( false );
626 SvLBoxEntry* pEntry = 0;
627 sal_uInt16 nNumItemIdx = 0;
628 for ( nNumItemIdx = 0; nNumItemIdx < maNumItems.size(); ++nNumItemIdx )
630 pEntry = aSelectionToolTipLB.InsertEntry(
631 pIDoc->getListItemText( *maNumItems[nNumItemIdx], true, true ) );
632 pEntry->SetUserData( reinterpret_cast<void*>(nNumItemIdx) );
633 if ( ( IsFldEdit() &&
634 pRefFld->GetReferencedTxtNode() == maNumItems[nNumItemIdx]->GetTxtNode() ) ||
635 GetSavedSelectedTxtNode() == maNumItems[nNumItemIdx]->GetTxtNode() )
637 aSelectionToolTipLB.Select( pEntry );
638 sOldSel.Erase();
639 bCertainTxtNodeSelected = true;
641 else if ( !bCertainTxtNodeSelected &&
642 GetSavedSelectedPos() == nNumItemIdx )
644 aSelectionToolTipLB.Select( pEntry );
645 sOldSel.Erase();
649 // <--
650 else
652 aSelectionLB.SetStyle(aSelectionLB.GetStyle()|WB_SORT);
653 // zum Seq-FeldTyp die Felder besorgen:
655 SwSetExpFieldType* pType = (SwSetExpFieldType*)pSh->GetFldType(
656 nTypeId & ~REFFLDFLAG, RES_SETEXPFLD );
657 if( pType )
659 SwSeqFldList aArr;
660 // old selection should be kept in non-edit mode
661 if(IsFldEdit())
662 sOldSel.Erase();
664 USHORT nCnt = pType->GetSeqFldList( aArr );
665 for( USHORT n = 0; n < nCnt; ++n )
667 aSelectionLB.InsertEntry( aArr[ n ]->sDlgEntry );
668 if (IsFldEdit() && !sOldSel.Len() &&
669 aArr[ n ]->nSeqNo == pRefFld->GetSeqNo())
670 sOldSel = aArr[ n ]->sDlgEntry;
673 if (IsFldEdit() && !sOldSel.Len())
674 sOldSel = String::CreateFromInt32( pRefFld->GetSeqNo() + 1);
678 else
680 SvStringsDtor aLst;
681 GetFldMgr().GetSubTypes(nTypeId, aLst);
682 for (USHORT i = 0; i < aLst.Count(); ++i)
683 aSelectionLB.InsertEntry(*aLst[i]);
685 if (IsFldEdit())
686 sOldSel = pRefFld->GetSetRefName();
689 // --> OD 2007-11-21 #i83479#
690 aSelectionToolTipLB.Show( bShowSelectionToolTipLB );
691 aSelectionLB.Show( !bShowSelectionToolTipLB );
692 if ( bShowSelectionToolTipLB )
694 aSelectionToolTipLB.SetUpdateMode(TRUE);
696 BOOL bEnable = aSelectionToolTipLB.GetEntryCount() != 0;
697 aSelectionToolTipLB.Enable( bEnable );
698 aSelectionFT.Enable( bEnable );
700 if ( aSelectionToolTipLB.GetCurEntry() != 0 )
702 aSelectionToolTipLB.MakeVisible( aSelectionToolTipLB.GetCurEntry() );
705 if ( IsFldEdit() && aSelectionToolTipLB.GetCurEntry() == 0 )
707 aNameED.SetText(sOldSel);
710 else
712 aSelectionLB.SetUpdateMode(TRUE);
714 // Enable oder Disable
715 BOOL bEnable = aSelectionLB.GetEntryCount() != 0;
716 aSelectionLB.Enable( bEnable );
717 aSelectionFT.Enable( bEnable );
719 if ( bEnable )
721 aSelectionLB.SelectEntry(sOldSel);
722 if (!aSelectionLB.GetSelectEntryCount() && !IsFldEdit())
723 aSelectionLB.SelectEntryPos(0);
726 if (IsFldEdit() && !aSelectionLB.GetSelectEntryCount()) // Falls die Referenz schon geloescht wurde...
727 aNameED.SetText(sOldSel);
729 // <--
732 /*--------------------------------------------------------------------
733 Beschreibung:
734 --------------------------------------------------------------------*/
736 USHORT SwFldRefPage::FillFormatLB(USHORT nTypeId)
738 String sOldSel;
740 USHORT nFormatSel = aFormatLB.GetSelectEntryPos();
741 if (nFormatSel != LISTBOX_ENTRY_NOTFOUND)
742 sOldSel = aFormatLB.GetEntry(nFormatSel);
744 // Format-Listbox fuellen
745 aFormatLB.Clear();
747 // Referenz hat weniger als die Beschriftung
748 USHORT nSize( 0 );
749 bool bAddCrossRefFormats( false );
750 switch (nTypeId)
752 // --> OD 2007-11-16 #i83479#
753 case REFFLDFLAG_HEADING:
754 case REFFLDFLAG_NUMITEM:
755 bAddCrossRefFormats = true;
756 // intentional no break here
757 // <--
759 case TYP_GETREFFLD:
760 case REFFLDFLAG_BOOKMARK:
761 case REFFLDFLAG_FOOTNOTE:
762 case REFFLDFLAG_ENDNOTE:
763 nSize = FMT_REF_PAGE_PGDSC - FMT_REF_BEGIN + 1;
764 break;
766 default:
767 // --> OD 2007-11-16 #i83479#
768 // nSize = GetFldMgr().GetFormatCount( (REFFLDFLAG & nTypeId)
769 // ? (USHORT)TYP_GETREFFLD : nTypeId,
770 // FALSE, IsFldDlgHtmlMode() );
771 if ( REFFLDFLAG & nTypeId )
773 nSize = FMT_REF_ONLYSEQNO - FMT_REF_BEGIN + 1;
775 else
777 nSize = GetFldMgr().GetFormatCount( nTypeId, FALSE, IsFldDlgHtmlMode() );
779 break;
782 if (REFFLDFLAG & nTypeId)
783 nTypeId = TYP_GETREFFLD;
785 for (USHORT i = 0; i < nSize; i++)
787 USHORT nPos = aFormatLB.InsertEntry(GetFldMgr().GetFormatStr( nTypeId, i ));
788 aFormatLB.SetEntryData( nPos, reinterpret_cast<void*>(GetFldMgr().GetFormatId( nTypeId, i )));
790 // --> OD 2007-11-16 #i83479#
791 if ( bAddCrossRefFormats )
793 USHORT nFormat = FMT_REF_NUMBER - FMT_REF_BEGIN;
794 USHORT nPos = aFormatLB.InsertEntry(GetFldMgr().GetFormatStr( nTypeId, nFormat ));
795 aFormatLB.SetEntryData( nPos, reinterpret_cast<void*>(GetFldMgr().GetFormatId( nTypeId, nFormat )));
796 nFormat = FMT_REF_NUMBER_NO_CONTEXT - FMT_REF_BEGIN;
797 nPos = aFormatLB.InsertEntry(GetFldMgr().GetFormatStr( nTypeId, nFormat ));
798 aFormatLB.SetEntryData( nPos, reinterpret_cast<void*>(GetFldMgr().GetFormatId( nTypeId, nFormat )));
799 nFormat = FMT_REF_NUMBER_FULL_CONTEXT - FMT_REF_BEGIN;
800 nPos = aFormatLB.InsertEntry(GetFldMgr().GetFormatStr( nTypeId, nFormat ));
801 aFormatLB.SetEntryData( nPos, reinterpret_cast<void*>(GetFldMgr().GetFormatId( nTypeId, nFormat )));
802 nSize += 3;
804 // <--
806 // select a certain entry
807 if (nSize)
809 if (!IsFldEdit())
810 aFormatLB.SelectEntry(sOldSel);
811 else
812 aFormatLB.SelectEntry(SW_RESSTR(FMT_REF_BEGIN + (USHORT)GetCurField()->GetFormat()));
814 if (!aFormatLB.GetSelectEntryCount())
816 aFormatLB.SelectEntryPos(nFldDlgFmtSel);
817 if (!aFormatLB.GetSelectEntryCount())
818 aFormatLB.SelectEntryPos(0);
822 return nSize;
825 /*--------------------------------------------------------------------
826 Beschreibung: Modify
827 --------------------------------------------------------------------*/
829 IMPL_LINK( SwFldRefPage, ModifyHdl, Edit *, EMPTYARG )
831 String aName(aNameED.GetText());
832 const USHORT nLen = aName.Len();
834 BOOL bEnable = TRUE;
835 USHORT nTypeId = (USHORT)(ULONG)aTypeLB.GetEntryData(GetTypeSel());
837 if ((nTypeId == TYP_SETREFFLD && !GetFldMgr().CanInsertRefMark(aName)) ||
838 (nLen == 0 && (nTypeId == TYP_GETREFFLD || nTypeId == TYP_SETREFFLD ||
839 nTypeId == REFFLDFLAG_BOOKMARK)))
840 bEnable = FALSE;
842 EnableInsert(bEnable);
844 aSelectionLB.SelectEntry(aName);
846 return 0;
849 /*--------------------------------------------------------------------
850 Beschreibung:
851 --------------------------------------------------------------------*/
853 BOOL SwFldRefPage::FillItemSet(SfxItemSet& )
855 BOOL bModified = FALSE;
856 USHORT nTypeId = (USHORT)(ULONG)aTypeLB.GetEntryData(GetTypeSel());
858 USHORT nSubType = 0;
859 ULONG nFormat;
861 nFormat = aFormatLB.GetSelectEntryPos();
863 if(nFormat == LISTBOX_ENTRY_NOTFOUND)
864 nFormat = 0;
865 else
866 nFormat = (ULONG)aFormatLB.GetEntryData((USHORT)nFormat);
868 String aVal(aValueED.GetText());
869 String aName(aNameED.GetText());
871 switch(nTypeId)
873 case TYP_GETREFFLD:
874 // aName = aSelectionLB.GetSelectEntry();
875 nSubType = REF_SETREFATTR;
876 break;
878 case TYP_SETREFFLD:
880 SwFieldType* pType = GetFldMgr().GetFldType(RES_SETEXPFLD, aName);
882 if(!pType) // Nur einfuegen, wenn es den Namen noch nicht gibt
884 aSelectionLB.InsertEntry(aName);
885 aSelectionLB.Enable();
886 aSelectionFT.Enable();
888 break;
892 SwGetRefField* pRefFld = (SwGetRefField*)GetCurField();
894 if (REFFLDFLAG & nTypeId)
896 SwWrtShell *pSh = GetWrtShell();
897 if(!pSh)
899 pSh = ::GetActiveWrtShell();
901 if (nTypeId == REFFLDFLAG_BOOKMARK) // TextMarken!
903 aName = aNameED.GetText();
904 nTypeId = TYP_GETREFFLD;
905 nSubType = REF_BOOKMARK;
907 else if (REFFLDFLAG_FOOTNOTE == nTypeId) // Fussnoten
909 SwSeqFldList aArr;
910 _SeqFldLstElem aElem( aSelectionLB.GetSelectEntry(), 0 );
912 USHORT nPos;
914 nTypeId = TYP_GETREFFLD;
915 nSubType = REF_FOOTNOTE;
916 aName.Erase();
918 if (pSh->GetSeqFtnList(aArr) && aArr.SeekEntry(aElem, &nPos))
920 aVal = String::CreateFromInt32( aArr[nPos]->nSeqNo );
922 if (IsFldEdit() && aArr[nPos]->nSeqNo == pRefFld->GetSeqNo())
923 bModified = TRUE; // Kann bei Feldern passieren, deren Referenz geloescht wurde
925 else if (IsFldEdit())
926 aVal = String::CreateFromInt32( pRefFld->GetSeqNo() );
928 else if (REFFLDFLAG_ENDNOTE == nTypeId) // Endnoten
930 SwSeqFldList aArr;
931 _SeqFldLstElem aElem( aSelectionLB.GetSelectEntry(), 0 );
933 USHORT nPos;
935 nTypeId = TYP_GETREFFLD;
936 nSubType = REF_ENDNOTE;
937 aName.Erase();
939 if (pSh->GetSeqFtnList(aArr, true) && aArr.SeekEntry(aElem, &nPos))
941 aVal = String::CreateFromInt32( aArr[nPos]->nSeqNo );
943 if (IsFldEdit() && aArr[nPos]->nSeqNo == pRefFld->GetSeqNo())
944 bModified = TRUE; // Kann bei Feldern passieren, deren Referenz geloescht wurde
946 else if (IsFldEdit())
947 aVal = String::CreateFromInt32( pRefFld->GetSeqNo() );
949 // --> OD 2007-11-16 #i83479#
950 else if ( nTypeId == REFFLDFLAG_HEADING )
952 SvLBoxEntry* pEntry = aSelectionToolTipLB.GetCurEntry();
953 ASSERT( pEntry,
954 "<SwFldRefPage::FillItemSet(..)> - no entry selected in selection tool tip listbox!" );
955 if ( pEntry )
957 const sal_uInt16 nOutlIdx( static_cast<sal_uInt16>(reinterpret_cast<ULONG>(pEntry->GetUserData())) );
958 pSh->getIDocumentOutlineNodesAccess()->getOutlineNodes( maOutlineNodes );
959 if ( nOutlIdx < maOutlineNodes.size() )
961 ::sw::mark::IMark const * const pMark = pSh->getIDocumentMarkAccess()->getMarkForTxtNode(
962 *(maOutlineNodes[nOutlIdx]),
963 IDocumentMarkAccess::CROSSREF_HEADING_BOOKMARK);
964 aName = pMark->GetName();
965 nTypeId = TYP_GETREFFLD;
966 nSubType = REF_BOOKMARK;
970 else if ( nTypeId == REFFLDFLAG_NUMITEM )
972 SvLBoxEntry* pEntry = aSelectionToolTipLB.GetCurEntry();
973 ASSERT( pEntry,
974 "<SwFldRefPage::FillItemSet(..)> - no entry selected in selection tool tip listbox!" );
975 if ( pEntry )
977 const sal_uInt16 nNumItemIdx( static_cast<sal_uInt16>(reinterpret_cast<ULONG>(pEntry->GetUserData())) );
978 pSh->getIDocumentListItemsAccess()->getNumItems( maNumItems );
979 if ( nNumItemIdx < maNumItems.size() )
981 ::sw::mark::IMark const * const pMark = pSh->getIDocumentMarkAccess()->getMarkForTxtNode(
982 *(maNumItems[nNumItemIdx]->GetTxtNode()),
983 IDocumentMarkAccess::CROSSREF_NUMITEM_BOOKMARK);
984 aName = pMark->GetName();
985 nTypeId = TYP_GETREFFLD;
986 nSubType = REF_BOOKMARK;
990 // <--
991 else // SeqenceFelder
993 // zum Seq-FeldTyp die Felder besorgen:
994 SwSetExpFieldType* pType = (SwSetExpFieldType*)pSh->GetFldType(
995 nTypeId & ~REFFLDFLAG, RES_SETEXPFLD );
996 if( pType )
998 SwSeqFldList aArr;
999 _SeqFldLstElem aElem( aSelectionLB.GetSelectEntry(), 0 );
1001 USHORT nPos;
1003 nTypeId = TYP_GETREFFLD;
1004 nSubType = REF_SEQUENCEFLD;
1005 aName = pType->GetName();
1007 if (pType->GetSeqFldList(aArr) && aArr.SeekEntry(aElem, &nPos))
1009 aVal = String::CreateFromInt32( aArr[nPos]->nSeqNo );
1011 if (IsFldEdit() && aArr[nPos]->nSeqNo == pRefFld->GetSeqNo())
1012 bModified = TRUE; // Kann bei Feldern passieren, deren Referenz geloescht wurde
1014 else if (IsFldEdit())
1015 aVal = String::CreateFromInt32( pRefFld->GetSeqNo() );
1020 if (IsFldEdit() && nTypeId == TYP_GETREFFLD)
1022 aVal.Insert('|', 0);
1023 aVal.Insert(String::CreateFromInt32(nSubType), 0);
1026 if (!IsFldEdit() || bModified ||
1027 aNameED.GetSavedValue() != aNameED.GetText() ||
1028 aValueED.GetSavedValue() != aValueED.GetText() ||
1029 aTypeLB.GetSavedValue() != aTypeLB.GetSelectEntryPos() ||
1030 aSelectionLB.GetSavedValue() != aSelectionLB.GetSelectEntryPos() ||
1031 aFormatLB.GetSavedValue() != aFormatLB.GetSelectEntryPos())
1033 InsertFld( nTypeId, nSubType, aName, aVal, nFormat );
1036 ModifyHdl(); // Insert ggf enablen/disablen
1038 return FALSE;
1041 /*--------------------------------------------------------------------
1042 Beschreibung:
1043 --------------------------------------------------------------------*/
1045 SfxTabPage* SwFldRefPage::Create( Window* pParent,
1046 const SfxItemSet& rAttrSet )
1048 return ( new SwFldRefPage( pParent, rAttrSet ) );
1051 /*--------------------------------------------------------------------
1052 Beschreibung:
1053 --------------------------------------------------------------------*/
1055 USHORT SwFldRefPage::GetGroup()
1057 return GRP_REF;
1060 /* -----------------12.01.99 10:09-------------------
1062 * --------------------------------------------------*/
1063 void SwFldRefPage::FillUserData()
1065 String sData( String::CreateFromAscii(
1066 RTL_CONSTASCII_STRINGPARAM( USER_DATA_VERSION )));
1067 sData += ';';
1068 USHORT nTypeSel = aTypeLB.GetSelectEntryPos();
1069 if( LISTBOX_ENTRY_NOTFOUND == nTypeSel )
1070 nTypeSel = USHRT_MAX;
1071 else
1072 nTypeSel = sal::static_int_cast< USHORT >(reinterpret_cast< sal_uIntPtr >(aTypeLB.GetEntryData( nTypeSel )));
1073 sData += String::CreateFromInt32( nTypeSel );
1074 SetUserData(sData);