/src/libreoffice/sd/source/ui/inc/sdtreelb.hxx
Line | Count | Source |
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 | | #pragma once |
21 | | |
22 | | #include <pres.hxx> |
23 | | #include <sddllapi.h> |
24 | | #include <vcl/weld/TreeView.hxx> |
25 | | #include <svl/urlbmk.hxx> |
26 | | #include <tools/ref.hxx> |
27 | | #include "sdxfer.hxx" |
28 | | #include <memory> |
29 | | #include <vector> |
30 | | |
31 | | class SdrView; |
32 | | class SdDrawDocument; |
33 | | class SfxMedium; |
34 | | class SfxViewFrame; |
35 | | class SdNavigatorWin; |
36 | | class SdrObject; |
37 | | class SdrObjList; |
38 | | class SdPage; |
39 | | struct ImplSVEvent; |
40 | | |
41 | | namespace sd { |
42 | | class ViewShell; |
43 | | |
44 | | class DrawDocShell; |
45 | | #ifndef SV_DECL_DRAW_DOC_SHELL_DEFINED |
46 | | #define SV_DECL_DRAW_DOC_SHELL_DEFINED |
47 | | typedef rtl::Reference<DrawDocShell> DrawDocShellRef; |
48 | | #endif |
49 | | } |
50 | | namespace svt { |
51 | | class AcceleratorExecute; |
52 | | } |
53 | | |
54 | | class SdPageObjsTLVDropTarget final : public DropTargetHelper |
55 | | { |
56 | | private: |
57 | | weld::TreeView& m_rTreeView; |
58 | | SdrView* m_pSdrView; |
59 | | bool m_bOrderFrontToBack = false; |
60 | | |
61 | | virtual sal_Int8 AcceptDrop( const AcceptDropEvent& rEvt ) override; |
62 | | virtual sal_Int8 ExecuteDrop( const ExecuteDropEvent& rEvt ) override; |
63 | | |
64 | | public: |
65 | | SdPageObjsTLVDropTarget(weld::TreeView& rTreeView); |
66 | | |
67 | 0 | void SetDrawView(SdrView* pSdrView) { m_pSdrView = pSdrView; } |
68 | 0 | void SetOrderFrontToBack(bool bSet) { m_bOrderFrontToBack = bSet; } |
69 | | }; |
70 | | |
71 | | class SdPageObjsTLV |
72 | | { |
73 | | private: |
74 | | std::unique_ptr<weld::TreeView> m_xTreeView; |
75 | | std::unique_ptr<weld::TreeIter> m_xScratchIter; |
76 | | std::unique_ptr<SdPageObjsTLVDropTarget> m_xDropTargetHelper; |
77 | | std::unique_ptr<::svt::AcceleratorExecute> m_xAccel; |
78 | | SdNavigatorWin* m_pNavigator; |
79 | | const SdDrawDocument* m_pDoc; |
80 | | SdDrawDocument* m_pBookmarkDoc; |
81 | | SfxMedium* m_pMedium; |
82 | | SfxMedium* m_pOwnMedium; |
83 | | bool m_bLinkableSelected; |
84 | | bool m_bShowAllShapes; |
85 | | bool m_bOrderFrontToBack; |
86 | | |
87 | | /** This flag controls whether to show all pages. |
88 | | */ |
89 | | bool m_bShowAllPages; |
90 | | |
91 | | /** |
92 | | * If changing the selection should also result in navigating to the |
93 | | * relevant shape. |
94 | | */ |
95 | | bool m_bSelectionHandlerNavigates; |
96 | | |
97 | | /** |
98 | | * If navigation should not only select the relevant shape but also change |
99 | | * focus to it. |
100 | | */ |
101 | | bool m_bNavigationGrabsFocus; |
102 | | |
103 | | bool m_bEditing = false; |
104 | | |
105 | | SelectionMode m_eSelectionMode; |
106 | | |
107 | | ImplSVEvent* m_nSelectEventId; |
108 | | ImplSVEvent* m_nRowActivateEventId; |
109 | | |
110 | | OUString m_aDocName; |
111 | | ::sd::DrawDocShellRef m_xBookmarkDocShRef; ///< for the loading of bookmarks |
112 | | Link<weld::TreeView&, void> m_aChangeHdl; |
113 | | Link<weld::TreeView&, bool> m_aRowActivatedHdl; |
114 | | Link<const KeyEvent&, bool> m_aKeyPressHdl; |
115 | | Link<const MouseEvent&, bool> m_aMouseReleaseHdl; |
116 | | Link<const CommandEvent&, bool> m_aPopupMenuHdl; |
117 | | |
118 | | /** Return the name of the object. When the object has no user supplied |
119 | | name and the bCreate flag is <TRUE/> then a name is created |
120 | | automatically. Additionally the mbShowAllShapes flag is taken into |
121 | | account when there is no user supplied name. When this flag is |
122 | | <FALSE/> then no name is created. |
123 | | @param pObject |
124 | | When this is NULL then an empty string is returned, regardless |
125 | | of the value of bCreate. |
126 | | @param bCreate |
127 | | This flag controls for objects without user supplied name |
128 | | whether a name is created. When a name is created then this |
129 | | name is not stored in the object. |
130 | | */ |
131 | | OUString GetObjectName ( |
132 | | const SdrObject* pObject, |
133 | | const bool bCreate = true) const; |
134 | | |
135 | | void CloseBookmarkDoc(); |
136 | | |
137 | | DECL_LINK(RequestingChildrenHdl, const weld::TreeIter&, bool); |
138 | | DECL_LINK(SelectHdl, weld::ItemView&, void); |
139 | | DECL_LINK(AsyncSelectHdl, void*, void); |
140 | | DECL_LINK(RowActivatedHdl, const weld::TreeIter&, bool); |
141 | | DECL_LINK(AsyncRowActivatedHdl, void*, void); |
142 | | DECL_LINK(DragBeginHdl, bool&, bool); |
143 | | DECL_LINK(KeyInputHdl, const KeyEvent&, bool); |
144 | | |
145 | | DECL_LINK(EditingEntryHdl, const weld::TreeIter&, bool); |
146 | | DECL_LINK(EditedEntryHdl, const weld::TreeView::IterColText&, bool); |
147 | | DECL_LINK(EditEntryAgain, void*, void); |
148 | | |
149 | | DECL_LINK(CommandHdl, const CommandEvent&, bool); |
150 | | |
151 | | /** Determine whether the specified page belongs to the current show |
152 | | which is either the standard show or a custom show. |
153 | | @param pPage |
154 | | Pointer to the page for which to check whether it belongs to the |
155 | | show. |
156 | | @return |
157 | | Returns <FALSE/> if there is no custom show or if the current |
158 | | show does not contain the specified page at least once. |
159 | | */ |
160 | | bool PageBelongsToCurrentShow (const SdPage* pPage) const; |
161 | | |
162 | | bool DoDrag(); |
163 | | |
164 | | // DragSourceHelper |
165 | | bool StartDrag(); |
166 | | |
167 | | public: |
168 | | |
169 | | SD_DLLPUBLIC SdPageObjsTLV(std::unique_ptr<weld::TreeView> xTreeview); |
170 | | SD_DLLPUBLIC ~SdPageObjsTLV(); |
171 | | |
172 | | void hide() |
173 | 0 | { |
174 | 0 | m_xTreeView->hide(); |
175 | 0 | } |
176 | | |
177 | | void show() |
178 | 0 | { |
179 | 0 | m_xTreeView->show(); |
180 | 0 | } |
181 | | |
182 | | void grab_focus() |
183 | 0 | { |
184 | 0 | m_xTreeView->grab_focus(); |
185 | 0 | } |
186 | | |
187 | | void set_size_request(int nWidth, int nHeight) |
188 | 0 | { |
189 | 0 | m_xTreeView->set_size_request(nWidth, nHeight); |
190 | 0 | } |
191 | | |
192 | | float get_approximate_digit_width() const |
193 | 0 | { |
194 | 0 | return m_xTreeView->get_approximate_digit_width(); |
195 | 0 | } |
196 | | |
197 | | DECL_LINK(MousePressHdl, const MouseEvent&, SD_DLLPUBLIC bool); |
198 | | DECL_LINK(MouseReleaseHdl, const MouseEvent&, SD_DLLPUBLIC bool); |
199 | | |
200 | | SD_DLLPUBLIC void Select(); |
201 | | |
202 | | int get_height_rows(int nRows) const |
203 | 0 | { |
204 | 0 | return m_xTreeView->get_height_rows(nRows); |
205 | 0 | } |
206 | | |
207 | | void set_selection_mode(SelectionMode eMode) |
208 | 0 | { |
209 | 0 | m_eSelectionMode = eMode; |
210 | 0 | m_xTreeView->set_selection_mode(eMode); |
211 | 0 | } |
212 | | |
213 | | SelectionMode get_selection_mode() const |
214 | 0 | { |
215 | 0 | return m_eSelectionMode; |
216 | 0 | } |
217 | | |
218 | | void connect_item_activated(const Link<weld::TreeView&, bool>& rLink) |
219 | 0 | { |
220 | 0 | m_aRowActivatedHdl = rLink; |
221 | 0 | } |
222 | | |
223 | | void connect_key_press(const Link<const KeyEvent&, bool>& rLink) |
224 | 0 | { |
225 | 0 | m_aKeyPressHdl = rLink; |
226 | 0 | } |
227 | | |
228 | | void connect_mouse_release(const Link<const MouseEvent&, bool>& rLink) |
229 | 0 | { |
230 | 0 | m_aMouseReleaseHdl = rLink; |
231 | 0 | } |
232 | | |
233 | | void connect_popup_menu(const Link<const CommandEvent&, bool>& rLink) |
234 | 0 | { |
235 | 0 | m_aPopupMenuHdl = rLink; |
236 | 0 | } |
237 | | |
238 | | bool HasSelectedChildren(std::u16string_view rName); |
239 | | SD_DLLPUBLIC bool SelectEntry(std::u16string_view rName); |
240 | | void SelectEntry(const SdrObject* pObj); |
241 | | |
242 | | OUString get_selected_text() const |
243 | 0 | { |
244 | 0 | return m_xTreeView->get_selected_text(); |
245 | 0 | } |
246 | | |
247 | | bool get_selected() const |
248 | 0 | { |
249 | 0 | return bool(m_xTreeView->get_selected()); |
250 | 0 | } |
251 | | |
252 | | int count_selected_rows() const |
253 | 0 | { |
254 | 0 | return m_xTreeView->count_selected_rows(); |
255 | 0 | } |
256 | | |
257 | | void connect_changed(const Link<weld::TreeView&, void>& rLink) |
258 | 0 | { |
259 | 0 | m_aChangeHdl = rLink; |
260 | 0 | } |
261 | | |
262 | | bool is_selected(const weld::TreeIter& rIter) const |
263 | 0 | { |
264 | 0 | return m_xTreeView->is_selected(rIter); |
265 | 0 | } |
266 | | |
267 | | bool get_iter_first(weld::TreeIter& rIter) const |
268 | 0 | { |
269 | 0 | return m_xTreeView->get_iter_first(rIter); |
270 | 0 | } |
271 | | |
272 | | weld::TreeView& get_treeview() |
273 | 0 | { |
274 | 0 | return *m_xTreeView; |
275 | 0 | } |
276 | | |
277 | | std::unique_ptr<weld::TreeIter> make_iterator() |
278 | 0 | { |
279 | 0 | return m_xTreeView->make_iterator(); |
280 | 0 | } |
281 | | |
282 | | bool get_visible() const |
283 | 0 | { |
284 | 0 | return m_xTreeView->get_visible(); |
285 | 0 | } |
286 | | |
287 | | void unselect_all() |
288 | 0 | { |
289 | 0 | m_xTreeView->unselect_all(); |
290 | 0 | } |
291 | | |
292 | | OUString get_cursor_text() const |
293 | 0 | { |
294 | 0 | if (std::unique_ptr<weld::TreeIter> xIter = m_xTreeView->get_cursor()) |
295 | 0 | return m_xTreeView->get_text(*xIter); |
296 | 0 | return OUString(); |
297 | 0 | } |
298 | | |
299 | | OUString get_cursor_id() const |
300 | 0 | { |
301 | 0 | if (std::unique_ptr<weld::TreeIter> xIter = m_xTreeView->get_cursor()) |
302 | 0 | return m_xTreeView->get_id(*xIter); |
303 | 0 | return OUString(); |
304 | 0 | } |
305 | | |
306 | | SD_DLLPUBLIC void SetViewFrame(const SfxViewFrame* pViewFrame); |
307 | | |
308 | | SD_DLLPUBLIC void Fill(const SdDrawDocument*, bool bAllPages, const OUString& rDocName); |
309 | | SD_DLLPUBLIC void Fill(const SdDrawDocument*, SfxMedium* pSfxMedium, const OUString& rDocName); |
310 | | |
311 | | void SetShowAllShapes (const bool bShowAllShapes, const bool bFill); |
312 | 0 | bool GetShowAllShapes() const { return m_bShowAllShapes; } |
313 | | |
314 | | void SetOrderFrontToBack (const bool bOrderFrontToBack); |
315 | 0 | bool GetOrderFrontToBack() const { return m_bOrderFrontToBack; } |
316 | | |
317 | 0 | bool IsNavigationGrabsFocus() const { return m_bNavigationGrabsFocus; } |
318 | | SD_DLLPUBLIC bool IsEqualToDoc(const SdDrawDocument* pInDoc); |
319 | | /// Visits rList recursively and tries to advance rEntry accordingly. |
320 | | bool IsEqualToShapeList(std::unique_ptr<weld::TreeIter>& rEntry, const SdrObjList& rList, |
321 | | std::u16string_view rListName); |
322 | | |
323 | | /** Return the view shell that is linked to the given doc shell. |
324 | | Call this method when the there is a chance that the doc shell |
325 | | has been disconnected from the view shell (but not the other |
326 | | way round.) |
327 | | @return |
328 | | May return <NULL/> when the link between view shell and |
329 | | doc shell has been severed. |
330 | | */ |
331 | | static ::sd::ViewShell* GetViewShellForDocShell (::sd::DrawDocShell &rDocShell); |
332 | | |
333 | | /** Add one list box entry for the parent of the given shapes and one child entry for |
334 | | each of the given shapes. |
335 | | @param rList |
336 | | The container of shapes that are to be inserted. |
337 | | @param pShape |
338 | | The parent shape or NULL when the parent is a page. |
339 | | @param rsName |
340 | | The name to be displayed for the new parent node. |
341 | | @param bIsExcluded |
342 | | Some pages can be excluded (from the show?). |
343 | | @param pParentEntry |
344 | | The parent entry of the new parent entry. |
345 | | */ |
346 | | void AddShapeList ( |
347 | | const SdrObjList& rList, |
348 | | const SdrObject* pShape, |
349 | | const OUString& rsName, |
350 | | const bool bIsExcluded, |
351 | | const weld::TreeIter* pParentEntry); |
352 | | |
353 | | /** Add the given object to a transferable object so that the object can |
354 | | be dragged and dropped without having a name. |
355 | | */ |
356 | | void AddShapeToTransferable ( |
357 | | SdTransferable& rTransferable, |
358 | | const SdrObject& rObject) const; |
359 | | |
360 | | /** return selected entries |
361 | | nDepth == 0 -> pages |
362 | | nDepth == 1 -> objects */ |
363 | | |
364 | | SD_DLLPUBLIC std::vector<OUString> GetSelectEntryList(const int nDepth) const; |
365 | | |
366 | | std::vector<OUString> GetSelectedEntryIds() const; |
367 | | |
368 | | SD_DLLPUBLIC SdDrawDocument* GetBookmarkDoc(SfxMedium* pMedium = nullptr); |
369 | | |
370 | 0 | bool IsLinkableSelected() const { return m_bLinkableSelected; } |
371 | | |
372 | | void InsertEntry(const OUString &rName, const OUString &rExpander) |
373 | 0 | { |
374 | 0 | m_xTreeView->insert(nullptr, -1, &rName, nullptr, nullptr, nullptr, false, m_xScratchIter.get()); |
375 | 0 | m_xTreeView->set_image(*m_xScratchIter, rExpander); |
376 | 0 | } |
377 | | |
378 | | void InsertEntry(const weld::TreeIter* pParent, const OUString& rId, const OUString &rName, const OUString &rExpander, weld::TreeIter* pEntry = nullptr) |
379 | 0 | { |
380 | 0 | if (pParent) |
381 | 0 | m_xTreeView->insert(pParent, m_bOrderFrontToBack ? 0 : -1, &rName, &rId, nullptr, |
382 | 0 | nullptr, false, m_xScratchIter.get()); |
383 | 0 | else |
384 | | // always append page/slide entry |
385 | 0 | m_xTreeView->insert(nullptr, -1, &rName, &rId, nullptr, nullptr, false, m_xScratchIter.get()); |
386 | 0 | m_xTreeView->set_image(*m_xScratchIter, rExpander); |
387 | 0 | if (pEntry) |
388 | 0 | m_xTreeView->copy_iterator(*m_xScratchIter, *pEntry); |
389 | 0 | } |
390 | | |
391 | | //Mark Current Entry |
392 | | void SetSdNavigator(SdNavigatorWin* pNavigator); |
393 | | |
394 | | void clear() |
395 | 0 | { |
396 | 0 | m_xTreeView->clear(); |
397 | 0 | } |
398 | | |
399 | | // nested class to implement the TransferableHelper |
400 | | class SdPageObjsTransferable final : public SdTransferable |
401 | | { |
402 | | public: |
403 | | SdPageObjsTransferable( |
404 | | INetBookmark aBookmark, |
405 | | ::sd::DrawDocShell& rDocShell, |
406 | | NavigatorDragType eDragType ); |
407 | 0 | ::sd::DrawDocShell& GetDocShell() const { return mrDocShell;} |
408 | 0 | NavigatorDragType GetDragType() const { return meDragType;} |
409 | | |
410 | | static SdPageObjsTransferable* getImplementation( const css::uno::Reference< css::uno::XInterface >& rxData ) noexcept; |
411 | | /** Return a temporary transferable data flavor that is used |
412 | | internally in the navigator for reordering entries. Its |
413 | | lifetime ends with the office application. |
414 | | */ |
415 | | static SotClipboardFormatId GetListBoxDropFormatId(); |
416 | | |
417 | | private: |
418 | | INetBookmark const maBookmark; |
419 | | ::sd::DrawDocShell& mrDocShell; |
420 | | NavigatorDragType const meDragType; |
421 | | virtual ~SdPageObjsTransferable() override; |
422 | | |
423 | | virtual void AddSupportedFormats() override; |
424 | | virtual bool GetData( const css::datatransfer::DataFlavor& rFlavor, const OUString& rDestDoc ) override; |
425 | | }; |
426 | | |
427 | | friend class SdPageObjsTLV::SdPageObjsTransferable; |
428 | | |
429 | | private: |
430 | | rtl::Reference<SdPageObjsTransferable> m_xHelper; |
431 | | }; |
432 | | |
433 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |