xref: /AOO41X/main/sw/source/ui/index/swuiidxmrk.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sw.hxx"
30 #ifdef SW_DLLIMPLEMENTATION
31 #undef SW_DLLIMPLEMENTATION
32 #endif
33 
34 #include "swuiidxmrk.hxx"
35 #include <hintids.hxx>
36 #include <helpid.h>
37 #define _SVSTDARR_STRINGSSORT
38 #include <svl/svstdarr.hxx>
39 #include <comphelper/processfactory.hxx>
40 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
41 #include <com/sun/star/beans/PropertyValue.hpp>
42 #include <com/sun/star/beans/XPropertySet.hpp>
43 #include <com/sun/star/util/SearchOptions.hpp>
44 #include <com/sun/star/util/SearchFlags.hpp>
45 #include <com/sun/star/i18n/TransliterationModules.hpp>
46 #include <svl/stritem.hxx>
47 #include <vcl/msgbox.hxx>
48 #include <sfx2/dispatch.hxx>
49 #include <svl/eitem.hxx>
50 #include <svtools/txtcmp.hxx>
51 #include <editeng/scripttypeitem.hxx>
52 #include <svl/itemset.hxx>
53 #include <editeng/langitem.hxx>
54 #include "editeng/unolingu.hxx"
55 #include <swtypes.hxx>
56 #include <idxmrk.hxx>
57 #include <txttxmrk.hxx>
58 #include <wrtsh.hxx>
59 #include <view.hxx>
60 #include <multmrk.hxx>
61 #include <swundo.hxx>               	// fuer Undo-Ids
62 #include <cmdid.h>
63 #include <index.hrc>
64 #include <idxmrk.hrc>
65 #include <swmodule.hxx>
66 #include <fldmgr.hxx>
67 #include <fldbas.hxx>
68 #include <utlui.hrc>
69 #include <swcont.hxx>
70 #include <svl/cjkoptions.hxx>
71 #include <ndtxt.hxx>
72 #include <breakit.hxx>
73 #include <SwRewriter.hxx>
74 
75 #include "swuiidxmrk.hxx"
76 #include <unomid.h>
77 
78 
79 #define POS_CONTENT 0
80 #define POS_INDEX   1
81 #define POS_USER    2
82 
83 static sal_uInt16 nTypePos = 1; // TOX_INDEX as standard
84 static sal_uInt16 nKey1Pos = USHRT_MAX;
85 
86 static sal_uInt16 nKey2Pos = USHRT_MAX;
87 
88 using namespace com::sun::star;
89 using namespace com::sun::star::i18n;
90 using namespace com::sun::star::lang;
91 using namespace com::sun::star::util;
92 using namespace com::sun::star::i18n;
93 using ::rtl::OUString;
94 using namespace ::comphelper;
95 using namespace ::com::sun::star;
96 
97 /*--------------------------------------------------------------------
98 	 Beschreibung:	Dialog zum Einfuegen einer Verzeichnismarkierung
99  --------------------------------------------------------------------*/
100 SwIndexMarkDlg::SwIndexMarkDlg(Window *pParent,
101 							   sal_Bool bNewDlg,
102 							   const ResId& rResId,
103                                sal_Int32 _nOptionsId, SwWrtShell& rWrtShell ) :
104 	  Window(pParent, rResId),
105     aIndexFL(this,  SW_RES(FL_INDEX )),
106     aTypeFT (this,  SW_RES(LBL_INDEX    )),
107     aTypeDCB(this,  SW_RES(DCB_INDEX    )),
108 	aNewBT(this, 	SW_RES(BT_NEW 	)),
109 
110     aEntryFT(this,  SW_RES(LBL_ENTRY    )),
111     aEntryED(this,  SW_RES(SL_ENTRY )),
112     aPhoneticFT0(this,  SW_RES(FT_PHONETIC_1 )),
113     aPhoneticED0(this,  SW_RES(ED_PHONETIC_1 )),
114 
115     aKeyFT(this,    SW_RES(LBL_KEY  )),
116     aKeyDCB(this,   SW_RES(DCB_KEY  )),
117     aPhoneticFT1(this,  SW_RES(FT_PHONETIC_2 )),
118     aPhoneticED1(this,  SW_RES(ED_PHONETIC_2 )),
119 
120     aKey2FT(this,   SW_RES(LBL_KEY2 )),
121     aKey2DCB(this,  SW_RES(DCB_KEY2 )),
122     aPhoneticFT2(this,  SW_RES(FT_PHONETIC_3 )),
123     aPhoneticED2(this,  SW_RES(ED_PHONETIC_3 )),
124 
125     aLevelFT(this,  SW_RES(LBL_LEVEL    )),
126     aLevelED(this,  SW_RES(SL_LEVEL )),
127     aMainEntryCB(this, SW_RES(CB_MAIN_ENTRY )),
128     aApplyToAllCB(this,SW_RES(CB_APPLY_TO_ALL)),
129     aSearchCaseSensitiveCB(this,    SW_RES(CB_CASESENSITIVE )),
130     aSearchCaseWordOnlyCB(this,     SW_RES(CB_WORDONLY      )),
131 
132 
133     aOKBT(this,     SW_RES(BT_OK    )),
134     aCancelBT(this, SW_RES(BT_CANCEL )),
135     aHelpBT(this,   SW_RES(BT_HELP   )),
136     aDelBT(this,    SW_RES(BT_DEL   )),
137 
138     aPrevSameBT(this,SW_RES(BT_PREVSAME)),
139     aNextSameBT(this,SW_RES(BT_NXTSAME)),
140     aPrevBT(this,   SW_RES(BT_PREV  )),
141     aNextBT(this,   SW_RES(BT_NXT   )),
142 
143     nOptionsId( _nOptionsId ),
144     bDel(sal_False),
145     bNewMark(bNewDlg),
146     bSelected(sal_False),
147 
148     bPhoneticED0_ChangedByUser(sal_False),
149 	bPhoneticED1_ChangedByUser(sal_False),
150 	bPhoneticED2_ChangedByUser(sal_False),
151     nLangForPhoneticReading(2052),
152     bIsPhoneticReadingEnabled(sal_False),
153     xExtendedIndexEntrySupplier(NULL),
154     pTOXMgr(0),
155     pSh(&rWrtShell)
156 {
157 	aNewBT.SetAccessibleRelationMemberOf(&aIndexFL);
158 
159 	if( SvtCJKOptions().IsCJKFontEnabled() )
160 	{
161 		uno::Reference< lang::XMultiServiceFactory > xMSF = getProcessServiceFactory();
162 
163 		xExtendedIndexEntrySupplier =
164             uno::Reference< i18n::XExtendedIndexEntrySupplier > (
165 					xMSF->createInstance( C2U("com.sun.star.i18n.IndexEntrySupplier") ),
166 																		uno::UNO_QUERY );
167 	}
168 
169 	SetStyle(GetStyle()|WB_DIALOGCONTROL);
170 	FreeResource();
171 	aOKBT			.SetHelpId(HID_INSERT_IDX_MRK_OK   		);
172 	aCancelBT		.SetHelpId(HID_INSERT_IDX_MRK_CLOSE		);
173 	aDelBT      	.SetHelpId(HID_INSERT_IDX_MRK_DELETE	);
174 	aNewBT      	.SetHelpId(HID_INSERT_IDX_MRK_NEW		);
175 	aPrevBT     	.SetHelpId(HID_INSERT_IDX_MRK_PREV		);
176 	aPrevSameBT 	.SetHelpId(HID_INSERT_IDX_MRK_PREV_SAME	);
177 	aNextBT     	.SetHelpId(HID_INSERT_IDX_MRK_NEXT		);
178 	aNextSameBT 	.SetHelpId(HID_INSERT_IDX_MRK_NEXT_SAME	);
179 	aTypeDCB    	.SetHelpId(HID_INSERT_IDX_MRK_TYPE		);
180 	aEntryED    	.SetHelpId(HID_INSERT_IDX_MRK_ENTRY		);
181 	aKeyDCB     	.SetHelpId(HID_INSERT_IDX_MRK_PRIM_KEY	);
182 	aKey2DCB    	.SetHelpId(HID_INSERT_IDX_MRK_SEC_KEY	);
183 	aLevelED    	.SetHelpId(HID_INSERT_IDX_MRK_LEVEL		);
184 	aMainEntryCB	.SetHelpId(HID_INSERT_IDX_MRK_MAIN_ENTRY);
185 	aApplyToAllCB	.SetHelpId(HID_INSERT_IDX_MRK_APPLY_ALL	);
186 	aPhoneticED0	.SetHelpId(HID_INSERT_IDX_MRK_PHONETIC_READING );
187 	aPhoneticED1	.SetHelpId(HID_INSERT_IDX_MRK_PHONETIC_READING );
188 	aPhoneticED2	.SetHelpId(HID_INSERT_IDX_MRK_PHONETIC_READING );
189 
190 	aSearchCaseSensitiveCB.SetHelpId(	HID_INSERT_IDX_MRK_SRCH_CASESENSITIVE	);
191 	aSearchCaseWordOnlyCB.SetHelpId(	HID_INSERT_IDX_MRK_SRCH_WORDONLY		);
192 
193 
194 	GetParent()->SetText( SW_RESSTR( bNewMark ? STR_IDXMRK_INSERT : STR_IDXMRK_EDIT));
195 
196 	aDelBT.SetClickHdl(LINK(this,SwIndexMarkDlg, 		DelHdl));
197 	aPrevBT.SetClickHdl(LINK(this,SwIndexMarkDlg, 		PrevHdl));
198 	aPrevSameBT.SetClickHdl(LINK(this,SwIndexMarkDlg, 	PrevSameHdl));
199 	aNextBT.SetClickHdl(LINK(this,SwIndexMarkDlg, 		NextHdl));
200 	aNextSameBT.SetClickHdl(LINK(this,SwIndexMarkDlg, 	NextSameHdl));
201 	//aTypeDCB.SetModifyHdl(LINK(this,SwIndexMarkDlg, 	ModifyHdl));
202 	aTypeDCB.SetSelectHdl(LINK(this,SwIndexMarkDlg, 	ModifyHdl));
203 	aKeyDCB.SetModifyHdl(LINK(this,SwIndexMarkDlg, 		KeyDCBModifyHdl));
204 	aKey2DCB.SetModifyHdl(LINK(this,SwIndexMarkDlg, 	KeyDCBModifyHdl));
205 	aOKBT.SetClickHdl(LINK(this,SwIndexMarkDlg, 		InsertHdl));
206 	aCancelBT.SetClickHdl(LINK(this,SwIndexMarkDlg, 	CloseHdl));
207 	aEntryED.SetModifyHdl(LINK(this,SwIndexMarkDlg, 	ModifyHdl));
208 	aNewBT.SetClickHdl(LINK(this, SwIndexMarkDlg,       NewUserIdxHdl));
209 	aApplyToAllCB.SetClickHdl(LINK(this, SwIndexMarkDlg, SearchTypeHdl));
210 	aPhoneticED0.SetModifyHdl(LINK(this,SwIndexMarkDlg, PhoneticEDModifyHdl));
211 	aPhoneticED1.SetModifyHdl(LINK(this,SwIndexMarkDlg, PhoneticEDModifyHdl));
212 	aPhoneticED2.SetModifyHdl(LINK(this,SwIndexMarkDlg, PhoneticEDModifyHdl));
213 
214 	if(bNewMark)
215 	{
216 		aDelBT.Hide();
217 
218 		{
219 			ImageList aTempList( SW_RES( IMG_NAVI_ENTRYBMPH ) );
220 			aNewBT.SetModeImage( aTempList.GetImage( SID_SW_START + CONTENT_TYPE_INDEX ), BMP_COLOR_HIGHCONTRAST );
221 		}
222 
223 		{
224 			ImageList aTempList( SW_RES( IMG_NAVI_ENTRYBMP ) );
225 			aNewBT.SetModeImage( aTempList.GetImage( SID_SW_START + CONTENT_TYPE_INDEX ), BMP_COLOR_NORMAL );
226 		}
227 	}
228 	else
229 	{
230 		aNewBT.Hide();
231 		OKButton aTmp(this, WB_HIDE);
232 		aOKBT.SetText( aTmp.GetText() );
233 	}
234 
235     aEntryED.GrabFocus();
236 }
237 
238 /*--------------------------------------------------------------------
239 	 Beschreibung:	Controls neu initialisieren mit der aktuellen
240 					Markierung
241  --------------------------------------------------------------------*/
242 
243 
244 void SwIndexMarkDlg::InitControls()
245 {
246 	DBG_ASSERT(pSh && pTOXMgr, "Shell nicht da?");
247 	// Inhalts-Verzeichnis
248 	const SwTOXType* pType = pTOXMgr->GetTOXType(TOX_CONTENT, 0);
249 	ASSERT(pType, "Kein Verzeichnistyp !!");
250 	String sTmpTypeSelection;
251 	if(aTypeDCB.GetSelectEntryCount())
252 		sTmpTypeSelection = aTypeDCB.GetSelectEntry();
253 	aTypeDCB.Clear();
254 	aTypeDCB.InsertEntry(pType->GetTypeName());
255 
256 	// Stichwort-Verzeichnis
257 	pType = pTOXMgr->GetTOXType(TOX_INDEX, 0);
258 	ASSERT(pType, "Kein Verzeichnistyp !!");
259 	aTypeDCB.InsertEntry(pType->GetTypeName());
260 
261 	// Benutzerverzeichnisse
262 	sal_uInt16 nCount = pSh->GetTOXTypeCount(TOX_USER);
263 	sal_uInt16 i;
264 	for( i = 0; i < nCount; ++i )
265 		aTypeDCB.InsertEntry( pSh->GetTOXType(TOX_USER, i)->GetTypeName() );
266 
267 	// KeyWords Primary einlesen
268 	SvStringsSort aArr;
269 	nCount = pSh->GetTOIKeys( TOI_PRIMARY, aArr );
270 	for(i=0; i < nCount; ++i)
271 		aKeyDCB.InsertEntry( *aArr[ i ] );
272 
273 	// KeyWords Secondary einlesen
274 	nCount = pSh->GetTOIKeys( TOI_SECONDARY, aArr );
275 	for(i=0; i < nCount; ++i)
276 		aKey2DCB.InsertEntry( *aArr[ i ] );
277 
278 	UpdateLanguageDependenciesForPhoneticReading();
279 
280 	// Aktueller Eintrag
281 	const SwTOXMark* pMark = pTOXMgr->GetCurTOXMark();
282 	if( pMark && !bNewMark)
283 	{
284 		// Controls-Handling
285 
286 		// nur wenn mehr als eins vorhanden
287 		// wenn gleich landet es auf dem gleichen Eintrag
288 		pSh->SttCrsrMove();
289 
290 		const SwTOXMark* pMoveMark;
291 		sal_Bool bShow = sal_False;
292 
293 		pMoveMark = &pSh->GotoTOXMark( *pMark, TOX_PRV );
294 		if( pMoveMark != pMark )
295 			pSh->GotoTOXMark( *pMoveMark, TOX_NXT ), bShow = sal_True;
296 		aPrevBT.Enable( pMoveMark != pMark );
297 		pMoveMark = &pSh->GotoTOXMark( *pMark, TOX_NXT );
298 		if( pMoveMark != pMark )
299 			pSh->GotoTOXMark( *pMoveMark, TOX_PRV ), bShow = sal_True;
300 		aNextBT.Enable( pMoveMark != pMark );
301 		if( bShow )
302 		{
303 			aPrevBT.Show();
304 			aNextBT.Show();
305 			bShow = sal_False;
306 		}
307 
308 		pMoveMark = &pSh->GotoTOXMark( *pMark, TOX_SAME_PRV );
309 		if( pMoveMark != pMark )
310 			pSh->GotoTOXMark( *pMoveMark, TOX_SAME_NXT ), bShow = sal_True;
311 		aPrevSameBT.Enable( pMoveMark != pMark );
312 		pMoveMark = &pSh->GotoTOXMark( *pMark, TOX_SAME_NXT );
313 		if( pMoveMark != pMark )
314 			pSh->GotoTOXMark( *pMoveMark, TOX_SAME_PRV ), bShow = sal_True;
315 		aNextSameBT.Enable( pMoveMark != pMark );
316 		if( bShow )
317 		{
318 			aNextSameBT.Show();
319 			aPrevSameBT.Show();
320 		}
321 		pSh->EndCrsrMove();
322 
323 		aTypeFT.Show();
324 
325 		aTypeDCB.Enable(sal_False);
326 		aTypeFT.Enable(sal_False);
327 
328 		UpdateDialog();
329 	}
330 	else
331 	{ 	// aktuelle Selektion (1.Element) anzeigen  ????
332 		sal_uInt16 nCnt = pSh->GetCrsrCnt();
333 		if (nCnt < 2)
334 		{
335 			bSelected = !pSh->HasSelection();
336 			aOrgStr = pSh->GetView().GetSelectionTextParam(sal_True, sal_False);
337 			aEntryED.SetText(aOrgStr);
338 
339 			//alle gleichen Eintraege aufzunehmen darf nur im Body und auch da nur
340 			//bei vorhandener einfacher Selektion erlaubt werden
341 			const sal_uInt16 nFrmType = pSh->GetFrmType(0,sal_True);
342 			aApplyToAllCB.Show();
343 			aSearchCaseSensitiveCB.Show();
344 			aSearchCaseWordOnlyCB.Show();
345 			aApplyToAllCB.Enable(0 != aOrgStr.Len() &&
346 				0 == (nFrmType & ( FRMTYPE_HEADER | FRMTYPE_FOOTER | FRMTYPE_FLY_ANY )));
347 			SearchTypeHdl(&aApplyToAllCB);
348 		}
349 
350 		// Verzeichnistyp ist default
351 		if(	sTmpTypeSelection.Len() &&
352 			LISTBOX_ENTRY_NOTFOUND != aTypeDCB.GetEntryPos( sTmpTypeSelection ) )
353             aTypeDCB.SelectEntry(sTmpTypeSelection);
354 		else
355 			aTypeDCB.SelectEntry(aTypeDCB.GetEntry(nTypePos));
356 		ModifyHdl(&aTypeDCB);
357 	}
358 }
359 
360 void	SwIndexMarkDlg::UpdateLanguageDependenciesForPhoneticReading()
361 {
362 	//no phonetic reading if no global cjk support
363 	if( !xExtendedIndexEntrySupplier.is() )
364 	{
365 		bIsPhoneticReadingEnabled = sal_False;
366 		return;
367 	}
368 	bIsPhoneticReadingEnabled = sal_True;
369 
370 	//get the current language
371 	if(!bNewMark) //if dialog is opened to iterate existing marks
372 	{
373 		ASSERT(pTOXMgr, "need TOXMgr")
374 		if(!pTOXMgr)
375 			return;
376 		SwTOXMark* pMark = pTOXMgr->GetCurTOXMark();
377 		ASSERT(pMark, "need current SwTOXMark");
378 		if(!pMark)
379 			return;
380 		SwTxtTOXMark* pTxtTOXMark = pMark->GetTxtTOXMark();
381 		ASSERT(pTxtTOXMark, "need current SwTxtTOXMark");
382 		if(!pTxtTOXMark)
383 			return;
384 		const SwTxtNode* pTxtNode = pTxtTOXMark->GetpTxtNd();
385 		ASSERT(pTxtNode, "need current SwTxtNode");
386 		if(!pTxtNode)
387 			return;
388 		xub_StrLen nTextIndex = *pTxtTOXMark->GetStart();
389 		nLangForPhoneticReading = pTxtNode->GetLang( nTextIndex );
390 	}
391 	else //if dialog is opened to create a new mark
392 	{
393 		sal_uInt16 nScriptType = pSh->GetScriptType();
394 		sal_uInt16 nWhich;
395 		switch(nScriptType)
396 		{
397 			case SCRIPTTYPE_ASIAN: nWhich = RES_CHRATR_CJK_LANGUAGE; break;
398 			case SCRIPTTYPE_COMPLEX:nWhich = RES_CHRATR_CTL_LANGUAGE; break;
399 			//case SCRIPTTYPE_LATIN:
400 			default:nWhich = RES_CHRATR_LANGUAGE; break;
401 		}
402         SfxItemSet aLangSet(pSh->GetAttrPool(), nWhich, nWhich);
403         pSh->GetCurAttr(aLangSet);
404         nLangForPhoneticReading = ((const SvxLanguageItem&)aLangSet.Get(nWhich)).GetLanguage();
405 	}
406 
407 	/*
408 	//enable phonetic reading dependent on the current language
409 	{
410 		lang::Locale aLocale( SvxCreateLocale( LanguageType( nLangForPhoneticReading ) ) );
411 		bIsPhoneticReadingEnabled = xExtendedIndexEntrySupplier->usePhoneticEntry( aLocale );
412 	}
413 	*/
414 }
415 
416 String	SwIndexMarkDlg::GetDefaultPhoneticReading( const String& rText )
417 {
418 	if( !bIsPhoneticReadingEnabled )
419 		return aEmptyStr;
420 
421 	lang::Locale aLocale( SvxCreateLocale( LanguageType( nLangForPhoneticReading ) ) );
422 	return xExtendedIndexEntrySupplier->getPhoneticCandidate(rText, aLocale);
423 }
424 
425 /* -----------------07.09.99 10:43-------------------
426 	Change the content of aEntryED if text is selected
427  --------------------------------------------------*/
428 
429 void	SwIndexMarkDlg::Activate()
430 {
431 	// aktuelle Selektion (1.Element) anzeigen  ????
432 	if(bNewMark)
433 	{
434 		sal_uInt16 nCnt = pSh->GetCrsrCnt();
435 		if (nCnt < 2)
436 		{
437 			bSelected = !pSh->HasSelection();
438 			aOrgStr = pSh->GetView().GetSelectionTextParam(sal_True, sal_False);
439 			aEntryED.SetText(aOrgStr);
440 
441 			//alle gleichen Eintraege aufzunehmen darf nur im Body und auch da nur
442 			//bei vorhandener einfacher Selektion erlaubt werden
443 			const sal_uInt16 nFrmType = pSh->GetFrmType(0,sal_True);
444 			aApplyToAllCB.Show();
445 			aSearchCaseSensitiveCB.Show();
446 			aSearchCaseWordOnlyCB.Show();
447 			aApplyToAllCB.Enable(0 != aOrgStr.Len() &&
448 				0 == (nFrmType & ( FRMTYPE_HEADER | FRMTYPE_FOOTER | FRMTYPE_FLY_ANY )));
449 			SearchTypeHdl(&aApplyToAllCB);
450 		}
451 		ModifyHdl(&aTypeDCB);
452 	}
453 }
454 
455 /*--------------------------------------------------------------------
456 	 Beschreibung:	Ok-Button auswerten
457  --------------------------------------------------------------------*/
458 void SwIndexMarkDlg::Apply()
459 {
460 	InsertUpdate();
461 	if(bSelected)
462 		pSh->ResetSelect(0, sal_False);
463 }
464 
465 /*--------------------------------------------------------------------
466 	Beschreibung: Aenderungen uebernehmen
467  --------------------------------------------------------------------*/
468 
469 
470 void SwIndexMarkDlg::InsertUpdate()
471 {
472 	pSh->StartUndo(bDel ? UNDO_INDEX_ENTRY_DELETE : UNDO_INDEX_ENTRY_INSERT);
473 	pSh->StartAllAction();
474 
475     SwRewriter aRewriter;
476 
477 	if( bNewMark )
478     {
479 		InsertMark();
480 
481         if ( pTOXMgr->GetCurTOXMark())
482             aRewriter.AddRule(UNDO_ARG1, pTOXMgr->GetCurTOXMark()->GetText());
483     }
484 	else if( !pSh->HasReadonlySel() )
485 	{
486         if ( pTOXMgr->GetCurTOXMark())
487             aRewriter.AddRule(UNDO_ARG1,
488                               pTOXMgr->GetCurTOXMark()->GetText());
489 
490 		if( bDel )
491 			pTOXMgr->DeleteTOXMark();
492 		else if( pTOXMgr->GetCurTOXMark() )
493 			UpdateMark();
494 	}
495 
496 	pSh->EndAllAction();
497 	pSh->EndUndo(bDel ? UNDO_INDEX_ENTRY_DELETE : UNDO_INDEX_ENTRY_INSERT);
498 
499 	if((nTypePos = aTypeDCB.GetEntryPos(aTypeDCB.GetSelectEntry())) == LISTBOX_ENTRY_NOTFOUND)
500 		nTypePos = 0;
501 
502 	nKey1Pos = aKeyDCB.GetEntryPos(aKeyDCB.GetText());
503 	nKey2Pos = aKey2DCB.GetEntryPos(aKey2DCB.GetText());
504 }
505 
506 /*--------------------------------------------------------------------
507 	 Beschreibung:	Marke einfuegen
508  --------------------------------------------------------------------*/
509 static void lcl_SelectSameStrings(SwWrtShell& rSh, sal_Bool bWordOnly, sal_Bool bCaseSensitive)
510 {
511 	rSh.Push();
512 
513 	SearchOptions aSearchOpt(
514 						SearchAlgorithms_ABSOLUTE,
515 						( bWordOnly ? SearchFlags::NORM_WORD_ONLY : 0 ),
516 						rSh.GetSelTxt(), OUString(),
517 						SvxCreateLocale( GetAppLanguage() ),
518 						0, 0, 0,
519 						(bCaseSensitive
520 							? 0
521 							: TransliterationModules_IGNORE_CASE) );
522 
523 	rSh.ClearMark();
524     sal_Bool bCancel;
525 
526 	//todo/mba: assuming that notes should not be searched
527 	sal_Bool bSearchInNotes = sal_False;
528     rSh.Find( aSearchOpt,  bSearchInNotes, DOCPOS_START, DOCPOS_END, bCancel,
529                         (FindRanges)(FND_IN_SELALL|FND_IN_BODYONLY), sal_False );
530 }
531 
532 
533 void SwIndexMarkDlg::InsertMark()
534 {
535 	sal_uInt16 nPos = aTypeDCB.GetEntryPos(aTypeDCB.GetSelectEntry());
536 	TOXTypes eType = nPos == POS_CONTENT ? TOX_CONTENT :
537 						nPos == POS_INDEX ? TOX_INDEX : TOX_USER;
538 
539 	SwTOXMarkDescription aDesc(eType);
540 
541 	sal_uInt16 nLevel = (sal_uInt16)aLevelED.Denormalize(aLevelED.GetValue());
542 	switch(nPos)
543 	{
544 		case POS_CONTENT : break;
545 		case POS_INDEX:  	// Stichwortverzeichnismarke
546 		{
547 			UpdateKeyBoxes();
548 			String  aPrim(aKeyDCB.GetText());
549 			String  aSec(aKey2DCB.GetText());
550 			aDesc.SetPrimKey(aPrim);
551 			aDesc.SetSecKey(aSec);
552 			aDesc.SetMainEntry(aMainEntryCB.IsChecked());
553 			aDesc.SetPhoneticReadingOfAltStr(aPhoneticED0.GetText());
554 			aDesc.SetPhoneticReadingOfPrimKey(aPhoneticED1.GetText());
555 			aDesc.SetPhoneticReadingOfSecKey(aPhoneticED2.GetText());
556 		}
557 		break;
558 		default:            // Userdefinedverz.-Marke
559 		{
560 			String aName(aTypeDCB.GetSelectEntry());
561 			aDesc.SetTOUName(aName);
562 		}
563 	}
564 	if (aOrgStr != aEntryED.GetText())
565 		aDesc.SetAltStr(aEntryED.GetText());
566 	sal_Bool bApplyAll = aApplyToAllCB.IsChecked();
567     sal_Bool bWordOnly = aSearchCaseWordOnlyCB.IsChecked();
568 	sal_Bool bCaseSensitive = aSearchCaseSensitiveCB.IsChecked();
569 
570 	pSh->StartAllAction();
571 	// hier muessen alle gleichen Strings selektiert werden
572 	// damit der Eintrag auf alle gleichen Strings angewandt wird
573 	if(bApplyAll)
574 	{
575 		lcl_SelectSameStrings(*pSh, bWordOnly, bCaseSensitive);
576 	}
577 	aDesc.SetLevel(nLevel);
578 	SwTOXMgr aMgr(pSh);
579 	aMgr.InsertTOXMark(aDesc);
580 	if(bApplyAll)
581 		pSh->Pop(sal_False);
582 
583 	pSh->EndAllAction();
584 }
585 
586 /*--------------------------------------------------------------------
587 	 Beschreibung:	Marke Updaten
588  --------------------------------------------------------------------*/
589 
590 
591 void SwIndexMarkDlg::UpdateMark()
592 {
593 	String 	aAltText(aEntryED.GetText());
594 	String* pAltText = aOrgStr != aEntryED.GetText() ? &aAltText : 0;
595 	//empty alternative texts are not allowed
596 	if(pAltText && !pAltText->Len())
597 		return;
598 
599 	UpdateKeyBoxes();
600 
601 	sal_uInt16 nPos = aTypeDCB.GetEntryPos(aTypeDCB.GetSelectEntry());
602 	TOXTypes eType = TOX_USER;
603 	if(POS_CONTENT == nPos)
604 		eType = TOX_CONTENT;
605 	else if(POS_INDEX == nPos)
606 		eType = TOX_INDEX;
607 
608 	SwTOXMarkDescription aDesc(eType);
609     aDesc.SetLevel( static_cast< int >(aLevelED.GetValue()) );
610 	if(pAltText)
611 		aDesc.SetAltStr(*pAltText);
612 
613 	String  aPrim(aKeyDCB.GetText());
614 	if(aPrim.Len())
615 		aDesc.SetPrimKey(aPrim);
616 	String  aSec(aKey2DCB.GetText());
617 	if(aSec.Len())
618 		aDesc.SetSecKey(aSec);
619 
620 	if(eType == TOX_INDEX)
621 	{
622 		aDesc.SetPhoneticReadingOfAltStr(aPhoneticED0.GetText());
623 		aDesc.SetPhoneticReadingOfPrimKey(aPhoneticED1.GetText());
624 		aDesc.SetPhoneticReadingOfSecKey(aPhoneticED2.GetText());
625 	}
626 	aDesc.SetMainEntry(aMainEntryCB.IsVisible() && aMainEntryCB.IsChecked());
627 	pTOXMgr->UpdateTOXMark(aDesc);
628 }
629 
630 /*--------------------------------------------------------------------
631 	Beschreibung: Neue Keys eintragen
632  --------------------------------------------------------------------*/
633 
634 
635 void SwIndexMarkDlg::UpdateKeyBoxes()
636 {
637 	String aKey(aKeyDCB.GetText());
638 	sal_uInt16 nPos = aKeyDCB.GetEntryPos(aKey);
639 
640 	if(nPos == LISTBOX_ENTRY_NOTFOUND && aKey.Len() > 0)
641 	{	// neuen Key erzeugen
642 		aKeyDCB.InsertEntry(aKey);
643 	}
644 
645 	aKey = aKey2DCB.GetText();
646 	nPos = aKey2DCB.GetEntryPos(aKey);
647 
648 	if(nPos == LISTBOX_ENTRY_NOTFOUND && aKey.Len() > 0)
649 	{	// neuen Key erzeugen
650 		aKey2DCB.InsertEntry(aKey);
651 	}
652 }
653 /* -----------------13.10.99 15:10-------------------
654 
655  --------------------------------------------------*/
656 class SwNewUserIdxDlg : public ModalDialog
657 {
658 	OKButton 		aOKPB;
659 	CancelButton 	aCancelPB;
660 	HelpButton 		aHelpPB;
661     FixedLine       aNameFL;
662 	FixedText		aNameFT;
663 	Edit			aNameED;
664 
665 	SwIndexMarkDlg*	pDlg;
666 
667 	DECL_LINK( ModifyHdl, Edit*);
668 
669 	public:
670 		SwNewUserIdxDlg(SwIndexMarkDlg* pParent) :
671 			ModalDialog(pParent, SW_RES(DLG_NEW_USER_IDX)),
672             aOKPB(this, SW_RES(     PB_OK       )),
673             aCancelPB(this, SW_RES( PB_CANCEL   )),
674             aHelpPB(this, SW_RES(   PB_HELP     )),
675             aNameFL(this, SW_RES(    FL_NAME     )),
676             aNameFT(this, SW_RES(   FT_NAME     )),
677             aNameED(this, SW_RES(    ED_NAME     )),
678             pDlg(pParent)
679 			{
680 				FreeResource();
681 				aNameED.SetModifyHdl(LINK(this, SwNewUserIdxDlg, ModifyHdl));
682 				aOKPB.Enable(sal_False);
683 				aNameED.GrabFocus();
684 			}
685 
686 	virtual void	Apply();
687 	String 	GetName(){return aNameED.GetText();}
688 };
689 void SwNewUserIdxDlg::Apply()
690 {
691 }
692 
693 IMPL_LINK( SwNewUserIdxDlg, ModifyHdl, Edit*, pEdit)
694 {
695 	aOKPB.Enable(pEdit->GetText().Len() && !pDlg->IsTOXType(pEdit->GetText()));
696 	return 0;
697 }
698 
699 IMPL_LINK( SwIndexMarkDlg, NewUserIdxHdl, Button*, EMPTYARG)
700 {
701 	SwNewUserIdxDlg* pDlg = new SwNewUserIdxDlg(this);
702 	if(RET_OK == pDlg->Execute())
703 	{
704 		String sNewName(pDlg->GetName());
705 		aTypeDCB.InsertEntry(sNewName);
706 		aTypeDCB.SelectEntry(sNewName);
707 	}
708 	delete pDlg;
709 	return 0;
710 }
711 /* -----------------------------17.01.00 12:18--------------------------------
712 
713  ---------------------------------------------------------------------------*/
714 IMPL_LINK( SwIndexMarkDlg, SearchTypeHdl, CheckBox*, pBox)
715 {
716 	sal_Bool bEnable = pBox->IsChecked() && pBox->IsEnabled();
717 	aSearchCaseWordOnlyCB.Enable(bEnable);
718 	aSearchCaseSensitiveCB.Enable(bEnable);
719 	return 0;
720 }
721 /* -----------------07.09.99 10:30-------------------
722 
723  --------------------------------------------------*/
724 IMPL_LINK( SwIndexMarkDlg, InsertHdl, Button *, pButton )
725 {
726 	Apply();
727 	//close the dialog if only one entry is available
728 	if(!bNewMark && !aPrevBT.IsVisible() && !aNextBT.IsVisible())
729 		CloseHdl(pButton);
730 	return 0;
731 }
732 /* -----------------07.09.99 10:29-------------------
733 
734  --------------------------------------------------*/
735 IMPL_LINK( SwIndexMarkDlg, CloseHdl, Button *, EMPTYARG )
736 {
737 	if(bNewMark)
738 	{
739 		sal_uInt16 nSlot = FN_INSERT_IDX_ENTRY_DLG;
740 		SfxViewFrame::Current()->GetDispatcher()->Execute(nSlot,
741 					SFX_CALLMODE_ASYNCHRON|SFX_CALLMODE_RECORD);
742 	}
743 	else
744 	{
745 		((SwIndexMarkModalDlg*)GetParent())->EndDialog(RET_CANCEL);
746 	}
747 	return 0;
748 }
749 /*--------------------------------------------------------------------
750 	 Beschreibung:	VerzeichnisTyp auswaehlen nur bei Einfuegen
751  --------------------------------------------------------------------*/
752 IMPL_LINK( SwIndexMarkDlg, ModifyHdl, ListBox *, pBox )
753 {
754 	if(&aTypeDCB == pBox)
755 	{
756 		// Verzeichnistyp setzen
757 		sal_uInt16 nPos = aTypeDCB.GetEntryPos(aTypeDCB.GetSelectEntry());
758 		sal_Bool bLevelEnable = sal_False,
759 		 	bKeyEnable	  = sal_False,
760 		 	bSetKey2 	  = sal_False,
761 		 	bKey2Enable  = sal_False,
762 			bEntryHasText	= sal_False,
763 			bKey1HasText	= sal_False,
764 			bKey2HasText	= sal_False;
765 		if(nPos == POS_INDEX)
766 		{
767 			if(aEntryED.GetText().Len())
768 				bEntryHasText = sal_True;
769 			aPhoneticED0.SetText(GetDefaultPhoneticReading(aEntryED.GetText()));
770 
771 			bKeyEnable = sal_True;
772 			aKeyDCB.SetText(aKeyDCB.GetEntry(nKey1Pos));
773 			aPhoneticED1.SetText(GetDefaultPhoneticReading(aKeyDCB.GetText()));
774 			if(aKeyDCB.GetText().Len() > 0)
775 			{
776 				bKey1HasText = bSetKey2 = bKey2Enable = sal_True;
777 				aKey2DCB.SetText(aKey2DCB.GetEntry(nKey2Pos));
778 				aPhoneticED2.SetText(GetDefaultPhoneticReading(aKey2DCB.GetText()));
779 				if(aKey2DCB.GetText().Len())
780 					bKey2HasText = sal_True;
781 			}
782 		}
783 		else
784 		{
785 			bLevelEnable = sal_True;
786 			aLevelED.SetMax(MAXLEVEL);
787 			aLevelED.SetValue(aLevelED.Normalize(0));
788 			bSetKey2 = sal_True;
789 		}
790 		aLevelFT.Show(bLevelEnable);
791 		aLevelED.Show(bLevelEnable);
792 		aMainEntryCB.Show(nPos == POS_INDEX);
793 
794 		aKeyFT.Enable(bKeyEnable);
795 		aKeyDCB.Enable(bKeyEnable);
796 		if ( bSetKey2 )
797 		{
798 			aKey2DCB.Enable(bKey2Enable);
799 			aKey2FT.Enable(bKey2Enable);
800 		}
801 		aPhoneticFT0.Enable(bKeyEnable&&bEntryHasText&&bIsPhoneticReadingEnabled);
802 		aPhoneticED0.Enable(bKeyEnable&&bEntryHasText&&bIsPhoneticReadingEnabled);
803 		aPhoneticFT1.Enable(bKeyEnable&&bKey1HasText&&bIsPhoneticReadingEnabled);
804 		aPhoneticED1.Enable(bKeyEnable&&bKey1HasText&&bIsPhoneticReadingEnabled);
805 		aPhoneticFT2.Enable(bKeyEnable&&bKey2HasText&&bIsPhoneticReadingEnabled);
806 		aPhoneticED2.Enable(bKeyEnable&&bKey2HasText&&bIsPhoneticReadingEnabled);
807 	}
808 	else //aEntryED  !!aEntryED is not a ListBox but a Edit
809 	{
810 		sal_Bool bHasText = (aEntryED.GetText().Len()>0);
811 		if(!bHasText)
812 		{
813 			aPhoneticED0.SetText(aEmptyStr);
814 			bPhoneticED0_ChangedByUser = sal_False;
815 		}
816 		else if(!bPhoneticED0_ChangedByUser)
817 			aPhoneticED0.SetText(GetDefaultPhoneticReading(aEntryED.GetText()));
818 
819 		aPhoneticFT0.Enable(bHasText&&bIsPhoneticReadingEnabled);
820 		aPhoneticED0.Enable(bHasText&&bIsPhoneticReadingEnabled);
821 	}
822     aOKBT.Enable(!pSh->HasReadonlySel() &&
823         (aEntryED.GetText().Len() || pSh->GetCrsrCnt(sal_False)));
824 	return 0;
825 }
826 
827 /*--------------------------------------------------------------------
828 	 Beschreibung:
829  --------------------------------------------------------------------*/
830 
831 
832 IMPL_LINK_INLINE_START( SwIndexMarkDlg, NextHdl, Button *, EMPTYARG )
833 {
834 	InsertUpdate();
835 	pTOXMgr->NextTOXMark();
836 	UpdateDialog();
837 	return 0;
838 }
839 IMPL_LINK_INLINE_END( SwIndexMarkDlg, NextHdl, Button *, EMPTYARG )
840 
841 
842 IMPL_LINK_INLINE_START( SwIndexMarkDlg, NextSameHdl, Button *, EMPTYARG )
843 {
844 	InsertUpdate();
845 	pTOXMgr->NextTOXMark(sal_True);
846 	UpdateDialog();
847 	return 0;
848 }
849 IMPL_LINK_INLINE_END( SwIndexMarkDlg, NextSameHdl, Button *, EMPTYARG )
850 
851 
852 IMPL_LINK_INLINE_START( SwIndexMarkDlg, PrevHdl, Button *, EMPTYARG )
853 {
854 	InsertUpdate();
855 	pTOXMgr->PrevTOXMark();
856 	UpdateDialog();
857 	return 0;
858 }
859 IMPL_LINK_INLINE_END( SwIndexMarkDlg, PrevHdl, Button *, EMPTYARG )
860 
861 
862 IMPL_LINK_INLINE_START( SwIndexMarkDlg, PrevSameHdl, Button *, EMPTYARG )
863 {
864 	InsertUpdate();
865 	pTOXMgr->PrevTOXMark(sal_True);
866 	UpdateDialog();
867 
868 	return 0;
869 }
870 IMPL_LINK_INLINE_END( SwIndexMarkDlg, PrevSameHdl, Button *, EMPTYARG )
871 
872 
873 IMPL_LINK( SwIndexMarkDlg, DelHdl, Button *, EMPTYARG )
874 {
875 	bDel = sal_True;
876 	InsertUpdate();
877 	bDel = sal_False;
878 
879 	if(pTOXMgr->GetCurTOXMark())
880 		UpdateDialog();
881 	else
882 	{
883 		CloseHdl(&aCancelBT);
884 		SfxViewFrame::Current()->GetBindings().Invalidate(FN_EDIT_IDX_ENTRY_DLG);
885 	}
886 	return 0;
887 }
888 
889 /*--------------------------------------------------------------------
890 	 Beschreibung: Dialoganzeige erneuern
891  --------------------------------------------------------------------*/
892 
893 
894 void SwIndexMarkDlg::UpdateDialog()
895 {
896 	DBG_ASSERT(pSh && pTOXMgr, "Shell nicht da?");
897 	SwTOXMark* pMark = pTOXMgr->GetCurTOXMark();
898 	ASSERT(pMark, "Keine aktuelle Markierung");
899 	if(!pMark)
900 		return;
901 
902 	ViewShell::SetCareWin( GetParent() );
903 
904 	aOrgStr = pMark->GetText();
905 	aEntryED.SetText(aOrgStr);
906 
907 	// Verzeichnistyp setzen
908 	sal_Bool bLevelEnable = sal_True,
909 		 bKeyEnable   = sal_False,
910 		 bKey2Enable  = sal_False,
911 		 bEntryHasText	= sal_False,
912 		 bKey1HasText	= sal_False,
913 		 bKey2HasText	= sal_False;
914 
915 	TOXTypes eCurType = pMark->GetTOXType()->GetType();
916 	if(TOX_INDEX == eCurType)
917 	{
918 		bLevelEnable = sal_False;
919 		bKeyEnable = sal_True;
920 		bKey1HasText = bKey2Enable = 0 != pMark->GetPrimaryKey().Len();
921 		bKey2HasText = 0 != pMark->GetSecondaryKey().Len();
922 		bEntryHasText = 0 != pMark->GetText().Len();
923 		aKeyDCB.SetText( pMark->GetPrimaryKey() );
924 		aKey2DCB.SetText( pMark->GetSecondaryKey() );
925 		aPhoneticED0.SetText( pMark->GetTextReading() );
926 		aPhoneticED1.SetText( pMark->GetPrimaryKeyReading() );
927 		aPhoneticED2.SetText( pMark->GetSecondaryKeyReading() );
928 		aMainEntryCB.Check(pMark->IsMainEntry());
929 	}
930 	else if(TOX_CONTENT == eCurType || TOX_USER == eCurType)
931 	{
932 		aLevelED.SetValue(aLevelED.Normalize(pMark->GetLevel()));
933 	}
934 	aKeyFT.Enable(bKeyEnable);
935 	aKeyDCB.Enable(bKeyEnable);
936 	aLevelED.SetMax(MAXLEVEL);
937 	aLevelFT.Show(bLevelEnable);
938 	aLevelED.Show(bLevelEnable);
939 	aMainEntryCB.Show(!bLevelEnable);
940 	aKey2FT.Enable(bKey2Enable);
941 	aKey2DCB.Enable(bKey2Enable);
942 
943 	UpdateLanguageDependenciesForPhoneticReading();
944 	aPhoneticFT0.Enable(bKeyEnable&&bEntryHasText&&bIsPhoneticReadingEnabled);
945 	aPhoneticED0.Enable(bKeyEnable&&bEntryHasText&&bIsPhoneticReadingEnabled);
946 	aPhoneticFT1.Enable(bKeyEnable&&bKey1HasText&&bIsPhoneticReadingEnabled);
947 	aPhoneticED1.Enable(bKeyEnable&&bKey1HasText&&bIsPhoneticReadingEnabled);
948 	aPhoneticFT2.Enable(bKeyEnable&&bKey2HasText&&bIsPhoneticReadingEnabled);
949 	aPhoneticED2.Enable(bKeyEnable&&bKey2HasText&&bIsPhoneticReadingEnabled);
950 
951 	// Verzeichnis-Typ setzen
952 	aTypeDCB.SelectEntry(pMark->GetTOXType()->GetTypeName());
953 
954 	// Next - Prev - Buttons setzen
955 	pSh->SttCrsrMove();
956 	if( aPrevBT.IsVisible() )
957 	{
958 		const SwTOXMark* pMoveMark = &pSh->GotoTOXMark( *pMark, TOX_PRV );
959 		if( pMoveMark != pMark )
960 			pSh->GotoTOXMark( *pMoveMark, TOX_NXT );
961 		aPrevBT.Enable( pMoveMark != pMark );
962 		pMoveMark = &pSh->GotoTOXMark( *pMark, TOX_NXT );
963 		if( pMoveMark != pMark )
964 			pSh->GotoTOXMark( *pMoveMark, TOX_PRV );
965 		aNextBT.Enable( pMoveMark != pMark );
966 	}
967 
968 	if( aPrevSameBT.IsVisible() )
969 	{
970 		const SwTOXMark* pMoveMark = &pSh->GotoTOXMark( *pMark, TOX_SAME_PRV );
971 		if( pMoveMark != pMark )
972 			pSh->GotoTOXMark( *pMoveMark, TOX_SAME_NXT );
973 		aPrevSameBT.Enable( pMoveMark != pMark );
974 		pMoveMark = &pSh->GotoTOXMark( *pMark, TOX_SAME_NXT );
975 		if( pMoveMark != pMark )
976 			pSh->GotoTOXMark( *pMoveMark, TOX_SAME_PRV );
977 		aNextSameBT.Enable( pMoveMark != pMark );
978 	}
979 
980 	sal_Bool bEnable = !pSh->HasReadonlySel();
981 	aOKBT.Enable( bEnable );
982 	aDelBT.Enable( bEnable );
983 	aEntryED.SetReadOnly( !bEnable );
984 	aLevelED.SetReadOnly( !bEnable );
985 	aKeyDCB.SetReadOnly( !bEnable );
986 	aKey2DCB.SetReadOnly( !bEnable );
987 
988 	pSh->SelectTxtAttr( RES_TXTATR_TOXMARK, pMark->GetTxtTOXMark() );
989 	// we need the point at the start of the attribut
990 	pSh->SwapPam();
991 
992 	pSh->EndCrsrMove();
993 }
994 
995 /*--------------------------------------------------------------------
996 	 Remind wether the edit boxes for Phonetic reading are changed manually
997  --------------------------------------------------------------------*/
998 
999 IMPL_LINK( SwIndexMarkDlg, PhoneticEDModifyHdl, Edit *, pEdit )
1000 {
1001 	if(&aPhoneticED0 == pEdit)
1002 	{
1003 		bPhoneticED0_ChangedByUser = pEdit->GetText().Len()>0;
1004 	}
1005 	else if(&aPhoneticED1 == pEdit)
1006 	{
1007 		bPhoneticED1_ChangedByUser = pEdit->GetText().Len()>0;
1008 	}
1009 	else if(&aPhoneticED2 == pEdit)
1010 	{
1011 		bPhoneticED2_ChangedByUser = pEdit->GetText().Len()>0;
1012 	}
1013 	return 0;
1014 }
1015 
1016 /*--------------------------------------------------------------------
1017 	 Beschreibung: Enable Disable des 2. Schluessels
1018  --------------------------------------------------------------------*/
1019 
1020 IMPL_LINK( SwIndexMarkDlg, KeyDCBModifyHdl, ComboBox *, pBox )
1021 {
1022 	if(&aKeyDCB == pBox)
1023 	{
1024 		sal_Bool bEnable = pBox->GetText().Len() > 0;
1025 		if(!bEnable)
1026 		{
1027 			aKey2DCB.SetText(aEmptyStr);
1028 			aPhoneticED1.SetText(aEmptyStr);
1029 			aPhoneticED2.SetText(aEmptyStr);
1030 			bPhoneticED1_ChangedByUser = sal_False;
1031 			bPhoneticED2_ChangedByUser = sal_False;
1032 		}
1033 		else
1034 		{
1035 			if(pBox->IsInDropDown())
1036 			{
1037 				//reset bPhoneticED1_ChangedByUser if a completly new string is selected
1038 				bPhoneticED1_ChangedByUser = sal_False;
1039 			}
1040 			if(!bPhoneticED1_ChangedByUser)
1041 				aPhoneticED1.SetText(GetDefaultPhoneticReading(pBox->GetText()));
1042 		}
1043 		aKey2DCB.Enable(bEnable);
1044 		aKey2FT.Enable(bEnable);
1045 	}
1046 	else if(&aKey2DCB == pBox)
1047 	{
1048 		if(!(pBox->GetText().Len()>0))
1049 		{
1050 			aPhoneticED2.SetText(aEmptyStr);
1051 			bPhoneticED2_ChangedByUser = sal_False;
1052 		}
1053 		else
1054 		{
1055 			if(pBox->IsInDropDown())
1056 			{
1057 				//reset bPhoneticED1_ChangedByUser if a completly new string is selected
1058 				bPhoneticED2_ChangedByUser = sal_False;
1059 			}
1060 			if(!bPhoneticED2_ChangedByUser)
1061 				aPhoneticED2.SetText(GetDefaultPhoneticReading(pBox->GetText()));
1062 		}
1063 	}
1064 	sal_Bool	bKey1HasText	= (0 != aKeyDCB.GetText().Len());
1065 	sal_Bool	bKey2HasText	= (0 != aKey2DCB.GetText().Len());
1066 
1067 	aPhoneticFT1.Enable(bKey1HasText&&bIsPhoneticReadingEnabled);
1068 	aPhoneticED1.Enable(bKey1HasText&bIsPhoneticReadingEnabled);
1069 	aPhoneticFT2.Enable(bKey2HasText&bIsPhoneticReadingEnabled);
1070 	aPhoneticED2.Enable(bKey2HasText&bIsPhoneticReadingEnabled);
1071 
1072 	return 0;
1073 }
1074 
1075 /*-----------------25.02.94 21:19-------------------
1076  dtor ueberladen
1077 --------------------------------------------------*/
1078 
1079 
1080 SwIndexMarkDlg::~SwIndexMarkDlg()
1081 {
1082 	delete pTOXMgr;
1083 	ViewShell::SetCareWin( 0 );
1084 }
1085 /* -----------------07.09.99 08:41-------------------
1086 
1087  --------------------------------------------------*/
1088 void    SwIndexMarkDlg::ReInitDlg(SwWrtShell& rWrtShell, SwTOXMark* pCurTOXMark)
1089 {
1090 	pSh = &rWrtShell;
1091 	delete pTOXMgr;
1092 	pTOXMgr = new SwTOXMgr(pSh);
1093     if(pCurTOXMark)
1094     {
1095         for(sal_uInt16 i = 0; i < pTOXMgr->GetTOXMarkCount(); i++)
1096             if(pTOXMgr->GetTOXMark(i) == pCurTOXMark)
1097             {
1098                 pTOXMgr->SetCurTOXMark(i);
1099                 break;
1100             }
1101     }
1102     InitControls();
1103 }
1104 /* -----------------06.10.99 10:00-------------------
1105 
1106  --------------------------------------------------*/
1107 SwIndexMarkFloatDlg::SwIndexMarkFloatDlg(SfxBindings* _pBindings,
1108 				   				SfxChildWindow* pChild,
1109 				   				Window *pParent,
1110 								SfxChildWinInfo* pInfo,
1111 				   				sal_Bool bNew) :
1112 SfxModelessDialog(_pBindings, pChild, pParent, SvtCJKOptions().IsCJKFontEnabled()?SW_RES(DLG_INSIDXMARK_CJK):SW_RES(DLG_INSIDXMARK)),
1113     aDlg(this, bNew, SW_RES(WIN_DLG), SvtCJKOptions().IsCJKFontEnabled()?DLG_INSIDXMARK_CJK:DLG_INSIDXMARK, *::GetActiveWrtShell())
1114 {
1115 	FreeResource();
1116     aDlg.ReInitDlg(*::GetActiveWrtShell());
1117 	Initialize(pInfo);
1118 }
1119 /* -----------------06.10.99 10:27-------------------
1120 
1121  --------------------------------------------------*/
1122 void	SwIndexMarkFloatDlg::Activate()
1123 {
1124 	SfxModelessDialog::Activate();
1125 	aDlg.Activate();
1126 }
1127 
1128 void SwIndexMarkFloatDlg::ReInitDlg(SwWrtShell& rWrtShell)
1129 {
1130 	aDlg.ReInitDlg( rWrtShell );
1131 }
1132 
1133 /* -----------------06.10.99 10:35-------------------
1134 
1135  --------------------------------------------------*/
1136 SwIndexMarkModalDlg::SwIndexMarkModalDlg(Window *pParent, SwWrtShell& rSh, SwTOXMark* pCurTOXMark) :
1137 SvxStandardDialog(pParent, SvtCJKOptions().IsCJKFontEnabled()?SW_RES(DLG_EDIT_IDXMARK_CJK):SW_RES(DLG_EDIT_IDXMARK)),
1138     aDlg(this, sal_False, SW_RES(WIN_DLG), SvtCJKOptions().IsCJKFontEnabled()?DLG_EDIT_IDXMARK_CJK:DLG_EDIT_IDXMARK, rSh)
1139 {
1140 	FreeResource();
1141     aDlg.ReInitDlg(rSh, pCurTOXMark);
1142 }
1143 /* -----------------06.10.99 10:46-------------------
1144 
1145  --------------------------------------------------*/
1146 void	SwIndexMarkModalDlg::Apply()
1147 {
1148 	aDlg.Apply();
1149 }
1150 /* -----------------16.09.99 14:19-------------------
1151 
1152  --------------------------------------------------*/
1153 class SwCreateAuthEntryDlg_Impl : public ModalDialog
1154 {
1155     FixedLine       aEntriesFL;
1156 
1157 	FixedText*		pFixedTexts[AUTH_FIELD_END];
1158 	ListBox*		pTypeListBox;
1159 	ComboBox*		pIdentifierBox;
1160 	Edit*			pEdits[AUTH_FIELD_END];
1161 
1162     OKButton        aOKBT;
1163 	CancelButton 	aCancelBT;
1164 	HelpButton 		aHelpBT;
1165 
1166 	Link			aShortNameCheckLink;
1167 
1168 	SwWrtShell& 	rWrtSh;
1169 
1170 	sal_Bool			m_bNewEntryMode;
1171 	sal_Bool			m_bNameAllowed;
1172 
1173 	DECL_LINK(IdentifierHdl, ComboBox*);
1174 	DECL_LINK(ShortNameHdl, Edit*);
1175 	DECL_LINK(EnableHdl, ListBox* pBox);
1176 
1177 public:
1178 	SwCreateAuthEntryDlg_Impl(Window* pParent,
1179 							const String pFields[],
1180 							SwWrtShell& rSh,
1181 							sal_Bool bNewEntry,
1182 							sal_Bool bCreate);
1183 	~SwCreateAuthEntryDlg_Impl();
1184 
1185 	String			GetEntryText(ToxAuthorityField eField) const;
1186 
1187 	void			SetCheckNameHdl(const Link& rLink) {aShortNameCheckLink = rLink;}
1188 
1189 };
1190 /*-- 15.09.99 08:43:24---------------------------------------------------
1191 
1192   -----------------------------------------------------------------------*/
1193 struct TextInfo
1194 {
1195 	sal_uInt16 nToxField;
1196 	const char* pHelpId;
1197 };
1198 
1199 static const TextInfo aTextInfoArr[] =
1200 {
1201 	{AUTH_FIELD_IDENTIFIER,      HID_AUTH_FIELD_IDENTIFIER      },
1202 	{AUTH_FIELD_AUTHORITY_TYPE,  HID_AUTH_FIELD_AUTHORITY_TYPE  },
1203 	{AUTH_FIELD_AUTHOR,          HID_AUTH_FIELD_AUTHOR          },
1204 	{AUTH_FIELD_TITLE,           HID_AUTH_FIELD_TITLE           },
1205 	{AUTH_FIELD_YEAR,            HID_AUTH_FIELD_YEAR            },
1206 	{AUTH_FIELD_PUBLISHER,       HID_AUTH_FIELD_PUBLISHER       },
1207 	{AUTH_FIELD_ADDRESS,         HID_AUTH_FIELD_ADDRESS         },
1208 	{AUTH_FIELD_ISBN,            HID_AUTH_FIELD_ISBN            },
1209 	{AUTH_FIELD_CHAPTER,         HID_AUTH_FIELD_CHAPTER         },
1210 	{AUTH_FIELD_PAGES,           HID_AUTH_FIELD_PAGES           },
1211 	{AUTH_FIELD_EDITOR,          HID_AUTH_FIELD_EDITOR          },
1212 	{AUTH_FIELD_EDITION,         HID_AUTH_FIELD_EDITION         },
1213 	{AUTH_FIELD_BOOKTITLE,       HID_AUTH_FIELD_BOOKTITLE       },
1214 	{AUTH_FIELD_VOLUME,          HID_AUTH_FIELD_VOLUME          },
1215 	{AUTH_FIELD_HOWPUBLISHED,    HID_AUTH_FIELD_HOWPUBLISHED    },
1216 	{AUTH_FIELD_ORGANIZATIONS,   HID_AUTH_FIELD_ORGANIZATIONS   },
1217 	{AUTH_FIELD_INSTITUTION,     HID_AUTH_FIELD_INSTITUTION     },
1218 	{AUTH_FIELD_SCHOOL,          HID_AUTH_FIELD_SCHOOL          },
1219 	{AUTH_FIELD_REPORT_TYPE,     HID_AUTH_FIELD_REPORT_TYPE     },
1220 	{AUTH_FIELD_MONTH,           HID_AUTH_FIELD_MONTH           },
1221 	{AUTH_FIELD_JOURNAL,         HID_AUTH_FIELD_JOURNAL         },
1222 	{AUTH_FIELD_NUMBER,          HID_AUTH_FIELD_NUMBER          },
1223 	{AUTH_FIELD_SERIES,          HID_AUTH_FIELD_SERIES          },
1224 	{AUTH_FIELD_ANNOTE,          HID_AUTH_FIELD_ANNOTE          },
1225 	{AUTH_FIELD_NOTE,            HID_AUTH_FIELD_NOTE            },
1226 	{AUTH_FIELD_URL,             HID_AUTH_FIELD_URL             },
1227 	{AUTH_FIELD_CUSTOM1,         HID_AUTH_FIELD_CUSTOM1         },
1228 	{AUTH_FIELD_CUSTOM2,         HID_AUTH_FIELD_CUSTOM2         },
1229 	{AUTH_FIELD_CUSTOM3,         HID_AUTH_FIELD_CUSTOM3         },
1230 	{AUTH_FIELD_CUSTOM4,         HID_AUTH_FIELD_CUSTOM4         },
1231 	{AUTH_FIELD_CUSTOM5,         HID_AUTH_FIELD_CUSTOM5         }
1232 };
1233 
1234 sal_Bool SwAuthMarkDlg::bIsFromComponent = sal_True;
1235 
1236 SwAuthMarkDlg::SwAuthMarkDlg(  Window *pParent,
1237 							   const ResId& rResId,
1238 							   sal_Bool bNewDlg) :
1239 	Window(pParent, rResId),
1240     aFromComponentRB(   this, ResId(RB_FROMCOMPONENT, *rResId.GetResMgr()   )),
1241     aFromDocContentRB(  this, ResId(RB_FROMDOCCONTENT, *rResId.GetResMgr()  )),
1242 
1243     aAuthorFT(  this, ResId(FT_AUTHOR, *rResId.GetResMgr()       )),
1244     aAuthorFI(  this, ResId(FI_AUTHOR, *rResId.GetResMgr()   )),
1245     aTitleFT(   this, ResId(FT_TITLE, *rResId.GetResMgr()    )),
1246     aTitleFI(   this, ResId(FI_TITLE, *rResId.GetResMgr()    )),
1247     aEntryFT(   this, ResId(FT_ENTRY, *rResId.GetResMgr()    )),
1248     aEntryED(   this, ResId(ED_ENTRY, *rResId.GetResMgr()   )),
1249     aEntryLB(   this, ResId(LB_ENTRY, *rResId.GetResMgr()   )),
1250 
1251     aEntryFL(   this, ResId(FL_ENTRY, *rResId.GetResMgr()    )),
1252 
1253     aOKBT(      this, ResId(PB_OK, *rResId.GetResMgr()       )),
1254     aCancelBT(  this, ResId(PB_CANCEL, *rResId.GetResMgr()  )),
1255     aHelpBT(    this, ResId(PB_HELP, *rResId.GetResMgr()    )),
1256     aCreateEntryPB(this,ResId(PB_CREATEENTRY, *rResId.GetResMgr())),
1257     aEditEntryPB(this,  ResId(PB_EDITENTRY, *rResId.GetResMgr())),
1258 
1259     sChangeST(  ResId(ST_CHANGE, *rResId.GetResMgr())),
1260     bNewEntry(bNewDlg),
1261     bBibAccessInitialized(sal_False),
1262 
1263     pSh(0)
1264 {
1265 	SetStyle(GetStyle()|WB_DIALOGCONTROL);
1266 	FreeResource();
1267 
1268 	aFromComponentRB.SetHelpId(HID_AUTH_MARK_DLG_FROM_COMP_RB);
1269 	aFromDocContentRB.SetHelpId(HID_AUTH_MARK_DLG_FROM_DOC_RB );
1270 	aEntryED.SetHelpId(HID_AUTH_MARK_DLG_ID_LISTBOX           );
1271 	aEntryLB.SetHelpId(HID_AUTH_MARK_DLG_ID_LISTBOX           );
1272 
1273 	aFromComponentRB.Show(bNewEntry);
1274 	aFromDocContentRB.Show(bNewEntry);
1275 	aFromComponentRB.Check(bIsFromComponent);
1276 	aFromDocContentRB.Check(!bIsFromComponent);
1277 
1278 	aOKBT		.SetHelpId(HID_INSERT_AUTH_MRK_OK   );
1279 	aCancelBT	.SetHelpId(HID_INSERT_AUTH_MRK_CLOSE);
1280 	aEntryED		.SetHelpId(HID_INSERT_AUTH_MRK_ENTRY		);
1281 	aCreateEntryPB  .SetHelpId(HID_INSERT_AUTH_MRK_CREATE_ENTRY	);
1282 	aEditEntryPB    .SetHelpId(HID_INSERT_AUTH_MRK_EDIT_ENTRY	);
1283 
1284 	aOKBT.SetClickHdl(LINK(this,SwAuthMarkDlg, InsertHdl));
1285 	aCancelBT.SetClickHdl(LINK(this,SwAuthMarkDlg, CloseHdl));
1286 	aCreateEntryPB.SetClickHdl(LINK(this,SwAuthMarkDlg, CreateEntryHdl));
1287 	aEditEntryPB.SetClickHdl(LINK(this,SwAuthMarkDlg, CreateEntryHdl));
1288 	aFromComponentRB.SetClickHdl(LINK(this,SwAuthMarkDlg, ChangeSourceHdl));
1289 	aFromDocContentRB.SetClickHdl(LINK(this,SwAuthMarkDlg, ChangeSourceHdl));
1290     aEntryED.SetModifyHdl(LINK(this,SwAuthMarkDlg, EditModifyHdl));
1291 
1292 	GetParent()->SetText(String(SW_RES(
1293 					bNewEntry ? STR_AUTHMRK_INSERT : STR_AUTHMRK_EDIT)));
1294 	aEntryED.Show(!bNewEntry);
1295 	aEntryLB.Show(bNewEntry);
1296 	if(!bNewEntry)
1297 	{
1298 		aOKBT.SetText(sChangeST);
1299 	}
1300 	else
1301 	{
1302 		aEntryLB.SetSelectHdl(LINK(this, SwAuthMarkDlg, CompEntryHdl));
1303 	}
1304 }
1305 /*-- 15.09.99 08:43:25---------------------------------------------------
1306 
1307   -----------------------------------------------------------------------*/
1308 SwAuthMarkDlg::~SwAuthMarkDlg()
1309 {
1310 }
1311 /*-- 15.09.99 08:43:25---------------------------------------------------
1312 
1313   -----------------------------------------------------------------------*/
1314 void	SwAuthMarkDlg::ReInitDlg(SwWrtShell& rWrtShell)
1315 {
1316 	pSh = &rWrtShell;
1317 	InitControls();
1318 }
1319 /* -----------------15.09.99 08:57-------------------
1320 
1321  --------------------------------------------------*/
1322 IMPL_LINK( SwAuthMarkDlg, CloseHdl, PushButton *, EMPTYARG )
1323 {
1324 	if(bNewEntry)
1325 	{
1326 		sal_uInt16 nSlot = FN_INSERT_AUTH_ENTRY_DLG;
1327 		SfxViewFrame::Current()->GetDispatcher()->Execute(nSlot,
1328 					SFX_CALLMODE_ASYNCHRON|SFX_CALLMODE_RECORD);
1329 	}
1330 	else
1331 	{
1332 		((SwAuthMarkModalDlg*)GetParent())->EndDialog(RET_CANCEL);
1333 	}
1334 	return 0;
1335 }
1336 /* -----------------06.12.99 13:54-------------------
1337 
1338  --------------------------------------------------*/
1339 static String lcl_FindColumnEntry(const beans::PropertyValue* pFields, sal_Int32 nLen, const String& rColumnTitle)
1340 {
1341 	String sRet;
1342 	OUString uColumnTitle = rColumnTitle;
1343     for(sal_uInt16 i = 0; i < nLen; i++)
1344 	{
1345         OUString uTmp;
1346         if(pFields[i].Name == uColumnTitle &&
1347             (pFields[i].Value >>= uTmp))
1348 		{
1349 			sRet = String(uTmp);
1350 			break;
1351 		}
1352 	}
1353 	return sRet;
1354 }
1355 /* -----------------------------07.12.99 15:39--------------------------------
1356 
1357  ---------------------------------------------------------------------------*/
1358 IMPL_LINK( SwAuthMarkDlg, CompEntryHdl, ListBox*, pBox)
1359 {
1360 	String sEntry(pBox->GetSelectEntry());
1361 	if(bIsFromComponent)
1362 	{
1363 		if(xBibAccess.is() && sEntry.Len())
1364 		{
1365 			OUString uEntry(sEntry);
1366 			if(xBibAccess->hasByName(uEntry))
1367 			{
1368 				uno::Any aEntry(xBibAccess->getByName(uEntry));
1369                 uno::Sequence<beans::PropertyValue> aFieldProps;
1370                 if(aEntry >>= aFieldProps)
1371 				{
1372 					const beans::PropertyValue* pProps = aFieldProps.getConstArray();
1373                     for(sal_uInt16 i = 0; i < AUTH_FIELD_END && i < aFieldProps.getLength(); i++)
1374 					{
1375 						m_sFields[i] = lcl_FindColumnEntry(
1376 								pProps, aFieldProps.getLength(), m_sColumnTitles[i]);
1377 					}
1378 				}
1379 			}
1380 		}
1381 	}
1382 	else
1383 	{
1384 		if(sEntry.Len())
1385 		{
1386 			const SwAuthorityFieldType* pFType = (const SwAuthorityFieldType*)
1387 										pSh->GetFldType(RES_AUTHORITY, aEmptyStr);
1388 			const SwAuthEntry* 	pEntry = pFType ? pFType->GetEntryByIdentifier(sEntry) : 0;
1389 			for(sal_uInt16 i = 0; i < AUTH_FIELD_END; i++)
1390 				m_sFields[i] = pEntry ?
1391 							pEntry->GetAuthorField((ToxAuthorityField)i) : aEmptyStr;
1392 		}
1393 	}
1394 	if(!pBox->GetSelectEntry().Len())
1395 	{
1396 		for(sal_uInt16 i = 0; i < AUTH_FIELD_END; i++)
1397 			m_sFields[i] = aEmptyStr;
1398 	}
1399 	aAuthorFI.SetText(m_sFields[AUTH_FIELD_AUTHOR]);
1400 	aTitleFI.SetText(m_sFields[AUTH_FIELD_TITLE]);
1401 	return 0;
1402 }
1403 
1404 /* -----------------15.09.99 08:57-------------------
1405 
1406  --------------------------------------------------*/
1407 IMPL_LINK( SwAuthMarkDlg, InsertHdl, PushButton *, EMPTYARG )
1408 {
1409 	//insert or update the SwAuthorityField...
1410 	if(pSh)
1411 	{
1412 		sal_Bool bDifferent = sal_False;
1413 		DBG_ASSERT(m_sFields[AUTH_FIELD_IDENTIFIER].Len() , "No Id is set!");
1414 		DBG_ASSERT(m_sFields[AUTH_FIELD_AUTHORITY_TYPE].Len() , "No authority type is set!");
1415 		//check if the entry already exists with different content
1416 		const SwAuthorityFieldType* pFType = (const SwAuthorityFieldType*)
1417 										pSh->GetFldType(RES_AUTHORITY, aEmptyStr);
1418 		const SwAuthEntry* 	pEntry = pFType ?
1419 				pFType->GetEntryByIdentifier( m_sFields[AUTH_FIELD_IDENTIFIER])
1420 				: 0;
1421 		if(pEntry)
1422 		{
1423 			for(sal_uInt16 i = 0; i < AUTH_FIELD_END && !bDifferent; i++)
1424 				bDifferent |= m_sFields[i] != pEntry->GetAuthorField((ToxAuthorityField)i);
1425 			if(bDifferent)
1426 			{
1427 				QueryBox aQuery(this, SW_RES(DLG_CHANGE_AUTH_ENTRY));
1428 				if(RET_YES != aQuery.Execute())
1429 					return 0;
1430 			}
1431 		}
1432 
1433 		SwFldMgr aMgr(pSh);
1434 		String sFields;
1435 		for(sal_uInt16 i = 0; i < AUTH_FIELD_END; i++)
1436 		{
1437 			sFields += m_sFields[i];
1438 			sFields += TOX_STYLE_DELIMITER;
1439 		}
1440 		if(bNewEntry)
1441 		{
1442 			if(bDifferent)
1443 			{
1444 				SwAuthEntry aNewData;
1445 				for(sal_uInt16 i = 0; i < AUTH_FIELD_END; i++)
1446 					aNewData.SetAuthorField((ToxAuthorityField)i, m_sFields[i]);
1447 				pSh->ChangeAuthorityData(&aNewData);
1448 			}
1449             SwInsertFld_Data aData(TYP_AUTHORITY, 0, sFields, aEmptyStr, 0 );
1450             aMgr.InsertFld( aData );
1451 		}
1452 		else if(aMgr.GetCurFld())
1453 		{
1454 			aMgr.UpdateCurFld(0, sFields, aEmptyStr);
1455 		}
1456 	}
1457 	if(!bNewEntry)
1458 		CloseHdl(0);
1459 	return 0;
1460 }
1461 /* -----------------17.09.99 13:06-------------------
1462 
1463  --------------------------------------------------*/
1464 IMPL_LINK(SwAuthMarkDlg, CreateEntryHdl, PushButton*, pButton)
1465 {
1466 	sal_Bool bCreate = pButton == &aCreateEntryPB;
1467 	String sOldId = m_sCreatedEntry[0];
1468 	for(sal_uInt16 i = 0; i < AUTH_FIELD_END; i++)
1469 		m_sCreatedEntry[i] = bCreate ? aEmptyStr : m_sFields[i];
1470 	SwCreateAuthEntryDlg_Impl aDlg(pButton,
1471 				bCreate ? m_sCreatedEntry : m_sFields,
1472 				*pSh, bNewEntry, bCreate);
1473 	if(bNewEntry)
1474 	{
1475 		aDlg.SetCheckNameHdl(LINK(this, SwAuthMarkDlg, IsEntryAllowedHdl));
1476 	}
1477 	if(RET_OK == aDlg.Execute())
1478 	{
1479 		if(bCreate && sOldId.Len())
1480 		{
1481 			aEntryLB.RemoveEntry(sOldId);
1482 		}
1483 		for(sal_uInt16 i = 0; i < AUTH_FIELD_END; i++)
1484 		{
1485 			m_sFields[i] = aDlg.GetEntryText((ToxAuthorityField)i);
1486 			m_sCreatedEntry[i] = m_sFields[i];
1487 		}
1488 		if(bNewEntry && !aFromDocContentRB.IsChecked())
1489 		{
1490 			aFromDocContentRB.Check(sal_True);
1491 			ChangeSourceHdl(&aFromDocContentRB);
1492 		}
1493 		if(bCreate)
1494 		{
1495 			DBG_ASSERT(LISTBOX_ENTRY_NOTFOUND ==
1496 						aEntryLB.GetEntryPos(m_sFields[AUTH_FIELD_IDENTIFIER]),
1497 						"entry exists!");
1498 			aEntryLB.InsertEntry(m_sFields[AUTH_FIELD_IDENTIFIER]);
1499 			aEntryLB.SelectEntry(m_sFields[AUTH_FIELD_IDENTIFIER]);
1500 		}
1501 		aEntryED.SetText(m_sFields[AUTH_FIELD_IDENTIFIER]);
1502 		aAuthorFI.SetText(m_sFields[AUTH_FIELD_AUTHOR]);
1503 		aTitleFI.SetText(m_sFields[AUTH_FIELD_TITLE]);
1504         aOKBT.Enable();
1505 	}
1506 	return 0;
1507 }
1508 /* -----------------------------20.12.99 14:26--------------------------------
1509 
1510  ---------------------------------------------------------------------------*/
1511 IMPL_LINK(SwAuthMarkDlg, ChangeSourceHdl, RadioButton*, pButton)
1512 {
1513 	sal_Bool bFromComp = (pButton == &aFromComponentRB);
1514 	bIsFromComponent = bFromComp;
1515 	aCreateEntryPB.Enable(!bIsFromComponent);
1516 	aEntryLB.Clear();
1517 	if(bIsFromComponent)
1518 	{
1519 		if(!bBibAccessInitialized)
1520 		{
1521  			uno::Reference< lang::XMultiServiceFactory > xMSF = getProcessServiceFactory();
1522 			xBibAccess = uno::Reference< container::XNameAccess > (
1523 							xMSF->createInstance( C2U("com.sun.star.frame.Bibliography") ),
1524 																		uno::UNO_QUERY );
1525 			uno::Reference< beans::XPropertySet >  xPropSet(xBibAccess, uno::UNO_QUERY);
1526 			OUString uPropName(C2U("BibliographyDataFieldNames"));
1527 			if(xPropSet.is() && xPropSet->getPropertySetInfo()->hasPropertyByName(uPropName))
1528 			{
1529 				uno::Any aNames = xPropSet->getPropertyValue(uPropName);
1530                 uno::Sequence<beans::PropertyValue> aSeq;
1531                 if( aNames >>= aSeq)
1532 				{
1533                     const beans::PropertyValue* pArr = aSeq.getConstArray();
1534 					for(sal_uInt16 i = 0; i < aSeq.getLength(); i++)
1535 					{
1536 						String sTitle = pArr[i].Name;
1537 						sal_Int16 nField = 0;
1538 						pArr[i].Value >>= nField;
1539 						if(nField >= 0 && nField < AUTH_FIELD_END)
1540 							m_sColumnTitles[nField] = sTitle;
1541 					}
1542 				}
1543 			}
1544 			bBibAccessInitialized = sal_True;
1545 		}
1546 		if(xBibAccess.is())
1547 		{
1548 			uno::Sequence<OUString> aIdentifiers = xBibAccess->getElementNames();
1549 			const OUString* pNames = aIdentifiers.getConstArray();
1550 			for(sal_uInt16 i = 0; i < aIdentifiers.getLength(); i++)
1551 			{
1552 				aEntryLB.InsertEntry(pNames[i]);
1553 			}
1554 		}
1555 	}
1556 	else
1557 	{
1558 		const SwAuthorityFieldType* pFType = (const SwAuthorityFieldType*)
1559 									pSh->GetFldType(RES_AUTHORITY, aEmptyStr);
1560 		if(pFType)
1561 		{
1562 			SvStringsDtor aIds;
1563 			pFType->GetAllEntryIdentifiers(	aIds );
1564 			for(sal_uInt16 n = 0; n < aIds.Count(); n++)
1565 				aEntryLB.InsertEntry(*aIds.GetObject(n));
1566 		}
1567 		if(m_sCreatedEntry[AUTH_FIELD_IDENTIFIER].Len())
1568 			aEntryLB.InsertEntry(m_sCreatedEntry[AUTH_FIELD_IDENTIFIER]);
1569 	}
1570 	aEntryLB.SelectEntryPos(0);
1571 	CompEntryHdl(&aEntryLB);
1572 	return 0;
1573 }
1574 /* -----------------15.10.2002 13:16-----------------
1575  *
1576  * --------------------------------------------------*/
1577 IMPL_LINK(SwAuthMarkDlg, EditModifyHdl, Edit*, pEdit)
1578 {
1579     Link aAllowed = LINK(this, SwAuthMarkDlg, IsEntryAllowedHdl);
1580     long nResult = aAllowed.Call(pEdit);
1581     aOKBT.Enable(nResult > 0);
1582     if(nResult)
1583     {
1584         String sEntry(pEdit->GetText());
1585         m_sFields[AUTH_FIELD_IDENTIFIER] = sEntry;
1586         m_sCreatedEntry[AUTH_FIELD_IDENTIFIER] = sEntry;
1587     }
1588     return 0;
1589 };
1590 /* -----------------------------20.12.99 15:11--------------------------------
1591 
1592  ---------------------------------------------------------------------------*/
1593 IMPL_LINK(SwAuthMarkDlg, IsEntryAllowedHdl, Edit*, pEdit)
1594 {
1595 	String sEntry = pEdit->GetText();
1596 	sal_Bool bAllowed = sal_False;
1597 	if(sEntry.Len())
1598 	{
1599 		if(aEntryLB.GetEntryPos(sEntry) != LISTBOX_ENTRY_NOTFOUND)
1600 			return 0;
1601 		else if(bIsFromComponent)
1602 		{
1603 			const SwAuthorityFieldType* pFType = (const SwAuthorityFieldType*)
1604 										pSh->GetFldType(RES_AUTHORITY, aEmptyStr);
1605 			bAllowed = !pFType || !pFType->GetEntryByIdentifier(sEntry);
1606 		}
1607 		else
1608 		{
1609 			bAllowed = !xBibAccess.is() || !xBibAccess->hasByName(sEntry);
1610 		}
1611 	}
1612 	return bAllowed;
1613 }
1614 /* -----------------21.09.99 14:19-------------------
1615 
1616  --------------------------------------------------*/
1617 void SwAuthMarkDlg::InitControls()
1618 {
1619 	DBG_ASSERT(pSh, "Shell nicht da?");
1620 	SwField* pField = pSh->GetCurFld();
1621 	ASSERT(bNewEntry || pField, "Keine aktuelle Markierung");
1622 	if(bNewEntry)
1623 	{
1624 		ChangeSourceHdl(aFromComponentRB.IsChecked() ? &aFromComponentRB : &aFromDocContentRB);
1625 		aCreateEntryPB.Enable(!aFromComponentRB.IsChecked());
1626 		if(!aFromComponentRB.IsChecked() && m_sCreatedEntry[0].Len())
1627 			for(sal_uInt16 i = 0; i < AUTH_FIELD_END; i++)
1628 				m_sFields[i] = m_sCreatedEntry[i];
1629 	}
1630 	if(bNewEntry || !pField || pField->GetTyp()->Which() != RES_AUTHORITY)
1631 		return;
1632 
1633 	const SwAuthEntry* pEntry = ((SwAuthorityFieldType*)pField->GetTyp())->
1634             GetEntryByHandle(((SwAuthorityField*)pField)->GetHandle());
1635 
1636 	DBG_ASSERT(pEntry, "No authority entry found");
1637 	if(!pEntry)
1638 		return;
1639 	for(sal_uInt16 i = 0; i < AUTH_FIELD_END; i++)
1640 		m_sFields[i] = pEntry->GetAuthorField((ToxAuthorityField)i);
1641 
1642 	aEntryED.SetText(pEntry->GetAuthorField(AUTH_FIELD_IDENTIFIER));
1643 	aAuthorFI.SetText(pEntry->GetAuthorField(AUTH_FIELD_AUTHOR));
1644 	aTitleFI.SetText(pEntry->GetAuthorField(AUTH_FIELD_TITLE));
1645 }
1646 /* -----------------------------05.09.2002 09:44------------------------------
1647 
1648  ---------------------------------------------------------------------------*/
1649 void    SwAuthMarkDlg::Activate()
1650 {
1651     aOKBT.Enable(!pSh->HasReadonlySel());
1652     Window::Activate();
1653 }
1654 /* -----------------16.09.99 14:27-------------------
1655 
1656  --------------------------------------------------*/
1657 SwCreateAuthEntryDlg_Impl::SwCreateAuthEntryDlg_Impl(Window* pParent,
1658 		const String pFields[],
1659 		SwWrtShell& rSh,
1660 		sal_Bool bNewEntry,
1661 		sal_Bool bCreate) :
1662 	ModalDialog(pParent, SW_RES(DLG_CREATE_AUTH_ENTRY)),
1663     aEntriesFL(this,    SW_RES(FL_ENTRIES    )),
1664     pTypeListBox(0),
1665     pIdentifierBox(0),
1666     aOKBT(this,         SW_RES(PB_OK         )),
1667     aCancelBT(this,     SW_RES(PB_CANCEL        )),
1668     aHelpBT(this,       SW_RES(PB_HELP      )),
1669     rWrtSh(rSh),
1670 	m_bNewEntryMode(bNewEntry),
1671 	m_bNameAllowed(sal_True)
1672 {
1673 	FreeResource();
1674     Point aFLPos(aEntriesFL.GetPosPixel());
1675     Point aTL1(aFLPos);
1676     Size aFLSz(aEntriesFL.GetSizePixel().Width(), GetSizePixel().Height());
1677     long nControlSpace = aFLSz.Width() / 4;
1678 	long nControlWidth = nControlSpace - 2 * aTL1.X();
1679 	aTL1.X() *= 2;
1680 	aTL1.Y() *= 5;
1681 	Point aTR1(aTL1);
1682 	aTR1.X() += nControlSpace;
1683 	Point aTL2(aTR1);
1684 	aTL2.X() += nControlSpace;
1685 	Point aTR2(aTL2);
1686 	aTR2.X() += nControlSpace;
1687     Size aFixedTextSize(aFLSz);
1688 	Size aTmpSz(8,10);
1689 	aTmpSz = LogicToPixel(aTmpSz, MAP_APPFONT);
1690 	aFixedTextSize.Height() = aTmpSz.Width();
1691 	Size aEditSize(aFixedTextSize);
1692     aFixedTextSize.Width() = nControlWidth + aFLPos.X();
1693 	aEditSize.Height() = aTmpSz.Height();
1694 	aEditSize.Width() = nControlWidth;
1695 
1696     sal_uInt16 nOffset = static_cast< sal_uInt16 >(aTmpSz.Width() * 3 / 2);
1697 	sal_Bool bLeft = sal_True;
1698     Window* pRefWindow = 0;
1699     for(sal_uInt16 nIndex = 0; nIndex < AUTH_FIELD_END; nIndex++)
1700 	{
1701 		const TextInfo aCurInfo = aTextInfoArr[nIndex];
1702 
1703 		pFixedTexts[nIndex] = new FixedText(this);
1704         if(nIndex)
1705             pFixedTexts[nIndex]->SetZOrder( pRefWindow, WINDOW_ZORDER_BEHIND );
1706         else
1707             pFixedTexts[nIndex]->SetZOrder( 0, WINDOW_ZORDER_FIRST );
1708 
1709         pRefWindow = pFixedTexts[nIndex];
1710 
1711 		pFixedTexts[nIndex]->SetSizePixel(aFixedTextSize);
1712 		pFixedTexts[nIndex]->SetPosPixel(bLeft ? aTL1 : aTL2);
1713 		pFixedTexts[nIndex]->SetText(SW_RES(STR_AUTH_FIELD_START + aCurInfo.nToxField));
1714 		pFixedTexts[nIndex]->Show();
1715 		pEdits[nIndex] = 0;
1716 		if( AUTH_FIELD_AUTHORITY_TYPE == aCurInfo.nToxField )
1717 		{
1718 			pTypeListBox = new ListBox(this, WB_DROPDOWN|WB_BORDER);
1719             pTypeListBox->SetZOrder( pRefWindow, WINDOW_ZORDER_BEHIND );
1720             pRefWindow = pTypeListBox;
1721 			for(sal_uInt16 j = 0; j < AUTH_TYPE_END; j++)
1722 				pTypeListBox->InsertEntry(String(SW_RES(STR_AUTH_TYPE_START + j)));
1723 			if(pFields[aCurInfo.nToxField].Len())
1724 			{
1725                 sal_uInt16 nIndexPos = static_cast< sal_uInt16 >(pFields[aCurInfo.nToxField].ToInt32());
1726 				pTypeListBox->SelectEntryPos(nIndexPos);
1727 			}
1728 			Size aTmp(aEditSize);
1729 			aTmp.Height() *= 4;
1730 			pTypeListBox->SetSizePixel(aTmp);
1731 			pTypeListBox->SetPosPixel(bLeft ? aTR1 : aTR2);
1732 			pTypeListBox->Show();
1733 			pTypeListBox->SetSelectHdl(LINK(this, SwCreateAuthEntryDlg_Impl, EnableHdl));
1734 			pTypeListBox->SetHelpId(aCurInfo.pHelpId);
1735 
1736 		}
1737 		else if(AUTH_FIELD_IDENTIFIER == aCurInfo.nToxField && !m_bNewEntryMode)
1738 		{
1739             pIdentifierBox = new ComboBox(this, WB_BORDER|WB_DROPDOWN);
1740             pIdentifierBox->SetZOrder( pRefWindow, WINDOW_ZORDER_BEHIND );
1741             pRefWindow = pIdentifierBox;
1742 
1743 			pIdentifierBox->SetSelectHdl(LINK(this,
1744 									SwCreateAuthEntryDlg_Impl, IdentifierHdl));
1745 
1746 
1747 			const SwAuthorityFieldType* pFType = (const SwAuthorityFieldType*)
1748 										rSh.GetFldType(RES_AUTHORITY, aEmptyStr);
1749 			if(pFType)
1750 			{
1751 				SvStringsDtor aIds;
1752 				pFType->GetAllEntryIdentifiers(	aIds );
1753 				for(sal_uInt16 n = 0; n < aIds.Count(); n++)
1754 					pIdentifierBox->InsertEntry(*aIds.GetObject(n));
1755 			}
1756 			pIdentifierBox->SetText(pFields[aCurInfo.nToxField]);
1757 			Size aTmp(aEditSize);
1758 			aTmp.Height() *= 4;
1759 			pIdentifierBox->SetSizePixel(aTmp);
1760 			pIdentifierBox->SetPosPixel(bLeft ? aTR1 : aTR2);
1761 			pIdentifierBox->Show();
1762 			pIdentifierBox->SetHelpId(aCurInfo.pHelpId);
1763 		}
1764 		else
1765 		{
1766 			pEdits[nIndex] = new Edit(this, WB_BORDER);
1767             pEdits[nIndex]->SetZOrder( pRefWindow, WINDOW_ZORDER_BEHIND );
1768             pRefWindow = pEdits[nIndex];
1769             pEdits[nIndex]->SetSizePixel(aEditSize);
1770 			pEdits[nIndex]->SetPosPixel(bLeft ? aTR1 : aTR2);
1771 			pEdits[nIndex]->SetText(pFields[aCurInfo.nToxField]);
1772 			pEdits[nIndex]->Show();
1773 			pEdits[nIndex]->SetHelpId(aCurInfo.pHelpId);
1774 			if(AUTH_FIELD_IDENTIFIER == aCurInfo.nToxField)
1775 			{
1776 				pEdits[nIndex]->SetModifyHdl(LINK(this, SwCreateAuthEntryDlg_Impl, ShortNameHdl));
1777 				m_bNameAllowed = pFields[nIndex].Len() > 0;
1778 				if(!bCreate)
1779 				{
1780 					pFixedTexts[nIndex]->Enable(sal_False);
1781 					pEdits[nIndex]->Enable(sal_False);
1782 				}
1783 			}
1784 		}
1785 		if(bLeft)
1786 		{
1787 			aTL1.Y() += nOffset;
1788 			aTR1.Y() += nOffset;
1789 		}
1790 		else
1791 		{
1792 			aTL2.Y() += nOffset;
1793 			aTR2.Y() += nOffset;
1794 		}
1795 		bLeft = !bLeft;
1796 	}
1797 	EnableHdl(pTypeListBox);
1798 
1799     long nHeightDiff = - aFLSz.Height();
1800     aFLSz.Height() = aTL1.Y();
1801     nHeightDiff += aFLSz.Height();
1802 //    aEntriesFL.SetSizePixel(aFLSz);
1803 	Size aDlgSize(GetSizePixel());
1804 	aDlgSize.Height() += nHeightDiff;
1805     SetSizePixel(aDlgSize);
1806 
1807 }
1808 /* -----------------16.09.99 14:47-------------------
1809 
1810  --------------------------------------------------*/
1811 SwCreateAuthEntryDlg_Impl::~SwCreateAuthEntryDlg_Impl()
1812 {
1813 	for(sal_uInt16 i = 0; i < AUTH_FIELD_END; i++)
1814 	{
1815 		delete pFixedTexts[i];
1816 		delete pEdits[i];
1817 	}
1818 	delete pTypeListBox;
1819 	delete pIdentifierBox;
1820 }
1821 /* -----------------16.09.99 14:27-------------------
1822 
1823  --------------------------------------------------*/
1824 String	SwCreateAuthEntryDlg_Impl::GetEntryText(ToxAuthorityField eField) const
1825 {
1826 	String sRet;
1827 	if( AUTH_FIELD_AUTHORITY_TYPE == eField )
1828 	{
1829 		DBG_ASSERT(pTypeListBox, "No ListBox");
1830 		sRet = String::CreateFromInt32(pTypeListBox->GetSelectEntryPos());
1831 	}
1832 	else if( AUTH_FIELD_IDENTIFIER == eField && !m_bNewEntryMode)
1833 	{
1834 		DBG_ASSERT(pIdentifierBox, "No ComboBox");
1835 		sRet = pIdentifierBox->GetText();
1836 	}
1837 	else
1838 	{
1839 		for(sal_uInt16 nIndex = 0; nIndex < AUTH_FIELD_END; nIndex++)
1840 		{
1841 			const TextInfo aCurInfo = aTextInfoArr[nIndex];
1842 			if(aCurInfo.nToxField == eField)
1843 			{
1844 				sRet = pEdits[nIndex]->GetText();
1845 				break;
1846 			}
1847 		}
1848 	}
1849 	return sRet;
1850 }
1851 /* -----------------21.09.99 13:54-------------------
1852 
1853  --------------------------------------------------*/
1854 IMPL_LINK(SwCreateAuthEntryDlg_Impl, IdentifierHdl, ComboBox*, pBox)
1855 {
1856 	const SwAuthorityFieldType* pFType = (const SwAuthorityFieldType*)
1857 								rWrtSh.GetFldType(RES_AUTHORITY, aEmptyStr);
1858 	if(pFType)
1859 	{
1860 		const SwAuthEntry* pEntry = pFType->GetEntryByIdentifier(
1861 														pBox->GetText());
1862 		if(pEntry)
1863 		{
1864 			for(sal_uInt16 i = 0; i < AUTH_FIELD_END; i++)
1865 			{
1866 				if(AUTH_FIELD_IDENTIFIER == i)
1867 					continue;
1868 				if(AUTH_FIELD_AUTHORITY_TYPE == i)
1869 					pTypeListBox->SelectEntry(
1870 								pEntry->GetAuthorField((ToxAuthorityField)i));
1871 				else
1872 					pEdits[i]->SetText(
1873 								pEntry->GetAuthorField((ToxAuthorityField)i));
1874 			}
1875 		}
1876 	}
1877 	return 0;
1878 }
1879 /* -----------------------------20.12.99 15:07--------------------------------
1880 
1881  ---------------------------------------------------------------------------*/
1882 
1883 IMPL_LINK(SwCreateAuthEntryDlg_Impl, ShortNameHdl, Edit*, pEdit)
1884 {
1885 	if(aShortNameCheckLink.IsSet())
1886 	{
1887 		sal_Bool bEnable = 0 != aShortNameCheckLink.Call(pEdit);
1888 		m_bNameAllowed |= bEnable;
1889 		aOKBT.Enable(pTypeListBox->GetSelectEntryCount() && bEnable);
1890 	}
1891 	return 0;
1892 }
1893 /* -----------------------------20.12.99 15:54--------------------------------
1894 
1895  ---------------------------------------------------------------------------*/
1896 IMPL_LINK(SwCreateAuthEntryDlg_Impl, EnableHdl, ListBox*, pBox)
1897 {
1898 	aOKBT.Enable(m_bNameAllowed && pBox->GetSelectEntryCount());
1899 	return 0;
1900 };
1901 /* -----------------06.10.99 10:00-------------------
1902 
1903  --------------------------------------------------*/
1904 SwAuthMarkFloatDlg::SwAuthMarkFloatDlg(SfxBindings* _pBindings,
1905 				   				SfxChildWindow* pChild,
1906 				   				Window *pParent,
1907 								SfxChildWinInfo* pInfo,
1908 				   				sal_Bool bNew) :
1909     SfxModelessDialog(_pBindings, pChild, pParent, SW_RES(DLG_INSAUTHMARK)),
1910     aDlg(this, SW_RES(WIN_DLG), bNew)
1911 {
1912 	FreeResource();
1913 	Initialize(pInfo);
1914 	SwWrtShell* pWrtShell = ::GetActiveWrtShell();
1915 	DBG_ASSERT(pWrtShell, "No shell?");
1916 	aDlg.ReInitDlg(*pWrtShell);
1917 }
1918 /* -----------------06.10.99 10:27-------------------
1919 
1920  --------------------------------------------------*/
1921 void	SwAuthMarkFloatDlg::Activate()
1922 {
1923 	SfxModelessDialog::Activate();
1924 	aDlg.Activate();
1925 }
1926 
1927 void SwAuthMarkFloatDlg::ReInitDlg(SwWrtShell& rWrtShell)
1928 {
1929 	aDlg.ReInitDlg( rWrtShell );
1930 }
1931 
1932 /* -----------------06.10.99 10:35-------------------
1933 
1934  --------------------------------------------------*/
1935 SwAuthMarkModalDlg::SwAuthMarkModalDlg(Window *pParent, SwWrtShell& rSh) :
1936 	SvxStandardDialog(pParent, SW_RES(DLG_EDIT_AUTHMARK)),
1937 	aDlg(this, SW_RES(WIN_DLG), sal_False)
1938 {
1939 	FreeResource();
1940 	aDlg.ReInitDlg(rSh);
1941 }
1942 /* -----------------06.10.99 10:46-------------------
1943 
1944  --------------------------------------------------*/
1945 void	SwAuthMarkModalDlg::Apply()
1946 {
1947 	aDlg.InsertHdl(0);
1948 }
1949 
1950