Skip to content

Commit

Permalink
[RICHED20] Sync with Wine Staging 2.16. CORE-13762
Browse files Browse the repository at this point in the history
58cac9c riched20: Remove the separate implementation of IOleWindow as IOleInPlaceSite inherits from IOleWindow.
adf53a9 riched20: Add support for pasting EMFs.
bbf34a4 riched20: Use the implementation of EM_PASTESPECIAL for EM_CANPASTE.
46fef3d riched20: Use the implementation of EM_PASTESPECIAL for WM_PASTE.
9bec53f riched20: Add support for EM_PASTESPECIAL.
417c80d riched20: Don't create a special richedit ole instance for the RTF parser.
1bc48be riched20: Initialize ME_TextEditor members in ME_MakeEditor().
5cc8c9f riched20: Retrieve the default paragraph alignment from the text host.
4cb7578 riched20: Move the editor initialization out of CreateTextHost().
2d91663 riched20: New high resolution cursor generated from SVG.
17b7cde riched20: The background colour is set using \highlight.

svn path=/trunk/; revision=75896
  • Loading branch information
AmineKhaldi committed Sep 17, 2017
1 parent ac45094 commit ec29185
Show file tree
Hide file tree
Showing 12 changed files with 213 additions and 147 deletions.
221 changes: 162 additions & 59 deletions reactos/dll/win32/riched20/editor.c
Expand Up @@ -1119,8 +1119,8 @@ void ME_RTFSpecialCharHook(RTF_Info *info)
}
}

