xref: /trunk/main/sd/source/ui/sidebar/MasterPagesSelector.hxx (revision 914d351e5f5b84e4342a86d6ab8d4aca7308b9bd)
102c50d82SAndre Fischer /**************************************************************
202c50d82SAndre Fischer  *
302c50d82SAndre Fischer  * Licensed to the Apache Software Foundation (ASF) under one
402c50d82SAndre Fischer  * or more contributor license agreements.  See the NOTICE file
502c50d82SAndre Fischer  * distributed with this work for additional information
602c50d82SAndre Fischer  * regarding copyright ownership.  The ASF licenses this file
702c50d82SAndre Fischer  * to you under the Apache License, Version 2.0 (the
802c50d82SAndre Fischer  * "License"); you may not use this file except in compliance
902c50d82SAndre Fischer  * with the License.  You may obtain a copy of the License at
1002c50d82SAndre Fischer  *
1102c50d82SAndre Fischer  *   http://www.apache.org/licenses/LICENSE-2.0
1202c50d82SAndre Fischer  *
1302c50d82SAndre Fischer  * Unless required by applicable law or agreed to in writing,
1402c50d82SAndre Fischer  * software distributed under the License is distributed on an
1502c50d82SAndre Fischer  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1602c50d82SAndre Fischer  * KIND, either express or implied.  See the License for the
1702c50d82SAndre Fischer  * specific language governing permissions and limitations
1802c50d82SAndre Fischer  * under the License.
1902c50d82SAndre Fischer  *
2002c50d82SAndre Fischer  *************************************************************/
2102c50d82SAndre Fischer 
2202c50d82SAndre Fischer #ifndef SD_SIDEBAR_PANELS_MASTER_PAGES_SELECTOR_HXX
2302c50d82SAndre Fischer #define SD_SIDEBAR_PANELS_MASTER_PAGES_SELECTOR_HXX
2402c50d82SAndre Fischer 
2502c50d82SAndre Fischer #include "MasterPageContainer.hxx"
2602c50d82SAndre Fischer #include "SlideSorterViewShell.hxx"
2702c50d82SAndre Fischer #include "PreviewValueSet.hxx"
2802c50d82SAndre Fischer #include "ISidebarReceiver.hxx"
2902c50d82SAndre Fischer #include <sfx2/sidebar/ILayoutableWindow.hxx>
3002c50d82SAndre Fischer 
3102c50d82SAndre Fischer #include "pres.hxx"
3202c50d82SAndre Fischer #include <sfx2/shell.hxx>
3302c50d82SAndre Fischer #include <vcl/image.hxx>
3402c50d82SAndre Fischer #include "glob.hxx"
3502c50d82SAndre Fischer #include <osl/mutex.hxx>
3602c50d82SAndre Fischer #include <com/sun/star/ui/XSidebar.hpp>
3702c50d82SAndre Fischer 
3802c50d82SAndre Fischer #include <queue>
3902c50d82SAndre Fischer 
4002c50d82SAndre Fischer namespace css = ::com::sun::star;
4102c50d82SAndre Fischer namespace cssu = ::com::sun::star::uno;
4202c50d82SAndre Fischer 
4302c50d82SAndre Fischer class MouseEvent;
4402c50d82SAndre Fischer class SdDrawDocument;
4502c50d82SAndre Fischer class SdPage;
4602c50d82SAndre Fischer class SfxModule;
4702c50d82SAndre Fischer 
4802c50d82SAndre Fischer namespace sd {
4902c50d82SAndre Fischer class DrawViewShell;
5002c50d82SAndre Fischer class TemplateEntry;
5102c50d82SAndre Fischer class TemplateDir;
5202c50d82SAndre Fischer class ViewShellBase;
5302c50d82SAndre Fischer }
5402c50d82SAndre Fischer 
5502c50d82SAndre Fischer namespace sd { namespace sidebar {
5602c50d82SAndre Fischer 
5702c50d82SAndre Fischer class PreviewValueSet;
5802c50d82SAndre Fischer class SidebarShellManager;
5902c50d82SAndre Fischer 
6002c50d82SAndre Fischer 
6102c50d82SAndre Fischer /** Base class of a menu that lets the user select from a list of
6202c50d82SAndre Fischer     templates or designs that are loaded from files.
6302c50d82SAndre Fischer */
6402c50d82SAndre Fischer class MasterPagesSelector
6502c50d82SAndre Fischer     : public PreviewValueSet,
6602c50d82SAndre Fischer       public sfx2::sidebar::ILayoutableWindow
6702c50d82SAndre Fischer {
6802c50d82SAndre Fischer public:
6902c50d82SAndre Fischer     MasterPagesSelector (
7002c50d82SAndre Fischer         ::Window* pParent,
7102c50d82SAndre Fischer         SdDrawDocument& rDocument,
7202c50d82SAndre Fischer         ViewShellBase& rBase,
7302c50d82SAndre Fischer         const ::boost::shared_ptr<MasterPageContainer>& rpContainer,
7402c50d82SAndre Fischer         const cssu::Reference<css::ui::XSidebar>& rxSidebar);
7502c50d82SAndre Fischer     virtual ~MasterPagesSelector (void);
7602c50d82SAndre Fischer 
7702c50d82SAndre Fischer     virtual void LateInit (void);
7802c50d82SAndre Fischer 
7902c50d82SAndre Fischer     /** Return the height that this control needs to show all of its lines.
8002c50d82SAndre Fischer     */
8102c50d82SAndre Fischer     long GetRequiredHeight (int nWidth) const;
8202c50d82SAndre Fischer 
8302c50d82SAndre Fischer     /** The given master page, either the master page of a slide or a notes
8402c50d82SAndre Fischer         page, is cloned and inserted into mrDocument.  The necessary styles
8502c50d82SAndre Fischer         are copied as well.
8602c50d82SAndre Fischer     */
8702c50d82SAndre Fischer     static SdPage* AddMasterPage (
8802c50d82SAndre Fischer         SdDrawDocument* pTargetDocument,
8902c50d82SAndre Fischer         SdPage* pMasterPage,
9002c50d82SAndre Fischer         sal_uInt16 nInsertionIndex);
9102c50d82SAndre Fischer 
9202c50d82SAndre Fischer     virtual Size GetPreferredSize (void);
9302c50d82SAndre Fischer     virtual sal_Int32 GetPreferredWidth (sal_Int32 nHeight);
9402c50d82SAndre Fischer     virtual sal_Int32 GetPreferredHeight (sal_Int32 nWidth);
9502c50d82SAndre Fischer     virtual bool IsResizable (void);
9602c50d82SAndre Fischer     virtual ::Window* GetWindow (void);
9702c50d82SAndre Fischer     virtual sal_Int32 GetMinimumWidth (void);
9802c50d82SAndre Fischer 
9902c50d82SAndre Fischer     /** Update the selection of previews according to whatever
100*86e1cf34SPedro Giffuni         influences them apart from mouse and keyboard.  If, for
10102c50d82SAndre Fischer         example, the current page of the main pane changes, then call
10202c50d82SAndre Fischer         this method at the CurrentMasterPagesSelector to select the
10302c50d82SAndre Fischer         previews of the master pages that are assigned to the new
10402c50d82SAndre Fischer         current page.
10502c50d82SAndre Fischer 
10602c50d82SAndre Fischer         The default implementation of this method ignores the call. This is
10702c50d82SAndre Fischer         used by e.g. the RecentMasterPagesSelector because it does not show
10802c50d82SAndre Fischer         the currently used master pages by default and thus is not
10902c50d82SAndre Fischer         influenced by its changes.
11002c50d82SAndre Fischer     */
11102c50d82SAndre Fischer     virtual void UpdateSelection (void);
11202c50d82SAndre Fischer 
11302c50d82SAndre Fischer     void FillPageSet (void);
11402c50d82SAndre Fischer 
11502c50d82SAndre Fischer     /** Make the selector empty.  This method clear the value set from any
11602c50d82SAndre Fischer         entries. Overload this method to add functionality, especially to
11702c50d82SAndre Fischer         destroy objects set as data items at the value set.
11802c50d82SAndre Fischer     */
11902c50d82SAndre Fischer     void ClearPageSet (void);
12002c50d82SAndre Fischer 
12102c50d82SAndre Fischer     void SetHelpId( const rtl::OString& aId );
12202c50d82SAndre Fischer 
12302c50d82SAndre Fischer     /** Mark the preview that belongs to the given index as not up-to-date
12402c50d82SAndre Fischer         anymore with respect to page content or preview size.
12502c50d82SAndre Fischer         The implementation of this method will either sunchronously or
12602c50d82SAndre Fischer         asynchronously call UpdatePreview().
12702c50d82SAndre Fischer         @param nIndex
12802c50d82SAndre Fischer             Index into the value set control that is used for displaying the
12902c50d82SAndre Fischer             previews.
13002c50d82SAndre Fischer     */
13102c50d82SAndre Fischer     void InvalidatePreview (const SdPage* pPage);
13202c50d82SAndre Fischer 
13302c50d82SAndre Fischer     void UpdateAllPreviews (void);
13402c50d82SAndre Fischer 
13502c50d82SAndre Fischer     // ILayoutableWindow
13602c50d82SAndre Fischer     virtual css::ui::LayoutSize GetHeightForWidth (const sal_Int32 nWidth);
13702c50d82SAndre Fischer 
13802c50d82SAndre Fischer protected:
13902c50d82SAndre Fischer     mutable ::osl::Mutex maMutex;
14002c50d82SAndre Fischer     ::boost::shared_ptr<MasterPageContainer> mpContainer;
14102c50d82SAndre Fischer 
14202c50d82SAndre Fischer     SdDrawDocument& mrDocument;
14302c50d82SAndre Fischer     bool mbSmallPreviewSize;
14402c50d82SAndre Fischer     ViewShellBase& mrBase;
14502c50d82SAndre Fischer     /** Slot that is executed as default action when the left mouse button is
14602c50d82SAndre Fischer         clicked over a master page.
14702c50d82SAndre Fischer     */
14802c50d82SAndre Fischer     sal_uInt16 mnDefaultClickAction;
14902c50d82SAndre Fischer     /** Pages with pointers in this queue have their previews updated
15002c50d82SAndre Fischer         eventually.  Filled by InvalidatePreview() and operated upon by
15102c50d82SAndre Fischer         UpdatePreviews().
15202c50d82SAndre Fischer     */
15302c50d82SAndre Fischer     ::std::queue<sal_uInt16> maPreviewUpdateQueue;
15402c50d82SAndre Fischer 
15502c50d82SAndre Fischer     virtual SdPage* GetSelectedMasterPage (void);
15602c50d82SAndre Fischer 
15702c50d82SAndre Fischer     /** Assign the given master page to all slides of the document.
15802c50d82SAndre Fischer         @param pMasterPage
15902c50d82SAndre Fischer             The master page to assign to all slides.
16002c50d82SAndre Fischer     */
16102c50d82SAndre Fischer     void AssignMasterPageToAllSlides (SdPage* pMasterPage);
16202c50d82SAndre Fischer 
16302c50d82SAndre Fischer     /** Assign the given master page to all slides that are selected in a
16402c50d82SAndre Fischer         slide sorter that is displayed in the lef or center pane.  When both
16502c50d82SAndre Fischer         panes display a slide sorter then the one in the center pane is
16602c50d82SAndre Fischer         used.
16702c50d82SAndre Fischer     */
16802c50d82SAndre Fischer     void AssignMasterPageToSelectedSlides (SdPage* pMasterPage);
16902c50d82SAndre Fischer 
17002c50d82SAndre Fischer     virtual void AssignMasterPageToPageList (
17102c50d82SAndre Fischer         SdPage* pMasterPage,
17202c50d82SAndre Fischer         const ::sd::slidesorter::SharedPageSelection& rPageList);
17302c50d82SAndre Fischer 
17402c50d82SAndre Fischer     virtual void NotifyContainerChangeEvent (const MasterPageContainerChangeEvent& rEvent);
17502c50d82SAndre Fischer 
17602c50d82SAndre Fischer     typedef ::std::pair<int, MasterPageContainer::Token> UserData;
17702c50d82SAndre Fischer     UserData* CreateUserData (int nIndex, MasterPageContainer::Token aToken) const;
17802c50d82SAndre Fischer     UserData* GetUserData (int nIndex) const;
17902c50d82SAndre Fischer     void SetUserData (int nIndex, UserData* pData);
18002c50d82SAndre Fischer 
18102c50d82SAndre Fischer     virtual sal_Int32 GetIndexForToken (MasterPageContainer::Token aToken) const;
18202c50d82SAndre Fischer     typedef ::std::vector<MasterPageContainer::Token> ItemList;
18302c50d82SAndre Fischer     void UpdateItemList (::std::auto_ptr<ItemList> pList);
18402c50d82SAndre Fischer     void Clear (void);
18502c50d82SAndre Fischer     /** Invalidate the specified item so that on the next Fill() this item
18602c50d82SAndre Fischer         is updated.
18702c50d82SAndre Fischer     */
18802c50d82SAndre Fischer     void InvalidateItem (MasterPageContainer::Token aToken);
18902c50d82SAndre Fischer 
19002c50d82SAndre Fischer     // For every item in the ValueSet we store its associated token.  This
19102c50d82SAndre Fischer     // allows a faster access and easier change tracking.
19202c50d82SAndre Fischer     ItemList maCurrentItemList;
19302c50d82SAndre Fischer     typedef ::std::map<MasterPageContainer::Token,sal_Int32> TokenToValueSetIndex;
19402c50d82SAndre Fischer     TokenToValueSetIndex maTokenToValueSetIndex;
19502c50d82SAndre Fischer 
19602c50d82SAndre Fischer     ItemList maLockedMasterPages;
19702c50d82SAndre Fischer     /** Lock master pages in the given list and release locks that where
198*86e1cf34SPedro Giffuni         previously acquired.
19902c50d82SAndre Fischer     */
20002c50d82SAndre Fischer     void UpdateLocks (const ItemList& rItemList);
20102c50d82SAndre Fischer 
20202c50d82SAndre Fischer     void Fill (void);
20302c50d82SAndre Fischer     virtual void Fill (ItemList& rItemList) = 0;
20402c50d82SAndre Fischer 
205*86e1cf34SPedro Giffuni     /** Give derived classes the opportunity to provide their own context
20602c50d82SAndre Fischer         menu.  If they do then they probably have to provide their own
20702c50d82SAndre Fischer         Execute() and GetState() methods as well.
20802c50d82SAndre Fischer     */
20902c50d82SAndre Fischer     virtual ResId GetContextMenuResId (void) const;
21002c50d82SAndre Fischer 
21102c50d82SAndre Fischer     virtual void Command (const CommandEvent& rEvent);
21202c50d82SAndre Fischer 
21302c50d82SAndre Fischer     virtual void ProcessPopupMenu (Menu& rMenu);
21402c50d82SAndre Fischer     virtual void ExecuteCommand (const sal_Int32 nCommandId);
21502c50d82SAndre Fischer 
21602c50d82SAndre Fischer private:
21702c50d82SAndre Fischer     cssu::Reference<css::ui::XSidebar> mxSidebar;
21802c50d82SAndre Fischer 
21902c50d82SAndre Fischer     /** The offset between ValueSet index and MasterPageContainer::Token
22002c50d82SAndre Fischer         last seen.  This value is used heuristically to speed up the lookup
22102c50d82SAndre Fischer         of an index for a token.
22202c50d82SAndre Fischer     */
22302c50d82SAndre Fischer     DECL_LINK(ClickHandler, PreviewValueSet*);
22402c50d82SAndre Fischer     DECL_LINK(RightClickHandler, MouseEvent*);
22502c50d82SAndre Fischer     DECL_LINK(ContextMenuCallback, CommandEvent*);
22602c50d82SAndre Fischer     DECL_LINK(ContainerChangeListener, MasterPageContainerChangeEvent*);
22702c50d82SAndre Fischer     DECL_LINK(OnMenuItemSelected, Menu*);
22802c50d82SAndre Fischer 
22902c50d82SAndre Fischer     void SetItem (
23002c50d82SAndre Fischer         sal_uInt16 nIndex,
23102c50d82SAndre Fischer         MasterPageContainer::Token aToken);
23202c50d82SAndre Fischer     void AddTokenToIndexEntry (
23302c50d82SAndre Fischer         sal_uInt16 nIndex,
23402c50d82SAndre Fischer         MasterPageContainer::Token aToken);
23502c50d82SAndre Fischer     void RemoveTokenToIndexEntry (
23602c50d82SAndre Fischer         sal_uInt16 nIndex,
23702c50d82SAndre Fischer         MasterPageContainer::Token aToken);
23802c50d82SAndre Fischer };
23902c50d82SAndre Fischer 
24002c50d82SAndre Fischer } } // end of namespace sd::sidebar
24102c50d82SAndre Fischer 
24202c50d82SAndre Fischer #endif
243