diff src/frame-x.c @ 398:74fd4e045ea6 r21-2-29

Import from CVS: tag r21-2-29
author cvs
date Mon, 13 Aug 2007 11:13:30 +0200
parents 6719134a07c2
children 2f8bb876ab1d
line wrap: on
line diff
--- a/src/frame-x.c	Mon Aug 13 11:12:06 2007 +0200
+++ b/src/frame-x.c	Mon Aug 13 11:13:30 2007 +0200
@@ -103,19 +103,34 @@
 struct frame *
 x_any_window_to_frame (struct device *d, Window wdesc)
 {
+  Widget w;
+  assert (DEVICE_X_P (d));
+
+  w = XtWindowToWidget (DEVICE_X_DISPLAY (d), wdesc);
+
+  if (!w)
+    return 0;
+
+  /* We used to map over all frames here and then map over all widgets
+     belonging to that frame. However it turns out that this was very fragile
+     as it requires our display stuctures to be in sync _and_ that the
+     loop is told about every new widget somebody adds. Therefore we
+     now let Xt find it for us (which does a bottom-up search which
+     could even be faster) */
+  return  x_any_widget_or_parent_to_frame (d, w);
+}
+
+static struct frame *
+x_find_frame_for_window (struct device *d, Window wdesc)
+{
   Lisp_Object tail, frame;
   struct frame *f;
-
-  assert (DEVICE_X_P (d));
-
   /* This function was previously written to accept only a window argument
      (and to loop over all devices looking for a matching window), but
      that is incorrect because window ID's are not unique across displays. */
 
   for (tail = DEVICE_FRAME_LIST (d); CONSP (tail); tail = XCDR (tail))
     {
-      int i;
-
       frame = XCAR (tail);
       f = XFRAME (frame);
       /* This frame matches if the window is any of its widgets. */
@@ -138,18 +153,18 @@
 	 would incorrectly get sucked away by Emacs if this function matched
 	 on psheet widgets. */
 
-      for (i = 0; i < FRAME_X_NUM_TOP_WIDGETS (f); i++)
-	{
-	  Widget wid = FRAME_X_TOP_WIDGETS (f)[i];
-	  if (wid && XtIsManaged (wid) && wdesc == XtWindow (wid))
-	    return f;
-	}
-
-#ifdef HAVE_SCROLLBARS
-      /* Match if the window is one of this frame's scrollbars. */
-      if (x_window_is_scrollbar (f, wdesc))
-	return f;
-#endif
+      /* Note: that this called only from
+         x_any_widget_or_parent_to_frame it is unnecessary to iterate
+         over the top level widgets. */
+
+      /* Note:  we use to special case scrollbars but this turns out to be a bad idea
+         because
+         1. We sometimes get events for _unmapped_ scrollbars and our
+         callers don't want us to fail.
+         2. Starting with the 21.2 widget stuff there are now loads of
+         widgets to check and it is easy to forget adding them in a loop here.
+         See x_any_window_to_frame
+         3. We pick up all widgets now anyway. */
     }
 
   return 0;
@@ -160,7 +175,7 @@
 {
   while (widget)
     {
-      struct frame *f = x_any_window_to_frame (d, XtWindow (widget));
+      struct frame *f = x_find_frame_for_window (d, XtWindow (widget));
       if (f)
 	return f;
       widget = XtParent (widget);
@@ -328,7 +343,7 @@
   XSetClassHint (dpy, XtWindow (shell), &classhint);
 }
 
-#ifndef HAVE_SESSION
+#ifndef HAVE_WMCOMMAND
 static void
 x_wm_maybe_store_wm_command (struct frame *f)
 {
@@ -379,7 +394,7 @@
 
     }
 }
-#endif /* !HAVE_SESSION */
+#endif /* !HAVE_WMCOMMAND */
 
 static int
 x_frame_iconified_p (struct frame *f)
@@ -421,9 +436,9 @@
 init_x_prop_symbols (void)
 {
 #define def(sym, rsrc) \
-   pure_put (sym, Qx_resource_name, build_string (rsrc))
+   Fput (sym, Qx_resource_name, build_string (rsrc))
 #define defi(sym,rsrc) \
-   def (sym, rsrc); pure_put (sym, Qintegerp, Qt)
+   def (sym, rsrc); Fput (sym, Qintegerp, Qt)
 
 #if 0 /* this interferes with things. #### fix this right */
   def (Qminibuffer, XtNminibuffer);
@@ -644,15 +659,17 @@
   for (ptr = value; *ptr; ptr++)
     if (!BYTE_ASCII_P (*ptr))
       {
-        CONST char * tmp;
+        const char * tmp;
         encoding = DEVICE_XATOM_COMPOUND_TEXT (XDEVICE (FRAME_DEVICE (f)));
-        GET_C_CHARPTR_EXT_CTEXT_DATA_ALLOCA ((CONST char *) value, tmp);
+	TO_EXTERNAL_FORMAT (C_STRING, value,
+			    C_STRING_ALLOCA, tmp,
+			    Qctext);
         new_XtValue = (String) tmp;
         break;
       }
 #endif /* MULE */
 
-  /* ### Caching is device-independent - belongs in update_frame_title. */
+  /* #### Caching is device-independent - belongs in update_frame_title. */
   Xt_GET_VALUE (FRAME_X_SHELL_WIDGET (f), Xt_resource_name, &old_XtValue);
   if (!old_XtValue || strcmp (new_XtValue, old_XtValue))
     {
@@ -743,18 +760,22 @@
 
       if (STRINGP (prop))
 	{
-	  CONST char *extprop;
+	  const char *extprop;
 
 	  if (XSTRING_LENGTH (prop) == 0)
 	    continue;
 
-	  GET_C_STRING_CTEXT_DATA_ALLOCA (prop, extprop);
+	  TO_EXTERNAL_FORMAT (LISP_STRING, prop,
+			      C_STRING_ALLOCA, extprop,
+			      Qctext);
 	  if (STRINGP (val))
 	    {
-	      CONST Extbyte *extval;
+	      const Extbyte *extval;
 	      Extcount extvallen;
 
-	      GET_STRING_CTEXT_DATA_ALLOCA (val, extval, extvallen);
+	      TO_EXTERNAL_FORMAT (LISP_STRING, val,
+				  ALLOCA, (extval, extvallen),
+				  Qctext);
 	      XtVaSetValues (w, XtVaTypedArg, extprop,
 			     XtRString, extval, extvallen + 1,
 			     (XtArgVal) NULL);
@@ -1088,7 +1109,7 @@
       unsigned int modifier = 0, state = 0;
       char *Ctext;
       int numItems = 0, textlen = 0, pos = 0;
-      struct Lisp_Event *lisp_event = XEVENT(event);
+      Lisp_Event *lisp_event = XEVENT (event);
       Lisp_Object item = Qnil;
       struct gcpro gcpro1;
 
@@ -1170,7 +1191,7 @@
 		  Ctext=NULL;
 		  break;
 		}
-	      strcpy (Ctext+pos, (CONST char *)XSTRING_DATA (XCAR (item)));
+	      strcpy (Ctext+pos, (const char *)XSTRING_DATA (XCAR (item)));
 	      pos += XSTRING_LENGTH (XCAR (item)) + 1;
 	      item = XCDR (item);
 	    }
@@ -1240,7 +1261,7 @@
 	{
 	  filePath = transferInfo->dropData->data.files[ii];
 	  hurl = dnd_url_hexify_string ((char *)filePath, "file:");
-          /* ### Mule-izing required */
+          /* #### Mule-izing required */
 	  l_data = Fcons (make_string ((Bufbyte* )hurl,
 				       strlen (hurl)),
 			  l_data);
@@ -1315,7 +1336,7 @@
       char *dnd_data = NULL;
       unsigned long dnd_len = 0;
       int dnd_typ = DndText, dnd_dealloc = 0;
-      struct Lisp_Event *lisp_event = XEVENT(event);
+      Lisp_Event *lisp_event = XEVENT (event);
 
       /* only drag if this is really a press */
       if (EVENT_TYPE(lisp_event) != button_press_event)
@@ -1346,7 +1367,7 @@
 		}
 	      len = XSTRING_LENGTH (XCAR (run)) + 1;
 	      dnd_data = (char *) xrealloc (dnd_data, dnd_len + len);
-	      strcpy (dnd_data + dnd_len - 1, (CONST char *)XSTRING_DATA (XCAR (run)));
+	      strcpy (dnd_data + dnd_len - 1, (const char *)XSTRING_DATA (XCAR (run)));
 	      dnd_len += len;
 	      run = XCDR (run);
 	    }
@@ -1840,7 +1861,7 @@
 #ifdef EXTERNAL_WIDGET
   Window window_id = 0;
 #endif
-  CONST char *name;
+  const char *name;
   Arg al [25];
   int ac = 0;
   Widget text, container, shell;
@@ -1851,7 +1872,9 @@
 #endif
 
   if (STRINGP (f->name))
-    GET_C_STRING_CTEXT_DATA_ALLOCA (f->name, name);
+    TO_EXTERNAL_FORMAT (LISP_STRING, f->name,
+			C_STRING_ALLOCA, name,
+			Qctext);
   else
     name = "emacs";
 
@@ -1880,7 +1903,7 @@
       char *string;
 
       CHECK_STRING (lisp_window_id);
-      string = (char *) (XSTRING_DATA (lisp_window_id));
+      string = (char *) XSTRING_DATA (lisp_window_id);
       if (string[0] == '0' && (string[1] == 'x' || string[1] == 'X'))
 	sscanf (string+2, "%lxu", &window_id);
 #if 0
@@ -2059,9 +2082,9 @@
 	/* tell the window manager about us. */
 	x_wm_store_class_hints (shell_widget, XtName (frame_widget));
 
-#ifndef HAVE_SESSION
+#ifndef HAVE_WMCOMMAND
 	x_wm_maybe_store_wm_command (f);
-#endif /* HAVE_SESSION */
+#endif /* HAVE_WMCOMMAND */
 
 	x_wm_hack_wm_protocols (shell_widget);
       }
@@ -2190,10 +2213,10 @@
 }
 
 static void
