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
58 // Flags for PopupMenu-enable/disable
59 enum class MenuEnableFlags
{
71 template<> struct typed_flags
<MenuEnableFlags
> : is_typed_flags
<MenuEnableFlags
, 0x00ff> {};
76 class SwContentTreeDropTarget final
: public DropTargetHelper
79 SwContentTree
& m_rTreeView
;
81 virtual sal_Int8
AcceptDrop( const AcceptDropEvent
& rEvt
) override
;
82 virtual sal_Int8
ExecuteDrop( const ExecuteDropEvent
& rEvt
) override
;
85 SwContentTreeDropTarget(SwContentTree
& rTreeView
);
88 /** TreeListBox for content indicator */
89 class SwContentTree final
: public SfxListener
91 friend class SwNavigationPI
;
93 std::unique_ptr
<weld::TreeView
> m_xTreeView
;
94 SwContentTreeDropTarget m_aDropTargetHelper
;
95 SwNavigationPI
* m_pDialog
;
97 AutoTimer m_aUpdTimer
;
98 AutoTimer m_aOverlayObjectDelayTimer
;
100 o3tl::enumarray
<ContentTypeId
,std::unique_ptr
<SwContentType
>> m_aActiveContentArr
;
101 o3tl::enumarray
<ContentTypeId
,std::unique_ptr
<SwContentType
>> m_aHiddenContentArr
;
102 OUString m_aContextStrings
[CONTEXT_COUNT
+ 1];
103 OUString m_sInvisible
;
104 OUString m_sSelectedItem
; // last selected item (only bookmarks yet)
106 SwWrtShell
* m_pHiddenShell
; // dropped Doc
107 SwWrtShell
* m_pActiveShell
; // the active or a const. open view
108 SwNavigationConfig
* m_pConfig
;
110 // these maps store the expand state of nodes with children
111 std::map
< void*, bool > mOutLineNodeMap
;
112 std::map
<const void*, bool> m_aRegionNodeExpandMap
;
113 std::map
<const void*, bool> m_aPostItNodeExpandMap
;
115 sal_Int32 m_nActiveBlock
; // used to restore content types expand state
116 sal_Int32 m_nHiddenBlock
;
117 size_t m_nEntryCount
;
118 ContentTypeId m_nRootType
; // content type that is currently displayed in the tree
119 ContentTypeId m_nLastSelType
;
120 sal_uInt8 m_nOutlineLevel
;
122 sal_uInt8 m_nOutlineTracking
= 1; // 1 default, 2 focus, 3 off
123 o3tl::enumarray
<ContentTypeId
, bool> mTrackContentType
;
125 SwOutlineNodes::size_type m_nLastGotoContentWasOutlinePos
= SwOutlineNodes::npos
;
127 enum class State
{ ACTIVE
, CONSTANT
, HIDDEN
} m_eState
;
130 bool m_bIsIdleClear
:1;
131 bool m_bIsLastReadOnly
:1;
132 bool m_bIsOutlineMoveable
:1;
133 bool m_bViewHasChanged
:1;
135 // outline root mode drag & drop
136 std::vector
<SwOutlineNodes::size_type
> m_aDndOutlinesSelected
;
138 bool m_bDocHasChanged
= true;
139 bool m_bIgnoreDocChange
= false; // used to prevent tracking update
141 ImplSVEvent
* m_nRowActivateEventId
= nullptr;
142 bool m_bSelectTo
= false;
144 std::unique_ptr
<weld::TreeIter
> m_xOverlayCompareEntry
;
145 std::unique_ptr
<sdr::overlay::OverlayObject
> m_xOverlayObject
;
147 void OverlayObject(std::vector
<basegfx::B2DRange
>&& aRanges
= {});
149 void BringEntryToAttention(const weld::TreeIter
& rEntry
);
150 void BringFramesToAttention(const std::vector
<const SwFrameFormat
*>& rFrameFormats
);
151 void BringBookmarksToAttention(const std::vector
<OUString
>& rNames
);
152 void BringURLFieldsToAttention(const SwGetINetAttrs
& rINetAttrsArr
);
153 void BringReferencesToAttention(std::vector
<const SwTextAttr
*>& rTextAttrsArr
);
154 void BringPostItFieldsToAttention(std::vector
<const SwTextAttr
*>& rTextAttrsArr
);
155 void BringDrawingObjectsToAttention(std::vector
<const SdrObject
*>& rDrawingObjectsArr
);
156 void BringTextFieldsToAttention(std::vector
<const SwTextAttr
*>& rTextAttrsArr
);
157 void BringFootnotesToAttention(std::vector
<const SwTextAttr
*>& rTextAttrsArr
);
158 void BringTypesWithFlowFramesToAttention(const std::vector
<const SwNode
*>& rNodes
,
159 const bool bIncludeTopMargin
= true);
162 * Before any data will be deleted, the last active entry has to be found.
163 * After this the UserData will be deleted
165 void FindActiveTypeAndRemoveUserData();
167 void InsertContent(const weld::TreeIter
& rParent
);
169 void insert(const weld::TreeIter
* pParent
, const OUString
& rStr
, const OUString
& rId
,
170 bool bChildrenOnDemand
, weld::TreeIter
* pRet
);
172 void remove(const weld::TreeIter
& rIter
);
174 SwNavigationPI
* GetParentWindow();
176 bool FillTransferData(TransferDataContainer
& rTransfer
);
178 /** Check if the displayed content is valid. */
179 bool HasContentChanged();
181 size_t GetAbsPos(const weld::TreeIter
& rIter
);
183 void EditEntry(const weld::TreeIter
& rEntry
, EditEntryMode nMode
);
185 void GotoContent(const SwContent
* pCnt
);
187 void ExecuteContextMenuAction(const OUString
& rSelectedPopupEntry
);
189 void DeleteOutlineSelections();
190 void CopyOutlineSelections();
192 size_t GetEntryCount() const;
194 size_t GetChildCount(const weld::TreeIter
& rParent
) const;
196 std::unique_ptr
<weld::TreeIter
> GetEntryAtAbsPos(size_t nAbsPos
) const;
198 void Expand(const weld::TreeIter
& rParent
, std::vector
<std::unique_ptr
<weld::TreeIter
>>* pNodesToExpand
);
200 void MoveOutline(SwOutlineNodes::size_type nTargetPos
);
202 void UpdateLastSelType();
204 bool IsDeletable(const weld::TreeIter
& rEntry
);
205 bool IsDeletable(const SwContent
* pContent
);
206 void DeleteAllContentOfEntryContentType(const weld::TreeIter
& rEntry
);
208 bool IsSelectedEntryCurrentDocCursorPosition(const weld::TreeIter
& rEntry
);
210 /** Expand - Remember the state for content types */
211 DECL_LINK(ExpandHdl
, const weld::TreeIter
&, bool);
212 /** Collapse - Remember the state for content types. */
213 DECL_LINK(CollapseHdl
, const weld::TreeIter
&, bool);
214 DECL_LINK(ContentDoubleClickHdl
, weld::TreeView
&, bool);
215 DECL_LINK(AsyncContentDoubleClickHdl
, void*, void);
216 DECL_LINK(SelectHdl
, weld::TreeView
&, void);
217 DECL_LINK(FocusInHdl
, weld::Widget
&, void);
218 DECL_LINK(KeyInputHdl
, const KeyEvent
&, bool);
219 DECL_LINK(CommandHdl
, const CommandEvent
&, bool);
220 DECL_LINK(QueryTooltipHdl
, const weld::TreeIter
&, OUString
);
221 DECL_LINK(DragBeginHdl
, bool&, bool);
222 DECL_LINK(TimerUpdate
, Timer
*, void);
223 DECL_LINK(OverlayObjectDelayTimerHdl
, Timer
*, void);
224 DECL_LINK(MouseMoveHdl
, const MouseEvent
&, bool);
225 DECL_LINK(MousePressHdl
, const MouseEvent
&, bool);
228 SwContentTree(std::unique_ptr
<weld::TreeView
> xTreeView
, SwNavigationPI
* pDialog
);
230 SdrObject
* GetDrawingObjectsByContent(const SwContent
*pCnt
);
232 /** Switch the display to Root */
234 void SetRootType(ContentTypeId nType
);
237 void Display( bool bActiveView
);
238 /** In the clear the content types have to be deleted, also. */
241 /** After a file is dropped on the Navigator, the new shell will be set */
242 void SetHiddenShell(SwWrtShell
* pSh
);
243 void ShowHiddenShell();
244 void ShowActualView();
246 /** Document change - set new Shell */
247 void SetActiveShell(SwWrtShell
* pSh
);
249 /** Set an open view as active. */
250 void SetConstantShell(SwWrtShell
* pSh
);
252 SwWrtShell
* GetWrtShell()
253 { return State::HIDDEN
== m_eState
? m_pHiddenShell
: m_pActiveShell
; }
255 bool IsInDrag() const;
256 bool HasHeadings() const;
258 sal_uInt8
GetOutlineLevel()const {return m_nOutlineLevel
;}
259 void SetOutlineLevel(sal_uInt8 nSet
);
261 void SetOutlineTracking(sal_uInt8 nSet
);
262 void SetContentTypeTracking(ContentTypeId eCntTypeId
, bool bSet
);
264 /** Execute commands of the Navigator */
265 void ExecCommand(std::u16string_view rCmd
, bool bModifier
);
270 bool IsConstantView() const { return State::CONSTANT
== m_eState
; }
271 bool IsActiveView() const { return State::ACTIVE
== m_eState
; }
272 bool IsHiddenView() const { return State::HIDDEN
== m_eState
; }
274 const SwWrtShell
* GetActiveWrtShell() const {return m_pActiveShell
;}
275 SwWrtShell
* GetHiddenWrtShell() {return m_pHiddenShell
;}
277 void UpdateContentFunctionsToolbar();
279 void UpdateTracking();
280 void SelectOutlinesWithSelection();
281 void SelectContentType(std::u16string_view rContentTypeName
);
283 // return true if it has any children
284 bool RequestingChildren(const weld::TreeIter
& rParent
);
286 void ExpandAllHeadings();
288 virtual void Notify(SfxBroadcaster
& rBC
, SfxHint
const& rHint
) override
;
290 sal_Int8
AcceptDrop(const AcceptDropEvent
& rEvt
);
291 sal_Int8
ExecuteDrop(const ExecuteDropEvent
& rEvt
);
293 bool IsDropFormatSupported(SotClipboardFormatId nFormat
)
295 return m_aDropTargetHelper
.IsDropFormatSupported(nFormat
);
298 void set_accessible_name(const OUString
& rName
)
300 m_xTreeView
->set_accessible_name(rName
);
305 m_xTreeView
->grab_focus();
308 void set_selection_mode(SelectionMode eMode
)
310 m_xTreeView
->set_selection_mode(eMode
);
313 weld::TreeView
& get_widget()
319 namespace sfx2
{ class DocumentInserter
; }
320 namespace sfx2
{ class FileDialogHelper
; }
324 class SwGlobalTreeDropTarget final
: public DropTargetHelper
327 SwGlobalTree
& m_rTreeView
;
329 virtual sal_Int8
AcceptDrop( const AcceptDropEvent
& rEvt
) override
;
330 virtual sal_Int8
ExecuteDrop( const ExecuteDropEvent
& rEvt
) override
;
333 SwGlobalTreeDropTarget(SwGlobalTree
& rTreeView
);
336 class SwGlobalTree final
: public SfxListener
339 std::unique_ptr
<weld::TreeView
> m_xTreeView
;
340 SwGlobalTreeDropTarget m_aDropTargetHelper
;
341 SwNavigationPI
* m_pDialog
;
342 AutoTimer m_aUpdateTimer
;
343 OUString m_aContextStrings
[GLOBAL_CONTEXT_COUNT
];
345 SwWrtShell
* m_pActiveShell
;
346 std::unique_ptr
<SwGlblDocContents
> m_pSwGlblDocContents
; // array with sorted content
348 std::optional
<SwGlblDocContent
> m_oDocContent
;
349 std::unique_ptr
<sfx2::DocumentInserter
> m_pDocInserter
;
351 static const SfxObjectShell
* s_pShowShell
;
353 void InsertRegion( const SwGlblDocContent
* _pContent
,
354 const css::uno::Sequence
< OUString
>& _rFiles
);
356 DECL_LINK( DialogClosedHdl
, sfx2::FileDialogHelper
*, void );
360 DECL_LINK(Timeout
, Timer
*, void);
361 DECL_LINK(DoubleClickHdl
, weld::TreeView
&, bool);
362 DECL_LINK(SelectHdl
, weld::TreeView
&, void);
363 DECL_LINK(FocusInHdl
, weld::Widget
&, void);
364 DECL_LINK(KeyInputHdl
, const KeyEvent
&, bool);
365 DECL_LINK(CommandHdl
, const CommandEvent
&, bool);
366 DECL_LINK(QueryTooltipHdl
, const weld::TreeIter
&, OUString
);
368 SwNavigationPI
* GetParentWindow();
370 void OpenDoc(const SwGlblDocContent
*);
371 void GotoContent(const SwGlblDocContent
*);
372 MenuEnableFlags
GetEnableFlags() const;
374 static void SetShowShell(const SfxObjectShell
*pSet
) {s_pShowShell
= pSet
;}
375 DECL_STATIC_LINK(SwGlobalTree
, ShowFrameHdl
, void*, void);
378 SwGlobalTree(std::unique_ptr
<weld::TreeView
> xTreeView
, SwNavigationPI
* pDialog
);
381 bool get_visible() const { return m_xTreeView
->get_visible(); }
383 void set_accessible_name(const OUString
& rName
)
385 m_xTreeView
->set_accessible_name(rName
);
390 m_xTreeView
->grab_focus();
393 void set_selection_mode(SelectionMode eMode
)
395 m_xTreeView
->set_selection_mode(eMode
);
398 weld::TreeView
& get_widget()
403 void MoveSelectionTo(const weld::TreeIter
* pDropTarget
);
405 void TbxMenuHdl(std::u16string_view rCommand
, weld::Menu
& rMenu
);
406 void InsertRegion( const SwGlblDocContent
* pCont
,
407 const OUString
* pFileName
= nullptr );
408 void EditContent(const SwGlblDocContent
* pCont
);
413 void ExecCommand(std::u16string_view rCmd
);
415 void Display(bool bOnlyUpdateUserData
= false);
417 bool Update(bool bHard
);
419 void ExecuteContextMenuAction(std::u16string_view rSelectedPopupEntry
);
421 const SwWrtShell
* GetActiveWrtShell() const {return m_pActiveShell
;}
423 virtual void Notify(SfxBroadcaster
& rBC
, SfxHint
const& rHint
) override
;
424 void UpdateTracking();
429 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */