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 /* $TOG: ca_aux.c /main/10 1999/09/17 15:44:00 mgreess $ */
24 /******************************************************************************/
26 /* ca_aux - auxiliary functions for create action */
28 /* Functions to get/set values from/to interface. */
29 /* Callback routines for CA interface. */
31 /******************************************************************************/
36 #include <sys/signal.h>
39 #include <X11/cursorfont.h>
41 #include <X11/Xatom.h>
44 #include <Xm/RowColumnP.h>
45 #include <Xm/MessageB.h>
46 #include <Xm/FileSB.h>
51 # if defined(__linux__)
54 # include <sys/dirent.h>
59 #include <Dt/IconFile.h>
67 #include "CreateActionAppShell.h"
68 #include "Confirmed.h"
69 #include "ErrorDialog.h"
70 #include "FileCharacteristics.h"
73 extern void RemoveTmpIconFiles( void );
75 /******************************************************************************/
77 /* External Variables */
79 /******************************************************************************/
80 extern XtArgVal /* Dimension */ wintypeheight, winheight, xprtheight, newheight;
82 /******************************************************************************/
86 /******************************************************************************/
87 struct _ActionData *ca_local_struct;
89 /******************************************************************************/
90 /* readCAFromGUI - loads Action data structure with data read from */
91 /* the GUI interface. */
94 /******************************************************************************/
95 void readCAFromGUI (struct _ActionData *ca_struct)
97 getCAactionName (ca_struct);
98 getCAdblClkCmd (ca_struct);
99 getCAactionHelpText (ca_struct);
100 /*getCAfileTypes (ca_struct);*/
101 getCAactionOpensText (ca_struct);
102 /*getCAwindowType (ca_struct);*/
103 /*getCAactionIcons (ca_struct);*/
104 /*getCAexpertOption (ca_struct);*/
109 /******************************************************************************/
110 /* writeCAToGUI - loads widgets with data stored in the integration */
114 /******************************************************************************/
115 void writeCAToGUI (struct _ActionData *pAD)
117 putCAactionName (pAD);
118 putCAactionIcons (pAD);
119 putCAdblClkCmd (pAD);
120 putCAactionHelpText (pAD);
121 putCAwindowType (pAD);
122 putCAactionOpensText (pAD);
123 putCAfileTypes (pAD);
124 putCAdropFiletypes(pAD);
129 /******************************************************************************/
130 /* getCAactionName - retrieves the action name text string and stores */
131 /* the value in the ActionData structure */
132 /* INPUT: _ActionData *ca_struct - Action data structure */
134 /******************************************************************************/
135 void getCAactionName (struct _ActionData *ca_struct)
137 GetWidgetTextString(CA_ActionNameTextField, &(AD.pszName));
141 /******************************************************************************/
142 /* getCAdblClkCmd - retrieves the double-click command text */
143 /* string and stores the value in the ActionData structure */
144 /* INPUT: _ActionData *ca_struct - Action data structure */
146 /******************************************************************************/
147 void getCAdblClkCmd (struct _ActionData *ca_struct)
149 GetWidgetTextString(CA_DblClkText, &(AD.pszCmd));
153 /******************************************************************************/
154 /* getCAactionHelpText - retrieves the help text string and stores */
155 /* the value in the ActionData structure */
156 /* INPUT: _ActionData *ca_struct - Action data structure */
158 /******************************************************************************/
159 void getCAactionHelpText (struct _ActionData *ca_struct)
161 GetWidgetTextString(CA_HelpText, &(AD.pszHelp));
164 /******************************************************************************/
165 /* getCAactionOpensText - retrieves the "action opens" text */
166 /* string and stores the value in the ActionData structure */
167 /* INPUT: _ActionData *ca_struct - Action data structure */
169 /******************************************************************************/
170 void getCAactionOpensText (struct _ActionData *ca_struct)
172 GetWidgetTextString(CA_XprtActionOpenText, &(AD.pszPrompt));
175 /******************************************************************************/
176 /* putCAactionName - sets the action name text field in the GUI */
177 /* from the value in the ActionData structure */
178 /* INPUT: _ActionData *ca_struct - Action data structure */
180 /******************************************************************************/
181 void putCAactionName (struct _ActionData *ca_struct)
183 PutWidgetTextString(CA_ActionNameTextField, CA_ActionName(ca_struct));
187 /******************************************************************************/
188 /* putCAdblClkCmd - sets the double-click command text */
189 /* string in the GUI from the value in the ActionData structure */
190 /* INPUT: _ActionData *ca_struct - Action data structure */
192 /******************************************************************************/
193 void putCAdblClkCmd (struct _ActionData *ca_struct)
195 PutWidgetTextString(CA_DblClkText, CA_DblClkAction(ca_struct));
199 /******************************************************************************/
200 /* putCAactionHelpText - sets the help text string in the GUI from */
201 /* the value in the ActionData structure */
202 /* INPUT: _ActionData *ca_struct - Action data structure */
204 /******************************************************************************/
205 void putCAactionHelpText (struct _ActionData *ca_struct)
207 PutWidgetTextString(CA_HelpText, CA_ActionHelpText(ca_struct));
211 /******************************************************************************/
212 /* putCAfileTypes - sets the list of file types in the GUI from */
213 /* the values in the ActionData structure */
214 /* INPUT: _ActionData *ca_struct - Action data structure */
216 /******************************************************************************/
217 void putCAfileTypes (struct _ActionData *pAD)
222 if (pAD->cFiletypes) {
223 for (i=0; i < pAD->cFiletypes; i++) {
224 if (!XmListItemExists(CA_FiletypesList,
225 XmStringCreateSimple((pAD->papFiletypes[i])->pszName))) {
226 XmListAddItem(CA_FiletypesList,
227 XmStringCreateSimple((pAD->papFiletypes[i])->pszName), i+1);
235 /******************************************************************************/
236 /* putCAactionOpensText - sets the "action opens" text string in */
237 /* the GUE from the value in the ActionData structure */
238 /* INPUT: _ActionData *ca_struct - Action data structure */
240 /******************************************************************************/
241 void putCAactionOpensText (struct _ActionData *ca_struct)
243 PutWidgetTextString(CA_XprtActionOpenText, CA_ActionOpensText(ca_struct));
247 /******************************************************************************/
248 /* putCAwindowType - sets the window type toggle status in the GUI */
249 /* from the value in the ActionData structure */
250 /* INPUT: _ActionData *ca_struct - Action data structure */
252 /******************************************************************************/
253 void putCAwindowType (struct _ActionData *ca_struct)
255 if (ca_struct->fsFlags & CA_WT_XWINDOWS) {
257 XtVaSetValues(CA_WindowTypeArea,XmNmenuHistory,CA_WinTypeNoOutput,NULL);
259 XtVaSetValues(CA_WindowTypeArea, XmNmenuHistory, CA_WinTypeX, NULL);
260 } else if (ca_struct->fsFlags & CA_WT_TERM) {
261 XtVaSetValues(CA_WindowTypeArea,XmNmenuHistory,CA_WinTypeAutoClose,NULL);
262 } else if (ca_struct->fsFlags & CA_WT_PERMTERM) {
263 XtVaSetValues(CA_WindowTypeArea,XmNmenuHistory,CA_WinTypeManualClose,NULL);
265 /*XtVaSetValues(CA_WindowTypeArea,XmNmenuHistory,CA_WinTypeNoOutput,NULL);*/
266 XtVaSetValues(CA_WindowTypeArea, XmNmenuHistory, CA_WinTypeX, NULL);
271 /******************************************************************************/
272 /* putCAactionIcons - */
273 /* GUI from the value in the ActionData structure */
274 /* INPUT: _ActionData *ca_struct - Action data structure */
276 /******************************************************************************/
277 void putCAactionIcons (ActionData *pAD)
279 char *pszIconFileName = (char *)NULL;
281 char *msgPtr, *fmtPtr, *errPtr;
283 /**************************************************************************/
284 /* Since we only have the base name, we must find the icon within the */
285 /* icon path, strip off the size and type extension, then set the icon */
286 /* data and gadget with this new name - base name and path. */
287 /**************************************************************************/
288 FIND_ICONGADGET_ICON(pAD->pszIcon, pszIconFileName, DtLARGE);
289 if (pszIconFileName) {
290 ptr = strstr(pszIconFileName, LARGE_EXT);
291 if (ptr) *ptr = '\0';
292 SetIconData(CA_LRG_IconGadget, pszIconFileName, Large_Icon);
293 XtFree(pszIconFileName);
295 msgPtr = GETMESSAGE(5, 95,
296 "Could not find the following icon file within the icon\n\
299 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
300 strlen(pAD->pszIcon) + 1) * sizeof(char));
301 sprintf(errPtr, fmtPtr, msgPtr, pAD->pszIcon);
302 display_error_message(CreateActionAppShell, errPtr);
306 FIND_ICONGADGET_ICON(pAD->pszIcon, pszIconFileName, DtMEDIUM);
307 if (pszIconFileName) {
308 ptr = strstr(pszIconFileName, MEDIUM_EXT);
309 if (ptr) *ptr = '\0';
310 SetIconData(CA_MED_IconGadget, pszIconFileName, Medium_Icon);
311 XtFree(pszIconFileName);
313 msgPtr = GETMESSAGE(5, 95,
314 "Could not find the following icon file within the icon\n\
317 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
318 strlen(pAD->pszIcon) + 1) * sizeof(char));
319 sprintf(errPtr, fmtPtr, msgPtr, pAD->pszIcon);
320 display_error_message(CreateActionAppShell, errPtr);
324 FIND_ICONGADGET_ICON(pAD->pszIcon, pszIconFileName, DtTINY);
325 if (pszIconFileName) {
326 ptr = strstr(pszIconFileName, TINY_EXT);
327 if (ptr) *ptr = '\0';
328 SetIconData(CA_TINY_IconGadget, pszIconFileName, Tiny_Icon);
329 XtFree(pszIconFileName);
331 msgPtr = GETMESSAGE(5, 95,
332 "Could not find the following icon file within the icon\n\
335 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
336 strlen(pAD->pszIcon) + 1) * sizeof(char));
337 sprintf(errPtr, fmtPtr, msgPtr, pAD->pszIcon);
338 display_error_message(CreateActionAppShell, errPtr);
343 /******************************************************************************/
344 /* putCAdropFiletypes - */
346 /* INPUT: _ActionData *ca_struct - Action data structure */
348 /******************************************************************************/
349 void putCAdropFiletypes (ActionData *pAD)
353 if (pAD->fsFlags & CA_DF_ONLYFTFILES) {
356 SET_TOGGLEBUTTON(CA_FiletypesInListToggle, set);
357 SET_TOGGLEBUTTON(CA_AllFiletypesToggle, !set);
362 /******************************************************************************/
363 /* set_ca_dialog_height - adjusts height of create action dialog to exclude */
364 /* height used by expert option section. */
367 /******************************************************************************/
368 void set_ca_dialog_height (void)
370 Boolean showExpert = sessiondata.useSession && sessiondata.showExpert;
372 /* get height of window */
373 XtVaGetValues (CreateActionAppShell, XmNheight, &winheight, NULL);
374 /* get height of expert option form */
375 XtVaGetValues (XprtOptionForm, XmNheight, &xprtheight, NULL);
376 /* calculate height of window without expert option form */
377 newheight = winheight - xprtheight;
381 /* remove attachment to expert option form */
382 XtVaSetValues (CA_Expand, XmNbottomAttachment, XmATTACH_NONE, NULL);
383 XtUnmanageChild (XprtOptionForm);
385 if (!sessiondata.useSession)
387 /* give window new height */
388 XtVaSetValues (CreateActionAppShell, XmNheight, newheight, NULL);
391 XtVaSetValues (CA_Expand, XmNbottomAttachment, XmATTACH_FORM, NULL);
395 XtVaSetValues (CA_Expand, RES_CONVERT(XmNlabelString,
396 GETMESSAGE(3, 52, "Basic")),
403 /******************************************************************************/
405 /* CALLBACK FUNCTIONS */
407 /******************************************************************************/
409 /******************************************************************************/
412 /* Callbacks for Create Action 'File' menu */
415 /******************************************************************************/
417 /*****************************************************************************/
422 /*****************************************************************************/
424 initAD( ActionData *pAD )
426 memset(pAD, 0, sizeof(ActionData));
427 pAD->fsFlags |= CA_WT_XWINDOWS;
428 pAD->pszIcon = (char *)XtMalloc(strlen(ca_icon_default) + 1);
429 strcpy(pAD->pszIcon, ca_icon_default);
432 /******************************************************************************/
433 /* FreeAndClearAD - free all fields in AD, frees filetypes and array, */
434 /* and zero's out all of the fields of the structure. */
437 /******************************************************************************/
438 void FreeAndClearAD (ActionData *pAD)
443 if (pAD->pszName) XtFree(pAD->pszName);
444 if (pAD->pszIcon) XtFree(pAD->pszIcon);
445 if (pAD->pszCmd) XtFree(pAD->pszCmd);
446 if (pAD->pszHelp) XtFree(pAD->pszHelp);
447 if (pAD->pszPrompt) XtFree(pAD->pszPrompt);
449 if (pAD->papFiletypes) {
450 for (i=0; i < pAD->cFiletypes; i++) {
451 free_Filetypedata(pAD->papFiletypes[i]);
453 XtFree((char *)pAD->papFiletypes);
455 memset(pAD, 0, sizeof(ActionData));
460 /******************************************************************************/
461 /* clear_CreateActionAppShell_fields */
465 /******************************************************************************/
466 void clear_CreateActionAppShell_fields(void)
468 clear_text_field (ACTION_NAME);
469 clear_text_field (DBL_CLK_CMND);
471 XtVaSetValues(CA_WindowTypeArea, XmNmenuHistory, CA_WinTypeX, NULL);
473 clear_text_field (ACTION_OPENS_TEXT);
474 clear_text (ACTION_HELP_TXT);
475 delete_all_list_items (FILETYPES_FOR_ACTION);
477 createCB_IconGadget(CA_LRG_IconGadget, True, Large_Icon);
478 createCB_IconGadget(CA_MED_IconGadget, True, Medium_Icon);
479 createCB_IconGadget(CA_TINY_IconGadget, True, Tiny_Icon);
481 SET_TOGGLEBUTTON(CA_AllFiletypesToggle, TRUE);
482 SET_TOGGLEBUTTON(CA_FiletypesInListToggle, FALSE);
487 /******************************************************************************/
488 /* activateCB_FileNew - clears the text and list widgets on the */
489 /* create action main panel */
490 /* INPUT: Widget wid - widget id */
491 /* XtPointer cdata - client data */
492 /* XtPointer cbs - callback structur */
494 /******************************************************************************/
495 void activateCB_FileNew (Widget wid, XtPointer cdata,
498 char pszFile[MAXBUFSIZE];
500 /**************************************************************************/
501 /* Clear the fields in the gui and set fields to default. */
502 /**************************************************************************/
503 clear_CreateActionAppShell_fields();
505 /**************************************************************************/
506 /* Clear the pszFileToEdit global variable. */
507 /**************************************************************************/
508 pszFileToEdit = (char *)NULL;
510 /**************************************************************************/
511 /* Clear the fields within the ActionData structure and free any */
512 /* FiletypeData structures. */
513 /**************************************************************************/
516 /**************************************************************************/
517 /* Initialize fields within the ActionData structure. */
518 /**************************************************************************/
521 /**************************************************************************/
522 /* Get a new copy of AD. */
523 /**************************************************************************/
524 FreeAndClearAD(pMyCopyAD);
525 XtFree((char *)pMyCopyAD);
526 pMyCopyAD = copyAD(&AD);
532 /******************************************************************************/
533 /* activateCB_FileOpen - Callback for the Open menu bar option that is */
534 /* located within the File submenu. This callback */
535 /* pops up the File Selection dialog box. */
537 /* INPUT: Widget wid - widget id */
538 /* XtPointer cdata - client data */
539 /* XtPointer cbs - callback structure */
542 /******************************************************************************/
543 void activateCB_FileOpen(Widget wid, XtPointer cdata,
548 XtVaSetValues (OpenFile, RES_CONVERT(XmNdirMask, "~/.dt/types/*.dt"),
549 RES_CONVERT(XmNdirSpec, "~/.dt/types/"),
550 RES_CONVERT(XmNdirectory, "~/.dt/types/"),
553 filter = XmFileSelectionBoxGetChild (OpenFile, XmDIALOG_FILTER_TEXT);
554 /*XtVaSetValues (filter, XmNeditable, False, NULL);*/
555 UxPopupInterface (OpenFile, no_grab);
559 /******************************************************************************/
565 /******************************************************************************/
566 void FreeResources ( void )
568 /**************************************************************************/
569 /* Clear the fields within the ActionData structure and free any */
570 /* FiletypeData structures. */
571 /**************************************************************************/
574 /**************************************************************************/
575 /* Free my copy of AD. */
576 /**************************************************************************/
577 FreeAndClearAD(pMyCopyAD);
578 XtFree((char *)pMyCopyAD);
580 /********************************************************************/
581 /* Free temporary icon files */
582 /********************************************************************/
583 RemoveTmpIconFiles();
588 /******************************************************************************/
589 /* activateCB_FileQuit */
590 /* INPUT: Widget wid - widget id */
591 /* XtPointer cdata - client data */
592 /* XtPointer cbs - callback structur */
594 /******************************************************************************/
595 void activateCB_FileQuit (Widget wid, XtPointer cdata,
603 /**************************************************************************/
604 /* Get latest changes from main window. */
605 /**************************************************************************/
608 /**************************************************************************/
609 /* Check if anything has changed. If so ask if they really want to quit. */
610 /**************************************************************************/
611 if (compareAD(&AD, pMyCopyAD)) {
612 msgPtr = GETMESSAGE(5, 150, "Your current work has not been saved.");
613 msgPtr = XtNewString(msgPtr);
615 /* CDExc19439 - Save GETMESSAGE results to buffers since it can */
616 /* return an internal buffer which can be overwritten on each call. */
617 savePtr = XtNewString(GETMESSAGE(2, 25, "Save"));
618 noSavePtr = XtNewString(GETMESSAGE(5, 152, "Don't Save"));
619 cancelPtr = XtNewString(GETMESSAGE(5, 154, "Cancel Close"));
621 display_question_message(CreateActionAppShell, msgPtr,
622 savePtr, (XtCallbackProc)saveCB_QuestionDialog,
623 noSavePtr, nosaveCB_QuestionDialog,
624 cancelPtr, cancelCB_QuestionDialog);
638 /******************************************************************************/
641 /* Callbacks for Create Action 'Options' menu */
644 /* void activateCB_ExpertOption (); */
647 /******************************************************************************/
650 /******************************************************************************/
651 /* activateCB_ExpertOption - turn expert option on/off */
652 /* INPUT: Widget wid - widget id */
653 /* XtPointer client_data - client data */
654 /* XtPointer *cbs - callback data */
656 /* Global Variables Accessed: (other than widgets) */
658 /******************************************************************************/
659 void activateCB_ExpertOption (Widget wid, XtPointer client_data,
662 XtArgVal /* Dimension */ ca_width;
664 if (!XtIsManaged(XprtOptionForm)) {
665 /**********************************************************************/
666 /* Expand the window to show optional data. */
667 /**********************************************************************/
668 XtVaGetValues (CA_WindowTypeArea, XmNwidth, &ca_width, NULL);
669 XtVaSetValues (CA_Expand,
670 XmNbottomAttachment, XmATTACH_NONE,
672 XtVaSetValues (XprtOptionForm,
673 XmNbottomAttachment, XmATTACH_FORM,
674 XmNleftAttachment, XmATTACH_FORM,
675 XmNrightAttachment, XmATTACH_FORM,
678 XtManageChild (XprtOptionForm);
679 XtVaSetValues (CA_Expand,
680 XmNbottomAttachment, XmATTACH_WIDGET,
681 XmNbottomWidget, XprtOptionForm,
683 /*XmNlabelString, GETMESSAGE(3, 52, "Basic"),*/
684 RES_CONVERT( XmNlabelString, GETMESSAGE(3, 52, "Basic")),
686 XtVaSetValues (CA_HelpTextWindow, XmNheight, wintypeheight, NULL);
687 /*XtVaSetValues (CA_WindowTypeArea, XmNheight, wintypeheight, NULL);*/
689 /**********************************************************************/
690 /* Shrink the window to hide optional data. */
691 /**********************************************************************/
692 XtVaSetValues (CA_Expand, XmNbottomAttachment, XmATTACH_NONE, NULL);
693 XtUnmanageChild (XprtOptionForm);
694 XtVaSetValues (CA_Expand,
695 XmNbottomAttachment, XmATTACH_FORM,
697 /*XmNlabelString, GETMESSAGE(3, 50, "Advanced"),*/
698 RES_CONVERT( XmNlabelString, GETMESSAGE(3, 50, "Advanced")),
700 XtVaSetValues (CA_HelpTextWindow, XmNheight, wintypeheight, NULL);
701 XtVaSetValues (CA_WindowTypeArea, XmNheight, wintypeheight, NULL);
706 /******************************************************************************/
708 /* valueChangedCB_ColorMonoOption - turn monochrome option on/off */
710 /* INPUT: Widget wid - widget id */
711 /* XtPointer client_data - client data */
712 /* XmToggleButtonCallbackStruct *tcb - callback data */
715 /******************************************************************************/
716 void valueChangedCB_ColorMonoOption (Widget wid, XtPointer client_data,
717 XmToggleButtonCallbackStruct *tcb)
719 int toggle_set= tcb->set;
725 /***************************************************************************/
726 /* If set then change icons from pixmaps to bitmaps. */
727 /***************************************************************************/
729 bShowPixmaps = FALSE;
734 /***************************************************************************/
735 /* Change icons for CA large, med, and tiny icons */
736 /***************************************************************************/
737 widIcons[0] = CA_LRG_IconGadget;
738 widIcons[1] = CA_MED_IconGadget;
739 widIcons[2] = CA_TINY_IconGadget;
740 for (i = 0; i < 3; i++) {
741 pIconData = GetIconDataFromWid(widIcons[i]);
744 SET_ICONGADGET_ICON(widIcons[i], pIconData->pmFileName);
746 SET_ICONGADGET_ICON(widIcons[i], pIconData->bmFileName);
753 /******************************************************************************/
755 /* createCB_ColorMonoOption */
757 /* INPUT: Widget wid - widget id */
760 /******************************************************************************/
761 void createCB_ColorMonoOption (Widget wid)
765 printf("bShowPixmaps = %d\n", (int)bShowPixmaps);
770 /******************************************************************************/
773 /* Callbacks for Create Action 'Help' menu */
776 /******************************************************************************/
778 /******************************************************************************/
781 /* Callbacks for Create Action Panel Buttons */
784 /* void activateCB_action_icon (); */
787 /******************************************************************************/
789 /******************************************************************************/
791 /* activateCB_action_icon - */
793 /* INPUT: Widget wid - id of icon gadget */
794 /* XtPointer client_data - not used */
795 /* XmPushButtonCallbackStruct *cbs - not used */
798 /******************************************************************************/
799 void activateCB_action_icon (Widget wid, XtPointer client_data,
800 DtIconCallbackStruct *cbs)
803 static Time prev_lts = 0;
805 if (cbs->reason == XmCR_ACTIVATE) {
808 printf("In activate_action_icon callback.\n");
810 if (last_action_pushed && (last_action_pushed != wid)) {
811 XtVaSetValues(XtParent(last_action_pushed), XmNborderWidth, 0, NULL);
813 XtVaSetValues(XtParent(wid), XmNborderWidth, ICON_BORDER_WIDTH, NULL);
815 last_action_pushed = wid;
817 /********************************************************************/
818 /* This is the support needed to provide double-click functionality */
819 /* to the icon gadgets. When double-clicked, the icon editor will */
821 /********************************************************************/
822 XtVaSetValues(wid, XmNpushButtonClickTime, 0, NULL);
824 lts = XtLastTimestampProcessed(XtDisplay(wid));
825 mct = XtGetMultiClickTime(XtDisplay(wid));
827 if ((prev_lts + mct) > lts) {
828 prev_lts = XtLastTimestampProcessed(XtDisplay(wid));
830 prev_lts = XtLastTimestampProcessed(XtDisplay(wid));
835 printf("DblClick icon callback.\n");
838 activateCB_edit_icon(wid, (XtPointer)CA_ACTION_ICONS,
839 (XmPushButtonCallbackStruct *)cbs /* unused anyway */);
845 /******************************************************************************/
846 /* activateCB_add_filetype - bring up the Add Filetype dialog with correct */
848 /* INPUT: Widget wid - not used */
849 /* XtPointer client_data - not used */
850 /* XmPushButtonCallbackStruct *cbs - not used */
852 /******************************************************************************/
853 void activateCB_add_filetype (Widget wid, XtPointer client_data,
854 XmPushButtonCallbackStruct *cbs)
859 char *pre, *suf, *title;
862 if (!CreateActionAppShellCheckFields()) {
865 printf("Allocating FiletypeData structure\n"); /* debug */
868 /******************************************************************/
869 /* Allocate FiletypeData structure */
870 /******************************************************************/
871 pFtD = (FiletypeData *)XtMalloc(sizeof(FiletypeData));
872 memset(pFtD, 0, sizeof(FiletypeData));
874 /******************************************************************/
875 /* Clear dialog fields */
876 /******************************************************************/
877 clear_AddFiletype_dialog_fields();
878 clear_FileCharacteristics_dialog_fields();
880 /******************************************************************/
881 /* Create name for filetype */
882 /******************************************************************/
883 memset(tmpbuf, 0, 50);
884 sprintf(tmpbuf, "%d", (AD.cFiletypes + 1));
885 ptr = (char *)XmTextFieldGetString(CA_ActionNameTextField);
886 pFtD->pszName = (char *)XtMalloc(strlen(ptr) + strlen("_FILE_") + strlen(tmpbuf) + 1);
887 sprintf(pFtD->pszName, "%s_FILE_%d", ptr, (AD.cFiletypes + 1));
889 XmTextFieldSetString(AF_FileTypeNameTextField, pFtD->pszName);
891 pFtD->pszIcon = (char *)XtMalloc(strlen(af_icon_default) + 1);
892 strcpy(pFtD->pszIcon, af_icon_default);
894 /******************************************************************/
895 /* Set Open command string */
896 /******************************************************************/
898 pFtD->pszOpenCmd = (char *)XmTextGetString(CA_DblClkText);
900 GetWidgetTextString(CA_DblClkText, &(pFtD->pszOpenCmd));
901 XmTextSetString(AF_OpenCmdText, pFtD->pszOpenCmd);
903 pre = GETMESSAGE(3, 10, "Create Action");
904 suf = GETMESSAGE(7, 10, "Add Datatype");
905 len = strlen(pre) + strlen(suf) + 4;
906 title = XtMalloc(len);
907 snprintf(title,len - 1,"%s - %s", pre, suf);
909 XtVaSetValues (AddFiletype,
910 RES_CONVERT (XmNdialogTitle, title ),
915 UxPopupInterface (AddFiletype, no_grab);
921 /******************************************************************************/
922 /* activateCB_edit_filetype - bring up the Add Filetype dialog with correct */
924 /* INPUT: Widget wid - not used */
925 /* XtPointer client_data - not used */
926 /* XmPushButtonCallbackStruct *cbs - not used */
928 /******************************************************************************/
929 void activateCB_edit_filetype (Widget wid, XtPointer client_data,
930 XmPushButtonCallbackStruct *cbs)
933 int *poslist, poscnt;
935 char *msgPtr1, *msgPtr2, *fmtPtr, *errPtr;
936 char *pre, *suf, *title;
939 pre = GETMESSAGE(3, 10, "Create Action");
940 suf = GETMESSAGE(7, 11, "Edit Datatype");
941 len = strlen(pre) + strlen(suf) + 4;
942 title = XtMalloc(len);
943 snprintf(title,len - 1, "%s - %s", pre, suf);
945 /**************************************************************************/
946 /* Determine the selected list item. */
947 /**************************************************************************/
948 if (XmListGetSelectedPos(CA_FiletypesList, &poslist, &poscnt)) {
949 selecteditem = *poslist;
951 if (selecteditem >= 0) {
952 pFtD = AD.papFiletypes[selecteditem];
953 pFtD->fsInternal |= CA_FT_EDIT;
954 GetWidgetTextString(CA_DblClkText, &(pFtD->pszOpenCmd));
955 clear_AddFiletype_dialog_fields();
956 init_AddFiletype_dialog_fields(pFtD);
958 /********************************************************************/
959 /* Pop up the AddFiletype dialog. */
960 /********************************************************************/
961 XtVaSetValues (AddFiletype,
962 RES_CONVERT (XmNdialogTitle, title),
965 UxPopupInterface (AddFiletype, no_grab);
968 msgPtr1 = XtNewString(GETMESSAGE(5, 120,
969 "You have not selected a Datatype from the\n\
970 'Datatypes That Use This Action' list."));
971 msgPtr2 = XtNewString(GETMESSAGE(5, 130,
972 "Please select the Datatype you would like to Edit."));
974 len = (strlen(msgPtr1) + strlen(msgPtr2) +
976 errPtr = XtMalloc(len);
977 snprintf(errPtr,len - 1, fmtPtr, msgPtr1, msgPtr2);
980 display_error_message(CreateActionAppShell, errPtr);
987 /******************************************************************************/
989 /* get_selected_action_icon - determines which action icon is currently */
993 /* OUTPUT: Widget wid - id of selected icon gadget */
995 /******************************************************************************/
996 Widget get_selected_action_icon (void)
1001 if (_DtIconGetState(CA_LRG_IconGadget)) wid = CA_LRG_IconGadget;
1002 else if (_DtIconGetState(CA_MED_IconGadget)) wid = CA_MED_IconGadget;
1003 else if (_DtIconGetState(CA_TINY_IconGadget)) wid = CA_TINY_IconGadget;
1004 else wid = CA_LRG_IconGadget;
1007 if (!last_action_pushed) {
1008 last_action_pushed = CA_LRG_IconGadget;
1010 return (last_action_pushed);
1013 /******************************************************************************/
1015 /* CreateActionAppShellCheckFields */
1018 /* OUTPUT: FALSE - no errors found */
1019 /* TRUE - found errors */
1021 /******************************************************************************/
1022 Boolean CreateActionAppShellCheckFields(void)
1025 char *ptr = (char *)NULL;
1026 char *ptrPrompt = (char *)NULL;
1027 Boolean bError = FALSE;
1028 char *msgPtr, *errPtr;
1030 /**************************************************************************/
1031 /* Check if action name is present. */
1032 /**************************************************************************/
1035 GetWidgetTextString(CA_ActionNameTextField, &ptr);
1037 printf("Action Name = '%s'\n", ptr);
1040 msgPtr = GETMESSAGE(5, 10, "The Action Name is missing.\n\
1041 Please enter a name in the 'Action Name' field.");
1042 errPtr = XtNewString(msgPtr);
1043 display_error_message(CreateActionAppShell, errPtr);
1045 XmProcessTraversal(CA_ActionNameTextField, XmTRAVERSE_CURRENT);
1052 /**************************************************************************/
1053 /* Check if execute command is present. */
1054 /**************************************************************************/
1057 GetWidgetTextString(CA_DblClkText, &ptr);
1059 printf("Exec String = '%s'\n", ptr);
1062 msgPtr = GETMESSAGE(5, 15, "The execute command is missing.\n\
1063 Please enter a command in the\n\
1064 'Command To Execute When Double-clicked' field.");
1065 errPtr = XtNewString(msgPtr);
1066 display_error_message(CreateActionAppShell, errPtr);
1068 XmProcessTraversal(CA_DblClkText, XmTRAVERSE_CURRENT);
1071 /********************************************************************/
1072 /* Now check to see if there is a prompt string. If so, make sure */
1073 /* there is an argument variable within the exec string. */
1074 /********************************************************************/
1075 GetWidgetTextString(CA_XprtActionOpenText, &ptrPrompt);
1077 if (!strchr(ptr, '$')) {
1078 msgPtr = GETMESSAGE(5, 30, "A variable name is missing in the\n\
1079 'Command To Execute When Double-clicked' field.\n\
1080 Add a variable name for the label you have entered\n\
1081 in the 'When Action Opens, Ask Users for' field.\n\
1082 Valid variable names are $*, $1, $2, ..., $9.");
1083 errPtr = XtNewString(msgPtr);
1084 display_error_message(CreateActionAppShell, errPtr);
1086 XmProcessTraversal(CA_DblClkText, XmTRAVERSE_CURRENT);
1095 /**************************************************************************/
1096 /* Check if droppable filetypes buttons are set correctly. */
1097 /**************************************************************************/
1099 if ((AD.fsFlags & CA_DF_ONLYFTFILES) && !(AD.papFiletypes)) {
1100 msgPtr = GETMESSAGE(5, 20,
1101 "The 'Datatypes That Use This Action' list is empty.\n\
1102 You have selected 'Only Above List' in the 'Dropable\n\
1103 Datatypes' field.\n\
1104 Change the Dropable Datatype choice to 'All Datatypes'\n\
1105 or add at least one datatype to the list.");
1106 errPtr = XtNewString(msgPtr);
1107 display_error_message(CreateActionAppShell, errPtr);
1109 XmProcessTraversal(CA_AllFiletypesToggle, XmTRAVERSE_CURRENT);
1117 /******************************************************************************/
1125 /******************************************************************************/
1126 char * copyString(char *string)
1131 newstring = (char *)XtMalloc(strlen(string) + 1);
1132 strcpy(newstring, string);
1134 newstring = (char *)NULL;
1139 /******************************************************************************/
1147 /******************************************************************************/
1148 FiletypeData * copyFtD(FiletypeData *pFtD)
1150 FiletypeData *pcopyFtD;
1152 pcopyFtD = (FiletypeData *)XtMalloc(sizeof(FiletypeData));
1153 memset(pcopyFtD, 0, sizeof(FiletypeData));
1155 if (pFtD->pszName) {
1156 pcopyFtD->pszName = copyString(pFtD->pszName);
1158 if (pFtD->pszIcon) {
1159 pcopyFtD->pszIcon = copyString(pFtD->pszIcon);
1161 if (pFtD->pszHelp) {
1162 pcopyFtD->pszHelp = copyString(pFtD->pszHelp);
1164 if (pFtD->pszOpenCmd) {
1165 pcopyFtD->pszOpenCmd = copyString(pFtD->pszOpenCmd);
1167 if (pFtD->pszPrintCmd) {
1168 pcopyFtD->pszPrintCmd = copyString(pFtD->pszPrintCmd);
1170 if (pFtD->pszPattern) {
1171 pcopyFtD->pszPattern = copyString(pFtD->pszPattern);
1173 if (pFtD->pszPermissions) {
1174 pcopyFtD->pszPermissions = copyString(pFtD->pszPermissions);
1176 if (pFtD->pszContents) {
1177 pcopyFtD->pszContents = copyString(pFtD->pszContents);
1180 pcopyFtD->sStart = pFtD->sStart;
1181 pcopyFtD->sEnd = pFtD->sEnd;
1182 pcopyFtD->fsFlags = pFtD->fsFlags;
1183 pcopyFtD->fsInternal = pFtD->fsInternal;
1188 /******************************************************************************/
1196 /******************************************************************************/
1197 ActionData * copyAD(ActionData *pAD)
1199 ActionData *pcopyAD;
1202 pcopyAD = (ActionData *)XtMalloc(sizeof(ActionData));
1204 return((ActionData *)NULL);
1206 memset(pcopyAD, 0, sizeof(ActionData));
1209 pcopyAD->pszName = copyString(pAD->pszName);
1212 pcopyAD->pszIcon = copyString(pAD->pszIcon);
1215 pcopyAD->pszCmd = copyString(pAD->pszCmd);
1218 pcopyAD->pszHelp = copyString(pAD->pszHelp);
1220 if (pAD->pszPrompt) {
1221 pcopyAD->pszPrompt = copyString(pAD->pszPrompt);
1223 if (pAD->papFiletypes) {
1224 pcopyAD->papFiletypes = (FiletypeData **) XtMalloc(sizeof(FiletypeData *) * (pAD->cFiletypes + 1));
1225 for (i=0; i < pAD->cFiletypes; i++) {
1226 pcopyAD->papFiletypes[i] = copyFtD(pAD->papFiletypes[i]);
1229 pcopyAD->cFiletypes = pAD->cFiletypes;
1230 pcopyAD->fsFlags = pAD->fsFlags;
1233 /******************************************************************************/
1235 /* compareStrings */
1237 /* INPUT: two pointers to char *'s */
1238 /* OUTPUT: 0 they are the same */
1239 /* 1 they are different */
1241 /******************************************************************************/
1242 Boolean compareStrings(char *pszStr1, char *pszStr2)
1244 if (pszStr1 || pszStr2) {
1247 if (!strcmp(pszStr1, pszStr2)) {
1263 /******************************************************************************/
1267 /* INPUT: two pointers to FtD structures */
1268 /* OUTPUT: 0 they are the same */
1269 /* 1 they are different */
1271 /******************************************************************************/
1272 Boolean compareFtD(FiletypeData *pFtD1, FiletypeData *pFtD2)
1274 if (compareStrings(pFtD1->pszName, pFtD2->pszName)) {
1277 if (compareStrings(pFtD1->pszIcon, pFtD2->pszIcon)) {
1280 if (compareStrings(pFtD1->pszHelp, pFtD2->pszHelp)) {
1283 if (compareStrings(pFtD1->pszOpenCmd, pFtD2->pszOpenCmd)) {
1286 if (compareStrings(pFtD1->pszPrintCmd, pFtD2->pszPrintCmd)) {
1289 if (compareStrings(pFtD1->pszPattern, pFtD2->pszPattern)) {
1292 if (compareStrings(pFtD1->pszPermissions, pFtD2->pszPermissions)) {
1295 if (compareStrings(pFtD1->pszContents, pFtD2->pszContents)) {
1298 if (pFtD1->fsFlags != pFtD2->fsFlags) {
1301 if (pFtD1->sStart != pFtD2->sStart) {
1304 if (pFtD1->sEnd != pFtD2->sEnd) {
1311 /******************************************************************************/
1315 /* INPUT: two pointers to AD structures */
1316 /* OUTPUT: 0 they are the same */
1317 /* 1 they are different */
1319 /******************************************************************************/
1320 Boolean compareAD(ActionData *pAD1, ActionData *pAD2)
1324 if (compareStrings(pAD1->pszName, pAD2->pszName)) {
1327 if (compareStrings(pAD1->pszIcon, pAD2->pszIcon)) {
1330 if (compareStrings(pAD1->pszCmd, pAD2->pszCmd)) {
1333 if (compareStrings(pAD1->pszHelp, pAD2->pszHelp)) {
1336 if (compareStrings(pAD1->pszPrompt, pAD2->pszPrompt)) {
1339 if (pAD1->fsFlags != pAD2->fsFlags) {
1342 if (pAD1->cFiletypes != pAD2->cFiletypes) {
1346 if (pAD1->papFiletypes) {
1347 for (i=0; i < pAD1->cFiletypes; i++) {
1348 if (compareFtD(pAD1->papFiletypes[i], pAD2->papFiletypes[i])) {