]> code.delx.au - gnu-emacs/blobdiff - src/xfns.c
(compute_tip_xy): Add parameters WIDTH and HEIGHT.
[gnu-emacs] / src / xfns.c
index 8ed08ee75ffd90a6586159ed7b6fc4fac15b74dc..4f718fa902018000bbe7e89af8c8bf982fa1d5be 100644 (file)
@@ -107,6 +107,14 @@ extern XFontStruct *xlwmenu_default_font;
 extern void free_frame_menubar ();
 extern double atof ();
 
+#ifdef USE_MOTIF
+
+/* LessTif/Motif version info.  */
+
+static Lisp_Object Vmotif_version_string;
+
+#endif /* USE_MOTIF */
+
 #endif /* USE_X_TOOLKIT */
 
 #define min(a,b) ((a) < (b) ? (a) : (b))
@@ -3969,8 +3977,7 @@ x_make_gc (f)
        gray_bits, gray_width, gray_height,
        f->output_data.x->foreground_pixel,
        f->output_data.x->background_pixel,
-       DefaultDepth (FRAME_X_DISPLAY (f),
-                     XScreenNumberOfScreen (FRAME_X_SCREEN (f)))));
+       DefaultDepth (FRAME_X_DISPLAY (f), FRAME_X_SCREEN_NUMBER (f))));
 
   UNBLOCK_INPUT;
 }
@@ -4455,6 +4462,11 @@ This function is an internal primitive--use `make-frame' instead.")
     }
 
   UNGCPRO;
+
+  /* Make sure windows on this frame appear in calls to next-window
+     and similar functions.  */
+  Vwindow_list = Qnil;
+  
   return unbind_to (count, frame);
 }
 
@@ -5783,6 +5795,7 @@ x_alloc_image_color (f, img, color_name, dflt)
  ***********************************************************************/
 
 static void cache_image P_ ((struct frame *f, struct image *img));
+static void postprocess_image P_ ((struct frame *, struct image *));
 
 
 /* Return a new, initialized image cache that is allocated from the
@@ -5914,6 +5927,81 @@ FRAME t means clear the image caches of all frames.")
 }
 
 
+/* Compute masks and transform image IMG on frame F, as specified
+   by the image's specification,  */
+
+static void
+postprocess_image (f, img)
+     struct frame *f;
+     struct image *img;
+{
+  /* Manipulation of the image's mask.  */
+  if (img->pixmap)
+    {
+      Lisp_Object conversion, spec;
+      Lisp_Object mask;
+
+      spec = img->spec;
+      
+      /* `:heuristic-mask t'
+        `:mask heuristic'
+        means build a mask heuristically.
+        `:heuristic-mask (R G B)'
+        `:mask (heuristic (R G B))'
+        means build a mask from color (R G B) in the
+        image.
+        `:mask nil'
+        means remove a mask, if any.  */
+             
+      mask = image_spec_value (spec, QCheuristic_mask, NULL);
+      if (!NILP (mask))
+       x_build_heuristic_mask (f, img, mask);
+      else
+       {
+         int found_p;
+                   
+         mask = image_spec_value (spec, QCmask, &found_p);
+                 
+         if (EQ (mask, Qheuristic))
+           x_build_heuristic_mask (f, img, Qt);
+         else if (CONSP (mask)
+                  && EQ (XCAR (mask), Qheuristic))
+           {
+             if (CONSP (XCDR (mask)))
+               x_build_heuristic_mask (f, img, XCAR (XCDR (mask)));
+             else
+               x_build_heuristic_mask (f, img, XCDR (mask));
+           }
+         else if (NILP (mask) && found_p && img->mask)
+           {
+             XFreePixmap (FRAME_X_DISPLAY (f), img->mask);
+             img->mask = None;
+           }
+       }
+         
+      /* Should we apply an image transformation algorithm?  */
+      conversion = image_spec_value (spec, QCconversion, NULL);
+      if (EQ (conversion, Qdisabled))
+       x_disable_image (f, img);
+      else if (EQ (conversion, Qlaplace))
+       x_laplace (f, img);
+      else if (EQ (conversion, Qemboss))
+       x_emboss (f, img);
+      else if (CONSP (conversion)
+              && EQ (XCAR (conversion), Qedge_detection))
+       {
+         Lisp_Object tem;
+         tem = XCDR (conversion);
+         if (CONSP (tem))
+           x_edge_detection (f, img,
+                             Fplist_get (tem, QCmatrix),
+                             Fplist_get (tem, QCcolor_adjustment));
+       }
+    }
+}
+
+
 /* Return the id of image with Lisp specification SPEC on frame F.
    SPEC must be a valid Lisp image specification (see valid_image_p).  */
 
