* dispnew.c: Make symbols static if they're not exported.
[bpt/emacs.git] / lwlib / xlwmenu.c
index d3205eb..5b97f2b 100644 (file)
@@ -1,7 +1,7 @@
 /* Implements a lightweight menubar widget.
+
 Copyright (C) 1992 Lucid, Inc.
-Copyright (C) 1994, 1995, 1997, 1999, 2000, 2001, 2002, 2003, 2004,
-  2005, 2006, 2007, 2008, 2009, 2010  Free Software Foundation, Inc.
+Copyright (C) 1994-1995, 1997, 1999-2011  Free Software Foundation, Inc.
 
 This file is part of the Lucid Widget Library.
 
@@ -27,7 +27,7 @@ Boston, MA 02110-1301, USA.  */
 #endif
 
 #include <setjmp.h>
-#include "lisp.h"
+#include <lisp.h>
 
 #include <stdio.h>
 #include <ctype.h>
@@ -57,7 +57,7 @@ extern int gray_bitmap_width;
 extern int gray_bitmap_height;
 extern char *gray_bitmap_bits;
 
-#include "xterm.h"
+#include <xterm.h>
 
 #else /* not emacs */
 
@@ -71,8 +71,6 @@ extern char *gray_bitmap_bits;
 static int pointer_grabbed;
 static XEvent menu_post_event;
 
-static XFontStruct *xlwmenu_default_font;
-
 static char
 xlwMenuTranslations [] =
 "<BtnDown>:      start()\n\
@@ -131,14 +129,12 @@ xlwMenuResources[] =
      offset(menu.fontSet), XtRFontSet, NULL},
 #endif
 #ifdef HAVE_XFT
-#define DEFAULT_FACENAME "Sans-10"
-  {XtNfaceName,  XtCFaceName, XtRString, sizeof(String),
-   offset(menu.faceName), XtRString, DEFAULT_FACENAME},
-  {XtNdefaultFace,  XtCDefaultFace, XtRInt, sizeof(int),
-   offset(menu.default_face), XtRImmediate, (XtPointer)1},
+#define DEFAULT_FONTNAME "Sans-10"
+#else
+#define DEFAULT_FONTNAME "XtDefaultFont"
 #endif
-  {XtNfont,  XtCFont, XtRFontStruct, sizeof(XFontStruct *),
-     offset(menu.font), XtRString, "XtDefaultFont"},
+  {XtNfont,  XtCFont, XtRString, sizeof(String),
+     offset(menu.fontName), XtRString, DEFAULT_FONTNAME },
   {XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel),
      offset(menu.foreground), XtRString, "XtDefaultForeground"},
   {XtNdisabledForeground, XtCDisabledForeground, XtRPixel, sizeof(Pixel),
@@ -1352,6 +1348,7 @@ make_windows_if_needed (XlwMenuWidget mw, int n)
 #endif
      set_window_type (windows [i].w, mw);
    }
+  XFlush (XtDisplay (mw));
 }
 
 /* Value is non-zero if WINDOW is part of menu bar widget W.  */
@@ -1534,10 +1531,12 @@ remap_menubar (XlwMenuWidget mw)
 
       fit_to_screen (mw, ws, previous_ws, mw->menu.horizontal && i == 1);
 
-      XtVaSetValues (ws->w, XtNwidth, ws->width, XtNheight, ws->height,
-                     XtNx, ws->x, XtNy, ws->y, NULL);
       create_pixmap_for_menu (ws, mw);
+      XtMoveWidget (ws->w, ws->x, ws->y);
       XtPopup (ws->w, XtGrabNone);
+      XtResizeWidget (ws->w, ws->width, ws->height,
+                      mw->core.border_width);
+      XtResizeWindow (ws->w);
       display_menu (mw, i, False, &selection_position, NULL, NULL);
     }
 
@@ -1613,14 +1612,17 @@ make_drawing_gcs (XlwMenuWidget mw)
   XtGCMask mask = GCForeground | GCBackground;
 
 #ifdef HAVE_X_I18N
-  if (!mw->menu.fontSet)
+  if (!mw->menu.fontSet && mw->menu.font)
     {
       xgcv.font = mw->menu.font->fid;
       mask |= GCFont;
     }
 #else
-  xgcv.font = mw->menu.font->fid;
-  mask |= GCFont;
+  if (mw->menu.font)
+    {
+      xgcv.font = mw->menu.font->fid;
+      mask |= GCFont;
+    }
 #endif
   xgcv.foreground = mw->menu.foreground;
   xgcv.background = mw->core.background_pixel;
@@ -1847,13 +1849,20 @@ release_shadow_gcs (XlwMenuWidget mw)
 }
 
 #ifdef HAVE_XFT
