xref: /aoo42x/main/cui/source/tabpages/autocdlg.cxx (revision 2ee96f1c)
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_cui.hxx"
26 
27 #define _SVSTDARR_STRINGSISORTDTOR
28 #define _SVSTDARR_STRINGSDTOR
29 #include <svl/svstdarr.hxx>
30 #include <vcl/msgbox.hxx>
31 #include <vcl/field.hxx>
32 #include <vcl/keycodes.hxx>
33 #include <sot/exchange.hxx>
34 #include <svtools/transfer.hxx>
35 #include <unotools/syslocale.hxx>
36 #include <sfx2/objsh.hxx>
37 #include <sfx2/viewsh.hxx>
38 #include <unotools/charclass.hxx>
39 #include <unotools/collatorwrapper.hxx>
40 #include <com/sun/star/i18n/CollatorOptions.hpp>
41 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
42 #include <comphelper/processfactory.hxx>
43 #include <vcl/svapp.hxx>
44 #include <sfx2/module.hxx>
45 #include <sfx2/request.hxx>
46 #include <sfx2/sfxsids.hrc>
47 #include <svl/eitem.hxx>
48 #include <svl/languageoptions.hxx>
49 #include <svx/SmartTagMgr.hxx>
50 #include <com/sun/star/smarttags/XSmartTagRecognizer.hpp>
51 #include <com/sun/star/smarttags/XSmartTagAction.hpp>
52 
53 #define _OFA_AUTOCDLG_CXX
54 #include "autocdlg.hxx"
55 #include "autocdlg.hrc"
56 #include "helpid.hrc"
57 #include <editeng/acorrcfg.hxx>
58 #include <editeng/svxacorr.hxx>
59 #include "cuicharmap.hxx"
60 #include <editeng/unolingu.hxx>
61 #include <dialmgr.hxx>
62 #include <svx/svxids.hrc> // SID_OPEN_SMARTTAGSOPTIONS
63 
64 static LanguageType eLastDialogLanguage = LANGUAGE_SYSTEM;
65 
66 using namespace ::com::sun::star::util;
67 using namespace ::com::sun::star;
68 using namespace ::rtl;
69 
70 static ::com::sun::star::uno::Reference<
71 		::com::sun::star::lang::XMultiServiceFactory >& GetProcessFact()
72 {
73 	static ::com::sun::star::uno::Reference<
74 			::com::sun::star::lang::XMultiServiceFactory > xMSF =
75 									::comphelper::getProcessServiceFactory();
76 	return xMSF;
77 }
78 
79 /*-----------------14.10.96 15.47-------------------
80 
81 --------------------------------------------------*/
82 
83 OfaAutoCorrDlg::OfaAutoCorrDlg(Window* pParent, const SfxItemSet* _pSet ) :
84     SfxTabDialog(pParent, CUI_RES( RID_OFA_AUTOCORR_DLG ), _pSet),
85 	aLanguageFT(    this, CUI_RES(FT_LANG 		  )),
86 	aLanguageLB(    this, CUI_RES(LB_LANG    		  ))
87 {
88 	sal_Bool bShowSWOptions = sal_False;
89     sal_Bool bOpenSmartTagOptions = sal_False;
90 
91     if ( _pSet )
92 	{
93         SFX_ITEMSET_ARG( _pSet, pItem, SfxBoolItem, SID_AUTO_CORRECT_DLG, sal_False );
94 		if ( pItem && pItem->GetValue() )
95 			bShowSWOptions = sal_True;
96 
97         SFX_ITEMSET_ARG( _pSet, pItem2, SfxBoolItem, SID_OPEN_SMARTTAGOPTIONS, sal_False );
98 		if ( pItem2 && pItem2->GetValue() )
99 			bOpenSmartTagOptions = sal_True;
100 	}
101 
102 	aLanguageFT.SetZOrder(0, WINDOW_ZORDER_FIRST);
103 	aLanguageLB.SetZOrder(&aLanguageFT, WINDOW_ZORDER_BEHIND);
104 	aLanguageLB.SetHelpId(HID_AUTOCORR_LANGUAGE);
105 	FreeResource();
106 
107 	AddTabPage(RID_OFAPAGE_AUTOCORR_OPTIONS, OfaAutocorrOptionsPage::Create, 0);
108 	AddTabPage(RID_OFAPAGE_AUTOFMT_APPLY, OfaSwAutoFmtOptionsPage::Create, 0);
109 	AddTabPage(RID_OFAPAGE_AUTOCOMPLETE_OPTIONS, OfaAutoCompleteTabPage::Create, 0);
110     AddTabPage(RID_OFAPAGE_SMARTTAG_OPTIONS, OfaSmartTagOptionsTabPage::Create, 0);
111 
112 	if (!bShowSWOptions)
113 	{
114 		RemoveTabPage(RID_OFAPAGE_AUTOFMT_APPLY);
115 		RemoveTabPage(RID_OFAPAGE_AUTOCOMPLETE_OPTIONS);
116 		RemoveTabPage(RID_OFAPAGE_SMARTTAG_OPTIONS);
117 	}
118 	else
119     {
120         // remove smart tag tab page if no extensions are installed
121         SvxAutoCorrect* pAutoCorrect = SvxAutoCorrCfg::Get()->GetAutoCorrect();
122         SvxSwAutoFmtFlags *pOpt = &pAutoCorrect->GetSwFlags();
123         if ( !pOpt || !pOpt->pSmartTagMgr || 0 == pOpt->pSmartTagMgr->NumberOfRecognizers() )
124             RemoveTabPage(RID_OFAPAGE_SMARTTAG_OPTIONS);
125 
126 		RemoveTabPage(RID_OFAPAGE_AUTOCORR_OPTIONS);
127     }
128 
129 	AddTabPage(RID_OFAPAGE_AUTOCORR_REPLACE, OfaAutocorrReplacePage::Create, 0);
130 	AddTabPage(RID_OFAPAGE_AUTOCORR_EXCEPT,  OfaAutocorrExceptPage::Create, 0);
131 	AddTabPage(RID_OFAPAGE_AUTOCORR_QUOTE, 	 OfaQuoteTabPage::Create, 0);
132 
133 	// initialize languages
134 	//! LANGUAGE_NONE is displayed as '[All]' and the LanguageType
135 	//! will be set to LANGUAGE_DONTKNOW
136     sal_Int16 nLangList = LANG_LIST_WESTERN;
137 
138     if( SvtLanguageOptions().IsCTLFontEnabled() )
139         nLangList |= LANG_LIST_CTL;
140     aLanguageLB.SetLanguageList( nLangList, sal_True, sal_True );
141 	aLanguageLB.SelectLanguage( LANGUAGE_NONE );
142 	sal_uInt16 nPos = aLanguageLB.GetSelectEntryPos();
143 	DBG_ASSERT( LISTBOX_ENTRY_NOTFOUND != nPos, "listbox entry missing" );
144 	aLanguageLB.SetEntryData( nPos, (void*)(long) LANGUAGE_DONTKNOW );
145 
146 	// Initialisierung funktionier fuer static nicht unter Linux - deswegen hier
147 	if( LANGUAGE_SYSTEM == eLastDialogLanguage )
148 		eLastDialogLanguage = Application::GetSettings().GetLanguage();
149 
150 	LanguageType nSelectLang = LANGUAGE_DONTKNOW;
151 	nPos = aLanguageLB.GetEntryPos( (void*)(long) eLastDialogLanguage );
152 	if (LISTBOX_ENTRY_NOTFOUND != nPos)
153 		nSelectLang = eLastDialogLanguage;
154 	aLanguageLB.SelectLanguage( nSelectLang );
155 
156 	aLanguageLB.SetSelectHdl(LINK(this, OfaAutoCorrDlg, SelectLanguageHdl));
157 
158     Size aMinSize(aLanguageFT.CalcMinimumSize());
159     //reserve some extra space for CJK accelerators that are possible inserted
160     //later (like '(A)')
161     aLanguageFT.SetPosSizePixel( 0, 0, aMinSize.Width() + 20, 0, WINDOW_POSSIZE_WIDTH );
162 
163     if ( bOpenSmartTagOptions )
164         SetCurPageId( RID_OFAPAGE_SMARTTAG_OPTIONS );
165 }
166 /*-----------------16.10.96 14.06-------------------
167 
168 --------------------------------------------------*/
169 
170 sal_Bool lcl_FindEntry( ListBox& rLB, const String& rEntry,
171 					CollatorWrapper& rCmpClass )
172 {
173 	sal_uInt16 nCount = rLB.GetEntryCount();
174 	sal_uInt16 nSelPos = rLB.GetSelectEntryPos();
175 	sal_uInt16 i;
176 	for(i = 0; i < nCount; i++)
177 	{
178 		if( 0 == rCmpClass.compareString(rEntry, rLB.GetEntry(i) ))
179 		{
180 			rLB.SelectEntryPos(i, sal_True);
181 			return sal_True;
182 		}
183 	}
184 	if(LISTBOX_ENTRY_NOTFOUND != nSelPos)
185 		rLB.SelectEntryPos(nSelPos, sal_False);
186 	return sal_False;
187 }
188 
189 /* -----------------23.11.98 10:46-------------------
190  *
191  * --------------------------------------------------*/
192 IMPL_LINK(OfaAutoCorrDlg, SelectLanguageHdl, ListBox*, pBox)
193 {
194 	sal_uInt16 nPos = pBox->GetSelectEntryPos();
195 	void* pVoid = pBox->GetEntryData(nPos);
196 	LanguageType eNewLang = (LanguageType)(long)pVoid;
197 	//alte Einstellungen speichern und neu fuellen
198 	if(eNewLang != eLastDialogLanguage)
199 	{
200 		sal_uInt16	nPageId = GetCurPageId();
201 		if(RID_OFAPAGE_AUTOCORR_REPLACE == nPageId)
202 			((OfaAutocorrReplacePage*)GetTabPage( nPageId ))->SetLanguage(eNewLang);
203 		else if(RID_OFAPAGE_AUTOCORR_EXCEPT == nPageId)
204 			((OfaAutocorrExceptPage*)GetTabPage( nPageId ))->SetLanguage(eNewLang);
205 	}
206 	return 0;
207 }
208 /*-----------------14.10.96 15.57-------------------
209 
210 --------------------------------------------------*/
211 
212 OfaAutocorrOptionsPage::OfaAutocorrOptionsPage( Window* pParent,
213 												const SfxItemSet& rSet ) :
214 	SfxTabPage(pParent, CUI_RES( RID_OFAPAGE_AUTOCORR_OPTIONS ), rSet),
215 	aCheckLB			(this, CUI_RES(CLB_SETTINGS	)),
216 
217 	sInput    			(CUI_RES(ST_USE_REPLACE		)),
218     sDoubleCaps         (CUI_RES(ST_CPTL_STT_WORD     )),
219     sStartCap           (CUI_RES(ST_CPTL_STT_SENT     )),
220     sBoldUnderline      (CUI_RES(ST_BOLD_UNDER        )),
221     sURL                (CUI_RES(ST_DETECT_URL        )),
222     sNoDblSpaces        (CUI_RES(STR_NO_DBL_SPACES    )),
223 	sDash    			(CUI_RES(ST_DASH	         	))
224 {
225 	FreeResource();
226 
227 	aCheckLB.SetHelpId(HID_OFAPAGE_AUTOCORR_CLB);
228 }
229 
230 /*-----------------14.10.96 15.58-------------------
231 
232 --------------------------------------------------*/
233 
234 
235 OfaAutocorrOptionsPage::~OfaAutocorrOptionsPage()
236 {
237 }
238 
239 /*-----------------14.10.96 15.58-------------------
240 
241 --------------------------------------------------*/
242 
243 
244 SfxTabPage*	OfaAutocorrOptionsPage::Create( Window* pParent,
245 								const SfxItemSet& rSet)
246 {
247 	return new OfaAutocorrOptionsPage(pParent, rSet);
248 }
249 /*-----------------14.10.96 15.58-------------------
250 
251 --------------------------------------------------*/
252 
253 
254 sal_Bool OfaAutocorrOptionsPage::FillItemSet( SfxItemSet& )
255 {
256 	SvxAutoCorrect* pAutoCorrect = SvxAutoCorrCfg::Get()->GetAutoCorrect();
257 	long nFlags = pAutoCorrect->GetFlags();
258 
259 	sal_uInt16 nPos = 0;
260 	pAutoCorrect->SetAutoCorrFlag(Autocorrect, 			aCheckLB.IsChecked(nPos++));
261 	pAutoCorrect->SetAutoCorrFlag(CptlSttWrd, 			aCheckLB.IsChecked(nPos++));
262 	pAutoCorrect->SetAutoCorrFlag(CptlSttSntnc, 		aCheckLB.IsChecked(nPos++));
263 	pAutoCorrect->SetAutoCorrFlag(ChgWeightUnderl,		aCheckLB.IsChecked(nPos++));
264 	pAutoCorrect->SetAutoCorrFlag(SetINetAttr, 			aCheckLB.IsChecked(nPos++));
265 	pAutoCorrect->SetAutoCorrFlag(ChgToEnEmDash,		aCheckLB.IsChecked(nPos++));
266 	pAutoCorrect->SetAutoCorrFlag(IgnoreDoubleSpace,	aCheckLB.IsChecked(nPos++));
267 
268 	sal_Bool bReturn = nFlags != pAutoCorrect->GetFlags();
269 	if(bReturn )
270     {
271         SvxAutoCorrCfg* pCfg = SvxAutoCorrCfg::Get();
272         pCfg->SetModified();
273         pCfg->Commit();
274     }
275 	return bReturn;
276 }
277 
278 /* -----------------23.11.98 16:15-------------------
279  *
280  * --------------------------------------------------*/
281 void	OfaAutocorrOptionsPage::ActivatePage( const SfxItemSet& )
282 {
283 	((OfaAutoCorrDlg*)GetTabDialog())->EnableLanguage(sal_False);
284 }
285 
286 /*-----------------14.10.96 15.58-------------------
287 
288 --------------------------------------------------*/
289 
290 
291 void OfaAutocorrOptionsPage::Reset( const SfxItemSet& )
292 {
293 	SvxAutoCorrect* pAutoCorrect = SvxAutoCorrCfg::Get()->GetAutoCorrect();
294 	const long nFlags = pAutoCorrect->GetFlags();
295 
296 	aCheckLB.SetUpdateMode(sal_False);
297 	aCheckLB.Clear();
298 
299 	aCheckLB.InsertEntry(sInput);
300 	aCheckLB.InsertEntry(sDoubleCaps);
301 	aCheckLB.InsertEntry(sStartCap);
302 	aCheckLB.InsertEntry(sBoldUnderline);
303 	aCheckLB.InsertEntry(sURL);
304 	aCheckLB.InsertEntry(sDash);
305 	aCheckLB.InsertEntry(sNoDblSpaces);
306 
307 	sal_uInt16 nPos = 0;
308 	aCheckLB.CheckEntryPos( nPos++, 0 != (nFlags & Autocorrect) );
309 	aCheckLB.CheckEntryPos( nPos++, 0 != (nFlags & CptlSttWrd) );
310 	aCheckLB.CheckEntryPos( nPos++, 0 != (nFlags & CptlSttSntnc) );
311 	aCheckLB.CheckEntryPos( nPos++, 0 != (nFlags & ChgWeightUnderl) );
312 	aCheckLB.CheckEntryPos( nPos++, 0 != (nFlags & SetINetAttr) );
313 	aCheckLB.CheckEntryPos( nPos++, 0 != (nFlags & ChgToEnEmDash) );
314 	aCheckLB.CheckEntryPos( nPos++, 0 != (nFlags & IgnoreDoubleSpace) );
315 
316 	aCheckLB.SetUpdateMode(sal_True);
317 }
318 
319 /*********************************************************************/
320 /*                                                                   */
321 /*  Hilfs-struct fuer dUserDaten der Checklistbox                    */
322 /*                                                                   */
323 /*********************************************************************/
324 
325 struct ImpUserData
326 {
327 	String 	*pString;
328 	Font* 	pFont;
329 
330 	ImpUserData(String* pText, Font* pFnt)
331 		{ pString = pText; pFont = pFnt;}
332 };
333 
334 
335 /*********************************************************************/
336 /*                                                                   */
337 /*	Dialog fuer Prozenteinstellung                                   */
338 /*                                                                   */
339 /*********************************************************************/
340 
341 class OfaAutoFmtPrcntSet : public ModalDialog
342 {
343 	OKButton 		aOKPB;
344 	CancelButton	aCancelPB;
345 	FixedLine		aPrcntFL;
346 	MetricField		aPrcntMF;
347 
348 	public:
349 		OfaAutoFmtPrcntSet(Window* pParent) :
350 			ModalDialog(pParent, CUI_RES(RID_OFADLG_PRCNT_SET)),
351 				aOKPB(this, 		CUI_RES(BT_OK)),
352 				aCancelPB(this, 	CUI_RES(BT_CANCEL)),
353 				aPrcntFL(this, 		CUI_RES(FL_PRCNT)),
354 				aPrcntMF(this, 	CUI_RES(ED_RIGHT_MARGIN))
355 			{
356 				FreeResource();
357 			}
358 	MetricField& 	GetPrcntFld(){return aPrcntMF;}
359 };
360 
361 
362 /*********************************************************************/
363 /*                                                                   */
364 /*  veraenderter LBoxString                                          */
365 /*                                                                   */
366 /*********************************************************************/
367 
368 class OfaImpBrwString : public SvLBoxString
369 {
370 public:
371 
372 	OfaImpBrwString( SvLBoxEntry* pEntry, sal_uInt16 nFlags,
373 		const String& rStr ) : SvLBoxString(pEntry,nFlags,rStr){}
374 
375 	virtual void Paint( const Point& rPos, SvLBox& rDev, sal_uInt16 nFlags,
376 											SvLBoxEntry* pEntry);
377 };
378 
379 /*********************************************************************/
380 /*                                                                   */
381 /*********************************************************************/
382 
383 
384 void __EXPORT OfaImpBrwString::Paint( const Point& rPos, SvLBox& rDev, sal_uInt16 /*nFlags*/,
385 	SvLBoxEntry* pEntry )
386 {
387 	rDev.DrawText( rPos, GetText() );
388 	if(pEntry->GetUserData())
389 	{
390 		ImpUserData* pUserData = (ImpUserData* )pEntry->GetUserData();
391 		Point aNewPos(rPos);
392 		aNewPos.X() += rDev.GetTextWidth(GetText());
393 		Font aOldFont( rDev.GetFont());
394 		Font aFont( aOldFont );
395 		if(pUserData->pFont)
396 		{
397 			aFont = *pUserData->pFont;
398 			aFont.SetColor(aOldFont.GetColor());
399 			aFont.SetSize(aOldFont.GetSize());
400 		}
401 		aFont.SetWeight( WEIGHT_BOLD );
402 
403 		sal_Bool bFett = sal_True;
404 		sal_uInt16 nPos = 0;
405 		do {
406 			String sTxt( pUserData->pString->GetToken( 0, 1, nPos ));
407 
408 			if( bFett )
409 				rDev.SetFont( aFont );
410 
411 			rDev.DrawText( aNewPos, sTxt );
412 
413 			if( STRING_NOTFOUND != nPos )
414 				aNewPos.X() += rDev.GetTextWidth( sTxt );
415 
416 			if( bFett )
417 				rDev.SetFont( aOldFont );
418 
419 			bFett = !bFett;
420 		} while( STRING_NOTFOUND != nPos );
421 	}
422 }
423 
424 /*********************************************************************/
425 /*                                                                   */
426 /* 	TabPage Autoformat anwenden			                             */
427 /*                                                                   */
428 /*********************************************************************/
429 
430 #define CBCOL_FIRST		0
431 #define CBCOL_SECOND	1
432 #define CBCOL_BOTH		2
433 
434 enum OfaAutoFmtOptions
435 {
436 	USE_REPLACE_TABLE,
437 	CORR_UPPER,
438 	BEGIN_UPPER,
439 	BOLD_UNDERLINE,
440 	DETECT_URL,
441 	REPLACE_DASHES,
442 	DEL_SPACES_AT_STT_END,
443 	DEL_SPACES_BETWEEN_LINES,
444 	IGNORE_DBLSPACE,
445 	APPLY_NUMBERING,
446 	INSERT_BORDER,
447 	CREATE_TABLE,
448 	REPLACE_STYLES,
449 	DEL_EMPTY_NODE,
450 	REPLACE_USER_COLL,
451 	REPLACE_BULLETS,
452 	MERGE_SINGLE_LINE_PARA
453 };
454 
455 OfaSwAutoFmtOptionsPage::OfaSwAutoFmtOptionsPage( Window* pParent,
456 								const SfxItemSet& rSet ) :
457 	SfxTabPage(pParent, CUI_RES(RID_OFAPAGE_AUTOFMT_APPLY), rSet),
458 	aCheckLB			(this,	CUI_RES(CLB_SETTINGS)),
459 	aEditPB				(this, 	CUI_RES(PB_EDIT)),
460 	aHeader1Expl		(this, 	CUI_RES(FT_HEADER1_EXPLANATION)),
461 	aHeader2Expl		(this, 	CUI_RES(FT_HEADER2_EXPLANATION)),
462 	sHeader1			(CUI_RES( STR_HEADER1		)),
463 	sHeader2			(CUI_RES( STR_HEADER2		)),
464 	sDeleteEmptyPara	(CUI_RES( ST_DEL_EMPTY_PARA)),
465 	sUseReplaceTbl		(CUI_RES(	ST_USE_REPLACE  )),
466 	sCptlSttWord		(CUI_RES(	ST_CPTL_STT_WORD)),
467 	sCptlSttSent		(CUI_RES(	ST_CPTL_STT_SENT)),
468 	sUserStyle			(CUI_RES(	ST_USER_STYLE   )),
469 	sBullet				(CUI_RES(	ST_BULLET       )),
470 	sBoldUnder			(CUI_RES(	ST_BOLD_UNDER   )),
471 	sNoDblSpaces		(CUI_RES(	STR_NO_DBL_SPACES)),
472 	sDetectURL			(CUI_RES(	ST_DETECT_URL   )),
473 	sDash				(CUI_RES(	ST_DASH         )),
474 	sRightMargin		(CUI_RES(	ST_RIGHT_MARGIN	)),
475 	sNum				(CUI_RES(	STR_NUM			)),
476 	sBorder				(CUI_RES(	STR_BORDER		)),
477 	sTable				(CUI_RES(	STR_TABLE		)),
478 	sReplaceTemplates   (CUI_RES(	STR_REPLACE_TEMPLATES)),
479 	sDelSpaceAtSttEnd	(CUI_RES(	STR_DEL_SPACES_AT_STT_END)),
480 	sDelSpaceBetweenLines(CUI_RES(STR_DEL_SPACES_BETWEEN_LINES)),
481 
482 	nPercent		( 50 ),
483 	pCheckButtonData( NULL )
484 
485 {
486 	FreeResource();
487 
488 	//typ. Anfuehrungszeichen einsetzen
489 	SvtSysLocale aSysLcl;
490 
491 	aCheckLB.SetHelpId(HID_OFAPAGE_AUTOFORMAT_CLB);
492 	aCheckLB.SetStyle(aCheckLB.GetStyle()|WB_HSCROLL| WB_VSCROLL);
493 
494 	aCheckLB.SetSelectHdl(LINK(this, OfaSwAutoFmtOptionsPage, SelectHdl));
495 	aCheckLB.SetDoubleClickHdl(LINK(this, OfaSwAutoFmtOptionsPage, EditHdl));
496 
497 	static long aStaticTabs[]=
498 	{
499 		3, 0, 20, 40
500 	};
501 
502 	aCheckLB.SvxSimpleTable::SetTabs(aStaticTabs);
503 	String sHeader( sHeader1 );
504 	sHeader += '\t';
505 	sHeader += sHeader2;
506 	sHeader += '\t';
507 	aCheckLB.InsertHeaderEntry( sHeader, HEADERBAR_APPEND,
508 						HIB_CENTER | HIB_VCENTER | HIB_FIXEDPOS | HIB_FIXED);
509 
510 	aEditPB.SetClickHdl(LINK(this, OfaSwAutoFmtOptionsPage, EditHdl));
511 }
512 
513 /*********************************************************************/
514 /*                                                                   */
515 /*********************************************************************/
516 
517 SvLBoxEntry* OfaSwAutoFmtOptionsPage::CreateEntry(String& rTxt, sal_uInt16 nCol)
518 {
519 	SvLBoxEntry* pEntry = new SvLBoxEntry;
520 
521 	if ( !pCheckButtonData )
522 	{
523 		pCheckButtonData = new SvLBoxButtonData( &aCheckLB );
524 		aCheckLB.SetCheckButtonData( pCheckButtonData );
525 	}
526 
527 	pEntry->AddItem( new SvLBoxContextBmp( pEntry, 0, Image(), Image(), 0));	// Sonst Puff!
528 
529 	String sEmpty;
530 	if (nCol == CBCOL_SECOND)
531 		pEntry->AddItem( new SvLBoxString( pEntry, 0, sEmpty) );	// Leerspalte
532 	else
533 		pEntry->AddItem( new SvLBoxButton( pEntry, SvLBoxButtonKind_enabledCheckbox, 0, pCheckButtonData ) );
534 
535 	if (nCol == CBCOL_FIRST)
536 		pEntry->AddItem( new SvLBoxString( pEntry, 0, sEmpty) );	// Leerspalte
537 	else
538 		pEntry->AddItem( new SvLBoxButton( pEntry, SvLBoxButtonKind_enabledCheckbox, 0, pCheckButtonData ) );
539 	pEntry->AddItem( new OfaImpBrwString( pEntry, 0, rTxt ) );
540 
541 	return pEntry;
542 }
543 
544 /*********************************************************************/
545 /*                                                                   */
546 /*********************************************************************/
547 
548 
549 __EXPORT OfaSwAutoFmtOptionsPage::~OfaSwAutoFmtOptionsPage()
550 {
551 	delete (ImpUserData*) aCheckLB.GetUserData( REPLACE_BULLETS );
552 	delete (ImpUserData*) aCheckLB.GetUserData( APPLY_NUMBERING );
553 	delete (ImpUserData*) aCheckLB.GetUserData( MERGE_SINGLE_LINE_PARA );
554 	delete pCheckButtonData;
555 }
556 
557 /*********************************************************************/
558 /*                                                                   */
559 /*********************************************************************/
560 
561 SfxTabPage* __EXPORT OfaSwAutoFmtOptionsPage::Create( Window* pParent,
562 								const SfxItemSet& rAttrSet)
563 {
564 	return new OfaSwAutoFmtOptionsPage(pParent, rAttrSet);
565 }
566 
567 /*********************************************************************/
568 /*                                                                   */
569 /*********************************************************************/
570 
571 sal_Bool OfaSwAutoFmtOptionsPage::FillItemSet( SfxItemSet&  )
572 {
573 	sal_Bool bModified = sal_False;
574 	SvxAutoCorrect* pAutoCorrect = SvxAutoCorrCfg::Get()->GetAutoCorrect();
575 	SvxSwAutoFmtFlags *pOpt = &pAutoCorrect->GetSwFlags();
576 	long nFlags = pAutoCorrect->GetFlags();
577 
578 	sal_Bool bCheck = aCheckLB.IsChecked(USE_REPLACE_TABLE, CBCOL_FIRST);
579 	bModified |= pOpt->bAutoCorrect != bCheck;
580 	pOpt->bAutoCorrect = bCheck;
581 	pAutoCorrect->SetAutoCorrFlag(Autocorrect,
582 						aCheckLB.IsChecked(USE_REPLACE_TABLE, CBCOL_SECOND));
583 
584 	bCheck = aCheckLB.IsChecked(CORR_UPPER, CBCOL_FIRST);
585 	bModified |= pOpt->bCptlSttWrd != bCheck;
586 	pOpt->bCptlSttWrd = bCheck;
587 	pAutoCorrect->SetAutoCorrFlag(CptlSttWrd,
588 						aCheckLB.IsChecked(CORR_UPPER, CBCOL_SECOND));
589 
590 	bCheck = aCheckLB.IsChecked(BEGIN_UPPER, CBCOL_FIRST);
591 	bModified |= pOpt->bCptlSttSntnc != bCheck;
592 	pOpt->bCptlSttSntnc = bCheck;
593 	pAutoCorrect->SetAutoCorrFlag(CptlSttSntnc,
594 						aCheckLB.IsChecked(BEGIN_UPPER, CBCOL_SECOND));
595 
596 	bCheck = aCheckLB.IsChecked(BOLD_UNDERLINE, CBCOL_FIRST);
597 	bModified |= pOpt->bChgWeightUnderl != bCheck;
598 	pOpt->bChgWeightUnderl = bCheck;
599 	pAutoCorrect->SetAutoCorrFlag(ChgWeightUnderl,
600 						aCheckLB.IsChecked(BOLD_UNDERLINE, CBCOL_SECOND));
601 
602 	pAutoCorrect->SetAutoCorrFlag(IgnoreDoubleSpace,
603 						aCheckLB.IsChecked(IGNORE_DBLSPACE, CBCOL_SECOND));
604 
605 	bCheck = aCheckLB.IsChecked(DETECT_URL, CBCOL_FIRST);
606 	bModified |= pOpt->bSetINetAttr != bCheck;
607 	pOpt->bSetINetAttr = bCheck;
608 	pAutoCorrect->SetAutoCorrFlag(SetINetAttr,
609 						aCheckLB.IsChecked(DETECT_URL, CBCOL_SECOND));
610 
611 	bCheck = aCheckLB.IsChecked(DEL_EMPTY_NODE, CBCOL_FIRST);
612 	bModified |= pOpt->bDelEmptyNode != bCheck;
613 	pOpt->bDelEmptyNode = bCheck;
614 
615 	bCheck = aCheckLB.IsChecked(REPLACE_USER_COLL, CBCOL_FIRST);
616 	bModified |= pOpt->bChgUserColl != bCheck;
617 	pOpt->bChgUserColl = bCheck;
618 
619 	bCheck = aCheckLB.IsChecked(REPLACE_BULLETS, CBCOL_FIRST);
620 	bModified |= pOpt->bChgEnumNum != bCheck;
621 	pOpt->bChgEnumNum = bCheck;
622 	bModified |= aBulletFont != pOpt->aBulletFont;
623 	pOpt->aBulletFont = aBulletFont;
624 	bModified |= String(pOpt->cBullet) != sBulletChar;
625 	pOpt->cBullet = sBulletChar.GetChar(0);
626 
627 	bModified |= aByInputBulletFont != pOpt->aByInputBulletFont;
628 	bModified |= String(pOpt->cByInputBullet) != sByInputBulletChar;
629 	pOpt->aByInputBulletFont = aByInputBulletFont;
630 	pOpt->cByInputBullet = sByInputBulletChar.GetChar(0);
631 
632 	bCheck = aCheckLB.IsChecked(MERGE_SINGLE_LINE_PARA, CBCOL_FIRST);
633 	bModified |= pOpt->bRightMargin != bCheck;
634 	pOpt->bRightMargin = bCheck;
635 	bModified |= nPercent != pOpt->nRightMargin;
636 	pOpt->nRightMargin = (sal_uInt8)nPercent;
637 
638 	bCheck = aCheckLB.IsChecked(APPLY_NUMBERING, CBCOL_SECOND);
639 	bModified |= pOpt->bSetNumRule != bCheck;
640 	pOpt->bSetNumRule = bCheck;
641 
642 	bCheck = aCheckLB.IsChecked(INSERT_BORDER, CBCOL_SECOND);
643 	bModified |= pOpt->bSetBorder != bCheck;
644 	pOpt->bSetBorder = bCheck;
645 
646 	bCheck = aCheckLB.IsChecked(CREATE_TABLE, CBCOL_SECOND);
647 	bModified |= pOpt->bCreateTable != bCheck;
648 	pOpt->bCreateTable = bCheck;
649 
650 	bCheck = aCheckLB.IsChecked(REPLACE_STYLES, CBCOL_SECOND);
651 	bModified |= pOpt->bReplaceStyles != bCheck;
652 	pOpt->bReplaceStyles = bCheck;
653 
654 	bCheck = aCheckLB.IsChecked(REPLACE_DASHES, CBCOL_FIRST);
655 	bModified |= pOpt->bChgToEnEmDash != bCheck;
656 	pOpt->bChgToEnEmDash = bCheck;
657 	pAutoCorrect->SetAutoCorrFlag(ChgToEnEmDash,
658 						aCheckLB.IsChecked(REPLACE_DASHES, CBCOL_SECOND));
659 
660 	bCheck = aCheckLB.IsChecked(DEL_SPACES_AT_STT_END, CBCOL_FIRST);
661 	bModified |= pOpt->bAFmtDelSpacesAtSttEnd != bCheck;
662 	pOpt->bAFmtDelSpacesAtSttEnd = bCheck;
663 	bCheck = aCheckLB.IsChecked(DEL_SPACES_AT_STT_END, CBCOL_SECOND);
664 	bModified |= pOpt->bAFmtByInpDelSpacesAtSttEnd != bCheck;
665 	pOpt->bAFmtByInpDelSpacesAtSttEnd = bCheck;
666 
667 	bCheck = aCheckLB.IsChecked(DEL_SPACES_BETWEEN_LINES, CBCOL_FIRST);
668 	bModified |= pOpt->bAFmtDelSpacesBetweenLines != bCheck;
669 	pOpt->bAFmtDelSpacesBetweenLines = bCheck;
670 	bCheck = aCheckLB.IsChecked(DEL_SPACES_BETWEEN_LINES, CBCOL_SECOND);
671 	bModified |= pOpt->bAFmtByInpDelSpacesBetweenLines != bCheck;
672 	pOpt->bAFmtByInpDelSpacesBetweenLines = bCheck;
673 
674 	if(bModified || nFlags != pAutoCorrect->GetFlags())
675     {
676         SvxAutoCorrCfg* pCfg = SvxAutoCorrCfg::Get();
677         pCfg->SetModified();
678         pCfg->Commit();
679     }
680 
681 	return sal_True;
682 }
683 
684 /* -----------------23.11.98 16:15-------------------
685  *
686  * --------------------------------------------------*/
687 void	OfaSwAutoFmtOptionsPage::ActivatePage( const SfxItemSet& )
688 {
689 	((OfaAutoCorrDlg*)GetTabDialog())->EnableLanguage(sal_False);
690 }
691 
692 /*********************************************************************/
693 /*                                                                   */
694 /*********************************************************************/
695 
696 
697 void OfaSwAutoFmtOptionsPage::Reset( const SfxItemSet& )
698 {
699 	SvxAutoCorrect* pAutoCorrect = SvxAutoCorrCfg::Get()->GetAutoCorrect();
700 	SvxSwAutoFmtFlags *pOpt = &pAutoCorrect->GetSwFlags();
701 	const long nFlags = pAutoCorrect->GetFlags();
702 
703 	aCheckLB.SetUpdateMode(sal_False);
704 	aCheckLB.Clear();
705 
706 	// Die folgenden Eintraege muessen in der selben Reihenfolge, wie im
707 	// OfaAutoFmtOptions-enum eingefuegt werden!
708 	aCheckLB.GetModel()->Insert(CreateEntry(sUseReplaceTbl,		CBCOL_BOTH	));
709 	aCheckLB.GetModel()->Insert(CreateEntry(sCptlSttWord,		CBCOL_BOTH	));
710 	aCheckLB.GetModel()->Insert(CreateEntry(sCptlSttSent,		CBCOL_BOTH	));
711 	aCheckLB.GetModel()->Insert(CreateEntry(sBoldUnder,			CBCOL_BOTH	));
712 	aCheckLB.GetModel()->Insert(CreateEntry(sDetectURL,			CBCOL_BOTH	));
713 	aCheckLB.GetModel()->Insert(CreateEntry(sDash,				CBCOL_BOTH  ));
714 	aCheckLB.GetModel()->Insert(CreateEntry(sDelSpaceAtSttEnd,	CBCOL_BOTH  ));
715 	aCheckLB.GetModel()->Insert(CreateEntry(sDelSpaceBetweenLines, CBCOL_BOTH  ));
716 
717 	aCheckLB.GetModel()->Insert(CreateEntry(sNoDblSpaces,		CBCOL_SECOND));
718 	aCheckLB.GetModel()->Insert(CreateEntry(sNum,				CBCOL_SECOND));
719 	aCheckLB.GetModel()->Insert(CreateEntry(sBorder,			CBCOL_SECOND));
720 	aCheckLB.GetModel()->Insert(CreateEntry(sTable,				CBCOL_SECOND));
721 	aCheckLB.GetModel()->Insert(CreateEntry(sReplaceTemplates,	CBCOL_SECOND));
722 	aCheckLB.GetModel()->Insert(CreateEntry(sDeleteEmptyPara,	CBCOL_FIRST	));
723 	aCheckLB.GetModel()->Insert(CreateEntry(sUserStyle,			CBCOL_FIRST	));
724 	aCheckLB.GetModel()->Insert(CreateEntry(sBullet,			CBCOL_FIRST	));
725 	aCheckLB.GetModel()->Insert(CreateEntry(sRightMargin,		CBCOL_FIRST	));
726 
727 	aCheckLB.CheckEntryPos( USE_REPLACE_TABLE, 	CBCOL_FIRST,	pOpt->bAutoCorrect );
728 	aCheckLB.CheckEntryPos( USE_REPLACE_TABLE,	CBCOL_SECOND,	0 != (nFlags & Autocorrect));
729 	aCheckLB.CheckEntryPos( CORR_UPPER,			CBCOL_FIRST,	pOpt->bCptlSttWrd );
730 	aCheckLB.CheckEntryPos( CORR_UPPER,			CBCOL_SECOND,	0 != (nFlags & CptlSttWrd) );
731 	aCheckLB.CheckEntryPos( BEGIN_UPPER,		CBCOL_FIRST,	pOpt->bCptlSttSntnc );
732 	aCheckLB.CheckEntryPos( BEGIN_UPPER,		CBCOL_SECOND,	0 != (nFlags & CptlSttSntnc) );
733 	aCheckLB.CheckEntryPos( BOLD_UNDERLINE,		CBCOL_FIRST,	pOpt->bChgWeightUnderl );
734 	aCheckLB.CheckEntryPos( BOLD_UNDERLINE,		CBCOL_SECOND,	0 != (nFlags & ChgWeightUnderl) );
735 	aCheckLB.CheckEntryPos( IGNORE_DBLSPACE,	CBCOL_SECOND,	0 != (nFlags & IgnoreDoubleSpace) );
736 	aCheckLB.CheckEntryPos( DETECT_URL,			CBCOL_FIRST,	pOpt->bSetINetAttr );
737 	aCheckLB.CheckEntryPos( DETECT_URL,			CBCOL_SECOND,	0 != (nFlags & SetINetAttr) );
738 	aCheckLB.CheckEntryPos( REPLACE_DASHES,		CBCOL_FIRST,	pOpt->bChgToEnEmDash );
739 	aCheckLB.CheckEntryPos( REPLACE_DASHES,		CBCOL_SECOND,	0 != (nFlags & ChgToEnEmDash) );
740 	aCheckLB.CheckEntryPos( DEL_SPACES_AT_STT_END,		CBCOL_FIRST,	pOpt->bAFmtDelSpacesAtSttEnd );
741 	aCheckLB.CheckEntryPos( DEL_SPACES_AT_STT_END,		CBCOL_SECOND,	pOpt->bAFmtByInpDelSpacesAtSttEnd );
742 	aCheckLB.CheckEntryPos( DEL_SPACES_BETWEEN_LINES,	CBCOL_FIRST,	pOpt->bAFmtDelSpacesBetweenLines );
743 	aCheckLB.CheckEntryPos( DEL_SPACES_BETWEEN_LINES,	CBCOL_SECOND,	pOpt->bAFmtByInpDelSpacesBetweenLines );
744 	aCheckLB.CheckEntryPos( DEL_EMPTY_NODE,		CBCOL_FIRST,	pOpt->bDelEmptyNode );
745 	aCheckLB.CheckEntryPos( REPLACE_USER_COLL,	CBCOL_FIRST,	pOpt->bChgUserColl );
746 	aCheckLB.CheckEntryPos( REPLACE_BULLETS,	CBCOL_FIRST,	pOpt->bChgEnumNum );
747 
748 	aBulletFont = pOpt->aBulletFont;
749 	sBulletChar = pOpt->cBullet;
750 	ImpUserData* pUserData = new ImpUserData(&sBulletChar, &aBulletFont);
751 	aCheckLB.SetUserData(  REPLACE_BULLETS, pUserData );
752 
753 	nPercent = pOpt->nRightMargin;
754 	sMargin = ' ';
755 	sMargin += String::CreateFromInt32( nPercent );
756 	sMargin += '%';
757 	pUserData = new ImpUserData(&sMargin, 0);
758 	aCheckLB.SetUserData( MERGE_SINGLE_LINE_PARA, pUserData );
759 
760 	aCheckLB.CheckEntryPos( APPLY_NUMBERING,	CBCOL_SECOND,	pOpt->bSetNumRule );
761 
762 	aByInputBulletFont = pOpt->aByInputBulletFont;
763 	sByInputBulletChar = pOpt->cByInputBullet;
764 	ImpUserData* pUserData2 = new ImpUserData(&sByInputBulletChar, &aByInputBulletFont);
765 	aCheckLB.SetUserData( APPLY_NUMBERING , pUserData2 );
766 
767 	aCheckLB.CheckEntryPos( MERGE_SINGLE_LINE_PARA, CBCOL_FIRST, pOpt->bRightMargin );
768 	aCheckLB.CheckEntryPos( INSERT_BORDER,		CBCOL_SECOND,	pOpt->bSetBorder );
769 	aCheckLB.CheckEntryPos( CREATE_TABLE,		CBCOL_SECOND,	pOpt->bCreateTable );
770 	aCheckLB.CheckEntryPos( REPLACE_STYLES,		CBCOL_SECOND,	pOpt->bReplaceStyles );
771 
772 	aCheckLB.SetUpdateMode(sal_True);
773 }
774 
775 /*********************************************************************/
776 /*                                                                   */
777 /*********************************************************************/
778 
779 IMPL_LINK(OfaSwAutoFmtOptionsPage, SelectHdl, OfaACorrCheckListBox*, pBox)
780 {
781 	aEditPB.Enable(0 != pBox->FirstSelected()->GetUserData());
782 	return 0;
783 }
784 
785 /*********************************************************************/
786 /*                                                                   */
787 /*********************************************************************/
788 
789 IMPL_LINK(OfaSwAutoFmtOptionsPage, EditHdl, PushButton*, EMPTYARG)
790 {
791     sal_uLong nSelEntryPos = aCheckLB.GetSelectEntryPos();
792 	if( nSelEntryPos == REPLACE_BULLETS ||
793 		nSelEntryPos == APPLY_NUMBERING)
794 	{
795 		SvxCharacterMap *pMapDlg = new SvxCharacterMap(this);
796 		ImpUserData* pUserData = (ImpUserData*)aCheckLB.FirstSelected()->GetUserData();
797 		pMapDlg->SetCharFont(*pUserData->pFont);
798 		pMapDlg->SetChar( pUserData->pString->GetChar(0) );
799 		if(RET_OK == pMapDlg->Execute())
800 		{
801 			Font aFont(pMapDlg->GetCharFont());
802 			*pUserData->pFont = aFont;
803 			sal_UCS4 aChar = pMapDlg->GetChar();
804 			// using the UCS4 constructor
805 			rtl::OUString aOUStr( &aChar, 1 );
806 			*pUserData->pString = aOUStr;
807 		}
808 		delete pMapDlg;
809 	}
810 	else if( MERGE_SINGLE_LINE_PARA == nSelEntryPos )
811 	{
812 		// Dialog fuer Prozenteinstellung
813 		OfaAutoFmtPrcntSet aDlg(this);
814 		aDlg.GetPrcntFld().SetValue(nPercent);
815 		if(RET_OK == aDlg.Execute())
816 		{
817 			nPercent = (sal_uInt16)aDlg.GetPrcntFld().GetValue();
818 			sMargin = ' ';
819 			sMargin += String::CreateFromInt32( nPercent );
820 			sMargin += '%';
821 		}
822 	}
823 	aCheckLB.Invalidate();
824 	return 0;
825 }
826 
827 /*********************************************************************/
828 /*                                                                   */
829 /*********************************************************************/
830 
831 void OfaACorrCheckListBox::SetTabs()
832 {
833 	SvxSimpleTable::SetTabs();
834 	sal_uInt16 nAdjust = SV_LBOXTAB_ADJUST_RIGHT|SV_LBOXTAB_ADJUST_LEFT|SV_LBOXTAB_ADJUST_CENTER|SV_LBOXTAB_ADJUST_NUMERIC|SV_LBOXTAB_FORCE;
835 
836 	if( aTabs.Count() > 1 )
837 	{
838 		SvLBoxTab* pTab = (SvLBoxTab*)aTabs.GetObject(1);
839 		pTab->nFlags &= ~nAdjust;
840 		pTab->nFlags |= SV_LBOXTAB_PUSHABLE|SV_LBOXTAB_ADJUST_CENTER|SV_LBOXTAB_FORCE;
841 	}
842 	if( aTabs.Count() > 2 )
843 	{
844 		SvLBoxTab* pTab = (SvLBoxTab*)aTabs.GetObject(2);
845 		pTab->nFlags &= ~nAdjust;
846 		pTab->nFlags |= SV_LBOXTAB_PUSHABLE|SV_LBOXTAB_ADJUST_CENTER|SV_LBOXTAB_FORCE;
847 	}
848 }
849 
850 /*********************************************************************/
851 /*                                                                   */
852 /*********************************************************************/
853 
854 void OfaACorrCheckListBox::CheckEntryPos(sal_uLong nPos, sal_uInt16 nCol, sal_Bool bChecked)
855 {
856 	if ( nPos < GetEntryCount() )
857 		SetCheckButtonState(
858 			GetEntry(nPos),
859 			nCol,
860 			bChecked ? SvButtonState( SV_BUTTON_CHECKED ) :
861 									   SvButtonState( SV_BUTTON_UNCHECKED ) );
862 }
863 
864 /*********************************************************************/
865 /*                                                                   */
866 /*********************************************************************/
867 
868 sal_Bool OfaACorrCheckListBox::IsChecked(sal_uLong nPos, sal_uInt16 nCol)
869 {
870 	return GetCheckButtonState( GetEntry(nPos), nCol ) == SV_BUTTON_CHECKED;
871 }
872 
873 /*********************************************************************/
874 /*                                                                   */
875 /*********************************************************************/
876 
877 void OfaACorrCheckListBox::SetCheckButtonState( SvLBoxEntry* pEntry, sal_uInt16 nCol, SvButtonState eState)
878 {
879 	SvLBoxButton* pItem = (SvLBoxButton*)(pEntry->GetItem(nCol + 1));
880 
881 	DBG_ASSERT(pItem,"SetCheckButton:Item not found");
882 	if (((SvLBoxItem*)pItem)->IsA() == SV_ITEM_ID_LBOXBUTTON)
883 	{
884 		switch( eState )
885 		{
886 			case SV_BUTTON_CHECKED:
887 				pItem->SetStateChecked();
888 				break;
889 
890 			case SV_BUTTON_UNCHECKED:
891 				pItem->SetStateUnchecked();
892 				break;
893 
894 			case SV_BUTTON_TRISTATE:
895 				pItem->SetStateTristate();
896 				break;
897 		}
898 		InvalidateEntry( pEntry );
899 	}
900 }
901 
902 /*********************************************************************/
903 /*                                                                   */
904 /*********************************************************************/
905 
906 SvButtonState OfaACorrCheckListBox::GetCheckButtonState( SvLBoxEntry* pEntry, sal_uInt16 nCol ) const
907 {
908 	SvButtonState eState = SV_BUTTON_UNCHECKED;
909 	SvLBoxButton* pItem = (SvLBoxButton*)(pEntry->GetItem(nCol + 1));
910 	DBG_ASSERT(pItem,"GetChButnState:Item not found");
911 
912 	if (((SvLBoxItem*)pItem)->IsA() == SV_ITEM_ID_LBOXBUTTON)
913 	{
914 		sal_uInt16 nButtonFlags = pItem->GetButtonFlags();
915 		eState = pCheckButtonData->ConvertToButtonState( nButtonFlags );
916 	}
917 
918 	return eState;
919 }
920 
921 void OfaACorrCheckListBox::HBarClick()
922 {
923 	// Sortierung durch diese Ueberladung abgeklemmt
924 }
925 /* -----------------------------22.05.2002 11:06------------------------------
926 
927  ---------------------------------------------------------------------------*/
928 void    OfaACorrCheckListBox::KeyInput( const KeyEvent& rKEvt )
929 {
930     if(!rKEvt.GetKeyCode().GetModifier() &&
931         KEY_SPACE == rKEvt.GetKeyCode().GetCode())
932     {
933         sal_uLong nSelPos = GetSelectEntryPos();
934         sal_uInt16 nCol = GetCurrentTabPos() - 1;
935         if ( nCol < 2 )
936         {
937             CheckEntryPos( nSelPos, nCol, !IsChecked( nSelPos, nCol ) );
938             CallImplEventListeners( VCLEVENT_CHECKBOX_TOGGLE, (void*)GetEntry( nSelPos ) );
939         }
940         else
941         {
942             sal_uInt16 nCheck = IsChecked(nSelPos, 1) ? 1 : 0;
943             if(IsChecked(nSelPos, 0))
944                 nCheck += 2;
945             nCheck--;
946             nCheck &= 3;
947             CheckEntryPos(nSelPos, 1, 0 != (nCheck & 1));
948             CheckEntryPos(nSelPos, 0, 0 != (nCheck & 2));
949         }
950     }
951     else
952         SvxSimpleTable::KeyInput(rKEvt);
953 }
954 /* -----------------19.11.98 15:57-------------------
955  *
956  * --------------------------------------------------*/
957 struct DoubleString
958 {
959 	String 	sShort;
960 	String 	sLong;
961 	void* 	pUserData; // CheckBox -> form. Text Bool -> Selektionstext
962 };
963 typedef DoubleString* DoubleStringPtr;
964 SV_DECL_PTRARR_DEL(DoubleStringArray, DoubleStringPtr, 4, 4)
965 SV_IMPL_PTRARR(DoubleStringArray, DoubleStringPtr);
966 
967 /* -----------------19.11.98 16:07-------------------
968  *
969  * --------------------------------------------------*/
970 void lcl_ClearTable(DoubleStringTable& rTable)
971 {
972 	DoubleStringArrayPtr pArray = rTable.Last();
973 	while(pArray)
974 	{
975 		pArray->DeleteAndDestroy(0, pArray->Count());
976 		delete pArray;
977 		pArray = rTable.Prev();
978 	}
979 	rTable.Clear();
980 }
981 
982 /*-----------------14.10.96 15.57-------------------
983 
984 --------------------------------------------------*/
985 
986 OfaAutocorrReplacePage::OfaAutocorrReplacePage( Window* pParent,
987 												const SfxItemSet& rSet ) :
988 	SfxTabPage(pParent, CUI_RES( RID_OFAPAGE_AUTOCORR_REPLACE ), rSet),
989     aTextOnlyCB(    this, CUI_RES(CB_TEXT_ONLY      )),
990     aShortFT  (     this, CUI_RES(FT_SHORT          )),
991 	aShortED  ( 	this, CUI_RES(ED_SHORT          )),
992 	aReplaceFT( 	this, CUI_RES(FT_REPLACE        )),
993 	aReplaceED( 	this, CUI_RES(ED_REPLACE        )),
994 	aReplaceTLB( 	this, CUI_RES(TLB_REPLACE       )),
995     aNewReplacePB(  this, CUI_RES(PB_NEW_REPLACE    )),
996 	aDeleteReplacePB(this,CUI_RES(PB_DELETE_REPLACE )),
997 	sModify(CUI_RES(STR_MODIFY)),
998 	sNew(aNewReplacePB.GetText()),
999     pFormatText(0),
1000     eLang(eLastDialogLanguage),
1001     bHasSelectionText(sal_False),
1002     bFirstSelect(sal_True),
1003 	bReplaceEditChanged(sal_False),
1004     bSWriter(sal_True)
1005 {
1006 	FreeResource();
1007 	SfxModule *pMod = *(SfxModule**)GetAppData(SHL_WRITER);
1008     bSWriter = pMod == SfxModule::GetActiveModule();
1009 
1010 	::com::sun::star::lang::Locale aLcl( SvxCreateLocale(eLastDialogLanguage ));
1011 	pCompareClass = new CollatorWrapper( GetProcessFact() );
1012     pCompareCaseClass = new CollatorWrapper( GetProcessFact() );
1013 	pCompareClass->loadDefaultCollator( aLcl, ::com::sun::star::i18n::
1014 							CollatorOptions::CollatorOptions_IGNORE_CASE );
1015     pCompareCaseClass->loadDefaultCollator( aLcl, 0 );
1016 	pCharClass = new CharClass( aLcl );
1017 
1018 	static long nTabs[] = { 2 /* Tab-Count */, 1, 61 };
1019 	aReplaceTLB.SetTabs( &nTabs[0], MAP_APPFONT );
1020 
1021 	aReplaceTLB.SetStyle(aReplaceTLB.GetStyle()|WB_HSCROLL|WB_CLIPCHILDREN);
1022 	aReplaceTLB.SetSelectHdl(LINK(this, OfaAutocorrReplacePage, SelectHdl));
1023 	aNewReplacePB.SetClickHdl( LINK(this, OfaAutocorrReplacePage, NewDelHdl));
1024 	aDeleteReplacePB.SetClickHdl(LINK(this, OfaAutocorrReplacePage, NewDelHdl));
1025 	aShortED.SetModifyHdl(LINK(this, OfaAutocorrReplacePage, ModifyHdl));
1026 	aReplaceED.SetModifyHdl(LINK(this, OfaAutocorrReplacePage, ModifyHdl));
1027 	aShortED.SetActionHdl(LINK(this, OfaAutocorrReplacePage, NewDelHdl));
1028 	aReplaceED.SetActionHdl(LINK(this, OfaAutocorrReplacePage, NewDelHdl));
1029 
1030 	aReplaceED.SetSpaces(sal_True);
1031 	aShortED.SetSpaces(sal_True);
1032 	aShortED.SetMaxTextLen(30);
1033 }
1034 
1035 /*-----------------14.10.96 15.58-------------------
1036 
1037 --------------------------------------------------*/
1038 
1039 
1040 OfaAutocorrReplacePage::~OfaAutocorrReplacePage()
1041 {
1042 	delete pFormatText;
1043 	lcl_ClearTable(aDoubleStringTable);
1044     delete pCompareClass;
1045     delete pCompareCaseClass;
1046     delete pCharClass;
1047 }
1048 /*-----------------14.10.96 15.58-------------------
1049 
1050 --------------------------------------------------*/
1051 
1052 SfxTabPage*	OfaAutocorrReplacePage::Create( Window* pParent,
1053 								const SfxItemSet& rSet)
1054 {
1055 	return new OfaAutocorrReplacePage(pParent, rSet);
1056 }
1057 /* -----------------20.11.98 13:26-------------------
1058  *
1059  * --------------------------------------------------*/
1060 void	OfaAutocorrReplacePage::ActivatePage( const SfxItemSet& )
1061 {
1062 	if(eLang != eLastDialogLanguage)
1063 		SetLanguage(eLastDialogLanguage);
1064 	((OfaAutoCorrDlg*)GetTabDialog())->EnableLanguage(sal_True);
1065 }
1066 /* -----------------20.11.98 13:26-------------------
1067  *
1068  * --------------------------------------------------*/
1069 int OfaAutocorrReplacePage::DeactivatePage( SfxItemSet*  )
1070 {
1071 	return LEAVE_PAGE;
1072 }
1073 /*-----------------14.10.96 15.58-------------------
1074 
1075 --------------------------------------------------*/
1076 
1077 sal_Bool OfaAutocorrReplacePage::FillItemSet( SfxItemSet& )
1078 {
1079     SvxAutoCorrect* pAutoCorrect = SvxAutoCorrCfg::Get()->GetAutoCorrect();
1080     DoubleStringArrayPtr pDoubleStringArray = aDoubleStringTable.Last();
1081 	while(pDoubleStringArray)
1082 	{
1083 		LanguageType eCurLang = (LanguageType)aDoubleStringTable.GetCurKey();
1084 		if(eCurLang != eLang) // die aktuelle Sprache wird weiter hinten behandelt
1085 		{
1086 			SvxAutocorrWordList* pWordList = pAutoCorrect->LoadAutocorrWordList(eCurLang);
1087 			sal_uInt16 nWordListCount = pWordList->Count();
1088 			sal_uInt16 nDoubleStringArrayCount = pDoubleStringArray->Count();
1089 			sal_uInt16 nPos = nDoubleStringArrayCount;
1090 			sal_uInt16 nLastPos = nPos;
1091 			// 1. Durchlauf: Eintraege loeschen oder veraendern:
1092 
1093 
1094 			for( sal_uInt16 nWordListPos = nWordListCount; nWordListPos; nWordListPos-- )
1095 			{
1096 				SvxAutocorrWordPtr pWordPtr = pWordList->GetObject(nWordListPos - 1);
1097 				String sEntry(pWordPtr->GetShort());
1098 				// formatierter Text steht nur im Writer
1099 				sal_Bool bFound = !bSWriter && !pWordPtr->IsTextOnly();
1100 				while(!bFound && nPos)
1101 				{
1102 					DoubleString* pDouble = pDoubleStringArray->GetObject( nPos - 1);
1103 
1104 					if( 0 == pCompareClass->compareString(
1105 													sEntry, pDouble->sShort ))
1106 					{
1107 						nLastPos = nPos - 1;
1108 						bFound = sal_True;
1109 						if( !(pWordPtr->IsTextOnly() == (0 == pDouble->pUserData)
1110                             && 0 == pCompareCaseClass->compareString(
1111 								pWordPtr->GetLong(), pDouble->sLong ) ) )
1112 						{
1113 							pAutoCorrect->PutText(sEntry, pDouble->sLong, eCurLang);
1114 						}
1115 						pDoubleStringArray->DeleteAndDestroy(nPos - 1, 1);
1116 						break;
1117 					}
1118 					nPos--;
1119 				}
1120 				nPos = nLastPos;
1121 				if(!bFound)
1122 				{
1123 					pAutoCorrect->DeleteText(sEntry, eCurLang);
1124 				}
1125 			}
1126 			nDoubleStringArrayCount = pDoubleStringArray->Count();
1127 			for(sal_uInt16 nDoubleStringArrayPos = 0; nDoubleStringArrayPos < nDoubleStringArrayCount; nDoubleStringArrayPos++ )
1128 			{
1129 				//jetzt sollte es nur noch neue Eintraege geben
1130 				DoubleString* pDouble = pDoubleStringArray->GetObject( nDoubleStringArrayPos );
1131 				if(pDouble->pUserData == &bHasSelectionText)
1132 					pAutoCorrect->PutText( pDouble->sShort,
1133 								*SfxObjectShell::Current(), eCurLang );
1134 				else
1135 				{
1136 					pAutoCorrect->PutText( pDouble->sShort, pDouble->sLong,
1137 															eCurLang);
1138 				}
1139 			}
1140 		}
1141 		pDoubleStringArray->DeleteAndDestroy(0, pDoubleStringArray->Count());
1142 		delete pDoubleStringArray;
1143 		pDoubleStringArray = aDoubleStringTable.Prev();
1144 	}
1145 	aDoubleStringTable.Clear();
1146 	// jetzt noch die aktuelle Selektion
1147 	SvxAutocorrWordList* pWordList = pAutoCorrect->LoadAutocorrWordList(eLang);
1148 	sal_uInt16 nWordListCount = pWordList->Count();
1149 	sal_uInt16 nListBoxCount = (sal_uInt16)aReplaceTLB.GetEntryCount();
1150 
1151 	aReplaceTLB.SetUpdateMode(sal_False);
1152 	sal_uInt16 nListBoxPos = nListBoxCount;
1153 	sal_uInt16 nLastListBoxPos = nListBoxPos;
1154 	// 1. Durchlauf: Eintraege loeschen oder veraendern:
1155 
1156 	sal_uInt16 i;
1157 	for( i = nWordListCount; i; i-- )
1158 	{
1159 		SvxAutocorrWordPtr pWordPtr = pWordList->GetObject(i- 1);
1160 		String sEntry(pWordPtr->GetShort());
1161 		// formatierter Text steht nur im Writer
1162 		sal_Bool bFound = !bSWriter && !pWordPtr->IsTextOnly();
1163 		while(!bFound && nListBoxPos)
1164 		{
1165 			SvLBoxEntry*  pEntry = aReplaceTLB.GetEntry( nListBoxPos - 1);
1166 			if( 0 == pCompareClass->compareString( sEntry,
1167 						aReplaceTLB.GetEntryText(pEntry, 0)))
1168 			{
1169 				nLastListBoxPos = nListBoxPos - 1;
1170 				bFound = sal_True;
1171 				String sLong = aReplaceTLB.GetEntryText(pEntry, 1);
1172 				if( !(pWordPtr->IsTextOnly() == (0 == pEntry->GetUserData())
1173                     && 0 == pCompareCaseClass->compareString(
1174 						pWordPtr->GetLong(), sLong )))
1175 				{
1176 					pAutoCorrect->PutText(sEntry, sLong, eLang);
1177 				}
1178 				aReplaceTLB.GetModel()->Remove(pEntry);
1179 				break;
1180 
1181 			}
1182 			nListBoxPos --;
1183 		}
1184 		nListBoxPos = nLastListBoxPos;
1185 		if(!bFound)
1186 		{
1187 			pAutoCorrect->DeleteText(sEntry, eLang);
1188 		}
1189 
1190 	}
1191 	nListBoxCount = (sal_uInt16)aReplaceTLB.GetEntryCount();
1192 	for(i = 0; i < nListBoxCount; i++ )
1193 	{
1194 		//jetzt sollte es nur noch neue Eintraege geben
1195 		SvLBoxEntry*  pEntry = aReplaceTLB.GetEntry( i );
1196 		String sShort = aReplaceTLB.GetEntryText(pEntry, 0);
1197 		if(pEntry->GetUserData() == &bHasSelectionText)
1198 			pAutoCorrect->PutText(sShort, *SfxObjectShell::Current(), eLang);
1199 		else
1200 		{
1201 			String sLong = aReplaceTLB.GetEntryText(pEntry, 1);
1202 			pAutoCorrect->PutText(sShort, sLong, eLang);
1203 		}
1204 	}
1205 
1206 	return sal_False;
1207 }
1208 
1209 /* -----------------19.11.98 13:16-------------------
1210  *
1211  * --------------------------------------------------*/
1212 void OfaAutocorrReplacePage::RefillReplaceBox(sal_Bool bFromReset,
1213 										LanguageType eOldLanguage,
1214 										LanguageType eNewLanguage)
1215 {
1216 	eLang = eNewLanguage;
1217 	if(bFromReset)
1218 		lcl_ClearTable(aDoubleStringTable);
1219 	else
1220 	{
1221 		DoubleStringArray* pArray = 0;
1222 		if(aDoubleStringTable.IsKeyValid(eOldLanguage))
1223 		{
1224 			pArray = aDoubleStringTable.Seek(sal_uLong(eOldLanguage));
1225 			pArray->DeleteAndDestroy(0, pArray->Count());
1226 		}
1227 		else
1228 		{
1229 			pArray = new DoubleStringArray;
1230 			aDoubleStringTable.Insert(sal_uLong(eOldLanguage), pArray);
1231 		}
1232 
1233 		sal_uInt16 nListBoxCount = (sal_uInt16)aReplaceTLB.GetEntryCount();
1234 		sal_uInt16 i;
1235 		for(i = 0; i < nListBoxCount; i++)
1236 		{
1237 			DoubleString* pDouble = new DoubleString();
1238 			SvLBoxEntry*  pEntry = aReplaceTLB.GetEntry( i );
1239 			pDouble->sShort = aReplaceTLB.GetEntryText(pEntry, 0);
1240 			pDouble->sLong = aReplaceTLB.GetEntryText(pEntry, 1);
1241 			pDouble->pUserData = pEntry->GetUserData();
1242 			pArray->Insert(pDouble, i);
1243 		}
1244 	}
1245 
1246 	aReplaceTLB.Clear();
1247 	if(!bSWriter)
1248 	{
1249 		if(pFormatText)
1250 			pFormatText->DeleteAndDestroy(0, pFormatText->Count());
1251 		else
1252 			pFormatText = new SvStringsISortDtor();
1253 	}
1254 
1255 	if(aDoubleStringTable.IsKeyValid(eLang))
1256 	{
1257 		DoubleStringArray* pArray = aDoubleStringTable.Seek(sal_uLong(eNewLanguage));
1258 		for(sal_uInt16 i = 0; i < pArray->Count(); i++)
1259 		{
1260 			DoubleString* pDouble = pArray->GetObject(i);
1261 			sal_Bool bTextOnly = 0 == pDouble->pUserData;
1262 			// formatierter Text wird nur im Writer angeboten
1263 			if(bSWriter || bTextOnly)
1264 			{
1265 				String sEntry(pDouble->sShort);
1266 				sEntry += '\t';
1267 				sEntry += pDouble->sLong;
1268 				SvLBoxEntry* pEntry = aReplaceTLB.InsertEntry(sEntry);
1269 				aTextOnlyCB.Check(bTextOnly);
1270 				if(!bTextOnly)
1271 					pEntry->SetUserData(pDouble->pUserData); // Das heisst: mit Formatinfo oder sogar mit Selektionstext
1272 			}
1273 			else
1274 			{
1275 				pFormatText->Insert(new String(pDouble->sShort));
1276 			}
1277 		}
1278 	}
1279 	else
1280 	{
1281         SvxAutoCorrect* pAutoCorrect = SvxAutoCorrCfg::Get()->GetAutoCorrect();
1282         SvxAutocorrWordList* pWordList = pAutoCorrect->LoadAutocorrWordList(eLang);
1283 
1284 		for(sal_uInt16 i = 0; i < pWordList->Count(); i++)
1285 		{
1286 			SvxAutocorrWordPtr pWordPtr = pWordList->GetObject(i);
1287 			sal_Bool bTextOnly = pWordPtr->IsTextOnly();
1288 			// formatierter Text wird nur im Writer angeboten
1289 			if(bSWriter || bTextOnly)
1290 			{
1291 				String sEntry(pWordPtr->GetShort());
1292 				sEntry += '\t';
1293 				sEntry += pWordPtr->GetLong();
1294 				SvLBoxEntry* pEntry = aReplaceTLB.InsertEntry(sEntry);
1295 				aTextOnlyCB.Check(pWordPtr->IsTextOnly());
1296 				if(!bTextOnly)
1297 					pEntry->SetUserData(&aTextOnlyCB); // Das heisst: mit Formatinfo
1298 			}
1299 			else
1300 			{
1301 				pFormatText->Insert(new String(pWordPtr->GetShort()));
1302 			}
1303 		}
1304 		aNewReplacePB.Enable(sal_False);
1305 		aDeleteReplacePB.Enable(sal_False);
1306 
1307 	}
1308 
1309 	SfxViewShell* pViewShell = SfxViewShell::Current();
1310 	if( pViewShell && pViewShell->HasSelection( sal_True ) )
1311 	{
1312 		bHasSelectionText = sal_True;
1313 		const String sSelection( pViewShell->GetSelectionText() );
1314 		aReplaceED.SetText( sSelection );
1315 		aTextOnlyCB.Check( !bSWriter );
1316 		aTextOnlyCB.Enable( bSWriter && sSelection.Len() );
1317 	}
1318 	else
1319 		aTextOnlyCB.Enable( sal_False );
1320 }
1321 /*-----------------14.10.96 15.58-------------------
1322 
1323 --------------------------------------------------*/
1324 
1325 void OfaAutocorrReplacePage::Reset( const SfxItemSet& )
1326 {
1327 	RefillReplaceBox(sal_True, eLang, eLang);
1328 	aShortED.GrabFocus();
1329 }
1330 
1331 /* -----------------23.11.98 10:33-------------------
1332  *
1333  * --------------------------------------------------*/
1334 void OfaAutocorrReplacePage::SetLanguage(LanguageType eSet)
1335 {
1336 	//save old settings an refill
1337 	if(eSet != eLang)
1338 	{
1339 		RefillReplaceBox(sal_False, eLang, eSet);
1340 		eLastDialogLanguage = eSet;
1341 		delete pCompareClass;
1342         delete pCompareCaseClass;
1343 		delete pCharClass;
1344 
1345 		::com::sun::star::lang::Locale aLcl( SvxCreateLocale(eLastDialogLanguage ));
1346 		pCompareClass = new CollatorWrapper( GetProcessFact() );
1347         pCompareCaseClass = new CollatorWrapper( GetProcessFact() );
1348         pCompareClass->loadDefaultCollator( aLcl, ::com::sun::star::i18n::
1349 								CollatorOptions::CollatorOptions_IGNORE_CASE );
1350         pCompareCaseClass->loadDefaultCollator( aLcl, 0 );
1351 		pCharClass = new CharClass( aLcl );
1352 		ModifyHdl(&aShortED);
1353 	}
1354 }
1355 /*-----------------14.10.96 15.58-------------------
1356 
1357 --------------------------------------------------*/
1358 
1359 
1360 IMPL_LINK(OfaAutocorrReplacePage, SelectHdl, SvTabListBox*, pBox)
1361 {
1362 	if(!bFirstSelect || !bHasSelectionText)
1363 	{
1364 		SvLBoxEntry* pEntry = pBox->FirstSelected();
1365 		String sTmpShort(pBox->GetEntryText(pEntry, 0));
1366 		// wird der Text ueber den ModifyHdl gesetzt, dann steht der Cursor sonst immer am Wortanfang,
1367 		// obwohl man gerade hier editiert
1368 		sal_Bool bSameContent = 0 == pCompareClass->compareString(
1369 				sTmpShort, aShortED.GetText() );
1370 		Selection aSel = aShortED.GetSelection();
1371 		if(aShortED.GetText() != sTmpShort)
1372 		{
1373 			aShortED.SetText(sTmpShort);
1374 			//war es nur eine andere Schreibweise, dann muss die Selektion auch wieder gesetzt werden
1375 			if(bSameContent)
1376 				aShortED.SetSelection(aSel);
1377 		}
1378 		aReplaceED.SetText(pBox->GetEntryText(pEntry, 1));
1379 		// mit UserData gibt es eine Formatinfo
1380 		aTextOnlyCB.Check(0 == pEntry->GetUserData());
1381 	}
1382 	else
1383 		bFirstSelect = sal_False;
1384 
1385 	aNewReplacePB.Enable(sal_False);
1386 	aDeleteReplacePB.Enable();
1387 	return 0;
1388 };
1389 
1390 /*-----------------14.10.96 15.58-------------------
1391 
1392 --------------------------------------------------*/
1393 
1394 
1395 IMPL_LINK(OfaAutocorrReplacePage, NewDelHdl, PushButton*, pBtn)
1396 {
1397     SvLBoxEntry* _pEntry = aReplaceTLB.FirstSelected();
1398 	if(pBtn == &aDeleteReplacePB)
1399 	{
1400         DBG_ASSERT(_pEntry, "keine Eintrag selektiert");
1401         if(_pEntry)
1402 		{
1403             aReplaceTLB.GetModel()->Remove(_pEntry);
1404 			ModifyHdl(&aShortED);
1405 			return 0;
1406 		}
1407 	}
1408 	if(pBtn == &aNewReplacePB || aNewReplacePB.IsEnabled())
1409 	{
1410         SvLBoxEntry* _pNewEntry = aReplaceTLB.FirstSelected();
1411 		String sEntry(aShortED.GetText());
1412 		if(sEntry.Len() && ( aReplaceED.GetText().Len() ||
1413 				( bHasSelectionText && bSWriter ) ))
1414 		{
1415 			aReplaceTLB.SetUpdateMode(sal_False);
1416 			sal_uInt16 nPos = USHRT_MAX;
1417 			sEntry += '\t';
1418 			sEntry += aReplaceED.GetText();
1419             if(_pNewEntry)
1420 			{
1421                 nPos = (sal_uInt16)aReplaceTLB.GetModel()->GetAbsPos(_pNewEntry);
1422                 aReplaceTLB.GetModel()->Remove(_pNewEntry);
1423 			}
1424 			else
1425 			{
1426 				sal_uInt16 j;
1427 				for( j = 0; j < aReplaceTLB.GetEntryCount(); j++ )
1428 				{
1429                     SvLBoxEntry* pReplaceEntry = aReplaceTLB.GetEntry(j);
1430 					if( 0 >=  pCompareClass->compareString(sEntry,
1431                                     aReplaceTLB.GetEntryText(pReplaceEntry, 0) ) )
1432 						break;
1433 				}
1434 				nPos = j;
1435 			}
1436 			SvLBoxEntry* pInsEntry =
1437                 aReplaceTLB.InsertEntry(
1438                     sEntry, static_cast< SvLBoxEntry * >(NULL), false,
1439                     nPos == USHRT_MAX ? LIST_APPEND : nPos);
1440 			if( !bReplaceEditChanged && !aTextOnlyCB.IsChecked())
1441 				pInsEntry->SetUserData(&bHasSelectionText); // neuer formatierter Text
1442 
1443 			aReplaceTLB.MakeVisible( pInsEntry );
1444 			aReplaceTLB.SetUpdateMode(sal_True);
1445 			// falls der Request aus dem ReplaceEdit kam, dann Focus in das ShortEdit setzen
1446 			if(aReplaceED.HasFocus())
1447 				aShortED.GrabFocus();
1448 
1449 		}
1450 	}
1451 	else
1452 	{
1453 		// das kann nur ein Enter in einem der beiden Edit-Felder sein und das
1454 		// bedeutet EndDialog() - muss im KeyInput ausgewertet werden
1455 		return 0;
1456 	}
1457 	ModifyHdl(&aShortED);
1458 	return 1;
1459 }
1460 
1461 /*-----------------17.10.96 07.49-------------------
1462 
1463 --------------------------------------------------*/
1464 IMPL_LINK(OfaAutocorrReplacePage, ModifyHdl, Edit*, pEdt)
1465 {
1466 	SvLBoxEntry* pFirstSel = aReplaceTLB.FirstSelected();
1467 	sal_Bool bShort = pEdt == &aShortED;
1468 	const String rEntry = pEdt->GetText();
1469 	const String rRepString = aReplaceED.GetText();
1470 	String aWordStr( pCharClass->lower( rEntry ));
1471 
1472 	if(bShort)
1473 	{
1474 		if(rEntry.Len())
1475 		{
1476 			sal_Bool bFound = sal_False;
1477 			sal_Bool bTmpSelEntry=sal_False;
1478 
1479 			for(sal_uInt16 i = 0; i < aReplaceTLB.GetEntryCount(); i++)
1480 			{
1481 				SvLBoxEntry*  pEntry = aReplaceTLB.GetEntry( i );
1482 				String aTestStr=aReplaceTLB.GetEntryText(pEntry, 0);
1483 				if( 0 == pCompareClass->compareString(rEntry, aTestStr ))
1484 				{
1485 					if(rRepString.Len())
1486 						bFirstSelect = sal_True;
1487 					aReplaceTLB.SetCurEntry(pEntry);
1488 					pFirstSel = pEntry;
1489 					aNewReplacePB.SetText(sModify);
1490 					bFound= sal_True;
1491 					break;
1492 				}
1493 				else
1494 				{
1495 					pCharClass->toLower( aTestStr );
1496 					if(aTestStr.Search(aWordStr)==0 && !bTmpSelEntry)
1497 					{
1498 						aReplaceTLB.MakeVisible(pEntry);
1499 						bTmpSelEntry=sal_True;
1500 					}
1501 				}
1502 			}
1503 			if(!bFound)
1504 			{
1505 				aReplaceTLB.SelectAll(sal_False);
1506 				pFirstSel = 0;
1507 				aNewReplacePB.SetText(sNew);
1508 				if(bReplaceEditChanged)
1509 					aTextOnlyCB.Enable(sal_False);
1510 			}
1511 			aDeleteReplacePB.Enable(bFound);
1512 		}
1513 		else if(aReplaceTLB.GetEntryCount()>0)
1514 		{
1515 			SvLBoxEntry*  pEntry = aReplaceTLB.GetEntry( 0 );
1516 			aReplaceTLB.MakeVisible(pEntry);
1517 		}
1518 
1519 	}
1520 	else if(!bShort)
1521 	{
1522 		bReplaceEditChanged = sal_True;
1523 		if(pFirstSel)
1524 		{
1525 			aNewReplacePB.SetText(sModify);
1526 		}
1527 	}
1528 
1529 	const String& rShortTxt = aShortED.GetText();
1530 	sal_Bool bEnableNew = rShortTxt.Len() &&
1531 						( rRepString.Len() ||
1532 								( bHasSelectionText && bSWriter )) &&
1533 						( !pFirstSel || rRepString !=
1534 								aReplaceTLB.GetEntryText( pFirstSel, 1 ) );
1535 	if(bEnableNew && pFormatText)
1536 	{
1537 		for(sal_uInt16 i = 0; i < pFormatText->Count(); i++)
1538 			if(*pFormatText->GetObject(i) == rShortTxt)
1539 			{
1540 				bEnableNew = sal_False;
1541 				break;
1542 			}
1543 	}
1544 	aNewReplacePB.Enable(bEnableNew);
1545 
1546 	return 0;
1547 }
1548 
1549 /* -----------------20.11.98 13:48-------------------
1550  *
1551  * --------------------------------------------------*/
1552 
1553 struct StringsArrays
1554 {
1555 
1556 	SvStringsDtor aAbbrevStrings;
1557 	SvStringsDtor aDoubleCapsStrings;
1558 
1559 	StringsArrays() :
1560 		aAbbrevStrings(5,5), aDoubleCapsStrings(5,5) {}
1561 };
1562 typedef StringsArrays* StringsArraysPtr;
1563 /* -----------------19.11.98 16:07-------------------
1564  *
1565  * --------------------------------------------------*/
1566 sal_Bool lcl_FindInArray(SvStringsDtor& rStrings, const String& rString)
1567 {
1568 	for(sal_uInt16 i = 0; i < rStrings.Count(); i++)
1569 		if(rString == *rStrings.GetObject(i))
1570 			return sal_True;
1571 	return sal_False;
1572 }
1573 
1574 void lcl_ClearTable(StringsTable& rTable)
1575 {
1576 	StringsArraysPtr pArrays = rTable.Last();
1577 	while(pArrays)
1578 	{
1579 		delete pArrays;
1580 		pArrays = rTable.Prev();
1581 	}
1582 	rTable.Clear();
1583 }
1584 
1585 /*-----------------14.10.96 15.57-------------------
1586 
1587 --------------------------------------------------*/
1588 
1589 OfaAutocorrExceptPage::OfaAutocorrExceptPage( Window* pParent,
1590 												const SfxItemSet& rSet ) :
1591 	SfxTabPage(pParent, CUI_RES( RID_OFAPAGE_AUTOCORR_EXCEPT ), rSet),
1592 	aAbbrevFL    	(this, CUI_RES(FL_ABBREV		 )),
1593 	aAbbrevED       (this, CUI_RES(ED_ABBREV		 )),
1594 	aAbbrevLB    	(this, CUI_RES(LB_ABBREV		 )),
1595 	aNewAbbrevPB    (this, CUI_RES(PB_NEWABBREV	 )),
1596 	aDelAbbrevPB    (this, CUI_RES(PB_DELABBREV	 )),
1597 	aAutoAbbrevCB   (this, CUI_RES(CB_AUTOABBREV	 )),
1598 	aDoubleCapsFL   (this, CUI_RES(FL_DOUBLECAPS	 )),
1599 	aDoubleCapsED   (this, CUI_RES(ED_DOUBLE_CAPS	 )),
1600 	aDoubleCapsLB   (this, CUI_RES(LB_DOUBLE_CAPS	 )),
1601 	aNewDoublePB    (this, CUI_RES(PB_NEWDOUBLECAPS)),
1602 	aDelDoublePB 	(this, CUI_RES(PB_DELDOUBLECAPS)),
1603 	aAutoCapsCB   	(this, CUI_RES(CB_AUTOCAPS	 )),
1604     eLang(eLastDialogLanguage)
1605 {
1606 	aNewAbbrevPB.SetAccessibleName(String(CUI_RES(STR_PB_NEWABBREV) ) );
1607 	aDelAbbrevPB.SetAccessibleName(String(CUI_RES(STR_PB_DELABBREV) ) );
1608 	aNewDoublePB.SetAccessibleName(String(CUI_RES(STR_PB_NEWDOUBLECAPS) ) );
1609 	aDelDoublePB.SetAccessibleName(String(CUI_RES(STR_PB_DELDOUBLECAPS) ) );
1610 
1611 	FreeResource();
1612 
1613 	::com::sun::star::lang::Locale aLcl( SvxCreateLocale(eLastDialogLanguage ));
1614 	pCompareClass = new CollatorWrapper( GetProcessFact() );
1615 	pCompareClass->loadDefaultCollator( aLcl, ::com::sun::star::i18n::
1616 							CollatorOptions::CollatorOptions_IGNORE_CASE );
1617 
1618 	aNewAbbrevPB.SetClickHdl(LINK(this, OfaAutocorrExceptPage, NewDelHdl));
1619 	aDelAbbrevPB.SetClickHdl(LINK(this, OfaAutocorrExceptPage, NewDelHdl));
1620 	aNewDoublePB.SetClickHdl(LINK(this, OfaAutocorrExceptPage, NewDelHdl));
1621 	aDelDoublePB.SetClickHdl(LINK(this, OfaAutocorrExceptPage, NewDelHdl));
1622 
1623 	aAbbrevLB.SetSelectHdl(LINK(this, OfaAutocorrExceptPage, SelectHdl));
1624 	aDoubleCapsLB.SetSelectHdl(LINK(this, OfaAutocorrExceptPage, SelectHdl));
1625 	aAbbrevED.SetModifyHdl(LINK(this, OfaAutocorrExceptPage, ModifyHdl));
1626 	aDoubleCapsED.SetModifyHdl(LINK(this, OfaAutocorrExceptPage, ModifyHdl));
1627 
1628 	aAbbrevED.SetActionHdl(LINK(this, OfaAutocorrExceptPage, NewDelHdl));
1629 	aDoubleCapsED.SetActionHdl(LINK(this, OfaAutocorrExceptPage, NewDelHdl));
1630 
1631 	aNewAbbrevPB.SetAccessibleRelationMemberOf(&aAbbrevFL);
1632 	aDelAbbrevPB.SetAccessibleRelationMemberOf(&aAbbrevFL);
1633 	aNewDoublePB.SetAccessibleRelationMemberOf(&aDoubleCapsFL);
1634 	aDelDoublePB.SetAccessibleRelationMemberOf(&aDoubleCapsFL);
1635 }
1636 
1637 /*-----------------14.10.96 15.58-------------------
1638 
1639 --------------------------------------------------*/
1640 
1641 OfaAutocorrExceptPage::~OfaAutocorrExceptPage()
1642 {
1643 	lcl_ClearTable(aStringsTable);
1644 	delete pCompareClass;
1645 }
1646 
1647 /*-----------------14.10.96 15.58-------------------
1648 
1649 --------------------------------------------------*/
1650 
1651 SfxTabPage*	OfaAutocorrExceptPage::Create( Window* pParent,
1652 								const SfxItemSet& rSet)
1653 {
1654 	return new OfaAutocorrExceptPage(pParent, rSet);
1655 }
1656 /* -----------------20.11.98 13:26-------------------
1657  *
1658  * --------------------------------------------------*/
1659 void	OfaAutocorrExceptPage::ActivatePage( const SfxItemSet& )
1660 {
1661 	if(eLang != eLastDialogLanguage)
1662 		SetLanguage(eLastDialogLanguage);
1663 	((OfaAutoCorrDlg*)GetTabDialog())->EnableLanguage(sal_True);
1664 }
1665 /* -----------------20.11.98 13:26-------------------
1666  *
1667  * --------------------------------------------------*/
1668 int     OfaAutocorrExceptPage::DeactivatePage( SfxItemSet* )
1669 {
1670 	return LEAVE_PAGE;
1671 }
1672 /*-----------------14.10.96 15.58-------------------
1673 
1674 --------------------------------------------------*/
1675 
1676 sal_Bool OfaAutocorrExceptPage::FillItemSet( SfxItemSet&  )
1677 {
1678     SvxAutoCorrect* pAutoCorrect = SvxAutoCorrCfg::Get()->GetAutoCorrect();
1679     StringsArraysPtr pArrays = aStringsTable.Last();
1680 	while(pArrays)
1681 	{
1682 		LanguageType eCurLang = (LanguageType)aStringsTable.GetCurKey();
1683 		if(eCurLang != eLang) // die aktuelle Sprache wird weiter hinten behandelt
1684 		{
1685 			SvStringsISortDtor* pWrdList = pAutoCorrect->LoadWrdSttExceptList(eCurLang);
1686 
1687 			if(pWrdList)
1688 			{
1689 				sal_uInt16 nCount = pWrdList->Count();
1690 				sal_uInt16 i;
1691 				for( i = nCount; i; )
1692 				{
1693 					String* pString = pWrdList->GetObject( --i );
1694 					//Eintrag finden u. gfs entfernen
1695 					if( !lcl_FindInArray(pArrays->aDoubleCapsStrings, *pString))
1696 					  pWrdList->DeleteAndDestroy( i );
1697 				}
1698 				nCount = pArrays->aDoubleCapsStrings.Count();
1699 				for( i = 0; i < nCount; ++i )
1700 				{
1701 					String* pEntry = new String( *pArrays->aDoubleCapsStrings.GetObject( i ) );
1702 					if( !pWrdList->Insert( pEntry ))
1703 						delete pEntry;
1704 				}
1705 				pAutoCorrect->SaveWrdSttExceptList(eCurLang);
1706 			}
1707 
1708 			SvStringsISortDtor* pCplList = pAutoCorrect->LoadCplSttExceptList(eCurLang);
1709 
1710 			if(pCplList)
1711 			{
1712 				sal_uInt16 nCount = pCplList->Count();
1713 				sal_uInt16 i;
1714 				for( i = nCount; i; )
1715 				{
1716 					String* pString = pCplList->GetObject( --i );
1717 					if( !lcl_FindInArray(pArrays->aAbbrevStrings, *pString))
1718 						pCplList->DeleteAndDestroy( i );
1719 				}
1720 				nCount = pArrays->aAbbrevStrings.Count();
1721 				for( i = 0; i < nCount; ++i )
1722 				{
1723 					String* pEntry = new String( *pArrays->aAbbrevStrings.GetObject(i) );
1724 					if( !pCplList->Insert( pEntry ))
1725 						delete pEntry;
1726 				}
1727 				pAutoCorrect->SaveCplSttExceptList(eCurLang);
1728 			}
1729 		}
1730 		pArrays = aStringsTable.Prev();
1731 	}
1732 	aStringsTable.Clear();
1733 
1734 	SvStringsISortDtor* pWrdList = pAutoCorrect->LoadWrdSttExceptList(eLang);
1735 
1736 	if(pWrdList)
1737 	{
1738 		sal_uInt16 nCount = pWrdList->Count();
1739 		sal_uInt16 i;
1740 		for( i = nCount; i; )
1741 		{
1742 			String* pString = pWrdList->GetObject( --i );
1743 			if( USHRT_MAX == aDoubleCapsLB.GetEntryPos(*pString) )
1744 				pWrdList->DeleteAndDestroy( i );
1745 		}
1746 		nCount = aDoubleCapsLB.GetEntryCount();
1747 		for( i = 0; i < nCount; ++i )
1748 		{
1749 			String* pEntry = new String( aDoubleCapsLB.GetEntry( i ) );
1750 			if( !pWrdList->Insert( pEntry ))
1751 				delete pEntry;
1752 		}
1753 		pAutoCorrect->SaveWrdSttExceptList(eLang);
1754 	}
1755 
1756 	SvStringsISortDtor* pCplList = pAutoCorrect->LoadCplSttExceptList(eLang);
1757 
1758 	if(pCplList)
1759 	{
1760 		sal_uInt16 nCount = pCplList->Count();
1761 		sal_uInt16 i;
1762 		for( i = nCount; i; )
1763 		{
1764 			String* pString = pCplList->GetObject( --i );
1765 			if( USHRT_MAX == aAbbrevLB.GetEntryPos(*pString) )
1766 				pCplList->DeleteAndDestroy( i );
1767 		}
1768 		nCount = aAbbrevLB.GetEntryCount();
1769 		for( i = 0; i < nCount; ++i )
1770 		{
1771 			String* pEntry = new String( aAbbrevLB.GetEntry( i ) );
1772 			if( !pCplList->Insert( pEntry ))
1773 				delete pEntry;
1774 		}
1775 		pAutoCorrect->SaveCplSttExceptList(eLang);
1776 	}
1777 	if(aAutoAbbrevCB.IsChecked() != aAutoAbbrevCB.GetSavedValue())
1778 		pAutoCorrect->SetAutoCorrFlag( SaveWordCplSttLst, aAutoAbbrevCB.IsChecked());
1779 	if(aAutoCapsCB.IsChecked() != aAutoCapsCB.GetSavedValue())
1780 		pAutoCorrect->SetAutoCorrFlag( SaveWordWrdSttLst, aAutoCapsCB.IsChecked());
1781 	return sal_False;
1782 }
1783 
1784 /* -----------------23.11.98 10:33-------------------
1785  *
1786  * --------------------------------------------------*/
1787 void OfaAutocorrExceptPage::SetLanguage(LanguageType eSet)
1788 {
1789 	if(eLang != eSet)
1790 	{
1791 		//alte Einstellungen speichern und neu fuellen
1792 		RefillReplaceBoxes(sal_False, eLang, eSet);
1793 		eLastDialogLanguage = eSet;
1794 		delete pCompareClass;
1795 		pCompareClass = new CollatorWrapper( GetProcessFact() );
1796 		pCompareClass->loadDefaultCollator( SvxCreateLocale( eLastDialogLanguage ),
1797 						::com::sun::star::i18n::
1798 							CollatorOptions::CollatorOptions_IGNORE_CASE );
1799 		ModifyHdl(&aAbbrevED);
1800 		ModifyHdl(&aDoubleCapsED);
1801 	}
1802 }
1803 /* -----------------20.11.98 14:06-------------------
1804  *
1805  * --------------------------------------------------*/
1806 void OfaAutocorrExceptPage::RefillReplaceBoxes(sal_Bool bFromReset,
1807 										LanguageType eOldLanguage,
1808 										LanguageType eNewLanguage)
1809 {
1810 	eLang = eNewLanguage;
1811 	if(bFromReset)
1812 		lcl_ClearTable(aStringsTable);
1813 	else
1814 	{
1815 		StringsArraysPtr pArrays = 0;
1816 		if(aStringsTable.IsKeyValid(eOldLanguage))
1817 		{
1818 			pArrays = aStringsTable.Seek(sal_uLong(eOldLanguage));
1819 			pArrays->aAbbrevStrings.DeleteAndDestroy(
1820 									0, pArrays->aAbbrevStrings.Count());
1821 			pArrays->aDoubleCapsStrings.DeleteAndDestroy(
1822 									0, pArrays->aDoubleCapsStrings.Count());
1823 		}
1824 		else
1825 		{
1826 			pArrays = new StringsArrays;
1827 			aStringsTable.Insert(sal_uLong(eOldLanguage), pArrays);
1828 		}
1829 
1830 		sal_uInt16 i;
1831 		for(i = 0; i < aAbbrevLB.GetEntryCount(); i++)
1832 		{
1833 			pArrays->aAbbrevStrings.Insert(
1834 				new String(aAbbrevLB.GetEntry(i)), i);
1835 
1836 		}
1837 		for(i = 0; i < aDoubleCapsLB.GetEntryCount(); i++)
1838 		{
1839 			pArrays->aDoubleCapsStrings.Insert(
1840 				new String(aDoubleCapsLB.GetEntry(i)), i);
1841 		}
1842 	}
1843 	aDoubleCapsLB.Clear();
1844 	aAbbrevLB.Clear();
1845 	String sTemp;
1846 	aAbbrevED.SetText(sTemp);
1847 	aDoubleCapsED.SetText(sTemp);
1848 
1849 	if(aStringsTable.IsKeyValid(eLang))
1850 	{
1851 		StringsArraysPtr pArrays = aStringsTable.Seek(sal_uLong(eLang));
1852 		sal_uInt16 i;
1853 		for(i = 0; i < pArrays->aAbbrevStrings.Count(); i++ )
1854 		{
1855 			aAbbrevLB.InsertEntry(*pArrays->aAbbrevStrings.GetObject(i));
1856 		}
1857 		for( i = 0; i < pArrays->aDoubleCapsStrings.Count(); i++ )
1858 		{
1859 			aDoubleCapsLB.InsertEntry(*pArrays->aDoubleCapsStrings.GetObject(i));
1860 		}
1861 	}
1862 	else
1863 	{
1864         SvxAutoCorrect* pAutoCorrect = SvxAutoCorrCfg::Get()->GetAutoCorrect();
1865         const SvStringsISortDtor* pCplList = pAutoCorrect->GetCplSttExceptList(eLang);
1866 		const SvStringsISortDtor* pWrdList = pAutoCorrect->GetWrdSttExceptList(eLang);
1867 		sal_uInt16 i;
1868 		for( i = 0; i < pCplList->Count(); i++ )
1869 		{
1870 			aAbbrevLB.InsertEntry(*pCplList->GetObject(i));
1871 		}
1872 		for( i = 0; i < pWrdList->Count(); i++ )
1873 		{
1874 			aDoubleCapsLB.InsertEntry(*pWrdList->GetObject(i));
1875 		}
1876 	}
1877 }
1878 
1879 /*-----------------14.10.96 15.58-------------------
1880 
1881 --------------------------------------------------*/
1882 
1883 void OfaAutocorrExceptPage::Reset( const SfxItemSet& )
1884 {
1885     SvxAutoCorrect* pAutoCorrect = SvxAutoCorrCfg::Get()->GetAutoCorrect();
1886     RefillReplaceBoxes(sal_True, eLang, eLang);
1887 	aAutoAbbrevCB.	Check(	pAutoCorrect->IsAutoCorrFlag( SaveWordCplSttLst ));
1888 	aAutoCapsCB.	Check(	pAutoCorrect->IsAutoCorrFlag( SaveWordWrdSttLst ));
1889 	aAutoAbbrevCB.SaveValue();
1890 	aAutoCapsCB.SaveValue();
1891 }
1892 
1893 /*-----------------16.10.96 12.27-------------------
1894 
1895 --------------------------------------------------*/
1896 
1897 
1898 IMPL_LINK(OfaAutocorrExceptPage, NewDelHdl, PushButton*, pBtn)
1899 {
1900 	if((pBtn == &aNewAbbrevPB || pBtn == (PushButton*)&aAbbrevED )
1901 		&& aAbbrevED.GetText().Len())
1902 	{
1903 		aAbbrevLB.InsertEntry(aAbbrevED.GetText());
1904 		ModifyHdl(&aAbbrevED);
1905 	}
1906 	else if(pBtn == &aDelAbbrevPB)
1907 	{
1908 		aAbbrevLB.RemoveEntry(aAbbrevED.GetText());
1909 		ModifyHdl(&aAbbrevED);
1910 	}
1911 	else if((pBtn == &aNewDoublePB || pBtn == (PushButton*)&aDoubleCapsED )
1912 			&& aDoubleCapsED.GetText().Len())
1913 	{
1914 		aDoubleCapsLB.InsertEntry(aDoubleCapsED.GetText());
1915 		ModifyHdl(&aDoubleCapsED);
1916 	}
1917 	else if(pBtn == &aDelDoublePB)
1918 	{
1919 		aDoubleCapsLB.RemoveEntry(aDoubleCapsED.GetText());
1920 		ModifyHdl(&aDoubleCapsED);
1921 	}
1922 	return 0;
1923 }
1924 
1925 /*-----------------16.10.96 12.57-------------------
1926 
1927 --------------------------------------------------*/
1928 
1929 IMPL_LINK(OfaAutocorrExceptPage, SelectHdl, ListBox*, pBox)
1930 {
1931 	if(pBox == &aAbbrevLB)
1932 	{
1933 		aAbbrevED.SetText(pBox->GetSelectEntry());
1934 		aNewAbbrevPB.Enable(sal_False);
1935 		aDelAbbrevPB.Enable();
1936 	}
1937 	else
1938 	{
1939 		aDoubleCapsED.SetText(pBox->GetSelectEntry());
1940 		aNewDoublePB.Enable(sal_False);
1941 		aDelDoublePB.Enable();
1942 	}
1943 	return 0;
1944 }
1945 
1946 /*-----------------16.10.96 13.02-------------------
1947 
1948 --------------------------------------------------*/
1949 
1950 IMPL_LINK(OfaAutocorrExceptPage, ModifyHdl, Edit*, pEdt)
1951 {
1952 //	sal_Bool bSame = pEdt->GetText() == ->GetSelectEntry();
1953 	const String& sEntry = pEdt->GetText();
1954 	sal_Bool bEntryLen = 0!= sEntry.Len();
1955 	if(pEdt == &aAbbrevED)
1956 	{
1957 		sal_Bool bSame = lcl_FindEntry(aAbbrevLB, sEntry, *pCompareClass);
1958 		if(bSame && sEntry != aAbbrevLB.GetSelectEntry())
1959 			pEdt->SetText(aAbbrevLB.GetSelectEntry());
1960 		aNewAbbrevPB.Enable(!bSame && bEntryLen);
1961 		aDelAbbrevPB.Enable(bSame && bEntryLen);
1962 	}
1963 	else
1964 	{
1965 		sal_Bool bSame = lcl_FindEntry(aDoubleCapsLB, sEntry, *pCompareClass);
1966 		if(bSame && sEntry != aDoubleCapsLB.GetSelectEntry())
1967 			pEdt->SetText(aDoubleCapsLB.GetSelectEntry());
1968 		aNewDoublePB.Enable(!bSame && bEntryLen);
1969 		aDelDoublePB.Enable(bSame && bEntryLen);
1970 	}
1971 	return 0;
1972 }
1973 
1974 /*-----------------16.10.96 15.03-------------------
1975 
1976 --------------------------------------------------*/
1977 
1978 void AutoCorrEdit::KeyInput( const KeyEvent& rKEvt )
1979 {
1980 	const KeyCode aKeyCode = rKEvt.GetKeyCode();
1981 	const sal_uInt16 nModifier = aKeyCode.GetModifier();
1982 	if( aKeyCode.GetCode() == KEY_RETURN )
1983 	{
1984 		//wird bei Enter nichts getan, dann doch die Basisklasse rufen
1985 		// um den Dialog zu schliessen
1986 		if(!nModifier && !aActionLink.Call(this))
1987 				 Edit::KeyInput(rKEvt);
1988 	}
1989 	else if(bSpaces || aKeyCode.GetCode() != KEY_SPACE)
1990 		Edit::KeyInput(rKEvt);
1991 }
1992 
1993 /*-----------------03.07.97 13:17-------------------
1994 
1995 --------------------------------------------------*/
1996 
1997 enum OfaQuoteOptions
1998 {
1999     ADD_NONBRK_SPACE,
2000 	REPLACE_1ST
2001 };
2002 
2003 SvLBoxEntry* OfaQuoteTabPage::CreateEntry(String& rTxt, sal_uInt16 nCol)
2004 {
2005 	SvLBoxEntry* pEntry = new SvLBoxEntry;
2006 
2007     if ( !pCheckButtonData )
2008 	{
2009 		pCheckButtonData = new SvLBoxButtonData( &aSwCheckLB );
2010 		aSwCheckLB.SetCheckButtonData( pCheckButtonData );
2011 	}
2012 
2013 	pEntry->AddItem( new SvLBoxContextBmp( pEntry, 0, Image(), Image(), 0));	// Sonst Puff!
2014 
2015 	String sEmpty;
2016 	if (nCol == CBCOL_SECOND)
2017 		pEntry->AddItem( new SvLBoxString( pEntry, 0, sEmpty) );	// Leerspalte
2018 	else
2019 		pEntry->AddItem( new SvLBoxButton( pEntry, SvLBoxButtonKind_enabledCheckbox, 0, pCheckButtonData ) );
2020 
2021 	if (nCol == CBCOL_FIRST)
2022 		pEntry->AddItem( new SvLBoxString( pEntry, 0, sEmpty) );	// Leerspalte
2023 	else
2024 		pEntry->AddItem( new SvLBoxButton( pEntry, SvLBoxButtonKind_enabledCheckbox, 0, pCheckButtonData ) );
2025 
2026 	pEntry->AddItem( new OfaImpBrwString( pEntry, 0, rTxt ) );
2027 
2028 	return pEntry;
2029 }
2030 
2031 OfaQuoteTabPage::OfaQuoteTabPage( Window* pParent, const SfxItemSet& rSet ) :
2032 	SfxTabPage(pParent, CUI_RES( RID_OFAPAGE_AUTOCORR_QUOTE ), rSet),
2033 	aCheckLB			(this, CUI_RES(CLB_SETTINGS     )),
2034 	aSwCheckLB			(this, CUI_RES(CLB_SETTINGS     )),
2035 	sHeader1			(CUI_RES( STR_HEADER1		    )),
2036 	sHeader2			(CUI_RES( STR_HEADER2		    )),
2037     sNonBrkSpace		(CUI_RES( ST_NON_BREAK_SPACE    )),
2038 	sOrdinal			(CUI_RES( ST_ORDINAL            )),
2039     pCheckButtonData    ( NULL ),
2040 
2041 	aSingleFL           (this, CUI_RES(FL_SINGLE		 )),
2042     aSingleTypoCB       (this, CUI_RES(CB_SGL_TYPO     )),
2043     aSglStartQuoteFT    (this, CUI_RES(FT_SGL_STARTQUOTE )),
2044     aSglStartQuotePB    (this, CUI_RES(PB_SGL_STARTQUOTE )),
2045     aSglStartExFT       (this, CUI_RES(FT_SGSTEX       )),
2046     aSglEndQuoteFT      (this, CUI_RES(FT_SGL_ENDQUOTE   )),
2047     aSglEndQuotePB      (this, CUI_RES(PB_SGL_ENDQUOTE   )),
2048     aSglEndExFT         (this, CUI_RES(FT_SGENEX       )),
2049     aSglStandardPB      (this, CUI_RES(PB_SGL_STD      )),
2050 
2051     aDoubleFL           (this, CUI_RES(FL_DOUBLE       )),
2052     aTypoCB             (this, CUI_RES(CB_TYPO         )),
2053     aStartQuoteFT       (this, CUI_RES(FT_STARTQUOTE   )),
2054     aStartQuotePB       (this, CUI_RES(PB_STARTQUOTE   )),
2055     aDblStartExFT       (this, CUI_RES(FT_DBSTEX       )),
2056     aEndQuoteFT         (this, CUI_RES(FT_ENDQUOTE     )),
2057 	aEndQuotePB    		(this, CUI_RES(PB_ENDQUOTE     )),
2058     aDblEndExFT         (this, CUI_RES(FT_DBECEX       )),
2059     aDblStandardPB      (this, CUI_RES(PB_DBL_STD      )),
2060 
2061     sStartQuoteDlg  (CUI_RES(STR_CHANGE_START)),
2062     sEndQuoteDlg    (CUI_RES(STR_CHANGE_END)),
2063 
2064     sStandard(CUI_RES(ST_STANDARD))
2065 {
2066 	aSglStandardPB.SetAccessibleName(String(CUI_RES(STR_PB_SGL_STD) ) );
2067 	aDblStandardPB.SetAccessibleName(String(CUI_RES(STR_PB_DBL_STD) ) );
2068 	aStartQuotePB.SetAccessibleName( String(CUI_RES(STR_PB_DBL_START) ));
2069 	aEndQuotePB.SetAccessibleName(String(CUI_RES(STR_PB_DBL_END) ));
2070 	aSglStartQuotePB.SetAccessibleName(String(CUI_RES(STR_PB_SGL_START) ));
2071 	aSglEndQuotePB.SetAccessibleName(String(CUI_RES(STR_PB_SGL_END) ) );
2072 
2073 	FreeResource();
2074 
2075     sal_Bool bShowSWOptions = sal_False;
2076 
2077     aCheckLB.SetHelpId( HID_OFAPAGE_QUOTE_CLB );
2078     aSwCheckLB.SetHelpId( HID_OFAPAGE_QUOTE_SW_CLB );
2079 
2080     SFX_ITEMSET_ARG( &rSet, pItem, SfxBoolItem, SID_AUTO_CORRECT_DLG, sal_False );
2081     if ( pItem && pItem->GetValue() )
2082 	    bShowSWOptions = sal_True;
2083 
2084     if ( bShowSWOptions )
2085     {
2086     	static long aStaticTabs[]=
2087 	    {
2088 		    3, 0, 20, 40
2089     	};
2090 
2091     	aSwCheckLB.SetStyle(aSwCheckLB.GetStyle() | WB_HSCROLL| WB_VSCROLL);
2092 
2093     	aSwCheckLB.SvxSimpleTable::SetTabs(aStaticTabs);
2094 	    String sHeader( sHeader1 );
2095     	sHeader += '\t';
2096 	    sHeader += sHeader2;
2097     	sHeader += '\t';
2098 	    aSwCheckLB.InsertHeaderEntry( sHeader, HEADERBAR_APPEND,
2099 						HIB_CENTER | HIB_VCENTER | HIB_FIXEDPOS | HIB_FIXED);
2100         aCheckLB.Hide( sal_True );
2101     }
2102     else
2103     {
2104         aSwCheckLB.HideTable( );
2105     }
2106 
2107 	aStartQuotePB.SetClickHdl(LINK(this, 	OfaQuoteTabPage, QuoteHdl));
2108 	aEndQuotePB.SetClickHdl(LINK(this, 		OfaQuoteTabPage, QuoteHdl));
2109 	aSglStartQuotePB.SetClickHdl(LINK(this, OfaQuoteTabPage, QuoteHdl));
2110 	aSglEndQuotePB.SetClickHdl(LINK(this, 	OfaQuoteTabPage, QuoteHdl));
2111 	aDblStandardPB.SetClickHdl(LINK(this, 	OfaQuoteTabPage, StdQuoteHdl));
2112 	aSglStandardPB.SetClickHdl(LINK(this, 	OfaQuoteTabPage, StdQuoteHdl));
2113 
2114 	aSglStartQuotePB.SetAccessibleRelationLabeledBy( &aSglStartQuoteFT );
2115 	aSglEndQuotePB.SetAccessibleRelationLabeledBy( &aSglEndQuoteFT );
2116 	aSglStartQuotePB.SetAccessibleRelationMemberOf( &aSingleFL );
2117 	aSglEndQuotePB.SetAccessibleRelationMemberOf( &aSingleFL );
2118 	aStartQuotePB.SetAccessibleRelationLabeledBy( &aStartQuoteFT );
2119 	aEndQuotePB.SetAccessibleRelationLabeledBy( &aEndQuoteFT );
2120 	aStartQuotePB.SetAccessibleRelationMemberOf( &aDoubleFL );
2121 	aEndQuotePB.SetAccessibleRelationMemberOf( &aDoubleFL );
2122 	aSglStandardPB.SetAccessibleRelationMemberOf(&aSingleFL);
2123 	aDblStandardPB.SetAccessibleRelationMemberOf(&aDoubleFL);
2124 }
2125 /*-----------------03.07.97 13:17-------------------
2126 
2127 --------------------------------------------------*/
2128 OfaQuoteTabPage::~OfaQuoteTabPage()
2129 {
2130     delete( pCheckButtonData );
2131 }
2132 /*-----------------03.07.97 13:17-------------------
2133 
2134 --------------------------------------------------*/
2135 SfxTabPage*	OfaQuoteTabPage::Create( Window* pParent,
2136 								const SfxItemSet& rAttrSet)
2137 {
2138 	return new OfaQuoteTabPage(pParent, rAttrSet);
2139 }
2140 /*-----------------03.07.97 13:18-------------------
2141 
2142 --------------------------------------------------*/
2143 sal_Bool OfaQuoteTabPage::FillItemSet( SfxItemSet&  )
2144 {
2145 	SvxAutoCorrect* pAutoCorrect = SvxAutoCorrCfg::Get()->GetAutoCorrect();
2146 
2147 	long nFlags = pAutoCorrect->GetFlags();
2148 
2149     if ( aCheckLB.IsVisible( ) )
2150     {
2151 	    sal_uInt16 nPos = 0;
2152         pAutoCorrect->SetAutoCorrFlag(AddNonBrkSpace,		aCheckLB.IsChecked(nPos++));
2153 	    pAutoCorrect->SetAutoCorrFlag(ChgOrdinalNumber,		aCheckLB.IsChecked(nPos++));
2154     }
2155 
2156     sal_Bool bModified = sal_False;
2157     if ( aSwCheckLB.IsVisible( ) )
2158     {
2159 	    SvxSwAutoFmtFlags *pOpt = &pAutoCorrect->GetSwFlags();
2160 
2161         sal_Bool bCheck = aSwCheckLB.IsChecked(ADD_NONBRK_SPACE, CBCOL_FIRST);
2162 	    bModified |= pOpt->bAddNonBrkSpace != bCheck;
2163         pOpt->bAddNonBrkSpace = bCheck;
2164         pAutoCorrect->SetAutoCorrFlag(AddNonBrkSpace,
2165                             aSwCheckLB.IsChecked(ADD_NONBRK_SPACE, CBCOL_SECOND));
2166 
2167     	bCheck = aSwCheckLB.IsChecked(REPLACE_1ST, CBCOL_FIRST);
2168 	    bModified |= pOpt->bChgOrdinalNumber != bCheck;
2169     	pOpt->bChgOrdinalNumber = bCheck;
2170 	    pAutoCorrect->SetAutoCorrFlag(ChgOrdinalNumber,
2171 						aSwCheckLB.IsChecked(REPLACE_1ST, CBCOL_SECOND));
2172     }
2173 
2174 	pAutoCorrect->SetAutoCorrFlag(ChgQuotes, 		aTypoCB.IsChecked());
2175 	pAutoCorrect->SetAutoCorrFlag(ChgSglQuotes, 	aSingleTypoCB.IsChecked());
2176 	sal_Bool bReturn = nFlags != pAutoCorrect->GetFlags();
2177 	if(cStartQuote != pAutoCorrect->GetStartDoubleQuote())
2178 	{
2179 		bReturn = sal_True;
2180 		sal_Unicode cUCS2 = static_cast<sal_Unicode>(cStartQuote); //TODO
2181 		pAutoCorrect->SetStartDoubleQuote(cUCS2);
2182 	}
2183 	if(cEndQuote != pAutoCorrect->GetEndDoubleQuote())
2184 	{
2185 		bReturn = sal_True;
2186 		sal_Unicode cUCS2 = static_cast<sal_Unicode>(cEndQuote); //TODO
2187 		pAutoCorrect->SetEndDoubleQuote(cUCS2);
2188 	}
2189 	if(cSglStartQuote != pAutoCorrect->GetStartSingleQuote())
2190 	{
2191 		bReturn = sal_True;
2192 		sal_Unicode cUCS2 = static_cast<sal_Unicode>(cSglStartQuote); //TODO
2193 		pAutoCorrect->SetStartSingleQuote(cUCS2);
2194 	}
2195 	if(cSglEndQuote != pAutoCorrect->GetEndSingleQuote())
2196 	{
2197 		bReturn = sal_True;
2198 		sal_Unicode cUCS2 = static_cast<sal_Unicode>(cSglEndQuote); //TODO
2199 		pAutoCorrect->SetEndSingleQuote(cUCS2);
2200 	}
2201 
2202 	if( bModified || bReturn )
2203     {
2204         SvxAutoCorrCfg* pCfg = SvxAutoCorrCfg::Get();
2205         pCfg->SetModified();
2206         pCfg->Commit();
2207     }
2208 	return bReturn;
2209 }
2210 /* -----------------23.11.98 16:15-------------------
2211  *
2212  * --------------------------------------------------*/
2213 void OfaQuoteTabPage::ActivatePage( const SfxItemSet& )
2214 {
2215 	((OfaAutoCorrDlg*)GetTabDialog())->EnableLanguage(sal_False);
2216 }
2217 /*-----------------03.07.97 13:18-------------------
2218 
2219 --------------------------------------------------*/
2220 void OfaQuoteTabPage::Reset( const SfxItemSet& )
2221 {
2222 	SvxAutoCorrect* pAutoCorrect = SvxAutoCorrCfg::Get()->GetAutoCorrect();
2223 	const long nFlags = pAutoCorrect->GetFlags();
2224 
2225     // Initialize the Sw options
2226     if ( aSwCheckLB.IsVisible( ) )
2227     {
2228         SvxSwAutoFmtFlags *pOpt = &pAutoCorrect->GetSwFlags();
2229 
2230         aSwCheckLB.SetUpdateMode( sal_False );
2231         aSwCheckLB.Clear();
2232 
2233         aSwCheckLB.GetModel()->Insert(CreateEntry(sNonBrkSpace,       CBCOL_BOTH ));
2234         aSwCheckLB.GetModel()->Insert(CreateEntry(sOrdinal,           CBCOL_BOTH ));
2235 
2236         aSwCheckLB.CheckEntryPos( ADD_NONBRK_SPACE, CBCOL_FIRST,	pOpt->bAddNonBrkSpace );
2237         aSwCheckLB.CheckEntryPos( ADD_NONBRK_SPACE,	CBCOL_SECOND,	0 != (nFlags & AddNonBrkSpace) );
2238         aSwCheckLB.CheckEntryPos( REPLACE_1ST,		CBCOL_FIRST,	pOpt->bChgOrdinalNumber );
2239         aSwCheckLB.CheckEntryPos( REPLACE_1ST,		CBCOL_SECOND,	0 != (nFlags & ChgOrdinalNumber) );
2240 
2241         aSwCheckLB.SetUpdateMode( sal_True );
2242     }
2243 
2244     // Initialize the non Sw options
2245     if ( aCheckLB.IsVisible( ) )
2246     {
2247         aCheckLB.SetUpdateMode( sal_False );
2248         aCheckLB.Clear( );
2249 
2250         aCheckLB.InsertEntry( sNonBrkSpace );
2251         aCheckLB.InsertEntry( sOrdinal );
2252 
2253         sal_uInt16 nPos = 0;
2254         aCheckLB.CheckEntryPos( nPos++, 0 != (nFlags & AddNonBrkSpace) );
2255         aCheckLB.CheckEntryPos( nPos++, 0 != (nFlags & ChgOrdinalNumber) );
2256 
2257         aCheckLB.SetUpdateMode( sal_True );
2258     }
2259 
2260     // Initialize the quote stuffs
2261 	aTypoCB    			.Check(0 != (nFlags & ChgQuotes));
2262 	aSingleTypoCB    	.Check(0 != (nFlags & ChgSglQuotes));
2263 	aTypoCB    			.SaveValue();
2264 	aSingleTypoCB    	.SaveValue();
2265 
2266 	cStartQuote = pAutoCorrect->GetStartDoubleQuote();
2267 	cEndQuote = pAutoCorrect->GetEndDoubleQuote();
2268 	cSglStartQuote = pAutoCorrect->GetStartSingleQuote();
2269 	cSglEndQuote = pAutoCorrect->GetEndSingleQuote();
2270 
2271 	aSglStartExFT .SetText(ChangeStringExt_Impl(cSglStartQuote));
2272 	aSglEndExFT   .SetText(ChangeStringExt_Impl(cSglEndQuote));
2273 	aDblStartExFT .SetText(ChangeStringExt_Impl(cStartQuote));
2274 	aDblEndExFT   .SetText(ChangeStringExt_Impl(cEndQuote));
2275 }
2276 
2277 
2278 /*-----------------15.10.96 16.42-------------------
2279 
2280 --------------------------------------------------*/
2281 #define SGL_START		0
2282 #define DBL_START       1
2283 #define SGL_END         2
2284 #define DBL_END         3
2285 
2286 
2287 IMPL_LINK( OfaQuoteTabPage, QuoteHdl, PushButton*, pBtn )
2288 {
2289 	sal_uInt16 nMode = SGL_START;
2290 	if(pBtn == &aSglEndQuotePB)
2291 		nMode = SGL_END;
2292 	else if(pBtn == &aStartQuotePB)
2293 		nMode = DBL_START;
2294 	else if(pBtn == &aEndQuotePB)
2295 		nMode = DBL_END;
2296 	// Zeichenauswahl-Dialog starten
2297 	SvxCharacterMap* pMap = new SvxCharacterMap( this, sal_True );
2298 	pMap->SetCharFont( OutputDevice::GetDefaultFont(DEFAULTFONT_LATIN_TEXT,
2299 						LANGUAGE_ENGLISH_US, DEFAULTFONT_FLAGS_ONLYONE, 0 ));
2300 	pMap->SetText(nMode < SGL_END ? sStartQuoteDlg  :  sEndQuoteDlg );
2301 	sal_UCS4 cDlg;
2302 	//The two lines below are added by BerryJia for Bug95846 Time:2002-8-13 15:50
2303 	SvxAutoCorrect* pAutoCorrect = SvxAutoCorrCfg::Get()->GetAutoCorrect();
2304 	LanguageType eLang = Application::GetSettings().GetLanguage();
2305 	switch( nMode )
2306 	{
2307 		case SGL_START:
2308 			cDlg = cSglStartQuote;
2309 			if(cDlg == 0)
2310 				cDlg = pAutoCorrect->GetQuote('\'',sal_True,eLang);   //add by BerryJia for Bug95846 Time:2002-8-13 15:50
2311 		break;
2312 		case SGL_END:
2313 			cDlg = cSglEndQuote;
2314 			if(cDlg == 0)
2315 				cDlg = pAutoCorrect->GetQuote('\'',sal_False,eLang);  //add by BerryJia for Bug95846 Time:2002-8-13 15:50
2316 		break;
2317 		case DBL_START:
2318 			cDlg = cStartQuote;
2319 			if(cDlg == 0)
2320 				cDlg = pAutoCorrect->GetQuote('\"',sal_True,eLang);   //add by BerryJia for Bug95846 Time:2002-8-13 15:50
2321 		break;
2322 		case DBL_END:
2323 			cDlg = cEndQuote;
2324 			if(cDlg == 0)
2325 				cDlg = pAutoCorrect->GetQuote('\"',sal_False,eLang);  //add by BerryJia for Bug95846 Time:2002-8-13 15:50
2326 		break;
2327 		default:
2328 			DBG_ERROR("svx::OfaQuoteTabPage::QuoteHdl(), how to initialize cDlg?" );
2329 			cDlg = 0;
2330 			break;
2331 
2332 	}
2333 	pMap->SetChar(  cDlg );
2334 	pMap->DisableFontSelection();
2335 	if(pMap->Execute() == RET_OK)
2336 	{
2337 		sal_UCS4 cNewChar = pMap->GetChar();
2338 		switch( nMode )
2339 		{
2340 			case SGL_START:
2341 				cSglStartQuote = cNewChar;
2342 				aSglStartExFT.SetText(ChangeStringExt_Impl(cNewChar));
2343 			break;
2344 			case SGL_END:
2345 				cSglEndQuote = cNewChar;
2346 				aSglEndExFT.SetText(ChangeStringExt_Impl(cNewChar));
2347 			break;
2348 			case DBL_START:
2349 				cStartQuote = cNewChar;
2350 				aDblStartExFT.SetText(ChangeStringExt_Impl(cNewChar));
2351 			break;
2352 			case DBL_END:
2353 				cEndQuote = cNewChar;
2354 				aDblEndExFT.SetText(ChangeStringExt_Impl(cNewChar));
2355 			break;
2356 		}
2357 	}
2358 	delete pMap;
2359 
2360 	return 0;
2361 }
2362 
2363 /*-----------------27.06.97 09.55-------------------
2364 
2365 --------------------------------------------------*/
2366 IMPL_LINK( OfaQuoteTabPage, StdQuoteHdl, PushButton*, pBtn )
2367 {
2368 	if(pBtn == &aDblStandardPB)
2369 	{
2370 		cStartQuote = 0;
2371 		aDblStartExFT.SetText(ChangeStringExt_Impl(0));
2372 		cEndQuote = 0;
2373 		aDblEndExFT.SetText(ChangeStringExt_Impl(0));
2374 
2375 	}
2376 	else
2377 	{
2378 		cSglStartQuote = 0;
2379 		aSglStartExFT.SetText(ChangeStringExt_Impl(0));
2380 		cSglEndQuote = 0;
2381 		aSglEndExFT.SetText(ChangeStringExt_Impl(0));
2382 	}
2383 	return 0;
2384 }
2385 
2386 // --------------------------------------------------
2387 
2388 String OfaQuoteTabPage::ChangeStringExt_Impl( sal_UCS4 cChar )
2389 {
2390 	if( !cChar )
2391 		return sStandard;
2392 
2393     // convert codepoint value to unicode-hex string
2394 	sal_UCS4 aStrCodes[32] = { 0, ' ', '(', 'U', '+', '0' };
2395 	aStrCodes[0] = cChar;
2396 	int nFullLen = 5;
2397     int nHexLen = 4;
2398     while( (cChar >> (4*nHexLen)) != 0 )
2399         ++nHexLen;
2400     for( int i = nHexLen; --i >= 0;)
2401     {
2402         sal_UCS4 cHexDigit = ((cChar >> (4*i)) & 0x0f) + '0';
2403 		if( cHexDigit > '9' )
2404 			cHexDigit += 'A' - ('9' + 1);
2405 		aStrCodes[ nFullLen++ ] = cHexDigit;
2406     }
2407 	aStrCodes[ nFullLen++ ] = ')';
2408 	// using the new UCS4 constructor
2409 	rtl::OUString aOUStr( aStrCodes, nFullLen );
2410 	return aOUStr;
2411 }
2412 
2413 OfaAutoCompleteTabPage::OfaAutoCompleteTabPage( Window* pParent,
2414 												const SfxItemSet& rSet )
2415 	: SfxTabPage(pParent, CUI_RES( RID_OFAPAGE_AUTOCOMPLETE_OPTIONS ), rSet),
2416 	aCBActiv		(this, CUI_RES(CB_ACTIV)),
2417     aCBAppendSpace  (this, CUI_RES(CB_APPEND_SPACE)),
2418     aCBAsTip        (this, CUI_RES(CB_AS_TIP)),
2419     aCBCollect      (this, CUI_RES(CB_COLLECT)),
2420     aCBRemoveList   (this, CUI_RES(CB_REMOVE_LIST)),
2421     aFTExpandKey    (this, CUI_RES(FT_EXPAND_KEY)),
2422     aDCBExpandKey   (this, CUI_RES(DCB_EXPAND_KEY)),
2423     aFTMinWordlen   (this, CUI_RES(FT_MIN_WORDLEN)),
2424     aNFMinWordlen   (this, CUI_RES(NF_MIN_WORDLEN)),
2425     aFTMaxEntries   (this, CUI_RES(FT_MAX_ENTRIES)),
2426     aNFMaxEntries   (this, CUI_RES(NF_MAX_ENTRIES)),
2427     aLBEntries      (*this, CUI_RES(LB_ENTRIES)),
2428 	aPBEntries      (this, CUI_RES(PB_ENTRIES)),
2429 	pAutoCmpltList( 0 ),
2430 	nAutoCmpltListCnt( 0 )
2431 {
2432 	FreeResource();
2433 
2434 	// the defined KEYs
2435 	static const sal_uInt16 aKeyCodes[] = {
2436 		KEY_END,
2437 		KEY_RETURN,
2438 		KEY_SPACE,
2439 		KEY_RIGHT,
2440         KEY_TAB,
2441 		0
2442 	};
2443 
2444 	for( const sal_uInt16* pKeys = aKeyCodes; *pKeys; ++pKeys )
2445 	{
2446 		KeyCode aKCode( *pKeys );
2447 		sal_uInt16 nPos = aDCBExpandKey.InsertEntry( aKCode.GetName() );
2448 		aDCBExpandKey.SetEntryData( nPos, (void*)(sal_uLong)*pKeys );
2449 		if( KEY_RETURN == *pKeys )		// default to RETURN
2450 			aDCBExpandKey.SelectEntryPos( nPos );
2451 	}
2452 
2453 	aPBEntries.SetClickHdl(LINK(this, OfaAutoCompleteTabPage, DeleteHdl));
2454 	aCBActiv.SetToggleHdl(LINK(this, OfaAutoCompleteTabPage, CheckHdl));
2455     aCBCollect.SetToggleHdl(LINK(this, OfaAutoCompleteTabPage, CheckHdl));
2456 	aLBEntries.SetAccessibleRelationLabeledBy(&aLBEntries);
2457 }
2458 
2459 OfaAutoCompleteTabPage::~OfaAutoCompleteTabPage()
2460 {
2461 }
2462 
2463 SfxTabPage*	OfaAutoCompleteTabPage::Create( Window* pParent,
2464 											const SfxItemSet& rSet)
2465 {
2466 	return new OfaAutoCompleteTabPage( pParent, rSet );
2467 }
2468 
2469 sal_Bool OfaAutoCompleteTabPage::FillItemSet( SfxItemSet& )
2470 {
2471 	sal_Bool bModified = sal_False, bCheck;
2472 	SvxAutoCorrect* pAutoCorrect = SvxAutoCorrCfg::Get()->GetAutoCorrect();
2473 	SvxSwAutoFmtFlags *pOpt = &pAutoCorrect->GetSwFlags();
2474 	sal_uInt16 nVal;
2475 
2476 	bCheck = aCBActiv.IsChecked();
2477 	bModified |= pOpt->bAutoCompleteWords != bCheck;
2478 	pOpt->bAutoCompleteWords = bCheck;
2479 	bCheck = aCBCollect.IsChecked();
2480 	bModified |= pOpt->bAutoCmpltCollectWords != bCheck;
2481 	pOpt->bAutoCmpltCollectWords = bCheck;
2482     bCheck = !aCBRemoveList.IsChecked(); // inverted value!
2483     bModified |= pOpt->bAutoCmpltKeepList != bCheck;
2484     pOpt->bAutoCmpltKeepList = bCheck;
2485     bCheck = aCBAppendSpace.IsChecked();
2486 	bModified |= pOpt->bAutoCmpltAppendBlanc != bCheck;
2487 	pOpt->bAutoCmpltAppendBlanc = bCheck;
2488 	bCheck = aCBAsTip.IsChecked();
2489 	bModified |= pOpt->bAutoCmpltShowAsTip != bCheck;
2490 	pOpt->bAutoCmpltShowAsTip = bCheck;
2491 
2492 	nVal = (sal_uInt16)aNFMinWordlen.GetValue();
2493 	bModified |= nVal != pOpt->nAutoCmpltWordLen;
2494 	pOpt->nAutoCmpltWordLen = nVal;
2495 
2496 	nVal = (sal_uInt16)aNFMaxEntries.GetValue();
2497 	bModified |= nVal != pOpt->nAutoCmpltListLen;
2498 	pOpt->nAutoCmpltListLen = nVal;
2499 
2500 	nVal = aDCBExpandKey.GetSelectEntryPos();
2501 	if( nVal < aDCBExpandKey.GetEntryCount() )
2502 	{
2503 		sal_uLong nKey = (sal_uLong)aDCBExpandKey.GetEntryData( nVal );
2504 		bModified |= nKey != pOpt->nAutoCmpltExpandKey;
2505 		pOpt->nAutoCmpltExpandKey = (sal_uInt16)nKey;
2506    }
2507 
2508 	if( pAutoCmpltList && nAutoCmpltListCnt != aLBEntries.GetEntryCount() )
2509 	{
2510 		bModified = sal_True;
2511 		pOpt->pAutoCmpltList = pAutoCmpltList;
2512 	}
2513 	if( bModified )
2514     {
2515         SvxAutoCorrCfg* pCfg = SvxAutoCorrCfg::Get();
2516         pCfg->SetModified();
2517         pCfg->Commit();
2518     }
2519 	return sal_True;
2520 }
2521 
2522 void OfaAutoCompleteTabPage::Reset( const SfxItemSet&  )
2523 {
2524 	SvxAutoCorrect* pAutoCorrect = SvxAutoCorrCfg::Get()->GetAutoCorrect();
2525 	SvxSwAutoFmtFlags *pOpt = &pAutoCorrect->GetSwFlags();
2526 
2527 	aCBActiv.Check( 0 != pOpt->bAutoCompleteWords );
2528 	aCBCollect.Check( 0 != pOpt->bAutoCmpltCollectWords );
2529     aCBRemoveList.Check( !pOpt->bAutoCmpltKeepList ); //inverted value!
2530     aCBAppendSpace.Check( 0 != pOpt->bAutoCmpltAppendBlanc );
2531 	aCBAsTip.Check( 0 != pOpt->bAutoCmpltShowAsTip );
2532 
2533 	aNFMinWordlen.SetValue( pOpt->nAutoCmpltWordLen );
2534 	aNFMaxEntries.SetValue( pOpt->nAutoCmpltListLen );
2535 
2536 	// select the specific KeyCode:
2537 	{
2538 		sal_uLong nKey = pOpt->nAutoCmpltExpandKey;
2539 		for( sal_uInt16 n = 0, nCnt = aDCBExpandKey.GetEntryCount(); n < nCnt; ++n )
2540 			if( nKey == (sal_uLong)aDCBExpandKey.GetEntryData( n ))
2541 			{
2542 				aDCBExpandKey.SelectEntryPos( n );
2543 				break;
2544 			}
2545 	}
2546 
2547 	if( pOpt->pAutoCmpltList && pOpt->pAutoCmpltList->Count() )
2548 	{
2549 		pAutoCmpltList = (SvStringsISortDtor*)pOpt->pAutoCmpltList;
2550 		pOpt->pAutoCmpltList = 0;
2551 		nAutoCmpltListCnt = pAutoCmpltList->Count();
2552 		for( sal_uInt16 n = 0; n < nAutoCmpltListCnt; ++n )
2553 		{
2554 			const StringPtr pStr = pAutoCmpltList->GetObject( n );
2555 			sal_uInt16 nPos = aLBEntries.InsertEntry( *pStr );
2556 			aLBEntries.SetEntryData( nPos, (void*)pStr );
2557 		}
2558 	}
2559 	else
2560 	{
2561 		aLBEntries.Disable();
2562 		aPBEntries.Disable();
2563 	}
2564 
2565 	CheckHdl( &aCBActiv );
2566     CheckHdl( &aCBCollect );
2567 }
2568 
2569 void OfaAutoCompleteTabPage::ActivatePage( const SfxItemSet& )
2570 {
2571 	((OfaAutoCorrDlg*)GetTabDialog())->EnableLanguage( sal_False );
2572 }
2573 
2574 IMPL_LINK( OfaAutoCompleteTabPage, DeleteHdl, PushButton*, EMPTYARG )
2575 {
2576 	sal_uInt16 nSelCnt = pAutoCmpltList ? aLBEntries.GetSelectEntryCount() : 0;
2577 	while( nSelCnt )
2578 	{
2579 		sal_uInt16 nPos = aLBEntries.GetSelectEntryPos( --nSelCnt );
2580 		const StringPtr pStr = (StringPtr)aLBEntries.GetEntryData( nPos );
2581 		aLBEntries.RemoveEntry( nPos );
2582 		nPos = pAutoCmpltList->GetPos( pStr );
2583 		if( USHRT_MAX != nPos )
2584 			pAutoCmpltList->Remove( nPos );
2585 	}
2586 	return 0;
2587 }
2588 
2589 IMPL_LINK( OfaAutoCompleteTabPage, CheckHdl, CheckBox*, pBox )
2590 {
2591     sal_Bool bEnable = pBox->IsChecked();
2592     if( pBox == &aCBActiv )
2593 	{
2594         aCBAppendSpace.Enable( bEnable );
2595         aCBAppendSpace.Enable( bEnable );
2596 		aCBAsTip.Enable( bEnable );
2597 		aDCBExpandKey.Enable( bEnable );
2598 	}
2599     else if(&aCBCollect == pBox)
2600         aCBRemoveList.Enable( bEnable );
2601     return 0;
2602 }
2603 
2604 void OfaAutoCompleteTabPage::CopyToClipboard() const
2605 {
2606 	sal_uInt16 nSelCnt = aLBEntries.GetSelectEntryCount();
2607 	if( pAutoCmpltList && nSelCnt )
2608 	{
2609 		TransferDataContainer* pCntnr = new TransferDataContainer;
2610 		::com::sun::star::uno::Reference<
2611 			::com::sun::star::datatransfer::XTransferable > xRef( pCntnr );
2612 
2613 		ByteString sData;
2614 		const sal_Char* pLineEnd =
2615 #if defined(UNX)
2616 				"\012";
2617 #else
2618 				"\015\012";
2619 #endif
2620 
2621 		rtl_TextEncoding nEncode = gsl_getSystemTextEncoding();
2622 
2623 		for( sal_uInt16 n = 0; n < nSelCnt; ++n )
2624 		{
2625 			sData += ByteString( aLBEntries.GetSelectEntry( n ), nEncode );
2626 			sData += pLineEnd;
2627 		}
2628 		pCntnr->CopyByteString( SOT_FORMAT_STRING, sData );
2629 		pCntnr->CopyToClipboard( (Window*)this );
2630 	}
2631 }
2632 
2633 long OfaAutoCompleteTabPage::AutoCompleteMultiListBox::PreNotify(
2634 			NotifyEvent& rNEvt )
2635 {
2636 	long nHandled = MultiListBox::PreNotify( rNEvt );
2637 
2638 	if( !nHandled && EVENT_KEYUP == rNEvt.GetType() )
2639 	{
2640 		const KeyCode& rKeyCode = rNEvt.GetKeyEvent()->GetKeyCode();
2641 		switch( rKeyCode.GetModifier() | rKeyCode.GetCode() )
2642 		{
2643 		case KEY_DELETE:
2644 			rPage.DeleteHdl( 0 );
2645 			nHandled = 1;
2646 			break;
2647 
2648 		default:
2649 			if( KEYFUNC_COPY == rKeyCode.GetFunction() )
2650 			{
2651 				rPage.CopyToClipboard();
2652 				nHandled = 1;
2653 			}
2654 			break;
2655 		}
2656 	}
2657 	return nHandled;
2658 }
2659 
2660 // class OfaSmartTagOptionsTabPage ---------------------------------------------
2661 
2662 OfaSmartTagOptionsTabPage::OfaSmartTagOptionsTabPage( Window* pParent,
2663 												      const SfxItemSet& rSet )
2664     : SfxTabPage(pParent, CUI_RES( RID_OFAPAGE_SMARTTAG_OPTIONS ), rSet),
2665     m_aMainCB( this, CUI_RES(CB_SMARTTAGS) ),
2666     m_aSmartTagTypesLB( this, CUI_RES(LB_SMARTTAGS) ),
2667     m_aPropertiesPB( this, CUI_RES(PB_SMARTTAGS) ),
2668     m_aTitleFT( this, CUI_RES(FT_SMARTTAGS) )
2669 {
2670 	FreeResource();
2671 
2672     // some options for the list box:
2673     m_aSmartTagTypesLB.SetStyle( m_aSmartTagTypesLB.GetStyle() | WB_HSCROLL | WB_HIDESELECTION );
2674 	m_aSmartTagTypesLB.SetHighlightRange();
2675 
2676     // set the handlers:
2677 	m_aMainCB.SetToggleHdl(LINK(this, OfaSmartTagOptionsTabPage, CheckHdl));
2678     m_aPropertiesPB.SetClickHdl(LINK(this, OfaSmartTagOptionsTabPage, ClickHdl));
2679     m_aSmartTagTypesLB.SetSelectHdl(LINK(this, OfaSmartTagOptionsTabPage, SelectHdl));
2680 }
2681 
2682 OfaSmartTagOptionsTabPage::~OfaSmartTagOptionsTabPage()
2683 {
2684 
2685 }
2686 
2687 SfxTabPage*	OfaSmartTagOptionsTabPage::Create( Window* pParent, const SfxItemSet& rSet)
2688 {
2689 	return new OfaSmartTagOptionsTabPage( pParent, rSet );
2690 }
2691 
2692 /** This struct is used to associate list box entries with smart tag data
2693 */
2694 struct ImplSmartTagLBUserData
2695 {
2696     rtl::OUString maSmartTagType;
2697     uno::Reference< smarttags::XSmartTagRecognizer > mxRec;
2698     sal_Int32 mnSmartTagIdx;
2699 
2700     ImplSmartTagLBUserData( const rtl::OUString& rSmartTagType,
2701                             uno::Reference< smarttags::XSmartTagRecognizer > xRec,
2702                             sal_Int32 nSmartTagIdx ) :
2703         maSmartTagType( rSmartTagType ),
2704         mxRec( xRec ),
2705         mnSmartTagIdx( nSmartTagIdx ) {}
2706 };
2707 
2708 /** Clears m_aSmartTagTypesLB
2709 */
2710 void OfaSmartTagOptionsTabPage::ClearListBox()
2711 {
2712     const sal_uLong nCount = m_aSmartTagTypesLB.GetEntryCount();
2713     for ( sal_uInt16 i = 0; i < nCount; ++i )
2714 	{
2715         const SvLBoxEntry* pEntry = m_aSmartTagTypesLB.GetEntry(i);
2716         const ImplSmartTagLBUserData* pUserData = static_cast< ImplSmartTagLBUserData* >(pEntry->GetUserData());
2717         delete pUserData;
2718     }
2719 
2720     m_aSmartTagTypesLB.Clear();
2721 }
2722 
2723 /** Inserts items into m_aSmartTagTypesLB
2724 */
2725 void OfaSmartTagOptionsTabPage::FillListBox( const SmartTagMgr& rSmartTagMgr )
2726 {
2727     // first we have to clear the list box:
2728     ClearListBox();
2729 
2730     // fill list box:
2731     const sal_uInt32 nNumberOfRecognizers = rSmartTagMgr.NumberOfRecognizers();
2732 	const lang::Locale aLocale( SvxCreateLocale( eLastDialogLanguage ) );
2733     std::vector< ActionReference > aActionReferences;
2734 
2735     for ( sal_uInt32 i = 0; i < nNumberOfRecognizers; ++i )
2736     {
2737         uno::Reference< smarttags::XSmartTagRecognizer > xRec = rSmartTagMgr.GetRecognizer(i);
2738 
2739         const rtl::OUString aName = xRec->getName( aLocale );
2740         const rtl::OUString aDesc = xRec->getDescription( aLocale );
2741         const sal_Int32 nNumberOfSupportedSmartTags = xRec->getSmartTagCount();
2742 
2743         for ( sal_Int32 j = 0; j < nNumberOfSupportedSmartTags; ++j )
2744         {
2745             const rtl::OUString aSmartTagType = xRec->getSmartTagName(j);
2746             rtl::OUString aSmartTagCaption = rSmartTagMgr.GetSmartTagCaption( aSmartTagType, aLocale );
2747 
2748             if ( !aSmartTagCaption.getLength() )
2749                 aSmartTagCaption = aSmartTagType;
2750 
2751             const rtl::OUString aLBEntry = aSmartTagCaption +
2752                                            OUString::createFromAscii(" (") +
2753                                            aName +
2754                                            OUString::createFromAscii(")");
2755 
2756             SvLBoxEntry* pEntry = m_aSmartTagTypesLB.SvTreeListBox::InsertEntry( aLBEntry );
2757             if ( pEntry )
2758             {
2759                 const bool bCheck = rSmartTagMgr.IsSmartTagTypeEnabled( aSmartTagType );
2760                 m_aSmartTagTypesLB.SetCheckButtonState( pEntry, bCheck ? SV_BUTTON_CHECKED : SV_BUTTON_UNCHECKED );
2761                 pEntry->SetUserData(static_cast<void*>(new ImplSmartTagLBUserData( aSmartTagType, xRec, j ) ) );
2762             }
2763         }
2764     }
2765 }
2766 
2767 /** Handler for the push button
2768 */
2769 IMPL_LINK( OfaSmartTagOptionsTabPage, ClickHdl, PushButton*, EMPTYARG )
2770 {
2771 	const sal_uInt16 nPos = m_aSmartTagTypesLB.GetSelectEntryPos();
2772     const SvLBoxEntry* pEntry = m_aSmartTagTypesLB.GetEntry(nPos);
2773     const ImplSmartTagLBUserData* pUserData = static_cast< ImplSmartTagLBUserData* >(pEntry->GetUserData());
2774     uno::Reference< smarttags::XSmartTagRecognizer > xRec = pUserData->mxRec;
2775     const sal_Int32 nSmartTagIdx = pUserData->mnSmartTagIdx;
2776 
2777  	const lang::Locale aLocale( SvxCreateLocale( eLastDialogLanguage ) );
2778     if ( xRec->hasPropertyPage( nSmartTagIdx, aLocale ) )
2779         xRec->displayPropertyPage( nSmartTagIdx, aLocale );
2780 
2781 	return 0;
2782 }
2783 
2784 /** Handler for the check box
2785 */
2786 IMPL_LINK( OfaSmartTagOptionsTabPage, CheckHdl, CheckBox*, EMPTYARG )
2787 {
2788     const sal_Bool bEnable = m_aMainCB.IsChecked();
2789     m_aSmartTagTypesLB.Enable( bEnable );
2790     m_aSmartTagTypesLB.Invalidate();
2791     m_aPropertiesPB.Enable( false );
2792 
2793     // if the controls are currently enabled, we still have to check
2794     // if the properties button should be disabled because the currently
2795     // seleted smart tag type does not have a properties dialog.
2796     // We do this by calling SelectHdl:
2797     if ( bEnable )
2798         SelectHdl( &m_aSmartTagTypesLB );
2799 
2800     return 0;
2801 }
2802 
2803 /** Handler for the list box
2804 */
2805 IMPL_LINK(OfaSmartTagOptionsTabPage, SelectHdl, SvxCheckListBox*, EMPTYARG)
2806 {
2807     if ( m_aSmartTagTypesLB.GetEntryCount() < 1 )
2808         return 0;
2809 
2810 	const sal_uInt16 nPos = m_aSmartTagTypesLB.GetSelectEntryPos();
2811     const SvLBoxEntry* pEntry = m_aSmartTagTypesLB.GetEntry(nPos);
2812     const ImplSmartTagLBUserData* pUserData = static_cast< ImplSmartTagLBUserData* >(pEntry->GetUserData());
2813     uno::Reference< smarttags::XSmartTagRecognizer > xRec = pUserData->mxRec;
2814     const sal_Int32 nSmartTagIdx = pUserData->mnSmartTagIdx;
2815 
2816     const lang::Locale aLocale( SvxCreateLocale( eLastDialogLanguage ) );
2817     if ( xRec->hasPropertyPage( nSmartTagIdx, aLocale ) )
2818         m_aPropertiesPB.Enable( sal_True );
2819     else
2820         m_aPropertiesPB.Enable( sal_False );
2821 
2822 	return 0;
2823 }
2824 
2825 /** Propagates the current settings to the smart tag manager.
2826 */
2827 sal_Bool OfaSmartTagOptionsTabPage::FillItemSet( SfxItemSet& )
2828 {
2829 	SvxAutoCorrect* pAutoCorrect = SvxAutoCorrCfg::Get()->GetAutoCorrect();
2830 	SvxSwAutoFmtFlags *pOpt = &pAutoCorrect->GetSwFlags();
2831     SmartTagMgr* pSmartTagMgr = pOpt->pSmartTagMgr;
2832 
2833     // robust!
2834     if ( !pSmartTagMgr )
2835         return sal_False;
2836 
2837     sal_Bool bModifiedSmartTagTypes = sal_False;
2838     std::vector< rtl::OUString > aDisabledSmartTagTypes;
2839 
2840     const sal_uLong nCount = m_aSmartTagTypesLB.GetEntryCount();
2841 
2842     for ( sal_uInt16 i = 0; i < nCount; ++i )
2843 	{
2844         const SvLBoxEntry* pEntry = m_aSmartTagTypesLB.GetEntry(i);
2845         const ImplSmartTagLBUserData* pUserData = static_cast< ImplSmartTagLBUserData* >(pEntry->GetUserData());
2846 		const sal_Bool bChecked = m_aSmartTagTypesLB.IsChecked(i);
2847         const sal_Bool bIsCurrentlyEnabled = pSmartTagMgr->IsSmartTagTypeEnabled( pUserData->maSmartTagType );
2848 
2849         bModifiedSmartTagTypes = bModifiedSmartTagTypes || ( !bChecked != !bIsCurrentlyEnabled );
2850 
2851         if ( !bChecked )
2852             aDisabledSmartTagTypes.push_back( pUserData->maSmartTagType );
2853 
2854         delete pUserData;
2855     }
2856 
2857     const sal_Bool bModifiedRecognize = ( !m_aMainCB.IsChecked() != !pSmartTagMgr->IsLabelTextWithSmartTags() );
2858     if ( bModifiedSmartTagTypes || bModifiedRecognize )
2859     {
2860         bool bLabelTextWithSmartTags = m_aMainCB.IsChecked() ? true : false;
2861         pSmartTagMgr->WriteConfiguration( bModifiedRecognize     ? &bLabelTextWithSmartTags : 0,
2862                                           bModifiedSmartTagTypes ? &aDisabledSmartTagTypes : 0 );
2863     }
2864 
2865 	return sal_True;
2866 }
2867 
2868 /** Sets the controls based on the current settings at SmartTagMgr.
2869 */
2870 void OfaSmartTagOptionsTabPage::Reset( const SfxItemSet&  )
2871 {
2872 	SvxAutoCorrect* pAutoCorrect = SvxAutoCorrCfg::Get()->GetAutoCorrect();
2873 	SvxSwAutoFmtFlags *pOpt = &pAutoCorrect->GetSwFlags();
2874     const SmartTagMgr* pSmartTagMgr = pOpt->pSmartTagMgr;
2875 
2876     // robust, should not happen!
2877     if ( !pSmartTagMgr )
2878         return;
2879 
2880     FillListBox( *pSmartTagMgr );
2881 	m_aSmartTagTypesLB.SelectEntryPos( 0 );
2882     m_aMainCB.Check( pSmartTagMgr->IsLabelTextWithSmartTags() );
2883     CheckHdl( &m_aMainCB );
2884 }
2885 
2886 void OfaSmartTagOptionsTabPage::ActivatePage( const SfxItemSet& )
2887 {
2888 	((OfaAutoCorrDlg*)GetTabDialog())->EnableLanguage( sal_False );
2889 }
2890 
2891