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: main.c /main/11 1999/09/17 17:22:06 mgreess $ */
24 /*****************************************************************************/
28 /*****************************************************************************/
33 #include <sys/types.h>
36 #include <sys/param.h>
37 #include <X11/Intrinsic.h>
38 #include <X11/StringDefs.h>
41 #include <Xm/Protocols.h>
42 #include <Xm/VendorSEP.h>
43 #include <Xm/XmPrivate.h> /* XmeFlushIconFileCache */
44 #include <Dt/Action.h>
45 #include <Dt/GetDispRes.h>
47 #include <Dt/EnvControlP.h>
48 #include <Dt/UserMsg.h>
49 #include <Dt/Session.h>
52 #define GETXMSTRING(s, m, d) XmStringCreateLocalized(GETMESSAGE(s,m,d))
53 #define CLASS_NAME "Dtcreate"
55 /* Copied from Xm/BaseClassI.h */
56 extern XmWidgetExtData _XmGetWidgetExtData(
58 #if NeedWidePrototypes
59 unsigned int extType) ;
61 unsigned char extType) ;
62 #endif /* NeedWidePrototypes */
68 #include "ErrorDialog.h"
73 void DieFromToolTalkError(Widget, char*, Tt_status);
74 Tt_message ProcessToolTalkMessage( );
77 #if !defined(NL_CAT_LOCALE)
78 #define NL_CAT_LOCALE 0
82 /*----------------------------------------------------
83 * UxXt.h needs to be included only when compiling a
84 * stand-alone application.
85 *---------------------------------------------------*/
88 #endif /* DESIGN_TIME */
90 XtAppContext UxAppContext;
95 /*----------------------------------------------
96 * Insert application global declarations here
97 *---------------------------------------------*/
99 extern XtArgVal /* Dimension */ wintypeheight;
101 /* Structure used on a save session to see if a dt is iconic */
107 /*****************************************************************************/
109 /* Routine: GetSessionInfo */
111 /* Purpose: get session management saved information */
113 /*****************************************************************************/
114 void GetSessionInfo( void )
117 char *tmpStr, *tmpStr2;
120 XrmRepresentation rep_type;
128 stat_out("GetSessionInfo\n");
131 /*****************************************/
132 /*** Open the resource database file ***/
133 /*****************************************/
135 /************************************************************************/
136 /* UxTopLevel is used because CreateActionAppShell isn't created yet...*/
137 /* okay because it only uses it to get a display, not a window */
138 /************************************************************************/
139 if (DtSessionRestorePath(UxTopLevel, &path, sessiondata.pszSessionFile) == False)
140 path = sessiondata.pszSessionFile;
142 printf("session file = %s\n", path);
144 if ((db = XrmGetFileDatabase (path)) == NULL)
146 msgPtr = GETMESSAGE(5, 162, "Could not restore session from file:");
147 fmtPtr = "%s\n %s\n";
148 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
149 strlen(path) + 1) * sizeof(char));
150 sprintf(errPtr, fmtPtr, msgPtr, path);
151 display_error_message(UxTopLevel, errPtr);
153 if (path != sessiondata.pszSessionFile) {
156 sessiondata.useSession = False;
159 if (path != sessiondata.pszSessionFile) {
163 /*** now get the information we want from the database ***/
164 /*** make sure values are at least somewhat reasonable ***/
168 /*******************************/
170 /*******************************/
171 xrm_name[0] = XrmStringToQuark ("x");
172 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value))
173 sessiondata.x = (Position)atoi((char *)value.addr);
176 if (sessiondata.x < 0) sessiondata.x = 0;
178 /*******************************/
180 /*******************************/
181 xrm_name[0] = XrmStringToQuark ("y");
182 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value))
183 sessiondata.y = (Position)atoi((char *)value.addr);
186 if (sessiondata.y < 0) sessiondata.y = 0;
188 /*******************************/
190 /*******************************/
191 xrm_name[0] = XrmStringToQuark ("width");
192 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value))
193 sessiondata.width = (Dimension)atoi((char *)value.addr);
196 sessiondata.width = DEFAULT_WIDTH;
197 if (sessiondata.width < DEFAULT_WIDTH) sessiondata.width = DEFAULT_WIDTH;
200 /*******************************/
202 /*******************************/
203 xrm_name[0] = XrmStringToQuark ("height");
204 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value))
205 sessiondata.height = (Dimension)atoi((char *)value.addr);
208 sessiondata.height = DEFAULT_HEIGHT;
209 if (sessiondata.height < DEFAULT_HEIGHT) sessiondata.height = DEFAULT_HEIGHT;
212 /*******************************/
213 /* get iconic state */
214 /*******************************/
215 xrm_name[0] = XrmStringToQuark ("iconic");
216 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value))
218 if ( value.addr!=NULL && strcmp((char *)value.addr, "True")==0 )
219 sessiondata.iconicState = IconicState;
221 sessiondata.iconicState = NormalState;
224 /*******************************/
225 /* get expert status */
226 /*******************************/
227 xrm_name[0] = XrmStringToQuark ("expert");
228 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value))
230 sessiondata.showExpert = ((value.addr != NULL) &&
231 (strcmp((char *)value.addr, "True") == 0));
234 /*******************************/
235 /* get workspace # */
236 /*******************************/
237 xrm_name[0] = XrmStringToQuark ("workspace");
238 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value))
240 if ( value.addr!=NULL)
241 strcpy(sessiondata.workspaces, value.addr);
243 sessiondata.workspaces[0] = '\0';
246 /*******************************/
248 /*******************************/
249 xrm_name[0] = XrmStringToQuark ("file");
250 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)) {
252 printf("file to edit = '%s'\n", value.addr);
254 pszFileToEdit = (char *)XtMalloc(strlen(value.addr) + 1);
255 strcpy(pszFileToEdit, value.addr);
258 /*****************************************************************************/
260 /* Routine: SaveSession */
262 /* Purpose: save state information for session management */
264 /*****************************************************************************/
265 void SaveSession( void )
269 char *xa_CommandStr[3];
270 char *tmpStr, *tmpStr2;
272 Dimension width, height;
273 char *msgPtr, *fmtPtr, *errPtr;
274 XmVendorShellExtObject vendorExt;
275 XmWidgetExtData extData;
277 Atom wmStateAtom, actualType;
278 Atom *ws_presence = NULL;
280 unsigned long nitems, leftover, num_workspaces=0;
281 char all_workspace_names[256];
282 char *workspace_name;
283 Display *display = XtDisplay(CreateActionAppShell);
286 DtSessionSavePath(CreateActionAppShell, &path, &name);
288 printf("path = %s\n", path);
289 printf("name = %s\n", name);
292 /* Create the session file */
293 if (((fd = creat(path, S_IRUSR | S_IRGRP | S_IWUSR | S_IWGRP)) == -1) ||
294 ((fp = fdopen(fd, "w")) == (FILE *)NULL))
296 msgPtr = GETMESSAGE(5, 160, "Could not save session to file:");
297 fmtPtr = "%s\n %s\n";
298 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
299 strlen(path) + 1) * sizeof(char));
300 sprintf(errPtr, fmtPtr, msgPtr, path);
301 display_error_message(CreateActionAppShell, errPtr);
308 XtFree ((char *)path);
309 XtFree ((char *)name);
313 /* Getting the WM_STATE property to see if iconified or not */
315 printf("getting wm state\n");
317 wmStateAtom = XInternAtom(display, "WM_STATE", False);
320 printf("getting window property\n");
322 XGetWindowProperty (XtDisplay(CreateActionAppShell),
323 XtWindow(CreateActionAppShell), wmStateAtom, 0L,
324 (long)BUFSIZ, False, wmStateAtom, &actualType,
325 &actualFormat, &nitems, &leftover,
326 (unsigned char **) &wmState);
328 if (wmState->state == IconicState)
329 fprintf(fp, "*iconic: True\n");
331 fprintf(fp, "*iconic: False\n");
333 fprintf(fp, "*expert: %s\n",
334 XtIsManaged(XprtOptionForm) ? "True" : "False");
336 /*** Get and write out the geometry info for our Window ***/
339 printf("getting geometry info\n");
342 x = XtX(CreateActionAppShell);
343 y = XtY(CreateActionAppShell);
344 width = XtWidth(CreateActionAppShell);
345 height = XtHeight(CreateActionAppShell);
347 /* Modify x & y to take into account window mgr frames
348 * This is pretty bogus, but I don't know a better way to do it.
350 extData = _XmGetWidgetExtData(CreateActionAppShell, XmSHELL_EXTENSION);
351 vendorExt = (XmVendorShellExtObject)extData->widget;
352 x -= vendorExt->vendor.xOffset;
353 y -= vendorExt->vendor.yOffset;
355 fprintf(fp, "*x: %d\n", x);
356 fprintf(fp, "*y: %d\n", y);
357 fprintf(fp, "*width: %d\n", width);
358 fprintf(fp, "*height: %d\n", height);
361 printf("getting workspaces this window is present \n");
364 if (DtWsmGetWorkspacesOccupied (display,
365 XtWindow(CreateActionAppShell),
366 &ws_presence, &num_workspaces) == Success)
368 for (j = 0; j < num_workspaces; j++)
370 workspace_name = XGetAtomName (display, ws_presence[j]);
372 (void) strcpy(all_workspace_names, workspace_name);
375 (void) strcat(all_workspace_names, "*");
376 (void) strcat(all_workspace_names, workspace_name);
378 XFree ((char *) workspace_name);
380 XtFree((char *)ws_presence);
381 fprintf(fp, "*workspace: %s\n", all_workspace_names);
384 /* This will be used to indicate what file is currently being edited. */
385 if (pszFileToEdit != NULL) {
386 fprintf(fp, "*file: %s\n", pszFileToEdit);
393 xa_CommandStr[n] = pszExecName; n++;
394 xa_CommandStr[n] = "-s"; n++;
395 xa_CommandStr[n] = name; n++;
397 XSetCommand(XtDisplay(CreateActionAppShell), XtWindow(CreateActionAppShell), xa_CommandStr, n);
398 XtFree ((char *)path);
399 XtFree ((char *)name);
401 /* Don't exit yet, SM needs time to get the new commandStr.*/
404 /*****************************************************************************/
408 /* Session is ending, save session information */
410 /*****************************************************************************/
414 XtPointer clientData,
415 XtPointer callbackArg )
417 char *xa_CommandStr[3];
422 xa_CommandStr[i] = pszExecName; i++;
423 XSetCommand(XtDisplay(CreateActionAppShell), XtWindow(CreateActionAppShell), xa_CommandStr, i);
429 /*****************************************************************************/
431 /* GetIconDataFromWid */
434 /*****************************************************************************/
435 IconData *GetIconDataFromWid( Widget wid )
440 for (i=0; i < ICON_NUMBER; i++) {
441 if ((IconDataList[i]) && (IconDataList[i]->wid == wid)) {
442 return(IconDataList[i]);
445 return((IconData *)NULL);
448 /*****************************************************************************/
450 /* GetIconDataFromMsgID */
453 /*****************************************************************************/
454 IconData *GetIconDataFromMsgID( char *msgID )
459 for (i=0; i < ICON_NUMBER; i++) {
460 if (IconDataList[i]->pmMsgID) {
461 if (!strcmp(IconDataList[i]->pmMsgID, msgID)) {
462 return(IconDataList[i]);
465 if (IconDataList[i]->bmMsgID) {
466 if (!strcmp(IconDataList[i]->bmMsgID, msgID)) {
467 return(IconDataList[i]);
472 for (i=0; i < ICON_NUMBER; i++) {
473 if ( ((IconDataList[i]->pmMsgID) &&
474 (!strcmp(IconDataList[i]->pmMsgID, msgID))) ||
475 ((IconDataList[i]->bmMsgID) &&
476 (!strcmp(IconDataList[i]->bmMsgID, msgID))) ) {
477 return(IconDataList[i]);
481 return((IconData *)NULL);
484 /*****************************************************************************/
486 /* RemoveTmpIconFiles */
489 /*****************************************************************************/
490 void RemoveTmpIconFiles( void )
494 char maskFile[MAXFILENAME];
496 for (i=0; i < ICON_NUMBER; i++) {
497 if ( (IconDataList[i]->pmDirtyBit) &&
498 (IconDataList[i]->pmFileName) &&
499 (strlen(IconDataList[i]->pmFileName)) ) {
501 printf("RemoveTmpIconFiles: unlink '%s'\n", IconDataList[i]->pmFileName); /* debug */
503 unlink(IconDataList[i]->pmFileName);
504 /* This is bogus. But just in case the user specified a bitmap */
505 /* rather than a pixmap during the edit process, this will make */
506 /* sure that file gets removed. The chance of this occurring */
507 /* is very unlikely. */
508 strcpy(maskFile, IconDataList[i]->pmFileName);
509 strcat(maskFile, "_m");
512 printf("Remove maskFile = %s\n", maskFile); /* debug */
516 if ( (IconDataList[i]->bmDirtyBit) &&
517 (strlen(IconDataList[i]->bmFileName)) ) {
519 printf("RemoveTmpIconFiles: unlink '%s'\n", IconDataList[i]->bmFileName); /* debug */
521 unlink(IconDataList[i]->bmFileName);
522 strcpy(maskFile, IconDataList[i]->bmFileName);
523 strcat(maskFile, "_m");
525 printf("Remove maskFile = %s\n", maskFile); /* debug */
533 /*****************************************************************************/
535 /* DieFromToolTalkError */
538 /*****************************************************************************/
540 ExitCB (Widget dialog, XtPointer client_data, XtPointer call_data)
542 exit((int)(XtArgVal) client_data);
546 DieFromToolTalkError(Widget parent, char *errfmt, Tt_status status)
549 Widget dialog, dialogShell;
550 char *errmsg, *statmsg, *title;
551 XmString xms_errmsg, xms_ok, xms_title;
554 if (! tt_is_err(status)) return;
556 statmsg = tt_status_message(status);
557 /* Solaris dtcreate ignores this so we should too */
558 if(status == TT_ERR_PTYPE)
560 errmsg = XtMalloc(strlen(errfmt) + strlen(statmsg) + 2);
561 sprintf(errmsg, errfmt, statmsg);
563 xms_ok = GETXMSTRING(13, 3, "OK");
564 xms_errmsg = XmStringCreateLocalized(errmsg);
565 xms_title = GETXMSTRING(13, 1, "Create Action - Error");
568 XtSetArg(args[n], XmNautoUnmanage, False); n++;
569 XtSetArg(args[n], XmNokLabelString, xms_ok); n++;
570 XtSetArg(args[n], XmNdialogTitle, xms_title); n++;
571 XtSetArg(args[n], XmNmessageString, xms_errmsg); n++;
572 XtSetArg(args[n], XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL); n++;
574 dialog = XmCreateErrorDialog(parent, "IconEditorError", args, n);
575 XtAddCallback(dialog, XmNokCallback, ExitCB, (XtPointer) status);
576 XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_CANCEL_BUTTON));
577 XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_HELP_BUTTON));
580 * Disable the frame menu from dialog since we don't want the user
581 * to be able to close dialogs with the frame menu
583 dialogShell = XtParent(dialog);
585 XtSetArg(args[n], XmNmwmDecorations, MWM_DECOR_ALL | MWM_DECOR_MENU); n++;
586 XtSetValues(dialogShell, args, n);
587 XtManageChild(dialog);
588 XtRealizeWidget(dialogShell);
590 _DtSimpleError(CLASS_NAME, DtFatalError, NULL, errmsg);
593 XmStringFree(xms_ok);
594 XmStringFree(xms_errmsg);
595 XmStringFree(xms_title);
598 XtAppProcessEvent(XtWidgetToApplicationContext(dialog), XtIMAll);
601 /*****************************************************************************/
603 /* ProcessToolTalkMessage */
606 /*****************************************************************************/
607 Tt_message ProcessToolTalkMessage(Tt_message msg,
609 Tt_message contract )
612 int ttMark = tt_mark();
614 if( 0 == strcmp( tt_message_op( msg ), "Quit" ) ) {
616 * Do the necessary cleanup, call tt_message_reply(),
617 * and exit. Since this is not yet fully implemented, just
618 * call tt_message_reply and exit.
622 printf("ProcessTTMsg: Quit\n"); /* debug */
624 tt_message_reply(msg);
625 RemoveTmpIconFiles();
629 * Any other desktop message ops that one would want
630 * to implement would go here. If
631 * a mapped, realized, top-level widget were passed into
632 * ttdt_session_join instead of (Widget) 0, then the
633 * messages that interact with the X environment
634 * Get_Geometry, etc.) would be handled automatically.
638 printf("ProcessTTMsg: Other\n");
642 tt_release( ttMark );
644 return (Tt_message) 0;
647 /*****************************************************************************/
648 /* NAME: IconEdit_tt_handler */
649 /* DESCRIPTION: Handler for Tooltalk conversation about editing icon. */
652 /* CREATION: 02/21/94 */
654 /*****************************************************************************/
655 Tt_callback_action IconEdit_tt_handler( Tt_message m, Tt_pattern p )
662 char *msgPtr, *fmtPtr, *errPtr;
663 char tmpbuf[MAXBUFSIZE];
669 Boolean bIsNewFile = False;
671 char *tmp = (char *)NULL;
672 char *tmp1 = (char *)NULL;
677 op = tt_message_op(m);
678 /************************************************************************/
679 /* Edit message... */
680 /************************************************************************/
681 if (!strcmp(op, "Edit")) {
683 printf("IconEdit_tt_handler: Edit tt msg = %p\n", m); /* debug */
685 mstate = tt_message_state( m );
686 switch ((int)mstate) {
688 TurnOffHourGlassAllWindows();
690 /* INTERNATIONALIZE */
691 msgPtr = "Failed ToolTalk msg";
693 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
695 sprintf(errPtr, fmtPtr, msgPtr, m);
696 display_error_message(CreateActionAppShell, errPtr);
699 printf( "Failed ToolTalk msg = %p\n", m); /* debug */
701 tt_message_destroy( m );
704 TurnOffHourGlassAllWindows();
706 printf( "Handled ToolTalk msg = %p\n", m); /* debug */
708 tt_message_destroy( m );
712 printf( "Started ToolTalk msg = %p\n", m); /* debug */
717 printf("IconEdit_tt_handler: Saved tt msg = %p\n", m); /* debug */
719 msgID = tt_message_arg_val(m, 1);
720 pIconData = GetIconDataFromMsgID(msgID);
722 printf("msgID = '%s'\n", msgID); /* debug */
725 /*********************************************************************/
726 /* Saved message... */
727 /*********************************************************************/
728 if ( (pIconData) && (!strcmp(op, "Saved")) ) {
729 tt_message_arg_bval(m, 0, (unsigned char **)&ttbuf, &blen);
731 if ( (pIconData->pmMsgID) && (!strcmp(pIconData->pmMsgID, msgID)) ) {
732 if (pIconData->pmDirtyBit) {
733 tmpIconFile = pIconData->pmFileName;
735 tmpnam(pIconData->pmFileName);
737 tmpIconFile = pIconData->pmFileName;
740 if (pIconData->bmDirtyBit) {
741 tmpIconFile = pIconData->bmFileName;
743 tmpnam(pIconData->bmFileName);
745 tmpIconFile = pIconData->bmFileName;
749 tmpfd = open(tmpIconFile, O_CREAT | O_WRONLY | O_NDELAY, 0666);
751 tmpfd = open(tmpIconFile, O_TRUNC | O_WRONLY | O_NDELAY, 0666);
754 msgPtr = GETMESSAGE(5, 60, "Could not open the following file:");
756 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
757 strlen(tmpIconFile) + 1) * sizeof(char));
758 sprintf(errPtr, fmtPtr, msgPtr, tmpIconFile);
759 display_error_message(XtParent(pIconData->wid), errPtr);
761 tt_release( ttMark );
762 return (TT_CALLBACK_CONTINUE);
765 /*******************************************************************/
766 /* Determine if this is a pixmap or bitmap. If it is a pixmap, */
767 /* handle as a one file buffer. If a bitmap, then it may be */
768 /* double buffered including the mask. */
769 /*******************************************************************/
771 /*******************************************************************/
772 /* Check for Pixmap first. */
773 /*******************************************************************/
774 if ( (ttbuf) && (!strncmp(ttbuf, "/* XPM */", 9)) ) {
776 printf("This is a XPM file\n"); /* debug */
778 tmp = strstr(ttbuf, "};");
780 tmp += 2; /* Go one char past the ";" */
782 tmplen = blen - strlen(tmp) + 1;
783 printf("Amro tmplen = %d\n", tmplen);
785 tmplen = (char *)tmp - (char *)ttbuf;
787 printf("Troy tmplen = %d\n", tmplen); /* debug */
792 if ((wlen = write(tmpfd, ttbuf, tmplen)) == tmplen) {
793 if (tmpfd > -1) close(tmpfd);
795 /* INTERNATIONALIZE */
796 msgPtr = "Could not write to the following file:";
798 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
799 strlen(tmpIconFile) + 1) * sizeof(char));
800 sprintf(errPtr, fmtPtr, msgPtr, tmpIconFile);
801 display_error_message(XtParent(pIconData->wid), errPtr);
803 tt_release( ttMark );
804 if (tmpfd > -1) close(tmpfd);
805 return (TT_CALLBACK_CONTINUE);
808 /*******************************************************************/
809 /* Must be a Bitmap. */
810 /*******************************************************************/
813 printf("This is a XBM file\n"); /* debug */
814 printf("ttbuffer size = %d\n", blen); /* debug */
816 /****************************************************************/
817 /* Determine size of first bitmap. */
818 /****************************************************************/
819 tmp = strstr(ttbuf, "};");
821 tmp += 2; /* Go one char past the ";" */
823 tmplen = blen - strlen(tmp) + 1;
824 printf("Amro tmplen = %d\n", tmplen);
826 tmplen = (char *)tmp - (char *)ttbuf;
828 printf("Troy tmplen = %d\n", tmplen); /* debug */
834 printf("File 1 size = %d\n", tmplen); /* debug */
837 /****************************************************************/
838 /* Write out first bitmap file. */
839 /****************************************************************/
841 printf("Writing first bitmap file\n"); /* debug */
843 if ((wlen = write(tmpfd, ttbuf, tmplen)) == tmplen) {
844 if (tmpfd > -1) close(tmpfd);
846 /* INTERNATIONALIZE */
847 msgPtr = "Could not write to the following file:";
849 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
850 strlen(tmpIconFile) + 1) * sizeof(char));
851 sprintf(errPtr, fmtPtr, msgPtr, tmpIconFile);
852 display_error_message(XtParent(pIconData->wid), errPtr);
854 tt_release( ttMark );
855 if (tmpfd > -1) close(tmpfd);
856 return (TT_CALLBACK_CONTINUE);
859 /****************************************************************/
860 /* Now determine if there is a second bitmap and its size. */
861 /****************************************************************/
863 tmp1 = strstr(tmp, "};");
865 snprintf(tmpbuf, sizeof(tmpbuf), "%s_m", tmpIconFile);
867 tmp1 += 2; /* Go one char past the ";" */
869 printf("Mask file name = '%s'\n", tmpbuf); /* debug */
871 tmpfd = open(tmpbuf, O_CREAT | O_WRONLY | O_NDELAY, 0666);
874 GETMESSAGE(5, 60, "Could not open the following file:");
876 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
877 strlen(tmpbuf) + 1) * sizeof(char));
878 sprintf(errPtr, fmtPtr, msgPtr, tmpbuf);
879 display_error_message(XtParent(pIconData->wid), errPtr);
881 tt_release( ttMark );
882 return (TT_CALLBACK_CONTINUE);
886 printf("writing mask file \n");
889 tmplen = strlen(tmp);
890 printf("Amro tmplen = %d\n", tmplen);
892 tmplen = (char *)tmp1 - (char *)tmp;
894 printf("Troy tmplen = %d\n", tmplen); /* debug */
896 if ((wlen = write(tmpfd, tmp, tmplen)) == tmplen) {
897 if (tmpfd > -1) close(tmpfd);
899 /* INTERNATIONALIZE */
900 msgPtr = "Could not write to the following file:";
902 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
903 strlen(tmpbuf) + 1) * sizeof(char));
904 sprintf(errPtr, fmtPtr, msgPtr, tmpbuf);
905 display_error_message(XtParent(pIconData->wid), errPtr);
907 tt_release( ttMark );
908 if (tmpfd > -1) close(tmpfd);
909 return (TT_CALLBACK_CONTINUE);
912 /****************************************************************/
913 /* Must not have a mask, so lets clean up any old mask file. */
914 /****************************************************************/
917 printf("Remove maskFile = %s\n", tmpbuf); /* debug */
923 /****************************************************************/
924 /* Set the icon gadget with new icon, and flag the dirty bit. */
925 /****************************************************************/
926 if ( ( (pIconData->pmMsgID) &&
927 (!strcmp(pIconData->pmMsgID, msgID)) &&
930 ( (pIconData->bmMsgID) &&
931 (!strcmp(pIconData->bmMsgID, msgID)) &&
932 (!bShowPixmaps) ) ) {
933 XmeFlushIconFileCache(NULL);
935 printf("Change icon image for widget = %p\n", pIconData->wid); /* debug */
937 SET_ICONGADGET_ICON(pIconData->wid, tmpIconFile);
939 if ((pIconData->pmMsgID) && (!strcmp(pIconData->pmMsgID, msgID))) {
940 pIconData->pmDirtyBit = True;
942 pIconData->bmDirtyBit = True;
945 printf("**********tmp file name = %s\n", tmpIconFile); /* debug */
949 tt_release( ttMark );
950 return( TT_CALLBACK_PROCESSED );
953 /*****************************************************************************/
954 /* NAME: UxDoEditPixmap */
955 /* DESCRIPTION: Loads the icon editor. */
956 /* PARAMETERS: none */
958 /* CREATION: 02/11/94 */
960 /*****************************************************************************/
961 void UxDoEditPixmap(Widget wid, char *fname)
963 Tt_message m; /* ToolTalk message */
964 Tt_pattern p; /* ToolTalk dynamic pattern */
965 Tt_status ttRc; /* ToolTalk status */
970 int lenFile1 = 0, rlenFile1 = 0;
971 int lenFile2 = 0, rlenFile2 = 0;
977 unsigned char *buffer;
980 char tmpbuf[MAXBUFSIZE];
984 char *mname = (char *)NULL;
985 char *type_name, *size_name;
989 if (fname) printf("Edit filename: '%s'\n", fname); /* debug */
994 /*********************************************************************/
996 /*********************************************************************/
997 m = tt_prequest_create( TT_SESSION, "Edit" );
998 msgID = tt_message_id(m);
999 pIconData = GetIconDataFromWid(wid);
1001 ppMsgID = &(pIconData->pmMsgID);
1003 ppMsgID = &(pIconData->bmMsgID);
1008 if (msgID && strlen(msgID)) {
1009 *ppMsgID = (char *)malloc(strlen(msgID) + 1);
1010 strcpy(*ppMsgID, msgID);
1014 printf("msgID = '%s'\n", msgID); /* debug */
1015 printf("Create Edit msg = %p\n", m); /* debug */
1018 /*********************************************************************/
1019 /* Add arguments to message */
1020 /*********************************************************************/
1022 fd1 = open(fname, O_RDONLY);
1024 /* Error opening icon file! */
1025 msgPtr = GETMESSAGE(5, 60, "Could not open the following file:");
1027 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
1028 strlen(fname) + 1) * sizeof(char));
1029 sprintf(errPtr, fmtPtr, msgPtr, fname);
1030 display_error_message(XtParent(wid), errPtr);
1034 /***************************************/
1035 /* Find out how big a buffer is needed */
1036 /***************************************/
1037 lenFile1 = lseek(fd1, 0, SEEK_END);
1038 (void) lseek(fd1, 0, SEEK_SET);
1040 /*************************************************************/
1041 /* Read first few bytes to determine what kind of file it is */
1042 /*************************************************************/
1043 read(fd1, tmpbuf, 10);
1044 (void) lseek(fd1, 0, SEEK_SET);
1046 /******************************************************************/
1047 /* If the file is a bitmap, then check for its mask file and add. */
1048 /******************************************************************/
1049 if ( strncmp(tmpbuf, "/* XPM */", 9) ) {
1051 mname = CreateMaskName(fname);
1053 /***************************************************************/
1054 /* Check if mask file exists. */
1055 /***************************************************************/
1056 if ((mname) && (check_file_exists(mname))) {
1057 fd2 = open(mname, O_RDONLY);
1059 /* Error opening icon file! */
1061 GETMESSAGE(5, 60, "Could not open the following file:");
1063 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
1064 strlen(mname) + 1) * sizeof(char));
1065 sprintf(errPtr, fmtPtr, msgPtr, mname);
1066 display_error_message(XtParent(wid), errPtr);
1069 if (fd1 > -1) close(fd1);
1072 /***************************************/
1073 /* Find out how big a buffer is needed */
1074 /***************************************/
1075 lenFile2 = lseek(fd2, 0, SEEK_END);
1076 (void) lseek(fd2, 0, SEEK_SET);
1080 /******************************************************************/
1081 /* Create 1 big buffer */
1082 /******************************************************************/
1084 printf("Size of file 1 = %d\n", lenFile1); /* debug */
1085 printf("Size of file 2 = %d\n", lenFile2); /* debug */
1087 buffer = (unsigned char *)XtMalloc((Cardinal)(lenFile1 + lenFile2 + 1));
1088 memset(buffer, 0, (lenFile1 + lenFile2 + 1));
1090 /***************************************/
1091 /* Read file1 into buffer. */
1092 /***************************************/
1093 if ((rlenFile1 = read(fd1, buffer, lenFile1)) != lenFile1) {
1094 /* didn't read whole file! */
1096 /* INTERNATIONALIZE */
1097 msgPtr = "Could not read the entire file:";
1099 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
1100 strlen(fname) + 1) * sizeof(char));
1101 sprintf(errPtr, fmtPtr, msgPtr, fname);
1102 display_error_message(XtParent(wid), errPtr);
1104 if (mname) XtFree(mname);
1105 XtFree((char *) buffer);
1106 if (fd1 > -1) close(fd1);
1107 if (fd2 > -1) close(fd2);
1112 printf("buffer = %p\n", buffer);
1114 /*ptr = (char *)&(buffer[lenFile1 + 1]);*/
1115 ptr = (char *)&(buffer[lenFile1]);
1117 printf("ptr = %p\n", ptr);
1119 if ((rlenFile2 = read(fd2, ptr, lenFile2)) != lenFile2) {
1120 /* didn't read whole file! */
1122 /* INTERNATIONALIZE */
1123 msgPtr = "Could not read the entire file:";
1125 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
1126 strlen(fname) + 1) * sizeof(char));
1127 sprintf(errPtr, fmtPtr, msgPtr, mname);
1128 display_error_message(XtParent(wid), errPtr);
1130 XtFree((char *) buffer);
1131 if (mname) XtFree(mname);
1132 if (fd1 > -1) close(fd1);
1133 if (fd2 > -1) close(fd2);
1137 if (fd1 > -1) close(fd1); fd1 = -1;
1138 if (fd2 > -1) close(fd2); fd2 = -1;
1141 printf("final buffer = '%s'\n", buffer); /* debug */
1142 printf("Buffer = '%s'\n", buffer); /* debug */
1144 tt_message_barg_add( m, TT_INOUT, "XPM", buffer, lenFile1 + lenFile2 + 1);
1145 if (mname) XtFree(mname);
1146 XtFree((char *) buffer);
1150 tt_message_barg_add( m, TT_INOUT, "XPM", (const unsigned char *)NULL, 0);
1152 tt_message_arg_add(m, TT_IN, "messageID", msgID);
1154 /******************************************************************/
1155 /* Create a pattern and add a callback to get notifications */
1156 /* of periodic saves */
1157 /******************************************************************/
1158 p = tt_pattern_create();
1159 tt_pattern_category_set(p, TT_OBSERVE);
1160 tt_pattern_scope_add(p, TT_SESSION);
1161 tt_pattern_session_add(p, tt_default_session());
1162 tt_pattern_address_add(p, TT_HANDLER);
1163 tt_pattern_op_add(p, "Saved");
1164 tt_pattern_callback_add(p, IconEdit_tt_handler);
1165 tt_pattern_register(p);
1167 /******************************************************************/
1168 /* Add callback to notify when change complete */
1169 /******************************************************************/
1170 tt_message_callback_add( m, IconEdit_tt_handler );
1172 /******************************************************************/
1174 /******************************************************************/
1175 TurnOnHourGlassAllWindows();
1176 ttRc = tt_message_send( m );
1177 DieFromToolTalkError( UxTopLevel, "tt_message_send", ttRc );
1179 if (fd1 > -1) close(fd1);
1180 if (fd2 > -1) close(fd2);
1182 #endif /* __TOOLTALK */
1184 /*****************************************************************************/
1191 /*****************************************************************************/
1193 main(int argc, char *argv[])
1195 /*-----------------------------------------------------------
1197 * The default identifier - mainIface will only be declared
1198 * if the interface function is global and of type swidget.
1199 * To change the identifier to a different name, modify the
1200 * string mainIface in the file "xtmain.dat". If "mainIface"
1201 * is declared, it will be used below where the return value
1202 * of PJ_INTERFACE_FUNCTION_CALL will be assigned to it.
1203 *----------------------------------------------------------*/
1210 char * sessionString;
1215 extern swidget create_AddFiletype();
1216 extern swidget create_FileCharacteristics();
1217 extern swidget create_OpenFile();
1218 extern swidget create_Confirmed();
1219 extern Widget create_ErrorDialog();
1221 Atom xa_WM_SAVE_YOURSELF;
1224 /*---------------------------------
1225 * Interface function declaration
1226 *--------------------------------*/
1227 Widget create_applicationShell1(swidget);
1228 swidget UxParent = NULL;
1231 /*---------------------
1232 * Initialize program
1233 *--------------------*/
1235 _DtEnvControl(DT_ENV_SET);
1236 XtSetLanguageProc(NULL, NULL, NULL);
1237 pszFileToEdit = (char *)NULL;
1238 memset(&sessiondata, 0, sizeof(SessionData));
1239 memset(IconDataList, 0, sizeof(IconDataList));
1241 /********************************************************************/
1242 /* Parse the command line arguments. */
1243 /********************************************************************/
1244 pszExecName = argv[0];
1247 for (i=1; i<argc; i++) {
1248 if ((argv[i][0] == '-') && (argv[i][1] == '?')) {
1249 setlocale(LC_ALL, "");
1250 nlmsg_fd = catopen("dtcreate", NL_CAT_LOCALE);
1252 GETMESSAGE(5, 110, "Usage: dtcreate [<filename>] [-?]"));
1255 if (argv[i][0] == '-') {
1256 if (!strcmp(argv[i], "-s")) {
1258 sessiondata.pszSessionFile = (char *)XtMalloc(strlen(argv[i]) + 1);
1259 strcpy(sessiondata.pszSessionFile, argv[i]);
1260 sessiondata.useSession = True;
1265 pszFileToEdit = (char *)XtMalloc(strlen(argv[i]) + 1);
1266 strcpy(pszFileToEdit, argv[i]);
1273 UxTopLevel = XtAppInitialize(&UxAppContext, CLASS_NAME,
1274 NULL, 0, &argc, argv, NULL, NULL, 0);
1276 nlmsg_fd = catopen("dtcreate", NL_CAT_LOCALE);
1278 UxDisplay = XtDisplay(UxTopLevel);
1279 UxScreen = XDefaultScreen(UxDisplay);
1281 if (sessiondata.useSession) {
1285 /*---------------------
1286 * Determine resolution
1287 *--------------------*/
1288 if (_DtGetDisplayResolution(UxDisplay, UxScreen) == 1) {
1298 /*-------------------------------------------------------
1299 * Insert initialization code for your application here
1300 *------------------------------------------------------*/
1303 printf("display string = '%s'\n", DisplayString(UxDisplay));
1305 ttsession = getenv("TT_SESSION");
1306 if (!ttsession || strlen(ttsession)==0) {
1307 char *ttxsession = tt_X_session(XDisplayString(UxDisplay));
1308 ttRc = tt_default_session_set(ttxsession);
1311 ttMark = tt_mark( );
1313 procId = tt_open( );
1314 ttRc = tt_ptr_error(procId);
1316 GETMESSAGE(13, 2, "Could not connect to ToolTalk:\n%s\nExiting ...");
1317 DieFromToolTalkError( UxTopLevel, errfmt, ttRc );
1320 DieFromToolTalkError( UxTopLevel, "tt_fd", tt_int_error( ttFd ) );
1322 ttRc = tt_ptype_declare( "dtcreate" );
1323 DieFromToolTalkError( UxTopLevel, "tt_ptype_declare", ttRc );
1325 ttRc = tt_session_join( tt_default_session( ));
1326 DieFromToolTalkError( UxTopLevel, "tt_session_join", ttRc );
1328 XtAppAddInput( UxAppContext, ttFd, (XtPointer)XtInputReadMask,
1329 (XtInputCallbackProc)ProcessToolTalkMessage, 0 );
1332 if (!pszFileToEdit) {
1337 /*----------------------------------------------------------------
1338 * Create and popup the first window of the interface. The
1339 * return value can be used in the popdown or destroy functions.
1340 * The Widget return value of PJ_INTERFACE_FUNCTION_CALL will
1341 * be assigned to "mainIface" from PJ_INTERFACE_RETVAL_TYPE.
1342 *---------------------------------------------------------------*/
1344 mainIface = create_applicationShell1(UxParent);
1345 AddFiletype = create_AddFiletype(mainIface);
1346 FileCharacteristics = create_FileCharacteristics(AddFiletype);
1347 OpenFile = create_OpenFile();
1349 UxPopupInterface(mainIface, no_grab);
1350 if (pszFileToEdit) {
1351 if (!OpenDefinitionFile(pszFileToEdit, &AD)) {
1355 XtVaGetValues (CA_WindowTypeArea, XmNheight, &wintypeheight, NULL);
1357 /*------------------------------------------------------------------*/
1358 /* Register for save and restore. */
1359 /*------------------------------------------------------------------*/
1360 xa_WM_SAVE_YOURSELF = XInternAtom(XtDisplay(CreateActionAppShell), "WM_SAVE_YOURSELF", False);
1361 XmAddWMProtocols(CreateActionAppShell, &xa_WM_SAVE_YOURSELF, 1);
1362 XmAddWMProtocolCallback(CreateActionAppShell, xa_WM_SAVE_YOURSELF,
1363 SaveSessionCB, (XtPointer)CreateActionAppShell);
1365 /*------------------------------------------------------------------*/
1366 /* Make a copy of the AD data structure. This will be used later */
1367 /* when the user wants to exit to determine if the latest data has */
1368 /* been saved or not. */
1369 /*------------------------------------------------------------------*/
1370 pMyCopyAD = copyAD(&AD);
1374 ttMark = tt_mark( );
1376 procId = ttdt_open( &ttFd, "dtcreate", "CDE", "1.0", 1 );
1377 ttRc = tt_ptr_error(procId);
1379 GETMESSAGE(13, 2, "Could not connect to ToolTalk:\n%s\nExiting ...");
1380 DieFromToolTalkError( UxTopLevel, errfmt, ttRc );
1383 ttRc = tt_int_error( ttFd );
1384 DieFromToolTalkError( UxTopLevel, "tt_fd", ttRc );
1386 sessionString = tt_default_session();
1387 ttRc = tt_ptr_error( sessionString );
1388 DieFromToolTalkError( UxTopLevel, "tt_default_session", ttRc );
1390 ttPatt = ttdt_session_join( sessionString, ProcessToolTalkMessage,
1391 (Widget) 0, (void *) 0, 1 );
1392 ttRc = tt_ptr_error(ttPatt);
1393 DieFromToolTalkError( UxTopLevel, "ttdt_session_join", ttRc );
1395 XtAppAddInput( UxAppContext, ttFd, (XtPointer)XtInputReadMask,
1396 tttk_Xt_input_handler, 0 );
1399 /*-----------------------
1400 * Enter the event loop
1401 *----------------------*/
1403 XtAppMainLoop (UxAppContext);
1406 ttdt_session_quit(0, 0, 1);
1408 tt_release( ttMark );
1409 RemoveTmpIconFiles();