From xemacs-m  Thu Sep 18 23:11:11 1997
Received: from server.sensei.co.uk (server.sensei.co.uk [193.132.124.5])
	by xemacs.org (8.8.5/8.8.5) with ESMTP id XAA20776
	for <xemacs-beta@xemacs.org>; Thu, 18 Sep 1997 23:11:08 -0500 (CDT)
Received: from cerise.sensei.co.uk (glynn@muvies.demon.co.uk [158.152.66.14]) by server.sensei.co.uk (8.8.5/8.8.2) with ESMTP id FAA10107; Fri, 19 Sep 1997 05:10:59 +0100
Received: (from glynn@localhost) by cerise.sensei.co.uk (8.8.5/8.8.2) id FAA18888; Fri, 19 Sep 1997 05:13:46 +0100
Date: Fri, 19 Sep 1997 05:13:46 +0100
Message-Id: <199709190413.FAA18888@cerise.sensei.co.uk>
From: Glynn Clements <glynn@sensei.co.uk>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="plsagKgdrn"
Content-Transfer-Encoding: 7bit
To: Joel Peterson <tarzan@aosi.com>
Cc: xemacs-beta@xemacs.org
Subject: Re: [Success] Bern, Linux
In-Reply-To: <3421B36C.9F19D1CA@aosi.com>
References: <199709172201.XAA08482@cerise.sensei.co.uk>
	<342094AE.1BD0243F@aosi.com>
	<199709180333.EAA09256@cerise.sensei.co.uk>
	<3421B36C.9F19D1CA@aosi.com>
X-Mailer: VM 6.34 under 20.3 "Minsk" XEmacs  Lucid (beta22)


--plsagKgdrn
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit


Joel Peterson wrote:

