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 /************************************<+>*************************************
24 ****************************************************************************
30 ** Description: Controls the Dtstyle Startup dialog
33 ** (c) Copyright Hewlett-Packard Company, 1990.
37 ****************************************************************************
38 ************************************<+>*************************************/
39 /*$XConsortium: Startup.c /main/6 1995/12/22 15:23:38 barstow $*/
40 /* +++++++++++++++++++++++++++++++++++++++*/
42 /* +++++++++++++++++++++++++++++++++++++++*/
45 #include <Xm/MwmUtil.h>
49 #include <Xm/DialogS.h>
51 #include <Xm/MessageB.h>
52 #include <Xm/PushBG.h>
53 #include <Xm/RowColumn.h>
55 #include <Xm/LabelG.h>
56 #include <Xm/ToggleBG.h>
57 #include <Xm/VendorSEP.h>
59 #include <Dt/DialogBox.h>
61 #include <Dt/TitleBox.h>
63 #include <Dt/Message.h>
64 #include <Dt/HourGlass.h>
68 #include "SaveRestore.h"
71 /*+++++++++++++++++++++++++++++++++++++++*/
72 /* Internal Functions */
73 /*+++++++++++++++++++++++++++++++++++++++*/
76 static void GetStartupValues( void ) ;
77 static Widget BuildStartup( Widget shell) ;
78 static void MapStartup(
80 XtPointer client_data,
81 XtPointer call_data) ;
84 XtPointer client_data,
85 XtPointer call_data) ;
86 static void SetCurrentCB(
88 XtPointer client_data,
89 XmToggleButtonCallbackStruct *call_data) ;
90 static void SetHomeCB(
92 XtPointer client_data,
93 XmToggleButtonCallbackStruct *call_data) ;
94 static void SetConfirmCB(
96 XtPointer client_data,
97 XmToggleButtonCallbackStruct *call_data) ;
98 static void SetHomeSession(
100 XtPointer client_data,
101 XtPointer call_data) ;
102 static void SaveHomeOk(
104 XtPointer client_data,
105 XtPointer call_data) ;
106 static void ButtonCB(
108 XtPointer client_data,
109 XtPointer call_data) ;
112 /*+++++++++++++++++++++++++++++++++++++++*/
113 /* Internal Variables */
114 /*+++++++++++++++++++++++++++++++++++++++*/
126 static Startup startup;
129 static saveRestore save = {FALSE, 0, };
132 /*+++++++++++++++++++++++++++++++++++++++*/
133 /* popup_startupBB */
134 /*+++++++++++++++++++++++++++++++++++++++*/
140 if (style.startupDialog == NULL)
144 if (style.smState.smCompatMode)
146 InfoDialog(((char *)GETMESSAGE(7, 13,
147 "This session was started from an X Window System\n\
148 startup script. Startup settings are not valid,\n\
149 since the session cannot be restored.")),
150 style.startupDialog ? style.startupDialog : style.shell, False);
155 _DtTurnOnHourGlass(shell);
158 XtManageChild(style.startupDialog);
159 _DtTurnOffHourGlass(shell);
162 else /* SM not running - post error dialog */
164 InfoDialog(((char *)GETMESSAGE(7, 15,
165 "The Session Manager is not running.\n\
166 Startup settings are not valid.")),
167 style.startupDialog ? style.startupDialog : style.shell, False);
174 XtManageChild(style.startupDialog);
175 raiseWindow(XtWindow(XtParent(style.startupDialog)));
179 /*++++++++++++++++++++++++++++++++++++++++*/
180 /* Get startup values ... used for cancel */
181 /*++++++++++++++++++++++++++++++++++++++++*/
183 GetStartupValues( void )
185 startup.origStartState = style.smState.smStartState;
186 startup.origConfirmMode = style.smState.smConfirmMode;
190 /*++++++++++++++++++++++++++++++++++++++++*/
191 /* build__startupBB */
192 /*++++++++++++++++++++++++++++++++++++++++*/
199 XmString button_string[NUM_LABELS];
203 Widget widget_list[5],
210 /* Set up DialogBoxDialog button labels */
211 button_string[0] = CMPSTR((String) _DtOkString);
212 button_string[1] = CMPSTR((String) _DtCancelString);
213 button_string[2] = CMPSTR((String) _DtHelpString);
215 /* Create toplevel DialogBox */
217 * Note that save.poscnt has been initialized elsewhere.
218 * save.posArgs may contain information from restoreStartup().*/
220 XtSetArg(save.posArgs[save.poscnt], XmNbuttonCount, NUM_LABELS);
222 XtSetArg(save.posArgs[save.poscnt], XmNbuttonLabelStrings, button_string);
224 XtSetArg(save.posArgs[save.poscnt], XmNdefaultPosition, False);
226 style.startupDialog =
227 __DtCreateDialogBoxDialog(shell, "startupDlg", save.posArgs, save.poscnt);
228 XtAddCallback(style.startupDialog, XmNcallback, ButtonCB, NULL);
229 XtAddCallback(style.startupDialog, XmNhelpCallback,
230 (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_STARTUP_DIALOG);
232 XmStringFree(button_string[0]);
233 XmStringFree(button_string[1]);
234 XmStringFree(button_string[2]);
236 widget_list[0] = _DtDialogBoxGetButton(style.startupDialog,2);
238 XtSetArg(args[n], XmNautoUnmanage, False); n++;
239 XtSetArg(args[n], XmNcancelButton, widget_list[0]); n++;
240 XtSetValues (style.startupDialog, args, n);
243 XtSetArg(args[n], XmNtitle, ((char *)GETMESSAGE(7, 14, "Style Manager - Startup"))); n++;
244 XtSetArg(args[n], XmNuseAsyncGeometry, True); n++;
245 XtSetArg(args[n], XmNmwmFunctions, DIALOG_MWM_FUNC ); n++;
246 XtSetValues (XtParent(style.startupDialog), args, n);
249 XtSetArg(args[n], XmNhorizontalSpacing, style.horizontalSpacing); n++;
250 XtSetArg(args[n], XmNverticalSpacing, style.verticalSpacing); n++;
251 XtSetArg(args[n], XmNallowOverlap, False); n++;
252 XtSetArg(args[n], XmNchildType, XmWORK_AREA); n++;
253 startup.startupForm = XmCreateForm(style.startupDialog, "startupForm", args, n);
256 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
257 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
258 XtSetArg(args[n], XmNfillMode, XmFILL_SELF); n++;
259 XtSetArg(args[n], XmNbehavior, XmICON_LABEL); n++;
260 XtSetArg(args[n], XmNpixmapForeground, style.secBSCol); n++;
261 XtSetArg(args[n], XmNpixmapBackground, style.secTSCol); n++;
262 XtSetArg(args[n], XmNstring, NULL); n++;
263 XtSetArg(args[n], XmNshadowThickness, 0); n++;
264 XtSetArg(args[n], XmNimageName, STARTUP_ICON); n++;
265 XtSetArg(args[n], XmNtraversalOn, False); n++;
266 widget_list[count++] =
267 _DtCreateIcon(startup.startupForm, "startupPict", args, n);
269 if (style.smState.smDisplaySpecific)
274 pch1 = (char *)GETMESSAGE(7, 16, "Display-specific session:");
275 pch2 = XtMalloc(strlen (pch1) +
276 strlen (XDisplayName (getenv("DISPLAY"))) + 3);
278 (void) sprintf(pch2, "%s\n%s", pch1, XDisplayName (getenv("DISPLAY")));
281 string = CMPSTR(pch2);
282 XtSetArg(args[n], XmNleftWidget, widget_list[count-1]); n++;
283 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
284 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
285 XtSetArg(args[n], XmNmarginLeft, 80); n++;
286 XtSetArg(args[n], XmNlabelString, string); n++;
287 widget_list[count++] =
288 XmCreateLabelGadget(startup.startupForm, "sessionLabel", args, n);
289 XmStringFree(string);
294 XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
295 XtSetArg(args[n], XmNtopWidget, widget_list[count-1]); n++;
296 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
297 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
298 XtSetArg(args[n], XmNmarginHeight, style.verticalSpacing); n++;
299 XtSetArg(args[n], XmNmarginWidth, style.horizontalSpacing); n++;
300 string = CMPSTR(((char *)GETMESSAGE(7, 3, "At Login:")));
301 XtSetArg(args[n], XmNtitleString, string); n++;
302 widget_list[count++] =
303 _DtCreateTitleBox(startup.startupForm,"shutdownBox", args, n);
304 XmStringFree(string);
307 XtSetArg(args[n], XmNmarginHeight, 0); n++;
308 XtSetArg(args[n], XmNmarginWidth, 0); n++;
309 shutdownRC= XmCreateRadioBox(widget_list[count-1],"shutdownRC", args, n);
312 * For early versions of dtstyle, style.smState.smStartState could
313 * be set to a value that is no longer supported. If this occurs,
314 * no button will be selected, so initialize style.smState.smStartState
315 * to a state that is supported.
317 if (style.smState.smStartState != DtSM_CURRENT_STATE &&
318 style.smState.smStartState != DtSM_HOME_STATE)
319 style.smState.smStartState = DtSM_CURRENT_STATE;
322 XtSetArg(args[n], XmNalignment, XmALIGNMENT_BEGINNING); n++;
323 string = CMPSTR(((char *)GETMESSAGE(7, 4, "Resume current session")));
324 XtSetArg(args[n], XmNlabelString, string); n++;
325 if (style.smState.smStartState == DtSM_CURRENT_STATE)
327 XtSetArg(args[n], XmNset, True); n++;
329 widget_list2[count2++] = startup.resumeTgl
330 = XmCreateToggleButtonGadget(shutdownRC,"resumeTgl", args, n);
331 XmStringFree(string);
334 XtSetArg(args[n], XmNalignment, XmALIGNMENT_BEGINNING); n++;
335 string = CMPSTR(((char *)GETMESSAGE(7, 5, "Return to Home session")));
336 XtSetArg(args[n], XmNlabelString, string); n++;
337 if (style.smState.smStartState == DtSM_HOME_STATE)
339 XtSetArg(args[n], XmNset, True); n++;
341 widget_list2[count2++] = startup.homeTgl
342 = XmCreateToggleButtonGadget(shutdownRC,"homeTgl", args, n);
343 XmStringFree(string);
346 XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
347 XtSetArg(args[n], XmNtopWidget, widget_list[count-1]); n++;
348 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
349 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
350 XtSetArg(args[n], XmNmarginHeight, style.verticalSpacing); n++;
351 XtSetArg(args[n], XmNmarginWidth, style.horizontalSpacing); n++;
352 string = CMPSTR(((char *)GETMESSAGE(7, 7, "Logout Confirmation Dialog:")));
353 XtSetArg(args[n], XmNtitleString, string); n++;
354 widget_list[count++] = _DtCreateTitleBox(startup.startupForm,"modeBox", args, n);
355 XmStringFree(string);
358 XtSetArg(args[n], XmNmarginHeight, 0); n++;
359 XtSetArg(args[n], XmNmarginWidth, 0); n++;
360 XtSetArg(args[n], XmNorientation, XmHORIZONTAL); n++;
361 modeForm = XmCreateRadioBox(widget_list[count-1], "modeForm", args, n);
364 XtSetArg(args[n], XmNalignment, XmALIGNMENT_BEGINNING); n++;
365 string = CMPSTR(((char *)GETMESSAGE(7, 8, "On")));
366 XtSetArg(args[n], XmNlabelString, string ); n++;
367 if (style.smState.smConfirmMode == DtSM_VERBOSE_MODE)
369 XtSetArg(args[n], XmNset, True); n++;
372 XtSetArg(args[n], XmNset, False); n++;
374 startup.modeYesTgl= XmCreateToggleButtonGadget(modeForm,"modeYesTgl", args, n);
375 XmStringFree(string);
378 XtSetArg(args[n], XmNalignment, XmALIGNMENT_BEGINNING); n++;
379 string = CMPSTR(((char *)GETMESSAGE(7, 9, "Off")));
380 XtSetArg(args[n], XmNlabelString, string ); n++;
381 if (style.smState.smConfirmMode != DtSM_VERBOSE_MODE)
383 XtSetArg(args[n], XmNset, True); n++;
386 XtSetArg(args[n], XmNset, False); n++;
388 startup.modeNoTgl= XmCreateToggleButtonGadget(modeForm,"modeNoTgl", args, n);
389 XmStringFree(string);
392 XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
393 XtSetArg(args[n], XmNtopWidget, widget_list[count-1]); n++;
394 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
395 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
396 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
397 XtSetArg(args[n], XmNmarginHeight, LB_MARGIN_HEIGHT); n++;
398 XtSetArg(args[n], XmNmarginWidth, LB_MARGIN_WIDTH); n++;
399 XtSetArg(args[n], XmNnavigationType, XmTAB_GROUP); n++;
400 string = CMPSTR(((char *)GETMESSAGE(7, 10, "Set Home Session ...")));
401 XtSetArg(args[n], XmNlabelString, string); n++;
402 widget_list[count++] = startup.setHome =
403 XmCreatePushButtonGadget(startup.startupForm,"setPB", args, n);
404 XmStringFree(string);
406 XtAddCallback(style.startupDialog, XmNmapCallback, MapStartup, shell);
407 XtAddCallback(style.startupDialog, XmNmapCallback, LayoutCB, shell);
408 XtAddCallback(startup.resumeTgl, XmNvalueChangedCallback,
409 (XtCallbackProc)SetCurrentCB, NULL);
410 XtAddCallback(startup.homeTgl, XmNvalueChangedCallback,
411 (XtCallbackProc)SetHomeCB, NULL);
412 XtAddCallback(startup.modeYesTgl, XmNvalueChangedCallback,
413 (XtCallbackProc)SetConfirmCB, NULL);
414 XtAddCallback( widget_list[count-1], XmNactivateCallback,
415 SetHomeSession, style.startupDialog);
417 XtManageChild(modeForm);
418 XtManageChild(startup.startupForm);
419 XtManageChild(shutdownRC);
420 XtManageChildren(widget_list2,count2);
421 XtManageChild(startup.modeYesTgl);
422 XtManageChild(startup.modeNoTgl);
423 XtManageChildren(widget_list,count);
425 return(style.startupDialog);
429 /*+++++++++++++++++++++++++++++++++++++++*/
431 /*+++++++++++++++++++++++++++++++++++++++*/
435 XtPointer client_data,
436 XtPointer call_data )
439 DtWsmRemoveWorkspaceFunctions (style.display, XtWindow(XtParent(w)));
441 if (!save.restoreFlag)
442 putDialog ((Widget)client_data, w);
444 XtRemoveCallback(style.startupDialog, XmNmapCallback, MapStartup, NULL);
448 /*+++++++++++++++++++++++++++++++++++++++*/
450 /*+++++++++++++++++++++++++++++++++++++++*/
454 XtPointer client_data,
455 XtPointer call_data )
460 if (XtWidth(startup.startupForm) < (Dimension) (XtWidth(startup.setHome) +
461 (2*style.horizontalSpacing)))
464 XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
465 XtSetValues(startup.setHome, args, n);
467 XtRemoveCallback(style.startupDialog, XmNmapCallback, LayoutCB, NULL);
471 /*+++++++++++++++++++++++++++++++++++++++*/
473 /* tell SM to resume current session */
474 /*+++++++++++++++++++++++++++++++++++++++*/
478 XtPointer client_data,
479 XmToggleButtonCallbackStruct *call_data )
482 style.smState.smStartState = DtSM_CURRENT_STATE;
486 /*+++++++++++++++++++++++++++++++++++++++*/
488 /* tell SM to use home session */
489 /*+++++++++++++++++++++++++++++++++++++++*/
493 XtPointer client_data,
494 XmToggleButtonCallbackStruct *call_data )
497 style.smState.smStartState = DtSM_HOME_STATE;
501 /*+++++++++++++++++++++++++++++++++++++++*/
503 /* tell SM to be verbose or not */
504 /*+++++++++++++++++++++++++++++++++++++++*/
508 XtPointer client_data,
509 XmToggleButtonCallbackStruct *call_data )
516 style.smState.smConfirmMode = DtSM_VERBOSE_MODE;
519 style.smState.smConfirmMode = DtSM_QUIET_MODE;
524 /*+++++++++++++++++++++++++++++++++++++++*/
526 /*+++++++++++++++++++++++++++++++++++++++*/
530 XtPointer client_data,
531 XtPointer call_data )
533 SmSaveHomeSession(startup.origStartState, startup.origConfirmMode);
537 /*+++++++++++++++++++++++++++++++++++++++*/
539 /* allow user to cancel out */
540 /*+++++++++++++++++++++++++++++++++++++++*/
544 XtPointer client_data,
545 XtPointer call_data )
549 Widget shell = (Widget) client_data;
551 XmString okstr, cancelstr;
553 if (startup.dlg == NULL)
555 string = CMPSTR(((char *)GETMESSAGE(7, 11, "This will replace your home session with\nthe current session.\n\n Continue?")));
556 XtSetArg(args[n], XmNmessageString, string); n++;
557 okstr = CMPSTR((String) _DtOkString);
558 cancelstr = CMPSTR((String) _DtCancelString);
559 XtSetArg(args[n], XmNokLabelString, okstr); n++;
560 XtSetArg(args[n], XmNcancelLabelString, cancelstr); n++;
561 XtSetArg(args[n], XmNmwmFunctions, DIALOG_MWM_FUNC ); n++;
562 startup.dlg = XmCreateWarningDialog(shell, "QNotice", args, n);
563 XtUnmanageChild (XmMessageBoxGetChild(startup.dlg, XmDIALOG_HELP_BUTTON));
564 XtAddCallback(startup.dlg, XmNokCallback, SaveHomeOk, NULL);
565 XmStringFree(string);
567 XmStringFree(cancelstr);
570 XtSetArg (args[n], XmNmwmInputMode,
571 MWM_INPUT_PRIMARY_APPLICATION_MODAL); n++;
572 XtSetArg(args[n], XmNtitle, ((char *)GETMESSAGE(7, 12, "Warning"))); n++;
573 XtSetValues (XtParent(startup.dlg), args, n);
575 XtManageChild(startup.dlg);
579 /*+++++++++++++++++++++++++++++++++++++++*/
581 /* CB for OK, Cancel, Help in DialogBox */
582 /*+++++++++++++++++++++++++++++++++++++++*/
586 XtPointer client_data,
587 XtPointer call_data )
589 Arg set[1], unset[1];
590 DtDialogBoxCallbackStruct *cb = (DtDialogBoxCallbackStruct *) call_data;
592 switch (cb->button_position)
597 if (XmToggleButtonGadgetGetState(startup.modeYesTgl))
598 startup.origConfirmMode = DtSM_VERBOSE_MODE;
600 startup.origConfirmMode = DtSM_QUIET_MODE;
602 SmNewStartupSettings();
607 XmToggleButtonGadgetSetState(startup.resumeTgl, True, True);
608 XmToggleButtonGadgetSetState(startup.resumeTgl, False, True);
610 XtSetArg(set[0], XmNset, True);
611 XtSetArg(unset[0], XmNset, False);
613 if (startup.origStartState == DtSM_CURRENT_STATE)
614 XmToggleButtonGadgetSetState(startup.resumeTgl, True, True);
616 else if (startup.origStartState == DtSM_HOME_STATE)
617 XmToggleButtonGadgetSetState(startup.homeTgl, True, True);
621 * Reasonable default?
623 XmToggleButtonGadgetSetState(startup.resumeTgl, True, True);
625 if (startup.origConfirmMode == DtSM_VERBOSE_MODE)
626 XmToggleButtonGadgetSetState(startup.modeYesTgl, True, True);
628 XmToggleButtonGadgetSetState(startup.modeNoTgl, True, True);
630 style.smState.smStartState = startup.origStartState;
631 style.smState.smConfirmMode = startup.origConfirmMode;
637 XtCallCallbacks(style.startupDialog, XmNhelpCallback, (XtPointer)NULL);
646 /************************************************************************
649 * restore any state information saved with saveStartup.
650 * This is called from restoreSession with the application
651 * shell and the special xrm database retrieved for restore.
652 ************************************************************************/
659 XrmRepresentation rep_type;
662 xrm_name [0] = XrmStringToQuark ("startupDlg");
666 xrm_name [1] = XrmStringToQuark ("x");
667 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)){
668 XtSetArg (save.posArgs[save.poscnt], XmNx, atoi((char *)value.addr));
670 save.restoreFlag = True;
674 xrm_name [1] = XrmStringToQuark ("y");
675 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)){
676 XtSetArg (save.posArgs[save.poscnt], XmNy, atoi((char *)value.addr));
680 xrm_name [1] = XrmStringToQuark ("ismapped");
681 XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value);
682 /* Are we supposed to be mapped? */
683 if (strcmp(value.addr, "True") == 0)
684 popup_startupBB(shell);
687 /************************************************************************
690 * This routine will write out to the passed file descriptor any state
691 * information this dialog needs. It is called from saveSessionCB with the
692 * file already opened.
693 * All information is saved in xrm format. There is no restriction
694 * on what can be saved. It doesn't have to be defined or be part of any
695 * widget or Xt definition. Just name and save it here and recover it in
696 * restoreStartup. The suggested minimum is whether you are mapped, and
698 ************************************************************************/
704 char *bufr = style.tmpBigStr; /* size=[1024], make bigger if needed */
705 XmVendorShellExtObject vendorExt;
706 XmWidgetExtData extData;
708 if (style.startupDialog != NULL) {
709 if (XtIsManaged(style.startupDialog))
710 sprintf(bufr, "*startupDlg.ismapped: True\n");
712 sprintf(bufr, "*startupDlg.ismapped: False\n");
714 /* Get and write out the geometry info for our Window */
715 x = XtX(XtParent(style.startupDialog));
716 y = XtY(XtParent(style.startupDialog));
718 /* Modify x & y to take into account window mgr frames
719 * This is pretty bogus, but I don't know a better way to do it.
721 extData = _XmGetWidgetExtData(style.shell, XmSHELL_EXTENSION);
722 vendorExt = (XmVendorShellExtObject)extData->widget;
723 x -= vendorExt->vendor.xOffset;
724 y -= vendorExt->vendor.yOffset;
726 sprintf(bufr, "%s*startupDlg.x: %d\n", bufr, x);
727 sprintf(bufr, "%s*startupDlg.y: %d\n", bufr, y);
729 write (fd, bufr, strlen(bufr));