diff src/xterm.c @ 86161:3408ab8b4152

* xterm.h (struct scroll_bar): Only use Lisp_Object for lisp data. Turn integer fields into `int'. Merge x_window_low and x_window_high. (SCROLL_BAR_PACK, SCROLL_BAR_UNPACK, SCROLL_BAR_X_WINDOW) (SET_SCROLL_BAR_X_WINDOW): Remove. (SCROLL_BAR_X_WIDGET, SET_SCROLL_BAR_X_WIDGET): Access the new x_window field directly. * xterm.c (x_scroll_bar_create): Use a pseudovector. Don't wrap/unwrap integers into Lisp_Objects. (XTset_vertical_scroll_bar, x_scroll_bar_handle_click) (x_scroll_bar_report_motion): Don't wrap/unwrap integers into Lisp_Objects. (x_term_init): Use SDATA. (x_window_to_scroll_bar, x_create_toolkit_scroll_bar) (x_scroll_bar_set_handle, x_scroll_bar_remove) (XTset_vertical_scroll_bar, x_scroll_bar_expose) (x_scroll_bar_report_motion, x_scroll_bar_clear): * xfns.c (x_set_background_color): * gtkutil.c (xg_create_scroll_bar, xg_set_toolkit_scroll_bar_thumb): Access the new x_window field directly.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Fri, 16 Nov 2007 21:04:30 +0000
parents b9c295c443e2
children 1da472256ca6
line wrap: on
line diff
--- a/src/xterm.c	Fri Nov 16 20:36:34 2007 +0000
+++ b/src/xterm.c	Fri Nov 16 21:04:30 2007 +0000
@@ -3962,7 +3962,7 @@
 			       condemned = Qnil,
 			       ! GC_NILP (bar));
 	   bar = XSCROLL_BAR (bar)->next)
-	if (SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar)) == window_id &&
+	if (XSCROLL_BAR (bar)->x_window == window_id &&
             FRAME_X_DISPLAY (XFRAME (frame)) == display)
 	  return XSCROLL_BAR (bar);
     }
@@ -4280,9 +4280,8 @@
     }
 }
 
-
-#else /* !USE_MOTIF, i.e. Xaw or GTK */
-#ifdef USE_GTK
+#elif defined USE_GTK
+
 /* Scroll bar callback for GTK scroll bars.  WIDGET is the scroll
    bar widget.  DATA is a pointer to the scroll_bar structure. */
 
@@ -4353,7 +4352,7 @@
     }
 }
 
-#else /* not USE_GTK */
+#else /* not USE_GTK and not USE_MOTIF */
 
 /* Xaw scroll bar callback.  Invoked when the thumb is dragged.
    WIDGET is the scroll bar widget.  CLIENT_DATA is a pointer to the
@@ -4436,8 +4435,7 @@
   x_send_scroll_bar_event (bar->window, part, position, height);
 }
 
-#endif /* not USE_GTK */
-#endif /* not USE_MOTIF */
+#endif /* not USE_GTK and not USE_MOTIF */
 
 #define SCROLL_BAR_NAME "verticalScrollBar"
 
@@ -4643,7 +4641,7 @@
   /* Remember X window and widget in the scroll bar vector.  */
   SET_SCROLL_BAR_X_WIDGET (bar, widget);
   xwindow = XtWindow (widget);
-  SET_SCROLL_BAR_X_WINDOW (bar, xwindow);
+  bar->x_window = xwindow;
 
   UNBLOCK_INPUT;
 }
@@ -4787,7 +4785,7 @@
 {
   struct frame *f = XFRAME (w->frame);
   struct scroll_bar *bar
-    = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE), Qnil));
+    = ALLOCATE_PSEUDOVECTOR (struct scroll_bar, x_window, PVEC_OTHER);
 
   BLOCK_INPUT;
 
@@ -4831,21 +4829,19 @@
 			    CopyFromParent,
 			     /* Attributes.  */
 			    mask, &a);
-    SET_SCROLL_BAR_X_WINDOW (bar, window);
+    bar->x_window = window;
   }
 #endif /* not USE_TOOLKIT_SCROLL_BARS */
 
   XSETWINDOW (bar->window, w);
-  XSETINT (bar->top, top);
-  XSETINT (bar->left, left);
-  XSETINT (bar->width, width);
-  XSETINT (bar->height, height);
-  XSETINT (bar->start, 0);
-  XSETINT (bar->end, 0);
+  bar->top = top;
+  bar->left = left;
+  bar->width = width;
+  bar->height = height;
+  bar->start = 0;
+  bar->end = 0;
   bar->dragging = Qnil;
-#ifdef USE_TOOLKIT_SCROLL_BARS
-  bar->fringe_extended_p = Qnil;
-#endif
+  bar->fringe_extended_p = 0;
 
   /* Add bar to its frame's list of scroll bars.  */
   bar->next = FRAME_SCROLL_BARS (f);
@@ -4859,12 +4855,12 @@
   {
 #ifdef USE_GTK
     xg_update_scrollbar_pos (f,
-                             SCROLL_BAR_X_WINDOW (bar),
+                             bar->x_window,
                              top,
                              left + VERTICAL_SCROLL_BAR_WIDTH_TRIM,
                              width - VERTICAL_SCROLL_BAR_WIDTH_TRIM * 2,
                              max (height, 1));
-    xg_show_scroll_bar (SCROLL_BAR_X_WINDOW (bar));
+    xg_show_scroll_bar (bar->x_window);
 #else /* not USE_GTK */
     Widget scroll_bar = SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f), bar);
     XtConfigureWidget (scroll_bar,
@@ -4876,7 +4872,7 @@
 #endif /* not USE_GTK */
     }
 #else /* not USE_TOOLKIT_SCROLL_BARS */
-  XMapRaised (FRAME_X_DISPLAY (f), SCROLL_BAR_X_WINDOW (bar));
+  XMapRaised (FRAME_X_DISPLAY (f), bar->x_window);
 #endif /* not USE_TOOLKIT_SCROLL_BARS */
 
   UNBLOCK_INPUT;
@@ -4884,6 +4880,8 @@
 }
 
 
+#ifndef USE_TOOLKIT_SCROLL_BARS
+
 /* Draw BAR's handle in the proper position.
 
    If the handle is already drawn from START to END, don't bother
@@ -4897,8 +4895,6 @@
    the bar's top is as far down as it goes; otherwise, there's no way
    to move to the very end of the buffer.  */
 
-#ifndef USE_TOOLKIT_SCROLL_BARS
-
 static void
 x_scroll_bar_set_handle (bar, start, end, rebuild)
      struct scroll_bar *bar;
@@ -4906,7 +4902,7 @@
      int rebuild;
 {
   int dragging = ! NILP (bar->dragging);
-  Window w = SCROLL_BAR_X_WINDOW (bar);
+  Window w = bar->x_window;
   FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window)));
   GC gc = f->output_data.x->normal_gc;
 
@@ -5009,12 +5005,12 @@
 
 #ifdef USE_TOOLKIT_SCROLL_BARS
 #ifdef USE_GTK
-  xg_remove_scroll_bar (f, SCROLL_BAR_X_WINDOW (bar));
+  xg_remove_scroll_bar (f, bar->x_window);
 #else /* not USE_GTK */
   XtDestroyWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f), bar));
 #endif /* not USE_GTK */
 #else
-  XDestroyWindow (FRAME_X_DISPLAY (f), SCROLL_BAR_X_WINDOW (bar));
+  XDestroyWindow (FRAME_X_DISPLAY (f), bar->x_window);
 #endif
 
   /* Disassociate this scroll bar from its window.  */
@@ -5112,19 +5108,19 @@
 
       BLOCK_INPUT;
 
-      if (sb_left != XINT (bar->left))
+      if (sb_left != bar->left)
 	mask |= CWX;
-      if (top != XINT (bar->top))
+      if (top != bar->top)
 	mask |= CWY;
-      if (sb_width != XINT (bar->width))
+      if (sb_width != bar->width)
 	mask |= CWWidth;
-      if (height != XINT (bar->height))
+      if (height != bar->height)
 	mask |= CWHeight;
 
 #ifdef USE_TOOLKIT_SCROLL_BARS
 
       /* Move/size the scroll bar widget.  */
-      if (mask || !NILP (bar->fringe_extended_p) != fringe_extended_p)
+      if (mask || bar->fringe_extended_p != fringe_extended_p)
 	{
 	  /* Since toolkit scroll bars are smaller than the space reserved
 	     for them on the frame, we have to clear "under" them.  */
@@ -5139,7 +5135,7 @@
 	    }
 #ifdef USE_GTK
           xg_update_scrollbar_pos (f,
-                                   SCROLL_BAR_X_WINDOW (bar),
+                                   bar->x_window,
                                    top,
                                    sb_left + VERTICAL_SCROLL_BAR_WIDTH_TRIM,
                                    sb_width - VERTICAL_SCROLL_BAR_WIDTH_TRIM *2,
@@ -5195,23 +5191,23 @@
 	  wc.y = top;
 	  wc.width = sb_width - VERTICAL_SCROLL_BAR_WIDTH_TRIM * 2;
 	  wc.height = height;
-	  XConfigureWindow (FRAME_X_DISPLAY (f), SCROLL_BAR_X_WINDOW (bar),
+	  XConfigureWindow (FRAME_X_DISPLAY (f), bar->x_window,
 			    mask, &wc);
 	}
 
 #endif /* not USE_TOOLKIT_SCROLL_BARS */
 
       /* Remember new settings.  */
-      XSETINT (bar->left, sb_left);
-      XSETINT (bar->top, top);
-      XSETINT (bar->width, sb_width);
-      XSETINT (bar->height, height);
+      bar->left = sb_left;
+      bar->top = top;
+      bar->width = sb_width;
+      bar->height = height;
 
       UNBLOCK_INPUT;
     }
 
 #ifdef USE_TOOLKIT_SCROLL_BARS
-  bar->fringe_extended_p = fringe_extended_p ? Qt : Qnil;
+  bar->fringe_extended_p = fringe_extended_p;
 
   x_set_toolkit_scroll_bar_thumb (bar, portion, position, whole);
 #else /* not USE_TOOLKIT_SCROLL_BARS */
@@ -5355,7 +5351,7 @@
      struct scroll_bar *bar;
      XEvent *event;
 {
-  Window w = SCROLL_BAR_X_WINDOW (bar);
+  Window w = bar->x_window;
   FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window)));
   GC gc = f->output_data.x->normal_gc;
   int width_trim = VERTICAL_SCROLL_BAR_WIDTH_TRIM;
@@ -5419,18 +5415,18 @@
 #if 0
     FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window)));
     int internal_height
-      = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f, XINT (bar->height));
+      = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f, bar->height);
 #endif
     int top_range
-      = VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height));
+      = VERTICAL_SCROLL_BAR_TOP_RANGE (f, bar->height);
     int y = event->xbutton.y - VERTICAL_SCROLL_BAR_TOP_BORDER;
 
     if (y < 0) y = 0;
     if (y > top_range) y = top_range;
 
-    if (y < XINT (bar->start))
+    if (y < bar->start)
       emacs_event->part = scroll_bar_above_handle;
-    else if (y < XINT (bar->end) + VERTICAL_SCROLL_BAR_MIN_HANDLE)
+    else if (y < bar->end + VERTICAL_SCROLL_BAR_MIN_HANDLE)
       emacs_event->part = scroll_bar_handle;
     else
       emacs_event->part = scroll_bar_below_handle;
@@ -5523,7 +5519,7 @@
      unsigned long *time;
 {
   struct scroll_bar *bar = XSCROLL_BAR (last_mouse_scroll_bar);
-  Window w = SCROLL_BAR_X_WINDOW (bar);
+  Window w = bar->x_window;
   FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window)));
   int win_x, win_y;
   Window dummy_window;
@@ -5550,10 +5546,10 @@
     {
 #if 0
       int inside_height
-	= VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f, XINT (bar->height));
+	= VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f, bar->height);
 #endif
       int top_range
-	= VERTICAL_SCROLL_BAR_TOP_RANGE     (f, XINT (bar->height));
+	= VERTICAL_SCROLL_BAR_TOP_RANGE     (f, bar->height);
 
       win_y -= VERTICAL_SCROLL_BAR_TOP_BORDER;
 
@@ -5570,9 +5566,9 @@
 
       if (! NILP (bar->dragging))
 	*part = scroll_bar_handle;
-      else if (win_y < XINT (bar->start))
+      else if (win_y < bar->start)
 	*part = scroll_bar_above_handle;
-      else if (win_y < XINT (bar->end) + VERTICAL_SCROLL_BAR_MIN_HANDLE)
+      else if (win_y < bar->end + VERTICAL_SCROLL_BAR_MIN_HANDLE)
 	*part = scroll_bar_handle;
       else
 	*part = scroll_bar_below_handle;
@@ -5609,7 +5605,7 @@
     for (bar = FRAME_SCROLL_BARS (f); VECTORP (bar);
 	 bar = XSCROLL_BAR (bar)->next)
       XClearArea (FRAME_X_DISPLAY (f),
-		  SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar)),
+		  XSCROLL_BAR (bar)->x_window,
 		  0, 0, 0, 0, True);
 #endif /* not USE_TOOLKIT_SCROLL_BARS */
 }
@@ -6847,12 +6843,10 @@
 
                 if (tool_bar_p && event.xbutton.button < 4)
                   {
-                    if (event.xbutton.type == ButtonPress)
-                      handle_tool_bar_click (f, x, y, 1, 0);
-                    else
-                      handle_tool_bar_click (f, x, y, 0,
-                                             x_x_to_emacs_modifiers (dpyinfo,
-								     event.xbutton.state));
+		    handle_tool_bar_click (f, x, y,
+					   event.xbutton.type == ButtonPress,
+					   x_x_to_emacs_modifiers (dpyinfo,
+								   event.xbutton.state));
                   }
               }
 
@@ -7854,7 +7848,7 @@
 
      Closing the display is reported to lead to a bus error on
      OpenWindows in certain situations.  I suspect that is a bug
-     in OpenWindows.  I don't know how to cicumvent it here.  */
+     in OpenWindows.  I don't know how to circumvent it here.  */
 
 #ifdef USE_X_TOOLKIT
   /* If DPYINFO is null, this means we didn't open the display
@@ -7905,6 +7899,10 @@
 
   unbind_to (index, Qnil);
   clear_waiting_for_input ();
+  /* FIXME: This is an asynchronous interrupt w.r.t elisp, so signalling an
+     error might not be the best thing to do.  I'd vote for creating an
+     elisp event and stuffing it in the queue so people can bind to it via
+     the global map.  --Stef  */
   error ("%s", error_msg);
 }
 
@@ -10868,8 +10866,8 @@
     /* Mac OS X 10.3's Xserver sometimes reports 0.0mm.  */
     dpyinfo->resy = (mm < 1) ? 100 : pixels * 25.4 / mm;
     pixels = DisplayWidth (dpyinfo->display, screen_number);
+    mm = DisplayWidthMM (dpyinfo->display, screen_number);
     /* Mac OS X 10.3's Xserver sometimes reports 0.0mm.  */
-    mm = DisplayWidthMM (dpyinfo->display, screen_number);
     dpyinfo->resx = (mm < 1) ? 100 : pixels * 25.4 / mm;
   }
 
@@ -11038,13 +11036,13 @@
 				    Qnil, Qnil);
 #ifdef USE_XIM
     if (STRINGP (value)
-	&& (!strcmp (XSTRING (value)->data, "false")
-	    || !strcmp (XSTRING (value)->data, "off")))
+	&& (!strcmp (SDATA (value), "false")
+	    || !strcmp (SDATA (value), "off")))
       use_xim = 0;
 #else
     if (STRINGP (value)
-	&& (!strcmp (XSTRING (value)->data, "true")
-	    || !strcmp (XSTRING (value)->data, "on")))
+	&& (!strcmp (SDATA (value), "true")
+	    || !strcmp (SDATA (value), "on")))
       use_xim = 1;
 #endif
   }