LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sw/source/ui/utlui - glbltree.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 740 0.1 %
Date: 2013-07-09 Functions: 2 52 3.8 %
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 <vcl/msgbox.hxx>
      21             : #include <svl/stritem.hxx>
      22             : #include <sfx2/fcontnr.hxx>
      23             : #include <sfx2/linkmgr.hxx>
      24             : #include <sfx2/dispatch.hxx>
      25             : #include <svl/urihelper.hxx>
      26             : #include <sfx2/docfile.hxx>
      27             : #include <vcl/help.hxx>
      28             : #include <sot/filelist.hxx>
      29             : #include <svl/eitem.hxx>
      30             : #include <svl/urlbmk.hxx>
      31             : #include <vcl/graphicfilter.hxx>
      32             : #include "svtools/treelistentry.hxx"
      33             : #include <sfx2/docinsert.hxx>
      34             : #include <sfx2/filedlghelper.hxx>
      35             : 
      36             : #include <sfx2/app.hxx>
      37             : #include <swmodule.hxx>
      38             : #include <wrtsh.hxx>
      39             : #include <view.hxx>
      40             : #include <docsh.hxx>
      41             : #include <content.hxx>
      42             : #include <edglbldc.hxx>
      43             : #include <section.hxx>
      44             : #include <tox.hxx>
      45             : #include <cnttab.hxx>
      46             : #include <navipi.hxx>
      47             : #include <navicont.hxx>
      48             : #include <edtwin.hxx>
      49             : #include <uitool.hxx>
      50             : 
      51             : #include <cmdid.h>
      52             : #include <helpid.h>
      53             : #include <navipi.hrc>
      54             : #include <utlui.hrc>
      55             : #include <comcore.hrc>
      56             : #include <globals.hrc>
      57             : #include "swabstdlg.hxx"
      58             : 
      59             : using namespace ::com::sun::star::uno;
      60             : 
      61             : // Context menu for GlobalTree
      62             : #define CTX_INSERT_ANY_INDEX 10
      63             : #define CTX_INSERT_FILE     11
      64             : #define CTX_INSERT_NEW_FILE 12
      65             : #define CTX_INSERT_TEXT     13
      66             : 
      67             : #define CTX_UPDATE_SEL      20
      68             : #define CTX_UPDATE_INDEX    21
      69             : #define CTX_UPDATE_LINK     22
      70             : #define CTX_UPDATE_ALL      23
      71             : 
      72             : #define CTX_UPDATE          1
      73             : #define CTX_INSERT          2
      74             : #define CTX_EDIT            3
      75             : #define CTX_DELETE          4
      76             : #define CTX_EDIT_LINK       5
      77             : 
      78             : #define GLOBAL_UPDATE_TIMEOUT 2000
      79             : 
      80             : // Flags for PopupMenu-enable/disable
      81             : #define ENABLE_INSERT_IDX   0x0001
      82             : #define ENABLE_INSERT_FILE  0x0002
      83             : #define ENABLE_INSERT_TEXT  0x0004
      84             : #define ENABLE_EDIT         0x0008
      85             : #define ENABLE_DELETE       0x0010
      86             : #define ENABLE_UPDATE       0x0020
      87             : #define ENABLE_UPDATE_SEL   0x0040
      88             : #define ENABLE_EDIT_LINK    0x0080
      89             : 
      90             : // TabPos: push to left
      91             : #define  GLBL_TABPOS_SUB 5
      92             : 
      93             : const SfxObjectShell* SwGlobalTree::pShowShell = 0;
      94             : static const char* aHelpForMenu[] =
      95             : {
      96             :     0,                          //
      97             :     HID_GLBLTREE_UPDATE,        //CTX_UPDATE
      98             :     HID_GLBLTREE_INSERT,        //CTX_INSERT
      99             :     HID_GLBLTREE_EDIT,          //CTX_EDIT
     100             :     HID_GLBLTREE_DEL,           //CTX_DELETE
     101             :     HID_GLBLTREE_EDIT_LINK,     //CTX_EDIT_LINK
     102             :     0,                        //
     103             :     0,                        //
     104             :     0,                        //
     105             :     0,                        //
     106             :     HID_GLBLTREE_INS_IDX,       //CTX_INSERT_ANY_INDEX
     107             :     HID_GLBLTREE_INS_FILE,      //CTX_INSERT_FILE
     108             :     HID_GLBLTREE_INS_NEW_FILE,  //CTX_INSERT_NEW_FILE
     109             :     HID_GLBLTREE_INS_TEXT,      //CTX_INSERT_TEXT
     110             :     0,                          //
     111             :     0,                          //
     112             :     0,                          //
     113             :     0,                          //
     114             :     0,                          //
     115             :     0,                          //
     116             :     HID_GLBLTREE_UPD_SEL,       //CTX_UPDATE_SEL
     117             :     HID_GLBLTREE_UPD_IDX,       //CTX_UPDATE_INDEX
     118             :     HID_GLBLTREE_UPD_LINK,      //CTX_UPDATE_LINK
     119             :     HID_GLBLTREEUPD_ALL         //CTX_UPDATE_ALL
     120             : };
     121             : 
     122           0 : class SwGlobalFrameListener_Impl : public SfxListener
     123             : {
     124             :     bool bValid;
     125             : public:
     126           0 :     SwGlobalFrameListener_Impl(SfxViewFrame& rFrame) :
     127           0 :         bValid(true)
     128             :         {
     129           0 :             StartListening(rFrame);
     130           0 :         }
     131             : 
     132             :     virtual void        Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
     133             : 
     134           0 :     bool                IsValid() const {return bValid;}
     135             : };
     136             : 
     137           0 : void    SwGlobalFrameListener_Impl::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint )
     138             : {
     139           0 :     if( rHint.ISA(SfxSimpleHint) &&
     140           0 :             (((SfxSimpleHint&) rHint).GetId() == SFX_HINT_DYING))
     141           0 :         bValid = false;
     142           0 : }
     143             : 
     144           0 : SwGlobalTree::SwGlobalTree(Window* pParent, const ResId& rResId) :
     145             : 
     146             :     SvTreeListBox(pParent, rResId),
     147             : 
     148             :     pActiveShell        ( NULL ),
     149             :     pEmphasisEntry      ( NULL ),
     150             :     pDDSource           ( NULL ),
     151             :     pSwGlblDocContents  ( NULL ),
     152             :     pDefParentWin       ( NULL ),
     153             :     pDocContent         ( NULL ),
     154             :     pDocInserter        ( NULL ),
     155             : 
     156             :     bIsInternalDrag         ( false ),
     157             :     bLastEntryEmphasis      ( false ),
     158           0 :     bIsImageListInitialized ( false )
     159             : 
     160             : {
     161             :     SetDragDropMode(SV_DRAGDROP_APP_COPY  |
     162             :                     SV_DRAGDROP_CTRL_MOVE |
     163           0 :                     SV_DRAGDROP_ENABLE_TOP );
     164             : 
     165           0 :     aUpdateTimer.SetTimeout(GLOBAL_UPDATE_TIMEOUT);
     166           0 :     aUpdateTimer.SetTimeoutHdl(LINK(this, SwGlobalTree, Timeout));
     167           0 :     aUpdateTimer.Start();
     168           0 :     for(sal_uInt16 i = 0; i < GLOBAL_CONTEXT_COUNT; i++)
     169             :     {
     170           0 :         aContextStrings[i] = SW_RESSTR(i+ ST_GLOBAL_CONTEXT_FIRST);
     171             :     }
     172           0 :     SetHelpId(HID_NAVIGATOR_GLOB_TREELIST);
     173           0 :     SelectHdl();
     174           0 :     SetDoubleClickHdl(LINK(this, SwGlobalTree, DoubleClickHdl));
     175           0 :     EnableContextMenuHandling();
     176           0 : }
     177             : 
     178           0 : SwGlobalTree::~SwGlobalTree()
     179             : {
     180           0 :     delete pSwGlblDocContents;
     181           0 :     delete pDocInserter;
     182           0 : }
     183             : 
     184           0 : sal_Int8 SwGlobalTree::ExecuteDrop( const ExecuteDropEvent& rEvt )
     185             : {
     186           0 :     sal_Int8 nRet = DND_ACTION_NONE;
     187           0 :     SvTreeListEntry* pLast = (SvTreeListEntry*)LastVisible();
     188           0 :     if(pEmphasisEntry)
     189             :     {
     190           0 :         ImplShowTargetEmphasis( Prev(pEmphasisEntry), sal_False );
     191           0 :         pEmphasisEntry = 0;
     192             :     }
     193           0 :     else if(bLastEntryEmphasis && pLast)
     194             :     {
     195           0 :         ImplShowTargetEmphasis( pLast, sal_False);
     196             :     }
     197             : 
     198           0 :     SvTreeListEntry* pDropEntry = bLastEntryEmphasis ? 0 : GetEntry(rEvt.maPosPixel);
     199           0 :     if( bIsInternalDrag )
     200             :     {
     201           0 :         SvTreeListEntry* pDummy = 0;
     202           0 :         sal_uLong nInsertionPos = LIST_APPEND;
     203           0 :         NotifyMoving( pDropEntry, pDDSource, pDummy, nInsertionPos );
     204             :     }
     205             :     else
     206             :     {
     207           0 :         TransferableDataHelper aData( rEvt.maDropEvent.Transferable );
     208             : 
     209           0 :         String sFileName;
     210             :         const SwGlblDocContent* pCnt = pDropEntry ?
     211             :                     (const SwGlblDocContent*)pDropEntry->GetUserData() :
     212           0 :                             0;
     213           0 :         if( aData.HasFormat( FORMAT_FILE_LIST ))
     214             :         {
     215           0 :             nRet = rEvt.mnAction;
     216           0 :             SwGlblDocContents* pTempContents = new SwGlblDocContents;
     217             :             int nAbsContPos = pDropEntry ?
     218           0 :                                 (int) GetModel()->GetAbsPos(pDropEntry):
     219           0 :                                     - 1;
     220           0 :             sal_uInt16 nEntryCount = (sal_uInt16)GetEntryCount();
     221             : 
     222             :             // Get data
     223           0 :             FileList aFileList;
     224           0 :             aData.GetFileList( FORMAT_FILE_LIST, aFileList );
     225           0 :             for ( sal_uInt16 n = (sal_uInt16)aFileList.Count(); n--; )
     226             :             {
     227           0 :                 sFileName = aFileList.GetFile(n);
     228           0 :                 InsertRegion(pCnt, &sFileName);
     229             :                 // The list of contents must be newly fetched after inserting,
     230             :                 // to not work on an old content.
     231           0 :                 if(n)
     232             :                 {
     233           0 :                     pActiveShell->GetGlobalDocContent(*pTempContents);
     234             :                     // If the file was successfully inserted,
     235             :                     // then the next content must also be fetched.
     236           0 :                     if(nEntryCount < pTempContents->size())
     237             :                     {
     238           0 :                         nEntryCount++;
     239           0 :                         nAbsContPos++;
     240           0 :                         pCnt = (*pTempContents)[ nAbsContPos ];
     241             :                     }
     242             :                 }
     243             :             }
     244           0 :             delete pTempContents;
     245             :         }
     246           0 :         else if( 0 != (sFileName =
     247           0 :                         SwNavigationPI::CreateDropFileName( aData )).Len())
     248             :         {
     249           0 :             INetURLObject aTemp(sFileName);
     250           0 :             GraphicDescriptor aDesc(aTemp);
     251           0 :             if( !aDesc.Detect() )   // accept no graphics
     252             :             {
     253           0 :                 nRet = rEvt.mnAction;
     254           0 :                 InsertRegion(pCnt, &sFileName);
     255           0 :             }
     256           0 :         }
     257             :     }
     258           0 :     bLastEntryEmphasis = false;
     259           0 :     return nRet;
     260             : 
     261             : }
     262             : 
     263           0 : sal_Int8 SwGlobalTree::AcceptDrop( const AcceptDropEvent& rEvt )
     264             : {
     265           0 :     sal_Int8 nRet = rEvt.mnAction;
     266             : 
     267             :     //initiate scrolling
     268           0 :     GetDropTarget( rEvt.maPosPixel );
     269           0 :     SvTreeListEntry* pLast = (SvTreeListEntry*)LastVisible();
     270           0 :     if( rEvt.mbLeaving )
     271             :     {
     272           0 :         if( pEmphasisEntry )
     273             :         {
     274           0 :             ImplShowTargetEmphasis( Prev(pEmphasisEntry), sal_False );
     275           0 :             pEmphasisEntry = 0;
     276             :         }
     277           0 :         else if(bLastEntryEmphasis && pLast)
     278             :         {
     279           0 :             ImplShowTargetEmphasis( pLast, sal_False);
     280             :         }
     281           0 :         bLastEntryEmphasis = false;
     282             :     }
     283             :     else
     284             :     {
     285           0 :         SvTreeListEntry* pDropEntry = GetEntry( rEvt.maPosPixel );
     286           0 :         if(bIsInternalDrag)
     287             :         {
     288           0 :             if( pDDSource != pDropEntry )
     289           0 :                 nRet = rEvt.mnAction;
     290             :         }
     291           0 :         else if( IsDropFormatSupported( FORMAT_FILE ) ||
     292           0 :                   IsDropFormatSupported( FORMAT_STRING ) ||
     293           0 :                   IsDropFormatSupported( FORMAT_FILE_LIST ) ||
     294           0 :                   IsDropFormatSupported( SOT_FORMATSTR_ID_SOLK ) ||
     295           0 :                    IsDropFormatSupported( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK )||
     296           0 :                    IsDropFormatSupported( SOT_FORMATSTR_ID_FILECONTENT ) ||
     297           0 :                    IsDropFormatSupported( SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR ) ||
     298           0 :                    IsDropFormatSupported( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR ) ||
     299           0 :                    IsDropFormatSupported( SOT_FORMATSTR_ID_FILENAME ))
     300           0 :                 nRet = DND_ACTION_LINK;
     301             : 
     302           0 :         if(pEmphasisEntry && pEmphasisEntry != pDropEntry)
     303           0 :             ImplShowTargetEmphasis( Prev(pEmphasisEntry), sal_False );
     304           0 :         else if(pLast && bLastEntryEmphasis  && pDropEntry)
     305             :         {
     306           0 :             ImplShowTargetEmphasis( pLast, sal_False);
     307           0 :             bLastEntryEmphasis = false;
     308             :         }
     309             : 
     310           0 :         if(pDropEntry)
     311           0 :             ImplShowTargetEmphasis( Prev(pDropEntry), DND_ACTION_NONE != nRet );
     312           0 :         else if(pLast)
     313             :         {
     314           0 :             ImplShowTargetEmphasis( pLast, DND_ACTION_NONE != nRet );
     315           0 :             bLastEntryEmphasis = true;
     316             :         }
     317           0 :         pEmphasisEntry = pDropEntry;
     318             :     }
     319           0 :     return nRet;
     320             : }
     321             : 
     322           0 : PopupMenu* SwGlobalTree::CreateContextMenu()
     323             : {
     324           0 :     PopupMenu* pPop = 0;
     325           0 :     if(pActiveShell &&
     326           0 :         !pActiveShell->GetView().GetDocShell()->IsReadOnly())
     327             :     {
     328           0 :         sal_uInt16 nEnableFlags = GetEnableFlags();
     329           0 :         pPop = new PopupMenu;
     330           0 :         PopupMenu* pSubPop1 = new PopupMenu;
     331           0 :         PopupMenu* pSubPop2 = new PopupMenu;
     332             : 
     333           0 :         for (sal_uInt16 i = CTX_UPDATE_SEL; i <= CTX_UPDATE_ALL; i++)
     334             :         {
     335           0 :             pSubPop2->InsertItem( i, aContextStrings[ST_UPDATE_SEL - ST_GLOBAL_CONTEXT_FIRST - CTX_UPDATE_SEL+ i] );
     336           0 :             pSubPop2->SetHelpId(i, aHelpForMenu[i]);
     337             :         }
     338           0 :         pSubPop2->EnableItem(CTX_UPDATE_SEL, 0 != (nEnableFlags & ENABLE_UPDATE_SEL));
     339             : 
     340           0 :         pSubPop1->InsertItem(CTX_INSERT_ANY_INDEX, aContextStrings[ST_INDEX  - ST_GLOBAL_CONTEXT_FIRST]);
     341           0 :         pSubPop1->SetHelpId(CTX_INSERT_ANY_INDEX, aHelpForMenu[CTX_INSERT_ANY_INDEX]);
     342           0 :         pSubPop1->InsertItem(CTX_INSERT_FILE, aContextStrings[ST_FILE   - ST_GLOBAL_CONTEXT_FIRST]);
     343           0 :         pSubPop1->SetHelpId(CTX_INSERT_FILE, aHelpForMenu[CTX_INSERT_FILE]);
     344           0 :         pSubPop1->InsertItem(CTX_INSERT_NEW_FILE, aContextStrings[ST_NEW_FILE   - ST_GLOBAL_CONTEXT_FIRST]);
     345           0 :         pSubPop1->SetHelpId(CTX_INSERT_NEW_FILE, aHelpForMenu[CTX_INSERT_NEW_FILE]);
     346           0 :         pSubPop1->InsertItem(CTX_INSERT_TEXT, aContextStrings[ST_TEXT   - ST_GLOBAL_CONTEXT_FIRST]);
     347           0 :         pSubPop1->SetHelpId(CTX_INSERT_TEXT, aHelpForMenu[CTX_INSERT_TEXT]);
     348             : 
     349             : 
     350           0 :         pPop->InsertItem(CTX_UPDATE, aContextStrings[ST_UPDATE - ST_GLOBAL_CONTEXT_FIRST]);
     351           0 :         pPop->SetHelpId(CTX_UPDATE, aHelpForMenu[CTX_UPDATE]);
     352           0 :         pPop->InsertItem(CTX_EDIT, aContextStrings[ST_EDIT_CONTENT - ST_GLOBAL_CONTEXT_FIRST]);
     353           0 :         pPop->SetHelpId(CTX_EDIT, aHelpForMenu[CTX_EDIT]);
     354           0 :         if(nEnableFlags&ENABLE_EDIT_LINK)
     355             :         {
     356           0 :             pPop->InsertItem(CTX_EDIT_LINK, aContextStrings[ST_EDIT_LINK - ST_GLOBAL_CONTEXT_FIRST]);
     357           0 :             pPop->SetHelpId(CTX_EDIT_LINK, aHelpForMenu[CTX_EDIT_LINK]);
     358             :         }
     359           0 :         pPop->InsertItem(CTX_INSERT, aContextStrings[ST_INSERT - ST_GLOBAL_CONTEXT_FIRST]);
     360           0 :         pPop->SetHelpId(CTX_INSERT, aHelpForMenu[CTX_INSERT]);
     361           0 :         pPop->InsertSeparator() ;
     362           0 :         pPop->InsertItem(CTX_DELETE, aContextStrings[ST_DELETE - ST_GLOBAL_CONTEXT_FIRST]);
     363           0 :         pPop->SetHelpId(CTX_DELETE, aHelpForMenu[CTX_DELETE]);
     364             : 
     365             :         //disabling if applicable
     366           0 :         pSubPop1->EnableItem(CTX_INSERT_ANY_INDEX,  0 != (nEnableFlags & ENABLE_INSERT_IDX ));
     367           0 :         pSubPop1->EnableItem(CTX_INSERT_TEXT,       0 != (nEnableFlags & ENABLE_INSERT_TEXT));
     368           0 :         pSubPop1->EnableItem(CTX_INSERT_FILE,       0 != (nEnableFlags & ENABLE_INSERT_FILE));
     369           0 :         pSubPop1->EnableItem(CTX_INSERT_NEW_FILE,   0 != (nEnableFlags & ENABLE_INSERT_FILE));
     370             : 
     371           0 :         pPop->EnableItem(CTX_UPDATE,    0 != (nEnableFlags & ENABLE_UPDATE));
     372           0 :         pPop->EnableItem(CTX_INSERT,    0 != (nEnableFlags & ENABLE_INSERT_IDX));
     373           0 :         pPop->EnableItem(CTX_EDIT,      0 != (nEnableFlags & ENABLE_EDIT));
     374           0 :         pPop->EnableItem(CTX_DELETE,    0 != (nEnableFlags & ENABLE_DELETE));
     375             : 
     376             : 
     377           0 :         pPop->SetPopupMenu( CTX_INSERT, pSubPop1 );
     378           0 :         pPop->SetPopupMenu( CTX_UPDATE, pSubPop2 );
     379             :     }
     380           0 :     return pPop;
     381             : }
     382             : 
     383           0 : void SwGlobalTree::TbxMenuHdl(sal_uInt16 nTbxId, ToolBox* pBox)
     384             : {
     385           0 :     sal_uInt16 nEnableFlags = GetEnableFlags();
     386           0 :     if(FN_GLOBAL_OPEN == nTbxId)
     387             :     {
     388           0 :         PopupMenu *pMenu = new PopupMenu;
     389           0 :         for (sal_uInt16 i = CTX_INSERT_ANY_INDEX; i <= CTX_INSERT_TEXT; i++)
     390             :         {
     391           0 :             pMenu->InsertItem( i, aContextStrings[ST_INDEX  - ST_GLOBAL_CONTEXT_FIRST - CTX_INSERT_ANY_INDEX + i] );
     392           0 :             pMenu->SetHelpId(i, aHelpForMenu[i] );
     393             :         }
     394           0 :         pMenu->EnableItem(CTX_INSERT_ANY_INDEX, 0 != (nEnableFlags & ENABLE_INSERT_IDX ));
     395           0 :         pMenu->EnableItem(CTX_INSERT_TEXT,      0 != (nEnableFlags & ENABLE_INSERT_TEXT));
     396           0 :         pMenu->EnableItem(CTX_INSERT_FILE,      0 != (nEnableFlags & ENABLE_INSERT_FILE));
     397           0 :         pMenu->EnableItem(CTX_INSERT_NEW_FILE,  0 != (nEnableFlags & ENABLE_INSERT_FILE));
     398           0 :         pMenu->SetSelectHdl(LINK(this, SwGlobalTree, PopupHdl));
     399           0 :         pMenu->Execute( pBox, pBox->GetItemRect(nTbxId).BottomLeft());
     400           0 :         delete pMenu;
     401           0 :         pBox->EndSelection();
     402           0 :         pBox->Invalidate();
     403             :     }
     404           0 :     else if(FN_GLOBAL_UPDATE == nTbxId)
     405             :     {
     406           0 :         PopupMenu *pMenu = new PopupMenu;
     407           0 :         for (sal_uInt16 i = CTX_UPDATE_SEL; i <= CTX_UPDATE_ALL; i++)
     408             :         {
     409           0 :             pMenu->InsertItem( i, aContextStrings[ST_UPDATE_SEL - ST_GLOBAL_CONTEXT_FIRST - CTX_UPDATE_SEL+ i] );
     410           0 :             pMenu->SetHelpId(i, aHelpForMenu[i] );
     411             :         }
     412           0 :         pMenu->EnableItem(CTX_UPDATE_SEL, 0 != (nEnableFlags & ENABLE_UPDATE_SEL));
     413           0 :         pMenu->SetSelectHdl(LINK(this, SwGlobalTree, PopupHdl));
     414           0 :         pMenu->Execute( pBox, pBox->GetItemRect(nTbxId).BottomLeft());
     415           0 :         delete pMenu;
     416           0 :         pBox->EndSelection();
     417           0 :         pBox->Invalidate();
     418             :     }
     419           0 : }
     420             : 
     421           0 : sal_uInt16  SwGlobalTree::GetEnableFlags() const
     422             : {
     423           0 :     SvTreeListEntry* pEntry = FirstSelected();
     424           0 :     sal_uInt16 nSelCount = (sal_uInt16)GetSelectionCount();
     425           0 :     sal_uInt16 nEntryCount = (sal_uInt16)GetEntryCount();
     426           0 :     SvTreeListEntry* pPrevEntry = pEntry ? Prev(pEntry) : 0;
     427             : 
     428           0 :     sal_uInt16 nRet = 0;
     429           0 :     if(nSelCount == 1 || !nEntryCount)
     430           0 :         nRet |= ENABLE_INSERT_IDX|ENABLE_INSERT_FILE;
     431           0 :     if(nSelCount == 1)
     432             :     {
     433           0 :         nRet |= ENABLE_EDIT;
     434           0 :         if( ((SwGlblDocContent*)pEntry->GetUserData())->GetType() != GLBLDOC_UNKNOWN &&
     435           0 :                     (!pPrevEntry || ((SwGlblDocContent*)pPrevEntry->GetUserData())->GetType() != GLBLDOC_UNKNOWN))
     436           0 :             nRet |= ENABLE_INSERT_TEXT;
     437           0 :         if( GLBLDOC_SECTION == ((SwGlblDocContent*)pEntry->GetUserData())->GetType() )
     438           0 :             nRet |= ENABLE_EDIT_LINK;
     439             :     }
     440           0 :     else if(!nEntryCount)
     441             :     {
     442           0 :         nRet |= ENABLE_INSERT_TEXT;
     443             :     }
     444           0 :     if(nEntryCount)
     445           0 :         nRet |= ENABLE_UPDATE|ENABLE_DELETE;
     446           0 :     if(nSelCount)
     447           0 :         nRet |= ENABLE_UPDATE_SEL;
     448           0 :     return nRet;
     449             : }
     450             : 
     451           0 : void     SwGlobalTree::RequestHelp( const HelpEvent& rHEvt )
     452             : {
     453           0 :     bool bParent = true;
     454           0 :     Update(sal_True);
     455           0 :     Display(true);
     456           0 :     if( rHEvt.GetMode() & HELPMODE_QUICK )
     457             :     {
     458           0 :         Point aPos( ScreenToOutputPixel( rHEvt.GetMousePosPixel() ));
     459           0 :         SvTreeListEntry* pEntry = GetEntry( aPos );
     460             :         const SwGlblDocContent* pCont = pEntry ?
     461           0 :                             (const SwGlblDocContent*)pEntry->GetUserData() : 0;
     462           0 :         if( pCont &&  GLBLDOC_SECTION == pCont->GetType())
     463             :         {
     464           0 :             bParent = false;
     465             :             SvLBoxTab* pTab;
     466           0 :             SvLBoxItem* pItem = GetItem( pEntry, aPos.X(), &pTab );
     467           0 :             if (pItem && SV_ITEM_ID_LBOXSTRING == pItem->GetType())
     468             :             {
     469           0 :                 const SwSection* pSect = pCont->GetSection();
     470           0 :                 String sEntry = pSect->GetLinkFileName().GetToken(0, sfx2::cTokenSeparator);
     471           0 :                 if(!pSect->IsConnectFlag())
     472           0 :                     sEntry.Insert(aContextStrings[ST_BROKEN_LINK - ST_GLOBAL_CONTEXT_FIRST], 0 );
     473           0 :                 Point aEntryPos = GetEntryPosition( pEntry );
     474             : 
     475           0 :                 aEntryPos.X() = GetTabPos( pEntry, pTab );
     476           0 :                 Size aSize( pItem->GetSize( this, pEntry ) );
     477             : 
     478           0 :                 if((aEntryPos.X() + aSize.Width()) > GetSizePixel().Width())
     479           0 :                     aSize.Width() = GetSizePixel().Width() - aEntryPos.X();
     480             : 
     481           0 :                 aEntryPos = OutputToScreenPixel(aEntryPos);
     482           0 :                 Rectangle aItemRect( aEntryPos, aSize );
     483           0 :                 if(Help::IsBalloonHelpEnabled())
     484             :                 {
     485           0 :                     aEntryPos.X() += aSize.Width();
     486           0 :                     Help::ShowBalloon( this, aEntryPos, aItemRect, sEntry );
     487             :                 }
     488             :                 else
     489             :                     Help::ShowQuickHelp( this, aItemRect, sEntry,
     490           0 :                         QUICKHELP_LEFT|QUICKHELP_VCENTER );
     491             :             }
     492             :         }
     493             :     }
     494             : 
     495           0 :     if(bParent)
     496           0 :         SvTreeListBox::RequestHelp(rHEvt);
     497           0 : }
     498             : 
     499           0 : void     SwGlobalTree::SelectHdl()
     500             : {
     501             : 
     502           0 :     sal_uInt16 nSelCount = (sal_uInt16)GetSelectionCount();
     503           0 :     SvTreeListEntry* pSel = FirstSelected();
     504           0 :     sal_uInt16 nAbsPos = pSel ? (sal_uInt16)GetModel()->GetAbsPos(pSel) : 0;
     505           0 :     SwNavigationPI* pNavi = GetParentWindow();
     506           0 :     bool bReadonly = !pActiveShell ||
     507           0 :                 pActiveShell->GetView().GetDocShell()->IsReadOnly();
     508           0 :     pNavi->aGlobalToolBox.EnableItem(FN_GLOBAL_EDIT,  nSelCount == 1 && !bReadonly);
     509           0 :     pNavi->aGlobalToolBox.EnableItem(FN_GLOBAL_OPEN,  nSelCount <= 1 && !bReadonly);
     510           0 :     pNavi->aGlobalToolBox.EnableItem(FN_GLOBAL_UPDATE,  GetEntryCount() > 0 && !bReadonly);
     511             :     pNavi->aGlobalToolBox.EnableItem(FN_ITEM_UP,
     512           0 :                     nSelCount == 1 && nAbsPos && !bReadonly);
     513             :     pNavi->aGlobalToolBox.EnableItem(FN_ITEM_DOWN,
     514           0 :                     nSelCount == 1 && nAbsPos < ((sal_uInt16)GetEntryCount()) - 1 && !bReadonly);
     515             : 
     516           0 : }
     517             : 
     518           0 : void     SwGlobalTree::DeselectHdl()
     519             : {
     520           0 :     SelectHdl();
     521           0 : }
     522             : 
     523           0 : DragDropMode SwGlobalTree::NotifyStartDrag( TransferDataContainer& ,
     524             :                                                 SvTreeListEntry* pEntry )
     525             : {
     526           0 :     bIsInternalDrag = true;
     527           0 :     pDDSource = pEntry;
     528           0 :     return SV_DRAGDROP_CTRL_MOVE;
     529             : }
     530             : 
     531           0 : sal_IntPtr SwGlobalTree::GetTabPos( SvTreeListEntry*, SvLBoxTab* pTab)
     532             : {
     533           0 :     return pTab->GetPos() - GLBL_TABPOS_SUB;
     534             : }
     535             : 
     536           0 : sal_Bool     SwGlobalTree::NotifyMoving(   SvTreeListEntry*  pTarget,
     537             :                                         SvTreeListEntry*  pSource,
     538             :                                         SvTreeListEntry*&,
     539             :                                         sal_uLong&
     540             :                                     )
     541             : {
     542           0 :     SvTreeList* _pModel = GetModel();
     543           0 :     sal_uInt16 nSource = (sal_uInt16) _pModel->GetAbsPos(pSource);
     544           0 :     sal_uInt16 nDest   = pTarget ? (sal_uInt16) _pModel->GetAbsPos(pTarget) : pSwGlblDocContents->size();
     545             : 
     546           0 :     if( pActiveShell->MoveGlobalDocContent(
     547           0 :             *pSwGlblDocContents, nSource, nSource + 1, nDest ) &&
     548           0 :             Update( sal_False ))
     549           0 :         Display();
     550           0 :     return sal_False;
     551             : }
     552             : 
     553           0 : sal_Bool     SwGlobalTree::NotifyCopying(  SvTreeListEntry*  /*pTarget*/,
     554             :                                         SvTreeListEntry*  /*pEntry*/,
     555             :                                         SvTreeListEntry*& /*rpNewParent*/,
     556             :                                         sal_uLong&        /*rNewChildPos*/
     557             :                                     )
     558             : {
     559           0 :     return sal_False;
     560             : }
     561             : 
     562           0 : sal_Bool SwGlobalTree::NotifyAcceptDrop( SvTreeListEntry* pEntry)
     563             : {
     564           0 :     return pEntry != 0;
     565             : }
     566             : 
     567           0 : void SwGlobalTree::StartDrag( sal_Int8 nAction, const Point& rPt )
     568             : {
     569           0 :     if( 1 == GetSelectionCount() )
     570           0 :         SvTreeListBox::StartDrag( nAction, rPt );
     571           0 : }
     572             : 
     573           0 : void SwGlobalTree::DragFinished( sal_Int8 nAction )
     574             : {
     575           0 :     SvTreeListBox::DragFinished( nAction );
     576           0 :     bIsInternalDrag = false;
     577           0 : }
     578             : 
     579             : // If a Ctrl+DoubleClick is executed in an empty area,
     580             : // then the base function of the control should be called.
     581             : 
     582           0 : void  SwGlobalTree::MouseButtonDown( const MouseEvent& rMEvt )
     583             : {
     584           0 :     Point aPos( rMEvt.GetPosPixel());
     585           0 :     SvTreeListEntry* pEntry = GetEntry( aPos, sal_True );
     586           0 :     if( !pEntry && rMEvt.IsLeft() && rMEvt.IsMod1() && (rMEvt.GetClicks() % 2) == 0)
     587           0 :         Control::MouseButtonDown( rMEvt );
     588             :     else
     589           0 :         SvTreeListBox::MouseButtonDown( rMEvt );
     590           0 : }
     591             : 
     592           0 : void     SwGlobalTree::GetFocus()
     593             : {
     594           0 :     if(Update( sal_False ))
     595           0 :         Display();
     596           0 :     SvTreeListBox::GetFocus();
     597           0 : }
     598             : 
     599           0 : void     SwGlobalTree::KeyInput(const KeyEvent& rKEvt)
     600             : {
     601           0 :     const KeyCode aCode = rKEvt.GetKeyCode();
     602           0 :     if(aCode.GetCode() == KEY_RETURN)
     603             :     {
     604           0 :         switch(aCode.GetModifier())
     605             :         {
     606             :             case KEY_MOD2:
     607             :                 // Switch boxes
     608           0 :                 GetParentWindow()->ToggleTree();
     609           0 :             break;
     610             :         }
     611             :     }
     612             :     else
     613           0 :         SvTreeListBox::KeyInput(rKEvt);
     614           0 : }
     615             : 
     616           0 : void SwGlobalTree::Clear()
     617             : {
     618           0 :     pEmphasisEntry = 0;
     619           0 :     SvTreeListBox::Clear();
     620           0 : }
     621             : 
     622           0 : void    SwGlobalTree::Display(bool bOnlyUpdateUserData)
     623             : {
     624           0 :     if(!bIsImageListInitialized)
     625             :     {
     626           0 :         aEntryImages = ImageList(SW_RES(IMG_NAVI_ENTRYBMP));
     627           0 :         bIsImageListInitialized = true;
     628             :     }
     629           0 :     sal_uInt16 nCount = pSwGlblDocContents->size();
     630           0 :     if(bOnlyUpdateUserData && GetEntryCount() == pSwGlblDocContents->size())
     631             :     {
     632           0 :         SvTreeListEntry* pEntry = First();
     633           0 :         for( sal_uInt16 i = 0; i < nCount; i++)
     634             :         {
     635           0 :             SwGlblDocContent* pCont = (*pSwGlblDocContents)[i];
     636           0 :             pEntry->SetUserData(pCont);
     637           0 :             pEntry = Next(pEntry);
     638             :         }
     639             :     }
     640             :     else
     641             :     {
     642           0 :         SetUpdateMode( sal_False );
     643           0 :         SvTreeListEntry* pOldSelEntry = FirstSelected();
     644           0 :         String sEntryName;  // Name of the entry
     645           0 :         sal_uInt16 nSelPos = USHRT_MAX;
     646           0 :         if(pOldSelEntry)
     647             :         {
     648           0 :             sEntryName = GetEntryText(pOldSelEntry);
     649           0 :             nSelPos = (sal_uInt16)GetModel()->GetAbsPos(pOldSelEntry);
     650             :         }
     651           0 :         Clear();
     652           0 :         if(!pSwGlblDocContents)
     653           0 :             Update( sal_False );
     654             : 
     655           0 :         SvTreeListEntry* pSelEntry = 0;
     656           0 :         for( sal_uInt16 i = 0; i < nCount; i++)
     657             :         {
     658           0 :             SwGlblDocContent* pCont = (*pSwGlblDocContents)[i];
     659           0 :             String sEntry;
     660           0 :             Image aImage;
     661           0 :             switch( pCont->GetType()  )
     662             :             {
     663             :                 case GLBLDOC_UNKNOWN:
     664             :                 {
     665           0 :                     sEntry = aContextStrings[ST_TEXT   - ST_GLOBAL_CONTEXT_FIRST];
     666           0 :                     aImage = aEntryImages.GetImage(SID_SW_START + GLOBAL_CONTENT_TEXT);
     667             :                 }
     668           0 :                 break;
     669             :                 case GLBLDOC_TOXBASE:
     670             :                 {
     671           0 :                     const SwTOXBase* pBase = pCont->GetTOX();
     672           0 :                     sEntry = pBase->GetTitle();
     673           0 :                     aImage = aEntryImages.GetImage(SID_SW_START + CONTENT_TYPE_INDEX);
     674             :                 }
     675           0 :                 break;
     676             :                 case GLBLDOC_SECTION:
     677             :                 {
     678           0 :                     const SwSection* pSect = pCont->GetSection();
     679           0 :                     sEntry = pSect->GetSectionName();
     680           0 :                     aImage = aEntryImages.GetImage(SID_SW_START + CONTENT_TYPE_REGION);
     681             :                 }
     682           0 :                 break;
     683             :             }
     684             :             SvTreeListEntry* pEntry = InsertEntry(sEntry, aImage, aImage,
     685           0 :                         0, sal_False, LIST_APPEND, pCont);
     686           0 :             if(sEntry == sEntryName)
     687             :             {
     688           0 :                 pSelEntry = pEntry;
     689             :             }
     690           0 :         }
     691           0 :         if(pSelEntry)
     692             :         {
     693           0 :             Select(pSelEntry);
     694             :         }
     695           0 :         else if(nSelPos != USHRT_MAX && nSelPos < nCount)
     696             :         {
     697           0 :             Select(GetEntry(nSelPos));
     698             :         }
     699           0 :         else if(nCount)
     700           0 :             Select(First());
     701             :         else
     702           0 :             SelectHdl();
     703           0 :         SetUpdateMode( sal_True );
     704             :     }
     705           0 : }
     706             : 
     707           0 : void SwGlobalTree::InsertRegion( const SwGlblDocContent* pCont, const String* pFileName )
     708             : {
     709           0 :     Sequence< OUString > aFileNames;
     710           0 :     if ( !pFileName )
     711             :     {
     712           0 :         pDefParentWin = Application::GetDefDialogParent();
     713           0 :         Application::SetDefDialogParent( this );
     714           0 :         delete pDocInserter;
     715             :         pDocInserter = new ::sfx2::DocumentInserter(
     716           0 :                 OUString("swriter"), true );
     717           0 :         pDocInserter->StartExecuteModal( LINK( this, SwGlobalTree, DialogClosedHdl ) );
     718             :     }
     719           0 :     else if ( pFileName->Len() )
     720             :     {
     721           0 :         aFileNames.realloc(1);
     722           0 :         INetURLObject aFileName;
     723           0 :         aFileName.SetSmartURL( *pFileName );
     724           0 :         aFileNames.getArray()[0] = aFileName.GetMainURL( INetURLObject::NO_DECODE );
     725           0 :         InsertRegion( pCont, aFileNames );
     726           0 :     }
     727           0 : }
     728             : 
     729           0 : void    SwGlobalTree::EditContent(const SwGlblDocContent* pCont )
     730             : {
     731           0 :     sal_uInt16 nSlot = 0;
     732           0 :     switch( pCont->GetType() )
     733             :     {
     734             :         case GLBLDOC_UNKNOWN:
     735           0 :             pActiveShell->GetView().GetEditWin().GrabFocus();
     736           0 :         break;
     737             :         case GLBLDOC_TOXBASE:
     738             :         {
     739           0 :             const SwTOXBase* pBase = pCont->GetTOX();
     740           0 :             if(pBase)
     741           0 :                 nSlot = FN_INSERT_MULTI_TOX;
     742             :         }
     743           0 :         break;
     744             :         case GLBLDOC_SECTION:
     745             :         {
     746           0 :             OpenDoc(pCont);
     747             : 
     748           0 :             nSlot = 0;
     749           0 :             pCont = 0;
     750             :         }
     751           0 :         break;
     752             :     }
     753           0 :     if(pCont)
     754           0 :         GotoContent(pCont);
     755           0 :     if(nSlot)
     756             :     {
     757           0 :         pActiveShell->GetView().GetViewFrame()->GetDispatcher()->Execute(nSlot);
     758           0 :         if(Update( sal_False ))
     759           0 :             Display();
     760             :     }
     761           0 : }
     762             : 
     763           0 : IMPL_LINK( SwGlobalTree, PopupHdl, Menu* , pMenu)
     764             : {
     765           0 :     ExcecuteContextMenuAction( pMenu->GetCurItemId());
     766           0 :     return sal_True;
     767             : }
     768             : 
     769           0 : void    SwGlobalTree::ExcecuteContextMenuAction( sal_uInt16 nSelectedPopupEntry )
     770             : {
     771           0 :     SvTreeListEntry* pEntry = FirstSelected();
     772           0 :     SwGlblDocContent* pCont = pEntry ? (SwGlblDocContent*)pEntry->GetUserData() : 0;
     773             :     // If a RequestHelp is called during the dialogue,
     774             :     // then the content gets lost. Because of that a copy
     775             :     // is created in which only the DocPos is set correctly.
     776           0 :     SwGlblDocContent* pContCopy = 0;
     777           0 :     if(pCont)
     778           0 :         pContCopy = new SwGlblDocContent(pCont->GetDocPos());
     779           0 :     SfxDispatcher& rDispatch = *pActiveShell->GetView().GetViewFrame()->GetDispatcher();
     780           0 :     sal_uInt16 nSlot = 0;
     781           0 :     bool bDeleteContentCopy = true;
     782           0 :     switch( nSelectedPopupEntry )
     783             :     {
     784             :         case CTX_UPDATE_SEL:
     785             :         {
     786             :             // Two passes: first update the areas, then the directories.
     787           0 :             SvTreeListEntry* pSelEntry = FirstSelected();
     788           0 :             while( pSelEntry )
     789             :             {
     790           0 :                 SwGlblDocContent* pContent = (SwGlblDocContent*)pSelEntry->GetUserData();
     791           0 :                 if(GLBLDOC_SECTION == pContent->GetType() &&
     792           0 :                     pContent->GetSection()->IsConnected())
     793             :                 {
     794           0 :                     ((SwSection*)pContent->GetSection())->UpdateNow();
     795             :                 }
     796             : 
     797           0 :                 pSelEntry = NextSelected(pSelEntry);
     798             :             }
     799           0 :             pSelEntry = FirstSelected();
     800           0 :             while( pSelEntry )
     801             :             {
     802           0 :                 SwGlblDocContent* pContent = (SwGlblDocContent*)pSelEntry->GetUserData();
     803           0 :                 if(GLBLDOC_TOXBASE == pContent->GetType())
     804           0 :                     pActiveShell->UpdateTableOf(*pContent->GetTOX());
     805           0 :                 pSelEntry = NextSelected(pSelEntry);
     806             :             }
     807             : 
     808             :         }
     809           0 :         break;
     810             :         case CTX_UPDATE_INDEX:
     811             :         {
     812           0 :             nSlot = FN_UPDATE_TOX;
     813             :         }
     814           0 :         break;
     815             :         case CTX_UPDATE_LINK:
     816             :         case CTX_UPDATE_ALL:
     817             :         {
     818           0 :             pActiveShell->GetLinkManager().UpdateAllLinks(true);
     819           0 :             if(CTX_UPDATE_ALL == nSelectedPopupEntry)
     820           0 :                 nSlot = FN_UPDATE_TOX;
     821           0 :             pCont = 0;
     822             :         }
     823           0 :         break;
     824             :         case CTX_EDIT:
     825             :         {
     826             :             OSL_ENSURE(pCont, "edit without entry ? " );
     827           0 :             EditContent(pCont);
     828             :         }
     829           0 :         break;
     830             :         case CTX_EDIT_LINK:
     831             :         {
     832             :             OSL_ENSURE(pCont, "edit without entry ? " );
     833             :             SfxStringItem aName(FN_EDIT_REGION,
     834           0 :                     pCont->GetSection()->GetSectionName());
     835           0 :             rDispatch.Execute(FN_EDIT_REGION, SFX_CALLMODE_ASYNCHRON, &aName, 0L);
     836             :         }
     837           0 :         break;
     838             :         case CTX_DELETE:
     839             :         {
     840             :             // If several entries selected, then after each delete the array
     841             :             // must be refilled. So you do not have to remember anything,
     842             :             // deleting begins at the end.
     843           0 :             SvTreeListEntry* pSelEntry = LastSelected();
     844           0 :             SwGlblDocContents* pTempContents  = 0;
     845           0 :             pActiveShell->StartAction();
     846           0 :             while(pSelEntry)
     847             :             {
     848             :                 pActiveShell->DeleteGlobalDocContent(
     849             :                     pTempContents ? *pTempContents : *pSwGlblDocContents,
     850           0 :                                      (sal_uInt16)GetModel()->GetAbsPos(pSelEntry));
     851           0 :                 pSelEntry = PrevSelected(pSelEntry);
     852           0 :                 if(pSelEntry)
     853             :                 {
     854           0 :                     pTempContents = new SwGlblDocContents;
     855           0 :                     pActiveShell->GetGlobalDocContent(*pTempContents);
     856             :                 }
     857             :             }
     858           0 :             delete pTempContents;
     859           0 :             pActiveShell->EndAction();
     860           0 :             pCont = 0;
     861             :         }
     862           0 :         break;
     863             :         case CTX_INSERT_ANY_INDEX:
     864             :         {
     865           0 :             if(pContCopy)
     866             :             {
     867           0 :                 SfxItemSet aSet(pActiveShell->GetView().GetPool(),
     868             :                             RES_COL, RES_COL,
     869             :                             RES_BACKGROUND, RES_BACKGROUND,
     870             :                             RES_FRM_SIZE, RES_FRM_SIZE,
     871             :                             SID_ATTR_PAGE_SIZE, SID_ATTR_PAGE_SIZE,
     872             :                             RES_LR_SPACE, RES_LR_SPACE,
     873             :                             FN_PARAM_TOX_TYPE, FN_PARAM_TOX_TYPE,
     874           0 :                             0);
     875             : 
     876           0 :                 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
     877             :                 OSL_ENSURE(pFact, "Dialogdiet fail!");
     878             :                 AbstractMultiTOXTabDialog* pDlg = pFact->CreateMultiTOXTabDialog( DLG_MULTI_TOX,
     879             :                                                         this, aSet,
     880             :                                                         *pActiveShell,
     881             :                                                         0,
     882             :                                                         USHRT_MAX,
     883           0 :                                                         sal_True);
     884             :                 OSL_ENSURE(pDlg, "Dialogdiet fail!");
     885           0 :                 if(RET_OK == pDlg->Execute())
     886             :                 {
     887             :                     SwTOXDescription&  rDesc = pDlg->GetTOXDescription(
     888           0 :                                                 pDlg->GetCurrentTOXType());
     889           0 :                     SwTOXMgr aMgr(pActiveShell);
     890           0 :                     SwTOXBase* pToInsert = 0;
     891           0 :                     if(aMgr.UpdateOrInsertTOX(rDesc, &pToInsert, pDlg->GetOutputItemSet()))
     892           0 :                         pActiveShell->InsertGlobalDocContent( *pContCopy, *pToInsert );
     893             :                 }
     894           0 :                 pCont = 0;
     895           0 :                 delete pDlg;
     896             :             }
     897             :         }
     898           0 :         break;
     899             :         case CTX_INSERT_FILE:
     900             :         {
     901           0 :             bDeleteContentCopy = false;
     902           0 :             pDocContent = pContCopy;
     903           0 :             InsertRegion( pContCopy );
     904           0 :             pCont = NULL;
     905             :         }
     906           0 :         break;
     907             :         case CTX_INSERT_NEW_FILE:
     908             :         {
     909           0 :             SfxViewFrame* pGlobFrm = pActiveShell->GetView().GetViewFrame();
     910           0 :             SwGlobalFrameListener_Impl aFrmListener(*pGlobFrm);
     911             : 
     912           0 :             sal_uLong nEntryPos = pEntry ? GetModel()->GetAbsPos(pEntry) : (sal_uLong)-1;
     913             :             // Creating a new doc
     914             :             SfxStringItem aFactory(SID_NEWDOCDIRECT,
     915           0 :                             SwDocShell::Factory().GetFilterContainer()->GetName());
     916             : 
     917             :              const SfxFrameItem* pItem = (SfxFrameItem*)
     918             :                             rDispatch.Execute(SID_NEWDOCDIRECT,
     919           0 :                                 SFX_CALLMODE_SYNCHRON, &aFactory, 0L);
     920             : 
     921             :             // save at
     922           0 :             SfxFrame* pFrm = pItem ? pItem->GetFrame() : 0;
     923           0 :             SfxViewFrame* pFrame = pFrm ? pFrm->GetCurrentViewFrame() : 0;
     924           0 :             if( pFrame )
     925             :             {
     926             :                 const SfxBoolItem* pBool = (const SfxBoolItem*)
     927             :                         pFrame->GetDispatcher()->Execute(
     928           0 :                                 SID_SAVEASDOC, SFX_CALLMODE_SYNCHRON );
     929           0 :                 SfxObjectShell& rObj = *pFrame->GetObjectShell();
     930           0 :                 const SfxMedium* pMedium = rObj.GetMedium();
     931           0 :                 String sNewFile(pMedium->GetURLObject().GetMainURL(INetURLObject::DECODE_TO_IURI));
     932             :                 // Insert the area with the Doc-Name
     933             :                 // Bring the own Doc in the foreground
     934           0 :                 if(aFrmListener.IsValid() && sNewFile.Len())
     935             :                 {
     936           0 :                     pGlobFrm->ToTop();
     937             :                     // Due to the update the entries are invalid
     938           0 :                     if(nEntryPos != (sal_uLong)-1)
     939             :                     {
     940           0 :                         Update( sal_False );
     941           0 :                         Display();
     942           0 :                         Select(GetModel()->GetEntryAtAbsPos(nEntryPos));
     943           0 :                         pEntry = FirstSelected();
     944           0 :                         pCont = pEntry ? (SwGlblDocContent*)pEntry->GetUserData() : 0;
     945             :                     }
     946             :                     else
     947             :                     {
     948           0 :                         pEntry = 0;
     949           0 :                         pCont = 0;
     950             :                     }
     951           0 :                     if(pBool->GetValue())
     952             :                     {
     953           0 :                         InsertRegion(pCont, &sNewFile);
     954           0 :                         pFrame->ToTop();
     955             :                     }
     956             :                     else
     957             :                         pFrame->GetDispatcher()->Execute(SID_CLOSEWIN,
     958           0 :                                                 SFX_CALLMODE_SYNCHRON);
     959             :                 }
     960             :                 else
     961             :                 {
     962           0 :                     pFrame->ToTop();
     963           0 :                     return;
     964           0 :                 }
     965           0 :             }
     966             :         }
     967           0 :         break;
     968             :         case CTX_INSERT_TEXT:
     969             :         {
     970           0 :             if(pCont)
     971           0 :                 pActiveShell->InsertGlobalDocContent(*pCont);
     972             :             else
     973             :             {
     974           0 :                 pActiveShell->SplitNode(); // Empty document
     975           0 :                 pActiveShell->Up( sal_False, 1 );
     976             :             }
     977           0 :             pActiveShell->GetView().GetEditWin().GrabFocus();
     978             :         }
     979           0 :         break;
     980             :         case CTX_UPDATE:
     981           0 :             pCont = 0;
     982           0 :         break;
     983             :         default:;
     984             :         // here nothing happens
     985             :     }
     986           0 :     if(pCont)
     987           0 :         GotoContent(pCont);
     988           0 :     if(nSlot)
     989           0 :         rDispatch.Execute(nSlot);
     990           0 :     if(Update( sal_False ))
     991           0 :         Display();
     992           0 :     if ( bDeleteContentCopy )
     993           0 :         delete pContCopy;
     994             :     else
     995           0 :         bDeleteContentCopy = true;
     996             : }
     997             : 
     998           0 : IMPL_LINK_NOARG(SwGlobalTree, Timeout)
     999             : {
    1000           0 :     if(!HasFocus() && Update( sal_False ))
    1001           0 :         Display();
    1002           0 :     return 0;
    1003             : }
    1004             : 
    1005           0 : void SwGlobalTree::GotoContent(const SwGlblDocContent* pCont)
    1006             : {
    1007           0 :     pActiveShell->EnterStdMode();
    1008             : 
    1009           0 :     switch( pCont->GetType()  )
    1010             :     {
    1011             :         case GLBLDOC_UNKNOWN:
    1012           0 :             pActiveShell->GotoGlobalDocContent(*pCont);
    1013           0 :         break;
    1014             :         case GLBLDOC_TOXBASE:
    1015             :         {
    1016           0 :             String sName = pCont->GetTOX()->GetTOXName();
    1017           0 :             if (!pActiveShell->GotoNextTOXBase(&sName))
    1018           0 :                 pActiveShell->GotoPrevTOXBase(&sName);
    1019             :         }
    1020           0 :         break;
    1021             :         case GLBLDOC_SECTION:
    1022           0 :         break;
    1023             :     }
    1024             : 
    1025           0 : }
    1026             : 
    1027           0 : void    SwGlobalTree::ShowTree()
    1028             : {
    1029           0 :     aUpdateTimer.Start();
    1030           0 :     SvTreeListBox::Show();
    1031           0 : }
    1032             : 
    1033           0 : void    SwGlobalTree::HideTree()
    1034             : {
    1035           0 :     aUpdateTimer.Stop();
    1036           0 :     SvTreeListBox::Hide();
    1037           0 : }
    1038             : 
    1039           0 : void    SwGlobalTree::ExecCommand(sal_uInt16 nCmd)
    1040             : {
    1041           0 :     SvTreeListEntry* pEntry = FirstSelected();
    1042             :     OSL_ENSURE(pEntry, "It explodes in the next moment");
    1043           0 :     if(FN_GLOBAL_EDIT == nCmd)
    1044             :     {
    1045             :         const SwGlblDocContent* pCont = (const SwGlblDocContent*)
    1046           0 :                                                 pEntry->GetUserData();
    1047           0 :         EditContent(pCont);
    1048             :     }
    1049             :     else
    1050             :     {
    1051           0 :         if(GetSelectionCount() == 1)
    1052             :         {
    1053           0 :             bool bMove = false;
    1054           0 :             sal_uInt16 nSource = (sal_uInt16)GetModel()->GetAbsPos(pEntry);
    1055           0 :             sal_uInt16 nDest = nSource;
    1056           0 :             switch(nCmd)
    1057             :             {
    1058             :                 case FN_ITEM_DOWN:
    1059             :                 {
    1060           0 :                     sal_uInt16 nEntryCount = (sal_uInt16)GetEntryCount();
    1061           0 :                     bMove = nEntryCount > nSource + 1;
    1062           0 :                     nDest+= 2;
    1063             :                 }
    1064           0 :                 break;
    1065             :                 case FN_ITEM_UP:
    1066             :                 {
    1067           0 :                     if(nSource)
    1068           0 :                         bMove = 0 != nSource;
    1069           0 :                     nDest--;
    1070             :                 }
    1071           0 :                 break;
    1072             :             }
    1073           0 :             if( bMove && pActiveShell->MoveGlobalDocContent(
    1074           0 :                 *pSwGlblDocContents, nSource, nSource + 1, nDest ) &&
    1075           0 :                     Update( sal_False ))
    1076           0 :                 Display();
    1077             :         }
    1078             :     }
    1079           0 : }
    1080             : 
    1081           0 : sal_Bool    SwGlobalTree::Update(sal_Bool bHard)
    1082             : {
    1083           0 :     SwView* pActView = GetParentWindow()->GetCreateView();
    1084           0 :     sal_Bool bRet = sal_False;
    1085           0 :     if(pActView && pActView->GetWrtShellPtr())
    1086             :     {
    1087           0 :         const SwWrtShell* pOldShell = pActiveShell;
    1088           0 :         pActiveShell = pActView->GetWrtShellPtr();
    1089           0 :         if(pActiveShell != pOldShell)
    1090             :         {
    1091           0 :             delete pSwGlblDocContents;
    1092           0 :             pSwGlblDocContents = 0;
    1093             :         }
    1094           0 :         if(!pSwGlblDocContents)
    1095             :         {
    1096           0 :             pSwGlblDocContents = new SwGlblDocContents;
    1097           0 :             bRet = sal_True;
    1098           0 :             pActiveShell->GetGlobalDocContent(*pSwGlblDocContents);
    1099             :         }
    1100             :         else
    1101             :         {
    1102           0 :             sal_Bool bCopy = sal_False;
    1103           0 :             SwGlblDocContents* pTempContents  = new SwGlblDocContents;
    1104           0 :             pActiveShell->GetGlobalDocContent(*pTempContents);
    1105           0 :             if(pTempContents->size() != pSwGlblDocContents->size() ||
    1106           0 :                     pTempContents->size() != GetEntryCount())
    1107             :             {
    1108           0 :                 bRet = sal_True;
    1109           0 :                 bCopy = sal_True;
    1110             :             }
    1111             :             else
    1112             :             {
    1113           0 :                 for(sal_uInt16 i = 0; i < pTempContents->size() && !bCopy; i++)
    1114             :                 {
    1115           0 :                     SwGlblDocContent* pLeft = (*pTempContents)[i];
    1116           0 :                     SwGlblDocContent* pRight = (*pSwGlblDocContents)[i];
    1117           0 :                     GlobalDocContentType eType = pLeft->GetType();
    1118           0 :                     SvTreeListEntry* pEntry = GetEntry(i);
    1119           0 :                     String sTemp = GetEntryText(pEntry);
    1120           0 :                     if (
    1121           0 :                          eType != pRight->GetType() ||
    1122             :                          (
    1123           0 :                            eType == GLBLDOC_SECTION &&
    1124           0 :                            pLeft->GetSection()->GetSectionName() != sTemp
    1125           0 :                          ) ||
    1126             :                          (
    1127           0 :                            eType == GLBLDOC_TOXBASE &&
    1128           0 :                            pLeft->GetTOX()->GetTitle() != sTemp
    1129             :                          )
    1130             :                        )
    1131             :                     {
    1132           0 :                         bCopy = bRet = sal_True;
    1133             :                     }
    1134           0 :                 }
    1135             :             }
    1136           0 :             if(bCopy || bHard)
    1137             :             {
    1138           0 :                 pSwGlblDocContents->DeleteAndDestroyAll();
    1139           0 :                 pSwGlblDocContents->insert( *pTempContents );
    1140           0 :                 pTempContents->clear();
    1141             : 
    1142             :             }
    1143           0 :             delete pTempContents;
    1144             :         }
    1145             : 
    1146             :     }
    1147             :     else
    1148             :     {
    1149           0 :         Clear();
    1150           0 :         if(pSwGlblDocContents)
    1151           0 :             pSwGlblDocContents->DeleteAndDestroyAll();
    1152             :     }
    1153             :     // FIXME: Implement a test for changes!
    1154           0 :     return bRet;
    1155             : }
    1156             : 
    1157           0 : void SwGlobalTree::OpenDoc(const SwGlblDocContent* pCont)
    1158             : {
    1159           0 :     String sFileName(pCont->GetSection()->GetLinkFileName().GetToken(0,
    1160           0 :             sfx2::cTokenSeparator));
    1161           0 :     bool bFound = false;
    1162           0 :     const SfxObjectShell* pCurr = SfxObjectShell::GetFirst();
    1163           0 :     while( !bFound && pCurr )
    1164             :     {
    1165           0 :         if(pCurr->GetMedium() &&
    1166           0 :             String(pCurr->GetMedium()->GetURLObject().GetMainURL(INetURLObject::DECODE_TO_IURI)) == sFileName)
    1167             :         {
    1168           0 :             bFound = true;
    1169           0 :             SwGlobalTree::SetShowShell(pCurr);
    1170             :             Application::PostUserEvent( STATIC_LINK(
    1171           0 :                         this, SwGlobalTree, ShowFrameHdl ) );
    1172           0 :             pCurr = 0;
    1173             :         }
    1174             :         else
    1175           0 :             pCurr = SfxObjectShell::GetNext(*pCurr);
    1176             :     }
    1177           0 :     if(!bFound)
    1178             :     {
    1179             :         SfxStringItem aURL(SID_FILE_NAME,
    1180           0 :             sFileName);
    1181           0 :         SfxBoolItem aReadOnly(SID_DOC_READONLY, sal_False);
    1182           0 :         SfxStringItem aTargetFrameName( SID_TARGETNAME, OUString("_blank") );
    1183           0 :         SfxStringItem aReferer(SID_REFERER, pActiveShell->GetView().GetDocShell()->GetTitle());
    1184           0 :         pActiveShell->GetView().GetViewFrame()->GetDispatcher()->
    1185             :                 Execute(SID_OPENDOC, SFX_CALLMODE_ASYNCHRON,
    1186           0 :                             &aURL, &aReadOnly, &aReferer, &aTargetFrameName, 0L);
    1187           0 :     }
    1188           0 : }
    1189             : 
    1190           0 : IMPL_LINK_NOARG( SwGlobalTree, DoubleClickHdl)
    1191             : {
    1192           0 :     SvTreeListEntry* pEntry = GetCurEntry();
    1193           0 :     SwGlblDocContent* pCont = (SwGlblDocContent*)pEntry->GetUserData();
    1194           0 :     if(pCont->GetType() == GLBLDOC_SECTION)
    1195           0 :         OpenDoc(pCont);
    1196             :     else
    1197             :     {
    1198           0 :         GotoContent(pCont);
    1199           0 :         pActiveShell->GetView().GetEditWin().GrabFocus();
    1200             :     }
    1201           0 :     return 0;
    1202             : }
    1203             : 
    1204           0 : IMPL_STATIC_LINK_NOINSTANCE(SwGlobalTree, ShowFrameHdl, SwGlobalTree*, EMPTYARG)
    1205             : {
    1206           0 :     if(SwGlobalTree::GetShowShell())
    1207           0 :         SfxViewFrame::GetFirst(SwGlobalTree::GetShowShell())->ToTop();
    1208           0 :     SwGlobalTree::SetShowShell(0);
    1209           0 :     return 0;
    1210             : }
    1211             : 
    1212           0 : void SwGlobalTree::InitEntry(SvTreeListEntry* pEntry,
    1213             :         const OUString& rStr ,const Image& rImg1,const Image& rImg2,
    1214             :         SvLBoxButtonKind eButtonKind)
    1215             : {
    1216           0 :     sal_uInt16 nColToHilite = 1; //0==Bitmap;1=="Column1";2=="Column2"
    1217           0 :     SvTreeListBox::InitEntry( pEntry, rStr, rImg1, rImg2, eButtonKind );
    1218           0 :     SvLBoxString* pCol = (SvLBoxString*)pEntry->GetItem( nColToHilite );
    1219           0 :     SwLBoxString* pStr = new SwLBoxString( pEntry, 0, pCol->GetText() );
    1220           0 :     pEntry->ReplaceItem( pStr, nColToHilite );
    1221           0 : }
    1222             : 
    1223           0 : void SwLBoxString::Paint(
    1224             :     const Point& rPos, SvTreeListBox& rDev, const SvViewDataEntry* pView,
    1225             :     const SvTreeListEntry* pEntry)
    1226             : {
    1227           0 :     SwGlblDocContent* pCont = (SwGlblDocContent*)pEntry->GetUserData();
    1228           0 :     if(pCont->GetType() == GLBLDOC_SECTION &&
    1229           0 :         !(pCont->GetSection())->IsConnectFlag() )
    1230             :     {
    1231           0 :         Font aOldFont( rDev.GetFont());
    1232           0 :         Font aFont(aOldFont);
    1233           0 :         Color aCol( COL_LIGHTRED );
    1234           0 :         aFont.SetColor( aCol );
    1235           0 :         rDev.SetFont( aFont );
    1236           0 :         rDev.DrawText( rPos, GetText() );
    1237           0 :         rDev.SetFont( aOldFont );
    1238             :     }
    1239             :     else
    1240           0 :         SvLBoxString::Paint( rPos, rDev, pView, pEntry);
    1241           0 : }
    1242             : 
    1243           0 : void    SwGlobalTree::DataChanged( const DataChangedEvent& rDCEvt )
    1244             : {
    1245           0 :     if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
    1246           0 :          (rDCEvt.GetFlags() & SETTINGS_STYLE) )
    1247             :     {
    1248           0 :         aEntryImages = ImageList(SW_RES(IMG_NAVI_ENTRYBMP));
    1249           0 :         Update(sal_True);
    1250             :     }
    1251           0 :     SvTreeListBox::DataChanged( rDCEvt );
    1252           0 : }
    1253             : 
    1254           0 : void SwGlobalTree::InsertRegion( const SwGlblDocContent* _pContent, const Sequence< OUString >& _rFiles )
    1255             : {
    1256           0 :     sal_Int32 nFiles = _rFiles.getLength();
    1257           0 :     if ( nFiles )
    1258             :     {
    1259           0 :         bool bMove = false;
    1260           0 :         if ( !_pContent )
    1261             :         {
    1262           0 :             SvTreeListEntry* pLast = (SvTreeListEntry*)LastVisible();
    1263           0 :             _pContent = (SwGlblDocContent*)pLast->GetUserData();
    1264           0 :             bMove = true;
    1265             :         }
    1266           0 :         String sFilePassword;
    1267           0 :         sal_uInt16 nEntryCount = (sal_uInt16)GetEntryCount();
    1268           0 :         const OUString* pFileNames = _rFiles.getConstArray();
    1269           0 :         SwWrtShell& rSh = GetParentWindow()->GetCreateView()->GetWrtShell();
    1270           0 :         rSh.StartAction();
    1271             :         // after insertion of the first new content the 'pCont' parameter becomes invalid
    1272             :         // find the index of the 'anchor' content to always use a current anchor content
    1273           0 :         size_t nAnchorContent = pSwGlblDocContents->size() - 1;
    1274           0 :         if ( !bMove )
    1275             :         {
    1276           0 :             for (size_t nContent = 0; nContent < pSwGlblDocContents->size();
    1277             :                     ++nContent)
    1278             :             {
    1279           0 :                 if( *_pContent == *(*pSwGlblDocContents)[ nContent ] )
    1280             :                 {
    1281           0 :                     nAnchorContent = nContent;
    1282           0 :                     break;
    1283             :                 }
    1284             :             }
    1285             :         }
    1286           0 :         SwGlblDocContents aTempContents;
    1287           0 :         for ( sal_Int32 nFile = 0; nFile < nFiles; ++nFile )
    1288             :         {
    1289             :             //update the global document content after each inserted document
    1290           0 :             rSh.GetGlobalDocContent(aTempContents);
    1291           0 :             SwGlblDocContent* pAnchorContent = 0;
    1292             :             OSL_ENSURE(aTempContents.size() > (nAnchorContent + nFile), "invalid anchor content -> last insertion failed");
    1293           0 :             if ( aTempContents.size() > (nAnchorContent + nFile) )
    1294           0 :                 pAnchorContent = aTempContents[nAnchorContent + nFile];
    1295             :             else
    1296           0 :                 pAnchorContent = aTempContents.back();
    1297           0 :             String sFileName(pFileNames[nFile]);
    1298           0 :             INetURLObject aFileUrl;
    1299           0 :             aFileUrl.SetSmartURL( sFileName );
    1300             :             String sSectionName(String(aFileUrl.GetLastName(
    1301             :                 INetURLObject::DECODE_UNAMBIGUOUS)).GetToken(0,
    1302           0 :                 sfx2::cTokenSeparator));
    1303           0 :             sal_uInt16 nSectCount = rSh.GetSectionFmtCount();
    1304           0 :             String sTempSectionName(sSectionName);
    1305           0 :             sal_uInt16 nAddNumber = 0;
    1306           0 :             sal_uInt16 nCount = 0;
    1307             :             // if applicable: add index if the range name is already in use.
    1308           0 :             while ( nCount < nSectCount )
    1309             :             {
    1310           0 :                 const SwSectionFmt& rFmt = rSh.GetSectionFmt(nCount);
    1311           0 :                 if ((rFmt.GetSection()->GetSectionName() == sTempSectionName)
    1312           0 :                     && rFmt.IsInNodesArr())
    1313             :                 {
    1314           0 :                     nCount = 0;
    1315           0 :                     nAddNumber++;
    1316           0 :                     sTempSectionName = sSectionName;
    1317           0 :                     sTempSectionName += ':';
    1318           0 :                     sTempSectionName += OUString::number( nAddNumber );
    1319             :                 }
    1320             :                 else
    1321           0 :                     nCount++;
    1322             :             }
    1323             : 
    1324           0 :             if ( nAddNumber )
    1325           0 :                 sSectionName = sTempSectionName;
    1326             : 
    1327           0 :             SwSectionData aSectionData(CONTENT_SECTION, sSectionName);
    1328           0 :             aSectionData.SetProtectFlag(true);
    1329           0 :             aSectionData.SetHidden(false);
    1330             : 
    1331           0 :             aSectionData.SetLinkFileName(sFileName);
    1332           0 :             aSectionData.SetType(FILE_LINK_SECTION);
    1333           0 :             aSectionData.SetLinkFilePassword( sFilePassword );
    1334             : 
    1335           0 :             rSh.InsertGlobalDocContent( *pAnchorContent, aSectionData );
    1336           0 :         }
    1337           0 :         if ( bMove )
    1338             :         {
    1339           0 :             Update( sal_False );
    1340             :             rSh.MoveGlobalDocContent(
    1341           0 :                 *pSwGlblDocContents, nEntryCount, nEntryCount + (sal_uInt16)nFiles, nEntryCount - (sal_uInt16)nFiles );
    1342             :         }
    1343           0 :         rSh.EndAction();
    1344           0 :         Update( sal_False );
    1345           0 :         Display();
    1346             :     }
    1347           0 : }
    1348             : 
    1349           0 : IMPL_LINK( SwGlobalTree, DialogClosedHdl, sfx2::FileDialogHelper*, _pFileDlg )
    1350             : {
    1351           0 :     Application::SetDefDialogParent( pDefParentWin );
    1352           0 :     if ( ERRCODE_NONE == _pFileDlg->GetError() )
    1353             :     {
    1354           0 :         SfxMediumList* pMedList = pDocInserter->CreateMediumList();
    1355           0 :         if ( pMedList )
    1356             :         {
    1357           0 :             Sequence< OUString >aFileNames( pMedList->size() );
    1358           0 :             OUString* pFileNames = aFileNames.getArray();
    1359           0 :             sal_Int32 nPos = 0;
    1360           0 :             for ( size_t i = 0, n = pMedList->size(); i < n; ++i )
    1361             :             {
    1362           0 :                 SfxMedium* pMed = pMedList->at( i );
    1363           0 :                 String sFileName = pMed->GetURLObject().GetMainURL( INetURLObject::NO_DECODE );
    1364           0 :                 sFileName += sfx2::cTokenSeparator;
    1365           0 :                 sFileName += pMed->GetFilter()->GetFilterName();
    1366           0 :                 sFileName += sfx2::cTokenSeparator;
    1367           0 :                 pFileNames[nPos++] = sFileName;
    1368           0 :             }
    1369           0 :             delete pMedList;
    1370           0 :             InsertRegion( pDocContent, aFileNames );
    1371           0 :             DELETEZ( pDocContent );
    1372             :         }
    1373             :     }
    1374           0 :     return 0;
    1375          99 : }
    1376             : 
    1377             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10