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