riched20: Store reference to editor in ole interface.
[wine/multimedia.git] / dlls / riched20 / editor.c
blob705cae6c63cf48263e981a3c024132412215ce2a
1 /*
2 * RichEdit - functions dealing with editor object
4 * Copyright 2004 by Krzysztof Foltman
5 * Copyright 2005 by Cihan Altinay
6 * Copyright 2005 by Phil Krylov
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 /*
24 API implementation status:
26 Messages (ANSI versions not done yet)
27 - EM_AUTOURLDETECT 2.0
28 + EM_CANPASTE
29 + EM_CANREDO 2.0
30 + EM_CANUNDO
31 + EM_CHARFROMPOS
32 - EM_DISPLAYBAND
33 + EM_EMPTYUNDOBUFFER
34 + EM_EXGETSEL
35 - EM_EXLIMITTEXT
36 + EM_EXLINEFROMCHAR
37 + EM_EXSETSEL
38 + EM_FINDTEXT (only FR_DOWN flag implemented)
39 + EM_FINDTEXTEX (only FR_DOWN flag implemented)
40 - EM_FINDWORDBREAK
41 - EM_FMTLINES
42 - EM_FORMATRANGE
43 - EM_GETAUTOURLDETECT 2.0
44 - EM_GETBIDIOPTIONS 3.0
45 - EM_GETCHARFORMAT (partly done)
46 - EM_GETEDITSTYLE
47 + EM_GETEVENTMASK
48 + EM_GETFIRSTVISIBLELINE (can be optimized if needed)
49 - EM_GETIMECOLOR 1.0asian
50 - EM_GETIMECOMPMODE 2.0
51 - EM_GETIMEOPTIONS 1.0asian
52 - EM_GETIMESTATUS
53 - EM_GETLANGOPTIONS 2.0
54 - EM_GETLIMITTEXT
55 - EM_GETLINE
56 + EM_GETLINECOUNT returns number of rows, not of paragraphs
57 + EM_GETMODIFY
58 - EM_GETOLEINTERFACE
59 + EM_GETOPTIONS
60 + EM_GETPARAFORMAT
61 - EM_GETPASSWORDCHAR 2.0
62 - EM_GETPUNCTUATION 1.0asian
63 + EM_GETRECT
64 - EM_GETREDONAME 2.0
65 + EM_GETSEL
66 + EM_GETSELTEXT (ANSI&Unicode)
67 + EM_GETSCROLLPOS 3.0 (only Y value valid)
68 ! - EM_GETTHUMB
69 - EM_GETTEXTEX 2.0
70 + EM_GETTEXTLENGTHEX (GTL_PRECISE unimplemented)
71 - EM_GETTEXTMODE 2.0
72 ? + EM_GETTEXTRANGE (ANSI&Unicode)
73 - EM_GETTYPOGRAPHYOPTIONS 3.0
74 - EM_GETUNDONAME
75 + EM_GETWORDBREAKPROC
76 - EM_GETWORDBREAKPROCEX
77 - EM_GETWORDWRAPMODE 1.0asian
78 + EM_GETZOOM 3.0
79 - EM_HIDESELECTION
80 - EM_LIMITTEXT
81 + EM_LINEFROMCHAR
82 + EM_LINEINDEX
83 + EM_LINELENGTH
84 + EM_LINESCROLL
85 - EM_PASTESPECIAL
86 + EM_POSFROMCHAR
87 + EM_REDO 2.0
88 + EM_REQUESTRESIZE
89 + EM_REPLACESEL (proper style?) ANSI&Unicode
90 - EM_SCROLL
91 + EM_SCROLLCARET
92 - EM_SELECTIONTYPE
93 - EM_SETBIDIOPTIONS 3.0
94 + EM_SETBKGNDCOLOR
95 - EM_SETCHARFORMAT (partly done, no ANSI)
96 - EM_SETEDITSTYLE
97 + EM_SETEVENTMASK (few notifications supported)
98 - EM_SETFONTSIZE
99 - EM_SETIMECOLOR 1.0asian
100 - EM_SETIMEOPTIONS 1.0asian
101 - EM_SETLANGOPTIONS 2.0
102 - EM_SETLIMITTEXT
103 + EM_SETMODIFY (not sure if implementation is correct)
104 - EM_SETOLECALLBACK
105 + EM_SETOPTIONS (partially implemented)
106 - EM_SETPALETTE 2.0
107 + EM_SETPARAFORMAT
108 - EM_SETPASSWORDCHAR 2.0
109 - EM_SETPUNCTUATION 1.0asian
110 + EM_SETREADONLY no beep on modification attempt
111 + EM_SETRECT
112 + EM_SETRECTNP (EM_SETRECT without repainting)
113 + EM_SETSEL
114 - EM_SETSCROLLPOS 3.0
115 - EM_SETTABSTOPS 3.0
116 - EM_SETTARGETDEVICE
117 + EM_SETTEXTEX 3.0 (unicode only, no rich text insertion handling, proper style?)
118 - EM_SETTEXTMODE 2.0
119 - EM_SETTYPOGRAPHYOPTIONS 3.0
120 - EM_SETUNDOLIMIT 2.0
121 + EM_SETWORDBREAKPROC (used only for word movement at the moment)
122 - EM_SETWORDBREAKPROCEX
123 - EM_SETWORDWRAPMODE 1.0asian
124 + EM_SETZOOM 3.0
125 - EM_SHOWSCROLLBAR 2.0
126 - EM_STOPGROUPTYPING 2.0
127 + EM_STREAMIN
128 + EM_STREAMOUT
129 + EM_UNDO
130 + WM_CHAR
131 + WM_CLEAR
132 + WM_COPY
133 + WM_CUT
134 + WM_GETDLGCODE (the current implementation is incomplete)
135 + WM_GETTEXT (ANSI&Unicode)
136 + WM_GETTEXTLENGTH (ANSI version sucks)
137 + WM_PASTE
138 - WM_SETFONT
139 + WM_SETTEXT (resets undo stack !) (proper style?) ANSI&Unicode
140 - WM_STYLECHANGING
141 - WM_STYLECHANGED (things like read-only flag)
142 - WM_UNICHAR
144 Notifications
146 * EN_CHANGE (sent from the wrong place)
147 - EN_CORRECTTEXT
148 - EN_DROPFILES
149 - EN_ERRSPACE
150 - EN_HSCROLL
151 - EN_IMECHANGE
152 + EN_KILLFOCUS
153 - EN_LINK
154 - EN_MAXTEXT
155 - EN_MSGFILTER
156 - EN_OLEOPFAILED
157 - EN_PROTECTED
158 + EN_REQUESTRESIZE
159 - EN_SAVECLIPBOARD
160 + EN_SELCHANGE
161 + EN_SETFOCUS
162 - EN_STOPNOUNDO
163 * EN_UPDATE (sent from the wrong place)
164 - EN_VSCROLL
166 Styles
168 - ES_AUTOHSCROLL
169 - ES_AUTOVSCROLL
170 - ES_CENTER
171 - ES_DISABLENOSCROLL (scrollbar is always visible)
172 - ES_EX_NOCALLOLEINIT
173 - ES_LEFT
174 - ES_MULTILINE (currently single line controls aren't supported)
175 - ES_NOIME
176 - ES_READONLY (I'm not sure if beeping is the proper behaviour)
177 - ES_RIGHT
178 - ES_SAVESEL
179 - ES_SELFIME
180 - ES_SUNKEN
181 - ES_VERTICAL
182 - ES_WANTRETURN (don't know how to do WM_GETDLGCODE part)
183 - WS_SETFONT
184 - WS_HSCROLL
185 - WS_VSCROLL
189 * RICHED20 TODO (incomplete):
191 * - messages/styles/notifications listed above
192 * - Undo coalescing
193 * - add remaining CHARFORMAT/PARAFORMAT fields
194 * - right/center align should strip spaces from the beginning
195 * - pictures/OLE objects (not just smiling faces that lack API support ;-) )
196 * - COM interface (looks like a major pain in the TODO list)
197 * - calculate heights of pictures (half-done)
198 * - horizontal scrolling (not even started)
199 * - hysteresis during wrapping (related to scrollbars appearing/disappearing)
200 * - find/replace
201 * - how to implement EM_FORMATRANGE and EM_DISPLAYBAND ? (Mission Impossible)
202 * - italic caret with italic fonts
203 * - IME
204 * - most notifications aren't sent at all (the most important ones are)
205 * - when should EN_SELCHANGE be sent after text change ? (before/after EN_UPDATE?)
206 * - WM_SETTEXT may use wrong style (but I'm 80% sure it's OK)
207 * - EM_GETCHARFORMAT with SCF_SELECTION may not behave 100% like in original (but very close)
208 * - full justification
209 * - hyphenation
210 * - tables
211 * - ListBox & ComboBox not implemented
213 * Bugs that are probably fixed, but not so easy to verify:
214 * - EN_UPDATE/EN_CHANGE are handled very incorrectly (should be OK now)
215 * - undo for ME_JoinParagraphs doesn't store paragraph format ? (it does)
216 * - check/fix artificial EOL logic (bCursorAtEnd, hardly logical)
217 * - caret shouldn't be displayed when selection isn't empty
218 * - check refcounting in style management functions (looks perfect now, but no bugs is suspicious)
219 * - undo for setting default format (done, might be buggy)
220 * - styles might be not released properly (looks like they work like charm, but who knows?
224 #include "editor.h"
225 #include "commdlg.h"
226 #include "winreg.h"
227 #define NO_SHLWAPI_STREAM
228 #include "shlwapi.h"
229 #include "imm.h"
230 #include "textserv.h"
231 #include "rtf.h"
233 WINE_DEFAULT_DEBUG_CHANNEL(richedit);
235 int me_debug = 0;
236 HANDLE me_heap = NULL;
238 static BOOL ME_ListBoxRegistered = FALSE;
239 static BOOL ME_ComboBoxRegistered = FALSE;
241 static ME_TextBuffer *ME_MakeText(void) {
243 ME_TextBuffer *buf = ALLOC_OBJ(ME_TextBuffer);
245 ME_DisplayItem *p1 = ME_MakeDI(diTextStart);
246 ME_DisplayItem *p2 = ME_MakeDI(diTextEnd);
248 p1->prev = NULL;
249 p1->next = p2;
250 p2->prev = p1;
251 p2->next = NULL;
252 p1->member.para.next_para = p2;
253 p2->member.para.prev_para = p1;
254 p2->member.para.nCharOfs = 0;
256 buf->pFirst = p1;
257 buf->pLast = p2;
258 buf->pCharStyle = NULL;
260 return buf;
264 static LRESULT ME_StreamInText(ME_TextEditor *editor, DWORD dwFormat, ME_InStream *stream, ME_Style *style)
266 WCHAR wszText[STREAMIN_BUFFER_SIZE+1];
267 WCHAR *pText;
269 TRACE("%08lx %p\n", dwFormat, stream);
271 do {
272 long nWideChars = 0;
274 if (!stream->dwSize)
276 ME_StreamInFill(stream);
277 if (stream->editstream->dwError)
278 break;
279 if (!stream->dwSize)
280 break;
283 if (!(dwFormat & SF_UNICODE))
285 /* FIXME? this is doomed to fail on true MBCS like UTF-8, luckily they're unlikely to be used as CP_ACP */
286 nWideChars = MultiByteToWideChar(CP_ACP, 0, stream->buffer, stream->dwSize, wszText, STREAMIN_BUFFER_SIZE);
287 pText = wszText;
289 else
291 nWideChars = stream->dwSize >> 1;
292 pText = (WCHAR *)stream->buffer;
295 ME_InsertTextFromCursor(editor, 0, pText, nWideChars, style);
296 if (stream->dwSize == 0)
297 break;
298 stream->dwSize = 0;
299 } while(1);
300 ME_CommitUndo(editor);
301 ME_UpdateRepaint(editor);
302 return 0;
305 static void ME_RTFCharAttrHook(RTF_Info *info)
307 CHARFORMAT2W fmt;
308 fmt.cbSize = sizeof(fmt);
309 fmt.dwMask = 0;
311 switch(info->rtfMinor)
313 case rtfPlain:
314 /* FIXME add more flags once they're implemented */
315 fmt.dwMask = CFM_BOLD | CFM_ITALIC | CFM_UNDERLINE | CFM_STRIKEOUT | CFM_COLOR | CFM_BACKCOLOR | CFM_SIZE | CFM_WEIGHT;
316 fmt.dwEffects = CFE_AUTOCOLOR | CFE_AUTOBACKCOLOR;
317 fmt.yHeight = 12*20; /* 12pt */
318 fmt.wWeight = 400;
319 break;
320 case rtfBold:
321 fmt.dwMask = CFM_BOLD;
322 fmt.dwEffects = info->rtfParam ? fmt.dwMask : 0;
323 break;
324 case rtfItalic:
325 fmt.dwMask = CFM_ITALIC;
326 fmt.dwEffects = info->rtfParam ? fmt.dwMask : 0;
327 break;
328 case rtfUnderline:
329 fmt.dwMask = CFM_UNDERLINE;
330 fmt.dwEffects = info->rtfParam ? fmt.dwMask : 0;
331 fmt.bUnderlineType = CFU_CF1UNDERLINE;
332 break;
333 case rtfNoUnderline:
334 fmt.dwMask = CFM_UNDERLINE;
335 fmt.dwEffects = 0;
336 break;
337 case rtfStrikeThru:
338 fmt.dwMask = CFM_STRIKEOUT;
339 fmt.dwEffects = info->rtfParam ? fmt.dwMask : 0;
340 break;
341 case rtfSubScript:
342 case rtfSuperScript:
343 case rtfSubScrShrink:
344 case rtfSuperScrShrink:
345 case rtfNoSuperSub:
346 fmt.dwMask = CFM_SUBSCRIPT|CFM_SUPERSCRIPT;
347 if (info->rtfMinor == rtfSubScrShrink) fmt.dwEffects = CFE_SUBSCRIPT;
348 if (info->rtfMinor == rtfSuperScrShrink) fmt.dwEffects = CFE_SUPERSCRIPT;
349 if (info->rtfMinor == rtfNoSuperSub) fmt.dwEffects = 0;
350 break;
351 case rtfInvisible:
352 fmt.dwMask = CFM_HIDDEN;
353 fmt.dwEffects = info->rtfParam ? fmt.dwMask : 0;
354 break;
355 case rtfBackColor:
356 fmt.dwMask = CFM_BACKCOLOR;
357 fmt.dwEffects = 0;
358 if (info->rtfParam == 0)
359 fmt.dwEffects = CFE_AUTOBACKCOLOR;
360 else if (info->rtfParam != rtfNoParam)
362 RTFColor *c = RTFGetColor(info, info->rtfParam);
363 fmt.crTextColor = (c->rtfCBlue<<16)|(c->rtfCGreen<<8)|(c->rtfCRed);
365 break;
366 case rtfForeColor:
367 fmt.dwMask = CFM_COLOR;
368 fmt.dwEffects = 0;
369 if (info->rtfParam == 0)
370 fmt.dwEffects = CFE_AUTOCOLOR;
371 else if (info->rtfParam != rtfNoParam)
373 RTFColor *c = RTFGetColor(info, info->rtfParam);
374 fmt.crTextColor = (c->rtfCBlue<<16)|(c->rtfCGreen<<8)|(c->rtfCRed);
376 break;
377 case rtfFontNum:
378 if (info->rtfParam != rtfNoParam)
380 RTFFont *f = RTFGetFont(info, info->rtfParam);
381 if (f)
383 MultiByteToWideChar(CP_ACP, 0, f->rtfFName, -1, fmt.szFaceName, sizeof(fmt.szFaceName)/sizeof(WCHAR));
384 fmt.szFaceName[sizeof(fmt.szFaceName)/sizeof(WCHAR)-1] = '\0';
385 fmt.bCharSet = f->rtfFCharSet;
386 fmt.dwMask = CFM_FACE | CFM_CHARSET;
389 break;
390 case rtfFontSize:
391 fmt.dwMask = CFM_SIZE;
392 if (info->rtfParam != rtfNoParam)
393 fmt.yHeight = info->rtfParam*10;
394 break;
396 if (fmt.dwMask) {
397 ME_Style *style2;
398 RTFFlushOutputBuffer(info);
399 /* FIXME too slow ? how come ? */
400 style2 = ME_ApplyStyle(info->style, &fmt);
401 ME_ReleaseStyle(info->style);
402 info->style = style2;
403 info->styleChanged = TRUE;
407 /* FIXME this function doesn't get any information about context of the RTF tag, which is very bad,
408 the same tags mean different things in different contexts */
409 static void ME_RTFParAttrHook(RTF_Info *info)
411 PARAFORMAT2 fmt;
412 fmt.cbSize = sizeof(fmt);
413 fmt.dwMask = 0;
415 switch(info->rtfMinor)
417 case rtfParDef: /* restores default paragraph attributes */
418 fmt.dwMask = PFM_ALIGNMENT | PFM_TABSTOPS | PFM_OFFSET | PFM_STARTINDENT;
419 fmt.wAlignment = PFA_LEFT;
420 fmt.cTabCount = 0;
421 fmt.dxOffset = fmt.dxStartIndent = 0;
422 RTFFlushOutputBuffer(info);
423 ME_GetParagraph(info->editor->pCursors[0].pRun)->member.para.bTable = FALSE;
424 break;
425 case rtfInTable:
427 ME_DisplayItem *para;
429 RTFFlushOutputBuffer(info);
430 para = ME_GetParagraph(info->editor->pCursors[0].pRun);
431 assert(para->member.para.pCells);
432 para->member.para.bTable = TRUE;
433 return;
435 case rtfFirstIndent:
436 ME_GetSelectionParaFormat(info->editor, &fmt);
437 fmt.dwMask = PFM_STARTINDENT | PFM_OFFSET;
438 fmt.dxStartIndent += info->rtfParam + fmt.dxOffset;
439 fmt.dxOffset = -info->rtfParam;
440 break;
441 case rtfLeftIndent:
442 ME_GetSelectionParaFormat(info->editor, &fmt);
443 fmt.dwMask = PFM_STARTINDENT;
444 fmt.dxStartIndent = -fmt.dxOffset + info->rtfParam;
445 break;
446 case rtfRightIndent:
447 fmt.dwMask = PFM_RIGHTINDENT;
448 fmt.dxRightIndent = info->rtfParam;
449 break;
450 case rtfQuadLeft:
451 case rtfQuadJust:
452 fmt.dwMask = PFM_ALIGNMENT;
453 fmt.wAlignment = PFA_LEFT;
454 break;
455 case rtfQuadRight:
456 fmt.dwMask = PFM_ALIGNMENT;
457 fmt.wAlignment = PFA_RIGHT;
458 break;
459 case rtfQuadCenter:
460 fmt.dwMask = PFM_ALIGNMENT;
461 fmt.wAlignment = PFA_CENTER;
462 break;
463 case rtfTabPos:
464 ME_GetSelectionParaFormat(info->editor, &fmt);
465 if (!(fmt.dwMask & PFM_TABSTOPS))
467 fmt.dwMask |= PFM_TABSTOPS;
468 fmt.cTabCount = 0;
470 if (fmt.cTabCount < MAX_TAB_STOPS)
471 fmt.rgxTabs[fmt.cTabCount++] = info->rtfParam;
472 break;
474 if (fmt.dwMask) {
475 RTFFlushOutputBuffer(info);
476 /* FIXME too slow ? how come ?*/
477 ME_SetSelectionParaFormat(info->editor, &fmt);
481 static void ME_RTFTblAttrHook(RTF_Info *info)
483 ME_DisplayItem *para;
485 switch (info->rtfMinor)
487 case rtfRowDef:
488 RTFFlushOutputBuffer(info);
489 para = ME_GetParagraph(info->editor->pCursors[0].pRun);
491 para->member.para.pCells = ALLOC_OBJ(ME_TableCell);
492 para->member.para.pCells->nRightBoundary = 0;
493 para->member.para.pCells->next = NULL;
494 para->member.para.pLastCell = para->member.para.pCells;
495 break;
496 case rtfCellPos:
497 RTFFlushOutputBuffer(info);
498 para = ME_GetParagraph(info->editor->pCursors[0].pRun);
500 if (para->member.para.pLastCell->nRightBoundary)
502 ME_TableCell *pCell = ALLOC_OBJ(ME_TableCell);
504 pCell->next = NULL;
505 para->member.para.pLastCell->next = pCell;
506 para->member.para.pLastCell = pCell;
508 para->member.para.pLastCell->nRightBoundary = info->rtfParam;
509 break;
513 static void ME_RTFReadHook(RTF_Info *info) {
514 switch(info->rtfClass)
516 case rtfGroup:
517 switch(info->rtfMajor)
519 case rtfBeginGroup:
520 if (info->stackTop < maxStack) {
521 memcpy(&info->stack[info->stackTop].fmt, &info->style->fmt, sizeof(CHARFORMAT2W));
522 info->stack[info->stackTop].codePage = info->codePage;
523 info->stack[info->stackTop].unicodeLength = info->unicodeLength;
525 info->stackTop++;
526 info->styleChanged = FALSE;
527 break;
528 case rtfEndGroup:
530 ME_Style *s;
531 RTFFlushOutputBuffer(info);
532 if (info->stackTop<=1) {
533 info->rtfClass = rtfEOF;
534 return;
536 info->stackTop--;
537 assert(info->stackTop >= 0);
538 if (info->styleChanged)
540 /* FIXME too slow ? how come ? */
541 s = ME_ApplyStyle(info->style, &info->stack[info->stackTop].fmt);
542 ME_ReleaseStyle(info->style);
543 info->style = s;
544 info->codePage = info->stack[info->stackTop].codePage;
545 info->unicodeLength = info->stack[info->stackTop].unicodeLength;
547 break;
550 break;
551 case rtfControl:
552 switch(info->rtfMajor)
554 case rtfCharAttr:
555 ME_RTFCharAttrHook(info);
556 break;
557 case rtfParAttr:
558 ME_RTFParAttrHook(info);
559 break;
560 case rtfTblAttr:
561 ME_RTFTblAttrHook(info);
562 break;
563 case rtfSpecialChar:
564 if (info->rtfMinor == rtfCell)
566 RTFFlushOutputBuffer(info);
567 ME_InsertTableCellFromCursor(info->editor, 0);
570 break;
574 void
575 ME_StreamInFill(ME_InStream *stream)
577 stream->editstream->dwError = stream->editstream->pfnCallback(stream->editstream->dwCookie,
578 (BYTE *)stream->buffer,
579 sizeof(stream->buffer),
580 (LONG *)&stream->dwSize);
581 stream->dwUsed = 0;
584 static LRESULT ME_StreamIn(ME_TextEditor *editor, DWORD format, EDITSTREAM *stream)
586 RTF_Info parser;
587 ME_Style *style;
588 int from, to, to2, nUndoMode;
589 ME_UndoItem *pUI;
590 int nEventMask = editor->nEventMask;
591 ME_InStream inStream;
593 TRACE("stream==%p hWnd==%p format==0x%X\n", stream, editor->hWnd, (UINT)format);
594 editor->nEventMask = 0;
596 ME_GetSelection(editor, &from, &to);
597 if ((format & SFF_SELECTION) && (editor->mode & TM_RICHTEXT)) {
598 style = ME_GetSelectionInsertStyle(editor);
600 ME_InternalDeleteText(editor, from, to-from);
602 else {
603 style = editor->pBuffer->pDefaultStyle;
604 ME_AddRefStyle(style);
605 SendMessageA(editor->hWnd, EM_SETSEL, 0, 0);
606 ME_InternalDeleteText(editor, 0, ME_GetTextLength(editor));
607 from = to = 0;
608 ME_ClearTempStyle(editor);
609 /* FIXME restore default paragraph formatting ! */
612 nUndoMode = editor->nUndoMode;
613 editor->nUndoMode = umIgnore;
615 inStream.editstream = stream;
616 inStream.editstream->dwError = 0;
617 inStream.dwSize = 0;
618 inStream.dwUsed = 0;
620 if (format & SF_RTF)
622 /* Check if it's really RTF, and if it is not, use plain text */
623 ME_StreamInFill(&inStream);
624 if (!inStream.editstream->dwError)
626 if (strncmp(inStream.buffer, "{\\rtf1", 6) && strncmp(inStream.buffer, "{\\urtf", 6))
628 format &= ~SF_RTF;
629 format |= SF_TEXT;
634 if (!inStream.editstream->dwError)
636 if (format & SF_RTF) {
637 /* setup the RTF parser */
638 memset(&parser, 0, sizeof parser);
639 RTFSetEditStream(&parser, &inStream);
640 parser.rtfFormat = format&(SF_TEXT|SF_RTF);
641 parser.hwndEdit = editor->hWnd;
642 parser.editor = editor;
643 parser.style = style;
644 WriterInit(&parser);
645 RTFInit(&parser);
646 RTFSetReadHook(&parser, ME_RTFReadHook);
647 BeginFile(&parser);
649 /* do the parsing */
650 RTFRead(&parser);
651 RTFFlushOutputBuffer(&parser);
652 RTFDestroy(&parser);
654 style = parser.style;
656 else if (format & SF_TEXT)
657 ME_StreamInText(editor, format, &inStream, style);
658 else
659 ERR("EM_STREAMIN without SF_TEXT or SF_RTF\n");
660 ME_GetSelection(editor, &to, &to2);
661 /* put the cursor at the top */
662 if (!(format & SFF_SELECTION))
663 SendMessageA(editor->hWnd, EM_SETSEL, 0, 0);
666 editor->nUndoMode = nUndoMode;
667 if (format & SFF_SELECTION)
669 pUI = ME_AddUndoItem(editor, diUndoDeleteRun, NULL);
670 TRACE("from %d to %d\n", from, to);
671 if (pUI && from < to)
673 pUI->nStart = from;
674 pUI->nLen = to-from;
676 ME_CommitUndo(editor);
678 else
680 ME_EmptyUndoStack(editor);
683 ME_ReleaseStyle(style);
684 editor->nEventMask = nEventMask;
685 if (editor->bRedraw)
687 ME_UpdateRepaint(editor);
689 if (!(format & SFF_SELECTION)) {
690 ME_ClearTempStyle(editor);
692 ME_MoveCaret(editor);
693 ME_SendSelChange(editor);
694 ME_SendRequestResize(editor, FALSE);
696 return 0;
700 typedef struct tagME_RTFStringStreamStruct
702 char *string;
703 int pos;
704 int length;
705 } ME_RTFStringStreamStruct;
707 static DWORD CALLBACK ME_ReadFromRTFString(DWORD_PTR dwCookie, LPBYTE lpBuff, LONG cb, LONG *pcb)
709 ME_RTFStringStreamStruct *pStruct = (ME_RTFStringStreamStruct *)dwCookie;
710 int count;
712 count = min(cb, pStruct->length - pStruct->pos);
713 memmove(lpBuff, pStruct->string + pStruct->pos, count);
714 pStruct->pos += count;
715 *pcb = count;
716 return 0;
719 static void
720 ME_StreamInRTFString(ME_TextEditor *editor, BOOL selection, char *string)
722 EDITSTREAM es;
723 ME_RTFStringStreamStruct data;
725 data.string = string;
726 data.length = strlen(string);
727 data.pos = 0;
728 es.dwCookie = (DWORD)&data;
729 es.pfnCallback = ME_ReadFromRTFString;
730 ME_StreamIn(editor, SF_RTF | (selection ? SFF_SELECTION : 0), &es);
734 ME_DisplayItem *
735 ME_FindItemAtOffset(ME_TextEditor *editor, ME_DIType nItemType, int nOffset, int *nItemOffset)
737 ME_DisplayItem *item = ME_FindItemFwd(editor->pBuffer->pFirst, diParagraph);
739 while (item && item->member.para.next_para->member.para.nCharOfs <= nOffset)
740 item = ME_FindItemFwd(item, diParagraph);
742 if (!item)
743 return item;
745 nOffset -= item->member.para.nCharOfs;
746 if (nItemType == diParagraph) {
747 if (nItemOffset)
748 *nItemOffset = nOffset;
749 return item;
752 do {
753 item = ME_FindItemFwd(item, diRun);
754 } while (item && (item->member.run.nCharOfs + ME_StrLen(item->member.run.strText) <= nOffset));
755 if (item) {
756 nOffset -= item->member.run.nCharOfs;
757 if (nItemOffset)
758 *nItemOffset = nOffset;
760 return item;
764 static int
765 ME_FindText(ME_TextEditor *editor, DWORD flags, CHARRANGE *chrg, WCHAR *text, CHARRANGE *chrgText)
767 int nStart, nEnd;
768 int nLen = lstrlenW(text);
769 int nMin, nMax;
770 ME_DisplayItem *item;
771 ME_DisplayItem *para;
773 TRACE("flags==0x%08lx, chrg->cpMin==%ld, chrg->cpMax==%ld text==%s\n",
774 flags, chrg->cpMin, chrg->cpMax, debugstr_w(text));
776 if (flags & ~(FR_DOWN | FR_MATCHCASE))
777 FIXME("Flags 0x%08lx not implemented\n", flags & ~(FR_DOWN | FR_MATCHCASE));
779 nMin = chrg->cpMin;
780 if (chrg->cpMax == -1)
781 nMax = ME_GetTextLength(editor);
782 else
783 nMax = chrg->cpMax;
785 /* when searching up, if cpMin < cpMax, then instead of searching
786 * on [cpMin,cpMax], we search on [0,cpMin], otherwise, search on
787 * [cpMax, cpMin]
789 if (!(flags & FR_DOWN))
791 int nSwap = nMax;
793 nMax = nMin;
794 if (nMin < nSwap)
795 nMin = 0;
796 else
797 nMin = nSwap;
800 if (!nLen || nMin < 0 || nMax < 0 || nMax < nMin)
802 if (chrgText)
803 chrgText->cpMin = chrgText->cpMax = -1;
804 return -1;
807 if (flags & FR_DOWN) /* Forward search */
809 nStart = nMin;
810 item = ME_FindItemAtOffset(editor, diRun, nStart, &nStart);
811 if (!item)
813 if (chrgText)
814 chrgText->cpMin = chrgText->cpMax = -1;
815 return -1;
818 para = ME_GetParagraph(item);
819 while (item
820 && para->member.para.nCharOfs + item->member.run.nCharOfs + nStart + nLen <= nMax)
822 ME_DisplayItem *pCurItem = item;
823 int nCurStart = nStart;
824 int nMatched = 0;
826 while (pCurItem && ME_CharCompare(pCurItem->member.run.strText->szData[nCurStart + nMatched], text[nMatched], (flags & FR_MATCHCASE)))
828 nMatched++;
829 if (nMatched == nLen)
831 nStart += para->member.para.nCharOfs + item->member.run.nCharOfs;
832 if (chrgText)
834 chrgText->cpMin = nStart;
835 chrgText->cpMax = nStart + nLen;
837 TRACE("found at %d-%d\n", nStart, nStart + nLen);
838 return nStart;
840 if (nCurStart + nMatched == ME_StrLen(pCurItem->member.run.strText))
842 pCurItem = ME_FindItemFwd(pCurItem, diRun);
843 para = ME_GetParagraph(pCurItem);
844 nCurStart = -nMatched;
847 nStart++;
848 if (nStart == ME_StrLen(item->member.run.strText))
850 item = ME_FindItemFwd(item, diRun);
851 para = ME_GetParagraph(item);
852 nStart = 0;
856 else /* Backward search */
858 nEnd = nMax;
859 item = ME_FindItemAtOffset(editor, diRun, nEnd, &nEnd);
860 if (!item) {
861 if (chrgText)
862 chrgText->cpMin = chrgText->cpMax = -1;
863 return -1;
866 para = ME_GetParagraph(item);
868 while (item
869 && para->member.para.nCharOfs + item->member.run.nCharOfs + nEnd - nLen >= nMin)
871 ME_DisplayItem *pCurItem = item;
872 int nCurEnd = nEnd;
873 int nMatched = 0;
875 while (ME_CharCompare(pCurItem->member.run.strText->szData[nCurEnd - nMatched - 1], text[nLen - nMatched - 1], (flags & FR_MATCHCASE)))
877 nMatched++;
878 if (nMatched == nLen)
880 nStart = para->member.para.nCharOfs + item->member.run.nCharOfs + nCurEnd - nMatched;
881 if (chrgText)
883 chrgText->cpMin = nStart;
884 chrgText->cpMax = nStart + nLen;
886 TRACE("found at %d-%d\n", nStart, nStart + nLen);
887 return nStart;
889 if (nCurEnd - nMatched == 0)
891 pCurItem = ME_FindItemBack(pCurItem, diRun);
892 para = ME_GetParagraph(pCurItem);
893 nCurEnd = ME_StrLen(pCurItem->member.run.strText) + nMatched;
896 nEnd--;
897 if (nEnd < 0)
899 item = ME_FindItemBack(item, diRun);
900 para = ME_GetParagraph(item);
901 nEnd = ME_StrLen(item->member.run.strText);
905 TRACE("not found\n");
906 if (chrgText)
907 chrgText->cpMin = chrgText->cpMax = -1;
908 return -1;
912 static BOOL
913 ME_KeyDown(ME_TextEditor *editor, WORD nKey)
915 BOOL ctrl_is_down = GetKeyState(VK_CONTROL) & 0x8000;
916 BOOL shift_is_down = GetKeyState(VK_SHIFT) & 0x8000;
918 switch (nKey)
920 case VK_LEFT:
921 case VK_RIGHT:
922 case VK_UP:
923 case VK_DOWN:
924 case VK_HOME:
925 case VK_END:
926 case VK_PRIOR:
927 case VK_NEXT:
928 ME_ArrowKey(editor, nKey, shift_is_down, ctrl_is_down);
929 return TRUE;
930 case VK_BACK:
931 case VK_DELETE:
932 /* FIXME backspace and delete aren't the same, they act different wrt paragraph style of the merged paragraph */
933 if (GetWindowLongW(editor->hWnd, GWL_STYLE) & ES_READONLY)
934 return FALSE;
935 if (ME_IsSelection(editor))
936 ME_DeleteSelection(editor);
937 else if (nKey == VK_DELETE || ME_ArrowKey(editor, VK_LEFT, FALSE, FALSE))
938 ME_DeleteTextAtCursor(editor, 1, 1);
939 else
940 return TRUE;
941 ME_QueueInvalidateFromCursor(editor, 1);
942 ME_UpdateRepaint(editor);
943 ME_SendRequestResize(editor, FALSE);
944 return TRUE;
946 default:
947 if (ctrl_is_down)
949 if (nKey == 'W')
951 CHARFORMAT2W chf;
952 char buf[2048];
954 ME_GetSelectionCharFormat(editor, &chf);
955 ME_DumpStyleToBuf(&chf, buf);
956 MessageBoxA(NULL, buf, "Style dump", MB_OK);
958 if (nKey == 'Q')
960 ME_CheckCharOffsets(editor);
964 return FALSE;
967 static void ME_ShowContextMenu(ME_TextEditor *editor, int x, int y)
969 CHARRANGE selrange;
970 HMENU menu;
971 int seltype = 0;
972 if(!editor->lpOleCallback)
973 return;
974 ME_GetSelection(editor, (int *)&selrange.cpMin, (int *)&selrange.cpMax);
975 if(selrange.cpMin == selrange.cpMax)
976 seltype |= SEL_EMPTY;
977 else
979 /* FIXME: Handle objects */
980 seltype |= SEL_TEXT;
981 if(selrange.cpMax-selrange.cpMin > 1)
982 seltype |= SEL_MULTICHAR;
984 if(SUCCEEDED(IRichEditOleCallback_GetContextMenu(editor->lpOleCallback, seltype, NULL, &selrange, &menu)))
986 TrackPopupMenu(menu, TPM_LEFTALIGN | TPM_RIGHTBUTTON, x, y, 0, GetParent(editor->hWnd), NULL);
987 DestroyMenu(menu);
991 ME_TextEditor *ME_MakeEditor(HWND hWnd) {
992 ME_TextEditor *ed = ALLOC_OBJ(ME_TextEditor);
993 HDC hDC;
994 int i;
995 ed->hWnd = hWnd;
996 ed->bEmulateVersion10 = FALSE;
997 ed->pBuffer = ME_MakeText();
998 hDC = GetDC(hWnd);
999 ME_MakeFirstParagraph(hDC, ed->pBuffer);
1000 ReleaseDC(hWnd, hDC);
1001 ed->bCaretShown = FALSE;
1002 ed->nCursors = 3;
1003 ed->pCursors = ALLOC_N_OBJ(ME_Cursor, ed->nCursors);
1004 ed->pCursors[0].pRun = ME_FindItemFwd(ed->pBuffer->pFirst, diRun);
1005 ed->pCursors[0].nOffset = 0;
1006 ed->pCursors[1].pRun = ME_FindItemFwd(ed->pBuffer->pFirst, diRun);
1007 ed->pCursors[1].nOffset = 0;
1008 ed->nLastTotalLength = ed->nTotalLength = 0;
1009 ed->nUDArrowX = -1;
1010 ed->nSequence = 0;
1011 ed->rgbBackColor = -1;
1012 ed->hbrBackground = GetSysColorBrush(COLOR_WINDOW);
1013 ed->bCaretAtEnd = FALSE;
1014 ed->nEventMask = 0;
1015 ed->nModifyStep = 0;
1016 ed->pUndoStack = ed->pRedoStack = NULL;
1017 ed->nUndoMode = umAddToUndo;
1018 ed->nParagraphs = 1;
1019 ed->nLastSelStart = ed->nLastSelEnd = 0;
1020 ed->nScrollPosY = 0;
1021 ed->nZoomNumerator = ed->nZoomDenominator = 0;
1022 ed->bRedraw = TRUE;
1023 ed->nInvalidOfs = -1;
1024 ed->pfnWordBreak = NULL;
1025 ed->lpOleCallback = NULL;
1026 ed->mode = TM_RICHTEXT | TM_MULTILEVELUNDO | TM_MULTICODEPAGE;
1027 GetClientRect(hWnd, &ed->rcFormat);
1028 for (i=0; i<HFONT_CACHE_SIZE; i++)
1030 ed->pFontCache[i].nRefs = 0;
1031 ed->pFontCache[i].nAge = 0;
1032 ed->pFontCache[i].hFont = NULL;
1034 ME_CheckCharOffsets(ed);
1035 return ed;
1038 typedef struct tagME_GlobalDestStruct
1040 HGLOBAL hData;
1041 int nLength;
1042 } ME_GlobalDestStruct;
1044 static DWORD CALLBACK ME_ReadFromHGLOBALUnicode(DWORD_PTR dwCookie, LPBYTE lpBuff, LONG cb, LONG *pcb)
1046 ME_GlobalDestStruct *pData = (ME_GlobalDestStruct *)dwCookie;
1047 int i;
1048 WORD *pSrc, *pDest;
1050 cb = cb >> 1;
1051 pDest = (WORD *)lpBuff;
1052 pSrc = (WORD *)GlobalLock(pData->hData);
1053 for (i = 0; i<cb && pSrc[pData->nLength+i]; i++) {
1054 pDest[i] = pSrc[pData->nLength+i];
1056 pData->nLength += i;
1057 *pcb = 2*i;
1058 GlobalUnlock(pData->hData);
1059 return 0;
1062 static DWORD CALLBACK ME_ReadFromHGLOBALRTF(DWORD_PTR dwCookie, LPBYTE lpBuff, LONG cb, LONG *pcb)
1064 ME_GlobalDestStruct *pData = (ME_GlobalDestStruct *)dwCookie;
1065 int i;
1066 BYTE *pSrc, *pDest;
1068 pDest = lpBuff;
1069 pSrc = (BYTE *)GlobalLock(pData->hData);
1070 for (i = 0; i<cb && pSrc[pData->nLength+i]; i++) {
1071 pDest[i] = pSrc[pData->nLength+i];
1073 pData->nLength += i;
1074 *pcb = i;
1075 GlobalUnlock(pData->hData);
1076 return 0;
1080 void ME_DestroyEditor(ME_TextEditor *editor)
1082 ME_DisplayItem *pFirst = editor->pBuffer->pFirst;
1083 ME_DisplayItem *p = pFirst, *pNext = NULL;
1084 int i;
1086 ME_ClearTempStyle(editor);
1087 ME_EmptyUndoStack(editor);
1088 while(p) {
1089 pNext = p->next;
1090 ME_DestroyDisplayItem(p);
1091 p = pNext;
1093 ME_ReleaseStyle(editor->pBuffer->pDefaultStyle);
1094 for (i=0; i<HFONT_CACHE_SIZE; i++)
1096 if (editor->pFontCache[i].hFont)
1097 DeleteObject(editor->pFontCache[i].hFont);
1099 DeleteObject(editor->hbrBackground);
1100 if(editor->lpOleCallback)
1101 IUnknown_Release(editor->lpOleCallback);
1103 FREE_OBJ(editor);
1106 static const WCHAR wszClassName[] = {'R', 'i', 'c', 'h', 'E', 'd', 'i', 't', '2', '0', 'W', 0};
1107 static const WCHAR wszClassName50[] = {'R', 'i', 'c', 'h', 'E', 'd', 'i', 't', '5', '0', 'W', 0};
1108 static const WCHAR wszClassNameListBox[] = {'R','E','L','i','s','t','B','o','x','2','0','W', 0};
1109 static const WCHAR wszClassNameComboBox[] = {'R','E','C','o','m','b','o','B','o','x','2','0','W', 0};
1111 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
1113 TRACE("\n");
1114 switch (fdwReason)
1116 case DLL_PROCESS_ATTACH:
1117 DisableThreadLibraryCalls(hinstDLL);
1118 me_heap = HeapCreate (0, 0x10000, 0);
1119 ME_RegisterEditorClass(hinstDLL);
1120 break;
1122 case DLL_PROCESS_DETACH:
1123 UnregisterClassW(wszClassName, 0);
1124 UnregisterClassW(wszClassName50, 0);
1125 UnregisterClassA("RichEdit20A", 0);
1126 UnregisterClassA("RichEdit50A", 0);
1127 if (ME_ListBoxRegistered)
1128 UnregisterClassW(wszClassNameListBox, 0);
1129 if (ME_ComboBoxRegistered)
1130 UnregisterClassW(wszClassNameComboBox, 0);
1131 HeapDestroy (me_heap);
1132 me_heap = NULL;
1133 break;
1135 return TRUE;
1139 #define UNSUPPORTED_MSG(e) \
1140 case e: \
1141 FIXME(#e ": stub\n"); \
1142 return DefWindowProcW(hWnd, msg, wParam, lParam);
1144 static const char * const edit_messages[] = {
1145 "EM_GETSEL",
1146 "EM_SETSEL",
1147 "EM_GETRECT",
1148 "EM_SETRECT",
1149 "EM_SETRECTNP",
1150 "EM_SCROLL",
1151 "EM_LINESCROLL",
1152 "EM_SCROLLCARET",
1153 "EM_GETMODIFY",
1154 "EM_SETMODIFY",
1155 "EM_GETLINECOUNT",
1156 "EM_LINEINDEX",
1157 "EM_SETHANDLE",
1158 "EM_GETHANDLE",
1159 "EM_GETTHUMB",
1160 "EM_UNKNOWN_BF",
1161 "EM_UNKNOWN_C0",
1162 "EM_LINELENGTH",
1163 "EM_REPLACESEL",
1164 "EM_UNKNOWN_C3",
1165 "EM_GETLINE",
1166 "EM_LIMITTEXT",
1167 "EM_CANUNDO",
1168 "EM_UNDO",
1169 "EM_FMTLINES",
1170 "EM_LINEFROMCHAR",
1171 "EM_UNKNOWN_CA",
1172 "EM_SETTABSTOPS",
1173 "EM_SETPASSWORDCHAR",
1174 "EM_EMPTYUNDOBUFFER",
1175 "EM_GETFIRSTVISIBLELINE",
1176 "EM_SETREADONLY",
1177 "EM_SETWORDBREAKPROC",
1178 "EM_GETWORDBREAKPROC",
1179 "EM_GETPASSWORDCHAR",
1180 "EM_SETMARGINS",
1181 "EM_GETMARGINS",
1182 "EM_GETLIMITTEXT",
1183 "EM_POSFROMCHAR",
1184 "EM_CHARFROMPOS"
1187 static const char * const richedit_messages[] = {
1188 "EM_CANPASTE",
1189 "EM_DISPLAYBAND",
1190 "EM_EXGETSEL",
1191 "EM_EXLIMITTEXT",
1192 "EM_EXLINEFROMCHAR",
1193 "EM_EXSETSEL",
1194 "EM_FINDTEXT",
1195 "EM_FORMATRANGE",
1196 "EM_GETCHARFORMAT",
1197 "EM_GETEVENTMASK",
1198 "EM_GETOLEINTERFACE",
1199 "EM_GETPARAFORMAT",
1200 "EM_GETSELTEXT",
1201 "EM_HIDESELECTION",
1202 "EM_PASTESPECIAL",
1203 "EM_REQUESTRESIZE",
1204 "EM_SELECTIONTYPE",
1205 "EM_SETBKGNDCOLOR",
1206 "EM_SETCHARFORMAT",
1207 "EM_SETEVENTMASK",
1208 "EM_SETOLECALLBACK",
1209 "EM_SETPARAFORMAT",
1210 "EM_SETTARGETDEVICE",
1211 "EM_STREAMIN",
1212 "EM_STREAMOUT",
1213 "EM_GETTEXTRANGE",
1214 "EM_FINDWORDBREAK",
1215 "EM_SETOPTIONS",
1216 "EM_GETOPTIONS",
1217 "EM_FINDTEXTEX",
1218 "EM_GETWORDBREAKPROCEX",
1219 "EM_SETWORDBREAKPROCEX",
1220 "EM_SETUNDOLIMIT",
1221 "EM_UNKNOWN_USER_83",
1222 "EM_REDO",
1223 "EM_CANREDO",
1224 "EM_GETUNDONAME",
1225 "EM_GETREDONAME",
1226 "EM_STOPGROUPTYPING",
1227 "EM_SETTEXTMODE",
1228 "EM_GETTEXTMODE",
1229 "EM_AUTOURLDETECT",
1230 "EM_GETAUTOURLDETECT",
1231 "EM_SETPALETTE",
1232 "EM_GETTEXTEX",
1233 "EM_GETTEXTLENGTHEX",
1234 "EM_SHOWSCROLLBAR",
1235 "EM_SETTEXTEX",
1236 "EM_UNKNOWN_USER_98",
1237 "EM_UNKNOWN_USER_99",
1238 "EM_SETPUNCTUATION",
1239 "EM_GETPUNCTUATION",
1240 "EM_SETWORDWRAPMODE",
1241 "EM_GETWORDWRAPMODE",
1242 "EM_SETIMECOLOR",
1243 "EM_GETIMECOLOR",
1244 "EM_SETIMEOPTIONS",
1245 "EM_GETIMEOPTIONS",
1246 "EM_CONVPOSITION",
1247 "EM_UNKNOWN_USER_109",
1248 "EM_UNKNOWN_USER_110",
1249 "EM_UNKNOWN_USER_111",
1250 "EM_UNKNOWN_USER_112",
1251 "EM_UNKNOWN_USER_113",
1252 "EM_UNKNOWN_USER_114",
1253 "EM_UNKNOWN_USER_115",
1254 "EM_UNKNOWN_USER_116",
1255 "EM_UNKNOWN_USER_117",
1256 "EM_UNKNOWN_USER_118",
1257 "EM_UNKNOWN_USER_119",
1258 "EM_SETLANGOPTIONS",
1259 "EM_GETLANGOPTIONS",
1260 "EM_GETIMECOMPMODE",
1261 "EM_FINDTEXTW",
1262 "EM_FINDTEXTEXW",
1263 "EM_RECONVERSION",
1264 "EM_SETIMEMODEBIAS",
1265 "EM_GETIMEMODEBIAS"
1268 static const char *
1269 get_msg_name(UINT msg)
1271 if (msg >= EM_GETSEL && msg <= EM_SETLIMITTEXT)
1272 return edit_messages[msg - EM_GETSEL];
1273 if (msg >= EM_CANPASTE && msg <= EM_GETIMEMODEBIAS)
1274 return richedit_messages[msg - EM_CANPASTE];
1275 return "";
1278 /******************************************************************
1279 * RichEditANSIWndProc (RICHED20.10)
1281 LRESULT WINAPI RichEditANSIWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
1282 SCROLLINFO si;
1283 ME_TextEditor *editor = (ME_TextEditor *)GetWindowLongW(hWnd, 0);
1285 TRACE("hWnd %p msg %04x (%s) %08x %08lx\n",
1286 hWnd, msg, get_msg_name(msg), wParam, lParam);
1288 switch(msg) {
1290 UNSUPPORTED_MSG(EM_AUTOURLDETECT)
1291 UNSUPPORTED_MSG(EM_DISPLAYBAND)
1292 UNSUPPORTED_MSG(EM_EXLIMITTEXT)
1293 UNSUPPORTED_MSG(EM_FINDWORDBREAK)
1294 UNSUPPORTED_MSG(EM_FMTLINES)
1295 UNSUPPORTED_MSG(EM_FORMATRANGE)
1296 UNSUPPORTED_MSG(EM_GETAUTOURLDETECT)
1297 UNSUPPORTED_MSG(EM_GETBIDIOPTIONS)
1298 UNSUPPORTED_MSG(EM_GETEDITSTYLE)
1299 UNSUPPORTED_MSG(EM_GETIMECOMPMODE)
1300 /* UNSUPPORTED_MSG(EM_GETIMESTATUS) missing in Wine headers */
1301 UNSUPPORTED_MSG(EM_GETLANGOPTIONS)
1302 UNSUPPORTED_MSG(EM_GETLIMITTEXT)
1303 UNSUPPORTED_MSG(EM_GETLINE)
1304 /* UNSUPPORTED_MSG(EM_GETOLEINTERFACE) separate stub */
1305 UNSUPPORTED_MSG(EM_GETPASSWORDCHAR)
1306 UNSUPPORTED_MSG(EM_GETREDONAME)
1307 UNSUPPORTED_MSG(EM_GETTEXTMODE)
1308 UNSUPPORTED_MSG(EM_GETTYPOGRAPHYOPTIONS)
1309 UNSUPPORTED_MSG(EM_GETUNDONAME)
1310 UNSUPPORTED_MSG(EM_GETWORDBREAKPROCEX)
1311 UNSUPPORTED_MSG(EM_HIDESELECTION)
1312 UNSUPPORTED_MSG(EM_LIMITTEXT) /* also known as EM_SETLIMITTEXT */
1313 UNSUPPORTED_MSG(EM_PASTESPECIAL)
1314 UNSUPPORTED_MSG(EM_SCROLL)
1315 UNSUPPORTED_MSG(EM_SELECTIONTYPE)
1316 UNSUPPORTED_MSG(EM_SETBIDIOPTIONS)
1317 UNSUPPORTED_MSG(EM_SETEDITSTYLE)
1318 UNSUPPORTED_MSG(EM_SETFONTSIZE)
1319 UNSUPPORTED_MSG(EM_SETLANGOPTIONS)
1320 UNSUPPORTED_MSG(EM_SETPALETTE)
1321 UNSUPPORTED_MSG(EM_SETPASSWORDCHAR)
1322 UNSUPPORTED_MSG(EM_SETSCROLLPOS)
1323 UNSUPPORTED_MSG(EM_SETTABSTOPS)
1324 UNSUPPORTED_MSG(EM_SETTARGETDEVICE)
1325 UNSUPPORTED_MSG(EM_SETTYPOGRAPHYOPTIONS)
1326 UNSUPPORTED_MSG(EM_SETUNDOLIMIT)
1327 UNSUPPORTED_MSG(EM_SETWORDBREAKPROCEX)
1328 UNSUPPORTED_MSG(EM_SHOWSCROLLBAR)
1329 UNSUPPORTED_MSG(WM_SETFONT)
1330 UNSUPPORTED_MSG(WM_STYLECHANGING)
1331 UNSUPPORTED_MSG(WM_STYLECHANGED)
1332 /* UNSUPPORTED_MSG(WM_UNICHAR) FIXME missing in Wine headers */
1334 /* Messages specific to Richedit controls */
1336 case EM_STREAMIN:
1337 return ME_StreamIn(editor, wParam, (EDITSTREAM*)lParam);
1338 case EM_STREAMOUT:
1339 return ME_StreamOut(editor, wParam, (EDITSTREAM *)lParam);
1340 case WM_GETDLGCODE:
1342 UINT code = DLGC_WANTCHARS|DLGC_WANTARROWS;
1343 if (GetWindowLongW(hWnd, GWL_STYLE)&ES_WANTRETURN)
1344 code |= 0; /* FIXME what can we do here ? ask for messages and censor them ? */
1345 return code;
1347 case WM_NCCREATE:
1349 CREATESTRUCTW *pcs = (CREATESTRUCTW *)lParam;
1350 TRACE("WM_NCCREATE: style 0x%08lx\n", pcs->style);
1351 editor = ME_MakeEditor(hWnd);
1352 SetWindowLongW(hWnd, 0, (long)editor);
1353 pcs = 0; /* ignore */
1354 return TRUE;
1356 case EM_EMPTYUNDOBUFFER:
1357 ME_EmptyUndoStack(editor);
1358 return 0;
1359 case EM_GETSEL:
1361 /* Note: wParam/lParam can be NULL */
1362 UINT from, to;
1363 PUINT pfrom = wParam ? (PUINT)wParam : &from;
1364 PUINT pto = lParam ? (PUINT)lParam : &to;
1365 ME_GetSelection(editor, (int *)pfrom, (int *)pto);
1366 if ((*pfrom|*pto) & 0xFFFF0000)
1367 return -1;
1368 return MAKELONG(*pfrom,*pto);
1370 case EM_EXGETSEL:
1372 CHARRANGE *pRange = (CHARRANGE *)lParam;
1373 ME_GetSelection(editor, (int *)&pRange->cpMin, (int *)&pRange->cpMax);
1374 TRACE("EM_EXGETSEL = (%ld,%ld)\n", pRange->cpMin, pRange->cpMax);
1375 return 0;
1377 case EM_CANUNDO:
1378 return editor->pUndoStack != NULL;
1379 case EM_CANREDO:
1380 return editor->pRedoStack != NULL;
1381 case WM_UNDO: /* FIXME: actually not the same */
1382 case EM_UNDO:
1383 ME_Undo(editor);
1384 return 0;
1385 case EM_REDO:
1386 ME_Redo(editor);
1387 return 0;
1388 case EM_GETOPTIONS:
1390 /* these flags are equivalent to the ES_* counterparts */
1391 DWORD mask = ECO_VERTICAL | ECO_AUTOHSCROLL | ECO_AUTOVSCROLL |
1392 ECO_NOHIDESEL | ECO_READONLY | ECO_WANTRETURN;
1393 DWORD settings = GetWindowLongW(hWnd, GWL_STYLE) & mask;
1395 return settings;
1397 case EM_SETOPTIONS:
1399 /* these flags are equivalent to ES_* counterparts
1400 * ECO_READONLY is already implemented in the code, only requires
1401 * setting the bit to work
1403 DWORD mask = ECO_VERTICAL | ECO_AUTOHSCROLL | ECO_AUTOVSCROLL |
1404 ECO_NOHIDESEL | ECO_READONLY | ECO_WANTRETURN;
1405 DWORD raw = GetWindowLongW(hWnd, GWL_STYLE);
1406 DWORD settings = mask & raw;
1408 switch(wParam)
1410 case ECOOP_SET:
1411 settings = lParam;
1412 break;
1413 case ECOOP_OR:
1414 settings |= lParam;
1415 break;
1416 case ECOOP_AND:
1417 settings &= lParam;
1418 break;
1419 case ECOOP_XOR:
1420 settings ^= lParam;
1422 SetWindowLongW(hWnd, GWL_STYLE, (raw & ~mask) | (settings & mask));
1424 if (lParam & ECO_AUTOWORDSELECTION)
1425 FIXME("ECO_AUTOWORDSELECTION not implemented yet!\n");
1426 if (lParam & ECO_SELECTIONBAR)
1427 FIXME("ECO_SELECTIONBAR not implemented yet!\n");
1428 if (lParam & ECO_VERTICAL)
1429 FIXME("ECO_VERTICAL not implemented yet!\n");
1430 if (lParam & ECO_AUTOHSCROLL)
1431 FIXME("ECO_AUTOHSCROLL not implemented yet!\n");
1432 if (lParam & ECO_AUTOVSCROLL)
1433 FIXME("ECO_AUTOVSCROLL not implemented yet!\n");
1434 if (lParam & ECO_NOHIDESEL)
1435 FIXME("ECO_NOHIDESEL not implemented yet!\n");
1436 if (lParam & ECO_WANTRETURN)
1437 FIXME("ECO_WANTRETURN not implemented yet!\n");
1439 return settings;
1441 case EM_SETSEL:
1443 ME_InvalidateSelection(editor);
1444 ME_SetSelection(editor, wParam, lParam);
1445 ME_InvalidateSelection(editor);
1446 ME_SendSelChange(editor);
1447 return 0;
1449 case EM_EXSETSEL:
1451 CHARRANGE *pRange = (CHARRANGE *)lParam;
1452 TRACE("EM_EXSETSEL (%ld,%ld)\n", pRange->cpMin, pRange->cpMax);
1453 ME_InvalidateSelection(editor);
1454 ME_SetSelection(editor, pRange->cpMin, pRange->cpMax);
1455 ME_InvalidateSelection(editor);
1456 ME_SendSelChange(editor);
1457 return 0;
1459 case EM_SETTEXTEX:
1461 LPWSTR wszText = (LPWSTR)lParam;
1462 SETTEXTEX *pStruct = (SETTEXTEX *)wParam;
1463 size_t len = lstrlenW(wszText);
1464 int from, to;
1465 ME_Style *style;
1466 TRACE("EM_SETTEXEX - %s, flags %d, cp %d\n", debugstr_w(wszText), (int)pStruct->flags, pStruct->codepage);
1467 if (pStruct->codepage != 1200) {
1468 FIXME("EM_SETTEXTEX only supports unicode right now!\n");
1469 return 0;
1471 /* FIXME: this should support RTF strings too, according to MSDN */
1472 if (pStruct->flags & ST_SELECTION) {
1473 ME_GetSelection(editor, &from, &to);
1474 style = ME_GetSelectionInsertStyle(editor);
1475 ME_InternalDeleteText(editor, from, to - from);
1476 ME_InsertTextFromCursor(editor, 0, wszText, len, style);
1477 ME_ReleaseStyle(style);
1479 else {
1480 ME_InternalDeleteText(editor, 0, ME_GetTextLength(editor));
1481 ME_InsertTextFromCursor(editor, 0, wszText, -1, editor->pBuffer->pDefaultStyle);
1482 len = 1;
1484 ME_CommitUndo(editor);
1485 if (!(pStruct->flags & ST_KEEPUNDO))
1486 ME_EmptyUndoStack(editor);
1487 ME_UpdateRepaint(editor);
1488 return len;
1490 case EM_SETBKGNDCOLOR:
1492 LRESULT lColor = ME_GetBackColor(editor);
1493 if (editor->rgbBackColor != -1)
1494 DeleteObject(editor->hbrBackground);
1495 if (wParam)
1497 editor->rgbBackColor = -1;
1498 editor->hbrBackground = GetSysColorBrush(COLOR_WINDOW);
1500 else
1502 editor->rgbBackColor = lParam;
1503 editor->hbrBackground = CreateSolidBrush(editor->rgbBackColor);
1505 if (editor->bRedraw)
1507 InvalidateRect(hWnd, NULL, TRUE);
1508 UpdateWindow(hWnd);
1510 return lColor;
1512 case EM_GETMODIFY:
1513 return editor->nModifyStep == 0 ? 0 : 1;
1514 case EM_SETMODIFY:
1516 if (wParam)
1517 editor->nModifyStep = 0x80000000;
1518 else
1519 editor->nModifyStep = 0;
1521 return 0;
1523 case EM_SETREADONLY:
1525 long nStyle = GetWindowLongW(hWnd, GWL_STYLE);
1526 if (wParam)
1527 nStyle |= ES_READONLY;
1528 else
1529 nStyle &= ~ES_READONLY;
1530 SetWindowLongW(hWnd, GWL_STYLE, nStyle);
1531 return 0;
1533 case EM_SETEVENTMASK:
1535 DWORD nOldMask = editor->nEventMask;
1537 editor->nEventMask = lParam;
1538 return nOldMask;
1540 case EM_GETEVENTMASK:
1541 return editor->nEventMask;
1542 case EM_SETCHARFORMAT:
1544 CHARFORMAT2W buf, *p;
1545 BOOL bRepaint = TRUE;
1546 p = ME_ToCF2W(&buf, (CHARFORMAT2W *)lParam);
1547 if (!wParam || (editor->mode & TM_PLAINTEXT))
1548 ME_SetDefaultCharFormat(editor, p);
1549 else if (wParam == (SCF_WORD | SCF_SELECTION))
1550 FIXME("EM_SETCHARFORMAT: word selection not supported\n");
1551 else if (wParam == SCF_ALL)
1552 ME_SetCharFormat(editor, 0, ME_GetTextLength(editor), p);
1553 else {
1554 int from, to;
1555 ME_GetSelection(editor, &from, &to);
1556 bRepaint = (from != to);
1557 ME_SetSelectionCharFormat(editor, p);
1559 ME_CommitUndo(editor);
1560 if (bRepaint)
1561 ME_UpdateRepaint(editor);
1562 return 0;
1564 case EM_GETCHARFORMAT:
1566 CHARFORMAT2W tmp, *dst = (CHARFORMAT2W *)lParam;
1567 if (dst->cbSize != sizeof(CHARFORMATA) &&
1568 dst->cbSize != sizeof(CHARFORMATW) &&
1569 dst->cbSize != sizeof(CHARFORMAT2A) &&
1570 dst->cbSize != sizeof(CHARFORMAT2W))
1571 return 0;
1572 tmp.cbSize = sizeof(tmp);
1573 if (!wParam)
1574 ME_GetDefaultCharFormat(editor, &tmp);
1575 else
1576 ME_GetSelectionCharFormat(editor, &tmp);
1577 ME_CopyToCFAny(dst, &tmp);
1578 return tmp.dwMask;
1580 case EM_SETPARAFORMAT:
1581 ME_SetSelectionParaFormat(editor, (PARAFORMAT2 *)lParam);
1582 ME_UpdateRepaint(editor);
1583 ME_CommitUndo(editor);
1584 return 0;
1585 case EM_GETPARAFORMAT:
1586 ME_GetSelectionParaFormat(editor, (PARAFORMAT2 *)lParam);
1587 return 0;
1588 case EM_GETFIRSTVISIBLELINE:
1590 ME_DisplayItem *p = editor->pBuffer->pFirst;
1591 int y = editor->nScrollPosY;
1592 int ypara = 0;
1593 int count = 0;
1594 int ystart, yend;
1595 while(p) {
1596 p = ME_FindItemFwd(p, diStartRowOrParagraphOrEnd);
1597 if (p->type == diTextEnd)
1598 break;
1599 if (p->type == diParagraph) {
1600 ypara = p->member.para.nYPos;
1601 continue;
1603 ystart = ypara + p->member.row.nYPos;
1604 yend = ystart + p->member.row.nHeight;
1605 if (y < yend) {
1606 break;
1608 count++;
1610 return count;
1612 case EM_LINESCROLL:
1614 int nPos = editor->nScrollPosY, nEnd= editor->nTotalLength - editor->sizeWindow.cy;
1615 nPos += 8 * lParam; /* FIXME follow the original */
1616 if (nPos>=nEnd)
1617 nPos = nEnd;
1618 if (nPos<0)
1619 nPos = 0;
1620 if (nPos != editor->nScrollPosY) {
1621 int dy = editor->nScrollPosY - nPos;
1622 editor->nScrollPosY = nPos;
1623 SetScrollPos(hWnd, SB_VERT, nPos, TRUE);
1624 if (editor->bRedraw)
1626 ScrollWindow(hWnd, 0, dy, NULL, NULL);
1627 UpdateWindow(hWnd);
1630 return TRUE; /* Should return false if a single line richedit control */
1632 case WM_CLEAR:
1634 int from, to;
1635 ME_GetSelection(editor, &from, &to);
1636 ME_InternalDeleteText(editor, from, to-from);
1637 ME_CommitUndo(editor);
1638 ME_UpdateRepaint(editor);
1639 return 0;
1641 case EM_REPLACESEL:
1643 int from, to;
1644 ME_Style *style;
1645 LPWSTR wszText = ME_ToUnicode(hWnd, (void *)lParam);
1646 size_t len = lstrlenW(wszText);
1647 TRACE("EM_REPLACESEL - %s\n", debugstr_w(wszText));
1649 ME_GetSelection(editor, &from, &to);
1650 style = ME_GetSelectionInsertStyle(editor);
1651 ME_InternalDeleteText(editor, from, to-from);
1652 ME_InsertTextFromCursor(editor, 0, wszText, len, style);
1653 ME_ReleaseStyle(style);
1654 ME_EndToUnicode(hWnd, wszText);
1655 /* drop temporary style if line end */
1656 /* FIXME question: does abc\n mean: put abc, clear temp style, put \n? (would require a change) */
1657 if (len>0 && wszText[len-1] == '\n')
1658 ME_ClearTempStyle(editor);
1660 ME_CommitUndo(editor);
1661 if (!wParam)
1662 ME_EmptyUndoStack(editor);
1663 ME_UpdateRepaint(editor);
1664 return 0;
1666 case EM_SCROLLCARET:
1668 int top, bottom; /* row's edges relative to document top */
1669 ME_DisplayItem *para, *row;
1671 row = ME_RowStart(editor->pCursors[0].pRun);
1672 para = ME_GetParagraph(row);
1673 top = para->member.para.nYPos + row->member.row.nYPos;
1674 bottom = top + row->member.row.nHeight;
1676 if ((top < editor->nScrollPosY)
1677 || (editor->nScrollPosY + editor->sizeWindow.cy < bottom))
1679 int dy;
1680 int prevScrollPosY = editor->nScrollPosY;
1682 if (top < editor->nScrollPosY) /* caret above window */
1683 editor->nScrollPosY = top;
1684 else /* caret below window */
1685 editor->nScrollPosY = bottom - editor->sizeWindow.cy;
1687 if (editor->nScrollPosY < 0)
1688 editor->nScrollPosY = 0;
1690 dy = prevScrollPosY - editor->nScrollPosY;
1691 SetScrollPos(hWnd, SB_VERT, editor->nScrollPosY, TRUE);
1692 if (editor->bRedraw)
1694 ScrollWindow(hWnd, 0, dy, NULL, NULL);
1695 UpdateWindow(hWnd);
1699 return 0;
1701 case WM_SETTEXT:
1703 ME_InternalDeleteText(editor, 0, ME_GetTextLength(editor));
1704 if (lParam)
1706 TRACE("WM_SETTEXT lParam==%lx\n",lParam);
1707 if (!IsWindowUnicode(hWnd) && !strncmp((char *)lParam, "{\\rtf1", 6))
1709 /* Undocumented: WM_SETTEXT supports RTF text */
1710 ME_StreamInRTFString(editor, 0, (char *)lParam);
1712 else
1714 LPWSTR wszText = ME_ToUnicode(hWnd, (void *)lParam);
1715 TRACE("WM_SETTEXT - %s\n", debugstr_w(wszText)); /* debugstr_w() */
1716 if (lstrlenW(wszText) > 0)
1718 /* uses default style! */
1719 ME_InsertTextFromCursor(editor, 0, wszText, -1, editor->pBuffer->pDefaultStyle);
1721 ME_EndToUnicode(hWnd, wszText);
1724 else
1725 TRACE("WM_SETTEXT - NULL\n");
1726 ME_CommitUndo(editor);
1727 ME_EmptyUndoStack(editor);
1728 ME_SetSelection(editor, 0, 0);
1729 ME_UpdateRepaint(editor);
1730 return 0;
1732 case EM_CANPASTE:
1734 UINT nRTFFormat = RegisterClipboardFormatA("Rich Text Format");
1735 if (IsClipboardFormatAvailable(nRTFFormat))
1736 return TRUE;
1737 if (IsClipboardFormatAvailable(CF_UNICODETEXT))
1738 return TRUE;
1739 return FALSE;
1741 case WM_PASTE:
1743 DWORD dwFormat = 0;
1744 EDITSTREAM es;
1745 ME_GlobalDestStruct gds;
1746 UINT nRTFFormat = RegisterClipboardFormatA("Rich Text Format");
1747 UINT cf = 0;
1749 if (IsClipboardFormatAvailable(nRTFFormat))
1750 cf = nRTFFormat, dwFormat = SF_RTF;
1751 else if (IsClipboardFormatAvailable(CF_UNICODETEXT))
1752 cf = CF_UNICODETEXT, dwFormat = SF_TEXT|SF_UNICODE;
1753 else
1754 return 0;
1756 if (!OpenClipboard(hWnd))
1757 return 0;
1758 gds.hData = GetClipboardData(cf);
1759 gds.nLength = 0;
1760 es.dwCookie = (DWORD)&gds;
1761 es.pfnCallback = dwFormat == SF_RTF ? ME_ReadFromHGLOBALRTF : ME_ReadFromHGLOBALUnicode;
1762 ME_StreamIn(editor, dwFormat|SFF_SELECTION, &es);
1764 CloseClipboard();
1765 return 0;
1767 case WM_CUT:
1768 case WM_COPY:
1770 LPDATAOBJECT dataObj;
1771 CHARRANGE range;
1772 HRESULT hr;
1773 ME_GetSelection(editor, (int*)&range.cpMin, (int*)&range.cpMax);
1774 hr = ME_GetDataObject(editor, &range, &dataObj);
1775 if(SUCCEEDED(hr)) {
1776 hr = OleSetClipboard(dataObj);
1777 IDataObject_Release(dataObj);
1779 if (SUCCEEDED(hr) && msg == WM_CUT)
1781 ME_InternalDeleteText(editor, range.cpMin, range.cpMax-range.cpMin);
1782 ME_CommitUndo(editor);
1783 ME_UpdateRepaint(editor);
1785 return 0;
1787 case WM_GETTEXTLENGTH:
1788 return ME_GetTextLength(editor);
1789 case EM_GETTEXTLENGTHEX:
1790 return ME_GetTextLengthEx(editor, (GETTEXTLENGTHEX *)wParam);
1791 case WM_GETTEXT:
1793 TEXTRANGEW tr; /* W and A differ only by rng->lpstrText */
1794 tr.chrg.cpMin = 0;
1795 tr.chrg.cpMax = wParam-1;
1796 tr.lpstrText = (WCHAR *)lParam;
1797 return RichEditANSIWndProc(hWnd, EM_GETTEXTRANGE, 0, (LPARAM)&tr);
1799 case EM_GETTEXTEX:
1801 GETTEXTEX *ex = (GETTEXTEX*)wParam;
1802 int nStart, nCount;
1804 if (ex->flags & ~(GT_SELECTION | GT_USECRLF))
1805 FIXME("GETTEXTEX flags 0x%08lx not supported\n", ex->flags & ~(GT_SELECTION | GT_USECRLF));
1807 if (ex->flags & GT_SELECTION)
1809 ME_GetSelection(editor, &nStart, &nCount);
1810 nCount -= nStart;
1811 nCount = min(nCount, ex->cb - 1);
1813 else
1815 nStart = 0;
1816 nCount = ex->cb - 1;
1818 if (ex->codepage == 1200 || IsWindowUnicode(hWnd))
1820 nCount = min(nCount, ex->cb / sizeof(WCHAR) - 1);
1821 return ME_GetTextW(editor, (LPWSTR)lParam, nStart, nCount, ex->flags & GT_USECRLF);
1823 else
1825 /* potentially each char may be a CR, why calculate the exact value with O(N) when
1826 we can just take a bigger buffer? :) */
1827 int crlfmul = (ex->flags & GT_USECRLF) ? 2 : 1;
1828 LPWSTR buffer = HeapAlloc(GetProcessHeap(), 0, (crlfmul*nCount + 1) * sizeof(WCHAR));
1829 DWORD buflen = ex->cb;
1830 LRESULT rc;
1831 DWORD flags = 0;
1833 buflen = ME_GetTextW(editor, buffer, nStart, nCount, ex->flags & GT_USECRLF);
1834 rc = WideCharToMultiByte(ex->codepage, flags, buffer, buflen, (LPSTR)lParam, ex->cb, ex->lpDefaultChar, ex->lpUsedDefaultChar);
1836 HeapFree(GetProcessHeap(),0,buffer);
1837 return rc;
1840 case EM_GETSELTEXT:
1842 int from, to;
1843 TEXTRANGEW tr; /* W and A differ only by rng->lpstrText */
1844 ME_GetSelection(editor, &from, &to);
1845 tr.chrg.cpMin = from;
1846 tr.chrg.cpMax = to;
1847 tr.lpstrText = (WCHAR *)lParam;
1848 return RichEditANSIWndProc(hWnd, EM_GETTEXTRANGE, 0, (LPARAM)&tr);
1850 case EM_GETSCROLLPOS:
1852 POINT *point = (POINT *)lParam;
1853 point->x = 0; /* FIXME side scrolling not implemented */
1854 point->y = editor->nScrollPosY;
1855 return 1;
1857 case EM_GETTEXTRANGE:
1859 TEXTRANGEW *rng = (TEXTRANGEW *)lParam;
1860 TRACE("EM_GETTEXTRANGE min=%ld max=%ld unicode=%d emul1.0=%d length=%d\n",
1861 rng->chrg.cpMin, rng->chrg.cpMax, IsWindowUnicode(hWnd),
1862 editor->bEmulateVersion10, ME_GetTextLength(editor));
1863 if (IsWindowUnicode(hWnd))
1864 return ME_GetTextW(editor, rng->lpstrText, rng->chrg.cpMin, rng->chrg.cpMax-rng->chrg.cpMin, editor->bEmulateVersion10);
1865 else
1867 int nLen = rng->chrg.cpMax-rng->chrg.cpMin;
1868 WCHAR *p = ALLOC_N_OBJ(WCHAR, nLen+1);
1869 int nChars = ME_GetTextW(editor, p, rng->chrg.cpMin, nLen, editor->bEmulateVersion10);
1870 /* FIXME this is a potential security hole (buffer overrun)
1871 if you know more about wchar->mbyte conversion please explain
1873 WideCharToMultiByte(CP_ACP, 0, p, nChars+1, (char *)rng->lpstrText, nLen+1, NULL, NULL);
1874 FREE_OBJ(p);
1875 return nChars;
1878 case EM_GETLINECOUNT:
1880 ME_DisplayItem *item = editor->pBuffer->pFirst->next;
1881 int nRows = 0;
1883 while (item != editor->pBuffer->pLast)
1885 assert(item->type == diParagraph);
1886 nRows += item->member.para.nRows;
1887 item = item->member.para.next_para;
1889 TRACE("EM_GETLINECOUNT: nRows==%d\n", nRows);
1890 return max(1, nRows);
1892 case EM_LINEFROMCHAR:
1894 if (wParam == -1)
1895 return ME_RowNumberFromCharOfs(editor, ME_GetCursorOfs(editor, 1));
1896 else
1897 return ME_RowNumberFromCharOfs(editor, wParam);
1899 case EM_EXLINEFROMCHAR:
1901 return ME_RowNumberFromCharOfs(editor, lParam);
1903 case EM_LINEINDEX:
1905 ME_DisplayItem *item, *para;
1906 int nCharOfs;
1908 if (wParam == -1)
1909 item = ME_FindItemBack(editor->pCursors[0].pRun, diStartRow);
1910 else
1911 item = ME_FindRowWithNumber(editor, wParam);
1912 if (!item)
1913 return -1;
1914 para = ME_GetParagraph(item);
1915 item = ME_FindItemFwd(item, diRun);
1916 nCharOfs = para->member.para.nCharOfs + item->member.run.nCharOfs;
1917 TRACE("EM_LINEINDEX: nCharOfs==%d\n", nCharOfs);
1918 return nCharOfs;
1920 case EM_LINELENGTH:
1922 ME_DisplayItem *item, *item_end;
1923 int nChars = 0, nThisLineOfs = 0, nNextLineOfs = 0;
1925 if (wParam > ME_GetTextLength(editor))
1926 return 0;
1927 if (wParam == -1)
1929 FIXME("EM_LINELENGTH: returning number of unselected characters on lines with selection unsupported.\n");
1930 return 0;
1932 item = ME_FindItemAtOffset(editor, diRun, wParam, NULL);
1933 item = ME_RowStart(item);
1934 nThisLineOfs = ME_CharOfsFromRunOfs(editor, ME_FindItemFwd(item, diRun), 0);
1935 item_end = ME_FindItemFwd(item, diStartRow);
1936 if (item_end)
1937 nNextLineOfs = ME_CharOfsFromRunOfs(editor, ME_FindItemFwd(item_end, diRun), 0);
1938 else
1939 nNextLineOfs = ME_FindItemFwd(item, diParagraphOrEnd)->member.para.nCharOfs
1940 - (editor->bEmulateVersion10?2:1);
1941 nChars = nNextLineOfs - nThisLineOfs;
1942 TRACE("EM_LINELENGTH(%d)==%d\n",wParam, nChars);
1943 return nChars;
1945 case EM_FINDTEXT:
1947 FINDTEXTA *ft = (FINDTEXTA *)lParam;
1948 int nChars = MultiByteToWideChar(CP_ACP, 0, ft->lpstrText, -1, NULL, 0);
1949 WCHAR *tmp;
1951 if ((tmp = ALLOC_N_OBJ(WCHAR, nChars)) != NULL)
1952 MultiByteToWideChar(CP_ACP, 0, ft->lpstrText, -1, tmp, nChars);
1953 return ME_FindText(editor, wParam, &ft->chrg, tmp, NULL);
1955 case EM_FINDTEXTEX:
1957 FINDTEXTEXA *ex = (FINDTEXTEXA *)lParam;
1958 int nChars = MultiByteToWideChar(CP_ACP, 0, ex->lpstrText, -1, NULL, 0);
1959 WCHAR *tmp;
1961 if ((tmp = ALLOC_N_OBJ(WCHAR, nChars)) != NULL)
1962 MultiByteToWideChar(CP_ACP, 0, ex->lpstrText, -1, tmp, nChars);
1963 return ME_FindText(editor, wParam, &ex->chrg, tmp, &ex->chrgText);
1965 case EM_FINDTEXTW:
1967 FINDTEXTW *ft = (FINDTEXTW *)lParam;
1968 return ME_FindText(editor, wParam, &ft->chrg, ft->lpstrText, NULL);
1970 case EM_FINDTEXTEXW:
1972 FINDTEXTEXW *ex = (FINDTEXTEXW *)lParam;
1973 return ME_FindText(editor, wParam, &ex->chrg, ex->lpstrText, &ex->chrgText);
1975 case EM_GETZOOM:
1976 if (!wParam || !lParam)
1977 return FALSE;
1978 *(int *)wParam = editor->nZoomNumerator;
1979 *(int *)lParam = editor->nZoomDenominator;
1980 return TRUE;
1981 case EM_SETZOOM:
1982 return ME_SetZoom(editor, wParam, lParam);
1983 case EM_CHARFROMPOS:
1984 return ME_CharFromPos(editor, ((POINTL *)lParam)->x, ((POINTL *)lParam)->y);
1985 case EM_POSFROMCHAR:
1987 ME_DisplayItem *pRun;
1988 int nCharOfs, nOffset, nLength;
1989 POINTL pt = {0,0};
1991 nCharOfs = wParam;
1992 /* detect which API version we're dealing with */
1993 if (wParam >= 0x40000)
1994 nCharOfs = lParam;
1995 nLength = ME_GetTextLength(editor);
1997 if (nCharOfs < nLength) {
1998 ME_RunOfsFromCharOfs(editor, nCharOfs, &pRun, &nOffset);
1999 assert(pRun->type == diRun);
2000 pt.y = pRun->member.run.pt.y;
2001 pt.x = pRun->member.run.pt.x + ME_PointFromChar(editor, &pRun->member.run, nOffset);
2002 pt.y += ME_GetParagraph(pRun)->member.para.nYPos;
2003 } else {
2004 pt.x = 0;
2005 pt.y = editor->pBuffer->pLast->member.para.nYPos;
2007 if (wParam >= 0x40000) {
2008 *(POINTL *)wParam = pt;
2010 return MAKELONG( pt.x, pt.y );
2012 case WM_CREATE:
2013 ME_CommitUndo(editor);
2014 ME_WrapMarkedParagraphs(editor);
2015 ME_MoveCaret(editor);
2016 return 0;
2017 case WM_DESTROY:
2018 ME_DestroyEditor(editor);
2019 SetWindowLongW(hWnd, 0, 0);
2020 return 0;
2021 case WM_LBUTTONDOWN:
2022 SetFocus(hWnd);
2023 ME_LButtonDown(editor, (short)LOWORD(lParam), (short)HIWORD(lParam));
2024 SetCapture(hWnd);
2025 break;
2026 case WM_MOUSEMOVE:
2027 if (GetCapture() == hWnd)
2028 ME_MouseMove(editor, (short)LOWORD(lParam), (short)HIWORD(lParam));
2029 break;
2030 case WM_LBUTTONUP:
2031 if (GetCapture() == hWnd)
2032 ReleaseCapture();
2033 break;
2034 case WM_LBUTTONDBLCLK:
2035 ME_SelectWord(editor);
2036 break;
2037 case WM_CONTEXTMENU:
2038 ME_ShowContextMenu(editor, (short)LOWORD(lParam), (short)HIWORD(lParam));
2039 break;
2040 case WM_PAINT:
2041 if (editor->bRedraw)
2043 HDC hDC;
2044 PAINTSTRUCT ps;
2046 hDC = BeginPaint(hWnd, &ps);
2047 ME_PaintContent(editor, hDC, FALSE, &ps.rcPaint);
2048 EndPaint(hWnd, &ps);
2050 break;
2051 case WM_SETFOCUS:
2052 ME_ShowCaret(editor);
2053 ME_SendOldNotify(editor, EN_SETFOCUS);
2054 return 0;
2055 case WM_KILLFOCUS:
2056 ME_HideCaret(editor);
2057 ME_SendOldNotify(editor, EN_KILLFOCUS);
2058 return 0;
2059 case WM_ERASEBKGND:
2061 if (editor->bRedraw)
2063 HDC hDC = (HDC)wParam;
2064 RECT rc;
2065 if (GetUpdateRect(hWnd,&rc,TRUE))
2067 FillRect(hDC, &rc, editor->hbrBackground);
2070 return 1;
2072 case WM_COMMAND:
2073 TRACE("editor wnd command = %d\n", LOWORD(wParam));
2074 return 0;
2075 case WM_KEYDOWN:
2076 if (ME_KeyDown(editor, LOWORD(wParam)))
2077 return 0;
2078 goto do_default;
2079 case WM_CHAR:
2081 WCHAR wstr = LOWORD(wParam);
2083 switch (wstr)
2085 case 3: /* Ctrl-C */
2086 SendMessageW(editor->hWnd, WM_COPY, 0, 0);
2087 return 0;
2090 if (GetWindowLongW(editor->hWnd, GWL_STYLE) & ES_READONLY) {
2091 MessageBeep(MB_ICONERROR);
2092 return 0; /* FIXME really 0 ? */
2095 switch (wstr)
2097 case 1: /* Ctrl-A */
2098 ME_SetSelection(editor, 0, -1);
2099 return 0;
2100 case 22: /* Ctrl-V */
2101 SendMessageW(editor->hWnd, WM_PASTE, 0, 0);
2102 return 0;
2103 case 24: /* Ctrl-X */
2104 SendMessageW(editor->hWnd, WM_CUT, 0, 0);
2105 return 0;
2106 case 25: /* Ctrl-Y */
2107 SendMessageW(editor->hWnd, EM_REDO, 0, 0);
2108 return 0;
2109 case 26: /* Ctrl-Z */
2110 SendMessageW(editor->hWnd, EM_UNDO, 0, 0);
2111 return 0;
2113 if (((unsigned)wstr)>=' ' || wstr=='\r' || wstr=='\t') {
2114 /* FIXME maybe it would make sense to call EM_REPLACESEL instead ? */
2115 ME_Style *style = ME_GetInsertStyle(editor, 0);
2116 ME_SaveTempStyle(editor);
2117 ME_InsertTextFromCursor(editor, 0, &wstr, 1, style);
2118 ME_ReleaseStyle(style);
2119 ME_CommitUndo(editor);
2120 ME_UpdateRepaint(editor);
2122 return 0;
2124 case WM_VSCROLL:
2126 int nPos = editor->nScrollPosY;
2127 si.cbSize = sizeof(SCROLLINFO);
2128 si.fMask = SIF_PAGE|SIF_POS|SIF_RANGE|SIF_TRACKPOS;
2129 GetScrollInfo(hWnd, SB_VERT, &si);
2130 switch(LOWORD(wParam)) {
2131 case SB_LINEUP:
2132 nPos -= 24; /* FIXME follow the original */
2133 if (nPos<0) nPos = 0;
2134 break;
2135 case SB_LINEDOWN:
2137 int nEnd = editor->nTotalLength - editor->sizeWindow.cy;
2138 nPos += 24; /* FIXME follow the original */
2139 if (nPos>=nEnd) nPos = nEnd;
2140 break;
2142 case SB_PAGEUP:
2143 nPos -= editor->sizeWindow.cy;
2144 if (nPos<0) nPos = 0;
2145 break;
2146 case SB_PAGEDOWN:
2147 nPos += editor->sizeWindow.cy;
2148 if (nPos>=editor->nTotalLength) nPos = editor->nTotalLength-1;
2149 break;
2150 case SB_THUMBTRACK:
2151 case SB_THUMBPOSITION:
2152 nPos = si.nTrackPos;
2153 break;
2155 if (nPos != editor->nScrollPosY) {
2156 int dy = editor->nScrollPosY - nPos;
2157 editor->nScrollPosY = nPos;
2158 SetScrollPos(hWnd, SB_VERT, nPos, TRUE);
2159 if (editor->bRedraw)
2161 ScrollWindow(hWnd, 0, dy, NULL, NULL);
2162 UpdateWindow(hWnd);
2165 break;
2167 case WM_MOUSEWHEEL:
2169 int gcWheelDelta = 0, nPos = editor->nScrollPosY, nEnd = editor->nTotalLength - editor->sizeWindow.cy;
2170 UINT pulScrollLines;
2171 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES,0, &pulScrollLines, 0);
2172 gcWheelDelta -= GET_WHEEL_DELTA_WPARAM(wParam);
2173 if (abs(gcWheelDelta) >= WHEEL_DELTA && pulScrollLines)
2174 nPos += pulScrollLines * (gcWheelDelta / WHEEL_DELTA) * 8; /* FIXME follow the original */
2175 if (nPos>=nEnd)
2176 nPos = nEnd;
2177 if (nPos<0)
2178 nPos = 0;
2179 if (nPos != editor->nScrollPosY) {
2180 int dy = editor->nScrollPosY - nPos;
2181 editor->nScrollPosY = nPos;
2182 SetScrollPos(hWnd, SB_VERT, nPos, TRUE);
2183 if (editor->bRedraw)
2185 ScrollWindow(hWnd, 0, dy, NULL, NULL);
2186 UpdateWindow(hWnd);
2189 break;
2191 case EM_GETRECT:
2193 *((RECT *)lParam) = editor->rcFormat;
2194 return 0;
2196 case EM_SETRECT:
2197 case EM_SETRECTNP:
2199 if (lParam)
2201 RECT *rc = (RECT *)lParam;
2203 if (wParam)
2205 editor->rcFormat.left += rc->left;
2206 editor->rcFormat.top += rc->top;
2207 editor->rcFormat.right += rc->right;
2208 editor->rcFormat.bottom += rc->bottom;
2210 else
2212 editor->rcFormat = *rc;
2215 else
2217 GetClientRect(hWnd, &editor->rcFormat);
2219 if (msg != EM_SETRECTNP)
2220 ME_RewrapRepaint(editor);
2221 return 0;
2223 case EM_REQUESTRESIZE:
2224 ME_SendRequestResize(editor, TRUE);
2225 return 0;
2226 case WM_SETREDRAW:
2227 editor->bRedraw = wParam;
2228 return 0;
2229 case WM_SIZE:
2231 GetClientRect(hWnd, &editor->rcFormat);
2232 ME_RewrapRepaint(editor);
2233 return DefWindowProcW(hWnd, msg, wParam, lParam);
2235 case EM_GETOLEINTERFACE:
2237 LPVOID *ppvObj = (LPVOID*) lParam;
2238 FIXME("EM_GETOLEINTERFACE %p: stub\n", ppvObj);
2239 return CreateIRichEditOle(editor, ppvObj);
2241 case EM_SETOLECALLBACK:
2242 if(editor->lpOleCallback)
2243 IUnknown_Release(editor->lpOleCallback);
2244 editor->lpOleCallback = (LPRICHEDITOLECALLBACK)lParam;
2245 if(editor->lpOleCallback)
2246 IUnknown_AddRef(editor->lpOleCallback);
2247 return TRUE;
2248 case EM_GETWORDBREAKPROC:
2249 return (LRESULT)editor->pfnWordBreak;
2250 case EM_SETWORDBREAKPROC:
2252 EDITWORDBREAKPROCW pfnOld = editor->pfnWordBreak;
2254 editor->pfnWordBreak = (EDITWORDBREAKPROCW)lParam;
2255 return (LRESULT)pfnOld;
2257 case EM_SETTEXTMODE:
2259 LRESULT ret;
2260 int mask = 0;
2261 int changes = 0;
2262 if ((ret = RichEditANSIWndProc(hWnd, WM_GETTEXTLENGTH, 0, 0)) == 0)
2264 /*Check for valid wParam*/
2265 if ((((wParam & TM_RICHTEXT) && ((wParam & TM_PLAINTEXT) << 1))) ||
2266 (((wParam & TM_MULTILEVELUNDO) && ((wParam & TM_SINGLELEVELUNDO) << 1))) ||
2267 (((wParam & TM_MULTICODEPAGE) && ((wParam & TM_SINGLECODEPAGE) << 1))))
2268 return 1;
2269 else
2271 if (wParam & (TM_RICHTEXT | TM_PLAINTEXT))
2273 mask |= (TM_RICHTEXT | TM_PLAINTEXT);
2274 changes |= (wParam & (TM_RICHTEXT | TM_PLAINTEXT));
2276 /*FIXME: Currently no support for undo level and code page options*/
2277 editor->mode = (editor->mode & (~mask)) | changes;
2278 return 0;
2281 return ret;
2283 default:
2284 do_default:
2285 return DefWindowProcW(hWnd, msg, wParam, lParam);
2287 return 0L;
2291 /******************************************************************
2292 * RichEdit10ANSIWndProc (RICHED20.9)
2294 LRESULT WINAPI RichEdit10ANSIWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
2296 LRESULT result;
2298 /* FIXME: this is NOT the same as 2.0 version */
2299 result = RichEditANSIWndProc(hWnd, msg, wParam, lParam);
2300 if (msg == WM_NCCREATE)
2302 ME_TextEditor *editor = (ME_TextEditor *)GetWindowLongW(hWnd, 0);
2304 editor->bEmulateVersion10 = TRUE;
2305 editor->pBuffer->pLast->member.para.nCharOfs = 2;
2307 return result;
2310 void ME_SendOldNotify(ME_TextEditor *editor, int nCode)
2312 HWND hWnd = editor->hWnd;
2313 SendMessageA(GetParent(hWnd), WM_COMMAND, (nCode<<16)|GetWindowLongW(hWnd, GWLP_ID), (LPARAM)hWnd);
2316 int ME_CountParagraphsBetween(ME_TextEditor *editor, int from, int to)
2318 ME_DisplayItem *item = ME_FindItemFwd(editor->pBuffer->pFirst, diParagraph);
2319 int i = 0;
2321 while(item && item->member.para.next_para->member.para.nCharOfs <= from)
2322 item = item->member.para.next_para;
2323 if (!item)
2324 return 0;
2325 while(item && item->member.para.next_para->member.para.nCharOfs <= to) {
2326 item = item->member.para.next_para;
2327 i++;
2329 return i;
2333 int ME_GetTextW(ME_TextEditor *editor, WCHAR *buffer, int nStart, int nChars, int bCRLF)
2335 ME_DisplayItem *item = ME_FindItemAtOffset(editor, diRun, nStart, &nStart);
2336 int nWritten = 0;
2337 WCHAR *pStart = buffer;
2339 if (!item) {
2340 *buffer = L'\0';
2341 return 0;
2344 if (nStart)
2346 int nLen = ME_StrLen(item->member.run.strText) - nStart;
2347 if (nLen > nChars)
2348 nLen = nChars;
2349 CopyMemory(buffer, item->member.run.strText->szData + nStart, sizeof(WCHAR)*nLen);
2350 nChars -= nLen;
2351 nWritten += nLen;
2352 if (!nChars)
2353 return nWritten;
2354 buffer += nLen;
2355 nStart = 0;
2356 item = ME_FindItemFwd(item, diRun);
2359 while(nChars && item)
2361 int nLen = ME_StrLen(item->member.run.strText);
2362 if (nLen > nChars)
2363 nLen = nChars;
2365 if (item->member.run.nFlags & MERF_ENDPARA)
2367 *buffer = '\r';
2368 if (bCRLF)
2370 *(++buffer) = '\n';
2371 nWritten++;
2373 assert(nLen == 1);
2374 /* our end paragraph consists of 2 characters now */
2375 if (editor->bEmulateVersion10)
2376 nChars--;
2378 else
2379 CopyMemory(buffer, item->member.run.strText->szData, sizeof(WCHAR)*nLen);
2380 nChars -= nLen;
2381 nWritten += nLen;
2382 buffer += nLen;
2384 if (!nChars)
2386 TRACE("nWritten=%d, actual=%d\n", nWritten, buffer-pStart);
2387 *buffer = L'\0';
2388 return nWritten;
2390 item = ME_FindItemFwd(item, diRun);
2392 *buffer = L'\0';
2393 TRACE("nWritten=%d, actual=%d\n", nWritten, buffer-pStart);
2394 return nWritten;
2397 void ME_RegisterEditorClass(HINSTANCE hInstance)
2399 BOOL bResult;
2400 WNDCLASSW wcW;
2401 WNDCLASSA wcA;
2403 wcW.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW | CS_GLOBALCLASS;
2404 wcW.lpfnWndProc = RichEditANSIWndProc;
2405 wcW.cbClsExtra = 0;
2406 wcW.cbWndExtra = 4;
2407 wcW.hInstance = NULL; /* hInstance would register DLL-local class */
2408 wcW.hIcon = NULL;
2409 wcW.hCursor = LoadCursorW(NULL, MAKEINTRESOURCEW(IDC_IBEAM));
2410 wcW.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);
2411 wcW.lpszMenuName = NULL;
2412 wcW.lpszClassName = wszClassName;
2413 bResult = RegisterClassW(&wcW);
2414 assert(bResult);
2415 wcW.lpszClassName = wszClassName50;
2416 bResult = RegisterClassW(&wcW);
2417 assert(bResult);
2419 wcA.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW | CS_GLOBALCLASS;
2420 wcA.lpfnWndProc = RichEditANSIWndProc;
2421 wcA.cbClsExtra = 0;
2422 wcA.cbWndExtra = 4;
2423 wcA.hInstance = NULL; /* hInstance would register DLL-local class */
2424 wcA.hIcon = NULL;
2425 wcA.hCursor = LoadCursorW(NULL, MAKEINTRESOURCEW(IDC_IBEAM));
2426 wcA.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);
2427 wcA.lpszMenuName = NULL;
2428 wcA.lpszClassName = "RichEdit20A";
2429 bResult = RegisterClassA(&wcA);
2430 assert(bResult);
2431 wcA.lpszClassName = "RichEdit50A";
2432 bResult = RegisterClassA(&wcA);
2433 assert(bResult);
2436 LRESULT WINAPI REComboWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
2437 /* FIXME: Not implemented */
2438 TRACE("hWnd %p msg %04x (%s) %08x %08lx\n",
2439 hWnd, msg, get_msg_name(msg), wParam, lParam);
2440 return DefWindowProcW(hWnd, msg, wParam, lParam);
2443 LRESULT WINAPI REListWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
2444 /* FIXME: Not implemented */
2445 TRACE("hWnd %p msg %04x (%s) %08x %08lx\n",
2446 hWnd, msg, get_msg_name(msg), wParam, lParam);
2447 return DefWindowProcW(hWnd, msg, wParam, lParam);
2450 /******************************************************************
2451 * REExtendedRegisterClass (RICHED20.8)
2453 * FIXME undocumented
2454 * Need to check for errors and implement controls and callbacks
2456 LRESULT WINAPI REExtendedRegisterClass(void)
2458 WNDCLASSW wcW;
2459 UINT result;
2461 FIXME("semi stub\n");
2463 wcW.cbClsExtra = 0;
2464 wcW.cbWndExtra = 4;
2465 wcW.hInstance = NULL;
2466 wcW.hIcon = NULL;
2467 wcW.hCursor = NULL;
2468 wcW.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
2469 wcW.lpszMenuName = NULL;
2471 if (!ME_ListBoxRegistered)
2473 wcW.style = CS_PARENTDC | CS_DBLCLKS | CS_GLOBALCLASS;
2474 wcW.lpfnWndProc = REListWndProc;
2475 wcW.lpszClassName = wszClassNameListBox;
2476 if (RegisterClassW(&wcW)) ME_ListBoxRegistered = TRUE;
2479 if (!ME_ComboBoxRegistered)
2481 wcW.style = CS_PARENTDC | CS_DBLCLKS | CS_GLOBALCLASS | CS_VREDRAW | CS_HREDRAW;
2482 wcW.lpfnWndProc = REComboWndProc;
2483 wcW.lpszClassName = wszClassNameComboBox;
2484 if (RegisterClassW(&wcW)) ME_ComboBoxRegistered = TRUE;
2487 result = 0;
2488 if (ME_ListBoxRegistered)
2489 result += 1;
2490 if (ME_ComboBoxRegistered)
2491 result += 2;
2493 return result;