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
116 
118 
119  enum class State { ACTIVE, CONSTANT, HIDDEN } m_eState;
120 
121  bool m_bIsRoot :1;
122  bool m_bIsIdleClear :1;
126 
127  // outline root mode drag & drop
128  std::vector<std::unique_ptr<weld::TreeIter>> m_aDndOutlinesSelected;
129 
130  bool m_bDocHasChanged = true;
131  bool m_bIgnoreDocChange = false; // used to prevent tracking update
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  void CopyOutlineSelections();
162 
163  size_t GetEntryCount() const;
164 
165  size_t GetChildCount(const weld::TreeIter& rParent) const;
166 
167  std::unique_ptr<weld::TreeIter> GetEntryAtAbsPos(size_t nAbsPos) const;
168 
169  void Expand(const weld::TreeIter& rParent, std::vector<std::unique_ptr<weld::TreeIter>>* pNodesToExpand);
170 
171  void MoveOutline(SwOutlineNodes::size_type nTargetPos);
172 
173  void UpdateLastSelType();
174 
176  DECL_LINK(ExpandHdl, const weld::TreeIter&, bool);
178  DECL_LINK(CollapseHdl, const weld::TreeIter&, bool);
179  DECL_LINK(ContentDoubleClickHdl, weld::TreeView&, bool);
180  DECL_LINK(SelectHdl, weld::TreeView&, void);
181  DECL_LINK(FocusInHdl, weld::Widget&, void);
182  DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
183  DECL_LINK(CommandHdl, const CommandEvent&, bool);
184  DECL_LINK(QueryTooltipHdl, const weld::TreeIter&, OUString);
185  DECL_LINK(DragBeginHdl, bool&, bool);
186  DECL_LINK(TimerUpdate, Timer *, void);
187 
188 public:
189  SwContentTree(std::unique_ptr<weld::TreeView> xTreeView, SwNavigationPI* pDialog);
190  ~SwContentTree();
192 
194  void ToggleToRoot();
195  void SetRootType(ContentTypeId nType);
196 
198  void Display( bool bActiveView );
200  void clear();
201 
203  void SetHiddenShell(SwWrtShell* pSh);
204  void ShowHiddenShell();
205  void ShowActualView();
206 
208  void SetActiveShell(SwWrtShell* pSh);
209 
211  void SetConstantShell(SwWrtShell* pSh);
212 
214  { return State::HIDDEN == m_eState ? m_pHiddenShell : m_pActiveShell; }
215 
216  bool IsInDrag() const;
217 
219  void SetOutlineLevel(sal_uInt8 nSet);
220 
221  void SetOutlineTracking(sal_uInt8 nSet);
222  void SetContentTypeTracking(ContentTypeId eCntTypeId, 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  void SelectContentType(std::u16string_view rContentTypeName);
242 
243  // return true if it has any children
244  bool RequestingChildren(const weld::TreeIter& rParent);
245 
246  virtual void Notify(SfxBroadcaster& rBC, SfxHint const& rHint) override;
247 
248  sal_Int8 AcceptDrop(const AcceptDropEvent& rEvt);
250 
252  {
253  return m_aDropTargetHelper.IsDropFormatSupported(nFormat);
254  }
255 
256  void set_accessible_name(const OUString& rName)
257  {
258  m_xTreeView->set_accessible_name(rName);
259  }
260 
261  void grab_focus()
262  {
263  m_xTreeView->grab_focus();
264  }
265 
267  {
268  m_xTreeView->set_selection_mode(eMode);
269  }
270 
272  {
273  return *m_xTreeView;
274  }
275 };
276 
277 namespace sfx2 { class DocumentInserter; }
278 namespace sfx2 { class FileDialogHelper; }
279 
280 class SwGlobalTree;
281 
283 {
284 private:
286 
287  virtual sal_Int8 AcceptDrop( const AcceptDropEvent& rEvt ) override;
288  virtual sal_Int8 ExecuteDrop( const ExecuteDropEvent& rEvt ) override;
289 
290 public:
292 };
293 
294 class SwGlobalTree final : public SfxListener
295 {
296 private:
297  std::unique_ptr<weld::TreeView> m_xTreeView;
302 
304  std::unique_ptr<SwGlblDocContents> m_pSwGlblDocContents; // array with sorted content
305 
306  std::unique_ptr<SwGlblDocContent> m_pDocContent;
307  std::unique_ptr<sfx2::DocumentInserter> m_pDocInserter;
308 
310 
311  void InsertRegion( const SwGlblDocContent* _pContent,
312  const css::uno::Sequence< OUString >& _rFiles );
313 
314  DECL_LINK( DialogClosedHdl, sfx2::FileDialogHelper*, void );
315 
316  void Select();
317 
318  DECL_LINK(Timeout, Timer*, void);
319  DECL_LINK(DoubleClickHdl, weld::TreeView&, bool);
320  DECL_LINK(SelectHdl, weld::TreeView&, void);
321  DECL_LINK(FocusInHdl, weld::Widget&, void);
322  DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
323  DECL_LINK(CommandHdl, const CommandEvent&, bool);
324  DECL_LINK(QueryTooltipHdl, const weld::TreeIter&, OUString);
325 
327 
328  void OpenDoc(const SwGlblDocContent*);
329  void GotoContent(const SwGlblDocContent*);
331 
332  static void SetShowShell(const SfxObjectShell*pSet) {s_pShowShell = pSet;}
333  DECL_STATIC_LINK(SwGlobalTree, ShowFrameHdl, void*, void);
334 
335 public:
336  SwGlobalTree(std::unique_ptr<weld::TreeView> xTreeView, SwNavigationPI* pDialog);
337  ~SwGlobalTree();
338 
339  bool get_visible() const { return m_xTreeView->get_visible(); }
340 
341  void set_accessible_name(const OUString& rName)
342  {
343  m_xTreeView->set_accessible_name(rName);
344  }
345 
346  void grab_focus()
347  {
348  m_xTreeView->grab_focus();
349  }
350 
352  {
353  m_xTreeView->set_selection_mode(eMode);
354  }
355 
357  {
358  return *m_xTreeView;
359  }
360 
361  void MoveSelectionTo(const weld::TreeIter* pDropTarget);
362 
363  void TbxMenuHdl(std::string_view rCommand, weld::Menu& rMenu);
364  void InsertRegion( const SwGlblDocContent* pCont,
365  const OUString* pFileName = nullptr );
366  void EditContent(const SwGlblDocContent* pCont );
367 
368  void ShowTree();
369  void HideTree();
370 
371  void ExecCommand(std::string_view rCmd);
372 
373  void Display(bool bOnlyUpdateUserData = false);
374 
375  bool Update(bool bHard);
376 
377  void ExecuteContextMenuAction(std::string_view rSelectedPopupEntry);
378 
379  const SwWrtShell* GetActiveWrtShell() const {return m_pActiveShell;}
380 
381  virtual void Notify(SfxBroadcaster& rBC, SfxHint const& rHint) override;
382  void UpdateTracking();
383 };
384 
385 #endif
386 
387 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
MenuEnableFlags GetEnableFlags() const
Definition: glbltree.cxx:312
bool RequestingChildren(const weld::TreeIter &rParent)
Definition: content.cxx:1942
void DeleteOutlineSelections()
Definition: content.cxx:4629
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:993
size_t GetChildCount(const weld::TreeIter &rParent) const
Definition: content.cxx:2291
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:1159
void SetHiddenShell(SwWrtShell *pSh)
After a file is dropped on the Navigator, the new shell will be set.
Definition: content.cxx:2944
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:4707
SwWrtShell * m_pHiddenShell
Definition: conttree.hxx:101
bool HasContentChanged()
Check if the displayed content is valid.
Definition: content.cxx:2714
std::unique_ptr< SwGlblDocContents > m_pSwGlblDocContents
Definition: conttree.hxx:304
void UpdateLastSelType()
Definition: content.cxx:2916
#define GLOBAL_CONTEXT_COUNT
Definition: swcont.hxx:52
void Select()
Definition: content.cxx:4734
SwContentTree(std::unique_ptr< weld::TreeView > xTreeView, SwNavigationPI *pDialog)
Definition: content.cxx:1045
SwContentTreeDropTarget m_aDropTargetHelper
Definition: conttree.hxx:91
void ExecCommand(std::string_view rCmd, bool bModifier)
Execute commands of the Navigator.
Definition: content.cxx:3081
SwGlobalTree & m_rTreeView
Definition: conttree.hxx:285
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:1119
void SetContentTypeTracking(ContentTypeId eCntTypeId, bool bSet)
Definition: content.cxx:4690
sal_uInt8 GetOutlineLevel() const
Definition: conttree.hxx:218
void HideTree()
Definition: content.cxx:3396
void UpdateTracking()
Definition: content.cxx:3612
weld::TreeView & get_widget()
Definition: conttree.hxx:271
void EditEntry(const weld::TreeIter &rEntry, EditEntryMode nMode)
Definition: content.cxx:4787
void ExecuteContextMenuAction(const OString &rSelectedPopupEntry)
Definition: content.cxx:4353
const SwWrtShell * GetActiveWrtShell() const
Definition: conttree.hxx:379
Used by the UI to modify the document model.
Definition: wrtsh.hxx:96
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:2932
void CopyOutlineSelections()
Definition: content.cxx:5072
std::unique_ptr< weld::TreeIter > GetEntryAtAbsPos(size_t nAbsPos) const
Definition: content.cxx:2314
TreeListBox for content indicator.
Definition: conttree.hxx:87
void set_accessible_name(const OUString &rName)
Definition: conttree.hxx:256
SwGlobalTreeDropTarget m_aDropTargetHelper
Definition: conttree.hxx:298
bool IsConstantView() const
Definition: conttree.hxx:230
SwGlobalTreeDropTarget(SwGlobalTree &rTreeView)
Definition: glbltree.cxx:160
void set_selection_mode(SelectionMode eMode)
Definition: conttree.hxx:351
SwWrtShell * GetHiddenWrtShell()
Definition: conttree.hxx:235
SotClipboardFormatId
void SetOutlineLevel(sal_uInt8 nSet)
Definition: content.cxx:4667
void MoveOutline(SwOutlineNodes::size_type nTargetPos)
Definition: content.cxx:3986
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:2662
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:2958
sal_Int8 AcceptDrop(const AcceptDropEvent &rEvt)
Definition: content.cxx:1185
std::unique_ptr< sfx2::DocumentInserter > m_pDocInserter
Definition: conttree.hxx:307
void SetRootType(ContentTypeId nType)
Definition: content.cxx:4767
SwNavigationConfig * m_pConfig
Definition: conttree.hxx:103
SwNavigationPI * GetParentWindow()
Definition: content.cxx:5251
SwNavigationPI * m_pDialog
Definition: conttree.hxx:299
static constexpr auto npos
Definition: ndarr.hxx:80
RENAME
bool get_visible() const
Definition: conttree.hxx:339
SwContentTree & m_rTreeView
Definition: conttree.hxx:77
static void SetShowShell(const SfxObjectShell *pSet)
Definition: conttree.hxx:332
void Select()
Definition: glbltree.cxx:371
void Expand(const weld::TreeIter &rParent, std::vector< std::unique_ptr< weld::TreeIter >> *pNodesToExpand)
Definition: content.cxx:2055
Content type, knows it's contents and the WrtShell.
Definition: content.hxx:171
enum SwContentTree::State m_eState
void ExecuteContextMenuAction(std::string_view rSelectedPopupEntry)
Definition: glbltree.cxx:567
bool m_bViewHasChanged
Definition: conttree.hxx:125
size_t m_nEntryCount
Definition: conttree.hxx:109
void clear()
In the clear the content types have to be deleted, also.
Definition: content.cxx:2515
virtual sal_Int8 AcceptDrop(const AcceptDropEvent &rEvt) override
Definition: content.cxx:1165
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:123
AutoTimer m_aUpdateTimer
Definition: conttree.hxx:300
void set_accessible_name(const OUString &rName)
Definition: conttree.hxx:341
std::vector< std::unique_ptr< weld::TreeIter > > m_aDndOutlinesSelected
Definition: conttree.hxx:128
bool IsInDrag() const
Definition: content.cxx:1179
SwWrtShell * m_pActiveShell
Definition: conttree.hxx:303
void SetOutlineTracking(sal_uInt8 nSet)
Definition: content.cxx:4684
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:2523
virtual void Notify(SfxBroadcaster &rBC, SfxHint const &rHint) override
Definition: content.cxx:3017
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:2023
SwWrtShell * m_pActiveShell
Definition: conttree.hxx:102
void OpenDoc(const SwGlblDocContent *)
Definition: glbltree.cxx:948
void ShowTree()
Definition: content.cxx:3390
void GotoContent(const SwContent *pCnt)
Definition: content.cxx:5098
void SelectOutlinesWithSelection()
Definition: content.cxx:3932
SwOutlineNodes::size_type m_nLastGotoContentWasOutlinePos
Definition: conttree.hxx:117
size_t GetAbsPos(const weld::TreeIter &rIter)
Definition: content.cxx:2281
static const SfxObjectShell * s_pShowShell
Definition: conttree.hxx:309
void Display(bool bOnlyUpdateUserData=false)
Definition: glbltree.cxx:426
std::unique_ptr< weld::TreeView > m_xTreeView
Definition: conttree.hxx:297
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:1922
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:1212
SwWrtShell * GetWrtShell()
Definition: conttree.hxx:213
void ShowHiddenShell()
Definition: content.cxx:4697
void SelectContentType(std::u16string_view rContentTypeName)
Definition: content.cxx:5256
void set_selection_mode(SelectionMode eMode)
Definition: conttree.hxx:266
weld::TreeView & get_widget()
Definition: conttree.hxx:356
void grab_focus()
Definition: conttree.hxx:346
OUString m_aContextStrings[GLOBAL_CONTEXT_COUNT]
Definition: conttree.hxx:301
SwGlobalTree(std::unique_ptr< weld::TreeView > xTreeView, SwNavigationPI *pDialog)
Definition: glbltree.cxx:126
bool m_bIsIdleClear
Definition: conttree.hxx:122
void SetConstantShell(SwWrtShell *pSh)
Set an open view as active.
Definition: content.cxx:3002
void grab_focus()
Definition: conttree.hxx:261
DECL_LINK(DialogClosedHdl, sfx2::FileDialogHelper *, void)
std::unique_ptr< SwGlblDocContent > m_pDocContent
Definition: conttree.hxx:306
void Display(bool bActiveView)
Show the file.
Definition: content.cxx:2329
DECL_LINK(ExpandHdl, const weld::TreeIter &, bool)
Expand - Remember the state for content types.
sal_Int8 ExecuteDrop(const ExecuteDropEvent &rEvt)
Definition: content.cxx:1217
std::vector< SwNode * >::size_type size_type
bool m_bIgnoreDocChange
Definition: conttree.hxx:131
void UpdateTracking()
Definition: glbltree.cxx:785
#define CONTEXT_COUNT
Definition: swcont.hxx:51
size_t GetEntryCount() const
Definition: content.cxx:2286
bool IsDropFormatSupported(SotClipboardFormatId nFormat)
Definition: conttree.hxx:251
bool m_bDocHasChanged
Definition: conttree.hxx:130
void ShowTree()
Definition: glbltree.cxx:825
o3tl::enumarray< ContentTypeId, bool > mTrackContentType
Definition: conttree.hxx:115
bool m_bIsOutlineMoveable
Definition: conttree.hxx:124
o3tl::enumarray< ContentTypeId, std::unique_ptr< SwContentType > > m_aHiddenContentArr
Definition: conttree.hxx:97