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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 API implementation status:
26 Messages (ANSI versions not done yet)
27 + EM_AUTOURLDETECT 2.0
38 + EM_FINDTEXT (only FR_DOWN flag implemented)
39 + EM_FINDTEXTEX (only FR_DOWN flag implemented)
43 + EM_GETAUTOURLDETECT 2.0
44 - EM_GETBIDIOPTIONS 3.0
45 - EM_GETCHARFORMAT (partly done)
48 + EM_GETFIRSTVISIBLELINE (can be optimized if needed)
49 - EM_GETIMECOLOR 1.0asian
50 - EM_GETIMECOMPMODE 2.0
51 - EM_GETIMEOPTIONS 1.0asian
53 - EM_GETLANGOPTIONS 2.0
56 + EM_GETLINECOUNT returns number of rows, not of paragraphs
61 + EM_GETPASSWORDCHAR 2.0
62 - EM_GETPUNCTUATION 1.0asian
66 + EM_GETSELTEXT (ANSI&Unicode)
67 + EM_GETSCROLLPOS 3.0 (only Y value valid)
70 + EM_GETTEXTLENGTHEX (GTL_PRECISE unimplemented)
72 ? + EM_GETTEXTRANGE (ANSI&Unicode)
73 - EM_GETTYPOGRAPHYOPTIONS 3.0
76 - EM_GETWORDBREAKPROCEX
77 - EM_GETWORDWRAPMODE 1.0asian
80 + EM_LIMITTEXT (Also called EM_SETLIMITTEXT)
89 + EM_REPLACESEL (proper style?) ANSI&Unicode
93 - EM_SETBIDIOPTIONS 3.0
95 + EM_SETCHARFORMAT (partly done, no ANSI)
97 + EM_SETEVENTMASK (few notifications supported)
99 - EM_SETIMECOLOR 1.0asian
100 - EM_SETIMEOPTIONS 1.0asian
101 - EM_SETLANGOPTIONS 2.0
103 + EM_SETMODIFY (not sure if implementation is correct)
105 + EM_SETOPTIONS (partially implemented)
108 + EM_SETPASSWORDCHAR 2.0
109 - EM_SETPUNCTUATION 1.0asian
110 + EM_SETREADONLY no beep on modification attempt
112 + EM_SETRECTNP (EM_SETRECT without repainting)
114 + EM_SETSCROLLPOS 3.0
117 + EM_SETTEXTEX 3.0 (no rich text insertion handling, proper style?)
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
125 + EM_SHOWSCROLLBAR 2.0
126 - EM_STOPGROUPTYPING 2.0
134 + WM_GETDLGCODE (the current implementation is incomplete)
135 + WM_GETTEXT (ANSI&Unicode)
136 + WM_GETTEXTLENGTH (ANSI version sucks)
139 + WM_SETTEXT (resets undo stack !) (proper style?) ANSI&Unicode
141 - WM_STYLECHANGED (things like read-only flag)
146 * EN_CHANGE (sent from the wrong place)
163 * EN_UPDATE (sent from the wrong place)
171 + ES_DISABLENOSCROLL (scrollbar is always visible)
172 - ES_EX_NOCALLOLEINIT
174 - ES_MULTILINE (currently single line controls aren't supported)
176 - ES_READONLY (I'm not sure if beeping is the proper behaviour)
182 - ES_WANTRETURN (don't know how to do WM_GETDLGCODE part)
189 * RICHED20 TODO (incomplete):
191 * - messages/styles/notifications listed above
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)
201 * - how to implement EM_FORMATRANGE and EM_DISPLAYBAND ? (Mission Impossible)
202 * - italic caret with italic fonts
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
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?
227 #define NO_SHLWAPI_STREAM
233 #define STACK_SIZE_DEFAULT 100
234 #define STACK_SIZE_MAX 1000
236 #define TEXT_LIMIT_DEFAULT 32767
238 WINE_DEFAULT_DEBUG_CHANNEL(richedit
);
240 static BOOL
ME_RegisterEditorClass(HINSTANCE
);
242 static const WCHAR RichEdit20W
[] = {'R', 'i', 'c', 'h', 'E', 'd', 'i', 't', '2', '0', 'W', 0};
243 static const WCHAR RichEdit50W
[] = {'R', 'i', 'c', 'h', 'E', 'd', 'i', 't', '5', '0', 'W', 0};
244 static const WCHAR REListBox20W
[] = {'R','E','L','i','s','t','B','o','x','2','0','W', 0};
245 static const WCHAR REComboBox20W
[] = {'R','E','C','o','m','b','o','B','o','x','2','0','W', 0};
246 static HCURSOR hLeft
;
247 static HCURSOR hBeam
;
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 */
339 fmt
.bUnderlineType
= CFU_UNDERLINENONE
;
342 fmt
.dwMask
= CFM_BOLD
;
343 fmt
.dwEffects
= info
->rtfParam
? fmt
.dwMask
: 0;
346 fmt
.dwMask
= CFM_ITALIC
;
347 fmt
.dwEffects
= info
->rtfParam
? fmt
.dwMask
: 0;
350 fmt
.dwMask
= CFM_UNDERLINETYPE
;
351 fmt
.bUnderlineType
= info
->rtfParam
? CFU_CF1UNDERLINE
: CFU_UNDERLINENONE
;
353 case rtfDotUnderline
:
354 fmt
.dwMask
= CFM_UNDERLINETYPE
;
355 fmt
.bUnderlineType
= info
->rtfParam
? CFU_UNDERLINEDOTTED
: CFU_UNDERLINENONE
;
358 fmt
.dwMask
= CFM_UNDERLINETYPE
;
359 fmt
.bUnderlineType
= info
->rtfParam
? CFU_UNDERLINEDOUBLE
: CFU_UNDERLINENONE
;
361 case rtfWordUnderline
:
362 fmt
.dwMask
= CFM_UNDERLINETYPE
;
363 fmt
.bUnderlineType
= info
->rtfParam
? CFU_UNDERLINEWORD
: CFU_UNDERLINENONE
;
366 fmt
.dwMask
= CFM_UNDERLINETYPE
;
367 fmt
.bUnderlineType
= CFU_UNDERLINENONE
;
370 fmt
.dwMask
= CFM_STRIKEOUT
;
371 fmt
.dwEffects
= info
->rtfParam
? fmt
.dwMask
: 0;
375 case rtfSubScrShrink
:
376 case rtfSuperScrShrink
:
378 fmt
.dwMask
= CFM_SUBSCRIPT
|CFM_SUPERSCRIPT
;
379 if (info
->rtfMinor
== rtfSubScrShrink
) fmt
.dwEffects
= CFE_SUBSCRIPT
;
380 if (info
->rtfMinor
== rtfSuperScrShrink
) fmt
.dwEffects
= CFE_SUPERSCRIPT
;
381 if (info
->rtfMinor
== rtfNoSuperSub
) fmt
.dwEffects
= 0;
384 fmt
.dwMask
= CFM_HIDDEN
;
385 fmt
.dwEffects
= info
->rtfParam
? fmt
.dwMask
: 0;
388 fmt
.dwMask
= CFM_BACKCOLOR
;
390 if (info
->rtfParam
== 0)
391 fmt
.dwEffects
= CFE_AUTOBACKCOLOR
;
392 else if (info
->rtfParam
!= rtfNoParam
)
394 RTFColor
*c
= RTFGetColor(info
, info
->rtfParam
);
395 fmt
.crTextColor
= (c
->rtfCBlue
<<16)|(c
->rtfCGreen
<<8)|(c
->rtfCRed
);
399 fmt
.dwMask
= CFM_COLOR
;
401 if (info
->rtfParam
== 0)
402 fmt
.dwEffects
= CFE_AUTOCOLOR
;
403 else if (info
->rtfParam
!= rtfNoParam
)
405 RTFColor
*c
= RTFGetColor(info
, info
->rtfParam
);
407 fmt
.crTextColor
= (c
->rtfCBlue
<<16)|(c
->rtfCGreen
<<8)|(c
->rtfCRed
);
413 if (info
->rtfParam
!= rtfNoParam
)
415 RTFFont
*f
= RTFGetFont(info
, info
->rtfParam
);
418 MultiByteToWideChar(CP_ACP
, 0, f
->rtfFName
, -1, fmt
.szFaceName
, sizeof(fmt
.szFaceName
)/sizeof(WCHAR
));
419 fmt
.szFaceName
[sizeof(fmt
.szFaceName
)/sizeof(WCHAR
)-1] = '\0';
420 fmt
.bCharSet
= f
->rtfFCharSet
;
421 fmt
.dwMask
= CFM_FACE
| CFM_CHARSET
;
426 fmt
.dwMask
= CFM_SIZE
;
427 if (info
->rtfParam
!= rtfNoParam
)
428 fmt
.yHeight
= info
->rtfParam
*10;
433 RTFFlushOutputBuffer(info
);
434 /* FIXME too slow ? how come ? */
435 style2
= ME_ApplyStyle(info
->style
, &fmt
);
436 ME_ReleaseStyle(info
->style
);
437 info
->style
= style2
;
438 info
->styleChanged
= TRUE
;
442 /* FIXME this function doesn't get any information about context of the RTF tag, which is very bad,
443 the same tags mean different things in different contexts */
444 static void ME_RTFParAttrHook(RTF_Info
*info
)
447 fmt
.cbSize
= sizeof(fmt
);
450 switch(info
->rtfMinor
)
452 case rtfParDef
: /* restores default paragraph attributes */
453 fmt
.dwMask
= PFM_ALIGNMENT
| PFM_TABSTOPS
| PFM_OFFSET
| PFM_STARTINDENT
;
454 fmt
.wAlignment
= PFA_LEFT
;
456 fmt
.dxOffset
= fmt
.dxStartIndent
= 0;
457 RTFFlushOutputBuffer(info
);
458 ME_GetParagraph(info
->editor
->pCursors
[0].pRun
)->member
.para
.bTable
= FALSE
;
462 ME_DisplayItem
*para
;
464 RTFFlushOutputBuffer(info
);
465 para
= ME_GetParagraph(info
->editor
->pCursors
[0].pRun
);
466 assert(para
->member
.para
.pCells
);
467 para
->member
.para
.bTable
= TRUE
;
471 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
472 fmt
.dwMask
= PFM_STARTINDENT
| PFM_OFFSET
;
473 fmt
.dxStartIndent
+= info
->rtfParam
+ fmt
.dxOffset
;
474 fmt
.dxOffset
= -info
->rtfParam
;
477 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
478 fmt
.dwMask
= PFM_STARTINDENT
;
479 fmt
.dxStartIndent
= -fmt
.dxOffset
+ info
->rtfParam
;
482 fmt
.dwMask
= PFM_RIGHTINDENT
;
483 fmt
.dxRightIndent
= info
->rtfParam
;
487 fmt
.dwMask
= PFM_ALIGNMENT
;
488 fmt
.wAlignment
= PFA_LEFT
;
491 fmt
.dwMask
= PFM_ALIGNMENT
;
492 fmt
.wAlignment
= PFA_RIGHT
;
495 fmt
.dwMask
= PFM_ALIGNMENT
;
496 fmt
.wAlignment
= PFA_CENTER
;
499 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
500 if (!(fmt
.dwMask
& PFM_TABSTOPS
))
502 fmt
.dwMask
|= PFM_TABSTOPS
;
505 if (fmt
.cTabCount
< MAX_TAB_STOPS
)
506 fmt
.rgxTabs
[fmt
.cTabCount
++] = info
->rtfParam
;
510 RTFFlushOutputBuffer(info
);
511 /* FIXME too slow ? how come ?*/
512 ME_SetSelectionParaFormat(info
->editor
, &fmt
);
516 static void ME_RTFTblAttrHook(RTF_Info
*info
)
518 ME_DisplayItem
*para
;
520 switch (info
->rtfMinor
)
523 RTFFlushOutputBuffer(info
);
524 para
= ME_GetParagraph(info
->editor
->pCursors
[0].pRun
);
526 /* Release possibly inherited cell definitions */
527 ME_DestroyTableCellList(para
);
529 para
->member
.para
.pCells
= ALLOC_OBJ(ME_TableCell
);
530 para
->member
.para
.pCells
->nRightBoundary
= 0;
531 para
->member
.para
.pCells
->next
= NULL
;
532 para
->member
.para
.pLastCell
= para
->member
.para
.pCells
;
535 RTFFlushOutputBuffer(info
);
536 para
= ME_GetParagraph(info
->editor
->pCursors
[0].pRun
);
538 if (para
->member
.para
.pLastCell
->nRightBoundary
)
540 ME_TableCell
*pCell
= ALLOC_OBJ(ME_TableCell
);
543 para
->member
.para
.pLastCell
->next
= pCell
;
544 para
->member
.para
.pLastCell
= pCell
;
546 para
->member
.para
.pLastCell
->nRightBoundary
= info
->rtfParam
;
551 static void ME_RTFReadHook(RTF_Info
*info
) {
552 switch(info
->rtfClass
)
555 switch(info
->rtfMajor
)
558 if (info
->stackTop
< maxStack
) {
559 memcpy(&info
->stack
[info
->stackTop
].fmt
, &info
->style
->fmt
, sizeof(CHARFORMAT2W
));
560 info
->stack
[info
->stackTop
].codePage
= info
->codePage
;
561 info
->stack
[info
->stackTop
].unicodeLength
= info
->unicodeLength
;
564 info
->styleChanged
= FALSE
;
569 RTFFlushOutputBuffer(info
);
570 if (info
->stackTop
<=1) {
571 info
->rtfClass
= rtfEOF
;
575 assert(info
->stackTop
>= 0);
576 if (info
->styleChanged
)
578 /* FIXME too slow ? how come ? */
579 s
= ME_ApplyStyle(info
->style
, &info
->stack
[info
->stackTop
].fmt
);
580 ME_ReleaseStyle(info
->style
);
582 info
->codePage
= info
->stack
[info
->stackTop
].codePage
;
583 info
->unicodeLength
= info
->stack
[info
->stackTop
].unicodeLength
;
590 switch(info
->rtfMajor
)
593 ME_RTFCharAttrHook(info
);
596 ME_RTFParAttrHook(info
);
599 ME_RTFTblAttrHook(info
);
602 if (info
->rtfMinor
== rtfCell
)
604 RTFFlushOutputBuffer(info
);
605 ME_InsertTableCellFromCursor(info
->editor
, 0);
613 ME_StreamInFill(ME_InStream
*stream
)
615 stream
->editstream
->dwError
= stream
->editstream
->pfnCallback(stream
->editstream
->dwCookie
,
616 (BYTE
*)stream
->buffer
,
617 sizeof(stream
->buffer
),
618 (LONG
*)&stream
->dwSize
);
622 static LRESULT
ME_StreamIn(ME_TextEditor
*editor
, DWORD format
, EDITSTREAM
*stream
)
626 int from
, to
, to2
, nUndoMode
;
627 int nEventMask
= editor
->nEventMask
;
628 ME_InStream inStream
;
630 TRACE("stream==%p hWnd==%p format==0x%X\n", stream
, editor
->hWnd
, (UINT
)format
);
631 editor
->nEventMask
= 0;
633 ME_GetSelection(editor
, &from
, &to
);
634 if ((format
& SFF_SELECTION
) && (editor
->mode
& TM_RICHTEXT
)) {
635 style
= ME_GetSelectionInsertStyle(editor
);
637 ME_InternalDeleteText(editor
, from
, to
-from
);
640 style
= editor
->pBuffer
->pDefaultStyle
;
641 ME_AddRefStyle(style
);
642 SendMessageA(editor
->hWnd
, EM_SETSEL
, 0, 0);
643 ME_InternalDeleteText(editor
, 0, ME_GetTextLength(editor
));
645 ME_ClearTempStyle(editor
);
646 /* FIXME restore default paragraph formatting ! */
650 /* Back up undo mode to a local variable */
651 nUndoMode
= editor
->nUndoMode
;
653 /* Only create an undo if SFF_SELECTION is set */
654 if (!(format
& SFF_SELECTION
))
655 editor
->nUndoMode
= umIgnore
;
657 inStream
.editstream
= stream
;
658 inStream
.editstream
->dwError
= 0;
664 /* Check if it's really RTF, and if it is not, use plain text */
665 ME_StreamInFill(&inStream
);
666 if (!inStream
.editstream
->dwError
)
668 if (strncmp(inStream
.buffer
, "{\\rtf", 5) && strncmp(inStream
.buffer
, "{\\urtf", 6))
676 if (!inStream
.editstream
->dwError
)
678 if (format
& SF_RTF
) {
679 /* setup the RTF parser */
680 memset(&parser
, 0, sizeof parser
);
681 RTFSetEditStream(&parser
, &inStream
);
682 parser
.rtfFormat
= format
&(SF_TEXT
|SF_RTF
);
683 parser
.hwndEdit
= editor
->hWnd
;
684 parser
.editor
= editor
;
685 parser
.style
= style
;
688 RTFSetReadHook(&parser
, ME_RTFReadHook
);
693 RTFFlushOutputBuffer(&parser
);
696 style
= parser
.style
;
698 else if (format
& SF_TEXT
)
699 ME_StreamInText(editor
, format
, &inStream
, style
);
701 ERR("EM_STREAMIN without SF_TEXT or SF_RTF\n");
702 ME_GetSelection(editor
, &to
, &to2
);
703 /* put the cursor at the top */
704 if (!(format
& SFF_SELECTION
))
705 SendMessageA(editor
->hWnd
, EM_SETSEL
, 0, 0);
708 /* Restore saved undo mode */
709 editor
->nUndoMode
= nUndoMode
;
711 /* even if we didn't add an undo, we need to commit anything on the stack */
712 ME_CommitUndo(editor
);
714 /* If SFF_SELECTION isn't set, delete any undos from before we started too */
715 if (!(format
& SFF_SELECTION
))
716 ME_EmptyUndoStack(editor
);
718 ME_ReleaseStyle(style
);
719 editor
->nEventMask
= nEventMask
;
722 ME_UpdateRepaint(editor
);
724 if (!(format
& SFF_SELECTION
)) {
725 ME_ClearTempStyle(editor
);
727 ME_MoveCaret(editor
);
728 ME_SendSelChange(editor
);
729 ME_SendRequestResize(editor
, FALSE
);
735 typedef struct tagME_RTFStringStreamStruct
740 } ME_RTFStringStreamStruct
;
742 static DWORD CALLBACK
ME_ReadFromRTFString(DWORD_PTR dwCookie
, LPBYTE lpBuff
, LONG cb
, LONG
*pcb
)
744 ME_RTFStringStreamStruct
*pStruct
= (ME_RTFStringStreamStruct
*)dwCookie
;
747 count
= min(cb
, pStruct
->length
- pStruct
->pos
);
748 memmove(lpBuff
, pStruct
->string
+ pStruct
->pos
, count
);
749 pStruct
->pos
+= count
;
755 ME_StreamInRTFString(ME_TextEditor
*editor
, BOOL selection
, char *string
)
758 ME_RTFStringStreamStruct data
;
760 data
.string
= string
;
761 data
.length
= strlen(string
);
763 es
.dwCookie
= (DWORD
)&data
;
764 es
.pfnCallback
= ME_ReadFromRTFString
;
765 ME_StreamIn(editor
, SF_RTF
| (selection
? SFF_SELECTION
: 0), &es
);
770 ME_FindItemAtOffset(ME_TextEditor
*editor
, ME_DIType nItemType
, int nOffset
, int *nItemOffset
)
772 ME_DisplayItem
*item
= ME_FindItemFwd(editor
->pBuffer
->pFirst
, diParagraph
);
774 while (item
&& item
->member
.para
.next_para
->member
.para
.nCharOfs
<= nOffset
)
775 item
= ME_FindItemFwd(item
, diParagraph
);
780 nOffset
-= item
->member
.para
.nCharOfs
;
781 if (nItemType
== diParagraph
) {
783 *nItemOffset
= nOffset
;
788 item
= ME_FindItemFwd(item
, diRun
);
789 } while (item
&& (item
->member
.run
.nCharOfs
+ ME_StrLen(item
->member
.run
.strText
) <= nOffset
));
791 nOffset
-= item
->member
.run
.nCharOfs
;
793 *nItemOffset
= nOffset
;
800 ME_FindText(ME_TextEditor
*editor
, DWORD flags
, const CHARRANGE
*chrg
, const WCHAR
*text
, CHARRANGE
*chrgText
)
802 const int nLen
= lstrlenW(text
);
803 const int nTextLen
= ME_GetTextLength(editor
);
806 ME_DisplayItem
*item
;
807 ME_DisplayItem
*para
;
808 WCHAR wLastChar
= ' ';
810 TRACE("flags==0x%08x, chrg->cpMin==%d, chrg->cpMax==%d text==%s\n",
811 flags
, chrg
->cpMin
, chrg
->cpMax
, debugstr_w(text
));
813 if (flags
& ~(FR_DOWN
| FR_MATCHCASE
| FR_WHOLEWORD
))
814 FIXME("Flags 0x%08x not implemented\n",
815 flags
& ~(FR_DOWN
| FR_MATCHCASE
| FR_WHOLEWORD
));
818 if (chrg
->cpMax
== -1)
821 nMax
= chrg
->cpMax
> nTextLen
? nTextLen
: chrg
->cpMax
;
823 /* when searching up, if cpMin < cpMax, then instead of searching
824 * on [cpMin,cpMax], we search on [0,cpMin], otherwise, search on
825 * [cpMax, cpMin]. The exception is when cpMax is -1, in which
826 * case, it is always bigger than cpMin.
828 if (!(flags
& FR_DOWN
))
832 nMax
= nMin
> nTextLen
? nTextLen
: nMin
;
833 if (nMin
< nSwap
|| chrg
->cpMax
== -1)
839 if (!nLen
|| nMin
< 0 || nMax
< 0 || nMax
< nMin
)
842 chrgText
->cpMin
= chrgText
->cpMax
= -1;
846 if (flags
& FR_DOWN
) /* Forward search */
848 /* If possible, find the character before where the search starts */
849 if ((flags
& FR_WHOLEWORD
) && nMin
)
852 item
= ME_FindItemAtOffset(editor
, diRun
, nStart
, &nStart
);
856 chrgText
->cpMin
= chrgText
->cpMax
= -1;
859 wLastChar
= item
->member
.run
.strText
->szData
[nStart
];
863 item
= ME_FindItemAtOffset(editor
, diRun
, nStart
, &nStart
);
867 chrgText
->cpMin
= chrgText
->cpMax
= -1;
871 para
= ME_GetParagraph(item
);
873 && para
->member
.para
.nCharOfs
+ item
->member
.run
.nCharOfs
+ nStart
+ nLen
<= nMax
)
875 ME_DisplayItem
*pCurItem
= item
;
876 int nCurStart
= nStart
;
879 while (pCurItem
&& ME_CharCompare(pCurItem
->member
.run
.strText
->szData
[nCurStart
+ nMatched
], text
[nMatched
], (flags
& FR_MATCHCASE
)))
881 if ((flags
& FR_WHOLEWORD
) && isalnumW(wLastChar
))
885 if (nMatched
== nLen
)
887 ME_DisplayItem
*pNextItem
= pCurItem
;
888 int nNextStart
= nCurStart
;
891 /* Check to see if next character is a whitespace */
892 if (flags
& FR_WHOLEWORD
)
894 if (nCurStart
+ nMatched
== ME_StrLen(pCurItem
->member
.run
.strText
))
896 pNextItem
= ME_FindItemFwd(pCurItem
, diRun
);
897 nNextStart
= -nMatched
;
901 wNextChar
= pNextItem
->member
.run
.strText
->szData
[nNextStart
+ nMatched
];
905 if (isalnumW(wNextChar
))
909 nStart
+= para
->member
.para
.nCharOfs
+ pCurItem
->member
.run
.nCharOfs
;
912 chrgText
->cpMin
= nStart
;
913 chrgText
->cpMax
= nStart
+ nLen
;
915 TRACE("found at %d-%d\n", nStart
, nStart
+ nLen
);
918 if (nCurStart
+ nMatched
== ME_StrLen(pCurItem
->member
.run
.strText
))
920 pCurItem
= ME_FindItemFwd(pCurItem
, diRun
);
921 para
= ME_GetParagraph(pCurItem
);
922 nCurStart
= -nMatched
;
926 wLastChar
= pCurItem
->member
.run
.strText
->szData
[nCurStart
+ nMatched
];
931 if (nStart
== ME_StrLen(item
->member
.run
.strText
))
933 item
= ME_FindItemFwd(item
, diRun
);
934 para
= ME_GetParagraph(item
);
939 else /* Backward search */
941 /* If possible, find the character after where the search ends */
942 if ((flags
& FR_WHOLEWORD
) && nMax
< nTextLen
- 1)
945 item
= ME_FindItemAtOffset(editor
, diRun
, nEnd
, &nEnd
);
949 chrgText
->cpMin
= chrgText
->cpMax
= -1;
952 wLastChar
= item
->member
.run
.strText
->szData
[nEnd
];
956 item
= ME_FindItemAtOffset(editor
, diRun
, nEnd
, &nEnd
);
960 chrgText
->cpMin
= chrgText
->cpMax
= -1;
964 para
= ME_GetParagraph(item
);
967 && para
->member
.para
.nCharOfs
+ item
->member
.run
.nCharOfs
+ nEnd
- nLen
>= nMin
)
969 ME_DisplayItem
*pCurItem
= item
;
973 if (nCurEnd
- nMatched
== 0)
975 pCurItem
= ME_FindItemBack(pCurItem
, diRun
);
976 para
= ME_GetParagraph(pCurItem
);
977 nCurEnd
= ME_StrLen(pCurItem
->member
.run
.strText
) + nMatched
;
980 while (pCurItem
&& ME_CharCompare(pCurItem
->member
.run
.strText
->szData
[nCurEnd
- nMatched
- 1], text
[nLen
- nMatched
- 1], (flags
& FR_MATCHCASE
)))
982 if ((flags
& FR_WHOLEWORD
) && isalnumW(wLastChar
))
986 if (nMatched
== nLen
)
988 ME_DisplayItem
*pPrevItem
= pCurItem
;
989 int nPrevEnd
= nCurEnd
;
992 /* Check to see if previous character is a whitespace */
993 if (flags
& FR_WHOLEWORD
)
995 if (nPrevEnd
- nMatched
== 0)
997 pPrevItem
= ME_FindItemBack(pCurItem
, diRun
);
999 nPrevEnd
= ME_StrLen(pPrevItem
->member
.run
.strText
) + nMatched
;
1003 wPrevChar
= pPrevItem
->member
.run
.strText
->szData
[nPrevEnd
- nMatched
- 1];
1007 if (isalnumW(wPrevChar
))
1011 nStart
= para
->member
.para
.nCharOfs
+ pCurItem
->member
.run
.nCharOfs
+ nCurEnd
- nMatched
;
1014 chrgText
->cpMin
= nStart
;
1015 chrgText
->cpMax
= nStart
+ nLen
;
1017 TRACE("found at %d-%d\n", nStart
, nStart
+ nLen
);
1020 if (nCurEnd
- nMatched
== 0)
1022 pCurItem
= ME_FindItemBack(pCurItem
, diRun
);
1023 /* Don't care about pCurItem becoming NULL here; it's already taken
1024 * care of in the exterior loop condition */
1025 para
= ME_GetParagraph(pCurItem
);
1026 nCurEnd
= ME_StrLen(pCurItem
->member
.run
.strText
) + nMatched
;
1030 wLastChar
= pCurItem
->member
.run
.strText
->szData
[nCurEnd
- nMatched
- 1];
1037 item
= ME_FindItemBack(item
, diRun
);
1038 para
= ME_GetParagraph(item
);
1039 nEnd
= ME_StrLen(item
->member
.run
.strText
);
1043 TRACE("not found\n");
1045 chrgText
->cpMin
= chrgText
->cpMax
= -1;
1049 /* helper to send a msg filter notification */
1051 ME_FilterEvent(ME_TextEditor
*editor
, UINT msg
, WPARAM
* wParam
, LPARAM
* lParam
)
1055 msgf
.nmhdr
.hwndFrom
= editor
->hWnd
;
1056 msgf
.nmhdr
.idFrom
= GetWindowLongW(editor
->hWnd
, GWLP_ID
);
1057 msgf
.nmhdr
.code
= EN_MSGFILTER
;
1060 msgf
.wParam
= *wParam
;
1061 msgf
.lParam
= *lParam
;
1062 if (SendMessageW(GetParent(editor
->hWnd
), WM_NOTIFY
, msgf
.nmhdr
.idFrom
, (LPARAM
)&msgf
))
1064 *wParam
= msgf
.wParam
;
1065 *lParam
= msgf
.lParam
;
1066 msgf
.wParam
= *wParam
;
1072 ME_KeyDown(ME_TextEditor
*editor
, WORD nKey
)
1074 BOOL ctrl_is_down
= GetKeyState(VK_CONTROL
) & 0x8000;
1075 BOOL shift_is_down
= GetKeyState(VK_SHIFT
) & 0x8000;
1087 ME_ArrowKey(editor
, nKey
, shift_is_down
, ctrl_is_down
);
1091 /* FIXME backspace and delete aren't the same, they act different wrt paragraph style of the merged paragraph */
1092 if (GetWindowLongW(editor
->hWnd
, GWL_STYLE
) & ES_READONLY
)
1094 if (ME_IsSelection(editor
))
1095 ME_DeleteSelection(editor
);
1096 else if (nKey
== VK_DELETE
|| ME_ArrowKey(editor
, VK_LEFT
, FALSE
, FALSE
))
1097 ME_DeleteTextAtCursor(editor
, 1, 1);
1100 ME_CommitUndo(editor
);
1101 ME_UpdateRepaint(editor
);
1102 ME_SendRequestResize(editor
, FALSE
);
1112 chf
.cbSize
= sizeof(chf
);
1114 ME_GetSelectionCharFormat(editor
, &chf
);
1115 ME_DumpStyleToBuf(&chf
, buf
);
1116 MessageBoxA(NULL
, buf
, "Style dump", MB_OK
);
1120 ME_CheckCharOffsets(editor
);
1127 static void ME_SetCursor(ME_TextEditor
*editor
, int x
)
1129 if (x
< editor
->selofs
|| editor
->linesel
)
1135 static BOOL
ME_ShowContextMenu(ME_TextEditor
*editor
, int x
, int y
)
1140 if(!editor
->lpOleCallback
)
1142 ME_GetSelection(editor
, (int *)&selrange
.cpMin
, (int *)&selrange
.cpMax
);
1143 if(selrange
.cpMin
== selrange
.cpMax
)
1144 seltype
|= SEL_EMPTY
;
1147 /* FIXME: Handle objects */
1148 seltype
|= SEL_TEXT
;
1149 if(selrange
.cpMax
-selrange
.cpMin
> 1)
1150 seltype
|= SEL_MULTICHAR
;
1152 if(SUCCEEDED(IRichEditOleCallback_GetContextMenu(editor
->lpOleCallback
, seltype
, NULL
, &selrange
, &menu
)))
1154 TrackPopupMenu(menu
, TPM_LEFTALIGN
| TPM_RIGHTBUTTON
, x
, y
, 0, GetParent(editor
->hWnd
), NULL
);
1160 ME_TextEditor
*ME_MakeEditor(HWND hWnd
) {
1161 ME_TextEditor
*ed
= ALLOC_OBJ(ME_TextEditor
);
1165 ed
->bEmulateVersion10
= FALSE
;
1166 ed
->pBuffer
= ME_MakeText();
1168 ME_MakeFirstParagraph(hDC
, ed
->pBuffer
);
1169 ReleaseDC(hWnd
, hDC
);
1170 ed
->bCaretShown
= FALSE
;
1172 ed
->pCursors
= ALLOC_N_OBJ(ME_Cursor
, ed
->nCursors
);
1173 ed
->pCursors
[0].pRun
= ME_FindItemFwd(ed
->pBuffer
->pFirst
, diRun
);
1174 ed
->pCursors
[0].nOffset
= 0;
1175 ed
->pCursors
[1].pRun
= ME_FindItemFwd(ed
->pBuffer
->pFirst
, diRun
);
1176 ed
->pCursors
[1].nOffset
= 0;
1177 ed
->nLastTotalLength
= ed
->nTotalLength
= 0;
1181 ed
->rgbBackColor
= -1;
1182 ed
->hbrBackground
= GetSysColorBrush(COLOR_WINDOW
);
1183 ed
->bCaretAtEnd
= FALSE
;
1185 ed
->nModifyStep
= 0;
1186 ed
->nTextLimit
= TEXT_LIMIT_DEFAULT
;
1187 ed
->pUndoStack
= ed
->pRedoStack
= ed
->pUndoStackBottom
= NULL
;
1188 ed
->nUndoStackSize
= 0;
1189 ed
->nUndoLimit
= STACK_SIZE_DEFAULT
;
1190 ed
->nUndoMode
= umAddToUndo
;
1191 ed
->nParagraphs
= 1;
1192 ed
->nLastSelStart
= ed
->nLastSelEnd
= 0;
1193 ed
->pLastSelStartPara
= ed
->pLastSelEndPara
= ME_FindItemFwd(ed
->pBuffer
->pFirst
, diParagraph
);
1194 ed
->nZoomNumerator
= ed
->nZoomDenominator
= 0;
1196 ed
->bHideSelection
= FALSE
;
1197 ed
->nInvalidOfs
= -1;
1198 ed
->pfnWordBreak
= NULL
;
1199 ed
->lpOleCallback
= NULL
;
1200 ed
->mode
= TM_RICHTEXT
| TM_MULTILEVELUNDO
| TM_MULTICODEPAGE
;
1201 ed
->AutoURLDetect_bEnable
= FALSE
;
1202 ed
->bHaveFocus
= FALSE
;
1203 GetClientRect(hWnd
, &ed
->rcFormat
);
1204 for (i
=0; i
<HFONT_CACHE_SIZE
; i
++)
1206 ed
->pFontCache
[i
].nRefs
= 0;
1207 ed
->pFontCache
[i
].nAge
= 0;
1208 ed
->pFontCache
[i
].hFont
= NULL
;
1211 ME_CheckCharOffsets(ed
);
1212 if (GetWindowLongW(hWnd
, GWL_STYLE
) & ES_SELECTIONBAR
)
1218 if (GetWindowLongW(hWnd
, GWL_STYLE
) & ES_PASSWORD
)
1219 ed
->cPasswordMask
= '*';
1221 ed
->cPasswordMask
= 0;
1226 typedef struct tagME_GlobalDestStruct
1230 } ME_GlobalDestStruct
;
1232 static DWORD CALLBACK
ME_ReadFromHGLOBALUnicode(DWORD_PTR dwCookie
, LPBYTE lpBuff
, LONG cb
, LONG
*pcb
)
1234 ME_GlobalDestStruct
*pData
= (ME_GlobalDestStruct
*)dwCookie
;
1239 pDest
= (WORD
*)lpBuff
;
1240 pSrc
= (WORD
*)GlobalLock(pData
->hData
);
1241 for (i
= 0; i
<cb
&& pSrc
[pData
->nLength
+i
]; i
++) {
1242 pDest
[i
] = pSrc
[pData
->nLength
+i
];
1244 pData
->nLength
+= i
;
1246 GlobalUnlock(pData
->hData
);
1250 static DWORD CALLBACK
ME_ReadFromHGLOBALRTF(DWORD_PTR dwCookie
, LPBYTE lpBuff
, LONG cb
, LONG
*pcb
)
1252 ME_GlobalDestStruct
*pData
= (ME_GlobalDestStruct
*)dwCookie
;
1257 pSrc
= (BYTE
*)GlobalLock(pData
->hData
);
1258 for (i
= 0; i
<cb
&& pSrc
[pData
->nLength
+i
]; i
++) {
1259 pDest
[i
] = pSrc
[pData
->nLength
+i
];
1261 pData
->nLength
+= i
;
1263 GlobalUnlock(pData
->hData
);
1268 void ME_DestroyEditor(ME_TextEditor
*editor
)
1270 ME_DisplayItem
*pFirst
= editor
->pBuffer
->pFirst
;
1271 ME_DisplayItem
*p
= pFirst
, *pNext
= NULL
;
1274 ME_ClearTempStyle(editor
);
1275 ME_EmptyUndoStack(editor
);
1278 ME_DestroyDisplayItem(p
);
1281 ME_ReleaseStyle(editor
->pBuffer
->pDefaultStyle
);
1282 for (i
=0; i
<HFONT_CACHE_SIZE
; i
++)
1284 if (editor
->pFontCache
[i
].hFont
)
1285 DeleteObject(editor
->pFontCache
[i
].hFont
);
1287 if (editor
->rgbBackColor
!= -1)
1288 DeleteObject(editor
->hbrBackground
);
1289 if(editor
->lpOleCallback
)
1290 IUnknown_Release(editor
->lpOleCallback
);
1292 FREE_OBJ(editor
->pBuffer
);
1293 FREE_OBJ(editor
->pCursors
);
1298 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
1303 case DLL_PROCESS_ATTACH
:
1304 DisableThreadLibraryCalls(hinstDLL
);
1305 me_heap
= HeapCreate (0, 0x10000, 0);
1306 if (!ME_RegisterEditorClass(hinstDLL
)) return FALSE
;
1307 hLeft
= LoadCursorW(hinstDLL
, MAKEINTRESOURCEW(OCR_REVERSE
));
1308 hBeam
= LoadCursorW(NULL
, MAKEINTRESOURCEW(IDC_IBEAM
));
1312 case DLL_PROCESS_DETACH
:
1313 UnregisterClassW(RichEdit20W
, 0);
1314 UnregisterClassW(RichEdit50W
, 0);
1315 UnregisterClassA("RichEdit20A", 0);
1316 UnregisterClassA("RichEdit50A", 0);
1317 if (ME_ListBoxRegistered
)
1318 UnregisterClassW(REListBox20W
, 0);
1319 if (ME_ComboBoxRegistered
)
1320 UnregisterClassW(REComboBox20W
, 0);
1322 HeapDestroy (me_heap
);
1330 #define UNSUPPORTED_MSG(e) \
1332 FIXME(#e ": stub\n"); \
1333 return DefWindowProcW(hWnd, msg, wParam, lParam);
1335 static const char * const edit_messages
[] = {
1364 "EM_SETPASSWORDCHAR",
1365 "EM_EMPTYUNDOBUFFER",
1366 "EM_GETFIRSTVISIBLELINE",
1368 "EM_SETWORDBREAKPROC",
1369 "EM_GETWORDBREAKPROC",
1370 "EM_GETPASSWORDCHAR",
1378 static const char * const richedit_messages
[] = {
1383 "EM_EXLINEFROMCHAR",
1389 "EM_GETOLEINTERFACE",
1399 "EM_SETOLECALLBACK",
1401 "EM_SETTARGETDEVICE",
1409 "EM_GETWORDBREAKPROCEX",
1410 "EM_SETWORDBREAKPROCEX",
1412 "EM_UNKNOWN_USER_83",
1417 "EM_STOPGROUPTYPING",
1421 "EM_GETAUTOURLDETECT",
1424 "EM_GETTEXTLENGTHEX",
1427 "EM_UNKNOWN_USER_98",
1428 "EM_UNKNOWN_USER_99",
1429 "EM_SETPUNCTUATION",
1430 "EM_GETPUNCTUATION",
1431 "EM_SETWORDWRAPMODE",
1432 "EM_GETWORDWRAPMODE",
1438 "EM_UNKNOWN_USER_109",
1439 "EM_UNKNOWN_USER_110",
1440 "EM_UNKNOWN_USER_111",
1441 "EM_UNKNOWN_USER_112",
1442 "EM_UNKNOWN_USER_113",
1443 "EM_UNKNOWN_USER_114",
1444 "EM_UNKNOWN_USER_115",
1445 "EM_UNKNOWN_USER_116",
1446 "EM_UNKNOWN_USER_117",
1447 "EM_UNKNOWN_USER_118",
1448 "EM_UNKNOWN_USER_119",
1449 "EM_SETLANGOPTIONS",
1450 "EM_GETLANGOPTIONS",
1451 "EM_GETIMECOMPMODE",
1455 "EM_SETIMEMODEBIAS",
1460 get_msg_name(UINT msg
)
1462 if (msg
>= EM_GETSEL
&& msg
<= EM_CHARFROMPOS
)
1463 return edit_messages
[msg
- EM_GETSEL
];
1464 if (msg
>= EM_CANPASTE
&& msg
<= EM_GETIMEMODEBIAS
)
1465 return richedit_messages
[msg
- EM_CANPASTE
];
1469 static LRESULT
RichEditWndProc_common(HWND hWnd
, UINT msg
, WPARAM wParam
,
1470 LPARAM lParam
, BOOL unicode
)
1472 ME_TextEditor
*editor
= (ME_TextEditor
*)GetWindowLongPtrW(hWnd
, 0);
1474 TRACE("hwnd %p msg %04x (%s) %lx %lx, unicode %d\n",
1475 hWnd
, msg
, get_msg_name(msg
), wParam
, lParam
, unicode
);
1477 if (!editor
&& msg
!= WM_NCCREATE
&& msg
!= WM_NCDESTROY
) {
1478 ERR("called with invalid hWnd %p - application bug?\n", hWnd
);
1484 UNSUPPORTED_MSG(EM_DISPLAYBAND
)
1485 UNSUPPORTED_MSG(EM_FINDWORDBREAK
)
1486 UNSUPPORTED_MSG(EM_FMTLINES
)
1487 UNSUPPORTED_MSG(EM_FORMATRANGE
)
1488 UNSUPPORTED_MSG(EM_GETBIDIOPTIONS
)
1489 UNSUPPORTED_MSG(EM_GETEDITSTYLE
)
1490 UNSUPPORTED_MSG(EM_GETIMECOMPMODE
)
1491 /* UNSUPPORTED_MSG(EM_GETIMESTATUS) missing in Wine headers */
1492 UNSUPPORTED_MSG(EM_GETLANGOPTIONS
)
1493 /* UNSUPPORTED_MSG(EM_GETOLEINTERFACE) separate stub */
1494 UNSUPPORTED_MSG(EM_GETREDONAME
)
1495 UNSUPPORTED_MSG(EM_GETTEXTMODE
)
1496 UNSUPPORTED_MSG(EM_GETTYPOGRAPHYOPTIONS
)
1497 UNSUPPORTED_MSG(EM_GETUNDONAME
)
1498 UNSUPPORTED_MSG(EM_GETWORDBREAKPROCEX
)
1499 UNSUPPORTED_MSG(EM_PASTESPECIAL
)
1500 UNSUPPORTED_MSG(EM_SELECTIONTYPE
)
1501 UNSUPPORTED_MSG(EM_SETBIDIOPTIONS
)
1502 UNSUPPORTED_MSG(EM_SETEDITSTYLE
)
1503 UNSUPPORTED_MSG(EM_SETFONTSIZE
)
1504 UNSUPPORTED_MSG(EM_SETLANGOPTIONS
)
1505 UNSUPPORTED_MSG(EM_SETPALETTE
)
1506 UNSUPPORTED_MSG(EM_SETTABSTOPS
)
1507 UNSUPPORTED_MSG(EM_SETTARGETDEVICE
)
1508 UNSUPPORTED_MSG(EM_SETTYPOGRAPHYOPTIONS
)
1509 UNSUPPORTED_MSG(EM_SETWORDBREAKPROCEX
)
1510 UNSUPPORTED_MSG(WM_STYLECHANGING
)
1511 UNSUPPORTED_MSG(WM_STYLECHANGED
)
1512 /* UNSUPPORTED_MSG(WM_UNICHAR) FIXME missing in Wine headers */
1514 /* Messages specific to Richedit controls */
1517 return ME_StreamIn(editor
, wParam
, (EDITSTREAM
*)lParam
);
1519 return ME_StreamOut(editor
, wParam
, (EDITSTREAM
*)lParam
);
1522 UINT code
= DLGC_WANTCHARS
|DLGC_WANTARROWS
;
1523 if(lParam
&& (((LPMSG
)lParam
)->message
== WM_KEYDOWN
))
1525 int vk
= (int)((LPMSG
)lParam
)->wParam
;
1526 /* if style says we want return key */
1527 if((vk
== VK_RETURN
) && (GetWindowLongW(hWnd
, GWL_STYLE
) & ES_WANTRETURN
))
1529 code
|= DLGC_WANTMESSAGE
;
1531 /* we always handle ctrl-tab */
1532 if((vk
== VK_TAB
) && (GetKeyState(VK_CONTROL
) & 0x8000))
1534 code
|= DLGC_WANTMESSAGE
;
1541 CREATESTRUCTW
*pcs
= (CREATESTRUCTW
*)lParam
;
1542 TRACE("WM_NCCREATE: style 0x%08x\n", pcs
->style
);
1543 editor
= ME_MakeEditor(hWnd
);
1544 SetWindowLongPtrW(hWnd
, 0, (LONG_PTR
)editor
);
1547 case EM_EMPTYUNDOBUFFER
:
1548 ME_EmptyUndoStack(editor
);
1552 /* Note: wParam/lParam can be NULL */
1554 PUINT pfrom
= wParam
? (PUINT
)wParam
: &from
;
1555 PUINT pto
= lParam
? (PUINT
)lParam
: &to
;
1556 ME_GetSelection(editor
, (int *)pfrom
, (int *)pto
);
1557 if ((*pfrom
|*pto
) & 0xFFFF0000)
1559 return MAKELONG(*pfrom
,*pto
);
1563 CHARRANGE
*pRange
= (CHARRANGE
*)lParam
;
1564 ME_GetSelection(editor
, (int *)&pRange
->cpMin
, (int *)&pRange
->cpMax
);
1565 TRACE("EM_EXGETSEL = (%d,%d)\n", pRange
->cpMin
, pRange
->cpMax
);
1568 case EM_SETUNDOLIMIT
:
1570 if ((int)wParam
< 0)
1571 editor
->nUndoLimit
= STACK_SIZE_DEFAULT
;
1573 editor
->nUndoLimit
= min(wParam
, STACK_SIZE_MAX
);
1574 /* Setting a max stack size keeps wine from getting killed
1575 for hogging memory. Windows allocates all this memory at once, so
1576 no program would realistically set a value above our maximum. */
1577 return editor
->nUndoLimit
;
1580 return editor
->pUndoStack
!= NULL
;
1582 return editor
->pRedoStack
!= NULL
;
1583 case WM_UNDO
: /* FIXME: actually not the same */
1592 /* these flags are equivalent to the ES_* counterparts */
1593 DWORD mask
= ECO_VERTICAL
| ECO_AUTOHSCROLL
| ECO_AUTOVSCROLL
|
1594 ECO_NOHIDESEL
| ECO_READONLY
| ECO_WANTRETURN
;
1595 DWORD settings
= GetWindowLongW(hWnd
, GWL_STYLE
) & mask
;
1601 /* these flags are equivalent to ES_* counterparts
1602 * ECO_READONLY is already implemented in the code, only requires
1603 * setting the bit to work
1605 DWORD mask
= ECO_VERTICAL
| ECO_AUTOHSCROLL
| ECO_AUTOVSCROLL
|
1606 ECO_NOHIDESEL
| ECO_READONLY
| ECO_WANTRETURN
| ECO_SELECTIONBAR
;
1607 DWORD raw
= GetWindowLongW(hWnd
, GWL_STYLE
);
1608 DWORD settings
= mask
& raw
;
1624 SetWindowLongW(hWnd
, GWL_STYLE
, (raw
& ~mask
) | (settings
& mask
));
1626 if (settings
& ECO_AUTOWORDSELECTION
)
1627 FIXME("ECO_AUTOWORDSELECTION not implemented yet!\n");
1628 if (settings
& ECO_SELECTIONBAR
)
1629 editor
->selofs
= 16;
1632 ME_WrapMarkedParagraphs(editor
);
1634 if (settings
& ECO_VERTICAL
)
1635 FIXME("ECO_VERTICAL not implemented yet!\n");
1636 if (settings
& ECO_AUTOHSCROLL
)
1637 FIXME("ECO_AUTOHSCROLL not implemented yet!\n");
1638 if (settings
& ECO_AUTOVSCROLL
)
1639 FIXME("ECO_AUTOVSCROLL not implemented yet!\n");
1640 if (settings
& ECO_NOHIDESEL
)
1641 FIXME("ECO_NOHIDESEL not implemented yet!\n");
1642 if (settings
& ECO_WANTRETURN
)
1643 FIXME("ECO_WANTRETURN not implemented yet!\n");
1649 ME_InvalidateSelection(editor
);
1650 ME_SetSelection(editor
, wParam
, lParam
);
1651 ME_InvalidateSelection(editor
);
1652 ME_SendSelChange(editor
);
1655 case EM_SETSCROLLPOS
:
1657 POINT
*point
= (POINT
*)lParam
;
1658 ME_ScrollAbs(editor
, point
->y
);
1661 case EM_AUTOURLDETECT
:
1663 if (wParam
==1 || wParam
==0)
1665 editor
->AutoURLDetect_bEnable
= (BOOL
)wParam
;
1668 return E_INVALIDARG
;
1670 case EM_GETAUTOURLDETECT
:
1672 return editor
->AutoURLDetect_bEnable
;
1677 CHARRANGE range
= *(CHARRANGE
*)lParam
;
1679 TRACE("EM_EXSETSEL (%d,%d)\n", range
.cpMin
, range
.cpMax
);
1681 ME_InvalidateSelection(editor
);
1682 end
= ME_SetSelection(editor
, range
.cpMin
, range
.cpMax
);
1683 ME_InvalidateSelection(editor
);
1684 ME_SendSelChange(editor
);
1688 case EM_SHOWSCROLLBAR
:
1690 ShowScrollBar(editor
->hWnd
, wParam
, lParam
);
1696 SETTEXTEX
*pStruct
= (SETTEXTEX
*)wParam
;
1700 int oldModify
= editor
->nModifyStep
;
1702 if (!pStruct
) return 0;
1704 TRACE("EM_SETTEXTEX - %s, flags %d, cp %d\n",
1705 pStruct
->codepage
== 1200 ? debugstr_w((LPCWSTR
)lParam
) : debugstr_a((LPCSTR
)lParam
),
1706 pStruct
->flags
, pStruct
->codepage
);
1708 /* FIXME: make use of pStruct->codepage in the to unicode translation */
1709 wszText
= lParam
? ME_ToUnicode(pStruct
->codepage
== 1200, (void *)lParam
) : NULL
;
1710 len
= wszText
? lstrlenW(wszText
) : 0;
1712 /* FIXME: this should support RTF strings too, according to MSDN */
1713 if (pStruct
->flags
& ST_SELECTION
) {
1714 ME_GetSelection(editor
, &from
, &to
);
1715 style
= ME_GetSelectionInsertStyle(editor
);
1716 ME_InternalDeleteText(editor
, from
, to
- from
);
1717 ME_InsertTextFromCursor(editor
, 0, wszText
, len
, style
);
1718 ME_ReleaseStyle(style
);
1721 ME_InternalDeleteText(editor
, 0, ME_GetTextLength(editor
));
1722 ME_InsertTextFromCursor(editor
, 0, wszText
, len
, editor
->pBuffer
->pDefaultStyle
);
1725 ME_CommitUndo(editor
);
1726 if (!(pStruct
->flags
& ST_KEEPUNDO
))
1728 editor
->nModifyStep
= oldModify
;
1729 ME_EmptyUndoStack(editor
);
1731 ME_UpdateRepaint(editor
);
1734 case EM_SETBKGNDCOLOR
:
1737 if (editor
->rgbBackColor
!= -1) {
1738 DeleteObject(editor
->hbrBackground
);
1739 lColor
= editor
->rgbBackColor
;
1741 else lColor
= GetSysColor(COLOR_WINDOW
);
1745 editor
->rgbBackColor
= -1;
1746 editor
->hbrBackground
= GetSysColorBrush(COLOR_WINDOW
);
1750 editor
->rgbBackColor
= lParam
;
1751 editor
->hbrBackground
= CreateSolidBrush(editor
->rgbBackColor
);
1753 if (editor
->bRedraw
)
1755 InvalidateRect(hWnd
, NULL
, TRUE
);
1761 return editor
->nModifyStep
== 0 ? 0 : 1;
1765 editor
->nModifyStep
= 1;
1767 editor
->nModifyStep
= 0;
1771 case EM_SETREADONLY
:
1773 long nStyle
= GetWindowLongW(hWnd
, GWL_STYLE
);
1775 nStyle
|= ES_READONLY
;
1777 nStyle
&= ~ES_READONLY
;
1778 SetWindowLongW(hWnd
, GWL_STYLE
, nStyle
);
1781 case EM_SETEVENTMASK
:
1783 DWORD nOldMask
= editor
->nEventMask
;
1785 editor
->nEventMask
= lParam
;
1788 case EM_GETEVENTMASK
:
1789 return editor
->nEventMask
;
1790 case EM_SETCHARFORMAT
:
1792 CHARFORMAT2W buf
, *p
;
1793 BOOL bRepaint
= TRUE
;
1794 p
= ME_ToCF2W(&buf
, (CHARFORMAT2W
*)lParam
);
1795 if (p
== NULL
) return 0;
1797 ME_SetDefaultCharFormat(editor
, p
);
1798 else if (wParam
== (SCF_WORD
| SCF_SELECTION
)) {
1799 FIXME("EM_SETCHARFORMAT: word selection not supported\n");
1801 } else if (wParam
== SCF_ALL
) {
1802 if (editor
->mode
& TM_PLAINTEXT
)
1803 ME_SetDefaultCharFormat(editor
, p
);
1805 ME_SetCharFormat(editor
, 0, ME_GetTextLength(editor
), p
);
1806 } else if (editor
->mode
& TM_PLAINTEXT
) {
1810 ME_GetSelection(editor
, &from
, &to
);
1811 bRepaint
= (from
!= to
);
1812 ME_SetSelectionCharFormat(editor
, p
);
1814 editor
->nModifyStep
= 1;
1815 ME_CommitUndo(editor
);
1817 ME_RewrapRepaint(editor
);
1820 case EM_GETCHARFORMAT
:
1822 CHARFORMAT2W tmp
, *dst
= (CHARFORMAT2W
*)lParam
;
1823 if (dst
->cbSize
!= sizeof(CHARFORMATA
) &&
1824 dst
->cbSize
!= sizeof(CHARFORMATW
) &&
1825 dst
->cbSize
!= sizeof(CHARFORMAT2A
) &&
1826 dst
->cbSize
!= sizeof(CHARFORMAT2W
))
1828 tmp
.cbSize
= sizeof(tmp
);
1830 ME_GetDefaultCharFormat(editor
, &tmp
);
1832 ME_GetSelectionCharFormat(editor
, &tmp
);
1833 ME_CopyToCFAny(dst
, &tmp
);
1836 case EM_SETPARAFORMAT
:
1837 ME_SetSelectionParaFormat(editor
, (PARAFORMAT2
*)lParam
);
1838 ME_RewrapRepaint(editor
);
1839 ME_CommitUndo(editor
);
1841 case EM_GETPARAFORMAT
:
1842 ME_GetSelectionParaFormat(editor
, (PARAFORMAT2
*)lParam
);
1844 case EM_GETFIRSTVISIBLELINE
:
1846 ME_DisplayItem
*p
= editor
->pBuffer
->pFirst
;
1847 int y
= ME_GetYScrollPos(editor
);
1852 p
= ME_FindItemFwd(p
, diStartRowOrParagraphOrEnd
);
1853 if (p
->type
== diTextEnd
)
1855 if (p
->type
== diParagraph
) {
1856 ypara
= p
->member
.para
.nYPos
;
1859 ystart
= ypara
+ p
->member
.row
.nYPos
;
1860 yend
= ystart
+ p
->member
.row
.nHeight
;
1868 case EM_HIDESELECTION
:
1870 editor
->bHideSelection
= (wParam
!= 0);
1871 ME_InvalidateSelection(editor
);
1876 ME_ScrollDown(editor
, lParam
* 8); /* FIXME follow the original */
1877 return TRUE
; /* Should return false if a single line richedit control */
1882 ME_GetSelection(editor
, &from
, &to
);
1883 ME_InternalDeleteText(editor
, from
, to
-from
);
1884 ME_CommitUndo(editor
);
1885 ME_UpdateRepaint(editor
);
1892 LPWSTR wszText
= lParam
? ME_ToUnicode(unicode
, (void *)lParam
) : NULL
;
1893 size_t len
= wszText
? lstrlenW(wszText
) : 0;
1894 TRACE("EM_REPLACESEL - %s\n", debugstr_w(wszText
));
1896 ME_GetSelection(editor
, &from
, &to
);
1897 style
= ME_GetSelectionInsertStyle(editor
);
1898 ME_InternalDeleteText(editor
, from
, to
-from
);
1899 ME_InsertTextFromCursor(editor
, 0, wszText
, len
, style
);
1900 ME_ReleaseStyle(style
);
1901 /* drop temporary style if line end */
1903 * FIXME question: does abc\n mean: put abc,
1904 * clear temp style, put \n? (would require a change)
1906 if (len
>0 && wszText
[len
-1] == '\n')
1907 ME_ClearTempStyle(editor
);
1908 ME_EndToUnicode(unicode
, wszText
);
1909 ME_CommitUndo(editor
);
1911 ME_EmptyUndoStack(editor
);
1912 ME_UpdateRepaint(editor
);
1915 case EM_SCROLLCARET
:
1917 int top
, bottom
; /* row's edges relative to document top */
1919 ME_DisplayItem
*para
, *row
;
1921 nPos
= ME_GetYScrollPos(editor
);
1922 row
= ME_RowStart(editor
->pCursors
[0].pRun
);
1923 para
= ME_GetParagraph(row
);
1924 top
= para
->member
.para
.nYPos
+ row
->member
.row
.nYPos
;
1925 bottom
= top
+ row
->member
.row
.nHeight
;
1927 if (top
< nPos
) /* caret above window */
1928 ME_ScrollAbs(editor
, top
);
1929 else if (nPos
+ editor
->sizeWindow
.cy
< bottom
) /*below*/
1930 ME_ScrollAbs(editor
, bottom
- editor
->sizeWindow
.cy
);
1938 BOOL bRepaint
= LOWORD(lParam
);
1941 wParam
= (WPARAM
)GetStockObject(SYSTEM_FONT
);
1942 GetObjectW((HGDIOBJ
)wParam
, sizeof(LOGFONTW
), &lf
);
1944 ME_CharFormatFromLogFont(hDC
, &lf
, &fmt
);
1945 ReleaseDC(hWnd
, hDC
);
1946 ME_SetCharFormat(editor
, 0, ME_GetTextLength(editor
), &fmt
);
1947 ME_SetDefaultCharFormat(editor
, &fmt
);
1949 ME_CommitUndo(editor
);
1951 ME_RewrapRepaint(editor
);
1956 ME_InternalDeleteText(editor
, 0, ME_GetTextLength(editor
));
1959 TRACE("WM_SETTEXT lParam==%lx\n",lParam
);
1960 if (!unicode
&& !strncmp((char *)lParam
, "{\\rtf", 5))
1962 /* Undocumented: WM_SETTEXT supports RTF text */
1963 ME_StreamInRTFString(editor
, 0, (char *)lParam
);
1967 LPWSTR wszText
= ME_ToUnicode(unicode
, (void *)lParam
);
1968 TRACE("WM_SETTEXT - %s\n", debugstr_w(wszText
)); /* debugstr_w() */
1969 if (lstrlenW(wszText
) > 0)
1973 /* uses default style! */
1974 if (!(GetWindowLongW(hWnd
, GWL_STYLE
) & ES_MULTILINE
))
1979 while (*p
!= '\0' && *p
!= '\r' && *p
!= '\n') p
++;
1982 ME_InsertTextFromCursor(editor
, 0, wszText
, len
, editor
->pBuffer
->pDefaultStyle
);
1984 ME_EndToUnicode(unicode
, wszText
);
1988 TRACE("WM_SETTEXT - NULL\n");
1989 ME_CommitUndo(editor
);
1990 ME_EmptyUndoStack(editor
);
1991 ME_SetSelection(editor
, 0, 0);
1992 editor
->nModifyStep
= 0;
1993 ME_UpdateRepaint(editor
);
1998 UINT nRTFFormat
= RegisterClipboardFormatA("Rich Text Format");
1999 if (IsClipboardFormatAvailable(nRTFFormat
))
2001 if (IsClipboardFormatAvailable(CF_UNICODETEXT
))
2009 ME_GlobalDestStruct gds
;
2010 UINT nRTFFormat
= RegisterClipboardFormatA("Rich Text Format");
2013 if (IsClipboardFormatAvailable(nRTFFormat
))
2014 cf
= nRTFFormat
, dwFormat
= SF_RTF
;
2015 else if (IsClipboardFormatAvailable(CF_UNICODETEXT
))
2016 cf
= CF_UNICODETEXT
, dwFormat
= SF_TEXT
|SF_UNICODE
;
2020 if (!OpenClipboard(hWnd
))
2022 gds
.hData
= GetClipboardData(cf
);
2024 es
.dwCookie
= (DWORD
)&gds
;
2025 es
.pfnCallback
= dwFormat
== SF_RTF
? ME_ReadFromHGLOBALRTF
: ME_ReadFromHGLOBALUnicode
;
2026 ME_StreamIn(editor
, dwFormat
|SFF_SELECTION
, &es
);
2034 LPDATAOBJECT dataObj
= NULL
;
2038 if (editor
->cPasswordMask
)
2039 return 0; /* Copying or Cutting masked text isn't allowed */
2041 ME_GetSelection(editor
, (int*)&range
.cpMin
, (int*)&range
.cpMax
);
2042 if(editor
->lpOleCallback
)
2043 hr
= IRichEditOleCallback_GetClipboardData(editor
->lpOleCallback
, &range
, RECO_COPY
, &dataObj
);
2044 if(FAILED(hr
) || !dataObj
)
2045 hr
= ME_GetDataObject(editor
, &range
, &dataObj
);
2047 hr
= OleSetClipboard(dataObj
);
2048 IDataObject_Release(dataObj
);
2050 if (SUCCEEDED(hr
) && msg
== WM_CUT
)
2052 ME_InternalDeleteText(editor
, range
.cpMin
, range
.cpMax
-range
.cpMin
);
2053 ME_CommitUndo(editor
);
2054 ME_UpdateRepaint(editor
);
2058 case WM_GETTEXTLENGTH
:
2060 GETTEXTLENGTHEX how
;
2062 how
.flags
= GTL_CLOSE
| (editor
->bEmulateVersion10
? 0 : GTL_USECRLF
) | GTL_NUMCHARS
;
2063 how
.codepage
= unicode
? 1200 : CP_ACP
;
2064 return ME_GetTextLengthEx(editor
, &how
);
2066 case EM_GETTEXTLENGTHEX
:
2067 return ME_GetTextLengthEx(editor
, (GETTEXTLENGTHEX
*)wParam
);
2072 LPSTR bufferA
= NULL
;
2073 LPWSTR bufferW
= NULL
;
2076 bufferW
= heap_alloc((wParam
+ 2) * sizeof(WCHAR
));
2078 bufferA
= heap_alloc(wParam
+ 2);
2080 ex
.cb
= wParam
+ (unicode
? 2*sizeof(WCHAR
) : 2);
2081 ex
.flags
= GT_USECRLF
;
2082 ex
.codepage
= unicode
? 1200 : CP_ACP
;
2083 ex
.lpDefaultChar
= NULL
;
2084 ex
.lpUsedDefaultChar
= NULL
;
2085 rc
= RichEditWndProc_common(hWnd
, EM_GETTEXTEX
, (WPARAM
)&ex
, unicode
? (LPARAM
)bufferW
: (LPARAM
)bufferA
, unicode
);
2089 memcpy((LPWSTR
)lParam
, bufferW
, wParam
);
2090 if (lstrlenW(bufferW
) >= wParam
/ sizeof(WCHAR
)) rc
= 0;
2094 memcpy((LPSTR
)lParam
, bufferA
, wParam
);
2095 if (strlen(bufferA
) >= wParam
) rc
= 0;
2103 GETTEXTEX
*ex
= (GETTEXTEX
*)wParam
;
2106 if (ex
->flags
& ~(GT_SELECTION
| GT_USECRLF
))
2107 FIXME("GETTEXTEX flags 0x%08x not supported\n", ex
->flags
& ~(GT_SELECTION
| GT_USECRLF
));
2109 if (ex
->flags
& GT_SELECTION
)
2111 ME_GetSelection(editor
, &nStart
, &nCount
);
2113 nCount
= min(nCount
, ex
->cb
- 1);
2118 nCount
= ex
->cb
- 1;
2120 if (ex
->codepage
== 1200)
2122 nCount
= min(nCount
, ex
->cb
/ sizeof(WCHAR
) - 1);
2123 return ME_GetTextW(editor
, (LPWSTR
)lParam
, nStart
, nCount
, ex
->flags
& GT_USECRLF
);
2127 /* potentially each char may be a CR, why calculate the exact value with O(N) when
2128 we can just take a bigger buffer? :) */
2129 int crlfmul
= (ex
->flags
& GT_USECRLF
) ? 2 : 1;
2130 LPWSTR buffer
= heap_alloc((crlfmul
*nCount
+ 1) * sizeof(WCHAR
));
2131 DWORD buflen
= ex
->cb
;
2135 buflen
= ME_GetTextW(editor
, buffer
, nStart
, nCount
, ex
->flags
& GT_USECRLF
);
2136 rc
= WideCharToMultiByte(ex
->codepage
, flags
, buffer
, -1, (LPSTR
)lParam
, ex
->cb
, ex
->lpDefaultChar
, ex
->lpUsedDefaultChar
);
2137 if (rc
) rc
--; /* do not count 0 terminator */
2146 TEXTRANGEW tr
; /* W and A differ only by rng->lpstrText */
2147 ME_GetSelection(editor
, &from
, &to
);
2148 tr
.chrg
.cpMin
= from
;
2150 tr
.lpstrText
= (WCHAR
*)lParam
;
2151 return RichEditWndProc_common(hWnd
, EM_GETTEXTRANGE
, 0, (LPARAM
)&tr
, unicode
);
2153 case EM_GETSCROLLPOS
:
2155 POINT
*point
= (POINT
*)lParam
;
2156 point
->x
= 0; /* FIXME side scrolling not implemented */
2157 point
->y
= ME_GetYScrollPos(editor
);
2160 case EM_GETTEXTRANGE
:
2162 TEXTRANGEW
*rng
= (TEXTRANGEW
*)lParam
;
2163 TRACE("EM_GETTEXTRANGE min=%d max=%d unicode=%d emul1.0=%d length=%d\n",
2164 rng
->chrg
.cpMin
, rng
->chrg
.cpMax
, unicode
,
2165 editor
->bEmulateVersion10
, ME_GetTextLength(editor
));
2167 return ME_GetTextW(editor
, rng
->lpstrText
, rng
->chrg
.cpMin
, rng
->chrg
.cpMax
-rng
->chrg
.cpMin
, editor
->bEmulateVersion10
);
2170 int nLen
= rng
->chrg
.cpMax
-rng
->chrg
.cpMin
;
2171 WCHAR
*p
= ALLOC_N_OBJ(WCHAR
, nLen
+1);
2172 int nChars
= ME_GetTextW(editor
, p
, rng
->chrg
.cpMin
, nLen
, editor
->bEmulateVersion10
);
2173 /* FIXME this is a potential security hole (buffer overrun)
2174 if you know more about wchar->mbyte conversion please explain
2176 WideCharToMultiByte(CP_ACP
, 0, p
, nChars
+1, (char *)rng
->lpstrText
, nLen
+1, NULL
, NULL
);
2183 ME_DisplayItem
*run
;
2184 const unsigned int nMaxChars
= *(WORD
*) lParam
;
2185 unsigned int nEndChars
, nCharsLeft
= nMaxChars
;
2186 char *dest
= (char *) lParam
;
2187 /* rich text editor 1.0 uses \r\n for line end, 2.0 uses just \r;
2188 we need to know how if we have the extra \n or not */
2189 int nLF
= editor
->bEmulateVersion10
;
2191 TRACE("EM_GETLINE: row=%d, nMaxChars=%d (%s)\n", (int) wParam
, nMaxChars
,
2192 unicode
? "Unicode" : "Ansi");
2194 run
= ME_FindRowWithNumber(editor
, wParam
);
2198 while (nCharsLeft
&& (run
= ME_FindItemFwd(run
, diRunOrStartRow
))
2199 && !(run
->member
.run
.nFlags
& MERF_ENDPARA
))
2203 if (run
->type
!= diRun
)
2205 strText
= run
->member
.run
.strText
;
2206 nCopy
= min(nCharsLeft
, strText
->nLen
);
2209 lstrcpynW((LPWSTR
) dest
, strText
->szData
, nCopy
);
2211 nCopy
= WideCharToMultiByte(CP_ACP
, 0, strText
->szData
, nCopy
, dest
,
2212 nCharsLeft
, NULL
, NULL
);
2213 dest
+= nCopy
* (unicode
? sizeof(WCHAR
) : 1);
2214 nCharsLeft
-= nCopy
;
2217 /* append \r\0 (or \r\n\0 in 1.0), space allowing */
2218 nEndChars
= min(nCharsLeft
, 2 + nLF
);
2219 nCharsLeft
-= nEndChars
;
2222 const WCHAR src
[] = {'\r', '\0'};
2223 const WCHAR src10
[] = {'\r', '\n', '\0'};
2224 lstrcpynW((LPWSTR
) dest
, nLF
? src10
: src
, nEndChars
);
2227 lstrcpynA(dest
, nLF
? "\r\n" : "\r", nEndChars
);
2229 TRACE("EM_GETLINE: got %u bytes\n", nMaxChars
- nCharsLeft
);
2231 if (nEndChars
== 2 + nLF
)
2232 return nMaxChars
- nCharsLeft
- 1; /* don't count \0 */
2234 return nMaxChars
- nCharsLeft
;
2236 case EM_GETLINECOUNT
:
2238 ME_DisplayItem
*item
= editor
->pBuffer
->pFirst
->next
;
2241 while (item
!= editor
->pBuffer
->pLast
)
2243 assert(item
->type
== diParagraph
);
2244 nRows
+= item
->member
.para
.nRows
;
2245 item
= item
->member
.para
.next_para
;
2247 TRACE("EM_GETLINECOUNT: nRows==%d\n", nRows
);
2248 return max(1, nRows
);
2250 case EM_LINEFROMCHAR
:
2253 return ME_RowNumberFromCharOfs(editor
, ME_GetCursorOfs(editor
, 1));
2255 return ME_RowNumberFromCharOfs(editor
, wParam
);
2257 case EM_EXLINEFROMCHAR
:
2260 return ME_RowNumberFromCharOfs(editor
, ME_GetCursorOfs(editor
,1));
2262 return ME_RowNumberFromCharOfs(editor
, lParam
);
2266 ME_DisplayItem
*item
, *para
;
2270 item
= ME_FindItemBack(editor
->pCursors
[0].pRun
, diStartRow
);
2272 item
= ME_FindRowWithNumber(editor
, wParam
);
2275 para
= ME_GetParagraph(item
);
2276 item
= ME_FindItemFwd(item
, diRun
);
2277 nCharOfs
= para
->member
.para
.nCharOfs
+ item
->member
.run
.nCharOfs
;
2278 TRACE("EM_LINEINDEX: nCharOfs==%d\n", nCharOfs
);
2283 ME_DisplayItem
*item
, *item_end
;
2284 int nChars
= 0, nThisLineOfs
= 0, nNextLineOfs
= 0;
2286 if (wParam
> ME_GetTextLength(editor
))
2290 FIXME("EM_LINELENGTH: returning number of unselected characters on lines with selection unsupported.\n");
2293 item
= ME_FindItemAtOffset(editor
, diRun
, wParam
, NULL
);
2294 item
= ME_RowStart(item
);
2295 nThisLineOfs
= ME_CharOfsFromRunOfs(editor
, ME_FindItemFwd(item
, diRun
), 0);
2296 item_end
= ME_FindItemFwd(item
, diStartRowOrParagraphOrEnd
);
2297 if (item_end
->type
== diStartRow
)
2298 nNextLineOfs
= ME_CharOfsFromRunOfs(editor
, ME_FindItemFwd(item_end
, diRun
), 0);
2300 nNextLineOfs
= ME_FindItemFwd(item
, diParagraphOrEnd
)->member
.para
.nCharOfs
2301 - (editor
->bEmulateVersion10
?2:1);
2302 nChars
= nNextLineOfs
- nThisLineOfs
;
2303 TRACE("EM_LINELENGTH(%ld)==%d\n",wParam
, nChars
);
2306 case EM_EXLIMITTEXT
:
2308 if ((int)lParam
< 0)
2311 editor
->nTextLimit
= 65536;
2313 editor
->nTextLimit
= (int) lParam
;
2319 editor
->nTextLimit
= 65536;
2321 editor
->nTextLimit
= (int) wParam
;
2324 case EM_GETLIMITTEXT
:
2326 return editor
->nTextLimit
;
2330 FINDTEXTA
*ft
= (FINDTEXTA
*)lParam
;
2331 int nChars
= MultiByteToWideChar(CP_ACP
, 0, ft
->lpstrText
, -1, NULL
, 0);
2335 if ((tmp
= ALLOC_N_OBJ(WCHAR
, nChars
)) != NULL
)
2336 MultiByteToWideChar(CP_ACP
, 0, ft
->lpstrText
, -1, tmp
, nChars
);
2337 r
= ME_FindText(editor
, wParam
, &ft
->chrg
, tmp
, NULL
);
2343 FINDTEXTEXA
*ex
= (FINDTEXTEXA
*)lParam
;
2344 int nChars
= MultiByteToWideChar(CP_ACP
, 0, ex
->lpstrText
, -1, NULL
, 0);
2348 if ((tmp
= ALLOC_N_OBJ(WCHAR
, nChars
)) != NULL
)
2349 MultiByteToWideChar(CP_ACP
, 0, ex
->lpstrText
, -1, tmp
, nChars
);
2350 r
= ME_FindText(editor
, wParam
, &ex
->chrg
, tmp
, &ex
->chrgText
);
2356 FINDTEXTW
*ft
= (FINDTEXTW
*)lParam
;
2357 return ME_FindText(editor
, wParam
, &ft
->chrg
, ft
->lpstrText
, NULL
);
2359 case EM_FINDTEXTEXW
:
2361 FINDTEXTEXW
*ex
= (FINDTEXTEXW
*)lParam
;
2362 return ME_FindText(editor
, wParam
, &ex
->chrg
, ex
->lpstrText
, &ex
->chrgText
);
2365 if (!wParam
|| !lParam
)
2367 *(int *)wParam
= editor
->nZoomNumerator
;
2368 *(int *)lParam
= editor
->nZoomDenominator
;
2371 return ME_SetZoom(editor
, wParam
, lParam
);
2372 case EM_CHARFROMPOS
:
2373 return ME_CharFromPos(editor
, ((POINTL
*)lParam
)->x
, ((POINTL
*)lParam
)->y
);
2374 case EM_POSFROMCHAR
:
2376 ME_DisplayItem
*pRun
;
2377 int nCharOfs
, nOffset
, nLength
;
2381 /* detect which API version we're dealing with */
2382 if (wParam
>= 0x40000)
2384 nLength
= ME_GetTextLength(editor
);
2386 if (nCharOfs
< nLength
) {
2387 ME_RunOfsFromCharOfs(editor
, nCharOfs
, &pRun
, &nOffset
);
2388 assert(pRun
->type
== diRun
);
2389 pt
.y
= pRun
->member
.run
.pt
.y
;
2390 pt
.x
= pRun
->member
.run
.pt
.x
+ ME_PointFromChar(editor
, &pRun
->member
.run
, nOffset
);
2391 pt
.y
+= ME_GetParagraph(pRun
)->member
.para
.nYPos
;
2394 pt
.y
= editor
->pBuffer
->pLast
->member
.para
.nYPos
;
2396 if (wParam
>= 0x40000) {
2397 *(POINTL
*)wParam
= pt
;
2399 return MAKELONG( pt
.x
, pt
.y
);
2402 if (GetWindowLongW(hWnd
, GWL_STYLE
) & WS_HSCROLL
)
2403 { /* Squelch the default horizontal scrollbar it would make */
2404 ShowScrollBar(editor
->hWnd
, SB_HORZ
, FALSE
);
2406 ME_CommitUndo(editor
);
2407 ME_WrapMarkedParagraphs(editor
);
2408 ME_MoveCaret(editor
);
2411 ME_DestroyEditor(editor
);
2412 SetWindowLongPtrW(hWnd
, 0, 0);
2414 case WM_LBUTTONDOWN
:
2415 if ((editor
->nEventMask
& ENM_MOUSEEVENTS
) &&
2416 !ME_FilterEvent(editor
, msg
, &wParam
, &lParam
))
2419 ME_LButtonDown(editor
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
2421 ME_LinkNotify(editor
,msg
,wParam
,lParam
);
2422 ME_SetCursor(editor
, LOWORD(lParam
));
2425 if ((editor
->nEventMask
& ENM_MOUSEEVENTS
) &&
2426 !ME_FilterEvent(editor
, msg
, &wParam
, &lParam
))
2428 if (GetCapture() == hWnd
)
2429 ME_MouseMove(editor
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
2430 ME_LinkNotify(editor
,msg
,wParam
,lParam
);
2431 ME_SetCursor(editor
, LOWORD(lParam
));
2434 if (GetCapture() == hWnd
)
2436 if ((editor
->nEventMask
& ENM_MOUSEEVENTS
) &&
2437 !ME_FilterEvent(editor
, msg
, &wParam
, &lParam
))
2439 editor
->linesel
= 0;
2440 ME_SetCursor(editor
, LOWORD(lParam
));
2441 ME_LinkNotify(editor
,msg
,wParam
,lParam
);
2443 case WM_LBUTTONDBLCLK
:
2444 if ((editor
->nEventMask
& ENM_MOUSEEVENTS
) &&
2445 !ME_FilterEvent(editor
, msg
, &wParam
, &lParam
))
2447 ME_LinkNotify(editor
,msg
,wParam
,lParam
);
2448 ME_SelectWord(editor
);
2451 case WM_RBUTTONDOWN
:
2452 if ((editor
->nEventMask
& ENM_MOUSEEVENTS
) &&
2453 !ME_FilterEvent(editor
, msg
, &wParam
, &lParam
))
2456 case WM_CONTEXTMENU
:
2457 if (!ME_ShowContextMenu(editor
, (short)LOWORD(lParam
), (short)HIWORD(lParam
)))
2461 if (editor
->bRedraw
)
2466 hDC
= BeginPaint(hWnd
, &ps
);
2467 ME_PaintContent(editor
, hDC
, FALSE
, &ps
.rcPaint
);
2468 EndPaint(hWnd
, &ps
);
2472 editor
->bHaveFocus
= TRUE
;
2473 ME_ShowCaret(editor
);
2474 ME_SendOldNotify(editor
, EN_SETFOCUS
);
2477 ME_HideCaret(editor
);
2478 editor
->bHaveFocus
= FALSE
;
2479 ME_SendOldNotify(editor
, EN_KILLFOCUS
);
2483 if (editor
->bRedraw
)
2485 HDC hDC
= (HDC
)wParam
;
2487 if (GetUpdateRect(hWnd
,&rc
,TRUE
))
2489 FillRect(hDC
, &rc
, editor
->hbrBackground
);
2495 TRACE("editor wnd command = %d\n", LOWORD(wParam
));
2498 if ((editor
->nEventMask
& ENM_KEYEVENTS
) &&
2499 !ME_FilterEvent(editor
, msg
, &wParam
, &lParam
))
2503 if ((editor
->nEventMask
& ENM_KEYEVENTS
) &&
2504 !ME_FilterEvent(editor
, msg
, &wParam
, &lParam
))
2506 if (ME_KeyDown(editor
, LOWORD(wParam
)))
2514 wstr
= (WCHAR
)wParam
;
2517 CHAR charA
= wParam
;
2518 MultiByteToWideChar(CP_ACP
, 0, &charA
, 1, &wstr
, 1);
2520 if (editor
->AutoURLDetect_bEnable
)
2521 ME_AutoURLDetect(editor
, wstr
);
2525 case 1: /* Ctrl-A */
2526 ME_SetSelection(editor
, 0, -1);
2528 case 3: /* Ctrl-C */
2529 SendMessageW(editor
->hWnd
, WM_COPY
, 0, 0);
2533 if (GetWindowLongW(editor
->hWnd
, GWL_STYLE
) & ES_READONLY
) {
2534 MessageBeep(MB_ICONERROR
);
2535 return 0; /* FIXME really 0 ? */
2540 case 22: /* Ctrl-V */
2541 SendMessageW(editor
->hWnd
, WM_PASTE
, 0, 0);
2543 case 24: /* Ctrl-X */
2544 SendMessageW(editor
->hWnd
, WM_CUT
, 0, 0);
2546 case 25: /* Ctrl-Y */
2547 SendMessageW(editor
->hWnd
, EM_REDO
, 0, 0);
2549 case 26: /* Ctrl-Z */
2550 SendMessageW(editor
->hWnd
, EM_UNDO
, 0, 0);
2553 if (((unsigned)wstr
)>=' '
2554 || (wstr
=='\r' && (GetWindowLongW(hWnd
, GWL_STYLE
) & ES_MULTILINE
))
2556 /* FIXME maybe it would make sense to call EM_REPLACESEL instead ? */
2557 /* WM_CHAR is restricted to nTextLimit */
2559 ME_GetSelection(editor
, &from
, &to
);
2560 if(editor
->nTextLimit
> ME_GetTextLength(editor
) - (to
-from
))
2562 ME_Style
*style
= ME_GetInsertStyle(editor
, 0);
2563 ME_SaveTempStyle(editor
);
2564 ME_InsertTextFromCursor(editor
, 0, &wstr
, 1, style
);
2565 ME_ReleaseStyle(style
);
2566 ME_CommitUndo(editor
);
2568 ME_UpdateRepaint(editor
);
2572 case EM_SCROLL
: /* fall through */
2578 origNPos
= ME_GetYScrollPos(editor
);
2581 if (editor
&& editor
->pBuffer
&& editor
->pBuffer
->pDefaultStyle
)
2582 lineHeight
= editor
->pBuffer
->pDefaultStyle
->tm
.tmHeight
;
2583 if (lineHeight
<= 0) lineHeight
= 24;
2585 switch(LOWORD(wParam
))
2588 ME_ScrollUp(editor
,lineHeight
);
2591 ME_ScrollDown(editor
,lineHeight
);
2594 ME_ScrollUp(editor
,editor
->sizeWindow
.cy
);
2597 ME_ScrollDown(editor
,editor
->sizeWindow
.cy
);
2600 case SB_THUMBPOSITION
:
2601 ME_ScrollAbs(editor
,HIWORD(wParam
));
2604 if (msg
== EM_SCROLL
)
2605 return 0x00010000 | (((ME_GetYScrollPos(editor
) - origNPos
)/lineHeight
) & 0xffff);
2611 UINT pulScrollLines
;
2613 if ((editor
->nEventMask
& ENM_MOUSEEVENTS
) &&
2614 !ME_FilterEvent(editor
, msg
, &wParam
, &lParam
))
2617 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
2618 gcWheelDelta
= -GET_WHEEL_DELTA_WPARAM(wParam
);
2620 if (abs(gcWheelDelta
) >= WHEEL_DELTA
&& pulScrollLines
)
2622 /* FIXME follow the original */
2623 ME_ScrollDown(editor
,pulScrollLines
* (gcWheelDelta
/ WHEEL_DELTA
) * 8);
2629 *((RECT
*)lParam
) = editor
->rcFormat
;
2637 RECT
*rc
= (RECT
*)lParam
;
2641 editor
->rcFormat
.left
+= rc
->left
;
2642 editor
->rcFormat
.top
+= rc
->top
;
2643 editor
->rcFormat
.right
+= rc
->right
;
2644 editor
->rcFormat
.bottom
+= rc
->bottom
;
2648 editor
->rcFormat
= *rc
;
2653 GetClientRect(hWnd
, &editor
->rcFormat
);
2655 if (msg
!= EM_SETRECTNP
)
2656 ME_RewrapRepaint(editor
);
2659 case EM_REQUESTRESIZE
:
2660 ME_SendRequestResize(editor
, TRUE
);
2663 editor
->bRedraw
= wParam
;
2667 GetClientRect(hWnd
, &editor
->rcFormat
);
2668 ME_RewrapRepaint(editor
);
2669 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
2671 /* IME messages to make richedit controls IME aware */
2672 case WM_IME_SETCONTEXT
:
2673 case WM_IME_CONTROL
:
2675 case WM_IME_COMPOSITIONFULL
:
2677 case WM_IME_STARTCOMPOSITION
:
2679 editor
->imeStartIndex
=ME_GetCursorOfs(editor
,0);
2680 ME_DeleteSelection(editor
);
2681 ME_CommitUndo(editor
);
2682 ME_UpdateRepaint(editor
);
2685 case WM_IME_COMPOSITION
:
2689 ME_Style
*style
= ME_GetInsertStyle(editor
, 0);
2690 hIMC
= ImmGetContext(hWnd
);
2691 ME_DeleteSelection(editor
);
2692 ME_CommitUndo(editor
);
2693 ME_SaveTempStyle(editor
);
2694 if (lParam
& GCS_RESULTSTR
)
2696 LPWSTR lpCompStr
= NULL
;
2699 dwBufLen
= ImmGetCompositionStringW(hIMC
, GCS_RESULTSTR
, NULL
, 0);
2700 lpCompStr
= HeapAlloc(GetProcessHeap(),0,dwBufLen
+ sizeof(WCHAR
));
2701 ImmGetCompositionStringW(hIMC
, GCS_RESULTSTR
, lpCompStr
, dwBufLen
);
2702 lpCompStr
[dwBufLen
/sizeof(WCHAR
)] = 0;
2703 ME_InsertTextFromCursor(editor
,0,lpCompStr
,dwBufLen
/sizeof(WCHAR
),style
);
2705 else if (lParam
& GCS_COMPSTR
)
2707 LPWSTR lpCompStr
= NULL
;
2710 dwBufLen
= ImmGetCompositionStringW(hIMC
, GCS_COMPSTR
, NULL
, 0);
2711 lpCompStr
= HeapAlloc(GetProcessHeap(),0,dwBufLen
+ sizeof(WCHAR
));
2712 ImmGetCompositionStringW(hIMC
, GCS_COMPSTR
, lpCompStr
, dwBufLen
);
2713 lpCompStr
[dwBufLen
/sizeof(WCHAR
)] = 0;
2715 ME_InsertTextFromCursor(editor
,0,lpCompStr
,dwBufLen
/sizeof(WCHAR
),style
);
2716 ME_SetSelection(editor
,editor
->imeStartIndex
,
2717 editor
->imeStartIndex
+ dwBufLen
/sizeof(WCHAR
));
2719 ME_ReleaseStyle(style
);
2720 ME_UpdateRepaint(editor
);
2723 case WM_IME_ENDCOMPOSITION
:
2725 ME_DeleteSelection(editor
);
2726 editor
->imeStartIndex
=-1;
2729 case EM_GETOLEINTERFACE
:
2731 LPVOID
*ppvObj
= (LPVOID
*) lParam
;
2732 return CreateIRichEditOle(editor
, ppvObj
);
2734 case EM_GETPASSWORDCHAR
:
2736 return editor
->cPasswordMask
;
2738 case EM_SETOLECALLBACK
:
2739 if(editor
->lpOleCallback
)
2740 IUnknown_Release(editor
->lpOleCallback
);
2741 editor
->lpOleCallback
= (LPRICHEDITOLECALLBACK
)lParam
;
2742 if(editor
->lpOleCallback
)
2743 IUnknown_AddRef(editor
->lpOleCallback
);
2745 case EM_GETWORDBREAKPROC
:
2746 return (LRESULT
)editor
->pfnWordBreak
;
2747 case EM_SETWORDBREAKPROC
:
2749 EDITWORDBREAKPROCW pfnOld
= editor
->pfnWordBreak
;
2751 editor
->pfnWordBreak
= (EDITWORDBREAKPROCW
)lParam
;
2752 return (LRESULT
)pfnOld
;
2754 case EM_SETTEXTMODE
:
2759 ret
= RichEditWndProc_common(hWnd
, WM_GETTEXTLENGTH
, 0, 0, unicode
);
2762 /*Check for valid wParam*/
2763 if ((((wParam
& TM_RICHTEXT
) && ((wParam
& TM_PLAINTEXT
) << 1))) ||
2764 (((wParam
& TM_MULTILEVELUNDO
) && ((wParam
& TM_SINGLELEVELUNDO
) << 1))) ||
2765 (((wParam
& TM_MULTICODEPAGE
) && ((wParam
& TM_SINGLECODEPAGE
) << 1))))
2769 if (wParam
& (TM_RICHTEXT
| TM_PLAINTEXT
))
2771 mask
|= (TM_RICHTEXT
| TM_PLAINTEXT
);
2772 changes
|= (wParam
& (TM_RICHTEXT
| TM_PLAINTEXT
));
2774 /*FIXME: Currently no support for undo level and code page options*/
2775 editor
->mode
= (editor
->mode
& (~mask
)) | changes
;
2781 case EM_SETPASSWORDCHAR
:
2783 editor
->cPasswordMask
= wParam
;
2784 ME_RewrapRepaint(editor
);
2789 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
2794 static LRESULT WINAPI
RichEditWndProcW(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2796 BOOL unicode
= TRUE
;
2798 /* Under Win9x RichEdit20W returns ANSI strings, see the tests. */
2799 if (msg
== WM_GETTEXT
&& (GetVersion() & 0x80000000))
2802 return RichEditWndProc_common(hWnd
, msg
, wParam
, lParam
, unicode
);
2805 static LRESULT WINAPI
RichEditWndProcA(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2807 return RichEditWndProc_common(hWnd
, msg
, wParam
, lParam
, FALSE
);
2810 /******************************************************************
2811 * RichEditANSIWndProc (RICHED20.10)
2813 LRESULT WINAPI
RichEditANSIWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2815 return RichEditWndProcA(hWnd
, msg
, wParam
, lParam
);
2818 /******************************************************************
2819 * RichEdit10ANSIWndProc (RICHED20.9)
2821 LRESULT WINAPI
RichEdit10ANSIWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2825 /* FIXME: this is NOT the same as 2.0 version */
2826 result
= RichEditANSIWndProc(hWnd
, msg
, wParam
, lParam
);
2827 if (msg
== WM_NCCREATE
)
2829 ME_TextEditor
*editor
= (ME_TextEditor
*)GetWindowLongPtrW(hWnd
, 0);
2831 editor
->bEmulateVersion10
= TRUE
;
2832 editor
->pBuffer
->pLast
->member
.para
.nCharOfs
= 2;
2837 void ME_SendOldNotify(ME_TextEditor
*editor
, int nCode
)
2839 HWND hWnd
= editor
->hWnd
;
2840 SendMessageA(GetParent(hWnd
), WM_COMMAND
, (nCode
<<16)|GetWindowLongW(hWnd
, GWLP_ID
), (LPARAM
)hWnd
);
2843 void ME_LinkNotify(ME_TextEditor
*editor
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2846 ME_Cursor tmpCursor
;
2847 int nCharOfs
; /* The start of the clicked text. Absolute character offset */
2852 x
= (short)LOWORD(lParam
);
2853 y
= (short)HIWORD(lParam
);
2854 nCharOfs
= ME_CharFromPos(editor
, x
, y
);
2855 if (nCharOfs
< 0) return;
2857 ME_CursorFromCharOfs(editor
, nCharOfs
, &tmpCursor
);
2858 tmpRun
= &tmpCursor
.pRun
->member
.run
;
2860 if ((tmpRun
->style
->fmt
.dwMask
& CFM_LINK
)
2861 && (tmpRun
->style
->fmt
.dwEffects
& CFE_LINK
))
2862 { /* The clicked run has CFE_LINK set */
2863 info
.nmhdr
.hwndFrom
= editor
->hWnd
;
2864 info
.nmhdr
.idFrom
= GetWindowLongW(editor
->hWnd
, GWLP_ID
);
2865 info
.nmhdr
.code
= EN_LINK
;
2867 info
.wParam
= wParam
;
2868 info
.lParam
= lParam
;
2869 info
.chrg
.cpMin
= ME_CharOfsFromRunOfs(editor
,tmpCursor
.pRun
,0);
2870 info
.chrg
.cpMax
= info
.chrg
.cpMin
+ ME_StrVLen(tmpRun
->strText
);
2871 SendMessageW(GetParent(editor
->hWnd
), WM_NOTIFY
,info
.nmhdr
.idFrom
, (LPARAM
)&info
);
2875 int ME_CountParagraphsBetween(ME_TextEditor
*editor
, int from
, int to
)
2877 ME_DisplayItem
*item
= ME_FindItemFwd(editor
->pBuffer
->pFirst
, diParagraph
);
2880 while(item
&& item
->member
.para
.next_para
->member
.para
.nCharOfs
<= from
)
2881 item
= item
->member
.para
.next_para
;
2884 while(item
&& item
->member
.para
.next_para
->member
.para
.nCharOfs
<= to
) {
2885 item
= item
->member
.para
.next_para
;
2892 int ME_GetTextW(ME_TextEditor
*editor
, WCHAR
*buffer
, int nStart
, int nChars
, int bCRLF
)
2894 ME_DisplayItem
*item
= ME_FindItemAtOffset(editor
, diRun
, nStart
, &nStart
);
2896 WCHAR
*pStart
= buffer
;
2905 int nLen
= ME_StrLen(item
->member
.run
.strText
) - nStart
;
2908 CopyMemory(buffer
, item
->member
.run
.strText
->szData
+ nStart
, sizeof(WCHAR
)*nLen
);
2915 item
= ME_FindItemFwd(item
, diRun
);
2918 while(nChars
&& item
)
2920 int nLen
= ME_StrLen(item
->member
.run
.strText
);
2924 if (item
->member
.run
.nFlags
& MERF_ENDPARA
)
2926 if (!ME_FindItemFwd(item
, diRun
))
2927 /* No '\r' is appended to the last paragraph. */
2929 else if (bCRLF
&& nChars
== 1) {
2940 /* our end paragraph consists of 2 characters now */
2941 if (editor
->bEmulateVersion10
)
2946 CopyMemory(buffer
, item
->member
.run
.strText
->szData
, sizeof(WCHAR
)*nLen
);
2953 TRACE("nWritten=%d, actual=%d\n", nWritten
, buffer
-pStart
);
2957 item
= ME_FindItemFwd(item
, diRun
);
2960 TRACE("nWritten=%d, actual=%d\n", nWritten
, buffer
-pStart
);
2964 static BOOL
ME_RegisterEditorClass(HINSTANCE hInstance
)
2969 wcW
.style
= CS_DBLCLKS
| CS_HREDRAW
| CS_VREDRAW
| CS_GLOBALCLASS
;
2970 wcW
.lpfnWndProc
= RichEditWndProcW
;
2972 wcW
.cbWndExtra
= sizeof(ME_TextEditor
*);
2973 wcW
.hInstance
= NULL
; /* hInstance would register DLL-local class */
2975 wcW
.hCursor
= hBeam
;
2976 wcW
.hbrBackground
= (HBRUSH
)GetStockObject(NULL_BRUSH
);
2977 wcW
.lpszMenuName
= NULL
;
2979 if (is_version_nt())
2981 wcW
.lpszClassName
= RichEdit20W
;
2982 if (!RegisterClassW(&wcW
)) return FALSE
;
2983 wcW
.lpszClassName
= RichEdit50W
;
2984 if (!RegisterClassW(&wcW
)) return FALSE
;
2988 /* WNDCLASSA/W have the same layout */
2989 wcW
.lpszClassName
= (LPCWSTR
)"RichEdit20W";
2990 if (!RegisterClassA((WNDCLASSA
*)&wcW
)) return FALSE
;
2991 wcW
.lpszClassName
= (LPCWSTR
)"RichEdit50W";
2992 if (!RegisterClassA((WNDCLASSA
*)&wcW
)) return FALSE
;
2995 wcA
.style
= CS_DBLCLKS
| CS_HREDRAW
| CS_VREDRAW
| CS_GLOBALCLASS
;
2996 wcA
.lpfnWndProc
= RichEditWndProcA
;
2998 wcA
.cbWndExtra
= sizeof(ME_TextEditor
*);
2999 wcA
.hInstance
= NULL
; /* hInstance would register DLL-local class */
3001 wcA
.hCursor
= LoadCursorW(NULL
, MAKEINTRESOURCEW(IDC_IBEAM
));
3002 wcA
.hbrBackground
= (HBRUSH
)GetStockObject(NULL_BRUSH
);
3003 wcA
.lpszMenuName
= NULL
;
3004 wcA
.lpszClassName
= "RichEdit20A";
3005 if (!RegisterClassA(&wcA
)) return FALSE
;
3006 wcA
.lpszClassName
= "RichEdit50A";
3007 if (!RegisterClassA(&wcA
)) return FALSE
;
3012 LRESULT WINAPI
REComboWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
) {
3013 /* FIXME: Not implemented */
3014 TRACE("hWnd %p msg %04x (%s) %08lx %08lx\n",
3015 hWnd
, msg
, get_msg_name(msg
), wParam
, lParam
);
3016 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
3019 LRESULT WINAPI
REListWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
) {
3020 /* FIXME: Not implemented */
3021 TRACE("hWnd %p msg %04x (%s) %08lx %08lx\n",
3022 hWnd
, msg
, get_msg_name(msg
), wParam
, lParam
);
3023 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
3026 /******************************************************************
3027 * REExtendedRegisterClass (RICHED20.8)
3029 * FIXME undocumented
3030 * Need to check for errors and implement controls and callbacks
3032 LRESULT WINAPI
REExtendedRegisterClass(void)
3037 FIXME("semi stub\n");
3041 wcW
.hInstance
= NULL
;
3044 wcW
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+1);
3045 wcW
.lpszMenuName
= NULL
;
3047 if (!ME_ListBoxRegistered
)
3049 wcW
.style
= CS_PARENTDC
| CS_DBLCLKS
| CS_GLOBALCLASS
;
3050 wcW
.lpfnWndProc
= REListWndProc
;
3051 wcW
.lpszClassName
= REListBox20W
;
3052 if (RegisterClassW(&wcW
)) ME_ListBoxRegistered
= TRUE
;
3055 if (!ME_ComboBoxRegistered
)
3057 wcW
.style
= CS_PARENTDC
| CS_DBLCLKS
| CS_GLOBALCLASS
| CS_VREDRAW
| CS_HREDRAW
;
3058 wcW
.lpfnWndProc
= REComboWndProc
;
3059 wcW
.lpszClassName
= REComboBox20W
;
3060 if (RegisterClassW(&wcW
)) ME_ComboBoxRegistered
= TRUE
;
3064 if (ME_ListBoxRegistered
)
3066 if (ME_ComboBoxRegistered
)
3072 int ME_AutoURLDetect(ME_TextEditor
*editor
, WCHAR curChar
)
3092 int curf_ef
, link_ef
, def_ef
;
3093 int cur_prefx
, prefx_cnt
;
3094 int sel_min
, sel_max
;
3097 int URLmin
, URLmax
= 0;
3100 CHARFORMAT2W cur_format
;
3101 CHARFORMAT2W default_format
;
3103 RichEditANSIWndProc(editor
->hWnd
, EM_EXGETSEL
, (WPARAM
) 0, (LPARAM
) &ins_pt
);
3104 sel_min
= ins_pt
.cpMin
;
3105 sel_max
= ins_pt
.cpMax
;
3106 if (sel_min
==sel_max
)
3108 if (sel_min
!=sel_max
)
3109 car_pos
= ME_GetTextLength(editor
)+1;
3110 cur_format
.cbSize
= sizeof(cur_format
);
3111 default_format
.cbSize
= sizeof(default_format
);
3112 RichEditANSIWndProc(editor
->hWnd
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
) &cur_format
);
3113 RichEditANSIWndProc(editor
->hWnd
, EM_GETCHARFORMAT
, SCF_DEFAULT
, (LPARAM
) &default_format
);
3114 link
.cbSize
= sizeof(link
);
3115 link
.dwMask
= CFM_LINK
;
3116 link
.dwEffects
= CFE_LINK
;
3117 curf_ef
= cur_format
.dwEffects
& link
.dwEffects
;
3118 def_ef
= default_format
.dwEffects
& link
.dwEffects
;
3119 link_ef
= link
.dwEffects
& link
.dwEffects
;
3120 if (curf_ef
== link_ef
)
3122 if( curChar
== '\n' || curChar
=='\r' || curChar
==' ')
3124 ME_SetSelection(editor
, car_pos
, car_pos
);
3125 RichEditANSIWndProc(editor
->hWnd
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
) &default_format
);
3130 if (curf_ef
== def_ef
)
3133 prefx_cnt
= (sizeof(prefixes
)/sizeof(struct prefix_s
))-1;
3134 while (cur_prefx
<=prefx_cnt
)
3138 ft
.lpstrText
= prefixes
[cur_prefx
].text
;
3139 URLmin
=max(0,(car_pos
-prefixes
[cur_prefx
].length
));
3140 URLmax
=max(0, car_pos
);
3141 if ((car_pos
== 0) && (ME_GetTextLength(editor
) != 0))
3143 URLmax
= ME_GetTextLength(editor
)+1;
3145 ft
.chrg
.cpMin
= URLmin
;
3146 ft
.chrg
.cpMax
= URLmax
;
3147 text_pos
=RichEditANSIWndProc(editor
->hWnd
, EM_FINDTEXT
, FR_DOWN
, (LPARAM
)&ft
);
3153 url
.cpMax
=car_pos
-1;
3154 ME_SetCharFormat(editor
, text_pos
, (URLmax
-text_pos
), &link
);
3155 ME_RewrapRepaint(editor
);