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