Widget XmPrintSetup( Widget video_widget, Screen *print_screen, String print_shell_name, ArgList args, Cardinal num_args) { String video_name, video_class ; Widget pappshell ; Widget print_shell; Display *print_display = DisplayOfScreen(print_screen); /* get to the video app root shell */ while(!XtIsApplicationShell(video_widget)) video_widget = XtParent(video_widget); if (!video_widget) return NULL; XtGetApplicationNameAndClass(XtDisplay(video_widget), &video_name, &video_class); /* we want to be able to specify things like: dtpad.print*textFontList: somefont dtpad.print*background:white so we create a first shell unrealized and them a popup named "print". */ pappshell = XtVaAppCreateShell(video_name, video_class, applicationShellWidgetClass, print_display, XmNscreen, print_screen, NULL); /* then create the XmPrintShell */ print_shell = XtCreatePopupShell(print_shell_name, xmPrintShellWidgetClass, pappshell, args, num_args); /* Add callback to destroy application Shell parent. */ XtAddCallback(print_shell, XmNdestroyCallback, _XmDestroyParentCallback, (XtPointer) NULL) ; /* we're mapping/unmapping at start/end page time */ XtSetMappedWhenManaged(print_shell, False); /* realize the shell now, so that XmPrintPopupPDM works dy default */ XtRealizeWidget(print_shell); return print_shell ; }
void help_win(Widget widget, XtPointer client_data, XtPointer call_data) { Widget tL1, vpane, buttonbox; Widget close, txt; int one = 1; char *argv[2]; Display * dpy; if (help_context != NULL) return; argv[0] = "xsuprem"; argv[1] = NULL; help_context = XtCreateApplicationContext(); dpy = XtOpenDisplay(help_context, (String) NULL, NULL, "XSuprem", NULL, 0, &one, argv); if (dpy == NULL) XtErrorMsg("invalidDisplay","xtInitialize","XtToolkitError", "Can't Open display", (String *) NULL, (Cardinal *)NULL); tL1 = XtVaAppCreateShell( "XSupHelp", "XSuprem", applicationShellWidgetClass, dpy, XtNscreen, (XtArgVal)DefaultScreenOfDisplay(dpy), NULL ); vpane = XtVaCreateManagedWidget("vpane", panedWidgetClass, tL1, NULL); buttonbox = XtVaCreateManagedWidget("buttonbox", boxWidgetClass, vpane, NULL); /*Make the Help Button*/ close = XtVaCreateManagedWidget("Cancel", commandWidgetClass, buttonbox, NULL); XtAddCallback(close, XtNcallback, destroy_help, NULL); txt = XtVaCreateManagedWidget("help", asciiTextWidgetClass, vpane, XtNscrollVertical, XawtextScrollAlways, XtNtype, XawAsciiFile, /*XtNstring, "/home/helios0/law/src/xgraph/help",*/ NULL); XtRealizeWidget(tL1); }
// Relacement for Qt function - add Xt stuff for top-level widgets Window qt_XCreateWindow( const QWidget* qw, Display *display, Window parent, int x, int y, uint w, uint h, int borderwidth, int depth, uint windowclass, Visual *visual, ulong valuemask, XSetWindowAttributes *attributes ) { // ### This isA will not work - we are still in QWidget's constructor. if ( qw->isTopLevel() && !qw->isA("QNPWidget") ) { // ### not sure it is good to use name() and className(). bool cmap = valuemask & CWColormap; Widget xtw = XtVaAppCreateShell( qw->name(), qw->className(), applicationShellWidgetClass, display, XtNx, x, XtNy, y, XtNwidth, w, XtNheight, h, XtNborderWidth, borderwidth, XtNdepth, depth, XtNvisual, visual, cmap ? XtNcolormap : 0, cmap ? attributes->colormap : 0, 0, 0 ); // Ensure it has a window, and get it. XtSetMappedWhenManaged( xtw, FALSE ); XtRealizeWidget( xtw ); Window xw = XtWindow( xtw ); // Set the attributes (directly) XChangeWindowAttributes( display, xw, valuemask, attributes ); // Inform us on enter/leave XtAddEventHandler( xtw, EnterWindowMask, TRUE, enter_event_handler, 0 ); XtAddEventHandler( xtw, LeaveWindowMask, TRUE, leave_event_handler, 0 ); // Return Xt's window for the widget return xw; } else { Window window = XCreateWindow( display, parent, x, y, w, h, borderwidth, depth, windowclass, visual, valuemask, attributes ); return window; } }
static DTIconRec *createDTIcon(Widget appshell, AppRec *app, int x, int y) { DTIconRec *newDTIcon = (DTIconRec *) XtMalloc(sizeof(DTIconRec)); newDTIcon->app = *app; readApplicationIcon(appshell, &newDTIcon->app, ERR_POPUP); newDTIcon->label_mask = None; newDTIcon->drop_pixmap = None; newDTIcon->moved = False; newDTIcon->save = False; if (x != -1) { newDTIcon->x = x; newDTIcon->y = y; } else placeDTIcon(newDTIcon); trans = XtParseTranslationTable(icon_translations); XtAppAddActions(app_context, icon_actions, XtNumber(icon_actions)); newDTIcon->shell = XtVaAppCreateShell(NULL, "dticon", topLevelShellWidgetClass, dpy, XmNmwmDecorations, 0, XmNmwmFunctions, 0, XmNtitle, "desktop icon", XmNx, newDTIcon->x, XmNy, newDTIcon->y, XmNallowShellResize, True, XmNoverrideRedirect, resources.override_redirect, NULL); #if (XtSpecificationRelease > 4) #ifndef _NO_XMU XtAddEventHandler(newDTIcon->shell, (EventMask)0, True, _XEditResCheckMessages, NULL); #endif #endif /* This widget seems to be necessary in order to prevent segfaults in connection with popup menus under Linux w/ MetroLink Motif 1.2.4 */ newDTIcon->cont = XtVaCreateManagedWidget("container", xmFormWidgetClass, newDTIcon->shell, XmNborderWidth, 0, XmNshadowThickness, 0, XmNhighlightThickness, 0, XmNx, 0, XmNy, 0, NULL); /* XtRealizeWidget(newDTIcon->shell);*/ return newDTIcon; }
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; }
int XtTest(int argc, char** argv) { Widget toplevel; Display* display; XtAppContext context; Widget form, label, label1, label2, button; Screen* screen; String swap; if (NULL == (swap = strrchr(argv[0], '/'))) { swap = argv[0]; } else { swap++; } context = XtCreateApplicationContext(); display = XtOpenDisplay( context, NULL, NULL, NULL, NULL, 0, &argc, argv); if (NULL == display) { return 0; } screen = XDefaultScreenOfDisplay(display); toplevel = XtVaAppCreateShell("k", "XtTest", applicationShellWidgetClass, display, XtNtitle, swap, XtNx, (screen->width /3), XtNy, (screen->height /3), NULL ); if (NULL == toplevel) { return -2; } if (3 != argc) { form = XtVaCreateManagedWidget("form", xmFormWidgetClass, toplevel, XmNhorizontalSpacing, 5, XmNmarginHeight, 10, XmNmarginWidth, 10, NULL ); label = XtVaCreateManagedWidget("label", xmLabelGadgetClass, form, XmNlabelString, XmStringCreateLocalized("Usage"), XmNalignment, XmALIGNMENT_BEGINNING, XmNtopAttachment, XmATTACH_FORM, XmNleftAttachment, XmATTACH_FORM, XmNrightAttachment, XmATTACH_FORM, NULL ); label1 = XtVaCreateManagedWidget("label1", xmLabelGadgetClass, form, XmNlabelString, XmStringCreateLocalized(swap), XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, label, XmNleftAttachment, XmATTACH_FORM, XmNbottomAttachment, XmATTACH_FORM, NULL ); label2 = XtVaCreateManagedWidget("label2", xmLabelGadgetClass, form, XmNlabelString, XmStringCreateLocalized(": arg1 arg2"), XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, label, XmNleftAttachment, XmATTACH_WIDGET, XmNleftWidget, label1, XmNbottomAttachment, XmATTACH_FORM, NULL); button = XtVaCreateManagedWidget("button", xmPushButtonWidgetClass, form, XmNlabelString, XmStringCreateLocalized("Close"), XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, label, XmNleftAttachment, XmATTACH_WIDGET, XmNleftWidget, label2, XmNbottomAttachment, XmATTACH_FORM, XmNrightAttachment, XmATTACH_FORM, NULL); XtAddCallback(button, XmNactivateCallback, XtTestDC, context); XtRealizeWidget(toplevel); XtAppMainLoop(context); } XtDestroyWidget(toplevel); XtDestroyApplicationContext(context); return 0; }
static int motTipsSet(Ihandle *ih) { char* tipText = iupAttribGet(ih, "TIP"); if (!tipText) return FALSE; if (!mot_tips.Dialog) { mot_tips.Dialog = XtVaAppCreateShell(" ", "tip", overrideShellWidgetClass, iupmot_display, XmNmappedWhenManaged, False, NULL); mot_tips.Label = XtVaCreateManagedWidget("label tip", xmLabelWidgetClass, mot_tips.Dialog, /* must use IupGetAttribute to use inheritance */ XmNforeground, iupmotColorGetPixelStr(IupGetAttribute(ih, "TIPFGCOLOR")), XmNbackground, iupmotColorGetPixelStr(IupGetAttribute(ih, "TIPBGCOLOR")), NULL); XtRealizeWidget(mot_tips.Dialog); } /* set label font */ { XmFontList fontlist = (XmFontList)iupmotGetFontListAttrib(ih); char* value = iupAttribGetStr(ih, "TIPFONT"); if (value) { if (iupStrEqualNoCase(value, "SYSTEM")) fontlist = NULL; else fontlist = iupmotGetFontList(iupAttribGet(ih, "TIPFOUNDRY"), value); } if (fontlist) XtVaSetValues(mot_tips.Label, XmNfontList, fontlist, NULL); } /* set label contents */ iupmotSetString(mot_tips.Label, XmNlabelString, tipText); /* set label size */ { int lw = 0, lh = 0; iupdrvFontGetMultiLineStringSize(ih, tipText, &lw, &lh); /* add room for margin */ lw += 2*(2); lh += 2*(2); XtVaSetValues(mot_tips.Label, XmNwidth, (XtArgVal)lw, XmNheight, (XtArgVal)lh, NULL); XtVaSetValues(mot_tips.Dialog, XmNwidth, (XtArgVal)lw, XmNheight, (XtArgVal)lh, NULL); } mot_tips.ShowTimerId = (XtIntervalId) NULL; mot_tips.HideTimerId = (XtIntervalId) NULL; mot_tips.Visible = FALSE; mot_tips.ShowInterval = 500; /* 1/2 second to show */ { int delay = IupGetInt(ih, "TIPDELAY"); /* must use IupGetInt to use inheritance */ mot_tips.HideInterval = delay + mot_tips.ShowInterval; } return TRUE; }
static Boolean create_pixmap(Widget parent, int iconidx, Pixmap *sen, Pixmap *insen) { static Boolean first_time = True; static Window rootWindow; static XpmColorSymbol color[5] = { {"none", "none", 0}, {"iconColor1", NULL, 0}, {"bottomShadowColor", NULL, 0}, {"topShadowColor", NULL, 0}, {"selectColor", NULL, 0} }; static int screenNum; static Pixmap tools_map; static Pixmap tools_mask; static Pixmap shade_map; static Pixmap shade_mask; int status = 0; XpmAttributes attr; Pixmap map; Pixmap mask; static String pixmap_file_path = NULL; /* note: never free()d */ ASSERT(iconidx >= 0, "index must be positive"); if (first_time) { /* FIXME: We use a dummy window here to get the correct depth/visual for the pixmap creation (cant use globals.widgets.top_level since it's not realized yet and realizing it now would result in wrong dimensions) ... */ Widget dummy = XtVaAppCreateShell("xdvi", "Xdvi", transientShellWidgetClass, DISP, XtNdepth, G_depth, XtNvisual, G_visual, XtNcolormap, G_colormap, XtNmappedWhenManaged, False, NULL); XtRealizeWidget(dummy); /* note: doesn't pop it up */ rootWindow = XtWindow(dummy); screenNum = DefaultScreen(XtDisplay(globals.widgets.top_level)); ASSERT(rootWindow != 0, ""); XtVaGetValues(parent, XmNbackground, &color[BACKGROUND].pixel, XmNforeground, &color[FOREGROUND].pixel, XmNbottomShadowColor, &color[BOTTOM_SHADOW].pixel, XmNtopShadowColor, &color[TOP_SHADOW].pixel, XmNhighlightColor, &color[HIGHLIGHT].pixel, NULL); /* try to locate the XPM file with the toolbar pixmaps */ pixmap_file_path = XtResolvePathname(DISP, "pixmaps", resource.toolbar_pixmap_file, (String)NULL, /* suffix */ (String)NULL, /* use default path */ (Substitution)NULL, /* substitutions */ 0, /* number of substitutions */ (XtFilePredicate)NULL); /* return True iff file exists */ TRACE_GUI((stderr, "pixmap file search via XtResolvePathname: %s => %s", resource.toolbar_pixmap_file, pixmap_file_path ? (char*)pixmap_file_path : "<NULL>")); if (pixmap_file_path == NULL) { pixmap_file_path = (String)kpse_find_file(resource.toolbar_pixmap_file, kpse_program_text_format, 0); TRACE_GUI((stderr, "pixmap file search via kpse_find_file: %s => %s", resource.toolbar_pixmap_file, pixmap_file_path ? (char*)pixmap_file_path : "<NULL>")); if (pixmap_file_path == NULL) { TRACE_GUI((stderr, "No installed toolbar pixmap found, using built-in pixmap.")); } } } /* Setup the color subsititution table */ attr.valuemask = XpmColorSymbols | XpmCloseness | XpmColormap | XpmDepth | XpmVisual; attr.closeness = 65535; /* accuracy isn't crucial */ attr.colorsymbols = color; attr.numsymbols = XtNumber(color); attr.visual = G_visual; attr.colormap = G_colormap; attr.depth = G_depth; /* Create the "sensitive" pixmap */ if (!tools_map) { if (pixmap_file_path != NULL) { status = XpmReadFileToPixmap(XtDisplay(globals.widgets.top_level), rootWindow, pixmap_file_path, &tools_map, &tools_mask, &attr); } else { status = XpmCreatePixmapFromData(XtDisplay(globals.widgets.top_level), rootWindow, (char **)toolbar_xpm, &tools_map, &tools_mask, &attr); } } else status = XpmSuccess; map = tools_map; mask = tools_mask; if (status == XpmSuccess) { static Pixmap tmp_mask; static GC gc; if (first_time) { tmp_mask = XCreatePixmap(XtDisplay(globals.widgets.top_level), rootWindow, PIXMAP_WIDTH, PIXMAP_HEIGHT, 1); gc = XCreateGC(XtDisplay(globals.widgets.top_level), tmp_mask, 0, NULL); } XCopyArea(XtDisplay(globals.widgets.top_level), mask, tmp_mask, gc, iconidx * PIXMAP_WIDTH, 0, PIXMAP_WIDTH, PIXMAP_HEIGHT, 0, 0); mask = tmp_mask; } else { /* something went wrong */ popup_message(globals.widgets.top_level, MSG_ERR, "Something's wrong with your XPM file - " "try to load it into an image editor and fix the problem.", "Xpm error: %s - switching toolbar off.", XpmGetErrorString(status)); sen = insen = NULL; resource.expert_mode ^= XPRT_SHOW_TOOLBAR; return False; } XpmFreeAttributes(&attr); if (map != 0) { static GC back_gc, bots_gc; if (first_time) { XGCValues gcvalues; gcvalues.foreground = color[BACKGROUND].pixel; back_gc = XCreateGC(XtDisplay(globals.widgets.top_level), rootWindow, GCForeground, &gcvalues); gcvalues.foreground = color[BOTTOM_SHADOW].pixel; bots_gc = XCreateGC(XtDisplay(globals.widgets.top_level), rootWindow, GCForeground, &gcvalues); } /* Need to create new Pixmaps with the mask applied. */ XSetClipMask(XtDisplay(globals.widgets.top_level), bots_gc, mask); /* Create the "sensitive" pixmap. */ *sen = XCreatePixmap(XtDisplay(globals.widgets.top_level), rootWindow, PIXMAP_WIDTH, PIXMAP_HEIGHT, G_depth); XFillRectangle(XtDisplay(globals.widgets.top_level), *sen, back_gc, 0, 0, PIXMAP_WIDTH, PIXMAP_HEIGHT); if (iconidx != -1) XCopyArea(XtDisplay(globals.widgets.top_level), map, *sen, bots_gc, iconidx * PIXMAP_WIDTH, 0, PIXMAP_WIDTH, PIXMAP_HEIGHT, 0, 0); else XCopyArea(XtDisplay(globals.widgets.top_level), map, *sen, bots_gc, 0, 0, PIXMAP_WIDTH, PIXMAP_HEIGHT, 0, 0); if (iconidx == -1) XFreePixmap(XtDisplay(globals.widgets.top_level), map); /* Create the "insensitive" pixmap. */ if (insen != NULL) { Pixmap map; Pixmap mask; attr.valuemask = XpmColorSymbols | XpmCloseness | XpmColorKey | XpmColormap | XpmDepth | XpmVisual; attr.closeness = 65535; /* accuracy isn't crucial */ attr.colorsymbols = color; attr.numsymbols = XtNumber(color); attr.color_key = XPM_MONO; attr.visual = G_visual; attr.colormap = G_colormap; attr.depth = G_depth; if (!shade_map) { if (pixmap_file_path != NULL) { status = XpmReadFileToPixmap(XtDisplay(globals.widgets.top_level), rootWindow, pixmap_file_path, &shade_map, &shade_mask, &attr); } else { status = XpmCreatePixmapFromData(XtDisplay(globals.widgets.top_level), rootWindow, (char **)toolbar_xpm, &shade_map, &shade_mask, &attr); } } else status = XpmSuccess; map = shade_map; mask = shade_mask; if (status == XpmSuccess) { static Pixmap tmp_mask; static GC gc; if (first_time) { tmp_mask = XCreatePixmap(XtDisplay(globals.widgets.top_level), rootWindow, PIXMAP_WIDTH, PIXMAP_HEIGHT, 1); gc = XCreateGC(XtDisplay(globals.widgets.top_level), tmp_mask, 0, NULL); } XCopyArea(XtDisplay(globals.widgets.top_level), mask, tmp_mask, gc, iconidx * PIXMAP_WIDTH, 0, PIXMAP_WIDTH, PIXMAP_HEIGHT, 0, 0); mask = tmp_mask; } else { /* something went wrong */ popup_message(globals.widgets.top_level, MSG_ERR, "Something's wrong with your XPM file - " "try to load it into an image editor and fix the problem.", "Xpm error: %s - switching toolbar off.", XpmGetErrorString(status)); sen = insen = NULL; resource.expert_mode ^= XPRT_SHOW_TOOLBAR; return False; } if (mask != 0) { static GC tops_gc; if (first_time) { XGCValues gcvalues; gcvalues.foreground = color[TOP_SHADOW].pixel; tops_gc = XCreateGC(XtDisplay(globals.widgets.top_level), rootWindow, GCForeground, &gcvalues); } /* Need to create new Pixmaps with the mask applied. */ XSetClipMask(XtDisplay(globals.widgets.top_level), bots_gc, mask); XSetClipMask(XtDisplay(globals.widgets.top_level), tops_gc, mask); XSetClipOrigin(XtDisplay(globals.widgets.top_level), tops_gc, 1, 1); *insen = XCreatePixmap(XtDisplay(globals.widgets.top_level), rootWindow, PIXMAP_WIDTH, PIXMAP_HEIGHT, G_depth); XFillRectangle(XtDisplay(globals.widgets.top_level), *insen, back_gc, 0, 0, PIXMAP_WIDTH, PIXMAP_HEIGHT); XFillRectangle(XtDisplay(globals.widgets.top_level), *insen, tops_gc, 1, 1, PIXMAP_WIDTH - 1, PIXMAP_HEIGHT - 1); XFillRectangle(XtDisplay(globals.widgets.top_level), *insen, bots_gc, 0, 0, PIXMAP_WIDTH, PIXMAP_HEIGHT); if (iconidx == -1) XFreePixmap(XtDisplay(globals.widgets.top_level), map); } XpmFreeAttributes(&attr); } } first_time = False; return True; }
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; }
/* * ------------------------------------------------------------------------ * Name: PdmShellCreate * * Description: * * This function creates a top level application shell. * * Return value: * * 0 if successful; a PDM_EXIT code if not. * */ static int PdmShellCreate(PdmShell* me, const String* fallback_resources, int* argc_in_out, String* argv_in_out) { String app_class; String app_name; XmPixelSet pixelSets[XmCO_NUM_COLORS]; XrmClass class_list[3]; XrmDatabase db; XrmName name_list[3]; XrmRepresentation rep_type; XrmValue value; int decor; int funcs; short secondary_id; /* * create the application context and open the video display */ XtToolkitInitialize(); XtSetLanguageProc((XtAppContext)NULL, (XtLanguageProc)NULL, (XtPointer)NULL); me->app_context = XtCreateApplicationContext(); XtAppSetFallbackResources(me->app_context, (String*)fallback_resources); me->display = XtOpenDisplay(me->app_context, (String)NULL, (String)NULL, "Dtpdm", PdmOptions, XtNumber(PdmOptions), argc_in_out, argv_in_out); if((Display*)NULL == me->display) return PDM_EXIT_VXAUTH; XtGetApplicationNameAndClass(me->display, &app_name, &app_class); /* * the fallback resources are only intended for the video display, so * remove them from the application context */ XtAppSetFallbackResources(me->app_context, (String*)NULL); /* * get the parent video window id from the display's resource database */ db = XtDatabase(me->display); name_list[0] = XrmStringToQuark(app_name); name_list[1] = XrmStringToQuark("parentWindowStr"); name_list[2] = NULLQUARK; class_list[0] = XrmStringToQuark(app_class); class_list[1] = XrmStringToQuark("ParentWindowStr"); class_list[2] = NULLQUARK; XrmQGetResource(db, name_list, class_list, &rep_type, &value); if(!value.addr) return PDM_EXIT_ERROR; me->parent_window = (Window)strtoul((char*)value.addr, (char**)NULL, 0); /* * obtain the parent video window's attributes */ if(!XGetWindowAttributes(me->display, me->parent_window, &me->parent_attr)) return PDM_EXIT_ERROR; /* * register interest in the DestroyNotify event for the parent window */ XSelectInput(me->display, me->parent_window, StructureNotifyMask); /* * create the application shell */ decor = MWM_DECOR_ALL | MWM_DECOR_RESIZEH | MWM_DECOR_MINIMIZE | MWM_DECOR_MAXIMIZE; funcs = MWM_FUNC_ALL | MWM_FUNC_RESIZE | MWM_FUNC_MINIMIZE | MWM_FUNC_MAXIMIZE; me->widget = XtVaAppCreateShell(app_name, app_class, applicationShellWidgetClass, me->display, XmNdeleteResponse, XmDESTROY, XmNmappedWhenManaged, False, XmNmwmDecorations, decor, XmNmwmFunctions, funcs, XmNmwmInputMode,MWM_INPUT_PRIMARY_APPLICATION_MODAL, XmNscreen, me->parent_attr.screen, XmNtransient, True, NULL); /* * pick up the secondary color set, so that the PDM presents the same * colors as a secondary window. (the XmColorObj is created by the * the XmDisplay object, which is created when the app shell is * created) */ if(XmeGetColorObjData(XtScreen(me->widget), (int*)NULL, pixelSets, XmCO_NUM_COLORS, (short*)NULL, (short*)NULL, (short*)NULL, &secondary_id, (short*)NULL)) { /* * In the Xrm database, reassign primary color resource values * with the corresponding secondary color values. This will cause * subsequently created widgets that utilize colors from the * primary set to actually present secondary colors. */ db = XtScreenDatabase(XtScreen(me->widget)); value.size = sizeof(Pixel); value.addr = (char*)&pixelSets[secondary_id].bg; XrmPutResource (&db, "*background", "Pixel", &value); XrmPutResource (&db, "*frameBackground", "Pixel", &value); value.addr = (char*)&pixelSets[secondary_id].fg; XrmPutResource (&db, "*foreground", "Pixel", &value); XrmPutResource (&db, "*backPageForeground", "Pixel", &value); value.addr = (char*)&pixelSets[secondary_id].bs; XrmPutResource (&db, "*bottomShadowColor", "Pixel", &value); value.addr = (char*)&pixelSets[secondary_id].ts; XrmPutResource (&db, "*topShadowColor", "Pixel", &value); } /* * get the application resources */ XtGetApplicationResources(me->widget, me, PdmResources, XtNumber(PdmResources), NULL, 0); /* * return */ return 0; }
void create_main_window() { Display *disp; int screen; disp = XtDisplay(overview_shell); screen = DefaultScreen(disp); /* Create top level shell widget */ top_level_widget = XtVaAppCreateShell("xregion","XRegion", applicationShellWidgetClass,disp, NULL); /* Create form widget to hold everything else */ box_widget = XtVaCreateManagedWidget("box", formWidgetClass, top_level_widget, XtNbackground, DEFAULT_BG, XtNforeground, DEFAULT_FG, NULL); /* Create the label to hold the title */ (void) strcpy(title, "Array Access Display"); title_widget = XtVaCreateManagedWidget("title", labelWidgetClass, box_widget, XtNbackground, DEFAULT_BG, XtNforeground, DEFAULT_FG, XtNx, 10, XtNy, 5, XtNwidth, 300, XtNlabel, title, XtNborderWidth, 0, NULL); coord_widget = XtVaCreateManagedWidget("coords", labelWidgetClass, box_widget, XtNbackground, DEFAULT_BG, XtNforeground, DEFAULT_FG, XtNy, 5, XtNhorizDistance, 10, XtNfromHoriz, title_widget, XtNjustify, XtJustifyLeft, XtNlabel, "Coordinates x, y: ", XtNborderWidth, 0, NULL); /* Create the Quit command button */ quit_button = XtVaCreateManagedWidget("quit", commandWidgetClass, box_widget, XtNbackground, DEFAULT_BG, XtNforeground, DEFAULT_FG, XtNx, 10, XtNvertDistance, 15, XtNfromVert, title_widget, XtNlabel, "Quit", XtNshapeStyle, XmuShapeOval, NULL); XtAddCallback(quit_button, XtNcallback, Quit, NULL); /* Create the Start/Stop command button */ start_stop_button = XtVaCreateManagedWidget("start/stop", commandWidgetClass, box_widget, XtNbackground, DEFAULT_BG, XtNforeground, DEFAULT_FG, XtNvertDistance, 15, XtNfromVert, title_widget, XtNhorizDistance, 10, XtNfromHoriz, quit_button, XtNlabel, "Start", XtNshapeStyle, XmuShapeOval, NULL); XtAddCallback(start_stop_button, XtNcallback, StartStop, NULL); /* Create the scroll bar for the interval */ interval_label = XtVaCreateManagedWidget("interval_label", labelWidgetClass, box_widget, XtNbackground, DEFAULT_BG, XtNforeground, DEFAULT_FG, XtNvertDistance, 5, XtNfromVert, title_widget, XtNhorizDistance, 20, XtNfromHoriz, start_stop_button, XtNlabel, "Time Interval", XtNborderWidth, 0, NULL); scroll_widget = XtVaCreateManagedWidget("scroll", scrollbarWidgetClass, box_widget, XtNbackground, DEFAULT_BG, XtNforeground, DEFAULT_FG, XtNvertDistance, 5, XtNfromVert, interval_label, XtNhorizDistance, 20, XtNfromHoriz, start_stop_button, XtNorientation, XtorientHorizontal, XtNlength, 100, XtNthickness, 15, NULL); XtAddCallback(scroll_widget, XtNscrollProc, ScrollProc, NULL); XtAddCallback(scroll_widget, XtNjumpProc, JumpProc, NULL); /* Create the label widget which displays the interval value associated with the scrollbar. */ (void) sprintf(interval_string, "%4d ms", interval); interval_widget = XtVaCreateManagedWidget("interval", labelWidgetClass, box_widget, XtNbackground, DEFAULT_BG, XtNforeground, DEFAULT_FG, XtNvertDistance, 5, XtNfromVert, interval_label, XtNhorizDistance, 5, XtNfromHoriz, scroll_widget, XtNjustify, XtJustifyRight, XtNlabel, interval_string, XtNborderWidth, 0, NULL); /* Create the scroll bar for the slowdown */ slowdown_label = XtVaCreateManagedWidget("slowdown_label", labelWidgetClass, box_widget, XtNbackground, DEFAULT_BG, XtNforeground, DEFAULT_FG, XtNvertDistance, 5, XtNfromVert, title_widget, XtNhorizDistance, 25, XtNfromHoriz, interval_widget, XtNlabel, "Slowdown Factor", XtNborderWidth, 0, NULL); scroll_widget2 = XtVaCreateManagedWidget("scroll2", scrollbarWidgetClass, box_widget, XtNbackground, DEFAULT_BG, XtNforeground, DEFAULT_FG, XtNvertDistance, 5, XtNfromVert, slowdown_label, XtNhorizDistance, 25, XtNfromHoriz, interval_widget, XtNorientation, XtorientHorizontal, XtNlength, 100, XtNthickness, 15, NULL); XtAddCallback(scroll_widget2, XtNscrollProc, ScrollProc2, NULL); XtAddCallback(scroll_widget2, XtNjumpProc, JumpProc2, NULL); /* Create the label widget which displays the slowdown value associated with the scrollbar 2. */ (void) sprintf(slowdown_string, "%5d times", (long)slowdown); slowdown_widget = XtVaCreateManagedWidget("slowdown", labelWidgetClass, box_widget, XtNbackground, DEFAULT_BG, XtNforeground, DEFAULT_FG, XtNvertDistance, 5, XtNfromVert, slowdown_label, XtNhorizDistance, 5, XtNfromHoriz, scroll_widget2, XtNjustify, XtJustifyRight, XtNlabel, slowdown_string, XtNborderWidth, 0, NULL); /* Now add the actual canvas ... */ canvas_widget = XtVaCreateManagedWidget("canvas", formWidgetClass, box_widget, XtNheight, pict_height * scale, XtNwidth, pict_width * scale, XtNvertDistance, 20, XtNfromVert, quit_button, XtNbackground, CANVAS_COLOR, XtNborderWidth, 0, NULL); /* Add callback for exposure */ XtAddEventHandler(canvas_widget,ExposureMask,False,Exposed,NULL); XtAddEventHandler(canvas_widget,PointerMotionMask,False,running_coords,NULL); /* Now add the color scale ... */ map_widget = XtVaCreateManagedWidget("colorMap", compositeWidgetClass, box_widget, XtNbackground, DEFAULT_BG, XtNforeground, DEFAULT_FG, XtNheight, 350, XtNwidth, 80, XtNvertDistance, 20, XtNfromVert, quit_button, XtNhorizDistance, 20, XtNfromHoriz, canvas_widget, XtNborderWidth, 0, NULL); }