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 <sal/config.h>
23 
24 #include <memory>
25 
26 #include <vcl/transfer.hxx>
27 #include <vcl/weld.hxx>
28 #include <CustomAnimationEffect.hxx>
29 
30 namespace com::sun::star::drawing { class XShape; }
31 
32 struct ImplSVEvent;
33 
34 namespace sd {
35 
36 typedef std::shared_ptr< CustomAnimationEffect > CustomAnimationEffectPtr;
37 
38 class ICustomAnimationListController
39 {
40 public:
41     virtual void onSelect() = 0;
42     virtual void onDoubleClick() = 0;
43     virtual void onContextMenu(const OString &rIdent) = 0;
44     virtual void onDragNDropComplete( std::vector< CustomAnimationEffectPtr > pEffectsDragged, CustomAnimationEffectPtr pEffectInsertBefore ) = 0;
~ICustomAnimationListController()45     virtual ~ICustomAnimationListController() {}
46 };
47 
48 class CustomAnimationList;
49 class CustomAnimationListEntryItem;
50 
51 class CustomAnimationListDropTarget : public DropTargetHelper
52 {
53 private:
54     CustomAnimationList& m_rTreeView;
55 
56     virtual sal_Int8 AcceptDrop( const AcceptDropEvent& rEvt ) override;
57     virtual sal_Int8 ExecuteDrop( const ExecuteDropEvent& rEvt ) override;
58 
59 public:
60     CustomAnimationListDropTarget(CustomAnimationList& rTreeView);
61 };
62 
63 class CustomAnimationList : public ISequenceListener
64 {
65     friend class CustomAnimationListEntryItem;
66     friend struct stl_append_effect_func;
67 
68 public:
69     explicit CustomAnimationList(std::unique_ptr<weld::TreeView> xTreeView,
70                                  std::unique_ptr<weld::Label> xLabel,
71                                  std::unique_ptr<weld::Widget> xScrolledWindow);
72     virtual ~CustomAnimationList();
73 
74     // methods
75 
76     /** selects or deselects the given effect.
77         Selections of other effects are not changed */
78     void select( const CustomAnimationEffectPtr& pEffect );
79 
80     /** populates the list with all effects from the given MainSequence */
81     void update( const MainSequencePtr& pMainSequence );
82 
83     void update();
84 
85     EffectSequence getSelection() const;
86 
87     // events
88     void onSelectionChanged(const css::uno::Any& rSelection);
89 
90     void Select();
91 
92     virtual void notify_change() override;
93 
94     bool isExpanded( const CustomAnimationEffectPtr& pEffect ) const;
95     bool isVisible( const CustomAnimationEffectPtr& pEffect ) const;
96 
97     // clears all entries from the listbox
98     void clear();
99 
setController(ICustomAnimationListController * pController)100     void setController( ICustomAnimationListController* pController )
101     {
102         mpController = pController;
103     };
104 
105     sal_Int8     AcceptDrop(const AcceptDropEvent& rEvt);
106     sal_Int8     ExecuteDrop(const ExecuteDropEvent& rEvt);
107 
set_sensitive(bool bSensitive)108     void set_sensitive(bool bSensitive) { mxTreeView->set_sensitive(bSensitive); }
get_height_rows(int nRows)109     int get_height_rows(int nRows) { return mxTreeView->get_height_rows(nRows); }
get_approximate_digit_width() const110     int get_approximate_digit_width() const { return mxTreeView->get_approximate_digit_width(); }
set_size_request(int nWidth,int nHeight)111     void set_size_request(int nWidth, int nHeight)
112     {
113         mxTreeView->set_size_request(nWidth, nHeight);
114         mxEmptyLabel->set_size_request(nWidth, nHeight);
115     }
unselect_all()116     void unselect_all() { mxTreeView->unselect_all(); }
get_widget()117     weld::TreeView& get_widget() { return *mxTreeView; }
118 
119     DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
120     DECL_LINK(ExpandHdl, const weld::TreeIter&, bool);
121     DECL_LINK(PostExpandHdl, void*, void);
122     DECL_LINK(CollapseHdl, const weld::TreeIter&, bool);
123     DECL_LINK(PostCollapseHdl, void*, void);
124 
125 private:
126     std::unique_ptr<weld::TreeView> mxTreeView;
127     CustomAnimationListDropTarget maDropTargetHelper;
128     std::unique_ptr<weld::Label> mxEmptyLabel;
129     std::unique_ptr<weld::Widget> mxEmptyLabelParent;
130     std::vector<std::unique_ptr<CustomAnimationListEntryItem>> mxEntries;
131     std::vector<std::unique_ptr<weld::TreeIter>> lastSelectedEntries;
132 
133     bool    mbIgnorePaint;
134 
135     DECL_LINK(SelectHdl, weld::TreeView&, void);
136     DECL_LINK(CommandHdl, const CommandEvent&, bool);
137     DECL_LINK(DoubleClickHdl, weld::TreeView&, bool);
138     DECL_LINK(DragBeginHdl, bool&, bool);
139     DECL_STATIC_LINK(CustomAnimationList, CustomRenderHdl, weld::TreeView::render_args, void);
140     DECL_STATIC_LINK(CustomAnimationList, CustomGetSizeHdl, weld::TreeView::get_size_args, Size);
141 
142     void ExecuteContextMenuAction(const OString& rSelectedPopupEntry);
143 
144     /** appends the given effect to the list*/
145     void append( CustomAnimationEffectPtr pEffect );
146 
147     ICustomAnimationListController* mpController;
148 
149     MainSequencePtr mpMainSequence;
150 
151     css::uno::Reference< css::drawing::XShape > mxLastTargetShape;
152     sal_Int32 mnLastGroupId;
153     ImplSVEvent* mnPostExpandEvent;
154     ImplSVEvent* mnPostCollapseEvent;
155 
156     std::unique_ptr<weld::TreeIter> mxLastParentEntry;
157 
158     // drag & drop
159     std::unique_ptr<weld::TreeIter> mxDndEffectDragging;
160     std::vector<std::unique_ptr<weld::TreeIter>> mDndEffectsSelected;
161 };
162 
163 OUString getPropertyName( sal_Int32 nPropertyType );
164 
165 OUString getShapeDescription( const css::uno::Reference< css::drawing::XShape >& xShape, bool bWithText );
166 
167 }
168 
169 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
170