[RICHEDIT] EM_STREAMIN enhancements
Krzysztof Foltman
kfoltman at portal.onet.pl
Tue Mar 8 12:23:27 CST 2005
ChangeLog:
* specialized handler for SF_TEXT (ANSI or Unicode), simple and fast
* clears control's text on EM_STREAMIN with no SFF_SELECTION
Krzysztof
-------------- next part --------------
Index: editor.c
===================================================================
RCS file: /home/wine/wine/dlls/riched20/editor.c,v
retrieving revision 1.5
diff -u -r1.5 editor.c
--- editor.c 8 Mar 2005 16:46:00 -0000 1.5
+++ editor.c 8 Mar 2005 18:22:17 -0000
@@ -306,27 +306,88 @@
return buf;
}
-static LRESULT ME_StreamIn(HWND hwnd, DWORD format, EDITSTREAM *stream)
-{
- RTF_Info parser;
+#define STREAMIN_BUFFER_SIZE 1024
- TRACE("%p %p\n", stream, hwnd);
+static LRESULT ME_StreamInText(ME_TextEditor *editor, DWORD dwFormat, EDITSTREAM *stream, ME_Style *style)
+{
+ BYTE buffer[STREAMIN_BUFFER_SIZE+1];
+ WCHAR wszText[STREAMIN_BUFFER_SIZE+1];
+
+ TRACE("%08lx %p\n", dwFormat, stream);
+ stream->dwError = 0;
+
+ do {
+ long nDataSize = 0, nWideChars = 0;
+ stream->dwError = stream->pfnCallback(stream->dwCookie,
+ (dwFormat & SF_UNICODE ? (BYTE *)wszText : buffer),
+ STREAMIN_BUFFER_SIZE, &nDataSize);
+
+ if (stream->dwError)
+ break;
+ if (!nDataSize)
+ break;
+
+ if (!(dwFormat & SF_UNICODE))
+ {
+ /* FIXME? this is doomed to fail on true MBCS like UTF-8, luckily they're unlikely to be used as CP_ACP */
+ nWideChars = MultiByteToWideChar(CP_ACP, 0, buffer, nDataSize, wszText, STREAMIN_BUFFER_SIZE);
+ }
+ else
+ nWideChars = nDataSize>>1;
+ ME_InsertTextFromCursor(editor, 0, wszText, nWideChars, style);
+ if (nDataSize<STREAMIN_BUFFER_SIZE)
+ break;
+ } while(1);
+ ME_CommitUndo(editor);
+ return 0;
+}
- /* setup the RTF parser */
- memset(&parser, 0, sizeof parser);
- RTFSetEditStream(&parser, stream);
- parser.rtfFormat = format&(SF_TEXT|SF_RTF);
- parser.hwndEdit = hwnd;
- WriterInit(&parser);
- RTFInit(&parser);
- BeginFile(&parser);
-
- /* do the parsing */
- RTFRead(&parser);
- RTFFlushOutputBuffer(&parser);
+static LRESULT ME_StreamIn(ME_TextEditor *editor, DWORD format, EDITSTREAM *stream)
+{
+ RTF_Info parser;
+ ME_Style *style;
+ FIXME("%08lx %p\n", format, stream);
+ TRACE("%p %p\n", stream, editor->hWnd);
+
+ if (format & SFF_SELECTION) {
+ style = ME_GetSelectionInsertStyle(editor);
+ SendMessageW(editor->hWnd, WM_CLEAR, 0, 0);
+ }
+ else {
+ style = editor->pBuffer->pDefaultStyle;
+ ME_AddRefStyle(style);
+ SendMessageA(editor->hWnd, EM_SETSEL, 0, 0);
+ SetWindowTextA(editor->hWnd, "");
+ ME_ClearTempStyle(editor);
+ }
+
+ if (format & SF_RTF) {
+ /* setup the RTF parser */
+ memset(&parser, 0, sizeof parser);
+ RTFSetEditStream(&parser, stream);
+ parser.rtfFormat = format&(SF_TEXT|SF_RTF);
+ parser.hwndEdit = editor->hWnd;
+ WriterInit(&parser);
+ RTFInit(&parser);
+ BeginFile(&parser);
+
+ /* do the parsing */
+ RTFRead(&parser);
+ RTFFlushOutputBuffer(&parser);
+ }
+ else if (format & SF_TEXT)
+ ME_StreamInText(editor, format, stream, style);
+ else
+ ERR("EM_STREAMIN without SF_TEXT or SF_RTF\n");
/* put the cursor at the top */
- SendMessageA(hwnd, EM_SETSEL, 0, 0);
+ if (!(format & SFF_SELECTION))
+ SendMessageA(editor->hWnd, EM_SETSEL, 0, 0);
+ else
+ {
+ /* FIXME where to put cursor now ? */
+ }
+ ME_ReleaseStyle(style);
return 0;
}
@@ -464,7 +525,7 @@
/* Messages specific to Richedit controls */
case EM_STREAMIN:
- return ME_StreamIn(hWnd, wParam, (EDITSTREAM*)lParam);
+ return ME_StreamIn(editor, wParam, (EDITSTREAM*)lParam);
case WM_GETDLGCODE:
{
UINT code = DLGC_WANTCHARS|DLGC_WANTARROWS;
@@ -606,20 +667,13 @@
case EM_REPLACESEL:
{
int from, to;
- ME_Cursor c;
ME_Style *style;
LPWSTR wszText = ME_ToUnicode(hWnd, (void *)lParam);
size_t len = lstrlenW(wszText);
TRACE("EM_REPLACESEL - %s\n", debugstr_w(wszText));
ME_GetSelection(editor, &from, &to);
- ME_CursorFromCharOfs(editor, from, &c);
- if (from != to) {
- style = c.pRun->member.run.style;
- ME_AddRefStyle(style); /* ME_GetInsertStyle has already done that */
- }
- else
- style = ME_GetInsertStyle(editor, 0);
+ style = ME_GetSelectionInsertStyle(editor);
ME_InternalDeleteText(editor, from, to-from);
ME_InsertTextFromCursor(editor, 0, wszText, len, style);
ME_ReleaseStyle(style);
Index: editor.h
===================================================================
RCS file: /home/wine/wine/dlls/riched20/editor.h,v
retrieving revision 1.3
diff -u -r1.3 editor.h
--- editor.h 8 Mar 2005 16:46:00 -0000 1.3
+++ editor.h 8 Mar 2005 18:22:17 -0000
@@ -156,6 +156,7 @@
void ME_InsertGraphicsFromCursor(ME_TextEditor *editor, int nCursor);
void ME_InternalDeleteText(ME_TextEditor *editor, int nOfs, int nChars);
int ME_GetTextLength(ME_TextEditor *editor);
+ME_Style *ME_GetSelectionInsertStyle(ME_TextEditor *editor);
/* wrap.c */
void ME_PrepareParagraphForWrapping(ME_Context *c, ME_DisplayItem *tp);
Index: caret.c
===================================================================
RCS file: /home/wine/wine/dlls/riched20/caret.c,v
retrieving revision 1.1
diff -u -r1.1 caret.c
--- caret.c 5 Mar 2005 11:19:14 -0000 1.1
+++ caret.c 8 Mar 2005 18:22:17 -0000
@@ -844,6 +844,23 @@
ME_DeleteTextAtCursor(editor, ME_GetSelCursor(editor,-1), to-from);
}
+ME_Style *ME_GetSelectionInsertStyle(ME_TextEditor *editor)
+{
+ ME_Style *style;
+ int from, to;
+ ME_Cursor c;
+
+ ME_GetSelection(editor, &from, &to);
+ ME_CursorFromCharOfs(editor, from, &c);
+ if (from != to) {
+ style = c.pRun->member.run.style;
+ ME_AddRefStyle(style); /* ME_GetInsertStyle has already done that */
+ }
+ else
+ style = ME_GetInsertStyle(editor, 0);
+ return style;
+}
+
void ME_SendSelChange(ME_TextEditor *editor)
{
SELCHANGE sc;
@@ -957,3 +974,4 @@
}
return FALSE;
}
+
More information about the wine-patches
mailing list