Dialog CreateDialog(Widget top_widget, String name, unsigned long options) { int i; Dialog popup; popup = (Dialog) XtMalloc(sizeof(_Dialog)); if (popup) { if (firstTime) { XtAddActions(actions_table, XtNumber(actions_table)); firstTime = False; } popup->top_widget = top_widget; popup->shell_widget = XtCreatePopupShell(name, transientShellWidgetClass, top_widget, NULL, 0); popup->dialog_widget = XtCreateManagedWidget("dialog", dialogWidgetClass, popup->shell_widget, NULL, 0); for (i = 0; i < XtNumber(dialog_buttons); i++) if (options & dialog_buttons[i].flag) XawDialogAddButton(popup->dialog_widget, dialog_buttons[i].name, SetSelected, dialog_buttons[i].name); popup->options = options; return popup; } else return NULL; }
int main(int argc, char *argv[]) { Arg arglist[10]; Cardinal num_args; #ifdef USE_PRIVSEP struct passwd *pw; #endif XtSetLanguageProc(NULL,NULL,NULL); top = XtInitialize ("xconsole", "XConsole", options, XtNumber (options), &argc, argv); XtGetApplicationResources (top, (XtPointer)&app_resources, resources, XtNumber (resources), NULL, 0); #ifdef USE_PRIVSEP /* Revoke privileges if any */ if (getuid() == 0) { /* Running as root */ pw = getpwnam(XCONSOLE_USER); if (!pw) { fprintf(stderr, "%s user not found\n", XCONSOLE_USER); exit(2); } if (priv_init(pw->pw_uid, pw->pw_gid) < 0) { fprintf(stderr, "priv_init failed\n"); exit(2); } } else if (priv_init(-1, -1) < 0) { fprintf(stderr, "priv_init failed\n"); exit(2); } #endif if (app_resources.daemon) if (fork ()) exit (0); XtAddActions (actions, XtNumber (actions)); text = XtCreateManagedWidget ("text", asciiTextWidgetClass, top, NULL, 0); XtRealizeWidget (top); num_args = 0; XtSetArg(arglist[num_args], XtNiconic, &iconified); num_args++; XtGetValues(top, arglist, num_args); if (iconified) Iconified((Widget)NULL, (XEvent*)NULL, (String*)NULL, (Cardinal*)NULL); else Deiconified((Widget)NULL,(XEvent*)NULL,(String*)NULL,(Cardinal*)NULL); wm_delete_window = XInternAtom(XtDisplay(top), "WM_DELETE_WINDOW", False); (void) XSetWMProtocols (XtDisplay(top), XtWindow(top), &wm_delete_window, 1); XmuGetHostname (mit_console_name + MIT_CONSOLE_LEN, 255); mit_console = XInternAtom(XtDisplay(top), mit_console_name, False); if (XGetSelectionOwner (XtDisplay (top), mit_console)) { XtGetSelectionValue(top, mit_console, XA_STRING, InsertSelection, NULL, CurrentTime); } else { XtOwnSelection(top, mit_console, CurrentTime, ConvertSelection, LoseSelection, NULL); OpenConsole (); } #ifdef USE_OSM ioerror = XSetIOErrorHandler(IOError); #endif #ifdef USE_PRIVSEP if (pledge("stdio rpath sendfd recvfd", NULL) == -1) err(1, "pledge"); #endif XtMainLoop (); return 0; }
void #ifdef STANDALONE_SERVER main (int argc, char *argv[]) { unsigned window_size; string identity; /* This will be the contents of the identity_atom */ #else /* not STANDALONE_SERVER */ start_server (unsigned window_size, string identity) { #endif /* not STANDALONE_SERVER */ XTextProperty textP; Widget viewport_widget; int zero = 0; /* This routine will intercept messages we get. */ XtActionsRec actions[] = { { "MessageHandler", message_handler } }; /* Here we assume that all the characters will fit in an em square. (We make further assumptions below.) The TFM format guarantees that the design size is not negative. Values in the resource database override this. These initial values are only useful if we are not standalone, but we reassign just below if we are standalone. */ Arg geometry_args[] = { { XtNheight, window_size }, { XtNwidth, window_size }, }; #ifdef STANDALONE_SERVER if (argc == 3) { window_size = atou (argv[1]); geometry_args[0].value = geometry_args[1].value = window_size; identity = argv[2]; } else { fprintf (stderr, "Usage: %s window-size identity.\n", argv[0]); exit(0); } #endif /* STANDALONE_SERVER */ /* We have no fallback resources, and we've already parsed the args. */ top_level = XtInitialize (NULL, CLASS_NAME, NULL, 0, &zero, NULL); viewport_widget = XtCreateManagedWidget ("viewport", viewportWidgetClass, top_level, NULL, 0); canvas_widget = XtCreateManagedWidget ("canvas", labelWidgetClass, viewport_widget, geometry_args, XtNumber (geometry_args)); XtAddActions (actions, XtNumber (actions)); XtRealizeWidget (top_level); display = XtDisplay (top_level); foserver_exit_atom = XInternAtom (display, FOSERVER_EXIT_ATOM, False); foserver_update_pixmap_atom = XInternAtom (display, FOSERVER_UPDATE_PIXMAP_ATOM, False); /* Get the identity atom number. Create it if it doesn't exist. */ foserver_identity_atom = XInternAtom (display, FOSERVER_IDENTITY_ATOM, False); textP.value = (unsigned char *) identity; /* Set value. */ textP.encoding = XA_STRING; textP.format = 8; textP.nitems = strlen (identity); XSetTextProperty (display, XtWindow (canvas_widget), &textP, foserver_identity_atom); /* Process events forever. */ XtMainLoop (); }
static Widget create_dialogs(popupMessageSizeHintT size, Widget parent, int cnt, const char *helptext, pre_message_cbT pre_cb, XtPointer arg, const char *yes_button, message_cbT yes_cb, XtPointer yes_arg, const char *no_button, message_cbT no_cb, XtPointer no_arg, const char *cancel_button, message_cbT cancel_cb, XtPointer cancel_arg) { Widget new_popup_window; char *translations_str = NULL; #ifdef MOTIF Widget new_dialog; UNUSED(size); #else char *key_translations_str = NULL; int msg_w = 400, msg_h = 100; Widget new_message_paned, new_message_text, new_message_box, new_message_ok, new_message_help = 0, new_message_not_ok; XtTranslations wm_translations, key_translations; #endif /* save callbacks to global arrays */ pre_callbacks[cnt].callback = pre_cb; pre_callbacks[cnt].arg = arg; yes_callbacks[cnt].callback = yes_cb; yes_callbacks[cnt].arg = yes_arg; no_callbacks[cnt].callback = no_cb; no_callbacks[cnt].arg = no_arg; cancel_callbacks[cnt].callback = cancel_cb; cancel_callbacks[cnt].arg = cancel_arg; XtAddActions(popdown_actions, XtNumber(popdown_actions)); #ifndef MOTIF /* get index into WM_popdown arg */ translations_str = get_string_va("<Message>WM_PROTOCOLS: WM_popdown(%d)", cnt); wm_translations = XtParseTranslationTable(translations_str); free(translations_str); #endif if (!XtIsRealized(globals.widgets.top_level)) { /* If toplevel window hasn't been realized yet, create a new toplevel shell (otherwise, setting visual/color map wouldn't work); use same application names so that resource settings will also apply to this window. */ new_popup_window = XtVaAppCreateShell("xdvi", "Xdvi", transientShellWidgetClass, DISP, NULL); } else { new_popup_window = XtVaCreatePopupShell(Xdvi_MESSAGE_SHELL_NAME, #ifdef MOTIF xmDialogShellWidgetClass, parent, XmNdeleteResponse, XmDO_NOTHING, /* we'll take care of that ourselves */ #else transientShellWidgetClass, parent, XtNx, 60, XtNy, 80, XtNtranslations, wm_translations, XtNaccelerators, G_accels_cr, #endif XtNtransientFor, parent, XtNmappedWhenManaged, False, NULL); } #ifdef MOTIF WM_DELETE_WINDOW = XmInternAtom(XtDisplay(new_popup_window), "WM_DELETE_WINDOW", False); XmAddWMProtocolCallback(new_popup_window, WM_DELETE_WINDOW, cancel_action, NULL); /* We also need to override the default ESC binding to use our internal housekeeping functions */ translations_str = get_string_va("#override\n<Key>osfCancel:close-popup-cancel(%d)", cnt); /* { */ /* XtTranslations xlats; */ /* char *translation_str = get_string_va("<Key>osfCancel:close-popup-cancel(%d)", cnt); */ /* xlats = XtParseTranslationTable(translation_str); */ /* free(translation_str); */ /* XtOverrideTranslations(new_dialog, xlats); */ /* } */ new_dialog = XtVaCreateWidget(Xdvi_MESSAGE_DIALOG_NAME, xmMessageBoxWidgetClass, new_popup_window, XmNdialogType, XmDIALOG_WARNING, /* default */ XmNtraversalOn, True, XmNhighlightOnEnter, True, XmNuserData, cast_int_to_XtPointer(cnt), XmNtranslations, XtParseTranslationTable(translations_str), NULL); free(translations_str); XtAddCallback(new_dialog, XmNokCallback, ok_action, NULL); if (no_button != NULL) { Arg args[4]; Widget b; XmString b_str = XmStringCreateLocalized((char *)no_button); XtSetArg(args[0], XmNlabelString, b_str); b = XmCreatePushButton(new_dialog, "no_button", args, 1); XtAddCallback(b, XmNactivateCallback, not_ok_action, NULL); XtManageChild(b); } if (cancel_button != NULL) { XmString cancel_label = XmStringCreateLtoR((char *)cancel_button, G_charset); XtVaSetValues(XmMessageBoxGetChild(new_dialog, XmDIALOG_CANCEL_BUTTON), XmNlabelString, cancel_label, NULL); XmStringFree(cancel_label); XtAddCallback(new_dialog, XmNcancelCallback, cancel_action, NULL); } else { XtUnmanageChild(XmMessageBoxGetChild(new_dialog, XmDIALOG_CANCEL_BUTTON)); } XtInstallAllAccelerators(new_dialog, XmMessageBoxGetChild(new_dialog, XmDIALOG_OK_BUTTON)); if (helptext != NULL) { XtAddCallback(new_dialog, XmNhelpCallback, help_action, (XtPointer)helptext); } else { XtUnmanageChild(XmMessageBoxGetChild(new_dialog, XmDIALOG_HELP_BUTTON)); } if (yes_button != NULL) { /* change `OK' button label */ XmString yes_label; yes_label = XmStringCreateLtoR((char *)yes_button, G_charset); XtVaSetValues(XmMessageBoxGetChild(new_dialog, XmDIALOG_OK_BUTTON), XmNlabelString, yes_label, NULL); XmStringFree(yes_label); } /* insert the new widgets into the global arrays */ dialog[cnt] = new_dialog; #else /* MOTIF */ switch (size) { case SIZE_SMALL: msg_w = 300; msg_h = 100; break; case SIZE_MEDIUM: msg_w = 430; msg_h = 160; break; case SIZE_LARGE: msg_w = 450; msg_h = 180; break; } WM_DELETE_WINDOW = XInternAtom(XtDisplay(new_popup_window), "WM_DELETE_WINDOW", False); new_message_paned = XtVaCreateManagedWidget("message_paned", panedWidgetClass, new_popup_window, XtNaccelerators, G_accels_cr, NULL); new_message_text = XtVaCreateManagedWidget("message_text", asciiTextWidgetClass, new_message_paned, /* XtNheight, 100, */ /* XtNwidth, 400, */ XtNwidth, msg_w, XtNheight, msg_h, /* wrap horizontally instead of scrolling * TODO: this won't work for the first widget instance? */ XtNwrap, XawtextWrapWord, XtNscrollVertical, XAW_SCROLL_ALWAYS, XtNeditType, XawtextRead, XtNinput, True, XtNdisplayCaret, False, XtNleftMargin, 5, XtNaccelerators, G_accels_cr, NULL); /* box for the OK/Cancel button */ new_message_box = XtVaCreateManagedWidget("message_box", formWidgetClass, new_message_paned, /* resizing by user isn't needed */ XtNshowGrip, False, XtNdefaultDistance, 6, /* some padding */ /* resizing the window shouldn't influence this box, * but only the text widget */ XtNskipAdjust, True, XtNaccelerators, G_accels_cr, NULL); new_message_ok = XtVaCreateManagedWidget(yes_button == NULL ? "OK" : yes_button, commandWidgetClass, new_message_box, XtNtop, XtChainTop, XtNbottom, XtChainBottom, XtNleft, XtChainLeft, XtNright, XtChainLeft, XtNaccelerators, G_accels_cr, NULL); /* add quit_action callback for the "OK" button */ /* FIXME: how to make accelerators be accepted by new_popup_window as well? */ key_translations_str = get_string_va("<Key>q:close-popup-cancel(%d)\n" "<Key>Return:close-popup-cancel(%d)\n" "<Key>Escape:close-popup-cancel(%d)\n", cnt, cnt, cnt); key_translations = XtParseTranslationTable(key_translations_str); free(key_translations_str); XtOverrideTranslations(new_popup_window, key_translations); XtOverrideTranslations(new_message_paned, key_translations); XtOverrideTranslations(new_message_text, key_translations); XtInstallAllAccelerators(new_message_box, new_message_ok); XtAddCallback(new_message_ok, XtNcallback, ok_action, cast_int_to_XtPointer(cnt)); /* we create additional buttons in any case, to make the sizing more consistent */ new_message_help = XtVaCreateManagedWidget("Help", commandWidgetClass, new_message_box, XtNtop, XtChainTop, XtNfromHoriz, new_message_ok, XtNbottom, XtChainBottom, XtNleft, XtChainRight, XtNright, XtChainRight, XtNaccelerators, G_accels_cr, NULL); message_help[cnt] = new_message_help; /* add cancel button */ new_message_not_ok = XtVaCreateManagedWidget(cancel_button == NULL ? "Cancel" : cancel_button, commandWidgetClass, new_message_box, XtNtop, XtChainTop, XtNfromHoriz, new_message_ok, XtNbottom, XtChainBottom, XtNleft, helptext == NULL ? XtChainRight : XtChainLeft, XtNright, helptext == NULL ? XtChainRight : XtChainLeft, XtNaccelerators, G_accels_cr, NULL); message_not_ok[cnt] = new_message_not_ok; if (no_button != NULL) { ASSERT(0, "third button not yet implemented in Xaw!!!"); } adjust_width_to_max(new_message_ok, new_message_help, new_message_not_ok, NULL); /* if helptext argument is not-NULL, add help_action callback, else unmanage help button */ if (helptext != NULL) { XtAddCallback(new_message_help, XtNcallback, help_action, (XtPointer)helptext); } else { XtUnmanageChild(new_message_help); } if (cancel_button != NULL) { XtAddCallback(new_message_not_ok, XtNcallback, cancel_action, cast_int_to_XtPointer(cnt)); } else { XtUnmanageChild(new_message_not_ok); } /* insert the new widgets into the global arrays */ message_box[cnt] = new_message_box; message_paned[cnt] = new_message_paned; message_text[cnt] = new_message_text; message_ok[cnt] = new_message_ok; #endif /* MOTIF */ popup_window[cnt] = new_popup_window; return new_popup_window; }