bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / sidebar / MasterPageContainer.hxx
blobdaf3ba8bc8b0d11b10051300f653670ee49d8e58
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_SD_SOURCE_UI_SIDEBAR_MASTERPAGECONTAINER_HXX
21 #define INCLUDED_SD_SOURCE_UI_SIDEBAR_MASTERPAGECONTAINER_HXX
23 #include "MasterPageContainerProviders.hxx"
25 #include <osl/mutex.hxx>
26 #include <vcl/image.hxx>
27 #include "PreviewRenderer.hxx"
28 #include <com/sun/star/frame/XModel.hpp>
29 #include <vcl/timer.hxx>
30 #include "tools/SdGlobalResourceContainer.hxx"
32 #include <boost/shared_ptr.hpp>
34 class SdPage;
36 namespace sd { namespace sidebar {
38 class MasterPageDescriptor;
40 /** This container manages the master pages used by the MasterPagesSelector
41 controls. It uses internally a singleton implementation object.
42 Therefore, all MasterPageContainer object operator on the same set of
43 master pages. Each MasterPageContainer, however, has its own
44 PreviewSize value and thus can independently switch between large and
45 small previews.
47 The container maintains its own document to store master page objects.
49 For each master page container stores its URL, preview bitmap, page
50 name, and, if available, the page object.
52 Entries are accessed via a Token, which is mostly a numerical index but
53 whose values do not necessarily have to be consecutive.
55 class MasterPageContainer
57 public:
58 typedef int Token;
59 static const Token NIL_TOKEN = -1;
61 MasterPageContainer();
62 virtual ~MasterPageContainer();
64 void AddChangeListener (const Link<>& rLink);
65 void RemoveChangeListener (const Link<>& rLink);
67 enum PreviewSize { SMALL, LARGE };
68 /** There are two different preview sizes, a small one and a large one.
69 Which one is used by the called container can be changed with this
70 method.
71 When the preview size is changed then all change listeners are
72 notified of this.
74 void SetPreviewSize (PreviewSize eSize);
76 /** Returns the preview size.
78 PreviewSize GetPreviewSize() const { return mePreviewSize;}
80 /** Return the preview size in pixels.
82 Size GetPreviewSizePixel() const;
84 enum PreviewState { PS_AVAILABLE, PS_CREATABLE, PS_PREPARING, PS_NOT_AVAILABLE };
85 PreviewState GetPreviewState (Token aToken);
87 /** This method is typically called for entries in the container for
88 which GetPreviewState() returns OS_CREATABLE. The creation of the
89 preview is then scheduled to be executed asynchronously at a later
90 point in time. When the preview is available the change listeners
91 will be notified.
93 bool RequestPreview (Token aToken);
95 /** Each entry of the container is either the first page of a template
96 document or is a master page of an Impress document.
98 enum Origin {
99 MASTERPAGE, // Master page of a document.
100 TEMPLATE, // First page of a template file.
101 DEFAULT, // Empty master page with default style.
102 UNKNOWN
105 /** Put the master page identified and described by the given parameters
106 into the container. When there already is a master page with the
107 given URL, page name, or object pointer (when that is not NULL) then
108 the existing entry is replaced/updated by the given one. Otherwise
109 a new entry is inserted.
111 Token PutMasterPage (const ::boost::shared_ptr<MasterPageDescriptor>& rDescriptor);
112 void AcquireToken (Token aToken);
113 void ReleaseToken (Token aToken);
115 /** This and the GetTokenForIndex() methods can be used to iterate over
116 all members of the container.
118 int GetTokenCount() const;
120 /** Determine whether the container has a member for the given token.
122 bool HasToken (Token aToken) const;
124 /** Return a token for an index in the range
125 0 <= index < GetTokenCount().
127 Token GetTokenForIndex (int nIndex);
129 Token GetTokenForURL (const OUString& sURL);
130 Token GetTokenForStyleName (const OUString& sStyleName);
131 Token GetTokenForPageObject (const SdPage* pPage);
133 OUString GetURLForToken (Token aToken);
134 OUString GetPageNameForToken (Token aToken);
135 OUString GetStyleNameForToken (Token aToken);
136 SdPage* GetPageObjectForToken (Token aToken, bool bLoad=true);
137 Origin GetOriginForToken (Token aToken);
138 sal_Int32 GetTemplateIndexForToken (Token aToken);
139 ::boost::shared_ptr<MasterPageDescriptor> GetDescriptorForToken (Token aToken);
141 void InvalidatePreview (Token aToken);
143 /** Return a preview for the specified token. When the preview is not
144 present then the PreviewProvider associated with the token is
145 executed only when that is not expensive. It is the responsibility
146 of the caller to call RequestPreview() to do the same
147 (asynchronously) for expensive PreviewProviders.
148 Call GetPreviewState() to find out if that is necessary.
149 @param aToken
150 This token specifies for which master page to return the prview.
151 Tokens are returned for example by the GetTokenFor...() methods.
152 @return
153 The returned image is the requested preview or a substitution.
155 Image GetPreviewForToken (Token aToken);
157 private:
158 class Implementation;
159 ::boost::shared_ptr<Implementation> mpImpl;
160 PreviewSize mePreviewSize;
162 /** Retrieve the preview of the document specified by the given URL.
164 static BitmapEx LoadPreviewFromURL (const OUString& aURL);
167 /** For some changes to the set of master pages in a MasterPageContainer or
168 to the data stored for each master page one or more events are sent to
169 registered listeners.
170 Each event has an event type and a token that tells the listener where
171 the change took place.
173 class MasterPageContainerChangeEvent
175 public:
176 enum EventType {
177 // A master page was added to the container.
178 CHILD_ADDED,
179 // A master page was removed from the container.
180 CHILD_REMOVED,
181 // The preview of a master page has changed.
182 PREVIEW_CHANGED,
183 // The size of a preview has changed.
184 SIZE_CHANGED,
185 // Some of the data stored for a master page has changed.
186 DATA_CHANGED,
187 // The TemplateIndex of a master page has changed.
188 INDEX_CHANGED,
189 // More than one entries changed their TemplateIndex
190 INDEXES_CHANGED
191 } meEventType;
193 // Token of the container entry whose data changed or which was added or
194 // removed.
195 MasterPageContainer::Token maChildToken;
198 } } // end of namespace sd::sidebar
200 #endif
202 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */