1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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
40 #include "swtypes.hxx"
44 #include <swmodule.hxx>
55 #include <fldtdlg.hrc>
58 #include <globals.hrc>
60 // --> OD 2007-11-14 #i83479#
61 #include <SwNodeNum.hxx>
62 #include <IDocumentMarkAccess.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
78 USHORT nFldDlgFmtSel
= 0;
80 #define USER_DATA_VERSION_1 "1"
81 #define USER_DATA_VERSION USER_DATA_VERSION_1
84 /*--------------------------------------------------------------------
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
) ),
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
)),
113 mpSavedSelectedTxtNode( 0 ),
114 mnSavedSelectedPos( 0 )
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();
136 /*--------------------------------------------------------------------
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();
154 const USHORT nTypeId
= (USHORT
)(ULONG
)aTypeLB
.GetEntryData(GetTypeSel());
155 SwWrtShell
*pSh
= GetWrtShell();
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
;
192 /*--------------------------------------------------------------------
194 --------------------------------------------------------------------*/
196 void SwFldRefPage::Reset(const SfxItemSet
& )
201 // --> OD 2007-11-22 #i83479#
202 SaveSelectedTxtNode();
205 SetSelectionSel(LISTBOX_ENTRY_NOTFOUND
);
206 SetTypeSel(LISTBOX_ENTRY_NOTFOUND
);
207 Init(); // Allgemeine initialisierung
209 // TypeListBox initialisieren
210 aTypeLB
.SetUpdateMode(FALSE
);
213 // Typ-Listbox fuellen
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
);
238 // mit den Sequence-Typen auffuellen
239 SwWrtShell
*pSh
= GetWrtShell();
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
);
263 nPos
= aTypeLB
.InsertEntry(sFootnoteTxt
);
264 aTypeLB
.SetEntryData(nPos
, (void*)REFFLDFLAG_FOOTNOTE
);
268 if ( pSh
->HasFtns(true) )
270 nPos
= aTypeLB
.InsertEntry(sEndnoteTxt
);
271 aTypeLB
.SetEntryData(nPos
, (void*)REFFLDFLAG_ENDNOTE
);
274 // alte Pos selektieren
276 RestorePos(&aTypeLB
);
278 aTypeLB
.SetUpdateMode(TRUE
);
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
);
306 aSelectionLB
.SaveValue();
307 aFormatLB
.SaveValue();
309 aValueED
.SaveValue();
313 /*--------------------------------------------------------------------
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
)
329 // Positionen selektieren
333 switch( GetCurField()->GetSubType() )
337 // --> OD 2007-11-14 #i83479#
338 // sName = sBookmarkTxt;
339 // nFlag = REFFLDFLAG_BOOKMARK;
340 SwGetRefField
* pRefFld
= dynamic_cast<SwGetRefField
*>(GetCurField());
342 pRefFld
->IsRefToHeadingCrossRefBookmark() )
345 nFlag
= REFFLDFLAG_HEADING
;
348 pRefFld
->IsRefToNumItemCrossRefBookmark() )
351 nFlag
= REFFLDFLAG_NUMITEM
;
355 sName
= sBookmarkTxt
;
356 nFlag
= REFFLDFLAG_BOOKMARK
;
363 sName
= sFootnoteTxt
;
364 nFlag
= REFFLDFLAG_FOOTNOTE
;
369 nFlag
= REFFLDFLAG_ENDNOTE
;
373 sName
= SW_RESSTR(STR_GETREFFLD
);
374 nFlag
= REF_SETREFATTR
;
377 case REF_SEQUENCEFLD
:
378 sName
= ((SwGetRefField
*)GetCurField())->GetSetRefName();
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());
395 aTypeLB
.SelectEntryPos(0);
399 if (nOld
!= GetTypeSel())
401 USHORT nTypeId
= (USHORT
)(ULONG
)aTypeLB
.GetEntryData(GetTypeSel());
403 // Auswahl-Listbox fuellen
406 BOOL bName
= FALSE
; nFldDlgFmtSel
= 0;
408 if ( ( !IsFldEdit() || aSelectionLB
.GetEntryCount() ) &&
409 nOld
!= LISTBOX_ENTRY_NOTFOUND
)
411 aNameED
.SetText(aEmptyStr
);
412 aValueED
.SetText(aEmptyStr
);
418 if (REFFLDFLAG
& (USHORT
)(ULONG
)aTypeLB
.GetEntryData(nOld
))
419 // dann bleibt die alte bestehen
420 nFldDlgFmtSel
= aFormatLB
.GetSelectEntryPos();
428 case REFFLDFLAG_BOOKMARK
:
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();
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
);
458 /*--------------------------------------------------------------------
460 --------------------------------------------------------------------*/
462 IMPL_LINK( SwFldRefPage
, SubTypeHdl
, ListBox
*, EMPTYARG
)
464 USHORT nTypeId
= (USHORT
)(ULONG
)aTypeLB
.GetEntryData(GetTypeSel());
469 if (!IsFldEdit() || aSelectionLB
.GetSelectEntryCount())
471 aNameED
.SetText(aSelectionLB
.GetSelectEntry());
478 SwWrtShell
*pSh
= GetWrtShell();
480 pSh
= ::GetActiveWrtShell();
483 aValueED
.SetText(pSh
->GetSelTxt());
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() ) );
502 if (!IsFldEdit() || aSelectionLB
.GetSelectEntryCount())
503 aNameED
.SetText(aSelectionLB
.GetSelectEntry());
510 /*--------------------------------------------------------------------
511 Beschreibung: Typen in SelectionLB erneuern
512 --------------------------------------------------------------------*/
514 void SwFldRefPage::UpdateSubType()
516 SwWrtShell
*pSh
= GetWrtShell();
518 pSh
= ::GetActiveWrtShell();
519 SwGetRefField
* pRefFld
= (SwGetRefField
*)GetCurField();
520 const USHORT nTypeId
= (USHORT
)(ULONG
)aTypeLB
.GetEntryData(GetTypeSel());
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
);
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 );
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();
555 const ::sw::mark::IMark
* pBkmk
= ppMark
->get();
556 if(IDocumentMarkAccess::BOOKMARK
== IDocumentMarkAccess::GetType(*pBkmk
))
557 aSelectionLB
.InsertEntry( pBkmk
->GetName() );
560 sOldSel
= pRefFld
->GetSetRefName();
562 else if (nTypeId
== REFFLDFLAG_FOOTNOTE
)
564 aSelectionLB
.SetStyle(aSelectionLB
.GetStyle() & ~WB_SORT
);
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
);
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
);
609 bCertainTxtNodeSelected
= true;
611 else if ( !bCertainTxtNodeSelected
&&
612 GetSavedSelectedPos() == nOutlIdx
)
614 aSelectionToolTipLB
.Select( pEntry
);
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
);
639 bCertainTxtNodeSelected
= true;
641 else if ( !bCertainTxtNodeSelected
&&
642 GetSavedSelectedPos() == nNumItemIdx
)
644 aSelectionToolTipLB
.Select( pEntry
);
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
);
660 // old selection should be kept in non-edit mode
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);
681 GetFldMgr().GetSubTypes(nTypeId
, aLst
);
682 for (USHORT i
= 0; i
< aLst
.Count(); ++i
)
683 aSelectionLB
.InsertEntry(*aLst
[i
]);
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
);
712 aSelectionLB
.SetUpdateMode(TRUE
);
714 // Enable oder Disable
715 BOOL bEnable
= aSelectionLB
.GetEntryCount() != 0;
716 aSelectionLB
.Enable( bEnable
);
717 aSelectionFT
.Enable( 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
);
732 /*--------------------------------------------------------------------
734 --------------------------------------------------------------------*/
736 USHORT
SwFldRefPage::FillFormatLB(USHORT nTypeId
)
740 USHORT nFormatSel
= aFormatLB
.GetSelectEntryPos();
741 if (nFormatSel
!= LISTBOX_ENTRY_NOTFOUND
)
742 sOldSel
= aFormatLB
.GetEntry(nFormatSel
);
744 // Format-Listbox fuellen
747 // Referenz hat weniger als die Beschriftung
749 bool bAddCrossRefFormats( false );
752 // --> OD 2007-11-16 #i83479#
753 case REFFLDFLAG_HEADING
:
754 case REFFLDFLAG_NUMITEM
:
755 bAddCrossRefFormats
= true;
756 // intentional no break here
760 case REFFLDFLAG_BOOKMARK
:
761 case REFFLDFLAG_FOOTNOTE
:
762 case REFFLDFLAG_ENDNOTE
:
763 nSize
= FMT_REF_PAGE_PGDSC
- FMT_REF_BEGIN
+ 1;
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;
777 nSize
= GetFldMgr().GetFormatCount( nTypeId
, FALSE
, IsFldDlgHtmlMode() );
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
)));
806 // select a certain entry
810 aFormatLB
.SelectEntry(sOldSel
);
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);
825 /*--------------------------------------------------------------------
827 --------------------------------------------------------------------*/
829 IMPL_LINK( SwFldRefPage
, ModifyHdl
, Edit
*, EMPTYARG
)
831 String
aName(aNameED
.GetText());
832 const USHORT nLen
= aName
.Len();
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
)))
842 EnableInsert(bEnable
);
844 aSelectionLB
.SelectEntry(aName
);
849 /*--------------------------------------------------------------------
851 --------------------------------------------------------------------*/
853 BOOL
SwFldRefPage::FillItemSet(SfxItemSet
& )
855 BOOL bModified
= FALSE
;
856 USHORT nTypeId
= (USHORT
)(ULONG
)aTypeLB
.GetEntryData(GetTypeSel());
861 nFormat
= aFormatLB
.GetSelectEntryPos();
863 if(nFormat
== LISTBOX_ENTRY_NOTFOUND
)
866 nFormat
= (ULONG
)aFormatLB
.GetEntryData((USHORT
)nFormat
);
868 String
aVal(aValueED
.GetText());
869 String
aName(aNameED
.GetText());
874 // aName = aSelectionLB.GetSelectEntry();
875 nSubType
= REF_SETREFATTR
;
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();
892 SwGetRefField
* pRefFld
= (SwGetRefField
*)GetCurField();
894 if (REFFLDFLAG
& nTypeId
)
896 SwWrtShell
*pSh
= GetWrtShell();
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
910 _SeqFldLstElem
aElem( aSelectionLB
.GetSelectEntry(), 0 );
914 nTypeId
= TYP_GETREFFLD
;
915 nSubType
= REF_FOOTNOTE
;
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
931 _SeqFldLstElem
aElem( aSelectionLB
.GetSelectEntry(), 0 );
935 nTypeId
= TYP_GETREFFLD
;
936 nSubType
= REF_ENDNOTE
;
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();
954 "<SwFldRefPage::FillItemSet(..)> - no entry selected in selection tool tip listbox!" );
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();
974 "<SwFldRefPage::FillItemSet(..)> - no entry selected in selection tool tip listbox!" );
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
;
991 else // SeqenceFelder
993 // zum Seq-FeldTyp die Felder besorgen:
994 SwSetExpFieldType
* pType
= (SwSetExpFieldType
*)pSh
->GetFldType(
995 nTypeId
& ~REFFLDFLAG
, RES_SETEXPFLD
);
999 _SeqFldLstElem
aElem( aSelectionLB
.GetSelectEntry(), 0 );
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
1041 /*--------------------------------------------------------------------
1043 --------------------------------------------------------------------*/
1045 SfxTabPage
* SwFldRefPage::Create( Window
* pParent
,
1046 const SfxItemSet
& rAttrSet
)
1048 return ( new SwFldRefPage( pParent
, rAttrSet
) );
1051 /*--------------------------------------------------------------------
1053 --------------------------------------------------------------------*/
1055 USHORT
SwFldRefPage::GetGroup()
1060 /* -----------------12.01.99 10:09-------------------
1062 * --------------------------------------------------*/
1063 void SwFldRefPage::FillUserData()
1065 String
sData( String::CreateFromAscii(
1066 RTL_CONSTASCII_STRINGPARAM( USER_DATA_VERSION
)));
1068 USHORT nTypeSel
= aTypeLB
.GetSelectEntryPos();
1069 if( LISTBOX_ENTRY_NOTFOUND
== nTypeSel
)
1070 nTypeSel
= USHRT_MAX
;
1072 nTypeSel
= sal::static_int_cast
< USHORT
>(reinterpret_cast< sal_uIntPtr
>(aTypeLB
.GetEntryData( nTypeSel
)));
1073 sData
+= String::CreateFromInt32( nTypeSel
);