> The code which implements Lucid menubars does things slightly
> differently if Motif is present.
> 
> If no one else volunteers to fix the Motif rendering, I'll do it but it
> will have to wait until I get Motif (which won't be until I get a new
> CD-Rom drive to replace the one that doesn't work).

I've had a go at it.

The following patch seems to work, although it might be a good idea if
someone who is more familiar with XmString's than I am took a look at
it.

I'm assuming that the XmString consists of a single segment using
XmFONTLIST_DEFAULT_TAG.

-- 
Glynn Clements <glynn@sensei.co.uk>


--plsagKgdrn
Content-Type: text/plain
Content-Description: xlwmenu.c-diff
Content-Disposition: inline;
	filename="xlwmenu-patch"
Content-Transfer-Encoding: 7bit

--- xlwmenu.c.orig	Fri Sep 19 02:12:30 1997
+++ xlwmenu.c	Fri Sep 19 05:04:09 1997
@@ -390,7 +390,7 @@
 static int
 string_width_u (XlwMenuWidget mw,
 #ifdef NEED_MOTIF
-	      XmString s
+	      XmString string
 #else
 	      char *string
 #endif
@@ -398,30 +398,44 @@
 {
 #ifdef NEED_MOTIF
   Dimension width, height;
-  XmStringExtent (mw->menu.font_list, s, &width, &height);
-  return width;
+  XmString newstring;
 #else
 # ifdef USE_XFONTSET
   XRectangle ri, rl;
-  XmbTextExtents (mw->menu.font_set, string, strlen (string), &ri, &rl);
-  return rl.width;
 # else /* ! USE_XFONTSET */
   XCharStruct xcs;
-  int i,s=0,w=0;
   int drop;
-  for (i=0;string[i];++i) {
-    if (string[i]=='%'&&string[i+1]=='_') {
-      XTextExtents (mw->menu.font, &string[s], i-s, &drop, &drop, &drop, &xcs);
-      w += xcs.width;
-      s = i + 2;
-      ++i;
-    }
-  }
-  if (string[s]) {
-	  XTextExtents (mw->menu.font, &string[s], i-s, &drop, &drop, &drop, &xcs);
-	  w += xcs.width;
-  }
-  return w;
+# endif
+#endif
+  char newchars[64];
+  char *chars;
+  int i, j;
+
+#ifdef NEED_MOTIF
+  XmStringGetLtoR (string, XmFONTLIST_DEFAULT_TAG, &chars);
+#else
+  chars = string;
+#endif
+
+  for (i = j = 0; chars[i]; i++)
+    if (chars[i]=='%'&&chars[i+1]=='_')
+	    i++;
+    else
+	    newchars[j++] = chars[i];
+  newchars[j] = '\0';
+
+#ifdef NEED_MOTIF
+  newstring = XmStringLtoRCreate (newchars, XmFONTLIST_DEFAULT_TAG);
+  XmStringExtent (mw->menu.font_list, newstring, &width, &height);
+  XmStringFree(newstring);
+  return width;
+#else
+# ifdef USE_XFONTSET
+  XmbTextExtents (mw->menu.font_set, newchars, j, &ri, &rl);
+  return rl.width;
+# else /* ! USE_XFONTSET */
+  XTextExtents (mw->menu.font, newchars, j, &drop, &drop, &drop, &xcs);
+  return xcs.width;
 # endif /* USE_XFONTSET */
 #endif
 }
@@ -768,79 +782,109 @@
 #endif
 }
 
-static void
-string_draw_u (XlwMenuWidget mw,
-	       Window window,
-	       int x, int y,
-	       GC gc,
-#ifdef NEED_MOTIF
-	       XmString string
-#else
-	       char *string
-#endif
+static int
+string_draw_range (
+	XlwMenuWidget mw,
+	Window window,
+	int x, int y,
+	GC gc,
+	char *string,
+	int start,
+	int end
 )
 {
 #ifdef NEED_MOTIF
-  XmStringDraw (XtDisplay (mw), window,
+	Dimension width, height;
+	XmString newstring;
+	int c;
+
+	if (end <= start)
+		return 0;
+	c = string[end];
+	string[end] = '\0';
+	newstring = XmStringLtoRCreate (&string[start], XmFONTLIST_DEFAULT_TAG);
+	XmStringDraw (
+		XtDisplay (mw), window,
 		mw->menu.font_list,
-		string, gc,
+		newstring, gc,
 		x, y,
 		1000,	/* ???? width */
 		XmALIGNMENT_BEGINNING,
 		0, /* ???? layout_direction */
-		0);
+		0
+	);
+	XmStringExtent (mw->menu.font_list, newstring, &width, &height);
+	XmStringFree (newstring);
+	string[end] = c;
+	return width;
 #else
-  int i,s=0;
-  for (i=0;string[i];++i) {
-      if (string[i]=='%'&&string[i+1]=='_') {
-	  XCharStruct xcs;
-	  int drop;
-	  /* underline next character */
-	  if (i>s)
 # ifdef USE_XFONTSET
-	    XmbDrawString (XtDisplay (mw), window, mw->menu.font_set, gc,
-			   x, y + mw->menu.font_ascent, &string[s], i-s);
+	XRectangle ri, rl;
+
+	if (end <= start)
+		return 0;
+	XmbDrawString (
+		XtDisplay (mw), window, mw->menu.font_set, gc,
+		x, y + mw->menu.font_ascent, &string[start], i-s
+	);
+	XmbTextExtents (
+		mw->menu.font_set, &string[start], end - start, &ri, &rl
+	);
+	return rl.width;
 # else
-	  XDrawString (XtDisplay (mw), window, gc,
-		       x, y + mw->menu.font_ascent, &string[s], i-s);
-# endif /* USE_XFONTSET */
+	XCharStruct xcs;
+	int drop;
 
-	  XTextExtents (mw->menu.font, &string[s], i-s, &drop, &drop, &drop,
-			&xcs);
-	  x += xcs.width;
+	if (end <= start)
+		return 0;
+	XDrawString (
+		XtDisplay (mw), window, gc,
+		x, y + mw->menu.font_ascent, &string[start], end - start);
+	XTextExtents (
+		mw->menu.font, &string[start], end - start,
+		&drop, &drop, &drop, &xcs);
+	return xcs.width;
+# endif
+#endif
+}
 
-	  s=i+3;
-	  i+=2;
+static void
+string_draw_u (XlwMenuWidget mw,
+	       Window window,
+	       int x, int y,
+	       GC gc,
+#ifdef NEED_MOTIF
+	       XmString string
+#else
+	       char *string
+#endif
+)
+{
+int i,s=0;
+char *chars;
 
-# ifdef USE_XFONTSET
-	  XmbDrawString (XtDisplay (mw), window, mw->menu.font_set, gc,
-			 x, y + mw->menu.font_ascent, &string[i], 1);
-# else
-	  XDrawString (XtDisplay (mw), window, gc,
-		       x, y + mw->menu.font_ascent, &string[i], 1);
-# endif /* USE_XFONTSET */
+#ifdef NEED_MOTIF
+  XmStringGetLtoR (string, XmFONTLIST_DEFAULT_TAG, &chars);
+#else
+  chars = string;
+#endif
+  for (i=0;chars[i];++i) {
+      if (chars[i]=='%'&&chars[i+1]=='_') {
+	  int w;
 
-	  XTextExtents (mw->menu.font, &string[i], 1, &drop, &drop, &drop,
-			&xcs);
+	  x += string_draw_range (mw, window, x, y, gc, chars, s, i);
+	  w = string_draw_range (mw, window, x, y, gc, chars, i+2, i+3);
 
+	  /* underline next character */
 	  XDrawLine (XtDisplay (mw), window, gc, x - 1,
 		     y + mw->menu.font_ascent + 1,
-		     x + xcs.width - 1, y + mw->menu.font_ascent + 1 );
-
-	  x += xcs.width;
+		     x + w - 1, y + mw->menu.font_ascent + 1 );
+	  x += w;
+	  s = i + 3;
+	  i += 2;
       }
   }
-  if (string[s])
-# ifdef USE_XFONTSET
-    XmbDrawString (XtDisplay (mw), window, mw->menu.font_set, gc,
-		   x, y + mw->menu.font_ascent, &string[s],
-		   strlen (&string[s]));
-# else
-  XDrawString (XtDisplay (mw), window, gc,
-	       x, y + mw->menu.font_ascent, &string[s],
-	       strlen (&string[s]));
-# endif /* USE_XFONTSET */
-#endif /* NEED_MOTIF */
+  x += string_draw_range (mw, window, x, y, gc, chars, s, i);
 }
 
 static void

--plsagKgdrn--

