xref: /aoo41x/main/cui/source/tabpages/autocdlg.cxx (revision 2d6beb75)
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<
GetProcessFact()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 
OfaAutoCorrDlg(Window * pParent,const SfxItemSet * _pSet)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 
lcl_FindEntry(ListBox & rLB,const String & rEntry,CollatorWrapper & rCmpClass)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  * --------------------------------------------------*/
IMPL_LINK(OfaAutoCorrDlg,SelectLanguageHdl,ListBox *,pBox)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 
OfaAutocorrOptionsPage(Window * pParent,const SfxItemSet & rSet)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 
~OfaAutocorrOptionsPage()235 OfaAutocorrOptionsPage::~OfaAutocorrOptionsPage()
236 {
237 }
238 
239 /*-----------------14.10.96 15.58-------------------
240 
241 --------------------------------------------------*/
242 
243 
Create(Window * pParent,const SfxItemSet & rSet)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 
FillItemSet(SfxItemSet &)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  * --------------------------------------------------*/
ActivatePage(const SfxItemSet &)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 
Reset(const SfxItemSet &)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 
ImpUserDataImpUserData330 	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:
OfaAutoFmtPrcntSet(Window * pParent)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 			}
GetPrcntFld()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 
OfaImpBrwString(SvLBoxEntry * pEntry,sal_uInt16 nFlags,const String & rStr)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 
Paint(const Point & rPos,SvLBox & rDev,sal_uInt16,SvLBoxEntry * pEntry)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 
OfaSwAutoFmtOptionsPage(Window * pParent,const SfxItemSet & rSet)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 
CreateEntry(String & rTxt,sal_uInt16 nCol)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 
~OfaSwAutoFmtOptionsPage()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 
Create(Window * pParent,const SfxItemSet & rAttrSet)561 SfxTabPage* __EXPORT OfaSwAutoFmtOptionsPage::Create( Window* pParent,
562 								const SfxItemSet& rAttrSet)
563 {
564 	return new OfaSwAutoFmtOptionsPage(pParent, rAttrSet);
565 }
566 
567 /*********************************************************************/
568 /*                                                                   */
569 /*********************************************************************/
570 
FillItemSet(SfxItemSet &)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  * --------------------------------------------------*/
ActivatePage(const SfxItemSet &)687 void	OfaSwAutoFmtOptionsPage::ActivatePage( const SfxItemSet& )
688 {
689 	((OfaAutoCorrDlg*)GetTabDialog())->EnableLanguage(sal_False);
690 }
691 
692 /*********************************************************************/
693 /*                                                                   */
694 /*********************************************************************/
695 
696 
Reset(const SfxItemSet &)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.AppendAscii( " %" );
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 
IMPL_LINK(OfaSwAutoFmtOptionsPage,SelectHdl,OfaACorrCheckListBox *,pBox)779 IMPL_LINK(OfaSwAutoFmtOptionsPage, SelectHdl, OfaACorrCheckListBox*, pBox)
780 {
781 	aEditPB.Enable(0 != pBox->FirstSelected()->GetUserData());
782 	return 0;
783 }
784 
785 /*********************************************************************/
786 /*                                                                   */
787 /*********************************************************************/
788 
IMPL_LINK(OfaSwAutoFmtOptionsPage,EditHdl,PushButton *,EMPTYARG)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.AppendAscii( " %" );
821 		}
822 	}
823 	aCheckLB.Invalidate();
824 	return 0;
825 }
826 
827 /*********************************************************************/
828 /*                                                                   */
829 /*********************************************************************/
830 
SetTabs()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 
CheckEntryPos(sal_uLong nPos,sal_uInt16 nCol,sal_Bool bChecked)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 
IsChecked(sal_uLong nPos,sal_uInt16 nCol)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 
SetCheckButtonState(SvLBoxEntry * pEntry,sal_uInt16 nCol,SvButtonState eState)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 
GetCheckButtonState(SvLBoxEntry * pEntry,sal_uInt16 nCol) const906 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 
HBarClick()921 void OfaACorrCheckListBox::HBarClick()
922 {
923 	// Sortierung durch diese Ueberladung abgeklemmt
924 }
925 /* -----------------------------22.05.2002 11:06------------------------------
926 
927  ---------------------------------------------------------------------------*/
KeyInput(const KeyEvent & rKEvt)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  * --------------------------------------------------*/
lcl_ClearTable(DoubleStringTable & rTable)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 
OfaAutocorrReplacePage(Window * pParent,const SfxItemSet & rSet)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 
~OfaAutocorrReplacePage()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 
Create(Window * pParent,const SfxItemSet & rSet)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  * --------------------------------------------------*/
ActivatePage(const SfxItemSet &)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  * --------------------------------------------------*/
DeactivatePage(SfxItemSet *)1065 int OfaAutocorrReplacePage::DeactivatePage( SfxItemSet*  )
1066 {
1067 	return LEAVE_PAGE;
1068 }
1069 /*-----------------14.10.96 15.58-------------------
1070 
1071 --------------------------------------------------*/
1072 
FillItemSet(SfxItemSet &)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  * --------------------------------------------------*/
RefillReplaceBox(sal_Bool bFromReset,LanguageType eOldLanguage,LanguageType eNewLanguage)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 
Reset(const SfxItemSet &)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  * --------------------------------------------------*/
SetLanguage(LanguageType eSet)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 
IMPL_LINK(OfaAutocorrReplacePage,SelectHdl,SvTabListBox *,pBox)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 
IMPL_LINK(OfaAutocorrReplacePage,NewDelHdl,PushButton *,pBtn)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 --------------------------------------------------*/
IMPL_LINK(OfaAutocorrReplacePage,ModifyHdl,Edit *,pEdt)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 
StringsArraysStringsArrays1551 	StringsArrays() :
1552 		aAbbrevStrings(5,5), aDoubleCapsStrings(5,5) {}
1553 };
1554 typedef StringsArrays* StringsArraysPtr;
1555 /* -----------------19.11.98 16:07-------------------
1556  *
1557  * --------------------------------------------------*/
lcl_FindInArray(SvStringsDtor & rStrings,const String & rString)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 
lcl_ClearTable(StringsTable & rTable)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 
OfaAutocorrExceptPage(Window * pParent,const SfxItemSet & rSet)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 
~OfaAutocorrExceptPage()1632 OfaAutocorrExceptPage::~OfaAutocorrExceptPage()
1633 {
1634 	lcl_ClearTable(aStringsTable);
1635 	delete pCompareClass;
1636 }
1637 
1638 /*-----------------14.10.96 15.58-------------------
1639 
1640 --------------------------------------------------*/
1641 
Create(Window * pParent,const SfxItemSet & rSet)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  * --------------------------------------------------*/
ActivatePage(const SfxItemSet &)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  * --------------------------------------------------*/
DeactivatePage(SfxItemSet *)1659 int     OfaAutocorrExceptPage::DeactivatePage( SfxItemSet* )
1660 {
1661 	return LEAVE_PAGE;
1662 }
1663 /*-----------------14.10.96 15.58-------------------
1664 
1665 --------------------------------------------------*/
1666 
FillItemSet(SfxItemSet &)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  * --------------------------------------------------*/
SetLanguage(LanguageType eSet)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  * --------------------------------------------------*/
RefillReplaceBoxes(sal_Bool bFromReset,LanguageType eOldLanguage,LanguageType eNewLanguage)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 
Reset(const SfxItemSet &)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 
IMPL_LINK(OfaAutocorrExceptPage,NewDelHdl,PushButton *,pBtn)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 
IMPL_LINK(OfaAutocorrExceptPage,SelectHdl,ListBox *,pBox)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 
IMPL_LINK(OfaAutocorrExceptPage,ModifyHdl,Edit *,pEdt)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 
KeyInput(const KeyEvent & rKEvt)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 
CreateEntry(String & rTxt,sal_uInt16 nCol)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 
OfaQuoteTabPage(Window * pParent,const SfxItemSet & rSet)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 	// Move down from the position before FreeResource()
2104 	// For lost help ID issue
2105 	aSglStandardPB.SetAccessibleName(String(CUI_RES(STR_PB_SGL_STD) ) );
2106 	aDblStandardPB.SetAccessibleName(String(CUI_RES(STR_PB_DBL_STD) ) );
2107 	aStartQuotePB.SetAccessibleName( String(CUI_RES(STR_PB_DBL_START) ));
2108 	aEndQuotePB.SetAccessibleName(String(CUI_RES(STR_PB_DBL_END) ));
2109 	aSglStartQuotePB.SetAccessibleName(String(CUI_RES(STR_PB_SGL_START) ));
2110 	aSglEndQuotePB.SetAccessibleName(String(CUI_RES(STR_PB_SGL_END) ) );
2111 	aSglStartQuotePB.SetAccessibleRelationLabeledBy( &aSglStartQuoteFT );
2112 	aSglEndQuotePB.SetAccessibleRelationLabeledBy( &aSglEndQuoteFT );
2113 	aSglStartQuotePB.SetAccessibleRelationMemberOf( &aSingleFL );
2114 	aSglEndQuotePB.SetAccessibleRelationMemberOf( &aSingleFL );
2115 	aStartQuotePB.SetAccessibleRelationLabeledBy( &aStartQuoteFT );
2116 	aEndQuotePB.SetAccessibleRelationLabeledBy( &aEndQuoteFT );
2117 	aStartQuotePB.SetAccessibleRelationMemberOf( &aDoubleFL );
2118 	aEndQuotePB.SetAccessibleRelationMemberOf( &aDoubleFL );
2119 	aSglStandardPB.SetAccessibleRelationMemberOf(&aSingleFL);
2120 	aDblStandardPB.SetAccessibleRelationMemberOf(&aDoubleFL);
2121 }
2122 /*-----------------03.07.97 13:17-------------------
2123 
2124 --------------------------------------------------*/
~OfaQuoteTabPage()2125 OfaQuoteTabPage::~OfaQuoteTabPage()
2126 {
2127     delete( pCheckButtonData );
2128 }
2129 /*-----------------03.07.97 13:17-------------------
2130 
2131 --------------------------------------------------*/
Create(Window * pParent,const SfxItemSet & rAttrSet)2132 SfxTabPage*	OfaQuoteTabPage::Create( Window* pParent,
2133 								const SfxItemSet& rAttrSet)
2134 {
2135 	return new OfaQuoteTabPage(pParent, rAttrSet);
2136 }
2137 /*-----------------03.07.97 13:18-------------------
2138 
2139 --------------------------------------------------*/
FillItemSet(SfxItemSet &)2140 sal_Bool OfaQuoteTabPage::FillItemSet( SfxItemSet&  )
2141 {
2142 	SvxAutoCorrect* pAutoCorrect = SvxAutoCorrCfg::Get()->GetAutoCorrect();
2143 
2144 	long nFlags = pAutoCorrect->GetFlags();
2145 
2146     if ( aCheckLB.IsVisible( ) )
2147     {
2148 	    sal_uInt16 nPos = 0;
2149         pAutoCorrect->SetAutoCorrFlag(AddNonBrkSpace,		aCheckLB.IsChecked(nPos++));
2150 	    pAutoCorrect->SetAutoCorrFlag(ChgOrdinalNumber,		aCheckLB.IsChecked(nPos++));
2151     }
2152 
2153     sal_Bool bModified = sal_False;
2154     if ( aSwCheckLB.IsVisible( ) )
2155     {
2156 	    SvxSwAutoFmtFlags *pOpt = &pAutoCorrect->GetSwFlags();
2157 
2158         sal_Bool bCheck = aSwCheckLB.IsChecked(ADD_NONBRK_SPACE, CBCOL_FIRST);
2159 	    bModified |= pOpt->bAddNonBrkSpace != bCheck;
2160         pOpt->bAddNonBrkSpace = bCheck;
2161         pAutoCorrect->SetAutoCorrFlag(AddNonBrkSpace,
2162                             aSwCheckLB.IsChecked(ADD_NONBRK_SPACE, CBCOL_SECOND));
2163 
2164     	bCheck = aSwCheckLB.IsChecked(REPLACE_1ST, CBCOL_FIRST);
2165 	    bModified |= pOpt->bChgOrdinalNumber != bCheck;
2166     	pOpt->bChgOrdinalNumber = bCheck;
2167 	    pAutoCorrect->SetAutoCorrFlag(ChgOrdinalNumber,
2168 						aSwCheckLB.IsChecked(REPLACE_1ST, CBCOL_SECOND));
2169     }
2170 
2171 	pAutoCorrect->SetAutoCorrFlag(ChgQuotes, 		aTypoCB.IsChecked());
2172 	pAutoCorrect->SetAutoCorrFlag(ChgSglQuotes, 	aSingleTypoCB.IsChecked());
2173 	sal_Bool bReturn = nFlags != pAutoCorrect->GetFlags();
2174 	if(cStartQuote != pAutoCorrect->GetStartDoubleQuote())
2175 	{
2176 		bReturn = sal_True;
2177 		sal_Unicode cUCS2 = static_cast<sal_Unicode>(cStartQuote); //TODO
2178 		pAutoCorrect->SetStartDoubleQuote(cUCS2);
2179 	}
2180 	if(cEndQuote != pAutoCorrect->GetEndDoubleQuote())
2181 	{
2182 		bReturn = sal_True;
2183 		sal_Unicode cUCS2 = static_cast<sal_Unicode>(cEndQuote); //TODO
2184 		pAutoCorrect->SetEndDoubleQuote(cUCS2);
2185 	}
2186 	if(cSglStartQuote != pAutoCorrect->GetStartSingleQuote())
2187 	{
2188 		bReturn = sal_True;
2189 		sal_Unicode cUCS2 = static_cast<sal_Unicode>(cSglStartQuote); //TODO
2190 		pAutoCorrect->SetStartSingleQuote(cUCS2);
2191 	}
2192 	if(cSglEndQuote != pAutoCorrect->GetEndSingleQuote())
2193 	{
2194 		bReturn = sal_True;
2195 		sal_Unicode cUCS2 = static_cast<sal_Unicode>(cSglEndQuote); //TODO
2196 		pAutoCorrect->SetEndSingleQuote(cUCS2);
2197 	}
2198 
2199 	if( bModified || bReturn )
2200     {
2201         SvxAutoCorrCfg* pCfg = SvxAutoCorrCfg::Get();
2202         pCfg->SetModified();
2203         pCfg->Commit();
2204     }
2205 	return bReturn;
2206 }
2207 /* -----------------23.11.98 16:15-------------------
2208  *
2209  * --------------------------------------------------*/
ActivatePage(const SfxItemSet &)2210 void OfaQuoteTabPage::ActivatePage( const SfxItemSet& )
2211 {
2212 	((OfaAutoCorrDlg*)GetTabDialog())->EnableLanguage(sal_False);
2213 }
2214 /*-----------------03.07.97 13:18-------------------
2215 
2216 --------------------------------------------------*/
Reset(const SfxItemSet &)2217 void OfaQuoteTabPage::Reset( const SfxItemSet& )
2218 {
2219 	SvxAutoCorrect* pAutoCorrect = SvxAutoCorrCfg::Get()->GetAutoCorrect();
2220 	const long nFlags = pAutoCorrect->GetFlags();
2221 
2222     // Initialize the Sw options
2223     if ( aSwCheckLB.IsVisible( ) )
2224     {
2225         SvxSwAutoFmtFlags *pOpt = &pAutoCorrect->GetSwFlags();
2226 
2227         aSwCheckLB.SetUpdateMode( sal_False );
2228         aSwCheckLB.Clear();
2229 
2230         aSwCheckLB.GetModel()->Insert(CreateEntry(sNonBrkSpace,       CBCOL_BOTH ));
2231         aSwCheckLB.GetModel()->Insert(CreateEntry(sOrdinal,           CBCOL_BOTH ));
2232 
2233         aSwCheckLB.CheckEntryPos( ADD_NONBRK_SPACE, CBCOL_FIRST,	pOpt->bAddNonBrkSpace );
2234         aSwCheckLB.CheckEntryPos( ADD_NONBRK_SPACE,	CBCOL_SECOND,	0 != (nFlags & AddNonBrkSpace) );
2235         aSwCheckLB.CheckEntryPos( REPLACE_1ST,		CBCOL_FIRST,	pOpt->bChgOrdinalNumber );
2236         aSwCheckLB.CheckEntryPos( REPLACE_1ST,		CBCOL_SECOND,	0 != (nFlags & ChgOrdinalNumber) );
2237 
2238         aSwCheckLB.SetUpdateMode( sal_True );
2239     }
2240 
2241     // Initialize the non Sw options
2242     if ( aCheckLB.IsVisible( ) )
2243     {
2244         aCheckLB.SetUpdateMode( sal_False );
2245         aCheckLB.Clear( );
2246 
2247         aCheckLB.InsertEntry( sNonBrkSpace );
2248         aCheckLB.InsertEntry( sOrdinal );
2249 
2250         sal_uInt16 nPos = 0;
2251         aCheckLB.CheckEntryPos( nPos++, 0 != (nFlags & AddNonBrkSpace) );
2252         aCheckLB.CheckEntryPos( nPos++, 0 != (nFlags & ChgOrdinalNumber) );
2253 
2254         aCheckLB.SetUpdateMode( sal_True );
2255     }
2256 
2257     // Initialize the quote stuffs
2258 	aTypoCB    			.Check(0 != (nFlags & ChgQuotes));
2259 	aSingleTypoCB    	.Check(0 != (nFlags & ChgSglQuotes));
2260 	aTypoCB    			.SaveValue();
2261 	aSingleTypoCB    	.SaveValue();
2262 
2263 	cStartQuote = pAutoCorrect->GetStartDoubleQuote();
2264 	cEndQuote = pAutoCorrect->GetEndDoubleQuote();
2265 	cSglStartQuote = pAutoCorrect->GetStartSingleQuote();
2266 	cSglEndQuote = pAutoCorrect->GetEndSingleQuote();
2267 
2268 	aSglStartExFT .SetText(ChangeStringExt_Impl(cSglStartQuote));
2269 	aSglEndExFT   .SetText(ChangeStringExt_Impl(cSglEndQuote));
2270 	aDblStartExFT .SetText(ChangeStringExt_Impl(cStartQuote));
2271 	aDblEndExFT   .SetText(ChangeStringExt_Impl(cEndQuote));
2272 }
2273 
2274 
2275 /*-----------------15.10.96 16.42-------------------
2276 
2277 --------------------------------------------------*/
2278 #define SGL_START		0
2279 #define DBL_START       1
2280 #define SGL_END         2
2281 #define DBL_END         3
2282 
2283 
IMPL_LINK(OfaQuoteTabPage,QuoteHdl,PushButton *,pBtn)2284 IMPL_LINK( OfaQuoteTabPage, QuoteHdl, PushButton*, pBtn )
2285 {
2286 	sal_uInt16 nMode = SGL_START;
2287 	if(pBtn == &aSglEndQuotePB)
2288 		nMode = SGL_END;
2289 	else if(pBtn == &aStartQuotePB)
2290 		nMode = DBL_START;
2291 	else if(pBtn == &aEndQuotePB)
2292 		nMode = DBL_END;
2293 	// Zeichenauswahl-Dialog starten
2294 	SvxCharacterMap* pMap = new SvxCharacterMap( this, sal_True );
2295 	pMap->SetCharFont( OutputDevice::GetDefaultFont(DEFAULTFONT_LATIN_TEXT,
2296 						LANGUAGE_ENGLISH_US, DEFAULTFONT_FLAGS_ONLYONE, 0 ));
2297 	pMap->SetText(nMode < SGL_END ? sStartQuoteDlg  :  sEndQuoteDlg );
2298 	sal_UCS4 cDlg;
2299 	//The two lines below are added by BerryJia for Bug95846 Time:2002-8-13 15:50
2300 	SvxAutoCorrect* pAutoCorrect = SvxAutoCorrCfg::Get()->GetAutoCorrect();
2301 	LanguageType eLang = Application::GetSettings().GetLanguage();
2302 	switch( nMode )
2303 	{
2304 		case SGL_START:
2305 			cDlg = cSglStartQuote;
2306 			if(cDlg == 0)
2307 				cDlg = pAutoCorrect->GetQuote('\'',sal_True,eLang);   //add by BerryJia for Bug95846 Time:2002-8-13 15:50
2308 		break;
2309 		case SGL_END:
2310 			cDlg = cSglEndQuote;
2311 			if(cDlg == 0)
2312 				cDlg = pAutoCorrect->GetQuote('\'',sal_False,eLang);  //add by BerryJia for Bug95846 Time:2002-8-13 15:50
2313 		break;
2314 		case DBL_START:
2315 			cDlg = cStartQuote;
2316 			if(cDlg == 0)
2317 				cDlg = pAutoCorrect->GetQuote('\"',sal_True,eLang);   //add by BerryJia for Bug95846 Time:2002-8-13 15:50
2318 		break;
2319 		case DBL_END:
2320 			cDlg = cEndQuote;
2321 			if(cDlg == 0)
2322 				cDlg = pAutoCorrect->GetQuote('\"',sal_False,eLang);  //add by BerryJia for Bug95846 Time:2002-8-13 15:50
2323 		break;
2324 		default:
2325 			DBG_ERROR("svx::OfaQuoteTabPage::QuoteHdl(), how to initialize cDlg?" );
2326 			cDlg = 0;
2327 			break;
2328 
2329 	}
2330 	pMap->SetChar(  cDlg );
2331 	pMap->DisableFontSelection();
2332 	if(pMap->Execute() == RET_OK)
2333 	{
2334 		sal_UCS4 cNewChar = pMap->GetChar();
2335 		switch( nMode )
2336 		{
2337 			case SGL_START:
2338 				cSglStartQuote = cNewChar;
2339 				aSglStartExFT.SetText(ChangeStringExt_Impl(cNewChar));
2340 			break;
2341 			case SGL_END:
2342 				cSglEndQuote = cNewChar;
2343 				aSglEndExFT.SetText(ChangeStringExt_Impl(cNewChar));
2344 			break;
2345 			case DBL_START:
2346 				cStartQuote = cNewChar;
2347 				aDblStartExFT.SetText(ChangeStringExt_Impl(cNewChar));
2348 			break;
2349 			case DBL_END:
2350 				cEndQuote = cNewChar;
2351 				aDblEndExFT.SetText(ChangeStringExt_Impl(cNewChar));
2352 			break;
2353 		}
2354 	}
2355 	delete pMap;
2356 
2357 	return 0;
2358 }
2359 
2360 /*-----------------27.06.97 09.55-------------------
2361 
2362 --------------------------------------------------*/
IMPL_LINK(OfaQuoteTabPage,StdQuoteHdl,PushButton *,pBtn)2363 IMPL_LINK( OfaQuoteTabPage, StdQuoteHdl, PushButton*, pBtn )
2364 {
2365 	if(pBtn == &aDblStandardPB)
2366 	{
2367 		cStartQuote = 0;
2368 		aDblStartExFT.SetText(ChangeStringExt_Impl(0));
2369 		cEndQuote = 0;
2370 		aDblEndExFT.SetText(ChangeStringExt_Impl(0));
2371 
2372 	}
2373 	else
2374 	{
2375 		cSglStartQuote = 0;
2376 		aSglStartExFT.SetText(ChangeStringExt_Impl(0));
2377 		cSglEndQuote = 0;
2378 		aSglEndExFT.SetText(ChangeStringExt_Impl(0));
2379 	}
2380 	return 0;
2381 }
2382 
2383 // --------------------------------------------------
2384 
ChangeStringExt_Impl(sal_UCS4 cChar)2385 String OfaQuoteTabPage::ChangeStringExt_Impl( sal_UCS4 cChar )
2386 {
2387 	if( !cChar )
2388 		return sStandard;
2389 
2390     // convert codepoint value to unicode-hex string
2391 	sal_UCS4 aStrCodes[32] = { 0, ' ', '(', 'U', '+', '0' };
2392 	aStrCodes[0] = cChar;
2393 	int nFullLen = 5;
2394     int nHexLen = 4;
2395     while( (cChar >> (4*nHexLen)) != 0 )
2396         ++nHexLen;
2397     for( int i = nHexLen; --i >= 0;)
2398     {
2399         sal_UCS4 cHexDigit = ((cChar >> (4*i)) & 0x0f) + '0';
2400 		if( cHexDigit > '9' )
2401 			cHexDigit += 'A' - ('9' + 1);
2402 		aStrCodes[ nFullLen++ ] = cHexDigit;
2403     }
2404 	aStrCodes[ nFullLen++ ] = ')';
2405 	// using the new UCS4 constructor
2406 	rtl::OUString aOUStr( aStrCodes, nFullLen );
2407 	return aOUStr;
2408 }
2409 
OfaAutoCompleteTabPage(Window * pParent,const SfxItemSet & rSet)2410 OfaAutoCompleteTabPage::OfaAutoCompleteTabPage( Window* pParent,
2411 												const SfxItemSet& rSet )
2412 	: SfxTabPage(pParent, CUI_RES( RID_OFAPAGE_AUTOCOMPLETE_OPTIONS ), rSet),
2413 	aCBActiv		(this, CUI_RES(CB_ACTIV)),
2414     aCBAppendSpace  (this, CUI_RES(CB_APPEND_SPACE)),
2415     aCBAsTip        (this, CUI_RES(CB_AS_TIP)),
2416     aCBCollect      (this, CUI_RES(CB_COLLECT)),
2417     aCBRemoveList   (this, CUI_RES(CB_REMOVE_LIST)),
2418     aFTExpandKey    (this, CUI_RES(FT_EXPAND_KEY)),
2419     aDCBExpandKey   (this, CUI_RES(DCB_EXPAND_KEY)),
2420     aFTMinWordlen   (this, CUI_RES(FT_MIN_WORDLEN)),
2421     aNFMinWordlen   (this, CUI_RES(NF_MIN_WORDLEN)),
2422     aFTMaxEntries   (this, CUI_RES(FT_MAX_ENTRIES)),
2423     aNFMaxEntries   (this, CUI_RES(NF_MAX_ENTRIES)),
2424     aLBEntries      (*this, CUI_RES(LB_ENTRIES)),
2425 	aPBEntries      (this, CUI_RES(PB_ENTRIES)),
2426 	pAutoCmpltList( 0 ),
2427 	nAutoCmpltListCnt( 0 )
2428 {
2429 	FreeResource();
2430 
2431 	// the defined KEYs
2432 	static const sal_uInt16 aKeyCodes[] = {
2433 		KEY_END,
2434 		KEY_RETURN,
2435 		KEY_SPACE,
2436 		KEY_RIGHT,
2437         KEY_TAB,
2438 		0
2439 	};
2440 
2441 	for( const sal_uInt16* pKeys = aKeyCodes; *pKeys; ++pKeys )
2442 	{
2443 		KeyCode aKCode( *pKeys );
2444 		sal_uInt16 nPos = aDCBExpandKey.InsertEntry( aKCode.GetName() );
2445 		aDCBExpandKey.SetEntryData( nPos, (void*)(sal_uLong)*pKeys );
2446 		if( KEY_RETURN == *pKeys )		// default to RETURN
2447 			aDCBExpandKey.SelectEntryPos( nPos );
2448 	}
2449 
2450 	aPBEntries.SetClickHdl(LINK(this, OfaAutoCompleteTabPage, DeleteHdl));
2451 	aCBActiv.SetToggleHdl(LINK(this, OfaAutoCompleteTabPage, CheckHdl));
2452     aCBCollect.SetToggleHdl(LINK(this, OfaAutoCompleteTabPage, CheckHdl));
2453 	aLBEntries.SetAccessibleRelationLabeledBy(&aLBEntries);
2454 }
2455 
~OfaAutoCompleteTabPage()2456 OfaAutoCompleteTabPage::~OfaAutoCompleteTabPage()
2457 {
2458 }
2459 
Create(Window * pParent,const SfxItemSet & rSet)2460 SfxTabPage*	OfaAutoCompleteTabPage::Create( Window* pParent,
2461 											const SfxItemSet& rSet)
2462 {
2463 	return new OfaAutoCompleteTabPage( pParent, rSet );
2464 }
2465 
FillItemSet(SfxItemSet &)2466 sal_Bool OfaAutoCompleteTabPage::FillItemSet( SfxItemSet& )
2467 {
2468 	sal_Bool bModified = sal_False, bCheck;
2469 	SvxAutoCorrect* pAutoCorrect = SvxAutoCorrCfg::Get()->GetAutoCorrect();
2470 	SvxSwAutoFmtFlags *pOpt = &pAutoCorrect->GetSwFlags();
2471 	sal_uInt16 nVal;
2472 
2473 	bCheck = aCBActiv.IsChecked();
2474 	bModified |= pOpt->bAutoCompleteWords != bCheck;
2475 	pOpt->bAutoCompleteWords = bCheck;
2476 	bCheck = aCBCollect.IsChecked();
2477 	bModified |= pOpt->bAutoCmpltCollectWords != bCheck;
2478 	pOpt->bAutoCmpltCollectWords = bCheck;
2479     bCheck = !aCBRemoveList.IsChecked(); // inverted value!
2480     bModified |= pOpt->bAutoCmpltKeepList != bCheck;
2481     pOpt->bAutoCmpltKeepList = bCheck;
2482     bCheck = aCBAppendSpace.IsChecked();
2483 	bModified |= pOpt->bAutoCmpltAppendBlanc != bCheck;
2484 	pOpt->bAutoCmpltAppendBlanc = bCheck;
2485 	bCheck = aCBAsTip.IsChecked();
2486 	bModified |= pOpt->bAutoCmpltShowAsTip != bCheck;
2487 	pOpt->bAutoCmpltShowAsTip = bCheck;
2488 
2489 	nVal = (sal_uInt16)aNFMinWordlen.GetValue();
2490 	bModified |= nVal != pOpt->nAutoCmpltWordLen;
2491 	pOpt->nAutoCmpltWordLen = nVal;
2492 
2493 	nVal = (sal_uInt16)aNFMaxEntries.GetValue();
2494 	bModified |= nVal != pOpt->nAutoCmpltListLen;
2495 	pOpt->nAutoCmpltListLen = nVal;
2496 
2497 	nVal = aDCBExpandKey.GetSelectEntryPos();
2498 	if( nVal < aDCBExpandKey.GetEntryCount() )
2499 	{
2500 		sal_uLong nKey = (sal_uLong)aDCBExpandKey.GetEntryData( nVal );
2501 		bModified |= nKey != pOpt->nAutoCmpltExpandKey;
2502 		pOpt->nAutoCmpltExpandKey = (sal_uInt16)nKey;
2503    }
2504 
2505 	if( pAutoCmpltList && nAutoCmpltListCnt != aLBEntries.GetEntryCount() )
2506 	{
2507 		bModified = sal_True;
2508 		pOpt->pAutoCmpltList = pAutoCmpltList;
2509 	}
2510 	if( bModified )
2511     {
2512         SvxAutoCorrCfg* pCfg = SvxAutoCorrCfg::Get();
2513         pCfg->SetModified();
2514         pCfg->Commit();
2515     }
2516 	return sal_True;
2517 }
2518 
Reset(const SfxItemSet &)2519 void OfaAutoCompleteTabPage::Reset( const SfxItemSet&  )
2520 {
2521 	SvxAutoCorrect* pAutoCorrect = SvxAutoCorrCfg::Get()->GetAutoCorrect();
2522 	SvxSwAutoFmtFlags *pOpt = &pAutoCorrect->GetSwFlags();
2523 
2524 	aCBActiv.Check( 0 != pOpt->bAutoCompleteWords );
2525 	aCBCollect.Check( 0 != pOpt->bAutoCmpltCollectWords );
2526     aCBRemoveList.Check( !pOpt->bAutoCmpltKeepList ); //inverted value!
2527     aCBAppendSpace.Check( 0 != pOpt->bAutoCmpltAppendBlanc );
2528 	aCBAsTip.Check( 0 != pOpt->bAutoCmpltShowAsTip );
2529 
2530 	aNFMinWordlen.SetValue( pOpt->nAutoCmpltWordLen );
2531 	aNFMaxEntries.SetValue( pOpt->nAutoCmpltListLen );
2532 
2533 	// select the specific KeyCode:
2534 	{
2535 		sal_uLong nKey = pOpt->nAutoCmpltExpandKey;
2536 		for( sal_uInt16 n = 0, nCnt = aDCBExpandKey.GetEntryCount(); n < nCnt; ++n )
2537 			if( nKey == (sal_uLong)aDCBExpandKey.GetEntryData( n ))
2538 			{
2539 				aDCBExpandKey.SelectEntryPos( n );
2540 				break;
2541 			}
2542 	}
2543 
2544 	if( pOpt->pAutoCmpltList && pOpt->pAutoCmpltList->Count() )
2545 	{
2546 		pAutoCmpltList = (SvStringsISortDtor*)pOpt->pAutoCmpltList;
2547 		pOpt->pAutoCmpltList = 0;
2548 		nAutoCmpltListCnt = pAutoCmpltList->Count();
2549 		for( sal_uInt16 n = 0; n < nAutoCmpltListCnt; ++n )
2550 		{
2551 			const StringPtr pStr = pAutoCmpltList->GetObject( n );
2552 			sal_uInt16 nPos = aLBEntries.InsertEntry( *pStr );
2553 			aLBEntries.SetEntryData( nPos, (void*)pStr );
2554 		}
2555 	}
2556 	else
2557 	{
2558 		aLBEntries.Disable();
2559 		aPBEntries.Disable();
2560 	}
2561 
2562 	CheckHdl( &aCBActiv );
2563     CheckHdl( &aCBCollect );
2564 }
2565 
ActivatePage(const SfxItemSet &)2566 void OfaAutoCompleteTabPage::ActivatePage( const SfxItemSet& )
2567 {
2568 	((OfaAutoCorrDlg*)GetTabDialog())->EnableLanguage( sal_False );
2569 }
2570 
IMPL_LINK(OfaAutoCompleteTabPage,DeleteHdl,PushButton *,EMPTYARG)2571 IMPL_LINK( OfaAutoCompleteTabPage, DeleteHdl, PushButton*, EMPTYARG )
2572 {
2573 	sal_uInt16 nSelCnt = pAutoCmpltList ? aLBEntries.GetSelectEntryCount() : 0;
2574 	while( nSelCnt )
2575 	{
2576 		sal_uInt16 nPos = aLBEntries.GetSelectEntryPos( --nSelCnt );
2577 		const StringPtr pStr = (StringPtr)aLBEntries.GetEntryData( nPos );
2578 		aLBEntries.RemoveEntry( nPos );
2579 		nPos = pAutoCmpltList->GetPos( pStr );
2580 		if( USHRT_MAX != nPos )
2581 			pAutoCmpltList->Remove( nPos );
2582 	}
2583 	return 0;
2584 }
2585 
IMPL_LINK(OfaAutoCompleteTabPage,CheckHdl,CheckBox *,pBox)2586 IMPL_LINK( OfaAutoCompleteTabPage, CheckHdl, CheckBox*, pBox )
2587 {
2588     sal_Bool bEnable = pBox->IsChecked();
2589     if( pBox == &aCBActiv )
2590 	{
2591         aCBAppendSpace.Enable( bEnable );
2592         aCBAppendSpace.Enable( bEnable );
2593 		aCBAsTip.Enable( bEnable );
2594 		aDCBExpandKey.Enable( bEnable );
2595 	}
2596     else if(&aCBCollect == pBox)
2597         aCBRemoveList.Enable( bEnable );
2598     return 0;
2599 }
2600 
CopyToClipboard() const2601 void OfaAutoCompleteTabPage::CopyToClipboard() const
2602 {
2603 	sal_uInt16 nSelCnt = aLBEntries.GetSelectEntryCount();
2604 	if( pAutoCmpltList && nSelCnt )
2605 	{
2606 		TransferDataContainer* pCntnr = new TransferDataContainer;
2607 		::com::sun::star::uno::Reference<
2608 			::com::sun::star::datatransfer::XTransferable > xRef( pCntnr );
2609 
2610 		ByteString sData;
2611 		const sal_Char* pLineEnd =
2612 #if defined(UNX)
2613 				"\012";
2614 #else
2615 				"\015\012";
2616 #endif
2617 
2618 		rtl_TextEncoding nEncode = gsl_getSystemTextEncoding();
2619 
2620 		for( sal_uInt16 n = 0; n < nSelCnt; ++n )
2621 		{
2622 			sData += ByteString( aLBEntries.GetSelectEntry( n ), nEncode );
2623 			sData += pLineEnd;
2624 		}
2625 		pCntnr->CopyByteString( SOT_FORMAT_STRING, sData );
2626 		pCntnr->CopyToClipboard( (Window*)this );
2627 	}
2628 }
2629 
PreNotify(NotifyEvent & rNEvt)2630 long OfaAutoCompleteTabPage::AutoCompleteMultiListBox::PreNotify(
2631 			NotifyEvent& rNEvt )
2632 {
2633 	long nHandled = MultiListBox::PreNotify( rNEvt );
2634 
2635 	if( !nHandled && EVENT_KEYUP == rNEvt.GetType() )
2636 	{
2637 		const KeyCode& rKeyCode = rNEvt.GetKeyEvent()->GetKeyCode();
2638 		switch( rKeyCode.GetModifier() | rKeyCode.GetCode() )
2639 		{
2640 		case KEY_DELETE:
2641 			rPage.DeleteHdl( 0 );
2642 			nHandled = 1;
2643 			break;
2644 
2645 		default:
2646 			if( KEYFUNC_COPY == rKeyCode.GetFunction() )
2647 			{
2648 				rPage.CopyToClipboard();
2649 				nHandled = 1;
2650 			}
2651 			break;
2652 		}
2653 	}
2654 	return nHandled;
2655 }
2656 
2657 // class OfaSmartTagOptionsTabPage ---------------------------------------------
2658 
OfaSmartTagOptionsTabPage(Window * pParent,const SfxItemSet & rSet)2659 OfaSmartTagOptionsTabPage::OfaSmartTagOptionsTabPage( Window* pParent,
2660 												      const SfxItemSet& rSet )
2661     : SfxTabPage(pParent, CUI_RES( RID_OFAPAGE_SMARTTAG_OPTIONS ), rSet),
2662     m_aMainCB( this, CUI_RES(CB_SMARTTAGS) ),
2663     m_aSmartTagTypesLB( this, CUI_RES(LB_SMARTTAGS) ),
2664     m_aPropertiesPB( this, CUI_RES(PB_SMARTTAGS) ),
2665     m_aTitleFT( this, CUI_RES(FT_SMARTTAGS) )
2666 {
2667 	FreeResource();
2668 
2669     // some options for the list box:
2670     m_aSmartTagTypesLB.SetStyle( m_aSmartTagTypesLB.GetStyle() | WB_HSCROLL | WB_HIDESELECTION );
2671 	m_aSmartTagTypesLB.SetHighlightRange();
2672 
2673     // set the handlers:
2674 	m_aMainCB.SetToggleHdl(LINK(this, OfaSmartTagOptionsTabPage, CheckHdl));
2675     m_aPropertiesPB.SetClickHdl(LINK(this, OfaSmartTagOptionsTabPage, ClickHdl));
2676     m_aSmartTagTypesLB.SetSelectHdl(LINK(this, OfaSmartTagOptionsTabPage, SelectHdl));
2677 }
2678 
~OfaSmartTagOptionsTabPage()2679 OfaSmartTagOptionsTabPage::~OfaSmartTagOptionsTabPage()
2680 {
2681 
2682 }
2683 
Create(Window * pParent,const SfxItemSet & rSet)2684 SfxTabPage*	OfaSmartTagOptionsTabPage::Create( Window* pParent, const SfxItemSet& rSet)
2685 {
2686 	return new OfaSmartTagOptionsTabPage( pParent, rSet );
2687 }
2688 
2689 /** This struct is used to associate list box entries with smart tag data
2690 */
2691 struct ImplSmartTagLBUserData
2692 {
2693     rtl::OUString maSmartTagType;
2694     uno::Reference< smarttags::XSmartTagRecognizer > mxRec;
2695     sal_Int32 mnSmartTagIdx;
2696 
ImplSmartTagLBUserDataImplSmartTagLBUserData2697     ImplSmartTagLBUserData( const rtl::OUString& rSmartTagType,
2698                             uno::Reference< smarttags::XSmartTagRecognizer > xRec,
2699                             sal_Int32 nSmartTagIdx ) :
2700         maSmartTagType( rSmartTagType ),
2701         mxRec( xRec ),
2702         mnSmartTagIdx( nSmartTagIdx ) {}
2703 };
2704 
2705 /** Clears m_aSmartTagTypesLB
2706 */
ClearListBox()2707 void OfaSmartTagOptionsTabPage::ClearListBox()
2708 {
2709     const sal_uLong nCount = m_aSmartTagTypesLB.GetEntryCount();
2710     for ( sal_uInt16 i = 0; i < nCount; ++i )
2711 	{
2712         const SvLBoxEntry* pEntry = m_aSmartTagTypesLB.GetEntry(i);
2713         const ImplSmartTagLBUserData* pUserData = static_cast< ImplSmartTagLBUserData* >(pEntry->GetUserData());
2714         delete pUserData;
2715     }
2716 
2717     m_aSmartTagTypesLB.Clear();
2718 }
2719 
2720 /** Inserts items into m_aSmartTagTypesLB
2721 */
FillListBox(const SmartTagMgr & rSmartTagMgr)2722 void OfaSmartTagOptionsTabPage::FillListBox( const SmartTagMgr& rSmartTagMgr )
2723 {
2724     // first we have to clear the list box:
2725     ClearListBox();
2726 
2727     // fill list box:
2728     const sal_uInt32 nNumberOfRecognizers = rSmartTagMgr.NumberOfRecognizers();
2729 	const lang::Locale aLocale( SvxCreateLocale( eLastDialogLanguage ) );
2730     std::vector< ActionReference > aActionReferences;
2731 
2732     for ( sal_uInt32 i = 0; i < nNumberOfRecognizers; ++i )
2733     {
2734         uno::Reference< smarttags::XSmartTagRecognizer > xRec = rSmartTagMgr.GetRecognizer(i);
2735 
2736         const rtl::OUString aName = xRec->getName( aLocale );
2737         const rtl::OUString aDesc = xRec->getDescription( aLocale );
2738         const sal_Int32 nNumberOfSupportedSmartTags = xRec->getSmartTagCount();
2739 
2740         for ( sal_Int32 j = 0; j < nNumberOfSupportedSmartTags; ++j )
2741         {
2742             const rtl::OUString aSmartTagType = xRec->getSmartTagName(j);
2743             rtl::OUString aSmartTagCaption = rSmartTagMgr.GetSmartTagCaption( aSmartTagType, aLocale );
2744 
2745             if ( !aSmartTagCaption.getLength() )
2746                 aSmartTagCaption = aSmartTagType;
2747 
2748             const rtl::OUString aLBEntry = aSmartTagCaption +
2749                                            OUString::createFromAscii(" (") +
2750                                            aName +
2751                                            OUString::createFromAscii(")");
2752 
2753             SvLBoxEntry* pEntry = m_aSmartTagTypesLB.SvTreeListBox::InsertEntry( aLBEntry );
2754             if ( pEntry )
2755             {
2756                 const bool bCheck = rSmartTagMgr.IsSmartTagTypeEnabled( aSmartTagType );
2757                 m_aSmartTagTypesLB.SetCheckButtonState( pEntry, bCheck ? SV_BUTTON_CHECKED : SV_BUTTON_UNCHECKED );
2758                 pEntry->SetUserData(static_cast<void*>(new ImplSmartTagLBUserData( aSmartTagType, xRec, j ) ) );
2759             }
2760         }
2761     }
2762 }
2763 
2764 /** Handler for the push button
2765 */
IMPL_LINK(OfaSmartTagOptionsTabPage,ClickHdl,PushButton *,EMPTYARG)2766 IMPL_LINK( OfaSmartTagOptionsTabPage, ClickHdl, PushButton*, EMPTYARG )
2767 {
2768 	const sal_uInt16 nPos = m_aSmartTagTypesLB.GetSelectEntryPos();
2769     const SvLBoxEntry* pEntry = m_aSmartTagTypesLB.GetEntry(nPos);
2770     const ImplSmartTagLBUserData* pUserData = static_cast< ImplSmartTagLBUserData* >(pEntry->GetUserData());
2771     uno::Reference< smarttags::XSmartTagRecognizer > xRec = pUserData->mxRec;
2772     const sal_Int32 nSmartTagIdx = pUserData->mnSmartTagIdx;
2773 
2774  	const lang::Locale aLocale( SvxCreateLocale( eLastDialogLanguage ) );
2775     if ( xRec->hasPropertyPage( nSmartTagIdx, aLocale ) )
2776         xRec->displayPropertyPage( nSmartTagIdx, aLocale );
2777 
2778 	return 0;
2779 }
2780 
2781 /** Handler for the check box
2782 */
IMPL_LINK(OfaSmartTagOptionsTabPage,CheckHdl,CheckBox *,EMPTYARG)2783 IMPL_LINK( OfaSmartTagOptionsTabPage, CheckHdl, CheckBox*, EMPTYARG )
2784 {
2785     const sal_Bool bEnable = m_aMainCB.IsChecked();
2786     m_aSmartTagTypesLB.Enable( bEnable );
2787     m_aSmartTagTypesLB.Invalidate();
2788     m_aPropertiesPB.Enable( false );
2789 
2790     // if the controls are currently enabled, we still have to check
2791     // if the properties button should be disabled because the currently
2792     // seleted smart tag type does not have a properties dialog.
2793     // We do this by calling SelectHdl:
2794     if ( bEnable )
2795         SelectHdl( &m_aSmartTagTypesLB );
2796 
2797     return 0;
2798 }
2799 
2800 /** Handler for the list box
2801 */
IMPL_LINK(OfaSmartTagOptionsTabPage,SelectHdl,SvxCheckListBox *,EMPTYARG)2802 IMPL_LINK(OfaSmartTagOptionsTabPage, SelectHdl, SvxCheckListBox*, EMPTYARG)
2803 {
2804     if ( m_aSmartTagTypesLB.GetEntryCount() < 1 )
2805         return 0;
2806 
2807 	const sal_uInt16 nPos = m_aSmartTagTypesLB.GetSelectEntryPos();
2808     const SvLBoxEntry* pEntry = m_aSmartTagTypesLB.GetEntry(nPos);
2809     const ImplSmartTagLBUserData* pUserData = static_cast< ImplSmartTagLBUserData* >(pEntry->GetUserData());
2810     uno::Reference< smarttags::XSmartTagRecognizer > xRec = pUserData->mxRec;
2811     const sal_Int32 nSmartTagIdx = pUserData->mnSmartTagIdx;
2812 
2813     const lang::Locale aLocale( SvxCreateLocale( eLastDialogLanguage ) );
2814     if ( xRec->hasPropertyPage( nSmartTagIdx, aLocale ) )
2815         m_aPropertiesPB.Enable( sal_True );
2816     else
2817         m_aPropertiesPB.Enable( sal_False );
2818 
2819 	return 0;
2820 }
2821 
2822 /** Propagates the current settings to the smart tag manager.
2823 */
FillItemSet(SfxItemSet &)2824 sal_Bool OfaSmartTagOptionsTabPage::FillItemSet( SfxItemSet& )
2825 {
2826 	SvxAutoCorrect* pAutoCorrect = SvxAutoCorrCfg::Get()->GetAutoCorrect();
2827 	SvxSwAutoFmtFlags *pOpt = &pAutoCorrect->GetSwFlags();
2828     SmartTagMgr* pSmartTagMgr = pOpt->pSmartTagMgr;
2829 
2830     // robust!
2831     if ( !pSmartTagMgr )
2832         return sal_False;
2833 
2834     sal_Bool bModifiedSmartTagTypes = sal_False;
2835     std::vector< rtl::OUString > aDisabledSmartTagTypes;
2836 
2837     const sal_uLong nCount = m_aSmartTagTypesLB.GetEntryCount();
2838 
2839     for ( sal_uInt16 i = 0; i < nCount; ++i )
2840 	{
2841         const SvLBoxEntry* pEntry = m_aSmartTagTypesLB.GetEntry(i);
2842         const ImplSmartTagLBUserData* pUserData = static_cast< ImplSmartTagLBUserData* >(pEntry->GetUserData());
2843 		const sal_Bool bChecked = m_aSmartTagTypesLB.IsChecked(i);
2844         const sal_Bool bIsCurrentlyEnabled = pSmartTagMgr->IsSmartTagTypeEnabled( pUserData->maSmartTagType );
2845 
2846         bModifiedSmartTagTypes = bModifiedSmartTagTypes || ( !bChecked != !bIsCurrentlyEnabled );
2847 
2848         if ( !bChecked )
2849             aDisabledSmartTagTypes.push_back( pUserData->maSmartTagType );
2850 
2851         delete pUserData;
2852     }
2853 
2854     const sal_Bool bModifiedRecognize = ( !m_aMainCB.IsChecked() != !pSmartTagMgr->IsLabelTextWithSmartTags() );
2855     if ( bModifiedSmartTagTypes || bModifiedRecognize )
2856     {
2857         bool bLabelTextWithSmartTags = m_aMainCB.IsChecked() ? true : false;
2858         pSmartTagMgr->WriteConfiguration( bModifiedRecognize     ? &bLabelTextWithSmartTags : 0,
2859                                           bModifiedSmartTagTypes ? &aDisabledSmartTagTypes : 0 );
2860     }
2861 
2862 	return sal_True;
2863 }
2864 
2865 /** Sets the controls based on the current settings at SmartTagMgr.
2866 */
Reset(const SfxItemSet &)2867 void OfaSmartTagOptionsTabPage::Reset( const SfxItemSet&  )
2868 {
2869 	SvxAutoCorrect* pAutoCorrect = SvxAutoCorrCfg::Get()->GetAutoCorrect();
2870 	SvxSwAutoFmtFlags *pOpt = &pAutoCorrect->GetSwFlags();
2871     const SmartTagMgr* pSmartTagMgr = pOpt->pSmartTagMgr;
2872 
2873     // robust, should not happen!
2874     if ( !pSmartTagMgr )
2875         return;
2876 
2877     FillListBox( *pSmartTagMgr );
2878 	m_aSmartTagTypesLB.SelectEntryPos( 0 );
2879     m_aMainCB.Check( pSmartTagMgr->IsLabelTextWithSmartTags() );
2880     CheckHdl( &m_aMainCB );
2881 }
2882 
ActivatePage(const SfxItemSet &)2883 void OfaSmartTagOptionsTabPage::ActivatePage( const SfxItemSet& )
2884 {
2885 	((OfaAutoCorrDlg*)GetTabDialog())->EnableLanguage( sal_False );
2886 }
2887 
2888