From 9bd259e8568f3db55e2b2d4499cd26e731c29fcc Mon Sep 17 00:00:00 2001 From: The Wine Synchronizer Date: Fri, 27 Jul 2007 10:05:21 +0000 Subject: [PATCH] Autosyncing with Wine HEAD svn path=/trunk/; revision=27917 --- reactos/dll/win32/riched20/caret.c | 19 +++- reactos/dll/win32/riched20/editor.c | 101 +++++++++++++++++---- reactos/dll/win32/riched20/editstr.h | 3 + reactos/dll/win32/riched20/reader.c | 2 +- reactos/dll/win32/riched20/riched20.rbuild | 1 + reactos/dll/win32/riched20/string.c | 4 +- reactos/dll/win32/riched20/txtsrv.c | 1 - 7 files changed, 106 insertions(+), 25 deletions(-) diff --git a/reactos/dll/win32/riched20/caret.c b/reactos/dll/win32/riched20/caret.c index 3f9547e7c25..f2ca5952487 100644 --- a/reactos/dll/win32/riched20/caret.c +++ b/reactos/dll/win32/riched20/caret.c @@ -232,21 +232,28 @@ ME_MoveCaret(ME_TextEditor *editor) ME_WrapMarkedParagraphs(editor); ME_GetCursorCoordinates(editor, &editor->pCursors[0], &x, &y, &height); - CreateCaret(editor->hWnd, NULL, 0, height); - SetCaretPos(x, y); + if(editor->bHaveFocus) + { + CreateCaret(editor->hWnd, NULL, 0, height); + SetCaretPos(x, y); + } } void ME_ShowCaret(ME_TextEditor *ed) { ME_MoveCaret(ed); - ShowCaret(ed->hWnd); + if(ed->bHaveFocus) + ShowCaret(ed->hWnd); } void ME_HideCaret(ME_TextEditor *ed) { - HideCaret(ed->hWnd); - DestroyCaret(); + if(ed->bHaveFocus) + { + HideCaret(ed->hWnd); + DestroyCaret(); + } } void ME_InternalDeleteText(ME_TextEditor *editor, int nOfs, @@ -366,6 +373,8 @@ void ME_DeleteTextAtCursor(ME_TextEditor *editor, int nCursor, int nChars) { assert(nCursor>=0 && nCursornCursors); + /* text operations set modified state */ + editor->nModifyStep = 1; ME_InternalDeleteText(editor, ME_GetCursorOfs(editor, nCursor), nChars); } diff --git a/reactos/dll/win32/riched20/editor.c b/reactos/dll/win32/riched20/editor.c index 2e2c54911d8..4cdb54a1be2 100644 --- a/reactos/dll/win32/riched20/editor.c +++ b/reactos/dll/win32/riched20/editor.c @@ -66,7 +66,7 @@ + EM_GETSELTEXT (ANSI&Unicode) + EM_GETSCROLLPOS 3.0 (only Y value valid) ! - EM_GETTHUMB - - EM_GETTEXTEX 2.0 + + EM_GETTEXTEX 2.0 + EM_GETTEXTLENGTHEX (GTL_PRECISE unimplemented) - EM_GETTEXTMODE 2.0 ? + EM_GETTEXTRANGE (ANSI&Unicode) @@ -114,7 +114,7 @@ + EM_SETSCROLLPOS 3.0 - EM_SETTABSTOPS 3.0 - EM_SETTARGETDEVICE - + EM_SETTEXTEX 3.0 (unicode only, no rich text insertion handling, proper style?) + + EM_SETTEXTEX 3.0 (no rich text insertion handling, proper style?) - EM_SETTEXTMODE 2.0 - EM_SETTYPOGRAPHYOPTIONS 3.0 + EM_SETUNDOLIMIT 2.0 @@ -226,9 +226,8 @@ #include "winreg.h" #define NO_SHLWAPI_STREAM #include "shlwapi.h" -#include "imm.h" -#include "textserv.h" #include "rtf.h" +#include "imm.h" #define STACK_SIZE_DEFAULT 100 #define STACK_SIZE_MAX 1000 @@ -1155,6 +1154,7 @@ ME_TextEditor *ME_MakeEditor(HWND hWnd) { ed->lpOleCallback = NULL; ed->mode = TM_RICHTEXT | TM_MULTILEVELUNDO | TM_MULTICODEPAGE; ed->AutoURLDetect_bEnable = FALSE; + ed->bHaveFocus = FALSE; GetClientRect(hWnd, &ed->rcFormat); for (i=0; inUndoLimit = min(wParam, STACK_SIZE_MAX); /* Setting a max stack size keeps wine from getting killed for hogging memory. Windows allocates all this memory at once, so - no program would realistically set a value above our maxiumum. */ + no program would realistically set a value above our maximum. */ return editor->nUndoLimit; } case EM_CANUNDO: @@ -1635,17 +1635,23 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam, } case EM_SETTEXTEX: { - LPWSTR wszText = (LPWSTR)lParam; + LPWSTR wszText; SETTEXTEX *pStruct = (SETTEXTEX *)wParam; - size_t len = wszText ? lstrlenW(wszText) : 0; + size_t len; int from, to; ME_Style *style; int oldModify = editor->nModifyStep; - TRACE("EM_SETTEXTEX - %s, flags %d, cp %d\n", debugstr_w(wszText), (int)pStruct->flags, pStruct->codepage); - if (pStruct->codepage != 1200) { - FIXME("EM_SETTEXTEX only supports unicode right now!\n"); - return 0; - } + + if (!pStruct) return 0; + + TRACE("EM_SETTEXTEX - %s, flags %d, cp %d\n", + pStruct->codepage == 1200 ? debugstr_w((LPCWSTR)lParam) : debugstr_a((LPCSTR)lParam), + pStruct->flags, pStruct->codepage); + + /* FIXME: make use of pStruct->codepage in the to unicode translation */ + wszText = lParam ? ME_ToUnicode(pStruct->codepage == 1200, (void *)lParam) : NULL; + len = wszText ? lstrlenW(wszText) : 0; + /* FIXME: this should support RTF strings too, according to MSDN */ if (pStruct->flags & ST_SELECTION) { ME_GetSelection(editor, &from, &to); @@ -2001,7 +2007,7 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam, nStart = 0; nCount = ex->cb - 1; } - if (ex->codepage == 1200 || unicode) + if (ex->codepage == 1200) { nCount = min(nCount, ex->cb / sizeof(WCHAR) - 1); return ME_GetTextW(editor, (LPWSTR)lParam, nStart, nCount, ex->flags & GT_USECRLF); @@ -2018,6 +2024,7 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam, buflen = ME_GetTextW(editor, buffer, nStart, nCount, ex->flags & GT_USECRLF); rc = WideCharToMultiByte(ex->codepage, flags, buffer, -1, (LPSTR)lParam, ex->cb, ex->lpDefaultChar, ex->lpUsedDefaultChar); + if (rc) rc--; /* do not count 0 terminator */ richedit_free(buffer); return rc; @@ -2183,7 +2190,7 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam, nNextLineOfs = ME_FindItemFwd(item, diParagraphOrEnd)->member.para.nCharOfs - (editor->bEmulateVersion10?2:1); nChars = nNextLineOfs - nThisLineOfs; - TRACE("EM_LINELENGTH(%d)==%d\n",wParam, nChars); + TRACE("EM_LINELENGTH(%ld)==%d\n",wParam, nChars); return nChars; } case EM_EXLIMITTEXT: @@ -2330,11 +2337,13 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam, } break; case WM_SETFOCUS: + editor->bHaveFocus = TRUE; ME_ShowCaret(editor); ME_SendOldNotify(editor, EN_SETFOCUS); return 0; case WM_KILLFOCUS: ME_HideCaret(editor); + editor->bHaveFocus = FALSE; ME_SendOldNotify(editor, EN_KILLFOCUS); return 0; case WM_ERASEBKGND: @@ -2507,6 +2516,64 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam, ME_RewrapRepaint(editor); return DefWindowProcW(hWnd, msg, wParam, lParam); } + /* IME messages to make richedit controls IME aware */ + case WM_IME_SETCONTEXT: + case WM_IME_CONTROL: + case WM_IME_SELECT: + case WM_IME_COMPOSITIONFULL: + return 0; + case WM_IME_STARTCOMPOSITION: + { + editor->imeStartIndex=ME_GetCursorOfs(editor,0); + ME_DeleteSelection(editor); + ME_CommitUndo(editor); + ME_UpdateRepaint(editor); + return 0; + } + case WM_IME_COMPOSITION: + { + HIMC hIMC; + + ME_Style *style = ME_GetInsertStyle(editor, 0); + hIMC = ImmGetContext(hWnd); + ME_DeleteSelection(editor); + ME_CommitUndo(editor); + ME_SaveTempStyle(editor); + if (lParam & GCS_RESULTSTR) + { + LPWSTR lpCompStr = NULL; + DWORD dwBufLen; + + dwBufLen = ImmGetCompositionStringW(hIMC, GCS_RESULTSTR, NULL, 0); + lpCompStr = HeapAlloc(GetProcessHeap(),0,dwBufLen + sizeof(WCHAR)); + ImmGetCompositionStringW(hIMC, GCS_RESULTSTR, lpCompStr, dwBufLen); + lpCompStr[dwBufLen/sizeof(WCHAR)] = 0; + ME_InsertTextFromCursor(editor,0,lpCompStr,dwBufLen/sizeof(WCHAR),style); + } + else if (lParam & GCS_COMPSTR) + { + LPWSTR lpCompStr = NULL; + DWORD dwBufLen; + + dwBufLen = ImmGetCompositionStringW(hIMC, GCS_COMPSTR, NULL, 0); + lpCompStr = HeapAlloc(GetProcessHeap(),0,dwBufLen + sizeof(WCHAR)); + ImmGetCompositionStringW(hIMC, GCS_COMPSTR, lpCompStr, dwBufLen); + lpCompStr[dwBufLen/sizeof(WCHAR)] = 0; + + ME_InsertTextFromCursor(editor,0,lpCompStr,dwBufLen/sizeof(WCHAR),style); + ME_SetSelection(editor,editor->imeStartIndex, + editor->imeStartIndex + dwBufLen/sizeof(WCHAR)); + } + ME_ReleaseStyle(style); + ME_UpdateRepaint(editor); + return 0; + } + case WM_IME_ENDCOMPOSITION: + { + ME_DeleteSelection(editor); + editor->imeStartIndex=-1; + return 0; + } case EM_GETOLEINTERFACE: { LPVOID *ppvObj = (LPVOID*) lParam; @@ -2789,14 +2856,14 @@ static BOOL ME_RegisterEditorClass(HINSTANCE hInstance) LRESULT WINAPI REComboWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { /* FIXME: Not implemented */ - TRACE("hWnd %p msg %04x (%s) %08x %08lx\n", + TRACE("hWnd %p msg %04x (%s) %08lx %08lx\n", hWnd, msg, get_msg_name(msg), wParam, lParam); return DefWindowProcW(hWnd, msg, wParam, lParam); } LRESULT WINAPI REListWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { /* FIXME: Not implemented */ - TRACE("hWnd %p msg %04x (%s) %08x %08lx\n", + TRACE("hWnd %p msg %04x (%s) %08lx %08lx\n", hWnd, msg, get_msg_name(msg), wParam, lParam); return DefWindowProcW(hWnd, msg, wParam, lParam); } diff --git a/reactos/dll/win32/riched20/editstr.h b/reactos/dll/win32/riched20/editstr.h index 9859fe78e8a..7bb91d52445 100644 --- a/reactos/dll/win32/riched20/editstr.h +++ b/reactos/dll/win32/riched20/editstr.h @@ -321,6 +321,9 @@ typedef struct tagME_TextEditor BOOL bHideSelection; BOOL AutoURLDetect_bEnable; WCHAR cPasswordMask; + BOOL bHaveFocus; + /*for IME */ + int imeStartIndex; } ME_TextEditor; typedef struct tagME_Context diff --git a/reactos/dll/win32/riched20/reader.c b/reactos/dll/win32/riched20/reader.c index 7fb641bd52e..0cf8ca7f561 100644 --- a/reactos/dll/win32/riched20/reader.c +++ b/reactos/dll/win32/riched20/reader.c @@ -2682,7 +2682,7 @@ static void RTFFlushCPOutputBuffer(RTF_Info *info) { int bufferMax = info->dwCPOutputCount * 2 * sizeof(WCHAR); - WCHAR *buffer = (WCHAR *)RTFAlloc(bufferMax); + WCHAR *buffer = RTFAlloc(bufferMax); int length; length = MultiByteToWideChar(info->codePage, 0, info->cpOutputBuffer, diff --git a/reactos/dll/win32/riched20/riched20.rbuild b/reactos/dll/win32/riched20/riched20.rbuild index 37eafa87e83..0f25da92fa1 100644 --- a/reactos/dll/win32/riched20/riched20.rbuild +++ b/reactos/dll/win32/riched20/riched20.rbuild @@ -10,6 +10,7 @@ 0x501 wine ole32 + imm32 user32 gdi32 kernel32 diff --git a/reactos/dll/win32/riched20/string.c b/reactos/dll/win32/riched20/string.c index 4c4491158d5..10f62397afa 100644 --- a/reactos/dll/win32/riched20/string.c +++ b/reactos/dll/win32/riched20/string.c @@ -130,7 +130,7 @@ ME_String *ME_VSplitString(ME_String *orig, int charidx) s = ME_MakeString(orig->szData+charidx); orig->nLen = charidx; - orig->szData[charidx] = L'\0'; + orig->szData[charidx] = '\0'; return s; } @@ -347,6 +347,8 @@ ME_CallWordBreakProc(ME_TextEditor *editor, ME_String *str, INT start, INT code) LPWSTR ME_ToUnicode(BOOL unicode, LPVOID psz) { + assert(psz != NULL); + if (unicode) return (LPWSTR)psz; else { diff --git a/reactos/dll/win32/riched20/txtsrv.c b/reactos/dll/win32/riched20/txtsrv.c index 069c916534e..95d6f7cb496 100644 --- a/reactos/dll/win32/riched20/txtsrv.c +++ b/reactos/dll/win32/riched20/txtsrv.c @@ -28,7 +28,6 @@ #include "editor.h" #include "ole2.h" #include "richole.h" -#include "winreg.h" #include "imm.h" #include "textserv.h" #include "wine/debug.h"