LCOV - code coverage report
Current view: top level - libreoffice/sfx2/source/doc - docvor.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 941 0.0 %
Date: 2012-12-17 Functions: 0 78 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 <com/sun/star/embed/XStorage.hpp>
      21             : #include <com/sun/star/embed/ElementModes.hpp>
      22             : #include <com/sun/star/beans/XPropertySet.hpp>
      23             : #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
      24             : 
      25             : #include <stdio.h>
      26             : 
      27             : #include <svtools/prnsetup.hxx>
      28             : #include <vcl/cmdevt.hxx>
      29             : #include <vcl/menubtn.hxx>
      30             : #include <vcl/msgbox.hxx>
      31             : #include <vcl/print.hxx>
      32             : #include <svl/style.hxx>
      33             : #include <svl/stritem.hxx>
      34             : #include <svl/eitem.hxx>
      35             : #include <svtools/sfxecode.hxx>
      36             : #include <svtools/ehdl.hxx>
      37             : #include <svtools/imagemgr.hxx>
      38             : #include <vcl/waitobj.hxx>
      39             : #include <tools/urlobj.hxx>
      40             : #include <tools/color.hxx>
      41             : #include <unotools/pathoptions.hxx>
      42             : #include <unotools/moduleoptions.hxx>
      43             : #include <sot/exchange.hxx>
      44             : #include <comphelper/storagehelper.hxx>
      45             : 
      46             : #include "helpid.hrc"
      47             : #include "docvor.hxx"
      48             : #include <sfx2/docfac.hxx>
      49             : #include "orgmgr.hxx"
      50             : #include <sfx2/doctempl.hxx>
      51             : #include <sfx2/templdlg.hxx>
      52             : #include "sfxtypes.hxx"
      53             : #include <sfx2/app.hxx>
      54             : #include <sfx2/dispatch.hxx>
      55             : #include "sfx2/sfxresid.hxx"
      56             : #include "doc.hrc"
      57             : #include <sfx2/sfx.hrc>
      58             : #include <sfx2/docfilt.hxx>
      59             : #include <sfx2/filedlghelper.hxx>
      60             : #include <sfx2/fcontnr.hxx>
      61             : #include <svtools/localresaccess.hxx>
      62             : #include <svtools/addresstemplate.hxx>
      63             : #include "svtools/treelistentry.hxx"
      64             : #include <comphelper/processfactory.hxx>
      65             : 
      66             : #define ID_NEW                     1
      67             : #define ID_DELETE                  2
      68             : #define ID_EDIT                    3
      69             : //seperator
      70             : #define ID_COPY_FROM               5
      71             : #define ID_COPY_TO                 6
      72             : //seperator
      73             : #define ID_PRINT                   8
      74             : #define ID_PRINTER_SETUP           9
      75             : //seperator
      76             : #define ID_RESCAN                 11
      77             : //seperator
      78             : #define ID_DEFAULT_TEMPLATE       13
      79             : #define ID_RESET_DEFAULT_TEMPLATE 14
      80             : 
      81             : sal_Bool SfxOrganizeListBox_Impl::bDropMoveOk = sal_True;
      82             : 
      83             : using namespace ::com::sun::star;
      84             : 
      85             : //=========================================================================
      86             : 
      87             : class SuspendAccel
      88             : {
      89             : public:
      90             :     Accelerator*    pAccel;
      91             : 
      92           0 :     SuspendAccel( Accelerator* pA )
      93             :     {
      94           0 :         pAccel=pA;
      95           0 :         GetpApp()->RemoveAccel( pAccel );
      96           0 :     }
      97           0 :     ~SuspendAccel()
      98             :     {
      99           0 :         GetpApp()->InsertAccel( pAccel );
     100           0 :     }
     101             : };
     102             : 
     103             : //=========================================================================
     104             : 
     105           0 : extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeSfxOrganizeListBox(Window *pParent,
     106             :     VclBuilder::stringmap &)
     107             : {
     108           0 :     return new SfxOrganizeListBox_Impl(pParent, WB_BORDER | WB_TABSTOP | WB_HSCROLL);
     109             : }
     110             : 
     111           0 : inline void SfxOrganizeListBox_Impl::SetBitmaps(
     112             :     const Image &rOFolder, const Image &rCFolder, const Image &rODoc, const Image &rCDoc )
     113             : {
     114           0 :     aOpenedFolderBmp = rOFolder;
     115           0 :     aClosedFolderBmp = rCFolder;
     116           0 :     aOpenedDocBmp = rODoc;
     117           0 :     aClosedDocBmp = rCDoc;
     118             : 
     119           0 : }
     120             : 
     121             : //=========================================================================
     122             : 
     123             : #define NO_DROP_ACTION  ((sal_Int8)-1)
     124             : 
     125             : class SfxOrganizeDlg_Impl
     126             : {
     127             : friend class SfxTemplateOrganizeDlg;
     128             : friend class SfxOrganizeListBox_Impl;
     129             : 
     130             :     SuspendAccel*           pSuspend;
     131             :     SfxTemplateOrganizeDlg* pDialog;
     132             : 
     133             :     SfxOrganizeListBox_Impl* pFocusBox;
     134             :     Printer*                 pPrt;
     135             : 
     136             :     // save pointer for asynchronous D&D
     137             :     SvTreeListBox*                 pSourceView;
     138             :     SvTreeListEntry*            pTargetEntry;
     139             :     SfxOrganizeListBox_Impl* pFinishedBox;
     140             :     sal_Int8                nDropAction;
     141             :     bool                    bExecDropFinished;
     142             : 
     143             :     // save some variables for the asynchronous file dialog
     144             :     sal_uInt16                  m_nRegion;
     145             :     sal_uInt16                  m_nIndex;
     146             :     String                  m_sExtension4Save;
     147             : 
     148             :     SfxOrganizeListBox_Impl* m_pLeftLb;
     149             :     ListBox*                m_pLeftTypLb;
     150             : 
     151             :     SfxOrganizeListBox_Impl* m_pRightLb;
     152             :     ListBox*                m_pRightTypLb;
     153             : 
     154             :     MenuButton*             m_pEditBtn;
     155             :     PushButton*             m_pAddressTemplateBtn;
     156             :     PushButton*             m_pFilesBtn;
     157             : 
     158             :     Accelerator             aEditAcc;
     159             : 
     160             :     String                  aLastDir;
     161             :     SfxOrganizeMgr          aMgr;
     162             :     sfx2::FileDialogHelper* pFileDlg;
     163             : 
     164             :     std::vector<rtl::OUString> GetAllFactoryURLs_Impl() const;
     165             :     sal_Bool                GetServiceName_Impl( String& rFactoryURL, String& rFileURL ) const;
     166             :     long                    Dispatch_Impl( sal_uInt16 nId, Menu* _pMenu );
     167             :     String                  GetPath_Impl( sal_Bool bOpen, const String& rFileName );
     168             :     ::com::sun::star::uno::Sequence< ::rtl::OUString >
     169             :                             GetPaths_Impl( const String& rFileName );
     170             :     void                    InitBitmaps( void );
     171             : 
     172             :     DECL_LINK( GetFocus_Impl, SfxOrganizeListBox_Impl * );
     173             :     DECL_LINK( LeftListBoxSelect_Impl, ListBox * );
     174             :     DECL_LINK( RightListBoxSelect_Impl, ListBox * );
     175             :     DECL_LINK( AccelSelect_Impl, Accelerator * );
     176             :     DECL_LINK( MenuSelect_Impl, Menu * );
     177             :     DECL_LINK( MenuActivate_Impl, Menu * );
     178             :     DECL_LINK( AddFiles_Impl, Button * );
     179             :     DECL_LINK( OnAddressTemplateClicked, void * );
     180             :     DECL_LINK( Close_Impl, void * );
     181             : 
     182             :     DECL_LINK(ImportHdl, void *);
     183             :     DECL_LINK(ExportHdl, void *);
     184             :     DECL_LINK(AddFilesHdl, void *);
     185             : 
     186             :     sal_Bool        DontDelete_Impl( SvTreeListEntry* pEntry );
     187             : 
     188             : public:
     189             :     SfxOrganizeDlg_Impl( SfxTemplateOrganizeDlg* pParent, SfxDocumentTemplates* pTempl );
     190             :     ~SfxOrganizeDlg_Impl();
     191             : };
     192             : 
     193             : //-------------------------------------------------------------------------
     194             : 
     195           0 : SfxOrganizeDlg_Impl::SfxOrganizeDlg_Impl( SfxTemplateOrganizeDlg* pParent,
     196             :                                           SfxDocumentTemplates* pTempl ) :
     197             :     pSuspend            ( NULL ),
     198             :     pDialog             ( pParent ),
     199             :     pFocusBox           ( NULL ),
     200             :     pPrt                ( NULL ),
     201             :     pSourceView         ( NULL ),
     202             :     pTargetEntry        ( NULL ),
     203             :     pFinishedBox        ( NULL ),
     204             :     nDropAction         ( NO_DROP_ACTION ),
     205             :     bExecDropFinished   ( true ),
     206             : 
     207             :     aMgr        ( pTempl ),
     208           0 :     pFileDlg    ( NULL )
     209             : 
     210             : {
     211           0 :     aEditAcc.InsertItem(ID_NEW, KeyCode(KEY_INSERT));
     212           0 :     aEditAcc.InsertItem(ID_DELETE, KeyCode(KEY_DELETE));
     213             : 
     214           0 :     pDialog->get(m_pLeftTypLb, "lefttype");
     215           0 :     pDialog->get(m_pLeftLb, "leftorganizer");
     216           0 :     m_pLeftLb->Init(this, SfxOrganizeListBox_Impl::VIEW_TEMPLATES);
     217             : 
     218             :     //20 lines
     219           0 :     m_pLeftLb->set_height_request(m_pLeftLb->GetEntryHeight() * 20);
     220             : 
     221           0 :     pDialog->get(m_pRightTypLb, "righttype");
     222           0 :     pDialog->get(m_pRightLb, "rightorganizer");
     223           0 :     m_pRightLb->Init(this, SfxOrganizeListBox_Impl::VIEW_FILES);
     224             : 
     225           0 :     pDialog->get(m_pEditBtn, "commands");
     226           0 :     pDialog->get(m_pAddressTemplateBtn, "addressbook");
     227           0 :     pDialog->get(m_pFilesBtn, "file");
     228             : 
     229           0 :     PushButton *pClose = pDialog->get<PushButton>("close");
     230           0 :     pClose->SetClickHdl(LINK(this,SfxOrganizeDlg_Impl, Close_Impl));
     231             : 
     232             :     // update the SfxDocumentTemplates the manager works with
     233           0 :     if ( aMgr.GetTemplates() )  // should never fail, but who knows ....
     234             :     {
     235             :         // for this, show a wait cursor (it may take a while)
     236           0 :         Window* pWaitObjectRange = pDialog ? pDialog->GetParent() : NULL;
     237           0 :         if ( !pWaitObjectRange )
     238           0 :             pWaitObjectRange = pDialog;
     239             : 
     240           0 :         WaitObject aWaitCursor( pWaitObjectRange );
     241           0 :         const_cast< SfxDocumentTemplates* >( aMgr.GetTemplates() )->Update( sal_True /* be smart */ );
     242             :             // this const_cast is a hack - but the alternative would be to
     243             :             // * have a method which returns the templates non-const
     244             :             // * use a new SfxDocumentTemplates instance for the update
     245             :             //   (knowing that they all share the same implementation class)
     246             :             // * always work with an own instance, even if we get only NULL in this ctor
     247             :     }
     248             : 
     249           0 :     String aWorkPath = SvtPathOptions().GetWorkPath();
     250           0 :     if ( aWorkPath.Len() )
     251             :     {
     252           0 :         INetURLObject aObj( aWorkPath );
     253             :         DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Illegal URL !" );
     254           0 :         aObj.setFinalSlash();
     255           0 :         aLastDir = aObj.GetMainURL( INetURLObject::DECODE_TO_IURI );
     256             :     }
     257             :     else
     258             :     {
     259             :         // fallback
     260           0 :         String aProgURL = SvtPathOptions().SubstituteVariable( rtl::OUString("$(PROGURL)") );
     261           0 :         INetURLObject aObj( aProgURL );
     262             :         DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Illegal URL !" );
     263           0 :         aLastDir = aObj.GetMainURL( INetURLObject::DECODE_TO_IURI );
     264             :     }
     265             : 
     266           0 :     InitBitmaps();
     267             : 
     268           0 :     m_pEditBtn->GetPopupMenu()->SetSelectHdl( LINK( this, SfxOrganizeDlg_Impl, MenuSelect_Impl ) );
     269           0 :     m_pEditBtn->GetPopupMenu()->SetActivateHdl( LINK( this, SfxOrganizeDlg_Impl, MenuActivate_Impl ) );
     270           0 :     aEditAcc.SetSelectHdl( LINK( this, SfxOrganizeDlg_Impl, AccelSelect_Impl ) );
     271           0 :     GetpApp()->InsertAccel( &aEditAcc );
     272             : 
     273             :     m_pFilesBtn->SetClickHdl(
     274           0 :         LINK(this,SfxOrganizeDlg_Impl, AddFiles_Impl));
     275             :     m_pAddressTemplateBtn->SetClickHdl(
     276           0 :         LINK(this,SfxOrganizeDlg_Impl, OnAddressTemplateClicked));
     277             :     m_pLeftTypLb->SetSelectHdl(
     278           0 :         LINK(this, SfxOrganizeDlg_Impl, LeftListBoxSelect_Impl));
     279             :     m_pRightTypLb->SetSelectHdl(
     280           0 :         LINK(this, SfxOrganizeDlg_Impl, RightListBoxSelect_Impl));
     281             :     m_pLeftLb->SetGetFocusHdl(
     282           0 :         LINK(this, SfxOrganizeDlg_Impl, GetFocus_Impl));
     283             :     m_pRightLb->SetGetFocusHdl(
     284           0 :         LINK(this, SfxOrganizeDlg_Impl, GetFocus_Impl));
     285           0 :     m_pLeftLb->SetPosSizePixel(pParent->LogicToPixel(Point(3, 6), MAP_APPFONT),
     286           0 :                             pParent->LogicToPixel(Size(94, 132), MAP_APPFONT));
     287           0 :     m_pRightLb->SetPosSizePixel(pParent->LogicToPixel(Point(103, 6), MAP_APPFONT),
     288           0 :                              pParent->LogicToPixel(Size(94, 132), MAP_APPFONT));
     289             : 
     290           0 :     if ( !SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::E_SDATABASE) )
     291           0 :         m_pAddressTemplateBtn->Hide();
     292           0 :     Font aFont(m_pLeftLb->GetFont());
     293           0 :     aFont.SetWeight(WEIGHT_NORMAL);
     294           0 :     m_pLeftLb->SetFont(aFont);
     295           0 :     m_pRightLb->SetFont(aFont);
     296           0 :     const long nIndent = m_pLeftLb->GetIndent() / 2;
     297           0 :     m_pLeftLb->SetIndent( (short)nIndent );
     298           0 :     m_pRightLb->SetIndent( (short)nIndent );
     299             : 
     300           0 :     m_pLeftLb->SetMgr(&aMgr);
     301           0 :     m_pRightLb->SetMgr(&aMgr);
     302           0 :     m_pLeftLb->Reset();
     303           0 :     m_pRightLb->Reset();//SetModel(m_pLeftLb->GetModel());
     304             : 
     305           0 :     m_pLeftLb->Show();
     306           0 :     m_pRightLb->Show();
     307             : 
     308           0 :     m_pLeftLb->SelectAll( sal_False );
     309           0 :     m_pRightLb->SelectAll( sal_False );
     310           0 :     m_pRightLb->GrabFocus();
     311           0 : }
     312             : 
     313             : //-------------------------------------------------------------------------
     314             : 
     315           0 : SfxOrganizeDlg_Impl::~SfxOrganizeDlg_Impl()
     316             : {
     317           0 :     delete pFileDlg;
     318           0 : }
     319             : 
     320             : //-------------------------------------------------------------------------
     321             : 
     322           0 : void SfxOrganizeDlg_Impl::InitBitmaps( void )
     323             : {
     324           0 :     const Image& rOpenedFolderBmp(pDialog->get<FixedImage>("folderop")->GetImage());
     325           0 :     const Image& rClosedFolderBmp(pDialog->get<FixedImage>("foldercl")->GetImage());
     326           0 :     const Image& rOpenedDocBmp(pDialog->get<FixedImage>("docop")->GetImage());
     327           0 :     const Image& rClosedDocBmp(pDialog->get<FixedImage>("doccl")->GetImage());
     328             : 
     329           0 :     m_pLeftLb->SetBitmaps(rOpenedFolderBmp, rClosedFolderBmp, rOpenedDocBmp, rClosedDocBmp);
     330           0 :     m_pRightLb->SetBitmaps(rOpenedFolderBmp, rClosedFolderBmp, rOpenedDocBmp, rClosedDocBmp);
     331           0 : }
     332             : 
     333             : //=========================================================================
     334             : 
     335           0 : sal_Bool QueryDelete_Impl(Window *pParent,      // Parent to QueryBox
     336             :                              sal_uInt16 nId,            // Resource Id
     337             :                              const String &rTemplateName)   // Name of template to be deleted
     338             : /*  [Description]
     339             : 
     340             :     Delete Query
     341             : 
     342             : */
     343             : {
     344           0 :     SfxResId aResId( nId );
     345           0 :     String aEntryText( aResId.toString() );
     346           0 :     aEntryText.SearchAndReplaceAscii( "$1", rTemplateName );
     347           0 :     QueryBox aBox( pParent, WB_YES_NO | WB_DEF_NO, aEntryText );
     348           0 :     return RET_NO != aBox.Execute();
     349             : }
     350             : 
     351             : //-------------------------------------------------------------------------
     352             : 
     353           0 : void ErrorDelete_Impl(Window *pParent, const String &rName, sal_Bool bFolder = sal_False )
     354             : 
     355             : /*  [Description]
     356             : 
     357             :     User information that the template rName could not be deleted.
     358             : */
     359             : {
     360           0 :     if ( bFolder )
     361             :     {
     362           0 :         rtl::OUString aText(SfxResId(STR_ERROR_DELETE_TEMPLATE_DIR).toString());
     363           0 :         ErrorBox( pParent, WB_OK, aText ).Execute();
     364             :     }
     365             :     else
     366             :     {
     367           0 :         String aText( SfxResId(STR_ERROR_DELETE_TEMPLATE).toString() );
     368           0 :         aText.SearchAndReplaceAscii( "$1", rName );
     369           0 :         ErrorBox( pParent, WB_OK, aText ).Execute();
     370             :     }
     371           0 : }
     372             : 
     373             : 
     374             : //=========================================================================
     375             : 
     376             : /*  [Description]
     377             : 
     378             :     Implementation class, the benchmark for sal_uInt16-Array
     379             : */
     380             : 
     381           0 : struct ImpPath_Impl
     382             : {
     383             :     std::vector<sal_uInt16> aUS;
     384             :     sal_uInt16      nRef;
     385             : 
     386             :     ImpPath_Impl();
     387             :     ImpPath_Impl( const ImpPath_Impl& rCopy );
     388             : };
     389             : 
     390             : //-------------------------------------------------------------------------
     391             : 
     392           0 : ImpPath_Impl::ImpPath_Impl() : nRef(1)
     393             : {
     394           0 : }
     395             : 
     396             : //-------------------------------------------------------------------------
     397             : 
     398           0 : ImpPath_Impl::ImpPath_Impl( const ImpPath_Impl& rCopy ) :
     399             : 
     400           0 :     aUS(rCopy.aUS), nRef( 1 )
     401             : 
     402             : {
     403           0 : }
     404             : 
     405             : //==========================================================================
     406             : 
     407             : /*  [Description]
     408             : 
     409             :     Implementation class, presentation of a position in the Outline-
     410             :     Listbox ass sal_uInt16-Array, this describes the position of each as
     411             :     Postions relative to the parent entry
     412             : */
     413             : class Path
     414             : {
     415             :     ImpPath_Impl *pData;
     416             : public:
     417             :     Path(SvTreeListBox *pBox, SvTreeListEntry *pEntry);
     418             :     Path(const Path &rPath):
     419             :         pData(rPath.pData)
     420             :     {
     421             :         ++pData->nRef;
     422             :     }
     423             :     const Path &operator=(const Path &rPath)
     424             :     {
     425             :         if(&rPath != this)
     426             :         {
     427             :             if(!--pData->nRef)
     428             :                 delete pData;
     429             :             pData = rPath.pData;
     430             :             pData->nRef++;
     431             :         }
     432             :         return *this;
     433             :     }
     434           0 :     ~Path()
     435             :     {
     436           0 :         if(!--pData->nRef)
     437           0 :             delete pData;
     438           0 :     }
     439           0 :     sal_uInt16 Count() const { return pData->aUS.size(); }
     440           0 :     sal_uInt16 operator[]( sal_uInt16 i ) const
     441             :     {
     442           0 :         return i < Count()? pData->aUS[i]: INDEX_IGNORE;
     443             :     }
     444             : };
     445             : 
     446             : //-------------------------------------------------------------------------
     447             : 
     448           0 : Path::Path(SvTreeListBox *pBox, SvTreeListEntry *pEntry) :
     449           0 :     pData(new ImpPath_Impl)
     450             : {
     451             :     DBG_ASSERT(pEntry != 0, "EntryPtr ist NULL");
     452           0 :     if(!pEntry)
     453           0 :         return;
     454           0 :     SvTreeListEntry *pParent = pBox->GetParent(pEntry);
     455           0 :     do {
     456             :         pData->aUS.insert(pData->aUS.begin(),
     457           0 :                 (sal_uInt16)pBox->GetModel()->GetRelPos(pEntry));
     458           0 :         if(0 == pParent)
     459           0 :             break;
     460           0 :         pEntry = pParent;
     461           0 :         pParent = pBox->GetParent(pEntry);
     462             :     } while(1);
     463             : }
     464             : 
     465             : //-------------------------------------------------------------------------
     466             : 
     467           0 : SvTreeListEntry *GetIndices_Impl(SvTreeListBox *pBox,
     468             :                                SvTreeListEntry *pEntry,
     469             :                                sal_uInt16 &rRegion,
     470             :                                sal_uInt16 &rOffset)
     471             : /*  [Description]
     472             : 
     473             :     Region and position within a range for a template is determined.
     474             : 
     475             :     [Parameter]
     476             : 
     477             :     SvTreeListBox *pBox            Listbox where the event occurred
     478             :     SvTreeListEntry *pEntry     Entry whose position is to be determined
     479             :     sal_uInt16 &rRegion         the region within the region of the
     480             :                             document template (Out-Parameter)
     481             :     sal_uInt16 &rOffset         the position within the region of the
     482             :                             document template (Out-Parameter)
     483             : 
     484             : 
     485             :     [Cross-references]
     486             : 
     487             :     <class Path>    (in certain circumstances this function can also be
     488             :                      dispensed in favor of the Path)
     489             : */
     490             : 
     491             : {
     492           0 :     if(!pEntry)
     493             :     {
     494           0 :         rRegion = rOffset = 0;
     495           0 :         return pEntry;
     496             :     }
     497           0 :     if(0 == pBox->GetModel()->GetDepth(pEntry))
     498             :     {
     499           0 :         rRegion = (sal_uInt16)pBox->GetModel()->GetRelPos(pEntry);
     500           0 :         rOffset = USHRT_MAX;
     501           0 :         return pEntry;
     502             :     }
     503           0 :     SvTreeListEntry *pParent = pBox->GetParent(pEntry);
     504           0 :     rRegion = (sal_uInt16)pBox->GetModel()->GetRelPos(pParent);
     505           0 :     rOffset = (sal_uInt16)pBox->GetModel()->GetRelPos(pEntry);
     506           0 :     return pEntry;
     507             : }
     508             : 
     509             : //-------------------------------------------------------------------------
     510             : 
     511           0 : sal_Bool SfxOrganizeListBox_Impl::Select( SvTreeListEntry* pEntry, sal_Bool bSelect )
     512             : {
     513           0 :     if(!bSelect)
     514           0 :         return SvTreeListBox::Select(pEntry,bSelect);
     515           0 :     sal_uInt16 nLevel = GetDocLevel();
     516           0 :     if(GetModel()->GetDepth(pEntry)+nLevel<3)
     517           0 :         return SvTreeListBox::Select(pEntry,bSelect);
     518             : 
     519           0 :     Path aPath(this, pEntry);
     520             : 
     521             :     // it is ok to use the SfxObjectShellRef here since the object that
     522             :     // provides it ( GetObjectShell() calls CreateObjectShell() ) has a lock on it
     523           0 :     GetObjectShell(aPath)->TriggerHelpPI(
     524           0 :         aPath[nLevel+1], aPath[nLevel+2]);
     525           0 :     return SvTreeListBox::Select(pEntry,bSelect);
     526             : }
     527             : 
     528             : //-------------------------------------------------------------------------
     529             : 
     530           0 : sal_Bool SfxOrganizeListBox_Impl::MoveOrCopyTemplates(SvTreeListBox *pSourceBox,
     531             :                                             SvTreeListEntry *pSource,
     532             :                                             SvTreeListEntry* pTarget,
     533             :                                             SvTreeListEntry *&pNewParent,
     534             :                                             sal_uIntPtr &rIdx,
     535             :                                             sal_Bool bCopy)
     536             : /*  [Description]
     537             : 
     538             :     Move or copy a document templates
     539             : 
     540             :     [Parameter]
     541             : 
     542             :     SvTreeListBox *pSourceBox          Source Listbox, at which the event occurred
     543             :     SvTreeListEntry* pTarget        Target entry, to where it will be moved
     544             :     SvTreeListEntry *pSource        Source entry, to be copied / moved
     545             :     SvTreeListEntry *&pNewParent    the parent of the target position generated
     546             :                                 at entry (out parameter)
     547             :     sal_uIntPtr &rIdx                 Index of the target entry
     548             :     sal_Bool bCopy                  Flag for Copy / Move
     549             : 
     550             : 
     551             :     [Return value]              sal_Bool: Success or failure
     552             : 
     553             :     [Cross-references]
     554             : 
     555             :     <SfxOrganizeListBox_Impl::MoveOrCopyContents(SvTreeListBox *pSourceBox,
     556             :                                             SvTreeListEntry *pSource,
     557             :                                             SvTreeListEntry* pTarget,
     558             :                                             SvTreeListEntry *&pNewParent,
     559             :                                             sal_uIntPtr &rIdx,
     560             :                                             sal_Bool bCopy)>
     561             :     <sal_Bool SfxOrganizeListBox_Impl::NotifyMoving(SvTreeListEntry *pTarget,
     562             :                                             SvTreeListEntry* pSource,
     563             :                                             SvTreeListEntry *&pNewParent,
     564             :                                             sal_uIntPtr &rIdx)>
     565             :     <sal_Bool SfxOrganizeListBox_Impl::NotifyCopying(SvTreeListEntry *pTarget,
     566             :                                             SvTreeListEntry* pSource,
     567             :                                             SvTreeListEntry *&pNewParent,
     568             :                                             sal_uIntPtr &rIdx)>
     569             : */
     570             : 
     571             : {
     572           0 :     sal_Bool bOk = sal_False;
     573             : 
     574           0 :     if(pSource)
     575             :     {
     576           0 :         sal_uInt16 nTargetRegion = 0, nTargetIndex = 0;
     577           0 :         GetIndices_Impl(this, pTarget, nTargetRegion, nTargetIndex);
     578             : 
     579           0 :         sal_uInt16 nSourceRegion = 0, nSourceIndex = 0;
     580           0 :         GetIndices_Impl(pSourceBox, pSource, nSourceRegion, nSourceIndex);
     581             : 
     582             :         bOk =  bCopy ?
     583             :             pMgr->Copy(nTargetRegion, nTargetIndex+1,
     584           0 :                        nSourceRegion, nSourceIndex):
     585             :             pMgr->Move(nTargetRegion, nTargetIndex+1,
     586           0 :                        nSourceRegion, nSourceIndex);
     587             : 
     588           0 :         if(bOk)
     589             :         {
     590           0 :             if(pSourceBox->GetModel()->GetDepth(pSource) == GetModel()->GetDepth(pTarget))
     591             :             {
     592           0 :                 pNewParent = GetParent(pTarget);
     593           0 :                 rIdx = GetModel()->GetRelPos(pTarget)+1;
     594             :             }
     595             :             else
     596             :             {
     597           0 :                 if(nTargetIndex == USHRT_MAX)
     598             :                 {
     599           0 :                     pNewParent = pTarget;
     600           0 :                     rIdx = 0;
     601             :                 }
     602             :                 else
     603             :                     SvTreeListBox::NotifyCopying(
     604           0 :                         pTarget, pSource, pNewParent, rIdx);
     605             :             }
     606             :         }
     607           0 :         else if ( bCopy )
     608             :         {
     609             :             // the template organizer always tries copy after the move, so no error is required for move case
     610           0 :             String aText( SfxResId( bCopy ? STR_ERROR_COPY_TEMPLATE : STR_ERROR_MOVE_TEMPLATE ).toString() );
     611             :             aText.SearchAndReplaceAscii( "$1",
     612           0 :                                          ( (SvTreeListBox *)pSourceBox )->GetEntryText( pSource ) );
     613           0 :             ErrorBox( this, WB_OK, aText ).Execute();
     614             :         }
     615             :     }
     616           0 :     return bOk;
     617             : }
     618             : 
     619             : //-------------------------------------------------------------------------
     620             : 
     621           0 : sal_Bool SfxOrganizeListBox_Impl::MoveOrCopyContents(SvTreeListBox *pSourceBox,
     622             :                                             SvTreeListEntry *pSource,
     623             :                                             SvTreeListEntry* pTarget,
     624             :                                             SvTreeListEntry *&pNewParent,
     625             :                                             sal_uIntPtr &rIdx,
     626             :                                             sal_Bool bCopy)
     627             : /*  [Description]
     628             : 
     629             :     Move or copy document contents
     630             : 
     631             :     [Parameter]
     632             : 
     633             :     SvTreeListBox *pSourceBox          Source Listbox, at which the event occurred
     634             :     SvTreeListEntry* pTarget        Target entry, to where it will be moved
     635             :     SvTreeListEntry *pSource        Source entry, to be copied / moved
     636             :     SvTreeListEntry *&pNewParent    the parent of the target position generated
     637             :                                 at entry (out parameter)
     638             :     sal_uIntPtr &rIdx                 Index of the target entry
     639             :     sal_Bool bCopy                  Flag for Copy / Move
     640             : 
     641             : 
     642             :     [Return value]              sal_Bool: Success or failure
     643             : 
     644             :     [Cross-references]
     645             : 
     646             :     <SfxOrganizeListBox_Impl::MoveOrCopyTemplates(SvTreeListBox *pSourceBox,
     647             :                                             SvTreeListEntry *pSource,
     648             :                                             SvTreeListEntry* pTarget,
     649             :                                             SvTreeListEntry *&pNewParent,
     650             :                                             sal_uIntPtr &rIdx,
     651             :                                             sal_Bool bCopy)>
     652             :     <sal_Bool SfxOrganizeListBox_Impl::NotifyMoving(SvTreeListEntry *pTarget,
     653             :                                             SvTreeListEntry* pSource,
     654             :                                             SvTreeListEntry *&pNewParent,
     655             :                                             sal_uIntPtr &rIdx)>
     656             :     <sal_Bool SfxOrganizeListBox_Impl::NotifyCopying(SvTreeListEntry *pTarget,
     657             :                                             SvTreeListEntry* pSource,
     658             :                                             SvTreeListEntry *&pNewParent,
     659             :                                             sal_uIntPtr &rIdx)>
     660             : */
     661             : 
     662             : {
     663           0 :     SfxErrorContext aEc( ERRCTX_SFX_MOVEORCOPYCONTENTS, this);
     664           0 :     sal_Bool bOk = sal_False, bKeepExpansion = sal_False;
     665           0 :     sal_Bool bRemovedFromSource = sal_False;
     666           0 :     Path aSource(pSourceBox, pSource);
     667           0 :     Path aTarget(this, pTarget);
     668             : 
     669             :     // it is ok to use the SfxObjectShellRef here since the object that
     670             :     // provides it ( GetObjectShell() calls CreateObjectShell() ) has a lock on it
     671           0 :     SfxObjectShellRef aSourceDoc = ((SfxOrganizeListBox_Impl *)pSourceBox)->GetObjectShell(aSource);
     672           0 :     SfxObjectShellRef aTargetDoc = GetObjectShell(aTarget);
     673             : 
     674             :     const sal_uInt16 nSLevel =
     675           0 :         ((SfxOrganizeListBox_Impl *)pSourceBox)->GetDocLevel();
     676           0 :     const sal_uInt16 nTLevel = GetDocLevel();
     677             : 
     678           0 :     if(aSourceDoc.Is() && aTargetDoc.Is())
     679             :     {
     680           0 :         if (aSourceDoc->GetStyleSheetPool())
     681           0 :             aSourceDoc->GetStyleSheetPool()->SetSearchMask(
     682           0 :                 SFX_STYLE_FAMILY_ALL, SFXSTYLEBIT_USERDEF | SFXSTYLEBIT_USED);
     683             : 
     684           0 :         if (aTargetDoc->GetStyleSheetPool())
     685           0 :             aTargetDoc->GetStyleSheetPool()->SetSearchMask(
     686           0 :                 SFX_STYLE_FAMILY_ALL, SFXSTYLEBIT_USERDEF | SFXSTYLEBIT_USED);
     687             :         sal_uInt16 p[3];
     688           0 :         sal_uInt16 nIdxDeleted = INDEX_IGNORE;
     689           0 :         p[0]=aTarget[nTLevel+1];
     690           0 :         p[1]=aTarget[nTLevel+2];
     691           0 :         if(p[1]!=INDEX_IGNORE)p[1]++;
     692           0 :         p[2]=aTarget[nTLevel+3];
     693             : 
     694           0 :         bOk = aTargetDoc->Insert(
     695           0 :             *aSourceDoc, aSource[nSLevel+1],
     696           0 :             aSource[nSLevel+2], aSource[nSLevel+3],
     697           0 :             p[0], p[1], p[2],  nIdxDeleted);
     698             :         // Evaluate Position correction
     699             :         // a = Document content
     700             :         // b = Position Sub-content 1
     701             :         // c = Position Sub-content 2
     702             :         // Delete duplicate entries
     703           0 :         if(bOk)
     704             :         {
     705           0 :             SvTreeListEntry *pParentIter = pTarget;
     706             :             // Up to the document level as
     707             :             // the general reference point
     708           0 :             while(GetModel()->GetDepth(pParentIter) != nTLevel)
     709           0 :                 pParentIter = GetParent(pParentIter);
     710           0 :             if(pParentIter->HasChildrenOnDemand() &&
     711           0 :                 !GetModel()->HasChildren(pParentIter))
     712           0 :                 RequestingChildren(pParentIter);
     713           0 :             SvTreeListEntry *pChildIter = 0;
     714             : 
     715           0 :             sal_uInt16 i = 0;
     716           0 :             while(i < 2 && p[i+1] != INDEX_IGNORE)
     717             :             {
     718           0 :                 pChildIter = FirstChild(pParentIter);
     719             :                 // To the index of the current level
     720           0 :                 for(sal_uInt16 j = 0; j < p[i]; ++j)
     721           0 :                     pChildIter = NextSibling(pChildIter);
     722             :                 // If possible, fill in Items onDemand
     723           0 :                 ++i;
     724           0 :                 if(i < 2 && p[i+1] != INDEX_IGNORE &&
     725           0 :                    pChildIter->HasChildrenOnDemand() &&
     726           0 :                    !GetModel()->HasChildren(pChildIter))
     727           0 :                     RequestingChildren(pChildIter);
     728           0 :                 pParentIter = pChildIter;
     729             :             }
     730           0 :             rIdx = p[i];
     731           0 :             pNewParent = pParentIter;
     732           0 :             if(!IsExpanded(pNewParent) &&
     733           0 :                pNewParent->HasChildrenOnDemand() &&
     734           0 :                !GetModel()->HasChildren(pNewParent))
     735             :             {
     736           0 :                 bOk = sal_False;
     737           0 :                 if(!bCopy)
     738           0 :                     pSourceBox->GetModel()->Remove(pSource);
     739             :             }
     740             :             // Remove deleted items
     741             :             // (can be done by overwriting)
     742           0 :             if(nIdxDeleted != INDEX_IGNORE)
     743             :             {
     744           0 :                 pChildIter = FirstChild(pParentIter);
     745           0 :                 for(sal_uInt16 j = 0; j < nIdxDeleted; ++j)
     746           0 :                     pChildIter = NextSibling(pChildIter);
     747           0 :                 if( pChildIter && pChildIter != pSource )
     748             :                 {
     749           0 :                     bKeepExpansion = IsExpanded(pParentIter);
     750           0 :                     GetModel()->Remove(pChildIter);
     751             :                 }
     752             :                 else
     753           0 :                     bOk = sal_False;
     754             :             }
     755           0 :             if(!bCopy && &aSourceDoc != &aTargetDoc)
     756             :             {
     757             :                 //pool styles that are moved produce
     758             :                 //an rIdx == INDEX_IGNORE
     759             :                 //the method has to return true to keep the box content consistent
     760           0 :                 bRemovedFromSource = aSourceDoc->Remove(aSource[nSLevel+1],
     761           0 :                                      aSource[nSLevel+2],
     762           0 :                                      aSource[nSLevel+3]);
     763             :             }
     764             :         }
     765             :     }
     766             :     return (((rIdx != INDEX_IGNORE)|| bRemovedFromSource) && bOk )
     767           0 :         ? bKeepExpansion? (sal_Bool)2: sal_True: sal_False;
     768             : }
     769             : 
     770             : //-------------------------------------------------------------------------
     771             : 
     772           0 : sal_Bool SfxOrganizeListBox_Impl::NotifyMoving(SvTreeListEntry *pTarget,
     773             :                                         SvTreeListEntry* pSource,
     774             :                                         SvTreeListEntry *&pNewParent,
     775             :                                         sal_uIntPtr &rIdx)
     776             : 
     777             : /*  [Description]
     778             : 
     779             :     Notification that an item will be moved.
     780             :     (SV-Handler)
     781             : 
     782             :     [Parameter]
     783             : 
     784             :     SvTreeListEntry* pTarget        Target entry, to where it will be moved
     785             :     SvTreeListEntry *pSource        Source entry, to be moved
     786             :     SvTreeListEntry *&pNewParent    the parent of the target position generated
     787             :                                 at entry (out parameter)
     788             :     sal_uIntPtr &rIdx                 Index of the target entry
     789             : 
     790             : 
     791             :     [Return value]              sal_Bool: Sucess or failure
     792             : 
     793             :     [Cross-references]
     794             : 
     795             :     <SfxOrganizeListBox_Impl::MoveOrCopyTemplates(SvTreeListBox *pSourceBox,
     796             :                                             SvTreeListEntry *pSource,
     797             :                                             SvTreeListEntry* pTarget,
     798             :                                             SvTreeListEntry *&pNewParent,
     799             :                                             sal_uIntPtr &rIdx,
     800             :                                             sal_Bool bCopy)>
     801             :     <SfxOrganizeListBox_Impl::MoveOrCopyContents(SvTreeListBox *pSourceBox,
     802             :                                             SvTreeListEntry *pSource,
     803             :                                             SvTreeListEntry* pTarget,
     804             :                                             SvTreeListEntry *&pNewParent,
     805             :                                             sal_uIntPtr &rIdx,
     806             :                                             sal_Bool bCopy)>
     807             :     <sal_Bool SfxOrganizeListBox_Impl::NotifyCopying(SvTreeListEntry *pTarget,
     808             :                                             SvTreeListEntry* pSource,
     809             :                                             SvTreeListEntry *&pNewParent,
     810             :                                             sal_uIntPtr &rIdx)>
     811             : */
     812             : 
     813             : {
     814           0 :     sal_Bool bOk =  sal_False;
     815           0 :     SvTreeListBox* pSourceBox = GetSourceView();
     816           0 :     if ( !pSourceBox )
     817           0 :         pSourceBox = pDlg->pSourceView;
     818             :     DBG_ASSERT( pSourceBox, "no source view" );
     819           0 :     if ( !pTarget )
     820           0 :         pTarget = pDlg->pTargetEntry;
     821             : 
     822           0 :     if ( pSourceBox->GetModel()->GetDepth( pSource ) <= GetDocLevel() &&
     823           0 :                       GetModel()->GetDepth( pTarget ) <= GetDocLevel() )
     824           0 :         bOk = MoveOrCopyTemplates( pSourceBox, pSource, pTarget, pNewParent, rIdx, sal_False );
     825             :     else
     826           0 :         bOk = MoveOrCopyContents(pSourceBox, pSource, pTarget, pNewParent, rIdx, sal_False );
     827             : 
     828           0 :     return bOk;
     829             : }
     830             : 
     831             : //-------------------------------------------------------------------------
     832             : 
     833           0 : sal_Bool SfxOrganizeListBox_Impl::NotifyCopying(SvTreeListEntry *pTarget,
     834             :                                         SvTreeListEntry* pSource,
     835             :                                         SvTreeListEntry *&pNewParent,
     836             :                                         sal_uIntPtr &rIdx)
     837             : /*  [Description]
     838             : 
     839             :     Notification that an item will be moved.
     840             :     (SV-Handler)
     841             : 
     842             :     [Parameter]
     843             : 
     844             :     SvTreeListEntry* pTarget        Target entry, to where it will be copied
     845             :     SvTreeListEntry *pSource        Source entry, to be copied
     846             :     SvTreeListEntry *&pNewParent    the parent of the target position generated
     847             :                                 at entry (out parameter)
     848             :     sal_uIntPtr &rIdx                 Index of the target entry
     849             : 
     850             :     [Return value]              sal_Bool: Sucess or failure
     851             : 
     852             :     [Cross-references]
     853             : 
     854             :     <SfxOrganizeListBox_Impl::MoveOrCopyTemplates(SvTreeListBox *pSourceBox,
     855             :                                             SvTreeListEntry *pSource,
     856             :                                             SvTreeListEntry* pTarget,
     857             :                                             SvTreeListEntry *&pNewParent,
     858             :                                             sal_uIntPtr &rIdx,
     859             :                                             sal_Bool bCopy)>
     860             :     <SfxOrganizeListBox_Impl::MoveOrCopyContents(SvTreeListBox *pSourceBox,
     861             :                                             SvTreeListEntry *pSource,
     862             :                                             SvTreeListEntry* pTarget,
     863             :                                             SvTreeListEntry *&pNewParent,
     864             :                                             sal_uIntPtr &rIdx,
     865             :                                             sal_Bool bCopy)>
     866             :     <sal_Bool SfxOrganizeListBox_Impl::NotifyMoving(SvTreeListEntry *pTarget,
     867             :                                             SvTreeListEntry* pSource,
     868             :                                             SvTreeListEntry *&pNewParent,
     869             :                                             sal_uIntPtr &rIdx)>
     870             : */
     871             : {
     872           0 :     sal_Bool bOk =  sal_False;
     873           0 :     SvTreeListBox* pSourceBox = GetSourceView();
     874           0 :     if ( !pSourceBox )
     875           0 :         pSourceBox = pDlg->pSourceView;
     876             :     DBG_ASSERT( pSourceBox, "no source view" );
     877           0 :     if ( !pTarget )
     878           0 :         pTarget = pDlg->pTargetEntry;
     879           0 :     if ( pSourceBox->GetModel()->GetDepth( pSource ) <= GetDocLevel() &&
     880           0 :                      GetModel()->GetDepth( pTarget ) <= GetDocLevel() )
     881           0 :         bOk = MoveOrCopyTemplates( pSourceBox, pSource, pTarget, pNewParent, rIdx, sal_True );
     882             :     else
     883           0 :         bOk = MoveOrCopyContents( pSourceBox, pSource, pTarget, pNewParent, rIdx, sal_True );
     884             : 
     885           0 :     return bOk;
     886             : }
     887             : 
     888             : //-------------------------------------------------------------------------
     889             : 
     890           0 : sal_Bool SfxOrganizeListBox_Impl::EditingEntry( SvTreeListEntry* pEntry, Selection&  )
     891             : 
     892             : /*  [Description]
     893             : 
     894             :     Check whether an item can be edited
     895             :     (SV-Handler)
     896             : 
     897             :     [Cross-references]
     898             :     <SfxOrganizeListBox_Impl::EditedEntry(SvTreeListEntry* pEntry, const rtl::OUString& rText)>
     899             : */
     900             : 
     901             : {
     902           0 :     if( VIEW_TEMPLATES == eViewType &&
     903           0 :         GetModel()->GetDepth(pEntry) < 2 )
     904             :     {
     905           0 :         pDlg->pSuspend = new SuspendAccel( &pDlg->aEditAcc );
     906           0 :         return sal_True;
     907             :     }
     908           0 :     return sal_False;
     909             : }
     910             : 
     911             : //-------------------------------------------------------------------------
     912             : 
     913           0 : sal_Bool SfxOrganizeListBox_Impl::EditedEntry(SvTreeListEntry* pEntry, const rtl::OUString& rText)
     914             : 
     915             : /*  [Description]
     916             : 
     917             :     The name of an entry has been processed, if the name you entered is a
     918             :     valid name (length> 0) then the model is updated.
     919             :     (SV-Handler)
     920             : 
     921             :     [Return value]
     922             : 
     923             :     sal_Bool            sal_True:  The name in the display should be changed
     924             :                         sal_False: The name should not be changed
     925             : 
     926             :     [Cross-references]
     927             :     <SfxOrganizeListBox_Impl::EditingEntry(SvTreeListEntry* pEntry, const String& rText)>
     928             : */
     929             : 
     930             : {
     931             :     DBG_ASSERT(pEntry, "No Entry selected");
     932           0 :     delete pDlg->pSuspend;
     933           0 :     pDlg->pSuspend = NULL;
     934           0 :     SvTreeListEntry* pParent = GetParent(pEntry);
     935           0 :     if( rText.isEmpty() )
     936             :     {
     937           0 :         ErrorBox aBox( this, SfxResId( MSG_ERROR_EMPTY_NAME ) );
     938           0 :         aBox.GrabFocus();
     939           0 :         aBox.Execute();
     940           0 :         return sal_False;
     941             :     }
     942           0 :     if ( !IsUniqName_Impl( rText, pParent, pEntry ) )
     943             :     {
     944           0 :         ErrorBox aBox( this, SfxResId( MSG_ERROR_UNIQ_NAME ) );
     945           0 :         aBox.GrabFocus();
     946           0 :         aBox.Execute();
     947           0 :         return sal_False;
     948             :     }
     949           0 :     sal_uInt16 nRegion = 0, nIndex = 0;
     950           0 :     GetIndices_Impl( this, pEntry, nRegion, nIndex );
     951           0 :     String aOldName;
     952           0 :     if ( USHRT_MAX != nIndex )
     953           0 :         aOldName = pMgr->GetTemplates()->GetName( nRegion, nIndex );
     954             :     else
     955           0 :         aOldName = pMgr->GetTemplates()->GetRegionName( nRegion );
     956             : 
     957           0 :     if ( !pMgr->SetName( rText, nRegion, nIndex ) )
     958             :     {
     959             :         SfxResId aResId( USHRT_MAX != nIndex ? MSG_ERROR_RENAME_TEMPLATE
     960           0 :                                              : MSG_ERROR_RENAME_TEMPLATE_REGION );
     961           0 :         ErrorBox( this, aResId ).Execute();
     962           0 :         return sal_False;
     963             :     }
     964             : 
     965           0 :     return sal_True;
     966             : }
     967             : 
     968             : //-------------------------------------------------------------------------
     969             : 
     970           0 : DragDropMode SfxOrganizeListBox_Impl::NotifyStartDrag( TransferDataContainer&, SvTreeListEntry* pEntry )
     971             : {
     972           0 :     sal_uInt16 nSourceLevel = GetModel()->GetDepth( pEntry );
     973           0 :     if ( VIEW_FILES == GetViewType() )
     974           0 :         ++nSourceLevel;
     975           0 :     if ( nSourceLevel >= 2 )
     976           0 :         bDropMoveOk = sal_False;
     977             :     else
     978           0 :         bDropMoveOk = sal_True;
     979             : 
     980           0 :     return GetDragDropMode();
     981             : }
     982             : 
     983             : //-------------------------------------------------------------------------
     984             : 
     985           0 : sal_Bool SfxOrganizeListBox_Impl::NotifyAcceptDrop( SvTreeListEntry* pEntry )
     986             : {
     987           0 :     if(!pEntry)
     988           0 :         return sal_False;
     989           0 :     SvTreeListBox *pSource = GetSourceView();
     990           0 :     SvTreeListEntry *pSourceEntry = pSource->FirstSelected();
     991           0 :     if(pEntry == pSourceEntry)
     992           0 :         return sal_False;
     993           0 :     sal_uInt16 nSourceLevel = pSource->GetModel()->GetDepth(pSourceEntry);
     994           0 :     if(VIEW_FILES == ((SfxOrganizeListBox_Impl *)pSource)->GetViewType())
     995           0 :         ++nSourceLevel;
     996           0 :     sal_uInt16 nTargetLevel = GetModel()->GetDepth(pEntry);
     997           0 :     if(VIEW_FILES == GetViewType())
     998           0 :         ++nTargetLevel;
     999           0 :     Path aSource(pSource, pSourceEntry);
    1000           0 :     Path aTarget(this, pEntry);
    1001           0 :     const sal_uInt16 SL = ((SfxOrganizeListBox_Impl *)pSource)->GetDocLevel();
    1002           0 :     const sal_uInt16 TL = GetDocLevel();
    1003             : 
    1004             :     return( (nSourceLevel == 1 && nTargetLevel == 0 &&
    1005             :             VIEW_TEMPLATES ==
    1006           0 :             ((SfxOrganizeListBox_Impl *)pSource)->GetViewType()) ||
    1007             :            (nSourceLevel == 1 && nTargetLevel == 1 &&
    1008             :             VIEW_TEMPLATES ==
    1009           0 :             ((SfxOrganizeListBox_Impl *)pSource)->GetViewType() &&
    1010           0 :             VIEW_TEMPLATES == GetViewType()) ||
    1011             :            (nSourceLevel == 3 && nTargetLevel == 1) ||
    1012             :            (nSourceLevel == 3 && nTargetLevel == 2 &&
    1013           0 :             aSource[1+SL] == aTarget[1+TL]) ||
    1014             :            (nSourceLevel == 3 && nTargetLevel == 3 &&
    1015           0 :             aSource[1+SL] == aTarget[1+TL]) ||
    1016             :            (nSourceLevel == 4 && nTargetLevel == 3 &&
    1017           0 :             aSource[1+SL] == aTarget[1+TL] &&
    1018           0 :             aSource[2+SL] == aTarget[2+TL]) ||
    1019             :            (nSourceLevel == 4 && nTargetLevel == 4 &&
    1020           0 :             aSource[1+SL] == aTarget[1+TL] &&
    1021           0 :             aSource[2+SL] == aTarget[2+TL]));
    1022             : }
    1023             : 
    1024             : //-------------------------------------------------------------------------
    1025             : 
    1026           0 : sal_Int8 SfxOrganizeListBox_Impl::AcceptDrop( const AcceptDropEvent& rEvt )
    1027             : {
    1028           0 :     sal_Bool bAccept = ( eViewType == VIEW_FILES && IsDropFormatSupported( SOT_FORMAT_FILE ) );
    1029           0 :     if ( bAccept )
    1030           0 :         return rEvt.mnAction;
    1031             :     else
    1032           0 :         return SvTreeListBox::AcceptDrop( rEvt );
    1033             : }
    1034             : 
    1035             : //-------------------------------------------------------------------------
    1036             : 
    1037           0 : sal_Int8 SfxOrganizeListBox_Impl::ExecuteDrop( const ExecuteDropEvent& rEvt )
    1038             : {
    1039           0 :     TransferableDataHelper aHelper( rEvt.maDropEvent.Transferable );
    1040           0 :     sal_uInt32 nFormatCount = aHelper.GetFormatCount();
    1041           0 :     sal_Bool bSuccess = sal_False;
    1042           0 :     for ( sal_uInt32 i = 0; i < nFormatCount; ++i )
    1043             :     {
    1044           0 :         String aFileName;
    1045           0 :         SotFormatStringId nId = aHelper.GetFormat(i);
    1046             : 
    1047           0 :         if ( SOT_FORMAT_FILE == nId && aHelper.GetString( nId, aFileName ) )
    1048             :         {
    1049           0 :             INetURLObject aObj( aFileName, INET_PROT_FILE );
    1050           0 :             bSuccess |= pMgr->InsertFile( this, aObj.GetMainURL(INetURLObject::DECODE_TO_IURI) );
    1051             :         }
    1052           0 :     }
    1053           0 :     bDropMoveOk = sal_True;
    1054           0 :     sal_Int8 nRet = rEvt.mnAction;
    1055           0 :     if ( !bSuccess )
    1056             :     {
    1057             :         // asynchronous, because of MessBoxes
    1058           0 :         pDlg->pSourceView = GetSourceView();
    1059           0 :         pDlg->pTargetEntry = pTargetEntry;
    1060           0 :         pDlg->pFinishedBox = NULL;
    1061           0 :         pDlg->nDropAction = NO_DROP_ACTION;
    1062             :         PostUserEvent( LINK( this, SfxOrganizeListBox_Impl, OnAsyncExecuteDrop ),
    1063           0 :                        new ExecuteDropEvent( rEvt ) );
    1064             :     }
    1065             : 
    1066           0 :     return nRet;
    1067             : }
    1068             : 
    1069             : //-------------------------------------------------------------------------
    1070             : 
    1071           0 : void SfxOrganizeListBox_Impl::DragFinished( sal_Int8 nDropAction )
    1072             : {
    1073           0 :     if ( pDlg->bExecDropFinished )
    1074             :     {
    1075           0 :         if ( pDlg->nDropAction != NO_DROP_ACTION )
    1076           0 :             nDropAction = pDlg->nDropAction;
    1077           0 :         SvTreeListBox::DragFinished( nDropAction );
    1078           0 :         pDlg->nDropAction = NO_DROP_ACTION;
    1079             :     }
    1080             :     else
    1081           0 :         pDlg->pFinishedBox = this;
    1082           0 : }
    1083             : 
    1084             : //-------------------------------------------------------------------------
    1085             : 
    1086           0 : inline sal_uInt16 SfxOrganizeListBox_Impl::GetDocLevel() const
    1087             : 
    1088             : /*  [Description]
    1089             : 
    1090             :     Determines on which level there are documents (in the template view or
    1091             :     the document view)
    1092             : 
    1093             :     [Return value]
    1094             : 
    1095             :     sal_uInt16             Document level
    1096             : 
    1097             : */
    1098             : 
    1099             : {
    1100           0 :     return eViewType == VIEW_FILES? 0: 1;
    1101             : }
    1102             : 
    1103             : //-------------------------------------------------------------------------
    1104             : 
    1105           0 : SfxObjectShellRef SfxOrganizeListBox_Impl::GetObjectShell(const Path &rPath)
    1106             : 
    1107             : /*  [Description]
    1108             : 
    1109             :     Access to the ObjectShell to which the current entry is connected.
    1110             : 
    1111             :     [Parameter]
    1112             : 
    1113             :     const Path &rPath       Description of the current entry
    1114             : 
    1115             :     [Return value]
    1116             : 
    1117             :     SfxObjectShellRef       Reference to the ObjectShell
    1118             : 
    1119             :     [Cross-references]
    1120             : 
    1121             :     <class Path>
    1122             : 
    1123             : */
    1124             : 
    1125             : {
    1126           0 :     SfxObjectShellRef aDoc;
    1127           0 :     if(eViewType == VIEW_FILES)
    1128           0 :         aDoc = pMgr->CreateObjectShell(rPath[0]);
    1129             :     else
    1130           0 :         aDoc = pMgr->CreateObjectShell(rPath[0], rPath[1]);
    1131           0 :     return aDoc;
    1132             : }
    1133             : 
    1134             : //-------------------------------------------------------------------------
    1135             : 
    1136           0 : void SfxOrganizeListBox_Impl::RequestingChildren( SvTreeListEntry* pEntry )
    1137             : 
    1138             : /*  [Description]
    1139             : 
    1140             :     Sent to the children of an entry that is going to be inserted.
    1141             :     (SV-Handler)
    1142             : 
    1143             :     [Parameter]
    1144             : 
    1145             :     SvTreeListEntry* pEntry     the entry whose children is requested
    1146             : */
    1147             : 
    1148             : {
    1149           0 :     if ( !GetModel()->HasChildren( pEntry ) )
    1150             :     {
    1151           0 :         WaitObject aWaitCursor( this );
    1152             : 
    1153             :         // Choose the correct mask color dependent from eColorMode. This
    1154             :         // must be adopted if we change the mask color for normal images, too!
    1155           0 :         Color aMaskColor( COL_LIGHTMAGENTA );
    1156             : 
    1157             :         // Here are all the initial inserted
    1158           0 :         SfxErrorContext aEc(ERRCTX_SFX_CREATEOBJSH, pDlg->pDialog);
    1159           0 :         if(VIEW_TEMPLATES == GetViewType() && 0 == GetModel()->GetDepth(pEntry))
    1160             :         {
    1161           0 :             sal_uInt16 i = (sal_uInt16)GetModel()->GetRelPos(pEntry);
    1162           0 :             const sal_uInt16 nEntryCount = pMgr->GetTemplates()->GetCount(i);
    1163           0 :             for(sal_uInt16 j = 0; j < nEntryCount; ++j)
    1164           0 :                 InsertEntryByBmpType( pMgr->GetTemplates()->GetName( i, j ), BMPTYPE_DOC, pEntry, sal_True );
    1165             :         }
    1166             :         else
    1167             :         {
    1168           0 :             const sal_uInt16 nDocLevel = GetDocLevel();
    1169           0 :             Path aPath(this, pEntry);
    1170             : 
    1171             :             // it is ok to use the SfxObjectShellRef here since the object that
    1172             :             // provides it ( GetObjectShell() calls CreateObjectShell() ) has a lock on it
    1173           0 :             SfxObjectShellRef aRef = GetObjectShell(aPath);
    1174           0 :             if(aRef.Is())
    1175             :             {
    1176           0 :                 const sal_uInt16 nCount = aRef->GetContentCount(aPath[nDocLevel+1]);
    1177           0 :                 String aText;
    1178           0 :                 Bitmap aClosedBmp, aOpenedBmp;
    1179             :                 const bool bCanHaveChildren =
    1180           0 :                     aRef->CanHaveChildren(aPath[nDocLevel+1],
    1181           0 :                                         aPath[nDocLevel+2]);
    1182           0 :                 for(sal_uInt16 i = 0; i < nCount; ++i)
    1183             :                 {
    1184             :                     sal_Bool bDeletable;
    1185           0 :                     aRef->GetContent(
    1186             :                         aText, aClosedBmp, aOpenedBmp, bDeletable,
    1187           0 :                         i, aPath[nDocLevel+1]);
    1188             : 
    1189             :                     // Create image with the correct mask color
    1190           0 :                     Image aClosedImage( aClosedBmp, aMaskColor );
    1191           0 :                     Image aOpenedImage( aOpenedBmp, aMaskColor );
    1192             : 
    1193             :                     SvTreeListEntry *pNew = SvTreeListBox::InsertEntry(
    1194             :                         aText, aOpenedImage, aClosedImage,
    1195           0 :                         pEntry, bCanHaveChildren);
    1196           0 :                     pNew->SetUserData(bDeletable ? &bDeletable : 0);
    1197           0 :                 }
    1198           0 :             }
    1199           0 :         }
    1200             :     }
    1201           0 : }
    1202             : 
    1203             : //-------------------------------------------------------------------------
    1204             : 
    1205           0 : long SfxOrganizeListBox_Impl::ExpandingHdl()
    1206             : 
    1207             : /*  [Description]
    1208             : 
    1209             :     SV-handler, before and after the unfolding of an entry is called.
    1210             :     Used if possibly to close the ObjectShell again, the entries with the
    1211             :     contents of this shell are also removed.
    1212             : */
    1213             : 
    1214             : {
    1215           0 :     if ( !(nImpFlags & SVLBOX_IS_EXPANDING) )
    1216             :     {
    1217           0 :         SvTreeListEntry* pEntry  = GetHdlEntry();
    1218           0 :         const sal_uInt16 nLevel = GetModel()->GetDepth(pEntry);
    1219           0 :         if((eViewType == VIEW_FILES && nLevel == 0) ||
    1220             :            (eViewType == VIEW_TEMPLATES && nLevel == 1))
    1221             :         {
    1222           0 :             Path aPath(this, pEntry);
    1223             :             // Release ObjectShell when closing the files
    1224           0 :             if(eViewType == VIEW_FILES && nLevel == 0)
    1225           0 :                 pMgr->DeleteObjectShell(aPath[0]);
    1226             :             else
    1227           0 :                 pMgr->DeleteObjectShell(aPath[0], aPath[1]);
    1228             :             // Delete all SubEntries
    1229           0 :             SvTreeListEntry *pToDel = SvTreeListBox::GetEntry(pEntry, 0);
    1230           0 :             while(pToDel)
    1231             :             {
    1232           0 :                 GetModel()->Remove(pToDel);
    1233           0 :                 pToDel = SvTreeListBox::GetEntry(pEntry, 0);
    1234           0 :             }
    1235             :         }
    1236             :     }
    1237           0 :     return sal_True;
    1238             : }
    1239             : 
    1240             : //-------------------------------------------------------------------------
    1241             : 
    1242           0 : sal_Bool SfxOrganizeListBox_Impl::IsUniqName_Impl(const String &rText,
    1243             :                                          SvTreeListEntry* pParent, SvTreeListEntry *pEntry) const
    1244             : 
    1245             : /*  [Description]
    1246             : 
    1247             :     Checks whether a name is unique at its level.
    1248             : 
    1249             :     [Parameter]
    1250             : 
    1251             :     const String &         Name of the search entry
    1252             :     SvTreeListEntry* pSibling  Siblings (referred to the level)
    1253             : 
    1254             :     [Return value]
    1255             : 
    1256             :     sal_Bool                     sal_True, if the name is unique, otherwise sal_False
    1257             : */
    1258             : 
    1259             : {
    1260           0 :     SvTreeListEntry* pChild = FirstChild(pParent);
    1261           0 :     while(pChild)  {
    1262           0 :         const String aEntryText(GetEntryText(pChild));
    1263           0 :         if(COMPARE_EQUAL == aEntryText.CompareIgnoreCaseToAscii(rText)&&(!pEntry || pEntry!=pChild))
    1264           0 :             return sal_False;
    1265           0 :         pChild = NextSibling(pChild);
    1266           0 :     }
    1267           0 :     return sal_True;
    1268             : }
    1269             : 
    1270             : //-------------------------------------------------------------------------
    1271             : 
    1272           0 : sal_uInt16 SfxOrganizeListBox_Impl::GetLevelCount_Impl(SvTreeListEntry* pParent) const
    1273             : {
    1274           0 :     SvTreeListEntry* pChild = FirstChild(pParent);
    1275           0 :     sal_uInt16 nCount = 0;
    1276           0 :     while(pChild)  {
    1277           0 :         pChild = NextSibling(pChild);
    1278           0 :         ++nCount;
    1279             :     }
    1280           0 :     return nCount;
    1281             : }
    1282             : 
    1283             : //-------------------------------------------------------------------------
    1284             : 
    1285           0 : SvTreeListEntry* SfxOrganizeListBox_Impl::InsertEntryByBmpType(
    1286             :     const OUString& rText,
    1287             :     BMPTYPE eBmpType,
    1288             :     SvTreeListEntry* pParent,
    1289             :     sal_Bool bChildrenOnDemand,
    1290             :     sal_uIntPtr nPos,
    1291             :     void* pUserData
    1292             : )
    1293             : {
    1294           0 :     SvTreeListEntry*    pEntry = NULL;
    1295           0 :     const Image*    pExp = NULL;
    1296           0 :     const Image*    pCol = NULL;
    1297             : 
    1298           0 :     switch( eBmpType )
    1299             :     {
    1300             :         case BMPTYPE_FOLDER:
    1301           0 :             pExp = &aOpenedFolderBmp;
    1302           0 :             pCol = &aClosedFolderBmp;
    1303           0 :             break;
    1304             : 
    1305             :         case BMPTYPE_DOC:
    1306           0 :             pExp = &aOpenedDocBmp;
    1307           0 :             pCol = &aClosedDocBmp;
    1308           0 :             break;
    1309             : 
    1310             :         default:
    1311             :             OSL_FAIL( "SfxOrganizeListBox_Impl::InsertEntryByBmpType(): something forgotten?!" );
    1312             :     }
    1313             : 
    1314           0 :     pEntry = SvTreeListBox::InsertEntry( rText, *pExp, *pCol, pParent, bChildrenOnDemand, nPos, pUserData );
    1315             : 
    1316           0 :     return pEntry;
    1317             : }
    1318             : 
    1319           0 : SfxOrganizeListBox_Impl::SfxOrganizeListBox_Impl(Window* pParent, WinBits nBits)
    1320             :     : SvTreeListBox( pParent, nBits )
    1321             :     , pMgr( NULL )
    1322             :     , pDlg( NULL )
    1323           0 :     , eViewType( SfxOrganizeListBox_Impl::VIEW_TEMPLATES )
    1324             : {
    1325             :     SetDragDropMode(
    1326             :         SV_DRAGDROP_CTRL_MOVE | SV_DRAGDROP_CTRL_COPY |
    1327           0 :         SV_DRAGDROP_APP_MOVE  | SV_DRAGDROP_APP_COPY  | SV_DRAGDROP_APP_DROP );
    1328           0 :     SetEntryHeight( 16 );
    1329           0 :     SetSelectionMode( SINGLE_SELECTION );
    1330           0 :     GetModel()->SetSortMode( SortNone );
    1331             : 
    1332           0 :     EnableContextMenuHandling();
    1333           0 : }
    1334             : 
    1335           0 : void SfxOrganizeListBox_Impl::Init(SfxOrganizeDlg_Impl* pArgDlg, DataEnum eType)
    1336             : {
    1337           0 :     pDlg = pArgDlg;
    1338           0 :     eViewType = eType;
    1339           0 : }
    1340             : 
    1341             : //-------------------------------------------------------------------------
    1342             : 
    1343           0 : IMPL_LINK( SfxOrganizeListBox_Impl, OnAsyncExecuteDrop, ExecuteDropEvent*, pEvent )
    1344             : {
    1345             :     DBG_ASSERT( pEvent, "invalid DropEvent" );
    1346           0 :     if ( pEvent )
    1347             :     {
    1348           0 :         SvTreeListBox* pSourceView = GetSourceView();
    1349           0 :         if ( !pSourceView )
    1350           0 :             pSourceView = pDlg->pSourceView;
    1351           0 :         pDlg->bExecDropFinished = false;
    1352             :         // if a template can not be moved it should be copied
    1353           0 :         if ( pEvent->mnAction == DND_ACTION_MOVE )
    1354           0 :             pEvent->mnAction = DND_ACTION_COPYMOVE;
    1355           0 :         pDlg->nDropAction = SvTreeListBox::ExecuteDrop( *pEvent, pSourceView );
    1356           0 :         delete pEvent;
    1357           0 :         pDlg->pSourceView = NULL;
    1358           0 :         pDlg->pTargetEntry = NULL;
    1359           0 :         pDlg->bExecDropFinished = true;
    1360           0 :         if ( pDlg->pFinishedBox )
    1361             :         {
    1362           0 :             pDlg->pFinishedBox->DragFinished( pDlg->nDropAction );
    1363           0 :             pDlg->pFinishedBox = NULL;
    1364             :         }
    1365             :     }
    1366           0 :     return 0;
    1367             : }
    1368             : 
    1369             : //-------------------------------------------------------------------------
    1370             : 
    1371           0 : void SfxOrganizeListBox_Impl::Reset()
    1372             : 
    1373             : /*  [Description]
    1374             : 
    1375             :     Paste the items in the ListBox
    1376             : */
    1377             : 
    1378             : {
    1379             :     DBG_ASSERT( pMgr != 0, "No Manager" );
    1380             :     // Delete contents
    1381           0 :     SetUpdateMode(sal_False);
    1382           0 :     Clear();
    1383           0 :     if ( VIEW_TEMPLATES == eViewType )
    1384             :     {
    1385           0 :         const sal_uInt16 nCount = pMgr->GetTemplates()->GetRegionCount();
    1386           0 :         for ( sal_uInt16 i = 0; i < nCount; ++i )
    1387           0 :             InsertEntryByBmpType( pMgr->GetTemplates()->GetFullRegionName(i), BMPTYPE_FOLDER, 0, sal_True );
    1388             :     }
    1389             :     else
    1390             :     {
    1391           0 :         const SfxObjectList& rList = pMgr->GetObjectList();
    1392           0 :         for ( SfxObjectList::const_iterator it = rList.begin(); it != rList.end(); ++it )
    1393           0 :             InsertEntryByBmpType( rList.GetBaseName(*it), BMPTYPE_DOC, 0, sal_True );
    1394             : 
    1395             :     }
    1396           0 :     SetUpdateMode(sal_True);
    1397           0 :     Invalidate();
    1398           0 :     Update();
    1399           0 : }
    1400             : 
    1401             : //-------------------------------------------------------------------------
    1402             : 
    1403           0 : const Image &SfxOrganizeListBox_Impl::GetClosedBmp(sal_uInt16 nLevel) const
    1404             : 
    1405             : /*  [Description]
    1406             : 
    1407             :     Access to the bitmap for a closed entry at each level
    1408             : 
    1409             :     [Parameter]
    1410             : 
    1411             :     sal_uInt16 nLevel       Indicator of the level, 2 levels are allowed
    1412             : 
    1413             :     [Return value]
    1414             : 
    1415             :     const Image &       The Image on level nLevel
    1416             : */
    1417             : 
    1418             : {
    1419           0 :     const Image*    pRet = NULL;
    1420             : 
    1421           0 :     switch( nLevel )
    1422             :     {
    1423             :         default:    OSL_FAIL( "Bitmap index overflow" );
    1424             : 
    1425           0 :         case 0:     pRet = &aClosedFolderBmp;
    1426           0 :             break;
    1427           0 :         case 1:     pRet = &aClosedDocBmp;
    1428           0 :             break;
    1429             :     }
    1430             : 
    1431           0 :     return *pRet;
    1432             : }
    1433             : 
    1434             : //-------------------------------------------------------------------------
    1435             : 
    1436           0 : const Image &SfxOrganizeListBox_Impl::GetOpenedBmp(sal_uInt16 nLevel) const
    1437             : 
    1438             : /*  [Description]
    1439             : 
    1440             :     Access to the bitmap for an open entry at each level
    1441             : 
    1442             :     [Parameter]
    1443             : 
    1444             :     sal_uInt16 nLevel       Indicator of the level, 2 levels are allowed
    1445             : 
    1446             :     [Return value]
    1447             : 
    1448             :     const Image &       the image on the level nLevel
    1449             : 
    1450             : */
    1451             : 
    1452             : {
    1453           0 :     const Image* pRet = NULL;
    1454             : 
    1455           0 :     switch( nLevel )
    1456             :     {
    1457             :         case 0:
    1458           0 :             pRet = &aOpenedFolderBmp; break;
    1459             :         case 1:
    1460           0 :             pRet = &aOpenedDocBmp; break;
    1461             :         default:
    1462           0 :             pRet = &aClosedFolderBmp; break;
    1463             :     }
    1464             : 
    1465           0 :     return *pRet;
    1466             : }
    1467             : 
    1468             : //-------------------------------------------------------------------------
    1469             : 
    1470           0 : PopupMenu* SfxOrganizeListBox_Impl::CreateContextMenu()
    1471             : {
    1472           0 :     return new PopupMenu( *( pDlg->m_pEditBtn->GetPopupMenu() ) );
    1473             : }
    1474             : 
    1475             : //-------------------------------------------------------------------------
    1476             : 
    1477           0 : String SfxOrganizeDlg_Impl::GetPath_Impl( sal_Bool bOpen, const String& rFileName )
    1478             : 
    1479             : /*  [Description]
    1480             : 
    1481             :     Get path from FileDialog, for Import / Export of Templates
    1482             : 
    1483             :     [Parameter]
    1484             : 
    1485             :     sal_Bool bOpen                     Flag: Open / Save
    1486             :     const String& rFileName        Current file name as default
    1487             : 
    1488             :     [Return value]                 File name with path or empty string if
    1489             :                                    users has pressed 'Cancel'
    1490             : */
    1491             : 
    1492             : {
    1493           0 :     String aPath;
    1494           0 :     m_sExtension4Save = DEFINE_CONST_UNICODE( "vor" );
    1495             :     sal_Int16 nDialogType = bOpen
    1496             :         ? com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE
    1497           0 :         : com::sun::star::ui::dialogs::TemplateDescription::FILESAVE_SIMPLE;
    1498           0 :     if ( pFileDlg )
    1499           0 :         delete pFileDlg;
    1500           0 :     pFileDlg = new sfx2::FileDialogHelper( nDialogType, 0L );
    1501             : 
    1502             :     // add "All" filter
    1503             :     pFileDlg->AddFilter( SfxResId(STR_SFX_FILTERNAME_ALL).toString(),
    1504           0 :                          DEFINE_CONST_UNICODE( FILEDIALOG_FILTER_ALL ) );
    1505             :     // add template filter
    1506           0 :     String sFilterName( SfxResId(STR_TEMPLATE_FILTER).toString() );
    1507           0 :     String sFilterExt;
    1508             :     // add filters of modules which are installed
    1509           0 :     SvtModuleOptions aModuleOpt;
    1510           0 :     if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SWRITER ) )
    1511           0 :         sFilterExt += DEFINE_CONST_UNICODE( "*.ott;*.stw;*.oth" );
    1512           0 :     if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SCALC ) )
    1513             :     {
    1514           0 :         if ( sFilterExt.Len() > 0 )
    1515           0 :             sFilterExt += ';';
    1516           0 :         sFilterExt += DEFINE_CONST_UNICODE( "*.ots;*.stc" );
    1517             :     }
    1518           0 :     if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SIMPRESS ) )
    1519             :     {
    1520           0 :         if ( sFilterExt.Len() > 0 )
    1521           0 :             sFilterExt += ';';
    1522           0 :         sFilterExt += DEFINE_CONST_UNICODE( "*.otp;*.sti" );
    1523             :     }
    1524           0 :     if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SDRAW ) )
    1525             :     {
    1526           0 :         if ( sFilterExt.Len() > 0 )
    1527           0 :             sFilterExt += ';';
    1528           0 :         sFilterExt += DEFINE_CONST_UNICODE( "*.otg;*.std" );
    1529             :     }
    1530           0 :     if ( sFilterExt.Len() > 0 )
    1531           0 :         sFilterExt += ';';
    1532           0 :     sFilterExt += DEFINE_CONST_UNICODE( "*.vor" );
    1533             : 
    1534           0 :     sFilterName += DEFINE_CONST_UNICODE( " (" );
    1535           0 :     sFilterName += sFilterExt;
    1536           0 :     sFilterName += ')';
    1537           0 :     pFileDlg->AddFilter( sFilterName, sFilterExt );
    1538           0 :     pFileDlg->SetCurrentFilter( sFilterName );
    1539             : 
    1540           0 :     if ( aLastDir.Len() || rFileName.Len() )
    1541             :     {
    1542           0 :         INetURLObject aObj;
    1543           0 :         if ( aLastDir.Len() )
    1544             :         {
    1545           0 :             aObj.SetURL( aLastDir );
    1546           0 :             if ( rFileName.Len() )
    1547           0 :                 aObj.insertName( rFileName );
    1548             :         }
    1549             :         else
    1550           0 :             aObj.SetURL( rFileName );
    1551             : 
    1552           0 :         if ( aObj.hasExtension() )
    1553             :         {
    1554             :             m_sExtension4Save = aObj.getExtension(
    1555           0 :                 INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET );
    1556           0 :             aObj.removeExtension();
    1557             :         }
    1558             : 
    1559             :         DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
    1560           0 :         pFileDlg->SetDisplayDirectory( aObj.GetMainURL( INetURLObject::NO_DECODE ) );
    1561             :     }
    1562             : 
    1563           0 :     pFileDlg->StartExecuteModal( LINK( this, SfxOrganizeDlg_Impl, ExportHdl ) );
    1564             : 
    1565           0 :     return aPath;
    1566             : }
    1567             : 
    1568             : //-------------------------------------------------------------------------
    1569             : 
    1570             : ::com::sun::star::uno::Sequence< ::rtl::OUString >
    1571           0 :     SfxOrganizeDlg_Impl::GetPaths_Impl( const String& rFileName )
    1572             : 
    1573             : /*  [Description]
    1574             : 
    1575             :    Query plural paths by FileDialog, for Import / Export from document
    1576             :    templates
    1577             : 
    1578             :    [Parameter]
    1579             : 
    1580             :    const String& rFileName         The default file name when dialog executes
    1581             : 
    1582             :    [Return value]                 Empty sequence when users have clicked
    1583             :                                   'Cancel', a sequence just containing one
    1584             :                                   file name with path when they have
    1585             :                                   choosed one file or a sequence containing
    1586             :                                   path and file names without path
    1587             : */
    1588             : 
    1589             : {
    1590           0 :     ::com::sun::star::uno::Sequence< ::rtl::OUString > aPaths;
    1591           0 :     m_sExtension4Save = DEFINE_CONST_UNICODE( "vor" );
    1592           0 :     if ( pFileDlg )
    1593           0 :             delete pFileDlg;
    1594             :     pFileDlg = new sfx2::FileDialogHelper(
    1595           0 :         com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, SFXWB_MULTISELECTION );
    1596             : 
    1597             :     // add "All" filter
    1598             :     pFileDlg->AddFilter( SfxResId(STR_SFX_FILTERNAME_ALL).toString(),
    1599           0 :                          DEFINE_CONST_UNICODE( FILEDIALOG_FILTER_ALL ) );
    1600             : 
    1601             :     // add template filter
    1602           0 :     String sFilterName( SfxResId(STR_TEMPLATE_FILTER).toString() );
    1603           0 :     String sFilterExt;
    1604             :     // add filters of modules which are installed
    1605           0 :     SvtModuleOptions aModuleOpt;
    1606           0 :     if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SWRITER ) )
    1607           0 :         sFilterExt += DEFINE_CONST_UNICODE( "*.ott;*.stw;*.oth;*.dot;*.dotm;*.dotx" );
    1608           0 :     if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SCALC ) )
    1609             :     {
    1610           0 :         if ( sFilterExt.Len() > 0 )
    1611           0 :             sFilterExt += ';';
    1612           0 :         sFilterExt += DEFINE_CONST_UNICODE( "*.ots;*.stc;*.xlt;*.xltm;*.xltx" );
    1613             :     }
    1614           0 :     if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SIMPRESS ) )
    1615             :     {
    1616           0 :         if ( sFilterExt.Len() > 0 )
    1617           0 :             sFilterExt += ';';
    1618           0 :         sFilterExt += DEFINE_CONST_UNICODE( "*.otp;*.sti;*.pot;*.potm;*.potx" );
    1619             :     }
    1620           0 :     if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SDRAW ) )
    1621             :     {
    1622           0 :         if ( sFilterExt.Len() > 0 )
    1623           0 :             sFilterExt += ';';
    1624           0 :         sFilterExt += DEFINE_CONST_UNICODE( "*.otg;*.std" );
    1625             :     }
    1626           0 :     if ( sFilterExt.Len() > 0 )
    1627           0 :         sFilterExt += ';';
    1628           0 :     sFilterExt += DEFINE_CONST_UNICODE( "*.vor" );
    1629             : 
    1630           0 :     sFilterName += DEFINE_CONST_UNICODE( " (" );
    1631           0 :     sFilterName += sFilterExt;
    1632           0 :     sFilterName += ')';
    1633           0 :     pFileDlg->AddFilter( sFilterName, sFilterExt );
    1634           0 :     pFileDlg->SetCurrentFilter( sFilterName );
    1635             : 
    1636           0 :     if ( aLastDir.Len() || rFileName.Len() )
    1637             :     {
    1638           0 :         INetURLObject aObj;
    1639           0 :         if ( aLastDir.Len() )
    1640             :         {
    1641           0 :             aObj.SetURL( aLastDir );
    1642           0 :             if ( rFileName.Len() )
    1643           0 :                 aObj.insertName( rFileName );
    1644             :         }
    1645             :         else
    1646           0 :             aObj.SetURL( rFileName );
    1647             : 
    1648           0 :         if ( aObj.hasExtension() )
    1649             :         {
    1650             :             m_sExtension4Save = aObj.getExtension(
    1651           0 :                  INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET );
    1652           0 :             aObj.removeExtension();
    1653             :         }
    1654             : 
    1655             :         DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
    1656           0 :         pFileDlg->SetDisplayDirectory( aObj.GetMainURL( INetURLObject::NO_DECODE ) );
    1657             :     }
    1658             : 
    1659           0 :     pFileDlg->StartExecuteModal( LINK( this, SfxOrganizeDlg_Impl, ImportHdl ) );
    1660             : 
    1661           0 :     return aPaths;
    1662             : }
    1663             : 
    1664             : //-------------------------------------------------------------------------
    1665             : 
    1666           0 : sal_Bool SfxOrganizeDlg_Impl::DontDelete_Impl( SvTreeListEntry* pEntry )
    1667             : {
    1668           0 :     sal_uInt16 nDepth = pFocusBox->GetModel()->GetDepth(pEntry);
    1669           0 :     if(SfxOrganizeListBox_Impl::VIEW_FILES ==
    1670           0 :        pFocusBox->GetViewType())
    1671           0 :         nDepth++;
    1672           0 :     if( (nDepth > 2 && !pEntry->GetUserData()) ||
    1673             :        //Delete using GetContent forbidden
    1674             :        nDepth==2 || // Template / Not deleting config header
    1675             :        (nDepth==1 && SfxOrganizeListBox_Impl::VIEW_FILES ==
    1676           0 :         pFocusBox->GetViewType()) || //Not deleting Files
    1677           0 :        (0 == nDepth && pFocusBox->GetLevelCount_Impl(0) < 2))
    1678             :         //At least keep one template
    1679             :     {
    1680           0 :         return sal_True;
    1681             :     }
    1682             : 
    1683             :     //If delete is pressed on e.g. a style entry go up the chain to find the
    1684             :     //owning template
    1685           0 :     while (nDepth > 1)
    1686             :     {
    1687           0 :         pEntry = pFocusBox->GetParent(pEntry);
    1688           0 :         --nDepth;
    1689             :     }
    1690           0 :     SvTreeListEntry *pTemplateEntry = pEntry;
    1691             : 
    1692           0 :     sal_uInt16 nRegion = 0, nIndex = 0;
    1693           0 :     GetIndices_Impl( pFocusBox, pTemplateEntry, nRegion, nIndex );
    1694           0 :     const SfxDocumentTemplates* pTemplates = aMgr.GetTemplates();
    1695           0 :     if ( !pTemplates || !pTemplates->HasUserContents( nRegion, nIndex ) )
    1696           0 :         return sal_True;
    1697             : 
    1698           0 :     return sal_False;
    1699             : }
    1700             : 
    1701           0 : std::vector<rtl::OUString> SfxOrganizeDlg_Impl::GetAllFactoryURLs_Impl( ) const
    1702             : {
    1703           0 :     SvtModuleOptions aModOpt;
    1704           0 :     const ::com::sun::star::uno::Sequence < ::rtl::OUString >& aServiceNames = aModOpt.GetAllServiceNames() ;
    1705           0 :     std::vector<rtl::OUString> aList;
    1706           0 :     sal_Int32 nCount = aServiceNames.getLength();
    1707           0 :     for( sal_Int32 i=0; i<nCount; ++i )
    1708             :     {
    1709           0 :         if ( SfxObjectFactory::GetStandardTemplate( aServiceNames[i] ).Len() > 0 )
    1710             :         {
    1711           0 :             SvtModuleOptions::EFactory eFac = SvtModuleOptions::E_WRITER;
    1712           0 :             SvtModuleOptions::ClassifyFactoryByName( aServiceNames[i], eFac );
    1713           0 :             aList.push_back(aModOpt.GetFactoryEmptyDocumentURL(eFac));
    1714             :         }
    1715             :     }
    1716             : 
    1717           0 :     return aList;
    1718             : }
    1719             : 
    1720           0 : sal_Bool SfxOrganizeDlg_Impl::GetServiceName_Impl( String& rName, String& rFileURL ) const
    1721             : {
    1722           0 :     sal_Bool bRet = sal_False;
    1723           0 :     const SfxDocumentTemplates* pTemplates = aMgr.GetTemplates();
    1724           0 :     SvTreeListEntry* pEntry = pFocusBox ? pFocusBox->FirstSelected() : NULL;
    1725           0 :     sal_uInt16 nRegion = 0, nIndex = 0;
    1726           0 :     GetIndices_Impl( pFocusBox, pEntry, nRegion, nIndex );
    1727           0 :     rFileURL = pTemplates->GetPath( nRegion, nIndex );
    1728           0 :     if ( rFileURL.Len() > 0 )
    1729             :     {
    1730             :         try
    1731             :         {
    1732             :             uno::Reference< embed::XStorage > xStorage = ::comphelper::OStorageHelper::GetStorageFromURL(
    1733             :                                                     rFileURL,
    1734           0 :                                                     embed::ElementModes::READ );
    1735           0 :             sal_uIntPtr nFormat = SotStorage::GetFormatID( xStorage );
    1736             :             const SfxFilter* pFilter =
    1737           0 :                 SFX_APP()->GetFilterMatcher().GetFilter4ClipBoardId( nFormat );
    1738           0 :             if ( pFilter )
    1739             :             {
    1740           0 :                 rName = pFilter->GetServiceName();
    1741           0 :                 bRet = sal_True;
    1742           0 :             }
    1743             :         }
    1744           0 :         catch( uno::Exception& )
    1745             :         {}
    1746             :     }
    1747             : 
    1748           0 :     return bRet;
    1749             : }
    1750             : 
    1751           0 : long SfxOrganizeDlg_Impl::Dispatch_Impl( sal_uInt16 nId, Menu* _pMenu )
    1752             : 
    1753             : /*  [Description]
    1754             : 
    1755             :     Processing the events from MenuButton or Accelerator
    1756             : 
    1757             :     [Parameter]
    1758             : 
    1759             :     sal_uInt16 nId                      Event ID
    1760             : 
    1761             :     [Return value]                  1: Event has been processed,
    1762             :                                     0: Event has not been processed (SV-Menu)
    1763             : */
    1764             : 
    1765             : {
    1766           0 :     SuspendAccel aTmp(&aEditAcc);
    1767           0 :     SvTreeListEntry *pEntry = pFocusBox? pFocusBox->FirstSelected(): 0;
    1768           0 :     sal_Bool bHandled = sal_True;
    1769           0 :     switch(nId)
    1770             :     {
    1771             :         case ID_NEW:
    1772             :         {
    1773           0 :             if(!pEntry)
    1774           0 :                 return 1;
    1775           0 :             if(pFocusBox->GetViewType() == SfxOrganizeListBox_Impl::VIEW_TEMPLATES)
    1776             :             {
    1777           0 :                 if(0 == pFocusBox->GetModel()->GetDepth(pEntry))
    1778             :                 {
    1779           0 :                     const rtl::OUString aNoName(SFX2_RESSTR(STR_NONAME));
    1780           0 :                     SvTreeListEntry* pParent = pFocusBox->GetParent(pEntry);
    1781           0 :                     rtl::OUString aName(aNoName);
    1782           0 :                     sal_Int32 n = 1;
    1783           0 :                     while(!pFocusBox->IsUniqName_Impl(aName, pParent))
    1784             :                     {
    1785           0 :                         aName = aNoName + rtl::OUString::valueOf(n++);
    1786             :                     }
    1787             :                     aMgr.InsertDir( pFocusBox, aName,
    1788           0 :                             (sal_uInt16)pFocusBox->GetModel()->GetRelPos(pEntry)+1);
    1789             :                 }
    1790             :             }
    1791           0 :             break;
    1792             :         }
    1793             : 
    1794             :         case ID_DELETE:
    1795             :         {
    1796           0 :             if(!pEntry || DontDelete_Impl(pEntry))
    1797           0 :                 return 1;
    1798           0 :             const sal_uInt16 nDepth = pFocusBox->GetModel()->GetDepth(pEntry);
    1799           0 :             if(nDepth < 2)
    1800             :             {
    1801           0 :                 if(0 == nDepth && pFocusBox->GetLevelCount_Impl(0) < 2) return 1;
    1802           0 :                 if(SfxOrganizeListBox_Impl::VIEW_TEMPLATES == pFocusBox->GetViewType())
    1803             :                 {
    1804             :                     sal_uInt16 nResId = nDepth? STR_DELETE_TEMPLATE :
    1805           0 :                                             STR_DELETE_REGION;
    1806           0 :                     if( !QueryDelete_Impl(
    1807           0 :                         pDialog, nResId, pFocusBox->GetEntryText(pEntry)))
    1808           0 :                         return 1;
    1809           0 :                     if ( STR_DELETE_REGION == nResId &&
    1810           0 :                          pFocusBox->GetChildCount(pEntry))
    1811             :                     {
    1812           0 :                         QueryBox aQBox(pDialog, SfxResId(MSG_REGION_NOTEMPTY));
    1813           0 :                         if(RET_NO == aQBox.Execute())
    1814           0 :                             return 1;
    1815             :                     }
    1816           0 :                     sal_uInt16 nRegion = 0, nIndex = 0;
    1817           0 :                     GetIndices_Impl(pFocusBox, pEntry, nRegion, nIndex);
    1818             : 
    1819           0 :                     sal_uInt16 nDeleteInd = ( STR_DELETE_REGION == nResId? USHRT_MAX: nIndex );
    1820           0 :                     if ( !aMgr.Delete( pFocusBox, nRegion, nDeleteInd ) )
    1821             :                         ErrorDelete_Impl(
    1822             :                             pDialog,
    1823           0 :                             pFocusBox->GetEntryText(pEntry),
    1824           0 :                             ( nDeleteInd == USHRT_MAX && pFocusBox->GetChildCount(pEntry) ) );
    1825             :                 }
    1826             :             }
    1827             :             //Content Format
    1828           0 :             else if(nDepth + pFocusBox->GetDocLevel() >= 2)
    1829             :             {
    1830           0 :                 if(!QueryDelete_Impl(pDialog, STR_DELETE_TEMPLATE, pFocusBox->GetEntryText(pEntry)))
    1831           0 :                     return 1;
    1832           0 :                 Path aPath(pFocusBox, pEntry);
    1833             : 
    1834             :                 // it is ok to use the SfxObjectShellRef here since the object that
    1835             :                 // provides it ( GetObjectShell() calls CreateObjectShell() ) has a lock on it
    1836           0 :                 SfxObjectShellRef aRef = pFocusBox->GetObjectShell(aPath);
    1837           0 :                 if(aRef.Is() &&
    1838           0 :                     aRef->Remove(aPath[1+pFocusBox->GetDocLevel()],
    1839           0 :                                  aPath[2+pFocusBox->GetDocLevel()],
    1840           0 :                                  aPath[3+pFocusBox->GetDocLevel()]))
    1841           0 :                     pFocusBox->GetModel()->Remove(pEntry);
    1842             :                 else
    1843           0 :                     ErrorDelete_Impl(pDialog, pFocusBox->GetEntryText(pEntry), sal_False );
    1844             :             }
    1845           0 :             break;
    1846             :         }
    1847             : 
    1848             :         case ID_EDIT:
    1849             :         {
    1850           0 :             if(!pEntry)
    1851           0 :                 return 1;
    1852           0 :             sal_uInt16 nRegion = 0, nIndex = 0;
    1853           0 :             GetIndices_Impl( pFocusBox, pEntry, nRegion, nIndex );
    1854           0 :             const SfxStringItem aName( SID_FILE_NAME, aMgr.GetTemplates()->GetPath( nRegion, nIndex ) );
    1855           0 :             const SfxStringItem aLongName( SID_FILE_LONGNAME, pFocusBox->GetEntryText( pEntry ) );
    1856           0 :             const SfxStringItem aReferer( SID_REFERER, DEFINE_CONST_UNICODE( "private:user" ) );
    1857           0 :             const SfxStringItem aTargetName( SID_TARGETNAME, DEFINE_CONST_UNICODE( "_default" ) );
    1858           0 :             const SfxBoolItem   aTemplateIndicator( SID_TEMPLATE, sal_False );
    1859             : 
    1860             :             SFX_APP()->GetAppDispatcher_Impl()->Execute( SID_OPENTEMPLATE, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD,
    1861           0 :                                       &aName, &aLongName, &aReferer, &aTargetName, &aTemplateIndicator, 0L );
    1862           0 :             pDialog->EndDialog( RET_EDIT_STYLE );
    1863           0 :             break;
    1864             :         }
    1865             : 
    1866             :         case ID_COPY_FROM:
    1867             :         {
    1868           0 :             if ( !pEntry )
    1869           0 :                 return 1;
    1870           0 :             m_nRegion = 0;
    1871           0 :             m_nIndex = 0;
    1872           0 :             GetIndices_Impl( pFocusBox, pEntry, m_nRegion, m_nIndex );
    1873           0 :             GetPaths_Impl( String() );
    1874           0 :             break;
    1875             :         }
    1876             : 
    1877             :         case ID_COPY_TO:
    1878             :         {
    1879           0 :             if ( !pEntry )
    1880           0 :                 return 1;
    1881           0 :             m_nRegion = 0;
    1882           0 :             m_nIndex = 0;
    1883           0 :             GetIndices_Impl( pFocusBox, pEntry, m_nRegion, m_nIndex );
    1884           0 :             GetPath_Impl( sal_False, aMgr.GetTemplates()->GetFileName( m_nRegion, m_nIndex ) );
    1885           0 :             break;
    1886             :         }
    1887             : 
    1888             :         case ID_RESCAN:
    1889           0 :             if ( !aMgr.Rescan() )
    1890           0 :                 ErrorBox( pDialog, SfxResId( MSG_ERROR_RESCAN ) ).Execute();
    1891           0 :             if ( SfxOrganizeListBox_Impl::VIEW_TEMPLATES == m_pLeftLb->GetViewType() )
    1892           0 :                 m_pLeftLb->Reset();
    1893           0 :             if ( SfxOrganizeListBox_Impl::VIEW_TEMPLATES == m_pRightLb->GetViewType() )
    1894           0 :                 m_pRightLb->Reset();
    1895           0 :             break;
    1896             : 
    1897             :         case ID_PRINT:
    1898             :         {
    1899           0 :             if ( !pEntry )
    1900           0 :                 return 1;
    1901           0 :             Path aPath( pFocusBox, pEntry );
    1902             : 
    1903             :             // it is ok to use the SfxObjectShellRef here since the object that
    1904             :             // provides it ( GetObjectShell() calls CreateObjectShell() ) has a lock on it
    1905           0 :             SfxObjectShellRef aRef = pFocusBox->GetObjectShell( aPath );
    1906           0 :             if ( aRef.Is() )
    1907             :             {
    1908           0 :                 const sal_uInt16 nDocLevel = pFocusBox->GetDocLevel();
    1909           0 :                 if ( !pPrt )
    1910           0 :                     pPrt = new Printer;
    1911           0 :                 SvTreeListEntry *pDocEntry = pEntry;
    1912           0 :                 while ( pFocusBox->GetModel()->GetDepth( pDocEntry ) > nDocLevel )
    1913           0 :                     pDocEntry = pFocusBox->GetParent( pDocEntry );
    1914           0 :                 const String aName(pFocusBox->GetEntryText(pDocEntry));
    1915           0 :                 if ( !aRef->Print( *pPrt, aPath[1+nDocLevel],
    1916           0 :                                    aPath[2+nDocLevel], aPath[3+nDocLevel], &aName ) )
    1917           0 :                     ErrorBox( pDialog, SfxResId( MSG_PRINT_ERROR ) ).Execute();
    1918             :             }
    1919           0 :             break;
    1920             :         }
    1921             : 
    1922             :         case ID_PRINTER_SETUP:
    1923             :         {
    1924           0 :             PrinterSetupDialog* pDlg = new PrinterSetupDialog( pDialog );
    1925           0 :             if ( !pPrt )
    1926           0 :                 pPrt = new Printer;
    1927           0 :             pDlg->SetPrinter( pPrt );
    1928           0 :             pDlg->Execute();
    1929           0 :             delete pDlg;
    1930           0 :             break;
    1931             :         }
    1932             : 
    1933             :         case ID_DEFAULT_TEMPLATE:
    1934             :         {
    1935           0 :             String aServiceName, aFileURL;
    1936           0 :             if ( GetServiceName_Impl( aServiceName, aFileURL ) )
    1937           0 :                 SfxObjectFactory::SetStandardTemplate( aServiceName, aFileURL );
    1938           0 :             break;
    1939             :         }
    1940             : 
    1941             :         default:
    1942           0 :             bHandled = sal_False;
    1943             :     }
    1944             : 
    1945           0 :     if ( !bHandled && nId > ID_RESET_DEFAULT_TEMPLATE )
    1946             :     {
    1947           0 :         Menu* pSubMenu = _pMenu ? _pMenu : m_pEditBtn->GetPopupMenu()->GetPopupMenu( ID_RESET_DEFAULT_TEMPLATE );
    1948           0 :         if ( pSubMenu )
    1949             :         {
    1950           0 :             String aServiceName = SfxObjectShell::GetServiceNameFromFactory( pSubMenu->GetItemCommand( nId ) );
    1951           0 :             SfxObjectFactory::SetStandardTemplate( aServiceName, String() );
    1952           0 :             bHandled = sal_True;
    1953             :         }
    1954             :     }
    1955             : 
    1956           0 :     return bHandled ? 1 : 0;
    1957             : }
    1958             : 
    1959             : //-------------------------------------------------------------------------
    1960             : 
    1961           0 : IMPL_LINK_INLINE_START( SfxOrganizeDlg_Impl, MenuSelect_Impl, Menu *, pMenu )
    1962             : 
    1963             : /*  [Description]
    1964             : 
    1965             :     SelectHandler of Menu and Menubuttons (SV)
    1966             : 
    1967             :     [Parameter]
    1968             : 
    1969             :     MenuButton *pBtn                Button triggering the event
    1970             : 
    1971             :     [Return value]                  1: Event has been processed,
    1972             :                                     0: Event has not been processed (SV-Menu)
    1973             : */
    1974             : {
    1975           0 :     return Dispatch_Impl( pMenu->GetCurItemId(), pMenu );
    1976             : }
    1977           0 : IMPL_LINK_INLINE_END( SfxOrganizeDlg_Impl, MenuSelect_Impl, Menu *, pMenu )
    1978             : 
    1979             : //-------------------------------------------------------------------------
    1980             : 
    1981           0 : IMPL_LINK( SfxOrganizeDlg_Impl, AccelSelect_Impl, Accelerator *, pAccel )
    1982             : 
    1983             : /*  [Description]
    1984             : 
    1985             :     SelectHandler of Accelerators (SV)
    1986             : 
    1987             :     [Parameter]
    1988             : 
    1989             :     Accelerator *pAccel            Accelerator triggering the event
    1990             : 
    1991             :     [Return value]                  1: Event has been processed,
    1992             :                                     0: Event has not been processed (SV)
    1993             : */
    1994             : 
    1995             : {
    1996           0 :     SvTreeListEntry* pEntry = pFocusBox && pFocusBox->GetSelectionCount() ?
    1997           0 :         pFocusBox->FirstSelected() : NULL ;
    1998           0 :     return pEntry && ( pAccel->GetCurItemId() == ID_NEW  || !DontDelete_Impl( pEntry ) ) ?
    1999           0 :         Dispatch_Impl( pAccel->GetCurItemId(), NULL ) : 0;
    2000             : }
    2001             : 
    2002           0 : IMPL_LINK( SfxOrganizeDlg_Impl, MenuActivate_Impl, Menu *, pMenu )
    2003             : 
    2004             : /*  [Description]
    2005             : 
    2006             :     ActivateHandler of Menu and Menubuttons (SV)
    2007             : 
    2008             :     [Parameter]
    2009             : 
    2010             :     Menu *pMenu                     Event triggering the Menu
    2011             : 
    2012             :     [Return value]                  1: Event has been processed,
    2013             :                                     0: Event has not been processed (SV-Menu)
    2014             : */
    2015             : {
    2016           0 :     if ( pFocusBox && pFocusBox->IsEditingActive() )
    2017           0 :         pFocusBox->EndEditing( sal_False );
    2018           0 :     sal_Bool bEnable = ( pFocusBox && pFocusBox->GetSelectionCount() );
    2019           0 :     SvTreeListEntry* pEntry = bEnable ? pFocusBox->FirstSelected() : NULL;
    2020             :     const sal_uInt16 nDepth =
    2021           0 :         ( bEnable && pFocusBox->GetSelectionCount() ) ? pFocusBox->GetModel()->GetDepth( pEntry ) : 0;
    2022           0 :     const sal_uInt16 nDocLevel = bEnable ? pFocusBox->GetDocLevel() : 0;
    2023           0 :     int eVT = pFocusBox ? pFocusBox->GetViewType() : 0;
    2024             :         // Create only Template
    2025           0 :     pMenu->EnableItem( ID_NEW, bEnable && 0 == nDepth && SfxOrganizeListBox_Impl::VIEW_TEMPLATES == eVT );
    2026             :     // Template: Delete level 0,1,3ff
    2027             :     //           At least one region must be retained
    2028             :     // Files:    Delete level> 2
    2029             : 
    2030           0 :     pMenu->EnableItem( ID_DELETE, bEnable && !DontDelete_Impl( pEntry ) );
    2031             :     pMenu->EnableItem( ID_EDIT,
    2032             :                        bEnable && eVT == SfxOrganizeListBox_Impl::VIEW_TEMPLATES && nDepth == nDocLevel
    2033           0 :                            && !DontDelete_Impl( pEntry ) );
    2034             :     pMenu->EnableItem( ID_COPY_FROM,
    2035             :                        bEnable && eVT == SfxOrganizeListBox_Impl::VIEW_TEMPLATES &&
    2036           0 :                        ( nDepth == nDocLevel || nDepth == nDocLevel - 1 ) );
    2037             :     pMenu->EnableItem( ID_COPY_TO,
    2038             :                        bEnable && eVT == SfxOrganizeListBox_Impl::VIEW_TEMPLATES &&
    2039           0 :                        nDepth == nDocLevel );
    2040             :     pMenu->EnableItem( ID_RESCAN,
    2041           0 :                        SfxOrganizeListBox_Impl::VIEW_TEMPLATES == m_pRightLb->GetViewType() ||
    2042           0 :                        SfxOrganizeListBox_Impl::VIEW_TEMPLATES == m_pLeftLb->GetViewType() );
    2043           0 :     sal_Bool bPrint = bEnable && nDepth > pFocusBox->GetDocLevel();
    2044           0 :     if ( bPrint && pPrt )
    2045           0 :         bPrint = !pPrt->IsPrinting() && !pPrt->IsJobActive();
    2046           0 :     if ( bPrint && bEnable )
    2047             :     {
    2048             :         // only styles printable
    2049           0 :         Path aPath( pFocusBox, pFocusBox->FirstSelected() );
    2050           0 :         sal_uInt16 nIndex = aPath[ nDocLevel + 1 ];
    2051           0 :         bPrint = ( nIndex == CONTENT_STYLE );
    2052             :                 }
    2053           0 :     pMenu->EnableItem( ID_PRINT, bPrint );
    2054             : 
    2055           0 :     if ( bEnable && eVT == SfxOrganizeListBox_Impl::VIEW_TEMPLATES && nDepth == nDocLevel )
    2056             :     {
    2057           0 :         String aFactoryURL, aFileURL;
    2058           0 :         bEnable = GetServiceName_Impl( aFactoryURL, aFileURL );
    2059             :     }
    2060           0 :     else if ( bEnable )
    2061           0 :         bEnable = sal_False;
    2062           0 :     pMenu->EnableItem( ID_DEFAULT_TEMPLATE, bEnable );
    2063             : 
    2064           0 :     bEnable = sal_True;
    2065           0 :     std::vector<rtl::OUString> aList(GetAllFactoryURLs_Impl());
    2066           0 :     if (!aList.empty())
    2067             :     {
    2068           0 :         PopupMenu* pSubMenu = new PopupMenu;
    2069           0 :         sal_uInt16 nItemId = ID_RESET_DEFAULT_TEMPLATE + 1;
    2070           0 :         for(std::vector<rtl::OUString>::const_iterator i = aList.begin(); i != aList.end(); ++i)
    2071             :         {
    2072           0 :             INetURLObject aObj(*i);
    2073           0 :             String aTitle = SvFileInformationManager::GetDescription(aObj);
    2074           0 :             pSubMenu->InsertItem(nItemId, aTitle, SvFileInformationManager::GetImage(aObj, false));
    2075           0 :             pSubMenu->SetItemCommand(nItemId++, *i);
    2076           0 :         }
    2077           0 :         pMenu->SetPopupMenu( ID_RESET_DEFAULT_TEMPLATE, pSubMenu );
    2078             :     }
    2079             :     else
    2080           0 :         bEnable = sal_False;
    2081             : 
    2082           0 :     pMenu->EnableItem( ID_RESET_DEFAULT_TEMPLATE, bEnable );
    2083             : 
    2084           0 :     return 1;
    2085             : }
    2086             : 
    2087             : //-------------------------------------------------------------------------
    2088             : 
    2089           0 : IMPL_LINK( SfxOrganizeDlg_Impl, GetFocus_Impl, SfxOrganizeListBox_Impl *, pBox )
    2090             : 
    2091             : /*  [Description]
    2092             : 
    2093             :     GetFocus-Handler, is called from the Select-Handler of ListBox
    2094             :     Used in the listBox that has the focus and to determine its condition.
    2095             : 
    2096             :     [Parameter]
    2097             : 
    2098             :     SfxOrganizeListBox *pBox        The calling Box
    2099             : */
    2100             : 
    2101             : {
    2102           0 :     if(pFocusBox && pFocusBox != pBox)
    2103           0 :         pFocusBox->SelectAll(sal_False);
    2104           0 :     pFocusBox = pBox;
    2105             :     m_pFilesBtn->Enable( SfxOrganizeListBox_Impl::VIEW_FILES ==
    2106           0 :                       pFocusBox->GetViewType() );
    2107           0 :     return 0;
    2108             : }
    2109             : 
    2110             : //-------------------------------------------------------------------------
    2111             : 
    2112           0 : IMPL_LINK( SfxOrganizeDlg_Impl, LeftListBoxSelect_Impl, ListBox *, pBox )
    2113             : 
    2114             : /*  [Description]
    2115             : 
    2116             :     Select-Handler, is called from the Select-Handler of ListBox.
    2117             :     If the mode of the Boxes are different (Document view or Template view)
    2118             :     then the models are separated, otherwise joined together.
    2119             : 
    2120             :     [Parameter]
    2121             : 
    2122             :     ListBox *pBox               The calling Box
    2123             : */
    2124             : {
    2125             :     const SfxOrganizeListBox_Impl::DataEnum
    2126           0 :         eViewType = pBox->GetSelectEntryPos() == 0 ?
    2127           0 :         SfxOrganizeListBox_Impl::VIEW_TEMPLATES : SfxOrganizeListBox_Impl::VIEW_FILES;
    2128           0 :     if(eViewType!= m_pLeftLb->GetViewType()) {
    2129           0 :         m_pLeftLb->SetViewType(eViewType);
    2130           0 :         if(m_pRightLb->GetViewType() == eViewType)
    2131           0 :             m_pLeftLb->SetModel(m_pRightLb->GetModel());
    2132             :         else {
    2133             :             // Models trennen
    2134           0 :             m_pLeftLb->DisconnectFromModel();
    2135           0 :             m_pLeftLb->Reset();
    2136             :         }
    2137             :     }
    2138           0 :     GetFocus_Impl(m_pLeftLb);
    2139           0 :     return 0;
    2140             : }
    2141             : 
    2142             : //-------------------------------------------------------------------------
    2143             : 
    2144           0 : IMPL_LINK( SfxOrganizeDlg_Impl, RightListBoxSelect_Impl, ListBox *, pBox )
    2145             : 
    2146             : /*  [Description]
    2147             : 
    2148             :     Select-Handler, will be called by Select-Handler of the ListBox.
    2149             :     If the mode of the Boxes are different (Document view or Template view)
    2150             :     then the models are separated, otherwise joined together.
    2151             : 
    2152             :     [Parameter]
    2153             : 
    2154             :     ListBox *pBox               The calling Box
    2155             : */
    2156             : {
    2157             :     const SfxOrganizeListBox_Impl::DataEnum eViewType =
    2158           0 :         pBox->GetSelectEntryPos() == 0 ?
    2159           0 :         SfxOrganizeListBox_Impl::VIEW_TEMPLATES : SfxOrganizeListBox_Impl::VIEW_FILES;
    2160           0 :     if(eViewType!= m_pRightLb->GetViewType())
    2161             :     {
    2162           0 :         m_pRightLb->SetViewType(eViewType);
    2163           0 :         if(m_pLeftLb->GetViewType() == eViewType)
    2164           0 :             m_pRightLb->SetModel(m_pLeftLb->GetModel());
    2165             :         else
    2166             :         {
    2167             :             // Separate models
    2168           0 :             m_pRightLb->DisconnectFromModel();
    2169           0 :             m_pRightLb->Reset();
    2170             :         }
    2171             :     }
    2172           0 :     m_pRightLb->GrabFocus();
    2173           0 :     GetFocus_Impl(m_pRightLb);
    2174           0 :     return 0;
    2175             : }
    2176             : 
    2177             : //-------------------------------------------------------------------------
    2178             : 
    2179           0 : IMPL_LINK_NOARG(SfxOrganizeDlg_Impl, OnAddressTemplateClicked)
    2180             : {
    2181           0 :     svt::AddressBookSourceDialog aDialog(pDialog, ::comphelper::getProcessServiceFactory());
    2182           0 :     aDialog.Execute();
    2183           0 :     return 0L;
    2184             : }
    2185             : 
    2186           0 : IMPL_LINK_NOARG(SfxOrganizeDlg_Impl, Close_Impl)
    2187             : {
    2188           0 :     pDialog->EndDialog( sal_True );
    2189           0 :     return 0L;
    2190             : }
    2191             : 
    2192             : //-------------------------------------------------------------------------
    2193             : 
    2194           0 : IMPL_LINK( SfxOrganizeDlg_Impl, AddFiles_Impl, Button *, pButton )
    2195             : 
    2196             : /*  [Description]
    2197             : 
    2198             :     Handler of the button for adding files through Dialog.
    2199             : 
    2200             :     [Parameter]
    2201             : 
    2202             :     Button *                Button, triggering this Event
    2203             : 
    2204             : */
    2205             : {
    2206             :     (void)pButton; //unused
    2207           0 :     if ( pFileDlg )
    2208           0 :         delete pFileDlg;
    2209             :     pFileDlg = new sfx2::FileDialogHelper(
    2210             :             ui::dialogs::TemplateDescription::FILEOPEN_READONLY_VERSION,
    2211           0 :             0, String() );
    2212             : 
    2213             :     // add config and basic filter
    2214           0 :     static String sOpenBracket( DEFINE_CONST_UNICODE( " (" ) );
    2215           0 :     static String sCloseBracket( DEFINE_CONST_UNICODE( ")" ) );
    2216           0 :     static String sConfigExt( DEFINE_CONST_UNICODE( "*.cfg" ) );
    2217           0 :     static String sBasicExt( DEFINE_CONST_UNICODE( "*.sbl" ) );
    2218             : 
    2219           0 :     String sFilterName( SfxResId(RID_STR_FILTCONFIG).toString() );
    2220           0 :     sFilterName += sOpenBracket;
    2221           0 :     sFilterName += sConfigExt;
    2222           0 :     sFilterName += sCloseBracket;
    2223           0 :     pFileDlg->AddFilter( sFilterName, sConfigExt );
    2224             : 
    2225           0 :     sFilterName = SfxResId(RID_STR_FILTBASIC).toString();
    2226           0 :     sFilterName += sOpenBracket;
    2227           0 :     sFilterName += sBasicExt;
    2228           0 :     sFilterName += sCloseBracket;
    2229           0 :     pFileDlg->AddFilter( sFilterName, sBasicExt );
    2230             : 
    2231             :     // set "All" filter as current
    2232           0 :     pFileDlg->SetCurrentFilter( SfxResId(STR_SFX_FILTERNAME_ALL).toString() );
    2233             : 
    2234           0 :     if ( aLastDir.Len() )
    2235           0 :         pFileDlg->SetDisplayDirectory( aLastDir );
    2236             : 
    2237           0 :     pFileDlg->StartExecuteModal( LINK( this, SfxOrganizeDlg_Impl, AddFilesHdl ) );
    2238             : 
    2239           0 :     return 0;
    2240             : }
    2241             : 
    2242             : //-------------------------------------------------------------------------
    2243             : 
    2244           0 : IMPL_LINK_NOARG(SfxOrganizeDlg_Impl, ExportHdl)
    2245             : {
    2246             :     DBG_ASSERT( pFileDlg, "SfxOrganizeDlg_Impl::ExportHdl(): no file dialog" );
    2247             : 
    2248           0 :     if ( ERRCODE_NONE == pFileDlg->GetError() )
    2249             :     {
    2250           0 :         String aPath = pFileDlg->GetPath();
    2251           0 :         INetURLObject aObj( aPath );
    2252             : 
    2253             :         // we want to keep the original extension when exporting, the file open dialog
    2254             :         // always sets the extension to *.vor
    2255           0 :         if ( pFileDlg->GetDialogType() ==
    2256             :                 com::sun::star::ui::dialogs::TemplateDescription::FILESAVE_SIMPLE )
    2257             :         {
    2258           0 :             if ( aObj.hasExtension() )
    2259           0 :                 aObj.removeExtension();
    2260             : 
    2261           0 :             aObj.setExtension( m_sExtension4Save );
    2262           0 :             aPath = aObj.GetMainURL( INetURLObject::DECODE_TO_IURI );
    2263             :         }
    2264             : 
    2265           0 :         aObj.removeSegment();
    2266           0 :         aLastDir = aObj.GetMainURL( INetURLObject::DECODE_TO_IURI );
    2267             : 
    2268           0 :         if ( aPath.Len() && !aMgr.CopyTo( m_nRegion, m_nIndex, aPath ) )
    2269             :         {
    2270           0 :             String aText( SfxResId(STR_ERROR_COPY_TEMPLATE).toString() );
    2271           0 :             aText.SearchAndReplaceAscii( "$1", aPath );
    2272           0 :             ErrorBox( pDialog, WB_OK, aText ).Execute();
    2273           0 :         }
    2274             :     }
    2275             : 
    2276           0 :     return 0L;
    2277             : }
    2278             : 
    2279             : //-------------------------------------------------------------------------
    2280             : 
    2281           0 : IMPL_LINK_NOARG(SfxOrganizeDlg_Impl, ImportHdl)
    2282             : {
    2283             :     DBG_ASSERT( pFileDlg, "SfxOrganizeDlg_Impl::ImportHdl(): no file dialog" );
    2284           0 :     ::com::sun::star::uno::Sequence< ::rtl::OUString > aPaths;
    2285             : 
    2286           0 :     if ( ERRCODE_NONE == pFileDlg->GetError() )
    2287             :     {
    2288           0 :         aPaths = pFileDlg->GetMPath();
    2289           0 :         sal_Int32 lastCount = aPaths.getLength() - 1;
    2290           0 :         INetURLObject aObj( aPaths.getArray()[ lastCount ] );
    2291             : 
    2292           0 :         aObj.removeSegment();
    2293           0 :         aLastDir = aObj.GetMainURL( INetURLObject::DECODE_TO_IURI );
    2294             :     }
    2295             : 
    2296           0 :     sal_Int32 nCount = aPaths.getLength();
    2297           0 :     if ( 1 == nCount )
    2298             :     {
    2299           0 :        String aPath = String( aPaths.getArray()[0] );
    2300           0 :        if ( aPath.Len() && !aMgr.CopyFrom( pFocusBox, m_nRegion, m_nIndex, aPath ) )
    2301             :        {
    2302           0 :            String aText( SfxResId(STR_ERROR_COPY_TEMPLATE).toString() );
    2303           0 :            aText.SearchAndReplaceAscii( "$1", aPath );
    2304           0 :            ErrorBox( pDialog, WB_OK, aText ).Execute();
    2305           0 :        }
    2306             :     }
    2307           0 :     else if ( nCount > 1 )
    2308             :     {
    2309           0 :         INetURLObject aPathObj( aPaths[0] );
    2310           0 :         aPathObj.setFinalSlash();
    2311           0 :         for ( sal_uInt16 i = 1; i < nCount; ++i )
    2312             :         {
    2313           0 :             if ( 1 == i )
    2314           0 :                 aPathObj.Append( aPaths[i] );
    2315             :             else
    2316           0 :                 aPathObj.setName( aPaths[i] );
    2317           0 :             String aPath = aPathObj.GetMainURL( INetURLObject::NO_DECODE );
    2318           0 :             if ( aPath.Len() && !aMgr.CopyFrom( pFocusBox, m_nRegion, m_nIndex, aPath ) )
    2319             :             {
    2320           0 :                 String aText( SfxResId(STR_ERROR_COPY_TEMPLATE).toString() );
    2321           0 :                 aText.SearchAndReplaceAscii( "$1", aPath );
    2322           0 :                 ErrorBox( pDialog, WB_OK, aText ).Execute();
    2323             :             }
    2324           0 :         }
    2325             :     }
    2326             : 
    2327           0 :     return 0L;
    2328             : }
    2329             : 
    2330             : //-------------------------------------------------------------------------
    2331             : 
    2332           0 : IMPL_LINK_NOARG(SfxOrganizeDlg_Impl, AddFilesHdl)
    2333             : {
    2334           0 :     if ( ERRCODE_NONE == pFileDlg->GetError() )
    2335             :     {
    2336           0 :         String aPath = pFileDlg->GetPath();
    2337           0 :         aMgr.InsertFile( pFocusBox, aPath );
    2338           0 :         INetURLObject aObj( aPath );
    2339           0 :         aObj.removeSegment();
    2340           0 :         aObj.setFinalSlash();
    2341           0 :         aLastDir = aObj.GetMainURL( INetURLObject::DECODE_TO_IURI );
    2342             :     }
    2343             : 
    2344           0 :     return 0L;
    2345             : }
    2346             : 
    2347             : //-------------------------------------------------------------------------
    2348             : 
    2349           0 : short SfxTemplateOrganizeDlg::Execute()
    2350             : 
    2351             : /*  [Description]
    2352             : 
    2353             :     Overloaded Execute method; stores changes to the document templates
    2354             :     (SV-Methode)
    2355             : 
    2356             : */
    2357             : 
    2358             : {
    2359           0 :     const short nRet = ModalDialog::Execute();
    2360           0 :     if(RET_CANCEL != nRet)
    2361             :     {
    2362           0 :         pImp->aMgr.SaveAll(this);
    2363           0 :         SfxTemplateDialog* pTemplDlg = SFX_APP()->GetTemplateDialog();
    2364           0 :         if(pTemplDlg)
    2365           0 :             pTemplDlg->Update();
    2366             :     }
    2367           0 :     return nRet;
    2368             : }
    2369             : 
    2370             : 
    2371             : //-------------------------------------------------------------------------
    2372             : 
    2373           0 : SfxTemplateOrganizeDlg::SfxTemplateOrganizeDlg(Window * pParent,
    2374             :                                                 SfxDocumentTemplates *pTempl)
    2375             :     : ModalDialog(pParent, "TemplateManagementDialog",
    2376             :         "sfx/ui/templatemanagementdialog.ui")
    2377           0 :     , pImp( new SfxOrganizeDlg_Impl(this, pTempl) )
    2378             : {
    2379           0 : }
    2380             : 
    2381             : //-------------------------------------------------------------------------
    2382             : 
    2383           0 : SfxTemplateOrganizeDlg::~SfxTemplateOrganizeDlg()
    2384             : {
    2385           0 :     GetpApp()->RemoveAccel(&pImp->aEditAcc);
    2386           0 :     delete pImp->pPrt;
    2387           0 :     delete pImp;
    2388           0 : }
    2389             : 
    2390             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10