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 .
24 #include <vcl/weld.hxx>
25 #include <svl/urlbmk.hxx>
26 #include <tools/ref.hxx>
45 #ifndef SV_DECL_DRAW_DOC_SHELL_DEFINED
46 #define SV_DECL_DRAW_DOC_SHELL_DEFINED
47 typedef rtl::Reference
<DrawDocShell
> DrawDocShellRef
;
51 class AcceleratorExecute
;
54 class SdPageObjsTLVDropTarget final
: public DropTargetHelper
57 weld::TreeView
& m_rTreeView
;
59 bool m_bOrderFrontToBack
= false;
61 virtual sal_Int8
AcceptDrop( const AcceptDropEvent
& rEvt
) override
;
62 virtual sal_Int8
ExecuteDrop( const ExecuteDropEvent
& rEvt
) override
;
65 SdPageObjsTLVDropTarget(weld::TreeView
& rTreeView
);
67 void SetDrawView(SdrView
* pSdrView
) { m_pSdrView
= pSdrView
; }
68 void SetOrderFrontToBack(bool bSet
) { m_bOrderFrontToBack
= bSet
; }
74 static bool bIsInDrag
; ///< static, in the case the navigator is deleted in ExecuteDrag
76 std::unique_ptr
<weld::TreeView
> m_xTreeView
;
77 std::unique_ptr
<weld::TreeIter
> m_xScratchIter
;
78 std::unique_ptr
<SdPageObjsTLVDropTarget
> m_xDropTargetHelper
;
79 std::unique_ptr
<::svt::AcceleratorExecute
> m_xAccel
;
80 SdNavigatorWin
* m_pNavigator
;
81 const SdDrawDocument
* m_pDoc
;
82 SdDrawDocument
* m_pBookmarkDoc
;
84 SfxMedium
* m_pOwnMedium
;
85 bool m_bLinkableSelected
;
86 bool m_bShowAllShapes
;
87 bool m_bOrderFrontToBack
;
89 /** This flag controls whether to show all pages.
94 * If changing the selection should also result in navigating to the
97 bool m_bSelectionHandlerNavigates
;
100 * If navigation should not only select the relevant shape but also change
103 bool m_bNavigationGrabsFocus
;
105 bool m_bEditing
= false;
107 SelectionMode m_eSelectionMode
;
109 ImplSVEvent
* m_nSelectEventId
;
110 ImplSVEvent
* m_nRowActivateEventId
;
113 ::sd::DrawDocShellRef m_xBookmarkDocShRef
; ///< for the loading of bookmarks
114 Link
<weld::TreeView
&, void> m_aChangeHdl
;
115 Link
<weld::TreeView
&, bool> m_aRowActivatedHdl
;
116 Link
<const KeyEvent
&, bool> m_aKeyPressHdl
;
117 Link
<const MouseEvent
&, bool> m_aMouseReleaseHdl
;
118 Link
<const CommandEvent
&, bool> m_aPopupMenuHdl
;
120 /** Return the name of the object. When the object has no user supplied
121 name and the bCreate flag is <TRUE/> then a name is created
122 automatically. Additionally the mbShowAllShapes flag is taken into
123 account when there is no user supplied name. When this flag is
124 <FALSE/> then no name is created.
126 When this is NULL then an empty string is returned, regardless
127 of the value of bCreate.
129 This flag controls for objects without user supplied name
130 whether a name is created. When a name is created then this
131 name is not stored in the object.
133 OUString
GetObjectName (
134 const SdrObject
* pObject
,
135 const bool bCreate
= true) const;
137 void CloseBookmarkDoc();
139 DECL_LINK(RequestingChildrenHdl
, const weld::TreeIter
&, bool);
140 DECL_LINK(SelectHdl
, weld::TreeView
&, void);
141 DECL_LINK(AsyncSelectHdl
, void*, void);
142 DECL_LINK(RowActivatedHdl
, weld::TreeView
&, bool);
143 DECL_LINK(AsyncRowActivatedHdl
, void*, void);
144 DECL_LINK(DragBeginHdl
, bool&, bool);
145 DECL_LINK(KeyInputHdl
, const KeyEvent
&, bool);
147 DECL_LINK(EditingEntryHdl
, const weld::TreeIter
&, bool);
148 typedef std::pair
<const weld::TreeIter
&, OUString
> IterString
;
149 DECL_LINK(EditedEntryHdl
, const IterString
&, bool);
150 DECL_LINK(EditEntryAgain
, void*, void);
152 DECL_LINK(CommandHdl
, const CommandEvent
&, bool);
154 /** Determine whether the specified page belongs to the current show
155 which is either the standard show or a custom show.
157 Pointer to the page for which to check whether it belongs to the
160 Returns <FALSE/> if there is no custom show or if the current
161 show does not contain the specified page at least once.
163 bool PageBelongsToCurrentShow (const SdPage
* pPage
) const;
166 static void OnDragFinished();
173 SD_DLLPUBLIC
SdPageObjsTLV(std::unique_ptr
<weld::TreeView
> xTreeview
);
174 SD_DLLPUBLIC
~SdPageObjsTLV();
176 bool IsEditingActive() const {return m_bEditing
;}
190 m_xTreeView
->grab_focus();
193 void set_size_request(int nWidth
, int nHeight
)
195 m_xTreeView
->set_size_request(nWidth
, nHeight
);
198 float get_approximate_digit_width() const
200 return m_xTreeView
->get_approximate_digit_width();
203 DECL_LINK(MousePressHdl
, const MouseEvent
&, SD_DLLPUBLIC
bool);
204 DECL_LINK(MouseReleaseHdl
, const MouseEvent
&, SD_DLLPUBLIC
bool);
206 SD_DLLPUBLIC
void Select();
208 int get_height_rows(int nRows
) const
210 return m_xTreeView
->get_height_rows(nRows
);
213 void set_selection_mode(SelectionMode eMode
)
215 m_eSelectionMode
= eMode
;
216 m_xTreeView
->set_selection_mode(eMode
);
219 SelectionMode
get_selection_mode() const
221 return m_eSelectionMode
;
224 void connect_row_activated(const Link
<weld::TreeView
&, bool>& rLink
)
226 m_aRowActivatedHdl
= rLink
;
229 void connect_key_press(const Link
<const KeyEvent
&, bool>& rLink
)
231 m_aKeyPressHdl
= rLink
;
234 void connect_mouse_release(const Link
<const MouseEvent
&, bool>& rLink
)
236 m_aMouseReleaseHdl
= rLink
;
239 void connect_popup_menu(const Link
<const CommandEvent
&, bool>& rLink
)
241 m_aPopupMenuHdl
= rLink
;
244 bool HasSelectedChildren(std::u16string_view rName
);
245 SD_DLLPUBLIC
bool SelectEntry(std::u16string_view rName
);
246 void SelectEntry(const SdrObject
* pObj
);
248 OUString
get_selected_text() const
250 return m_xTreeView
->get_selected_text();
253 bool get_selected() const
255 return m_xTreeView
->get_selected(nullptr);
258 int count_selected_rows() const
260 return m_xTreeView
->count_selected_rows();
263 void connect_changed(const Link
<weld::TreeView
&, void>& rLink
)
265 m_aChangeHdl
= rLink
;
268 bool is_selected(const weld::TreeIter
& rIter
) const
270 return m_xTreeView
->is_selected(rIter
);
273 bool get_iter_first(weld::TreeIter
& rIter
) const
275 return m_xTreeView
->get_iter_first(rIter
);
278 weld::TreeView
& get_treeview()
283 std::unique_ptr
<weld::TreeIter
> make_iterator()
285 return m_xTreeView
->make_iterator();
288 bool get_visible() const
290 return m_xTreeView
->get_visible();
295 m_xTreeView
->unselect_all();
298 OUString
get_cursor_text() const
300 std::unique_ptr
<weld::TreeIter
> xIter(m_xTreeView
->make_iterator());
301 if (m_xTreeView
->get_cursor(xIter
.get()))
302 return m_xTreeView
->get_text(*xIter
);
306 OUString
get_cursor_id() const
308 std::unique_ptr
<weld::TreeIter
> xIter(m_xTreeView
->make_iterator());
309 if (m_xTreeView
->get_cursor(xIter
.get()))
310 return m_xTreeView
->get_id(*xIter
);
314 SD_DLLPUBLIC
void SetViewFrame(const SfxViewFrame
* pViewFrame
);
316 SD_DLLPUBLIC
void Fill(const SdDrawDocument
*, bool bAllPages
, const OUString
& rDocName
);
317 SD_DLLPUBLIC
void Fill(const SdDrawDocument
*, SfxMedium
* pSfxMedium
, const OUString
& rDocName
);
319 void SetShowAllShapes (const bool bShowAllShapes
, const bool bFill
);
320 bool GetShowAllShapes() const { return m_bShowAllShapes
; }
322 void SetOrderFrontToBack (const bool bOrderFrontToBack
);
323 bool GetOrderFrontToBack() const { return m_bOrderFrontToBack
; }
325 bool IsNavigationGrabsFocus() const { return m_bNavigationGrabsFocus
; }
326 SD_DLLPUBLIC
bool IsEqualToDoc(const SdDrawDocument
* pInDoc
);
327 /// Visits rList recursively and tries to advance rEntry accordingly.
328 bool IsEqualToShapeList(std::unique_ptr
<weld::TreeIter
>& rEntry
, const SdrObjList
& rList
,
329 std::u16string_view rListName
);
331 static bool IsInDrag();
333 /** Return the view shell that is linked to the given doc shell.
334 Call this method when the there is a chance that the doc shell
335 has been disconnected from the view shell (but not the other
338 May return <NULL/> when the link between view shell and
339 doc shell has been severed.
341 static ::sd::ViewShell
* GetViewShellForDocShell (::sd::DrawDocShell
&rDocShell
);
343 /** Add one list box entry for the parent of the given shapes and one child entry for
344 each of the given shapes.
346 The container of shapes that are to be inserted.
348 The parent shape or NULL when the parent is a page.
350 The name to be displayed for the new parent node.
352 Some pages can be excluded (from the show?).
354 The parent entry of the new parent entry.
357 const SdrObjList
& rList
,
358 const SdrObject
* pShape
,
359 const OUString
& rsName
,
360 const bool bIsExcluded
,
361 const weld::TreeIter
* pParentEntry
);
363 /** Add the given object to a transferable object so that the object can
364 be dragged and dropped without having a name.
366 void AddShapeToTransferable (
367 SdTransferable
& rTransferable
,
368 const SdrObject
& rObject
) const;
370 /** return selected entries
372 nDepth == 1 -> objects */
374 SD_DLLPUBLIC
std::vector
<OUString
> GetSelectEntryList(const int nDepth
) const;
376 std::vector
<OUString
> GetSelectedEntryIds() const;
378 SD_DLLPUBLIC SdDrawDocument
* GetBookmarkDoc(SfxMedium
* pMedium
= nullptr);
380 bool IsLinkableSelected() const { return m_bLinkableSelected
; }
382 void InsertEntry(const OUString
&rName
, const OUString
&rExpander
)
384 m_xTreeView
->insert(nullptr, -1, &rName
, nullptr, nullptr, nullptr, false, m_xScratchIter
.get());
385 m_xTreeView
->set_image(*m_xScratchIter
, rExpander
);
388 void InsertEntry(const weld::TreeIter
* pParent
, const OUString
& rId
, const OUString
&rName
, const OUString
&rExpander
, weld::TreeIter
* pEntry
= nullptr)
391 m_xTreeView
->insert(pParent
, m_bOrderFrontToBack
? 0 : -1, &rName
, &rId
, nullptr,
392 nullptr, false, m_xScratchIter
.get());
394 // always append page/slide entry
395 m_xTreeView
->insert(nullptr, -1, &rName
, &rId
, nullptr, nullptr, false, m_xScratchIter
.get());
396 m_xTreeView
->set_image(*m_xScratchIter
, rExpander
);
398 m_xTreeView
->copy_iterator(*m_xScratchIter
, *pEntry
);
402 void SetSdNavigator(SdNavigatorWin
* pNavigator
);
406 m_xTreeView
->clear();
409 // nested class to implement the TransferableHelper
410 class SdPageObjsTransferable final
: public SdTransferable
413 SdPageObjsTransferable(
414 INetBookmark aBookmark
,
415 ::sd::DrawDocShell
& rDocShell
,
416 NavigatorDragType eDragType
);
417 ::sd::DrawDocShell
& GetDocShell() const { return mrDocShell
;}
418 NavigatorDragType
GetDragType() const { return meDragType
;}
420 static SdPageObjsTransferable
* getImplementation( const css::uno::Reference
< css::uno::XInterface
>& rxData
) noexcept
;
421 /** Return a temporary transferable data flavor that is used
422 internally in the navigator for reordering entries. Its
423 lifetime ends with the office application.
425 static SotClipboardFormatId
GetListBoxDropFormatId();
428 /** Temporary drop flavor id that is used internally in the
431 static SotClipboardFormatId mnListBoxDropFormatId
;
433 INetBookmark
const maBookmark
;
434 ::sd::DrawDocShell
& mrDocShell
;
435 NavigatorDragType
const meDragType
;
436 virtual ~SdPageObjsTransferable() override
;
438 virtual void AddSupportedFormats() override
;
439 virtual bool GetData( const css::datatransfer::DataFlavor
& rFlavor
, const OUString
& rDestDoc
) override
;
440 virtual void DragFinished( sal_Int8 nDropAction
) override
;
443 friend class SdPageObjsTLV::SdPageObjsTransferable
;
446 rtl::Reference
<SdPageObjsTransferable
> m_xHelper
;
449 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */