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