[emacs] (malloc, free): Define as xmalloc, and xfree.
[bpt/emacs.git] / src / w32term.c
index 3f214a5..6db366c 100644 (file)
@@ -14,8 +14,9 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with GNU Emacs; see the file COPYING.  If not, write to
-the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
+along with GNU Emacs; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
 
 /* Added by Kevin Gallo */
 
@@ -1288,7 +1289,7 @@ note_mouse_movement (frame, msg)
   /* Has the mouse moved off the glyph it was on at the last sighting?  */
   else if (LOWORD (msg->lParam) < last_mouse_glyph.left
           || LOWORD (msg->lParam) > last_mouse_glyph.right
-          || HIWORD (msg->lParam) < last_mouse_glyph.left
+          || HIWORD (msg->lParam) < last_mouse_glyph.top
           || HIWORD (msg->lParam) > last_mouse_glyph.bottom)
     {
       frame->mouse_moved = 1;
@@ -1349,7 +1350,8 @@ note_mouse_highlight (f, x, y)
   if (WINDOWP (window) && portion == 0 && row >= 0 && column >= 0
       && row < FRAME_HEIGHT (f) && column < FRAME_WIDTH (f)
       && EQ (w->window_end_valid, w->buffer)
-      && w->last_modified == BUF_MODIFF (XBUFFER (w->buffer)))
+      && w->last_modified == BUF_MODIFF (XBUFFER (w->buffer))
+      && w->last_overlay_modified == BUF_OVERLAY_MODIFF (XBUFFER (w->buffer)))
     {
       int *ptr = FRAME_CURRENT_GLYPHS (f)->charstarts[row];
       int i, pos;
@@ -1507,7 +1509,7 @@ fast_find_position (window, pos, columnp, rowp)
   FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
   int i;
   int row = 0;
-  int left = w->left;
+  int left = WINDOW_LEFT_MARGIN (w);
   int top = w->top;
   int height = XFASTINT (w->height) - ! MINI_WINDOW_P (w);
   int width = window_internal_width (w);
@@ -1592,10 +1594,10 @@ show_mouse_face (dpyinfo, hl)
     {
       int column = (i == FRAME_WIN32_DISPLAY_INFO (f)->mouse_face_beg_row
                    ? FRAME_WIN32_DISPLAY_INFO (f)->mouse_face_beg_col
-                   : w->left);
+                   : WINDOW_LEFT_MARGIN (w));
       int endcolumn = (i == FRAME_WIN32_DISPLAY_INFO (f)->mouse_face_end_row
                       ? FRAME_WIN32_DISPLAY_INFO (f)->mouse_face_end_col
-                      : w->left + width);
+                      : WINDOW_LEFT_MARGIN (w) + width);
       endcolumn = min (endcolumn, FRAME_CURRENT_GLYPHS (f)->used[i]);
 
       /* If the cursor's in the text we are about to rewrite,
@@ -1923,9 +1925,7 @@ x_scroll_bar_set_handle (bar, start, end, rebuild)
   XSETINT (bar->start, start);
   XSETINT (bar->end, end);
 
-  /* If we are less than half of the page use start otherwise use end */
-
-  SetScrollPos (w, SB_CTL, ((start >> 1) < bar->height)?start:end, TRUE);
+  SetScrollPos (w, SB_CTL, start, TRUE);
 
   UNBLOCK_INPUT;
 }
@@ -1945,6 +1945,7 @@ x_scroll_bar_move (bar, top, left, width, height)
   MoveWindow (w, left, top, width, height, TRUE);
   SetScrollRange (w, SB_CTL, 0, height, FALSE);
   InvalidateRect (w, NULL, FALSE);
+  my_show_window (w, SW_NORMAL);
 
   XSETINT (bar->left, left);
   XSETINT (bar->top, top);
@@ -2137,6 +2138,7 @@ win32_judge_scroll_bars (f)
 
    This may be called from a signal handler, so we have to ignore GC
    mark bits.  */
+
 static int
 x_scroll_bar_handle_click (bar, msg, emacs_event)
      struct scroll_bar *bar;
@@ -2161,43 +2163,40 @@ x_scroll_bar_handle_click (bar, msg, emacs_event)
     int y = GetScrollPos ((HWND) msg->msg.lParam, SB_CTL);
 
     switch (LOWORD (msg->msg.wParam))
-    {
-    case SB_THUMBTRACK:
+      {
+      case SB_THUMBTRACK:
        emacs_event->part = scroll_bar_handle;
        if (VERTICAL_SCROLL_BAR_TOP_RANGE (XINT (bar->height)) <= 0xffff)
            y = HIWORD (msg->msg.wParam);
        break;
-    case SB_LINEDOWN:
+      case SB_LINEDOWN:
        emacs_event->part = scroll_bar_down_arrow;
-       if (y < top_range) y++;
        break;
-    case SB_LINEUP:
+      case SB_LINEUP:
        emacs_event->part = scroll_bar_up_arrow;
-       if (y) y--;
        break;
-    case SB_PAGEUP:
+      case SB_PAGEUP:
        emacs_event->part = scroll_bar_above_handle;
        break;
-    case SB_PAGEDOWN:
+      case SB_PAGEDOWN:
        emacs_event->part = scroll_bar_below_handle;
        break;
-    case SB_TOP:
+      case SB_TOP:
        emacs_event->part = scroll_bar_handle;
        y = 0;
        break;
-    case SB_BOTTOM:
+      case SB_BOTTOM:
        emacs_event->part = scroll_bar_handle;
        y = top_range;
        break;
-    case SB_THUMBPOSITION:
+      case SB_THUMBPOSITION:
        emacs_event->part = scroll_bar_handle;
        break;
-    case SB_ENDSCROLL:
-    default:
+      case SB_ENDSCROLL:
+      default:
+       SetScrollPos (SCROLL_BAR_WIN32_WINDOW (bar), SB_CTL, y, TRUE);
        return FALSE;
-    }
-
-    x_scroll_bar_set_handle (bar, y , y, 0);
+      }
 
     XSETINT (emacs_event->x, y);
     XSETINT (emacs_event->y, top_range);
