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.
52 #define C_GlobalHistoryMgr
59 #define C_NodeHistoryAgent
64 LONG_LIVED_CC(GlobalHistoryMgr,global_history_mgr);
66 class NodeRecorder : public UAS_Receiver<UAS_DocumentRetrievedMsg>
70 { UAS_Common::request ((UAS_Receiver<UAS_DocumentRetrievedMsg> *)this); }
72 void receive (UAS_DocumentRetrievedMsg &message, void *client_data);
77 NodeRecorder::receive (UAS_DocumentRetrievedMsg &message, void *client_data)
79 extern bool g_style_sheet_update ;
80 if (!g_style_sheet_update)
81 global_history_mgr().add (message.fDoc);
84 static NodeRecorder node_recorder;
86 // /////////////////////////////////////////////////////////////////
88 // /////////////////////////////////////////////////////////////////
90 GlobalHistoryMgr::GlobalHistoryMgr()
91 : f_max_length (pref_mgr().get_int (PrefMgr::NodeHistSize)),
92 f_history_agent (NULL)
94 // It should default to 100 from the resource file, but just in case:
95 if (f_max_length <= 0)
97 UAS_Common::request ((UAS_Receiver<UAS_LibraryDestroyedMsg> *) this);
101 GlobalHistoryMgr::~GlobalHistoryMgr()
103 List_Iterator<UAS_Pointer<UAS_Common> > hl (f_history_list);
105 f_history_list.remove (hl);
106 delete f_history_agent;
110 // /////////////////////////////////////////////////////////////////
111 // display - display the agent
112 // /////////////////////////////////////////////////////////////////
115 GlobalHistoryMgr::display()
117 if (f_history_agent == NULL)
118 f_history_agent = new NodeHistoryAgent();
119 f_history_agent->display();
123 // /////////////////////////////////////////////////////////////////
124 // set_max_length - reset the maximum length
125 // /////////////////////////////////////////////////////////////////
128 GlobalHistoryMgr::set_max_length (int new_length)
130 f_max_length = new_length;
132 // Need to remove some entries if the current list is too long.
133 if (f_history_list.length() > f_max_length)
135 List_Iterator<UAS_Pointer<UAS_Common> > hl (f_history_list);
136 int count = f_history_list.length() - f_max_length;
138 ON_DEBUG (printf ("GlobalHistoryMgr: removing %d excess\n", count));
139 HistoryDelete delmsg;
141 delmsg.f_count = count;
142 UAS_Sender<HistoryDelete>::send_message (delmsg, 0);
146 f_history_list.remove (hl);
153 // /////////////////////////////////////////////////////////////////
154 // add - add a node to the history list
155 // /////////////////////////////////////////////////////////////////
158 GlobalHistoryMgr::add (UAS_Pointer<UAS_Common> &node_ptr)
160 // First see if the node is already in the history list.
161 List_Iterator<UAS_Pointer<UAS_Common> > hl (f_history_list);
164 for (i = 0; hl; hl++, i++)
166 ON_DEBUG (printf ("%2d: Checking <%s>\n", i, hl.item()->title()));
167 if (hl.item() == node_ptr)
171 if (hl) // Item exists, so remove it first.
173 HistoryDelete delmsg;
176 delmsg.f_moving = TRUE;
177 UAS_Sender<HistoryDelete>::send_message (delmsg, 0);
178 f_history_list.remove (hl);
180 else if (f_history_list.length() + 1 > f_max_length)
183 f_history_list.remove (hl);
184 HistoryDelete delmsg;
187 delmsg.f_moving = FALSE;
188 UAS_Sender<HistoryDelete>::send_message (delmsg, 0);
191 f_history_list.append (node_ptr);
193 HistoryAdd addmsg (node_ptr);
194 addmsg.f_moving = hl ? TRUE : FALSE;
195 UAS_Sender<HistoryAdd>::send_message (addmsg, 0);
199 GlobalHistoryMgr::receive (UAS_LibraryDestroyedMsg &msg, void *client_data) {
201 // Go through each element in the list, sending history
202 // delete messages for all docs contained in the dead library
205 List_Iterator<UAS_Pointer<UAS_Common> > hl (f_history_list);
207 if (hl.item()->get_library() == msg.fLib) {
208 HistoryDelete delmsg;
209 delmsg.f_index = curIndex;
211 delmsg.f_moving = FALSE;
212 UAS_Sender<HistoryDelete>::send_message (delmsg, 0);
213 f_history_list.remove (hl);