1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 #ifndef SD_SIDEBAR_PANELS_MASTER_PAGES_SELECTOR_HXX
23 #define SD_SIDEBAR_PANELS_MASTER_PAGES_SELECTOR_HXX
24 
25 #include "MasterPageContainer.hxx"
26 #include "SlideSorterViewShell.hxx"
27 #include "PreviewValueSet.hxx"
28 #include "ISidebarReceiver.hxx"
29 #include <sfx2/sidebar/ILayoutableWindow.hxx>
30 
31 #include "pres.hxx"
32 #include <sfx2/shell.hxx>
33 #include <vcl/image.hxx>
34 #include "glob.hxx"
35 #include <osl/mutex.hxx>
36 #include <com/sun/star/ui/XSidebar.hpp>
37 
38 #include <queue>
39 
40 namespace css = ::com::sun::star;
41 namespace cssu = ::com::sun::star::uno;
42 
43 class MouseEvent;
44 class SdDrawDocument;
45 class SdPage;
46 class SfxModule;
47 
48 namespace sd {
49 class DrawViewShell;
50 class TemplateEntry;
51 class TemplateDir;
52 class ViewShellBase;
53 }
54 
55 namespace sd { namespace sidebar {
56 
57 class PreviewValueSet;
58 class SidebarShellManager;
59 
60 
61 /** Base class of a menu that lets the user select from a list of
62     templates or designs that are loaded from files.
63 */
64 class MasterPagesSelector
65     : public PreviewValueSet,
66       public sfx2::sidebar::ILayoutableWindow
67 {
68 public:
69     MasterPagesSelector (
70         ::Window* pParent,
71         SdDrawDocument& rDocument,
72         ViewShellBase& rBase,
73         const ::boost::shared_ptr<MasterPageContainer>& rpContainer,
74         const cssu::Reference<css::ui::XSidebar>& rxSidebar);
75     virtual ~MasterPagesSelector (void);
76 
77     virtual void LateInit (void);
78 
79     /** Return the height that this control needs to show all of its lines.
80     */
81     long GetRequiredHeight (int nWidth) const;
82 
83     /** The given master page, either the master page of a slide or a notes
84         page, is cloned and inserted into mrDocument.  The necessary styles
85         are copied as well.
86     */
87     static SdPage* AddMasterPage (
88         SdDrawDocument* pTargetDocument,
89         SdPage* pMasterPage,
90         sal_uInt16 nInsertionIndex);
91 
92     virtual Size GetPreferredSize (void);
93     virtual sal_Int32 GetPreferredWidth (sal_Int32 nHeight);
94     virtual sal_Int32 GetPreferredHeight (sal_Int32 nWidth);
95     virtual bool IsResizable (void);
96     virtual ::Window* GetWindow (void);
97     virtual sal_Int32 GetMinimumWidth (void);
98 
99     /** Update the selection of previews according to whatever
100         influences them appart from mouse and keyboard.  If, for
101         example, the current page of the main pane changes, then call
102         this method at the CurrentMasterPagesSelector to select the
103         previews of the master pages that are assigned to the new
104         current page.
105 
106         The default implementation of this method ignores the call. This is
107         used by e.g. the RecentMasterPagesSelector because it does not show
108         the currently used master pages by default and thus is not
109         influenced by its changes.
110     */
111     virtual void UpdateSelection (void);
112 
113     void FillPageSet (void);
114 
115     /** Make the selector empty.  This method clear the value set from any
116         entries. Overload this method to add functionality, especially to
117         destroy objects set as data items at the value set.
118     */
119     void ClearPageSet (void);
120 
121 	void SetHelpId( const rtl::OString& aId );
122 
123     /** Mark the preview that belongs to the given index as not up-to-date
124         anymore with respect to page content or preview size.
125         The implementation of this method will either sunchronously or
126         asynchronously call UpdatePreview().
127         @param nIndex
128             Index into the value set control that is used for displaying the
129             previews.
130     */
131     void InvalidatePreview (const SdPage* pPage);
132 
133     void UpdateAllPreviews (void);
134 
135     // ILayoutableWindow
136     virtual css::ui::LayoutSize GetHeightForWidth (const sal_Int32 nWidth);
137 
138 protected:
139     mutable ::osl::Mutex maMutex;
140     ::boost::shared_ptr<MasterPageContainer> mpContainer;
141 
142     SdDrawDocument& mrDocument;
143     bool mbSmallPreviewSize;
144     ViewShellBase& mrBase;
145     /** Slot that is executed as default action when the left mouse button is
146         clicked over a master page.
147     */
148 	sal_uInt16 mnDefaultClickAction;
149     /** Pages with pointers in this queue have their previews updated
150         eventually.  Filled by InvalidatePreview() and operated upon by
151         UpdatePreviews().
152     */
153     ::std::queue<sal_uInt16> maPreviewUpdateQueue;
154 
155     virtual SdPage* GetSelectedMasterPage (void);
156 
157     /** Assign the given master page to all slides of the document.
158         @param pMasterPage
159             The master page to assign to all slides.
160     */
161     void AssignMasterPageToAllSlides (SdPage* pMasterPage);
162 
163     /** Assign the given master page to all slides that are selected in a
164         slide sorter that is displayed in the lef or center pane.  When both
165         panes display a slide sorter then the one in the center pane is
166         used.
167     */
168     void AssignMasterPageToSelectedSlides (SdPage* pMasterPage);
169 
170     virtual void AssignMasterPageToPageList (
171         SdPage* pMasterPage,
172         const ::sd::slidesorter::SharedPageSelection& rPageList);
173 
174     virtual void NotifyContainerChangeEvent (const MasterPageContainerChangeEvent& rEvent);
175 
176     typedef ::std::pair<int, MasterPageContainer::Token> UserData;
177     UserData* CreateUserData (int nIndex, MasterPageContainer::Token aToken) const;
178     UserData* GetUserData (int nIndex) const;
179     void SetUserData (int nIndex, UserData* pData);
180 
181     virtual sal_Int32 GetIndexForToken (MasterPageContainer::Token aToken) const;
182     typedef ::std::vector<MasterPageContainer::Token> ItemList;
183     void UpdateItemList (::std::auto_ptr<ItemList> pList);
184     void Clear (void);
185     /** Invalidate the specified item so that on the next Fill() this item
186         is updated.
187     */
188     void InvalidateItem (MasterPageContainer::Token aToken);
189 
190     // For every item in the ValueSet we store its associated token.  This
191     // allows a faster access and easier change tracking.
192     ItemList maCurrentItemList;
193     typedef ::std::map<MasterPageContainer::Token,sal_Int32> TokenToValueSetIndex;
194     TokenToValueSetIndex maTokenToValueSetIndex;
195 
196     ItemList maLockedMasterPages;
197     /** Lock master pages in the given list and release locks that where
198         previously aquired.
199     */
200     void UpdateLocks (const ItemList& rItemList);
201 
202     void Fill (void);
203     virtual void Fill (ItemList& rItemList) = 0;
204 
205     /** Give derived classes the oportunity to provide their own context
206         menu.  If they do then they probably have to provide their own
207         Execute() and GetState() methods as well.
208     */
209     virtual ResId GetContextMenuResId (void) const;
210 
211     virtual void Command (const CommandEvent& rEvent);
212 
213     virtual void ProcessPopupMenu (Menu& rMenu);
214     virtual void ExecuteCommand (const sal_Int32 nCommandId);
215 
216 private:
217     cssu::Reference<css::ui::XSidebar> mxSidebar;
218 
219     /** The offset between ValueSet index and MasterPageContainer::Token
220         last seen.  This value is used heuristically to speed up the lookup
221         of an index for a token.
222     */
223     DECL_LINK(ClickHandler, PreviewValueSet*);
224     DECL_LINK(RightClickHandler, MouseEvent*);
225     DECL_LINK(ContextMenuCallback, CommandEvent*);
226     DECL_LINK(ContainerChangeListener, MasterPageContainerChangeEvent*);
227     DECL_LINK(OnMenuItemSelected, Menu*);
228 
229     void SetItem (
230         sal_uInt16 nIndex,
231         MasterPageContainer::Token aToken);
232     void AddTokenToIndexEntry (
233         sal_uInt16 nIndex,
234         MasterPageContainer::Token aToken);
235     void RemoveTokenToIndexEntry (
236         sal_uInt16 nIndex,
237         MasterPageContainer::Token aToken);
238 };
239 
240 } } // end of namespace sd::sidebar
241 
242 #endif
243