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 libraries 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>
77 #include <Dt/SharedProcs.h>
80 #include <Dt/HelpDialog.h>
88 #include "SharedMsgs.h"
91 /******** Static Function Declarations ********/
93 static Boolean IsMainWinDialog(
94 DialogData *dialogData) ;
95 static XtPointer MapIconWidgetToFileType(
97 FileMgrData * fileMgrData) ;
98 static Boolean IsMenuWidget(
100 FileMgrRec * fileMgrRec,
101 FileMgrData * fileMgrData,
104 static Boolean IsFilterIcon(
106 FileMgrData * fileMgrData,
108 static Boolean ProcessItemHelp(
110 static void ReusePrimaryHelpWindow(
111 DialogData * primaryHelpDialog,
118 /******** End Static Function Declarations ********/
122 /************************************************************************
124 * The main help callback
126 ************************************************************************/
131 XtPointer clientData,
135 XtPointer recordStruct;
136 DialogData * dialogData;
139 String topicTitle = NULL;
141 Boolean freeClientData;
147 /* Refresh the display */
148 /* printf ("in HelpRequestCB: clientdata=\"%s\"\n",(char *)clientData); */
151 if (recordStruct = LocateRecordStructure(w))
153 if (dialogData = _DtGetInstanceData(recordStruct))
155 if (IsMainWinDialog(dialogData))
157 FileMgrData * fileMgrData = (FileMgrData *)dialogData->data;
158 FileMgrRec * fileMgrRec = (FileMgrRec *)recordStruct;
160 /* Check for item help */
161 if (clientData && strcmp(clientData, HELP_HELP_MODE_STR) == 0)
163 if( !ProcessItemHelp( fileMgrRec->shell ) )
165 char *tmpStr, *title, *msg;
167 tmpStr = GetSharedMessage(ITEM_HELP_ERROR_TITLE);
168 title = XtNewString(tmpStr);
170 if( fileMgrData->toolbox )
172 tmpStr = GetSharedMessage( AMITEM_HELP_ERROR );
173 msg = XtNewString(tmpStr);
177 tmpStr = GetSharedMessage( ITEM_HELP_ERROR ),
178 msg = XtNewString(tmpStr);
181 _DtMessage(fileMgrRec->shell, title, msg, NULL,
188 /* Item help comes in with a NULL client data */
193 helpType = DtHELP_TYPE_TOPIC;
194 freeClientData = False;
198 if(fileMgrData->selected_file_count > 1)
205 XtSetArg(args[n], XmNokLabelString, okXmString); n++;
206 XtSetArg(args[n], XmNcancelLabelString, cancelXmString); n++;
207 s = GETMESSAGE(29,10, "Help is not available for multiple selected objects.");
208 xmstr = XmStringCreateLocalized(s);
210 XtSetArg(args[n], XmNmessageString, xmstr); n++;
211 XtSetArg(args[n], XmNtitle, (GETMESSAGE(29,1, "File Manager Help"))); n++;
213 warn = XmCreateWarningDialog(fileMgrRec->shell, "warn_msg", args, n);
215 XtUnmanageChild(XmMessageBoxGetChild(warn,XmDIALOG_HELP_BUTTON));
222 /* Action/Filetype Help */
223 topicTitle = GetSharedMessage(ACTION_FT_HELP_TITLE);
224 helpType = DtHELP_TYPE_DYNAMIC_STRING;
227 /* Determine string, and set clientData accordingly */
229 MapIconWidgetToFileType(w, fileMgrData)) == NULL)
231 /* Not a file icon; is it an action menu item? */
232 if (!IsMenuWidget(w, fileMgrRec, fileMgrData, &strVal,
235 if (! IsFilterIcon(w, fileMgrData, &strVal))
238 clientData = (XtPointer)strVal;
240 freeClientData = True;
243 /* printf ("topic = %s\n", clientData); */
245 /* Special check for 'Using Help'; required different volume */
246 locId = (char *)clientData;
247 if ((w == *usingHelp) && (strcmp(locId, HELP_HOME_TOPIC) == 0))
250 vol = fileMgrData->helpVol;
252 if (fileMgrData->primaryHelpDialog)
254 ReusePrimaryHelpWindow( fileMgrData->primaryHelpDialog,
255 clientData, vol, topicTitle,
260 /* Create the main help window for this view */
261 ShowHelpDialog(fileMgrRec->shell, (XtPointer)fileMgrRec,
263 NULL, clientData, vol,
264 topicTitle, fileType, helpType);
277 Widget mainHelpDialog=NULL;
281 XtSetArg(args[0],XmNuserData,&mainHelpDialog);
282 XtGetValues(w,args,1);
284 XtSetArg(args[i], DtNhelpType,(unsigned char) DtHELP_TYPE_TOPIC); i++;
285 XtSetArg(args[i], DtNhelpVolume, DTFILE_HELP_NAME); i++;
286 XtSetArg(args[i], DtNlocationId, clientData); i++;
287 XtSetArg(args[i], XmNtitle, (GETMESSAGE(29,1, "File Manager Help")));i++;
288 if(!mainHelpDialog || ( mainHelpDialog && !XtIsManaged(mainHelpDialog)) )
291 mainHelpDialog = DtCreateHelpDialog(w, "mainHelpDialog", args, i);
292 XtAddCallback(mainHelpDialog, DtNcloseCallback,
293 closeCB_mainHelpDialog,
295 XtManageChild(mainHelpDialog);
296 XtSetArg(args[0],XmNuserData,mainHelpDialog);
297 XtSetValues(w,args,1);
300 XtSetValues(mainHelpDialog, args, i);
305 /************************************************************************
307 * The main help callback for desktop items
309 ************************************************************************/
314 XtPointer clientData,
321 String topicTitle = NULL;
323 String filetypeOrActionName;
324 String fileType = NULL;
326 /* Refresh the display */
330 * For all of the following cases, the desktop information is
331 * attached as userData to the direct child of the closest shell.
333 if ((dtInfo = (DesktopRec *)LocateRecordStructure(w)) == NULL)
337 * If the clientData is not NULL, then it represents the topic string.
341 helpType = DtHELP_TYPE_TOPIC;
342 filetypeOrActionName = clientData;
346 /* Context sensitive help (menu items or the file icon) */
347 if (XtParent(w) == desktop_data->popupMenu->popup)
350 * One of the action related menu items. The command
351 * string for the action is attached as userData.
353 topicTitle = GetSharedMessage(ACTION_FT_HELP_TITLE);
354 helpType = DtHELP_TYPE_DYNAMIC_STRING;
355 XtSetArg(args[0], XmNuserData, &filetypeOrActionName);
356 XtGetValues(w, args, 1);
358 /* Get the filetype from the active item */
359 fileType = dtInfo->file_view_data->file_data->logical_type;
363 /* The desktop icon itself */
364 topicTitle = GetSharedMessage(ACTION_FT_HELP_TITLE);
365 helpType = DtHELP_TYPE_DYNAMIC_STRING;
367 /* Determine string, and set clientData accordingly */
368 filetypeOrActionName = dtInfo->file_view_data->file_data->logical_type;
372 /* printf ("topic = %s\n", filetypeOrActionName); */
373 for(i=0;i<desktop_data->numWorkspaces;i++)
374 if(desktop_data->workspaceData[i]->number == dtInfo->workspace_num)
376 if(desktop_data->workspaceData[i]->primaryHelpDialog)
378 ReusePrimaryHelpWindow(desktop_data->workspaceData[i]->primaryHelpDialog,
379 filetypeOrActionName, DTFILE_HELP_NAME,
380 topicTitle, fileType, helpType);
384 /* Create the main help window for this workspace */
385 ShowDTHelpDialog(NULL, i, MAIN_HELP_DIALOG,
386 NULL, filetypeOrActionName, DTFILE_HELP_NAME,
387 topicTitle, fileType, helpType);
393 /************************************************************************
395 * The trash window's help callback
397 ************************************************************************/
402 XtPointer clientData,
410 /* Refresh the display */
413 /* printf ("topic = %s\n", clientData); */
415 /* Check for item help */
416 if (strcmp(clientData, HELP_HELP_MODE_STR) == 0)
418 if( ! ProcessItemHelp(trashShell) )
420 char *tmpStr, *title, *msg;
422 tmpStr = GetSharedMessage(ITEM_HELP_ERROR_TITLE);
423 title = XtNewString(tmpStr);
425 tmpStr = GetSharedMessage( ITEM_HELP_ERROR ),
426 msg = XtNewString(tmpStr);
428 _DtMessage(trashShell, title, msg, NULL,
436 /* Special check for 'Using Help'; required different volume */
437 locId = (char *)clientData;
438 if ((w == *usingHelpTrash) && (strcmp(locId, HELP_HOME_TOPIC) == 0))
441 vol = DTFILE_HELP_NAME;
443 if (primaryTrashHelpDialog)
445 ReusePrimaryHelpWindow(primaryTrashHelpDialog,
446 clientData, vol, NULL, NULL, DtHELP_TYPE_TOPIC);
450 /* Create the main help window for this view */
451 ShowTrashHelpDialog(trashShell, MAIN_HELP_DIALOG, NULL, clientData,
458 * Given a widget, trace up through its ancestors, until you come to the
459 * shell. Get the userData from the shell's child; this gets the 'record'
460 * structure, which can then be used to determine which view's help window
465 LocateRecordStructure(
472 while (XtParent(w) && !XtIsShell(XtParent(w)))
477 XtSetArg(args[0], XmNuserData, &recordPtr);
478 XtGetValues(w, args, 1);
487 * Check to see if this is the dialog data for one of the top level
488 * application windows.
493 DialogData * dialogData )
498 for (i = 0; i < view_count; i++)
500 if (view_set[i]->dialog_data == (XtPointer)dialogData)
504 if( (FileMgrData *)dialogData->data == trashFileMgrData)
511 * The application must free up the returned string.
515 MapIconWidgetToFileType(
517 FileMgrData * fileMgrData )
525 /* Based on whether in directory graph mode */
526 if (fileMgrData->show_type == SINGLE_DIRECTORY)
529 directoryCount = fileMgrData->directory_count;
531 for (i = directoryCount - 1; i >= 0; i--)
533 for (j = 0; j < fileMgrData->directory_set[i]->file_count; j++)
535 if (w == fileMgrData->directory_set[i]->file_view_data[j]->widget)
538 fileMgrData->directory_set[i]->file_view_data[j]->file_data->logical_type;
539 return (XtNewString(ftName));
544 /* The icon was unknown; should never happen */
551 * This function takes a widget, and determines if it is one of the
552 * menu buttons in the action menupane, or the action popup. If so,
553 * then it returns the action name and the associated filetype string.
555 * The caller must free up the returned string values.
561 FileMgrRec * fileMgrRec,
562 FileMgrData * fileMgrData,
568 CompositeWidget action_pane = (CompositeWidget)fileMgrRec->action_pane;
572 if (action_pane == NULL)
575 /* First, check if this is a menubar item */
576 for (i = 0; i < action_pane->composite.num_children; i++)
578 if (w == action_pane->composite.children[i])
580 XtSetArg(args[0], XmNuserData, &actionName);
581 XtGetValues(w, args, 1);
582 *aName = XtNewString(actionName);
584 /* Get the filetype from the active item */
585 *ftName = XtNewString(
586 fileMgrData->selection_list[0]->file_data->logical_type);
591 /* Secondly, check if this is a fileMgr popup item */
592 if (XtParent(w) == fileMgrPopup.menu)
594 XtSetArg(args[0], XmNuserData, &actionName);
595 XtGetValues(w, args, 1);
596 *aName = XtNewString(actionName);
598 /* Get the filetype from the active item */
599 *ftName = XtNewString(
600 fileMgrData->popup_menu_icon->file_data->logical_type);
601 fileMgrData->popup_menu_icon = NULL;
605 /* This was not a menu item */
612 * This function takes a widget, and determines if it is one of the
613 * filetype icons in the filter dialog. If so, then it returns the
614 * filetype string associated with the icon.
616 * The caller must free up the returned string values.
622 FileMgrData * fileMgrData,
627 DialogData * filterEditDialogData;
628 FilterData * filterData;
629 FilterRec * filterRec;
630 FTData * filterEntryData;
632 filterEditDialogData = fileMgrData->filter_edit;
633 if (!filterEditDialogData)
636 filterData = (FilterData *)filterEditDialogData->data;
638 if (!filterData->displayed)
641 filterRec = (FilterRec *) _DtGetDialogInstance(filterEditDialogData);
643 /* Check if the parent of the widget is the filter's drawingArea */
644 if (XtParent(w) != filterRec->file_window)
648 * Each icon in the filter dialog has attached as its userData a
649 * pointer to a structure of information about the associated
650 * filetype; get this structure, to get the filetype index.
652 XtSetArg(args[0], XmNuserData, &filterEntryData);
653 XtGetValues(w, args, 1);
654 *ftName = XtNewString(filterEntryData->filetype);
664 Widget selectedWidget;
667 returnVal = DtHelpReturnSelectedWidgetId(shell, 0, &selectedWidget);
670 case DtHELP_SELECT_VALID:
672 while (!XtIsShell(selectedWidget))
674 if (XtHasCallbacks(selectedWidget, XmNhelpCallback)
675 == XtCallbackHasSome)
677 XtCallCallbacks(selectedWidget,
678 XmNhelpCallback, NULL);
682 selectedWidget = XtParent(selectedWidget);
687 case DtHELP_SELECT_INVALID:
690 case DtHELP_SELECT_ABORT:
691 case DtHELP_SELECT_ERROR:
700 ReusePrimaryHelpWindow(
701 DialogData * primaryHelpDialog,
711 String helpString = NULL;
715 /* Reuse the existing main help window for this view */
716 helpData = (HelpData *)primaryHelpDialog->data;
717 XtFree(helpData->idString);
718 XtFree(helpData->volString);
719 XtFree(helpData->topicTitle);
720 XtFree(helpData->fileType);
721 helpData->idString = XtNewString(idString);
722 helpData->volString = XtNewString(volume);
723 helpData->topicTitle = XtNewString(topicTitle);
724 helpData->fileType = XtNewString(fileType);
725 helpData->helpType = helpType;
726 helpRec = (HelpRec *) _DtGetDialogInstance(primaryHelpDialog);
728 XtSetArg(args[n], DtNhelpType, (unsigned char )helpType); n++;
729 XtSetArg(args[n], DtNhelpType, helpType); n++;
730 if (helpType == DtHELP_TYPE_TOPIC)
732 XtSetArg(args[n], DtNlocationId, helpData->idString); n++;
736 helpString = MapFileTypeToHelpString(helpData->idString,
738 XtSetArg(args[n], DtNstringData, helpString); n++;
739 XtSetArg(args[n], DtNtopicTitle, helpData->topicTitle); n++;
741 XtSetValues(helpRec->helpDialog, args, n);
748 XtPointer clientData,
752 XtCallCallbacks((Widget)clientData, XmNhelpCallback, NULL);
756 /******************************************************************************/
758 /* closeCB_mainHelpDialog */
760 /* INPUT: Widget wid - widget id */
761 /* XtPointer cd - client data */
762 /* XtPointer cbs - callback data */
765 /******************************************************************************/
768 closeCB_mainHelpDialog(Widget wid, XtPointer client_data,
771 XtDestroyWidget(wid);