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;
87  std::unique_ptr<weld::TreeIter> m_xScratchIter;
90  OUString m_sSpace;
92 
96  OUString m_sInvisible;
97 
98  SwWrtShell* m_pHiddenShell; // dropped Doc
99  SwWrtShell* m_pActiveShell; // the active or a const. open view
101 
102  std::map< void*, bool > mOutLineNodeMap;
103 
104  sal_Int32 m_nActiveBlock;
105  sal_Int32 m_nHiddenBlock;
110 
111  sal_uInt32 m_nOutlineTracking = 1;
112 
113  enum class State { ACTIVE, CONSTANT, HIDDEN } m_eState;
114 
115  bool m_bIsRoot :1;
116  bool m_bIsIdleClear :1;
120 
121  // outline root mode drag & drop
122  std::vector<std::unique_ptr<weld::TreeIter>> m_aDndOutlinesSelected;
123 
124  bool m_bIgnoreViewChange = false;
125 
131 
132  void insert(const weld::TreeIter* pParent, const OUString& rStr, const OUString& rId,
133  bool bChildrenOnDemand, weld::TreeIter* pRet);
134 
135  void remove(const weld::TreeIter& rIter);
136 
138 
139  bool FillTransferData( TransferDataContainer& rTransfer,
140  sal_Int8& rDragMode );
141 
143  bool HasContentChanged();
144 
145  size_t GetAbsPos(const weld::TreeIter& rIter);
146 
147  void EditEntry(const weld::TreeIter& rEntry, EditEntryMode nMode);
148 
149  void GotoContent(const SwContent* pCnt);
150 
151  void ExecuteContextMenuAction(const OString& rSelectedPopupEntry);
152 
154 
155  size_t GetEntryCount() const;
156 
157  size_t GetChildCount(const weld::TreeIter& rParent) const;
158 
159  std::unique_ptr<weld::TreeIter> GetEntryAtAbsPos(size_t nAbsPos) const;
160 
161  void Expand(const weld::TreeIter& rParent, std::vector<std::unique_ptr<weld::TreeIter>>* pNodesToExpand);
162 
163  void MoveOutline(SwOutlineNodes::size_type nTargetPos);
164 
165  void UpdateLastSelType();
166 
168  DECL_LINK(ExpandHdl, const weld::TreeIter&, bool);
170  DECL_LINK(CollapseHdl, const weld::TreeIter&, bool);
171  DECL_LINK(ContentDoubleClickHdl, weld::TreeView&, bool);
172  DECL_LINK(SelectHdl, weld::TreeView&, void);
173  DECL_LINK(FocusHdl, weld::Widget&, void);
174  DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
175  DECL_LINK(CommandHdl, const CommandEvent&, bool);
176  DECL_LINK(QueryTooltipHdl, const weld::TreeIter&, OUString);
177  DECL_LINK(DragBeginHdl, bool&, bool);
178  DECL_LINK(TimerUpdate, Timer *, void);
179 
180 public:
181  SwContentTree(std::unique_ptr<weld::TreeView> xTreeView, SwNavigationPI* pDialog);
182  ~SwContentTree();
184 
186  void ToggleToRoot();
187  void SetRootType(ContentTypeId nType);
188 
190  void Display( bool bActiveView );
192  void clear();
193 
195  void SetHiddenShell(SwWrtShell* pSh);
196  void ShowHiddenShell();
197  void ShowActualView();
198 
200  void SetActiveShell(SwWrtShell* pSh);
201 
203  void SetConstantShell(SwWrtShell* pSh);
204 
206  { return State::HIDDEN == m_eState ? m_pHiddenShell : m_pActiveShell; }
207 
208  bool IsInDrag() const;
209 
211  void SetOutlineLevel(sal_uInt8 nSet);
212 
214  void ExecCommand(const OString& rCmd, bool bModifier);
215 
216  void ShowTree();
217  void HideTree();
218 
219  bool IsConstantView() const { return State::CONSTANT == m_eState; }
220  bool IsActiveView() const { return State::ACTIVE == m_eState; }
221  bool IsHiddenView() const { return State::HIDDEN == m_eState; }
222 
223  const SwWrtShell* GetActiveWrtShell() const {return m_pActiveShell;}
225 
226  void Select();
227 
228  void UpdateTracking();
230 
231  // return true if it has any children
232  bool RequestingChildren(const weld::TreeIter& rParent);
233 
234  virtual void Notify(SfxBroadcaster& rBC, SfxHint const& rHint) override;
235 
236  sal_Int8 AcceptDrop(const AcceptDropEvent& rEvt);
238 
240  {
241  return m_aDropTargetHelper.IsDropFormatSupported(nFormat);
242  }
243 
244  void set_accessible_name(const OUString& rName)
245  {
246  m_xTreeView->set_accessible_name(rName);
247  }
248 
249  void grab_focus()
250  {
251  m_xTreeView->grab_focus();
252  FocusHdl(*m_xTreeView);
253  }
254 
255  OUString get_selected_text() const
256  {
257  return m_xTreeView->get_selected_text();
258  }
259 
261  {
262  return m_xTreeView->count_selected_rows();
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
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  FocusInHdl(*m_xTreeView);
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(const OString& 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(const OString& rCmd);
372 
373  void Display(bool bOnlyUpdateUserData = false);
374 
375  bool Update(bool bHard);
376 
377  void ExecuteContextMenuAction(const OString& rSelectedPopupEntry);
378 
379  const SwWrtShell* GetActiveWrtShell() const {return m_pActiveShell;}
380 };
381 
382 #endif
383 
384 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
MenuEnableFlags GetEnableFlags() const
Definition: glbltree.cxx:313
bool RequestingChildren(const weld::TreeIter &rParent)
Definition: content.cxx:1608
void DeleteOutlineSelections()
Definition: content.cxx:3914
ContentTypeId
Definition: swcont.hxx:28
void EditContent(const SwGlblDocContent *pCont)
Definition: glbltree.cxx:531
SwNavigationPI * GetParentWindow()
Definition: glbltree.cxx:966
size_t GetChildCount(const weld::TreeIter &rParent) const
Definition: content.cxx:1956
ContentTypeId m_nRootType
Definition: conttree.hxx:107
std::unique_ptr< weld::TreeIter > m_xScratchIter
Definition: conttree.hxx:87
void MoveSelectionTo(const weld::TreeIter *pDropTarget)
Definition: glbltree.cxx:390
SwContentTreeDropTarget(SwContentTree &rTreeView)
Definition: content.cxx:1002
void SetHiddenShell(SwWrtShell *pSh)
After a file is dropped on the Navigator, the new shell will be set.
Definition: content.cxx:2647
OUString m_aContextStrings[CONTEXT_COUNT+1]
Definition: conttree.hxx:95
int count_selected_rows() const
Definition: conttree.hxx:260
signed char sal_Int8
DECL_STATIC_LINK(SwGlobalTree, ShowFrameHdl, void *, void)
void ShowActualView()
Definition: content.cxx:3970
SwWrtShell * m_pHiddenShell
Definition: conttree.hxx:98
void ExecCommand(const OString &rCmd, bool bModifier)
Execute commands of the Navigator.
Definition: content.cxx:2774
void ExecuteContextMenuAction(const OString &rSelectedPopupEntry)
Definition: glbltree.cxx:565
bool HasContentChanged()
Check if the displayed content is valid.
Definition: content.cxx:2410
std::unique_ptr< SwGlblDocContents > m_pSwGlblDocContents
Definition: conttree.hxx:303
void UpdateLastSelType()
Definition: content.cxx:2619
#define GLOBAL_CONTEXT_COUNT
Definition: swcont.hxx:48
void Select()
Definition: content.cxx:3983
static const SfxObjectShell * pShowShell
Definition: conttree.hxx:308
SwContentTree(std::unique_ptr< weld::TreeView > xTreeView, SwNavigationPI *pDialog)
Definition: content.cxx:890
SwContentTreeDropTarget m_aDropTargetHelper
Definition: conttree.hxx:88
SwGlobalTree & m_rTreeView
Definition: conttree.hxx:284
virtual sal_Int8 AcceptDrop(const AcceptDropEvent &rEvt) override
Definition: glbltree.cxx:233
bool IsActiveView() const
Definition: conttree.hxx:220
SelectionMode
VclPtr< SwNavigationPI > m_xDialog
Definition: conttree.hxx:89
sal_uInt8 GetOutlineLevel() const
Definition: conttree.hxx:210
void HideTree()
Definition: content.cxx:3087
void UpdateTracking()
Definition: content.cxx:3174
weld::TreeView & get_widget()
Definition: conttree.hxx:270
void EditEntry(const weld::TreeIter &rEntry, EditEntryMode nMode)
Definition: content.cxx:4035
void ExecuteContextMenuAction(const OString &rSelectedPopupEntry)
Definition: content.cxx:3709
const SwWrtShell * GetActiveWrtShell() const
Definition: conttree.hxx:379
Used by the UI to modify the document model.
Definition: wrtsh.hxx:90
sal_uInt8 m_nOutlineLevel
Definition: conttree.hxx:109
void FindActiveTypeAndRemoveUserData()
Before any data will be deleted, the last active entry has to be found.
Definition: content.cxx:2635
std::unique_ptr< weld::TreeIter > GetEntryAtAbsPos(size_t nAbsPos) const
Definition: content.cxx:1979
TreeListBox for content indicator.
Definition: conttree.hxx:84
void set_accessible_name(const OUString &rName)
Definition: conttree.hxx:244
SwGlobalTreeDropTarget m_aDropTargetHelper
Definition: conttree.hxx:297
bool IsConstantView() const
Definition: conttree.hxx:219
SwGlobalTreeDropTarget(SwGlobalTree &rTreeView)
Definition: glbltree.cxx:161
void set_selection_mode(SelectionMode eMode)
Definition: conttree.hxx:351
SwWrtShell * GetHiddenWrtShell()
Definition: conttree.hxx:224
SotClipboardFormatId
void SetOutlineLevel(sal_uInt8 nSet)
Definition: content.cxx:3944
void MoveOutline(SwOutlineNodes::size_type nTargetPos)
Definition: content.cxx:3360
bool Update(bool bHard)
Definition: glbltree.cxx:850
sal_Int32 m_nActiveBlock
Definition: conttree.hxx:104
void GotoContent(const SwGlblDocContent *)
Definition: glbltree.cxx:779
MenuEnableFlags
Definition: conttree.hxx:54
void ToggleToRoot()
Switch the display to Root.
Definition: content.cxx:2369
sal_Int32 m_nHiddenBlock
Definition: conttree.hxx:105
const SwWrtShell * GetActiveWrtShell() const
Definition: conttree.hxx:223
bool IsHiddenView() const
Definition: conttree.hxx:221
void SetActiveShell(SwWrtShell *pSh)
Document change - set new Shell.
Definition: content.cxx:2661
sal_Int8 AcceptDrop(const AcceptDropEvent &rEvt)
Definition: content.cxx:1028
std::unique_ptr< sfx2::DocumentInserter > m_pDocInserter
Definition: conttree.hxx:306
void SetRootType(ContentTypeId nType)
Definition: content.cxx:4015
SwNavigationConfig * m_pConfig
Definition: conttree.hxx:100
SwNavigationPI * GetParentWindow()
Definition: content.cxx:4429
RENAME
bool get_visible() const
Definition: conttree.hxx:338
SwContentTree & m_rTreeView
Definition: conttree.hxx:74
static void SetShowShell(const SfxObjectShell *pSet)
Definition: conttree.hxx:331
void Select()
Definition: glbltree.cxx:372
void Expand(const weld::TreeIter &rParent, std::vector< std::unique_ptr< weld::TreeIter >> *pNodesToExpand)
Definition: content.cxx:1732
Content type, knows it's contents and the WrtShell.
Definition: content.hxx:138
enum SwContentTree::State m_eState
bool m_bViewHasChanged
Definition: conttree.hxx:119
size_t m_nEntryCount
Definition: conttree.hxx:106
void clear()
In the clear the content types have to be deleted, also.
Definition: content.cxx:2223
virtual sal_Int8 AcceptDrop(const AcceptDropEvent &rEvt) override
Definition: content.cxx:1008
bool m_bIgnoreViewChange
Definition: conttree.hxx:124
void TbxMenuHdl(const OString &rCommand, weld::Menu &rMenu)
Definition: glbltree.cxx:297
OUString m_sInvisible
Definition: conttree.hxx:96
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:807
EditEntryMode
Definition: conttree.hxx:43
OUString get_selected_text() const
Definition: conttree.hxx:255
bool m_bIsLastReadOnly
Definition: conttree.hxx:117
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:122
bool IsInDrag() const
Definition: content.cxx:1022
SwWrtShell * m_pActiveShell
Definition: conttree.hxx:302
AutoTimer m_aUpdTimer
Definition: conttree.hxx:91
VclPtr< SwNavigationPI > m_xDialog
Definition: conttree.hxx:298
bool FillTransferData(TransferDataContainer &rTransfer, sal_Int8 &rDragMode)
Definition: content.cxx:2231
sal_uInt32 m_nOutlineTracking
Definition: conttree.hxx:111
virtual void Notify(SfxBroadcaster &rBC, SfxHint const &rHint) override
Definition: content.cxx:2710
unsigned char sal_uInt8
o3tl::enumarray< ContentTypeId, std::unique_ptr< SwContentType > > m_aActiveContentArr
Definition: conttree.hxx:93
void ExecCommand(const OString &rCmd)
Definition: glbltree.cxx:813
SdrObject * GetDrawingObjectsByContent(const SwContent *pCnt)
Definition: content.cxx:1700
SwWrtShell * m_pActiveShell
Definition: conttree.hxx:99
void OpenDoc(const SwGlblDocContent *)
Definition: glbltree.cxx:921
void ShowTree()
Definition: content.cxx:3081
void GotoContent(const SwContent *pCnt)
Definition: content.cxx:4272
void SelectOutlinesWithSelection()
Definition: content.cxx:3306
size_t GetAbsPos(const weld::TreeIter &rIter)
Definition: content.cxx:1946
void Display(bool bOnlyUpdateUserData=false)
Definition: glbltree.cxx:427
std::unique_ptr< weld::TreeView > m_xTreeView
Definition: conttree.hxx:296
OUString m_sSpace
Definition: conttree.hxx:90
std::map< void *, bool > mOutLineNodeMap
Definition: conttree.hxx:102
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:1588
ContentTypeId m_nLastSelType
Definition: conttree.hxx:108
virtual sal_Int8 ExecuteDrop(const ExecuteDropEvent &rEvt) override
Definition: glbltree.cxx:167
virtual sal_Int8 ExecuteDrop(const ExecuteDropEvent &rEvt) override
Definition: content.cxx:1055
SwWrtShell * GetWrtShell()
Definition: conttree.hxx:205
void ShowHiddenShell()
Definition: content.cxx:3960
void set_selection_mode(SelectionMode eMode)
Definition: conttree.hxx:265
weld::TreeView & get_widget()
Definition: conttree.hxx:356
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:127
bool m_bIsIdleClear
Definition: conttree.hxx:116
void SetConstantShell(SwWrtShell *pSh)
Set an open view as active.
Definition: content.cxx:2695
void grab_focus()
Definition: conttree.hxx:249
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:1994
DECL_LINK(ExpandHdl, const weld::TreeIter &, bool)
Expand - Remember the state for content types.
sal_Int8 ExecuteDrop(const ExecuteDropEvent &rEvt)
Definition: content.cxx:1060
std::vector< SwNode * >::size_type size_type
#define CONTEXT_COUNT
Definition: swcont.hxx:47
size_t GetEntryCount() const
Definition: content.cxx:1951
bool IsDropFormatSupported(SotClipboardFormatId nFormat)
Definition: conttree.hxx:239
void ShowTree()
Definition: glbltree.cxx:801
bool m_bIsOutlineMoveable
Definition: conttree.hxx:118
o3tl::enumarray< ContentTypeId, std::unique_ptr< SwContentType > > m_aHiddenContentArr
Definition: conttree.hxx:94