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_PAGE_CONTAINER_HXX 237a32b0c8SAndre Fischer #define SD_SIDEBAR_PANELS_MASTER_PAGE_CONTAINER_HXX 24cdf0e10cSrcweir 25cdf0e10cSrcweir #include "MasterPageContainerProviders.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <osl/mutex.hxx> 28cdf0e10cSrcweir #include <tools/string.hxx> 29cdf0e10cSrcweir #include <vcl/image.hxx> 30cdf0e10cSrcweir #include <memory> 31cdf0e10cSrcweir #include "PreviewRenderer.hxx" 32cdf0e10cSrcweir #include <com/sun/star/frame/XModel.hpp> 33cdf0e10cSrcweir #include <vcl/timer.hxx> 34cdf0e10cSrcweir #include "tools/SdGlobalResourceContainer.hxx" 35cdf0e10cSrcweir 36cdf0e10cSrcweir #include <boost/shared_ptr.hpp> 37cdf0e10cSrcweir 38cdf0e10cSrcweir class SdPage; 39cdf0e10cSrcweir class SdDrawDocument; 40cdf0e10cSrcweir class SfxObjectShellLock; 41cdf0e10cSrcweir 42cdf0e10cSrcweir namespace sd { 43cdf0e10cSrcweir class DrawDocShell; 44cdf0e10cSrcweir } 45cdf0e10cSrcweir 467a32b0c8SAndre Fischer namespace sd { namespace sidebar { 47cdf0e10cSrcweir 48cdf0e10cSrcweir class MasterPageDescriptor; 49cdf0e10cSrcweir 50cdf0e10cSrcweir /** This container manages the master pages used by the MasterPagesSelector 51cdf0e10cSrcweir controls. It uses internally a singleton implementation object. 52cdf0e10cSrcweir Therefore, all MasterPageContainer object operator on the same set of 53cdf0e10cSrcweir master pages. Each MasterPageContainer, however, has its own 54cdf0e10cSrcweir PreviewSize value and thus can independantly switch between large and 55cdf0e10cSrcweir small previews. 56cdf0e10cSrcweir 57cdf0e10cSrcweir The container maintains its own document to store master page objects. 58cdf0e10cSrcweir 59cdf0e10cSrcweir For each master page container stores its URL, preview bitmap, page 60cdf0e10cSrcweir name, and, if available, the page object. 61cdf0e10cSrcweir 62cdf0e10cSrcweir Entries are accessed via a Token, which is mostly a numerical index but 63cdf0e10cSrcweir whose values do not neccessarily have to be consecutive. 64cdf0e10cSrcweir */ 65cdf0e10cSrcweir class MasterPageContainer 66cdf0e10cSrcweir { 67cdf0e10cSrcweir public: 68cdf0e10cSrcweir typedef int Token; 69cdf0e10cSrcweir static const Token NIL_TOKEN = -1; 70cdf0e10cSrcweir 71cdf0e10cSrcweir MasterPageContainer (void); 72cdf0e10cSrcweir virtual ~MasterPageContainer (void); 73cdf0e10cSrcweir 74cdf0e10cSrcweir void AddChangeListener (const Link& rLink); 75cdf0e10cSrcweir void RemoveChangeListener (const Link& rLink); 76cdf0e10cSrcweir 77cdf0e10cSrcweir enum PreviewSize { SMALL, LARGE }; 78cdf0e10cSrcweir /** There are two different preview sizes, a small one and a large one. 79cdf0e10cSrcweir Which one is used by the called container can be changed with this 80cdf0e10cSrcweir method. 81cdf0e10cSrcweir When the preview size is changed then all change listeners are 82cdf0e10cSrcweir notified of this. 83cdf0e10cSrcweir */ 84cdf0e10cSrcweir void SetPreviewSize (PreviewSize eSize); 85cdf0e10cSrcweir 86cdf0e10cSrcweir /** Returns the preview size. 87cdf0e10cSrcweir */ 88cdf0e10cSrcweir PreviewSize GetPreviewSize (void) const; 89cdf0e10cSrcweir 90cdf0e10cSrcweir /** Return the preview size in pixels. 91cdf0e10cSrcweir */ 92cdf0e10cSrcweir Size GetPreviewSizePixel (void) const; 93cdf0e10cSrcweir 94cdf0e10cSrcweir enum PreviewState { PS_AVAILABLE, PS_CREATABLE, PS_PREPARING, PS_NOT_AVAILABLE }; 95cdf0e10cSrcweir PreviewState GetPreviewState (Token aToken); 96cdf0e10cSrcweir 97cdf0e10cSrcweir /** This method is typically called for entries in the container for 98cdf0e10cSrcweir which GetPreviewState() returns OS_CREATABLE. The creation of the 99cdf0e10cSrcweir preview is then scheduled to be executed asynchronously at a later 100cdf0e10cSrcweir point in time. When the preview is available the change listeners 101cdf0e10cSrcweir will be notified. 102cdf0e10cSrcweir */ 103cdf0e10cSrcweir bool RequestPreview (Token aToken); 104cdf0e10cSrcweir 105cdf0e10cSrcweir /** Each entry of the container is either the first page of a template 106cdf0e10cSrcweir document or is a master page of an Impress document. 107cdf0e10cSrcweir */ 108cdf0e10cSrcweir enum Origin { 109cdf0e10cSrcweir MASTERPAGE, // Master page of a document. 110cdf0e10cSrcweir TEMPLATE, // First page of a template file. 111cdf0e10cSrcweir DEFAULT, // Empty master page with default style. 112cdf0e10cSrcweir UNKNOWN 113cdf0e10cSrcweir }; 114cdf0e10cSrcweir 115cdf0e10cSrcweir /** Put the master page identified and described by the given parameters 116cdf0e10cSrcweir into the container. When there already is a master page with the 117cdf0e10cSrcweir given URL, page name, or object pointer (when that is not NULL) then 118cdf0e10cSrcweir the existing entry is replaced/updated by the given one. Otherwise 119cdf0e10cSrcweir a new entry is inserted. 120cdf0e10cSrcweir */ 121cdf0e10cSrcweir Token PutMasterPage (const ::boost::shared_ptr<MasterPageDescriptor>& rDescriptor); 122cdf0e10cSrcweir void AcquireToken (Token aToken); 123cdf0e10cSrcweir void ReleaseToken (Token aToken); 124cdf0e10cSrcweir 125cdf0e10cSrcweir /** This and the GetTokenForIndex() methods can be used to iterate over 126cdf0e10cSrcweir all members of the container. 127cdf0e10cSrcweir */ 128cdf0e10cSrcweir int GetTokenCount (void) const; 129cdf0e10cSrcweir 130cdf0e10cSrcweir /** Determine whether the container has a member for the given token. 131cdf0e10cSrcweir */ 132cdf0e10cSrcweir bool HasToken (Token aToken) const; 133cdf0e10cSrcweir 134cdf0e10cSrcweir /** Return a token for an index in the range 135cdf0e10cSrcweir 0 <= index < GetTokenCount(). 136cdf0e10cSrcweir */ 137cdf0e10cSrcweir Token GetTokenForIndex (int nIndex); 138cdf0e10cSrcweir 139cdf0e10cSrcweir Token GetTokenForURL (const String& sURL); 140cdf0e10cSrcweir Token GetTokenForStyleName (const String& sStyleName); 141cdf0e10cSrcweir Token GetTokenForPageObject (const SdPage* pPage); 142cdf0e10cSrcweir 143cdf0e10cSrcweir String GetURLForToken (Token aToken); 144cdf0e10cSrcweir String GetPageNameForToken (Token aToken); 145cdf0e10cSrcweir String GetStyleNameForToken (Token aToken); 146cdf0e10cSrcweir SdPage* GetPageObjectForToken (Token aToken, bool bLoad=true); 147cdf0e10cSrcweir Origin GetOriginForToken (Token aToken); 148cdf0e10cSrcweir sal_Int32 GetTemplateIndexForToken (Token aToken); 149cdf0e10cSrcweir ::boost::shared_ptr<MasterPageDescriptor> GetDescriptorForToken (Token aToken); 150cdf0e10cSrcweir 151cdf0e10cSrcweir void InvalidatePreview (Token aToken); 152cdf0e10cSrcweir 153cdf0e10cSrcweir /** Return a preview for the specified token. When the preview is not 154cdf0e10cSrcweir present then the PreviewProvider associated with the token is 155cdf0e10cSrcweir executed only when that is not expensive. It is the responsibility 156cdf0e10cSrcweir of the caller to call RequestPreview() to do the same 157cdf0e10cSrcweir (asynchronously) for expensive PreviewProviders. 158cdf0e10cSrcweir Call GetPreviewState() to find out if that is necessary. 159cdf0e10cSrcweir @param aToken 160cdf0e10cSrcweir This token specifies for which master page to return the prview. 161cdf0e10cSrcweir Tokens are returned for example by the GetTokenFor...() methods. 162cdf0e10cSrcweir @return 163cdf0e10cSrcweir The returned image is the requested preview or a substitution. 164cdf0e10cSrcweir */ 165cdf0e10cSrcweir Image GetPreviewForToken (Token aToken); 166cdf0e10cSrcweir 167cdf0e10cSrcweir private: 168cdf0e10cSrcweir class Implementation; 169cdf0e10cSrcweir ::boost::shared_ptr<Implementation> mpImpl; 170cdf0e10cSrcweir PreviewSize mePreviewSize; 171cdf0e10cSrcweir 172cdf0e10cSrcweir /** Retrieve the preview of the document specified by the given URL. 173cdf0e10cSrcweir */ 174cdf0e10cSrcweir static BitmapEx LoadPreviewFromURL (const ::rtl::OUString& aURL); 175cdf0e10cSrcweir }; 176cdf0e10cSrcweir 177cdf0e10cSrcweir 178cdf0e10cSrcweir 179cdf0e10cSrcweir 180cdf0e10cSrcweir /** For some changes to the set of master pages in a MasterPageContainer or 181cdf0e10cSrcweir to the data stored for each master page one or more events are sent to 182cdf0e10cSrcweir registered listeners. 183cdf0e10cSrcweir Each event has an event type and a token that tells the listener where 184cdf0e10cSrcweir the change took place. 185cdf0e10cSrcweir */ 186cdf0e10cSrcweir class MasterPageContainerChangeEvent 187cdf0e10cSrcweir { 188cdf0e10cSrcweir public: 189cdf0e10cSrcweir enum EventType { 190cdf0e10cSrcweir // A master page was added to the container. 191cdf0e10cSrcweir CHILD_ADDED, 192cdf0e10cSrcweir // A master page was removed from the container. 193cdf0e10cSrcweir CHILD_REMOVED, 194cdf0e10cSrcweir // The preview of a master page has changed. 195cdf0e10cSrcweir PREVIEW_CHANGED, 196cdf0e10cSrcweir // The size of a preview has changed. 197cdf0e10cSrcweir SIZE_CHANGED, 198cdf0e10cSrcweir // Some of the data stored for a master page has changed. 199cdf0e10cSrcweir DATA_CHANGED, 200cdf0e10cSrcweir // The TemplateIndex of a master page has changed. 201cdf0e10cSrcweir INDEX_CHANGED, 202cdf0e10cSrcweir // More than one entries changed their TemplateIndex 203cdf0e10cSrcweir INDEXES_CHANGED 204cdf0e10cSrcweir } meEventType; 205cdf0e10cSrcweir 206cdf0e10cSrcweir // Token of the container entry whose data changed or which was added or 207cdf0e10cSrcweir // removed. 208cdf0e10cSrcweir MasterPageContainer::Token maChildToken; 209cdf0e10cSrcweir }; 210cdf0e10cSrcweir 211cdf0e10cSrcweir 2127a32b0c8SAndre Fischer } } // end of namespace sd::sidebar 213cdf0e10cSrcweir 214cdf0e10cSrcweir #endif 215