aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2009-09-09 15:19:40 +0000
committermarha <marha@users.sourceforge.net>2009-09-09 15:19:40 +0000
commite978fab10babba27885fe6b8a3f8dd72fecbc792 (patch)
tree755b19ad0256af3b44bf79c021c132288a396529
parentce016335ab8ff2413bb82de6f74b2b96f746d07b (diff)
downloadvcxsrv-e978fab10babba27885fe6b8a3f8dd72fecbc792.tar.gz
vcxsrv-e978fab10babba27885fe6b8a3f8dd72fecbc792.tar.bz2
vcxsrv-e978fab10babba27885fe6b8a3f8dd72fecbc792.zip
Synchronised with released branch.
-rw-r--r--xorg-server/hw/xwin/XWin.exe.manifest16
-rw-r--r--xorg-server/hw/xwin/XWin.rc206
-rw-r--r--xorg-server/hw/xwin/win.h2
-rw-r--r--xorg-server/hw/xwin/winclipboardwndproc.c1166
-rw-r--r--xorg-server/hw/xwin/winclipboardxevents.c1666
-rw-r--r--xorg-server/hw/xwin/windialogs.c15
-rw-r--r--xorg-server/hw/xwin/winkeybd.c2
-rw-r--r--xorg-server/hw/xwin/winmouse.c2
-rw-r--r--xorg-server/hw/xwin/winmultiwindowclass.c2
-rw-r--r--xorg-server/hw/xwin/winmultiwindowwm.c2
-rw-r--r--xorg-server/hw/xwin/winprefsyacc.c4
-rw-r--r--xorg-server/hw/xwin/winresource.h1
-rw-r--r--xorg-server/hw/xwin/winwin32rootless.c1
-rw-r--r--xorg-server/hw/xwin/winwin32rootlesswndproc.c27
-rw-r--r--xorg-server/hw/xwin/winwndproc.c16
15 files changed, 1561 insertions, 1567 deletions
diff --git a/xorg-server/hw/xwin/XWin.exe.manifest b/xorg-server/hw/xwin/XWin.exe.manifest
deleted file mode 100644
index 221150d52..000000000
--- a/xorg-server/hw/xwin/XWin.exe.manifest
+++ /dev/null
@@ -1,16 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
-<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
- <description>The XWin X Windows server for Cygwin.</description>
- <dependency>
- <dependentAssembly>
- <assemblyIdentity
- type="win32"
- name="Microsoft.Windows.Common-Controls"
- version="6.0.0.0"
- processorArchitecture="X86"
- publicKeyToken="6595b64144ccf1df"
- language="*"
- />
- </dependentAssembly>
- </dependency>
-</assembly>
diff --git a/xorg-server/hw/xwin/XWin.rc b/xorg-server/hw/xwin/XWin.rc
index 2e399634d..863792127 100644
--- a/xorg-server/hw/xwin/XWin.rc
+++ b/xorg-server/hw/xwin/XWin.rc
@@ -1,103 +1,103 @@
-/*
- *Copyright (C) 2002-2004 Harold L Hunt II All Rights Reserved.
- *Copyright (C) 2008 Yaakov Selkowitz All Rights Reserved
- *
- *Permission is hereby granted, free of charge, to any person obtaining
- * a copy of this software and associated documentation files (the
- *"Software"), to deal in the Software without restriction, including
- *without limitation the rights to use, copy, modify, merge, publish,
- *distribute, sublicense, and/or sell copies of the Software, and to
- *permit persons to whom the Software is furnished to do so, subject to
- *the following conditions:
- *
- *The above copyright notice and this permission notice shall be
- *included in all copies or substantial portions of the Software.
- *
- *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II BE LIABLE FOR
- *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
- *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- *Except as contained in this notice, the names of the authors
- *shall not be used in advertising or otherwise to promote the sale, use
- *or other dealings in this Software without prior written authorization
- *from the authors.
- *
- * Authors: Harold L Hunt II, Yaakov Selkowitz
- */
-
-#include <windows.h>
-#include "winresource.h"
-#include "xwin-config.h"
-
-/*
- * Dialogs
- */
-
-/* About */
-ABOUT_BOX DIALOGEX 32, 32, 260, 95
-STYLE WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_VISIBLE | WS_TABSTOP | DS_CENTERMOUSE
-CAPTION "About VcXsrv"
-FONT 8, "MS Shell Dlg 2"
-BEGIN
- CONTROL IDI_XWIN, IDC_STATIC, "Static", SS_ICON, 8, 8, 32, 32
- LTEXT "VcXsrv X Server ", IDC_STATIC, 36, 8, 220, 8
- LTEXT "Version 1.0.2 (6 Aug 2009)", IDC_STATIC, 36, 18, 220, 8
- DEFPUSHBUTTON "OK", IDOK, 105, 75, 50, 15
-END
-
-
-/* Depth change */
-
-DEPTH_CHANGE_BOX DIALOGEX 32, 32, 180, 100
-STYLE WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_VISIBLE | DS_CENTERMOUSE
-FONT 8, "MS Shell Dlg 2"
-CAPTION "VcXsrv"
-BEGIN
- DEFPUSHBUTTON "Dismiss", IDOK, 66, 80, 50, 14
- CTEXT "VcXsrv", IDC_STATIC, 40, 12, 100, 8
- CTEXT "Disruptive screen configuration change.", IDC_STATIC, 7, 40, 166, 8
- CTEXT "Restore previous resolution to use VcXsrv.", IDC_STATIC, 7, 52, 166, 8
-END
-
-
-/* Exit */
-
-EXIT_DIALOG DIALOGEX 32, 32, 180, 78
-STYLE WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_VISIBLE | WS_TABSTOP | DS_CENTERMOUSE
-FONT 8, "MS Shell Dlg 2"
-CAPTION "Exit VcXsrv?"
-BEGIN
- PUSHBUTTON "E&xit", IDOK, 55, 56, 30, 14
- DEFPUSHBUTTON "&Cancel", IDCANCEL, 95, 56, 30, 14
- CTEXT "E&xiting will close all screens running on this display.", IDC_STATIC, 7, 12, 166, 8
- CTEXT "No information about connected clients available.", IDC_CLIENTS_CONNECTED, 7, 24, 166, 8
- CTEXT "Proceed with shutdown of this display/server?", IDC_STATIC, 7, 36, 166, 8
-END
-
-
-/*
- * Menus
- */
-
-IDM_TRAYICON_MENU MENU
-BEGIN
- POPUP "TRAYICON_MENU"
- BEGIN
- MENUITEM "&Hide Root Window", ID_APP_HIDE_ROOT
- MENUITEM "&About...", ID_APP_ABOUT
- MENUITEM SEPARATOR
- MENUITEM "E&xit...", ID_APP_EXIT
- END
-END
-
-
-/*
- * Icons
- */
-
-IDI_XWIN ICON "X.ico"
-CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "XWin.exe.manifest"
+/*
+ *Copyright (C) 2002-2004 Harold L Hunt II All Rights Reserved.
+ *Copyright (C) 2008 Yaakov Selkowitz All Rights Reserved
+ *
+ *Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ *"Software"), to deal in the Software without restriction, including
+ *without limitation the rights to use, copy, modify, merge, publish,
+ *distribute, sublicense, and/or sell copies of the Software, and to
+ *permit persons to whom the Software is furnished to do so, subject to
+ *the following conditions:
+ *
+ *The above copyright notice and this permission notice shall be
+ *included in all copies or substantial portions of the Software.
+ *
+ *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II BE LIABLE FOR
+ *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+ *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ *Except as contained in this notice, the names of the authors
+ *shall not be used in advertising or otherwise to promote the sale, use
+ *or other dealings in this Software without prior written authorization
+ *from the authors.
+ *
+ * Authors: Harold L Hunt II, Yaakov Selkowitz
+ */
+
+#include <windows.h>
+#include "winresource.h"
+#include "xwin-config.h"
+
+/*
+ * Dialogs
+ */
+
+/* About */
+ABOUT_BOX DIALOGEX DISCARDABLE 32, 32, 260, 95
+STYLE WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_VISIBLE | WS_TABSTOP | DS_CENTERMOUSE
+CAPTION "About VcXsrv"
+FONT 8, "MS Shell Dlg 2"
+BEGIN
+ CONTROL IDI_XWIN, IDC_STATIC, "Static", SS_ICON, 8, 8, 32, 32
+ LTEXT "VcXsrv X Server ", IDC_STATIC, 36, 8, 220, 8
+ LTEXT "Version 1.0.3 (31 Aug 2009)", IDC_STATIC, 36, 18, 220, 8
+ DEFPUSHBUTTON "OK", IDOK, 105, 75, 50, 15
+END
+
+
+/* Depth change */
+
+DEPTH_CHANGE_BOX DIALOGEX DISCARDABLE 32, 32, 180, 100
+STYLE WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_VISIBLE | DS_CENTERMOUSE
+FONT 8, "MS Shell Dlg 2"
+CAPTION "VcXsrv"
+BEGIN
+ DEFPUSHBUTTON "Dismiss", IDOK, 66, 80, 50, 14
+ CTEXT "VcXsrv", IDC_STATIC, 40, 12, 100, 8
+ CTEXT "Disruptive screen configuration change.", IDC_STATIC, 7, 40, 166, 8
+ CTEXT "Restore previous resolution to use VcXsrv.", IDC_STATIC, 7, 52, 166, 8
+END
+
+
+/* Exit */
+
+EXIT_DIALOG DIALOGEX DISCARDABLE 32, 32, 180, 78
+STYLE WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_VISIBLE | WS_TABSTOP | DS_CENTERMOUSE
+FONT 8, "MS Shell Dlg 2"
+CAPTION "Exit VcXsrv?"
+BEGIN
+ PUSHBUTTON "E&xit", IDOK, 55, 56, 30, 14
+ DEFPUSHBUTTON "&Cancel", IDCANCEL, 95, 56, 30, 14
+ CTEXT "E&xiting will close all screens running on this display.", IDC_STATIC, 7, 12, 166, 8
+ CTEXT "No information about connected clients available.", IDC_CLIENTS_CONNECTED, 7, 24, 166, 8
+ CTEXT "Proceed with shutdown of this display/server?", IDC_STATIC, 7, 36, 166, 8
+END
+
+
+/*
+ * Menus
+ */
+
+IDM_TRAYICON_MENU MENU DISCARDABLE
+BEGIN
+ POPUP "TRAYICON_MENU"
+ BEGIN
+ MENUITEM "&Hide Root Window", ID_APP_HIDE_ROOT
+ MENUITEM "&About...", ID_APP_ABOUT
+ MENUITEM SEPARATOR
+ MENUITEM "E&xit...", ID_APP_EXIT
+ END
+END
+
+
+/*
+ * Icons
+ */
+
+IDI_XWIN ICON DISCARDABLE "X.ico"
+IDI_XWIN_BOXED ICON DISCARDABLE "X-boxed.ico"
diff --git a/xorg-server/hw/xwin/win.h b/xorg-server/hw/xwin/win.h
index bd36768ca..31f0fd3b2 100644
--- a/xorg-server/hw/xwin/win.h
+++ b/xorg-server/hw/xwin/win.h
@@ -1018,7 +1018,7 @@ winMouseButtonsSendEvent (int iEventType, int iButton);
int
winMouseButtonsHandle (ScreenPtr pScreen,
- int iEventType, int iButton,
+ int iEventType, int iButton,
WPARAM wParam);
void
diff --git a/xorg-server/hw/xwin/winclipboardwndproc.c b/xorg-server/hw/xwin/winclipboardwndproc.c
index ad8e7d0a4..40c1e9a5c 100644
--- a/xorg-server/hw/xwin/winclipboardwndproc.c
+++ b/xorg-server/hw/xwin/winclipboardwndproc.c
@@ -1,583 +1,583 @@
-/*
- *Copyright (C) 2003-2004 Harold L Hunt II All Rights Reserved.
- *Copyright (C) Colin Harrison 2005-2008
- *
- *Permission is hereby granted, free of charge, to any person obtaining
- * a copy of this software and associated documentation files (the
- *"Software"), to deal in the Software without restriction, including
- *without limitation the rights to use, copy, modify, merge, publish,
- *distribute, sublicense, and/or sell copies of the Software, and to
- *permit persons to whom the Software is furnished to do so, subject to
- *the following conditions:
- *
- *The above copyright notice and this permission notice shall be
- *included in all copies or substantial portions of the Software.
- *
- *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II BE LIABLE FOR
- *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
- *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- *Except as contained in this notice, the name of the copyright holder(s)
- *and author(s) shall not be used in advertising or otherwise to promote
- *the sale, use or other dealings in this Software without prior written
- *authorization from the copyright holder(s) and author(s).
- *
- * Authors: Harold L Hunt II
- * Colin Harrison
- */
-
-#ifdef HAVE_XWIN_CONFIG_H
-#include <xwin-config.h>
-#endif
-#include <sys/types.h>
-#include <sys/time.h>
-#include "winclipboard.h"
-#include "misc.h"
-
-/*
- * Constants
- */
-
-#define WIN_CLIPBOARD_PROP "cyg_clipboard_prop"
-#define WIN_POLL_TIMEOUT 1
-
-
-/*
- * References to external symbols
- */
-
-extern Bool g_fUseUnicode;
-extern Bool g_fUnicodeSupport;
-extern void *g_pClipboardDisplay;
-extern Window g_iClipboardWindow;
-extern Atom g_atomLastOwnedSelection;
-
-/* BPS - g_hwndClipboard needed for X app->Windows paste fix */
-extern HWND g_hwndClipboard;
-
-/*
- * Local function prototypes
- */
-
-static int
-winProcessXEventsTimeout (HWND hwnd, int iWindow, Display *pDisplay,
- Bool fUseUnicode, int iTimeoutSec);
-
-
-/*
- * Process X events up to specified timeout
- */
-
-static int
-winProcessXEventsTimeout (HWND hwnd, int iWindow, Display *pDisplay,
- Bool fUseUnicode, int iTimeoutSec)
-{
- int iConnNumber;
- struct timeval tv;
- int iReturn;
- DWORD dwStopTime = (GetTickCount () / 1000) + iTimeoutSec;
-
- /* We need to ensure that all pending events are processed */
- XSync (pDisplay, FALSE);
-
- /* Get our connection number */
- iConnNumber = ConnectionNumber (pDisplay);
-
- /* Loop for X events */
- while (1)
- {
- fd_set fdsRead;
-
- /* Setup the file descriptor set */
- FD_ZERO (&fdsRead);
- FD_SET (iConnNumber, &fdsRead);
-
- /* Adjust timeout */
- tv.tv_sec = dwStopTime - (GetTickCount () / 1000);
- tv.tv_usec = 0;
-
- /* Break out if no time left */
- if (tv.tv_sec < 0)
- return WIN_XEVENTS_SUCCESS;
-
- /* Wait for a Windows event or an X event */
- iReturn = select (iConnNumber + 1,/* Highest fds number */
- &fdsRead, /* Read mask */
- NULL, /* No write mask */
- NULL, /* No exception mask */
- &tv); /* No timeout */
- if (iReturn <= 0)
- {
- ErrorF ("winProcessXEventsTimeout - Call to select () failed: %d. "
- "Bailing.\n", iReturn);
- break;
- }
-
- /* Branch on which descriptor became active */
- if (FD_ISSET (iConnNumber, &fdsRead))
- {
- /* Process X events */
- /* Exit when we see that server is shutting down */
- iReturn = winClipboardFlushXEvents (hwnd,
- iWindow,
- pDisplay,
- fUseUnicode);
- if (WIN_XEVENTS_NOTIFY == iReturn
- || WIN_XEVENTS_CONVERT == iReturn)
- {
- /* Bail out if convert or notify processed */
- return iReturn;
- }
- }
- }
-
- return WIN_XEVENTS_SUCCESS;
-}
-
-
-/*
- * Process a given Windows message
- */
-
-LRESULT CALLBACK
-winClipboardWindowProc (HWND hwnd, UINT message,
- WPARAM wParam, LPARAM lParam)
-{
- static HWND s_hwndNextViewer;
- static Bool s_fCBCInitialized;
-
- /* Branch on message type */
- switch (message)
- {
- case WM_DESTROY:
- {
- winDebug ("winClipboardWindowProc - WM_DESTROY\n");
-
- /* Remove ourselves from the clipboard chain */
- ChangeClipboardChain (hwnd, s_hwndNextViewer);
-
- s_hwndNextViewer = NULL;
-
- PostQuitMessage (0);
- }
- return 0;
-
-
- case WM_CREATE:
- {
- HWND first, next;
- DWORD error_code = 0;
- winDebug ("winClipboardWindowProc - WM_CREATE\n");
-
- first = GetClipboardViewer(); /* Get handle to first viewer in chain. */
- if (first == hwnd) return 0; /* Make sure it's not us! */
- /* Add ourselves to the clipboard viewer chain */
- next = SetClipboardViewer (hwnd);
- error_code = GetLastError();
- if (SUCCEEDED(error_code) && (next == first)) /* SetClipboardViewer must have succeeded, and the handle */
- s_hwndNextViewer = next; /* it returned must have been the first window in the chain */
- else
- s_fCBCInitialized = FALSE;
- }
- return 0;
-
-
- case WM_CHANGECBCHAIN:
- {
- winDebug ("winClipboardWindowProc - WM_CHANGECBCHAIN: wParam(%x) "
- "lParam(%x) s_hwndNextViewer(%x)\n",
- wParam, lParam, s_hwndNextViewer);
-
- if ((HWND) wParam == s_hwndNextViewer)
- {
- s_hwndNextViewer = (HWND) lParam;
- if (s_hwndNextViewer == hwnd)
- {
- s_hwndNextViewer = NULL;
- winErrorFVerb (1, "winClipboardWindowProc - WM_CHANGECBCHAIN: "
- "attempted to set next window to ourselves.");
- }
- }
- else if (s_hwndNextViewer)
- SendMessage (s_hwndNextViewer, message,
- wParam, lParam);
-
- }
- winDebug ("winClipboardWindowProc - WM_CHANGECBCHAIN: Exit\n");
- return 0;
-
- case WM_WM_REINIT:
- {
- /* Ensure that we're in the clipboard chain. Some apps,
- * WinXP's remote desktop for one, don't play nice with the
- * chain. This message is called whenever we receive a
- * WM_ACTIVATEAPP message to ensure that we continue to
- * receive clipboard messages.
- *
- * It might be possible to detect if we're still in the chain
- * by calling SendMessage (GetClipboardViewer(),
- * WM_DRAWCLIPBOARD, 0, 0); and then seeing if we get the
- * WM_DRAWCLIPBOARD message. That, however, might be more
- * expensive than just putting ourselves back into the chain.
- */
-
- HWND first, next;
- DWORD error_code = 0;
- winDebug ("winClipboardWindowProc - WM_WM_REINIT: Enter\n");
-
- first = GetClipboardViewer(); /* Get handle to first viewer in chain. */
- if (first == hwnd) return 0; /* Make sure it's not us! */
- winDebug (" WM_WM_REINIT: Replacing us(%x) with %x at head "
- "of chain\n", hwnd, s_hwndNextViewer);
- s_fCBCInitialized = FALSE;
- ChangeClipboardChain (hwnd, s_hwndNextViewer);
- s_hwndNextViewer = NULL;
- s_fCBCInitialized = FALSE;
- winDebug (" WM_WM_REINIT: Putting us back at head of chain.\n");
- first = GetClipboardViewer(); /* Get handle to first viewer in chain. */
- if (first == hwnd) return 0; /* Make sure it's not us! */
- next = SetClipboardViewer (hwnd);
- error_code = GetLastError();
- if (SUCCEEDED(error_code) && (next == first)) /* SetClipboardViewer must have succeeded, and the handle */
- s_hwndNextViewer = next; /* it returned must have been the first window in the chain */
- else
- s_fCBCInitialized = FALSE;
- }
- winDebug ("winClipboardWindowProc - WM_WM_REINIT: Exit\n");
- return 0;
-
-
- case WM_DRAWCLIPBOARD:
- {
- static Atom atomClipboard;
- static int generation;
- static Bool s_fProcessingDrawClipboard = FALSE;
- Display *pDisplay = g_pClipboardDisplay;
- Window iWindow = g_iClipboardWindow;
- int iReturn;
-
- winDebug ("winClipboardWindowProc - WM_DRAWCLIPBOARD: Enter\n");
-
- if (generation != serverGeneration)
- {
- generation = serverGeneration;
- atomClipboard = XInternAtom (pDisplay, "CLIPBOARD", False);
- }
-
- /*
- * We've occasionally seen a loop in the clipboard chain.
- * Try and fix it on the first hint of recursion.
- */
- if (! s_fProcessingDrawClipboard)
- {
- s_fProcessingDrawClipboard = TRUE;
- }
- else
- {
- /* Attempt to break the nesting by getting out of the chain, twice?, and then fix and bail */
- s_fCBCInitialized = FALSE;
- ChangeClipboardChain (hwnd, s_hwndNextViewer);
- winFixClipboardChain();
- winErrorFVerb (1, "winClipboardWindowProc - WM_DRAWCLIPBOARD - "
- "Nested calls detected. Re-initing.\n");
- winDebug ("winClipboardWindowProc - WM_DRAWCLIPBOARD: Exit\n");
- s_fProcessingDrawClipboard = FALSE;
- return 0;
- }
-
- /* Bail on first message */
- if (!s_fCBCInitialized)
- {
- s_fCBCInitialized = TRUE;
- s_fProcessingDrawClipboard = FALSE;
- winDebug ("winClipboardWindowProc - WM_DRAWCLIPBOARD: Exit\n");
- return 0;
- }
-
- /*
- * NOTE: We cannot bail out when NULL == GetClipboardOwner ()
- * because some applications deal with the clipboard in a manner
- * that causes the clipboard owner to be NULL when they are in
- * fact taking ownership. One example of this is the Win32
- * native compile of emacs.
- */
-
- /* Bail when we still own the clipboard */
- if (hwnd == GetClipboardOwner ())
- {
-
- winDebug ("winClipboardWindowProc - WM_DRAWCLIPBOARD - "
- "We own the clipboard, returning.\n");
- winDebug ("winClipboardWindowProc - WM_DRAWCLIPBOARD: Exit\n");
- s_fProcessingDrawClipboard = FALSE;
- if (s_hwndNextViewer)
- SendMessage (s_hwndNextViewer, message, wParam, lParam);
- return 0;
- }
-
- /*
- * Do not take ownership of the X11 selections when something
- * other than CF_TEXT or CF_UNICODETEXT has been copied
- * into the Win32 clipboard.
- */
- if (!IsClipboardFormatAvailable (CF_TEXT)
- && !IsClipboardFormatAvailable (CF_UNICODETEXT))
- {
-
- winDebug ("winClipboardWindowProc - WM_DRAWCLIPBOARD - "
- "Clipboard does not contain CF_TEXT nor "
- "CF_UNICODETEXT.\n");
-
- /*
- * We need to make sure that the X Server has processed
- * previous XSetSelectionOwner messages.
- */
- XSync (pDisplay, FALSE);
-
- /* Release PRIMARY selection if owned */
- iReturn = XGetSelectionOwner (pDisplay, XA_PRIMARY);
- if (iReturn == g_iClipboardWindow)
- {
- winDebug ("winClipboardWindowProc - WM_DRAWCLIPBOARD - "
- "PRIMARY selection is owned by us.\n");
- XSetSelectionOwner (pDisplay,
- XA_PRIMARY,
- None,
- CurrentTime);
- }
- else if (BadWindow == iReturn || BadAtom == iReturn)
- winErrorFVerb (1, "winClipboardWindowProc - WM_DRAWCLIPBOARD - "
- "XGetSelection failed for PRIMARY: %d\n", iReturn);
-
- /* Release CLIPBOARD selection if owned */
- iReturn = XGetSelectionOwner (pDisplay,
- atomClipboard);
- if (iReturn == g_iClipboardWindow)
- {
- winDebug ("winClipboardWindowProc - WM_DRAWCLIPBOARD - "
- "CLIPBOARD selection is owned by us.\n");
- XSetSelectionOwner (pDisplay,
- atomClipboard,
- None,
- CurrentTime);
- }
- else if (BadWindow == iReturn || BadAtom == iReturn)
- winErrorFVerb (1, "winClipboardWindowProc - WM_DRAWCLIPBOARD - "
- "XGetSelection failed for CLIPBOARD: %d\n", iReturn);
-
- winDebug ("winClipboardWindowProc - WM_DRAWCLIPBOARD: Exit\n");
- s_fProcessingDrawClipboard = FALSE;
- if (s_hwndNextViewer)
- SendMessage (s_hwndNextViewer, message, wParam, lParam);
- return 0;
- }
-
- /* Reassert ownership of PRIMARY */
- iReturn = XSetSelectionOwner (pDisplay,
- XA_PRIMARY,
- iWindow,
- CurrentTime);
- if (iReturn == BadAtom || iReturn == BadWindow ||
- XGetSelectionOwner (pDisplay, XA_PRIMARY) != iWindow)
- {
- winErrorFVerb (1, "winClipboardWindowProc - WM_DRAWCLIPBOARD - "
- "Could not reassert ownership of PRIMARY\n");
- }
- else
- {
- winDebug ("winClipboardWindowProc - WM_DRAWCLIPBOARD - "
- "Reasserted ownership of PRIMARY\n");
- }
-
- /* Reassert ownership of the CLIPBOARD */
- iReturn = XSetSelectionOwner (pDisplay,
- atomClipboard,
- iWindow,
- CurrentTime);
-
- if (iReturn == BadAtom || iReturn == BadWindow ||
- XGetSelectionOwner (pDisplay, atomClipboard) != iWindow)
- {
- winErrorFVerb (1, "winClipboardWindowProc - WM_DRAWCLIPBOARD - "
- "Could not reassert ownership of CLIPBOARD\n");
- }
- else
- {
- winDebug ("winClipboardWindowProc - WM_DRAWCLIPBOARD - "
- "Reasserted ownership of CLIPBOARD\n");
- }
-
- /* Flush the pending SetSelectionOwner event now */
- XFlush (pDisplay);
-
- s_fProcessingDrawClipboard = FALSE;
- }
- winDebug ("winClipboardWindowProc - WM_DRAWCLIPBOARD: Exit\n");
- /* Pass the message on the next window in the clipboard viewer chain */
- if (s_hwndNextViewer)
- SendMessage (s_hwndNextViewer, message, wParam, lParam);
- return 0;
-
-
- case WM_DESTROYCLIPBOARD:
- /*
- * NOTE: Intentionally do nothing.
- * Changes in the Win32 clipboard are handled by WM_DRAWCLIPBOARD
- * above. We only process this message to conform to the specs
- * for delayed clipboard rendering in Win32. You might think
- * that we need to release ownership of the X11 selections, but
- * we do not, because a WM_DRAWCLIPBOARD message will closely
- * follow this message and reassert ownership of the X11
- * selections, handling the issue for us.
- */
- return 0;
-
-
- case WM_RENDERFORMAT:
- case WM_RENDERALLFORMATS:
- {
- int iReturn;
- Display *pDisplay = g_pClipboardDisplay;
- Window iWindow = g_iClipboardWindow;
- Bool fConvertToUnicode;
-
- winDebug ("winClipboardWindowProc - WM_RENDER*FORMAT - Hello.\n");
-
- /* Flag whether to convert to Unicode or not */
- if (message == WM_RENDERALLFORMATS)
- fConvertToUnicode = FALSE;
- else
- fConvertToUnicode = g_fUnicodeSupport && (CF_UNICODETEXT == wParam);
-
- /* Request the selection contents */
- iReturn = XConvertSelection (pDisplay,
- g_atomLastOwnedSelection,
- XInternAtom (pDisplay,
- "COMPOUND_TEXT", False),
- XInternAtom (pDisplay,
- "CYGX_CUT_BUFFER", False),
- iWindow,
- CurrentTime);
- if (iReturn == BadAtom || iReturn == BadWindow)
- {
- winErrorFVerb (1, "winClipboardWindowProc - WM_RENDER*FORMAT - "
- "XConvertSelection () failed\n");
- break;
- }
-
- /* Special handling for WM_RENDERALLFORMATS */
- if (message == WM_RENDERALLFORMATS)
- {
- /* We must open and empty the clipboard */
-
- /* Close clipboard if we have it open already */
- if (GetOpenClipboardWindow () == hwnd)
- {
- CloseClipboard ();
- }
-
- if (!OpenClipboard (hwnd))
- {
- winErrorFVerb (1, "winClipboardWindowProc - WM_RENDER*FORMATS - "
- "OpenClipboard () failed: %08x\n",
- GetLastError ());
- break;
- }
-
- if (!EmptyClipboard ())
- {
- winErrorFVerb (1, "winClipboardWindowProc - WM_RENDER*FORMATS - "
- "EmptyClipboard () failed: %08x\n",
- GetLastError ());
- break;
- }
- }
-
- /* Process the SelectionNotify event */
- iReturn = winProcessXEventsTimeout (hwnd,
- iWindow,
- pDisplay,
- fConvertToUnicode,
- WIN_POLL_TIMEOUT);
- if (WIN_XEVENTS_CONVERT == iReturn)
- {
- /*
- * The selection was offered for conversion first, so we have
- * to process a second SelectionNotify event to get the actual
- * data in the selection.
- */
- iReturn = winProcessXEventsTimeout (hwnd,
- iWindow,
- pDisplay,
- fConvertToUnicode,
- WIN_POLL_TIMEOUT);
- }
-
- /*
- * The last of the up-to two calls to winProcessXEventsTimeout
- * from above had better have seen a notify event, or else we
- * are dealing with a buggy or old X11 app. In these cases we
- * have to paste some fake data to the Win32 clipboard to
- * satisfy the requirement that we write something to it.
- */
- if (WIN_XEVENTS_NOTIFY != iReturn)
- {
- /* Paste no data, to satisfy required call to SetClipboardData */
- if (g_fUnicodeSupport)
- SetClipboardData (CF_UNICODETEXT, NULL);
- SetClipboardData (CF_TEXT, NULL);
- }
-
- /* Special handling for WM_RENDERALLFORMATS */
- if (message == WM_RENDERALLFORMATS)
- {
- /* We must close the clipboard */
-
- if (!CloseClipboard ())
- {
- winErrorFVerb (1, "winClipboardWindowProc - WM_RENDERALLFORMATS - "
- "CloseClipboard () failed: %08x\n",
- GetLastError ());
- break;
- }
- }
-
- winDebug ("winClipboardWindowProc - WM_RENDER*FORMAT - Returning.\n");
- return 0;
- }
- }
-
- /* Let Windows perform default processing for unhandled messages */
- return DefWindowProc (hwnd, message, wParam, lParam);
-}
-
-
-/*
- * Process any pending Windows messages
- */
-
-BOOL
-winClipboardFlushWindowsMessageQueue (HWND hwnd)
-{
- MSG msg;
-
- /* Flush the messaging window queue */
- /* NOTE: Do not pass the hwnd of our messaging window to PeekMessage,
- * as this will filter out many non-window-specific messages that
- * are sent to our thread, such as WM_QUIT.
- */
- while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
- {
- /* Dispatch the message if not WM_QUIT */
- if (msg.message == WM_QUIT)
- return FALSE;
- else
- DispatchMessage (&msg);
- }
-
- return TRUE;
-}
+/*
+ *Copyright (C) 2003-2004 Harold L Hunt II All Rights Reserved.
+ *Copyright (C) Colin Harrison 2005-2008
+ *
+ *Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ *"Software"), to deal in the Software without restriction, including
+ *without limitation the rights to use, copy, modify, merge, publish,
+ *distribute, sublicense, and/or sell copies of the Software, and to
+ *permit persons to whom the Software is furnished to do so, subject to
+ *the following conditions:
+ *
+ *The above copyright notice and this permission notice shall be
+ *included in all copies or substantial portions of the Software.
+ *
+ *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II BE LIABLE FOR
+ *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+ *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ *Except as contained in this notice, the name of the copyright holder(s)
+ *and author(s) shall not be used in advertising or otherwise to promote
+ *the sale, use or other dealings in this Software without prior written
+ *authorization from the copyright holder(s) and author(s).
+ *
+ * Authors: Harold L Hunt II
+ * Colin Harrison
+ */
+
+#ifdef HAVE_XWIN_CONFIG_H
+#include <xwin-config.h>
+#endif
+#include <sys/types.h>
+#include <sys/time.h>
+#include "winclipboard.h"
+#include "misc.h"
+
+/*
+ * Constants
+ */
+
+#define WIN_CLIPBOARD_PROP "cyg_clipboard_prop"
+#define WIN_POLL_TIMEOUT 1
+
+
+/*
+ * References to external symbols
+ */
+
+extern Bool g_fUseUnicode;
+extern Bool g_fUnicodeSupport;
+extern void *g_pClipboardDisplay;
+extern Window g_iClipboardWindow;
+extern Atom g_atomLastOwnedSelection;
+
+/* BPS - g_hwndClipboard needed for X app->Windows paste fix */
+extern HWND g_hwndClipboard;
+
+/*
+ * Local function prototypes
+ */
+
+static int
+winProcessXEventsTimeout (HWND hwnd, int iWindow, Display *pDisplay,
+ Bool fUseUnicode, int iTimeoutSec);
+
+
+/*
+ * Process X events up to specified timeout
+ */
+
+static int
+winProcessXEventsTimeout (HWND hwnd, int iWindow, Display *pDisplay,
+ Bool fUseUnicode, int iTimeoutSec)
+{
+ int iConnNumber;
+ struct timeval tv;
+ int iReturn;
+ DWORD dwStopTime = (GetTickCount () / 1000) + iTimeoutSec;
+
+ /* We need to ensure that all pending events are processed */
+ XSync (pDisplay, FALSE);
+
+ /* Get our connection number */
+ iConnNumber = ConnectionNumber (pDisplay);
+
+ /* Loop for X events */
+ while (1)
+ {
+ fd_set fdsRead;
+
+ /* Setup the file descriptor set */
+ FD_ZERO (&fdsRead);
+ FD_SET (iConnNumber, &fdsRead);
+
+ /* Adjust timeout */
+ tv.tv_sec = dwStopTime - (GetTickCount () / 1000);
+ tv.tv_usec = 0;
+
+ /* Break out if no time left */
+ if (tv.tv_sec < 0)
+ return WIN_XEVENTS_SUCCESS;
+
+ /* Wait for a Windows event or an X event */
+ iReturn = select (iConnNumber + 1,/* Highest fds number */
+ &fdsRead, /* Read mask */
+ NULL, /* No write mask */
+ NULL, /* No exception mask */
+ &tv); /* No timeout */
+ if (iReturn <= 0)
+ {
+ ErrorF ("winProcessXEventsTimeout - Call to select () failed: %d (%x). "
+ "Bailing.\n", iReturn, WSAGetLastError());
+ break;
+ }
+
+ /* Branch on which descriptor became active */
+ if (FD_ISSET (iConnNumber, &fdsRead))
+ {
+ /* Process X events */
+ /* Exit when we see that server is shutting down */
+ iReturn = winClipboardFlushXEvents (hwnd,
+ iWindow,
+ pDisplay,
+ fUseUnicode);
+ if (WIN_XEVENTS_NOTIFY == iReturn
+ || WIN_XEVENTS_CONVERT == iReturn)
+ {
+ /* Bail out if convert or notify processed */
+ return iReturn;
+ }
+ }
+ }
+
+ return WIN_XEVENTS_SUCCESS;
+}
+
+
+/*
+ * Process a given Windows message
+ */
+
+LRESULT CALLBACK
+winClipboardWindowProc (HWND hwnd, UINT message,
+ WPARAM wParam, LPARAM lParam)
+{
+ static HWND s_hwndNextViewer;
+ static Bool s_fCBCInitialized;
+
+ /* Branch on message type */
+ switch (message)
+ {
+ case WM_DESTROY:
+ {
+ winDebug ("winClipboardWindowProc - WM_DESTROY\n");
+
+ /* Remove ourselves from the clipboard chain */
+ ChangeClipboardChain (hwnd, s_hwndNextViewer);
+
+ s_hwndNextViewer = NULL;
+
+ PostQuitMessage (0);
+ }
+ return 0;
+
+
+ case WM_CREATE:
+ {
+ HWND first, next;
+ DWORD error_code = 0;
+ winDebug ("winClipboardWindowProc - WM_CREATE\n");
+
+ first = GetClipboardViewer(); /* Get handle to first viewer in chain. */
+ if (first == hwnd) return 0; /* Make sure it's not us! */
+ /* Add ourselves to the clipboard viewer chain */
+ next = SetClipboardViewer (hwnd);
+ error_code = GetLastError();
+ if (SUCCEEDED(error_code) && (next == first)) /* SetClipboardViewer must have succeeded, and the handle */
+ s_hwndNextViewer = next; /* it returned must have been the first window in the chain */
+ else
+ s_fCBCInitialized = FALSE;
+ }
+ return 0;
+
+
+ case WM_CHANGECBCHAIN:
+ {
+ winDebug ("winClipboardWindowProc - WM_CHANGECBCHAIN: wParam(%x) "
+ "lParam(%x) s_hwndNextViewer(%x)\n",
+ wParam, lParam, s_hwndNextViewer);
+
+ if ((HWND) wParam == s_hwndNextViewer)
+ {
+ s_hwndNextViewer = (HWND) lParam;
+ if (s_hwndNextViewer == hwnd)
+ {
+ s_hwndNextViewer = NULL;
+ winErrorFVerb (1, "winClipboardWindowProc - WM_CHANGECBCHAIN: "
+ "attempted to set next window to ourselves.");
+ }
+ }
+ else if (s_hwndNextViewer)
+ SendMessage (s_hwndNextViewer, message,
+ wParam, lParam);
+
+ }
+ winDebug ("winClipboardWindowProc - WM_CHANGECBCHAIN: Exit\n");
+ return 0;
+
+ case WM_WM_REINIT:
+ {
+ /* Ensure that we're in the clipboard chain. Some apps,
+ * WinXP's remote desktop for one, don't play nice with the
+ * chain. This message is called whenever we receive a
+ * WM_ACTIVATEAPP message to ensure that we continue to
+ * receive clipboard messages.
+ *
+ * It might be possible to detect if we're still in the chain
+ * by calling SendMessage (GetClipboardViewer(),
+ * WM_DRAWCLIPBOARD, 0, 0); and then seeing if we get the
+ * WM_DRAWCLIPBOARD message. That, however, might be more
+ * expensive than just putting ourselves back into the chain.
+ */
+
+ HWND first, next;
+ DWORD error_code = 0;
+ winDebug ("winClipboardWindowProc - WM_WM_REINIT: Enter\n");
+
+ first = GetClipboardViewer(); /* Get handle to first viewer in chain. */
+ if (first == hwnd) return 0; /* Make sure it's not us! */
+ winDebug (" WM_WM_REINIT: Replacing us(%x) with %x at head "
+ "of chain\n", hwnd, s_hwndNextViewer);
+ s_fCBCInitialized = FALSE;
+ ChangeClipboardChain (hwnd, s_hwndNextViewer);
+ s_hwndNextViewer = NULL;
+ s_fCBCInitialized = FALSE;
+ winDebug (" WM_WM_REINIT: Putting us back at head of chain.\n");
+ first = GetClipboardViewer(); /* Get handle to first viewer in chain. */
+ if (first == hwnd) return 0; /* Make sure it's not us! */
+ next = SetClipboardViewer (hwnd);
+ error_code = GetLastError();
+ if (SUCCEEDED(error_code) && (next == first)) /* SetClipboardViewer must have succeeded, and the handle */
+ s_hwndNextViewer = next; /* it returned must have been the first window in the chain */
+ else
+ s_fCBCInitialized = FALSE;
+ }
+ winDebug ("winClipboardWindowProc - WM_WM_REINIT: Exit\n");
+ return 0;
+
+
+ case WM_DRAWCLIPBOARD:
+ {
+ static Atom atomClipboard;
+ static int generation;
+ static Bool s_fProcessingDrawClipboard = FALSE;
+ Display *pDisplay = g_pClipboardDisplay;
+ Window iWindow = g_iClipboardWindow;
+ int iReturn;
+
+ winDebug ("winClipboardWindowProc - WM_DRAWCLIPBOARD: Enter\n");
+
+ if (generation != serverGeneration)
+ {
+ generation = serverGeneration;
+ atomClipboard = XInternAtom (pDisplay, "CLIPBOARD", False);
+ }
+
+ /*
+ * We've occasionally seen a loop in the clipboard chain.
+ * Try and fix it on the first hint of recursion.
+ */
+ if (! s_fProcessingDrawClipboard)
+ {
+ s_fProcessingDrawClipboard = TRUE;
+ }
+ else
+ {
+ /* Attempt to break the nesting by getting out of the chain, twice?, and then fix and bail */
+ s_fCBCInitialized = FALSE;
+ ChangeClipboardChain (hwnd, s_hwndNextViewer);
+ winFixClipboardChain();
+ winErrorFVerb (1, "winClipboardWindowProc - WM_DRAWCLIPBOARD - "
+ "Nested calls detected. Re-initing.\n");
+ winDebug ("winClipboardWindowProc - WM_DRAWCLIPBOARD: Exit\n");
+ s_fProcessingDrawClipboard = FALSE;
+ return 0;
+ }
+
+ /* Bail on first message */
+ if (!s_fCBCInitialized)
+ {
+ s_fCBCInitialized = TRUE;
+ s_fProcessingDrawClipboard = FALSE;
+ winDebug ("winClipboardWindowProc - WM_DRAWCLIPBOARD: Exit\n");
+ return 0;
+ }
+
+ /*
+ * NOTE: We cannot bail out when NULL == GetClipboardOwner ()
+ * because some applications deal with the clipboard in a manner
+ * that causes the clipboard owner to be NULL when they are in
+ * fact taking ownership. One example of this is the Win32
+ * native compile of emacs.
+ */
+
+ /* Bail when we still own the clipboard */
+ if (hwnd == GetClipboardOwner ())
+ {
+
+ winDebug ("winClipboardWindowProc - WM_DRAWCLIPBOARD - "
+ "We own the clipboard, returning.\n");
+ winDebug ("winClipboardWindowProc - WM_DRAWCLIPBOARD: Exit\n");
+ s_fProcessingDrawClipboard = FALSE;
+ if (s_hwndNextViewer)
+ SendMessage (s_hwndNextViewer, message, wParam, lParam);
+ return 0;
+ }
+
+ /*
+ * Do not take ownership of the X11 selections when something
+ * other than CF_TEXT or CF_UNICODETEXT has been copied
+ * into the Win32 clipboard.
+ */
+ if (!IsClipboardFormatAvailable (CF_TEXT)
+ && !IsClipboardFormatAvailable (CF_UNICODETEXT))
+ {
+
+ winDebug ("winClipboardWindowProc - WM_DRAWCLIPBOARD - "
+ "Clipboard does not contain CF_TEXT nor "
+ "CF_UNICODETEXT.\n");
+
+ /*
+ * We need to make sure that the X Server has processed
+ * previous XSetSelectionOwner messages.
+ */
+ XSync (pDisplay, FALSE);
+
+ /* Release PRIMARY selection if owned */
+ iReturn = XGetSelectionOwner (pDisplay, XA_PRIMARY);
+ if (iReturn == g_iClipboardWindow)
+ {
+ winDebug ("winClipboardWindowProc - WM_DRAWCLIPBOARD - "
+ "PRIMARY selection is owned by us.\n");
+ XSetSelectionOwner (pDisplay,
+ XA_PRIMARY,
+ None,
+ CurrentTime);
+ }
+ else if (BadWindow == iReturn || BadAtom == iReturn)
+ winErrorFVerb (1, "winClipboardWindowProc - WM_DRAWCLIPBOARD - "
+ "XGetSelection failed for PRIMARY: %d\n", iReturn);
+
+ /* Release CLIPBOARD selection if owned */
+ iReturn = XGetSelectionOwner (pDisplay,
+ atomClipboard);
+ if (iReturn == g_iClipboardWindow)
+ {
+ winDebug ("winClipboardWindowProc - WM_DRAWCLIPBOARD - "
+ "CLIPBOARD selection is owned by us.\n");
+ XSetSelectionOwner (pDisplay,
+ atomClipboard,
+ None,
+ CurrentTime);
+ }
+ else if (BadWindow == iReturn || BadAtom == iReturn)
+ winErrorFVerb (1, "winClipboardWindowProc - WM_DRAWCLIPBOARD - "
+ "XGetSelection failed for CLIPBOARD: %d\n", iReturn);
+
+ winDebug ("winClipboardWindowProc - WM_DRAWCLIPBOARD: Exit\n");
+ s_fProcessingDrawClipboard = FALSE;
+ if (s_hwndNextViewer)
+ SendMessage (s_hwndNextViewer, message, wParam, lParam);
+ return 0;
+ }
+
+ /* Reassert ownership of PRIMARY */
+ iReturn = XSetSelectionOwner (pDisplay,
+ XA_PRIMARY,
+ iWindow,
+ CurrentTime);
+ if (iReturn == BadAtom || iReturn == BadWindow ||
+ XGetSelectionOwner (pDisplay, XA_PRIMARY) != iWindow)
+ {
+ winErrorFVerb (1, "winClipboardWindowProc - WM_DRAWCLIPBOARD - "
+ "Could not reassert ownership of PRIMARY\n");
+ }
+ else
+ {
+ winDebug ("winClipboardWindowProc - WM_DRAWCLIPBOARD - "
+ "Reasserted ownership of PRIMARY\n");
+ }
+
+ /* Reassert ownership of the CLIPBOARD */
+ iReturn = XSetSelectionOwner (pDisplay,
+ atomClipboard,
+ iWindow,
+ CurrentTime);
+
+ if (iReturn == BadAtom || iReturn == BadWindow ||
+ XGetSelectionOwner (pDisplay, atomClipboard) != iWindow)
+ {
+ winErrorFVerb (1, "winClipboardWindowProc - WM_DRAWCLIPBOARD - "
+ "Could not reassert ownership of CLIPBOARD\n");
+ }
+ else
+ {
+ winDebug ("winClipboardWindowProc - WM_DRAWCLIPBOARD - "
+ "Reasserted ownership of CLIPBOARD\n");
+ }
+
+ /* Flush the pending SetSelectionOwner event now */
+ XFlush (pDisplay);
+
+ s_fProcessingDrawClipboard = FALSE;
+ }
+ winDebug ("winClipboardWindowProc - WM_DRAWCLIPBOARD: Exit\n");
+ /* Pass the message on the next window in the clipboard viewer chain */
+ if (s_hwndNextViewer)
+ SendMessage (s_hwndNextViewer, message, wParam, lParam);
+ return 0;
+
+
+ case WM_DESTROYCLIPBOARD:
+ /*
+ * NOTE: Intentionally do nothing.
+ * Changes in the Win32 clipboard are handled by WM_DRAWCLIPBOARD
+ * above. We only process this message to conform to the specs
+ * for delayed clipboard rendering in Win32. You might think
+ * that we need to release ownership of the X11 selections, but
+ * we do not, because a WM_DRAWCLIPBOARD message will closely
+ * follow this message and reassert ownership of the X11
+ * selections, handling the issue for us.
+ */
+ return 0;
+
+
+ case WM_RENDERFORMAT:
+ case WM_RENDERALLFORMATS:
+ {
+ int iReturn;
+ Display *pDisplay = g_pClipboardDisplay;
+ Window iWindow = g_iClipboardWindow;
+ Bool fConvertToUnicode;
+
+ winDebug ("winClipboardWindowProc - WM_RENDER*FORMAT - Hello.\n");
+
+ /* Flag whether to convert to Unicode or not */
+ if (message == WM_RENDERALLFORMATS)
+ fConvertToUnicode = FALSE;
+ else
+ fConvertToUnicode = g_fUnicodeSupport && (CF_UNICODETEXT == wParam);
+
+ /* Request the selection contents */
+ iReturn = XConvertSelection (pDisplay,
+ g_atomLastOwnedSelection,
+ XInternAtom (pDisplay,
+ "COMPOUND_TEXT", False),
+ XInternAtom (pDisplay,
+ "CYGX_CUT_BUFFER", False),
+ iWindow,
+ CurrentTime);
+ if (iReturn == BadAtom || iReturn == BadWindow)
+ {
+ winErrorFVerb (1, "winClipboardWindowProc - WM_RENDER*FORMAT - "
+ "XConvertSelection () failed\n");
+ break;
+ }
+
+ /* Special handling for WM_RENDERALLFORMATS */
+ if (message == WM_RENDERALLFORMATS)
+ {
+ /* We must open and empty the clipboard */
+
+ /* Close clipboard if we have it open already */
+ if (GetOpenClipboardWindow () == hwnd)
+ {
+ CloseClipboard ();
+ }
+
+ if (!OpenClipboard (hwnd))
+ {
+ winErrorFVerb (1, "winClipboardWindowProc - WM_RENDER*FORMATS - "
+ "OpenClipboard () failed: %08x\n",
+ GetLastError ());
+ break;
+ }
+
+ if (!EmptyClipboard ())
+ {
+ winErrorFVerb (1, "winClipboardWindowProc - WM_RENDER*FORMATS - "
+ "EmptyClipboard () failed: %08x\n",
+ GetLastError ());
+ break;
+ }
+ }
+
+ /* Process the SelectionNotify event */
+ iReturn = winProcessXEventsTimeout (hwnd,
+ iWindow,
+ pDisplay,
+ fConvertToUnicode,
+ WIN_POLL_TIMEOUT);
+ if (WIN_XEVENTS_CONVERT == iReturn)
+ {
+ /*
+ * The selection was offered for conversion first, so we have
+ * to process a second SelectionNotify event to get the actual
+ * data in the selection.
+ */
+ iReturn = winProcessXEventsTimeout (hwnd,
+ iWindow,
+ pDisplay,
+ fConvertToUnicode,
+ WIN_POLL_TIMEOUT);
+ }
+
+ /*
+ * The last of the up-to two calls to winProcessXEventsTimeout
+ * from above had better have seen a notify event, or else we
+ * are dealing with a buggy or old X11 app. In these cases we
+ * have to paste some fake data to the Win32 clipboard to
+ * satisfy the requirement that we write something to it.
+ */
+ if (WIN_XEVENTS_NOTIFY != iReturn)
+ {
+ /* Paste no data, to satisfy required call to SetClipboardData */
+ if (g_fUnicodeSupport)
+ SetClipboardData (CF_UNICODETEXT, NULL);
+ SetClipboardData (CF_TEXT, NULL);
+ }
+
+ /* Special handling for WM_RENDERALLFORMATS */
+ if (message == WM_RENDERALLFORMATS)
+ {
+ /* We must close the clipboard */
+
+ if (!CloseClipboard ())
+ {
+ winErrorFVerb (1, "winClipboardWindowProc - WM_RENDERALLFORMATS - "
+ "CloseClipboard () failed: %08x\n",
+ GetLastError ());
+ break;
+ }
+ }
+
+ winDebug ("winClipboardWindowProc - WM_RENDER*FORMAT - Returning.\n");
+ return 0;
+ }
+ }
+
+ /* Let Windows perform default processing for unhandled messages */
+ return DefWindowProc (hwnd, message, wParam, lParam);
+}
+
+
+/*
+ * Process any pending Windows messages
+ */
+
+BOOL
+winClipboardFlushWindowsMessageQueue (HWND hwnd)
+{
+ MSG msg;
+
+ /* Flush the messaging window queue */
+ /* NOTE: Do not pass the hwnd of our messaging window to PeekMessage,
+ * as this will filter out many non-window-specific messages that
+ * are sent to our thread, such as WM_QUIT.
+ */
+ while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
+ {
+ /* Dispatch the message if not WM_QUIT */
+ if (msg.message == WM_QUIT)
+ return FALSE;
+ else
+ DispatchMessage (&msg);
+ }
+
+ return TRUE;
+}
diff --git a/xorg-server/hw/xwin/winclipboardxevents.c b/xorg-server/hw/xwin/winclipboardxevents.c
index 1d912936a..25ce15f07 100644
--- a/xorg-server/hw/xwin/winclipboardxevents.c
+++ b/xorg-server/hw/xwin/winclipboardxevents.c
@@ -1,833 +1,833 @@
-/*
- *Copyright (C) 2003-2004 Harold L Hunt II All Rights Reserved.
- *Copyright (C) Colin Harrison 2005-2008
- *
- *Permission is hereby granted, free of charge, to any person obtaining
- * a copy of this software and associated documentation files (the
- *"Software"), to deal in the Software without restriction, including
- *without limitation the rights to use, copy, modify, merge, publish,
- *distribute, sublicense, and/or sell copies of the Software, and to
- *permit persons to whom the Software is furnished to do so, subject to
- *the following conditions:
- *
- *The above copyright notice and this permission notice shall be
- *included in all copies or substantial portions of the Software.
- *
- *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II BE LIABLE FOR
- *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
- *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- *Except as contained in this notice, the name of the copyright holder(s)
- *and author(s) shall not be used in advertising or otherwise to promote
- *the sale, use or other dealings in this Software without prior written
- *authorization from the copyright holder(s) and author(s).
- *
- * Authors: Harold L Hunt II
- * Colin Harrison
- */
-
-#ifdef HAVE_XWIN_CONFIG_H
-#include <xwin-config.h>
-#endif
-#include "winclipboard.h"
-#include "misc.h"
-
-
-/*
- * References to external symbols
- */
-
-extern Bool g_fUnicodeSupport;
-
-
-/*
- * Process any pending X events
- */
-
-int
-winClipboardFlushXEvents (HWND hwnd,
- int iWindow,
- Display *pDisplay,
- Bool fUseUnicode)
-{
- static Atom atomLocalProperty;
- static Atom atomCompoundText;
- static Atom atomUTF8String;
- static Atom atomTargets;
- static int generation;
-
- if (generation != serverGeneration)
- {
- generation = serverGeneration;
- atomLocalProperty = XInternAtom (pDisplay, WIN_LOCAL_PROPERTY, False);
- atomUTF8String = XInternAtom (pDisplay, "UTF8_STRING", False);
- atomCompoundText = XInternAtom (pDisplay, "COMPOUND_TEXT", False);
- atomTargets = XInternAtom (pDisplay, "TARGETS", False);
- }
-
- /* Process all pending events */
- while (XPending (pDisplay))
- {
- XTextProperty xtpText = {0};
- XEvent event;
- XSelectionEvent eventSelection;
- unsigned long ulReturnBytesLeft;
- unsigned char *pszReturnData = NULL;
- char *pszGlobalData = NULL;
- int iReturn;
- HGLOBAL hGlobal = NULL;
- XICCEncodingStyle xiccesStyle;
- int iConvertDataLen = 0;
- char *pszConvertData = NULL;
- char *pszTextList[2] = {NULL};
- int iCount;
- char **ppszTextList = NULL;
- wchar_t *pwszUnicodeStr = NULL;
- int iUnicodeLen = 0;
- int iReturnDataLen = 0;
- int i;
- Bool fAbort = FALSE;
- Bool fCloseClipboard = FALSE;
- Bool fSetClipboardData = TRUE;
-
- /* Get the next event - will not block because one is ready */
- XNextEvent (pDisplay, &event);
-
- /* Branch on the event type */
- switch (event.type)
- {
- /*
- * SelectionRequest
- */
-
- case SelectionRequest:
-#if 0
- {
- char *pszAtomName = NULL;
-
- ErrorF ("SelectionRequest - target %d\n",
- event.xselectionrequest.target);
-
- pszAtomName = XGetAtomName (pDisplay,
- event.xselectionrequest.target);
- ErrorF ("SelectionRequest - Target atom name %s\n", pszAtomName);
- XFree (pszAtomName);
- pszAtomName = NULL;
- }
-#endif
-
- /* Abort if invalid target type */
- if (event.xselectionrequest.target != XA_STRING
- && event.xselectionrequest.target != atomUTF8String
- && event.xselectionrequest.target != atomCompoundText
- && event.xselectionrequest.target != atomTargets)
- {
- /* Abort */
- fAbort = TRUE;
- goto winClipboardFlushXEvents_SelectionRequest_Done;
- }
-
- /* Handle targets type of request */
- if (event.xselectionrequest.target == atomTargets)
- {
- Atom atomTargetArr[] = {atomTargets,
- atomCompoundText,
- atomUTF8String,
- XA_STRING};
-
- /* Try to change the property */
- iReturn = XChangeProperty (pDisplay,
- event.xselectionrequest.requestor,
- event.xselectionrequest.property,
- XA_ATOM,
- 32,
- PropModeReplace,
- (unsigned char *) atomTargetArr,
- (sizeof (atomTargetArr)
- / sizeof (atomTargetArr[0])));
- if (iReturn == BadAlloc
- || iReturn == BadAtom
- || iReturn == BadMatch
- || iReturn == BadValue
- || iReturn == BadWindow)
- {
- ErrorF ("winClipboardFlushXEvents - SelectionRequest - "
- "XChangeProperty failed: %d\n",
- iReturn);
- }
-
- /* Setup selection notify xevent */
- eventSelection.type = SelectionNotify;
- eventSelection.send_event = True;
- eventSelection.display = pDisplay;
- eventSelection.requestor = event.xselectionrequest.requestor;
- eventSelection.selection = event.xselectionrequest.selection;
- eventSelection.target = event.xselectionrequest.target;
- eventSelection.property = event.xselectionrequest.property;
- eventSelection.time = event.xselectionrequest.time;
-
- /*
- * Notify the requesting window that
- * the operation has completed
- */
- iReturn = XSendEvent (pDisplay,
- eventSelection.requestor,
- False,
- 0L,
- (XEvent *) &eventSelection);
- if (iReturn == BadValue || iReturn == BadWindow)
- {
- ErrorF ("winClipboardFlushXEvents - SelectionRequest - "
- "XSendEvent () failed\n");
- }
- break;
- }
-
- /* Check that clipboard format is available */
- XLockDisplay (pDisplay);
- if (fUseUnicode
- && !IsClipboardFormatAvailable (CF_UNICODETEXT))
- {
- static int count; /* Hack to stop acroread spamming the log */
- static HWND lasthwnd; /* I've not seen any other client get here repeatedly? */
- if (hwnd != lasthwnd) count = 0;
- count++;
- if (count < 6) ErrorF ("winClipboardFlushXEvents - CF_UNICODETEXT is not "
- "available from Win32 clipboard. Aborting %d.\n", count);
- lasthwnd = hwnd;
-
- /* Abort */
- XUnlockDisplay (pDisplay);
- fAbort = TRUE;
- goto winClipboardFlushXEvents_SelectionRequest_Done;
- }
- else if (!fUseUnicode
- && !IsClipboardFormatAvailable (CF_TEXT))
- {
- ErrorF ("winClipboardFlushXEvents - CF_TEXT is not "
- "available from Win32 clipboard. Aborting.\n");
-
- /* Abort */
- XUnlockDisplay (pDisplay);
- fAbort = TRUE;
- goto winClipboardFlushXEvents_SelectionRequest_Done;
- }
-
- /* Close clipboard if we have it open already */
- if (GetOpenClipboardWindow () == hwnd)
- {
- CloseClipboard ();
- }
-
- /* Access the clipboard */
- if (!OpenClipboard (hwnd))
- {
- ErrorF ("winClipboardFlushXEvents - SelectionRequest - "
- "OpenClipboard () failed: %08x\n",
- GetLastError ());
-
- /* Abort */
- XUnlockDisplay (pDisplay);
- fAbort = TRUE;
- goto winClipboardFlushXEvents_SelectionRequest_Done;
- }
-
- /* Indicate that clipboard was opened */
- fCloseClipboard = TRUE;
-
- /* Setup the string style */
- if (event.xselectionrequest.target == XA_STRING)
- xiccesStyle = XStringStyle;
-#ifdef X_HAVE_UTF8_STRING
- else if (event.xselectionrequest.target == atomUTF8String)
- xiccesStyle = XUTF8StringStyle;
-#endif
- else if (event.xselectionrequest.target == atomCompoundText)
- xiccesStyle = XCompoundTextStyle;
- else
- xiccesStyle = XStringStyle;
-
- /*
- * FIXME: Can't pass CF_UNICODETEXT on Windows 95/98/Me
- */
-
- /* Get a pointer to the clipboard text, in desired format */
- if (fUseUnicode)
- {
- /* Retrieve clipboard data */
- hGlobal = GetClipboardData (CF_UNICODETEXT);
- }
- else
- {
- /* Retrieve clipboard data */
- hGlobal = GetClipboardData (CF_TEXT);
- }
- if (!hGlobal)
- {
- ErrorF ("winClipboardFlushXEvents - SelectionRequest - "
- "GetClipboardData () failed: %08x\n",
- GetLastError ());
-
- /* Abort */
- XUnlockDisplay (pDisplay);
- fAbort = TRUE;
- goto winClipboardFlushXEvents_SelectionRequest_Done;
- }
- pszGlobalData = (char *) GlobalLock (hGlobal);
-
- /* Convert the Unicode string to UTF8 (MBCS) */
- if (fUseUnicode)
- {
- iConvertDataLen = WideCharToMultiByte (CP_UTF8,
- 0,
- (LPCWSTR)pszGlobalData,
- -1,
- NULL,
- 0,
- NULL,
- NULL);
- /* NOTE: iConvertDataLen includes space for null terminator */
- pszConvertData = (char *) malloc (iConvertDataLen);
- WideCharToMultiByte (CP_UTF8,
- 0,
- (LPCWSTR)pszGlobalData,
- -1,
- pszConvertData,
- iConvertDataLen,
- NULL,
- NULL);
- }
- else
- {
- pszConvertData = strdup (pszGlobalData);
- iConvertDataLen = strlen (pszConvertData) + 1;
- }
-
- /* Convert DOS string to UNIX string */
- winClipboardDOStoUNIX (pszConvertData, strlen (pszConvertData));
- XUnlockDisplay (pDisplay);
-
- /* Setup our text list */
- pszTextList[0] = pszConvertData;
- pszTextList[1] = NULL;
-
- /* Initialize the text property */
- xtpText.value = NULL;
- xtpText.nitems = 0;
-
- /* Create the text property from the text list */
- if (fUseUnicode)
- {
-#ifdef X_HAVE_UTF8_STRING
- iReturn = Xutf8TextListToTextProperty (pDisplay,
- pszTextList,
- 1,
- xiccesStyle,
- &xtpText);
-#endif
- }
- else
- {
- iReturn = XmbTextListToTextProperty (pDisplay,
- pszTextList,
- 1,
- xiccesStyle,
- &xtpText);
- }
- if (iReturn == XNoMemory || iReturn == XLocaleNotSupported)
- {
- ErrorF ("winClipboardFlushXEvents - SelectionRequest - "
- "X*TextListToTextProperty failed: %d\n",
- iReturn);
-
- /* Abort */
- fAbort = TRUE;
- goto winClipboardFlushXEvents_SelectionRequest_Done;
- }
-
- /* Free the converted string */
- free (pszConvertData);
- pszConvertData = NULL;
-
- /* Copy the clipboard text to the requesting window */
- iReturn = XChangeProperty (pDisplay,
- event.xselectionrequest.requestor,
- event.xselectionrequest.property,
- event.xselectionrequest.target,
- 8,
- PropModeReplace,
- xtpText.value,
- xtpText.nitems);
- if (iReturn == BadAlloc || iReturn == BadAtom
- || iReturn == BadMatch || iReturn == BadValue
- || iReturn == BadWindow)
- {
- ErrorF ("winClipboardFlushXEvents - SelectionRequest - "
- "XChangeProperty failed: %d\n",
- iReturn);
-
- /* Abort */
- fAbort = TRUE;
- goto winClipboardFlushXEvents_SelectionRequest_Done;
- }
-
- /* Release the clipboard data */
- GlobalUnlock (hGlobal);
- pszGlobalData = NULL;
- fCloseClipboard = FALSE;
- CloseClipboard ();
-
- /* Clean up */
- XFree (xtpText.value);
- xtpText.value = NULL;
- xtpText.nitems = 0;
-
- /* Setup selection notify event */
- eventSelection.type = SelectionNotify;
- eventSelection.send_event = True;
- eventSelection.display = pDisplay;
- eventSelection.requestor = event.xselectionrequest.requestor;
- eventSelection.selection = event.xselectionrequest.selection;
- eventSelection.target = event.xselectionrequest.target;
- eventSelection.property = event.xselectionrequest.property;
- eventSelection.time = event.xselectionrequest.time;
-
- /* Notify the requesting window that the operation has completed */
- iReturn = XSendEvent (pDisplay,
- eventSelection.requestor,
- False,
- 0L,
- (XEvent *) &eventSelection);
- if (iReturn == BadValue || iReturn == BadWindow)
- {
- ErrorF ("winClipboardFlushXEvents - SelectionRequest - "
- "XSendEvent () failed\n");
-
- /* Abort */
- fAbort = TRUE;
- goto winClipboardFlushXEvents_SelectionRequest_Done;
- }
-
- winClipboardFlushXEvents_SelectionRequest_Done:
- /* Free allocated resources */
- if (xtpText.value)
- {
- XFree (xtpText.value);
- xtpText.value = NULL;
- xtpText.nitems = 0;
- }
- if (pszConvertData)
- free (pszConvertData);
- if (hGlobal && pszGlobalData)
- GlobalUnlock (hGlobal);
-
- /*
- * Send a SelectionNotify event to the requesting
- * client when we abort.
- */
- if (fAbort)
- {
- /* Setup selection notify event */
- eventSelection.type = SelectionNotify;
- eventSelection.send_event = True;
- eventSelection.display = pDisplay;
- eventSelection.requestor = event.xselectionrequest.requestor;
- eventSelection.selection = event.xselectionrequest.selection;
- eventSelection.target = event.xselectionrequest.target;
- eventSelection.property = None;
- eventSelection.time = event.xselectionrequest.time;
-
- /* Notify the requesting window that the operation is complete */
- iReturn = XSendEvent (pDisplay,
- eventSelection.requestor,
- False,
- 0L,
- (XEvent *) &eventSelection);
- if (iReturn == BadValue || iReturn == BadWindow)
- {
- /*
- * Should not be a problem if XSendEvent fails because
- * the client may simply have exited.
- */
- ErrorF ("winClipboardFlushXEvents - SelectionRequest - "
- "XSendEvent () failed for abort event.\n");
- }
- }
-
- /* Close clipboard if it was opened */
- if (fCloseClipboard)
- {
- fCloseClipboard = FALSE;
- CloseClipboard ();
- }
- break;
-
-
- /*
- * SelectionNotify
- */
-
- case SelectionNotify:
-#if 0
- ErrorF ("winClipboardFlushXEvents - SelectionNotify\n");
- {
- char *pszAtomName;
-
- pszAtomName = XGetAtomName (pDisplay,
- event.xselection.selection);
-
- ErrorF ("winClipboardFlushXEvents - SelectionNotify - ATOM: %s\n",
- pszAtomName);
-
- XFree (pszAtomName);
- }
-#endif
-
-
- /*
- * Request conversion of UTF8 and CompoundText targets.
- */
- if (event.xselection.property == None)
- {
- if (event.xselection.target == XA_STRING)
- {
-#if 0
- ErrorF ("winClipboardFlushXEvents - SelectionNotify - "
- "XA_STRING\n");
-#endif
- return WIN_XEVENTS_CONVERT;
- }
- else if (event.xselection.target == atomUTF8String)
- {
-#if 0
- ErrorF ("winClipboardFlushXEvents - SelectionNotify - "
- "Requesting conversion of UTF8 target.\n");
-#endif
- iReturn = XConvertSelection (pDisplay,
- event.xselection.selection,
- XA_STRING,
- atomLocalProperty,
- iWindow,
- CurrentTime);
- if (iReturn != Success)
- {
- ErrorF ("winClipboardFlushXEvents - SelectionNotify - "
- "XConvertSelection () failed for UTF8String, "
- "aborting: %d\n",
- iReturn);
- break;
- }
-
- /* Process the ConvertSelection event */
- XFlush (pDisplay);
- return WIN_XEVENTS_CONVERT;
- }
-#ifdef X_HAVE_UTF8_STRING
- else if (event.xselection.target == atomCompoundText)
- {
-#if 0
- ErrorF ("winClipboardFlushXEvents - SelectionNotify - "
- "Requesting conversion of CompoundText target.\n");
-#endif
- iReturn = XConvertSelection (pDisplay,
- event.xselection.selection,
- atomUTF8String,
- atomLocalProperty,
- iWindow,
- CurrentTime);
- if (iReturn != Success)
- {
- ErrorF ("winClipboardFlushXEvents - SelectionNotify - "
- "XConvertSelection () failed for CompoundText, "
- "aborting: %d\n",
- iReturn);
- break;
- }
-
- /* Process the ConvertSelection event */
- XFlush (pDisplay);
- return WIN_XEVENTS_CONVERT;
- }
-#endif
- else
- {
- ErrorF ("winClipboardFlushXEvents - SelectionNotify - "
- "Unknown format. Cannot request conversion, "
- "aborting.\n");
- break;
- }
- }
-
- /* Retrieve the size of the stored data */
- iReturn = XGetWindowProperty (pDisplay,
- iWindow,
- atomLocalProperty,
- 0,
- 0, /* Don't get data, just size */
- False,
- AnyPropertyType,
- &xtpText.encoding,
- &xtpText.format,
- &xtpText.nitems,
- &ulReturnBytesLeft,
- &xtpText.value);
- if (iReturn != Success)
- {
- ErrorF ("winClipboardFlushXEvents - SelectionNotify - "
- "XGetWindowProperty () failed, aborting: %d\n",
- iReturn);
- break;
- }
-
-#if 0
- ErrorF ("SelectionNotify - returned data %d left %d\n",
- xtpText.nitems, ulReturnBytesLeft);
-#endif
-
- /* Request the selection data */
- iReturn = XGetWindowProperty (pDisplay,
- iWindow,
- atomLocalProperty,
- 0,
- ulReturnBytesLeft,
- False,
- AnyPropertyType,
- &xtpText.encoding,
- &xtpText.format,
- &xtpText.nitems,
- &ulReturnBytesLeft,
- &xtpText.value);
- if (iReturn != Success)
- {
- ErrorF ("winClipboardFlushXEvents - SelectionNotify - "
- "XGetWindowProperty () failed, aborting: %d\n",
- iReturn);
- break;
- }
-
-#if 0
- {
- char *pszAtomName = NULL;
-
- ErrorF ("SelectionNotify - returned data %d left %d\n",
- xtpText.nitems, ulReturnBytesLeft);
-
- pszAtomName = XGetAtomName(pDisplay, xtpText.encoding);
- ErrorF ("Notify atom name %s\n", pszAtomName);
- XFree (pszAtomName);
- pszAtomName = NULL;
- }
-#endif
-
- if (fUseUnicode)
- {
-#ifdef X_HAVE_UTF8_STRING
- /* Convert the text property to a text list */
- iReturn = Xutf8TextPropertyToTextList (pDisplay,
- &xtpText,
- &ppszTextList,
- &iCount);
-#endif
- }
- else
- {
- iReturn = XmbTextPropertyToTextList (pDisplay,
- &xtpText,
- &ppszTextList,
- &iCount);
- }
- if (iReturn == Success || iReturn > 0)
- {
- /* Conversion succeeded or some unconvertible characters */
- if (ppszTextList != NULL)
- {
- iReturnDataLen = 0;
- for (i = 0; i < iCount; i++)
- {
- iReturnDataLen += strlen(ppszTextList[i]);
- }
- pszReturnData = (char *) malloc (iReturnDataLen + 1);
- pszReturnData[0] = '\0';
- for (i = 0; i < iCount; i++)
- {
- strcat (pszReturnData, ppszTextList[i]);
- }
- }
- else
- {
- ErrorF ("winClipboardFlushXEvents - SelectionNotify - "
- "X*TextPropertyToTextList list_return is NULL.\n");
- pszReturnData = (char *) malloc (1);
- pszReturnData[0] = '\0';
- }
- }
- else
- {
- ErrorF ("winClipboardFlushXEvents - SelectionNotify - "
- "X*TextPropertyToTextList returned: ");
- switch (iReturn)
- {
- case XNoMemory:
- ErrorF ("XNoMemory\n");
- break;
- case XConverterNotFound:
- ErrorF ("XConverterNotFound\n");
- break;
- default:
- ErrorF ("%d", iReturn);
- break;
- }
- pszReturnData = (char *) malloc (1);
- pszReturnData[0] = '\0';
- }
-
- /* Free the data returned from XGetWindowProperty */
- if (ppszTextList)
- XFreeStringList (ppszTextList);
- ppszTextList = NULL;
- XFree (xtpText.value);
- xtpText.value = NULL;
- xtpText.nitems = 0;
-
- /* Convert the X clipboard string to DOS format */
- XLockDisplay (pDisplay);
- winClipboardUNIXtoDOS ((unsigned char **)&pszReturnData, strlen (pszReturnData));
-
- if (fUseUnicode)
- {
- /* Find out how much space needed to convert MBCS to Unicode */
- iUnicodeLen = MultiByteToWideChar (CP_UTF8,
- 0,
- pszReturnData,
- -1,
- NULL,
- 0);
-
- /* Allocate memory for the Unicode string */
- pwszUnicodeStr
- = (wchar_t*) malloc (sizeof (wchar_t) * (iUnicodeLen + 1));
- if (!pwszUnicodeStr)
- {
- ErrorF ("winClipboardFlushXEvents - SelectionNotify "
- "malloc failed for pwszUnicodeStr, aborting.\n");
-
- /* Abort */
- fAbort = TRUE;
- goto winClipboardFlushXEvents_SelectionNotify_Done;
- }
-
- /* Do the actual conversion */
- MultiByteToWideChar (CP_UTF8,
- 0,
- pszReturnData,
- -1,
- pwszUnicodeStr,
- iUnicodeLen);
-
- /* Allocate global memory for the X clipboard data */
- hGlobal = GlobalAlloc (GMEM_MOVEABLE,
- sizeof (wchar_t) * (iUnicodeLen + 1));
- }
- else
- {
- pszConvertData = strdup (pszReturnData);
- iConvertDataLen = strlen (pszConvertData) + 1;
-
- /* Allocate global memory for the X clipboard data */
- hGlobal = GlobalAlloc (GMEM_MOVEABLE, iConvertDataLen);
- }
-
- free (pszReturnData);
-
- /* Check that global memory was allocated */
- if (!hGlobal)
- {
- ErrorF ("winClipboardFlushXEvents - SelectionNotify "
- "GlobalAlloc failed, aborting: %ld\n",
- GetLastError ());
-
- /* Abort */
- fAbort = TRUE;
- goto winClipboardFlushXEvents_SelectionNotify_Done;
- }
-
- /* Obtain a pointer to the global memory */
- pszGlobalData = GlobalLock (hGlobal);
- if (pszGlobalData == NULL)
- {
- ErrorF ("winClipboardFlushXEvents - Could not lock global "
- "memory for clipboard transfer\n");
-
- /* Abort */
- fAbort = TRUE;
- goto winClipboardFlushXEvents_SelectionNotify_Done;
- }
-
- /* Copy the returned string into the global memory */
- if (fUseUnicode)
- {
- memcpy (pszGlobalData,
- pwszUnicodeStr,
- sizeof (wchar_t) * (iUnicodeLen + 1));
- free (pwszUnicodeStr);
- pwszUnicodeStr = NULL;
- }
- else
- {
- strcpy (pszGlobalData, pszConvertData);
- free (pszConvertData);
- pszConvertData = NULL;
- }
-
- /* Release the pointer to the global memory */
- GlobalUnlock (hGlobal);
- pszGlobalData = NULL;
-
- /* Push the selection data to the Windows clipboard */
- if (fUseUnicode)
- SetClipboardData (CF_UNICODETEXT, hGlobal);
- else
- SetClipboardData (CF_TEXT, hGlobal);
-
- /* Flag that SetClipboardData has been called */
- fSetClipboardData = FALSE;
-
- /*
- * NOTE: Do not try to free pszGlobalData, it is owned by
- * Windows after the call to SetClipboardData ().
- */
-
- winClipboardFlushXEvents_SelectionNotify_Done:
- XUnlockDisplay (pDisplay);
- /* Free allocated resources */
- if (ppszTextList)
- XFreeStringList (ppszTextList);
- if (xtpText.value)
- {
- XFree (xtpText.value);
- xtpText.value = NULL;
- xtpText.nitems = 0;
- }
- if (pszConvertData)
- free (pszConvertData);
- if (pwszUnicodeStr)
- free (pwszUnicodeStr);
- if (hGlobal && pszGlobalData)
- GlobalUnlock (hGlobal);
- if (fSetClipboardData && g_fUnicodeSupport)
- SetClipboardData (CF_UNICODETEXT, NULL);
- if (fSetClipboardData)
- SetClipboardData (CF_TEXT, NULL);
- return WIN_XEVENTS_NOTIFY;
-
- default:
- break;
- }
- }
-
- return WIN_XEVENTS_SUCCESS;
-}
+/*
+ *Copyright (C) 2003-2004 Harold L Hunt II All Rights Reserved.
+ *Copyright (C) Colin Harrison 2005-2008
+ *
+ *Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ *"Software"), to deal in the Software without restriction, including
+ *without limitation the rights to use, copy, modify, merge, publish,
+ *distribute, sublicense, and/or sell copies of the Software, and to
+ *permit persons to whom the Software is furnished to do so, subject to
+ *the following conditions:
+ *
+ *The above copyright notice and this permission notice shall be
+ *included in all copies or substantial portions of the Software.
+ *
+ *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II BE LIABLE FOR
+ *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+ *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ *Except as contained in this notice, the name of the copyright holder(s)
+ *and author(s) shall not be used in advertising or otherwise to promote
+ *the sale, use or other dealings in this Software without prior written
+ *authorization from the copyright holder(s) and author(s).
+ *
+ * Authors: Harold L Hunt II
+ * Colin Harrison
+ */
+
+#ifdef HAVE_XWIN_CONFIG_H
+#include <xwin-config.h>
+#endif
+#include "winclipboard.h"
+#include "misc.h"
+
+
+/*
+ * References to external symbols
+ */
+
+extern Bool g_fUnicodeSupport;
+
+
+/*
+ * Process any pending X events
+ */
+
+int
+winClipboardFlushXEvents (HWND hwnd,
+ int iWindow,
+ Display *pDisplay,
+ Bool fUseUnicode)
+{
+ static Atom atomLocalProperty;
+ static Atom atomCompoundText;
+ static Atom atomUTF8String;
+ static Atom atomTargets;
+ static int generation;
+
+ if (generation != serverGeneration)
+ {
+ generation = serverGeneration;
+ atomLocalProperty = XInternAtom (pDisplay, WIN_LOCAL_PROPERTY, False);
+ atomUTF8String = XInternAtom (pDisplay, "UTF8_STRING", False);
+ atomCompoundText = XInternAtom (pDisplay, "COMPOUND_TEXT", False);
+ atomTargets = XInternAtom (pDisplay, "TARGETS", False);
+ }
+
+ /* Process all pending events */
+ while (XPending (pDisplay))
+ {
+ XTextProperty xtpText = {0};
+ XEvent event;
+ XSelectionEvent eventSelection;
+ unsigned long ulReturnBytesLeft;
+ unsigned char *pszReturnData = NULL;
+ char *pszGlobalData = NULL;
+ int iReturn;
+ HGLOBAL hGlobal = NULL;
+ XICCEncodingStyle xiccesStyle;
+ int iConvertDataLen = 0;
+ char *pszConvertData = NULL;
+ char *pszTextList[2] = {NULL};
+ int iCount;
+ char **ppszTextList = NULL;
+ wchar_t *pwszUnicodeStr = NULL;
+ int iUnicodeLen = 0;
+ int iReturnDataLen = 0;
+ int i;
+ Bool fAbort = FALSE;
+ Bool fCloseClipboard = FALSE;
+ Bool fSetClipboardData = TRUE;
+
+ /* Get the next event - will not block because one is ready */
+ XNextEvent (pDisplay, &event);
+
+ /* Branch on the event type */
+ switch (event.type)
+ {
+ /*
+ * SelectionRequest
+ */
+
+ case SelectionRequest:
+#if 0
+ {
+ char *pszAtomName = NULL;
+
+ ErrorF ("SelectionRequest - target %d\n",
+ event.xselectionrequest.target);
+
+ pszAtomName = XGetAtomName (pDisplay,
+ event.xselectionrequest.target);
+ ErrorF ("SelectionRequest - Target atom name %s\n", pszAtomName);
+ XFree (pszAtomName);
+ pszAtomName = NULL;
+ }
+#endif
+
+ /* Abort if invalid target type */
+ if (event.xselectionrequest.target != XA_STRING
+ && event.xselectionrequest.target != atomUTF8String
+ && event.xselectionrequest.target != atomCompoundText
+ && event.xselectionrequest.target != atomTargets)
+ {
+ /* Abort */
+ fAbort = TRUE;
+ goto winClipboardFlushXEvents_SelectionRequest_Done;
+ }
+
+ /* Handle targets type of request */
+ if (event.xselectionrequest.target == atomTargets)
+ {
+ Atom atomTargetArr[] = {atomTargets,
+ atomCompoundText,
+ atomUTF8String,
+ XA_STRING};
+
+ /* Try to change the property */
+ iReturn = XChangeProperty (pDisplay,
+ event.xselectionrequest.requestor,
+ event.xselectionrequest.property,
+ XA_ATOM,
+ 32,
+ PropModeReplace,
+ (unsigned char *) atomTargetArr,
+ (sizeof (atomTargetArr)
+ / sizeof (atomTargetArr[0])));
+ if (iReturn == BadAlloc
+ || iReturn == BadAtom
+ || iReturn == BadMatch
+ || iReturn == BadValue
+ || iReturn == BadWindow)
+ {
+ ErrorF ("winClipboardFlushXEvents - SelectionRequest - "
+ "XChangeProperty failed: %d\n",
+ iReturn);
+ }
+
+ /* Setup selection notify xevent */
+ eventSelection.type = SelectionNotify;
+ eventSelection.send_event = True;
+ eventSelection.display = pDisplay;
+ eventSelection.requestor = event.xselectionrequest.requestor;
+ eventSelection.selection = event.xselectionrequest.selection;
+ eventSelection.target = event.xselectionrequest.target;
+ eventSelection.property = event.xselectionrequest.property;
+ eventSelection.time = event.xselectionrequest.time;
+
+ /*
+ * Notify the requesting window that
+ * the operation has completed
+ */
+ iReturn = XSendEvent (pDisplay,
+ eventSelection.requestor,
+ False,
+ 0L,
+ (XEvent *) &eventSelection);
+ if (iReturn == BadValue || iReturn == BadWindow)
+ {
+ ErrorF ("winClipboardFlushXEvents - SelectionRequest - "
+ "XSendEvent () failed\n");
+ }
+ break;
+ }
+
+ /* Check that clipboard format is available */
+ XLockDisplay (pDisplay);
+ if (fUseUnicode
+ && !IsClipboardFormatAvailable (CF_UNICODETEXT))
+ {
+ static int count; /* Hack to stop acroread spamming the log */
+ static HWND lasthwnd; /* I've not seen any other client get here repeatedly? */
+ if (hwnd != lasthwnd) count = 0;
+ count++;
+ if (count < 6) ErrorF ("winClipboardFlushXEvents - CF_UNICODETEXT is not "
+ "available from Win32 clipboard. Aborting %d.\n", count);
+ lasthwnd = hwnd;
+
+ /* Abort */
+ XUnlockDisplay (pDisplay);
+ fAbort = TRUE;
+ goto winClipboardFlushXEvents_SelectionRequest_Done;
+ }
+ else if (!fUseUnicode
+ && !IsClipboardFormatAvailable (CF_TEXT))
+ {
+ ErrorF ("winClipboardFlushXEvents - CF_TEXT is not "
+ "available from Win32 clipboard. Aborting.\n");
+
+ /* Abort */
+ XUnlockDisplay (pDisplay);
+ fAbort = TRUE;
+ goto winClipboardFlushXEvents_SelectionRequest_Done;
+ }
+
+ /* Close clipboard if we have it open already */
+ if (GetOpenClipboardWindow () == hwnd)
+ {
+ CloseClipboard ();
+ }
+
+ /* Access the clipboard */
+ if (!OpenClipboard (hwnd))
+ {
+ ErrorF ("winClipboardFlushXEvents - SelectionRequest - "
+ "OpenClipboard () failed: %08x\n",
+ GetLastError ());
+
+ /* Abort */
+ XUnlockDisplay (pDisplay);
+ fAbort = TRUE;
+ goto winClipboardFlushXEvents_SelectionRequest_Done;
+ }
+
+ /* Indicate that clipboard was opened */
+ fCloseClipboard = TRUE;
+
+ /* Setup the string style */
+ if (event.xselectionrequest.target == XA_STRING)
+ xiccesStyle = XStringStyle;
+#ifdef X_HAVE_UTF8_STRING
+ else if (event.xselectionrequest.target == atomUTF8String)
+ xiccesStyle = XUTF8StringStyle;
+#endif
+ else if (event.xselectionrequest.target == atomCompoundText)
+ xiccesStyle = XCompoundTextStyle;
+ else
+ xiccesStyle = XStringStyle;
+
+ /*
+ * FIXME: Can't pass CF_UNICODETEXT on Windows 95/98/Me
+ */
+
+ /* Get a pointer to the clipboard text, in desired format */
+ if (fUseUnicode)
+ {
+ /* Retrieve clipboard data */
+ hGlobal = GetClipboardData (CF_UNICODETEXT);
+ }
+ else
+ {
+ /* Retrieve clipboard data */
+ hGlobal = GetClipboardData (CF_TEXT);
+ }
+ if (!hGlobal)
+ {
+ ErrorF ("winClipboardFlushXEvents - SelectionRequest - "
+ "GetClipboardData () failed: 0x%08x\n",
+ GetLastError ());
+
+ /* Abort */
+ XUnlockDisplay (pDisplay);
+ fAbort = TRUE;
+ goto winClipboardFlushXEvents_SelectionRequest_Done;
+ }
+ pszGlobalData = (char *) GlobalLock (hGlobal);
+
+ /* Convert the Unicode string to UTF8 (MBCS) */
+ if (fUseUnicode)
+ {
+ iConvertDataLen = WideCharToMultiByte (CP_UTF8,
+ 0,
+ (LPCWSTR)pszGlobalData,
+ -1,
+ NULL,
+ 0,
+ NULL,
+ NULL);
+ /* NOTE: iConvertDataLen includes space for null terminator */
+ pszConvertData = (char *) malloc (iConvertDataLen);
+ WideCharToMultiByte (CP_UTF8,
+ 0,
+ (LPCWSTR)pszGlobalData,
+ -1,
+ pszConvertData,
+ iConvertDataLen,
+ NULL,
+ NULL);
+ }
+ else
+ {
+ pszConvertData = strdup (pszGlobalData);
+ iConvertDataLen = strlen (pszConvertData) + 1;
+ }
+
+ /* Convert DOS string to UNIX string */
+ winClipboardDOStoUNIX (pszConvertData, strlen (pszConvertData));
+ XUnlockDisplay (pDisplay);
+
+ /* Setup our text list */
+ pszTextList[0] = pszConvertData;
+ pszTextList[1] = NULL;
+
+ /* Initialize the text property */
+ xtpText.value = NULL;
+ xtpText.nitems = 0;
+
+ /* Create the text property from the text list */
+ if (fUseUnicode)
+ {
+#ifdef X_HAVE_UTF8_STRING
+ iReturn = Xutf8TextListToTextProperty (pDisplay,
+ pszTextList,
+ 1,
+ xiccesStyle,
+ &xtpText);
+#endif
+ }
+ else
+ {
+ iReturn = XmbTextListToTextProperty (pDisplay,
+ pszTextList,
+ 1,
+ xiccesStyle,
+ &xtpText);
+ }
+ if (iReturn == XNoMemory || iReturn == XLocaleNotSupported)
+ {
+ ErrorF ("winClipboardFlushXEvents - SelectionRequest - "
+ "X*TextListToTextProperty failed: %d\n",
+ iReturn);
+
+ /* Abort */
+ fAbort = TRUE;
+ goto winClipboardFlushXEvents_SelectionRequest_Done;
+ }
+
+ /* Free the converted string */
+ free (pszConvertData);
+ pszConvertData = NULL;
+
+ /* Copy the clipboard text to the requesting window */
+ iReturn = XChangeProperty (pDisplay,
+ event.xselectionrequest.requestor,
+ event.xselectionrequest.property,
+ event.xselectionrequest.target,
+ 8,
+ PropModeReplace,
+ xtpText.value,
+ xtpText.nitems);
+ if (iReturn == BadAlloc || iReturn == BadAtom
+ || iReturn == BadMatch || iReturn == BadValue
+ || iReturn == BadWindow)
+ {
+ ErrorF ("winClipboardFlushXEvents - SelectionRequest - "
+ "XChangeProperty failed: %d\n",
+ iReturn);
+
+ /* Abort */
+ fAbort = TRUE;
+ goto winClipboardFlushXEvents_SelectionRequest_Done;
+ }
+
+ /* Release the clipboard data */
+ GlobalUnlock (hGlobal);
+ pszGlobalData = NULL;
+ fCloseClipboard = FALSE;
+ CloseClipboard ();
+
+ /* Clean up */
+ XFree (xtpText.value);
+ xtpText.value = NULL;
+ xtpText.nitems = 0;
+
+ /* Setup selection notify event */
+ eventSelection.type = SelectionNotify;
+ eventSelection.send_event = True;
+ eventSelection.display = pDisplay;
+ eventSelection.requestor = event.xselectionrequest.requestor;
+ eventSelection.selection = event.xselectionrequest.selection;
+ eventSelection.target = event.xselectionrequest.target;
+ eventSelection.property = event.xselectionrequest.property;
+ eventSelection.time = event.xselectionrequest.time;
+
+ /* Notify the requesting window that the operation has completed */
+ iReturn = XSendEvent (pDisplay,
+ eventSelection.requestor,
+ False,
+ 0L,
+ (XEvent *) &eventSelection);
+ if (iReturn == BadValue || iReturn == BadWindow)
+ {
+ ErrorF ("winClipboardFlushXEvents - SelectionRequest - "
+ "XSendEvent () failed\n");
+
+ /* Abort */
+ fAbort = TRUE;
+ goto winClipboardFlushXEvents_SelectionRequest_Done;
+ }
+
+ winClipboardFlushXEvents_SelectionRequest_Done:
+ /* Free allocated resources */
+ if (xtpText.value)
+ {
+ XFree (xtpText.value);
+ xtpText.value = NULL;
+ xtpText.nitems = 0;
+ }
+ if (pszConvertData)
+ free (pszConvertData);
+ if (hGlobal && pszGlobalData)
+ GlobalUnlock (hGlobal);
+
+ /*
+ * Send a SelectionNotify event to the requesting
+ * client when we abort.
+ */
+ if (fAbort)
+ {
+ /* Setup selection notify event */
+ eventSelection.type = SelectionNotify;
+ eventSelection.send_event = True;
+ eventSelection.display = pDisplay;
+ eventSelection.requestor = event.xselectionrequest.requestor;
+ eventSelection.selection = event.xselectionrequest.selection;
+ eventSelection.target = event.xselectionrequest.target;
+ eventSelection.property = None;
+ eventSelection.time = event.xselectionrequest.time;
+
+ /* Notify the requesting window that the operation is complete */
+ iReturn = XSendEvent (pDisplay,
+ eventSelection.requestor,
+ False,
+ 0L,
+ (XEvent *) &eventSelection);
+ if (iReturn == BadValue || iReturn == BadWindow)
+ {
+ /*
+ * Should not be a problem if XSendEvent fails because
+ * the client may simply have exited.
+ */
+ ErrorF ("winClipboardFlushXEvents - SelectionRequest - "
+ "XSendEvent () failed for abort event.\n");
+ }
+ }
+
+ /* Close clipboard if it was opened */
+ if (fCloseClipboard)
+ {
+ fCloseClipboard = FALSE;
+ CloseClipboard ();
+ }
+ break;
+
+
+ /*
+ * SelectionNotify
+ */
+
+ case SelectionNotify:
+#if 0
+ ErrorF ("winClipboardFlushXEvents - SelectionNotify\n");
+ {
+ char *pszAtomName;
+
+ pszAtomName = XGetAtomName (pDisplay,
+ event.xselection.selection);
+
+ ErrorF ("winClipboardFlushXEvents - SelectionNotify - ATOM: %s\n",
+ pszAtomName);
+
+ XFree (pszAtomName);
+ }
+#endif
+
+
+ /*
+ * Request conversion of UTF8 and CompoundText targets.
+ */
+ if (event.xselection.property == None)
+ {
+ if (event.xselection.target == XA_STRING)
+ {
+#if 0
+ ErrorF ("winClipboardFlushXEvents - SelectionNotify - "
+ "XA_STRING\n");
+#endif
+ return WIN_XEVENTS_CONVERT;
+ }
+ else if (event.xselection.target == atomUTF8String)
+ {
+#if 0
+ ErrorF ("winClipboardFlushXEvents - SelectionNotify - "
+ "Requesting conversion of UTF8 target.\n");
+#endif
+ iReturn = XConvertSelection (pDisplay,
+ event.xselection.selection,
+ XA_STRING,
+ atomLocalProperty,
+ iWindow,
+ CurrentTime);
+ if (iReturn != Success)
+ {
+ ErrorF ("winClipboardFlushXEvents - SelectionNotify - "
+ "XConvertSelection () failed for UTF8String, "
+ "aborting: %d\n",
+ iReturn);
+ break;
+ }
+
+ /* Process the ConvertSelection event */
+ XFlush (pDisplay);
+ return WIN_XEVENTS_CONVERT;
+ }
+#ifdef X_HAVE_UTF8_STRING
+ else if (event.xselection.target == atomCompoundText)
+ {
+#if 0
+ ErrorF ("winClipboardFlushXEvents - SelectionNotify - "
+ "Requesting conversion of CompoundText target.\n");
+#endif
+ iReturn = XConvertSelection (pDisplay,
+ event.xselection.selection,
+ atomUTF8String,
+ atomLocalProperty,
+ iWindow,
+ CurrentTime);
+ if (iReturn != Success)
+ {
+ ErrorF ("winClipboardFlushXEvents - SelectionNotify - "
+ "XConvertSelection () failed for CompoundText, "
+ "aborting: %d\n",
+ iReturn);
+ break;
+ }
+
+ /* Process the ConvertSelection event */
+ XFlush (pDisplay);
+ return WIN_XEVENTS_CONVERT;
+ }
+#endif
+ else
+ {
+ ErrorF ("winClipboardFlushXEvents - SelectionNotify - "
+ "Unknown format. Cannot request conversion, "
+ "aborting.\n");
+ break;
+ }
+ }
+
+ /* Retrieve the size of the stored data */
+ iReturn = XGetWindowProperty (pDisplay,
+ iWindow,
+ atomLocalProperty,
+ 0,
+ 0, /* Don't get data, just size */
+ False,
+ AnyPropertyType,
+ &xtpText.encoding,
+ &xtpText.format,
+ &xtpText.nitems,
+ &ulReturnBytesLeft,
+ &xtpText.value);
+ if (iReturn != Success)
+ {
+ ErrorF ("winClipboardFlushXEvents - SelectionNotify - "
+ "XGetWindowProperty () failed, aborting: %d\n",
+ iReturn);
+ break;
+ }
+
+#if 0
+ ErrorF ("SelectionNotify - returned data %d left %d\n",
+ xtpText.nitems, ulReturnBytesLeft);
+#endif
+
+ /* Request the selection data */
+ iReturn = XGetWindowProperty (pDisplay,
+ iWindow,
+ atomLocalProperty,
+ 0,
+ ulReturnBytesLeft,
+ False,
+ AnyPropertyType,
+ &xtpText.encoding,
+ &xtpText.format,
+ &xtpText.nitems,
+ &ulReturnBytesLeft,
+ &xtpText.value);
+ if (iReturn != Success)
+ {
+ ErrorF ("winClipboardFlushXEvents - SelectionNotify - "
+ "XGetWindowProperty () failed, aborting: %d\n",
+ iReturn);
+ break;
+ }
+
+#if 0
+ {
+ char *pszAtomName = NULL;
+
+ ErrorF ("SelectionNotify - returned data %d left %d\n",
+ xtpText.nitems, ulReturnBytesLeft);
+
+ pszAtomName = XGetAtomName(pDisplay, xtpText.encoding);
+ ErrorF ("Notify atom name %s\n", pszAtomName);
+ XFree (pszAtomName);
+ pszAtomName = NULL;
+ }
+#endif
+
+ if (fUseUnicode)
+ {
+#ifdef X_HAVE_UTF8_STRING
+ /* Convert the text property to a text list */
+ iReturn = Xutf8TextPropertyToTextList (pDisplay,
+ &xtpText,
+ &ppszTextList,
+ &iCount);
+#endif
+ }
+ else
+ {
+ iReturn = XmbTextPropertyToTextList (pDisplay,
+ &xtpText,
+ &ppszTextList,
+ &iCount);
+ }
+ if (iReturn == Success || iReturn > 0)
+ {
+ /* Conversion succeeded or some unconvertible characters */
+ if (ppszTextList != NULL)
+ {
+ iReturnDataLen = 0;
+ for (i = 0; i < iCount; i++)
+ {
+ iReturnDataLen += strlen(ppszTextList[i]);
+ }
+ pszReturnData = (char *) malloc (iReturnDataLen + 1);
+ pszReturnData[0] = '\0';
+ for (i = 0; i < iCount; i++)
+ {
+ strcat (pszReturnData, ppszTextList[i]);
+ }
+ }
+ else
+ {
+ ErrorF ("winClipboardFlushXEvents - SelectionNotify - "
+ "X*TextPropertyToTextList list_return is NULL.\n");
+ pszReturnData = (char *) malloc (1);
+ pszReturnData[0] = '\0';
+ }
+ }
+ else
+ {
+ ErrorF ("winClipboardFlushXEvents - SelectionNotify - "
+ "X*TextPropertyToTextList returned: ");
+ switch (iReturn)
+ {
+ case XNoMemory:
+ ErrorF ("XNoMemory\n");
+ break;
+ case XConverterNotFound:
+ ErrorF ("XConverterNotFound\n");
+ break;
+ default:
+ ErrorF ("%d", iReturn);
+ break;
+ }
+ pszReturnData = (char *) malloc (1);
+ pszReturnData[0] = '\0';
+ }
+
+ /* Free the data returned from XGetWindowProperty */
+ if (ppszTextList)
+ XFreeStringList (ppszTextList);
+ ppszTextList = NULL;
+ XFree (xtpText.value);
+ xtpText.value = NULL;
+ xtpText.nitems = 0;
+
+ /* Convert the X clipboard string to DOS format */
+ XLockDisplay (pDisplay);
+ winClipboardUNIXtoDOS ((unsigned char **)&pszReturnData, strlen (pszReturnData));
+
+ if (fUseUnicode)
+ {
+ /* Find out how much space needed to convert MBCS to Unicode */
+ iUnicodeLen = MultiByteToWideChar (CP_UTF8,
+ 0,
+ pszReturnData,
+ -1,
+ NULL,
+ 0);
+
+ /* Allocate memory for the Unicode string */
+ pwszUnicodeStr
+ = (wchar_t*) malloc (sizeof (wchar_t) * (iUnicodeLen + 1));
+ if (!pwszUnicodeStr)
+ {
+ ErrorF ("winClipboardFlushXEvents - SelectionNotify "
+ "malloc failed for pwszUnicodeStr, aborting.\n");
+
+ /* Abort */
+ fAbort = TRUE;
+ goto winClipboardFlushXEvents_SelectionNotify_Done;
+ }
+
+ /* Do the actual conversion */
+ MultiByteToWideChar (CP_UTF8,
+ 0,
+ pszReturnData,
+ -1,
+ pwszUnicodeStr,
+ iUnicodeLen);
+
+ /* Allocate global memory for the X clipboard data */
+ hGlobal = GlobalAlloc (GMEM_MOVEABLE,
+ sizeof (wchar_t) * (iUnicodeLen + 1));
+ }
+ else
+ {
+ pszConvertData = strdup (pszReturnData);
+ iConvertDataLen = strlen (pszConvertData) + 1;
+
+ /* Allocate global memory for the X clipboard data */
+ hGlobal = GlobalAlloc (GMEM_MOVEABLE, iConvertDataLen);
+ }
+
+ free (pszReturnData);
+
+ /* Check that global memory was allocated */
+ if (!hGlobal)
+ {
+ ErrorF ("winClipboardFlushXEvents - SelectionNotify "
+ "GlobalAlloc failed, aborting: %ld\n",
+ GetLastError ());
+
+ /* Abort */
+ fAbort = TRUE;
+ goto winClipboardFlushXEvents_SelectionNotify_Done;
+ }
+
+ /* Obtain a pointer to the global memory */
+ pszGlobalData = GlobalLock (hGlobal);
+ if (pszGlobalData == NULL)
+ {
+ ErrorF ("winClipboardFlushXEvents - Could not lock global "
+ "memory for clipboard transfer\n");
+
+ /* Abort */
+ fAbort = TRUE;
+ goto winClipboardFlushXEvents_SelectionNotify_Done;
+ }
+
+ /* Copy the returned string into the global memory */
+ if (fUseUnicode)
+ {
+ memcpy (pszGlobalData,
+ pwszUnicodeStr,
+ sizeof (wchar_t) * (iUnicodeLen + 1));
+ free (pwszUnicodeStr);
+ pwszUnicodeStr = NULL;
+ }
+ else
+ {
+ strcpy (pszGlobalData, pszConvertData);
+ free (pszConvertData);
+ pszConvertData = NULL;
+ }
+
+ /* Release the pointer to the global memory */
+ GlobalUnlock (hGlobal);
+ pszGlobalData = NULL;
+
+ /* Push the selection data to the Windows clipboard */
+ if (fUseUnicode)
+ SetClipboardData (CF_UNICODETEXT, hGlobal);
+ else
+ SetClipboardData (CF_TEXT, hGlobal);
+
+ /* Flag that SetClipboardData has been called */
+ fSetClipboardData = FALSE;
+
+ /*
+ * NOTE: Do not try to free pszGlobalData, it is owned by
+ * Windows after the call to SetClipboardData ().
+ */
+
+ winClipboardFlushXEvents_SelectionNotify_Done:
+ XUnlockDisplay (pDisplay);
+ /* Free allocated resources */
+ if (ppszTextList)
+ XFreeStringList (ppszTextList);
+ if (xtpText.value)
+ {
+ XFree (xtpText.value);
+ xtpText.value = NULL;
+ xtpText.nitems = 0;
+ }
+ if (pszConvertData)
+ free (pszConvertData);
+ if (pwszUnicodeStr)
+ free (pwszUnicodeStr);
+ if (hGlobal && pszGlobalData)
+ GlobalUnlock (hGlobal);
+ if (fSetClipboardData && g_fUnicodeSupport)
+ SetClipboardData (CF_UNICODETEXT, NULL);
+ if (fSetClipboardData)
+ SetClipboardData (CF_TEXT, NULL);
+ return WIN_XEVENTS_NOTIFY;
+
+ default:
+ break;
+ }
+ }
+
+ return WIN_XEVENTS_SUCCESS;
+}
diff --git a/xorg-server/hw/xwin/windialogs.c b/xorg-server/hw/xwin/windialogs.c
index 94afcd989..75a2c7c65 100644
--- a/xorg-server/hw/xwin/windialogs.c
+++ b/xorg-server/hw/xwin/windialogs.c
@@ -194,7 +194,7 @@ winInitDialog (HWND hwndDlg)
HWND hwndDesk;
RECT rc, rcDlg, rcDesk;
HICON hIcon, hIconSmall;
-
+
hwndDesk = GetParent (hwndDlg);
if (!hwndDesk || IsIconic (hwndDesk))
hwndDesk = GetDesktopWindow ();
@@ -237,22 +237,23 @@ winInitDialog (HWND hwndDlg)
if (g_hIconX) hIcon=g_hIconX;
else
#endif
- hIcon = LoadIcon (g_hInstance, MAKEINTRESOURCE(IDI_XWIN));
+ hIcon = LoadIcon (g_hInstance, MAKEINTRESOURCE(IDI_XWIN));
#ifdef XWIN_MULTIWINDOW
if (g_hSmallIconX) hIconSmall=g_hSmallIconX;
else
#endif
- hIconSmall = LoadImage (g_hInstance,
- MAKEINTRESOURCE(IDI_XWIN), IMAGE_ICON,
- GetSystemMetrics(SM_CXSMICON),
- GetSystemMetrics(SM_CYSMICON),
- LR_SHARED);
+ hIconSmall = LoadImage (g_hInstance,
+ MAKEINTRESOURCE(IDI_XWIN), IMAGE_ICON,
+ GetSystemMetrics(SM_CXSMICON),
+ GetSystemMetrics(SM_CYSMICON),
+ LR_SHARED);
PostMessage (hwndDlg, WM_SETICON, ICON_BIG, (LPARAM) hIcon);
PostMessage (hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM) hIconSmall);
}
+
/*
* Display the Exit dialog box
*/
diff --git a/xorg-server/hw/xwin/winkeybd.c b/xorg-server/hw/xwin/winkeybd.c
index 13659b24d..5d0f58442 100644
--- a/xorg-server/hw/xwin/winkeybd.c
+++ b/xorg-server/hw/xwin/winkeybd.c
@@ -265,7 +265,7 @@ winKeybdProc (DeviceIntPtr pDeviceInt, int iState)
XkbSetExtension(pDeviceInt, ProcessKeyboardEvent);
break;
- case DEVICE_ON:
+ case DEVICE_ON:
pDevice->on = TRUE;
break;
diff --git a/xorg-server/hw/xwin/winmouse.c b/xorg-server/hw/xwin/winmouse.c
index c99e9c992..3c7b46d6c 100644
--- a/xorg-server/hw/xwin/winmouse.c
+++ b/xorg-server/hw/xwin/winmouse.c
@@ -265,7 +265,7 @@ winMouseButtonsSendEvent (int iEventType, int iButton)
int
winMouseButtonsHandle (ScreenPtr pScreen,
- int iEventType, int iButton,
+ int iEventType, int iButton,
WPARAM wParam)
{
winScreenPriv(pScreen);
diff --git a/xorg-server/hw/xwin/winmultiwindowclass.c b/xorg-server/hw/xwin/winmultiwindowclass.c
index fe81f2bd0..a5cf2120a 100644
--- a/xorg-server/hw/xwin/winmultiwindowclass.c
+++ b/xorg-server/hw/xwin/winmultiwindowclass.c
@@ -1,6 +1,5 @@
/*
*Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved.
- *Copyright (C) Colin Harrison 2005-2008
*
*Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@@ -27,7 +26,6 @@
*from the XFree86 Project.
*
* Authors: Earle F. Philhower, III
- * Colin Harrison
*/
#ifdef HAVE_XWIN_CONFIG_H
diff --git a/xorg-server/hw/xwin/winmultiwindowwm.c b/xorg-server/hw/xwin/winmultiwindowwm.c
index 4c908daf9..8a05eb3fc 100644
--- a/xorg-server/hw/xwin/winmultiwindowwm.c
+++ b/xorg-server/hw/xwin/winmultiwindowwm.c
@@ -1328,7 +1328,7 @@ winInitMultiWindowWM (WMInfoPtr pWMInfo, WMProcArgPtr pProcArg)
False);
pWMInfo->atmPrivMap = XInternAtom (pWMInfo->pDisplay,
- "_WINDOWSWM_NATIVE_HWND",
+ WINDOWSWM_NATIVE_HWND,
False);
diff --git a/xorg-server/hw/xwin/winprefsyacc.c b/xorg-server/hw/xwin/winprefsyacc.c
index ccecc6e33..3ea9e96bb 100644
--- a/xorg-server/hw/xwin/winprefsyacc.c
+++ b/xorg-server/hw/xwin/winprefsyacc.c
@@ -417,14 +417,14 @@ YYID (yyi)
# endif
# ifndef YYMALLOC
# define YYMALLOC malloc
-# if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
+# if ! defined malloc && !defined _MSC_VER && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus)
void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
# endif
# endif
# ifndef YYFREE
# define YYFREE free
-# if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
+# if ! defined free && !defined _MSC_VER && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus)
void free (void *); /* INFRINGES ON USER NAME SPACE */
# endif
diff --git a/xorg-server/hw/xwin/winresource.h b/xorg-server/hw/xwin/winresource.h
index 7085117e6..5aa884030 100644
--- a/xorg-server/hw/xwin/winresource.h
+++ b/xorg-server/hw/xwin/winresource.h
@@ -37,6 +37,7 @@
#define IDC_STATIC -1
#define IDI_XWIN 101
+#define IDI_XWIN_BOXED 102
#define IDM_TRAYICON_MENU 103
#define IDC_CLIENTS_CONNECTED 104
diff --git a/xorg-server/hw/xwin/winwin32rootless.c b/xorg-server/hw/xwin/winwin32rootless.c
index d875884d9..c225a4495 100644
--- a/xorg-server/hw/xwin/winwin32rootless.c
+++ b/xorg-server/hw/xwin/winwin32rootless.c
@@ -48,6 +48,7 @@
/*
* Constant defines
*/
+
#ifndef ULW_COLORKEY
#define ULW_COLORKEY 0x00000001
#endif
diff --git a/xorg-server/hw/xwin/winwin32rootlesswndproc.c b/xorg-server/hw/xwin/winwin32rootlesswndproc.c
index 00627d218..4d7afee42 100644
--- a/xorg-server/hw/xwin/winwin32rootlesswndproc.c
+++ b/xorg-server/hw/xwin/winwin32rootlesswndproc.c
@@ -522,7 +522,16 @@ winMWExtWMWindowProc (HWND hwnd, UINT message,
#if CYGMULTIWINDOW_DEBUG && 0
winDebug ("winMWExtWMWindowProc - WM_MOUSEMOVE\n");
#endif
- winGetPtMouse(hwnd,lParam,&ptMouse);
+ /* Unpack the client area mouse coordinates */
+ ptMouse.x = GET_X_LPARAM(lParam);
+ ptMouse.y = GET_Y_LPARAM(lParam);
+
+ /* Translate the client area mouse coordinates to screen coordinates */
+ ClientToScreen (hwnd, &ptMouse);
+
+ /* Screen Coords from (-X, -Y) -> Root Window (0, 0) */
+ ptMouse.x -= GetSystemMetrics (SM_XVIRTUALSCREEN);
+ ptMouse.y -= GetSystemMetrics (SM_YVIRTUALSCREEN);
/* We can't do anything without privates */
if (pScreenPriv == NULL || pScreenInfo->fIgnoreInput)
@@ -622,7 +631,7 @@ winMWExtWMWindowProc (HWND hwnd, UINT message,
if (pScreenPriv == NULL || pScreenInfo->fIgnoreInput)
break;
SetCapture (hwnd);
- return winMouseButtonsHandle (pScreen, DeviceeButtonPress, Button1, wParam, hwnd, lParam);
+ return winMouseButtonsHandle (pScreen, ButtonPress, Button1, wParam);
case WM_LBUTTONUP:
#if CYGMULTIWINDOW_DEBUG
@@ -631,7 +640,7 @@ winMWExtWMWindowProc (HWND hwnd, UINT message,
if (pScreenPriv == NULL || pScreenInfo->fIgnoreInput)
break;
ReleaseCapture ();
- return winMouseButtonsHandle (pScreen, DeviceButtonRelease, Button1, wParam, hwnd, lParam);
+ return winMouseButtonsHandle (pScreen, ButtonRelease, Button1, wParam);
case WM_MBUTTONDBLCLK:
case WM_MBUTTONDOWN:
@@ -641,7 +650,7 @@ winMWExtWMWindowProc (HWND hwnd, UINT message,
if (pScreenPriv == NULL || pScreenInfo->fIgnoreInput)
break;
SetCapture (hwnd);
- return winMouseButtonsHandle (pScreen, DeviceButtonPress, Button2, wParam, hwnd, lParam);
+ return winMouseButtonsHandle (pScreen, ButtonPress, Button2, wParam);
case WM_MBUTTONUP:
#if CYGMULTIWINDOW_DEBUG
@@ -650,7 +659,7 @@ winMWExtWMWindowProc (HWND hwnd, UINT message,
if (pScreenPriv == NULL || pScreenInfo->fIgnoreInput)
break;
ReleaseCapture ();
- return winMouseButtonsHandle (pScreen, DeviceButtonRelease, Button2, wParam, hwnd, lParam);
+ return winMouseButtonsHandle (pScreen, ButtonRelease, Button2, wParam);
case WM_RBUTTONDBLCLK:
case WM_RBUTTONDOWN:
@@ -660,7 +669,7 @@ winMWExtWMWindowProc (HWND hwnd, UINT message,
if (pScreenPriv == NULL || pScreenInfo->fIgnoreInput)
break;
SetCapture (hwnd);
- return winMouseButtonsHandle (pScreen, DeviceButtonPress, Button3, wParam, hwnd, lParam);
+ return winMouseButtonsHandle (pScreen, ButtonPress, Button3, wParam);
case WM_RBUTTONUP:
#if CYGMULTIWINDOW_DEBUG
@@ -669,19 +678,19 @@ winMWExtWMWindowProc (HWND hwnd, UINT message,
if (pScreenPriv == NULL || pScreenInfo->fIgnoreInput)
break;
ReleaseCapture ();
- return winMouseButtonsHandle (pScreen, DeviceButtonRelease, Button3, wParam, hwnd, lParam);
+ return winMouseButtonsHandle (pScreen, ButtonRelease, Button3, wParam);
case WM_XBUTTONDBLCLK:
case WM_XBUTTONDOWN:
if (pScreenPriv == NULL || pScreenInfo->fIgnoreInput)
break;
SetCapture (hwnd);
- return winMouseButtonsHandle (pScreen, DeviceButtonPress, HIWORD(wParam) + 5, wParam, hwnd, lParam);
+ return winMouseButtonsHandle (pScreen, ButtonPress, HIWORD(wParam) + 5, wParam);
case WM_XBUTTONUP:
if (pScreenPriv == NULL || pScreenInfo->fIgnoreInput)
break;
ReleaseCapture ();
- return winMouseButtonsHandle (pScreen, DeviceButtonRelease, HIWORD(wParam) + 5, wParam, hwnd, lParam);
+ return winMouseButtonsHandle (pScreen, ButtonRelease, HIWORD(wParam) + 5, wParam);
case WM_MOUSEWHEEL:
#if CYGMULTIWINDOW_DEBUG
diff --git a/xorg-server/hw/xwin/winwndproc.c b/xorg-server/hw/xwin/winwndproc.c
index a9207f666..0399545f8 100644
--- a/xorg-server/hw/xwin/winwndproc.c
+++ b/xorg-server/hw/xwin/winwndproc.c
@@ -760,7 +760,7 @@ winWindowProc (HWND hwnd, UINT message,
g_fCursor = TRUE;
ShowCursor (TRUE);
}
-
+
/* Deliver absolute cursor position to X Server */
winEnqueueMotion(GET_X_LPARAM(lParam)-s_pScreenInfo->dwXOffset,
GET_Y_LPARAM(lParam)-s_pScreenInfo->dwYOffset);
@@ -901,15 +901,15 @@ winWindowProc (HWND hwnd, UINT message,
switch (wParam)
{
case WIN_E3B_TIMER_ID:
- /* Send delayed button press */
- winMouseButtonsSendEvent (ButtonPress,
+ /* Send delayed button press */
+ winMouseButtonsSendEvent (ButtonPress,
s_pScreenPriv->iE3BCachedPress);
- /* Kill this timer */
- KillTimer (s_pScreenPriv->hwndScreen, WIN_E3B_TIMER_ID);
+ /* Kill this timer */
+ KillTimer (s_pScreenPriv->hwndScreen, WIN_E3B_TIMER_ID);
- /* Clear screen privates flags */
- s_pScreenPriv->iE3BCachedPress = 0;
+ /* Clear screen privates flags */
+ s_pScreenPriv->iE3BCachedPress = 0;
break;
case WIN_POLLING_MOUSE_TIMER_ID:
@@ -924,7 +924,7 @@ winWindowProc (HWND hwnd, UINT message,
/* Map from screen (-X, -Y) to root (0, 0) */
point.x -= GetSystemMetrics (SM_XVIRTUALSCREEN);
point.y -= GetSystemMetrics (SM_YVIRTUALSCREEN);
-
+
/* Deliver absolute cursor position to X Server */
winEnqueueMotion(point.x , point.y);