dtinfo subtree dtinfo
[oweals/cde.git] / cde / programs / dtinfo / dtinfo / src / Agents / SearchHistoryListViewMotif.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 /*
24  * $XConsortium: SearchHistoryListViewMotif.C /main/10 1996/11/14 16:08:06 cde-hal $
25  *
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
30  * OR DISCLOSURE.
31  * 
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
36  * INTERNATIONAL, LTD.
37  * 
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.
43  *
44  *          HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
45  *                  1315 Dell Avenue
46  *                  Campbell, CA  95008
47  * 
48  */
49
50 #include "iostream"
51 using namespace std;
52
53 #include "UAS.hh"
54
55 #define C_List
56 #define C_TOC_Element
57 #define L_Basic
58
59
60 #define C_ResultID
61 #define L_OliasSearch
62
63 #define C_SearchHistoryListView
64 #define L_Agents
65
66 #include <Prelude.h>
67
68 #include "Other/XmStringLocalized.hh"
69 #include "Managers/CatMgr.hh"
70 #include "Managers/WString.hh"
71
72 #include "Registration.hh"
73
74 #include <WWL/WXmString.h>
75 #include <WWL/WXmList.h>
76 #include <WWL/WXmForm.h>
77 #include <WWL/WXmLabel.h>
78
79 #include <stdio.h>
80 // /////////////////////////////////////////////////////////////////////////
81 // display_list()
82 // put the list in the Motif List Widget -> f_list 
83 // /////////////////////////////////////////////////////////////////////////
84
85 XmString
86 SearchHistoryListView::display_value(FolioObject *object)
87 {
88   ResultID &rid = *(ResultID*)object;
89
90   char buf[8];
91   sprintf(buf, "%d", rid.ndocs());
92   WXmString matchString = buf;
93
94   UAS_Pointer<UAS_SearchResults> results = rid.results();  
95   WXmString scopeString = (char*)*results->scope_name();
96
97   WXmString queryString = rid.display_as();
98
99   XmFontList fontlist = f_list->FontList();
100
101   int number_width = WXmString("0").Width(fontlist) ;
102
103   WXmString matchPostfix(
104         window_system().make_space(
105                 8 * number_width - matchString.Width(fontlist),
106                 *f_list
107         ),
108         False);
109
110   int scope_field_width = 22 * number_width;
111
112   int allowance;
113
114   if ((allowance = scope_field_width - scopeString.Width(fontlist)) < 0)
115   {
116     char* dots = (char*)"...";
117
118     // need to free ungenerated at the end
119     char* ungenerated = (char*)(scopeString + WXmString(dots));
120
121     wchar_t* buf = WString(ungenerated);
122     wchar_t* ptr = buf + wcslen(buf) - (strlen(dots)+1);
123
124     XtFree(ungenerated);
125
126     WXmString stake;
127     WString wdots(dots);
128
129     do
130     {
131       char* str;
132       memcpy(ptr--, (wchar_t*)wdots, (strlen(dots)+1) * sizeof(wchar_t));
133
134       stake = str = WString(buf).get_mbstr();
135       allowance = scope_field_width - stake.Width(fontlist);
136
137       delete[] str;
138     }
139     while (allowance <= 0 && ptr >= buf);
140
141     while (*ptr <= (wchar_t)' ' && ptr >= buf)
142     {
143       char* str;
144       memcpy(ptr--, (wchar_t*)wdots, (strlen(dots)+1) * sizeof(wchar_t));
145
146       stake = str = WString(buf).get_mbstr();
147       allowance = scope_field_width - stake.Width(fontlist);
148
149       delete[] str;
150     }
151
152     scopeString = stake;
153   }
154
155   WXmString scopePostfix(
156         window_system().make_space(allowance, *f_list), False);
157
158   WXmString entry_string = matchString + matchPostfix +
159                            scopeString + scopePostfix +
160                            queryString;
161
162   return entry_string.disown();
163 }
164
165 void
166 SearchHistoryListView::child_create_ui_pre(WXmForm &form)
167 {
168   Widget header = WXmLabel(form, "header", WAutoManage);
169
170   XmFontList header_font;
171   {
172     XmFontList font;
173     XtVaGetValues(header, XmNfontList, &font, NULL);
174     header_font = XmFontListCopy(font);
175   }
176
177   if (window_system().dtinfo_space_font())
178     header_font = XmFontListAppendEntry(header_font,
179                                         window_system().dtinfo_space_font());
180
181   XtVaSetValues(header, XmNfontList, header_font, NULL);
182
183 #ifdef FONT_DEBUG
184   XmFontContext font_context;
185
186   if (XmFontListInitFontContext(&font_context, header_font))
187   {
188
189     XmFontListEntry fle = NULL;
190     do
191     {
192       if (fle = XmFontListNextEntry(font_context)) {
193         char* tag = XmFontListEntryGetTag(fle);
194         if (tag)
195           fprintf(stderr, "(DEBUG) tag=%s\n", tag);
196       }
197     }
198     while (fle);
199   
200     XmFontListFreeFontContext(font_context);
201   }
202 #endif
203
204   int number_width = WXmString("0").Width(header_font);
205
206   WXmString matchString = CATGETS(Set_AgentLabel, 246, "Matches");
207   WXmString scopeString = CATGETS(Set_AgentLabel, 243, "Scope");
208   WXmString queryString = CATGETS(Set_AgentLabel, 230, "Query");
209
210   int scope_offset = 8 * number_width;
211
212   if (matchString.Width(header_font) >= scope_offset)
213   {
214     char* dots = (char*)"...";
215
216     char* ungenerated = (char*)(matchString + WXmString(dots));
217
218     WString anonym_wstring = ungenerated; // important for digital compiler!
219     wchar_t* buf = (wchar_t*)anonym_wstring;
220     wchar_t* ptr = buf + wcslen(buf) - (strlen(dots)+1);
221
222     XtFree(ungenerated);
223
224     WXmString stake;
225     WString wdots(dots);    
226
227     int allowance;
228     do
229     {
230       char* str;
231       memcpy(ptr--, (wchar_t*)wdots, (strlen(dots)+1) * sizeof(wchar_t));
232
233       stake = str = WString(buf).get_mbstr();
234       
235       allowance = scope_offset - stake.Width(header_font);
236
237       delete[] str;
238     }
239     while (allowance <= 0 && ptr >= buf);
240
241     while (*ptr <= (wchar_t)' ' && ptr >= buf)
242     {
243       char* str;
244       memcpy(ptr--, (wchar_t*)wdots, (strlen(dots)+1) * sizeof(wchar_t));
245
246       stake = str = WString(buf).get_mbstr();
247       allowance = scope_offset - stake.Width(header_font);
248
249       delete[] str;
250     }
251     
252     matchString = stake;
253   }
254
255   WXmString matchPostfix(
256         window_system().make_space(
257                 scope_offset - matchString.Width(header_font),
258                 header
259         ),
260         False);
261   WXmString scopePostfix(
262         window_system().make_space(
263                 22 * number_width - scopeString.Width(header_font),
264                 header
265         ),
266         False);
267         
268   WXmString header_string = matchString + matchPostfix +
269                             scopeString + scopePostfix +
270                             queryString;
271                         
272   XtVaSetValues(header, XmNlabelString, (XmString)header_string, NULL);
273
274 }
275
276 void
277 SearchHistoryListView::display()
278 {
279 #ifdef VF_DEBUG
280   cerr << "ListView::display()...";  
281 #endif
282   ListView::display();
283 #ifdef VF_DEBUG
284   cerr << "done." << endl; 
285 #endif
286   XtVaSetValues(*f_shell, XmNtitle,
287         CATGETS(Set_SearchHistoryList, 1, "Dtinfo: Search History"), NULL);
288 }