@@ -5947,6 +6035,8 @@ lookup_image (f, spec)
   /* If not found, create a new image and cache it.  */
   if (img == NULL)
     {
+      extern Lisp_Object Qpostscript;
+      
       BLOCK_INPUT;
       img = make_image (spec, hash);
       cache_image (f, img);
@@ -5998,71 +6088,10 @@ lookup_image (f, spec)
              img->vmargin += abs (img->relief);
            }
 
-         /* Manipulation of the image's mask.  */
-         if (img->pixmap)
-           {
-             /* `:heuristic-mask t'
-                `:mask heuristic'
-                       means build a mask heuristically.
-                `:heuristic-mask (R G B)'
-                `:mask (heuristic (R G B))'
-                       means build a mask from color (R G B) in the
-                       image.
-                `:mask nil'
-                       means remove a mask, if any.  */
-             
-             Lisp_Object mask;
-
-             mask = image_spec_value (spec, QCheuristic_mask, NULL);
-             if (!NILP (mask))
-               x_build_heuristic_mask (f, img, mask);
-             else
-               {
-                 int found_p;
-                   
-                 mask = image_spec_value (spec, QCmask, &found_p);
-                 
-                 if (EQ (mask, Qheuristic))
-                   x_build_heuristic_mask (f, img, Qt);
-                 else if (CONSP (mask)
-                          && EQ (XCAR (mask), Qheuristic))
-                   {
-                     if (CONSP (XCDR (mask)))
-                       x_build_heuristic_mask (f, img, XCAR (XCDR (mask)));
-                     else
-                       x_build_heuristic_mask (f, img, XCDR (mask));
-                   }
-                 else if (NILP (mask) && found_p && img->mask)
-                   {
-                     XFreePixmap (FRAME_X_DISPLAY (f), img->mask);
-                     img->mask = None;
-                   }
-               }
-           }
-         
-         /* Should we apply an image transformation algorithm?  */
-         if (img->pixmap)
-           {
-             Lisp_Object conversion;
-
-             conversion = image_spec_value (spec, QCconversion, NULL);
-             if (EQ (conversion, Qdisabled))
-               x_disable_image (f, img);
-             else if (EQ (conversion, Qlaplace))
-               x_laplace (f, img);
-             else if (EQ (conversion, Qemboss))
-               x_emboss (f, img);
-             else if (CONSP (conversion)
-                      && EQ (XCAR (conversion), Qedge_detection))
-               {
-                 Lisp_Object tem;
-                 tem = XCDR (conversion);
-                 if (CONSP (tem))
-                   x_edge_detection (f, img,
-                                     Fplist_get (tem, QCmatrix),
-                                     Fplist_get (tem, QCcolor_adjustment));
-               }
-           }
+         /* Do image transformations and compute masks, unless we
+            don't have the image yet.  */
+         if (!EQ (*img->type->type, Qpostscript))
+           postprocess_image (f, img);
        }
 
       UNBLOCK_INPUT;
@@ -10087,6 +10116,12 @@ x_kill_gs_process (pixmap, f)
       
       UNBLOCK_INPUT;
     }
+
+  /* Now that we have the pixmap, compute mask and transform the
+     image if requested.  */
+  BLOCK_INPUT;
+  postprocess_image (f, img);
+  UNBLOCK_INPUT;
 }
 
 
@@ -10377,9 +10412,9 @@ hide_hourglass ()
  ***********************************************************************/
 
 static Lisp_Object x_create_tip_frame P_ ((struct x_display_info *,
-                                          Lisp_Object));
+                                          Lisp_Object, Lisp_Object));
 static void compute_tip_xy P_ ((struct frame *, Lisp_Object, Lisp_Object,
-                               Lisp_Object, int *, int *));
+                               Lisp_Object, int, int, int *, int *));
      
 /* The frame of a currently visible tooltip.  */
 
@@ -10415,7 +10450,8 @@ unwind_create_tip_frame (frame)
 
 
 /* Create a frame for a tooltip on the display described by DPYINFO.
-   PARMS is a list of frame parameters.  Value is the frame.
+   PARMS is a list of frame parameters.  TEXT is the string to
+   display in the tip frame.  Value is the frame.
 
    Note that functions called here, esp. x_default_parameter can
    signal errors, for instance when a specified color name is
@@ -10423,9 +10459,9 @@ unwind_create_tip_frame (frame)
    when this happens.  */
 
 static Lisp_Object
-x_create_tip_frame (dpyinfo, parms)
+x_create_tip_frame (dpyinfo, parms, text)
      struct x_display_info *dpyinfo;
-     Lisp_Object parms;
+     Lisp_Object parms, text;
 {
   struct frame *f;
   Lisp_Object frame, tem;
@@ -10436,6 +10472,8 @@ x_create_tip_frame (dpyinfo, parms)
   struct gcpro gcpro1, gcpro2, gcpro3;
   struct kboard *kb;
   int face_change_count_before = face_change_count;
+  Lisp_Object buffer;
+  struct buffer *old_buffer;
 
   check_x ();
 
@@ -10461,6 +10499,15 @@ x_create_tip_frame (dpyinfo, parms)
   GCPRO3 (parms, name, frame);
   f = make_frame (1);
   XSETFRAME (frame, f);
+
+  buffer = Fget_buffer_create (build_string (" *tip*"));
+  Fset_window_buffer (FRAME_ROOT_WINDOW (f), buffer);
+  old_buffer = current_buffer;
+  set_buffer_internal_1 (XBUFFER (buffer));
+  Ferase_buffer ();
+  Finsert (1, &text);
+  set_buffer_internal_1 (old_buffer);
+  
   FRAME_CAN_HAVE_SCROLL_BARS (f) = 0;
   record_unwind_protect (unwind_create_tip_frame, frame);
 
@@ -10720,13 +10767,15 @@ x_create_tip_frame (dpyinfo, parms)
 
 /* Compute where to display tip frame F.  PARMS is the list of frame
    parameters for F.  DX and DY are specified offsets from the current
-   location of the mouse.  Return coordinates relative to the root
-   window of the display in *ROOT_X, and *ROOT_Y.  */
+   location of the mouse.  WIDTH and HEIGHT are the width and height
+   of the tooltip.  Return coordinates relative to the root window of
+   the display in *ROOT_X, and *ROOT_Y.  */
 
 static void
-compute_tip_xy (f, parms, dx, dy, root_x, root_y)
+compute_tip_xy (f, parms, dx, dy, width, height, root_x, root_y)
      struct frame *f;
      Lisp_Object parms, dx, dy;
+     int width, height;
      int *root_x, *root_y;
 {
   Lisp_Object left, top;
@@ -10740,18 +10789,30 @@ compute_tip_xy (f, parms, dx, dy, root_x, root_y)
   
   /* Move the tooltip window where the mouse pointer is.  Resize and
      show it.  */
-  BLOCK_INPUT;
-  XQueryPointer (FRAME_X_DISPLAY (f), FRAME_X_DISPLAY_INFO (f)->root_window,
-                &root, &child, root_x, root_y, &win_x, &win_y, &pmask);
-  UNBLOCK_INPUT;
+  if (!INTEGERP (left) && !INTEGERP (top))
+    {
+      BLOCK_INPUT;
+      XQueryPointer (FRAME_X_DISPLAY (f), FRAME_X_DISPLAY_INFO (f)->root_window,
+                    &root, &child, root_x, root_y, &win_x, &win_y, &pmask);
+      UNBLOCK_INPUT;
+    }
 
-  *root_x += XINT (dx);
-  *root_y += XINT (dy);
-  
-  if (INTEGERP (left))
-    *root_x = XINT (left);
   if (INTEGERP (top))
     *root_y = XINT (top);
+  else if (*root_y + XINT (dy) - height < 0)
+    *root_y -= XINT (dy);
+  else
+    {
+      *root_y -= height;
+      *root_y += XINT (dy);
+    }
+
+  if (INTEGERP (left))
+    *root_x = XINT (left);
+  else if (*root_x + XINT (dx) + width > FRAME_X_DISPLAY_INFO (f)->width)
+    *root_x -= width + XINT (dx);
+  else
+    *root_x += XINT (dx);
 }
 
 
@@ -10833,9 +10894,10 @@ DY added (default is -10).")
            }
 
          BLOCK_INPUT;
