diff src/menubar-msw.c @ 327:03446687b7cc r21-0-61

Import from CVS: tag r21-0-61
author cvs
date Mon, 13 Aug 2007 10:48:16 +0200
parents 70ad99077275
children fbbf69b4e8a7
line wrap: on
line diff
--- a/src/menubar-msw.c	Mon Aug 13 10:47:36 2007 +0200
+++ b/src/menubar-msw.c	Mon Aug 13 10:48:16 2007 +0200
@@ -130,11 +130,37 @@
      and better be caught than displayed! */
   
   static char buf[MAX_MENUITEM_LENGTH+2];
+  char *ptr;
   unsigned int ll, lr;
 
   /* Left flush part of the string */
   ll = gui_item_display_flush_left (pgui_item, buf, MAX_MENUITEM_LENGTH);
 
+  /* Escape '&' as '&&' */
+  ptr = buf;
+  while ((ptr=memchr (ptr, '&', ll-(ptr-buf))) != NULL)
+    {
+      if (ll+2 >= MAX_MENUITEM_LENGTH)
+	signal_simple_error ("Menu item produces too long displayable string",
+			     pgui_item->name);
+      memmove (ptr+1, ptr, ll-(ptr-buf));
+      ll++;
+      ptr+=2;
+    }
+
+  /* Replace XEmacs accelerator '%_' with Windows accelerator '&' */
+  ptr = buf;
+  while ((ptr=memchr (ptr, '%', ll-(ptr-buf))) != NULL)
+    {
+      if (*(ptr+1) == '_')
+	{
+	  *ptr = '&';
+	  memmove (ptr+1, ptr+2, ll-(ptr-buf+2));
+	  ll--;
+	}
+      ptr++;
+    }
+
   /* Right flush part */
   assert (MAX_MENUITEM_LENGTH > ll + 1);
   lr = gui_item_display_flush_right (pgui_item, buf + ll + 1,