@@ -2273,6 +2272,7 @@ x_scroll_bar_clear (f)
       HDC hdc = GetDC (window);
       RECT rect;
 
+      my_show_window (window, SW_HIDE);
       GetClientRect (window, &rect);
       select_palette (f, hdc);
       win32_clear_rect (f, hdc, &rect);
@@ -2347,7 +2347,6 @@ is_dead_key (int wparam)
    We return the number of characters stored into the buffer,
    thus pretending to be `read'.
 
-   WAITP is nonzero if we should block until input arrives.
    EXPECTED is nonzero if the caller knows input is available.  
 
    Some of these messages are reposted back to the message queue since the
@@ -2360,11 +2359,10 @@ is_dead_key (int wparam)
 */
 
 int
-w32_read_socket (sd, bufp, numchars, waitp, expected)
+w32_read_socket (sd, bufp, numchars, expected)
      register int sd;
      register struct input_event *bufp;
      register int numchars;
-     int waitp;
      int expected;
 {
   int count = 0;
@@ -2396,13 +2394,6 @@ w32_read_socket (sd, bufp, numchars, waitp, expected)
     {
       switch (msg.msg.message)
        {
-       case WM_ERASEBKGND:
-         f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
-         if (f)
-           {
-             win32_clear_rect (f, NULL, &msg.rect);
-           }
-         break;
        case WM_PAINT:
          {
            f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
@@ -2417,22 +2408,16 @@ w32_read_socket (sd, bufp, numchars, waitp, expected)
                  }
                else
                  {
+                   /* Erase background again for safety.  */
+                   win32_clear_rect (f, NULL, &msg.rect);
                    dumprectangle (f,
                                   msg.rect.left,
                                   msg.rect.top,
                                   msg.rect.right-msg.rect.left+1,
                                   msg.rect.bottom-msg.rect.top+1);
-                     
                  }
              }
          }
-         
-         break;
-       case WM_PALETTECHANGED:
-         f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
-         if (f)
-           /* Realize palette - will force update if needed. */
-           release_frame_dc (f, get_frame_dc (f));
          break;
        case WM_KEYDOWN:
        case WM_SYSKEYDOWN:
@@ -2482,8 +2467,12 @@ w32_read_socket (sd, bufp, numchars, waitp, expected)
                      add = 1;
                    }
 
-                 /* Throw dead keys away.  */
-                 if (is_dead_key (msg.msg.wParam))
+                 /* Throw dead keys away.  However, be sure not to
+                    throw away the dead key if it was produced using
+                    AltGr and there is a valid AltGr scan code for
+                    this key.  */
+                 if (is_dead_key (msg.msg.wParam) 
+                     && !((VkKeyScan ((char) bufp->code) & 0xff00) == 0x600))
                    break;
 
                  bufp += add;
@@ -2630,7 +2619,7 @@ w32_read_socket (sd, bufp, numchars, waitp, expected)
          
          break;
        case WM_SYSCOMMAND:
-         switch (msg.msg.wParam
+         switch (msg.msg.wParam & 0xfff0)  /* Lower 4 bits used by Windows. */
            {
            case SC_CLOSE:
              f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
@@ -3309,6 +3298,21 @@ x_set_window_size (f, change_gravity, cols, rows)
 \f
 /* Mouse warping.  */
 
+void
+x_set_mouse_pixel_position (f, pix_x, pix_y)
+     struct frame *f;
+     int pix_x, pix_y;
+{
+  BLOCK_INPUT;
+
+  pix_x += f->output_data.win32->left_pos;
+  pix_y += f->output_data.win32->top_pos;
+
+  SetCursorPos (pix_x, pix_y);
+
+  UNBLOCK_INPUT;
+}
+
 void
 x_set_mouse_position (f, x, y)
      struct frame *f;
@@ -3325,25 +3329,7 @@ x_set_mouse_position (f, x, y)
   if (pix_y < 0) pix_y = 0;
   if (pix_y > PIXEL_HEIGHT (f)) pix_y = PIXEL_HEIGHT (f);
 
-  BLOCK_INPUT;
-
-  SetCursorPos (pix_x, pix_y);
-
-  UNBLOCK_INPUT;
-}
-
-/* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F.  */
-
-void
-x_set_mouse_pixel_position (f, pix_x, pix_y)
-     struct frame *f;
-     int pix_x, pix_y;
-{
-  BLOCK_INPUT;
-
-  SetCursorPos (pix_x, pix_y);
-
-  UNBLOCK_INPUT;
+  x_set_mouse_pixel_position (f, pix_x, pix_y);
 }
 \f
 /* focus shifting, raising and lowering.  */