static BOOL ME_RTFInsertOleObject(RTF_Info *info, HENHMETAFILE hemf, HBITMAP hbmp,
const SIZEL* sz)
static HRESULT insert_static_object(ME_TextEditor *editor, HENHMETAFILE hemf, HBITMAP hbmp,
const SIZEL* sz)
{
LPOLEOBJECT lpObject = NULL;
LPSTORAGE lpStorage = NULL;
Expand All @@ -1130,7 +1130,7 @@ static BOOL ME_RTFInsertOleObject(RTF_Info *info, HENHMETAFILE hemf, HBITMAP hbm
STGMEDIUM stgm;
FORMATETC fm;
CLSID clsid;
BOOL ret = FALSE;
HRESULT hr = E_FAIL;
DWORD conn;

if (hemf)
Expand All @@ -1152,13 +1152,14 @@ static BOOL ME_RTFInsertOleObject(RTF_Info *info, HENHMETAFILE hemf, HBITMAP hbm
fm.lindex = -1;
fm.tymed = stgm.tymed;

if (!info->lpRichEditOle)
if (!editor->reOle)
{
CreateIRichEditOle(NULL, info->editor, (VOID**)&info->lpRichEditOle);
if (!CreateIRichEditOle(NULL, editor, (LPVOID *)&editor->reOle))
return hr;
}

if (OleCreateDefaultHandler(&CLSID_NULL, NULL, &IID_IOleObject, (void**)&lpObject) == S_OK &&
IRichEditOle_GetClientSite(info->lpRichEditOle, &lpClientSite) == S_OK &&
IRichEditOle_GetClientSite(editor->reOle, &lpClientSite) == S_OK &&
IOleObject_SetClientSite(lpObject, lpClientSite) == S_OK &&
IOleObject_GetUserClassID(lpObject, &clsid) == S_OK &&
IOleObject_QueryInterface(lpObject, &IID_IOleCache, (void**)&lpOleCache) == S_OK &&
Expand All @@ -1181,8 +1182,8 @@ static BOOL ME_RTFInsertOleObject(RTF_Info *info, HENHMETAFILE hemf, HBITMAP hbm
reobject.dwFlags = 0; /* FIXME */
reobject.dwUser = 0;

ME_InsertOLEFromCursor(info->editor, &reobject, 0);
ret = TRUE;
ME_InsertOLEFromCursor(editor, &reobject, 0);
hr = S_OK;
}

if (lpObject) IOleObject_Release(lpObject);
Expand All @@ -1191,7 +1192,7 @@ static BOOL ME_RTFInsertOleObject(RTF_Info *info, HENHMETAFILE hemf, HBITMAP hbm
if (lpDataObject) IDataObject_Release(lpDataObject);
if (lpOleCache) IOleCache_Release(lpOleCache);

return ret;
return hr;
}

static void ME_RTFReadShpPictGroup( RTF_Info *info )
Expand Down Expand Up @@ -1350,11 +1351,11 @@ static void ME_RTFReadPictGroup(RTF_Info *info)
{
case gfx_enhmetafile:
if ((hemf = SetEnhMetaFileBits( size, buffer )))
ME_RTFInsertOleObject( info, hemf, NULL, &sz );
insert_static_object( info->editor, hemf, NULL, &sz );
break;
case gfx_metafile:
if ((hemf = SetWinMetaFileBits( size, buffer, NULL, &mfp )))
ME_RTFInsertOleObject( info, hemf, NULL, &sz );
insert_static_object( info->editor, hemf, NULL, &sz );
break;
case gfx_dib:
{
Expand All @@ -1368,7 +1369,7 @@ static void ME_RTFReadPictGroup(RTF_Info *info)
if ((hbmp = CreateDIBitmap( hdc, &bi->bmiHeader,
CBM_INIT, (char*)(bi + 1) + nc * sizeof(RGBQUAD),
bi, DIB_RGB_COLORS)) )
ME_RTFInsertOleObject( info, NULL, hbmp, &sz );
insert_static_object( info->editor, NULL, hbmp, &sz );
ReleaseDC( 0, hdc );
break;
}
Expand Down Expand Up @@ -1724,8 +1725,6 @@ static LRESULT ME_StreamIn(ME_TextEditor *editor, DWORD format, EDITSTREAM *stre
}
ME_CheckTablesForCorruption(editor);
RTFDestroy(&parser);
if (parser.lpRichEditOle)
IRichEditOle_Release(parser.lpRichEditOle);

if (parser.stackTop > 0)
{
Expand Down Expand Up @@ -2207,31 +2206,122 @@ static DWORD CALLBACK ME_ReadFromHGLOBALRTF(DWORD_PTR dwCookie, LPBYTE lpBuff, L
return 0;
}

static BOOL ME_Paste(ME_TextEditor *editor)
static const WCHAR rtfW[] = {'R','i','c','h',' ','T','e','x','t',' ','F','o','r','m','a','t',0};

static HRESULT paste_rtf(ME_TextEditor *editor, FORMATETC *fmt, STGMEDIUM *med)
{
DWORD dwFormat = 0;
EDITSTREAM es;
ME_GlobalDestStruct gds;
UINT nRTFFormat = RegisterClipboardFormatA("Rich Text Format");
UINT cf = 0;

if (IsClipboardFormatAvailable(nRTFFormat))
cf = nRTFFormat, dwFormat = SF_RTF;
else if (IsClipboardFormatAvailable(CF_UNICODETEXT))
cf = CF_UNICODETEXT, dwFormat = SF_TEXT|SF_UNICODE;
else
return FALSE;
EDITSTREAM es;
ME_GlobalDestStruct gds;
HRESULT hr;

gds.hData = med->u.hGlobal;
gds.nLength = 0;
es.dwCookie = (DWORD_PTR)&gds;
es.pfnCallback = ME_ReadFromHGLOBALRTF;
hr = ME_StreamIn( editor, SF_RTF | SFF_SELECTION, &es, FALSE ) == 0 ? E_FAIL : S_OK;
ReleaseStgMedium( med );
return hr;
}

if (!OpenClipboard(editor->hWnd))
return FALSE;
gds.hData = GetClipboardData(cf);
gds.nLength = 0;
es.dwCookie = (DWORD_PTR)&gds;
es.pfnCallback = dwFormat == SF_RTF ? ME_ReadFromHGLOBALRTF : ME_ReadFromHGLOBALUnicode;
ME_StreamIn(editor, dwFormat|SFF_SELECTION, &es, FALSE);
static HRESULT paste_text(ME_TextEditor *editor, FORMATETC *fmt, STGMEDIUM *med)
{
EDITSTREAM es;
ME_GlobalDestStruct gds;
HRESULT hr;

gds.hData = med->u.hGlobal;
gds.nLength = 0;
es.dwCookie = (DWORD_PTR)&gds;
es.pfnCallback = ME_ReadFromHGLOBALUnicode;
hr = ME_StreamIn( editor, SF_TEXT | SF_UNICODE | SFF_SELECTION, &es, FALSE ) == 0 ? E_FAIL : S_OK;
ReleaseStgMedium( med );
return hr;
}

CloseClipboard();
return TRUE;
static HRESULT paste_emf(ME_TextEditor *editor, FORMATETC *fmt, STGMEDIUM *med)
{
HRESULT hr;
SIZEL sz = {0, 0};

hr = insert_static_object( editor, med->u.hEnhMetaFile, NULL, &sz );
if (SUCCEEDED(hr))
{
ME_CommitUndo( editor );
ME_UpdateRepaint( editor, FALSE );
}
else
ReleaseStgMedium( med );

return hr;
}

static struct paste_format
{
FORMATETC fmt;
HRESULT (*paste)(ME_TextEditor *, FORMATETC *, STGMEDIUM *);
const WCHAR *name;
} paste_formats[] =
{
{{ -1, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL }, paste_rtf, rtfW },
{{ CF_UNICODETEXT, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL }, paste_text },
{{ CF_ENHMETAFILE, NULL, DVASPECT_CONTENT, -1, TYMED_ENHMF }, paste_emf },
{{ 0 }}
};

static void init_paste_formats(void)
{
struct paste_format *format;
static int done;

if (!done)
{
for (format = paste_formats; format->fmt.cfFormat; format++)
{
if (format->name)
format->fmt.cfFormat = RegisterClipboardFormatW( format->name );
}
done = 1;
}
}

static BOOL paste_special(ME_TextEditor *editor, UINT cf, REPASTESPECIAL *ps, BOOL check_only)
{
HRESULT hr;
STGMEDIUM med;
struct paste_format *format;
IDataObject *data;

init_paste_formats();

if (ps && ps->dwAspect != DVASPECT_CONTENT)
FIXME("Ignoring aspect %x\n", ps->dwAspect);

hr = OleGetClipboard( &data );
if (hr != S_OK) return FALSE;

if (cf == CF_TEXT) cf = CF_UNICODETEXT;

hr = S_FALSE;
for (format = paste_formats; format->fmt.cfFormat; format++)
{
if (cf && cf != format->fmt.cfFormat) continue;
hr = IDataObject_QueryGetData( data, &format->fmt );
if (hr == S_OK)
{
if (!check_only)
{
hr = IDataObject_GetData( data, &format->fmt, &med );
if (hr != S_OK) goto done;
hr = format->paste( editor, &format->fmt, &med );
}
break;
}
}

done:
IDataObject_Release( data );

return hr == S_OK;
}

static BOOL ME_Copy(ME_TextEditor *editor, const ME_Cursor *start, int nChars)
Expand Down Expand Up @@ -2547,7 +2637,7 @@ ME_KeyDown(ME_TextEditor *editor, WORD nKey)
break;
case 'V':
if (ctrl_is_down)
return ME_Paste(editor);
return paste_special( editor, 0, NULL, FALSE );
break;
case 'C':
case 'X':
Expand Down Expand Up @@ -2881,7 +2971,7 @@ static BOOL ME_ShowContextMenu(ME_TextEditor *editor, int x, int y)
return TRUE;
}

ME_TextEditor *ME_MakeEditor(ITextHost *texthost, BOOL bEmulateVersion10, DWORD csStyle)
ME_TextEditor *ME_MakeEditor(ITextHost *texthost, BOOL bEmulateVersion10)
{
ME_TextEditor *ed = ALLOC_OBJ(ME_TextEditor);
int i;
Expand All @@ -2895,11 +2985,7 @@ ME_TextEditor *ME_MakeEditor(ITextHost *texthost, BOOL bEmulateVersion10, DWORD
ed->reOle = NULL;
ed->bEmulateVersion10 = bEmulateVersion10;
ed->styleFlags = 0;
ed->alignStyle = PFA_LEFT;
if (csStyle & ES_RIGHT)
ed->alignStyle = PFA_RIGHT;
if (csStyle & ES_CENTER)
ed->alignStyle = PFA_CENTER;
ed->exStyleFlags = 0;
ITextHost_TxGetPropertyBits(texthost,
(TXTBIT_RICHTEXT|TXTBIT_MULTILINE|
TXTBIT_READONLY|TXTBIT_USEPASSWORD|
Expand Down Expand Up @@ -2960,6 +3046,7 @@ ME_TextEditor *ME_MakeEditor(ITextHost *texthost, BOOL bEmulateVersion10, DWORD
}

ME_CheckCharOffsets(ed);
SetRectEmpty(&ed->rcFormat);
ed->bDefaultFormatRect = TRUE;
ITextHost_TxGetSelectionBarWidth(ed->texthost, &selbarwidth);
if (selbarwidth) {
Expand Down Expand Up @@ -3411,7 +3498,6 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
UNSUPPORTED_MSG(EM_GETTYPOGRAPHYOPTIONS)
UNSUPPORTED_MSG(EM_GETUNDONAME)
UNSUPPORTED_MSG(EM_GETWORDBREAKPROCEX)
UNSUPPORTED_MSG(EM_PASTESPECIAL)
UNSUPPORTED_MSG(EM_SELECTIONTYPE)
UNSUPPORTED_MSG(EM_SETBIDIOPTIONS)
UNSUPPORTED_MSG(EM_SETEDITSTYLE)
Expand Down Expand Up @@ -3968,17 +4054,14 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
return 1;
}
case EM_CANPASTE:
{
UINT nRTFFormat = RegisterClipboardFormatA("Rich Text Format");
if (IsClipboardFormatAvailable(nRTFFormat))
return TRUE;
if (IsClipboardFormatAvailable(CF_UNICODETEXT))
return TRUE;
return FALSE;
}
return paste_special( editor, 0, NULL, TRUE );
case WM_PASTE:
case WM_MBUTTONDOWN:
ME_Paste(editor);
wParam = 0;
lParam = 0;
/* fall through */
case EM_PASTESPECIAL:
paste_special( editor, wParam, (REPASTESPECIAL *)lParam, FALSE );
return 0;
case WM_CUT:
case WM_COPY:
Expand Down Expand Up @@ -4789,6 +4872,30 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
return 0L;
}

static BOOL create_windowed_editor(HWND hwnd, CREATESTRUCTW *create, BOOL emulate_10)
{
ITextHost *host = ME_CreateTextHost( hwnd, create, emulate_10 );
ME_TextEditor *editor;

if (!host) return FALSE;

editor = ME_MakeEditor( host, emulate_10 );
if (!editor)
{
ITextHost_Release( host );
return FALSE;
}

editor->exStyleFlags = GetWindowLongW( hwnd, GWL_EXSTYLE );
editor->styleFlags |= GetWindowLongW( hwnd, GWL_STYLE ) & ES_WANTRETURN;
editor->hWnd = hwnd; /* FIXME: Remove editor's dependence on hWnd */
editor->hwndParent = create->hwndParent;

SetWindowLongPtrW( hwnd, 0, (LONG_PTR)editor );

return TRUE;
}

static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam,
LPARAM lParam, BOOL unicode)
{
Expand All @@ -4805,11 +4912,9 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam,
if (msg == WM_NCCREATE)
{
CREATESTRUCTW *pcs = (CREATESTRUCTW *)lParam;
ITextHost *texthost;

TRACE("WM_NCCREATE: hWnd %p style 0x%08x\n", hWnd, pcs->style);
texthost = ME_CreateTextHost(hWnd, pcs, FALSE);
return texthost != NULL;
return create_windowed_editor( hWnd, pcs, FALSE );
}
else
{
Expand Down Expand Up @@ -4935,12 +5040,10 @@ LRESULT WINAPI RichEdit10ANSIWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM
{
if (msg == WM_NCCREATE && !GetWindowLongPtrW(hWnd, 0))
{
ITextHost *texthost;
CREATESTRUCTW *pcs = (CREATESTRUCTW *)lParam;

TRACE("WM_NCCREATE: hWnd %p style 0x%08x\n", hWnd, pcs->style);
texthost = ME_CreateTextHost(hWnd, pcs, TRUE);
return texthost != NULL;
return create_windowed_editor( hWnd, pcs, TRUE );
}
return RichEditANSIWndProc(hWnd, msg, wParam, lParam);
}
Expand Down
2 changes: 1 addition & 1 deletion reactos/dll/win32/riched20/editor.h
Expand Up @@ -290,7 +290,7 @@ void ME_DeleteReObject(REOBJECT* reo) DECLSPEC_HIDDEN;
void ME_GetITextDocumentInterface(IRichEditOle *iface, LPVOID *ppvObj) DECLSPEC_HIDDEN;

/* editor.c */
ME_TextEditor *ME_MakeEditor(ITextHost *texthost, BOOL bEmulateVersion10, DWORD csStyle) DECLSPEC_HIDDEN;
ME_TextEditor *ME_MakeEditor(ITextHost *texthost, BOOL bEmulateVersion10) DECLSPEC_HIDDEN;
void ME_DestroyEditor(ME_TextEditor *editor) DECLSPEC_HIDDEN;
LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
LPARAM lParam, BOOL unicode, HRESULT* phresult) DECLSPEC_HIDDEN;
Expand Down
1 change: 0 additions & 1 deletion reactos/dll/win32/riched20/editstr.h
Expand Up @@ -353,7 +353,6 @@ typedef struct tagME_TextEditor
ME_TextBuffer *pBuffer;
ME_Cursor *pCursors;
DWORD styleFlags;
DWORD alignStyle;
DWORD exStyleFlags;
int nCursors;
SIZE sizeWindow;
Expand Down
Binary file modified reactos/dll/win32/riched20/ocr_reverse.cur
Binary file not shown.

0 comments on commit ec29185

Please sign in to comment.