xref: /aoo4110/main/sw/source/ui/fldui/fldref.cxx (revision b1cdbd2c)
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 
SwFldRefPage(Window * pParent,const SfxItemSet & rCoreSet)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 
~SwFldRefPage()133 SwFldRefPage::~SwFldRefPage()
134 {
135 }
136 
137 // --> OD 2007-11-22 #i83479#
SaveSelectedTxtNode()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 
GetSavedSelectedTxtNode() const173 const SwTxtNode* SwFldRefPage::GetSavedSelectedTxtNode() const
174 {
175     return mpSavedSelectedTxtNode;
176 }
177 
GetSavedSelectedPos() const178 sal_uInt16 SwFldRefPage::GetSavedSelectedPos() const
179 {
180     return mnSavedSelectedPos;
181 }
182 
183 // <--
184 
185 /*--------------------------------------------------------------------
186 	Beschreibung:
187  --------------------------------------------------------------------*/
188 
Reset(const SfxItemSet &)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 
IMPL_LINK(SwFldRefPage,TypeHdl,ListBox *,EMPTYARG)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 
IMPL_LINK(SwFldRefPage,SubTypeHdl,ListBox *,EMPTYARG)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 
UpdateSubType()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     if ( aSelectionLB.IsVisible() )
517     {
518         const sal_uInt16 nSelectionSel = aSelectionLB.GetSelectEntryPos();
519         if (nSelectionSel != LISTBOX_ENTRY_NOTFOUND)
520         {
521             sOldSel = aSelectionLB.GetEntry(nSelectionSel);
522         }
523     }
524     if (IsFldEdit() && !sOldSel.Len())
525         sOldSel = String::CreateFromInt32( pRefFld->GetSeqNo() + 1 );
526 
527     aSelectionLB.SetUpdateMode(sal_False);
528     aSelectionLB.Clear();
529     aSelectionToolTipLB.SetUpdateMode(sal_False);
530     aSelectionToolTipLB.Clear();
531     bool bShowSelectionToolTipLB( false );
532 
533     if( REFFLDFLAG & nTypeId )
534     {
535         if (nTypeId == REFFLDFLAG_BOOKMARK)     // TextMarken!
536         {
537             aSelectionLB.SetStyle(aSelectionLB.GetStyle()|WB_SORT);
538             // alle Textmarken besorgen
539             IDocumentMarkAccess* const pMarkAccess = pSh->getIDocumentMarkAccess();
540             for(IDocumentMarkAccess::const_iterator_t ppMark = pMarkAccess->getBookmarksBegin();
541                 ppMark != pMarkAccess->getBookmarksEnd();
542                 ppMark++)
543             {
544                 const ::sw::mark::IMark* pBkmk = ppMark->get();
545                 if(IDocumentMarkAccess::BOOKMARK == IDocumentMarkAccess::GetType(*pBkmk))
546                     aSelectionLB.InsertEntry( pBkmk->GetName() );
547             }
548             if (IsFldEdit())
549                 sOldSel = pRefFld->GetSetRefName();
550         }
551         else if (nTypeId == REFFLDFLAG_FOOTNOTE)
552         {
553             aSelectionLB.SetStyle(aSelectionLB.GetStyle() & ~WB_SORT);
554             SwSeqFldList aArr;
555             sal_uInt16 nCnt = pSh->GetSeqFtnList( aArr );
556 
557             for( sal_uInt16 n = 0; n < nCnt; ++n )
558             {
559                 aSelectionLB.InsertEntry( aArr[ n ]->sDlgEntry );
560                 if (IsFldEdit() && pRefFld->GetSeqNo() == aArr[ n ]->nSeqNo)
561                     sOldSel = aArr[n]->sDlgEntry;
562             }
563         }
564         else if (nTypeId == REFFLDFLAG_ENDNOTE)
565         {
566             aSelectionLB.SetStyle(aSelectionLB.GetStyle() & ~WB_SORT);
567             SwSeqFldList aArr;
568             sal_uInt16 nCnt = pSh->GetSeqFtnList( aArr, true );
569 
570             for( sal_uInt16 n = 0; n < nCnt; ++n )
571             {
572                 aSelectionLB.InsertEntry( aArr[ n ]->sDlgEntry );
573                 if (IsFldEdit() && pRefFld->GetSeqNo() == aArr[ n ]->nSeqNo)
574                     sOldSel = aArr[n]->sDlgEntry;
575             }
576         }
577         else if ( nTypeId == REFFLDFLAG_HEADING )
578         {
579             bShowSelectionToolTipLB = true;
580 
581             const IDocumentOutlineNodes* pIDoc( pSh->getIDocumentOutlineNodesAccess() );
582             pIDoc->getOutlineNodes( maOutlineNodes );
583             bool bCertainTxtNodeSelected( false );
584             SvLBoxEntry* pEntry = 0;
585             sal_uInt16 nOutlIdx = 0;
586             for ( nOutlIdx = 0; nOutlIdx < maOutlineNodes.size(); ++nOutlIdx )
587             {
588                 pEntry = aSelectionToolTipLB.InsertEntry(
589                                 pIDoc->getOutlineText( nOutlIdx, true, true ) );
590                 pEntry->SetUserData( reinterpret_cast<void*>(nOutlIdx) );
591                 if ( ( IsFldEdit() &&
592                        pRefFld->GetReferencedTxtNode() == maOutlineNodes[nOutlIdx] ) ||
593                      GetSavedSelectedTxtNode() == maOutlineNodes[nOutlIdx] )
594                 {
595                     aSelectionToolTipLB.Select( pEntry );
596                     sOldSel.Erase();
597                     bCertainTxtNodeSelected = true;
598                 }
599                 else if ( !bCertainTxtNodeSelected &&
600                           GetSavedSelectedPos() == nOutlIdx )
601                 {
602                     aSelectionToolTipLB.Select( pEntry );
603                     sOldSel.Erase();
604                 }
605             }
606         }
607         else if ( nTypeId == REFFLDFLAG_NUMITEM )
608         {
609             bShowSelectionToolTipLB = true;
610 
611             const IDocumentListItems* pIDoc( pSh->getIDocumentListItemsAccess() );
612             pIDoc->getNumItems( maNumItems );
613             bool bCertainTxtNodeSelected( false );
614             SvLBoxEntry* pEntry = 0;
615             sal_uInt16 nNumItemIdx = 0;
616             for ( nNumItemIdx = 0; nNumItemIdx < maNumItems.size(); ++nNumItemIdx )
617             {
618                 pEntry = aSelectionToolTipLB.InsertEntry(
619                             pIDoc->getListItemText( *maNumItems[nNumItemIdx], true, true ) );
620                 pEntry->SetUserData( reinterpret_cast<void*>(nNumItemIdx) );
621                 if ( ( IsFldEdit() &&
622                        pRefFld->GetReferencedTxtNode() == maNumItems[nNumItemIdx]->GetTxtNode() ) ||
623                      GetSavedSelectedTxtNode() == maNumItems[nNumItemIdx]->GetTxtNode() )
624                 {
625                     aSelectionToolTipLB.Select( pEntry );
626                     sOldSel.Erase();
627                     bCertainTxtNodeSelected = true;
628                 }
629                 else if ( !bCertainTxtNodeSelected &&
630                           GetSavedSelectedPos() == nNumItemIdx )
631                 {
632                     aSelectionToolTipLB.Select( pEntry );
633                     sOldSel.Erase();
634                 }
635             }
636         }
637         else
638         {
639             aSelectionLB.SetStyle(aSelectionLB.GetStyle()|WB_SORT);
640             // zum Seq-FeldTyp die Felder besorgen:
641 
642             SwSetExpFieldType* pType = (SwSetExpFieldType*)pSh->GetFldType(
643                                 nTypeId & ~REFFLDFLAG, RES_SETEXPFLD );
644             if( pType )
645             {
646                 SwSeqFldList aArr;
647                 // old selection should be kept in non-edit mode
648                 if(IsFldEdit())
649                     sOldSel.Erase();
650 
651                 sal_uInt16 nCnt = pType->GetSeqFldList( aArr );
652                 for( sal_uInt16 n = 0; n < nCnt; ++n )
653                 {
654                     aSelectionLB.InsertEntry( aArr[ n ]->sDlgEntry );
655                     if (IsFldEdit() && !sOldSel.Len() &&
656                         aArr[ n ]->nSeqNo == pRefFld->GetSeqNo())
657                         sOldSel = aArr[ n ]->sDlgEntry;
658                 }
659 
660                 if (IsFldEdit() && !sOldSel.Len())
661                     sOldSel = String::CreateFromInt32( pRefFld->GetSeqNo() + 1);
662             }
663         }
664     }
665     else
666     {
667         SvStringsDtor aLst;
668         GetFldMgr().GetSubTypes(nTypeId, aLst);
669         for (sal_uInt16 i = 0; i < aLst.Count(); ++i)
670             aSelectionLB.InsertEntry(*aLst[i]);
671 
672         if (IsFldEdit())
673             sOldSel = pRefFld->GetSetRefName();
674     }
675 
676     // --> OD 2007-11-21 #i83479#
677     aSelectionToolTipLB.Show( bShowSelectionToolTipLB );
678     aSelectionLB.Show( !bShowSelectionToolTipLB );
679     if ( bShowSelectionToolTipLB )
680     {
681         aSelectionToolTipLB.SetUpdateMode(sal_True);
682 
683         sal_Bool bEnable = aSelectionToolTipLB.GetEntryCount() != 0;
684         aSelectionToolTipLB.Enable( bEnable );
685         aSelectionFT.Enable( bEnable );
686 
687         if ( aSelectionToolTipLB.GetCurEntry() != 0 )
688         {
689             aSelectionToolTipLB.MakeVisible( aSelectionToolTipLB.GetCurEntry() );
690         }
691 
692         if ( IsFldEdit() && aSelectionToolTipLB.GetCurEntry() == 0 )
693         {
694             aNameED.SetText(sOldSel);
695         }
696     }
697     else
698     {
699         aSelectionLB.SetUpdateMode(sal_True);
700 
701         // Enable oder Disable
702         sal_Bool bEnable = aSelectionLB.GetEntryCount() != 0;
703         aSelectionLB.Enable( bEnable );
704         aSelectionFT.Enable( bEnable );
705 
706         if ( bEnable )
707         {
708             aSelectionLB.SelectEntry(sOldSel);
709             if (!aSelectionLB.GetSelectEntryCount() && !IsFldEdit())
710                 aSelectionLB.SelectEntryPos(0);
711         }
712 
713         if (IsFldEdit() && !aSelectionLB.GetSelectEntryCount()) // Falls die Referenz schon geloescht wurde...
714             aNameED.SetText(sOldSel);
715     }
716     // <--
717 }
718 
719 /*--------------------------------------------------------------------
720 	Beschreibung:
721  --------------------------------------------------------------------*/
722 
FillFormatLB(sal_uInt16 nTypeId)723 sal_uInt16 SwFldRefPage::FillFormatLB(sal_uInt16 nTypeId)
724 {
725 	String sOldSel;
726 
727 	sal_uInt16 nFormatSel = aFormatLB.GetSelectEntryPos();
728 	if (nFormatSel != LISTBOX_ENTRY_NOTFOUND)
729 		sOldSel = aFormatLB.GetEntry(nFormatSel);
730 
731 	// Format-Listbox fuellen
732 	aFormatLB.Clear();
733 
734 	// Referenz hat weniger als die Beschriftung
735     sal_uInt16 nSize( 0 );
736     bool bAddCrossRefFormats( false );
737 	switch (nTypeId)
738 	{
739         // --> OD 2007-11-16 #i83479#
740         case REFFLDFLAG_HEADING:
741         case REFFLDFLAG_NUMITEM:
742             bAddCrossRefFormats = true;
743             // intentional no break here
744         // <--
745 
746         case TYP_GETREFFLD:
747         case REFFLDFLAG_BOOKMARK:
748         case REFFLDFLAG_FOOTNOTE:
749         case REFFLDFLAG_ENDNOTE:
750             nSize = FMT_REF_PAGE_PGDSC - FMT_REF_BEGIN + 1;
751             break;
752 
753         default:
754             // --> OD 2007-11-16 #i83479#
755 //            nSize = GetFldMgr().GetFormatCount( (REFFLDFLAG & nTypeId)
756 //                                                    ? (sal_uInt16)TYP_GETREFFLD : nTypeId,
757 //                                                sal_False, IsFldDlgHtmlMode() );
758             if ( REFFLDFLAG & nTypeId )
759             {
760                 nSize = FMT_REF_ONLYSEQNO - FMT_REF_BEGIN + 1;
761             }
762             else
763             {
764                 nSize = GetFldMgr().GetFormatCount( nTypeId, sal_False, IsFldDlgHtmlMode() );
765             }
766             break;
767 	}
768 
769 	if (REFFLDFLAG & nTypeId)
770 		nTypeId = TYP_GETREFFLD;
771 
772 	for (sal_uInt16 i = 0; i < nSize; i++)
773 	{
774 		sal_uInt16 nPos = aFormatLB.InsertEntry(GetFldMgr().GetFormatStr( nTypeId, i ));
775         aFormatLB.SetEntryData( nPos, reinterpret_cast<void*>(GetFldMgr().GetFormatId( nTypeId, i )));
776 	}
777     // --> OD 2007-11-16 #i83479#
778     if ( bAddCrossRefFormats )
779     {
780         sal_uInt16 nFormat = FMT_REF_NUMBER - FMT_REF_BEGIN;
781         sal_uInt16 nPos = aFormatLB.InsertEntry(GetFldMgr().GetFormatStr( nTypeId, nFormat ));
782         aFormatLB.SetEntryData( nPos, reinterpret_cast<void*>(GetFldMgr().GetFormatId( nTypeId, nFormat )));
783         nFormat = FMT_REF_NUMBER_NO_CONTEXT - FMT_REF_BEGIN;
784         nPos = aFormatLB.InsertEntry(GetFldMgr().GetFormatStr( nTypeId, nFormat ));
785         aFormatLB.SetEntryData( nPos, reinterpret_cast<void*>(GetFldMgr().GetFormatId( nTypeId, nFormat )));
786         nFormat = FMT_REF_NUMBER_FULL_CONTEXT - FMT_REF_BEGIN;
787         nPos = aFormatLB.InsertEntry(GetFldMgr().GetFormatStr( nTypeId, nFormat ));
788         aFormatLB.SetEntryData( nPos, reinterpret_cast<void*>(GetFldMgr().GetFormatId( nTypeId, nFormat )));
789         nSize += 3;
790     }
791     // <--
792 
793     // select a certain entry
794 	if (nSize)
795 	{
796 		if (!IsFldEdit())
797 			aFormatLB.SelectEntry(sOldSel);
798 		else
799 			aFormatLB.SelectEntry(SW_RESSTR(FMT_REF_BEGIN + (sal_uInt16)GetCurField()->GetFormat()));
800 
801 		if (!aFormatLB.GetSelectEntryCount())
802 		{
803 			aFormatLB.SelectEntryPos(nFldDlgFmtSel);
804 			if (!aFormatLB.GetSelectEntryCount())
805 				aFormatLB.SelectEntryPos(0);
806 		}
807 	}
808 
809 	return nSize;
810 }
811 
812 /*--------------------------------------------------------------------
813 	Beschreibung: Modify
814  --------------------------------------------------------------------*/
815 
IMPL_LINK(SwFldRefPage,ModifyHdl,Edit *,EMPTYARG)816 IMPL_LINK( SwFldRefPage, ModifyHdl, Edit *, EMPTYARG )
817 {
818 	String aName(aNameED.GetText());
819 	const sal_uInt16 nLen = aName.Len();
820 
821 	sal_Bool bEnable = sal_True;
822 	sal_uInt16 nTypeId = (sal_uInt16)(sal_uLong)aTypeLB.GetEntryData(GetTypeSel());
823 
824 	if ((nTypeId == TYP_SETREFFLD && !GetFldMgr().CanInsertRefMark(aName)) ||
825 		(nLen == 0 && (nTypeId == TYP_GETREFFLD || nTypeId == TYP_SETREFFLD ||
826 					   nTypeId == REFFLDFLAG_BOOKMARK)))
827 		bEnable = sal_False;
828 
829 	EnableInsert(bEnable);
830 
831 	aSelectionLB.SelectEntry(aName);
832 
833 	return 0;
834 }
835 
836 /*--------------------------------------------------------------------
837 	Beschreibung:
838  --------------------------------------------------------------------*/
839 
FillItemSet(SfxItemSet &)840 sal_Bool SwFldRefPage::FillItemSet(SfxItemSet& )
841 {
842 	sal_Bool bModified = sal_False;
843 	sal_uInt16 nTypeId = (sal_uInt16)(sal_uLong)aTypeLB.GetEntryData(GetTypeSel());
844 
845 	sal_uInt16 nSubType = 0;
846 	sal_uLong nFormat;
847 
848 	nFormat = aFormatLB.GetSelectEntryPos();
849 
850 	if(nFormat == LISTBOX_ENTRY_NOTFOUND)
851 		nFormat = 0;
852 	else
853 		nFormat = (sal_uLong)aFormatLB.GetEntryData((sal_uInt16)nFormat);
854 
855 	String aVal(aValueED.GetText());
856 	String aName(aNameED.GetText());
857 
858 	switch(nTypeId)
859 	{
860 		case TYP_GETREFFLD:
861 			// aName = aSelectionLB.GetSelectEntry();
862 			nSubType = REF_SETREFATTR;
863 			break;
864 
865 		case TYP_SETREFFLD:
866 		{
867 			SwFieldType* pType = GetFldMgr().GetFldType(RES_SETEXPFLD, aName);
868 
869 			if(!pType)	// Nur einfuegen, wenn es den Namen noch nicht gibt
870 			{
871 				aSelectionLB.InsertEntry(aName);
872 				aSelectionLB.Enable();
873 				aSelectionFT.Enable();
874 			}
875 			break;
876 		}
877 	}
878 
879 	SwGetRefField* pRefFld = (SwGetRefField*)GetCurField();
880 
881 	if (REFFLDFLAG & nTypeId)
882 	{
883         SwWrtShell *pSh = GetWrtShell();
884         if(!pSh)
885         {
886             pSh = ::GetActiveWrtShell();
887         }
888 		if (nTypeId == REFFLDFLAG_BOOKMARK)		// TextMarken!
889 		{
890 			aName = aNameED.GetText();
891 			nTypeId = TYP_GETREFFLD;
892 			nSubType = REF_BOOKMARK;
893 		}
894 		else if (REFFLDFLAG_FOOTNOTE == nTypeId) 		// Fussnoten
895 		{
896 			SwSeqFldList aArr;
897 			_SeqFldLstElem aElem( aSelectionLB.GetSelectEntry(), 0 );
898 
899 			sal_uInt16 nPos;
900 
901 			nTypeId = TYP_GETREFFLD;
902 			nSubType = REF_FOOTNOTE;
903 			aName.Erase();
904 
905             if (pSh->GetSeqFtnList(aArr) && aArr.SeekEntry(aElem, &nPos))
906 			{
907 				aVal = String::CreateFromInt32( aArr[nPos]->nSeqNo );
908 
909 				if (IsFldEdit() && aArr[nPos]->nSeqNo == pRefFld->GetSeqNo())
910 					bModified = sal_True; // Kann bei Feldern passieren, deren Referenz geloescht wurde
911 			}
912 			else if (IsFldEdit())
913 				aVal = String::CreateFromInt32( pRefFld->GetSeqNo() );
914 		}
915 		else if (REFFLDFLAG_ENDNOTE == nTypeId) 		// Endnoten
916 		{
917 			SwSeqFldList aArr;
918 			_SeqFldLstElem aElem( aSelectionLB.GetSelectEntry(), 0 );
919 
920 			sal_uInt16 nPos;
921 
922 			nTypeId = TYP_GETREFFLD;
923 			nSubType = REF_ENDNOTE;
924 			aName.Erase();
925 
926             if (pSh->GetSeqFtnList(aArr, true) && aArr.SeekEntry(aElem, &nPos))
927 			{
928 				aVal = String::CreateFromInt32( aArr[nPos]->nSeqNo );
929 
930 				if (IsFldEdit() && aArr[nPos]->nSeqNo == pRefFld->GetSeqNo())
931 					bModified = sal_True; // Kann bei Feldern passieren, deren Referenz geloescht wurde
932 			}
933 			else if (IsFldEdit())
934 				aVal = String::CreateFromInt32( pRefFld->GetSeqNo() );
935 		}
936         // --> OD 2007-11-16 #i83479#
937         else if ( nTypeId == REFFLDFLAG_HEADING )
938         {
939             SvLBoxEntry* pEntry = aSelectionToolTipLB.GetCurEntry();
940             ASSERT( pEntry,
941                     "<SwFldRefPage::FillItemSet(..)> - no entry selected in selection tool tip listbox!" );
942             if ( pEntry )
943             {
944                 const sal_uInt16 nOutlIdx( static_cast<sal_uInt16>(reinterpret_cast<sal_uLong>(pEntry->GetUserData())) );
945                 pSh->getIDocumentOutlineNodesAccess()->getOutlineNodes( maOutlineNodes );
946                 if ( nOutlIdx < maOutlineNodes.size() )
947                 {
948                     ::sw::mark::IMark const * const pMark = pSh->getIDocumentMarkAccess()->getMarkForTxtNode(
949                         *(maOutlineNodes[nOutlIdx]),
950                         IDocumentMarkAccess::CROSSREF_HEADING_BOOKMARK);
951                     aName = pMark->GetName();
952                     nTypeId = TYP_GETREFFLD;
953                     nSubType = REF_BOOKMARK;
954                 }
955             }
956         }
957         else if ( nTypeId == REFFLDFLAG_NUMITEM )
958         {
959             SvLBoxEntry* pEntry = aSelectionToolTipLB.GetCurEntry();
960             ASSERT( pEntry,
961                     "<SwFldRefPage::FillItemSet(..)> - no entry selected in selection tool tip listbox!" );
962             if ( pEntry )
963             {
964                 const sal_uInt16 nNumItemIdx( static_cast<sal_uInt16>(reinterpret_cast<sal_uLong>(pEntry->GetUserData())) );
965                 pSh->getIDocumentListItemsAccess()->getNumItems( maNumItems );
966                 if ( nNumItemIdx < maNumItems.size() )
967                 {
968                     ::sw::mark::IMark const * const pMark = pSh->getIDocumentMarkAccess()->getMarkForTxtNode(
969                         *(maNumItems[nNumItemIdx]->GetTxtNode()),
970                         IDocumentMarkAccess::CROSSREF_NUMITEM_BOOKMARK);
971                     aName = pMark->GetName();
972                     nTypeId = TYP_GETREFFLD;
973                     nSubType = REF_BOOKMARK;
974                 }
975             }
976         }
977         // <--
978         else                                // SeqenceFelder
979 		{
980 			// zum Seq-FeldTyp die Felder besorgen:
981             SwSetExpFieldType* pType = (SwSetExpFieldType*)pSh->GetFldType(
982 									nTypeId & ~REFFLDFLAG, RES_SETEXPFLD );
983 			if( pType )
984 			{
985 				SwSeqFldList aArr;
986 				_SeqFldLstElem aElem( aSelectionLB.GetSelectEntry(), 0 );
987 
988 				sal_uInt16 nPos;
989 
990 				nTypeId = TYP_GETREFFLD;
991 				nSubType = REF_SEQUENCEFLD;
992 				aName = pType->GetName();
993 
994 				if (pType->GetSeqFldList(aArr) && aArr.SeekEntry(aElem, &nPos))
995 				{
996 					aVal = String::CreateFromInt32( aArr[nPos]->nSeqNo );
997 
998 					if (IsFldEdit() && aArr[nPos]->nSeqNo == pRefFld->GetSeqNo())
999 						bModified = sal_True; // Kann bei Feldern passieren, deren Referenz geloescht wurde
1000 				}
1001 				else if (IsFldEdit())
1002 					aVal = String::CreateFromInt32( pRefFld->GetSeqNo() );
1003 			}
1004 		}
1005 	}
1006 
1007 	if (IsFldEdit() && nTypeId == TYP_GETREFFLD)
1008 	{
1009 		aVal.Insert('|', 0);
1010 		aVal.Insert(String::CreateFromInt32(nSubType), 0);
1011 	}
1012 
1013 	if (!IsFldEdit() || bModified ||
1014 		aNameED.GetSavedValue() != aNameED.GetText() ||
1015 		aValueED.GetSavedValue() != aValueED.GetText() ||
1016 		aTypeLB.GetSavedValue() != aTypeLB.GetSelectEntryPos() ||
1017 		aSelectionLB.GetSavedValue() != aSelectionLB.GetSelectEntryPos() ||
1018 		aFormatLB.GetSavedValue() != aFormatLB.GetSelectEntryPos())
1019 	{
1020 		InsertFld( nTypeId, nSubType, aName, aVal, nFormat );
1021 	}
1022 
1023 	ModifyHdl();	// Insert ggf enablen/disablen
1024 
1025 	return sal_False;
1026 }
1027 
1028 /*--------------------------------------------------------------------
1029 	Beschreibung:
1030  --------------------------------------------------------------------*/
1031 
Create(Window * pParent,const SfxItemSet & rAttrSet)1032 SfxTabPage* SwFldRefPage::Create( 	Window* pParent,
1033 						const SfxItemSet& rAttrSet )
1034 {
1035 	return ( new SwFldRefPage( pParent, rAttrSet ) );
1036 }
1037 
1038 /*--------------------------------------------------------------------
1039 	Beschreibung:
1040  --------------------------------------------------------------------*/
1041 
GetGroup()1042 sal_uInt16 SwFldRefPage::GetGroup()
1043 {
1044 	return GRP_REF;
1045 }
1046 
1047 /* -----------------12.01.99 10:09-------------------
1048  *
1049  * --------------------------------------------------*/
FillUserData()1050 void	SwFldRefPage::FillUserData()
1051 {
1052 	String sData( String::CreateFromAscii(
1053 					RTL_CONSTASCII_STRINGPARAM( USER_DATA_VERSION )));
1054 	sData += ';';
1055 	sal_uInt16 nTypeSel = aTypeLB.GetSelectEntryPos();
1056 	if( LISTBOX_ENTRY_NOTFOUND == nTypeSel )
1057 		nTypeSel = USHRT_MAX;
1058 	else
1059         nTypeSel = sal::static_int_cast< sal_uInt16 >(reinterpret_cast< sal_uIntPtr >(aTypeLB.GetEntryData( nTypeSel )));
1060 	sData += String::CreateFromInt32( nTypeSel );
1061 	SetUserData(sData);
1062 }
1063 
1064