Update ooo320-m1
[ooovba.git] / sd / source / ui / toolpanel / controls / MasterPageContainer.hxx
blobd79dda703f0231610b096a1c73547bddde31d949
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: MasterPageContainer.hxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef SD_TOOLPANEL_CONTROLS_MASTER_PAGE_CONTAINER_HXX
32 #define SD_TOOLPANEL_CONTROLS_MASTER_PAGE_CONTAINER_HXX
34 #include "MasterPageContainerProviders.hxx"
36 #include <osl/mutex.hxx>
37 #include <tools/string.hxx>
38 #include <vcl/image.hxx>
39 #include <memory>
40 #include "PreviewRenderer.hxx"
41 #include <com/sun/star/frame/XModel.hpp>
42 #include <vcl/timer.hxx>
43 #include "tools/SdGlobalResourceContainer.hxx"
45 #include <boost/shared_ptr.hpp>
47 class SdPage;
48 class SdDrawDocument;
49 class SfxObjectShellLock;
51 namespace sd {
52 class DrawDocShell;
55 namespace sd { namespace toolpanel { namespace controls {
57 class MasterPageDescriptor;
59 /** This container manages the master pages used by the MasterPagesSelector
60 controls. It uses internally a singleton implementation object.
61 Therefore, all MasterPageContainer object operator on the same set of
62 master pages. Each MasterPageContainer, however, has its own
63 PreviewSize value and thus can independantly switch between large and
64 small previews.
66 The container maintains its own document to store master page objects.
68 For each master page container stores its URL, preview bitmap, page
69 name, and, if available, the page object.
71 Entries are accessed via a Token, which is mostly a numerical index but
72 whose values do not neccessarily have to be consecutive.
74 class MasterPageContainer
76 public:
77 typedef int Token;
78 static const Token NIL_TOKEN = -1;
80 MasterPageContainer (void);
81 virtual ~MasterPageContainer (void);
83 void AddChangeListener (const Link& rLink);
84 void RemoveChangeListener (const Link& rLink);
86 enum PreviewSize { SMALL, LARGE };
87 /** There are two different preview sizes, a small one and a large one.
88 Which one is used by the called container can be changed with this
89 method.
90 When the preview size is changed then all change listeners are
91 notified of this.
93 void SetPreviewSize (PreviewSize eSize);
95 /** Returns the preview size.
97 PreviewSize GetPreviewSize (void) const;
99 /** Return the preview size in pixels.
101 Size GetPreviewSizePixel (void) const;
103 enum PreviewState { PS_AVAILABLE, PS_CREATABLE, PS_PREPARING, PS_NOT_AVAILABLE };
104 PreviewState GetPreviewState (Token aToken);
106 /** This method is typically called for entries in the container for
107 which GetPreviewState() returns OS_CREATABLE. The creation of the
108 preview is then scheduled to be executed asynchronously at a later
109 point in time. When the preview is available the change listeners
110 will be notified.
112 bool RequestPreview (Token aToken);
114 /** Each entry of the container is either the first page of a template
115 document or is a master page of an Impress document.
117 enum Origin {
118 MASTERPAGE, // Master page of a document.
119 TEMPLATE, // First page of a template file.
120 DEFAULT, // Empty master page with default style.
121 UNKNOWN
124 /** Put the master page identified and described by the given parameters
125 into the container. When there already is a master page with the
126 given URL, page name, or object pointer (when that is not NULL) then
127 the existing entry is replaced/updated by the given one. Otherwise
128 a new entry is inserted.
130 Token PutMasterPage (const ::boost::shared_ptr<MasterPageDescriptor>& rDescriptor);
131 void AcquireToken (Token aToken);
132 void ReleaseToken (Token aToken);
134 /** This and the GetTokenForIndex() methods can be used to iterate over
135 all members of the container.
137 int GetTokenCount (void) const;
139 /** Determine whether the container has a member for the given token.
141 bool HasToken (Token aToken) const;
143 /** Return a token for an index in the range
144 0 <= index < GetTokenCount().
146 Token GetTokenForIndex (int nIndex);
148 Token GetTokenForURL (const String& sURL);
149 Token GetTokenForPageName (const String& sPageName);
150 Token GetTokenForStyleName (const String& sStyleName);
151 Token GetTokenForPageObject (const SdPage* pPage);
153 String GetURLForToken (Token aToken);
154 String GetPageNameForToken (Token aToken);
155 String GetStyleNameForToken (Token aToken);
156 SdPage* GetSlideForToken (Token aToken, bool bLoad=true);
157 SdPage* GetPageObjectForToken (Token aToken, bool bLoad=true);
158 Origin GetOriginForToken (Token aToken);
159 sal_Int32 GetTemplateIndexForToken (Token aToken);
160 ::boost::shared_ptr<MasterPageDescriptor> GetDescriptorForToken (Token aToken);
161 bool UpdateDescriptor (
162 const ::boost::shared_ptr<MasterPageDescriptor>& rpDescriptor,
163 bool bForcePageObject,
164 bool bForcePreview,
165 bool bSendEvents);
167 void SetPreviewProviderForToken (Token aToken,
168 const ::boost::shared_ptr<PreviewProvider>& rpPreviewProvider);
170 void InvalidatePreview (Token aToken);
172 /** Return a preview for the specified token. When the preview is not
173 present then the PreviewProvider associated with the token is
174 executed only when that is not expensive. It is the responsibility
175 of the caller to call RequestPreview() to do the same
176 (asynchronously) for expensive PreviewProviders.
177 Call GetPreviewState() to find out if that is necessary.
178 @param aToken
179 This token specifies for which master page to return the prview.
180 Tokens are returned for example by the GetTokenFor...() methods.
181 @return
182 The returned image is the requested preview or a substitution.
184 Image GetPreviewForToken (Token aToken);
186 private:
187 class Implementation;
188 ::boost::shared_ptr<Implementation> mpImpl;
189 PreviewSize mePreviewSize;
191 /** Retrieve the preview of the document specified by the given URL.
193 static BitmapEx LoadPreviewFromURL (const ::rtl::OUString& aURL);
199 /** For some changes to the set of master pages in a MasterPageContainer or
200 to the data stored for each master page one or more events are sent to
201 registered listeners.
202 Each event has an event type and a token that tells the listener where
203 the change took place.
205 class MasterPageContainerChangeEvent
207 public:
208 enum EventType {
209 // A master page was added to the container.
210 CHILD_ADDED,
211 // A master page was removed from the container.
212 CHILD_REMOVED,
213 // The preview of a master page has changed.
214 PREVIEW_CHANGED,
215 // The size of a preview has changed.
216 SIZE_CHANGED,
217 // Some of the data stored for a master page has changed.
218 DATA_CHANGED,
219 // The TemplateIndex of a master page has changed.
220 INDEX_CHANGED,
221 // More than one entries changed their TemplateIndex
222 INDEXES_CHANGED
223 } meEventType;
225 // Token of the container entry whose data changed or which was added or
226 // removed.
227 MasterPageContainer::Token maChildToken;
231 } } } // end of namespace ::sd::toolpanel::controls
233 #endif