Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / sd / source / ui / sidebar / MasterPagesSelector.hxx
blob05c4461934c19f7a380795470b6d246cdbafe936
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 #ifndef INCLUDED_SD_SOURCE_UI_SIDEBAR_MASTERPAGESSELECTOR_HXX
21 #define INCLUDED_SD_SOURCE_UI_SIDEBAR_MASTERPAGESSELECTOR_HXX
23 #include <memory>
24 #include "MasterPageContainer.hxx"
25 #include <SlideSorterViewShell.hxx>
26 #include "PreviewValueSet.hxx"
27 #include "ISidebarReceiver.hxx"
28 #include <sfx2/sidebar/ILayoutableWindow.hxx>
30 #include <pres.hxx>
31 #include <sfx2/shell.hxx>
32 #include <vcl/image.hxx>
33 #include <glob.hxx>
34 #include <osl/mutex.hxx>
35 #include <com/sun/star/ui/XSidebar.hpp>
37 #include <queue>
40 class MouseEvent;
41 class SdDrawDocument;
42 class SdPage;
44 namespace sd {
45 class ViewShellBase;
48 namespace sd { namespace sidebar {
50 class PreviewValueSet;
52 /** Base class of a menu that lets the user select from a list of
53 templates or designs that are loaded from files.
55 class MasterPagesSelector
56 : public PreviewValueSet,
57 public sfx2::sidebar::ILayoutableWindow
59 public:
60 MasterPagesSelector (
61 vcl::Window* pParent,
62 SdDrawDocument& rDocument,
63 ViewShellBase& rBase,
64 const std::shared_ptr<MasterPageContainer>& rpContainer,
65 const css::uno::Reference<css::ui::XSidebar>& rxSidebar);
66 virtual ~MasterPagesSelector() override;
67 virtual void dispose() override;
69 virtual void LateInit();
71 sal_Int32 GetPreferredHeight (sal_Int32 nWidth);
73 /** Make the selector empty. This method clear the value set from any
74 entries. Override this method to add functionality, especially to
75 destroy objects set as data items at the value set.
77 void ClearPageSet();
79 void SetHelpId( const OString& aId );
81 /** Mark the preview that belongs to the given index as not up-to-date
82 anymore with respect to page content or preview size.
83 The implementation of this method will either sunchronously or
84 asynchronously call UpdatePreview().
85 @param nIndex
86 Index into the value set control that is used for displaying the
87 previews.
89 void InvalidatePreview (const SdPage* pPage);
91 void UpdateAllPreviews();
93 // ILayoutableWindow
94 virtual css::ui::LayoutSize GetHeightForWidth (const sal_Int32 nWidth) override;
96 protected:
97 mutable ::osl::Mutex maMutex;
98 std::shared_ptr<MasterPageContainer> mpContainer;
100 SdDrawDocument& mrDocument;
101 ViewShellBase& mrBase;
102 /** menu entry that is executed as default action when the left mouse button is
103 clicked over a master page.
105 OString msDefaultClickAction;
107 SdPage* GetSelectedMasterPage();
109 /** Assign the given master page to all slides of the document.
110 @param pMasterPage
111 The master page to assign to all slides.
113 void AssignMasterPageToAllSlides (SdPage* pMasterPage);
115 /** Assign the given master page to all slides that are selected in a
116 slide sorter that is displayed in the lef or center pane. When both
117 panes display a slide sorter then the one in the center pane is
118 used.
120 void AssignMasterPageToSelectedSlides (SdPage* pMasterPage);
122 virtual void AssignMasterPageToPageList (
123 SdPage* pMasterPage,
124 const ::sd::slidesorter::SharedPageSelection& rPageList);
126 virtual void NotifyContainerChangeEvent (const MasterPageContainerChangeEvent& rEvent);
128 typedef ::std::pair<int, MasterPageContainer::Token> UserData;
129 UserData* GetUserData (int nIndex) const;
130 void SetUserData (int nIndex, UserData* pData);
132 sal_Int32 GetIndexForToken (MasterPageContainer::Token aToken) const;
133 typedef ::std::vector<MasterPageContainer::Token> ItemList;
134 void UpdateItemList (::std::unique_ptr<ItemList> && pList);
135 void Clear();
136 /** Invalidate the specified item so that on the next Fill() this item
137 is updated.
139 void InvalidateItem (MasterPageContainer::Token aToken);
141 // For every item in the ValueSet we store its associated token. This
142 // allows a faster access and easier change tracking.
143 ItemList maCurrentItemList;
144 typedef ::std::map<MasterPageContainer::Token,sal_Int32> TokenToValueSetIndex;
145 TokenToValueSetIndex maTokenToValueSetIndex;
147 ItemList maLockedMasterPages;
148 /** Lock master pages in the given list and release locks that where
149 previously acquired.
151 void UpdateLocks (const ItemList& rItemList);
153 void Fill();
154 virtual void Fill (ItemList& rItemList) = 0;
156 /** Give derived classes the opportunity to provide their own context
157 menu. If they do then they probably have to provide their own
158 Execute() and GetState() methods as well.
160 virtual OUString GetContextMenuUIFile() const;
162 virtual void Command (const CommandEvent& rEvent) override;
164 virtual void ProcessPopupMenu (Menu& rMenu);
165 virtual void ExecuteCommand(const OString& rIdent);
167 private:
168 css::uno::Reference<css::ui::XSidebar> mxSidebar;
170 /** The offset between ValueSet index and MasterPageContainer::Token
171 last seen. This value is used heuristically to speed up the lookup
172 of an index for a token.
174 DECL_LINK(ClickHandler, ValueSet*, void);
175 DECL_LINK(RightClickHandler, const MouseEvent&, void);
176 DECL_LINK(ContainerChangeListener, MasterPageContainerChangeEvent&, void);
177 DECL_LINK(OnMenuItemSelected, Menu*, bool);
179 void SetItem (
180 sal_uInt16 nIndex,
181 MasterPageContainer::Token aToken);
182 void AddTokenToIndexEntry (
183 sal_uInt16 nIndex,
184 MasterPageContainer::Token aToken);
185 void RemoveTokenToIndexEntry (
186 sal_uInt16 nIndex,
187 MasterPageContainer::Token aToken);
190 } } // end of namespace sd::sidebar
192 #endif
194 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */