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>
29 #include <o3tl/enumarray.hxx>
30 #include <o3tl/typed_flags_set.hxx>
35 class SwNavigationConfig
;
38 class SwGlblDocContents
;
39 class SwGlblDocContent
;
43 enum class EditEntryMode
53 // Flags for PopupMenu-enable/disable
54 enum class MenuEnableFlags
{
66 template<> struct typed_flags
<MenuEnableFlags
> : is_typed_flags
<MenuEnableFlags
, 0x00ff> {};
71 class SwContentTreeDropTarget
: public DropTargetHelper
74 SwContentTree
& m_rTreeView
;
76 virtual sal_Int8
AcceptDrop( const AcceptDropEvent
& rEvt
) override
;
77 virtual sal_Int8
ExecuteDrop( const ExecuteDropEvent
& rEvt
) override
;
80 SwContentTreeDropTarget(SwContentTree
& rTreeView
);
83 /** TreeListBox for content indicator */
84 class SwContentTree final
: public SfxListener
86 std::unique_ptr
<weld::TreeView
> m_xTreeView
;
87 std::unique_ptr
<weld::TreeIter
> m_xScratchIter
;
88 SwContentTreeDropTarget m_aDropTargetHelper
;
89 VclPtr
<SwNavigationPI
> m_xDialog
;
91 AutoTimer m_aUpdTimer
;
93 o3tl::enumarray
<ContentTypeId
,std::unique_ptr
<SwContentType
>> m_aActiveContentArr
;
94 o3tl::enumarray
<ContentTypeId
,std::unique_ptr
<SwContentType
>> m_aHiddenContentArr
;
95 OUString m_aContextStrings
[CONTEXT_COUNT
+ 1];
96 OUString m_sInvisible
;
98 SwWrtShell
* m_pHiddenShell
; // dropped Doc
99 SwWrtShell
* m_pActiveShell
; // the active or a const. open view
100 SwNavigationConfig
* m_pConfig
;
102 std::map
< void*, bool > mOutLineNodeMap
;
104 sal_Int32 m_nActiveBlock
;
105 sal_Int32 m_nHiddenBlock
;
106 size_t m_nEntryCount
;
107 ContentTypeId m_nRootType
;
108 ContentTypeId m_nLastSelType
;
109 sal_uInt8 m_nOutlineLevel
;
111 sal_uInt32 m_nOutlineTracking
= 1;
113 enum class State
{ ACTIVE
, CONSTANT
, HIDDEN
} m_eState
;
116 bool m_bIsIdleClear
:1;
117 bool m_bIsLastReadOnly
:1;
118 bool m_bIsOutlineMoveable
:1;
119 bool m_bViewHasChanged
:1;
121 // outline root mode drag & drop
122 std::vector
<std::unique_ptr
<weld::TreeIter
>> m_aDndOutlinesSelected
;
124 bool m_bIgnoreViewChange
= false;
127 * Before any data will be deleted, the last active entry has to be found.
128 * After this the UserData will be deleted
130 void FindActiveTypeAndRemoveUserData();
132 void insert(const weld::TreeIter
* pParent
, const OUString
& rStr
, const OUString
& rId
,
133 bool bChildrenOnDemand
, weld::TreeIter
* pRet
);
135 void remove(const weld::TreeIter
& rIter
);
137 SwNavigationPI
* GetParentWindow();
139 bool FillTransferData( TransferDataContainer
& rTransfer
,
140 sal_Int8
& rDragMode
);
142 /** Check if the displayed content is valid. */
143 bool HasContentChanged();
145 size_t GetAbsPos(const weld::TreeIter
& rIter
);
147 void EditEntry(const weld::TreeIter
& rEntry
, EditEntryMode nMode
);
149 void GotoContent(const SwContent
* pCnt
);
151 void ExecuteContextMenuAction(const OString
& rSelectedPopupEntry
);
153 void DeleteOutlineSelections();
155 size_t GetEntryCount() const;
157 size_t GetChildCount(const weld::TreeIter
& rParent
) const;
159 std::unique_ptr
<weld::TreeIter
> GetEntryAtAbsPos(size_t nAbsPos
) const;
161 void Expand(const weld::TreeIter
& rParent
, std::vector
<std::unique_ptr
<weld::TreeIter
>>* pNodesToExpand
);
163 void MoveOutline(SwOutlineNodes::size_type nTargetPos
);
165 void UpdateLastSelType();
167 /** Expand - Remember the state for content types */
168 DECL_LINK(ExpandHdl
, const weld::TreeIter
&, bool);
169 /** Collapse - Remember the state for content types. */
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);
181 SwContentTree(std::unique_ptr
<weld::TreeView
> xTreeView
, SwNavigationPI
* pDialog
);
183 SdrObject
* GetDrawingObjectsByContent(const SwContent
*pCnt
);
185 /** Switch the display to Root */
187 void SetRootType(ContentTypeId nType
);
190 void Display( bool bActiveView
);
191 /** In the clear the content types have to be deleted, also. */
194 /** After a file is dropped on the Navigator, the new shell will be set */
195 void SetHiddenShell(SwWrtShell
* pSh
);
196 void ShowHiddenShell();
197 void ShowActualView();
199 /** Document change - set new Shell */
200 void SetActiveShell(SwWrtShell
* pSh
);
202 /** Set an open view as active. */
203 void SetConstantShell(SwWrtShell
* pSh
);
205 SwWrtShell
* GetWrtShell()
206 { return State::HIDDEN
== m_eState
? m_pHiddenShell
: m_pActiveShell
; }
208 bool IsInDrag() const;
210 sal_uInt8
GetOutlineLevel()const {return m_nOutlineLevel
;}
211 void SetOutlineLevel(sal_uInt8 nSet
);
213 /** Execute commands of the Navigator */
214 void ExecCommand(const OString
& rCmd
, bool bModifier
);
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
; }
223 const SwWrtShell
* GetActiveWrtShell() const {return m_pActiveShell
;}
224 SwWrtShell
* GetHiddenWrtShell() {return m_pHiddenShell
;}
228 void UpdateTracking();
229 void SelectOutlinesWithSelection();
231 // return true if it has any children
232 bool RequestingChildren(const weld::TreeIter
& rParent
);
234 virtual void Notify(SfxBroadcaster
& rBC
, SfxHint
const& rHint
) override
;
236 sal_Int8
AcceptDrop(const AcceptDropEvent
& rEvt
);
237 sal_Int8
ExecuteDrop(const ExecuteDropEvent
& rEvt
);
239 bool IsDropFormatSupported(SotClipboardFormatId nFormat
)
241 return m_aDropTargetHelper
.IsDropFormatSupported(nFormat
);
244 void set_accessible_name(const OUString
& rName
)
246 m_xTreeView
->set_accessible_name(rName
);
251 m_xTreeView
->grab_focus();
254 OUString
get_selected_text() const
256 return m_xTreeView
->get_selected_text();
259 int count_selected_rows() const
261 return m_xTreeView
->count_selected_rows();
264 void set_selection_mode(SelectionMode eMode
)
266 m_xTreeView
->set_selection_mode(eMode
);
269 weld::TreeView
& get_widget()
275 namespace sfx2
{ class DocumentInserter
; }
276 namespace sfx2
{ class FileDialogHelper
; }
280 class SwGlobalTreeDropTarget
: public DropTargetHelper
283 SwGlobalTree
& m_rTreeView
;
285 virtual sal_Int8
AcceptDrop( const AcceptDropEvent
& rEvt
) override
;
286 virtual sal_Int8
ExecuteDrop( const ExecuteDropEvent
& rEvt
) override
;
289 SwGlobalTreeDropTarget(SwGlobalTree
& rTreeView
);
292 class SwGlobalTree final
295 std::unique_ptr
<weld::TreeView
> m_xTreeView
;
296 SwGlobalTreeDropTarget m_aDropTargetHelper
;
297 VclPtr
<SwNavigationPI
> m_xDialog
;
298 AutoTimer m_aUpdateTimer
;
299 OUString m_aContextStrings
[GLOBAL_CONTEXT_COUNT
];
301 SwWrtShell
* m_pActiveShell
;
302 std::unique_ptr
<SwGlblDocContents
> m_pSwGlblDocContents
; // array with sorted content
304 std::unique_ptr
<SwGlblDocContent
> m_pDocContent
;
305 std::unique_ptr
<sfx2::DocumentInserter
> m_pDocInserter
;
307 static const SfxObjectShell
* pShowShell
;
309 void InsertRegion( const SwGlblDocContent
* _pContent
,
310 const css::uno::Sequence
< OUString
>& _rFiles
);
312 DECL_LINK( DialogClosedHdl
, sfx2::FileDialogHelper
*, void );
316 DECL_LINK(Timeout
, Timer
*, void);
317 DECL_LINK(DoubleClickHdl
, weld::TreeView
&, bool);
318 DECL_LINK(SelectHdl
, weld::TreeView
&, void);
319 DECL_LINK(FocusInHdl
, weld::Widget
&, void);
320 DECL_LINK(KeyInputHdl
, const KeyEvent
&, bool);
321 DECL_LINK(CommandHdl
, const CommandEvent
&, bool);
322 DECL_LINK(QueryTooltipHdl
, const weld::TreeIter
&, OUString
);
324 SwNavigationPI
* GetParentWindow();
326 void OpenDoc(const SwGlblDocContent
*);
327 void GotoContent(const SwGlblDocContent
*);
328 MenuEnableFlags
GetEnableFlags() const;
330 static void SetShowShell(const SfxObjectShell
*pSet
) {pShowShell
= pSet
;}
331 DECL_STATIC_LINK(SwGlobalTree
, ShowFrameHdl
, void*, void);
334 SwGlobalTree(std::unique_ptr
<weld::TreeView
> xTreeView
, SwNavigationPI
* pDialog
);
337 bool get_visible() const { return m_xTreeView
->get_visible(); }
339 void set_accessible_name(const OUString
& rName
)
341 m_xTreeView
->set_accessible_name(rName
);
346 m_xTreeView
->grab_focus();
349 void set_selection_mode(SelectionMode eMode
)
351 m_xTreeView
->set_selection_mode(eMode
);
354 weld::TreeView
& get_widget()
359 void MoveSelectionTo(const weld::TreeIter
* pDropTarget
);
361 void TbxMenuHdl(const OString
& rCommand
, weld::Menu
& rMenu
);
362 void InsertRegion( const SwGlblDocContent
* pCont
,
363 const OUString
* pFileName
= nullptr );
364 void EditContent(const SwGlblDocContent
* pCont
);
369 void ExecCommand(const OString
& rCmd
);
371 void Display(bool bOnlyUpdateUserData
= false);
373 bool Update(bool bHard
);
375 void ExecuteContextMenuAction(const OString
& rSelectedPopupEntry
);
377 const SwWrtShell
* GetActiveWrtShell() const {return m_pActiveShell
;}
382 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */