2 * RichEdit - functions dealing with editor object
4 * Copyright 2004 by Krzysztof Foltman
5 * Copyright 2005 by Cihan Altinay
6 * Copyright 2005 by Phil Krylov
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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
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 (unicode only, 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
230 #include "textserv.h"
233 WINE_DEFAULT_DEBUG_CHANNEL(richedit
);
236 HANDLE me_heap
= NULL
;
238 static BOOL ME_ListBoxRegistered
= FALSE
;
239 static BOOL ME_ComboBoxRegistered
= FALSE
;
241 static ME_TextBuffer
*ME_MakeText(void) {
243 ME_TextBuffer
*buf
= ALLOC_OBJ(ME_TextBuffer
);
245 ME_DisplayItem
*p1
= ME_MakeDI(diTextStart
);
246 ME_DisplayItem
*p2
= ME_MakeDI(diTextEnd
);
252 p1
->member
.para
.next_para
= p2
;
253 p2
->member
.para
.prev_para
= p1
;
254 p2
->member
.para
.nCharOfs
= 0;
258 buf
->pCharStyle
= NULL
;
264 static LRESULT
ME_StreamInText(ME_TextEditor
*editor
, DWORD dwFormat
, ME_InStream
*stream
, ME_Style
*style
)
266 WCHAR wszText
[STREAMIN_BUFFER_SIZE
+1];
269 TRACE("%08lx %p\n", dwFormat
, stream
);
276 ME_StreamInFill(stream
);
277 if (stream
->editstream
->dwError
)
283 if (!(dwFormat
& SF_UNICODE
))
285 /* FIXME? this is doomed to fail on true MBCS like UTF-8, luckily they're unlikely to be used as CP_ACP */
286 nWideChars
= MultiByteToWideChar(CP_ACP
, 0, stream
->buffer
, stream
->dwSize
, wszText
, STREAMIN_BUFFER_SIZE
);
291 nWideChars
= stream
->dwSize
>> 1;
292 pText
= (WCHAR
*)stream
->buffer
;
295 ME_InsertTextFromCursor(editor
, 0, pText
, nWideChars
, style
);
296 if (stream
->dwSize
== 0)
300 ME_CommitUndo(editor
);
301 ME_UpdateRepaint(editor
);
305 static void ME_RTFCharAttrHook(RTF_Info
*info
)
308 fmt
.cbSize
= sizeof(fmt
);
311 switch(info
->rtfMinor
)
314 /* FIXME add more flags once they're implemented */
315 fmt
.dwMask
= CFM_BOLD
| CFM_ITALIC
| CFM_UNDERLINE
| CFM_STRIKEOUT
| CFM_COLOR
| CFM_BACKCOLOR
| CFM_SIZE
| CFM_WEIGHT
;
316 fmt
.dwEffects
= CFE_AUTOCOLOR
| CFE_AUTOBACKCOLOR
;
317 fmt
.yHeight
= 12*20; /* 12pt */
321 fmt
.dwMask
= CFM_BOLD
;
322 fmt
.dwEffects
= info
->rtfParam
? fmt
.dwMask
: 0;
325 fmt
.dwMask
= CFM_ITALIC
;
326 fmt
.dwEffects
= info
->rtfParam
? fmt
.dwMask
: 0;
329 fmt
.dwMask
= CFM_UNDERLINE
;
330 fmt
.dwEffects
= info
->rtfParam
? fmt
.dwMask
: 0;
331 fmt
.bUnderlineType
= CFU_CF1UNDERLINE
;
334 fmt
.dwMask
= CFM_UNDERLINE
;
338 fmt
.dwMask
= CFM_STRIKEOUT
;
339 fmt
.dwEffects
= info
->rtfParam
? fmt
.dwMask
: 0;
343 case rtfSubScrShrink
:
344 case rtfSuperScrShrink
:
346 fmt
.dwMask
= CFM_SUBSCRIPT
|CFM_SUPERSCRIPT
;
347 if (info
->rtfMinor
== rtfSubScrShrink
) fmt
.dwEffects
= CFE_SUBSCRIPT
;
348 if (info
->rtfMinor
== rtfSuperScrShrink
) fmt
.dwEffects
= CFE_SUPERSCRIPT
;
349 if (info
->rtfMinor
== rtfNoSuperSub
) fmt
.dwEffects
= 0;
352 fmt
.dwMask
= CFM_HIDDEN
;
353 fmt
.dwEffects
= info
->rtfParam
? fmt
.dwMask
: 0;
356 fmt
.dwMask
= CFM_BACKCOLOR
;
358 if (info
->rtfParam
== 0)
359 fmt
.dwEffects
= CFE_AUTOBACKCOLOR
;
360 else if (info
->rtfParam
!= rtfNoParam
)
362 RTFColor
*c
= RTFGetColor(info
, info
->rtfParam
);
363 fmt
.crTextColor
= (c
->rtfCBlue
<<16)|(c
->rtfCGreen
<<8)|(c
->rtfCRed
);
367 fmt
.dwMask
= CFM_COLOR
;
369 if (info
->rtfParam
== 0)
370 fmt
.dwEffects
= CFE_AUTOCOLOR
;
371 else if (info
->rtfParam
!= rtfNoParam
)
373 RTFColor
*c
= RTFGetColor(info
, info
->rtfParam
);
374 fmt
.crTextColor
= (c
->rtfCBlue
<<16)|(c
->rtfCGreen
<<8)|(c
->rtfCRed
);
378 if (info
->rtfParam
!= rtfNoParam
)
380 RTFFont
*f
= RTFGetFont(info
, info
->rtfParam
);
383 MultiByteToWideChar(CP_ACP
, 0, f
->rtfFName
, -1, fmt
.szFaceName
, sizeof(fmt
.szFaceName
)/sizeof(WCHAR
));
384 fmt
.szFaceName
[sizeof(fmt
.szFaceName
)/sizeof(WCHAR
)-1] = '\0';
385 fmt
.bCharSet
= f
->rtfFCharSet
;
386 fmt
.dwMask
= CFM_FACE
| CFM_CHARSET
;
391 fmt
.dwMask
= CFM_SIZE
;
392 if (info
->rtfParam
!= rtfNoParam
)
393 fmt
.yHeight
= info
->rtfParam
*10;
398 RTFFlushOutputBuffer(info
);
399 /* FIXME too slow ? how come ? */
400 style2
= ME_ApplyStyle(info
->style
, &fmt
);
401 ME_ReleaseStyle(info
->style
);
402 info
->style
= style2
;
403 info
->styleChanged
= TRUE
;
407 /* FIXME this function doesn't get any information about context of the RTF tag, which is very bad,
408 the same tags mean different things in different contexts */
409 static void ME_RTFParAttrHook(RTF_Info
*info
)
412 fmt
.cbSize
= sizeof(fmt
);
415 switch(info
->rtfMinor
)
417 case rtfParDef
: /* restores default paragraph attributes */
418 fmt
.dwMask
= PFM_ALIGNMENT
| PFM_TABSTOPS
| PFM_OFFSET
| PFM_STARTINDENT
;
419 fmt
.wAlignment
= PFA_LEFT
;
421 fmt
.dxOffset
= fmt
.dxStartIndent
= 0;
422 RTFFlushOutputBuffer(info
);
423 ME_GetParagraph(info
->editor
->pCursors
[0].pRun
)->member
.para
.bTable
= FALSE
;
427 ME_DisplayItem
*para
;
429 RTFFlushOutputBuffer(info
);
430 para
= ME_GetParagraph(info
->editor
->pCursors
[0].pRun
);
431 assert(para
->member
.para
.pCells
);
432 para
->member
.para
.bTable
= TRUE
;
436 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
437 fmt
.dwMask
= PFM_STARTINDENT
| PFM_OFFSET
;
438 fmt
.dxStartIndent
+= info
->rtfParam
+ fmt
.dxOffset
;
439 fmt
.dxOffset
= -info
->rtfParam
;
442 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
443 fmt
.dwMask
= PFM_STARTINDENT
;
444 fmt
.dxStartIndent
= -fmt
.dxOffset
+ info
->rtfParam
;
447 fmt
.dwMask
= PFM_RIGHTINDENT
;
448 fmt
.dxRightIndent
= info
->rtfParam
;
452 fmt
.dwMask
= PFM_ALIGNMENT
;
453 fmt
.wAlignment
= PFA_LEFT
;
456 fmt
.dwMask
= PFM_ALIGNMENT
;
457 fmt
.wAlignment
= PFA_RIGHT
;
460 fmt
.dwMask
= PFM_ALIGNMENT
;
461 fmt
.wAlignment
= PFA_CENTER
;
464 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
465 if (!(fmt
.dwMask
& PFM_TABSTOPS
))
467 fmt
.dwMask
|= PFM_TABSTOPS
;
470 if (fmt
.cTabCount
< MAX_TAB_STOPS
)
471 fmt
.rgxTabs
[fmt
.cTabCount
++] = info
->rtfParam
;
475 RTFFlushOutputBuffer(info
);
476 /* FIXME too slow ? how come ?*/
477 ME_SetSelectionParaFormat(info
->editor
, &fmt
);
481 static void ME_RTFTblAttrHook(RTF_Info
*info
)
483 ME_DisplayItem
*para
;
485 switch (info
->rtfMinor
)
488 RTFFlushOutputBuffer(info
);
489 para
= ME_GetParagraph(info
->editor
->pCursors
[0].pRun
);
491 para
->member
.para
.pCells
= ALLOC_OBJ(ME_TableCell
);
492 para
->member
.para
.pCells
->nRightBoundary
= 0;
493 para
->member
.para
.pCells
->next
= NULL
;
494 para
->member
.para
.pLastCell
= para
->member
.para
.pCells
;
497 RTFFlushOutputBuffer(info
);
498 para
= ME_GetParagraph(info
->editor
->pCursors
[0].pRun
);
500 if (para
->member
.para
.pLastCell
->nRightBoundary
)
502 ME_TableCell
*pCell
= ALLOC_OBJ(ME_TableCell
);
505 para
->member
.para
.pLastCell
->next
= pCell
;
506 para
->member
.para
.pLastCell
= pCell
;
508 para
->member
.para
.pLastCell
->nRightBoundary
= info
->rtfParam
;
513 static void ME_RTFReadHook(RTF_Info
*info
) {
514 switch(info
->rtfClass
)
517 switch(info
->rtfMajor
)
520 if (info
->stackTop
< maxStack
) {
521 memcpy(&info
->stack
[info
->stackTop
].fmt
, &info
->style
->fmt
, sizeof(CHARFORMAT2W
));
522 info
->stack
[info
->stackTop
].codePage
= info
->codePage
;
523 info
->stack
[info
->stackTop
].unicodeLength
= info
->unicodeLength
;
526 info
->styleChanged
= FALSE
;
531 RTFFlushOutputBuffer(info
);
532 if (info
->stackTop
<=1) {
533 info
->rtfClass
= rtfEOF
;
537 assert(info
->stackTop
>= 0);
538 if (info
->styleChanged
)
540 /* FIXME too slow ? how come ? */
541 s
= ME_ApplyStyle(info
->style
, &info
->stack
[info
->stackTop
].fmt
);
542 ME_ReleaseStyle(info
->style
);
544 info
->codePage
= info
->stack
[info
->stackTop
].codePage
;
545 info
->unicodeLength
= info
->stack
[info
->stackTop
].unicodeLength
;
552 switch(info
->rtfMajor
)
555 ME_RTFCharAttrHook(info
);
558 ME_RTFParAttrHook(info
);
561 ME_RTFTblAttrHook(info
);
564 if (info
->rtfMinor
== rtfCell
)
566 RTFFlushOutputBuffer(info
);
567 ME_InsertTableCellFromCursor(info
->editor
, 0);
575 ME_StreamInFill(ME_InStream
*stream
)
577 stream
->editstream
->dwError
= stream
->editstream
->pfnCallback(stream
->editstream
->dwCookie
,
578 (BYTE
*)stream
->buffer
,
579 sizeof(stream
->buffer
),
580 (LONG
*)&stream
->dwSize
);
584 static LRESULT
ME_StreamIn(ME_TextEditor
*editor
, DWORD format
, EDITSTREAM
*stream
)
588 int from
, to
, to2
, nUndoMode
;
590 int nEventMask
= editor
->nEventMask
;
591 ME_InStream inStream
;
593 TRACE("stream==%p hWnd==%p format==0x%X\n", stream
, editor
->hWnd
, (UINT
)format
);
594 editor
->nEventMask
= 0;
596 ME_GetSelection(editor
, &from
, &to
);
597 if ((format
& SFF_SELECTION
) && (editor
->mode
& TM_RICHTEXT
)) {
598 style
= ME_GetSelectionInsertStyle(editor
);
600 ME_InternalDeleteText(editor
, from
, to
-from
);
603 style
= editor
->pBuffer
->pDefaultStyle
;
604 ME_AddRefStyle(style
);
605 SendMessageA(editor
->hWnd
, EM_SETSEL
, 0, 0);
606 ME_InternalDeleteText(editor
, 0, ME_GetTextLength(editor
));
608 ME_ClearTempStyle(editor
);
609 /* FIXME restore default paragraph formatting ! */
612 nUndoMode
= editor
->nUndoMode
;
613 editor
->nUndoMode
= umIgnore
;
615 inStream
.editstream
= stream
;
616 inStream
.editstream
->dwError
= 0;
622 /* Check if it's really RTF, and if it is not, use plain text */
623 ME_StreamInFill(&inStream
);
624 if (!inStream
.editstream
->dwError
)
626 if (strncmp(inStream
.buffer
, "{\\rtf1", 6) && strncmp(inStream
.buffer
, "{\\urtf", 6))
634 if (!inStream
.editstream
->dwError
)
636 if (format
& SF_RTF
) {
637 /* setup the RTF parser */
638 memset(&parser
, 0, sizeof parser
);
639 RTFSetEditStream(&parser
, &inStream
);
640 parser
.rtfFormat
= format
&(SF_TEXT
|SF_RTF
);
641 parser
.hwndEdit
= editor
->hWnd
;
642 parser
.editor
= editor
;
643 parser
.style
= style
;
646 RTFSetReadHook(&parser
, ME_RTFReadHook
);
651 RTFFlushOutputBuffer(&parser
);
654 style
= parser
.style
;
656 else if (format
& SF_TEXT
)
657 ME_StreamInText(editor
, format
, &inStream
, style
);
659 ERR("EM_STREAMIN without SF_TEXT or SF_RTF\n");
660 ME_GetSelection(editor
, &to
, &to2
);
661 /* put the cursor at the top */
662 if (!(format
& SFF_SELECTION
))
663 SendMessageA(editor
->hWnd
, EM_SETSEL
, 0, 0);
666 editor
->nUndoMode
= nUndoMode
;
667 if (format
& SFF_SELECTION
)
669 pUI
= ME_AddUndoItem(editor
, diUndoDeleteRun
, NULL
);
670 TRACE("from %d to %d\n", from
, to
);
671 if (pUI
&& from
< to
)
676 ME_CommitUndo(editor
);
680 ME_EmptyUndoStack(editor
);
683 ME_ReleaseStyle(style
);
684 editor
->nEventMask
= nEventMask
;
687 ME_UpdateRepaint(editor
);
689 if (!(format
& SFF_SELECTION
)) {
690 ME_ClearTempStyle(editor
);
692 ME_MoveCaret(editor
);
693 ME_SendSelChange(editor
);
694 ME_SendRequestResize(editor
, FALSE
);
700 typedef struct tagME_RTFStringStreamStruct
705 } ME_RTFStringStreamStruct
;
707 static DWORD CALLBACK
ME_ReadFromRTFString(DWORD_PTR dwCookie
, LPBYTE lpBuff
, LONG cb
, LONG
*pcb
)
709 ME_RTFStringStreamStruct
*pStruct
= (ME_RTFStringStreamStruct
*)dwCookie
;
712 count
= min(cb
, pStruct
->length
- pStruct
->pos
);
713 memmove(lpBuff
, pStruct
->string
+ pStruct
->pos
, count
);
714 pStruct
->pos
+= count
;
720 ME_StreamInRTFString(ME_TextEditor
*editor
, BOOL selection
, char *string
)
723 ME_RTFStringStreamStruct data
;
725 data
.string
= string
;
726 data
.length
= strlen(string
);
728 es
.dwCookie
= (DWORD
)&data
;
729 es
.pfnCallback
= ME_ReadFromRTFString
;
730 ME_StreamIn(editor
, SF_RTF
| (selection
? SFF_SELECTION
: 0), &es
);
735 ME_FindItemAtOffset(ME_TextEditor
*editor
, ME_DIType nItemType
, int nOffset
, int *nItemOffset
)
737 ME_DisplayItem
*item
= ME_FindItemFwd(editor
->pBuffer
->pFirst
, diParagraph
);
739 while (item
&& item
->member
.para
.next_para
->member
.para
.nCharOfs
<= nOffset
)
740 item
= ME_FindItemFwd(item
, diParagraph
);
745 nOffset
-= item
->member
.para
.nCharOfs
;
746 if (nItemType
== diParagraph
) {
748 *nItemOffset
= nOffset
;
753 item
= ME_FindItemFwd(item
, diRun
);
754 } while (item
&& (item
->member
.run
.nCharOfs
+ ME_StrLen(item
->member
.run
.strText
) <= nOffset
));
756 nOffset
-= item
->member
.run
.nCharOfs
;
758 *nItemOffset
= nOffset
;
765 ME_FindText(ME_TextEditor
*editor
, DWORD flags
, CHARRANGE
*chrg
, WCHAR
*text
, CHARRANGE
*chrgText
)
768 int nLen
= lstrlenW(text
);
770 ME_DisplayItem
*item
;
771 ME_DisplayItem
*para
;
773 TRACE("flags==0x%08lx, chrg->cpMin==%ld, chrg->cpMax==%ld text==%s\n",
774 flags
, chrg
->cpMin
, chrg
->cpMax
, debugstr_w(text
));
776 if (flags
& ~(FR_DOWN
| FR_MATCHCASE
))
777 FIXME("Flags 0x%08lx not implemented\n", flags
& ~(FR_DOWN
| FR_MATCHCASE
));
780 if (chrg
->cpMax
== -1)
781 nMax
= ME_GetTextLength(editor
);
785 /* when searching up, if cpMin < cpMax, then instead of searching
786 * on [cpMin,cpMax], we search on [0,cpMin], otherwise, search on
789 if (!(flags
& FR_DOWN
))
800 if (!nLen
|| nMin
< 0 || nMax
< 0 || nMax
< nMin
)
803 chrgText
->cpMin
= chrgText
->cpMax
= -1;
807 if (flags
& FR_DOWN
) /* Forward search */
810 item
= ME_FindItemAtOffset(editor
, diRun
, nStart
, &nStart
);
814 chrgText
->cpMin
= chrgText
->cpMax
= -1;
818 para
= ME_GetParagraph(item
);
820 && para
->member
.para
.nCharOfs
+ item
->member
.run
.nCharOfs
+ nStart
+ nLen
<= nMax
)
822 ME_DisplayItem
*pCurItem
= item
;
823 int nCurStart
= nStart
;
826 while (pCurItem
&& ME_CharCompare(pCurItem
->member
.run
.strText
->szData
[nCurStart
+ nMatched
], text
[nMatched
], (flags
& FR_MATCHCASE
)))
829 if (nMatched
== nLen
)
831 nStart
+= para
->member
.para
.nCharOfs
+ item
->member
.run
.nCharOfs
;
834 chrgText
->cpMin
= nStart
;
835 chrgText
->cpMax
= nStart
+ nLen
;
837 TRACE("found at %d-%d\n", nStart
, nStart
+ nLen
);
840 if (nCurStart
+ nMatched
== ME_StrLen(pCurItem
->member
.run
.strText
))
842 pCurItem
= ME_FindItemFwd(pCurItem
, diRun
);
843 para
= ME_GetParagraph(pCurItem
);
844 nCurStart
= -nMatched
;
848 if (nStart
== ME_StrLen(item
->member
.run
.strText
))
850 item
= ME_FindItemFwd(item
, diRun
);
851 para
= ME_GetParagraph(item
);
856 else /* Backward search */
859 item
= ME_FindItemAtOffset(editor
, diRun
, nEnd
, &nEnd
);
862 chrgText
->cpMin
= chrgText
->cpMax
= -1;
866 para
= ME_GetParagraph(item
);
869 && para
->member
.para
.nCharOfs
+ item
->member
.run
.nCharOfs
+ nEnd
- nLen
>= nMin
)
871 ME_DisplayItem
*pCurItem
= item
;
875 while (ME_CharCompare(pCurItem
->member
.run
.strText
->szData
[nCurEnd
- nMatched
- 1], text
[nLen
- nMatched
- 1], (flags
& FR_MATCHCASE
)))
878 if (nMatched
== nLen
)
880 nStart
= para
->member
.para
.nCharOfs
+ item
->member
.run
.nCharOfs
+ nCurEnd
- nMatched
;
883 chrgText
->cpMin
= nStart
;
884 chrgText
->cpMax
= nStart
+ nLen
;
886 TRACE("found at %d-%d\n", nStart
, nStart
+ nLen
);
889 if (nCurEnd
- nMatched
== 0)
891 pCurItem
= ME_FindItemBack(pCurItem
, diRun
);
892 /* Don't care about pCurItem becoming NULL here; it's already taken
893 * care of in the exterior loop condition */
894 para
= ME_GetParagraph(pCurItem
);
895 nCurEnd
= ME_StrLen(pCurItem
->member
.run
.strText
) + nMatched
;
901 item
= ME_FindItemBack(item
, diRun
);
902 para
= ME_GetParagraph(item
);
903 nEnd
= ME_StrLen(item
->member
.run
.strText
);
907 TRACE("not found\n");
909 chrgText
->cpMin
= chrgText
->cpMax
= -1;
915 ME_KeyDown(ME_TextEditor
*editor
, WORD nKey
)
917 BOOL ctrl_is_down
= GetKeyState(VK_CONTROL
) & 0x8000;
918 BOOL shift_is_down
= GetKeyState(VK_SHIFT
) & 0x8000;
930 ME_ArrowKey(editor
, nKey
, shift_is_down
, ctrl_is_down
);
934 /* FIXME backspace and delete aren't the same, they act different wrt paragraph style of the merged paragraph */
935 if (GetWindowLongW(editor
->hWnd
, GWL_STYLE
) & ES_READONLY
)
937 if (ME_IsSelection(editor
))
938 ME_DeleteSelection(editor
);
939 else if (nKey
== VK_DELETE
|| ME_ArrowKey(editor
, VK_LEFT
, FALSE
, FALSE
))
940 ME_DeleteTextAtCursor(editor
, 1, 1);
943 ME_QueueInvalidateFromCursor(editor
, 1);
944 ME_UpdateRepaint(editor
);
945 ME_SendRequestResize(editor
, FALSE
);
956 ME_GetSelectionCharFormat(editor
, &chf
);
957 ME_DumpStyleToBuf(&chf
, buf
);
958 MessageBoxA(NULL
, buf
, "Style dump", MB_OK
);
962 ME_CheckCharOffsets(editor
);
969 static void ME_ShowContextMenu(ME_TextEditor
*editor
, int x
, int y
)
974 if(!editor
->lpOleCallback
)
976 ME_GetSelection(editor
, (int *)&selrange
.cpMin
, (int *)&selrange
.cpMax
);
977 if(selrange
.cpMin
== selrange
.cpMax
)
978 seltype
|= SEL_EMPTY
;
981 /* FIXME: Handle objects */
983 if(selrange
.cpMax
-selrange
.cpMin
> 1)
984 seltype
|= SEL_MULTICHAR
;
986 if(SUCCEEDED(IRichEditOleCallback_GetContextMenu(editor
->lpOleCallback
, seltype
, NULL
, &selrange
, &menu
)))
988 TrackPopupMenu(menu
, TPM_LEFTALIGN
| TPM_RIGHTBUTTON
, x
, y
, 0, GetParent(editor
->hWnd
), NULL
);
993 ME_TextEditor
*ME_MakeEditor(HWND hWnd
) {
994 ME_TextEditor
*ed
= ALLOC_OBJ(ME_TextEditor
);
998 ed
->bEmulateVersion10
= FALSE
;
999 ed
->pBuffer
= ME_MakeText();
1001 ME_MakeFirstParagraph(hDC
, ed
->pBuffer
);
1002 ReleaseDC(hWnd
, hDC
);
1003 ed
->bCaretShown
= FALSE
;
1005 ed
->pCursors
= ALLOC_N_OBJ(ME_Cursor
, ed
->nCursors
);
1006 ed
->pCursors
[0].pRun
= ME_FindItemFwd(ed
->pBuffer
->pFirst
, diRun
);
1007 ed
->pCursors
[0].nOffset
= 0;
1008 ed
->pCursors
[1].pRun
= ME_FindItemFwd(ed
->pBuffer
->pFirst
, diRun
);
1009 ed
->pCursors
[1].nOffset
= 0;
1010 ed
->nLastTotalLength
= ed
->nTotalLength
= 0;
1013 ed
->rgbBackColor
= -1;
1014 ed
->hbrBackground
= GetSysColorBrush(COLOR_WINDOW
);
1015 ed
->bCaretAtEnd
= FALSE
;
1017 ed
->nModifyStep
= 0;
1018 ed
->pUndoStack
= ed
->pRedoStack
= NULL
;
1019 ed
->nUndoMode
= umAddToUndo
;
1020 ed
->nParagraphs
= 1;
1021 ed
->nLastSelStart
= ed
->nLastSelEnd
= 0;
1022 ed
->nScrollPosY
= 0;
1023 ed
->nZoomNumerator
= ed
->nZoomDenominator
= 0;
1025 ed
->bHideSelection
= FALSE
;
1026 ed
->nInvalidOfs
= -1;
1027 ed
->pfnWordBreak
= NULL
;
1028 ed
->lpOleCallback
= NULL
;
1029 ed
->mode
= TM_RICHTEXT
| TM_MULTILEVELUNDO
| TM_MULTICODEPAGE
;
1030 GetClientRect(hWnd
, &ed
->rcFormat
);
1031 for (i
=0; i
<HFONT_CACHE_SIZE
; i
++)
1033 ed
->pFontCache
[i
].nRefs
= 0;
1034 ed
->pFontCache
[i
].nAge
= 0;
1035 ed
->pFontCache
[i
].hFont
= NULL
;
1037 ME_CheckCharOffsets(ed
);
1041 typedef struct tagME_GlobalDestStruct
1045 } ME_GlobalDestStruct
;
1047 static DWORD CALLBACK
ME_ReadFromHGLOBALUnicode(DWORD_PTR dwCookie
, LPBYTE lpBuff
, LONG cb
, LONG
*pcb
)
1049 ME_GlobalDestStruct
*pData
= (ME_GlobalDestStruct
*)dwCookie
;
1054 pDest
= (WORD
*)lpBuff
;
1055 pSrc
= (WORD
*)GlobalLock(pData
->hData
);
1056 for (i
= 0; i
<cb
&& pSrc
[pData
->nLength
+i
]; i
++) {
1057 pDest
[i
] = pSrc
[pData
->nLength
+i
];
1059 pData
->nLength
+= i
;
1061 GlobalUnlock(pData
->hData
);
1065 static DWORD CALLBACK
ME_ReadFromHGLOBALRTF(DWORD_PTR dwCookie
, LPBYTE lpBuff
, LONG cb
, LONG
*pcb
)
1067 ME_GlobalDestStruct
*pData
= (ME_GlobalDestStruct
*)dwCookie
;
1072 pSrc
= (BYTE
*)GlobalLock(pData
->hData
);
1073 for (i
= 0; i
<cb
&& pSrc
[pData
->nLength
+i
]; i
++) {
1074 pDest
[i
] = pSrc
[pData
->nLength
+i
];
1076 pData
->nLength
+= i
;
1078 GlobalUnlock(pData
->hData
);
1083 void ME_DestroyEditor(ME_TextEditor
*editor
)
1085 ME_DisplayItem
*pFirst
= editor
->pBuffer
->pFirst
;
1086 ME_DisplayItem
*p
= pFirst
, *pNext
= NULL
;
1089 ME_ClearTempStyle(editor
);
1090 ME_EmptyUndoStack(editor
);
1093 ME_DestroyDisplayItem(p
);
1096 ME_ReleaseStyle(editor
->pBuffer
->pDefaultStyle
);
1097 for (i
=0; i
<HFONT_CACHE_SIZE
; i
++)
1099 if (editor
->pFontCache
[i
].hFont
)
1100 DeleteObject(editor
->pFontCache
[i
].hFont
);
1102 DeleteObject(editor
->hbrBackground
);
1103 if(editor
->lpOleCallback
)
1104 IUnknown_Release(editor
->lpOleCallback
);
1109 static const WCHAR wszClassName
[] = {'R', 'i', 'c', 'h', 'E', 'd', 'i', 't', '2', '0', 'W', 0};
1110 static const WCHAR wszClassName50
[] = {'R', 'i', 'c', 'h', 'E', 'd', 'i', 't', '5', '0', 'W', 0};
1111 static const WCHAR wszClassNameListBox
[] = {'R','E','L','i','s','t','B','o','x','2','0','W', 0};
1112 static const WCHAR wszClassNameComboBox
[] = {'R','E','C','o','m','b','o','B','o','x','2','0','W', 0};
1114 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
1119 case DLL_PROCESS_ATTACH
:
1120 DisableThreadLibraryCalls(hinstDLL
);
1121 me_heap
= HeapCreate (0, 0x10000, 0);
1122 ME_RegisterEditorClass(hinstDLL
);
1125 case DLL_PROCESS_DETACH
:
1126 UnregisterClassW(wszClassName
, 0);
1127 UnregisterClassW(wszClassName50
, 0);
1128 UnregisterClassA("RichEdit20A", 0);
1129 UnregisterClassA("RichEdit50A", 0);
1130 if (ME_ListBoxRegistered
)
1131 UnregisterClassW(wszClassNameListBox
, 0);
1132 if (ME_ComboBoxRegistered
)
1133 UnregisterClassW(wszClassNameComboBox
, 0);
1134 HeapDestroy (me_heap
);
1142 #define UNSUPPORTED_MSG(e) \
1144 FIXME(#e ": stub\n"); \
1145 return DefWindowProcW(hWnd, msg, wParam, lParam);
1147 static const char * const edit_messages
[] = {
1176 "EM_SETPASSWORDCHAR",
1177 "EM_EMPTYUNDOBUFFER",
1178 "EM_GETFIRSTVISIBLELINE",
1180 "EM_SETWORDBREAKPROC",
1181 "EM_GETWORDBREAKPROC",
1182 "EM_GETPASSWORDCHAR",
1190 static const char * const richedit_messages
[] = {
1195 "EM_EXLINEFROMCHAR",
1201 "EM_GETOLEINTERFACE",
1211 "EM_SETOLECALLBACK",
1213 "EM_SETTARGETDEVICE",
1221 "EM_GETWORDBREAKPROCEX",
1222 "EM_SETWORDBREAKPROCEX",
1224 "EM_UNKNOWN_USER_83",
1229 "EM_STOPGROUPTYPING",
1233 "EM_GETAUTOURLDETECT",
1236 "EM_GETTEXTLENGTHEX",
1239 "EM_UNKNOWN_USER_98",
1240 "EM_UNKNOWN_USER_99",
1241 "EM_SETPUNCTUATION",
1242 "EM_GETPUNCTUATION",
1243 "EM_SETWORDWRAPMODE",
1244 "EM_GETWORDWRAPMODE",
1250 "EM_UNKNOWN_USER_109",
1251 "EM_UNKNOWN_USER_110",
1252 "EM_UNKNOWN_USER_111",
1253 "EM_UNKNOWN_USER_112",
1254 "EM_UNKNOWN_USER_113",
1255 "EM_UNKNOWN_USER_114",
1256 "EM_UNKNOWN_USER_115",
1257 "EM_UNKNOWN_USER_116",
1258 "EM_UNKNOWN_USER_117",
1259 "EM_UNKNOWN_USER_118",
1260 "EM_UNKNOWN_USER_119",
1261 "EM_SETLANGOPTIONS",
1262 "EM_GETLANGOPTIONS",
1263 "EM_GETIMECOMPMODE",
1267 "EM_SETIMEMODEBIAS",
1272 get_msg_name(UINT msg
)
1274 if (msg
>= EM_GETSEL
&& msg
<= EM_SETLIMITTEXT
)
1275 return edit_messages
[msg
- EM_GETSEL
];
1276 if (msg
>= EM_CANPASTE
&& msg
<= EM_GETIMEMODEBIAS
)
1277 return richedit_messages
[msg
- EM_CANPASTE
];
1281 /******************************************************************
1282 * RichEditANSIWndProc (RICHED20.10)
1284 LRESULT WINAPI
RichEditANSIWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
) {
1286 ME_TextEditor
*editor
= (ME_TextEditor
*)GetWindowLongW(hWnd
, 0);
1288 TRACE("hWnd %p msg %04x (%s) %08x %08lx\n",
1289 hWnd
, msg
, get_msg_name(msg
), wParam
, lParam
);
1293 UNSUPPORTED_MSG(EM_DISPLAYBAND
)
1294 UNSUPPORTED_MSG(EM_EXLIMITTEXT
)
1295 UNSUPPORTED_MSG(EM_FINDWORDBREAK
)
1296 UNSUPPORTED_MSG(EM_FMTLINES
)
1297 UNSUPPORTED_MSG(EM_FORMATRANGE
)
1298 UNSUPPORTED_MSG(EM_GETBIDIOPTIONS
)
1299 UNSUPPORTED_MSG(EM_GETEDITSTYLE
)
1300 UNSUPPORTED_MSG(EM_GETIMECOMPMODE
)
1301 /* UNSUPPORTED_MSG(EM_GETIMESTATUS) missing in Wine headers */
1302 UNSUPPORTED_MSG(EM_GETLANGOPTIONS
)
1303 UNSUPPORTED_MSG(EM_GETLIMITTEXT
)
1304 UNSUPPORTED_MSG(EM_GETLINE
)
1305 /* UNSUPPORTED_MSG(EM_GETOLEINTERFACE) separate stub */
1306 UNSUPPORTED_MSG(EM_GETPASSWORDCHAR
)
1307 UNSUPPORTED_MSG(EM_GETREDONAME
)
1308 UNSUPPORTED_MSG(EM_GETTEXTMODE
)
1309 UNSUPPORTED_MSG(EM_GETTYPOGRAPHYOPTIONS
)
1310 UNSUPPORTED_MSG(EM_GETUNDONAME
)
1311 UNSUPPORTED_MSG(EM_GETWORDBREAKPROCEX
)
1312 UNSUPPORTED_MSG(EM_LIMITTEXT
) /* also known as EM_SETLIMITTEXT */
1313 UNSUPPORTED_MSG(EM_PASTESPECIAL
)
1314 UNSUPPORTED_MSG(EM_SELECTIONTYPE
)
1315 UNSUPPORTED_MSG(EM_SETBIDIOPTIONS
)
1316 UNSUPPORTED_MSG(EM_SETEDITSTYLE
)
1317 UNSUPPORTED_MSG(EM_SETFONTSIZE
)
1318 UNSUPPORTED_MSG(EM_SETLANGOPTIONS
)
1319 UNSUPPORTED_MSG(EM_SETPALETTE
)
1320 UNSUPPORTED_MSG(EM_SETPASSWORDCHAR
)
1321 UNSUPPORTED_MSG(EM_SETSCROLLPOS
)
1322 UNSUPPORTED_MSG(EM_SETTABSTOPS
)
1323 UNSUPPORTED_MSG(EM_SETTARGETDEVICE
)
1324 UNSUPPORTED_MSG(EM_SETTYPOGRAPHYOPTIONS
)
1325 UNSUPPORTED_MSG(EM_SETUNDOLIMIT
)
1326 UNSUPPORTED_MSG(EM_SETWORDBREAKPROCEX
)
1327 UNSUPPORTED_MSG(EM_SHOWSCROLLBAR
)
1328 UNSUPPORTED_MSG(WM_SETFONT
)
1329 UNSUPPORTED_MSG(WM_STYLECHANGING
)
1330 UNSUPPORTED_MSG(WM_STYLECHANGED
)
1331 /* UNSUPPORTED_MSG(WM_UNICHAR) FIXME missing in Wine headers */
1333 /* Messages specific to Richedit controls */
1336 return ME_StreamIn(editor
, wParam
, (EDITSTREAM
*)lParam
);
1338 return ME_StreamOut(editor
, wParam
, (EDITSTREAM
*)lParam
);
1341 UINT code
= DLGC_WANTCHARS
|DLGC_WANTARROWS
;
1342 if (GetWindowLongW(hWnd
, GWL_STYLE
)&ES_WANTRETURN
)
1343 code
|= 0; /* FIXME what can we do here ? ask for messages and censor them ? */
1348 CREATESTRUCTW
*pcs
= (CREATESTRUCTW
*)lParam
;
1349 TRACE("WM_NCCREATE: style 0x%08lx\n", pcs
->style
);
1350 editor
= ME_MakeEditor(hWnd
);
1351 SetWindowLongW(hWnd
, 0, (long)editor
);
1352 pcs
= 0; /* ignore */
1355 case EM_EMPTYUNDOBUFFER
:
1356 ME_EmptyUndoStack(editor
);
1360 /* Note: wParam/lParam can be NULL */
1362 PUINT pfrom
= wParam
? (PUINT
)wParam
: &from
;
1363 PUINT pto
= lParam
? (PUINT
)lParam
: &to
;
1364 ME_GetSelection(editor
, (int *)pfrom
, (int *)pto
);
1365 if ((*pfrom
|*pto
) & 0xFFFF0000)
1367 return MAKELONG(*pfrom
,*pto
);
1371 CHARRANGE
*pRange
= (CHARRANGE
*)lParam
;
1372 ME_GetSelection(editor
, (int *)&pRange
->cpMin
, (int *)&pRange
->cpMax
);
1373 TRACE("EM_EXGETSEL = (%ld,%ld)\n", pRange
->cpMin
, pRange
->cpMax
);
1377 return editor
->pUndoStack
!= NULL
;
1379 return editor
->pRedoStack
!= NULL
;
1380 case WM_UNDO
: /* FIXME: actually not the same */
1389 /* these flags are equivalent to the ES_* counterparts */
1390 DWORD mask
= ECO_VERTICAL
| ECO_AUTOHSCROLL
| ECO_AUTOVSCROLL
|
1391 ECO_NOHIDESEL
| ECO_READONLY
| ECO_WANTRETURN
;
1392 DWORD settings
= GetWindowLongW(hWnd
, GWL_STYLE
) & mask
;
1398 /* these flags are equivalent to ES_* counterparts
1399 * ECO_READONLY is already implemented in the code, only requires
1400 * setting the bit to work
1402 DWORD mask
= ECO_VERTICAL
| ECO_AUTOHSCROLL
| ECO_AUTOVSCROLL
|
1403 ECO_NOHIDESEL
| ECO_READONLY
| ECO_WANTRETURN
;
1404 DWORD raw
= GetWindowLongW(hWnd
, GWL_STYLE
);
1405 DWORD settings
= mask
& raw
;
1421 SetWindowLongW(hWnd
, GWL_STYLE
, (raw
& ~mask
) | (settings
& mask
));
1423 if (lParam
& ECO_AUTOWORDSELECTION
)
1424 FIXME("ECO_AUTOWORDSELECTION not implemented yet!\n");
1425 if (lParam
& ECO_SELECTIONBAR
)
1426 FIXME("ECO_SELECTIONBAR not implemented yet!\n");
1427 if (lParam
& ECO_VERTICAL
)
1428 FIXME("ECO_VERTICAL not implemented yet!\n");
1429 if (lParam
& ECO_AUTOHSCROLL
)
1430 FIXME("ECO_AUTOHSCROLL not implemented yet!\n");
1431 if (lParam
& ECO_AUTOVSCROLL
)
1432 FIXME("ECO_AUTOVSCROLL not implemented yet!\n");
1433 if (lParam
& ECO_NOHIDESEL
)
1434 FIXME("ECO_NOHIDESEL not implemented yet!\n");
1435 if (lParam
& ECO_WANTRETURN
)
1436 FIXME("ECO_WANTRETURN not implemented yet!\n");
1442 ME_InvalidateSelection(editor
);
1443 ME_SetSelection(editor
, wParam
, lParam
);
1444 ME_InvalidateSelection(editor
);
1445 ME_SendSelChange(editor
);
1448 case EM_AUTOURLDETECT
:
1450 if (wParam
==1 || wParam
==0)
1452 editor
->AutoURLDetect_bEnable
= (BOOL
)wParam
;
1455 return E_INVALIDARG
;
1457 case EM_GETAUTOURLDETECT
:
1459 return editor
->AutoURLDetect_bEnable
;
1463 CHARRANGE
*pRange
= (CHARRANGE
*)lParam
;
1464 TRACE("EM_EXSETSEL (%ld,%ld)\n", pRange
->cpMin
, pRange
->cpMax
);
1465 ME_InvalidateSelection(editor
);
1466 ME_SetSelection(editor
, pRange
->cpMin
, pRange
->cpMax
);
1467 ME_InvalidateSelection(editor
);
1468 ME_SendSelChange(editor
);
1473 LPWSTR wszText
= (LPWSTR
)lParam
;
1474 SETTEXTEX
*pStruct
= (SETTEXTEX
*)wParam
;
1475 size_t len
= lstrlenW(wszText
);
1478 TRACE("EM_SETTEXEX - %s, flags %d, cp %d\n", debugstr_w(wszText
), (int)pStruct
->flags
, pStruct
->codepage
);
1479 if (pStruct
->codepage
!= 1200) {
1480 FIXME("EM_SETTEXTEX only supports unicode right now!\n");
1483 /* FIXME: this should support RTF strings too, according to MSDN */
1484 if (pStruct
->flags
& ST_SELECTION
) {
1485 ME_GetSelection(editor
, &from
, &to
);
1486 style
= ME_GetSelectionInsertStyle(editor
);
1487 ME_InternalDeleteText(editor
, from
, to
- from
);
1488 ME_InsertTextFromCursor(editor
, 0, wszText
, len
, style
);
1489 ME_ReleaseStyle(style
);
1492 ME_InternalDeleteText(editor
, 0, ME_GetTextLength(editor
));
1493 ME_InsertTextFromCursor(editor
, 0, wszText
, -1, editor
->pBuffer
->pDefaultStyle
);
1496 ME_CommitUndo(editor
);
1497 if (!(pStruct
->flags
& ST_KEEPUNDO
))
1498 ME_EmptyUndoStack(editor
);
1499 ME_UpdateRepaint(editor
);
1502 case EM_SETBKGNDCOLOR
:
1504 LRESULT lColor
= ME_GetBackColor(editor
);
1505 if (editor
->rgbBackColor
!= -1)
1506 DeleteObject(editor
->hbrBackground
);
1509 editor
->rgbBackColor
= -1;
1510 editor
->hbrBackground
= GetSysColorBrush(COLOR_WINDOW
);
1514 editor
->rgbBackColor
= lParam
;
1515 editor
->hbrBackground
= CreateSolidBrush(editor
->rgbBackColor
);
1517 if (editor
->bRedraw
)
1519 InvalidateRect(hWnd
, NULL
, TRUE
);
1525 return editor
->nModifyStep
== 0 ? 0 : 1;
1529 editor
->nModifyStep
= 0x80000000;
1531 editor
->nModifyStep
= 0;
1535 case EM_SETREADONLY
:
1537 long nStyle
= GetWindowLongW(hWnd
, GWL_STYLE
);
1539 nStyle
|= ES_READONLY
;
1541 nStyle
&= ~ES_READONLY
;
1542 SetWindowLongW(hWnd
, GWL_STYLE
, nStyle
);
1545 case EM_SETEVENTMASK
:
1547 DWORD nOldMask
= editor
->nEventMask
;
1549 editor
->nEventMask
= lParam
;
1552 case EM_GETEVENTMASK
:
1553 return editor
->nEventMask
;
1554 case EM_SETCHARFORMAT
:
1556 CHARFORMAT2W buf
, *p
;
1557 BOOL bRepaint
= TRUE
;
1558 p
= ME_ToCF2W(&buf
, (CHARFORMAT2W
*)lParam
);
1559 if (!wParam
|| (editor
->mode
& TM_PLAINTEXT
))
1560 ME_SetDefaultCharFormat(editor
, p
);
1561 else if (wParam
== (SCF_WORD
| SCF_SELECTION
))
1562 FIXME("EM_SETCHARFORMAT: word selection not supported\n");
1563 else if (wParam
== SCF_ALL
)
1564 ME_SetCharFormat(editor
, 0, ME_GetTextLength(editor
), p
);
1567 ME_GetSelection(editor
, &from
, &to
);
1568 bRepaint
= (from
!= to
);
1569 ME_SetSelectionCharFormat(editor
, p
);
1571 ME_CommitUndo(editor
);
1573 ME_UpdateRepaint(editor
);
1576 case EM_GETCHARFORMAT
:
1578 CHARFORMAT2W tmp
, *dst
= (CHARFORMAT2W
*)lParam
;
1579 if (dst
->cbSize
!= sizeof(CHARFORMATA
) &&
1580 dst
->cbSize
!= sizeof(CHARFORMATW
) &&
1581 dst
->cbSize
!= sizeof(CHARFORMAT2A
) &&
1582 dst
->cbSize
!= sizeof(CHARFORMAT2W
))
1584 tmp
.cbSize
= sizeof(tmp
);
1586 ME_GetDefaultCharFormat(editor
, &tmp
);
1588 ME_GetSelectionCharFormat(editor
, &tmp
);
1589 ME_CopyToCFAny(dst
, &tmp
);
1592 case EM_SETPARAFORMAT
:
1593 ME_SetSelectionParaFormat(editor
, (PARAFORMAT2
*)lParam
);
1594 ME_UpdateRepaint(editor
);
1595 ME_CommitUndo(editor
);
1597 case EM_GETPARAFORMAT
:
1598 ME_GetSelectionParaFormat(editor
, (PARAFORMAT2
*)lParam
);
1600 case EM_GETFIRSTVISIBLELINE
:
1602 ME_DisplayItem
*p
= editor
->pBuffer
->pFirst
;
1603 int y
= editor
->nScrollPosY
;
1608 p
= ME_FindItemFwd(p
, diStartRowOrParagraphOrEnd
);
1609 if (p
->type
== diTextEnd
)
1611 if (p
->type
== diParagraph
) {
1612 ypara
= p
->member
.para
.nYPos
;
1615 ystart
= ypara
+ p
->member
.row
.nYPos
;
1616 yend
= ystart
+ p
->member
.row
.nHeight
;
1624 case EM_HIDESELECTION
:
1626 editor
->bHideSelection
= (wParam
!= 0);
1627 ME_InvalidateSelection(editor
);
1632 int nPos
= editor
->nScrollPosY
, nEnd
= editor
->nTotalLength
- editor
->sizeWindow
.cy
;
1633 nPos
+= 8 * lParam
; /* FIXME follow the original */
1638 if (nPos
!= editor
->nScrollPosY
) {
1639 int dy
= editor
->nScrollPosY
- nPos
;
1640 editor
->nScrollPosY
= nPos
;
1641 SetScrollPos(hWnd
, SB_VERT
, nPos
, TRUE
);
1642 if (editor
->bRedraw
)
1644 ScrollWindow(hWnd
, 0, dy
, NULL
, NULL
);
1648 return TRUE
; /* Should return false if a single line richedit control */
1653 ME_GetSelection(editor
, &from
, &to
);
1654 ME_InternalDeleteText(editor
, from
, to
-from
);
1655 ME_CommitUndo(editor
);
1656 ME_UpdateRepaint(editor
);
1663 LPWSTR wszText
= ME_ToUnicode(hWnd
, (void *)lParam
);
1664 size_t len
= lstrlenW(wszText
);
1665 TRACE("EM_REPLACESEL - %s\n", debugstr_w(wszText
));
1667 ME_GetSelection(editor
, &from
, &to
);
1668 style
= ME_GetSelectionInsertStyle(editor
);
1669 ME_InternalDeleteText(editor
, from
, to
-from
);
1670 ME_InsertTextFromCursor(editor
, 0, wszText
, len
, style
);
1671 ME_ReleaseStyle(style
);
1672 ME_EndToUnicode(hWnd
, wszText
);
1673 /* drop temporary style if line end */
1674 /* FIXME question: does abc\n mean: put abc, clear temp style, put \n? (would require a change) */
1675 if (len
>0 && wszText
[len
-1] == '\n')
1676 ME_ClearTempStyle(editor
);
1678 ME_CommitUndo(editor
);
1680 ME_EmptyUndoStack(editor
);
1681 ME_UpdateRepaint(editor
);
1684 case EM_SCROLLCARET
:
1686 int top
, bottom
; /* row's edges relative to document top */
1687 ME_DisplayItem
*para
, *row
;
1689 row
= ME_RowStart(editor
->pCursors
[0].pRun
);
1690 para
= ME_GetParagraph(row
);
1691 top
= para
->member
.para
.nYPos
+ row
->member
.row
.nYPos
;
1692 bottom
= top
+ row
->member
.row
.nHeight
;
1694 if ((top
< editor
->nScrollPosY
)
1695 || (editor
->nScrollPosY
+ editor
->sizeWindow
.cy
< bottom
))
1698 int prevScrollPosY
= editor
->nScrollPosY
;
1700 if (top
< editor
->nScrollPosY
) /* caret above window */
1701 editor
->nScrollPosY
= top
;
1702 else /* caret below window */
1703 editor
->nScrollPosY
= bottom
- editor
->sizeWindow
.cy
;
1705 if (editor
->nScrollPosY
< 0)
1706 editor
->nScrollPosY
= 0;
1708 dy
= prevScrollPosY
- editor
->nScrollPosY
;
1709 SetScrollPos(hWnd
, SB_VERT
, editor
->nScrollPosY
, TRUE
);
1710 if (editor
->bRedraw
)
1712 ScrollWindow(hWnd
, 0, dy
, NULL
, NULL
);
1721 ME_InternalDeleteText(editor
, 0, ME_GetTextLength(editor
));
1724 TRACE("WM_SETTEXT lParam==%lx\n",lParam
);
1725 if (!IsWindowUnicode(hWnd
) && !strncmp((char *)lParam
, "{\\rtf1", 6))
1727 /* Undocumented: WM_SETTEXT supports RTF text */
1728 ME_StreamInRTFString(editor
, 0, (char *)lParam
);
1732 LPWSTR wszText
= ME_ToUnicode(hWnd
, (void *)lParam
);
1733 TRACE("WM_SETTEXT - %s\n", debugstr_w(wszText
)); /* debugstr_w() */
1734 if (lstrlenW(wszText
) > 0)
1736 /* uses default style! */
1737 ME_InsertTextFromCursor(editor
, 0, wszText
, -1, editor
->pBuffer
->pDefaultStyle
);
1739 ME_EndToUnicode(hWnd
, wszText
);
1743 TRACE("WM_SETTEXT - NULL\n");
1744 ME_CommitUndo(editor
);
1745 ME_EmptyUndoStack(editor
);
1746 ME_SetSelection(editor
, 0, 0);
1747 ME_UpdateRepaint(editor
);
1752 UINT nRTFFormat
= RegisterClipboardFormatA("Rich Text Format");
1753 if (IsClipboardFormatAvailable(nRTFFormat
))
1755 if (IsClipboardFormatAvailable(CF_UNICODETEXT
))
1763 ME_GlobalDestStruct gds
;
1764 UINT nRTFFormat
= RegisterClipboardFormatA("Rich Text Format");
1767 if (IsClipboardFormatAvailable(nRTFFormat
))
1768 cf
= nRTFFormat
, dwFormat
= SF_RTF
;
1769 else if (IsClipboardFormatAvailable(CF_UNICODETEXT
))
1770 cf
= CF_UNICODETEXT
, dwFormat
= SF_TEXT
|SF_UNICODE
;
1774 if (!OpenClipboard(hWnd
))
1776 gds
.hData
= GetClipboardData(cf
);
1778 es
.dwCookie
= (DWORD
)&gds
;
1779 es
.pfnCallback
= dwFormat
== SF_RTF
? ME_ReadFromHGLOBALRTF
: ME_ReadFromHGLOBALUnicode
;
1780 ME_StreamIn(editor
, dwFormat
|SFF_SELECTION
, &es
);
1788 LPDATAOBJECT dataObj
= NULL
;
1791 ME_GetSelection(editor
, (int*)&range
.cpMin
, (int*)&range
.cpMax
);
1792 if(editor
->lpOleCallback
)
1793 hr
= IRichEditOleCallback_GetClipboardData(editor
->lpOleCallback
, &range
, RECO_COPY
, &dataObj
);
1794 if(FAILED(hr
) || !dataObj
)
1795 hr
= ME_GetDataObject(editor
, &range
, &dataObj
);
1797 hr
= OleSetClipboard(dataObj
);
1798 IDataObject_Release(dataObj
);
1800 if (SUCCEEDED(hr
) && msg
== WM_CUT
)
1802 ME_InternalDeleteText(editor
, range
.cpMin
, range
.cpMax
-range
.cpMin
);
1803 ME_CommitUndo(editor
);
1804 ME_UpdateRepaint(editor
);
1808 case WM_GETTEXTLENGTH
:
1809 return ME_GetTextLength(editor
);
1810 case EM_GETTEXTLENGTHEX
:
1811 return ME_GetTextLengthEx(editor
, (GETTEXTLENGTHEX
*)wParam
);
1814 TEXTRANGEW tr
; /* W and A differ only by rng->lpstrText */
1816 tr
.chrg
.cpMax
= wParam
-1;
1817 tr
.lpstrText
= (WCHAR
*)lParam
;
1818 return RichEditANSIWndProc(hWnd
, EM_GETTEXTRANGE
, 0, (LPARAM
)&tr
);
1822 GETTEXTEX
*ex
= (GETTEXTEX
*)wParam
;
1825 if (ex
->flags
& ~(GT_SELECTION
| GT_USECRLF
))
1826 FIXME("GETTEXTEX flags 0x%08lx not supported\n", ex
->flags
& ~(GT_SELECTION
| GT_USECRLF
));
1828 if (ex
->flags
& GT_SELECTION
)
1830 ME_GetSelection(editor
, &nStart
, &nCount
);
1832 nCount
= min(nCount
, ex
->cb
- 1);
1837 nCount
= ex
->cb
- 1;
1839 if (ex
->codepage
== 1200 || IsWindowUnicode(hWnd
))
1841 nCount
= min(nCount
, ex
->cb
/ sizeof(WCHAR
) - 1);
1842 return ME_GetTextW(editor
, (LPWSTR
)lParam
, nStart
, nCount
, ex
->flags
& GT_USECRLF
);
1846 /* potentially each char may be a CR, why calculate the exact value with O(N) when
1847 we can just take a bigger buffer? :) */
1848 int crlfmul
= (ex
->flags
& GT_USECRLF
) ? 2 : 1;
1849 LPWSTR buffer
= HeapAlloc(GetProcessHeap(), 0, (crlfmul
*nCount
+ 1) * sizeof(WCHAR
));
1850 DWORD buflen
= ex
->cb
;
1854 buflen
= ME_GetTextW(editor
, buffer
, nStart
, nCount
, ex
->flags
& GT_USECRLF
);
1855 rc
= WideCharToMultiByte(ex
->codepage
, flags
, buffer
, buflen
, (LPSTR
)lParam
, ex
->cb
, ex
->lpDefaultChar
, ex
->lpUsedDefaultChar
);
1857 HeapFree(GetProcessHeap(),0,buffer
);
1864 TEXTRANGEW tr
; /* W and A differ only by rng->lpstrText */
1865 ME_GetSelection(editor
, &from
, &to
);
1866 tr
.chrg
.cpMin
= from
;
1868 tr
.lpstrText
= (WCHAR
*)lParam
;
1869 return RichEditANSIWndProc(hWnd
, EM_GETTEXTRANGE
, 0, (LPARAM
)&tr
);
1871 case EM_GETSCROLLPOS
:
1873 POINT
*point
= (POINT
*)lParam
;
1874 point
->x
= 0; /* FIXME side scrolling not implemented */
1875 point
->y
= editor
->nScrollPosY
;
1878 case EM_GETTEXTRANGE
:
1880 TEXTRANGEW
*rng
= (TEXTRANGEW
*)lParam
;
1881 TRACE("EM_GETTEXTRANGE min=%ld max=%ld unicode=%d emul1.0=%d length=%d\n",
1882 rng
->chrg
.cpMin
, rng
->chrg
.cpMax
, IsWindowUnicode(hWnd
),
1883 editor
->bEmulateVersion10
, ME_GetTextLength(editor
));
1884 if (IsWindowUnicode(hWnd
))
1885 return ME_GetTextW(editor
, rng
->lpstrText
, rng
->chrg
.cpMin
, rng
->chrg
.cpMax
-rng
->chrg
.cpMin
, editor
->bEmulateVersion10
);
1888 int nLen
= rng
->chrg
.cpMax
-rng
->chrg
.cpMin
;
1889 WCHAR
*p
= ALLOC_N_OBJ(WCHAR
, nLen
+1);
1890 int nChars
= ME_GetTextW(editor
, p
, rng
->chrg
.cpMin
, nLen
, editor
->bEmulateVersion10
);
1891 /* FIXME this is a potential security hole (buffer overrun)
1892 if you know more about wchar->mbyte conversion please explain
1894 WideCharToMultiByte(CP_ACP
, 0, p
, nChars
+1, (char *)rng
->lpstrText
, nLen
+1, NULL
, NULL
);
1899 case EM_GETLINECOUNT
:
1901 ME_DisplayItem
*item
= editor
->pBuffer
->pFirst
->next
;
1904 while (item
!= editor
->pBuffer
->pLast
)
1906 assert(item
->type
== diParagraph
);
1907 nRows
+= item
->member
.para
.nRows
;
1908 item
= item
->member
.para
.next_para
;
1910 TRACE("EM_GETLINECOUNT: nRows==%d\n", nRows
);
1911 return max(1, nRows
);
1913 case EM_LINEFROMCHAR
:
1916 return ME_RowNumberFromCharOfs(editor
, ME_GetCursorOfs(editor
, 1));
1918 return ME_RowNumberFromCharOfs(editor
, wParam
);
1920 case EM_EXLINEFROMCHAR
:
1922 return ME_RowNumberFromCharOfs(editor
, lParam
);
1926 ME_DisplayItem
*item
, *para
;
1930 item
= ME_FindItemBack(editor
->pCursors
[0].pRun
, diStartRow
);
1932 item
= ME_FindRowWithNumber(editor
, wParam
);
1935 para
= ME_GetParagraph(item
);
1936 item
= ME_FindItemFwd(item
, diRun
);
1937 nCharOfs
= para
->member
.para
.nCharOfs
+ item
->member
.run
.nCharOfs
;
1938 TRACE("EM_LINEINDEX: nCharOfs==%d\n", nCharOfs
);
1943 ME_DisplayItem
*item
, *item_end
;
1944 int nChars
= 0, nThisLineOfs
= 0, nNextLineOfs
= 0;
1946 if (wParam
> ME_GetTextLength(editor
))
1950 FIXME("EM_LINELENGTH: returning number of unselected characters on lines with selection unsupported.\n");
1953 item
= ME_FindItemAtOffset(editor
, diRun
, wParam
, NULL
);
1954 item
= ME_RowStart(item
);
1955 nThisLineOfs
= ME_CharOfsFromRunOfs(editor
, ME_FindItemFwd(item
, diRun
), 0);
1956 item_end
= ME_FindItemFwd(item
, diStartRow
);
1958 nNextLineOfs
= ME_CharOfsFromRunOfs(editor
, ME_FindItemFwd(item_end
, diRun
), 0);
1960 nNextLineOfs
= ME_FindItemFwd(item
, diParagraphOrEnd
)->member
.para
.nCharOfs
1961 - (editor
->bEmulateVersion10
?2:1);
1962 nChars
= nNextLineOfs
- nThisLineOfs
;
1963 TRACE("EM_LINELENGTH(%d)==%d\n",wParam
, nChars
);
1968 FINDTEXTA
*ft
= (FINDTEXTA
*)lParam
;
1969 int nChars
= MultiByteToWideChar(CP_ACP
, 0, ft
->lpstrText
, -1, NULL
, 0);
1972 if ((tmp
= ALLOC_N_OBJ(WCHAR
, nChars
)) != NULL
)
1973 MultiByteToWideChar(CP_ACP
, 0, ft
->lpstrText
, -1, tmp
, nChars
);
1974 return ME_FindText(editor
, wParam
, &ft
->chrg
, tmp
, NULL
);
1978 FINDTEXTEXA
*ex
= (FINDTEXTEXA
*)lParam
;
1979 int nChars
= MultiByteToWideChar(CP_ACP
, 0, ex
->lpstrText
, -1, NULL
, 0);
1982 if ((tmp
= ALLOC_N_OBJ(WCHAR
, nChars
)) != NULL
)
1983 MultiByteToWideChar(CP_ACP
, 0, ex
->lpstrText
, -1, tmp
, nChars
);
1984 return ME_FindText(editor
, wParam
, &ex
->chrg
, tmp
, &ex
->chrgText
);
1988 FINDTEXTW
*ft
= (FINDTEXTW
*)lParam
;
1989 return ME_FindText(editor
, wParam
, &ft
->chrg
, ft
->lpstrText
, NULL
);
1991 case EM_FINDTEXTEXW
:
1993 FINDTEXTEXW
*ex
= (FINDTEXTEXW
*)lParam
;
1994 return ME_FindText(editor
, wParam
, &ex
->chrg
, ex
->lpstrText
, &ex
->chrgText
);
1997 if (!wParam
|| !lParam
)
1999 *(int *)wParam
= editor
->nZoomNumerator
;
2000 *(int *)lParam
= editor
->nZoomDenominator
;
2003 return ME_SetZoom(editor
, wParam
, lParam
);
2004 case EM_CHARFROMPOS
:
2005 return ME_CharFromPos(editor
, ((POINTL
*)lParam
)->x
, ((POINTL
*)lParam
)->y
);
2006 case EM_POSFROMCHAR
:
2008 ME_DisplayItem
*pRun
;
2009 int nCharOfs
, nOffset
, nLength
;
2013 /* detect which API version we're dealing with */
2014 if (wParam
>= 0x40000)
2016 nLength
= ME_GetTextLength(editor
);
2018 if (nCharOfs
< nLength
) {
2019 ME_RunOfsFromCharOfs(editor
, nCharOfs
, &pRun
, &nOffset
);
2020 assert(pRun
->type
== diRun
);
2021 pt
.y
= pRun
->member
.run
.pt
.y
;
2022 pt
.x
= pRun
->member
.run
.pt
.x
+ ME_PointFromChar(editor
, &pRun
->member
.run
, nOffset
);
2023 pt
.y
+= ME_GetParagraph(pRun
)->member
.para
.nYPos
;
2026 pt
.y
= editor
->pBuffer
->pLast
->member
.para
.nYPos
;
2028 if (wParam
>= 0x40000) {
2029 *(POINTL
*)wParam
= pt
;
2031 return MAKELONG( pt
.x
, pt
.y
);
2034 ME_CommitUndo(editor
);
2035 ME_WrapMarkedParagraphs(editor
);
2036 ME_MoveCaret(editor
);
2039 ME_DestroyEditor(editor
);
2040 SetWindowLongW(hWnd
, 0, 0);
2042 case WM_LBUTTONDOWN
:
2044 ME_LButtonDown(editor
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
2048 if (GetCapture() == hWnd
)
2049 ME_MouseMove(editor
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
2052 if (GetCapture() == hWnd
)
2055 case WM_LBUTTONDBLCLK
:
2056 ME_SelectWord(editor
);
2058 case WM_CONTEXTMENU
:
2059 ME_ShowContextMenu(editor
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
2062 if (editor
->bRedraw
)
2067 hDC
= BeginPaint(hWnd
, &ps
);
2068 ME_PaintContent(editor
, hDC
, FALSE
, &ps
.rcPaint
);
2069 EndPaint(hWnd
, &ps
);
2073 ME_ShowCaret(editor
);
2074 ME_SendOldNotify(editor
, EN_SETFOCUS
);
2077 ME_HideCaret(editor
);
2078 ME_SendOldNotify(editor
, EN_KILLFOCUS
);
2082 if (editor
->bRedraw
)
2084 HDC hDC
= (HDC
)wParam
;
2086 if (GetUpdateRect(hWnd
,&rc
,TRUE
))
2088 FillRect(hDC
, &rc
, editor
->hbrBackground
);
2094 TRACE("editor wnd command = %d\n", LOWORD(wParam
));
2097 if (ME_KeyDown(editor
, LOWORD(wParam
)))
2102 WCHAR wstr
= LOWORD(wParam
);
2103 if (editor
->AutoURLDetect_bEnable
)
2104 ME_AutoURLDetect(editor
, wstr
);
2108 case 3: /* Ctrl-C */
2109 SendMessageW(editor
->hWnd
, WM_COPY
, 0, 0);
2113 if (GetWindowLongW(editor
->hWnd
, GWL_STYLE
) & ES_READONLY
) {
2114 MessageBeep(MB_ICONERROR
);
2115 return 0; /* FIXME really 0 ? */
2120 case 1: /* Ctrl-A */
2121 ME_SetSelection(editor
, 0, -1);
2123 case 22: /* Ctrl-V */
2124 SendMessageW(editor
->hWnd
, WM_PASTE
, 0, 0);
2126 case 24: /* Ctrl-X */
2127 SendMessageW(editor
->hWnd
, WM_CUT
, 0, 0);
2129 case 25: /* Ctrl-Y */
2130 SendMessageW(editor
->hWnd
, EM_REDO
, 0, 0);
2132 case 26: /* Ctrl-Z */
2133 SendMessageW(editor
->hWnd
, EM_UNDO
, 0, 0);
2136 if (((unsigned)wstr
)>=' ' || wstr
=='\r' || wstr
=='\t') {
2137 /* FIXME maybe it would make sense to call EM_REPLACESEL instead ? */
2138 ME_Style
*style
= ME_GetInsertStyle(editor
, 0);
2139 ME_SaveTempStyle(editor
);
2140 ME_InsertTextFromCursor(editor
, 0, &wstr
, 1, style
);
2141 ME_ReleaseStyle(style
);
2142 ME_CommitUndo(editor
);
2143 ME_UpdateRepaint(editor
);
2147 case EM_SCROLL
: /* fall through */
2151 int nPos
= editor
->nScrollPosY
;
2152 int origNPos
= nPos
;
2153 int lineHeight
= 24;
2154 si
.cbSize
= sizeof(SCROLLINFO
);
2155 si
.fMask
= SIF_PAGE
|SIF_POS
|SIF_RANGE
|SIF_TRACKPOS
;
2156 GetScrollInfo(hWnd
, SB_VERT
, &si
);
2157 if (editor
&& editor
->pBuffer
&& editor
->pBuffer
->pDefaultStyle
)
2158 lineHeight
= editor
->pBuffer
->pDefaultStyle
->tm
.tmHeight
;
2159 if (lineHeight
<= 0) lineHeight
= 24;
2160 switch(LOWORD(wParam
)) {
2163 if (nPos
<0) nPos
= 0;
2167 nEnd
= editor
->nTotalLength
- editor
->sizeWindow
.cy
;
2168 if (nEnd
< 0) nEnd
= 0;
2170 if (nPos
>=nEnd
) nPos
= nEnd
;
2174 nPos
-= editor
->sizeWindow
.cy
;
2175 if (nPos
<0) nPos
= 0;
2178 nEnd
= editor
->nTotalLength
- editor
->sizeWindow
.cy
;
2179 if (nEnd
< 0) nEnd
= 0;
2180 nPos
+= editor
->sizeWindow
.cy
;
2181 if (nPos
>=nEnd
) nPos
= nEnd
;
2184 case SB_THUMBPOSITION
:
2185 nPos
= si
.nTrackPos
;
2188 if (nPos
!= editor
->nScrollPosY
) {
2189 int dy
= editor
->nScrollPosY
- nPos
;
2190 editor
->nScrollPosY
= nPos
;
2191 SetScrollPos(hWnd
, SB_VERT
, nPos
, TRUE
);
2192 if (editor
->bRedraw
)
2194 ScrollWindow(hWnd
, 0, dy
, NULL
, NULL
);
2198 if (msg
== EM_SCROLL
)
2199 return 0x00010000 | (((nPos
- origNPos
)/lineHeight
) & 0xffff);
2204 int gcWheelDelta
= 0, nPos
= editor
->nScrollPosY
, nEnd
= editor
->nTotalLength
- editor
->sizeWindow
.cy
;
2205 UINT pulScrollLines
;
2206 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
2207 gcWheelDelta
-= GET_WHEEL_DELTA_WPARAM(wParam
);
2208 if (abs(gcWheelDelta
) >= WHEEL_DELTA
&& pulScrollLines
)
2209 nPos
+= pulScrollLines
* (gcWheelDelta
/ WHEEL_DELTA
) * 8; /* FIXME follow the original */
2214 if (nPos
!= editor
->nScrollPosY
) {
2215 int dy
= editor
->nScrollPosY
- nPos
;
2216 editor
->nScrollPosY
= nPos
;
2217 SetScrollPos(hWnd
, SB_VERT
, nPos
, TRUE
);
2218 if (editor
->bRedraw
)
2220 ScrollWindow(hWnd
, 0, dy
, NULL
, NULL
);
2228 *((RECT
*)lParam
) = editor
->rcFormat
;
2236 RECT
*rc
= (RECT
*)lParam
;
2240 editor
->rcFormat
.left
+= rc
->left
;
2241 editor
->rcFormat
.top
+= rc
->top
;
2242 editor
->rcFormat
.right
+= rc
->right
;
2243 editor
->rcFormat
.bottom
+= rc
->bottom
;
2247 editor
->rcFormat
= *rc
;
2252 GetClientRect(hWnd
, &editor
->rcFormat
);
2254 if (msg
!= EM_SETRECTNP
)
2255 ME_RewrapRepaint(editor
);
2258 case EM_REQUESTRESIZE
:
2259 ME_SendRequestResize(editor
, TRUE
);
2262 editor
->bRedraw
= wParam
;
2266 GetClientRect(hWnd
, &editor
->rcFormat
);
2267 ME_RewrapRepaint(editor
);
2268 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
2270 case EM_GETOLEINTERFACE
:
2272 LPVOID
*ppvObj
= (LPVOID
*) lParam
;
2273 return CreateIRichEditOle(editor
, ppvObj
);
2275 case EM_SETOLECALLBACK
:
2276 if(editor
->lpOleCallback
)
2277 IUnknown_Release(editor
->lpOleCallback
);
2278 editor
->lpOleCallback
= (LPRICHEDITOLECALLBACK
)lParam
;
2279 if(editor
->lpOleCallback
)
2280 IUnknown_AddRef(editor
->lpOleCallback
);
2282 case EM_GETWORDBREAKPROC
:
2283 return (LRESULT
)editor
->pfnWordBreak
;
2284 case EM_SETWORDBREAKPROC
:
2286 EDITWORDBREAKPROCW pfnOld
= editor
->pfnWordBreak
;
2288 editor
->pfnWordBreak
= (EDITWORDBREAKPROCW
)lParam
;
2289 return (LRESULT
)pfnOld
;
2291 case EM_SETTEXTMODE
:
2296 if ((ret
= RichEditANSIWndProc(hWnd
, WM_GETTEXTLENGTH
, 0, 0)) == 0)
2298 /*Check for valid wParam*/
2299 if ((((wParam
& TM_RICHTEXT
) && ((wParam
& TM_PLAINTEXT
) << 1))) ||
2300 (((wParam
& TM_MULTILEVELUNDO
) && ((wParam
& TM_SINGLELEVELUNDO
) << 1))) ||
2301 (((wParam
& TM_MULTICODEPAGE
) && ((wParam
& TM_SINGLECODEPAGE
) << 1))))
2305 if (wParam
& (TM_RICHTEXT
| TM_PLAINTEXT
))
2307 mask
|= (TM_RICHTEXT
| TM_PLAINTEXT
);
2308 changes
|= (wParam
& (TM_RICHTEXT
| TM_PLAINTEXT
));
2310 /*FIXME: Currently no support for undo level and code page options*/
2311 editor
->mode
= (editor
->mode
& (~mask
)) | changes
;
2319 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
2325 /******************************************************************
2326 * RichEdit10ANSIWndProc (RICHED20.9)
2328 LRESULT WINAPI
RichEdit10ANSIWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2332 /* FIXME: this is NOT the same as 2.0 version */
2333 result
= RichEditANSIWndProc(hWnd
, msg
, wParam
, lParam
);
2334 if (msg
== WM_NCCREATE
)
2336 ME_TextEditor
*editor
= (ME_TextEditor
*)GetWindowLongW(hWnd
, 0);
2338 editor
->bEmulateVersion10
= TRUE
;
2339 editor
->pBuffer
->pLast
->member
.para
.nCharOfs
= 2;
2344 void ME_SendOldNotify(ME_TextEditor
*editor
, int nCode
)
2346 HWND hWnd
= editor
->hWnd
;
2347 SendMessageA(GetParent(hWnd
), WM_COMMAND
, (nCode
<<16)|GetWindowLongW(hWnd
, GWLP_ID
), (LPARAM
)hWnd
);
2350 int ME_CountParagraphsBetween(ME_TextEditor
*editor
, int from
, int to
)
2352 ME_DisplayItem
*item
= ME_FindItemFwd(editor
->pBuffer
->pFirst
, diParagraph
);
2355 while(item
&& item
->member
.para
.next_para
->member
.para
.nCharOfs
<= from
)
2356 item
= item
->member
.para
.next_para
;
2359 while(item
&& item
->member
.para
.next_para
->member
.para
.nCharOfs
<= to
) {
2360 item
= item
->member
.para
.next_para
;
2367 int ME_GetTextW(ME_TextEditor
*editor
, WCHAR
*buffer
, int nStart
, int nChars
, int bCRLF
)
2369 ME_DisplayItem
*item
= ME_FindItemAtOffset(editor
, diRun
, nStart
, &nStart
);
2371 WCHAR
*pStart
= buffer
;
2380 int nLen
= ME_StrLen(item
->member
.run
.strText
) - nStart
;
2383 CopyMemory(buffer
, item
->member
.run
.strText
->szData
+ nStart
, sizeof(WCHAR
)*nLen
);
2390 item
= ME_FindItemFwd(item
, diRun
);
2393 while(nChars
&& item
)
2395 int nLen
= ME_StrLen(item
->member
.run
.strText
);
2399 if (item
->member
.run
.nFlags
& MERF_ENDPARA
)
2408 /* our end paragraph consists of 2 characters now */
2409 if (editor
->bEmulateVersion10
)
2413 CopyMemory(buffer
, item
->member
.run
.strText
->szData
, sizeof(WCHAR
)*nLen
);
2420 TRACE("nWritten=%d, actual=%d\n", nWritten
, buffer
-pStart
);
2424 item
= ME_FindItemFwd(item
, diRun
);
2427 TRACE("nWritten=%d, actual=%d\n", nWritten
, buffer
-pStart
);
2431 void ME_RegisterEditorClass(HINSTANCE hInstance
)
2437 wcW
.style
= CS_DBLCLKS
| CS_HREDRAW
| CS_VREDRAW
| CS_GLOBALCLASS
;
2438 wcW
.lpfnWndProc
= RichEditANSIWndProc
;
2441 wcW
.hInstance
= NULL
; /* hInstance would register DLL-local class */
2443 wcW
.hCursor
= LoadCursorW(NULL
, MAKEINTRESOURCEW(IDC_IBEAM
));
2444 wcW
.hbrBackground
= (HBRUSH
)GetStockObject(NULL_BRUSH
);
2445 wcW
.lpszMenuName
= NULL
;
2446 wcW
.lpszClassName
= wszClassName
;
2447 bResult
= RegisterClassW(&wcW
);
2449 wcW
.lpszClassName
= wszClassName50
;
2450 bResult
= RegisterClassW(&wcW
);
2453 wcA
.style
= CS_DBLCLKS
| CS_HREDRAW
| CS_VREDRAW
| CS_GLOBALCLASS
;
2454 wcA
.lpfnWndProc
= RichEditANSIWndProc
;
2457 wcA
.hInstance
= NULL
; /* hInstance would register DLL-local class */
2459 wcA
.hCursor
= LoadCursorW(NULL
, MAKEINTRESOURCEW(IDC_IBEAM
));
2460 wcA
.hbrBackground
= (HBRUSH
)GetStockObject(NULL_BRUSH
);
2461 wcA
.lpszMenuName
= NULL
;
2462 wcA
.lpszClassName
= "RichEdit20A";
2463 bResult
= RegisterClassA(&wcA
);
2465 wcA
.lpszClassName
= "RichEdit50A";
2466 bResult
= RegisterClassA(&wcA
);
2470 LRESULT WINAPI
REComboWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
) {
2471 /* FIXME: Not implemented */
2472 TRACE("hWnd %p msg %04x (%s) %08x %08lx\n",
2473 hWnd
, msg
, get_msg_name(msg
), wParam
, lParam
);
2474 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
2477 LRESULT WINAPI
REListWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
) {
2478 /* FIXME: Not implemented */
2479 TRACE("hWnd %p msg %04x (%s) %08x %08lx\n",
2480 hWnd
, msg
, get_msg_name(msg
), wParam
, lParam
);
2481 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
2484 /******************************************************************
2485 * REExtendedRegisterClass (RICHED20.8)
2487 * FIXME undocumented
2488 * Need to check for errors and implement controls and callbacks
2490 LRESULT WINAPI
REExtendedRegisterClass(void)
2495 FIXME("semi stub\n");
2499 wcW
.hInstance
= NULL
;
2502 wcW
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+1);
2503 wcW
.lpszMenuName
= NULL
;
2505 if (!ME_ListBoxRegistered
)
2507 wcW
.style
= CS_PARENTDC
| CS_DBLCLKS
| CS_GLOBALCLASS
;
2508 wcW
.lpfnWndProc
= REListWndProc
;
2509 wcW
.lpszClassName
= wszClassNameListBox
;
2510 if (RegisterClassW(&wcW
)) ME_ListBoxRegistered
= TRUE
;
2513 if (!ME_ComboBoxRegistered
)
2515 wcW
.style
= CS_PARENTDC
| CS_DBLCLKS
| CS_GLOBALCLASS
| CS_VREDRAW
| CS_HREDRAW
;
2516 wcW
.lpfnWndProc
= REComboWndProc
;
2517 wcW
.lpszClassName
= wszClassNameComboBox
;
2518 if (RegisterClassW(&wcW
)) ME_ComboBoxRegistered
= TRUE
;
2522 if (ME_ListBoxRegistered
)
2524 if (ME_ComboBoxRegistered
)
2530 int ME_AutoURLDetect(ME_TextEditor
*editor
, WCHAR curChar
)
2550 int curf_ef
, link_ef
, def_ef
;
2551 int cur_prefx
, prefx_cnt
;
2552 int sel_min
, sel_max
;
2555 int URLmin
, URLmax
= 0;
2558 CHARFORMAT2W cur_format
;
2559 CHARFORMAT2W default_format
;
2561 RichEditANSIWndProc(editor
->hWnd
, EM_EXGETSEL
, (WPARAM
) 0, (LPARAM
) &ins_pt
);
2562 sel_min
= ins_pt
.cpMin
;
2563 sel_max
= ins_pt
.cpMax
;
2564 if (sel_min
==sel_max
)
2566 if (sel_min
!=sel_max
)
2567 car_pos
= ME_GetTextLength(editor
)+1;
2568 cur_format
.cbSize
= sizeof(cur_format
);
2569 default_format
.cbSize
= sizeof(default_format
);
2570 RichEditANSIWndProc(editor
->hWnd
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
) &cur_format
);
2571 RichEditANSIWndProc(editor
->hWnd
, EM_GETCHARFORMAT
, SCF_DEFAULT
, (LPARAM
) &default_format
);
2572 link
.cbSize
= sizeof(link
);
2573 link
.dwMask
= CFM_LINK
| CFM_COLOR
| CFM_UNDERLINE
;
2574 link
.dwEffects
= CFE_LINK
| CFE_UNDERLINE
;
2575 link
.crTextColor
= RGB(0,0,255);
2576 curf_ef
= cur_format
.dwEffects
& link
.dwEffects
;
2577 def_ef
= default_format
.dwEffects
& link
.dwEffects
;
2578 link_ef
= link
.dwEffects
& link
.dwEffects
;
2579 if (curf_ef
== link_ef
)
2581 if( curChar
== '\n' || curChar
=='\r' || curChar
==' ')
2583 ME_SetSelection(editor
, car_pos
, car_pos
);
2584 RichEditANSIWndProc(editor
->hWnd
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
) &default_format
);
2589 if (curf_ef
== def_ef
)
2592 prefx_cnt
= (sizeof(prefixes
)/sizeof(struct prefix_s
))-1;
2593 while (cur_prefx
<=prefx_cnt
)
2597 ft
.lpstrText
= prefixes
[cur_prefx
].text
;
2598 URLmin
=max(0,(car_pos
-prefixes
[cur_prefx
].length
));
2599 URLmax
=max(0, car_pos
);
2600 if ((car_pos
== 0) && (ME_GetTextLength(editor
) != 0))
2602 URLmax
= ME_GetTextLength(editor
)+1;
2604 ft
.chrg
.cpMin
= URLmin
;
2605 ft
.chrg
.cpMax
= URLmax
;
2606 text_pos
=RichEditANSIWndProc(editor
->hWnd
, EM_FINDTEXT
, FR_DOWN
, (LPARAM
)&ft
);
2612 url
.cpMax
=car_pos
-1;
2613 ME_SetCharFormat(editor
, text_pos
, (URLmax
-text_pos
), &link
);