-         compute_tip_xy (f, parms, dx, dy, &root_x, &root_y);
+         compute_tip_xy (f, parms, dx, dy, PIXEL_WIDTH (f),
+                         PIXEL_HEIGHT (f), &root_x, &root_y);
          XMoveWindow (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
-                      root_x, root_y - PIXEL_HEIGHT (f));
+                      root_x, root_y);
          UNBLOCK_INPUT;
          goto start_timer;
        }
@@ -10863,7 +10925,7 @@ DY added (default is -10).")
 
   /* Create a frame for the tooltip, and record it in the global
      variable tip_frame.  */
-  frame = x_create_tip_frame (FRAME_X_DISPLAY_INFO (f), parms);
+  frame = x_create_tip_frame (FRAME_X_DISPLAY_INFO (f), parms, string);
   f = XFRAME (frame);
 
   /* Set up the frame's root window.  Currently we use a size of 80
@@ -10877,12 +10939,8 @@ DY added (default is -10).")
   w->pseudo_window_p = 1;
 
   /* Display the tooltip text in a temporary buffer.  */
-  buffer = Fget_buffer_create (build_string (" *tip*"));
-  Fset_window_buffer (FRAME_ROOT_WINDOW (f), buffer);
   old_buffer = current_buffer;
-  set_buffer_internal_1 (XBUFFER (buffer));
-  Ferase_buffer ();
-  Finsert (1, &string);
+  set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f))->buffer));
   clear_glyph_matrix (w->desired_matrix);
   clear_glyph_matrix (w->current_matrix);
   SET_TEXT_POS (pos, BEGV, BEGV_BYTE);
@@ -10924,11 +10982,11 @@ DY added (default is -10).")
 
   /* Move the tooltip window where the mouse pointer is.  Resize and
      show it.  */
-  compute_tip_xy (f, parms, dx, dy, &root_x, &root_y);
+  compute_tip_xy (f, parms, dx, dy, width, height, &root_x, &root_y);
 
   BLOCK_INPUT;
   XMoveResizeWindow (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
-                    root_x, root_y - height, width, height);
+                    root_x, root_y, width, height);
   XMapRaised (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f));
   UNBLOCK_INPUT;
   
@@ -11485,10 +11543,15 @@ meaning don't clear the cache.");
 
 #ifdef USE_X_TOOLKIT
   Fprovide (intern ("x-toolkit"));
-#endif
+  
 #ifdef USE_MOTIF
   Fprovide (intern ("motif"));
-#endif
+
+  DEFVAR_LISP ("motif-version-string", &Vmotif_version_string,
+     "Version info for LessTif/Motif.");
+  Vmotif_version_string = build_string (XmVERSION_STRING);
+#endif /* USE_MOTIF */
+#endif /* USE_X_TOOLKIT */
 
   defsubr (&Sx_get_resource);