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_TOOLPANEL_CONTROLS_RECENTLY_USED_MASTER_PAGES_HXX
29 #define SD_TOOLPANEL_CONTROLS_RECENTLY_USED_MASTER_PAGES_HXX
30 
31 #include "tools/SdGlobalResourceContainer.hxx"
32 #include <osl/mutex.hxx>
33 #include <tools/link.hxx>
34 #include <vcl/image.hxx>
35 #include <vector>
36 #include <tools/string.hxx>
37 
38 #include "DrawDocShell.hxx"
39 #include "MasterPageContainer.hxx"
40 #include <com/sun/star/uno/XInterface.hpp>
41 
42 class SdPage;
43 
44 namespace sd {
45 class MasterPageObserverEvent;
46 }
47 
48 
49 namespace sd { namespace toolpanel { namespace controls {
50 
51 /** This singleton holds a list of the most recently used master pages.
52 */
53 class RecentlyUsedMasterPages
54     : public SdGlobalResource
55 {
56 public:
57     /** Return the single instance of this class.
58     */
59     static RecentlyUsedMasterPages& Instance (void);
60 
61     void AddEventListener (const Link& rEventListener);
62     void RemoveEventListener (const Link& rEventListener);
63 
64     int GetMasterPageCount (void) const;
65     MasterPageContainer::Token GetTokenForIndex (sal_uInt32 nIndex) const;
66 
67 private:
68     /** The single instance of this class.  It is created on demand when
69         Instance() is called for the first time.
70     */
71     static RecentlyUsedMasterPages* mpInstance;
72 
73     ::std::vector<Link> maListeners;
74 
75     class MasterPageList;
76     ::std::auto_ptr<MasterPageList> mpMasterPages;
77     unsigned long int mnMaxListSize;
78     ::boost::shared_ptr<MasterPageContainer> mpContainer;
79 
80     RecentlyUsedMasterPages (void);
81     virtual ~RecentlyUsedMasterPages (void);
82 
83     /** Call this method after a new object has been created.
84     */
85     void LateInit (void);
86 
87     /// The copy constructor is not implemented.  Do not use!
88     RecentlyUsedMasterPages (const RecentlyUsedMasterPages&);
89 
90     /// The assignment operator is not implemented.  Do not use!
91     RecentlyUsedMasterPages& operator= (const RecentlyUsedMasterPages&);
92 
93     void SendEvent (void);
94     DECL_LINK(MasterPageChangeListener, MasterPageObserverEvent*);
95     DECL_LINK(MasterPageContainerChangeListener, MasterPageContainerChangeEvent*);
96 
97     /** Add a descriptor for the specified master page to the end of the
98         list of most recently used master pages.  When the page is already a
99         member of that list the associated descriptor is moved to the end of
100         the list to make it the most recently used entry.
101         @param bMakePersistent
102             When <TRUE/> is given then the new list of recently used master
103             pages is written back into the configuration to make it
104             persistent.  Giving <FALSE/> to ommit this is used while loading
105             the persistent list from the configuration.
106     */
107     void AddMasterPage (
108         MasterPageContainer::Token aToken,
109         bool bMakePersistent = true);
110 
111     /** Load the list of recently used master pages from the registry where
112         it was saved to make it persistent.
113     */
114     void LoadPersistentValues (void);
115 
116     /** Save the list of recently used master pages to the registry to make
117         it presistent.
118     */
119     void SavePersistentValues (void);
120 
121     void ResolveList (void);
122 };
123 
124 
125 
126 } } } // end of namespace ::sd::toolpanel::controls
127 
128 #endif
129