I am presenting here a diff with a couple changes to XmString.c.
One is a change that I thought I sumbmitted a while back to make
XmStringCompare cope if both strings are in iso10646 (Unicode)
encoding. Since Unicode is 2 bytes per character, the regular strcmp()
call didn't work.
The other change is something more experimental. We had people
complaining about the ugly sitppled text for disabled widgets, so I
modified _XmStringDraw and _XmStringDrawUnderline in a rather Evil way
(it's inside an #ifdef STIPPLED_TEXT_OVERRIDE_HACK, which is not defined
by default, so it won't hurt to apply the patch even if you don't want
this feature) I'm making the big assumption that anybody calling
XmStringDraw with a GC set to stipple is meaning to render "disabled"
text and wouldn't mind if we override their stipple and disable it a
different way.
If the gc passed in has fill_style set to FillStippled, it cheats. It
sets a local gc to solid white and calls itself with a point down and to
the right by one pixel. It then computes a color halfway between the
foreground and background color and draws the text again at the normal
location using that color but no sitpple. The result is text that looks
dimmed and "etched in", and I think it looks quite good. Much better
than stippled text which was unreadable most of the time anyway.
I'd rather have the "white" be the top border color, but I didn't know
how to get at that.
I would like to discuss how best to activate/deactivate this
modification. Currently it's a #define and enabled or not at compile time.
I think a function to set a static variable for turning it on and off
might be a better idea though.
It could also be modified to have 3 modes
1. Stippled (the current way)
2. Dimmed and 3D (my current implementation)
3. Dimmed (same as my above description but only draw once, skipping
the white pass)
Does anybody have any thoughts on this?
Is anybody still on this list, or has everybody unsubscribed due to the
high volume of spam?
Dave Williss
MicroImages, Inc.
ps. I just noticed that the indenting is all messed up in the diff. I
edited with tabs set to 3 instead of 8. Sorry.
*** \\10.0.0.1\dwilliss\lesstif\lesstif\lib\Xm-2.1\XmString.c Wed Apr 19
18:42:22 2006 UTC
--- c:\home\dev\tnt73\xlibs\lesstif\lib\Xm-2.1\XmString.c Tue Aug 14
21:46:13 2007 UTC
***************
*** 360,365 ****
return (len);
}
static _XmString
__XmAllocNewXmString(int number_of_components)
{
--- 360,380 ----
return (len);
}
+ /* Compare two Unicode strings */
+ static int _ucstrcmp (
+ const unicode_t *p1,
+ const unicode_t *p2
+ ) {
+ int diff;
+
+ while (*p1 && *p2) {
+ if ((diff = *p1++ - *p2++) != 0) return (diff);
+ }
+ if (*p1) return (*p1);
+ else if (*p2) return (-*p2);
+ return (0);
+ }
+
static _XmString
__XmAllocNewXmString(int number_of_components)
{
***************
*** 2342,2347 ****
XmRendition r, rend = NULL;
XmTabList tl;
GC mygc;
if (w == 0 || string == 0) {
return;
--- 2357,2363 ----
XmRendition r, rend = NULL;
XmTabList tl;
GC mygc;
+ XGCValues GCValues;
if (w == 0 || string == 0) {
return;
***************
*** 2369,2374 ****
mygc = XCreateGC(d, w, 0, NULL);
XCopyGC(d, gc, ~0, mygc);
pending_newlines = 0;
have_line_height = False;
clipped = False;
--- 2385,2421 ----
mygc = XCreateGC(d, w, 0, NULL);
XCopyGC(d, gc, ~0, mygc);
+ #ifdef STIPPLED_TEXT_OVERRIDE_HACK
+ // BEGIN MICROIMAGES ADDITION
+ XGetGCValues(d, mygc, GCFillStyle|GCForeground|GCBackground, &GCValues);
+ if (GCValues.fill_style == FillStippled) {
+ static Pixel s_LastForeground, s_DimPixel;
+ static int s_ColorComputed;
+ if (!s_ColorComputed || s_LastForeground !=
GCValues.foreground) {
+ XColor defs[2];
+ defs[0].pixel = GCValues.foreground;
+ defs[1].pixel = GCValues.background;
+ defs[0].flags = defs[1].flags = DoRed | DoGreen | DoBlue;
+ XQueryColors(d, DefaultColormap(d,0), defs, 2);
+ defs[0].red = (unsigned short)(((int)defs[0].red + defs[1].red) /
2);
+ defs[0].green = (unsigned short)(((int)defs[0].green +
defs[1].green) / 2);
+ defs[0].blue = (unsigned short)(((int)defs[0].blue +
defs[1].blue) / 2);
+ XAllocColor(d, DefaultColormap(d,0), defs);
+ s_DimPixel = defs[0].pixel;
+ s_LastForeground = GCValues.foreground;
+ s_ColorComputed = TRUE;
+ }
+
+ GCValues.fill_style = FillSolid;
+ GCValues.foreground = WhitePixel(d, 0);
+ XChangeGC(d, mygc, GCFillStyle|GCForeground, &GCValues);
+ _XmStringDraw(d, w, fontlist, string, mygc, x+1, y+1, width,
align, lay_dir, clip);
+ GCValues.foreground = s_DimPixel;
+ XChangeGC(d, mygc, GCForeground, &GCValues);
+ }
+ // END MICROIMAGES ADDITION
+ #endif
+
pending_newlines = 0;
have_line_height = False;
clipped = False;
***************
*** 3114,3125 ****
Dimension default_line_height;
XRectangle ink, log;
int pending_newlines;
if (w == 0)
{
return;
}
DEBUGOUT(_LtDebug(__FILE__, XtWindowToWidget(d, w),
"_XmStringDrawUnderline x %d y %d wid %d\n",
x, y, width));
--- 3161,3208 ----
Dimension default_line_height;
XRectangle ink, log;
int pending_newlines;
+ XGCValues GCValues; // MicroImages
if (w == 0)
{
return;
}
+ #ifdef STIPPLED_TEXT_OVERRIDE_HACK
+ // BEGIN MICROIMAGES ADDITION
+ XGetGCValues(d, gc, GCFillStyle|GCForeground|GCBackground, &GCValues);
+ if (GCValues.fill_style == FillStippled) {
+ static Pixel s_LastForeground, s_DimPixel;
+ static int s_ColorComputed;
+ GC mygc = XCreateGC(d, w, 0, NULL);
+ XCopyGC(d, gc, ~0, mygc);
+ if (!s_ColorComputed || s_LastForeground != GCValues.foreground) {
+ XColor defs[2];
+ defs[0].pixel = GCValues.foreground;
+ defs[1].pixel = GCValues.background;
+ defs[0].flags = defs[1].flags = DoRed | DoGreen | DoBlue;
+ XQueryColors(d, DefaultColormap(d,0), defs, 2);
+ defs[0].red = (unsigned short)(((int)defs[0].red + defs[1].red) /
2);
+ defs[0].green = (unsigned short)(((int)defs[0].green +
defs[1].green) / 2);
+ defs[0].blue = (unsigned short)(((int)defs[0].blue + defs[1].blue)
/ 2);
+ XAllocColor(d, DefaultColormap(d,0), defs);
+ s_DimPixel = defs[0].pixel;
+ s_LastForeground = GCValues.foreground;
+ s_ColorComputed = TRUE;
+ }
+
+ GCValues.fill_style = FillSolid;
+ GCValues.foreground = WhitePixel(d, 0);
+ XChangeGC(d, mygc, GCFillStyle|GCForeground, &GCValues);
+ _XmStringDrawUnderline(d, w, fontlist, string, mygc, x+1, y+1, width,
align, lay_dir, clip, underline);
+ GCValues.foreground = s_DimPixel;
+ XChangeGC(d, mygc, GCForeground, &GCValues);
+ _XmStringDrawUnderline(d, w, fontlist, string, mygc, x+1, y+1, width,
align, lay_dir, clip, underline);
+ XFreeGC(d, mygc);
+ return;
+ }
+ // END MICROIMAGES ADDITION
+ #endif
DEBUGOUT(_LtDebug(__FILE__, XtWindowToWidget(d, w),
"_XmStringDrawUnderline x %d y %d wid %d\n",
x, y, width));
***************
*** 3722,3728 ****
{
XmStringContext context1 = NULL, context2 = NULL;
char *text1, *text2, *tag1, *tag2;
! Boolean separator1, separator2, compare_tags;
XmStringDirection direction1, direction2;
if (!_XmStringIsXmString(s1) || !_XmStringIsXmString(s2))
--- 3805,3811 ----
{
XmStringContext context1 = NULL, context2 = NULL;
char *text1, *text2, *tag1, *tag2;
! Boolean separator1, separator2, compare_tags, both_unicode;
XmStringDirection direction1, direction2;
if (!_XmStringIsXmString(s1) || !_XmStringIsXmString(s2))
***************
*** 3743,3757 ****
XmStringFreeContext(context2);
return False;
}
! compare_tags = (strcmp(tag1, XmFONTLIST_DEFAULT_TAG) != 0 &&
strcmp(tag2, XmFONTLIST_DEFAULT_TAG) != 0);
/* Don't compare tags when one of them = XmFONTLIST_DEFAULT_TAG */
/*
printf("%p %p\n>%s< >%s<\n%i %i\n%i %i\n", text1, text2, text1, text2,
direction1, direction2, separator1, separator2);
*/
if (
((text1 == NULL || text2 == NULL) && text1 != text2)
! || (text1 != text2 && strcmp(text1, text2) != 0) /* diferent text */
|| direction1 != direction2
|| (compare_tags && strcmp(tag1, tag2) != 0)
|| separator1 != separator2
--- 3826,3847 ----
XmStringFreeContext(context2);
return False;
}
! /* Unicode support added 31-Oct-06, dwilliss */
! both_unicode = (strncasecmp(tag1, "iso10646", 8) == 0 &&
! strncasecmp(tag2, "iso10646", 8) == 0);
!
! compare_tags = (!both_unicode &&
! strcmp(tag1, XmFONTLIST_DEFAULT_TAG) != 0 &&
strcmp(tag2, XmFONTLIST_DEFAULT_TAG) != 0);
+
/* Don't compare tags when one of them = XmFONTLIST_DEFAULT_TAG */
/*
printf("%p %p\n>%s< >%s<\n%i %i\n%i %i\n", text1, text2, text1, text2,
direction1, direction2, separator1, separator2);
*/
if (
((text1 == NULL || text2 == NULL) && text1 != text2)
! || (!both_unicode && text1 != text2 && strcmp(text1, text2) != 0)
/* diferent text */
! || (both_unicode && text1 != text2 && _ucstrcmp((unicode_t*)text1,
(unicode_t*)text2) != 0) /* diferent text */
|| direction1 != direction2
|| (compare_tags && strcmp(tag1, tag2) != 0)
|| separator1 != separator2
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Lesstif-discuss mailing list
Lesstif-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lesstif-discuss