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>
50 # if defined(__osf__) || defined(linux)
53 # include <sys/dirent.h>
64 /******************************************************************************/
66 /* External Variables */
68 /******************************************************************************/
70 /******************************************************************************/
74 /******************************************************************************/
76 /******************************************************************************/
78 /* CALLBACK FUNCTIONS */
80 /******************************************************************************/
82 /******************************************************************************/
84 /* get_selected_filetype_icon - determines which filetype icon is currently */
88 /* OUTPUT: Widget wid - id of selected icon gadget */
90 /******************************************************************************/
91 Widget get_selected_filetype_icon (void)
93 if (!last_filetype_pushed) {
94 last_filetype_pushed = AF_MED_IconGadget;
96 return (last_filetype_pushed);
99 /******************************************************************************/
101 /* activateCB_filetype_icon */
103 /* INPUT: Widget wid - id of icon gadget */
104 /* XtPointer client_data - not used */
105 /* XmPushButtonCallbackStruct *cbs - not used */
108 /******************************************************************************/
109 void activateCB_filetype_icon (Widget wid, XtPointer client_data,
110 DtIconCallbackStruct *cbs)
113 static Time prev_lts = 0;
115 if (cbs->reason == XmCR_ACTIVATE) {
118 printf("In activate_filetype_icon callback.\n");
120 if (last_filetype_pushed && (last_filetype_pushed != wid)) {
121 XtVaSetValues(XtParent(last_filetype_pushed), XmNborderWidth, 0, NULL);
123 XtVaSetValues(XtParent(wid), XmNborderWidth, ICON_BORDER_WIDTH, NULL);
125 last_filetype_pushed = wid;
127 /********************************************************************/
128 /* This is the support needed to provide double-click functionality */
129 /* to the icon gadgets. When double-clicked, the icon editor will */
131 /********************************************************************/
132 XtVaSetValues(wid, XmNpushButtonClickTime, 0, NULL);
134 lts = XtLastTimestampProcessed(XtDisplay(wid));
135 mct = XtGetMultiClickTime(XtDisplay(wid));
137 if ((prev_lts + mct) > lts) {
138 prev_lts = XtLastTimestampProcessed(XtDisplay(wid));
140 prev_lts = XtLastTimestampProcessed(XtDisplay(wid));
145 printf("DblClick icon callback.\n");
148 activateCB_edit_icon(wid, CA_FILETYPE_ICONS, cbs);
155 /******************************************************************************/
157 /* readAFFromGUI - */
161 /******************************************************************************/
162 void readAFFromGUI (FiletypeData *pFiletypedata)
164 getAF_FiletypeName(pFiletypedata);
165 getAF_HelpText(pFiletypedata);
166 getAF_OpenCmd(pFiletypedata);
167 getAF_PrintCmd(pFiletypedata);
168 getAF_Icons(pFiletypedata);
173 /******************************************************************************/
175 /* getAF_FiletypeName - get name of filetype family */
177 /* INPUT: FiletypeData *pFiletypedata - pointer to filetype data structure */
180 /******************************************************************************/
181 void getAF_FiletypeName (FiletypeData *pFiletypedata)
183 GetWidgetTextString(AF_FileTypeNameTextField, &(pFiletypedata->pszName));
187 /******************************************************************************/
189 /* getAF_HelpText - retrieve the Help text for the filetype */
191 /* INPUT: FiletypeData *pFiletypedata - pointer to filetype data structure */
194 /******************************************************************************/
195 void getAF_HelpText (FiletypeData *pFiletypedata)
197 GetWidgetTextString(AF_FiletypeHelpText, &(pFiletypedata->pszHelp));
201 /******************************************************************************/
203 /* getAF_Icons - store temporary icon names. */
205 /* INPUT: FiletypeData *pFiletypedata - pointer to filetype data structure */
208 /******************************************************************************/
209 void getAF_Icons(FiletypeData *pFiletypedata)
213 /***************************************************************/
215 /***************************************************************/
216 pIconData = GetIconDataFromWid(AF_MED_IconGadget);
217 if ( (pIconData->pmDirtyBit) &&
218 (pIconData->pmFileName) &&
219 (strlen(pIconData->pmFileName)) ) {
220 pFiletypedata->pszMedPmIcon = XtMalloc(strlen(pIconData->pmFileName) + 1);
221 if (pFiletypedata->pszMedPmIcon) {
222 strcpy(pFiletypedata->pszMedPmIcon, pIconData->pmFileName);
225 pIconData->pmDirtyBit = False;
226 strcpy(pIconData->pmFileName, "");
228 /***************************************************************/
230 /***************************************************************/
231 if ( (pIconData->bmDirtyBit) &&
232 (pIconData->bmFileName) &&
233 (strlen(pIconData->bmFileName)) ) {
234 pFiletypedata->pszMedBmIcon = XtMalloc(strlen(pIconData->bmFileName) + 1);
235 if (pFiletypedata->pszMedBmIcon) {
236 strcpy(pFiletypedata->pszMedBmIcon, pIconData->bmFileName);
239 pIconData->bmDirtyBit = False;
240 strcpy(pIconData->bmFileName, "");
242 /***************************************************************/
244 /***************************************************************/
245 pIconData = GetIconDataFromWid(AF_TINY_IconGadget);
246 if ( (pIconData->pmDirtyBit) &&
247 (pIconData->pmFileName) &&
248 (strlen(pIconData->pmFileName)) ) {
249 pFiletypedata->pszTinyPmIcon = XtMalloc(strlen(pIconData->pmFileName) + 1);
250 if (pFiletypedata->pszTinyPmIcon) {
251 strcpy(pFiletypedata->pszTinyPmIcon, pIconData->pmFileName);
254 pIconData->pmDirtyBit = False;
255 strcpy(pIconData->pmFileName, "");
257 /***************************************************************/
259 /***************************************************************/
260 if ( (pIconData->bmDirtyBit) &&
261 (pIconData->bmFileName) &&
262 (strlen(pIconData->bmFileName)) ) {
263 pFiletypedata->pszTinyBmIcon = XtMalloc(strlen(pIconData->bmFileName) + 1);
264 if (pFiletypedata->pszTinyBmIcon) {
265 strcpy(pFiletypedata->pszTinyBmIcon, pIconData->bmFileName);
268 pIconData->bmDirtyBit = False;
269 strcpy(pIconData->bmFileName, "");
277 AF_wids[0] = AF_MED_IconGadget;
278 AF_wids[1] = AF_TINY_IconGadget;
280 for (i=0; i < 2; i++) {
282 pIconData = GetIconDataFromWid(AF_wids[i]);
283 if ( (pIconData->pmDirtyBit) &&
284 (pIconData->pmFileName) &&
285 (strlen(pIconData->pmFileName)) ) {
286 pFiletypedata->pszMedPmIcon = XtMalloc(strlen(pIconData->pmFileName) + 1);
287 if (pFiletypedata->pszMedPmIcon) {
288 strcpy(pFiletypedata->pszMedPmIcon, pIconData->pmFileName);
291 pIconData->pmDirtyBit = False;
292 strcpy(pIconData->pmFileName, "");
295 if ( (pIconData->bmDirtyBit) &&
296 (pIconData->bmFileName) &&
297 (strlen(pIconData->bmFileName)) ) {
298 pFiletypedata->pszMedBmIcon = XtMalloc(strlen(pIconData->bmFileName) + 1);
299 if (pFiletypedata->pszMedBmIcon) {
300 strcpy(pFiletypedata->pszMedBmIcon, pIconData->bmFileName);
303 pIconData->bmDirtyBit = False;
304 strcpy(pIconData->bmFileName, "");
311 /******************************************************************************/
313 /* getAF_OpenCmd - retrieve the Open command string */
315 /* INPUT: FiletypeData *pFiletypedata - pointer to filetype data structure */
318 /******************************************************************************/
319 void getAF_OpenCmd (FiletypeData *pFiletypedata)
321 GetWidgetTextString(AF_OpenCmdText, &(pFiletypedata->pszOpenCmd));
325 /******************************************************************************/
327 /* getAF_PrintCmd - retrieve Print command string */
329 /* INPUT: FiletypeData *pFiletypedata - pointer to filetype data structure */
332 /******************************************************************************/
333 void getAF_PrintCmd (FiletypeData *pFiletypedata)
335 GetWidgetTextString(AF_FiletypePrintCmdTextField, &(pFiletypedata->pszPrintCmd));
339 /******************************************************************************/
341 /* init_AddFiletype_dialog_fields */
343 /* INPUT: FiletypeData * - pointer to FiletypeData structure */
346 /******************************************************************************/
347 void init_AddFiletype_dialog_fields(FiletypeData *pFtD)
349 char *pszIconFileName = (char *)NULL;
353 PutWidgetTextString(AF_FileTypeNameTextField, pFtD->pszName);
356 ParseAndUpdateID(pFtD);
359 PutWidgetTextString(AF_FiletypeHelpText, pFtD->pszHelp);
366 /*************************/
368 /*************************/
369 if (pFtD->pszMedPmIcon) {
370 SET_ICONGADGET_ICON(AF_MED_IconGadget, pFtD->pszMedPmIcon);
372 pszIconFileName = (char *)NULL;
373 FIND_ICONGADGET_ICON(pFtD->pszIcon, pszIconFileName, DtMEDIUM);
374 pszTmpFile = GetCorrectIconType(pszIconFileName);
375 SET_ICONGADGET_ICON(AF_MED_IconGadget, pszTmpFile);
376 if (pszIconFileName) XtFree(pszIconFileName);
377 if (pszTmpFile) XtFree(pszTmpFile);
380 /*************************/
382 /*************************/
383 if (pFtD->pszTinyPmIcon) {
384 SET_ICONGADGET_ICON(AF_TINY_IconGadget, pFtD->pszTinyPmIcon);
386 pszIconFileName = (char *)NULL;
387 FIND_ICONGADGET_ICON(pFtD->pszIcon, pszIconFileName, DtTINY);
388 pszTmpFile = GetCorrectIconType(pszIconFileName);
389 SET_ICONGADGET_ICON(AF_TINY_IconGadget, pszTmpFile);
390 if (pszIconFileName) XtFree(pszIconFileName);
391 if (pszTmpFile) XtFree(pszTmpFile);
394 /*************************/
396 /*************************/
397 if (pFtD->pszMedBmIcon) {
398 SET_ICONGADGET_ICON(AF_MED_IconGadget, pFtD->pszMedBmIcon);
400 pszIconFileName = (char *)NULL;
401 FIND_ICONGADGET_ICON(pFtD->pszIcon, pszIconFileName, DtMEDIUM);
402 pszTmpFile = GetCorrectIconType(pszIconFileName);
403 SET_ICONGADGET_ICON(AF_MED_IconGadget, pszTmpFile);
404 if (pszIconFileName) XtFree(pszIconFileName);
405 if (pszTmpFile) XtFree(pszTmpFile);
408 /*************************/
410 /*************************/
411 if (pFtD->pszTinyBmIcon) {
412 SET_ICONGADGET_ICON(AF_TINY_IconGadget, pFtD->pszTinyBmIcon);
414 pszIconFileName = (char *)NULL;
415 FIND_ICONGADGET_ICON(pFtD->pszIcon, pszIconFileName, DtTINY);
416 pszTmpFile = GetCorrectIconType(pszIconFileName);
417 SET_ICONGADGET_ICON(AF_TINY_IconGadget, pszTmpFile);
418 if (pszIconFileName) XtFree(pszIconFileName);
419 if (pszTmpFile) XtFree(pszTmpFile);
425 /*************************/
427 /*************************/
428 pszIconFileName = (char *)NULL;
429 if (pFtD->pszTinyPmIcon) {
430 pszTmpFile = pFtD->pszTinyPmIcon;
432 FIND_ICONGADGET_ICON(pFtD->pszIcon, pszIconFileName, DtTINY);
433 pszTmpFile = pszIconFileName;
435 SET_ICONGADGET_ICON(AF_TINY_IconGadget, pszTmpFile);
436 if (pszIconFileName) XtFree(pszIconFileName);
440 /*************************/
442 /*************************/
443 pszIconFileName = (char *)NULL;
444 if (pFtD->pszMedBmIcon) {
445 pszTmpFile = pFtD->pszMedBmIcon;
447 FIND_ICONGADGET_ICON(pFtD->pszIcon, pszIconFileName, DtMEDIUM);
448 pszTmpFile = pszIconFileName;
450 SET_ICONGADGET_ICON(AF_MED_IconGadget, pszTmpFile);
451 if (pszIconFileName) XtFree(pszIconFileName);
453 /*************************/
455 /*************************/
456 pszIconFileName = (char *)NULL;
457 if (pFtD->pszTinyBmIcon) {
458 pszTmpFile = pFtD->pszTinyBmIcon;
460 FIND_ICONGADGET_ICON(pFtD->pszIcon, pszIconFileName, DtTINY);
461 pszTmpFile = pszIconFileName;
463 SET_ICONGADGET_ICON(AF_TINY_IconGadget, pszTmpFile);
464 if (pszIconFileName) XtFree(pszIconFileName);
470 if (pFtD->pszOpenCmd) {
471 PutWidgetTextString(AF_OpenCmdText, pFtD->pszOpenCmd);
473 if (pFtD->pszPrintCmd) {
474 PutWidgetTextString(AF_FiletypePrintCmdTextField, pFtD->pszPrintCmd);
480 /******************************************************************************/
482 /* clear_AddFiletype_dialog_fields */
484 /* INPUT: FiletypeData * - pointer to FiletypeData structure */
487 /******************************************************************************/
488 void clear_AddFiletype_dialog_fields(void)
490 /*char pszFile[MAXBUFSIZE];*/
492 clear_text(AF_FileTypeNameTextField);
493 clear_text(AF_IdCharacteristicsText);
494 clear_text(AF_FiletypeHelpText);
495 createCB_IconGadget(AF_MED_IconGadget, FALSE, Medium_Icon);
496 createCB_IconGadget(AF_TINY_IconGadget, FALSE, Tiny_Icon);
498 SET_ICONGADGET_ICON_AND_EXT(AF_MED_IconGadget, af_med_icon_default, pszFile);
499 SET_ICONGADGET_ICON_AND_EXT(AF_TINY_IconGadget, af_tiny_icon_default, pszFile);
501 clear_text(AF_OpenCmdText);
502 clear_text(AF_FiletypePrintCmdTextField);
507 /******************************************************************************/
509 /* free_Filetypedata */
511 /* INPUT: FiletypeData * - pointer to FiletypeData structure */
514 /******************************************************************************/
515 void free_Filetypedata(FiletypeData *pFtD)
517 char buffer[MAXFILENAME];
520 printf("Free FiletypeData structure\n"); /* debug */
523 if (pFtD->pszName) XtFree(pFtD->pszName);
525 printf("Freed Name\n");
528 if (pFtD->pszIcon) XtFree(pFtD->pszIcon);
529 if (pFtD->pszMedPmIcon) {
531 printf("free_Filetypedata: unlink '%s'\n", pFtD->pszMedPmIcon); /* debug */
533 unlink(pFtD->pszMedPmIcon);
534 XtFree(pFtD->pszMedPmIcon);
536 if (pFtD->pszMedBmIcon) {
538 printf("free_Filetypedata: unlink '%s'\n", pFtD->pszMedBmIcon); /* debug */
540 unlink(pFtD->pszMedBmIcon);
541 /**** remove the mask if it exists ****/
542 sprintf(buffer, "%s_m", pFtD->pszMedBmIcon);
544 XtFree(pFtD->pszMedBmIcon);
546 if (pFtD->pszTinyPmIcon) {
548 printf("free_Filetypedata: unlink '%s'\n", pFtD->pszTinyPmIcon); /* debug */
550 unlink(pFtD->pszTinyPmIcon);
551 XtFree(pFtD->pszTinyPmIcon);
553 if (pFtD->pszTinyBmIcon) {
555 printf("free_Filetypedata: unlink '%s'\n", pFtD->pszTinyBmIcon); /* debug */
557 unlink(pFtD->pszTinyBmIcon);
558 /**** remove the mask if it exists ****/
559 sprintf(buffer, "%s_m", pFtD->pszTinyBmIcon);
561 XtFree(pFtD->pszTinyBmIcon);
564 if (pFtD->pszHelp) XtFree(pFtD->pszHelp);
565 if (pFtD->pszOpenCmd) XtFree(pFtD->pszOpenCmd);
566 if (pFtD->pszPrintCmd) XtFree(pFtD->pszPrintCmd);
567 if (pFtD->pszPattern) XtFree(pFtD->pszPattern);
568 if (pFtD->pszPermissions) XtFree(pFtD->pszPermissions);
569 if (pFtD->pszContents) XtFree(pFtD->pszContents);
570 XtFree((char *) pFtD);
574 /******************************************************************************/
576 /* AddFiletypeToList */
581 /******************************************************************************/
582 void AddFiletypeToList(void)
584 if (!XmListItemExists(CA_FiletypesList, XmStringCreateSimple(XmTextFieldGetString(AF_FileTypeNameTextField)))) {
585 XmListAddItem(CA_FiletypesList, XmStringCreateSimple(XmTextFieldGetString(AF_FileTypeNameTextField)), 0);
589 /******************************************************************************/
591 /* UpdateFiletypeDataArray */
596 /******************************************************************************/
597 void UpdateFiletypeDataArray(FiletypeData *pFtD)
599 FiletypeData **papArray;
602 /**************************************************************************/
603 /* Add this structure to the filetype array in the ActionData structure. */
604 /**************************************************************************/
605 papArray = (FiletypeData **) XtMalloc(sizeof(FiletypeData *) * (AD.cFiletypes + 1));
606 for (i=0; i < AD.cFiletypes; i++) {
607 papArray[i] = AD.papFiletypes[i];
609 papArray[AD.cFiletypes] = pFtD;
610 if (AD.papFiletypes) {
611 XtFree((char *) AD.papFiletypes);
613 AD.papFiletypes = papArray;
617 /******************************************************************************/
619 /* AddFiletypeCheckFields */
622 /* OUTPUT: FALSE - no errors found */
623 /* TRUE - found errors */
625 /******************************************************************************/
626 Boolean AddFiletypeCheckFields(void)
629 char *ptr = (char *)NULL;
630 Boolean bError = FALSE;
631 char *msgPtr, *errPtr;
633 /**************************************************************************/
634 /* Check if filetype name is present. */
635 /**************************************************************************/
638 GetWidgetTextString(AF_FileTypeNameTextField, &ptr);
640 printf("Filetype Family Name = '%s'\n", ptr);
643 msgPtr = GETMESSAGE(8, 10, "The Datatype Family Name is missing.\n\
644 Enter a name in the 'Name of Datatype Family' field.");
645 errPtr = XtNewString(msgPtr);
646 display_error_message(AddFiletype, errPtr);
648 XmProcessTraversal(AF_FileTypeNameTextField, XmTRAVERSE_CURRENT);
655 /**************************************************************************/
656 /* Check if identifying characteristics are present. */
657 /**************************************************************************/
660 GetWidgetTextString(AF_IdCharacteristicsText, &ptr);
662 printf("Identifying Chars = '%s'\n", ptr);
665 msgPtr = GETMESSAGE(8, 15,
666 "The Identifying Characteristics are missing.\n\
667 You must specify the characteristics before the datatype\n\
668 can be created. Select the Edit button next to the\n\
669 Identifying Characteristics list to specify the characteristics.");
670 errPtr = XtNewString(msgPtr);
671 display_error_message(AddFiletype, errPtr);
673 XmProcessTraversal(AF_IdCharacteristicsEdit, XmTRAVERSE_CURRENT);