xref: /trunk/main/cui/source/tabpages/autocdlg.cxx (revision a9075099)
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 	pCompareClass->loadDefaultCollator( aLcl, 0 );
1013 	pCharClass = new CharClass( aLcl );
1014 
1015 	static long nTabs[] = { 2 /* Tab-Count */, 1, 61 };
1016 	aReplaceTLB.SetTabs( &nTabs[0], MAP_APPFONT );
1017 
1018 	aReplaceTLB.SetStyle(aReplaceTLB.GetStyle()|WB_HSCROLL|WB_CLIPCHILDREN);
1019 	aReplaceTLB.SetSelectHdl(LINK(this, OfaAutocorrReplacePage, SelectHdl));
1020 	aNewReplacePB.SetClickHdl( LINK(this, OfaAutocorrReplacePage, NewDelHdl));
1021 	aDeleteReplacePB.SetClickHdl(LINK(this, OfaAutocorrReplacePage, NewDelHdl));
1022 	aShortED.SetModifyHdl(LINK(this, OfaAutocorrReplacePage, ModifyHdl));
1023 	aReplaceED.SetModifyHdl(LINK(this, OfaAutocorrReplacePage, ModifyHdl));
1024 	aShortED.SetActionHdl(LINK(this, OfaAutocorrReplacePage, NewDelHdl));
1025 	aReplaceED.SetActionHdl(LINK(this, OfaAutocorrReplacePage, NewDelHdl));
1026 
1027 	aReplaceED.SetSpaces(sal_True);
1028 	aShortED.SetSpaces(sal_True);
1029 	aShortED.SetMaxTextLen(30);
1030 }
1031 
1032 /*-----------------14.10.96 15.58-------------------
1033 
1034 --------------------------------------------------*/
1035 
1036 
1037 OfaAutocorrReplacePage::~OfaAutocorrReplacePage()
1038 {
1039 	delete pFormatText;
1040 	lcl_ClearTable(aDoubleStringTable);
1041     delete pCompareClass;
1042     delete pCharClass;
1043 }
1044 /*-----------------14.10.96 15.58-------------------
1045 
1046 --------------------------------------------------*/
1047 
1048 SfxTabPage*	OfaAutocorrReplacePage::Create( Window* pParent,
1049 								const SfxItemSet& rSet)
1050 {
1051 	return new OfaAutocorrReplacePage(pParent, rSet);
1052 }
1053 /* -----------------20.11.98 13:26-------------------
1054  *
1055  * --------------------------------------------------*/
1056 void	OfaAutocorrReplacePage::ActivatePage( const SfxItemSet& )
1057 {
1058 	if(eLang != eLastDialogLanguage)
1059 		SetLanguage(eLastDialogLanguage);
1060 	((OfaAutoCorrDlg*)GetTabDialog())->EnableLanguage(sal_True);
1061 }
1062 /* -----------------20.11.98 13:26-------------------
1063  *
1064  * --------------------------------------------------*/
1065 int OfaAutocorrReplacePage::DeactivatePage( SfxItemSet*  )
1066 {
1067 	return LEAVE_PAGE;
1068 }
1069 /*-----------------14.10.96 15.58-------------------
1070 
1071 --------------------------------------------------*/
1072 
1073 sal_Bool OfaAutocorrReplacePage::FillItemSet( SfxItemSet& )
1074 {
1075     SvxAutoCorrect* pAutoCorrect = SvxAutoCorrCfg::Get()->GetAutoCorrect();
1076     DoubleStringArrayPtr pDoubleStringArray = aDoubleStringTable.Last();
1077 	while(pDoubleStringArray)
1078 	{
1079 		LanguageType eCurLang = (LanguageType)aDoubleStringTable.GetCurKey();
1080 		if(eCurLang != eLang) // die aktuelle Sprache wird weiter hinten behandelt
1081 		{
1082 			SvxAutocorrWordList* pWordList = pAutoCorrect->LoadAutocorrWordList(eCurLang);
1083 			sal_uInt16 nWordListCount = pWordList->Count();
1084 			sal_uInt16 nDoubleStringArrayCount = pDoubleStringArray->Count();
1085 			sal_uInt16 nPos = nDoubleStringArrayCount;
1086 			sal_uInt16 nLastPos = nPos;
1087 			// 1. Durchlauf: Eintraege loeschen oder veraendern:
1088 
1089 
1090 			for( sal_uInt16 nWordListPos = nWordListCount; nWordListPos; nWordListPos-- )
1091 			{
1092 				SvxAutocorrWordPtr pWordPtr = pWordList->GetObject(nWordListPos - 1);
1093 				String sEntry(pWordPtr->GetShort());
1094 				// formatierter Text steht nur im Writer
1095 				sal_Bool bFound = !bSWriter && !pWordPtr->IsTextOnly();
1096 				while(!bFound && nPos)
1097 				{
1098 					DoubleString* pDouble = pDoubleStringArray->GetObject( nPos - 1);
1099 
1100 					if( 0 == pCompareClass->compareString(
1101 													sEntry, pDouble->sShort ))
1102 					{
1103 						nLastPos = nPos - 1;
1104 						bFound = sal_True;
1105 						if( !(pWordPtr->IsTextOnly() == (0 == pDouble->pUserData)
1106                             && 0 == pCompareClass->compareString(
1107 								pWordPtr->GetLong(), pDouble->sLong ) ) )
1108 						{
1109 							pAutoCorrect->PutText(sEntry, pDouble->sLong, eCurLang);
1110 						}
1111 						pDoubleStringArray->DeleteAndDestroy(nPos - 1, 1);
1112 						break;
1113 					}
1114 					nPos--;
1115 				}
1116 				nPos = nLastPos;
1117 				if(!bFound)
1118 				{
1119 					pAutoCorrect->DeleteText(sEntry, eCurLang);
1120 				}
1121 			}
1122 			nDoubleStringArrayCount = pDoubleStringArray->Count();
1123 			for(sal_uInt16 nDoubleStringArrayPos = 0; nDoubleStringArrayPos < nDoubleStringArrayCount; nDoubleStringArrayPos++ )
1124 			{
1125 				//jetzt sollte es nur noch neue Eintraege geben
1126 				DoubleString* pDouble = pDoubleStringArray->GetObject( nDoubleStringArrayPos );
1127 				if(pDouble->pUserData == &bHasSelectionText)
1128 					pAutoCorrect->PutText( pDouble->sShort,
1129 								*SfxObjectShell::Current(), eCurLang );
1130 				else
1131 				{
1132 					pAutoCorrect->PutText( pDouble->sShort, pDouble->sLong,
1133 															eCurLang);
1134 				}
1135 			}
1136 		}
1137 		pDoubleStringArray->DeleteAndDestroy(0, pDoubleStringArray->Count());
1138 		delete pDoubleStringArray;
1139 		pDoubleStringArray = aDoubleStringTable.Prev();
1140 	}
1141 	aDoubleStringTable.Clear();
1142 	// jetzt noch die aktuelle Selektion
1143 	SvxAutocorrWordList* pWordList = pAutoCorrect->LoadAutocorrWordList(eLang);
1144 	sal_uInt16 nWordListCount = pWordList->Count();
1145 	sal_uInt16 nListBoxCount = (sal_uInt16)aReplaceTLB.GetEntryCount();
1146 
1147 	aReplaceTLB.SetUpdateMode(sal_False);
1148 	sal_uInt16 nListBoxPos = nListBoxCount;
1149 	sal_uInt16 nLastListBoxPos = nListBoxPos;
1150 	// 1. Durchlauf: Eintraege loeschen oder veraendern:
1151 
1152 	sal_uInt16 i;
1153 	for( i = nWordListCount; i; i-- )
1154 	{
1155 		SvxAutocorrWordPtr pWordPtr = pWordList->GetObject(i- 1);
1156 		String sEntry(pWordPtr->GetShort());
1157 		// formatierter Text steht nur im Writer
1158 		sal_Bool bFound = !bSWriter && !pWordPtr->IsTextOnly();
1159 		while(!bFound && nListBoxPos)
1160 		{
1161 			SvLBoxEntry*  pEntry = aReplaceTLB.GetEntry( nListBoxPos - 1);
1162 			if( 0 == pCompareClass->compareString( sEntry,
1163 						aReplaceTLB.GetEntryText(pEntry, 0)))
1164 			{
1165 				nLastListBoxPos = nListBoxPos - 1;
1166 				bFound = sal_True;
1167 				String sLong = aReplaceTLB.GetEntryText(pEntry, 1);
1168 				if( !(pWordPtr->IsTextOnly() == (0 == pEntry->GetUserData())
1169                     && 0 == pCompareClass->compareString(
1170 						pWordPtr->GetLong(), sLong )))
1171 				{
1172 					pAutoCorrect->PutText(sEntry, sLong, eLang);
1173 				}
1174 				aReplaceTLB.GetModel()->Remove(pEntry);
1175 				break;
1176 
1177 			}
1178 			nListBoxPos --;
1179 		}
1180 		nListBoxPos = nLastListBoxPos;
1181 		if(!bFound)
1182 		{
1183 			pAutoCorrect->DeleteText(sEntry, eLang);
1184 		}
1185 
1186 	}
1187 	nListBoxCount = (sal_uInt16)aReplaceTLB.GetEntryCount();
1188 	for(i = 0; i < nListBoxCount; i++ )
1189 	{
1190 		//jetzt sollte es nur noch neue Eintraege geben
1191 		SvLBoxEntry*  pEntry = aReplaceTLB.GetEntry( i );
1192 		String sShort = aReplaceTLB.GetEntryText(pEntry, 0);
1193 		if(pEntry->GetUserData() == &bHasSelectionText)
1194 			pAutoCorrect->PutText(sShort, *SfxObjectShell::Current(), eLang);
1195 		else
1196 		{
1197 			String sLong = aReplaceTLB.GetEntryText(pEntry, 1);
1198 			pAutoCorrect->PutText(sShort, sLong, eLang);
1199 		}
1200 	}
1201 
1202 	return sal_False;
1203 }
1204 
1205 /* -----------------19.11.98 13:16-------------------
1206  *
1207  * --------------------------------------------------*/
1208 void OfaAutocorrReplacePage::RefillReplaceBox(sal_Bool bFromReset,
1209 										LanguageType eOldLanguage,
1210 										LanguageType eNewLanguage)
1211 {
1212 	eLang = eNewLanguage;
1213 	if(bFromReset)
1214 		lcl_ClearTable(aDoubleStringTable);
1215 	else
1216 	{
1217 		DoubleStringArray* pArray = 0;
1218 		if(aDoubleStringTable.IsKeyValid(eOldLanguage))
1219 		{
1220 			pArray = aDoubleStringTable.Seek(sal_uLong(eOldLanguage));
1221 			pArray->DeleteAndDestroy(0, pArray->Count());
1222 		}
1223 		else
1224 		{
1225 			pArray = new DoubleStringArray;
1226 			aDoubleStringTable.Insert(sal_uLong(eOldLanguage), pArray);
1227 		}
1228 
1229 		sal_uInt16 nListBoxCount = (sal_uInt16)aReplaceTLB.GetEntryCount();
1230 		sal_uInt16 i;
1231 		for(i = 0; i < nListBoxCount; i++)
1232 		{
1233 			DoubleString* pDouble = new DoubleString();
1234 			SvLBoxEntry*  pEntry = aReplaceTLB.GetEntry( i );
1235 			pDouble->sShort = aReplaceTLB.GetEntryText(pEntry, 0);
1236 			pDouble->sLong = aReplaceTLB.GetEntryText(pEntry, 1);
1237 			pDouble->pUserData = pEntry->GetUserData();
1238 			pArray->Insert(pDouble, i);
1239 		}
1240 	}
1241 
1242 	aReplaceTLB.Clear();
1243 	if(!bSWriter)
1244 	{
1245 		if(pFormatText)
1246 			pFormatText->DeleteAndDestroy(0, pFormatText->Count());
1247 		else
1248 			pFormatText = new SvStringsISortDtor();
1249 	}
1250 
1251 	if(aDoubleStringTable.IsKeyValid(eLang))
1252 	{
1253 		DoubleStringArray* pArray = aDoubleStringTable.Seek(sal_uLong(eNewLanguage));
1254 		for(sal_uInt16 i = 0; i < pArray->Count(); i++)
1255 		{
1256 			DoubleString* pDouble = pArray->GetObject(i);
1257 			sal_Bool bTextOnly = 0 == pDouble->pUserData;
1258 			// formatierter Text wird nur im Writer angeboten
1259 			if(bSWriter || bTextOnly)
1260 			{
1261 				String sEntry(pDouble->sShort);
1262 				sEntry += '\t';
1263 				sEntry += pDouble->sLong;
1264 				SvLBoxEntry* pEntry = aReplaceTLB.InsertEntry(sEntry);
1265 				aTextOnlyCB.Check(bTextOnly);
1266 				if(!bTextOnly)
1267 					pEntry->SetUserData(pDouble->pUserData); // Das heisst: mit Formatinfo oder sogar mit Selektionstext
1268 			}
1269 			else
1270 			{
1271 				pFormatText->Insert(new String(pDouble->sShort));
1272 			}
1273 		}
1274 	}
1275 	else
1276 	{
1277         SvxAutoCorrect* pAutoCorrect = SvxAutoCorrCfg::Get()->GetAutoCorrect();
1278         SvxAutocorrWordList* pWordList = pAutoCorrect->LoadAutocorrWordList(eLang);
1279 
1280 		for(sal_uInt16 i = 0; i < pWordList->Count(); i++)
1281 		{
1282 			SvxAutocorrWordPtr pWordPtr = pWordList->GetObject(i);
1283 			sal_Bool bTextOnly = pWordPtr->IsTextOnly();
1284 			// formatierter Text wird nur im Writer angeboten
1285 			if(bSWriter || bTextOnly)
1286 			{
1287 				String sEntry(pWordPtr->GetShort());
1288 				sEntry += '\t';
1289 				sEntry += pWordPtr->GetLong();
1290 				SvLBoxEntry* pEntry = aReplaceTLB.InsertEntry(sEntry);
1291 				aTextOnlyCB.Check(pWordPtr->IsTextOnly());
1292 				if(!bTextOnly)
1293 					pEntry->SetUserData(&aTextOnlyCB); // Das heisst: mit Formatinfo
1294 			}
1295 			else
1296 			{
1297 				pFormatText->Insert(new String(pWordPtr->GetShort()));
1298 			}
1299 		}
1300 		aNewReplacePB.Enable(sal_False);
1301 		aDeleteReplacePB.Enable(sal_False);
1302 
1303 	}
1304 
1305 	SfxViewShell* pViewShell = SfxViewShell::Current();
1306 	if( pViewShell && pViewShell->HasSelection( sal_True ) )
1307 	{
1308 		bHasSelectionText = sal_True;
1309 		const String sSelection( pViewShell->GetSelectionText() );
1310 		aReplaceED.SetText( sSelection );
1311 		aTextOnlyCB.Check( !bSWriter );
1312 		aTextOnlyCB.Enable( bSWriter && sSelection.Len() );
1313 	}
1314 	else
1315 		aTextOnlyCB.Enable( sal_False );
1316 }
1317 /*-----------------14.10.96 15.58-------------------
1318 
1319 --------------------------------------------------*/
1320 
1321 void OfaAutocorrReplacePage::Reset( const SfxItemSet& )
1322 {
1323 	RefillReplaceBox(sal_True, eLang, eLang);
1324 	aShortED.GrabFocus();
1325 }
1326 
1327 /* -----------------23.11.98 10:33-------------------
1328  *
1329  * --------------------------------------------------*/
1330 void OfaAutocorrReplacePage::SetLanguage(LanguageType eSet)
1331 {
1332 	//save old settings an refill
1333 	if(eSet != eLang)
1334 	{
1335 		RefillReplaceBox(sal_False, eLang, eSet);
1336 		eLastDialogLanguage = eSet;
1337 		delete pCompareClass;
1338 		delete pCharClass;
1339 
1340 		::com::sun::star::lang::Locale aLcl( SvxCreateLocale(eLastDialogLanguage ));
1341 		pCompareClass = new CollatorWrapper( GetProcessFact() );
1342         pCompareClass->loadDefaultCollator( aLcl, 0 );
1343 		pCharClass = new CharClass( aLcl );
1344 		ModifyHdl(&aShortED);
1345 	}
1346 }
1347 /*-----------------14.10.96 15.58-------------------
1348 
1349 --------------------------------------------------*/
1350 
1351 
1352 IMPL_LINK(OfaAutocorrReplacePage, SelectHdl, SvTabListBox*, pBox)
1353 {
1354 	if(!bFirstSelect || !bHasSelectionText)
1355 	{
1356 		SvLBoxEntry* pEntry = pBox->FirstSelected();
1357 		String sTmpShort(pBox->GetEntryText(pEntry, 0));
1358 		// wird der Text ueber den ModifyHdl gesetzt, dann steht der Cursor sonst immer am Wortanfang,
1359 		// obwohl man gerade hier editiert
1360 		sal_Bool bSameContent = 0 == pCompareClass->compareString(
1361 				sTmpShort, aShortED.GetText() );
1362 		Selection aSel = aShortED.GetSelection();
1363 		if(aShortED.GetText() != sTmpShort)
1364 		{
1365 			aShortED.SetText(sTmpShort);
1366 			//war es nur eine andere Schreibweise, dann muss die Selektion auch wieder gesetzt werden
1367 			if(bSameContent)
1368 				aShortED.SetSelection(aSel);
1369 		}
1370 		aReplaceED.SetText(pBox->GetEntryText(pEntry, 1));
1371 		// mit UserData gibt es eine Formatinfo
1372 		aTextOnlyCB.Check(0 == pEntry->GetUserData());
1373 	}
1374 	else
1375 		bFirstSelect = sal_False;
1376 
1377 	aNewReplacePB.Enable(sal_False);
1378 	aDeleteReplacePB.Enable();
1379 	return 0;
1380 };
1381 
1382 /*-----------------14.10.96 15.58-------------------
1383 
1384 --------------------------------------------------*/
1385 
1386 
1387 IMPL_LINK(OfaAutocorrReplacePage, NewDelHdl, PushButton*, pBtn)
1388 {
1389     SvLBoxEntry* _pEntry = aReplaceTLB.FirstSelected();
1390 	if(pBtn == &aDeleteReplacePB)
1391 	{
1392         DBG_ASSERT(_pEntry, "keine Eintrag selektiert");
1393         if(_pEntry)
1394 		{
1395             aReplaceTLB.GetModel()->Remove(_pEntry);
1396 			ModifyHdl(&aShortED);
1397 			return 0;
1398 		}
1399 	}
1400 	if(pBtn == &aNewReplacePB || aNewReplacePB.IsEnabled())
1401 	{
1402         SvLBoxEntry* _pNewEntry = aReplaceTLB.FirstSelected();
1403 		String sEntry(aShortED.GetText());
1404 		if(sEntry.Len() && ( aReplaceED.GetText().Len() ||
1405 				( bHasSelectionText && bSWriter ) ))
1406 		{
1407 			aReplaceTLB.SetUpdateMode(sal_False);
1408 			sal_uInt16 nPos = USHRT_MAX;
1409 			sEntry += '\t';
1410 			sEntry += aReplaceED.GetText();
1411             if(_pNewEntry)
1412 			{
1413                 nPos = (sal_uInt16)aReplaceTLB.GetModel()->GetAbsPos(_pNewEntry);
1414                 aReplaceTLB.GetModel()->Remove(_pNewEntry);
1415 			}
1416 			else
1417 			{
1418 				sal_uInt16 j;
1419 				for( j = 0; j < aReplaceTLB.GetEntryCount(); j++ )
1420 				{
1421                     SvLBoxEntry* pReplaceEntry = aReplaceTLB.GetEntry(j);
1422 					if( 0 >=  pCompareClass->compareString(sEntry,
1423                                     aReplaceTLB.GetEntryText(pReplaceEntry, 0) ) )
1424 						break;
1425 				}
1426 				nPos = j;
1427 			}
1428 			SvLBoxEntry* pInsEntry =
1429                 aReplaceTLB.InsertEntry(
1430                     sEntry, static_cast< SvLBoxEntry * >(NULL), false,
1431                     nPos == USHRT_MAX ? LIST_APPEND : nPos);
1432 			if( !bReplaceEditChanged && !aTextOnlyCB.IsChecked())
1433 				pInsEntry->SetUserData(&bHasSelectionText); // neuer formatierter Text
1434 
1435 			aReplaceTLB.MakeVisible( pInsEntry );
1436 			aReplaceTLB.SetUpdateMode(sal_True);
1437 			// falls der Request aus dem ReplaceEdit kam, dann Focus in das ShortEdit setzen
1438 			if(aReplaceED.HasFocus())
1439 				aShortED.GrabFocus();
1440 
1441 		}
1442 	}
1443 	else
1444 	{
1445 		// das kann nur ein Enter in einem der beiden Edit-Felder sein und das
1446 		// bedeutet EndDialog() - muss im KeyInput ausgewertet werden
1447 		return 0;
1448 	}
1449 	ModifyHdl(&aShortED);
1450 	return 1;
1451 }
1452 
1453 /*-----------------17.10.96 07.49-------------------
1454 
1455 --------------------------------------------------*/
1456 IMPL_LINK(OfaAutocorrReplacePage, ModifyHdl, Edit*, pEdt)
1457 {
1458 	SvLBoxEntry* pFirstSel = aReplaceTLB.FirstSelected();
1459 	sal_Bool bShort = pEdt == &aShortED;
1460 	const String rEntry = pEdt->GetText();
1461 	const String rRepString = aReplaceED.GetText();
1462 	String aWordStr( pCharClass->lower( rEntry ));
1463 
1464 	if(bShort)
1465 	{
1466 		if(rEntry.Len())
1467 		{
1468 			sal_Bool bFound = sal_False;
1469 			sal_Bool bTmpSelEntry=sal_False;
1470 
1471 			for(sal_uInt16 i = 0; i < aReplaceTLB.GetEntryCount(); i++)
1472 			{
1473 				SvLBoxEntry*  pEntry = aReplaceTLB.GetEntry( i );
1474 				String aTestStr=aReplaceTLB.GetEntryText(pEntry, 0);
1475 				if( 0 == pCompareClass->compareString(rEntry, aTestStr ))
1476 				{
1477 					if(rRepString.Len())
1478 						bFirstSelect = sal_True;
1479 					aReplaceTLB.SetCurEntry(pEntry);
1480 					pFirstSel = pEntry;
1481 					aNewReplacePB.SetText(sModify);
1482 					bFound= sal_True;
1483 					break;
1484 				}
1485 				else
1486 				{
1487 					pCharClass->toLower( aTestStr );
1488 					if(aTestStr.Search(aWordStr)==0 && !bTmpSelEntry)
1489 					{
1490 						aReplaceTLB.MakeVisible(pEntry);
1491 						bTmpSelEntry=sal_True;
1492 					}
1493 				}
1494 			}
1495 			if(!bFound)
1496 			{
1497 				aReplaceTLB.SelectAll(sal_False);
1498 				pFirstSel = 0;
1499 				aNewReplacePB.SetText(sNew);
1500 				if(bReplaceEditChanged)
1501 					aTextOnlyCB.Enable(sal_False);
1502 			}
1503 			aDeleteReplacePB.Enable(bFound);
1504 		}
1505 		else if(aReplaceTLB.GetEntryCount()>0)
1506 		{
1507 			SvLBoxEntry*  pEntry = aReplaceTLB.GetEntry( 0 );
1508 			aReplaceTLB.MakeVisible(pEntry);
1509 		}
1510 
1511 	}
1512 	else if(!bShort)
1513 	{
1514 		bReplaceEditChanged = sal_True;
1515 		if(pFirstSel)
1516 		{
1517 			aNewReplacePB.SetText(sModify);
1518 		}
1519 	}
1520 
1521 	const String& rShortTxt = aShortED.GetText();
1522 	sal_Bool bEnableNew = rShortTxt.Len() &&
1523 						( rRepString.Len() ||
1524 								( bHasSelectionText && bSWriter )) &&
1525 						( !pFirstSel || rRepString !=
1526 								aReplaceTLB.GetEntryText( pFirstSel, 1 ) );
1527 	if(bEnableNew && pFormatText)
1528 	{
1529 		for(sal_uInt16 i = 0; i < pFormatText->Count(); i++)
1530 			if(*pFormatText->GetObject(i) == rShortTxt)
1531 			{
1532 				bEnableNew = sal_False;
1533 				break;
1534 			}
1535 	}
1536 	aNewReplacePB.Enable(bEnableNew);
1537 
1538 	return 0;
1539 }
1540 
1541 /* -----------------20.11.98 13:48-------------------
1542  *
1543  * --------------------------------------------------*/
1544 
1545 struct StringsArrays
1546 {
1547 
1548 	SvStringsDtor aAbbrevStrings;
1549 	SvStringsDtor aDoubleCapsStrings;
1550 
1551 	StringsArrays() :
1552 		aAbbrevStrings(5,5), aDoubleCapsStrings(5,5) {}
1553 };
1554 typedef StringsArrays* StringsArraysPtr;
1555 /* -----------------19.11.98 16:07-------------------
1556  *
1557  * --------------------------------------------------*/
1558 sal_Bool lcl_FindInArray(SvStringsDtor& rStrings, const String& rString)
1559 {
1560 	for(sal_uInt16 i = 0; i < rStrings.Count(); i++)
1561 		if(rString == *rStrings.GetObject(i))
1562 			return sal_True;
1563 	return sal_False;
1564 }
1565 
1566 void lcl_ClearTable(StringsTable& rTable)
1567 {
1568 	StringsArraysPtr pArrays = rTable.Last();
1569 	while(pArrays)
1570 	{
1571 		delete pArrays;
1572 		pArrays = rTable.Prev();
1573 	}
1574 	rTable.Clear();
1575 }
1576 
1577 /*-----------------14.10.96 15.57-------------------
1578 
1579 --------------------------------------------------*/
1580 
1581 OfaAutocorrExceptPage::OfaAutocorrExceptPage( Window* pParent,
1582 												const SfxItemSet& rSet ) :
1583 	SfxTabPage(pParent, CUI_RES( RID_OFAPAGE_AUTOCORR_EXCEPT ), rSet),
1584 	aAbbrevFL    	(this, CUI_RES(FL_ABBREV		 )),
1585 	aAbbrevED       (this, CUI_RES(ED_ABBREV		 )),
1586 	aAbbrevLB    	(this, CUI_RES(LB_ABBREV		 )),
1587 	aNewAbbrevPB    (this, CUI_RES(PB_NEWABBREV	 )),
1588 	aDelAbbrevPB    (this, CUI_RES(PB_DELABBREV	 )),
1589 	aAutoAbbrevCB   (this, CUI_RES(CB_AUTOABBREV	 )),
1590 	aDoubleCapsFL   (this, CUI_RES(FL_DOUBLECAPS	 )),
1591 	aDoubleCapsED   (this, CUI_RES(ED_DOUBLE_CAPS	 )),
1592 	aDoubleCapsLB   (this, CUI_RES(LB_DOUBLE_CAPS	 )),
1593 	aNewDoublePB    (this, CUI_RES(PB_NEWDOUBLECAPS)),
1594 	aDelDoublePB 	(this, CUI_RES(PB_DELDOUBLECAPS)),
1595 	aAutoCapsCB   	(this, CUI_RES(CB_AUTOCAPS	 )),
1596     eLang(eLastDialogLanguage)
1597 {
1598 	aNewAbbrevPB.SetAccessibleName(String(CUI_RES(STR_PB_NEWABBREV) ) );
1599 	aDelAbbrevPB.SetAccessibleName(String(CUI_RES(STR_PB_DELABBREV) ) );
1600 	aNewDoublePB.SetAccessibleName(String(CUI_RES(STR_PB_NEWDOUBLECAPS) ) );
1601 	aDelDoublePB.SetAccessibleName(String(CUI_RES(STR_PB_DELDOUBLECAPS) ) );
1602 
1603 	FreeResource();
1604 
1605 	::com::sun::star::lang::Locale aLcl( SvxCreateLocale(eLastDialogLanguage ));
1606 	pCompareClass = new CollatorWrapper( GetProcessFact() );
1607 	pCompareClass->loadDefaultCollator( aLcl, 0 );
1608 
1609 	aNewAbbrevPB.SetClickHdl(LINK(this, OfaAutocorrExceptPage, NewDelHdl));
1610 	aDelAbbrevPB.SetClickHdl(LINK(this, OfaAutocorrExceptPage, NewDelHdl));
1611 	aNewDoublePB.SetClickHdl(LINK(this, OfaAutocorrExceptPage, NewDelHdl));
1612 	aDelDoublePB.SetClickHdl(LINK(this, OfaAutocorrExceptPage, NewDelHdl));
1613 
1614 	aAbbrevLB.SetSelectHdl(LINK(this, OfaAutocorrExceptPage, SelectHdl));
1615 	aDoubleCapsLB.SetSelectHdl(LINK(this, OfaAutocorrExceptPage, SelectHdl));
1616 	aAbbrevED.SetModifyHdl(LINK(this, OfaAutocorrExceptPage, ModifyHdl));
1617 	aDoubleCapsED.SetModifyHdl(LINK(this, OfaAutocorrExceptPage, ModifyHdl));
1618 
1619 	aAbbrevED.SetActionHdl(LINK(this, OfaAutocorrExceptPage, NewDelHdl));
1620 	aDoubleCapsED.SetActionHdl(LINK(this, OfaAutocorrExceptPage, NewDelHdl));
1621 
1622 	aNewAbbrevPB.SetAccessibleRelationMemberOf(&aAbbrevFL);
1623 	aDelAbbrevPB.SetAccessibleRelationMemberOf(&aAbbrevFL);
1624 	aNewDoublePB.SetAccessibleRelationMemberOf(&aDoubleCapsFL);
1625 	aDelDoublePB.SetAccessibleRelationMemberOf(&aDoubleCapsFL);
1626 }
1627 
1628 /*-----------------14.10.96 15.58-------------------
1629 
1630 --------------------------------------------------*/
1631 
1632 OfaAutocorrExceptPage::~OfaAutocorrExceptPage()
1633 {
1634 	lcl_ClearTable(aStringsTable);
1635 	delete pCompareClass;
1636 }
1637 
1638 /*-----------------14.10.96 15.58-------------------
1639 
1640 --------------------------------------------------*/
1641 
1642 SfxTabPage*	OfaAutocorrExceptPage::Create( Window* pParent,
1643 								const SfxItemSet& rSet)
1644 {
1645 	return new OfaAutocorrExceptPage(pParent, rSet);
1646 }
1647 /* -----------------20.11.98 13:26-------------------
1648  *
1649  * --------------------------------------------------*/
1650 void	OfaAutocorrExceptPage::ActivatePage( const SfxItemSet& )
1651 {
1652 	if(eLang != eLastDialogLanguage)
1653 		SetLanguage(eLastDialogLanguage);
1654 	((OfaAutoCorrDlg*)GetTabDialog())->EnableLanguage(sal_True);
1655 }
1656 /* -----------------20.11.98 13:26-------------------
1657  *
1658  * --------------------------------------------------*/
1659 int     OfaAutocorrExceptPage::DeactivatePage( SfxItemSet* )
1660 {
1661 	return LEAVE_PAGE;
1662 }
1663 /*-----------------14.10.96 15.58-------------------
1664 
1665 --------------------------------------------------*/
1666 
1667 sal_Bool OfaAutocorrExceptPage::FillItemSet( SfxItemSet&  )
1668 {
1669     SvxAutoCorrect* pAutoCorrect = SvxAutoCorrCfg::Get()->GetAutoCorrect();
1670     StringsArraysPtr pArrays = aStringsTable.Last();
1671 	while(pArrays)
1672 	{
1673 		LanguageType eCurLang = (LanguageType)aStringsTable.GetCurKey();
1674 		if(eCurLang != eLang) // die aktuelle Sprache wird weiter hinten behandelt
1675 		{
1676 			SvStringsISortDtor* pWrdList = pAutoCorrect->LoadWrdSttExceptList(eCurLang);
1677 
1678 			if(pWrdList)
1679 			{
1680 				sal_uInt16 nCount = pWrdList->Count();
1681 				sal_uInt16 i;
1682 				for( i = nCount; i; )
1683 				{
1684 					String* pString = pWrdList->GetObject( --i );
1685 					//Eintrag finden u. gfs entfernen
1686 					if( !lcl_FindInArray(pArrays->aDoubleCapsStrings, *pString))
1687 					  pWrdList->DeleteAndDestroy( i );
1688 				}
1689 				nCount = pArrays->aDoubleCapsStrings.Count();
1690 				for( i = 0; i < nCount; ++i )
1691 				{
1692 					String* pEntry = new String( *pArrays->aDoubleCapsStrings.GetObject( i ) );
1693 					if( !pWrdList->Insert( pEntry ))
1694 						delete pEntry;
1695 				}
1696 				pAutoCorrect->SaveWrdSttExceptList(eCurLang);
1697 			}
1698 
1699 			SvStringsISortDtor* pCplList = pAutoCorrect->LoadCplSttExceptList(eCurLang);
1700 
1701 			if(pCplList)
1702 			{
1703 				sal_uInt16 nCount = pCplList->Count();
1704 				sal_uInt16 i;
1705 				for( i = nCount; i; )
1706 				{
1707 					String* pString = pCplList->GetObject( --i );
1708 					if( !lcl_FindInArray(pArrays->aAbbrevStrings, *pString))
1709 						pCplList->DeleteAndDestroy( i );
1710 				}
1711 				nCount = pArrays->aAbbrevStrings.Count();
1712 				for( i = 0; i < nCount; ++i )
1713 				{
1714 					String* pEntry = new String( *pArrays->aAbbrevStrings.GetObject(i) );
1715 					if( !pCplList->Insert( pEntry ))
1716 						delete pEntry;
1717 				}
1718 				pAutoCorrect->SaveCplSttExceptList(eCurLang);
1719 			}
1720 		}
1721 		pArrays = aStringsTable.Prev();
1722 	}
1723 	aStringsTable.Clear();
1724 
1725 	SvStringsISortDtor* pWrdList = pAutoCorrect->LoadWrdSttExceptList(eLang);
1726 
1727 	if(pWrdList)
1728 	{
1729 		sal_uInt16 nCount = pWrdList->Count();
1730 		sal_uInt16 i;
1731 		for( i = nCount; i; )
1732 		{
1733 			String* pString = pWrdList->GetObject( --i );
1734 			if( USHRT_MAX == aDoubleCapsLB.GetEntryPos(*pString) )
1735 				pWrdList->DeleteAndDestroy( i );
1736 		}
1737 		nCount = aDoubleCapsLB.GetEntryCount();
1738 		for( i = 0; i < nCount; ++i )
1739 		{
1740 			String* pEntry = new String( aDoubleCapsLB.GetEntry( i ) );
1741 			if( !pWrdList->Insert( pEntry ))
1742 				delete pEntry;
1743 		}
1744 		pAutoCorrect->SaveWrdSttExceptList(eLang);
1745 	}
1746 
1747 	SvStringsISortDtor* pCplList = pAutoCorrect->LoadCplSttExceptList(eLang);
1748 
1749 	if(pCplList)
1750 	{
1751 		sal_uInt16 nCount = pCplList->Count();
1752 		sal_uInt16 i;
1753 		for( i = nCount; i; )
1754 		{
1755 			String* pString = pCplList->GetObject( --i );
1756 			if( USHRT_MAX == aAbbrevLB.GetEntryPos(*pString) )
1757 				pCplList->DeleteAndDestroy( i );
1758 		}
1759 		nCount = aAbbrevLB.GetEntryCount();
1760 		for( i = 0; i < nCount; ++i )
1761 		{
1762 			String* pEntry = new String( aAbbrevLB.GetEntry( i ) );
1763 			if( !pCplList->Insert( pEntry ))
1764 				delete pEntry;
1765 		}
1766 		pAutoCorrect->SaveCplSttExceptList(eLang);
1767 	}
1768 	if(aAutoAbbrevCB.IsChecked() != aAutoAbbrevCB.GetSavedValue())
1769 		pAutoCorrect->SetAutoCorrFlag( SaveWordCplSttLst, aAutoAbbrevCB.IsChecked());
1770 	if(aAutoCapsCB.IsChecked() != aAutoCapsCB.GetSavedValue())
1771 		pAutoCorrect->SetAutoCorrFlag( SaveWordWrdSttLst, aAutoCapsCB.IsChecked());
1772 	return sal_False;
1773 }
1774 
1775 /* -----------------23.11.98 10:33-------------------
1776  *
1777  * --------------------------------------------------*/
1778 void OfaAutocorrExceptPage::SetLanguage(LanguageType eSet)
1779 {
1780 	if(eLang != eSet)
1781 	{
1782 		//alte Einstellungen speichern und neu fuellen
1783 		RefillReplaceBoxes(sal_False, eLang, eSet);
1784 		eLastDialogLanguage = eSet;
1785 		delete pCompareClass;
1786 		pCompareClass = new CollatorWrapper( GetProcessFact() );
1787 		pCompareClass->loadDefaultCollator( SvxCreateLocale( eLastDialogLanguage ), 0 );
1788 		ModifyHdl(&aAbbrevED);
1789 		ModifyHdl(&aDoubleCapsED);
1790 	}
1791 }
1792 /* -----------------20.11.98 14:06-------------------
1793  *
1794  * --------------------------------------------------*/
1795 void OfaAutocorrExceptPage::RefillReplaceBoxes(sal_Bool bFromReset,
1796 										LanguageType eOldLanguage,
1797 										LanguageType eNewLanguage)
1798 {
1799 	eLang = eNewLanguage;
1800 	if(bFromReset)
1801 		lcl_ClearTable(aStringsTable);
1802 	else
1803 	{
1804 		StringsArraysPtr pArrays = 0;
1805 		if(aStringsTable.IsKeyValid(eOldLanguage))
1806 		{
1807 			pArrays = aStringsTable.Seek(sal_uLong(eOldLanguage));
1808 			pArrays->aAbbrevStrings.DeleteAndDestroy(
1809 									0, pArrays->aAbbrevStrings.Count());
1810 			pArrays->aDoubleCapsStrings.DeleteAndDestroy(
1811 									0, pArrays->aDoubleCapsStrings.Count());
1812 		}
1813 		else
1814 		{
1815 			pArrays = new StringsArrays;
1816 			aStringsTable.Insert(sal_uLong(eOldLanguage), pArrays);
1817 		}
1818 
1819 		sal_uInt16 i;
1820 		for(i = 0; i < aAbbrevLB.GetEntryCount(); i++)
1821 		{
1822 			pArrays->aAbbrevStrings.Insert(
1823 				new String(aAbbrevLB.GetEntry(i)), i);
1824 
1825 		}
1826 		for(i = 0; i < aDoubleCapsLB.GetEntryCount(); i++)
1827 		{
1828 			pArrays->aDoubleCapsStrings.Insert(
1829 				new String(aDoubleCapsLB.GetEntry(i)), i);
1830 		}
1831 	}
1832 	aDoubleCapsLB.Clear();
1833 	aAbbrevLB.Clear();
1834 	String sTemp;
1835 	aAbbrevED.SetText(sTemp);
1836 	aDoubleCapsED.SetText(sTemp);
1837 
1838 	if(aStringsTable.IsKeyValid(eLang))
1839 	{
1840 		StringsArraysPtr pArrays = aStringsTable.Seek(sal_uLong(eLang));
1841 		sal_uInt16 i;
1842 		for(i = 0; i < pArrays->aAbbrevStrings.Count(); i++ )
1843 		{
1844 			aAbbrevLB.InsertEntry(*pArrays->aAbbrevStrings.GetObject(i));
1845 		}
1846 		for( i = 0; i < pArrays->aDoubleCapsStrings.Count(); i++ )
1847 		{
1848 			aDoubleCapsLB.InsertEntry(*pArrays->aDoubleCapsStrings.GetObject(i));
1849 		}
1850 	}
1851 	else
1852 	{
1853         SvxAutoCorrect* pAutoCorrect = SvxAutoCorrCfg::Get()->GetAutoCorrect();
1854         const SvStringsISortDtor* pCplList = pAutoCorrect->GetCplSttExceptList(eLang);
1855 		const SvStringsISortDtor* pWrdList = pAutoCorrect->GetWrdSttExceptList(eLang);
1856 		sal_uInt16 i;
1857 		for( i = 0; i < pCplList->Count(); i++ )
1858 		{
1859 			aAbbrevLB.InsertEntry(*pCplList->GetObject(i));
1860 		}
1861 		for( i = 0; i < pWrdList->Count(); i++ )
1862 		{
1863 			aDoubleCapsLB.InsertEntry(*pWrdList->GetObject(i));
1864 		}
1865 	}
1866 }
1867 
1868 /*-----------------14.10.96 15.58-------------------
1869 
1870 --------------------------------------------------*/
1871 
1872 void OfaAutocorrExceptPage::Reset( const SfxItemSet& )
1873 {
1874     SvxAutoCorrect* pAutoCorrect = SvxAutoCorrCfg::Get()->GetAutoCorrect();
1875     RefillReplaceBoxes(sal_True, eLang, eLang);
1876 	aAutoAbbrevCB.	Check(	pAutoCorrect->IsAutoCorrFlag( SaveWordCplSttLst ));
1877 	aAutoCapsCB.	Check(	pAutoCorrect->IsAutoCorrFlag( SaveWordWrdSttLst ));
1878 	aAutoAbbrevCB.SaveValue();
1879 	aAutoCapsCB.SaveValue();
1880 }
1881 
1882 /*-----------------16.10.96 12.27-------------------
1883 
1884 --------------------------------------------------*/
1885 
1886 
1887 IMPL_LINK(OfaAutocorrExceptPage, NewDelHdl, PushButton*, pBtn)
1888 {
1889 	if((pBtn == &aNewAbbrevPB || pBtn == (PushButton*)&aAbbrevED )
1890 		&& aAbbrevED.GetText().Len())
1891 	{
1892 		aAbbrevLB.InsertEntry(aAbbrevED.GetText());
1893 		ModifyHdl(&aAbbrevED);
1894 	}
1895 	else if(pBtn == &aDelAbbrevPB)
1896 	{
1897 		aAbbrevLB.RemoveEntry(aAbbrevED.GetText());
1898 		ModifyHdl(&aAbbrevED);
1899 	}
1900 	else if((pBtn == &aNewDoublePB || pBtn == (PushButton*)&aDoubleCapsED )
1901 			&& aDoubleCapsED.GetText().Len())
1902 	{
1903 		aDoubleCapsLB.InsertEntry(aDoubleCapsED.GetText());
1904 		ModifyHdl(&aDoubleCapsED);
1905 	}
1906 	else if(pBtn == &aDelDoublePB)
1907 	{
1908 		aDoubleCapsLB.RemoveEntry(aDoubleCapsED.GetText());
1909 		ModifyHdl(&aDoubleCapsED);
1910 	}
1911 	return 0;
1912 }
1913 
1914 /*-----------------16.10.96 12.57-------------------
1915 
1916 --------------------------------------------------*/
1917 
1918 IMPL_LINK(OfaAutocorrExceptPage, SelectHdl, ListBox*, pBox)
1919 {
1920 	if(pBox == &aAbbrevLB)
1921 	{
1922 		aAbbrevED.SetText(pBox->GetSelectEntry());
1923 		aNewAbbrevPB.Enable(sal_False);
1924 		aDelAbbrevPB.Enable();
1925 	}
1926 	else
1927 	{
1928 		aDoubleCapsED.SetText(pBox->GetSelectEntry());
1929 		aNewDoublePB.Enable(sal_False);
1930 		aDelDoublePB.Enable();
1931 	}
1932 	return 0;
1933 }
1934 
1935 /*-----------------16.10.96 13.02-------------------
1936 
1937 --------------------------------------------------*/
1938 
1939 IMPL_LINK(OfaAutocorrExceptPage, ModifyHdl, Edit*, pEdt)
1940 {
1941 //	sal_Bool bSame = pEdt->GetText() == ->GetSelectEntry();
1942 	const String& sEntry = pEdt->GetText();
1943 	sal_Bool bEntryLen = 0!= sEntry.Len();
1944 	if(pEdt == &aAbbrevED)
1945 	{
1946 		sal_Bool bSame = lcl_FindEntry(aAbbrevLB, sEntry, *pCompareClass);
1947 		if(bSame && sEntry != aAbbrevLB.GetSelectEntry())
1948 			pEdt->SetText(aAbbrevLB.GetSelectEntry());
1949 		aNewAbbrevPB.Enable(!bSame && bEntryLen);
1950 		aDelAbbrevPB.Enable(bSame && bEntryLen);
1951 	}
1952 	else
1953 	{
1954 		sal_Bool bSame = lcl_FindEntry(aDoubleCapsLB, sEntry, *pCompareClass);
1955 		if(bSame && sEntry != aDoubleCapsLB.GetSelectEntry())
1956 			pEdt->SetText(aDoubleCapsLB.GetSelectEntry());
1957 		aNewDoublePB.Enable(!bSame && bEntryLen);
1958 		aDelDoublePB.Enable(bSame && bEntryLen);
1959 	}
1960 	return 0;
1961 }
1962 
1963 /*-----------------16.10.96 15.03-------------------
1964 
1965 --------------------------------------------------*/
1966 
1967 void AutoCorrEdit::KeyInput( const KeyEvent& rKEvt )
1968 {
1969 	const KeyCode aKeyCode = rKEvt.GetKeyCode();
1970 	const sal_uInt16 nModifier = aKeyCode.GetModifier();
1971 	if( aKeyCode.GetCode() == KEY_RETURN )
1972 	{
1973 		//wird bei Enter nichts getan, dann doch die Basisklasse rufen
1974 		// um den Dialog zu schliessen
1975 		if(!nModifier && !aActionLink.Call(this))
1976 				 Edit::KeyInput(rKEvt);
1977 	}
1978 	else if(bSpaces || aKeyCode.GetCode() != KEY_SPACE)
1979 		Edit::KeyInput(rKEvt);
1980 }
1981 
1982 /*-----------------03.07.97 13:17-------------------
1983 
1984 --------------------------------------------------*/
1985 
1986 enum OfaQuoteOptions
1987 {
1988     ADD_NONBRK_SPACE,
1989 	REPLACE_1ST
1990 };
1991 
1992 SvLBoxEntry* OfaQuoteTabPage::CreateEntry(String& rTxt, sal_uInt16 nCol)
1993 {
1994 	SvLBoxEntry* pEntry = new SvLBoxEntry;
1995 
1996     if ( !pCheckButtonData )
1997 	{
1998 		pCheckButtonData = new SvLBoxButtonData( &aSwCheckLB );
1999 		aSwCheckLB.SetCheckButtonData( pCheckButtonData );
2000 	}
2001 
2002 	pEntry->AddItem( new SvLBoxContextBmp( pEntry, 0, Image(), Image(), 0));	// Sonst Puff!
2003 
2004 	String sEmpty;
2005 	if (nCol == CBCOL_SECOND)
2006 		pEntry->AddItem( new SvLBoxString( pEntry, 0, sEmpty) );	// Leerspalte
2007 	else
2008 		pEntry->AddItem( new SvLBoxButton( pEntry, SvLBoxButtonKind_enabledCheckbox, 0, pCheckButtonData ) );
2009 
2010 	if (nCol == CBCOL_FIRST)
2011 		pEntry->AddItem( new SvLBoxString( pEntry, 0, sEmpty) );	// Leerspalte
2012 	else
2013 		pEntry->AddItem( new SvLBoxButton( pEntry, SvLBoxButtonKind_enabledCheckbox, 0, pCheckButtonData ) );
2014 
2015 	pEntry->AddItem( new OfaImpBrwString( pEntry, 0, rTxt ) );
2016 
2017 	return pEntry;
2018 }
2019 
2020 OfaQuoteTabPage::OfaQuoteTabPage( Window* pParent, const SfxItemSet& rSet ) :
2021 	SfxTabPage(pParent, CUI_RES( RID_OFAPAGE_AUTOCORR_QUOTE ), rSet),
2022 	aCheckLB			(this, CUI_RES(CLB_SETTINGS     )),
2023 	aSwCheckLB			(this, CUI_RES(CLB_SETTINGS     )),
2024 	sHeader1			(CUI_RES( STR_HEADER1		    )),
2025 	sHeader2			(CUI_RES( STR_HEADER2		    )),
2026     sNonBrkSpace		(CUI_RES( ST_NON_BREAK_SPACE    )),
2027 	sOrdinal			(CUI_RES( ST_ORDINAL            )),
2028     pCheckButtonData    ( NULL ),
2029 
2030 	aSingleFL           (this, CUI_RES(FL_SINGLE		 )),
2031     aSingleTypoCB       (this, CUI_RES(CB_SGL_TYPO     )),
2032     aSglStartQuoteFT    (this, CUI_RES(FT_SGL_STARTQUOTE )),
2033     aSglStartQuotePB    (this, CUI_RES(PB_SGL_STARTQUOTE )),
2034     aSglStartExFT       (this, CUI_RES(FT_SGSTEX       )),
2035     aSglEndQuoteFT      (this, CUI_RES(FT_SGL_ENDQUOTE   )),
2036     aSglEndQuotePB      (this, CUI_RES(PB_SGL_ENDQUOTE   )),
2037     aSglEndExFT         (this, CUI_RES(FT_SGENEX       )),
2038     aSglStandardPB      (this, CUI_RES(PB_SGL_STD      )),
2039 
2040     aDoubleFL           (this, CUI_RES(FL_DOUBLE       )),
2041     aTypoCB             (this, CUI_RES(CB_TYPO         )),
2042     aStartQuoteFT       (this, CUI_RES(FT_STARTQUOTE   )),
2043     aStartQuotePB       (this, CUI_RES(PB_STARTQUOTE   )),
2044     aDblStartExFT       (this, CUI_RES(FT_DBSTEX       )),
2045     aEndQuoteFT         (this, CUI_RES(FT_ENDQUOTE     )),
2046 	aEndQuotePB    		(this, CUI_RES(PB_ENDQUOTE     )),
2047     aDblEndExFT         (this, CUI_RES(FT_DBECEX       )),
2048     aDblStandardPB      (this, CUI_RES(PB_DBL_STD      )),
2049 
2050     sStartQuoteDlg  (CUI_RES(STR_CHANGE_START)),
2051     sEndQuoteDlg    (CUI_RES(STR_CHANGE_END)),
2052 
2053     sStandard(CUI_RES(ST_STANDARD))
2054 {
2055 	aSglStandardPB.SetAccessibleName(String(CUI_RES(STR_PB_SGL_STD) ) );
2056 	aDblStandardPB.SetAccessibleName(String(CUI_RES(STR_PB_DBL_STD) ) );
2057 	aStartQuotePB.SetAccessibleName( String(CUI_RES(STR_PB_DBL_START) ));
2058 	aEndQuotePB.SetAccessibleName(String(CUI_RES(STR_PB_DBL_END) ));
2059 	aSglStartQuotePB.SetAccessibleName(String(CUI_RES(STR_PB_SGL_START) ));
2060 	aSglEndQuotePB.SetAccessibleName(String(CUI_RES(STR_PB_SGL_END) ) );
2061 
2062 	FreeResource();
2063 
2064     sal_Bool bShowSWOptions = sal_False;
2065 
2066     aCheckLB.SetHelpId( HID_OFAPAGE_QUOTE_CLB );
2067     aSwCheckLB.SetHelpId( HID_OFAPAGE_QUOTE_SW_CLB );
2068 
2069     SFX_ITEMSET_ARG( &rSet, pItem, SfxBoolItem, SID_AUTO_CORRECT_DLG, sal_False );
2070     if ( pItem && pItem->GetValue() )
2071 	    bShowSWOptions = sal_True;
2072 
2073     if ( bShowSWOptions )
2074     {
2075     	static long aStaticTabs[]=
2076 	    {
2077 		    3, 0, 20, 40
2078     	};
2079 
2080     	aSwCheckLB.SetStyle(aSwCheckLB.GetStyle() | WB_HSCROLL| WB_VSCROLL);
2081 
2082     	aSwCheckLB.SvxSimpleTable::SetTabs(aStaticTabs);
2083 	    String sHeader( sHeader1 );
2084     	sHeader += '\t';
2085 	    sHeader += sHeader2;
2086     	sHeader += '\t';
2087 	    aSwCheckLB.InsertHeaderEntry( sHeader, HEADERBAR_APPEND,
2088 						HIB_CENTER | HIB_VCENTER | HIB_FIXEDPOS | HIB_FIXED);
2089         aCheckLB.Hide( sal_True );
2090     }
2091     else
2092     {
2093         aSwCheckLB.HideTable( );
2094     }
2095 
2096 	aStartQuotePB.SetClickHdl(LINK(this, 	OfaQuoteTabPage, QuoteHdl));
2097 	aEndQuotePB.SetClickHdl(LINK(this, 		OfaQuoteTabPage, QuoteHdl));
2098 	aSglStartQuotePB.SetClickHdl(LINK(this, OfaQuoteTabPage, QuoteHdl));
2099 	aSglEndQuotePB.SetClickHdl(LINK(this, 	OfaQuoteTabPage, QuoteHdl));
2100 	aDblStandardPB.SetClickHdl(LINK(this, 	OfaQuoteTabPage, StdQuoteHdl));
2101 	aSglStandardPB.SetClickHdl(LINK(this, 	OfaQuoteTabPage, StdQuoteHdl));
2102 
2103 	aSglStartQuotePB.SetAccessibleRelationLabeledBy( &aSglStartQuoteFT );
2104 	aSglEndQuotePB.SetAccessibleRelationLabeledBy( &aSglEndQuoteFT );
2105 	aSglStartQuotePB.SetAccessibleRelationMemberOf( &aSingleFL );
2106 	aSglEndQuotePB.SetAccessibleRelationMemberOf( &aSingleFL );
2107 	aStartQuotePB.SetAccessibleRelationLabeledBy( &aStartQuoteFT );
2108 	aEndQuotePB.SetAccessibleRelationLabeledBy( &aEndQuoteFT );
2109 	aStartQuotePB.SetAccessibleRelationMemberOf( &aDoubleFL );
2110 	aEndQuotePB.SetAccessibleRelationMemberOf( &aDoubleFL );
2111 	aSglStandardPB.SetAccessibleRelationMemberOf(&aSingleFL);
2112 	aDblStandardPB.SetAccessibleRelationMemberOf(&aDoubleFL);
2113 }
2114 /*-----------------03.07.97 13:17-------------------
2115 
2116 --------------------------------------------------*/
2117 OfaQuoteTabPage::~OfaQuoteTabPage()
2118 {
2119     delete( pCheckButtonData );
2120 }
2121 /*-----------------03.07.97 13:17-------------------
2122 
2123 --------------------------------------------------*/
2124 SfxTabPage*	OfaQuoteTabPage::Create( Window* pParent,
2125 								const SfxItemSet& rAttrSet)
2126 {
2127 	return new OfaQuoteTabPage(pParent, rAttrSet);
2128 }
2129 /*-----------------03.07.97 13:18-------------------
2130 
2131 --------------------------------------------------*/
2132 sal_Bool OfaQuoteTabPage::FillItemSet( SfxItemSet&  )
2133 {
2134 	SvxAutoCorrect* pAutoCorrect = SvxAutoCorrCfg::Get()->GetAutoCorrect();
2135 
2136 	long nFlags = pAutoCorrect->GetFlags();
2137 
2138     if ( aCheckLB.IsVisible( ) )
2139     {
2140 	    sal_uInt16 nPos = 0;
2141         pAutoCorrect->SetAutoCorrFlag(AddNonBrkSpace,		aCheckLB.IsChecked(nPos++));
2142 	    pAutoCorrect->SetAutoCorrFlag(ChgOrdinalNumber,		aCheckLB.IsChecked(nPos++));
2143     }
2144 
2145     sal_Bool bModified = sal_False;
2146     if ( aSwCheckLB.IsVisible( ) )
2147     {
2148 	    SvxSwAutoFmtFlags *pOpt = &pAutoCorrect->GetSwFlags();
2149 
2150         sal_Bool bCheck = aSwCheckLB.IsChecked(ADD_NONBRK_SPACE, CBCOL_FIRST);
2151 	    bModified |= pOpt->bAddNonBrkSpace != bCheck;
2152         pOpt->bAddNonBrkSpace = bCheck;
2153         pAutoCorrect->SetAutoCorrFlag(AddNonBrkSpace,
2154                             aSwCheckLB.IsChecked(ADD_NONBRK_SPACE, CBCOL_SECOND));
2155 
2156     	bCheck = aSwCheckLB.IsChecked(REPLACE_1ST, CBCOL_FIRST);
2157 	    bModified |= pOpt->bChgOrdinalNumber != bCheck;
2158     	pOpt->bChgOrdinalNumber = bCheck;
2159 	    pAutoCorrect->SetAutoCorrFlag(ChgOrdinalNumber,
2160 						aSwCheckLB.IsChecked(REPLACE_1ST, CBCOL_SECOND));
2161     }
2162 
2163 	pAutoCorrect->SetAutoCorrFlag(ChgQuotes, 		aTypoCB.IsChecked());
2164 	pAutoCorrect->SetAutoCorrFlag(ChgSglQuotes, 	aSingleTypoCB.IsChecked());
2165 	sal_Bool bReturn = nFlags != pAutoCorrect->GetFlags();
2166 	if(cStartQuote != pAutoCorrect->GetStartDoubleQuote())
2167 	{
2168 		bReturn = sal_True;
2169 		sal_Unicode cUCS2 = static_cast<sal_Unicode>(cStartQuote); //TODO
2170 		pAutoCorrect->SetStartDoubleQuote(cUCS2);
2171 	}
2172 	if(cEndQuote != pAutoCorrect->GetEndDoubleQuote())
2173 	{
2174 		bReturn = sal_True;
2175 		sal_Unicode cUCS2 = static_cast<sal_Unicode>(cEndQuote); //TODO
2176 		pAutoCorrect->SetEndDoubleQuote(cUCS2);
2177 	}
2178 	if(cSglStartQuote != pAutoCorrect->GetStartSingleQuote())
2179 	{
2180 		bReturn = sal_True;
2181 		sal_Unicode cUCS2 = static_cast<sal_Unicode>(cSglStartQuote); //TODO
2182 		pAutoCorrect->SetStartSingleQuote(cUCS2);
2183 	}
2184 	if(cSglEndQuote != pAutoCorrect->GetEndSingleQuote())
2185 	{
2186 		bReturn = sal_True;
2187 		sal_Unicode cUCS2 = static_cast<sal_Unicode>(cSglEndQuote); //TODO
2188 		pAutoCorrect->SetEndSingleQuote(cUCS2);
2189 	}
2190 
2191 	if( bModified || bReturn )
2192     {
2193         SvxAutoCorrCfg* pCfg = SvxAutoCorrCfg::Get();
2194         pCfg->SetModified();
2195         pCfg->Commit();
2196     }
2197 	return bReturn;
2198 }
2199 /* -----------------23.11.98 16:15-------------------
2200  *
2201  * --------------------------------------------------*/
2202 void OfaQuoteTabPage::ActivatePage( const SfxItemSet& )
2203 {
2204 	((OfaAutoCorrDlg*)GetTabDialog())->EnableLanguage(sal_False);
2205 }
2206 /*-----------------03.07.97 13:18-------------------
2207 
2208 --------------------------------------------------*/
2209 void OfaQuoteTabPage::Reset( const SfxItemSet& )
2210 {
2211 	SvxAutoCorrect* pAutoCorrect = SvxAutoCorrCfg::Get()->GetAutoCorrect();
2212 	const long nFlags = pAutoCorrect->GetFlags();
2213 
2214     // Initialize the Sw options
2215     if ( aSwCheckLB.IsVisible( ) )
2216     {
2217         SvxSwAutoFmtFlags *pOpt = &pAutoCorrect->GetSwFlags();
2218 
2219         aSwCheckLB.SetUpdateMode( sal_False );
2220         aSwCheckLB.Clear();
2221 
2222         aSwCheckLB.GetModel()->Insert(CreateEntry(sNonBrkSpace,       CBCOL_BOTH ));
2223         aSwCheckLB.GetModel()->Insert(CreateEntry(sOrdinal,           CBCOL_BOTH ));
2224 
2225         aSwCheckLB.CheckEntryPos( ADD_NONBRK_SPACE, CBCOL_FIRST,	pOpt->bAddNonBrkSpace );
2226         aSwCheckLB.CheckEntryPos( ADD_NONBRK_SPACE,	CBCOL_SECOND,	0 != (nFlags & AddNonBrkSpace) );
2227         aSwCheckLB.CheckEntryPos( REPLACE_1ST,		CBCOL_FIRST,	pOpt->bChgOrdinalNumber );
2228         aSwCheckLB.CheckEntryPos( REPLACE_1ST,		CBCOL_SECOND,	0 != (nFlags & ChgOrdinalNumber) );
2229 
2230         aSwCheckLB.SetUpdateMode( sal_True );
2231     }
2232 
2233     // Initialize the non Sw options
2234     if ( aCheckLB.IsVisible( ) )
2235     {
2236         aCheckLB.SetUpdateMode( sal_False );
2237         aCheckLB.Clear( );
2238 
2239         aCheckLB.InsertEntry( sNonBrkSpace );
2240         aCheckLB.InsertEntry( sOrdinal );
2241 
2242         sal_uInt16 nPos = 0;
2243         aCheckLB.CheckEntryPos( nPos++, 0 != (nFlags & AddNonBrkSpace) );
2244         aCheckLB.CheckEntryPos( nPos++, 0 != (nFlags & ChgOrdinalNumber) );
2245 
2246         aCheckLB.SetUpdateMode( sal_True );
2247     }
2248 
2249     // Initialize the quote stuffs
2250 	aTypoCB    			.Check(0 != (nFlags & ChgQuotes));
2251 	aSingleTypoCB    	.Check(0 != (nFlags & ChgSglQuotes));
2252 	aTypoCB    			.SaveValue();
2253 	aSingleTypoCB    	.SaveValue();
2254 
2255 	cStartQuote = pAutoCorrect->GetStartDoubleQuote();
2256 	cEndQuote = pAutoCorrect->GetEndDoubleQuote();
2257 	cSglStartQuote = pAutoCorrect->GetStartSingleQuote();
2258 	cSglEndQuote = pAutoCorrect->GetEndSingleQuote();
2259 
2260 	aSglStartExFT .SetText(ChangeStringExt_Impl(cSglStartQuote));
2261 	aSglEndExFT   .SetText(ChangeStringExt_Impl(cSglEndQuote));
2262 	aDblStartExFT .SetText(ChangeStringExt_Impl(cStartQuote));
2263 	aDblEndExFT   .SetText(ChangeStringExt_Impl(cEndQuote));
2264 }
2265 
2266 
2267 /*-----------------15.10.96 16.42-------------------
2268 
2269 --------------------------------------------------*/
2270 #define SGL_START		0
2271 #define DBL_START       1
2272 #define SGL_END         2
2273 #define DBL_END         3
2274 
2275 
2276 IMPL_LINK( OfaQuoteTabPage, QuoteHdl, PushButton*, pBtn )
2277 {
2278 	sal_uInt16 nMode = SGL_START;
2279 	if(pBtn == &aSglEndQuotePB)
2280 		nMode = SGL_END;
2281 	else if(pBtn == &aStartQuotePB)
2282 		nMode = DBL_START;
2283 	else if(pBtn == &aEndQuotePB)
2284 		nMode = DBL_END;
2285 	// Zeichenauswahl-Dialog starten
2286 	SvxCharacterMap* pMap = new SvxCharacterMap( this, sal_True );
2287 	pMap->SetCharFont( OutputDevice::GetDefaultFont(DEFAULTFONT_LATIN_TEXT,
2288 						LANGUAGE_ENGLISH_US, DEFAULTFONT_FLAGS_ONLYONE, 0 ));
2289 	pMap->SetText(nMode < SGL_END ? sStartQuoteDlg  :  sEndQuoteDlg );
2290 	sal_UCS4 cDlg;
2291 	//The two lines below are added by BerryJia for Bug95846 Time:2002-8-13 15:50
2292 	SvxAutoCorrect* pAutoCorrect = SvxAutoCorrCfg::Get()->GetAutoCorrect();
2293 	LanguageType eLang = Application::GetSettings().GetLanguage();
2294 	switch( nMode )
2295 	{
2296 		case SGL_START:
2297 			cDlg = cSglStartQuote;
2298 			if(cDlg == 0)
2299 				cDlg = pAutoCorrect->GetQuote('\'',sal_True,eLang);   //add by BerryJia for Bug95846 Time:2002-8-13 15:50
2300 		break;
2301 		case SGL_END:
2302 			cDlg = cSglEndQuote;
2303 			if(cDlg == 0)
2304 				cDlg = pAutoCorrect->GetQuote('\'',sal_False,eLang);  //add by BerryJia for Bug95846 Time:2002-8-13 15:50
2305 		break;
2306 		case DBL_START:
2307 			cDlg = cStartQuote;
2308 			if(cDlg == 0)
2309 				cDlg = pAutoCorrect->GetQuote('\"',sal_True,eLang);   //add by BerryJia for Bug95846 Time:2002-8-13 15:50
2310 		break;
2311 		case DBL_END:
2312 			cDlg = cEndQuote;
2313 			if(cDlg == 0)
2314 				cDlg = pAutoCorrect->GetQuote('\"',sal_False,eLang);  //add by BerryJia for Bug95846 Time:2002-8-13 15:50
2315 		break;
2316 		default:
2317 			DBG_ERROR("svx::OfaQuoteTabPage::QuoteHdl(), how to initialize cDlg?" );
2318 			cDlg = 0;
2319 			break;
2320 
2321 	}
2322 	pMap->SetChar(  cDlg );
2323 	pMap->DisableFontSelection();
2324 	if(pMap->Execute() == RET_OK)
2325 	{
2326 		sal_UCS4 cNewChar = pMap->GetChar();
2327 		switch( nMode )
2328 		{
2329 			case SGL_START:
2330 				cSglStartQuote = cNewChar;
2331 				aSglStartExFT.SetText(ChangeStringExt_Impl(cNewChar));
2332 			break;
2333 			case SGL_END:
2334 				cSglEndQuote = cNewChar;
2335 				aSglEndExFT.SetText(ChangeStringExt_Impl(cNewChar));
2336 			break;
2337 			case DBL_START:
2338 				cStartQuote = cNewChar;
2339 				aDblStartExFT.SetText(ChangeStringExt_Impl(cNewChar));
2340 			break;
2341 			case DBL_END:
2342 				cEndQuote = cNewChar;
2343 				aDblEndExFT.SetText(ChangeStringExt_Impl(cNewChar));
2344 			break;
2345 		}
2346 	}
2347 	delete pMap;
2348 
2349 	return 0;
2350 }
2351 
2352 /*-----------------27.06.97 09.55-------------------
2353 
2354 --------------------------------------------------*/
2355 IMPL_LINK( OfaQuoteTabPage, StdQuoteHdl, PushButton*, pBtn )
2356 {
2357 	if(pBtn == &aDblStandardPB)
2358 	{
2359 		cStartQuote = 0;
2360 		aDblStartExFT.SetText(ChangeStringExt_Impl(0));
2361 		cEndQuote = 0;
2362 		aDblEndExFT.SetText(ChangeStringExt_Impl(0));
2363 
2364 	}
2365 	else
2366 	{
2367 		cSglStartQuote = 0;
2368 		aSglStartExFT.SetText(ChangeStringExt_Impl(0));
2369 		cSglEndQuote = 0;
2370 		aSglEndExFT.SetText(ChangeStringExt_Impl(0));
2371 	}
2372 	return 0;
2373 }
2374 
2375 // --------------------------------------------------
2376 
2377 String OfaQuoteTabPage::ChangeStringExt_Impl( sal_UCS4 cChar )
2378 {
2379 	if( !cChar )
2380 		return sStandard;
2381 
2382     // convert codepoint value to unicode-hex string
2383 	sal_UCS4 aStrCodes[32] = { 0, ' ', '(', 'U', '+', '0' };
2384 	aStrCodes[0] = cChar;
2385 	int nFullLen = 5;
2386     int nHexLen = 4;
2387     while( (cChar >> (4*nHexLen)) != 0 )
2388         ++nHexLen;
2389     for( int i = nHexLen; --i >= 0;)
2390     {
2391         sal_UCS4 cHexDigit = ((cChar >> (4*i)) & 0x0f) + '0';
2392 		if( cHexDigit > '9' )
2393 			cHexDigit += 'A' - ('9' + 1);
2394 		aStrCodes[ nFullLen++ ] = cHexDigit;
2395     }
2396 	aStrCodes[ nFullLen++ ] = ')';
2397 	// using the new UCS4 constructor
2398 	rtl::OUString aOUStr( aStrCodes, nFullLen );
2399 	return aOUStr;
2400 }
2401 
2402 OfaAutoCompleteTabPage::OfaAutoCompleteTabPage( Window* pParent,
2403 												const SfxItemSet& rSet )
2404 	: SfxTabPage(pParent, CUI_RES( RID_OFAPAGE_AUTOCOMPLETE_OPTIONS ), rSet),
2405 	aCBActiv		(this, CUI_RES(CB_ACTIV)),
2406     aCBAppendSpace  (this, CUI_RES(CB_APPEND_SPACE)),
2407     aCBAsTip        (this, CUI_RES(CB_AS_TIP)),
2408     aCBCollect      (this, CUI_RES(CB_COLLECT)),
2409     aCBRemoveList   (this, CUI_RES(CB_REMOVE_LIST)),
2410     aFTExpandKey    (this, CUI_RES(FT_EXPAND_KEY)),
2411     aDCBExpandKey   (this, CUI_RES(DCB_EXPAND_KEY)),
2412     aFTMinWordlen   (this, CUI_RES(FT_MIN_WORDLEN)),
2413     aNFMinWordlen   (this, CUI_RES(NF_MIN_WORDLEN)),
2414     aFTMaxEntries   (this, CUI_RES(FT_MAX_ENTRIES)),
2415     aNFMaxEntries   (this, CUI_RES(NF_MAX_ENTRIES)),
2416     aLBEntries      (*this, CUI_RES(LB_ENTRIES)),
2417 	aPBEntries      (this, CUI_RES(PB_ENTRIES)),
2418 	pAutoCmpltList( 0 ),
2419 	nAutoCmpltListCnt( 0 )
2420 {
2421 	FreeResource();
2422 
2423 	// the defined KEYs
2424 	static const sal_uInt16 aKeyCodes[] = {
2425 		KEY_END,
2426 		KEY_RETURN,
2427 		KEY_SPACE,
2428 		KEY_RIGHT,
2429         KEY_TAB,
2430 		0
2431 	};
2432 
2433 	for( const sal_uInt16* pKeys = aKeyCodes; *pKeys; ++pKeys )
2434 	{
2435 		KeyCode aKCode( *pKeys );
2436 		sal_uInt16 nPos = aDCBExpandKey.InsertEntry( aKCode.GetName() );
2437 		aDCBExpandKey.SetEntryData( nPos, (void*)(sal_uLong)*pKeys );
2438 		if( KEY_RETURN == *pKeys )		// default to RETURN
2439 			aDCBExpandKey.SelectEntryPos( nPos );
2440 	}
2441 
2442 	aPBEntries.SetClickHdl(LINK(this, OfaAutoCompleteTabPage, DeleteHdl));
2443 	aCBActiv.SetToggleHdl(LINK(this, OfaAutoCompleteTabPage, CheckHdl));
2444     aCBCollect.SetToggleHdl(LINK(this, OfaAutoCompleteTabPage, CheckHdl));
2445 	aLBEntries.SetAccessibleRelationLabeledBy(&aLBEntries);
2446 }
2447 
2448 OfaAutoCompleteTabPage::~OfaAutoCompleteTabPage()
2449 {
2450 }
2451 
2452 SfxTabPage*	OfaAutoCompleteTabPage::Create( Window* pParent,
2453 											const SfxItemSet& rSet)
2454 {
2455 	return new OfaAutoCompleteTabPage( pParent, rSet );
2456 }
2457 
2458 sal_Bool OfaAutoCompleteTabPage::FillItemSet( SfxItemSet& )
2459 {
2460 	sal_Bool bModified = sal_False, bCheck;
2461 	SvxAutoCorrect* pAutoCorrect = SvxAutoCorrCfg::Get()->GetAutoCorrect();
2462 	SvxSwAutoFmtFlags *pOpt = &pAutoCorrect->GetSwFlags();
2463 	sal_uInt16 nVal;
2464 
2465 	bCheck = aCBActiv.IsChecked();
2466 	bModified |= pOpt->bAutoCompleteWords != bCheck;
2467 	pOpt->bAutoCompleteWords = bCheck;
2468 	bCheck = aCBCollect.IsChecked();
2469 	bModified |= pOpt->bAutoCmpltCollectWords != bCheck;
2470 	pOpt->bAutoCmpltCollectWords = bCheck;
2471     bCheck = !aCBRemoveList.IsChecked(); // inverted value!
2472     bModified |= pOpt->bAutoCmpltKeepList != bCheck;
2473     pOpt->bAutoCmpltKeepList = bCheck;
2474     bCheck = aCBAppendSpace.IsChecked();
2475 	bModified |= pOpt->bAutoCmpltAppendBlanc != bCheck;
2476 	pOpt->bAutoCmpltAppendBlanc = bCheck;
2477 	bCheck = aCBAsTip.IsChecked();
2478 	bModified |= pOpt->bAutoCmpltShowAsTip != bCheck;
2479 	pOpt->bAutoCmpltShowAsTip = bCheck;
2480 
2481 	nVal = (sal_uInt16)aNFMinWordlen.GetValue();
2482 	bModified |= nVal != pOpt->nAutoCmpltWordLen;
2483 	pOpt->nAutoCmpltWordLen = nVal;
2484 
2485 	nVal = (sal_uInt16)aNFMaxEntries.GetValue();
2486 	bModified |= nVal != pOpt->nAutoCmpltListLen;
2487 	pOpt->nAutoCmpltListLen = nVal;
2488 
2489 	nVal = aDCBExpandKey.GetSelectEntryPos();
2490 	if( nVal < aDCBExpandKey.GetEntryCount() )
2491 	{
2492 		sal_uLong nKey = (sal_uLong)aDCBExpandKey.GetEntryData( nVal );
2493 		bModified |= nKey != pOpt->nAutoCmpltExpandKey;
2494 		pOpt->nAutoCmpltExpandKey = (sal_uInt16)nKey;
2495    }
2496 
2497 	if( pAutoCmpltList && nAutoCmpltListCnt != aLBEntries.GetEntryCount() )
2498 	{
2499 		bModified = sal_True;
2500 		pOpt->pAutoCmpltList = pAutoCmpltList;
2501 	}
2502 	if( bModified )
2503     {
2504         SvxAutoCorrCfg* pCfg = SvxAutoCorrCfg::Get();
2505         pCfg->SetModified();
2506         pCfg->Commit();
2507     }
2508 	return sal_True;
2509 }
2510 
2511 void OfaAutoCompleteTabPage::Reset( const SfxItemSet&  )
2512 {
2513 	SvxAutoCorrect* pAutoCorrect = SvxAutoCorrCfg::Get()->GetAutoCorrect();
2514 	SvxSwAutoFmtFlags *pOpt = &pAutoCorrect->GetSwFlags();
2515 
2516 	aCBActiv.Check( 0 != pOpt->bAutoCompleteWords );
2517 	aCBCollect.Check( 0 != pOpt->bAutoCmpltCollectWords );
2518     aCBRemoveList.Check( !pOpt->bAutoCmpltKeepList ); //inverted value!
2519     aCBAppendSpace.Check( 0 != pOpt->bAutoCmpltAppendBlanc );
2520 	aCBAsTip.Check( 0 != pOpt->bAutoCmpltShowAsTip );
2521 
2522 	aNFMinWordlen.SetValue( pOpt->nAutoCmpltWordLen );
2523 	aNFMaxEntries.SetValue( pOpt->nAutoCmpltListLen );
2524 
2525 	// select the specific KeyCode:
2526 	{
2527 		sal_uLong nKey = pOpt->nAutoCmpltExpandKey;
2528 		for( sal_uInt16 n = 0, nCnt = aDCBExpandKey.GetEntryCount(); n < nCnt; ++n )
2529 			if( nKey == (sal_uLong)aDCBExpandKey.GetEntryData( n ))
2530 			{
2531 				aDCBExpandKey.SelectEntryPos( n );
2532 				break;
2533 			}
2534 	}
2535 
2536 	if( pOpt->pAutoCmpltList && pOpt->pAutoCmpltList->Count() )
2537 	{
2538 		pAutoCmpltList = (SvStringsISortDtor*)pOpt->pAutoCmpltList;
2539 		pOpt->pAutoCmpltList = 0;
2540 		nAutoCmpltListCnt = pAutoCmpltList->Count();
2541 		for( sal_uInt16 n = 0; n < nAutoCmpltListCnt; ++n )
2542 		{
2543 			const StringPtr pStr = pAutoCmpltList->GetObject( n );
2544 			sal_uInt16 nPos = aLBEntries.InsertEntry( *pStr );
2545 			aLBEntries.SetEntryData( nPos, (void*)pStr );
2546 		}
2547 	}
2548 	else
2549 	{
2550 		aLBEntries.Disable();
2551 		aPBEntries.Disable();
2552 	}
2553 
2554 	CheckHdl( &aCBActiv );
2555     CheckHdl( &aCBCollect );
2556 }
2557 
2558 void OfaAutoCompleteTabPage::ActivatePage( const SfxItemSet& )
2559 {
2560 	((OfaAutoCorrDlg*)GetTabDialog())->EnableLanguage( sal_False );
2561 }
2562 
2563 IMPL_LINK( OfaAutoCompleteTabPage, DeleteHdl, PushButton*, EMPTYARG )
2564 {
2565 	sal_uInt16 nSelCnt = pAutoCmpltList ? aLBEntries.GetSelectEntryCount() : 0;
2566 	while( nSelCnt )
2567 	{
2568 		sal_uInt16 nPos = aLBEntries.GetSelectEntryPos( --nSelCnt );
2569 		const StringPtr pStr = (StringPtr)aLBEntries.GetEntryData( nPos );
2570 		aLBEntries.RemoveEntry( nPos );
2571 		nPos = pAutoCmpltList->GetPos( pStr );
2572 		if( USHRT_MAX != nPos )
2573 			pAutoCmpltList->Remove( nPos );
2574 	}
2575 	return 0;
2576 }
2577 
2578 IMPL_LINK( OfaAutoCompleteTabPage, CheckHdl, CheckBox*, pBox )
2579 {
2580     sal_Bool bEnable = pBox->IsChecked();
2581     if( pBox == &aCBActiv )
2582 	{
2583         aCBAppendSpace.Enable( bEnable );
2584         aCBAppendSpace.Enable( bEnable );
2585 		aCBAsTip.Enable( bEnable );
2586 		aDCBExpandKey.Enable( bEnable );
2587 	}
2588     else if(&aCBCollect == pBox)
2589         aCBRemoveList.Enable( bEnable );
2590     return 0;
2591 }
2592 
2593 void OfaAutoCompleteTabPage::CopyToClipboard() const
2594 {
2595 	sal_uInt16 nSelCnt = aLBEntries.GetSelectEntryCount();
2596 	if( pAutoCmpltList && nSelCnt )
2597 	{
2598 		TransferDataContainer* pCntnr = new TransferDataContainer;
2599 		::com::sun::star::uno::Reference<
2600 			::com::sun::star::datatransfer::XTransferable > xRef( pCntnr );
2601 
2602 		ByteString sData;
2603 		const sal_Char* pLineEnd =
2604 #if defined(UNX)
2605 				"\012";
2606 #else
2607 				"\015\012";
2608 #endif
2609 
2610 		rtl_TextEncoding nEncode = gsl_getSystemTextEncoding();
2611 
2612 		for( sal_uInt16 n = 0; n < nSelCnt; ++n )
2613 		{
2614 			sData += ByteString( aLBEntries.GetSelectEntry( n ), nEncode );
2615 			sData += pLineEnd;
2616 		}
2617 		pCntnr->CopyByteString( SOT_FORMAT_STRING, sData );
2618 		pCntnr->CopyToClipboard( (Window*)this );
2619 	}
2620 }
2621 
2622 long OfaAutoCompleteTabPage::AutoCompleteMultiListBox::PreNotify(
2623 			NotifyEvent& rNEvt )
2624 {
2625 	long nHandled = MultiListBox::PreNotify( rNEvt );
2626 
2627 	if( !nHandled && EVENT_KEYUP == rNEvt.GetType() )
2628 	{
2629 		const KeyCode& rKeyCode = rNEvt.GetKeyEvent()->GetKeyCode();
2630 		switch( rKeyCode.GetModifier() | rKeyCode.GetCode() )
2631 		{
2632 		case KEY_DELETE:
2633 			rPage.DeleteHdl( 0 );
2634 			nHandled = 1;
2635 			break;
2636 
2637 		default:
2638 			if( KEYFUNC_COPY == rKeyCode.GetFunction() )
2639 			{
2640 				rPage.CopyToClipboard();
2641 				nHandled = 1;
2642 			}
2643 			break;
2644 		}
2645 	}
2646 	return nHandled;
2647 }
2648 
2649 // class OfaSmartTagOptionsTabPage ---------------------------------------------
2650 
2651 OfaSmartTagOptionsTabPage::OfaSmartTagOptionsTabPage( Window* pParent,
2652 												      const SfxItemSet& rSet )
2653     : SfxTabPage(pParent, CUI_RES( RID_OFAPAGE_SMARTTAG_OPTIONS ), rSet),
2654     m_aMainCB( this, CUI_RES(CB_SMARTTAGS) ),
2655     m_aSmartTagTypesLB( this, CUI_RES(LB_SMARTTAGS) ),
2656     m_aPropertiesPB( this, CUI_RES(PB_SMARTTAGS) ),
2657     m_aTitleFT( this, CUI_RES(FT_SMARTTAGS) )
2658 {
2659 	FreeResource();
2660 
2661     // some options for the list box:
2662     m_aSmartTagTypesLB.SetStyle( m_aSmartTagTypesLB.GetStyle() | WB_HSCROLL | WB_HIDESELECTION );
2663 	m_aSmartTagTypesLB.SetHighlightRange();
2664 
2665     // set the handlers:
2666 	m_aMainCB.SetToggleHdl(LINK(this, OfaSmartTagOptionsTabPage, CheckHdl));
2667     m_aPropertiesPB.SetClickHdl(LINK(this, OfaSmartTagOptionsTabPage, ClickHdl));
2668     m_aSmartTagTypesLB.SetSelectHdl(LINK(this, OfaSmartTagOptionsTabPage, SelectHdl));
2669 }
2670 
2671 OfaSmartTagOptionsTabPage::~OfaSmartTagOptionsTabPage()
2672 {
2673 
2674 }
2675 
2676 SfxTabPage*	OfaSmartTagOptionsTabPage::Create( Window* pParent, const SfxItemSet& rSet)
2677 {
2678 	return new OfaSmartTagOptionsTabPage( pParent, rSet );
2679 }
2680 
2681 /** This struct is used to associate list box entries with smart tag data
2682 */
2683 struct ImplSmartTagLBUserData
2684 {
2685     rtl::OUString maSmartTagType;
2686     uno::Reference< smarttags::XSmartTagRecognizer > mxRec;
2687     sal_Int32 mnSmartTagIdx;
2688 
2689     ImplSmartTagLBUserData( const rtl::OUString& rSmartTagType,
2690                             uno::Reference< smarttags::XSmartTagRecognizer > xRec,
2691                             sal_Int32 nSmartTagIdx ) :
2692         maSmartTagType( rSmartTagType ),
2693         mxRec( xRec ),
2694         mnSmartTagIdx( nSmartTagIdx ) {}
2695 };
2696 
2697 /** Clears m_aSmartTagTypesLB
2698 */
2699 void OfaSmartTagOptionsTabPage::ClearListBox()
2700 {
2701     const sal_uLong nCount = m_aSmartTagTypesLB.GetEntryCount();
2702     for ( sal_uInt16 i = 0; i < nCount; ++i )
2703 	{
2704         const SvLBoxEntry* pEntry = m_aSmartTagTypesLB.GetEntry(i);
2705         const ImplSmartTagLBUserData* pUserData = static_cast< ImplSmartTagLBUserData* >(pEntry->GetUserData());
2706         delete pUserData;
2707     }
2708 
2709     m_aSmartTagTypesLB.Clear();
2710 }
2711 
2712 /** Inserts items into m_aSmartTagTypesLB
2713 */
2714 void OfaSmartTagOptionsTabPage::FillListBox( const SmartTagMgr& rSmartTagMgr )
2715 {
2716     // first we have to clear the list box:
2717     ClearListBox();
2718 
2719     // fill list box:
2720     const sal_uInt32 nNumberOfRecognizers = rSmartTagMgr.NumberOfRecognizers();
2721 	const lang::Locale aLocale( SvxCreateLocale( eLastDialogLanguage ) );
2722     std::vector< ActionReference > aActionReferences;
2723 
2724     for ( sal_uInt32 i = 0; i < nNumberOfRecognizers; ++i )
2725     {
2726         uno::Reference< smarttags::XSmartTagRecognizer > xRec = rSmartTagMgr.GetRecognizer(i);
2727 
2728         const rtl::OUString aName = xRec->getName( aLocale );
2729         const rtl::OUString aDesc = xRec->getDescription( aLocale );
2730         const sal_Int32 nNumberOfSupportedSmartTags = xRec->getSmartTagCount();
2731 
2732         for ( sal_Int32 j = 0; j < nNumberOfSupportedSmartTags; ++j )
2733         {
2734             const rtl::OUString aSmartTagType = xRec->getSmartTagName(j);
2735             rtl::OUString aSmartTagCaption = rSmartTagMgr.GetSmartTagCaption( aSmartTagType, aLocale );
2736 
2737             if ( !aSmartTagCaption.getLength() )
2738                 aSmartTagCaption = aSmartTagType;
2739 
2740             const rtl::OUString aLBEntry = aSmartTagCaption +
2741                                            OUString::createFromAscii(" (") +
2742                                            aName +
2743                                            OUString::createFromAscii(")");
2744 
2745             SvLBoxEntry* pEntry = m_aSmartTagTypesLB.SvTreeListBox::InsertEntry( aLBEntry );
2746             if ( pEntry )
2747             {
2748                 const bool bCheck = rSmartTagMgr.IsSmartTagTypeEnabled( aSmartTagType );
2749                 m_aSmartTagTypesLB.SetCheckButtonState( pEntry, bCheck ? SV_BUTTON_CHECKED : SV_BUTTON_UNCHECKED );
2750                 pEntry->SetUserData(static_cast<void*>(new ImplSmartTagLBUserData( aSmartTagType, xRec, j ) ) );
2751             }
2752         }
2753     }
2754 }
2755 
2756 /** Handler for the push button
2757 */
2758 IMPL_LINK( OfaSmartTagOptionsTabPage, ClickHdl, PushButton*, EMPTYARG )
2759 {
2760 	const sal_uInt16 nPos = m_aSmartTagTypesLB.GetSelectEntryPos();
2761     const SvLBoxEntry* pEntry = m_aSmartTagTypesLB.GetEntry(nPos);
2762     const ImplSmartTagLBUserData* pUserData = static_cast< ImplSmartTagLBUserData* >(pEntry->GetUserData());
2763     uno::Reference< smarttags::XSmartTagRecognizer > xRec = pUserData->mxRec;
2764     const sal_Int32 nSmartTagIdx = pUserData->mnSmartTagIdx;
2765 
2766  	const lang::Locale aLocale( SvxCreateLocale( eLastDialogLanguage ) );
2767     if ( xRec->hasPropertyPage( nSmartTagIdx, aLocale ) )
2768         xRec->displayPropertyPage( nSmartTagIdx, aLocale );
2769 
2770 	return 0;
2771 }
2772 
2773 /** Handler for the check box
2774 */
2775 IMPL_LINK( OfaSmartTagOptionsTabPage, CheckHdl, CheckBox*, EMPTYARG )
2776 {
2777     const sal_Bool bEnable = m_aMainCB.IsChecked();
2778     m_aSmartTagTypesLB.Enable( bEnable );
2779     m_aSmartTagTypesLB.Invalidate();
2780     m_aPropertiesPB.Enable( false );
2781 
2782     // if the controls are currently enabled, we still have to check
2783     // if the properties button should be disabled because the currently
2784     // seleted smart tag type does not have a properties dialog.
2785     // We do this by calling SelectHdl:
2786     if ( bEnable )
2787         SelectHdl( &m_aSmartTagTypesLB );
2788 
2789     return 0;
2790 }
2791 
2792 /** Handler for the list box
2793 */
2794 IMPL_LINK(OfaSmartTagOptionsTabPage, SelectHdl, SvxCheckListBox*, EMPTYARG)
2795 {
2796     if ( m_aSmartTagTypesLB.GetEntryCount() < 1 )
2797         return 0;
2798 
2799 	const sal_uInt16 nPos = m_aSmartTagTypesLB.GetSelectEntryPos();
2800     const SvLBoxEntry* pEntry = m_aSmartTagTypesLB.GetEntry(nPos);
2801     const ImplSmartTagLBUserData* pUserData = static_cast< ImplSmartTagLBUserData* >(pEntry->GetUserData());
2802     uno::Reference< smarttags::XSmartTagRecognizer > xRec = pUserData->mxRec;
2803     const sal_Int32 nSmartTagIdx = pUserData->mnSmartTagIdx;
2804 
2805     const lang::Locale aLocale( SvxCreateLocale( eLastDialogLanguage ) );
2806     if ( xRec->hasPropertyPage( nSmartTagIdx, aLocale ) )
2807         m_aPropertiesPB.Enable( sal_True );
2808     else
2809         m_aPropertiesPB.Enable( sal_False );
2810 
2811 	return 0;
2812 }
2813 
2814 /** Propagates the current settings to the smart tag manager.
2815 */
2816 sal_Bool OfaSmartTagOptionsTabPage::FillItemSet( SfxItemSet& )
2817 {
2818 	SvxAutoCorrect* pAutoCorrect = SvxAutoCorrCfg::Get()->GetAutoCorrect();
2819 	SvxSwAutoFmtFlags *pOpt = &pAutoCorrect->GetSwFlags();
2820     SmartTagMgr* pSmartTagMgr = pOpt->pSmartTagMgr;
2821 
2822     // robust!
2823     if ( !pSmartTagMgr )
2824         return sal_False;
2825 
2826     sal_Bool bModifiedSmartTagTypes = sal_False;
2827     std::vector< rtl::OUString > aDisabledSmartTagTypes;
2828 
2829     const sal_uLong nCount = m_aSmartTagTypesLB.GetEntryCount();
2830 
2831     for ( sal_uInt16 i = 0; i < nCount; ++i )
2832 	{
2833         const SvLBoxEntry* pEntry = m_aSmartTagTypesLB.GetEntry(i);
2834         const ImplSmartTagLBUserData* pUserData = static_cast< ImplSmartTagLBUserData* >(pEntry->GetUserData());
2835 		const sal_Bool bChecked = m_aSmartTagTypesLB.IsChecked(i);
2836         const sal_Bool bIsCurrentlyEnabled = pSmartTagMgr->IsSmartTagTypeEnabled( pUserData->maSmartTagType );
2837 
2838         bModifiedSmartTagTypes = bModifiedSmartTagTypes || ( !bChecked != !bIsCurrentlyEnabled );
2839 
2840         if ( !bChecked )
2841             aDisabledSmartTagTypes.push_back( pUserData->maSmartTagType );
2842 
2843         delete pUserData;
2844     }
2845 
2846     const sal_Bool bModifiedRecognize = ( !m_aMainCB.IsChecked() != !pSmartTagMgr->IsLabelTextWithSmartTags() );
2847     if ( bModifiedSmartTagTypes || bModifiedRecognize )
2848     {
2849         bool bLabelTextWithSmartTags = m_aMainCB.IsChecked() ? true : false;
2850         pSmartTagMgr->WriteConfiguration( bModifiedRecognize     ? &bLabelTextWithSmartTags : 0,
2851                                           bModifiedSmartTagTypes ? &aDisabledSmartTagTypes : 0 );
2852     }
2853 
2854 	return sal_True;
2855 }
2856 
2857 /** Sets the controls based on the current settings at SmartTagMgr.
2858 */
2859 void OfaSmartTagOptionsTabPage::Reset( const SfxItemSet&  )
2860 {
2861 	SvxAutoCorrect* pAutoCorrect = SvxAutoCorrCfg::Get()->GetAutoCorrect();
2862 	SvxSwAutoFmtFlags *pOpt = &pAutoCorrect->GetSwFlags();
2863     const SmartTagMgr* pSmartTagMgr = pOpt->pSmartTagMgr;
2864 
2865     // robust, should not happen!
2866     if ( !pSmartTagMgr )
2867         return;
2868 
2869     FillListBox( *pSmartTagMgr );
2870 	m_aSmartTagTypesLB.SelectEntryPos( 0 );
2871     m_aMainCB.Check( pSmartTagMgr->IsLabelTextWithSmartTags() );
2872     CheckHdl( &m_aMainCB );
2873 }
2874 
2875 void OfaSmartTagOptionsTabPage::ActivatePage( const SfxItemSet& )
2876 {
2877 	((OfaAutoCorrDlg*)GetTabDialog())->EnableLanguage( sal_False );
2878 }
2879 
2880