xref: /trunk/main/sw/source/ui/utlui/glbltree.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sw.hxx"
30 
31 #ifndef _SVSTDARR_HXX
32 #define _SVSTDARR_STRINGSDTOR
33 #include <svl/svstdarr.hxx>
34 #endif
35 #include <vcl/msgbox.hxx>
36 #include <svl/stritem.hxx>
37 #include <sfx2/fcontnr.hxx>
38 #include <sfx2/linkmgr.hxx>
39 #include <sfx2/dispatch.hxx>
40 #include <svl/urihelper.hxx>
41 #include <sfx2/docfile.hxx>
42 #include <vcl/help.hxx>
43 #include <sot/filelist.hxx>
44 #include <svl/eitem.hxx>
45 #include <svl/urlbmk.hxx>
46 #include <svtools/filter.hxx>
47 #include <sfx2/docinsert.hxx>
48 #include <sfx2/filedlghelper.hxx>
49 
50 #include <sfx2/app.hxx>
51 #include <swmodule.hxx>
52 #include <wrtsh.hxx>
53 #include <view.hxx>
54 #include <errhdl.hxx>
55 #include <docsh.hxx>
56 #include <content.hxx>
57 #include <edglbldc.hxx>
58 #include <section.hxx>
59 #include <tox.hxx>
60 #include <cnttab.hxx>
61 #define NAVIPI_CXX
62 #include <navipi.hxx>
63 #include <navicont.hxx>
64 #include <edtwin.hxx>
65 #include <uitool.hxx>
66 
67 #include <cmdid.h>
68 #include <helpid.h>
69 #ifndef _NAVIPI_HRC
70 #include <navipi.hrc>
71 #endif
72 #ifndef _UTLUI_HRC
73 #include <utlui.hrc>
74 #endif
75 #ifndef _COMCORE_HRC
76 #include <comcore.hrc>
77 #endif
78 #include <globals.hrc>
79 #include "swabstdlg.hxx"
80 
81 using namespace ::com::sun::star::uno;
82 using ::rtl::OUString;
83 
84 
85 // Kontextmenue fuer GlobalTree
86 #define CTX_INSERT_ANY_INDEX 10
87 //#define CTX_INSERT_CNTIDX   11
88 //#define CTX_INSERT_USRIDX   12
89 #define CTX_INSERT_FILE     11
90 #define CTX_INSERT_NEW_FILE 12
91 #define CTX_INSERT_TEXT     13
92 
93 #define CTX_UPDATE_SEL      20
94 #define CTX_UPDATE_INDEX    21
95 #define CTX_UPDATE_LINK     22
96 #define CTX_UPDATE_ALL      23
97 
98 #define CTX_UPDATE          1
99 #define CTX_INSERT          2
100 #define CTX_EDIT            3
101 #define CTX_DELETE          4
102 #define CTX_EDIT_LINK       5
103 
104 #define GLOBAL_UPDATE_TIMEOUT 2000
105 
106 // Flags fuer PopupMenu-enable/disable
107 #define ENABLE_INSERT_IDX   0x0001
108 #define ENABLE_INSERT_FILE  0x0002
109 #define ENABLE_INSERT_TEXT  0x0004
110 #define ENABLE_EDIT         0x0008
111 #define ENABLE_DELETE       0x0010
112 #define ENABLE_UPDATE       0x0020
113 #define ENABLE_UPDATE_SEL   0x0040
114 #define ENABLE_EDIT_LINK    0x0080
115 
116 // TabPos nach links schieben
117 #define  GLBL_TABPOS_SUB 5
118 
119 const SfxObjectShell* SwGlobalTree::pShowShell = 0;
120 static const char* __FAR_DATA aHelpForMenu[] =
121 {
122     0,                          //
123     HID_GLBLTREE_UPDATE,        //CTX_UPDATE
124     HID_GLBLTREE_INSERT,        //CTX_INSERT
125     HID_GLBLTREE_EDIT,          //CTX_EDIT
126     HID_GLBLTREE_DEL,           //CTX_DELETE
127     HID_GLBLTREE_EDIT_LINK,     //CTX_EDIT_LINK
128     0,                        //
129     0,                        //
130     0,                        //
131     0,                        //
132     HID_GLBLTREE_INS_IDX,       //CTX_INSERT_ANY_INDEX
133     HID_GLBLTREE_INS_FILE,      //CTX_INSERT_FILE
134     HID_GLBLTREE_INS_NEW_FILE,  //CTX_INSERT_NEW_FILE
135     HID_GLBLTREE_INS_TEXT,      //CTX_INSERT_TEXT
136     0,                          //
137     0,                          //
138     0,                          //
139     0,                          //
140     0,                          //
141     0,                          //
142     HID_GLBLTREE_UPD_SEL,       //CTX_UPDATE_SEL
143     HID_GLBLTREE_UPD_IDX,       //CTX_UPDATE_INDEX
144     HID_GLBLTREE_UPD_LINK,      //CTX_UPDATE_LINK
145     HID_GLBLTREEUPD_ALL         //CTX_UPDATE_ALL
146 };
147 
148 /************************************************************************/
149 /*                                                                      */
150 /************************************************************************/
151 /* -----------------------------24.08.00 12:04--------------------------------
152 
153  ---------------------------------------------------------------------------*/
154 class SwGlobalFrameListener_Impl : public SfxListener
155 {
156     sal_Bool bValid;
157 public:
158     SwGlobalFrameListener_Impl(SfxViewFrame& rFrame) :
159         bValid(sal_True)
160         {
161             StartListening(rFrame);
162         }
163 
164     virtual void        Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
165 
166     sal_Bool                IsValid() const {return bValid;}
167 };
168 /* -----------------------------24.08.00 12:05--------------------------------
169 
170  ---------------------------------------------------------------------------*/
171 void    SwGlobalFrameListener_Impl::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint )
172 {
173     if( rHint.ISA(SfxSimpleHint) &&
174             (((SfxSimpleHint&) rHint).GetId() == SFX_HINT_DYING))
175         bValid = sal_False;
176 }
177 
178 /*-----------------12.06.97 09:38-------------------
179 
180 --------------------------------------------------*/
181 SwGlobalTree::SwGlobalTree(Window* pParent, const ResId& rResId) :
182 
183     SvTreeListBox(pParent, rResId),
184 
185     pActiveShell        ( NULL ),
186     pEmphasisEntry      ( NULL ),
187     pDDSource           ( NULL ),
188     pSwGlblDocContents  ( NULL ),
189     pDefParentWin       ( NULL ),
190     pDocContent         ( NULL ),
191     pDocInserter        ( NULL ),
192 
193     bIsInternalDrag         ( sal_False ),
194     bLastEntryEmphasis      ( sal_False ),
195     bIsImageListInitialized ( sal_False )
196 
197 {
198     SetDragDropMode(SV_DRAGDROP_APP_COPY  |
199                     SV_DRAGDROP_CTRL_MOVE |
200                     SV_DRAGDROP_ENABLE_TOP );
201 
202     aUpdateTimer.SetTimeout(GLOBAL_UPDATE_TIMEOUT);
203     aUpdateTimer.SetTimeoutHdl(LINK(this, SwGlobalTree, Timeout));
204     aUpdateTimer.Start();
205     for(sal_uInt16 i = 0; i < GLOBAL_CONTEXT_COUNT; i++)
206     {
207         aContextStrings[i] = SW_RESSTR(i+ ST_GLOBAL_CONTEXT_FIRST);
208     }
209     SetHelpId(HID_NAVIGATOR_GLOB_TREELIST);
210     SelectHdl();
211     SetDoubleClickHdl(LINK(this, SwGlobalTree, DoubleClickHdl));
212     EnableContextMenuHandling();
213 }
214 
215 /*-----------------12.06.97 09:38-------------------
216 
217 --------------------------------------------------*/
218 SwGlobalTree::~SwGlobalTree()
219 {
220     delete pSwGlblDocContents;
221     delete pDocInserter;
222 }
223 
224 /*-----------------12.06.97 09:38-------------------
225 
226 --------------------------------------------------*/
227 sal_Int8 SwGlobalTree::ExecuteDrop( const ExecuteDropEvent& rEvt )
228 {
229     sal_Int8 nRet = DND_ACTION_NONE;
230     SvLBoxEntry* pLast = (SvLBoxEntry*)LastVisible();
231     if(pEmphasisEntry)
232     {
233         ImplShowTargetEmphasis( Prev(pEmphasisEntry), sal_False );
234         pEmphasisEntry = 0;
235     }
236     else if(bLastEntryEmphasis && pLast)
237     {
238         ImplShowTargetEmphasis( pLast, sal_False);
239     }
240 
241     SvLBoxEntry* pDropEntry = bLastEntryEmphasis ? 0 : GetEntry(rEvt.maPosPixel);
242     if( bIsInternalDrag )
243     {
244         SvLBoxEntry* pDummy = 0;
245         sal_uLong nInsertionPos = LIST_APPEND;
246         NotifyMoving( pDropEntry, pDDSource, pDummy, nInsertionPos );
247     }
248     else
249     {
250         TransferableDataHelper aData( rEvt.maDropEvent.Transferable );
251 
252         String sFileName;
253         const SwGlblDocContent* pCnt = pDropEntry ?
254                     (const SwGlblDocContent*)pDropEntry->GetUserData() :
255                             0;
256         if( aData.HasFormat( FORMAT_FILE_LIST ))
257         {
258             nRet = rEvt.mnAction;
259             SwGlblDocContents* pTempContents = new SwGlblDocContents;
260             int nAbsContPos = pDropEntry ?
261                                 (int) GetModel()->GetAbsPos(pDropEntry):
262                                     - 1;
263             sal_uInt16 nEntryCount = (sal_uInt16)GetEntryCount();
264 
265             // Daten holen
266             FileList aFileList;
267             aData.GetFileList( FORMAT_FILE_LIST, aFileList );
268             for ( sal_uInt16 n = (sal_uInt16)aFileList.Count(); n--; )
269             {
270                 sFileName = aFileList.GetFile(n);
271                 InsertRegion(pCnt, &sFileName);
272                 // nach dem Einfuegen muss die Liste der Contents neu
273                 // geholt werden, um nicht auf einem alten Content zu
274                 // arbeiten
275                 if(n)
276                 {
277                     pActiveShell->GetGlobalDocContent(*pTempContents);
278                     // wenn das file erfolgreich eingefuegt wurde,
279                     // dann muss auch der naechste Content geholt werden
280                     if(nEntryCount < pTempContents->Count())
281                     {
282                         nEntryCount++;
283                         nAbsContPos++;
284                         pCnt = pTempContents->GetObject( static_cast< sal_uInt16 >(nAbsContPos) );
285                     }
286                 }
287             }
288             delete pTempContents;
289         }
290         else if( 0 != (sFileName =
291                         SwNavigationPI::CreateDropFileName( aData )).Len())
292         {
293             INetURLObject aTemp(sFileName);
294             GraphicDescriptor aDesc(aTemp);
295             if( !aDesc.Detect() )   // keine Grafiken annehmen
296             {
297                 nRet = rEvt.mnAction;
298                 InsertRegion(pCnt, &sFileName);
299             }
300         }
301     }
302     bLastEntryEmphasis = sal_False;
303     return nRet;
304 
305 }
306 /*-----------------12.06.97 09:38-------------------
307 
308 --------------------------------------------------*/
309 sal_Int8 SwGlobalTree::AcceptDrop( const AcceptDropEvent& rEvt )
310 {
311     sal_Int8 nRet = rEvt.mnAction;
312 
313     //initiate scrolling
314     GetDropTarget( rEvt.maPosPixel );
315     SvLBoxEntry* pLast = (SvLBoxEntry*)LastVisible();
316     if( rEvt.mbLeaving )
317     {
318         if( pEmphasisEntry )
319         {
320             ImplShowTargetEmphasis( Prev(pEmphasisEntry), sal_False );
321             pEmphasisEntry = 0;
322         }
323         else if(bLastEntryEmphasis && pLast)
324         {
325             ImplShowTargetEmphasis( pLast, sal_False);
326         }
327         bLastEntryEmphasis = sal_False;
328     }
329     else
330     {
331         SvLBoxEntry* pDropEntry = GetEntry( rEvt.maPosPixel );
332         if(bIsInternalDrag)
333         {
334             if( pDDSource != pDropEntry )
335                 nRet = rEvt.mnAction;
336         }
337         else if( IsDropFormatSupported( FORMAT_FILE ) ||
338                 IsDropFormatSupported( FORMAT_STRING ) ||
339                 IsDropFormatSupported( FORMAT_FILE_LIST ) ||
340                 IsDropFormatSupported( SOT_FORMATSTR_ID_SOLK ) ||
341                 IsDropFormatSupported( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK )||
342                 IsDropFormatSupported( SOT_FORMATSTR_ID_FILECONTENT ) ||
343                 IsDropFormatSupported( SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR ) ||
344                 IsDropFormatSupported( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR ) ||
345                 IsDropFormatSupported( SOT_FORMATSTR_ID_FILENAME ))
346                 nRet = DND_ACTION_LINK;
347 
348         if(pEmphasisEntry && pEmphasisEntry != pDropEntry)
349             ImplShowTargetEmphasis( Prev(pEmphasisEntry), sal_False );
350         else if(pLast && bLastEntryEmphasis  && pDropEntry)
351         {
352             ImplShowTargetEmphasis( pLast, sal_False);
353             bLastEntryEmphasis = sal_False;
354         }
355 
356         if(pDropEntry)
357             ImplShowTargetEmphasis( Prev(pDropEntry), DND_ACTION_NONE != nRet );
358         else if(pLast)
359         {
360             ImplShowTargetEmphasis( pLast, DND_ACTION_NONE != nRet );
361             bLastEntryEmphasis = sal_True;
362         }
363         pEmphasisEntry = pDropEntry;
364     }
365     return nRet;
366 }
367 /*-----------------12.06.97 09:38-------------------
368 
369 --------------------------------------------------*/
370 PopupMenu* SwGlobalTree::CreateContextMenu()
371 {
372     PopupMenu* pPop = 0;
373     if(pActiveShell &&
374         !pActiveShell->GetView().GetDocShell()->IsReadOnly())
375     {
376         sal_uInt16 nEnableFlags = GetEnableFlags();
377         pPop = new PopupMenu;
378         PopupMenu* pSubPop1 = new PopupMenu;
379         PopupMenu* pSubPop2 = new PopupMenu;
380 
381         for (sal_uInt16 i = CTX_UPDATE_SEL; i <= CTX_UPDATE_ALL; i++)
382         {
383             pSubPop2->InsertItem( i, aContextStrings[ST_UPDATE_SEL - ST_GLOBAL_CONTEXT_FIRST - CTX_UPDATE_SEL+ i] );
384             pSubPop2->SetHelpId(i, aHelpForMenu[i]);
385         }
386         pSubPop2->EnableItem(CTX_UPDATE_SEL, 0 != (nEnableFlags & ENABLE_UPDATE_SEL));
387 
388         pSubPop1->InsertItem(CTX_INSERT_ANY_INDEX, aContextStrings[ST_INDEX  - ST_GLOBAL_CONTEXT_FIRST]);
389         pSubPop1->SetHelpId(CTX_INSERT_ANY_INDEX, aHelpForMenu[CTX_INSERT_ANY_INDEX]);
390         pSubPop1->InsertItem(CTX_INSERT_FILE, aContextStrings[ST_FILE   - ST_GLOBAL_CONTEXT_FIRST]);
391         pSubPop1->SetHelpId(CTX_INSERT_FILE, aHelpForMenu[CTX_INSERT_FILE]);
392         pSubPop1->InsertItem(CTX_INSERT_NEW_FILE, aContextStrings[ST_NEW_FILE   - ST_GLOBAL_CONTEXT_FIRST]);
393         pSubPop1->SetHelpId(CTX_INSERT_NEW_FILE, aHelpForMenu[CTX_INSERT_NEW_FILE]);
394         pSubPop1->InsertItem(CTX_INSERT_TEXT, aContextStrings[ST_TEXT   - ST_GLOBAL_CONTEXT_FIRST]);
395         pSubPop1->SetHelpId(CTX_INSERT_TEXT, aHelpForMenu[CTX_INSERT_TEXT]);
396 
397 
398         pPop->InsertItem(CTX_UPDATE, aContextStrings[ST_UPDATE - ST_GLOBAL_CONTEXT_FIRST]);
399         pPop->SetHelpId(CTX_UPDATE, aHelpForMenu[CTX_UPDATE]);
400         pPop->InsertItem(CTX_EDIT, aContextStrings[ST_EDIT_CONTENT - ST_GLOBAL_CONTEXT_FIRST]);
401         pPop->SetHelpId(CTX_EDIT, aHelpForMenu[CTX_EDIT]);
402         if(nEnableFlags&ENABLE_EDIT_LINK)
403         {
404             pPop->InsertItem(CTX_EDIT_LINK, aContextStrings[ST_EDIT_LINK - ST_GLOBAL_CONTEXT_FIRST]);
405             pPop->SetHelpId(CTX_EDIT_LINK, aHelpForMenu[CTX_EDIT_LINK]);
406         }
407         pPop->InsertItem(CTX_INSERT, aContextStrings[ST_INSERT - ST_GLOBAL_CONTEXT_FIRST]);
408         pPop->SetHelpId(CTX_INSERT, aHelpForMenu[CTX_INSERT]);
409         pPop->InsertSeparator() ;
410         pPop->InsertItem(CTX_DELETE, aContextStrings[ST_DELETE - ST_GLOBAL_CONTEXT_FIRST]);
411         pPop->SetHelpId(CTX_DELETE, aHelpForMenu[CTX_DELETE]);
412 
413         //evtl. disablen
414         pSubPop1->EnableItem(CTX_INSERT_ANY_INDEX,  0 != (nEnableFlags & ENABLE_INSERT_IDX ));
415         pSubPop1->EnableItem(CTX_INSERT_TEXT,       0 != (nEnableFlags & ENABLE_INSERT_TEXT));
416         pSubPop1->EnableItem(CTX_INSERT_FILE,       0 != (nEnableFlags & ENABLE_INSERT_FILE));
417         pSubPop1->EnableItem(CTX_INSERT_NEW_FILE,   0 != (nEnableFlags & ENABLE_INSERT_FILE));
418 
419         pPop->EnableItem(CTX_UPDATE,    0 != (nEnableFlags & ENABLE_UPDATE));
420         pPop->EnableItem(CTX_INSERT,    0 != (nEnableFlags & ENABLE_INSERT_IDX));
421         pPop->EnableItem(CTX_EDIT,      0 != (nEnableFlags & ENABLE_EDIT));
422         pPop->EnableItem(CTX_DELETE,    0 != (nEnableFlags & ENABLE_DELETE));
423 
424 
425         pPop->SetPopupMenu( CTX_INSERT, pSubPop1 );
426         pPop->SetPopupMenu( CTX_UPDATE, pSubPop2 );
427     }
428     return pPop;
429 }
430 /*-----------------16.06.97 10:41-------------------
431 
432 --------------------------------------------------*/
433 void SwGlobalTree::TbxMenuHdl(sal_uInt16 nTbxId, ToolBox* pBox)
434 {
435     sal_uInt16 nEnableFlags = GetEnableFlags();
436     if(FN_GLOBAL_OPEN == nTbxId)
437     {
438         PopupMenu *pMenu = new PopupMenu;
439         for (sal_uInt16 i = CTX_INSERT_ANY_INDEX; i <= CTX_INSERT_TEXT; i++)
440         {
441             pMenu->InsertItem( i, aContextStrings[ST_INDEX  - ST_GLOBAL_CONTEXT_FIRST - CTX_INSERT_ANY_INDEX + i] );
442             pMenu->SetHelpId(i, aHelpForMenu[i] );
443         }
444         pMenu->EnableItem(CTX_INSERT_ANY_INDEX, 0 != (nEnableFlags & ENABLE_INSERT_IDX ));
445 //      pMenu->EnableItem(CTX_INSERT_CNTIDX,    0 != (nEnableFlags & ENABLE_INSERT_IDX ));
446 //      pMenu->EnableItem(CTX_INSERT_USRIDX,    0 != (nEnableFlags & ENABLE_INSERT_IDX ));
447         pMenu->EnableItem(CTX_INSERT_TEXT,      0 != (nEnableFlags & ENABLE_INSERT_TEXT));
448         pMenu->EnableItem(CTX_INSERT_FILE,      0 != (nEnableFlags & ENABLE_INSERT_FILE));
449         pMenu->EnableItem(CTX_INSERT_NEW_FILE,  0 != (nEnableFlags & ENABLE_INSERT_FILE));
450         pMenu->SetSelectHdl(LINK(this, SwGlobalTree, PopupHdl));
451         pMenu->Execute( pBox, pBox->GetItemRect(nTbxId).BottomLeft());
452         delete pMenu;
453         pBox->EndSelection();
454         pBox->Invalidate();
455     }
456     else if(FN_GLOBAL_UPDATE == nTbxId)
457     {
458         PopupMenu *pMenu = new PopupMenu;
459         for (sal_uInt16 i = CTX_UPDATE_SEL; i <= CTX_UPDATE_ALL; i++)
460         {
461             pMenu->InsertItem( i, aContextStrings[ST_UPDATE_SEL - ST_GLOBAL_CONTEXT_FIRST - CTX_UPDATE_SEL+ i] );
462             pMenu->SetHelpId(i, aHelpForMenu[i] );
463         }
464         pMenu->EnableItem(CTX_UPDATE_SEL, 0 != (nEnableFlags & ENABLE_UPDATE_SEL));
465         pMenu->SetSelectHdl(LINK(this, SwGlobalTree, PopupHdl));
466         pMenu->Execute( pBox, pBox->GetItemRect(nTbxId).BottomLeft());
467         delete pMenu;
468         pBox->EndSelection();
469         pBox->Invalidate();
470     }
471 }
472 /*-----------------16.06.97 11:02-------------------
473 
474 --------------------------------------------------*/
475 sal_uInt16  SwGlobalTree::GetEnableFlags() const
476 {
477     SvLBoxEntry* pEntry = FirstSelected();
478     sal_uInt16 nSelCount = (sal_uInt16)GetSelectionCount();
479     sal_uInt16 nEntryCount = (sal_uInt16)GetEntryCount();
480     SvLBoxEntry* pPrevEntry = pEntry ? Prev(pEntry) : 0;
481 
482     sal_uInt16 nRet = 0;
483     if(nSelCount == 1 || !nEntryCount)
484         nRet |= ENABLE_INSERT_IDX|ENABLE_INSERT_FILE;
485     if(nSelCount == 1)
486     {
487         nRet |= ENABLE_EDIT;
488         if( ((SwGlblDocContent*)pEntry->GetUserData())->GetType() != GLBLDOC_UNKNOWN &&
489                     (!pPrevEntry || ((SwGlblDocContent*)pPrevEntry->GetUserData())->GetType() != GLBLDOC_UNKNOWN))
490             nRet |= ENABLE_INSERT_TEXT;
491         if( GLBLDOC_SECTION == ((SwGlblDocContent*)pEntry->GetUserData())->GetType() )
492             nRet |= ENABLE_EDIT_LINK;
493     }
494     else if(!nEntryCount)
495     {
496         nRet |= ENABLE_INSERT_TEXT;
497     }
498     if(nEntryCount)
499         nRet |= ENABLE_UPDATE|ENABLE_DELETE;
500     if(nSelCount)
501         nRet |= ENABLE_UPDATE_SEL;
502     return nRet;
503 }
504 
505 /*-----------------12.06.97 09:38-------------------
506 
507 --------------------------------------------------*/
508 void     SwGlobalTree::RequestHelp( const HelpEvent& rHEvt )
509 {
510     sal_Bool bParent = sal_True;
511     Update(sal_True);
512     Display(sal_True);
513     if( rHEvt.GetMode() & HELPMODE_QUICK )
514     {
515         Point aPos( ScreenToOutputPixel( rHEvt.GetMousePosPixel() ));
516         SvLBoxEntry* pEntry = GetEntry( aPos );
517         const SwGlblDocContent* pCont = pEntry ?
518                             (const SwGlblDocContent*)pEntry->GetUserData() : 0;
519         if( pCont &&  GLBLDOC_SECTION == pCont->GetType())
520         {
521             bParent = sal_False;
522             SvLBoxTab* pTab;
523             SvLBoxItem* pItem = GetItem( pEntry, aPos.X(), &pTab );
524             if(pItem && SV_ITEM_ID_LBOXSTRING == pItem->IsA())
525             {
526                 const SwSection* pSect = pCont->GetSection();
527                 String sEntry = pSect->GetLinkFileName().GetToken(0, sfx2::cTokenSeperator);
528                 if(!pSect->IsConnectFlag())
529                     sEntry.Insert(aContextStrings[ST_BROKEN_LINK - ST_GLOBAL_CONTEXT_FIRST], 0 );
530                 Point aEntryPos = GetEntryPosition( pEntry );
531 
532                 aEntryPos.X() = GetTabPos( pEntry, pTab );
533                 Size aSize( pItem->GetSize( this, pEntry ) );
534 
535                 if((aEntryPos.X() + aSize.Width()) > GetSizePixel().Width())
536                     aSize.Width() = GetSizePixel().Width() - aEntryPos.X();
537 
538                 aEntryPos = OutputToScreenPixel(aEntryPos);
539                 Rectangle aItemRect( aEntryPos, aSize );
540                 if(Help::IsBalloonHelpEnabled())
541                 {
542                     aEntryPos.X() += aSize.Width();
543                     Help::ShowBalloon( this, aEntryPos, aItemRect, sEntry );
544                 }
545                 else
546                     Help::ShowQuickHelp( this, aItemRect, sEntry,
547                         QUICKHELP_LEFT|QUICKHELP_VCENTER );
548             }
549         }
550     }
551 
552     if(bParent)
553         SvTreeListBox::RequestHelp(rHEvt);
554 }
555 /*-----------------16.06.97 16:15-------------------
556 
557 --------------------------------------------------*/
558 void     SwGlobalTree::SelectHdl()
559 {
560 
561     sal_uInt16 nSelCount = (sal_uInt16)GetSelectionCount();
562     SvLBoxEntry* pSel = FirstSelected();
563     sal_uInt16 nAbsPos = pSel ? (sal_uInt16)GetModel()->GetAbsPos(pSel) : 0;
564     SwNavigationPI* pNavi = GetParentWindow();
565     sal_Bool bReadonly = !pActiveShell ||
566                 pActiveShell->GetView().GetDocShell()->IsReadOnly();
567     pNavi->aGlobalToolBox.EnableItem(FN_GLOBAL_EDIT,  nSelCount == 1 && !bReadonly);
568     pNavi->aGlobalToolBox.EnableItem(FN_GLOBAL_OPEN,  nSelCount <= 1 && !bReadonly);
569     pNavi->aGlobalToolBox.EnableItem(FN_GLOBAL_UPDATE,  GetEntryCount() > 0 && !bReadonly);
570     pNavi->aGlobalToolBox.EnableItem(FN_ITEM_UP,
571                     nSelCount == 1 && nAbsPos && !bReadonly);
572     pNavi->aGlobalToolBox.EnableItem(FN_ITEM_DOWN,
573                     nSelCount == 1 && nAbsPos < ((sal_uInt16)GetEntryCount()) - 1 && !bReadonly);
574 
575 }
576 /*-----------------16.06.97 16:15-------------------
577 
578 --------------------------------------------------*/
579 void     SwGlobalTree::DeselectHdl()
580 {
581     SelectHdl();
582 }
583 
584 /*-----------------17.06.97 13:11-------------------
585 
586 --------------------------------------------------*/
587 DragDropMode SwGlobalTree::NotifyStartDrag( TransferDataContainer& ,
588                                                 SvLBoxEntry* pEntry )
589 {
590     bIsInternalDrag = sal_True;
591     pDDSource = pEntry;
592     return SV_DRAGDROP_CTRL_MOVE;
593 }
594 
595 /*-----------------21.06.97 12:44-------------------
596 
597 --------------------------------------------------*/
598 long     SwGlobalTree::GetTabPos( SvLBoxEntry*, SvLBoxTab* pTab)
599 {
600     return pTab->GetPos() - GLBL_TABPOS_SUB;
601 }
602 
603 /*-----------------12.06.97 09:38-------------------
604 
605 --------------------------------------------------*/
606 sal_Bool     SwGlobalTree::NotifyMoving(   SvLBoxEntry*  pTarget,
607                                         SvLBoxEntry*  pSource,
608                                         SvLBoxEntry*&,
609                                         sal_uLong&
610                                     )
611 {
612     SvTreeList* _pModel = GetModel();
613     sal_uInt16 nSource = (sal_uInt16) _pModel->GetAbsPos(pSource);
614     sal_uInt16 nDest   = pTarget ? (sal_uInt16) _pModel->GetAbsPos(pTarget) : pSwGlblDocContents->Count();
615 
616     if( pActiveShell->MoveGlobalDocContent(
617             *pSwGlblDocContents, nSource, nSource + 1, nDest ) &&
618             Update( sal_False ))
619         Display();
620     return sal_False;
621 }
622 /*-----------------12.06.97 09:39-------------------
623 
624 --------------------------------------------------*/
625 sal_Bool     SwGlobalTree::NotifyCopying(  SvLBoxEntry*  /*pTarget*/,
626                                         SvLBoxEntry*  /*pEntry*/,
627                                         SvLBoxEntry*& /*rpNewParent*/,
628                                         sal_uLong&        /*rNewChildPos*/
629                                     )
630 {
631     return sal_False;
632 }
633 /*-----------------12.06.97 09:39-------------------
634 
635 --------------------------------------------------*/
636 sal_Bool SwGlobalTree::NotifyAcceptDrop( SvLBoxEntry* pEntry)
637 {
638     return pEntry != 0;
639 }
640 /*-----------------12.06.97 09:39-------------------
641 
642 --------------------------------------------------*/
643 void SwGlobalTree::StartDrag( sal_Int8 nAction, const Point& rPt )
644 {
645     if( 1 == GetSelectionCount() )
646         SvTreeListBox::StartDrag( nAction, rPt );
647 }
648 /*-----------------12.06.97 09:39-------------------
649 
650 --------------------------------------------------*/
651 void SwGlobalTree::DragFinished( sal_Int8 nAction )
652 {
653     SvTreeListBox::DragFinished( nAction );
654     bIsInternalDrag = sal_False;
655 }
656 
657 /***************************************************************************
658     Beschreibung:   Wird ein Ctrl+DoubleClick in einen freien Bereich ausgefuehrt,
659  *                  dann soll die Basisfunktion des Controls gerufen werden
660 ***************************************************************************/
661 void  SwGlobalTree::MouseButtonDown( const MouseEvent& rMEvt )
662 {
663     Point aPos( rMEvt.GetPosPixel());
664     SvLBoxEntry* pEntry = GetEntry( aPos, sal_True );
665     if( !pEntry && rMEvt.IsLeft() && rMEvt.IsMod1() && (rMEvt.GetClicks() % 2) == 0)
666         Control::MouseButtonDown( rMEvt );
667     else
668         SvTreeListBox::MouseButtonDown( rMEvt );
669 }
670 
671 /*-----------------12.06.97 13:08-------------------
672 
673 --------------------------------------------------*/
674 void     SwGlobalTree::GetFocus()
675 {
676     if(Update( sal_False ))
677         Display();
678     SvTreeListBox::GetFocus();
679 }
680 
681 /*-----------------12.06.97 12:34-------------------
682 
683 --------------------------------------------------*/
684 void     SwGlobalTree::KeyInput(const KeyEvent& rKEvt)
685 {
686     const KeyCode aCode = rKEvt.GetKeyCode();
687     if(aCode.GetCode() == KEY_RETURN)
688     {
689         switch(aCode.GetModifier())
690         {
691             case KEY_MOD2:
692                 // Boxen umschalten
693                 GetParentWindow()->ToggleTree();
694             break;
695         }
696     }
697     else
698         SvTreeListBox::KeyInput(rKEvt);
699 }
700 
701 /*-----------------17.06.97 11:59-------------------
702 
703 --------------------------------------------------*/
704 void SwGlobalTree::Clear()
705 {
706     pEmphasisEntry = 0;
707     SvTreeListBox::Clear();
708 }
709 /*-----------------12.06.97 12:38-------------------
710 
711 --------------------------------------------------*/
712 void    SwGlobalTree::Display(sal_Bool bOnlyUpdateUserData)
713 {
714     if(!bIsImageListInitialized)
715     {
716         sal_uInt16 nResId = GetSettings().GetStyleSettings().GetHighContrastMode() ? IMG_NAVI_ENTRYBMPH : IMG_NAVI_ENTRYBMP;
717         aEntryImages = ImageList(SW_RES(nResId));
718         bIsImageListInitialized = sal_True;
719     }
720     sal_uInt16 nCount = pSwGlblDocContents->Count();
721     if(bOnlyUpdateUserData && GetEntryCount() == pSwGlblDocContents->Count())
722     {
723         SvLBoxEntry* pEntry = First();
724         for( sal_uInt16 i = 0; i < nCount; i++)
725         {
726             SwGlblDocContentPtr pCont = pSwGlblDocContents->GetObject(i);
727             pEntry->SetUserData(pCont);
728             pEntry = Next(pEntry);
729         }
730     }
731     else
732     {
733         SetUpdateMode( sal_False );
734         SvLBoxEntry* pOldSelEntry = FirstSelected();
735         String sEntryName;  // Name des Eintrags
736         sal_uInt16 nSelPos = USHRT_MAX;
737         if(pOldSelEntry)
738         {
739             sEntryName = GetEntryText(pOldSelEntry);
740             nSelPos = (sal_uInt16)GetModel()->GetAbsPos(pOldSelEntry);
741         }
742         Clear();
743         if(!pSwGlblDocContents)
744             Update( sal_False );
745 
746         SvLBoxEntry* pSelEntry = 0;
747         for( sal_uInt16 i = 0; i < nCount; i++)
748         {
749             SwGlblDocContentPtr pCont = pSwGlblDocContents->GetObject(i);
750             String sEntry;
751             Image aImage;
752             switch( pCont->GetType()  )
753             {
754                 case GLBLDOC_UNKNOWN:
755                 {
756                     sEntry = aContextStrings[ST_TEXT   - ST_GLOBAL_CONTEXT_FIRST];
757                     aImage = aEntryImages.GetImage(SID_SW_START + GLOBAL_CONTENT_TEXT);
758                 }
759                 break;
760                 case GLBLDOC_TOXBASE:
761                 {
762                     const SwTOXBase* pBase = pCont->GetTOX();
763                     sEntry = pBase->GetTitle();
764                     aImage = aEntryImages.GetImage(SID_SW_START + CONTENT_TYPE_INDEX);
765                 }
766                 break;
767                 case GLBLDOC_SECTION:
768                 {
769                     const SwSection* pSect = pCont->GetSection();
770                     sEntry = pSect->GetSectionName();
771                     aImage = aEntryImages.GetImage(SID_SW_START + CONTENT_TYPE_REGION);
772                 }
773                 break;
774             }
775             SvLBoxEntry* pEntry = InsertEntry(sEntry, aImage, aImage,
776                         0, sal_False, LIST_APPEND, pCont);
777             if(sEntry == sEntryName)
778             {
779                 pSelEntry = pEntry;
780             }
781         }
782         if(pSelEntry)
783         {
784             Select(pSelEntry);
785         }
786         else if(nSelPos != USHRT_MAX && nSelPos < nCount)
787         {
788             Select(GetEntry(nSelPos));
789         }
790         else if(nCount)
791             Select(First());
792         else
793             SelectHdl();
794         SetUpdateMode( sal_True );
795     }
796 }
797 
798 /*-----------------13.06.97 10:32-------------------
799 
800 --------------------------------------------------*/
801 void SwGlobalTree::InsertRegion( const SwGlblDocContent* pCont, const String* pFileName )
802 {
803     Sequence< OUString > aFileNames;
804     if ( !pFileName )
805     {
806         pDefParentWin = Application::GetDefDialogParent();
807         Application::SetDefDialogParent( this );
808         if ( pDocInserter )
809             delete pDocInserter;
810         pDocInserter = new ::sfx2::DocumentInserter( 0, String::CreateFromAscii("swriter"), true );
811         pDocInserter->StartExecuteModal( LINK( this, SwGlobalTree, DialogClosedHdl ) );
812     }
813     else if ( pFileName->Len() )
814     {
815         aFileNames.realloc(1);
816         INetURLObject aFileName;
817         aFileName.SetSmartURL( *pFileName );
818         aFileNames.getArray()[0] = aFileName.GetMainURL( INetURLObject::NO_DECODE );
819         InsertRegion( pCont, aFileNames );
820     }
821 }
822 
823 /*-----------------18.06.97 12:42-------------------
824 
825 --------------------------------------------------*/
826 void    SwGlobalTree::EditContent(const SwGlblDocContent* pCont )
827 {
828     sal_uInt16 nSlot = 0;
829     switch( pCont->GetType() )
830     {
831         case GLBLDOC_UNKNOWN:
832             pActiveShell->GetView().GetEditWin().GrabFocus();
833         break;
834         case GLBLDOC_TOXBASE:
835         {
836             const SwTOXBase* pBase = pCont->GetTOX();
837             if(pBase)
838                 nSlot = FN_INSERT_MULTI_TOX;
839         }
840         break;
841         case GLBLDOC_SECTION:
842         {
843             OpenDoc(pCont);
844 
845             nSlot = 0;
846             pCont = 0;
847         }
848         break;
849     }
850     if(pCont)
851         GotoContent(pCont);
852     if(nSlot)
853     {
854         pActiveShell->GetView().GetViewFrame()->GetDispatcher()->Execute(nSlot);
855         if(Update( sal_False ))
856             Display();
857     }
858 }
859 
860 /*-----------------13.06.97 14:22-------------------
861 
862 --------------------------------------------------*/
863 IMPL_LINK( SwGlobalTree, PopupHdl, Menu* , pMenu)
864 {
865     ExcecuteContextMenuAction( pMenu->GetCurItemId());
866     return sal_True;
867 }
868 /* -----------------26.08.2003 11:57-----------------
869 
870  --------------------------------------------------*/
871 void    SwGlobalTree::ExcecuteContextMenuAction( sal_uInt16 nSelectedPopupEntry )
872 //IMPL_LINK( SwGlobalTree, PopupHdl, Menu* , pMenu)
873 {
874 //  sal_uInt16 nId = pMenu->GetCurItemId();
875     SvLBoxEntry* pEntry = FirstSelected();
876     SwGlblDocContent* pCont = pEntry ? (SwGlblDocContent*)pEntry->GetUserData() : 0;
877     // wird waehrend des Dialogs ein RequestHelp gerufen,
878     // dann geht der Content verloren. Deshalb wird hier eine
879     // Kopie angelegt, in der nur die DocPos richtig gesetzt ist.
880     SwGlblDocContent* pContCopy = 0;
881     if(pCont)
882         pContCopy = new SwGlblDocContent(pCont->GetDocPos());
883     SfxDispatcher& rDispatch = *pActiveShell->GetView().GetViewFrame()->GetDispatcher();
884     sal_uInt16 nSlot = 0;
885     bool bDeleteContentCopy = true;
886     switch( nSelectedPopupEntry )
887     {
888         case CTX_UPDATE_SEL:
889         {
890             // zwei Durchlaeufe: zuerst die Bereiche, dann die Verzeichnisse
891             // aktualisieren
892             SvLBoxEntry* pSelEntry = FirstSelected();
893             while( pSelEntry )
894             {
895                 SwGlblDocContent* pContent = (SwGlblDocContent*)pSelEntry->GetUserData();
896                 if(GLBLDOC_SECTION == pContent->GetType() &&
897                     pContent->GetSection()->IsConnected())
898                 {
899                     ((SwSection*)pContent->GetSection())->UpdateNow();
900                 }
901 
902                 pSelEntry = NextSelected(pSelEntry);
903             }
904             pSelEntry = FirstSelected();
905             while( pSelEntry )
906             {
907                 SwGlblDocContent* pContent = (SwGlblDocContent*)pSelEntry->GetUserData();
908                 if(GLBLDOC_TOXBASE == pContent->GetType())
909                     pActiveShell->UpdateTableOf(*pContent->GetTOX());
910                 pSelEntry = NextSelected(pSelEntry);
911             }
912 
913         }
914         break;
915         case CTX_UPDATE_INDEX:
916         {
917             nSlot = FN_UPDATE_TOX;
918         }
919         break;
920         case CTX_UPDATE_LINK:
921         case CTX_UPDATE_ALL:
922         {
923             pActiveShell->GetLinkManager().UpdateAllLinks(sal_True);
924             if(CTX_UPDATE_ALL == nSelectedPopupEntry)
925                 nSlot = FN_UPDATE_TOX;
926             pCont = 0;
927         }
928         break;
929         case CTX_EDIT:
930         {
931             DBG_ASSERT(pCont, "Edit ohne Entry ? " );
932             EditContent(pCont);
933         }
934         break;
935         case CTX_EDIT_LINK:
936         {
937             DBG_ASSERT(pCont, "Edit ohne Entry ? " );
938             SfxStringItem aName(FN_EDIT_REGION,
939                     pCont->GetSection()->GetSectionName());
940             rDispatch.Execute(FN_EDIT_REGION, SFX_CALLMODE_ASYNCHRON, &aName, 0L);
941         }
942         break;
943         case CTX_DELETE:
944         {
945             // sind mehrere Eintraege selektiert, dann muss nach jedem delete
946             // das Array neu gefuellt werden. Damit man sich nichts merken muss,
947             // beginnt das Loeschen am Ende
948             SvLBoxEntry* pSelEntry = LastSelected();
949             SwGlblDocContents* pTempContents  = 0;
950             pActiveShell->StartAction();
951             while(pSelEntry)
952             {
953                 pActiveShell->DeleteGlobalDocContent(
954                     pTempContents ? *pTempContents : *pSwGlblDocContents,
955                                      (sal_uInt16)GetModel()->GetAbsPos(pSelEntry));
956                 pSelEntry = PrevSelected(pSelEntry);
957                 if(pSelEntry)
958                 {
959                     pTempContents = new SwGlblDocContents;
960                     pActiveShell->GetGlobalDocContent(*pTempContents);
961                 }
962             }
963             delete pTempContents;
964             pActiveShell->EndAction();
965             pCont = 0;
966         }
967         break;
968         case CTX_INSERT_ANY_INDEX:
969 //      case CTX_INSERT_CNTIDX:
970 //      case CTX_INSERT_USRIDX:
971         {
972             if(pContCopy)
973             {
974                 SfxItemSet aSet(pActiveShell->GetView().GetPool(),
975                             RES_COL, RES_COL,
976                             RES_BACKGROUND, RES_BACKGROUND,
977                             RES_FRM_SIZE, RES_FRM_SIZE,
978                             SID_ATTR_PAGE_SIZE, SID_ATTR_PAGE_SIZE,
979                             RES_LR_SPACE, RES_LR_SPACE,
980                             FN_PARAM_TOX_TYPE, FN_PARAM_TOX_TYPE,
981                             0);
982 
983                 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
984                 DBG_ASSERT(pFact, "Dialogdiet fail!");
985                 AbstractMultiTOXTabDialog* pDlg = pFact->CreateMultiTOXTabDialog( DLG_MULTI_TOX,
986                                                         this, aSet,
987                                                         *pActiveShell,
988                                                         0,
989                                                         USHRT_MAX,
990                                                         sal_True);
991                 DBG_ASSERT(pDlg, "Dialogdiet fail!");
992                 if(RET_OK == pDlg->Execute())
993                 {
994                     SwTOXDescription&  rDesc = pDlg->GetTOXDescription(
995                                                 pDlg->GetCurrentTOXType());
996                     SwTOXMgr aMgr(pActiveShell);
997                     SwTOXBase* pToInsert = 0;
998                     if(aMgr.UpdateOrInsertTOX(rDesc, &pToInsert, pDlg->GetOutputItemSet()))
999                         pActiveShell->InsertGlobalDocContent( *pContCopy, *pToInsert );
1000                 }
1001                 pCont = 0;
1002                 delete pDlg;
1003             }
1004         }
1005         break;
1006         case CTX_INSERT_FILE:
1007         {
1008             bDeleteContentCopy = false;
1009             pDocContent = pContCopy;
1010             InsertRegion( pContCopy );
1011             pCont = NULL;
1012         }
1013         break;
1014         case CTX_INSERT_NEW_FILE:
1015         {
1016             SfxViewFrame* pGlobFrm = pActiveShell->GetView().GetViewFrame();
1017             SwGlobalFrameListener_Impl aFrmListener(*pGlobFrm);
1018 
1019             sal_uLong nEntryPos = pEntry ? GetModel()->GetAbsPos(pEntry) : (sal_uLong)-1;
1020             // neues Dok anlegen
1021             SfxStringItem aFactory(SID_NEWDOCDIRECT,
1022                             SwDocShell::Factory().GetFilterContainer()->GetName());
1023 
1024              const SfxFrameItem* pItem = (SfxFrameItem*)
1025                             rDispatch.Execute(SID_NEWDOCDIRECT,
1026                                 SFX_CALLMODE_SYNCHRON, &aFactory, 0L);
1027 
1028             // sichern unter
1029             SfxFrame* pFrm = pItem ? pItem->GetFrame() : 0;
1030             SfxViewFrame* pFrame = pFrm ? pFrm->GetCurrentViewFrame() : 0;
1031             if( pFrame )
1032             {
1033                 const SfxBoolItem* pBool = (const SfxBoolItem*)
1034                         pFrame->GetDispatcher()->Execute(
1035                                 SID_SAVEASDOC, SFX_CALLMODE_SYNCHRON );
1036                 SfxObjectShell& rObj = *pFrame->GetObjectShell();
1037                 const SfxMedium* pMedium = rObj.GetMedium();
1038                 String sNewFile(pMedium->GetURLObject().GetMainURL(INetURLObject::DECODE_TO_IURI));
1039                 // Bereich mit dem Dok-Namen einfuegen
1040                 // eigenes Dok in den Vordergrund
1041 
1042                 if(aFrmListener.IsValid() && sNewFile.Len())
1043                 {
1044                     pGlobFrm->ToTop();
1045                     // durch das Update sind die Eintraege invalid
1046                     if(nEntryPos != (sal_uLong)-1)
1047                     {
1048                         Update( sal_False );
1049                         Display();
1050                         Select(GetModel()->GetEntryAtAbsPos(nEntryPos));
1051                         pEntry = FirstSelected();
1052                         pCont = pEntry ? (SwGlblDocContent*)pEntry->GetUserData() : 0;
1053                     }
1054                     else
1055                     {
1056                         pEntry = 0;
1057                         pCont = 0;
1058                     }
1059                     if(pBool->GetValue())
1060                     {
1061                         InsertRegion(pCont, &sNewFile);
1062                         pFrame->ToTop();
1063                     }
1064                     else
1065                         pFrame->GetDispatcher()->Execute(SID_CLOSEWIN,
1066                                                 SFX_CALLMODE_SYNCHRON);
1067                 }
1068                 else
1069                 {
1070                     pFrame->ToTop();
1071                     return;
1072                 }
1073             }
1074         }
1075         break;
1076         case CTX_INSERT_TEXT:
1077         {
1078             if(pCont)
1079                 pActiveShell->InsertGlobalDocContent(*pCont);
1080             else
1081             {
1082                 pActiveShell->SplitNode(); // leeres Dokument
1083                 pActiveShell->Up( sal_False, 1 );
1084             }
1085             pActiveShell->GetView().GetEditWin().GrabFocus();
1086         }
1087         break;
1088         case CTX_UPDATE:
1089             pCont = 0;
1090         break;
1091         default:;
1092         // hier passiert nichts
1093     }
1094     if(pCont)
1095         GotoContent(pCont);
1096     if(nSlot)
1097         rDispatch.Execute(nSlot);
1098     if(Update( sal_False ))
1099         Display();
1100     if ( bDeleteContentCopy )
1101         delete pContCopy;
1102     else
1103         bDeleteContentCopy = true;
1104 //  return sal_True;
1105 }
1106 
1107 /*-----------------16.06.97 07:57-------------------
1108 
1109 --------------------------------------------------*/
1110 IMPL_LINK( SwGlobalTree, Timeout, Timer*, EMPTYARG )
1111 {
1112     if(!HasFocus() && Update( sal_False ))
1113         Display();
1114     return 0;
1115 }
1116 
1117 /*-----------------13.06.97 16:56-------------------
1118 
1119 --------------------------------------------------*/
1120 void SwGlobalTree::GotoContent(const SwGlblDocContent* pCont)
1121 {
1122     pActiveShell->EnterStdMode();
1123 
1124     switch( pCont->GetType()  )
1125     {
1126         case GLBLDOC_UNKNOWN:
1127             pActiveShell->GotoGlobalDocContent(*pCont);
1128         break;
1129         case GLBLDOC_TOXBASE:
1130         {
1131             String sName = pCont->GetTOX()->GetTOXName();
1132             if (!pActiveShell->GotoNextTOXBase(&sName))
1133                 pActiveShell->GotoPrevTOXBase(&sName);
1134         }
1135         break;
1136         case GLBLDOC_SECTION:
1137         break;
1138     }
1139 
1140 }
1141 /*-----------------16.06.97 07:42-------------------
1142 
1143 --------------------------------------------------*/
1144 void    SwGlobalTree::ShowTree()
1145 {
1146     aUpdateTimer.Start();
1147     SvTreeListBox::Show();
1148 }
1149 /*-----------------16.06.97 07:42-------------------
1150 
1151 --------------------------------------------------*/
1152 void    SwGlobalTree::HideTree()
1153 {
1154     aUpdateTimer.Stop();
1155     SvTreeListBox::Hide();
1156 }
1157 /*-----------------18.06.97 10:02-------------------
1158 
1159 --------------------------------------------------*/
1160 void    SwGlobalTree::ExecCommand(sal_uInt16 nCmd)
1161 {
1162     SvLBoxEntry* pEntry = FirstSelected();
1163     DBG_ASSERT(pEntry, "gleich knallt's");
1164     if(FN_GLOBAL_EDIT == nCmd)
1165     {
1166         const SwGlblDocContent* pCont = (const SwGlblDocContent*)
1167                                                 pEntry->GetUserData();
1168         EditContent(pCont);
1169     }
1170     else
1171     {
1172         if(GetSelectionCount() == 1)
1173         {
1174             sal_Bool bMove = sal_False;
1175             sal_uInt16 nSource = (sal_uInt16)GetModel()->GetAbsPos(pEntry);
1176             sal_uInt16 nDest = nSource;
1177             switch(nCmd)
1178             {
1179                 case FN_ITEM_DOWN:
1180                 {
1181                     sal_uInt16 nEntryCount = (sal_uInt16)GetEntryCount();
1182                     bMove = nEntryCount > nSource + 1;
1183                     nDest+= 2;
1184                 }
1185                 break;
1186                 case FN_ITEM_UP:
1187                 {
1188                     if(nSource)
1189                         bMove = 0 != nSource;
1190                     nDest--;
1191                 }
1192                 break;
1193             }
1194             if( bMove && pActiveShell->MoveGlobalDocContent(
1195                 *pSwGlblDocContents, nSource, nSource + 1, nDest ) &&
1196                     Update( sal_False ))
1197                 Display();
1198         }
1199     }
1200 }
1201 
1202 /*-----------------16.06.97 07:43-------------------
1203 
1204 --------------------------------------------------*/
1205 sal_Bool    SwGlobalTree::Update(sal_Bool bHard)
1206 {
1207     SwView* pActView = GetParentWindow()->GetCreateView();
1208     sal_Bool bRet = sal_False;
1209     if(pActView && pActView->GetWrtShellPtr())
1210     {
1211         const SwWrtShell* pOldShell = pActiveShell;
1212         pActiveShell = pActView->GetWrtShellPtr();
1213         if(pActiveShell != pOldShell)
1214         {
1215             delete pSwGlblDocContents;
1216             pSwGlblDocContents = 0;
1217         }
1218         if(!pSwGlblDocContents)
1219         {
1220             pSwGlblDocContents = new SwGlblDocContents;
1221             bRet = sal_True;
1222             pActiveShell->GetGlobalDocContent(*pSwGlblDocContents);
1223         }
1224         else
1225         {
1226             sal_Bool bCopy = sal_False;
1227             SwGlblDocContents* pTempContents  = new SwGlblDocContents;
1228             pActiveShell->GetGlobalDocContent(*pTempContents);
1229             if(pTempContents->Count() != pSwGlblDocContents->Count() ||
1230                     pTempContents->Count() != GetEntryCount())
1231             {
1232                 bRet = sal_True;
1233                 bCopy = sal_True;
1234             }
1235             else
1236             {
1237                 for(sal_uInt16 i = 0; i < pTempContents->Count() && !bCopy; i++)
1238                 {
1239                     SwGlblDocContent* pLeft = pTempContents->GetObject(i);
1240                     SwGlblDocContent* pRight = pSwGlblDocContents->GetObject(i);
1241                     GlobalDocContentType eType = pLeft->GetType();
1242                     SvLBoxEntry* pEntry = GetEntry(i);
1243                     String sTemp = GetEntryText(pEntry);
1244                     if (
1245                          eType != pRight->GetType() ||
1246                          (
1247                            eType == GLBLDOC_SECTION &&
1248                            pLeft->GetSection()->GetSectionName() != sTemp
1249                          ) ||
1250                          (
1251                            eType == GLBLDOC_TOXBASE &&
1252                            pLeft->GetTOX()->GetTitle() != sTemp
1253                          )
1254                        )
1255                     {
1256                         bCopy = bRet = sal_True;
1257                     }
1258                 }
1259             }
1260             if(bCopy || bHard)
1261             {
1262                 sal_uInt16 i;
1263 
1264                 pSwGlblDocContents->DeleteAndDestroy(0, pSwGlblDocContents->Count());
1265                 for( i = 0; i < pTempContents->Count(); i++)
1266                 {
1267                     pSwGlblDocContents->Insert(pTempContents->GetObject(i));
1268                 }
1269                 for( i = pTempContents->Count(); i; i--)
1270                     pTempContents->Remove(i - 1);
1271 
1272             }
1273             delete pTempContents;
1274         }
1275 
1276     }
1277     else
1278     {
1279         Clear();
1280         if(pSwGlblDocContents)
1281             pSwGlblDocContents->DeleteAndDestroy(0, pSwGlblDocContents->Count());
1282     }
1283     // hier muss noch eine Veraenderungspruefung rein!
1284     return bRet;
1285 }
1286 
1287 /*-----------------25.06.97 16:20-------------------
1288 
1289 --------------------------------------------------*/
1290 void SwGlobalTree::OpenDoc(const SwGlblDocContent* pCont)
1291 {
1292     String sFileName(pCont->GetSection()->GetLinkFileName().GetToken(0,
1293             sfx2::cTokenSeperator));
1294     sal_Bool bFound = sal_False;
1295     const SfxObjectShell* pCurr = SfxObjectShell::GetFirst();
1296     while( !bFound && pCurr )
1297     {
1298         if(pCurr->GetMedium() &&
1299             String(pCurr->GetMedium()->GetURLObject().GetMainURL(INetURLObject::DECODE_TO_IURI)) == sFileName)
1300         {
1301             bFound = sal_True;
1302             SwGlobalTree::SetShowShell(pCurr);
1303             Application::PostUserEvent( STATIC_LINK(
1304                         this, SwGlobalTree, ShowFrameHdl ) );
1305             pCurr = 0;
1306         }
1307         else
1308             pCurr = SfxObjectShell::GetNext(*pCurr);
1309     }
1310     if(!bFound)
1311     {
1312         SfxStringItem aURL(SID_FILE_NAME,
1313             sFileName);
1314         SfxBoolItem aReadOnly(SID_DOC_READONLY, sal_False);
1315         SfxStringItem aTargetFrameName( SID_TARGETNAME, String::CreateFromAscii("_blank") );
1316         SfxStringItem aReferer(SID_REFERER, pActiveShell->GetView().GetDocShell()->GetTitle());
1317         pActiveShell->GetView().GetViewFrame()->GetDispatcher()->
1318                 Execute(SID_OPENDOC, SFX_CALLMODE_ASYNCHRON,
1319                             &aURL, &aReadOnly, &aReferer, &aTargetFrameName, 0L);
1320     }
1321 }
1322 
1323 /*-----------------25.06.97 16:08-------------------
1324 
1325 --------------------------------------------------*/
1326 IMPL_LINK(  SwGlobalTree, DoubleClickHdl, SwGlobalTree *, EMPTYARG )
1327 {
1328     SvLBoxEntry* pEntry = GetCurEntry();
1329     SwGlblDocContent* pCont = (SwGlblDocContent*)pEntry->GetUserData();
1330     if(pCont->GetType() == GLBLDOC_SECTION)
1331         OpenDoc(pCont);
1332     else
1333     {
1334         GotoContent(pCont);
1335         pActiveShell->GetView().GetEditWin().GrabFocus();
1336     }
1337     return 0;
1338 }
1339 
1340 /*-----------------07.10.97 08:09-------------------
1341 
1342 --------------------------------------------------*/
1343 IMPL_STATIC_LINK_NOINSTANCE(SwGlobalTree, ShowFrameHdl, SwGlobalTree*, EMPTYARG)
1344 {
1345     if(SwGlobalTree::GetShowShell())
1346         SfxViewFrame::GetFirst(SwGlobalTree::GetShowShell())->ToTop();
1347     SwGlobalTree::SetShowShell(0);
1348     return 0;
1349 }
1350 /* -----------------04.11.98 10:43-------------------
1351  *
1352  * --------------------------------------------------*/
1353 void SwGlobalTree::InitEntry(SvLBoxEntry* pEntry,
1354         const XubString& rStr ,const Image& rImg1,const Image& rImg2,
1355         SvLBoxButtonKind eButtonKind)
1356 {
1357     sal_uInt16 nColToHilite = 1; //0==Bitmap;1=="Spalte1";2=="Spalte2"
1358     SvTreeListBox::InitEntry( pEntry, rStr, rImg1, rImg2, eButtonKind );
1359     SvLBoxString* pCol = (SvLBoxString*)pEntry->GetItem( nColToHilite );
1360     SwLBoxString* pStr = new SwLBoxString( pEntry, 0, pCol->GetText() );
1361     pEntry->ReplaceItem( pStr, nColToHilite );
1362 }
1363 /* -----------------04.11.98 10:39-------------------
1364  *
1365  * --------------------------------------------------*/
1366 
1367 void SwLBoxString::Paint( const Point& rPos, SvLBox& rDev, sal_uInt16 nFlags,
1368     SvLBoxEntry* pEntry )
1369 {
1370     SwGlblDocContent* pCont = (SwGlblDocContent*)pEntry->GetUserData();
1371     const SwSection* pSect;
1372     if(pCont->GetType() == GLBLDOC_SECTION &&
1373         !(pSect = pCont->GetSection())->IsConnectFlag() )
1374     {
1375         Font aOldFont( rDev.GetFont());
1376         Font aFont(aOldFont);
1377         Color aCol( COL_LIGHTRED );
1378         aFont.SetColor( aCol );
1379         rDev.SetFont( aFont );
1380         rDev.DrawText( rPos, GetText() );
1381         rDev.SetFont( aOldFont );
1382     }
1383     else
1384         SvLBoxString::Paint( rPos, rDev, nFlags, pEntry);
1385 }
1386 /* -----------------------------06.05.2002 10:20------------------------------
1387 
1388  ---------------------------------------------------------------------------*/
1389 void    SwGlobalTree::DataChanged( const DataChangedEvent& rDCEvt )
1390 {
1391     if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
1392          (rDCEvt.GetFlags() & SETTINGS_STYLE) )
1393     {
1394         sal_uInt16 nResId = GetSettings().GetStyleSettings().GetHighContrastMode() ? IMG_NAVI_ENTRYBMPH : IMG_NAVI_ENTRYBMP;
1395         aEntryImages = ImageList(SW_RES(nResId));
1396         Update(sal_True);
1397     }
1398     SvTreeListBox::DataChanged( rDCEvt );
1399 }
1400 
1401 void SwGlobalTree::InsertRegion( const SwGlblDocContent* _pContent, const Sequence< OUString >& _rFiles )
1402 {
1403     sal_Int32 nFiles = _rFiles.getLength();
1404     if ( nFiles )
1405     {
1406         sal_Bool bMove = sal_False;
1407         if ( !_pContent )
1408         {
1409             SvLBoxEntry* pLast = (SvLBoxEntry*)LastVisible();
1410             _pContent = (SwGlblDocContent*)pLast->GetUserData();
1411             bMove = sal_True;
1412         }
1413         String sFilePassword;
1414         sal_uInt16 nEntryCount = (sal_uInt16)GetEntryCount();
1415         const OUString* pFileNames = _rFiles.getConstArray();
1416         SwWrtShell& rSh = GetParentWindow()->GetCreateView()->GetWrtShell();
1417         rSh.StartAction();
1418         // after insertion of the first new content the 'pCont' parameter becomes invalid
1419         // find the index of the 'anchor' content to always use a current anchor content
1420         sal_uInt16 nAnchorContent = pSwGlblDocContents->Count() - 1;
1421         if ( !bMove )
1422         {
1423             for( sal_uInt16 nContent = 0; nContent < pSwGlblDocContents->Count(); ++nContent )
1424             {
1425                 if( *_pContent == *pSwGlblDocContents->GetObject( nContent ) )
1426                 {
1427                     nAnchorContent = nContent;
1428                     break;
1429                 }
1430             }
1431         }
1432         SwGlblDocContents aTempContents;
1433         for ( sal_Int32 nFile = 0; nFile < nFiles; ++nFile )
1434         {
1435             //update the global document content after each inserted document
1436             rSh.GetGlobalDocContent(aTempContents);
1437             SwGlblDocContent* pAnchorContent = 0;
1438             DBG_ASSERT(aTempContents.Count() > (nAnchorContent + nFile), "invalid anchor content -> last insertion failed");
1439             if ( aTempContents.Count() > (nAnchorContent + nFile) )
1440                 pAnchorContent = aTempContents.GetObject(nAnchorContent + (sal_uInt16)nFile);
1441             else
1442                 pAnchorContent = aTempContents.GetObject(aTempContents.Count() - 1);
1443             String sFileName(pFileNames[nFile]);
1444             INetURLObject aFileUrl;
1445             aFileUrl.SetSmartURL( sFileName );
1446             String sSectionName(String(aFileUrl.GetLastName(
1447                 INetURLObject::DECODE_UNAMBIGUOUS)).GetToken(0,
1448                 sfx2::cTokenSeperator));
1449             sal_uInt16 nSectCount = rSh.GetSectionFmtCount();
1450             String sTempSectionName(sSectionName);
1451             sal_uInt16 nAddNumber = 0;
1452             sal_uInt16 nCount = 0;
1453             // evtl : und Index anhaengen, wenn der Bereichsname schon vergeben ist
1454             while ( nCount < nSectCount )
1455             {
1456                 const SwSectionFmt& rFmt = rSh.GetSectionFmt(nCount);
1457                 if ((rFmt.GetSection()->GetSectionName() == sTempSectionName)
1458                     && rFmt.IsInNodesArr())
1459                 {
1460                     nCount = 0;
1461                     nAddNumber++;
1462                     sTempSectionName = sSectionName;
1463                     sTempSectionName += ':';
1464                     sTempSectionName += String::CreateFromInt32( nAddNumber );
1465                 }
1466                 else
1467                     nCount++;
1468             }
1469 
1470             if ( nAddNumber )
1471                 sSectionName = sTempSectionName;
1472 
1473             SwSectionData aSectionData(CONTENT_SECTION, sSectionName);
1474             aSectionData.SetProtectFlag(true);
1475             aSectionData.SetHidden(false);
1476 
1477             aSectionData.SetLinkFileName(sFileName);
1478             aSectionData.SetType(FILE_LINK_SECTION);
1479             aSectionData.SetLinkFilePassword( sFilePassword );
1480 
1481             rSh.InsertGlobalDocContent( *pAnchorContent, aSectionData );
1482         }
1483         if ( bMove )
1484         {
1485             Update( sal_False );
1486             rSh.MoveGlobalDocContent(
1487                 *pSwGlblDocContents, nEntryCount, nEntryCount + (sal_uInt16)nFiles, nEntryCount - (sal_uInt16)nFiles );
1488         }
1489         rSh.EndAction();
1490         Update( sal_False );
1491         Display();
1492     }
1493 }
1494 
1495 IMPL_LINK( SwGlobalTree, DialogClosedHdl, sfx2::FileDialogHelper*, _pFileDlg )
1496 {
1497     Application::SetDefDialogParent( pDefParentWin );
1498     if ( ERRCODE_NONE == _pFileDlg->GetError() )
1499     {
1500         SfxMediumList* pMedList = pDocInserter->CreateMediumList();
1501         if ( pMedList )
1502         {
1503             Sequence< OUString >aFileNames( pMedList->Count() );
1504             OUString* pFileNames = aFileNames.getArray();
1505             SfxMedium* pMed = pMedList->First();
1506             sal_Int32 nPos = 0;
1507             while ( pMed )
1508             {
1509                 String sFileName = pMed->GetURLObject().GetMainURL( INetURLObject::NO_DECODE );
1510                 sFileName += sfx2::cTokenSeperator;
1511                 sFileName += pMed->GetFilter()->GetFilterName();
1512                 sFileName += sfx2::cTokenSeperator;
1513                 pFileNames[nPos++] = sFileName;
1514                 pMed = pMedList->Next();
1515             }
1516             delete pMedList;
1517             InsertRegion( pDocContent, aFileNames );
1518             DELETEZ( pDocContent );
1519         }
1520     }
1521     return 0;
1522 }
1523 
1524