wine/misc/clipboard.c
Alexandre Julliard ecc3712ddf Release 941122
Sun Nov 20 18:30:06 1994  Alexandre Julliard  (julliard@lamisun.epfl.ch)

	* [controls/scroll.c] [include/scroll.h]
	Rewritten most of scroll-bar code for better Windows look & feel.
	Implemented EnableScrollBar().
	Preliminary keyboard support.

	* [objects/bitblt.c]
	Fixed BadMatch error for BitBlt() and StretchBlt() when reading
	bits from outside the visible region.

	* [objects/oembitmap.c] [include/bitmaps/obm_*]
	Use XPM symbolic colors to load bitmaps. This allows the colors
	of the bitmaps to depend on the system colors.

	* [tools/make_debug]
	Made the make_debug script more robust.

	* [windows/dialog.c]
	Fixed CheckRadioButton().

	* [windows/nonclient.c]
	A few changes to scroll-bar drawing and tracking.

	* [windows/winpos.c]
	Renamed NextWindowFromPoint() to WINPOS_NextWindowFromPoint() to
	avoid confusion, and optimized it somewhat.

Nov 19, 94 Martin Ayotte (wine@trgcorp.mksinfo.qc.ca)

	* [misc/audio.c]
	* [misc/mcianim.c]
	more coding but nothing spectacular.

	* [misc/mmaux.c]
	some coding to access '/dev/mixer'.

	* [misc/midi.c]
	some coding to read .MID files, but it's not playing yet.

Sun Nov 13 19:31:03 1994    James Youngman (mbcstjy@afs.man.ac.uk)

	* [objects/dib.c]
	Reimplemented DIB_SetImageBits_RLE8() so that it would cope with
	bitmaps which don't end 0x00, 0x02 (previously it blew up).  This
	includes some bitmaps output by Paint Shop Pro.  Implementation is
	possibly now too lax.  Please see the notes on the function about
	why.

	* [controls/desktop.c]
	The desktop pattern should be painted if the wallpaper doesn't
	cover the whole screen width OR the whole screen height.

Sun Nov 13 00:07:11 MET 1994	Erik Bos	<erik@xs4all.nl>

	* [objects/dib.c]
	Small bug in DIB_SetImageBits() fixed, bitmaps in 16,24 bpp
	now work.

	* [loader/ne_resource.c] [include/resource.h]
	Some cleanup.

Thu Nov 10 20:44:58 1994  Martin von Loewis  (martin@cs.csufresno.edu)

	* [Configure]
	  [rc/sysres.rc]
	Primitive compile-time support for multiple languages

	* [rc/sysres_De.rc]
	New file

	* [loader/resource.c]
	LoadBitmap: Recognize end of sysresbm properly

	* [rc/Imakefile]
	Rules to compile resources simplified, dependencies changed

	* [rc/sysresbm.rc]
	Don't use sysresbm if using XPM

	* [windows/dialog.c]
	CreateDialogIndirectParam: Reverse Z-order of controls

	* [windows/message.c]
	MSG_TranslateMouseMsg: Fix HTTRANSPARENT handling

	* [windows/winpos.c]
	NextWindowFromPoint: New function

	* [controls/button.c]
	WM_NCHITTEST: Group Box is HTTRANSPARENT
	BUTTON_CheckAutoRadioButton: New function
	BM_SETCHECK: Added call to BUTTON_CheckAutoRadioButton

