Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / sd / source / ui / sidebar / MasterPageContainerQueue.hxx
blob092af203e894adf26da587088f8a86e737da854f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SD_SOURCE_UI_SIDEBAR_MASTERPAGECONTAINERQUEUE_HXX
21 #define INCLUDED_SD_SOURCE_UI_SIDEBAR_MASTERPAGECONTAINERQUEUE_HXX
23 #include "MasterPageContainer.hxx"
24 #include "MasterPageDescriptor.hxx"
26 #include <memory>
28 namespace sd { namespace sidebar {
30 /** The queue stores and processes all requests from a MasterPageContainer
31 for the creation of previews.
32 The order of request processing and its timing is controlled by a
33 heuristic that uses values given with each request and which is
34 controlled by various parameters that are described below.
36 class MasterPageContainerQueue final
38 public:
39 class ContainerAdapter {
40 public:
41 virtual bool UpdateDescriptor (
42 const SharedMasterPageDescriptor& rpDescriptor,
43 bool bForcePageObject,
44 bool bForcePreview,
45 bool bSendEvents) = 0;
47 protected:
48 ~ContainerAdapter() {}
51 static MasterPageContainerQueue* Create (
52 const std::weak_ptr<ContainerAdapter>& rpContainer);
53 ~MasterPageContainerQueue();
55 /** This method is typically called for entries in the container for
56 which GetPreviewState() returns OS_CREATABLE. The creation of the
57 preview is then scheduled to be executed asynchronously at a later
58 point in time. When the preview is available the change listeners
59 will be notified.
61 bool RequestPreview (const SharedMasterPageDescriptor& rDescriptor);
63 /** Return <TRUE/> when there is a request currently in the queue for
64 the given token.
66 bool HasRequest (MasterPageContainer::Token aToken) const;
68 /** Return <TRUE/> when there is at least one request in the queue.
70 bool IsEmpty() const;
72 /** After this call the queue does not wait anymore for requests with
73 higher priority when only a small number of requests with lower
74 priority are present. This method should be called when all
75 templates are inserted into the MasterPageContainer.
77 void ProcessAllRequests();
79 private:
80 std::weak_ptr<ContainerAdapter> mpWeakContainer;
81 class PreviewCreationRequest;
82 class RequestQueue;
83 std::unique_ptr<RequestQueue> mpRequestQueue;
84 Timer maDelayedPreviewCreationTimer;
85 sal_uInt32 mnRequestsServedCount;
87 // There are a couple of values that define various aspects of the
88 // heuristic that defines the order and timing in which requests for
89 // preview creation are processed.
91 /** The time to wait (in milliseconds) between the creation of previews.
93 static const sal_Int32 snDelayedCreationTimeout;
95 /** The time to wait when the system is not idle.
97 static const sal_Int32 snDelayedCreationTimeoutWhenNotIdle;
99 /** Requests for previews of master pages in a document have their
100 priority increased by this value.
102 static const sal_Int32 snMasterPagePriorityBoost;
104 /** When only requests which a priority lower than this threshold exist
105 and not many requests have been made yet then wait with processing
106 them until more requests are present.
108 static const sal_Int32 snWaitForMoreRequestsPriorityThreshold;
110 /** When only requests which a priority lower than a threshold exist
111 and not more requests than this number have been made or already
112 processed then wait with processing them until more requests are
113 present.
115 static sal_uInt32 snWaitForMoreRequestsCount;
117 explicit MasterPageContainerQueue (const std::weak_ptr<ContainerAdapter>& rpContainer);
118 void LateInit();
120 /** Calculate the priority that defines the order in which requests
121 are processed.
123 static sal_Int32 CalculatePriority (const SharedMasterPageDescriptor& rDescriptor);
125 DECL_LINK(DelayedPreviewCreation, Timer *, void);
128 } } // end of namespace sd::sidebar
130 #endif
132 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */