Commit a1324584 authored by Kevin Koltzau's avatar Kevin Koltzau Committed by Alexandre Julliard

riched20: Add IDataObject implementation and use it for cut/copy.

parent a8b20975
......@@ -9,6 +9,7 @@ EXTRALIBS = $(LIBUNICODE) -luuid
C_SRCS = \
caret.c \
clipboard.c \
context.c \
editor.c \
list.c \
......
......@@ -1041,29 +1041,6 @@ typedef struct tagME_GlobalDestStruct
int nLength;
} ME_GlobalDestStruct;
static DWORD CALLBACK ME_AppendToHGLOBAL(DWORD_PTR dwCookie, LPBYTE lpBuff, LONG cb, LONG *pcb)
{
ME_GlobalDestStruct *pData = (ME_GlobalDestStruct *)dwCookie;
int nMaxSize;
BYTE *pDest;
nMaxSize = GlobalSize(pData->hData);
if (pData->nLength+cb+1 >= cb)
{
/* round up to 2^17 */
int nNewSize = (((nMaxSize+cb+1)|0x1FFFF)+1) & 0xFFFE0000;
pData->hData = GlobalReAlloc(pData->hData, nNewSize, 0);
}
pDest = (BYTE *)GlobalLock(pData->hData);
memcpy(pDest + pData->nLength, lpBuff, cb);
pData->nLength += cb;
pDest[pData->nLength] = '\0';
GlobalUnlock(pData->hData);
*pcb = cb;
return 0;
}
static DWORD CALLBACK ME_ReadFromHGLOBALUnicode(DWORD_PTR dwCookie, LPBYTE lpBuff, LONG cb, LONG *pcb)
{
ME_GlobalDestStruct *pData = (ME_GlobalDestStruct *)dwCookie;
......@@ -1790,38 +1767,18 @@ LRESULT WINAPI RichEditANSIWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lP
case WM_CUT:
case WM_COPY:
{
int from, to, pars;
WCHAR *data;
HANDLE hData;
EDITSTREAM es;
ME_GlobalDestStruct gds;
if (!OpenClipboard(hWnd))
return 0;
EmptyClipboard();
ME_GetSelection(editor, &from, &to);
pars = ME_CountParagraphsBetween(editor, from, to);
hData = GlobalAlloc(GMEM_MOVEABLE, sizeof(WCHAR)*(to-from+pars+1));
data = (WCHAR *)GlobalLock(hData);
ME_GetTextW(editor, data, from, to-from, TRUE);
GlobalUnlock(hData);
if (editor->mode & TM_RICHTEXT)
{
gds.hData = GlobalAlloc(GMEM_MOVEABLE, 0);
gds.nLength = 0;
es.dwCookie = (DWORD)&gds;
es.pfnCallback = ME_AppendToHGLOBAL;
ME_StreamOutRange(editor, SF_RTF, from, to, &es);
GlobalReAlloc(gds.hData, gds.nLength+1, 0);
SetClipboardData(RegisterClipboardFormatA("Rich Text Format"), gds.hData);
LPDATAOBJECT dataObj;
CHARRANGE range;
HRESULT hr;
ME_GetSelection(editor, (int*)&range.cpMin, (int*)&range.cpMax);
hr = ME_GetDataObject(editor, &range, &dataObj);
if(SUCCEEDED(hr)) {
hr = OleSetClipboard(dataObj);
IDataObject_Release(dataObj);
}
SetClipboardData(CF_UNICODETEXT, hData);
CloseClipboard();
if (msg == WM_CUT)
if (SUCCEEDED(hr) && msg == WM_CUT)
{
ME_InternalDeleteText(editor, from, to-from);
ME_InternalDeleteText(editor, range.cpMin, range.cpMax-range.cpMin);
ME_CommitUndo(editor);
ME_UpdateRepaint(editor);
}
......
......@@ -28,6 +28,15 @@
#define RUN_IS_HIDDEN(run) ((run)->style->fmt.dwMask & CFM_HIDDEN \
&& (run)->style->fmt.dwEffects & CFE_HIDDEN)
#define InitFormatEtc(fe, cf, med) \
{\
(fe).cfFormat=cf;\
(fe).dwAspect=DVASPECT_CONTENT;\
(fe).ptd=NULL;\
(fe).tymed=med;\
(fe).lindex=-1;\
};
/* style.c */
ME_Style *ME_MakeStyle(CHARFORMAT2W *style);
void ME_AddRefStyle(ME_Style *item);
......@@ -249,3 +258,6 @@ extern void DoWrap(ME_TextEditor *editor);
/* writer.c */
LRESULT ME_StreamOutRange(ME_TextEditor *editor, DWORD dwFormat, int nStart, int nTo, EDITSTREAM *stream);
LRESULT ME_StreamOut(ME_TextEditor *editor, DWORD dwFormat, EDITSTREAM *stream);
/* clipboard.c */
HRESULT ME_GetDataObject(ME_TextEditor *editor, CHARRANGE *lpchrg, LPDATAOBJECT *lplpdataobj);
......@@ -30,6 +30,10 @@
#include <stdio.h>
#include <stdlib.h>
#define COBJMACROS
#define NONAMELESSUNION
#define NONAMELESSSTRUCT
#include <windef.h>
#include <winbase.h>
#include <winnls.h>
......@@ -38,7 +42,6 @@
#include <winuser.h>
#include <richedit.h>
#include <commctrl.h>
#define COBJMACROS
#include <ole2.h>
#include <richole.h>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment