Get the style color and number just once
[LibreOffice.git] / sd / source / ui / sidebar / MasterPagesSelector.hxx
blobb1c92b5d1c55923b6717e8e7cdc4b29c5d11c028
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #pragma once
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.hxx>
29 #include <sfx2/sidebar/ILayoutableWindow.hxx>
30 #include <sfx2/sidebar/PanelLayout.hxx>
32 #include <osl/mutex.hxx>
34 namespace com::sun::star::ui { class XSidebar; }
35 class MouseEvent;
36 class SdDrawDocument;
37 class SdPage;
39 namespace sd {
40 class ViewShellBase;
43 namespace sd::sidebar {
45 /** Base class of a menu that lets the user select from a list of
46 templates or designs that are loaded from files.
48 class MasterPagesSelector : public PanelLayout
49 , public sfx2::sidebar::ILayoutableWindow
51 public:
52 MasterPagesSelector(weld::Widget* pParent, SdDrawDocument& rDocument, ViewShellBase& rBase,
53 std::shared_ptr<MasterPageContainer> pContainer,
54 css::uno::Reference<css::ui::XSidebar> xSidebar,
55 const OUString& rUIFileName, const OUString& rIconViewId);
56 virtual ~MasterPagesSelector() override;
58 virtual void LateInit();
60 sal_Int32 GetPreferredHeight (sal_Int32 nWidth);
62 /** Make the selector empty. This method clear the value set from any
63 entries. Override this method to add functionality, especially to
64 destroy objects set as data items at the value set.
66 void ClearPageSet();
68 void SetHelpId( const OUString& aId );
70 /** Mark the preview that belongs to the given index as not up-to-date
71 anymore with respect to page content or preview size.
72 The implementation of this method will either sunchronously or
73 asynchronously call UpdatePreview().
74 @param nIndex
75 Index into the value set control that is used for displaying the
76 previews.
78 void InvalidatePreview (const SdPage* pPage);
80 void UpdateAllPreviews();
82 void ShowContextMenu(const Point& pPos);
84 // ILayoutableWindow
85 virtual css::ui::LayoutSize GetHeightForWidth (const sal_Int32 nWidth) override;
87 protected:
88 mutable ::osl::Mutex maMutex;
89 std::shared_ptr<MasterPageContainer> mpContainer;
91 std::unique_ptr<weld::IconView> mxPreviewIconView;
93 SdDrawDocument& mrDocument;
94 ViewShellBase& mrBase;
96 SdPage* GetSelectedMasterPage();
98 /** Assign the given master page to all slides of the document.
99 @param pMasterPage
100 The master page to assign to all slides.
102 void AssignMasterPageToAllSlides (SdPage* pMasterPage);
104 /** Assign the given master page to all slides that are selected in a
105 slide sorter that is displayed in the lef or center pane. When both
106 panes display a slide sorter then the one in the center pane is
107 used.
109 void AssignMasterPageToSelectedSlides (SdPage* pMasterPage);
111 virtual void AssignMasterPageToPageList (
112 SdPage* pMasterPage,
113 const std::shared_ptr<std::vector<SdPage*>>& rPageList);
115 virtual void NotifyContainerChangeEvent (const MasterPageContainerChangeEvent& rEvent);
117 typedef ::std::pair<int, MasterPageContainer::Token> UserData;
118 std::unique_ptr<MasterPagesSelector::UserData> GetUserData(int nIndex) const;
120 sal_Int32 GetIndexForToken (MasterPageContainer::Token aToken) const;
121 typedef ::std::vector<MasterPageContainer::Token> ItemList;
122 void UpdateItemList (::std::unique_ptr<ItemList> && pList);
123 void Clear();
124 /** Invalidate the specified item so that on the next Fill() this item
125 is updated.
127 void InvalidateItem (MasterPageContainer::Token aToken);
129 // For every item in the ValueSet we store its associated token. This
130 // allows a faster access and easier change tracking.
131 ItemList maCurrentItemList;
132 typedef ::std::map<MasterPageContainer::Token,sal_Int32> TokenToValueSetIndex;
133 TokenToValueSetIndex maTokenToValueSetIndex;
135 ItemList maLockedMasterPages;
136 /** Lock master pages in the given list and release locks that were
137 previously acquired.
139 void UpdateLocks (const ItemList& rItemList);
141 void Fill();
142 virtual void Fill (ItemList& rItemList) = 0;
144 /** Give derived classes the opportunity to provide their own context
145 menu. If they do then they probably have to provide their own
146 Execute() and GetState() methods as well.
148 virtual OUString GetContextMenuUIFile() const;
150 virtual void ProcessPopupMenu(weld::Menu& rMenu);
151 virtual void ExecuteCommand(const OUString& rIdent);
153 private:
154 css::uno::Reference<css::ui::XSidebar> mxSidebar;
155 OUString maIconViewId;
157 /** The offset between ValueSet index and MasterPageContainer::Token
158 last seen. This value is used heuristically to speed up the lookup
159 of an index for a token.
161 DECL_LINK(MasterPageSelected, weld::IconView&, bool);
162 DECL_LINK(MousePressHdl, const MouseEvent&, bool);
163 DECL_LINK(ContainerChangeListener, MasterPageContainerChangeEvent&, void);
164 DECL_LINK(QueryTooltipHdl, const weld::TreeIter&, OUString);
166 void SetItem (
167 sal_uInt16 nIndex,
168 MasterPageContainer::Token aToken);
169 void AddTokenToIndexEntry (
170 sal_uInt16 nIndex,
171 MasterPageContainer::Token aToken);
172 void RemoveTokenToIndexEntry (
173 sal_uInt16 nIndex,
174 MasterPageContainer::Token aToken);
176 static VclPtr<VirtualDevice> GetVirtualDevice(const Image& rPreview);
179 } // end of namespace sd::sidebar
181 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */