Merged in changes from CVS trunk.
[bpt/emacs.git] / src / w32term.c
index 0614522..e02019f 100644 (file)
@@ -62,7 +62,8 @@ Boston, MA 02111-1307, USA.  */
 \f
 /* Fringe bitmaps.  */
 
-static HBITMAP fringe_bmp[MAX_FRINGE_BITMAPS];
+static int max_fringe_bmp = 0;
+static HBITMAP *fringe_bmp = 0;
 
 /* Non-nil means Emacs uses toolkit scroll bars.  */
 
@@ -259,7 +260,7 @@ static void x_frame_rehighlight P_ ((struct w32_display_info *));
 static void x_draw_hollow_cursor P_ ((struct window *, struct glyph_row *));
 static void x_draw_bar_cursor P_ ((struct window *, struct glyph_row *, int,
                                   enum text_cursor_kinds));
-static void w32_clip_to_row P_ ((struct window *, struct glyph_row *, HDC));
+static void w32_clip_to_row P_ ((struct window *, struct glyph_row *, int, HDC));
 
 static Lisp_Object Qvendor_specific_keysyms;
 
@@ -539,9 +540,8 @@ x_update_window_end (w, cursor_on_p, mouse_face_overwritten_p)
                                output_cursor.vpos,
                                output_cursor.x, output_cursor.y);
 
-      x_draw_vertical_border (w);
-
-      draw_window_fringes (w);
+      if (draw_window_fringes (w, 1))
+       x_draw_vertical_border (w);
 
       UNBLOCK_INPUT;
     }
@@ -691,12 +691,12 @@ w32_draw_fringe_bitmap (w, row, p)
       int oldVH = row->visible_height;
       row->visible_height = p->h;
       row->y -= rowY - p->y;
-      w32_clip_to_row (w, row, hdc);
+      w32_clip_to_row (w, row, -1, hdc);
       row->y = oldY;
       row->visible_height = oldVH;
     }
   else
-    w32_clip_to_row (w, row, hdc);
+    w32_clip_to_row (w, row, -1, hdc);
 
   if (p->bx >= 0 && !p->overlay_p)
     {
@@ -704,7 +704,7 @@ w32_draw_fringe_bitmap (w, row, p)
                     p->bx, p->by, p->nx, p->ny);
     }
 
-  if (p->which)
+  if (p->which && p->which < max_fringe_bmp)
     {
       HBITMAP pixmap = fringe_bmp[p->which];
       HDC compat_hdc;
@@ -767,6 +767,15 @@ w32_define_fringe_bitmap (which, bits, h, wd)
      unsigned short *bits;
      int h, wd;
 {
+  if (which >= max_fringe_bmp)
+    {
+      int i = max_fringe_bmp;
+      max_fringe_bmp = which + 20;
+      fringe_bmp = (HBITMAP *) xrealloc (fringe_bmp, max_fringe_bmp * sizeof (HBITMAP));
+      while (i < max_fringe_bmp)
+       fringe_bmp[i++] = 0;
+    }
+
   fringe_bmp[which] = CreateBitmap (wd, h, 1, 1, bits);
 }
 
@@ -774,6 +783,9 @@ static void
 w32_destroy_fringe_bitmap (which)
      int which;
 {
+  if (which >= max_fringe_bmp)
+    return;
+
   if (fringe_bmp[which])
     DeleteObject (fringe_bmp[which]);
   fringe_bmp[which] = 0;
@@ -1197,7 +1209,6 @@ w32_text_out (s, x, y,chars,nchars)
 }
 
 
-
 static void x_set_glyph_string_clipping P_ ((struct glyph_string *));
 static void x_set_glyph_string_gc P_ ((struct glyph_string *));
 static void x_draw_glyph_string_background P_ ((struct glyph_string *,
@@ -2049,7 +2060,6 @@ x_draw_image_foreground (s)
 }
 
 
-
 /* Draw a relief around the image glyph string S.  */
 
 static void
@@ -2506,7 +2516,7 @@ x_draw_glyph_string (s)
         }
           else
             {
-              w32_fill_area (s->f, s->hdc, s->face->underline_color, s->x,
+              w32_fill_area (s->f, s->hdc, s->face->overline_color, s->x,
                              s->y + dy, s->width, h);
             }
         }
@@ -2753,9 +2763,13 @@ x_scroll_run (w, run)
     /* If the dirty region is not what we expected, redraw the entire frame.  */
     if (!EqualRgn (combined, expect_dirty))
       SET_FRAME_GARBAGED (f);
+
+    DeleteObject (dirty);
+    DeleteObject (combined);
   }
 
   UNBLOCK_INPUT;
