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: HelpCB.c /main/7 1996/11/08 14:32:02 mustafa $ */
24 /************************************<+>*************************************
25 ****************************************************************************
29 * COMPONENT_NAME: Desktop File Manager (dtfile)
31 * Description: This file contains the help callbacks for the annotator.
33 * FUNCTIONS: DTHelpRequestCB
38 * LocateRecordStructure
39 * MapIconWidgetToFileType
42 * ReusePrimaryHelpWindow
44 * closeCB_mainHelpDialog
46 * (c) Copyright 1993, 1994, 1995 Hewlett-Packard Company
47 * (c) Copyright 1993, 1994, 1995 International Business Machines Corp.
48 * (c) Copyright 1993, 1994, 1995 Sun Microsystems, Inc.
49 * (c) Copyright 1993, 1994, 1995 Novell, Inc.
51 ****************************************************************************
52 ************************************<+>*************************************/
54 #include <sys/types.h>
56 #include <sys/param.h>
64 #include <Xm/MessageB.h>
65 #include <Xm/MwmUtil.h>
67 #include <X11/Shell.h>
68 #include <X11/Xatom.h>
70 #include <Xm/Protocols.h>
73 #include <Dt/UserMsg.h>
74 #include <Dt/DtNlUtils.h>
76 #include <Dt/Action.h>
79 #include <Dt/HelpDialog.h>
87 #include "SharedMsgs.h"
90 /******** Static Function Declarations ********/
92 static Boolean IsMainWinDialog(
93 DialogData *dialogData) ;
94 static XtPointer MapIconWidgetToFileType(
96 FileMgrData * fileMgrData) ;
97 static Boolean IsMenuWidget(
99 FileMgrRec * fileMgrRec,
100 FileMgrData * fileMgrData,
103 static Boolean IsFilterIcon(
105 FileMgrData * fileMgrData,
107 static Boolean ProcessItemHelp(
109 static void ReusePrimaryHelpWindow(
110 DialogData * primaryHelpDialog,
117 /******** End Static Function Declarations ********/
121 /************************************************************************
123 * The main help callback
125 ************************************************************************/
130 XtPointer clientData,
134 XtPointer recordStruct;
135 DialogData * dialogData;
138 String topicTitle = NULL;
140 Boolean freeClientData;
146 /* Refresh the display */
147 /* printf ("in HelpRequestCB: clientdata=\"%s\"\n",(char *)clientData); */
150 if (recordStruct = LocateRecordStructure(w))
152 if (dialogData = _DtGetInstanceData(recordStruct))
154 if (IsMainWinDialog(dialogData))
156 FileMgrData * fileMgrData = (FileMgrData *)dialogData->data;
157 FileMgrRec * fileMgrRec = (FileMgrRec *)recordStruct;
159 /* Check for item help */
160 if (clientData && strcmp(clientData, HELP_HELP_MODE_STR) == 0)
162 if( !ProcessItemHelp( fileMgrRec->shell ) )
164 char *tmpStr, *title, *msg;
166 tmpStr = GetSharedMessage(ITEM_HELP_ERROR_TITLE);
167 title = XtNewString(tmpStr);
169 if( fileMgrData->toolbox )
171 tmpStr = GetSharedMessage( AMITEM_HELP_ERROR );
172 msg = XtNewString(tmpStr);
176 tmpStr = GetSharedMessage( ITEM_HELP_ERROR ),
177 msg = XtNewString(tmpStr);
180 _DtMessage(fileMgrRec->shell, title, msg, NULL,
187 /* Item help comes in with a NULL client data */
192 helpType = DtHELP_TYPE_TOPIC;
193 freeClientData = False;
197 if(fileMgrData->selected_file_count > 1)
204 XtSetArg(args[n], XmNokLabelString, okXmString); n++;
205 XtSetArg(args[n], XmNcancelLabelString, cancelXmString); n++;
206 s = GETMESSAGE(29,10, "Help is not available for multiple selected objects.");
207 xmstr = XmStringCreateLocalized(s);
209 XtSetArg(args[n], XmNmessageString, xmstr); n++;
210 XtSetArg(args[n], XmNtitle, (GETMESSAGE(29,1, "File Manager Help"))); n++;
212 warn = XmCreateWarningDialog(fileMgrRec->shell, "warn_msg", args, n);
214 XtUnmanageChild(XmMessageBoxGetChild(warn,XmDIALOG_HELP_BUTTON));
221 /* Action/Filetype Help */
222 topicTitle = GetSharedMessage(ACTION_FT_HELP_TITLE);
223 helpType = DtHELP_TYPE_DYNAMIC_STRING;
226 /* Determine string, and set clientData accordingly */
228 MapIconWidgetToFileType(w, fileMgrData)) == NULL)
230 /* Not a file icon; is it an action menu item? */
231 if (!IsMenuWidget(w, fileMgrRec, fileMgrData, &strVal,
234 if (! IsFilterIcon(w, fileMgrData, &strVal))
237 clientData = (XtPointer)strVal;
239 freeClientData = True;
242 /* printf ("topic = %s\n", clientData); */
244 /* Special check for 'Using Help'; required different volume */
245 locId = (char *)clientData;
246 if ((w == *usingHelp) && (strcmp(locId, HELP_HOME_TOPIC) == 0))
249 vol = fileMgrData->helpVol;
251 if (fileMgrData->primaryHelpDialog)
253 ReusePrimaryHelpWindow( fileMgrData->primaryHelpDialog,
254 clientData, vol, topicTitle,
259 /* Create the main help window for this view */
260 ShowHelpDialog(fileMgrRec->shell, (XtPointer)fileMgrRec,
262 NULL, clientData, vol,
263 topicTitle, fileType, helpType);
276 Widget mainHelpDialog=NULL;
280 XtSetArg(args[0],XmNuserData,&mainHelpDialog);
281 XtGetValues(w,args,1);
283 XtSetArg(args[i], DtNhelpType,(unsigned char) DtHELP_TYPE_TOPIC); i++;
284 XtSetArg(args[i], DtNhelpVolume, DTFILE_HELP_NAME); i++;
285 XtSetArg(args[i], DtNlocationId, clientData); i++;
286 XtSetArg(args[i], XmNtitle, (GETMESSAGE(29,1, "File Manager Help")));i++;
287 if(!mainHelpDialog || ( mainHelpDialog && !XtIsManaged(mainHelpDialog)) )
290 mainHelpDialog = DtCreateHelpDialog(w, "mainHelpDialog", args, i);
291 XtAddCallback(mainHelpDialog, DtNcloseCallback,
292 closeCB_mainHelpDialog,
294 XtManageChild(mainHelpDialog);
295 XtSetArg(args[0],XmNuserData,mainHelpDialog);
296 XtSetValues(w,args,1);
299 XtSetValues(mainHelpDialog, args, i);
304 /************************************************************************
306 * The main help callback for desktop items
308 ************************************************************************/
313 XtPointer clientData,
320 String topicTitle = NULL;
322 String filetypeOrActionName;
323 String fileType = NULL;
325 /* Refresh the display */
329 * For all of the following cases, the desktop information is
330 * attached as userData to the direct child of the closest shell.
332 if ((dtInfo = (DesktopRec *)LocateRecordStructure(w)) == NULL)
336 * If the clientData is not NULL, then it represents the topic string.
340 helpType = DtHELP_TYPE_TOPIC;
341 filetypeOrActionName = clientData;
345 /* Context sensitive help (menu items or the file icon) */
346 if (XtParent(w) == desktop_data->popupMenu->popup)
349 * One of the action related menu items. The command
350 * string for the action is attached as userData.
352 topicTitle = GetSharedMessage(ACTION_FT_HELP_TITLE);
353 helpType = DtHELP_TYPE_DYNAMIC_STRING;
354 XtSetArg(args[0], XmNuserData, &filetypeOrActionName);
355 XtGetValues(w, args, 1);
357 /* Get the filetype from the active item */
358 fileType = dtInfo->file_view_data->file_data->logical_type;
362 /* The desktop icon itself */
363 topicTitle = GetSharedMessage(ACTION_FT_HELP_TITLE);
364 helpType = DtHELP_TYPE_DYNAMIC_STRING;
366 /* Determine string, and set clientData accordingly */
367 filetypeOrActionName = dtInfo->file_view_data->file_data->logical_type;
371 /* printf ("topic = %s\n", filetypeOrActionName); */
372 for(i=0;i<desktop_data->numWorkspaces;i++)
373 if(desktop_data->workspaceData[i]->number == dtInfo->workspace_num)
375 if(desktop_data->workspaceData[i]->primaryHelpDialog)
377 ReusePrimaryHelpWindow(desktop_data->workspaceData[i]->primaryHelpDialog,
378 filetypeOrActionName, DTFILE_HELP_NAME,
379 topicTitle, fileType, helpType);
383 /* Create the main help window for this workspace */
384 ShowDTHelpDialog(NULL, i, MAIN_HELP_DIALOG,
385 NULL, filetypeOrActionName, DTFILE_HELP_NAME,
386 topicTitle, fileType, helpType);
392 /************************************************************************
394 * The trash window's help callback
396 ************************************************************************/
401 XtPointer clientData,
409 /* Refresh the display */
412 /* printf ("topic = %s\n", clientData); */
414 /* Check for item help */
415 if (strcmp(clientData, HELP_HELP_MODE_STR) == 0)
417 if( ! ProcessItemHelp(trashShell) )
419 char *tmpStr, *title, *msg;
421 tmpStr = GetSharedMessage(ITEM_HELP_ERROR_TITLE);
422 title = XtNewString(tmpStr);
424 tmpStr = GetSharedMessage( ITEM_HELP_ERROR ),
425 msg = XtNewString(tmpStr);
427 _DtMessage(trashShell, title, msg, NULL,
435 /* Special check for 'Using Help'; required different volume */
436 locId = (char *)clientData;
437 if ((w == *usingHelpTrash) && (strcmp(locId, HELP_HOME_TOPIC) == 0))
440 vol = DTFILE_HELP_NAME;
442 if (primaryTrashHelpDialog)
444 ReusePrimaryHelpWindow(primaryTrashHelpDialog,
445 clientData, vol, NULL, NULL, DtHELP_TYPE_TOPIC);
449 /* Create the main help window for this view */
450 ShowTrashHelpDialog(trashShell, MAIN_HELP_DIALOG, NULL, clientData,
457 * Given a widget, trace up through its ancestors, until you come to the
458 * shell. Get the userData from the shell's child; this gets the 'record'
459 * structure, which can then be used to determine which view's help window
464 LocateRecordStructure(
471 while (XtParent(w) && !XtIsShell(XtParent(w)))
476 XtSetArg(args[0], XmNuserData, &recordPtr);
477 XtGetValues(w, args, 1);
486 * Check to see if this is the dialog data for one of the top level
487 * application windows.
492 DialogData * dialogData )
497 for (i = 0; i < view_count; i++)
499 if (view_set[i]->dialog_data == (XtPointer)dialogData)
503 if( (FileMgrData *)dialogData->data == trashFileMgrData)
510 * The application must free up the returned string.
514 MapIconWidgetToFileType(
516 FileMgrData * fileMgrData )
524 /* Based on whether in directory graph mode */
525 if (fileMgrData->show_type == SINGLE_DIRECTORY)
528 directoryCount = fileMgrData->directory_count;
530 for (i = directoryCount - 1; i >= 0; i--)
532 for (j = 0; j < fileMgrData->directory_set[i]->file_count; j++)
534 if (w == fileMgrData->directory_set[i]->file_view_data[j]->widget)
537 fileMgrData->directory_set[i]->file_view_data[j]->file_data->logical_type;
538 return (XtNewString(ftName));
543 /* The icon was unknown; should never happen */
550 * This function takes a widget, and determines if it is one of the
551 * menu buttons in the action menupane, or the action popup. If so,
552 * then it returns the action name and the associated filetype string.
554 * The caller must free up the returned string values.
560 FileMgrRec * fileMgrRec,
561 FileMgrData * fileMgrData,
567 CompositeWidget action_pane = (CompositeWidget)fileMgrRec->action_pane;
571 if (action_pane == NULL)
574 /* First, check if this is a menubar item */
575 for (i = 0; i < action_pane->composite.num_children; i++)
577 if (w == action_pane->composite.children[i])
579 XtSetArg(args[0], XmNuserData, &actionName);
580 XtGetValues(w, args, 1);
581 *aName = XtNewString(actionName);
583 /* Get the filetype from the active item */
584 *ftName = XtNewString(
585 fileMgrData->selection_list[0]->file_data->logical_type);
590 /* Secondly, check if this is a fileMgr popup item */
591 if (XtParent(w) == fileMgrPopup.menu)
593 XtSetArg(args[0], XmNuserData, &actionName);
594 XtGetValues(w, args, 1);
595 *aName = XtNewString(actionName);
597 /* Get the filetype from the active item */
598 *ftName = XtNewString(
599 fileMgrData->popup_menu_icon->file_data->logical_type);
600 fileMgrData->popup_menu_icon = NULL;
604 /* This was not a menu item */
611 * This function takes a widget, and determines if it is one of the
612 * filetype icons in the filter dialog. If so, then it returns the
613 * filetype string associated with the icon.
615 * The caller must free up the returned string values.
621 FileMgrData * fileMgrData,
626 DialogData * filterEditDialogData;
627 FilterData * filterData;
628 FilterRec * filterRec;
629 FTData * filterEntryData;
631 filterEditDialogData = fileMgrData->filter_edit;
632 if (!filterEditDialogData)
635 filterData = (FilterData *)filterEditDialogData->data;
637 if (!filterData->displayed)
640 filterRec = (FilterRec *) _DtGetDialogInstance(filterEditDialogData);
642 /* Check if the parent of the widget is the filter's drawingArea */
643 if (XtParent(w) != filterRec->file_window)
647 * Each icon in the filter dialog has attached as its userData a
648 * pointer to a structure of information about the associated
649 * filetype; get this structure, to get the filetype index.
651 XtSetArg(args[0], XmNuserData, &filterEntryData);
652 XtGetValues(w, args, 1);
653 *ftName = XtNewString(filterEntryData->filetype);
663 Widget selectedWidget;
666 returnVal = DtHelpReturnSelectedWidgetId(shell, 0, &selectedWidget);
669 case DtHELP_SELECT_VALID:
671 while (!XtIsShell(selectedWidget))
673 if (XtHasCallbacks(selectedWidget, XmNhelpCallback)
674 == XtCallbackHasSome)
676 XtCallCallbacks(selectedWidget,
677 XmNhelpCallback, NULL);
681 selectedWidget = XtParent(selectedWidget);
686 case DtHELP_SELECT_INVALID:
689 case DtHELP_SELECT_ABORT:
690 case DtHELP_SELECT_ERROR:
699 ReusePrimaryHelpWindow(
700 DialogData * primaryHelpDialog,
710 String helpString = NULL;
714 /* Reuse the existing main help window for this view */
715 helpData = (HelpData *)primaryHelpDialog->data;
716 XtFree(helpData->idString);
717 XtFree(helpData->volString);
718 XtFree(helpData->topicTitle);
719 XtFree(helpData->fileType);
720 helpData->idString = XtNewString(idString);
721 helpData->volString = XtNewString(volume);
722 helpData->topicTitle = XtNewString(topicTitle);
723 helpData->fileType = XtNewString(fileType);
724 helpData->helpType = helpType;
725 helpRec = (HelpRec *) _DtGetDialogInstance(primaryHelpDialog);
727 XtSetArg(args[n], DtNhelpType, (unsigned char )helpType); n++;
728 XtSetArg(args[n], DtNhelpType, helpType); n++;
729 if (helpType == DtHELP_TYPE_TOPIC)
731 XtSetArg(args[n], DtNlocationId, helpData->idString); n++;
735 helpString = MapFileTypeToHelpString(helpData->idString,
737 XtSetArg(args[n], DtNstringData, helpString); n++;
738 XtSetArg(args[n], DtNtopicTitle, helpData->topicTitle); n++;
740 XtSetValues(helpRec->helpDialog, args, n);
747 XtPointer clientData,
751 XtCallCallbacks((Widget)clientData, XmNhelpCallback, NULL);
755 /******************************************************************************/
757 /* closeCB_mainHelpDialog */
759 /* INPUT: Widget wid - widget id */
760 /* XtPointer cd - client data */
761 /* XtPointer cbs - callback data */
764 /******************************************************************************/
767 closeCB_mainHelpDialog(Widget wid, XtPointer client_data,
770 XtDestroyWidget(wid);