52c7f3f1150975d6d3b979d47ae986449ea72de2
[oweals/cde.git] / cde / programs / dtinfo / dtinfo / src / Managers / SearchResultsMgr.C
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
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)
10  * any later version.
11  *
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
16  * details.
17  *
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
22  */
23 /*      Copyright (c) 1994 FUJITSU LIMITED      */
24 /*      All Rights Reserved                     */
25
26 /*
27  * $XConsortium: SearchResultsMgr.cc /main/5 1996/06/11 16:27:43 cde-hal $
28  *
29  * Copyright (c) 1991 HaL Computer Systems, Inc.  All rights reserved.
30  * UNPUBLISHED -- rights reserved under the Copyright Laws of the United
31  * States.  Use of a copyright notice is precautionary only and does not
32  * imply publication or disclosure.
33  * 
34  * This software contains confidential information and trade secrets of HaL
35  * Computer Systems, Inc.  Use, disclosure, or reproduction is prohibited
36  * without the prior express written permission of HaL Computer Systems, Inc.
37  * 
38  *                         RESTRICTED RIGHTS LEGEND
39  * Use, duplication, or disclosure by the Government is subject to
40  * restrictions as set forth in subparagraph (c)(l)(ii) of the Rights in
41  * Technical Data and Computer Software clause at DFARS 252.227-7013.
42  *                        HaL Computer Systems, Inc.
43  *                  1315 Dell Avenue, Campbell, CA  95008
44  *
45  */
46
47 #define C_ResultID
48 #define L_OliasSearch
49
50 #define C_NodeListMgr
51 #define C_SearchResultsMgr
52 #define L_Managers
53
54 #define C_NodeListAgent
55 #define C_SearchResultsAgent
56 #define L_Agents
57
58 #include "Prelude.h"
59
60 LONG_LIVED_CC(SearchResultsMgr,search_results_mgr);
61
62 // /////////////////////////////////////////////////////////////////
63 // class constructor
64 // /////////////////////////////////////////////////////////////////
65
66 SearchResultsMgr::SearchResultsMgr()
67 {
68 }
69
70
71 SearchResultsMgr::~SearchResultsMgr()
72 {
73   g_search_results_mgr = NULL;
74 }
75
76
77 // /////////////////////////////////////////////////////////////////
78 // display
79 // /////////////////////////////////////////////////////////////////
80
81 void
82 SearchResultsMgr::display (ResultID *results)
83 {
84   SearchResultsAgent *sra = get_agent();
85
86   // NOTE: error checking
87   // NOTE: save in f_active_agents
88   sra->display (results);
89
90   setStatus (eSuccess);
91 }
92
93 // /////////////////////////////////////////////////////////////////
94 // get_agent
95 // /////////////////////////////////////////////////////////////////
96
97 SearchResultsAgent *
98 SearchResultsMgr::get_agent ()
99 {
100   AgentListEntry *ale;
101   
102   // First try a non-retained visible window.
103   ale =  (AgentListEntry *)
104     f_active_agents.iterate (&SearchResultsMgr::check_entry, NULL);
105     
106   // If none are available, try the inactive list.
107   if (ale == NULL)
108     ale = (AgentListEntry *) next_inactive ();
109
110   // Finally, if none are available for reuse we have to create one.
111   if (ale == NULL)
112     {
113       ON_DEBUG (printf ("Creating a new results agent...take cover!\n");)
114       SearchResultsAgent *sra = new SearchResultsAgent();
115       sra->init ();
116       ale = new AgentListEntry (sra);
117       sra->set_agent_list_entry (ale);
118       activate (ale);
119     }
120
121   return ((SearchResultsAgent *) ale->agent());
122 }
123
124
125 // /////////////////////////////////////////////////////////////////
126 // check_entry
127 // /////////////////////////////////////////////////////////////////
128
129 bool
130 SearchResultsMgr::check_entry (ListEntry *le, void *)
131 {
132   AgentListEntry *ale = (AgentListEntry *) le;
133   SearchResultsAgent *sra = (SearchResultsAgent *) ale->agent();
134
135   if (sra->retain ())
136     return (TRUE);
137   else
138     return (FALSE);
139 }