Mon Nov  7 11:20:26 1994  Paul Falstad  (pf@zoof.cts.com)

	* [objects/text.c]
	Fix hang when using DrawText(..., DT_WORDBREAK) with a word that
	is too long to break.

	* [objects/font.c]
	Don't assume helvetica if there is no font family; let the other
	font attributes decide what font to use.

	* [controls/widgets.c]
	Listboxes and combo boxes need to be notified of double-clicks.

	* [controls/listbox.c]
	  [include/listbox.h]

	scrolling to bottom of list box should display last item at the
	bottom, not at the top.
	
	list boxes need to allocate a separate heap for their item data,
	rather than using the user heap.  Otherwise, it's very easy to run
	out of memory for list box items.

	removed redundant code in ListBoxAddString().  Implemented simple
	version of LBS_SORT.

	Don't put [.] in the list box when using DDL_DIRECTORY.

	* [controls/combo.c]
	Combos should pass CBS_SORT onto their list box.

	* [windows/win.c]
	If window creation is aborted, remove the window from the
	linked lists.

	* [controls/static.c]
	static controls with SS_ICON were always returning 0 from
	WM_NCCREATE.

	Make sure static controls have text to draw before drawing it.
1994-11-22 16:31:29 +00:00

409 lines
12 KiB
C

