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 errmsg = XtMalloc(strlen(errfmt) + strlen(statmsg) + 2);
552 sprintf(errmsg, errfmt, statmsg);
554 xms_ok = GETXMSTRING(13, 3, "OK");
555 xms_errmsg = XmStringCreateLocalized(errmsg);
556 xms_title = GETXMSTRING(13, 1, "Create Action - Error");
559 XtSetArg(args[n], XmNautoUnmanage, False); n++;
560 XtSetArg(args[n], XmNokLabelString, xms_ok); n++;
561 XtSetArg(args[n], XmNdialogTitle, xms_title); n++;
562 XtSetArg(args[n], XmNmessageString, xms_errmsg); n++;
563 XtSetArg(args[n], XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL); n++;
565 dialog = XmCreateErrorDialog(parent, "IconEditorError", args, n);
566 XtAddCallback(dialog, XmNokCallback, ExitCB, (XtPointer) status);
567 XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_CANCEL_BUTTON));
568 XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_HELP_BUTTON));
571 * Disable the frame menu from dialog since we don't want the user
572 * to be able to close dialogs with the frame menu
574 dialogShell = XtParent(dialog);
576 XtSetArg(args[n], XmNmwmDecorations, MWM_DECOR_ALL | MWM_DECOR_MENU); n++;
577 XtSetValues(dialogShell, args, n);
578 XtManageChild(dialog);
579 XtRealizeWidget(dialogShell);
581 _DtSimpleError(CLASS_NAME, DtFatalError, NULL, errmsg);
584 XmStringFree(xms_ok);
585 XmStringFree(xms_errmsg);
586 XmStringFree(xms_title);
589 XtAppProcessEvent(XtWidgetToApplicationContext(dialog), XtIMAll);
592 /*****************************************************************************/
594 /* ProcessToolTalkMessage */
597 /*****************************************************************************/
598 Tt_message ProcessToolTalkMessage(Tt_message msg,
600 Tt_message contract )
603 int ttMark = tt_mark();
605 if( 0 == strcmp( tt_message_op( msg ), "Quit" ) ) {
607 * Do the necessary cleanup, call tt_message_reply(),
608 * and exit. Since this is not yet fully implemented, just
609 * call tt_message_reply and exit.
613 printf("ProcessTTMsg: Quit\n"); /* debug */
615 tt_message_reply(msg);
616 RemoveTmpIconFiles();
620 * Any other desktop message ops that one would want
621 * to implement would go here. If
622 * a mapped, realized, top-level widget were passed into
623 * ttdt_session_join instead of (Widget) 0, then the
624 * messages that interact with the X environment
625 * Get_Geometry, etc.) would be handled automatically.
629 printf("ProcessTTMsg: Other\n");
633 tt_release( ttMark );
635 return (Tt_message) 0;
638 /*****************************************************************************/
639 /* NAME: IconEdit_tt_handler */
640 /* DESCRIPTION: Handler for Tooltalk conversation about editing icon. */
643 /* CREATION: 02/21/94 */
645 /*****************************************************************************/
646 Tt_callback_action IconEdit_tt_handler( Tt_message m, Tt_pattern p )
653 char *msgPtr, *fmtPtr, *errPtr;
654 char tmpbuf[MAXBUFSIZE];
660 Boolean bIsNewFile = False;
662 char *tmp = (char *)NULL;
663 char *tmp1 = (char *)NULL;
668 op = tt_message_op(m);
669 /************************************************************************/
670 /* Edit message... */
671 /************************************************************************/
672 if (!strcmp(op, "Edit")) {
674 printf("IconEdit_tt_handler: Edit tt msg = %p\n", m); /* debug */
676 mstate = tt_message_state( m );
677 switch ((int)mstate) {
679 TurnOffHourGlassAllWindows();
681 /* INTERNATIONALIZE */
682 msgPtr = "Failed ToolTalk msg";
684 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
686 sprintf(errPtr, fmtPtr, msgPtr, m);
687 display_error_message(CreateActionAppShell, errPtr);
690 printf( "Failed ToolTalk msg = %p\n", m); /* debug */
692 tt_message_destroy( m );
695 TurnOffHourGlassAllWindows();
697 printf( "Handled ToolTalk msg = %p\n", m); /* debug */
699 tt_message_destroy( m );
703 printf( "Started ToolTalk msg = %p\n", m); /* debug */
708 printf("IconEdit_tt_handler: Saved tt msg = %p\n", m); /* debug */
710 msgID = tt_message_arg_val(m, 1);
711 pIconData = GetIconDataFromMsgID(msgID);
713 printf("msgID = '%s'\n", msgID); /* debug */
716 /*********************************************************************/
717 /* Saved message... */
718 /*********************************************************************/
719 if ( (pIconData) && (!strcmp(op, "Saved")) ) {
720 tt_message_arg_bval(m, 0, (unsigned char **)&ttbuf, &blen);
722 if ( (pIconData->pmMsgID) && (!strcmp(pIconData->pmMsgID, msgID)) ) {
723 if (pIconData->pmDirtyBit) {
724 tmpIconFile = pIconData->pmFileName;
726 tmpnam(pIconData->pmFileName);
728 tmpIconFile = pIconData->pmFileName;
731 if (pIconData->bmDirtyBit) {
732 tmpIconFile = pIconData->bmFileName;
734 tmpnam(pIconData->bmFileName);
736 tmpIconFile = pIconData->bmFileName;
740 tmpfd = open(tmpIconFile, O_CREAT | O_WRONLY | O_NDELAY, 0666);
742 tmpfd = open(tmpIconFile, O_TRUNC | O_WRONLY | O_NDELAY, 0666);
745 msgPtr = GETMESSAGE(5, 60, "Could not open the following file:");
747 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
748 strlen(tmpIconFile) + 1) * sizeof(char));
749 sprintf(errPtr, fmtPtr, msgPtr, tmpIconFile);
750 display_error_message(XtParent(pIconData->wid), errPtr);
752 tt_release( ttMark );
756 /*******************************************************************/
757 /* Determine if this is a pixmap or bitmap. If it is a pixmap, */
758 /* handle as a one file buffer. If a bitmap, then it may be */
759 /* double buffered including the mask. */
760 /*******************************************************************/
762 /*******************************************************************/
763 /* Check for Pixmap first. */
764 /*******************************************************************/
765 if ( (ttbuf) && (!strncmp(ttbuf, "/* XPM */", 9)) ) {
767 printf("This is a XPM file\n"); /* debug */
769 tmp = strstr(ttbuf, "};");
771 tmp += 2; /* Go one char past the ";" */
773 tmplen = blen - strlen(tmp) + 1;
774 printf("Amro tmplen = %d\n", tmplen);
776 tmplen = (char *)tmp - (char *)ttbuf;
778 printf("Troy tmplen = %d\n", tmplen); /* debug */
783 if ((wlen = write(tmpfd, ttbuf, tmplen)) == tmplen) {
784 if (tmpfd > -1) close(tmpfd);
786 /* INTERNATIONALIZE */
787 msgPtr = "Could not write to the following file:";
789 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
790 strlen(tmpIconFile) + 1) * sizeof(char));
791 sprintf(errPtr, fmtPtr, msgPtr, tmpIconFile);
792 display_error_message(XtParent(pIconData->wid), errPtr);
794 tt_release( ttMark );
795 if (tmpfd > -1) close(tmpfd);
799 /*******************************************************************/
800 /* Must be a Bitmap. */
801 /*******************************************************************/
804 printf("This is a XBM file\n"); /* debug */
805 printf("ttbuffer size = %d\n", blen); /* debug */
807 /****************************************************************/
808 /* Determine size of first bitmap. */
809 /****************************************************************/
810 tmp = strstr(ttbuf, "};");
812 tmp += 2; /* Go one char past the ";" */
814 tmplen = blen - strlen(tmp) + 1;
815 printf("Amro tmplen = %d\n", tmplen);
817 tmplen = (char *)tmp - (char *)ttbuf;
819 printf("Troy tmplen = %d\n", tmplen); /* debug */
825 printf("File 1 size = %d\n", tmplen); /* debug */
828 /****************************************************************/
829 /* Write out first bitmap file. */
830 /****************************************************************/
832 printf("Writing first bitmap file\n"); /* debug */
834 if ((wlen = write(tmpfd, ttbuf, tmplen)) == tmplen) {
835 if (tmpfd > -1) close(tmpfd);
837 /* INTERNATIONALIZE */
838 msgPtr = "Could not write to the following file:";
840 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
841 strlen(tmpIconFile) + 1) * sizeof(char));
842 sprintf(errPtr, fmtPtr, msgPtr, tmpIconFile);
843 display_error_message(XtParent(pIconData->wid), errPtr);
845 tt_release( ttMark );
846 if (tmpfd > -1) close(tmpfd);
850 /****************************************************************/
851 /* Now determine if there is a second bitmap and its size. */
852 /****************************************************************/
854 tmp1 = strstr(tmp, "};");
856 sprintf(tmpbuf, "%s_m", tmpIconFile);
858 tmp1 += 2; /* Go one char past the ";" */
860 printf("Mask file name = '%s'\n", tmpbuf); /* debug */
862 tmpfd = open(tmpbuf, O_CREAT | O_WRONLY | O_NDELAY, 0666);
865 GETMESSAGE(5, 60, "Could not open the following file:");
867 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
868 strlen(tmpbuf) + 1) * sizeof(char));
869 sprintf(errPtr, fmtPtr, msgPtr, tmpbuf);
870 display_error_message(XtParent(pIconData->wid), errPtr);
872 tt_release( ttMark );
877 printf("writing mask file \n");
880 tmplen = strlen(tmp);
881 printf("Amro tmplen = %d\n", tmplen);
883 tmplen = (char *)tmp1 - (char *)tmp;
885 printf("Troy tmplen = %d\n", tmplen); /* debug */
887 if ((wlen = write(tmpfd, tmp, tmplen)) == tmplen) {
888 if (tmpfd > -1) close(tmpfd);
890 /* INTERNATIONALIZE */
891 msgPtr = "Could not write to the following file:";
893 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
894 strlen(tmpbuf) + 1) * sizeof(char));
895 sprintf(errPtr, fmtPtr, msgPtr, tmpbuf);
896 display_error_message(XtParent(pIconData->wid), errPtr);
898 tt_release( ttMark );
899 if (tmpfd > -1) close(tmpfd);
903 /****************************************************************/
904 /* Must not have a mask, so lets clean up any old mask file. */
905 /****************************************************************/
908 printf("Remove maskFile = %s\n", tmpbuf); /* debug */
914 /****************************************************************/
915 /* Set the icon gadget with new icon, and flag the dirty bit. */
916 /****************************************************************/
917 if ( ( (pIconData->pmMsgID) &&
918 (!strcmp(pIconData->pmMsgID, msgID)) &&
921 ( (pIconData->bmMsgID) &&
922 (!strcmp(pIconData->bmMsgID, msgID)) &&
923 (!bShowPixmaps) ) ) {
924 XmeFlushIconFileCache(NULL);
926 printf("Change icon image for widget = %p\n", pIconData->wid); /* debug */
928 SET_ICONGADGET_ICON(pIconData->wid, tmpIconFile);
930 if ((pIconData->pmMsgID) && (!strcmp(pIconData->pmMsgID, msgID))) {
931 pIconData->pmDirtyBit = True;
933 pIconData->bmDirtyBit = True;
936 printf("**********tmp file name = %s\n", tmpIconFile); /* debug */
940 tt_release( ttMark );
941 return( TT_CALLBACK_PROCESSED );
944 /*****************************************************************************/
945 /* NAME: UxDoEditPixmap */
946 /* DESCRIPTION: Loads the icon editor. */
947 /* PARAMETERS: none */
949 /* CREATION: 02/11/94 */
951 /*****************************************************************************/
952 void UxDoEditPixmap(Widget wid, char *fname)
954 Tt_message m; /* ToolTalk message */
955 Tt_pattern p; /* ToolTalk dynamic pattern */
956 Tt_status ttRc; /* ToolTalk status */
961 int lenFile1 = 0, rlenFile1 = 0;
962 int lenFile2 = 0, rlenFile2 = 0;
968 unsigned char *buffer;
971 char tmpbuf[MAXBUFSIZE];
975 char *mname = (char *)NULL;
976 char *type_name, *size_name;
980 if (fname) printf("Edit filename: '%s'\n", fname); /* debug */
985 /*********************************************************************/
987 /*********************************************************************/
988 m = tt_prequest_create( TT_SESSION, "Edit" );
989 msgID = tt_message_id(m);
990 pIconData = GetIconDataFromWid(wid);
992 ppMsgID = &(pIconData->pmMsgID);
994 ppMsgID = &(pIconData->bmMsgID);
999 if (msgID && strlen(msgID)) {
1000 *ppMsgID = (char *)malloc(strlen(msgID) + 1);
1001 strcpy(*ppMsgID, msgID);
1005 printf("msgID = '%s'\n", msgID); /* debug */
1006 printf("Create Edit msg = %p\n", m); /* debug */
1009 /*********************************************************************/
1010 /* Add arguments to message */
1011 /*********************************************************************/
1013 fd1 = open(fname, O_RDONLY);
1015 /* Error opening icon file! */
1016 msgPtr = GETMESSAGE(5, 60, "Could not open the following file:");
1018 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
1019 strlen(fname) + 1) * sizeof(char));
1020 sprintf(errPtr, fmtPtr, msgPtr, fname);
1021 display_error_message(XtParent(wid), errPtr);
1025 /***************************************/
1026 /* Find out how big a buffer is needed */
1027 /***************************************/
1028 lenFile1 = lseek(fd1, 0, SEEK_END);
1029 (void) lseek(fd1, 0, SEEK_SET);
1031 /*************************************************************/
1032 /* Read first few bytes to determine what kind of file it is */
1033 /*************************************************************/
1034 read(fd1, tmpbuf, 10);
1035 (void) lseek(fd1, 0, SEEK_SET);
1037 /******************************************************************/
1038 /* If the file is a bitmap, then check for its mask file and add. */
1039 /******************************************************************/
1040 if ( strncmp(tmpbuf, "/* XPM */", 9) ) {
1042 mname = CreateMaskName(fname);
1044 /***************************************************************/
1045 /* Check if mask file exists. */
1046 /***************************************************************/
1047 if ((mname) && (check_file_exists(mname))) {
1048 fd2 = open(mname, O_RDONLY);
1050 /* Error opening icon file! */
1052 GETMESSAGE(5, 60, "Could not open the following file:");
1054 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
1055 strlen(mname) + 1) * sizeof(char));
1056 sprintf(errPtr, fmtPtr, msgPtr, mname);
1057 display_error_message(XtParent(wid), errPtr);
1062 /***************************************/
1063 /* Find out how big a buffer is needed */
1064 /***************************************/
1065 lenFile2 = lseek(fd2, 0, SEEK_END);
1066 (void) lseek(fd2, 0, SEEK_SET);
1070 /******************************************************************/
1071 /* Create 1 big buffer */
1072 /******************************************************************/
1074 printf("Size of file 1 = %d\n", lenFile1); /* debug */
1075 printf("Size of file 2 = %d\n", lenFile2); /* debug */
1077 buffer = (unsigned char *)XtMalloc((Cardinal)(lenFile1 + lenFile2 + 1));
1078 memset(buffer, 0, (lenFile1 + lenFile2 + 1));
1080 /***************************************/
1081 /* Read file1 into buffer. */
1082 /***************************************/
1083 if ((rlenFile1 = read(fd1, buffer, lenFile1)) != lenFile1) {
1084 /* didn't read whole file! */
1086 /* INTERNATIONALIZE */
1087 msgPtr = "Could not read the entire file:";
1089 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
1090 strlen(fname) + 1) * sizeof(char));
1091 sprintf(errPtr, fmtPtr, msgPtr, fname);
1092 display_error_message(XtParent(wid), errPtr);
1094 if (mname) XtFree(mname);
1095 XtFree((char *) buffer);
1100 printf("buffer = %p\n", buffer);
1102 /*ptr = (char *)&(buffer[lenFile1 + 1]);*/
1103 ptr = (char *)&(buffer[lenFile1]);
1105 printf("ptr = %p\n", ptr);
1107 if ((rlenFile2 = read(fd2, ptr, lenFile2)) != lenFile2) {
1108 /* didn't read whole file! */
1110 /* INTERNATIONALIZE */
1111 msgPtr = "Could not read the entire file:";
1113 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
1114 strlen(fname) + 1) * sizeof(char));
1115 sprintf(errPtr, fmtPtr, msgPtr, mname);
1116 display_error_message(XtParent(wid), errPtr);
1118 XtFree((char *) buffer);
1119 if (mname) XtFree(mname);
1123 if (fd1 > -1) close(fd1);
1124 if (fd2 > -1) close(fd2);
1127 printf("final buffer = '%s'\n", buffer); /* debug */
1128 printf("Buffer = '%s'\n", buffer); /* debug */
1130 tt_message_barg_add( m, TT_INOUT, "XPM", buffer, lenFile1 + lenFile2 + 1);
1131 if (mname) XtFree(mname);
1132 XtFree((char *) buffer);
1136 tt_message_barg_add( m, TT_INOUT, "XPM", (const unsigned char *)NULL, 0);
1138 tt_message_arg_add(m, TT_IN, "messageID", msgID);
1140 /******************************************************************/
1141 /* Create a pattern and add a callback to get notifications */
1142 /* of periodic saves */
1143 /******************************************************************/
1144 p = tt_pattern_create();
1145 tt_pattern_category_set(p, TT_OBSERVE);
1146 tt_pattern_scope_add(p, TT_SESSION);
1147 tt_pattern_session_add(p, tt_default_session());
1148 tt_pattern_address_add(p, TT_HANDLER);
1149 tt_pattern_op_add(p, "Saved");
1150 tt_pattern_callback_add(p, IconEdit_tt_handler);
1151 tt_pattern_register(p);
1153 /******************************************************************/
1154 /* Add callback to notify when change complete */
1155 /******************************************************************/
1156 tt_message_callback_add( m, IconEdit_tt_handler );
1158 /******************************************************************/
1160 /******************************************************************/
1161 TurnOnHourGlassAllWindows();
1162 ttRc = tt_message_send( m );
1163 DieFromToolTalkError( UxTopLevel, "tt_message_send", ttRc );
1165 #endif /* __TOOLTALK */
1167 /*****************************************************************************/
1174 /*****************************************************************************/
1175 main(int argc, char *argv[])
1177 /*-----------------------------------------------------------
1179 * The default identifier - mainIface will only be declared
1180 * if the interface function is global and of type swidget.
1181 * To change the identifier to a different name, modify the
1182 * string mainIface in the file "xtmain.dat". If "mainIface"
1183 * is declared, it will be used below where the return value
1184 * of PJ_INTERFACE_FUNCTION_CALL will be assigned to it.
1185 *----------------------------------------------------------*/
1192 char * sessionString;
1197 extern swidget create_AddFiletype();
1198 extern swidget create_FileCharacteristics();
1199 extern swidget create_OpenFile();
1200 extern swidget create_Confirmed();
1201 extern Widget create_ErrorDialog();
1203 Atom xa_WM_SAVE_YOURSELF;
1206 /*---------------------------------
1207 * Interface function declaration
1208 *--------------------------------*/
1209 Widget create_applicationShell1(swidget);
1210 swidget UxParent = NULL;
1213 /*---------------------
1214 * Initialize program
1215 *--------------------*/
1217 _DtEnvControl(DT_ENV_SET);
1218 XtSetLanguageProc(NULL, NULL, NULL);
1219 pszFileToEdit = (char *)NULL;
1220 memset(&sessiondata, 0, sizeof(SessionData));
1221 memset(IconDataList, 0, sizeof(IconDataList));
1223 /********************************************************************/
1224 /* Parse the command line arguments. */
1225 /********************************************************************/
1226 pszExecName = argv[0];
1229 for (i=1; i<argc; i++) {
1230 if ((argv[i][0] == '-') && (argv[i][1] == '?')) {
1231 setlocale(LC_ALL, "");
1232 nlmsg_fd = catopen("dtcreate", NL_CAT_LOCALE);
1234 GETMESSAGE(5, 110, "Usage: dtcreate [<filename>] [-?]"));
1237 if (argv[i][0] == '-') {
1238 if (!strcmp(argv[i], "-s")) {
1240 sessiondata.pszSessionFile = (char *)XtMalloc(strlen(argv[i]) + 1);
1241 strcpy(sessiondata.pszSessionFile, argv[i]);
1242 sessiondata.useSession = True;
1247 pszFileToEdit = (char *)XtMalloc(strlen(argv[i]) + 1);
1248 strcpy(pszFileToEdit, argv[i]);
1255 UxTopLevel = XtAppInitialize(&UxAppContext, CLASS_NAME,
1256 NULL, 0, &argc, argv, NULL, NULL, 0);
1258 nlmsg_fd = catopen("dtcreate", NL_CAT_LOCALE);
1260 UxDisplay = XtDisplay(UxTopLevel);
1261 UxScreen = XDefaultScreen(UxDisplay);
1263 if (sessiondata.useSession) {
1267 /*---------------------
1268 * Determine resolution
1269 *--------------------*/
1270 if (_DtGetDisplayResolution(UxDisplay, UxScreen) == 1) {
1280 /*-------------------------------------------------------
1281 * Insert initialization code for your application here
1282 *------------------------------------------------------*/
1285 printf("display string = '%s'\n", DisplayString(UxDisplay));
1287 ttsession = getenv("TT_SESSION");
1288 if (!ttsession || strlen(ttsession)==0) {
1289 char *ttxsession = tt_X_session(XDisplayString(UxDisplay));
1290 ttRc = tt_default_session_set(ttxsession);
1293 ttMark = tt_mark( );
1295 procId = tt_open( );
1296 ttRc = tt_ptr_error(procId);
1298 GETMESSAGE(13, 2, "Could not connect to ToolTalk:\n%s\nExiting ...");
1299 DieFromToolTalkError( UxTopLevel, errfmt, ttRc );
1302 DieFromToolTalkError( UxTopLevel, "tt_fd", tt_int_error( ttFd ) );
1304 ttRc = tt_ptype_declare( "dtcreate" );
1305 DieFromToolTalkError( UxTopLevel, "tt_ptype_declare", ttRc );
1307 ttRc = tt_session_join( tt_default_session( ));
1308 DieFromToolTalkError( UxTopLevel, "tt_session_join", ttRc );
1310 XtAppAddInput( UxAppContext, ttFd, (XtPointer)XtInputReadMask,
1311 (XtInputCallbackProc)ProcessToolTalkMessage, 0 );
1314 if (!pszFileToEdit) {
1319 /*----------------------------------------------------------------
1320 * Create and popup the first window of the interface. The
1321 * return value can be used in the popdown or destroy functions.
1322 * The Widget return value of PJ_INTERFACE_FUNCTION_CALL will
1323 * be assigned to "mainIface" from PJ_INTERFACE_RETVAL_TYPE.
1324 *---------------------------------------------------------------*/
1326 mainIface = create_applicationShell1(UxParent);
1327 AddFiletype = create_AddFiletype(mainIface);
1328 FileCharacteristics = create_FileCharacteristics(AddFiletype);
1329 OpenFile = create_OpenFile();
1331 UxPopupInterface(mainIface, no_grab);
1332 if (pszFileToEdit) {
1333 if (!OpenDefinitionFile(pszFileToEdit, &AD)) {
1337 XtVaGetValues (CA_WindowTypeArea, XmNheight, &wintypeheight, NULL);
1339 /*------------------------------------------------------------------*/
1340 /* Register for save and restore. */
1341 /*------------------------------------------------------------------*/
1342 xa_WM_SAVE_YOURSELF = XInternAtom(XtDisplay(CreateActionAppShell), "WM_SAVE_YOURSELF", False);
1343 XmAddWMProtocols(CreateActionAppShell, &xa_WM_SAVE_YOURSELF, 1);
1344 XmAddWMProtocolCallback(CreateActionAppShell, xa_WM_SAVE_YOURSELF,
1345 SaveSessionCB, (XtPointer)CreateActionAppShell);
1347 /*------------------------------------------------------------------*/
1348 /* Make a copy of the AD data structure. This will be used later */
1349 /* when the user wants to exit to determine if the latest data has */
1350 /* been saved or not. */
1351 /*------------------------------------------------------------------*/
1352 pMyCopyAD = copyAD(&AD);
1356 ttMark = tt_mark( );
1358 procId = ttdt_open( &ttFd, "dtcreate", "CDE", "1.0", 1 );
1359 ttRc = tt_ptr_error(procId);
1361 GETMESSAGE(13, 2, "Could not connect to ToolTalk:\n%s\nExiting ...");
1362 DieFromToolTalkError( UxTopLevel, errfmt, ttRc );
1365 ttRc = tt_int_error( ttFd );
1366 DieFromToolTalkError( UxTopLevel, "tt_fd", ttRc );
1368 sessionString = tt_default_session();
1369 ttRc = tt_ptr_error( sessionString );
1370 DieFromToolTalkError( UxTopLevel, "tt_default_session", ttRc );
1372 ttPatt = ttdt_session_join( sessionString, ProcessToolTalkMessage,
1373 (Widget) 0, (void *) 0, 1 );
1374 ttRc = tt_ptr_error(ttPatt);
1375 DieFromToolTalkError( UxTopLevel, "ttdt_session_join", ttRc );
1377 XtAppAddInput( UxAppContext, ttFd, (XtPointer)XtInputReadMask,
1378 tttk_Xt_input_handler, 0 );
1381 /*-----------------------
1382 * Enter the event loop
1383 *----------------------*/
1385 XtAppMainLoop (UxAppContext);
1388 ttdt_session_quit(0, 0, 1);
1390 tt_release( ttMark );
1391 RemoveTmpIconFiles();