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
23 /* $XConsortium: Help.c /main/6 1996/10/29 17:08:14 mustafa $ */
24 /************************************<+>*************************************
25 ****************************************************************************
29 * COMPONENT_NAME: Desktop File Manager (dtfile)
31 * Description: Source file for the help dialog.
39 * MapFileTypeToHelpString
43 * (c) Copyright 1993, 1994, 1995 Hewlett-Packard Company
44 * (c) Copyright 1993, 1994, 1995 International Business Machines Corp.
45 * (c) Copyright 1993, 1994, 1995 Sun Microsystems, Inc.
46 * (c) Copyright 1993, 1994, 1995 Novell, Inc.
48 ****************************************************************************
49 ************************************<+>*************************************/
55 #include <sys/types.h>
62 #include <Xm/DialogS.h>
63 #include <Xm/VendorSEP.h>
64 #include <Xm/MwmUtil.h>
66 #include <X11/ShellP.h>
67 #include <X11/Shell.h>
68 #include <X11/Xatom.h>
69 #include <Xm/Protocols.h>
71 #include <Dt/Action.h>
72 #include <Dt/Connect.h>
73 #include <Dt/DtNlUtils.h>
77 #include "SharedProcs.h"
79 #include <Dt/HelpDialog.h>
85 #include "SharedMsgs.h"
88 /* Resource definitions for the help dialog */
90 static DialogResource resources[] =
92 { "idString", XmRString, sizeof(String),
93 XtOffset(HelpDataPtr, idString),
94 (caddr_t) NULL, _DtStringToString },
96 { "volString", XmRString, sizeof(String),
97 XtOffset(HelpDataPtr, volString),
98 (caddr_t) NULL, _DtStringToString },
100 { "topicTitle", XmRString, sizeof(String),
101 XtOffset(HelpDataPtr, topicTitle),
102 (caddr_t) NULL, _DtStringToString },
104 { "fileType", XmRString, sizeof(String),
105 XtOffset(HelpDataPtr, fileType),
106 (caddr_t) NULL, _DtStringToString },
108 { "helpType", XmRInt, sizeof(int),
109 XtOffset(HelpDataPtr, helpType),
110 (caddr_t) DtHELP_TYPE_TOPIC, _DtIntToString },
114 static char * HELP_DIALOG = "HelpDialog";
116 /******** Static Function Declarations ********/
121 Widget *return_widget,
123 static void InstallClose(
125 XtCallbackProc callback,
126 XtPointer clientData) ;
127 static XtPointer GetValues(
129 static XtPointer GetDefaultValues( void ) ;
130 static XtPointer GetResourceValues(
131 XrmDatabase data_base,
133 static void SetValues(
135 HelpData *helpData) ;
136 static void WriteResourceValues(
140 static void FreeValues(
141 HelpData *helpData) ;
143 /******** End Static Function Declarations ********/
146 * The Dialog Class structure.
149 static DialogClass helpClassRec =
153 (DialogCreateProc)Create,
154 (DialogInstallChangeProc)NULL,
155 (DialogInstallCloseProc)InstallClose,
156 (DialogDestroyProc)_DtGenericDestroy,
157 (DialogGetValuesProc)GetValues,
158 (DialogGetDefaultValuesProc)GetDefaultValues,
159 (DialogGetResourceValuesProc)GetResourceValues,
160 (DialogSetValuesProc)SetValues,
161 (DialogWriteResourceValuesProc)WriteResourceValues,
162 (DialogFreeValuesProc)FreeValues,
163 (DialogMapWindowProc)_DtGenericMapWindow,
164 (DialogSetFocusProc)NULL,
167 DialogClass * helpClass = (DialogClass *) &helpClassRec;
172 /************************************************************************
176 ************************************************************************/
182 Widget *return_widget,
191 /* Allocate the audio annotation dialog instance record. */
193 helpRec = (HelpRec *) XtMalloc(sizeof(HelpRec));
196 /* Create the canned help dialog. */
198 helpDialog = DtCreateHelpDialog(parent, "helpDialog", args, 0);
200 /* Fill in our instance structure */
201 helpRec->shell = XtParent(helpDialog);
202 helpRec->helpDialog = helpDialog;
204 /* Set the return values for the dialog widget and dialog instance. */
205 *return_widget = helpDialog;
206 *dialog = (XtPointer) helpRec;
210 /************************************************************************
214 ************************************************************************/
219 XtCallbackProc callback,
220 XtPointer clientData )
223 XtAddCallback(helpRec->helpDialog, DtNcloseCallback, callback,
228 /************************************************************************
232 ************************************************************************/
239 DialogData * dialog_data;
246 /* Allocate and initialize the help dialog data. */
248 helpData = (HelpData *) XtMalloc(sizeof(HelpData));
250 helpData->displayed = True;
253 XtSetArg(args[n], XmNx, &helpData->x); n++;
254 XtSetArg(args[n], XmNy, &helpData->y); n++;
255 XtSetArg(args[n], XmNwidth, &helpData->width); n++;
256 XtSetArg(args[n], XmNheight, &helpData->height); n++;
257 XtGetValues(helpRec->helpDialog, args, n);
259 dialog_data = _DtGetInstanceData((XtPointer)helpRec);
260 oldData = (HelpData *) dialog_data->data;
261 helpData->idString = XtNewString(oldData->idString);
262 helpData->volString = XtNewString(oldData->volString);
263 helpData->topicTitle = XtNewString(oldData->topicTitle);
264 helpData->fileType = XtNewString(oldData->fileType);
265 helpData->helpType = oldData->helpType;
267 return((XtPointer)helpData);
273 /************************************************************************
277 ************************************************************************/
280 GetDefaultValues( void )
286 /* Allocate and initialize the default help dialog data. */
287 helpData = (HelpData *) XtMalloc(sizeof(HelpData));
289 helpData->displayed = False;
292 helpData->height = 0;
295 helpData->idString = NULL;
296 helpData->volString = NULL;
297 helpData->topicTitle = NULL;
298 helpData->fileType = NULL;
299 helpData->helpType = 0;
301 return((XtPointer) helpData);
307 /************************************************************************
311 ************************************************************************/
315 XrmDatabase data_base,
321 helpData = (HelpData *) XtMalloc(sizeof(HelpData));
323 _DtDialogGetResources(data_base, name_list, HELP_DIALOG, (char *)helpData,
324 resources, helpClass->resource_count);
326 /* We need copies of all strings returned by the resource manager */
327 if (helpData->idString)
328 helpData->idString = XtNewString(helpData->idString);
329 if (helpData->volString)
330 helpData->volString = XtNewString(helpData->volString);
331 if (helpData->topicTitle)
332 helpData->topicTitle = XtNewString(helpData->topicTitle);
333 if (helpData->fileType)
334 helpData->fileType = XtNewString(helpData->fileType);
336 return((XtPointer) helpData);
342 /************************************************************************
346 ************************************************************************/
356 String helpString = NULL;
357 DtHelpDialogWidget diaShell;
359 diaShell = (DtHelpDialogWidget)helpRec->helpDialog;
362 XtSetArg(args[n], DtNhelpVolume, helpData->volString); n++;
363 XtSetArg(args[n], DtNhelpType, (unsigned char) helpData->helpType); n++;
364 if (helpData->helpType == DtHELP_TYPE_TOPIC)
366 XtSetArg(args[n], DtNlocationId, helpData->idString); n++;
370 helpString = MapFileTypeToHelpString(helpData->idString,
372 XtSetArg(args[n], DtNstringData, helpString); n++;
373 XtSetArg(args[n], DtNtopicTitle, helpData->topicTitle); n++;
375 XtSetValues(helpRec->helpDialog, args, n);
377 diaShell = (DtHelpDialogWidget)helpRec->helpDialog;
383 /************************************************************************
385 * WriteResourceValues
387 ************************************************************************/
398 HelpData * helpData = (HelpData *) values->data;
403 unsigned char helpType;
407 /* If the dialog is currently displayed, update the geometry */
408 /* fields to their current values. */
409 if (helpData->displayed == True)
411 _DtGenericUpdateWindowPosition(values);
412 helpRec = (HelpRec *)_DtGetDialogInstance(values);
414 /* Get the current help volume and locationId */
416 XtSetArg(args[n], DtNhelpVolume, &volString); n++;
417 XtSetArg(args[n], DtNlocationId, &idString); n++;
418 XtSetArg(args[n], DtNtopicTitle, &topicTitle); n++;
419 XtSetArg(args[n], DtNstringData, &stringData); n++;
420 XtSetArg(args[n], DtNhelpType, &helpType); n++;
421 XtGetValues(helpRec->helpDialog, args, n);
422 XtFree(helpData->volString);
423 helpData->helpType = (int) helpType;
424 helpData->volString = XtNewString(volString);
425 if (helpData->helpType == DtHELP_TYPE_TOPIC)
427 XtFree(helpData->idString);
428 XtFree(helpData->topicTitle);
429 helpData->idString = XtNewString(idString);
430 helpData->topicTitle = NULL;
433 _DtDialogPutResources(fd, name_list, HELP_DIALOG, values->data,
434 resources, helpClass->resource_count);
440 /************************************************************************
444 ************************************************************************/
451 XtFree((char *) helpData->topicTitle);
452 XtFree((char *) helpData->idString);
453 XtFree((char *) helpData->volString);
454 XtFree((char *) helpData->fileType);
455 XtFree((char *) helpData);
460 * The application must free up the returned string.
461 * If 'miscData' is not NULL, then we are attempting to get the description
462 * for a specific action, as defined for a specific filetype.
466 MapFileTypeToHelpString(
478 /* Special case for the 2 built in directory commands */
479 if (strcmp(filetype, openNewView) == 0)
481 tmpStr = (GETMESSAGE(29,7, "The `%s` action opens a new File Manager view window\nof the requested folder."));
482 desc = XtNewString(tmpStr);
484 buf = XtMalloc(strlen(desc) + strlen(filetype) + 100);
485 sprintf(buf, desc, filetype);
489 if (strcmp(filetype, openInPlace) == 0)
492 (GETMESSAGE(29,8, "The `%s` action displays the requested folder in\nthe current File Manager view window."));
493 desc = XtNewString(tmpStr);
495 buf = XtMalloc(strlen(desc) + strlen(filetype) + 100);
496 sprintf(buf, desc, filetype);
501 desc = DtDtsDataTypeToAttributeValue(filetype,
502 DtDTS_DA_DESCRIPTION,
505 isAction = DtDtsDataTypeIsAction(filetype);
509 char *descptr = XtNewString(desc);
510 XtFree((char *)desc);
517 /* No description found for this filetype */
520 tmpStr=(GETMESSAGE(29,5, "There is no help available for the %s action"));
521 helpPattern = XtNewString(tmpStr);
526 (GETMESSAGE(29,6, "There is no help available for the %s filetype"));
527 helpPattern = XtNewString(tmpStr);
530 label = DtDtsDataTypeToAttributeValue(filetype,
535 buf = XtMalloc(strlen(label) + strlen(helpPattern) + 100);
536 sprintf(buf, helpPattern, label);
537 DtDtsFreeAttributeValue(label);
542 buf = XtMalloc(strlen(filetype) + strlen(helpPattern) + 100);
543 sprintf(buf, helpPattern, filetype);
547 DtDtsFreeAttributeValue(label);