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 .
20 #ifndef INCLUDED_SD_SOURCE_UI_INC_SDTREELB_HXX
21 #define INCLUDED_SD_SOURCE_UI_INC_SDTREELB_HXX
25 #include <vcl/treelistbox.hxx>
26 #include <vcl/weld.hxx>
27 #include <svl/urlbmk.hxx>
28 #include <tools/ref.hxx>
40 class SvTreeListEntry
;
46 #ifndef SV_DECL_DRAW_DOC_SHELL_DEFINED
47 #define SV_DECL_DRAW_DOC_SHELL_DEFINED
48 typedef ::tools::SvRef
<DrawDocShell
> DrawDocShellRef
;
52 class AcceleratorExecute
;
58 class SD_DLLPUBLIC SdPageObjsTLB final
: public SvTreeListBox
60 static bool SAL_DLLPRIVATE bIsInDrag
; ///< static, in the case the navigator is deleted in ExecuteDrag
62 ::std::unique_ptr
< ::svt::AcceleratorExecute
> m_pAccel
;
66 // nested class to implement the TransferableHelper
67 class SdPageObjsTransferable
: public SdTransferable
70 SdPageObjsTransferable(
71 SdPageObjsTLB
& rParent
,
72 const INetBookmark
& rBookmark
,
73 ::sd::DrawDocShell
& rDocShell
,
74 NavigatorDragType eDragType
);
75 ::sd::DrawDocShell
& GetDocShell() const { return mrDocShell
;}
76 NavigatorDragType
GetDragType() const { return meDragType
;}
78 static const css::uno::Sequence
< sal_Int8
>& getUnoTunnelId();
79 static SdPageObjsTransferable
* getImplementation( const css::uno::Reference
< css::uno::XInterface
>& rxData
) throw();
80 /** Return a temporary transferable data flavor that is used
81 internally in the navigator for reordering entries. Its
82 lifetime ends with the office application.
84 static SotClipboardFormatId
GetListBoxDropFormatId();
87 /** Temporary drop flavor id that is used internally in the
90 static SotClipboardFormatId mnListBoxDropFormatId
;
92 SdPageObjsTLB
& mrParent
;
93 INetBookmark
const maBookmark
;
94 ::sd::DrawDocShell
& mrDocShell
;
95 NavigatorDragType
const meDragType
;
96 SAL_DLLPRIVATE
virtual ~SdPageObjsTransferable() override
;
98 SAL_DLLPRIVATE
virtual void AddSupportedFormats() override
;
99 SAL_DLLPRIVATE
virtual bool GetData( const css::datatransfer::DataFlavor
& rFlavor
, const OUString
& rDestDoc
) override
;
100 SAL_DLLPRIVATE
virtual void DragFinished( sal_Int8 nDropAction
) override
;
102 SAL_DLLPRIVATE
virtual sal_Int64 SAL_CALL
getSomething( const css::uno::Sequence
< sal_Int8
>& rId
) override
;
105 friend class SdPageObjsTLB::SdPageObjsTransferable
;
107 /** Determine whether the specified page belongs to the current show
108 which is either the standard show or a custom show.
110 Pointer to the page for which to check whether it belongs to the
113 Returns <FALSE/> if there is no custom show or if the current
114 show does not contain the specified page at least once.
116 bool PageBelongsToCurrentShow (const SdPage
* pPage
) const;
120 VclPtr
<SdNavigatorWin
> mpNavigator
;
121 const SdDrawDocument
* mpDoc
;
122 SdDrawDocument
* mpBookmarkDoc
;
124 SfxMedium
* mpOwnMedium
;
125 Image
const maImgOle
;
126 Image
const maImgGraphic
;
127 bool mbLinkableSelected
;
129 ::sd::DrawDocShellRef mxBookmarkDocShRef
; ///< for the loading of bookmarks
130 std::vector
<OUString
> maTreeItem
;
131 bool mbSaveTreeItemState
;
132 OUString maSelectionEntryText
;
135 virtual void StartDrag( sal_Int8 nAction
, const Point
& rPosPixel
) override
;
138 virtual sal_Int8
AcceptDrop( const AcceptDropEvent
& rEvt
) override
;
139 virtual sal_Int8
ExecuteDrop( const ExecuteDropEvent
& rEvt
) override
;
141 virtual void RequestingChildren( SvTreeListEntry
* pParent
) override
;
144 void OnDragFinished();
146 /** Return the name of the object. When the object has no user supplied
147 name and the bCreate flag is <TRUE/> then a name is created
148 automatically. Additionally the mbShowAllShapes flag is taken into
149 account when there is no user supplied name. When this flag is
150 <FALSE/> then no name is created.
152 When this is NULL then an empty string is returned, regardless
153 of the value of bCreate.
155 This flag controls for objects without user supplied name
156 whether a name is created. When a name is created then this
157 name is not stored in the object.
159 OUString
GetObjectName (
160 const SdrObject
* pObject
,
161 const bool bCreate
= true) const;
162 void CloseBookmarkDoc();
163 DECL_LINK(ExecDragHdl
, void*, void);
165 /** Handle the reordering of entries in the navigator. This method
166 reorders both the involved shapes in their page as well as the
167 associated list box entries.
169 virtual TriState
NotifyMoving(
170 SvTreeListEntry
* pTarget
,
171 SvTreeListEntry
* pEntry
,
172 SvTreeListEntry
*& rpNewParent
,
173 sal_uLong
& rNewChildPos
) override
;
175 using Window::GetDropTarget
;
176 virtual SvTreeListEntry
* GetDropTarget (const Point
& rLocation
) override
;
177 virtual void InitEntry(SvTreeListEntry
*, const OUString
&, const Image
&, const Image
&,SvLBoxButtonKind
) override
;
181 SdPageObjsTLB(vcl::Window
* pParent
, WinBits nStyle
);
182 virtual ~SdPageObjsTLB() override
;
183 virtual void dispose() override
;
185 // helper function for GetEntryAltText and GetEntryLongDescription
186 OUString
getAltLongDescText( SvTreeListEntry
* pEntry
, bool isAltText
) const;
187 OUString
GetEntryAltText( SvTreeListEntry
* pEntry
) const override
;
188 OUString
GetEntryLongDescription( SvTreeListEntry
* pEntry
) const override
;
189 virtual void SelectHdl() override
;
190 virtual void KeyInput( const KeyEvent
& rKEvt
) override
;
191 void MouseButtonDown(const MouseEvent
& rMEvt
) override
;
193 void SetViewFrame( const SfxViewFrame
* pViewFrame
);
195 void Fill( const SdDrawDocument
*, bool bAllPages
, const OUString
& rDocName
);
196 void Fill( const SdDrawDocument
*, SfxMedium
* pSfxMedium
, const OUString
& rDocName
);
197 void SetShowAllShapes (const bool bShowAllShapes
, const bool bFill
);
198 bool GetShowAllShapes() const { return mbShowAllShapes
;}
199 bool IsNavigationGrabsFocus() const { return mbNavigationGrabsFocus
; }
200 bool IsEqualToDoc( const SdDrawDocument
* pInDoc
);
201 /// Visits rList recursively and tries to advance pEntry accordingly.
202 bool IsEqualToShapeList(SvTreeListEntry
*& pEntry
, const SdrObjList
& rList
,
203 const OUString
& rListName
);
204 bool HasSelectedChildren( const OUString
& rName
);
205 bool SelectEntry( const OUString
& rName
);
206 OUString
GetSelectedEntry();
209 void SetSdNavigator(SdNavigatorWin
* pNavigator
);
212 void SetSaveTreeItemStateFlag(bool bState
){mbSaveTreeItemState
= bState
;}
213 void SaveExpandedTreeItemState(SvTreeListEntry
* pEntry
, std::vector
<OUString
>& vectTreeItem
);
215 SdDrawDocument
* GetBookmarkDoc(SfxMedium
* pMedium
= nullptr);
217 bool IsLinkableSelected() const { return mbLinkableSelected
; }
219 static bool IsInDrag();
220 using SvTreeListBox::ExecuteDrop
;
222 using SvTreeListBox::SelectEntry
;
224 /** Return the view shell that is linked to the given doc shell.
225 Call this method when the there is a chance that the doc shell
226 has been disconnected from the view shell (but not the other
229 May return <NULL/> when the link between view shell and
230 doc shell has been severed.
232 static ::sd::ViewShell
* GetViewShellForDocShell (::sd::DrawDocShell
&rDocShell
);
235 /** This flag controls whether all shapes are shown as children of pages
236 and group shapes or only the named shapes.
238 bool mbShowAllShapes
;
239 /** This flag controls whether to show all pages.
243 * If changing the selection should also result in navigating to the
246 bool mbSelectionHandlerNavigates
;
248 * If navigation should not only select the relevant shape but also change
251 bool mbNavigationGrabsFocus
;
253 /** Return <TRUE/> when the current transferable may be dropped at the
254 given list box entry.
256 bool IsDropAllowed (SvTreeListEntry
const * pEntry
);
258 /** This inner class is defined in sdtreelb.cxx and is basically a
259 container for the icons used in the list box for the entries.
263 /** Add one list box entry for the parent of the given shapes and one child entry for
264 each of the given shapes.
266 The container of shapes that are to be inserted.
268 The parent shape or NULL when the parent is a page.
270 The name to be displayed for the new parent node.
272 Some pages can be excluded (from the show?).
274 The parent entry of the new parent entry.
276 Icons used to visualize the different shape and page types.
279 const SdrObjList
& rList
,
281 const OUString
& rsName
,
282 const bool bIsExcluded
,
283 SvTreeListEntry
* pParentEntry
,
284 const IconProvider
& rIconProvider
);
286 /** Add the given object to a transferable object so that the object can
287 be dragged and dropped without having a name.
289 void AddShapeToTransferable (
290 SdTransferable
& rTransferable
,
291 SdrObject
& rObject
) const;
294 class SD_DLLPUBLIC SdPageObjsTLV
297 std::unique_ptr
<weld::TreeView
> m_xTreeView
;
298 std::unique_ptr
<::svt::AcceleratorExecute
> m_xAccel
;
299 const SdDrawDocument
* m_pDoc
;
300 SdDrawDocument
* m_pBookmarkDoc
;
301 SfxMedium
* m_pMedium
;
302 bool m_bLinkableSelected
;
303 /** This flag controls whether to show all pages.
305 bool m_bShowAllPages
;
307 ::sd::DrawDocShellRef m_xBookmarkDocShRef
; ///< for the loading of bookmarks
308 Link
<weld::TreeView
&, void> m_aChangeHdl
;
310 /** Return the name of the object. When the object has no user supplied
311 name and the bCreate flag is <TRUE/> then a name is created
312 automatically. Additionally the mbShowAllShapes flag is taken into
313 account when there is no user supplied name. When this flag is
314 <FALSE/> then no name is created.
316 When this is NULL then an empty string is returned, regardless
317 of the value of bCreate.
319 static OUString
GetObjectName (const SdrObject
* pObject
);
321 void CloseBookmarkDoc();
323 DECL_LINK(RequestingChildrenHdl
, const weld::TreeIter
&, bool);
324 DECL_LINK(SelectHdl
, weld::TreeView
&, void);
326 /** Determine whether the specified page belongs to the current show
327 which is either the standard show or a custom show.
329 Pointer to the page for which to check whether it belongs to the
332 Returns <FALSE/> if there is no custom show or if the current
333 show does not contain the specified page at least once.
335 bool PageBelongsToCurrentShow (const SdPage
* pPage
) const;
339 SdPageObjsTLV(std::unique_ptr
<weld::TreeView
> xTreeview
);
352 void set_size_request(int nWidth
, int nHeight
)
354 m_xTreeView
->set_size_request(nWidth
, nHeight
);
357 float get_approximate_digit_width() const
359 return m_xTreeView
->get_approximate_digit_width();
362 int get_height_rows(int nRows
) const
364 return m_xTreeView
->get_height_rows(nRows
);
367 void set_selection_mode(SelectionMode eMode
)
369 m_xTreeView
->set_selection_mode(eMode
);
372 bool SelectEntry(const OUString
& rName
);
374 OUString
get_selected_text() const
376 return m_xTreeView
->get_selected_text();
379 bool get_selected() const
381 return m_xTreeView
->get_selected(nullptr);
384 void connect_changed(const Link
<weld::TreeView
&, void>& rLink
)
386 m_aChangeHdl
= rLink
;
389 bool is_selected(const weld::TreeIter
& rIter
) const
391 return m_xTreeView
->is_selected(rIter
);
394 bool get_iter_first(weld::TreeIter
& rIter
) const
396 return m_xTreeView
->get_iter_first(rIter
);
399 std::unique_ptr
<weld::TreeIter
> make_iterator()
401 return m_xTreeView
->make_iterator();
404 bool get_visible() const
406 return m_xTreeView
->get_visible();
411 m_xTreeView
->unselect_all();
414 void SetViewFrame(const SfxViewFrame
* pViewFrame
);
416 void Fill(const SdDrawDocument
*, bool bAllPages
, const OUString
& rDocName
);
417 void Fill(const SdDrawDocument
*, SfxMedium
* pSfxMedium
, const OUString
& rDocName
);
419 /** Add one list box entry for the parent of the given shapes and one child entry for
420 each of the given shapes.
422 The container of shapes that are to be inserted.
424 The parent shape or NULL when the parent is a page.
426 The name to be displayed for the new parent node.
428 Some pages can be excluded (from the show?).
430 The parent entry of the new parent entry.
433 const SdrObjList
& rList
,
435 const OUString
& rsName
,
436 const bool bIsExcluded
,
437 weld::TreeIter
* pParentEntry
);
439 /** return selected entries
441 nDepth == 1 -> objects */
443 std::vector
<OUString
> GetSelectEntryList(const int nDepth
) const;
445 SdDrawDocument
* GetBookmarkDoc();
447 bool IsLinkableSelected() const { return m_bLinkableSelected
; }
449 void InsertEntry(const OUString
&rName
, const OUString
&rExpander
)
451 m_xTreeView
->insert(nullptr, -1, &rName
, nullptr, nullptr, nullptr, &rExpander
, false, nullptr);
454 void InsertEntry(weld::TreeIter
* pParent
, const OUString
& rId
, const OUString
&rName
, const OUString
&rExpander
, weld::TreeIter
* pEntry
= nullptr)
456 m_xTreeView
->insert(pParent
, -1, &rName
, &rId
, nullptr, nullptr, &rExpander
, false, pEntry
);
461 m_xTreeView
->clear();
465 #endif // INCLUDED_SD_SOURCE_UI_INC_SDTREELB_HXX
467 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */