1 /* $XConsortium: Help.c /main/6 1996/10/29 17:08:14 mustafa $ */
2 /************************************<+>*************************************
3 ****************************************************************************
7 * COMPONENT_NAME: Desktop File Manager (dtfile)
9 * Description: Source file for the help dialog.
17 * MapFileTypeToHelpString
21 * (c) Copyright 1993, 1994, 1995 Hewlett-Packard Company
22 * (c) Copyright 1993, 1994, 1995 International Business Machines Corp.
23 * (c) Copyright 1993, 1994, 1995 Sun Microsystems, Inc.
24 * (c) Copyright 1993, 1994, 1995 Novell, Inc.
26 ****************************************************************************
27 ************************************<+>*************************************/
33 #include <sys/types.h>
40 #include <Xm/DialogS.h>
41 #include <Xm/VendorSEP.h>
42 #include <Xm/MwmUtil.h>
44 #include <X11/ShellP.h>
45 #include <X11/Shell.h>
46 #include <X11/Xatom.h>
47 #include <Xm/Protocols.h>
49 #include <Dt/Action.h>
50 #include <Dt/Connect.h>
51 #include <Dt/DtNlUtils.h>
55 #include "SharedProcs.h"
57 #include <Dt/HelpDialog.h>
63 #include "SharedMsgs.h"
66 /* Resource definitions for the help dialog */
68 static DialogResource resources[] =
70 { "idString", XmRString, sizeof(String),
71 XtOffset(HelpDataPtr, idString),
72 (caddr_t) NULL, _DtStringToString },
74 { "volString", XmRString, sizeof(String),
75 XtOffset(HelpDataPtr, volString),
76 (caddr_t) NULL, _DtStringToString },
78 { "topicTitle", XmRString, sizeof(String),
79 XtOffset(HelpDataPtr, topicTitle),
80 (caddr_t) NULL, _DtStringToString },
82 { "fileType", XmRString, sizeof(String),
83 XtOffset(HelpDataPtr, fileType),
84 (caddr_t) NULL, _DtStringToString },
86 { "helpType", XmRInt, sizeof(int),
87 XtOffset(HelpDataPtr, helpType),
88 (caddr_t) DtHELP_TYPE_TOPIC, _DtIntToString },
92 static char * HELP_DIALOG = "HelpDialog";
94 /******** Static Function Declarations ********/
99 Widget *return_widget,
101 static void InstallClose(
103 XtCallbackProc callback,
104 XtPointer clientData) ;
105 static XtPointer GetValues(
107 static XtPointer GetDefaultValues( void ) ;
108 static XtPointer GetResourceValues(
109 XrmDatabase data_base,
111 static void SetValues(
113 HelpData *helpData) ;
114 static void WriteResourceValues(
118 static void FreeValues(
119 HelpData *helpData) ;
121 /******** End Static Function Declarations ********/
124 * The Dialog Class structure.
127 static DialogClass helpClassRec =
131 (DialogCreateProc)Create,
132 (DialogInstallChangeProc)NULL,
133 (DialogInstallCloseProc)InstallClose,
134 (DialogDestroyProc)_DtGenericDestroy,
135 (DialogGetValuesProc)GetValues,
136 (DialogGetDefaultValuesProc)GetDefaultValues,
137 (DialogGetResourceValuesProc)GetResourceValues,
138 (DialogSetValuesProc)SetValues,
139 (DialogWriteResourceValuesProc)WriteResourceValues,
140 (DialogFreeValuesProc)FreeValues,
141 (DialogMapWindowProc)_DtGenericMapWindow,
142 (DialogSetFocusProc)NULL,
145 DialogClass * helpClass = (DialogClass *) &helpClassRec;
150 /************************************************************************
154 ************************************************************************/
160 Widget *return_widget,
169 /* Allocate the audio annotation dialog instance record. */
171 helpRec = (HelpRec *) XtMalloc(sizeof(HelpRec));
174 /* Create the canned help dialog. */
176 helpDialog = DtCreateHelpDialog(parent, "helpDialog", args, 0);
178 /* Fill in our instance structure */
179 helpRec->shell = XtParent(helpDialog);
180 helpRec->helpDialog = helpDialog;
182 /* Set the return values for the dialog widget and dialog instance. */
183 *return_widget = helpDialog;
184 *dialog = (XtPointer) helpRec;
188 /************************************************************************
192 ************************************************************************/
197 XtCallbackProc callback,
198 XtPointer clientData )
201 XtAddCallback(helpRec->helpDialog, DtNcloseCallback, callback,
206 /************************************************************************
210 ************************************************************************/
217 DialogData * dialog_data;
224 /* Allocate and initialize the help dialog data. */
226 helpData = (HelpData *) XtMalloc(sizeof(HelpData));
228 helpData->displayed = True;
231 XtSetArg(args[n], XmNx, &helpData->x); n++;
232 XtSetArg(args[n], XmNy, &helpData->y); n++;
233 XtSetArg(args[n], XmNwidth, &helpData->width); n++;
234 XtSetArg(args[n], XmNheight, &helpData->height); n++;
235 XtGetValues(helpRec->helpDialog, args, n);
237 dialog_data = _DtGetInstanceData((XtPointer)helpRec);
238 oldData = (HelpData *) dialog_data->data;
239 helpData->idString = XtNewString(oldData->idString);
240 helpData->volString = XtNewString(oldData->volString);
241 helpData->topicTitle = XtNewString(oldData->topicTitle);
242 helpData->fileType = XtNewString(oldData->fileType);
243 helpData->helpType = oldData->helpType;
245 return((XtPointer)helpData);
251 /************************************************************************
255 ************************************************************************/
258 GetDefaultValues( void )
264 /* Allocate and initialize the default help dialog data. */
265 helpData = (HelpData *) XtMalloc(sizeof(HelpData));
267 helpData->displayed = False;
270 helpData->height = 0;
273 helpData->idString = NULL;
274 helpData->volString = NULL;
275 helpData->topicTitle = NULL;
276 helpData->fileType = NULL;
277 helpData->helpType = 0;
279 return((XtPointer) helpData);
285 /************************************************************************
289 ************************************************************************/
293 XrmDatabase data_base,
299 helpData = (HelpData *) XtMalloc(sizeof(HelpData));
301 _DtDialogGetResources(data_base, name_list, HELP_DIALOG, (char *)helpData,
302 resources, helpClass->resource_count);
304 /* We need copies of all strings returned by the resource manager */
305 if (helpData->idString)
306 helpData->idString = XtNewString(helpData->idString);
307 if (helpData->volString)
308 helpData->volString = XtNewString(helpData->volString);
309 if (helpData->topicTitle)
310 helpData->topicTitle = XtNewString(helpData->topicTitle);
311 if (helpData->fileType)
312 helpData->fileType = XtNewString(helpData->fileType);
314 return((XtPointer) helpData);
320 /************************************************************************
324 ************************************************************************/
334 String helpString = NULL;
335 DtHelpDialogWidget diaShell;
337 diaShell = (DtHelpDialogWidget)helpRec->helpDialog;
340 XtSetArg(args[n], DtNhelpVolume, helpData->volString); n++;
341 XtSetArg(args[n], DtNhelpType, (unsigned char) helpData->helpType); n++;
342 if (helpData->helpType == DtHELP_TYPE_TOPIC)
344 XtSetArg(args[n], DtNlocationId, helpData->idString); n++;
348 helpString = MapFileTypeToHelpString(helpData->idString,
350 XtSetArg(args[n], DtNstringData, helpString); n++;
351 XtSetArg(args[n], DtNtopicTitle, helpData->topicTitle); n++;
353 XtSetValues(helpRec->helpDialog, args, n);
355 diaShell = (DtHelpDialogWidget)helpRec->helpDialog;
361 /************************************************************************
363 * WriteResourceValues
365 ************************************************************************/
376 HelpData * helpData = (HelpData *) values->data;
381 unsigned char helpType;
385 /* If the dialog is currently displayed, update the geometry */
386 /* fields to their current values. */
387 if (helpData->displayed == True)
389 _DtGenericUpdateWindowPosition(values);
390 helpRec = (HelpRec *)_DtGetDialogInstance(values);
392 /* Get the current help volume and locationId */
394 XtSetArg(args[n], DtNhelpVolume, &volString); n++;
395 XtSetArg(args[n], DtNlocationId, &idString); n++;
396 XtSetArg(args[n], DtNtopicTitle, &topicTitle); n++;
397 XtSetArg(args[n], DtNstringData, &stringData); n++;
398 XtSetArg(args[n], DtNhelpType, &helpType); n++;
399 XtGetValues(helpRec->helpDialog, args, n);
400 XtFree(helpData->volString);
401 helpData->helpType = (int) helpType;
402 helpData->volString = XtNewString(volString);
403 if (helpData->helpType == DtHELP_TYPE_TOPIC)
405 XtFree(helpData->idString);
406 XtFree(helpData->topicTitle);
407 helpData->idString = XtNewString(idString);
408 helpData->topicTitle = NULL;
411 _DtDialogPutResources(fd, name_list, HELP_DIALOG, values->data,
412 resources, helpClass->resource_count);
418 /************************************************************************
422 ************************************************************************/
429 XtFree((char *) helpData->topicTitle);
430 XtFree((char *) helpData->idString);
431 XtFree((char *) helpData->volString);
432 XtFree((char *) helpData->fileType);
433 XtFree((char *) helpData);
438 * The application must free up the returned string.
439 * If 'miscData' is not NULL, then we are attempting to get the description
440 * for a specific action, as defined for a specific filetype.
444 MapFileTypeToHelpString(
456 /* Special case for the 2 built in directory commands */
457 if (strcmp(filetype, openNewView) == 0)
459 tmpStr = (GETMESSAGE(29,7, "The `%s` action opens a new File Manager view window\nof the requested folder."));
460 desc = XtNewString(tmpStr);
462 buf = XtMalloc(strlen(desc) + strlen(filetype) + 100);
463 sprintf(buf, desc, filetype);
467 if (strcmp(filetype, openInPlace) == 0)
470 (GETMESSAGE(29,8, "The `%s` action displays the requested folder in\nthe current File Manager view window."));
471 desc = XtNewString(tmpStr);
473 buf = XtMalloc(strlen(desc) + strlen(filetype) + 100);
474 sprintf(buf, desc, filetype);
481 /* The DtGetActionDescription function must be modified to
482 accept a non-integral second parameter. (Filetypes are no
483 longer expressed as integers. */
484 desc = DtGetActionDescription(filetype, -1);
487 desc = DtDtsDataTypeToAttributeValue(filetype,
488 DtDTS_DA_DESCRIPTION,
491 isAction = DtDtsDataTypeIsAction(filetype);
494 return(XtNewString(desc));
496 /* No description found for this filetype */
499 tmpStr=(GETMESSAGE(29,5, "There is no help available for the %s action"));
500 helpPattern = XtNewString(tmpStr);
505 (GETMESSAGE(29,6, "There is no help available for the %s filetype"));
506 helpPattern = XtNewString(tmpStr);
509 label = DtDtsDataTypeToAttributeValue(filetype,
514 buf = XtMalloc(strlen(label) + strlen(helpPattern) + 100);
515 sprintf(buf, helpPattern, label);
516 DtDtsFreeAttributeValue(label);
520 buf = XtMalloc(strlen(filetype) + strlen(helpPattern) + 100);
521 sprintf(buf, helpPattern, filetype);
525 DtDtsFreeAttributeValue(label);