1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_SW_SOURCE_UIBASE_INC_CONTTREE_HXX
20 #define INCLUDED_SW_SOURCE_UIBASE_INC_CONTTREE_HXX
22 #include <svl/lstner.hxx>
23 #include <vcl/timer.hxx>
24 #include <vcl/transfer.hxx>
25 #include <vcl/weld.hxx>
32 #include <o3tl/enumarray.hxx>
33 #include <o3tl/typed_flags_set.hxx>
35 #include <svx/sdr/overlay/overlayobject.hxx>
37 #include <edglbldc.hxx>
42 class SwNavigationConfig
;
45 class SwGlblDocContents
;
49 enum class EditEntryMode
59 // Flags for PopupMenu-enable/disable
60 enum class MenuEnableFlags
{
72 template<> struct typed_flags
<MenuEnableFlags
> : is_typed_flags
<MenuEnableFlags
, 0x00ff> {};
77 class SwContentTreeDropTarget final
: public DropTargetHelper
80 SwContentTree
& m_rTreeView
;
82 virtual sal_Int8
AcceptDrop( const AcceptDropEvent
& rEvt
) override
;
83 virtual sal_Int8
ExecuteDrop( const ExecuteDropEvent
& rEvt
) override
;
86 SwContentTreeDropTarget(SwContentTree
& rTreeView
);
89 /** TreeListBox for content indicator */
90 class SwContentTree final
: public SfxListener
92 std::unique_ptr
<weld::TreeView
> m_xTreeView
;
93 SwContentTreeDropTarget m_aDropTargetHelper
;
94 SwNavigationPI
* m_pDialog
;
96 AutoTimer m_aUpdTimer
;
97 AutoTimer m_aOverlayObjectDelayTimer
;
99 o3tl::enumarray
<ContentTypeId
,std::unique_ptr
<SwContentType
>> m_aActiveContentArr
;
100 o3tl::enumarray
<ContentTypeId
,std::unique_ptr
<SwContentType
>> m_aHiddenContentArr
;
101 OUString m_aContextStrings
[CONTEXT_COUNT
+ 1];
102 OUString m_sInvisible
;
103 OUString m_sSelectedItem
; // last selected item (only bookmarks yet)
105 SwWrtShell
* m_pHiddenShell
; // dropped Doc
106 SwWrtShell
* m_pActiveShell
; // the active or a const. open view
107 SwNavigationConfig
* m_pConfig
;
109 std::map
< void*, bool > mOutLineNodeMap
;
111 sal_Int32 m_nActiveBlock
; // used to restore content types/categories expand state
112 sal_Int32 m_nHiddenBlock
;
113 size_t m_nEntryCount
;
114 ContentTypeId m_nRootType
;
115 ContentTypeId m_nLastSelType
;
116 sal_uInt8 m_nOutlineLevel
;
118 sal_uInt8 m_nOutlineTracking
= 1; // 1 default, 2 focus, 3 off
119 o3tl::enumarray
<ContentTypeId
, bool> mTrackContentType
;
121 SwOutlineNodes::size_type m_nLastGotoContentWasOutlinePos
= SwOutlineNodes::npos
;
123 enum class State
{ ACTIVE
, CONSTANT
, HIDDEN
} m_eState
;
126 bool m_bIsIdleClear
:1;
127 bool m_bIsLastReadOnly
:1;
128 bool m_bIsOutlineMoveable
:1;
129 bool m_bViewHasChanged
:1;
131 // outline root mode drag & drop
132 std::vector
<std::unique_ptr
<weld::TreeIter
>> m_aDndOutlinesSelected
;
134 bool m_bDocHasChanged
= true;
135 bool m_bIgnoreDocChange
= false; // used to prevent tracking update
137 ImplSVEvent
* m_nRowActivateEventId
= nullptr;
138 bool m_bSelectTo
= false;
140 std::unique_ptr
<weld::TreeIter
> m_xOverlayCompareEntry
;
141 std::unique_ptr
<sdr::overlay::OverlayObject
> m_xOverlayObject
;
143 void OverlayObject(std::vector
<basegfx::B2DRange
>&& aRanges
= {});
145 void BringEntryToAttention(const weld::TreeIter
& rEntry
);
146 void BringFramesToAttention(const std::vector
<const SwFrameFormat
*>& rFrameFormats
);
147 void BringBookmarksToAttention(const std::vector
<OUString
>& rNames
);
148 void BringURLFieldsToAttention(const SwGetINetAttrs
& rINetAttrsArr
);
149 void BringReferencesToAttention(std::vector
<const SwTextAttr
*>& rTextAttrsArr
);
150 void BringPostItFieldsToAttention(std::vector
<const SwTextAttr
*>& rTextAttrsArr
);
151 void BringDrawingObjectsToAttention(std::vector
<const SdrObject
*>& rDrawingObjectsArr
);
152 void BringTextFieldsToAttention(std::vector
<const SwTextAttr
*>& rTextAttrsArr
);
153 void BringFootnotesToAttention(std::vector
<const SwTextAttr
*>& rTextAttrsArr
);
154 void BringTypesWithFlowFramesToAttention(const std::vector
<const SwNode
*>& rNodes
);
157 * Before any data will be deleted, the last active entry has to be found.
158 * After this the UserData will be deleted
160 void FindActiveTypeAndRemoveUserData();
162 void InsertContent(const weld::TreeIter
& rParent
);
164 void insert(const weld::TreeIter
* pParent
, const OUString
& rStr
, const OUString
& rId
,
165 bool bChildrenOnDemand
, weld::TreeIter
* pRet
);
167 void remove(const weld::TreeIter
& rIter
);
169 SwNavigationPI
* GetParentWindow();
171 bool FillTransferData( TransferDataContainer
& rTransfer
,
172 sal_Int8
& rDragMode
);
174 /** Check if the displayed content is valid. */
175 bool HasContentChanged();
177 size_t GetAbsPos(const weld::TreeIter
& rIter
);
179 void EditEntry(const weld::TreeIter
& rEntry
, EditEntryMode nMode
);
181 void GotoContent(const SwContent
* pCnt
);
183 void ExecuteContextMenuAction(const OUString
& rSelectedPopupEntry
);
185 void DeleteOutlineSelections();
186 void CopyOutlineSelections();
188 size_t GetEntryCount() const;
190 size_t GetChildCount(const weld::TreeIter
& rParent
) const;
192 std::unique_ptr
<weld::TreeIter
> GetEntryAtAbsPos(size_t nAbsPos
) const;
194 void Expand(const weld::TreeIter
& rParent
, std::vector
<std::unique_ptr
<weld::TreeIter
>>* pNodesToExpand
);
196 void MoveOutline(SwOutlineNodes::size_type nTargetPos
);
198 void UpdateLastSelType();
200 /** Expand - Remember the state for content types */
201 DECL_LINK(ExpandHdl
, const weld::TreeIter
&, bool);
202 /** Collapse - Remember the state for content types. */
203 DECL_LINK(CollapseHdl
, const weld::TreeIter
&, bool);
204 DECL_LINK(ContentDoubleClickHdl
, weld::TreeView
&, bool);
205 DECL_LINK(AsyncContentDoubleClickHdl
, void*, void);
206 DECL_LINK(SelectHdl
, weld::TreeView
&, void);
207 DECL_LINK(FocusInHdl
, weld::Widget
&, void);
208 DECL_LINK(KeyInputHdl
, const KeyEvent
&, bool);
209 DECL_LINK(CommandHdl
, const CommandEvent
&, bool);
210 DECL_LINK(QueryTooltipHdl
, const weld::TreeIter
&, OUString
);
211 DECL_LINK(DragBeginHdl
, bool&, bool);
212 DECL_LINK(TimerUpdate
, Timer
*, void);
213 DECL_LINK(OverlayObjectDelayTimerHdl
, Timer
*, void);
214 DECL_LINK(MouseMoveHdl
, const MouseEvent
&, bool);
215 DECL_LINK(MousePressHdl
, const MouseEvent
&, bool);
218 SwContentTree(std::unique_ptr
<weld::TreeView
> xTreeView
, SwNavigationPI
* pDialog
);
220 SdrObject
* GetDrawingObjectsByContent(const SwContent
*pCnt
);
222 /** Switch the display to Root */
224 void SetRootType(ContentTypeId nType
);
227 void Display( bool bActiveView
);
228 /** In the clear the content types have to be deleted, also. */
231 /** After a file is dropped on the Navigator, the new shell will be set */
232 void SetHiddenShell(SwWrtShell
* pSh
);
233 void ShowHiddenShell();
234 void ShowActualView();
236 /** Document change - set new Shell */
237 void SetActiveShell(SwWrtShell
* pSh
);
239 /** Set an open view as active. */
240 void SetConstantShell(SwWrtShell
* pSh
);
242 SwWrtShell
* GetWrtShell()
243 { return State::HIDDEN
== m_eState
? m_pHiddenShell
: m_pActiveShell
; }
245 bool IsInDrag() const;
247 sal_uInt8
GetOutlineLevel()const {return m_nOutlineLevel
;}
248 void SetOutlineLevel(sal_uInt8 nSet
);
250 void SetOutlineTracking(sal_uInt8 nSet
);
251 void SetContentTypeTracking(ContentTypeId eCntTypeId
, bool bSet
);
253 /** Execute commands of the Navigator */
254 void ExecCommand(std::u16string_view rCmd
, bool bModifier
);
259 bool IsConstantView() const { return State::CONSTANT
== m_eState
; }
260 bool IsActiveView() const { return State::ACTIVE
== m_eState
; }
261 bool IsHiddenView() const { return State::HIDDEN
== m_eState
; }
263 const SwWrtShell
* GetActiveWrtShell() const {return m_pActiveShell
;}
264 SwWrtShell
* GetHiddenWrtShell() {return m_pHiddenShell
;}
268 void UpdateTracking();
269 void SelectOutlinesWithSelection();
270 void SelectContentType(std::u16string_view rContentTypeName
);
272 // return true if it has any children
273 bool RequestingChildren(const weld::TreeIter
& rParent
);
275 virtual void Notify(SfxBroadcaster
& rBC
, SfxHint
const& rHint
) override
;
277 sal_Int8
AcceptDrop(const AcceptDropEvent
& rEvt
);
278 sal_Int8
ExecuteDrop(const ExecuteDropEvent
& rEvt
);
280 bool IsDropFormatSupported(SotClipboardFormatId nFormat
)
282 return m_aDropTargetHelper
.IsDropFormatSupported(nFormat
);
285 void set_accessible_name(const OUString
& rName
)
287 m_xTreeView
->set_accessible_name(rName
);
292 m_xTreeView
->grab_focus();
295 void set_selection_mode(SelectionMode eMode
)
297 m_xTreeView
->set_selection_mode(eMode
);
300 weld::TreeView
& get_widget()
306 namespace sfx2
{ class DocumentInserter
; }
307 namespace sfx2
{ class FileDialogHelper
; }
311 class SwGlobalTreeDropTarget final
: public DropTargetHelper
314 SwGlobalTree
& m_rTreeView
;
316 virtual sal_Int8
AcceptDrop( const AcceptDropEvent
& rEvt
) override
;
317 virtual sal_Int8
ExecuteDrop( const ExecuteDropEvent
& rEvt
) override
;
320 SwGlobalTreeDropTarget(SwGlobalTree
& rTreeView
);
323 class SwGlobalTree final
: public SfxListener
326 std::unique_ptr
<weld::TreeView
> m_xTreeView
;
327 SwGlobalTreeDropTarget m_aDropTargetHelper
;
328 SwNavigationPI
* m_pDialog
;
329 AutoTimer m_aUpdateTimer
;
330 OUString m_aContextStrings
[GLOBAL_CONTEXT_COUNT
];
332 SwWrtShell
* m_pActiveShell
;
333 std::unique_ptr
<SwGlblDocContents
> m_pSwGlblDocContents
; // array with sorted content
335 std::optional
<SwGlblDocContent
> m_oDocContent
;
336 std::unique_ptr
<sfx2::DocumentInserter
> m_pDocInserter
;
338 static const SfxObjectShell
* s_pShowShell
;
340 void InsertRegion( const SwGlblDocContent
* _pContent
,
341 const css::uno::Sequence
< OUString
>& _rFiles
);
343 DECL_LINK( DialogClosedHdl
, sfx2::FileDialogHelper
*, void );
347 DECL_LINK(Timeout
, Timer
*, void);
348 DECL_LINK(DoubleClickHdl
, weld::TreeView
&, bool);
349 DECL_LINK(SelectHdl
, weld::TreeView
&, void);
350 DECL_LINK(FocusInHdl
, weld::Widget
&, void);
351 DECL_LINK(KeyInputHdl
, const KeyEvent
&, bool);
352 DECL_LINK(CommandHdl
, const CommandEvent
&, bool);
353 DECL_LINK(QueryTooltipHdl
, const weld::TreeIter
&, OUString
);
355 SwNavigationPI
* GetParentWindow();
357 void OpenDoc(const SwGlblDocContent
*);
358 void GotoContent(const SwGlblDocContent
*);
359 MenuEnableFlags
GetEnableFlags() const;
361 static void SetShowShell(const SfxObjectShell
*pSet
) {s_pShowShell
= pSet
;}
362 DECL_STATIC_LINK(SwGlobalTree
, ShowFrameHdl
, void*, void);
365 SwGlobalTree(std::unique_ptr
<weld::TreeView
> xTreeView
, SwNavigationPI
* pDialog
);
368 bool get_visible() const { return m_xTreeView
->get_visible(); }
370 void set_accessible_name(const OUString
& rName
)
372 m_xTreeView
->set_accessible_name(rName
);
377 m_xTreeView
->grab_focus();
380 void set_selection_mode(SelectionMode eMode
)
382 m_xTreeView
->set_selection_mode(eMode
);
385 weld::TreeView
& get_widget()
390 void MoveSelectionTo(const weld::TreeIter
* pDropTarget
);
392 void TbxMenuHdl(std::u16string_view rCommand
, weld::Menu
& rMenu
);
393 void InsertRegion( const SwGlblDocContent
* pCont
,
394 const OUString
* pFileName
= nullptr );
395 void EditContent(const SwGlblDocContent
* pCont
);
400 void ExecCommand(std::u16string_view rCmd
);
402 void Display(bool bOnlyUpdateUserData
= false);
404 bool Update(bool bHard
);
406 void ExecuteContextMenuAction(std::u16string_view rSelectedPopupEntry
);
408 const SwWrtShell
* GetActiveWrtShell() const {return m_pActiveShell
;}
410 virtual void Notify(SfxBroadcaster
& rBC
, SfxHint
const& rHint
) override
;
411 void UpdateTracking();
416 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */