(x_create_tip_frame): Use CWSaveUnder only if the
[bpt/emacs.git] / src / xfns.c
index 999c60d..a9750be 100644 (file)
@@ -663,9 +663,6 @@ x_create_bitmap_from_file (f, file)
   fd = openp (Vx_bitmap_file_path, file, "", &found, 0);
   if (fd < 0)
     return -1;
-  /* XReadBitmapFile won't handle magic file names.  */
-  if (fd == 0)
-    return -1;
   emacs_close (fd);
 
   filename = (char *) XSTRING (found)->data;
@@ -744,6 +741,7 @@ struct x_frame_parm_table
   void (*setter) P_ ((struct frame *, Lisp_Object, Lisp_Object));
 };
 
+static void x_change_window_heights P_ ((Lisp_Object, int));
 static void x_disable_image P_ ((struct frame *, struct image *));
 static void x_create_im P_ ((struct frame *));
 void x_set_foreground_color P_ ((struct frame *, Lisp_Object, Lisp_Object));
@@ -1302,8 +1300,9 @@ x_decode_color (f, color_name, mono_color)
   if (x_defined_color (f, XSTRING (color_name)->data, &cdef, 1))
     return cdef.pixel;
 
-  return Fsignal (Qerror, Fcons (build_string ("Undefined color"),
-                                Fcons (color_name, Qnil)));
+  Fsignal (Qerror, Fcons (build_string ("Undefined color"),
+                         Fcons (color_name, Qnil)));
+  return 0;
 }
 
 
@@ -1504,11 +1503,10 @@ x_set_mouse_color (f, arg, oldval)
     XColor fore_color, back_color;
 
     fore_color.pixel = f->output_data.x->mouse_pixel;
+    x_query_color (f, &fore_color);
     back_color.pixel = mask_color;
-    XQueryColor (FRAME_X_DISPLAY (f), FRAME_X_COLORMAP (f),
-                &fore_color);
-    XQueryColor (FRAME_X_DISPLAY (f), FRAME_X_COLORMAP (f),
-                &back_color);
+    x_query_color (f, &back_color);
+    
     XRecolorCursor (FRAME_X_DISPLAY (f), cursor,
                    &fore_color, &back_color);
     XRecolorCursor (FRAME_X_DISPLAY (f), nontext_cursor,
@@ -1516,7 +1514,7 @@ x_set_mouse_color (f, arg, oldval)
     XRecolorCursor (FRAME_X_DISPLAY (f), mode_cursor,
                    &fore_color, &back_color);
     XRecolorCursor (FRAME_X_DISPLAY (f), cross_cursor,
-                    &fore_color, &back_color);
+                   &fore_color, &back_color);
     XRecolorCursor (FRAME_X_DISPLAY (f), busy_cursor,
                     &fore_color, &back_color);
   }
@@ -1915,9 +1913,12 @@ x_set_visibility (f, value, oldval)
   else
     Fmake_frame_visible (frame);
 }
+
 \f
+/* Change window heights in windows rooted in WINDOW by N lines.  */
+
 static void
-x_set_menu_bar_lines_1 (window, n)
+x_change_window_heights (window, n)
   Lisp_Object window;
   int n;
 {
@@ -1933,13 +1934,13 @@ x_set_menu_bar_lines_1 (window, n)
 
   /* Handle just the top child in a vertical split.  */
   if (!NILP (w->vchild))
-    x_set_menu_bar_lines_1 (w->vchild, n);
+    x_change_window_heights (w->vchild, n);
 
   /* Adjust all children in a horizontal split.  */
   for (window = w->hchild; !NILP (window); window = w->next)
     {
       w = XWINDOW (window);
-      x_set_menu_bar_lines_1 (window, n);
+      x_change_window_heights (window, n);
     }
 }
 
@@ -1987,7 +1988,7 @@ x_set_menu_bar_lines (f, value, oldval)
     }
 #else /* not USE_X_TOOLKIT */
   FRAME_MENU_BAR_LINES (f) = nlines;
-  x_set_menu_bar_lines_1 (f->root_window, nlines - olines);
+  x_change_window_heights (f->root_window, nlines - olines);
 #endif /* not USE_X_TOOLKIT */
   adjust_glyphs (f);
 }
@@ -2004,7 +2005,8 @@ x_set_tool_bar_lines (f, value, oldval)
      struct frame *f;
      Lisp_Object value, oldval;
 {
-  int delta, nlines;
+  int delta, nlines, root_height;
+  Lisp_Object root_window;
 
   /* Use VALUE only if an integer >= 0.  */
   if (INTEGERP (value) && XINT (value) >= 0)
@@ -2016,9 +2018,33 @@ x_set_tool_bar_lines (f, value, oldval)
   ++windows_or_buffers_changed;
 
   delta = nlines - FRAME_TOOL_BAR_LINES (f);
+
+  /* Don't resize the tool-bar to more than we have room for.  */
+  root_window = FRAME_ROOT_WINDOW (f);
+  root_height = XINT (XWINDOW (root_window)->height);
+  if (root_height - delta < 1)
+    {
+      delta = root_height - 1;
+      nlines = FRAME_TOOL_BAR_LINES (f) + delta;
+    }
+
   FRAME_TOOL_BAR_LINES (f) = nlines;
-  x_set_menu_bar_lines_1 (FRAME_ROOT_WINDOW (f), delta);
+  x_change_window_heights (root_window, delta);
   adjust_glyphs (f);
+  
+  /* We also have to make sure that the internal border at the top of
+     the frame, below the menu bar or tool bar, is redrawn when the
+     tool bar disappears.  This is so because the internal border is
+     below the tool bar if one is displayed, but is below the menu bar
+     if there isn't a tool bar.  The tool bar draws into the area
+     below the menu bar.  */
+  if (FRAME_X_WINDOW (f) && FRAME_TOOL_BAR_LINES (f) == 0)
+    {
+      updating_frame = f;
+      clear_frame ();
+      clear_current_matrices (f);
+      updating_frame = NULL;
+    }
 }
 
 
@@ -2135,6 +2161,8 @@ x_encode_text (string, coding_system, text_bytes, stringp)
   coding.mode |= CODING_MODE_LAST_BLOCK;
   if (coding.type == coding_type_iso2022)
     coding.flags |= CODING_FLAG_ISO_SAFE;
+  /* We suppress producing escape sequences for composition.  */
+  coding.composing = COMPOSITION_DISABLED;
   bufsize = encoding_buffer_size (&coding, bytes);
   buf = (unsigned char *) xmalloc (bufsize);
   encode_coding (&coding, str, buf, bytes, bufsize);
@@ -4248,9 +4276,6 @@ This function is an internal primitive--use `make-frame' instead.")
   SET_FRAME_WIDTH (f, 0);
   change_frame_size (f, height, width, 1, 0, 0);
 
-  /* Set up faces after all frame parameters are known.  */
-  call1 (Qface_set_after_frame_default, frame);
-
 #ifdef USE_X_TOOLKIT
   /* Create the menu bar.  */
   if (!minibuffer_only && FRAME_EXTERNAL_MENU_BAR (f))
@@ -5497,7 +5522,12 @@ image_ascent (img, face)
   if (img->ascent == CENTERED_IMAGE_ASCENT)
     {
       if (face->font)
-       ascent = height / 2 - (face->font->descent - face->font->ascent) / 2;
+       /* This expression is arranged so that if the image can't be
+          exactly centered, it will be moved slightly up.  This is
+          because a typical font is `top-heavy' (due to the presence
+          uppercase letters), so the image placement should err towards
+          being top-heavy too.  It also just generally looks better.  */
+       ascent = (height + face->font->ascent - face->font->descent + 1) / 2;
       else
        ascent = height / 2;
     }
@@ -6078,7 +6108,7 @@ x_find_image_file (file)
   /* Try to find FILE in data-directory, then x-bitmap-file-path.  */
   fd = openp (search_path, file, "", &file_found, 0);
   
-  if (fd < 0)
+  if (fd == -1)
     file_found = Qnil;
   else
     close (fd);
@@ -7367,7 +7397,7 @@ lookup_pixel_color (f, pixel)
 
       cmap = FRAME_X_COLORMAP (f);
       color.pixel = pixel;
-      XQueryColor (FRAME_X_DISPLAY (f), cmap, &color);
+      x_query_color (f, &color);
       rc = x_alloc_nearest_color (f, cmap, &color);
 
       if (rc)
@@ -7495,8 +7525,7 @@ x_to_xcolors (f, img, rgb_p)
        p->pixel = XGetPixel (ximg, x, y);
 
       if (rgb_p)
-       XQueryColors (FRAME_X_DISPLAY (f), FRAME_X_COLORMAP (f),
-                     row, img->width);
+       x_query_colors (f, row, img->width);
     }
 
   XDestroyImage (ximg);
@@ -7876,6 +7905,8 @@ enum pbm_keyword_index
   PBM_ALGORITHM,
   PBM_HEURISTIC_MASK,
   PBM_MASK,
+  PBM_FOREGROUND,
+  PBM_BACKGROUND,
   PBM_LAST
 };
 
@@ -7892,7 +7923,9 @@ static struct image_keyword pbm_format[PBM_LAST] =
   {":relief",          IMAGE_INTEGER_VALUE,                    0},
   {":algorithm",       IMAGE_DONT_CHECK_VALUE_TYPE,            0},
   {":heuristic-mask",  IMAGE_DONT_CHECK_VALUE_TYPE,            0},
-  {":mask",            IMAGE_DONT_CHECK_VALUE_TYPE,            0}
+  {":mask",            IMAGE_DONT_CHECK_VALUE_TYPE,            0},
+  {":foreground",      IMAGE_STRING_VALUE,                     0},
+  {":background",      IMAGE_STRING_VALUE,                     0}
 };
 
 /* Structure describing the image type `pbm'.  */
@@ -8081,6 +8114,19 @@ pbm_load (f, img)
   if (type == PBM_MONO)
     {
       int c = 0, g;
+      struct image_keyword fmt[PBM_LAST];
+      unsigned long fg = FRAME_FOREGROUND_PIXEL (f);
+      unsigned long bg = FRAME_BACKGROUND_PIXEL (f);
+
+      /* Parse the image specification.  */
+      bcopy (pbm_format, fmt, sizeof fmt);
+      parse_image_spec (img->spec, fmt, PBM_LAST, Qpbm);
+      
+      /* Get foreground and background colors, maybe allocate colors.  */
+      if (fmt[PBM_FOREGROUND].count)
+       fg = x_alloc_image_color (f, img, fmt[PBM_FOREGROUND].value, fg);
+      if (fmt[PBM_BACKGROUND].count)
+       bg = x_alloc_image_color (f, img, fmt[PBM_BACKGROUND].value, bg);
       
       for (y = 0; y < height; ++y)
        for (x = 0; x < width; ++x)
@@ -8095,9 +8141,7 @@ pbm_load (f, img)
            else
              g = pbm_scan_number (&p, end);
 
-           XPutPixel (ximg, x, y, (g
-                                   ? FRAME_FOREGROUND_PIXEL (f)
-                                   : FRAME_BACKGROUND_PIXEL (f)));
+           XPutPixel (ximg, x, y, g ? fg : bg);
          }
     }
   else
@@ -8495,7 +8539,7 @@ png_load (f, img)
 
          cmap = FRAME_X_COLORMAP (f);
          color.pixel = FRAME_BACKGROUND_PIXEL (f);
-         XQueryColor (FRAME_X_DISPLAY (f), cmap, &color);
+         x_query_color (f, &color);
 
          bzero (&frame_background, sizeof frame_background);
          frame_background.red = color.red;
@@ -10380,7 +10424,10 @@ x_create_tip_frame (dpyinfo, parms)
     unsigned long mask;
     
     BLOCK_INPUT;
-    mask = CWBackPixel | CWOverrideRedirect | CWSaveUnder | CWEventMask;
+    mask = CWBackPixel | CWOverrideRedirect | CWEventMask;
+    if (DoesSaveUnders (dpyinfo->screen))
+      mask |= CWSaveUnder;
+    
     /* Window managers look at the override-redirect flag to determine
        whether or net to give windows a decoration (Xlib spec, chapter
        3.2.8).  */
@@ -10455,7 +10502,7 @@ displayed at the mouse position, with offset DX added (default is 5 if\n\
 DX isn't specified).  Likewise for the y-position; if a `top' frame\n\
 parameter is specified, it determines the y-position of the tooltip\n\
 window, otherwise it is displayed at the mouse position, with offset\n\
-DY added (default is -5).")
+DY added (default is -10).")
   (string, frame, parms, timeout, dx, dy)
      Lisp_Object string, frame, parms, timeout, dx, dy;
 {
@@ -10489,7 +10536,7 @@ DY added (default is -5).")
     CHECK_NUMBER (dx, 5);
   
   if (NILP (dy))
-    dy = make_number (-5);
+    dy = make_number (-10);
   else
     CHECK_NUMBER (dy, 6);