Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef SD_TOOLPANEL_CONTROLS_MASTER_PAGE_CONTAINER_QUEUE_HXX
30 : : #define SD_TOOLPANEL_CONTROLS_MASTER_PAGE_CONTAINER_QUEUE_HXX
31 : :
32 : : #include "MasterPageContainer.hxx"
33 : : #include "MasterPageDescriptor.hxx"
34 : :
35 : : #include <boost/scoped_ptr.hpp>
36 : : #include <boost/weak_ptr.hpp>
37 : :
38 : : namespace sd { namespace toolpanel { namespace controls {
39 : :
40 : :
41 : : /** The queue stores and processes all requests from a MasterPageContainer
42 : : for the creation of previews.
43 : : The order of request processing and its timing is controlled by a
44 : : heuristic that uses values given with each request and which is
45 : : controlled by various parameters that are described below.
46 : : */
47 : : class MasterPageContainerQueue
48 : : {
49 : : public:
50 : 0 : class ContainerAdapter {
51 : : public:
52 : : virtual bool UpdateDescriptor (
53 : : const SharedMasterPageDescriptor& rpDescriptor,
54 : : bool bForcePageObject,
55 : : bool bForcePreview,
56 : : bool bSendEvents) = 0;
57 : :
58 : : protected:
59 : 0 : ~ContainerAdapter() {}
60 : : };
61 : :
62 : : static MasterPageContainerQueue* Create (
63 : : const ::boost::weak_ptr<ContainerAdapter>& rpContainer);
64 : : virtual ~MasterPageContainerQueue (void);
65 : :
66 : : /** This method is typically called for entries in the container for
67 : : which GetPreviewState() returns OS_CREATABLE. The creation of the
68 : : preview is then scheduled to be executed asynchronously at a later
69 : : point in time. When the preview is available the change listeners
70 : : will be notified.
71 : : */
72 : : bool RequestPreview (const SharedMasterPageDescriptor& rDescriptor);
73 : :
74 : : /** Return <TRUE/> when there is a request currently in the queue for
75 : : the given token.
76 : : */
77 : : bool HasRequest (MasterPageContainer::Token aToken) const;
78 : :
79 : : /** Return <TRUE/> when there is at least one request in the queue.
80 : : */
81 : : bool IsEmpty (void) const;
82 : :
83 : : /** After this call the queue does not wait anymore for requests with
84 : : higher priority when only a small number of requests with lower
85 : : priority are present. This method should be called when all
86 : : templates are inserted into the MasterPageContainer.
87 : : */
88 : : void ProcessAllRequests (void);
89 : :
90 : : private:
91 : : ::boost::weak_ptr<ContainerAdapter> mpWeakContainer;
92 : : class PreviewCreationRequest;
93 : : class RequestQueue;
94 : : ::boost::scoped_ptr<RequestQueue> mpRequestQueue;
95 : : Timer maDelayedPreviewCreationTimer;
96 : : sal_uInt32 mnRequestsServedCount;
97 : :
98 : : // There are a couple of values that define various aspects of the
99 : : // heuristic that defines the order and timing in which requests for
100 : : // preview creation are processed.
101 : :
102 : : /** The time to wait (in milliseconds) between the creation of previews.
103 : : */
104 : : static const sal_Int32 snDelayedCreationTimeout;
105 : :
106 : : /** The time to wait when the system is not idle.
107 : : */
108 : : static const sal_Int32 snDelayedCreationTimeoutWhenNotIdle;
109 : :
110 : : /** Requests for previews of master pages in a document have their
111 : : priority increased by this value.
112 : : */
113 : : static const sal_Int32 snMasterPagePriorityBoost;
114 : :
115 : : /** When only requests which a priority lower than this threshold exist
116 : : and not many requests have been made yet then wait with processing
117 : : them until more requests are present.
118 : : */
119 : : static const sal_Int32 snWaitForMoreRequestsPriorityThreshold;
120 : :
121 : : /** When only requests which a priority lower than a threshold exist
122 : : and not more requests than this number have been made or already
123 : : processed then wait with processing them until more requests are
124 : : present.
125 : : */
126 : : static sal_uInt32 snWaitForMoreRequestsCount;
127 : :
128 : : MasterPageContainerQueue (const ::boost::weak_ptr<ContainerAdapter>& rpContainer);
129 : : void LateInit (void);
130 : :
131 : : /** Calculate the priority that defines the order in which requests
132 : : are processed.
133 : : */
134 : : sal_Int32 CalculatePriority (const SharedMasterPageDescriptor& rDescriptor) const;
135 : :
136 : : DECL_LINK(DelayedPreviewCreation, Timer *);
137 : : };
138 : :
139 : : } } } // end of namespace ::sd::toolpanel::controls
140 : :
141 : : #endif
142 : :
143 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|