LCOV - code coverage report
Current view: top level - cui/source/tabpages - autocdlg.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 1574 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 140 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.11