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
7 * Copyright 2008 Eric Pouech
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 API implementation status:
27 Messages (ANSI versions not done yet)
28 + EM_AUTOURLDETECT 2.0
39 + EM_FINDTEXT (only FR_DOWN flag implemented)
40 + EM_FINDTEXTEX (only FR_DOWN flag implemented)
44 + EM_GETAUTOURLDETECT 2.0
45 - EM_GETBIDIOPTIONS 3.0
46 - EM_GETCHARFORMAT (partly done)
49 + EM_GETFIRSTVISIBLELINE (can be optimized if needed)
50 - EM_GETIMECOLOR 1.0asian
51 - EM_GETIMECOMPMODE 2.0
52 - EM_GETIMEOPTIONS 1.0asian
54 - EM_GETLANGOPTIONS 2.0
57 + EM_GETLINECOUNT returns number of rows, not of paragraphs
62 + EM_GETPASSWORDCHAR 2.0
63 - EM_GETPUNCTUATION 1.0asian
67 + EM_GETSELTEXT (ANSI&Unicode)
68 + EM_GETSCROLLPOS 3.0 (only Y value valid)
71 + EM_GETTEXTLENGTHEX (GTL_PRECISE unimplemented)
73 ? + EM_GETTEXTRANGE (ANSI&Unicode)
74 - EM_GETTYPOGRAPHYOPTIONS 3.0
77 - EM_GETWORDBREAKPROCEX
78 - EM_GETWORDWRAPMODE 1.0asian
81 + EM_LIMITTEXT (Also called EM_SETLIMITTEXT)
90 + EM_REPLACESEL (proper style?) ANSI&Unicode
94 - EM_SETBIDIOPTIONS 3.0
96 + EM_SETCHARFORMAT (partly done, no ANSI)
98 + EM_SETEVENTMASK (few notifications supported)
100 - EM_SETIMECOLOR 1.0asian
101 - EM_SETIMEOPTIONS 1.0asian
102 - EM_SETLANGOPTIONS 2.0
104 + EM_SETMODIFY (not sure if implementation is correct)
106 + EM_SETOPTIONS (partially implemented)
109 + EM_SETPASSWORDCHAR 2.0
110 - EM_SETPUNCTUATION 1.0asian
111 + EM_SETREADONLY no beep on modification attempt
113 + EM_SETRECTNP (EM_SETRECT without repainting)
115 + EM_SETSCROLLPOS 3.0
117 - EM_SETTARGETDEVICE (partial)
118 + EM_SETTEXTEX 3.0 (proper style?)
120 - EM_SETTYPOGRAPHYOPTIONS 3.0
121 + EM_SETUNDOLIMIT 2.0
122 + EM_SETWORDBREAKPROC (used only for word movement at the moment)
123 - EM_SETWORDBREAKPROCEX
124 - EM_SETWORDWRAPMODE 1.0asian
126 + EM_SHOWSCROLLBAR 2.0
127 - EM_STOPGROUPTYPING 2.0
135 + WM_GETDLGCODE (the current implementation is incomplete)
136 + WM_GETTEXT (ANSI&Unicode)
137 + WM_GETTEXTLENGTH (ANSI version sucks)
140 + WM_SETTEXT (resets undo stack !) (proper style?) ANSI&Unicode
142 - WM_STYLECHANGED (things like read-only flag)
147 * EN_CHANGE (sent from the wrong place)
164 * EN_UPDATE (sent from the wrong place)
172 + ES_DISABLENOSCROLL (scrollbar is always visible)
173 - ES_EX_NOCALLOLEINIT
175 - ES_MULTILINE (currently single line controls aren't supported)
177 - ES_READONLY (I'm not sure if beeping is the proper behaviour)
183 - ES_WANTRETURN (don't know how to do WM_GETDLGCODE part)
190 * RICHED20 TODO (incomplete):
192 * - messages/styles/notifications listed above
194 * - add remaining CHARFORMAT/PARAFORMAT fields
195 * - right/center align should strip spaces from the beginning
196 * - pictures/OLE objects (not just smiling faces that lack API support ;-) )
197 * - COM interface (looks like a major pain in the TODO list)
198 * - calculate heights of pictures (half-done)
199 * - horizontal scrolling (not even started)
200 * - hysteresis during wrapping (related to scrollbars appearing/disappearing)
202 * - how to implement EM_FORMATRANGE and EM_DISPLAYBAND ? (Mission Impossible)
203 * - italic caret with italic fonts
205 * - most notifications aren't sent at all (the most important ones are)
206 * - when should EN_SELCHANGE be sent after text change ? (before/after EN_UPDATE?)
207 * - WM_SETTEXT may use wrong style (but I'm 80% sure it's OK)
208 * - EM_GETCHARFORMAT with SCF_SELECTION may not behave 100% like in original (but very close)
209 * - full justification
212 * - ListBox & ComboBox not implemented
214 * Bugs that are probably fixed, but not so easy to verify:
215 * - EN_UPDATE/EN_CHANGE are handled very incorrectly (should be OK now)
216 * - undo for ME_JoinParagraphs doesn't store paragraph format ? (it does)
217 * - check/fix artificial EOL logic (bCursorAtEnd, hardly logical)
218 * - caret shouldn't be displayed when selection isn't empty
219 * - check refcounting in style management functions (looks perfect now, but no bugs is suspicious)
220 * - undo for setting default format (done, might be buggy)
221 * - styles might be not released properly (looks like they work like charm, but who knows?
228 #define NO_SHLWAPI_STREAM
234 #define STACK_SIZE_DEFAULT 100
235 #define STACK_SIZE_MAX 1000
237 #define TEXT_LIMIT_DEFAULT 32767
239 WINE_DEFAULT_DEBUG_CHANNEL(richedit);
241 static BOOL ME_RegisterEditorClass(HINSTANCE);
243 static const WCHAR RichEdit20W[] = {'R', 'i', 'c', 'h', 'E', 'd', 'i', 't', '2', '0', 'W', 0};
244 static const WCHAR RichEdit50W[] = {'R', 'i', 'c', 'h', 'E', 'd', 'i', 't', '5', '0', 'W', 0};
245 static const WCHAR REListBox20W[] = {'R','E','L','i','s','t','B','o','x','2','0','W', 0};
246 static const WCHAR REComboBox20W[] = {'R','E','C','o','m','b','o','B','o','x','2','0','W', 0};
247 static HCURSOR hLeft;
250 HANDLE me_heap = NULL;
252 static BOOL ME_ListBoxRegistered = FALSE;
253 static BOOL ME_ComboBoxRegistered = FALSE;
255 static inline int is_version_nt(void)
257 return !(GetVersion() & 0x80000000);
260 static ME_TextBuffer *ME_MakeText(void) {
262 ME_TextBuffer *buf = ALLOC_OBJ(ME_TextBuffer);
264 ME_DisplayItem *p1 = ME_MakeDI(diTextStart);
265 ME_DisplayItem *p2 = ME_MakeDI(diTextEnd);
271 p1->member.para.next_para = p2;
272 p2->member.para.prev_para = p1;
273 p2->member.para.nCharOfs = 0;
277 buf->pCharStyle = NULL;
283 static LRESULT ME_StreamInText(ME_TextEditor *editor, DWORD dwFormat, ME_InStream *stream, ME_Style *style)
285 WCHAR wszText[STREAMIN_BUFFER_SIZE+1];
288 TRACE("%08x %p\n", dwFormat, stream);
295 ME_StreamInFill(stream);
296 if (stream->editstream->dwError)
302 if (!(dwFormat & SF_UNICODE))
304 /* FIXME? this is doomed to fail on true MBCS like UTF-8, luckily they're unlikely to be used as CP_ACP */
305 nWideChars = MultiByteToWideChar(CP_ACP, 0, stream->buffer, stream->dwSize, wszText, STREAMIN_BUFFER_SIZE);
310 nWideChars = stream->dwSize >> 1;
311 pText = (WCHAR *)stream->buffer;
314 ME_InsertTextFromCursor(editor, 0, pText, nWideChars, style);
315 if (stream->dwSize == 0)
319 ME_CommitUndo(editor);
320 ME_UpdateRepaint(editor);
324 static void ME_RTFCharAttrHook(RTF_Info *info)
327 fmt.cbSize = sizeof(fmt);
331 switch(info->rtfMinor)
334 /* FIXME add more flags once they're implemented */
335 fmt.dwMask = CFM_BOLD | CFM_ITALIC | CFM_UNDERLINETYPE | CFM_STRIKEOUT | CFM_COLOR | CFM_BACKCOLOR | CFM_SIZE | CFM_WEIGHT;
336 fmt.dwEffects = CFE_AUTOCOLOR | CFE_AUTOBACKCOLOR;
337 fmt.yHeight = 12*20; /* 12pt */
338 fmt.wWeight = FW_NORMAL;
339 fmt.bUnderlineType = CFU_UNDERLINENONE;
342 fmt.dwMask = CFM_BOLD | CFM_WEIGHT;
343 fmt.dwEffects = info->rtfParam ? CFE_BOLD : 0;
344 fmt.wWeight = info->rtfParam ? FW_BOLD : FW_NORMAL;
347 fmt.dwMask = CFM_ITALIC;
348 fmt.dwEffects = info->rtfParam ? fmt.dwMask : 0;
351 fmt.dwMask = CFM_UNDERLINETYPE;
352 fmt.bUnderlineType = info->rtfParam ? CFU_CF1UNDERLINE : CFU_UNDERLINENONE;
354 case rtfDotUnderline:
355 fmt.dwMask = CFM_UNDERLINETYPE;
356 fmt.bUnderlineType = info->rtfParam ? CFU_UNDERLINEDOTTED : CFU_UNDERLINENONE;
359 fmt.dwMask = CFM_UNDERLINETYPE;
360 fmt.bUnderlineType = info->rtfParam ? CFU_UNDERLINEDOUBLE : CFU_UNDERLINENONE;
362 case rtfWordUnderline:
363 fmt.dwMask = CFM_UNDERLINETYPE;
364 fmt.bUnderlineType = info->rtfParam ? CFU_UNDERLINEWORD : CFU_UNDERLINENONE;
367 fmt.dwMask = CFM_UNDERLINETYPE;
368 fmt.bUnderlineType = CFU_UNDERLINENONE;
371 fmt.dwMask = CFM_STRIKEOUT;
372 fmt.dwEffects = info->rtfParam ? fmt.dwMask : 0;
376 case rtfSubScrShrink:
377 case rtfSuperScrShrink:
379 fmt.dwMask = CFM_SUBSCRIPT|CFM_SUPERSCRIPT;
380 if (info->rtfMinor == rtfSubScrShrink) fmt.dwEffects = CFE_SUBSCRIPT;
381 if (info->rtfMinor == rtfSuperScrShrink) fmt.dwEffects = CFE_SUPERSCRIPT;
382 if (info->rtfMinor == rtfNoSuperSub) fmt.dwEffects = 0;
385 fmt.dwMask = CFM_HIDDEN;
386 fmt.dwEffects = info->rtfParam ? fmt.dwMask : 0;
389 fmt.dwMask = CFM_BACKCOLOR;
391 if (info->rtfParam == 0)
392 fmt.dwEffects = CFE_AUTOBACKCOLOR;
393 else if (info->rtfParam != rtfNoParam)
395 RTFColor *c = RTFGetColor(info, info->rtfParam);
396 fmt.crTextColor = (c->rtfCBlue<<16)|(c->rtfCGreen<<8)|(c->rtfCRed);
400 fmt.dwMask = CFM_COLOR;
402 if (info->rtfParam == 0)
403 fmt.dwEffects = CFE_AUTOCOLOR;
404 else if (info->rtfParam != rtfNoParam)
406 RTFColor *c = RTFGetColor(info, info->rtfParam);
408 fmt.crTextColor = (c->rtfCBlue<<16)|(c->rtfCGreen<<8)|(c->rtfCRed);
414 if (info->rtfParam != rtfNoParam)
416 RTFFont *f = RTFGetFont(info, info->rtfParam);
419 MultiByteToWideChar(CP_ACP, 0, f->rtfFName, -1, fmt.szFaceName, sizeof(fmt.szFaceName)/sizeof(WCHAR));
420 fmt.szFaceName[sizeof(fmt.szFaceName)/sizeof(WCHAR)-1] = '\0';
421 fmt.bCharSet = f->rtfFCharSet;
422 fmt.dwMask = CFM_FACE | CFM_CHARSET;
423 fmt.bPitchAndFamily = f->rtfFPitch | (f->rtfFFamily << 4);
428 fmt.dwMask = CFM_SIZE;
429 if (info->rtfParam != rtfNoParam)
430 fmt.yHeight = info->rtfParam*10;
435 RTFFlushOutputBuffer(info);
436 /* FIXME too slow ? how come ? */
437 style2 = ME_ApplyStyle(info->style, &fmt);
438 ME_ReleaseStyle(info->style);
439 info->style = style2;
440 info->styleChanged = TRUE;
444 /* FIXME this function doesn't get any information about context of the RTF tag, which is very bad,
445 the same tags mean different things in different contexts */
446 static void ME_RTFParAttrHook(RTF_Info *info)
449 fmt.cbSize = sizeof(fmt);
452 switch(info->rtfMinor)
454 case rtfParDef: /* restores default paragraph attributes */
455 fmt.dwMask = PFM_ALIGNMENT | PFM_BORDER | PFM_LINESPACING | PFM_TABSTOPS | PFM_OFFSET |
456 PFM_RIGHTINDENT | PFM_SPACEAFTER | PFM_SPACEBEFORE | PFM_STARTINDENT;
457 /* TODO: numbering, shading */
458 fmt.wAlignment = PFA_LEFT;
460 fmt.dxOffset = fmt.dxStartIndent = fmt.dxRightIndent = 0;
461 fmt.wBorderWidth = fmt.wBorders = 0;
462 fmt.wBorderSpace = 0;
463 fmt.bLineSpacingRule = 0;
464 fmt.dySpaceBefore = fmt.dySpaceAfter = 0;
465 fmt.dyLineSpacing = 0;
466 RTFFlushOutputBuffer(info);
467 ME_GetParagraph(info->editor->pCursors[0].pRun)->member.para.bTable = FALSE;
471 ME_DisplayItem *para;
473 RTFFlushOutputBuffer(info);
474 para = ME_GetParagraph(info->editor->pCursors[0].pRun);
475 assert(para->member.para.pCells);
476 para->member.para.bTable = TRUE;
480 ME_GetSelectionParaFormat(info->editor, &fmt);
481 fmt.dwMask |= PFM_STARTINDENT | PFM_OFFSET;
482 fmt.dxStartIndent += info->rtfParam;
483 fmt.dxOffset = -info->rtfParam;
486 /* we assume rtfLeftIndent is always specified before rtfFirstIndent */
487 ME_GetSelectionParaFormat(info->editor, &fmt);
488 fmt.dwMask |= PFM_STARTINDENT;
489 fmt.dxStartIndent = info->rtfParam;
493 fmt.dwMask = PFM_RIGHTINDENT;
494 fmt.dxRightIndent = info->rtfParam;
498 fmt.dwMask = PFM_ALIGNMENT;
499 fmt.wAlignment = PFA_LEFT;
502 fmt.dwMask = PFM_ALIGNMENT;
503 fmt.wAlignment = PFA_RIGHT;
506 fmt.dwMask = PFM_ALIGNMENT;
507 fmt.wAlignment = PFA_CENTER;
510 ME_GetSelectionParaFormat(info->editor, &fmt);
511 if (!(fmt.dwMask & PFM_TABSTOPS))
513 fmt.dwMask |= PFM_TABSTOPS;
516 if (fmt.cTabCount < MAX_TAB_STOPS)
517 fmt.rgxTabs[fmt.cTabCount++] = info->rtfParam;
520 fmt.dwMask = PFM_KEEP;
521 fmt.wEffects = PFE_KEEP;
523 case rtfNoWidowControl:
524 fmt.dwMask = PFM_NOWIDOWCONTROL;
525 fmt.wEffects = PFE_NOWIDOWCONTROL;
528 fmt.dwMask = PFM_KEEPNEXT;
529 fmt.wEffects = PFE_KEEPNEXT;
532 fmt.dwMask = PFM_SPACEAFTER;
533 fmt.dySpaceAfter = info->rtfParam;
536 fmt.dwMask = PFM_SPACEBEFORE;
537 fmt.dySpaceBefore = info->rtfParam;
539 case rtfSpaceBetween:
540 fmt.dwMask = PFM_LINESPACING;
541 if ((int)info->rtfParam > 0)
543 fmt.dyLineSpacing = info->rtfParam;
544 fmt.bLineSpacingRule = 3;
548 fmt.dyLineSpacing = info->rtfParam;
549 fmt.bLineSpacingRule = 4;
551 case rtfSpaceMultiply:
552 fmt.dwMask = PFM_LINESPACING;
553 fmt.dyLineSpacing = info->rtfParam * 20;
554 fmt.bLineSpacingRule = 5;
557 fmt.dwMask = PFM_NUMBERING;
558 fmt.wNumbering = PFN_BULLET;
561 fmt.dwMask = PFM_NUMBERING;
562 fmt.wNumbering = 2; /* FIXME: MSDN says it's not used ?? */
564 case rtfParNumDecimal:
565 fmt.dwMask = PFM_NUMBERING;
566 fmt.wNumbering = 2; /* FIXME: MSDN says it's not used ?? */
568 case rtfParNumIndent:
569 fmt.dwMask = PFM_NUMBERINGTAB;
570 fmt.wNumberingTab = info->rtfParam;
572 case rtfParNumStartAt:
573 fmt.dwMask = PFM_NUMBERINGSTART;
574 fmt.wNumberingStart = info->rtfParam;
577 ME_GetSelectionParaFormat(info->editor, &fmt);
578 if (!(fmt.dwMask & PFM_BORDER))
580 fmt.dwMask |= PFM_BORDER;
581 fmt.wBorderSpace = 0;
582 fmt.wBorderWidth = 1;
588 ME_GetSelectionParaFormat(info->editor, &fmt);
589 if (!(fmt.dwMask & PFM_BORDER))
591 fmt.dwMask |= PFM_BORDER;
592 fmt.wBorderSpace = 0;
593 fmt.wBorderWidth = 1;
599 ME_GetSelectionParaFormat(info->editor, &fmt);
600 if (!(fmt.dwMask & PFM_BORDER))
602 fmt.dwMask |= PFM_BORDER;
603 fmt.wBorderSpace = 0;
604 fmt.wBorderWidth = 1;
609 case rtfBorderBottom:
610 ME_GetSelectionParaFormat(info->editor, &fmt);
611 if (!(fmt.dwMask & PFM_BORDER))
613 fmt.dwMask |= PFM_BORDER;
614 fmt.wBorderSpace = 0;
615 fmt.wBorderWidth = 1;
620 case rtfBorderSingle:
621 ME_GetSelectionParaFormat(info->editor, &fmt);
622 /* we assume that borders have been created before (RTF spec) */
623 fmt.wBorders &= ~0x700;
624 fmt.wBorders |= 1 << 8;
627 ME_GetSelectionParaFormat(info->editor, &fmt);
628 /* we assume that borders have been created before (RTF spec) */
629 fmt.wBorders &= ~0x700;
630 fmt.wBorders |= 2 << 8;
632 case rtfBorderShadow:
633 ME_GetSelectionParaFormat(info->editor, &fmt);
634 /* we assume that borders have been created before (RTF spec) */
635 fmt.wBorders &= ~0x700;
636 fmt.wBorders |= 10 << 8;
638 case rtfBorderDouble:
639 ME_GetSelectionParaFormat(info->editor, &fmt);
640 /* we assume that borders have been created before (RTF spec) */
641 fmt.wBorders &= ~0x700;
642 fmt.wBorders |= 7 << 8;
645 ME_GetSelectionParaFormat(info->editor, &fmt);
646 /* we assume that borders have been created before (RTF spec) */
647 fmt.wBorders &= ~0x700;
648 fmt.wBorders |= 11 << 8;
651 ME_GetSelectionParaFormat(info->editor, &fmt);
652 /* we assume that borders have been created before (RTF spec) */
653 fmt.wBorderWidth |= ((info->rtfParam / 15) & 7) << 8;
656 ME_GetSelectionParaFormat(info->editor, &fmt);
657 /* we assume that borders have been created before (RTF spec) */
658 fmt.wBorderSpace = info->rtfParam;
662 RTFFlushOutputBuffer(info);
663 /* FIXME too slow ? how come ?*/
664 ME_SetSelectionParaFormat(info->editor, &fmt);
668 static void ME_RTFTblAttrHook(RTF_Info *info)
670 ME_DisplayItem *para;
672 switch (info->rtfMinor)
675 RTFFlushOutputBuffer(info);
676 para = ME_GetParagraph(info->editor->pCursors[0].pRun);
678 /* Release possibly inherited cell definitions */
679 ME_DestroyTableCellList(para);
681 para->member.para.pCells = ALLOC_OBJ(ME_TableCell);
682 para->member.para.pCells->nRightBoundary = 0;
683 para->member.para.pCells->next = NULL;
684 para->member.para.pLastCell = para->member.para.pCells;
687 RTFFlushOutputBuffer(info);
688 para = ME_GetParagraph(info->editor->pCursors[0].pRun);
690 if (para->member.para.pLastCell->nRightBoundary)
692 ME_TableCell *pCell = ALLOC_OBJ(ME_TableCell);
695 para->member.para.pLastCell->next = pCell;
696 para->member.para.pLastCell = pCell;
698 para->member.para.pLastCell->nRightBoundary = info->rtfParam;
703 static BOOL ME_RTFInsertOleObject(RTF_Info *info, HENHMETAFILE hemf, HBITMAP hbmp,
706 LPOLEOBJECT lpObject = NULL;
707 LPSTORAGE lpStorage = NULL;
708 LPOLECLIENTSITE lpClientSite = NULL;
709 LPDATAOBJECT lpDataObject = NULL;
710 LPOLECACHE lpOleCache = NULL;
719 stgm.tymed = TYMED_ENHMF;
720 stgm.u.hEnhMetaFile = hemf;
721 fm.cfFormat = CF_ENHMETAFILE;
725 stgm.tymed = TYMED_GDI;
726 stgm.u.hBitmap = hbmp;
727 fm.cfFormat = CF_BITMAP;
729 stgm.pUnkForRelease = NULL;
732 fm.dwAspect = DVASPECT_CONTENT;
734 fm.tymed = stgm.tymed;
736 if (!info->lpRichEditOle)
738 CreateIRichEditOle(info->editor, (VOID**)&info->lpRichEditOle);
741 if (OleCreateDefaultHandler(&CLSID_NULL, NULL, &IID_IOleObject, (void**)&lpObject) == S_OK &&
743 /* FIXME: enable it when rich-edit properly implements this method */
744 IRichEditOle_GetClientSite(info->lpRichEditOle, &lpClientSite) == S_OK &&
745 IOleObject_SetClientSite(lpObject, lpClientSite) == S_OK &&
747 IOleObject_GetUserClassID(lpObject, &clsid) == S_OK &&
748 IOleObject_QueryInterface(lpObject, &IID_IOleCache, (void**)&lpOleCache) == S_OK &&
749 IOleCache_Cache(lpOleCache, &fm, 0, &conn) == S_OK &&
750 IOleObject_QueryInterface(lpObject, &IID_IDataObject, (void**)&lpDataObject) == S_OK &&
751 IDataObject_SetData(lpDataObject, &fm, &stgm, TRUE) == S_OK)
755 reobject.cbStruct = sizeof(reobject);
756 reobject.cp = REO_CP_SELECTION;
757 reobject.clsid = clsid;
758 reobject.poleobj = lpObject;
759 reobject.pstg = lpStorage;
760 reobject.polesite = lpClientSite;
761 /* convert from twips to .01 mm */
762 reobject.sizel.cx = MulDiv(sz->cx, 254, 144);
763 reobject.sizel.cy = MulDiv(sz->cy, 254, 144);
764 reobject.dvaspect = DVASPECT_CONTENT;
765 reobject.dwFlags = 0; /* FIXME */
768 /* FIXME: could be simpler */
769 ret = IRichEditOle_InsertObject(info->lpRichEditOle, &reobject) == S_OK;
772 if (lpObject) IOleObject_Release(lpObject);
773 if (lpClientSite) IOleClientSite_Release(lpClientSite);
774 if (lpStorage) IStorage_Release(lpStorage);
775 if (lpDataObject) IDataObject_Release(lpDataObject);
776 if (lpOleCache) IOleCache_Release(lpOleCache);
781 static void ME_RTFReadPictGroup(RTF_Info *info)
785 unsigned bufsz, bufidx;
791 enum gfxkind {gfx_unknown = 0, gfx_enhmetafile, gfx_metafile, gfx_dib} gfx = gfx_unknown;
794 if (info->rtfClass == rtfEOF)
797 /* fetch picture type */
798 if (RTFCheckMM (info, rtfPictAttr, rtfWinMetafile))
800 mfp.mm = info->rtfParam;
803 else if (RTFCheckMM (info, rtfPictAttr, rtfDevIndBitmap))
805 if (info->rtfParam != 0) FIXME("dibitmap should be 0 (%d)\n", info->rtfParam);
808 else if (RTFCheckMM (info, rtfPictAttr, rtfEmfBlip))
810 gfx = gfx_enhmetafile;
814 FIXME("%d %d\n", info->rtfMajor, info->rtfMinor);
818 /* fetch picture attributes */
822 if (info->rtfClass == rtfEOF)
824 if (info->rtfClass == rtfText)
826 if (!RTFCheckCM (info, rtfControl, rtfPictAttr))
828 ERR("Expected picture attribute (%d %d)\n",
829 info->rtfClass, info->rtfMajor);
832 else if (RTFCheckMM (info, rtfPictAttr, rtfPicWid))
834 if (gfx == gfx_metafile) mfp.xExt = info->rtfParam;
836 else if (RTFCheckMM (info, rtfPictAttr, rtfPicHt))
838 if (gfx == gfx_metafile) mfp.yExt = info->rtfParam;
840 else if (RTFCheckMM (info, rtfPictAttr, rtfPicGoalWid))
841 sz.cx = info->rtfParam;
842 else if (RTFCheckMM (info, rtfPictAttr, rtfPicGoalHt))
843 sz.cy = info->rtfParam;
845 FIXME("Non supported attribute: %d %d %d\n", info->rtfClass, info->rtfMajor, info->rtfMinor);
847 /* fetch picture data */
850 buffer = HeapAlloc(GetProcessHeap(), 0, bufsz);
851 val = info->rtfMajor;
852 for (flip = TRUE;; flip = !flip)
855 if (info->rtfClass == rtfEOF)
857 HeapFree(GetProcessHeap(), 0, buffer);
858 return; /* Warn ?? */
860 if (RTFCheckCM(info, rtfGroup, rtfEndGroup))
862 if (info->rtfClass != rtfText) goto skip_group;
865 if (bufidx >= bufsz &&
866 !(buffer = HeapReAlloc(GetProcessHeap(), 0, buffer, bufsz += 1024)))
868 buffer[bufidx++] = RTFCharToHex(val) * 16 + RTFCharToHex(info->rtfMajor);
871 val = info->rtfMajor;
873 if (flip) FIXME("wrong hex string\n");
877 case gfx_enhmetafile:
878 if ((hemf = SetEnhMetaFileBits(bufidx, buffer)))
879 ME_RTFInsertOleObject(info, hemf, NULL, &sz);
882 if ((hemf = SetWinMetaFileBits(bufidx, buffer, NULL, &mfp)))
883 ME_RTFInsertOleObject(info, hemf, NULL, &sz);
887 BITMAPINFO* bi = (BITMAPINFO*)buffer;
889 unsigned nc = bi->bmiHeader.biClrUsed;
891 /* not quite right, especially for bitfields type of compression */
892 if (!nc && bi->bmiHeader.biBitCount <= 8)
893 nc = 1 << bi->bmiHeader.biBitCount;
894 if ((hbmp = CreateDIBitmap(hdc, &bi->bmiHeader,
895 CBM_INIT, (char*)(bi + 1) + nc * sizeof(RGBQUAD),
896 bi, DIB_RGB_COLORS)))
897 ME_RTFInsertOleObject(info, NULL, hbmp, &sz);
904 HeapFree(GetProcessHeap(), 0, buffer);
905 RTFRouteToken (info); /* feed "}" back to router */
908 HeapFree(GetProcessHeap(), 0, buffer);
910 RTFRouteToken(info); /* feed "}" back to router */
913 /* for now, lookup the \result part and use it, whatever the object */
914 static void ME_RTFReadObjectGroup(RTF_Info *info)
919 if (info->rtfClass == rtfEOF)
921 if (RTFCheckCM(info, rtfGroup, rtfEndGroup))
923 if (RTFCheckCM(info, rtfGroup, rtfBeginGroup))
926 if (info->rtfClass == rtfEOF)
928 if (RTFCheckCMM(info, rtfControl, rtfDestination, rtfObjResult))
932 while (RTFGetToken (info) != rtfEOF)
934 if (info->rtfClass == rtfGroup)
936 if (info->rtfMajor == rtfBeginGroup) level++;
937 else if (info->rtfMajor == rtfEndGroup && --level < 0) break;
942 else RTFSkipGroup(info);
945 if (!RTFCheckCM (info, rtfControl, rtfObjAttr))
947 FIXME("Non supported attribute: %d %d %d\n", info->rtfClass, info->rtfMajor, info->rtfMinor);
951 RTFRouteToken(info); /* feed "}" back to router */
954 static void ME_RTFReadHook(RTF_Info *info) {
955 switch(info->rtfClass)
958 switch(info->rtfMajor)
961 if (info->stackTop < maxStack) {
962 info->stack[info->stackTop].fmt = info->style->fmt;
963 info->stack[info->stackTop].codePage = info->codePage;
964 info->stack[info->stackTop].unicodeLength = info->unicodeLength;
967 info->styleChanged = FALSE;
972 RTFFlushOutputBuffer(info);
973 if (info->stackTop<=1) {
974 info->rtfClass = rtfEOF;
978 assert(info->stackTop >= 0);
979 if (info->styleChanged)
981 /* FIXME too slow ? how come ? */
982 s = ME_ApplyStyle(info->style, &info->stack[info->stackTop].fmt);
983 ME_ReleaseStyle(info->style);
985 info->codePage = info->stack[info->stackTop].codePage;
986 info->unicodeLength = info->stack[info->stackTop].unicodeLength;
993 switch(info->rtfMajor)
996 ME_RTFCharAttrHook(info);
999 ME_RTFParAttrHook(info);
1002 ME_RTFTblAttrHook(info);
1004 case rtfSpecialChar:
1005 if (info->rtfMinor == rtfCell)
1007 RTFFlushOutputBuffer(info);
1008 ME_InsertTableCellFromCursor(info->editor, 0);
1016 ME_StreamInFill(ME_InStream *stream)
1018 stream->editstream->dwError = stream->editstream->pfnCallback(stream->editstream->dwCookie,
1019 (BYTE *)stream->buffer,
1020 sizeof(stream->buffer),
1021 (LONG *)&stream->dwSize);
1025 static LRESULT ME_StreamIn(ME_TextEditor *editor, DWORD format, EDITSTREAM *stream, BOOL stripLastCR)
1029 int from, to, to2, nUndoMode;
1030 int nEventMask = editor->nEventMask;
1031 ME_InStream inStream;
1032 BOOL invalidRTF = FALSE;
1034 TRACE("stream==%p hWnd==%p format==0x%X\n", stream, editor->hWnd, format);
1035 editor->nEventMask = 0;
1037 ME_GetSelection(editor, &from, &to);
1038 if ((format & SFF_SELECTION) && (editor->mode & TM_RICHTEXT)) {
1039 style = ME_GetSelectionInsertStyle(editor);
1041 ME_InternalDeleteText(editor, from, to-from);
1044 style = editor->pBuffer->pDefaultStyle;
1045 ME_AddRefStyle(style);
1046 SendMessageA(editor->hWnd, EM_SETSEL, 0, 0);
1047 ME_InternalDeleteText(editor, 0, ME_GetTextLength(editor));
1049 ME_ClearTempStyle(editor);
1050 /* FIXME restore default paragraph formatting ! */
1054 /* Back up undo mode to a local variable */
1055 nUndoMode = editor->nUndoMode;
1057 /* Only create an undo if SFF_SELECTION is set */
1058 if (!(format & SFF_SELECTION))
1059 editor->nUndoMode = umIgnore;
1061 inStream.editstream = stream;
1062 inStream.editstream->dwError = 0;
1063 inStream.dwSize = 0;
1064 inStream.dwUsed = 0;
1066 if (format & SF_RTF)
1068 /* Check if it's really RTF, and if it is not, use plain text */
1069 ME_StreamInFill(&inStream);
1070 if (!inStream.editstream->dwError)
1072 if ((!editor->bEmulateVersion10 && strncmp(inStream.buffer, "{\\rtf", 5) && strncmp(inStream.buffer, "{\\urtf", 6))
1073 || (editor->bEmulateVersion10 && *inStream.buffer != '{'))
1076 inStream.editstream->dwError = -16;
1081 if (!invalidRTF && !inStream.editstream->dwError)
1083 if (format & SF_RTF) {
1084 /* setup the RTF parser */
1085 memset(&parser, 0, sizeof parser);
1086 RTFSetEditStream(&parser, &inStream);
1087 parser.rtfFormat = format&(SF_TEXT|SF_RTF);
1088 parser.hwndEdit = editor->hWnd;
1089 parser.editor = editor;
1090 parser.style = style;
1091 WriterInit(&parser);
1093 RTFSetReadHook(&parser, ME_RTFReadHook);
1094 RTFSetDestinationCallback(&parser, rtfPict, ME_RTFReadPictGroup);
1095 RTFSetDestinationCallback(&parser, rtfObject, ME_RTFReadObjectGroup);
1098 /* do the parsing */
1100 RTFFlushOutputBuffer(&parser);
1101 RTFDestroy(&parser);
1102 if (parser.lpRichEditOle)
1103 IRichEditOle_Release(parser.lpRichEditOle);
1105 /* Remove last line break, as mandated by tests. This is not affected by
1106 CR/LF counters, since RTF streaming presents only \para tokens, which
1107 are converted according to the standard rules: \r for 2.0, \r\n for 1.0
1111 ME_GetSelection(editor, &newfrom, &newto);
1112 if (newto > to + (editor->bEmulateVersion10 ? 1 : 0)) {
1113 WCHAR lastchar[3] = {'\0', '\0'};
1114 int linebreakSize = editor->bEmulateVersion10 ? 2 : 1;
1116 ME_GetTextW(editor, lastchar, newto - linebreakSize, linebreakSize, 0);
1117 if (lastchar[0] == '\r' && (lastchar[1] == '\n' || lastchar[1] == '\0')) {
1118 ME_InternalDeleteText(editor, newto - linebreakSize, linebreakSize);
1123 style = parser.style;
1125 else if (format & SF_TEXT)
1126 ME_StreamInText(editor, format, &inStream, style);
1128 ERR("EM_STREAMIN without SF_TEXT or SF_RTF\n");
1129 ME_GetSelection(editor, &to, &to2);
1130 /* put the cursor at the top */
1131 if (!(format & SFF_SELECTION))
1132 SendMessageA(editor->hWnd, EM_SETSEL, 0, 0);
1135 /* Restore saved undo mode */
1136 editor->nUndoMode = nUndoMode;
1138 /* even if we didn't add an undo, we need to commit anything on the stack */
1139 ME_CommitUndo(editor);
1141 /* If SFF_SELECTION isn't set, delete any undos from before we started too */
1142 if (!(format & SFF_SELECTION))
1143 ME_EmptyUndoStack(editor);
1145 ME_ReleaseStyle(style);
1146 editor->nEventMask = nEventMask;
1147 ME_UpdateRepaint(editor);
1148 if (!(format & SFF_SELECTION)) {
1149 ME_ClearTempStyle(editor);
1151 ME_MoveCaret(editor);
1152 ME_SendSelChange(editor);
1153 ME_SendRequestResize(editor, FALSE);
1159 typedef struct tagME_RTFStringStreamStruct
1164 } ME_RTFStringStreamStruct;
1166 static DWORD CALLBACK ME_ReadFromRTFString(DWORD_PTR dwCookie, LPBYTE lpBuff, LONG cb, LONG *pcb)
1168 ME_RTFStringStreamStruct *pStruct = (ME_RTFStringStreamStruct *)dwCookie;
1171 count = min(cb, pStruct->length - pStruct->pos);
1172 memmove(lpBuff, pStruct->string + pStruct->pos, count);
1173 pStruct->pos += count;
1179 ME_StreamInRTFString(ME_TextEditor *editor, BOOL selection, char *string)
1182 ME_RTFStringStreamStruct data;
1184 data.string = string;
1185 data.length = strlen(string);
1187 es.dwCookie = (DWORD)&data;
1188 es.pfnCallback = ME_ReadFromRTFString;
1189 ME_StreamIn(editor, SF_RTF | (selection ? SFF_SELECTION : 0), &es, FALSE);
1194 ME_FindItemAtOffset(ME_TextEditor *editor, ME_DIType nItemType, int nOffset, int *nItemOffset)
1196 ME_DisplayItem *item = ME_FindItemFwd(editor->pBuffer->pFirst, diParagraph);
1199 while (item && item->member.para.next_para->member.para.nCharOfs <= nOffset)
1200 item = ME_FindItemFwd(item, diParagraph);
1205 nOffset -= item->member.para.nCharOfs;
1206 if (nItemType == diParagraph) {
1208 *nItemOffset = nOffset;
1213 item = ME_FindItemFwd(item, diRun);
1214 runLength = ME_StrLen(item->member.run.strText);
1215 if (item->member.run.nFlags & MERF_ENDPARA)
1216 runLength = item->member.run.nCR + item->member.run.nLF;
1217 } while (item && (item->member.run.nCharOfs + runLength <= nOffset));
1219 nOffset -= item->member.run.nCharOfs;
1221 /* Special case: nOffset may not point exactly at the division between the
1222 \r and the \n in 1.0 emulation. If such a case happens, it is sent
1223 into the next run, if one exists
1225 if ( item->member.run.nFlags & MERF_ENDPARA
1226 && nOffset == item->member.run.nCR
1227 && item->member.run.nLF > 0) {
1228 ME_DisplayItem *nextItem;
1229 nextItem = ME_FindItemFwd(item, diRun);
1236 *nItemOffset = nOffset;
1243 ME_FindText(ME_TextEditor *editor, DWORD flags, const CHARRANGE *chrg, const WCHAR *text, CHARRANGE *chrgText)
1245 const int nLen = lstrlenW(text);
1246 const int nTextLen = ME_GetTextLength(editor);
1249 ME_DisplayItem *item;
1250 ME_DisplayItem *para;
1251 WCHAR wLastChar = ' ';
1253 TRACE("flags==0x%08x, chrg->cpMin==%d, chrg->cpMax==%d text==%s\n",
1254 flags, chrg->cpMin, chrg->cpMax, debugstr_w(text));
1256 if (flags & ~(FR_DOWN | FR_MATCHCASE | FR_WHOLEWORD))
1257 FIXME("Flags 0x%08x not implemented\n",
1258 flags & ~(FR_DOWN | FR_MATCHCASE | FR_WHOLEWORD));
1261 if (chrg->cpMax == -1)
1264 nMax = chrg->cpMax > nTextLen ? nTextLen : chrg->cpMax;
1266 /* In 1.0 emulation, if cpMax reaches end of text, add the FR_DOWN flag */
1267 if (editor->bEmulateVersion10 && nMax == nTextLen)
1272 /* In 1.0 emulation, cpMin must always be no greater than cpMax */
1273 if (editor->bEmulateVersion10 && nMax < nMin)
1277 chrgText->cpMin = -1;
1278 chrgText->cpMax = -1;
1283 /* when searching up, if cpMin < cpMax, then instead of searching
1284 * on [cpMin,cpMax], we search on [0,cpMin], otherwise, search on
1285 * [cpMax, cpMin]. The exception is when cpMax is -1, in which
1286 * case, it is always bigger than cpMin.
1288 if (!editor->bEmulateVersion10 && !(flags & FR_DOWN))
1292 nMax = nMin > nTextLen ? nTextLen : nMin;
1293 if (nMin < nSwap || chrg->cpMax == -1)
1299 if (!nLen || nMin < 0 || nMax < 0 || nMax < nMin)
1302 chrgText->cpMin = chrgText->cpMax = -1;
1306 if (flags & FR_DOWN) /* Forward search */
1308 /* If possible, find the character before where the search starts */
1309 if ((flags & FR_WHOLEWORD) && nMin)
1312 item = ME_FindItemAtOffset(editor, diRun, nStart, &nStart);
1316 chrgText->cpMin = chrgText->cpMax = -1;
1319 wLastChar = item->member.run.strText->szData[nStart];
1323 item = ME_FindItemAtOffset(editor, diRun, nStart, &nStart);
1327 chrgText->cpMin = chrgText->cpMax = -1;
1331 para = ME_GetParagraph(item);
1333 && para->member.para.nCharOfs + item->member.run.nCharOfs + nStart + nLen <= nMax)
1335 ME_DisplayItem *pCurItem = item;
1336 int nCurStart = nStart;
1339 while (pCurItem && ME_CharCompare(pCurItem->member.run.strText->szData[nCurStart + nMatched], text[nMatched], (flags & FR_MATCHCASE)))
1341 if ((flags & FR_WHOLEWORD) && isalnumW(wLastChar))
1345 if (nMatched == nLen)
1347 ME_DisplayItem *pNextItem = pCurItem;
1348 int nNextStart = nCurStart;
1351 /* Check to see if next character is a whitespace */
1352 if (flags & FR_WHOLEWORD)
1354 if (nCurStart + nMatched == ME_StrLen(pCurItem->member.run.strText))
1356 pNextItem = ME_FindItemFwd(pCurItem, diRun);
1357 nNextStart = -nMatched;
1361 wNextChar = pNextItem->member.run.strText->szData[nNextStart + nMatched];
1365 if (isalnumW(wNextChar))
1369 nStart += para->member.para.nCharOfs + item->member.run.nCharOfs;
1372 chrgText->cpMin = nStart;
1373 chrgText->cpMax = nStart + nLen;
1375 TRACE("found at %d-%d\n", nStart, nStart + nLen);
1378 if (nCurStart + nMatched == ME_StrLen(pCurItem->member.run.strText))
1380 pCurItem = ME_FindItemFwd(pCurItem, diRun);
1381 para = ME_GetParagraph(pCurItem);
1382 nCurStart = -nMatched;
1386 wLastChar = pCurItem->member.run.strText->szData[nCurStart + nMatched];
1391 if (nStart == ME_StrLen(item->member.run.strText))
1393 item = ME_FindItemFwd(item, diRun);
1394 para = ME_GetParagraph(item);
1399 else /* Backward search */
1401 /* If possible, find the character after where the search ends */
1402 if ((flags & FR_WHOLEWORD) && nMax < nTextLen - 1)
1405 item = ME_FindItemAtOffset(editor, diRun, nEnd, &nEnd);
1409 chrgText->cpMin = chrgText->cpMax = -1;
1412 wLastChar = item->member.run.strText->szData[nEnd];
1416 item = ME_FindItemAtOffset(editor, diRun, nEnd, &nEnd);
1420 chrgText->cpMin = chrgText->cpMax = -1;
1424 para = ME_GetParagraph(item);
1427 && para->member.para.nCharOfs + item->member.run.nCharOfs + nEnd - nLen >= nMin)
1429 ME_DisplayItem *pCurItem = item;
1433 if (nCurEnd - nMatched == 0)
1435 pCurItem = ME_FindItemBack(pCurItem, diRun);
1436 para = ME_GetParagraph(pCurItem);
1437 nCurEnd = ME_StrLen(pCurItem->member.run.strText) + nMatched;
1440 while (pCurItem && ME_CharCompare(pCurItem->member.run.strText->szData[nCurEnd - nMatched - 1], text[nLen - nMatched - 1], (flags & FR_MATCHCASE)))
1442 if ((flags & FR_WHOLEWORD) && isalnumW(wLastChar))
1446 if (nMatched == nLen)
1448 ME_DisplayItem *pPrevItem = pCurItem;
1449 int nPrevEnd = nCurEnd;
1452 /* Check to see if previous character is a whitespace */
1453 if (flags & FR_WHOLEWORD)
1455 if (nPrevEnd - nMatched == 0)
1457 pPrevItem = ME_FindItemBack(pCurItem, diRun);
1459 nPrevEnd = ME_StrLen(pPrevItem->member.run.strText) + nMatched;
1463 wPrevChar = pPrevItem->member.run.strText->szData[nPrevEnd - nMatched - 1];
1467 if (isalnumW(wPrevChar))
1471 nStart = para->member.para.nCharOfs + pCurItem->member.run.nCharOfs + nCurEnd - nMatched;
1474 chrgText->cpMin = nStart;
1475 chrgText->cpMax = nStart + nLen;
1477 TRACE("found at %d-%d\n", nStart, nStart + nLen);
1480 if (nCurEnd - nMatched == 0)
1482 pCurItem = ME_FindItemBack(pCurItem, diRun);
1483 /* Don't care about pCurItem becoming NULL here; it's already taken
1484 * care of in the exterior loop condition */
1485 para = ME_GetParagraph(pCurItem);
1486 nCurEnd = ME_StrLen(pCurItem->member.run.strText) + nMatched;
1490 wLastChar = pCurItem->member.run.strText->szData[nCurEnd - nMatched - 1];
1497 item = ME_FindItemBack(item, diRun);
1498 para = ME_GetParagraph(item);
1499 nEnd = ME_StrLen(item->member.run.strText);
1503 TRACE("not found\n");
1505 chrgText->cpMin = chrgText->cpMax = -1;
1509 /* helper to send a msg filter notification */
1511 ME_FilterEvent(ME_TextEditor *editor, UINT msg, WPARAM* wParam, LPARAM* lParam)
1515 msgf.nmhdr.hwndFrom = editor->hWnd;
1516 msgf.nmhdr.idFrom = GetWindowLongW(editor->hWnd, GWLP_ID);
1517 msgf.nmhdr.code = EN_MSGFILTER;
1520 msgf.wParam = *wParam;
1521 msgf.lParam = *lParam;
1522 if (SendMessageW(GetParent(editor->hWnd), WM_NOTIFY, msgf.nmhdr.idFrom, (LPARAM)&msgf))
1524 *wParam = msgf.wParam;
1525 *lParam = msgf.lParam;
1526 msgf.wParam = *wParam;
1532 ME_KeyDown(ME_TextEditor *editor, WORD nKey)
1534 BOOL ctrl_is_down = GetKeyState(VK_CONTROL) & 0x8000;
1535 BOOL shift_is_down = GetKeyState(VK_SHIFT) & 0x8000;
1547 ME_ArrowKey(editor, nKey, shift_is_down, ctrl_is_down);
1551 /* FIXME backspace and delete aren't the same, they act different wrt paragraph style of the merged paragraph */
1552 if (GetWindowLongW(editor->hWnd, GWL_STYLE) & ES_READONLY)
1554 if (ME_IsSelection(editor))
1555 ME_DeleteSelection(editor);
1556 else if (nKey == VK_DELETE || ME_ArrowKey(editor, VK_LEFT, FALSE, FALSE))
1557 ME_DeleteTextAtCursor(editor, 1, 1);
1560 ME_CommitUndo(editor);
1561 ME_UpdateRepaint(editor);
1562 ME_SendRequestResize(editor, FALSE);
1572 chf.cbSize = sizeof(chf);
1574 ME_GetSelectionCharFormat(editor, &chf);
1575 ME_DumpStyleToBuf(&chf, buf);
1576 MessageBoxA(NULL, buf, "Style dump", MB_OK);
1580 ME_CheckCharOffsets(editor);
1587 static BOOL ME_SetCursor(ME_TextEditor *editor, int x)
1589 if ((GetWindowLongW(editor->hWnd, GWL_STYLE) & ES_SELECTIONBAR) &&
1590 (x < editor->selofs || editor->linesel))
1598 static BOOL ME_ShowContextMenu(ME_TextEditor *editor, int x, int y)
1603 if(!editor->lpOleCallback)
1605 ME_GetSelection(editor, &selrange.cpMin, &selrange.cpMax);
1606 if(selrange.cpMin == selrange.cpMax)
1607 seltype |= SEL_EMPTY;
1610 /* FIXME: Handle objects */
1611 seltype |= SEL_TEXT;
1612 if(selrange.cpMax-selrange.cpMin > 1)
1613 seltype |= SEL_MULTICHAR;
1615 if(SUCCEEDED(IRichEditOleCallback_GetContextMenu(editor->lpOleCallback, seltype, NULL, &selrange, &menu)))
1617 TrackPopupMenu(menu, TPM_LEFTALIGN | TPM_RIGHTBUTTON, x, y, 0, GetParent(editor->hWnd), NULL);
1623 ME_TextEditor *ME_MakeEditor(HWND hWnd) {
1624 ME_TextEditor *ed = ALLOC_OBJ(ME_TextEditor);
1627 ed->bEmulateVersion10 = FALSE;
1628 ed->pBuffer = ME_MakeText();
1629 ed->nZoomNumerator = ed->nZoomDenominator = 0;
1630 ME_MakeFirstParagraph(ed);
1631 ed->bCaretShown = FALSE;
1633 ed->pCursors = ALLOC_N_OBJ(ME_Cursor, ed->nCursors);
1634 ed->pCursors[0].pRun = ME_FindItemFwd(ed->pBuffer->pFirst, diRun);
1635 ed->pCursors[0].nOffset = 0;
1636 ed->pCursors[1].pRun = ME_FindItemFwd(ed->pBuffer->pFirst, diRun);
1637 ed->pCursors[1].nOffset = 0;
1638 ed->pCursors[2] = ed->pCursors[0];
1639 ed->pCursors[3] = ed->pCursors[1];
1640 ed->nLastTotalLength = ed->nTotalLength = 0;
1644 ed->rgbBackColor = -1;
1645 ed->hbrBackground = GetSysColorBrush(COLOR_WINDOW);
1646 ed->bCaretAtEnd = FALSE;
1648 ed->nModifyStep = 0;
1649 ed->nTextLimit = TEXT_LIMIT_DEFAULT;
1650 ed->pUndoStack = ed->pRedoStack = ed->pUndoStackBottom = NULL;
1651 ed->nUndoStackSize = 0;
1652 ed->nUndoLimit = STACK_SIZE_DEFAULT;
1653 ed->nUndoMode = umAddToUndo;
1654 ed->nParagraphs = 1;
1655 ed->nLastSelStart = ed->nLastSelEnd = 0;
1656 ed->pLastSelStartPara = ed->pLastSelEndPara = ME_FindItemFwd(ed->pBuffer->pFirst, diParagraph);
1658 ed->bWordWrap = (GetWindowLongW(hWnd, GWL_STYLE) & WS_HSCROLL) ? FALSE : TRUE;
1659 ed->bHideSelection = FALSE;
1660 ed->nInvalidOfs = -1;
1661 ed->pfnWordBreak = NULL;
1662 ed->lpOleCallback = NULL;
1663 ed->mode = TM_RICHTEXT | TM_MULTILEVELUNDO | TM_MULTICODEPAGE;
1664 ed->AutoURLDetect_bEnable = FALSE;
1665 ed->bHaveFocus = FALSE;
1666 GetClientRect(hWnd, &ed->rcFormat);
1667 for (i=0; i<HFONT_CACHE_SIZE; i++)
1669 ed->pFontCache[i].nRefs = 0;
1670 ed->pFontCache[i].nAge = 0;
1671 ed->pFontCache[i].hFont = NULL;
1674 ME_CheckCharOffsets(ed);
1675 if (GetWindowLongW(hWnd, GWL_STYLE) & ES_SELECTIONBAR)
1681 if (GetWindowLongW(hWnd, GWL_STYLE) & ES_PASSWORD)
1682 ed->cPasswordMask = '*';
1684 ed->cPasswordMask = 0;
1686 ed->notified_cr.cpMin = ed->notified_cr.cpMax = 0;
1691 typedef struct tagME_GlobalDestStruct
1695 } ME_GlobalDestStruct;
1697 static DWORD CALLBACK ME_ReadFromHGLOBALUnicode(DWORD_PTR dwCookie, LPBYTE lpBuff, LONG cb, LONG *pcb)
1699 ME_GlobalDestStruct *pData = (ME_GlobalDestStruct *)dwCookie;
1704 pDest = (WORD *)lpBuff;
1705 pSrc = (WORD *)GlobalLock(pData->hData);
1706 for (i = 0; i<cb && pSrc[pData->nLength+i]; i++) {
1707 pDest[i] = pSrc[pData->nLength+i];
1709 pData->nLength += i;
1711 GlobalUnlock(pData->hData);
1715 static DWORD CALLBACK ME_ReadFromHGLOBALRTF(DWORD_PTR dwCookie, LPBYTE lpBuff, LONG cb, LONG *pcb)
1717 ME_GlobalDestStruct *pData = (ME_GlobalDestStruct *)dwCookie;
1722 pSrc = (BYTE *)GlobalLock(pData->hData);
1723 for (i = 0; i<cb && pSrc[pData->nLength+i]; i++) {
1724 pDest[i] = pSrc[pData->nLength+i];
1726 pData->nLength += i;
1728 GlobalUnlock(pData->hData);
1733 void ME_DestroyEditor(ME_TextEditor *editor)
1735 ME_DisplayItem *pFirst = editor->pBuffer->pFirst;
1736 ME_DisplayItem *p = pFirst, *pNext = NULL;
1739 ME_ClearTempStyle(editor);
1740 ME_EmptyUndoStack(editor);
1743 ME_DestroyDisplayItem(p);
1746 ME_ReleaseStyle(editor->pBuffer->pDefaultStyle);
1747 for (i=0; i<HFONT_CACHE_SIZE; i++)
1749 if (editor->pFontCache[i].hFont)
1750 DeleteObject(editor->pFontCache[i].hFont);
1752 if (editor->rgbBackColor != -1)
1753 DeleteObject(editor->hbrBackground);
1754 if(editor->lpOleCallback)
1755 IUnknown_Release(editor->lpOleCallback);
1757 FREE_OBJ(editor->pBuffer);
1758 FREE_OBJ(editor->pCursors);
1763 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
1768 case DLL_PROCESS_ATTACH:
1769 DisableThreadLibraryCalls(hinstDLL);
1770 me_heap = HeapCreate (0, 0x10000, 0);
1771 if (!ME_RegisterEditorClass(hinstDLL)) return FALSE;
1772 hLeft = LoadCursorW(hinstDLL, MAKEINTRESOURCEW(OCR_REVERSE));
1776 case DLL_PROCESS_DETACH:
1777 UnregisterClassW(RichEdit20W, 0);
1778 UnregisterClassW(RichEdit50W, 0);
1779 UnregisterClassA("RichEdit20A", 0);
1780 UnregisterClassA("RichEdit50A", 0);
1781 if (ME_ListBoxRegistered)
1782 UnregisterClassW(REListBox20W, 0);
1783 if (ME_ComboBoxRegistered)
1784 UnregisterClassW(REComboBox20W, 0);
1786 HeapDestroy (me_heap);
1794 #define UNSUPPORTED_MSG(e) \
1796 FIXME(#e ": stub\n"); \
1797 return DefWindowProcW(hWnd, msg, wParam, lParam);
1799 static const char * const edit_messages[] = {
1828 "EM_SETPASSWORDCHAR",
1829 "EM_EMPTYUNDOBUFFER",
1830 "EM_GETFIRSTVISIBLELINE",
1832 "EM_SETWORDBREAKPROC",
1833 "EM_GETWORDBREAKPROC",
1834 "EM_GETPASSWORDCHAR",
1842 static const char * const richedit_messages[] = {
1847 "EM_EXLINEFROMCHAR",
1853 "EM_GETOLEINTERFACE",
1863 "EM_SETOLECALLBACK",
1865 "EM_SETTARGETDEVICE",
1873 "EM_GETWORDBREAKPROCEX",
1874 "EM_SETWORDBREAKPROCEX",
1876 "EM_UNKNOWN_USER_83",
1881 "EM_STOPGROUPTYPING",
1885 "EM_GETAUTOURLDETECT",
1888 "EM_GETTEXTLENGTHEX",
1891 "EM_UNKNOWN_USER_98",
1892 "EM_UNKNOWN_USER_99",
1893 "EM_SETPUNCTUATION",
1894 "EM_GETPUNCTUATION",
1895 "EM_SETWORDWRAPMODE",
1896 "EM_GETWORDWRAPMODE",
1902 "EM_UNKNOWN_USER_109",
1903 "EM_UNKNOWN_USER_110",
1904 "EM_UNKNOWN_USER_111",
1905 "EM_UNKNOWN_USER_112",
1906 "EM_UNKNOWN_USER_113",
1907 "EM_UNKNOWN_USER_114",
1908 "EM_UNKNOWN_USER_115",
1909 "EM_UNKNOWN_USER_116",
1910 "EM_UNKNOWN_USER_117",
1911 "EM_UNKNOWN_USER_118",
1912 "EM_UNKNOWN_USER_119",
1913 "EM_SETLANGOPTIONS",
1914 "EM_GETLANGOPTIONS",
1915 "EM_GETIMECOMPMODE",
1919 "EM_SETIMEMODEBIAS",
1924 get_msg_name(UINT msg)
1926 if (msg >= EM_GETSEL && msg <= EM_CHARFROMPOS)
1927 return edit_messages[msg - EM_GETSEL];
1928 if (msg >= EM_CANPASTE && msg <= EM_GETIMEMODEBIAS)
1929 return richedit_messages[msg - EM_CANPASTE];
1933 static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam,
1934 LPARAM lParam, BOOL unicode)
1936 ME_TextEditor *editor = (ME_TextEditor *)GetWindowLongPtrW(hWnd, 0);
1938 TRACE("hwnd %p msg %04x (%s) %lx %lx, unicode %d\n",
1939 hWnd, msg, get_msg_name(msg), wParam, lParam, unicode);
1941 if (!editor && msg != WM_NCCREATE && msg != WM_NCDESTROY) {
1942 ERR("called with invalid hWnd %p - application bug?\n", hWnd);
1948 UNSUPPORTED_MSG(EM_DISPLAYBAND)
1949 UNSUPPORTED_MSG(EM_FINDWORDBREAK)
1950 UNSUPPORTED_MSG(EM_FMTLINES)
1951 UNSUPPORTED_MSG(EM_FORMATRANGE)
1952 UNSUPPORTED_MSG(EM_GETBIDIOPTIONS)
1953 UNSUPPORTED_MSG(EM_GETEDITSTYLE)
1954 UNSUPPORTED_MSG(EM_GETIMECOMPMODE)
1955 /* UNSUPPORTED_MSG(EM_GETIMESTATUS) missing in Wine headers */
1956 UNSUPPORTED_MSG(EM_GETLANGOPTIONS)
1957 /* UNSUPPORTED_MSG(EM_GETOLEINTERFACE) separate stub */
1958 UNSUPPORTED_MSG(EM_GETREDONAME)
1959 UNSUPPORTED_MSG(EM_GETTEXTMODE)
1960 UNSUPPORTED_MSG(EM_GETTYPOGRAPHYOPTIONS)
1961 UNSUPPORTED_MSG(EM_GETUNDONAME)
1962 UNSUPPORTED_MSG(EM_GETWORDBREAKPROCEX)
1963 UNSUPPORTED_MSG(EM_PASTESPECIAL)
1964 UNSUPPORTED_MSG(EM_SELECTIONTYPE)
1965 UNSUPPORTED_MSG(EM_SETBIDIOPTIONS)
1966 UNSUPPORTED_MSG(EM_SETEDITSTYLE)
1967 UNSUPPORTED_MSG(EM_SETFONTSIZE)
1968 UNSUPPORTED_MSG(EM_SETLANGOPTIONS)
1969 UNSUPPORTED_MSG(EM_SETPALETTE)
1970 UNSUPPORTED_MSG(EM_SETTABSTOPS)
1971 UNSUPPORTED_MSG(EM_SETTYPOGRAPHYOPTIONS)
1972 UNSUPPORTED_MSG(EM_SETWORDBREAKPROCEX)
1973 UNSUPPORTED_MSG(WM_STYLECHANGING)
1974 UNSUPPORTED_MSG(WM_STYLECHANGED)
1975 /* UNSUPPORTED_MSG(WM_UNICHAR) FIXME missing in Wine headers */
1977 /* Messages specific to Richedit controls */
1980 return ME_StreamIn(editor, wParam, (EDITSTREAM*)lParam, TRUE);
1982 return ME_StreamOut(editor, wParam, (EDITSTREAM *)lParam);
1985 UINT code = DLGC_WANTCHARS|DLGC_WANTARROWS;
1986 if(lParam && (((LPMSG)lParam)->message == WM_KEYDOWN))
1988 int vk = (int)((LPMSG)lParam)->wParam;
1989 /* if style says we want return key */
1990 if((vk == VK_RETURN) && (GetWindowLongW(hWnd, GWL_STYLE) & ES_WANTRETURN))
1992 code |= DLGC_WANTMESSAGE;
1994 /* we always handle ctrl-tab */
1995 if((vk == VK_TAB) && (GetKeyState(VK_CONTROL) & 0x8000))
1997 code |= DLGC_WANTMESSAGE;
2004 CREATESTRUCTW *pcs = (CREATESTRUCTW *)lParam;
2005 TRACE("WM_NCCREATE: style 0x%08x\n", pcs->style);
2006 editor = ME_MakeEditor(hWnd);
2007 SetWindowLongPtrW(hWnd, 0, (LONG_PTR)editor);
2010 case EM_EMPTYUNDOBUFFER:
2011 ME_EmptyUndoStack(editor);
2015 /* Note: wParam/lParam can be NULL */
2017 PUINT pfrom = wParam ? (PUINT)wParam : &from;
2018 PUINT pto = lParam ? (PUINT)lParam : &to;
2019 ME_GetSelection(editor, (int *)pfrom, (int *)pto);
2020 if ((*pfrom|*pto) & 0xFFFF0000)
2022 return MAKELONG(*pfrom,*pto);
2026 CHARRANGE *pRange = (CHARRANGE *)lParam;
2027 ME_GetSelection(editor, &pRange->cpMin, &pRange->cpMax);
2028 TRACE("EM_EXGETSEL = (%d,%d)\n", pRange->cpMin, pRange->cpMax);
2031 case EM_SETUNDOLIMIT:
2033 if ((int)wParam < 0)
2034 editor->nUndoLimit = STACK_SIZE_DEFAULT;
2036 editor->nUndoLimit = min(wParam, STACK_SIZE_MAX);
2037 /* Setting a max stack size keeps wine from getting killed
2038 for hogging memory. Windows allocates all this memory at once, so
2039 no program would realistically set a value above our maximum. */
2040 return editor->nUndoLimit;
2043 return editor->pUndoStack != NULL;
2045 return editor->pRedoStack != NULL;
2046 case WM_UNDO: /* FIXME: actually not the same */
2055 /* these flags are equivalent to the ES_* counterparts */
2056 DWORD mask = ECO_VERTICAL | ECO_AUTOHSCROLL | ECO_AUTOVSCROLL |
2057 ECO_NOHIDESEL | ECO_READONLY | ECO_WANTRETURN;
2058 DWORD settings = GetWindowLongW(hWnd, GWL_STYLE) & mask;
2064 /* these flags are equivalent to ES_* counterparts
2065 * ECO_READONLY is already implemented in the code, only requires
2066 * setting the bit to work
2068 DWORD mask = ECO_VERTICAL | ECO_AUTOHSCROLL | ECO_AUTOVSCROLL |
2069 ECO_NOHIDESEL | ECO_READONLY | ECO_WANTRETURN | ECO_SELECTIONBAR;
2070 DWORD raw = GetWindowLongW(hWnd, GWL_STYLE);
2071 DWORD settings = mask & raw;
2087 SetWindowLongW(hWnd, GWL_STYLE, (raw & ~mask) | (settings & mask));
2089 if (settings & ECO_AUTOWORDSELECTION)
2090 FIXME("ECO_AUTOWORDSELECTION not implemented yet!\n");
2091 if (settings & ECO_SELECTIONBAR)
2092 editor->selofs = 16;
2095 ME_WrapMarkedParagraphs(editor);
2097 if (settings & ECO_VERTICAL)
2098 FIXME("ECO_VERTICAL not implemented yet!\n");
2099 if (settings & ECO_AUTOHSCROLL)
2100 FIXME("ECO_AUTOHSCROLL not implemented yet!\n");
2101 if (settings & ECO_AUTOVSCROLL)
2102 FIXME("ECO_AUTOVSCROLL not implemented yet!\n");
2103 if (settings & ECO_NOHIDESEL)
2104 FIXME("ECO_NOHIDESEL not implemented yet!\n");
2105 if (settings & ECO_WANTRETURN)
2106 FIXME("ECO_WANTRETURN not implemented yet!\n");
2112 ME_InvalidateSelection(editor);
2113 ME_SetSelection(editor, wParam, lParam);
2114 ME_InvalidateSelection(editor);
2115 ME_SendSelChange(editor);
2118 case EM_SETSCROLLPOS:
2120 POINT *point = (POINT *)lParam;
2121 ME_ScrollAbs(editor, point->y);
2124 case EM_AUTOURLDETECT:
2126 if (wParam==1 || wParam ==0)
2128 editor->AutoURLDetect_bEnable = (BOOL)wParam;
2131 return E_INVALIDARG;
2133 case EM_GETAUTOURLDETECT:
2135 return editor->AutoURLDetect_bEnable;
2140 CHARRANGE range = *(CHARRANGE *)lParam;
2142 TRACE("EM_EXSETSEL (%d,%d)\n", range.cpMin, range.cpMax);
2144 ME_InvalidateSelection(editor);
2145 end = ME_SetSelection(editor, range.cpMin, range.cpMax);
2146 ME_InvalidateSelection(editor);
2147 ME_SendSelChange(editor);
2151 case EM_SHOWSCROLLBAR:
2153 ShowScrollBar(editor->hWnd, wParam, lParam);
2159 SETTEXTEX *pStruct = (SETTEXTEX *)wParam;
2163 int oldModify = editor->nModifyStep;
2165 if (!pStruct) return 0;
2167 TRACE("EM_SETTEXTEX - %s, flags %d, cp %d\n",
2168 pStruct->codepage == 1200 ? debugstr_w((LPCWSTR)lParam) : debugstr_a((LPCSTR)lParam),
2169 pStruct->flags, pStruct->codepage);
2171 /* FIXME: make use of pStruct->codepage in the to unicode translation */
2172 wszText = lParam ? ME_ToUnicode(pStruct->codepage == 1200, (void *)lParam) : NULL;
2173 len = wszText ? lstrlenW(wszText) : 0;
2175 if (pStruct->flags & ST_SELECTION) {
2176 ME_GetSelection(editor, &from, &to);
2177 style = ME_GetSelectionInsertStyle(editor);
2178 ME_InternalDeleteText(editor, from, to - from);
2179 if (pStruct->codepage != 1200 && lParam && !strncmp((char *)lParam, "{\\rtf", 5))
2180 ME_StreamInRTFString(editor, 0, (char *)lParam);
2181 else ME_InsertTextFromCursor(editor, 0, wszText, len, style);
2182 ME_ReleaseStyle(style);
2185 ME_InternalDeleteText(editor, 0, ME_GetTextLength(editor));
2186 if (pStruct->codepage != 1200 && lParam && !strncmp((char *)lParam, "{\\rtf", 5))
2187 ME_StreamInRTFString(editor, 0, (char *)lParam);
2188 else ME_InsertTextFromCursor(editor, 0, wszText, len, editor->pBuffer->pDefaultStyle);
2191 ME_CommitUndo(editor);
2192 if (!(pStruct->flags & ST_KEEPUNDO))
2194 editor->nModifyStep = oldModify;
2195 ME_EmptyUndoStack(editor);
2197 ME_UpdateRepaint(editor);
2200 case EM_SETBKGNDCOLOR:
2203 if (editor->rgbBackColor != -1) {
2204 DeleteObject(editor->hbrBackground);
2205 lColor = editor->rgbBackColor;
2207 else lColor = GetSysColor(COLOR_WINDOW);
2211 editor->rgbBackColor = -1;
2212 editor->hbrBackground = GetSysColorBrush(COLOR_WINDOW);
2216 editor->rgbBackColor = lParam;
2217 editor->hbrBackground = CreateSolidBrush(editor->rgbBackColor);
2219 if (editor->bRedraw)
2221 InvalidateRect(hWnd, NULL, TRUE);
2227 return editor->nModifyStep == 0 ? 0 : -1;
2231 editor->nModifyStep = 1;
2233 editor->nModifyStep = 0;
2237 case EM_SETREADONLY:
2239 long nStyle = GetWindowLongW(hWnd, GWL_STYLE);
2241 nStyle |= ES_READONLY;
2243 nStyle &= ~ES_READONLY;
2244 SetWindowLongW(hWnd, GWL_STYLE, nStyle);
2247 case EM_SETEVENTMASK:
2249 DWORD nOldMask = editor->nEventMask;
2251 editor->nEventMask = lParam;
2254 case EM_GETEVENTMASK:
2255 return editor->nEventMask;
2256 case EM_SETCHARFORMAT:
2258 CHARFORMAT2W buf, *p;
2259 BOOL bRepaint = TRUE;
2260 p = ME_ToCF2W(&buf, (CHARFORMAT2W *)lParam);
2261 if (p == NULL) return 0;
2263 ME_SetDefaultCharFormat(editor, p);
2264 else if (wParam == (SCF_WORD | SCF_SELECTION)) {
2265 FIXME("EM_SETCHARFORMAT: word selection not supported\n");
2267 } else if (wParam == SCF_ALL) {
2268 if (editor->mode & TM_PLAINTEXT)
2269 ME_SetDefaultCharFormat(editor, p);
2271 ME_SetCharFormat(editor, 0, ME_GetTextLength(editor), p);
2272 editor->nModifyStep = 1;
2274 } else if (editor->mode & TM_PLAINTEXT) {
2278 ME_GetSelection(editor, &from, &to);
2279 bRepaint = (from != to);
2280 ME_SetSelectionCharFormat(editor, p);
2281 if (from != to) editor->nModifyStep = 1;
2283 ME_CommitUndo(editor);
2285 ME_RewrapRepaint(editor);
2288 case EM_GETCHARFORMAT:
2290 CHARFORMAT2W tmp, *dst = (CHARFORMAT2W *)lParam;
2291 if (dst->cbSize != sizeof(CHARFORMATA) &&
2292 dst->cbSize != sizeof(CHARFORMATW) &&
2293 dst->cbSize != sizeof(CHARFORMAT2A) &&
2294 dst->cbSize != sizeof(CHARFORMAT2W))
2296 tmp.cbSize = sizeof(tmp);
2298 ME_GetDefaultCharFormat(editor, &tmp);
2300 ME_GetSelectionCharFormat(editor, &tmp);
2301 ME_CopyToCFAny(dst, &tmp);
2304 case EM_SETPARAFORMAT:
2305 ME_SetSelectionParaFormat(editor, (PARAFORMAT2 *)lParam);
2306 ME_RewrapRepaint(editor);
2307 ME_CommitUndo(editor);
2309 case EM_GETPARAFORMAT:
2310 ME_GetSelectionParaFormat(editor, (PARAFORMAT2 *)lParam);
2312 case EM_GETFIRSTVISIBLELINE:
2314 ME_DisplayItem *p = editor->pBuffer->pFirst;
2315 int y = ME_GetYScrollPos(editor);
2320 p = ME_FindItemFwd(p, diStartRowOrParagraphOrEnd);
2321 if (p->type == diTextEnd)
2323 if (p->type == diParagraph) {
2324 ypara = p->member.para.nYPos;
2327 ystart = ypara + p->member.row.nYPos;
2328 yend = ystart + p->member.row.nHeight;
2336 case EM_HIDESELECTION:
2338 editor->bHideSelection = (wParam != 0);
2339 ME_InvalidateSelection(editor);
2344 ME_ScrollDown(editor, lParam * 8); /* FIXME follow the original */
2345 return TRUE; /* Should return false if a single line richedit control */
2350 ME_GetSelection(editor, &from, &to);
2351 ME_InternalDeleteText(editor, from, to-from);
2352 ME_CommitUndo(editor);
2353 ME_UpdateRepaint(editor);
2360 LPWSTR wszText = lParam ? ME_ToUnicode(unicode, (void *)lParam) : NULL;
2361 size_t len = wszText ? lstrlenW(wszText) : 0;
2362 TRACE("EM_REPLACESEL - %s\n", debugstr_w(wszText));
2364 ME_GetSelection(editor, &from, &to);
2365 style = ME_GetSelectionInsertStyle(editor);
2366 ME_InternalDeleteText(editor, from, to-from);
2367 ME_InsertTextFromCursor(editor, 0, wszText, len, style);
2368 ME_ReleaseStyle(style);
2369 /* drop temporary style if line end */
2371 * FIXME question: does abc\n mean: put abc,
2372 * clear temp style, put \n? (would require a change)
2374 if (len>0 && wszText[len-1] == '\n')
2375 ME_ClearTempStyle(editor);
2376 ME_EndToUnicode(unicode, wszText);
2377 ME_CommitUndo(editor);
2379 ME_EmptyUndoStack(editor);
2380 ME_UpdateRepaint(editor);
2383 case EM_SCROLLCARET:
2385 int top, bottom; /* row's edges relative to document top */
2387 ME_DisplayItem *para, *row;
2389 nPos = ME_GetYScrollPos(editor);
2390 row = ME_RowStart(editor->pCursors[0].pRun);
2391 para = ME_GetParagraph(row);
2392 top = para->member.para.nYPos + row->member.row.nYPos;
2393 bottom = top + row->member.row.nHeight;
2395 if (top < nPos) /* caret above window */
2396 ME_ScrollAbs(editor, top);
2397 else if (nPos + editor->sizeWindow.cy < bottom) /*below*/
2398 ME_ScrollAbs(editor, bottom - editor->sizeWindow.cy);
2406 BOOL bRepaint = LOWORD(lParam);
2409 wParam = (WPARAM)GetStockObject(SYSTEM_FONT);
2410 GetObjectW((HGDIOBJ)wParam, sizeof(LOGFONTW), &lf);
2412 ME_CharFormatFromLogFont(hDC, &lf, &fmt);
2413 ReleaseDC(hWnd, hDC);
2414 ME_SetCharFormat(editor, 0, ME_GetTextLength(editor), &fmt);
2415 ME_SetDefaultCharFormat(editor, &fmt);
2417 ME_CommitUndo(editor);
2419 ME_RewrapRepaint(editor);
2424 ME_InternalDeleteText(editor, 0, ME_GetTextLength(editor));
2427 TRACE("WM_SETTEXT lParam==%lx\n",lParam);
2428 if (!unicode && !strncmp((char *)lParam, "{\\rtf", 5))
2430 /* Undocumented: WM_SETTEXT supports RTF text */
2431 ME_StreamInRTFString(editor, 0, (char *)lParam);
2435 LPWSTR wszText = ME_ToUnicode(unicode, (void *)lParam);
2436 TRACE("WM_SETTEXT - %s\n", debugstr_w(wszText)); /* debugstr_w() */
2437 if (lstrlenW(wszText) > 0)
2441 /* uses default style! */
2442 if (!(GetWindowLongW(hWnd, GWL_STYLE) & ES_MULTILINE))
2447 while (*p != '\0' && *p != '\r' && *p != '\n') p++;
2450 ME_InsertTextFromCursor(editor, 0, wszText, len, editor->pBuffer->pDefaultStyle);
2452 ME_EndToUnicode(unicode, wszText);
2456 TRACE("WM_SETTEXT - NULL\n");
2457 if (editor->AutoURLDetect_bEnable)
2459 int cMin = 0, cMax = -1;
2460 while (ME_FindNextURLCandidate(editor, cMin, cMax, &cMin, &cMax))
2462 if (ME_IsCandidateAnURL(editor, cMin, cMax)) {
2464 link.cbSize = sizeof(link);
2465 link.dwMask = CFM_LINK;
2466 link.dwEffects = CFE_LINK;
2467 ME_SetCharFormat(editor, cMin, cMax - cMin, &link);
2473 ME_SetSelection(editor, 0, 0);
2474 editor->nModifyStep = 0;
2475 ME_CommitUndo(editor);
2476 ME_EmptyUndoStack(editor);
2477 ME_UpdateRepaint(editor);
2482 UINT nRTFFormat = RegisterClipboardFormatA("Rich Text Format");
2483 if (IsClipboardFormatAvailable(nRTFFormat))
2485 if (IsClipboardFormatAvailable(CF_UNICODETEXT))
2493 ME_GlobalDestStruct gds;
2494 UINT nRTFFormat = RegisterClipboardFormatA("Rich Text Format");
2497 if (IsClipboardFormatAvailable(nRTFFormat))
2498 cf = nRTFFormat, dwFormat = SF_RTF;
2499 else if (IsClipboardFormatAvailable(CF_UNICODETEXT))
2500 cf = CF_UNICODETEXT, dwFormat = SF_TEXT|SF_UNICODE;
2504 if (!OpenClipboard(hWnd))
2506 gds.hData = GetClipboardData(cf);
2508 es.dwCookie = (DWORD)&gds;
2509 es.pfnCallback = dwFormat == SF_RTF ? ME_ReadFromHGLOBALRTF : ME_ReadFromHGLOBALUnicode;
2510 ME_StreamIn(editor, dwFormat|SFF_SELECTION, &es, FALSE);
2518 LPDATAOBJECT dataObj = NULL;
2522 if (editor->cPasswordMask)
2523 return 0; /* Copying or Cutting masked text isn't allowed */
2525 ME_GetSelection(editor, &range.cpMin, &range.cpMax);
2526 if(editor->lpOleCallback)
2527 hr = IRichEditOleCallback_GetClipboardData(editor->lpOleCallback, &range, RECO_COPY, &dataObj);
2528 if(FAILED(hr) || !dataObj)
2529 hr = ME_GetDataObject(editor, &range, &dataObj);
2531 hr = OleSetClipboard(dataObj);
2532 IDataObject_Release(dataObj);
2534 if (SUCCEEDED(hr) && msg == WM_CUT)
2536 ME_InternalDeleteText(editor, range.cpMin, range.cpMax-range.cpMin);
2537 ME_CommitUndo(editor);
2538 ME_UpdateRepaint(editor);
2542 case WM_GETTEXTLENGTH:
2544 GETTEXTLENGTHEX how;
2546 /* CR/LF conversion required in 2.0 mode, verbatim in 1.0 mode */
2547 how.flags = GTL_CLOSE | (editor->bEmulateVersion10 ? 0 : GTL_USECRLF) | GTL_NUMCHARS;
2548 how.codepage = unicode ? 1200 : CP_ACP;
2549 return ME_GetTextLengthEx(editor, &how);
2551 case EM_GETTEXTLENGTHEX:
2552 return ME_GetTextLengthEx(editor, (GETTEXTLENGTHEX *)wParam);
2557 LPSTR bufferA = NULL;
2558 LPWSTR bufferW = NULL;
2561 bufferW = heap_alloc((wParam + 2) * sizeof(WCHAR));
2563 bufferA = heap_alloc(wParam + 2);
2565 ex.cb = (wParam + 2) * (unicode ? sizeof(WCHAR) : sizeof(CHAR));
2566 ex.flags = GT_USECRLF;
2567 ex.codepage = unicode ? 1200 : CP_ACP;
2568 ex.lpDefaultChar = NULL;
2569 ex.lpUsedDefChar = NULL;
2570 rc = RichEditWndProc_common(hWnd, EM_GETTEXTEX, (WPARAM)&ex, unicode ? (LPARAM)bufferW : (LPARAM)bufferA, unicode);
2574 memcpy((LPWSTR)lParam, bufferW, wParam * sizeof(WCHAR));
2575 if (lstrlenW(bufferW) >= wParam) rc = 0;
2579 memcpy((LPSTR)lParam, bufferA, wParam);
2580 if (strlen(bufferA) >= wParam) rc = 0;
2588 GETTEXTEX *ex = (GETTEXTEX*)wParam;
2589 int nStart, nCount; /* in chars */
2591 if (ex->flags & ~(GT_SELECTION | GT_USECRLF))
2592 FIXME("GETTEXTEX flags 0x%08x not supported\n", ex->flags & ~(GT_SELECTION | GT_USECRLF));
2594 if (ex->flags & GT_SELECTION)
2596 ME_GetSelection(editor, &nStart, &nCount);
2602 nCount = 0x7fffffff;
2604 if (ex->codepage == 1200)
2606 nCount = min(nCount, ex->cb / sizeof(WCHAR) - 1);
2607 return ME_GetTextW(editor, (LPWSTR)lParam, nStart, nCount, ex->flags & GT_USECRLF);
2611 /* potentially each char may be a CR, why calculate the exact value with O(N) when
2612 we can just take a bigger buffer? :)
2613 The above assumption still holds with CR/LF counters, since CR->CRLF expansion
2614 occurs only in richedit 2.0 mode, in which line breaks have only one CR
2616 int crlfmul = (ex->flags & GT_USECRLF) ? 2 : 1;
2618 DWORD buflen = ex->cb;
2622 nCount = min(nCount, ex->cb - 1);
2623 buffer = heap_alloc((crlfmul*nCount + 1) * sizeof(WCHAR));
2625 buflen = ME_GetTextW(editor, buffer, nStart, nCount, ex->flags & GT_USECRLF);
2626 rc = WideCharToMultiByte(ex->codepage, flags, buffer, -1, (LPSTR)lParam, ex->cb, ex->lpDefaultChar, ex->lpUsedDefChar);
2627 if (rc) rc--; /* do not count 0 terminator */
2636 TEXTRANGEW tr; /* W and A differ only by rng->lpstrText */
2637 ME_GetSelection(editor, &from, &to);
2638 tr.chrg.cpMin = from;
2640 tr.lpstrText = (WCHAR *)lParam;
2641 return RichEditWndProc_common(hWnd, EM_GETTEXTRANGE, 0, (LPARAM)&tr, unicode);
2643 case EM_GETSCROLLPOS:
2645 POINT *point = (POINT *)lParam;
2646 point->x = 0; /* FIXME side scrolling not implemented */
2647 point->y = ME_GetYScrollPos(editor);
2650 case EM_GETTEXTRANGE:
2652 TEXTRANGEW *rng = (TEXTRANGEW *)lParam;
2653 TRACE("EM_GETTEXTRANGE min=%d max=%d unicode=%d emul1.0=%d length=%d\n",
2654 rng->chrg.cpMin, rng->chrg.cpMax, unicode,
2655 editor->bEmulateVersion10, ME_GetTextLength(editor));
2657 return ME_GetTextW(editor, rng->lpstrText, rng->chrg.cpMin, rng->chrg.cpMax-rng->chrg.cpMin, 0);
2660 int nLen = rng->chrg.cpMax-rng->chrg.cpMin;
2661 WCHAR *p = ALLOC_N_OBJ(WCHAR, nLen+1);
2662 int nChars = ME_GetTextW(editor, p, rng->chrg.cpMin, nLen, 0);
2663 /* FIXME this is a potential security hole (buffer overrun)
2664 if you know more about wchar->mbyte conversion please explain
2666 WideCharToMultiByte(CP_ACP, 0, p, nChars+1, (char *)rng->lpstrText, nLen+1, NULL, NULL);
2673 ME_DisplayItem *run;
2674 const unsigned int nMaxChars = *(WORD *) lParam;
2675 unsigned int nCharsLeft = nMaxChars;
2676 char *dest = (char *) lParam;
2677 BOOL wroteNull = FALSE;
2679 TRACE("EM_GETLINE: row=%d, nMaxChars=%d (%s)\n", (int) wParam, nMaxChars,
2680 unicode ? "Unicode" : "Ansi");
2682 run = ME_FindRowWithNumber(editor, wParam);
2686 while (nCharsLeft && (run = ME_FindItemFwd(run, diRunOrStartRow))
2687 && !(run->member.run.nFlags & MERF_ENDPARA))
2691 if (run->type != diRun)
2693 strText = run->member.run.strText;
2694 nCopy = min(nCharsLeft, strText->nLen);
2697 lstrcpynW((LPWSTR) dest, strText->szData, nCopy);
2699 nCopy = WideCharToMultiByte(CP_ACP, 0, strText->szData, nCopy, dest,
2700 nCharsLeft, NULL, NULL);
2701 dest += nCopy * (unicode ? sizeof(WCHAR) : 1);
2702 nCharsLeft -= nCopy;
2705 /* append line termination, space allowing */
2708 if (run && (run->member.run.nFlags & MERF_ENDPARA))
2711 /* Write as many \r as encoded in end-of-paragraph, space allowing */
2712 for (i = 0; i < run->member.run.nCR && nCharsLeft > 0; i++, nCharsLeft--)
2714 *((WCHAR *)dest) = '\r';
2715 dest += unicode ? sizeof(WCHAR) : 1;
2717 /* Write as many \n as encoded in end-of-paragraph, space allowing */
2718 for (i = 0; i < run->member.run.nLF && nCharsLeft > 0; i++, nCharsLeft--)
2720 *((WCHAR *)dest) = '\n';
2721 dest += unicode ? sizeof(WCHAR) : 1;
2727 *((WCHAR *)dest) = '\0';
2735 TRACE("EM_GETLINE: got %u characters\n", nMaxChars - nCharsLeft);
2736 return nMaxChars - nCharsLeft - (wroteNull ? 1 : 0);
2738 case EM_GETLINECOUNT:
2740 ME_DisplayItem *item = editor->pBuffer->pFirst->next;
2743 ME_DisplayItem *prev_para = NULL, *last_para = NULL;
2745 while (item != editor->pBuffer->pLast)
2747 assert(item->type == diParagraph);
2748 prev_para = ME_FindItemBack(item, diRun);
2750 assert(prev_para->member.run.nFlags & MERF_ENDPARA);
2752 nRows += item->member.para.nRows;
2753 item = item->member.para.next_para;
2755 last_para = ME_FindItemBack(item, diRun);
2757 assert(last_para->member.run.nFlags & MERF_ENDPARA);
2758 if (editor->bEmulateVersion10 && prev_para && last_para->member.run.nCharOfs == 0
2759 && prev_para->member.run.nCR == 1 && prev_para->member.run.nLF == 0)
2761 /* In 1.0 emulation, the last solitary \r at the very end of the text
2762 (if one exists) is NOT a line break.
2763 FIXME: this is an ugly hack. This should have a more regular model. */
2767 TRACE("EM_GETLINECOUNT: nRows==%d\n", nRows);
2768 return max(1, nRows);
2770 case EM_LINEFROMCHAR:
2773 return ME_RowNumberFromCharOfs(editor, ME_GetCursorOfs(editor, 1));
2775 return ME_RowNumberFromCharOfs(editor, wParam);
2777 case EM_EXLINEFROMCHAR:
2780 return ME_RowNumberFromCharOfs(editor, ME_GetCursorOfs(editor,1));
2782 return ME_RowNumberFromCharOfs(editor, lParam);
2786 ME_DisplayItem *item, *para;
2790 item = ME_FindItemBack(editor->pCursors[0].pRun, diStartRow);
2792 item = ME_FindRowWithNumber(editor, wParam);
2795 para = ME_GetParagraph(item);
2796 item = ME_FindItemFwd(item, diRun);
2797 nCharOfs = para->member.para.nCharOfs + item->member.run.nCharOfs;
2798 TRACE("EM_LINEINDEX: nCharOfs==%d\n", nCharOfs);
2803 ME_DisplayItem *item, *item_end;
2804 int nChars = 0, nThisLineOfs = 0, nNextLineOfs = 0;
2806 if (wParam > ME_GetTextLength(editor))
2810 FIXME("EM_LINELENGTH: returning number of unselected characters on lines with selection unsupported.\n");
2813 item = ME_FindItemAtOffset(editor, diRun, wParam, NULL);
2814 item = ME_RowStart(item);
2815 nThisLineOfs = ME_CharOfsFromRunOfs(editor, ME_FindItemFwd(item, diRun), 0);
2816 item_end = ME_FindItemFwd(item, diStartRowOrParagraphOrEnd);
2817 if (item_end->type == diStartRow)
2818 nNextLineOfs = ME_CharOfsFromRunOfs(editor, ME_FindItemFwd(item_end, diRun), 0);
2821 ME_DisplayItem *endPara;
2823 nNextLineOfs = ME_FindItemFwd(item, diParagraphOrEnd)->member.para.nCharOfs;
2824 endPara = ME_FindItemFwd(item, diParagraphOrEnd);
2825 endPara = ME_FindItemBack(endPara, diRun);
2827 assert(endPara->type == diRun);
2828 assert(endPara->member.run.nFlags & MERF_ENDPARA);
2829 nNextLineOfs -= endPara->member.run.nCR + endPara->member.run.nLF;
2831 nChars = nNextLineOfs - nThisLineOfs;
2832 TRACE("EM_LINELENGTH(%ld)==%d\n",wParam, nChars);
2835 case EM_EXLIMITTEXT:
2837 if ((int)lParam < 0)
2840 editor->nTextLimit = 65536;
2842 editor->nTextLimit = (int) lParam;
2848 editor->nTextLimit = 65536;
2850 editor->nTextLimit = (int) wParam;
2853 case EM_GETLIMITTEXT:
2855 return editor->nTextLimit;
2859 FINDTEXTA *ft = (FINDTEXTA *)lParam;
2860 int nChars = MultiByteToWideChar(CP_ACP, 0, ft->lpstrText, -1, NULL, 0);
2864 if ((tmp = ALLOC_N_OBJ(WCHAR, nChars)) != NULL)
2865 MultiByteToWideChar(CP_ACP, 0, ft->lpstrText, -1, tmp, nChars);
2866 r = ME_FindText(editor, wParam, &ft->chrg, tmp, NULL);
2872 FINDTEXTEXA *ex = (FINDTEXTEXA *)lParam;
2873 int nChars = MultiByteToWideChar(CP_ACP, 0, ex->lpstrText, -1, NULL, 0);
2877 if ((tmp = ALLOC_N_OBJ(WCHAR, nChars)) != NULL)
2878 MultiByteToWideChar(CP_ACP, 0, ex->lpstrText, -1, tmp, nChars);
2879 r = ME_FindText(editor, wParam, &ex->chrg, tmp, &ex->chrgText);
2885 FINDTEXTW *ft = (FINDTEXTW *)lParam;
2886 return ME_FindText(editor, wParam, &ft->chrg, ft->lpstrText, NULL);
2888 case EM_FINDTEXTEXW:
2890 FINDTEXTEXW *ex = (FINDTEXTEXW *)lParam;
2891 return ME_FindText(editor, wParam, &ex->chrg, ex->lpstrText, &ex->chrgText);
2894 if (!wParam || !lParam)
2896 *(int *)wParam = editor->nZoomNumerator;
2897 *(int *)lParam = editor->nZoomDenominator;
2900 return ME_SetZoom(editor, wParam, lParam);
2901 case EM_CHARFROMPOS:
2902 return ME_CharFromPos(editor, ((POINTL *)lParam)->x, ((POINTL *)lParam)->y);
2903 case EM_POSFROMCHAR:
2905 ME_DisplayItem *pRun;
2906 int nCharOfs, nOffset, nLength;
2910 /* detect which API version we're dealing with */
2911 if (wParam >= 0x40000)
2913 nLength = ME_GetTextLength(editor);
2915 if (nCharOfs < nLength) {
2916 ME_RunOfsFromCharOfs(editor, nCharOfs, &pRun, &nOffset);
2917 assert(pRun->type == diRun);
2918 pt.y = pRun->member.run.pt.y;
2919 pt.x = pRun->member.run.pt.x + ME_PointFromChar(editor, &pRun->member.run, nOffset);
2920 pt.y += ME_GetParagraph(pRun)->member.para.nYPos;
2923 pt.y = editor->pBuffer->pLast->member.para.nYPos;
2925 pt.x += editor->selofs;
2926 if (wParam >= 0x40000) {
2927 *(POINTL *)wParam = pt;
2929 return MAKELONG( pt.x, pt.y );
2932 if (GetWindowLongW(hWnd, GWL_STYLE) & WS_HSCROLL)
2933 { /* Squelch the default horizontal scrollbar it would make */
2934 ShowScrollBar(editor->hWnd, SB_HORZ, FALSE);
2936 ME_CommitUndo(editor);
2937 ME_WrapMarkedParagraphs(editor);
2938 ME_MoveCaret(editor);
2941 ME_DestroyEditor(editor);
2942 SetWindowLongPtrW(hWnd, 0, 0);
2944 case WM_LBUTTONDOWN:
2945 if ((editor->nEventMask & ENM_MOUSEEVENTS) &&
2946 !ME_FilterEvent(editor, msg, &wParam, &lParam))
2949 ME_LButtonDown(editor, (short)LOWORD(lParam), (short)HIWORD(lParam));
2951 ME_LinkNotify(editor,msg,wParam,lParam);
2952 if (!ME_SetCursor(editor, LOWORD(lParam))) goto do_default;
2955 if ((editor->nEventMask & ENM_MOUSEEVENTS) &&
2956 !ME_FilterEvent(editor, msg, &wParam, &lParam))
2958 if (GetCapture() == hWnd)
2959 ME_MouseMove(editor, (short)LOWORD(lParam), (short)HIWORD(lParam));
2960 ME_LinkNotify(editor,msg,wParam,lParam);
2961 if (!ME_SetCursor(editor, LOWORD(lParam))) goto do_default;
2964 if (GetCapture() == hWnd)
2966 if ((editor->nEventMask & ENM_MOUSEEVENTS) &&
2967 !ME_FilterEvent(editor, msg, &wParam, &lParam))
2972 editor->linesel = 0;
2973 ret = ME_SetCursor(editor, LOWORD(lParam));
2974 ME_LinkNotify(editor,msg,wParam,lParam);
2975 if (!ret) goto do_default;
2978 case WM_LBUTTONDBLCLK:
2979 if ((editor->nEventMask & ENM_MOUSEEVENTS) &&
2980 !ME_FilterEvent(editor, msg, &wParam, &lParam))
2982 ME_LinkNotify(editor,msg,wParam,lParam);
2983 ME_SelectWord(editor);
2986 case WM_RBUTTONDOWN:
2987 if ((editor->nEventMask & ENM_MOUSEEVENTS) &&
2988 !ME_FilterEvent(editor, msg, &wParam, &lParam))
2991 case WM_CONTEXTMENU:
2992 if (!ME_ShowContextMenu(editor, (short)LOWORD(lParam), (short)HIWORD(lParam)))
2996 if (editor->bRedraw)
3001 hDC = BeginPaint(hWnd, &ps);
3002 ME_PaintContent(editor, hDC, FALSE, &ps.rcPaint);
3003 EndPaint(hWnd, &ps);
3007 editor->bHaveFocus = TRUE;
3008 ME_ShowCaret(editor);
3009 ME_SendOldNotify(editor, EN_SETFOCUS);
3012 ME_HideCaret(editor);
3013 editor->bHaveFocus = FALSE;
3014 ME_SendOldNotify(editor, EN_KILLFOCUS);
3018 if (editor->bRedraw)
3020 HDC hDC = (HDC)wParam;
3022 if (GetUpdateRect(hWnd,&rc,TRUE))
3024 FillRect(hDC, &rc, editor->hbrBackground);
3030 TRACE("editor wnd command = %d\n", LOWORD(wParam));
3033 if ((editor->nEventMask & ENM_KEYEVENTS) &&
3034 !ME_FilterEvent(editor, msg, &wParam, &lParam))
3038 if ((editor->nEventMask & ENM_KEYEVENTS) &&
3039 !ME_FilterEvent(editor, msg, &wParam, &lParam))
3041 if (ME_KeyDown(editor, LOWORD(wParam)))
3049 wstr = (WCHAR)wParam;
3052 CHAR charA = wParam;
3053 MultiByteToWideChar(CP_ACP, 0, &charA, 1, &wstr, 1);
3055 if (editor->AutoURLDetect_bEnable)
3056 ME_AutoURLDetect(editor, wstr);
3060 case 1: /* Ctrl-A */
3061 ME_SetSelection(editor, 0, -1);
3063 case 3: /* Ctrl-C */
3064 SendMessageW(editor->hWnd, WM_COPY, 0, 0);
3068 if (GetWindowLongW(editor->hWnd, GWL_STYLE) & ES_READONLY) {
3069 MessageBeep(MB_ICONERROR);
3070 return 0; /* FIXME really 0 ? */
3075 case 22: /* Ctrl-V */
3076 SendMessageW(editor->hWnd, WM_PASTE, 0, 0);
3078 case 24: /* Ctrl-X */
3079 SendMessageW(editor->hWnd, WM_CUT, 0, 0);
3081 case 25: /* Ctrl-Y */
3082 SendMessageW(editor->hWnd, EM_REDO, 0, 0);
3084 case 26: /* Ctrl-Z */
3085 SendMessageW(editor->hWnd, EM_UNDO, 0, 0);
3088 if (((unsigned)wstr)>=' '
3089 || (wstr=='\r' && (GetWindowLongW(hWnd, GWL_STYLE) & ES_MULTILINE))
3091 /* FIXME maybe it would make sense to call EM_REPLACESEL instead ? */
3092 /* WM_CHAR is restricted to nTextLimit */
3094 ME_GetSelection(editor, &from, &to);
3095 if(editor->nTextLimit > ME_GetTextLength(editor) - (to-from))
3097 ME_Style *style = ME_GetInsertStyle(editor, 0);
3098 ME_SaveTempStyle(editor);
3099 if (wstr == '\r' && (GetKeyState(VK_SHIFT) & 0x8000))
3100 ME_InsertEndRowFromCursor(editor, 0);
3102 ME_InsertTextFromCursor(editor, 0, &wstr, 1, style);
3103 ME_ReleaseStyle(style);
3104 ME_CommitUndo(editor);
3106 ME_UpdateRepaint(editor);
3110 case EM_SCROLL: /* fall through */
3116 origNPos = ME_GetYScrollPos(editor);
3119 if (editor && editor->pBuffer && editor->pBuffer->pDefaultStyle)
3120 lineHeight = editor->pBuffer->pDefaultStyle->tm.tmHeight;
3121 if (lineHeight <= 0) lineHeight = 24;
3123 switch(LOWORD(wParam))
3126 ME_ScrollUp(editor,lineHeight);
3129 ME_ScrollDown(editor,lineHeight);
3132 ME_ScrollUp(editor,editor->sizeWindow.cy);
3135 ME_ScrollDown(editor,editor->sizeWindow.cy);
3138 case SB_THUMBPOSITION:
3139 ME_ScrollAbs(editor,HIWORD(wParam));
3142 if (msg == EM_SCROLL)
3143 return 0x00010000 | (((ME_GetYScrollPos(editor) - origNPos)/lineHeight) & 0xffff);
3149 UINT pulScrollLines;
3151 if ((editor->nEventMask & ENM_MOUSEEVENTS) &&
3152 !ME_FilterEvent(editor, msg, &wParam, &lParam))
3155 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES,0, &pulScrollLines, 0);
3156 gcWheelDelta = -GET_WHEEL_DELTA_WPARAM(wParam);
3158 if (abs(gcWheelDelta) >= WHEEL_DELTA && pulScrollLines)
3160 /* FIXME follow the original */
3161 ME_ScrollDown(editor,pulScrollLines * (gcWheelDelta / WHEEL_DELTA) * 8);
3167 *((RECT *)lParam) = editor->rcFormat;
3175 RECT *rc = (RECT *)lParam;
3179 editor->rcFormat.left += rc->left;
3180 editor->rcFormat.top += rc->top;
3181 editor->rcFormat.right += rc->right;
3182 editor->rcFormat.bottom += rc->bottom;
3186 editor->rcFormat = *rc;
3191 GetClientRect(hWnd, &editor->rcFormat);
3193 if (msg != EM_SETRECTNP)
3194 ME_RewrapRepaint(editor);
3197 case EM_REQUESTRESIZE:
3198 ME_SendRequestResize(editor, TRUE);
3201 if ((editor->bRedraw = wParam))
3202 ME_RewrapRepaint(editor);
3206 GetClientRect(hWnd, &editor->rcFormat);
3207 ME_RewrapRepaint(editor);
3208 return DefWindowProcW(hWnd, msg, wParam, lParam);
3210 /* IME messages to make richedit controls IME aware */
3211 case WM_IME_SETCONTEXT:
3212 case WM_IME_CONTROL:
3214 case WM_IME_COMPOSITIONFULL:
3216 case WM_IME_STARTCOMPOSITION:
3218 editor->imeStartIndex=ME_GetCursorOfs(editor,0);
3219 ME_DeleteSelection(editor);
3220 ME_CommitUndo(editor);
3221 ME_UpdateRepaint(editor);
3224 case WM_IME_COMPOSITION:
3228 ME_Style *style = ME_GetInsertStyle(editor, 0);
3229 hIMC = ImmGetContext(hWnd);
3230 ME_DeleteSelection(editor);
3231 ME_CommitUndo(editor);
3232 ME_SaveTempStyle(editor);
3233 if (lParam & GCS_RESULTSTR)
3235 LPWSTR lpCompStr = NULL;
3238 dwBufLen = ImmGetCompositionStringW(hIMC, GCS_RESULTSTR, NULL, 0);
3239 lpCompStr = HeapAlloc(GetProcessHeap(),0,dwBufLen + sizeof(WCHAR));
3240 ImmGetCompositionStringW(hIMC, GCS_RESULTSTR, lpCompStr, dwBufLen);
3241 lpCompStr[dwBufLen/sizeof(WCHAR)] = 0;
3242 ME_InsertTextFromCursor(editor,0,lpCompStr,dwBufLen/sizeof(WCHAR),style);
3244 else if (lParam & GCS_COMPSTR)
3246 LPWSTR lpCompStr = NULL;
3249 dwBufLen = ImmGetCompositionStringW(hIMC, GCS_COMPSTR, NULL, 0);
3250 lpCompStr = HeapAlloc(GetProcessHeap(),0,dwBufLen + sizeof(WCHAR));
3251 ImmGetCompositionStringW(hIMC, GCS_COMPSTR, lpCompStr, dwBufLen);
3252 lpCompStr[dwBufLen/sizeof(WCHAR)] = 0;
3254 ME_InsertTextFromCursor(editor,0,lpCompStr,dwBufLen/sizeof(WCHAR),style);
3255 ME_SetSelection(editor,editor->imeStartIndex,
3256 editor->imeStartIndex + dwBufLen/sizeof(WCHAR));
3258 ME_ReleaseStyle(style);
3259 ME_UpdateRepaint(editor);
3262 case WM_IME_ENDCOMPOSITION:
3264 ME_DeleteSelection(editor);
3265 editor->imeStartIndex=-1;
3268 case EM_GETOLEINTERFACE:
3270 LPVOID *ppvObj = (LPVOID*) lParam;
3271 return CreateIRichEditOle(editor, ppvObj);
3273 case EM_GETPASSWORDCHAR:
3275 return editor->cPasswordMask;
3277 case EM_SETOLECALLBACK:
3278 if(editor->lpOleCallback)
3279 IUnknown_Release(editor->lpOleCallback);
3280 editor->lpOleCallback = (LPRICHEDITOLECALLBACK)lParam;
3281 if(editor->lpOleCallback)
3282 IUnknown_AddRef(editor->lpOleCallback);
3284 case EM_GETWORDBREAKPROC:
3285 return (LRESULT)editor->pfnWordBreak;
3286 case EM_SETWORDBREAKPROC:
3288 EDITWORDBREAKPROCW pfnOld = editor->pfnWordBreak;
3290 editor->pfnWordBreak = (EDITWORDBREAKPROCW)lParam;
3291 return (LRESULT)pfnOld;
3293 case EM_SETTEXTMODE:
3298 ret = RichEditWndProc_common(hWnd, WM_GETTEXTLENGTH, 0, 0, unicode);
3301 /*Check for valid wParam*/
3302 if ((((wParam & TM_RICHTEXT) && ((wParam & TM_PLAINTEXT) << 1))) ||
3303 (((wParam & TM_MULTILEVELUNDO) && ((wParam & TM_SINGLELEVELUNDO) << 1))) ||
3304 (((wParam & TM_MULTICODEPAGE) && ((wParam & TM_SINGLECODEPAGE) << 1))))
3308 if (wParam & (TM_RICHTEXT | TM_PLAINTEXT))
3310 mask |= (TM_RICHTEXT | TM_PLAINTEXT);
3311 changes |= (wParam & (TM_RICHTEXT | TM_PLAINTEXT));
3313 /*FIXME: Currently no support for undo level and code page options*/
3314 editor->mode = (editor->mode & (~mask)) | changes;
3320 case EM_SETPASSWORDCHAR:
3322 editor->cPasswordMask = wParam;
3323 ME_RewrapRepaint(editor);
3326 case EM_SETTARGETDEVICE:
3329 BOOL new = (lParam == 0);
3330 if (editor->bWordWrap != new)
3332 editor->bWordWrap = new;
3333 ME_RewrapRepaint(editor);
3336 else FIXME("Unsupported yet non NULL device in EM_SETTARGETDEVICE\n");
3340 return DefWindowProcW(hWnd, msg, wParam, lParam);
3345 static LRESULT WINAPI RichEditWndProcW(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
3347 BOOL unicode = TRUE;
3349 /* Under Win9x RichEdit20W returns ANSI strings, see the tests. */
3350 if (msg == WM_GETTEXT && (GetVersion() & 0x80000000))
3353 return RichEditWndProc_common(hWnd, msg, wParam, lParam, unicode);
3356 static LRESULT WINAPI RichEditWndProcA(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
3358 return RichEditWndProc_common(hWnd, msg, wParam, lParam, FALSE);
3361 /******************************************************************
3362 * RichEditANSIWndProc (RICHED20.10)
3364 LRESULT WINAPI RichEditANSIWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
3366 return RichEditWndProcA(hWnd, msg, wParam, lParam);
3369 /******************************************************************
3370 * RichEdit10ANSIWndProc (RICHED20.9)
3372 LRESULT WINAPI RichEdit10ANSIWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
3376 /* FIXME: this is NOT the same as 2.0 version */
3377 result = RichEditANSIWndProc(hWnd, msg, wParam, lParam);
3378 if (msg == WM_NCCREATE)
3380 ME_TextEditor *editor = (ME_TextEditor *)GetWindowLongPtrW(hWnd, 0);
3382 editor->bEmulateVersion10 = TRUE;
3383 editor->pBuffer->pLast->member.para.nCharOfs = 2;
3384 assert(editor->pBuffer->pLast->prev->type == diRun);
3385 assert(editor->pBuffer->pLast->prev->member.run.nFlags & MERF_ENDPARA);
3386 editor->pBuffer->pLast->prev->member.run.nLF = 1;
3391 void ME_SendOldNotify(ME_TextEditor *editor, int nCode)
3393 HWND hWnd = editor->hWnd;
3394 SendMessageA(GetParent(hWnd), WM_COMMAND, (nCode<<16)|GetWindowLongW(hWnd, GWLP_ID), (LPARAM)hWnd);
3397 void ME_LinkNotify(ME_TextEditor *editor, UINT msg, WPARAM wParam, LPARAM lParam)
3400 ME_Cursor tmpCursor;
3401 int nCharOfs; /* The start of the clicked text. Absolute character offset */
3406 x = (short)LOWORD(lParam);
3407 y = (short)HIWORD(lParam);
3408 nCharOfs = ME_CharFromPos(editor, x, y);
3409 if (nCharOfs < 0) return;
3411 ME_CursorFromCharOfs(editor, nCharOfs, &tmpCursor);
3412 tmpRun = &tmpCursor.pRun->member.run;
3414 if ((tmpRun->style->fmt.dwMask & CFM_LINK)
3415 && (tmpRun->style->fmt.dwEffects & CFE_LINK))
3416 { /* The clicked run has CFE_LINK set */
3417 info.nmhdr.hwndFrom = editor->hWnd;
3418 info.nmhdr.idFrom = GetWindowLongW(editor->hWnd, GWLP_ID);
3419 info.nmhdr.code = EN_LINK;
3421 info.wParam = wParam;
3422 info.lParam = lParam;
3423 info.chrg.cpMin = ME_CharOfsFromRunOfs(editor,tmpCursor.pRun,0);
3424 info.chrg.cpMax = info.chrg.cpMin + ME_StrVLen(tmpRun->strText);
3425 SendMessageW(GetParent(editor->hWnd), WM_NOTIFY,info.nmhdr.idFrom, (LPARAM)&info);
3429 int ME_CountParagraphsBetween(ME_TextEditor *editor, int from, int to)
3431 ME_DisplayItem *item = ME_FindItemFwd(editor->pBuffer->pFirst, diParagraph);
3434 while(item && item->member.para.next_para->member.para.nCharOfs <= from)
3435 item = item->member.para.next_para;
3438 while(item && item->member.para.next_para->member.para.nCharOfs <= to) {
3439 item = item->member.para.next_para;
3446 int ME_GetTextW(ME_TextEditor *editor, WCHAR *buffer, int nStart, int nChars, int bCRLF)
3448 ME_DisplayItem *item = ME_FindItemAtOffset(editor, diRun, nStart, &nStart);
3450 WCHAR *pStart = buffer;
3457 /* bCRLF flag is only honored in 2.0 and up. 1.0 must always return text verbatim */
3458 if (editor->bEmulateVersion10) bCRLF = 0;
3462 int nLen = ME_StrLen(item->member.run.strText) - nStart;
3465 CopyMemory(buffer, item->member.run.strText->szData + nStart, sizeof(WCHAR)*nLen);
3474 item = ME_FindItemFwd(item, diRun);
3477 while(nChars && item)
3479 int nLen = ME_StrLen(item->member.run.strText);
3480 if (item->member.run.nFlags & MERF_ENDPARA)
3481 nLen = item->member.run.nCR + item->member.run.nLF;
3485 if (item->member.run.nFlags & MERF_ENDPARA)
3487 if (!ME_FindItemFwd(item, diRun))
3488 /* No '\r' is appended to the last paragraph. */
3490 else if (bCRLF && nChars == 1) {
3496 /* richedit 2.0 case - actual line-break is \r but should report \r\n */
3499 *buffer = '\n'; /* Later updated by nLen==1 at the end of the loop */
3506 /* richedit 2.0 verbatim has only \r. richedit 1.0 should honor encodings */
3508 while (nChars - i > 0 && i < item->member.run.nCR)
3510 buffer[i] = '\r'; i++;
3513 while (nChars - i - j > 0 && j < item->member.run.nLF)
3515 buffer[i+j] = '\n'; j++;
3521 CopyMemory(buffer, item->member.run.strText->szData, sizeof(WCHAR)*nLen);
3528 TRACE("nWritten=%d, actual=%d\n", nWritten, buffer-pStart);
3532 item = ME_FindItemFwd(item, diRun);
3535 TRACE("nWritten=%d, actual=%d\n", nWritten, buffer-pStart);
3539 static BOOL ME_RegisterEditorClass(HINSTANCE hInstance)
3544 wcW.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW | CS_GLOBALCLASS;
3545 wcW.lpfnWndProc = RichEditWndProcW;
3547 wcW.cbWndExtra = sizeof(ME_TextEditor *);
3548 wcW.hInstance = NULL; /* hInstance would register DLL-local class */
3550 wcW.hCursor = LoadCursorW(NULL, MAKEINTRESOURCEW(IDC_IBEAM));
3551 wcW.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);
3552 wcW.lpszMenuName = NULL;
3554 if (is_version_nt())
3556 wcW.lpszClassName = RichEdit20W;
3557 if (!RegisterClassW(&wcW)) return FALSE;
3558 wcW.lpszClassName = RichEdit50W;
3559 if (!RegisterClassW(&wcW)) return FALSE;
3563 /* WNDCLASSA/W have the same layout */
3564 wcW.lpszClassName = (LPCWSTR)"RichEdit20W";
3565 if (!RegisterClassA((WNDCLASSA *)&wcW)) return FALSE;
3566 wcW.lpszClassName = (LPCWSTR)"RichEdit50W";
3567 if (!RegisterClassA((WNDCLASSA *)&wcW)) return FALSE;
3570 wcA.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW | CS_GLOBALCLASS;
3571 wcA.lpfnWndProc = RichEditWndProcA;
3573 wcA.cbWndExtra = sizeof(ME_TextEditor *);
3574 wcA.hInstance = NULL; /* hInstance would register DLL-local class */
3576 wcA.hCursor = LoadCursorW(NULL, MAKEINTRESOURCEW(IDC_IBEAM));
3577 wcA.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);
3578 wcA.lpszMenuName = NULL;
3579 wcA.lpszClassName = "RichEdit20A";
3580 if (!RegisterClassA(&wcA)) return FALSE;
3581 wcA.lpszClassName = "RichEdit50A";
3582 if (!RegisterClassA(&wcA)) return FALSE;
3587 LRESULT WINAPI REComboWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
3588 /* FIXME: Not implemented */
3589 TRACE("hWnd %p msg %04x (%s) %08lx %08lx\n",
3590 hWnd, msg, get_msg_name(msg), wParam, lParam);
3591 return DefWindowProcW(hWnd, msg, wParam, lParam);
3594 LRESULT WINAPI REListWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
3595 /* FIXME: Not implemented */
3596 TRACE("hWnd %p msg %04x (%s) %08lx %08lx\n",
3597 hWnd, msg, get_msg_name(msg), wParam, lParam);
3598 return DefWindowProcW(hWnd, msg, wParam, lParam);
3601 /******************************************************************
3602 * REExtendedRegisterClass (RICHED20.8)
3604 * FIXME undocumented
3605 * Need to check for errors and implement controls and callbacks
3607 LRESULT WINAPI REExtendedRegisterClass(void)
3612 FIXME("semi stub\n");
3616 wcW.hInstance = NULL;
3619 wcW.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
3620 wcW.lpszMenuName = NULL;
3622 if (!ME_ListBoxRegistered)
3624 wcW.style = CS_PARENTDC | CS_DBLCLKS | CS_GLOBALCLASS;
3625 wcW.lpfnWndProc = REListWndProc;
3626 wcW.lpszClassName = REListBox20W;
3627 if (RegisterClassW(&wcW)) ME_ListBoxRegistered = TRUE;
3630 if (!ME_ComboBoxRegistered)
3632 wcW.style = CS_PARENTDC | CS_DBLCLKS | CS_GLOBALCLASS | CS_VREDRAW | CS_HREDRAW;
3633 wcW.lpfnWndProc = REComboWndProc;
3634 wcW.lpszClassName = REComboBox20W;
3635 if (RegisterClassW(&wcW)) ME_ComboBoxRegistered = TRUE;
3639 if (ME_ListBoxRegistered)
3641 if (ME_ComboBoxRegistered)
3647 int ME_AutoURLDetect(ME_TextEditor *editor, WCHAR curChar)
3667 int curf_ef, link_ef, def_ef;
3668 int cur_prefx, prefx_cnt;
3669 int sel_min, sel_max;
3672 int URLmin, URLmax = 0;
3674 CHARFORMAT2W cur_format;
3675 CHARFORMAT2W default_format;
3677 RichEditANSIWndProc(editor->hWnd, EM_EXGETSEL, (WPARAM) 0, (LPARAM) &ins_pt);
3678 sel_min = ins_pt.cpMin;
3679 sel_max = ins_pt.cpMax;
3680 if (sel_min==sel_max)
3682 if (sel_min!=sel_max)
3683 car_pos = ME_GetTextLength(editor)+1;
3684 cur_format.cbSize = sizeof(cur_format);
3685 default_format.cbSize = sizeof(default_format);
3686 RichEditANSIWndProc(editor->hWnd, EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM) &cur_format);
3687 RichEditANSIWndProc(editor->hWnd, EM_GETCHARFORMAT, SCF_DEFAULT, (LPARAM) &default_format);
3688 link.cbSize = sizeof(link);
3689 link.dwMask = CFM_LINK;
3690 link.dwEffects = CFE_LINK;
3691 curf_ef = cur_format.dwEffects & link.dwEffects;
3692 def_ef = default_format.dwEffects & link.dwEffects;
3693 link_ef = link.dwEffects & link.dwEffects;
3694 if (curf_ef == link_ef)
3696 if( curChar == '\n' || curChar=='\r' || curChar==' ')
3698 ME_SetSelection(editor, car_pos, car_pos);
3699 RichEditANSIWndProc(editor->hWnd, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &default_format);
3704 if (curf_ef == def_ef)
3707 prefx_cnt = (sizeof(prefixes)/sizeof(struct prefix_s))-1;
3708 while (cur_prefx<=prefx_cnt)
3712 ft.lpstrText = prefixes[cur_prefx].text;
3713 URLmin=max(0,(car_pos-prefixes[cur_prefx].length));
3714 URLmax=max(0, car_pos);
3715 if ((car_pos == 0) && (ME_GetTextLength(editor) != 0))
3717 URLmax = ME_GetTextLength(editor)+1;
3719 ft.chrg.cpMin = URLmin;
3720 ft.chrg.cpMax = URLmax;
3721 text_pos=RichEditANSIWndProc(editor->hWnd, EM_FINDTEXT, FR_DOWN, (LPARAM)&ft);
3726 ME_SetCharFormat(editor, text_pos, (URLmax-text_pos), &link);
3727 ME_RewrapRepaint(editor);
3736 static BOOL isurlspecial(WCHAR c)
3738 static const WCHAR special_chars[] = {'.','/','%','@','*','|','\\','+','#',0};
3739 return strchrW( special_chars, c ) != NULL;
3743 * This proc takes a selection, and scans it forward in order to select the span
3744 * of a possible URL candidate. A possible URL candidate must start with isalnum
3745 * or one of the following special characters: *|/\+%#@ and must consist entirely
3746 * of the characters allowed to start the URL, plus : (colon) which may occur
3747 * at most once, and not at either end.
3749 * sel_max == -1 indicates scan to end of text.
3751 BOOL ME_FindNextURLCandidate(ME_TextEditor *editor, int sel_min, int sel_max,
3752 int * candidate_min, int * candidate_max)
3754 ME_DisplayItem * item;
3755 ME_DisplayItem * para;
3757 BOOL foundColon = FALSE;
3758 WCHAR lastAcceptedChar = '\0';
3760 TRACE("sel_min = %d sel_max = %d\n", sel_min, sel_max);
3762 *candidate_min = *candidate_max = -1;
3763 item = ME_FindItemAtOffset(editor, diRun, sel_min, &nStart);
3764 if (!item) return FALSE;
3765 TRACE("nStart = %d\n", nStart);
3766 para = ME_GetParagraph(item);
3767 if (sel_max == -1) sel_max = ME_GetTextLength(editor);
3768 while (item && para->member.para.nCharOfs + item->member.run.nCharOfs + nStart < sel_max)
3770 ME_DisplayItem * next_item;
3772 if (!(item->member.run.nFlags & MERF_ENDPARA)) {
3773 /* Find start of candidate */
3774 if (*candidate_min == -1) {
3775 while (nStart < ME_StrLen(item->member.run.strText) &&
3776 !(isalnumW(item->member.run.strText->szData[nStart]) ||
3777 isurlspecial(item->member.run.strText->szData[nStart]))) {
3780 if (nStart < ME_StrLen(item->member.run.strText) &&
3781 (isalnumW(item->member.run.strText->szData[nStart]) ||
3782 isurlspecial(item->member.run.strText->szData[nStart]))) {
3783 *candidate_min = para->member.para.nCharOfs + item->member.run.nCharOfs + nStart;
3784 lastAcceptedChar = item->member.run.strText->szData[nStart];
3789 /* Find end of candidate */
3790 if (*candidate_min >= 0) {
3791 while (nStart < ME_StrLen(item->member.run.strText) &&
3792 (isalnumW(item->member.run.strText->szData[nStart]) ||
3793 isurlspecial(item->member.run.strText->szData[nStart]) ||
3794 (!foundColon && item->member.run.strText->szData[nStart] == ':') )) {
3795 if (item->member.run.strText->szData[nStart] == ':') foundColon = TRUE;
3796 lastAcceptedChar = item->member.run.strText->szData[nStart];
3799 if (nStart < ME_StrLen(item->member.run.strText) &&
3800 !(isalnumW(item->member.run.strText->szData[nStart]) ||
3801 isurlspecial(item->member.run.strText->szData[nStart]) )) {
3802 *candidate_max = para->member.para.nCharOfs + item->member.run.nCharOfs + nStart;
3804 if (lastAcceptedChar == ':') (*candidate_max)--;
3809 /* End of paragraph: skip it if before candidate span, or terminates
3810 current active span */
3811 if (*candidate_min >= 0) {
3812 *candidate_max = para->member.para.nCharOfs + item->member.run.nCharOfs;
3813 if (lastAcceptedChar == ':') (*candidate_max)--;
3818 /* Reaching this point means no span was found, so get next span */
3819 next_item = ME_FindItemFwd(item, diRun);
3821 if (*candidate_min >= 0) {
3822 /* There are no further runs, so take end of text as end of candidate */
3823 *candidate_max = para->member.para.nCharOfs + item->member.run.nCharOfs + nStart;
3824 if (lastAcceptedChar == ':') (*candidate_max)--;
3829 para = ME_GetParagraph(item);
3834 if (*candidate_min >= 0) {
3835 /* There are no further runs, so take end of text as end of candidate */
3836 *candidate_max = para->member.para.nCharOfs + item->member.run.nCharOfs + nStart;
3837 if (lastAcceptedChar == ':') (*candidate_max)--;
3845 * This proc evaluates the selection and returns TRUE if it can be considered an URL
3847 BOOL ME_IsCandidateAnURL(ME_TextEditor *editor, int sel_min, int sel_max)
3853 /* Code below depends on these being in decreasing length order! */
3867 LPWSTR bufferW = NULL;
3871 if (sel_max == -1) sel_max = ME_GetTextLength(editor);
3872 assert(sel_min <= sel_max);
3873 for (i = 0; i < sizeof(prefixes) / sizeof(struct prefix_s); i++)
3875 if (sel_max - sel_min < prefixes[i].length) continue;
3876 if (bufferW == NULL) {
3877 bufferW = (LPWSTR)heap_alloc((sel_max - sel_min + 1) * sizeof(WCHAR));
3879 ME_GetTextW(editor, bufferW, sel_min, min(sel_max - sel_min, strlen(prefixes[i].text)), 0);
3880 MultiByteToWideChar(CP_ACP, 0, prefixes[i].text, -1, bufW, 32);
3881 if (!lstrcmpW(bufW, bufferW))
3887 if (bufferW != NULL) heap_free(bufferW);