/*
* 'Wine' Clipboard function handling
*
* Copyright 1994 Martin Ayotte
*/
static char Copyright[] = "Copyright Martin Ayotte, 1994";
#include <stdlib.h>
#include <stdio.h>
#include <windows.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include "prototypes.h"
#include "heap.h"
#include "win.h"
#include "stddebug.h"
/* #define DEBUG_CLIPBOARD /* */
/* #undef DEBUG_CLIPBOARD /* */
#include "debug.h"
typedef struct tagCLIPFORMAT {
WORD wFormatID;
WORD wRefCount;
LPSTR Name;
HANDLE hData;
DWORD BufSize;
void *PrevFormat;
void *NextFormat;
} CLIPFORMAT;
typedef CLIPFORMAT FAR* LPCLIPFORMAT;
static HWND hWndClipboardOwner = 0;
static HWND hWndViewer = 0;
static WORD LastRegFormat = 0xC000;
static Bool wait_for_selection = False;
static Bool wineOwnsSelection = False;
CLIPFORMAT ClipFormats[12] = {
{ CF_TEXT, 1, "Text", (HANDLE)NULL, 0, NULL, &ClipFormats[1] },
{ CF_BITMAP, 1, "Bitmap", (HANDLE)NULL, 0, &ClipFormats[0], &ClipFormats[2] },
{ CF_METAFILEPICT, 1, "MetaFile Picture", (HANDLE)NULL, 0, &ClipFormats[1], &ClipFormats[3] },
{ CF_SYLK, 1, "Sylk", (HANDLE)NULL, 0, &ClipFormats[2], &ClipFormats[4] },
{ CF_DIF, 1, "DIF", (HANDLE)NULL, 0, &ClipFormats[3], &ClipFormats[5] },
{ CF_TIFF, 1, "TIFF", (HANDLE)NULL, 0, &ClipFormats[4], &ClipFormats[6] },
{ CF_OEMTEXT, 1, "OEM Text", (HANDLE)NULL, 0, &ClipFormats[5], &ClipFormats[7] },
{ CF_DIB, 1, "DIB", (HANDLE)NULL, 0, &ClipFormats[6], &ClipFormats[8] },
{ CF_PALETTE, 1, "Palette", (HANDLE)NULL, 0, &ClipFormats[7], &ClipFormats[9] },
{ CF_PENDATA, 1, "PenData", (HANDLE)NULL, 0, &ClipFormats[8], &ClipFormats[10] },
{ CF_RIFF, 1, "RIFF", (HANDLE)NULL, 0, &ClipFormats[9], &ClipFormats[11] },
{ CF_WAVE, 1, "Wave", (HANDLE)NULL, 0, &ClipFormats[10], NULL }
};
/**************************************************************************
* OpenClipboard [USER.137]
*/
BOOL OpenClipboard(HWND hWnd)
{
if (hWndClipboardOwner != 0) return FALSE;
hWndClipboardOwner = hWnd;
dprintf_clipboard(stddeb,"OpenClipboard(%04X); !\n", hWnd);
return TRUE;
}
/**************************************************************************
* CloseClipboard [USER.138]
*/
BOOL CloseClipboard()
{
if (hWndClipboardOwner == 0) return FALSE;
hWndClipboardOwner = 0;
dprintf_clipboard(stddeb,"CloseClipboard(); !\n");
return TRUE;
}
/**************************************************************************
* EmptyClipboard [USER.139]
*/
BOOL EmptyClipboard()
{
LPCLIPFORMAT lpFormat = ClipFormats;
if (hWndClipboardOwner == 0) return FALSE;
dprintf_clipboard(stddeb,"EmptyClipboard(); !\n");
while(TRUE) {
if (lpFormat == NULL) break;
if (lpFormat->hData != 0) {
GlobalFree(lpFormat->hData);
lpFormat->hData = 0;
}
lpFormat = lpFormat->NextFormat;
}
if(wineOwnsSelection){
dprintf_clipboard(stddeb,"Losing selection\n");
wineOwnsSelection=False;
XSetSelectionOwner(display,XA_PRIMARY,None,CurrentTime);
}
return TRUE;
}
/**************************************************************************
* GetClipboardOwner [USER.140]
*/
HWND GetClipboardOwner()
{
dprintf_clipboard(stddeb,
"GetClipboardOwner() = %04X !\n", hWndClipboardOwner);
return hWndClipboardOwner;
}
/**************************************************************************
* SetClipboardData [USER.141]
*/
HANDLE SetClipboardData(WORD wFormat, HANDLE hData)
{
LPCLIPFORMAT lpFormat = ClipFormats;
dprintf_clipboard(stddeb,
"SetClipboardDate(%04X, %04X) !\n", wFormat, hData);
while(TRUE) {
if (lpFormat == NULL) return 0;
if (lpFormat->wFormatID == wFormat) break;
lpFormat = lpFormat->NextFormat;
}
/* doc says we shouldn't use CurrentTime */
/* should we become owner of CLIPBOARD as well? */
XSetSelectionOwner(display,XA_PRIMARY,WIN_GetXWindow(hWndClipboardOwner),CurrentTime);
wineOwnsSelection = True;
dprintf_clipboard(stddeb,"Getting selection\n");
if (lpFormat->hData != 0) GlobalFree(lpFormat->hData);
lpFormat->hData = hData;
return lpFormat->hData;
}
/**************************************************************************
* GetClipboardData [USER.142]
*/
HANDLE GetClipboardData(WORD wFormat)
{
LPCLIPFORMAT lpFormat = ClipFormats;
dprintf_clipboard(stddeb,"GetClipboardData(%04X) !\n", wFormat);
if(wFormat == CF_TEXT && !wineOwnsSelection)
{ wait_for_selection=True;
dprintf_clipboard(stddeb,"Requesting selection\n");
XConvertSelection(display,XA_PRIMARY,XA_STRING,
XInternAtom(display,"PRIMARY_TEXT",False),
WIN_GetXWindow(hWndClipboardOwner),CurrentTime);
/* TODO: need time-out for broken clients */
while(wait_for_selection)MSG_WaitXEvent(-1);
}
while(TRUE) {
if (lpFormat == NULL) return 0;
if (lpFormat->wFormatID == wFormat) break;
lpFormat = lpFormat->NextFormat;
}
return lpFormat->hData;
}
/**************************************************************************
* CountClipboardFormats [USER.143]
*/
int CountClipboardFormats()
{
int FormatCount = 0;
LPCLIPFORMAT lpFormat = ClipFormats;
while(TRUE) {
if (lpFormat == NULL) break;
if (lpFormat->hData != 0) {
dprintf_clipboard(stddeb,
"CountClipboardFormats // Find Not Empty (%04X) !\n",
lpFormat->hData);
FormatCount++;
}
lpFormat = lpFormat->NextFormat;
}
dprintf_clipboard(stddeb,"CountClipboardFormats() = %d !\n", FormatCount);
return FormatCount;
}
/**************************************************************************
* EnumClipboardFormats [USER.144]
*/
WORD EnumClipboardFormats(WORD wFormat)
{
LPCLIPFORMAT lpFormat = ClipFormats;
dprintf_clipboard(stddeb,"EnumClipboardFormats(%04X) !\n", wFormat);
if (wFormat == 0) {
if (lpFormat->hData != 0)
return lpFormat->wFormatID;
else
wFormat = lpFormat->wFormatID;
}
while(TRUE) {
if (lpFormat == NULL) return 0;
if (lpFormat->wFormatID == wFormat) break;
lpFormat = lpFormat->NextFormat;
}
dprintf_clipboard(stddeb,"EnumClipboardFormats // Find Last (%04X) !\n",
lpFormat->wFormatID);
lpFormat = lpFormat->NextFormat;
while(TRUE) {
if (lpFormat == NULL) return 0;
if (lpFormat->hData != 0) break;
lpFormat = lpFormat->NextFormat;
}
dprintf_clipboard(stddeb,
"EnumClipboardFormats // Find Not Empty Id=%04X hData=%04X !\n",
lpFormat->wFormatID, lpFormat->hData);
return lpFormat->wFormatID;
}
/**************************************************************************
* RegisterClipboardFormat [USER.145]
*/
WORD RegisterClipboardFormat(LPCSTR FormatName)
{
LPCLIPFORMAT lpNewFormat;
LPCLIPFORMAT lpFormat = ClipFormats;
if (FormatName == NULL) return 0;
while(TRUE) {
if (lpFormat->NextFormat == NULL) break;
lpFormat = lpFormat->NextFormat;
}
lpNewFormat = (LPCLIPFORMAT)malloc(sizeof(CLIPFORMAT));
if (lpNewFormat == NULL) return 0;
lpFormat->NextFormat = lpNewFormat;
dprintf_clipboard(stddeb,"RegisterClipboardFormat('%s') !\n", FormatName);
lpNewFormat->wFormatID = LastRegFormat;
lpNewFormat->wRefCount = 1;
lpNewFormat->Name = (LPSTR)malloc(strlen(FormatName) + 1);
if (lpNewFormat->Name == NULL) {
free(lpNewFormat);
return 0;
}
strcpy(lpNewFormat->Name, FormatName);
lpNewFormat->hData = 0;
lpNewFormat->BufSize = 0;
lpNewFormat->PrevFormat = lpFormat;
lpNewFormat->NextFormat = NULL;
return LastRegFormat++;
}
/**************************************************************************
* GetClipboardFormatName [USER.146]
*/
int GetClipboardFormatName(WORD wFormat, LPSTR retStr, short maxlen)
{
LPCLIPFORMAT lpFormat = ClipFormats;
dprintf_clipboard(stddeb,
"GetClipboardFormat(%04X, %p, %d) !\n", wFormat, retStr, maxlen);
while(TRUE) {
if (lpFormat == NULL) return 0;
if (lpFormat->wFormatID == wFormat) break;
lpFormat = lpFormat->NextFormat;
}
if (lpFormat->Name == NULL) return 0;
dprintf_clipboard(stddeb,
"GetClipboardFormat // Name='%s' !\n", lpFormat->Name);
maxlen = min(maxlen - 1, strlen(lpFormat->Name));
dprintf_clipboard(stddeb,"GetClipboardFormat // maxlen=%d !\n", maxlen);
memcpy(retStr, lpFormat->Name, maxlen);
retStr[maxlen] = 0;
return maxlen;
}
/**************************************************************************
* SetClipboardViewer [USER.147]
*/
HWND SetClipboardViewer(HWND hWnd)
{
HWND hwndPrev = hWndViewer;
dprintf_clipboard(stddeb,"SetClipboardViewer(%04X) !\n", hWnd);
hWndViewer = hWnd;
return hwndPrev;
}
/**************************************************************************
* GetClipboardViewer [USER.148]
*/
HWND GetClipboardViewer()
{
dprintf_clipboard(stddeb,"GetClipboardFormat() = %04X !\n", hWndViewer);
return hWndViewer;
}
/**************************************************************************
* ChangeClipboardChain [USER.149]
*/
BOOL ChangeClipboardChain(HWND hWnd, HWND hWndNext)
{
dprintf_clipboard(stdnimp,
"ChangeClipboardChain(%04X, %04X) !\n", hWnd, hWndNext);
}
/**************************************************************************
* IsClipboardFormatAvailable [USER.193]
*/
BOOL IsClipboardFormatAvailable(WORD wFormat)
{
LPCLIPFORMAT lpFormat = ClipFormats;
dprintf_clipboard(stddeb,"IsClipboardFormatAvailable(%04X) !\n", wFormat);
if(wFormat == CF_TEXT && !wineOwnsSelection) /* obtain selection as text if possible */
return GetClipboardData(CF_TEXT)!=0;
while(TRUE) {
if (lpFormat == NULL) return FALSE;
if (lpFormat->wFormatID == wFormat) break;
lpFormat = lpFormat->NextFormat;
}
return (lpFormat->hData != 0);
}
/**************************************************************************
* GetOpenClipboardWindow [USER.248]
*/
HWND GetOpenClipboardWindow()
{
dprintf_clipboard(stddeb,
"GetOpenClipboardWindow() = %04X !\n", hWndClipboardOwner);
return hWndClipboardOwner;
}
/**************************************************************************
* GetPriorityClipboardFormat [USER.402]
*/
int GetPriorityClipboardFormat(WORD FAR *lpPriorityList, short nCount)
{
dprintf_clipboard(stdnimp,
"GetPriorityClipboardFormat(%p, %d) !\n", lpPriorityList, nCount);
}
/**************************************************************************
* CLIPBOARD_ReadSelection
*
* The current selection owner has set prop at our window w
* Transfer the property contents into the Clipboard
*/
void CLIPBOARD_ReadSelection(Window w,Atom prop)
{
HANDLE hText;
LPCLIPFORMAT lpFormat = ClipFormats;
if(prop==None)
hText=0;
else{
Atom atype=None;
int aformat;
unsigned long nitems,remain;
unsigned char *val=NULL;
dprintf_clipboard(stddeb,"Received prop %s\n",XGetAtomName(display,prop));
/* TODO: Properties longer than 64K */
if(XGetWindowProperty(display,w,prop,0,0x3FFF,True,XA_STRING,
&atype, &aformat, &nitems, &remain, &val)!=Success)
printf("couldn't read property\n");
dprintf_clipboard(stddeb,"Type %s,Format %d,nitems %ld,value %s\n",
XGetAtomName(display,atype),aformat,nitems,val);
if(atype!=XA_STRING || aformat!=8){
fprintf(stderr,"Property not set\n");
hText=0;
} else {
dprintf_clipboard(stddeb,"Selection is %s\n",val);
hText=GlobalAlloc(GMEM_MOVEABLE, nitems);
memcpy(GlobalLock(hText),val,nitems+1);
GlobalUnlock(hText);
}
XFree(val);
}
while(TRUE) {
if (lpFormat == NULL) return;
if (lpFormat->wFormatID == CF_TEXT) break;
lpFormat = lpFormat->NextFormat;
}
if (lpFormat->hData != 0) GlobalFree(lpFormat->hData);
wait_for_selection=False;
lpFormat->hData = hText;
dprintf_clipboard(stddeb,"Received selection\n");
}
/**************************************************************************
* CLIPBOARD_ReleaseSelection
*
* Wine lost the primary selection.
* Empty the clipboard, but don't set the current owner to None.
* Make sure current get/put attempts fail.
*/
void CLIPBOARD_ReleaseSelection(HWND hwnd)
{
wineOwnsSelection=False;
OpenClipboard(hwnd);
EmptyClipboard();
CloseClipboard();
}