1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 "MasterPageContainer.hxx"
24 #include "SlideSorterViewShell.hxx"
25 #include "PreviewValueSet.hxx"
26 #include "ISidebarReceiver.hxx"
27 #include <sfx2/sidebar/ILayoutableWindow.hxx>
30 #include <sfx2/shell.hxx>
31 #include <vcl/image.hxx>
33 #include <osl/mutex.hxx>
34 #include <com/sun/star/ui/XSidebar.hpp>
47 namespace sd
{ namespace sidebar
{
49 class PreviewValueSet
;
51 /** Base class of a menu that lets the user select from a list of
52 templates or designs that are loaded from files.
54 class MasterPagesSelector
55 : public PreviewValueSet
,
56 public sfx2::sidebar::ILayoutableWindow
61 SdDrawDocument
& rDocument
,
63 const ::boost::shared_ptr
<MasterPageContainer
>& rpContainer
,
64 const css::uno::Reference
<css::ui::XSidebar
>& rxSidebar
);
65 virtual ~MasterPagesSelector();
66 virtual void dispose() SAL_OVERRIDE
;
68 virtual void LateInit();
70 /** Return the height that this control needs to show all of its lines.
72 long GetRequiredHeight (int nWidth
) const;
74 /** The given master page, either the master page of a slide or a notes
75 page, is cloned and inserted into mrDocument. The necessary styles
78 static SdPage
* AddMasterPage (
79 SdDrawDocument
* pTargetDocument
,
81 sal_uInt16 nInsertionIndex
);
83 sal_Int32
GetPreferredHeight (sal_Int32 nWidth
);
85 /** Update the selection of previews according to whatever
86 influences them apart from mouse and keyboard. If, for
87 example, the current page of the main pane changes, then call
88 this method at the CurrentMasterPagesSelector to select the
89 previews of the master pages that are assigned to the new
92 The default implementation of this method ignores the call. This is
93 used by e.g. the RecentMasterPagesSelector because it does not show
94 the currently used master pages by default and thus is not
95 influenced by its changes.
97 virtual void UpdateSelection();
101 /** Make the selector empty. This method clear the value set from any
102 entries. Override this method to add functionality, especially to
103 destroy objects set as data items at the value set.
107 void SetHelpId( const OString
& aId
);
109 /** Mark the preview that belongs to the given index as not up-to-date
110 anymore with respect to page content or preview size.
111 The implementation of this method will either sunchronously or
112 asynchronously call UpdatePreview().
114 Index into the value set control that is used for displaying the
117 void InvalidatePreview (const SdPage
* pPage
);
119 void UpdateAllPreviews();
122 virtual css::ui::LayoutSize
GetHeightForWidth (const sal_Int32 nWidth
) SAL_OVERRIDE
;
125 mutable ::osl::Mutex maMutex
;
126 ::boost::shared_ptr
<MasterPageContainer
> mpContainer
;
128 SdDrawDocument
& mrDocument
;
129 bool mbSmallPreviewSize
;
130 ViewShellBase
& mrBase
;
131 /** Slot that is executed as default action when the left mouse button is
132 clicked over a master page.
134 sal_uInt16 mnDefaultClickAction
;
135 /** Pages with pointers in this queue have their previews updated
136 eventually. Filled by InvalidatePreview() and operated upon by
139 ::std::queue
<sal_uInt16
> maPreviewUpdateQueue
;
141 SdPage
* GetSelectedMasterPage();
143 /** Assign the given master page to all slides of the document.
145 The master page to assign to all slides.
147 void AssignMasterPageToAllSlides (SdPage
* pMasterPage
);
149 /** Assign the given master page to all slides that are selected in a
150 slide sorter that is displayed in the lef or center pane. When both
151 panes display a slide sorter then the one in the center pane is
154 void AssignMasterPageToSelectedSlides (SdPage
* pMasterPage
);
156 virtual void AssignMasterPageToPageList (
158 const ::sd::slidesorter::SharedPageSelection
& rPageList
);
160 virtual void NotifyContainerChangeEvent (const MasterPageContainerChangeEvent
& rEvent
);
162 typedef ::std::pair
<int, MasterPageContainer::Token
> UserData
;
163 static UserData
* CreateUserData (int nIndex
, MasterPageContainer::Token aToken
);
164 UserData
* GetUserData (int nIndex
) const;
165 void SetUserData (int nIndex
, UserData
* pData
);
167 sal_Int32
GetIndexForToken (MasterPageContainer::Token aToken
) const;
168 typedef ::std::vector
<MasterPageContainer::Token
> ItemList
;
169 void UpdateItemList (::std::unique_ptr
<ItemList
> && pList
);
171 /** Invalidate the specified item so that on the next Fill() this item
174 void InvalidateItem (MasterPageContainer::Token aToken
);
176 // For every item in the ValueSet we store its associated token. This
177 // allows a faster access and easier change tracking.
178 ItemList maCurrentItemList
;
179 typedef ::std::map
<MasterPageContainer::Token
,sal_Int32
> TokenToValueSetIndex
;
180 TokenToValueSetIndex maTokenToValueSetIndex
;
182 ItemList maLockedMasterPages
;
183 /** Lock master pages in the given list and release locks that where
186 void UpdateLocks (const ItemList
& rItemList
);
189 virtual void Fill (ItemList
& rItemList
) = 0;
191 /** Give derived classes the opportunity to provide their own context
192 menu. If they do then they probably have to provide their own
193 Execute() and GetState() methods as well.
195 virtual ResId
GetContextMenuResId() const;
197 virtual void Command (const CommandEvent
& rEvent
) SAL_OVERRIDE
;
199 virtual void ProcessPopupMenu (Menu
& rMenu
);
200 virtual void ExecuteCommand (const sal_Int32 nCommandId
);
203 css::uno::Reference
<css::ui::XSidebar
> mxSidebar
;
205 /** The offset between ValueSet index and MasterPageContainer::Token
206 last seen. This value is used heuristically to speed up the lookup
207 of an index for a token.
209 DECL_LINK(ClickHandler
, void *);
210 DECL_LINK(RightClickHandler
, MouseEvent
*);
211 DECL_LINK(ContextMenuCallback
, CommandEvent
*);
212 DECL_LINK(ContainerChangeListener
, MasterPageContainerChangeEvent
*);
213 DECL_LINK(OnMenuItemSelected
, Menu
*);
217 MasterPageContainer::Token aToken
);
218 void AddTokenToIndexEntry (
220 MasterPageContainer::Token aToken
);
221 void RemoveTokenToIndexEntry (
223 MasterPageContainer::Token aToken
);
226 } } // end of namespace sd::sidebar
230 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */