/* Graphical user interface functions for the Microsoft Windows API.
-Copyright (C) 1989, 1992-2014 Free Software Foundation, Inc.
+Copyright (C) 1989, 1992-2015 Free Software Foundation, Inc.
This file is part of GNU Emacs.
run_window_configuration_change_hook (f);
}
+static void
+w32_set_title_bar_text (struct frame *f, Lisp_Object name)
+{
+ if (FRAME_W32_WINDOW (f))
+ {
+ block_input ();
+#ifdef __CYGWIN__
+ GUI_FN (SetWindowText) (FRAME_W32_WINDOW (f),
+ GUI_SDATA (GUI_ENCODE_SYSTEM (name)));
+#else
+ /* The frame's title many times shows the name of the file
+ visited in the selected window's buffer, so it makes sense to
+ support non-ASCII characters outside of the current system
+ codepage in the title. */
+ if (w32_unicode_filenames)
+ {
+ Lisp_Object encoded_title = ENCODE_UTF_8 (name);
+ wchar_t *title_w;
+ int tlen = pMultiByteToWideChar (CP_UTF8, 0, SSDATA (encoded_title),
+ -1, NULL, 0);
+
+ if (tlen > 0)
+ {
+ /* Windows truncates the title text beyond what fits on
+ a single line, so we can limit the length to some
+ reasonably large value, and use alloca. */
+ if (tlen > 10000)
+ tlen = 10000;
+ title_w = alloca ((tlen + 1) * sizeof (wchar_t));
+ pMultiByteToWideChar (CP_UTF8, 0, SSDATA (encoded_title), -1,
+ title_w, tlen);
+ title_w[tlen] = L'\0';
+ SetWindowTextW (FRAME_W32_WINDOW (f), title_w);
+ }
+ else /* Conversion to UTF-16 failed, so we punt. */
+ SetWindowTextA (FRAME_W32_WINDOW (f),
+ SSDATA (ENCODE_SYSTEM (name)));
+ }
+ else
+ SetWindowTextA (FRAME_W32_WINDOW (f), SSDATA (ENCODE_SYSTEM (name)));
+#endif
+ unblock_input ();
+ }
+}
/* Change the name of frame F to NAME. If NAME is nil, set F's name to
w32_id_name.
if (! NILP (f->title))
name = f->title;
- if (FRAME_W32_WINDOW (f))
- {
- block_input ();
- GUI_FN (SetWindowText) (FRAME_W32_WINDOW (f),
- GUI_SDATA (GUI_ENCODE_SYSTEM (name)));
- unblock_input ();
- }
+ w32_set_title_bar_text (f, name);
}
/* This function should be called when the user's lisp code has
if (NILP (name))
name = f->name;
- if (FRAME_W32_WINDOW (f))
- {
- block_input ();
- GUI_FN (SetWindowText) (FRAME_W32_WINDOW (f),
- GUI_SDATA (GUI_ENCODE_SYSTEM (name)));
- unblock_input ();
- }
+ w32_set_title_bar_text (f, name);
}
void
}
static void
-w32_createwindow (struct frame *f)
+w32_createwindow (struct frame *f, int *coords)
{
HWND hwnd;
RECT rect;
- Lisp_Object top = Qunbound;
- Lisp_Object left = Qunbound;
- struct w32_display_info *dpyinfo = &one_w32_display_info;
+ int top;
+ int left;
rect.left = rect.top = 0;
rect.right = FRAME_PIXEL_WIDTH (f);
if (f->size_hint_flags & USPosition || f->size_hint_flags & PPosition)
{
- XSETINT (left, f->left_pos);
- XSETINT (top, f->top_pos);
+ left = f->left_pos;
+ top = f->top_pos;
}
- else if (EQ (left, Qunbound) && EQ (top, Qunbound))
+ else
{
- /* When called with RES_TYPE_NUMBER, w32_get_arg will return zero
- for anything that is not a number and is not Qunbound. */
- left = x_get_arg (dpyinfo, Qnil, Qleft, "left", "Left", RES_TYPE_NUMBER);
- top = x_get_arg (dpyinfo, Qnil, Qtop, "top", "Top", RES_TYPE_NUMBER);
+ left = coords[0];
+ top = coords[1];
}
FRAME_W32_WINDOW (f) = hwnd
= CreateWindow (EMACS_CLASS,
f->namebuf,
f->output_data.w32->dwStyle | WS_CLIPCHILDREN,
- EQ (left, Qunbound) ? CW_USEDEFAULT : XINT (left),
- EQ (top, Qunbound) ? CW_USEDEFAULT : XINT (top),
- rect.right - rect.left,
- rect.bottom - rect.top,
+ left, top,
+ rect.right - rect.left, rect.bottom - rect.top,
NULL,
NULL,
hinst,
#define CURRENT_STATE(key) ((GetAsyncKeyState (key) & 0x8000) >> 8)
+ memset (keystate, 0, sizeof (keystate));
GetKeyboardState (keystate);
keystate[VK_SHIFT] = CURRENT_STATE (VK_SHIFT);
keystate[VK_CONTROL] = CURRENT_STATE (VK_CONTROL);
the patch for XP is not publicly available until XP SP3,
and older versions will never be patched. */
CoInitialize (NULL);
- w32_createwindow ((struct frame *) msg.wParam);
+ w32_createwindow ((struct frame *) msg.wParam,
+ (int *) msg.lParam);
if (!PostThreadMessage (dwMainThreadId, WM_EMACS_DONE, 0, 0))
emacs_abort ();
break;
tme.cbSize = sizeof (tme);
tme.dwFlags = TME_LEAVE;
tme.hwndTrack = hwnd;
+ tme.dwHoverTime = HOVER_DEFAULT;
track_mouse_event_fn (&tme);
track_mouse_window = hwnd;
wp.length = sizeof (WINDOWPLACEMENT);
GetWindowPlacement (hwnd, &wp);
- if (wp.showCmd != SW_SHOWMINIMIZED && (lppos->flags & SWP_NOSIZE) == 0)
+ if (wp.showCmd != SW_SHOWMAXIMIZED && wp.showCmd != SW_SHOWMINIMIZED
+ && (lppos->flags & SWP_NOSIZE) == 0)
{
RECT rect;
int wdiff;
my_create_window (struct frame * f)
{
MSG msg;
+ static int coords[2];
+ Lisp_Object left, top;
+ struct w32_display_info *dpyinfo = &one_w32_display_info;
- if (!PostThreadMessage (dwWindowsThreadId, WM_EMACS_CREATEWINDOW, (WPARAM)f, 0))
+ /* When called with RES_TYPE_NUMBER, x_get_arg will return zero for
+ anything that is not a number and is not Qunbound. */
+ left = x_get_arg (dpyinfo, Qnil, Qleft, "left", "Left", RES_TYPE_NUMBER);
+ top = x_get_arg (dpyinfo, Qnil, Qtop, "top", "Top", RES_TYPE_NUMBER);
+ if (EQ (left, Qunbound))
+ coords[0] = CW_USEDEFAULT;
+ else
+ coords[0] = XINT (left);
+ if (EQ (top, Qunbound))
+ coords[1] = CW_USEDEFAULT;
+ else
+ coords[1] = XINT (top);
+
+ if (!PostThreadMessage (dwWindowsThreadId, WM_EMACS_CREATEWINDOW,
+ (WPARAM)f, (LPARAM)coords))
emacs_abort ();
GetMessage (&msg, NULL, WM_EMACS_DONE, WM_EMACS_DONE);
}
{
#ifdef GLYPH_DEBUG
struct w32_display_info *dpyinfo = FRAME_DISPLAY_INFO (f);
+
+ /* If the frame's image cache refcount is still the same as our
+ private shadow variable, it means we are unwinding a frame
+ for which we didn't yet call init_frame_faces, where the
+ refcount is incremented. Therefore, we increment it here, so
+ that free_frame_faces, called in x_free_frame_resources
+ below, will not mistakenly decrement the counter that was not
+ incremented yet to account for this new frame. */
+ if (FRAME_IMAGE_CACHE (f) != NULL
+ && FRAME_IMAGE_CACHE (f)->refcount == image_cache_refcount)
+ FRAME_IMAGE_CACHE (f)->refcount++;
#endif
x_free_frame_resources (f);
eassert (dpyinfo->reference_count == dpyinfo_refcount);
eassert ((dpyinfo->terminal->image_cache == NULL
&& image_cache_refcount == 0)
- || dpyinfo->terminal->image_cache->refcount == image_cache_refcount);
+ || (dpyinfo->terminal->image_cache != NULL
+ && dpyinfo->terminal->image_cache->refcount == image_cache_refcount));
#endif
return Qt;
}
"leftFringe", "LeftFringe", RES_TYPE_NUMBER);
x_default_parameter (f, parameters, Qright_fringe, Qnil,
"rightFringe", "RightFringe", RES_TYPE_NUMBER);
+ /* Process alpha here (Bug#16619). */
+ x_default_parameter (f, parameters, Qalpha, Qnil,
+ "alpha", "Alpha", RES_TYPE_NUMBER);
/* Init faces before x_default_parameter is called for scroll-bar
parameters because that function calls x_set_scroll_bar_width,
"cursorType", "CursorType", RES_TYPE_SYMBOL);
x_default_parameter (f, parameters, Qscroll_bar_width, Qnil,
"scrollBarWidth", "ScrollBarWidth", RES_TYPE_NUMBER);
- x_default_parameter (f, parameters, Qalpha, Qnil,
- "alpha", "Alpha", RES_TYPE_NUMBER);
/* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
Change will not be effected unless different from the current
}
DEFUN ("x-server-vendor", Fx_server_vendor, Sx_server_vendor, 0, 1, 0,
- doc: /* Return the "vendor ID" string of the W32 system (Microsoft).
-The optional argument DISPLAY specifies which display to ask about.
-DISPLAY should be either a frame or a display name (a string).
+ doc: /* Return the "vendor ID" string of the GUI software on TERMINAL.
+
+\(Labeling every distributor as a "vendor" embodies the false assumption
+that operating systems cannot be developed and distributed noncommercially.)
+
+For GNU and Unix systems, this queries the X server software; for
+MS-Windows, this queries the OS.
+
+The optional argument TERMINAL specifies which display to ask about.
+TERMINAL should be a terminal object, a frame or a display name (a string).
If omitted or nil, that stands for the selected frame's display. */)
- (Lisp_Object display)
+ (Lisp_Object terminal)
{
return build_string ("Microsoft Corp.");
}
DEFUN ("x-server-version", Fx_server_version, Sx_server_version, 0, 1, 0,
- doc: /* Return the version numbers of the server of DISPLAY.
-The value is a list of three integers: the major and minor
-version numbers of the X Protocol in use, and the distributor-specific
-release number. See also the function `x-server-vendor'.
+ doc: /* Return the version numbers of the GUI software on TERMINAL.
+The value is a list of three integers specifying the version of the GUI
+software in use.
-The optional argument DISPLAY specifies which display to ask about.
-DISPLAY should be either a frame or a display name (a string).
+For GNU and Unix system, the first 2 numbers are the version of the X
+Protocol used on TERMINAL and the 3rd number is the distributor-specific
+release number. For MS-Windows, the 3 numbers report the version and
+the build number of the OS.
+
+See also the function `x-server-vendor'.
+
+The optional argument TERMINAL specifies which display to ask about.
+TERMINAL should be a terminal object, a frame or a display name (a string).
If omitted or nil, that stands for the selected frame's display. */)
- (Lisp_Object display)
+ (Lisp_Object terminal)
{
return list3i (w32_major_version, w32_minor_version, w32_build_number);
}
/* Put tooltip in topmost group and in position. */
SetWindowPos (FRAME_W32_WINDOW (f), HWND_TOPMOST,
root_x, root_y, 0, 0,
- SWP_NOSIZE | SWP_NOACTIVATE);
+ SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOOWNERZORDER);
/* Ensure tooltip is on top of other topmost windows (eg menus). */
SetWindowPos (FRAME_W32_WINDOW (f), HWND_TOP,
0, 0, 0, 0,
- SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
+ SWP_NOMOVE | SWP_NOSIZE
+ | SWP_NOACTIVATE | SWP_NOOWNERZORDER);
unblock_input ();
goto start_timer;
SetWindowPos (FRAME_W32_WINDOW (f), HWND_TOPMOST,
root_x, root_y,
rect.right - rect.left + FRAME_COLUMN_WIDTH (f),
- rect.bottom - rect.top, SWP_NOACTIVATE);
+ rect.bottom - rect.top, SWP_NOACTIVATE | SWP_NOOWNERZORDER);
/* Ensure tooltip is on top of other topmost windows (eg menus). */
SetWindowPos (FRAME_W32_WINDOW (f), HWND_TOP,
0, 0, 0, 0,
- SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
+ SWP_NOMOVE | SWP_NOSIZE
+ | SWP_NOACTIVATE | SWP_NOOWNERZORDER);
/* Let redisplay know that we have made the frame visible already. */
SET_FRAME_VISIBLE (f, 1);
This function is only defined on NS, MS Windows, and X Windows with the
Motif or Gtk toolkits. With the Motif toolkit, ONLY-DIR-P is ignored.
-Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories. */)
+Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories.
+On Windows 7 and later, the file selection dialog "remembers" the last
+directory where the user selected a file, and will open that directory
+instead of DIR on subsequent invocations of this function with the same
+value of DIR as in previous invocations; this is standard Windows behavior. */)
(Lisp_Object prompt, Lisp_Object dir, Lisp_Object default_filename, Lisp_Object mustmatch, Lisp_Object only_dir_p)
{
/* Filter index: 1: All Files, 2: Directories only */
if (errno == ENOENT && filename_buf_w[MAX_PATH - 1] != 0)
report_file_error ("filename too long", default_filename);
}
- len = MultiByteToWideChar (CP_UTF8, MB_ERR_INVALID_CHARS,
- SSDATA (prompt), -1, NULL, 0);
+ len = pMultiByteToWideChar (CP_UTF8, MB_ERR_INVALID_CHARS,
+ SSDATA (prompt), -1, NULL, 0);
if (len > 32768)
len = 32768;
prompt_w = alloca (len * sizeof (wchar_t));
- MultiByteToWideChar (CP_UTF8, MB_ERR_INVALID_CHARS,
- SSDATA (prompt), -1, prompt_w, len);
+ pMultiByteToWideChar (CP_UTF8, MB_ERR_INVALID_CHARS,
+ SSDATA (prompt), -1, prompt_w, len);
}
else
{
if (errno == ENOENT && filename_buf_a[MAX_PATH - 1] != 0)
report_file_error ("filename too long", default_filename);
}
- len = MultiByteToWideChar (CP_UTF8, MB_ERR_INVALID_CHARS,
- SSDATA (prompt), -1, NULL, 0);
+ len = pMultiByteToWideChar (CP_UTF8, MB_ERR_INVALID_CHARS,
+ SSDATA (prompt), -1, NULL, 0);
if (len > 32768)
len = 32768;
prompt_w = alloca (len * sizeof (wchar_t));
- MultiByteToWideChar (CP_UTF8, MB_ERR_INVALID_CHARS,
- SSDATA (prompt), -1, prompt_w, len);
- len = WideCharToMultiByte (CP_ACP, 0, prompt_w, -1, NULL, 0, NULL, NULL);
+ pMultiByteToWideChar (CP_UTF8, MB_ERR_INVALID_CHARS,
+ SSDATA (prompt), -1, prompt_w, len);
+ len = pWideCharToMultiByte (CP_ACP, 0, prompt_w, -1, NULL, 0, NULL, NULL);
if (len > 32768)
len = 32768;
prompt_a = alloca (len);
- WideCharToMultiByte (CP_ACP, 0, prompt_w, -1, prompt_a, len, NULL, NULL);
+ pWideCharToMultiByte (CP_ACP, 0, prompt_w, -1, prompt_a, len, NULL, NULL);
}
#endif /* NTGUI_UNICODE */
operations:
\"open\" - open DOCUMENT, which could be a file, a directory, or an
- executable program. If it is an application, that
- application is launched in the current buffer's default
+ executable program (application). If it is an application,
+ that application is launched in the current buffer's default
directory. Otherwise, the application associated with
DOCUMENT is launched in the buffer's default directory.
- \"print\" - print DOCUMENT, which must be a file
- \"explore\" - start the Windows Explorer on DOCUMENT
+ \"opennew\" - like \"open\", but instruct the application to open
+ DOCUMENT in a new window.
+ \"openas\" - open the \"Open With\" dialog for DOCUMENT.
+ \"print\" - print DOCUMENT, which must be a file.
+ \"printto\" - print DOCUMENT, which must be a file, to a specified printer.
+ The printer should be provided in PARAMETERS, see below.
+ \"explore\" - start the Windows Explorer on DOCUMENT.
\"edit\" - launch an editor and open DOCUMENT for editing; which
editor is launched depends on the association for the
- specified DOCUMENT
- \"find\" - initiate search starting from DOCUMENT which must specify
- a directory
+ specified DOCUMENT.
+ \"find\" - initiate search starting from DOCUMENT, which must specify
+ a directory.
\"runas\" - run DOCUMENT, which must be an excutable file, with
elevated privileges (a.k.a. \"as Administrator\").
+ \"properties\"
+ - open the the property sheet dialog for DOCUMENT; works
+ for *.lnk desktop shortcuts, and little or nothing else.
nil - invoke the default OPERATION, or \"open\" if default is
- not defined or unavailable
+ not defined or unavailable.
DOCUMENT is typically the name of a document file or a URL, but can
-also be a program executable to run, or a directory to open in the
+also be an executable program to run, or a directory to open in the
Windows Explorer. If it is a file, it must be a local one; this
function does not support remote file names.
-If DOCUMENT is a program executable, the optional third arg PARAMETERS
+If DOCUMENT is an executable program, the optional third arg PARAMETERS
can be a string containing command line parameters that will be passed
-to the program; otherwise, PARAMETERS should be nil or unspecified.
+to the program. Some values of OPERATION also require parameters (e.g.,
+\"printto\" requires the printer address). Otherwise, PARAMETERS should
+be nil or unspecified.
Optional fourth argument SHOW-FLAG can be used to control how the
application will be displayed when it is invoked. If SHOW-FLAG is nil
-or unspecified, the application is displayed normally, otherwise it is
-an integer representing a ShowWindow flag:
+or unspecified, the application is displayed as if SHOW-FLAG of 10 was
+specified, otherwise it is an integer between 0 and 11 representing
+a ShowWindow flag:
0 - start hidden
- 1 - start normally
- 3 - start maximized
- 6 - start minimized */)
+ 1 - start as normal-size window
+ 3 - start in a maximized window
+ 6 - start in a minimized window
+ 10 - start as the application itself specifies; this is the default. */)
(Lisp_Object operation, Lisp_Object document, Lisp_Object parameters, Lisp_Object show_flag)
{
char *errstr;
#else /* !CYGWIN */
current_dir = ENCODE_FILE (current_dir);
/* We have a situation here. If DOCUMENT is a relative file name,
- and is not in CURRENT_DIR, ShellExecute below will fail to find
- it. So we need to make the file name absolute. But DOCUMENT
- does not have to be a file, it can be a URL, for example. So we
- make it absolute only if it is an existing file; if it is a file
- that does not exist, tough. */
+ but its name includes leading directories, i.e. it lives not in
+ CURRENT_DIR, but in its subdirectory, then ShellExecute below
+ will fail to find it. So we need to make the file name is
+ absolute. But DOCUMENT does not have to be a file, it can be a
+ URL, for example. So we make it absolute only if it is an
+ existing file; if it is a file that does not exist, tough. */
GCPRO1 (absdoc);
absdoc = Fexpand_file_name (document, Qnil);
/* Don't call file handlers for file-exists-p, since they might
Lisp_Object absdoc_encoded = ENCODE_FILE (absdoc);
if (faccessat (AT_FDCWD, SSDATA (absdoc_encoded), F_OK, AT_EACCESS) == 0)
- document = absdoc_encoded;
+ {
+ /* ShellExecute fails if DOCUMENT is a UNC with forward
+ slashes (expand-file-name above converts all backslashes
+ to forward slashes). Now that we know DOCUMENT is a
+ file, we can mirror all forward slashes into backslashes. */
+ unixtodos_filename (SSDATA (absdoc_encoded));
+ document = absdoc_encoded;
+ }
else
document = ENCODE_FILE (document);
}
int len;
parameters = ENCODE_SYSTEM (parameters);
- len = MultiByteToWideChar (CP_ACP, MB_ERR_INVALID_CHARS,
- SSDATA (parameters), -1, NULL, 0);
+ len = pMultiByteToWideChar (CP_ACP, MB_ERR_INVALID_CHARS,
+ SSDATA (parameters), -1, NULL, 0);
if (len > 32768)
len = 32768;
params_w = alloca (len * sizeof (wchar_t));
- MultiByteToWideChar (CP_ACP, MB_ERR_INVALID_CHARS,
- SSDATA (parameters), -1, params_w, len);
+ pMultiByteToWideChar (CP_ACP, MB_ERR_INVALID_CHARS,
+ SSDATA (parameters), -1, params_w, len);
}
if (STRINGP (operation))
{
added rather late on. */
{
HMODULE hKernel = GetModuleHandle ("kernel32");
- BOOL (*pfn_GetDiskFreeSpaceExW)
+ BOOL (WINAPI *pfn_GetDiskFreeSpaceExW)
(wchar_t *, PULARGE_INTEGER, PULARGE_INTEGER, PULARGE_INTEGER)
- = (void *) GetProcAddress (hKernel, "GetDiskFreeSpaceExW");
- BOOL (*pfn_GetDiskFreeSpaceExA)
+ = GetProcAddress (hKernel, "GetDiskFreeSpaceExW");
+ BOOL (WINAPI *pfn_GetDiskFreeSpaceExA)
(char *, PULARGE_INTEGER, PULARGE_INTEGER, PULARGE_INTEGER)
- = (void *) GetProcAddress (hKernel, "GetDiskFreeSpaceExA");
+ = GetProcAddress (hKernel, "GetDiskFreeSpaceExA");
bool have_pfn_GetDiskFreeSpaceEx =
(w32_unicode_filenames && pfn_GetDiskFreeSpaceExW
|| !w32_unicode_filenames && pfn_GetDiskFreeSpaceExA);