bump product version to 4.1.6.2
[LibreOffice.git] / sw / source / ui / utlui / glbltree.cxx
blob5bc1f08cc714944b3c019bc60d2400630e5441a1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <vcl/msgbox.hxx>
21 #include <svl/stritem.hxx>
22 #include <sfx2/fcontnr.hxx>
23 #include <sfx2/linkmgr.hxx>
24 #include <sfx2/dispatch.hxx>
25 #include <svl/urihelper.hxx>
26 #include <sfx2/docfile.hxx>
27 #include <vcl/help.hxx>
28 #include <sot/filelist.hxx>
29 #include <svl/eitem.hxx>
30 #include <svl/urlbmk.hxx>
31 #include <vcl/graphicfilter.hxx>
32 #include "svtools/treelistentry.hxx"
33 #include <sfx2/docinsert.hxx>
34 #include <sfx2/filedlghelper.hxx>
36 #include <sfx2/app.hxx>
37 #include <swmodule.hxx>
38 #include <wrtsh.hxx>
39 #include <view.hxx>
40 #include <docsh.hxx>
41 #include <content.hxx>
42 #include <edglbldc.hxx>
43 #include <section.hxx>
44 #include <tox.hxx>
45 #include <cnttab.hxx>
46 #include <navipi.hxx>
47 #include <navicont.hxx>
48 #include <edtwin.hxx>
49 #include <uitool.hxx>
51 #include <cmdid.h>
52 #include <helpid.h>
53 #include <navipi.hrc>
54 #include <utlui.hrc>
55 #include <comcore.hrc>
56 #include <globals.hrc>
57 #include "swabstdlg.hxx"
59 using namespace ::com::sun::star::uno;
61 // Context menu for GlobalTree
62 #define CTX_INSERT_ANY_INDEX 10
63 #define CTX_INSERT_FILE 11
64 #define CTX_INSERT_NEW_FILE 12
65 #define CTX_INSERT_TEXT 13
67 #define CTX_UPDATE_SEL 20
68 #define CTX_UPDATE_INDEX 21
69 #define CTX_UPDATE_LINK 22
70 #define CTX_UPDATE_ALL 23
72 #define CTX_UPDATE 1
73 #define CTX_INSERT 2
74 #define CTX_EDIT 3
75 #define CTX_DELETE 4
76 #define CTX_EDIT_LINK 5
78 #define GLOBAL_UPDATE_TIMEOUT 2000
80 // Flags for PopupMenu-enable/disable
81 #define ENABLE_INSERT_IDX 0x0001
82 #define ENABLE_INSERT_FILE 0x0002
83 #define ENABLE_INSERT_TEXT 0x0004
84 #define ENABLE_EDIT 0x0008
85 #define ENABLE_DELETE 0x0010
86 #define ENABLE_UPDATE 0x0020
87 #define ENABLE_UPDATE_SEL 0x0040
88 #define ENABLE_EDIT_LINK 0x0080
90 // TabPos: push to left
91 #define GLBL_TABPOS_SUB 5
93 const SfxObjectShell* SwGlobalTree::pShowShell = 0;
94 static const char* aHelpForMenu[] =
96 0, //
97 HID_GLBLTREE_UPDATE, //CTX_UPDATE
98 HID_GLBLTREE_INSERT, //CTX_INSERT
99 HID_GLBLTREE_EDIT, //CTX_EDIT
100 HID_GLBLTREE_DEL, //CTX_DELETE
101 HID_GLBLTREE_EDIT_LINK, //CTX_EDIT_LINK
102 0, //
103 0, //
104 0, //
105 0, //
106 HID_GLBLTREE_INS_IDX, //CTX_INSERT_ANY_INDEX
107 HID_GLBLTREE_INS_FILE, //CTX_INSERT_FILE
108 HID_GLBLTREE_INS_NEW_FILE, //CTX_INSERT_NEW_FILE
109 HID_GLBLTREE_INS_TEXT, //CTX_INSERT_TEXT
110 0, //
111 0, //
112 0, //
113 0, //
114 0, //
115 0, //
116 HID_GLBLTREE_UPD_SEL, //CTX_UPDATE_SEL
117 HID_GLBLTREE_UPD_IDX, //CTX_UPDATE_INDEX
118 HID_GLBLTREE_UPD_LINK, //CTX_UPDATE_LINK
119 HID_GLBLTREEUPD_ALL //CTX_UPDATE_ALL
122 class SwGlobalFrameListener_Impl : public SfxListener
124 bool bValid;
125 public:
126 SwGlobalFrameListener_Impl(SfxViewFrame& rFrame) :
127 bValid(true)
129 StartListening(rFrame);
132 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
134 bool IsValid() const {return bValid;}
137 void SwGlobalFrameListener_Impl::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint )
139 if( rHint.ISA(SfxSimpleHint) &&
140 (((SfxSimpleHint&) rHint).GetId() == SFX_HINT_DYING))
141 bValid = false;
144 SwGlobalTree::SwGlobalTree(Window* pParent, const ResId& rResId) :
146 SvTreeListBox(pParent, rResId),
148 pActiveShell ( NULL ),
149 pEmphasisEntry ( NULL ),
150 pDDSource ( NULL ),
151 pSwGlblDocContents ( NULL ),
152 pDefParentWin ( NULL ),
153 pDocContent ( NULL ),
154 pDocInserter ( NULL ),
156 bIsInternalDrag ( false ),
157 bLastEntryEmphasis ( false ),
158 bIsImageListInitialized ( false )
161 SetDragDropMode(SV_DRAGDROP_APP_COPY |
162 SV_DRAGDROP_CTRL_MOVE |
163 SV_DRAGDROP_ENABLE_TOP );
165 aUpdateTimer.SetTimeout(GLOBAL_UPDATE_TIMEOUT);
166 aUpdateTimer.SetTimeoutHdl(LINK(this, SwGlobalTree, Timeout));
167 aUpdateTimer.Start();
168 for(sal_uInt16 i = 0; i < GLOBAL_CONTEXT_COUNT; i++)
170 aContextStrings[i] = SW_RESSTR(i+ ST_GLOBAL_CONTEXT_FIRST);
172 SetHelpId(HID_NAVIGATOR_GLOB_TREELIST);
173 SelectHdl();
174 SetDoubleClickHdl(LINK(this, SwGlobalTree, DoubleClickHdl));
175 EnableContextMenuHandling();
178 SwGlobalTree::~SwGlobalTree()
180 delete pSwGlblDocContents;
181 delete pDocInserter;
184 sal_Int8 SwGlobalTree::ExecuteDrop( const ExecuteDropEvent& rEvt )
186 sal_Int8 nRet = DND_ACTION_NONE;
187 SvTreeListEntry* pLast = (SvTreeListEntry*)LastVisible();
188 if(pEmphasisEntry)
190 ImplShowTargetEmphasis( Prev(pEmphasisEntry), sal_False );
191 pEmphasisEntry = 0;
193 else if(bLastEntryEmphasis && pLast)
195 ImplShowTargetEmphasis( pLast, sal_False);
198 SvTreeListEntry* pDropEntry = bLastEntryEmphasis ? 0 : GetEntry(rEvt.maPosPixel);
199 if( bIsInternalDrag )
201 SvTreeListEntry* pDummy = 0;
202 sal_uLong nInsertionPos = LIST_APPEND;
203 NotifyMoving( pDropEntry, pDDSource, pDummy, nInsertionPos );
205 else
207 TransferableDataHelper aData( rEvt.maDropEvent.Transferable );
209 String sFileName;
210 const SwGlblDocContent* pCnt = pDropEntry ?
211 (const SwGlblDocContent*)pDropEntry->GetUserData() :
213 if( aData.HasFormat( FORMAT_FILE_LIST ))
215 nRet = rEvt.mnAction;
216 SwGlblDocContents* pTempContents = new SwGlblDocContents;
217 int nAbsContPos = pDropEntry ?
218 (int) GetModel()->GetAbsPos(pDropEntry):
219 - 1;
220 sal_uInt16 nEntryCount = (sal_uInt16)GetEntryCount();
222 // Get data
223 FileList aFileList;
224 aData.GetFileList( FORMAT_FILE_LIST, aFileList );
225 for ( sal_uInt16 n = (sal_uInt16)aFileList.Count(); n--; )
227 sFileName = aFileList.GetFile(n);
228 InsertRegion(pCnt, &sFileName);
229 // The list of contents must be newly fetched after inserting,
230 // to not work on an old content.
231 if(n)
233 pActiveShell->GetGlobalDocContent(*pTempContents);
234 // If the file was successfully inserted,
235 // then the next content must also be fetched.
236 if(nEntryCount < pTempContents->size())
238 nEntryCount++;
239 nAbsContPos++;
240 pCnt = (*pTempContents)[ nAbsContPos ];
244 delete pTempContents;
246 else if( 0 != (sFileName =
247 SwNavigationPI::CreateDropFileName( aData )).Len())
249 INetURLObject aTemp(sFileName);
250 GraphicDescriptor aDesc(aTemp);
251 if( !aDesc.Detect() ) // accept no graphics
253 nRet = rEvt.mnAction;
254 InsertRegion(pCnt, &sFileName);
258 bLastEntryEmphasis = false;
259 return nRet;
263 sal_Int8 SwGlobalTree::AcceptDrop( const AcceptDropEvent& rEvt )
265 sal_Int8 nRet = rEvt.mnAction;
267 //initiate scrolling
268 GetDropTarget( rEvt.maPosPixel );
269 SvTreeListEntry* pLast = (SvTreeListEntry*)LastVisible();
270 if( rEvt.mbLeaving )
272 if( pEmphasisEntry )
274 ImplShowTargetEmphasis( Prev(pEmphasisEntry), sal_False );
275 pEmphasisEntry = 0;
277 else if(bLastEntryEmphasis && pLast)
279 ImplShowTargetEmphasis( pLast, sal_False);
281 bLastEntryEmphasis = false;
283 else
285 SvTreeListEntry* pDropEntry = GetEntry( rEvt.maPosPixel );
286 if(bIsInternalDrag)
288 if( pDDSource != pDropEntry )
289 nRet = rEvt.mnAction;
291 else if( IsDropFormatSupported( FORMAT_FILE ) ||
292 IsDropFormatSupported( FORMAT_STRING ) ||
293 IsDropFormatSupported( FORMAT_FILE_LIST ) ||
294 IsDropFormatSupported( SOT_FORMATSTR_ID_SOLK ) ||
295 IsDropFormatSupported( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK )||
296 IsDropFormatSupported( SOT_FORMATSTR_ID_FILECONTENT ) ||
297 IsDropFormatSupported( SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR ) ||
298 IsDropFormatSupported( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR ) ||
299 IsDropFormatSupported( SOT_FORMATSTR_ID_FILENAME ))
300 nRet = DND_ACTION_LINK;
302 if(pEmphasisEntry && pEmphasisEntry != pDropEntry)
303 ImplShowTargetEmphasis( Prev(pEmphasisEntry), sal_False );
304 else if(pLast && bLastEntryEmphasis && pDropEntry)
306 ImplShowTargetEmphasis( pLast, sal_False);
307 bLastEntryEmphasis = false;
310 if(pDropEntry)
311 ImplShowTargetEmphasis( Prev(pDropEntry), DND_ACTION_NONE != nRet );
312 else if(pLast)
314 ImplShowTargetEmphasis( pLast, DND_ACTION_NONE != nRet );
315 bLastEntryEmphasis = true;
317 pEmphasisEntry = pDropEntry;
319 return nRet;
322 PopupMenu* SwGlobalTree::CreateContextMenu()
324 PopupMenu* pPop = 0;
325 if(pActiveShell &&
326 !pActiveShell->GetView().GetDocShell()->IsReadOnly())
328 sal_uInt16 nEnableFlags = GetEnableFlags();
329 pPop = new PopupMenu;
330 PopupMenu* pSubPop1 = new PopupMenu;
331 PopupMenu* pSubPop2 = new PopupMenu;
333 for (sal_uInt16 i = CTX_UPDATE_SEL; i <= CTX_UPDATE_ALL; i++)
335 pSubPop2->InsertItem( i, aContextStrings[ST_UPDATE_SEL - ST_GLOBAL_CONTEXT_FIRST - CTX_UPDATE_SEL+ i] );
336 pSubPop2->SetHelpId(i, aHelpForMenu[i]);
338 pSubPop2->EnableItem(CTX_UPDATE_SEL, 0 != (nEnableFlags & ENABLE_UPDATE_SEL));
340 pSubPop1->InsertItem(CTX_INSERT_ANY_INDEX, aContextStrings[ST_INDEX - ST_GLOBAL_CONTEXT_FIRST]);
341 pSubPop1->SetHelpId(CTX_INSERT_ANY_INDEX, aHelpForMenu[CTX_INSERT_ANY_INDEX]);
342 pSubPop1->InsertItem(CTX_INSERT_FILE, aContextStrings[ST_FILE - ST_GLOBAL_CONTEXT_FIRST]);
343 pSubPop1->SetHelpId(CTX_INSERT_FILE, aHelpForMenu[CTX_INSERT_FILE]);
344 pSubPop1->InsertItem(CTX_INSERT_NEW_FILE, aContextStrings[ST_NEW_FILE - ST_GLOBAL_CONTEXT_FIRST]);
345 pSubPop1->SetHelpId(CTX_INSERT_NEW_FILE, aHelpForMenu[CTX_INSERT_NEW_FILE]);
346 pSubPop1->InsertItem(CTX_INSERT_TEXT, aContextStrings[ST_TEXT - ST_GLOBAL_CONTEXT_FIRST]);
347 pSubPop1->SetHelpId(CTX_INSERT_TEXT, aHelpForMenu[CTX_INSERT_TEXT]);
350 pPop->InsertItem(CTX_UPDATE, aContextStrings[ST_UPDATE - ST_GLOBAL_CONTEXT_FIRST]);
351 pPop->SetHelpId(CTX_UPDATE, aHelpForMenu[CTX_UPDATE]);
352 pPop->InsertItem(CTX_EDIT, aContextStrings[ST_EDIT_CONTENT - ST_GLOBAL_CONTEXT_FIRST]);
353 pPop->SetHelpId(CTX_EDIT, aHelpForMenu[CTX_EDIT]);
354 if(nEnableFlags&ENABLE_EDIT_LINK)
356 pPop->InsertItem(CTX_EDIT_LINK, aContextStrings[ST_EDIT_LINK - ST_GLOBAL_CONTEXT_FIRST]);
357 pPop->SetHelpId(CTX_EDIT_LINK, aHelpForMenu[CTX_EDIT_LINK]);
359 pPop->InsertItem(CTX_INSERT, aContextStrings[ST_INSERT - ST_GLOBAL_CONTEXT_FIRST]);
360 pPop->SetHelpId(CTX_INSERT, aHelpForMenu[CTX_INSERT]);
361 pPop->InsertSeparator() ;
362 pPop->InsertItem(CTX_DELETE, aContextStrings[ST_DELETE - ST_GLOBAL_CONTEXT_FIRST]);
363 pPop->SetHelpId(CTX_DELETE, aHelpForMenu[CTX_DELETE]);
365 //disabling if applicable
366 pSubPop1->EnableItem(CTX_INSERT_ANY_INDEX, 0 != (nEnableFlags & ENABLE_INSERT_IDX ));
367 pSubPop1->EnableItem(CTX_INSERT_TEXT, 0 != (nEnableFlags & ENABLE_INSERT_TEXT));
368 pSubPop1->EnableItem(CTX_INSERT_FILE, 0 != (nEnableFlags & ENABLE_INSERT_FILE));
369 pSubPop1->EnableItem(CTX_INSERT_NEW_FILE, 0 != (nEnableFlags & ENABLE_INSERT_FILE));
371 pPop->EnableItem(CTX_UPDATE, 0 != (nEnableFlags & ENABLE_UPDATE));
372 pPop->EnableItem(CTX_INSERT, 0 != (nEnableFlags & ENABLE_INSERT_IDX));
373 pPop->EnableItem(CTX_EDIT, 0 != (nEnableFlags & ENABLE_EDIT));
374 pPop->EnableItem(CTX_DELETE, 0 != (nEnableFlags & ENABLE_DELETE));
377 pPop->SetPopupMenu( CTX_INSERT, pSubPop1 );
378 pPop->SetPopupMenu( CTX_UPDATE, pSubPop2 );
380 return pPop;
383 void SwGlobalTree::TbxMenuHdl(sal_uInt16 nTbxId, ToolBox* pBox)
385 sal_uInt16 nEnableFlags = GetEnableFlags();
386 if(FN_GLOBAL_OPEN == nTbxId)
388 PopupMenu *pMenu = new PopupMenu;
389 for (sal_uInt16 i = CTX_INSERT_ANY_INDEX; i <= CTX_INSERT_TEXT; i++)
391 pMenu->InsertItem( i, aContextStrings[ST_INDEX - ST_GLOBAL_CONTEXT_FIRST - CTX_INSERT_ANY_INDEX + i] );
392 pMenu->SetHelpId(i, aHelpForMenu[i] );
394 pMenu->EnableItem(CTX_INSERT_ANY_INDEX, 0 != (nEnableFlags & ENABLE_INSERT_IDX ));
395 pMenu->EnableItem(CTX_INSERT_TEXT, 0 != (nEnableFlags & ENABLE_INSERT_TEXT));
396 pMenu->EnableItem(CTX_INSERT_FILE, 0 != (nEnableFlags & ENABLE_INSERT_FILE));
397 pMenu->EnableItem(CTX_INSERT_NEW_FILE, 0 != (nEnableFlags & ENABLE_INSERT_FILE));
398 pMenu->SetSelectHdl(LINK(this, SwGlobalTree, PopupHdl));
399 pMenu->Execute( pBox, pBox->GetItemRect(nTbxId).BottomLeft());
400 delete pMenu;
401 pBox->EndSelection();
402 pBox->Invalidate();
404 else if(FN_GLOBAL_UPDATE == nTbxId)
406 PopupMenu *pMenu = new PopupMenu;
407 for (sal_uInt16 i = CTX_UPDATE_SEL; i <= CTX_UPDATE_ALL; i++)
409 pMenu->InsertItem( i, aContextStrings[ST_UPDATE_SEL - ST_GLOBAL_CONTEXT_FIRST - CTX_UPDATE_SEL+ i] );
410 pMenu->SetHelpId(i, aHelpForMenu[i] );
412 pMenu->EnableItem(CTX_UPDATE_SEL, 0 != (nEnableFlags & ENABLE_UPDATE_SEL));
413 pMenu->SetSelectHdl(LINK(this, SwGlobalTree, PopupHdl));
414 pMenu->Execute( pBox, pBox->GetItemRect(nTbxId).BottomLeft());
415 delete pMenu;
416 pBox->EndSelection();
417 pBox->Invalidate();
421 sal_uInt16 SwGlobalTree::GetEnableFlags() const
423 SvTreeListEntry* pEntry = FirstSelected();
424 sal_uInt16 nSelCount = (sal_uInt16)GetSelectionCount();
425 sal_uInt16 nEntryCount = (sal_uInt16)GetEntryCount();
426 SvTreeListEntry* pPrevEntry = pEntry ? Prev(pEntry) : 0;
428 sal_uInt16 nRet = 0;
429 if(nSelCount == 1 || !nEntryCount)
430 nRet |= ENABLE_INSERT_IDX|ENABLE_INSERT_FILE;
431 if(nSelCount == 1)
433 nRet |= ENABLE_EDIT;
434 if( ((SwGlblDocContent*)pEntry->GetUserData())->GetType() != GLBLDOC_UNKNOWN &&
435 (!pPrevEntry || ((SwGlblDocContent*)pPrevEntry->GetUserData())->GetType() != GLBLDOC_UNKNOWN))
436 nRet |= ENABLE_INSERT_TEXT;
437 if( GLBLDOC_SECTION == ((SwGlblDocContent*)pEntry->GetUserData())->GetType() )
438 nRet |= ENABLE_EDIT_LINK;
440 else if(!nEntryCount)
442 nRet |= ENABLE_INSERT_TEXT;
444 if(nEntryCount)
445 nRet |= ENABLE_UPDATE|ENABLE_DELETE;
446 if(nSelCount)
447 nRet |= ENABLE_UPDATE_SEL;
448 return nRet;
451 void SwGlobalTree::RequestHelp( const HelpEvent& rHEvt )
453 bool bParent = true;
454 Update(sal_True);
455 Display(true);
456 if( rHEvt.GetMode() & HELPMODE_QUICK )
458 Point aPos( ScreenToOutputPixel( rHEvt.GetMousePosPixel() ));
459 SvTreeListEntry* pEntry = GetEntry( aPos );
460 const SwGlblDocContent* pCont = pEntry ?
461 (const SwGlblDocContent*)pEntry->GetUserData() : 0;
462 if( pCont && GLBLDOC_SECTION == pCont->GetType())
464 bParent = false;
465 SvLBoxTab* pTab;
466 SvLBoxItem* pItem = GetItem( pEntry, aPos.X(), &pTab );
467 if (pItem && SV_ITEM_ID_LBOXSTRING == pItem->GetType())
469 const SwSection* pSect = pCont->GetSection();
470 String sEntry = pSect->GetLinkFileName().GetToken(0, sfx2::cTokenSeparator);
471 if(!pSect->IsConnectFlag())
472 sEntry.Insert(aContextStrings[ST_BROKEN_LINK - ST_GLOBAL_CONTEXT_FIRST], 0 );
473 Point aEntryPos = GetEntryPosition( pEntry );
475 aEntryPos.X() = GetTabPos( pEntry, pTab );
476 Size aSize( pItem->GetSize( this, pEntry ) );
478 if((aEntryPos.X() + aSize.Width()) > GetSizePixel().Width())
479 aSize.Width() = GetSizePixel().Width() - aEntryPos.X();
481 aEntryPos = OutputToScreenPixel(aEntryPos);
482 Rectangle aItemRect( aEntryPos, aSize );
483 if(Help::IsBalloonHelpEnabled())
485 aEntryPos.X() += aSize.Width();
486 Help::ShowBalloon( this, aEntryPos, aItemRect, sEntry );
488 else
489 Help::ShowQuickHelp( this, aItemRect, sEntry,
490 QUICKHELP_LEFT|QUICKHELP_VCENTER );
495 if(bParent)
496 SvTreeListBox::RequestHelp(rHEvt);
499 void SwGlobalTree::SelectHdl()
502 sal_uInt16 nSelCount = (sal_uInt16)GetSelectionCount();
503 SvTreeListEntry* pSel = FirstSelected();
504 sal_uInt16 nAbsPos = pSel ? (sal_uInt16)GetModel()->GetAbsPos(pSel) : 0;
505 SwNavigationPI* pNavi = GetParentWindow();
506 bool bReadonly = !pActiveShell ||
507 pActiveShell->GetView().GetDocShell()->IsReadOnly();
508 pNavi->aGlobalToolBox.EnableItem(FN_GLOBAL_EDIT, nSelCount == 1 && !bReadonly);
509 pNavi->aGlobalToolBox.EnableItem(FN_GLOBAL_OPEN, nSelCount <= 1 && !bReadonly);
510 pNavi->aGlobalToolBox.EnableItem(FN_GLOBAL_UPDATE, GetEntryCount() > 0 && !bReadonly);
511 pNavi->aGlobalToolBox.EnableItem(FN_ITEM_UP,
512 nSelCount == 1 && nAbsPos && !bReadonly);
513 pNavi->aGlobalToolBox.EnableItem(FN_ITEM_DOWN,
514 nSelCount == 1 && nAbsPos < ((sal_uInt16)GetEntryCount()) - 1 && !bReadonly);
518 void SwGlobalTree::DeselectHdl()
520 SelectHdl();
523 DragDropMode SwGlobalTree::NotifyStartDrag( TransferDataContainer& ,
524 SvTreeListEntry* pEntry )
526 bIsInternalDrag = true;
527 pDDSource = pEntry;
528 return SV_DRAGDROP_CTRL_MOVE;
531 long SwGlobalTree::GetTabPos( SvTreeListEntry*, SvLBoxTab* pTab)
533 return pTab->GetPos() - GLBL_TABPOS_SUB;
536 sal_Bool SwGlobalTree::NotifyMoving( SvTreeListEntry* pTarget,
537 SvTreeListEntry* pSource,
538 SvTreeListEntry*&,
539 sal_uLong&
542 SvTreeList* _pModel = GetModel();
543 sal_uInt16 nSource = (sal_uInt16) _pModel->GetAbsPos(pSource);
544 sal_uInt16 nDest = pTarget ? (sal_uInt16) _pModel->GetAbsPos(pTarget) : pSwGlblDocContents->size();
546 if( pActiveShell->MoveGlobalDocContent(
547 *pSwGlblDocContents, nSource, nSource + 1, nDest ) &&
548 Update( sal_False ))
549 Display();
550 return sal_False;
553 sal_Bool SwGlobalTree::NotifyCopying( SvTreeListEntry* /*pTarget*/,
554 SvTreeListEntry* /*pEntry*/,
555 SvTreeListEntry*& /*rpNewParent*/,
556 sal_uLong& /*rNewChildPos*/
559 return sal_False;
562 sal_Bool SwGlobalTree::NotifyAcceptDrop( SvTreeListEntry* pEntry)
564 return pEntry != 0;
567 void SwGlobalTree::StartDrag( sal_Int8 nAction, const Point& rPt )
569 if( 1 == GetSelectionCount() )
570 SvTreeListBox::StartDrag( nAction, rPt );
573 void SwGlobalTree::DragFinished( sal_Int8 nAction )
575 SvTreeListBox::DragFinished( nAction );
576 bIsInternalDrag = false;
579 // If a Ctrl+DoubleClick is executed in an empty area,
580 // then the base function of the control should be called.
582 void SwGlobalTree::MouseButtonDown( const MouseEvent& rMEvt )
584 Point aPos( rMEvt.GetPosPixel());
585 SvTreeListEntry* pEntry = GetEntry( aPos, sal_True );
586 if( !pEntry && rMEvt.IsLeft() && rMEvt.IsMod1() && (rMEvt.GetClicks() % 2) == 0)
587 Control::MouseButtonDown( rMEvt );
588 else
589 SvTreeListBox::MouseButtonDown( rMEvt );
592 void SwGlobalTree::GetFocus()
594 if(Update( sal_False ))
595 Display();
596 SvTreeListBox::GetFocus();
599 void SwGlobalTree::KeyInput(const KeyEvent& rKEvt)
601 const KeyCode aCode = rKEvt.GetKeyCode();
602 if(aCode.GetCode() == KEY_RETURN)
604 switch(aCode.GetModifier())
606 case KEY_MOD2:
607 // Switch boxes
608 GetParentWindow()->ToggleTree();
609 break;
612 else
613 SvTreeListBox::KeyInput(rKEvt);
616 void SwGlobalTree::Clear()
618 pEmphasisEntry = 0;
619 SvTreeListBox::Clear();
622 void SwGlobalTree::Display(bool bOnlyUpdateUserData)
624 if(!bIsImageListInitialized)
626 aEntryImages = ImageList(SW_RES(IMG_NAVI_ENTRYBMP));
627 bIsImageListInitialized = true;
629 sal_uInt16 nCount = pSwGlblDocContents->size();
630 if(bOnlyUpdateUserData && GetEntryCount() == pSwGlblDocContents->size())
632 SvTreeListEntry* pEntry = First();
633 for( sal_uInt16 i = 0; i < nCount; i++)
635 SwGlblDocContent* pCont = (*pSwGlblDocContents)[i];
636 pEntry->SetUserData(pCont);
637 pEntry = Next(pEntry);
640 else
642 SetUpdateMode( sal_False );
643 SvTreeListEntry* pOldSelEntry = FirstSelected();
644 String sEntryName; // Name of the entry
645 sal_uInt16 nSelPos = USHRT_MAX;
646 if(pOldSelEntry)
648 sEntryName = GetEntryText(pOldSelEntry);
649 nSelPos = (sal_uInt16)GetModel()->GetAbsPos(pOldSelEntry);
651 Clear();
652 if(!pSwGlblDocContents)
653 Update( sal_False );
655 SvTreeListEntry* pSelEntry = 0;
656 for( sal_uInt16 i = 0; i < nCount; i++)
658 SwGlblDocContent* pCont = (*pSwGlblDocContents)[i];
659 String sEntry;
660 Image aImage;
661 switch( pCont->GetType() )
663 case GLBLDOC_UNKNOWN:
665 sEntry = aContextStrings[ST_TEXT - ST_GLOBAL_CONTEXT_FIRST];
666 aImage = aEntryImages.GetImage(SID_SW_START + GLOBAL_CONTENT_TEXT);
668 break;
669 case GLBLDOC_TOXBASE:
671 const SwTOXBase* pBase = pCont->GetTOX();
672 sEntry = pBase->GetTitle();
673 aImage = aEntryImages.GetImage(SID_SW_START + CONTENT_TYPE_INDEX);
675 break;
676 case GLBLDOC_SECTION:
678 const SwSection* pSect = pCont->GetSection();
679 sEntry = pSect->GetSectionName();
680 aImage = aEntryImages.GetImage(SID_SW_START + CONTENT_TYPE_REGION);
682 break;
684 SvTreeListEntry* pEntry = InsertEntry(sEntry, aImage, aImage,
685 0, sal_False, LIST_APPEND, pCont);
686 if(sEntry == sEntryName)
688 pSelEntry = pEntry;
691 if(pSelEntry)
693 Select(pSelEntry);
695 else if(nSelPos != USHRT_MAX && nSelPos < nCount)
697 Select(GetEntry(nSelPos));
699 else if(nCount)
700 Select(First());
701 else
702 SelectHdl();
703 SetUpdateMode( sal_True );
707 void SwGlobalTree::InsertRegion( const SwGlblDocContent* pCont, const String* pFileName )
709 Sequence< OUString > aFileNames;
710 if ( !pFileName )
712 pDefParentWin = Application::GetDefDialogParent();
713 Application::SetDefDialogParent( this );
714 delete pDocInserter;
715 pDocInserter = new ::sfx2::DocumentInserter(
716 OUString("swriter"), true );
717 pDocInserter->StartExecuteModal( LINK( this, SwGlobalTree, DialogClosedHdl ) );
719 else if ( pFileName->Len() )
721 aFileNames.realloc(1);
722 INetURLObject aFileName;
723 aFileName.SetSmartURL( *pFileName );
724 aFileNames.getArray()[0] = aFileName.GetMainURL( INetURLObject::NO_DECODE );
725 InsertRegion( pCont, aFileNames );
729 void SwGlobalTree::EditContent(const SwGlblDocContent* pCont )
731 sal_uInt16 nSlot = 0;
732 switch( pCont->GetType() )
734 case GLBLDOC_UNKNOWN:
735 pActiveShell->GetView().GetEditWin().GrabFocus();
736 break;
737 case GLBLDOC_TOXBASE:
739 const SwTOXBase* pBase = pCont->GetTOX();
740 if(pBase)
741 nSlot = FN_INSERT_MULTI_TOX;
743 break;
744 case GLBLDOC_SECTION:
746 OpenDoc(pCont);
748 nSlot = 0;
749 pCont = 0;
751 break;
753 if(pCont)
754 GotoContent(pCont);
755 if(nSlot)
757 pActiveShell->GetView().GetViewFrame()->GetDispatcher()->Execute(nSlot);
758 if(Update( sal_False ))
759 Display();
763 IMPL_LINK( SwGlobalTree, PopupHdl, Menu* , pMenu)
765 ExcecuteContextMenuAction( pMenu->GetCurItemId());
766 return sal_True;
769 void SwGlobalTree::ExcecuteContextMenuAction( sal_uInt16 nSelectedPopupEntry )
771 SvTreeListEntry* pEntry = FirstSelected();
772 SwGlblDocContent* pCont = pEntry ? (SwGlblDocContent*)pEntry->GetUserData() : 0;
773 // If a RequestHelp is called during the dialogue,
774 // then the content gets lost. Because of that a copy
775 // is created in which only the DocPos is set correctly.
776 SwGlblDocContent* pContCopy = 0;
777 if(pCont)
778 pContCopy = new SwGlblDocContent(pCont->GetDocPos());
779 SfxDispatcher& rDispatch = *pActiveShell->GetView().GetViewFrame()->GetDispatcher();
780 sal_uInt16 nSlot = 0;
781 bool bDeleteContentCopy = true;
782 switch( nSelectedPopupEntry )
784 case CTX_UPDATE_SEL:
786 // Two passes: first update the areas, then the directories.
787 SvTreeListEntry* pSelEntry = FirstSelected();
788 while( pSelEntry )
790 SwGlblDocContent* pContent = (SwGlblDocContent*)pSelEntry->GetUserData();
791 if(GLBLDOC_SECTION == pContent->GetType() &&
792 pContent->GetSection()->IsConnected())
794 ((SwSection*)pContent->GetSection())->UpdateNow();
797 pSelEntry = NextSelected(pSelEntry);
799 pSelEntry = FirstSelected();
800 while( pSelEntry )
802 SwGlblDocContent* pContent = (SwGlblDocContent*)pSelEntry->GetUserData();
803 if(GLBLDOC_TOXBASE == pContent->GetType())
804 pActiveShell->UpdateTableOf(*pContent->GetTOX());
805 pSelEntry = NextSelected(pSelEntry);
809 break;
810 case CTX_UPDATE_INDEX:
812 nSlot = FN_UPDATE_TOX;
814 break;
815 case CTX_UPDATE_LINK:
816 case CTX_UPDATE_ALL:
818 pActiveShell->GetLinkManager().UpdateAllLinks(true);
819 if(CTX_UPDATE_ALL == nSelectedPopupEntry)
820 nSlot = FN_UPDATE_TOX;
821 pCont = 0;
823 break;
824 case CTX_EDIT:
826 OSL_ENSURE(pCont, "edit without entry ? " );
827 EditContent(pCont);
829 break;
830 case CTX_EDIT_LINK:
832 OSL_ENSURE(pCont, "edit without entry ? " );
833 SfxStringItem aName(FN_EDIT_REGION,
834 pCont->GetSection()->GetSectionName());
835 rDispatch.Execute(FN_EDIT_REGION, SFX_CALLMODE_ASYNCHRON, &aName, 0L);
837 break;
838 case CTX_DELETE:
840 // If several entries selected, then after each delete the array
841 // must be refilled. So you do not have to remember anything,
842 // deleting begins at the end.
843 SvTreeListEntry* pSelEntry = LastSelected();
844 SwGlblDocContents* pTempContents = 0;
845 pActiveShell->StartAction();
846 while(pSelEntry)
848 pActiveShell->DeleteGlobalDocContent(
849 pTempContents ? *pTempContents : *pSwGlblDocContents,
850 (sal_uInt16)GetModel()->GetAbsPos(pSelEntry));
851 pSelEntry = PrevSelected(pSelEntry);
852 if(pSelEntry)
854 pTempContents = new SwGlblDocContents;
855 pActiveShell->GetGlobalDocContent(*pTempContents);
858 delete pTempContents;
859 pActiveShell->EndAction();
860 pCont = 0;
862 break;
863 case CTX_INSERT_ANY_INDEX:
865 if(pContCopy)
867 SfxItemSet aSet(pActiveShell->GetView().GetPool(),
868 RES_COL, RES_COL,
869 RES_BACKGROUND, RES_BACKGROUND,
870 RES_FRM_SIZE, RES_FRM_SIZE,
871 SID_ATTR_PAGE_SIZE, SID_ATTR_PAGE_SIZE,
872 RES_LR_SPACE, RES_LR_SPACE,
873 FN_PARAM_TOX_TYPE, FN_PARAM_TOX_TYPE,
876 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
877 OSL_ENSURE(pFact, "Dialogdiet fail!");
878 AbstractMultiTOXTabDialog* pDlg = pFact->CreateMultiTOXTabDialog( DLG_MULTI_TOX,
879 this, aSet,
880 *pActiveShell,
882 USHRT_MAX,
883 sal_True);
884 OSL_ENSURE(pDlg, "Dialogdiet fail!");
885 if(RET_OK == pDlg->Execute())
887 SwTOXDescription& rDesc = pDlg->GetTOXDescription(
888 pDlg->GetCurrentTOXType());
889 SwTOXMgr aMgr(pActiveShell);
890 SwTOXBase* pToInsert = 0;
891 if(aMgr.UpdateOrInsertTOX(rDesc, &pToInsert, pDlg->GetOutputItemSet()))
892 pActiveShell->InsertGlobalDocContent( *pContCopy, *pToInsert );
894 pCont = 0;
895 delete pDlg;
898 break;
899 case CTX_INSERT_FILE:
901 bDeleteContentCopy = false;
902 pDocContent = pContCopy;
903 InsertRegion( pContCopy );
904 pCont = NULL;
906 break;
907 case CTX_INSERT_NEW_FILE:
909 SfxViewFrame* pGlobFrm = pActiveShell->GetView().GetViewFrame();
910 SwGlobalFrameListener_Impl aFrmListener(*pGlobFrm);
912 sal_uLong nEntryPos = pEntry ? GetModel()->GetAbsPos(pEntry) : (sal_uLong)-1;
913 // Creating a new doc
914 SfxStringItem aFactory(SID_NEWDOCDIRECT,
915 SwDocShell::Factory().GetFilterContainer()->GetName());
917 const SfxFrameItem* pItem = (SfxFrameItem*)
918 rDispatch.Execute(SID_NEWDOCDIRECT,
919 SFX_CALLMODE_SYNCHRON, &aFactory, 0L);
921 // save at
922 SfxFrame* pFrm = pItem ? pItem->GetFrame() : 0;
923 SfxViewFrame* pFrame = pFrm ? pFrm->GetCurrentViewFrame() : 0;
924 if( pFrame )
926 const SfxBoolItem* pBool = (const SfxBoolItem*)
927 pFrame->GetDispatcher()->Execute(
928 SID_SAVEASDOC, SFX_CALLMODE_SYNCHRON );
929 SfxObjectShell& rObj = *pFrame->GetObjectShell();
930 const SfxMedium* pMedium = rObj.GetMedium();
931 String sNewFile(pMedium->GetURLObject().GetMainURL(INetURLObject::DECODE_TO_IURI));
932 // Insert the area with the Doc-Name
933 // Bring the own Doc in the foreground
934 if(aFrmListener.IsValid() && sNewFile.Len())
936 pGlobFrm->ToTop();
937 // Due to the update the entries are invalid
938 if(nEntryPos != (sal_uLong)-1)
940 Update( sal_False );
941 Display();
942 Select(GetModel()->GetEntryAtAbsPos(nEntryPos));
943 pEntry = FirstSelected();
944 pCont = pEntry ? (SwGlblDocContent*)pEntry->GetUserData() : 0;
946 else
948 pEntry = 0;
949 pCont = 0;
951 if(pBool->GetValue())
953 InsertRegion(pCont, &sNewFile);
954 pFrame->ToTop();
956 else
957 pFrame->GetDispatcher()->Execute(SID_CLOSEWIN,
958 SFX_CALLMODE_SYNCHRON);
960 else
962 pFrame->ToTop();
963 return;
967 break;
968 case CTX_INSERT_TEXT:
970 if(pCont)
971 pActiveShell->InsertGlobalDocContent(*pCont);
972 else
974 pActiveShell->SplitNode(); // Empty document
975 pActiveShell->Up( sal_False, 1 );
977 pActiveShell->GetView().GetEditWin().GrabFocus();
979 break;
980 case CTX_UPDATE:
981 pCont = 0;
982 break;
983 default:;
984 // here nothing happens
986 if(pCont)
987 GotoContent(pCont);
988 if(nSlot)
989 rDispatch.Execute(nSlot);
990 if(Update( sal_False ))
991 Display();
992 if ( bDeleteContentCopy )
993 delete pContCopy;
994 else
995 bDeleteContentCopy = true;
998 IMPL_LINK_NOARG(SwGlobalTree, Timeout)
1000 if(!HasFocus() && Update( sal_False ))
1001 Display();
1002 return 0;
1005 void SwGlobalTree::GotoContent(const SwGlblDocContent* pCont)
1007 pActiveShell->EnterStdMode();
1009 switch( pCont->GetType() )
1011 case GLBLDOC_UNKNOWN:
1012 pActiveShell->GotoGlobalDocContent(*pCont);
1013 break;
1014 case GLBLDOC_TOXBASE:
1016 String sName = pCont->GetTOX()->GetTOXName();
1017 if (!pActiveShell->GotoNextTOXBase(&sName))
1018 pActiveShell->GotoPrevTOXBase(&sName);
1020 break;
1021 case GLBLDOC_SECTION:
1022 break;
1027 void SwGlobalTree::ShowTree()
1029 aUpdateTimer.Start();
1030 SvTreeListBox::Show();
1033 void SwGlobalTree::HideTree()
1035 aUpdateTimer.Stop();
1036 SvTreeListBox::Hide();
1039 void SwGlobalTree::ExecCommand(sal_uInt16 nCmd)
1041 SvTreeListEntry* pEntry = FirstSelected();
1042 OSL_ENSURE(pEntry, "It explodes in the next moment");
1043 if(FN_GLOBAL_EDIT == nCmd)
1045 const SwGlblDocContent* pCont = (const SwGlblDocContent*)
1046 pEntry->GetUserData();
1047 EditContent(pCont);
1049 else
1051 if(GetSelectionCount() == 1)
1053 bool bMove = false;
1054 sal_uInt16 nSource = (sal_uInt16)GetModel()->GetAbsPos(pEntry);
1055 sal_uInt16 nDest = nSource;
1056 switch(nCmd)
1058 case FN_ITEM_DOWN:
1060 sal_uInt16 nEntryCount = (sal_uInt16)GetEntryCount();
1061 bMove = nEntryCount > nSource + 1;
1062 nDest+= 2;
1064 break;
1065 case FN_ITEM_UP:
1067 if(nSource)
1068 bMove = 0 != nSource;
1069 nDest--;
1071 break;
1073 if( bMove && pActiveShell->MoveGlobalDocContent(
1074 *pSwGlblDocContents, nSource, nSource + 1, nDest ) &&
1075 Update( sal_False ))
1076 Display();
1081 sal_Bool SwGlobalTree::Update(sal_Bool bHard)
1083 SwView* pActView = GetParentWindow()->GetCreateView();
1084 sal_Bool bRet = sal_False;
1085 if(pActView && pActView->GetWrtShellPtr())
1087 const SwWrtShell* pOldShell = pActiveShell;
1088 pActiveShell = pActView->GetWrtShellPtr();
1089 if(pActiveShell != pOldShell)
1091 delete pSwGlblDocContents;
1092 pSwGlblDocContents = 0;
1094 if(!pSwGlblDocContents)
1096 pSwGlblDocContents = new SwGlblDocContents;
1097 bRet = sal_True;
1098 pActiveShell->GetGlobalDocContent(*pSwGlblDocContents);
1100 else
1102 sal_Bool bCopy = sal_False;
1103 SwGlblDocContents* pTempContents = new SwGlblDocContents;
1104 pActiveShell->GetGlobalDocContent(*pTempContents);
1105 if(pTempContents->size() != pSwGlblDocContents->size() ||
1106 pTempContents->size() != GetEntryCount())
1108 bRet = sal_True;
1109 bCopy = sal_True;
1111 else
1113 for(sal_uInt16 i = 0; i < pTempContents->size() && !bCopy; i++)
1115 SwGlblDocContent* pLeft = (*pTempContents)[i];
1116 SwGlblDocContent* pRight = (*pSwGlblDocContents)[i];
1117 GlobalDocContentType eType = pLeft->GetType();
1118 SvTreeListEntry* pEntry = GetEntry(i);
1119 String sTemp = GetEntryText(pEntry);
1120 if (
1121 eType != pRight->GetType() ||
1123 eType == GLBLDOC_SECTION &&
1124 pLeft->GetSection()->GetSectionName() != sTemp
1125 ) ||
1127 eType == GLBLDOC_TOXBASE &&
1128 pLeft->GetTOX()->GetTitle() != sTemp
1132 bCopy = bRet = sal_True;
1136 if(bCopy || bHard)
1138 pSwGlblDocContents->DeleteAndDestroyAll();
1139 pSwGlblDocContents->insert( *pTempContents );
1140 pTempContents->clear();
1143 delete pTempContents;
1147 else
1149 Clear();
1150 if(pSwGlblDocContents)
1151 pSwGlblDocContents->DeleteAndDestroyAll();
1153 // FIXME: Implement a test for changes!
1154 return bRet;
1157 void SwGlobalTree::OpenDoc(const SwGlblDocContent* pCont)
1159 String sFileName(pCont->GetSection()->GetLinkFileName().GetToken(0,
1160 sfx2::cTokenSeparator));
1161 bool bFound = false;
1162 const SfxObjectShell* pCurr = SfxObjectShell::GetFirst();
1163 while( !bFound && pCurr )
1165 if(pCurr->GetMedium() &&
1166 String(pCurr->GetMedium()->GetURLObject().GetMainURL(INetURLObject::DECODE_TO_IURI)) == sFileName)
1168 bFound = true;
1169 SwGlobalTree::SetShowShell(pCurr);
1170 Application::PostUserEvent( STATIC_LINK(
1171 this, SwGlobalTree, ShowFrameHdl ) );
1172 pCurr = 0;
1174 else
1175 pCurr = SfxObjectShell::GetNext(*pCurr);
1177 if(!bFound)
1179 SfxStringItem aURL(SID_FILE_NAME,
1180 sFileName);
1181 SfxBoolItem aReadOnly(SID_DOC_READONLY, sal_False);
1182 SfxStringItem aTargetFrameName( SID_TARGETNAME, OUString("_blank") );
1183 SfxStringItem aReferer(SID_REFERER, pActiveShell->GetView().GetDocShell()->GetTitle());
1184 pActiveShell->GetView().GetViewFrame()->GetDispatcher()->
1185 Execute(SID_OPENDOC, SFX_CALLMODE_ASYNCHRON,
1186 &aURL, &aReadOnly, &aReferer, &aTargetFrameName, 0L);
1190 IMPL_LINK_NOARG( SwGlobalTree, DoubleClickHdl)
1192 SvTreeListEntry* pEntry = GetCurEntry();
1193 SwGlblDocContent* pCont = (SwGlblDocContent*)pEntry->GetUserData();
1194 if(pCont->GetType() == GLBLDOC_SECTION)
1195 OpenDoc(pCont);
1196 else
1198 GotoContent(pCont);
1199 pActiveShell->GetView().GetEditWin().GrabFocus();
1201 return 0;
1204 IMPL_STATIC_LINK_NOINSTANCE(SwGlobalTree, ShowFrameHdl, SwGlobalTree*, EMPTYARG)
1206 if(SwGlobalTree::GetShowShell())
1207 SfxViewFrame::GetFirst(SwGlobalTree::GetShowShell())->ToTop();
1208 SwGlobalTree::SetShowShell(0);
1209 return 0;
1212 void SwGlobalTree::InitEntry(SvTreeListEntry* pEntry,
1213 const OUString& rStr ,const Image& rImg1,const Image& rImg2,
1214 SvLBoxButtonKind eButtonKind)
1216 sal_uInt16 nColToHilite = 1; //0==Bitmap;1=="Column1";2=="Column2"
1217 SvTreeListBox::InitEntry( pEntry, rStr, rImg1, rImg2, eButtonKind );
1218 SvLBoxString* pCol = (SvLBoxString*)pEntry->GetItem( nColToHilite );
1219 SwLBoxString* pStr = new SwLBoxString( pEntry, 0, pCol->GetText() );
1220 pEntry->ReplaceItem( pStr, nColToHilite );
1223 void SwLBoxString::Paint(
1224 const Point& rPos, SvTreeListBox& rDev, const SvViewDataEntry* pView,
1225 const SvTreeListEntry* pEntry)
1227 SwGlblDocContent* pCont = (SwGlblDocContent*)pEntry->GetUserData();
1228 if(pCont->GetType() == GLBLDOC_SECTION &&
1229 !(pCont->GetSection())->IsConnectFlag() )
1231 Font aOldFont( rDev.GetFont());
1232 Font aFont(aOldFont);
1233 Color aCol( COL_LIGHTRED );
1234 aFont.SetColor( aCol );
1235 rDev.SetFont( aFont );
1236 rDev.DrawText( rPos, GetText() );
1237 rDev.SetFont( aOldFont );
1239 else
1240 SvLBoxString::Paint( rPos, rDev, pView, pEntry);
1243 void SwGlobalTree::DataChanged( const DataChangedEvent& rDCEvt )
1245 if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
1246 (rDCEvt.GetFlags() & SETTINGS_STYLE) )
1248 aEntryImages = ImageList(SW_RES(IMG_NAVI_ENTRYBMP));
1249 Update(sal_True);
1251 SvTreeListBox::DataChanged( rDCEvt );
1254 void SwGlobalTree::InsertRegion( const SwGlblDocContent* _pContent, const Sequence< OUString >& _rFiles )
1256 sal_Int32 nFiles = _rFiles.getLength();
1257 if ( nFiles )
1259 bool bMove = false;
1260 if ( !_pContent )
1262 SvTreeListEntry* pLast = (SvTreeListEntry*)LastVisible();
1263 _pContent = (SwGlblDocContent*)pLast->GetUserData();
1264 bMove = true;
1266 String sFilePassword;
1267 sal_uInt16 nEntryCount = (sal_uInt16)GetEntryCount();
1268 const OUString* pFileNames = _rFiles.getConstArray();
1269 SwWrtShell& rSh = GetParentWindow()->GetCreateView()->GetWrtShell();
1270 rSh.StartAction();
1271 // after insertion of the first new content the 'pCont' parameter becomes invalid
1272 // find the index of the 'anchor' content to always use a current anchor content
1273 size_t nAnchorContent = pSwGlblDocContents->size() - 1;
1274 if ( !bMove )
1276 for (size_t nContent = 0; nContent < pSwGlblDocContents->size();
1277 ++nContent)
1279 if( *_pContent == *(*pSwGlblDocContents)[ nContent ] )
1281 nAnchorContent = nContent;
1282 break;
1286 SwGlblDocContents aTempContents;
1287 for ( sal_Int32 nFile = 0; nFile < nFiles; ++nFile )
1289 //update the global document content after each inserted document
1290 rSh.GetGlobalDocContent(aTempContents);
1291 SwGlblDocContent* pAnchorContent = 0;
1292 OSL_ENSURE(aTempContents.size() > (nAnchorContent + nFile), "invalid anchor content -> last insertion failed");
1293 if ( aTempContents.size() > (nAnchorContent + nFile) )
1294 pAnchorContent = aTempContents[nAnchorContent + nFile];
1295 else
1296 pAnchorContent = aTempContents.back();
1297 String sFileName(pFileNames[nFile]);
1298 INetURLObject aFileUrl;
1299 aFileUrl.SetSmartURL( sFileName );
1300 String sSectionName(String(aFileUrl.GetLastName(
1301 INetURLObject::DECODE_UNAMBIGUOUS)).GetToken(0,
1302 sfx2::cTokenSeparator));
1303 sal_uInt16 nSectCount = rSh.GetSectionFmtCount();
1304 String sTempSectionName(sSectionName);
1305 sal_uInt16 nAddNumber = 0;
1306 sal_uInt16 nCount = 0;
1307 // if applicable: add index if the range name is already in use.
1308 while ( nCount < nSectCount )
1310 const SwSectionFmt& rFmt = rSh.GetSectionFmt(nCount);
1311 if ((rFmt.GetSection()->GetSectionName() == sTempSectionName)
1312 && rFmt.IsInNodesArr())
1314 nCount = 0;
1315 nAddNumber++;
1316 sTempSectionName = sSectionName;
1317 sTempSectionName += ':';
1318 sTempSectionName += OUString::number( nAddNumber );
1320 else
1321 nCount++;
1324 if ( nAddNumber )
1325 sSectionName = sTempSectionName;
1327 SwSectionData aSectionData(CONTENT_SECTION, sSectionName);
1328 aSectionData.SetProtectFlag(true);
1329 aSectionData.SetHidden(false);
1331 aSectionData.SetLinkFileName(sFileName);
1332 aSectionData.SetType(FILE_LINK_SECTION);
1333 aSectionData.SetLinkFilePassword( sFilePassword );
1335 rSh.InsertGlobalDocContent( *pAnchorContent, aSectionData );
1337 if ( bMove )
1339 Update( sal_False );
1340 rSh.MoveGlobalDocContent(
1341 *pSwGlblDocContents, nEntryCount, nEntryCount + (sal_uInt16)nFiles, nEntryCount - (sal_uInt16)nFiles );
1343 rSh.EndAction();
1344 Update( sal_False );
1345 Display();
1349 IMPL_LINK( SwGlobalTree, DialogClosedHdl, sfx2::FileDialogHelper*, _pFileDlg )
1351 Application::SetDefDialogParent( pDefParentWin );
1352 if ( ERRCODE_NONE == _pFileDlg->GetError() )
1354 SfxMediumList* pMedList = pDocInserter->CreateMediumList();
1355 if ( pMedList )
1357 Sequence< OUString >aFileNames( pMedList->size() );
1358 OUString* pFileNames = aFileNames.getArray();
1359 sal_Int32 nPos = 0;
1360 for ( size_t i = 0, n = pMedList->size(); i < n; ++i )
1362 SfxMedium* pMed = pMedList->at( i );
1363 String sFileName = pMed->GetURLObject().GetMainURL( INetURLObject::NO_DECODE );
1364 sFileName += sfx2::cTokenSeparator;
1365 sFileName += pMed->GetFilter()->GetFilterName();
1366 sFileName += sfx2::cTokenSeparator;
1367 pFileNames[nPos++] = sFileName;
1369 delete pMedList;
1370 InsertRegion( pDocContent, aFileNames );
1371 DELETEZ( pDocContent );
1374 return 0;
1377 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */