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: 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>
44 #include <Dt/EnvControlP.h>
45 #include <Dt/UserMsg.h>
47 #define GETXMSTRING(s, m, d) XmStringCreateLocalized(GETMESSAGE(s,m,d))
48 #define CLASS_NAME "Dtcreate"
50 /* Copied from Xm/BaseClassI.h */
51 extern XmWidgetExtData _XmGetWidgetExtData(
53 #if NeedWidePrototypes
54 unsigned int extType) ;
56 unsigned char extType) ;
57 #endif /* NeedWidePrototypes */
66 void DieFromToolTalkError(Widget, char*, Tt_status);
67 Tt_message ProcessToolTalkMessage( );
70 #if !defined(NL_CAT_LOCALE)
71 #define NL_CAT_LOCALE 0
75 /*----------------------------------------------------
76 * UxXt.h needs to be included only when compiling a
77 * stand-alone application.
78 *---------------------------------------------------*/
81 #endif /* DESIGN_TIME */
83 XtAppContext UxAppContext;
88 /*----------------------------------------------
89 * Insert application global declarations here
90 *---------------------------------------------*/
92 extern Dimension wintypeheight;
94 /* Structure used on a save session to see if a dt is iconic */
100 /*****************************************************************************/
102 /* Routine: GetSessionInfo */
104 /* Purpose: get session management saved information */
106 /*****************************************************************************/
107 void GetSessionInfo( void )
110 char *tmpStr, *tmpStr2;
113 XrmRepresentation rep_type;
121 stat_out("GetSessionInfo\n");
124 /*****************************************/
125 /*** Open the resource database file ***/
126 /*****************************************/
128 /************************************************************************/
129 /* UxTopLevel is used because CreateActionAppShell isn't created yet...*/
130 /* okay because it only uses it to get a display, not a window */
131 /************************************************************************/
132 if (DtSessionRestorePath(UxTopLevel, &path, sessiondata.pszSessionFile) == False)
133 path = sessiondata.pszSessionFile;
135 printf("session file = %s\n", path);
137 if ((db = XrmGetFileDatabase (path)) == NULL)
139 msgPtr = GETMESSAGE(5, 162, "Could not restore session from file:");
140 fmtPtr = "%s\n %s\n";
141 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
142 strlen(path) + 1) * sizeof(char));
143 sprintf(errPtr, fmtPtr, msgPtr, path);
144 display_error_message(UxTopLevel, errPtr);
146 if (path != sessiondata.pszSessionFile) {
149 sessiondata.useSession = False;
152 if (path != sessiondata.pszSessionFile) {
156 /*** now get the information we want from the database ***/
157 /*** make sure values are at least somewhat reasonable ***/
161 /*******************************/
163 /*******************************/
164 xrm_name[0] = XrmStringToQuark ("x");
165 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value))
166 sessiondata.x = (Position)atoi((char *)value.addr);
169 if (sessiondata.x < 0) sessiondata.x = 0;
171 /*******************************/
173 /*******************************/
174 xrm_name[0] = XrmStringToQuark ("y");
175 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value))
176 sessiondata.y = (Position)atoi((char *)value.addr);
179 if (sessiondata.y < 0) sessiondata.y = 0;
181 /*******************************/
183 /*******************************/
184 xrm_name[0] = XrmStringToQuark ("width");
185 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value))
186 sessiondata.width = (Dimension)atoi((char *)value.addr);
189 sessiondata.width = DEFAULT_WIDTH;
190 if (sessiondata.width < DEFAULT_WIDTH) sessiondata.width = DEFAULT_WIDTH;
193 /*******************************/
195 /*******************************/
196 xrm_name[0] = XrmStringToQuark ("height");
197 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value))
198 sessiondata.height = (Dimension)atoi((char *)value.addr);
201 sessiondata.height = DEFAULT_HEIGHT;
202 if (sessiondata.height < DEFAULT_HEIGHT) sessiondata.height = DEFAULT_HEIGHT;
205 /*******************************/
206 /* get iconic state */
207 /*******************************/
208 xrm_name[0] = XrmStringToQuark ("iconic");
209 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value))
211 if ( value.addr!=NULL && strcmp((char *)value.addr, "True")==0 )
212 sessiondata.iconicState = IconicState;
214 sessiondata.iconicState = NormalState;
217 /*******************************/
218 /* get expert status */
219 /*******************************/
220 xrm_name[0] = XrmStringToQuark ("expert");
221 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value))
223 sessiondata.showExpert = ((value.addr != NULL) &&
224 (strcmp((char *)value.addr, "True") == 0));
227 /*******************************/
228 /* get workspace # */
229 /*******************************/
230 xrm_name[0] = XrmStringToQuark ("workspace");
231 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value))
233 if ( value.addr!=NULL)
234 strcpy(sessiondata.workspaces, value.addr);
236 sessiondata.workspaces[0] = '\0';
239 /*******************************/
241 /*******************************/
242 xrm_name[0] = XrmStringToQuark ("file");
243 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)) {
245 printf("file to edit = '%s'\n", value.addr);
247 pszFileToEdit = (char *)XtMalloc(strlen(value.addr) + 1);
248 strcpy(pszFileToEdit, value.addr);
251 /*****************************************************************************/
253 /* Routine: SaveSession */
255 /* Purpose: save state information for session management */
257 /*****************************************************************************/
258 void SaveSession( void )
262 char *xa_CommandStr[3];
263 char *tmpStr, *tmpStr2;
265 Dimension width, height;
266 char *msgPtr, *fmtPtr, *errPtr;
267 XmVendorShellExtObject vendorExt;
268 XmWidgetExtData extData;
270 Atom wmStateAtom, actualType;
271 Atom *ws_presence = NULL;
273 unsigned long nitems, leftover, num_workspaces=0;
274 char all_workspace_names[256];
275 char *workspace_name;
276 Display *display = XtDisplay(CreateActionAppShell);
279 DtSessionSavePath(CreateActionAppShell, &path, &name);
281 printf("path = %s\n", path);
282 printf("name = %s\n", name);
285 /* Create the session file */
286 if (((fd = creat(path, S_IRUSR | S_IRGRP | S_IWUSR | S_IWGRP)) == -1) ||
287 ((fp = fdopen(fd, "w")) == (FILE *)NULL))
289 msgPtr = GETMESSAGE(5, 160, "Could not save session to file:");
290 fmtPtr = "%s\n %s\n";
291 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
292 strlen(path) + 1) * sizeof(char));
293 sprintf(errPtr, fmtPtr, msgPtr, path);
294 display_error_message(CreateActionAppShell, errPtr);
301 XtFree ((char *)path);
302 XtFree ((char *)name);
306 /* Getting the WM_STATE property to see if iconified or not */
308 printf("getting wm state\n");
310 wmStateAtom = XInternAtom(display, "WM_STATE", False);
313 printf("getting window property\n");
315 XGetWindowProperty (XtDisplay(CreateActionAppShell),
316 XtWindow(CreateActionAppShell), wmStateAtom, 0L,
317 (long)BUFSIZ, False, wmStateAtom, &actualType,
318 &actualFormat, &nitems, &leftover,
319 (unsigned char **) &wmState);
321 if (wmState->state == IconicState)
322 fprintf(fp, "*iconic: True\n");
324 fprintf(fp, "*iconic: False\n");
326 fprintf(fp, "*expert: %s\n",
327 XtIsManaged(XprtOptionForm) ? "True" : "False");
329 /*** Get and write out the geometry info for our Window ***/
332 printf("getting geometry info\n");
335 x = XtX(CreateActionAppShell);
336 y = XtY(CreateActionAppShell);
337 width = XtWidth(CreateActionAppShell);
338 height = XtHeight(CreateActionAppShell);
340 /* Modify x & y to take into account window mgr frames
341 * This is pretty bogus, but I don't know a better way to do it.
343 extData = _XmGetWidgetExtData(CreateActionAppShell, XmSHELL_EXTENSION);
344 vendorExt = (XmVendorShellExtObject)extData->widget;
345 x -= vendorExt->vendor.xOffset;
346 y -= vendorExt->vendor.yOffset;
348 fprintf(fp, "*x: %d\n", x);
349 fprintf(fp, "*y: %d\n", y);
350 fprintf(fp, "*width: %d\n", width);
351 fprintf(fp, "*height: %d\n", height);
354 printf("getting workspaces this window is present \n");
357 if (DtWsmGetWorkspacesOccupied (display,
358 XtWindow(CreateActionAppShell),
359 &ws_presence, &num_workspaces) == Success)
361 for (j = 0; j < num_workspaces; j++)
363 workspace_name = XGetAtomName (display, ws_presence[j]);
365 (void) strcpy(all_workspace_names, workspace_name);
368 (void) strcat(all_workspace_names, "*");
369 (void) strcat(all_workspace_names, workspace_name);
371 XFree ((char *) workspace_name);
373 XtFree((char *)ws_presence);
374 fprintf(fp, "*workspace: %s\n", all_workspace_names);
377 /* This will be used to indicate what file is currently being edited. */
378 if (pszFileToEdit != NULL) {
379 fprintf(fp, "*file: %s\n", pszFileToEdit);
386 xa_CommandStr[n] = pszExecName; n++;
387 xa_CommandStr[n] = "-s"; n++;
388 xa_CommandStr[n] = name; n++;
390 XSetCommand(XtDisplay(CreateActionAppShell), XtWindow(CreateActionAppShell), xa_CommandStr, n);
391 XtFree ((char *)path);
392 XtFree ((char *)name);
394 /* Don't exit yet, SM needs time to get the new commandStr.*/
397 /*****************************************************************************/
401 /* Session is ending, save session information */
403 /*****************************************************************************/
407 XtPointer clientData,
408 XtPointer callbackArg )
410 char *xa_CommandStr[3];
415 xa_CommandStr[i] = pszExecName; i++;
416 XSetCommand(XtDisplay(CreateActionAppShell), XtWindow(CreateActionAppShell), xa_CommandStr, i);
422 /*****************************************************************************/
424 /* GetIconDataFromWid */
427 /*****************************************************************************/
428 IconData *GetIconDataFromWid( Widget wid )
433 for (i=0; i < ICON_NUMBER; i++) {
434 if ((IconDataList[i]) && (IconDataList[i]->wid == wid)) {
435 return(IconDataList[i]);
438 return((IconData *)NULL);
441 /*****************************************************************************/
443 /* GetIconDataFromMsgID */
446 /*****************************************************************************/
447 IconData *GetIconDataFromMsgID( char *msgID )
452 for (i=0; i < ICON_NUMBER; i++) {
453 if (IconDataList[i]->pmMsgID) {
454 if (!strcmp(IconDataList[i]->pmMsgID, msgID)) {
455 return(IconDataList[i]);
458 if (IconDataList[i]->bmMsgID) {
459 if (!strcmp(IconDataList[i]->bmMsgID, msgID)) {
460 return(IconDataList[i]);
465 for (i=0; i < ICON_NUMBER; i++) {
466 if ( ((IconDataList[i]->pmMsgID) &&
467 (!strcmp(IconDataList[i]->pmMsgID, msgID))) ||
468 ((IconDataList[i]->bmMsgID) &&
469 (!strcmp(IconDataList[i]->bmMsgID, msgID))) ) {
470 return(IconDataList[i]);
474 return((IconData *)NULL);
477 /*****************************************************************************/
479 /* RemoveTmpIconFiles */
482 /*****************************************************************************/
483 void RemoveTmpIconFiles( void )
487 char maskFile[MAXFILENAME];
489 for (i=0; i < ICON_NUMBER; i++) {
490 if ( (IconDataList[i]->pmDirtyBit) &&
491 (IconDataList[i]->pmFileName) &&
492 (strlen(IconDataList[i]->pmFileName)) ) {
494 printf("RemoveTmpIconFiles: unlink '%s'\n", IconDataList[i]->pmFileName); /* debug */
496 unlink(IconDataList[i]->pmFileName);
497 /* This is bogus. But just in case the user specified a bitmap */
498 /* rather than a pixmap during the edit process, this will make */
499 /* sure that file gets removed. The chance of this occurring */
500 /* is very unlikely. */
501 strcpy(maskFile, IconDataList[i]->pmFileName);
502 strcat(maskFile, "_m");
505 printf("Remove maskFile = %s\n", maskFile); /* debug */
509 if ( (IconDataList[i]->bmDirtyBit) &&
510 (IconDataList[i]->bmFileName) &&
511 (strlen(IconDataList[i]->bmFileName)) ) {
513 printf("RemoveTmpIconFiles: unlink '%s'\n", IconDataList[i]->bmFileName); /* debug */
515 unlink(IconDataList[i]->bmFileName);
516 strcpy(maskFile, IconDataList[i]->bmFileName);
517 strcat(maskFile, "_m");
519 printf("Remove maskFile = %s\n", maskFile); /* debug */
527 /*****************************************************************************/
529 /* DieFromToolTalkError */
532 /*****************************************************************************/
534 ExitCB (Widget dialog, XtPointer client_data, XtPointer call_data)
536 exit((int) client_data);
540 DieFromToolTalkError(Widget parent, char *errfmt, Tt_status status)
543 Widget dialog, dialogShell;
544 char *errmsg, *statmsg, *title;
545 XmString xms_errmsg, xms_ok, xms_title;
548 if (! tt_is_err(status)) return;
550 statmsg = tt_status_message(status);
551 /* Solaris dtcreate ignores this so we should too */
552 if(status == TT_ERR_PTYPE)
554 errmsg = XtMalloc(strlen(errfmt) + strlen(statmsg) + 2);
555 sprintf(errmsg, errfmt, statmsg);
557 xms_ok = GETXMSTRING(13, 3, "OK");
558 xms_errmsg = XmStringCreateLocalized(errmsg);
559 xms_title = GETXMSTRING(13, 1, "Create Action - Error");
562 XtSetArg(args[n], XmNautoUnmanage, False); n++;
563 XtSetArg(args[n], XmNokLabelString, xms_ok); n++;
564 XtSetArg(args[n], XmNdialogTitle, xms_title); n++;
565 XtSetArg(args[n], XmNmessageString, xms_errmsg); n++;
566 XtSetArg(args[n], XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL); n++;
568 dialog = XmCreateErrorDialog(parent, "IconEditorError", args, n);
569 XtAddCallback(dialog, XmNokCallback, ExitCB, (XtPointer) status);
570 XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_CANCEL_BUTTON));
571 XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_HELP_BUTTON));
574 * Disable the frame menu from dialog since we don't want the user
575 * to be able to close dialogs with the frame menu
577 dialogShell = XtParent(dialog);
579 XtSetArg(args[n], XmNmwmDecorations, MWM_DECOR_ALL | MWM_DECOR_MENU); n++;
580 XtSetValues(dialogShell, args, n);
581 XtManageChild(dialog);
582 XtRealizeWidget(dialogShell);
584 _DtSimpleError(CLASS_NAME, DtFatalError, NULL, errmsg);
587 XmStringFree(xms_ok);
588 XmStringFree(xms_errmsg);
589 XmStringFree(xms_title);
592 XtAppProcessEvent(XtWidgetToApplicationContext(dialog), XtIMAll);
595 /*****************************************************************************/
597 /* ProcessToolTalkMessage */
600 /*****************************************************************************/
601 Tt_message ProcessToolTalkMessage(Tt_message msg,
603 Tt_message contract )
606 int ttMark = tt_mark();
608 if( 0 == strcmp( tt_message_op( msg ), "Quit" ) ) {
610 * Do the necessary cleanup, call tt_message_reply(),
611 * and exit. Since this is not yet fully implemented, just
612 * call tt_message_reply and exit.
616 printf("ProcessTTMsg: Quit\n"); /* debug */
618 tt_message_reply(msg);
619 RemoveTmpIconFiles();
623 * Any other desktop message ops that one would want
624 * to implement would go here. If
625 * a mapped, realized, top-level widget were passed into
626 * ttdt_session_join instead of (Widget) 0, then the
627 * messages that interact with the X environment
628 * Get_Geometry, etc.) would be handled automatically.
632 printf("ProcessTTMsg: Other\n");
636 tt_release( ttMark );
638 return (Tt_message) 0;
641 /*****************************************************************************/
642 /* NAME: IconEdit_tt_handler */
643 /* DESCRIPTION: Handler for Tooltalk conversation about editing icon. */
646 /* CREATION: 02/21/94 */
648 /*****************************************************************************/
649 Tt_callback_action IconEdit_tt_handler( Tt_message m, Tt_pattern p )
656 char *msgPtr, *fmtPtr, *errPtr;
657 char tmpbuf[MAXBUFSIZE];
663 Boolean bIsNewFile = False;
665 char *tmp = (char *)NULL;
666 char *tmp1 = (char *)NULL;
671 op = tt_message_op(m);
672 /************************************************************************/
673 /* Edit message... */
674 /************************************************************************/
675 if (!strcmp(op, "Edit")) {
677 printf("IconEdit_tt_handler: Edit tt msg = %p\n", m); /* debug */
679 mstate = tt_message_state( m );
680 switch ((int)mstate) {
682 TurnOffHourGlassAllWindows();
684 /* INTERNATIONALIZE */
685 msgPtr = "Failed ToolTalk msg";
687 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
689 sprintf(errPtr, fmtPtr, msgPtr, m);
690 display_error_message(CreateActionAppShell, errPtr);
693 printf( "Failed ToolTalk msg = %p\n", m); /* debug */
695 tt_message_destroy( m );
698 TurnOffHourGlassAllWindows();
700 printf( "Handled ToolTalk msg = %p\n", m); /* debug */
702 tt_message_destroy( m );
706 printf( "Started ToolTalk msg = %p\n", m); /* debug */
711 printf("IconEdit_tt_handler: Saved tt msg = %p\n", m); /* debug */
713 msgID = tt_message_arg_val(m, 1);
714 pIconData = GetIconDataFromMsgID(msgID);
716 printf("msgID = '%s'\n", msgID); /* debug */
719 /*********************************************************************/
720 /* Saved message... */
721 /*********************************************************************/
722 if ( (pIconData) && (!strcmp(op, "Saved")) ) {
723 tt_message_arg_bval(m, 0, (unsigned char **)&ttbuf, &blen);
725 if ( (pIconData->pmMsgID) && (!strcmp(pIconData->pmMsgID, msgID)) ) {
726 if (pIconData->pmDirtyBit) {
727 tmpIconFile = pIconData->pmFileName;
729 tmpnam(pIconData->pmFileName);
731 tmpIconFile = pIconData->pmFileName;
734 if (pIconData->bmDirtyBit) {
735 tmpIconFile = pIconData->bmFileName;
737 tmpnam(pIconData->bmFileName);
739 tmpIconFile = pIconData->bmFileName;
743 tmpfd = open(tmpIconFile, O_CREAT | O_WRONLY | O_NDELAY, 0666);
745 tmpfd = open(tmpIconFile, O_TRUNC | O_WRONLY | O_NDELAY, 0666);
748 msgPtr = GETMESSAGE(5, 60, "Could not open the following file:");
750 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
751 strlen(tmpIconFile) + 1) * sizeof(char));
752 sprintf(errPtr, fmtPtr, msgPtr, tmpIconFile);
753 display_error_message(XtParent(pIconData->wid), errPtr);
755 tt_release( ttMark );
759 /*******************************************************************/
760 /* Determine if this is a pixmap or bitmap. If it is a pixmap, */
761 /* handle as a one file buffer. If a bitmap, then it may be */
762 /* double buffered including the mask. */
763 /*******************************************************************/
765 /*******************************************************************/
766 /* Check for Pixmap first. */
767 /*******************************************************************/
768 if ( (ttbuf) && (!strncmp(ttbuf, "/* XPM */", 9)) ) {
770 printf("This is a XPM file\n"); /* debug */
772 tmp = strstr(ttbuf, "};");
774 tmp += 2; /* Go one char past the ";" */
776 tmplen = blen - strlen(tmp) + 1;
777 printf("Amro tmplen = %d\n", tmplen);
779 tmplen = (char *)tmp - (char *)ttbuf;
781 printf("Troy tmplen = %d\n", tmplen); /* debug */
786 if ((wlen = write(tmpfd, ttbuf, tmplen)) == tmplen) {
787 if (tmpfd > -1) close(tmpfd);
789 /* INTERNATIONALIZE */
790 msgPtr = "Could not write to the following file:";
792 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
793 strlen(tmpIconFile) + 1) * sizeof(char));
794 sprintf(errPtr, fmtPtr, msgPtr, tmpIconFile);
795 display_error_message(XtParent(pIconData->wid), errPtr);
797 tt_release( ttMark );
798 if (tmpfd > -1) close(tmpfd);
802 /*******************************************************************/
803 /* Must be a Bitmap. */
804 /*******************************************************************/
807 printf("This is a XBM file\n"); /* debug */
808 printf("ttbuffer size = %d\n", blen); /* debug */
810 /****************************************************************/
811 /* Determine size of first bitmap. */
812 /****************************************************************/
813 tmp = strstr(ttbuf, "};");
815 tmp += 2; /* Go one char past the ";" */
817 tmplen = blen - strlen(tmp) + 1;
818 printf("Amro tmplen = %d\n", tmplen);
820 tmplen = (char *)tmp - (char *)ttbuf;
822 printf("Troy tmplen = %d\n", tmplen); /* debug */
828 printf("File 1 size = %d\n", tmplen); /* debug */
831 /****************************************************************/
832 /* Write out first bitmap file. */
833 /****************************************************************/
835 printf("Writing first bitmap file\n"); /* debug */
837 if ((wlen = write(tmpfd, ttbuf, tmplen)) == tmplen) {
838 if (tmpfd > -1) close(tmpfd);
840 /* INTERNATIONALIZE */
841 msgPtr = "Could not write to the following file:";
843 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
844 strlen(tmpIconFile) + 1) * sizeof(char));
845 sprintf(errPtr, fmtPtr, msgPtr, tmpIconFile);
846 display_error_message(XtParent(pIconData->wid), errPtr);
848 tt_release( ttMark );
849 if (tmpfd > -1) close(tmpfd);
853 /****************************************************************/
854 /* Now determine if there is a second bitmap and its size. */
855 /****************************************************************/
857 tmp1 = strstr(tmp, "};");
859 sprintf(tmpbuf, "%s_m", tmpIconFile);
861 tmp1 += 2; /* Go one char past the ";" */
863 printf("Mask file name = '%s'\n", tmpbuf); /* debug */
865 tmpfd = open(tmpbuf, O_CREAT | O_WRONLY | O_NDELAY, 0666);
868 GETMESSAGE(5, 60, "Could not open the following file:");
870 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
871 strlen(tmpbuf) + 1) * sizeof(char));
872 sprintf(errPtr, fmtPtr, msgPtr, tmpbuf);
873 display_error_message(XtParent(pIconData->wid), errPtr);
875 tt_release( ttMark );
880 printf("writing mask file \n");
883 tmplen = strlen(tmp);
884 printf("Amro tmplen = %d\n", tmplen);
886 tmplen = (char *)tmp1 - (char *)tmp;
888 printf("Troy tmplen = %d\n", tmplen); /* debug */
890 if ((wlen = write(tmpfd, tmp, tmplen)) == tmplen) {
891 if (tmpfd > -1) close(tmpfd);
893 /* INTERNATIONALIZE */
894 msgPtr = "Could not write to the following file:";
896 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
897 strlen(tmpbuf) + 1) * sizeof(char));
898 sprintf(errPtr, fmtPtr, msgPtr, tmpbuf);
899 display_error_message(XtParent(pIconData->wid), errPtr);
901 tt_release( ttMark );
902 if (tmpfd > -1) close(tmpfd);
906 /****************************************************************/
907 /* Must not have a mask, so lets clean up any old mask file. */
908 /****************************************************************/
911 printf("Remove maskFile = %s\n", tmpbuf); /* debug */
917 /****************************************************************/
918 /* Set the icon gadget with new icon, and flag the dirty bit. */
919 /****************************************************************/
920 if ( ( (pIconData->pmMsgID) &&
921 (!strcmp(pIconData->pmMsgID, msgID)) &&
924 ( (pIconData->bmMsgID) &&
925 (!strcmp(pIconData->bmMsgID, msgID)) &&
926 (!bShowPixmaps) ) ) {
927 XmeFlushIconFileCache(NULL);
929 printf("Change icon image for widget = %p\n", pIconData->wid); /* debug */
931 SET_ICONGADGET_ICON(pIconData->wid, tmpIconFile);
933 if ((pIconData->pmMsgID) && (!strcmp(pIconData->pmMsgID, msgID))) {
934 pIconData->pmDirtyBit = True;
936 pIconData->bmDirtyBit = True;
939 printf("**********tmp file name = %s\n", tmpIconFile); /* debug */
943 tt_release( ttMark );
944 return( TT_CALLBACK_PROCESSED );
947 /*****************************************************************************/
948 /* NAME: UxDoEditPixmap */
949 /* DESCRIPTION: Loads the icon editor. */
950 /* PARAMETERS: none */
952 /* CREATION: 02/11/94 */
954 /*****************************************************************************/
955 void UxDoEditPixmap(Widget wid, char *fname)
957 Tt_message m; /* ToolTalk message */
958 Tt_pattern p; /* ToolTalk dynamic pattern */
959 Tt_status ttRc; /* ToolTalk status */
964 int lenFile1 = 0, rlenFile1 = 0;
965 int lenFile2 = 0, rlenFile2 = 0;
971 unsigned char *buffer;
974 char tmpbuf[MAXBUFSIZE];
978 char *mname = (char *)NULL;
979 char *type_name, *size_name;
983 if (fname) printf("Edit filename: '%s'\n", fname); /* debug */
988 /*********************************************************************/
990 /*********************************************************************/
991 m = tt_prequest_create( TT_SESSION, "Edit" );
992 msgID = tt_message_id(m);
993 pIconData = GetIconDataFromWid(wid);
995 ppMsgID = &(pIconData->pmMsgID);
997 ppMsgID = &(pIconData->bmMsgID);
1002 if (msgID && strlen(msgID)) {
1003 *ppMsgID = (char *)malloc(strlen(msgID) + 1);
1004 strcpy(*ppMsgID, msgID);
1008 printf("msgID = '%s'\n", msgID); /* debug */
1009 printf("Create Edit msg = %p\n", m); /* debug */
1012 /*********************************************************************/
1013 /* Add arguments to message */
1014 /*********************************************************************/
1016 fd1 = open(fname, O_RDONLY);
1018 /* Error opening icon file! */
1019 msgPtr = GETMESSAGE(5, 60, "Could not open the following file:");
1021 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
1022 strlen(fname) + 1) * sizeof(char));
1023 sprintf(errPtr, fmtPtr, msgPtr, fname);
1024 display_error_message(XtParent(wid), errPtr);
1028 /***************************************/
1029 /* Find out how big a buffer is needed */
1030 /***************************************/
1031 lenFile1 = lseek(fd1, 0, SEEK_END);
1032 (void) lseek(fd1, 0, SEEK_SET);
1034 /*************************************************************/
1035 /* Read first few bytes to determine what kind of file it is */
1036 /*************************************************************/
1037 read(fd1, tmpbuf, 10);
1038 (void) lseek(fd1, 0, SEEK_SET);
1040 /******************************************************************/
1041 /* If the file is a bitmap, then check for its mask file and add. */
1042 /******************************************************************/
1043 if ( strncmp(tmpbuf, "/* XPM */", 9) ) {
1045 mname = CreateMaskName(fname);
1047 /***************************************************************/
1048 /* Check if mask file exists. */
1049 /***************************************************************/
1050 if ((mname) && (check_file_exists(mname))) {
1051 fd2 = open(mname, O_RDONLY);
1053 /* Error opening icon file! */
1055 GETMESSAGE(5, 60, "Could not open the following file:");
1057 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
1058 strlen(mname) + 1) * sizeof(char));
1059 sprintf(errPtr, fmtPtr, msgPtr, mname);
1060 display_error_message(XtParent(wid), errPtr);
1065 /***************************************/
1066 /* Find out how big a buffer is needed */
1067 /***************************************/
1068 lenFile2 = lseek(fd2, 0, SEEK_END);
1069 (void) lseek(fd2, 0, SEEK_SET);
1073 /******************************************************************/
1074 /* Create 1 big buffer */
1075 /******************************************************************/
1077 printf("Size of file 1 = %d\n", lenFile1); /* debug */
1078 printf("Size of file 2 = %d\n", lenFile2); /* debug */
1080 buffer = (unsigned char *)XtMalloc((Cardinal)(lenFile1 + lenFile2 + 1));
1081 memset(buffer, 0, (lenFile1 + lenFile2 + 1));
1083 /***************************************/
1084 /* Read file1 into buffer. */
1085 /***************************************/
1086 if ((rlenFile1 = read(fd1, buffer, lenFile1)) != lenFile1) {
1087 /* didn't read whole file! */
1089 /* INTERNATIONALIZE */
1090 msgPtr = "Could not read the entire file:";
1092 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
1093 strlen(fname) + 1) * sizeof(char));
1094 sprintf(errPtr, fmtPtr, msgPtr, fname);
1095 display_error_message(XtParent(wid), errPtr);
1097 if (mname) XtFree(mname);
1098 XtFree((char *) buffer);
1103 printf("buffer = %p\n", buffer);
1105 /*ptr = (char *)&(buffer[lenFile1 + 1]);*/
1106 ptr = (char *)&(buffer[lenFile1]);
1108 printf("ptr = %p\n", ptr);
1110 if ((rlenFile2 = read(fd2, ptr, lenFile2)) != lenFile2) {
1111 /* didn't read whole file! */
1113 /* INTERNATIONALIZE */
1114 msgPtr = "Could not read the entire file:";
1116 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
1117 strlen(fname) + 1) * sizeof(char));
1118 sprintf(errPtr, fmtPtr, msgPtr, mname);
1119 display_error_message(XtParent(wid), errPtr);
1121 XtFree((char *) buffer);
1122 if (mname) XtFree(mname);
1126 if (fd1 > -1) close(fd1);
1127 if (fd2 > -1) close(fd2);
1130 printf("final buffer = '%s'\n", buffer); /* debug */
1131 printf("Buffer = '%s'\n", buffer); /* debug */
1133 tt_message_barg_add( m, TT_INOUT, "XPM", buffer, lenFile1 + lenFile2 + 1);
1134 if (mname) XtFree(mname);
1135 XtFree((char *) buffer);
1139 tt_message_barg_add( m, TT_INOUT, "XPM", (const unsigned char *)NULL, 0);
1141 tt_message_arg_add(m, TT_IN, "messageID", msgID);
1143 /******************************************************************/
1144 /* Create a pattern and add a callback to get notifications */
1145 /* of periodic saves */
1146 /******************************************************************/
1147 p = tt_pattern_create();
1148 tt_pattern_category_set(p, TT_OBSERVE);
1149 tt_pattern_scope_add(p, TT_SESSION);
1150 tt_pattern_session_add(p, tt_default_session());
1151 tt_pattern_address_add(p, TT_HANDLER);
1152 tt_pattern_op_add(p, "Saved");
1153 tt_pattern_callback_add(p, IconEdit_tt_handler);
1154 tt_pattern_register(p);
1156 /******************************************************************/
1157 /* Add callback to notify when change complete */
1158 /******************************************************************/
1159 tt_message_callback_add( m, IconEdit_tt_handler );
1161 /******************************************************************/
1163 /******************************************************************/
1164 TurnOnHourGlassAllWindows();
1165 ttRc = tt_message_send( m );
1166 DieFromToolTalkError( UxTopLevel, "tt_message_send", ttRc );
1168 #endif /* __TOOLTALK */
1170 /*****************************************************************************/
1177 /*****************************************************************************/
1178 main(int argc, char *argv[])
1180 /*-----------------------------------------------------------
1182 * The default identifier - mainIface will only be declared
1183 * if the interface function is global and of type swidget.
1184 * To change the identifier to a different name, modify the
1185 * string mainIface in the file "xtmain.dat". If "mainIface"
1186 * is declared, it will be used below where the return value
1187 * of PJ_INTERFACE_FUNCTION_CALL will be assigned to it.
1188 *----------------------------------------------------------*/
1195 char * sessionString;
1200 extern swidget create_AddFiletype();
1201 extern swidget create_FileCharacteristics();
1202 extern swidget create_OpenFile();
1203 extern swidget create_Confirmed();
1204 extern Widget create_ErrorDialog();
1206 Atom xa_WM_SAVE_YOURSELF;
1209 /*---------------------------------
1210 * Interface function declaration
1211 *--------------------------------*/
1212 Widget create_applicationShell1(swidget);
1213 swidget UxParent = NULL;
1216 /*---------------------
1217 * Initialize program
1218 *--------------------*/
1220 _DtEnvControl(DT_ENV_SET);
1221 XtSetLanguageProc(NULL, NULL, NULL);
1222 pszFileToEdit = (char *)NULL;
1223 memset(&sessiondata, 0, sizeof(SessionData));
1224 memset(IconDataList, 0, sizeof(IconDataList));
1226 /********************************************************************/
1227 /* Parse the command line arguments. */
1228 /********************************************************************/
1229 pszExecName = argv[0];
1232 for (i=1; i<argc; i++) {
1233 if ((argv[i][0] == '-') && (argv[i][1] == '?')) {
1234 setlocale(LC_ALL, "");
1235 nlmsg_fd = catopen("dtcreate", NL_CAT_LOCALE);
1237 GETMESSAGE(5, 110, "Usage: dtcreate [<filename>] [-?]"));
1240 if (argv[i][0] == '-') {
1241 if (!strcmp(argv[i], "-s")) {
1243 sessiondata.pszSessionFile = (char *)XtMalloc(strlen(argv[i]) + 1);
1244 strcpy(sessiondata.pszSessionFile, argv[i]);
1245 sessiondata.useSession = True;
1250 pszFileToEdit = (char *)XtMalloc(strlen(argv[i]) + 1);
1251 strcpy(pszFileToEdit, argv[i]);
1258 UxTopLevel = XtAppInitialize(&UxAppContext, CLASS_NAME,
1259 NULL, 0, &argc, argv, NULL, NULL, 0);
1261 nlmsg_fd = catopen("dtcreate", NL_CAT_LOCALE);
1263 UxDisplay = XtDisplay(UxTopLevel);
1264 UxScreen = XDefaultScreen(UxDisplay);
1266 if (sessiondata.useSession) {
1270 /*---------------------
1271 * Determine resolution
1272 *--------------------*/
1273 if (_DtGetDisplayResolution(UxDisplay, UxScreen) == 1) {
1283 /*-------------------------------------------------------
1284 * Insert initialization code for your application here
1285 *------------------------------------------------------*/
1288 printf("display string = '%s'\n", DisplayString(UxDisplay));
1290 ttsession = getenv("TT_SESSION");
1291 if (!ttsession || strlen(ttsession)==0) {
1292 char *ttxsession = tt_X_session(XDisplayString(UxDisplay));
1293 ttRc = tt_default_session_set(ttxsession);
1296 ttMark = tt_mark( );
1298 procId = tt_open( );
1299 ttRc = tt_ptr_error(procId);
1301 GETMESSAGE(13, 2, "Could not connect to ToolTalk:\n%s\nExiting ...");
1302 DieFromToolTalkError( UxTopLevel, errfmt, ttRc );
1305 DieFromToolTalkError( UxTopLevel, "tt_fd", tt_int_error( ttFd ) );
1307 ttRc = tt_ptype_declare( "dtcreate" );
1308 DieFromToolTalkError( UxTopLevel, "tt_ptype_declare", ttRc );
1310 ttRc = tt_session_join( tt_default_session( ));
1311 DieFromToolTalkError( UxTopLevel, "tt_session_join", ttRc );
1313 XtAppAddInput( UxAppContext, ttFd, (XtPointer)XtInputReadMask,
1314 (XtInputCallbackProc)ProcessToolTalkMessage, 0 );
1317 if (!pszFileToEdit) {
1322 /*----------------------------------------------------------------
1323 * Create and popup the first window of the interface. The
1324 * return value can be used in the popdown or destroy functions.
1325 * The Widget return value of PJ_INTERFACE_FUNCTION_CALL will
1326 * be assigned to "mainIface" from PJ_INTERFACE_RETVAL_TYPE.
1327 *---------------------------------------------------------------*/
1329 mainIface = create_applicationShell1(UxParent);
1330 AddFiletype = create_AddFiletype(mainIface);
1331 FileCharacteristics = create_FileCharacteristics(AddFiletype);
1332 OpenFile = create_OpenFile();
1334 UxPopupInterface(mainIface, no_grab);
1335 if (pszFileToEdit) {
1336 if (!OpenDefinitionFile(pszFileToEdit, &AD)) {
1340 XtVaGetValues (CA_WindowTypeArea, XmNheight, &wintypeheight, NULL);
1342 /*------------------------------------------------------------------*/
1343 /* Register for save and restore. */
1344 /*------------------------------------------------------------------*/
1345 xa_WM_SAVE_YOURSELF = XInternAtom(XtDisplay(CreateActionAppShell), "WM_SAVE_YOURSELF", False);
1346 XmAddWMProtocols(CreateActionAppShell, &xa_WM_SAVE_YOURSELF, 1);
1347 XmAddWMProtocolCallback(CreateActionAppShell, xa_WM_SAVE_YOURSELF,
1348 SaveSessionCB, (XtPointer)CreateActionAppShell);
1350 /*------------------------------------------------------------------*/
1351 /* Make a copy of the AD data structure. This will be used later */
1352 /* when the user wants to exit to determine if the latest data has */
1353 /* been saved or not. */
1354 /*------------------------------------------------------------------*/
1355 pMyCopyAD = copyAD(&AD);
1359 ttMark = tt_mark( );
1361 procId = ttdt_open( &ttFd, "dtcreate", "CDE", "1.0", 1 );
1362 ttRc = tt_ptr_error(procId);
1364 GETMESSAGE(13, 2, "Could not connect to ToolTalk:\n%s\nExiting ...");
1365 DieFromToolTalkError( UxTopLevel, errfmt, ttRc );
1368 ttRc = tt_int_error( ttFd );
1369 DieFromToolTalkError( UxTopLevel, "tt_fd", ttRc );
1371 sessionString = tt_default_session();
1372 ttRc = tt_ptr_error( sessionString );
1373 DieFromToolTalkError( UxTopLevel, "tt_default_session", ttRc );
1375 ttPatt = ttdt_session_join( sessionString, ProcessToolTalkMessage,
1376 (Widget) 0, (void *) 0, 1 );
1377 ttRc = tt_ptr_error(ttPatt);
1378 DieFromToolTalkError( UxTopLevel, "ttdt_session_join", ttRc );
1380 XtAppAddInput( UxAppContext, ttFd, (XtPointer)XtInputReadMask,
1381 tttk_Xt_input_handler, 0 );
1384 /*-----------------------
1385 * Enter the event loop
1386 *----------------------*/
1388 XtAppMainLoop (UxAppContext);
1391 ttdt_session_quit(0, 0, 1);
1393 tt_release( ttMark );
1394 RemoveTmpIconFiles();