(png_load): Ignore png-supplied background color.
[bpt/emacs.git] / lisp / mouse.el
index dae098e..cbbaf73 100644 (file)
@@ -10,7 +10,7 @@
 
 ;; GNU Emacs is free software; you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
+;; the Free Software Foundation; either version 3, or (at your option)
 ;; any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
@@ -409,11 +409,6 @@ MODE-LINE-P non-nil means dragging a mode line; nil means a header line."
         should-enlarge-minibuffer event mouse y top bot edges wconfig growth)
     (track-mouse
       (progn
-       ;; enlarge-window only works on the selected window, so
-       ;; we must select the window where the start event originated.
-       ;; unwind-protect will restore the old selected window later.
-       (select-window start-event-window)
-
        ;; if this is the bottommost ordinary window, then to
        ;; move its modeline the minibuffer must be enlarged.
        (setq should-enlarge-minibuffer
@@ -421,7 +416,7 @@ MODE-LINE-P non-nil means dragging a mode line; nil means a header line."
                   mode-line-p
                   (not (one-window-p t))
                   (= (nth 1 (window-edges minibuffer))
-                     (nth 3 (window-edges)))))
+                     (nth 3 (window-edges start-event-window)))))
 
        ;; loop reading events and sampling the position of
        ;; the mouse.
@@ -438,9 +433,8 @@ MODE-LINE-P non-nil means dragging a mode line; nil means a header line."
          ;;   - there is a scroll-bar-movement event
          ;;     (same as mouse movement for our purposes)
          ;; quit if
-         ;;   - there is a keyboard event or some other unknown event
-         ;;     unknown event.
-         (cond ((integerp event)
+         ;;   - there is a keyboard event or some other unknown event.
+         (cond ((not (consp event))
                 (setq done t))
 
                ((memq (car event) '(switch-frame select-window))
@@ -448,7 +442,11 @@ MODE-LINE-P non-nil means dragging a mode line; nil means a header line."
 
                ((not (memq (car event) '(mouse-movement scroll-bar-movement)))
                 (when (consp event)
-                  (push event unread-command-events))
+                  ;; Do not unread a drag-mouse-1 event since it will cause the
+                  ;; selection of the window above when dragging the modeline
+                  ;; above the selected window.
+                  (unless (eq (car event) 'drag-mouse-1)
+                    (push event unread-command-events)))
                 (setq done t))
 
                ((not (eq (car mouse) start-event-frame))
@@ -459,7 +457,7 @@ MODE-LINE-P non-nil means dragging a mode line; nil means a header line."
 
                (t
                 (setq y (cdr (cdr mouse))
-                      edges (window-edges)
+                      edges (window-edges start-event-window)
                       top (nth 1 edges)
                       bot (nth 3 edges))
 
@@ -503,7 +501,10 @@ MODE-LINE-P non-nil means dragging a mode line; nil means a header line."
                           (and (not should-enlarge-minibuffer)
                                (> growth 0)
                                mode-line-p
-                               (/= top (nth 1 (window-edges)))))
+                               (/= top
+                                   (nth 1 (window-edges
+                                           ;; Choose right window.
+                                           start-event-window)))))
                   (set-window-configuration wconfig)))))))))
 
 (defun mouse-drag-mode-line (start-event)
@@ -572,10 +573,6 @@ resized by dragging their header-line."
       (error "Attempt to drag leftmost scrollbar")))
     (track-mouse
       (progn
-       ;; enlarge-window only works on the selected window, so
-       ;; we must select the window where the start event originated.
-       ;; unwind-protect will restore the old selected window later.
-       (select-window start-event-window)
        ;; loop reading events and sampling the position of
        ;; the mouse.
        (while (not done)
@@ -611,9 +608,9 @@ resized by dragging their header-line."
                        ;; If the scroll bar is on the window's left,
                        ;; adjust the window on the left.
                        (if (eq which-side 'right)
-                           (selected-window)
+                           start-event-window
                          (mouse-drag-vertical-line-rightward-window
-                          (selected-window)))))
+                          start-event-window))))
                   (setq x (- (car (cdr mouse))
                              (if (eq which-side 'right) 0 2))
                         edges (window-edges window)
@@ -1016,6 +1013,11 @@ should only be used by mouse-drag-region."
                              (overlay-start mouse-drag-overlay))
                           region-termination))
                       last-command this-command)
+                 (when (eq transient-mark-mode 'identity)
+                   ;; Reset `transient-mark-mode' to avoid expanding the region
+                   ;; while scrolling (compare thread on "Erroneous selection
+                   ;; extension ..." on bug-gnu-emacs from 2007-06-10).
+                   (setq transient-mark-mode nil))
                  (push-mark region-commencement t t)
                  (goto-char region-termination)
                  (if (not do-mouse-drag-region-post-process)
@@ -1061,7 +1063,6 @@ should only be used by mouse-drag-region."
                                (not (eq mouse-1-click-follows-link 'double))
                                (= click-count 0)
                                (= (event-click-count event) 1)
-                               (not (input-pending-p))
                                (or (not (integerp mouse-1-click-follows-link))
                                    (let ((t0 (posn-timestamp (event-start start-event)))
                                          (t1 (posn-timestamp (event-end event))))
@@ -1276,7 +1277,17 @@ If MODE is 2 then do the same for lines."
     (unless ignore
       ;; For certain special keys, delete the region.
       (if (member key mouse-region-delete-keys)
-         (delete-region (mark t) (point))
+         (progn
+           ;; Since notionally this is a separate command,
+           ;; run all the hooks that would be run if it were
+           ;; executed separately.
+           (run-hooks 'post-command-hook)
+           (setq last-command this-command)
+           (setq this-original-command 'delete-region)
+           (setq this-command (or (command-remapping this-original-command)
+                                  this-original-command))
+           (run-hooks 'pre-command-hook)
+           (call-interactively this-command))
        ;; Otherwise, unread the key so it gets executed normally.
        (setq unread-command-events
              (nconc events unread-command-events))))
@@ -1521,7 +1532,11 @@ This must be bound to a mouse drag event."
     (with-current-buffer (window-buffer (posn-window posn))
       (if (numberp (posn-point posn))
          (setq beg (posn-point posn)))
-      (move-overlay mouse-secondary-overlay beg (posn-point end)))))
+      (move-overlay mouse-secondary-overlay beg (posn-point end))
+      (x-set-selection
+       'SECONDARY
+       (buffer-substring (overlay-start mouse-secondary-overlay)
+                        (overlay-end mouse-secondary-overlay))))))
 
 (defun mouse-drag-secondary (start-event)
   "Set the secondary selection to the text that the mouse is dragged over.
@@ -1616,7 +1631,10 @@ regardless of where you click."
   ;; Give temporary modes such as isearch a chance to turn off.
   (run-hooks 'mouse-leave-buffer-hook)
   (or mouse-yank-at-point (mouse-set-point click))
-  (insert (x-get-selection 'SECONDARY)))
+  (let ((secondary (x-get-selection 'SECONDARY)))
+    (if secondary
+        (insert (x-get-selection 'SECONDARY))
+      (error "No secondary selection"))))
 
 (defun mouse-kill-secondary ()
   "Kill the text in the secondary selection.