xref: /trunk/main/sd/source/ui/sidebar/MasterPageContainerQueue.hxx (revision 914d351e5f5b84e4342a86d6ab8d4aca7308b9bd)
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_QUEUE_HXX
23*02c50d82SAndre Fischer #define SD_SIDEBAR_PANELS_MASTER_PAGE_CONTAINER_QUEUE_HXX
24*02c50d82SAndre Fischer 
25*02c50d82SAndre Fischer #include "MasterPageContainer.hxx"
26*02c50d82SAndre Fischer #include "MasterPageDescriptor.hxx"
27*02c50d82SAndre Fischer 
28*02c50d82SAndre Fischer #include <boost/scoped_ptr.hpp>
29*02c50d82SAndre Fischer #include <boost/weak_ptr.hpp>
30*02c50d82SAndre Fischer 
31*02c50d82SAndre Fischer namespace sd { namespace sidebar {
32*02c50d82SAndre Fischer 
33*02c50d82SAndre Fischer 
34*02c50d82SAndre Fischer /** The queue stores and processes all requests from a MasterPageContainer
35*02c50d82SAndre Fischer     for the creation of previews.
36*02c50d82SAndre Fischer     The order of request processing and its timing is controlled by a
37*02c50d82SAndre Fischer     heuristic that uses values given with each request and which is
38*02c50d82SAndre Fischer     controlled by various parameters that are described below.
39*02c50d82SAndre Fischer */
40*02c50d82SAndre Fischer class MasterPageContainerQueue
41*02c50d82SAndre Fischer {
42*02c50d82SAndre Fischer public:
43*02c50d82SAndre Fischer     class ContainerAdapter { public:
44*02c50d82SAndre Fischer         virtual bool UpdateDescriptor (
45*02c50d82SAndre Fischer             const SharedMasterPageDescriptor& rpDescriptor,
46*02c50d82SAndre Fischer             bool bForcePageObject,
47*02c50d82SAndre Fischer             bool bForcePreview,
48*02c50d82SAndre Fischer             bool bSendEvents) = 0;
49*02c50d82SAndre Fischer     };
50*02c50d82SAndre Fischer 
51*02c50d82SAndre Fischer     static MasterPageContainerQueue* Create (
52*02c50d82SAndre Fischer         const ::boost::weak_ptr<ContainerAdapter>& rpContainer);
53*02c50d82SAndre Fischer     virtual ~MasterPageContainerQueue (void);
54*02c50d82SAndre Fischer 
55*02c50d82SAndre Fischer     /** This method is typically called for entries in the container for
56*02c50d82SAndre Fischer         which GetPreviewState() returns OS_CREATABLE.  The creation of the
57*02c50d82SAndre Fischer         preview is then scheduled to be executed asynchronously at a later
58*02c50d82SAndre Fischer         point in time.  When the preview is available the change listeners
59*02c50d82SAndre Fischer         will be notified.
60*02c50d82SAndre Fischer     */
61*02c50d82SAndre Fischer     bool RequestPreview (const SharedMasterPageDescriptor& rDescriptor);
62*02c50d82SAndre Fischer 
63*02c50d82SAndre Fischer     /** Return <TRUE/> when there is a request currently in the queue for
64*02c50d82SAndre Fischer         the given token.
65*02c50d82SAndre Fischer     */
66*02c50d82SAndre Fischer     bool HasRequest (MasterPageContainer::Token aToken) const;
67*02c50d82SAndre Fischer 
68*02c50d82SAndre Fischer     /** Return <TRUE/> when there is at least one request in the queue.
69*02c50d82SAndre Fischer     */
70*02c50d82SAndre Fischer     bool IsEmpty (void) const;
71*02c50d82SAndre Fischer 
72*02c50d82SAndre Fischer     /** After this call the queue does not wait anymore for requests with
73*02c50d82SAndre Fischer         higher priority when only a small number of requests with lower
74*02c50d82SAndre Fischer         priority are present.  This method should be called when all
75*02c50d82SAndre Fischer         templates are inserted into the MasterPageContainer.
76*02c50d82SAndre Fischer     */
77*02c50d82SAndre Fischer     void ProcessAllRequests (void);
78*02c50d82SAndre Fischer 
79*02c50d82SAndre Fischer private:
80*02c50d82SAndre Fischer     ::boost::weak_ptr<ContainerAdapter> mpWeakContainer;
81*02c50d82SAndre Fischer     class PreviewCreationRequest;
82*02c50d82SAndre Fischer     class RequestQueue;
83*02c50d82SAndre Fischer     ::boost::scoped_ptr<RequestQueue> mpRequestQueue;
84*02c50d82SAndre Fischer     Timer maDelayedPreviewCreationTimer;
85*02c50d82SAndre Fischer     sal_uInt32 mnRequestsServedCount;
86*02c50d82SAndre Fischer 
87*02c50d82SAndre Fischer     // There are a couple of values that define various aspects of the
88*02c50d82SAndre Fischer     // heuristic that defines the order and timing in which requests for
89*02c50d82SAndre Fischer     // preview creation are processed.
90*02c50d82SAndre Fischer 
91*02c50d82SAndre Fischer     /** The time to wait (in milliseconds) between the creation of previews.
92*02c50d82SAndre Fischer     */
93*02c50d82SAndre Fischer     static const sal_Int32 snDelayedCreationTimeout;
94*02c50d82SAndre Fischer 
95*02c50d82SAndre Fischer     /** The time to wait when the system is not idle.
96*02c50d82SAndre Fischer     */
97*02c50d82SAndre Fischer     static const sal_Int32 snDelayedCreationTimeoutWhenNotIdle;
98*02c50d82SAndre Fischer 
99*02c50d82SAndre Fischer     /** Requests for previews of master pages in a document have their
100*02c50d82SAndre Fischer         priority increased by this value.
101*02c50d82SAndre Fischer     */
102*02c50d82SAndre Fischer     static const sal_Int32 snMasterPagePriorityBoost;
103*02c50d82SAndre Fischer 
104*02c50d82SAndre Fischer     /** When only requests which a priority lower than this threshold exist
105*02c50d82SAndre Fischer         and not many requests have been made yet then wait with processing
106*02c50d82SAndre Fischer         them until more requests are present.
107*02c50d82SAndre Fischer     */
108*02c50d82SAndre Fischer     static const sal_Int32 snWaitForMoreRequestsPriorityThreshold;
109*02c50d82SAndre Fischer 
110*02c50d82SAndre Fischer     /** When only requests which a priority lower than a threshold exist
111*02c50d82SAndre Fischer         and not more requests than this number have been made or already
112*02c50d82SAndre Fischer         processed then wait with processing them until more requests are
113*02c50d82SAndre Fischer         present.
114*02c50d82SAndre Fischer     */
115*02c50d82SAndre Fischer     static sal_uInt32 snWaitForMoreRequestsCount;
116*02c50d82SAndre Fischer 
117*02c50d82SAndre Fischer     MasterPageContainerQueue (const ::boost::weak_ptr<ContainerAdapter>& rpContainer);
118*02c50d82SAndre Fischer     void LateInit (void);
119*02c50d82SAndre Fischer 
120*02c50d82SAndre Fischer     /** Calculate the priority that defines the order in which requests
121*02c50d82SAndre Fischer         are processed.
122*02c50d82SAndre Fischer     */
123*02c50d82SAndre Fischer     sal_Int32 CalculatePriority (const SharedMasterPageDescriptor& rDescriptor) const;
124*02c50d82SAndre Fischer 
125*02c50d82SAndre Fischer     DECL_LINK(DelayedPreviewCreation, Timer *);
126*02c50d82SAndre Fischer };
127*02c50d82SAndre Fischer 
128*02c50d82SAndre Fischer } } // end of namespace sd::sidebar
129*02c50d82SAndre Fischer 
130*02c50d82SAndre Fischer #endif
131