Update ooo320-m1
[ooovba.git] / sd / source / ui / toolpanel / controls / MasterPagesSelector.hxx
blob14434df88dda607bb36ee0f0b7e20893e2c764a4
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: MasterPagesSelector.hxx,v $
10 * $Revision: 1.13 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef SD_TASKPANE_CONTROLS_MASTER_PAGES_SELECTOR_HXX
32 #define SD_TASKPANE_CONTROLS_MASTER_PAGES_SELECTOR_HXX
34 #include "taskpane/TaskPaneTreeNode.hxx"
35 #include "MasterPageContainer.hxx"
36 #include "SlideSorterViewShell.hxx"
38 #include "pres.hxx"
39 #include <sfx2/shell.hxx>
40 #include <vcl/image.hxx>
41 #include "glob.hxx"
42 #include <osl/mutex.hxx>
44 #include <queue>
46 class MouseEvent;
47 class SdDrawDocument;
48 class SdPage;
49 class SfxModule;
51 namespace sd {
52 class DrawViewShell;
53 class TemplateEntry;
54 class TemplateDir;
55 class ViewShellBase;
58 namespace sd { namespace toolpanel { namespace controls {
60 class PreviewValueSet;
62 /** Base class of a menu that lets the user select from a list of
63 templates or designs that are loaded from files.
65 class MasterPagesSelector
66 : public TreeNode,
67 public SfxShell
69 public:
70 TYPEINFO();
71 SFX_DECL_INTERFACE(SD_IF_SDMASTERPAGESSELECTOR)
73 MasterPagesSelector (
74 TreeNode* pParent,
75 SdDrawDocument& rDocument,
76 ViewShellBase& rBase,
77 const ::boost::shared_ptr<MasterPageContainer>& rpContainer);
78 virtual ~MasterPagesSelector (void);
80 virtual void LateInit (void);
82 /** Return the height that this control needs to show all of its lines.
84 long GetRequiredHeight (int nWidth) const;
86 /** The given master page, either the master page of a slide or a notes
87 page, is cloned and inserted into mrDocument. The necessary styles
88 are copied as well.
90 static SdPage* AddMasterPage (
91 SdDrawDocument* pTargetDocument,
92 SdPage* pMasterPage,
93 USHORT nInsertionIndex);
95 virtual Size GetPreferredSize (void);
96 virtual sal_Int32 GetPreferredWidth (sal_Int32 nHeight);
97 virtual sal_Int32 GetPreferredHeight (sal_Int32 nWidth);
98 virtual bool IsResizable (void);
99 virtual ::Window* GetWindow (void);
100 virtual sal_Int32 GetMinimumWidth (void);
102 virtual void Execute (SfxRequest& rRequest);
103 virtual void GetState (SfxItemSet& rItemSet);
105 /** Update the selection of previews according to whatever
106 influences them appart from mouse and keyboard. If, for
107 example, the current page of the main pane changes, then call
108 this method at the CurrentMasterPagesSelector to select the
109 previews of the master pages that are assigned to the new
110 current page.
112 The default implementation of this method ignores the call. This is
113 used by e.g. the RecentMasterPagesSelector because it does not show
114 the currently used master pages by default and thus is not
115 influenced by its changes.
117 virtual void UpdateSelection (void);
119 void FillPageSet (void);
121 /** Make the selector empty. This method clear the value set from any
122 entries. Overload this method to add functionality, especially to
123 destroy objects set as data items at the value set.
125 void ClearPageSet (void);
127 void SetSmartHelpId( const SmartId& aId, SmartIdUpdateMode aMode = SMART_SET_SMART );
129 /** Mark the preview that belongs to the given index as not up-to-date
130 anymore with respect to page content or preview size.
131 The implementation of this method will either sunchronously or
132 asynchronously call UpdatePreview().
133 @param nIndex
134 Index into the value set control that is used for displaying the
135 previews.
137 void InvalidatePreview (MasterPageContainer::Token aToken);
138 void InvalidatePreview (const SdPage* pPage);
140 /** Mark all previews as no being up-to-date anymore. This method is
141 typically called when the size of the previews has changed.
143 void InvalidateAllPreviews (void);
145 void UpdateAllPreviews (void);
147 protected:
148 mutable ::osl::Mutex maMutex;
149 ::boost::shared_ptr<MasterPageContainer> mpContainer;
151 SdDrawDocument& mrDocument;
152 ::std::auto_ptr<PreviewValueSet> mpPageSet;
153 bool mbSmallPreviewSize;
154 ViewShellBase& mrBase;
155 /** Slot that is executed as default action when the left mouse button is
156 clicked over a master page.
158 sal_uInt16 mnDefaultClickAction;
159 /** Pages with pointers in this queue have their previews updated
160 eventually. Filled by InvalidatePreview() and operated upon by
161 UpdatePreviews().
163 ::std::queue<USHORT> maPreviewUpdateQueue;
165 virtual SdPage* GetSelectedMasterPage (void);
167 /** Assign the given master page to all slides of the document.
168 @param pMasterPage
169 The master page to assign to all slides.
171 void AssignMasterPageToAllSlides (SdPage* pMasterPage);
173 /** Assign the given master page to all slides that are selected in a
174 slide sorter that is displayed in the lef or center pane. When both
175 panes display a slide sorter then the one in the center pane is
176 used.
178 void AssignMasterPageToSelectedSlides (SdPage* pMasterPage);
180 virtual void AssignMasterPageToPageList (
181 SdPage* pMasterPage,
182 const ::sd::slidesorter::SharedPageSelection& rPageList);
184 virtual void NotifyContainerChangeEvent (const MasterPageContainerChangeEvent& rEvent);
186 typedef ::std::pair<int, MasterPageContainer::Token> UserData;
187 UserData* CreateUserData (int nIndex, MasterPageContainer::Token aToken) const;
188 UserData* GetUserData (int nIndex) const;
189 void SetUserData (int nIndex, UserData* pData);
191 virtual sal_Int32 GetIndexForToken (MasterPageContainer::Token aToken) const;
192 typedef ::std::vector<MasterPageContainer::Token> ItemList;
193 void UpdateItemList (::std::auto_ptr<ItemList> pList);
194 void Clear (void);
195 /** Invalidate the specified item so that on the next Fill() this item
196 is updated.
198 void InvalidateItem (MasterPageContainer::Token aToken);
200 // For every item in the ValueSet we store its associated token. This
201 // allows a faster access and easier change tracking.
202 ItemList maCurrentItemList;
203 typedef ::std::map<MasterPageContainer::Token,sal_Int32> TokenToValueSetIndex;
204 TokenToValueSetIndex maTokenToValueSetIndex;
206 ItemList maLockedMasterPages;
207 /** Lock master pages in the given list and release locks that where
208 previously aquired.
210 void UpdateLocks (const ItemList& rItemList);
212 void Fill (void);
213 virtual void Fill (ItemList& rItemList) = 0;
215 /** Give derived classes the oportunity to provide their own context
216 menu. If they do then they probably have to provide their own
217 Execute() and GetState() methods as well.
219 virtual ResId GetContextMenuResId (void) const;
221 private:
222 /** The offset between ValueSet index and MasterPageContainer::Token
223 last seen. This value is used heuristically to speed up the lookup
224 of an index for a token.
226 DECL_LINK(ClickHandler, PreviewValueSet*);
227 DECL_LINK(RightClickHandler, MouseEvent*);
228 DECL_LINK(ContextMenuCallback, CommandEvent*);
229 DECL_LINK(ContainerChangeListener, MasterPageContainerChangeEvent*);
231 void SetItem (
232 USHORT nIndex,
233 MasterPageContainer::Token aToken);
234 void AddTokenToIndexEntry (
235 USHORT nIndex,
236 MasterPageContainer::Token aToken);
237 void RemoveTokenToIndexEntry (
238 USHORT nIndex,
239 MasterPageContainer::Token aToken);
242 } } } // end of namespace ::sd::toolpanel::controls
244 #endif