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 /* $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(__osf__) || defined(linux)
54 # include <sys/dirent.h>
59 #include <Dt/IconFile.h>
65 #include "CreateActionAppShell.h"
66 #include "Confirmed.h"
68 /******************************************************************************/
70 /* External Variables */
72 /******************************************************************************/
73 extern Dimension wintypeheight, winheight, xprtheight, newheight;
75 /******************************************************************************/
79 /******************************************************************************/
80 struct _ActionData *ca_local_struct;
82 /******************************************************************************/
83 /* readCAFromGUI - loads Action data structure with data read from */
84 /* the GUI interface. */
87 /******************************************************************************/
88 void readCAFromGUI (struct _ActionData *ca_struct)
90 getCAactionName (ca_struct);
91 getCAdblClkCmd (ca_struct);
92 getCAactionHelpText (ca_struct);
93 /*getCAfileTypes (ca_struct);*/
94 getCAactionOpensText (ca_struct);
95 /*getCAwindowType (ca_struct);*/
96 /*getCAactionIcons (ca_struct);*/
97 /*getCAexpertOption (ca_struct);*/
102 /******************************************************************************/
103 /* writeCAToGUI - loads widgets with data stored in the integration */
107 /******************************************************************************/
108 void writeCAToGUI (struct _ActionData *pAD)
110 putCAactionName (pAD);
111 putCAactionIcons (pAD);
112 putCAdblClkCmd (pAD);
113 putCAactionHelpText (pAD);
114 putCAwindowType (pAD);
115 putCAactionOpensText (pAD);
116 putCAfileTypes (pAD);
117 putCAdropFiletypes(pAD);
122 /******************************************************************************/
123 /* getCAactionName - retrieves the action name text string and stores */
124 /* the value in the ActionData structure */
125 /* INPUT: _ActionData *ca_struct - Action data structure */
127 /******************************************************************************/
128 void getCAactionName (struct _ActionData *ca_struct)
130 GetWidgetTextString(CA_ActionNameTextField, &(AD.pszName));
134 /******************************************************************************/
135 /* getCAdblClkCmd - retrieves the double-click command text */
136 /* string and stores the value in the ActionData structure */
137 /* INPUT: _ActionData *ca_struct - Action data structure */
139 /******************************************************************************/
140 void getCAdblClkCmd (struct _ActionData *ca_struct)
142 GetWidgetTextString(CA_DblClkText, &(AD.pszCmd));
146 /******************************************************************************/
147 /* getCAactionHelpText - retrieves the help text string and stores */
148 /* the value in the ActionData structure */
149 /* INPUT: _ActionData *ca_struct - Action data structure */
151 /******************************************************************************/
152 void getCAactionHelpText (struct _ActionData *ca_struct)
154 GetWidgetTextString(CA_HelpText, &(AD.pszHelp));
157 /******************************************************************************/
158 /* getCAactionOpensText - retrieves the "action opens" text */
159 /* string and stores the value in the ActionData structure */
160 /* INPUT: _ActionData *ca_struct - Action data structure */
162 /******************************************************************************/
163 void getCAactionOpensText (struct _ActionData *ca_struct)
165 GetWidgetTextString(CA_XprtActionOpenText, &(AD.pszPrompt));
168 /******************************************************************************/
169 /* putCAactionName - sets the action name text field in the GUI */
170 /* from the value in the ActionData structure */
171 /* INPUT: _ActionData *ca_struct - Action data structure */
173 /******************************************************************************/
174 void putCAactionName (struct _ActionData *ca_struct)
176 PutWidgetTextString(CA_ActionNameTextField, CA_ActionName(ca_struct));
180 /******************************************************************************/
181 /* putCAdblClkCmd - sets the double-click command text */
182 /* string in the GUI from the value in the ActionData structure */
183 /* INPUT: _ActionData *ca_struct - Action data structure */
185 /******************************************************************************/
186 void putCAdblClkCmd (struct _ActionData *ca_struct)
188 PutWidgetTextString(CA_DblClkText, CA_DblClkAction(ca_struct));
192 /******************************************************************************/
193 /* putCAactionHelpText - sets the help text string in the GUI from */
194 /* the value in the ActionData structure */
195 /* INPUT: _ActionData *ca_struct - Action data structure */
197 /******************************************************************************/
198 void putCAactionHelpText (struct _ActionData *ca_struct)
200 PutWidgetTextString(CA_HelpText, CA_ActionHelpText(ca_struct));
204 /******************************************************************************/
205 /* putCAfileTypes - sets the list of file types in the GUI from */
206 /* the values in the ActionData structure */
207 /* INPUT: _ActionData *ca_struct - Action data structure */
209 /******************************************************************************/
210 void putCAfileTypes (struct _ActionData *pAD)
215 if (pAD->cFiletypes) {
216 for (i=0; i < pAD->cFiletypes; i++) {
217 if (!XmListItemExists(CA_FiletypesList,
218 XmStringCreateSimple((pAD->papFiletypes[i])->pszName))) {
219 XmListAddItem(CA_FiletypesList,
220 XmStringCreateSimple((pAD->papFiletypes[i])->pszName), i+1);
228 /******************************************************************************/
229 /* putCAactionOpensText - sets the "action opens" text string in */
230 /* the GUE from the value in the ActionData structure */
231 /* INPUT: _ActionData *ca_struct - Action data structure */
233 /******************************************************************************/
234 void putCAactionOpensText (struct _ActionData *ca_struct)
236 PutWidgetTextString(CA_XprtActionOpenText, CA_ActionOpensText(ca_struct));
240 /******************************************************************************/
241 /* putCAwindowType - sets the window type toggle status in the GUI */
242 /* from the value in the ActionData structure */
243 /* INPUT: _ActionData *ca_struct - Action data structure */
245 /******************************************************************************/
246 void putCAwindowType (struct _ActionData *ca_struct)
248 if (ca_struct->fsFlags & CA_WT_XWINDOWS) {
250 XtVaSetValues(CA_WindowTypeArea,XmNmenuHistory,CA_WinTypeNoOutput,NULL);
252 XtVaSetValues(CA_WindowTypeArea, XmNmenuHistory, CA_WinTypeX, NULL);
253 } else if (ca_struct->fsFlags & CA_WT_TERM) {
254 XtVaSetValues(CA_WindowTypeArea,XmNmenuHistory,CA_WinTypeAutoClose,NULL);
255 } else if (ca_struct->fsFlags & CA_WT_PERMTERM) {
256 XtVaSetValues(CA_WindowTypeArea,XmNmenuHistory,CA_WinTypeManualClose,NULL);
258 /*XtVaSetValues(CA_WindowTypeArea,XmNmenuHistory,CA_WinTypeNoOutput,NULL);*/
259 XtVaSetValues(CA_WindowTypeArea, XmNmenuHistory, CA_WinTypeX, NULL);
264 /******************************************************************************/
265 /* putCAactionIcons - */
266 /* GUI from the value in the ActionData structure */
267 /* INPUT: _ActionData *ca_struct - Action data structure */
269 /******************************************************************************/
270 void putCAactionIcons (ActionData *pAD)
272 char *pszIconFileName = (char *)NULL;
274 char *msgPtr, *fmtPtr, *errPtr;
276 /**************************************************************************/
277 /* Since we only have the base name, we must find the icon within the */
278 /* icon path, strip off the size and type extension, then set the icon */
279 /* data and gadget with this new name - base name and path. */
280 /**************************************************************************/
281 FIND_ICONGADGET_ICON(pAD->pszIcon, pszIconFileName, DtLARGE);
282 if (pszIconFileName) {
283 ptr = strstr(pszIconFileName, LARGE_EXT);
284 if (ptr) *ptr = '\0';
285 SetIconData(CA_LRG_IconGadget, pszIconFileName, Large_Icon);
286 XtFree(pszIconFileName);
288 msgPtr = GETMESSAGE(5, 95,
289 "Could not find the following icon file within the icon\n\
292 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
293 strlen(pAD->pszIcon) + 1) * sizeof(char));
294 sprintf(errPtr, fmtPtr, msgPtr, pAD->pszIcon);
295 display_error_message(CreateActionAppShell, errPtr);
299 FIND_ICONGADGET_ICON(pAD->pszIcon, pszIconFileName, DtMEDIUM);
300 if (pszIconFileName) {
301 ptr = strstr(pszIconFileName, MEDIUM_EXT);
302 if (ptr) *ptr = '\0';
303 SetIconData(CA_MED_IconGadget, pszIconFileName, Medium_Icon);
304 XtFree(pszIconFileName);
306 msgPtr = GETMESSAGE(5, 95,
307 "Could not find the following icon file within the icon\n\
310 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
311 strlen(pAD->pszIcon) + 1) * sizeof(char));
312 sprintf(errPtr, fmtPtr, msgPtr, pAD->pszIcon);
313 display_error_message(CreateActionAppShell, errPtr);
317 FIND_ICONGADGET_ICON(pAD->pszIcon, pszIconFileName, DtTINY);
318 if (pszIconFileName) {
319 ptr = strstr(pszIconFileName, TINY_EXT);
320 if (ptr) *ptr = '\0';
321 SetIconData(CA_TINY_IconGadget, pszIconFileName, Tiny_Icon);
322 XtFree(pszIconFileName);
324 msgPtr = GETMESSAGE(5, 95,
325 "Could not find the following icon file within the icon\n\
328 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
329 strlen(pAD->pszIcon) + 1) * sizeof(char));
330 sprintf(errPtr, fmtPtr, msgPtr, pAD->pszIcon);
331 display_error_message(CreateActionAppShell, errPtr);
336 /******************************************************************************/
337 /* putCAdropFiletypes - */
339 /* INPUT: _ActionData *ca_struct - Action data structure */
341 /******************************************************************************/
342 void putCAdropFiletypes (ActionData *pAD)
346 if (pAD->fsFlags & CA_DF_ONLYFTFILES) {
349 SET_TOGGLEBUTTON(CA_FiletypesInListToggle, set);
350 SET_TOGGLEBUTTON(CA_AllFiletypesToggle, !set);
355 /******************************************************************************/
356 /* set_ca_dialog_height - adjusts height of create action dialog to exclude */
357 /* height used by expert option section. */
360 /******************************************************************************/
361 void set_ca_dialog_height (void)
363 Boolean showExpert = sessiondata.useSession && sessiondata.showExpert;
365 /* get height of window */
366 XtVaGetValues (CreateActionAppShell, XmNheight, &winheight, NULL);
367 /* get height of expert option form */
368 XtVaGetValues (XprtOptionForm, XmNheight, &xprtheight, NULL);
369 /* calculate height of window without expert option form */
370 newheight = winheight - xprtheight;
374 /* remove attachment to expert option form */
375 XtVaSetValues (CA_Expand, XmNbottomAttachment, XmATTACH_NONE, NULL);
376 XtUnmanageChild (XprtOptionForm);
378 if (!sessiondata.useSession)
380 /* give window new height */
381 XtVaSetValues (CreateActionAppShell, XmNheight, newheight, NULL);
384 XtVaSetValues (CA_Expand, XmNbottomAttachment, XmATTACH_FORM, NULL);
388 XtVaSetValues (CA_Expand, RES_CONVERT(XmNlabelString,
389 GETMESSAGE(3, 52, "Basic")),
396 /******************************************************************************/
398 /* CALLBACK FUNCTIONS */
400 /******************************************************************************/
402 /******************************************************************************/
405 /* Callbacks for Create Action 'File' menu */
408 /******************************************************************************/
410 /*****************************************************************************/
415 /*****************************************************************************/
417 initAD( ActionData *pAD )
419 memset(pAD, 0, sizeof(ActionData));
420 pAD->fsFlags |= CA_WT_XWINDOWS;
421 pAD->pszIcon = (char *)XtMalloc(strlen(ca_icon_default) + 1);
422 strcpy(pAD->pszIcon, ca_icon_default);
425 /******************************************************************************/
426 /* FreeAndClearAD - free all fields in AD, frees filetypes and array, */
427 /* and zero's out all of the fields of the structure. */
430 /******************************************************************************/
431 void FreeAndClearAD (ActionData *pAD)
436 if (pAD->pszName) XtFree(pAD->pszName);
437 if (pAD->pszIcon) XtFree(pAD->pszIcon);
438 if (pAD->pszCmd) XtFree(pAD->pszCmd);
439 if (pAD->pszHelp) XtFree(pAD->pszHelp);
440 if (pAD->pszPrompt) XtFree(pAD->pszPrompt);
442 if (pAD->papFiletypes) {
443 for (i=0; i < pAD->cFiletypes; i++) {
444 free_Filetypedata(pAD->papFiletypes[i]);
446 XtFree((char *)pAD->papFiletypes);
448 memset(pAD, 0, sizeof(ActionData));
453 /******************************************************************************/
454 /* clear_CreateActionAppShell_fields */
458 /******************************************************************************/
459 void clear_CreateActionAppShell_fields(void)
461 clear_text_field (ACTION_NAME);
462 clear_text_field (DBL_CLK_CMND);
464 XtVaSetValues(CA_WindowTypeArea, XmNmenuHistory, CA_WinTypeX, NULL);
466 clear_text_field (ACTION_OPENS_TEXT);
467 clear_text (ACTION_HELP_TXT);
468 delete_all_list_items (FILETYPES_FOR_ACTION);
470 createCB_IconGadget(CA_LRG_IconGadget, True, Large_Icon);
471 createCB_IconGadget(CA_MED_IconGadget, True, Medium_Icon);
472 createCB_IconGadget(CA_TINY_IconGadget, True, Tiny_Icon);
474 SET_TOGGLEBUTTON(CA_AllFiletypesToggle, TRUE);
475 SET_TOGGLEBUTTON(CA_FiletypesInListToggle, FALSE);
480 /******************************************************************************/
481 /* activateCB_FileNew - clears the text and list widgets on the */
482 /* create action main panel */
483 /* INPUT: Widget wid - widget id */
484 /* XtPointer cdata - client data */
485 /* XtPointer cbs - callback structur */
487 /******************************************************************************/
488 void activateCB_FileNew (Widget wid, XtPointer cdata,
491 char pszFile[MAXBUFSIZE];
493 /**************************************************************************/
494 /* Clear the fields in the gui and set fields to default. */
495 /**************************************************************************/
496 clear_CreateActionAppShell_fields();
498 /**************************************************************************/
499 /* Clear the pszFileToEdit global variable. */
500 /**************************************************************************/
501 pszFileToEdit = (char *)NULL;
503 /**************************************************************************/
504 /* Clear the fields within the ActionData structure and free any */
505 /* FiletypeData structures. */
506 /**************************************************************************/
509 /**************************************************************************/
510 /* Initialize fields within the ActionData structure. */
511 /**************************************************************************/
514 /**************************************************************************/
515 /* Get a new copy of AD. */
516 /**************************************************************************/
517 FreeAndClearAD(pMyCopyAD);
518 XtFree((char *)pMyCopyAD);
519 pMyCopyAD = copyAD(&AD);
525 /******************************************************************************/
526 /* activateCB_FileOpen - Callback for the Open menu bar option that is */
527 /* located within the File submenu. This callback */
528 /* pops up the File Selection dialog box. */
530 /* INPUT: Widget wid - widget id */
531 /* XtPointer cdata - client data */
532 /* XtPointer cbs - callback structure */
535 /******************************************************************************/
536 void activateCB_FileOpen(Widget wid, XtPointer cdata,
541 XtVaSetValues (OpenFile, RES_CONVERT(XmNdirMask, "~/.dt/types/*.dt"),
542 RES_CONVERT(XmNdirSpec, "~/.dt/types/"),
543 RES_CONVERT(XmNdirectory, "~/.dt/types/"),
546 filter = XmFileSelectionBoxGetChild (OpenFile, XmDIALOG_FILTER_TEXT);
547 /*XtVaSetValues (filter, XmNeditable, False, NULL);*/
548 UxPopupInterface (OpenFile, no_grab);
552 /******************************************************************************/
558 /******************************************************************************/
559 void FreeResources ( void )
561 /**************************************************************************/
562 /* Clear the fields within the ActionData structure and free any */
563 /* FiletypeData structures. */
564 /**************************************************************************/
567 /**************************************************************************/
568 /* Free my copy of AD. */
569 /**************************************************************************/
570 FreeAndClearAD(pMyCopyAD);
571 XtFree((char *)pMyCopyAD);
573 /********************************************************************/
574 /* Free temporary icon files */
575 /********************************************************************/
576 RemoveTmpIconFiles();
581 /******************************************************************************/
582 /* activateCB_FileQuit */
583 /* INPUT: Widget wid - widget id */
584 /* XtPointer cdata - client data */
585 /* XtPointer cbs - callback structur */
587 /******************************************************************************/
588 void activateCB_FileQuit (Widget wid, XtPointer cdata,
596 /**************************************************************************/
597 /* Get latest changes from main window. */
598 /**************************************************************************/
601 /**************************************************************************/
602 /* Check if anything has changed. If so ask if they really want to quit. */
603 /**************************************************************************/
604 if (compareAD(&AD, pMyCopyAD)) {
605 msgPtr = GETMESSAGE(5, 150, "Your current work has not been saved.");
606 msgPtr = XtNewString(msgPtr);
608 /* CDExc19439 - Save GETMESSAGE results to buffers since it can */
609 /* return an internal buffer which can be overwritten on each call. */
610 savePtr = XtNewString(GETMESSAGE(2, 25, "Save"));
611 noSavePtr = XtNewString(GETMESSAGE(5, 152, "Don't Save"));
612 cancelPtr = XtNewString(GETMESSAGE(5, 154, "Cancel Close"));
614 display_question_message(CreateActionAppShell, msgPtr,
615 savePtr, (XtCallbackProc)saveCB_QuestionDialog,
616 noSavePtr, nosaveCB_QuestionDialog,
617 cancelPtr, cancelCB_QuestionDialog);
631 /******************************************************************************/
634 /* Callbacks for Create Action 'Options' menu */
637 /* void activateCB_ExpertOption (); */
640 /******************************************************************************/
643 /******************************************************************************/
644 /* activateCB_ExpertOption - turn expert option on/off */
645 /* INPUT: Widget wid - widget id */
646 /* XtPointer client_data - client data */
647 /* XtPointer *cbs - callback data */
649 /* Global Variables Accessed: (other than widgets) */
651 /******************************************************************************/
652 void activateCB_ExpertOption (Widget wid, XtPointer client_data,
657 if (!XtIsManaged(XprtOptionForm)) {
658 /**********************************************************************/
659 /* Expand the window to show optional data. */
660 /**********************************************************************/
661 XtVaGetValues (CA_WindowTypeArea, XmNwidth, &ca_width, NULL);
662 XtVaSetValues (CA_Expand,
663 XmNbottomAttachment, XmATTACH_NONE,
665 XtVaSetValues (XprtOptionForm,
666 XmNbottomAttachment, XmATTACH_FORM,
667 XmNleftAttachment, XmATTACH_FORM,
668 XmNrightAttachment, XmATTACH_FORM,
671 XtManageChild (XprtOptionForm);
672 XtVaSetValues (CA_Expand,
673 XmNbottomAttachment, XmATTACH_WIDGET,
674 XmNbottomWidget, XprtOptionForm,
676 /*XmNlabelString, GETMESSAGE(3, 52, "Basic"),*/
677 RES_CONVERT( XmNlabelString, GETMESSAGE(3, 52, "Basic")),
679 XtVaSetValues (CA_HelpTextWindow, XmNheight, wintypeheight, NULL);
680 /*XtVaSetValues (CA_WindowTypeArea, XmNheight, wintypeheight, NULL);*/
682 /**********************************************************************/
683 /* Shrink the window to hide optional data. */
684 /**********************************************************************/
685 XtVaSetValues (CA_Expand, XmNbottomAttachment, XmATTACH_NONE, NULL);
686 XtUnmanageChild (XprtOptionForm);
687 XtVaSetValues (CA_Expand,
688 XmNbottomAttachment, XmATTACH_FORM,
690 /*XmNlabelString, GETMESSAGE(3, 50, "Advanced"),*/
691 RES_CONVERT( XmNlabelString, GETMESSAGE(3, 50, "Advanced")),
693 XtVaSetValues (CA_HelpTextWindow, XmNheight, wintypeheight, NULL);
694 XtVaSetValues (CA_WindowTypeArea, XmNheight, wintypeheight, NULL);
699 /******************************************************************************/
701 /* valueChangedCB_ColorMonoOption - turn monochrome option on/off */
703 /* INPUT: Widget wid - widget id */
704 /* XtPointer client_data - client data */
705 /* XmToggleButtonCallbackStruct *tcb - callback data */
708 /******************************************************************************/
709 void valueChangedCB_ColorMonoOption (Widget wid, XtPointer client_data,
710 XmToggleButtonCallbackStruct *tcb)
712 int toggle_set= tcb->set;
718 /***************************************************************************/
719 /* If set then change icons from pixmaps to bitmaps. */
720 /***************************************************************************/
722 bShowPixmaps = FALSE;
727 /***************************************************************************/
728 /* Change icons for CA large, med, and tiny icons */
729 /***************************************************************************/
730 widIcons[0] = CA_LRG_IconGadget;
731 widIcons[1] = CA_MED_IconGadget;
732 widIcons[2] = CA_TINY_IconGadget;
733 for (i = 0; i < 3; i++) {
734 pIconData = GetIconDataFromWid(widIcons[i]);
737 SET_ICONGADGET_ICON(widIcons[i], pIconData->pmFileName);
739 SET_ICONGADGET_ICON(widIcons[i], pIconData->bmFileName);
746 /******************************************************************************/
748 /* createCB_ColorMonoOption */
750 /* INPUT: Widget wid - widget id */
753 /******************************************************************************/
754 void createCB_ColorMonoOption (Widget wid)
758 printf("bShowPixmaps = %d\n", (int)bShowPixmaps);
763 /******************************************************************************/
766 /* Callbacks for Create Action 'Help' menu */
769 /******************************************************************************/
771 /******************************************************************************/
774 /* Callbacks for Create Action Panel Buttons */
777 /* void activateCB_action_icon (); */
780 /******************************************************************************/
782 /******************************************************************************/
784 /* activateCB_action_icon - */
786 /* INPUT: Widget wid - id of icon gadget */
787 /* XtPointer client_data - not used */
788 /* XmPushButtonCallbackStruct *cbs - not used */
791 /******************************************************************************/
792 void activateCB_action_icon (Widget wid, XtPointer client_data,
793 DtIconCallbackStruct *cbs)
796 static Time prev_lts = 0;
798 if (cbs->reason == XmCR_ACTIVATE) {
801 printf("In activate_action_icon callback.\n");
803 if (last_action_pushed && (last_action_pushed != wid)) {
804 XtVaSetValues(XtParent(last_action_pushed), XmNborderWidth, 0, NULL);
806 XtVaSetValues(XtParent(wid), XmNborderWidth, ICON_BORDER_WIDTH, NULL);
808 last_action_pushed = wid;
810 /********************************************************************/
811 /* This is the support needed to provide double-click functionality */
812 /* to the icon gadgets. When double-clicked, the icon editor will */
814 /********************************************************************/
815 XtVaSetValues(wid, XmNpushButtonClickTime, 0, NULL);
817 lts = XtLastTimestampProcessed(XtDisplay(wid));
818 mct = XtGetMultiClickTime(XtDisplay(wid));
820 if ((prev_lts + mct) > lts) {
821 prev_lts = XtLastTimestampProcessed(XtDisplay(wid));
823 prev_lts = XtLastTimestampProcessed(XtDisplay(wid));
828 printf("DblClick icon callback.\n");
831 activateCB_edit_icon(wid, CA_ACTION_ICONS, cbs);
837 /******************************************************************************/
838 /* activateCB_add_filetype - bring up the Add Filetype dialog with correct */
840 /* INPUT: Widget wid - not used */
841 /* XtPointer client_data - not used */
842 /* XmPushButtonCallbackStruct *cbs - not used */
844 /******************************************************************************/
845 void activateCB_add_filetype (Widget wid, XtPointer client_data,
846 XmPushButtonCallbackStruct *cbs)
851 char *pre, *suf, *title;
853 if (!CreateActionAppShellCheckFields()) {
856 printf("Allocating FiletypeData structure\n"); /* debug */
859 /******************************************************************/
860 /* Allocate FiletypeData structure */
861 /******************************************************************/
862 pFtD = (FiletypeData *)XtMalloc(sizeof(FiletypeData));
863 memset(pFtD, 0, sizeof(FiletypeData));
865 /******************************************************************/
866 /* Clear dialog fields */
867 /******************************************************************/
868 clear_AddFiletype_dialog_fields();
869 clear_FileCharacteristics_dialog_fields();
871 /******************************************************************/
872 /* Create name for filetype */
873 /******************************************************************/
874 memset(tmpbuf, 0, 50);
875 sprintf(tmpbuf, "%d", (AD.cFiletypes + 1));
876 ptr = (char *)XmTextFieldGetString(CA_ActionNameTextField);
877 pFtD->pszName = (char *)XtMalloc(strlen(ptr) + strlen("_FILE_") + strlen(tmpbuf) + 1);
878 sprintf(pFtD->pszName, "%s_FILE_%d", ptr, (AD.cFiletypes + 1));
880 XmTextFieldSetString(AF_FileTypeNameTextField, pFtD->pszName);
882 pFtD->pszIcon = (char *)XtMalloc(strlen(af_icon_default) + 1);
883 strcpy(pFtD->pszIcon, af_icon_default);
885 /******************************************************************/
886 /* Set Open command string */
887 /******************************************************************/
889 pFtD->pszOpenCmd = (char *)XmTextGetString(CA_DblClkText);
891 GetWidgetTextString(CA_DblClkText, &(pFtD->pszOpenCmd));
892 XmTextSetString(AF_OpenCmdText, pFtD->pszOpenCmd);
894 pre = GETMESSAGE(3, 10, "Create Action");
895 suf = GETMESSAGE(7, 10, "Add Datatype");
896 title = XtMalloc(strlen(pre) + strlen(suf) + 2);
897 sprintf(title, "%s - %s", pre, suf);
899 XtVaSetValues (AddFiletype,
900 RES_CONVERT (XmNdialogTitle, title ),
905 UxPopupInterface (AddFiletype, no_grab);
911 /******************************************************************************/
912 /* activateCB_edit_filetype - bring up the Add Filetype dialog with correct */
914 /* INPUT: Widget wid - not used */
915 /* XtPointer client_data - not used */
916 /* XmPushButtonCallbackStruct *cbs - not used */
918 /******************************************************************************/
919 void activateCB_edit_filetype (Widget wid, XtPointer client_data,
920 XmPushButtonCallbackStruct *cbs)
923 int *poslist, poscnt;
925 char *msgPtr1, *msgPtr2, *fmtPtr, *errPtr;
926 char *pre, *suf, *title;
928 pre = GETMESSAGE(3, 10, "Create Action");
929 suf = GETMESSAGE(7, 11, "Edit Datatype");
930 title = XtMalloc(strlen(pre) + strlen(suf) + 2);
931 sprintf(title, "%s - %s", pre, suf);
933 /**************************************************************************/
934 /* Determine the selected list item. */
935 /**************************************************************************/
936 if (XmListGetSelectedPos(CA_FiletypesList, &poslist, &poscnt)) {
937 selecteditem = *poslist;
939 if (selecteditem >= 0) {
940 pFtD = AD.papFiletypes[selecteditem];
941 pFtD->fsInternal |= CA_FT_EDIT;
942 GetWidgetTextString(CA_DblClkText, &(pFtD->pszOpenCmd));
943 clear_AddFiletype_dialog_fields();
944 init_AddFiletype_dialog_fields(pFtD);
946 /********************************************************************/
947 /* Pop up the AddFiletype dialog. */
948 /********************************************************************/
949 XtVaSetValues (AddFiletype,
950 RES_CONVERT (XmNdialogTitle, title),
953 UxPopupInterface (AddFiletype, no_grab);
956 msgPtr1 = XtNewString(GETMESSAGE(5, 120,
957 "You have not selected a Datatype from the\n\
958 'Datatypes That Use This Action' list."));
959 msgPtr2 = XtNewString(GETMESSAGE(5, 130,
960 "Please select the Datatype you would like to Edit."));
962 errPtr = XtMalloc((strlen(msgPtr1) + strlen(msgPtr2) +
963 strlen(fmtPtr) + 1) * sizeof(char));
964 sprintf(errPtr, fmtPtr, msgPtr1, msgPtr2);
967 display_error_message(CreateActionAppShell, errPtr);
974 /******************************************************************************/
976 /* get_selected_action_icon - determines which action icon is currently */
980 /* OUTPUT: Widget wid - id of selected icon gadget */
982 /******************************************************************************/
983 Widget get_selected_action_icon (void)
988 if (_DtIconGetState(CA_LRG_IconGadget)) wid = CA_LRG_IconGadget;
989 else if (_DtIconGetState(CA_MED_IconGadget)) wid = CA_MED_IconGadget;
990 else if (_DtIconGetState(CA_TINY_IconGadget)) wid = CA_TINY_IconGadget;
991 else wid = CA_LRG_IconGadget;
994 if (!last_action_pushed) {
995 last_action_pushed = CA_LRG_IconGadget;
997 return (last_action_pushed);
1000 /******************************************************************************/
1002 /* CreateActionAppShellCheckFields */
1005 /* OUTPUT: FALSE - no errors found */
1006 /* TRUE - found errors */
1008 /******************************************************************************/
1009 Boolean CreateActionAppShellCheckFields(void)
1012 char *ptr = (char *)NULL;
1013 char *ptrPrompt = (char *)NULL;
1014 Boolean bError = FALSE;
1015 char *msgPtr, *errPtr;
1017 /**************************************************************************/
1018 /* Check if action name is present. */
1019 /**************************************************************************/
1022 GetWidgetTextString(CA_ActionNameTextField, &ptr);
1024 printf("Action Name = '%s'\n", ptr);
1027 msgPtr = GETMESSAGE(5, 10, "The Action Name is missing.\n\
1028 Please enter a name in the 'Action Name' field.");
1029 errPtr = XtNewString(msgPtr);
1030 display_error_message(CreateActionAppShell, errPtr);
1032 XmProcessTraversal(CA_ActionNameTextField, XmTRAVERSE_CURRENT);
1039 /**************************************************************************/
1040 /* Check if execute command is present. */
1041 /**************************************************************************/
1044 GetWidgetTextString(CA_DblClkText, &ptr);
1046 printf("Exec String = '%s'\n", ptr);
1049 msgPtr = GETMESSAGE(5, 15, "The execute command is missing.\n\
1050 Please enter a command in the\n\
1051 'Command To Execute When Double-clicked' field.");
1052 errPtr = XtNewString(msgPtr);
1053 display_error_message(CreateActionAppShell, errPtr);
1055 XmProcessTraversal(CA_DblClkText, XmTRAVERSE_CURRENT);
1058 /********************************************************************/
1059 /* Now check to see if there is a prompt string. If so, make sure */
1060 /* there is an argument variable within the exec string. */
1061 /********************************************************************/
1062 GetWidgetTextString(CA_XprtActionOpenText, &ptrPrompt);
1064 if (!strchr(ptr, '$')) {
1065 msgPtr = GETMESSAGE(5, 30, "A variable name is missing in the\n\
1066 'Command To Execute When Double-clicked' field.\n\
1067 Add a variable name for the label you have entered\n\
1068 in the 'When Action Opens, Ask Users for' field.\n\
1069 Valid variable names are $*, $1, $2, ..., $9.");
1070 errPtr = XtNewString(msgPtr);
1071 display_error_message(CreateActionAppShell, errPtr);
1073 XmProcessTraversal(CA_DblClkText, XmTRAVERSE_CURRENT);
1082 /**************************************************************************/
1083 /* Check if droppable filetypes buttons are set correctly. */
1084 /**************************************************************************/
1086 if ((AD.fsFlags & CA_DF_ONLYFTFILES) && !(AD.papFiletypes)) {
1087 msgPtr = GETMESSAGE(5, 20,
1088 "The 'Datatypes That Use This Action' list is empty.\n\
1089 You have selected 'Only Above List' in the 'Dropable\n\
1090 Datatypes' field.\n\
1091 Change the Dropable Datatype choice to 'All Datatypes'\n\
1092 or add at least one datatype to the list.");
1093 errPtr = XtNewString(msgPtr);
1094 display_error_message(CreateActionAppShell, errPtr);
1096 XmProcessTraversal(CA_AllFiletypesToggle, XmTRAVERSE_CURRENT);
1104 /******************************************************************************/
1112 /******************************************************************************/
1113 char * copyString(char *string)
1118 newstring = (char *)XtMalloc(strlen(string) + 1);
1119 strcpy(newstring, string);
1121 newstring = (char *)NULL;
1126 /******************************************************************************/
1134 /******************************************************************************/
1135 FiletypeData * copyFtD(FiletypeData *pFtD)
1137 FiletypeData *pcopyFtD;
1139 pcopyFtD = (FiletypeData *)XtMalloc(sizeof(FiletypeData));
1140 memset(pcopyFtD, 0, sizeof(FiletypeData));
1142 if (pFtD->pszName) {
1143 pcopyFtD->pszName = copyString(pFtD->pszName);
1145 if (pFtD->pszIcon) {
1146 pcopyFtD->pszIcon = copyString(pFtD->pszIcon);
1148 if (pFtD->pszHelp) {
1149 pcopyFtD->pszHelp = copyString(pFtD->pszHelp);
1151 if (pFtD->pszOpenCmd) {
1152 pcopyFtD->pszOpenCmd = copyString(pFtD->pszOpenCmd);
1154 if (pFtD->pszPrintCmd) {
1155 pcopyFtD->pszPrintCmd = copyString(pFtD->pszPrintCmd);
1157 if (pFtD->pszPattern) {
1158 pcopyFtD->pszPattern = copyString(pFtD->pszPattern);
1160 if (pFtD->pszPermissions) {
1161 pcopyFtD->pszPermissions = copyString(pFtD->pszPermissions);
1163 if (pFtD->pszContents) {
1164 pcopyFtD->pszContents = copyString(pFtD->pszContents);
1167 pcopyFtD->sStart = pFtD->sStart;
1168 pcopyFtD->sEnd = pFtD->sEnd;
1169 pcopyFtD->fsFlags = pFtD->fsFlags;
1170 pcopyFtD->fsInternal = pFtD->fsInternal;
1175 /******************************************************************************/
1183 /******************************************************************************/
1184 ActionData * copyAD(ActionData *pAD)
1186 ActionData *pcopyAD;
1189 pcopyAD = (ActionData *)XtMalloc(sizeof(ActionData));
1191 return((ActionData *)NULL);
1193 memset(pcopyAD, 0, sizeof(ActionData));
1196 pcopyAD->pszName = copyString(pAD->pszName);
1199 pcopyAD->pszIcon = copyString(pAD->pszIcon);
1202 pcopyAD->pszCmd = copyString(pAD->pszCmd);
1205 pcopyAD->pszHelp = copyString(pAD->pszHelp);
1207 if (pAD->pszPrompt) {
1208 pcopyAD->pszPrompt = copyString(pAD->pszPrompt);
1210 if (pAD->papFiletypes) {
1211 pcopyAD->papFiletypes = (FiletypeData **) XtMalloc(sizeof(FiletypeData *) * (pAD->cFiletypes + 1));
1212 for (i=0; i < pAD->cFiletypes; i++) {
1213 pcopyAD->papFiletypes[i] = copyFtD(pAD->papFiletypes[i]);
1216 pcopyAD->cFiletypes = pAD->cFiletypes;
1217 pcopyAD->fsFlags = pAD->fsFlags;
1220 /******************************************************************************/
1222 /* compareStrings */
1224 /* INPUT: two pointers to char *'s */
1225 /* OUTPUT: 0 they are the same */
1226 /* 1 they are different */
1228 /******************************************************************************/
1229 Boolean compareStrings(char *pszStr1, char *pszStr2)
1231 if (pszStr1 || pszStr2) {
1234 if (!strcmp(pszStr1, pszStr2)) {
1250 /******************************************************************************/
1254 /* INPUT: two pointers to FtD structures */
1255 /* OUTPUT: 0 they are the same */
1256 /* 1 they are different */
1258 /******************************************************************************/
1259 Boolean compareFtD(FiletypeData *pFtD1, FiletypeData *pFtD2)
1261 if (compareStrings(pFtD1->pszName, pFtD2->pszName)) {
1264 if (compareStrings(pFtD1->pszIcon, pFtD2->pszIcon)) {
1267 if (compareStrings(pFtD1->pszHelp, pFtD2->pszHelp)) {
1270 if (compareStrings(pFtD1->pszOpenCmd, pFtD2->pszOpenCmd)) {
1273 if (compareStrings(pFtD1->pszPrintCmd, pFtD2->pszPrintCmd)) {
1276 if (compareStrings(pFtD1->pszPattern, pFtD2->pszPattern)) {
1279 if (compareStrings(pFtD1->pszPermissions, pFtD2->pszPermissions)) {
1282 if (compareStrings(pFtD1->pszContents, pFtD2->pszContents)) {
1285 if (pFtD1->fsFlags != pFtD2->fsFlags) {
1288 if (pFtD1->sStart != pFtD2->sStart) {
1291 if (pFtD1->sEnd != pFtD2->sEnd) {
1298 /******************************************************************************/
1302 /* INPUT: two pointers to AD structures */
1303 /* OUTPUT: 0 they are the same */
1304 /* 1 they are different */
1306 /******************************************************************************/
1307 Boolean compareAD(ActionData *pAD1, ActionData *pAD2)
1311 if (compareStrings(pAD1->pszName, pAD2->pszName)) {
1314 if (compareStrings(pAD1->pszIcon, pAD2->pszIcon)) {
1317 if (compareStrings(pAD1->pszCmd, pAD2->pszCmd)) {
1320 if (compareStrings(pAD1->pszHelp, pAD2->pszHelp)) {
1323 if (compareStrings(pAD1->pszPrompt, pAD2->pszPrompt)) {
1326 if (pAD1->fsFlags != pAD2->fsFlags) {
1329 if (pAD1->cFiletypes != pAD2->cFiletypes) {
1333 if (pAD1->papFiletypes) {
1334 for (i=0; i < pAD1->cFiletypes; i++) {
1335 if (compareFtD(pAD1->papFiletypes[i], pAD2->papFiletypes[i])) {