Esempio n. 1
0
static Object P_Install_All_Accelerators (Object dst, Object src) {
    Check_Widget (dst);
    Check_Widget (src);
    XtInstallAllAccelerators (WIDGET(dst)->widget, WIDGET(src)->widget);
    return Void;

}
Esempio n. 2
0
void
create_choose_session_popup(void)

{
    static XtActionsRec choose_actions[] = {
        {"ChooseSessionUp", ChooseSessionUp},
        {"ChooseSessionDown", ChooseSessionDown},
        {"ChooseSessionBtn1Down", ChooseSessionBtn1Down}
    };

    /*
     * Pop up for choosing session at startup
     */

    chooseSessionPopup = XtVaCreatePopupShell (
	"chooseSessionPopup", transientShellWidgetClass, topLevel,
	XtNallowShellResize, True,
	NULL);
    

    chooseSessionForm = XtVaCreateManagedWidget (
	"chooseSessionForm", formWidgetClass, chooseSessionPopup,
	NULL);


    chooseSessionLabel = XtVaCreateManagedWidget (
	"chooseSessionLabel", labelWidgetClass, chooseSessionForm,
        XtNfromHoriz, NULL,
        XtNfromVert, NULL,
        XtNborderWidth, 0,
	XtNresizable, True,
	XtNjustify, XtJustifyCenter,
	NULL);

    chooseSessionListWidget = XtVaCreateManagedWidget (
	"chooseSessionListWidget", listWidgetClass, chooseSessionForm,
	XtNresizable, True,
        XtNdefaultColumns, 1,
	XtNforceColumns, True,
        XtNfromHoriz, NULL,
        XtNfromVert, chooseSessionLabel,
	XtNvertDistance, 25,
	NULL);

    chooseSessionMessageLabel = XtVaCreateManagedWidget (
	"chooseSessionMessageLabel", labelWidgetClass, chooseSessionForm,
        XtNfromHoriz, NULL,
        XtNfromVert, chooseSessionListWidget,
        XtNborderWidth, 0,
	XtNresizable, True,
	XtNjustify, XtJustifyCenter,
	NULL);

    chooseSessionLoadButton = XtVaCreateManagedWidget (
	"chooseSessionLoadButton", commandWidgetClass, chooseSessionForm,
        XtNfromHoriz, NULL,
        XtNfromVert, chooseSessionMessageLabel,
        NULL);

    XtAddCallback (chooseSessionLoadButton, XtNcallback,
	ChooseSessionLoadXtProc, NULL);

    chooseSessionDeleteButton = XtVaCreateManagedWidget (
	"chooseSessionDeleteButton", commandWidgetClass, chooseSessionForm,
        XtNfromHoriz, chooseSessionLoadButton,
        XtNfromVert, chooseSessionMessageLabel,
        NULL);

    XtAddCallback (chooseSessionDeleteButton, XtNcallback,
	ChooseSessionDeleteXtProc, NULL);

    chooseSessionBreakLockButton = XtVaCreateManagedWidget (
	"chooseSessionBreakLockButton",
	commandWidgetClass, chooseSessionForm,
        XtNfromHoriz, chooseSessionDeleteButton,
        XtNfromVert, chooseSessionMessageLabel,
        NULL);

    XtAddCallback (chooseSessionBreakLockButton, XtNcallback,
	ChooseSessionBreakLockXtProc, NULL);

    chooseSessionFailSafeButton = XtVaCreateManagedWidget (
	"chooseSessionFailSafeButton", commandWidgetClass, chooseSessionForm,
        XtNfromHoriz, chooseSessionBreakLockButton,
        XtNfromVert, chooseSessionMessageLabel,
        NULL);

    XtAddCallback (chooseSessionFailSafeButton, XtNcallback,
	ChooseSessionFailSafeXtProc, NULL);


    chooseSessionCancelButton = XtVaCreateManagedWidget (
	"chooseSessionCancelButton", commandWidgetClass, chooseSessionForm,
        XtNfromHoriz, chooseSessionFailSafeButton,
        XtNfromVert, chooseSessionMessageLabel,
        NULL);

    XtAddCallback (chooseSessionCancelButton, XtNcallback,
	ChooseSessionCancelXtProc, NULL);

    XtAppAddActions (appContext, choose_actions, XtNumber (choose_actions));

    XtInstallAllAccelerators (chooseSessionListWidget, chooseSessionPopup);
}
Esempio n. 3
0
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;
}
Esempio n. 4
0
static void XSetupDisplay(int nframes) {
  XGCValues xgcv;
  XtAccelerators keys;

  /* Had to do it this way since embedding the keystrokes in the fallback
     resources failed to work properly -- what a kludge. */

  keys = XtParseAcceleratorTable(ckeys);

  xi.depth = DefaultDepthOfScreen(DefaultScreenOfDisplay(xi.disp));

  // give me TrueColor
  if (!XMatchVisualInfo(xi.disp, xi.screenno, xi.depth, TrueColor, &(xi.vi)))
    ErrorExit(ERROR_BADPARM, "Could not find a TrueColor visual");

  xi.vis = xi.vi.visual;
  xi.root = RootWindow(xi.disp, xi.screenno);

  // AllocNone -- clients can allocate the colormap entries
  // For TrueColor, alloc must be AloocNone
  xi.colormap = XCreateColormap(xi.disp, xi.root, xi.vis, AllocNone);

  toplevel = XtVaAppCreateShell("NMovie", "NMovie",
                                applicationShellWidgetClass,
                                xi.disp,
                                XtNvisual, xi.vis,
                                XtNcolormap, xi.colormap,
                                NULL);

  XtAppAddActions(xi.context,actions,XtNumber(actions));

  // frame
  frame = XtVaCreateManagedWidget("Frame", formWidgetClass, toplevel, NULL);
  // create buttons
  buttons = XtVaCreateManagedWidget("Buttons", formWidgetClass, frame, NULL );
  loop_bt = XtVaCreateManagedWidget("Loop", commandWidgetClass,
                                    buttons, NULL);
  swing_bt = XtVaCreateManagedWidget("Swing", commandWidgetClass,
                                     buttons, NULL);
  fast_bt = XtVaCreateManagedWidget("Faster", commandWidgetClass,
                                    buttons, NULL);
  slow_bt = XtVaCreateManagedWidget("Slower", commandWidgetClass,
                                    buttons, NULL);
  stop_bt = XtVaCreateManagedWidget("Stop", commandWidgetClass,
                                    buttons, NULL);
  back_bt = XtVaCreateManagedWidget("Back", commandWidgetClass,
                                    buttons, NULL);
  forward_bt = XtVaCreateManagedWidget("Forward", commandWidgetClass,
                                       buttons, NULL);
  quit_bt = XtVaCreateManagedWidget("Quit", commandWidgetClass,
                                    buttons, NULL);
  // canvas
  canvas = XtVaCreateManagedWidget("Canvas", simpleWidgetClass, frame,
                                   XtNwidth, cols,
                                   XtNheight, rows,
                                   XtNaccelerators, keys, NULL);
  XtInstallAllAccelerators(canvas,toplevel);
  XtRealizeWidget(toplevel);
  xi.canvas = XtWindow(canvas);

  xi.theGC = XCreateGC(xi.disp, xi.canvas, 0L, &xgcv);

  xi.rmask = xi.vis->red_mask;   // 0xFF0000
  xi.gmask = xi.vis->green_mask; // 0x00FF00
  xi.bmask = xi.vis->blue_mask;  // 0x0000FF

  xi.rshift = 7 - highbit(xi.rmask); // -16
  xi.gshift = 7 - highbit(xi.gmask); //  -8
  xi.bshift = 7 - highbit(xi.bmask); //   0

  // format is ZPixmap                                offset,data
  ximg = XCreateImage(xi.disp,xi.vis,xi.depth,ZPixmap, 0,    NULL,
                      //  bytes_per_line = 0 means assume contiguous and calculated
                      cols, rows, 32, 0);

  if ((imgdata = (char *)calloc((size_t)(rows*ximg->bytes_per_line*nframes),
                                sizeof(byte)))
      ==NULL)
    ErrorExit(ERROR_NO_MEMORY,"Failed to allocate image buffer");

  ximg->data = (char *) imgdata;
}