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