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;
854 if (!CreateActionAppShellCheckFields()) {
857 printf("Allocating FiletypeData structure\n"); /* debug */
860 /******************************************************************/
861 /* Allocate FiletypeData structure */
862 /******************************************************************/
863 pFtD = (FiletypeData *)XtMalloc(sizeof(FiletypeData));
864 memset(pFtD, 0, sizeof(FiletypeData));
866 /******************************************************************/
867 /* Clear dialog fields */
868 /******************************************************************/
869 clear_AddFiletype_dialog_fields();
870 clear_FileCharacteristics_dialog_fields();
872 /******************************************************************/
873 /* Create name for filetype */
874 /******************************************************************/
875 memset(tmpbuf, 0, 50);
876 sprintf(tmpbuf, "%d", (AD.cFiletypes + 1));
877 ptr = (char *)XmTextFieldGetString(CA_ActionNameTextField);
878 pFtD->pszName = (char *)XtMalloc(strlen(ptr) + strlen("_FILE_") + strlen(tmpbuf) + 1);
879 sprintf(pFtD->pszName, "%s_FILE_%d", ptr, (AD.cFiletypes + 1));
881 XmTextFieldSetString(AF_FileTypeNameTextField, pFtD->pszName);
883 pFtD->pszIcon = (char *)XtMalloc(strlen(af_icon_default) + 1);
884 strcpy(pFtD->pszIcon, af_icon_default);
886 /******************************************************************/
887 /* Set Open command string */
888 /******************************************************************/
890 pFtD->pszOpenCmd = (char *)XmTextGetString(CA_DblClkText);
892 GetWidgetTextString(CA_DblClkText, &(pFtD->pszOpenCmd));
893 XmTextSetString(AF_OpenCmdText, pFtD->pszOpenCmd);
895 pre = GETMESSAGE(3, 10, "Create Action");
896 suf = GETMESSAGE(7, 10, "Add Datatype");
897 len = strlen(pre) + strlen(suf) + 4;
898 title = XtMalloc(len);
899 snprintf(title,len - 1,"%s - %s", pre, suf);
901 XtVaSetValues (AddFiletype,
902 RES_CONVERT (XmNdialogTitle, title ),
907 UxPopupInterface (AddFiletype, no_grab);
913 /******************************************************************************/
914 /* activateCB_edit_filetype - bring up the Add Filetype dialog with correct */
916 /* INPUT: Widget wid - not used */
917 /* XtPointer client_data - not used */
918 /* XmPushButtonCallbackStruct *cbs - not used */
920 /******************************************************************************/
921 void activateCB_edit_filetype (Widget wid, XtPointer client_data,
922 XmPushButtonCallbackStruct *cbs)
925 int *poslist, poscnt;
927 char *msgPtr1, *msgPtr2, *fmtPtr, *errPtr;
928 char *pre, *suf, *title;
931 pre = GETMESSAGE(3, 10, "Create Action");
932 suf = GETMESSAGE(7, 11, "Edit Datatype");
933 len = strlen(pre) + strlen(suf) + 4;
934 title = XtMalloc(len);
935 snprintf(title,len - 1, "%s - %s", pre, suf);
937 /**************************************************************************/
938 /* Determine the selected list item. */
939 /**************************************************************************/
940 if (XmListGetSelectedPos(CA_FiletypesList, &poslist, &poscnt)) {
941 selecteditem = *poslist;
943 if (selecteditem >= 0) {
944 pFtD = AD.papFiletypes[selecteditem];
945 pFtD->fsInternal |= CA_FT_EDIT;
946 GetWidgetTextString(CA_DblClkText, &(pFtD->pszOpenCmd));
947 clear_AddFiletype_dialog_fields();
948 init_AddFiletype_dialog_fields(pFtD);
950 /********************************************************************/
951 /* Pop up the AddFiletype dialog. */
952 /********************************************************************/
953 XtVaSetValues (AddFiletype,
954 RES_CONVERT (XmNdialogTitle, title),
957 UxPopupInterface (AddFiletype, no_grab);
960 msgPtr1 = XtNewString(GETMESSAGE(5, 120,
961 "You have not selected a Datatype from the\n\
962 'Datatypes That Use This Action' list."));
963 msgPtr2 = XtNewString(GETMESSAGE(5, 130,
964 "Please select the Datatype you would like to Edit."));
966 len = (strlen(msgPtr1) + strlen(msgPtr2) +
968 errPtr = XtMalloc(len);
969 snprintf(errPtr,len - 1, fmtPtr, msgPtr1, msgPtr2);
972 display_error_message(CreateActionAppShell, errPtr);
979 /******************************************************************************/
981 /* get_selected_action_icon - determines which action icon is currently */
985 /* OUTPUT: Widget wid - id of selected icon gadget */
987 /******************************************************************************/
988 Widget get_selected_action_icon (void)
993 if (_DtIconGetState(CA_LRG_IconGadget)) wid = CA_LRG_IconGadget;
994 else if (_DtIconGetState(CA_MED_IconGadget)) wid = CA_MED_IconGadget;
995 else if (_DtIconGetState(CA_TINY_IconGadget)) wid = CA_TINY_IconGadget;
996 else wid = CA_LRG_IconGadget;
999 if (!last_action_pushed) {
1000 last_action_pushed = CA_LRG_IconGadget;
1002 return (last_action_pushed);
1005 /******************************************************************************/
1007 /* CreateActionAppShellCheckFields */
1010 /* OUTPUT: FALSE - no errors found */
1011 /* TRUE - found errors */
1013 /******************************************************************************/
1014 Boolean CreateActionAppShellCheckFields(void)
1017 char *ptr = (char *)NULL;
1018 char *ptrPrompt = (char *)NULL;
1019 Boolean bError = FALSE;
1020 char *msgPtr, *errPtr;
1022 /**************************************************************************/
1023 /* Check if action name is present. */
1024 /**************************************************************************/
1027 GetWidgetTextString(CA_ActionNameTextField, &ptr);
1029 printf("Action Name = '%s'\n", ptr);
1032 msgPtr = GETMESSAGE(5, 10, "The Action Name is missing.\n\
1033 Please enter a name in the 'Action Name' field.");
1034 errPtr = XtNewString(msgPtr);
1035 display_error_message(CreateActionAppShell, errPtr);
1037 XmProcessTraversal(CA_ActionNameTextField, XmTRAVERSE_CURRENT);
1044 /**************************************************************************/
1045 /* Check if execute command is present. */
1046 /**************************************************************************/
1049 GetWidgetTextString(CA_DblClkText, &ptr);
1051 printf("Exec String = '%s'\n", ptr);
1054 msgPtr = GETMESSAGE(5, 15, "The execute command is missing.\n\
1055 Please enter a command in the\n\
1056 'Command To Execute When Double-clicked' field.");
1057 errPtr = XtNewString(msgPtr);
1058 display_error_message(CreateActionAppShell, errPtr);
1060 XmProcessTraversal(CA_DblClkText, XmTRAVERSE_CURRENT);
1063 /********************************************************************/
1064 /* Now check to see if there is a prompt string. If so, make sure */
1065 /* there is an argument variable within the exec string. */
1066 /********************************************************************/
1067 GetWidgetTextString(CA_XprtActionOpenText, &ptrPrompt);
1069 if (!strchr(ptr, '$')) {
1070 msgPtr = GETMESSAGE(5, 30, "A variable name is missing in the\n\
1071 'Command To Execute When Double-clicked' field.\n\
1072 Add a variable name for the label you have entered\n\
1073 in the 'When Action Opens, Ask Users for' field.\n\
1074 Valid variable names are $*, $1, $2, ..., $9.");
1075 errPtr = XtNewString(msgPtr);
1076 display_error_message(CreateActionAppShell, errPtr);
1078 XmProcessTraversal(CA_DblClkText, XmTRAVERSE_CURRENT);
1087 /**************************************************************************/
1088 /* Check if droppable filetypes buttons are set correctly. */
1089 /**************************************************************************/
1091 if ((AD.fsFlags & CA_DF_ONLYFTFILES) && !(AD.papFiletypes)) {
1092 msgPtr = GETMESSAGE(5, 20,
1093 "The 'Datatypes That Use This Action' list is empty.\n\
1094 You have selected 'Only Above List' in the 'Dropable\n\
1095 Datatypes' field.\n\
1096 Change the Dropable Datatype choice to 'All Datatypes'\n\
1097 or add at least one datatype to the list.");
1098 errPtr = XtNewString(msgPtr);
1099 display_error_message(CreateActionAppShell, errPtr);
1101 XmProcessTraversal(CA_AllFiletypesToggle, XmTRAVERSE_CURRENT);
1109 /******************************************************************************/
1117 /******************************************************************************/
1118 char * copyString(char *string)
1123 newstring = (char *)XtMalloc(strlen(string) + 1);
1124 strcpy(newstring, string);
1126 newstring = (char *)NULL;
1131 /******************************************************************************/
1139 /******************************************************************************/
1140 FiletypeData * copyFtD(FiletypeData *pFtD)
1142 FiletypeData *pcopyFtD;
1144 pcopyFtD = (FiletypeData *)XtMalloc(sizeof(FiletypeData));
1145 memset(pcopyFtD, 0, sizeof(FiletypeData));
1147 if (pFtD->pszName) {
1148 pcopyFtD->pszName = copyString(pFtD->pszName);
1150 if (pFtD->pszIcon) {
1151 pcopyFtD->pszIcon = copyString(pFtD->pszIcon);
1153 if (pFtD->pszHelp) {
1154 pcopyFtD->pszHelp = copyString(pFtD->pszHelp);
1156 if (pFtD->pszOpenCmd) {
1157 pcopyFtD->pszOpenCmd = copyString(pFtD->pszOpenCmd);
1159 if (pFtD->pszPrintCmd) {
1160 pcopyFtD->pszPrintCmd = copyString(pFtD->pszPrintCmd);
1162 if (pFtD->pszPattern) {
1163 pcopyFtD->pszPattern = copyString(pFtD->pszPattern);
1165 if (pFtD->pszPermissions) {
1166 pcopyFtD->pszPermissions = copyString(pFtD->pszPermissions);
1168 if (pFtD->pszContents) {
1169 pcopyFtD->pszContents = copyString(pFtD->pszContents);
1172 pcopyFtD->sStart = pFtD->sStart;
1173 pcopyFtD->sEnd = pFtD->sEnd;
1174 pcopyFtD->fsFlags = pFtD->fsFlags;
1175 pcopyFtD->fsInternal = pFtD->fsInternal;
1180 /******************************************************************************/
1188 /******************************************************************************/
1189 ActionData * copyAD(ActionData *pAD)
1191 ActionData *pcopyAD;
1194 pcopyAD = (ActionData *)XtMalloc(sizeof(ActionData));
1196 return((ActionData *)NULL);
1198 memset(pcopyAD, 0, sizeof(ActionData));
1201 pcopyAD->pszName = copyString(pAD->pszName);
1204 pcopyAD->pszIcon = copyString(pAD->pszIcon);
1207 pcopyAD->pszCmd = copyString(pAD->pszCmd);
1210 pcopyAD->pszHelp = copyString(pAD->pszHelp);
1212 if (pAD->pszPrompt) {
1213 pcopyAD->pszPrompt = copyString(pAD->pszPrompt);
1215 if (pAD->papFiletypes) {
1216 pcopyAD->papFiletypes = (FiletypeData **) XtMalloc(sizeof(FiletypeData *) * (pAD->cFiletypes + 1));
1217 for (i=0; i < pAD->cFiletypes; i++) {
1218 pcopyAD->papFiletypes[i] = copyFtD(pAD->papFiletypes[i]);
1221 pcopyAD->cFiletypes = pAD->cFiletypes;
1222 pcopyAD->fsFlags = pAD->fsFlags;
1225 /******************************************************************************/
1227 /* compareStrings */
1229 /* INPUT: two pointers to char *'s */
1230 /* OUTPUT: 0 they are the same */
1231 /* 1 they are different */
1233 /******************************************************************************/
1234 Boolean compareStrings(char *pszStr1, char *pszStr2)
1236 if (pszStr1 || pszStr2) {
1239 if (!strcmp(pszStr1, pszStr2)) {
1255 /******************************************************************************/
1259 /* INPUT: two pointers to FtD structures */
1260 /* OUTPUT: 0 they are the same */
1261 /* 1 they are different */
1263 /******************************************************************************/
1264 Boolean compareFtD(FiletypeData *pFtD1, FiletypeData *pFtD2)
1266 if (compareStrings(pFtD1->pszName, pFtD2->pszName)) {
1269 if (compareStrings(pFtD1->pszIcon, pFtD2->pszIcon)) {
1272 if (compareStrings(pFtD1->pszHelp, pFtD2->pszHelp)) {
1275 if (compareStrings(pFtD1->pszOpenCmd, pFtD2->pszOpenCmd)) {
1278 if (compareStrings(pFtD1->pszPrintCmd, pFtD2->pszPrintCmd)) {
1281 if (compareStrings(pFtD1->pszPattern, pFtD2->pszPattern)) {
1284 if (compareStrings(pFtD1->pszPermissions, pFtD2->pszPermissions)) {
1287 if (compareStrings(pFtD1->pszContents, pFtD2->pszContents)) {
1290 if (pFtD1->fsFlags != pFtD2->fsFlags) {
1293 if (pFtD1->sStart != pFtD2->sStart) {
1296 if (pFtD1->sEnd != pFtD2->sEnd) {
1303 /******************************************************************************/
1307 /* INPUT: two pointers to AD structures */
1308 /* OUTPUT: 0 they are the same */
1309 /* 1 they are different */
1311 /******************************************************************************/
1312 Boolean compareAD(ActionData *pAD1, ActionData *pAD2)
1316 if (compareStrings(pAD1->pszName, pAD2->pszName)) {
1319 if (compareStrings(pAD1->pszIcon, pAD2->pszIcon)) {
1322 if (compareStrings(pAD1->pszCmd, pAD2->pszCmd)) {
1325 if (compareStrings(pAD1->pszHelp, pAD2->pszHelp)) {
1328 if (compareStrings(pAD1->pszPrompt, pAD2->pszPrompt)) {
1331 if (pAD1->fsFlags != pAD2->fsFlags) {
1334 if (pAD1->cFiletypes != pAD2->cFiletypes) {
1338 if (pAD1->papFiletypes) {
1339 for (i=0; i < pAD1->cFiletypes; i++) {
1340 if (compareFtD(pAD1->papFiletypes[i], pAD2->papFiletypes[i])) {