1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: MasterPageContainerQueue.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef SD_TOOLPANEL_CONTROLS_MASTER_PAGE_CONTAINER_QUEUE_HXX
32 #define SD_TOOLPANEL_CONTROLS_MASTER_PAGE_CONTAINER_QUEUE_HXX
34 #include "MasterPageContainer.hxx"
35 #include "MasterPageDescriptor.hxx"
37 #include <boost/scoped_ptr.hpp>
38 #include <boost/weak_ptr.hpp>
40 namespace sd
{ namespace toolpanel
{ namespace controls
{
43 /** The queue stores and processes all requests from a MasterPageContainer
44 for the creation of previews.
45 The order of request processing and its timing is controlled by a
46 heuristic that uses values given with each request and which is
47 controlled by various parameters that are described below.
49 class MasterPageContainerQueue
52 class ContainerAdapter
{ public:
53 virtual bool UpdateDescriptor (
54 const SharedMasterPageDescriptor
& rpDescriptor
,
55 bool bForcePageObject
,
57 bool bSendEvents
) = 0;
60 static MasterPageContainerQueue
* Create (
61 const ::boost::weak_ptr
<ContainerAdapter
>& rpContainer
);
62 virtual ~MasterPageContainerQueue (void);
64 /** This method is typically called for entries in the container for
65 which GetPreviewState() returns OS_CREATABLE. The creation of the
66 preview is then scheduled to be executed asynchronously at a later
67 point in time. When the preview is available the change listeners
70 bool RequestPreview (const SharedMasterPageDescriptor
& rDescriptor
);
72 /** Return <TRUE/> when there is a request currently in the queue for
75 bool HasRequest (MasterPageContainer::Token aToken
) const;
77 /** Return <TRUE/> when there is at least one request in the queue.
79 bool IsEmpty (void) const;
81 /** After this call the queue does not wait anymore for requests with
82 higher priority when only a small number of requests with lower
83 priority are present. This method should be called when all
84 templates are inserted into the MasterPageContainer.
86 void ProcessAllRequests (void);
89 ::boost::weak_ptr
<ContainerAdapter
> mpWeakContainer
;
90 class PreviewCreationRequest
;
92 ::boost::scoped_ptr
<RequestQueue
> mpRequestQueue
;
93 Timer maDelayedPreviewCreationTimer
;
94 sal_uInt32 mnRequestsServedCount
;
96 // There are a couple of values that define various aspects of the
97 // heuristic that defines the order and timing in which requests for
98 // preview creation are processed.
100 /** The time to wait (in milliseconds) between the creation of previews.
102 static const sal_Int32 snDelayedCreationTimeout
;
104 /** The time to wait when the system is not idle.
106 static const sal_Int32 snDelayedCreationTimeoutWhenNotIdle
;
108 /** Requests for previews of master pages in a document have their
109 priority increased by this value.
111 static const sal_Int32 snMasterPagePriorityBoost
;
113 /** When only requests which a priority lower than this threshold exist
114 and not many requests have been made yet then wait with processing
115 them until more requests are present.
117 static const sal_Int32 snWaitForMoreRequestsPriorityThreshold
;
119 /** When only requests which a priority lower than a threshold exist
120 and not more requests than this number have been made or already
121 processed then wait with processing them until more requests are
124 static sal_uInt32 snWaitForMoreRequestsCount
;
126 MasterPageContainerQueue (const ::boost::weak_ptr
<ContainerAdapter
>& rpContainer
);
127 void LateInit (void);
129 /** Calculate the priority that defines the order in which requests
132 sal_Int32
CalculatePriority (const SharedMasterPageDescriptor
& rDescriptor
) const;
134 DECL_LINK(DelayedPreviewCreation
, Timer
*);
137 } } } // end of namespace ::sd::toolpanel::controls