1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #ifndef INCLUDED_SD_SOURCE_UI_INC_SDTREELB_HXX
21 #define INCLUDED_SD_SOURCE_UI_INC_SDTREELB_HXX
22 
23 #include <pres.hxx>
24 #include <sddllapi.h>
25 #include <vcl/treelistbox.hxx>
26 #include <vcl/weld.hxx>
27 #include <svl/urlbmk.hxx>
28 #include <tools/ref.hxx>
29 #include "sdxfer.hxx"
30 #include <memory>
31 #include <vector>
32 
33 class SdDrawDocument;
34 class SfxMedium;
35 class SfxViewFrame;
36 class SdNavigatorWin;
37 class SdrObject;
38 class SdrObjList;
39 class SdPage;
40 class SvTreeListEntry;
41 
42 namespace sd {
43 class ViewShell;
44 
45 class DrawDocShell;
46 #ifndef SV_DECL_DRAW_DOC_SHELL_DEFINED
47 #define SV_DECL_DRAW_DOC_SHELL_DEFINED
48 typedef ::tools::SvRef<DrawDocShell> DrawDocShellRef;
49 #endif
50 }
51 namespace svt {
52     class AcceleratorExecute;
53 }
54 
55 /**
56  * Effect-Tab-Dialog
57  */
58 class SD_DLLPUBLIC SdPageObjsTLB final : public SvTreeListBox
59 {
60     static bool  SAL_DLLPRIVATE bIsInDrag;      ///< static, in the case the navigator is deleted in ExecuteDrag
61 
62     ::std::unique_ptr< ::svt::AcceleratorExecute> m_pAccel;
63 
64 public:
65 
66     // nested class to implement the TransferableHelper
67     class SdPageObjsTransferable : public SdTransferable
68     {
69     public:
70         SdPageObjsTransferable(
71             SdPageObjsTLB& rParent,
72             const INetBookmark& rBookmark,
73             ::sd::DrawDocShell& rDocShell,
74             NavigatorDragType eDragType );
GetDocShell() const75         ::sd::DrawDocShell&     GetDocShell() const { return mrDocShell;}
GetDragType() const76         NavigatorDragType   GetDragType() const { return meDragType;}
77 
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.
83         */
84         static SotClipboardFormatId GetListBoxDropFormatId();
85 
86     private:
87         /** Temporary drop flavor id that is used internally in the
88             navigator.
89         */
90         static SotClipboardFormatId mnListBoxDropFormatId;
91 
92         SdPageObjsTLB&      mrParent;
93         INetBookmark const      maBookmark;
94         ::sd::DrawDocShell&     mrDocShell;
95         NavigatorDragType const   meDragType;
96         SAL_DLLPRIVATE virtual               ~SdPageObjsTransferable() override;
97 
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;
101 
102         SAL_DLLPRIVATE virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& rId ) override;
103     };
104 
105     friend class SdPageObjsTLB::SdPageObjsTransferable;
106 
107     /** Determine whether the specified page belongs to the current show
108         which is either the standard show or a custom show.
109         @param pPage
110             Pointer to the page for which to check whether it belongs to the
111             show.
112         @return
113             Returns <FALSE/> if there is no custom show or if the current
114             show does not contain the specified page at least once.
115     */
116     bool PageBelongsToCurrentShow (const SdPage* pPage) const;
117 
118 private:
119 
120     VclPtr<SdNavigatorWin>  mpNavigator;
121     const SdDrawDocument*   mpDoc;
122     SdDrawDocument*         mpBookmarkDoc;
123     SfxMedium*              mpMedium;
124     SfxMedium*              mpOwnMedium;
125     Image const             maImgOle;
126     Image const             maImgGraphic;
127     bool                    mbLinkableSelected;
128     OUString                maDocName;
129     ::sd::DrawDocShellRef   mxBookmarkDocShRef; ///< for the loading of bookmarks
130     std::vector<OUString>   maTreeItem;
131     bool                    mbSaveTreeItemState;
132     OUString                maSelectionEntryText;
133 
134     // DragSourceHelper
135     virtual void            StartDrag( sal_Int8 nAction, const Point& rPosPixel ) override;
136 
137     // DropTargetHelper
138     virtual sal_Int8        AcceptDrop( const AcceptDropEvent& rEvt ) override;
139     virtual sal_Int8        ExecuteDrop( const ExecuteDropEvent& rEvt ) override;
140 
141     virtual void            RequestingChildren( SvTreeListEntry* pParent ) override;
142 
143     void                    DoDrag();
144     void                    OnDragFinished();
145 
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.
151         @param pObject
152             When this is NULL then an empty string is returned, regardless
153             of the value of bCreate.
154         @param 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.
158     */
159     OUString GetObjectName (
160         const SdrObject* pObject,
161         const bool bCreate = true) const;
162     void                    CloseBookmarkDoc();
163                             DECL_LINK(ExecDragHdl, void*, void);
164 
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.
168     */
169     virtual TriState NotifyMoving(
170         SvTreeListEntry*  pTarget,
171         SvTreeListEntry*  pEntry,
172         SvTreeListEntry*& rpNewParent,
173         sal_uLong&        rNewChildPos) override;
174 
175     using Window::GetDropTarget;
176     virtual SvTreeListEntry* GetDropTarget (const Point& rLocation) override;
177     virtual void InitEntry(SvTreeListEntry*, const OUString&, const Image&, const Image&) override;
178 
179 public:
180 
181     SdPageObjsTLB(vcl::Window* pParent, WinBits nStyle);
182     virtual ~SdPageObjsTLB() override;
183     virtual void            dispose() override;
184 
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;
192 
193     void                    SetViewFrame( const SfxViewFrame* pViewFrame );
194 
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);
GetShowAllShapes() const198     bool                    GetShowAllShapes() const { return mbShowAllShapes;}
IsNavigationGrabsFocus() const199     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() const;
207 
208     //Mark Current Entry
209     void                    SetSdNavigator(SdNavigatorWin* pNavigator);
210 
211     void                    Clear();
SetSaveTreeItemStateFlag(bool bState)212     void                    SetSaveTreeItemStateFlag(bool bState){mbSaveTreeItemState = bState;}
213     void                    SaveExpandedTreeItemState(SvTreeListEntry* pEntry, std::vector<OUString>& vectTreeItem);
214 
215     SdDrawDocument*         GetBookmarkDoc(SfxMedium* pMedium = nullptr);
216 
IsLinkableSelected() const217     bool                    IsLinkableSelected() const { return mbLinkableSelected; }
218 
219     static bool             IsInDrag();
220     using SvTreeListBox::ExecuteDrop;
221 
222     using SvTreeListBox::SelectEntry;
223 
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
227         way round.)
228         @return
229             May return <NULL/> when the link between view shell and
230             doc shell has been severed.
231     */
232     static ::sd::ViewShell* GetViewShellForDocShell (::sd::DrawDocShell &rDocShell);
233 
234 private:
235     /** This flag controls whether all shapes are shown as children of pages
236         and group shapes or only the named shapes.
237     */
238     bool mbShowAllShapes;
239     /** This flag controls whether to show all pages.
240     */
241     bool mbShowAllPages;
242     /**
243      * If changing the selection should also result in navigating to the
244      * relevant shape.
245      */
246     bool mbSelectionHandlerNavigates;
247     /**
248      * If navigation should not only select the relevant shape but also change
249      * focus to it.
250      */
251     bool mbNavigationGrabsFocus;
252 
253     /** Return <TRUE/> when the current transferable may be dropped at the
254         given list box entry.
255     */
256     bool IsDropAllowed (SvTreeListEntry const * pEntry);
257 
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.
260     */
261     class IconProvider;
262 
263     /** Add one list box entry for the parent of the given shapes and one child entry for
264         each of the given shapes.
265         @param rList
266             The container of shapes that are to be inserted.
267         @param pShape
268             The parent shape or NULL when the parent is a page.
269         @param rsName
270             The name to be displayed for the new parent node.
271         @param bIsExcluded
272             Some pages can be excluded (from the show?).
273         @param pParentEntry
274             The parent entry of the new parent entry.
275         @param rIconProvider
276             Icons used to visualize the different shape and page types.
277     */
278     void AddShapeList (
279         const SdrObjList& rList,
280         SdrObject* pShape,
281         const OUString& rsName,
282         const bool bIsExcluded,
283         SvTreeListEntry* pParentEntry,
284         const IconProvider& rIconProvider);
285 
286     /** Add the given object to a transferable object so that the object can
287         be dragged and dropped without having a name.
288     */
289     void AddShapeToTransferable (
290         SdTransferable& rTransferable,
291         SdrObject& rObject) const;
292 };
293 
294 class SD_DLLPUBLIC SdPageObjsTLV
295 {
296 private:
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.
304     */
305     bool m_bShowAllPages;
306     OUString m_aDocName;
307     ::sd::DrawDocShellRef m_xBookmarkDocShRef; ///< for the loading of bookmarks
308     Link<weld::TreeView&, void> m_aChangeHdl;
309 
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.
315         @param pObject
316             When this is NULL then an empty string is returned, regardless
317             of the value of bCreate.
318     */
319     static OUString GetObjectName (const SdrObject* pObject);
320 
321     void CloseBookmarkDoc();
322 
323     DECL_LINK(RequestingChildrenHdl, const weld::TreeIter&, bool);
324     DECL_LINK(SelectHdl, weld::TreeView&, void);
325 
326     /** Determine whether the specified page belongs to the current show
327         which is either the standard show or a custom show.
328         @param pPage
329             Pointer to the page for which to check whether it belongs to the
330             show.
331         @return
332             Returns <FALSE/> if there is no custom show or if the current
333             show does not contain the specified page at least once.
334     */
335     bool PageBelongsToCurrentShow (const SdPage* pPage) const;
336 
337 public:
338 
339     SdPageObjsTLV(std::unique_ptr<weld::TreeView> xTreeview);
340     ~SdPageObjsTLV();
341 
hide()342     void hide()
343     {
344         m_xTreeView->hide();
345     }
346 
show()347     void show()
348     {
349         m_xTreeView->show();
350     }
351 
set_size_request(int nWidth,int nHeight)352     void set_size_request(int nWidth, int nHeight)
353     {
354         m_xTreeView->set_size_request(nWidth, nHeight);
355     }
356 
get_approximate_digit_width() const357     float get_approximate_digit_width() const
358     {
359         return m_xTreeView->get_approximate_digit_width();
360     }
361 
get_height_rows(int nRows) const362     int get_height_rows(int nRows) const
363     {
364         return m_xTreeView->get_height_rows(nRows);
365     }
366 
set_selection_mode(SelectionMode eMode)367     void set_selection_mode(SelectionMode eMode)
368     {
369         m_xTreeView->set_selection_mode(eMode);
370     }
371 
372     bool SelectEntry(const OUString& rName);
373 
get_selected_text() const374     OUString get_selected_text() const
375     {
376         return m_xTreeView->get_selected_text();
377     }
378 
get_selected() const379     bool get_selected() const
380     {
381         return m_xTreeView->get_selected(nullptr);
382     }
383 
connect_changed(const Link<weld::TreeView &,void> & rLink)384     void connect_changed(const Link<weld::TreeView&, void>& rLink)
385     {
386         m_aChangeHdl = rLink;
387     }
388 
is_selected(const weld::TreeIter & rIter) const389     bool is_selected(const weld::TreeIter& rIter) const
390     {
391         return m_xTreeView->is_selected(rIter);
392     }
393 
get_iter_first(weld::TreeIter & rIter) const394     bool get_iter_first(weld::TreeIter& rIter) const
395     {
396         return m_xTreeView->get_iter_first(rIter);
397     }
398 
make_iterator()399     std::unique_ptr<weld::TreeIter> make_iterator()
400     {
401         return m_xTreeView->make_iterator();
402     }
403 
get_visible() const404     bool get_visible() const
405     {
406         return m_xTreeView->get_visible();
407     }
408 
unselect_all()409     void unselect_all()
410     {
411         m_xTreeView->unselect_all();
412     }
413 
414     void SetViewFrame(const SfxViewFrame* pViewFrame);
415 
416     void Fill(const SdDrawDocument*, const OUString& rDocName);
417     void Fill(const SdDrawDocument*, SfxMedium* pSfxMedium, const OUString& rDocName);
418 
419     /** Add one list box entry for the parent of the given shapes and one child entry for
420         each of the given shapes.
421         @param rList
422             The container of shapes that are to be inserted.
423         @param pShape
424             The parent shape or NULL when the parent is a page.
425         @param rsName
426             The name to be displayed for the new parent node.
427         @param bIsExcluded
428             Some pages can be excluded (from the show?).
429         @param pParentEntry
430             The parent entry of the new parent entry.
431     */
432     void AddShapeList (
433         const SdrObjList& rList,
434         SdrObject* pShape,
435         const OUString& rsName,
436         const bool bIsExcluded,
437         const weld::TreeIter* pParentEntry);
438 
439     /** return selected entries
440           nDepth == 0 -> pages
441           nDepth == 1 -> objects  */
442 
443     std::vector<OUString> GetSelectEntryList(const int nDepth) const;
444 
445     SdDrawDocument* GetBookmarkDoc();
446 
IsLinkableSelected() const447     bool IsLinkableSelected() const { return m_bLinkableSelected; }
448 
InsertEntry(const OUString & rName,const OUString & rExpander)449     void InsertEntry(const OUString &rName, const OUString &rExpander)
450     {
451         m_xTreeView->insert(nullptr, -1, &rName, nullptr, nullptr, nullptr, &rExpander, false, nullptr);
452     }
453 
InsertEntry(const weld::TreeIter * pParent,const OUString & rId,const OUString & rName,const OUString & rExpander,weld::TreeIter * pEntry=nullptr)454     void InsertEntry(const weld::TreeIter* pParent, const OUString& rId, const OUString &rName, const OUString &rExpander, weld::TreeIter* pEntry = nullptr)
455     {
456         m_xTreeView->insert(pParent, -1, &rName, &rId, nullptr, nullptr, &rExpander, false, pEntry);
457     }
458 
clear()459     void clear()
460     {
461         m_xTreeView->clear();
462     }
463 };
464 
465 #endif // INCLUDED_SD_SOURCE_UI_INC_SDTREELB_HXX
466 
467 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
468