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

Generated by: LCOV version 1.10