1 /* $XConsortium: HelpCB.c /main/7 1996/11/08 14:32:02 mustafa $ */
2 /************************************<+>*************************************
3 ****************************************************************************
7 * COMPONENT_NAME: Desktop File Manager (dtfile)
9 * Description: This file contains the help callbacks for the annotator.
11 * FUNCTIONS: DTHelpRequestCB
16 * LocateRecordStructure
17 * MapIconWidgetToFileType
20 * ReusePrimaryHelpWindow
22 * closeCB_mainHelpDialog
24 * (c) Copyright 1993, 1994, 1995 Hewlett-Packard Company
25 * (c) Copyright 1993, 1994, 1995 International Business Machines Corp.
26 * (c) Copyright 1993, 1994, 1995 Sun Microsystems, Inc.
27 * (c) Copyright 1993, 1994, 1995 Novell, Inc.
29 ****************************************************************************
30 ************************************<+>*************************************/
32 #include <sys/types.h>
34 #include <sys/param.h>
43 #include <Xm/MessageB.h>
44 #include <Xm/MwmUtil.h>
46 #include <X11/Shell.h>
47 #include <X11/Xatom.h>
49 #include <Xm/Protocols.h>
52 #include <Dt/UserMsg.h>
53 #include <Dt/DtNlUtils.h>
55 #include <Dt/Action.h>
58 #include <Dt/HelpDialog.h>
66 #include "SharedMsgs.h"
69 /******** Static Function Declarations ********/
71 static Boolean IsMainWinDialog(
72 DialogData *dialogData) ;
73 static XtPointer MapIconWidgetToFileType(
75 FileMgrData * fileMgrData) ;
76 static Boolean IsMenuWidget(
78 FileMgrRec * fileMgrRec,
79 FileMgrData * fileMgrData,
82 static Boolean IsFilterIcon(
84 FileMgrData * fileMgrData,
86 static Boolean ProcessItemHelp(
88 static void ReusePrimaryHelpWindow(
89 DialogData * primaryHelpDialog,
96 /******** End Static Function Declarations ********/
100 /************************************************************************
102 * The main help callback
104 ************************************************************************/
109 XtPointer clientData,
113 XtPointer recordStruct;
114 DialogData * dialogData;
117 String topicTitle = NULL;
119 Boolean freeClientData;
125 /* Refresh the display */
126 /* printf ("in HelpRequestCB: clientdata=\"%s\"\n",(char *)clientData); */
129 if (recordStruct = LocateRecordStructure(w))
131 if (dialogData = _DtGetInstanceData(recordStruct))
133 if (IsMainWinDialog(dialogData))
135 FileMgrData * fileMgrData = (FileMgrData *)dialogData->data;
136 FileMgrRec * fileMgrRec = (FileMgrRec *)recordStruct;
138 /* Check for item help */
139 if (clientData && strcmp(clientData, HELP_HELP_MODE_STR) == 0)
141 if( !ProcessItemHelp( fileMgrRec->shell ) )
143 char *tmpStr, *title, *msg;
145 tmpStr = GetSharedMessage(ITEM_HELP_ERROR_TITLE);
146 title = XtNewString(tmpStr);
148 if( fileMgrData->toolbox )
150 tmpStr = GetSharedMessage( AMITEM_HELP_ERROR );
151 msg = XtNewString(tmpStr);
155 tmpStr = GetSharedMessage( ITEM_HELP_ERROR ),
156 msg = XtNewString(tmpStr);
159 _DtMessage(fileMgrRec->shell, title, msg, NULL,
166 /* Item help comes in with a NULL client data */
171 helpType = DtHELP_TYPE_TOPIC;
172 freeClientData = False;
176 if(fileMgrData->selected_file_count > 1)
183 XtSetArg(args[n], XmNokLabelString, okXmString); n++;
184 XtSetArg(args[n], XmNcancelLabelString, cancelXmString); n++;
185 s = GETMESSAGE(29,10, "Help is not available for multiple selected objects.");
186 xmstr = XmStringCreateLocalized(s);
188 XtSetArg(args[n], XmNmessageString, xmstr); n++;
189 XtSetArg(args[n], XmNtitle, (GETMESSAGE(29,1, "File Manager Help"))); n++;
191 warn = XmCreateWarningDialog(fileMgrRec->shell, "warn_msg", args, n);
193 XtUnmanageChild(XmMessageBoxGetChild(warn,XmDIALOG_HELP_BUTTON));
200 /* Action/Filetype Help */
201 topicTitle = GetSharedMessage(ACTION_FT_HELP_TITLE);
202 helpType = DtHELP_TYPE_DYNAMIC_STRING;
205 /* Determine string, and set clientData accordingly */
207 MapIconWidgetToFileType(w, fileMgrData)) == NULL)
209 /* Not a file icon; is it an action menu item? */
210 if (!IsMenuWidget(w, fileMgrRec, fileMgrData, &strVal,
213 if (! IsFilterIcon(w, fileMgrData, &strVal))
216 clientData = (XtPointer)strVal;
218 freeClientData = True;
221 /* printf ("topic = %s\n", clientData); */
223 /* Special check for 'Using Help'; required different volume */
224 locId = (char *)clientData;
225 if ((w == *usingHelp) && (strcmp(locId, HELP_HOME_TOPIC) == 0))
228 vol = fileMgrData->helpVol;
230 if (fileMgrData->primaryHelpDialog)
232 ReusePrimaryHelpWindow( fileMgrData->primaryHelpDialog,
233 clientData, vol, topicTitle,
238 /* Create the main help window for this view */
239 ShowHelpDialog(fileMgrRec->shell, (XtPointer)fileMgrRec,
241 NULL, clientData, vol,
242 topicTitle, fileType, helpType);
255 Widget mainHelpDialog=NULL;
259 XtSetArg(args[0],XmNuserData,&mainHelpDialog);
260 XtGetValues(w,args,1);
262 XtSetArg(args[i], DtNhelpType,(unsigned char) DtHELP_TYPE_TOPIC); i++;
263 XtSetArg(args[i], DtNhelpVolume, DTFILE_HELP_NAME); i++;
264 XtSetArg(args[i], DtNlocationId, clientData); i++;
265 XtSetArg(args[i], XmNtitle, (GETMESSAGE(29,1, "File Manager Help")));i++;
266 if(!mainHelpDialog || ( mainHelpDialog && !XtIsManaged(mainHelpDialog)) )
269 mainHelpDialog = DtCreateHelpDialog(w, "mainHelpDialog", args, i);
270 XtAddCallback(mainHelpDialog, DtNcloseCallback,
271 closeCB_mainHelpDialog,
273 XtManageChild(mainHelpDialog);
274 XtSetArg(args[0],XmNuserData,mainHelpDialog);
275 XtSetValues(w,args,1);
278 XtSetValues(mainHelpDialog, args, i);
283 /************************************************************************
285 * The main help callback for desktop items
287 ************************************************************************/
292 XtPointer clientData,
299 String topicTitle = NULL;
301 String filetypeOrActionName;
302 String fileType = NULL;
304 /* Refresh the display */
308 * For all of the following cases, the desktop information is
309 * attached as userData to the direct child of the closest shell.
311 if ((dtInfo = (DesktopRec *)LocateRecordStructure(w)) == NULL)
315 * If the clientData is not NULL, then it represents the topic string.
319 helpType = DtHELP_TYPE_TOPIC;
320 filetypeOrActionName = clientData;
324 /* Context sensitive help (menu items or the file icon) */
325 if (XtParent(w) == desktop_data->popupMenu->popup)
328 * One of the action related menu items. The command
329 * string for the action is attached as userData.
331 topicTitle = GetSharedMessage(ACTION_FT_HELP_TITLE);
332 helpType = DtHELP_TYPE_DYNAMIC_STRING;
333 XtSetArg(args[0], XmNuserData, &filetypeOrActionName);
334 XtGetValues(w, args, 1);
336 /* Get the filetype from the active item */
337 fileType = dtInfo->file_view_data->file_data->logical_type;
341 /* The desktop icon itself */
342 topicTitle = GetSharedMessage(ACTION_FT_HELP_TITLE);
343 helpType = DtHELP_TYPE_DYNAMIC_STRING;
345 /* Determine string, and set clientData accordingly */
346 filetypeOrActionName = dtInfo->file_view_data->file_data->logical_type;
350 /* printf ("topic = %s\n", filetypeOrActionName); */
351 for(i=0;i<desktop_data->numWorkspaces;i++)
352 if(desktop_data->workspaceData[i]->number == dtInfo->workspace_num)
354 if(desktop_data->workspaceData[i]->primaryHelpDialog)
356 ReusePrimaryHelpWindow(desktop_data->workspaceData[i]->primaryHelpDialog,
357 filetypeOrActionName, DTFILE_HELP_NAME,
358 topicTitle, fileType, helpType);
362 /* Create the main help window for this workspace */
363 ShowDTHelpDialog(NULL, i, MAIN_HELP_DIALOG,
364 NULL, filetypeOrActionName, DTFILE_HELP_NAME,
365 topicTitle, fileType, helpType);
371 /************************************************************************
373 * The trash window's help callback
375 ************************************************************************/
380 XtPointer clientData,
388 /* Refresh the display */
391 /* printf ("topic = %s\n", clientData); */
393 /* Check for item help */
394 if (strcmp(clientData, HELP_HELP_MODE_STR) == 0)
396 if( ! ProcessItemHelp(trashShell) )
398 char *tmpStr, *title, *msg;
400 tmpStr = GetSharedMessage(ITEM_HELP_ERROR_TITLE);
401 title = XtNewString(tmpStr);
403 tmpStr = GetSharedMessage( ITEM_HELP_ERROR ),
404 msg = XtNewString(tmpStr);
406 _DtMessage(trashShell, title, msg, NULL,
414 /* Special check for 'Using Help'; required different volume */
415 locId = (char *)clientData;
416 if ((w == *usingHelpTrash) && (strcmp(locId, HELP_HOME_TOPIC) == 0))
419 vol = DTFILE_HELP_NAME;
421 if (primaryTrashHelpDialog)
423 ReusePrimaryHelpWindow(primaryTrashHelpDialog,
424 clientData, vol, NULL, NULL, DtHELP_TYPE_TOPIC);
428 /* Create the main help window for this view */
429 ShowTrashHelpDialog(trashShell, MAIN_HELP_DIALOG, NULL, clientData,
436 * Given a widget, trace up through its ancestors, until you come to the
437 * shell. Get the userData from the shell's child; this gets the 'record'
438 * structure, which can then be used to determine which view's help window
443 LocateRecordStructure(
450 while (XtParent(w) && !XtIsShell(XtParent(w)))
455 XtSetArg(args[0], XmNuserData, &recordPtr);
456 XtGetValues(w, args, 1);
465 * Check to see if this is the dialog data for one of the top level
466 * application windows.
471 DialogData * dialogData )
476 for (i = 0; i < view_count; i++)
478 if (view_set[i]->dialog_data == (XtPointer)dialogData)
482 if( (FileMgrData *)dialogData->data == trashFileMgrData)
489 * The application must free up the returned string.
493 MapIconWidgetToFileType(
495 FileMgrData * fileMgrData )
503 /* Based on whether in directory graph mode */
504 if (fileMgrData->show_type == SINGLE_DIRECTORY)
507 directoryCount = fileMgrData->directory_count;
509 for (i = directoryCount - 1; i >= 0; i--)
511 for (j = 0; j < fileMgrData->directory_set[i]->file_count; j++)
513 if (w == fileMgrData->directory_set[i]->file_view_data[j]->widget)
516 fileMgrData->directory_set[i]->file_view_data[j]->file_data->logical_type;
517 return (XtNewString(ftName));
522 /* The icon was unknown; should never happen */
529 * This function takes a widget, and determines if it is one of the
530 * menu buttons in the action menupane, or the action popup. If so,
531 * then it returns the action name and the associated filetype string.
533 * The caller must free up the returned string values.
539 FileMgrRec * fileMgrRec,
540 FileMgrData * fileMgrData,
546 CompositeWidget action_pane = (CompositeWidget)fileMgrRec->action_pane;
550 if (action_pane == NULL)
553 /* First, check if this is a menubar item */
554 for (i = 0; i < action_pane->composite.num_children; i++)
556 if (w == action_pane->composite.children[i])
558 XtSetArg(args[0], XmNuserData, &actionName);
559 XtGetValues(w, args, 1);
560 *aName = XtNewString(actionName);
562 /* Get the filetype from the active item */
563 *ftName = XtNewString(
564 fileMgrData->selection_list[0]->file_data->logical_type);
569 /* Secondly, check if this is a fileMgr popup item */
570 if (XtParent(w) == fileMgrPopup.menu)
572 XtSetArg(args[0], XmNuserData, &actionName);
573 XtGetValues(w, args, 1);
574 *aName = XtNewString(actionName);
576 /* Get the filetype from the active item */
577 *ftName = XtNewString(
578 fileMgrData->popup_menu_icon->file_data->logical_type);
579 fileMgrData->popup_menu_icon = NULL;
583 /* This was not a menu item */
590 * This function takes a widget, and determines if it is one of the
591 * filetype icons in the filter dialog. If so, then it returns the
592 * filetype string associated with the icon.
594 * The caller must free up the returned string values.
600 FileMgrData * fileMgrData,
605 DialogData * filterEditDialogData;
606 FilterData * filterData;
607 FilterRec * filterRec;
608 FTData * filterEntryData;
610 filterEditDialogData = fileMgrData->filter_edit;
611 if (!filterEditDialogData)
614 filterData = (FilterData *)filterEditDialogData->data;
616 if (!filterData->displayed)
619 filterRec = (FilterRec *) _DtGetDialogInstance(filterEditDialogData);
621 /* Check if the parent of the widget is the filter's drawingArea */
622 if (XtParent(w) != filterRec->file_window)
626 * Each icon in the filter dialog has attached as its userData a
627 * pointer to a structure of information about the associated
628 * filetype; get this structure, to get the filetype index.
630 XtSetArg(args[0], XmNuserData, &filterEntryData);
631 XtGetValues(w, args, 1);
632 *ftName = XtNewString(filterEntryData->filetype);
642 Widget selectedWidget;
645 returnVal = DtHelpReturnSelectedWidgetId(shell, NULL, &selectedWidget);
648 case DtHELP_SELECT_VALID:
650 while (!XtIsShell(selectedWidget))
652 if (XtHasCallbacks(selectedWidget, XmNhelpCallback)
653 == XtCallbackHasSome)
655 XtCallCallbacks(selectedWidget,
656 XmNhelpCallback, NULL);
660 selectedWidget = XtParent(selectedWidget);
665 case DtHELP_SELECT_INVALID:
668 case DtHELP_SELECT_ABORT:
669 case DtHELP_SELECT_ERROR:
678 ReusePrimaryHelpWindow(
679 DialogData * primaryHelpDialog,
689 String helpString = NULL;
693 /* Reuse the existing main help window for this view */
694 helpData = (HelpData *)primaryHelpDialog->data;
695 XtFree(helpData->idString);
696 XtFree(helpData->volString);
697 XtFree(helpData->topicTitle);
698 XtFree(helpData->fileType);
699 helpData->idString = XtNewString(idString);
700 helpData->volString = XtNewString(volume);
701 helpData->topicTitle = XtNewString(topicTitle);
702 helpData->fileType = XtNewString(fileType);
703 helpData->helpType = helpType;
704 helpRec = (HelpRec *) _DtGetDialogInstance(primaryHelpDialog);
706 XtSetArg(args[n], DtNhelpType, (unsigned char )helpType); n++;
707 XtSetArg(args[n], DtNhelpType, helpType); n++;
708 if (helpType == DtHELP_TYPE_TOPIC)
710 XtSetArg(args[n], DtNlocationId, helpData->idString); n++;
714 helpString = MapFileTypeToHelpString(helpData->idString,
716 XtSetArg(args[n], DtNstringData, helpString); n++;
717 XtSetArg(args[n], DtNtopicTitle, helpData->topicTitle); n++;
719 XtSetValues(helpRec->helpDialog, args, n);
726 XtPointer clientData,
730 XtCallCallbacks((Widget)clientData, XmNhelpCallback, NULL);
734 /******************************************************************************/
736 /* closeCB_mainHelpDialog */
738 /* INPUT: Widget wid - widget id */
739 /* XtPointer cd - client data */
740 /* XtPointer cbs - callback data */
743 /******************************************************************************/
746 closeCB_mainHelpDialog(Widget wid, XtPointer client_data,
749 XtDestroyWidget(wid);