1 /* $TOG: af_aux.c /main/6 1998/04/06 13:14:19 mgreess $ */
2 /******************************************************************************/
4 /* af_aux - auxiliary functions for add filetype */
6 /* Functions to get/set values from/to interface. */
7 /* Callback routines for AF interface. */
9 /******************************************************************************/
13 #include <sys/signal.h>
16 #include <X11/cursorfont.h>
18 #include <X11/Xatom.h>
21 #include <Xm/RowColumnP.h>
22 #include <Xm/MessageB.h>
23 #include <Xm/FileSB.h>
28 # if defined(__osf__) || defined(linux)
31 # include <sys/dirent.h>
42 /******************************************************************************/
44 /* External Variables */
46 /******************************************************************************/
48 /******************************************************************************/
52 /******************************************************************************/
54 /******************************************************************************/
56 /* CALLBACK FUNCTIONS */
58 /******************************************************************************/
60 /******************************************************************************/
62 /* get_selected_filetype_icon - determines which filetype icon is currently */
66 /* OUTPUT: Widget wid - id of selected icon gadget */
68 /******************************************************************************/
69 Widget get_selected_filetype_icon (void)
71 if (!last_filetype_pushed) {
72 last_filetype_pushed = AF_MED_IconGadget;
74 return (last_filetype_pushed);
77 /******************************************************************************/
79 /* activateCB_filetype_icon */
81 /* INPUT: Widget wid - id of icon gadget */
82 /* XtPointer client_data - not used */
83 /* XmPushButtonCallbackStruct *cbs - not used */
86 /******************************************************************************/
87 void activateCB_filetype_icon (Widget wid, XtPointer client_data,
88 DtIconCallbackStruct *cbs)
91 static Time prev_lts = 0;
93 if (cbs->reason == XmCR_ACTIVATE) {
96 printf("In activate_filetype_icon callback.\n");
98 if (last_filetype_pushed && (last_filetype_pushed != wid)) {
99 XtVaSetValues(XtParent(last_filetype_pushed), XmNborderWidth, 0, NULL);
101 XtVaSetValues(XtParent(wid), XmNborderWidth, ICON_BORDER_WIDTH, NULL);
103 last_filetype_pushed = wid;
105 /********************************************************************/
106 /* This is the support needed to provide double-click functionality */
107 /* to the icon gadgets. When double-clicked, the icon editor will */
109 /********************************************************************/
110 XtVaSetValues(wid, XmNpushButtonClickTime, 0, NULL);
112 lts = XtLastTimestampProcessed(XtDisplay(wid));
113 mct = XtGetMultiClickTime(XtDisplay(wid));
115 if ((prev_lts + mct) > lts) {
116 prev_lts = XtLastTimestampProcessed(XtDisplay(wid));
118 prev_lts = XtLastTimestampProcessed(XtDisplay(wid));
123 printf("DblClick icon callback.\n");
126 activateCB_edit_icon(wid, CA_FILETYPE_ICONS, cbs);
133 /******************************************************************************/
135 /* readAFFromGUI - */
139 /******************************************************************************/
140 void readAFFromGUI (FiletypeData *pFiletypedata)
142 getAF_FiletypeName(pFiletypedata);
143 getAF_HelpText(pFiletypedata);
144 getAF_OpenCmd(pFiletypedata);
145 getAF_PrintCmd(pFiletypedata);
146 getAF_Icons(pFiletypedata);
151 /******************************************************************************/
153 /* getAF_FiletypeName - get name of filetype family */
155 /* INPUT: FiletypeData *pFiletypedata - pointer to filetype data structure */
158 /******************************************************************************/
159 void getAF_FiletypeName (FiletypeData *pFiletypedata)
161 GetWidgetTextString(AF_FileTypeNameTextField, &(pFiletypedata->pszName));
165 /******************************************************************************/
167 /* getAF_HelpText - retrieve the Help text for the filetype */
169 /* INPUT: FiletypeData *pFiletypedata - pointer to filetype data structure */
172 /******************************************************************************/
173 void getAF_HelpText (FiletypeData *pFiletypedata)
175 GetWidgetTextString(AF_FiletypeHelpText, &(pFiletypedata->pszHelp));
179 /******************************************************************************/
181 /* getAF_Icons - store temporary icon names. */
183 /* INPUT: FiletypeData *pFiletypedata - pointer to filetype data structure */
186 /******************************************************************************/
187 void getAF_Icons(FiletypeData *pFiletypedata)
191 /***************************************************************/
193 /***************************************************************/
194 pIconData = GetIconDataFromWid(AF_MED_IconGadget);
195 if ( (pIconData->pmDirtyBit) &&
196 (pIconData->pmFileName) &&
197 (strlen(pIconData->pmFileName)) ) {
198 pFiletypedata->pszMedPmIcon = XtMalloc(strlen(pIconData->pmFileName) + 1);
199 if (pFiletypedata->pszMedPmIcon) {
200 strcpy(pFiletypedata->pszMedPmIcon, pIconData->pmFileName);
203 pIconData->pmDirtyBit = False;
204 strcpy(pIconData->pmFileName, "");
206 /***************************************************************/
208 /***************************************************************/
209 if ( (pIconData->bmDirtyBit) &&
210 (pIconData->bmFileName) &&
211 (strlen(pIconData->bmFileName)) ) {
212 pFiletypedata->pszMedBmIcon = XtMalloc(strlen(pIconData->bmFileName) + 1);
213 if (pFiletypedata->pszMedBmIcon) {
214 strcpy(pFiletypedata->pszMedBmIcon, pIconData->bmFileName);
217 pIconData->bmDirtyBit = False;
218 strcpy(pIconData->bmFileName, "");
220 /***************************************************************/
222 /***************************************************************/
223 pIconData = GetIconDataFromWid(AF_TINY_IconGadget);
224 if ( (pIconData->pmDirtyBit) &&
225 (pIconData->pmFileName) &&
226 (strlen(pIconData->pmFileName)) ) {
227 pFiletypedata->pszTinyPmIcon = XtMalloc(strlen(pIconData->pmFileName) + 1);
228 if (pFiletypedata->pszTinyPmIcon) {
229 strcpy(pFiletypedata->pszTinyPmIcon, pIconData->pmFileName);
232 pIconData->pmDirtyBit = False;
233 strcpy(pIconData->pmFileName, "");
235 /***************************************************************/
237 /***************************************************************/
238 if ( (pIconData->bmDirtyBit) &&
239 (pIconData->bmFileName) &&
240 (strlen(pIconData->bmFileName)) ) {
241 pFiletypedata->pszTinyBmIcon = XtMalloc(strlen(pIconData->bmFileName) + 1);
242 if (pFiletypedata->pszTinyBmIcon) {
243 strcpy(pFiletypedata->pszTinyBmIcon, pIconData->bmFileName);
246 pIconData->bmDirtyBit = False;
247 strcpy(pIconData->bmFileName, "");
255 AF_wids[0] = AF_MED_IconGadget;
256 AF_wids[1] = AF_TINY_IconGadget;
258 for (i=0; i < 2; i++) {
260 pIconData = GetIconDataFromWid(AF_wids[i]);
261 if ( (pIconData->pmDirtyBit) &&
262 (pIconData->pmFileName) &&
263 (strlen(pIconData->pmFileName)) ) {
264 pFiletypedata->pszMedPmIcon = XtMalloc(strlen(pIconData->pmFileName) + 1);
265 if (pFiletypedata->pszMedPmIcon) {
266 strcpy(pFiletypedata->pszMedPmIcon, pIconData->pmFileName);
269 pIconData->pmDirtyBit = False;
270 strcpy(pIconData->pmFileName, "");
273 if ( (pIconData->bmDirtyBit) &&
274 (pIconData->bmFileName) &&
275 (strlen(pIconData->bmFileName)) ) {
276 pFiletypedata->pszMedBmIcon = XtMalloc(strlen(pIconData->bmFileName) + 1);
277 if (pFiletypedata->pszMedBmIcon) {
278 strcpy(pFiletypedata->pszMedBmIcon, pIconData->bmFileName);
281 pIconData->bmDirtyBit = False;
282 strcpy(pIconData->bmFileName, "");
289 /******************************************************************************/
291 /* getAF_OpenCmd - retrieve the Open command string */
293 /* INPUT: FiletypeData *pFiletypedata - pointer to filetype data structure */
296 /******************************************************************************/
297 void getAF_OpenCmd (FiletypeData *pFiletypedata)
299 GetWidgetTextString(AF_OpenCmdText, &(pFiletypedata->pszOpenCmd));
303 /******************************************************************************/
305 /* getAF_PrintCmd - retrieve Print command string */
307 /* INPUT: FiletypeData *pFiletypedata - pointer to filetype data structure */
310 /******************************************************************************/
311 void getAF_PrintCmd (FiletypeData *pFiletypedata)
313 GetWidgetTextString(AF_FiletypePrintCmdTextField, &(pFiletypedata->pszPrintCmd));
317 /******************************************************************************/
319 /* init_AddFiletype_dialog_fields */
321 /* INPUT: FiletypeData * - pointer to FiletypeData structure */
324 /******************************************************************************/
325 void init_AddFiletype_dialog_fields(FiletypeData *pFtD)
327 char *pszIconFileName = (char *)NULL;
331 PutWidgetTextString(AF_FileTypeNameTextField, pFtD->pszName);
334 ParseAndUpdateID(pFtD);
337 PutWidgetTextString(AF_FiletypeHelpText, pFtD->pszHelp);
344 /*************************/
346 /*************************/
347 if (pFtD->pszMedPmIcon) {
348 SET_ICONGADGET_ICON(AF_MED_IconGadget, pFtD->pszMedPmIcon);
350 pszIconFileName = (char *)NULL;
351 FIND_ICONGADGET_ICON(pFtD->pszIcon, pszIconFileName, DtMEDIUM);
352 pszTmpFile = GetCorrectIconType(pszIconFileName);
353 SET_ICONGADGET_ICON(AF_MED_IconGadget, pszTmpFile);
354 if (pszIconFileName) XtFree(pszIconFileName);
355 if (pszTmpFile) XtFree(pszTmpFile);
358 /*************************/
360 /*************************/
361 if (pFtD->pszTinyPmIcon) {
362 SET_ICONGADGET_ICON(AF_TINY_IconGadget, pFtD->pszTinyPmIcon);
364 pszIconFileName = (char *)NULL;
365 FIND_ICONGADGET_ICON(pFtD->pszIcon, pszIconFileName, DtTINY);
366 pszTmpFile = GetCorrectIconType(pszIconFileName);
367 SET_ICONGADGET_ICON(AF_TINY_IconGadget, pszTmpFile);
368 if (pszIconFileName) XtFree(pszIconFileName);
369 if (pszTmpFile) XtFree(pszTmpFile);
372 /*************************/
374 /*************************/
375 if (pFtD->pszMedBmIcon) {
376 SET_ICONGADGET_ICON(AF_MED_IconGadget, pFtD->pszMedBmIcon);
378 pszIconFileName = (char *)NULL;
379 FIND_ICONGADGET_ICON(pFtD->pszIcon, pszIconFileName, DtMEDIUM);
380 pszTmpFile = GetCorrectIconType(pszIconFileName);
381 SET_ICONGADGET_ICON(AF_MED_IconGadget, pszTmpFile);
382 if (pszIconFileName) XtFree(pszIconFileName);
383 if (pszTmpFile) XtFree(pszTmpFile);
386 /*************************/
388 /*************************/
389 if (pFtD->pszTinyBmIcon) {
390 SET_ICONGADGET_ICON(AF_TINY_IconGadget, pFtD->pszTinyBmIcon);
392 pszIconFileName = (char *)NULL;
393 FIND_ICONGADGET_ICON(pFtD->pszIcon, pszIconFileName, DtTINY);
394 pszTmpFile = GetCorrectIconType(pszIconFileName);
395 SET_ICONGADGET_ICON(AF_TINY_IconGadget, pszTmpFile);
396 if (pszIconFileName) XtFree(pszIconFileName);
397 if (pszTmpFile) XtFree(pszTmpFile);
403 /*************************/
405 /*************************/
406 pszIconFileName = (char *)NULL;
407 if (pFtD->pszTinyPmIcon) {
408 pszTmpFile = pFtD->pszTinyPmIcon;
410 FIND_ICONGADGET_ICON(pFtD->pszIcon, pszIconFileName, DtTINY);
411 pszTmpFile = pszIconFileName;
413 SET_ICONGADGET_ICON(AF_TINY_IconGadget, pszTmpFile);
414 if (pszIconFileName) XtFree(pszIconFileName);
418 /*************************/
420 /*************************/
421 pszIconFileName = (char *)NULL;
422 if (pFtD->pszMedBmIcon) {
423 pszTmpFile = pFtD->pszMedBmIcon;
425 FIND_ICONGADGET_ICON(pFtD->pszIcon, pszIconFileName, DtMEDIUM);
426 pszTmpFile = pszIconFileName;
428 SET_ICONGADGET_ICON(AF_MED_IconGadget, pszTmpFile);
429 if (pszIconFileName) XtFree(pszIconFileName);
431 /*************************/
433 /*************************/
434 pszIconFileName = (char *)NULL;
435 if (pFtD->pszTinyBmIcon) {
436 pszTmpFile = pFtD->pszTinyBmIcon;
438 FIND_ICONGADGET_ICON(pFtD->pszIcon, pszIconFileName, DtTINY);
439 pszTmpFile = pszIconFileName;
441 SET_ICONGADGET_ICON(AF_TINY_IconGadget, pszTmpFile);
442 if (pszIconFileName) XtFree(pszIconFileName);
448 if (pFtD->pszOpenCmd) {
449 PutWidgetTextString(AF_OpenCmdText, pFtD->pszOpenCmd);
451 if (pFtD->pszPrintCmd) {
452 PutWidgetTextString(AF_FiletypePrintCmdTextField, pFtD->pszPrintCmd);
458 /******************************************************************************/
460 /* clear_AddFiletype_dialog_fields */
462 /* INPUT: FiletypeData * - pointer to FiletypeData structure */
465 /******************************************************************************/
466 void clear_AddFiletype_dialog_fields(void)
468 /*char pszFile[MAXBUFSIZE];*/
470 clear_text(AF_FileTypeNameTextField);
471 clear_text(AF_IdCharacteristicsText);
472 clear_text(AF_FiletypeHelpText);
473 createCB_IconGadget(AF_MED_IconGadget, FALSE, Medium_Icon);
474 createCB_IconGadget(AF_TINY_IconGadget, FALSE, Tiny_Icon);
476 SET_ICONGADGET_ICON_AND_EXT(AF_MED_IconGadget, af_med_icon_default, pszFile);
477 SET_ICONGADGET_ICON_AND_EXT(AF_TINY_IconGadget, af_tiny_icon_default, pszFile);
479 clear_text(AF_OpenCmdText);
480 clear_text(AF_FiletypePrintCmdTextField);
485 /******************************************************************************/
487 /* free_Filetypedata */
489 /* INPUT: FiletypeData * - pointer to FiletypeData structure */
492 /******************************************************************************/
493 void free_Filetypedata(FiletypeData *pFtD)
495 char buffer[MAXFILENAME];
498 printf("Free FiletypeData structure\n"); /* debug */
501 if (pFtD->pszName) XtFree(pFtD->pszName);
503 printf("Freed Name\n");
506 if (pFtD->pszIcon) XtFree(pFtD->pszIcon);
507 if (pFtD->pszMedPmIcon) {
509 printf("free_Filetypedata: unlink '%s'\n", pFtD->pszMedPmIcon); /* debug */
511 unlink(pFtD->pszMedPmIcon);
512 XtFree(pFtD->pszMedPmIcon);
514 if (pFtD->pszMedBmIcon) {
516 printf("free_Filetypedata: unlink '%s'\n", pFtD->pszMedBmIcon); /* debug */
518 unlink(pFtD->pszMedBmIcon);
519 /**** remove the mask if it exists ****/
520 sprintf(buffer, "%s_m", pFtD->pszMedBmIcon);
522 XtFree(pFtD->pszMedBmIcon);
524 if (pFtD->pszTinyPmIcon) {
526 printf("free_Filetypedata: unlink '%s'\n", pFtD->pszTinyPmIcon); /* debug */
528 unlink(pFtD->pszTinyPmIcon);
529 XtFree(pFtD->pszTinyPmIcon);
531 if (pFtD->pszTinyBmIcon) {
533 printf("free_Filetypedata: unlink '%s'\n", pFtD->pszTinyBmIcon); /* debug */
535 unlink(pFtD->pszTinyBmIcon);
536 /**** remove the mask if it exists ****/
537 sprintf(buffer, "%s_m", pFtD->pszTinyBmIcon);
539 XtFree(pFtD->pszTinyBmIcon);
542 if (pFtD->pszHelp) XtFree(pFtD->pszHelp);
543 if (pFtD->pszOpenCmd) XtFree(pFtD->pszOpenCmd);
544 if (pFtD->pszPrintCmd) XtFree(pFtD->pszPrintCmd);
545 if (pFtD->pszPattern) XtFree(pFtD->pszPattern);
546 if (pFtD->pszPermissions) XtFree(pFtD->pszPermissions);
547 if (pFtD->pszContents) XtFree(pFtD->pszContents);
548 XtFree((char *) pFtD);
552 /******************************************************************************/
554 /* AddFiletypeToList */
559 /******************************************************************************/
560 void AddFiletypeToList(void)
562 if (!XmListItemExists(CA_FiletypesList, XmStringCreateSimple(XmTextFieldGetString(AF_FileTypeNameTextField)))) {
563 XmListAddItem(CA_FiletypesList, XmStringCreateSimple(XmTextFieldGetString(AF_FileTypeNameTextField)), 0);
567 /******************************************************************************/
569 /* UpdateFiletypeDataArray */
574 /******************************************************************************/
575 void UpdateFiletypeDataArray(FiletypeData *pFtD)
577 FiletypeData **papArray;
580 /**************************************************************************/
581 /* Add this structure to the filetype array in the ActionData structure. */
582 /**************************************************************************/
583 papArray = (FiletypeData **) XtMalloc(sizeof(FiletypeData *) * (AD.cFiletypes + 1));
584 for (i=0; i < AD.cFiletypes; i++) {
585 papArray[i] = AD.papFiletypes[i];
587 papArray[AD.cFiletypes] = pFtD;
588 if (AD.papFiletypes) {
589 XtFree((char *) AD.papFiletypes);
591 AD.papFiletypes = papArray;
595 /******************************************************************************/
597 /* AddFiletypeCheckFields */
600 /* OUTPUT: FALSE - no errors found */
601 /* TRUE - found errors */
603 /******************************************************************************/
604 Boolean AddFiletypeCheckFields(void)
607 char *ptr = (char *)NULL;
608 Boolean bError = FALSE;
609 char *msgPtr, *errPtr;
611 /**************************************************************************/
612 /* Check if filetype name is present. */
613 /**************************************************************************/
616 GetWidgetTextString(AF_FileTypeNameTextField, &ptr);
618 printf("Filetype Family Name = '%s'\n", ptr);
621 msgPtr = GETMESSAGE(8, 10, "The Datatype Family Name is missing.\n\
622 Enter a name in the 'Name of Datatype Family' field.");
623 errPtr = XtNewString(msgPtr);
624 display_error_message(AddFiletype, errPtr);
626 XmProcessTraversal(AF_FileTypeNameTextField, XmTRAVERSE_CURRENT);
633 /**************************************************************************/
634 /* Check if identifying characteristics are present. */
635 /**************************************************************************/
638 GetWidgetTextString(AF_IdCharacteristicsText, &ptr);
640 printf("Identifying Chars = '%s'\n", ptr);
643 msgPtr = GETMESSAGE(8, 15,
644 "The Identifying Characteristics are missing.\n\
645 You must specify the characteristics before the datatype\n\
646 can be created. Select the Edit button next to the\n\
647 Identifying Characteristics list to specify the characteristics.");
648 errPtr = XtNewString(msgPtr);
649 display_error_message(AddFiletype, errPtr);
651 XmProcessTraversal(AF_IdCharacteristicsEdit, XmTRAVERSE_CURRENT);