Update copyright notices for 2013.
[bpt/emacs.git] / lisp / w32-common-fns.el
CommitLineData
f701ab72
DC
1;;; w32-common-fns.el --- Lisp routines for Windows and Cygwin-w32
2
ab422c4d 3;; Copyright (C) 1994, 2001-2013 Free Software Foundation, Inc.
f701ab72
DC
4
5;; This file is part of GNU Emacs.
6
7;; GNU Emacs is free software: you can redistribute it and/or modify
8;; it under the terms of the GNU General Public License as published by
9;; the Free Software Foundation, either version 3 of the License, or
10;; (at your option) any later version.
11
12;; GNU Emacs is distributed in the hope that it will be useful,
13;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15;; GNU General Public License for more details.
16
17;; You should have received a copy of the GNU General Public License
18;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
19
20;;; Commentary:
21;;;
22;;; This file contains functions that are used by both native NT Emacs
23;;; and Cygwin Emacs compiled to use the native Windows widget
24;;; library.
25
26(defun w32-version ()
27 "Return the MS-Windows version numbers.
28The value is a list of three integers: the major and minor version
29numbers, and the build number."
30 (x-server-version))
31
32(defun w32-using-nt ()
33 "Return non-nil if running on a Windows NT descendant.
34That includes all Windows systems except for 9X/Me."
35 (getenv "SystemRoot"))
36
37(declare-function w32-get-clipboard-data "w32select.c")
38(declare-function w32-set-clipboard-data "w32select.c")
39(declare-function x-server-version "w32fns.c" (&optional display))
40
41;;; Fix interface to (X-specific) mouse.el
42(defun x-set-selection (type data)
43 "Make an X selection of type TYPE and value DATA.
44The argument TYPE (nil means `PRIMARY') says which selection, and
45DATA specifies the contents. TYPE must be a symbol. \(It can also
46be a string, which stands for the symbol with that name, but this
47is considered obsolete.) DATA may be a string, a symbol, an
48integer (or a cons of two integers or list of two integers).
49
50The selection may also be a cons of two markers pointing to the same buffer,
51or an overlay. In these cases, the selection is considered to be the text
52between the markers *at whatever time the selection is examined*.
53Thus, editing done in the buffer after you specify the selection
54can alter the effective value of the selection.
55
56The data may also be a vector of valid non-vector selection values.
57
58The return value is DATA.
59
60Interactively, this command sets the primary selection. Without
61prefix argument, it reads the selection in the minibuffer. With
62prefix argument, it uses the text of the region as the selection value.
63
64Note that on MS-Windows, primary and secondary selections set by Emacs
65are not available to other programs."
66 (put 'x-selections (or type 'PRIMARY) data))
67
68(defun x-get-selection (&optional type _data-type)
69 "Return the value of an X Windows selection.
70The argument TYPE (default `PRIMARY') says which selection,
71and the argument DATA-TYPE (default `STRING') says
72how to convert the data.
73
74TYPE may be any symbol \(but nil stands for `PRIMARY'). However,
75only a few symbols are commonly used. They conventionally have
76all upper-case names. The most often used ones, in addition to
77`PRIMARY', are `SECONDARY' and `CLIPBOARD'.
78
79DATA-TYPE is usually `STRING', but can also be one of the symbols
80in `selection-converter-alist', which see."
81 (get 'x-selections (or type 'PRIMARY)))
82
83;; x-selection-owner-p is used in simple.el
84(defun x-selection-owner-p (&optional type)
85 (and (memq type '(nil PRIMARY SECONDARY))
86 (get 'x-selections (or type 'PRIMARY))))
87
88;; The "Windows" keys on newer keyboards bring up the Start menu
89;; whether you want it or not - make Emacs ignore these keystrokes
90;; rather than beep.
91(global-set-key [lwindow] 'ignore)
92(global-set-key [rwindow] 'ignore)
93
94(defvar w32-charset-info-alist) ; w32font.c
95
96\f
97;;;; Selections
98
99;; We keep track of the last text selected here, so we can check the
100;; current selection against it, and avoid passing back our own text
101;; from x-selection-value.
102(defvar x-last-selected-text nil)
103
104(defun x-get-selection-value ()
105 "Return the value of the current selection.
106Consult the selection. Treat empty strings as if they were unset."
107 (if x-select-enable-clipboard
108 (let (text)
109 ;; Don't die if x-get-selection signals an error.
110 (condition-case c
111 (setq text (w32-get-clipboard-data))
112 (error (message "w32-get-clipboard-data:%s" c)))
113 (if (string= text "") (setq text nil))
114 (cond
115 ((not text) nil)
116 ((eq text x-last-selected-text) nil)
117 ((string= text x-last-selected-text)
118 ;; Record the newer string, so subsequent calls can use the 'eq' test.
119 (setq x-last-selected-text text)
120 nil)
121 (t
122 (setq x-last-selected-text text))))))
123\f
124(defalias 'x-selection-value 'x-get-selection-value)
125
126;; Arrange for the kill and yank functions to set and check the clipboard.
127(setq interprogram-cut-function 'x-select-text)
128(setq interprogram-paste-function 'x-get-selection-value)
129
130(provide 'w32-common-fns)