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: af_aux.c /main/6 1998/04/06 13:14:19 mgreess $ */
24 /******************************************************************************/
26 /* af_aux - auxiliary functions for add filetype */
28 /* Functions to get/set values from/to interface. */
29 /* Callback routines for AF interface. */
31 /******************************************************************************/
35 #include <sys/signal.h>
38 #include <X11/cursorfont.h>
40 #include <X11/Xatom.h>
43 #include <Xm/RowColumnP.h>
44 #include <Xm/MessageB.h>
45 #include <Xm/FileSB.h>
51 # if defined(__osf__) || defined(linux)
54 # include <sys/dirent.h>
65 #include "ErrorDialog.h"
66 #include "FileCharacteristics.h"
68 /******************************************************************************/
70 /* External Variables */
72 /******************************************************************************/
74 /******************************************************************************/
78 /******************************************************************************/
80 /******************************************************************************/
82 /* CALLBACK FUNCTIONS */
84 /******************************************************************************/
86 /******************************************************************************/
88 /* get_selected_filetype_icon - determines which filetype icon is currently */
92 /* OUTPUT: Widget wid - id of selected icon gadget */
94 /******************************************************************************/
95 Widget get_selected_filetype_icon (void)
97 if (!last_filetype_pushed) {
98 last_filetype_pushed = AF_MED_IconGadget;
100 return (last_filetype_pushed);
103 /******************************************************************************/
105 /* activateCB_filetype_icon */
107 /* INPUT: Widget wid - id of icon gadget */
108 /* XtPointer client_data - not used */
109 /* XmPushButtonCallbackStruct *cbs - not used */
112 /******************************************************************************/
113 void activateCB_filetype_icon (Widget wid, XtPointer client_data,
114 DtIconCallbackStruct *cbs)
117 static Time prev_lts = 0;
119 if (cbs->reason == XmCR_ACTIVATE) {
122 printf("In activate_filetype_icon callback.\n");
124 if (last_filetype_pushed && (last_filetype_pushed != wid)) {
125 XtVaSetValues(XtParent(last_filetype_pushed), XmNborderWidth, 0, NULL);
127 XtVaSetValues(XtParent(wid), XmNborderWidth, ICON_BORDER_WIDTH, NULL);
129 last_filetype_pushed = wid;
131 /********************************************************************/
132 /* This is the support needed to provide double-click functionality */
133 /* to the icon gadgets. When double-clicked, the icon editor will */
135 /********************************************************************/
136 XtVaSetValues(wid, XmNpushButtonClickTime, 0, NULL);
138 lts = XtLastTimestampProcessed(XtDisplay(wid));
139 mct = XtGetMultiClickTime(XtDisplay(wid));
141 if ((prev_lts + mct) > lts) {
142 prev_lts = XtLastTimestampProcessed(XtDisplay(wid));
144 prev_lts = XtLastTimestampProcessed(XtDisplay(wid));
149 printf("DblClick icon callback.\n");
152 activateCB_edit_icon(wid, (XtPointer)CA_FILETYPE_ICONS,
153 (XmPushButtonCallbackStruct *)cbs /* unused anyway */);
160 /******************************************************************************/
162 /* readAFFromGUI - */
166 /******************************************************************************/
167 void readAFFromGUI (FiletypeData *pFiletypedata)
169 getAF_FiletypeName(pFiletypedata);
170 getAF_HelpText(pFiletypedata);
171 getAF_OpenCmd(pFiletypedata);
172 getAF_PrintCmd(pFiletypedata);
173 getAF_Icons(pFiletypedata);
178 /******************************************************************************/
180 /* getAF_FiletypeName - get name of filetype family */
182 /* INPUT: FiletypeData *pFiletypedata - pointer to filetype data structure */
185 /******************************************************************************/
186 void getAF_FiletypeName (FiletypeData *pFiletypedata)
188 GetWidgetTextString(AF_FileTypeNameTextField, &(pFiletypedata->pszName));
192 /******************************************************************************/
194 /* getAF_HelpText - retrieve the Help text for the filetype */
196 /* INPUT: FiletypeData *pFiletypedata - pointer to filetype data structure */
199 /******************************************************************************/
200 void getAF_HelpText (FiletypeData *pFiletypedata)
202 GetWidgetTextString(AF_FiletypeHelpText, &(pFiletypedata->pszHelp));
206 /******************************************************************************/
208 /* getAF_Icons - store temporary icon names. */
210 /* INPUT: FiletypeData *pFiletypedata - pointer to filetype data structure */
213 /******************************************************************************/
214 void getAF_Icons(FiletypeData *pFiletypedata)
218 /***************************************************************/
220 /***************************************************************/
221 pIconData = GetIconDataFromWid(AF_MED_IconGadget);
222 if ( (pIconData->pmDirtyBit) &&
223 (pIconData->pmFileName) &&
224 (strlen(pIconData->pmFileName)) ) {
225 pFiletypedata->pszMedPmIcon = XtMalloc(strlen(pIconData->pmFileName) + 1);
226 if (pFiletypedata->pszMedPmIcon) {
227 strcpy(pFiletypedata->pszMedPmIcon, pIconData->pmFileName);
230 pIconData->pmDirtyBit = False;
231 strcpy(pIconData->pmFileName, "");
233 /***************************************************************/
235 /***************************************************************/
236 if ( (pIconData->bmDirtyBit) &&
237 (pIconData->bmFileName) &&
238 (strlen(pIconData->bmFileName)) ) {
239 pFiletypedata->pszMedBmIcon = XtMalloc(strlen(pIconData->bmFileName) + 1);
240 if (pFiletypedata->pszMedBmIcon) {
241 strcpy(pFiletypedata->pszMedBmIcon, pIconData->bmFileName);
244 pIconData->bmDirtyBit = False;
245 strcpy(pIconData->bmFileName, "");
247 /***************************************************************/
249 /***************************************************************/
250 pIconData = GetIconDataFromWid(AF_TINY_IconGadget);
251 if ( (pIconData->pmDirtyBit) &&
252 (pIconData->pmFileName) &&
253 (strlen(pIconData->pmFileName)) ) {
254 pFiletypedata->pszTinyPmIcon = XtMalloc(strlen(pIconData->pmFileName) + 1);
255 if (pFiletypedata->pszTinyPmIcon) {
256 strcpy(pFiletypedata->pszTinyPmIcon, pIconData->pmFileName);
259 pIconData->pmDirtyBit = False;
260 strcpy(pIconData->pmFileName, "");
262 /***************************************************************/
264 /***************************************************************/
265 if ( (pIconData->bmDirtyBit) &&
266 (pIconData->bmFileName) &&
267 (strlen(pIconData->bmFileName)) ) {
268 pFiletypedata->pszTinyBmIcon = XtMalloc(strlen(pIconData->bmFileName) + 1);
269 if (pFiletypedata->pszTinyBmIcon) {
270 strcpy(pFiletypedata->pszTinyBmIcon, pIconData->bmFileName);
273 pIconData->bmDirtyBit = False;
274 strcpy(pIconData->bmFileName, "");
282 AF_wids[0] = AF_MED_IconGadget;
283 AF_wids[1] = AF_TINY_IconGadget;
285 for (i=0; i < 2; i++) {
287 pIconData = GetIconDataFromWid(AF_wids[i]);
288 if ( (pIconData->pmDirtyBit) &&
289 (pIconData->pmFileName) &&
290 (strlen(pIconData->pmFileName)) ) {
291 pFiletypedata->pszMedPmIcon = XtMalloc(strlen(pIconData->pmFileName) + 1);
292 if (pFiletypedata->pszMedPmIcon) {
293 strcpy(pFiletypedata->pszMedPmIcon, pIconData->pmFileName);
296 pIconData->pmDirtyBit = False;
297 strcpy(pIconData->pmFileName, "");
300 if ( (pIconData->bmDirtyBit) &&
301 (pIconData->bmFileName) &&
302 (strlen(pIconData->bmFileName)) ) {
303 pFiletypedata->pszMedBmIcon = XtMalloc(strlen(pIconData->bmFileName) + 1);
304 if (pFiletypedata->pszMedBmIcon) {
305 strcpy(pFiletypedata->pszMedBmIcon, pIconData->bmFileName);
308 pIconData->bmDirtyBit = False;
309 strcpy(pIconData->bmFileName, "");
316 /******************************************************************************/
318 /* getAF_OpenCmd - retrieve the Open command string */
320 /* INPUT: FiletypeData *pFiletypedata - pointer to filetype data structure */
323 /******************************************************************************/
324 void getAF_OpenCmd (FiletypeData *pFiletypedata)
326 GetWidgetTextString(AF_OpenCmdText, &(pFiletypedata->pszOpenCmd));
330 /******************************************************************************/
332 /* getAF_PrintCmd - retrieve Print command string */
334 /* INPUT: FiletypeData *pFiletypedata - pointer to filetype data structure */
337 /******************************************************************************/
338 void getAF_PrintCmd (FiletypeData *pFiletypedata)
340 GetWidgetTextString(AF_FiletypePrintCmdTextField, &(pFiletypedata->pszPrintCmd));
344 /******************************************************************************/
346 /* init_AddFiletype_dialog_fields */
348 /* INPUT: FiletypeData * - pointer to FiletypeData structure */
351 /******************************************************************************/
352 void init_AddFiletype_dialog_fields(FiletypeData *pFtD)
354 char *pszIconFileName = (char *)NULL;
358 PutWidgetTextString(AF_FileTypeNameTextField, pFtD->pszName);
361 ParseAndUpdateID(pFtD);
364 PutWidgetTextString(AF_FiletypeHelpText, pFtD->pszHelp);
371 /*************************/
373 /*************************/
374 if (pFtD->pszMedPmIcon) {
375 SET_ICONGADGET_ICON(AF_MED_IconGadget, pFtD->pszMedPmIcon);
377 pszIconFileName = (char *)NULL;
378 FIND_ICONGADGET_ICON(pFtD->pszIcon, pszIconFileName, DtMEDIUM);
379 pszTmpFile = GetCorrectIconType(pszIconFileName);
380 SET_ICONGADGET_ICON(AF_MED_IconGadget, pszTmpFile);
381 if (pszIconFileName) XtFree(pszIconFileName);
382 if (pszTmpFile) XtFree(pszTmpFile);
385 /*************************/
387 /*************************/
388 if (pFtD->pszTinyPmIcon) {
389 SET_ICONGADGET_ICON(AF_TINY_IconGadget, pFtD->pszTinyPmIcon);
391 pszIconFileName = (char *)NULL;
392 FIND_ICONGADGET_ICON(pFtD->pszIcon, pszIconFileName, DtTINY);
393 pszTmpFile = GetCorrectIconType(pszIconFileName);
394 SET_ICONGADGET_ICON(AF_TINY_IconGadget, pszTmpFile);
395 if (pszIconFileName) XtFree(pszIconFileName);
396 if (pszTmpFile) XtFree(pszTmpFile);
399 /*************************/
401 /*************************/
402 if (pFtD->pszMedBmIcon) {
403 SET_ICONGADGET_ICON(AF_MED_IconGadget, pFtD->pszMedBmIcon);
405 pszIconFileName = (char *)NULL;
406 FIND_ICONGADGET_ICON(pFtD->pszIcon, pszIconFileName, DtMEDIUM);
407 pszTmpFile = GetCorrectIconType(pszIconFileName);
408 SET_ICONGADGET_ICON(AF_MED_IconGadget, pszTmpFile);
409 if (pszIconFileName) XtFree(pszIconFileName);
410 if (pszTmpFile) XtFree(pszTmpFile);
413 /*************************/
415 /*************************/
416 if (pFtD->pszTinyBmIcon) {
417 SET_ICONGADGET_ICON(AF_TINY_IconGadget, pFtD->pszTinyBmIcon);
419 pszIconFileName = (char *)NULL;
420 FIND_ICONGADGET_ICON(pFtD->pszIcon, pszIconFileName, DtTINY);
421 pszTmpFile = GetCorrectIconType(pszIconFileName);
422 SET_ICONGADGET_ICON(AF_TINY_IconGadget, pszTmpFile);
423 if (pszIconFileName) XtFree(pszIconFileName);
424 if (pszTmpFile) XtFree(pszTmpFile);
430 /*************************/
432 /*************************/
433 pszIconFileName = (char *)NULL;
434 if (pFtD->pszTinyPmIcon) {
435 pszTmpFile = pFtD->pszTinyPmIcon;
437 FIND_ICONGADGET_ICON(pFtD->pszIcon, pszIconFileName, DtTINY);
438 pszTmpFile = pszIconFileName;
440 SET_ICONGADGET_ICON(AF_TINY_IconGadget, pszTmpFile);
441 if (pszIconFileName) XtFree(pszIconFileName);
445 /*************************/
447 /*************************/
448 pszIconFileName = (char *)NULL;
449 if (pFtD->pszMedBmIcon) {
450 pszTmpFile = pFtD->pszMedBmIcon;
452 FIND_ICONGADGET_ICON(pFtD->pszIcon, pszIconFileName, DtMEDIUM);
453 pszTmpFile = pszIconFileName;
455 SET_ICONGADGET_ICON(AF_MED_IconGadget, pszTmpFile);
456 if (pszIconFileName) XtFree(pszIconFileName);
458 /*************************/
460 /*************************/
461 pszIconFileName = (char *)NULL;
462 if (pFtD->pszTinyBmIcon) {
463 pszTmpFile = pFtD->pszTinyBmIcon;
465 FIND_ICONGADGET_ICON(pFtD->pszIcon, pszIconFileName, DtTINY);
466 pszTmpFile = pszIconFileName;
468 SET_ICONGADGET_ICON(AF_TINY_IconGadget, pszTmpFile);
469 if (pszIconFileName) XtFree(pszIconFileName);
475 if (pFtD->pszOpenCmd) {
476 PutWidgetTextString(AF_OpenCmdText, pFtD->pszOpenCmd);
478 if (pFtD->pszPrintCmd) {
479 PutWidgetTextString(AF_FiletypePrintCmdTextField, pFtD->pszPrintCmd);
485 /******************************************************************************/
487 /* clear_AddFiletype_dialog_fields */
489 /* INPUT: FiletypeData * - pointer to FiletypeData structure */
492 /******************************************************************************/
493 void clear_AddFiletype_dialog_fields(void)
495 /*char pszFile[MAXBUFSIZE];*/
497 clear_text(AF_FileTypeNameTextField);
498 clear_text(AF_IdCharacteristicsText);
499 clear_text(AF_FiletypeHelpText);
500 createCB_IconGadget(AF_MED_IconGadget, FALSE, Medium_Icon);
501 createCB_IconGadget(AF_TINY_IconGadget, FALSE, Tiny_Icon);
503 SET_ICONGADGET_ICON_AND_EXT(AF_MED_IconGadget, af_med_icon_default, pszFile);
504 SET_ICONGADGET_ICON_AND_EXT(AF_TINY_IconGadget, af_tiny_icon_default, pszFile);
506 clear_text(AF_OpenCmdText);
507 clear_text(AF_FiletypePrintCmdTextField);
512 /******************************************************************************/
514 /* free_Filetypedata */
516 /* INPUT: FiletypeData * - pointer to FiletypeData structure */
519 /******************************************************************************/
520 void free_Filetypedata(FiletypeData *pFtD)
522 char buffer[MAXFILENAME];
525 printf("Free FiletypeData structure\n"); /* debug */
528 if (pFtD->pszName) XtFree(pFtD->pszName);
530 printf("Freed Name\n");
533 if (pFtD->pszIcon) XtFree(pFtD->pszIcon);
534 if (pFtD->pszMedPmIcon) {
536 printf("free_Filetypedata: unlink '%s'\n", pFtD->pszMedPmIcon); /* debug */
538 unlink(pFtD->pszMedPmIcon);
539 XtFree(pFtD->pszMedPmIcon);
541 if (pFtD->pszMedBmIcon) {
543 printf("free_Filetypedata: unlink '%s'\n", pFtD->pszMedBmIcon); /* debug */
545 unlink(pFtD->pszMedBmIcon);
546 /**** remove the mask if it exists ****/
547 sprintf(buffer, "%s_m", pFtD->pszMedBmIcon);
549 XtFree(pFtD->pszMedBmIcon);
551 if (pFtD->pszTinyPmIcon) {
553 printf("free_Filetypedata: unlink '%s'\n", pFtD->pszTinyPmIcon); /* debug */
555 unlink(pFtD->pszTinyPmIcon);
556 XtFree(pFtD->pszTinyPmIcon);
558 if (pFtD->pszTinyBmIcon) {
560 printf("free_Filetypedata: unlink '%s'\n", pFtD->pszTinyBmIcon); /* debug */
562 unlink(pFtD->pszTinyBmIcon);
563 /**** remove the mask if it exists ****/
564 sprintf(buffer, "%s_m", pFtD->pszTinyBmIcon);
566 XtFree(pFtD->pszTinyBmIcon);
569 if (pFtD->pszHelp) XtFree(pFtD->pszHelp);
570 if (pFtD->pszOpenCmd) XtFree(pFtD->pszOpenCmd);
571 if (pFtD->pszPrintCmd) XtFree(pFtD->pszPrintCmd);
572 if (pFtD->pszPattern) XtFree(pFtD->pszPattern);
573 if (pFtD->pszPermissions) XtFree(pFtD->pszPermissions);
574 if (pFtD->pszContents) XtFree(pFtD->pszContents);
575 XtFree((char *) pFtD);
579 /******************************************************************************/
581 /* AddFiletypeToList */
586 /******************************************************************************/
587 void AddFiletypeToList(void)
589 if (!XmListItemExists(CA_FiletypesList, XmStringCreateSimple(XmTextFieldGetString(AF_FileTypeNameTextField)))) {
590 XmListAddItem(CA_FiletypesList, XmStringCreateSimple(XmTextFieldGetString(AF_FileTypeNameTextField)), 0);
594 /******************************************************************************/
596 /* UpdateFiletypeDataArray */
601 /******************************************************************************/
602 void UpdateFiletypeDataArray(FiletypeData *pFtD)
604 FiletypeData **papArray;
607 /**************************************************************************/
608 /* Add this structure to the filetype array in the ActionData structure. */
609 /**************************************************************************/
610 papArray = (FiletypeData **) XtMalloc(sizeof(FiletypeData *) * (AD.cFiletypes + 1));
611 for (i=0; i < AD.cFiletypes; i++) {
612 papArray[i] = AD.papFiletypes[i];
614 papArray[AD.cFiletypes] = pFtD;
615 if (AD.papFiletypes) {
616 XtFree((char *) AD.papFiletypes);
618 AD.papFiletypes = papArray;
622 /******************************************************************************/
624 /* AddFiletypeCheckFields */
627 /* OUTPUT: FALSE - no errors found */
628 /* TRUE - found errors */
630 /******************************************************************************/
631 Boolean AddFiletypeCheckFields(void)
634 char *ptr = (char *)NULL;
635 Boolean bError = FALSE;
636 char *msgPtr, *errPtr;
638 /**************************************************************************/
639 /* Check if filetype name is present. */
640 /**************************************************************************/
643 GetWidgetTextString(AF_FileTypeNameTextField, &ptr);
645 printf("Filetype Family Name = '%s'\n", ptr);
648 msgPtr = GETMESSAGE(8, 10, "The Datatype Family Name is missing.\n\
649 Enter a name in the 'Name of Datatype Family' field.");
650 errPtr = XtNewString(msgPtr);
651 display_error_message(AddFiletype, errPtr);
653 XmProcessTraversal(AF_FileTypeNameTextField, XmTRAVERSE_CURRENT);
660 /**************************************************************************/
661 /* Check if identifying characteristics are present. */
662 /**************************************************************************/
665 GetWidgetTextString(AF_IdCharacteristicsText, &ptr);
667 printf("Identifying Chars = '%s'\n", ptr);
670 msgPtr = GETMESSAGE(8, 15,
671 "The Identifying Characteristics are missing.\n\
672 You must specify the characteristics before the datatype\n\
673 can be created. Select the Edit button next to the\n\
674 Identifying Characteristics list to specify the characteristics.");
675 errPtr = XtNewString(msgPtr);
676 display_error_message(AddFiletype, errPtr);
678 XmProcessTraversal(AF_IdCharacteristicsEdit, XmTRAVERSE_CURRENT);