int workshop_get_font_height() { XmFontList fontList; /* fontList made from gui.norm_font */ XmString str; Dimension w; Dimension h; #ifdef WSDEBUG_TRACE if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) wstrace("workshop_get_font_height()\n"); #endif /* Pick the proper signs for this font size */ fontList = gui_motif_create_fontlist((XFontStruct *)gui.norm_font); h = 0; if (fontList != NULL) { str = XmStringCreateLocalized("A"); XmStringExtent(fontList, str, &w, &h); XmStringFree(str); XmFontListFree(fontList); } return (int)h; }
void MotifUI::StringWidthHeight(const char *string, int *width, int *height) { Dimension w, h; XmString xm_string = StringCreate((char *)string); XmStringExtent(userFont, xm_string, &w, &h); *width = w; *height = h; StringFree(xm_string); }
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); }
void XmLStringDraw(Widget w, XmString string, XmStringDirection stringDir, XmFontList fontList, unsigned char alignment, GC gc, XRectangle *rect, XRectangle *clipRect) { Display *dpy; Window win; Dimension width, height; int x, y, drawType; unsigned char strAlignment; if (!string) return; dpy = XtDisplay(w); win = XtWindow(w); XmStringExtent(fontList, string, &width, &height); drawType = XmLDrawCalc(w, width, height, alignment, rect, clipRect, &x, &y); if (drawType == XmLDrawNODRAW) return; x = rect->x + 2; if (alignment == XmALIGNMENT_LEFT || alignment == XmALIGNMENT_TOP_LEFT || alignment == XmALIGNMENT_BOTTOM_LEFT) strAlignment = XmALIGNMENT_BEGINNING; else if (alignment == XmALIGNMENT_CENTER || alignment == XmALIGNMENT_TOP || alignment == XmALIGNMENT_BOTTOM) if (width <= rect->width - 4) strAlignment = XmALIGNMENT_CENTER; else strAlignment = XmALIGNMENT_BEGINNING; else strAlignment = XmALIGNMENT_END; /* XmStringDraw clipping doesnt work in all cases so we use a clip region for clipping */ if (drawType == XmLDrawCLIPPED) XSetClipRectangles(dpy, gc, 0, 0, clipRect, 1, Unsorted); XmStringDraw(dpy, win, fontList, string, gc, x, y, rect->width - 4, strAlignment, stringDir, clipRect); if (drawType == XmLDrawCLIPPED) XSetClipMask(dpy, gc, None); }
void Container::UpdateAreaMessage(Widget widget, XtPointer client_data, XEvent * /*event*/, Boolean * /*continued*/) { unsigned char direction; XGCValues values; XtGCMask valueMask; Dimension width, height; Dimension w, h; int x, y; static GC gc = (GC) NULL; Container *container = (Container *) client_data; if (!container->_xm_update_message) return; if (!gc) { XtVaGetValues(widget, XmNforeground, &values.foreground, NULL); if (container->font) valueMask = GCFont | GCForeground; else valueMask = GCForeground; values.font = container->font; gc = XCreateGC(display, root, valueMask, &values); } XClearArea(display, XtWindow(widget), 0, 0, 0, 0, FALSE); XtVaGetValues(widget, XmNwidth, &width, XmNheight, &height, NULL); XtVaGetValues(container->_workArea, XmNstringDirection, &direction, NULL); XmStringExtent(container->userFont, container->_xm_update_message, &w, &h); x = (Dimension)(width - w) / 2; y = (Dimension)(height - h) / 2; XmStringDraw(display, XtWindow(widget), container->userFont, container->_xm_update_message, gc, x, y, w, XmALIGNMENT_CENTER, direction, NULL); }
void XmLDrawnButtonSetType(Widget w, int drawnType, int drawnDir) { XmLDrawnBData *dd; XmDrawnButtonWidget b; XmString str; XmFontList fontlist; XGCValues values; XtGCMask mask; Dimension width, height, dim; Dimension highlightThickness, shadowThickness; Dimension marginWidth, marginHeight; Dimension marginTop, marginBottom, marginLeft, marginRight; if (!XtIsSubclass(w, xmDrawnButtonWidgetClass)) { XmLWarning(w, "DrawnButtonSetType() - not an XmDrawnButton"); return; } XtVaSetValues(w, XmNpushButtonEnabled, True, NULL); XtRemoveAllCallbacks(w, XmNexposeCallback); XtRemoveAllCallbacks(w, XmNresizeCallback); if (drawnType == XmDRAWNB_STRING && drawnDir == XmDRAWNB_RIGHT) { XtVaSetValues(w, XmNlabelType, XmSTRING, NULL); return; } b = (XmDrawnButtonWidget)w; dd = (XmLDrawnBData *)malloc(sizeof(XmLDrawnBData)); dd->type = drawnType; dd->dir = drawnDir; dd->gc = 0; if (dd->type == XmDRAWNB_STRING) { XtVaGetValues(w, XmNlabelString, &str, XmNfontList, &fontlist, XmNhighlightThickness, &highlightThickness, XmNshadowThickness, &shadowThickness, XmNmarginHeight, &marginHeight, XmNmarginWidth, &marginWidth, XmNmarginTop, &marginTop, XmNmarginBottom, &marginBottom, XmNmarginLeft, &marginLeft, XmNmarginRight, &marginRight, NULL); if (!str && XtName(w)) str = XmStringCreateSimple(XtName(w)); if (!str) str = XmStringCreateSimple(""); XmStringExtent(fontlist, str, &width, &height); XmStringFree(str); if (drawnDir == XmDRAWNB_UP || drawnDir == XmDRAWNB_DOWN) { dim = width; width = height; height = dim; } height += (highlightThickness + shadowThickness + marginHeight) * 2 + marginTop + marginBottom; width += (highlightThickness + shadowThickness + marginWidth) * 2 + marginLeft + marginRight; /* change to pixmap type so label string isnt drawn */ XtVaSetValues(w, XmNlabelType, XmPIXMAP, NULL); XtVaSetValues(w, XmNwidth, width, XmNheight, height, NULL); XtAddCallback(w, XmNexposeCallback, XmLDrawnBDrawStringCB, (XtPointer)dd); XtAddCallback(w, XmNresizeCallback, XmLDrawnBDrawStringCB, (XtPointer)dd); } else { mask = GCForeground; values.foreground = b->primitive.foreground; dd->gc = XtGetGC(w, mask, &values); XtAddCallback(w, XmNexposeCallback, XmLDrawnBDrawCB, (XtPointer)dd); XtAddCallback(w, XmNresizeCallback, XmLDrawnBDrawCB, (XtPointer)dd); } XtAddCallback(w, XmNdestroyCallback, XmLDrawnBDestroyCB, (XtPointer)dd); }
void XmLStringDrawDirection(Display *dpy, Window win, XmFontList fontlist, XmString string, GC gc, int x, int y, Dimension width, unsigned char alignment, unsigned char layout_direction, unsigned char drawing_direction) { Screen *screen; XFontStruct *fontStruct; XImage *sourceImage, *destImage; Pixmap pixmap; GC pixmapGC; /* int sourceWidth, sourceHeight;*/ int destWidth, destHeight; int stringWidth, stringHeight; int i, j, bytesPerLine; Dimension dW, dH; char *data; screen = DefaultScreenOfDisplay(dpy); XmStringExtent(fontlist, string, &dW, &dH); stringWidth = (int)dW; stringHeight = (int)dH; if (!stringWidth || !stringHeight) return; /* draw string into 1 bit deep pixmap */ pixmap = XCreatePixmap(dpy, win, stringWidth, stringHeight, 1); pixmapGC = XCreateGC(dpy, pixmap, 0, NULL); fontStruct = XLoadQueryFont(dpy, "fixed"); if (!fontStruct) { fprintf(stderr, "XmLStringDrawDirection: error - "); fprintf(stderr, "can't load fixed font\n"); return; } XSetFont(dpy, pixmapGC, fontStruct->fid); XSetBackground(dpy, pixmapGC, 0L); XSetForeground(dpy, pixmapGC, 0L); XFillRectangle(dpy, pixmap, pixmapGC, 0, 0, stringWidth, stringHeight); XSetForeground(dpy, pixmapGC, 1L); XmStringDraw(dpy, pixmap, fontlist, string, pixmapGC, 0, 0, stringWidth, XmALIGNMENT_BEGINNING, layout_direction, 0); XFreeFont(dpy, fontStruct); /* copy 1 bit deep pixmap into source image */ sourceImage = XGetImage(dpy, pixmap, 0, 0, stringWidth, stringHeight, 1, XYPixmap); XFreePixmap(dpy, pixmap); /* draw rotated text into destination image */ if (drawing_direction == XmSTRING_UP || drawing_direction == XmSTRING_DOWN) { destWidth = stringHeight; destHeight = stringWidth; } else { destWidth = stringWidth; destHeight = stringHeight; } bytesPerLine = (destWidth - 1) / 8 + 1; data = (char *)malloc(bytesPerLine * destHeight); destImage = XCreateImage(dpy, DefaultVisualOfScreen(screen), 1, XYBitmap, 0, data, destWidth, destHeight, 8, 0); for (i = 0; i < stringWidth; i++) for (j = 0; j < stringHeight; j++) { if (drawing_direction == XmSTRING_UP) XPutPixel(destImage, j, i, XGetPixel(sourceImage, stringWidth - i - 1, j)); else if (drawing_direction == XmSTRING_DOWN) XPutPixel(destImage, stringHeight - j - 1, stringWidth - i - 1, XGetPixel(sourceImage, stringWidth - i - 1, j)); else if (drawing_direction == XmSTRING_LEFT) XPutPixel(destImage, i, stringHeight - j - 1, XGetPixel(sourceImage, stringWidth - i - 1, j)); else XPutPixel(destImage, i, j, XGetPixel(sourceImage, i, j)); } XDestroyImage(sourceImage); /* copy rotated image into 1 bit deep pixmap */ pixmap = XCreatePixmap(dpy, win, destWidth, destHeight, 1); XPutImage(dpy, pixmap, pixmapGC, destImage, 0, 0, 0, 0, destWidth, destHeight); XDestroyImage(destImage); XFreeGC(dpy, pixmapGC); /* adjust position for alignment */ if (drawing_direction == XmSTRING_UP || drawing_direction == XmSTRING_DOWN) { if (alignment == XmALIGNMENT_BEGINNING) ; else if (alignment == XmALIGNMENT_CENTER) y += width / 2 - stringWidth / 2; else if (alignment == XmALIGNMENT_END) y += (int)width - stringWidth; } else { if (alignment == XmALIGNMENT_BEGINNING) ; else if (alignment == XmALIGNMENT_CENTER) x += width / 2 - stringWidth / 2; else if (alignment == XmALIGNMENT_END) x += (int)width - stringWidth; } /* draw the pixmap as a stipple in the window */ XSetStipple(dpy, gc, pixmap); XSetFillStyle(dpy, gc, FillStippled); XSetTSOrigin(dpy, gc, x % destWidth, y % destHeight); XFillRectangle(dpy, win, gc, x, y, destWidth, destHeight); XFreePixmap(dpy, pixmap); XSetFillStyle(dpy, gc, FillSolid); }
void AttachArea::initialize() { // We're making the assumption here that this widget's parent` // is also a form XtWidgetGeometry size; Dimension parWid, parHeight; Dimension txt_w, txt_h; XmFontList fl; XmString xms; int colorUse; short act, inact, prim, second, text; XmPixelSet pixels[XmCO_NUM_COLORS]; _w = XtVaCreateManagedWidget ( "AttachPane", xmFormWidgetClass, _parent, NULL); // Get pixel data. XmeGetColorObjData(XtScreen(_parent), &colorUse, pixels, XmCO_NUM_COLORS, &act, &inact, &prim, &second, &text); _foreground = pixels[text].fg; _background = pixels[text].sc; parWid = _myOwner->textEditor()->get_text_width(); fl = _myOwner->textEditor()->get_text_fontList(); xms = XmStringCreateLocalized("Xyb"); XmStringExtent(fl, xms, &txt_w, &txt_h); parHeight = txt_h + Icon::maxIconHeight() + (2*VSPACE); _appBackground = _background; _appForeground = _foreground; _sw = XtVaCreateManagedWidget ( "AttachPane_ScrolledWindow", xmScrolledWindowWidgetClass, _w, XmNscrollingPolicy, XmAPPLICATION_DEFINED, XmNrightAttachment, XmATTACH_FORM, XmNleftAttachment, XmATTACH_FORM, XmNtopAttachment, XmATTACH_FORM, XmNshadowThickness, (Dimension)1, XmNspacing, 2, XmNwidth, parWid, XmNheight, parHeight, NULL); rowOfAttachmentsStatus = XtCreateManagedWidget("Attachments_Status", xmFormWidgetClass, _w, NULL, 0); XtVaSetValues(rowOfAttachmentsStatus, XmNrightAttachment, XmATTACH_FORM, XmNleftAttachment, XmATTACH_FORM, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, _sw, XmNtopOffset, 5, XmNbottomOffset, 5, NULL ); this->addToRowOfAttachmentsStatus(); size.request_mode = CWHeight; XtQueryGeometry(rowOfAttachmentsStatus, NULL, &size); XtVaSetValues( rowOfAttachmentsStatus, XmNpaneMaximum, size.height, XmNpaneMinimum, size.height, NULL ); _vsb = XtVaCreateManagedWidget("vsb", xmScrollBarWidgetClass, _sw, XmNorientation, XmVERTICAL, XmNsliderSize, 1, XmNmaximum, 1, XmNpageIncrement, 1, NULL); XtAddCallback( _vsb, XmNvalueChangedCallback,&AttachArea::valueChangedCallback, (XtPointer) this ); XtAddCallback( _vsb, XmNdragCallback, &AttachArea::dragCallback, (XtPointer) this ); _clipWindow = XtVaCreateManagedWidget("AttachArea_clipWindow", xmDrawingAreaWidgetClass, _sw, XmNresizePolicy, XmRESIZE_NONE, XmNbackground, _background, XmNwidth, parWid, XmNheight, parHeight, NULL); XmScrolledWindowSetAreas(_sw, NULL, _vsb, _clipWindow); XtManageChild(_clipWindow); XtManageChild(_vsb); XtManageChild(_sw); // Set RowCol to NULL here. // It gets set in the expose_all_attachments. _rc = NULL; CalcSizeOfAttachPane(); installDestroyHandler(); }