LCOV - code coverage report
Current view: top level - sw/source/ui/index - cnttab.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 2267 0.0 %
Date: 2014-04-11 Functions: 0 209 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 <config_folders.h>
      21             : 
      22             : #include <comphelper/string.hxx>
      23             : #include <rsc/rscsfx.hxx>
      24             : #include <vcl/msgbox.hxx>
      25             : #include <vcl/help.hxx>
      26             : #include <svl/stritem.hxx>
      27             : #include <svl/urihelper.hxx>
      28             : #include <unotools/pathoptions.hxx>
      29             : #include <sfx2/request.hxx>
      30             : #include <sfx2/viewfrm.hxx>
      31             : #include <sfx2/dispatch.hxx>
      32             : #include <sfx2/docfile.hxx>
      33             : #include <svtools/simptabl.hxx>
      34             : #include <svtools/treelistentry.hxx>
      35             : #include <svx/dialogs.hrc>
      36             : #include <svx/svxdlg.hxx>
      37             : #include <svx/flagsdef.hxx>
      38             : #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
      39             : #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
      40             : #include <com/sun/star/ui/dialogs/XFilterManager.hpp>
      41             : #include <svtools/indexentryres.hxx>
      42             : #include <editeng/unolingu.hxx>
      43             : #include <column.hxx>
      44             : #include <fmtfsize.hxx>
      45             : #include <shellio.hxx>
      46             : #include <authfld.hxx>
      47             : #include <swtypes.hxx>
      48             : #include <wrtsh.hxx>
      49             : #include <view.hxx>
      50             : #include <basesh.hxx>
      51             : #include <outline.hxx>
      52             : #include <cnttab.hxx>
      53             : #include <swuicnttab.hxx>
      54             : #include <formedt.hxx>
      55             : #include <poolfmt.hxx>
      56             : #include <poolfmt.hrc>
      57             : #include <uitool.hxx>
      58             : #include <fmtcol.hxx>
      59             : #include <fldbas.hxx>
      60             : #include <expfld.hxx>
      61             : #include <unotools.hxx>
      62             : #include <unotxdoc.hxx>
      63             : #include <docsh.hxx>
      64             : #include <swmodule.hxx>
      65             : #include <modcfg.hxx>
      66             : 
      67             : #include <cmdid.h>
      68             : #include <helpid.h>
      69             : #include <utlui.hrc>
      70             : #include <index.hrc>
      71             : #include <globals.hrc>
      72             : #include <SwStyleNameMapper.hxx>
      73             : #include <sfx2/filedlghelper.hxx>
      74             : #include <toxwrap.hxx>
      75             : #include <chpfld.hxx>
      76             : 
      77             : #include <sfx2/app.hxx>
      78             : 
      79             : #include <unomid.h>
      80             : using namespace ::com::sun::star;
      81             : using namespace ::com::sun::star::lang;
      82             : using namespace ::com::sun::star::uno;
      83             : using namespace com::sun::star::ui::dialogs;
      84             : using namespace ::sfx2;
      85             : #include <svtools/editbrowsebox.hxx>
      86             : 
      87             : static const sal_Unicode aDeliStart = '['; // for the form
      88             : static const sal_Unicode aDeliEnd    = ']'; // for the form
      89             : 
      90           0 : static OUString lcl_CreateAutoMarkFileDlg( const OUString& rURL,
      91             :                                 const OUString& rFileString, bool bOpen )
      92             : {
      93           0 :     OUString sRet;
      94             : 
      95             :     FileDialogHelper aDlgHelper( bOpen ?
      96           0 :                 TemplateDescription::FILEOPEN_SIMPLE : TemplateDescription::FILESAVE_AUTOEXTENSION, 0 );
      97           0 :     uno::Reference < XFilePicker > xFP = aDlgHelper.GetFilePicker();
      98             : 
      99           0 :     uno::Reference<XFilterManager> xFltMgr(xFP, UNO_QUERY);
     100           0 :     xFltMgr->appendFilter( rFileString, "*.sdi" );
     101           0 :     xFltMgr->setCurrentFilter( rFileString ) ;
     102             : 
     103           0 :     OUString& rLastSaveDir = (OUString&)SFX_APP()->GetLastSaveDirectory();
     104           0 :     OUString sSaveDir = rLastSaveDir;
     105             : 
     106           0 :     if( !rURL.isEmpty() )
     107           0 :         xFP->setDisplayDirectory( rURL );
     108             :     else
     109             :     {
     110           0 :         SvtPathOptions aPathOpt;
     111           0 :         xFP->setDisplayDirectory( aPathOpt.GetUserConfigPath() );
     112             :     }
     113             : 
     114           0 :     if( aDlgHelper.Execute() == ERRCODE_NONE )
     115             :     {
     116           0 :         sRet = xFP->getFiles().getConstArray()[0];
     117             :     }
     118           0 :     rLastSaveDir = sSaveDir;
     119           0 :     return sRet;
     120             : }
     121             : 
     122           0 : struct AutoMarkEntry
     123             : {
     124             :     OUString sSearch;
     125             :     OUString sAlternative;
     126             :     OUString sPrimKey;
     127             :     OUString sSecKey;
     128             :     OUString sComment;
     129             :     sal_Bool    bCase;
     130             :     sal_Bool    bWord;
     131             : 
     132           0 :     AutoMarkEntry() :
     133             :         bCase(sal_False),
     134           0 :         bWord(sal_False){}
     135             : };
     136             : typedef boost::ptr_vector<AutoMarkEntry> AutoMarkEntryArr;
     137             : 
     138             : typedef ::svt::EditBrowseBox SwEntryBrowseBox_Base;
     139             : 
     140           0 : class SwEntryBrowseBox : public SwEntryBrowseBox_Base
     141             : {
     142             :     Edit                    aCellEdit;
     143             :     ::svt::CheckBoxControl  aCellCheckBox;
     144             : 
     145             :     OUString  sSearch;
     146             :     OUString  sAlternative;
     147             :     OUString  sPrimKey;
     148             :     OUString  sSecKey;
     149             :     OUString  sComment;
     150             :     OUString  sCaseSensitive;
     151             :     OUString  sWordOnly;
     152             :     OUString  sYes;
     153             :     OUString  sNo;
     154             : 
     155             :     AutoMarkEntryArr    aEntryArr;
     156             : 
     157             :     ::svt::CellControllerRef    xController;
     158             :     ::svt::CellControllerRef    xCheckController;
     159             : 
     160             :     long    nCurrentRow;
     161             :     bool    bModified;
     162             : 
     163           0 :     void                            SetModified() {bModified = true;}
     164             : 
     165             : protected:
     166             :     virtual bool                    SeekRow( long nRow ) SAL_OVERRIDE;
     167             :     virtual void                    PaintCell(OutputDevice& rDev, const Rectangle& rRect, sal_uInt16 nColId) const SAL_OVERRIDE;
     168             :     virtual void                    InitController(::svt::CellControllerRef& rController, long nRow, sal_uInt16 nCol) SAL_OVERRIDE;
     169             :     virtual ::svt::CellController*  GetController(long nRow, sal_uInt16 nCol) SAL_OVERRIDE;
     170             :     virtual bool                    SaveModified() SAL_OVERRIDE;
     171             : 
     172             :     std::vector<long>               GetOptimalColWidths() const;
     173             : 
     174             : public:
     175             :     SwEntryBrowseBox(Window* pParent, VclBuilderContainer* pBuilder);
     176             :     void                            ReadEntries(SvStream& rInStr);
     177             :     void                            WriteEntries(SvStream& rOutStr);
     178             : 
     179             :     bool                            IsModified()const SAL_OVERRIDE;
     180             : 
     181             :     virtual OUString GetCellText( long nRow, sal_uInt16 nColumn ) const SAL_OVERRIDE;
     182             :     virtual void                    Resize() SAL_OVERRIDE;
     183             :     virtual Size                    GetOptimalSize() const SAL_OVERRIDE;
     184             : };
     185             : 
     186             : class SwAutoMarkDlg_Impl : public ModalDialog
     187             : {
     188             :     OKButton*           m_pOKPB;
     189             : 
     190             :     SwEntryBrowseBox*   m_pEntriesBB;
     191             : 
     192             :     OUString            sAutoMarkURL;
     193             :     const OUString      sAutoMarkType;
     194             : 
     195             :     bool                bCreateMode;
     196             : 
     197             :     DECL_LINK(OkHdl, void *);
     198             : public:
     199             :     SwAutoMarkDlg_Impl(Window* pParent, const OUString& rAutoMarkURL,
     200             :                         const OUString& rAutoMarkType, bool bCreate);
     201             :     virtual ~SwAutoMarkDlg_Impl();
     202             : 
     203             : };
     204             : 
     205           0 : sal_uInt16 CurTOXType::GetFlatIndex() const
     206             : {
     207           0 :     return static_cast< sal_uInt16 >( (eType == TOX_USER && nIndex)
     208           0 :         ? eType : TOX_AUTHORITIES + nIndex );
     209             : }
     210             : 
     211             : #define EDIT_MINWIDTH 15
     212             : 
     213           0 : SwMultiTOXTabDialog::SwMultiTOXTabDialog(Window* pParent, const SfxItemSet& rSet,
     214             :                     SwWrtShell &rShell,
     215             :                     SwTOXBase* pCurTOX,
     216             :                     sal_uInt16 nToxType, sal_Bool bGlobal)
     217             :     : SfxTabDialog(pParent, "TocDialog",
     218             :         "modules/swriter/ui/tocdialog.ui", &rSet)
     219           0 :     , pMgr( new SwTOXMgr( &rShell ) )
     220             :     , rSh(rShell)
     221             :     , pExampleFrame(0)
     222             :     , pParamTOXBase(pCurTOX)
     223             :     , sUserDefinedIndex(SW_RESSTR(STR_USER_DEFINED_INDEX))
     224             :     , nInitialTOXType(nToxType)
     225             :     , bEditTOX(false)
     226             :     , bExampleCreated(false)
     227           0 :     , bGlobalFlag(bGlobal)
     228             : {
     229           0 :     get(m_pShowExampleCB, "showexample");
     230           0 :     get(m_pExampleContainerWIN, "example");
     231           0 :     Size aWinSize(LogicToPixel(Size(150, 188), MapMode(MAP_APPFONT)));
     232           0 :     m_pExampleContainerWIN->set_width_request(aWinSize.Width());
     233           0 :     m_pExampleContainerWIN->set_height_request(aWinSize.Height());
     234           0 :     m_pExampleContainerWIN->SetSizePixel(aWinSize);
     235             : 
     236           0 :     eCurrentTOXType.eType = TOX_CONTENT;
     237           0 :     eCurrentTOXType.nIndex = 0;
     238             : 
     239           0 :     const sal_uInt16 nUserTypeCount = rSh.GetTOXTypeCount(TOX_USER);
     240           0 :     nTypeCount = nUserTypeCount + 6;
     241           0 :     pFormArr = new SwForm*[nTypeCount];
     242           0 :     pDescArr = new SwTOXDescription*[nTypeCount];
     243           0 :     pxIndexSectionsArr = new SwIndexSections_Impl*[nTypeCount];
     244             :     //the standard user index is on position TOX_USER
     245             :     //all user user indexes follow after position TOX_AUTHORITIES
     246           0 :     if(pCurTOX)
     247             :     {
     248           0 :         bEditTOX = sal_True;
     249             :     }
     250           0 :     for(int i = nTypeCount - 1; i > -1; i--)
     251             :     {
     252           0 :         pFormArr[i] = 0;
     253           0 :         pDescArr[i] = 0;
     254           0 :         pxIndexSectionsArr[i] = new SwIndexSections_Impl;
     255           0 :         if(pCurTOX)
     256             :         {
     257           0 :             eCurrentTOXType.eType = pCurTOX->GetType();
     258           0 :             sal_uInt16 nArrayIndex = static_cast< sal_uInt16 >(eCurrentTOXType.eType);
     259           0 :             if(eCurrentTOXType.eType == TOX_USER)
     260             :             {
     261             :                 //which user type is it?
     262           0 :                 for(sal_uInt16 nUser = 0; nUser < nUserTypeCount; nUser++)
     263             :                 {
     264           0 :                     const SwTOXType* pTemp = rSh.GetTOXType(TOX_USER, nUser);
     265           0 :                     if(pCurTOX->GetTOXType() == pTemp)
     266             :                     {
     267           0 :                         eCurrentTOXType.nIndex = nUser;
     268           0 :                         nArrayIndex = static_cast< sal_uInt16 >(nUser > 0 ? TOX_AUTHORITIES + nUser : TOX_USER);
     269           0 :                         break;
     270             :                     }
     271             :                 }
     272             :             }
     273           0 :             pFormArr[nArrayIndex] = new SwForm(pCurTOX->GetTOXForm());
     274           0 :             pDescArr[nArrayIndex] = CreateTOXDescFromTOXBase(pCurTOX);
     275           0 :             if(TOX_AUTHORITIES == eCurrentTOXType.eType)
     276             :             {
     277             :                 const SwAuthorityFieldType* pFType = (const SwAuthorityFieldType*)
     278           0 :                                                 rSh.GetFldType(RES_AUTHORITY, aEmptyOUStr);
     279           0 :                 if(pFType)
     280             :                 {
     281           0 :                     OUString sBrackets;
     282           0 :                     if(pFType->GetPrefix())
     283           0 :                         sBrackets += OUString(pFType->GetPrefix());
     284           0 :                     if(pFType->GetSuffix())
     285           0 :                         sBrackets += OUString(pFType->GetSuffix());
     286           0 :                     pDescArr[nArrayIndex]->SetAuthBrackets(sBrackets);
     287           0 :                     pDescArr[nArrayIndex]->SetAuthSequence(pFType->IsSequence());
     288             :                 }
     289             :                 else
     290             :                 {
     291           0 :                     pDescArr[nArrayIndex]->SetAuthBrackets("[]");
     292             :                 }
     293             :             }
     294             :         }
     295             :     }
     296           0 :     SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
     297             :     OSL_ENSURE(pFact, "Dialogdiet fail!");
     298           0 :     m_nSelectId = AddTabPage("index", SwTOXSelectTabPage::Create, 0);
     299           0 :     m_nStylesId = AddTabPage("styles", SwTOXStylesTabPage::Create, 0);
     300           0 :     m_nColumnId = AddTabPage("columns", SwColumnPage::Create, 0);
     301           0 :     m_nBackGroundId = AddTabPage("background", pFact->GetTabPageCreatorFunc( RID_SVXPAGE_BACKGROUND ), 0);
     302           0 :     m_nEntriesId = AddTabPage("entries", SwTOXEntryTabPage::Create, 0);
     303           0 :     if(!pCurTOX)
     304           0 :         SetCurPageId(m_nSelectId);
     305             : 
     306           0 :     m_pShowExampleCB->SetClickHdl(LINK(this, SwMultiTOXTabDialog, ShowPreviewHdl));
     307             : 
     308           0 :     m_pShowExampleCB->Check( SW_MOD()->GetModuleConfig()->IsShowIndexPreview());
     309             : 
     310           0 :     m_pExampleContainerWIN->SetAccessibleName(m_pShowExampleCB->GetText());
     311           0 :     SetViewAlign( WINDOWALIGN_LEFT );
     312             :     // SetViewWindow does not work if the dialog is visible!
     313             : 
     314           0 :     if(!m_pShowExampleCB->IsChecked())
     315           0 :         SetViewWindow(m_pExampleContainerWIN);
     316             : 
     317           0 :     ShowPreviewHdl(0);
     318           0 : }
     319             : 
     320           0 : SwMultiTOXTabDialog::~SwMultiTOXTabDialog()
     321             : {
     322           0 :     SW_MOD()->GetModuleConfig()->SetShowIndexPreview(m_pShowExampleCB->IsChecked());
     323             : 
     324             :     // fdo#38515 Avoid setting focus on deleted controls in the destructors
     325           0 :     EnableInput( false );
     326             : 
     327           0 :     for(sal_uInt16 i = 0; i < nTypeCount; i++)
     328             :     {
     329           0 :         delete pFormArr[i];
     330           0 :         delete pDescArr[i];
     331           0 :         delete pxIndexSectionsArr[i];
     332             :     }
     333           0 :     delete[] pxIndexSectionsArr;
     334             : 
     335           0 :     delete[] pFormArr;
     336           0 :     delete[] pDescArr;
     337           0 :     delete pMgr;
     338           0 :     delete pExampleFrame;
     339           0 : }
     340             : 
     341           0 : void SwMultiTOXTabDialog::PageCreated( sal_uInt16 nId, SfxTabPage &rPage )
     342             : {
     343           0 :     if (nId == m_nBackGroundId)
     344             :     {
     345           0 :         SfxAllItemSet aSet(*(GetInputSetImpl()->GetPool()));
     346           0 :         aSet.Put (SfxUInt32Item(SID_FLAG_TYPE, SVX_SHOW_SELECTOR));
     347           0 :         rPage.PageCreated(aSet);
     348             :     }
     349           0 :     else if(nId == m_nColumnId)
     350             :     {
     351           0 :         const SwFmtFrmSize& rSize = (const SwFmtFrmSize&)GetInputSetImpl()->Get(RES_FRM_SIZE);
     352             : 
     353           0 :         ((SwColumnPage&)rPage).SetPageWidth(rSize.GetWidth());
     354             :     }
     355           0 :     else if (nId == m_nEntriesId)
     356           0 :         ((SwTOXEntryTabPage&)rPage).SetWrtShell(rSh);
     357           0 :     else if (nId == m_nSelectId)
     358             :     {
     359           0 :         ((SwTOXSelectTabPage&)rPage).SetWrtShell(rSh);
     360           0 :         if(USHRT_MAX != nInitialTOXType)
     361           0 :             ((SwTOXSelectTabPage&)rPage).SelectType((TOXTypes)nInitialTOXType);
     362             :     }
     363           0 : }
     364             : 
     365           0 : short SwMultiTOXTabDialog::Ok()
     366             : {
     367           0 :     short nRet = SfxTabDialog::Ok();
     368           0 :     SwTOXDescription& rDesc = GetTOXDescription(eCurrentTOXType);
     369           0 :     SwTOXBase aNewDef(*rSh.GetDefaultTOXBase( eCurrentTOXType.eType, true ));
     370             : 
     371             :     const sal_uInt16 nIndex = static_cast< sal_uInt16 >(
     372           0 :         eCurrentTOXType.eType == TOX_USER && eCurrentTOXType.nIndex
     373             :         ? eCurrentTOXType.eType
     374           0 :         : TOX_AUTHORITIES + eCurrentTOXType.nIndex );
     375             : 
     376           0 :     if(pFormArr[nIndex])
     377             :     {
     378           0 :         rDesc.SetForm(*pFormArr[nIndex]);
     379           0 :         aNewDef.SetTOXForm(*pFormArr[nIndex]);
     380             :     }
     381           0 :     rDesc.ApplyTo(aNewDef);
     382           0 :     if(!bGlobalFlag)
     383             :         pMgr->UpdateOrInsertTOX(
     384           0 :                 rDesc, 0, GetOutputItemSet());
     385           0 :     else if(bEditTOX)
     386             :         pMgr->UpdateOrInsertTOX(
     387           0 :                 rDesc, &pParamTOXBase, GetOutputItemSet());
     388             : 
     389           0 :     if(!eCurrentTOXType.nIndex)
     390           0 :         rSh.SetDefaultTOXBase(aNewDef);
     391             : 
     392           0 :     return nRet;
     393             : }
     394             : 
     395           0 : SwForm* SwMultiTOXTabDialog::GetForm(CurTOXType eType)
     396             : {
     397           0 :     const sal_uInt16 nIndex = eType.GetFlatIndex();
     398           0 :     if(!pFormArr[nIndex])
     399           0 :         pFormArr[nIndex] = new SwForm(eType.eType);
     400           0 :     return pFormArr[nIndex];
     401             : }
     402             : 
     403           0 : SwTOXDescription& SwMultiTOXTabDialog::GetTOXDescription(CurTOXType eType)
     404             : {
     405           0 :     const sal_uInt16 nIndex = eType.GetFlatIndex();
     406           0 :     if(!pDescArr[nIndex])
     407             :     {
     408           0 :         const SwTOXBase* pDef = rSh.GetDefaultTOXBase( eType.eType );
     409           0 :         if(pDef)
     410           0 :             pDescArr[nIndex] = CreateTOXDescFromTOXBase(pDef);
     411             :         else
     412             :         {
     413           0 :             pDescArr[nIndex] = new SwTOXDescription(eType.eType);
     414           0 :             if(eType.eType == TOX_USER)
     415           0 :                 pDescArr[nIndex]->SetTitle(sUserDefinedIndex);
     416             :             else
     417           0 :                 pDescArr[nIndex]->SetTitle(
     418           0 :                     rSh.GetTOXType(eType.eType, 0)->GetTypeName());
     419             :         }
     420           0 :         if(TOX_AUTHORITIES == eType.eType)
     421             :         {
     422             :             const SwAuthorityFieldType* pFType = (const SwAuthorityFieldType*)
     423           0 :                                             rSh.GetFldType(RES_AUTHORITY, aEmptyOUStr);
     424           0 :             if(pFType)
     425             :             {
     426           0 :                 pDescArr[nIndex]->SetAuthBrackets(OUString(pFType->GetPrefix()) +
     427           0 :                                                   OUString(pFType->GetSuffix()));
     428           0 :                 pDescArr[nIndex]->SetAuthSequence(pFType->IsSequence());
     429             :             }
     430             :             else
     431             :             {
     432           0 :                 pDescArr[nIndex]->SetAuthBrackets("[]");
     433             :             }
     434             :         }
     435           0 :         else if(TOX_INDEX == eType.eType)
     436           0 :             pDescArr[nIndex]->SetMainEntryCharStyle(SW_RESSTR(STR_POOLCHR_IDX_MAIN_ENTRY));
     437             : 
     438             :     }
     439           0 :     return *pDescArr[nIndex];
     440             : }
     441             : 
     442           0 : SwTOXDescription* SwMultiTOXTabDialog::CreateTOXDescFromTOXBase(
     443             :             const SwTOXBase*pCurTOX)
     444             : {
     445           0 :     SwTOXDescription * pDesc = new SwTOXDescription(pCurTOX->GetType());
     446           0 :     for(sal_uInt16 i = 0; i < MAXLEVEL; i++)
     447           0 :         pDesc->SetStyleNames(pCurTOX->GetStyleNames(i), i);
     448           0 :     pDesc->SetAutoMarkURL(rSh.GetTOIAutoMarkURL());
     449           0 :     pDesc->SetTitle(pCurTOX->GetTitle());
     450             : 
     451           0 :     pDesc->SetContentOptions(pCurTOX->GetCreateType());
     452           0 :     if(pDesc->GetTOXType() == TOX_INDEX)
     453           0 :         pDesc->SetIndexOptions(pCurTOX->GetOptions());
     454           0 :     pDesc->SetMainEntryCharStyle(pCurTOX->GetMainEntryCharStyle());
     455           0 :     if(pDesc->GetTOXType() != TOX_INDEX)
     456           0 :         pDesc->SetLevel((sal_uInt8)pCurTOX->GetLevel());
     457           0 :     pDesc->SetCreateFromObjectNames(pCurTOX->IsFromObjectNames());
     458           0 :     pDesc->SetSequenceName(pCurTOX->GetSequenceName());
     459           0 :     pDesc->SetCaptionDisplay(pCurTOX->GetCaptionDisplay());
     460           0 :     pDesc->SetFromChapter(pCurTOX->IsFromChapter());
     461           0 :     pDesc->SetReadonly(pCurTOX->IsProtected());
     462           0 :     pDesc->SetOLEOptions(pCurTOX->GetOLEOptions());
     463           0 :     pDesc->SetLevelFromChapter(pCurTOX->IsLevelFromChapter());
     464           0 :     pDesc->SetLanguage(pCurTOX->GetLanguage());
     465           0 :     pDesc->SetSortAlgorithm(pCurTOX->GetSortAlgorithm());
     466           0 :     return pDesc;
     467             : }
     468             : 
     469           0 : IMPL_LINK_NOARG( SwMultiTOXTabDialog, ShowPreviewHdl )
     470             : {
     471           0 :     if(m_pShowExampleCB->IsChecked())
     472             :     {
     473           0 :         if(!pExampleFrame && !bExampleCreated)
     474             :         {
     475           0 :             bExampleCreated = sal_True;
     476           0 :             OUString sTemplate("internal/idxexample.odt");
     477             : 
     478           0 :             SvtPathOptions aOpt;
     479           0 :             bool bExist = aOpt.SearchFile( sTemplate, SvtPathOptions::PATH_TEMPLATE );
     480             : 
     481           0 :             if(!bExist)
     482             :             {
     483           0 :                 OUString sInfo(SW_RESSTR(STR_FILE_NOT_FOUND));
     484           0 :                 sInfo = sInfo.replaceFirst( "%1", sTemplate );
     485           0 :                 sInfo = sInfo.replaceFirst( "%2", aOpt.GetTemplatePath() );
     486           0 :                 InfoBox aInfo(GetParent(), sInfo);
     487           0 :                 aInfo.Execute();
     488             :             }
     489             :             else
     490             :             {
     491           0 :                 Link aLink(LINK(this, SwMultiTOXTabDialog, CreateExample_Hdl));
     492             :                 pExampleFrame = new SwOneExampleFrame(
     493           0 :                         *m_pExampleContainerWIN, EX_SHOW_ONLINE_LAYOUT, &aLink, &sTemplate);
     494             : 
     495           0 :                 if(!pExampleFrame->IsServiceAvailable())
     496             :                 {
     497           0 :                     pExampleFrame->CreateErrorMessage(0);
     498             :                 }
     499             :             }
     500           0 :             m_pShowExampleCB->Show(pExampleFrame && pExampleFrame->IsServiceAvailable());
     501             :         }
     502             :     }
     503           0 :     sal_Bool bSetViewWindow = m_pShowExampleCB->IsChecked()
     504           0 :         && pExampleFrame && pExampleFrame->IsServiceAvailable();
     505             : 
     506           0 :     m_pExampleContainerWIN->Show( bSetViewWindow );
     507           0 :     SetViewWindow( bSetViewWindow ? m_pExampleContainerWIN : 0 );
     508             : 
     509           0 :     setOptimalLayoutSize();
     510             : 
     511           0 :     return 0;
     512             : }
     513             : 
     514           0 : sal_Bool SwMultiTOXTabDialog::IsNoNum(SwWrtShell& rSh, const OUString& rName)
     515             : {
     516           0 :     SwTxtFmtColl* pColl = rSh.GetParaStyle(rName);
     517           0 :     if(pColl && ! pColl->IsAssignedToListLevelOfOutlineStyle())
     518           0 :         return sal_True;
     519             : 
     520             :     const sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName(
     521           0 :         rName, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL);
     522           0 :     if(nId != USHRT_MAX &&
     523           0 :         ! rSh.GetTxtCollFromPool(nId)->IsAssignedToListLevelOfOutlineStyle())
     524           0 :         return sal_True;
     525             : 
     526           0 :     return sal_False;
     527             : }
     528             : 
     529           0 : class SwIndexTreeLB : public SvSimpleTable
     530             : {
     531             : public:
     532             :     SwIndexTreeLB(SvSimpleTableContainer& rParent, WinBits nBits = 0);
     533             :     virtual void KeyInput( const KeyEvent& rKEvt ) SAL_OVERRIDE;
     534             :     virtual void Resize() SAL_OVERRIDE;
     535             :     virtual sal_IntPtr GetTabPos( SvTreeListEntry*, SvLBoxTab* ) SAL_OVERRIDE;
     536             :     void setColSizes();
     537             : };
     538             : 
     539           0 : SwIndexTreeLB::SwIndexTreeLB(SvSimpleTableContainer& rParent, WinBits nBits)
     540           0 :     : SvSimpleTable(rParent, nBits)
     541             : {
     542           0 :     HeaderBar& rStylesHB = GetTheHeaderBar();
     543           0 :     rStylesHB.SetStyle(rStylesHB.GetStyle()|WB_BUTTONSTYLE);
     544           0 :     SetStyle(GetStyle() & ~(WB_AUTOHSCROLL|WB_HSCROLL));
     545           0 : }
     546             : 
     547           0 : sal_IntPtr SwIndexTreeLB::GetTabPos( SvTreeListEntry* pEntry, SvLBoxTab* pTab)
     548             : {
     549           0 :     sal_IntPtr nData = (sal_IntPtr)pEntry->GetUserData();
     550           0 :     if(nData != USHRT_MAX)
     551             :     {
     552           0 :         HeaderBar& rStylesHB = GetTheHeaderBar();
     553           0 :         sal_IntPtr  nPos = rStylesHB.GetItemRect( static_cast< sal_uInt16 >(2 + nData) ).TopLeft().X();
     554           0 :         nData = nPos;
     555             :     }
     556             :     else
     557           0 :         nData = 0;
     558           0 :     nData += pTab->GetPos();
     559           0 :     return nData;
     560             : }
     561             : 
     562           0 : void SwIndexTreeLB::KeyInput( const KeyEvent& rKEvt )
     563             : {
     564           0 :     SvTreeListEntry* pEntry = FirstSelected();
     565           0 :     KeyCode aCode = rKEvt.GetKeyCode();
     566           0 :     sal_Bool bChanged = sal_False;
     567           0 :     if(pEntry)
     568             :     {
     569           0 :         sal_IntPtr nLevel = (sal_IntPtr)pEntry->GetUserData();
     570           0 :         if(aCode.GetCode() == KEY_ADD )
     571             :         {
     572           0 :             if(nLevel < MAXLEVEL - 1)
     573           0 :                 nLevel++;
     574           0 :             else if(nLevel == USHRT_MAX)
     575           0 :                 nLevel = 0;
     576           0 :             bChanged = sal_True;
     577             :         }
     578           0 :         else if(aCode.GetCode() == KEY_SUBTRACT)
     579             :         {
     580           0 :             if(!nLevel)
     581           0 :                 nLevel = USHRT_MAX;
     582           0 :             else if(nLevel != USHRT_MAX)
     583           0 :                 nLevel--;
     584           0 :             bChanged = sal_True;
     585             :         }
     586           0 :         if(bChanged)
     587             :         {
     588           0 :             pEntry->SetUserData((void*)nLevel);
     589           0 :             Invalidate();
     590             :         }
     591             :     }
     592           0 :     if(!bChanged)
     593           0 :         SvTreeListBox::KeyInput(rKEvt);
     594           0 : }
     595             : 
     596           0 : void SwIndexTreeLB::Resize()
     597             : {
     598           0 :     SvSimpleTable::Resize();
     599           0 :     setColSizes();
     600           0 : }
     601             : 
     602           0 : void SwIndexTreeLB::setColSizes()
     603             : {
     604           0 :     HeaderBar &rHB = GetTheHeaderBar();
     605           0 :     if (rHB.GetItemCount() < MAXLEVEL+1)
     606           0 :         return;
     607             : 
     608           0 :     long nWidth = rHB.GetSizePixel().Width();
     609           0 :     nWidth /= 14;
     610           0 :     nWidth--;
     611             : 
     612             :     long nTabs_Impl[MAXLEVEL+2];
     613             : 
     614           0 :     nTabs_Impl[0] = MAXLEVEL+1;
     615           0 :     nTabs_Impl[1] = 3 * nWidth;
     616             : 
     617           0 :     for(sal_uInt16 i = 1; i <= MAXLEVEL; ++i)
     618           0 :         nTabs_Impl[i+1] = nTabs_Impl[i] + nWidth;
     619           0 :     SvSimpleTable::SetTabs(&nTabs_Impl[0], MAP_PIXEL);
     620             : }
     621             : 
     622             : class SwAddStylesDlg_Impl : public SfxModalDialog
     623             : {
     624             :     OKButton*       m_pOk;
     625             : 
     626             :     SwIndexTreeLB*  m_pHeaderTree;
     627             :     PushButton*     m_pLeftPB;
     628             :     PushButton*     m_pRightPB;
     629             : 
     630             :     OUString*       pStyleArr;
     631             : 
     632             :     DECL_LINK(OkHdl, void *);
     633             :     DECL_LINK(LeftRightHdl, PushButton*);
     634             :     DECL_LINK(HeaderDragHdl, void *);
     635             : 
     636             : public:
     637             :     SwAddStylesDlg_Impl(Window* pParent, SwWrtShell& rWrtSh, OUString rStringArr[]);
     638             :     virtual ~SwAddStylesDlg_Impl();
     639             : };
     640             : 
     641           0 : SwAddStylesDlg_Impl::SwAddStylesDlg_Impl(Window* pParent,
     642             :             SwWrtShell& rWrtSh, OUString rStringArr[])
     643             :     : SfxModalDialog(pParent, "AssignStylesDialog",
     644             :         "modules/swriter/ui/assignstylesdialog.ui")
     645           0 :     , pStyleArr(rStringArr)
     646             : {
     647           0 :     get(m_pOk, "ok");
     648           0 :     get(m_pLeftPB, "left");
     649           0 :     get(m_pRightPB, "right");
     650           0 :     OUString sHBFirst = get<FixedText>("notapplied")->GetText();
     651           0 :     SvSimpleTableContainer *pHeaderTreeContainer = get<SvSimpleTableContainer>("styles");
     652           0 :     Size aSize = pHeaderTreeContainer->LogicToPixel(Size(273, 164), MAP_APPFONT);
     653           0 :     pHeaderTreeContainer->set_width_request(aSize.Width());
     654           0 :     pHeaderTreeContainer->set_height_request(aSize.Height());
     655           0 :     m_pHeaderTree = new SwIndexTreeLB(*pHeaderTreeContainer);
     656             : 
     657           0 :     m_pOk->SetClickHdl(LINK(this, SwAddStylesDlg_Impl, OkHdl));
     658           0 :     m_pLeftPB->SetClickHdl(LINK(this, SwAddStylesDlg_Impl, LeftRightHdl));
     659           0 :     m_pRightPB->SetClickHdl(LINK(this, SwAddStylesDlg_Impl, LeftRightHdl));
     660             : 
     661           0 :     HeaderBar& rHB = m_pHeaderTree->GetTheHeaderBar();
     662           0 :     rHB.SetEndDragHdl(LINK(this, SwAddStylesDlg_Impl, HeaderDragHdl));
     663             : 
     664           0 :     for(sal_uInt16 i = 1; i <= MAXLEVEL; ++i)
     665           0 :         sHBFirst += "\t" + OUString::number(i);
     666           0 :     m_pHeaderTree->InsertHeaderEntry(sHBFirst);
     667           0 :     m_pHeaderTree->setColSizes();
     668             : 
     669           0 :     m_pHeaderTree->SetStyle(m_pHeaderTree->GetStyle()|WB_CLIPCHILDREN|WB_SORT);
     670           0 :     m_pHeaderTree->GetModel()->SetSortMode(SortAscending);
     671           0 :     for (sal_uInt16 i = 0; i < MAXLEVEL; ++i)
     672             :     {
     673           0 :         OUString sStyles(rStringArr[i]);
     674           0 :         for(sal_Int32 nToken = 0;
     675           0 :             nToken < comphelper::string::getTokenCount(sStyles, TOX_STYLE_DELIMITER);
     676             :             ++nToken)
     677             :         {
     678           0 :             const OUString sTmp(sStyles.getToken(nToken, TOX_STYLE_DELIMITER));
     679           0 :             SvTreeListEntry* pEntry = m_pHeaderTree->InsertEntry(sTmp);
     680           0 :             pEntry->SetUserData(reinterpret_cast<void*>(i));
     681           0 :         }
     682           0 :     }
     683             :     // now the other styles
     684             : 
     685           0 :     const SwTxtFmtColl *pColl   = 0;
     686           0 :     const sal_uInt16 nSz = rWrtSh.GetTxtFmtCollCount();
     687             : 
     688           0 :     for ( sal_uInt16 j = 0;j < nSz; ++j )
     689             :     {
     690           0 :         pColl = &rWrtSh.GetTxtFmtColl(j);
     691           0 :         if(pColl->IsDefault())
     692           0 :             continue;
     693             : 
     694           0 :         const OUString aName = pColl->GetName();
     695           0 :         if (!aName.isEmpty())
     696             :         {
     697           0 :             SvTreeListEntry* pEntry = m_pHeaderTree->First();
     698           0 :             while (pEntry && m_pHeaderTree->GetEntryText(pEntry, 0) != aName)
     699             :             {
     700           0 :                 pEntry = m_pHeaderTree->Next(pEntry);
     701             :             }
     702           0 :             if (!pEntry)
     703             :             {
     704           0 :                 m_pHeaderTree->InsertEntry(aName)->SetUserData((void*)USHRT_MAX);
     705             :             }
     706             :         }
     707           0 :     }
     708           0 :     m_pHeaderTree->GetModel()->Resort();
     709           0 : }
     710             : 
     711           0 : SwAddStylesDlg_Impl::~SwAddStylesDlg_Impl()
     712             : {
     713           0 :     delete m_pHeaderTree;
     714           0 : }
     715             : 
     716           0 : IMPL_LINK_NOARG(SwAddStylesDlg_Impl, OkHdl)
     717             : {
     718           0 :     for(sal_uInt16 i = 0; i < MAXLEVEL; i++)
     719           0 :         pStyleArr[i] = "";
     720             : 
     721           0 :     SvTreeListEntry* pEntry = m_pHeaderTree->First();
     722           0 :     while(pEntry)
     723             :     {
     724           0 :         sal_IntPtr nLevel = (sal_IntPtr)pEntry->GetUserData();
     725           0 :         if(nLevel != USHRT_MAX)
     726             :         {
     727           0 :             if(!pStyleArr[nLevel].isEmpty())
     728           0 :                 pStyleArr[nLevel] += OUString(TOX_STYLE_DELIMITER);
     729           0 :             pStyleArr[nLevel] += m_pHeaderTree->GetEntryText(pEntry, 0);
     730             :         }
     731           0 :         pEntry = m_pHeaderTree->Next(pEntry);
     732             :     }
     733             : 
     734             :     //TODO write back style names
     735           0 :     EndDialog(RET_OK);
     736           0 :     return 0;
     737             : }
     738             : 
     739           0 : IMPL_LINK_NOARG(SwAddStylesDlg_Impl, HeaderDragHdl)
     740             : {
     741           0 :     m_pHeaderTree->Invalidate();
     742           0 :     return 0;
     743             : }
     744             : 
     745           0 : IMPL_LINK(SwAddStylesDlg_Impl, LeftRightHdl, PushButton*, pBtn)
     746             : {
     747           0 :     sal_Bool bLeft = pBtn == m_pLeftPB;
     748           0 :     SvTreeListEntry* pEntry = m_pHeaderTree->FirstSelected();
     749           0 :     if(pEntry)
     750             :     {
     751           0 :         sal_IntPtr nLevel = (sal_IntPtr)pEntry->GetUserData();
     752           0 :         if(bLeft)
     753             :         {
     754           0 :             if(!nLevel)
     755           0 :                 nLevel = USHRT_MAX;
     756           0 :             else if(nLevel != USHRT_MAX)
     757           0 :                 nLevel--;
     758             :         }
     759             :         else
     760             :         {
     761           0 :             if(nLevel < MAXLEVEL - 1)
     762           0 :                 nLevel++;
     763           0 :             else if(nLevel == USHRT_MAX)
     764           0 :                 nLevel = 0;
     765             :         }
     766           0 :         pEntry->SetUserData((void*)nLevel);
     767           0 :         m_pHeaderTree->Invalidate();
     768             :     }
     769           0 :     return 0;
     770             : }
     771             : 
     772           0 : SwTOXSelectTabPage::SwTOXSelectTabPage(Window* pParent, const SfxItemSet& rAttrSet)
     773             :     : SfxTabPage(pParent, "TocIndexPage",
     774             :         "modules/swriter/ui/tocindexpage.ui", rAttrSet)
     775             :     , aFromNames(SW_RES(RES_SRCTYPES))
     776             :     , pIndexRes(0)
     777             :     , sAutoMarkType(SW_RESSTR(STR_AUTOMARK_TYPE))
     778           0 :     , m_bWaitingInitialSettings(true)
     779             : {
     780           0 :     get(m_pTitleED, "title");
     781           0 :     get(m_pTypeFT, "typeft");
     782           0 :     get(m_pTypeLB, "type");
     783           0 :     get(m_pReadOnlyCB, "readonly");
     784             : 
     785           0 :     get(m_pAreaFrame, "areaframe");
     786           0 :     get(m_pAreaLB, "scope");
     787           0 :     get(m_pLevelFT, "levelft");
     788           0 :     get(m_pLevelNF, "level");
     789             : 
     790           0 :     get(m_pCreateFrame, "createframe");
     791           0 :     get(m_pFromHeadingsCB, "fromheadings");
     792           0 :     get(m_pAddStylesCB, "addstylescb");
     793           0 :     sAddStyleUser = get<Window>("stylescb")->GetText();
     794           0 :     get(m_pAddStylesPB, "styles");
     795           0 :     get(m_pFromTablesCB, "fromtables");
     796           0 :     get(m_pFromFramesCB, "fromframes");
     797           0 :     get(m_pFromGraphicsCB, "fromgraphics");
     798           0 :     get(m_pFromOLECB, "fromoles");
     799           0 :     get(m_pLevelFromChapterCB, "uselevel");
     800             : 
     801           0 :     get(m_pFromCaptionsRB, "captions");
     802           0 :     get(m_pFromObjectNamesRB, "objnames");
     803             : 
     804           0 :     get(m_pCaptionSequenceFT, "categoryft");
     805           0 :     get(m_pCaptionSequenceLB, "category");
     806           0 :     get(m_pDisplayTypeFT, "displayft");
     807           0 :     get(m_pDisplayTypeLB, "display");
     808           0 :     get(m_pTOXMarksCB, "indexmarks");
     809             : 
     810           0 :     get(m_pIdxOptionsFrame, "optionsframe");
     811           0 :     get(m_pCollectSameCB, "combinesame");
     812           0 :     get(m_pUseFFCB, "useff");
     813           0 :     get(m_pUseDashCB, "usedash");
     814           0 :     get(m_pCaseSensitiveCB, "casesens");
     815           0 :     get(m_pInitialCapsCB, "initcaps");
     816           0 :     get(m_pKeyAsEntryCB, "keyasentry");
     817           0 :     get(m_pFromFileCB, "fromfile");
     818           0 :     get(m_pAutoMarkPB, "file");
     819             : 
     820           0 :     get(m_pFromObjFrame, "objectframe");
     821           0 :     get(m_pFromObjCLB, "objects");
     822             : 
     823           0 :     get(m_pAuthorityFrame, "authframe");
     824           0 :     get(m_pSequenceCB, "numberentries");
     825           0 :     get(m_pBracketLB, "brackets");
     826             : 
     827           0 :     get(m_pSortFrame, "sortframe");
     828           0 :     get(m_pLanguageLB, "lang");
     829           0 :     get(m_pSortAlgorithmLB, "keytype");
     830             : 
     831             :     //Default mode is arranged to be the tallest mode
     832             :     //of alphabetical index, lock that height in now
     833           0 :     Size aPrefSize(get_preferred_size());
     834           0 :     set_height_request(aPrefSize.Height());
     835             : 
     836           0 :     pIndexEntryWrapper = new IndexEntrySupplierWrapper();
     837             : 
     838             :     m_pLanguageLB->SetLanguageList( LANG_LIST_ALL | LANG_LIST_ONLY_KNOWN,
     839           0 :                                  false, false, false );
     840             : 
     841           0 :     sAddStyleContent = m_pAddStylesCB->GetText();
     842             : 
     843           0 :     ResStringArray& rNames = aFromNames.GetNames();
     844           0 :     for(sal_uInt32 i = 0; i < rNames.Count(); i++)
     845             :     {
     846           0 :         m_pFromObjCLB->InsertEntry(rNames.GetString(i));
     847           0 :         m_pFromObjCLB->SetEntryData( i, (void*)rNames.GetValue(i) );
     848             :     }
     849             : 
     850           0 :     SetExchangeSupport();
     851           0 :     m_pTypeLB->SetSelectHdl(LINK(this, SwTOXSelectTabPage, TOXTypeHdl));
     852             : 
     853           0 :     m_pAddStylesPB->SetClickHdl(LINK(this, SwTOXSelectTabPage, AddStylesHdl));
     854             : 
     855           0 :     PopupMenu*  pMenu = m_pAutoMarkPB->GetPopupMenu();
     856           0 :     pMenu->SetActivateHdl(LINK(this, SwTOXSelectTabPage, MenuEnableHdl));
     857           0 :     pMenu->SetSelectHdl(LINK(this, SwTOXSelectTabPage, MenuExecuteHdl));
     858             : 
     859           0 :     Link aLk =  LINK(this, SwTOXSelectTabPage, CheckBoxHdl);
     860           0 :     m_pAddStylesCB->SetClickHdl(aLk);
     861           0 :     m_pFromHeadingsCB->SetClickHdl(aLk);
     862           0 :     m_pTOXMarksCB->SetClickHdl(aLk);
     863           0 :     m_pFromFileCB->SetClickHdl(aLk);
     864           0 :     m_pCollectSameCB->SetClickHdl(aLk);
     865           0 :     m_pUseFFCB->SetClickHdl(aLk);
     866           0 :     m_pUseDashCB->SetClickHdl(aLk);
     867           0 :     m_pInitialCapsCB->SetClickHdl(aLk);
     868           0 :     m_pKeyAsEntryCB->SetClickHdl(aLk);
     869             : 
     870           0 :     Link aModifyLk = LINK(this, SwTOXSelectTabPage, ModifyHdl);
     871           0 :     m_pTitleED->SetModifyHdl(aModifyLk);
     872           0 :     m_pLevelNF->SetModifyHdl(aModifyLk);
     873           0 :     m_pSortAlgorithmLB->SetSelectHdl(aModifyLk);
     874             : 
     875           0 :     aLk =  LINK(this, SwTOXSelectTabPage, RadioButtonHdl);
     876           0 :     m_pFromCaptionsRB->SetClickHdl(aLk);
     877           0 :     m_pFromObjectNamesRB->SetClickHdl(aLk);
     878           0 :     RadioButtonHdl(m_pFromCaptionsRB);
     879             : 
     880           0 :     m_pLanguageLB->SetSelectHdl(LINK(this, SwTOXSelectTabPage, LanguageHdl));
     881           0 :     m_pTypeLB->SelectEntryPos(0);
     882           0 :     m_pTitleED->SaveValue();
     883           0 : }
     884             : 
     885           0 : SwTOXSelectTabPage::~SwTOXSelectTabPage()
     886             : {
     887           0 :     delete pIndexRes;
     888           0 :     delete pIndexEntryWrapper;
     889           0 : }
     890             : 
     891           0 : void SwTOXSelectTabPage::SetWrtShell(SwWrtShell& rSh)
     892             : {
     893           0 :     const sal_uInt16 nUserTypeCount = rSh.GetTOXTypeCount(TOX_USER);
     894           0 :     if(nUserTypeCount > 1)
     895             :     {
     896             :         //insert all new user indexes names after the standard user index
     897           0 :         sal_Int32 nPos = m_pTypeLB->GetEntryPos((void*)(sal_uInt32)TO_USER) + 1;
     898           0 :         for(sal_uInt16 nUser = 1; nUser < nUserTypeCount; nUser++)
     899             :         {
     900           0 :             nPos = m_pTypeLB->InsertEntry(rSh.GetTOXType(TOX_USER, nUser)->GetTypeName(), nPos);
     901           0 :             sal_uIntPtr nEntryData = nUser << 8;
     902           0 :             nEntryData |= TO_USER;
     903           0 :             m_pTypeLB->SetEntryData(nPos, (void*)nEntryData);
     904             :         }
     905             :     }
     906           0 : }
     907             : 
     908           0 : bool SwTOXSelectTabPage::FillItemSet( SfxItemSet& )
     909             : {
     910           0 :     return true;
     911             : }
     912             : 
     913           0 : static long lcl_TOXTypesToUserData(CurTOXType eType)
     914             : {
     915           0 :     sal_uInt16 nRet = TOX_INDEX;
     916           0 :     switch(eType.eType)
     917             :     {
     918           0 :         case TOX_INDEX       : nRet = TO_INDEX;     break;
     919             :         case TOX_USER        :
     920             :         {
     921           0 :             nRet = eType.nIndex << 8;
     922           0 :             nRet |= TO_USER;
     923             :         }
     924           0 :         break;
     925           0 :         case TOX_CONTENT     : nRet = TO_CONTENT;   break;
     926           0 :         case TOX_ILLUSTRATIONS:nRet = TO_ILLUSTRATION; break;
     927           0 :         case TOX_OBJECTS     : nRet = TO_OBJECT;    break;
     928           0 :         case TOX_TABLES      : nRet = TO_TABLE;     break;
     929           0 :         case TOX_AUTHORITIES : nRet = TO_AUTHORITIES; break;
     930           0 :         case TOX_BIBLIOGRAPHY : nRet = TO_BIBLIOGRAPHY; break;
     931           0 :         case TOX_CITATION :break;
     932             :     }
     933           0 :     return nRet;
     934             : }
     935             : 
     936           0 : void SwTOXSelectTabPage::SelectType(TOXTypes eSet)
     937             : {
     938           0 :     CurTOXType eCurType (eSet, 0);
     939             : 
     940           0 :     sal_IntPtr nData = lcl_TOXTypesToUserData(eCurType);
     941           0 :     m_pTypeLB->SelectEntryPos(m_pTypeLB->GetEntryPos((void*)nData));
     942           0 :     m_pTypeFT->Enable(false);
     943           0 :     m_pTypeLB->Enable(false);
     944           0 :     TOXTypeHdl(m_pTypeLB);
     945           0 : }
     946             : 
     947           0 : static CurTOXType lcl_UserData2TOXTypes(sal_uInt16 nData)
     948             : {
     949           0 :     CurTOXType eRet;
     950             : 
     951           0 :     switch(nData&0xff)
     952             :     {
     953           0 :         case TO_INDEX       : eRet.eType = TOX_INDEX;       break;
     954             :         case TO_USER        :
     955             :         {
     956           0 :             eRet.eType = TOX_USER;
     957           0 :             eRet.nIndex  = (nData&0xff00) >> 8;
     958             :         }
     959           0 :         break;
     960           0 :         case TO_CONTENT     : eRet.eType = TOX_CONTENT;     break;
     961           0 :         case TO_ILLUSTRATION: eRet.eType = TOX_ILLUSTRATIONS; break;
     962           0 :         case TO_OBJECT      : eRet.eType = TOX_OBJECTS;     break;
     963           0 :         case TO_TABLE       : eRet.eType = TOX_TABLES;      break;
     964           0 :         case TO_AUTHORITIES : eRet.eType = TOX_AUTHORITIES; break;
     965           0 :         case TO_BIBLIOGRAPHY : eRet.eType = TOX_BIBLIOGRAPHY; break;
     966             :         default: OSL_FAIL("what a type?");
     967             :     }
     968           0 :     return eRet;
     969             : }
     970             : 
     971           0 : void SwTOXSelectTabPage::ApplyTOXDescription()
     972             : {
     973           0 :     SwMultiTOXTabDialog* pTOXDlg = (SwMultiTOXTabDialog*)GetTabDialog();
     974           0 :     const CurTOXType aCurType = pTOXDlg->GetCurrentTOXType();
     975           0 :     SwTOXDescription& rDesc = pTOXDlg->GetTOXDescription(aCurType);
     976           0 :     m_pReadOnlyCB->Check(rDesc.IsReadonly());
     977           0 :     if(m_pTitleED->GetText() == m_pTitleED->GetSavedValue())
     978             :     {
     979           0 :         if(rDesc.GetTitle())
     980           0 :             m_pTitleED->SetText(*rDesc.GetTitle());
     981             :         else
     982           0 :             m_pTitleED->SetText(aEmptyOUStr);
     983           0 :         m_pTitleED->SaveValue();
     984             :     }
     985             : 
     986           0 :     m_pAreaLB->SelectEntryPos(rDesc.IsFromChapter() ? 1 : 0);
     987             : 
     988           0 :     if(aCurType.eType != TOX_INDEX)
     989           0 :         m_pLevelNF->SetValue(rDesc.GetLevel());   //content, user
     990             : 
     991           0 :     sal_uInt16 nCreateType = rDesc.GetContentOptions();
     992             : 
     993             :     //user + content
     994           0 :     sal_Bool bHasStyleNames = sal_False;
     995             : 
     996           0 :     for( sal_uInt16 i = 0; i < MAXLEVEL; i++)
     997           0 :         if(!rDesc.GetStyleNames(i).isEmpty())
     998             :         {
     999           0 :             bHasStyleNames = sal_True;
    1000           0 :             break;
    1001             :         }
    1002           0 :     m_pAddStylesCB->Check(bHasStyleNames && (nCreateType & nsSwTOXElement::TOX_TEMPLATE));
    1003             : 
    1004           0 :     m_pFromOLECB->     Check( 0 != (nCreateType & nsSwTOXElement::TOX_OLE) );
    1005           0 :     m_pFromTablesCB->  Check( 0 != (nCreateType & nsSwTOXElement::TOX_TABLE) );
    1006           0 :     m_pFromGraphicsCB->Check( 0 != (nCreateType & nsSwTOXElement::TOX_GRAPHIC) );
    1007           0 :     m_pFromFramesCB->  Check( 0 != (nCreateType & nsSwTOXElement::TOX_FRAME) );
    1008             : 
    1009           0 :     m_pLevelFromChapterCB->Check(rDesc.IsLevelFromChapter());
    1010             : 
    1011             :     //all but illustration and table
    1012           0 :     m_pTOXMarksCB->Check( 0 != (nCreateType & nsSwTOXElement::TOX_MARK) );
    1013             : 
    1014             :     //content
    1015           0 :     if(TOX_CONTENT == aCurType.eType)
    1016             :     {
    1017           0 :         m_pFromHeadingsCB->Check( 0 != (nCreateType & nsSwTOXElement::TOX_OUTLINELEVEL) );
    1018           0 :         m_pAddStylesCB->SetText(sAddStyleContent);
    1019           0 :         m_pAddStylesPB->Enable(m_pAddStylesCB->IsChecked());
    1020             :     }
    1021             :     //index only
    1022           0 :     else if(TOX_INDEX == aCurType.eType)
    1023             :     {
    1024           0 :         const sal_uInt16 nIndexOptions = rDesc.GetIndexOptions();
    1025           0 :         m_pCollectSameCB->     Check( 0 != (nIndexOptions & nsSwTOIOptions::TOI_SAME_ENTRY) );
    1026           0 :         m_pUseFFCB->           Check( 0 != (nIndexOptions & nsSwTOIOptions::TOI_FF) );
    1027           0 :         m_pUseDashCB->         Check( 0 != (nIndexOptions & nsSwTOIOptions::TOI_DASH) );
    1028           0 :         if(m_pUseFFCB->IsChecked())
    1029           0 :             m_pUseDashCB->Enable(false);
    1030           0 :         else if(m_pUseDashCB->IsChecked())
    1031           0 :             m_pUseFFCB->Enable(false);
    1032             : 
    1033           0 :         m_pCaseSensitiveCB->   Check( 0 != (nIndexOptions & nsSwTOIOptions::TOI_CASE_SENSITIVE) );
    1034           0 :         m_pInitialCapsCB->     Check( 0 != (nIndexOptions & nsSwTOIOptions::TOI_INITIAL_CAPS) );
    1035           0 :         m_pKeyAsEntryCB->      Check( 0 != (nIndexOptions & nsSwTOIOptions::TOI_KEY_AS_ENTRY) );
    1036             :     }
    1037           0 :     else if(TOX_ILLUSTRATIONS == aCurType.eType ||
    1038           0 :         TOX_TABLES == aCurType.eType)
    1039             :     {
    1040           0 :         m_pFromObjectNamesRB->Check(rDesc.IsCreateFromObjectNames());
    1041           0 :         m_pFromCaptionsRB->Check(!rDesc.IsCreateFromObjectNames());
    1042           0 :         m_pCaptionSequenceLB->SelectEntry(rDesc.GetSequenceName());
    1043           0 :         m_pDisplayTypeLB->SelectEntryPos( static_cast< sal_Int32 >(rDesc.GetCaptionDisplay()) );
    1044           0 :         RadioButtonHdl(m_pFromCaptionsRB);
    1045             : 
    1046             :     }
    1047           0 :     else if(TOX_OBJECTS == aCurType.eType)
    1048             :     {
    1049           0 :         long nOLEData = rDesc.GetOLEOptions();
    1050           0 :         for(sal_uLong nFromObj = 0; nFromObj < m_pFromObjCLB->GetEntryCount(); nFromObj++)
    1051             :         {
    1052           0 :             sal_IntPtr nData = (sal_IntPtr)m_pFromObjCLB->GetEntryData(nFromObj);
    1053           0 :             m_pFromObjCLB->CheckEntryPos(nFromObj, 0 != (nData & nOLEData));
    1054             :         }
    1055             :     }
    1056           0 :     else if(TOX_AUTHORITIES == aCurType.eType)
    1057             :     {
    1058           0 :         const OUString sBrackets(rDesc.GetAuthBrackets());
    1059           0 :         if(sBrackets.isEmpty() || sBrackets == "  ")
    1060           0 :             m_pBracketLB->SelectEntryPos(0);
    1061             :         else
    1062           0 :             m_pBracketLB->SelectEntry(sBrackets);
    1063           0 :         m_pSequenceCB->Check(rDesc.IsAuthSequence());
    1064             :     }
    1065           0 :     m_pAutoMarkPB->Enable(m_pFromFileCB->IsChecked());
    1066             : 
    1067           0 :     for(sal_uInt16 i = 0; i < MAXLEVEL; i++)
    1068           0 :         aStyleArr[i] = rDesc.GetStyleNames(i);
    1069             : 
    1070           0 :     m_pLanguageLB->SelectLanguage(rDesc.GetLanguage());
    1071           0 :     LanguageHdl(0);
    1072           0 :     for( sal_Int32 nCnt = 0; nCnt < m_pSortAlgorithmLB->GetEntryCount(); ++nCnt )
    1073             :     {
    1074           0 :         const OUString* pEntryData = (const OUString*)m_pSortAlgorithmLB->GetEntryData( nCnt );
    1075             :         OSL_ENSURE(pEntryData, "no entry data available");
    1076           0 :         if( pEntryData && *pEntryData == rDesc.GetSortAlgorithm())
    1077             :         {
    1078           0 :             m_pSortAlgorithmLB->SelectEntryPos( nCnt );
    1079           0 :             break;
    1080             :         }
    1081             :     }
    1082           0 : }
    1083             : 
    1084           0 : void SwTOXSelectTabPage::FillTOXDescription()
    1085             : {
    1086           0 :     SwMultiTOXTabDialog* pTOXDlg = (SwMultiTOXTabDialog*)GetTabDialog();
    1087           0 :     CurTOXType aCurType = pTOXDlg->GetCurrentTOXType();
    1088           0 :     SwTOXDescription& rDesc = pTOXDlg->GetTOXDescription(aCurType);
    1089           0 :     rDesc.SetTitle(m_pTitleED->GetText());
    1090           0 :     rDesc.SetFromChapter(1 == m_pAreaLB->GetSelectEntryPos());
    1091           0 :     sal_uInt16 nContentOptions = 0;
    1092           0 :     if(m_pTOXMarksCB->IsVisible() && m_pTOXMarksCB->IsChecked())
    1093           0 :         nContentOptions |= nsSwTOXElement::TOX_MARK;
    1094             : 
    1095           0 :     sal_uInt16 nIndexOptions = rDesc.GetIndexOptions()&nsSwTOIOptions::TOI_ALPHA_DELIMITTER;
    1096           0 :     switch(rDesc.GetTOXType())
    1097             :     {
    1098             :         case TOX_CONTENT:
    1099           0 :             if(m_pFromHeadingsCB->IsChecked())
    1100           0 :                 nContentOptions |= nsSwTOXElement::TOX_OUTLINELEVEL;
    1101           0 :         break;
    1102             :         case TOX_USER:
    1103             :         {
    1104           0 :             rDesc.SetTOUName(m_pTypeLB->GetSelectEntry());
    1105             : 
    1106           0 :             if(m_pFromOLECB->IsChecked())
    1107           0 :                 nContentOptions |= nsSwTOXElement::TOX_OLE;
    1108           0 :             if(m_pFromTablesCB->IsChecked())
    1109           0 :                 nContentOptions |= nsSwTOXElement::TOX_TABLE;
    1110           0 :             if(m_pFromFramesCB->IsChecked())
    1111           0 :                 nContentOptions |= nsSwTOXElement::TOX_FRAME;
    1112           0 :             if(m_pFromGraphicsCB->IsChecked())
    1113           0 :                 nContentOptions |= nsSwTOXElement::TOX_GRAPHIC;
    1114             :         }
    1115           0 :         break;
    1116             :         case TOX_INDEX:
    1117             :         {
    1118           0 :             nContentOptions = nsSwTOXElement::TOX_MARK;
    1119             : 
    1120           0 :             if(m_pCollectSameCB->IsChecked())
    1121           0 :                 nIndexOptions |= nsSwTOIOptions::TOI_SAME_ENTRY;
    1122           0 :             if(m_pUseFFCB->IsChecked())
    1123           0 :                 nIndexOptions |= nsSwTOIOptions::TOI_FF;
    1124           0 :             if(m_pUseDashCB->IsChecked())
    1125           0 :                 nIndexOptions |= nsSwTOIOptions::TOI_DASH;
    1126           0 :             if(m_pCaseSensitiveCB->IsChecked())
    1127           0 :                 nIndexOptions |= nsSwTOIOptions::TOI_CASE_SENSITIVE;
    1128           0 :             if(m_pInitialCapsCB->IsChecked())
    1129           0 :                 nIndexOptions |= nsSwTOIOptions::TOI_INITIAL_CAPS;
    1130           0 :             if(m_pKeyAsEntryCB->IsChecked())
    1131           0 :                 nIndexOptions |= nsSwTOIOptions::TOI_KEY_AS_ENTRY;
    1132           0 :             if(m_pFromFileCB->IsChecked())
    1133           0 :                 rDesc.SetAutoMarkURL(sAutoMarkURL);
    1134             :             else
    1135           0 :                 rDesc.SetAutoMarkURL(aEmptyOUStr);
    1136             :         }
    1137           0 :         break;
    1138             :         case TOX_ILLUSTRATIONS:
    1139             :         case TOX_TABLES :
    1140           0 :             rDesc.SetCreateFromObjectNames(m_pFromObjectNamesRB->IsChecked());
    1141           0 :             rDesc.SetSequenceName(m_pCaptionSequenceLB->GetSelectEntry());
    1142           0 :             rDesc.SetCaptionDisplay((SwCaptionDisplay)m_pDisplayTypeLB->GetSelectEntryPos());
    1143           0 :         break;
    1144             :         case TOX_OBJECTS:
    1145             :         {
    1146           0 :             long nOLEData = 0;
    1147           0 :             for(sal_uLong i = 0; i < m_pFromObjCLB->GetEntryCount(); i++)
    1148             :             {
    1149           0 :                 if(m_pFromObjCLB->IsChecked(i))
    1150             :                 {
    1151           0 :                     sal_IntPtr nData = (sal_IntPtr)m_pFromObjCLB->GetEntryData(i);
    1152           0 :                     nOLEData |= nData;
    1153             :                 }
    1154             :             }
    1155           0 :             rDesc.SetOLEOptions((sal_uInt16)nOLEData);
    1156             :         }
    1157           0 :         break;
    1158             :         case TOX_AUTHORITIES:
    1159             :         case TOX_BIBLIOGRAPHY :
    1160             :         {
    1161           0 :             if(m_pBracketLB->GetSelectEntryPos())
    1162           0 :                 rDesc.SetAuthBrackets(m_pBracketLB->GetSelectEntry());
    1163             :             else
    1164           0 :                 rDesc.SetAuthBrackets(aEmptyOUStr);
    1165           0 :             rDesc.SetAuthSequence(m_pSequenceCB->IsChecked());
    1166             :         }
    1167           0 :         break;
    1168             :         case TOX_CITATION :
    1169           0 :         break;
    1170             :     }
    1171             : 
    1172           0 :     rDesc.SetLevelFromChapter(  m_pLevelFromChapterCB->IsVisible() &&
    1173           0 :                                 m_pLevelFromChapterCB->IsChecked());
    1174           0 :     if(m_pTOXMarksCB->IsChecked() && m_pTOXMarksCB->IsVisible())
    1175           0 :         nContentOptions |= nsSwTOXElement::TOX_MARK;
    1176           0 :     if(m_pFromHeadingsCB->IsChecked() && m_pFromHeadingsCB->IsVisible())
    1177           0 :         nContentOptions |= nsSwTOXElement::TOX_OUTLINELEVEL;
    1178           0 :     if(m_pAddStylesCB->IsChecked() && m_pAddStylesCB->IsVisible())
    1179           0 :         nContentOptions |= nsSwTOXElement::TOX_TEMPLATE;
    1180             : 
    1181           0 :     rDesc.SetContentOptions(nContentOptions);
    1182           0 :     rDesc.SetIndexOptions(nIndexOptions);
    1183           0 :     rDesc.SetLevel( static_cast< sal_uInt8 >(m_pLevelNF->GetValue()) );
    1184             : 
    1185           0 :     rDesc.SetReadonly(m_pReadOnlyCB->IsChecked());
    1186             : 
    1187           0 :     for(sal_uInt16 i = 0; i < MAXLEVEL; i++)
    1188           0 :         rDesc.SetStyleNames(aStyleArr[i], i);
    1189             : 
    1190           0 :     rDesc.SetLanguage(m_pLanguageLB->GetSelectLanguage());
    1191             :     const OUString* pEntryData = (const OUString*)m_pSortAlgorithmLB->GetEntryData(
    1192           0 :                                             m_pSortAlgorithmLB->GetSelectEntryPos() );
    1193             :     OSL_ENSURE(pEntryData, "no entry data available");
    1194           0 :     if(pEntryData)
    1195           0 :         rDesc.SetSortAlgorithm(*pEntryData);
    1196           0 : }
    1197             : 
    1198           0 : void SwTOXSelectTabPage::Reset( const SfxItemSet& )
    1199             : {
    1200           0 :     SwMultiTOXTabDialog* pTOXDlg = (SwMultiTOXTabDialog*)GetTabDialog();
    1201           0 :     SwWrtShell& rSh = pTOXDlg->GetWrtShell();
    1202           0 :     const CurTOXType aCurType = pTOXDlg->GetCurrentTOXType();
    1203           0 :     sal_IntPtr nData = lcl_TOXTypesToUserData(aCurType);
    1204           0 :     m_pTypeLB->SelectEntryPos(m_pTypeLB->GetEntryPos((void*)nData));
    1205             : 
    1206           0 :     sAutoMarkURL = INetURLObject::decode( rSh.GetTOIAutoMarkURL(),
    1207             :                                         '%',
    1208             :                                            INetURLObject::DECODE_UNAMBIGUOUS,
    1209           0 :                                         RTL_TEXTENCODING_UTF8 );
    1210           0 :     m_pFromFileCB->Check( !sAutoMarkURL.isEmpty() );
    1211             : 
    1212           0 :     m_pCaptionSequenceLB->Clear();
    1213           0 :     const sal_uInt16 nCount = rSh.GetFldTypeCount(RES_SETEXPFLD);
    1214           0 :     for (sal_uInt16 i = 0; i < nCount; i++)
    1215             :     {
    1216           0 :         SwFieldType *pType = rSh.GetFldType( i, RES_SETEXPFLD );
    1217           0 :         if( pType->Which() == RES_SETEXPFLD &&
    1218           0 :             ((SwSetExpFieldType *) pType)->GetType() & nsSwGetSetExpType::GSE_SEQ )
    1219           0 :             m_pCaptionSequenceLB->InsertEntry(pType->GetName());
    1220             :     }
    1221             : 
    1222           0 :     if(pTOXDlg->IsTOXEditMode())
    1223             :     {
    1224           0 :         m_pTypeFT->Enable(false);
    1225           0 :         m_pTypeLB->Enable(false);
    1226             :     }
    1227             : 
    1228           0 :     if(!m_bWaitingInitialSettings)
    1229             :     {
    1230             :         // save current values into the proper TOXDescription
    1231           0 :         FillTOXDescription();
    1232             :     }
    1233           0 :     m_bWaitingInitialSettings = false;
    1234             : 
    1235           0 :     TOXTypeHdl(m_pTypeLB);
    1236           0 :     CheckBoxHdl(m_pAddStylesCB);
    1237           0 : }
    1238             : 
    1239           0 : void SwTOXSelectTabPage::ActivatePage( const SfxItemSet& )
    1240             : {
    1241             :     //nothing to do
    1242           0 : }
    1243             : 
    1244           0 : int SwTOXSelectTabPage::DeactivatePage( SfxItemSet* _pSet )
    1245             : {
    1246           0 :     if(_pSet)
    1247             :         _pSet->Put(SfxUInt16Item(FN_PARAM_TOX_TYPE,
    1248           0 :             (sal_uInt16)(sal_IntPtr)m_pTypeLB->GetEntryData( m_pTypeLB->GetSelectEntryPos() )));
    1249           0 :     FillTOXDescription();
    1250           0 :     return LEAVE_PAGE;
    1251             : }
    1252             : 
    1253           0 : SfxTabPage* SwTOXSelectTabPage::Create( Window* pParent, const SfxItemSet& rAttrSet)
    1254             : {
    1255           0 :     return new SwTOXSelectTabPage(pParent, rAttrSet);
    1256             : }
    1257             : 
    1258           0 : IMPL_LINK(SwTOXSelectTabPage, TOXTypeHdl,   ListBox*, pBox)
    1259             : {
    1260           0 :     SwMultiTOXTabDialog* pTOXDlg = (SwMultiTOXTabDialog*)GetTabDialog();
    1261             :     const sal_uInt16 nType =  sal::static_int_cast< sal_uInt16 >(reinterpret_cast< sal_uIntPtr >(
    1262           0 :                                 pBox->GetEntryData( pBox->GetSelectEntryPos() )));
    1263           0 :     CurTOXType eCurType = lcl_UserData2TOXTypes(nType);
    1264           0 :     pTOXDlg->SetCurrentTOXType(eCurType);
    1265             : 
    1266           0 :     m_pAreaLB->Show( 0 != (nType & (TO_CONTENT|TO_ILLUSTRATION|TO_USER|TO_INDEX|TO_TABLE|TO_OBJECT)) );
    1267           0 :     m_pLevelFT->Show( 0 != (nType & (TO_CONTENT)) );
    1268           0 :     m_pLevelNF->Show( 0 != (nType & (TO_CONTENT)) );
    1269           0 :     m_pLevelFromChapterCB->Show( 0 != (nType & (TO_USER)) );
    1270           0 :     m_pAreaFrame->Show( 0 != (nType & (TO_CONTENT|TO_ILLUSTRATION|TO_USER|TO_INDEX|TO_TABLE|TO_OBJECT)) );
    1271             : 
    1272           0 :     m_pFromHeadingsCB->Show( 0 != (nType & (TO_CONTENT)) );
    1273           0 :     m_pAddStylesCB->Show( 0 != (nType & (TO_CONTENT|TO_USER)) );
    1274           0 :     m_pAddStylesPB->Show( 0 != (nType & (TO_CONTENT|TO_USER)) );
    1275             : 
    1276           0 :     m_pFromTablesCB->Show( 0 != (nType & (TO_USER)) );
    1277           0 :     m_pFromFramesCB->Show( 0 != (nType & (TO_USER)) );
    1278           0 :     m_pFromGraphicsCB->Show( 0 != (nType & (TO_USER)) );
    1279           0 :     m_pFromOLECB->Show( 0 != (nType & (TO_USER)) );
    1280             : 
    1281           0 :     m_pFromCaptionsRB->Show( 0 != (nType & (TO_ILLUSTRATION|TO_TABLE)) );
    1282           0 :     m_pFromObjectNamesRB->Show( 0 != (nType & (TO_ILLUSTRATION|TO_TABLE)) );
    1283             : 
    1284           0 :     m_pTOXMarksCB->Show( 0 != (nType & (TO_CONTENT|TO_USER)) );
    1285             : 
    1286           0 :     m_pCreateFrame->Show( 0 != (nType & (TO_CONTENT|TO_ILLUSTRATION|TO_USER|TO_TABLE)) );
    1287           0 :     m_pCaptionSequenceFT->Show( 0 != (nType & (TO_ILLUSTRATION|TO_TABLE)) );
    1288           0 :     m_pCaptionSequenceLB->Show( 0 != (nType & (TO_ILLUSTRATION|TO_TABLE)) );
    1289           0 :     m_pDisplayTypeFT->Show( 0 != (nType & (TO_ILLUSTRATION|TO_TABLE)) );
    1290           0 :     m_pDisplayTypeLB->Show( 0 != (nType & (TO_ILLUSTRATION|TO_TABLE)) );
    1291             : 
    1292           0 :     m_pAuthorityFrame->Show( 0 != (nType & TO_AUTHORITIES) );
    1293             : 
    1294           0 :     bool bEnableSortLanguage = 0 != (nType & (TO_INDEX|TO_AUTHORITIES));
    1295           0 :     m_pSortFrame->Show(bEnableSortLanguage);
    1296             : 
    1297           0 :     if( nType & TO_ILLUSTRATION )
    1298             :     {
    1299             :         m_pCaptionSequenceLB->SelectEntry( SwStyleNameMapper::GetUIName(
    1300           0 :                                     RES_POOLCOLL_LABEL_ABB, OUString() ));
    1301             :     }
    1302           0 :     else if( nType & TO_TABLE )
    1303             :     {
    1304             :         m_pCaptionSequenceLB->SelectEntry( SwStyleNameMapper::GetUIName(
    1305           0 :                                     RES_POOLCOLL_LABEL_TABLE, OUString() ));
    1306             :     }
    1307           0 :     else if( nType & TO_USER )
    1308             :     {
    1309           0 :         m_pAddStylesCB->SetText(sAddStyleUser);
    1310             :     }
    1311             : 
    1312           0 :     m_pIdxOptionsFrame->Show( 0 != (nType & TO_INDEX) );
    1313             : 
    1314             :     //object index
    1315           0 :     m_pFromObjFrame->Show( 0 != (nType & TO_OBJECT) );
    1316             : 
    1317             :     //set control values from the proper TOXDescription
    1318             :     {
    1319           0 :         ApplyTOXDescription();
    1320             :     }
    1321           0 :     ModifyHdl(0);
    1322           0 :     return 0;
    1323             : }
    1324             : 
    1325           0 : IMPL_LINK_NOARG(SwTOXSelectTabPage, ModifyHdl)
    1326             : {
    1327           0 :     if(!m_bWaitingInitialSettings)
    1328             :     {
    1329           0 :         FillTOXDescription();
    1330           0 :         SwMultiTOXTabDialog* pTOXDlg = (SwMultiTOXTabDialog*)GetTabDialog();
    1331           0 :         pTOXDlg->CreateOrUpdateExample(pTOXDlg->GetCurrentTOXType().eType, TOX_PAGE_SELECT);
    1332             :     }
    1333           0 :     return 0;
    1334             : }
    1335             : 
    1336           0 : IMPL_LINK(SwTOXSelectTabPage, CheckBoxHdl,  CheckBox*, pBox )
    1337             : {
    1338           0 :     SwMultiTOXTabDialog* pTOXDlg = (SwMultiTOXTabDialog*)GetTabDialog();
    1339           0 :     const CurTOXType aCurType = pTOXDlg->GetCurrentTOXType();
    1340           0 :     if(TOX_CONTENT == aCurType.eType)
    1341             :     {
    1342             :         //at least one of the three CheckBoxes must be checked
    1343           0 :         if(!m_pAddStylesCB->IsChecked() && !m_pFromHeadingsCB->IsChecked() && !m_pTOXMarksCB->IsChecked())
    1344             :         {
    1345             :             //TODO: InfoBox?
    1346           0 :             pBox->Check(true);
    1347             :         }
    1348           0 :         m_pAddStylesPB->Enable(m_pAddStylesCB->IsChecked());
    1349             :     }
    1350           0 :     if(TOX_USER == aCurType.eType)
    1351             :     {
    1352           0 :         m_pAddStylesPB->Enable(m_pAddStylesCB->IsChecked());
    1353             :     }
    1354           0 :     else if(TOX_INDEX == aCurType.eType)
    1355             :     {
    1356           0 :         m_pAutoMarkPB->Enable(m_pFromFileCB->IsChecked());
    1357           0 :         m_pUseFFCB->Enable(m_pCollectSameCB->IsChecked() && !m_pUseDashCB->IsChecked());
    1358           0 :         m_pUseDashCB->Enable(m_pCollectSameCB->IsChecked() && !m_pUseFFCB->IsChecked());
    1359           0 :         m_pCaseSensitiveCB->Enable(m_pCollectSameCB->IsChecked());
    1360             :     }
    1361           0 :     ModifyHdl(0);
    1362           0 :     return 0;
    1363             : };
    1364             : 
    1365           0 : IMPL_LINK_NOARG(SwTOXSelectTabPage, RadioButtonHdl)
    1366             : {
    1367           0 :     sal_Bool bEnable = m_pFromCaptionsRB->IsChecked();
    1368           0 :     m_pCaptionSequenceFT->Enable(bEnable);
    1369           0 :     m_pCaptionSequenceLB->Enable(bEnable);
    1370           0 :     m_pDisplayTypeFT->Enable(bEnable);
    1371           0 :     m_pDisplayTypeLB->Enable(bEnable);
    1372           0 :     ModifyHdl(0);
    1373           0 :     return 0;
    1374             : }
    1375             : 
    1376           0 : IMPL_LINK(SwTOXSelectTabPage, LanguageHdl, ListBox*, pBox)
    1377             : {
    1378           0 :     lang::Locale aLcl( LanguageTag( m_pLanguageLB->GetSelectLanguage() ).getLocale() );
    1379           0 :     Sequence< OUString > aSeq = pIndexEntryWrapper->GetAlgorithmList( aLcl );
    1380             : 
    1381           0 :     if( !pIndexRes )
    1382           0 :         pIndexRes = new IndexEntryResource();
    1383             : 
    1384           0 :     OUString sOldString;
    1385             :     void* pUserData;
    1386           0 :     if( 0 != (pUserData = m_pSortAlgorithmLB->GetEntryData( m_pSortAlgorithmLB->GetSelectEntryPos())) )
    1387           0 :         sOldString = *(OUString*)pUserData;
    1388             :     void* pDel;
    1389           0 :     sal_Int32 nEnd = m_pSortAlgorithmLB->GetEntryCount();
    1390           0 :     for( sal_Int32 n = 0; n < nEnd; ++n )
    1391           0 :         if( 0 != ( pDel = m_pSortAlgorithmLB->GetEntryData( n )) )
    1392           0 :             delete (OUString*)pDel;
    1393           0 :     m_pSortAlgorithmLB->Clear();
    1394             : 
    1395           0 :     nEnd = aSeq.getLength();
    1396           0 :     for( sal_Int32 nCnt = 0; nCnt < nEnd; ++nCnt )
    1397             :     {
    1398           0 :         const OUString sAlg(aSeq[ nCnt ]);
    1399           0 :         const OUString sUINm = pIndexRes->GetTranslation( sAlg );
    1400           0 :         sal_Int32 nInsPos = m_pSortAlgorithmLB->InsertEntry( sUINm );
    1401           0 :         m_pSortAlgorithmLB->SetEntryData( nInsPos, new OUString( sAlg ));
    1402           0 :         if( sAlg == sOldString )
    1403           0 :             m_pSortAlgorithmLB->SelectEntryPos( nInsPos );
    1404           0 :     }
    1405             : 
    1406           0 :     if( LISTBOX_ENTRY_NOTFOUND == m_pSortAlgorithmLB->GetSelectEntryPos() )
    1407           0 :         m_pSortAlgorithmLB->SelectEntryPos( 0 );
    1408             : 
    1409           0 :     if(pBox)
    1410           0 :         ModifyHdl(0);
    1411           0 :     return 0;
    1412             : };
    1413             : 
    1414           0 : IMPL_LINK(SwTOXSelectTabPage, AddStylesHdl, PushButton*, pButton)
    1415             : {
    1416             :     SwAddStylesDlg_Impl* pDlg = new SwAddStylesDlg_Impl(pButton,
    1417           0 :         ((SwMultiTOXTabDialog*)GetTabDialog())->GetWrtShell(),
    1418           0 :         aStyleArr);
    1419           0 :     pDlg->Execute();
    1420           0 :     delete pDlg;
    1421           0 :     ModifyHdl(0);
    1422           0 :     return 0;
    1423             : }
    1424             : 
    1425           0 : IMPL_LINK(SwTOXSelectTabPage, MenuEnableHdl, Menu*, pMenu)
    1426             : {
    1427           0 :     pMenu->EnableItem("edit", !sAutoMarkURL.isEmpty());
    1428           0 :     return 0;
    1429             : }
    1430             : 
    1431           0 : IMPL_LINK(SwTOXSelectTabPage, MenuExecuteHdl, Menu*, pMenu)
    1432             : {
    1433           0 :     const OUString sSaveAutoMarkURL = sAutoMarkURL;
    1434           0 :     OString sIdent(pMenu->GetCurItemIdent());
    1435             : 
    1436           0 :     if (sIdent == "open")
    1437             :     {
    1438           0 :         sAutoMarkURL = lcl_CreateAutoMarkFileDlg(
    1439           0 :                                 sAutoMarkURL, sAutoMarkType, true);
    1440             :     }
    1441           0 :     else if ((sIdent == "new") || (sIdent == "edit"))
    1442             :     {
    1443           0 :         bool bNew = (sIdent == "new");
    1444           0 :         if (bNew)
    1445             :         {
    1446           0 :             sAutoMarkURL = lcl_CreateAutoMarkFileDlg(
    1447           0 :                                     sAutoMarkURL, sAutoMarkType, false);
    1448           0 :             if( sAutoMarkURL.isEmpty() )
    1449           0 :                 return 0;
    1450             :         }
    1451             : 
    1452             :         SwAutoMarkDlg_Impl* pAutoMarkDlg = new SwAutoMarkDlg_Impl(
    1453           0 :                 m_pAutoMarkPB, sAutoMarkURL, sAutoMarkType, bNew );
    1454             : 
    1455           0 :         if( RET_OK != pAutoMarkDlg->Execute() && bNew )
    1456           0 :             sAutoMarkURL = sSaveAutoMarkURL;
    1457           0 :         delete pAutoMarkDlg;
    1458             :     }
    1459           0 :     return 0;
    1460             : }
    1461             : 
    1462           0 : class SwTOXEdit : public Edit
    1463             : {
    1464             :     SwFormToken aFormToken;
    1465             :     Link        aPrevNextControlLink;
    1466             :     bool     bNextControl;
    1467             :     SwTokenWindow* m_pParent;
    1468             : public:
    1469           0 :     SwTOXEdit( Window* pParent, SwTokenWindow* pTokenWin,
    1470             :                 const SwFormToken& aToken)
    1471             :         : Edit( pParent, WB_BORDER|WB_TABSTOP|WB_CENTER),
    1472             :         aFormToken(aToken),
    1473             :         bNextControl(false),
    1474           0 :         m_pParent( pTokenWin )
    1475             :     {
    1476           0 :     }
    1477             : 
    1478             :     virtual void    KeyInput( const KeyEvent& rKEvt ) SAL_OVERRIDE;
    1479             :     virtual void    RequestHelp( const HelpEvent& rHEvt ) SAL_OVERRIDE;
    1480             : 
    1481           0 :     bool    IsNextControl() const {return bNextControl;}
    1482           0 :     void SetPrevNextLink( const Link& rLink )   {aPrevNextControlLink = rLink;}
    1483             : 
    1484           0 :     const SwFormToken&  GetFormToken()
    1485             :         {
    1486           0 :             aFormToken.sText = GetText();
    1487           0 :             return aFormToken;
    1488             :         }
    1489             : 
    1490           0 :     void    SetCharStyleName(const OUString& rSet, sal_uInt16 nPoolId)
    1491             :         {
    1492           0 :             aFormToken.sCharStyleName = rSet;
    1493           0 :             aFormToken.nPoolId = nPoolId;
    1494           0 :         }
    1495             : 
    1496             :     void    AdjustSize();
    1497             : };
    1498             : 
    1499           0 : void SwTOXEdit::RequestHelp( const HelpEvent& rHEvt )
    1500             : {
    1501           0 :     if(!m_pParent->CreateQuickHelp(this, aFormToken, rHEvt))
    1502           0 :         Edit::RequestHelp(rHEvt);
    1503           0 : }
    1504             : 
    1505           0 : void SwTOXEdit::KeyInput( const KeyEvent& rKEvt )
    1506             : {
    1507           0 :     const Selection& rSel = GetSelection();
    1508           0 :     const sal_Int32 nTextLen = GetText().getLength();
    1509           0 :     if((rSel.A() == rSel.B() &&
    1510           0 :         !rSel.A()) || rSel.A() == nTextLen )
    1511             :     {
    1512           0 :         bool bCall = false;
    1513           0 :         KeyCode aCode = rKEvt.GetKeyCode();
    1514           0 :         if(aCode.GetCode() == KEY_RIGHT && rSel.A() == nTextLen)
    1515             :         {
    1516           0 :             bNextControl = true;
    1517           0 :             bCall = true;
    1518             :         }
    1519           0 :         else if(aCode.GetCode() == KEY_LEFT && !rSel.A() )
    1520             :         {
    1521           0 :             bNextControl = false;
    1522           0 :             bCall = true;
    1523             :         }
    1524           0 :         else if ( (aCode.GetCode() == KEY_F3) && aCode.IsShift() && !aCode.IsMod1() && !aCode.IsMod2() )
    1525             :         {
    1526           0 :             if ( m_pParent )
    1527             :             {
    1528           0 :                 m_pParent->SetFocus2theAllBtn();
    1529             :             }
    1530             :         }
    1531           0 :         if(bCall && aPrevNextControlLink.IsSet())
    1532           0 :             aPrevNextControlLink.Call(this);
    1533             : 
    1534             :     }
    1535           0 :     Edit::KeyInput(rKEvt);
    1536           0 : }
    1537             : 
    1538           0 : void SwTOXEdit::AdjustSize()
    1539             : {
    1540           0 :      Size aSize(GetSizePixel());
    1541           0 :      Size aTextSize(GetTextWidth(GetText()), GetTextHeight());
    1542           0 :     aTextSize = LogicToPixel(aTextSize);
    1543           0 :     aSize.Width() = aTextSize.Width() + EDIT_MINWIDTH;
    1544           0 :     SetSizePixel(aSize);
    1545           0 : }
    1546             : 
    1547           0 : class SwTOXButton : public PushButton
    1548             : {
    1549             :     SwFormToken aFormToken;
    1550             :     Link        aPrevNextControlLink;
    1551             :     bool        bNextControl;
    1552             :     SwTokenWindow* m_pParent;
    1553             : public:
    1554           0 :     SwTOXButton( Window* pParent, SwTokenWindow* pTokenWin,
    1555             :                 const SwFormToken& rToken)
    1556             :         : PushButton(pParent, WB_BORDER|WB_TABSTOP),
    1557             :         aFormToken(rToken),
    1558             :         bNextControl(false),
    1559           0 :         m_pParent(pTokenWin)
    1560             :     {
    1561           0 :     }
    1562             : 
    1563             :     virtual void KeyInput( const KeyEvent& rKEvt ) SAL_OVERRIDE;
    1564             :     virtual void RequestHelp( const HelpEvent& rHEvt ) SAL_OVERRIDE;
    1565             : 
    1566           0 :     bool IsNextControl() const          {return bNextControl;}
    1567           0 :     void SetPrevNextLink(const Link& rLink) {aPrevNextControlLink = rLink;}
    1568           0 :     const SwFormToken& GetFormToken() const {return aFormToken;}
    1569             : 
    1570           0 :     void SetCharStyleName(const OUString& rSet, sal_uInt16 nPoolId)
    1571             :         {
    1572           0 :             aFormToken.sCharStyleName = rSet;
    1573           0 :             aFormToken.nPoolId = nPoolId;
    1574           0 :         }
    1575             : 
    1576           0 :     void SetTabPosition(SwTwips nSet)
    1577           0 :         { aFormToken.nTabStopPosition = nSet; }
    1578             : 
    1579           0 :     void SetFillChar( sal_Unicode cSet )
    1580           0 :         { aFormToken.cTabFillChar = cSet; }
    1581             : 
    1582           0 :     void SetTabAlign(SvxTabAdjust eAlign)
    1583           0 :          {  aFormToken.eTabAlign = eAlign;}
    1584             : 
    1585             : //---> i89791
    1586             :     //used for entry number format, in TOC only
    1587             :     //needed for different UI dialog position
    1588           0 :     void SetEntryNumberFormat(sal_uInt16 nSet) {
    1589           0 :         switch(nSet)
    1590             :         {
    1591             :         default:
    1592             :         case 0:
    1593           0 :             aFormToken.nChapterFormat = CF_NUMBER;
    1594           0 :             break;
    1595             :         case 1:
    1596           0 :             aFormToken.nChapterFormat = CF_NUM_NOPREPST_TITLE;
    1597           0 :             break;
    1598             :         }
    1599           0 :     }
    1600             : 
    1601           0 :     void SetChapterInfo(sal_uInt16 nSet) {
    1602           0 :         switch(nSet)
    1603             :         {
    1604             :         default:
    1605             :         case 0:
    1606           0 :             aFormToken.nChapterFormat = CF_NUM_NOPREPST_TITLE;
    1607           0 :             break;
    1608             :         case 1:
    1609           0 :             aFormToken.nChapterFormat = CF_TITLE;
    1610           0 :             break;
    1611             :         case 2:
    1612           0 :             aFormToken.nChapterFormat = CF_NUMBER_NOPREPST;
    1613           0 :             break;
    1614             :         }
    1615           0 :     }
    1616             :     sal_uInt16 GetChapterInfo() const{ return aFormToken.nChapterFormat;}
    1617             : 
    1618           0 :     void SetOutlineLevel( sal_uInt16 nSet ) { aFormToken.nOutlineLevel = nSet;}//i53420
    1619             :     sal_uInt16 GetOutlineLevel() const{ return aFormToken.nOutlineLevel;}
    1620             : 
    1621           0 :     void SetLinkEnd()
    1622             :         {
    1623             :             OSL_ENSURE(TOKEN_LINK_START == aFormToken.eTokenType,
    1624             :                                     "call SetLinkEnd for link start only!");
    1625           0 :             aFormToken.eTokenType = TOKEN_LINK_END;
    1626           0 :             aFormToken.sText = SwForm::GetFormLinkEnd();
    1627           0 :             SetText(aFormToken.sText);
    1628           0 :         }
    1629           0 :     void SetLinkStart()
    1630             :         {
    1631             :             OSL_ENSURE(TOKEN_LINK_END == aFormToken.eTokenType,
    1632             :                                     "call SetLinkStart for link start only!");
    1633           0 :             aFormToken.eTokenType = TOKEN_LINK_START;
    1634           0 :             aFormToken.sText = SwForm::GetFormLinkStt();
    1635           0 :             SetText(aFormToken.sText);
    1636           0 :         }
    1637             : };
    1638             : 
    1639           0 : void SwTOXButton::KeyInput( const KeyEvent& rKEvt )
    1640             : {
    1641           0 :     bool bCall = false;
    1642           0 :     KeyCode aCode = rKEvt.GetKeyCode();
    1643           0 :     if(aCode.GetCode() == KEY_RIGHT)
    1644             :     {
    1645           0 :         bNextControl = true;
    1646           0 :         bCall = true;
    1647             :     }
    1648           0 :     else if(aCode.GetCode() == KEY_LEFT  )
    1649             :     {
    1650           0 :         bNextControl = false;
    1651           0 :         bCall = true;
    1652             :     }
    1653           0 :     else if(aCode.GetCode() == KEY_DELETE)
    1654             :     {
    1655           0 :         m_pParent->RemoveControl(this, sal_True);
    1656             :         //this is invalid here
    1657           0 :         return;
    1658             :     }
    1659           0 :     else if ( (aCode.GetCode() == KEY_F3) && aCode.IsShift() && !aCode.IsMod1() && !aCode.IsMod2() )
    1660             :     {
    1661           0 :         if ( m_pParent )
    1662             :         {
    1663           0 :             m_pParent->SetFocus2theAllBtn();
    1664             :         }
    1665             :     }
    1666           0 :     if(bCall && aPrevNextControlLink.IsSet())
    1667           0 :             aPrevNextControlLink.Call(this);
    1668             :     else
    1669           0 :         PushButton::KeyInput(rKEvt);
    1670             : }
    1671             : 
    1672           0 : void SwTOXButton::RequestHelp( const HelpEvent& rHEvt )
    1673             : {
    1674           0 :     if(!m_pParent->CreateQuickHelp(this, aFormToken, rHEvt))
    1675           0 :         Button::RequestHelp(rHEvt);
    1676           0 : }
    1677             : 
    1678           0 : SwIdxTreeListBox::SwIdxTreeListBox(Window* pPar, WinBits nStyle)
    1679             :     : SvTreeListBox(pPar, nStyle)
    1680           0 :     , pParent(NULL)
    1681             : {
    1682           0 : }
    1683             : 
    1684           0 : extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeSwIdxTreeListBox(Window *pParent, VclBuilder::stringmap &rMap)
    1685             : {
    1686           0 :     WinBits nWinStyle = WB_TABSTOP;
    1687           0 :     OString sBorder = VclBuilder::extractCustomProperty(rMap);
    1688           0 :     if (!sBorder.isEmpty())
    1689           0 :         nWinStyle |= WB_BORDER;
    1690           0 :     return new SwIdxTreeListBox(pParent, nWinStyle);
    1691             : }
    1692             : 
    1693           0 : void SwIdxTreeListBox::RequestHelp( const HelpEvent& rHEvt )
    1694             : {
    1695           0 :     if( rHEvt.GetMode() & HELPMODE_QUICK )
    1696             :     {
    1697           0 :      Point aPos( ScreenToOutputPixel( rHEvt.GetMousePosPixel() ));
    1698           0 :         SvTreeListEntry* pEntry = GetEntry( aPos );
    1699           0 :         if( pEntry )
    1700             :         {
    1701           0 :             sal_uInt16 nLevel = static_cast< sal_uInt16 >(GetModel()->GetAbsPos(pEntry));
    1702           0 :             OUString sEntry = pParent->GetLevelHelp(++nLevel);
    1703           0 :             if (comphelper::string::equals(sEntry, '*'))
    1704           0 :                 sEntry = GetEntryText(pEntry);
    1705           0 :             if(!sEntry.isEmpty())
    1706             :             {
    1707             :                 SvLBoxTab* pTab;
    1708           0 :                 SvLBoxItem* pItem = GetItem( pEntry, aPos.X(), &pTab );
    1709           0 :                 if (pItem && SV_ITEM_ID_LBOXSTRING == pItem->GetType())
    1710             :                 {
    1711           0 :                     aPos = GetEntryPosition( pEntry );
    1712             : 
    1713           0 :                     aPos.X() = GetTabPos( pEntry, pTab );
    1714           0 :                  Size aSize( pItem->GetSize( this, pEntry ) );
    1715             : 
    1716           0 :                     if((aPos.X() + aSize.Width()) > GetSizePixel().Width())
    1717           0 :                         aSize.Width() = GetSizePixel().Width() - aPos.X();
    1718             : 
    1719           0 :                     aPos = OutputToScreenPixel(aPos);
    1720           0 :                      Rectangle aItemRect( aPos, aSize );
    1721             :                     Help::ShowQuickHelp( this, aItemRect, sEntry,
    1722           0 :                             QUICKHELP_LEFT|QUICKHELP_VCENTER );
    1723             :                 }
    1724           0 :             }
    1725             :         }
    1726             :     }
    1727             :     else
    1728           0 :         SvTreeListBox::RequestHelp(rHEvt);
    1729           0 : }
    1730             : 
    1731           0 : SwTOXEntryTabPage::SwTOXEntryTabPage(Window* pParent, const SfxItemSet& rAttrSet)
    1732             :     : SfxTabPage(pParent, "TocEntriesPage",
    1733             :         "modules/swriter/ui/tocentriespage.ui", rAttrSet)
    1734             :     , sDelimStr(SW_RESSTR(STR_DELIM))
    1735             :     , sNoCharStyle(SW_RESSTR(STR_NO_CHAR_STYLE))
    1736             :     , sNoCharSortKey(SW_RESSTR(STR_NOSORTKEY))
    1737             :     , m_pCurrentForm(0)
    1738           0 :     , bInLevelHdl(false)
    1739             : {
    1740           0 :     get(m_pLevelFT, "levelft");
    1741           0 :     sAuthTypeStr = get<FixedText>("typeft")->GetText();
    1742           0 :     get(m_pLevelLB, "level");
    1743           0 :     m_pLevelLB->SetTabPage(this);
    1744           0 :     get(m_pAllLevelsPB, "all");
    1745           0 :     get(m_pEntryNoPB, "chapterno");
    1746           0 :     get(m_pEntryPB, "entrytext");
    1747           0 :     get(m_pTabPB, "tabstop");
    1748           0 :     get(m_pChapterInfoPB, "chapterinfo");
    1749           0 :     get(m_pPageNoPB, "pageno");
    1750           0 :     get(m_pHyperLinkPB, "hyperlink");
    1751             : 
    1752           0 :     get(m_pAuthFieldsLB, "authfield");
    1753           0 :     m_pAuthFieldsLB->SetStyle(m_pAuthFieldsLB->GetStyle() | WB_SORT);
    1754           0 :     get(m_pAuthInsertPB, "insert");
    1755           0 :     get(m_pAuthRemovePB, "remove");
    1756             : 
    1757           0 :     get(m_pCharStyleLB, "charstyle");
    1758           0 :     get(m_pEditStylePB, "edit");
    1759             : 
    1760           0 :     get(m_pChapterEntryFT, "chapterentryft");
    1761           0 :     get(m_pChapterEntryLB, "chapterentry");
    1762             : 
    1763           0 :     get(m_pNumberFormatFT, "numberformatft");
    1764           0 :     get(m_pNumberFormatLB, "numberformat");
    1765             : 
    1766           0 :     get(m_pEntryOutlineLevelFT, "entryoutlinelevelft");
    1767           0 :     get(m_pEntryOutlineLevelNF, "entryoutlinelevel");
    1768             : 
    1769           0 :     get(m_pFillCharFT, "fillcharft");
    1770           0 :     get(m_pFillCharCB, "fillchar");
    1771             : 
    1772           0 :     get(m_pTabPosFT, "tabstopposft");
    1773           0 :     get(m_pTabPosMF, "tabstoppos");
    1774           0 :     get(m_pAutoRightCB, "alignright");
    1775             : 
    1776           0 :     get(m_pFormatFrame, "formatframe");
    1777           0 :     get(m_pRelToStyleCB, "reltostyle");
    1778           0 :     get(m_pMainEntryStyleFT, "mainstyleft");
    1779           0 :     get(m_pMainEntryStyleLB, "mainstyle");
    1780           0 :     get(m_pAlphaDelimCB, "alphadelim");
    1781           0 :     get(m_pCommaSeparatedCB, "commasep");
    1782             : 
    1783           0 :     get(m_pSortingFrame, "sortingframe");
    1784           0 :     get(m_pSortDocPosRB, "sortpos");
    1785           0 :     get(m_pSortContentRB, "sortcontents");
    1786             : 
    1787           0 :     get(m_pSortKeyFrame, "sortkeyframe");
    1788           0 :     get(m_pFirstKeyLB, "key1lb");
    1789           0 :     get(m_pSecondKeyLB, "key2lb");
    1790           0 :     get(m_pThirdKeyLB, "key3lb");
    1791           0 :     get(m_pFirstSortUpRB, "up1cb");
    1792           0 :     get(m_pSecondSortUpRB, "up2cb");
    1793           0 :     get(m_pThirdSortUpRB, "up3cb");
    1794           0 :     get(m_pFirstSortDownRB, "down1cb");
    1795           0 :     get(m_pSecondSortDownRB, "down2cb");
    1796           0 :     get(m_pThirdSortDownRB, "down3cb");
    1797             : 
    1798           0 :     get(m_pTokenWIN, "token");
    1799           0 :     m_pTokenWIN->SetTabPage(this);
    1800             : 
    1801           0 :     sLevelStr = m_pLevelFT->GetText();
    1802           0 :     m_pLevelLB->SetStyle( m_pLevelLB->GetStyle() | WB_HSCROLL );
    1803           0 :     m_pLevelLB->SetSpaceBetweenEntries(0);
    1804           0 :     m_pLevelLB->SetSelectionMode( SINGLE_SELECTION );
    1805           0 :     m_pLevelLB->SetHighlightRange();   // select full width
    1806           0 :     m_pLevelLB->Show();
    1807             : 
    1808           0 :     aLastTOXType.eType = (TOXTypes)USHRT_MAX;
    1809           0 :     aLastTOXType.nIndex = 0;
    1810             : 
    1811           0 :     SetExchangeSupport();
    1812           0 :     m_pEntryNoPB->SetClickHdl(LINK(this, SwTOXEntryTabPage, InsertTokenHdl));
    1813           0 :     m_pEntryPB->SetClickHdl(LINK(this, SwTOXEntryTabPage, InsertTokenHdl));
    1814           0 :     m_pChapterInfoPB->SetClickHdl(LINK(this, SwTOXEntryTabPage, InsertTokenHdl));
    1815           0 :     m_pPageNoPB->SetClickHdl(LINK(this, SwTOXEntryTabPage, InsertTokenHdl));
    1816           0 :     m_pTabPB->SetClickHdl(LINK(this, SwTOXEntryTabPage, InsertTokenHdl));
    1817           0 :     m_pHyperLinkPB->SetClickHdl(LINK(this, SwTOXEntryTabPage, InsertTokenHdl));
    1818           0 :     m_pEditStylePB->SetClickHdl(LINK(this, SwTOXEntryTabPage, EditStyleHdl));
    1819           0 :     m_pLevelLB->SetSelectHdl(LINK(this, SwTOXEntryTabPage, LevelHdl));
    1820           0 :     m_pTokenWIN->SetButtonSelectedHdl(LINK(this, SwTOXEntryTabPage, TokenSelectedHdl));
    1821           0 :     m_pTokenWIN->SetModifyHdl(LINK(this, SwTOXEntryTabPage, ModifyHdl));
    1822           0 :     m_pCharStyleLB->SetSelectHdl(LINK(this, SwTOXEntryTabPage, StyleSelectHdl));
    1823           0 :     m_pCharStyleLB->InsertEntry(sNoCharStyle);
    1824           0 :     m_pChapterEntryLB->SetSelectHdl(LINK(this, SwTOXEntryTabPage, ChapterInfoHdl));
    1825           0 :     m_pEntryOutlineLevelNF->SetModifyHdl(LINK(this, SwTOXEntryTabPage, ChapterInfoOutlineHdl));
    1826           0 :     m_pNumberFormatLB->SetSelectHdl(LINK(this, SwTOXEntryTabPage, NumberFormatHdl));
    1827             : 
    1828           0 :     m_pTabPosMF->SetModifyHdl(LINK(this, SwTOXEntryTabPage, TabPosHdl));
    1829           0 :     m_pFillCharCB->SetModifyHdl(LINK(this, SwTOXEntryTabPage, FillCharHdl));
    1830           0 :     m_pAutoRightCB->SetClickHdl(LINK(this, SwTOXEntryTabPage, AutoRightHdl));
    1831           0 :     m_pAuthInsertPB->SetClickHdl(LINK(this, SwTOXEntryTabPage, RemoveInsertAuthHdl));
    1832           0 :     m_pAuthRemovePB->SetClickHdl(LINK(this, SwTOXEntryTabPage, RemoveInsertAuthHdl));
    1833           0 :     m_pSortDocPosRB->SetClickHdl(LINK(this, SwTOXEntryTabPage, SortKeyHdl));
    1834           0 :     m_pSortContentRB->SetClickHdl(LINK(this, SwTOXEntryTabPage, SortKeyHdl));
    1835           0 :     m_pAllLevelsPB->SetClickHdl(LINK(this, SwTOXEntryTabPage, AllLevelsHdl));
    1836             : 
    1837           0 :     m_pAlphaDelimCB->SetClickHdl(LINK(this, SwTOXEntryTabPage, ModifyHdl));
    1838           0 :     m_pCommaSeparatedCB->SetClickHdl(LINK(this, SwTOXEntryTabPage, ModifyHdl));
    1839           0 :     m_pRelToStyleCB->SetClickHdl(LINK(this, SwTOXEntryTabPage, ModifyHdl));
    1840             : 
    1841           0 :     FieldUnit aMetric = ::GetDfltMetric(sal_False);
    1842           0 :     SetMetric(*m_pTabPosMF, aMetric);
    1843             : 
    1844           0 :     m_pSortDocPosRB->Check();
    1845             : 
    1846           0 :     m_pFillCharCB->SetMaxTextLen(1);
    1847           0 :     m_pFillCharCB->InsertEntry(OUString(' '));
    1848           0 :     m_pFillCharCB->InsertEntry(OUString('.'));
    1849           0 :     m_pFillCharCB->InsertEntry(OUString('-'));
    1850           0 :     m_pFillCharCB->InsertEntry(OUString('_'));
    1851             : 
    1852           0 :     m_pEditStylePB->Enable(false);
    1853             : 
    1854             :     //fill the types in
    1855           0 :     for (sal_uInt16 i = 0; i < AUTH_FIELD_END; ++i)
    1856             :     {
    1857           0 :         sal_Int32 nPos = m_pAuthFieldsLB->InsertEntry(SW_RESSTR(STR_AUTH_FIELD_START + i));
    1858           0 :         m_pAuthFieldsLB->SetEntryData(nPos, reinterpret_cast< void * >(sal::static_int_cast< sal_uIntPtr >(i)));
    1859             :     }
    1860           0 :     sal_Int32 nPos = m_pFirstKeyLB->InsertEntry(sNoCharSortKey);
    1861           0 :     m_pFirstKeyLB->SetEntryData(nPos, reinterpret_cast< void * >(sal::static_int_cast< sal_uIntPtr >(USHRT_MAX)));
    1862           0 :     nPos = m_pSecondKeyLB->InsertEntry(sNoCharSortKey);
    1863           0 :     m_pSecondKeyLB->SetEntryData(nPos, reinterpret_cast< void * >(sal::static_int_cast< sal_uIntPtr >(USHRT_MAX)));
    1864           0 :     nPos = m_pThirdKeyLB->InsertEntry(sNoCharSortKey);
    1865           0 :     m_pThirdKeyLB->SetEntryData(nPos, reinterpret_cast< void * >(sal::static_int_cast< sal_uIntPtr >(USHRT_MAX)));
    1866             : 
    1867           0 :     for (sal_uInt16 i = 0; i < AUTH_FIELD_END; ++i)
    1868             :     {
    1869           0 :         const OUString sTmp(m_pAuthFieldsLB->GetEntry(i));
    1870           0 :         void* pEntryData = m_pAuthFieldsLB->GetEntryData(i);
    1871           0 :         nPos = m_pFirstKeyLB->InsertEntry(sTmp);
    1872           0 :         m_pFirstKeyLB->SetEntryData(nPos, pEntryData);
    1873           0 :         nPos = m_pSecondKeyLB->InsertEntry(sTmp);
    1874           0 :         m_pSecondKeyLB->SetEntryData(nPos, pEntryData);
    1875           0 :         nPos = m_pThirdKeyLB->InsertEntry(sTmp);
    1876           0 :         m_pThirdKeyLB->SetEntryData(nPos, pEntryData);
    1877           0 :     }
    1878           0 :     m_pFirstKeyLB->SelectEntryPos(0);
    1879           0 :     m_pSecondKeyLB->SelectEntryPos(0);
    1880           0 :     m_pThirdKeyLB->SelectEntryPos(0);
    1881           0 : }
    1882             : // pVoid is used as signal to change all levels of the example
    1883           0 : IMPL_LINK(SwTOXEntryTabPage, ModifyHdl, void*, pVoid)
    1884             : {
    1885           0 :     UpdateDescriptor();
    1886             : 
    1887           0 :     SwMultiTOXTabDialog* pTOXDlg = (SwMultiTOXTabDialog*)GetTabDialog();
    1888           0 :     if (pTOXDlg)
    1889             :     {
    1890           0 :         sal_uInt16 nCurLevel = static_cast< sal_uInt16 >(m_pLevelLB->GetModel()->GetAbsPos(m_pLevelLB->FirstSelected()) + 1);
    1891           0 :         if(aLastTOXType.eType == TOX_CONTENT && pVoid)
    1892           0 :             nCurLevel = USHRT_MAX;
    1893             :         pTOXDlg->CreateOrUpdateExample(
    1894           0 :             pTOXDlg->GetCurrentTOXType().eType, TOX_PAGE_ENTRY, nCurLevel);
    1895             :     }
    1896           0 :     return 0;
    1897             : }
    1898             : 
    1899           0 : SwTOXEntryTabPage::~SwTOXEntryTabPage()
    1900             : {
    1901           0 : }
    1902             : 
    1903           0 : bool SwTOXEntryTabPage::FillItemSet( SfxItemSet& )
    1904             : {
    1905             :     // nothing to do
    1906           0 :     return true;
    1907             : }
    1908             : 
    1909           0 : void SwTOXEntryTabPage::Reset( const SfxItemSet& )
    1910             : {
    1911           0 :     SwMultiTOXTabDialog* pTOXDlg = (SwMultiTOXTabDialog*)GetTabDialog();
    1912           0 :     const CurTOXType aCurType = pTOXDlg->GetCurrentTOXType();
    1913           0 :     m_pCurrentForm = pTOXDlg->GetForm(aCurType);
    1914           0 :     if(TOX_INDEX == aCurType.eType)
    1915             :     {
    1916           0 :         SwTOXDescription& rDesc = pTOXDlg->GetTOXDescription(aCurType);
    1917           0 :         const OUString sMainEntryCharStyle = rDesc.GetMainEntryCharStyle();
    1918           0 :         if(!sMainEntryCharStyle.isEmpty())
    1919             :         {
    1920           0 :             if( LISTBOX_ENTRY_NOTFOUND ==
    1921           0 :                     m_pMainEntryStyleLB->GetEntryPos(sMainEntryCharStyle))
    1922             :                 m_pMainEntryStyleLB->InsertEntry(
    1923           0 :                         sMainEntryCharStyle);
    1924           0 :             m_pMainEntryStyleLB->SelectEntry(sMainEntryCharStyle);
    1925             :         }
    1926             :         else
    1927           0 :             m_pMainEntryStyleLB->SelectEntry(sNoCharStyle);
    1928           0 :         m_pAlphaDelimCB->Check( 0 != (rDesc.GetIndexOptions() & nsSwTOIOptions::TOI_ALPHA_DELIMITTER) );
    1929             :     }
    1930           0 :     m_pRelToStyleCB->Check(m_pCurrentForm->IsRelTabPos());
    1931           0 :     m_pCommaSeparatedCB->Check(m_pCurrentForm->IsCommaSeparated());
    1932           0 : }
    1933             : 
    1934           0 : void SwTOXEntryTabPage::ActivatePage( const SfxItemSet& /*rSet*/)
    1935             : {
    1936           0 :     SwMultiTOXTabDialog* pTOXDlg = (SwMultiTOXTabDialog*)GetTabDialog();
    1937           0 :     const CurTOXType aCurType = pTOXDlg->GetCurrentTOXType();
    1938             : 
    1939           0 :     m_pCurrentForm = pTOXDlg->GetForm(aCurType);
    1940           0 :     if( !( aLastTOXType == aCurType ))
    1941             :     {
    1942           0 :         sal_Bool bToxIsAuthorities = TOX_AUTHORITIES == aCurType.eType;
    1943           0 :         sal_Bool bToxIsIndex =       TOX_INDEX == aCurType.eType;
    1944           0 :         sal_Bool bToxIsContent =     TOX_CONTENT == aCurType.eType;
    1945           0 :         sal_Bool bToxIsSequence =    TOX_ILLUSTRATIONS == aCurType.eType;
    1946             : 
    1947           0 :         m_pLevelLB->Clear();
    1948           0 :         for(sal_uInt16 i = 1; i < m_pCurrentForm->GetFormMax(); i++)
    1949             :         {
    1950           0 :             if(bToxIsAuthorities)
    1951             :                 m_pLevelLB->InsertEntry( SwAuthorityFieldType::GetAuthTypeName(
    1952           0 :                                             (ToxAuthorityType) (i - 1)) );
    1953           0 :             else if( bToxIsIndex )
    1954             :             {
    1955           0 :                 if(i == 1)
    1956           0 :                     m_pLevelLB->InsertEntry( sDelimStr );
    1957             :                 else
    1958           0 :                     m_pLevelLB->InsertEntry( OUString::number(i - 1) );
    1959             :             }
    1960             :             else
    1961           0 :                 m_pLevelLB->InsertEntry(OUString::number(i));
    1962             :         }
    1963           0 :         if(bToxIsAuthorities)
    1964             :         {
    1965           0 :             SwWrtShell& rSh = pTOXDlg->GetWrtShell();
    1966             :             const SwAuthorityFieldType* pFType = (const SwAuthorityFieldType*)
    1967           0 :                                     rSh.GetFldType(RES_AUTHORITY, aEmptyOUStr);
    1968           0 :             if(pFType)
    1969             :             {
    1970           0 :                 if(pFType->IsSortByDocument())
    1971           0 :                     m_pSortDocPosRB->Check();
    1972             :                 else
    1973             :                 {
    1974           0 :                     m_pSortContentRB->Check();
    1975           0 :                     const sal_uInt16 nKeyCount = pFType->GetSortKeyCount();
    1976           0 :                     if(0 < nKeyCount)
    1977             :                     {
    1978           0 :                         const SwTOXSortKey* pKey = pFType->GetSortKey(0);
    1979             :                         m_pFirstKeyLB->SelectEntryPos(
    1980           0 :                             m_pFirstKeyLB->GetEntryPos((void*)(sal_uIntPtr)pKey->eField));
    1981           0 :                         m_pFirstSortUpRB->Check(pKey->bSortAscending);
    1982           0 :                         m_pFirstSortDownRB->Check(!pKey->bSortAscending);
    1983             :                     }
    1984           0 :                     if(1 < nKeyCount)
    1985             :                     {
    1986           0 :                         const SwTOXSortKey* pKey = pFType->GetSortKey(1);
    1987             :                         m_pSecondKeyLB->SelectEntryPos(
    1988           0 :                             m_pSecondKeyLB->GetEntryPos((void*)(sal_uIntPtr)pKey->eField));
    1989           0 :                         m_pSecondSortUpRB->Check(pKey->bSortAscending);
    1990           0 :                         m_pSecondSortDownRB->Check(!pKey->bSortAscending);
    1991             :                     }
    1992           0 :                     if(2 < nKeyCount)
    1993             :                     {
    1994           0 :                         const SwTOXSortKey* pKey = pFType->GetSortKey(2);
    1995             :                         m_pThirdKeyLB->SelectEntryPos(
    1996           0 :                             m_pThirdKeyLB->GetEntryPos((void*)(sal_uIntPtr)pKey->eField));
    1997           0 :                         m_pThirdSortUpRB->Check(pKey->bSortAscending);
    1998           0 :                         m_pThirdSortDownRB->Check(!pKey->bSortAscending);
    1999             :                     }
    2000             :                 }
    2001             :             }
    2002           0 :             SortKeyHdl(m_pSortDocPosRB->IsChecked() ? m_pSortDocPosRB : m_pSortContentRB);
    2003           0 :             m_pLevelFT->SetText(sAuthTypeStr);
    2004             :         }
    2005             :         else
    2006           0 :             m_pLevelFT->SetText(sLevelStr);
    2007             : 
    2008           0 :         Link aLink = m_pLevelLB->GetSelectHdl();
    2009           0 :         m_pLevelLB->SetSelectHdl(Link());
    2010           0 :         m_pLevelLB->Select( m_pLevelLB->GetEntry( bToxIsIndex ? 1 : 0 ) );
    2011           0 :         m_pLevelLB->SetSelectHdl(aLink);
    2012             : 
    2013             :         //show or hide controls
    2014           0 :         m_pEntryNoPB->Show(bToxIsContent);
    2015           0 :         m_pHyperLinkPB->Show(bToxIsContent || bToxIsSequence);
    2016           0 :         m_pRelToStyleCB->Show(!bToxIsAuthorities);
    2017           0 :         m_pChapterInfoPB->Show(!bToxIsContent && !bToxIsAuthorities);
    2018           0 :         m_pEntryPB->Show(!bToxIsAuthorities);
    2019           0 :         m_pPageNoPB->Show(!bToxIsAuthorities);
    2020           0 :         m_pAuthFieldsLB->Show(bToxIsAuthorities);
    2021           0 :         m_pAuthInsertPB->Show(bToxIsAuthorities);
    2022           0 :         m_pAuthRemovePB->Show(bToxIsAuthorities);
    2023             : 
    2024           0 :         m_pFormatFrame->Show(!bToxIsAuthorities);
    2025             : 
    2026           0 :         m_pSortingFrame->Show(bToxIsAuthorities);
    2027           0 :         m_pSortKeyFrame->Show(bToxIsAuthorities);
    2028             : 
    2029           0 :         m_pMainEntryStyleFT->Show(bToxIsIndex);
    2030           0 :         m_pMainEntryStyleLB->Show(bToxIsIndex);
    2031           0 :         m_pAlphaDelimCB->Show(bToxIsIndex);
    2032           0 :         m_pCommaSeparatedCB->Show(bToxIsIndex);
    2033             :     }
    2034           0 :     aLastTOXType = aCurType;
    2035             : 
    2036             :     //invalidate PatternWindow
    2037           0 :     m_pTokenWIN->SetInvalid();
    2038           0 :     LevelHdl(m_pLevelLB);
    2039           0 : }
    2040             : 
    2041           0 : void SwTOXEntryTabPage::UpdateDescriptor()
    2042             : {
    2043           0 :     WriteBackLevel();
    2044           0 :     SwMultiTOXTabDialog* pTOXDlg = (SwMultiTOXTabDialog*)GetTabDialog();
    2045           0 :     SwTOXDescription& rDesc = pTOXDlg->GetTOXDescription(aLastTOXType);
    2046           0 :     if(TOX_INDEX == aLastTOXType.eType)
    2047             :     {
    2048           0 :         const OUString sTemp(m_pMainEntryStyleLB->GetSelectEntry());
    2049           0 :         rDesc.SetMainEntryCharStyle(sNoCharStyle == sTemp ? aEmptyOUStr : sTemp);
    2050           0 :         sal_uInt16 nIdxOptions = rDesc.GetIndexOptions() & ~nsSwTOIOptions::TOI_ALPHA_DELIMITTER;
    2051           0 :         if(m_pAlphaDelimCB->IsChecked())
    2052           0 :             nIdxOptions |= nsSwTOIOptions::TOI_ALPHA_DELIMITTER;
    2053           0 :         rDesc.SetIndexOptions(nIdxOptions);
    2054             :     }
    2055           0 :     else if(TOX_AUTHORITIES == aLastTOXType.eType)
    2056             :     {
    2057           0 :         rDesc.SetSortByDocument(m_pSortDocPosRB->IsChecked());
    2058           0 :         SwTOXSortKey aKey1, aKey2, aKey3;
    2059             :         aKey1.eField = (ToxAuthorityField)(sal_uIntPtr)m_pFirstKeyLB->GetEntryData(
    2060           0 :                                     m_pFirstKeyLB->GetSelectEntryPos());
    2061           0 :         aKey1.bSortAscending = m_pFirstSortUpRB->IsChecked();
    2062             :         aKey2.eField = (ToxAuthorityField)(sal_uIntPtr)m_pSecondKeyLB->GetEntryData(
    2063           0 :                                     m_pSecondKeyLB->GetSelectEntryPos());
    2064           0 :         aKey2.bSortAscending = m_pSecondSortUpRB->IsChecked();
    2065             :         aKey3.eField = (ToxAuthorityField)(sal_uIntPtr)m_pThirdKeyLB->GetEntryData(
    2066           0 :                                 m_pThirdKeyLB->GetSelectEntryPos());
    2067           0 :         aKey3.bSortAscending = m_pThirdSortUpRB->IsChecked();
    2068             : 
    2069           0 :         rDesc.SetSortKeys(aKey1, aKey2, aKey3);
    2070             :     }
    2071           0 :     SwForm* pCurrentForm = pTOXDlg->GetForm(aLastTOXType);
    2072           0 :     if(m_pRelToStyleCB->IsVisible())
    2073             :     {
    2074           0 :         pCurrentForm->SetRelTabPos(m_pRelToStyleCB->IsChecked());
    2075             :     }
    2076           0 :     if(m_pCommaSeparatedCB->IsVisible())
    2077           0 :         pCurrentForm->SetCommaSeparated(m_pCommaSeparatedCB->IsChecked());
    2078           0 : }
    2079             : 
    2080           0 : int SwTOXEntryTabPage::DeactivatePage( SfxItemSet* /*pSet*/)
    2081             : {
    2082           0 :     UpdateDescriptor();
    2083           0 :     return LEAVE_PAGE;
    2084             : }
    2085             : 
    2086           0 : SfxTabPage* SwTOXEntryTabPage::Create( Window* pParent,     const SfxItemSet& rAttrSet)
    2087             : {
    2088           0 :     return new SwTOXEntryTabPage(pParent, rAttrSet);
    2089             : }
    2090             : 
    2091           0 : IMPL_LINK(SwTOXEntryTabPage, EditStyleHdl, PushButton*, pBtn)
    2092             : {
    2093           0 :     if( LISTBOX_ENTRY_NOTFOUND != m_pCharStyleLB->GetSelectEntryPos())
    2094             :     {
    2095           0 :         SfxStringItem aStyle(SID_STYLE_EDIT, m_pCharStyleLB->GetSelectEntry());
    2096           0 :         SfxUInt16Item aFamily(SID_STYLE_FAMILY, SFX_STYLE_FAMILY_CHAR);
    2097           0 :         Window* pDefDlgParent = Application::GetDefDialogParent();
    2098           0 :         Application::SetDefDialogParent( pBtn );
    2099           0 :         ((SwMultiTOXTabDialog*)GetTabDialog())->GetWrtShell().
    2100           0 :         GetView().GetViewFrame()->GetDispatcher()->Execute(
    2101             :         SID_STYLE_EDIT, SFX_CALLMODE_SYNCHRON|SFX_CALLMODE_MODAL,
    2102           0 :             &aStyle, &aFamily, 0L);
    2103           0 :         Application::SetDefDialogParent( pDefDlgParent );
    2104             :     }
    2105           0 :     return 0;
    2106             : }
    2107             : 
    2108           0 : IMPL_LINK(SwTOXEntryTabPage, RemoveInsertAuthHdl, PushButton*, pButton)
    2109             : {
    2110           0 :     bool bInsert = pButton == m_pAuthInsertPB;
    2111           0 :     if(bInsert)
    2112             :     {
    2113           0 :         sal_Int32 nSelPos = m_pAuthFieldsLB->GetSelectEntryPos();
    2114           0 :         const OUString sToInsert(m_pAuthFieldsLB->GetSelectEntry());
    2115           0 :         SwFormToken aInsert(TOKEN_AUTHORITY);
    2116           0 :         aInsert.nAuthorityField = (sal_uInt16)(sal_uIntPtr)m_pAuthFieldsLB->GetEntryData(nSelPos);
    2117           0 :         m_pTokenWIN->InsertAtSelection(SwForm::GetFormAuth(), aInsert);
    2118           0 :         m_pAuthFieldsLB->RemoveEntry(sToInsert);
    2119           0 :         m_pAuthFieldsLB->SelectEntryPos( nSelPos ? nSelPos - 1 : 0);
    2120             :     }
    2121             :     else
    2122             :     {
    2123           0 :         Control* pCtrl = m_pTokenWIN->GetActiveControl();
    2124             :         OSL_ENSURE(WINDOW_EDIT != pCtrl->GetType(), "Remove should be disabled");
    2125           0 :         if( WINDOW_EDIT != pCtrl->GetType() )
    2126             :         {
    2127             :             //fill it into the ListBox
    2128           0 :             const SwFormToken& rToken = ((SwTOXButton*)pCtrl)->GetFormToken();
    2129           0 :             PreTokenButtonRemoved(rToken);
    2130           0 :             m_pTokenWIN->RemoveControl((SwTOXButton*)pCtrl);
    2131             :         }
    2132             :     }
    2133           0 :     ModifyHdl(0);
    2134           0 :     return 0;
    2135             : }
    2136             : 
    2137           0 : void SwTOXEntryTabPage::PreTokenButtonRemoved(const SwFormToken& rToken)
    2138             : {
    2139             :     //fill it into the ListBox
    2140           0 :     sal_uInt32 nData = rToken.nAuthorityField;
    2141           0 :     sal_Int32 nPos = m_pAuthFieldsLB->InsertEntry(SW_RESSTR(STR_AUTH_FIELD_START + nData));
    2142           0 :     m_pAuthFieldsLB->SetEntryData(nPos, (void*)(sal_uIntPtr)(nData));
    2143           0 : }
    2144             : 
    2145           0 : void SwTOXEntryTabPage::SetFocus2theAllBtn()
    2146             : {
    2147           0 :     m_pAllLevelsPB->GrabFocus();
    2148           0 : }
    2149             : 
    2150           0 : bool SwTOXEntryTabPage::Notify( NotifyEvent& rNEvt )
    2151             : {
    2152           0 :     if ( rNEvt.GetType() == EVENT_KEYINPUT )
    2153             :     {
    2154           0 :         const KeyEvent& rKEvt = *rNEvt.GetKeyEvent();
    2155           0 :         KeyCode aCode = rKEvt.GetKeyCode();
    2156           0 :         if ( (aCode.GetCode() == KEY_F4) && aCode.IsShift() && !aCode.IsMod1() && !aCode.IsMod2() )
    2157             :         {
    2158           0 :             if ( m_pTokenWIN->GetActiveControl() )
    2159             :             {
    2160           0 :                 m_pTokenWIN->GetActiveControl()->GrabFocus();
    2161             :             }
    2162             :         }
    2163             : 
    2164             :     }
    2165             : 
    2166           0 :     return SfxTabPage::Notify( rNEvt );
    2167             : }
    2168             : 
    2169             : // This function initializes the default value in the Token
    2170             : // put here the UI dependent initializations
    2171           0 : IMPL_LINK(SwTOXEntryTabPage, InsertTokenHdl, PushButton*, pBtn)
    2172             : {
    2173           0 :     OUString sText;
    2174           0 :     FormTokenType eTokenType = TOKEN_ENTRY_NO;
    2175           0 :     OUString sCharStyle;
    2176           0 :     sal_uInt16  nChapterFormat = CF_NUMBER; // i89791
    2177           0 :     if(pBtn == m_pEntryNoPB)
    2178             :     {
    2179           0 :         sText = SwForm::GetFormEntryNum();
    2180           0 :         eTokenType = TOKEN_ENTRY_NO;
    2181             :     }
    2182           0 :     else if(pBtn == m_pEntryPB)
    2183             :     {
    2184           0 :         if( TOX_CONTENT == m_pCurrentForm->GetTOXType() )
    2185             :         {
    2186           0 :             sText = SwForm::GetFormEntryTxt();
    2187           0 :             eTokenType = TOKEN_ENTRY_TEXT;
    2188             :         }
    2189             :         else
    2190             :         {
    2191           0 :             sText = SwForm::GetFormEntry();
    2192           0 :             eTokenType = TOKEN_ENTRY;
    2193             :         }
    2194             :     }
    2195           0 :     else if(pBtn == m_pChapterInfoPB)
    2196             :     {
    2197           0 :         sText = SwForm::GetFormChapterMark();
    2198           0 :         eTokenType = TOKEN_CHAPTER_INFO;
    2199           0 :         nChapterFormat = CF_NUM_NOPREPST_TITLE; // i89791
    2200             :     }
    2201           0 :     else if(pBtn == m_pPageNoPB)
    2202             :     {
    2203           0 :         sText = SwForm::GetFormPageNums();
    2204           0 :         eTokenType = TOKEN_PAGE_NUMS;
    2205             :     }
    2206           0 :     else if(pBtn == m_pHyperLinkPB)
    2207             :     {
    2208           0 :         sText = SwForm::GetFormLinkStt();
    2209           0 :         eTokenType = TOKEN_LINK_START;
    2210           0 :         sCharStyle = SW_RES(STR_POOLCHR_TOXJUMP);
    2211             :     }
    2212           0 :     else if(pBtn == m_pTabPB)
    2213             :     {
    2214           0 :         sText = SwForm::GetFormTab();
    2215           0 :         eTokenType = TOKEN_TAB_STOP;
    2216             :     }
    2217           0 :     SwFormToken aInsert(eTokenType);
    2218           0 :     aInsert.sCharStyleName = sCharStyle;
    2219           0 :     aInsert.nTabStopPosition = 0;
    2220           0 :     aInsert.nChapterFormat = nChapterFormat; // i89791
    2221           0 :     m_pTokenWIN->InsertAtSelection(sText, aInsert);
    2222           0 :     ModifyHdl(0);
    2223           0 :     return 0;
    2224             : }
    2225             : 
    2226           0 : IMPL_LINK_NOARG(SwTOXEntryTabPage, AllLevelsHdl)
    2227             : {
    2228             :     //get current level
    2229             :     //write it into all levels
    2230           0 :     if(m_pTokenWIN->IsValid())
    2231             :     {
    2232           0 :         const OUString sNewToken = m_pTokenWIN->GetPattern();
    2233           0 :         for(sal_uInt16 i = 1; i < m_pCurrentForm->GetFormMax(); i++)
    2234           0 :             m_pCurrentForm->SetPattern(i, sNewToken);
    2235             : 
    2236           0 :         ModifyHdl(this);
    2237             :     }
    2238           0 :     return 0;
    2239             : }
    2240             : 
    2241           0 : void SwTOXEntryTabPage::WriteBackLevel()
    2242             : {
    2243           0 :     if(m_pTokenWIN->IsValid())
    2244             :     {
    2245           0 :         const OUString sNewToken = m_pTokenWIN->GetPattern();
    2246           0 :         const sal_uInt16 nLastLevel = m_pTokenWIN->GetLastLevel();
    2247           0 :         if(nLastLevel != USHRT_MAX)
    2248           0 :             m_pCurrentForm->SetPattern(nLastLevel + 1, sNewToken);
    2249             :     }
    2250           0 : }
    2251             : 
    2252           0 : IMPL_LINK(SwTOXEntryTabPage, LevelHdl, SvTreeListBox*, pBox)
    2253             : {
    2254           0 :     if(bInLevelHdl)
    2255           0 :         return 0;
    2256           0 :     bInLevelHdl = true;
    2257           0 :     WriteBackLevel();
    2258             : 
    2259             :     const sal_uInt16 nLevel = static_cast< sal_uInt16 >(
    2260           0 :         pBox->GetModel()->GetAbsPos(pBox->FirstSelected()));
    2261           0 :     m_pTokenWIN->SetForm(*m_pCurrentForm, nLevel);
    2262           0 :     if(TOX_AUTHORITIES == m_pCurrentForm->GetTOXType())
    2263             :     {
    2264             :         //fill the types in
    2265           0 :         m_pAuthFieldsLB->Clear();
    2266           0 :         for( sal_uInt32 i = 0; i < AUTH_FIELD_END; i++)
    2267             :         {
    2268           0 :             sal_Int32 nPos = m_pAuthFieldsLB->InsertEntry(SW_RESSTR(STR_AUTH_FIELD_START + i));
    2269           0 :             m_pAuthFieldsLB->SetEntryData(nPos, (void*)(sal_uIntPtr)(i));
    2270             :         }
    2271             : 
    2272             :         // #i21237#
    2273           0 :         SwFormTokens aPattern = m_pCurrentForm->GetPattern(nLevel + 1);
    2274           0 :         SwFormTokens::iterator aIt = aPattern.begin();
    2275             : 
    2276           0 :         while(aIt != aPattern.end())
    2277             :         {
    2278           0 :             SwFormToken aToken = *aIt; // #i21237#
    2279           0 :             if(TOKEN_AUTHORITY == aToken.eTokenType)
    2280             :             {
    2281           0 :                 sal_uInt32 nSearch = aToken.nAuthorityField;
    2282           0 :                 sal_Int32  nLstBoxPos = m_pAuthFieldsLB->GetEntryPos( (void*)(sal_uIntPtr)nSearch );
    2283             :                 OSL_ENSURE(LISTBOX_ENTRY_NOTFOUND != nLstBoxPos, "Entry not found?");
    2284           0 :                 m_pAuthFieldsLB->RemoveEntry(nLstBoxPos);
    2285             :             }
    2286             : 
    2287           0 :             aIt++; // #i21237#
    2288           0 :         }
    2289           0 :         m_pAuthFieldsLB->SelectEntryPos(0);
    2290             :     }
    2291           0 :     bInLevelHdl = false;
    2292           0 :     pBox->GrabFocus();
    2293           0 :     return 0;
    2294             : }
    2295             : 
    2296           0 : IMPL_LINK(SwTOXEntryTabPage, SortKeyHdl, RadioButton*, pButton)
    2297             : {
    2298           0 :     bool bEnable = m_pSortContentRB == pButton;
    2299           0 :     m_pSortKeyFrame->Enable(bEnable);
    2300           0 :     return 0;
    2301             : }
    2302             : 
    2303           0 : IMPL_LINK(SwTOXEntryTabPage, TokenSelectedHdl, SwFormToken*, pToken)
    2304             : {
    2305           0 :     if (!pToken->sCharStyleName.isEmpty())
    2306           0 :         m_pCharStyleLB->SelectEntry(pToken->sCharStyleName);
    2307             :     else
    2308           0 :         m_pCharStyleLB->SelectEntry(sNoCharStyle);
    2309             : 
    2310           0 :     const OUString sEntry = m_pCharStyleLB->GetSelectEntry();
    2311           0 :     m_pEditStylePB->Enable(sEntry != sNoCharStyle);
    2312             : 
    2313           0 :     if(pToken->eTokenType == TOKEN_CHAPTER_INFO)
    2314             :     {
    2315             : //---> i89791
    2316           0 :         switch(pToken->nChapterFormat)
    2317             :         {
    2318             :         default:
    2319           0 :             m_pChapterEntryLB->SetNoSelection();//to alert the user
    2320           0 :             break;
    2321             :         case CF_NUM_NOPREPST_TITLE:
    2322           0 :             m_pChapterEntryLB->SelectEntryPos(0);
    2323           0 :             break;
    2324             :         case CF_TITLE:
    2325           0 :             m_pChapterEntryLB->SelectEntryPos(1);
    2326           0 :            break;
    2327             :         case CF_NUMBER_NOPREPST:
    2328           0 :             m_pChapterEntryLB->SelectEntryPos(2);
    2329           0 :             break;
    2330             :         }
    2331             : //i53420
    2332             : 
    2333           0 :         m_pEntryOutlineLevelNF->SetValue(pToken->nOutlineLevel);
    2334             :     }
    2335             : 
    2336             : //i53420
    2337           0 :     if(pToken->eTokenType == TOKEN_ENTRY_NO)
    2338             :     {
    2339           0 :         m_pEntryOutlineLevelNF->SetValue(pToken->nOutlineLevel);
    2340             :         const sal_uInt16 nFormat =
    2341           0 :             pToken->nChapterFormat == CF_NUM_NOPREPST_TITLE ? 1 : 0;
    2342           0 :         m_pNumberFormatLB->SelectEntryPos(nFormat);
    2343             :     }
    2344             : 
    2345           0 :     sal_Bool bTabStop = TOKEN_TAB_STOP == pToken->eTokenType;
    2346           0 :     m_pFillCharFT->Show(bTabStop);
    2347           0 :     m_pFillCharCB->Show(bTabStop);
    2348           0 :     m_pTabPosFT->Show(bTabStop);
    2349           0 :     m_pTabPosMF->Show(bTabStop);
    2350           0 :     m_pAutoRightCB->Show(bTabStop);
    2351           0 :     m_pAutoRightCB->Enable(bTabStop);
    2352           0 :     if(bTabStop)
    2353             :     {
    2354           0 :         m_pTabPosMF->SetValue(m_pTabPosMF->Normalize(pToken->nTabStopPosition), FUNIT_TWIP);
    2355           0 :         m_pAutoRightCB->Check(SVX_TAB_ADJUST_END == pToken->eTabAlign);
    2356           0 :         m_pFillCharCB->SetText(OUString(pToken->cTabFillChar));
    2357           0 :         m_pTabPosFT->Enable(!m_pAutoRightCB->IsChecked());
    2358           0 :         m_pTabPosMF->Enable(!m_pAutoRightCB->IsChecked());
    2359             :     }
    2360             :     else
    2361             :     {
    2362           0 :         m_pTabPosMF->Enable(false);
    2363             :     }
    2364             : 
    2365           0 :     sal_Bool bIsChapterInfo = pToken->eTokenType == TOKEN_CHAPTER_INFO;
    2366           0 :     sal_Bool bIsEntryNumber = pToken->eTokenType == TOKEN_ENTRY_NO;
    2367           0 :     m_pChapterEntryFT->Show( bIsChapterInfo );
    2368           0 :     m_pChapterEntryLB->Show( bIsChapterInfo );
    2369           0 :     m_pEntryOutlineLevelFT->Show( bIsChapterInfo || bIsEntryNumber );
    2370           0 :     m_pEntryOutlineLevelNF->Show( bIsChapterInfo || bIsEntryNumber );
    2371           0 :     m_pNumberFormatFT->Show( bIsEntryNumber );
    2372           0 :     m_pNumberFormatLB->Show( bIsEntryNumber );
    2373             : 
    2374             :     //now enable the visible buttons
    2375             :     //- inserting the same type of control is not allowed
    2376             :     //- some types of controls can only appear once (EntryText EntryNumber)
    2377             : 
    2378           0 :     if(m_pEntryNoPB->IsVisible())
    2379             :     {
    2380           0 :         m_pEntryNoPB->Enable(TOKEN_ENTRY_NO != pToken->eTokenType );
    2381             :     }
    2382           0 :     if(m_pEntryPB->IsVisible())
    2383             :     {
    2384           0 :         m_pEntryPB->Enable(TOKEN_ENTRY_TEXT != pToken->eTokenType &&
    2385           0 :                                 !m_pTokenWIN->Contains(TOKEN_ENTRY_TEXT)
    2386           0 :                                 && !m_pTokenWIN->Contains(TOKEN_ENTRY));
    2387             :     }
    2388             : 
    2389           0 :     if(m_pChapterInfoPB->IsVisible())
    2390             :     {
    2391           0 :         m_pChapterInfoPB->Enable(TOKEN_CHAPTER_INFO != pToken->eTokenType);
    2392             :     }
    2393           0 :     if(m_pPageNoPB->IsVisible())
    2394             :     {
    2395           0 :         m_pPageNoPB->Enable(TOKEN_PAGE_NUMS != pToken->eTokenType &&
    2396           0 :                                 !m_pTokenWIN->Contains(TOKEN_PAGE_NUMS));
    2397             :     }
    2398           0 :     if(m_pTabPB->IsVisible())
    2399             :     {
    2400           0 :         m_pTabPB->Enable(!bTabStop);
    2401             :     }
    2402           0 :     if(m_pHyperLinkPB->IsVisible())
    2403             :     {
    2404           0 :         m_pHyperLinkPB->Enable(TOKEN_LINK_START != pToken->eTokenType &&
    2405           0 :                             TOKEN_LINK_END != pToken->eTokenType);
    2406             :     }
    2407             :     //table of authorities
    2408           0 :     if(m_pAuthInsertPB->IsVisible())
    2409             :     {
    2410           0 :         bool bText = TOKEN_TEXT == pToken->eTokenType;
    2411           0 :         m_pAuthInsertPB->Enable(bText && !m_pAuthFieldsLB->GetSelectEntry().isEmpty());
    2412           0 :         m_pAuthRemovePB->Enable(!bText);
    2413             :     }
    2414             : 
    2415           0 :     return 0;
    2416             : }
    2417             : 
    2418           0 : IMPL_LINK(SwTOXEntryTabPage, StyleSelectHdl, ListBox*, pBox)
    2419             : {
    2420           0 :     OUString sEntry = pBox->GetSelectEntry();
    2421           0 :     const sal_uInt16 nId = (sal_uInt16)(sal_IntPtr)pBox->GetEntryData(pBox->GetSelectEntryPos());
    2422           0 :     const bool bEqualsNoCharStyle = sEntry == sNoCharStyle;
    2423           0 :     m_pEditStylePB->Enable(!bEqualsNoCharStyle);
    2424           0 :     if (bEqualsNoCharStyle)
    2425           0 :         sEntry = "";
    2426           0 :     Control* pCtrl = m_pTokenWIN->GetActiveControl();
    2427             :     OSL_ENSURE(pCtrl, "no active control?");
    2428           0 :     if(pCtrl)
    2429             :     {
    2430           0 :         if(WINDOW_EDIT == pCtrl->GetType())
    2431           0 :             ((SwTOXEdit*)pCtrl)->SetCharStyleName(sEntry, nId);
    2432             :         else
    2433           0 :             ((SwTOXButton*)pCtrl)->SetCharStyleName(sEntry, nId);
    2434             : 
    2435             :     }
    2436           0 :     ModifyHdl(0);
    2437           0 :     return 0;
    2438             : }
    2439             : 
    2440           0 : IMPL_LINK(SwTOXEntryTabPage, ChapterInfoHdl, ListBox*, pBox)
    2441             : {
    2442           0 :     sal_Int32 nPos = pBox->GetSelectEntryPos();
    2443           0 :     if(LISTBOX_ENTRY_NOTFOUND != nPos)
    2444             :     {
    2445           0 :         Control* pCtrl = m_pTokenWIN->GetActiveControl();
    2446             :         OSL_ENSURE(pCtrl, "no active control?");
    2447           0 :         if(pCtrl && WINDOW_EDIT != pCtrl->GetType())
    2448           0 :             ((SwTOXButton*)pCtrl)->SetChapterInfo(nPos);
    2449             : 
    2450           0 :         ModifyHdl(0);
    2451             :     }
    2452           0 :     return 0;
    2453             : }
    2454             : 
    2455           0 : IMPL_LINK(SwTOXEntryTabPage, ChapterInfoOutlineHdl, NumericField*, pField)
    2456             : {
    2457           0 :     const sal_uInt16 nLevel = static_cast<sal_uInt8>(pField->GetValue());
    2458             : 
    2459           0 :     Control* pCtrl = m_pTokenWIN->GetActiveControl();
    2460             :     OSL_ENSURE(pCtrl, "no active control?");
    2461           0 :     if(pCtrl && WINDOW_EDIT != pCtrl->GetType())
    2462           0 :         ((SwTOXButton*)pCtrl)->SetOutlineLevel(nLevel);
    2463             : 
    2464           0 :     ModifyHdl(0);
    2465           0 :     return 0;
    2466             : }
    2467             : 
    2468           0 : IMPL_LINK(SwTOXEntryTabPage, NumberFormatHdl, ListBox*, pBox)
    2469             : {
    2470           0 :     const sal_Int32 nPos = pBox->GetSelectEntryPos();
    2471             : 
    2472           0 :     if(LISTBOX_ENTRY_NOTFOUND != nPos)
    2473             :     {
    2474           0 :         Control* pCtrl = m_pTokenWIN->GetActiveControl();
    2475             :         OSL_ENSURE(pCtrl, "no active control?");
    2476           0 :         if(pCtrl && WINDOW_EDIT != pCtrl->GetType())
    2477             :         {
    2478           0 :            ((SwTOXButton*)pCtrl)->SetEntryNumberFormat(nPos);//i89791
    2479             :         }
    2480           0 :         ModifyHdl(0);
    2481             :     }
    2482           0 :     return 0;
    2483             : }
    2484             : 
    2485           0 : IMPL_LINK(SwTOXEntryTabPage, TabPosHdl, MetricField*, pField)
    2486             : {
    2487           0 :     Control* pCtrl = m_pTokenWIN->GetActiveControl();
    2488             :     OSL_ENSURE(pCtrl && WINDOW_EDIT != pCtrl->GetType() &&
    2489             :         TOKEN_TAB_STOP == ((SwTOXButton*)pCtrl)->GetFormToken().eTokenType,
    2490             :                 "no active style::TabStop control?");
    2491           0 :     if( pCtrl && WINDOW_EDIT != pCtrl->GetType() )
    2492             :     {
    2493             :         ((SwTOXButton*)pCtrl)->SetTabPosition( static_cast< SwTwips >(
    2494           0 :                 pField->Denormalize( pField->GetValue( FUNIT_TWIP ))));
    2495             :     }
    2496           0 :     ModifyHdl(0);
    2497           0 :     return 0;
    2498             : }
    2499             : 
    2500           0 : IMPL_LINK(SwTOXEntryTabPage, FillCharHdl, ComboBox*, pBox)
    2501             : {
    2502           0 :     Control* pCtrl = m_pTokenWIN->GetActiveControl();
    2503             :     OSL_ENSURE(pCtrl && WINDOW_EDIT != pCtrl->GetType() &&
    2504             :         TOKEN_TAB_STOP == ((SwTOXButton*)pCtrl)->GetFormToken().eTokenType,
    2505             :                 "no active style::TabStop control?");
    2506           0 :     if(pCtrl && WINDOW_EDIT != pCtrl->GetType())
    2507             :     {
    2508             :         sal_Unicode cSet;
    2509           0 :         if( !pBox->GetText().isEmpty() )
    2510           0 :             cSet = pBox->GetText()[0];
    2511             :         else
    2512           0 :             cSet = ' ';
    2513           0 :         ((SwTOXButton*)pCtrl)->SetFillChar( cSet );
    2514             :     }
    2515           0 :     ModifyHdl(0);
    2516           0 :     return 0;
    2517             : }
    2518             : 
    2519           0 : IMPL_LINK(SwTOXEntryTabPage, AutoRightHdl, CheckBox*, pBox)
    2520             : {
    2521             :     //the most right style::TabStop is usually right aligned
    2522           0 :     Control* pCurCtrl = m_pTokenWIN->GetActiveControl();
    2523             :     OSL_ENSURE(WINDOW_EDIT != pCurCtrl->GetType() &&
    2524             :             ((SwTOXButton*)pCurCtrl)->GetFormToken().eTokenType == TOKEN_TAB_STOP,
    2525             :             "no style::TabStop selected!");
    2526             : 
    2527           0 :     const SwFormToken& rToken = ((SwTOXButton*)pCurCtrl)->GetFormToken();
    2528           0 :     sal_Bool bChecked = pBox->IsChecked();
    2529           0 :     if(rToken.eTokenType == TOKEN_TAB_STOP)
    2530             :         ((SwTOXButton*)pCurCtrl)->SetTabAlign(
    2531           0 :             bChecked ? SVX_TAB_ADJUST_END : SVX_TAB_ADJUST_LEFT);
    2532           0 :     m_pTabPosFT->Enable(!bChecked);
    2533           0 :     m_pTabPosMF->Enable(!bChecked);
    2534           0 :     ModifyHdl(0);
    2535           0 :     return 0;
    2536             : }
    2537             : 
    2538           0 : void SwTOXEntryTabPage::SetWrtShell(SwWrtShell& rSh)
    2539             : {
    2540           0 :     SwDocShell* pDocSh = rSh.GetView().GetDocShell();
    2541           0 :     ::FillCharStyleListBox(*m_pCharStyleLB, pDocSh, true, true);
    2542           0 :     const OUString sDefault(SW_RES(STR_POOLCOLL_STANDARD));
    2543           0 :     for(sal_Int32 i = 0; i < m_pCharStyleLB->GetEntryCount(); i++)
    2544             :     {
    2545           0 :         const OUString sEntry = m_pCharStyleLB->GetEntry(i);
    2546           0 :         if(sDefault != sEntry)
    2547             :         {
    2548           0 :             m_pMainEntryStyleLB->InsertEntry( sEntry );
    2549           0 :             m_pMainEntryStyleLB->SetEntryData(i, m_pCharStyleLB->GetEntryData(i));
    2550             :         }
    2551           0 :     }
    2552             :     m_pMainEntryStyleLB->SelectEntry( SwStyleNameMapper::GetUIName(
    2553           0 :                                 RES_POOLCHR_IDX_MAIN_ENTRY, aEmptyOUStr ));
    2554           0 : }
    2555             : 
    2556           0 : OUString SwTOXEntryTabPage::GetLevelHelp(sal_uInt16 nLevel) const
    2557             : {
    2558           0 :     OUString sRet;
    2559           0 :     SwMultiTOXTabDialog* pTOXDlg = (SwMultiTOXTabDialog*)GetTabDialog();
    2560           0 :     const CurTOXType aCurType = pTOXDlg->GetCurrentTOXType();
    2561           0 :     if( TOX_INDEX == aCurType.eType )
    2562             :         SwStyleNameMapper::FillUIName( static_cast< sal_uInt16 >(1 == nLevel ? RES_POOLCOLL_TOX_IDXBREAK
    2563           0 :                                   : RES_POOLCOLL_TOX_IDX1 + nLevel-2), sRet );
    2564             : 
    2565           0 :     else if( TOX_AUTHORITIES == aCurType.eType )
    2566             :     {
    2567             :         //wildcard -> show entry text
    2568           0 :         sRet = "*";
    2569             :     }
    2570           0 :     return sRet;
    2571             : }
    2572             : 
    2573           0 : SwTokenWindow::SwTokenWindow(Window* pParent)
    2574             :     : VclHBox(pParent)
    2575             :     , pForm(0)
    2576             :     , nLevel(0)
    2577             :     , bValid(false)
    2578             :     , sCharStyle(SW_RESSTR(STR_CHARSTYLE))
    2579             :     , pActiveCtrl(0)
    2580           0 :     , m_pParent(NULL)
    2581             : {
    2582             :     m_pUIBuilder = new VclBuilder(this, getUIRootDir(),
    2583           0 :         "modules/swriter/ui/tokenwidget.ui", "TokenWidget");
    2584           0 :     get(m_pLeftScrollWin, "left");
    2585           0 :     get(m_pCtrlParentWin, "ctrl");
    2586           0 :     m_pCtrlParentWin->set_height_request(Edit::GetMinimumEditSize().Height());
    2587           0 :     get(m_pRightScrollWin, "right");
    2588             : 
    2589           0 :     for (sal_uInt32 i = 0; i < TOKEN_END; ++i)
    2590             :     {
    2591           0 :         sal_uInt32 nTextId = STR_BUTTON_TEXT_START + i;
    2592           0 :         if( STR_TOKEN_ENTRY_TEXT == nTextId )
    2593           0 :             nTextId = STR_TOKEN_ENTRY;
    2594           0 :         aButtonTexts[i] = SW_RESSTR(nTextId);
    2595             : 
    2596           0 :         sal_uInt32 nHelpId = STR_BUTTON_HELP_TEXT_START + i;
    2597           0 :         if(STR_TOKEN_HELP_ENTRY_TEXT == nHelpId)
    2598           0 :             nHelpId = STR_TOKEN_HELP_ENTRY;
    2599           0 :         aButtonHelpTexts[i] = SW_RESSTR(nHelpId);
    2600             :     }
    2601             : 
    2602           0 :     accessibleName = SW_RESSTR(STR_STRUCTURE);
    2603           0 :     sAdditionalAccnameString1 = SW_RESSTR(STR_ADDITIONAL_ACCNAME_STRING1);
    2604           0 :     sAdditionalAccnameString2 = SW_RESSTR(STR_ADDITIONAL_ACCNAME_STRING2);
    2605           0 :     sAdditionalAccnameString3 = SW_RESSTR(STR_ADDITIONAL_ACCNAME_STRING3);
    2606             : 
    2607           0 :     Link aLink(LINK(this, SwTokenWindow, ScrollHdl));
    2608           0 :     m_pLeftScrollWin->SetClickHdl(aLink);
    2609           0 :     m_pRightScrollWin->SetClickHdl(aLink);
    2610           0 : }
    2611             : 
    2612           0 : extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeSwTokenWindow(Window *pParent, VclBuilder::stringmap &)
    2613             : {
    2614           0 :     return new SwTokenWindow(pParent);
    2615             : }
    2616             : 
    2617           0 : void SwTokenWindow::setAllocation(const Size &rAllocation)
    2618             : {
    2619           0 :     VclHBox::setAllocation(rAllocation);
    2620             : 
    2621           0 :     if (aControlList.empty())
    2622           0 :         return;
    2623             : 
    2624           0 :     Size aControlSize(m_pCtrlParentWin->GetSizePixel());
    2625           0 :     for (ctrl_iterator it = aControlList.begin(); it != aControlList.end(); ++it)
    2626             :     {
    2627           0 :         Control* pControl = (*it);
    2628           0 :         Size aSize(pControl->GetSizePixel());
    2629           0 :         aSize.Height() = aControlSize.Height();
    2630           0 :         pControl->SetSizePixel(aSize);
    2631             :     }
    2632             : }
    2633             : 
    2634           0 : SwTokenWindow::~SwTokenWindow()
    2635             : {
    2636           0 :     for (ctrl_iterator it = aControlList.begin(); it != aControlList.end(); ++it)
    2637             :     {
    2638           0 :         Control* pControl = (*it);
    2639           0 :         pControl->SetGetFocusHdl( Link() );
    2640           0 :         pControl->SetLoseFocusHdl( Link() );
    2641           0 :         delete pControl;
    2642             :     }
    2643           0 : }
    2644             : 
    2645           0 : void SwTokenWindow::SetForm(SwForm& rForm, sal_uInt16 nL)
    2646             : {
    2647           0 :     SetActiveControl(0);
    2648           0 :     bValid = true;
    2649             : 
    2650           0 :     if(pForm)
    2651             :     {
    2652             :         //apply current level settings to the form
    2653           0 :         for (ctrl_iterator iter = aControlList.begin(); iter != aControlList.end(); ++iter)
    2654           0 :             delete (*iter);
    2655             : 
    2656           0 :         aControlList.clear();
    2657             :     }
    2658             : 
    2659           0 :     nLevel = nL;
    2660           0 :     pForm = &rForm;
    2661             :     //now the display
    2662           0 :     if(nLevel < MAXLEVEL || rForm.GetTOXType() == TOX_AUTHORITIES)
    2663             :     {
    2664             :         // #i21237#
    2665           0 :         SwFormTokens aPattern = pForm->GetPattern(nLevel + 1);
    2666           0 :         SwFormTokens::iterator aIt = aPattern.begin();
    2667           0 :         bool bLastWasText = false; //assure alternating text - code - text
    2668             : 
    2669           0 :         Control* pSetActiveControl = 0;
    2670           0 :         while(aIt != aPattern.end()) // #i21237#
    2671             :         {
    2672           0 :             SwFormToken aToken(*aIt); // #i21237#
    2673             : 
    2674           0 :             if(TOKEN_TEXT == aToken.eTokenType)
    2675             :             {
    2676             :                 OSL_ENSURE(!bLastWasText, "text following text is invalid");
    2677           0 :                 Control* pCtrl = InsertItem(aToken.sText, aToken);
    2678           0 :                 bLastWasText = true;
    2679           0 :                 if(!GetActiveControl())
    2680           0 :                     SetActiveControl(pCtrl);
    2681             :             }
    2682             :             else
    2683             :             {
    2684           0 :                 if( !bLastWasText )
    2685             :                 {
    2686           0 :                     bLastWasText = true;
    2687           0 :                     SwFormToken aTemp(TOKEN_TEXT);
    2688           0 :                     Control* pCtrl = InsertItem(aEmptyOUStr, aTemp);
    2689           0 :                     if(!pSetActiveControl)
    2690           0 :                         pSetActiveControl = pCtrl;
    2691             :                 }
    2692             : 
    2693           0 :                 OUString sForm;
    2694           0 :                 switch( aToken.eTokenType )
    2695             :                 {
    2696           0 :                 case TOKEN_ENTRY_NO:     sForm = SwForm::GetFormEntryNum(); break;
    2697           0 :                 case TOKEN_ENTRY_TEXT:   sForm = SwForm::GetFormEntryTxt(); break;
    2698           0 :                 case TOKEN_ENTRY:        sForm = SwForm::GetFormEntry(); break;
    2699           0 :                 case TOKEN_TAB_STOP:     sForm = SwForm::GetFormTab(); break;
    2700           0 :                 case TOKEN_PAGE_NUMS:    sForm = SwForm::GetFormPageNums(); break;
    2701           0 :                 case TOKEN_CHAPTER_INFO: sForm = SwForm::GetFormChapterMark(); break;
    2702           0 :                 case TOKEN_LINK_START:   sForm = SwForm::GetFormLinkStt(); break;
    2703           0 :                 case TOKEN_LINK_END:     sForm = SwForm::GetFormLinkEnd(); break;
    2704           0 :                 case TOKEN_AUTHORITY:    sForm = SwForm::GetFormAuth(); break;
    2705             :                 default:; //prevent warning
    2706             :                 }
    2707             : 
    2708           0 :                 InsertItem( sForm, aToken );
    2709           0 :                 bLastWasText = false;
    2710             :             }
    2711             : 
    2712           0 :             ++aIt; // #i21237#
    2713           0 :         }
    2714           0 :         if(!bLastWasText)
    2715             :         {
    2716           0 :             bLastWasText = true;
    2717           0 :             SwFormToken aTemp(TOKEN_TEXT);
    2718           0 :             Control* pCtrl = InsertItem(aEmptyOUStr, aTemp);
    2719           0 :             if(!pSetActiveControl)
    2720           0 :                 pSetActiveControl = pCtrl;
    2721             :         }
    2722           0 :         SetActiveControl(pSetActiveControl);
    2723             :     }
    2724           0 :     AdjustScrolling();
    2725           0 : }
    2726             : 
    2727           0 : void SwTokenWindow::SetActiveControl(Control* pSet)
    2728             : {
    2729           0 :     if( pSet != pActiveCtrl )
    2730             :     {
    2731           0 :         pActiveCtrl = pSet;
    2732           0 :         if( pActiveCtrl )
    2733             :         {
    2734           0 :             pActiveCtrl->GrabFocus();
    2735             :             //it must be a SwTOXEdit
    2736             :             const SwFormToken* pFToken;
    2737           0 :             if( WINDOW_EDIT == pActiveCtrl->GetType() )
    2738           0 :                 pFToken = &((SwTOXEdit*)pActiveCtrl)->GetFormToken();
    2739             :             else
    2740           0 :                 pFToken = &((SwTOXButton*)pActiveCtrl)->GetFormToken();
    2741             : 
    2742           0 :             SwFormToken aTemp( *pFToken );
    2743           0 :             aButtonSelectedHdl.Call( &aTemp );
    2744             :         }
    2745             :     }
    2746           0 : }
    2747             : 
    2748           0 : Control*    SwTokenWindow::InsertItem(const OUString& rText, const SwFormToken& rToken)
    2749             : {
    2750           0 :     Control* pRet = 0;
    2751           0 :     Size aControlSize(m_pCtrlParentWin->GetSizePixel());
    2752           0 :     Point aControlPos;
    2753             : 
    2754           0 :     if(!aControlList.empty())
    2755             :     {
    2756           0 :         Control* pLast = *(aControlList.rbegin());
    2757             : 
    2758           0 :         aControlSize = pLast->GetSizePixel();
    2759           0 :         aControlPos = pLast->GetPosPixel();
    2760           0 :         aControlPos.X() += aControlSize.Width();
    2761             :     }
    2762             : 
    2763           0 :     if(TOKEN_TEXT == rToken.eTokenType)
    2764             :     {
    2765           0 :         SwTOXEdit* pEdit = new SwTOXEdit(m_pCtrlParentWin, this, rToken);
    2766           0 :         pEdit->SetPosPixel(aControlPos);
    2767             : 
    2768           0 :         aControlList.push_back(pEdit);
    2769             : 
    2770           0 :         pEdit->SetText(rText);
    2771           0 :         sal_uInt32 nIndex = GetControlIndex( TOKEN_TEXT );
    2772           0 :         OUString strName(accessibleName + OUString::number(nIndex));
    2773           0 :         if ( nIndex == 1 )
    2774             :         {
    2775             :             /*Press left or right arrow to choose the structure controls*/
    2776           0 :             strName += " (" + sAdditionalAccnameString2 + ", "
    2777             :             /*Press Ctrl+Alt+A to move focus for more operations*/
    2778           0 :                      + sAdditionalAccnameString1 + ", "
    2779             :             /*Press Ctrl+Alt+B to move focus back to the current structure control*/
    2780           0 :                      + sAdditionalAccnameString3 + ")";
    2781             :         }
    2782           0 :         pEdit->SetAccessibleName(strName);
    2783           0 :         Size aEditSize(aControlSize);
    2784           0 :         aEditSize.Width() = pEdit->GetTextWidth(rText) + EDIT_MINWIDTH;
    2785           0 :         pEdit->SetSizePixel(aEditSize);
    2786           0 :         pEdit->SetModifyHdl(LINK(this, SwTokenWindow, EditResize ));
    2787           0 :         pEdit->SetPrevNextLink(LINK(this, SwTokenWindow, NextItemHdl));
    2788           0 :         pEdit->SetGetFocusHdl(LINK(this, SwTokenWindow, TbxFocusHdl));
    2789           0 :         pEdit->Show();
    2790           0 :         pRet = pEdit;
    2791             :     }
    2792             :     else
    2793             :     {
    2794           0 :         SwTOXButton* pButton = new SwTOXButton(m_pCtrlParentWin, this, rToken);
    2795           0 :         pButton->SetPosPixel(aControlPos);
    2796             : 
    2797           0 :         aControlList.push_back(pButton);
    2798             : 
    2799           0 :         Size aEditSize(aControlSize);
    2800           0 :         aEditSize.Width() = pButton->GetTextWidth(rText) + 5;
    2801           0 :         pButton->SetSizePixel(aEditSize);
    2802           0 :         pButton->SetPrevNextLink(LINK(this, SwTokenWindow, NextItemBtnHdl));
    2803           0 :         pButton->SetGetFocusHdl(LINK(this, SwTokenWindow, TbxFocusBtnHdl));
    2804             : 
    2805           0 :         if(TOKEN_AUTHORITY != rToken.eTokenType)
    2806           0 :             pButton->SetText(aButtonTexts[rToken.eTokenType]);
    2807             :         else
    2808             :         {
    2809             :             //use the first two chars as symbol
    2810             :             OUString sTmp(SwAuthorityFieldType::GetAuthFieldName(
    2811           0 :                         (ToxAuthorityField)rToken.nAuthorityField));
    2812           0 :             pButton->SetText(sTmp.copy(0, 2));
    2813             :         }
    2814             : 
    2815           0 :         sal_uInt32 nIndex = GetControlIndex( rToken.eTokenType );
    2816           0 :         OUString sAccName = aButtonHelpTexts[rToken.eTokenType];
    2817           0 :         if ( nIndex )
    2818             :         {
    2819           0 :             sAccName += " " + OUString::number(nIndex);
    2820             :         }
    2821           0 :         pButton->SetAccessibleName( sAccName );
    2822             : 
    2823           0 :         pButton->Show();
    2824           0 :         pRet = pButton;
    2825             :     }
    2826             : 
    2827           0 :     return pRet;
    2828             : }
    2829             : 
    2830           0 : void SwTokenWindow::InsertAtSelection(const OUString& rText, const SwFormToken& rToken)
    2831             : {
    2832             :     OSL_ENSURE(pActiveCtrl, "no active control!");
    2833             : 
    2834           0 :     if(!pActiveCtrl)
    2835           0 :         return;
    2836             : 
    2837           0 :     SwFormToken aToInsertToken(rToken);
    2838             : 
    2839           0 :     if(TOKEN_LINK_START == aToInsertToken.eTokenType)
    2840             :     {
    2841             :         //determine if start or end of hyperlink is appropriate
    2842             :         //eventually change a following link start into a link end
    2843             :         // groups of LS LE should be ignored
    2844             :         // <insert>
    2845             :         //LS <insert>
    2846             :         //LE <insert>
    2847             :         //<insert> LS
    2848             :         //<insert> LE
    2849             :         //<insert>
    2850           0 :         bool bPreStartLinkFound = false;
    2851           0 :         bool bPreEndLinkFound = false;
    2852             : 
    2853           0 :         const Control* pControl = 0;
    2854           0 :         const Control* pExchange = 0;
    2855             : 
    2856           0 :         ctrl_const_iterator it = aControlList.begin();
    2857           0 :         for( ; it != aControlList.end() && pActiveCtrl != (*it); ++it )
    2858             :         {
    2859           0 :             pControl = *it;
    2860             : 
    2861           0 :             if( WINDOW_EDIT != pControl->GetType())
    2862             :             {
    2863             :                 const SwFormToken& rNewToken =
    2864           0 :                                 ((SwTOXButton*)pControl)->GetFormToken();
    2865             : 
    2866           0 :                 if( TOKEN_LINK_START == rNewToken.eTokenType )
    2867             :                 {
    2868           0 :                     bPreStartLinkFound = true;
    2869           0 :                     pExchange = 0;
    2870             :                 }
    2871           0 :                 else if(TOKEN_LINK_END == rNewToken.eTokenType)
    2872             :                 {
    2873           0 :                     if( bPreStartLinkFound )
    2874           0 :                         bPreStartLinkFound = false;
    2875             :                     else
    2876             :                     {
    2877           0 :                         bPreEndLinkFound = false;
    2878           0 :                         pExchange = pControl;
    2879             :                     }
    2880             :                 }
    2881             :             }
    2882             :         }
    2883             : 
    2884           0 :         bool bPostLinkStartFound = false;
    2885             : 
    2886           0 :         if(!bPreStartLinkFound && !bPreEndLinkFound)
    2887             :         {
    2888           0 :             for( ; it != aControlList.end(); ++it )
    2889             :             {
    2890           0 :                 pControl = *it;
    2891             : 
    2892           0 :                 if( pControl != pActiveCtrl &&
    2893           0 :                     WINDOW_EDIT != pControl->GetType())
    2894             :                 {
    2895             :                     const SwFormToken& rNewToken =
    2896           0 :                                     ((SwTOXButton*)pControl)->GetFormToken();
    2897             : 
    2898           0 :                     if( TOKEN_LINK_START == rNewToken.eTokenType )
    2899             :                     {
    2900           0 :                         if(bPostLinkStartFound)
    2901           0 :                             break;
    2902           0 :                         bPostLinkStartFound = true;
    2903           0 :                         pExchange = pControl;
    2904             :                     }
    2905           0 :                     else if(TOKEN_LINK_END == rNewToken.eTokenType )
    2906             :                     {
    2907           0 :                         if(bPostLinkStartFound)
    2908             :                         {
    2909           0 :                             bPostLinkStartFound = false;
    2910           0 :                             pExchange = 0;
    2911             :                         }
    2912           0 :                         break;
    2913             :                     }
    2914             :                 }
    2915             :             }
    2916             :         }
    2917             : 
    2918           0 :         if(bPreStartLinkFound)
    2919             :         {
    2920           0 :             aToInsertToken.eTokenType = TOKEN_LINK_END;
    2921           0 :             aToInsertToken.sText =  aButtonTexts[TOKEN_LINK_END];
    2922             :         }
    2923             : 
    2924           0 :         if(bPostLinkStartFound)
    2925             :         {
    2926             :             OSL_ENSURE(pExchange, "no control to exchange?");
    2927           0 :             if(pExchange)
    2928             :             {
    2929           0 :                 ((SwTOXButton*)pExchange)->SetLinkEnd();
    2930           0 :                 ((SwTOXButton*)pExchange)->SetText(aButtonTexts[TOKEN_LINK_END]);
    2931             :             }
    2932             :         }
    2933             : 
    2934           0 :         if(bPreEndLinkFound)
    2935             :         {
    2936             :             OSL_ENSURE(pExchange, "no control to exchange?");
    2937             : 
    2938           0 :             if(pExchange)
    2939             :             {
    2940           0 :                 ((SwTOXButton*)pExchange)->SetLinkStart();
    2941           0 :                 ((SwTOXButton*)pExchange)->SetText(aButtonTexts[TOKEN_LINK_START]);
    2942             :             }
    2943             :         }
    2944             :     }
    2945             : 
    2946             :     //if the active control is text then insert a new button at the selection
    2947             :     //else replace the button
    2948             :     ctrl_iterator iterActive = std::find(aControlList.begin(),
    2949           0 :                                          aControlList.end(), pActiveCtrl);
    2950             : 
    2951             :     assert(iterActive != aControlList.end());
    2952           0 :     if (iterActive == aControlList.end())
    2953           0 :         return;
    2954             : 
    2955           0 :     Size aControlSize(GetOutputSizePixel());
    2956             : 
    2957           0 :     if( WINDOW_EDIT == pActiveCtrl->GetType())
    2958             :     {
    2959           0 :         ++iterActive;
    2960             : 
    2961           0 :         Selection aSel = ((SwTOXEdit*)pActiveCtrl)->GetSelection();
    2962           0 :         aSel.Justify();
    2963             : 
    2964           0 :         const OUString sEditText = ((SwTOXEdit*)pActiveCtrl)->GetText();
    2965           0 :         const OUString sLeft = sEditText.copy( 0, aSel.A() );
    2966           0 :         const OUString sRight = sEditText.copy( aSel.B() );
    2967             : 
    2968           0 :         ((SwTOXEdit*)pActiveCtrl)->SetText(sLeft);
    2969           0 :         ((SwTOXEdit*)pActiveCtrl)->AdjustSize();
    2970             : 
    2971           0 :         SwFormToken aTmpToken(TOKEN_TEXT);
    2972           0 :         SwTOXEdit* pEdit = new SwTOXEdit(m_pCtrlParentWin, this, aTmpToken);
    2973             : 
    2974           0 :         iterActive = aControlList.insert(iterActive, pEdit);
    2975             : 
    2976           0 :         pEdit->SetText(sRight);
    2977           0 :         sal_uInt32 nIndex = GetControlIndex( TOKEN_TEXT );
    2978           0 :         OUString strName(accessibleName + OUString::number(nIndex));
    2979           0 :         if ( nIndex == 1)
    2980             :         {
    2981             :             /*Press left or right arrow to choose the structure controls*/
    2982           0 :             strName += " (" + sAdditionalAccnameString2 + ", "
    2983             :             /*Press Ctrl+Alt+A to move focus for more operations*/
    2984           0 :                      + sAdditionalAccnameString1 + ", "
    2985             :             /*Press Ctrl+Alt+B to move focus back to the current structure control*/
    2986           0 :                      + sAdditionalAccnameString3 + ")";
    2987             :         }
    2988           0 :         pEdit->SetAccessibleName(strName);
    2989           0 :         pEdit->SetSizePixel(aControlSize);
    2990           0 :         pEdit->AdjustSize();
    2991           0 :         pEdit->SetModifyHdl(LINK(this, SwTokenWindow, EditResize ));
    2992           0 :         pEdit->SetPrevNextLink(LINK(this, SwTokenWindow, NextItemHdl));
    2993           0 :         pEdit->SetGetFocusHdl(LINK(this, SwTokenWindow, TbxFocusHdl));
    2994           0 :         pEdit->Show();
    2995             :     }
    2996             :     else
    2997             :     {
    2998           0 :         iterActive = aControlList.erase(iterActive);
    2999           0 :         pActiveCtrl->Hide();
    3000           0 :         delete pActiveCtrl;
    3001             :     }
    3002             : 
    3003             :     //now the new button
    3004           0 :     SwTOXButton* pButton = new SwTOXButton(m_pCtrlParentWin, this, aToInsertToken);
    3005             : 
    3006           0 :     aControlList.insert(iterActive, pButton);
    3007             : 
    3008           0 :     pButton->SetPrevNextLink(LINK(this, SwTokenWindow, NextItemBtnHdl));
    3009           0 :     pButton->SetGetFocusHdl(LINK(this, SwTokenWindow, TbxFocusBtnHdl));
    3010             : 
    3011           0 :     if(TOKEN_AUTHORITY != aToInsertToken.eTokenType)
    3012             :     {
    3013           0 :         pButton->SetText(aButtonTexts[aToInsertToken.eTokenType]);
    3014             :     }
    3015             :     else
    3016             :     {
    3017             :         //use the first two chars as symbol
    3018             :         OUString sTmp(SwAuthorityFieldType::GetAuthFieldName(
    3019           0 :                     (ToxAuthorityField)aToInsertToken.nAuthorityField));
    3020           0 :         pButton->SetText(sTmp.copy(0, 2));
    3021             :     }
    3022             : 
    3023           0 :     Size aEditSize(GetOutputSizePixel());
    3024           0 :     aEditSize.Width() = pButton->GetTextWidth(rText) + 5;
    3025           0 :     pButton->SetSizePixel(aEditSize);
    3026           0 :     pButton->Check(true);
    3027           0 :     pButton->Show();
    3028           0 :     SetActiveControl(pButton);
    3029             : 
    3030           0 :     AdjustPositions();
    3031             : }
    3032             : 
    3033           0 : void SwTokenWindow::RemoveControl(SwTOXButton* pDel, sal_Bool bInternalCall )
    3034             : {
    3035           0 :     if(bInternalCall && TOX_AUTHORITIES == pForm->GetTOXType())
    3036           0 :         m_pParent->PreTokenButtonRemoved(pDel->GetFormToken());
    3037             : 
    3038           0 :     ctrl_iterator it = std::find(aControlList.begin(), aControlList.end(), pDel);
    3039             : 
    3040             :     assert(it != aControlList.end()); //Control does not exist!
    3041           0 :     if (it == aControlList.end())
    3042           0 :         return;
    3043             : 
    3044             :     // the two neighbours of the box must be merged
    3045             :     // the properties of the right one will be lost
    3046             :     assert(it != aControlList.begin() && it != aControlList.end() - 1); //Button at first or last position?
    3047           0 :     if (it == aControlList.begin() || it == aControlList.end() - 1)
    3048           0 :         return;
    3049             : 
    3050           0 :     ctrl_iterator itLeft = it, itRight = it;
    3051           0 :     --itLeft;
    3052           0 :     ++itRight;
    3053           0 :     Control *pLeftEdit = *itLeft;
    3054           0 :     Control *pRightEdit = *itRight;
    3055             : 
    3056           0 :     ((SwTOXEdit*)pLeftEdit)->SetText(((SwTOXEdit*)pLeftEdit)->GetText() +
    3057           0 :                                      ((SwTOXEdit*)pRightEdit)->GetText());
    3058           0 :     ((SwTOXEdit*)pLeftEdit)->AdjustSize();
    3059             : 
    3060           0 :     aControlList.erase(itRight);
    3061           0 :     delete pRightEdit;
    3062             : 
    3063           0 :     aControlList.erase(it);
    3064           0 :     pActiveCtrl->Hide();
    3065           0 :     delete pActiveCtrl;
    3066             : 
    3067           0 :     SetActiveControl(pLeftEdit);
    3068           0 :     AdjustPositions();
    3069           0 :     if(aModifyHdl.IsSet())
    3070           0 :         aModifyHdl.Call(0);
    3071             : }
    3072             : 
    3073           0 : void SwTokenWindow::AdjustPositions()
    3074             : {
    3075           0 :     if(aControlList.size() > 1)
    3076             :     {
    3077           0 :         ctrl_iterator it = aControlList.begin();
    3078           0 :         Control* pCtrl = *it;
    3079           0 :         ++it;
    3080             : 
    3081           0 :         Point aNextPos = pCtrl->GetPosPixel();
    3082           0 :         aNextPos.X() += pCtrl->GetSizePixel().Width();
    3083             : 
    3084           0 :         for(; it != aControlList.end(); ++it)
    3085             :         {
    3086           0 :             pCtrl = *it;
    3087           0 :             pCtrl->SetPosPixel(aNextPos);
    3088           0 :             aNextPos.X() += pCtrl->GetSizePixel().Width();
    3089             :         }
    3090             : 
    3091           0 :         AdjustScrolling();
    3092             :     }
    3093           0 : };
    3094             : 
    3095           0 : void SwTokenWindow::MoveControls(long nOffset)
    3096             : {
    3097             :     // move the complete list
    3098           0 :     for (ctrl_iterator it = aControlList.begin(); it != aControlList.end(); ++it)
    3099             :     {
    3100           0 :         Control *pCtrl = *it;
    3101             : 
    3102           0 :         Point aPos = pCtrl->GetPosPixel();
    3103           0 :         aPos.X() += nOffset;
    3104             : 
    3105           0 :         pCtrl->SetPosPixel(aPos);
    3106             :     }
    3107           0 : }
    3108             : 
    3109           0 : void SwTokenWindow::AdjustScrolling()
    3110             : {
    3111           0 :     if(aControlList.size() > 1)
    3112             :     {
    3113             :         //validate scroll buttons
    3114           0 :         Control* pFirstCtrl = *(aControlList.begin());
    3115           0 :         Control* pLastCtrl = *(aControlList.rbegin());
    3116             : 
    3117           0 :         long nSpace = m_pCtrlParentWin->GetSizePixel().Width();
    3118           0 :         long nWidth = pLastCtrl->GetPosPixel().X() - pFirstCtrl->GetPosPixel().X()
    3119           0 :                                                     + pLastCtrl->GetSizePixel().Width();
    3120           0 :         bool bEnable = nWidth > nSpace;
    3121             : 
    3122             :         //the active control must be visible
    3123           0 :         if(bEnable && pActiveCtrl)
    3124             :         {
    3125           0 :             Point aActivePos(pActiveCtrl->GetPosPixel());
    3126             : 
    3127           0 :             long nMove = 0;
    3128             : 
    3129           0 :             if(aActivePos.X() < 0)
    3130           0 :                 nMove = -aActivePos.X();
    3131           0 :             else if((aActivePos.X() + pActiveCtrl->GetSizePixel().Width())  > nSpace)
    3132           0 :                 nMove = -(aActivePos.X() + pActiveCtrl->GetSizePixel().Width() - nSpace);
    3133             : 
    3134           0 :             if(nMove)
    3135           0 :                 MoveControls(nMove);
    3136             : 
    3137           0 :             m_pLeftScrollWin->Enable(pFirstCtrl->GetPosPixel().X() < 0);
    3138             : 
    3139           0 :             m_pRightScrollWin->Enable((pLastCtrl->GetPosPixel().X() + pLastCtrl->GetSizePixel().Width()) > nSpace);
    3140             :         }
    3141             :         else
    3142             :         {
    3143             :             //if the control fits into the space then the first control must be at postion 0
    3144           0 :             long nFirstPos = pFirstCtrl->GetPosPixel().X();
    3145             : 
    3146           0 :             if(nFirstPos != 0)
    3147           0 :                 MoveControls(-nFirstPos);
    3148             : 
    3149           0 :             m_pRightScrollWin->Enable(false);
    3150           0 :             m_pLeftScrollWin->Enable(false);
    3151             :         }
    3152             :     }
    3153           0 : }
    3154             : 
    3155           0 : IMPL_LINK(SwTokenWindow, ScrollHdl, ImageButton*, pBtn )
    3156             : {
    3157           0 :     if(aControlList.empty())
    3158           0 :         return 0;
    3159             : 
    3160           0 :     const long nSpace = m_pCtrlParentWin->GetSizePixel().Width();
    3161             : #if OSL_DEBUG_LEVEL > 1
    3162             :     //find all start/end positions and print it
    3163             :     OUString sMessage("Space: " + OUString::number(nSpace) + " | ");
    3164             : 
    3165             :     for (ctrl_const_iterator it = aControlList.begin(); it != aControlList.end(); ++it)
    3166             :     {
    3167             :         Control *pDebugCtrl = *it;
    3168             : 
    3169             :         long nDebugXPos = pDebugCtrl->GetPosPixel().X();
    3170             :         long nDebugWidth = pDebugCtrl->GetSizePixel().Width();
    3171             : 
    3172             :         sMessage += OUString::number(nDebugXPos) + " "
    3173             :                   + OUString::number(nDebugXPos + nDebugWidth) + " | ";
    3174             :     }
    3175             : 
    3176             : #endif
    3177             : 
    3178           0 :     long nMove = 0;
    3179           0 :     if(pBtn == m_pLeftScrollWin)
    3180             :     {
    3181             :         //find the first completely visible control (left edge visible)
    3182           0 :         for (ctrl_iterator it = aControlList.begin(); it != aControlList.end(); ++it)
    3183             :         {
    3184           0 :             Control *pCtrl = *it;
    3185             : 
    3186           0 :             long nXPos = pCtrl->GetPosPixel().X();
    3187             : 
    3188           0 :             if (nXPos >= 0)
    3189             :             {
    3190           0 :                 if (it == aControlList.begin())
    3191             :                 {
    3192             :                     //move the current control to the left edge
    3193           0 :                     nMove = -nXPos;
    3194             :                 }
    3195             :                 else
    3196             :                 {
    3197             :                     //move the left neighbor to the start position
    3198           0 :                     ctrl_iterator itLeft = it;
    3199           0 :                     --itLeft;
    3200           0 :                     Control *pLeft = *itLeft;
    3201             : 
    3202           0 :                     nMove = -pLeft->GetPosPixel().X();
    3203             :                 }
    3204             : 
    3205           0 :                 break;
    3206             :             }
    3207             :         }
    3208             :     }
    3209             :     else
    3210             :     {
    3211             :         //find the first completely visible control (right edge visible)
    3212           0 :         for (ctrl_reverse_iterator it = aControlList.rbegin(); it != aControlList.rend(); ++it)
    3213             :         {
    3214           0 :             Control *pCtrl = *it;
    3215             : 
    3216           0 :             long nCtrlWidth = pCtrl->GetSizePixel().Width();
    3217           0 :             long nXPos = pCtrl->GetPosPixel().X() + nCtrlWidth;
    3218             : 
    3219           0 :             if (nXPos <= nSpace)
    3220             :             {
    3221           0 :                 if (it != aControlList.rbegin())
    3222             :                 {
    3223             :                     //move the right neighbor  to the right edge right aligned
    3224           0 :                     ctrl_reverse_iterator itRight = it;
    3225           0 :                     --itRight;
    3226           0 :                     Control *pRight = *itRight;
    3227           0 :                     nMove = nSpace - pRight->GetPosPixel().X() - pRight->GetSizePixel().Width();
    3228             :                 }
    3229             : 
    3230           0 :                 break;
    3231             :             }
    3232             :         }
    3233             : 
    3234             :         //move it left until it's completely visible
    3235             :     }
    3236             : 
    3237           0 :     if(nMove)
    3238             :     {
    3239             :         // move the complete list
    3240           0 :         MoveControls(nMove);
    3241             : 
    3242           0 :         Control *pCtrl = 0;
    3243             : 
    3244           0 :         pCtrl = *(aControlList.begin());
    3245           0 :         m_pLeftScrollWin->Enable(pCtrl->GetPosPixel().X() < 0);
    3246             : 
    3247           0 :         pCtrl = *(aControlList.rbegin());
    3248           0 :         m_pRightScrollWin->Enable((pCtrl->GetPosPixel().X() + pCtrl->GetSizePixel().Width()) > nSpace);
    3249             :     }
    3250             : 
    3251           0 :     return 0;
    3252             : }
    3253             : 
    3254           0 : OUString SwTokenWindow::GetPattern() const
    3255             : {
    3256           0 :     OUString sRet;
    3257             : 
    3258           0 :     for (ctrl_const_iterator it = aControlList.begin(); it != aControlList.end(); ++it)
    3259             :     {
    3260           0 :         const Control *pCtrl = *it;
    3261             : 
    3262           0 :         const SwFormToken &rNewToken = pCtrl->GetType() == WINDOW_EDIT
    3263             :                 ? ((SwTOXEdit*)pCtrl)->GetFormToken()
    3264           0 :                 : ((SwTOXButton*)pCtrl)->GetFormToken();
    3265             : 
    3266             :         //TODO: prevent input of TOX_STYLE_DELIMITER in KeyInput
    3267           0 :         sRet += rNewToken.GetString();
    3268             :     }
    3269             : 
    3270           0 :     return sRet;
    3271             : }
    3272             : 
    3273             : // Check if a control of the specified TokenType is already contained in the list
    3274           0 : sal_Bool SwTokenWindow::Contains(FormTokenType eSearchFor) const
    3275             : {
    3276           0 :     bool bRet = false;
    3277             : 
    3278           0 :     for (ctrl_const_iterator it = aControlList.begin(); it != aControlList.end(); ++it)
    3279             :     {
    3280           0 :         const Control *pCtrl = *it;
    3281             : 
    3282           0 :         const SwFormToken &rNewToken = pCtrl->GetType() == WINDOW_EDIT
    3283             :                 ? ((SwTOXEdit*)pCtrl)->GetFormToken()
    3284           0 :                 : ((SwTOXButton*)pCtrl)->GetFormToken();
    3285             : 
    3286           0 :         if (eSearchFor == rNewToken.eTokenType)
    3287             :         {
    3288           0 :             bRet = true;
    3289           0 :             break;
    3290             :         }
    3291             :     }
    3292             : 
    3293           0 :     return bRet;
    3294             : }
    3295             : 
    3296           0 : sal_Bool SwTokenWindow::CreateQuickHelp(Control* pCtrl,
    3297             :             const SwFormToken& rToken,
    3298             :             const HelpEvent& rHEvt)
    3299             : {
    3300           0 :     sal_Bool bRet = sal_False;
    3301           0 :     if( rHEvt.GetMode() & HELPMODE_QUICK )
    3302             :     {
    3303           0 :         sal_Bool bBalloon = Help::IsBalloonHelpEnabled();
    3304           0 :         OUString sEntry;
    3305           0 :         if(bBalloon || rToken.eTokenType != TOKEN_AUTHORITY)
    3306           0 :             sEntry = (aButtonHelpTexts[rToken.eTokenType]);
    3307           0 :         if(rToken.eTokenType == TOKEN_AUTHORITY )
    3308             :         {
    3309           0 :              sEntry += SwAuthorityFieldType::GetAuthFieldName(
    3310           0 :                                 (ToxAuthorityField) rToken.nAuthorityField);
    3311             :         }
    3312             : 
    3313           0 :         Point aPos = OutputToScreenPixel(pCtrl->GetPosPixel());
    3314           0 :         Rectangle aItemRect( aPos, pCtrl->GetSizePixel() );
    3315           0 :         if ( rToken.eTokenType != TOKEN_TAB_STOP )
    3316             :         {
    3317           0 :             if (!rToken.sCharStyleName.isEmpty())
    3318             :             {
    3319             :                 sEntry += OUString(bBalloon ? '\n' : ' ')
    3320           0 :                         + sCharStyle + rToken.sCharStyleName;
    3321             :             }
    3322             :         }
    3323           0 :         if(bBalloon)
    3324             :         {
    3325           0 :             Help::ShowBalloon( this, aPos, aItemRect, sEntry );
    3326             :         }
    3327             :         else
    3328             :             Help::ShowQuickHelp( this, aItemRect, sEntry,
    3329           0 :                 QUICKHELP_LEFT|QUICKHELP_VCENTER );
    3330           0 :         bRet = sal_True;
    3331             :     }
    3332           0 :     return bRet;
    3333             : }
    3334             : 
    3335           0 : IMPL_LINK(SwTokenWindow, EditResize, Edit*, pEdit)
    3336             : {
    3337           0 :     ((SwTOXEdit*)pEdit)->AdjustSize();
    3338           0 :     AdjustPositions();
    3339           0 :     if(aModifyHdl.IsSet())
    3340           0 :         aModifyHdl.Call(0);
    3341           0 :     return 0;
    3342             : }
    3343             : 
    3344           0 : IMPL_LINK(SwTokenWindow, NextItemHdl, SwTOXEdit*,  pEdit)
    3345             : {
    3346           0 :     ctrl_iterator it = std::find(aControlList.begin(),aControlList.end(),pEdit);
    3347             : 
    3348           0 :     if (it == aControlList.end())
    3349           0 :         return 0;
    3350             : 
    3351           0 :     ctrl_iterator itTest = it;
    3352           0 :     ++itTest;
    3353             : 
    3354           0 :     if ((it != aControlList.begin() && !pEdit->IsNextControl()) ||
    3355           0 :         (itTest != aControlList.end() && pEdit->IsNextControl()))
    3356             :     {
    3357           0 :         ctrl_iterator iterFocus = it;
    3358           0 :         pEdit->IsNextControl() ? ++iterFocus : --iterFocus;
    3359             : 
    3360           0 :         Control *pCtrlFocus = *iterFocus;
    3361           0 :         pCtrlFocus->GrabFocus();
    3362           0 :         static_cast<SwTOXButton*>(pCtrlFocus)->Check();
    3363             : 
    3364           0 :         AdjustScrolling();
    3365             :     }
    3366             : 
    3367           0 :     return 0;
    3368             : }
    3369             : 
    3370           0 : IMPL_LINK(SwTokenWindow, TbxFocusHdl, SwTOXEdit*, pEdit)
    3371             : {
    3372           0 :     for (ctrl_iterator it = aControlList.begin(); it != aControlList.end(); ++it)
    3373             :     {
    3374           0 :         Control *pCtrl = *it;
    3375             : 
    3376           0 :         if (pCtrl && pCtrl->GetType() != WINDOW_EDIT)
    3377           0 :             static_cast<SwTOXButton*>(pCtrl)->Check(false);
    3378             :     }
    3379             : 
    3380           0 :     SetActiveControl(pEdit);
    3381             : 
    3382           0 :     return 0;
    3383             : }
    3384             : 
    3385           0 : IMPL_LINK(SwTokenWindow, NextItemBtnHdl, SwTOXButton*, pBtn )
    3386             : {
    3387           0 :     ctrl_iterator it = std::find(aControlList.begin(),aControlList.end(),pBtn);
    3388             : 
    3389           0 :     if (it == aControlList.end())
    3390           0 :         return 0;
    3391             : 
    3392           0 :     ctrl_iterator itTest = it;
    3393           0 :     ++itTest;
    3394             : 
    3395           0 :     if (!pBtn->IsNextControl() || (itTest != aControlList.end() && pBtn->IsNextControl()))
    3396             :     {
    3397           0 :         bool isNext = pBtn->IsNextControl();
    3398             : 
    3399           0 :         ctrl_iterator iterFocus = it;
    3400           0 :         isNext ? ++iterFocus : --iterFocus;
    3401             : 
    3402           0 :         Control *pCtrlFocus = *iterFocus;
    3403           0 :         pCtrlFocus->GrabFocus();
    3404           0 :         Selection aSel(0,0);
    3405             : 
    3406           0 :         if (!isNext)
    3407             :         {
    3408           0 :             const sal_Int32 nLen = static_cast<SwTOXEdit*>(pCtrlFocus)->GetText().getLength();
    3409             : 
    3410           0 :             aSel.A() = nLen;
    3411           0 :             aSel.B() = nLen;
    3412             :         }
    3413             : 
    3414           0 :         static_cast<SwTOXEdit*>(pCtrlFocus)->SetSelection(aSel);
    3415             : 
    3416           0 :         pBtn->Check(false);
    3417             : 
    3418           0 :         AdjustScrolling();
    3419             :     }
    3420             : 
    3421           0 :     return 0;
    3422             : }
    3423             : 
    3424           0 : IMPL_LINK(SwTokenWindow, TbxFocusBtnHdl, SwTOXButton*, pBtn )
    3425             : {
    3426           0 :     for (ctrl_iterator it = aControlList.begin(); it != aControlList.end(); ++it)
    3427             :     {
    3428           0 :         Control *pControl = *it;
    3429             : 
    3430           0 :         if (pControl && WINDOW_EDIT != pControl->GetType())
    3431           0 :             static_cast<SwTOXButton*>(pControl)->Check(pBtn == pControl);
    3432             :     }
    3433             : 
    3434           0 :     SetActiveControl(pBtn);
    3435             : 
    3436           0 :     return 0;
    3437             : }
    3438             : 
    3439           0 : void SwTokenWindow::GetFocus()
    3440             : {
    3441           0 :     if(GETFOCUS_TAB & GetGetFocusFlags())
    3442             :     {
    3443           0 :         if (!aControlList.empty())
    3444             :         {
    3445           0 :             Control *pFirst = *aControlList.begin();
    3446             : 
    3447           0 :             if (pFirst)
    3448             :             {
    3449           0 :                 pFirst->GrabFocus();
    3450           0 :                 SetActiveControl(pFirst);
    3451           0 :                 AdjustScrolling();
    3452             :             }
    3453             :         }
    3454             :     }
    3455           0 : }
    3456             : 
    3457           0 : void SwTokenWindow::SetFocus2theAllBtn()
    3458             : {
    3459           0 :     if (m_pParent)
    3460             :     {
    3461           0 :         m_pParent->SetFocus2theAllBtn();
    3462             :     }
    3463           0 : }
    3464             : 
    3465           0 : sal_uInt32 SwTokenWindow::GetControlIndex(FormTokenType eType) const
    3466             : {
    3467             :     //there are only one entry-text button and only one page-number button,
    3468             :     //so we need not add index for these two buttons.
    3469           0 :     if ( eType == TOKEN_ENTRY_TEXT || eType == TOKEN_PAGE_NUMS )
    3470             :     {
    3471           0 :         return 0;
    3472             :     }
    3473             : 
    3474           0 :     sal_uInt32 nIndex = 0;
    3475           0 :     for (ctrl_const_iterator it = aControlList.begin(); it != aControlList.end(); ++it)
    3476             :     {
    3477           0 :         const Control* pControl = *it;
    3478           0 :         const SwFormToken& rNewToken = WINDOW_EDIT == pControl->GetType()
    3479             :             ? ((SwTOXEdit*)pControl)->GetFormToken()
    3480           0 :             : ((SwTOXButton*)pControl)->GetFormToken();
    3481             : 
    3482           0 :         if(eType == rNewToken.eTokenType)
    3483             :         {
    3484           0 :             ++nIndex;
    3485             :         }
    3486             :     }
    3487             : 
    3488           0 :     return nIndex;
    3489             : }
    3490             : 
    3491           0 : SwTOXStylesTabPage::SwTOXStylesTabPage(Window* pParent, const SfxItemSet& rAttrSet )
    3492             :     : SfxTabPage(pParent, "TocStylesPage",
    3493             :         "modules/swriter/ui/tocstylespage.ui", rAttrSet)
    3494           0 :     , m_pCurrentForm(0)
    3495             : {
    3496           0 :     get(m_pLevelLB, "levels");
    3497           0 :     get(m_pAssignBT, "assign");
    3498           0 :     get(m_pParaLayLB, "styles");
    3499           0 :     m_pParaLayLB->SetStyle(m_pParaLayLB->GetStyle() | WB_SORT);
    3500           0 :     get(m_pStdBT, "default");
    3501           0 :     get(m_pEditStyleBT, "edit");
    3502           0 :     long nHeight = m_pLevelLB->GetTextHeight() * 16;
    3503           0 :     m_pLevelLB->set_height_request(nHeight);
    3504           0 :     m_pParaLayLB->set_height_request(nHeight);
    3505             : 
    3506           0 :     SetExchangeSupport( true );
    3507             : 
    3508           0 :     m_pEditStyleBT->SetClickHdl   (LINK(   this, SwTOXStylesTabPage, EditStyleHdl));
    3509           0 :     m_pAssignBT->SetClickHdl      (LINK(   this, SwTOXStylesTabPage, AssignHdl));
    3510           0 :     m_pStdBT->SetClickHdl         (LINK(   this, SwTOXStylesTabPage, StdHdl));
    3511           0 :     m_pParaLayLB->SetSelectHdl    (LINK(   this, SwTOXStylesTabPage, EnableSelectHdl));
    3512           0 :     m_pLevelLB->SetSelectHdl(LINK(this, SwTOXStylesTabPage, EnableSelectHdl));
    3513           0 :     m_pParaLayLB->SetDoubleClickHdl(LINK(  this, SwTOXStylesTabPage, DoubleClickHdl));
    3514           0 : }
    3515             : 
    3516           0 : SwTOXStylesTabPage::~SwTOXStylesTabPage()
    3517             : {
    3518           0 :     delete m_pCurrentForm;
    3519           0 : }
    3520             : 
    3521           0 : bool SwTOXStylesTabPage::FillItemSet( SfxItemSet& )
    3522             : {
    3523           0 :     return true;
    3524             : }
    3525             : 
    3526           0 : void SwTOXStylesTabPage::Reset( const SfxItemSet& rSet )
    3527             : {
    3528           0 :     ActivatePage(rSet);
    3529           0 : }
    3530             : 
    3531           0 : void SwTOXStylesTabPage::ActivatePage( const SfxItemSet& )
    3532             : {
    3533           0 :     m_pCurrentForm = new SwForm(GetForm());
    3534           0 :     m_pParaLayLB->Clear();
    3535           0 :     m_pLevelLB->Clear();
    3536             : 
    3537             :     // not hyperlink for user directories
    3538             : 
    3539           0 :     const sal_uInt16 nSize = m_pCurrentForm->GetFormMax();
    3540             : 
    3541             :     // display form pattern without title
    3542             : 
    3543             :     // display 1st TemplateEntry
    3544           0 :     OUString aStr( SW_RES( STR_TITLE ));
    3545           0 :     if( !m_pCurrentForm->GetTemplate( 0 ).isEmpty() )
    3546             :     {
    3547           0 :         aStr += " " + OUString(aDeliStart)
    3548           0 :               + m_pCurrentForm->GetTemplate( 0 )
    3549           0 :               + OUString(aDeliEnd);
    3550             :     }
    3551           0 :     m_pLevelLB->InsertEntry(aStr);
    3552             : 
    3553           0 :     for( sal_uInt16 i=1; i < nSize; ++i )
    3554             :     {
    3555           0 :         if( TOX_INDEX == m_pCurrentForm->GetTOXType() &&
    3556             :             FORM_ALPHA_DELIMITTER == i )
    3557             :         {
    3558           0 :             aStr = SW_RESSTR(STR_ALPHA);
    3559             :         }
    3560             :         else
    3561             :         {
    3562           0 :             aStr = SW_RESSTR(STR_LEVEL) + OUString::number(
    3563           0 :                     TOX_INDEX == m_pCurrentForm->GetTOXType() ? i - 1 : i );
    3564             :         }
    3565           0 :         if( !m_pCurrentForm->GetTemplate( i ).isEmpty() )
    3566             :         {
    3567           0 :             aStr += " " + OUString(aDeliStart)
    3568           0 :                   + m_pCurrentForm->GetTemplate( i )
    3569           0 :                   + OUString(aDeliEnd);
    3570             :         }
    3571           0 :         m_pLevelLB->InsertEntry( aStr );
    3572             :     }
    3573             : 
    3574             :     // initialise templates
    3575             :     const SwTxtFmtColl *pColl;
    3576           0 :     SwWrtShell& rSh = ((SwMultiTOXTabDialog*)GetTabDialog())->GetWrtShell();
    3577           0 :     const sal_uInt16 nSz = rSh.GetTxtFmtCollCount();
    3578             : 
    3579           0 :     for( sal_uInt16 i = 0; i < nSz; ++i )
    3580           0 :         if( !(pColl = &rSh.GetTxtFmtColl( i ))->IsDefault() )
    3581           0 :             m_pParaLayLB->InsertEntry( pColl->GetName() );
    3582             : 
    3583             :     // query pool collections and set them for the directory
    3584           0 :     for( sal_uInt16 i = 0; i < m_pCurrentForm->GetFormMax(); ++i )
    3585             :     {
    3586           0 :         aStr = m_pCurrentForm->GetTemplate( i );
    3587           0 :         if( !aStr.isEmpty() &&
    3588           0 :             LISTBOX_ENTRY_NOTFOUND == m_pParaLayLB->GetEntryPos( aStr ))
    3589           0 :             m_pParaLayLB->InsertEntry( aStr );
    3590             :     }
    3591             : 
    3592           0 :     EnableSelectHdl(m_pParaLayLB);
    3593           0 : }
    3594             : 
    3595           0 : int SwTOXStylesTabPage::DeactivatePage( SfxItemSet* /*pSet*/  )
    3596             : {
    3597           0 :     GetForm() = *m_pCurrentForm;
    3598           0 :     return LEAVE_PAGE;
    3599             : }
    3600             : 
    3601           0 : SfxTabPage* SwTOXStylesTabPage::Create( Window* pParent,
    3602             :                                 const SfxItemSet& rAttrSet)
    3603             : {
    3604           0 :     return new SwTOXStylesTabPage(pParent, rAttrSet);
    3605             : }
    3606             : 
    3607           0 : IMPL_LINK( SwTOXStylesTabPage, EditStyleHdl, Button *, pBtn )
    3608             : {
    3609           0 :     if( LISTBOX_ENTRY_NOTFOUND != m_pParaLayLB->GetSelectEntryPos())
    3610             :     {
    3611           0 :         SfxStringItem aStyle(SID_STYLE_EDIT, m_pParaLayLB->GetSelectEntry());
    3612           0 :         SfxUInt16Item aFamily(SID_STYLE_FAMILY, SFX_STYLE_FAMILY_PARA);
    3613           0 :         Window* pDefDlgParent = Application::GetDefDialogParent();
    3614           0 :         Application::SetDefDialogParent( pBtn );
    3615           0 :         SwWrtShell& rSh = ((SwMultiTOXTabDialog*)GetTabDialog())->GetWrtShell();
    3616           0 :         rSh.GetView().GetViewFrame()->GetDispatcher()->Execute(
    3617             :         SID_STYLE_EDIT, SFX_CALLMODE_SYNCHRON|SFX_CALLMODE_MODAL,
    3618           0 :             &aStyle, &aFamily, 0L);
    3619           0 :         Application::SetDefDialogParent( pDefDlgParent );
    3620             :     }
    3621           0 :     return 0;
    3622             : }
    3623             : 
    3624             : // allocate templates
    3625           0 : IMPL_LINK_NOARG(SwTOXStylesTabPage, AssignHdl)
    3626             : {
    3627           0 :     sal_Int32 nLevPos   = m_pLevelLB->GetSelectEntryPos();
    3628           0 :     sal_Int32 nTemplPos = m_pParaLayLB->GetSelectEntryPos();
    3629           0 :     if(nLevPos   != LISTBOX_ENTRY_NOTFOUND &&
    3630             :        nTemplPos != LISTBOX_ENTRY_NOTFOUND)
    3631             :     {
    3632             :         const OUString aStr(m_pLevelLB->GetEntry(nLevPos).getToken(0, aDeliStart)
    3633           0 :             + " " + OUString(aDeliStart)
    3634           0 :             + m_pParaLayLB->GetSelectEntry()
    3635           0 :             + OUString(aDeliEnd));
    3636             : 
    3637           0 :         m_pCurrentForm->SetTemplate(nLevPos, m_pParaLayLB->GetSelectEntry());
    3638             : 
    3639           0 :         m_pLevelLB->RemoveEntry(nLevPos);
    3640           0 :         m_pLevelLB->InsertEntry(aStr, nLevPos);
    3641           0 :         m_pLevelLB->SelectEntry(aStr);
    3642           0 :         Modify();
    3643             :     }
    3644           0 :     return 0;
    3645             : }
    3646             : 
    3647           0 : IMPL_LINK_NOARG(SwTOXStylesTabPage, StdHdl)
    3648             : {
    3649           0 :     const sal_Int32 nPos = m_pLevelLB->GetSelectEntryPos();
    3650           0 :     if(nPos != LISTBOX_ENTRY_NOTFOUND)
    3651             :     {
    3652           0 :         const OUString aStr(m_pLevelLB->GetEntry(nPos).getToken(0, aDeliStart));
    3653           0 :         m_pLevelLB->RemoveEntry(nPos);
    3654           0 :         m_pLevelLB->InsertEntry(aStr, nPos);
    3655           0 :         m_pLevelLB->SelectEntry(aStr);
    3656           0 :         m_pCurrentForm->SetTemplate(nPos, aEmptyOUStr);
    3657           0 :         Modify();
    3658             :     }
    3659           0 :     return 0;
    3660             : }
    3661             : 
    3662           0 : IMPL_LINK_NOARG_INLINE_START(SwTOXStylesTabPage, DoubleClickHdl)
    3663             : {
    3664           0 :     const OUString aTmpName( m_pParaLayLB->GetSelectEntry() );
    3665           0 :     SwWrtShell& rSh = ((SwMultiTOXTabDialog*)GetTabDialog())->GetWrtShell();
    3666             : 
    3667           0 :     if(m_pParaLayLB->GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND &&
    3668           0 :        (m_pLevelLB->GetSelectEntryPos() == 0 || SwMultiTOXTabDialog::IsNoNum(rSh, aTmpName)))
    3669           0 :         AssignHdl(m_pAssignBT);
    3670           0 :     return 0;
    3671             : }
    3672           0 : IMPL_LINK_NOARG_INLINE_END(SwTOXStylesTabPage, DoubleClickHdl)
    3673             : 
    3674             : // enable only when selected
    3675           0 : IMPL_LINK_NOARG(SwTOXStylesTabPage, EnableSelectHdl)
    3676             : {
    3677           0 :     m_pStdBT->Enable(m_pLevelLB->GetSelectEntryPos()  != LISTBOX_ENTRY_NOTFOUND);
    3678             : 
    3679           0 :     SwWrtShell& rSh = ((SwMultiTOXTabDialog*)GetTabDialog())->GetWrtShell();
    3680           0 :     const OUString aTmpName(m_pParaLayLB->GetSelectEntry());
    3681           0 :     m_pAssignBT->Enable(m_pParaLayLB->GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND &&
    3682           0 :                      LISTBOX_ENTRY_NOTFOUND != m_pLevelLB->GetSelectEntryPos() &&
    3683           0 :        (m_pLevelLB->GetSelectEntryPos() == 0 || SwMultiTOXTabDialog::IsNoNum(rSh, aTmpName)));
    3684           0 :     m_pEditStyleBT->Enable(m_pParaLayLB->GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND );
    3685           0 :     return 0;
    3686             : }
    3687             : 
    3688           0 : void SwTOXStylesTabPage::Modify()
    3689             : {
    3690           0 :     SwMultiTOXTabDialog* pTOXDlg = (SwMultiTOXTabDialog*)GetTabDialog();
    3691           0 :     if (pTOXDlg)
    3692             :     {
    3693           0 :         GetForm() = *m_pCurrentForm;
    3694           0 :         pTOXDlg->CreateOrUpdateExample(pTOXDlg->GetCurrentTOXType().eType, TOX_PAGE_STYLES);
    3695             :     }
    3696           0 : }
    3697             : 
    3698             : #define ITEM_SEARCH         1
    3699             : #define ITEM_ALTERNATIVE    2
    3700             : #define ITEM_PRIM_KEY       3
    3701             : #define ITEM_SEC_KEY        4
    3702             : #define ITEM_COMMENT        5
    3703             : #define ITEM_CASE           6
    3704             : #define ITEM_WORDONLY       7
    3705             : 
    3706           0 : SwEntryBrowseBox::SwEntryBrowseBox(Window* pParent, VclBuilderContainer* pBuilder)
    3707             :     : SwEntryBrowseBox_Base( pParent, EBBF_NONE, WB_TABSTOP | WB_BORDER,
    3708             :                            BROWSER_KEEPSELECTION |
    3709             :                            BROWSER_COLUMNSELECTION |
    3710             :                            BROWSER_MULTISELECTION |
    3711             :                            BROWSER_TRACKING_TIPS |
    3712             :                            BROWSER_HLINESFULL |
    3713             :                            BROWSER_VLINESFULL |
    3714             :                            BROWSER_AUTO_VSCROLL|
    3715             :                            BROWSER_HIDECURSOR   )
    3716           0 :     , aCellEdit(&GetDataWindow(), 0)
    3717           0 :     , aCellCheckBox(&GetDataWindow())
    3718             :     , nCurrentRow(0)
    3719           0 :     , bModified(false)
    3720             : {
    3721           0 :     sSearch = pBuilder->get<Window>("searchterm")->GetText();
    3722           0 :     sAlternative = pBuilder->get<Window>("alternative")->GetText();
    3723           0 :     sPrimKey = pBuilder->get<Window>("key1")->GetText();
    3724           0 :     sSecKey = pBuilder->get<Window>("key2")->GetText();
    3725           0 :     sComment = pBuilder->get<Window>("comment")->GetText();
    3726           0 :     sCaseSensitive = pBuilder->get<Window>("casesensitive")->GetText();
    3727           0 :     sWordOnly = pBuilder->get<Window>("wordonly")->GetText();
    3728           0 :     sYes = pBuilder->get<Window>("yes")->GetText();
    3729           0 :     sNo = pBuilder->get<Window>("no")->GetText();
    3730             : 
    3731           0 :     aCellCheckBox.GetBox().EnableTriState(false);
    3732           0 :     xController = new ::svt::EditCellController(&aCellEdit);
    3733           0 :     xCheckController = new ::svt::CheckBoxCellController(&aCellCheckBox);
    3734             : 
    3735             :     // HACK: BrowseBox doesn't invalidate its children, how it should be.
    3736             :     // That's why WB_CLIPCHILDREN is reset in order to enforce the
    3737             :     // children' invalidation
    3738           0 :     WinBits aStyle = GetStyle();
    3739           0 :     if( aStyle & WB_CLIPCHILDREN )
    3740             :     {
    3741           0 :         aStyle &= ~WB_CLIPCHILDREN;
    3742           0 :         SetStyle( aStyle );
    3743             :     }
    3744             : 
    3745             :     const OUString* aTitles[7] =
    3746             :     {
    3747             :         &sSearch,
    3748             :         &sAlternative,
    3749             :         &sPrimKey,
    3750             :         &sSecKey,
    3751             :         &sComment,
    3752             :         &sCaseSensitive,
    3753             :         &sWordOnly
    3754           0 :     };
    3755             : 
    3756           0 :     long nWidth = GetSizePixel().Width();
    3757           0 :     nWidth /=7;
    3758           0 :     --nWidth;
    3759           0 :     for(sal_uInt16 i = 1; i < 8; i++)
    3760           0 :         InsertDataColumn( i, *aTitles[i - 1], nWidth,
    3761           0 :                           HIB_STDSTYLE, HEADERBAR_APPEND );
    3762           0 : }
    3763             : 
    3764           0 : void SwEntryBrowseBox::Resize()
    3765             : {
    3766           0 :     SwEntryBrowseBox_Base::Resize();
    3767             : 
    3768           0 :     Dialog *pDlg = GetParentDialog();
    3769           0 :     if (pDlg && pDlg->isCalculatingInitialLayoutSize())
    3770             :     {
    3771           0 :         long nWidth = GetSizePixel().Width();
    3772           0 :         std::vector<long> aWidths = GetOptimalColWidths();
    3773           0 :         long nNaturalWidth(::std::accumulate(aWidths.begin(), aWidths.end(), 0));
    3774           0 :         long nExcess = ((nWidth - nNaturalWidth) / aWidths.size()) - 1;
    3775             : 
    3776           0 :         for (size_t i = 0; i < aWidths.size(); ++i)
    3777           0 :             SetColumnWidth(i+1, aWidths[i] + nExcess);
    3778             :     }
    3779           0 : }
    3780             : 
    3781           0 : std::vector<long> SwEntryBrowseBox::GetOptimalColWidths() const
    3782             : {
    3783           0 :     std::vector<long> aWidths;
    3784             : 
    3785           0 :     long nStandardColMinWidth = approximate_char_width() * 16;
    3786           0 :     long nYesNoWidth = approximate_char_width() * 5;
    3787           0 :     nYesNoWidth = std::max(nYesNoWidth, GetTextWidth(sYes));
    3788           0 :     nYesNoWidth = std::max(nYesNoWidth, GetTextWidth(sNo));
    3789           0 :     for (sal_uInt16 i = 1; i < 6; i++)
    3790             :     {
    3791             :         long nColWidth = std::max(nStandardColMinWidth,
    3792           0 :                                   GetTextWidth(GetColumnTitle(i)));
    3793           0 :         nColWidth += 12;
    3794           0 :         aWidths.push_back(nColWidth);
    3795             :     }
    3796             : 
    3797           0 :     for (sal_uInt16 i = 6; i < 8; i++)
    3798             :     {
    3799             :         long nColWidth = std::max(nYesNoWidth,
    3800           0 :                                   GetTextWidth(GetColumnTitle(i)));
    3801           0 :         nColWidth += 12;
    3802           0 :         aWidths.push_back(nColWidth);
    3803             :     }
    3804             : 
    3805           0 :     return aWidths;
    3806             : }
    3807             : 
    3808           0 : Size SwEntryBrowseBox::GetOptimalSize() const
    3809             : {
    3810           0 :     Size aSize = LogicToPixel(Size(276 , 175), MapMode(MAP_APPFONT));
    3811             : 
    3812           0 :     std::vector<long> aWidths = GetOptimalColWidths();
    3813             : 
    3814           0 :     long nWidth(::std::accumulate(aWidths.begin(), aWidths.end(), 0));
    3815             : 
    3816           0 :     aSize.Width() = std::max(aSize.Width(), nWidth);
    3817             : 
    3818           0 :     return aSize;
    3819             : }
    3820             : 
    3821           0 : bool SwEntryBrowseBox::SeekRow( long nRow )
    3822             : {
    3823           0 :     nCurrentRow = nRow;
    3824           0 :     return true;
    3825             : }
    3826             : 
    3827           0 : OUString SwEntryBrowseBox::GetCellText(long nRow, sal_uInt16 nColumn) const
    3828             : {
    3829           0 :     const OUString* pRet = &aEmptyOUStr;
    3830           0 :     if (aEntryArr.size() > static_cast<size_t>(nRow))
    3831             :     {
    3832           0 :         const AutoMarkEntry* pEntry = &aEntryArr[ nRow ];
    3833           0 :         switch(nColumn)
    3834             :         {
    3835           0 :             case  ITEM_SEARCH       :pRet = &pEntry->sSearch; break;
    3836           0 :             case  ITEM_ALTERNATIVE  :pRet = &pEntry->sAlternative; break;
    3837           0 :             case  ITEM_PRIM_KEY     :pRet = &pEntry->sPrimKey   ; break;
    3838           0 :             case  ITEM_SEC_KEY      :pRet = &pEntry->sSecKey    ; break;
    3839           0 :             case  ITEM_COMMENT      :pRet = &pEntry->sComment   ; break;
    3840           0 :             case  ITEM_CASE         :pRet = pEntry->bCase ? &sYes : &sNo; break;
    3841           0 :             case  ITEM_WORDONLY     :pRet = pEntry->bWord ? &sYes : &sNo; break;
    3842             :         }
    3843             :     }
    3844           0 :     return *pRet;
    3845             : }
    3846             : 
    3847           0 : void SwEntryBrowseBox::PaintCell(OutputDevice& rDev,
    3848             :                                 const Rectangle& rRect, sal_uInt16 nColumnId) const
    3849             : {
    3850           0 :     const sal_uInt16 nStyle = TEXT_DRAW_CLIP | TEXT_DRAW_CENTER;
    3851           0 :     rDev.DrawText( rRect, GetCellText( nCurrentRow, nColumnId ), nStyle );
    3852           0 : }
    3853             : 
    3854           0 : ::svt::CellController* SwEntryBrowseBox::GetController(long /*nRow*/, sal_uInt16 nCol)
    3855             : {
    3856           0 :     return nCol < ITEM_CASE ? xController : xCheckController;
    3857             : }
    3858             : 
    3859           0 : bool SwEntryBrowseBox::SaveModified()
    3860             : {
    3861           0 :     SetModified();
    3862           0 :     const size_t nRow = GetCurRow();
    3863           0 :     const sal_uInt16 nCol = GetCurColumnId();
    3864             : 
    3865           0 :     OUString sNew;
    3866           0 :     sal_Bool bVal = sal_False;
    3867           0 :     ::svt::CellController* pController = 0;
    3868           0 :     if(nCol < ITEM_CASE)
    3869             :     {
    3870           0 :         pController = xController;
    3871           0 :         sNew = ((::svt::EditCellController*)pController)->GetEditImplementation()->GetText( LINEEND_LF );
    3872             :     }
    3873             :     else
    3874             :     {
    3875           0 :         pController = xCheckController;
    3876           0 :         bVal = ((::svt::CheckBoxCellController*)pController)->GetCheckBox().IsChecked();
    3877             :     }
    3878           0 :     AutoMarkEntry* pEntry = nRow >= aEntryArr.size() ? new AutoMarkEntry
    3879           0 :                                                       : &aEntryArr[nRow];
    3880           0 :     switch(nCol)
    3881             :     {
    3882           0 :         case  ITEM_SEARCH       : pEntry->sSearch = sNew; break;
    3883           0 :         case  ITEM_ALTERNATIVE  : pEntry->sAlternative = sNew; break;
    3884           0 :         case  ITEM_PRIM_KEY     : pEntry->sPrimKey   = sNew; break;
    3885           0 :         case  ITEM_SEC_KEY      : pEntry->sSecKey    = sNew; break;
    3886           0 :         case  ITEM_COMMENT      : pEntry->sComment   = sNew; break;
    3887           0 :         case  ITEM_CASE         : pEntry->bCase = bVal; break;
    3888           0 :         case  ITEM_WORDONLY     : pEntry->bWord = bVal; break;
    3889             :     }
    3890           0 :     if(nRow >= aEntryArr.size())
    3891             :     {
    3892           0 :         aEntryArr.push_back( pEntry );
    3893           0 :         RowInserted(nRow, 1, true, true);
    3894           0 :         if(nCol < ITEM_WORDONLY)
    3895             :         {
    3896           0 :             pController->ClearModified();
    3897           0 :             GoToRow( nRow );
    3898             :         }
    3899             :     }
    3900           0 :     return true;
    3901             : }
    3902             : 
    3903           0 : void SwEntryBrowseBox::InitController(
    3904             :                 ::svt::CellControllerRef& rController, long nRow, sal_uInt16 nCol)
    3905             : {
    3906           0 :     const OUString rTxt = GetCellText( nRow, nCol );
    3907           0 :     if(nCol < ITEM_CASE)
    3908             :     {
    3909           0 :         rController = xController;
    3910           0 :         ::svt::CellController* pController = xController;
    3911           0 :         ((::svt::EditCellController*)pController)->GetEditImplementation()->SetText( rTxt );
    3912             :     }
    3913             :     else
    3914             :     {
    3915           0 :         rController = xCheckController;
    3916           0 :         ::svt::CellController* pController = xCheckController;
    3917           0 :         ((::svt::CheckBoxCellController*)pController)->GetCheckBox().Check(
    3918           0 :                                                             rTxt == sYes );
    3919           0 :      }
    3920           0 : }
    3921             : 
    3922           0 : void SwEntryBrowseBox::ReadEntries(SvStream& rInStr)
    3923             : {
    3924           0 :     AutoMarkEntry* pToInsert = 0;
    3925           0 :     rtl_TextEncoding  eTEnc = osl_getThreadTextEncoding();
    3926           0 :     while( !rInStr.GetError() && !rInStr.IsEof() )
    3927             :     {
    3928           0 :         OUString sLine;
    3929           0 :         rInStr.ReadByteStringLine( sLine, eTEnc );
    3930             : 
    3931             :         // # -> comment
    3932             :         // ; -> delimiter between entries ->
    3933             :         // Format: TextToSearchFor;AlternativeString;PrimaryKey;SecondaryKey
    3934             :         // Leading and trailing blanks are ignored
    3935           0 :         if( !sLine.isEmpty() )
    3936             :         {
    3937             :             //comments are contained in separate lines but are put into the struct of the following data
    3938             :             //line (if available)
    3939           0 :             if( '#' != sLine[0] )
    3940             :             {
    3941           0 :                 if( !pToInsert )
    3942           0 :                     pToInsert = new AutoMarkEntry;
    3943             : 
    3944           0 :                 sal_Int32 nSttPos = 0;
    3945           0 :                 pToInsert->sSearch      = sLine.getToken(0, ';', nSttPos );
    3946           0 :                 pToInsert->sAlternative = sLine.getToken(0, ';', nSttPos );
    3947           0 :                 pToInsert->sPrimKey     = sLine.getToken(0, ';', nSttPos );
    3948           0 :                 pToInsert->sSecKey      = sLine.getToken(0, ';', nSttPos );
    3949             : 
    3950           0 :                 OUString sStr = sLine.getToken(0, ';', nSttPos );
    3951           0 :                 pToInsert->bCase = !sStr.isEmpty() && !comphelper::string::equals(sStr, '0');
    3952             : 
    3953           0 :                 sStr = sLine.getToken(0, ';', nSttPos );
    3954           0 :                 pToInsert->bWord = !sStr.isEmpty() && !comphelper::string::equals(sStr, '0');
    3955             : 
    3956           0 :                 aEntryArr.push_back( pToInsert );
    3957           0 :                 pToInsert = 0;
    3958             :             }
    3959             :             else
    3960             :             {
    3961           0 :                 if(pToInsert)
    3962           0 :                     aEntryArr.push_back(pToInsert);
    3963           0 :                 pToInsert = new AutoMarkEntry;
    3964           0 :                 pToInsert->sComment = sLine.copy(1);
    3965             :             }
    3966             :         }
    3967           0 :     }
    3968           0 :     if( pToInsert )
    3969           0 :         aEntryArr.push_back(pToInsert);
    3970           0 :     RowInserted(0, aEntryArr.size() + 1, true);
    3971           0 : }
    3972             : 
    3973           0 : void SwEntryBrowseBox::WriteEntries(SvStream& rOutStr)
    3974             : {
    3975             :     //check if the current controller is modified
    3976           0 :     const sal_uInt16 nCol = GetCurColumnId();
    3977             :     ::svt::CellController* pController;
    3978           0 :     if(nCol < ITEM_CASE)
    3979           0 :         pController = xController;
    3980             :     else
    3981           0 :         pController = xCheckController;
    3982           0 :     if(pController ->IsModified())
    3983           0 :         GoToColumnId(nCol + (nCol < ITEM_CASE ? 1 : -1 ));
    3984             : 
    3985           0 :     rtl_TextEncoding  eTEnc = osl_getThreadTextEncoding();
    3986           0 :     for(size_t i = 0; i < aEntryArr.size(); i++)
    3987             :     {
    3988           0 :         AutoMarkEntry* pEntry = &aEntryArr[i];
    3989           0 :         if(!pEntry->sComment.isEmpty())
    3990             :         {
    3991           0 :             rOutStr.WriteByteStringLine( "#" + pEntry->sComment, eTEnc );
    3992             :         }
    3993             : 
    3994           0 :         OUString sWrite( pEntry->sSearch + ";" +
    3995           0 :                          pEntry->sAlternative + ";" +
    3996           0 :                          pEntry->sPrimKey  + ";" +
    3997           0 :                          pEntry->sSecKey + ";" +
    3998           0 :                          (pEntry->bCase ? OUString("1") : OUString("0")) + ";" +
    3999           0 :                          (pEntry->bWord ? OUString("1") : OUString("0")) );
    4000             : 
    4001           0 :         if( sWrite.getLength() > 5 )
    4002           0 :             rOutStr.WriteByteStringLine( sWrite, eTEnc );
    4003           0 :     }
    4004           0 : }
    4005             : 
    4006           0 : bool SwEntryBrowseBox::IsModified()const
    4007             : {
    4008           0 :     if(bModified)
    4009           0 :         return true;
    4010             : 
    4011             :     //check if the current controller is modified
    4012           0 :     const sal_uInt16 nCol = GetCurColumnId();
    4013             :     ::svt::CellController* pController;
    4014           0 :     if(nCol < ITEM_CASE)
    4015           0 :         pController = xController;
    4016             :     else
    4017           0 :         pController = xCheckController;
    4018           0 :     return pController->IsModified();
    4019             : }
    4020             : 
    4021           0 : SwAutoMarkDlg_Impl::SwAutoMarkDlg_Impl(Window* pParent, const OUString& rAutoMarkURL,
    4022             :         const OUString& rAutoMarkType, bool bCreate)
    4023             :     : ModalDialog(pParent, "CreateAutomarkDialog",
    4024             :         "modules/swriter/ui/createautomarkdialog.ui")
    4025             :     , sAutoMarkURL(rAutoMarkURL)
    4026             :     , sAutoMarkType(rAutoMarkType)
    4027           0 :     , bCreateMode(bCreate)
    4028             : {
    4029           0 :     get(m_pOKPB, "ok");
    4030           0 :     m_pEntriesBB = new SwEntryBrowseBox(get<VclContainer>("area"), this);
    4031           0 :     m_pEntriesBB->set_expand(true);
    4032           0 :     m_pEntriesBB->Show();
    4033           0 :     m_pOKPB->SetClickHdl(LINK(this, SwAutoMarkDlg_Impl, OkHdl));
    4034             : 
    4035           0 :     SetText(GetText() + ": " + sAutoMarkURL);
    4036           0 :     bool bError = false;
    4037           0 :     if( bCreateMode )
    4038           0 :         m_pEntriesBB->RowInserted(0, 1, true);
    4039             :     else
    4040             :     {
    4041           0 :         SfxMedium aMed( sAutoMarkURL, STREAM_STD_READ );
    4042           0 :         if( aMed.GetInStream() && !aMed.GetInStream()->GetError() )
    4043           0 :             m_pEntriesBB->ReadEntries( *aMed.GetInStream() );
    4044             :         else
    4045           0 :             bError = true;
    4046             :     }
    4047             : 
    4048           0 :     if(bError)
    4049           0 :         EndDialog(RET_CANCEL);
    4050           0 : }
    4051             : 
    4052           0 : SwAutoMarkDlg_Impl::~SwAutoMarkDlg_Impl()
    4053             : {
    4054           0 :     delete m_pEntriesBB;
    4055           0 : }
    4056             : 
    4057           0 : IMPL_LINK_NOARG(SwAutoMarkDlg_Impl, OkHdl)
    4058             : {
    4059           0 :     bool bError = false;
    4060           0 :     if(m_pEntriesBB->IsModified() || bCreateMode)
    4061             :     {
    4062             :         SfxMedium aMed( sAutoMarkURL,
    4063             :                         bCreateMode ? STREAM_WRITE
    4064           0 :                                     : STREAM_WRITE| STREAM_TRUNC );
    4065           0 :         SvStream* pStrm = aMed.GetOutStream();
    4066           0 :         pStrm->SetStreamCharSet( RTL_TEXTENCODING_MS_1253 );
    4067           0 :         if( !pStrm->GetError() )
    4068             :         {
    4069           0 :             m_pEntriesBB->WriteEntries( *pStrm );
    4070           0 :             aMed.Commit();
    4071             :         }
    4072             :         else
    4073           0 :             bError = true;
    4074             :     }
    4075           0 :     if( !bError )
    4076           0 :         EndDialog(RET_OK);
    4077           0 :     return 0;
    4078           0 : }
    4079             : 
    4080             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10