LibreOffice Module sw (master)  1
glbltree.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <svl/stritem.hxx>
21 #include <sfx2/fcontnr.hxx>
22 #include <sfx2/linkmgr.hxx>
23 #include <sfx2/dispatch.hxx>
24 #include <sfx2/viewfrm.hxx>
25 #include <sfx2/docfile.hxx>
26 #include <sfx2/docfilt.hxx>
27 #include <vcl/help.hxx>
28 #include <sot/filelist.hxx>
29 #include <svl/eitem.hxx>
30 #include <vcl/graphicfilter.hxx>
31 #include <vcl/settings.hxx>
32 
33 #include <vcl/treelistentry.hxx>
34 #include <sfx2/docinsert.hxx>
35 #include <sfx2/filedlghelper.hxx>
36 
37 #include <wrtsh.hxx>
38 #include <view.hxx>
39 #include <docsh.hxx>
40 #include <edglbldc.hxx>
41 #include <section.hxx>
42 #include <tox.hxx>
43 #include <navipi.hxx>
44 #include <edtwin.hxx>
45 #include <toxmgr.hxx>
46 
47 #include <cmdid.h>
48 #include <helpids.h>
49 #include <strings.hrc>
50 #include <bitmaps.hlst>
51 #include <swabstdlg.hxx>
52 #include <memory>
53 
54 using namespace ::com::sun::star::uno;
55 
56 // Context menu for GlobalTree
57 #define CTX_INSERT_ANY_INDEX 10
58 #define CTX_INSERT_FILE 11
59 #define CTX_INSERT_NEW_FILE 12
60 #define CTX_INSERT_TEXT 13
61 
62 #define CTX_UPDATE_SEL 20
63 #define CTX_UPDATE_INDEX 21
64 #define CTX_UPDATE_LINK 22
65 #define CTX_UPDATE_ALL 23
66 
67 #define CTX_UPDATE 1
68 #define CTX_INSERT 2
69 #define CTX_EDIT 3
70 #define CTX_DELETE 4
71 #define CTX_EDIT_LINK 5
72 
73 #define GLOBAL_UPDATE_TIMEOUT 2000
74 
75 // TabPos: push to left
76 #define GLBL_TABPOS_SUB 5
77 
79 static const char* aHelpForMenu[] =
80 {
81  nullptr,
82  HID_GLBLTREE_UPDATE, //CTX_UPDATE
83  HID_GLBLTREE_INSERT, //CTX_INSERT
84  HID_GLBLTREE_EDIT, //CTX_EDIT
85  HID_GLBLTREE_DEL, //CTX_DELETE
86  HID_GLBLTREE_EDIT_LINK, //CTX_EDIT_LINK
87  nullptr,
88  nullptr,
89  nullptr,
90  nullptr,
91  HID_GLBLTREE_INS_IDX, //CTX_INSERT_ANY_INDEX
92  HID_GLBLTREE_INS_FILE, //CTX_INSERT_FILE
93  HID_GLBLTREE_INS_NEW_FILE, //CTX_INSERT_NEW_FILE
94  HID_GLBLTREE_INS_TEXT, //CTX_INSERT_TEXT
95  nullptr,
96  nullptr,
97  nullptr,
98  nullptr,
99  nullptr,
100  nullptr,
101  HID_GLBLTREE_UPD_SEL, //CTX_UPDATE_SEL
102  HID_GLBLTREE_UPD_IDX, //CTX_UPDATE_INDEX
103  HID_GLBLTREE_UPD_LINK, //CTX_UPDATE_LINK
104  HID_GLBLTREEUPD_ALL //CTX_UPDATE_ALL
105 };
106 
107 namespace {
108 
109 class SwGlobalFrameListener_Impl : public SfxListener
110 {
111  bool bValid;
112 public:
113  explicit SwGlobalFrameListener_Impl(SfxViewFrame& rFrame)
114  : bValid(true)
115  {
116  StartListening(rFrame);
117  }
118 
119  virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
120 
121  bool IsValid() const {return bValid;}
122 };
123 
124 }
125 
126 void SwGlobalFrameListener_Impl::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint )
127 {
128  if( rHint.GetId() == SfxHintId::Dying)
129  bValid = false;
130 }
131 
132 namespace {
133 
135 {
136  IDX_STR_UPDATE = 0,
137  IDX_STR_EDIT_CONTENT = 1,
138  IDX_STR_EDIT_INSERT = 2,
139  IDX_STR_INDEX = 3,
140  IDX_STR_FILE = 4,
141  IDX_STR_NEW_FILE = 5,
142  IDX_STR_INSERT_TEXT = 6,
143  IDX_STR_DELETE = 7,
144  IDX_STR_UPDATE_SEL = 8,
145  IDX_STR_UPDATE_INDEX = 9,
146  IDX_STR_UPDATE_LINK = 10,
147  IDX_STR_UPDATE_ALL = 11,
148  IDX_STR_BROKEN_LINK = 12,
149  IDX_STR_EDIT_LINK = 13
150 };
151 
152 }
153 
154 static const char* GLOBAL_CONTEXT_ARY[] =
155 {
156  STR_UPDATE,
157  STR_EDIT_CONTENT,
158  STR_EDIT_INSERT,
159  STR_INDEX,
160  STR_FILE,
161  STR_NEW_FILE,
162  STR_INSERT_TEXT,
163  STR_DELETE,
164  STR_UPDATE_SEL,
165  STR_UPDATE_INDEX,
166  STR_UPDATE_LINK,
167  STR_UPDATE_ALL,
168  STR_BROKEN_LINK,
169  STR_EDIT_LINK
170 };
171 
173  : SvTreeListBox(pParent)
174  , m_xDialog(pDialog)
175  , m_pActiveShell(nullptr)
176  , m_pEmphasisEntry(nullptr)
177  , m_pDDSource(nullptr)
178  , m_bIsInternalDrag(false)
179  , m_bLastEntryEmphasis(false)
180 {
181  SetDragDropMode(DragDropMode::APP_COPY |
182  DragDropMode::CTRL_MOVE |
183  DragDropMode::ENABLE_TOP );
184 
188  for (sal_uInt16 i = 0; i < GLOBAL_CONTEXT_COUNT; i++)
189  {
190  m_aContextStrings[i] = SwResId(GLOBAL_CONTEXT_ARY[i]);
191  }
193  SelectHdl();
196 }
197 
199 {
200  disposeOnce();
201 }
202 
204 {
205  m_pSwGlblDocContents.reset();
206  m_pDocInserter.reset();
208  m_xDialog.clear();
210 }
211 
213 {
214  return LogicToPixel(Size(110, 112), MapMode(MapUnit::MapAppFont));
215 }
216 
218 {
219  sal_Int8 nRet = DND_ACTION_NONE;
220  SvTreeListEntry* pLast = LastVisible();
221  if(m_pEmphasisEntry)
222  {
224  m_pEmphasisEntry = nullptr;
225  }
226  else if(m_bLastEntryEmphasis && pLast)
227  {
228  ImplShowTargetEmphasis( pLast, false);
229  }
230 
231  SvTreeListEntry* pDropEntry = m_bLastEntryEmphasis ? nullptr : GetEntry(rEvt.maPosPixel);
232  if( m_bIsInternalDrag )
233  {
234  SvTreeListEntry* pDummy = nullptr;
235  sal_uLong nInsertionPos = TREELIST_APPEND;
236  NotifyMoving( pDropEntry, m_pDDSource, pDummy, nInsertionPos );
237  }
238  else
239  {
240  TransferableDataHelper aData( rEvt.maDropEvent.Transferable );
241 
242  OUString sFileName;
243  const SwGlblDocContent* pCnt = pDropEntry ?
244  static_cast<const SwGlblDocContent*>(pDropEntry->GetUserData()) :
245  nullptr;
246  if( aData.HasFormat( SotClipboardFormatId::FILE_LIST ))
247  {
248  nRet = rEvt.mnAction;
249  std::unique_ptr<SwGlblDocContents> pTempContents(new SwGlblDocContents);
250  int nAbsContPos = pDropEntry ?
251  static_cast<int>(GetModel()->GetAbsPos(pDropEntry)):
252  - 1;
253  sal_uLong nEntryCount = GetEntryCount();
254 
255  // Get data
256  FileList aFileList;
257  aData.GetFileList( SotClipboardFormatId::FILE_LIST, aFileList );
258  for ( size_t n = aFileList.Count(); n--; )
259  {
260  sFileName = aFileList.GetFile(n);
261  InsertRegion(pCnt, &sFileName);
262  // The list of contents must be newly fetched after inserting,
263  // to not work on an old content.
264  if(n)
265  {
266  m_pActiveShell->GetGlobalDocContent(*pTempContents);
267  // If the file was successfully inserted,
268  // then the next content must also be fetched.
269  if(nEntryCount < pTempContents->size())
270  {
271  nEntryCount++;
272  nAbsContPos++;
273  pCnt = (*pTempContents)[ nAbsContPos ].get();
274  }
275  }
276  }
277  }
278  else if( !(sFileName =
279  SwNavigationPI::CreateDropFileName( aData )).isEmpty())
280  {
281  INetURLObject aTemp(sFileName);
282  GraphicDescriptor aDesc(aTemp);
283  if( !aDesc.Detect() ) // accept no graphics
284  {
285  nRet = rEvt.mnAction;
286  InsertRegion(pCnt, &sFileName);
287  }
288  }
289  }
290  m_bLastEntryEmphasis = false;
291  return nRet;
292 
293 }
294 
296 {
297  sal_Int8 nRet = rEvt.mnAction;
298 
299  //initiate scrolling
300  GetDropTarget( rEvt.maPosPixel );
301  SvTreeListEntry* pLast = LastVisible();
302  if( rEvt.mbLeaving )
303  {
304  if( m_pEmphasisEntry )
305  {
307  m_pEmphasisEntry = nullptr;
308  }
309  else if(m_bLastEntryEmphasis && pLast)
310  {
311  ImplShowTargetEmphasis( pLast, false);
312  }
313  m_bLastEntryEmphasis = false;
314  }
315  else
316  {
317  SvTreeListEntry* pDropEntry = GetEntry( rEvt.maPosPixel );
319  {
320  if( m_pDDSource != pDropEntry )
321  nRet = rEvt.mnAction;
322  }
323  else if( IsDropFormatSupported( SotClipboardFormatId::SIMPLE_FILE ) ||
324  IsDropFormatSupported( SotClipboardFormatId::STRING ) ||
325  IsDropFormatSupported( SotClipboardFormatId::FILE_LIST ) ||
326  IsDropFormatSupported( SotClipboardFormatId::SOLK ) ||
327  IsDropFormatSupported( SotClipboardFormatId::NETSCAPE_BOOKMARK )||
328  IsDropFormatSupported( SotClipboardFormatId::FILECONTENT ) ||
329  IsDropFormatSupported( SotClipboardFormatId::FILEGRPDESCRIPTOR ) ||
330  IsDropFormatSupported( SotClipboardFormatId::UNIFORMRESOURCELOCATOR ) ||
331  IsDropFormatSupported( SotClipboardFormatId::FILENAME ))
332  nRet = DND_ACTION_LINK;
333 
334  if(m_pEmphasisEntry && m_pEmphasisEntry != pDropEntry)
336  else if(pLast && m_bLastEntryEmphasis && pDropEntry)
337  {
338  ImplShowTargetEmphasis( pLast, false);
339  m_bLastEntryEmphasis = false;
340  }
341 
342  if(pDropEntry)
343  ImplShowTargetEmphasis( Prev(pDropEntry), DND_ACTION_NONE != nRet );
344  else if(pLast)
345  {
346  ImplShowTargetEmphasis( pLast, DND_ACTION_NONE != nRet );
347  m_bLastEntryEmphasis = true;
348  }
349  m_pEmphasisEntry = pDropEntry;
350  }
351  return nRet;
352 }
353 
355 {
356  VclPtr<PopupMenu> pPop;
357  if(m_pActiveShell &&
359  {
360  const MenuEnableFlags nEnableFlags = GetEnableFlags();
361  pPop = VclPtr<PopupMenu>::Create();
362  VclPtrInstance<PopupMenu> pSubPop1;
363  VclPtrInstance<PopupMenu> pSubPop2;
364 
365  for (sal_uInt16 i = CTX_UPDATE_SEL; i <= CTX_UPDATE_ALL; i++)
366  {
367  pSubPop2->InsertItem( i, m_aContextStrings[IDX_STR_UPDATE_SEL + i - CTX_UPDATE_SEL] );
368  pSubPop2->SetHelpId(i, aHelpForMenu[i]);
369  }
370  pSubPop2->EnableItem(CTX_UPDATE_SEL, bool(nEnableFlags & MenuEnableFlags::UpdateSel));
371 
372  pSubPop1->InsertItem(CTX_INSERT_ANY_INDEX, m_aContextStrings[IDX_STR_INDEX]);
374  pSubPop1->InsertItem(CTX_INSERT_FILE, m_aContextStrings[IDX_STR_FILE]);
376  pSubPop1->InsertItem(CTX_INSERT_NEW_FILE, m_aContextStrings[IDX_STR_NEW_FILE]);
378  pSubPop1->InsertItem(CTX_INSERT_TEXT, m_aContextStrings[IDX_STR_INSERT_TEXT]);
380 
381  pPop->InsertItem(CTX_UPDATE, m_aContextStrings[IDX_STR_UPDATE]);
383  pPop->InsertItem(CTX_EDIT, m_aContextStrings[IDX_STR_EDIT_CONTENT]);
385  if(nEnableFlags&MenuEnableFlags::EditLink)
386  {
387  pPop->InsertItem(CTX_EDIT_LINK, m_aContextStrings[IDX_STR_EDIT_LINK]);
389  }
390  pPop->InsertItem(CTX_INSERT, m_aContextStrings[IDX_STR_EDIT_INSERT]);
392  pPop->InsertSeparator() ;
393  pPop->InsertItem(CTX_DELETE, m_aContextStrings[IDX_STR_DELETE]);
395 
396  //disabling if applicable
397  pSubPop1->EnableItem(CTX_INSERT_ANY_INDEX, bool(nEnableFlags & MenuEnableFlags::InsertIdx ));
398  pSubPop1->EnableItem(CTX_INSERT_TEXT, bool(nEnableFlags & MenuEnableFlags::InsertText));
399  pSubPop1->EnableItem(CTX_INSERT_FILE, bool(nEnableFlags & MenuEnableFlags::InsertFile));
400  pSubPop1->EnableItem(CTX_INSERT_NEW_FILE, bool(nEnableFlags & MenuEnableFlags::InsertFile));
401 
402  pPop->EnableItem(CTX_UPDATE, bool(nEnableFlags & MenuEnableFlags::Update));
403  pPop->EnableItem(CTX_INSERT, bool(nEnableFlags & MenuEnableFlags::InsertIdx));
404  pPop->EnableItem(CTX_EDIT, bool(nEnableFlags & MenuEnableFlags::Edit));
405  pPop->EnableItem(CTX_DELETE, bool(nEnableFlags & MenuEnableFlags::Delete));
406 
407  pPop->SetPopupMenu( CTX_INSERT, pSubPop1 );
408  pPop->SetPopupMenu( CTX_UPDATE, pSubPop2 );
409  }
410  return pPop;
411 }
412 
413 void SwGlobalTree::TbxMenuHdl(sal_uInt16 nTbxId, ToolBox* pBox)
414 {
415  const MenuEnableFlags nEnableFlags = GetEnableFlags();
416  const OUString sCommand(pBox->GetItemCommand(nTbxId));
417  if (sCommand == "insert")
418  {
420  for (sal_uInt16 i = CTX_INSERT_ANY_INDEX; i <= CTX_INSERT_TEXT; ++i)
421  {
422  pMenu->InsertItem( i, m_aContextStrings[IDX_STR_INDEX + i - CTX_INSERT_ANY_INDEX] );
423  pMenu->SetHelpId(i, aHelpForMenu[i] );
424  }
425  pMenu->EnableItem(CTX_INSERT_ANY_INDEX, bool(nEnableFlags & MenuEnableFlags::InsertIdx ));
426  pMenu->EnableItem(CTX_INSERT_TEXT, bool(nEnableFlags & MenuEnableFlags::InsertText));
427  pMenu->EnableItem(CTX_INSERT_FILE, bool(nEnableFlags & MenuEnableFlags::InsertFile));
428  pMenu->EnableItem(CTX_INSERT_NEW_FILE, bool(nEnableFlags & MenuEnableFlags::InsertFile));
429  pMenu->SetSelectHdl(LINK(this, SwGlobalTree, PopupHdl));
430  pMenu->Execute(pBox, pBox->GetItemRect(nTbxId));
431  pMenu.disposeAndClear();
432  pBox->EndSelection();
433  pBox->Invalidate();
434  }
435  else if (sCommand == "update")
436  {
438  for (sal_uInt16 i = CTX_UPDATE_SEL; i <= CTX_UPDATE_ALL; i++)
439  {
440  pMenu->InsertItem( i, m_aContextStrings[IDX_STR_UPDATE_SEL + i - CTX_UPDATE_SEL] );
441  pMenu->SetHelpId(i, aHelpForMenu[i] );
442  }
443  pMenu->EnableItem(CTX_UPDATE_SEL, bool(nEnableFlags & MenuEnableFlags::UpdateSel));
444  pMenu->SetSelectHdl(LINK(this, SwGlobalTree, PopupHdl));
445  pMenu->Execute(pBox, pBox->GetItemRect(nTbxId));
446  pMenu.disposeAndClear();
447  pBox->EndSelection();
448  pBox->Invalidate();
449  }
450 }
451 
453 {
454  SvTreeListEntry* pEntry = FirstSelected();
455  sal_uLong nSelCount = GetSelectionCount();
456  sal_uLong nEntryCount = GetEntryCount();
457  SvTreeListEntry* pPrevEntry = pEntry ? Prev(pEntry) : nullptr;
458 
460  if(nSelCount == 1 || !nEntryCount)
462  if(nSelCount == 1)
463  {
464  nRet |= MenuEnableFlags::Edit;
465  if (pEntry && static_cast<SwGlblDocContent*>(pEntry->GetUserData())->GetType() != GLBLDOC_UNKNOWN &&
466  (!pPrevEntry || static_cast<SwGlblDocContent*>(pPrevEntry->GetUserData())->GetType() != GLBLDOC_UNKNOWN))
468  if (pEntry && GLBLDOC_SECTION == static_cast<SwGlblDocContent*>(pEntry->GetUserData())->GetType())
470  }
471  else if(!nEntryCount)
472  {
474  }
475  if(nEntryCount)
477  if(nSelCount)
479  return nRet;
480 }
481 
483 {
484  bool bParent = true;
485  Update(true);
486  Display(true);
487  if( rHEvt.GetMode() & HelpEventMode::QUICK )
488  {
489  Point aPos( ScreenToOutputPixel( rHEvt.GetMousePosPixel() ));
490  SvTreeListEntry* pEntry = GetEntry( aPos );
491  const SwGlblDocContent* pCont = pEntry ?
492  static_cast<const SwGlblDocContent*>(pEntry->GetUserData()) : nullptr;
493  if( pCont && GLBLDOC_SECTION == pCont->GetType())
494  {
495  bParent = false;
496  SvLBoxTab* pTab;
497  SvLBoxItem* pItem = GetItem( pEntry, aPos.X(), &pTab );
498  if (pItem && SvLBoxItemType::String == pItem->GetType())
499  {
500  const SwSection* pSect = pCont->GetSection();
501  OUString sEntry = pSect->GetLinkFileName().getToken(0, sfx2::cTokenSeparator);
502  if(!pSect->IsConnectFlag())
503  sEntry = m_aContextStrings[IDX_STR_BROKEN_LINK] + sEntry;
504  Point aEntryPos = GetEntryPosition( pEntry );
505 
506  aEntryPos.setX( GetTabPos( pEntry, pTab ) );
507  Size aSize(pItem->GetWidth(this, pEntry), pItem->GetHeight(this, pEntry));
508 
509  if((aEntryPos.X() + aSize.Width()) > GetSizePixel().Width())
510  aSize.setWidth( GetSizePixel().Width() - aEntryPos.X() );
511 
512  aEntryPos = OutputToScreenPixel(aEntryPos);
513  tools::Rectangle aItemRect( aEntryPos, aSize );
515  {
516  aEntryPos.AdjustX(aSize.Width() );
517  Help::ShowBalloon( this, aEntryPos, aItemRect, sEntry );
518  }
519  else
520  Help::ShowQuickHelp( this, aItemRect, sEntry,
521  QuickHelpFlags::Left|QuickHelpFlags::VCenter );
522  }
523  }
524  }
525 
526  if(bParent)
528 }
529 
531 {
532 
533  sal_uLong nSelCount = GetSelectionCount();
534  SvTreeListEntry* pSel = FirstSelected();
535  sal_uLong nAbsPos = pSel ? GetModel()->GetAbsPos(pSel) : 0;
536  SwNavigationPI* pNavi = GetParentWindow();
537  bool bReadonly = !m_pActiveShell ||
539  pNavi->m_aGlobalToolBox->EnableItem(pNavi->m_aGlobalToolBox->GetItemId("edit"), nSelCount == 1 && !bReadonly);
540  pNavi->m_aGlobalToolBox->EnableItem(pNavi->m_aGlobalToolBox->GetItemId("insert"), nSelCount <= 1 && !bReadonly);
541  pNavi->m_aGlobalToolBox->EnableItem(pNavi->m_aGlobalToolBox->GetItemId("update"), GetEntryCount() > 0 && !bReadonly);
543  nSelCount == 1 && nAbsPos && !bReadonly);
544  pNavi->m_aGlobalToolBox->EnableItem(pNavi->m_aGlobalToolBox->GetItemId("down"),
545  nSelCount == 1 && nAbsPos < GetEntryCount() - 1 && !bReadonly);
546 
547 }
548 
550 {
551  SelectHdl();
552 }
553 
555  SvTreeListEntry* pEntry )
556 {
557  m_bIsInternalDrag = true;
558  m_pDDSource = pEntry;
559  return DragDropMode::CTRL_MOVE;
560 }
561 
563 {
564  return pTab->GetPos() - GLBL_TABPOS_SUB;
565 }
566 
568  SvTreeListEntry* pSource,
569  SvTreeListEntry*&,
570  sal_uLong&
571  )
572 {
573  SvTreeList* _pModel = GetModel();
574  sal_uLong nSource = _pModel->GetAbsPos(pSource);
575  sal_uLong nDest = pTarget ? _pModel->GetAbsPos(pTarget) : m_pSwGlblDocContents->size();
576 
578  *m_pSwGlblDocContents, nSource, nSource + 1, nDest ) &&
579  Update( false ))
580  Display();
581 
582  return TRISTATE_FALSE;
583 }
584 
586  SvTreeListEntry* /*pEntry*/,
587  SvTreeListEntry*& /*rpNewParent*/,
588  sal_uLong& /*rNewChildPos*/
589  )
590 {
591  return TRISTATE_FALSE;
592 }
593 
595 {
596  return pEntry != nullptr;
597 }
598 
599 void SwGlobalTree::StartDrag( sal_Int8 nAction, const Point& rPt )
600 {
601  if( 1 == GetSelectionCount() )
602  SvTreeListBox::StartDrag( nAction, rPt );
603 }
604 
606 {
607  SvTreeListBox::DragFinished( nAction );
608  m_bIsInternalDrag = false;
609 }
610 
611 // If a Ctrl+DoubleClick is executed in an empty area,
612 // then the base function of the control should be called.
613 
615 {
616  Point aPos( rMEvt.GetPosPixel());
617  SvTreeListEntry* pEntry = GetEntry( aPos, true );
618  if( !pEntry && rMEvt.IsLeft() && rMEvt.IsMod1() && (rMEvt.GetClicks() % 2) == 0)
619  Control::MouseButtonDown( rMEvt );
620  else
622 }
623 
625 {
626  if(Update( false ))
627  Display();
629 }
630 
632 {
633  const vcl::KeyCode aCode = rKEvt.GetKeyCode();
634  if(aCode.GetCode() == KEY_RETURN)
635  {
636  switch(aCode.GetModifier())
637  {
638  case KEY_MOD2:
639  // Switch boxes
641  break;
642  }
643  }
644  else
646 }
647 
649 {
650  m_pEmphasisEntry = nullptr;
652 }
653 
654 void SwGlobalTree::Display(bool bOnlyUpdateUserData)
655 {
656  size_t nCount = m_pSwGlblDocContents->size();
657  if(bOnlyUpdateUserData && GetEntryCount() == m_pSwGlblDocContents->size())
658  {
659  SvTreeListEntry* pEntry = First();
660  for (size_t i = 0; i < nCount && pEntry; i++)
661  {
662  SwGlblDocContent* pCont = (*m_pSwGlblDocContents)[i].get();
663  pEntry->SetUserData(pCont);
664  pEntry = Next(pEntry);
665  assert(pEntry || i == nCount - 1);
666  }
667  }
668  else
669  {
670  SetUpdateMode( false );
671  SvTreeListEntry* pOldSelEntry = FirstSelected();
672  OUString sEntryName; // Name of the entry
674  if(pOldSelEntry)
675  {
676  sEntryName = GetEntryText(pOldSelEntry);
677  nSelPos = GetModel()->GetAbsPos(pOldSelEntry);
678  }
679  Clear();
681  Update( false );
682 
683  SvTreeListEntry* pSelEntry = nullptr;
684  for( size_t i = 0; i < nCount; i++)
685  {
686  SwGlblDocContent* pCont = (*m_pSwGlblDocContents)[i].get();
687  OUString sEntry;
688  Image aImage;
689  switch( pCont->GetType() )
690  {
691  case GLBLDOC_UNKNOWN:
692  {
693  sEntry = m_aContextStrings[IDX_STR_INSERT_TEXT];
694  }
695  break;
696  case GLBLDOC_TOXBASE:
697  {
698  const SwTOXBase* pBase = pCont->GetTOX();
699  sEntry = pBase->GetTitle();
700  aImage = Image(StockImage::Yes, RID_BMP_NAVI_INDEX);
701  }
702  break;
703  case GLBLDOC_SECTION:
704  {
705  const SwSection* pSect = pCont->GetSection();
706  sEntry = pSect->GetSectionName();
707  aImage = Image(StockImage::Yes, RID_BMP_DROP_REGION);
708  }
709  break;
710  }
711  SvTreeListEntry* pEntry = InsertEntry(sEntry, aImage, aImage,
712  nullptr, false, TREELIST_APPEND, pCont);
713  if(sEntry == sEntryName)
714  {
715  pSelEntry = pEntry;
716  }
717  }
718  if(pSelEntry)
719  {
720  Select(pSelEntry);
721  }
722  else if(nSelPos != TREELIST_ENTRY_NOTFOUND && nSelPos < nCount)
723  {
724  Select(GetEntry(nSelPos));
725  }
726  else if(nCount)
727  Select(First());
728  else
729  SelectHdl();
730  SetUpdateMode( true );
731  }
732 }
733 
734 void SwGlobalTree::InsertRegion( const SwGlblDocContent* pCont, const OUString* pFileName )
735 {
736  Sequence< OUString > aFileNames;
737  if ( !pFileName )
738  {
739  m_pDocInserter.reset(new ::sfx2::DocumentInserter(GetFrameWeld(), "swriter", sfx2::DocumentInserter::Mode::InsertMulti));
740  m_pDocInserter->StartExecuteModal( LINK( this, SwGlobalTree, DialogClosedHdl ) );
741  }
742  else if ( !pFileName->isEmpty() )
743  {
744  aFileNames.realloc(1);
745  INetURLObject aFileName;
746  aFileName.SetSmartURL( *pFileName );
747  aFileNames.getArray()[0] = aFileName.GetMainURL( INetURLObject::DecodeMechanism::NONE );
748  InsertRegion( pCont, aFileNames );
749  }
750 }
751 
753 {
754  sal_uInt16 nSlot = 0;
755  switch( pCont->GetType() )
756  {
757  case GLBLDOC_UNKNOWN:
759  break;
760  case GLBLDOC_TOXBASE:
761  {
762  const SwTOXBase* pBase = pCont->GetTOX();
763  if(pBase)
764  nSlot = FN_INSERT_MULTI_TOX;
765  }
766  break;
767  case GLBLDOC_SECTION:
768  {
769  OpenDoc(pCont);
770 
771  nSlot = 0;
772  pCont = nullptr;
773  }
774  break;
775  }
776  if(pCont)
777  GotoContent(pCont);
778  if(nSlot)
779  {
781  if(Update( false ))
782  Display();
783  }
784 }
785 
786 IMPL_LINK( SwGlobalTree, PopupHdl, Menu* , pMenu, bool)
787 {
788  ExecuteContextMenuAction( pMenu->GetCurItemId());
789  return true;
790 }
791 
792 void SwGlobalTree::ExecuteContextMenuAction( sal_uInt16 nSelectedPopupEntry )
793 {
794  SvTreeListEntry* pEntry = FirstSelected();
795  SwGlblDocContent* pCont = pEntry ? static_cast<SwGlblDocContent*>(pEntry->GetUserData()) : nullptr;
796  // If a RequestHelp is called during the dialogue,
797  // then the content gets lost. Because of that a copy
798  // is created in which only the DocPos is set correctly.
799  std::unique_ptr<SwGlblDocContent> pContCopy;
800  if(pCont)
801  pContCopy.reset(new SwGlblDocContent(pCont->GetDocPos()));
803  sal_uInt16 nSlot = 0;
804  switch( nSelectedPopupEntry )
805  {
806  case CTX_UPDATE_SEL:
807  {
808  // Two passes: first update the areas, then the directories.
809  SvTreeListEntry* pSelEntry = FirstSelected();
810  while( pSelEntry )
811  {
812  SwGlblDocContent* pContent = static_cast<SwGlblDocContent*>(pSelEntry->GetUserData());
813  if(GLBLDOC_SECTION == pContent->GetType() &&
814  pContent->GetSection()->IsConnected())
815  {
816  const_cast<SwSection*>(pContent->GetSection())->UpdateNow();
817  }
818 
819  pSelEntry = NextSelected(pSelEntry);
820  }
821  pSelEntry = FirstSelected();
822  while( pSelEntry )
823  {
824  SwGlblDocContent* pContent = static_cast<SwGlblDocContent*>(pSelEntry->GetUserData());
825  if(GLBLDOC_TOXBASE == pContent->GetType())
826  m_pActiveShell->UpdateTableOf(*pContent->GetTOX());
827  pSelEntry = NextSelected(pSelEntry);
828  }
829 
830  }
831  break;
832  case CTX_UPDATE_INDEX:
833  {
834  nSlot = FN_UPDATE_TOX;
835  }
836  break;
837  case CTX_UPDATE_LINK:
838  case CTX_UPDATE_ALL:
839  {
840  m_pActiveShell->GetLinkManager().UpdateAllLinks(true, false, nullptr);
841  if(CTX_UPDATE_ALL == nSelectedPopupEntry)
842  nSlot = FN_UPDATE_TOX;
843  pCont = nullptr;
844  }
845  break;
846  case CTX_EDIT:
847  {
848  OSL_ENSURE(pCont, "edit without entry ? " );
849  if (pCont)
850  {
851  EditContent(pCont);
852  }
853  }
854  break;
855  case CTX_EDIT_LINK:
856  {
857  OSL_ENSURE(pCont, "edit without entry ? " );
858  if (pCont)
859  {
861  pCont->GetSection()->GetSectionName());
862  rDispatch.ExecuteList(FN_EDIT_REGION, SfxCallMode::ASYNCHRON,
863  { &aName });
864  }
865  }
866  break;
867  case CTX_DELETE:
868  {
869  // If several entries selected, then after each delete the array
870  // must be refilled. So you do not have to remember anything,
871  // deleting begins at the end.
872  SvTreeListEntry* pSelEntry = LastSelected();
873  std::unique_ptr<SwGlblDocContents> pTempContents;
875  while(pSelEntry)
876  {
878  pTempContents ? *pTempContents : *m_pSwGlblDocContents,
879  GetModel()->GetAbsPos(pSelEntry));
880  pSelEntry = PrevSelected(pSelEntry);
881  if(pSelEntry)
882  {
883  pTempContents.reset(new SwGlblDocContents);
884  m_pActiveShell->GetGlobalDocContent(*pTempContents);
885  }
886  }
887  pTempContents.reset();
889  pCont = nullptr;
890  }
891  break;
893  {
894  if(pContCopy)
895  {
896  SfxItemSet aSet(
898  svl::Items<
902  RES_COL, RES_COL,
903  SID_ATTR_PAGE_SIZE, SID_ATTR_PAGE_SIZE,
904  FN_PARAM_TOX_TYPE, FN_PARAM_TOX_TYPE>{});
905 
907  ScopedVclPtr<AbstractMultiTOXTabDialog> pDlg(pFact->CreateMultiTOXTabDialog(
908  GetFrameWeld(), aSet,
910  nullptr,
911  true));
912  if(RET_OK == pDlg->Execute())
913  {
914  SwTOXDescription& rDesc = pDlg->GetTOXDescription(
915  pDlg->GetCurrentTOXType());
916  SwTOXMgr aMgr(m_pActiveShell);
917  SwTOXBase* pToInsert = nullptr;
918  if(aMgr.UpdateOrInsertTOX(rDesc, &pToInsert, pDlg->GetOutputItemSet()))
919  m_pActiveShell->InsertGlobalDocContent( *pContCopy, *pToInsert );
920  }
921  pCont = nullptr;
922  }
923  }
924  break;
925  case CTX_INSERT_FILE:
926  {
927  m_pDocContent = std::move(pContCopy);
928  InsertRegion( m_pDocContent.get() );
929  pCont = nullptr;
930  }
931  break;
932  case CTX_INSERT_NEW_FILE:
933  {
934  SfxViewFrame* pGlobFrame = m_pActiveShell->GetView().GetViewFrame();
935  SwGlobalFrameListener_Impl aFrameListener(*pGlobFrame);
936 
937  sal_uLong nEntryPos = pEntry ? GetModel()->GetAbsPos(pEntry) : sal_uLong(-1);
938  // Creating a new doc
939  SfxStringItem aFactory(SID_NEWDOCDIRECT,
940  SwDocShell::Factory().GetFilterContainer()->GetName());
941 
942  const SfxFrameItem* pItem = static_cast<const SfxFrameItem*>(
943  rDispatch.ExecuteList(SID_NEWDOCDIRECT,
944  SfxCallMode::SYNCHRON, { &aFactory }));
945 
946  // save at
947  SfxFrame* pFrame = pItem ? pItem->GetFrame() : nullptr;
948  SfxViewFrame* pViewFrame = pFrame ? pFrame->GetCurrentViewFrame() : nullptr;
949  if (pViewFrame)
950  {
951  const SfxBoolItem* pBool = static_cast<const SfxBoolItem*>(
952  pViewFrame->GetDispatcher()->Execute(
953  SID_SAVEASDOC, SfxCallMode::SYNCHRON ));
954  SfxObjectShell& rObj = *pViewFrame->GetObjectShell();
955  const SfxMedium* pMedium = rObj.GetMedium();
956  OUString sNewFile(pMedium->GetURLObject().GetMainURL(INetURLObject::DecodeMechanism::ToIUri));
957  // Insert the area with the Doc-Name
958  // Bring the own Doc in the foreground
959  if(aFrameListener.IsValid() && !sNewFile.isEmpty())
960  {
961  pGlobFrame->ToTop();
962  // Due to the update the entries are invalid
963  if(nEntryPos != sal_uLong(-1))
964  {
965  Update( false );
966  Display();
967  Select(GetModel()->GetEntryAtAbsPos(nEntryPos));
968  pEntry = FirstSelected();
969  pCont = pEntry ? static_cast<SwGlblDocContent*>(pEntry->GetUserData()) : nullptr;
970  }
971  else
972  {
973  pEntry = nullptr;
974  pCont = nullptr;
975  }
976  if(pBool->GetValue())
977  {
978  InsertRegion(pCont, &sNewFile);
979  pViewFrame->ToTop();
980  }
981  else
982  pViewFrame->GetDispatcher()->Execute(SID_CLOSEWIN,
983  SfxCallMode::SYNCHRON);
984  }
985  else
986  {
987  pViewFrame->ToTop();
988  return;
989  }
990  }
991  }
992  break;
993  case CTX_INSERT_TEXT:
994  {
995  if(pCont)
997  else
998  {
999  m_pActiveShell->SplitNode(); // Empty document
1000  m_pActiveShell->Up( false );
1001  }
1003  }
1004  break;
1005  case CTX_UPDATE:
1006  pCont = nullptr;
1007  break;
1008  default:;
1009  // here nothing happens
1010  }
1011  if(pCont)
1012  GotoContent(pCont);
1013  if(nSlot)
1014  rDispatch.Execute(nSlot);
1015  if(Update( false ))
1016  Display();
1017 }
1018 
1020 {
1021  if(!IsDisposed() && !HasFocus() && Update( false ))
1022  Display();
1023 }
1024 
1026 {
1028 
1029  switch( pCont->GetType() )
1030  {
1031  case GLBLDOC_UNKNOWN:
1033  break;
1034  case GLBLDOC_TOXBASE:
1035  {
1036  const OUString sName = pCont->GetTOX()->GetTOXName();
1037  if (!m_pActiveShell->GotoNextTOXBase(&sName))
1039  }
1040  break;
1041  case GLBLDOC_SECTION:
1042  break;
1043  }
1044 
1045 }
1046 
1048 {
1051 }
1052 
1054 {
1055  m_aUpdateTimer.Stop();
1057 }
1058 
1059 void SwGlobalTree::ExecCommand(const OUString &rCmd)
1060 {
1061  SvTreeListEntry* pEntry = FirstSelected();
1062  OSL_ENSURE(pEntry, "It explodes in the next moment");
1063  if (rCmd == "edit")
1064  {
1065  const SwGlblDocContent* pCont = static_cast<const SwGlblDocContent*>(
1066  pEntry->GetUserData());
1067  EditContent(pCont);
1068  }
1069  else
1070  {
1071  if(GetSelectionCount() == 1)
1072  {
1073  bool bMove = false;
1074  sal_uLong nSource = GetModel()->GetAbsPos(pEntry);
1075  sal_uLong nDest = nSource;
1076  if (rCmd == "down")
1077  {
1078  sal_uLong nEntryCount = GetEntryCount();
1079  bMove = nEntryCount > nSource + 1;
1080  nDest+= 2;
1081  }
1082  else if (rCmd == "up")
1083  {
1084  bMove = 0 != nSource;
1085  nDest--;
1086  }
1087  if( bMove && m_pActiveShell->MoveGlobalDocContent(
1088  *m_pSwGlblDocContents, nSource, nSource + 1, nDest ) &&
1089  Update( false ))
1090  Display();
1091  }
1092  }
1093 }
1094 
1095 bool SwGlobalTree::Update(bool bHard)
1096 {
1097  SwView* pActView = GetParentWindow()->GetCreateView();
1098  bool bRet = false;
1099  if(pActView && pActView->GetWrtShellPtr())
1100  {
1101  const SwWrtShell* pOldShell = m_pActiveShell;
1102  m_pActiveShell = pActView->GetWrtShellPtr();
1103  if(m_pActiveShell != pOldShell)
1104  {
1105  m_pSwGlblDocContents.reset();
1106  }
1108  {
1110  bRet = true;
1112  }
1113  else
1114  {
1115  bool bCopy = false;
1116  std::unique_ptr<SwGlblDocContents> pTempContents(new SwGlblDocContents);
1117  m_pActiveShell->GetGlobalDocContent(*pTempContents);
1118  if(pTempContents->size() != m_pSwGlblDocContents->size() ||
1119  pTempContents->size() != GetEntryCount())
1120  {
1121  bRet = true;
1122  bCopy = true;
1123  }
1124  else
1125  {
1126  for(size_t i = 0; i < pTempContents->size() && !bCopy; i++)
1127  {
1128  SwGlblDocContent* pLeft = (*pTempContents)[i].get();
1129  SwGlblDocContent* pRight = (*m_pSwGlblDocContents)[i].get();
1130  GlobalDocContentType eType = pLeft->GetType();
1131  SvTreeListEntry* pEntry = GetEntry(i);
1132  OUString sTemp = GetEntryText(pEntry);
1133  if (
1134  eType != pRight->GetType() ||
1135  (
1136  eType == GLBLDOC_SECTION &&
1137  pLeft->GetSection()->GetSectionName() != sTemp
1138  ) ||
1139  (
1140  eType == GLBLDOC_TOXBASE &&
1141  pLeft->GetTOX()->GetTitle() != sTemp
1142  )
1143  )
1144  {
1145  bCopy = bRet = true;
1146  }
1147  }
1148  }
1149  if(bCopy || bHard)
1150  {
1151  *m_pSwGlblDocContents = std::move( *pTempContents );
1152  }
1153  }
1154 
1155  }
1156  else
1157  {
1158  Clear();
1160  m_pSwGlblDocContents->clear();
1161  }
1162  // FIXME: Implement a test for changes!
1163  return bRet;
1164 }
1165 
1167 {
1168  const OUString sFileName(pCont->GetSection()->GetLinkFileName().getToken(0,
1170  bool bFound = false;
1171  const SfxObjectShell* pCurr = SfxObjectShell::GetFirst();
1172  while( !bFound && pCurr )
1173  {
1174  if(pCurr->GetMedium() &&
1176  {
1177  bFound = true;
1179  Application::PostUserEvent( LINK( this, SwGlobalTree, ShowFrameHdl ), nullptr, true );
1180  pCurr = nullptr;
1181  }
1182  else
1183  pCurr = SfxObjectShell::GetNext(*pCurr);
1184  }
1185  if(!bFound)
1186  {
1187  SfxStringItem aURL(SID_FILE_NAME, sFileName);
1188  SfxBoolItem aReadOnly(SID_DOC_READONLY, false);
1189  SfxStringItem aTargetFrameName( SID_TARGETNAME, "_blank" );
1190  SfxStringItem aReferer(SID_REFERER, m_pActiveShell->GetView().GetDocShell()->GetTitle());
1192  ExecuteList(SID_OPENDOC, SfxCallMode::ASYNCHRON,
1193  { &aURL, &aReadOnly, &aReferer, &aTargetFrameName });
1194  }
1195 }
1196 
1197 IMPL_LINK_NOARG( SwGlobalTree, DoubleClickHdl, SvTreeListBox*, bool)
1198 {
1199  SvTreeListEntry* pEntry = GetCurEntry();
1200  SwGlblDocContent* pCont = static_cast<SwGlblDocContent*>(pEntry->GetUserData());
1201  if(pCont->GetType() == GLBLDOC_SECTION)
1202  OpenDoc(pCont);
1203  else
1204  {
1205  GotoContent(pCont);
1206  m_pActiveShell->GetView().GetEditWin().GrabFocus();
1207  }
1208  return false;
1209 }
1210 
1212 {
1213  return m_xDialog;
1214 }
1215 
1216 IMPL_STATIC_LINK_NOARG(SwGlobalTree, ShowFrameHdl, void*, void)
1217 {
1218  SfxViewFrame* pFirst = pShowShell ? SfxViewFrame::GetFirst(pShowShell) : nullptr;
1219  if (pFirst)
1220  pFirst->ToTop();
1221  SwGlobalTree::SetShowShell(nullptr);
1222 }
1223 
1225  const OUString& rStr ,const Image& rImg1,const Image& rImg2)
1226 {
1227  const size_t nColToHilite = 1; //0==Bitmap;1=="Column1";2=="Column2"
1228  SvTreeListBox::InitEntry( pEntry, rStr, rImg1, rImg2 );
1229  SvLBoxString& rCol = static_cast<SvLBoxString&>(pEntry->GetItem( nColToHilite ));
1230  pEntry->ReplaceItem(std::make_unique<SwLBoxString>(rCol.GetText()), nColToHilite);
1231 }
1232 
1233 void SwLBoxString::Paint(const Point& rPos, SvTreeListBox& rDev, vcl::RenderContext& rRenderContext,
1234  const SvViewDataEntry* pView, const SvTreeListEntry& rEntry)
1235 {
1236  SwGlblDocContent* pCont = static_cast<SwGlblDocContent*>(rEntry.GetUserData());
1237  if (pCont->GetType() == GLBLDOC_SECTION &&
1238  !pCont->GetSection()->IsConnectFlag())
1239  {
1240  rRenderContext.Push(PushFlags::FONT);
1241  vcl::Font aFont(rRenderContext.GetFont());
1242  aFont.SetColor(COL_LIGHTRED);
1243  rRenderContext.SetFont(aFont);
1244  rRenderContext.DrawText(rPos, GetText());
1245  rRenderContext.Pop();
1246  }
1247  else
1248  SvLBoxString::Paint(rPos, rDev, rRenderContext, pView, rEntry);
1249 }
1250 
1252 {
1253  if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
1254  (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
1255  {
1256  Update(true);
1257  }
1258  SvTreeListBox::DataChanged( rDCEvt );
1259 }
1260 
1261 void SwGlobalTree::InsertRegion( const SwGlblDocContent* _pContent, const Sequence< OUString >& _rFiles )
1262 {
1263  sal_Int32 nFiles = _rFiles.getLength();
1264  if ( !nFiles )
1265  return;
1266 
1267  bool bMove = false;
1268  if ( !_pContent )
1269  {
1270  SvTreeListEntry* pLast = LastVisible();
1271  _pContent = static_cast<SwGlblDocContent*>(pLast->GetUserData());
1272  bMove = true;
1273  }
1274  sal_uLong nEntryCount = GetEntryCount();
1275  const OUString* pFileNames = _rFiles.getConstArray();
1277  rSh.StartAction();
1278  // after insertion of the first new content the 'pCont' parameter becomes invalid
1279  // find the index of the 'anchor' content to always use a current anchor content
1280  size_t nAnchorContent = m_pSwGlblDocContents->size() - 1;
1281  if ( !bMove )
1282  {
1283  for (size_t nContent = 0; nContent < m_pSwGlblDocContents->size();
1284  ++nContent)
1285  {
1286  if( *_pContent == *(*m_pSwGlblDocContents)[ nContent ] )
1287  {
1288  nAnchorContent = nContent;
1289  break;
1290  }
1291  }
1292  }
1293  SwGlblDocContents aTempContents;
1294  for ( sal_Int32 nFile = 0; nFile < nFiles; ++nFile )
1295  {
1296  //update the global document content after each inserted document
1297  rSh.GetGlobalDocContent(aTempContents);
1298  SwGlblDocContent* pAnchorContent = nullptr;
1299  OSL_ENSURE(aTempContents.size() > (nAnchorContent + nFile), "invalid anchor content -> last insertion failed");
1300  if ( aTempContents.size() > (nAnchorContent + nFile) )
1301  pAnchorContent = aTempContents[nAnchorContent + nFile].get();
1302  else
1303  pAnchorContent = aTempContents.back().get();
1304  OUString sFileName(pFileNames[nFile]);
1305  INetURLObject aFileUrl;
1306  aFileUrl.SetSmartURL( sFileName );
1307  OUString sSectionName(aFileUrl.GetLastName(
1309  sal_uInt16 nSectCount = rSh.GetSectionFormatCount();
1310  OUString sTempSectionName(sSectionName);
1311  sal_uInt16 nAddNumber = 0;
1312  sal_uInt16 nCount = 0;
1313  // if applicable: add index if the range name is already in use.
1314  while ( nCount < nSectCount )
1315  {
1316  const SwSectionFormat& rFormat = rSh.GetSectionFormat(nCount);
1317  if ((rFormat.GetSection()->GetSectionName() == sTempSectionName)
1318  && rFormat.IsInNodesArr())
1319  {
1320  nCount = 0;
1321  nAddNumber++;
1322  sTempSectionName = sSectionName + ":" + OUString::number( nAddNumber );
1323  }
1324  else
1325  nCount++;
1326  }
1327 
1328  if ( nAddNumber )
1329  sSectionName = sTempSectionName;
1330 
1331  SwSectionData aSectionData(SectionType::Content, sSectionName);
1332  aSectionData.SetProtectFlag(true);
1333  aSectionData.SetHidden(false);
1334 
1335  aSectionData.SetLinkFileName(sFileName);
1336  aSectionData.SetType(SectionType::FileLink);
1337  aSectionData.SetLinkFilePassword( OUString() );
1338 
1339  rSh.InsertGlobalDocContent( *pAnchorContent, aSectionData );
1340  }
1341  if ( bMove )
1342  {
1343  Update( false );
1345  *m_pSwGlblDocContents, nEntryCount, nEntryCount + nFiles, nEntryCount - nFiles );
1346  }
1347  rSh.EndAction();
1348  Update( false );
1349  Display();
1350 
1351 }
1352 
1353 IMPL_LINK( SwGlobalTree, DialogClosedHdl, sfx2::FileDialogHelper*, _pFileDlg, void )
1354 {
1355  if ( ERRCODE_NONE != _pFileDlg->GetError() )
1356  return;
1357 
1358  SfxMediumList aMedList(m_pDocInserter->CreateMediumList());
1359  if ( !aMedList.empty() )
1360  {
1361  Sequence< OUString >aFileNames( aMedList.size() );
1362  OUString* pFileNames = aFileNames.getArray();
1363  sal_Int32 nPos = 0;
1364  for (const std::unique_ptr<SfxMedium>& pMed : aMedList)
1365  {
1366  OUString sFileName = pMed->GetURLObject().GetMainURL( INetURLObject::DecodeMechanism::NONE )
1367  + OUStringChar(sfx2::cTokenSeparator)
1368  + pMed->GetFilter()->GetFilterName()
1369  + OUStringChar(sfx2::cTokenSeparator);
1370  pFileNames[nPos++] = sFileName;
1371  }
1372  InsertRegion( m_pDocContent.get(), aFileNames );
1373  m_pDocContent.reset();
1374  }
1375 }
1376 
1377 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SfxViewFrame * GetViewFrame() const
bool GetValue() const
long Width() const
MenuEnableFlags GetEnableFlags() const
Definition: glbltree.cxx:452
void DrawText(const Point &rStartPt, const OUString &rStr, sal_Int32 nIndex=0, sal_Int32 nLen=-1, MetricVector *pVector=nullptr, OUString *pDisplayText=nullptr, const SalLayoutGlyphs *pLayoutCache=nullptr)
virtual Size GetOptimalSize() const override
Definition: glbltree.cxx:212
const SfxPoolItem * ExecuteList(sal_uInt16 nSlot, SfxCallMode nCall, std::initializer_list< SfxPoolItem const * > args, std::initializer_list< SfxPoolItem const * > internalargs=std::initializer_list< SfxPoolItem const * >())
#define FN_UPDATE_TOX
Definition: cmdid.h:495
URL aURL
#define RES_FRM_SIZE
Definition: hintids.hxx:289
#define RES_COL
Definition: hintids.hxx:309
const Value & back() const
SvTreeListEntry * NextSelected(SvTreeListEntry *pEntry) const
void EditContent(const SwGlblDocContent *pCont)
Definition: glbltree.cxx:752
const css::datatransfer::dnd::DropTargetDropEvent maDropEvent
virtual void RequestHelp(const HelpEvent &rHEvt) override
Definition: glbltree.cxx:482
void SplitNode(bool bAutoFormat=false)
Definition: wrtsh1.cxx:981
#define CTX_DELETE
Definition: glbltree.cxx:70
virtual void MouseButtonDown(const MouseEvent &rMEvt) override
Definition: glbltree.cxx:614
virtual VclPtr< PopupMenu > CreateContextMenu() override
Definition: glbltree.cxx:354
#define FN_EDIT_REGION
Definition: cmdid.h:108
#define CTX_EDIT_LINK
Definition: glbltree.cxx:71
SwNavigationPI * GetParentWindow()
Definition: glbltree.cxx:1211
virtual DragDropMode NotifyStartDrag(TransferDataContainer &rData, SvTreeListEntry *) override
Definition: glbltree.cxx:554
bool MoveGlobalDocContent(const SwGlblDocContents &rArr, size_t nFromPos, size_t nToPos, size_t nNewPos)
Definition: edglbldc.cxx:297
virtual void DragFinished(sal_Int8 nDropAction)
OUString GetTitle(sal_uInt16 nMaxLen=0) const
void Notify(SwFlyFrame *pFly, SwPageFrame *pOld, const SwRect &rOld, const SwRect *pOldRect=nullptr)
Notify the background based on the difference between old and new rectangle.
Definition: frmtool.cxx:3003
const char aData[]
Definition: ww8scan.hxx:47
long AdjustX(long nHorzMove)
virtual void MouseButtonDown(const MouseEvent &rMEvt)
sfx2::LinkManager & GetLinkManager()
Definition: editsh.cxx:592
SfxFrame * GetFrame() const
virtual void DragFinished(sal_Int8) override
Definition: glbltree.cxx:605
void SetHelpId(sal_uInt16 nItemId, const OString &rHelpId)
virtual void StartDrag(sal_Int8 nAction, const Point &rPosPixel) override
Definition: glbltree.cxx:599
signed char sal_Int8
SvTreeList * GetModel() const
bool m_bLastEntryEmphasis
Definition: conttree.hxx:276
virtual void Paint(const Point &rPos, SvTreeListBox &rOutDev, vcl::RenderContext &rRenderContext, const SvViewDataEntry *pView, const SvTreeListEntry &rEntry) override
SfxDispatcher * GetDispatcher()
void SetDoubleClickHdl(const Link< SvTreeListBox *, bool > &rNewHdl)
sal_uIntPtr sal_uLong
std::unique_ptr< SwGlblDocContents > m_pSwGlblDocContents
Definition: conttree.hxx:270
void disposeAndClear()
sal_uLong GetEntryCount() const
SvLBoxItem * GetItem(SvTreeListEntry *, long nX, SvLBoxTab **ppTab)
#define GLOBAL_CONTEXT_COUNT
Definition: swcont.hxx:48
const sal_Unicode cTokenSeparator
sal_Int64 n
static const SfxObjectShell * pShowShell
Definition: conttree.hxx:278
bool IsDropFormatSupported(SotClipboardFormatId nFormat)
virtual Size GetSizePixel() const
bool IsConnected() const
Definition: section.hxx:225
static ImplSVEvent * PostUserEvent(const Link< void *, void > &rLink, void *pCaller=nullptr, bool bReferenceLink=false)
sal_uInt16 GetCode() const
virtual void StartDrag(sal_Int8 nAction, const Point &rPosPixel) override
virtual TriState NotifyMoving(SvTreeListEntry *pTarget, SvTreeListEntry *pEntry, SvTreeListEntry *&rpNewParent, sal_uLong &rNewChildPos) override
Definition: glbltree.cxx:567
DataChangedEventType GetType() const
void EnterStdMode()
Definition: select.cxx:550
SwEditWin & GetEditWin()
Definition: view.hxx:403
sal_uInt16 Execute(vcl::Window *pWindow, const Point &rPopupPos)
constexpr::Color COL_LIGHTRED(0xFF, 0x00, 0x00)
OUString GetLastName(DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
const OUString & GetText() const
long GetPos() const
virtual void RequestHelp(const HelpEvent &rHEvt) override
void SetHelpId(const OString &)
virtual bool DoubleClickHdl()
OUString const & GetLinkFileName() const
Definition: section.cxx:544
static const char * aHelpForMenu[]
Definition: glbltree.cxx:79
virtual SfxObjectShell * GetObjectShell() override
virtual void InitEntry(SvTreeListEntry *, const OUString &, const Image &, const Image &) override
Definition: glbltree.cxx:1224
#define HID_GLBLTREE_INSERT
Definition: helpids.h:43
virtual bool NotifyAcceptDrop(SvTreeListEntry *) override
Definition: glbltree.cxx:594
bool HasFormat(SotClipboardFormatId nFormat) const
SvTreeListEntry * LastSelected() const
#define CTX_EDIT
Definition: glbltree.cxx:69
HelpEventMode GetMode() const
SfxHintId GetId() const
SwGlobalTree(vcl::Window *pParent, SwNavigationPI *pDialog)
Definition: glbltree.cxx:172
virtual sal_IntPtr GetTabPos(SvTreeListEntry *, SvLBoxTab *) override
Definition: glbltree.cxx:562
void EnableContextMenuHandling()
virtual void DataChanged(const DataChangedEvent &rDCEvt) override
Definition: glbltree.cxx:1251
void SetUpdateMode(bool)
SwWrtShell & GetWrtShell() const
Definition: view.hxx:400
sal_uLong GetAbsPos(SvTreeListEntry const *pEntry) const
Used by the UI to modify the document model.
Definition: wrtsh.hxx:90
virtual void DataChanged(const DataChangedEvent &rDCEvt) override
IMPL_STATIC_LINK_NOARG(SwGlobalTree, ShowFrameHdl, void *, void)
Definition: glbltree.cxx:1216
weld::Window * GetFrameWeld() const
sal_uInt16 GetClicks() const
int GetHeight(const SvTreeListBox *pView, const SvTreeListEntry *pEntry) const
#define GLOBAL_UPDATE_TIMEOUT
Definition: glbltree.cxx:73
const SwView & GetView() const
Definition: wrtsh.hxx:428
bool GotoNextTOXBase(const OUString *pName=nullptr)
Definition: move.cxx:646
virtual void GetFocus() override
DragDropMode
#define KEY_MOD2
void setX(long nX)
SvTreeListEntry * FirstSelected() const
const vcl::Font & GetFont() const
virtual TriState NotifyCopying(SvTreeListEntry *pTarget, SvTreeListEntry *pEntry, SvTreeListEntry *&rpNewParent, sal_uLong &rNewChildPos) override
Definition: glbltree.cxx:585
void SetDragDropMode(DragDropMode)
#define HID_GLBLTREE_UPD_LINK
Definition: helpids.h:52
virtual void KeyInput(const KeyEvent &rKEvt) override
int nCount
bool GotoPrevTOXBase(const OUString *=nullptr)
jump to previous index
Definition: crstrvl.cxx:314
#define DND_ACTION_NONE
AllSettingsFlags GetFlags() const
static OUString CreateDropFileName(TransferableDataHelper &rData)
Definition: navipi.cxx:928
void ToggleTree()
Definition: navipi.cxx:1038
#define HID_GLBLTREE_INS_NEW_FILE
Definition: helpids.h:48
virtual sal_Int8 AcceptDrop(const AcceptDropEvent &rEvt) override
Definition: glbltree.cxx:295
SfxViewFrame * GetCurrentViewFrame() const
sal_uInt16 GetModifier() const
void InsertSeparator(const OString &rIdent=OString(), sal_uInt16 nPos=MENU_APPEND)
void EnableItem(sal_uInt16 nItemId, bool bEnable=true)
size_type size() const
void UpdateTableOf(const SwTOXBase &rTOX, const SfxItemSet *pSet=nullptr)
Definition: wrtsh2.cxx:332
const SwSectionFormat & GetSectionFormat(size_t nFormat) const
Definition: edsect.cxx:141
const char * sName
void GotoContent(const SwGlblDocContent *)
Definition: glbltree.cxx:1025
#define CTX_INSERT_NEW_FILE
Definition: glbltree.cxx:59
MenuEnableFlags
Definition: conttree.hxx:55
SfxItemPool & GetPool() const
void Update()
tools::Rectangle GetItemRect(sal_uInt16 nItemId)
void SetPopupMenu(sal_uInt16 nItemId, PopupMenu *pMenu)
const Point & GetMousePosPixel() const
#define RES_BACKGROUND
Definition: hintids.hxx:305
std::unique_ptr< sfx2::DocumentInserter > m_pDocInserter
Definition: conttree.hxx:273
#define HID_GLBLTREE_DEL
Definition: helpids.h:45
#define HID_GLBLTREE_EDIT_LINK
Definition: helpids.h:55
#define CTX_UPDATE_INDEX
Definition: glbltree.cxx:63
virtual void MouseButtonDown(const MouseEvent &rMEvt) override
void clear()
bool Up(bool bSelect, sal_uInt16 nCount=1, bool bBasicCall=false)
Definition: move.cxx:141
#define CTX_INSERT_FILE
Definition: glbltree.cxx:58
void SetSelectHdl(const Link< Menu *, bool > &rLink)
#define HID_GLBLTREE_INS_IDX
Definition: helpids.h:46
void EndSelection()
VclPtr< ToolBox > m_aGlobalToolBox
Definition: navipi.hxx:70
sal_uLong GetAbsPos(const SvTreeListEntry *pEntry) const
SvTreeListEntry * m_pDDSource
Definition: conttree.hxx:269
#define HID_GLBLTREE_UPDATE
Definition: helpids.h:42
#define HID_GLBLTREE_UPD_IDX
Definition: helpids.h:51
const OUString & GetSectionName() const
Definition: section.hxx:169
void Clear()
Definition: glbltree.cxx:648
void EndAction(const bool bIdleEnd=false, const bool DoSetPosX=false)
Definition: crsrsh.cxx:232
void DeleteGlobalDocContent(const SwGlblDocContents &rArr, size_t nPos)
Definition: edglbldc.cxx:233
static void SetShowShell(const SfxObjectShell *pSet)
Definition: conttree.hxx:334
virtual void dispose() override
Definition: glbltree.cxx:203
int i
#define CTX_UPDATE_SEL
Definition: glbltree.cxx:62
TRISTATE_FALSE
virtual void Invalidate(InvalidateFlags nFlags=InvalidateFlags::NONE)
css::uno::Reference< css::datatransfer::dnd::XDropTarget > GetDropTarget()
void * GetUserData() const
IMPL_LINK(SwGlobalTree, PopupHdl, Menu *, pMenu, bool)
Definition: glbltree.cxx:786
::rtl::Reference< Content > pContent
virtual void Start() override
OUString GetFile(size_t nIndex) const
size
#define CTX_UPDATE
Definition: glbltree.cxx:67
static SwAbstractDialogFactory * Create()
Definition: swabstdlg.cxx:36
Display
virtual SvTreeListEntry * InsertEntry(const OUString &rText, SvTreeListEntry *pParent=nullptr, bool bChildrenOnDemand=false, sal_uLong nPos=TREELIST_APPEND, void *pUserData=nullptr)
void StartListening(SfxBroadcaster &rBroadcaster, DuplicateHandling eDuplicateHanding=DuplicateHandling::Unexpected)
OUString SwResId(const char *pId)
Definition: swmodule.cxx:178
virtual void InitEntry(SvTreeListEntry *, const OUString &, const Image &, const Image &)
#define DND_ACTION_LINK
virtual OUString GetEntryText(SvTreeListEntry *pEntry) const
const SvLBoxItem & GetItem(size_t nPos) const
size_t Count() const
DocumentType const eType
void SetTimeout(sal_uInt64 nTimeoutMs)
Point ScreenToOutputPixel(const Point &rPos) const
void GrabFocus()
GlobalDocContentType
Definition: edglbldc.hxx:29
static void ShowQuickHelp(vcl::Window *pParent, const tools::Rectangle &rScreenRect, const OUString &rHelpText, QuickHelpFlags nStyle=QuickHelpFlags::NONE)
const OUString & GetTitle() const
Definition: tox.hxx:674
long X() const
void GetGlobalDocContent(SwGlblDocContents &rArr) const
Definition: edglbldc.cxx:54
void GotoGlobalDocContent(const SwGlblDocContent &rPos)
Definition: edglbldc.cxx:334
static bool IsBalloonHelpEnabled()
SwDocShell * GetDocShell()
Definition: view.cxx:1107
void EnableItem(sal_uInt16 nItemId, bool bEnable=true)
bool IsReadOnly() const
void InsertRegion(const SwGlblDocContent *_pContent, const css::uno::Sequence< OUString > &_rFiles)
Point GetEntryPosition(SvTreeListEntry *) const
void SetColor(const Color &)
#define HID_GLBLTREE_UPD_SEL
Definition: helpids.h:50
virtual SvLBoxItemType GetType() const =0
#define RES_LR_SPACE
Definition: hintids.hxx:291
Point LogicToPixel(const Point &rLogicPt) const
void StartAction()
Definition: crsrsh.cxx:215
SvTreeListEntry * Next(SvTreeListEntry *pEntry) const
void HideTree()
Definition: glbltree.cxx:1053
SwView * GetCreateView() const
Definition: navipi.cxx:1100
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
#define KEY_RETURN
SvTreeListEntry * LastVisible() const
int GetWidth(const SvTreeListBox *pView, const SvTreeListEntry *pEntry) const
SvTreeListEntry * First() const
const SwTOXBase * GetTOX() const
Definition: edglbldc.hxx:53
size_t GetSectionFormatCount() const
Definition: edsect.cxx:113
AutoTimer m_aUpdateTimer
Definition: conttree.hxx:264
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint)
void InsertItem(sal_uInt16 nItemId, const OUString &rStr, MenuItemBits nItemBits=MenuItemBits::NONE, const OString &rIdent=OString(), sal_uInt16 nPos=MENU_APPEND)
const vcl::KeyCode & GetKeyCode() const
SwWrtShell * m_pActiveShell
Definition: conttree.hxx:267
void InsertGlobalDocContent(const SwGlblDocContent &rPos, SwSectionData &rNew)
Definition: edglbldc.cxx:131
SvTreeListEntry * m_pEmphasisEntry
Definition: conttree.hxx:268
IMPL_LINK_NOARG(SwGlobalTree, Timeout, Timer *, void)
Definition: glbltree.cxx:1019
OUString GetItemCommand(sal_uInt16 nItemId) const
SwWrtShell * GetWrtShellPtr() const
Definition: view.hxx:401
virtual void Paint(const Point &rPos, SvTreeListBox &rDev, vcl::RenderContext &rRenderContext, const SvViewDataEntry *pView, const SvTreeListEntry &rEntry) override
Definition: glbltree.cxx:1233
#define HID_GLBLTREE_INS_FILE
Definition: helpids.h:47
void Stop()
VclPtr< SwNavigationPI > m_xDialog
Definition: conttree.hxx:263
#define HID_NAVIGATOR_GLOB_TREELIST
Definition: helpids.h:41
virtual sal_Int8 ExecuteDrop(const ExecuteDropEvent &rEvt) override
Definition: glbltree.cxx:217
#define ERRCODE_NONE
static SfxObjectShell * GetFirst(const std::function< bool(const SfxObjectShell *)> &isObjectShell=nullptr, bool bOnlyVisible=true)
void UpdateAllLinks(bool bAskUpdate, bool bUpdateGrfLinks, weld::Window *pParentWin)
bool m_bIsInternalDrag
Definition: conttree.hxx:275
GlobalDocContentType GetType() const
Query contents.
Definition: edglbldc.hxx:50
void SetFont(const vcl::Font &rNewFont)
virtual void KeyInput(const KeyEvent &rKEvt) override
Definition: glbltree.cxx:631
void ReplaceItem(std::unique_ptr< SvLBoxItem > pNewItem, size_t nPos)
OUString aName
bool IsLeft() const
void OpenDoc(const SwGlblDocContent *)
Definition: glbltree.cxx:1166
SvTreeListEntry * GetEntry(SvTreeListEntry *pParent, sal_uLong nPos) const
RET_OK
#define HID_GLBLTREE_EDIT
Definition: helpids.h:44
bool IsConnectFlag() const
Definition: section.hxx:239
static VclPtr< reference_type > Create(Arg &&...arg)
const SwSection * GetSection() const
Definition: edglbldc.hxx:51
Reference< XExecutableDialog > m_xDialog
bool GetFileList(SotClipboardFormatId nFormat, FileList &rFileList)
const INetURLObject & GetURLObject() const
#define HID_GLBLTREE_INS_TEXT
Definition: helpids.h:49
#define CTX_UPDATE_ALL
Definition: glbltree.cxx:65
void Display(bool bOnlyUpdateUserData=false)
Definition: glbltree.cxx:654
#define CTX_INSERT_ANY_INDEX
Definition: glbltree.cxx:57
void SetInvokeHandler(const Link< Timer *, void > &rLink)
const Point & GetPosPixel() const
virtual void ExecuteContextMenuAction(sal_uInt16 nSelectedPopupEntry) override
Definition: glbltree.cxx:792
#define GLBL_TABPOS_SUB
Definition: glbltree.cxx:76
virtual void SelectHdl() override
Definition: glbltree.cxx:530
SvTreeListEntry * PrevSelected(SvTreeListEntry *pEntry) const
virtual void dispose() override
SvTreeListEntry * GetEntryAtAbsPos(sal_uLong nAbsPos) const
#define CTX_UPDATE_LINK
Definition: glbltree.cxx:64
WindowType GetType() const
sal_uInt16 GetItemId(ImplToolItems::size_type nPos) const
#define CTX_INSERT
Definition: glbltree.cxx:68
void ExecCommand(const OUString &rCmd)
Definition: glbltree.cxx:1059
static SfxViewFrame * GetFirst(const SfxObjectShell *pDoc=nullptr, bool bOnlyVisible=true)
virtual void GetFocus() override
Definition: glbltree.cxx:624
static SfxObjectShell * GetNext(const SfxObjectShell &rPrev, const std::function< bool(const SfxObjectShell *)> &isObjectShell=nullptr, bool bOnlyVisible=true)
#define FN_PARAM_TOX_TYPE
Definition: cmdid.h:795
void ImplShowTargetEmphasis(SvTreeListEntry *pEntry, bool bShow)
#define CTX_INSERT_TEXT
Definition: glbltree.cxx:60
Point OutputToScreenPixel(const Point &rPos) const
virtual bool Select(SvTreeListEntry *pEntry, bool bSelect=true)
const SfxPoolItem * Execute(sal_uInt16 nSlot, SfxCallMode nCall=SfxCallMode::SLOT, const SfxPoolItem **pArgs=nullptr, sal_uInt16 nModi=0, const SfxPoolItem **pInternalArgs=nullptr)
OUString m_aContextStrings[GLOBAL_CONTEXT_COUNT]
Definition: conttree.hxx:265
static const char * GLOBAL_CONTEXT_ARY[]
Definition: glbltree.cxx:154
virtual ~SwGlobalTree() override
Definition: glbltree.cxx:198
void TbxMenuHdl(sal_uInt16 nTbxId, ToolBox *pBox)
Definition: glbltree.cxx:413
std::unique_ptr< SwGlblDocContent > m_pDocContent
Definition: conttree.hxx:272
#define TREELIST_ENTRY_NOTFOUND
SwSection * GetSection() const
Definition: section.cxx:671
bool Detect(bool bExtendedInfo=false)
sal_Int8 mnAction
TriState
#define FN_INSERT_MULTI_TOX
Definition: cmdid.h:276
sal_uLong GetSelectionCount() const
void Push(PushFlags nFlags=PushFlags::ALL)
void setWidth(long nWidth)
GLOBAL_CONTEXT_IDX
Definition: glbltree.cxx:134
void ShowTree()
Definition: glbltree.cxx:1047
#define HID_GLBLTREEUPD_ALL
Definition: helpids.h:53
SvTreeListEntry * Prev(SvTreeListEntry *pEntry) const
sal_uLong GetDocPos() const
Definition: edglbldc.hxx:55
Definition: view.hxx:146
sal_uInt16 nPos
virtual void DeselectHdl() override
Definition: glbltree.cxx:549
bool UpdateOrInsertTOX(const SwTOXDescription &rDesc, SwTOXBase **ppBase, const SfxItemSet *pSet)
Definition: toxmgr.cxx:266
bool SetSmartURL(OUString const &rTheAbsURIRef, EncodeMechanism eMechanism=EncodeMechanism::WasEncoded, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8, FSysStyle eStyle=FSysStyle::Detect)
const OUString & GetTOXName() const
Definition: tox.hxx:441
static void ShowBalloon(vcl::Window *pParent, const Point &rScreenPos, const tools::Rectangle &, const OUString &rHelpText)
#define TREELIST_APPEND
::std::vector< std::unique_ptr< SfxMedium > > SfxMediumList
bool IsMod1() const
void Show(bool bVisible=true, ShowFlags nFlags=ShowFlags::NONE)
bool IsInNodesArr() const
Definition: section.cxx:915
SfxMedium * GetMedium() const