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