LibreOffice Module sw (master)  1
conttree.hxx
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 #ifndef INCLUDED_SW_SOURCE_UIBASE_INC_CONTTREE_HXX
20 #define INCLUDED_SW_SOURCE_UIBASE_INC_CONTTREE_HXX
21 
22 #include <svl/lstner.hxx>
23 #include <vcl/timer.hxx>
24 #include <vcl/transfer.hxx>
25 #include <vcl/weld.hxx>
26 #include <ndarr.hxx>
27 #include "swcont.hxx"
28 
29 #include <map>
30 #include <memory>
31 
32 #include <o3tl/enumarray.hxx>
33 #include <o3tl/typed_flags_set.hxx>
34 
35 class SwWrtShell;
36 class SwContentType;
37 class SwNavigationPI;
38 class SwNavigationConfig;
39 class Menu;
40 class ToolBox;
41 class SwGlblDocContents;
42 class SwGlblDocContent;
43 class SfxObjectShell;
44 class SdrObject;
45 
46 enum class EditEntryMode
47 {
48  EDIT = 0,
49  UPD_IDX = 1,
50  RMV_IDX = 2,
51  UNPROTECT_TABLE = 3,
52  DELETE = 4,
53  RENAME = 5,
54 };
55 
56 // Flags for PopupMenu-enable/disable
57 enum class MenuEnableFlags {
58  NONE = 0x0000,
59  InsertIdx = 0x0001,
60  InsertFile = 0x0002,
61  InsertText = 0x0004,
62  Edit = 0x0008,
63  Delete = 0x0010,
64  Update = 0x0020,
65  UpdateSel = 0x0040,
66  EditLink = 0x0080
67 };
68 namespace o3tl {
69  template<> struct typed_flags<MenuEnableFlags> : is_typed_flags<MenuEnableFlags, 0x00ff> {};
70 }
71 
72 class SwContentTree;
73 
75 {
76 private:
78 
79  virtual sal_Int8 AcceptDrop( const AcceptDropEvent& rEvt ) override;
80  virtual sal_Int8 ExecuteDrop( const ExecuteDropEvent& rEvt ) override;
81 
82 public:
84 };
85 
87 class SwContentTree final : public SfxListener
88 {
89  std::unique_ptr<weld::TreeView> m_xTreeView;
90  std::unique_ptr<weld::TreeIter> m_xScratchIter;
93  OUString m_sSpace;
95 
99  OUString m_sInvisible;
100 
101  SwWrtShell* m_pHiddenShell; // dropped Doc
102  SwWrtShell* m_pActiveShell; // the active or a const. open view
104 
105  std::map< void*, bool > mOutLineNodeMap;
106 
107  sal_Int32 m_nActiveBlock;
108  sal_Int32 m_nHiddenBlock;
113 
114  sal_uInt8 m_nOutlineTracking = 1; // 1 default, 2 focus, 3 off
115  bool m_bTableTracking = true;
116  bool m_bSectionTracking = true;
117 
119 
120  enum class State { ACTIVE, CONSTANT, HIDDEN } m_eState;
121 
122  bool m_bIsRoot :1;
123  bool m_bIsIdleClear :1;
127 
128  // outline root mode drag & drop
129  std::vector<std::unique_ptr<weld::TreeIter>> m_aDndOutlinesSelected;
130 
131  bool m_bIgnoreViewChange = false;
132 
138 
139  void insert(const weld::TreeIter* pParent, const OUString& rStr, const OUString& rId,
140  bool bChildrenOnDemand, weld::TreeIter* pRet);
141 
142  void remove(const weld::TreeIter& rIter);
143 
145 
146  bool FillTransferData( TransferDataContainer& rTransfer,
147  sal_Int8& rDragMode );
148 
150  bool HasContentChanged();
151 
152  size_t GetAbsPos(const weld::TreeIter& rIter);
153 
154  void EditEntry(const weld::TreeIter& rEntry, EditEntryMode nMode);
155 
156  void GotoContent(const SwContent* pCnt);
157 
158  void ExecuteContextMenuAction(const OString& rSelectedPopupEntry);
159 
161 
162  size_t GetEntryCount() const;
163 
164  size_t GetChildCount(const weld::TreeIter& rParent) const;
165 
166  std::unique_ptr<weld::TreeIter> GetEntryAtAbsPos(size_t nAbsPos) const;
167 
168  void Expand(const weld::TreeIter& rParent, std::vector<std::unique_ptr<weld::TreeIter>>* pNodesToExpand);
169 
170  void MoveOutline(SwOutlineNodes::size_type nTargetPos);
171 
172  void UpdateLastSelType();
173 
175  DECL_LINK(ExpandHdl, const weld::TreeIter&, bool);
177  DECL_LINK(CollapseHdl, const weld::TreeIter&, bool);
178  DECL_LINK(ContentDoubleClickHdl, weld::TreeView&, bool);
179  DECL_LINK(SelectHdl, weld::TreeView&, void);
180  DECL_LINK(FocusInHdl, weld::Widget&, void);
181  DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
182  DECL_LINK(CommandHdl, const CommandEvent&, bool);
183  DECL_LINK(QueryTooltipHdl, const weld::TreeIter&, OUString);
184  DECL_LINK(DragBeginHdl, bool&, bool);
185  DECL_LINK(TimerUpdate, Timer *, void);
186 
187 public:
188  SwContentTree(std::unique_ptr<weld::TreeView> xTreeView, SwNavigationPI* pDialog);
189  ~SwContentTree();
191 
193  void ToggleToRoot();
194  void SetRootType(ContentTypeId nType);
195 
197  void Display( bool bActiveView );
199  void clear();
200 
202  void SetHiddenShell(SwWrtShell* pSh);
203  void ShowHiddenShell();
204  void ShowActualView();
205 
207  void SetActiveShell(SwWrtShell* pSh);
208 
210  void SetConstantShell(SwWrtShell* pSh);
211 
213  { return State::HIDDEN == m_eState ? m_pHiddenShell : m_pActiveShell; }
214 
215  bool IsInDrag() const;
216 
218  void SetOutlineLevel(sal_uInt8 nSet);
219 
220  void SetOutlineTracking(sal_uInt8 nSet);
221  void SetTableTracking(bool bSet);
222  void SetSectionTracking(bool bSet);
223 
225  void ExecCommand(std::string_view rCmd, bool bModifier);
226 
227  void ShowTree();
228  void HideTree();
229 
230  bool IsConstantView() const { return State::CONSTANT == m_eState; }
231  bool IsActiveView() const { return State::ACTIVE == m_eState; }
232  bool IsHiddenView() const { return State::HIDDEN == m_eState; }
233 
234  const SwWrtShell* GetActiveWrtShell() const {return m_pActiveShell;}
236 
237  void Select();
238 
239  void UpdateTracking();
241 
242  // return true if it has any children
243  bool RequestingChildren(const weld::TreeIter& rParent);
244 
245  virtual void Notify(SfxBroadcaster& rBC, SfxHint const& rHint) override;
246 
247  sal_Int8 AcceptDrop(const AcceptDropEvent& rEvt);
249 
251  {
252  return m_aDropTargetHelper.IsDropFormatSupported(nFormat);
253  }
254 
255  void set_accessible_name(const OUString& rName)
256  {
257  m_xTreeView->set_accessible_name(rName);
258  }
259 
260  void grab_focus()
261  {
262  m_xTreeView->grab_focus();
263  }
264 
266  {
267  m_xTreeView->set_selection_mode(eMode);
268  }
269 
271  {
272  return *m_xTreeView;
273  }
274 };
275 
276 namespace sfx2 { class DocumentInserter; }
277 namespace sfx2 { class FileDialogHelper; }
278 
279 class SwGlobalTree;
280 
282 {
283 private:
285 
286  virtual sal_Int8 AcceptDrop( const AcceptDropEvent& rEvt ) override;
287  virtual sal_Int8 ExecuteDrop( const ExecuteDropEvent& rEvt ) override;
288 
289 public:
291 };
292 
293 class SwGlobalTree final : public SfxListener
294 {
295 private:
296  std::unique_ptr<weld::TreeView> m_xTreeView;
301 
303  std::unique_ptr<SwGlblDocContents> m_pSwGlblDocContents; // array with sorted content
304 
305  std::unique_ptr<SwGlblDocContent> m_pDocContent;
306  std::unique_ptr<sfx2::DocumentInserter> m_pDocInserter;
307 
308  static const SfxObjectShell* pShowShell;
309 
310  void InsertRegion( const SwGlblDocContent* _pContent,
311  const css::uno::Sequence< OUString >& _rFiles );
312 
313  DECL_LINK( DialogClosedHdl, sfx2::FileDialogHelper*, void );
314 
315  void Select();
316 
317  DECL_LINK(Timeout, Timer*, void);
318  DECL_LINK(DoubleClickHdl, weld::TreeView&, bool);
319  DECL_LINK(SelectHdl, weld::TreeView&, void);
320  DECL_LINK(FocusInHdl, weld::Widget&, void);
321  DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
322  DECL_LINK(CommandHdl, const CommandEvent&, bool);
323  DECL_LINK(QueryTooltipHdl, const weld::TreeIter&, OUString);
324 
326 
327  void OpenDoc(const SwGlblDocContent*);
328  void GotoContent(const SwGlblDocContent*);
330 
331  static void SetShowShell(const SfxObjectShell*pSet) {pShowShell = pSet;}
332  DECL_STATIC_LINK(SwGlobalTree, ShowFrameHdl, void*, void);
333 
334 public:
335  SwGlobalTree(std::unique_ptr<weld::TreeView> xTreeView, SwNavigationPI* pDialog);
336  ~SwGlobalTree();
337 
338  bool get_visible() const { return m_xTreeView->get_visible(); }
339 
340  void set_accessible_name(const OUString& rName)
341  {
342  m_xTreeView->set_accessible_name(rName);
343  }
344 
345  void grab_focus()
346  {
347  m_xTreeView->grab_focus();
348  }
349 
351  {
352  m_xTreeView->set_selection_mode(eMode);
353  }
354 
356  {
357  return *m_xTreeView;
358  }
359 
360  void MoveSelectionTo(const weld::TreeIter* pDropTarget);
361 
362  void TbxMenuHdl(std::string_view rCommand, weld::Menu& rMenu);
363  void InsertRegion( const SwGlblDocContent* pCont,
364  const OUString* pFileName = nullptr );
365  void EditContent(const SwGlblDocContent* pCont );
366 
367  void ShowTree();
368  void HideTree();
369 
370  void ExecCommand(std::string_view rCmd);
371 
372  void Display(bool bOnlyUpdateUserData = false);
373 
374  bool Update(bool bHard);
375 
376  void ExecuteContextMenuAction(std::string_view rSelectedPopupEntry);
377 
378  const SwWrtShell* GetActiveWrtShell() const {return m_pActiveShell;}
379 
380  virtual void Notify(SfxBroadcaster& rBC, SfxHint const& rHint) override;
381  void UpdateTracking();
382 };
383 
384 #endif
385 
386 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetSectionTracking(bool bSet)
Definition: content.cxx:4500
MenuEnableFlags GetEnableFlags() const
Definition: glbltree.cxx:312
bool RequestingChildren(const weld::TreeIter &rParent)
Definition: content.cxx:1879
void DeleteOutlineSelections()
Definition: content.cxx:4441
ContentTypeId
Definition: swcont.hxx:29
void EditContent(const SwGlblDocContent *pCont)
Definition: glbltree.cxx:533
void TbxMenuHdl(std::string_view rCommand, weld::Menu &rMenu)
Definition: glbltree.cxx:296
SwNavigationPI * GetParentWindow()
Definition: glbltree.cxx:994
size_t GetChildCount(const weld::TreeIter &rParent) const
Definition: content.cxx:2220
ContentTypeId m_nRootType
Definition: conttree.hxx:110
std::unique_ptr< weld::TreeIter > m_xScratchIter
Definition: conttree.hxx:90
void MoveSelectionTo(const weld::TreeIter *pDropTarget)
Definition: glbltree.cxx:389
SwContentTreeDropTarget(SwContentTree &rTreeView)
Definition: content.cxx:1229
void SetHiddenShell(SwWrtShell *pSh)
After a file is dropped on the Navigator, the new shell will be set.
Definition: content.cxx:2913
OUString m_aContextStrings[CONTEXT_COUNT+1]
Definition: conttree.hxx:98
signed char sal_Int8
DECL_STATIC_LINK(SwGlobalTree, ShowFrameHdl, void *, void)
void ShowActualView()
Definition: content.cxx:4517
SwWrtShell * m_pHiddenShell
Definition: conttree.hxx:101
bool HasContentChanged()
Check if the displayed content is valid.
Definition: content.cxx:2676
std::unique_ptr< SwGlblDocContents > m_pSwGlblDocContents
Definition: conttree.hxx:303
void UpdateLastSelType()
Definition: content.cxx:2885
#define GLOBAL_CONTEXT_COUNT
Definition: swcont.hxx:51
void Select()
Definition: content.cxx:4530
static const SfxObjectShell * pShowShell
Definition: conttree.hxx:308
SwContentTree(std::unique_ptr< weld::TreeView > xTreeView, SwNavigationPI *pDialog)
Definition: content.cxx:1117
SwContentTreeDropTarget m_aDropTargetHelper
Definition: conttree.hxx:91
void ExecCommand(std::string_view rCmd, bool bModifier)
Execute commands of the Navigator.
Definition: content.cxx:3040
SwGlobalTree & m_rTreeView
Definition: conttree.hxx:284
virtual sal_Int8 AcceptDrop(const AcceptDropEvent &rEvt) override
Definition: glbltree.cxx:232
bool IsActiveView() const
Definition: conttree.hxx:231
SelectionMode
virtual void Notify(SfxBroadcaster &rBC, SfxHint const &rHint) override
Definition: glbltree.cxx:1120
sal_uInt8 GetOutlineLevel() const
Definition: conttree.hxx:217
void HideTree()
Definition: content.cxx:3355
void UpdateTracking()
Definition: content.cxx:3548
weld::TreeView & get_widget()
Definition: conttree.hxx:270
void EditEntry(const weld::TreeIter &rEntry, EditEntryMode nMode)
Definition: content.cxx:4583
void ExecuteContextMenuAction(const OString &rSelectedPopupEntry)
Definition: content.cxx:4217
const SwWrtShell * GetActiveWrtShell() const
Definition: conttree.hxx:378
Used by the UI to modify the document model.
Definition: wrtsh.hxx:93
sal_uInt8 m_nOutlineLevel
Definition: conttree.hxx:112
void FindActiveTypeAndRemoveUserData()
Before any data will be deleted, the last active entry has to be found.
Definition: content.cxx:2901
std::unique_ptr< weld::TreeIter > GetEntryAtAbsPos(size_t nAbsPos) const
Definition: content.cxx:2243
TreeListBox for content indicator.
Definition: conttree.hxx:87
void set_accessible_name(const OUString &rName)
Definition: conttree.hxx:255
SwGlobalTreeDropTarget m_aDropTargetHelper
Definition: conttree.hxx:297
bool IsConstantView() const
Definition: conttree.hxx:230
SwGlobalTreeDropTarget(SwGlobalTree &rTreeView)
Definition: glbltree.cxx:160
void set_selection_mode(SelectionMode eMode)
Definition: conttree.hxx:350
SwWrtShell * GetHiddenWrtShell()
Definition: conttree.hxx:235
SotClipboardFormatId
void SetOutlineLevel(sal_uInt8 nSet)
Definition: content.cxx:4473
void MoveOutline(SwOutlineNodes::size_type nTargetPos)
Definition: content.cxx:3853
bool Update(bool bHard)
Definition: glbltree.cxx:875
sal_Int32 m_nActiveBlock
Definition: conttree.hxx:107
void GotoContent(const SwGlblDocContent *)
Definition: glbltree.cxx:803
SwNavigationPI * m_pDialog
Definition: conttree.hxx:92
MenuEnableFlags
Definition: conttree.hxx:57
void ToggleToRoot()
Switch the display to Root.
Definition: content.cxx:2634
sal_Int32 m_nHiddenBlock
Definition: conttree.hxx:108
void ExecCommand(std::string_view rCmd)
Definition: glbltree.cxx:838
const SwWrtShell * GetActiveWrtShell() const
Definition: conttree.hxx:234
bool IsHiddenView() const
Definition: conttree.hxx:232
void SetActiveShell(SwWrtShell *pSh)
Document change - set new Shell.
Definition: content.cxx:2927
sal_Int8 AcceptDrop(const AcceptDropEvent &rEvt)
Definition: content.cxx:1255
std::unique_ptr< sfx2::DocumentInserter > m_pDocInserter
Definition: conttree.hxx:306
void SetTableTracking(bool bSet)
Definition: content.cxx:4494
void SetRootType(ContentTypeId nType)
Definition: content.cxx:4563
SwNavigationConfig * m_pConfig
Definition: conttree.hxx:103
bool m_bTableTracking
Definition: conttree.hxx:115
SwNavigationPI * GetParentWindow()
Definition: content.cxx:5015
SwNavigationPI * m_pDialog
Definition: conttree.hxx:298
static constexpr auto npos
Definition: ndarr.hxx:78
RENAME
bool get_visible() const
Definition: conttree.hxx:338
SwContentTree & m_rTreeView
Definition: conttree.hxx:77
static void SetShowShell(const SfxObjectShell *pSet)
Definition: conttree.hxx:331
void Select()
Definition: glbltree.cxx:371
void Expand(const weld::TreeIter &rParent, std::vector< std::unique_ptr< weld::TreeIter >> *pNodesToExpand)
Definition: content.cxx:1990
Content type, knows it's contents and the WrtShell.
Definition: content.hxx:171
bool m_bSectionTracking
Definition: conttree.hxx:116
enum SwContentTree::State m_eState
void ExecuteContextMenuAction(std::string_view rSelectedPopupEntry)
Definition: glbltree.cxx:567
bool m_bViewHasChanged
Definition: conttree.hxx:126
size_t m_nEntryCount
Definition: conttree.hxx:109
void clear()
In the clear the content types have to be deleted, also.
Definition: content.cxx:2487
virtual sal_Int8 AcceptDrop(const AcceptDropEvent &rEvt) override
Definition: content.cxx:1235
bool m_bIgnoreViewChange
Definition: conttree.hxx:131
OUString m_sInvisible
Definition: conttree.hxx:99
void InsertRegion(const SwGlblDocContent *_pContent, const css::uno::Sequence< OUString > &_rFiles)
std::unique_ptr< weld::TreeView > m_xTreeView
Definition: conttree.hxx:89
void HideTree()
Definition: glbltree.cxx:832
EditEntryMode
Definition: conttree.hxx:46
bool m_bIsLastReadOnly
Definition: conttree.hxx:124
AutoTimer m_aUpdateTimer
Definition: conttree.hxx:299
void set_accessible_name(const OUString &rName)
Definition: conttree.hxx:340
std::vector< std::unique_ptr< weld::TreeIter > > m_aDndOutlinesSelected
Definition: conttree.hxx:129
bool IsInDrag() const
Definition: content.cxx:1249
SwWrtShell * m_pActiveShell
Definition: conttree.hxx:302
void SetOutlineTracking(sal_uInt8 nSet)
Definition: content.cxx:4488
sal_uInt8 m_nOutlineTracking
Definition: conttree.hxx:114
AutoTimer m_aUpdTimer
Definition: conttree.hxx:94
bool FillTransferData(TransferDataContainer &rTransfer, sal_Int8 &rDragMode)
Definition: content.cxx:2495
virtual void Notify(SfxBroadcaster &rBC, SfxHint const &rHint) override
Definition: content.cxx:2976
unsigned char sal_uInt8
o3tl::enumarray< ContentTypeId, std::unique_ptr< SwContentType > > m_aActiveContentArr
Definition: conttree.hxx:96
SdrObject * GetDrawingObjectsByContent(const SwContent *pCnt)
Definition: content.cxx:1958
SwWrtShell * m_pActiveShell
Definition: conttree.hxx:102
void OpenDoc(const SwGlblDocContent *)
Definition: glbltree.cxx:949
void ShowTree()
Definition: content.cxx:3349
void GotoContent(const SwContent *pCnt)
Definition: content.cxx:4865
void SelectOutlinesWithSelection()
Definition: content.cxx:3799
SwOutlineNodes::size_type m_nLastGotoContentWasOutlinePos
Definition: conttree.hxx:118
size_t GetAbsPos(const weld::TreeIter &rIter)
Definition: content.cxx:2210
void Display(bool bOnlyUpdateUserData=false)
Definition: glbltree.cxx:426
std::unique_ptr< weld::TreeView > m_xTreeView
Definition: conttree.hxx:296
OUString m_sSpace
Definition: conttree.hxx:93
std::map< void *, bool > mOutLineNodeMap
Definition: conttree.hxx:105
bool IsDropFormatSupported(SotClipboardFormatId nFormat) const
void insert(const weld::TreeIter *pParent, const OUString &rStr, const OUString &rId, bool bChildrenOnDemand, weld::TreeIter *pRet)
Definition: content.cxx:1859
ContentTypeId m_nLastSelType
Definition: conttree.hxx:111
virtual sal_Int8 ExecuteDrop(const ExecuteDropEvent &rEvt) override
Definition: glbltree.cxx:166
virtual sal_Int8 ExecuteDrop(const ExecuteDropEvent &rEvt) override
Definition: content.cxx:1282
SwWrtShell * GetWrtShell()
Definition: conttree.hxx:212
void ShowHiddenShell()
Definition: content.cxx:4507
void set_selection_mode(SelectionMode eMode)
Definition: conttree.hxx:265
weld::TreeView & get_widget()
Definition: conttree.hxx:355
void grab_focus()
Definition: conttree.hxx:345
OUString m_aContextStrings[GLOBAL_CONTEXT_COUNT]
Definition: conttree.hxx:300
SwGlobalTree(std::unique_ptr< weld::TreeView > xTreeView, SwNavigationPI *pDialog)
Definition: glbltree.cxx:126
bool m_bIsIdleClear
Definition: conttree.hxx:123
void SetConstantShell(SwWrtShell *pSh)
Set an open view as active.
Definition: content.cxx:2961
void grab_focus()
Definition: conttree.hxx:260
DECL_LINK(DialogClosedHdl, sfx2::FileDialogHelper *, void)
std::unique_ptr< SwGlblDocContent > m_pDocContent
Definition: conttree.hxx:305
void Display(bool bActiveView)
Show the file.
Definition: content.cxx:2258
DECL_LINK(ExpandHdl, const weld::TreeIter &, bool)
Expand - Remember the state for content types.
sal_Int8 ExecuteDrop(const ExecuteDropEvent &rEvt)
Definition: content.cxx:1287
std::vector< SwNode * >::size_type size_type
void UpdateTracking()
Definition: glbltree.cxx:785
#define CONTEXT_COUNT
Definition: swcont.hxx:50
size_t GetEntryCount() const
Definition: content.cxx:2215
bool IsDropFormatSupported(SotClipboardFormatId nFormat)
Definition: conttree.hxx:250
void ShowTree()
Definition: glbltree.cxx:825
bool m_bIsOutlineMoveable
Definition: conttree.hxx:125
o3tl::enumarray< ContentTypeId, std::unique_ptr< SwContentType > > m_aHiddenContentArr
Definition: conttree.hxx:97