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