Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef INCLUDED_SD_SOURCE_UI_SIDEBAR_MASTERPAGECONTAINER_HXX
21 : #define INCLUDED_SD_SOURCE_UI_SIDEBAR_MASTERPAGECONTAINER_HXX
22 :
23 : #include "MasterPageContainerProviders.hxx"
24 :
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"
31 :
32 : #include <boost/shared_ptr.hpp>
33 :
34 : class SdPage;
35 :
36 : namespace sd { namespace sidebar {
37 :
38 : class MasterPageDescriptor;
39 :
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.
46 :
47 : The container maintains its own document to store master page objects.
48 :
49 : For each master page container stores its URL, preview bitmap, page
50 : name, and, if available, the page object.
51 :
52 : Entries are accessed via a Token, which is mostly a numerical index but
53 : whose values do not necessarily have to be consecutive.
54 : */
55 : class MasterPageContainer
56 : {
57 : public:
58 : typedef int Token;
59 : static const Token NIL_TOKEN = -1;
60 :
61 : MasterPageContainer (void);
62 : virtual ~MasterPageContainer (void);
63 :
64 : void AddChangeListener (const Link& rLink);
65 : void RemoveChangeListener (const Link& rLink);
66 :
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.
73 : */
74 : void SetPreviewSize (PreviewSize eSize);
75 :
76 : /** Returns the preview size.
77 : */
78 0 : PreviewSize GetPreviewSize (void) const { return mePreviewSize;}
79 :
80 : /** Return the preview size in pixels.
81 : */
82 : Size GetPreviewSizePixel (void) const;
83 :
84 : enum PreviewState { PS_AVAILABLE, PS_CREATABLE, PS_PREPARING, PS_NOT_AVAILABLE };
85 : PreviewState GetPreviewState (Token aToken);
86 :
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.
92 : */
93 : bool RequestPreview (Token aToken);
94 :
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.
97 : */
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
103 : };
104 :
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.
110 : */
111 : Token PutMasterPage (const ::boost::shared_ptr<MasterPageDescriptor>& rDescriptor);
112 : void AcquireToken (Token aToken);
113 : void ReleaseToken (Token aToken);
114 :
115 : /** This and the GetTokenForIndex() methods can be used to iterate over
116 : all members of the container.
117 : */
118 : int GetTokenCount (void) const;
119 :
120 : /** Determine whether the container has a member for the given token.
121 : */
122 : bool HasToken (Token aToken) const;
123 :
124 : /** Return a token for an index in the range
125 : 0 <= index < GetTokenCount().
126 : */
127 : Token GetTokenForIndex (int nIndex);
128 :
129 : Token GetTokenForURL (const OUString& sURL);
130 : Token GetTokenForStyleName (const OUString& sStyleName);
131 : Token GetTokenForPageObject (const SdPage* pPage);
132 :
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);
140 :
141 : void InvalidatePreview (Token aToken);
142 :
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.
154 : */
155 : Image GetPreviewForToken (Token aToken);
156 :
157 : private:
158 : class Implementation;
159 : ::boost::shared_ptr<Implementation> mpImpl;
160 : PreviewSize mePreviewSize;
161 :
162 : /** Retrieve the preview of the document specified by the given URL.
163 : */
164 : static BitmapEx LoadPreviewFromURL (const OUString& aURL);
165 : };
166 :
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.
172 : */
173 : class MasterPageContainerChangeEvent
174 : {
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;
192 :
193 : // Token of the container entry whose data changed or which was added or
194 : // removed.
195 : MasterPageContainer::Token maChildToken;
196 : };
197 :
198 : } } // end of namespace sd::sidebar
199 :
200 : #endif
201 :
202 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|