2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $TOG: 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 (strlen(pIconData->bmFileName)) ) {
267 pFiletypedata->pszTinyBmIcon = XtMalloc(strlen(pIconData->bmFileName) + 1);
268 if (pFiletypedata->pszTinyBmIcon) {
269 strcpy(pFiletypedata->pszTinyBmIcon, pIconData->bmFileName);
272 pIconData->bmDirtyBit = False;
273 strcpy(pIconData->bmFileName, "");
281 AF_wids[0] = AF_MED_IconGadget;
282 AF_wids[1] = AF_TINY_IconGadget;
284 for (i=0; i < 2; i++) {
286 pIconData = GetIconDataFromWid(AF_wids[i]);
287 if ( (pIconData->pmDirtyBit) &&
288 (pIconData->pmFileName) &&
289 (strlen(pIconData->pmFileName)) ) {
290 pFiletypedata->pszMedPmIcon = XtMalloc(strlen(pIconData->pmFileName) + 1);
291 if (pFiletypedata->pszMedPmIcon) {
292 strcpy(pFiletypedata->pszMedPmIcon, pIconData->pmFileName);
295 pIconData->pmDirtyBit = False;
296 strcpy(pIconData->pmFileName, "");
299 if ( (pIconData->bmDirtyBit) &&
300 (pIconData->bmFileName) &&
301 (strlen(pIconData->bmFileName)) ) {
302 pFiletypedata->pszMedBmIcon = XtMalloc(strlen(pIconData->bmFileName) + 1);
303 if (pFiletypedata->pszMedBmIcon) {
304 strcpy(pFiletypedata->pszMedBmIcon, pIconData->bmFileName);
307 pIconData->bmDirtyBit = False;
308 strcpy(pIconData->bmFileName, "");
315 /******************************************************************************/
317 /* getAF_OpenCmd - retrieve the Open command string */
319 /* INPUT: FiletypeData *pFiletypedata - pointer to filetype data structure */
322 /******************************************************************************/
323 void getAF_OpenCmd (FiletypeData *pFiletypedata)
325 GetWidgetTextString(AF_OpenCmdText, &(pFiletypedata->pszOpenCmd));
329 /******************************************************************************/
331 /* getAF_PrintCmd - retrieve Print command string */
333 /* INPUT: FiletypeData *pFiletypedata - pointer to filetype data structure */
336 /******************************************************************************/
337 void getAF_PrintCmd (FiletypeData *pFiletypedata)
339 GetWidgetTextString(AF_FiletypePrintCmdTextField, &(pFiletypedata->pszPrintCmd));
343 /******************************************************************************/
345 /* init_AddFiletype_dialog_fields */
347 /* INPUT: FiletypeData * - pointer to FiletypeData structure */
350 /******************************************************************************/
351 void init_AddFiletype_dialog_fields(FiletypeData *pFtD)
353 char *pszIconFileName = (char *)NULL;
357 PutWidgetTextString(AF_FileTypeNameTextField, pFtD->pszName);
360 ParseAndUpdateID(pFtD);
363 PutWidgetTextString(AF_FiletypeHelpText, pFtD->pszHelp);
370 /*************************/
372 /*************************/
373 if (pFtD->pszMedPmIcon) {
374 SET_ICONGADGET_ICON(AF_MED_IconGadget, pFtD->pszMedPmIcon);
376 pszIconFileName = (char *)NULL;
377 FIND_ICONGADGET_ICON(pFtD->pszIcon, pszIconFileName, DtMEDIUM);
378 pszTmpFile = GetCorrectIconType(pszIconFileName);
379 SET_ICONGADGET_ICON(AF_MED_IconGadget, pszTmpFile);
380 if (pszIconFileName) XtFree(pszIconFileName);
381 if (pszTmpFile) XtFree(pszTmpFile);
384 /*************************/
386 /*************************/
387 if (pFtD->pszTinyPmIcon) {
388 SET_ICONGADGET_ICON(AF_TINY_IconGadget, pFtD->pszTinyPmIcon);
390 pszIconFileName = (char *)NULL;
391 FIND_ICONGADGET_ICON(pFtD->pszIcon, pszIconFileName, DtTINY);
392 pszTmpFile = GetCorrectIconType(pszIconFileName);
393 SET_ICONGADGET_ICON(AF_TINY_IconGadget, pszTmpFile);
394 if (pszIconFileName) XtFree(pszIconFileName);
395 if (pszTmpFile) XtFree(pszTmpFile);
398 /*************************/
400 /*************************/
401 if (pFtD->pszMedBmIcon) {
402 SET_ICONGADGET_ICON(AF_MED_IconGadget, pFtD->pszMedBmIcon);
404 pszIconFileName = (char *)NULL;
405 FIND_ICONGADGET_ICON(pFtD->pszIcon, pszIconFileName, DtMEDIUM);
406 pszTmpFile = GetCorrectIconType(pszIconFileName);
407 SET_ICONGADGET_ICON(AF_MED_IconGadget, pszTmpFile);
408 if (pszIconFileName) XtFree(pszIconFileName);
409 if (pszTmpFile) XtFree(pszTmpFile);
412 /*************************/
414 /*************************/
415 if (pFtD->pszTinyBmIcon) {
416 SET_ICONGADGET_ICON(AF_TINY_IconGadget, pFtD->pszTinyBmIcon);
418 pszIconFileName = (char *)NULL;
419 FIND_ICONGADGET_ICON(pFtD->pszIcon, pszIconFileName, DtTINY);
420 pszTmpFile = GetCorrectIconType(pszIconFileName);
421 SET_ICONGADGET_ICON(AF_TINY_IconGadget, pszTmpFile);
422 if (pszIconFileName) XtFree(pszIconFileName);
423 if (pszTmpFile) XtFree(pszTmpFile);
429 /*************************/
431 /*************************/
432 pszIconFileName = (char *)NULL;
433 if (pFtD->pszTinyPmIcon) {
434 pszTmpFile = pFtD->pszTinyPmIcon;
436 FIND_ICONGADGET_ICON(pFtD->pszIcon, pszIconFileName, DtTINY);
437 pszTmpFile = pszIconFileName;
439 SET_ICONGADGET_ICON(AF_TINY_IconGadget, pszTmpFile);
440 if (pszIconFileName) XtFree(pszIconFileName);
444 /*************************/
446 /*************************/
447 pszIconFileName = (char *)NULL;
448 if (pFtD->pszMedBmIcon) {
449 pszTmpFile = pFtD->pszMedBmIcon;
451 FIND_ICONGADGET_ICON(pFtD->pszIcon, pszIconFileName, DtMEDIUM);
452 pszTmpFile = pszIconFileName;
454 SET_ICONGADGET_ICON(AF_MED_IconGadget, pszTmpFile);
455 if (pszIconFileName) XtFree(pszIconFileName);
457 /*************************/
459 /*************************/
460 pszIconFileName = (char *)NULL;
461 if (pFtD->pszTinyBmIcon) {
462 pszTmpFile = pFtD->pszTinyBmIcon;
464 FIND_ICONGADGET_ICON(pFtD->pszIcon, pszIconFileName, DtTINY);
465 pszTmpFile = pszIconFileName;
467 SET_ICONGADGET_ICON(AF_TINY_IconGadget, pszTmpFile);
468 if (pszIconFileName) XtFree(pszIconFileName);
474 if (pFtD->pszOpenCmd) {
475 PutWidgetTextString(AF_OpenCmdText, pFtD->pszOpenCmd);
477 if (pFtD->pszPrintCmd) {
478 PutWidgetTextString(AF_FiletypePrintCmdTextField, pFtD->pszPrintCmd);
484 /******************************************************************************/
486 /* clear_AddFiletype_dialog_fields */
488 /* INPUT: FiletypeData * - pointer to FiletypeData structure */
491 /******************************************************************************/
492 void clear_AddFiletype_dialog_fields(void)
494 /*char pszFile[MAXBUFSIZE];*/
496 clear_text(AF_FileTypeNameTextField);
497 clear_text(AF_IdCharacteristicsText);
498 clear_text(AF_FiletypeHelpText);
499 createCB_IconGadget(AF_MED_IconGadget, FALSE, Medium_Icon);
500 createCB_IconGadget(AF_TINY_IconGadget, FALSE, Tiny_Icon);
502 SET_ICONGADGET_ICON_AND_EXT(AF_MED_IconGadget, af_med_icon_default, pszFile);
503 SET_ICONGADGET_ICON_AND_EXT(AF_TINY_IconGadget, af_tiny_icon_default, pszFile);
505 clear_text(AF_OpenCmdText);
506 clear_text(AF_FiletypePrintCmdTextField);
511 /******************************************************************************/
513 /* free_Filetypedata */
515 /* INPUT: FiletypeData * - pointer to FiletypeData structure */
518 /******************************************************************************/
519 void free_Filetypedata(FiletypeData *pFtD)
521 char buffer[MAXFILENAME];
524 printf("Free FiletypeData structure\n"); /* debug */
527 if (pFtD->pszName) XtFree(pFtD->pszName);
529 printf("Freed Name\n");
532 if (pFtD->pszIcon) XtFree(pFtD->pszIcon);
533 if (pFtD->pszMedPmIcon) {
535 printf("free_Filetypedata: unlink '%s'\n", pFtD->pszMedPmIcon); /* debug */
537 unlink(pFtD->pszMedPmIcon);
538 XtFree(pFtD->pszMedPmIcon);
540 if (pFtD->pszMedBmIcon) {
542 printf("free_Filetypedata: unlink '%s'\n", pFtD->pszMedBmIcon); /* debug */
544 unlink(pFtD->pszMedBmIcon);
545 /**** remove the mask if it exists ****/
546 sprintf(buffer, "%s_m", pFtD->pszMedBmIcon);
548 XtFree(pFtD->pszMedBmIcon);
550 if (pFtD->pszTinyPmIcon) {
552 printf("free_Filetypedata: unlink '%s'\n", pFtD->pszTinyPmIcon); /* debug */
554 unlink(pFtD->pszTinyPmIcon);
555 XtFree(pFtD->pszTinyPmIcon);
557 if (pFtD->pszTinyBmIcon) {
559 printf("free_Filetypedata: unlink '%s'\n", pFtD->pszTinyBmIcon); /* debug */
561 unlink(pFtD->pszTinyBmIcon);
562 /**** remove the mask if it exists ****/
563 sprintf(buffer, "%s_m", pFtD->pszTinyBmIcon);
565 XtFree(pFtD->pszTinyBmIcon);
568 if (pFtD->pszHelp) XtFree(pFtD->pszHelp);
569 if (pFtD->pszOpenCmd) XtFree(pFtD->pszOpenCmd);
570 if (pFtD->pszPrintCmd) XtFree(pFtD->pszPrintCmd);
571 if (pFtD->pszPattern) XtFree(pFtD->pszPattern);
572 if (pFtD->pszPermissions) XtFree(pFtD->pszPermissions);
573 if (pFtD->pszContents) XtFree(pFtD->pszContents);
574 XtFree((char *) pFtD);
578 /******************************************************************************/
580 /* AddFiletypeToList */
585 /******************************************************************************/
586 void AddFiletypeToList(void)
588 if (!XmListItemExists(CA_FiletypesList, XmStringCreateSimple(XmTextFieldGetString(AF_FileTypeNameTextField)))) {
589 XmListAddItem(CA_FiletypesList, XmStringCreateSimple(XmTextFieldGetString(AF_FileTypeNameTextField)), 0);
593 /******************************************************************************/
595 /* UpdateFiletypeDataArray */
600 /******************************************************************************/
601 void UpdateFiletypeDataArray(FiletypeData *pFtD)
603 FiletypeData **papArray;
606 /**************************************************************************/
607 /* Add this structure to the filetype array in the ActionData structure. */
608 /**************************************************************************/
609 papArray = (FiletypeData **) XtMalloc(sizeof(FiletypeData *) * (AD.cFiletypes + 1));
610 for (i=0; i < AD.cFiletypes; i++) {
611 papArray[i] = AD.papFiletypes[i];
613 papArray[AD.cFiletypes] = pFtD;
614 if (AD.papFiletypes) {
615 XtFree((char *) AD.papFiletypes);
617 AD.papFiletypes = papArray;
621 /******************************************************************************/
623 /* AddFiletypeCheckFields */
626 /* OUTPUT: FALSE - no errors found */
627 /* TRUE - found errors */
629 /******************************************************************************/
630 Boolean AddFiletypeCheckFields(void)
633 char *ptr = (char *)NULL;
634 Boolean bError = FALSE;
635 char *msgPtr, *errPtr;
637 /**************************************************************************/
638 /* Check if filetype name is present. */
639 /**************************************************************************/
642 GetWidgetTextString(AF_FileTypeNameTextField, &ptr);
644 printf("Filetype Family Name = '%s'\n", ptr);
647 msgPtr = GETMESSAGE(8, 10, "The Datatype Family Name is missing.\n\
648 Enter a name in the 'Name of Datatype Family' field.");
649 errPtr = XtNewString(msgPtr);
650 display_error_message(AddFiletype, errPtr);
652 XmProcessTraversal(AF_FileTypeNameTextField, XmTRAVERSE_CURRENT);
659 /**************************************************************************/
660 /* Check if identifying characteristics are present. */
661 /**************************************************************************/
664 GetWidgetTextString(AF_IdCharacteristicsText, &ptr);
666 printf("Identifying Chars = '%s'\n", ptr);
669 msgPtr = GETMESSAGE(8, 15,
670 "The Identifying Characteristics are missing.\n\
671 You must specify the characteristics before the datatype\n\
672 can be created. Select the Edit button next to the\n\
673 Identifying Characteristics list to specify the characteristics.");
674 errPtr = XtNewString(msgPtr);
675 display_error_message(AddFiletype, errPtr);
677 XmProcessTraversal(AF_IdCharacteristicsEdit, XmTRAVERSE_CURRENT);