1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef SD_UPDATE_LOCK_MANAGER_HXX
29 #define SD_UPDATE_LOCK_MANAGER_HXX
30 
31 #include <memory>
32 
33 namespace sd {
34 
35 class ViewShellBase;
36 
37 /** Manage update locks of ViewShellBase objects.
38     A ViewShellBase object is locked while views are switched in order to
39     avoid unnecessary repaints of views and object bars.
40     Locking a ViewShellBase locks the frame::XLayoutManager and prevents
41     Activate() and Deactivate() calls at ViewShell objects being processed.
42 
43     The main responsibility of this class is find the right moment to unlock
44     the managed ViewShellBase object: Only Lock() has to be called from the
45     outside (usually from PaneManager).  Unlock() is called by this class
46     itself.  When all else fails it has a timer that calls Unlock()
47     eventually.
48 */
49 class UpdateLockManager
50 {
51 public:
52     /** The newly created instance supports locking for the specified
53         ViewShellBase object by default.  Call Disable() for Lock() and
54         Unlock() calls being ignored.
55     */
56     UpdateLockManager (ViewShellBase& rBase);
57     ~UpdateLockManager (void);
58 
59     /** For e.g. the PresentationViewShellBase locking is not necessary and
60         does lead to problems.  This method lets Lock() and Unlock() calls
61         be ignored and thus turns locking essentially off.
62     */
63     void Disable (void);
64 
65     /** Lock some UI updates.  For every call to this method a call to
66         Unlock() is required to really unlock.
67     */
68     void Lock (void);
69 
70     /** When called as many times as Lock() has been called before then the
71         ViewShellBase object is unlocked.
72     */
73     void Unlock (void);
74 
75     /** Return whether the ViewShellBase object is locked.  When locking is
76         disabled, i.e. Disable() has been called before, then this method
77         always returns <FALSE/>.
78     */
79     bool IsLocked (void) const;
80 
81 private:
82     class Implementation;
83     Implementation* mpImpl;
84 
85     UpdateLockManager (const UpdateLockManager&); // Not supported.
86     UpdateLockManager& operator= (const UpdateLockManager&); // Not supported.
87 };
88 
89 } // end of namespace sd
90 
91 #endif
92 
93