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: HelpAgent.C /main/16 1996/11/26 12:49:50 cde-hal $
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_WindowSystem
66 #include "Other/XmStringLocalized.hh"
67 #include "Managers/CatMgr.hh"
69 #include "Registration.hh"
71 // HGL Help include file:
72 // #include "Help/Help.h"
74 #include "WWL/WXmPrimitive.h"
75 #include "WWL/WXmManager.h"
76 #include "WWL/WXmPushButton.h"
77 #include "WWL/WXmPushButtonGadget.h"
78 #include <X11/cursorfont.h>
80 //#include <Dt/HelpQuickD.h>
82 #include <Dt/HelpDialog.h>
86 #define CLASS HelpAgent
87 #include "create_macros.hh"
89 #include "external-api/olias.h"
91 /******** The onitem cursor (32x32, xbm format) ********/
92 #define onitem32_width 32
93 #define onitem32_height 32
94 #define onitem32_x_hot 0
95 #define onitem32_y_hot 0
96 static unsigned char onitem32_bits[] = {
97 0xff, 0xff, 0xff, 0xff, 0xfd, 0xff, 0x1f, 0xfc, 0xf9, 0xff, 0xe7, 0xf3,
98 0xf1, 0xff, 0xfb, 0xef, 0xe1, 0xff, 0xfd, 0xdf, 0xc1, 0xff, 0xfd, 0xdf,
99 0x83, 0xff, 0xfe, 0xbf, 0x03, 0xff, 0x7e, 0x7e, 0x03, 0xfe, 0xbe, 0x7d,
100 0x03, 0xfc, 0xbe, 0x7d, 0x03, 0xf0, 0xc1, 0x7d, 0x03, 0xe0, 0xff, 0x7e,
101 0x07, 0xc0, 0x7f, 0xbf, 0x07, 0x80, 0xbf, 0xbf, 0x07, 0x00, 0xde, 0xdf,
102 0x07, 0x00, 0xdc, 0xef, 0x07, 0x00, 0xdf, 0xf7, 0x07, 0x80, 0xdf, 0xfb,
103 0x0f, 0xc0, 0xdf, 0xfb, 0x0f, 0xc0, 0xdf, 0xfb, 0x0f, 0x81, 0xdf, 0xfb,
104 0xcf, 0x83, 0x3f, 0xfc, 0xef, 0x07, 0xff, 0xff, 0xff, 0x07, 0xff, 0xff,
105 0xff, 0x0f, 0x3e, 0xfc, 0xff, 0x0f, 0xde, 0xfb, 0xff, 0x1f, 0xdc, 0xfb,
106 0xff, 0x1f, 0xdc, 0xfb, 0xff, 0x3f, 0xd8, 0xfb, 0xff, 0x3f, 0x3c, 0xfc,
107 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
109 #define onitem32_m_width 32
110 #define onitem32_m_height 32
111 #define onitem32_m_x_hot 0
112 #define onitem32_m_y_hot 0
113 static unsigned char onitem32_m_bits[] = {
114 0x03, 0x00, 0x00, 0x00, 0x07, 0x00, 0xe0, 0x03, 0x0f, 0x00, 0xf8, 0x0f,
115 0x1f, 0x00, 0xfc, 0x1f, 0x3f, 0x00, 0xfe, 0x3f, 0x7f, 0x00, 0xfe, 0x3f,
116 0xfe, 0x00, 0xff, 0x7f, 0xfe, 0x01, 0xff, 0xff, 0xfe, 0x03, 0x7f, 0xfe,
117 0xfe, 0x0f, 0x7f, 0xfe, 0xfe, 0x1f, 0x3e, 0xfe, 0xfe, 0x3f, 0x00, 0xff,
118 0xfc, 0x7f, 0x80, 0x7f, 0xfc, 0xff, 0xc1, 0x7f, 0xfc, 0xff, 0xe3, 0x3f,
119 0xfc, 0xff, 0xe7, 0x1f, 0xfc, 0xff, 0xe3, 0x0f, 0xfc, 0xff, 0xe0, 0x07,
120 0xf8, 0x7f, 0xe0, 0x07, 0xf8, 0x7f, 0xe0, 0x07, 0xf8, 0xff, 0xe0, 0x07,
121 0xf8, 0xfe, 0xc0, 0x03, 0x38, 0xfc, 0x01, 0x00, 0x18, 0xfc, 0x01, 0x00,
122 0x00, 0xf8, 0xc3, 0x03, 0x00, 0xf8, 0xe3, 0x07, 0x00, 0xf0, 0xe7, 0x07,
123 0x00, 0xf0, 0xe7, 0x07, 0x00, 0xe0, 0xef, 0x07, 0x00, 0xe0, 0xc7, 0x03,
124 0x00, 0xc0, 0x03, 0x00, 0x00, 0x80, 0x00, 0x00};
126 #define NULL_LOCATORID "__HaL__DefaultLocatorId__"
128 HelpAgent *HelpAgent::g_help_agent;
130 // /////////////////////////////////////////////////////////////////
132 // /////////////////////////////////////////////////////////////////
134 HelpAgent::HelpAgent()
137 Widget app_shell = window_system().toplevel();
138 f_cursor = create_help_cursor(app_shell);
142 // /////////////////////////////////////////////////////////////////
144 // /////////////////////////////////////////////////////////////////
146 HelpAgent::~HelpAgent()
152 // /////////////////////////////////////////////////////////////////
154 // /////////////////////////////////////////////////////////////////
157 HelpAgent::create_ui()
161 Widget app_shell = window_system().toplevel();
162 f_appXrmDb = XrmGetDatabase (XtDisplay (app_shell));
165 XtSetArg(args[n], XmNtitle, "Dtinfo Help"); n++;
166 f_helper = DtCreateHelpDialog(app_shell,
172 // /////////////////////////////////////////////////////////////////
174 // /////////////////////////////////////////////////////////////////
176 HelpAgent::display_help (Widget w)
178 char* locator_id=get_locator_id(w);
179 if(locator_id == NULL)
181 message_mgr().error_dialog ((char*)UAS_String(
182 CATGETS(Set_Messages, 3, "No help available")));
188 if (f_helper == NULL)
190 XtVaSetValues(f_helper,
191 DtNhelpType, DtHELP_TYPE_TOPIC,
192 DtNhelpVolume, "Infomgr",
193 DtNlocationId, locator_id,
194 XmNdialogStyle, XmDIALOG_MODELESS,
197 XtManageChild(f_helper);
202 HelpAgent::display_help (const String locatoridResourceString)
206 if (f_helper == NULL)
215 cerr << "Resource string: " << locatoridResourceString << endl;
216 if(XrmGetResource(f_appXrmDb, locatoridResourceString,
217 locatoridResourceString, &type, &value ))
220 cerr << "Value: " << value.addr << endl;
221 XtVaSetValues(f_helper,
222 DtNhelpType, DtHELP_TYPE_TOPIC,
223 DtNhelpVolume, "Infomgr",
224 DtNlocationId, value.addr,
225 XmNdialogStyle, XmDIALOG_MODELESS,
227 XtManageChild(f_helper);
232 message_mgr().error_dialog (UAS_String(
233 CATGETS(Set_Messages, 3, "No help available")));
241 Widget app_shell = window_system().toplevel();
242 Widget parent = XtParent(f_helper);
243 //XRaiseWindow(XtDisplay(parent), XtWindow(parent));
244 UAS_List<UAS_String> env_infolibs(env().infolibs());
245 library_mgr().init(env_infolibs);
247 XMapRaised(XtDisplay(app_shell), XtWindow(app_shell));
248 XMapRaised(XtDisplay(parent), XtWindow(parent));
252 // /////////////////////////////////////////////////////////////////
253 // Help Callback Functions
254 // /////////////////////////////////////////////////////////////////
255 // This provides F1 help support
258 helpCB(Widget w, XtPointer, XtPointer)
260 help_agent().help_cb(w);
264 HelpAgent::add_help_cb (Widget w)
266 XtAddCallback(w, XmNhelpCallback, helpCB, NULL);
270 HelpAgent::help_cb (Widget w)
276 // /////////////////////////////////////////////////////////////////
277 // Context Help functions
278 // /////////////////////////////////////////////////////////////////
279 // This provides context-sensitive help
282 contextHelpCB(Widget w, XtPointer, XtPointer)
284 help_agent().context_help(w);
288 HelpAgent::add_context_help (Widget w)
290 XtAddCallback(w, XmNactivateCallback, contextHelpCB, NULL);
294 HelpAgent::context_help(Widget widget)
296 while(!XtIsSubclass(widget, topLevelShellWidgetClass))
297 widget = XtParent(widget);
302 Widget sel_widget = XmTrackingEvent(widget, f_cursor, False, &event);
303 if (sel_widget != NULL)
304 display_help(sel_widget);
308 // /////////////////////////////////////////////////////////////////
309 // Activate Help functions
310 // /////////////////////////////////////////////////////////////////
311 // This provides help for help buttons and help menu items.
312 // Widgets that register an activate callback also need a help
316 activateHelpCB(Widget w, XtPointer client_data, XtPointer)
318 help_agent().activate_help(w, (String)client_data);
322 HelpAgent::add_activate_help (Widget w, const String locator_id)
324 XtAddCallback(w, XmNactivateCallback, activateHelpCB, (XtPointer)locator_id);
329 HelpAgent::add_activate_help (WXmPushButton& w, const String locator_id)
331 XtAddCallback((Widget)w, XmNactivateCallback, activateHelpCB, (XtPointer)locator_id);
335 HelpAgent::add_activate_help (WXmPushButtonGadget& w, const String locator_id)
337 XtAddCallback((Widget)w, XmNactivateCallback, activateHelpCB, (XtPointer)locator_id);
341 HelpAgent::activate_help (Widget w, String locator_id)
343 if (locator_id != NULL)
344 display_help(locator_id);
350 void HelpAgent::add_context_help (WXmPrimitive &w)
352 w.SetHelpCallback (this, (WWL_FUN) &HelpAgent::context_help_cb);
355 void HelpAgent::add_context_help (WXmManager &w)
357 w.SetHelpCallback (this, (WWL_FUN) &HelpAgent::context_help_cb);
361 HelpAgent::add_context_help(WXmPushButton &pb, int context)
363 pb.SetHelpCallback (this, (WWL_FUN) &HelpAgent::context_help_cb);
364 //pb.SetActivateCallback (this, (WWL_FUN) &HelpAgent::context_help_cb,
365 // (XtPointer) context);
369 HelpAgent::add_context_help(WXmPushButtonGadget &pb, int context)
371 pb.SetActivateCallback (this, (WWL_FUN) &HelpAgent::context_help_cb,
372 (XtPointer) context);
376 HelpAgent::add_activate_help (WXmPushButton &pb, const String card_id)
378 pb.SetActivateCallback (this, (WWL_FUN) &HelpAgent::help_cb,
383 HelpAgent::add_activate_help (WXmPushButtonGadget &pbg, const String card_id)
385 pbg.SetActivateCallback (this, (WWL_FUN) &HelpAgent::help_cb,
390 HelpAgent::add_activate_help (Widget w, const String card_id)
392 pbg.SetActivateCallback (this, (WWL_FUN) &HelpAgent::help_cb,
398 HelpAgent::get_locator_id(const Widget w)
401 //res.resource_name = (resourceName ? (String)resourceName : "helpcard");
402 res.resource_name = "helpcard";
403 res.resource_class = XtCString;
404 res.resource_type = XtRString;
405 res.resource_size = sizeof(String);
406 res.resource_offset = 0;
407 res.default_type = XtRString;
408 res.default_addr = NULL_LOCATORID;
410 char *wname = XtName(w); // Just for gdb
412 XtGetApplicationResources(w, &string, &res, 1, NULL, 0);
416 UAS_String wname = XtName(w);
418 Widget parent = XtParent(w);
419 while(parent != NULL)
421 UAS_String Parent(XtName(parent));
422 wname = Parent + dot + wname;
423 parent = XtParent(parent);
425 cerr << "Widget: " << (char*)wname << endl;
428 if ( strcmp(string, NULL_LOCATORID)==0 )
430 // Locator id not found, look for it in a parent
431 //cerr << "Locator id not found, searching parent" << endl;
432 Widget parent = XtParent(w);
433 while(parent != NULL)
435 XtGetApplicationResources(parent, &string, &res, 1, NULL, 0);
436 if ( strcmp(string, NULL_LOCATORID)==0 ) // Not found
437 parent = XtParent(parent);
441 cerr << "Parent Locator is: " << string << endl;
449 cerr << "Locator is: " << string << endl;
454 HelpAgent::create_help_cursor(Widget parent)
456 Display *display = XtDisplay(parent);
457 Screen *retScr = XtScreen(parent);
458 int screen = XScreenNumberOfScreen(retScr);
463 unsigned int xHotspot;
464 unsigned int yHotspot;
470 width = onitem32_width;
471 height = onitem32_height;
472 bits = (char *) onitem32_bits;
473 maskBits = (char *) onitem32_m_bits;
474 xHotspot = onitem32_x_hot;
475 yHotspot = onitem32_y_hot;
477 pixmap = XCreateBitmapFromData (display,
478 RootWindowOfScreen(XtScreen(parent)), bits,
482 maskPixmap = XCreateBitmapFromData (display,
483 RootWindowOfScreen(XtScreen(parent)), maskBits,
486 xcolors[0].pixel = BlackPixelOfScreen(ScreenOfDisplay(display, screen));
487 xcolors[1].pixel = WhitePixelOfScreen(ScreenOfDisplay(display, screen));
489 XQueryColors (display,
490 DefaultColormapOfScreen(ScreenOfDisplay(display, screen)), xcolors, 2);
492 cursor = XCreatePixmapCursor (display, pixmap, maskPixmap,
493 &(xcolors[0]), &(xcolors[1]),
495 XFreePixmap (display, pixmap);
496 XFreePixmap (display, maskPixmap);