+static XftFont *
+getDefaultXftFont (XlwMenuWidget mw)
+{
+  int screen = XScreenNumberOfScreen (mw->core.screen);
+  return XftFontOpenName (XtDisplay (mw), screen, DEFAULT_FONTNAME);
+}
+
 static int
 openXftFont (XlwMenuWidget mw)
 {
-  char *fname = mw->menu.faceName;
+  char *fname = mw->menu.fontName;
 
   mw->menu.xft_font = 0;
-  mw->menu.default_face = fname && strcmp (fname, DEFAULT_FACENAME) == 0;
+  mw->menu.default_face = fname && strcmp (fname, DEFAULT_FONTNAME) == 0;
 
   if (fname && strcmp (fname, "none") != 0)
     {
@@ -1864,20 +1873,23 @@ openXftFont (XlwMenuWidget mw)
         --i;
       if (fname[i] == ' ')
         {
-          fname = xstrdup (mw->menu.faceName);
+          fname = xstrdup (mw->menu.fontName);
           fname[i] = '-';
         }
 
-      mw->menu.xft_font = XftFontOpenName (XtDisplay (mw), screen, fname);
-      if (!mw->menu.xft_font) 
+      mw->menu.font = XLoadQueryFont (XtDisplay (mw), fname);
+      if (!mw->menu.font)
         {
-          fprintf (stderr, "Can't find font '%s'\n", fname);
-          mw->menu.xft_font = XftFontOpenName (XtDisplay (mw), screen,
-                                               DEFAULT_FACENAME);
+          mw->menu.xft_font = XftFontOpenName (XtDisplay (mw), screen, fname);
+          if (!mw->menu.xft_font) 
+            {
+              fprintf (stderr, "Can't find font '%s'\n", fname);
+              mw->menu.xft_font = getDefaultXftFont (mw);
+            }
         }
     }
 
-  if (fname != mw->menu.faceName) free (fname);
+  if (fname != mw->menu.fontName) free (fname);
 
   return mw->menu.xft_font != 0;
 }
@@ -1913,19 +1925,19 @@ XlwMenuInitialize (Widget request, Widget w, ArgList args, Cardinal *num_args)
     ;
   else
 #endif
-  
-  if (!mw->menu.font)
     {
-      if (!xlwmenu_default_font)
-        xlwmenu_default_font = XLoadQueryFont (display, "fixed");
-      mw->menu.font = xlwmenu_default_font;
-      if (!mw->menu.font) 
+      mw->menu.font = XLoadQueryFont (display, mw->menu.fontName);
+      if (!mw->menu.font)
         {
-          fprintf (stderr, "Menu font fixed not found, can't continue.\n");
-          abort ();
+          mw->menu.font = XLoadQueryFont (display, "fixed");
+          if (!mw->menu.font) 
+            {
+              fprintf (stderr, "Menu font fixed not found, can't continue.\n");
+              abort ();
+            }
         }
     }
-
+  
 #ifdef HAVE_X_I18N
   if (mw->menu.fontSet)
     mw->menu.font_extents = XExtentsOfFontSet (mw->menu.fontSet);
@@ -1966,7 +1978,6 @@ XlwMenuInitialize (Widget request, Widget w, ArgList args, Cardinal *num_args)
 static void
 XlwMenuClassInitialize (void)
 {
-  xlwmenu_default_font = 0;
 }
 
 static void
@@ -2126,13 +2137,13 @@ XlwMenuDestroy (Widget w)
 
 #ifdef HAVE_XFT
 static int
-facename_changed (XlwMenuWidget newmw,
+fontname_changed (XlwMenuWidget newmw,
                   XlwMenuWidget oldmw)
 {
-  /* This will fore a new XftFont even if the same string is set.
+  /* This will force a new XftFont even if the same string is set.
      This is good, as rendering parameters may have changed and
      we just want to do a redisplay.  */
-  return newmw->menu.faceName != oldmw->menu.faceName;
+  return newmw->menu.fontName != oldmw->menu.fontName;
 }
 #endif
 
@@ -2158,7 +2169,7 @@ XlwMenuSetValues (Widget current, Widget request, Widget new,
   if (newmw->core.background_pixel != oldmw->core.background_pixel
       || newmw->menu.foreground != oldmw->menu.foreground
 #ifdef HAVE_XFT
-      || facename_changed (newmw, oldmw)
+      || fontname_changed (newmw, oldmw)
 #endif
 #ifdef HAVE_X_I18N
       || newmw->menu.fontSet != oldmw->menu.fontSet
@@ -2193,7 +2204,7 @@ XlwMenuSetValues (Widget current, Widget request, Widget new,
     }
 
 #ifdef HAVE_XFT
-  if (facename_changed (newmw, oldmw))
+  if (fontname_changed (newmw, oldmw))
     {
       int i;
       int screen = XScreenNumberOfScreen (newmw->core.screen);
@@ -2690,6 +2701,3 @@ pop_up_menu (XlwMenuWidget mw, XButtonPressedEvent *event)
   ((XMotionEvent*)event)->is_hint = 0;
   handle_motion_event (mw, (XMotionEvent*)event);
 }
-
-/* arch-tag: 657f43dd-dfd0-4cc9-910c-52935f01176e
-   (do not change this comment) */