1 /*$XConsortium: SaveRestore.c /main/5 1996/03/25 00:53:19 pascale $ */
2 /************************************<+>*************************************
3 ****************************************************************************
9 ** Description: Controls the Dtstyle Save/Restore functionality
12 ****************************************************************************
13 ************************************<+>*************************************/
15 * (c) Copyright 1996 Digital Equipment Corporation.
16 * (c) Copyright 1990, 1996 Hewlett-Packard Company.
17 * (c) Copyright 1996 International Business Machines Corp.
18 * (c) Copyright 1996 Sun Microsystems, Inc.
19 * (c) Copyright 1996 Novell, Inc.
20 * (c) Copyright 1996 FUJITSU LIMITED.
21 * (c) Copyright 1996 Hitachi.
24 /*+++++++++++++++++++++++++++++++++++++++*/
26 /*+++++++++++++++++++++++++++++++++++++++*/
35 #include <Xm/LabelG.h>
36 #include <Xm/PushBG.h>
39 #include <Dt/DialogBox.h>
41 #include <Dt/HourGlass.h>
42 #include <Dt/UserMsg.h>
46 /*+++++++++++++++++++++++++++++++++++++++*/
47 /* include extern functions */
48 /*+++++++++++++++++++++++++++++++++++++++*/
49 #include "SaveRestore.h"
51 /*+++++++++++++++++++++++++++++++++++++++*/
53 /*+++++++++++++++++++++++++++++++++++++++*/
54 #define MSG1 ((char *)GETMESSAGE(10, 1, "Check file permissions."))
55 #define MSG2 ((char *)GETMESSAGE(10, 3, "%s is the file that would have been used to save your session\n"))
58 /************************************************************************
61 * Creates a file as a resource data base, and writes out all
62 * info needed to save our current state. This info will be used
63 * later by restoreSession to start up the help system in the exact
64 * state in which we saved the session.
66 ************************************************************************/
70 XtPointer client_data,
73 char *longpath, *name;
75 char *xa_CommandStr[3];
76 unsigned char *data = NULL;
80 char *noCommands = NULL;
83 /* get the root window property of SaveMode */
84 GetSessionSaveMode(&data );
86 /* if the property is "home" don't save dtstyle */
87 if(strcmp((char *)data, "home") == 0)
89 #ifdef _SUN_OS /* Sun doesn't like "NULL" when expecting "char **" */
90 XSetCommand(style.display, XtWindow(w), &noCommands, 0);
92 XSetCommand(style.display, XtWindow(w), NULL, 0);
97 /* Xt may not pass a widget as advertised */
99 DtSessionSavePath(XtParent(w), &longpath, &name);
101 DtSessionSavePath(w, &longpath, &name);
103 /* Create the session file */
104 if ((fd = creat (longpath, S_IRUSR | S_IRGRP | S_IWUSR | S_IWGRP)) == -1)
106 tmpStr = (char *)XtMalloc(strlen(MSG2) + strlen(longpath)+ 1);
107 sprintf(tmpStr, MSG2, longpath);
108 _DtSimpleErrnoError(progName,DtError, MSG1, tmpStr, NULL);
110 XtFree ((char *)longpath);
111 XtFree ((char *)name);
115 /*write out each needed resource*/
131 /*If this is a session manager requested saveYrSlf, need to put dialogs in*/
132 /*recoverable state, and make them consistent with server (etc) state.*/
133 /*Have to do it before exit so SM gets corrected server state.*/
137 xa_CommandStr[n] = style.execName; n++;
138 xa_CommandStr[n] = "-session"; n++;
139 xa_CommandStr[n] = name; n++;
141 XSetCommand(style.display, XtWindow(w), xa_CommandStr, n);
142 XtFree ((char *)longpath);
143 XtFree ((char *)name);
145 /* Don't exit yet, SM needs time to get the new commandStr.*/
149 /************************************************************************
152 * Open the file as a resource data base, and use the data to
153 * set the dialog position and (optionally) size.
155 ************************************************************************/
167 status = DtSessionRestorePath(shell, &longpath, name);
171 /* Open the file as a resource database */
172 if ((db = XrmGetFileDatabase (longpath)) == NULL) {
173 tmpStr = (char *)XtMalloc(strlen(MSG2) + strlen(longpath)+ 1);
174 sprintf(tmpStr, MSG2, longpath);
175 _DtSimpleErrnoError(progName, DtError, MSG1, tmpStr, NULL);
181 restoreMain(shell, db); /* Must happen first */
183 /* Now, Restore the dialogs */
184 restoreColor(shell, db);
185 restoreColorEdit(shell, db);
186 restoreFonts(shell, db);
187 restoreBackdrop(shell, db);
188 restoreKeybd(shell, db);
189 restoreMouse(shell, db);
190 restoreAudio(shell, db);
191 restoreScreen(shell, db);
192 restoreDtwm(shell, db);
193 restoreStartup(shell, db);
194 restoreI18n(shell, db);
196 XrmDestroyDatabase(db);