-x_mark_frame (struct frame *f, void (*markobj) (Lisp_Object))
+x_mark_frame (struct frame *f)
 {
-  markobj (FRAME_X_ICON_PIXMAP (f));
-  markobj (FRAME_X_ICON_PIXMAP_MASK (f));
+  mark_object (FRAME_X_ICON_PIXMAP (f));
+  mark_object (FRAME_X_ICON_PIXMAP_MASK (f));
 }
 
 static void
@@ -2625,10 +2648,10 @@
 {
   Display *dpy;
 
-#ifndef HAVE_SESSION
+#ifndef HAVE_WMCOMMAND
   if (FRAME_X_TOP_LEVEL_FRAME_P (f))
     x_wm_maybe_move_wm_command (f);
-#endif /* HAVE_SESSION */
+#endif /* HAVE_WMCOMMAND */
 
 #ifdef HAVE_CDE
   DtDndDropUnregister (FRAME_X_TEXT_WIDGET (f));
@@ -2649,7 +2672,7 @@
 #else
   XtDestroyWidget (FRAME_X_SHELL_WIDGET (f));
   /* make sure the windows are really gone! */
-  /* ### Is this REALLY necessary? */
+  /* #### Is this REALLY necessary? */
   XFlush (dpy);
 #endif /* EXTERNAL_WIDGET */