Exemplo n.º 1
0
int
main(int argc,
     char **argv)
{
    Widget toplevel;
    XtAppContext app;
    Dimension width, height;
    XmFontList fl;
    XmString xmstr, xmstr2, xmstr3;

    toplevel = XtVaAppInitialize(&app, "XmString", NULL, 0, &argc, argv, NULL, NULL);

    fl = _XmGetDefaultFontList(toplevel, XmTEXT_FONTLIST);

    xmstr = XmStringCreate("Hello World", XmFONTLIST_DEFAULT_TAG);
    xmstr2 = XmStringCreateLtoR("Hello\nWorld", XmFONTLIST_DEFAULT_TAG);
    xmstr3 = XmStringCreateLocalized("Céline Dion a chantée à Paris");

    XmStringExtent(fl, xmstr, &width, &height);

    printf ("String 'Hello World' has dimensions %dx%d\n", width, height);

    XmStringExtent(fl, xmstr2, &width, &height);

    printf ("String 'Hello\\nWorld' has dimensions %dx%d\n", width, height);

    PrintIt((char *)xmstr);
    PrintIt((char *)xmstr2);
    PrintIt((char *)xmstr3);

    printf("Trying XmStringCreateLtoR(NULL, XmFONTLIST_DEFAULT_TAG) ...\n");
    xmstr = XmStringCreateLtoR(NULL, XmFONTLIST_DEFAULT_TAG);
    printf("Result is %p\n", xmstr);

    printf("Trying XmStringCreateLtoR('This', NULL) ...\n");
    xmstr = XmStringCreateLtoR("This", NULL);
    printf("Result is %p\n", xmstr);
    exit(0);
}
Exemplo n.º 2
0
/**********************************************************************************
 * FUNCTIONS
 **********************************************************************************/
