bump product version to 6.3.0.0.beta1
[LibreOffice.git] / sd / source / ui / sidebar / MasterPageContainer.hxx
blob107622ca74c51e55bf02bb9e308cd7fbd4d4ad93
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 <vcl/image.hxx>
25 #include <memory>
27 class SdPage;
29 namespace sd { namespace sidebar {
31 class MasterPageDescriptor;
32 class MasterPageContainerChangeEvent;
34 /** This container manages the master pages used by the MasterPagesSelector
35 controls. It uses internally a singleton implementation object.
36 Therefore, all MasterPageContainer object operator on the same set of
37 master pages. Each MasterPageContainer, however, has its own
38 PreviewSize value and thus can independently switch between large and
39 small previews.
41 The container maintains its own document to store master page objects.
43 For each master page container stores its URL, preview bitmap, page
44 name, and, if available, the page object.
46 Entries are accessed via a Token, which is mostly a numerical index but
47 whose values do not necessarily have to be consecutive.
49 class MasterPageContainer final
51 public:
52 typedef int Token;
53 static const Token NIL_TOKEN = -1;
55 MasterPageContainer();
56 ~MasterPageContainer();
58 void AddChangeListener (const Link<MasterPageContainerChangeEvent&,void>& rLink);
59 void RemoveChangeListener (const Link<MasterPageContainerChangeEvent&,void>& rLink);
61 enum PreviewSize { SMALL, LARGE };
62 /** There are two different preview sizes, a small one and a large one.
63 Which one is used by the called container can be changed with this
64 method.
65 When the preview size is changed then all change listeners are
66 notified of this.
68 void SetPreviewSize (PreviewSize eSize);
70 /** Returns the preview size.
72 PreviewSize GetPreviewSize() const { return mePreviewSize;}
74 /** Return the preview size in pixels.
76 Size const & GetPreviewSizePixel() const;
78 enum PreviewState { PS_AVAILABLE, PS_CREATABLE, PS_PREPARING, PS_NOT_AVAILABLE };
79 PreviewState GetPreviewState (Token aToken);
81 /** This method is typically called for entries in the container for
82 which GetPreviewState() returns OS_CREATABLE. The creation of the
83 preview is then scheduled to be executed asynchronously at a later
84 point in time. When the preview is available the change listeners
85 will be notified.
87 bool RequestPreview (Token aToken);
89 /** Each entry of the container is either the first page of a template
90 document or is a master page of an Impress document.
92 enum Origin {
93 MASTERPAGE, // Master page of a document.
94 TEMPLATE, // First page of a template file.
95 DEFAULT, // Empty master page with default style.
96 UNKNOWN
99 /** Put the master page identified and described by the given parameters
100 into the container. When there already is a master page with the
101 given URL, page name, or object pointer (when that is not NULL) then
102 the existing entry is replaced/updated by the given one. Otherwise
103 a new entry is inserted.
105 Token PutMasterPage (const std::shared_ptr<MasterPageDescriptor>& rDescriptor);
106 void AcquireToken (Token aToken);
107 void ReleaseToken (Token aToken);
109 /** This and the GetTokenForIndex() methods can be used to iterate over
110 all members of the container.
112 int GetTokenCount() const;
114 /** Determine whether the container has a member for the given token.
116 bool HasToken (Token aToken) const;
118 /** Return a token for an index in the range
119 0 <= index < GetTokenCount().
121 Token GetTokenForIndex (int nIndex);
123 Token GetTokenForURL (const OUString& sURL);
124 Token GetTokenForStyleName (const OUString& sStyleName);
125 Token GetTokenForPageObject (const SdPage* pPage);
127 OUString GetURLForToken (Token aToken);
128 OUString GetPageNameForToken (Token aToken);
129 OUString GetStyleNameForToken (Token aToken);
130 SdPage* GetPageObjectForToken (Token aToken, bool bLoad);
131 Origin GetOriginForToken (Token aToken);
132 sal_Int32 GetTemplateIndexForToken (Token aToken);
133 std::shared_ptr<MasterPageDescriptor> GetDescriptorForToken (Token aToken);
135 void InvalidatePreview (Token aToken);
137 /** Return a preview for the specified token. When the preview is not
138 present then the PreviewProvider associated with the token is
139 executed only when that is not expensive. It is the responsibility
140 of the caller to call RequestPreview() to do the same
141 (asynchronously) for expensive PreviewProviders.
142 Call GetPreviewState() to find out if that is necessary.
143 @param aToken
144 This token specifies for which master page to return the preview.
145 Tokens are returned for example by the GetTokenFor...() methods.
146 @return
147 The returned image is the requested preview or a substitution.
149 Image GetPreviewForToken (Token aToken);
151 private:
152 class Implementation;
153 std::shared_ptr<Implementation> mpImpl;
154 PreviewSize mePreviewSize;
157 /** For some changes to the set of master pages in a MasterPageContainer or
158 to the data stored for each master page one or more events are sent to
159 registered listeners.
160 Each event has an event type and a token that tells the listener where
161 the change took place.
163 class MasterPageContainerChangeEvent
165 public:
166 enum class EventType {
167 // A master page was added to the container.
168 CHILD_ADDED,
169 // A master page was removed from the container.
170 CHILD_REMOVED,
171 // The preview of a master page has changed.
172 PREVIEW_CHANGED,
173 // The size of a preview has changed.
174 SIZE_CHANGED,
175 // Some of the data stored for a master page has changed.
176 DATA_CHANGED,
177 // The TemplateIndex of a master page has changed.
178 INDEX_CHANGED,
179 } meEventType;
181 // Token of the container entry whose data changed or which was added or
182 // removed.
183 MasterPageContainer::Token maChildToken;
186 } } // end of namespace sd::sidebar
188 #endif
190 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */