LCOV - code coverage report
Current view: top level - sw/source/ui/dialog - uiregionsw.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 1287 0.0 %
Date: 2014-11-03 Functions: 0 123 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 <hintids.hxx>
      21             : #include <regionsw.hxx>
      22             : #include <svl/urihelper.hxx>
      23             : #include <svl/PasswordHelper.hxx>
      24             : #include <vcl/svapp.hxx>
      25             : #include <vcl/layout.hxx>
      26             : #include <svl/stritem.hxx>
      27             : #include <svl/eitem.hxx>
      28             : #include <sfx2/passwd.hxx>
      29             : #include <sfx2/docfilt.hxx>
      30             : #include <sfx2/request.hxx>
      31             : #include <sfx2/docfile.hxx>
      32             : #include <sfx2/linkmgr.hxx>
      33             : #include <sfx2/docinsert.hxx>
      34             : #include <sfx2/filedlghelper.hxx>
      35             : #include <editeng/sizeitem.hxx>
      36             : #include <svtools/htmlcfg.hxx>
      37             : #include <svtools/treelistentry.hxx>
      38             : 
      39             : #include <comphelper/storagehelper.hxx>
      40             : #include <uitool.hxx>
      41             : #include <IMark.hxx>
      42             : #include <section.hxx>
      43             : #include <docary.hxx>
      44             : #include <doc.hxx>
      45             : #include <basesh.hxx>
      46             : #include <wdocsh.hxx>
      47             : #include <view.hxx>
      48             : #include <swmodule.hxx>
      49             : #include <wrtsh.hxx>
      50             : #include <swundo.hxx>
      51             : #include <column.hxx>
      52             : #include <fmtfsize.hxx>
      53             : #include <shellio.hxx>
      54             : 
      55             : #include <helpid.h>
      56             : #include <cmdid.h>
      57             : #include <../../uibase/dialog/regionsw.hrc>
      58             : #include <comcore.hrc>
      59             : #include <globals.hrc>
      60             : #include <sfx2/bindings.hxx>
      61             : #include <sfx2/htmlmode.hxx>
      62             : #include <svx/dlgutil.hxx>
      63             : #include <svx/dialogs.hrc>
      64             : #include <svx/svxdlg.hxx>
      65             : #include <svx/flagsdef.hxx>
      66             : #include <boost/scoped_ptr.hpp>
      67             : 
      68             : using namespace ::com::sun::star;
      69             : 
      70             : static void   lcl_ReadSections( SfxMedium& rMedium, ComboBox& rBox );
      71             : 
      72           0 : static void lcl_FillList( SwWrtShell& rSh, ComboBox& rSubRegions, ComboBox* pAvailNames, const SwSectionFmt* pNewFmt )
      73             : {
      74             :     const SwSectionFmt* pFmt;
      75           0 :     if( !pNewFmt )
      76             :     {
      77           0 :         const sal_uInt16 nCount = rSh.GetSectionFmtCount();
      78           0 :         for(sal_uInt16 i=0;i<nCount;i++)
      79             :         {
      80             :             SectionType eTmpType;
      81           0 :             if( !(pFmt = &rSh.GetSectionFmt(i))->GetParent() &&
      82           0 :                     pFmt->IsInNodesArr() &&
      83           0 :                     (eTmpType = pFmt->GetSection()->GetType()) != TOX_CONTENT_SECTION
      84           0 :                     && TOX_HEADER_SECTION != eTmpType )
      85             :             {
      86           0 :                     const OUString sString(pFmt->GetSection()->GetSectionName());
      87           0 :                     if(pAvailNames)
      88           0 :                         pAvailNames->InsertEntry(sString);
      89           0 :                     rSubRegions.InsertEntry(sString);
      90           0 :                     lcl_FillList( rSh, rSubRegions, pAvailNames, pFmt );
      91             :             }
      92             :         }
      93             :     }
      94             :     else
      95             :     {
      96           0 :         SwSections aTmpArr;
      97           0 :         const sal_uInt16 nCnt = pNewFmt->GetChildSections(aTmpArr,SORTSECT_POS);
      98           0 :         if( nCnt )
      99             :         {
     100             :             SectionType eTmpType;
     101           0 :             for( sal_uInt16 n = 0; n < nCnt; ++n )
     102           0 :                 if( (pFmt = aTmpArr[n]->GetFmt())->IsInNodesArr()&&
     103           0 :                     (eTmpType = pFmt->GetSection()->GetType()) != TOX_CONTENT_SECTION
     104           0 :                     && TOX_HEADER_SECTION != eTmpType )
     105             :                 {
     106           0 :                     const OUString sString(pFmt->GetSection()->GetSectionName());
     107           0 :                     if(pAvailNames)
     108           0 :                         pAvailNames->InsertEntry(sString);
     109           0 :                     rSubRegions.InsertEntry(sString);
     110           0 :                     lcl_FillList( rSh, rSubRegions, pAvailNames, pFmt );
     111             :                 }
     112           0 :         }
     113             :     }
     114           0 : }
     115             : 
     116           0 : static void lcl_FillSubRegionList( SwWrtShell& rSh, ComboBox& rSubRegions, ComboBox* pAvailNames )
     117             : {
     118           0 :     lcl_FillList( rSh, rSubRegions, pAvailNames, 0 );
     119           0 :     IDocumentMarkAccess* const pMarkAccess = rSh.getIDocumentMarkAccess();
     120           0 :     for( IDocumentMarkAccess::const_iterator_t ppMark = pMarkAccess->getBookmarksBegin();
     121           0 :         ppMark != pMarkAccess->getBookmarksBegin();
     122             :         ++ppMark)
     123             :     {
     124           0 :         const ::sw::mark::IMark* pBkmk = ppMark->get();
     125           0 :         if( pBkmk->IsExpanded() )
     126           0 :             rSubRegions.InsertEntry( pBkmk->GetName() );
     127             :     }
     128           0 : }
     129             : 
     130             : // user data class for region information
     131           0 : class SectRepr
     132             : {
     133             : private:
     134             :     SwSectionData           m_SectionData;
     135             :     SwFmtCol                m_Col;
     136             :     SvxBrushItem            m_Brush;
     137             :     SwFmtFtnAtTxtEnd        m_FtnNtAtEnd;
     138             :     SwFmtEndAtTxtEnd        m_EndNtAtEnd;
     139             :     SwFmtNoBalancedColumns  m_Balance;
     140             :     SvxFrameDirectionItem   m_FrmDirItem;
     141             :     SvxLRSpaceItem          m_LRSpaceItem;
     142             :     sal_uInt16                  m_nArrPos;
     143             :     // shows, if maybe textcontent is in the region
     144             :     bool                    m_bContent  : 1;
     145             :     // for multiselection, mark at first, then work with TreeListBox!
     146             :     bool                    m_bSelected : 1;
     147             :     uno::Sequence<sal_Int8> m_TempPasswd;
     148             : 
     149             : public:
     150             :     SectRepr(sal_uInt16 nPos, SwSection& rSect);
     151             : 
     152           0 :     bool    operator< (const SectRepr& rSectRef) const
     153           0 :             { return m_nArrPos <  rSectRef.GetArrPos(); }
     154             : 
     155           0 :     SwSectionData &     GetSectionData()        { return m_SectionData; }
     156           0 :     SwFmtCol&               GetCol()            { return m_Col; }
     157           0 :     SvxBrushItem&           GetBackground()     { return m_Brush; }
     158           0 :     SwFmtFtnAtTxtEnd&       GetFtnNtAtEnd()     { return m_FtnNtAtEnd; }
     159           0 :     SwFmtEndAtTxtEnd&       GetEndNtAtEnd()     { return m_EndNtAtEnd; }
     160           0 :     SwFmtNoBalancedColumns& GetBalance()        { return m_Balance; }
     161           0 :     SvxFrameDirectionItem&  GetFrmDir()         { return m_FrmDirItem; }
     162           0 :     SvxLRSpaceItem&         GetLRSpace()        { return m_LRSpaceItem; }
     163             : 
     164           0 :     sal_uInt16              GetArrPos() const { return m_nArrPos; }
     165             :     OUString            GetFile() const;
     166             :     OUString            GetSubRegion() const;
     167             :     void                SetFile(OUString const& rFile);
     168             :     void                SetFilter(OUString const& rFilter);
     169             :     void                SetSubRegion(OUString const& rSubRegion);
     170             : 
     171           0 :     bool                IsContent() { return m_bContent; }
     172           0 :     void                SetContent(bool const bValue) { m_bContent = bValue; }
     173             : 
     174           0 :     void                SetSelected() { m_bSelected = true; }
     175           0 :     bool                IsSelected() const { return m_bSelected; }
     176             : 
     177           0 :     uno::Sequence<sal_Int8> & GetTempPasswd() { return m_TempPasswd; }
     178           0 :     void SetTempPasswd(const uno::Sequence<sal_Int8> & rPasswd)
     179           0 :         { m_TempPasswd = rPasswd; }
     180             : };
     181             : 
     182           0 : SectRepr::SectRepr( sal_uInt16 nPos, SwSection& rSect )
     183             :     : m_SectionData( rSect )
     184             :     , m_Brush( RES_BACKGROUND )
     185             :     , m_FrmDirItem( FRMDIR_ENVIRONMENT, RES_FRAMEDIR )
     186             :     , m_LRSpaceItem( RES_LR_SPACE )
     187             :     , m_nArrPos(nPos)
     188           0 :     , m_bContent(m_SectionData.GetLinkFileName().isEmpty())
     189           0 :     , m_bSelected(false)
     190             : {
     191           0 :     SwSectionFmt *pFmt = rSect.GetFmt();
     192           0 :     if( pFmt )
     193             :     {
     194           0 :         m_Col = pFmt->GetCol();
     195           0 :         m_Brush = pFmt->makeBackgroundBrushItem();
     196           0 :         m_FtnNtAtEnd = pFmt->GetFtnAtTxtEnd();
     197           0 :         m_EndNtAtEnd = pFmt->GetEndAtTxtEnd();
     198           0 :         m_Balance.SetValue(pFmt->GetBalancedColumns().GetValue());
     199           0 :         m_FrmDirItem = pFmt->GetFrmDir();
     200           0 :         m_LRSpaceItem = pFmt->GetLRSpace();
     201             :     }
     202           0 : }
     203             : 
     204           0 : void SectRepr::SetFile( const OUString& rFile )
     205             : {
     206             :     OUString sNewFile( INetURLObject::decode( rFile, '%',
     207             :                                            INetURLObject::DECODE_UNAMBIGUOUS,
     208           0 :                                         RTL_TEXTENCODING_UTF8 ));
     209           0 :     const OUString sOldFileName( m_SectionData.GetLinkFileName() );
     210           0 :     const OUString sSub( sOldFileName.getToken( 2, sfx2::cTokenSeparator ) );
     211             : 
     212           0 :     if( !rFile.isEmpty() || !sSub.isEmpty() )
     213             :     {
     214           0 :         sNewFile += OUString(sfx2::cTokenSeparator);
     215           0 :         if( !rFile.isEmpty() ) // Filter only with FileName
     216           0 :             sNewFile += sOldFileName.getToken( 1, sfx2::cTokenSeparator );
     217             : 
     218           0 :         sNewFile += OUString(sfx2::cTokenSeparator) + sSub;
     219             :     }
     220             : 
     221           0 :     m_SectionData.SetLinkFileName( sNewFile );
     222             : 
     223           0 :     if( !rFile.isEmpty() || !sSub.isEmpty() )
     224             :     {
     225           0 :         m_SectionData.SetType( FILE_LINK_SECTION );
     226             :     }
     227             :     else
     228             :     {
     229           0 :         m_SectionData.SetType( CONTENT_SECTION );
     230           0 :     }
     231           0 : }
     232             : 
     233           0 : void SectRepr::SetFilter( const OUString& rFilter )
     234             : {
     235           0 :     OUString sNewFile;
     236           0 :     const OUString sOldFileName( m_SectionData.GetLinkFileName() );
     237           0 :     const OUString sFile( sOldFileName.getToken( 0, sfx2::cTokenSeparator ) );
     238           0 :     const OUString sSub( sOldFileName.getToken( 2, sfx2::cTokenSeparator ) );
     239             : 
     240           0 :     if( !sFile.isEmpty() )
     241           0 :         sNewFile = sFile + OUString(sfx2::cTokenSeparator) +
     242           0 :                    rFilter + OUString(sfx2::cTokenSeparator) + sSub;
     243           0 :     else if( !sSub.isEmpty() )
     244           0 :         sNewFile = OUString(sfx2::cTokenSeparator) + OUString(sfx2::cTokenSeparator) + sSub;
     245             : 
     246           0 :     m_SectionData.SetLinkFileName( sNewFile );
     247             : 
     248           0 :     if( !sNewFile.isEmpty() )
     249             :     {
     250           0 :         m_SectionData.SetType( FILE_LINK_SECTION );
     251           0 :     }
     252           0 : }
     253             : 
     254           0 : void SectRepr::SetSubRegion(const OUString& rSubRegion)
     255             : {
     256           0 :     OUString sNewFile;
     257           0 :     sal_Int32 n(0);
     258           0 :     const OUString sLinkFileName(m_SectionData.GetLinkFileName());
     259           0 :     const OUString sOldFileName( sLinkFileName.getToken( 0, sfx2::cTokenSeparator, n ) );
     260           0 :     const OUString sFilter( sLinkFileName.getToken( 0, sfx2::cTokenSeparator, n ) );
     261             : 
     262           0 :     if( !rSubRegion.isEmpty() || !sOldFileName.isEmpty() )
     263           0 :         sNewFile = sOldFileName + OUString(sfx2::cTokenSeparator) +
     264           0 :                    sFilter + OUString(sfx2::cTokenSeparator) + rSubRegion;
     265             : 
     266           0 :     m_SectionData.SetLinkFileName( sNewFile );
     267             : 
     268           0 :     if( !rSubRegion.isEmpty() || !sOldFileName.isEmpty() )
     269             :     {
     270           0 :         m_SectionData.SetType( FILE_LINK_SECTION );
     271             :     }
     272             :     else
     273             :     {
     274           0 :         m_SectionData.SetType( CONTENT_SECTION );
     275           0 :     }
     276           0 : }
     277             : 
     278           0 : OUString SectRepr::GetFile() const
     279             : {
     280           0 :     const OUString sLinkFile( m_SectionData.GetLinkFileName() );
     281             : 
     282           0 :     if( sLinkFile.isEmpty() )
     283             :     {
     284           0 :         return sLinkFile;
     285             :     }
     286           0 :     if (DDE_LINK_SECTION == m_SectionData.GetType())
     287             :     {
     288           0 :         sal_Int32 n = 0;
     289             :         return sLinkFile.replaceFirst( OUString(sfx2::cTokenSeparator), " ", &n )
     290           0 :                         .replaceFirst( OUString(sfx2::cTokenSeparator), " ", &n );
     291             :     }
     292             :     return INetURLObject::decode( sLinkFile.getToken( 0, sfx2::cTokenSeparator ),
     293             :                                   '%',
     294             :                                   INetURLObject::DECODE_UNAMBIGUOUS,
     295           0 :                                   RTL_TEXTENCODING_UTF8 );
     296             : }
     297             : 
     298           0 : OUString SectRepr::GetSubRegion() const
     299             : {
     300           0 :     const OUString sLinkFile( m_SectionData.GetLinkFileName() );
     301           0 :     if( !sLinkFile.isEmpty() )
     302           0 :         return sLinkFile.getToken( 2, sfx2::cTokenSeparator );
     303           0 :     return sLinkFile;
     304             : }
     305             : 
     306             : // dialog edit regions
     307           0 : SwEditRegionDlg::SwEditRegionDlg( vcl::Window* pParent, SwWrtShell& rWrtSh )
     308             :     : SfxModalDialog(pParent, "EditSectionDialog",
     309             :         "modules/swriter/ui/editsectiondialog.ui")
     310             :     , m_bSubRegionsFilled(false)
     311             :     , aImageIL(SW_RES(IL_SECTION_BITMAPS))
     312             :     , rSh(rWrtSh)
     313             :     , m_pDocInserter(NULL)
     314             :     , m_pOldDefDlgParent(NULL)
     315           0 :     , bDontCheckPasswd(true)
     316             : {
     317           0 :     get(m_pCurName, "curname");
     318           0 :     get(m_pTree, "tree");
     319           0 :     m_pTree->set_height_request(m_pTree->GetTextHeight() * 16);
     320           0 :     get(m_pFileCB, "link");
     321           0 :     m_pFileCB->SetState(TRISTATE_FALSE);
     322           0 :     get(m_pDDECB, "dde");
     323           0 :     get(m_pDDEFrame, "ddedepend");
     324           0 :     get(m_pFileNameFT, "filenameft");
     325           0 :     get(m_pDDECommandFT, "ddeft");
     326           0 :     get(m_pFileNameED, "filename");
     327           0 :     get(m_pFilePB, "file");
     328           0 :     get(m_pSubRegionFT, "sectionft");
     329           0 :     get(m_pSubRegionED, "section");
     330           0 :     m_pSubRegionED->SetStyle(m_pSubRegionED->GetStyle() | WB_SORT);
     331           0 :     get(m_pProtectCB, "protect");
     332           0 :     m_pProtectCB->SetState(TRISTATE_FALSE);
     333           0 :     get(m_pPasswdCB, "withpassword");
     334           0 :     get(m_pPasswdPB, "password");
     335           0 :     get(m_pHideCB, "hide");
     336           0 :     m_pHideCB->SetState(TRISTATE_FALSE);
     337           0 :     get(m_pConditionFT, "conditionft");
     338           0 :     get(m_pConditionED, "condition");
     339             :     // edit in readonly sections
     340           0 :     get(m_pEditInReadonlyCB, "editinro");
     341           0 :     m_pEditInReadonlyCB->SetState(TRISTATE_FALSE);
     342           0 :     get(m_pOptionsPB, "options");
     343           0 :     get(m_pDismiss, "remove");
     344           0 :     get(m_pOK, "ok");
     345             : 
     346           0 :     bWeb = 0 != PTR_CAST( SwWebDocShell, rSh.GetView().GetDocShell() );
     347             : 
     348           0 :     m_pTree->SetSelectHdl(LINK(this, SwEditRegionDlg, GetFirstEntryHdl));
     349           0 :     m_pTree->SetDeselectHdl(LINK(this, SwEditRegionDlg, DeselectHdl));
     350           0 :     m_pCurName->SetModifyHdl(LINK(this, SwEditRegionDlg, NameEditHdl));
     351           0 :     m_pConditionED->SetModifyHdl( LINK( this, SwEditRegionDlg, ConditionEditHdl));
     352           0 :     m_pOK->SetClickHdl         ( LINK( this, SwEditRegionDlg, OkHdl));
     353           0 :     m_pPasswdCB->SetClickHdl(LINK(this, SwEditRegionDlg, ChangePasswdHdl));
     354           0 :     m_pPasswdPB->SetClickHdl(LINK(this, SwEditRegionDlg, ChangePasswdHdl));
     355           0 :     m_pHideCB->SetClickHdl(LINK(this, SwEditRegionDlg, ChangeHideHdl));
     356             :     // edit in readonly sections
     357           0 :     m_pEditInReadonlyCB->SetClickHdl(LINK(this, SwEditRegionDlg, ChangeEditInReadonlyHdl));
     358             : 
     359           0 :     m_pOptionsPB->SetClickHdl(LINK(this, SwEditRegionDlg, OptionsHdl));
     360           0 :     m_pProtectCB->SetClickHdl(LINK(this, SwEditRegionDlg, ChangeProtectHdl));
     361           0 :     m_pDismiss->SetClickHdl    ( LINK( this, SwEditRegionDlg, ChangeDismissHdl));
     362           0 :     m_pFileCB->SetClickHdl(LINK(this, SwEditRegionDlg, UseFileHdl));
     363           0 :     m_pFilePB->SetClickHdl(LINK(this, SwEditRegionDlg, FileSearchHdl));
     364           0 :     m_pFileNameED->SetModifyHdl(LINK(this, SwEditRegionDlg, FileNameHdl));
     365           0 :     m_pSubRegionED->SetModifyHdl(LINK(this, SwEditRegionDlg, FileNameHdl));
     366           0 :     m_pSubRegionED->AddEventListener(LINK(this, SwEditRegionDlg, SubRegionEventHdl));
     367           0 :     m_pSubRegionED->EnableAutocomplete(true, true);
     368             : 
     369           0 :     m_pTree->SetSelectionMode( MULTIPLE_SELECTION );
     370           0 :     m_pTree->SetStyle(m_pTree->GetStyle()|WB_HASBUTTONSATROOT|WB_CLIPCHILDREN|WB_HSCROLL);
     371           0 :     m_pTree->SetSpaceBetweenEntries(0);
     372           0 :     m_pTree->SetAllEntriesAccessibleRoleType(TREEBOX_ALLITEM_ACCROLE_TYPE_TREE);
     373             : 
     374           0 :     if(bWeb)
     375             :     {
     376           0 :         m_pDDECB->Hide();
     377           0 :         get<VclContainer>("hideframe")->Hide();
     378           0 :         m_pPasswdCB->Hide();
     379             :     }
     380             : 
     381           0 :     m_pDDECB->SetClickHdl(LINK(this, SwEditRegionDlg, DDEHdl));
     382             : 
     383           0 :     pCurrSect = rSh.GetCurrSection();
     384           0 :     RecurseList( 0, 0 );
     385             :     // if the cursor is not in a region
     386             :     // the first one will always be selected
     387           0 :     if( !m_pTree->FirstSelected() && m_pTree->First() )
     388           0 :         m_pTree->Select( m_pTree->First() );
     389           0 :     m_pTree->Show();
     390           0 :     bDontCheckPasswd = false;
     391           0 : }
     392             : 
     393           0 : bool SwEditRegionDlg::CheckPasswd(CheckBox* pBox)
     394             : {
     395           0 :     if(bDontCheckPasswd)
     396           0 :         return true;
     397           0 :     bool bRet = true;
     398           0 :     SvTreeListEntry* pEntry = m_pTree->FirstSelected();
     399           0 :     while( pEntry )
     400             :     {
     401           0 :         SectReprPtr pRepr = (SectReprPtr)pEntry->GetUserData();
     402           0 :         if (!pRepr->GetTempPasswd().getLength()
     403           0 :             && pRepr->GetSectionData().GetPassword().getLength())
     404             :         {
     405           0 :             SfxPasswordDialog aPasswdDlg(this);
     406           0 :             bRet = false;
     407           0 :             if (aPasswdDlg.Execute())
     408             :             {
     409           0 :                 const OUString sNewPasswd( aPasswdDlg.GetPassword() );
     410           0 :                 ::com::sun::star::uno::Sequence <sal_Int8 > aNewPasswd;
     411           0 :                 SvPasswordHelper::GetHashPassword( aNewPasswd, sNewPasswd );
     412           0 :                 if (SvPasswordHelper::CompareHashPassword(
     413           0 :                         pRepr->GetSectionData().GetPassword(), sNewPasswd))
     414             :                 {
     415           0 :                     pRepr->SetTempPasswd(aNewPasswd);
     416           0 :                     bRet = true;
     417             :                 }
     418             :                 else
     419             :                 {
     420           0 :                     MessageDialog(this, SW_RES(STR_WRONG_PASSWORD), VCL_MESSAGE_INFO).Execute();
     421           0 :                 }
     422           0 :             }
     423             :         }
     424           0 :         pEntry = m_pTree->NextSelected(pEntry);
     425             :     }
     426           0 :     if(!bRet && pBox)
     427             :     {
     428             :         //reset old button state
     429           0 :         if(pBox->IsTriStateEnabled())
     430           0 :             pBox->SetState(pBox->IsChecked() ? TRISTATE_FALSE : TRISTATE_INDET);
     431             :         else
     432           0 :             pBox->Check(!pBox->IsChecked());
     433             :     }
     434             : 
     435           0 :     return bRet;
     436             : }
     437             : 
     438             : // recursively look for child-sections
     439           0 : void SwEditRegionDlg::RecurseList( const SwSectionFmt* pFmt, SvTreeListEntry* pEntry )
     440             : {
     441           0 :     SwSection* pSect = 0;
     442           0 :     SvTreeListEntry* pSelEntry = 0;
     443           0 :     if (!pFmt)
     444             :     {
     445           0 :         const sal_uInt16 nCount=rSh.GetSectionFmtCount();
     446           0 :         for ( sal_uInt16 n=0; n < nCount; n++ )
     447             :         {
     448             :             SectionType eTmpType;
     449           0 :             if( !( pFmt = &rSh.GetSectionFmt(n))->GetParent() &&
     450           0 :                 pFmt->IsInNodesArr() &&
     451           0 :                 (eTmpType = pFmt->GetSection()->GetType()) != TOX_CONTENT_SECTION
     452           0 :                 && TOX_HEADER_SECTION != eTmpType )
     453             :             {
     454             :                 SectRepr* pSectRepr = new SectRepr( n,
     455           0 :                                             *(pSect=pFmt->GetSection()) );
     456           0 :                 Image aImg = BuildBitmap( pSect->IsProtect(),pSect->IsHidden());
     457           0 :                 pEntry = m_pTree->InsertEntry(pSect->GetSectionName(), aImg, aImg);
     458           0 :                 pEntry->SetUserData(pSectRepr);
     459           0 :                 RecurseList( pFmt, pEntry );
     460           0 :                 if (pEntry->HasChildren())
     461           0 :                     m_pTree->Expand(pEntry);
     462           0 :                 if (pCurrSect==pSect)
     463           0 :                     m_pTree->Select(pEntry);
     464             :             }
     465             :         }
     466             :     }
     467             :     else
     468             :     {
     469           0 :         SwSections aTmpArr;
     470             :         SvTreeListEntry* pNEntry;
     471           0 :         const sal_uInt16 nCnt = pFmt->GetChildSections(aTmpArr,SORTSECT_POS);
     472           0 :         if( nCnt )
     473             :         {
     474           0 :             for( sal_uInt16 n = 0; n < nCnt; ++n )
     475             :             {
     476             :                 SectionType eTmpType;
     477           0 :                 pFmt = aTmpArr[n]->GetFmt();
     478           0 :                 if( pFmt->IsInNodesArr() &&
     479           0 :                     (eTmpType = pFmt->GetSection()->GetType()) != TOX_CONTENT_SECTION
     480           0 :                     && TOX_HEADER_SECTION != eTmpType )
     481             :                 {
     482           0 :                     pSect=aTmpArr[n];
     483             :                     SectRepr* pSectRepr=new SectRepr(
     484           0 :                                     FindArrPos( pSect->GetFmt() ), *pSect );
     485           0 :                     Image aImage = BuildBitmap( pSect->IsProtect(),
     486           0 :                                             pSect->IsHidden());
     487             :                     pNEntry = m_pTree->InsertEntry(
     488           0 :                         pSect->GetSectionName(), aImage, aImage, pEntry);
     489           0 :                     pNEntry->SetUserData(pSectRepr);
     490           0 :                     RecurseList( aTmpArr[n]->GetFmt(), pNEntry );
     491           0 :                     if( pNEntry->HasChildren())
     492           0 :                         m_pTree->Expand(pNEntry);
     493           0 :                     if (pCurrSect==pSect)
     494           0 :                         pSelEntry = pNEntry;
     495             :                 }
     496             :             }
     497           0 :         }
     498             :     }
     499           0 :     if(0 != pSelEntry)
     500             :     {
     501           0 :         m_pTree->MakeVisible(pSelEntry);
     502           0 :         m_pTree->Select(pSelEntry);
     503             :     }
     504           0 : }
     505             : 
     506           0 : sal_uInt16 SwEditRegionDlg::FindArrPos(const SwSectionFmt* pFmt )
     507             : {
     508           0 :     const sal_uInt16 nCount=rSh.GetSectionFmtCount();
     509           0 :     for (sal_uInt16 i=0;i<nCount;i++)
     510           0 :         if (pFmt==&rSh.GetSectionFmt(i))
     511           0 :             return i;
     512             : 
     513             :     OSL_FAIL("SectionFormat not on the list" );
     514           0 :     return USHRT_MAX;
     515             : }
     516             : 
     517           0 : SwEditRegionDlg::~SwEditRegionDlg( )
     518             : {
     519           0 :     SvTreeListEntry* pEntry = m_pTree->First();
     520           0 :     while( pEntry )
     521             :     {
     522           0 :         delete (SectRepr*)pEntry->GetUserData();
     523           0 :         pEntry = m_pTree->Next( pEntry );
     524             :     }
     525             : 
     526           0 :     delete m_pDocInserter;
     527           0 : }
     528             : 
     529           0 : void    SwEditRegionDlg::SelectSection(const OUString& rSectionName)
     530             : {
     531           0 :     SvTreeListEntry* pEntry = m_pTree->First();
     532           0 :     while(pEntry)
     533             :     {
     534           0 :         SectReprPtr pRepr = (SectReprPtr)pEntry->GetUserData();
     535           0 :         if (pRepr->GetSectionData().GetSectionName() == rSectionName)
     536           0 :             break;
     537           0 :         pEntry = m_pTree->Next(pEntry);
     538             :     }
     539           0 :     if(pEntry)
     540             :     {
     541           0 :         m_pTree->SelectAll(false);
     542           0 :         m_pTree->Select(pEntry);
     543           0 :         m_pTree->MakeVisible(pEntry);
     544             :     }
     545           0 : }
     546             : 
     547             : // selected entry in TreeListBox is showed in Edit window in case of
     548             : // multiselection some controls are disabled
     549           0 : IMPL_LINK( SwEditRegionDlg, GetFirstEntryHdl, SvTreeListBox *, pBox )
     550             : {
     551           0 :     bDontCheckPasswd = true;
     552           0 :     SvTreeListEntry* pEntry=pBox->FirstSelected();
     553           0 :     m_pHideCB->Enable(true);
     554             :     // edit in readonly sections
     555           0 :     m_pEditInReadonlyCB->Enable(true);
     556             : 
     557           0 :     m_pProtectCB->Enable(true);
     558           0 :     m_pFileCB->Enable(true);
     559           0 :     ::com::sun::star::uno::Sequence <sal_Int8> aCurPasswd;
     560           0 :     if( 1 < pBox->GetSelectionCount() )
     561             :     {
     562           0 :         m_pHideCB->EnableTriState(true);
     563           0 :         m_pProtectCB->EnableTriState(true);
     564             :         // edit in readonly sections
     565           0 :         m_pEditInReadonlyCB->EnableTriState(true);
     566             : 
     567           0 :         m_pFileCB->EnableTriState(true);
     568             : 
     569           0 :         bool bHiddenValid       = true;
     570           0 :         bool bProtectValid      = true;
     571           0 :         bool bConditionValid    = true;
     572             :         // edit in readonly sections
     573           0 :         bool bEditInReadonlyValid = true;
     574           0 :         bool bEditInReadonly    = true;
     575             : 
     576           0 :         bool bHidden            = true;
     577           0 :         bool bProtect           = true;
     578           0 :         OUString sCondition;
     579           0 :         bool bFirst             = true;
     580           0 :         bool bFileValid         = true;
     581           0 :         bool bFile              = true;
     582           0 :         bool bPasswdValid       = true;
     583             : 
     584           0 :         while( pEntry )
     585             :         {
     586           0 :             SectRepr* pRepr=(SectRepr*) pEntry->GetUserData();
     587           0 :             SwSectionData const& rData( pRepr->GetSectionData() );
     588           0 :             if(bFirst)
     589             :             {
     590           0 :                 sCondition      = rData.GetCondition();
     591           0 :                 bHidden         = rData.IsHidden();
     592           0 :                 bProtect        = rData.IsProtectFlag();
     593             :                 // edit in readonly sections
     594           0 :                 bEditInReadonly = rData.IsEditInReadonlyFlag();
     595             : 
     596           0 :                 bFile           = (rData.GetType() != CONTENT_SECTION);
     597           0 :                 aCurPasswd      = rData.GetPassword();
     598             :             }
     599             :             else
     600             :             {
     601           0 :                 if(sCondition != rData.GetCondition())
     602           0 :                     bConditionValid = false;
     603           0 :                 bHiddenValid      = (bHidden == rData.IsHidden());
     604           0 :                 bProtectValid     = (bProtect == rData.IsProtectFlag());
     605             :                 // edit in readonly sections
     606             :                 bEditInReadonlyValid =
     607           0 :                     (bEditInReadonly == rData.IsEditInReadonlyFlag());
     608             : 
     609           0 :                 bFileValid        = (bFile ==
     610           0 :                     (rData.GetType() != CONTENT_SECTION));
     611           0 :                 bPasswdValid      = (aCurPasswd == rData.GetPassword());
     612             :             }
     613           0 :             pEntry = pBox->NextSelected(pEntry);
     614           0 :             bFirst = false;
     615             :         }
     616             : 
     617             :         m_pHideCB->SetState(!bHiddenValid ? TRISTATE_INDET :
     618           0 :                     bHidden ? TRISTATE_TRUE : TRISTATE_FALSE);
     619             :         m_pProtectCB->SetState(!bProtectValid ? TRISTATE_INDET :
     620           0 :                     bProtect ? TRISTATE_TRUE : TRISTATE_FALSE);
     621             :         // edit in readonly sections
     622             :         m_pEditInReadonlyCB->SetState(!bEditInReadonlyValid ? TRISTATE_INDET :
     623           0 :                     bEditInReadonly ? TRISTATE_TRUE : TRISTATE_FALSE);
     624             : 
     625             :         m_pFileCB->SetState(!bFileValid ? TRISTATE_INDET :
     626           0 :                     bFile ? TRISTATE_TRUE : TRISTATE_FALSE);
     627             : 
     628           0 :         if (bConditionValid)
     629           0 :             m_pConditionED->SetText(sCondition);
     630             :         else
     631             :         {
     632           0 :             m_pConditionFT->Enable(false);
     633           0 :             m_pConditionED->Enable(false);
     634             :         }
     635             : 
     636           0 :         m_pCurName->Enable(false);
     637           0 :         m_pDDECB->Enable(false);
     638           0 :         m_pDDEFrame->Enable(false);
     639           0 :         m_pOptionsPB->Enable(false);
     640           0 :         bool bPasswdEnabled = m_pProtectCB->GetState() == TRISTATE_TRUE;
     641           0 :         m_pPasswdCB->Enable(bPasswdEnabled);
     642           0 :         m_pPasswdPB->Enable(bPasswdEnabled);
     643           0 :         if(!bPasswdValid)
     644             :         {
     645           0 :             pEntry = pBox->FirstSelected();
     646           0 :             pBox->SelectAll( false );
     647           0 :             pBox->Select( pEntry );
     648           0 :             GetFirstEntryHdl(pBox);
     649           0 :             return 0;
     650             :         }
     651             :         else
     652           0 :             m_pPasswdCB->Check(aCurPasswd.getLength() > 0);
     653             :     }
     654           0 :     else if (pEntry )
     655             :     {
     656           0 :         m_pCurName->Enable(true);
     657           0 :         m_pOptionsPB->Enable(true);
     658           0 :         SectRepr* pRepr=(SectRepr*) pEntry->GetUserData();
     659           0 :         SwSectionData const& rData( pRepr->GetSectionData() );
     660           0 :         m_pConditionED->SetText(rData.GetCondition());
     661           0 :         m_pHideCB->Enable();
     662           0 :         m_pHideCB->SetState((rData.IsHidden()) ? TRISTATE_TRUE : TRISTATE_FALSE);
     663           0 :         bool bHide = TRISTATE_TRUE == m_pHideCB->GetState();
     664           0 :         m_pConditionED->Enable(bHide);
     665           0 :         m_pConditionFT->Enable(bHide);
     666           0 :         m_pPasswdCB->Check(rData.GetPassword().getLength() > 0);
     667             : 
     668           0 :         m_pOK->Enable();
     669           0 :         m_pPasswdCB->Enable();
     670           0 :         m_pCurName->SetText(pBox->GetEntryText(pEntry));
     671           0 :         m_pCurName->Enable();
     672           0 :         m_pDismiss->Enable();
     673           0 :         const OUString aFile = pRepr->GetFile();
     674           0 :         const OUString sSub = pRepr->GetSubRegion();
     675           0 :         m_bSubRegionsFilled = false;
     676           0 :         m_pSubRegionED->Clear();
     677           0 :         if( !aFile.isEmpty() || !sSub.isEmpty() )
     678             :         {
     679           0 :             m_pFileCB->Check(true);
     680           0 :             m_pFileNameED->SetText(aFile);
     681           0 :             m_pSubRegionED->SetText(sSub);
     682           0 :             m_pDDECB->Check(rData.GetType() == DDE_LINK_SECTION);
     683             :         }
     684             :         else
     685             :         {
     686           0 :             m_pFileCB->Check(false);
     687           0 :             m_pFileNameED->SetText(aFile);
     688           0 :             m_pDDECB->Enable(false);
     689           0 :             m_pDDECB->Check(false);
     690             :         }
     691           0 :         UseFileHdl(m_pFileCB);
     692           0 :         DDEHdl(m_pDDECB);
     693           0 :         m_pProtectCB->SetState((rData.IsProtectFlag())
     694           0 :                 ? TRISTATE_TRUE : TRISTATE_FALSE);
     695           0 :         m_pProtectCB->Enable();
     696             : 
     697             :         // edit in readonly sections
     698           0 :         m_pEditInReadonlyCB->SetState((rData.IsEditInReadonlyFlag())
     699           0 :                 ? TRISTATE_TRUE : TRISTATE_FALSE);
     700           0 :         m_pEditInReadonlyCB->Enable();
     701             : 
     702           0 :         bool bPasswdEnabled = m_pProtectCB->IsChecked();
     703           0 :         m_pPasswdCB->Enable(bPasswdEnabled);
     704           0 :         m_pPasswdPB->Enable(bPasswdEnabled);
     705             :     }
     706           0 :     bDontCheckPasswd = false;
     707           0 :     return 0;
     708             : }
     709             : 
     710           0 : IMPL_LINK( SwEditRegionDlg, DeselectHdl, SvTreeListBox *, pBox )
     711             : {
     712           0 :     if( !pBox->GetSelectionCount() )
     713             :     {
     714           0 :         m_pHideCB->Enable(false);
     715           0 :         m_pProtectCB->Enable(false);
     716             :         // edit in readonly sections
     717           0 :         m_pEditInReadonlyCB->Enable(false);
     718             : 
     719           0 :         m_pPasswdCB->Enable(false);
     720           0 :         m_pConditionFT->Enable(false);
     721           0 :         m_pConditionED->Enable(false);
     722           0 :         m_pFileCB->Enable(false);
     723           0 :         m_pDDEFrame->Enable(false);
     724           0 :         m_pDDECB->Enable(false);
     725           0 :         m_pCurName->Enable(false);
     726             : 
     727           0 :         UseFileHdl(m_pFileCB);
     728           0 :         DDEHdl(m_pDDECB);
     729             :     }
     730           0 :     return 0;
     731             : }
     732             : 
     733             : // in OkHdl the modified settings are being applied and reversed regions are deleted
     734           0 : IMPL_LINK_NOARG(SwEditRegionDlg, OkHdl)
     735             : {
     736             :     // temp. Array because during changing of a region the position
     737             :     // inside of the "Core-Arrays" can be shifted:
     738             :     //  - at linked regions, when they have more SubRegions or get
     739             :     //    new ones.
     740             :     // StartUndo must certainly also happen not before the formats
     741             :     // are copied (ClearRedo!)
     742             : 
     743           0 :     const SwSectionFmts& rDocFmts = rSh.GetDoc()->GetSections();
     744           0 :     SwSectionFmts aOrigArray(rDocFmts);
     745             : 
     746           0 :     rSh.StartAllAction();
     747           0 :     rSh.StartUndo();
     748           0 :     rSh.ResetSelect( 0,false );
     749           0 :     SvTreeListEntry* pEntry = m_pTree->First();
     750             : 
     751           0 :     while( pEntry )
     752             :     {
     753           0 :         SectReprPtr pRepr = (SectReprPtr) pEntry->GetUserData();
     754           0 :         SwSectionFmt* pFmt = aOrigArray[ pRepr->GetArrPos() ];
     755           0 :         if (!pRepr->GetSectionData().IsProtectFlag())
     756             :         {
     757           0 :             pRepr->GetSectionData().SetPassword(uno::Sequence<sal_Int8 >());
     758             :         }
     759           0 :         sal_uInt16 nNewPos = rDocFmts.GetPos( pFmt );
     760           0 :         if( USHRT_MAX != nNewPos )
     761             :         {
     762           0 :             boost::scoped_ptr<SfxItemSet> pSet(pFmt->GetAttrSet().Clone( false ));
     763           0 :             if( pFmt->GetCol() != pRepr->GetCol() )
     764           0 :                 pSet->Put( pRepr->GetCol() );
     765             : 
     766           0 :             SvxBrushItem aBrush(pFmt->makeBackgroundBrushItem(false));
     767           0 :             if( aBrush != pRepr->GetBackground() )
     768           0 :                 pSet->Put( pRepr->GetBackground() );
     769             : 
     770           0 :             if( pFmt->GetFtnAtTxtEnd(false) != pRepr->GetFtnNtAtEnd() )
     771           0 :                 pSet->Put( pRepr->GetFtnNtAtEnd() );
     772             : 
     773           0 :             if( pFmt->GetEndAtTxtEnd(false) != pRepr->GetEndNtAtEnd() )
     774           0 :                 pSet->Put( pRepr->GetEndNtAtEnd() );
     775             : 
     776           0 :             if( pFmt->GetBalancedColumns() != pRepr->GetBalance() )
     777           0 :                 pSet->Put( pRepr->GetBalance() );
     778             : 
     779           0 :             if( pFmt->GetFrmDir() != pRepr->GetFrmDir() )
     780           0 :                 pSet->Put( pRepr->GetFrmDir() );
     781             : 
     782           0 :             if( pFmt->GetLRSpace() != pRepr->GetLRSpace())
     783           0 :                 pSet->Put( pRepr->GetLRSpace());
     784             : 
     785           0 :             rSh.UpdateSection( nNewPos, pRepr->GetSectionData(),
     786           0 :                                pSet->Count() ? pSet.get() : 0 );
     787             :         }
     788           0 :         pEntry = m_pTree->Next( pEntry );
     789             :     }
     790             : 
     791           0 :     for (SectReprArr::reverse_iterator aI = aSectReprArr.rbegin(), aEnd = aSectReprArr.rend(); aI != aEnd; ++aI)
     792             :     {
     793           0 :         SwSectionFmt* pFmt = aOrigArray[ aI->GetArrPos() ];
     794           0 :         const sal_uInt16 nNewPos = rDocFmts.GetPos( pFmt );
     795           0 :         if( USHRT_MAX != nNewPos )
     796           0 :             rSh.DelSectionFmt( nNewPos );
     797             :     }
     798             : 
     799           0 :     aOrigArray.clear();
     800             : 
     801             :     // EndDialog must be called ahead of EndAction's end,
     802             :     // otherwise ScrollError can occur.
     803           0 :     EndDialog(RET_OK);
     804             : 
     805           0 :     rSh.EndUndo();
     806           0 :     rSh.EndAllAction();
     807             : 
     808           0 :     return 0;
     809             : }
     810             : 
     811             : // Toggle protect
     812           0 : IMPL_LINK( SwEditRegionDlg, ChangeProtectHdl, TriStateBox *, pBox )
     813             : {
     814           0 :     if(!CheckPasswd(pBox))
     815           0 :         return 0;
     816           0 :     pBox->EnableTriState(false);
     817           0 :     SvTreeListEntry* pEntry = m_pTree->FirstSelected();
     818             :     OSL_ENSURE(pEntry,"no entry found");
     819           0 :     bool bCheck = TRISTATE_TRUE == pBox->GetState();
     820           0 :     while( pEntry )
     821             :     {
     822           0 :         SectReprPtr pRepr = (SectReprPtr) pEntry->GetUserData();
     823           0 :         pRepr->GetSectionData().SetProtectFlag(bCheck);
     824             :         Image aImage = BuildBitmap(bCheck,
     825           0 :                                    TRISTATE_TRUE == m_pHideCB->GetState());
     826           0 :         m_pTree->SetExpandedEntryBmp(  pEntry, aImage );
     827           0 :         m_pTree->SetCollapsedEntryBmp( pEntry, aImage );
     828           0 :         pEntry = m_pTree->NextSelected(pEntry);
     829           0 :     }
     830           0 :     m_pPasswdCB->Enable(bCheck);
     831           0 :     m_pPasswdPB->Enable(bCheck);
     832           0 :     return 0;
     833             : }
     834             : 
     835             : // Toggle hide
     836           0 : IMPL_LINK( SwEditRegionDlg, ChangeHideHdl, TriStateBox *, pBox )
     837             : {
     838           0 :     if(!CheckPasswd(pBox))
     839           0 :         return 0;
     840           0 :     pBox->EnableTriState(false);
     841           0 :     SvTreeListEntry* pEntry = m_pTree->FirstSelected();
     842             :     OSL_ENSURE(pEntry,"no entry found");
     843           0 :     while( pEntry )
     844             :     {
     845           0 :         SectReprPtr pRepr = (SectReprPtr) pEntry->GetUserData();
     846           0 :         pRepr->GetSectionData().SetHidden(TRISTATE_TRUE == pBox->GetState());
     847             : 
     848           0 :         Image aImage = BuildBitmap(TRISTATE_TRUE == m_pProtectCB->GetState(),
     849           0 :                                     TRISTATE_TRUE == pBox->GetState());
     850           0 :         m_pTree->SetExpandedEntryBmp(  pEntry, aImage );
     851           0 :         m_pTree->SetCollapsedEntryBmp( pEntry, aImage );
     852             : 
     853           0 :         pEntry = m_pTree->NextSelected(pEntry);
     854           0 :     }
     855             : 
     856           0 :     bool bHide = TRISTATE_TRUE == pBox->GetState();
     857           0 :     m_pConditionED->Enable(bHide);
     858           0 :     m_pConditionFT->Enable(bHide);
     859           0 :     return 0;
     860             : }
     861             : 
     862             : // Toggle edit in readonly
     863           0 : IMPL_LINK( SwEditRegionDlg, ChangeEditInReadonlyHdl, TriStateBox *, pBox )
     864             : {
     865           0 :     if(!CheckPasswd(pBox))
     866           0 :         return 0;
     867           0 :     pBox->EnableTriState(false);
     868           0 :     SvTreeListEntry* pEntry = m_pTree->FirstSelected();
     869             :     OSL_ENSURE(pEntry,"no entry found");
     870           0 :     while( pEntry )
     871             :     {
     872           0 :         SectReprPtr pRepr = (SectReprPtr) pEntry->GetUserData();
     873           0 :         pRepr->GetSectionData().SetEditInReadonlyFlag(
     874           0 :                 TRISTATE_TRUE == pBox->GetState());
     875           0 :         pEntry = m_pTree->NextSelected(pEntry);
     876             :     }
     877             : 
     878           0 :     return 0;
     879             : }
     880             : 
     881             : // clear selected region
     882           0 : IMPL_LINK_NOARG(SwEditRegionDlg, ChangeDismissHdl)
     883             : {
     884           0 :     if(!CheckPasswd())
     885           0 :         return 0;
     886           0 :     SvTreeListEntry* pEntry = m_pTree->FirstSelected();
     887             :     SvTreeListEntry* pChild;
     888             :     SvTreeListEntry* pParent;
     889             :     // at first mark all selected
     890           0 :     while(pEntry)
     891             :     {
     892           0 :         const SectReprPtr pSectRepr = (SectRepr*)pEntry->GetUserData();
     893           0 :         pSectRepr->SetSelected();
     894           0 :         pEntry = m_pTree->NextSelected(pEntry);
     895             :     }
     896           0 :     pEntry = m_pTree->FirstSelected();
     897             :     // then delete
     898           0 :     while(pEntry)
     899             :     {
     900           0 :         const SectReprPtr pSectRepr = (SectRepr*)pEntry->GetUserData();
     901           0 :         SvTreeListEntry* pRemove = 0;
     902           0 :         bool bRestart = false;
     903           0 :         if(pSectRepr->IsSelected())
     904             :         {
     905           0 :             aSectReprArr.insert( pSectRepr );
     906           0 :             while( (pChild = m_pTree->FirstChild(pEntry) )!= 0 )
     907             :             {
     908             :                 // because of the repositioning we have to start at the beginning again
     909           0 :                 bRestart = true;
     910           0 :                 pParent = m_pTree->GetParent(pEntry);
     911           0 :                 m_pTree->GetModel()->Move(pChild, pParent, m_pTree->GetModel()->GetRelPos(pEntry));
     912             :             }
     913           0 :             pRemove = pEntry;
     914             :         }
     915           0 :         if(bRestart)
     916           0 :             pEntry = m_pTree->First();
     917             :         else
     918           0 :             pEntry = m_pTree->Next(pEntry);
     919           0 :         if(pRemove)
     920           0 :             m_pTree->GetModel()->Remove( pRemove );
     921             :     }
     922             : 
     923           0 :     if ( m_pTree->FirstSelected() == 0 )
     924             :     {
     925           0 :         m_pConditionFT->Enable(false);
     926           0 :         m_pConditionED->Enable(false);
     927           0 :         m_pDismiss->       Enable(false);
     928           0 :         m_pCurName->Enable(false);
     929           0 :         m_pProtectCB->Enable(false);
     930           0 :         m_pPasswdCB->Enable(false);
     931           0 :         m_pHideCB->Enable(false);
     932             :         // edit in readonly sections
     933           0 :         m_pEditInReadonlyCB->Enable(false);
     934           0 :         m_pEditInReadonlyCB->SetState(TRISTATE_FALSE);
     935           0 :         m_pProtectCB->SetState(TRISTATE_FALSE);
     936           0 :         m_pPasswdCB->Check(false);
     937           0 :         m_pHideCB->SetState(TRISTATE_FALSE);
     938           0 :         m_pFileCB->Check(false);
     939             :         // otherwise the focus would be on HelpButton
     940           0 :         m_pOK->GrabFocus();
     941           0 :         UseFileHdl(m_pFileCB);
     942             :     }
     943           0 :     return 0;
     944             : }
     945             : 
     946             : // link CheckBox to file?
     947           0 : IMPL_LINK( SwEditRegionDlg, UseFileHdl, CheckBox *, pBox )
     948             : {
     949           0 :     if(!CheckPasswd(pBox))
     950           0 :         return 0;
     951           0 :     SvTreeListEntry* pEntry = m_pTree->FirstSelected();
     952           0 :     pBox->EnableTriState(false);
     953           0 :     bool bMulti = 1 < m_pTree->GetSelectionCount();
     954           0 :     bool bFile = pBox->IsChecked();
     955           0 :     if(pEntry)
     956             :     {
     957           0 :         while(pEntry)
     958             :         {
     959           0 :             const SectReprPtr pSectRepr = (SectRepr*)pEntry->GetUserData();
     960           0 :             bool bContent = pSectRepr->IsContent();
     961           0 :             if( pBox->IsChecked() && bContent && rSh.HasSelection() )
     962             :             {
     963           0 :                 if (RET_NO == MessageDialog(this, SW_RES(STR_QUERY_CONNECT), VCL_MESSAGE_QUESTION, VCL_BUTTONS_YES_NO).Execute())
     964           0 :                     pBox->Check( false );
     965             :             }
     966           0 :             if( bFile )
     967           0 :                 pSectRepr->SetContent(false);
     968             :             else
     969             :             {
     970           0 :                 pSectRepr->SetFile(aEmptyOUStr);
     971           0 :                 pSectRepr->SetSubRegion(aEmptyOUStr);
     972           0 :                 pSectRepr->GetSectionData().SetLinkFilePassword(aEmptyOUStr);
     973             :             }
     974             : 
     975           0 :             pEntry = m_pTree->NextSelected(pEntry);
     976             :         }
     977           0 :         m_pDDECB->Enable(bFile && ! bMulti);
     978           0 :         m_pDDEFrame->Enable(bFile && ! bMulti);
     979           0 :         if( bFile )
     980             :         {
     981           0 :             m_pProtectCB->SetState(TRISTATE_TRUE);
     982           0 :             m_pFileNameED->GrabFocus();
     983             : 
     984             :         }
     985             :         else
     986             :         {
     987           0 :             m_pDDECB->Check(false);
     988           0 :             DDEHdl(m_pDDECB);
     989           0 :             m_pSubRegionED->SetText(OUString());
     990             :         }
     991             :     }
     992             :     else
     993             :     {
     994           0 :         pBox->Check(false);
     995           0 :         pBox->Enable(false);
     996           0 :         m_pDDECB->Check(false);
     997           0 :         m_pDDECB->Enable(false);
     998           0 :         m_pDDEFrame->Enable(false);
     999             :     }
    1000           0 :     return 0;
    1001             : }
    1002             : 
    1003             : // call dialog paste file
    1004           0 : IMPL_LINK_NOARG(SwEditRegionDlg, FileSearchHdl)
    1005             : {
    1006           0 :     if(!CheckPasswd(0))
    1007           0 :         return 0;
    1008           0 :     m_pOldDefDlgParent = Application::GetDefDialogParent();
    1009           0 :     Application::SetDefDialogParent( this );
    1010           0 :     delete m_pDocInserter;
    1011             :     m_pDocInserter =
    1012           0 :         new ::sfx2::DocumentInserter( "swriter" );
    1013           0 :     m_pDocInserter->StartExecuteModal( LINK( this, SwEditRegionDlg, DlgClosedHdl ) );
    1014           0 :     return 0;
    1015             : }
    1016             : 
    1017           0 : IMPL_LINK_NOARG(SwEditRegionDlg, OptionsHdl)
    1018             : {
    1019           0 :     if(!CheckPasswd())
    1020           0 :         return 0;
    1021           0 :     SvTreeListEntry* pEntry = m_pTree->FirstSelected();
    1022             : 
    1023           0 :     if(pEntry)
    1024             :     {
    1025           0 :         SectReprPtr pSectRepr = (SectRepr*)pEntry->GetUserData();
    1026           0 :         SfxItemSet aSet(rSh.GetView().GetPool(),
    1027             :                             RES_COL, RES_COL,
    1028             :                             RES_COLUMNBALANCE, RES_FRAMEDIR,
    1029             :                             RES_BACKGROUND, RES_BACKGROUND,
    1030             :                             RES_FRM_SIZE, RES_FRM_SIZE,
    1031             :                             SID_ATTR_PAGE_SIZE, SID_ATTR_PAGE_SIZE,
    1032             :                             RES_LR_SPACE, RES_LR_SPACE,
    1033             :                             RES_FTN_AT_TXTEND, RES_END_AT_TXTEND,
    1034           0 :                             0);
    1035             : 
    1036           0 :         aSet.Put( pSectRepr->GetCol() );
    1037           0 :         aSet.Put( pSectRepr->GetBackground() );
    1038           0 :         aSet.Put( pSectRepr->GetFtnNtAtEnd() );
    1039           0 :         aSet.Put( pSectRepr->GetEndNtAtEnd() );
    1040           0 :         aSet.Put( pSectRepr->GetBalance() );
    1041           0 :         aSet.Put( pSectRepr->GetFrmDir() );
    1042           0 :         aSet.Put( pSectRepr->GetLRSpace() );
    1043             : 
    1044           0 :         const SwSectionFmts& rDocFmts = rSh.GetDoc()->GetSections();
    1045           0 :         SwSectionFmts aOrigArray(rDocFmts);
    1046             : 
    1047           0 :         SwSectionFmt* pFmt = aOrigArray[pSectRepr->GetArrPos()];
    1048           0 :         long nWidth = rSh.GetSectionWidth(*pFmt);
    1049           0 :         aOrigArray.clear();
    1050           0 :         if (!nWidth)
    1051           0 :             nWidth = USHRT_MAX;
    1052             : 
    1053           0 :         aSet.Put(SwFmtFrmSize(ATT_VAR_SIZE, nWidth));
    1054           0 :         aSet.Put(SvxSizeItem(SID_ATTR_PAGE_SIZE, Size(nWidth, nWidth)));
    1055             : 
    1056           0 :         SwSectionPropertyTabDialog aTabDlg(this, aSet, rSh);
    1057           0 :         if(RET_OK == aTabDlg.Execute())
    1058             :         {
    1059           0 :             const SfxItemSet* pOutSet = aTabDlg.GetOutputItemSet();
    1060           0 :             if( pOutSet && pOutSet->Count() )
    1061             :             {
    1062             :                 const SfxPoolItem *pColItem, *pBrushItem,
    1063             :                                   *pFtnItem, *pEndItem, *pBalanceItem,
    1064             :                                   *pFrmDirItem, *pLRSpaceItem;
    1065             :                 SfxItemState eColState = pOutSet->GetItemState(
    1066           0 :                                         RES_COL, false, &pColItem );
    1067             :                 SfxItemState eBrushState = pOutSet->GetItemState(
    1068           0 :                                         RES_BACKGROUND, false, &pBrushItem );
    1069             :                 SfxItemState eFtnState = pOutSet->GetItemState(
    1070           0 :                                         RES_FTN_AT_TXTEND, false, &pFtnItem );
    1071             :                 SfxItemState eEndState = pOutSet->GetItemState(
    1072           0 :                                         RES_END_AT_TXTEND, false, &pEndItem );
    1073             :                 SfxItemState eBalanceState = pOutSet->GetItemState(
    1074           0 :                                         RES_COLUMNBALANCE, false, &pBalanceItem );
    1075             :                 SfxItemState eFrmDirState = pOutSet->GetItemState(
    1076           0 :                                         RES_FRAMEDIR, false, &pFrmDirItem );
    1077             :                 SfxItemState eLRState = pOutSet->GetItemState(
    1078           0 :                                         RES_LR_SPACE, false, &pLRSpaceItem);
    1079             : 
    1080           0 :                 if( SfxItemState::SET == eColState ||
    1081           0 :                     SfxItemState::SET == eBrushState ||
    1082           0 :                     SfxItemState::SET == eFtnState ||
    1083           0 :                     SfxItemState::SET == eEndState ||
    1084           0 :                     SfxItemState::SET == eBalanceState||
    1085           0 :                     SfxItemState::SET == eFrmDirState||
    1086             :                     SfxItemState::SET == eLRState)
    1087             :                 {
    1088           0 :                     SvTreeListEntry* pSelEntry = m_pTree->FirstSelected();
    1089           0 :                     while( pSelEntry )
    1090             :                     {
    1091           0 :                         SectReprPtr pRepr = (SectReprPtr)pSelEntry->GetUserData();
    1092           0 :                         if( SfxItemState::SET == eColState )
    1093           0 :                             pRepr->GetCol() = *(SwFmtCol*)pColItem;
    1094           0 :                         if( SfxItemState::SET == eBrushState )
    1095           0 :                             pRepr->GetBackground() = *(SvxBrushItem*)pBrushItem;
    1096           0 :                         if( SfxItemState::SET == eFtnState )
    1097           0 :                             pRepr->GetFtnNtAtEnd() = *(SwFmtFtnAtTxtEnd*)pFtnItem;
    1098           0 :                         if( SfxItemState::SET == eEndState )
    1099           0 :                             pRepr->GetEndNtAtEnd() = *(SwFmtEndAtTxtEnd*)pEndItem;
    1100           0 :                         if( SfxItemState::SET == eBalanceState )
    1101           0 :                             pRepr->GetBalance().SetValue(((SwFmtNoBalancedColumns*)pBalanceItem)->GetValue());
    1102           0 :                         if( SfxItemState::SET == eFrmDirState )
    1103           0 :                             pRepr->GetFrmDir().SetValue(((SvxFrameDirectionItem*)pFrmDirItem)->GetValue());
    1104           0 :                         if( SfxItemState::SET == eLRState )
    1105           0 :                             pRepr->GetLRSpace() = *(SvxLRSpaceItem*)pLRSpaceItem;
    1106             : 
    1107           0 :                         pSelEntry = m_pTree->NextSelected(pSelEntry);
    1108             :                     }
    1109             :                 }
    1110             :             }
    1111           0 :         }
    1112             :     }
    1113             : 
    1114           0 :     return 0;
    1115             : }
    1116             : 
    1117             : // Applying of the filename or the linked region
    1118           0 : IMPL_LINK( SwEditRegionDlg, FileNameHdl, Edit *, pEdit )
    1119             : {
    1120           0 :     Selection aSelect = pEdit->GetSelection();
    1121           0 :     if(!CheckPasswd())
    1122           0 :         return 0;
    1123           0 :     pEdit->SetSelection(aSelect);
    1124           0 :     SvTreeListEntry* pEntry = m_pTree->FirstSelected();
    1125             :     OSL_ENSURE(pEntry,"no entry found");
    1126           0 :     SectReprPtr pSectRepr = (SectRepr*)pEntry->GetUserData();
    1127           0 :     if (pEdit == m_pFileNameED)
    1128             :     {
    1129           0 :         m_bSubRegionsFilled = false;
    1130           0 :         m_pSubRegionED->Clear();
    1131           0 :         if (m_pDDECB->IsChecked())
    1132             :         {
    1133           0 :             OUString sLink( SwSectionData::CollapseWhiteSpaces(pEdit->GetText()) );
    1134           0 :             sal_Int32 nPos = 0;
    1135           0 :             sLink = sLink.replaceFirst( " ", OUString(sfx2::cTokenSeparator), &nPos );
    1136           0 :             if (nPos>=0)
    1137             :             {
    1138           0 :                 sLink = sLink.replaceFirst( " ", OUString(sfx2::cTokenSeparator), &nPos );
    1139             :             }
    1140             : 
    1141           0 :             pSectRepr->GetSectionData().SetLinkFileName( sLink );
    1142           0 :             pSectRepr->GetSectionData().SetType( DDE_LINK_SECTION );
    1143             :         }
    1144             :         else
    1145             :         {
    1146           0 :             OUString sTmp(pEdit->GetText());
    1147           0 :             if(!sTmp.isEmpty())
    1148             :             {
    1149           0 :                 SfxMedium* pMedium = rSh.GetView().GetDocShell()->GetMedium();
    1150           0 :                 INetURLObject aAbs;
    1151           0 :                 if( pMedium )
    1152           0 :                     aAbs = pMedium->GetURLObject();
    1153           0 :                 sTmp = URIHelper::SmartRel2Abs(
    1154           0 :                     aAbs, sTmp, URIHelper::GetMaybeFileHdl() );
    1155             :             }
    1156           0 :             pSectRepr->SetFile( sTmp );
    1157           0 :             pSectRepr->GetSectionData().SetLinkFilePassword( aEmptyOUStr );
    1158             :         }
    1159             :     }
    1160             :     else
    1161             :     {
    1162           0 :         pSectRepr->SetSubRegion( pEdit->GetText() );
    1163             :     }
    1164           0 :     return 0;
    1165             : }
    1166             : 
    1167           0 : IMPL_LINK( SwEditRegionDlg, DDEHdl, CheckBox*, pBox )
    1168             : {
    1169           0 :     if(!CheckPasswd(pBox))
    1170           0 :         return 0;
    1171           0 :     SvTreeListEntry* pEntry = m_pTree->FirstSelected();
    1172           0 :     if(pEntry)
    1173             :     {
    1174           0 :         bool bFile = m_pFileCB->IsChecked();
    1175           0 :         SectReprPtr pSectRepr = (SectRepr*)pEntry->GetUserData();
    1176           0 :         SwSectionData & rData( pSectRepr->GetSectionData() );
    1177           0 :         bool bDDE = pBox->IsChecked();
    1178           0 :         if(bDDE)
    1179             :         {
    1180           0 :             m_pFileNameFT->Hide();
    1181           0 :             m_pDDECommandFT->Enable();
    1182           0 :             m_pDDECommandFT->Show();
    1183           0 :             m_pSubRegionFT->Hide();
    1184           0 :             m_pSubRegionED->Hide();
    1185           0 :             if (FILE_LINK_SECTION == rData.GetType())
    1186             :             {
    1187           0 :                 pSectRepr->SetFile(OUString());
    1188           0 :                 m_pFileNameED->SetText(OUString());
    1189           0 :                 rData.SetLinkFilePassword(OUString());
    1190             :             }
    1191           0 :             rData.SetType(DDE_LINK_SECTION);
    1192             :         }
    1193             :         else
    1194             :         {
    1195           0 :             m_pDDECommandFT->Hide();
    1196           0 :             m_pFileNameFT->Enable(bFile);
    1197           0 :             m_pFileNameFT->Show();
    1198           0 :             m_pSubRegionED->Show();
    1199           0 :             m_pSubRegionFT->Show();
    1200           0 :             m_pSubRegionED->Enable(bFile);
    1201           0 :             m_pSubRegionFT->Enable(bFile);
    1202           0 :             m_pSubRegionED->Enable(bFile);
    1203           0 :             if (DDE_LINK_SECTION == rData.GetType())
    1204             :             {
    1205           0 :                 rData.SetType(FILE_LINK_SECTION);
    1206           0 :                 pSectRepr->SetFile(OUString());
    1207           0 :                 rData.SetLinkFilePassword(OUString());
    1208           0 :                 m_pFileNameED->SetText(OUString());
    1209             :             }
    1210             :         }
    1211           0 :         m_pFilePB->Enable(bFile && !bDDE);
    1212             :     }
    1213           0 :     return 0;
    1214             : }
    1215             : 
    1216           0 : IMPL_LINK( SwEditRegionDlg, ChangePasswdHdl, Button *, pBox )
    1217             : {
    1218           0 :     bool bChange = pBox == m_pPasswdPB;
    1219           0 :     if(!CheckPasswd(0))
    1220             :     {
    1221           0 :         if(!bChange)
    1222           0 :             m_pPasswdCB->Check(!m_pPasswdCB->IsChecked());
    1223           0 :         return 0;
    1224             :     }
    1225           0 :     SvTreeListEntry* pEntry = m_pTree->FirstSelected();
    1226           0 :     bool bSet = bChange ? bChange : m_pPasswdCB->IsChecked();
    1227             :     OSL_ENSURE(pEntry,"no entry found");
    1228           0 :     while( pEntry )
    1229             :     {
    1230           0 :         SectReprPtr pRepr = (SectReprPtr)pEntry->GetUserData();
    1231           0 :         if(bSet)
    1232             :         {
    1233           0 :             if(!pRepr->GetTempPasswd().getLength() || bChange)
    1234             :             {
    1235           0 :                 SfxPasswordDialog aPasswdDlg(this);
    1236           0 :                 aPasswdDlg.ShowExtras(SHOWEXTRAS_CONFIRM);
    1237           0 :                 if(RET_OK == aPasswdDlg.Execute())
    1238             :                 {
    1239           0 :                     const OUString sNewPasswd( aPasswdDlg.GetPassword() );
    1240           0 :                     if( aPasswdDlg.GetConfirm() == sNewPasswd )
    1241             :                     {
    1242           0 :                         SvPasswordHelper::GetHashPassword( pRepr->GetTempPasswd(), sNewPasswd );
    1243             :                     }
    1244             :                     else
    1245             :                     {
    1246           0 :                         MessageDialog(pBox, SW_RES(STR_WRONG_PASSWD_REPEAT), VCL_MESSAGE_INFO).Execute();
    1247           0 :                         ChangePasswdHdl(pBox);
    1248           0 :                         break;
    1249           0 :                     }
    1250             :                 }
    1251             :                 else
    1252             :                 {
    1253           0 :                     if(!bChange)
    1254           0 :                         m_pPasswdCB->Check(false);
    1255           0 :                     break;
    1256           0 :                 }
    1257             :             }
    1258           0 :             pRepr->GetSectionData().SetPassword(pRepr->GetTempPasswd());
    1259             :         }
    1260             :         else
    1261             :         {
    1262           0 :             pRepr->GetSectionData().SetPassword(uno::Sequence<sal_Int8 >());
    1263             :         }
    1264           0 :         pEntry = m_pTree->NextSelected(pEntry);
    1265             :     }
    1266           0 :     return 0;
    1267             : }
    1268             : 
    1269             : // the current region name is being added to the TreeListBox immediately during
    1270             : // editing, with empty string no Ok()
    1271           0 : IMPL_LINK_NOARG(SwEditRegionDlg, NameEditHdl)
    1272             : {
    1273           0 :     if(!CheckPasswd(0))
    1274           0 :         return 0;
    1275           0 :     SvTreeListEntry* pEntry = m_pTree->FirstSelected();
    1276             :     OSL_ENSURE(pEntry,"no entry found");
    1277           0 :     if (pEntry)
    1278             :     {
    1279           0 :         const OUString aName = m_pCurName->GetText();
    1280           0 :         m_pTree->SetEntryText(pEntry,aName);
    1281           0 :         SectReprPtr pRepr = (SectReprPtr) pEntry->GetUserData();
    1282           0 :         pRepr->GetSectionData().SetSectionName(aName);
    1283             : 
    1284           0 :         m_pOK->Enable(!aName.isEmpty());
    1285             :     }
    1286           0 :     return 0;
    1287             : }
    1288             : 
    1289           0 : IMPL_LINK( SwEditRegionDlg, ConditionEditHdl, Edit *, pEdit )
    1290             : {
    1291           0 :     Selection aSelect = pEdit->GetSelection();
    1292           0 :     if(!CheckPasswd(0))
    1293           0 :         return 0;
    1294           0 :     pEdit->SetSelection(aSelect);
    1295           0 :     SvTreeListEntry* pEntry = m_pTree->FirstSelected();
    1296             :     OSL_ENSURE(pEntry,"no entry found");
    1297           0 :     while( pEntry )
    1298             :     {
    1299           0 :         SectReprPtr pRepr = (SectReprPtr)pEntry->GetUserData();
    1300           0 :         pRepr->GetSectionData().SetCondition(pEdit->GetText());
    1301           0 :         pEntry = m_pTree->NextSelected(pEntry);
    1302             :     }
    1303           0 :     return 0;
    1304             : }
    1305             : 
    1306           0 : IMPL_LINK( SwEditRegionDlg, DlgClosedHdl, sfx2::FileDialogHelper *, _pFileDlg )
    1307             : {
    1308           0 :     OUString sFileName, sFilterName, sPassword;
    1309           0 :     if ( _pFileDlg->GetError() == ERRCODE_NONE )
    1310             :     {
    1311           0 :         boost::scoped_ptr<SfxMedium> pMedium(m_pDocInserter->CreateMedium());
    1312           0 :         if ( pMedium )
    1313             :         {
    1314           0 :             sFileName = pMedium->GetURLObject().GetMainURL( INetURLObject::NO_DECODE );
    1315           0 :             sFilterName = pMedium->GetFilter()->GetFilterName();
    1316             :             const SfxPoolItem* pItem;
    1317           0 :             if ( SfxItemState::SET == pMedium->GetItemSet()->GetItemState( SID_PASSWORD, false, &pItem ) )
    1318           0 :                 sPassword = ( (SfxStringItem*)pItem )->GetValue();
    1319           0 :             ::lcl_ReadSections(*pMedium, *m_pSubRegionED);
    1320           0 :         }
    1321             :     }
    1322             : 
    1323           0 :     SvTreeListEntry* pEntry = m_pTree->FirstSelected();
    1324             :     OSL_ENSURE( pEntry, "no entry found" );
    1325           0 :     if ( pEntry )
    1326             :     {
    1327           0 :         SectReprPtr pSectRepr = (SectRepr*)pEntry->GetUserData();
    1328           0 :         pSectRepr->SetFile( sFileName );
    1329           0 :         pSectRepr->SetFilter( sFilterName );
    1330           0 :         pSectRepr->GetSectionData().SetLinkFilePassword(sPassword);
    1331           0 :         m_pFileNameED->SetText(pSectRepr->GetFile());
    1332             :     }
    1333             : 
    1334           0 :     Application::SetDefDialogParent( m_pOldDefDlgParent );
    1335           0 :     return 0;
    1336             : }
    1337             : 
    1338           0 : IMPL_LINK( SwEditRegionDlg, SubRegionEventHdl, VclWindowEvent *, pEvent )
    1339             : {
    1340           0 :     if( !m_bSubRegionsFilled && pEvent && pEvent->GetId() == VCLEVENT_DROPDOWN_PRE_OPEN )
    1341             :     {
    1342             :         //if necessary fill the names bookmarks/sections/tables now
    1343             : 
    1344           0 :         OUString sFileName = m_pFileNameED->GetText();
    1345           0 :         if(!sFileName.isEmpty())
    1346             :         {
    1347           0 :             SfxMedium* pMedium = rSh.GetView().GetDocShell()->GetMedium();
    1348           0 :             INetURLObject aAbs;
    1349           0 :             if( pMedium )
    1350           0 :                 aAbs = pMedium->GetURLObject();
    1351           0 :             sFileName = URIHelper::SmartRel2Abs(
    1352           0 :                     aAbs, sFileName, URIHelper::GetMaybeFileHdl() );
    1353             : 
    1354             :             //load file and set the shell
    1355           0 :             SfxMedium aMedium( sFileName, STREAM_STD_READ );
    1356           0 :             sFileName = aMedium.GetURLObject().GetMainURL( INetURLObject::NO_DECODE );
    1357           0 :             ::lcl_ReadSections(aMedium, *m_pSubRegionED);
    1358             :         }
    1359             :         else
    1360           0 :             lcl_FillSubRegionList(rSh, *m_pSubRegionED, 0);
    1361           0 :         m_bSubRegionsFilled = true;
    1362             :     }
    1363           0 :     return 0;
    1364             : }
    1365             : 
    1366           0 : Image SwEditRegionDlg::BuildBitmap( bool bProtect, bool bHidden )
    1367             : {
    1368           0 :     ImageList& rImgLst = aImageIL;
    1369           0 :     return rImgLst.GetImage((int(!bHidden)+((bProtect ? 1 : 0)<<1)) + 1);
    1370             : }
    1371             : 
    1372             : // helper function - read region names from medium
    1373           0 : static void lcl_ReadSections( SfxMedium& rMedium, ComboBox& rBox )
    1374             : {
    1375           0 :     rBox.Clear();
    1376           0 :     uno::Reference < embed::XStorage > xStg;
    1377           0 :     if( rMedium.IsStorage() && (xStg = rMedium.GetStorage()).is() )
    1378             :     {
    1379           0 :         std::vector<OUString*> aArr;
    1380           0 :         sal_uInt32 nFormat = SotStorage::GetFormatID( xStg );
    1381           0 :         if ( nFormat == SOT_FORMATSTR_ID_STARWRITER_60 || nFormat == SOT_FORMATSTR_ID_STARWRITERGLOB_60 ||
    1382           0 :             nFormat == SOT_FORMATSTR_ID_STARWRITER_8 || nFormat == SOT_FORMATSTR_ID_STARWRITERGLOB_8)
    1383           0 :             SwGetReaderXML()->GetSectionList( rMedium, aArr );
    1384             : 
    1385           0 :         for(std::vector<OUString*>::const_iterator it(aArr.begin()); it != aArr.end(); ++it) {
    1386           0 :             rBox.InsertEntry( **it );
    1387           0 :             delete *it;
    1388           0 :         }
    1389           0 :     }
    1390           0 : }
    1391             : 
    1392           0 : SwInsertSectionTabDialog::SwInsertSectionTabDialog(
    1393             :             vcl::Window* pParent, const SfxItemSet& rSet, SwWrtShell& rSh)
    1394             :     : SfxTabDialog(pParent, "InsertSectionDialog",
    1395             :         "modules/swriter/ui/insertsectiondialog.ui", &rSet)
    1396           0 :     , rWrtSh(rSh)
    1397             : {
    1398           0 :     SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
    1399             :     OSL_ENSURE(pFact, "Dialog creation failed!");
    1400           0 :     m_nSectionPageId = AddTabPage("section", SwInsertSectionTabPage::Create, 0);
    1401           0 :     m_nColumnPageId = AddTabPage("columns",   SwColumnPage::Create,    0);
    1402           0 :     m_nBackPageId = AddTabPage("background", pFact->GetTabPageCreatorFunc( RID_SVXPAGE_BACKGROUND ), 0);
    1403           0 :     m_nNotePageId = AddTabPage("notes", SwSectionFtnEndTabPage::Create, 0);
    1404           0 :     m_nIndentPage = AddTabPage("indents", SwSectionIndentTabPage::Create, 0);
    1405             : 
    1406           0 :     SvxHtmlOptions& rHtmlOpt = SvxHtmlOptions::Get();
    1407           0 :     long nHtmlMode = rHtmlOpt.GetExportMode();
    1408             : 
    1409           0 :     bool bWeb = 0 != PTR_CAST( SwWebDocShell, rSh.GetView().GetDocShell() );
    1410           0 :     if(bWeb)
    1411             :     {
    1412           0 :         RemoveTabPage(m_nNotePageId);
    1413           0 :         RemoveTabPage(m_nIndentPage);
    1414           0 :         if( HTML_CFG_NS40 != nHtmlMode && HTML_CFG_WRITER != nHtmlMode)
    1415           0 :             RemoveTabPage(m_nColumnPageId);
    1416             :     }
    1417           0 :     SetCurPageId(m_nSectionPageId);
    1418           0 : }
    1419             : 
    1420           0 : SwInsertSectionTabDialog::~SwInsertSectionTabDialog()
    1421             : {
    1422           0 : }
    1423             : 
    1424           0 : void SwInsertSectionTabDialog::PageCreated( sal_uInt16 nId, SfxTabPage &rPage )
    1425             : {
    1426           0 :     if (nId == m_nSectionPageId)
    1427           0 :         ((SwInsertSectionTabPage&)rPage).SetWrtShell(rWrtSh);
    1428           0 :     else if (nId == m_nBackPageId)
    1429             :     {
    1430           0 :             SfxAllItemSet aSet(*(GetInputSetImpl()->GetPool()));
    1431           0 :             aSet.Put (SfxUInt32Item(SID_FLAG_TYPE, SVX_SHOW_SELECTOR));
    1432           0 :             rPage.PageCreated(aSet);
    1433             :     }
    1434           0 :     else if (nId == m_nColumnPageId)
    1435             :     {
    1436           0 :         const SwFmtFrmSize& rSize = (const SwFmtFrmSize&)GetInputSetImpl()->Get(RES_FRM_SIZE);
    1437           0 :         ((SwColumnPage&)rPage).SetPageWidth(rSize.GetWidth());
    1438           0 :         ((SwColumnPage&)rPage).ShowBalance(true);
    1439           0 :         ((SwColumnPage&)rPage).SetInSection(true);
    1440             :     }
    1441           0 :     else if (nId == m_nIndentPage)
    1442           0 :         ((SwSectionIndentTabPage&)rPage).SetWrtShell(rWrtSh);
    1443           0 : }
    1444             : 
    1445           0 : void SwInsertSectionTabDialog::SetSectionData(SwSectionData const& rSect)
    1446             : {
    1447           0 :     m_pSectionData.reset( new SwSectionData(rSect) );
    1448           0 : }
    1449             : 
    1450           0 : short   SwInsertSectionTabDialog::Ok()
    1451             : {
    1452           0 :     short nRet = SfxTabDialog::Ok();
    1453             :     OSL_ENSURE(m_pSectionData.get(),
    1454             :             "SwInsertSectionTabDialog: no SectionData?");
    1455           0 :     const SfxItemSet* pOutputItemSet = GetOutputItemSet();
    1456           0 :     rWrtSh.InsertSection(*m_pSectionData, pOutputItemSet);
    1457           0 :     SfxViewFrame* pViewFrm = rWrtSh.GetView().GetViewFrame();
    1458             :     uno::Reference< frame::XDispatchRecorder > xRecorder =
    1459           0 :             pViewFrm->GetBindings().GetRecorder();
    1460           0 :     if ( xRecorder.is() )
    1461             :     {
    1462           0 :         SfxRequest aRequest( pViewFrm, FN_INSERT_REGION);
    1463             :         const SfxPoolItem* pCol;
    1464           0 :         if(SfxItemState::SET == pOutputItemSet->GetItemState(RES_COL, false, &pCol))
    1465             :         {
    1466             :             aRequest.AppendItem(SfxUInt16Item(SID_ATTR_COLUMNS,
    1467           0 :                 ((const SwFmtCol*)pCol)->GetColumns().size()));
    1468             :         }
    1469             :         aRequest.AppendItem(SfxStringItem( FN_PARAM_REGION_NAME,
    1470           0 :                     m_pSectionData->GetSectionName()));
    1471             :         aRequest.AppendItem(SfxStringItem( FN_PARAM_REGION_CONDITION,
    1472           0 :                     m_pSectionData->GetCondition()));
    1473             :         aRequest.AppendItem(SfxBoolItem( FN_PARAM_REGION_HIDDEN,
    1474           0 :                     m_pSectionData->IsHidden()));
    1475             :         aRequest.AppendItem(SfxBoolItem( FN_PARAM_REGION_PROTECT,
    1476           0 :                     m_pSectionData->IsProtectFlag()));
    1477             :         // edit in readonly sections
    1478             :         aRequest.AppendItem(SfxBoolItem( FN_PARAM_REGION_EDIT_IN_READONLY,
    1479           0 :                     m_pSectionData->IsEditInReadonlyFlag()));
    1480             : 
    1481           0 :         const OUString sLinkFileName( m_pSectionData->GetLinkFileName() );
    1482           0 :         sal_Int32 n = 0;
    1483           0 :         aRequest.AppendItem(SfxStringItem( FN_PARAM_1, sLinkFileName.getToken( 0, sfx2::cTokenSeparator, n )));
    1484           0 :         aRequest.AppendItem(SfxStringItem( FN_PARAM_2, sLinkFileName.getToken( 0, sfx2::cTokenSeparator, n )));
    1485           0 :         aRequest.AppendItem(SfxStringItem( FN_PARAM_3, sLinkFileName.getToken( 0, sfx2::cTokenSeparator, n )));
    1486           0 :         aRequest.Done();
    1487             :     }
    1488           0 :     return nRet;
    1489             : }
    1490             : 
    1491           0 : SwInsertSectionTabPage::SwInsertSectionTabPage(
    1492             :                             vcl::Window *pParent, const SfxItemSet &rAttrSet)
    1493             :     : SfxTabPage(pParent, "SectionPage",
    1494             :         "modules/swriter/ui/sectionpage.ui", &rAttrSet)
    1495             :     , m_pWrtSh(0)
    1496             :     , m_pDocInserter(NULL)
    1497           0 :     , m_pOldDefDlgParent(NULL)
    1498             : {
    1499           0 :     get(m_pCurName, "sectionnames");
    1500           0 :     m_pCurName->SetStyle(m_pCurName->GetStyle() | WB_SORT);
    1501           0 :     m_pCurName->set_height_request(m_pCurName->GetTextHeight() * 12);
    1502           0 :     get(m_pFileCB, "link");
    1503           0 :     get(m_pDDECB, "dde");
    1504           0 :     get(m_pDDECommandFT, "ddelabel");
    1505           0 :     get(m_pFileNameFT, "filelabel");
    1506           0 :     get(m_pFileNameED, "filename");
    1507           0 :     get(m_pFilePB, "selectfile");
    1508           0 :     get(m_pSubRegionFT, "sectionlabel");
    1509           0 :     get(m_pSubRegionED, "sectionname");
    1510           0 :     m_pSubRegionED->SetStyle(m_pSubRegionED->GetStyle() | WB_SORT);
    1511           0 :     get(m_pProtectCB, "protect");
    1512           0 :     get(m_pPasswdCB, "withpassword");
    1513           0 :     get(m_pPasswdPB, "selectpassword");
    1514           0 :     get(m_pHideCB, "hide");
    1515           0 :     get(m_pConditionFT, "condlabel");
    1516           0 :     get(m_pConditionED, "withcond");
    1517             :     // edit in readonly sections
    1518           0 :     get(m_pEditInReadonlyCB, "editable");
    1519             : 
    1520           0 :     m_pProtectCB->SetClickHdl  ( LINK( this, SwInsertSectionTabPage, ChangeProtectHdl));
    1521           0 :     m_pPasswdCB->SetClickHdl   ( LINK( this, SwInsertSectionTabPage, ChangePasswdHdl));
    1522           0 :     m_pPasswdPB->SetClickHdl   ( LINK( this, SwInsertSectionTabPage, ChangePasswdHdl));
    1523           0 :     m_pHideCB->SetClickHdl     ( LINK( this, SwInsertSectionTabPage, ChangeHideHdl));
    1524             :     // edit in readonly sections
    1525           0 :     m_pEditInReadonlyCB->SetClickHdl       ( LINK( this, SwInsertSectionTabPage, ChangeEditInReadonlyHdl));
    1526           0 :     m_pFileCB->SetClickHdl     ( LINK( this, SwInsertSectionTabPage, UseFileHdl ));
    1527           0 :     m_pFilePB->SetClickHdl     ( LINK( this, SwInsertSectionTabPage, FileSearchHdl ));
    1528           0 :     m_pCurName->SetModifyHdl   ( LINK( this, SwInsertSectionTabPage, NameEditHdl));
    1529           0 :     m_pDDECB->SetClickHdl      ( LINK( this, SwInsertSectionTabPage, DDEHdl ));
    1530           0 :     ChangeProtectHdl(m_pProtectCB);
    1531           0 :     m_pSubRegionED->EnableAutocomplete( true, true );
    1532           0 : }
    1533             : 
    1534           0 : SwInsertSectionTabPage::~SwInsertSectionTabPage()
    1535             : {
    1536           0 :     delete m_pDocInserter;
    1537           0 : }
    1538             : 
    1539           0 : void    SwInsertSectionTabPage::SetWrtShell(SwWrtShell& rSh)
    1540             : {
    1541           0 :     m_pWrtSh = &rSh;
    1542             : 
    1543           0 :     bool bWeb = 0 != PTR_CAST(SwWebDocShell, m_pWrtSh->GetView().GetDocShell());
    1544           0 :     if(bWeb)
    1545             :     {
    1546           0 :         m_pHideCB->Hide();
    1547           0 :         m_pConditionED->Hide();
    1548           0 :         m_pConditionFT->Hide();
    1549           0 :         m_pDDECB->Hide();
    1550           0 :         m_pDDECommandFT->Hide();
    1551             :     }
    1552             : 
    1553           0 :     lcl_FillSubRegionList(*m_pWrtSh, *m_pSubRegionED, m_pCurName);
    1554             : 
    1555             :     SwSectionData *const pSectionData =
    1556           0 :         static_cast<SwInsertSectionTabDialog*>(GetTabDialog())
    1557           0 :             ->GetSectionData();
    1558           0 :     if (pSectionData) // something set?
    1559             :     {
    1560           0 :         const OUString sSectionName(pSectionData->GetSectionName());
    1561           0 :         m_pCurName->SetText(rSh.GetUniqueSectionName(&sSectionName));
    1562           0 :         m_pProtectCB->Check( pSectionData->IsProtectFlag() );
    1563           0 :         m_sFileName = pSectionData->GetLinkFileName();
    1564           0 :         m_sFilePasswd = pSectionData->GetLinkFilePassword();
    1565           0 :         m_pFileCB->Check( !m_sFileName.isEmpty() );
    1566           0 :         m_pFileNameED->SetText( m_sFileName );
    1567           0 :         UseFileHdl(m_pFileCB);
    1568             :     }
    1569             :     else
    1570             :     {
    1571           0 :         m_pCurName->SetText( rSh.GetUniqueSectionName() );
    1572             :     }
    1573           0 : }
    1574             : 
    1575           0 : bool SwInsertSectionTabPage::FillItemSet( SfxItemSet* )
    1576             : {
    1577           0 :     SwSectionData aSection(CONTENT_SECTION, m_pCurName->GetText());
    1578           0 :     aSection.SetCondition(m_pConditionED->GetText());
    1579           0 :     bool bProtected = m_pProtectCB->IsChecked();
    1580           0 :     aSection.SetProtectFlag(bProtected);
    1581           0 :     aSection.SetHidden(m_pHideCB->IsChecked());
    1582             :     // edit in readonly sections
    1583           0 :     aSection.SetEditInReadonlyFlag(m_pEditInReadonlyCB->IsChecked());
    1584             : 
    1585           0 :     if(bProtected)
    1586             :     {
    1587           0 :         aSection.SetPassword(m_aNewPasswd);
    1588             :     }
    1589           0 :     const OUString sFileName = m_pFileNameED->GetText();
    1590           0 :     const OUString sSubRegion = m_pSubRegionED->GetText();
    1591           0 :     bool bDDe = m_pDDECB->IsChecked();
    1592           0 :     if(m_pFileCB->IsChecked() && (!sFileName.isEmpty() || !sSubRegion.isEmpty() || bDDe))
    1593             :     {
    1594           0 :         OUString aLinkFile;
    1595           0 :         if( bDDe )
    1596             :         {
    1597           0 :             aLinkFile = SwSectionData::CollapseWhiteSpaces(sFileName);
    1598           0 :             sal_Int32 nPos = 0;
    1599           0 :             aLinkFile = aLinkFile.replaceFirst( " ", OUString(sfx2::cTokenSeparator), &nPos );
    1600           0 :             if (nPos>=0)
    1601             :             {
    1602           0 :                 aLinkFile = aLinkFile.replaceFirst( " ", OUString(sfx2::cTokenSeparator), &nPos );
    1603             :             }
    1604             :         }
    1605             :         else
    1606             :         {
    1607           0 :             if(!sFileName.isEmpty())
    1608             :             {
    1609           0 :                 SfxMedium* pMedium = m_pWrtSh->GetView().GetDocShell()->GetMedium();
    1610           0 :                 INetURLObject aAbs;
    1611           0 :                 if( pMedium )
    1612           0 :                     aAbs = pMedium->GetURLObject();
    1613           0 :                 aLinkFile = URIHelper::SmartRel2Abs(
    1614           0 :                     aAbs, sFileName, URIHelper::GetMaybeFileHdl() );
    1615           0 :                 aSection.SetLinkFilePassword( m_sFilePasswd );
    1616             :             }
    1617             : 
    1618           0 :             aLinkFile += OUString(sfx2::cTokenSeparator) + m_sFilterName
    1619           0 :                       +  OUString(sfx2::cTokenSeparator) + sSubRegion;
    1620             :         }
    1621             : 
    1622           0 :         aSection.SetLinkFileName(aLinkFile);
    1623           0 :         if (!aLinkFile.isEmpty())
    1624             :         {
    1625           0 :             aSection.SetType( m_pDDECB->IsChecked() ?
    1626             :                                     DDE_LINK_SECTION :
    1627           0 :                                         FILE_LINK_SECTION);
    1628           0 :         }
    1629             :     }
    1630           0 :     ((SwInsertSectionTabDialog*)GetTabDialog())->SetSectionData(aSection);
    1631           0 :     return true;
    1632             : }
    1633             : 
    1634           0 : void SwInsertSectionTabPage::Reset( const SfxItemSet* )
    1635             : {
    1636           0 : }
    1637             : 
    1638           0 : SfxTabPage* SwInsertSectionTabPage::Create( vcl::Window* pParent,
    1639             :                                 const SfxItemSet* rAttrSet)
    1640             : {
    1641           0 :     return new SwInsertSectionTabPage(pParent, *rAttrSet);
    1642             : }
    1643             : 
    1644           0 : IMPL_LINK( SwInsertSectionTabPage, ChangeHideHdl, CheckBox *, pBox )
    1645             : {
    1646           0 :     bool bHide = pBox->IsChecked();
    1647           0 :     m_pConditionED->Enable(bHide);
    1648           0 :     m_pConditionFT->Enable(bHide);
    1649           0 :     return 0;
    1650             : }
    1651             : 
    1652           0 : IMPL_LINK_NOARG(SwInsertSectionTabPage, ChangeEditInReadonlyHdl)
    1653             : {
    1654           0 :     return 0;
    1655             : }
    1656             : 
    1657           0 : IMPL_LINK( SwInsertSectionTabPage, ChangeProtectHdl, CheckBox *, pBox )
    1658             : {
    1659           0 :     bool bCheck = pBox->IsChecked();
    1660           0 :     m_pPasswdCB->Enable(bCheck);
    1661           0 :     m_pPasswdPB->Enable(bCheck);
    1662           0 :     return 0;
    1663             : }
    1664             : 
    1665           0 : IMPL_LINK( SwInsertSectionTabPage, ChangePasswdHdl, Button *, pButton )
    1666             : {
    1667           0 :     bool bChange = pButton == m_pPasswdPB;
    1668           0 :     bool bSet = bChange ? bChange : m_pPasswdCB->IsChecked();
    1669           0 :     if(bSet)
    1670             :     {
    1671           0 :         if(!m_aNewPasswd.getLength() || bChange)
    1672             :         {
    1673           0 :             SfxPasswordDialog aPasswdDlg(this);
    1674           0 :             aPasswdDlg.ShowExtras(SHOWEXTRAS_CONFIRM);
    1675           0 :             if(RET_OK == aPasswdDlg.Execute())
    1676             :             {
    1677           0 :                 const OUString sNewPasswd( aPasswdDlg.GetPassword() );
    1678           0 :                 if( aPasswdDlg.GetConfirm() == sNewPasswd )
    1679             :                 {
    1680           0 :                     SvPasswordHelper::GetHashPassword( m_aNewPasswd, sNewPasswd );
    1681             :                 }
    1682             :                 else
    1683             :                 {
    1684           0 :                     MessageDialog(pButton, SW_RES(STR_WRONG_PASSWD_REPEAT), VCL_MESSAGE_INFO).Execute();
    1685           0 :                 }
    1686             :             }
    1687           0 :             else if(!bChange)
    1688           0 :                 m_pPasswdCB->Check(false);
    1689             :         }
    1690             :     }
    1691             :     else
    1692           0 :         m_aNewPasswd.realloc(0);
    1693           0 :     return 0;
    1694             : }
    1695             : 
    1696           0 : IMPL_LINK_NOARG_INLINE_START(SwInsertSectionTabPage, NameEditHdl)
    1697             : {
    1698           0 :     const OUString aName = m_pCurName->GetText();
    1699           0 :     GetTabDialog()->GetOKButton().Enable(!aName.isEmpty() &&
    1700           0 :             m_pCurName->GetEntryPos( aName ) == LISTBOX_ENTRY_NOTFOUND);
    1701           0 :     return 0;
    1702             : }
    1703           0 : IMPL_LINK_NOARG_INLINE_END(SwInsertSectionTabPage, NameEditHdl)
    1704             : 
    1705           0 : IMPL_LINK( SwInsertSectionTabPage, UseFileHdl, CheckBox *, pBox )
    1706             : {
    1707           0 :     if( pBox->IsChecked() )
    1708             :     {
    1709           0 :         if( m_pWrtSh->HasSelection() &&
    1710           0 :             RET_NO == MessageDialog(this, SW_RES(STR_QUERY_CONNECT), VCL_MESSAGE_QUESTION, VCL_BUTTONS_YES_NO).Execute())
    1711           0 :             pBox->Check( false );
    1712             :     }
    1713             : 
    1714           0 :     bool bFile = pBox->IsChecked();
    1715           0 :     m_pFileNameFT->Enable(bFile);
    1716           0 :     m_pFileNameED->Enable(bFile);
    1717           0 :     m_pFilePB->Enable(bFile);
    1718           0 :     m_pSubRegionFT->Enable(bFile);
    1719           0 :     m_pSubRegionED->Enable(bFile);
    1720           0 :     m_pDDECommandFT->Enable(bFile);
    1721           0 :     m_pDDECB->Enable(bFile);
    1722           0 :     if( bFile )
    1723             :     {
    1724           0 :         m_pFileNameED->GrabFocus();
    1725           0 :         m_pProtectCB->Check( true );
    1726             :     }
    1727             :     else
    1728             :     {
    1729           0 :         m_pDDECB->Check(false);
    1730           0 :         DDEHdl(m_pDDECB);
    1731             :     }
    1732           0 :     return 0;
    1733             : }
    1734             : 
    1735           0 : IMPL_LINK_NOARG(SwInsertSectionTabPage, FileSearchHdl)
    1736             : {
    1737           0 :     m_pOldDefDlgParent = Application::GetDefDialogParent();
    1738           0 :     Application::SetDefDialogParent( this );
    1739           0 :     delete m_pDocInserter;
    1740           0 :     m_pDocInserter = new ::sfx2::DocumentInserter( "swriter" );
    1741           0 :     m_pDocInserter->StartExecuteModal( LINK( this, SwInsertSectionTabPage, DlgClosedHdl ) );
    1742           0 :     return 0;
    1743             : }
    1744             : 
    1745           0 : IMPL_LINK( SwInsertSectionTabPage, DDEHdl, CheckBox*, pBox )
    1746             : {
    1747           0 :     bool bDDE = pBox->IsChecked();
    1748           0 :     bool bFile = m_pFileCB->IsChecked();
    1749           0 :     m_pFilePB->Enable(!bDDE && bFile);
    1750           0 :     if(bDDE)
    1751             :     {
    1752           0 :         m_pFileNameFT->Hide();
    1753           0 :         m_pDDECommandFT->Enable(bDDE);
    1754           0 :         m_pDDECommandFT->Show();
    1755           0 :         m_pSubRegionFT->Hide();
    1756           0 :         m_pSubRegionED->Hide();
    1757           0 :         m_pFileNameED->SetAccessibleName(m_pDDECommandFT->GetText());
    1758             :     }
    1759             :     else
    1760             :     {
    1761           0 :         m_pDDECommandFT->Hide();
    1762           0 :         m_pFileNameFT->Enable(bFile);
    1763           0 :         m_pFileNameFT->Show();
    1764           0 :         m_pSubRegionFT->Show();
    1765           0 :         m_pSubRegionED->Show();
    1766           0 :         m_pSubRegionED->Enable(bFile);
    1767           0 :         m_pFileNameED->SetAccessibleName(m_pFileNameFT->GetText());
    1768             :     }
    1769           0 :     return 0;
    1770             : }
    1771             : 
    1772           0 : IMPL_LINK( SwInsertSectionTabPage, DlgClosedHdl, sfx2::FileDialogHelper *, _pFileDlg )
    1773             : {
    1774           0 :     if ( _pFileDlg->GetError() == ERRCODE_NONE )
    1775             :     {
    1776           0 :         boost::scoped_ptr<SfxMedium> pMedium(m_pDocInserter->CreateMedium());
    1777           0 :         if ( pMedium )
    1778             :         {
    1779           0 :             m_sFileName = pMedium->GetURLObject().GetMainURL( INetURLObject::NO_DECODE );
    1780           0 :             m_sFilterName = pMedium->GetFilter()->GetFilterName();
    1781             :             const SfxPoolItem* pItem;
    1782           0 :             if ( SfxItemState::SET == pMedium->GetItemSet()->GetItemState( SID_PASSWORD, false, &pItem ) )
    1783           0 :                 m_sFilePasswd = ( (SfxStringItem*)pItem )->GetValue();
    1784             :             m_pFileNameED->SetText( INetURLObject::decode(
    1785           0 :                 m_sFileName, '%', INetURLObject::DECODE_UNAMBIGUOUS, RTL_TEXTENCODING_UTF8 ) );
    1786           0 :             ::lcl_ReadSections(*pMedium, *m_pSubRegionED);
    1787           0 :         }
    1788             :     }
    1789             :     else
    1790           0 :         m_sFilterName = m_sFilePasswd = aEmptyOUStr;
    1791             : 
    1792           0 :     Application::SetDefDialogParent( m_pOldDefDlgParent );
    1793           0 :     return 0;
    1794             : }
    1795             : 
    1796           0 : SwSectionFtnEndTabPage::SwSectionFtnEndTabPage( vcl::Window *pParent,
    1797             :                                                 const SfxItemSet &rAttrSet)
    1798           0 :     : SfxTabPage( pParent, "FootnotesEndnotesTabPage", "modules/swriter/ui/footnotesendnotestabpage.ui", &rAttrSet )
    1799             : 
    1800             : {
    1801           0 :     get(pFtnNtAtTextEndCB,"ftnntattextend");
    1802             : 
    1803           0 :     get(pFtnNtNumCB,"ftnntnum");
    1804           0 :     get(pFtnOffsetLbl,"ftnoffset_label");
    1805           0 :     get(pFtnOffsetFld,"ftnoffset");
    1806             : 
    1807           0 :     get(pFtnNtNumFmtCB,"ftnntnumfmt");
    1808           0 :     get(pFtnPrefixFT,"ftnprefix_label");
    1809           0 :     get(pFtnPrefixED,"ftnprefix");
    1810           0 :     get(pFtnNumViewBox,"ftnnumviewbox");
    1811           0 :     get(pFtnSuffixFT,"ftnsuffix_label");
    1812           0 :     get(pFtnSuffixED,"ftnsuffix");
    1813             : 
    1814           0 :     get(pEndNtAtTextEndCB,"endntattextend");
    1815             : 
    1816           0 :     get(pEndNtNumCB,"endntnum");
    1817           0 :     get(pEndOffsetLbl,"endoffset_label");
    1818           0 :     get(pEndOffsetFld,"endoffset");
    1819             : 
    1820           0 :     get(pEndNtNumFmtCB,"endntnumfmt");
    1821           0 :     get(pEndPrefixFT,"endprefix_label");
    1822           0 :     get(pEndPrefixED,"endprefix");
    1823           0 :     get(pEndNumViewBox,"endnumviewbox");
    1824           0 :     get(pEndSuffixFT,"endsuffix_label");
    1825           0 :     get(pEndSuffixED,"endsuffix");
    1826             : 
    1827           0 :     Link aLk( LINK( this, SwSectionFtnEndTabPage, FootEndHdl));
    1828           0 :     pFtnNtAtTextEndCB->SetClickHdl( aLk );
    1829           0 :     pFtnNtNumCB->SetClickHdl( aLk );
    1830           0 :     pEndNtAtTextEndCB->SetClickHdl( aLk );
    1831           0 :     pEndNtNumCB->SetClickHdl( aLk );
    1832           0 :     pFtnNtNumFmtCB->SetClickHdl( aLk );
    1833           0 :     pEndNtNumFmtCB->SetClickHdl( aLk );
    1834           0 : }
    1835             : 
    1836           0 : SwSectionFtnEndTabPage::~SwSectionFtnEndTabPage()
    1837             : {
    1838           0 : }
    1839             : 
    1840           0 : bool SwSectionFtnEndTabPage::FillItemSet( SfxItemSet* rSet )
    1841             : {
    1842           0 :     SwFmtFtnAtTxtEnd aFtn( pFtnNtAtTextEndCB->IsChecked()
    1843           0 :                             ? ( pFtnNtNumCB->IsChecked()
    1844           0 :                                 ? ( pFtnNtNumFmtCB->IsChecked()
    1845             :                                     ? FTNEND_ATTXTEND_OWNNUMANDFMT
    1846             :                                     : FTNEND_ATTXTEND_OWNNUMSEQ )
    1847             :                                 : FTNEND_ATTXTEND )
    1848           0 :                             : FTNEND_ATPGORDOCEND );
    1849             : 
    1850           0 :     switch( aFtn.GetValue() )
    1851             :     {
    1852             :     case FTNEND_ATTXTEND_OWNNUMANDFMT:
    1853           0 :         aFtn.SetNumType( pFtnNumViewBox->GetSelectedNumberingType() );
    1854           0 :         aFtn.SetPrefix( pFtnPrefixED->GetText().replaceAll("\\t", "\t") ); // fdo#65666
    1855           0 :         aFtn.SetSuffix( pFtnSuffixED->GetText().replaceAll("\\t", "\t") );
    1856             :         // no break;
    1857             : 
    1858             :     case FTNEND_ATTXTEND_OWNNUMSEQ:
    1859           0 :         aFtn.SetOffset( static_cast< sal_uInt16 >( pFtnOffsetFld->GetValue()-1 ) );
    1860             :         // no break;
    1861             :     }
    1862             : 
    1863           0 :     SwFmtEndAtTxtEnd aEnd( pEndNtAtTextEndCB->IsChecked()
    1864           0 :                             ? ( pEndNtNumCB->IsChecked()
    1865           0 :                                 ? ( pEndNtNumFmtCB->IsChecked()
    1866             :                                     ? FTNEND_ATTXTEND_OWNNUMANDFMT
    1867             :                                     : FTNEND_ATTXTEND_OWNNUMSEQ )
    1868             :                                 : FTNEND_ATTXTEND )
    1869           0 :                             : FTNEND_ATPGORDOCEND );
    1870             : 
    1871           0 :     switch( aEnd.GetValue() )
    1872             :     {
    1873             :     case FTNEND_ATTXTEND_OWNNUMANDFMT:
    1874           0 :         aEnd.SetNumType( pEndNumViewBox->GetSelectedNumberingType() );
    1875           0 :         aEnd.SetPrefix( pEndPrefixED->GetText().replaceAll("\\t", "\t") );
    1876           0 :         aEnd.SetSuffix( pEndSuffixED->GetText().replaceAll("\\t", "\t") );
    1877             :         // no break;
    1878             : 
    1879             :     case FTNEND_ATTXTEND_OWNNUMSEQ:
    1880           0 :         aEnd.SetOffset( static_cast< sal_uInt16 >( pEndOffsetFld->GetValue()-1 ) );
    1881             :         // no break;
    1882             :     }
    1883             : 
    1884           0 :     rSet->Put( aFtn );
    1885           0 :     rSet->Put( aEnd );
    1886             : 
    1887           0 :     return true;
    1888             : }
    1889             : 
    1890           0 : void SwSectionFtnEndTabPage::ResetState( bool bFtn,
    1891             :                                          const SwFmtFtnEndAtTxtEnd& rAttr )
    1892             : {
    1893             :     CheckBox *pNtAtTextEndCB, *pNtNumCB, *pNtNumFmtCB;
    1894             :     FixedText*pPrefixFT, *pSuffixFT;
    1895             :     Edit *pPrefixED, *pSuffixED;
    1896             :     SwNumberingTypeListBox *pNumViewBox;
    1897             :     FixedText* pOffsetTxt;
    1898             :     NumericField *pOffsetFld;
    1899             : 
    1900           0 :     if( bFtn )
    1901             :     {
    1902           0 :         pNtAtTextEndCB = pFtnNtAtTextEndCB;
    1903           0 :         pNtNumCB = pFtnNtNumCB;
    1904           0 :         pNtNumFmtCB = pFtnNtNumFmtCB;
    1905           0 :         pPrefixFT = pFtnPrefixFT;
    1906           0 :         pPrefixED = pFtnPrefixED;
    1907           0 :         pSuffixFT = pFtnSuffixFT;
    1908           0 :         pSuffixED = pFtnSuffixED;
    1909           0 :         pNumViewBox = pFtnNumViewBox;
    1910           0 :         pOffsetTxt = pFtnOffsetLbl;
    1911           0 :         pOffsetFld = pFtnOffsetFld;
    1912             :     }
    1913             :     else
    1914             :     {
    1915           0 :         pNtAtTextEndCB = pEndNtAtTextEndCB;
    1916           0 :         pNtNumCB = pEndNtNumCB;
    1917           0 :         pNtNumFmtCB = pEndNtNumFmtCB;
    1918           0 :         pPrefixFT = pEndPrefixFT;
    1919           0 :         pPrefixED = pEndPrefixED;
    1920           0 :         pSuffixFT = pEndSuffixFT;
    1921           0 :         pSuffixED = pEndSuffixED;
    1922           0 :         pNumViewBox = pEndNumViewBox;
    1923           0 :         pOffsetTxt = pEndOffsetLbl;
    1924           0 :         pOffsetFld = pEndOffsetFld;
    1925             :     }
    1926             : 
    1927           0 :     const sal_uInt16 eState = rAttr.GetValue();
    1928           0 :     switch( eState )
    1929             :     {
    1930             :     case FTNEND_ATTXTEND_OWNNUMANDFMT:
    1931           0 :         pNtNumFmtCB->SetState( TRISTATE_TRUE );
    1932             :         // no break;
    1933             : 
    1934             :     case FTNEND_ATTXTEND_OWNNUMSEQ:
    1935           0 :         pNtNumCB->SetState( TRISTATE_TRUE );
    1936             :         // no break;
    1937             : 
    1938             :     case FTNEND_ATTXTEND:
    1939           0 :         pNtAtTextEndCB->SetState( TRISTATE_TRUE );
    1940             :         // no break;
    1941             :     }
    1942             : 
    1943           0 :     pNumViewBox->SelectNumberingType( rAttr.GetNumType() );
    1944           0 :     pOffsetFld->SetValue( rAttr.GetOffset() + 1 );
    1945           0 :     pPrefixED->SetText( rAttr.GetPrefix().replaceAll("\t", "\\t") );
    1946           0 :     pSuffixED->SetText( rAttr.GetSuffix().replaceAll("\t", "\\t") );
    1947             : 
    1948           0 :     switch( eState )
    1949             :     {
    1950             :     case FTNEND_ATPGORDOCEND:
    1951           0 :         pNtNumCB->Enable( false );
    1952             :         // no break;
    1953             : 
    1954             :     case FTNEND_ATTXTEND:
    1955           0 :         pNtNumFmtCB->Enable( false );
    1956           0 :         pOffsetFld->Enable( false );
    1957           0 :         pOffsetTxt->Enable( false );
    1958             :         // no break;
    1959             : 
    1960             :     case FTNEND_ATTXTEND_OWNNUMSEQ:
    1961           0 :         pNumViewBox->Enable( false );
    1962           0 :         pPrefixFT->Enable( false );
    1963           0 :         pPrefixED->Enable( false );
    1964           0 :         pSuffixFT->Enable( false );
    1965           0 :         pSuffixED->Enable( false );
    1966             :         // no break;
    1967             :     }
    1968           0 : }
    1969             : 
    1970           0 : void SwSectionFtnEndTabPage::Reset( const SfxItemSet* rSet )
    1971             : {
    1972             :     ResetState( true, (const SwFmtFtnAtTxtEnd&)rSet->Get(
    1973           0 :                                     RES_FTN_AT_TXTEND, false ));
    1974             :     ResetState( false, (const SwFmtEndAtTxtEnd&)rSet->Get(
    1975           0 :                                     RES_END_AT_TXTEND, false ));
    1976           0 : }
    1977             : 
    1978           0 : SfxTabPage* SwSectionFtnEndTabPage::Create( vcl::Window* pParent,
    1979             :                                 const SfxItemSet* rAttrSet)
    1980             : {
    1981           0 :     return new SwSectionFtnEndTabPage(pParent, *rAttrSet);
    1982             : }
    1983             : 
    1984           0 : IMPL_LINK( SwSectionFtnEndTabPage, FootEndHdl, CheckBox *, pBox )
    1985             : {
    1986           0 :     bool bFoot = pFtnNtAtTextEndCB == pBox || pFtnNtNumCB == pBox ||
    1987           0 :                     pFtnNtNumFmtCB == pBox ;
    1988             : 
    1989             :     CheckBox *pNumBox, *pNumFmtBox, *pEndBox;
    1990             :     SwNumberingTypeListBox* pNumViewBox;
    1991             :     FixedText* pOffsetTxt;
    1992             :     NumericField *pOffsetFld;
    1993             :     FixedText*pPrefixFT, *pSuffixFT;
    1994             :     Edit *pPrefixED, *pSuffixED;
    1995             : 
    1996           0 :     if( bFoot )
    1997             :     {
    1998           0 :         pEndBox = pFtnNtAtTextEndCB;
    1999           0 :         pNumBox = pFtnNtNumCB;
    2000           0 :         pNumFmtBox = pFtnNtNumFmtCB;
    2001           0 :         pNumViewBox = pFtnNumViewBox;
    2002           0 :         pOffsetTxt = pFtnOffsetLbl;
    2003           0 :         pOffsetFld = pFtnOffsetFld;
    2004           0 :         pPrefixFT = pFtnPrefixFT;
    2005           0 :         pSuffixFT = pFtnSuffixFT;
    2006           0 :         pPrefixED = pFtnPrefixED;
    2007           0 :         pSuffixED = pFtnSuffixED;
    2008             :     }
    2009             :     else
    2010             :     {
    2011           0 :         pEndBox = pEndNtAtTextEndCB;
    2012           0 :         pNumBox = pEndNtNumCB;
    2013           0 :         pNumFmtBox = pEndNtNumFmtCB;
    2014           0 :         pNumViewBox = pEndNumViewBox;
    2015           0 :         pOffsetTxt = pEndOffsetLbl;
    2016           0 :         pOffsetFld = pEndOffsetFld;
    2017           0 :         pPrefixFT = pEndPrefixFT;
    2018           0 :         pSuffixFT = pEndSuffixFT;
    2019           0 :         pPrefixED = pEndPrefixED;
    2020           0 :         pSuffixED = pEndSuffixED;
    2021             :     }
    2022             : 
    2023           0 :     bool bEnableAtEnd = TRISTATE_TRUE == pEndBox->GetState();
    2024           0 :     bool bEnableNum = bEnableAtEnd && TRISTATE_TRUE == pNumBox->GetState();
    2025           0 :     bool bEnableNumFmt = bEnableNum && TRISTATE_TRUE == pNumFmtBox->GetState();
    2026             : 
    2027           0 :     pNumBox->Enable( bEnableAtEnd );
    2028           0 :     pOffsetTxt->Enable( bEnableNum );
    2029           0 :     pOffsetFld->Enable( bEnableNum );
    2030           0 :     pNumFmtBox->Enable( bEnableNum );
    2031           0 :     pNumViewBox->Enable( bEnableNumFmt );
    2032           0 :     pPrefixED->Enable( bEnableNumFmt );
    2033           0 :     pSuffixED->Enable( bEnableNumFmt );
    2034           0 :     pPrefixFT->Enable( bEnableNumFmt );
    2035           0 :     pSuffixFT->Enable( bEnableNumFmt );
    2036             : 
    2037           0 :     return 0;
    2038             : }
    2039             : 
    2040           0 : SwSectionPropertyTabDialog::SwSectionPropertyTabDialog(
    2041             :     vcl::Window* pParent, const SfxItemSet& rSet, SwWrtShell& rSh)
    2042             :     : SfxTabDialog(pParent, "FormatSectionDialog",
    2043             :         "modules/swriter/ui/formatsectiondialog.ui", &rSet)
    2044           0 :     , rWrtSh(rSh)
    2045             : {
    2046           0 :     SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
    2047             :     OSL_ENSURE(pFact, "Dialog creation failed!");
    2048           0 :     m_nColumnPageId = AddTabPage("columns",   SwColumnPage::Create,    0);
    2049           0 :     m_nBackPageId = AddTabPage("background", pFact->GetTabPageCreatorFunc( RID_SVXPAGE_BACKGROUND ), 0 );
    2050           0 :     m_nNotePageId = AddTabPage("notes", SwSectionFtnEndTabPage::Create, 0);
    2051           0 :     m_nIndentPage = AddTabPage("indents", SwSectionIndentTabPage::Create, 0);
    2052             : 
    2053           0 :     SvxHtmlOptions& rHtmlOpt = SvxHtmlOptions::Get();
    2054           0 :     long nHtmlMode = rHtmlOpt.GetExportMode();
    2055           0 :     bool bWeb = 0 != PTR_CAST( SwWebDocShell, rSh.GetView().GetDocShell() );
    2056           0 :     if(bWeb)
    2057             :     {
    2058           0 :         RemoveTabPage(m_nNotePageId);
    2059           0 :         RemoveTabPage(m_nIndentPage);
    2060           0 :         if( HTML_CFG_NS40 != nHtmlMode && HTML_CFG_WRITER != nHtmlMode)
    2061           0 :             RemoveTabPage(m_nColumnPageId);
    2062             :     }
    2063           0 : }
    2064             : 
    2065           0 : SwSectionPropertyTabDialog::~SwSectionPropertyTabDialog()
    2066             : {
    2067           0 : }
    2068             : 
    2069           0 : void SwSectionPropertyTabDialog::PageCreated( sal_uInt16 nId, SfxTabPage &rPage )
    2070             : {
    2071           0 :     if (nId == m_nBackPageId)
    2072             :     {
    2073           0 :             SfxAllItemSet aSet(*(GetInputSetImpl()->GetPool()));
    2074           0 :             aSet.Put (SfxUInt32Item(SID_FLAG_TYPE, SVX_SHOW_SELECTOR));
    2075           0 :             rPage.PageCreated(aSet);
    2076             :     }
    2077           0 :     else if (nId == m_nColumnPageId)
    2078             :     {
    2079           0 :         ((SwColumnPage&)rPage).ShowBalance(true);
    2080           0 :         ((SwColumnPage&)rPage).SetInSection(true);
    2081             :     }
    2082           0 :     else if (nId == m_nIndentPage)
    2083           0 :         ((SwSectionIndentTabPage&)rPage).SetWrtShell(rWrtSh);
    2084           0 : }
    2085             : 
    2086           0 : SwSectionIndentTabPage::SwSectionIndentTabPage(vcl::Window *pParent, const SfxItemSet &rAttrSet)
    2087           0 :     : SfxTabPage(pParent, "IndentPage", "modules/swriter/ui/indentpage.ui", &rAttrSet)
    2088             : {
    2089           0 :     get(m_pBeforeMF, "before");
    2090           0 :     get(m_pAfterMF, "after");
    2091           0 :     get(m_pPreviewWin, "preview");
    2092           0 :     Link aLk = LINK(this, SwSectionIndentTabPage, IndentModifyHdl);
    2093           0 :     m_pBeforeMF->SetModifyHdl(aLk);
    2094           0 :     m_pAfterMF->SetModifyHdl(aLk);
    2095           0 : }
    2096             : 
    2097           0 : SwSectionIndentTabPage::~SwSectionIndentTabPage()
    2098             : {
    2099           0 : }
    2100             : 
    2101           0 : bool SwSectionIndentTabPage::FillItemSet( SfxItemSet* rSet)
    2102             : {
    2103           0 :     if(m_pBeforeMF->IsValueModified() ||
    2104           0 :             m_pAfterMF->IsValueModified())
    2105             :     {
    2106             :         SvxLRSpaceItem aLRSpace(
    2107           0 :                 static_cast< long >(m_pBeforeMF->Denormalize(m_pBeforeMF->GetValue(FUNIT_TWIP))) ,
    2108           0 :                 static_cast< long >(m_pAfterMF->Denormalize(m_pAfterMF->GetValue(FUNIT_TWIP))), 0, 0, RES_LR_SPACE);
    2109           0 :         rSet->Put(aLRSpace);
    2110             :     }
    2111           0 :     return true;
    2112             : }
    2113             : 
    2114           0 : void SwSectionIndentTabPage::Reset( const SfxItemSet* rSet)
    2115             : {
    2116             :     //this page doesn't show up in HTML mode
    2117           0 :     FieldUnit aMetric = ::GetDfltMetric(false);
    2118           0 :     SetMetric(*m_pBeforeMF, aMetric);
    2119           0 :     SetMetric(*m_pAfterMF , aMetric);
    2120             : 
    2121           0 :     SfxItemState eItemState = rSet->GetItemState( RES_LR_SPACE );
    2122           0 :     if ( eItemState >= SfxItemState::DEFAULT )
    2123             :     {
    2124             :         const SvxLRSpaceItem& rSpace =
    2125           0 :             (const SvxLRSpaceItem&)rSet->Get( RES_LR_SPACE );
    2126             : 
    2127           0 :         m_pBeforeMF->SetValue( m_pBeforeMF->Normalize(rSpace.GetLeft()), FUNIT_TWIP );
    2128           0 :         m_pAfterMF->SetValue( m_pAfterMF->Normalize(rSpace.GetRight()), FUNIT_TWIP );
    2129             :     }
    2130             :     else
    2131             :     {
    2132           0 :         m_pBeforeMF->SetEmptyFieldValue();
    2133           0 :         m_pAfterMF->SetEmptyFieldValue();
    2134             :     }
    2135           0 :     m_pBeforeMF->SaveValue();
    2136           0 :     m_pAfterMF->SaveValue();
    2137           0 :     IndentModifyHdl(0);
    2138           0 : }
    2139             : 
    2140           0 : SfxTabPage*  SwSectionIndentTabPage::Create( vcl::Window* pParent, const SfxItemSet* rAttrSet)
    2141             : {
    2142           0 :     return new SwSectionIndentTabPage(pParent, *rAttrSet);
    2143             : }
    2144             : 
    2145           0 : void SwSectionIndentTabPage::SetWrtShell(SwWrtShell& rSh)
    2146             : {
    2147             :     //set sensible values at the preview
    2148           0 :     m_pPreviewWin->SetAdjust(SVX_ADJUST_BLOCK);
    2149           0 :     m_pPreviewWin->SetLastLine(SVX_ADJUST_BLOCK);
    2150           0 :     const SwRect& rPageRect = rSh.GetAnyCurRect( RECT_PAGE, 0 );
    2151           0 :     Size aPageSize(rPageRect.Width(), rPageRect.Height());
    2152           0 :     m_pPreviewWin->SetSize(aPageSize);
    2153           0 : }
    2154             : 
    2155           0 : IMPL_LINK_NOARG(SwSectionIndentTabPage, IndentModifyHdl)
    2156             : {
    2157           0 :     m_pPreviewWin->SetLeftMargin( static_cast< long >(m_pBeforeMF->Denormalize(m_pBeforeMF->GetValue(FUNIT_TWIP))) );
    2158           0 :     m_pPreviewWin->SetRightMargin( static_cast< long >(m_pAfterMF->Denormalize(m_pAfterMF->GetValue(FUNIT_TWIP))) );
    2159           0 :     m_pPreviewWin->Draw(true);
    2160           0 :     return 0;
    2161           0 : }
    2162             : 
    2163             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10