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 <ndarr.hxx>
24 #include "swcont.hxx"
25 
26 #include <map>
27 #include <memory>
28 
29 #include <o3tl/enumarray.hxx>
30 #include <o3tl/typed_flags_set.hxx>
31 
32 class SwWrtShell;
33 class SwContentType;
34 class SwNavigationPI;
35 class SwNavigationConfig;
36 class Menu;
37 class ToolBox;
38 class SwGlblDocContents;
39 class SwGlblDocContent;
40 class SfxObjectShell;
41 class SdrObject;
42 
43 enum class EditEntryMode
44 {
45  EDIT = 0,
46  UPD_IDX = 1,
47  RMV_IDX = 2,
48  UNPROTECT_TABLE = 3,
49  DELETE = 4,
50  RENAME = 5,
51 };
52 
53 // Flags for PopupMenu-enable/disable
54 enum class MenuEnableFlags {
55  NONE = 0x0000,
56  InsertIdx = 0x0001,
57  InsertFile = 0x0002,
58  InsertText = 0x0004,
59  Edit = 0x0008,
60  Delete = 0x0010,
61  Update = 0x0020,
62  UpdateSel = 0x0040,
63  EditLink = 0x0080
64 };
65 namespace o3tl {
66  template<> struct typed_flags<MenuEnableFlags> : is_typed_flags<MenuEnableFlags, 0x00ff> {};
67 }
68 
69 class SwContentTree;
70 
72 {
73 private:
75 
76  virtual sal_Int8 AcceptDrop( const AcceptDropEvent& rEvt ) override;
77  virtual sal_Int8 ExecuteDrop( const ExecuteDropEvent& rEvt ) override;
78 
79 public:
81 };
82 
84 class SwContentTree final : public SfxListener
85 {
86  std::unique_ptr<weld::TreeView> m_xTreeView;
89  OUString m_sSpace;
91 
95  OUString m_sInvisible;
96 
97  SwWrtShell* m_pHiddenShell; // dropped Doc
98  SwWrtShell* m_pActiveShell; // the active or a const. open view
100 
101  std::map< void*, bool > mOutLineNodeMap;
102 
103  sal_Int32 m_nActiveBlock;
104  sal_Int32 m_nHiddenBlock;
109 
110  sal_uInt32 m_nOutlineTracking = 1;
111 
112  enum class State { ACTIVE, CONSTANT, HIDDEN } m_eState;
113 
114  bool m_bIsRoot :1;
115  bool m_bIsIdleClear :1;
119 
120  // outline root mode drag & drop
121  std::vector<std::unique_ptr<weld::TreeIter>> m_aDndOutlinesSelected;
122 
123  bool m_bIsInPromoteDemote = false;
124 
130 
131  void insert(const weld::TreeIter* pParent, const OUString& rStr, const OUString& rId,
132  const OUString* pExpanderName, bool bChildrenOnDemand, weld::TreeIter* pRet);
133 
134  void remove(const weld::TreeIter& rIter);
135 
137 
138  bool FillTransferData( TransferDataContainer& rTransfer,
139  sal_Int8& rDragMode );
140 
142  bool HasContentChanged();
143 
144  size_t GetAbsPos(const weld::TreeIter& rIter);
145 
146  void EditEntry(const weld::TreeIter& rEntry, EditEntryMode nMode);
147 
148  void GotoContent(const SwContent* pCnt);
149 
150  void ExecuteContextMenuAction(const OString& rSelectedPopupEntry);
151 
153 
154  size_t GetEntryCount() const;
155 
156  size_t GetChildCount(const weld::TreeIter& rParent) const;
157 
158  std::unique_ptr<weld::TreeIter> GetEntryAtAbsPos(size_t nAbsPos) const;
159 
160  void Expand(const weld::TreeIter& rParent, std::vector<std::unique_ptr<weld::TreeIter>>* pNodesToExpand);
161 
162  void MoveOutline(SwOutlineNodes::size_type nTargetPos);
163 
164  void UpdateLastSelType();
165 
167  DECL_LINK(ExpandHdl, const weld::TreeIter&, bool);
169  DECL_LINK(CollapseHdl, const weld::TreeIter&, bool);
170  DECL_LINK(ContentDoubleClickHdl, weld::TreeView&, bool);
171  DECL_LINK(SelectHdl, weld::TreeView&, void);
172  DECL_LINK(FocusHdl, weld::Widget&, void);
173  DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
174  DECL_LINK(CommandHdl, const CommandEvent&, bool);
175  DECL_LINK(QueryTooltipHdl, const weld::TreeIter&, OUString);
176  DECL_LINK(DragBeginHdl, bool&, bool);
177  DECL_LINK(TimerUpdate, Timer *, void);
178 
179 public:
180  SwContentTree(std::unique_ptr<weld::TreeView> xTreeView, SwNavigationPI* pDialog);
181  ~SwContentTree();
183 
185  void ToggleToRoot();
186  void SetRootType(ContentTypeId nType);
187 
189  void Display( bool bActiveView );
191  void clear();
192 
194  void SetHiddenShell(SwWrtShell* pSh);
195  void ShowHiddenShell();
196  void ShowActualView();
197 
199  void SetActiveShell(SwWrtShell* pSh);
200 
202  void SetConstantShell(SwWrtShell* pSh);
203 
205  { return State::HIDDEN == m_eState ? m_pHiddenShell : m_pActiveShell; }
206 
207  bool IsInDrag() const;
208 
210  void SetOutlineLevel(sal_uInt8 nSet);
211 
213  void ExecCommand(const OString& rCmd, bool bModifier);
214 
215  void ShowTree();
216  void HideTree();
217 
218  bool IsConstantView() const { return State::CONSTANT == m_eState; }
219  bool IsActiveView() const { return State::ACTIVE == m_eState; }
220  bool IsHiddenView() const { return State::HIDDEN == m_eState; }
221 
222  const SwWrtShell* GetActiveWrtShell() const {return m_pActiveShell;}
224 
225  void Select();
226 
227  // return true if it has any children
228  bool RequestingChildren(const weld::TreeIter& rParent);
229 
230  virtual void Notify(SfxBroadcaster& rBC, SfxHint const& rHint) override;
231 
232  sal_Int8 AcceptDrop(const AcceptDropEvent& rEvt);
234 
236  {
237  return m_aDropTargetHelper.IsDropFormatSupported(nFormat);
238  }
239 
240  void set_accessible_name(const OUString& rName)
241  {
242  m_xTreeView->set_accessible_name(rName);
243  }
244 
245  void grab_focus()
246  {
247  m_xTreeView->grab_focus();
248  }
249 
251  {
252  return m_xTreeView->count_selected_rows();
253  }
254 
256  {
257  m_xTreeView->set_selection_mode(eMode);
258  }
259 
261  {
262  return *m_xTreeView;
263  }
264 };
265 
266 namespace sfx2 { class DocumentInserter; }
267 namespace sfx2 { class FileDialogHelper; }
268 
269 class SwGlobalTree;
270 
272 {
273 private:
275 
276  virtual sal_Int8 AcceptDrop( const AcceptDropEvent& rEvt ) override;
277  virtual sal_Int8 ExecuteDrop( const ExecuteDropEvent& rEvt ) override;
278 
279 public:
281 };
282 
283 class SwGlobalTree final
284 {
285 private:
286  std::unique_ptr<weld::TreeView> m_xTreeView;
291 
293  std::unique_ptr<SwGlblDocContents> m_pSwGlblDocContents; // array with sorted content
294 
295  std::unique_ptr<SwGlblDocContent> m_pDocContent;
296  std::unique_ptr<sfx2::DocumentInserter> m_pDocInserter;
297 
298  static const SfxObjectShell* pShowShell;
299 
300  void InsertRegion( const SwGlblDocContent* _pContent,
301  const css::uno::Sequence< OUString >& _rFiles );
302 
303  DECL_LINK( DialogClosedHdl, sfx2::FileDialogHelper*, void );
304 
305  void Select();
306 
307  DECL_LINK(Timeout, Timer*, void);
308  DECL_LINK(DoubleClickHdl, weld::TreeView&, bool);
309  DECL_LINK(SelectHdl, weld::TreeView&, void);
310  DECL_LINK(FocusInHdl, weld::Widget&, void);
311  DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
312  DECL_LINK(CommandHdl, const CommandEvent&, bool);
313  DECL_LINK(QueryTooltipHdl, const weld::TreeIter&, OUString);
314 
316 
317  void OpenDoc(const SwGlblDocContent*);
318  void GotoContent(const SwGlblDocContent*);
320 
321  static void SetShowShell(const SfxObjectShell*pSet) {pShowShell = pSet;}
322  DECL_STATIC_LINK(SwGlobalTree, ShowFrameHdl, void*, void);
323 
324 public:
325  SwGlobalTree(std::unique_ptr<weld::TreeView> xTreeView, SwNavigationPI* pDialog);
326  ~SwGlobalTree();
327 
328  bool get_visible() const { return m_xTreeView->get_visible(); }
329 
330  void set_accessible_name(const OUString& rName)
331  {
332  m_xTreeView->set_accessible_name(rName);
333  }
334 
335  void grab_focus()
336  {
337  m_xTreeView->grab_focus();
338  }
339 
341  {
342  return m_xTreeView->count_selected_rows();
343  }
344 
346  {
347  m_xTreeView->set_selection_mode(eMode);
348  }
349 
351  {
352  return *m_xTreeView;
353  }
354 
355  void MoveSelectionTo(weld::TreeIter* pDropTarget);
356 
357  void TbxMenuHdl(const OString& rCommand, weld::Menu& rMenu);
358  void InsertRegion( const SwGlblDocContent* pCont,
359  const OUString* pFileName = nullptr );
360  void EditContent(const SwGlblDocContent* pCont );
361 
362  void ShowTree();
363  void HideTree();
364 
365  void ExecCommand(const OString& rCmd);
366 
367  void Display(bool bOnlyUpdateUserData = false);
368 
369  bool Update(bool bHard);
370 
371  void ExecuteContextMenuAction(const OString& rSelectedPopupEntry);
372 
373  const SwWrtShell* GetActiveWrtShell() const {return m_pActiveShell;}
374 };
375 
376 #endif
377 
378 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
MenuEnableFlags GetEnableFlags() const
Definition: glbltree.cxx:311
bool RequestingChildren(const weld::TreeIter &rParent)
Definition: content.cxx:1428
void DeleteOutlineSelections()
Definition: content.cxx:3515
ContentTypeId
Definition: swcont.hxx:28
void EditContent(const SwGlblDocContent *pCont)
Definition: glbltree.cxx:529
SwNavigationPI * GetParentWindow()
Definition: glbltree.cxx:964
size_t GetChildCount(const weld::TreeIter &rParent) const
Definition: content.cxx:1779
ContentTypeId m_nRootType
Definition: conttree.hxx:106
SwContentTreeDropTarget(SwContentTree &rTreeView)
Definition: content.cxx:975
int count_selected_rows() const
Definition: conttree.hxx:340
void SetHiddenShell(SwWrtShell *pSh)
After a file is dropped on the Navigator, the new shell will be set.
Definition: content.cxx:2461
OUString m_aContextStrings[CONTEXT_COUNT+1]
Definition: conttree.hxx:94
int count_selected_rows() const
Definition: conttree.hxx:250
signed char sal_Int8
DECL_STATIC_LINK(SwGlobalTree, ShowFrameHdl, void *, void)
void ShowActualView()
Definition: content.cxx:3571
SwWrtShell * m_pHiddenShell
Definition: conttree.hxx:97
void ExecCommand(const OString &rCmd, bool bModifier)
Execute commands of the Navigator.
Definition: content.cxx:2571
void ExecuteContextMenuAction(const OString &rSelectedPopupEntry)
Definition: glbltree.cxx:563
bool HasContentChanged()
Check if the displayed content is valid.
Definition: content.cxx:2225
std::unique_ptr< SwGlblDocContents > m_pSwGlblDocContents
Definition: conttree.hxx:293
void UpdateLastSelType()
Definition: content.cxx:2433
#define GLOBAL_CONTEXT_COUNT
Definition: swcont.hxx:48
void Select()
Definition: content.cxx:3584
static const SfxObjectShell * pShowShell
Definition: conttree.hxx:298
SwContentTree(std::unique_ptr< weld::TreeView > xTreeView, SwNavigationPI *pDialog)
Definition: content.cxx:864
SwContentTreeDropTarget m_aDropTargetHelper
Definition: conttree.hxx:87
SwGlobalTree & m_rTreeView
Definition: conttree.hxx:274
virtual sal_Int8 AcceptDrop(const AcceptDropEvent &rEvt) override
Definition: glbltree.cxx:233
bool IsActiveView() const
Definition: conttree.hxx:219
SelectionMode
VclPtr< SwNavigationPI > m_xDialog
Definition: conttree.hxx:88
sal_uInt8 GetOutlineLevel() const
Definition: conttree.hxx:209
void HideTree()
Definition: content.cxx:2884
weld::TreeView & get_widget()
Definition: conttree.hxx:260
void EditEntry(const weld::TreeIter &rEntry, EditEntryMode nMode)
Definition: content.cxx:3636
void ExecuteContextMenuAction(const OString &rSelectedPopupEntry)
Definition: content.cxx:3349
const SwWrtShell * GetActiveWrtShell() const
Definition: conttree.hxx:373
Used by the UI to modify the document model.
Definition: wrtsh.hxx:90
sal_uInt8 m_nOutlineLevel
Definition: conttree.hxx:108
void FindActiveTypeAndRemoveUserData()
Before any data will be deleted, the last active entry has to be found.
Definition: content.cxx:2449
std::unique_ptr< weld::TreeIter > GetEntryAtAbsPos(size_t nAbsPos) const
Definition: content.cxx:1802
TreeListBox for content indicator.
Definition: conttree.hxx:84
void set_accessible_name(const OUString &rName)
Definition: conttree.hxx:240
SwGlobalTreeDropTarget m_aDropTargetHelper
Definition: conttree.hxx:287
bool IsConstantView() const
Definition: conttree.hxx:218
SwGlobalTreeDropTarget(SwGlobalTree &rTreeView)
Definition: glbltree.cxx:161
void set_selection_mode(SelectionMode eMode)
Definition: conttree.hxx:345
SwWrtShell * GetHiddenWrtShell()
Definition: conttree.hxx:223
SotClipboardFormatId
void SetOutlineLevel(sal_uInt8 nSet)
Definition: content.cxx:3545
void MoveOutline(SwOutlineNodes::size_type nTargetPos)
Definition: content.cxx:3000
bool Update(bool bHard)
Definition: glbltree.cxx:848
sal_Int32 m_nActiveBlock
Definition: conttree.hxx:103
void GotoContent(const SwGlblDocContent *)
Definition: glbltree.cxx:777
MenuEnableFlags
Definition: conttree.hxx:54
void ToggleToRoot()
Switch the display to Root.
Definition: content.cxx:2184
sal_Int32 m_nHiddenBlock
Definition: conttree.hxx:104
const SwWrtShell * GetActiveWrtShell() const
Definition: conttree.hxx:222
bool IsHiddenView() const
Definition: conttree.hxx:220
void SetActiveShell(SwWrtShell *pSh)
Document change - set new Shell.
Definition: content.cxx:2475
sal_Int8 AcceptDrop(const AcceptDropEvent &rEvt)
Definition: content.cxx:1001
std::unique_ptr< sfx2::DocumentInserter > m_pDocInserter
Definition: conttree.hxx:296
void SetRootType(ContentTypeId nType)
Definition: content.cxx:3616
SwNavigationConfig * m_pConfig
Definition: conttree.hxx:99
SwNavigationPI * GetParentWindow()
Definition: content.cxx:4027
RENAME
bool get_visible() const
Definition: conttree.hxx:328
SwContentTree & m_rTreeView
Definition: conttree.hxx:74
static void SetShowShell(const SfxObjectShell *pSet)
Definition: conttree.hxx:321
void Select()
Definition: glbltree.cxx:370
void Expand(const weld::TreeIter &rParent, std::vector< std::unique_ptr< weld::TreeIter >> *pNodesToExpand)
Definition: content.cxx:1552
Content type, knows it's contents and the WrtShell.
Definition: content.hxx:138
enum SwContentTree::State m_eState
bool m_bViewHasChanged
Definition: conttree.hxx:118
void insert(const weld::TreeIter *pParent, const OUString &rStr, const OUString &rId, const OUString *pExpanderName, bool bChildrenOnDemand, weld::TreeIter *pRet)
Definition: content.cxx:1408
size_t m_nEntryCount
Definition: conttree.hxx:105
void clear()
In the clear the content types have to be deleted, also.
Definition: content.cxx:2038
virtual sal_Int8 AcceptDrop(const AcceptDropEvent &rEvt) override
Definition: content.cxx:981
void TbxMenuHdl(const OString &rCommand, weld::Menu &rMenu)
Definition: glbltree.cxx:295
OUString m_sInvisible
Definition: conttree.hxx:95
void InsertRegion(const SwGlblDocContent *_pContent, const css::uno::Sequence< OUString > &_rFiles)
std::unique_ptr< weld::TreeView > m_xTreeView
Definition: conttree.hxx:86
void HideTree()
Definition: glbltree.cxx:805
EditEntryMode
Definition: conttree.hxx:43
bool m_bIsLastReadOnly
Definition: conttree.hxx:116
AutoTimer m_aUpdateTimer
Definition: conttree.hxx:289
void set_accessible_name(const OUString &rName)
Definition: conttree.hxx:330
std::vector< std::unique_ptr< weld::TreeIter > > m_aDndOutlinesSelected
Definition: conttree.hxx:121
bool IsInDrag() const
Definition: content.cxx:995
SwWrtShell * m_pActiveShell
Definition: conttree.hxx:292
AutoTimer m_aUpdTimer
Definition: conttree.hxx:90
VclPtr< SwNavigationPI > m_xDialog
Definition: conttree.hxx:288
bool FillTransferData(TransferDataContainer &rTransfer, sal_Int8 &rDragMode)
Definition: content.cxx:2046
sal_uInt32 m_nOutlineTracking
Definition: conttree.hxx:110
virtual void Notify(SfxBroadcaster &rBC, SfxHint const &rHint) override
Definition: content.cxx:2524
unsigned char sal_uInt8
o3tl::enumarray< ContentTypeId, std::unique_ptr< SwContentType > > m_aActiveContentArr
Definition: conttree.hxx:92
void ExecCommand(const OString &rCmd)
Definition: glbltree.cxx:811
SdrObject * GetDrawingObjectsByContent(const SwContent *pCnt)
Definition: content.cxx:1520
SwWrtShell * m_pActiveShell
Definition: conttree.hxx:98
void OpenDoc(const SwGlblDocContent *)
Definition: glbltree.cxx:919
void ShowTree()
Definition: content.cxx:2878
void GotoContent(const SwContent *pCnt)
Definition: content.cxx:3870
size_t GetAbsPos(const weld::TreeIter &rIter)
Definition: content.cxx:1769
void MoveSelectionTo(weld::TreeIter *pDropTarget)
Definition: glbltree.cxx:388
void Display(bool bOnlyUpdateUserData=false)
Definition: glbltree.cxx:425
std::unique_ptr< weld::TreeView > m_xTreeView
Definition: conttree.hxx:286
OUString m_sSpace
Definition: conttree.hxx:89
std::map< void *, bool > mOutLineNodeMap
Definition: conttree.hxx:101
bool IsDropFormatSupported(SotClipboardFormatId nFormat) const
ContentTypeId m_nLastSelType
Definition: conttree.hxx:107
virtual sal_Int8 ExecuteDrop(const ExecuteDropEvent &rEvt) override
Definition: glbltree.cxx:167
virtual sal_Int8 ExecuteDrop(const ExecuteDropEvent &rEvt) override
Definition: content.cxx:1028
SwWrtShell * GetWrtShell()
Definition: conttree.hxx:204
void ShowHiddenShell()
Definition: content.cxx:3561
void set_selection_mode(SelectionMode eMode)
Definition: conttree.hxx:255
weld::TreeView & get_widget()
Definition: conttree.hxx:350
void grab_focus()
Definition: conttree.hxx:335
OUString m_aContextStrings[GLOBAL_CONTEXT_COUNT]
Definition: conttree.hxx:290
SwGlobalTree(std::unique_ptr< weld::TreeView > xTreeView, SwNavigationPI *pDialog)
Definition: glbltree.cxx:127
bool m_bIsIdleClear
Definition: conttree.hxx:115
void SetConstantShell(SwWrtShell *pSh)
Set an open view as active.
Definition: content.cxx:2509
bool m_bIsInPromoteDemote
Definition: conttree.hxx:123
void grab_focus()
Definition: conttree.hxx:245
DECL_LINK(DialogClosedHdl, sfx2::FileDialogHelper *, void)
std::unique_ptr< SwGlblDocContent > m_pDocContent
Definition: conttree.hxx:295
void Display(bool bActiveView)
Show the file.
Definition: content.cxx:1817
DECL_LINK(ExpandHdl, const weld::TreeIter &, bool)
Expand - Remember the state for content types.
sal_Int8 ExecuteDrop(const ExecuteDropEvent &rEvt)
Definition: content.cxx:1033
std::vector< SwNode * >::size_type size_type
#define CONTEXT_COUNT
Definition: swcont.hxx:47
size_t GetEntryCount() const
Definition: content.cxx:1774
bool IsDropFormatSupported(SotClipboardFormatId nFormat)
Definition: conttree.hxx:235
void ShowTree()
Definition: glbltree.cxx:799
bool m_bIsOutlineMoveable
Definition: conttree.hxx:117
o3tl::enumarray< ContentTypeId, std::unique_ptr< SwContentType > > m_aHiddenContentArr
Definition: conttree.hxx:93