android: Update app-specific/MIME type icons
[LibreOffice.git] / cui / source / tabpages / autocdlg.cxx
blob378fb68c41431b55d81fb3b061b3bcf84ae64ee4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/config.h>
22 #include <i18nutil/unicode.hxx>
23 #include <o3tl/safeint.hxx>
24 #include <utility>
25 #include <vcl/event.hxx>
26 #include <vcl/keycodes.hxx>
27 #include <vcl/settings.hxx>
28 #include <vcl/transfer.hxx>
29 #include <sfx2/app.hxx>
30 #include <sfx2/objsh.hxx>
31 #include <sfx2/viewsh.hxx>
32 #include <unotools/charclass.hxx>
33 #include <unotools/collatorwrapper.hxx>
34 #include <comphelper/processfactory.hxx>
35 #include <vcl/svapp.hxx>
36 #include <sfx2/module.hxx>
37 #include <svl/eitem.hxx>
38 #include <svl/cjkoptions.hxx>
39 #include <svl/ctloptions.hxx>
40 #include <svx/SmartTagMgr.hxx>
41 #include <com/sun/star/smarttags/XSmartTagRecognizer.hpp>
42 #include <rtl/strbuf.hxx>
43 #include <o3tl/temporary.hxx>
44 #include <osl/diagnose.h>
45 #include <tools/debug.hxx>
47 #include <autocdlg.hxx>
48 #include <editeng/acorrcfg.hxx>
49 #include <editeng/svxacorr.hxx>
50 #include <cui/cuicharmap.hxx>
51 #include <strings.hrc>
52 #include <dialmgr.hxx>
53 #include <svx/svxids.hrc>
55 static LanguageType eLastDialogLanguage = LANGUAGE_SYSTEM;
57 using namespace ::com::sun::star::util;
58 using namespace ::com::sun::star;
60 OfaAutoCorrDlg::OfaAutoCorrDlg(weld::Window* pParent, const SfxItemSet* _pSet )
61 : SfxTabDialogController(pParent, "cui/ui/autocorrectdialog.ui", "AutoCorrectDialog", _pSet)
62 , m_xLanguageBox(m_xBuilder->weld_widget("langbox"))
63 , m_xLanguageLB(new SvxLanguageBox(m_xBuilder->weld_combo_box("lang")))
65 bool bShowSWOptions = false;
66 bool bOpenSmartTagOptions = false;
68 if ( _pSet )
70 const SfxBoolItem* pItem = SfxItemSet::GetItem<SfxBoolItem>(_pSet, SID_AUTO_CORRECT_DLG, false);
71 if ( pItem && pItem->GetValue() )
72 bShowSWOptions = true;
74 const SfxBoolItem* pItem2 = SfxItemSet::GetItem<SfxBoolItem>(_pSet, SID_OPEN_SMARTTAGOPTIONS, false);
75 if ( pItem2 && pItem2->GetValue() )
76 bOpenSmartTagOptions = true;
79 AddTabPage("options", OfaAutocorrOptionsPage::Create, nullptr);
80 AddTabPage("applypage", OfaSwAutoFmtOptionsPage::Create, nullptr);
81 AddTabPage("wordcompletion", OfaAutoCompleteTabPage::Create, nullptr);
82 AddTabPage("smarttags", OfaSmartTagOptionsTabPage::Create, nullptr);
84 if (!bShowSWOptions)
86 RemoveTabPage("applypage");
87 RemoveTabPage("wordcompletion");
88 RemoveTabPage("smarttags");
90 else
92 // remove smart tag tab page if no extensions are installed
93 SvxAutoCorrect* pAutoCorrect = SvxAutoCorrCfg::Get().GetAutoCorrect();
94 SvxSwAutoFormatFlags& rOpt = pAutoCorrect->GetSwFlags();
95 if (!rOpt.pSmartTagMgr || 0 == rOpt.pSmartTagMgr->NumberOfRecognizers())
96 RemoveTabPage("smarttags");
98 RemoveTabPage("options");
101 AddTabPage("replace", OfaAutocorrReplacePage::Create, nullptr);
102 AddTabPage("exceptions", OfaAutocorrExceptPage::Create, nullptr);
103 AddTabPage("localized", OfaQuoteTabPage::Create, nullptr);
105 // initialize languages
106 //! LANGUAGE_NONE is displayed as '[All]' and the LanguageType
107 //! will be set to LANGUAGE_UNDETERMINED
108 SvxLanguageListFlags nLangList = SvxLanguageListFlags::WESTERN;
110 if( SvtCTLOptions::IsCTLFontEnabled() )
111 nLangList |= SvxLanguageListFlags::CTL;
112 if( SvtCJKOptions::IsCJKFontEnabled() )
113 nLangList |= SvxLanguageListFlags::CJK;
114 m_xLanguageLB->SetLanguageList( nLangList, true, true );
115 m_xLanguageLB->set_active_id( LANGUAGE_NONE );
116 int nPos = m_xLanguageLB->get_active();
117 DBG_ASSERT(nPos != -1, "listbox entry missing" );
118 m_xLanguageLB->set_id(nPos, LANGUAGE_UNDETERMINED);
120 // Initializing doesn't work for static on linux - therefore here
121 if (LANGUAGE_SYSTEM == eLastDialogLanguage)
122 eLastDialogLanguage = Application::GetSettings().GetLanguageTag().getLanguageType();
124 LanguageType nSelectLang = LANGUAGE_UNDETERMINED;
125 nPos = m_xLanguageLB->find_id(eLastDialogLanguage);
126 if (nPos != -1)
127 nSelectLang = eLastDialogLanguage;
128 m_xLanguageLB->set_active_id(nSelectLang);
130 m_xLanguageLB->connect_changed(LINK(this, OfaAutoCorrDlg, SelectLanguageHdl));
132 if ( bOpenSmartTagOptions )
133 SetCurPageId("smarttags");
136 OfaAutoCorrDlg::~OfaAutoCorrDlg()
140 void OfaAutoCorrDlg::EnableLanguage(bool bEnable)
142 m_xLanguageBox->set_sensitive(bEnable);
145 static bool lcl_FindEntry(weld::TreeView& rLB, const OUString& rEntry,
146 CollatorWrapper const & rCmpClass)
148 int nCount = rLB.n_children();
149 int nSelPos = rLB.get_selected_index();
150 for (int i = 0; i < nCount; i++)
152 if (0 == rCmpClass.compareString(rEntry, rLB.get_text(i)))
154 rLB.select(i);
155 return true;
158 if (nSelPos != -1)
159 rLB.unselect(nSelPos);
160 return false;
163 IMPL_LINK_NOARG(OfaAutoCorrDlg, SelectLanguageHdl, weld::ComboBox&, void)
165 LanguageType eNewLang = m_xLanguageLB->get_active_id();
166 // save old settings and fill anew
167 if(eNewLang == eLastDialogLanguage)
168 return;
170 OUString sPageId = GetCurPageId();
171 if (sPageId == "replace")
173 OfaAutocorrReplacePage* pPage = static_cast<OfaAutocorrReplacePage*>(GetTabPage(sPageId));
174 assert(pPage);
175 pPage->SetLanguage(eNewLang);
177 else if (sPageId == "exceptions")
179 OfaAutocorrExceptPage* pPage = static_cast<OfaAutocorrExceptPage*>(GetTabPage(sPageId));
180 assert(pPage);
181 pPage->SetLanguage(eNewLang);
185 OfaAutocorrOptionsPage::OfaAutocorrOptionsPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet)
186 : SfxTabPage(pPage, pController, "cui/ui/acoroptionspage.ui", "AutocorrectOptionsPage", &rSet)
187 , m_sInput(CuiResId(RID_CUISTR_USE_REPLACE))
188 , m_sDoubleCaps(CuiResId(RID_CUISTR_CPTL_STT_WORD))
189 , m_sStartCap(CuiResId(RID_CUISTR_CPTL_STT_SENT))
190 , m_sBoldUnderline(CuiResId(RID_CUISTR_BOLD_UNDER))
191 , m_sURL(CuiResId(RID_CUISTR_DETECT_URL))
192 , m_sDOI(CuiResId(RID_CUISTR_DETECT_DOI))
193 , m_sNoDblSpaces(CuiResId(RID_CUISTR_NO_DBL_SPACES))
194 , m_sDash(CuiResId(RID_CUISTR_DASH))
195 , m_sAccidentalCaps(CuiResId(RID_CUISTR_CORRECT_ACCIDENTAL_CAPS_LOCK))
196 , m_xCheckLB(m_xBuilder->weld_tree_view("checklist"))
198 m_xCheckLB->enable_toggle_buttons(weld::ColumnToggleType::Check);
199 m_xCheckLB->set_size_request(-1, m_xCheckLB->get_height_rows(10));
202 OfaAutocorrOptionsPage::~OfaAutocorrOptionsPage()
206 std::unique_ptr<SfxTabPage> OfaAutocorrOptionsPage::Create(weld::Container* pPage, weld::DialogController* pController,
207 const SfxItemSet* rSet)
209 return std::make_unique<OfaAutocorrOptionsPage>(pPage, pController, *rSet);
212 #define CBCOL_FIRST 0
213 #define CBCOL_SECOND 1
214 #define CBCOL_BOTH 2
216 bool OfaAutocorrOptionsPage::FillItemSet( SfxItemSet* )
218 SvxAutoCorrect* pAutoCorrect = SvxAutoCorrCfg::Get().GetAutoCorrect();
219 ACFlags nFlags = pAutoCorrect->GetFlags();
221 int nPos = 0;
222 pAutoCorrect->SetAutoCorrFlag(ACFlags::Autocorrect, m_xCheckLB->get_toggle(nPos++) == TRISTATE_TRUE);
223 pAutoCorrect->SetAutoCorrFlag(ACFlags::CapitalStartWord, m_xCheckLB->get_toggle(nPos++) == TRISTATE_TRUE);
224 pAutoCorrect->SetAutoCorrFlag(ACFlags::CapitalStartSentence, m_xCheckLB->get_toggle(nPos++) == TRISTATE_TRUE);
225 pAutoCorrect->SetAutoCorrFlag(ACFlags::ChgWeightUnderl, m_xCheckLB->get_toggle(nPos++) == TRISTATE_TRUE);
226 pAutoCorrect->SetAutoCorrFlag(ACFlags::SetINetAttr, m_xCheckLB->get_toggle(nPos++) == TRISTATE_TRUE);
227 pAutoCorrect->SetAutoCorrFlag(ACFlags::SetDOIAttr, m_xCheckLB->get_toggle(nPos++) == TRISTATE_TRUE);
228 pAutoCorrect->SetAutoCorrFlag(ACFlags::ChgToEnEmDash, m_xCheckLB->get_toggle(nPos++) == TRISTATE_TRUE);
229 pAutoCorrect->SetAutoCorrFlag(ACFlags::IgnoreDoubleSpace, m_xCheckLB->get_toggle(nPos++) == TRISTATE_TRUE);
230 pAutoCorrect->SetAutoCorrFlag(ACFlags::CorrectCapsLock, m_xCheckLB->get_toggle(nPos++) == TRISTATE_TRUE);
232 bool bReturn = nFlags != pAutoCorrect->GetFlags();
233 if(bReturn )
235 SvxAutoCorrCfg& rCfg = SvxAutoCorrCfg::Get();
236 rCfg.SetModified();
237 rCfg.Commit();
239 return bReturn;
242 void OfaAutocorrOptionsPage::ActivatePage( const SfxItemSet& )
244 static_cast<OfaAutoCorrDlg*>(GetDialogController())->EnableLanguage(false);
247 void OfaAutocorrOptionsPage::InsertEntry(const OUString& rTxt)
249 m_xCheckLB->append();
250 const int nRow = m_xCheckLB->n_children() - 1;
251 m_xCheckLB->set_toggle(nRow, TRISTATE_FALSE);
252 m_xCheckLB->set_text(nRow, rTxt, 0);
255 void OfaAutocorrOptionsPage::Reset( const SfxItemSet* )
257 SvxAutoCorrect* pAutoCorrect = SvxAutoCorrCfg::Get().GetAutoCorrect();
258 const ACFlags nFlags = pAutoCorrect->GetFlags();
260 m_xCheckLB->freeze();
261 m_xCheckLB->clear();
263 InsertEntry(m_sInput);
264 InsertEntry(m_sDoubleCaps);
265 InsertEntry(m_sStartCap);
266 InsertEntry(m_sBoldUnderline);
267 InsertEntry(m_sURL);
268 InsertEntry(m_sDOI);
269 InsertEntry(m_sDash);
270 InsertEntry(m_sNoDblSpaces);
271 InsertEntry(m_sAccidentalCaps);
273 int nPos = 0;
274 m_xCheckLB->set_toggle( nPos++, bool(nFlags & ACFlags::Autocorrect) ? TRISTATE_TRUE : TRISTATE_FALSE );
275 m_xCheckLB->set_toggle( nPos++, bool(nFlags & ACFlags::CapitalStartWord) ? TRISTATE_TRUE : TRISTATE_FALSE );
276 m_xCheckLB->set_toggle( nPos++, bool(nFlags & ACFlags::CapitalStartSentence) ? TRISTATE_TRUE : TRISTATE_FALSE );
277 m_xCheckLB->set_toggle( nPos++, bool(nFlags & ACFlags::ChgWeightUnderl) ? TRISTATE_TRUE : TRISTATE_FALSE );
278 m_xCheckLB->set_toggle( nPos++, bool(nFlags & ACFlags::SetINetAttr) ? TRISTATE_TRUE : TRISTATE_FALSE );
279 m_xCheckLB->set_toggle( nPos++, bool(nFlags & ACFlags::SetDOIAttr) ? TRISTATE_TRUE : TRISTATE_FALSE );
280 m_xCheckLB->set_toggle( nPos++, bool(nFlags & ACFlags::ChgToEnEmDash) ? TRISTATE_TRUE : TRISTATE_FALSE );
281 m_xCheckLB->set_toggle( nPos++, bool(nFlags & ACFlags::IgnoreDoubleSpace) ? TRISTATE_TRUE : TRISTATE_FALSE );
282 m_xCheckLB->set_toggle( nPos++, bool(nFlags & ACFlags::CorrectCapsLock) ? TRISTATE_TRUE : TRISTATE_FALSE );
284 m_xCheckLB->thaw();
287 /*********************************************************************/
288 /* */
289 /* helping struct for dUserData of the Checklistbox */
290 /* */
291 /*********************************************************************/
293 namespace {
295 struct ImpUserData
297 OUString *pString;
298 vcl::Font *pFont;
300 ImpUserData(OUString* pText, vcl::Font* pFnt)
301 { pString = pText; pFont = pFnt;}
305 /*********************************************************************/
306 /* */
307 /* dialog for per cent settings */
308 /* */
309 /*********************************************************************/
311 class OfaAutoFmtPrcntSet : public weld::GenericDialogController
313 std::unique_ptr<weld::MetricSpinButton> m_xPrcntMF;
314 public:
315 explicit OfaAutoFmtPrcntSet(weld::Window* pParent)
316 : GenericDialogController(pParent, "cui/ui/percentdialog.ui", "PercentDialog")
317 , m_xPrcntMF(m_xBuilder->weld_metric_spin_button("margin", FieldUnit::PERCENT))
321 weld::MetricSpinButton& GetPrcntFld()
323 return *m_xPrcntMF;
327 /*********************************************************************/
328 /* */
329 /* use TabPage autoformat */
330 /* */
331 /*********************************************************************/
333 enum OfaAutoFmtOptions
335 USE_REPLACE_TABLE,
336 CORR_UPPER,
337 BEGIN_UPPER,
338 BOLD_UNDERLINE,
339 DETECT_URL,
340 DETECT_DOI,
341 REPLACE_DASHES,
342 DEL_SPACES_AT_STT_END,
343 DEL_SPACES_BETWEEN_LINES,
344 IGNORE_DBLSPACE,
345 CORRECT_CAPS_LOCK,
346 APPLY_NUMBERING,
347 INSERT_BORDER,
348 CREATE_TABLE,
349 REPLACE_STYLES,
350 DEL_EMPTY_NODE,
351 REPLACE_USER_COLL,
352 REPLACE_BULLETS,
353 MERGE_SINGLE_LINE_PARA
358 OfaSwAutoFmtOptionsPage::OfaSwAutoFmtOptionsPage(weld::Container* pPage, weld::DialogController* pController,
359 const SfxItemSet& rSet )
360 : SfxTabPage(pPage, pController, "cui/ui/applyautofmtpage.ui", "ApplyAutoFmtPage", &rSet)
361 , sDeleteEmptyPara(CuiResId(RID_CUISTR_DEL_EMPTY_PARA))
362 , sUseReplaceTbl(CuiResId(RID_CUISTR_USE_REPLACE))
363 , sCapitalStartWord(CuiResId(RID_CUISTR_CPTL_STT_WORD))
364 , sCapitalStartSentence(CuiResId(RID_CUISTR_CPTL_STT_SENT))
365 , sUserStyle(CuiResId(RID_CUISTR_USER_STYLE))
366 , sBullet(CuiResId(RID_CUISTR_BULLET))
367 , sBoldUnder(CuiResId(RID_CUISTR_BOLD_UNDER))
368 , sNoDblSpaces(CuiResId(RID_CUISTR_NO_DBL_SPACES))
369 , sCorrectCapsLock(CuiResId(RID_CUISTR_CORRECT_ACCIDENTAL_CAPS_LOCK))
370 , sDetectURL(CuiResId(RID_CUISTR_DETECT_URL))
371 , sDetectDOI(CuiResId(RID_CUISTR_DETECT_DOI))
372 , sDash(CuiResId(RID_CUISTR_DASH))
373 , sRightMargin(CuiResId(RID_CUISTR_RIGHT_MARGIN))
374 , sNum(CuiResId(RID_CUISTR_NUM))
375 , sBorder(CuiResId(RID_CUISTR_BORDER))
376 , sTable(CuiResId(RID_CUISTR_CREATE_TABLE))
377 , sReplaceTemplates(CuiResId(RID_CUISTR_REPLACE_TEMPLATES))
378 , sDelSpaceAtSttEnd(CuiResId(RID_CUISTR_DEL_SPACES_AT_STT_END))
379 , sDelSpaceBetweenLines(CuiResId(RID_CUISTR_DEL_SPACES_BETWEEN_LINES))
380 , nPercent(50)
381 , m_xCheckLB(m_xBuilder->weld_tree_view("list"))
382 , m_xEditPB(m_xBuilder->weld_button("edit"))
384 m_xCheckLB->connect_changed(LINK(this, OfaSwAutoFmtOptionsPage, SelectHdl));
385 m_xCheckLB->connect_row_activated(LINK(this, OfaSwAutoFmtOptionsPage, DoubleClickEditHdl));
387 std::vector<int> aWidths
389 o3tl::narrowing<int>(m_xCheckLB->get_pixel_size(m_xCheckLB->get_column_title(0)).Width() * 2),
390 o3tl::narrowing<int>(m_xCheckLB->get_pixel_size(m_xCheckLB->get_column_title(1)).Width() * 2)
392 m_xCheckLB->set_column_fixed_widths(aWidths);
394 m_xEditPB->connect_clicked(LINK(this, OfaSwAutoFmtOptionsPage, EditHdl));
397 void OfaSwAutoFmtOptionsPage::CreateEntry(const OUString& rTxt, sal_uInt16 nCol)
399 m_xCheckLB->append();
400 const int nRow = m_xCheckLB->n_children() - 1;
401 if (nCol == CBCOL_FIRST || nCol == CBCOL_BOTH)
402 m_xCheckLB->set_toggle(nRow, TRISTATE_FALSE, CBCOL_FIRST);
403 if (nCol == CBCOL_SECOND || nCol == CBCOL_BOTH)
404 m_xCheckLB->set_toggle(nRow, TRISTATE_FALSE, CBCOL_SECOND);
405 m_xCheckLB->set_text(nRow, rTxt, 2);
408 OfaSwAutoFmtOptionsPage::~OfaSwAutoFmtOptionsPage()
410 delete weld::fromId<ImpUserData*>(m_xCheckLB->get_id(REPLACE_BULLETS));
411 delete weld::fromId<ImpUserData*>(m_xCheckLB->get_id(APPLY_NUMBERING));
412 delete weld::fromId<ImpUserData*>(m_xCheckLB->get_id(MERGE_SINGLE_LINE_PARA));
415 std::unique_ptr<SfxTabPage> OfaSwAutoFmtOptionsPage::Create(weld::Container* pPage, weld::DialogController* pController,
416 const SfxItemSet* rAttrSet)
418 return std::make_unique<OfaSwAutoFmtOptionsPage>(pPage, pController, *rAttrSet);
421 bool OfaSwAutoFmtOptionsPage::FillItemSet( SfxItemSet* )
423 bool bModified = false;
424 SvxAutoCorrect* pAutoCorrect = SvxAutoCorrCfg::Get().GetAutoCorrect();
425 SvxSwAutoFormatFlags *pOpt = &pAutoCorrect->GetSwFlags();
426 ACFlags nFlags = pAutoCorrect->GetFlags();
428 bool bCheck = m_xCheckLB->get_toggle(USE_REPLACE_TABLE, CBCOL_FIRST) == TRISTATE_TRUE;
429 bModified |= pOpt->bAutoCorrect != bCheck;
430 pOpt->bAutoCorrect = bCheck;
431 pAutoCorrect->SetAutoCorrFlag(ACFlags::Autocorrect,
432 m_xCheckLB->get_toggle(USE_REPLACE_TABLE, CBCOL_SECOND) == TRISTATE_TRUE);
434 bCheck = m_xCheckLB->get_toggle(CORR_UPPER, CBCOL_FIRST) == TRISTATE_TRUE;
435 bModified |= pOpt->bCapitalStartWord != bCheck;
436 pOpt->bCapitalStartWord = bCheck;
437 pAutoCorrect->SetAutoCorrFlag(ACFlags::CapitalStartWord,
438 m_xCheckLB->get_toggle(CORR_UPPER, CBCOL_SECOND) == TRISTATE_TRUE);
440 bCheck = m_xCheckLB->get_toggle(BEGIN_UPPER, CBCOL_FIRST) == TRISTATE_TRUE;
441 bModified |= pOpt->bCapitalStartSentence != bCheck;
442 pOpt->bCapitalStartSentence = bCheck;
443 pAutoCorrect->SetAutoCorrFlag(ACFlags::CapitalStartSentence,
444 m_xCheckLB->get_toggle(BEGIN_UPPER, CBCOL_SECOND) == TRISTATE_TRUE);
446 bCheck = m_xCheckLB->get_toggle(BOLD_UNDERLINE, CBCOL_FIRST) == TRISTATE_TRUE;
447 bModified |= pOpt->bChgWeightUnderl != bCheck;
448 pOpt->bChgWeightUnderl = bCheck;
449 pAutoCorrect->SetAutoCorrFlag(ACFlags::ChgWeightUnderl,
450 m_xCheckLB->get_toggle(BOLD_UNDERLINE, CBCOL_SECOND) == TRISTATE_TRUE);
452 pAutoCorrect->SetAutoCorrFlag(ACFlags::IgnoreDoubleSpace,
453 m_xCheckLB->get_toggle(IGNORE_DBLSPACE, CBCOL_SECOND) == TRISTATE_TRUE);
455 pAutoCorrect->SetAutoCorrFlag(ACFlags::CorrectCapsLock,
456 m_xCheckLB->get_toggle(CORRECT_CAPS_LOCK, CBCOL_SECOND) == TRISTATE_TRUE);
458 bCheck = m_xCheckLB->get_toggle(DETECT_URL, CBCOL_FIRST) == TRISTATE_TRUE;
459 bModified |= pOpt->bSetINetAttr != bCheck;
460 pOpt->bSetINetAttr = bCheck;
461 pAutoCorrect->SetAutoCorrFlag(ACFlags::SetINetAttr,
462 m_xCheckLB->get_toggle(DETECT_URL, CBCOL_SECOND) == TRISTATE_TRUE);
464 bCheck = m_xCheckLB->get_toggle(DETECT_DOI, CBCOL_FIRST) == TRISTATE_TRUE;
465 bModified |= pOpt->bSetDOIAttr != bCheck;
466 pOpt->bSetDOIAttr = bCheck;
467 pAutoCorrect->SetAutoCorrFlag(ACFlags::SetDOIAttr,
468 m_xCheckLB->get_toggle(DETECT_DOI, CBCOL_SECOND) == TRISTATE_TRUE);
470 bCheck = m_xCheckLB->get_toggle(DEL_EMPTY_NODE, CBCOL_FIRST) == TRISTATE_TRUE;
471 bModified |= pOpt->bDelEmptyNode != bCheck;
472 pOpt->bDelEmptyNode = bCheck;
474 bCheck = m_xCheckLB->get_toggle(REPLACE_USER_COLL, CBCOL_FIRST) == TRISTATE_TRUE;
475 bModified |= pOpt->bChgUserColl != bCheck;
476 pOpt->bChgUserColl = bCheck;
478 bCheck = m_xCheckLB->get_toggle(REPLACE_BULLETS, CBCOL_FIRST) == TRISTATE_TRUE;
479 bModified |= pOpt->bChgEnumNum != bCheck;
480 pOpt->bChgEnumNum = bCheck;
481 bModified |= aBulletFont != pOpt->aBulletFont;
482 pOpt->aBulletFont = aBulletFont;
483 bModified |= sBulletChar != OUString(&pOpt->cBullet, 1);
484 pOpt->cBullet = sBulletChar.iterateCodePoints(&o3tl::temporary(sal_Int32(0)));
486 bModified |= aByInputBulletFont != pOpt->aByInputBulletFont;
487 bModified |= sByInputBulletChar != OUString(&pOpt->cByInputBullet, 1);
488 pOpt->aByInputBulletFont = aByInputBulletFont;
489 pOpt->cByInputBullet = sByInputBulletChar.iterateCodePoints(&o3tl::temporary(sal_Int32(0)));
491 bCheck = m_xCheckLB->get_toggle(MERGE_SINGLE_LINE_PARA, CBCOL_FIRST) == TRISTATE_TRUE;
492 bModified |= pOpt->bRightMargin != bCheck;
493 pOpt->bRightMargin = bCheck;
494 bModified |= nPercent != pOpt->nRightMargin;
495 pOpt->nRightMargin = static_cast<sal_uInt8>(nPercent);
497 bCheck = m_xCheckLB->get_toggle(APPLY_NUMBERING, CBCOL_SECOND) == TRISTATE_TRUE;
498 bModified |= pOpt->bSetNumRule != bCheck;
499 pOpt->bSetNumRule = bCheck;
501 bCheck = m_xCheckLB->get_toggle(INSERT_BORDER, CBCOL_SECOND) == TRISTATE_TRUE;
502 bModified |= pOpt->bSetBorder != bCheck;
503 pOpt->bSetBorder = bCheck;
505 bCheck = m_xCheckLB->get_toggle(CREATE_TABLE, CBCOL_SECOND) == TRISTATE_TRUE;
506 bModified |= pOpt->bCreateTable != bCheck;
507 pOpt->bCreateTable = bCheck;
509 bCheck = m_xCheckLB->get_toggle(REPLACE_STYLES, CBCOL_SECOND) == TRISTATE_TRUE;
510 bModified |= pOpt->bReplaceStyles != bCheck;
511 pOpt->bReplaceStyles = bCheck;
513 bCheck = m_xCheckLB->get_toggle(REPLACE_DASHES, CBCOL_FIRST) == TRISTATE_TRUE;
514 bModified |= pOpt->bChgToEnEmDash != bCheck;
515 pOpt->bChgToEnEmDash = bCheck;
516 pAutoCorrect->SetAutoCorrFlag(ACFlags::ChgToEnEmDash,
517 m_xCheckLB->get_toggle(REPLACE_DASHES, CBCOL_SECOND) == TRISTATE_TRUE);
519 bCheck = m_xCheckLB->get_toggle(DEL_SPACES_AT_STT_END, CBCOL_FIRST) == TRISTATE_TRUE;
520 bModified |= pOpt->bAFormatDelSpacesAtSttEnd != bCheck;
521 pOpt->bAFormatDelSpacesAtSttEnd = bCheck;
522 bCheck = m_xCheckLB->get_toggle(DEL_SPACES_AT_STT_END, CBCOL_SECOND) == TRISTATE_TRUE;
523 bModified |= pOpt->bAFormatByInpDelSpacesAtSttEnd != bCheck;
524 pOpt->bAFormatByInpDelSpacesAtSttEnd = bCheck;
526 bCheck = m_xCheckLB->get_toggle(DEL_SPACES_BETWEEN_LINES, CBCOL_FIRST) == TRISTATE_TRUE;
527 bModified |= pOpt->bAFormatDelSpacesBetweenLines != bCheck;
528 pOpt->bAFormatDelSpacesBetweenLines = bCheck;
529 bCheck = m_xCheckLB->get_toggle(DEL_SPACES_BETWEEN_LINES, CBCOL_SECOND) == TRISTATE_TRUE;
530 bModified |= pOpt->bAFormatByInpDelSpacesBetweenLines != bCheck;
531 pOpt->bAFormatByInpDelSpacesBetweenLines = bCheck;
533 if(bModified || nFlags != pAutoCorrect->GetFlags())
535 SvxAutoCorrCfg& rCfg = SvxAutoCorrCfg::Get();
536 rCfg.SetModified();
537 rCfg.Commit();
540 return true;
543 void OfaSwAutoFmtOptionsPage::ActivatePage( const SfxItemSet& )
545 static_cast<OfaAutoCorrDlg*>(GetDialogController())->EnableLanguage(false);
548 void OfaSwAutoFmtOptionsPage::Reset( const SfxItemSet* )
550 SvxAutoCorrect* pAutoCorrect = SvxAutoCorrCfg::Get().GetAutoCorrect();
551 SvxSwAutoFormatFlags *pOpt = &pAutoCorrect->GetSwFlags();
552 const ACFlags nFlags = pAutoCorrect->GetFlags();
554 aBulletFont = pOpt->aBulletFont;
555 sBulletChar = OUString(&pOpt->cBullet, 1);
557 aByInputBulletFont = pOpt->aByInputBulletFont;
558 sByInputBulletChar = OUString(&pOpt->cByInputBullet, 1);
560 nPercent = pOpt->nRightMargin;
561 sMargin = unicode::formatPercent(nPercent, Application::GetSettings().GetUILanguageTag());
563 m_xCheckLB->freeze();
564 m_xCheckLB->clear();
566 // The following entries have to be inserted in the same order
567 // as in the OfaAutoFmtOptions-enum!
568 CreateEntry(sUseReplaceTbl, CBCOL_BOTH );
569 CreateEntry(sCapitalStartWord, CBCOL_BOTH );
570 CreateEntry(sCapitalStartSentence, CBCOL_BOTH );
571 CreateEntry(sBoldUnder, CBCOL_BOTH );
572 CreateEntry(sDetectURL, CBCOL_BOTH );
573 CreateEntry(sDetectDOI, CBCOL_BOTH );
574 CreateEntry(sDash, CBCOL_BOTH );
575 CreateEntry(sDelSpaceAtSttEnd, CBCOL_BOTH );
576 CreateEntry(sDelSpaceBetweenLines, CBCOL_BOTH );
578 CreateEntry(sNoDblSpaces, CBCOL_SECOND);
579 CreateEntry(sCorrectCapsLock, CBCOL_SECOND);
580 CreateEntry(sNum.replaceFirst("%1", sBulletChar), CBCOL_SECOND);
581 CreateEntry(sBorder, CBCOL_SECOND);
582 CreateEntry(sTable, CBCOL_SECOND);
583 CreateEntry(sReplaceTemplates, CBCOL_SECOND);
584 CreateEntry(sDeleteEmptyPara, CBCOL_FIRST );
585 CreateEntry(sUserStyle, CBCOL_FIRST );
586 CreateEntry(sBullet.replaceFirst("%1", sByInputBulletChar), CBCOL_FIRST);
587 CreateEntry(sRightMargin.replaceFirst("%1", sMargin), CBCOL_FIRST);
589 m_xCheckLB->set_toggle(USE_REPLACE_TABLE, pOpt->bAutoCorrect ? TRISTATE_TRUE : TRISTATE_FALSE, CBCOL_FIRST);
590 m_xCheckLB->set_toggle(USE_REPLACE_TABLE, bool(nFlags & ACFlags::Autocorrect) ? TRISTATE_TRUE : TRISTATE_FALSE, CBCOL_SECOND);
591 m_xCheckLB->set_toggle(CORR_UPPER, pOpt->bCapitalStartWord ? TRISTATE_TRUE : TRISTATE_FALSE, CBCOL_FIRST);
592 m_xCheckLB->set_toggle(CORR_UPPER, bool(nFlags & ACFlags::CapitalStartWord) ? TRISTATE_TRUE : TRISTATE_FALSE, CBCOL_SECOND);
593 m_xCheckLB->set_toggle(BEGIN_UPPER, pOpt->bCapitalStartSentence ? TRISTATE_TRUE : TRISTATE_FALSE, CBCOL_FIRST);
594 m_xCheckLB->set_toggle(BEGIN_UPPER, bool(nFlags & ACFlags::CapitalStartSentence) ? TRISTATE_TRUE : TRISTATE_FALSE, CBCOL_SECOND);
595 m_xCheckLB->set_toggle(BOLD_UNDERLINE, pOpt->bChgWeightUnderl ? TRISTATE_TRUE : TRISTATE_FALSE, CBCOL_FIRST);
596 m_xCheckLB->set_toggle(BOLD_UNDERLINE, bool(nFlags & ACFlags::ChgWeightUnderl) ? TRISTATE_TRUE : TRISTATE_FALSE, CBCOL_SECOND);
597 m_xCheckLB->set_toggle(DETECT_URL, pOpt->bSetINetAttr ? TRISTATE_TRUE : TRISTATE_FALSE, CBCOL_FIRST);
598 m_xCheckLB->set_toggle(DETECT_URL, bool(nFlags & ACFlags::SetINetAttr) ? TRISTATE_TRUE : TRISTATE_FALSE, CBCOL_SECOND);
599 m_xCheckLB->set_toggle(DETECT_DOI, pOpt->bSetDOIAttr ? TRISTATE_TRUE : TRISTATE_FALSE, CBCOL_FIRST);
600 m_xCheckLB->set_toggle(DETECT_DOI, bool(nFlags & ACFlags::SetDOIAttr) ? TRISTATE_TRUE : TRISTATE_FALSE, CBCOL_SECOND);
601 m_xCheckLB->set_toggle(REPLACE_DASHES, pOpt->bChgToEnEmDash ? TRISTATE_TRUE : TRISTATE_FALSE, CBCOL_FIRST);
602 m_xCheckLB->set_toggle(REPLACE_DASHES, bool(nFlags & ACFlags::ChgToEnEmDash) ? TRISTATE_TRUE : TRISTATE_FALSE, CBCOL_SECOND);
603 m_xCheckLB->set_toggle(DEL_SPACES_AT_STT_END, pOpt->bAFormatDelSpacesAtSttEnd ? TRISTATE_TRUE : TRISTATE_FALSE, CBCOL_FIRST);
604 m_xCheckLB->set_toggle(DEL_SPACES_AT_STT_END, pOpt->bAFormatByInpDelSpacesAtSttEnd ? TRISTATE_TRUE : TRISTATE_FALSE, CBCOL_SECOND);
605 m_xCheckLB->set_toggle(DEL_SPACES_BETWEEN_LINES, pOpt->bAFormatDelSpacesBetweenLines ? TRISTATE_TRUE : TRISTATE_FALSE, CBCOL_FIRST);
606 m_xCheckLB->set_toggle(DEL_SPACES_BETWEEN_LINES, pOpt->bAFormatByInpDelSpacesBetweenLines ? TRISTATE_TRUE : TRISTATE_FALSE, CBCOL_SECOND);
607 m_xCheckLB->set_toggle(IGNORE_DBLSPACE, bool(nFlags & ACFlags::IgnoreDoubleSpace) ? TRISTATE_TRUE : TRISTATE_FALSE, CBCOL_SECOND);
608 m_xCheckLB->set_toggle(CORRECT_CAPS_LOCK, bool(nFlags & ACFlags::CorrectCapsLock) ? TRISTATE_TRUE : TRISTATE_FALSE, CBCOL_SECOND);
609 m_xCheckLB->set_toggle(APPLY_NUMBERING, pOpt->bSetNumRule ? TRISTATE_TRUE : TRISTATE_FALSE, CBCOL_SECOND);
610 m_xCheckLB->set_toggle(INSERT_BORDER, pOpt->bSetBorder ? TRISTATE_TRUE : TRISTATE_FALSE, CBCOL_SECOND);
611 m_xCheckLB->set_toggle(CREATE_TABLE, pOpt->bCreateTable ? TRISTATE_TRUE : TRISTATE_FALSE, CBCOL_SECOND);
612 m_xCheckLB->set_toggle(REPLACE_STYLES, pOpt->bReplaceStyles ? TRISTATE_TRUE : TRISTATE_FALSE, CBCOL_SECOND);
613 m_xCheckLB->set_toggle(DEL_EMPTY_NODE, pOpt->bDelEmptyNode ? TRISTATE_TRUE : TRISTATE_FALSE, CBCOL_FIRST);
614 m_xCheckLB->set_toggle(REPLACE_USER_COLL, pOpt->bChgUserColl ? TRISTATE_TRUE : TRISTATE_FALSE, CBCOL_FIRST);
615 m_xCheckLB->set_toggle(REPLACE_BULLETS, pOpt->bChgEnumNum ? TRISTATE_TRUE : TRISTATE_FALSE, CBCOL_FIRST);
616 m_xCheckLB->set_toggle(MERGE_SINGLE_LINE_PARA, pOpt->bRightMargin ? TRISTATE_TRUE : TRISTATE_FALSE, CBCOL_FIRST);
618 ImpUserData* pUserData = new ImpUserData(&sBulletChar, &aBulletFont);
619 OUString sId(weld::toId(pUserData));
620 m_xCheckLB->set_id(REPLACE_BULLETS, sId);
622 pUserData = new ImpUserData(&sMargin, nullptr);
623 sId = weld::toId(pUserData);
624 m_xCheckLB->set_id(MERGE_SINGLE_LINE_PARA, sId);
626 ImpUserData* pUserData2 = new ImpUserData(&sByInputBulletChar, &aByInputBulletFont);
627 sId = weld::toId(pUserData2);
628 m_xCheckLB->set_id(APPLY_NUMBERING, sId);
630 m_xCheckLB->thaw();
633 IMPL_LINK(OfaSwAutoFmtOptionsPage, SelectHdl, weld::TreeView&, rBox, void)
635 m_xEditPB->set_sensitive(rBox.get_selected_id().toInt64() != 0);
638 IMPL_LINK_NOARG(OfaSwAutoFmtOptionsPage, DoubleClickEditHdl, weld::TreeView&, bool)
640 EditHdl(*m_xEditPB);
641 return true;
644 IMPL_LINK_NOARG(OfaSwAutoFmtOptionsPage, EditHdl, weld::Button&, void)
646 int nSelEntryPos = m_xCheckLB->get_selected_index();
647 if (nSelEntryPos == REPLACE_BULLETS || nSelEntryPos == APPLY_NUMBERING)
649 SvxCharacterMap aMapDlg(GetFrameWeld(), nullptr, nullptr);
650 ImpUserData* pUserData = weld::fromId<ImpUserData*>(m_xCheckLB->get_id(nSelEntryPos));
651 aMapDlg.SetCharFont(*pUserData->pFont);
652 aMapDlg.SetChar( (*pUserData->pString)[0] );
653 if (RET_OK == aMapDlg.run())
655 const vcl::Font& aFont(aMapDlg.GetCharFont());
656 *pUserData->pFont = aFont;
657 sal_UCS4 aChar = aMapDlg.GetChar();
658 // using the UCS4 constructor
659 OUString aOUStr( &aChar, 1 );
660 *pUserData->pString = aOUStr;
661 if (nSelEntryPos == REPLACE_BULLETS)
662 m_xCheckLB->set_text(nSelEntryPos, sNum.replaceFirst("%1", aOUStr), 2);
663 else
664 m_xCheckLB->set_text(nSelEntryPos, sBullet.replaceFirst("%1", aOUStr), 2);
667 else if( MERGE_SINGLE_LINE_PARA == nSelEntryPos )
669 // dialog for per cent settings
670 OfaAutoFmtPrcntSet aDlg(GetFrameWeld());
671 aDlg.GetPrcntFld().set_value(nPercent, FieldUnit::PERCENT);
672 if (aDlg.run() == RET_OK)
674 nPercent = static_cast<sal_uInt16>(aDlg.GetPrcntFld().get_value(FieldUnit::PERCENT));
675 sMargin = unicode::formatPercent(nPercent, Application::GetSettings().GetUILanguageTag());
676 m_xCheckLB->set_text(nSelEntryPos, sRightMargin.replaceFirst("%1", sMargin), 2);
682 OfaAutocorrReplacePage::OfaAutocorrReplacePage(weld::Container* pPage, weld::DialogController* pController,
683 const SfxItemSet& rSet)
684 : SfxTabPage(pPage, pController, "cui/ui/acorreplacepage.ui", "AcorReplacePage", &rSet)
685 , maCompareClass(comphelper::getProcessComponentContext())
686 , eLang(eLastDialogLanguage)
687 , bHasSelectionText(false)
688 , bFirstSelect(true)
689 , bReplaceEditChanged(false)
690 , bSWriter(true)
691 , m_xTextOnlyCB(m_xBuilder->weld_check_button("textonly"))
692 , m_xShortED(m_xBuilder->weld_entry("origtext"))
693 , m_xReplaceED(m_xBuilder->weld_entry("newtext"))
694 , m_xReplaceTLB(m_xBuilder->weld_tree_view("tabview"))
695 , m_xNewReplacePB(m_xBuilder->weld_button("new"))
696 , m_xReplacePB(m_xBuilder->weld_button("replace"))
697 , m_xDeleteReplacePB(m_xBuilder->weld_button("delete"))
698 , m_xButtonBox(m_xBuilder->weld_container("buttonbox"))
700 sNew = m_xNewReplacePB->get_label();
701 sModify = m_xReplacePB->get_label();
703 // lock down the width of the button box to its max
704 // desired width
705 auto nMaxWidth = m_xButtonBox->get_preferred_size().Width();
706 m_xButtonBox->set_size_request(nMaxWidth, -1);
707 m_xReplacePB->hide();
709 // tdf#125348 set some small but fixed initial width size, final width will
710 // depend on the size of the entry boxes
711 m_xReplaceTLB->set_size_request(42, m_xReplaceTLB->get_height_rows(10));
713 SfxModule *pMod = SfxApplication::GetModule(SfxToolsModule::Writer);
714 bSWriter = pMod == SfxModule::GetActiveModule();
716 LanguageTag aLanguageTag( eLastDialogLanguage );
717 maCompareClass.loadDefaultCollator( aLanguageTag.getLocale(), 0 );
718 pCharClass.reset( new CharClass( std::move(aLanguageTag) ) );
720 auto nColWidth = m_xReplaceTLB->get_approximate_digit_width() * 32;
721 m_aReplaceFixedWidths.push_back(nColWidth);
722 m_aReplaceFixedWidths.push_back(nColWidth);
724 m_xReplaceTLB->connect_changed( LINK(this, OfaAutocorrReplacePage, SelectHdl) );
725 m_xNewReplacePB->connect_clicked( LINK(this, OfaAutocorrReplacePage, NewDelButtonHdl) );
726 m_xDeleteReplacePB->connect_clicked( LINK(this, OfaAutocorrReplacePage, NewDelButtonHdl) );
727 m_xShortED->connect_changed( LINK(this, OfaAutocorrReplacePage, ModifyHdl) );
728 m_xReplaceED->connect_changed( LINK(this, OfaAutocorrReplacePage, ModifyHdl) );
729 m_xShortED->connect_activate( LINK(this, OfaAutocorrReplacePage, NewDelActionHdl) );
730 m_xReplaceED->connect_activate( LINK(this, OfaAutocorrReplacePage, NewDelActionHdl) );
731 m_xShortED->connect_size_allocate(LINK(this, OfaAutocorrReplacePage, EntrySizeAllocHdl));
732 m_xReplaceED->connect_size_allocate(LINK(this, OfaAutocorrReplacePage, EntrySizeAllocHdl));
735 OfaAutocorrReplacePage::~OfaAutocorrReplacePage()
737 aDoubleStringTable.clear();
738 aChangesTable.clear();
740 pCharClass.reset();
743 std::unique_ptr<SfxTabPage> OfaAutocorrReplacePage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rSet)
745 return std::make_unique<OfaAutocorrReplacePage>(pPage, pController, *rSet);
748 void OfaAutocorrReplacePage::ActivatePage( const SfxItemSet& )
750 if(eLang != eLastDialogLanguage)
751 SetLanguage(eLastDialogLanguage);
752 static_cast<OfaAutoCorrDlg*>(GetDialogController())->EnableLanguage(true);
755 DeactivateRC OfaAutocorrReplacePage::DeactivatePage( SfxItemSet* )
757 return DeactivateRC::LeavePage;
760 bool OfaAutocorrReplacePage::FillItemSet( SfxItemSet* )
762 SvxAutoCorrect* pAutoCorrect = SvxAutoCorrCfg::Get().GetAutoCorrect();
764 for (StringChangeTable::reverse_iterator it = aChangesTable.rbegin(); it != aChangesTable.rend(); ++it)
766 LanguageType eCurrentLang = it->first;
767 StringChangeList& rStringChangeList = it->second;
768 std::vector<SvxAutocorrWord> aDeleteWords;
769 std::vector<SvxAutocorrWord> aNewWords;
771 aDeleteWords.reserve( rStringChangeList.aDeletedEntries.size() );
772 for (const DoubleString & deleteEntry : rStringChangeList.aDeletedEntries)
774 SvxAutocorrWord aDeleteWord( deleteEntry.sShort, deleteEntry.sLong );
775 aDeleteWords.push_back( aDeleteWord );
778 aNewWords.reserve( rStringChangeList.aNewEntries.size() );
779 for (const DoubleString & newEntry : rStringChangeList.aNewEntries)
781 //fdo#67697 if the user data is set then we want to retain the
782 //source formatting of the entry, so don't use the optimized
783 //text-only MakeCombinedChanges for this entry
784 bool bKeepSourceFormatting = newEntry.pUserData == &bHasSelectionText;
785 if (bKeepSourceFormatting)
787 if (SfxObjectShell* pSh = SfxObjectShell::Current())
788 pAutoCorrect->PutText(newEntry.sShort, *pSh, eCurrentLang);
789 continue;
792 SvxAutocorrWord aNewWord( newEntry.sShort, newEntry.sLong );
793 aNewWords.push_back( aNewWord );
795 pAutoCorrect->MakeCombinedChanges( aNewWords, aDeleteWords, eCurrentLang );
797 aChangesTable.clear();
798 return false;
801 void OfaAutocorrReplacePage::RefillReplaceBox(bool bFromReset,
802 LanguageType eOldLanguage,
803 LanguageType eNewLanguage)
805 eLang = eNewLanguage;
806 if(bFromReset)
808 aDoubleStringTable.clear();
809 aChangesTable.clear();
811 else
813 DoubleStringArray* pArray;
814 if(aDoubleStringTable.find(eOldLanguage) != aDoubleStringTable.end())
816 pArray = &aDoubleStringTable[eOldLanguage];
817 pArray->clear();
819 else
821 pArray = &aDoubleStringTable[eOldLanguage]; // create new array
824 m_xReplaceTLB->all_foreach([this, &pArray](weld::TreeIter& rIter) {
825 pArray->push_back(DoubleString(m_xReplaceTLB->get_text(rIter, 0),
826 m_xReplaceTLB->get_text(rIter, 1)));
827 DoubleString& rDouble = pArray->back();
828 rDouble.pUserData = weld::fromId<void*>(m_xReplaceTLB->get_id(rIter));
829 return false;
833 if( !bSWriter )
834 aFormatText.clear();
836 if (aDoubleStringTable.find(eLang) != aDoubleStringTable.end())
838 DoubleStringArray& rArray = aDoubleStringTable[eNewLanguage];
840 m_xReplaceTLB->bulk_insert_for_each(rArray.size(), [this, &rArray](weld::TreeIter& rIter, int nIndex) {
841 DoubleString &rDouble = rArray[nIndex];
842 bool bTextOnly = nullptr == rDouble.pUserData;
843 // formatted text is only in Writer
844 if (bSWriter || bTextOnly)
846 if (!bTextOnly)
848 // that means: with format info or even with selection text
849 OUString sId = weld::toId(rDouble.pUserData);
850 m_xReplaceTLB->set_id(rIter, sId);
852 m_xReplaceTLB->set_text(rIter, rDouble.sShort, 0);
853 m_xReplaceTLB->set_text(rIter, rDouble.sLong, 1);
855 else
857 aFormatText.insert(rDouble.sShort);
859 }, nullptr, &m_aReplaceFixedWidths);
861 else
863 SvxAutoCorrect* pAutoCorrect = SvxAutoCorrCfg::Get().GetAutoCorrect();
864 SvxAutocorrWordList* pWordList = pAutoCorrect->LoadAutocorrWordList(eLang);
865 const SvxAutocorrWordList::AutocorrWordSetType & rContent = pWordList->getSortedContent();
866 m_xReplaceTLB->bulk_insert_for_each(rContent.size(), [this, rContent](weld::TreeIter& rIter, int nIndex) {
867 auto const& elem = rContent[nIndex];
868 bool bTextOnly = elem.IsTextOnly();
869 // formatted text is only in Writer
870 if (bSWriter || bTextOnly)
872 if (!bTextOnly)
874 // that means: with format info or even with selection text
875 OUString sId = weld::toId(m_xTextOnlyCB.get());
876 m_xReplaceTLB->set_id(rIter, sId);
878 m_xReplaceTLB->set_text(rIter, elem.GetShort(), 0);
879 m_xReplaceTLB->set_text(rIter, elem.GetLong(), 1);
881 else
883 aFormatText.insert(elem.GetShort());
885 }, nullptr, &m_aReplaceFixedWidths);
886 m_xNewReplacePB->set_sensitive(false);
887 m_xDeleteReplacePB->set_sensitive(false);
890 SfxViewShell* pViewShell = SfxViewShell::Current();
891 if (pViewShell && pViewShell->HasSelection())
893 bHasSelectionText = true;
894 const OUString sSelection( pViewShell->GetSelectionText() );
895 m_xReplaceED->set_text(sSelection);
896 m_xTextOnlyCB->set_active(!bSWriter);
897 m_xTextOnlyCB->set_sensitive(bSWriter && !sSelection.isEmpty());
899 else
901 m_xTextOnlyCB->set_active(true);
902 m_xTextOnlyCB->set_sensitive(false);
906 void OfaAutocorrReplacePage::Reset( const SfxItemSet* )
908 RefillReplaceBox(true, eLang, eLang);
909 m_xShortED->grab_focus();
912 void OfaAutocorrReplacePage::SetLanguage(LanguageType eSet)
914 //save old settings and refill
915 if(eSet != eLang)
917 RefillReplaceBox(false, eLang, eSet);
918 eLastDialogLanguage = eSet;
920 LanguageTag aLanguageTag( eLastDialogLanguage );
921 maCompareClass = CollatorWrapper( comphelper::getProcessComponentContext() );
922 maCompareClass.loadDefaultCollator( aLanguageTag.getLocale(), 0 );
923 pCharClass.reset( new CharClass( std::move(aLanguageTag) ) );
924 ModifyHdl(*m_xShortED);
928 IMPL_LINK(OfaAutocorrReplacePage, SelectHdl, weld::TreeView&, rBox, void)
930 if(!bFirstSelect || !bHasSelectionText)
932 int nEntry = rBox.get_selected_index();
933 OUString sTmpShort(rBox.get_text(nEntry, 0));
934 // if the text is set via ModifyHdl, the cursor is always at the beginning
935 // of a word, although you're editing here
936 bool bSameContent = 0 == maCompareClass.compareString(sTmpShort, m_xShortED->get_text());
937 int nStartPos, nEndPos;
938 m_xShortED->get_selection_bounds(nStartPos, nEndPos);
939 if (m_xShortED->get_text() != sTmpShort)
941 m_xShortED->set_text(sTmpShort);
942 // if it was only a different notation, the selection has to be set again
943 if (bSameContent)
945 m_xShortED->select_region(nStartPos, nEndPos);
948 m_xReplaceED->set_text(rBox.get_text(nEntry, 1));
949 // with UserData there is a Formatinfo
950 m_xTextOnlyCB->set_active(rBox.get_id(nEntry).isEmpty());
952 else
954 bFirstSelect = false;
957 m_xNewReplacePB->set_sensitive(false);
958 m_xDeleteReplacePB->set_sensitive(true);
961 void OfaAutocorrReplacePage::NewEntry(const OUString& sShort, const OUString& sLong, bool bKeepSourceFormatting)
963 DoubleStringArray& rNewArray = aChangesTable[eLang].aNewEntries;
964 for (size_t i = 0; i < rNewArray.size(); i++)
966 if (rNewArray[i].sShort == sShort)
968 rNewArray.erase(rNewArray.begin() + i);
969 break;
973 DoubleStringArray& rDeletedArray = aChangesTable[eLang].aDeletedEntries;
974 for (size_t i = 0; i < rDeletedArray.size(); i++)
976 if (rDeletedArray[i].sShort == sShort)
978 rDeletedArray.erase(rDeletedArray.begin() + i);
979 break;
983 DoubleString aNewString(sShort, sLong);
984 rNewArray.push_back(aNewString);
985 if (bKeepSourceFormatting)
986 rNewArray.back().pUserData = &bHasSelectionText;
989 void OfaAutocorrReplacePage::DeleteEntry(const OUString& sShort, const OUString& sLong)
991 DoubleStringArray& rNewArray = aChangesTable[eLang].aNewEntries;
992 for (size_t i = 0; i < rNewArray.size(); i++)
994 if (rNewArray[i].sShort == sShort)
996 rNewArray.erase(rNewArray.begin() + i);
997 break;
1001 DoubleStringArray& rDeletedArray = aChangesTable[eLang].aDeletedEntries;
1002 for (size_t i = 0; i < rDeletedArray.size(); i++)
1004 if (rDeletedArray[i].sShort == sShort)
1006 rDeletedArray.erase(rDeletedArray.begin() + i);
1007 break;
1011 DoubleString aDeletedString(sShort, sLong);
1012 rDeletedArray.push_back(aDeletedString);
1015 IMPL_LINK(OfaAutocorrReplacePage, NewDelButtonHdl, weld::Button&, rBtn, void)
1017 NewDelHdl(&rBtn);
1020 IMPL_LINK(OfaAutocorrReplacePage, NewDelActionHdl, weld::Entry&, rEdit, bool)
1022 return NewDelHdl(&rEdit);
1025 IMPL_LINK_NOARG(OfaAutocorrReplacePage, EntrySizeAllocHdl, const Size&, void)
1027 m_aReplaceFixedWidths.clear();
1028 int x, y, width, height;
1029 if (m_xReplaceED->get_extents_relative_to(*m_xReplaceTLB, x, y, width, height))
1031 m_aReplaceFixedWidths.push_back(x);
1032 m_aReplaceFixedWidths.push_back(width - 1);
1033 m_xReplaceTLB->set_column_fixed_widths(m_aReplaceFixedWidths);
1037 bool OfaAutocorrReplacePage::NewDelHdl(const weld::Widget* pBtn)
1039 int nEntry = m_xReplaceTLB->get_selected_index();
1040 if (pBtn == m_xDeleteReplacePB.get())
1042 DBG_ASSERT( nEntry != -1, "no entry selected" );
1043 if (nEntry != -1)
1045 DeleteEntry(m_xReplaceTLB->get_text(nEntry, 0), m_xReplaceTLB->get_text(nEntry, 1));
1046 m_xReplaceTLB->remove(nEntry);
1047 ModifyHdl(*m_xShortED);
1048 return true;
1052 if (pBtn == m_xNewReplacePB.get() || m_xNewReplacePB->get_sensitive())
1054 OUString sEntry(m_xShortED->get_text());
1055 if (!sEntry.isEmpty() && (!m_xReplaceED->get_text().isEmpty() ||
1056 ( bHasSelectionText && bSWriter ) ))
1058 bool bKeepSourceFormatting = !bReplaceEditChanged && !m_xTextOnlyCB->get_active();
1060 NewEntry(m_xShortED->get_text(), m_xReplaceED->get_text(), bKeepSourceFormatting);
1061 m_xReplaceTLB->freeze();
1062 int nPos = -1;
1063 if (nEntry != -1)
1065 nPos = nEntry;
1066 m_xReplaceTLB->remove(nEntry);
1068 else
1070 int j;
1071 int nCount = m_xReplaceTLB->n_children();
1072 for (j = 0; j < nCount; ++j)
1074 if (0 >= maCompareClass.compareString(sEntry, m_xReplaceTLB->get_text(j, 0)))
1075 break;
1077 nPos = j;
1080 OUString sId;
1081 if (bKeepSourceFormatting)
1083 sId = weld::toId(&bHasSelectionText); // new formatted text
1086 m_xReplaceTLB->insert(nPos, sEntry, &sId, nullptr, nullptr);
1087 m_xReplaceTLB->set_text(nPos, m_xReplaceED->get_text(), 1);
1088 m_xReplaceTLB->thaw();
1089 m_xReplaceTLB->scroll_to_row(nPos);
1090 // if the request came from the ReplaceEdit, give focus to the ShortEdit
1091 if (m_xReplaceED->has_focus())
1093 m_xShortED->grab_focus();
1097 else
1099 // this can only be an enter in one of the two edit fields
1100 // which means EndDialog() - has to be evaluated in KeyInput
1101 return false;
1103 ModifyHdl(*m_xShortED);
1104 return true;
1107 IMPL_LINK(OfaAutocorrReplacePage, ModifyHdl, weld::Entry&, rEdt, void)
1109 std::unique_ptr<weld::TreeIter> xFirstSel(m_xReplaceTLB->make_iterator());
1110 bool bFirstSelIterSet = m_xReplaceTLB->get_selected(xFirstSel.get());
1111 bool bShort = &rEdt == m_xShortED.get();
1112 const OUString rEntry = rEdt.get_text();
1113 const OUString rRepString = m_xReplaceED->get_text();
1114 OUString aWordStr(pCharClass->lowercase(rEntry));
1116 if(bShort)
1118 if(!rEntry.isEmpty())
1120 bool bFound = false;
1121 bool bTmpSelEntry=false;
1123 m_xReplaceTLB->all_foreach([this, &rEntry, &rRepString, &bFound,
1124 &bTmpSelEntry, &bFirstSelIterSet,
1125 &xFirstSel, &aWordStr](weld::TreeIter& rIter){
1126 OUString aTestStr = m_xReplaceTLB->get_text(rIter, 0);
1127 if( maCompareClass.compareString(rEntry, aTestStr ) == 0 )
1129 if (!rRepString.isEmpty())
1130 bFirstSelect = true;
1131 m_xReplaceTLB->set_cursor(rIter);
1132 m_xReplaceTLB->copy_iterator(rIter, *xFirstSel);
1133 bFirstSelIterSet = true;
1134 m_xNewReplacePB->set_label(sModify);
1135 bFound = true;
1136 return true;
1138 else
1140 aTestStr = pCharClass->lowercase( aTestStr );
1141 if( aTestStr.startsWith(aWordStr) && !bTmpSelEntry )
1143 m_xReplaceTLB->scroll_to_row(rIter);
1144 bTmpSelEntry = true;
1147 return false;
1149 if( !bFound )
1151 m_xReplaceTLB->select(-1);
1152 bFirstSelIterSet = false;
1153 m_xNewReplacePB->set_label(sNew);
1154 if( bReplaceEditChanged )
1155 m_xTextOnlyCB->set_sensitive(false);
1157 m_xDeleteReplacePB->set_sensitive(bFound);
1159 else if (m_xReplaceTLB->n_children() > 0)
1161 m_xReplaceTLB->scroll_to_row(0);
1165 else if( !bShort )
1167 bReplaceEditChanged = true;
1168 if (bFirstSelIterSet)
1170 m_xNewReplacePB->set_label(sModify);
1174 const OUString& rShortTxt = m_xShortED->get_text();
1175 bool bEnableNew = !rShortTxt.isEmpty() &&
1176 ( !rRepString.isEmpty() ||
1177 ( bHasSelectionText && bSWriter )) &&
1178 ( !bFirstSelIterSet || rRepString !=
1179 m_xReplaceTLB->get_text(*xFirstSel, 1) );
1180 if( bEnableNew )
1182 for (auto const& elem : aFormatText)
1184 if(elem == rShortTxt)
1186 bEnableNew = false;
1187 break;
1191 m_xNewReplacePB->set_sensitive(bEnableNew);
1194 static bool lcl_FindInArray(std::vector<OUString>& rStrings, std::u16string_view rString)
1196 for (auto const& elem : rStrings)
1198 if(elem == rString)
1200 return true;
1203 return false;
1206 OfaAutocorrExceptPage::OfaAutocorrExceptPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet)
1207 : SfxTabPage(pPage, pController, "cui/ui/acorexceptpage.ui", "AcorExceptPage", &rSet)
1208 , maCompareClass(comphelper::getProcessComponentContext())
1209 , eLang(eLastDialogLanguage)
1210 , m_xAbbrevED(m_xBuilder->weld_entry("abbrev"))
1211 , m_xAbbrevLB(m_xBuilder->weld_tree_view("abbrevlist"))
1212 , m_xNewAbbrevPB(m_xBuilder->weld_button("newabbrev"))
1213 , m_xDelAbbrevPB(m_xBuilder->weld_button("delabbrev"))
1214 , m_xAutoAbbrevCB(m_xBuilder->weld_check_button("autoabbrev"))
1215 , m_xDoubleCapsED(m_xBuilder->weld_entry("double"))
1216 , m_xDoubleCapsLB(m_xBuilder->weld_tree_view("doublelist"))
1217 , m_xNewDoublePB(m_xBuilder->weld_button("newdouble"))
1218 , m_xDelDoublePB(m_xBuilder->weld_button("deldouble"))
1219 , m_xAutoCapsCB(m_xBuilder->weld_check_button("autodouble"))
1221 m_xAbbrevLB->make_sorted();
1222 m_xAbbrevLB->set_size_request(-1, m_xAbbrevLB->get_height_rows(6));
1224 m_xDoubleCapsLB->make_sorted();
1225 m_xDoubleCapsLB->set_size_request(-1, m_xDoubleCapsLB->get_height_rows(6));
1227 css::lang::Locale aLcl( LanguageTag::convertToLocale(eLastDialogLanguage ));
1228 maCompareClass.loadDefaultCollator( aLcl, 0 );
1230 m_xNewAbbrevPB->connect_clicked(LINK(this, OfaAutocorrExceptPage, NewDelButtonHdl));
1231 m_xDelAbbrevPB->connect_clicked(LINK(this, OfaAutocorrExceptPage, NewDelButtonHdl));
1232 m_xNewDoublePB->connect_clicked(LINK(this, OfaAutocorrExceptPage, NewDelButtonHdl));
1233 m_xDelDoublePB->connect_clicked(LINK(this, OfaAutocorrExceptPage, NewDelButtonHdl));
1235 m_xAbbrevLB->connect_changed(LINK(this, OfaAutocorrExceptPage, SelectHdl));
1236 m_xDoubleCapsLB->connect_changed(LINK(this, OfaAutocorrExceptPage, SelectHdl));
1237 m_xAbbrevED->connect_changed(LINK(this, OfaAutocorrExceptPage, ModifyHdl));
1238 m_xDoubleCapsED->connect_changed(LINK(this, OfaAutocorrExceptPage, ModifyHdl));
1240 m_xAbbrevED->connect_activate(LINK(this, OfaAutocorrExceptPage, NewDelActionHdl));
1241 m_xDoubleCapsED->connect_activate(LINK(this, OfaAutocorrExceptPage, NewDelActionHdl));
1244 OfaAutocorrExceptPage::~OfaAutocorrExceptPage()
1246 aStringsTable.clear();
1249 std::unique_ptr<SfxTabPage> OfaAutocorrExceptPage::Create(weld::Container* pPage, weld::DialogController* pController,
1250 const SfxItemSet* rSet)
1252 return std::make_unique<OfaAutocorrExceptPage>(pPage, pController, *rSet);
1255 void OfaAutocorrExceptPage::ActivatePage( const SfxItemSet& )
1257 if(eLang != eLastDialogLanguage)
1258 SetLanguage(eLastDialogLanguage);
1259 static_cast<OfaAutoCorrDlg*>(GetDialogController())->EnableLanguage(true);
1262 DeactivateRC OfaAutocorrExceptPage::DeactivatePage( SfxItemSet* )
1264 return DeactivateRC::LeavePage;
1267 bool OfaAutocorrExceptPage::FillItemSet( SfxItemSet* )
1269 SvxAutoCorrect* pAutoCorrect = SvxAutoCorrCfg::Get().GetAutoCorrect();
1270 for(StringsTable::reverse_iterator it1 = aStringsTable.rbegin(); it1 != aStringsTable.rend(); ++it1)
1272 LanguageType eCurLang = it1->first;
1273 StringsArrays& rArrays = it1->second;
1274 if(eCurLang != eLang) // current language is treated later
1276 SvStringsISortDtor* pWrdList = pAutoCorrect->LoadWordStartExceptList(eCurLang);
1278 if(pWrdList)
1280 size_t nCount = pWrdList->size();
1281 size_t i;
1282 for( i = nCount; i; )
1284 OUString aString = (*pWrdList)[ --i ];
1286 if( !lcl_FindInArray(rArrays.aDoubleCapsStrings, aString))
1288 pWrdList->erase_at(i);
1292 for (auto const& elem : rArrays.aDoubleCapsStrings)
1294 pWrdList->insert(elem);
1296 pAutoCorrect->SaveWordStartExceptList(eCurLang);
1299 SvStringsISortDtor* pCplList = pAutoCorrect->LoadCplSttExceptList(eCurLang);
1301 if(pCplList)
1303 size_t nCount = pCplList->size();
1304 size_t i;
1305 for( i = nCount; i; )
1307 OUString aString = (*pCplList)[ --i ];
1308 if( !lcl_FindInArray(rArrays.aAbbrevStrings, aString))
1310 pCplList->erase_at(i);
1314 for (auto const& elem : rArrays.aAbbrevStrings)
1316 pCplList->insert(elem);
1319 pAutoCorrect->SaveCplSttExceptList(eCurLang);
1323 aStringsTable.clear();
1325 SvStringsISortDtor* pWrdList = pAutoCorrect->LoadWordStartExceptList(eLang);
1327 if(pWrdList)
1329 size_t nCount = pWrdList->size();
1330 size_t i;
1331 for( i = nCount; i; )
1333 OUString aString = (*pWrdList)[ --i ];
1334 if (m_xDoubleCapsLB->find_text(aString) == -1)
1336 pWrdList->erase_at(i);
1339 nCount = m_xDoubleCapsLB->n_children();
1340 for( i = 0; i < nCount; ++i )
1342 pWrdList->insert(m_xDoubleCapsLB->get_text(i));
1344 pAutoCorrect->SaveWordStartExceptList(eLang);
1347 SvStringsISortDtor* pCplList = pAutoCorrect->LoadCplSttExceptList(eLang);
1349 if(pCplList)
1351 size_t nCount = pCplList->size();
1352 for( size_t i = nCount; i; )
1354 OUString aString = (*pCplList)[ --i ];
1355 if (m_xAbbrevLB->find_text(aString) == -1)
1357 pCplList->erase_at(i);
1360 sal_Int32 nAbbrevCount = m_xAbbrevLB->n_children();
1361 for( sal_Int32 ia = 0; ia < nAbbrevCount; ++ia )
1363 pCplList->insert(m_xAbbrevLB->get_text(ia));
1365 pAutoCorrect->SaveCplSttExceptList(eLang);
1367 if (m_xAutoAbbrevCB->get_state_changed_from_saved())
1368 pAutoCorrect->SetAutoCorrFlag( ACFlags::SaveWordCplSttLst, m_xAutoAbbrevCB->get_active());
1369 if (m_xAutoCapsCB->get_state_changed_from_saved())
1370 pAutoCorrect->SetAutoCorrFlag( ACFlags::SaveWordWordStartLst, m_xAutoCapsCB->get_active());
1371 return false;
1374 void OfaAutocorrExceptPage::SetLanguage(LanguageType eSet)
1376 if(eLang != eSet)
1378 // save old settings and fill anew
1379 RefillReplaceBoxes(false, eLang, eSet);
1380 eLastDialogLanguage = eSet;
1381 maCompareClass = CollatorWrapper( comphelper::getProcessComponentContext() );
1382 maCompareClass.loadDefaultCollator( LanguageTag::convertToLocale( eLastDialogLanguage ), 0 );
1383 ModifyHdl(*m_xAbbrevED);
1384 ModifyHdl(*m_xDoubleCapsED);
1388 void OfaAutocorrExceptPage::RefillReplaceBoxes(bool bFromReset,
1389 LanguageType eOldLanguage,
1390 LanguageType eNewLanguage)
1392 eLang = eNewLanguage;
1393 if(bFromReset)
1395 aStringsTable.clear();
1397 else
1399 StringsArrays* pArrays;
1400 if(aStringsTable.find(eOldLanguage) != aStringsTable.end())
1402 pArrays = &aStringsTable[eOldLanguage];
1403 pArrays->aAbbrevStrings.clear();
1404 pArrays->aDoubleCapsStrings.clear();
1406 else
1408 pArrays = &aStringsTable[eOldLanguage]; // create new array
1411 sal_Int32 i, nCount;
1412 nCount = m_xAbbrevLB->n_children();
1413 for(i = 0; i < nCount; i++)
1414 pArrays->aAbbrevStrings.push_back(m_xAbbrevLB->get_text(i));
1416 nCount = m_xDoubleCapsLB->n_children();
1417 for(i = 0; i < nCount; i++)
1418 pArrays->aDoubleCapsStrings.push_back(m_xDoubleCapsLB->get_text(i));
1420 m_xDoubleCapsLB->clear();
1421 m_xAbbrevLB->clear();
1422 m_xAbbrevED->set_text("");
1423 m_xDoubleCapsED->set_text("");
1425 if(aStringsTable.find(eLang) != aStringsTable.end())
1427 StringsArrays& rArrays = aStringsTable[eLang];
1428 for (auto const& elem : rArrays.aAbbrevStrings)
1429 m_xAbbrevLB->append_text(elem);
1431 for (auto const& elem : rArrays.aDoubleCapsStrings)
1432 m_xDoubleCapsLB->append_text(elem);
1434 else
1436 SvxAutoCorrect* pAutoCorrect = SvxAutoCorrCfg::Get().GetAutoCorrect();
1437 const SvStringsISortDtor* pCplList = pAutoCorrect->GetCplSttExceptList(eLang);
1438 const SvStringsISortDtor* pWrdList = pAutoCorrect->GetWordStartExceptList(eLang);
1439 size_t i;
1440 for( i = 0; i < pCplList->size(); i++ )
1442 m_xAbbrevLB->append_text((*pCplList)[i]);
1444 for( i = 0; i < pWrdList->size(); i++ )
1446 m_xDoubleCapsLB->append_text((*pWrdList)[i]);
1451 void OfaAutocorrExceptPage::Reset( const SfxItemSet* )
1453 SvxAutoCorrect* pAutoCorrect = SvxAutoCorrCfg::Get().GetAutoCorrect();
1454 RefillReplaceBoxes(true, eLang, eLang);
1455 m_xAutoAbbrevCB->set_active(pAutoCorrect->IsAutoCorrFlag( ACFlags::SaveWordCplSttLst));
1456 m_xAutoCapsCB->set_active(pAutoCorrect->IsAutoCorrFlag( ACFlags::SaveWordWordStartLst));
1457 m_xAutoAbbrevCB->save_state();
1458 m_xAutoCapsCB->save_state();
1461 IMPL_LINK(OfaAutocorrExceptPage, NewDelButtonHdl, weld::Button&, rBtn, void)
1463 NewDelHdl(&rBtn);
1466 IMPL_LINK(OfaAutocorrExceptPage, NewDelActionHdl, weld::Entry&, rEdit, bool)
1468 return NewDelHdl(&rEdit);
1471 bool OfaAutocorrExceptPage::NewDelHdl(const weld::Widget* pBtn)
1473 if ((pBtn == m_xNewAbbrevPB.get() || pBtn == m_xAbbrevED.get())
1474 && !m_xAbbrevED->get_text().isEmpty() && m_xNewAbbrevPB->get_sensitive())
1476 m_xAbbrevLB->append_text(m_xAbbrevED->get_text());
1477 ModifyHdl(*m_xAbbrevED);
1479 else if(pBtn == m_xDelAbbrevPB.get())
1481 m_xAbbrevLB->remove_text(m_xAbbrevED->get_text());
1482 ModifyHdl(*m_xAbbrevED);
1484 else if((pBtn == m_xNewDoublePB.get() || pBtn == m_xDoubleCapsED.get() )
1485 && !m_xDoubleCapsED->get_text().isEmpty() && m_xNewDoublePB->get_sensitive())
1487 m_xDoubleCapsLB->append_text(m_xDoubleCapsED->get_text());
1488 ModifyHdl(*m_xDoubleCapsED);
1490 else if (pBtn == m_xDelDoublePB.get())
1492 m_xDoubleCapsLB->remove_text(m_xDoubleCapsED->get_text());
1493 ModifyHdl(*m_xDoubleCapsED);
1495 else
1497 // we didn't do anything, if this was because of 'activate' in an
1498 // entry then let it continue to close the dialog like the replace
1499 // page does
1500 return false;
1502 return true;
1505 IMPL_LINK(OfaAutocorrExceptPage, SelectHdl, weld::TreeView&, rBox, void)
1507 if (&rBox == m_xAbbrevLB.get())
1509 m_xAbbrevED->set_text(rBox.get_selected_text());
1510 m_xNewAbbrevPB->set_sensitive(false);
1511 m_xDelAbbrevPB->set_sensitive(true);
1513 else
1515 m_xDoubleCapsED->set_text(rBox.get_selected_text());
1516 m_xNewDoublePB->set_sensitive(false);
1517 m_xDelDoublePB->set_sensitive(true);
1521 IMPL_LINK(OfaAutocorrExceptPage, ModifyHdl, weld::Entry&, rEdt, void)
1523 const OUString& sEntry = rEdt.get_text();
1524 bool bEntryLen = !sEntry.isEmpty();
1525 if (&rEdt == m_xAbbrevED.get())
1527 bool bSame = lcl_FindEntry(*m_xAbbrevLB, sEntry, maCompareClass);
1528 if(bSame && sEntry != m_xAbbrevLB->get_selected_text())
1529 rEdt.set_text(m_xAbbrevLB->get_selected_text());
1530 m_xNewAbbrevPB->set_sensitive(!bSame && bEntryLen);
1531 m_xDelAbbrevPB->set_sensitive(bSame && bEntryLen);
1533 else
1535 bool bSame = lcl_FindEntry(*m_xDoubleCapsLB, sEntry, maCompareClass);
1536 if(bSame && sEntry != m_xDoubleCapsLB->get_selected_text())
1537 rEdt.set_text(m_xDoubleCapsLB->get_selected_text());
1538 m_xNewDoublePB->set_sensitive(!bSame && bEntryLen);
1539 m_xDelDoublePB->set_sensitive(bSame && bEntryLen);
1543 namespace {
1545 enum OfaQuoteOptions
1547 ADD_NONBRK_SPACE,
1548 REPLACE_1ST,
1549 TRANSLITERATE_RTL,
1550 REPLACE_ANGLE_QUOTES
1555 void OfaQuoteTabPage::CreateEntry(weld::TreeView& rCheckLB, const OUString& rTxt, sal_uInt16 nCol, sal_uInt16 nTextCol)
1557 rCheckLB.append();
1558 const int nRow = rCheckLB.n_children() - 1;
1559 if (nCol == CBCOL_FIRST || nCol == CBCOL_BOTH)
1560 rCheckLB.set_toggle(nRow, TRISTATE_FALSE, CBCOL_FIRST);
1561 if (nCol == CBCOL_SECOND || nCol == CBCOL_BOTH)
1562 rCheckLB.set_toggle(nRow, TRISTATE_FALSE, CBCOL_SECOND);
1563 rCheckLB.set_text(nRow, rTxt, nTextCol);
1566 OfaQuoteTabPage::OfaQuoteTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet)
1567 : SfxTabPage(pPage, pController, "cui/ui/applylocalizedpage.ui", "ApplyLocalizedPage", &rSet)
1568 , sNonBrkSpace(CuiResId(RID_CUISTR_NON_BREAK_SPACE))
1569 , sOrdinal(CuiResId(RID_CUISTR_ORDINAL))
1570 , sTransliterateRTL(CuiResId(RID_CUISTR_OLD_HUNGARIAN))
1571 , sAngleQuotes(CuiResId(RID_CUISTR_ANGLE_QUOTES))
1572 , cSglStartQuote(0)
1573 , cSglEndQuote(0)
1574 , cStartQuote(0)
1575 , cEndQuote(0)
1576 , m_xSingleTypoCB(m_xBuilder->weld_check_button("singlereplace"))
1577 , m_xSglStartQuotePB(m_xBuilder->weld_button("startsingle"))
1578 , m_xSglStartExFT(m_xBuilder->weld_label("singlestartex"))
1579 , m_xSglEndQuotePB(m_xBuilder->weld_button("endsingle"))
1580 , m_xSglEndExFT(m_xBuilder->weld_label("singleendex"))
1581 , m_xSglStandardPB(m_xBuilder->weld_button("defaultsingle"))
1582 , m_xDoubleTypoCB(m_xBuilder->weld_check_button("doublereplace"))
1583 , m_xDblStartQuotePB(m_xBuilder->weld_button("startdouble"))
1584 , m_xDblStartExFT(m_xBuilder->weld_label("doublestartex"))
1585 , m_xDblEndQuotePB(m_xBuilder->weld_button("enddouble"))
1586 , m_xDblEndExFT(m_xBuilder->weld_label("doubleendex"))
1587 , m_xDblStandardPB(m_xBuilder->weld_button("defaultdouble"))
1588 , m_sStandard(m_xSglStartExFT->get_label())
1589 , m_xCheckLB(m_xBuilder->weld_tree_view("checklist"))
1590 , m_xSwCheckLB(m_xBuilder->weld_tree_view("list"))
1592 m_xSwCheckLB->set_size_request(m_xSwCheckLB->get_approximate_digit_width() * 50,
1593 m_xSwCheckLB->get_height_rows(6));
1595 bool bShowSWOptions = false;
1597 const SfxBoolItem* pItem = rSet.GetItem<SfxBoolItem>(SID_AUTO_CORRECT_DLG, false);
1598 if ( pItem && pItem->GetValue() )
1599 bShowSWOptions = true;
1601 if ( bShowSWOptions )
1603 std::vector<int> aWidths
1605 o3tl::narrowing<int>(m_xSwCheckLB->get_pixel_size(m_xSwCheckLB->get_column_title(0)).Width() * 2),
1606 o3tl::narrowing<int>(m_xSwCheckLB->get_pixel_size(m_xSwCheckLB->get_column_title(1)).Width() * 2)
1608 m_xSwCheckLB->set_column_fixed_widths(aWidths);
1609 m_xCheckLB->hide();
1611 else
1613 m_xCheckLB->enable_toggle_buttons(weld::ColumnToggleType::Check);
1614 m_xSwCheckLB->hide();
1617 m_xDblStartQuotePB->connect_clicked(LINK(this, OfaQuoteTabPage, QuoteHdl));
1618 m_xDblEndQuotePB->connect_clicked(LINK(this, OfaQuoteTabPage, QuoteHdl));
1619 m_xSglStartQuotePB->connect_clicked(LINK(this, OfaQuoteTabPage, QuoteHdl));
1620 m_xSglEndQuotePB->connect_clicked(LINK(this, OfaQuoteTabPage, QuoteHdl));
1621 m_xDblStandardPB->connect_clicked(LINK(this, OfaQuoteTabPage, StdQuoteHdl));
1622 m_xSglStandardPB->connect_clicked(LINK(this, OfaQuoteTabPage, StdQuoteHdl));
1625 OfaQuoteTabPage::~OfaQuoteTabPage()
1629 std::unique_ptr<SfxTabPage> OfaQuoteTabPage::Create(weld::Container* pPage, weld::DialogController* pController,
1630 const SfxItemSet* rAttrSet)
1632 return std::make_unique<OfaQuoteTabPage>(pPage, pController, *rAttrSet);
1635 bool OfaQuoteTabPage::FillItemSet( SfxItemSet* )
1637 SvxAutoCorrect* pAutoCorrect = SvxAutoCorrCfg::Get().GetAutoCorrect();
1639 ACFlags nFlags = pAutoCorrect->GetFlags();
1641 if (m_xCheckLB->get_visible())
1643 int nPos = 0;
1644 pAutoCorrect->SetAutoCorrFlag(ACFlags::AddNonBrkSpace, m_xCheckLB->get_toggle(nPos++) == TRISTATE_TRUE);
1645 pAutoCorrect->SetAutoCorrFlag(ACFlags::ChgOrdinalNumber, m_xCheckLB->get_toggle(nPos++) == TRISTATE_TRUE);
1646 pAutoCorrect->SetAutoCorrFlag(ACFlags::TransliterateRTL, m_xCheckLB->get_toggle(nPos++) == TRISTATE_TRUE);
1647 pAutoCorrect->SetAutoCorrFlag(ACFlags::ChgAngleQuotes, m_xCheckLB->get_toggle(nPos++) == TRISTATE_TRUE);
1650 bool bModified = false;
1651 if (m_xSwCheckLB->get_visible())
1653 SvxSwAutoFormatFlags *pOpt = &pAutoCorrect->GetSwFlags();
1655 bool bCheck = m_xSwCheckLB->get_toggle(ADD_NONBRK_SPACE, CBCOL_FIRST) == TRISTATE_TRUE;
1656 bModified |= pOpt->bAddNonBrkSpace != bCheck;
1657 pOpt->bAddNonBrkSpace = bCheck;
1658 pAutoCorrect->SetAutoCorrFlag(ACFlags::AddNonBrkSpace,
1659 m_xSwCheckLB->get_toggle(ADD_NONBRK_SPACE, CBCOL_SECOND) == TRISTATE_TRUE);
1661 bCheck = m_xSwCheckLB->get_toggle(REPLACE_1ST, CBCOL_FIRST) == TRISTATE_TRUE;
1662 bModified |= pOpt->bChgOrdinalNumber != bCheck;
1663 pOpt->bChgOrdinalNumber = bCheck;
1664 pAutoCorrect->SetAutoCorrFlag(ACFlags::ChgOrdinalNumber,
1665 m_xSwCheckLB->get_toggle(REPLACE_1ST, CBCOL_SECOND) == TRISTATE_TRUE);
1667 bCheck = m_xSwCheckLB->get_toggle(TRANSLITERATE_RTL, CBCOL_FIRST) == TRISTATE_TRUE;
1668 bModified |= pOpt->bTransliterateRTL != bCheck;
1669 pOpt->bTransliterateRTL = bCheck;
1670 pAutoCorrect->SetAutoCorrFlag(ACFlags::TransliterateRTL,
1671 m_xSwCheckLB->get_toggle(TRANSLITERATE_RTL, CBCOL_SECOND) == TRISTATE_TRUE);
1673 bCheck = m_xSwCheckLB->get_toggle(REPLACE_ANGLE_QUOTES, CBCOL_FIRST) == TRISTATE_TRUE;
1674 bModified |= pOpt->bChgAngleQuotes != bCheck;
1675 pOpt->bChgAngleQuotes = bCheck;
1676 pAutoCorrect->SetAutoCorrFlag(ACFlags::ChgAngleQuotes,
1677 m_xSwCheckLB->get_toggle(REPLACE_ANGLE_QUOTES, CBCOL_SECOND) == TRISTATE_TRUE);
1680 pAutoCorrect->SetAutoCorrFlag(ACFlags::ChgQuotes, m_xDoubleTypoCB->get_active());
1681 pAutoCorrect->SetAutoCorrFlag(ACFlags::ChgSglQuotes, m_xSingleTypoCB->get_active());
1682 bool bReturn = nFlags != pAutoCorrect->GetFlags();
1683 if(cStartQuote != pAutoCorrect->GetStartDoubleQuote())
1685 bReturn = true;
1686 sal_Unicode cUCS2 = static_cast<sal_Unicode>(cStartQuote); //TODO
1687 pAutoCorrect->SetStartDoubleQuote(cUCS2);
1689 if(cEndQuote != pAutoCorrect->GetEndDoubleQuote())
1691 bReturn = true;
1692 sal_Unicode cUCS2 = static_cast<sal_Unicode>(cEndQuote); //TODO
1693 pAutoCorrect->SetEndDoubleQuote(cUCS2);
1695 if(cSglStartQuote != pAutoCorrect->GetStartSingleQuote())
1697 bReturn = true;
1698 sal_Unicode cUCS2 = static_cast<sal_Unicode>(cSglStartQuote); //TODO
1699 pAutoCorrect->SetStartSingleQuote(cUCS2);
1701 if(cSglEndQuote != pAutoCorrect->GetEndSingleQuote())
1703 bReturn = true;
1704 sal_Unicode cUCS2 = static_cast<sal_Unicode>(cSglEndQuote); //TODO
1705 pAutoCorrect->SetEndSingleQuote(cUCS2);
1708 if( bModified || bReturn )
1710 SvxAutoCorrCfg& rCfg = SvxAutoCorrCfg::Get();
1711 rCfg.SetModified();
1712 rCfg.Commit();
1714 return bReturn;
1717 void OfaQuoteTabPage::ActivatePage( const SfxItemSet& )
1719 static_cast<OfaAutoCorrDlg*>(GetDialogController())->EnableLanguage(false);
1722 void OfaQuoteTabPage::Reset( const SfxItemSet* )
1724 SvxAutoCorrect* pAutoCorrect = SvxAutoCorrCfg::Get().GetAutoCorrect();
1725 const ACFlags nFlags = pAutoCorrect->GetFlags();
1727 // Initialize the Sw options
1728 if (m_xSwCheckLB->get_visible())
1730 SvxSwAutoFormatFlags *pOpt = &pAutoCorrect->GetSwFlags();
1732 m_xSwCheckLB->freeze();
1733 m_xSwCheckLB->clear();
1735 CreateEntry(*m_xSwCheckLB, sNonBrkSpace, CBCOL_BOTH, 2);
1736 CreateEntry(*m_xSwCheckLB, sOrdinal, CBCOL_BOTH, 2);
1737 CreateEntry(*m_xSwCheckLB, sTransliterateRTL, CBCOL_BOTH, 2);
1738 CreateEntry(*m_xSwCheckLB, sAngleQuotes, CBCOL_BOTH, 2);
1740 m_xSwCheckLB->set_toggle(ADD_NONBRK_SPACE, pOpt->bAddNonBrkSpace ? TRISTATE_TRUE : TRISTATE_FALSE, CBCOL_FIRST);
1741 m_xSwCheckLB->set_toggle(ADD_NONBRK_SPACE, bool(nFlags & ACFlags::AddNonBrkSpace) ? TRISTATE_TRUE : TRISTATE_FALSE, CBCOL_SECOND);
1742 m_xSwCheckLB->set_toggle(REPLACE_1ST, pOpt->bChgOrdinalNumber ? TRISTATE_TRUE : TRISTATE_FALSE, CBCOL_FIRST);
1743 m_xSwCheckLB->set_toggle(REPLACE_1ST, bool(nFlags & ACFlags::ChgOrdinalNumber) ? TRISTATE_TRUE : TRISTATE_FALSE, CBCOL_SECOND);
1744 m_xSwCheckLB->set_toggle(TRANSLITERATE_RTL, pOpt->bTransliterateRTL ? TRISTATE_TRUE : TRISTATE_FALSE, CBCOL_FIRST);
1745 m_xSwCheckLB->set_toggle(TRANSLITERATE_RTL, bool(nFlags & ACFlags::TransliterateRTL) ? TRISTATE_TRUE : TRISTATE_FALSE, CBCOL_SECOND);
1746 m_xSwCheckLB->set_toggle(REPLACE_ANGLE_QUOTES, pOpt->bChgAngleQuotes ? TRISTATE_TRUE : TRISTATE_FALSE, CBCOL_FIRST);
1747 m_xSwCheckLB->set_toggle(REPLACE_ANGLE_QUOTES, bool(nFlags & ACFlags::ChgAngleQuotes) ? TRISTATE_TRUE : TRISTATE_FALSE, CBCOL_SECOND);
1749 m_xSwCheckLB->thaw();
1752 // Initialize the non Sw options
1753 if (m_xCheckLB->get_visible())
1755 m_xCheckLB->freeze();
1756 m_xCheckLB->clear();
1758 int nPos = 0;
1759 m_xCheckLB->append();
1760 m_xCheckLB->set_toggle(nPos, bool(nFlags & ACFlags::AddNonBrkSpace) ? TRISTATE_TRUE : TRISTATE_FALSE);
1761 m_xCheckLB->set_text(nPos++, sNonBrkSpace, 0);
1762 m_xCheckLB->append();
1763 m_xCheckLB->set_toggle(nPos, bool(nFlags & ACFlags::ChgOrdinalNumber) ? TRISTATE_TRUE : TRISTATE_FALSE);
1764 m_xCheckLB->set_text(nPos++, sOrdinal, 0);
1765 m_xCheckLB->append();
1766 m_xCheckLB->set_toggle(nPos, bool(nFlags & ACFlags::TransliterateRTL) ? TRISTATE_TRUE : TRISTATE_FALSE);
1767 m_xCheckLB->set_text(nPos++, sTransliterateRTL, 0);
1768 m_xCheckLB->append();
1769 m_xCheckLB->set_toggle(nPos, bool(nFlags & ACFlags::ChgAngleQuotes) ? TRISTATE_TRUE : TRISTATE_FALSE);
1770 m_xCheckLB->set_text(nPos++, sAngleQuotes, 0);
1772 m_xCheckLB->thaw();
1775 // Initialize the quote stuffs
1776 m_xDoubleTypoCB->set_active(bool(nFlags & ACFlags::ChgQuotes));
1777 m_xSingleTypoCB->set_active(bool(nFlags & ACFlags::ChgSglQuotes));
1778 m_xDoubleTypoCB->save_state();
1779 m_xSingleTypoCB->save_state();
1781 cStartQuote = pAutoCorrect->GetStartDoubleQuote();
1782 cEndQuote = pAutoCorrect->GetEndDoubleQuote();
1783 cSglStartQuote = pAutoCorrect->GetStartSingleQuote();
1784 cSglEndQuote = pAutoCorrect->GetEndSingleQuote();
1786 m_xSglStartExFT->set_label(ChangeStringExt_Impl(cSglStartQuote));
1787 m_xSglEndExFT->set_label(ChangeStringExt_Impl(cSglEndQuote));
1788 m_xDblStartExFT->set_label(ChangeStringExt_Impl(cStartQuote));
1789 m_xDblEndExFT->set_label(ChangeStringExt_Impl(cEndQuote));
1792 #define SGL_START 0
1793 #define DBL_START 1
1794 #define SGL_END 2
1795 #define DBL_END 3
1798 IMPL_LINK(OfaQuoteTabPage, QuoteHdl, weld::Button&, rBtn, void)
1800 sal_uInt16 nMode = SGL_START;
1801 if (&rBtn == m_xSglEndQuotePB.get())
1802 nMode = SGL_END;
1803 else if (&rBtn == m_xDblStartQuotePB.get())
1804 nMode = DBL_START;
1805 else if (&rBtn == m_xDblEndQuotePB.get())
1806 nMode = DBL_END;
1807 // start character selection dialog
1808 SvxCharacterMap aMap(GetFrameWeld(), nullptr, nullptr);
1809 aMap.SetCharFont( OutputDevice::GetDefaultFont(DefaultFontType::LATIN_TEXT,
1810 LANGUAGE_ENGLISH_US, GetDefaultFontFlags::OnlyOne ));
1811 aMap.set_title(nMode < SGL_END ? CuiResId(RID_CUISTR_STARTQUOTE) : CuiResId(RID_CUISTR_ENDQUOTE));
1812 sal_UCS4 cDlg;
1813 SvxAutoCorrect* pAutoCorrect = SvxAutoCorrCfg::Get().GetAutoCorrect();
1814 LanguageType eLang = Application::GetSettings().GetLanguageTag().getLanguageType();
1815 switch( nMode )
1817 case SGL_START:
1818 cDlg = cSglStartQuote;
1819 if(cDlg == 0)
1820 cDlg = pAutoCorrect->GetQuote('\'', true, eLang);
1821 break;
1822 case SGL_END:
1823 cDlg = cSglEndQuote;
1824 if(cDlg == 0)
1825 cDlg = pAutoCorrect->GetQuote('\'', false, eLang);
1826 break;
1827 case DBL_START:
1828 cDlg = cStartQuote;
1829 if(cDlg == 0)
1830 cDlg = pAutoCorrect->GetQuote('\"', true, eLang);
1831 break;
1832 case DBL_END:
1833 cDlg = cEndQuote;
1834 if(cDlg == 0)
1835 cDlg = pAutoCorrect->GetQuote('\"', false, eLang);
1836 break;
1837 default:
1838 OSL_FAIL("svx::OfaQuoteTabPage::QuoteHdl(), how to initialize cDlg?" );
1839 cDlg = 0;
1840 break;
1843 aMap.SetChar( cDlg );
1844 aMap.DisableFontSelection();
1845 if (aMap.run() != RET_OK)
1846 return;
1848 sal_UCS4 cNewChar = aMap.GetChar();
1849 switch( nMode )
1851 case SGL_START:
1852 cSglStartQuote = cNewChar;
1853 m_xSglStartExFT->set_label(ChangeStringExt_Impl(cNewChar));
1854 break;
1855 case SGL_END:
1856 cSglEndQuote = cNewChar;
1857 m_xSglEndExFT->set_label(ChangeStringExt_Impl(cNewChar));
1858 break;
1859 case DBL_START:
1860 cStartQuote = cNewChar;
1861 m_xDblStartExFT->set_label(ChangeStringExt_Impl(cNewChar));
1862 break;
1863 case DBL_END:
1864 cEndQuote = cNewChar;
1865 m_xDblEndExFT->set_label(ChangeStringExt_Impl(cNewChar));
1866 break;
1870 IMPL_LINK(OfaQuoteTabPage, StdQuoteHdl, weld::Button&, rBtn, void)
1872 if (&rBtn == m_xDblStandardPB.get())
1874 cStartQuote = 0;
1875 m_xDblStartExFT->set_label(ChangeStringExt_Impl(0));
1876 cEndQuote = 0;
1877 m_xDblEndExFT->set_label(ChangeStringExt_Impl(0));
1880 else
1882 cSglStartQuote = 0;
1883 m_xSglStartExFT->set_label(ChangeStringExt_Impl(0));
1884 cSglEndQuote = 0;
1885 m_xSglEndExFT->set_label(ChangeStringExt_Impl(0));
1889 OUString OfaQuoteTabPage::ChangeStringExt_Impl( sal_UCS4 cChar )
1891 if (!cChar)
1892 return m_sStandard;
1894 // convert codepoint value to unicode-hex string
1895 sal_UCS4 aStrCodes[32] = { 0, ' ', '(', 'U', '+', '0' };
1896 aStrCodes[0] = cChar;
1897 int nFullLen = 5;
1898 int nHexLen = 4;
1899 while( (cChar >> (4*nHexLen)) != 0 )
1900 ++nHexLen;
1901 for( int i = nHexLen; --i >= 0;)
1903 sal_UCS4 cHexDigit = ((cChar >> (4*i)) & 0x0f) + '0';
1904 if( cHexDigit > '9' )
1905 cHexDigit += 'A' - ('9' + 1);
1906 aStrCodes[ nFullLen++ ] = cHexDigit;
1908 aStrCodes[ nFullLen++ ] = ')';
1909 // using the new UCS4 constructor
1910 OUString aOUStr( aStrCodes, nFullLen );
1911 return aOUStr;
1914 OfaAutoCompleteTabPage::OfaAutoCompleteTabPage(weld::Container* pPage, weld::DialogController* pController,
1915 const SfxItemSet& rSet)
1916 : SfxTabPage(pPage, pController, "cui/ui/wordcompletionpage.ui",
1917 "WordCompletionPage", &rSet)
1918 , m_pAutoCompleteList(nullptr)
1919 , m_nAutoCmpltListCnt(0)
1920 , m_xCBActiv(m_xBuilder->weld_check_button("enablewordcomplete"))
1921 , m_xCBAppendSpace(m_xBuilder->weld_check_button("appendspace"))
1922 , m_xCBAsTip(m_xBuilder->weld_check_button("showastip"))
1923 , m_xCBCollect(m_xBuilder->weld_check_button("collectwords"))
1924 , m_xCBRemoveList(m_xBuilder->weld_check_button("whenclosing"))
1925 , m_xDCBExpandKey(m_xBuilder->weld_combo_box("acceptwith"))
1926 , m_xNFMinWordlen(m_xBuilder->weld_spin_button("minwordlen"))
1927 , m_xNFMaxEntries(m_xBuilder->weld_spin_button("maxentries"))
1928 , m_xLBEntries(m_xBuilder->weld_tree_view("entries"))
1929 , m_xPBEntries(m_xBuilder->weld_button("delete"))
1931 //fdo#65595, we need height-for-width support here, but for now we can
1932 //bodge it
1933 Size aPrefSize(m_xCBRemoveList->get_preferred_size());
1934 int nMaxWidth = m_xCBRemoveList->get_approximate_digit_width() * 40;
1935 if (aPrefSize.Width() > nMaxWidth)
1937 m_xCBRemoveList->set_label_wrap(true);
1938 m_xCBRemoveList->set_size_request(nMaxWidth, -1);
1941 m_xLBEntries->set_size_request(m_xLBEntries->get_approximate_digit_width() * 30,
1942 m_xLBEntries->get_height_rows(10));
1943 m_xLBEntries->set_selection_mode(SelectionMode::Multiple);
1945 // the defined KEYs
1946 static const sal_uInt16 aKeyCodes[] = {
1947 KEY_END,
1948 KEY_RETURN,
1949 KEY_SPACE,
1950 KEY_RIGHT,
1951 KEY_TAB,
1955 for( const sal_uInt16* pKeys = aKeyCodes; *pKeys; ++pKeys )
1957 vcl::KeyCode aKCode(*pKeys);
1958 m_xDCBExpandKey->append(OUString::number(static_cast<sal_Int32>(*pKeys)), aKCode.GetName());
1959 if (KEY_RETURN == *pKeys) // default to RETURN
1960 m_xDCBExpandKey->set_active(std::distance(aKeyCodes, pKeys));
1963 m_xPBEntries->connect_clicked(LINK(this, OfaAutoCompleteTabPage, DeleteHdl));
1964 m_xCBActiv->connect_toggled(LINK(this, OfaAutoCompleteTabPage, CheckHdl));
1965 m_xCBCollect->connect_toggled(LINK(this, OfaAutoCompleteTabPage, CheckHdl));
1966 m_xLBEntries->connect_key_release(LINK(this, OfaAutoCompleteTabPage, KeyReleaseHdl));
1969 OfaAutoCompleteTabPage::~OfaAutoCompleteTabPage()
1973 std::unique_ptr<SfxTabPage> OfaAutoCompleteTabPage::Create(weld::Container* pPage, weld::DialogController* pController,
1974 const SfxItemSet* rSet)
1976 return std::make_unique<OfaAutoCompleteTabPage>(pPage, pController, *rSet);
1979 bool OfaAutoCompleteTabPage::FillItemSet( SfxItemSet* )
1981 bool bModified = false, bCheck;
1982 SvxAutoCorrect* pAutoCorrect = SvxAutoCorrCfg::Get().GetAutoCorrect();
1983 SvxSwAutoFormatFlags *pOpt = &pAutoCorrect->GetSwFlags();
1984 sal_uInt16 nVal;
1986 bCheck = m_xCBActiv->get_active();
1987 bModified |= pOpt->bAutoCompleteWords != bCheck;
1988 pOpt->bAutoCompleteWords = bCheck;
1989 bCheck = m_xCBCollect->get_active();
1990 bModified |= pOpt->bAutoCmpltCollectWords != bCheck;
1991 pOpt->bAutoCmpltCollectWords = bCheck;
1992 bCheck = !m_xCBRemoveList->get_active(); // inverted value!
1993 bModified |= pOpt->bAutoCmpltKeepList != bCheck;
1994 pOpt->bAutoCmpltKeepList = bCheck;
1995 bCheck = m_xCBAppendSpace->get_active();
1996 bModified |= pOpt->bAutoCmpltAppendBlank != bCheck;
1997 pOpt->bAutoCmpltAppendBlank = bCheck;
1998 bCheck = m_xCBAsTip->get_active();
1999 bModified |= pOpt->bAutoCmpltShowAsTip != bCheck;
2000 pOpt->bAutoCmpltShowAsTip = bCheck;
2002 nVal = static_cast<sal_uInt16>(m_xNFMinWordlen->get_value());
2003 bModified |= nVal != pOpt->nAutoCmpltWordLen;
2004 pOpt->nAutoCmpltWordLen = nVal;
2006 nVal = static_cast<sal_uInt16>(m_xNFMaxEntries->get_value());
2007 bModified |= nVal != pOpt->nAutoCmpltListLen;
2008 pOpt->nAutoCmpltListLen = nVal;
2010 const int nPos = m_xDCBExpandKey->get_active();
2011 if (nPos != -1)
2013 sal_Int32 nKey = m_xDCBExpandKey->get_id(nPos).toInt32();
2014 bModified |= nKey != pOpt->nAutoCmpltExpandKey;
2015 pOpt->nAutoCmpltExpandKey = static_cast<sal_uInt16>(nKey);
2018 if (m_pAutoCompleteList && m_nAutoCmpltListCnt != m_xLBEntries->n_children())
2020 bModified = true;
2021 pOpt->m_pAutoCompleteList = m_pAutoCompleteList;
2023 if( bModified )
2025 SvxAutoCorrCfg& rCfg = SvxAutoCorrCfg::Get();
2026 rCfg.SetModified();
2027 rCfg.Commit();
2029 return true;
2032 void OfaAutoCompleteTabPage::Reset( const SfxItemSet* )
2034 SvxAutoCorrect* pAutoCorrect = SvxAutoCorrCfg::Get().GetAutoCorrect();
2035 SvxSwAutoFormatFlags *pOpt = &pAutoCorrect->GetSwFlags();
2037 m_xCBActiv->set_active( pOpt->bAutoCompleteWords );
2038 m_xCBCollect->set_active( pOpt->bAutoCmpltCollectWords );
2039 m_xCBRemoveList->set_active( !pOpt->bAutoCmpltKeepList ); //inverted value!
2040 m_xCBAppendSpace->set_active( pOpt->bAutoCmpltAppendBlank );
2041 m_xCBAsTip->set_active( pOpt->bAutoCmpltShowAsTip );
2043 m_xNFMinWordlen->set_value( pOpt->nAutoCmpltWordLen );
2044 m_xNFMaxEntries->set_value( pOpt->nAutoCmpltListLen );
2046 // select the specific KeyCode:
2048 sal_Int32 nKey = pOpt->nAutoCmpltExpandKey;
2049 for (int n = 0, nCnt = m_xDCBExpandKey->get_count(); n < nCnt; ++n)
2051 if (nKey == m_xDCBExpandKey->get_id(n).toInt32())
2053 m_xDCBExpandKey->set_active(n);
2054 break;
2059 if (pOpt->m_pAutoCompleteList && !pOpt->m_pAutoCompleteList->empty())
2061 m_pAutoCompleteList = const_cast<editeng::SortedAutoCompleteStrings*>(
2062 pOpt->m_pAutoCompleteList);
2063 pOpt->m_pAutoCompleteList = nullptr;
2064 m_nAutoCmpltListCnt = m_pAutoCompleteList->size();
2065 for (size_t n = 0; n < m_nAutoCmpltListCnt; ++n)
2067 const OUString* pStr =
2068 &(*m_pAutoCompleteList)[n]->GetAutoCompleteString();
2069 OUString sId(weld::toId(pStr));
2070 m_xLBEntries->append(sId, *pStr);
2073 else
2075 m_xLBEntries->set_sensitive(false);
2076 m_xPBEntries->set_sensitive(false);
2079 CheckHdl(*m_xCBActiv);
2080 CheckHdl(*m_xCBCollect);
2083 void OfaAutoCompleteTabPage::ActivatePage( const SfxItemSet& )
2085 static_cast<OfaAutoCorrDlg*>(GetDialogController())->EnableLanguage( false );
2088 IMPL_LINK_NOARG(OfaAutoCompleteTabPage, DeleteHdl, weld::Button&, void)
2090 auto rows = m_xLBEntries->get_selected_rows();
2091 std::sort(rows.begin(), rows.end());
2092 while (!rows.empty())
2094 sal_Int32 nPos = rows.back();
2095 OUString* pStr = weld::fromId<OUString*>(m_xLBEntries->get_id(nPos));
2096 m_xLBEntries->remove(nPos);
2097 editeng::IAutoCompleteString hack(*pStr); // UGLY
2098 m_pAutoCompleteList->erase(&hack);
2099 rows.pop_back();
2103 IMPL_LINK(OfaAutoCompleteTabPage, CheckHdl, weld::Toggleable&, rBox, void)
2105 bool bEnable = rBox.get_active();
2106 if (&rBox == m_xCBActiv.get())
2108 m_xCBAppendSpace->set_sensitive(bEnable);
2109 m_xCBAppendSpace->set_sensitive(bEnable);
2110 m_xCBAsTip->set_sensitive(bEnable);
2111 m_xDCBExpandKey->set_sensitive(bEnable);
2113 else if (&rBox == m_xCBCollect.get())
2114 m_xCBRemoveList->set_sensitive(bEnable);
2117 void OfaAutoCompleteTabPage::CopyToClipboard() const
2119 auto rows = m_xLBEntries->get_selected_rows();
2120 if (!m_pAutoCompleteList || rows.empty())
2121 return;
2123 rtl::Reference<TransferDataContainer> pCntnr = new TransferDataContainer;
2125 OStringBuffer sData;
2127 rtl_TextEncoding nEncode = osl_getThreadTextEncoding();
2129 for (auto a : rows)
2131 sData.append(OUStringToOString(m_xLBEntries->get_text(a), nEncode) + SAL_NEWLINE_STRING);
2133 pCntnr->CopyByteString( SotClipboardFormatId::STRING, sData.makeStringAndClear() );
2134 pCntnr->CopyToClipboard(m_xLBEntries->get_clipboard());
2137 IMPL_LINK(OfaAutoCompleteTabPage, KeyReleaseHdl, const KeyEvent&, rEvent, bool)
2139 bool bHandled = false;
2140 const vcl::KeyCode& rKeyCode = rEvent.GetKeyCode();
2141 switch (rKeyCode.GetModifier() | rKeyCode.GetCode())
2143 case KEY_DELETE:
2144 DeleteHdl(*m_xPBEntries);
2145 bHandled = true;
2146 break;
2147 default:
2148 if (KeyFuncType::COPY == rKeyCode.GetFunction())
2150 CopyToClipboard();
2151 bHandled = true;
2153 break;
2155 return bHandled;
2158 // class OfaSmartTagOptionsTabPage ---------------------------------------------
2160 OfaSmartTagOptionsTabPage::OfaSmartTagOptionsTabPage(weld::Container* pPage, weld::DialogController* pController,
2161 const SfxItemSet& rSet )
2162 : SfxTabPage(pPage, pController, "cui/ui/smarttagoptionspage.ui", "SmartTagOptionsPage", &rSet)
2163 , m_xMainCB(m_xBuilder->weld_check_button("main"))
2164 , m_xSmartTagTypesLB(m_xBuilder->weld_tree_view("list"))
2165 , m_xPropertiesPB(m_xBuilder->weld_button("properties"))
2167 m_xSmartTagTypesLB->set_size_request(m_xSmartTagTypesLB->get_approximate_digit_width() * 50,
2168 m_xSmartTagTypesLB->get_height_rows(6));
2170 m_xSmartTagTypesLB->enable_toggle_buttons(weld::ColumnToggleType::Check);
2172 // set the handlers:
2173 m_xMainCB->connect_toggled(LINK(this, OfaSmartTagOptionsTabPage, CheckHdl));
2174 m_xPropertiesPB->connect_clicked(LINK(this, OfaSmartTagOptionsTabPage, ClickHdl));
2175 m_xSmartTagTypesLB->connect_changed(LINK(this, OfaSmartTagOptionsTabPage, SelectHdl));
2178 OfaSmartTagOptionsTabPage::~OfaSmartTagOptionsTabPage()
2182 std::unique_ptr<SfxTabPage> OfaSmartTagOptionsTabPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rSet)
2184 return std::make_unique<OfaSmartTagOptionsTabPage>(pPage, pController, *rSet);
2187 namespace {
2189 /** This struct is used to associate list box entries with smart tag data
2191 struct ImplSmartTagLBUserData
2193 OUString maSmartTagType;
2194 uno::Reference< smarttags::XSmartTagRecognizer > mxRec;
2195 sal_Int32 mnSmartTagIdx;
2197 ImplSmartTagLBUserData( OUString aSmartTagType,
2198 uno::Reference< smarttags::XSmartTagRecognizer > xRec,
2199 sal_Int32 nSmartTagIdx ) :
2200 maSmartTagType(std::move( aSmartTagType )),
2201 mxRec(std::move( xRec )),
2202 mnSmartTagIdx( nSmartTagIdx ) {}
2207 /** Clears m_xSmartTagTypesLB
2209 void OfaSmartTagOptionsTabPage::ClearListBox()
2211 const int nCount = m_xSmartTagTypesLB->n_children();
2212 for (int i = 0; i < nCount; ++i)
2214 const ImplSmartTagLBUserData* pUserData = weld::fromId<ImplSmartTagLBUserData*>(m_xSmartTagTypesLB->get_id(i));
2215 delete pUserData;
2218 m_xSmartTagTypesLB->clear();
2221 /** Inserts items into m_xSmartTagTypesLB
2223 void OfaSmartTagOptionsTabPage::FillListBox( const SmartTagMgr& rSmartTagMgr )
2225 // first we have to clear the list box:
2226 ClearListBox();
2228 // fill list box:
2229 const sal_uInt32 nNumberOfRecognizers = rSmartTagMgr.NumberOfRecognizers();
2230 const lang::Locale aLocale( LanguageTag::convertToLocale( eLastDialogLanguage ) );
2232 for ( sal_uInt32 i = 0; i < nNumberOfRecognizers; ++i )
2234 const uno::Reference< smarttags::XSmartTagRecognizer >& xRec = rSmartTagMgr.GetRecognizer(i);
2236 const OUString aName = xRec->getName( aLocale );
2237 const sal_Int32 nNumberOfSupportedSmartTags = xRec->getSmartTagCount();
2239 for ( sal_Int32 j = 0; j < nNumberOfSupportedSmartTags; ++j )
2241 const OUString aSmartTagType = xRec->getSmartTagName(j);
2242 OUString aSmartTagCaption = rSmartTagMgr.GetSmartTagCaption( aSmartTagType, aLocale );
2244 if ( aSmartTagCaption.isEmpty() )
2245 aSmartTagCaption = aSmartTagType;
2247 const OUString aLBEntry = aSmartTagCaption + " (" + aName + ")";
2249 m_xSmartTagTypesLB->append();
2250 const int nRow = m_xSmartTagTypesLB->n_children() - 1;
2251 const bool bCheck = rSmartTagMgr.IsSmartTagTypeEnabled( aSmartTagType );
2252 m_xSmartTagTypesLB->set_toggle(nRow, bCheck ? TRISTATE_TRUE : TRISTATE_FALSE);
2253 m_xSmartTagTypesLB->set_text(nRow, aLBEntry, 0);
2254 m_xSmartTagTypesLB->set_id(nRow, weld::toId(new ImplSmartTagLBUserData(aSmartTagType, xRec, j)));
2259 /** Handler for the push button
2261 IMPL_LINK_NOARG(OfaSmartTagOptionsTabPage, ClickHdl, weld::Button&, void)
2263 const int nPos = m_xSmartTagTypesLB->get_selected_index();
2264 const ImplSmartTagLBUserData* pUserData = weld::fromId<ImplSmartTagLBUserData*>(m_xSmartTagTypesLB->get_id(nPos));
2265 uno::Reference< smarttags::XSmartTagRecognizer > xRec = pUserData->mxRec;
2266 const sal_Int32 nSmartTagIdx = pUserData->mnSmartTagIdx;
2268 const lang::Locale aLocale( LanguageTag::convertToLocale( eLastDialogLanguage ) );
2269 if ( xRec->hasPropertyPage( nSmartTagIdx, aLocale ) )
2270 xRec->displayPropertyPage( nSmartTagIdx, aLocale );
2273 /** Handler for the check box
2275 IMPL_LINK_NOARG(OfaSmartTagOptionsTabPage, CheckHdl, weld::Toggleable&, void)
2277 const bool bEnable = m_xMainCB->get_active();
2278 m_xSmartTagTypesLB->set_sensitive(bEnable);
2279 m_xPropertiesPB->set_sensitive(false);
2281 // if the controls are currently enabled, we still have to check
2282 // if the properties button should be disabled because the currently
2283 // selected smart tag type does not have a properties dialog.
2284 // We do this by calling SelectHdl:
2285 if (bEnable)
2286 SelectHdl(*m_xSmartTagTypesLB);
2289 /** Handler for the list box
2291 IMPL_LINK_NOARG(OfaSmartTagOptionsTabPage, SelectHdl, weld::TreeView&, void)
2293 const int nPos = m_xSmartTagTypesLB->get_selected_index();
2294 if (nPos == -1)
2295 return;
2296 const ImplSmartTagLBUserData* pUserData = weld::fromId<ImplSmartTagLBUserData*>(m_xSmartTagTypesLB->get_id(nPos));
2297 uno::Reference< smarttags::XSmartTagRecognizer > xRec = pUserData->mxRec;
2298 const sal_Int32 nSmartTagIdx = pUserData->mnSmartTagIdx;
2300 const lang::Locale aLocale( LanguageTag::convertToLocale( eLastDialogLanguage ) );
2301 if ( xRec->hasPropertyPage( nSmartTagIdx, aLocale ) )
2302 m_xPropertiesPB->set_sensitive(true);
2303 else
2304 m_xPropertiesPB->set_sensitive(false);
2307 /** Propagates the current settings to the smart tag manager.
2309 bool OfaSmartTagOptionsTabPage::FillItemSet( SfxItemSet* )
2311 SvxAutoCorrect* pAutoCorrect = SvxAutoCorrCfg::Get().GetAutoCorrect();
2312 SvxSwAutoFormatFlags *pOpt = &pAutoCorrect->GetSwFlags();
2313 SmartTagMgr* pSmartTagMgr = pOpt->pSmartTagMgr;
2315 // robust!
2316 if ( !pSmartTagMgr )
2317 return false;
2319 bool bModifiedSmartTagTypes = false;
2320 std::vector< OUString > aDisabledSmartTagTypes;
2322 const int nCount = m_xSmartTagTypesLB->n_children();
2324 for (int i = 0; i < nCount; ++i)
2326 const ImplSmartTagLBUserData* pUserData = weld::fromId<ImplSmartTagLBUserData*>(m_xSmartTagTypesLB->get_id(i));
2327 const bool bChecked = m_xSmartTagTypesLB->get_toggle(i) == TRISTATE_TRUE;
2328 const bool bIsCurrentlyEnabled = pSmartTagMgr->IsSmartTagTypeEnabled( pUserData->maSmartTagType );
2330 bModifiedSmartTagTypes = bModifiedSmartTagTypes || ( !bChecked != !bIsCurrentlyEnabled );
2332 if ( !bChecked )
2333 aDisabledSmartTagTypes.push_back( pUserData->maSmartTagType );
2335 delete pUserData;
2338 const bool bModifiedRecognize = ( !m_xMainCB->get_active() != !pSmartTagMgr->IsLabelTextWithSmartTags() );
2339 if ( bModifiedSmartTagTypes || bModifiedRecognize )
2341 bool bLabelTextWithSmartTags = m_xMainCB->get_active();
2342 pSmartTagMgr->WriteConfiguration( bModifiedRecognize ? &bLabelTextWithSmartTags : nullptr,
2343 bModifiedSmartTagTypes ? &aDisabledSmartTagTypes : nullptr );
2346 return true;
2349 /** Sets the controls based on the current settings at SmartTagMgr.
2351 void OfaSmartTagOptionsTabPage::Reset( const SfxItemSet* )
2353 SvxAutoCorrect* pAutoCorrect = SvxAutoCorrCfg::Get().GetAutoCorrect();
2354 SvxSwAutoFormatFlags *pOpt = &pAutoCorrect->GetSwFlags();
2355 const SmartTagMgr* pSmartTagMgr = pOpt->pSmartTagMgr;
2357 // robust, should not happen!
2358 if ( !pSmartTagMgr )
2359 return;
2361 FillListBox(*pSmartTagMgr);
2362 m_xSmartTagTypesLB->select(0);
2363 m_xMainCB->set_active(pSmartTagMgr->IsLabelTextWithSmartTags());
2364 CheckHdl(*m_xMainCB);
2367 void OfaSmartTagOptionsTabPage::ActivatePage( const SfxItemSet& )
2369 static_cast<OfaAutoCorrDlg*>(GetDialogController())->EnableLanguage( false );
2372 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */