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