2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
24 * $XConsortium: GlobalHistoryMgr.cc /main/5 1996/07/10 09:38:04 rcs $
26 * Copyright (c) 1993 HAL Computer Systems International, Ltd.
27 * All rights reserved. Unpublished -- rights reserved under
28 * the Copyright Laws of the United States. USE OF A COPYRIGHT
29 * NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
32 * THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
33 * SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. USE,
34 * DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
35 * PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
38 * RESTRICTED RIGHTS LEGEND
39 * Use, duplication, or disclosure by the Government is subject
40 * to the restrictions as set forth in subparagraph (c)(l)(ii)
41 * of the Rights in Technical Data and Computer Software clause
42 * at DFARS 252.227-7013.
44 * HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
53 #define C_GlobalHistoryMgr
60 #define C_NodeHistoryAgent
65 LONG_LIVED_CC(GlobalHistoryMgr,global_history_mgr);
67 class NodeRecorder : public UAS_Receiver<UAS_DocumentRetrievedMsg>
71 { UAS_Common::request ((UAS_Receiver<UAS_DocumentRetrievedMsg> *)this); }
73 void receive (UAS_DocumentRetrievedMsg &message, void *client_data);
78 NodeRecorder::receive (UAS_DocumentRetrievedMsg &message, void *client_data)
80 extern bool g_style_sheet_update ;
81 if (!g_style_sheet_update)
82 global_history_mgr().add (message.fDoc);
85 static NodeRecorder node_recorder;
87 // /////////////////////////////////////////////////////////////////
89 // /////////////////////////////////////////////////////////////////
91 GlobalHistoryMgr::GlobalHistoryMgr()
92 : f_max_length (pref_mgr().get_int (PrefMgr::NodeHistSize)),
93 f_history_agent (NULL)
95 // It should default to 100 from the resource file, but just in case:
96 if (f_max_length <= 0)
98 UAS_Common::request ((UAS_Receiver<UAS_LibraryDestroyedMsg> *) this);
102 GlobalHistoryMgr::~GlobalHistoryMgr()
104 List_Iterator<UAS_Pointer<UAS_Common> > hl (f_history_list);
106 f_history_list.remove (hl);
107 delete f_history_agent;
111 // /////////////////////////////////////////////////////////////////
112 // display - display the agent
113 // /////////////////////////////////////////////////////////////////
116 GlobalHistoryMgr::display()
118 if (f_history_agent == NULL)
119 f_history_agent = new NodeHistoryAgent();
120 f_history_agent->display();
124 // /////////////////////////////////////////////////////////////////
125 // set_max_length - reset the maximum length
126 // /////////////////////////////////////////////////////////////////
129 GlobalHistoryMgr::set_max_length (int new_length)
131 f_max_length = new_length;
133 // Need to remove some entries if the current list is too long.
134 if (f_history_list.length() > f_max_length)
136 List_Iterator<UAS_Pointer<UAS_Common> > hl (f_history_list);
137 int count = f_history_list.length() - f_max_length;
139 ON_DEBUG (printf ("GlobalHistoryMgr: removing %d excess\n", count));
140 HistoryDelete delmsg;
142 delmsg.f_count = count;
143 UAS_Sender<HistoryDelete>::send_message (delmsg, 0);
147 f_history_list.remove (hl);
154 // /////////////////////////////////////////////////////////////////
155 // add - add a node to the history list
156 // /////////////////////////////////////////////////////////////////
159 GlobalHistoryMgr::add (UAS_Pointer<UAS_Common> &node_ptr)
161 // First see if the node is already in the history list.
162 List_Iterator<UAS_Pointer<UAS_Common> > hl (f_history_list);
165 for (i = 0; hl; hl++, i++)
167 ON_DEBUG (printf ("%2d: Checking <%s>\n", i, (char*)hl.item()->title()));
168 if (hl.item() == node_ptr)
172 if (hl) // Item exists, so remove it first.
174 HistoryDelete delmsg;
177 delmsg.f_moving = TRUE;
178 UAS_Sender<HistoryDelete>::send_message (delmsg, 0);
179 f_history_list.remove (hl);
181 else if (f_history_list.length() + 1 > f_max_length)
184 f_history_list.remove (hl);
185 HistoryDelete delmsg;
188 delmsg.f_moving = FALSE;
189 UAS_Sender<HistoryDelete>::send_message (delmsg, 0);
192 f_history_list.append (node_ptr);
194 HistoryAdd addmsg (node_ptr);
195 addmsg.f_moving = hl ? TRUE : FALSE;
196 UAS_Sender<HistoryAdd>::send_message (addmsg, 0);
200 GlobalHistoryMgr::receive (UAS_LibraryDestroyedMsg &msg, void *client_data) {
202 // Go through each element in the list, sending history
203 // delete messages for all docs contained in the dead library
206 List_Iterator<UAS_Pointer<UAS_Common> > hl (f_history_list);
208 if (hl.item()->get_library() == msg.fLib) {
209 HistoryDelete delmsg;
210 delmsg.f_index = curIndex;
212 delmsg.f_moving = FALSE;
213 UAS_Sender<HistoryDelete>::send_message (delmsg, 0);
214 f_history_list.remove (hl);