int video_open(PLOT *plot)
{
	struct videodata *plotdata;
	Display *dpy;
	Screen *scr;
	Widget w, mw, m0, m1, m2, m3;
	int status = SUCCESS;
	Dimension width, height;
	int depth;
    XGCValues values;
	unsigned long foreground, background;
	XmString xmstr, xmstr1;
	Arg args[10];
	int n;

	plot->plotdata = (void *)calloc(1, sizeof(struct videodata));
	plotdata = (struct videodata *)plot->plotdata;
	plotdata->image = (XImage *)calloc(sizeof(XImage), 1);
	plotdata->framedata = NULL;
	plotdata->width = 0;
	plotdata->height = 0;
	plotdata->ncomps = 0;
	plotdata->microsecs_per_frame = 0;
	plotdata->colormap = defaults.colormap;
	plotdata->framenum = 0;
	plotdata->loadedframenum = -1;

	plot->plot_widget = XtVaCreateManagedWidget("video", xmDrawingAreaWidgetClass, plot->panel->panel_container,
		XmNheight, defaults.video_height,
		XmNwidth, defaults.width,
		XmNmarginHeight, 0,
		XmNmarginWidth, 0,
		NULL);
	XtAddCallback(plot->plot_widget, XmNexposeCallback, video_expose_callback, (XtPointer)plot);
	XtAddCallback(plot->plot_widget, XmNresizeCallback, video_resize_callback, (XtPointer)plot);

	w = (Widget)plot->plot_widget;
	dpy = XtDisplay(w);
	scr = XtScreen(w);

	XtVaGetValues(w,
		XmNheight, &height,
		XmNwidth, &width,
		XmNdepth, &depth,
		XmNforeground, &foreground,
		XmNbackground, &background,
		NULL);

	/*
	** Get the font;  also, calculate the margins for the axes (this depends on the font size!).
	** Store these margins for use later (we might start off without axes, and turn them on later.
	*/
	plot->ticklblfont = XmFontListCopy(_XmGetDefaultFontList(w, XmLABEL_FONTLIST));
	plot->minoffx = 6 + XmStringWidth(plot->ticklblfont, xmstr = XmStringCreateSimple("-32768")); XmStringFree(xmstr);
	plot->minoffx2 = 0;
	plot->minoffy = 0;
	plot->minoffy2 = 6 + XmStringHeight(plot->ticklblfont, xmstr = XmStringCreateSimple("1")); XmStringFree(xmstr);

	plot->offx = 0;
	plot->offy = 0;
	plot->offx2 = 0;
	plot->offy2 = 0;
	plot->width = width;
	plot->height = height;
	plot->depth = depth;

	/*
	** Allocate our colors.  We use the XCC code that is:
	** Copyright 1994,1995 John L. Cwikla
	** This allows us to work on any visual, etc.   The danger is that
	** we may not get the exact colors we ask for... meaning that things
	** may not really be as we see them.  This is unfortunate, but the
	** alternative is to not run at all (the old code crashed).  So...
	*/
	plotdata->ncolors = MIN(SONO_DEFAULT_MAX_COLORS, MIN(XDisplayCells(dpy, XDefaultScreen(dpy)), MAXCOLORS - RESERVED_COLORS));
	plotdata->xcc = XCCCreate(dpy, DefaultVisual(dpy, DefaultScreen(dpy)), TRUE, TRUE, XA_RGB_GRAY_MAP, &(plotdata->cmap));
	if (XCCGetNumColors(plotdata->xcc) < plotdata->ncolors)
	{
		plotdata->ncolors = XCCGetNumColors(plotdata->xcc);
		printf("Warning.  Using only %d colors.\n", plotdata->ncolors);
	}
	(*((colormap[plotdata->colormap]).cmap))(dpy, plotdata->ncolors, plotdata->colors, NULL);

	/*
	** Create the Graphics contexts.
	** drawing_GC is for the picture itself.  inverse_GC is for erasing.  mark_GC is for the subregion marks.
	*/
	values.font = getFontStruct(plot->ticklblfont)->fid;
	values.function = GXcopy;
	values.plane_mask = AllPlanes;
	values.foreground = foreground;
	values.background = background;
	plotdata->drawing_GC = XtGetGC(w, GCFunction | GCPlaneMask | GCForeground | GCBackground | GCFont, &values);
	values.foreground = background;
	values.background = background;
	plotdata->inverse_GC = XtGetGC(w, GCForeground | GCBackground, &values);
	values.function = GXxor;
	values.plane_mask = foreground ^ background;
	values.foreground = 0xffffffff;
	values.background = 0x0;
	values.line_style = LineSolid;
	plotdata->mark_GC = XtGetGC(w, GCFunction | GCPlaneMask | GCForeground | GCBackground | GCLineStyle, &values);

	plotdata->pixmap = XCreatePixmap(dpy, DefaultRootWindow(dpy), width, height, depth);
	plotdata->pixmapalloced = TRUE;
	XFillRectangle(dpy, plotdata->pixmap, plotdata->inverse_GC, 0, 0, width, height);

	/*
	** Create the popup menu
	** 
	*/
	n = 0;
	XtSetArg(args[n], XmNmenuPost, "<Btn3Down>"); n++;
	mw = plot->plot_popupmenu_widget = XmCreatePopupMenu(w, "popupmenu", args, n);

	m0 = XtVaCreateManagedWidget("m0", xmLabelGadgetClass, mw,
		XmNlabelString, xmstr1 = XmStringCreateSimple("Options"),
		NULL);
	XmStringFree(xmstr1);

	m1 = XtVaCreateManagedWidget("m1", xmSeparatorGadgetClass, mw,
		NULL);

	CreateMenuButton(m2, mw, "save", "Save", "Save");
	CreateMenuButton(m3, mw, "print", "Print EPS", "Print EPS");

	/*
	** Register an event handler
	*/
	XtAddEventHandler(w, KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | Button1MotionMask | Button2MotionMask,
		FALSE, (XtEventHandler) video_event_handler, (XtPointer)plot);

	plot->plot_display = video_display;
	plot->plot_set = video_set;
	plot->plot_close = video_close;
	plot->plot_print = video_print;

	plot->plot_playmarker = NULL;
	plot->plot_showvideoframe = video_showvideoframe;
	plot->plot_clearmarks = NULL;
	plot->plot_drawstartmark = NULL;
	plot->plot_drawstopmark = NULL;
	plot->plot_conv_pixel_to_time = NULL;

	plot->plot_save = video_save;

	plot->plot_event_handler = video_event_handler;
	plot->plot_play = video_play;

	plotdata->butgrabbed = FALSE;
	plot->playmark = -1;
	plot->markx1 = -1;
	plot->markx2 = -1;

	plot->group->needpcm = 1;

	return status;
}