+  DeleteObject (expect_dirty);
 }
 
 
@@ -2800,14 +2814,6 @@ x_new_focus_frame (dpyinfo, frame)
       if (old_focus && old_focus->auto_lower)
        x_lower_frame (old_focus);
 
-
-
-
-
-
-
-
-
       if (dpyinfo->w32_focus_frame && dpyinfo->w32_focus_frame->auto_raise)
        pending_autoraise_frame = dpyinfo->w32_focus_frame;
       else
@@ -4676,7 +4682,6 @@ w32_read_socket (sd, expected, hold_quit)
           if (f)
             x_new_focus_frame (dpyinfo, f);
 
-
          dpyinfo->grabbed = 0;
          check_visibility = 1;
          break;
@@ -4894,7 +4899,6 @@ w32_read_socket (sd, expected, hold_quit)
 }
 
 
-
 \f
 /***********************************************************************
                             Text Cursor
@@ -4908,18 +4912,19 @@ w32_read_socket (sd, expected, hold_quit)
    mode lines must be clipped to the whole window.  */
 
 static void
-w32_clip_to_row (w, row, hdc)
+w32_clip_to_row (w, row, area, hdc)
      struct window *w;
      struct glyph_row *row;
+     int area;
      HDC hdc;
 {
   struct frame *f = XFRAME (WINDOW_FRAME (w));
   RECT clip_rect;
-  int window_y, window_width;
+  int window_x, window_y, window_width;
 
-  window_box (w, -1, 0, &window_y, &window_width, 0);
+  window_box (w, area, &window_x, &window_y, &window_width, 0);
 
-  clip_rect.left = WINDOW_TO_FRAME_PIXEL_X (w, 0);
+  clip_rect.left = window_x;
   clip_rect.top = WINDOW_TO_FRAME_PIXEL_Y (w, row->y);
   clip_rect.top = max (clip_rect.top, window_y);
   clip_rect.right = clip_rect.left + window_width;
@@ -4979,7 +4984,7 @@ x_draw_hollow_cursor (w, row)
   rect.right = rect.left + wd;
   hdc = get_frame_dc (f);
   /* Set clipping, draw the rectangle, and reset clipping again.  */
-  w32_clip_to_row (w, row, hdc);
+  w32_clip_to_row (w, row, TEXT_AREA, hdc);
   FrameRect (hdc, &rect, hb);
   DeleteObject (hb);
   w32_set_clip_rectangle (hdc, NULL);
@@ -5045,7 +5050,7 @@ x_draw_bar_cursor (w, row, width, kind)
 
 
       hdc = get_frame_dc (f);
-      w32_clip_to_row (w, row, hdc);
+      w32_clip_to_row (w, row, TEXT_AREA, hdc);
 
       if (kind == BAR_CURSOR)
        {
@@ -5369,47 +5374,17 @@ void
 x_calc_absolute_position (f)
      struct frame *f;
 {
-  POINT pt;
   int flags = f->size_hint_flags;
 
-  pt.x = pt.y = 0;
-
-  /* Find the position of the outside upper-left corner of
-     the inner window, with respect to the outer window.
-     But do this only if we will need the results.  */
-  if (f->output_data.w32->parent_desc != FRAME_W32_DISPLAY_INFO (f)->root_window)
-    {
-      BLOCK_INPUT;
-      MapWindowPoints (FRAME_W32_WINDOW (f),
-                      f->output_data.w32->parent_desc,
-                      &pt, 1);
-      UNBLOCK_INPUT;
-    }
-
-  {
-      RECT rt;
-      rt.left = rt.right = rt.top = rt.bottom = 0;
-
-      BLOCK_INPUT;
-      AdjustWindowRect(&rt, f->output_data.w32->dwStyle,
-                      FRAME_EXTERNAL_MENU_BAR (f));
-      UNBLOCK_INPUT;
-
-      pt.x += (rt.right - rt.left);
-      pt.y += (rt.bottom - rt.top);
-  }
-
   /* Treat negative positions as relative to the leftmost bottommost
      position that fits on the screen.  */
   if (flags & XNegative)
     f->left_pos = (FRAME_W32_DISPLAY_INFO (f)->width
-                  - 2 * f->border_width - pt.x
                   - FRAME_PIXEL_WIDTH (f)
                   + f->left_pos);
 
   if (flags & YNegative)
     f->top_pos = (FRAME_W32_DISPLAY_INFO (f)->height
-                 - 2 * f->border_width - pt.y
                  - FRAME_PIXEL_HEIGHT (f)
                  + f->top_pos);
   /* The left_pos and top_pos