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>
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 (IconDataList[i]->bmFileName) &&
518 (strlen(IconDataList[i]->bmFileName)) ) {
520 printf("RemoveTmpIconFiles: unlink '%s'\n", IconDataList[i]->bmFileName); /* debug */
522 unlink(IconDataList[i]->bmFileName);
523 strcpy(maskFile, IconDataList[i]->bmFileName);
524 strcat(maskFile, "_m");
526 printf("Remove maskFile = %s\n", maskFile); /* debug */
534 /*****************************************************************************/
536 /* DieFromToolTalkError */
539 /*****************************************************************************/
541 ExitCB (Widget dialog, XtPointer client_data, XtPointer call_data)
543 exit((int)(XtArgVal) client_data);
547 DieFromToolTalkError(Widget parent, char *errfmt, Tt_status status)
550 Widget dialog, dialogShell;
551 char *errmsg, *statmsg, *title;
552 XmString xms_errmsg, xms_ok, xms_title;
555 if (! tt_is_err(status)) return;
557 statmsg = tt_status_message(status);
558 /* Solaris dtcreate ignores this so we should too */
559 if(status == TT_ERR_PTYPE)
561 errmsg = XtMalloc(strlen(errfmt) + strlen(statmsg) + 2);
562 sprintf(errmsg, errfmt, statmsg);
564 xms_ok = GETXMSTRING(13, 3, "OK");
565 xms_errmsg = XmStringCreateLocalized(errmsg);
566 xms_title = GETXMSTRING(13, 1, "Create Action - Error");
569 XtSetArg(args[n], XmNautoUnmanage, False); n++;
570 XtSetArg(args[n], XmNokLabelString, xms_ok); n++;
571 XtSetArg(args[n], XmNdialogTitle, xms_title); n++;
572 XtSetArg(args[n], XmNmessageString, xms_errmsg); n++;
573 XtSetArg(args[n], XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL); n++;
575 dialog = XmCreateErrorDialog(parent, "IconEditorError", args, n);
576 XtAddCallback(dialog, XmNokCallback, ExitCB, (XtPointer) status);
577 XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_CANCEL_BUTTON));
578 XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_HELP_BUTTON));
581 * Disable the frame menu from dialog since we don't want the user
582 * to be able to close dialogs with the frame menu
584 dialogShell = XtParent(dialog);
586 XtSetArg(args[n], XmNmwmDecorations, MWM_DECOR_ALL | MWM_DECOR_MENU); n++;
587 XtSetValues(dialogShell, args, n);
588 XtManageChild(dialog);
589 XtRealizeWidget(dialogShell);
591 _DtSimpleError(CLASS_NAME, DtFatalError, NULL, errmsg);
594 XmStringFree(xms_ok);
595 XmStringFree(xms_errmsg);
596 XmStringFree(xms_title);
599 XtAppProcessEvent(XtWidgetToApplicationContext(dialog), XtIMAll);
602 /*****************************************************************************/
604 /* ProcessToolTalkMessage */
607 /*****************************************************************************/
608 Tt_message ProcessToolTalkMessage(Tt_message msg,
610 Tt_message contract )
613 int ttMark = tt_mark();
615 if( 0 == strcmp( tt_message_op( msg ), "Quit" ) ) {
617 * Do the necessary cleanup, call tt_message_reply(),
618 * and exit. Since this is not yet fully implemented, just
619 * call tt_message_reply and exit.
623 printf("ProcessTTMsg: Quit\n"); /* debug */
625 tt_message_reply(msg);
626 RemoveTmpIconFiles();
630 * Any other desktop message ops that one would want
631 * to implement would go here. If
632 * a mapped, realized, top-level widget were passed into
633 * ttdt_session_join instead of (Widget) 0, then the
634 * messages that interact with the X environment
635 * Get_Geometry, etc.) would be handled automatically.
639 printf("ProcessTTMsg: Other\n");
643 tt_release( ttMark );
645 return (Tt_message) 0;
648 /*****************************************************************************/
649 /* NAME: IconEdit_tt_handler */
650 /* DESCRIPTION: Handler for Tooltalk conversation about editing icon. */
653 /* CREATION: 02/21/94 */
655 /*****************************************************************************/
656 Tt_callback_action IconEdit_tt_handler( Tt_message m, Tt_pattern p )
663 char *msgPtr, *fmtPtr, *errPtr;
664 char tmpbuf[MAXBUFSIZE];
670 Boolean bIsNewFile = False;
672 char *tmp = (char *)NULL;
673 char *tmp1 = (char *)NULL;
678 op = tt_message_op(m);
679 /************************************************************************/
680 /* Edit message... */
681 /************************************************************************/
682 if (!strcmp(op, "Edit")) {
684 printf("IconEdit_tt_handler: Edit tt msg = %p\n", m); /* debug */
686 mstate = tt_message_state( m );
687 switch ((int)mstate) {
689 TurnOffHourGlassAllWindows();
691 /* INTERNATIONALIZE */
692 msgPtr = "Failed ToolTalk msg";
694 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
696 sprintf(errPtr, fmtPtr, msgPtr, m);
697 display_error_message(CreateActionAppShell, errPtr);
700 printf( "Failed ToolTalk msg = %p\n", m); /* debug */
702 tt_message_destroy( m );
705 TurnOffHourGlassAllWindows();
707 printf( "Handled ToolTalk msg = %p\n", m); /* debug */
709 tt_message_destroy( m );
713 printf( "Started ToolTalk msg = %p\n", m); /* debug */
718 printf("IconEdit_tt_handler: Saved tt msg = %p\n", m); /* debug */
720 msgID = tt_message_arg_val(m, 1);
721 pIconData = GetIconDataFromMsgID(msgID);
723 printf("msgID = '%s'\n", msgID); /* debug */
726 /*********************************************************************/
727 /* Saved message... */
728 /*********************************************************************/
729 if ( (pIconData) && (!strcmp(op, "Saved")) ) {
730 tt_message_arg_bval(m, 0, (unsigned char **)&ttbuf, &blen);
732 if ( (pIconData->pmMsgID) && (!strcmp(pIconData->pmMsgID, msgID)) ) {
733 if (pIconData->pmDirtyBit) {
734 tmpIconFile = pIconData->pmFileName;
736 tmpnam(pIconData->pmFileName);
738 tmpIconFile = pIconData->pmFileName;
741 if (pIconData->bmDirtyBit) {
742 tmpIconFile = pIconData->bmFileName;
744 tmpnam(pIconData->bmFileName);
746 tmpIconFile = pIconData->bmFileName;
750 tmpfd = open(tmpIconFile, O_CREAT | O_WRONLY | O_NDELAY, 0666);
752 tmpfd = open(tmpIconFile, O_TRUNC | O_WRONLY | O_NDELAY, 0666);
755 msgPtr = GETMESSAGE(5, 60, "Could not open the following file:");
757 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
758 strlen(tmpIconFile) + 1) * sizeof(char));
759 sprintf(errPtr, fmtPtr, msgPtr, tmpIconFile);
760 display_error_message(XtParent(pIconData->wid), errPtr);
762 tt_release( ttMark );
763 return (TT_CALLBACK_CONTINUE);
766 /*******************************************************************/
767 /* Determine if this is a pixmap or bitmap. If it is a pixmap, */
768 /* handle as a one file buffer. If a bitmap, then it may be */
769 /* double buffered including the mask. */
770 /*******************************************************************/
772 /*******************************************************************/
773 /* Check for Pixmap first. */
774 /*******************************************************************/
775 if ( (ttbuf) && (!strncmp(ttbuf, "/* XPM */", 9)) ) {
777 printf("This is a XPM file\n"); /* debug */
779 tmp = strstr(ttbuf, "};");
781 tmp += 2; /* Go one char past the ";" */
783 tmplen = blen - strlen(tmp) + 1;
784 printf("Amro tmplen = %d\n", tmplen);
786 tmplen = (char *)tmp - (char *)ttbuf;
788 printf("Troy tmplen = %d\n", tmplen); /* debug */
793 if ((wlen = write(tmpfd, ttbuf, tmplen)) == tmplen) {
794 if (tmpfd > -1) close(tmpfd);
796 /* INTERNATIONALIZE */
797 msgPtr = "Could not write to the following file:";
799 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
800 strlen(tmpIconFile) + 1) * sizeof(char));
801 sprintf(errPtr, fmtPtr, msgPtr, tmpIconFile);
802 display_error_message(XtParent(pIconData->wid), errPtr);
804 tt_release( ttMark );
805 if (tmpfd > -1) close(tmpfd);
806 return (TT_CALLBACK_CONTINUE);
809 /*******************************************************************/
810 /* Must be a Bitmap. */
811 /*******************************************************************/
814 printf("This is a XBM file\n"); /* debug */
815 printf("ttbuffer size = %d\n", blen); /* debug */
817 /****************************************************************/
818 /* Determine size of first bitmap. */
819 /****************************************************************/
820 tmp = strstr(ttbuf, "};");
822 tmp += 2; /* Go one char past the ";" */
824 tmplen = blen - strlen(tmp) + 1;
825 printf("Amro tmplen = %d\n", tmplen);
827 tmplen = (char *)tmp - (char *)ttbuf;
829 printf("Troy tmplen = %d\n", tmplen); /* debug */
835 printf("File 1 size = %d\n", tmplen); /* debug */
838 /****************************************************************/
839 /* Write out first bitmap file. */
840 /****************************************************************/
842 printf("Writing first bitmap file\n"); /* debug */
844 if ((wlen = write(tmpfd, ttbuf, tmplen)) == tmplen) {
845 if (tmpfd > -1) close(tmpfd);
847 /* INTERNATIONALIZE */
848 msgPtr = "Could not write to the following file:";
850 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
851 strlen(tmpIconFile) + 1) * sizeof(char));
852 sprintf(errPtr, fmtPtr, msgPtr, tmpIconFile);
853 display_error_message(XtParent(pIconData->wid), errPtr);
855 tt_release( ttMark );
856 if (tmpfd > -1) close(tmpfd);
857 return (TT_CALLBACK_CONTINUE);
860 /****************************************************************/
861 /* Now determine if there is a second bitmap and its size. */
862 /****************************************************************/
864 tmp1 = strstr(tmp, "};");
866 sprintf(tmpbuf, "%s_m", tmpIconFile);
868 tmp1 += 2; /* Go one char past the ";" */
870 printf("Mask file name = '%s'\n", tmpbuf); /* debug */
872 tmpfd = open(tmpbuf, O_CREAT | O_WRONLY | O_NDELAY, 0666);
875 GETMESSAGE(5, 60, "Could not open the following file:");
877 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
878 strlen(tmpbuf) + 1) * sizeof(char));
879 sprintf(errPtr, fmtPtr, msgPtr, tmpbuf);
880 display_error_message(XtParent(pIconData->wid), errPtr);
882 tt_release( ttMark );
883 return (TT_CALLBACK_CONTINUE);
887 printf("writing mask file \n");
890 tmplen = strlen(tmp);
891 printf("Amro tmplen = %d\n", tmplen);
893 tmplen = (char *)tmp1 - (char *)tmp;
895 printf("Troy tmplen = %d\n", tmplen); /* debug */
897 if ((wlen = write(tmpfd, tmp, tmplen)) == tmplen) {
898 if (tmpfd > -1) close(tmpfd);
900 /* INTERNATIONALIZE */
901 msgPtr = "Could not write to the following file:";
903 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
904 strlen(tmpbuf) + 1) * sizeof(char));
905 sprintf(errPtr, fmtPtr, msgPtr, tmpbuf);
906 display_error_message(XtParent(pIconData->wid), errPtr);
908 tt_release( ttMark );
909 if (tmpfd > -1) close(tmpfd);
910 return (TT_CALLBACK_CONTINUE);
913 /****************************************************************/
914 /* Must not have a mask, so lets clean up any old mask file. */
915 /****************************************************************/
918 printf("Remove maskFile = %s\n", tmpbuf); /* debug */
924 /****************************************************************/
925 /* Set the icon gadget with new icon, and flag the dirty bit. */
926 /****************************************************************/
927 if ( ( (pIconData->pmMsgID) &&
928 (!strcmp(pIconData->pmMsgID, msgID)) &&
931 ( (pIconData->bmMsgID) &&
932 (!strcmp(pIconData->bmMsgID, msgID)) &&
933 (!bShowPixmaps) ) ) {
934 XmeFlushIconFileCache(NULL);
936 printf("Change icon image for widget = %p\n", pIconData->wid); /* debug */
938 SET_ICONGADGET_ICON(pIconData->wid, tmpIconFile);
940 if ((pIconData->pmMsgID) && (!strcmp(pIconData->pmMsgID, msgID))) {
941 pIconData->pmDirtyBit = True;
943 pIconData->bmDirtyBit = True;
946 printf("**********tmp file name = %s\n", tmpIconFile); /* debug */
950 tt_release( ttMark );
951 return( TT_CALLBACK_PROCESSED );
954 /*****************************************************************************/
955 /* NAME: UxDoEditPixmap */
956 /* DESCRIPTION: Loads the icon editor. */
957 /* PARAMETERS: none */
959 /* CREATION: 02/11/94 */
961 /*****************************************************************************/
962 void UxDoEditPixmap(Widget wid, char *fname)
964 Tt_message m; /* ToolTalk message */
965 Tt_pattern p; /* ToolTalk dynamic pattern */
966 Tt_status ttRc; /* ToolTalk status */
971 int lenFile1 = 0, rlenFile1 = 0;
972 int lenFile2 = 0, rlenFile2 = 0;
978 unsigned char *buffer;
981 char tmpbuf[MAXBUFSIZE];
985 char *mname = (char *)NULL;
986 char *type_name, *size_name;
990 if (fname) printf("Edit filename: '%s'\n", fname); /* debug */
995 /*********************************************************************/
997 /*********************************************************************/
998 m = tt_prequest_create( TT_SESSION, "Edit" );
999 msgID = tt_message_id(m);
1000 pIconData = GetIconDataFromWid(wid);
1002 ppMsgID = &(pIconData->pmMsgID);
1004 ppMsgID = &(pIconData->bmMsgID);
1009 if (msgID && strlen(msgID)) {
1010 *ppMsgID = (char *)malloc(strlen(msgID) + 1);
1011 strcpy(*ppMsgID, msgID);
1015 printf("msgID = '%s'\n", msgID); /* debug */
1016 printf("Create Edit msg = %p\n", m); /* debug */
1019 /*********************************************************************/
1020 /* Add arguments to message */
1021 /*********************************************************************/
1023 fd1 = open(fname, O_RDONLY);
1025 /* Error opening icon file! */
1026 msgPtr = GETMESSAGE(5, 60, "Could not open the following file:");
1028 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
1029 strlen(fname) + 1) * sizeof(char));
1030 sprintf(errPtr, fmtPtr, msgPtr, fname);
1031 display_error_message(XtParent(wid), errPtr);
1035 /***************************************/
1036 /* Find out how big a buffer is needed */
1037 /***************************************/
1038 lenFile1 = lseek(fd1, 0, SEEK_END);
1039 (void) lseek(fd1, 0, SEEK_SET);
1041 /*************************************************************/
1042 /* Read first few bytes to determine what kind of file it is */
1043 /*************************************************************/
1044 read(fd1, tmpbuf, 10);
1045 (void) lseek(fd1, 0, SEEK_SET);
1047 /******************************************************************/
1048 /* If the file is a bitmap, then check for its mask file and add. */
1049 /******************************************************************/
1050 if ( strncmp(tmpbuf, "/* XPM */", 9) ) {
1052 mname = CreateMaskName(fname);
1054 /***************************************************************/
1055 /* Check if mask file exists. */
1056 /***************************************************************/
1057 if ((mname) && (check_file_exists(mname))) {
1058 fd2 = open(mname, O_RDONLY);
1060 /* Error opening icon file! */
1062 GETMESSAGE(5, 60, "Could not open the following file:");
1064 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
1065 strlen(mname) + 1) * sizeof(char));
1066 sprintf(errPtr, fmtPtr, msgPtr, mname);
1067 display_error_message(XtParent(wid), errPtr);
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);
1110 printf("buffer = %p\n", buffer);
1112 /*ptr = (char *)&(buffer[lenFile1 + 1]);*/
1113 ptr = (char *)&(buffer[lenFile1]);
1115 printf("ptr = %p\n", ptr);
1117 if ((rlenFile2 = read(fd2, ptr, lenFile2)) != lenFile2) {
1118 /* didn't read whole file! */
1120 /* INTERNATIONALIZE */
1121 msgPtr = "Could not read the entire file:";
1123 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
1124 strlen(fname) + 1) * sizeof(char));
1125 sprintf(errPtr, fmtPtr, msgPtr, mname);
1126 display_error_message(XtParent(wid), errPtr);
1128 XtFree((char *) buffer);
1129 if (mname) XtFree(mname);
1133 if (fd1 > -1) close(fd1);
1134 if (fd2 > -1) close(fd2);
1137 printf("final buffer = '%s'\n", buffer); /* debug */
1138 printf("Buffer = '%s'\n", buffer); /* debug */
1140 tt_message_barg_add( m, TT_INOUT, "XPM", buffer, lenFile1 + lenFile2 + 1);
1141 if (mname) XtFree(mname);
1142 XtFree((char *) buffer);
1146 tt_message_barg_add( m, TT_INOUT, "XPM", (const unsigned char *)NULL, 0);
1148 tt_message_arg_add(m, TT_IN, "messageID", msgID);
1150 /******************************************************************/
1151 /* Create a pattern and add a callback to get notifications */
1152 /* of periodic saves */
1153 /******************************************************************/
1154 p = tt_pattern_create();
1155 tt_pattern_category_set(p, TT_OBSERVE);
1156 tt_pattern_scope_add(p, TT_SESSION);
1157 tt_pattern_session_add(p, tt_default_session());
1158 tt_pattern_address_add(p, TT_HANDLER);
1159 tt_pattern_op_add(p, "Saved");
1160 tt_pattern_callback_add(p, IconEdit_tt_handler);
1161 tt_pattern_register(p);
1163 /******************************************************************/
1164 /* Add callback to notify when change complete */
1165 /******************************************************************/
1166 tt_message_callback_add( m, IconEdit_tt_handler );
1168 /******************************************************************/
1170 /******************************************************************/
1171 TurnOnHourGlassAllWindows();
1172 ttRc = tt_message_send( m );
1173 DieFromToolTalkError( UxTopLevel, "tt_message_send", ttRc );
1175 #endif /* __TOOLTALK */
1177 /*****************************************************************************/
1184 /*****************************************************************************/
1186 main(int argc, char *argv[])
1188 /*-----------------------------------------------------------
1190 * The default identifier - mainIface will only be declared
1191 * if the interface function is global and of type swidget.
1192 * To change the identifier to a different name, modify the
1193 * string mainIface in the file "xtmain.dat". If "mainIface"
1194 * is declared, it will be used below where the return value
1195 * of PJ_INTERFACE_FUNCTION_CALL will be assigned to it.
1196 *----------------------------------------------------------*/
1203 char * sessionString;
1208 extern swidget create_AddFiletype();
1209 extern swidget create_FileCharacteristics();
1210 extern swidget create_OpenFile();
1211 extern swidget create_Confirmed();
1212 extern Widget create_ErrorDialog();
1214 Atom xa_WM_SAVE_YOURSELF;
1217 /*---------------------------------
1218 * Interface function declaration
1219 *--------------------------------*/
1220 Widget create_applicationShell1(swidget);
1221 swidget UxParent = NULL;
1224 /*---------------------
1225 * Initialize program
1226 *--------------------*/
1228 _DtEnvControl(DT_ENV_SET);
1229 XtSetLanguageProc(NULL, NULL, NULL);
1230 pszFileToEdit = (char *)NULL;
1231 memset(&sessiondata, 0, sizeof(SessionData));
1232 memset(IconDataList, 0, sizeof(IconDataList));
1234 /********************************************************************/
1235 /* Parse the command line arguments. */
1236 /********************************************************************/
1237 pszExecName = argv[0];
1240 for (i=1; i<argc; i++) {
1241 if ((argv[i][0] == '-') && (argv[i][1] == '?')) {
1242 setlocale(LC_ALL, "");
1243 nlmsg_fd = catopen("dtcreate", NL_CAT_LOCALE);
1245 GETMESSAGE(5, 110, "Usage: dtcreate [<filename>] [-?]"));
1248 if (argv[i][0] == '-') {
1249 if (!strcmp(argv[i], "-s")) {
1251 sessiondata.pszSessionFile = (char *)XtMalloc(strlen(argv[i]) + 1);
1252 strcpy(sessiondata.pszSessionFile, argv[i]);
1253 sessiondata.useSession = True;
1258 pszFileToEdit = (char *)XtMalloc(strlen(argv[i]) + 1);
1259 strcpy(pszFileToEdit, argv[i]);
1266 UxTopLevel = XtAppInitialize(&UxAppContext, CLASS_NAME,
1267 NULL, 0, &argc, argv, NULL, NULL, 0);
1269 nlmsg_fd = catopen("dtcreate", NL_CAT_LOCALE);
1271 UxDisplay = XtDisplay(UxTopLevel);
1272 UxScreen = XDefaultScreen(UxDisplay);
1274 if (sessiondata.useSession) {
1278 /*---------------------
1279 * Determine resolution
1280 *--------------------*/
1281 if (_DtGetDisplayResolution(UxDisplay, UxScreen) == 1) {
1291 /*-------------------------------------------------------
1292 * Insert initialization code for your application here
1293 *------------------------------------------------------*/
1296 printf("display string = '%s'\n", DisplayString(UxDisplay));
1298 ttsession = getenv("TT_SESSION");
1299 if (!ttsession || strlen(ttsession)==0) {
1300 char *ttxsession = tt_X_session(XDisplayString(UxDisplay));
1301 ttRc = tt_default_session_set(ttxsession);
1304 ttMark = tt_mark( );
1306 procId = tt_open( );
1307 ttRc = tt_ptr_error(procId);
1309 GETMESSAGE(13, 2, "Could not connect to ToolTalk:\n%s\nExiting ...");
1310 DieFromToolTalkError( UxTopLevel, errfmt, ttRc );
1313 DieFromToolTalkError( UxTopLevel, "tt_fd", tt_int_error( ttFd ) );
1315 ttRc = tt_ptype_declare( "dtcreate" );
1316 DieFromToolTalkError( UxTopLevel, "tt_ptype_declare", ttRc );
1318 ttRc = tt_session_join( tt_default_session( ));
1319 DieFromToolTalkError( UxTopLevel, "tt_session_join", ttRc );
1321 XtAppAddInput( UxAppContext, ttFd, (XtPointer)XtInputReadMask,
1322 (XtInputCallbackProc)ProcessToolTalkMessage, 0 );
1325 if (!pszFileToEdit) {
1330 /*----------------------------------------------------------------
1331 * Create and popup the first window of the interface. The
1332 * return value can be used in the popdown or destroy functions.
1333 * The Widget return value of PJ_INTERFACE_FUNCTION_CALL will
1334 * be assigned to "mainIface" from PJ_INTERFACE_RETVAL_TYPE.
1335 *---------------------------------------------------------------*/
1337 mainIface = create_applicationShell1(UxParent);
1338 AddFiletype = create_AddFiletype(mainIface);
1339 FileCharacteristics = create_FileCharacteristics(AddFiletype);
1340 OpenFile = create_OpenFile();
1342 UxPopupInterface(mainIface, no_grab);
1343 if (pszFileToEdit) {
1344 if (!OpenDefinitionFile(pszFileToEdit, &AD)) {
1348 XtVaGetValues (CA_WindowTypeArea, XmNheight, &wintypeheight, NULL);
1350 /*------------------------------------------------------------------*/
1351 /* Register for save and restore. */
1352 /*------------------------------------------------------------------*/
1353 xa_WM_SAVE_YOURSELF = XInternAtom(XtDisplay(CreateActionAppShell), "WM_SAVE_YOURSELF", False);
1354 XmAddWMProtocols(CreateActionAppShell, &xa_WM_SAVE_YOURSELF, 1);
1355 XmAddWMProtocolCallback(CreateActionAppShell, xa_WM_SAVE_YOURSELF,
1356 SaveSessionCB, (XtPointer)CreateActionAppShell);
1358 /*------------------------------------------------------------------*/
1359 /* Make a copy of the AD data structure. This will be used later */
1360 /* when the user wants to exit to determine if the latest data has */
1361 /* been saved or not. */
1362 /*------------------------------------------------------------------*/
1363 pMyCopyAD = copyAD(&AD);
1367 ttMark = tt_mark( );
1369 procId = ttdt_open( &ttFd, "dtcreate", "CDE", "1.0", 1 );
1370 ttRc = tt_ptr_error(procId);
1372 GETMESSAGE(13, 2, "Could not connect to ToolTalk:\n%s\nExiting ...");
1373 DieFromToolTalkError( UxTopLevel, errfmt, ttRc );
1376 ttRc = tt_int_error( ttFd );
1377 DieFromToolTalkError( UxTopLevel, "tt_fd", ttRc );
1379 sessionString = tt_default_session();
1380 ttRc = tt_ptr_error( sessionString );
1381 DieFromToolTalkError( UxTopLevel, "tt_default_session", ttRc );
1383 ttPatt = ttdt_session_join( sessionString, ProcessToolTalkMessage,
1384 (Widget) 0, (void *) 0, 1 );
1385 ttRc = tt_ptr_error(ttPatt);
1386 DieFromToolTalkError( UxTopLevel, "ttdt_session_join", ttRc );
1388 XtAppAddInput( UxAppContext, ttFd, (XtPointer)XtInputReadMask,
1389 tttk_Xt_input_handler, 0 );
1392 /*-----------------------
1393 * Enter the event loop
1394 *----------------------*/
1396 XtAppMainLoop (UxAppContext);
1399 ttdt_session_quit(0, 0, 1);
1401 tt_release( ttMark );
1402 RemoveTmpIconFiles();