1998-12-07 10:13:40 +01:00
|
|
|
/*
|
1999-09-03 17:17:57 +02:00
|
|
|
* X11 clipboard windows driver
|
1998-12-07 10:13:40 +01:00
|
|
|
*
|
|
|
|
* Copyright 1994 Martin Ayotte
|
|
|
|
* 1996 Alex Korobka
|
1999-09-03 17:17:57 +02:00
|
|
|
* 1999 Noel Borthwick
|
|
|
|
*
|
2002-03-10 00:29:33 +01:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
1999-09-03 17:17:57 +02:00
|
|
|
* NOTES:
|
|
|
|
* This file contains the X specific implementation for the windows
|
|
|
|
* Clipboard API.
|
|
|
|
*
|
|
|
|
* Wine's internal clipboard is exposed to external apps via the X
|
|
|
|
* selection mechanism.
|
|
|
|
* Currently the driver asserts ownership via two selection atoms:
|
|
|
|
* 1. PRIMARY(XA_PRIMARY)
|
|
|
|
* 2. CLIPBOARD
|
|
|
|
*
|
2001-05-18 23:01:38 +02:00
|
|
|
* In our implementation, the CLIPBOARD selection takes precedence over PRIMARY,
|
1999-09-03 17:17:57 +02:00
|
|
|
* i.e. if a CLIPBOARD selection is available, it is used instead of PRIMARY.
|
2001-05-18 23:01:38 +02:00
|
|
|
* When Wine takes ownership of the clipboard, it takes ownership of BOTH selections.
|
1999-09-03 17:17:57 +02:00
|
|
|
* While giving up selection ownership, if the CLIPBOARD selection is lost,
|
|
|
|
* it will lose both PRIMARY and CLIPBOARD and empty the clipboard.
|
|
|
|
* However if only PRIMARY is lost, it will continue to hold the CLIPBOARD selection
|
|
|
|
* (leaving the clipboard cache content unaffected).
|
|
|
|
*
|
|
|
|
* Every format exposed via a windows clipboard format is also exposed through
|
|
|
|
* a corresponding X selection target. A selection target atom is synthesized
|
|
|
|
* whenever a new Windows clipboard format is registered via RegisterClipboardFormat,
|
2001-05-18 23:01:38 +02:00
|
|
|
* or when a built-in format is used for the first time.
|
1999-09-03 17:17:57 +02:00
|
|
|
* Windows native format are exposed by prefixing the format name with "<WCF>"
|
|
|
|
* This allows us to uniquely identify windows native formats exposed by other
|
|
|
|
* running WINE apps.
|
|
|
|
*
|
|
|
|
* In order to allow external applications to query WINE for supported formats,
|
|
|
|
* we respond to the "TARGETS" selection target. (See EVENT_SelectionRequest
|
|
|
|
* for implementation) We use the same mechanism to query external clients for
|
2001-05-18 23:01:38 +02:00
|
|
|
* availability of a particular format, by caching the list of available targets
|
1999-09-03 17:17:57 +02:00
|
|
|
* by using the clipboard cache's "delayed render" mechanism. If a selection client
|
|
|
|
* does not support the "TARGETS" selection target, we actually attempt to retrieve
|
|
|
|
* the format requested as a fallback mechanism.
|
|
|
|
*
|
|
|
|
* Certain Windows native formats are automatically converted to X native formats
|
|
|
|
* and vice versa. If a native format is available in the selection, it takes
|
|
|
|
* precedence, in order to avoid unnecessary conversions.
|
|
|
|
*
|
1998-12-07 10:13:40 +01:00
|
|
|
*/
|
|
|
|
|
2001-11-06 21:57:11 +01:00
|
|
|
#include "config.h"
|
1998-12-07 10:13:40 +01:00
|
|
|
|
1999-09-03 17:17:57 +02:00
|
|
|
#include <string.h>
|
2000-02-10 20:03:02 +01:00
|
|
|
#include <stdio.h>
|
2000-11-01 04:11:12 +01:00
|
|
|
#include <stdlib.h>
|
1999-10-24 22:22:24 +02:00
|
|
|
#include <unistd.h>
|
1999-11-07 06:12:43 +01:00
|
|
|
#include <fcntl.h>
|
1999-10-24 22:22:24 +02:00
|
|
|
|
2001-11-06 21:57:11 +01:00
|
|
|
#include "ts_xlib.h"
|
2001-06-19 05:32:44 +02:00
|
|
|
#include "winreg.h"
|
1998-12-07 10:13:40 +01:00
|
|
|
#include "clipboard.h"
|
|
|
|
#include "win.h"
|
|
|
|
#include "x11drv.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
1998-12-07 10:13:40 +01:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(clipboard);
|
1999-04-19 16:56:29 +02:00
|
|
|
|
1999-09-03 17:17:57 +02:00
|
|
|
/* Selection masks */
|
|
|
|
|
|
|
|
#define S_NOSELECTION 0
|
|
|
|
#define S_PRIMARY 1
|
|
|
|
#define S_CLIPBOARD 2
|
|
|
|
|
|
|
|
/* X selection context info */
|
|
|
|
|
|
|
|
static char _CLIPBOARD[] = "CLIPBOARD"; /* CLIPBOARD atom name */
|
|
|
|
static char FMT_PREFIX[] = "<WCF>"; /* Prefix for windows specific formats */
|
1999-10-24 22:22:24 +02:00
|
|
|
static int selectionAcquired = 0; /* Contains the current selection masks */
|
1999-09-03 17:17:57 +02:00
|
|
|
static Window selectionWindow = None; /* The top level X window which owns the selection */
|
|
|
|
static Window selectionPrevWindow = None; /* The last X window that owned the selection */
|
|
|
|
static Window PrimarySelectionOwner = None; /* The window which owns the primary selection */
|
|
|
|
static Window ClipboardSelectionOwner = None; /* The window which owns the clipboard selection */
|
|
|
|
static unsigned long cSelectionTargets = 0; /* Number of target formats reported by TARGETS selection */
|
|
|
|
static Atom selectionCacheSrc = XA_PRIMARY; /* The selection source from which the clipboard cache was filled */
|
1999-11-28 21:31:04 +01:00
|
|
|
static HANDLE selectionClearEvent = 0;/* Synchronization object used to block until server is started */
|
1998-12-07 10:13:40 +01:00
|
|
|
|
2000-01-26 03:21:30 +01:00
|
|
|
typedef struct tagPROPERTY
|
|
|
|
{
|
|
|
|
struct tagPROPERTY *next;
|
|
|
|
Atom atom;
|
|
|
|
Pixmap pixmap;
|
|
|
|
} PROPERTY;
|
1999-09-20 17:42:47 +02:00
|
|
|
|
2000-01-26 03:21:30 +01:00
|
|
|
static PROPERTY *prop_head;
|
1999-09-20 17:42:47 +02:00
|
|
|
|
1998-12-07 10:13:40 +01:00
|
|
|
|
|
|
|
/**************************************************************************
|
1999-09-20 17:42:47 +02:00
|
|
|
* X11DRV_CLIPBOARD_MapPropertyToFormat
|
1998-12-07 10:13:40 +01:00
|
|
|
*
|
1999-09-03 17:17:57 +02:00
|
|
|
* Map an X selection property type atom name to a windows clipboard format ID
|
1998-12-07 10:13:40 +01:00
|
|
|
*/
|
1999-09-03 17:17:57 +02:00
|
|
|
UINT X11DRV_CLIPBOARD_MapPropertyToFormat(char *itemFmtName)
|
1998-12-07 10:13:40 +01:00
|
|
|
{
|
1999-09-03 17:17:57 +02:00
|
|
|
/*
|
|
|
|
* If the property name starts with FMT_PREFIX strip this off and
|
|
|
|
* get the ID for a custom Windows registered format with this name.
|
|
|
|
* We can also understand STRING, PIXMAP and BITMAP.
|
|
|
|
*/
|
|
|
|
if ( NULL == itemFmtName )
|
|
|
|
return 0;
|
|
|
|
else if ( 0 == strncmp(itemFmtName, FMT_PREFIX, strlen(FMT_PREFIX)) )
|
|
|
|
return RegisterClipboardFormatA(itemFmtName + strlen(FMT_PREFIX));
|
|
|
|
else if ( 0 == strcmp(itemFmtName, "STRING") )
|
2000-12-11 02:09:56 +01:00
|
|
|
return CF_UNICODETEXT;
|
1999-09-20 17:42:47 +02:00
|
|
|
else if ( 0 == strcmp(itemFmtName, "PIXMAP")
|
|
|
|
|| 0 == strcmp(itemFmtName, "BITMAP") )
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Return CF_DIB as first preference, if WINE is the selection owner
|
|
|
|
* and if CF_DIB exists in the cache.
|
|
|
|
* If wine dowsn't own the selection we always return CF_DIB
|
|
|
|
*/
|
2000-08-10 03:16:19 +02:00
|
|
|
if ( !X11DRV_IsSelectionOwner() )
|
1999-09-20 17:42:47 +02:00
|
|
|
return CF_DIB;
|
|
|
|
else if ( CLIPBOARD_IsPresent(CF_DIB) )
|
|
|
|
return CF_DIB;
|
|
|
|
else
|
|
|
|
return CF_BITMAP;
|
|
|
|
}
|
1999-09-03 17:17:57 +02:00
|
|
|
|
|
|
|
WARN("\tNo mapping to Windows clipboard format for property %s\n", itemFmtName);
|
|
|
|
return 0;
|
|
|
|
}
|
1998-12-07 10:13:40 +01:00
|
|
|
|
1999-09-03 17:17:57 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* X11DRV_CLIPBOARD_MapFormatToProperty
|
|
|
|
*
|
|
|
|
* Map a windows clipboard format ID to an X selection property atom
|
|
|
|
*/
|
|
|
|
Atom X11DRV_CLIPBOARD_MapFormatToProperty(UINT wFormat)
|
|
|
|
{
|
|
|
|
Atom prop = None;
|
|
|
|
|
|
|
|
switch (wFormat)
|
1998-12-07 10:13:40 +01:00
|
|
|
{
|
2000-12-11 02:09:56 +01:00
|
|
|
/* We support only CF_UNICODETEXT, other formats are synthesized */
|
1999-09-03 17:17:57 +02:00
|
|
|
case CF_OEMTEXT:
|
|
|
|
case CF_TEXT:
|
2000-12-11 02:09:56 +01:00
|
|
|
return None;
|
|
|
|
|
|
|
|
case CF_UNICODETEXT:
|
1999-09-03 17:17:57 +02:00
|
|
|
prop = XA_STRING;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CF_DIB:
|
|
|
|
case CF_BITMAP:
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Request a PIXMAP, only if WINE is NOT the selection owner,
|
|
|
|
* AND the requested format is not in the cache.
|
|
|
|
*/
|
2000-08-10 03:16:19 +02:00
|
|
|
if ( !X11DRV_IsSelectionOwner() && !CLIPBOARD_IsPresent(wFormat) )
|
1999-09-03 17:17:57 +02:00
|
|
|
{
|
|
|
|
prop = XA_PIXMAP;
|
|
|
|
break;
|
|
|
|
}
|
2001-08-21 19:07:17 +02:00
|
|
|
/* Fall through to the default case in order to use the native format */
|
1999-09-03 17:17:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* If an X atom is registered for this format, return that
|
|
|
|
* Otherwise register a new atom.
|
|
|
|
*/
|
|
|
|
char str[256];
|
|
|
|
char *fmtName = CLIPBOARD_GetFormatName(wFormat);
|
|
|
|
strcpy(str, FMT_PREFIX);
|
|
|
|
|
|
|
|
if (fmtName)
|
|
|
|
{
|
|
|
|
strncat(str, fmtName, sizeof(str) - strlen(FMT_PREFIX));
|
2001-05-16 21:52:29 +02:00
|
|
|
prop = TSXInternAtom(thread_display(), str, False);
|
1999-09-03 17:17:57 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1998-12-07 10:13:40 +01:00
|
|
|
|
1999-09-03 17:17:57 +02:00
|
|
|
if (prop == None)
|
|
|
|
TRACE("\tNo mapping to X property for Windows clipboard format %d(%s)\n",
|
|
|
|
wFormat, CLIPBOARD_GetFormatName(wFormat));
|
|
|
|
|
|
|
|
return prop;
|
|
|
|
}
|
1998-12-07 10:13:40 +01:00
|
|
|
|
1999-09-03 17:17:57 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* X11DRV_CLIPBOARD_IsNativeProperty
|
|
|
|
*
|
2000-12-23 00:26:18 +01:00
|
|
|
* Checks if a property is a native Wine property type
|
1999-09-03 17:17:57 +02:00
|
|
|
*/
|
|
|
|
BOOL X11DRV_CLIPBOARD_IsNativeProperty(Atom prop)
|
|
|
|
{
|
2001-05-16 21:52:29 +02:00
|
|
|
char *itemFmtName = TSXGetAtomName(thread_display(), prop);
|
1999-09-03 17:17:57 +02:00
|
|
|
BOOL bRet = FALSE;
|
|
|
|
|
|
|
|
if ( 0 == strncmp(itemFmtName, FMT_PREFIX, strlen(FMT_PREFIX)) )
|
|
|
|
bRet = TRUE;
|
|
|
|
|
|
|
|
TSXFree(itemFmtName);
|
|
|
|
return bRet;
|
|
|
|
}
|
1998-12-07 10:13:40 +01:00
|
|
|
|
1999-09-20 17:42:47 +02:00
|
|
|
|
1999-10-24 22:22:24 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* X11DRV_CLIPBOARD_LaunchServer
|
|
|
|
* Launches the clipboard server. This is called from X11DRV_CLIPBOARD_ResetOwner
|
|
|
|
* when the selection can no longer be recyled to another top level window.
|
|
|
|
* In order to make the selection persist after Wine shuts down a server
|
|
|
|
* process is launched which services subsequent selection requests.
|
|
|
|
*/
|
|
|
|
BOOL X11DRV_CLIPBOARD_LaunchServer()
|
|
|
|
{
|
|
|
|
int iWndsLocks;
|
2001-06-19 05:32:44 +02:00
|
|
|
char clearSelection[8] = "0";
|
|
|
|
int persistent_selection = 1;
|
|
|
|
HKEY hkey;
|
2002-04-06 02:41:43 +02:00
|
|
|
int fd[2], err;
|
1999-10-24 22:22:24 +02:00
|
|
|
|
|
|
|
/* If persistant selection has been disabled in the .winerc Clipboard section,
|
|
|
|
* don't launch the server
|
|
|
|
*/
|
2001-06-19 05:32:44 +02:00
|
|
|
if(!RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\Clipboard", &hkey))
|
|
|
|
{
|
|
|
|
char buffer[20];
|
|
|
|
DWORD type, count = sizeof(buffer);
|
|
|
|
if(!RegQueryValueExA(hkey, "PersistentSelection", 0, &type, buffer, &count))
|
|
|
|
persistent_selection = atoi(buffer);
|
|
|
|
|
|
|
|
/* Get the clear selection preference */
|
|
|
|
count = sizeof(clearSelection);
|
|
|
|
RegQueryValueExA(hkey, "ClearAllSelections", 0, &type, clearSelection, &count);
|
|
|
|
RegCloseKey(hkey);
|
|
|
|
}
|
|
|
|
if ( !persistent_selection )
|
1999-10-24 22:22:24 +02:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* Start up persistant WINE X clipboard server process which will
|
|
|
|
* take ownership of the X selection and continue to service selection
|
|
|
|
* requests from other apps.
|
|
|
|
*/
|
2002-04-06 02:41:43 +02:00
|
|
|
|
|
|
|
if(pipe(fd) == -1) return FALSE;
|
|
|
|
fcntl(fd[1], F_SETFD, 1); /* set close on exec */
|
|
|
|
|
1999-10-24 22:22:24 +02:00
|
|
|
selectionWindow = selectionPrevWindow;
|
|
|
|
if ( !fork() )
|
|
|
|
{
|
|
|
|
/* NOTE: This code only executes in the context of the child process
|
|
|
|
* Do note make any Wine specific calls here.
|
|
|
|
*/
|
|
|
|
int dbgClasses = 0;
|
2001-05-16 21:52:29 +02:00
|
|
|
char selMask[8], dbgClassMask[8];
|
1999-10-24 22:22:24 +02:00
|
|
|
|
2002-04-06 02:41:43 +02:00
|
|
|
close(fd[0]);
|
1999-10-24 22:22:24 +02:00
|
|
|
sprintf(selMask, "%d", selectionAcquired);
|
|
|
|
|
|
|
|
/* Build the debug class mask to pass to the server, by inheriting
|
|
|
|
* the settings for the clipboard debug channel.
|
|
|
|
*/
|
2000-02-10 20:03:02 +01:00
|
|
|
dbgClasses |= FIXME_ON(clipboard) ? 1 : 0;
|
|
|
|
dbgClasses |= ERR_ON(clipboard) ? 2 : 0;
|
|
|
|
dbgClasses |= WARN_ON(clipboard) ? 4 : 0;
|
|
|
|
dbgClasses |= TRACE_ON(clipboard) ? 8 : 0;
|
1999-10-24 22:22:24 +02:00
|
|
|
sprintf(dbgClassMask, "%d", dbgClasses);
|
|
|
|
|
|
|
|
/* Exec the clipboard server passing it the selection and debug class masks */
|
1999-11-07 06:12:43 +01:00
|
|
|
execl( BINDIR "/wineclipsrv", "wineclipsrv",
|
1999-10-24 22:22:24 +02:00
|
|
|
selMask, dbgClassMask, clearSelection, NULL );
|
1999-11-07 06:12:43 +01:00
|
|
|
execlp( "wineclipsrv", "wineclipsrv", selMask, dbgClassMask, clearSelection, NULL );
|
|
|
|
execl( "./windows/x11drv/wineclipsrv", "wineclipsrv",
|
1999-10-24 22:22:24 +02:00
|
|
|
selMask, dbgClassMask, clearSelection, NULL );
|
|
|
|
|
|
|
|
/* Exec Failed! */
|
|
|
|
perror("Could not start Wine clipboard server");
|
2002-04-06 02:41:43 +02:00
|
|
|
write(fd[1], &err, sizeof(err));
|
|
|
|
_exit( 1 ); /* Exit the child process */
|
|
|
|
}
|
|
|
|
close(fd[1]);
|
|
|
|
|
|
|
|
if(read(fd[0], &err, sizeof(err)) > 0) { /* exec failed */
|
|
|
|
close(fd[0]);
|
|
|
|
return FALSE;
|
1999-10-24 22:22:24 +02:00
|
|
|
}
|
2002-04-06 02:41:43 +02:00
|
|
|
close(fd[0]);
|
1999-10-24 22:22:24 +02:00
|
|
|
|
|
|
|
/* Wait until the clipboard server acquires the selection.
|
|
|
|
* We must release the windows lock to enable Wine to process
|
|
|
|
* selection messages in response to the servers requests.
|
|
|
|
*/
|
|
|
|
|
|
|
|
iWndsLocks = WIN_SuspendWndsLock();
|
|
|
|
|
|
|
|
/* We must wait until the server finishes acquiring the selection,
|
|
|
|
* before proceeding, otherwise the window which owns the selection
|
|
|
|
* will be destroyed prematurely!
|
|
|
|
* Create a non-signalled, auto-reset event which will be set by
|
|
|
|
* X11DRV_CLIPBOARD_ReleaseSelection, and wait until this gets
|
|
|
|
* signalled before proceeding.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ( !(selectionClearEvent = CreateEventA(NULL, FALSE, FALSE, NULL)) )
|
|
|
|
ERR("Could not create wait object. Clipboard server won't start!\n");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Wait until we lose the selection, timing out after a minute */
|
2001-10-08 22:28:36 +02:00
|
|
|
DWORD start_time, timeout, elapsed, ret;
|
1999-10-24 22:22:24 +02:00
|
|
|
|
|
|
|
TRACE("Waiting for clipboard server to acquire selection\n");
|
|
|
|
|
2001-10-08 22:28:36 +02:00
|
|
|
timeout = 60000;
|
|
|
|
start_time = GetTickCount();
|
|
|
|
elapsed=0;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
ret = MsgWaitForMultipleObjects( 1, &selectionClearEvent, FALSE, timeout - elapsed, QS_ALLINPUT );
|
|
|
|
if (ret != WAIT_OBJECT_0+1)
|
|
|
|
break;
|
|
|
|
elapsed = GetTickCount() - start_time;
|
|
|
|
if (elapsed > timeout)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
while (1);
|
|
|
|
if ( ret != WAIT_OBJECT_0 )
|
2000-11-01 04:11:12 +01:00
|
|
|
TRACE("Server could not acquire selection, or a timeout occurred!\n");
|
1999-10-24 22:22:24 +02:00
|
|
|
else
|
|
|
|
TRACE("Server successfully acquired selection\n");
|
|
|
|
|
|
|
|
/* Release the event */
|
|
|
|
CloseHandle(selectionClearEvent);
|
1999-11-28 21:31:04 +01:00
|
|
|
selectionClearEvent = 0;
|
1999-10-24 22:22:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
WIN_RestoreWndsLock(iWndsLocks);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-09-03 17:17:57 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* X11DRV_CLIPBOARD_CacheDataFormats
|
|
|
|
*
|
|
|
|
* Caches the list of data formats available from the current selection.
|
|
|
|
* This queries the selection owner for the TARGETS property and saves all
|
|
|
|
* reported property types.
|
|
|
|
*/
|
|
|
|
int X11DRV_CLIPBOARD_CacheDataFormats( Atom SelectionName )
|
|
|
|
{
|
2001-05-16 21:52:29 +02:00
|
|
|
Display *display = thread_display();
|
1999-11-28 21:31:04 +01:00
|
|
|
HWND hWnd = 0;
|
1999-09-03 17:17:57 +02:00
|
|
|
HWND hWndClipWindow = GetOpenClipboardWindow();
|
|
|
|
XEvent xe;
|
|
|
|
Atom aTargets;
|
|
|
|
Atom atype=AnyPropertyType;
|
|
|
|
int aformat;
|
|
|
|
unsigned long remain;
|
|
|
|
Atom* targetList=NULL;
|
|
|
|
Window w;
|
1999-11-28 21:31:04 +01:00
|
|
|
Window ownerSelection = 0;
|
1999-09-03 17:17:57 +02:00
|
|
|
|
2000-12-23 00:26:18 +01:00
|
|
|
TRACE("enter\n");
|
1999-09-03 17:17:57 +02:00
|
|
|
/*
|
|
|
|
* Empty the clipboard cache
|
|
|
|
*/
|
|
|
|
CLIPBOARD_EmptyCache(TRUE);
|
|
|
|
|
|
|
|
cSelectionTargets = 0;
|
|
|
|
selectionCacheSrc = SelectionName;
|
|
|
|
|
|
|
|
hWnd = (hWndClipWindow) ? hWndClipWindow : GetActiveWindow();
|
|
|
|
|
|
|
|
ownerSelection = TSXGetSelectionOwner(display, SelectionName);
|
|
|
|
if ( !hWnd || (ownerSelection == None) )
|
|
|
|
return cSelectionTargets;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Query the selection owner for the TARGETS property
|
|
|
|
*/
|
2001-08-24 02:26:59 +02:00
|
|
|
w = X11DRV_get_whole_window( GetAncestor(hWnd,GA_ROOT) );
|
1999-09-03 17:17:57 +02:00
|
|
|
|
|
|
|
aTargets = TSXInternAtom(display, "TARGETS", False);
|
|
|
|
|
|
|
|
TRACE("Requesting TARGETS selection for '%s' (owner=%08x)...\n",
|
|
|
|
TSXGetAtomName(display, selectionCacheSrc), (unsigned)ownerSelection );
|
2001-01-15 23:31:24 +01:00
|
|
|
wine_tsx11_lock();
|
1999-09-03 17:17:57 +02:00
|
|
|
XConvertSelection(display, selectionCacheSrc, aTargets,
|
|
|
|
TSXInternAtom(display, "SELECTION_DATA", False),
|
|
|
|
w, CurrentTime);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait until SelectionNotify is received
|
|
|
|
*/
|
|
|
|
while( TRUE )
|
|
|
|
{
|
|
|
|
if( XCheckTypedWindowEvent(display, w, SelectionNotify, &xe) )
|
|
|
|
if( xe.xselection.selection == selectionCacheSrc )
|
|
|
|
break;
|
|
|
|
}
|
2001-01-15 23:31:24 +01:00
|
|
|
wine_tsx11_unlock();
|
1999-09-03 17:17:57 +02:00
|
|
|
|
|
|
|
/* Verify that the selection returned a valid TARGETS property */
|
|
|
|
if ( (xe.xselection.target != aTargets)
|
|
|
|
|| (xe.xselection.property == None) )
|
|
|
|
{
|
2000-12-23 00:26:18 +01:00
|
|
|
TRACE("\tExit, could not retrieve TARGETS\n");
|
1999-09-03 17:17:57 +02:00
|
|
|
return cSelectionTargets;
|
1998-12-07 10:13:40 +01:00
|
|
|
}
|
1999-09-03 17:17:57 +02:00
|
|
|
|
|
|
|
/* Read the TARGETS property contents */
|
|
|
|
if(TSXGetWindowProperty(display, xe.xselection.requestor, xe.xselection.property,
|
1999-09-20 17:42:47 +02:00
|
|
|
0, 0x3FFF, True, AnyPropertyType/*XA_ATOM*/, &atype, &aformat,
|
1999-09-03 17:17:57 +02:00
|
|
|
&cSelectionTargets, &remain, (unsigned char**)&targetList) != Success)
|
|
|
|
TRACE("\tCouldn't read TARGETS property\n");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TRACE("\tType %s,Format %d,nItems %ld, Remain %ld\n",
|
|
|
|
TSXGetAtomName(display,atype),aformat,cSelectionTargets, remain);
|
|
|
|
/*
|
|
|
|
* The TARGETS property should have returned us a list of atoms
|
|
|
|
* corresponding to each selection target format supported.
|
|
|
|
*/
|
1999-09-20 17:42:47 +02:00
|
|
|
if( (atype == XA_ATOM || atype == aTargets) && aformat == 32 )
|
1999-09-03 17:17:57 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
LPWINE_CLIPFORMAT lpFormat;
|
|
|
|
|
|
|
|
/* Cache these formats in the clipboard cache */
|
|
|
|
|
|
|
|
for (i = 0; i < cSelectionTargets; i++)
|
|
|
|
{
|
|
|
|
char *itemFmtName = TSXGetAtomName(display, targetList[i]);
|
|
|
|
UINT wFormat = X11DRV_CLIPBOARD_MapPropertyToFormat(itemFmtName);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the clipboard format maps to a Windows format, simply store
|
|
|
|
* the atom identifier and record its availablity status
|
|
|
|
* in the clipboard cache.
|
|
|
|
*/
|
|
|
|
if (wFormat)
|
|
|
|
{
|
|
|
|
lpFormat = CLIPBOARD_LookupFormat( wFormat );
|
|
|
|
|
1999-09-20 17:42:47 +02:00
|
|
|
/* Don't replace if the property already cached is a native format,
|
|
|
|
* or if a PIXMAP is being replaced by a BITMAP.
|
|
|
|
*/
|
|
|
|
if (lpFormat->wDataPresent &&
|
|
|
|
( X11DRV_CLIPBOARD_IsNativeProperty(lpFormat->drvData)
|
|
|
|
|| (lpFormat->drvData == XA_PIXMAP && targetList[i] == XA_BITMAP) )
|
|
|
|
)
|
1999-09-03 17:17:57 +02:00
|
|
|
{
|
|
|
|
TRACE("\tAtom# %d: '%s' --> FormatID(%d) %s (Skipped)\n",
|
|
|
|
i, itemFmtName, wFormat, lpFormat->Name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
lpFormat->wDataPresent = 1;
|
|
|
|
lpFormat->drvData = targetList[i];
|
|
|
|
TRACE("\tAtom# %d: '%s' --> FormatID(%d) %s\n",
|
|
|
|
i, itemFmtName, wFormat, lpFormat->Name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TSXFree(itemFmtName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Free the list of targets */
|
|
|
|
TSXFree(targetList);
|
|
|
|
}
|
2000-12-23 00:26:18 +01:00
|
|
|
|
1999-09-03 17:17:57 +02:00
|
|
|
return cSelectionTargets;
|
1998-12-07 10:13:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* X11DRV_CLIPBOARD_ReadSelection
|
1999-09-03 17:17:57 +02:00
|
|
|
* Reads the contents of the X selection property into the WINE clipboard cache
|
|
|
|
* converting the selection into a format compatible with the windows clipboard
|
|
|
|
* if possible.
|
|
|
|
* This method is invoked only to read the contents of a the selection owned
|
|
|
|
* by an external application. i.e. when we do not own the X selection.
|
1998-12-07 10:13:40 +01:00
|
|
|
*/
|
1999-09-20 17:42:47 +02:00
|
|
|
static BOOL X11DRV_CLIPBOARD_ReadSelection(UINT wFormat, Window w, Atom prop, Atom reqType)
|
1998-12-07 10:13:40 +01:00
|
|
|
{
|
2001-05-16 21:52:29 +02:00
|
|
|
Display *display = thread_display();
|
1999-09-03 17:17:57 +02:00
|
|
|
Atom atype=AnyPropertyType;
|
|
|
|
int aformat;
|
2001-02-23 02:31:47 +01:00
|
|
|
unsigned long total,nitems,remain,itemSize,val_cnt;
|
|
|
|
long lRequestLength,bwc;
|
|
|
|
unsigned char* val;
|
|
|
|
unsigned char* buffer;
|
1999-09-03 17:17:57 +02:00
|
|
|
LPWINE_CLIPFORMAT lpFormat;
|
|
|
|
BOOL bRet = FALSE;
|
|
|
|
HWND hWndClipWindow = GetOpenClipboardWindow();
|
1999-09-20 17:42:47 +02:00
|
|
|
|
1999-09-03 17:17:57 +02:00
|
|
|
|
|
|
|
if(prop == None)
|
|
|
|
return bRet;
|
1998-12-07 10:13:40 +01:00
|
|
|
|
1999-07-04 18:02:24 +02:00
|
|
|
TRACE("Reading X selection...\n");
|
1998-12-07 10:13:40 +01:00
|
|
|
|
1999-09-20 17:42:47 +02:00
|
|
|
TRACE("\tretrieving property %s from window %ld into %s\n",
|
|
|
|
TSXGetAtomName(display,reqType), (long)w, TSXGetAtomName(display,prop) );
|
1998-12-07 10:13:40 +01:00
|
|
|
|
1999-09-03 17:17:57 +02:00
|
|
|
/*
|
|
|
|
* First request a zero length in order to figure out the request size.
|
|
|
|
*/
|
1999-09-20 17:42:47 +02:00
|
|
|
if(TSXGetWindowProperty(display,w,prop,0,0,False, AnyPropertyType/*reqType*/,
|
1999-09-03 17:17:57 +02:00
|
|
|
&atype, &aformat, &nitems, &itemSize, &val) != Success)
|
|
|
|
{
|
|
|
|
WARN("\tcouldn't get property size\n");
|
|
|
|
return bRet;
|
|
|
|
}
|
1999-09-20 17:42:47 +02:00
|
|
|
|
|
|
|
/* Free zero length return data if any */
|
1999-09-03 17:17:57 +02:00
|
|
|
if ( val )
|
|
|
|
{
|
|
|
|
TSXFree(val);
|
|
|
|
val = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("\tretrieving %ld bytes...\n", itemSize * aformat/8);
|
|
|
|
lRequestLength = (itemSize * aformat/8)/4 + 1;
|
2001-02-23 02:31:47 +01:00
|
|
|
|
|
|
|
bwc = aformat/8;
|
|
|
|
/* we want to read the property, but not it too large of chunks or
|
|
|
|
we could hang the cause problems. Lets go for 4k blocks */
|
|
|
|
|
|
|
|
if(TSXGetWindowProperty(display,w,prop,0,4096,False,
|
|
|
|
AnyPropertyType/*reqType*/,
|
|
|
|
&atype, &aformat, &nitems, &remain, &buffer)
|
|
|
|
!= Success)
|
1999-09-03 17:17:57 +02:00
|
|
|
{
|
|
|
|
WARN("\tcouldn't read property\n");
|
|
|
|
return bRet;
|
|
|
|
}
|
2001-02-23 02:31:47 +01:00
|
|
|
val = (char*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,
|
|
|
|
nitems*bwc);
|
|
|
|
memcpy(val,buffer,nitems*bwc);
|
|
|
|
TSXFree(buffer);
|
|
|
|
|
|
|
|
for (total = nitems*bwc,val_cnt=0; remain;)
|
|
|
|
{
|
|
|
|
val_cnt +=nitems*bwc;
|
|
|
|
TSXGetWindowProperty(display, w, prop,
|
|
|
|
(total / 4), 4096, False,
|
|
|
|
AnyPropertyType, &atype,
|
|
|
|
&aformat, &nitems, &remain,
|
|
|
|
&buffer);
|
|
|
|
|
|
|
|
total += nitems*bwc;
|
|
|
|
HeapReAlloc(GetProcessHeap(),0,val, total);
|
|
|
|
memcpy(&val[val_cnt], buffer, nitems*(aformat/8));
|
|
|
|
TSXFree(buffer);
|
|
|
|
}
|
|
|
|
nitems = total;
|
1998-12-07 10:13:40 +01:00
|
|
|
|
1999-09-03 17:17:57 +02:00
|
|
|
/*
|
|
|
|
* Translate the X property into the appropriate Windows clipboard
|
|
|
|
* format, if possible.
|
|
|
|
*/
|
1999-09-20 17:42:47 +02:00
|
|
|
if ( (reqType == XA_STRING)
|
2000-12-11 02:09:56 +01:00
|
|
|
&& (atype == XA_STRING) && (aformat == 8) )
|
|
|
|
/* convert Unix text to CF_UNICODETEXT */
|
1999-09-03 17:17:57 +02:00
|
|
|
{
|
|
|
|
int i,inlcount = 0;
|
|
|
|
char* lpstr;
|
|
|
|
|
|
|
|
for(i=0; i <= nitems; i++)
|
|
|
|
if( val[i] == '\n' ) inlcount++;
|
|
|
|
|
2000-12-11 02:09:56 +01:00
|
|
|
if( (lpstr = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, nitems + inlcount + 1)) )
|
|
|
|
{
|
|
|
|
static UINT text_cp = (UINT)-1;
|
|
|
|
UINT count;
|
|
|
|
HANDLE hUnicodeText;
|
|
|
|
|
1999-09-03 17:17:57 +02:00
|
|
|
for(i=0,inlcount=0; i <= nitems; i++)
|
|
|
|
{
|
|
|
|
if( val[i] == '\n' ) lpstr[inlcount++]='\r';
|
|
|
|
lpstr[inlcount++]=val[i];
|
|
|
|
}
|
2000-12-11 02:09:56 +01:00
|
|
|
|
|
|
|
if(text_cp == (UINT)-1)
|
2001-06-19 05:32:44 +02:00
|
|
|
{
|
|
|
|
HKEY hkey;
|
|
|
|
/* default value */
|
|
|
|
text_cp = CP_ACP;
|
|
|
|
if(!RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\x11drv", &hkey))
|
|
|
|
{
|
|
|
|
char buf[20];
|
|
|
|
DWORD type, count = sizeof(buf);
|
|
|
|
if(!RegQueryValueExA(hkey, "TextCP", 0, &type, buf, &count))
|
|
|
|
text_cp = atoi(buf);
|
|
|
|
RegCloseKey(hkey);
|
|
|
|
}
|
|
|
|
}
|
2000-12-11 02:09:56 +01:00
|
|
|
|
|
|
|
count = MultiByteToWideChar(text_cp, 0, lpstr, -1, NULL, 0);
|
|
|
|
hUnicodeText = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, count * sizeof(WCHAR));
|
|
|
|
if(hUnicodeText)
|
|
|
|
{
|
|
|
|
WCHAR *textW = GlobalLock(hUnicodeText);
|
|
|
|
MultiByteToWideChar(text_cp, 0, lpstr, -1, textW, count);
|
|
|
|
GlobalUnlock(hUnicodeText);
|
2001-02-23 02:31:47 +01:00
|
|
|
if (!SetClipboardData(CF_UNICODETEXT, hUnicodeText))
|
|
|
|
{
|
|
|
|
ERR("Not SET! Need to free our own block\n");
|
|
|
|
GlobalFree(hUnicodeText);
|
|
|
|
}
|
2000-12-11 02:09:56 +01:00
|
|
|
bRet = TRUE;
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpstr);
|
1999-09-03 17:17:57 +02:00
|
|
|
}
|
|
|
|
}
|
1999-09-20 17:42:47 +02:00
|
|
|
else if ( reqType == XA_PIXMAP || reqType == XA_BITMAP ) /* treat PIXMAP as CF_DIB or CF_BITMAP */
|
1999-09-03 17:17:57 +02:00
|
|
|
{
|
1999-09-20 17:42:47 +02:00
|
|
|
/* Get the first pixmap handle passed to us */
|
|
|
|
Pixmap *pPixmap = (Pixmap *)val;
|
1999-11-28 21:31:04 +01:00
|
|
|
HANDLE hTargetImage = 0; /* Handle to store the converted bitmap or DIB */
|
1999-09-20 17:42:47 +02:00
|
|
|
|
|
|
|
if (aformat != 32 || nitems < 1 || atype != XA_PIXMAP
|
|
|
|
|| (wFormat != CF_BITMAP && wFormat != CF_DIB))
|
|
|
|
{
|
|
|
|
WARN("\tUnimplemented format conversion request\n");
|
|
|
|
goto END;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( wFormat == CF_BITMAP )
|
|
|
|
{
|
|
|
|
/* For CF_BITMAP requests we must return an HBITMAP */
|
|
|
|
hTargetImage = X11DRV_BITMAP_CreateBitmapFromPixmap(*pPixmap, TRUE);
|
|
|
|
}
|
|
|
|
else if (wFormat == CF_DIB)
|
|
|
|
{
|
|
|
|
HWND hwnd = GetOpenClipboardWindow();
|
|
|
|
HDC hdc = GetDC(hwnd);
|
|
|
|
|
|
|
|
/* For CF_DIB requests we must return an HGLOBAL storing a packed DIB */
|
|
|
|
hTargetImage = X11DRV_DIB_CreateDIBFromPixmap(*pPixmap, hdc, TRUE);
|
|
|
|
|
2001-09-19 22:34:17 +02:00
|
|
|
ReleaseDC(hwnd, hdc);
|
1999-09-20 17:42:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!hTargetImage)
|
|
|
|
{
|
|
|
|
WARN("PIXMAP conversion failed!\n" );
|
|
|
|
goto END;
|
|
|
|
}
|
2000-12-11 02:09:56 +01:00
|
|
|
|
1999-09-20 17:42:47 +02:00
|
|
|
/* Delete previous clipboard data */
|
|
|
|
lpFormat = CLIPBOARD_LookupFormat(wFormat);
|
|
|
|
if (lpFormat->wDataPresent && (lpFormat->hData16 || lpFormat->hData32))
|
|
|
|
CLIPBOARD_DeleteRecord(lpFormat, !(hWndClipWindow));
|
|
|
|
|
|
|
|
/* Update the clipboard record */
|
|
|
|
lpFormat->wDataPresent = 1;
|
|
|
|
lpFormat->hData32 = hTargetImage;
|
|
|
|
lpFormat->hData16 = 0;
|
|
|
|
|
|
|
|
bRet = TRUE;
|
1999-09-03 17:17:57 +02:00
|
|
|
}
|
|
|
|
|
1999-09-20 17:42:47 +02:00
|
|
|
/* For native properties simply copy the X data without conversion */
|
|
|
|
else if (X11DRV_CLIPBOARD_IsNativeProperty(reqType)) /* <WCF>* */
|
1999-09-03 17:17:57 +02:00
|
|
|
{
|
|
|
|
HANDLE hClipData = 0;
|
|
|
|
void* lpClipData;
|
|
|
|
int cBytes = nitems * aformat/8;
|
|
|
|
|
|
|
|
if( cBytes )
|
|
|
|
{
|
|
|
|
/* Turn on the DDESHARE flag to enable shared 32 bit memory */
|
|
|
|
hClipData = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, cBytes );
|
|
|
|
if( (lpClipData = GlobalLock(hClipData)) )
|
|
|
|
{
|
|
|
|
memcpy(lpClipData, val, cBytes);
|
|
|
|
GlobalUnlock(hClipData);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
hClipData = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( hClipData )
|
|
|
|
{
|
|
|
|
/* delete previous clipboard record if any */
|
|
|
|
lpFormat = CLIPBOARD_LookupFormat(wFormat);
|
|
|
|
if (lpFormat->wDataPresent || lpFormat->hData16 || lpFormat->hData32)
|
|
|
|
CLIPBOARD_DeleteRecord(lpFormat, !(hWndClipWindow));
|
|
|
|
|
|
|
|
/* Update the clipboard record */
|
|
|
|
lpFormat->wDataPresent = 1;
|
|
|
|
lpFormat->hData32 = hClipData;
|
|
|
|
lpFormat->hData16 = 0;
|
|
|
|
|
|
|
|
bRet = TRUE;
|
|
|
|
}
|
|
|
|
}
|
1999-09-20 17:42:47 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
WARN("\tUnimplemented format conversion request\n");
|
|
|
|
goto END;
|
|
|
|
}
|
|
|
|
|
|
|
|
END:
|
|
|
|
/* Delete the property on the window now that we are done
|
|
|
|
* This will send a PropertyNotify event to the selection owner. */
|
|
|
|
TSXDeleteProperty(display,w,prop);
|
|
|
|
|
|
|
|
/* Free the retrieved property data */
|
2001-02-23 02:31:47 +01:00
|
|
|
HeapFree(GetProcessHeap(),0,val);
|
1999-09-03 17:17:57 +02:00
|
|
|
return bRet;
|
1998-12-07 10:13:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* X11DRV_CLIPBOARD_ReleaseSelection
|
|
|
|
*
|
1999-09-03 17:17:57 +02:00
|
|
|
* Release an XA_PRIMARY or XA_CLIPBOARD selection that we own, in response
|
|
|
|
* to a SelectionClear event.
|
|
|
|
* This can occur in response to another client grabbing the X selection.
|
1999-10-24 22:22:24 +02:00
|
|
|
* If the XA_CLIPBOARD selection is lost, we relinquish XA_PRIMARY as well.
|
1998-12-07 10:13:40 +01:00
|
|
|
*/
|
1999-09-03 17:17:57 +02:00
|
|
|
void X11DRV_CLIPBOARD_ReleaseSelection(Atom selType, Window w, HWND hwnd)
|
1998-12-07 10:13:40 +01:00
|
|
|
{
|
2001-05-16 21:52:29 +02:00
|
|
|
Display *display = thread_display();
|
1999-09-03 17:17:57 +02:00
|
|
|
Atom xaClipboard = TSXInternAtom(display, "CLIPBOARD", False);
|
2001-06-19 05:32:44 +02:00
|
|
|
int clearAllSelections = 0;
|
|
|
|
HKEY hkey;
|
|
|
|
|
|
|
|
if(!RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\Clipboard", &hkey))
|
|
|
|
{
|
|
|
|
char buffer[20];
|
|
|
|
DWORD type, count = sizeof(buffer);
|
|
|
|
if(!RegQueryValueExA(hkey, "ClearAllSelections", 0, &type, buffer, &count))
|
|
|
|
clearAllSelections = atoi(buffer);
|
|
|
|
RegCloseKey(hkey);
|
|
|
|
}
|
1999-09-03 17:17:57 +02:00
|
|
|
|
1999-10-24 22:22:24 +02:00
|
|
|
/* w is the window that lost the selection
|
1998-12-07 10:13:40 +01:00
|
|
|
* selectionPrevWindow is nonzero if CheckSelection() was called.
|
|
|
|
*/
|
|
|
|
|
1999-07-04 18:02:24 +02:00
|
|
|
TRACE("\tevent->window = %08x (sw = %08x, spw=%08x)\n",
|
1998-12-07 10:13:40 +01:00
|
|
|
(unsigned)w, (unsigned)selectionWindow, (unsigned)selectionPrevWindow );
|
|
|
|
|
|
|
|
if( selectionAcquired )
|
|
|
|
{
|
|
|
|
if( w == selectionWindow || selectionPrevWindow == None)
|
|
|
|
{
|
1999-10-24 22:22:24 +02:00
|
|
|
/* If we're losing the CLIPBOARD selection, or if the preferences in .winerc
|
|
|
|
* dictate that *all* selections should be cleared on loss of a selection,
|
|
|
|
* we must give up all the selections we own.
|
|
|
|
*/
|
|
|
|
if ( clearAllSelections || (selType == xaClipboard) )
|
1999-09-03 17:17:57 +02:00
|
|
|
{
|
1999-10-24 22:22:24 +02:00
|
|
|
/* completely give up the selection */
|
|
|
|
TRACE("Lost CLIPBOARD (+PRIMARY) selection\n");
|
|
|
|
|
1999-09-03 17:17:57 +02:00
|
|
|
/* We are completely giving up the selection.
|
|
|
|
* Make sure we can open the windows clipboard first. */
|
|
|
|
|
|
|
|
if ( !OpenClipboard(hwnd) )
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* We can't empty the clipboard if we cant open it so abandon.
|
|
|
|
* Wine will think that it still owns the selection but this is
|
|
|
|
* safer than losing the selection without properly emptying
|
|
|
|
* the clipboard. Perhaps we should forcibly re-assert ownership
|
|
|
|
* of the CLIPBOARD selection in this case...
|
|
|
|
*/
|
|
|
|
ERR("\tClipboard is busy. Could not give up selection!\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1999-10-24 22:22:24 +02:00
|
|
|
/* We really lost CLIPBOARD but want to voluntarily lose PRIMARY */
|
|
|
|
if ( (selType == xaClipboard)
|
|
|
|
&& (selectionAcquired & S_PRIMARY) )
|
|
|
|
{
|
|
|
|
XSetSelectionOwner(display, XA_PRIMARY, None, CurrentTime);
|
|
|
|
}
|
1999-09-03 17:17:57 +02:00
|
|
|
|
1999-10-24 22:22:24 +02:00
|
|
|
/* We really lost PRIMARY but want to voluntarily lose CLIPBOARD */
|
|
|
|
if ( (selType == XA_PRIMARY)
|
|
|
|
&& (selectionAcquired & S_CLIPBOARD) )
|
1999-09-03 17:17:57 +02:00
|
|
|
{
|
1999-10-24 22:22:24 +02:00
|
|
|
XSetSelectionOwner(display, xaClipboard, None, CurrentTime);
|
1999-09-03 17:17:57 +02:00
|
|
|
}
|
1999-10-24 22:22:24 +02:00
|
|
|
|
|
|
|
selectionWindow = None;
|
|
|
|
PrimarySelectionOwner = ClipboardSelectionOwner = 0;
|
|
|
|
|
1999-09-03 17:17:57 +02:00
|
|
|
/* Empty the windows clipboard.
|
|
|
|
* We should pretend that we still own the selection BEFORE calling
|
|
|
|
* EmptyClipboard() since otherwise this has the side effect of
|
|
|
|
* triggering X11DRV_CLIPBOARD_Acquire() and causing the X selection
|
|
|
|
* to be re-acquired by us!
|
|
|
|
*/
|
|
|
|
selectionAcquired = (S_PRIMARY | S_CLIPBOARD);
|
|
|
|
EmptyClipboard();
|
|
|
|
CloseClipboard();
|
|
|
|
|
|
|
|
/* Give up ownership of the windows clipboard */
|
|
|
|
CLIPBOARD_ReleaseOwner();
|
1999-10-24 22:22:24 +02:00
|
|
|
|
|
|
|
/* Reset the selection flags now that we are done */
|
|
|
|
selectionAcquired = S_NOSELECTION;
|
1999-09-03 17:17:57 +02:00
|
|
|
}
|
|
|
|
else if ( selType == XA_PRIMARY ) /* Give up only PRIMARY selection */
|
|
|
|
{
|
|
|
|
TRACE("Lost PRIMARY selection\n");
|
|
|
|
PrimarySelectionOwner = 0;
|
|
|
|
selectionAcquired &= ~S_PRIMARY; /* clear S_PRIMARY mask */
|
|
|
|
}
|
|
|
|
|
|
|
|
cSelectionTargets = 0;
|
1998-12-07 10:13:40 +01:00
|
|
|
}
|
1999-09-03 17:17:57 +02:00
|
|
|
/* but we'll keep existing data for internal use */
|
1998-12-07 10:13:40 +01:00
|
|
|
else if( w == selectionPrevWindow )
|
|
|
|
{
|
1999-09-03 17:17:57 +02:00
|
|
|
Atom xaClipboard = TSXInternAtom(display, _CLIPBOARD, False);
|
|
|
|
|
1998-12-07 10:13:40 +01:00
|
|
|
w = TSXGetSelectionOwner(display, XA_PRIMARY);
|
|
|
|
if( w == None )
|
|
|
|
TSXSetSelectionOwner(display, XA_PRIMARY, selectionWindow, CurrentTime);
|
1999-09-03 17:17:57 +02:00
|
|
|
|
|
|
|
w = TSXGetSelectionOwner(display, xaClipboard);
|
|
|
|
if( w == None )
|
|
|
|
TSXSetSelectionOwner(display, xaClipboard, selectionWindow, CurrentTime);
|
|
|
|
}
|
1998-12-07 10:13:40 +01:00
|
|
|
}
|
|
|
|
|
1999-10-24 22:22:24 +02:00
|
|
|
/* Signal to a selectionClearEvent listener if the selection is completely lost */
|
|
|
|
if (selectionClearEvent && !selectionAcquired)
|
|
|
|
{
|
|
|
|
TRACE("Lost all selections, signalling to selectionClearEvent listener\n");
|
|
|
|
SetEvent(selectionClearEvent);
|
|
|
|
}
|
|
|
|
|
1998-12-07 10:13:40 +01:00
|
|
|
selectionPrevWindow = None;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
2001-02-12 04:49:07 +01:00
|
|
|
* ReleaseClipboard (X11DRV.@)
|
1999-09-03 17:17:57 +02:00
|
|
|
* Voluntarily release all currently owned X selections
|
1998-12-07 10:13:40 +01:00
|
|
|
*/
|
2000-08-10 03:16:19 +02:00
|
|
|
void X11DRV_ReleaseClipboard(void)
|
1998-12-07 10:13:40 +01:00
|
|
|
{
|
2001-05-16 21:52:29 +02:00
|
|
|
Display *display = thread_display();
|
1999-04-01 14:03:52 +02:00
|
|
|
if( selectionAcquired )
|
1998-12-07 10:13:40 +01:00
|
|
|
{
|
1999-04-01 14:03:52 +02:00
|
|
|
XEvent xe;
|
1999-09-03 17:17:57 +02:00
|
|
|
Window savePrevWindow = selectionWindow;
|
|
|
|
Atom xaClipboard = TSXInternAtom(display, _CLIPBOARD, False);
|
|
|
|
BOOL bHasPrimarySelection = selectionAcquired & S_PRIMARY;
|
1999-04-01 14:03:52 +02:00
|
|
|
|
1999-09-03 17:17:57 +02:00
|
|
|
selectionAcquired = S_NOSELECTION;
|
1999-04-01 14:03:52 +02:00
|
|
|
selectionPrevWindow = selectionWindow;
|
|
|
|
selectionWindow = None;
|
1998-12-07 10:13:40 +01:00
|
|
|
|
1999-07-04 18:02:24 +02:00
|
|
|
TRACE("\tgiving up selection (spw = %08x)\n",
|
1999-04-01 14:03:52 +02:00
|
|
|
(unsigned)selectionPrevWindow);
|
1998-12-07 10:13:40 +01:00
|
|
|
|
2001-01-15 23:31:24 +01:00
|
|
|
wine_tsx11_lock();
|
1999-04-01 14:03:52 +02:00
|
|
|
|
1999-09-03 17:17:57 +02:00
|
|
|
TRACE("Releasing CLIPBOARD selection\n");
|
|
|
|
XSetSelectionOwner(display, xaClipboard, None, CurrentTime);
|
1999-04-01 14:03:52 +02:00
|
|
|
if( selectionPrevWindow )
|
|
|
|
while( !XCheckTypedWindowEvent( display, selectionPrevWindow,
|
1999-09-03 17:17:57 +02:00
|
|
|
SelectionClear, &xe ) );
|
|
|
|
|
|
|
|
if ( bHasPrimarySelection )
|
|
|
|
{
|
|
|
|
TRACE("Releasing XA_PRIMARY selection\n");
|
|
|
|
selectionPrevWindow = savePrevWindow; /* May be cleared in X11DRV_CLIPBOARD_ReleaseSelection */
|
|
|
|
XSetSelectionOwner(display, XA_PRIMARY, None, CurrentTime);
|
|
|
|
|
|
|
|
if( selectionPrevWindow )
|
|
|
|
while( !XCheckTypedWindowEvent( display, selectionPrevWindow,
|
|
|
|
SelectionClear, &xe ) );
|
|
|
|
}
|
2001-01-15 23:31:24 +01:00
|
|
|
wine_tsx11_unlock();
|
1998-12-07 10:13:40 +01:00
|
|
|
}
|
1999-09-20 17:42:47 +02:00
|
|
|
|
|
|
|
/* Get rid of any Pixmap resources we may still have */
|
2000-01-26 03:21:30 +01:00
|
|
|
while (prop_head)
|
1999-09-20 17:42:47 +02:00
|
|
|
{
|
2000-01-26 03:21:30 +01:00
|
|
|
PROPERTY *prop = prop_head;
|
|
|
|
prop_head = prop->next;
|
2001-05-11 02:17:47 +02:00
|
|
|
XFreePixmap( gdi_display, prop->pixmap );
|
2000-01-26 03:21:30 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, prop );
|
1999-09-20 17:42:47 +02:00
|
|
|
}
|
1998-12-07 10:13:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
2001-02-12 04:49:07 +01:00
|
|
|
* AcquireClipboard (X11DRV.@)
|
1998-12-07 10:13:40 +01:00
|
|
|
*/
|
2000-08-10 03:16:19 +02:00
|
|
|
void X11DRV_AcquireClipboard(void)
|
1998-12-07 10:13:40 +01:00
|
|
|
{
|
2001-05-16 21:52:29 +02:00
|
|
|
Display *display = thread_display();
|
1998-12-07 10:13:40 +01:00
|
|
|
Window owner;
|
1999-09-03 17:17:57 +02:00
|
|
|
HWND hWndClipWindow = GetOpenClipboardWindow();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Acquire X selection if we don't already own it.
|
|
|
|
* Note that we only acquire the selection if it hasn't been already
|
|
|
|
* acquired by us, and ignore the fact that another X window may be
|
|
|
|
* asserting ownership. The reason for this is we need *any* top level
|
|
|
|
* X window to hold selection ownership. The actual clipboard data requests
|
|
|
|
* are made via GetClipboardData from EVENT_SelectionRequest and this
|
|
|
|
* ensures that the real HWND owner services the request.
|
|
|
|
* If the owning X window gets destroyed the selection ownership is
|
|
|
|
* re-cycled to another top level X window in X11DRV_CLIPBOARD_ResetOwner.
|
|
|
|
*
|
|
|
|
*/
|
1998-12-07 10:13:40 +01:00
|
|
|
|
1999-09-03 17:17:57 +02:00
|
|
|
if ( !(selectionAcquired == (S_PRIMARY | S_CLIPBOARD)) )
|
1998-12-07 10:13:40 +01:00
|
|
|
{
|
1999-09-03 17:17:57 +02:00
|
|
|
Atom xaClipboard = TSXInternAtom(display, _CLIPBOARD, False);
|
2001-08-24 02:26:59 +02:00
|
|
|
owner = X11DRV_get_whole_window( GetAncestor( hWndClipWindow ? hWndClipWindow : AnyPopup(),
|
|
|
|
GA_ROOT ) );
|
1998-12-07 10:13:40 +01:00
|
|
|
|
1999-09-03 17:17:57 +02:00
|
|
|
/* Grab PRIMARY selection if not owned */
|
|
|
|
if ( !(selectionAcquired & S_PRIMARY) )
|
|
|
|
TSXSetSelectionOwner(display, XA_PRIMARY, owner, CurrentTime);
|
|
|
|
|
|
|
|
/* Grab CLIPBOARD selection if not owned */
|
|
|
|
if ( !(selectionAcquired & S_CLIPBOARD) )
|
|
|
|
TSXSetSelectionOwner(display, xaClipboard, owner, CurrentTime);
|
|
|
|
|
|
|
|
if( TSXGetSelectionOwner(display,XA_PRIMARY) == owner )
|
|
|
|
selectionAcquired |= S_PRIMARY;
|
|
|
|
|
|
|
|
if( TSXGetSelectionOwner(display,xaClipboard) == owner)
|
|
|
|
selectionAcquired |= S_CLIPBOARD;
|
|
|
|
|
|
|
|
if (selectionAcquired)
|
|
|
|
{
|
1998-12-07 10:13:40 +01:00
|
|
|
selectionWindow = owner;
|
1999-09-03 17:17:57 +02:00
|
|
|
TRACE("Grabbed X selection, owner=(%08x)\n", (unsigned) owner);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1998-12-07 10:13:40 +01:00
|
|
|
|
1999-09-03 17:17:57 +02:00
|
|
|
/**************************************************************************
|
2001-02-12 04:49:07 +01:00
|
|
|
* IsClipboardFormatAvailable (X11DRV.@)
|
1999-09-03 17:17:57 +02:00
|
|
|
*
|
|
|
|
* Checks if the specified format is available in the current selection
|
|
|
|
* Only invoked when WINE is not the selection owner
|
|
|
|
*/
|
2000-08-10 03:16:19 +02:00
|
|
|
BOOL X11DRV_IsClipboardFormatAvailable(UINT wFormat)
|
1999-09-03 17:17:57 +02:00
|
|
|
{
|
2001-05-16 21:52:29 +02:00
|
|
|
Display *display = thread_display();
|
1999-09-03 17:17:57 +02:00
|
|
|
Atom xaClipboard = TSXInternAtom(display, _CLIPBOARD, False);
|
|
|
|
Window ownerPrimary = TSXGetSelectionOwner(display,XA_PRIMARY);
|
|
|
|
Window ownerClipboard = TSXGetSelectionOwner(display,xaClipboard);
|
|
|
|
|
2000-12-23 00:26:18 +01:00
|
|
|
TRACE("enter for %d\n", wFormat);
|
2000-12-11 02:09:56 +01:00
|
|
|
|
1999-09-03 17:17:57 +02:00
|
|
|
/*
|
|
|
|
* If the selection has not been previously cached, or the selection has changed,
|
|
|
|
* try and cache the list of available selection targets from the current selection.
|
|
|
|
*/
|
|
|
|
if ( !cSelectionTargets || (PrimarySelectionOwner != ownerPrimary)
|
|
|
|
|| (ClipboardSelectionOwner != ownerClipboard) )
|
|
|
|
{
|
|
|
|
/*
|
2001-05-18 23:01:38 +02:00
|
|
|
* First try caching the CLIPBOARD selection.
|
1999-09-03 17:17:57 +02:00
|
|
|
* If unavailable try PRIMARY.
|
|
|
|
*/
|
|
|
|
if ( X11DRV_CLIPBOARD_CacheDataFormats(xaClipboard) == 0 )
|
|
|
|
{
|
|
|
|
X11DRV_CLIPBOARD_CacheDataFormats(XA_PRIMARY);
|
|
|
|
}
|
|
|
|
|
|
|
|
ClipboardSelectionOwner = ownerClipboard;
|
|
|
|
PrimarySelectionOwner = ownerPrimary;
|
1998-12-07 10:13:40 +01:00
|
|
|
}
|
1999-09-03 17:17:57 +02:00
|
|
|
|
|
|
|
/* Exit if there is no selection */
|
|
|
|
if ( !ownerClipboard && !ownerPrimary )
|
2000-12-11 02:09:56 +01:00
|
|
|
{
|
2000-12-23 00:26:18 +01:00
|
|
|
TRACE("There is no selection owner\n");
|
1999-09-03 17:17:57 +02:00
|
|
|
return FALSE;
|
2000-12-11 02:09:56 +01:00
|
|
|
}
|
2000-12-23 00:26:18 +01:00
|
|
|
|
|
|
|
/* Check if the format is available in the clipboard cache */
|
|
|
|
if ( CLIPBOARD_IsPresent(wFormat) )
|
|
|
|
return TRUE;
|
1999-09-03 17:17:57 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Many X client apps (such as XTerminal) don't support being queried
|
|
|
|
* for the "TARGETS" target atom. To handle such clients we must actually
|
|
|
|
* try to convert the selection to the requested type.
|
|
|
|
*/
|
|
|
|
if ( !cSelectionTargets )
|
2000-08-10 03:16:19 +02:00
|
|
|
return X11DRV_GetClipboardData( wFormat );
|
1999-09-03 17:17:57 +02:00
|
|
|
|
2000-12-11 02:09:56 +01:00
|
|
|
TRACE("There is no selection\n");
|
1999-09-03 17:17:57 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
2001-02-12 04:49:07 +01:00
|
|
|
* RegisterClipboardFormat (X11DRV.@)
|
1999-09-03 17:17:57 +02:00
|
|
|
*
|
|
|
|
* Registers a custom X clipboard format
|
|
|
|
* Returns: TRUE - success, FALSE - failure
|
|
|
|
*/
|
2000-08-10 03:16:19 +02:00
|
|
|
BOOL X11DRV_RegisterClipboardFormat( LPCSTR FormatName )
|
1999-09-03 17:17:57 +02:00
|
|
|
{
|
2001-05-16 21:52:29 +02:00
|
|
|
Display *display = thread_display();
|
1999-09-03 17:17:57 +02:00
|
|
|
Atom prop = None;
|
|
|
|
char str[256];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If an X atom is registered for this format, return that
|
|
|
|
* Otherwise register a new atom.
|
|
|
|
*/
|
|
|
|
if (FormatName)
|
|
|
|
{
|
|
|
|
/* Add a WINE specific prefix to the format */
|
|
|
|
strcpy(str, FMT_PREFIX);
|
|
|
|
strncat(str, FormatName, sizeof(str) - strlen(FMT_PREFIX));
|
|
|
|
prop = TSXInternAtom(display, str, False);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (prop) ? TRUE : FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
2001-02-12 04:49:07 +01:00
|
|
|
* IsSelectionOwner (X11DRV.@)
|
1999-09-03 17:17:57 +02:00
|
|
|
*
|
|
|
|
* Returns: TRUE - We(WINE) own the selection, FALSE - Selection not owned by us
|
|
|
|
*/
|
2000-08-10 03:16:19 +02:00
|
|
|
BOOL X11DRV_IsSelectionOwner(void)
|
1999-09-03 17:17:57 +02:00
|
|
|
{
|
|
|
|
return selectionAcquired;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
2001-02-12 04:49:07 +01:00
|
|
|
* SetClipboardData (X11DRV.@)
|
1999-09-03 17:17:57 +02:00
|
|
|
*
|
|
|
|
* We don't need to do anything special here since the clipboard code
|
|
|
|
* maintains the cache.
|
|
|
|
*
|
|
|
|
*/
|
2000-08-10 03:16:19 +02:00
|
|
|
void X11DRV_SetClipboardData(UINT wFormat)
|
1999-09-03 17:17:57 +02:00
|
|
|
{
|
|
|
|
/* Make sure we have acquired the X selection */
|
2000-08-10 03:16:19 +02:00
|
|
|
X11DRV_AcquireClipboard();
|
1998-12-07 10:13:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
2001-02-12 04:49:07 +01:00
|
|
|
* GetClipboardData (X11DRV.@)
|
1999-04-01 14:03:52 +02:00
|
|
|
*
|
1999-09-03 17:17:57 +02:00
|
|
|
* This method is invoked only when we DO NOT own the X selection
|
|
|
|
*
|
2000-12-11 02:09:56 +01:00
|
|
|
* NOTE: Clipboard driver get requests only for CF_UNICODETEXT data.
|
1999-09-03 17:17:57 +02:00
|
|
|
* We always get the data from the selection client each time,
|
|
|
|
* since we have no way of determining if the data in our cache is stale.
|
1998-12-07 10:13:40 +01:00
|
|
|
*/
|
2000-08-10 03:16:19 +02:00
|
|
|
BOOL X11DRV_GetClipboardData(UINT wFormat)
|
1998-12-07 10:13:40 +01:00
|
|
|
{
|
2001-05-16 21:52:29 +02:00
|
|
|
Display *display = thread_display();
|
1999-04-01 14:03:52 +02:00
|
|
|
BOOL bRet = selectionAcquired;
|
1999-09-03 17:17:57 +02:00
|
|
|
HWND hWndClipWindow = GetOpenClipboardWindow();
|
1999-02-26 12:11:13 +01:00
|
|
|
HWND hWnd = (hWndClipWindow) ? hWndClipWindow : GetActiveWindow();
|
1999-09-03 17:17:57 +02:00
|
|
|
LPWINE_CLIPFORMAT lpFormat;
|
1998-12-07 10:13:40 +01:00
|
|
|
|
2000-12-11 02:09:56 +01:00
|
|
|
TRACE("%d\n", wFormat);
|
|
|
|
|
2001-06-04 23:55:17 +02:00
|
|
|
if (!selectionAcquired)
|
1999-04-01 14:03:52 +02:00
|
|
|
{
|
2001-10-12 20:41:50 +02:00
|
|
|
XEvent xe;
|
1999-09-03 17:17:57 +02:00
|
|
|
Atom propRequest;
|
2001-10-12 20:41:50 +02:00
|
|
|
Window w = X11DRV_get_whole_window( GetAncestor( hWnd, GA_ROOT ));
|
|
|
|
if(!w)
|
|
|
|
{
|
|
|
|
FIXME("No parent win found %x %x\n", hWnd, hWndClipWindow);
|
|
|
|
return FALSE;
|
|
|
|
}
|
1999-09-03 17:17:57 +02:00
|
|
|
|
|
|
|
/* Map the format ID requested to an X selection property.
|
|
|
|
* If the format is in the cache, use the atom associated
|
|
|
|
* with it.
|
|
|
|
*/
|
|
|
|
|
|
|
|
lpFormat = CLIPBOARD_LookupFormat( wFormat );
|
|
|
|
if (lpFormat && lpFormat->wDataPresent && lpFormat->drvData)
|
|
|
|
propRequest = (Atom)lpFormat->drvData;
|
|
|
|
else
|
|
|
|
propRequest = X11DRV_CLIPBOARD_MapFormatToProperty(wFormat);
|
|
|
|
|
|
|
|
if (propRequest)
|
|
|
|
{
|
|
|
|
TRACE("Requesting %s selection from %s...\n",
|
|
|
|
TSXGetAtomName(display, propRequest),
|
|
|
|
TSXGetAtomName(display, selectionCacheSrc) );
|
2001-01-15 23:31:24 +01:00
|
|
|
wine_tsx11_lock();
|
1999-09-03 17:17:57 +02:00
|
|
|
XConvertSelection(display, selectionCacheSrc, propRequest,
|
|
|
|
TSXInternAtom(display, "SELECTION_DATA", False),
|
|
|
|
w, CurrentTime);
|
|
|
|
|
|
|
|
/* wait until SelectionNotify is received */
|
|
|
|
|
|
|
|
while( TRUE )
|
|
|
|
{
|
|
|
|
if( XCheckTypedWindowEvent(display, w, SelectionNotify, &xe) )
|
|
|
|
if( xe.xselection.selection == selectionCacheSrc )
|
|
|
|
break;
|
|
|
|
}
|
2001-01-15 23:31:24 +01:00
|
|
|
wine_tsx11_unlock();
|
|
|
|
|
1999-09-03 17:17:57 +02:00
|
|
|
/*
|
|
|
|
* Read the contents of the X selection property into WINE's
|
|
|
|
* clipboard cache converting the selection to be compatible if possible.
|
|
|
|
*/
|
|
|
|
bRet = X11DRV_CLIPBOARD_ReadSelection( wFormat,
|
|
|
|
xe.xselection.requestor,
|
|
|
|
xe.xselection.property,
|
|
|
|
xe.xselection.target);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
bRet = FALSE;
|
|
|
|
|
|
|
|
TRACE("\tpresent %s = %i\n", CLIPBOARD_GetFormatName(wFormat), bRet );
|
1999-04-01 14:03:52 +02:00
|
|
|
}
|
2000-12-11 02:09:56 +01:00
|
|
|
|
|
|
|
TRACE("Returning %d\n", bRet);
|
1999-09-03 17:17:57 +02:00
|
|
|
|
1999-04-01 14:03:52 +02:00
|
|
|
return bRet;
|
1998-12-07 10:13:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
2001-02-12 04:49:07 +01:00
|
|
|
* ResetSelectionOwner (X11DRV.@)
|
1998-12-07 10:13:40 +01:00
|
|
|
*
|
1999-09-03 17:17:57 +02:00
|
|
|
* Called from DestroyWindow() to prevent X selection from being lost when
|
|
|
|
* a top level window is destroyed, by switching ownership to another top
|
|
|
|
* level window.
|
|
|
|
* Any top level window can own the selection. See X11DRV_CLIPBOARD_Acquire
|
|
|
|
* for a more detailed description of this.
|
1998-12-07 10:13:40 +01:00
|
|
|
*/
|
2001-08-18 20:08:26 +02:00
|
|
|
void X11DRV_ResetSelectionOwner(HWND hwnd, BOOL bFooBar)
|
1998-12-07 10:13:40 +01:00
|
|
|
{
|
2001-05-16 21:52:29 +02:00
|
|
|
Display *display = thread_display();
|
1999-09-03 17:17:57 +02:00
|
|
|
HWND hWndClipOwner = 0;
|
2001-08-18 20:08:26 +02:00
|
|
|
HWND tmp;
|
|
|
|
Window XWnd = X11DRV_get_whole_window(hwnd);
|
1999-09-03 17:17:57 +02:00
|
|
|
Atom xaClipboard;
|
|
|
|
BOOL bLostSelection = FALSE;
|
|
|
|
|
|
|
|
/* There is nothing to do if we don't own the selection,
|
|
|
|
* or if the X window which currently owns the selecion is different
|
|
|
|
* from the one passed in.
|
|
|
|
*/
|
|
|
|
if ( !selectionAcquired || XWnd != selectionWindow
|
|
|
|
|| selectionWindow == None )
|
|
|
|
return;
|
1998-12-26 13:00:43 +01:00
|
|
|
|
1999-09-03 17:17:57 +02:00
|
|
|
if ( (bFooBar && XWnd) || (!bFooBar && !XWnd) )
|
|
|
|
return;
|
1998-12-26 13:00:43 +01:00
|
|
|
|
1999-09-03 17:17:57 +02:00
|
|
|
hWndClipOwner = GetClipboardOwner();
|
|
|
|
xaClipboard = TSXInternAtom(display, _CLIPBOARD, False);
|
|
|
|
|
|
|
|
TRACE("clipboard owner = %04x, selection window = %08x\n",
|
|
|
|
hWndClipOwner, (unsigned)selectionWindow);
|
1998-12-07 10:13:40 +01:00
|
|
|
|
|
|
|
/* now try to salvage current selection from being destroyed by X */
|
|
|
|
|
1999-09-03 17:17:57 +02:00
|
|
|
TRACE("\tchecking %08x\n", (unsigned) XWnd);
|
|
|
|
|
|
|
|
selectionPrevWindow = selectionWindow;
|
|
|
|
selectionWindow = None;
|
|
|
|
|
2001-08-18 20:08:26 +02:00
|
|
|
if (!(tmp = GetWindow( hwnd, GW_HWNDNEXT ))) tmp = GetWindow( hwnd, GW_HWNDFIRST );
|
|
|
|
if (tmp && tmp != hwnd) selectionWindow = X11DRV_get_whole_window(tmp);
|
1999-09-03 17:17:57 +02:00
|
|
|
|
|
|
|
if( selectionWindow != None )
|
|
|
|
{
|
|
|
|
/* We must pretend that we don't own the selection while making the switch
|
|
|
|
* since a SelectionClear event will be sent to the last owner.
|
|
|
|
* If there is no owner X11DRV_CLIPBOARD_ReleaseSelection will do nothing.
|
|
|
|
*/
|
|
|
|
int saveSelectionState = selectionAcquired;
|
|
|
|
selectionAcquired = False;
|
|
|
|
|
|
|
|
TRACE("\tswitching selection from %08x to %08x\n",
|
|
|
|
(unsigned)selectionPrevWindow, (unsigned)selectionWindow);
|
|
|
|
|
|
|
|
/* Assume ownership for the PRIMARY and CLIPBOARD selection */
|
|
|
|
if ( saveSelectionState & S_PRIMARY )
|
|
|
|
TSXSetSelectionOwner(display, XA_PRIMARY, selectionWindow, CurrentTime);
|
|
|
|
|
|
|
|
TSXSetSelectionOwner(display, xaClipboard, selectionWindow, CurrentTime);
|
1999-10-24 22:22:24 +02:00
|
|
|
|
|
|
|
/* Restore the selection masks */
|
|
|
|
selectionAcquired = saveSelectionState;
|
|
|
|
|
1999-09-03 17:17:57 +02:00
|
|
|
/* Lose the selection if something went wrong */
|
|
|
|
if ( ( (saveSelectionState & S_PRIMARY) &&
|
|
|
|
(TSXGetSelectionOwner(display, XA_PRIMARY) != selectionWindow) )
|
|
|
|
|| (TSXGetSelectionOwner(display, xaClipboard) != selectionWindow) )
|
|
|
|
{
|
|
|
|
bLostSelection = TRUE;
|
|
|
|
goto END;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Update selection state */
|
|
|
|
if (saveSelectionState & S_PRIMARY)
|
|
|
|
PrimarySelectionOwner = selectionWindow;
|
|
|
|
|
|
|
|
ClipboardSelectionOwner = selectionWindow;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bLostSelection = TRUE;
|
|
|
|
goto END;
|
|
|
|
}
|
|
|
|
|
|
|
|
END:
|
|
|
|
if (bLostSelection)
|
|
|
|
{
|
1999-10-24 22:22:24 +02:00
|
|
|
/* Launch the clipboard server if the selection can no longer be recyled
|
|
|
|
* to another top level window. */
|
|
|
|
|
|
|
|
if ( !X11DRV_CLIPBOARD_LaunchServer() )
|
|
|
|
{
|
|
|
|
/* Empty the windows clipboard if the server was not launched.
|
|
|
|
* We should pretend that we still own the selection BEFORE calling
|
|
|
|
* EmptyClipboard() since otherwise this has the side effect of
|
|
|
|
* triggering X11DRV_CLIPBOARD_Acquire() and causing the X selection
|
|
|
|
* to be re-acquired by us!
|
|
|
|
*/
|
|
|
|
|
|
|
|
TRACE("\tLost the selection! Emptying the clipboard...\n");
|
|
|
|
|
1999-11-28 21:31:04 +01:00
|
|
|
OpenClipboard( 0 );
|
1999-10-24 22:22:24 +02:00
|
|
|
selectionAcquired = (S_PRIMARY | S_CLIPBOARD);
|
|
|
|
EmptyClipboard();
|
|
|
|
|
|
|
|
CloseClipboard();
|
|
|
|
|
|
|
|
/* Give up ownership of the windows clipboard */
|
|
|
|
CLIPBOARD_ReleaseOwner();
|
|
|
|
}
|
1999-09-03 17:17:57 +02:00
|
|
|
|
1999-10-24 22:22:24 +02:00
|
|
|
selectionAcquired = S_NOSELECTION;
|
|
|
|
ClipboardSelectionOwner = PrimarySelectionOwner = 0;
|
|
|
|
selectionWindow = 0;
|
1999-09-03 17:17:57 +02:00
|
|
|
}
|
1998-12-07 10:13:40 +01:00
|
|
|
}
|
|
|
|
|
1999-09-20 17:42:47 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* X11DRV_CLIPBOARD_RegisterPixmapResource
|
|
|
|
* Registers a Pixmap resource which is to be associated with a property Atom.
|
|
|
|
* When the property is destroyed we also destroy the Pixmap through the
|
|
|
|
* PropertyNotify event.
|
|
|
|
*/
|
|
|
|
BOOL X11DRV_CLIPBOARD_RegisterPixmapResource( Atom property, Pixmap pixmap )
|
|
|
|
{
|
2000-01-26 03:21:30 +01:00
|
|
|
PROPERTY *prop = HeapAlloc( GetProcessHeap(), 0, sizeof(*prop) );
|
|
|
|
if (!prop) return FALSE;
|
|
|
|
prop->atom = property;
|
|
|
|
prop->pixmap = pixmap;
|
|
|
|
prop->next = prop_head;
|
|
|
|
prop_head = prop;
|
|
|
|
return TRUE;
|
1999-09-20 17:42:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* X11DRV_CLIPBOARD_FreeResources
|
|
|
|
*
|
|
|
|
* Called from EVENT_PropertyNotify() to give us a chance to destroy
|
|
|
|
* any resources associated with this property.
|
|
|
|
*/
|
|
|
|
void X11DRV_CLIPBOARD_FreeResources( Atom property )
|
|
|
|
{
|
|
|
|
/* Do a simple linear search to see if we have a Pixmap resource
|
|
|
|
* associated with this property and release it.
|
|
|
|
*/
|
2000-01-26 03:21:30 +01:00
|
|
|
PROPERTY **prop = &prop_head;
|
|
|
|
|
|
|
|
while (*prop)
|
1999-09-20 17:42:47 +02:00
|
|
|
{
|
2000-01-26 03:21:30 +01:00
|
|
|
if ((*prop)->atom == property)
|
1999-09-20 17:42:47 +02:00
|
|
|
{
|
2000-01-26 03:21:30 +01:00
|
|
|
PROPERTY *next = (*prop)->next;
|
2001-05-11 02:17:47 +02:00
|
|
|
XFreePixmap( gdi_display, (*prop)->pixmap );
|
2000-01-26 03:21:30 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, *prop );
|
|
|
|
*prop = next;
|
1999-09-20 17:42:47 +02:00
|
|
|
}
|
2000-01-26 03:21:30 +01:00
|
|
|
else prop = &(*prop)->next;
|
1999-09-20 17:42:47 +02:00
|
|
|
}
|
|
|
|
}
|