/src/libreoffice/sd/source/ui/sidebar/MasterPagesSelector.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 <map> |
23 | | #include <memory> |
24 | | #include "MasterPageContainer.hxx" |
25 | | #include <vcl/image.hxx> |
26 | | #include <vcl/vclptr.hxx> |
27 | | #include <vcl/virdev.hxx> |
28 | | #include <vcl/weld/IconView.hxx> |
29 | | #include <vcl/weld/Menu.hxx> |
30 | | #include <vcl/idle.hxx> |
31 | | #include <sfx2/sidebar/PanelLayout.hxx> |
32 | | |
33 | | #include <osl/mutex.hxx> |
34 | | |
35 | | namespace com::sun::star::ui { class XSidebar; } |
36 | | class MouseEvent; |
37 | | class SdDrawDocument; |
38 | | class SdPage; |
39 | | |
40 | | namespace sd { |
41 | | class ViewShellBase; |
42 | | } |
43 | | |
44 | | namespace sd::sidebar { |
45 | | |
46 | | /** Base class of a menu that lets the user select from a list of |
47 | | templates or designs that are loaded from files. |
48 | | */ |
49 | | class MasterPagesSelector : public PanelLayout |
50 | | { |
51 | | class UpdateTask final : public Idle |
52 | | { |
53 | | MasterPagesSelector& m_rContainer; |
54 | | |
55 | | public: |
56 | | UpdateTask(MasterPagesSelector& rStylesList) |
57 | 0 | : Idle("MasterPagesUpdateTask") |
58 | 0 | , m_rContainer(rStylesList) |
59 | 0 | { |
60 | 0 | SetPriority(TaskPriority::DEFAULT_IDLE); |
61 | 0 | } |
62 | | |
63 | 0 | virtual void Invoke() override { m_rContainer.LateInit(); } |
64 | | }; |
65 | | |
66 | | public: |
67 | | // Sidebar |
68 | | MasterPagesSelector(weld::Widget* pParent, SdDrawDocument& rDocument, ViewShellBase& rBase, |
69 | | std::shared_ptr<MasterPageContainer> pContainer, |
70 | | css::uno::Reference<css::ui::XSidebar> xSidebar, |
71 | | const OUString& rUIFileName, const OUString& rIconViewId); |
72 | | |
73 | | // Notebookbar |
74 | | MasterPagesSelector(weld::Widget* pParent, SdDrawDocument& rDocument, ViewShellBase& rBase, |
75 | | std::shared_ptr<MasterPageContainer> pContainer, |
76 | | const OUString& rUIFileName, const OUString& rIconViewId); |
77 | | |
78 | | virtual ~MasterPagesSelector() override; |
79 | | |
80 | | virtual void LateInit(); |
81 | | |
82 | | /** Make the selector empty. This method clears the value set from any |
83 | | entries. Override this method to add functionality, especially to |
84 | | destroy objects set as data items at the value set. |
85 | | */ |
86 | | void ClearPageSet(); |
87 | | |
88 | | void SetHelpId( const OUString& aId ); |
89 | | |
90 | | /** Mark the preview that belongs to the given index as not up-to-date |
91 | | anymore with respect to page content or preview size. |
92 | | The implementation of this method will either synchronously or |
93 | | asynchronously call UpdatePreview(). |
94 | | @param nIndex |
95 | | Index into the value set control that is used for displaying the |
96 | | previews. |
97 | | */ |
98 | | void InvalidatePreview (const SdPage* pPage); |
99 | | |
100 | | void UpdateAllPreviews(); |
101 | | |
102 | | void ShowContextMenu(const Point& pPos); |
103 | | |
104 | | virtual css::ui::LayoutSize GetHeightForWidth (const sal_Int32 nWidth) override; |
105 | | |
106 | | protected: |
107 | | mutable ::osl::Mutex maMutex; |
108 | | std::shared_ptr<MasterPageContainer> mpContainer; |
109 | | |
110 | | std::unique_ptr<weld::IconView> mxPreviewIconView; |
111 | | |
112 | | SdDrawDocument& mrDocument; |
113 | | ViewShellBase& mrBase; |
114 | | |
115 | | SdPage* GetSelectedMasterPage(); |
116 | | |
117 | | /** Assign the given master page to all slides of the document. |
118 | | @param pMasterPage |
119 | | The master page to assign to all slides. |
120 | | */ |
121 | | void AssignMasterPageToAllSlides (SdPage* pMasterPage); |
122 | | |
123 | | /** Assign the given master page to all slides that are selected in a |
124 | | slide sorter that is displayed in the left or center pane. When both |
125 | | panes display a slide sorter then the one in the center pane is |
126 | | used. |
127 | | */ |
128 | | void AssignMasterPageToSelectedSlides (SdPage* pMasterPage); |
129 | | |
130 | | void AssignMasterPageToPageList ( |
131 | | SdPage* pMasterPage, |
132 | | const std::shared_ptr<std::vector<SdPage*>>& rPageList); |
133 | | |
134 | | virtual void NotifyContainerChangeEvent (const MasterPageContainerChangeEvent& rEvent); |
135 | | |
136 | | typedef ::std::pair<int, MasterPageContainer::Token> UserData; |
137 | | std::unique_ptr<MasterPagesSelector::UserData> GetUserData(int nIndex) const; |
138 | | |
139 | | sal_Int32 GetIndexForToken (MasterPageContainer::Token aToken) const; |
140 | | typedef ::std::vector<MasterPageContainer::Token> ItemList; |
141 | | void UpdateItemList (::std::unique_ptr<ItemList> && pList); |
142 | | void Clear(); |
143 | | /** Invalidate the specified item so that on the next Fill() this item |
144 | | is updated. |
145 | | */ |
146 | | void InvalidateItem (MasterPageContainer::Token aToken); |
147 | | |
148 | | // For every item in the ValueSet we store its associated token. This |
149 | | // allows a faster access and easier change tracking. |
150 | | ItemList maCurrentItemList; |
151 | | typedef ::std::map<MasterPageContainer::Token,sal_Int32> TokenToValueSetIndex; |
152 | | TokenToValueSetIndex maTokenToValueSetIndex; |
153 | | |
154 | | ItemList maLockedMasterPages; |
155 | | /** Lock master pages in the given list and release locks that were |
156 | | previously acquired. |
157 | | */ |
158 | | void UpdateLocks (const ItemList& rItemList); |
159 | | |
160 | | void Fill(); |
161 | | virtual void Fill (ItemList& rItemList) = 0; |
162 | | |
163 | | /** Give derived classes the opportunity to provide their own context |
164 | | menu. If they do then they probably have to provide their own |
165 | | Execute() and GetState() methods as well. |
166 | | */ |
167 | | virtual OUString GetContextMenuUIFile() const; |
168 | | |
169 | | virtual void ProcessPopupMenu(weld::Menu& rMenu); |
170 | | virtual void ExecuteCommand(const OUString& rIdent); |
171 | | |
172 | | private: |
173 | | css::uno::Reference<css::ui::XSidebar> mxSidebar; |
174 | | UpdateTask maUpdateTask; |
175 | | |
176 | | /** The offset between ValueSet index and MasterPageContainer::Token |
177 | | last seen. This value is used heuristically to speed up the lookup |
178 | | of an index for a token. |
179 | | */ |
180 | | DECL_LINK(MasterPageSelected, const weld::TreeIter&, bool); |
181 | | DECL_LINK(CommandHdl, const CommandEvent&, bool); |
182 | | DECL_LINK(ContainerChangeListener, MasterPageContainerChangeEvent&, void); |
183 | | DECL_LINK(QueryTooltipHdl, const weld::TreeIter&, OUString); |
184 | | |
185 | | void SetItem ( |
186 | | sal_uInt16 nIndex, |
187 | | MasterPageContainer::Token aToken); |
188 | | void AddTokenToIndexEntry ( |
189 | | sal_uInt16 nIndex, |
190 | | MasterPageContainer::Token aToken); |
191 | | void RemoveTokenToIndexEntry ( |
192 | | sal_uInt16 nIndex, |
193 | | MasterPageContainer::Token aToken); |
194 | | |
195 | | static ScopedVclPtr<VirtualDevice> GetVirtualDevice(const Image& rPreview); |
196 | | static Bitmap GetPreviewAsBitmap(const Image& rPreview); |
197 | | }; |
198 | | |
199 | | } // end of namespace sd::sidebar |
200 | | |
201 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |