2 * RichEdit - functions dealing with editor object
4 * Copyright 2004 by Krzysztof Foltman
5 * Copyright 2005 by Cihan Altinay
6 * Copyright 2005 by Phil Krylov
7 * Copyright 2008 Eric Pouech
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 API implementation status:
27 Messages (ANSI versions not done yet)
28 + EM_AUTOURLDETECT 2.0
39 + EM_FINDTEXT (only FR_DOWN flag implemented)
40 + EM_FINDTEXTEX (only FR_DOWN flag implemented)
44 + EM_GETAUTOURLDETECT 2.0
45 - EM_GETBIDIOPTIONS 3.0
46 - EM_GETCHARFORMAT (partly done)
49 + EM_GETFIRSTVISIBLELINE (can be optimized if needed)
50 - EM_GETIMECOLOR 1.0asian
51 - EM_GETIMECOMPMODE 2.0
52 - EM_GETIMEOPTIONS 1.0asian
54 - EM_GETLANGOPTIONS 2.0
57 + EM_GETLINECOUNT returns number of rows, not of paragraphs
62 + EM_GETPASSWORDCHAR 2.0
63 - EM_GETPUNCTUATION 1.0asian
67 + EM_GETSELTEXT (ANSI&Unicode)
71 + EM_GETTEXTLENGTHEX (GTL_PRECISE unimplemented)
73 ? + EM_GETTEXTRANGE (ANSI&Unicode)
74 - EM_GETTYPOGRAPHYOPTIONS 3.0
77 - EM_GETWORDBREAKPROCEX
78 - EM_GETWORDWRAPMODE 1.0asian
81 + EM_LIMITTEXT (Also called EM_SETLIMITTEXT)
90 + EM_REPLACESEL (proper style?) ANSI&Unicode
94 - EM_SETBIDIOPTIONS 3.0
96 + EM_SETCHARFORMAT (partly done, no ANSI)
98 + EM_SETEVENTMASK (few notifications supported)
100 - EM_SETIMECOLOR 1.0asian
101 - EM_SETIMEOPTIONS 1.0asian
103 - EM_SETLANGOPTIONS 2.0
106 + EM_SETMODIFY (not sure if implementation is correct)
108 + EM_SETOPTIONS (partially implemented)
111 + EM_SETPASSWORDCHAR 2.0
112 - EM_SETPUNCTUATION 1.0asian
113 + EM_SETREADONLY no beep on modification attempt
115 + EM_SETRECTNP (EM_SETRECT without repainting)
117 + EM_SETSCROLLPOS 3.0
119 - EM_SETTARGETDEVICE (partial)
120 + EM_SETTEXTEX 3.0 (proper style?)
122 - EM_SETTYPOGRAPHYOPTIONS 3.0
123 + EM_SETUNDOLIMIT 2.0
124 + EM_SETWORDBREAKPROC (used only for word movement at the moment)
125 - EM_SETWORDBREAKPROCEX
126 - EM_SETWORDWRAPMODE 1.0asian
128 + EM_SHOWSCROLLBAR 2.0
129 + EM_STOPGROUPTYPING 2.0
137 + WM_GETDLGCODE (the current implementation is incomplete)
138 + WM_GETTEXT (ANSI&Unicode)
139 + WM_GETTEXTLENGTH (ANSI version sucks)
143 + WM_SETTEXT (resets undo stack !) (proper style?) ANSI&Unicode
145 - WM_STYLECHANGED (things like read-only flag)
151 * EN_CHANGE (sent from the wrong place)
168 * EN_UPDATE (sent from the wrong place)
176 + ES_DISABLENOSCROLL (scrollbar is always visible)
177 - ES_EX_NOCALLOLEINIT
179 - ES_MULTILINE (currently single line controls aren't supported)
181 - ES_READONLY (I'm not sure if beeping is the proper behaviour)
187 - ES_WANTRETURN (don't know how to do WM_GETDLGCODE part)
194 * RICHED20 TODO (incomplete):
196 * - messages/styles/notifications listed above
197 * - add remaining CHARFORMAT/PARAFORMAT fields
198 * - right/center align should strip spaces from the beginning
199 * - pictures/OLE objects (not just smiling faces that lack API support ;-) )
200 * - COM interface (looks like a major pain in the TODO list)
201 * - calculate heights of pictures (half-done)
202 * - hysteresis during wrapping (related to scrollbars appearing/disappearing)
204 * - how to implement EM_FORMATRANGE and EM_DISPLAYBAND ? (Mission Impossible)
205 * - italic caret with italic fonts
207 * - most notifications aren't sent at all (the most important ones are)
208 * - when should EN_SELCHANGE be sent after text change ? (before/after EN_UPDATE?)
209 * - WM_SETTEXT may use wrong style (but I'm 80% sure it's OK)
210 * - EM_GETCHARFORMAT with SCF_SELECTION may not behave 100% like in original (but very close)
211 * - full justification
214 * - ListBox & ComboBox not implemented
216 * Bugs that are probably fixed, but not so easy to verify:
217 * - EN_UPDATE/EN_CHANGE are handled very incorrectly (should be OK now)
218 * - undo for ME_JoinParagraphs doesn't store paragraph format ? (it does)
219 * - check/fix artificial EOL logic (bCursorAtEnd, hardly logical)
220 * - caret shouldn't be displayed when selection isn't empty
221 * - check refcounting in style management functions (looks perfect now, but no bugs is suspicious)
222 * - undo for setting default format (done, might be buggy)
223 * - styles might be not released properly (looks like they work like charm, but who knows?
230 #define NO_SHLWAPI_STREAM
236 #define STACK_SIZE_DEFAULT 100
237 #define STACK_SIZE_MAX 1000
239 #define TEXT_LIMIT_DEFAULT 32767
241 WINE_DEFAULT_DEBUG_CHANNEL(richedit
);
243 static BOOL
ME_RegisterEditorClass(HINSTANCE
);
244 static BOOL
ME_UpdateLinkAttribute(ME_TextEditor
*editor
, int sel_min
, int sel_max
);
246 static const WCHAR RichEdit20W
[] = {'R', 'i', 'c', 'h', 'E', 'd', 'i', 't', '2', '0', 'W', 0};
247 static const WCHAR RichEdit50W
[] = {'R', 'i', 'c', 'h', 'E', 'd', 'i', 't', '5', '0', 'W', 0};
248 static const WCHAR REListBox20W
[] = {'R','E','L','i','s','t','B','o','x','2','0','W', 0};
249 static const WCHAR REComboBox20W
[] = {'R','E','C','o','m','b','o','B','o','x','2','0','W', 0};
250 static HCURSOR hLeft
;
253 HANDLE me_heap
= NULL
;
255 static BOOL ME_ListBoxRegistered
= FALSE
;
256 static BOOL ME_ComboBoxRegistered
= FALSE
;
258 static inline int is_version_nt(void)
260 return !(GetVersion() & 0x80000000);
263 static ME_TextBuffer
*ME_MakeText(void) {
265 ME_TextBuffer
*buf
= ALLOC_OBJ(ME_TextBuffer
);
267 ME_DisplayItem
*p1
= ME_MakeDI(diTextStart
);
268 ME_DisplayItem
*p2
= ME_MakeDI(diTextEnd
);
274 p1
->member
.para
.next_para
= p2
;
275 p2
->member
.para
.prev_para
= p1
;
276 p2
->member
.para
.nCharOfs
= 0;
280 buf
->pCharStyle
= NULL
;
286 static LRESULT
ME_StreamInText(ME_TextEditor
*editor
, DWORD dwFormat
, ME_InStream
*stream
, ME_Style
*style
)
288 WCHAR wszText
[STREAMIN_BUFFER_SIZE
+1];
291 TRACE("%08x %p\n", dwFormat
, stream
);
298 ME_StreamInFill(stream
);
299 if (stream
->editstream
->dwError
)
305 if (!(dwFormat
& SF_UNICODE
))
307 /* FIXME? this is doomed to fail on true MBCS like UTF-8, luckily they're unlikely to be used as CP_ACP */
308 nWideChars
= MultiByteToWideChar(CP_ACP
, 0, stream
->buffer
, stream
->dwSize
, wszText
, STREAMIN_BUFFER_SIZE
);
313 nWideChars
= stream
->dwSize
>> 1;
314 pText
= (WCHAR
*)stream
->buffer
;
317 ME_InsertTextFromCursor(editor
, 0, pText
, nWideChars
, style
);
318 if (stream
->dwSize
== 0)
322 ME_CommitUndo(editor
);
323 ME_UpdateRepaint(editor
);
327 static void ME_ApplyBorderProperties(RTF_Info
*info
,
328 ME_BorderRect
*borderRect
,
329 RTFBorder
*borderDef
)
332 ME_Border
*pBorders
[] = {&borderRect
->top
,
336 for (i
= 0; i
< 4; i
++)
338 RTFColor
*colorDef
= info
->colorList
;
339 pBorders
[i
]->width
= borderDef
[i
].width
;
340 colorNum
= borderDef
[i
].color
;
341 while (colorDef
&& colorDef
->rtfCNum
!= colorNum
)
342 colorDef
= colorDef
->rtfNextColor
;
344 pBorders
[i
]->colorRef
= RGB(
345 colorDef
->rtfCRed
>= 0 ? colorDef
->rtfCRed
: 0,
346 colorDef
->rtfCGreen
>= 0 ? colorDef
->rtfCGreen
: 0,
347 colorDef
->rtfCBlue
>= 0 ? colorDef
->rtfCBlue
: 0);
349 pBorders
[i
]->colorRef
= RGB(0, 0, 0);
353 void ME_RTFCharAttrHook(RTF_Info
*info
)
356 fmt
.cbSize
= sizeof(fmt
);
360 switch(info
->rtfMinor
)
363 /* FIXME add more flags once they're implemented */
364 fmt
.dwMask
= CFM_BOLD
| CFM_ITALIC
| CFM_UNDERLINETYPE
| CFM_STRIKEOUT
| CFM_COLOR
| CFM_BACKCOLOR
| CFM_SIZE
| CFM_WEIGHT
;
365 fmt
.dwEffects
= CFE_AUTOCOLOR
| CFE_AUTOBACKCOLOR
;
366 fmt
.yHeight
= 12*20; /* 12pt */
367 fmt
.wWeight
= FW_NORMAL
;
368 fmt
.bUnderlineType
= CFU_UNDERLINENONE
;
371 fmt
.dwMask
= CFM_BOLD
| CFM_WEIGHT
;
372 fmt
.dwEffects
= info
->rtfParam
? CFE_BOLD
: 0;
373 fmt
.wWeight
= info
->rtfParam
? FW_BOLD
: FW_NORMAL
;
376 fmt
.dwMask
= CFM_ITALIC
;
377 fmt
.dwEffects
= info
->rtfParam
? fmt
.dwMask
: 0;
380 fmt
.dwMask
= CFM_UNDERLINETYPE
;
381 fmt
.bUnderlineType
= info
->rtfParam
? CFU_CF1UNDERLINE
: CFU_UNDERLINENONE
;
383 case rtfDotUnderline
:
384 fmt
.dwMask
= CFM_UNDERLINETYPE
;
385 fmt
.bUnderlineType
= info
->rtfParam
? CFU_UNDERLINEDOTTED
: CFU_UNDERLINENONE
;
388 fmt
.dwMask
= CFM_UNDERLINETYPE
;
389 fmt
.bUnderlineType
= info
->rtfParam
? CFU_UNDERLINEDOUBLE
: CFU_UNDERLINENONE
;
391 case rtfWordUnderline
:
392 fmt
.dwMask
= CFM_UNDERLINETYPE
;
393 fmt
.bUnderlineType
= info
->rtfParam
? CFU_UNDERLINEWORD
: CFU_UNDERLINENONE
;
396 fmt
.dwMask
= CFM_UNDERLINETYPE
;
397 fmt
.bUnderlineType
= CFU_UNDERLINENONE
;
400 fmt
.dwMask
= CFM_STRIKEOUT
;
401 fmt
.dwEffects
= info
->rtfParam
? fmt
.dwMask
: 0;
405 case rtfSubScrShrink
:
406 case rtfSuperScrShrink
:
408 fmt
.dwMask
= CFM_SUBSCRIPT
|CFM_SUPERSCRIPT
;
409 if (info
->rtfMinor
== rtfSubScrShrink
) fmt
.dwEffects
= CFE_SUBSCRIPT
;
410 if (info
->rtfMinor
== rtfSuperScrShrink
) fmt
.dwEffects
= CFE_SUPERSCRIPT
;
411 if (info
->rtfMinor
== rtfNoSuperSub
) fmt
.dwEffects
= 0;
414 fmt
.dwMask
= CFM_HIDDEN
;
415 fmt
.dwEffects
= info
->rtfParam
? fmt
.dwMask
: 0;
418 fmt
.dwMask
= CFM_BACKCOLOR
;
420 if (info
->rtfParam
== 0)
421 fmt
.dwEffects
= CFE_AUTOBACKCOLOR
;
422 else if (info
->rtfParam
!= rtfNoParam
)
424 RTFColor
*c
= RTFGetColor(info
, info
->rtfParam
);
425 if (c
&& c
->rtfCBlue
>= 0)
426 fmt
.crTextColor
= (c
->rtfCBlue
<<16)|(c
->rtfCGreen
<<8)|(c
->rtfCRed
);
428 fmt
.dwEffects
= CFE_AUTOBACKCOLOR
;
432 fmt
.dwMask
= CFM_COLOR
;
434 if (info
->rtfParam
== 0)
435 fmt
.dwEffects
= CFE_AUTOCOLOR
;
436 else if (info
->rtfParam
!= rtfNoParam
)
438 RTFColor
*c
= RTFGetColor(info
, info
->rtfParam
);
439 if (c
&& c
->rtfCBlue
>= 0)
440 fmt
.crTextColor
= (c
->rtfCBlue
<<16)|(c
->rtfCGreen
<<8)|(c
->rtfCRed
);
442 fmt
.dwEffects
= CFE_AUTOCOLOR
;
447 if (info
->rtfParam
!= rtfNoParam
)
449 RTFFont
*f
= RTFGetFont(info
, info
->rtfParam
);
452 MultiByteToWideChar(CP_ACP
, 0, f
->rtfFName
, -1, fmt
.szFaceName
, sizeof(fmt
.szFaceName
)/sizeof(WCHAR
));
453 fmt
.szFaceName
[sizeof(fmt
.szFaceName
)/sizeof(WCHAR
)-1] = '\0';
454 fmt
.bCharSet
= f
->rtfFCharSet
;
455 fmt
.dwMask
= CFM_FACE
| CFM_CHARSET
;
456 fmt
.bPitchAndFamily
= f
->rtfFPitch
| (f
->rtfFFamily
<< 4);
461 fmt
.dwMask
= CFM_SIZE
;
462 if (info
->rtfParam
!= rtfNoParam
)
463 fmt
.yHeight
= info
->rtfParam
*10;
468 RTFFlushOutputBuffer(info
);
469 /* FIXME too slow ? how come ? */
470 style2
= ME_ApplyStyle(info
->style
, &fmt
);
471 ME_ReleaseStyle(info
->style
);
472 info
->style
= style2
;
473 info
->styleChanged
= TRUE
;
477 /* FIXME this function doesn't get any information about context of the RTF tag, which is very bad,
478 the same tags mean different things in different contexts */
479 void ME_RTFParAttrHook(RTF_Info
*info
)
482 fmt
.cbSize
= sizeof(fmt
);
485 switch(info
->rtfMinor
)
487 case rtfParDef
: /* restores default paragraph attributes */
488 if (!info
->editor
->bEmulateVersion10
) /* v4.1 */
489 info
->borderType
= RTFBorderParaLeft
;
490 else /* v1.0 - 3.0 */
491 info
->borderType
= RTFBorderParaTop
;
492 fmt
.dwMask
= PFM_ALIGNMENT
| PFM_BORDER
| PFM_LINESPACING
| PFM_TABSTOPS
|
493 PFM_OFFSET
| PFM_RIGHTINDENT
| PFM_SPACEAFTER
| PFM_SPACEBEFORE
|
495 /* TODO: numbering, shading */
496 fmt
.wAlignment
= PFA_LEFT
;
498 fmt
.dxOffset
= fmt
.dxStartIndent
= fmt
.dxRightIndent
= 0;
499 fmt
.wBorderWidth
= fmt
.wBorders
= 0;
500 fmt
.wBorderSpace
= 0;
501 fmt
.bLineSpacingRule
= 0;
502 fmt
.dySpaceBefore
= fmt
.dySpaceAfter
= 0;
503 fmt
.dyLineSpacing
= 0;
504 if (!info
->editor
->bEmulateVersion10
) /* v4.1 */
506 if (info
->tableDef
&& info
->tableDef
->tableRowStart
&&
507 info
->tableDef
->tableRowStart
->member
.para
.nFlags
& MEPF_ROWEND
)
510 ME_DisplayItem
*para
;
511 /* We are just after a table row. */
512 RTFFlushOutputBuffer(info
);
513 cursor
= info
->editor
->pCursors
[0];
515 if (para
== info
->tableDef
->tableRowStart
->member
.para
.next_para
516 && !cursor
.nOffset
&& !cursor
.pRun
->member
.run
.nCharOfs
)
518 /* Since the table row end, no text has been inserted, and the \intbl
519 * control word has not be used. We can confirm that we are not in a
522 info
->tableDef
->tableRowStart
= NULL
;
523 info
->canInheritInTbl
= FALSE
;
526 } else { /* v1.0 - v3.0 */
527 fmt
.dwMask
|= PFM_TABLE
;
528 fmt
.wEffects
&= ~PFE_TABLE
;
532 if (!info
->editor
->bEmulateVersion10
) /* v4.1 */
534 while (info
->rtfParam
> info
->nestingLevel
) {
535 RTFTable
*tableDef
= ALLOC_OBJ(RTFTable
);
536 ZeroMemory(tableDef
, sizeof(RTFTable
));
537 tableDef
->parent
= info
->tableDef
;
538 info
->tableDef
= tableDef
;
540 RTFFlushOutputBuffer(info
);
541 if (tableDef
->tableRowStart
&&
542 tableDef
->tableRowStart
->member
.para
.nFlags
& MEPF_ROWEND
)
544 ME_DisplayItem
*para
= tableDef
->tableRowStart
;
545 para
= para
->member
.para
.next_para
;
546 para
= ME_InsertTableRowStartAtParagraph(info
->editor
, para
);
547 tableDef
->tableRowStart
= para
;
551 cursor
= info
->editor
->pCursors
[0];
552 if (cursor
.nOffset
|| cursor
.pRun
->member
.run
.nCharOfs
)
553 ME_InsertTextFromCursor(info
->editor
, 0, &endl
, 1, info
->style
);
554 tableDef
->tableRowStart
= ME_InsertTableRowStartFromCursor(info
->editor
);
557 info
->nestingLevel
++;
559 info
->canInheritInTbl
= FALSE
;
564 if (!info
->editor
->bEmulateVersion10
) /* v4.1 */
566 if (info
->nestingLevel
< 1)
571 info
->tableDef
= ALLOC_OBJ(RTFTable
);
572 ZeroMemory(info
->tableDef
, sizeof(RTFTable
));
574 tableDef
= info
->tableDef
;
575 RTFFlushOutputBuffer(info
);
576 if (tableDef
->tableRowStart
&&
577 tableDef
->tableRowStart
->member
.para
.nFlags
& MEPF_ROWEND
)
579 ME_DisplayItem
*para
= tableDef
->tableRowStart
;
580 para
= para
->member
.para
.next_para
;
581 para
= ME_InsertTableRowStartAtParagraph(info
->editor
, para
);
582 tableDef
->tableRowStart
= para
;
586 cursor
= info
->editor
->pCursors
[0];
587 if (cursor
.nOffset
|| cursor
.pRun
->member
.run
.nCharOfs
)
588 ME_InsertTextFromCursor(info
->editor
, 0, &endl
, 1, info
->style
);
589 tableDef
->tableRowStart
= ME_InsertTableRowStartFromCursor(info
->editor
);
591 info
->nestingLevel
= 1;
592 info
->canInheritInTbl
= TRUE
;
595 } else { /* v1.0 - v3.0 */
596 fmt
.dwMask
|= PFM_TABLE
;
597 fmt
.wEffects
|= PFE_TABLE
;
602 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
603 fmt
.dwMask
= PFM_STARTINDENT
| PFM_OFFSET
;
604 fmt
.dxStartIndent
+= fmt
.dxOffset
+ info
->rtfParam
;
605 fmt
.dxOffset
= -info
->rtfParam
;
608 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
609 fmt
.dwMask
= PFM_STARTINDENT
;
610 fmt
.dxStartIndent
= info
->rtfParam
- fmt
.dxOffset
;
613 fmt
.dwMask
= PFM_RIGHTINDENT
;
614 fmt
.dxRightIndent
= info
->rtfParam
;
618 fmt
.dwMask
= PFM_ALIGNMENT
;
619 fmt
.wAlignment
= PFA_LEFT
;
622 fmt
.dwMask
= PFM_ALIGNMENT
;
623 fmt
.wAlignment
= PFA_RIGHT
;
626 fmt
.dwMask
= PFM_ALIGNMENT
;
627 fmt
.wAlignment
= PFA_CENTER
;
630 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
631 if (!(fmt
.dwMask
& PFM_TABSTOPS
))
635 if (fmt
.cTabCount
< MAX_TAB_STOPS
&& info
->rtfParam
< 0x1000000)
636 fmt
.rgxTabs
[fmt
.cTabCount
++] = info
->rtfParam
;
637 fmt
.dwMask
= PFM_TABSTOPS
;
640 fmt
.dwMask
= PFM_KEEP
;
641 fmt
.wEffects
= PFE_KEEP
;
643 case rtfNoWidowControl
:
644 fmt
.dwMask
= PFM_NOWIDOWCONTROL
;
645 fmt
.wEffects
= PFE_NOWIDOWCONTROL
;
648 fmt
.dwMask
= PFM_KEEPNEXT
;
649 fmt
.wEffects
= PFE_KEEPNEXT
;
652 fmt
.dwMask
= PFM_SPACEAFTER
;
653 fmt
.dySpaceAfter
= info
->rtfParam
;
656 fmt
.dwMask
= PFM_SPACEBEFORE
;
657 fmt
.dySpaceBefore
= info
->rtfParam
;
659 case rtfSpaceBetween
:
660 fmt
.dwMask
= PFM_LINESPACING
;
661 if ((int)info
->rtfParam
> 0)
663 fmt
.dyLineSpacing
= info
->rtfParam
;
664 fmt
.bLineSpacingRule
= 3;
668 fmt
.dyLineSpacing
= info
->rtfParam
;
669 fmt
.bLineSpacingRule
= 4;
671 case rtfSpaceMultiply
:
672 fmt
.dwMask
= PFM_LINESPACING
;
673 fmt
.dyLineSpacing
= info
->rtfParam
* 20;
674 fmt
.bLineSpacingRule
= 5;
677 fmt
.dwMask
= PFM_NUMBERING
;
678 fmt
.wNumbering
= PFN_BULLET
;
681 fmt
.dwMask
= PFM_NUMBERING
;
682 fmt
.wNumbering
= 2; /* FIXME: MSDN says it's not used ?? */
684 case rtfParNumDecimal
:
685 fmt
.dwMask
= PFM_NUMBERING
;
686 fmt
.wNumbering
= 2; /* FIXME: MSDN says it's not used ?? */
688 case rtfParNumIndent
:
689 fmt
.dwMask
= PFM_NUMBERINGTAB
;
690 fmt
.wNumberingTab
= info
->rtfParam
;
692 case rtfParNumStartAt
:
693 fmt
.dwMask
= PFM_NUMBERINGSTART
;
694 fmt
.wNumberingStart
= info
->rtfParam
;
697 info
->borderType
= RTFBorderParaLeft
;
698 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
699 if (!(fmt
.dwMask
& PFM_BORDER
))
701 fmt
.wBorderSpace
= 0;
702 fmt
.wBorderWidth
= 1;
706 fmt
.dwMask
= PFM_BORDER
;
709 info
->borderType
= RTFBorderParaRight
;
710 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
711 if (!(fmt
.dwMask
& PFM_BORDER
))
713 fmt
.wBorderSpace
= 0;
714 fmt
.wBorderWidth
= 1;
718 fmt
.dwMask
= PFM_BORDER
;
721 info
->borderType
= RTFBorderParaTop
;
722 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
723 if (!(fmt
.dwMask
& PFM_BORDER
))
725 fmt
.wBorderSpace
= 0;
726 fmt
.wBorderWidth
= 1;
730 fmt
.dwMask
= PFM_BORDER
;
732 case rtfBorderBottom
:
733 info
->borderType
= RTFBorderParaBottom
;
734 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
735 if (!(fmt
.dwMask
& PFM_BORDER
))
737 fmt
.wBorderSpace
= 0;
738 fmt
.wBorderWidth
= 1;
742 fmt
.dwMask
= PFM_BORDER
;
744 case rtfBorderSingle
:
745 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
746 /* we assume that borders have been created before (RTF spec) */
747 fmt
.wBorders
&= ~0x700;
748 fmt
.wBorders
|= 1 << 8;
749 fmt
.dwMask
= PFM_BORDER
;
752 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
753 /* we assume that borders have been created before (RTF spec) */
754 fmt
.wBorders
&= ~0x700;
755 fmt
.wBorders
|= 2 << 8;
756 fmt
.dwMask
= PFM_BORDER
;
758 case rtfBorderShadow
:
759 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
760 /* we assume that borders have been created before (RTF spec) */
761 fmt
.wBorders
&= ~0x700;
762 fmt
.wBorders
|= 10 << 8;
763 fmt
.dwMask
= PFM_BORDER
;
765 case rtfBorderDouble
:
766 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
767 /* we assume that borders have been created before (RTF spec) */
768 fmt
.wBorders
&= ~0x700;
769 fmt
.wBorders
|= 7 << 8;
770 fmt
.dwMask
= PFM_BORDER
;
773 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
774 /* we assume that borders have been created before (RTF spec) */
775 fmt
.wBorders
&= ~0x700;
776 fmt
.wBorders
|= 11 << 8;
777 fmt
.dwMask
= PFM_BORDER
;
781 int borderSide
= info
->borderType
& RTFBorderSideMask
;
782 RTFTable
*tableDef
= info
->tableDef
;
783 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
784 /* we assume that borders have been created before (RTF spec) */
785 fmt
.wBorderWidth
|= ((info
->rtfParam
/ 15) & 7) << 8;
786 if ((info
->borderType
& RTFBorderTypeMask
) == RTFBorderTypeCell
)
789 if (!tableDef
|| tableDef
->numCellsDefined
>= MAX_TABLE_CELLS
)
791 border
= &tableDef
->cells
[tableDef
->numCellsDefined
].border
[borderSide
];
792 border
->width
= info
->rtfParam
;
795 fmt
.dwMask
= PFM_BORDER
;
799 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
800 /* we assume that borders have been created before (RTF spec) */
801 fmt
.wBorderSpace
= info
->rtfParam
;
802 fmt
.dwMask
= PFM_BORDER
;
806 RTFTable
*tableDef
= info
->tableDef
;
807 int borderSide
= info
->borderType
& RTFBorderSideMask
;
808 int borderType
= info
->borderType
& RTFBorderTypeMask
;
811 case RTFBorderTypePara
:
812 if (!info
->editor
->bEmulateVersion10
) /* v4.1 */
814 /* v1.0 - 3.0 treat paragraph and row borders the same. */
815 case RTFBorderTypeRow
:
817 tableDef
->border
[borderSide
].color
= info
->rtfParam
;
820 case RTFBorderTypeCell
:
821 if (tableDef
&& tableDef
->numCellsDefined
< MAX_TABLE_CELLS
) {
822 tableDef
->cells
[tableDef
->numCellsDefined
].border
[borderSide
].color
= info
->rtfParam
;
830 RTFFlushOutputBuffer(info
);
831 /* FIXME too slow ? how come ?*/
832 ME_SetSelectionParaFormat(info
->editor
, &fmt
);
836 void ME_RTFTblAttrHook(RTF_Info
*info
)
838 switch (info
->rtfMinor
)
842 if (!info
->editor
->bEmulateVersion10
) /* v4.1 */
843 info
->borderType
= 0; /* Not sure */
844 else /* v1.0 - 3.0 */
845 info
->borderType
= RTFBorderRowTop
;
846 if (!info
->tableDef
) {
847 info
->tableDef
= ME_MakeTableDef(info
->editor
);
849 ME_InitTableDef(info
->editor
, info
->tableDef
);
858 info
->tableDef
= ME_MakeTableDef(info
->editor
);
860 cellNum
= info
->tableDef
->numCellsDefined
;
861 if (cellNum
>= MAX_TABLE_CELLS
)
863 info
->tableDef
->cells
[cellNum
].rightBoundary
= info
->rtfParam
;
864 if (cellNum
< MAX_TAB_STOPS
) {
865 /* Tab stops were used to store cell positions before v4.1 but v4.1
866 * still seems to set the tabstops without using them. */
867 ME_DisplayItem
*para
= info
->editor
->pCursors
[0].pPara
;
868 PARAFORMAT2
*pFmt
= para
->member
.para
.pFmt
;
869 pFmt
->rgxTabs
[cellNum
] &= ~0x00FFFFFF;
870 pFmt
->rgxTabs
[cellNum
] = 0x00FFFFFF & info
->rtfParam
;
872 info
->tableDef
->numCellsDefined
++;
876 info
->borderType
= RTFBorderRowTop
;
879 info
->borderType
= RTFBorderRowLeft
;
881 case rtfRowBordBottom
:
882 info
->borderType
= RTFBorderRowBottom
;
884 case rtfRowBordRight
:
885 info
->borderType
= RTFBorderRowRight
;
888 info
->borderType
= RTFBorderCellTop
;
890 case rtfCellBordLeft
:
891 info
->borderType
= RTFBorderCellLeft
;
893 case rtfCellBordBottom
:
894 info
->borderType
= RTFBorderCellBottom
;
896 case rtfCellBordRight
:
897 info
->borderType
= RTFBorderCellRight
;
901 info
->tableDef
->gapH
= info
->rtfParam
;
905 info
->tableDef
->leftEdge
= info
->rtfParam
;
910 void ME_RTFSpecialCharHook(RTF_Info
*info
)
912 RTFTable
*tableDef
= info
->tableDef
;
913 switch (info
->rtfMinor
)
916 if (info
->editor
->bEmulateVersion10
) /* v1.0 - v3.0 */
918 /* else fall through since v4.1 treats rtfNestCell and rtfCell the same */
922 RTFFlushOutputBuffer(info
);
923 if (!info
->editor
->bEmulateVersion10
) { /* v4.1 */
924 if (tableDef
->tableRowStart
)
926 if (!info
->nestingLevel
&&
927 tableDef
->tableRowStart
->member
.para
.nFlags
& MEPF_ROWEND
)
929 ME_DisplayItem
*para
= tableDef
->tableRowStart
;
930 para
= para
->member
.para
.next_para
;
931 para
= ME_InsertTableRowStartAtParagraph(info
->editor
, para
);
932 tableDef
->tableRowStart
= para
;
933 info
->nestingLevel
= 1;
935 ME_InsertTableCellFromCursor(info
->editor
);
937 } else { /* v1.0 - v3.0 */
938 ME_DisplayItem
*para
= info
->editor
->pCursors
[0].pPara
;
939 PARAFORMAT2
*pFmt
= para
->member
.para
.pFmt
;
940 if (pFmt
->dwMask
& PFM_TABLE
&& pFmt
->wEffects
& PFE_TABLE
&&
941 tableDef
->numCellsInserted
< tableDef
->numCellsDefined
)
944 ME_InsertTextFromCursor(info
->editor
, 0, &tab
, 1, info
->style
);
945 tableDef
->numCellsInserted
++;
950 if (info
->editor
->bEmulateVersion10
) /* v1.0 - v3.0 */
952 /* else fall through since v4.1 treats rtfNestRow and rtfRow the same */
955 ME_DisplayItem
*para
, *cell
, *run
;
960 RTFFlushOutputBuffer(info
);
961 if (!info
->editor
->bEmulateVersion10
) { /* v4.1 */
962 if (!tableDef
->tableRowStart
)
964 if (!info
->nestingLevel
&&
965 tableDef
->tableRowStart
->member
.para
.nFlags
& MEPF_ROWEND
)
967 para
= tableDef
->tableRowStart
;
968 para
= para
->member
.para
.next_para
;
969 para
= ME_InsertTableRowStartAtParagraph(info
->editor
, para
);
970 tableDef
->tableRowStart
= para
;
971 info
->nestingLevel
++;
973 para
= tableDef
->tableRowStart
;
974 cell
= ME_FindItemFwd(para
, diCell
);
975 assert(cell
&& !cell
->member
.cell
.prev_cell
);
976 if (tableDef
->numCellsDefined
< 1)
978 /* 2000 twips appears to be the cell size that native richedit uses
979 * when no cell sizes are specified. */
980 const int defaultCellSize
= 2000;
981 int nRightBoundary
= defaultCellSize
;
982 cell
->member
.cell
.nRightBoundary
= nRightBoundary
;
983 while (cell
->member
.cell
.next_cell
) {
984 cell
= cell
->member
.cell
.next_cell
;
985 nRightBoundary
+= defaultCellSize
;
986 cell
->member
.cell
.nRightBoundary
= nRightBoundary
;
988 para
= ME_InsertTableCellFromCursor(info
->editor
);
989 cell
= para
->member
.para
.pCell
;
990 cell
->member
.cell
.nRightBoundary
= nRightBoundary
;
992 for (i
= 0; i
< tableDef
->numCellsDefined
; i
++)
994 RTFCell
*cellDef
= &tableDef
->cells
[i
];
995 cell
->member
.cell
.nRightBoundary
= cellDef
->rightBoundary
;
996 ME_ApplyBorderProperties(info
, &cell
->member
.cell
.border
,
998 cell
= cell
->member
.cell
.next_cell
;
1001 para
= ME_InsertTableCellFromCursor(info
->editor
);
1002 cell
= para
->member
.para
.pCell
;
1005 /* Cell for table row delimiter is empty */
1006 cell
->member
.cell
.nRightBoundary
= tableDef
->cells
[i
-1].rightBoundary
;
1009 run
= ME_FindItemFwd(cell
, diRun
);
1010 if (info
->editor
->pCursors
[0].pRun
!= run
||
1011 info
->editor
->pCursors
[0].nOffset
)
1014 /* Delete inserted cells that aren't defined. */
1015 info
->editor
->pCursors
[1].pRun
= run
;
1016 info
->editor
->pCursors
[1].pPara
= ME_GetParagraph(run
);
1017 info
->editor
->pCursors
[1].nOffset
= 0;
1018 nOfs
= ME_GetCursorOfs(info
->editor
, 1);
1019 nChars
= ME_GetCursorOfs(info
->editor
, 0) - nOfs
;
1020 ME_InternalDeleteText(info
->editor
, nOfs
, nChars
, TRUE
);
1023 para
= ME_InsertTableRowEndFromCursor(info
->editor
);
1024 para
->member
.para
.pFmt
->dxOffset
= abs(info
->tableDef
->gapH
);
1025 para
->member
.para
.pFmt
->dxStartIndent
= info
->tableDef
->leftEdge
;
1026 ME_ApplyBorderProperties(info
, ¶
->member
.para
.border
,
1028 info
->nestingLevel
--;
1029 if (!info
->nestingLevel
)
1031 if (info
->canInheritInTbl
) {
1032 tableDef
->tableRowStart
= para
;
1034 while (info
->tableDef
) {
1035 tableDef
= info
->tableDef
;
1036 info
->tableDef
= tableDef
->parent
;
1037 heap_free(tableDef
);
1041 info
->tableDef
= tableDef
->parent
;
1042 heap_free(tableDef
);
1044 } else { /* v1.0 - v3.0 */
1046 ME_DisplayItem
*para
= info
->editor
->pCursors
[0].pPara
;
1047 PARAFORMAT2
*pFmt
= para
->member
.para
.pFmt
;
1048 pFmt
->dxOffset
= info
->tableDef
->gapH
;
1049 pFmt
->dxStartIndent
= info
->tableDef
->leftEdge
;
1051 ME_ApplyBorderProperties(info
, ¶
->member
.para
.border
,
1053 while (tableDef
->numCellsInserted
< tableDef
->numCellsDefined
)
1056 ME_InsertTextFromCursor(info
->editor
, 0, &tab
, 1, info
->style
);
1057 tableDef
->numCellsInserted
++;
1059 pFmt
->cTabCount
= min(tableDef
->numCellsDefined
, MAX_TAB_STOPS
);
1060 if (!tableDef
->numCellsDefined
)
1061 pFmt
->wEffects
&= ~PFE_TABLE
;
1062 ME_InsertTextFromCursor(info
->editor
, 0, &endl
, 1, info
->style
);
1063 tableDef
->numCellsInserted
= 0;
1069 if (info
->editor
->bEmulateVersion10
) { /* v1.0 - 3.0 */
1070 ME_DisplayItem
*para
;
1072 RTFFlushOutputBuffer(info
);
1073 para
= info
->editor
->pCursors
[0].pPara
;
1074 pFmt
= para
->member
.para
.pFmt
;
1075 if (pFmt
->dwMask
& PFM_TABLE
&& pFmt
->wEffects
& PFE_TABLE
)
1077 /* rtfPar is treated like a space within a table. */
1078 info
->rtfClass
= rtfText
;
1079 info
->rtfMajor
= ' ';
1081 else if (info
->rtfMinor
== rtfPar
&& tableDef
)
1082 tableDef
->numCellsInserted
= 0;
1088 static BOOL
ME_RTFInsertOleObject(RTF_Info
*info
, HENHMETAFILE hemf
, HBITMAP hbmp
,
1091 LPOLEOBJECT lpObject
= NULL
;
1092 LPSTORAGE lpStorage
= NULL
;
1093 LPOLECLIENTSITE lpClientSite
= NULL
;
1094 LPDATAOBJECT lpDataObject
= NULL
;
1095 LPOLECACHE lpOleCache
= NULL
;
1104 stgm
.tymed
= TYMED_ENHMF
;
1105 stgm
.u
.hEnhMetaFile
= hemf
;
1106 fm
.cfFormat
= CF_ENHMETAFILE
;
1110 stgm
.tymed
= TYMED_GDI
;
1111 stgm
.u
.hBitmap
= hbmp
;
1112 fm
.cfFormat
= CF_BITMAP
;
1114 stgm
.pUnkForRelease
= NULL
;
1117 fm
.dwAspect
= DVASPECT_CONTENT
;
1119 fm
.tymed
= stgm
.tymed
;
1121 if (!info
->lpRichEditOle
)
1123 CreateIRichEditOle(info
->editor
, (VOID
**)&info
->lpRichEditOle
);
1126 if (OleCreateDefaultHandler(&CLSID_NULL
, NULL
, &IID_IOleObject
, (void**)&lpObject
) == S_OK
&&
1128 /* FIXME: enable it when rich-edit properly implements this method */
1129 IRichEditOle_GetClientSite(info
->lpRichEditOle
, &lpClientSite
) == S_OK
&&
1130 IOleObject_SetClientSite(lpObject
, lpClientSite
) == S_OK
&&
1132 IOleObject_GetUserClassID(lpObject
, &clsid
) == S_OK
&&
1133 IOleObject_QueryInterface(lpObject
, &IID_IOleCache
, (void**)&lpOleCache
) == S_OK
&&
1134 IOleCache_Cache(lpOleCache
, &fm
, 0, &conn
) == S_OK
&&
1135 IOleObject_QueryInterface(lpObject
, &IID_IDataObject
, (void**)&lpDataObject
) == S_OK
&&
1136 IDataObject_SetData(lpDataObject
, &fm
, &stgm
, TRUE
) == S_OK
)
1140 reobject
.cbStruct
= sizeof(reobject
);
1141 reobject
.cp
= REO_CP_SELECTION
;
1142 reobject
.clsid
= clsid
;
1143 reobject
.poleobj
= lpObject
;
1144 reobject
.pstg
= lpStorage
;
1145 reobject
.polesite
= lpClientSite
;
1146 /* convert from twips to .01 mm */
1147 reobject
.sizel
.cx
= MulDiv(sz
->cx
, 254, 144);
1148 reobject
.sizel
.cy
= MulDiv(sz
->cy
, 254, 144);
1149 reobject
.dvaspect
= DVASPECT_CONTENT
;
1150 reobject
.dwFlags
= 0; /* FIXME */
1151 reobject
.dwUser
= 0;
1153 /* FIXME: could be simpler */
1154 ret
= IRichEditOle_InsertObject(info
->lpRichEditOle
, &reobject
) == S_OK
;
1157 if (lpObject
) IOleObject_Release(lpObject
);
1158 if (lpClientSite
) IOleClientSite_Release(lpClientSite
);
1159 if (lpStorage
) IStorage_Release(lpStorage
);
1160 if (lpDataObject
) IDataObject_Release(lpDataObject
);
1161 if (lpOleCache
) IOleCache_Release(lpOleCache
);
1166 static void ME_RTFReadPictGroup(RTF_Info
*info
)
1169 BYTE
* buffer
= NULL
;
1170 unsigned bufsz
, bufidx
;
1176 enum gfxkind
{gfx_unknown
= 0, gfx_enhmetafile
, gfx_metafile
, gfx_dib
} gfx
= gfx_unknown
;
1179 if (info
->rtfClass
== rtfEOF
)
1182 /* fetch picture type */
1183 if (RTFCheckMM (info
, rtfPictAttr
, rtfWinMetafile
))
1185 mfp
.mm
= info
->rtfParam
;
1188 else if (RTFCheckMM (info
, rtfPictAttr
, rtfDevIndBitmap
))
1190 if (info
->rtfParam
!= 0) FIXME("dibitmap should be 0 (%d)\n", info
->rtfParam
);
1193 else if (RTFCheckMM (info
, rtfPictAttr
, rtfEmfBlip
))
1195 gfx
= gfx_enhmetafile
;
1199 FIXME("%d %d\n", info
->rtfMajor
, info
->rtfMinor
);
1203 /* fetch picture attributes */
1207 if (info
->rtfClass
== rtfEOF
)
1209 if (info
->rtfClass
== rtfText
)
1211 if (!RTFCheckCM (info
, rtfControl
, rtfPictAttr
))
1213 ERR("Expected picture attribute (%d %d)\n",
1214 info
->rtfClass
, info
->rtfMajor
);
1217 else if (RTFCheckMM (info
, rtfPictAttr
, rtfPicWid
))
1219 if (gfx
== gfx_metafile
) mfp
.xExt
= info
->rtfParam
;
1221 else if (RTFCheckMM (info
, rtfPictAttr
, rtfPicHt
))
1223 if (gfx
== gfx_metafile
) mfp
.yExt
= info
->rtfParam
;
1225 else if (RTFCheckMM (info
, rtfPictAttr
, rtfPicGoalWid
))
1226 sz
.cx
= info
->rtfParam
;
1227 else if (RTFCheckMM (info
, rtfPictAttr
, rtfPicGoalHt
))
1228 sz
.cy
= info
->rtfParam
;
1230 FIXME("Non supported attribute: %d %d %d\n", info
->rtfClass
, info
->rtfMajor
, info
->rtfMinor
);
1232 /* fetch picture data */
1235 buffer
= HeapAlloc(GetProcessHeap(), 0, bufsz
);
1236 val
= info
->rtfMajor
;
1237 for (flip
= TRUE
;; flip
= !flip
)
1240 if (info
->rtfClass
== rtfEOF
)
1242 HeapFree(GetProcessHeap(), 0, buffer
);
1243 return; /* Warn ?? */
1245 if (RTFCheckCM(info
, rtfGroup
, rtfEndGroup
))
1247 if (info
->rtfClass
!= rtfText
) goto skip_group
;
1250 if (bufidx
>= bufsz
&&
1251 !(buffer
= HeapReAlloc(GetProcessHeap(), 0, buffer
, bufsz
+= 1024)))
1253 buffer
[bufidx
++] = RTFCharToHex(val
) * 16 + RTFCharToHex(info
->rtfMajor
);
1256 val
= info
->rtfMajor
;
1258 if (flip
) FIXME("wrong hex string\n");
1262 case gfx_enhmetafile
:
1263 if ((hemf
= SetEnhMetaFileBits(bufidx
, buffer
)))
1264 ME_RTFInsertOleObject(info
, hemf
, NULL
, &sz
);
1267 if ((hemf
= SetWinMetaFileBits(bufidx
, buffer
, NULL
, &mfp
)))
1268 ME_RTFInsertOleObject(info
, hemf
, NULL
, &sz
);
1272 BITMAPINFO
* bi
= (BITMAPINFO
*)buffer
;
1274 unsigned nc
= bi
->bmiHeader
.biClrUsed
;
1276 /* not quite right, especially for bitfields type of compression */
1277 if (!nc
&& bi
->bmiHeader
.biBitCount
<= 8)
1278 nc
= 1 << bi
->bmiHeader
.biBitCount
;
1279 if ((hbmp
= CreateDIBitmap(hdc
, &bi
->bmiHeader
,
1280 CBM_INIT
, (char*)(bi
+ 1) + nc
* sizeof(RGBQUAD
),
1281 bi
, DIB_RGB_COLORS
)))
1282 ME_RTFInsertOleObject(info
, NULL
, hbmp
, &sz
);
1289 HeapFree(GetProcessHeap(), 0, buffer
);
1290 RTFRouteToken (info
); /* feed "}" back to router */
1293 HeapFree(GetProcessHeap(), 0, buffer
);
1295 RTFRouteToken(info
); /* feed "}" back to router */
1298 /* for now, lookup the \result part and use it, whatever the object */
1299 static void ME_RTFReadObjectGroup(RTF_Info
*info
)
1304 if (info
->rtfClass
== rtfEOF
)
1306 if (RTFCheckCM(info
, rtfGroup
, rtfEndGroup
))
1308 if (RTFCheckCM(info
, rtfGroup
, rtfBeginGroup
))
1311 if (info
->rtfClass
== rtfEOF
)
1313 if (RTFCheckCMM(info
, rtfControl
, rtfDestination
, rtfObjResult
))
1317 while (RTFGetToken (info
) != rtfEOF
)
1319 if (info
->rtfClass
== rtfGroup
)
1321 if (info
->rtfMajor
== rtfBeginGroup
) level
++;
1322 else if (info
->rtfMajor
== rtfEndGroup
&& --level
< 0) break;
1324 RTFRouteToken(info
);
1327 else RTFSkipGroup(info
);
1330 if (!RTFCheckCM (info
, rtfControl
, rtfObjAttr
))
1332 FIXME("Non supported attribute: %d %d %d\n", info
->rtfClass
, info
->rtfMajor
, info
->rtfMinor
);
1336 RTFRouteToken(info
); /* feed "}" back to router */
1339 static void ME_RTFReadHook(RTF_Info
*info
)
1341 switch(info
->rtfClass
)
1344 switch(info
->rtfMajor
)
1347 if (info
->stackTop
< maxStack
) {
1348 info
->stack
[info
->stackTop
].fmt
= info
->style
->fmt
;
1349 info
->stack
[info
->stackTop
].codePage
= info
->codePage
;
1350 info
->stack
[info
->stackTop
].unicodeLength
= info
->unicodeLength
;
1353 info
->styleChanged
= FALSE
;
1358 RTFFlushOutputBuffer(info
);
1360 if (info
->stackTop
<=0) {
1361 info
->rtfClass
= rtfEOF
;
1364 assert(info
->stackTop
>= 0);
1365 if (info
->styleChanged
)
1367 /* FIXME too slow ? how come ? */
1368 s
= ME_ApplyStyle(info
->style
, &info
->stack
[info
->stackTop
].fmt
);
1369 ME_ReleaseStyle(info
->style
);
1371 info
->codePage
= info
->stack
[info
->stackTop
].codePage
;
1372 info
->unicodeLength
= info
->stack
[info
->stackTop
].unicodeLength
;
1382 ME_StreamInFill(ME_InStream
*stream
)
1384 stream
->editstream
->dwError
= stream
->editstream
->pfnCallback(stream
->editstream
->dwCookie
,
1385 (BYTE
*)stream
->buffer
,
1386 sizeof(stream
->buffer
),
1387 (LONG
*)&stream
->dwSize
);
1391 static LRESULT
ME_StreamIn(ME_TextEditor
*editor
, DWORD format
, EDITSTREAM
*stream
, BOOL stripLastCR
)
1395 int from
, to
, to2
, nUndoMode
;
1396 int nEventMask
= editor
->nEventMask
;
1397 ME_InStream inStream
;
1398 BOOL invalidRTF
= FALSE
;
1400 TRACE("stream==%p editor==%p format==0x%X\n", stream
, editor
, format
);
1401 editor
->nEventMask
= 0;
1403 ME_GetSelection(editor
, &from
, &to
);
1404 if ((format
& SFF_SELECTION
) && (editor
->mode
& TM_RICHTEXT
)) {
1405 style
= ME_GetSelectionInsertStyle(editor
);
1407 ME_InternalDeleteText(editor
, from
, to
-from
, FALSE
);
1409 /* Don't insert text at the end of the table row */
1410 if (!editor
->bEmulateVersion10
) { /* v4.1 */
1411 ME_DisplayItem
*para
= editor
->pCursors
->pPara
;
1412 if (para
->member
.para
.nFlags
& MEPF_ROWEND
)
1414 para
= para
->member
.para
.next_para
;
1415 editor
->pCursors
[0].pPara
= para
;
1416 editor
->pCursors
[0].pRun
= ME_FindItemFwd(para
, diRun
);
1417 editor
->pCursors
[0].nOffset
= 0;
1419 if (para
->member
.para
.nFlags
& MEPF_ROWSTART
)
1421 para
= para
->member
.para
.next_para
;
1422 editor
->pCursors
[0].pPara
= para
;
1423 editor
->pCursors
[0].pRun
= ME_FindItemFwd(para
, diRun
);
1424 editor
->pCursors
[0].nOffset
= 0;
1426 editor
->pCursors
[1] = editor
->pCursors
[0];
1427 } else { /* v1.0 - 3.0 */
1428 if (editor
->pCursors
[0].pRun
->member
.run
.nFlags
& MERF_ENDPARA
&&
1429 ME_IsInTable(editor
->pCursors
[0].pRun
))
1434 style
= editor
->pBuffer
->pDefaultStyle
;
1435 ME_AddRefStyle(style
);
1436 ME_SetSelection(editor
, 0, 0);
1437 ME_InternalDeleteText(editor
, 0, ME_GetTextLength(editor
), FALSE
);
1439 ME_ClearTempStyle(editor
);
1440 ME_SetDefaultParaFormat(editor
->pCursors
[0].pPara
->member
.para
.pFmt
);
1444 /* Back up undo mode to a local variable */
1445 nUndoMode
= editor
->nUndoMode
;
1447 /* Only create an undo if SFF_SELECTION is set */
1448 if (!(format
& SFF_SELECTION
))
1449 editor
->nUndoMode
= umIgnore
;
1451 inStream
.editstream
= stream
;
1452 inStream
.editstream
->dwError
= 0;
1453 inStream
.dwSize
= 0;
1454 inStream
.dwUsed
= 0;
1456 if (format
& SF_RTF
)
1458 /* Check if it's really RTF, and if it is not, use plain text */
1459 ME_StreamInFill(&inStream
);
1460 if (!inStream
.editstream
->dwError
)
1462 if ((!editor
->bEmulateVersion10
&& strncmp(inStream
.buffer
, "{\\rtf", 5) && strncmp(inStream
.buffer
, "{\\urtf", 6))
1463 || (editor
->bEmulateVersion10
&& *inStream
.buffer
!= '{'))
1466 inStream
.editstream
->dwError
= -16;
1471 if (!invalidRTF
&& !inStream
.editstream
->dwError
)
1473 if (format
& SF_RTF
) {
1474 /* setup the RTF parser */
1475 memset(&parser
, 0, sizeof parser
);
1476 RTFSetEditStream(&parser
, &inStream
);
1477 parser
.rtfFormat
= format
&(SF_TEXT
|SF_RTF
);
1478 parser
.editor
= editor
;
1479 parser
.style
= style
;
1480 WriterInit(&parser
);
1482 RTFSetReadHook(&parser
, ME_RTFReadHook
);
1483 RTFSetDestinationCallback(&parser
, rtfPict
, ME_RTFReadPictGroup
);
1484 RTFSetDestinationCallback(&parser
, rtfObject
, ME_RTFReadObjectGroup
);
1485 if (!parser
.editor
->bEmulateVersion10
) /* v4.1 */
1487 RTFSetDestinationCallback(&parser
, rtfNoNestTables
, RTFSkipGroup
);
1488 RTFSetDestinationCallback(&parser
, rtfNestTableProps
, RTFReadGroup
);
1492 /* do the parsing */
1494 RTFFlushOutputBuffer(&parser
);
1495 if (!editor
->bEmulateVersion10
) { /* v4.1 */
1496 if (parser
.tableDef
&& parser
.tableDef
->tableRowStart
&&
1497 (parser
.nestingLevel
> 0 || parser
.canInheritInTbl
))
1499 /* Delete any incomplete table row at the end of the rich text. */
1501 ME_DisplayItem
*pCell
;
1502 ME_DisplayItem
*para
;
1504 parser
.rtfMinor
= rtfRow
;
1505 /* Complete the table row before deleting it.
1506 * By doing it this way we will have the current paragraph format set
1507 * properly to reflect that is not in the complete table, and undo items
1508 * will be added for this change to the current paragraph format. */
1509 if (parser
.nestingLevel
> 0)
1511 while (parser
.nestingLevel
> 1)
1512 ME_RTFSpecialCharHook(&parser
); /* Decrements nestingLevel */
1513 para
= parser
.tableDef
->tableRowStart
;
1514 ME_RTFSpecialCharHook(&parser
);
1516 para
= parser
.tableDef
->tableRowStart
;
1517 ME_RTFSpecialCharHook(&parser
);
1518 assert(para
->member
.para
.nFlags
& MEPF_ROWEND
);
1519 para
= para
->member
.para
.next_para
;
1521 pCell
= para
->member
.para
.pCell
;
1523 editor
->pCursors
[1].pPara
= para
;
1524 editor
->pCursors
[1].pRun
= ME_FindItemFwd(para
, diRun
);
1525 editor
->pCursors
[1].nOffset
= 0;
1526 nOfs
= ME_GetCursorOfs(editor
, 1);
1527 nChars
= ME_GetCursorOfs(editor
, 0) - nOfs
;
1528 ME_InternalDeleteText(editor
, nOfs
, nChars
, TRUE
);
1529 if (parser
.tableDef
)
1530 parser
.tableDef
->tableRowStart
= NULL
;
1533 ME_CheckTablesForCorruption(editor
);
1534 RTFDestroy(&parser
);
1535 if (parser
.lpRichEditOle
)
1536 IRichEditOle_Release(parser
.lpRichEditOle
);
1538 if (!inStream
.editstream
->dwError
&& parser
.stackTop
> 0)
1539 inStream
.editstream
->dwError
= HRESULT_FROM_WIN32(ERROR_HANDLE_EOF
);
1541 /* Remove last line break, as mandated by tests. This is not affected by
1542 CR/LF counters, since RTF streaming presents only \para tokens, which
1543 are converted according to the standard rules: \r for 2.0, \r\n for 1.0
1547 ME_GetSelection(editor
, &newfrom
, &newto
);
1548 if (newto
> to
+ (editor
->bEmulateVersion10
? 1 : 0)) {
1549 WCHAR lastchar
[3] = {'\0', '\0'};
1550 int linebreakSize
= editor
->bEmulateVersion10
? 2 : 1;
1552 ME_GetTextW(editor
, lastchar
, newto
- linebreakSize
, linebreakSize
, 0);
1553 if (lastchar
[0] == '\r' && (lastchar
[1] == '\n' || lastchar
[1] == '\0')) {
1554 ME_InternalDeleteText(editor
, newto
- linebreakSize
, linebreakSize
, FALSE
);
1559 style
= parser
.style
;
1561 else if (format
& SF_TEXT
)
1562 ME_StreamInText(editor
, format
, &inStream
, style
);
1564 ERR("EM_STREAMIN without SF_TEXT or SF_RTF\n");
1565 ME_GetSelection(editor
, &to
, &to2
);
1566 /* put the cursor at the top */
1567 if (!(format
& SFF_SELECTION
))
1568 ME_SetSelection(editor
, 0, 0);
1571 /* Restore saved undo mode */
1572 editor
->nUndoMode
= nUndoMode
;
1574 /* even if we didn't add an undo, we need to commit anything on the stack */
1575 ME_CommitUndo(editor
);
1577 /* If SFF_SELECTION isn't set, delete any undos from before we started too */
1578 if (!(format
& SFF_SELECTION
))
1579 ME_EmptyUndoStack(editor
);
1581 ME_ReleaseStyle(style
);
1582 editor
->nEventMask
= nEventMask
;
1583 ME_UpdateRepaint(editor
);
1584 if (!(format
& SFF_SELECTION
)) {
1585 ME_ClearTempStyle(editor
);
1587 ITextHost_TxShowCaret(editor
->texthost
, FALSE
);
1588 ME_MoveCaret(editor
);
1589 ITextHost_TxShowCaret(editor
->texthost
, TRUE
);
1590 ME_SendSelChange(editor
);
1591 ME_SendRequestResize(editor
, FALSE
);
1597 typedef struct tagME_RTFStringStreamStruct
1602 } ME_RTFStringStreamStruct
;
1604 static DWORD CALLBACK
ME_ReadFromRTFString(DWORD_PTR dwCookie
, LPBYTE lpBuff
, LONG cb
, LONG
*pcb
)
1606 ME_RTFStringStreamStruct
*pStruct
= (ME_RTFStringStreamStruct
*)dwCookie
;
1609 count
= min(cb
, pStruct
->length
- pStruct
->pos
);
1610 memmove(lpBuff
, pStruct
->string
+ pStruct
->pos
, count
);
1611 pStruct
->pos
+= count
;
1617 ME_StreamInRTFString(ME_TextEditor
*editor
, BOOL selection
, char *string
)
1620 ME_RTFStringStreamStruct data
;
1622 data
.string
= string
;
1623 data
.length
= strlen(string
);
1625 es
.dwCookie
= (DWORD_PTR
)&data
;
1626 es
.pfnCallback
= ME_ReadFromRTFString
;
1627 ME_StreamIn(editor
, SF_RTF
| (selection
? SFF_SELECTION
: 0), &es
, FALSE
);
1632 ME_FindText(ME_TextEditor
*editor
, DWORD flags
, const CHARRANGE
*chrg
, const WCHAR
*text
, CHARRANGE
*chrgText
)
1634 const int nLen
= lstrlenW(text
);
1635 const int nTextLen
= ME_GetTextLength(editor
);
1638 ME_DisplayItem
*item
;
1639 ME_DisplayItem
*para
;
1640 WCHAR wLastChar
= ' ';
1642 TRACE("flags==0x%08x, chrg->cpMin==%d, chrg->cpMax==%d text==%s\n",
1643 flags
, chrg
->cpMin
, chrg
->cpMax
, debugstr_w(text
));
1645 if (flags
& ~(FR_DOWN
| FR_MATCHCASE
| FR_WHOLEWORD
))
1646 FIXME("Flags 0x%08x not implemented\n",
1647 flags
& ~(FR_DOWN
| FR_MATCHCASE
| FR_WHOLEWORD
));
1650 if (chrg
->cpMax
== -1)
1653 nMax
= chrg
->cpMax
> nTextLen
? nTextLen
: chrg
->cpMax
;
1655 /* In 1.0 emulation, if cpMax reaches end of text, add the FR_DOWN flag */
1656 if (editor
->bEmulateVersion10
&& nMax
== nTextLen
)
1661 /* In 1.0 emulation, cpMin must always be no greater than cpMax */
1662 if (editor
->bEmulateVersion10
&& nMax
< nMin
)
1666 chrgText
->cpMin
= -1;
1667 chrgText
->cpMax
= -1;
1672 /* when searching up, if cpMin < cpMax, then instead of searching
1673 * on [cpMin,cpMax], we search on [0,cpMin], otherwise, search on
1674 * [cpMax, cpMin]. The exception is when cpMax is -1, in which
1675 * case, it is always bigger than cpMin.
1677 if (!editor
->bEmulateVersion10
&& !(flags
& FR_DOWN
))
1681 nMax
= nMin
> nTextLen
? nTextLen
: nMin
;
1682 if (nMin
< nSwap
|| chrg
->cpMax
== -1)
1688 if (!nLen
|| nMin
< 0 || nMax
< 0 || nMax
< nMin
)
1691 chrgText
->cpMin
= chrgText
->cpMax
= -1;
1695 if (flags
& FR_DOWN
) /* Forward search */
1697 /* If possible, find the character before where the search starts */
1698 if ((flags
& FR_WHOLEWORD
) && nMin
)
1700 ME_RunOfsFromCharOfs(editor
, nMin
- 1, NULL
, &item
, &nStart
);
1701 wLastChar
= item
->member
.run
.strText
->szData
[nStart
];
1704 ME_RunOfsFromCharOfs(editor
, nMin
, ¶
, &item
, &nStart
);
1707 && para
->member
.para
.nCharOfs
+ item
->member
.run
.nCharOfs
+ nStart
+ nLen
<= nMax
)
1709 ME_DisplayItem
*pCurItem
= item
;
1710 int nCurStart
= nStart
;
1713 while (pCurItem
&& ME_CharCompare(pCurItem
->member
.run
.strText
->szData
[nCurStart
+ nMatched
], text
[nMatched
], (flags
& FR_MATCHCASE
)))
1715 if ((flags
& FR_WHOLEWORD
) && isalnumW(wLastChar
))
1719 if (nMatched
== nLen
)
1721 ME_DisplayItem
*pNextItem
= pCurItem
;
1722 int nNextStart
= nCurStart
;
1725 /* Check to see if next character is a whitespace */
1726 if (flags
& FR_WHOLEWORD
)
1728 if (nCurStart
+ nMatched
== pCurItem
->member
.run
.strText
->nLen
)
1730 pNextItem
= ME_FindItemFwd(pCurItem
, diRun
);
1731 nNextStart
= -nMatched
;
1735 wNextChar
= pNextItem
->member
.run
.strText
->szData
[nNextStart
+ nMatched
];
1739 if (isalnumW(wNextChar
))
1743 nStart
+= para
->member
.para
.nCharOfs
+ item
->member
.run
.nCharOfs
;
1746 chrgText
->cpMin
= nStart
;
1747 chrgText
->cpMax
= nStart
+ nLen
;
1749 TRACE("found at %d-%d\n", nStart
, nStart
+ nLen
);
1752 if (nCurStart
+ nMatched
== pCurItem
->member
.run
.strText
->nLen
)
1754 pCurItem
= ME_FindItemFwd(pCurItem
, diRun
);
1755 nCurStart
= -nMatched
;
1759 wLastChar
= pCurItem
->member
.run
.strText
->szData
[nCurStart
+ nMatched
];
1764 if (nStart
== item
->member
.run
.strText
->nLen
)
1766 item
= ME_FindItemFwd(item
, diRun
);
1767 para
= ME_GetParagraph(item
);
1772 else /* Backward search */
1774 /* If possible, find the character after where the search ends */
1775 if ((flags
& FR_WHOLEWORD
) && nMax
< nTextLen
- 1)
1777 ME_RunOfsFromCharOfs(editor
, nMax
+ 1, NULL
, &item
, &nEnd
);
1778 wLastChar
= item
->member
.run
.strText
->szData
[nEnd
];
1781 ME_RunOfsFromCharOfs(editor
, nMax
, ¶
, &item
, &nEnd
);
1784 && para
->member
.para
.nCharOfs
+ item
->member
.run
.nCharOfs
+ nEnd
- nLen
>= nMin
)
1786 ME_DisplayItem
*pCurItem
= item
;
1792 pCurItem
= ME_FindItemBack(pCurItem
, diRun
);
1793 nCurEnd
= pCurItem
->member
.run
.strText
->nLen
+ nMatched
;
1796 while (pCurItem
&& ME_CharCompare(pCurItem
->member
.run
.strText
->szData
[nCurEnd
- nMatched
- 1], text
[nLen
- nMatched
- 1], (flags
& FR_MATCHCASE
)))
1798 if ((flags
& FR_WHOLEWORD
) && isalnumW(wLastChar
))
1802 if (nMatched
== nLen
)
1804 ME_DisplayItem
*pPrevItem
= pCurItem
;
1805 int nPrevEnd
= nCurEnd
;
1808 /* Check to see if previous character is a whitespace */
1809 if (flags
& FR_WHOLEWORD
)
1811 if (nPrevEnd
- nMatched
== 0)
1813 pPrevItem
= ME_FindItemBack(pCurItem
, diRun
);
1815 nPrevEnd
= pPrevItem
->member
.run
.strText
->nLen
+ nMatched
;
1819 wPrevChar
= pPrevItem
->member
.run
.strText
->szData
[nPrevEnd
- nMatched
- 1];
1823 if (isalnumW(wPrevChar
))
1827 nStart
= ME_GetParagraph(pCurItem
)->member
.para
.nCharOfs
1828 + pCurItem
->member
.run
.nCharOfs
+ nCurEnd
- nMatched
;
1831 chrgText
->cpMin
= nStart
;
1832 chrgText
->cpMax
= nStart
+ nLen
;
1834 TRACE("found at %d-%d\n", nStart
, nStart
+ nLen
);
1837 if (nCurEnd
- nMatched
== 0)
1839 pCurItem
= ME_FindItemBack(pCurItem
, diRun
);
1840 /* Don't care about pCurItem becoming NULL here; it's already taken
1841 * care of in the exterior loop condition */
1842 nCurEnd
= pCurItem
->member
.run
.strText
->nLen
+ nMatched
;
1846 wLastChar
= pCurItem
->member
.run
.strText
->szData
[nCurEnd
- nMatched
- 1];
1853 item
= ME_FindItemBack(item
, diRun
);
1854 para
= ME_GetParagraph(item
);
1855 nEnd
= item
->member
.run
.strText
->nLen
;
1859 TRACE("not found\n");
1861 chrgText
->cpMin
= chrgText
->cpMax
= -1;
1865 static int ME_GetTextEx(ME_TextEditor
*editor
, GETTEXTEX
*ex
, LPARAM pText
)
1867 int nStart
, nCount
; /* in chars */
1869 if (ex
->flags
& ~(GT_SELECTION
| GT_USECRLF
))
1870 FIXME("GETTEXTEX flags 0x%08x not supported\n", ex
->flags
& ~(GT_SELECTION
| GT_USECRLF
));
1872 if (ex
->flags
& GT_SELECTION
)
1874 ME_GetSelection(editor
, &nStart
, &nCount
);
1880 nCount
= 0x7fffffff;
1882 if (ex
->codepage
== 1200)
1884 nCount
= min(nCount
, ex
->cb
/ sizeof(WCHAR
) - 1);
1885 return ME_GetTextW(editor
, (LPWSTR
)pText
, nStart
, nCount
, ex
->flags
& GT_USECRLF
);
1889 /* potentially each char may be a CR, why calculate the exact value with O(N) when
1890 we can just take a bigger buffer? :)
1891 The above assumption still holds with CR/LF counters, since CR->CRLF expansion
1892 occurs only in richedit 2.0 mode, in which line breaks have only one CR
1894 int crlfmul
= (ex
->flags
& GT_USECRLF
) ? 2 : 1;
1896 DWORD buflen
= ex
->cb
;
1900 nCount
= min(nCount
, ex
->cb
- 1);
1901 buffer
= heap_alloc((crlfmul
*nCount
+ 1) * sizeof(WCHAR
));
1903 buflen
= ME_GetTextW(editor
, buffer
, nStart
, nCount
, ex
->flags
& GT_USECRLF
);
1904 rc
= WideCharToMultiByte(ex
->codepage
, flags
, buffer
, buflen
+1,
1905 (LPSTR
)pText
, ex
->cb
, ex
->lpDefaultChar
, ex
->lpUsedDefChar
);
1906 if (rc
) rc
--; /* do not count 0 terminator */
1913 static int ME_GetTextRange(ME_TextEditor
*editor
, WCHAR
*strText
,
1914 int start
, int nLen
, BOOL unicode
)
1917 return ME_GetTextW(editor
, strText
, start
, nLen
, 0);
1919 WCHAR
*p
= ALLOC_N_OBJ(WCHAR
, nLen
+1);
1920 int nChars
= ME_GetTextW(editor
, p
, start
, nLen
, 0);
1921 WideCharToMultiByte(CP_ACP
, 0, p
, nChars
+1, (char *)strText
,
1922 nLen
+1, NULL
, NULL
);
1928 typedef struct tagME_GlobalDestStruct
1932 } ME_GlobalDestStruct
;
1934 static DWORD CALLBACK
ME_ReadFromHGLOBALUnicode(DWORD_PTR dwCookie
, LPBYTE lpBuff
, LONG cb
, LONG
*pcb
)
1936 ME_GlobalDestStruct
*pData
= (ME_GlobalDestStruct
*)dwCookie
;
1941 pDest
= (WORD
*)lpBuff
;
1942 pSrc
= GlobalLock(pData
->hData
);
1943 for (i
= 0; i
<cb
&& pSrc
[pData
->nLength
+i
]; i
++) {
1944 pDest
[i
] = pSrc
[pData
->nLength
+i
];
1946 pData
->nLength
+= i
;
1948 GlobalUnlock(pData
->hData
);
1952 static DWORD CALLBACK
ME_ReadFromHGLOBALRTF(DWORD_PTR dwCookie
, LPBYTE lpBuff
, LONG cb
, LONG
*pcb
)
1954 ME_GlobalDestStruct
*pData
= (ME_GlobalDestStruct
*)dwCookie
;
1959 pSrc
= GlobalLock(pData
->hData
);
1960 for (i
= 0; i
<cb
&& pSrc
[pData
->nLength
+i
]; i
++) {
1961 pDest
[i
] = pSrc
[pData
->nLength
+i
];
1963 pData
->nLength
+= i
;
1965 GlobalUnlock(pData
->hData
);
1969 static BOOL
ME_Paste(ME_TextEditor
*editor
)
1973 ME_GlobalDestStruct gds
;
1974 UINT nRTFFormat
= RegisterClipboardFormatA("Rich Text Format");
1977 if (IsClipboardFormatAvailable(nRTFFormat
))
1978 cf
= nRTFFormat
, dwFormat
= SF_RTF
;
1979 else if (IsClipboardFormatAvailable(CF_UNICODETEXT
))
1980 cf
= CF_UNICODETEXT
, dwFormat
= SF_TEXT
|SF_UNICODE
;
1984 if (!OpenClipboard(editor
->hWnd
))
1986 gds
.hData
= GetClipboardData(cf
);
1988 es
.dwCookie
= (DWORD_PTR
)&gds
;
1989 es
.pfnCallback
= dwFormat
== SF_RTF
? ME_ReadFromHGLOBALRTF
: ME_ReadFromHGLOBALUnicode
;
1990 ME_StreamIn(editor
, dwFormat
|SFF_SELECTION
, &es
, FALSE
);
1996 static BOOL
ME_Copy(ME_TextEditor
*editor
, CHARRANGE
*range
)
1998 LPDATAOBJECT dataObj
= NULL
;
2001 if (editor
->cPasswordMask
)
2002 return FALSE
; /* Copying or Cutting masked text isn't allowed */
2004 if(editor
->lpOleCallback
)
2005 hr
= IRichEditOleCallback_GetClipboardData(editor
->lpOleCallback
, range
, RECO_COPY
, &dataObj
);
2006 if(FAILED(hr
) || !dataObj
)
2007 hr
= ME_GetDataObject(editor
, range
, &dataObj
);
2009 hr
= OleSetClipboard(dataObj
);
2010 IDataObject_Release(dataObj
);
2012 return SUCCEEDED(hr
) != 0;
2015 /* helper to send a msg filter notification */
2017 ME_FilterEvent(ME_TextEditor
*editor
, UINT msg
, WPARAM
* wParam
, LPARAM
* lParam
)
2021 if (!editor
->hWnd
) return FALSE
;
2022 msgf
.nmhdr
.hwndFrom
= editor
->hWnd
;
2023 msgf
.nmhdr
.idFrom
= GetWindowLongW(editor
->hWnd
, GWLP_ID
);
2024 msgf
.nmhdr
.code
= EN_MSGFILTER
;
2026 msgf
.wParam
= *wParam
;
2027 msgf
.lParam
= *lParam
;
2028 if (SendMessageW(GetParent(editor
->hWnd
), WM_NOTIFY
, msgf
.nmhdr
.idFrom
, (LPARAM
)&msgf
))
2030 *wParam
= msgf
.wParam
;
2031 *lParam
= msgf
.lParam
;
2032 msgf
.wParam
= *wParam
;
2037 static void ME_UpdateSelectionLinkAttribute(ME_TextEditor
*editor
)
2039 ME_DisplayItem
*startPara
, *endPara
;
2040 ME_DisplayItem
*prev_para
;
2043 if (!editor
->AutoURLDetect_bEnable
) return;
2045 ME_GetSelection(editor
, &from
, &to
);
2047 /* Find paragraph previous to the one that contains start cursor */
2048 ME_RunOfsFromCharOfs(editor
, from
, &startPara
, NULL
, NULL
);
2049 prev_para
= startPara
->member
.para
.prev_para
;
2050 if (prev_para
->type
== diParagraph
) startPara
= prev_para
;
2052 /* Find paragraph that contains end cursor */
2053 ME_RunOfsFromCharOfs(editor
, to
, &endPara
, NULL
, NULL
);
2054 endPara
= endPara
->member
.para
.next_para
;
2056 ME_UpdateLinkAttribute(editor
,
2057 startPara
->member
.para
.nCharOfs
,
2058 endPara
->member
.para
.nCharOfs
);
2062 ME_KeyDown(ME_TextEditor
*editor
, WORD nKey
)
2064 BOOL ctrl_is_down
= GetKeyState(VK_CONTROL
) & 0x8000;
2065 BOOL shift_is_down
= GetKeyState(VK_SHIFT
) & 0x8000;
2067 if (editor
->bMouseCaptured
)
2069 if (nKey
!= VK_SHIFT
&& nKey
!= VK_CONTROL
&& nKey
!= VK_MENU
)
2070 editor
->nSelectionType
= stPosition
;
2078 editor
->nUDArrowX
= -1;
2084 ME_CommitUndo(editor
); /* End coalesced undos for typed characters */
2085 ME_ArrowKey(editor
, nKey
, shift_is_down
, ctrl_is_down
);
2089 editor
->nUDArrowX
= -1;
2090 /* FIXME backspace and delete aren't the same, they act different wrt paragraph style of the merged paragraph */
2091 if (editor
->styleFlags
& ES_READONLY
)
2093 if (ME_IsSelection(editor
))
2095 ME_DeleteSelection(editor
);
2096 ME_CommitUndo(editor
);
2098 else if (nKey
== VK_DELETE
)
2100 /* Delete stops group typing.
2101 * (See MSDN remarks on EM_STOPGROUPTYPING message) */
2102 ME_DeleteTextAtCursor(editor
, 1, 1);
2103 ME_CommitUndo(editor
);
2105 else if (ME_ArrowKey(editor
, VK_LEFT
, FALSE
, FALSE
))
2107 BOOL bDeletionSucceeded
;
2108 /* Backspace can be grouped for a single undo */
2109 ME_ContinueCoalescingTransaction(editor
);
2110 bDeletionSucceeded
= ME_DeleteTextAtCursor(editor
, 1, 1);
2111 if (!bDeletionSucceeded
&& !editor
->bEmulateVersion10
) { /* v4.1 */
2112 /* Deletion was prevented so the cursor is moved back to where it was.
2113 * (e.g. this happens when trying to delete cell boundaries)
2115 ME_ArrowKey(editor
, VK_RIGHT
, FALSE
, FALSE
);
2117 ME_CommitCoalescingUndo(editor
);
2121 ME_MoveCursorFromTableRowStartParagraph(editor
);
2122 ME_UpdateSelectionLinkAttribute(editor
);
2123 ME_UpdateRepaint(editor
);
2124 ME_SendRequestResize(editor
, FALSE
);
2127 if (editor
->styleFlags
& ES_MULTILINE
)
2129 ME_Cursor cursor
= editor
->pCursors
[0];
2130 ME_DisplayItem
*para
= cursor
.pPara
;
2132 const WCHAR endl
= '\r';
2135 if (editor
->styleFlags
& ES_READONLY
) {
2136 MessageBeep(MB_ICONERROR
);
2140 ME_GetSelection(editor
, &from
, &to
);
2141 if (editor
->nTextLimit
> ME_GetTextLength(editor
) - (to
-from
))
2143 if (!editor
->bEmulateVersion10
) { /* v4.1 */
2144 if (para
->member
.para
.nFlags
& MEPF_ROWEND
) {
2145 /* Add a new table row after this row. */
2146 para
= ME_AppendTableRow(editor
, para
);
2147 para
= para
->member
.para
.next_para
;
2148 editor
->pCursors
[0].pPara
= para
;
2149 editor
->pCursors
[0].pRun
= ME_FindItemFwd(para
, diRun
);
2150 editor
->pCursors
[0].nOffset
= 0;
2151 editor
->pCursors
[1] = editor
->pCursors
[0];
2152 ME_CommitUndo(editor
);
2153 ME_CheckTablesForCorruption(editor
);
2154 ME_UpdateRepaint(editor
);
2157 else if (para
== editor
->pCursors
[1].pPara
&&
2158 cursor
.nOffset
+ cursor
.pRun
->member
.run
.nCharOfs
== 0 &&
2159 para
->member
.para
.prev_para
->member
.para
.nFlags
& MEPF_ROWSTART
&&
2160 !para
->member
.para
.prev_para
->member
.para
.nCharOfs
)
2162 /* Insert a newline before the table. */
2163 para
= para
->member
.para
.prev_para
;
2164 para
->member
.para
.nFlags
&= ~MEPF_ROWSTART
;
2165 editor
->pCursors
[0].pPara
= para
;
2166 editor
->pCursors
[0].pRun
= ME_FindItemFwd(para
, diRun
);
2167 editor
->pCursors
[1] = editor
->pCursors
[0];
2168 ME_InsertTextFromCursor(editor
, 0, &endl
, 1,
2169 editor
->pCursors
[0].pRun
->member
.run
.style
);
2170 para
= editor
->pBuffer
->pFirst
->member
.para
.next_para
;
2171 ME_SetDefaultParaFormat(para
->member
.para
.pFmt
);
2172 para
->member
.para
.nFlags
= MEPF_REWRAP
;
2173 editor
->pCursors
[0].pPara
= para
;
2174 editor
->pCursors
[0].pRun
= ME_FindItemFwd(para
, diRun
);
2175 editor
->pCursors
[1] = editor
->pCursors
[0];
2176 para
->member
.para
.next_para
->member
.para
.nFlags
|= MEPF_ROWSTART
;
2177 ME_CommitCoalescingUndo(editor
);
2178 ME_CheckTablesForCorruption(editor
);
2179 ME_UpdateRepaint(editor
);
2182 } else { /* v1.0 - 3.0 */
2183 ME_DisplayItem
*para
= cursor
.pPara
;
2184 if (ME_IsInTable(para
))
2186 if (cursor
.pRun
->member
.run
.nFlags
& MERF_ENDPARA
)
2189 ME_ContinueCoalescingTransaction(editor
);
2190 para
= ME_AppendTableRow(editor
, para
);
2191 editor
->pCursors
[0].pPara
= para
;
2192 editor
->pCursors
[0].pRun
= ME_FindItemFwd(para
, diRun
);
2193 editor
->pCursors
[0].nOffset
= 0;
2194 editor
->pCursors
[1] = editor
->pCursors
[0];
2195 ME_CommitCoalescingUndo(editor
);
2196 ME_UpdateRepaint(editor
);
2200 ME_ContinueCoalescingTransaction(editor
);
2201 if (cursor
.pRun
->member
.run
.nCharOfs
+ cursor
.nOffset
== 0 &&
2202 !ME_IsInTable(para
->member
.para
.prev_para
))
2204 /* Insert newline before table */
2205 cursor
.pRun
= ME_FindItemBack(para
, diRun
);
2207 editor
->pCursors
[0].pRun
= cursor
.pRun
;
2208 editor
->pCursors
[0].pPara
= para
->member
.para
.prev_para
;
2210 editor
->pCursors
[0].nOffset
= 0;
2211 editor
->pCursors
[1] = editor
->pCursors
[0];
2212 ME_InsertTextFromCursor(editor
, 0, &endl
, 1,
2213 editor
->pCursors
[0].pRun
->member
.run
.style
);
2215 editor
->pCursors
[1] = editor
->pCursors
[0];
2216 para
= ME_AppendTableRow(editor
, para
);
2217 editor
->pCursors
[0].pPara
= para
;
2218 editor
->pCursors
[0].pRun
= ME_FindItemFwd(para
, diRun
);
2219 editor
->pCursors
[0].nOffset
= 0;
2220 editor
->pCursors
[1] = editor
->pCursors
[0];
2222 ME_CommitCoalescingUndo(editor
);
2223 ME_UpdateRepaint(editor
);
2229 style
= ME_GetInsertStyle(editor
, 0);
2230 ME_SaveTempStyle(editor
);
2231 ME_ContinueCoalescingTransaction(editor
);
2233 ME_InsertEndRowFromCursor(editor
, 0);
2235 ME_InsertTextFromCursor(editor
, 0, &endl
, 1, style
);
2236 ME_ReleaseStyle(style
);
2237 ME_CommitCoalescingUndo(editor
);
2240 ME_UpdateSelectionLinkAttribute(editor
);
2241 ME_UpdateRepaint(editor
);
2249 ME_SetSelection(editor
, 0, -1);
2255 return ME_Paste(editor
);
2264 ME_GetSelection(editor
, &range
.cpMin
, &range
.cpMax
);
2265 result
= ME_Copy(editor
, &range
);
2266 if (result
&& nKey
== 'X')
2268 ME_InternalDeleteText(editor
, range
.cpMin
, range
.cpMax
-range
.cpMin
, FALSE
);
2269 ME_CommitUndo(editor
);
2270 ME_UpdateRepaint(editor
);
2291 if (nKey
!= VK_SHIFT
&& nKey
!= VK_CONTROL
&& nKey
&& nKey
!= VK_MENU
)
2292 editor
->nUDArrowX
= -1;
2299 chf
.cbSize
= sizeof(chf
);
2301 ME_GetSelectionCharFormat(editor
, &chf
);
2302 ME_DumpStyleToBuf(&chf
, buf
);
2303 MessageBoxA(NULL
, buf
, "Style dump", MB_OK
);
2307 ME_CheckCharOffsets(editor
);
2314 static LRESULT
ME_Char(ME_TextEditor
*editor
, WPARAM charCode
,
2315 LPARAM flags
, BOOL unicode
)
2319 if (editor
->bMouseCaptured
)
2323 wstr
= (WCHAR
)charCode
;
2326 CHAR charA
= charCode
;
2327 MultiByteToWideChar(CP_ACP
, 0, &charA
, 1, &wstr
, 1);
2330 if (editor
->styleFlags
& ES_READONLY
) {
2331 MessageBeep(MB_ICONERROR
);
2332 return 0; /* FIXME really 0 ? */
2335 if ((unsigned)wstr
>= ' ' || wstr
== '\t')
2337 ME_Cursor cursor
= editor
->pCursors
[0];
2338 ME_DisplayItem
*para
= cursor
.pPara
;
2340 BOOL ctrl_is_down
= GetKeyState(VK_CONTROL
) & 0x8000;
2341 ME_GetSelection(editor
, &from
, &to
);
2343 /* v4.1 allows tabs to be inserted with ctrl key down */
2344 !(ctrl_is_down
&& !editor
->bEmulateVersion10
))
2346 ME_DisplayItem
*para
;
2347 BOOL bSelectedRow
= FALSE
;
2349 para
= cursor
.pPara
;
2350 if (ME_IsSelection(editor
) &&
2351 cursor
.pRun
->member
.run
.nCharOfs
+ cursor
.nOffset
== 0 &&
2352 to
== ME_GetCursorOfs(editor
, 0) &&
2353 para
->member
.para
.prev_para
->type
== diParagraph
)
2355 para
= para
->member
.para
.prev_para
;
2356 bSelectedRow
= TRUE
;
2358 if (ME_IsInTable(para
))
2360 ME_TabPressedInTable(editor
, bSelectedRow
);
2361 ME_CommitUndo(editor
);
2364 } else if (!editor
->bEmulateVersion10
) { /* v4.1 */
2365 if (para
->member
.para
.nFlags
& MEPF_ROWEND
) {
2367 para
= para
->member
.para
.next_para
;
2368 if (para
->member
.para
.nFlags
& MEPF_ROWSTART
)
2369 para
= para
->member
.para
.next_para
;
2370 editor
->pCursors
[0].pPara
= para
;
2371 editor
->pCursors
[0].pRun
= ME_FindItemFwd(para
, diRun
);
2372 editor
->pCursors
[0].nOffset
= 0;
2373 editor
->pCursors
[1] = editor
->pCursors
[0];
2376 } else { /* v1.0 - 3.0 */
2377 if (ME_IsInTable(cursor
.pRun
) &&
2378 cursor
.pRun
->member
.run
.nFlags
& MERF_ENDPARA
&&
2381 /* Text should not be inserted at the end of the table. */
2386 /* FIXME maybe it would make sense to call EM_REPLACESEL instead ? */
2387 /* WM_CHAR is restricted to nTextLimit */
2388 if(editor
->nTextLimit
> ME_GetTextLength(editor
) - (to
-from
))
2390 ME_Style
*style
= ME_GetInsertStyle(editor
, 0);
2391 ME_SaveTempStyle(editor
);
2392 ME_ContinueCoalescingTransaction(editor
);
2393 ME_InsertTextFromCursor(editor
, 0, &wstr
, 1, style
);
2394 ME_ReleaseStyle(style
);
2395 ME_CommitCoalescingUndo(editor
);
2396 ITextHost_TxSetCursor(editor
->texthost
, NULL
, FALSE
);
2399 ME_UpdateSelectionLinkAttribute(editor
);
2400 ME_UpdateRepaint(editor
);
2405 /* Process the message and calculate the new click count.
2407 * returns: The click count if it is mouse down event, else returns 0. */
2408 static int ME_CalculateClickCount(ME_TextEditor
*editor
, UINT msg
, WPARAM wParam
,
2411 static int clickNum
= 0;
2412 if (msg
< WM_MOUSEFIRST
|| msg
> WM_MOUSELAST
)
2415 if ((msg
== WM_LBUTTONDBLCLK
) ||
2416 (msg
== WM_RBUTTONDBLCLK
) ||
2417 (msg
== WM_MBUTTONDBLCLK
) ||
2418 (msg
== WM_XBUTTONDBLCLK
))
2420 msg
-= (WM_LBUTTONDBLCLK
- WM_LBUTTONDOWN
);
2423 if ((msg
== WM_LBUTTONDOWN
) ||
2424 (msg
== WM_RBUTTONDOWN
) ||
2425 (msg
== WM_MBUTTONDOWN
) ||
2426 (msg
== WM_XBUTTONDOWN
))
2428 static MSG prevClickMsg
;
2430 /* Compare the editor instead of the hwnd so that the this
2431 * can still be done for windowless richedit controls. */
2432 clickMsg
.hwnd
= (HWND
)editor
;
2433 clickMsg
.message
= msg
;
2434 clickMsg
.wParam
= wParam
;
2435 clickMsg
.lParam
= lParam
;
2436 clickMsg
.time
= GetMessageTime();
2437 clickMsg
.pt
.x
= (short)LOWORD(lParam
);
2438 clickMsg
.pt
.y
= (short)HIWORD(lParam
);
2439 if ((clickNum
!= 0) &&
2440 (clickMsg
.message
== prevClickMsg
.message
) &&
2441 (clickMsg
.hwnd
== prevClickMsg
.hwnd
) &&
2442 (clickMsg
.wParam
== prevClickMsg
.wParam
) &&
2443 (clickMsg
.time
- prevClickMsg
.time
< GetDoubleClickTime()) &&
2444 (abs(clickMsg
.pt
.x
- prevClickMsg
.pt
.x
) < GetSystemMetrics(SM_CXDOUBLECLK
)/2) &&
2445 (abs(clickMsg
.pt
.y
- prevClickMsg
.pt
.y
) < GetSystemMetrics(SM_CYDOUBLECLK
)/2))
2451 prevClickMsg
= clickMsg
;
2458 static BOOL
ME_SetCursor(ME_TextEditor
*editor
)
2464 DWORD messagePos
= GetMessagePos();
2465 pt
.x
= (short)LOWORD(messagePos
);
2466 pt
.y
= (short)HIWORD(messagePos
);
2470 sbi
.cbSize
= sizeof(sbi
);
2471 GetScrollBarInfo(editor
->hWnd
, OBJID_HSCROLL
, &sbi
);
2472 if (!(sbi
.rgstate
[0] & (STATE_SYSTEM_INVISIBLE
|STATE_SYSTEM_OFFSCREEN
)) &&
2473 PtInRect(&sbi
.rcScrollBar
, pt
))
2475 ITextHost_TxSetCursor(editor
->texthost
,
2476 LoadCursorW(NULL
, (WCHAR
*)IDC_ARROW
), FALSE
);
2479 sbi
.cbSize
= sizeof(sbi
);
2480 GetScrollBarInfo(editor
->hWnd
, OBJID_VSCROLL
, &sbi
);
2481 if (!(sbi
.rgstate
[0] & (STATE_SYSTEM_INVISIBLE
|STATE_SYSTEM_OFFSCREEN
)) &&
2482 PtInRect(&sbi
.rcScrollBar
, pt
))
2484 ITextHost_TxSetCursor(editor
->texthost
,
2485 LoadCursorW(NULL
, (WCHAR
*)IDC_ARROW
), FALSE
);
2489 ITextHost_TxScreenToClient(editor
->texthost
, &pt
);
2491 if (editor
->nSelectionType
== stLine
&& editor
->bMouseCaptured
) {
2492 ITextHost_TxSetCursor(editor
->texthost
, hLeft
, FALSE
);
2495 if (!editor
->bEmulateVersion10
/* v4.1 */ &&
2496 pt
.y
< editor
->rcFormat
.top
&&
2497 pt
.x
< editor
->rcFormat
.left
)
2499 ITextHost_TxSetCursor(editor
->texthost
, hLeft
, FALSE
);
2502 if (pt
.y
< editor
->rcFormat
.top
|| pt
.y
> editor
->rcFormat
.bottom
)
2504 if (editor
->bEmulateVersion10
) /* v1.0 - 3.0 */
2505 ITextHost_TxSetCursor(editor
->texthost
,
2506 LoadCursorW(NULL
, (WCHAR
*)IDC_ARROW
), FALSE
);
2508 ITextHost_TxSetCursor(editor
->texthost
,
2509 LoadCursorW(NULL
, (WCHAR
*)IDC_IBEAM
), TRUE
);
2512 if (pt
.x
< editor
->rcFormat
.left
)
2514 ITextHost_TxSetCursor(editor
->texthost
, hLeft
, FALSE
);
2517 offset
= ME_CharFromPos(editor
, pt
.x
, pt
.y
, &isExact
);
2523 ME_CursorFromCharOfs(editor
, offset
, &cursor
);
2524 run
= &cursor
.pRun
->member
.run
;
2525 if (run
->style
->fmt
.dwMask
& CFM_LINK
&&
2526 run
->style
->fmt
.dwEffects
& CFE_LINK
)
2528 ITextHost_TxSetCursor(editor
->texthost
,
2529 LoadCursorW(NULL
, (WCHAR
*)IDC_HAND
),
2534 if (ME_IsSelection(editor
))
2536 int selStart
, selEnd
;
2537 ME_GetSelection(editor
, &selStart
, &selEnd
);
2538 if (selStart
<= offset
&& selEnd
>= offset
) {
2539 ITextHost_TxSetCursor(editor
->texthost
,
2540 LoadCursorW(NULL
, (WCHAR
*)IDC_ARROW
),
2546 ITextHost_TxSetCursor(editor
->texthost
,
2547 LoadCursorW(NULL
, (WCHAR
*)IDC_IBEAM
), TRUE
);
2551 static void ME_SetDefaultFormatRect(ME_TextEditor
*editor
)
2553 ITextHost_TxGetClientRect(editor
->texthost
, &editor
->rcFormat
);
2554 editor
->rcFormat
.top
+= editor
->exStyleFlags
& WS_EX_CLIENTEDGE
? 1 : 0;
2555 editor
->rcFormat
.left
+= 1 + editor
->selofs
;
2556 editor
->rcFormat
.right
-= 1;
2559 static BOOL
ME_ShowContextMenu(ME_TextEditor
*editor
, int x
, int y
)
2564 if(!editor
->lpOleCallback
|| !editor
->hWnd
)
2566 ME_GetSelection(editor
, &selrange
.cpMin
, &selrange
.cpMax
);
2567 if(selrange
.cpMin
== selrange
.cpMax
)
2568 seltype
|= SEL_EMPTY
;
2571 /* FIXME: Handle objects */
2572 seltype
|= SEL_TEXT
;
2573 if(selrange
.cpMax
-selrange
.cpMin
> 1)
2574 seltype
|= SEL_MULTICHAR
;
2576 if(SUCCEEDED(IRichEditOleCallback_GetContextMenu(editor
->lpOleCallback
, seltype
, NULL
, &selrange
, &menu
)))
2578 TrackPopupMenu(menu
, TPM_LEFTALIGN
| TPM_RIGHTBUTTON
, x
, y
, 0, GetParent(editor
->hWnd
), NULL
);
2584 ME_TextEditor
*ME_MakeEditor(ITextHost
*texthost
, BOOL bEmulateVersion10
)
2586 ME_TextEditor
*ed
= ALLOC_OBJ(ME_TextEditor
);
2592 ed
->texthost
= texthost
;
2593 ed
->bEmulateVersion10
= bEmulateVersion10
;
2594 ITextHost_TxGetPropertyBits(texthost
,
2595 (TXTBIT_RICHTEXT
|TXTBIT_MULTILINE
|
2596 TXTBIT_READONLY
|TXTBIT_USEPASSWORD
|
2597 TXTBIT_HIDESELECTION
|TXTBIT_SAVESELECTION
|
2598 TXTBIT_AUTOWORDSEL
|TXTBIT_VERTICAL
|
2599 TXTBIT_WORDWRAP
|TXTBIT_DISABLEDRAG
),
2601 ITextHost_TxGetScrollBars(texthost
, &ed
->styleFlags
);
2602 ed
->styleFlags
&= (WS_VSCROLL
|WS_HSCROLL
|ES_AUTOVSCROLL
|
2603 ES_AUTOHSCROLL
|ES_DISABLENOSCROLL
);
2604 ed
->pBuffer
= ME_MakeText();
2605 ed
->nZoomNumerator
= ed
->nZoomDenominator
= 0;
2606 ME_MakeFirstParagraph(ed
);
2607 /* The four cursors are for:
2608 * 0 - The position where the caret is shown
2609 * 1 - The anchored end of the selection (for normal selection)
2610 * 2 & 3 - The anchored start and end respectively for word, line,
2611 * or paragraph selection.
2614 ed
->pCursors
= ALLOC_N_OBJ(ME_Cursor
, ed
->nCursors
);
2615 ed
->pCursors
[0].pPara
= ed
->pBuffer
->pFirst
->member
.para
.next_para
;
2616 ed
->pCursors
[0].pRun
= ME_FindItemFwd(ed
->pCursors
[0].pPara
, diRun
);
2617 ed
->pCursors
[0].nOffset
= 0;
2618 ed
->pCursors
[1] = ed
->pCursors
[0];
2619 ed
->pCursors
[2] = ed
->pCursors
[0];
2620 ed
->pCursors
[3] = ed
->pCursors
[1];
2621 ed
->nLastTotalLength
= ed
->nTotalLength
= 0;
2622 ed
->nLastTotalWidth
= ed
->nTotalWidth
= 0;
2625 ed
->rgbBackColor
= -1;
2626 ed
->hbrBackground
= GetSysColorBrush(COLOR_WINDOW
);
2627 ed
->bCaretAtEnd
= FALSE
;
2629 ed
->nModifyStep
= 0;
2630 ed
->nTextLimit
= TEXT_LIMIT_DEFAULT
;
2631 ed
->pUndoStack
= ed
->pRedoStack
= ed
->pUndoStackBottom
= NULL
;
2632 ed
->nUndoStackSize
= 0;
2633 ed
->nUndoLimit
= STACK_SIZE_DEFAULT
;
2634 ed
->nUndoMode
= umAddToUndo
;
2635 ed
->nParagraphs
= 1;
2636 ed
->nLastSelStart
= ed
->nLastSelEnd
= 0;
2637 ed
->pLastSelStartPara
= ed
->pLastSelEndPara
= ME_FindItemFwd(ed
->pBuffer
->pFirst
, diParagraph
);
2638 ed
->nAvailWidth
= 0; /* wrap to client area */
2639 ed
->bHideSelection
= FALSE
;
2640 ed
->pfnWordBreak
= NULL
;
2641 ed
->lpOleCallback
= NULL
;
2642 ed
->mode
= TM_MULTILEVELUNDO
| TM_MULTICODEPAGE
;
2643 ed
->mode
|= (props
& TXTBIT_RICHTEXT
) ? TM_RICHTEXT
: TM_PLAINTEXT
;
2644 ed
->AutoURLDetect_bEnable
= FALSE
;
2645 ed
->bHaveFocus
= FALSE
;
2646 ed
->bMouseCaptured
= FALSE
;
2647 for (i
=0; i
<HFONT_CACHE_SIZE
; i
++)
2649 ed
->pFontCache
[i
].nRefs
= 0;
2650 ed
->pFontCache
[i
].nAge
= 0;
2651 ed
->pFontCache
[i
].hFont
= NULL
;
2654 ME_CheckCharOffsets(ed
);
2655 ed
->bDefaultFormatRect
= TRUE
;
2656 ITextHost_TxGetSelectionBarWidth(ed
->texthost
, &selbarwidth
);
2658 /* FIXME: Convert selbarwidth from HIMETRIC to pixels */
2659 ed
->selofs
= SELECTIONBAR_WIDTH
;
2660 ed
->styleFlags
|= ES_SELECTIONBAR
;
2664 ed
->nSelectionType
= stPosition
;
2666 ed
->cPasswordMask
= 0;
2667 if (props
& TXTBIT_USEPASSWORD
)
2668 ITextHost_TxGetPasswordChar(texthost
, &ed
->cPasswordMask
);
2670 if (props
& TXTBIT_AUTOWORDSEL
)
2671 ed
->styleFlags
|= ECO_AUTOWORDSELECTION
;
2672 if (props
& TXTBIT_MULTILINE
) {
2673 ed
->styleFlags
|= ES_MULTILINE
;
2674 ed
->bWordWrap
= (props
& TXTBIT_WORDWRAP
) != 0;
2676 ed
->bWordWrap
= FALSE
;
2678 if (props
& TXTBIT_READONLY
)
2679 ed
->styleFlags
|= ES_READONLY
;
2680 if (!(props
& TXTBIT_HIDESELECTION
))
2681 ed
->styleFlags
|= ES_NOHIDESEL
;
2682 if (props
& TXTBIT_SAVESELECTION
)
2683 ed
->styleFlags
|= ES_SAVESEL
;
2684 if (props
& TXTBIT_VERTICAL
)
2685 ed
->styleFlags
|= ES_VERTICAL
;
2686 if (props
& TXTBIT_DISABLEDRAG
)
2687 ed
->styleFlags
|= ES_NOOLEDRAGDROP
;
2689 ed
->notified_cr
.cpMin
= ed
->notified_cr
.cpMax
= 0;
2691 /* Default scrollbar information */
2692 ed
->vert_si
.cbSize
= sizeof(SCROLLINFO
);
2693 ed
->vert_si
.nMin
= 0;
2694 ed
->vert_si
.nMax
= 0;
2695 ed
->vert_si
.nPage
= 0;
2696 ed
->vert_si
.nPos
= 0;
2698 ed
->horz_si
.cbSize
= sizeof(SCROLLINFO
);
2699 ed
->horz_si
.nMin
= 0;
2700 ed
->horz_si
.nMax
= 0;
2701 ed
->horz_si
.nPage
= 0;
2702 ed
->horz_si
.nPos
= 0;
2704 OleInitialize(NULL
);
2709 static void ME_DestroyEditor(ME_TextEditor
*editor
)
2711 ME_DisplayItem
*pFirst
= editor
->pBuffer
->pFirst
;
2712 ME_DisplayItem
*p
= pFirst
, *pNext
= NULL
;
2715 ME_ClearTempStyle(editor
);
2716 ME_EmptyUndoStack(editor
);
2719 ME_DestroyDisplayItem(p
);
2722 ME_ReleaseStyle(editor
->pBuffer
->pDefaultStyle
);
2723 for (i
=0; i
<HFONT_CACHE_SIZE
; i
++)
2725 if (editor
->pFontCache
[i
].hFont
)
2726 DeleteObject(editor
->pFontCache
[i
].hFont
);
2728 if (editor
->rgbBackColor
!= -1)
2729 DeleteObject(editor
->hbrBackground
);
2730 if(editor
->lpOleCallback
)
2731 IUnknown_Release(editor
->lpOleCallback
);
2732 IUnknown_Release(editor
->texthost
);
2735 FREE_OBJ(editor
->pBuffer
);
2736 FREE_OBJ(editor
->pCursors
);
2741 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
2746 case DLL_PROCESS_ATTACH
:
2747 DisableThreadLibraryCalls(hinstDLL
);
2748 me_heap
= HeapCreate (0, 0x10000, 0);
2749 if (!ME_RegisterEditorClass(hinstDLL
)) return FALSE
;
2750 hLeft
= LoadCursorW(hinstDLL
, MAKEINTRESOURCEW(OCR_REVERSE
));
2754 case DLL_PROCESS_DETACH
:
2755 UnregisterClassW(RichEdit20W
, 0);
2756 UnregisterClassW(RichEdit50W
, 0);
2757 UnregisterClassA("RichEdit20A", 0);
2758 UnregisterClassA("RichEdit50A", 0);
2759 if (ME_ListBoxRegistered
)
2760 UnregisterClassW(REListBox20W
, 0);
2761 if (ME_ComboBoxRegistered
)
2762 UnregisterClassW(REComboBox20W
, 0);
2764 HeapDestroy (me_heap
);
2772 static const char * const edit_messages
[] = {
2801 "EM_SETPASSWORDCHAR",
2802 "EM_EMPTYUNDOBUFFER",
2803 "EM_GETFIRSTVISIBLELINE",
2805 "EM_SETWORDBREAKPROC",
2806 "EM_GETWORDBREAKPROC",
2807 "EM_GETPASSWORDCHAR",
2817 static const char * const richedit_messages
[] = {
2822 "EM_EXLINEFROMCHAR",
2828 "EM_GETOLEINTERFACE",
2838 "EM_SETOLECALLBACK",
2840 "EM_SETTARGETDEVICE",
2848 "EM_GETWORDBREAKPROCEX",
2849 "EM_SETWORDBREAKPROCEX",
2851 "EM_UNKNOWN_USER_83",
2856 "EM_STOPGROUPTYPING",
2860 "EM_GETAUTOURLDETECT",
2863 "EM_GETTEXTLENGTHEX",
2866 "EM_UNKNOWN_USER_98",
2867 "EM_UNKNOWN_USER_99",
2868 "EM_SETPUNCTUATION",
2869 "EM_GETPUNCTUATION",
2870 "EM_SETWORDWRAPMODE",
2871 "EM_GETWORDWRAPMODE",
2877 "EM_UNKNOWN_USER_109",
2878 "EM_UNKNOWN_USER_110",
2879 "EM_UNKNOWN_USER_111",
2880 "EM_UNKNOWN_USER_112",
2881 "EM_UNKNOWN_USER_113",
2882 "EM_UNKNOWN_USER_114",
2883 "EM_UNKNOWN_USER_115",
2884 "EM_UNKNOWN_USER_116",
2885 "EM_UNKNOWN_USER_117",
2886 "EM_UNKNOWN_USER_118",
2887 "EM_UNKNOWN_USER_119",
2888 "EM_SETLANGOPTIONS",
2889 "EM_GETLANGOPTIONS",
2890 "EM_GETIMECOMPMODE",
2894 "EM_SETIMEMODEBIAS",
2899 get_msg_name(UINT msg
)
2901 if (msg
>= EM_GETSEL
&& msg
<= EM_CHARFROMPOS
)
2902 return edit_messages
[msg
- EM_GETSEL
];
2903 if (msg
>= EM_CANPASTE
&& msg
<= EM_GETIMEMODEBIAS
)
2904 return richedit_messages
[msg
- EM_CANPASTE
];
2908 static void ME_LinkNotify(ME_TextEditor
*editor
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2911 ME_DisplayItem
*para
, *run
;
2913 int nCharOfs
; /* The start of the clicked text. Absolute character offset */
2916 x
= (short)LOWORD(lParam
);
2917 y
= (short)HIWORD(lParam
);
2918 nCharOfs
= ME_CharFromPos(editor
, x
, y
, &isExact
);
2919 if (!isExact
) return;
2921 ME_RunOfsFromCharOfs(editor
, nCharOfs
, ¶
, &run
, NULL
);
2923 if ((run
->member
.run
.style
->fmt
.dwMask
& CFM_LINK
)
2924 && (run
->member
.run
.style
->fmt
.dwEffects
& CFE_LINK
))
2925 { /* The clicked run has CFE_LINK set */
2926 info
.nmhdr
.hwndFrom
= editor
->hWnd
;
2927 info
.nmhdr
.idFrom
= GetWindowLongW(editor
->hWnd
, GWLP_ID
);
2928 info
.nmhdr
.code
= EN_LINK
;
2930 info
.wParam
= wParam
;
2931 info
.lParam
= lParam
;
2932 info
.chrg
.cpMin
= ME_CharOfsFromRunOfs(editor
, para
, run
, 0);
2933 info
.chrg
.cpMax
= info
.chrg
.cpMin
+ run
->member
.run
.strText
->nLen
;
2934 SendMessageW(GetParent(editor
->hWnd
), WM_NOTIFY
,info
.nmhdr
.idFrom
, (LPARAM
)&info
);
2938 #define UNSUPPORTED_MSG(e) \
2940 FIXME(#e ": stub\n"); \
2941 *phresult = S_FALSE; \
2944 /* Handle messages for windowless and windoweded richedit controls.
2946 * The LRESULT that is returned is a return value for window procs,
2947 * and the phresult parameter is the COM return code needed by the
2948 * text services interface. */
2949 LRESULT
ME_HandleMessage(ME_TextEditor
*editor
, UINT msg
, WPARAM wParam
,
2950 LPARAM lParam
, BOOL unicode
, HRESULT
* phresult
)
2956 UNSUPPORTED_MSG(EM_DISPLAYBAND
)
2957 UNSUPPORTED_MSG(EM_FINDWORDBREAK
)
2958 UNSUPPORTED_MSG(EM_FMTLINES
)
2959 UNSUPPORTED_MSG(EM_FORMATRANGE
)
2960 UNSUPPORTED_MSG(EM_GETBIDIOPTIONS
)
2961 UNSUPPORTED_MSG(EM_GETEDITSTYLE
)
2962 UNSUPPORTED_MSG(EM_GETIMECOMPMODE
)
2963 UNSUPPORTED_MSG(EM_GETIMESTATUS
)
2964 UNSUPPORTED_MSG(EM_SETIMESTATUS
)
2965 UNSUPPORTED_MSG(EM_GETLANGOPTIONS
)
2966 UNSUPPORTED_MSG(EM_GETREDONAME
)
2967 UNSUPPORTED_MSG(EM_GETTYPOGRAPHYOPTIONS
)
2968 UNSUPPORTED_MSG(EM_GETUNDONAME
)
2969 UNSUPPORTED_MSG(EM_GETWORDBREAKPROCEX
)
2970 UNSUPPORTED_MSG(EM_PASTESPECIAL
)
2971 UNSUPPORTED_MSG(EM_SELECTIONTYPE
)
2972 UNSUPPORTED_MSG(EM_SETBIDIOPTIONS
)
2973 UNSUPPORTED_MSG(EM_SETEDITSTYLE
)
2974 UNSUPPORTED_MSG(EM_SETFONTSIZE
)
2975 UNSUPPORTED_MSG(EM_SETLANGOPTIONS
)
2976 UNSUPPORTED_MSG(EM_SETMARGINS
)
2977 UNSUPPORTED_MSG(EM_SETPALETTE
)
2978 UNSUPPORTED_MSG(EM_SETTABSTOPS
)
2979 UNSUPPORTED_MSG(EM_SETTYPOGRAPHYOPTIONS
)
2980 UNSUPPORTED_MSG(EM_SETWORDBREAKPROCEX
)
2981 UNSUPPORTED_MSG(WM_STYLECHANGING
)
2982 UNSUPPORTED_MSG(WM_STYLECHANGED
)
2984 /* Messages specific to Richedit controls */
2987 return ME_StreamIn(editor
, wParam
, (EDITSTREAM
*)lParam
, TRUE
);
2989 return ME_StreamOut(editor
, wParam
, (EDITSTREAM
*)lParam
);
2992 UINT code
= DLGC_WANTCHARS
|DLGC_WANTTAB
|DLGC_WANTARROWS
|DLGC_HASSETSEL
;
2993 if (editor
->styleFlags
& ES_MULTILINE
)
2994 code
|= DLGC_WANTMESSAGE
;
2997 case EM_EMPTYUNDOBUFFER
:
2998 ME_EmptyUndoStack(editor
);
3002 /* Note: wParam/lParam can be NULL */
3004 PUINT pfrom
= wParam
? (PUINT
)wParam
: &from
;
3005 PUINT pto
= lParam
? (PUINT
)lParam
: &to
;
3006 ME_GetSelection(editor
, (int *)pfrom
, (int *)pto
);
3007 if ((*pfrom
|*pto
) & 0xFFFF0000)
3009 return MAKELONG(*pfrom
,*pto
);
3013 CHARRANGE
*pRange
= (CHARRANGE
*)lParam
;
3014 ME_GetSelection(editor
, &pRange
->cpMin
, &pRange
->cpMax
);
3015 TRACE("EM_EXGETSEL = (%d,%d)\n", pRange
->cpMin
, pRange
->cpMax
);
3018 case EM_SETUNDOLIMIT
:
3020 if ((int)wParam
< 0)
3021 editor
->nUndoLimit
= STACK_SIZE_DEFAULT
;
3023 editor
->nUndoLimit
= min(wParam
, STACK_SIZE_MAX
);
3024 /* Setting a max stack size keeps wine from getting killed
3025 for hogging memory. Windows allocates all this memory at once, so
3026 no program would realistically set a value above our maximum. */
3027 return editor
->nUndoLimit
;
3030 return editor
->pUndoStack
!= NULL
;
3032 return editor
->pRedoStack
!= NULL
;
3033 case WM_UNDO
: /* FIXME: actually not the same */
3035 return ME_Undo(editor
);
3037 return ME_Redo(editor
);
3040 /* these flags are equivalent to the ES_* counterparts */
3041 DWORD mask
= ECO_VERTICAL
| ECO_AUTOHSCROLL
| ECO_AUTOVSCROLL
|
3042 ECO_NOHIDESEL
| ECO_READONLY
| ECO_WANTRETURN
| ECO_SELECTIONBAR
;
3043 DWORD settings
= editor
->styleFlags
& mask
;
3049 /* these flags are equivalent to ES_* counterparts, except for
3050 * ECO_AUTOWORDSELECTION that doesn't have an ES_* counterpart,
3051 * but is still stored in editor->styleFlags. */
3052 const DWORD mask
= ECO_VERTICAL
| ECO_AUTOHSCROLL
| ECO_AUTOVSCROLL
|
3053 ECO_NOHIDESEL
| ECO_READONLY
| ECO_WANTRETURN
|
3054 ECO_SELECTIONBAR
| ECO_AUTOWORDSELECTION
;
3055 DWORD settings
= mask
& editor
->styleFlags
;
3056 DWORD oldSettings
= settings
;
3057 DWORD changedSettings
;
3073 changedSettings
= oldSettings
^ settings
;
3075 if (changedSettings
) {
3076 editor
->styleFlags
= (editor
->styleFlags
& ~mask
) | (settings
& mask
);
3078 if (changedSettings
& ECO_SELECTIONBAR
)
3080 ITextHost_TxInvalidateRect(editor
->texthost
, &editor
->rcFormat
, TRUE
);
3081 if (settings
& ECO_SELECTIONBAR
) {
3082 assert(!editor
->selofs
);
3083 editor
->selofs
= SELECTIONBAR_WIDTH
;
3084 editor
->rcFormat
.left
+= editor
->selofs
;
3086 editor
->rcFormat
.left
-= editor
->selofs
;
3089 ME_RewrapRepaint(editor
);
3092 if (changedSettings
& settings
& ECO_VERTICAL
)
3093 FIXME("ECO_VERTICAL not implemented yet!\n");
3094 if (changedSettings
& settings
& ECO_AUTOHSCROLL
)
3095 FIXME("ECO_AUTOHSCROLL not implemented yet!\n");
3096 if (changedSettings
& settings
& ECO_AUTOVSCROLL
)
3097 FIXME("ECO_AUTOVSCROLL not implemented yet!\n");
3098 if (changedSettings
& settings
& ECO_NOHIDESEL
)
3099 FIXME("ECO_NOHIDESEL not implemented yet!\n");
3100 if (changedSettings
& settings
& ECO_WANTRETURN
)
3101 FIXME("ECO_WANTRETURN not implemented yet!\n");
3102 if (changedSettings
& settings
& ECO_AUTOWORDSELECTION
)
3103 FIXME("ECO_AUTOWORDSELECTION not implemented yet!\n");
3110 ME_InvalidateSelection(editor
);
3111 ME_SetSelection(editor
, wParam
, lParam
);
3112 ME_InvalidateSelection(editor
);
3113 ITextHost_TxShowCaret(editor
->texthost
, FALSE
);
3114 ME_ShowCaret(editor
);
3115 ME_SendSelChange(editor
);
3118 case EM_SETSCROLLPOS
:
3120 POINT
*point
= (POINT
*)lParam
;
3121 ME_ScrollAbs(editor
, point
->x
, point
->y
);
3124 case EM_AUTOURLDETECT
:
3126 if (wParam
==1 || wParam
==0)
3128 editor
->AutoURLDetect_bEnable
= (BOOL
)wParam
;
3131 return E_INVALIDARG
;
3133 case EM_GETAUTOURLDETECT
:
3135 return editor
->AutoURLDetect_bEnable
;
3140 CHARRANGE range
= *(CHARRANGE
*)lParam
;
3142 TRACE("EM_EXSETSEL (%d,%d)\n", range
.cpMin
, range
.cpMax
);
3144 ME_InvalidateSelection(editor
);
3145 end
= ME_SetSelection(editor
, range
.cpMin
, range
.cpMax
);
3146 ME_InvalidateSelection(editor
);
3147 ITextHost_TxShowCaret(editor
->texthost
, FALSE
);
3148 ME_ShowCaret(editor
);
3149 ME_SendSelChange(editor
);
3153 case EM_SHOWSCROLLBAR
:
3166 flags
= WS_HSCROLL
|WS_VSCROLL
;
3173 editor
->styleFlags
|= flags
;
3174 if (flags
& WS_HSCROLL
)
3175 ITextHost_TxShowScrollBar(editor
->texthost
, SB_HORZ
,
3176 editor
->nTotalWidth
> editor
->sizeWindow
.cx
);
3177 if (flags
& WS_VSCROLL
)
3178 ITextHost_TxShowScrollBar(editor
->texthost
, SB_VERT
,
3179 editor
->nTotalLength
> editor
->sizeWindow
.cy
);
3181 editor
->styleFlags
&= ~flags
;
3182 ITextHost_TxShowScrollBar(editor
->texthost
, wParam
, FALSE
);
3189 SETTEXTEX
*pStruct
= (SETTEXTEX
*)wParam
;
3193 BOOL bRtf
, bUnicode
, bSelection
;
3194 int oldModify
= editor
->nModifyStep
;
3196 if (!pStruct
) return 0;
3198 /* If we detect ascii rtf at the start of the string,
3199 * we know it isn't unicode. */
3200 bRtf
= (lParam
&& (!strncmp((char *)lParam
, "{\\rtf", 5) ||
3201 !strncmp((char *)lParam
, "{\\urtf", 6)));
3202 bUnicode
= !bRtf
&& pStruct
->codepage
== 1200;
3204 TRACE("EM_SETTEXTEX - %s, flags %d, cp %d\n",
3205 bUnicode
? debugstr_w((LPCWSTR
)lParam
) : debugstr_a((LPCSTR
)lParam
),
3206 pStruct
->flags
, pStruct
->codepage
);
3208 bSelection
= (pStruct
->flags
& ST_SELECTION
) != 0;
3210 ME_GetSelection(editor
, &from
, &to
);
3211 style
= ME_GetSelectionInsertStyle(editor
);
3212 ME_InternalDeleteText(editor
, from
, to
- from
, FALSE
);
3214 ME_InternalDeleteText(editor
, 0, ME_GetTextLength(editor
), FALSE
);
3215 style
= editor
->pBuffer
->pDefaultStyle
;
3219 ME_StreamInRTFString(editor
, bSelection
, (char *)lParam
);
3221 /* FIXME: The length returned is doesn't include the rtf control
3222 * characters, only the actual text. */
3223 len
= lParam
? strlen((char *)lParam
) : 0;
3226 /* FIXME: make use of pStruct->codepage in the to unicode translation */
3227 wszText
= lParam
? ME_ToUnicode(bUnicode
, (void *)lParam
) : NULL
;
3228 len
= wszText
? lstrlenW(wszText
) : 0;
3229 ME_InsertTextFromCursor(editor
, 0, wszText
, len
, style
);
3233 ME_ReleaseStyle(style
);
3234 ME_UpdateSelectionLinkAttribute(editor
);
3237 ME_UpdateLinkAttribute(editor
, 0, -1);
3239 ME_CommitUndo(editor
);
3240 if (!(pStruct
->flags
& ST_KEEPUNDO
))
3242 editor
->nModifyStep
= oldModify
;
3243 ME_EmptyUndoStack(editor
);
3245 ME_UpdateRepaint(editor
);
3248 case EM_SETBKGNDCOLOR
:
3251 if (editor
->rgbBackColor
!= -1) {
3252 DeleteObject(editor
->hbrBackground
);
3253 lColor
= editor
->rgbBackColor
;
3255 else lColor
= ITextHost_TxGetSysColor(editor
->texthost
, COLOR_WINDOW
);
3259 editor
->rgbBackColor
= -1;
3260 editor
->hbrBackground
= GetSysColorBrush(COLOR_WINDOW
);
3264 editor
->rgbBackColor
= lParam
;
3265 editor
->hbrBackground
= CreateSolidBrush(editor
->rgbBackColor
);
3267 ITextHost_TxInvalidateRect(editor
->texthost
, NULL
, TRUE
);
3268 ITextHost_TxViewChange(editor
->texthost
, TRUE
);
3272 return editor
->nModifyStep
== 0 ? 0 : -1;
3276 editor
->nModifyStep
= 1;
3278 editor
->nModifyStep
= 0;
3282 case EM_SETREADONLY
:
3285 editor
->styleFlags
|= ES_READONLY
;
3287 editor
->styleFlags
&= ~ES_READONLY
;
3290 case EM_SETEVENTMASK
:
3292 DWORD nOldMask
= editor
->nEventMask
;
3294 editor
->nEventMask
= lParam
;
3297 case EM_GETEVENTMASK
:
3298 return editor
->nEventMask
;
3299 case EM_SETCHARFORMAT
:
3301 CHARFORMAT2W buf
, *p
;
3302 BOOL bRepaint
= TRUE
;
3303 p
= ME_ToCF2W(&buf
, (CHARFORMAT2W
*)lParam
);
3304 if (p
== NULL
) return 0;
3306 ME_SetDefaultCharFormat(editor
, p
);
3307 else if (wParam
== (SCF_WORD
| SCF_SELECTION
)) {
3308 FIXME("EM_SETCHARFORMAT: word selection not supported\n");
3310 } else if (wParam
== SCF_ALL
) {
3311 if (editor
->mode
& TM_PLAINTEXT
)
3312 ME_SetDefaultCharFormat(editor
, p
);
3314 ME_SetCharFormat(editor
, 0, ME_GetTextLength(editor
), p
);
3315 editor
->nModifyStep
= 1;
3317 } else if (editor
->mode
& TM_PLAINTEXT
) {
3321 ME_GetSelection(editor
, &from
, &to
);
3322 bRepaint
= (from
!= to
);
3323 ME_SetSelectionCharFormat(editor
, p
);
3324 if (from
!= to
) editor
->nModifyStep
= 1;
3326 ME_CommitUndo(editor
);
3329 ME_WrapMarkedParagraphs(editor
);
3330 ME_UpdateScrollBar(editor
);
3335 case EM_GETCHARFORMAT
:
3337 CHARFORMAT2W tmp
, *dst
= (CHARFORMAT2W
*)lParam
;
3338 if (dst
->cbSize
!= sizeof(CHARFORMATA
) &&
3339 dst
->cbSize
!= sizeof(CHARFORMATW
) &&
3340 dst
->cbSize
!= sizeof(CHARFORMAT2A
) &&
3341 dst
->cbSize
!= sizeof(CHARFORMAT2W
))
3343 tmp
.cbSize
= sizeof(tmp
);
3345 ME_GetDefaultCharFormat(editor
, &tmp
);
3347 ME_GetSelectionCharFormat(editor
, &tmp
);
3348 ME_CopyToCFAny(dst
, &tmp
);
3351 case EM_SETPARAFORMAT
:
3353 BOOL result
= ME_SetSelectionParaFormat(editor
, (PARAFORMAT2
*)lParam
);
3354 ME_WrapMarkedParagraphs(editor
);
3355 ME_UpdateScrollBar(editor
);
3357 ME_CommitUndo(editor
);
3360 case EM_GETPARAFORMAT
:
3361 ME_GetSelectionParaFormat(editor
, (PARAFORMAT2
*)lParam
);
3362 return ((PARAFORMAT2
*)lParam
)->dwMask
;
3363 case EM_GETFIRSTVISIBLELINE
:
3365 ME_DisplayItem
*p
= editor
->pBuffer
->pFirst
;
3366 int y
= editor
->vert_si
.nPos
;
3371 p
= ME_FindItemFwd(p
, diStartRowOrParagraphOrEnd
);
3372 if (p
->type
== diTextEnd
)
3374 if (p
->type
== diParagraph
) {
3375 ypara
= p
->member
.para
.pt
.y
;
3378 ystart
= ypara
+ p
->member
.row
.pt
.y
;
3379 yend
= ystart
+ p
->member
.row
.nHeight
;
3387 case EM_HIDESELECTION
:
3389 editor
->bHideSelection
= (wParam
!= 0);
3390 ME_InvalidateSelection(editor
);
3395 if (!(editor
->styleFlags
& ES_MULTILINE
))
3397 ME_ScrollDown(editor
, lParam
* 8); /* FIXME follow the original */
3403 ME_GetSelection(editor
, &from
, &to
);
3404 ME_InternalDeleteText(editor
, from
, to
-from
, FALSE
);
3405 ME_CommitUndo(editor
);
3406 ME_UpdateRepaint(editor
);
3413 LPWSTR wszText
= lParam
? ME_ToUnicode(unicode
, (void *)lParam
) : NULL
;
3414 size_t len
= wszText
? lstrlenW(wszText
) : 0;
3415 TRACE("EM_REPLACESEL - %s\n", debugstr_w(wszText
));
3417 ME_GetSelection(editor
, &from
, &to
);
3418 style
= ME_GetSelectionInsertStyle(editor
);
3419 ME_InternalDeleteText(editor
, from
, to
-from
, FALSE
);
3420 ME_InsertTextFromCursor(editor
, 0, wszText
, len
, style
);
3421 ME_ReleaseStyle(style
);
3422 /* drop temporary style if line end */
3424 * FIXME question: does abc\n mean: put abc,
3425 * clear temp style, put \n? (would require a change)
3427 if (len
>0 && wszText
[len
-1] == '\n')
3428 ME_ClearTempStyle(editor
);
3429 ME_EndToUnicode(unicode
, wszText
);
3430 ME_CommitUndo(editor
);
3431 ME_UpdateSelectionLinkAttribute(editor
);
3433 ME_EmptyUndoStack(editor
);
3434 ME_UpdateRepaint(editor
);
3437 case EM_SCROLLCARET
:
3438 ME_EnsureVisible(editor
, &editor
->pCursors
[0]);
3445 BOOL bRepaint
= LOWORD(lParam
);
3448 wParam
= (WPARAM
)GetStockObject(SYSTEM_FONT
);
3449 GetObjectW((HGDIOBJ
)wParam
, sizeof(LOGFONTW
), &lf
);
3450 hDC
= ITextHost_TxGetDC(editor
->texthost
);
3451 ME_CharFormatFromLogFont(hDC
, &lf
, &fmt
);
3452 ITextHost_TxReleaseDC(editor
->texthost
, hDC
);
3453 ME_SetCharFormat(editor
, 0, ME_GetTextLength(editor
), &fmt
);
3454 ME_SetDefaultCharFormat(editor
, &fmt
);
3456 ME_CommitUndo(editor
);
3457 ME_MarkAllForWrapping(editor
);
3458 ME_WrapMarkedParagraphs(editor
);
3459 ME_UpdateScrollBar(editor
);
3466 ME_InternalDeleteText(editor
, 0, ME_GetTextLength(editor
), FALSE
);
3469 TRACE("WM_SETTEXT lParam==%lx\n",lParam
);
3470 if (!strncmp((char *)lParam
, "{\\rtf", 5) ||
3471 !strncmp((char *)lParam
, "{\\urtf", 6))
3473 /* Undocumented: WM_SETTEXT supports RTF text */
3474 ME_StreamInRTFString(editor
, 0, (char *)lParam
);
3478 LPWSTR wszText
= ME_ToUnicode(unicode
, (void *)lParam
);
3479 TRACE("WM_SETTEXT - %s\n", debugstr_w(wszText
)); /* debugstr_w() */
3480 if (lstrlenW(wszText
) > 0)
3484 /* uses default style! */
3485 if (!(editor
->styleFlags
& ES_MULTILINE
))
3490 while (*p
!= '\0' && *p
!= '\r' && *p
!= '\n') p
++;
3493 ME_InsertTextFromCursor(editor
, 0, wszText
, len
, editor
->pBuffer
->pDefaultStyle
);
3495 ME_EndToUnicode(unicode
, wszText
);
3499 TRACE("WM_SETTEXT - NULL\n");
3500 ME_UpdateLinkAttribute(editor
, 0, -1);
3501 ME_SetSelection(editor
, 0, 0);
3502 editor
->nModifyStep
= 0;
3503 ME_CommitUndo(editor
);
3504 ME_EmptyUndoStack(editor
);
3505 ME_UpdateRepaint(editor
);
3510 UINT nRTFFormat
= RegisterClipboardFormatA("Rich Text Format");
3511 if (IsClipboardFormatAvailable(nRTFFormat
))
3513 if (IsClipboardFormatAvailable(CF_UNICODETEXT
))
3524 ME_GetSelection(editor
, &range
.cpMin
, &range
.cpMax
);
3526 if (ME_Copy(editor
, &range
) && msg
== WM_CUT
)
3528 ME_InternalDeleteText(editor
, range
.cpMin
, range
.cpMax
-range
.cpMin
, FALSE
);
3529 ME_CommitUndo(editor
);
3530 ME_UpdateRepaint(editor
);
3534 case WM_GETTEXTLENGTH
:
3536 GETTEXTLENGTHEX how
;
3538 /* CR/LF conversion required in 2.0 mode, verbatim in 1.0 mode */
3539 how
.flags
= GTL_CLOSE
| (editor
->bEmulateVersion10
? 0 : GTL_USECRLF
) | GTL_NUMCHARS
;
3540 how
.codepage
= unicode
? 1200 : CP_ACP
;
3541 return ME_GetTextLengthEx(editor
, &how
);
3543 case EM_GETTEXTLENGTHEX
:
3544 return ME_GetTextLengthEx(editor
, (GETTEXTLENGTHEX
*)wParam
);
3549 LPSTR bufferA
= NULL
;
3550 LPWSTR bufferW
= NULL
;
3553 bufferW
= heap_alloc((wParam
+ 2) * sizeof(WCHAR
));
3555 bufferA
= heap_alloc(wParam
+ 2);
3557 ex
.cb
= (wParam
+ 2) * (unicode
? sizeof(WCHAR
) : sizeof(CHAR
));
3558 ex
.flags
= GT_USECRLF
;
3559 ex
.codepage
= unicode
? 1200 : CP_ACP
;
3560 ex
.lpDefaultChar
= NULL
;
3561 ex
.lpUsedDefChar
= NULL
;
3563 rc
= ME_GetTextEx(editor
, &ex
, unicode
? (LPARAM
)bufferW
: (LPARAM
)bufferA
);
3567 memcpy((LPWSTR
)lParam
, bufferW
, wParam
* sizeof(WCHAR
));
3568 if (strlenW(bufferW
) >= wParam
) rc
= 0;
3572 memcpy((LPSTR
)lParam
, bufferA
, wParam
);
3573 if (strlen(bufferA
) >= wParam
) rc
= 0;
3580 return ME_GetTextEx(editor
, (GETTEXTEX
*)wParam
, lParam
);
3584 ME_GetSelection(editor
, &from
, &to
);
3585 return ME_GetTextRange(editor
, (WCHAR
*)lParam
, from
,
3586 to
- from
, unicode
);
3588 case EM_GETSCROLLPOS
:
3590 POINT
*point
= (POINT
*)lParam
;
3591 point
->x
= editor
->horz_si
.nPos
;
3592 point
->y
= editor
->vert_si
.nPos
;
3595 case EM_GETTEXTRANGE
:
3597 TEXTRANGEW
*rng
= (TEXTRANGEW
*)lParam
;
3598 int start
= rng
->chrg
.cpMin
;
3599 int end
= rng
->chrg
.cpMax
;
3600 int textlength
= ME_GetTextLength(editor
);
3601 TRACE("EM_GETTEXTRANGE min=%d max=%d unicode=%d emul1.0=%d length=%d\n",
3602 rng
->chrg
.cpMin
, rng
->chrg
.cpMax
, unicode
,
3603 editor
->bEmulateVersion10
, ME_GetTextLength(editor
));
3604 if (start
< 0) return 0;
3605 if ((start
== 0 && end
== -1) || end
> textlength
)
3607 if (start
>= end
) return 0;
3608 return ME_GetTextRange(editor
, rng
->lpstrText
, start
, end
- start
, unicode
);
3612 ME_DisplayItem
*run
;
3613 const unsigned int nMaxChars
= *(WORD
*) lParam
;
3614 unsigned int nCharsLeft
= nMaxChars
;
3615 char *dest
= (char *) lParam
;
3616 BOOL wroteNull
= FALSE
;
3618 TRACE("EM_GETLINE: row=%d, nMaxChars=%d (%s)\n", (int) wParam
, nMaxChars
,
3619 unicode
? "Unicode" : "Ansi");
3621 run
= ME_FindRowWithNumber(editor
, wParam
);
3625 while (nCharsLeft
&& (run
= ME_FindItemFwd(run
, diRunOrStartRow
))
3626 && run
->type
== diRun
)
3631 strText
= run
->member
.run
.strText
;
3632 nCopy
= min(nCharsLeft
, strText
->nLen
);
3635 memcpy(dest
, strText
->szData
, nCopy
* sizeof(WCHAR
));
3637 nCopy
= WideCharToMultiByte(CP_ACP
, 0, strText
->szData
, nCopy
, dest
,
3638 nCharsLeft
, NULL
, NULL
);
3639 dest
+= nCopy
* (unicode
? sizeof(WCHAR
) : 1);
3640 nCharsLeft
-= nCopy
;
3643 /* append line termination, space allowing */
3647 *((WCHAR
*)dest
) = '\0';
3654 TRACE("EM_GETLINE: got %u characters\n", nMaxChars
- nCharsLeft
);
3655 return nMaxChars
- nCharsLeft
- (wroteNull
? 1 : 0);
3657 case EM_GETLINECOUNT
:
3659 ME_DisplayItem
*item
= editor
->pBuffer
->pFirst
->next
;
3662 ME_DisplayItem
*prev_para
= NULL
, *last_para
= NULL
;
3664 while (item
!= editor
->pBuffer
->pLast
)
3666 assert(item
->type
== diParagraph
);
3667 prev_para
= ME_FindItemBack(item
, diRun
);
3669 assert(prev_para
->member
.run
.nFlags
& MERF_ENDPARA
);
3671 nRows
+= item
->member
.para
.nRows
;
3672 item
= item
->member
.para
.next_para
;
3674 last_para
= ME_FindItemBack(item
, diRun
);
3676 assert(last_para
->member
.run
.nFlags
& MERF_ENDPARA
);
3677 if (editor
->bEmulateVersion10
&& prev_para
&&
3678 last_para
->member
.run
.nCharOfs
== 0 &&
3679 prev_para
->member
.run
.strText
->nLen
== 1 &&
3680 prev_para
->member
.run
.strText
->szData
[0] == '\r')
3682 /* In 1.0 emulation, the last solitary \r at the very end of the text
3683 (if one exists) is NOT a line break.
3684 FIXME: this is an ugly hack. This should have a more regular model. */
3688 TRACE("EM_GETLINECOUNT: nRows==%d\n", nRows
);
3689 return max(1, nRows
);
3691 case EM_LINEFROMCHAR
:
3694 return ME_RowNumberFromCharOfs(editor
, ME_GetCursorOfs(editor
, 1));
3696 return ME_RowNumberFromCharOfs(editor
, wParam
);
3698 case EM_EXLINEFROMCHAR
:
3701 return ME_RowNumberFromCharOfs(editor
, ME_GetCursorOfs(editor
,1));
3703 return ME_RowNumberFromCharOfs(editor
, lParam
);
3707 ME_DisplayItem
*item
, *para
;
3711 item
= ME_FindItemBack(editor
->pCursors
[0].pRun
, diStartRow
);
3713 item
= ME_FindRowWithNumber(editor
, wParam
);
3716 para
= ME_GetParagraph(item
);
3717 item
= ME_FindItemFwd(item
, diRun
);
3718 nCharOfs
= para
->member
.para
.nCharOfs
+ item
->member
.run
.nCharOfs
;
3719 TRACE("EM_LINEINDEX: nCharOfs==%d\n", nCharOfs
);
3724 ME_DisplayItem
*item
, *item_end
;
3725 int nChars
= 0, nThisLineOfs
= 0, nNextLineOfs
= 0;
3726 ME_DisplayItem
*para
, *run
;
3728 if (wParam
> ME_GetTextLength(editor
))
3732 FIXME("EM_LINELENGTH: returning number of unselected characters on lines with selection unsupported.\n");
3735 ME_RunOfsFromCharOfs(editor
, wParam
, ¶
, &run
, NULL
);
3736 item
= ME_RowStart(run
);
3737 nThisLineOfs
= ME_CharOfsFromRunOfs(editor
, para
, ME_FindItemFwd(item
, diRun
), 0);
3738 item_end
= ME_FindItemFwd(item
, diStartRowOrParagraphOrEnd
);
3739 if (item_end
->type
== diStartRow
) {
3740 nNextLineOfs
= ME_CharOfsFromRunOfs(editor
, para
, ME_FindItemFwd(item_end
, diRun
), 0);
3742 ME_DisplayItem
*endRun
= ME_FindItemBack(item_end
, diRun
);
3743 assert(endRun
&& endRun
->member
.run
.nFlags
& MERF_ENDPARA
);
3744 nNextLineOfs
= item_end
->member
.para
.nCharOfs
- endRun
->member
.run
.strText
->nLen
;
3746 nChars
= nNextLineOfs
- nThisLineOfs
;
3747 TRACE("EM_LINELENGTH(%ld)==%d\n",wParam
, nChars
);
3750 case EM_EXLIMITTEXT
:
3752 if ((int)lParam
< 0)
3755 editor
->nTextLimit
= 65536;
3757 editor
->nTextLimit
= (int) lParam
;
3763 editor
->nTextLimit
= 65536;
3765 editor
->nTextLimit
= (int) wParam
;
3768 case EM_GETLIMITTEXT
:
3770 return editor
->nTextLimit
;
3774 FINDTEXTA
*ft
= (FINDTEXTA
*)lParam
;
3775 int nChars
= MultiByteToWideChar(CP_ACP
, 0, ft
->lpstrText
, -1, NULL
, 0);
3779 if ((tmp
= ALLOC_N_OBJ(WCHAR
, nChars
)) != NULL
)
3780 MultiByteToWideChar(CP_ACP
, 0, ft
->lpstrText
, -1, tmp
, nChars
);
3781 r
= ME_FindText(editor
, wParam
, &ft
->chrg
, tmp
, NULL
);
3787 FINDTEXTEXA
*ex
= (FINDTEXTEXA
*)lParam
;
3788 int nChars
= MultiByteToWideChar(CP_ACP
, 0, ex
->lpstrText
, -1, NULL
, 0);
3792 if ((tmp
= ALLOC_N_OBJ(WCHAR
, nChars
)) != NULL
)
3793 MultiByteToWideChar(CP_ACP
, 0, ex
->lpstrText
, -1, tmp
, nChars
);
3794 r
= ME_FindText(editor
, wParam
, &ex
->chrg
, tmp
, &ex
->chrgText
);
3800 FINDTEXTW
*ft
= (FINDTEXTW
*)lParam
;
3801 return ME_FindText(editor
, wParam
, &ft
->chrg
, ft
->lpstrText
, NULL
);
3803 case EM_FINDTEXTEXW
:
3805 FINDTEXTEXW
*ex
= (FINDTEXTEXW
*)lParam
;
3806 return ME_FindText(editor
, wParam
, &ex
->chrg
, ex
->lpstrText
, &ex
->chrgText
);
3809 if (!wParam
|| !lParam
)
3811 *(int *)wParam
= editor
->nZoomNumerator
;
3812 *(int *)lParam
= editor
->nZoomDenominator
;
3815 return ME_SetZoom(editor
, wParam
, lParam
);
3816 case EM_CHARFROMPOS
:
3817 return ME_CharFromPos(editor
, ((POINTL
*)lParam
)->x
, ((POINTL
*)lParam
)->y
, NULL
);
3818 case EM_POSFROMCHAR
:
3820 ME_DisplayItem
*pPara
, *pRun
;
3821 int nCharOfs
, nOffset
, nLength
;
3825 /* detect which API version we're dealing with */
3826 if (wParam
>= 0x40000)
3828 nLength
= ME_GetTextLength(editor
);
3829 nCharOfs
= min(nCharOfs
, nLength
);
3830 nCharOfs
= max(nCharOfs
, 0);
3832 ME_RunOfsFromCharOfs(editor
, nCharOfs
, &pPara
, &pRun
, &nOffset
);
3833 assert(pRun
->type
== diRun
);
3834 pt
.y
= pRun
->member
.run
.pt
.y
;
3835 pt
.x
= pRun
->member
.run
.pt
.x
+ ME_PointFromChar(editor
, &pRun
->member
.run
, nOffset
);
3836 pt
.y
+= pPara
->member
.para
.pt
.y
+ editor
->rcFormat
.top
;
3837 pt
.x
+= editor
->rcFormat
.left
;
3839 pt
.x
-= editor
->horz_si
.nPos
;
3840 pt
.y
-= editor
->vert_si
.nPos
;
3842 if (wParam
>= 0x40000) {
3843 *(POINTL
*)wParam
= pt
;
3845 return (wParam
>= 0x40000) ? 0 : MAKELONG( pt
.x
, pt
.y
);
3851 ME_SetDefaultFormatRect(editor
);
3853 max
= (editor
->styleFlags
& ES_DISABLENOSCROLL
) ? 1 : 0;
3854 if (~editor
->styleFlags
& ES_DISABLENOSCROLL
|| editor
->styleFlags
& WS_VSCROLL
)
3855 ITextHost_TxSetScrollRange(editor
->texthost
, SB_VERT
, 0, max
, TRUE
);
3857 if (~editor
->styleFlags
& ES_DISABLENOSCROLL
|| editor
->styleFlags
& WS_HSCROLL
)
3858 ITextHost_TxSetScrollRange(editor
->texthost
, SB_HORZ
, 0, max
, TRUE
);
3860 if (editor
->styleFlags
& ES_DISABLENOSCROLL
)
3862 if (editor
->styleFlags
& WS_VSCROLL
)
3864 ITextHost_TxEnableScrollBar(editor
->texthost
, SB_VERT
, ESB_DISABLE_BOTH
);
3865 ITextHost_TxShowScrollBar(editor
->texthost
, SB_VERT
, TRUE
);
3867 if (editor
->styleFlags
& WS_HSCROLL
)
3869 ITextHost_TxEnableScrollBar(editor
->texthost
, SB_HORZ
, ESB_DISABLE_BOTH
);
3870 ITextHost_TxShowScrollBar(editor
->texthost
, SB_HORZ
, TRUE
);
3874 ME_CommitUndo(editor
);
3875 ME_WrapMarkedParagraphs(editor
);
3876 ME_MoveCaret(editor
);
3880 ME_DestroyEditor(editor
);
3884 return ME_SetCursor(editor
);
3886 case WM_LBUTTONDBLCLK
:
3887 case WM_LBUTTONDOWN
:
3889 ME_CommitUndo(editor
); /* End coalesced undos for typed characters */
3890 if ((editor
->nEventMask
& ENM_MOUSEEVENTS
) &&
3891 !ME_FilterEvent(editor
, msg
, &wParam
, &lParam
))
3893 ITextHost_TxSetFocus(editor
->texthost
);
3894 ME_LButtonDown(editor
, (short)LOWORD(lParam
), (short)HIWORD(lParam
),
3895 ME_CalculateClickCount(editor
, msg
, wParam
, lParam
));
3896 ITextHost_TxSetCapture(editor
->texthost
, TRUE
);
3897 editor
->bMouseCaptured
= TRUE
;
3898 ME_LinkNotify(editor
,msg
,wParam
,lParam
);
3899 if (!ME_SetCursor(editor
)) goto do_default
;
3903 if ((editor
->nEventMask
& ENM_MOUSEEVENTS
) &&
3904 !ME_FilterEvent(editor
, msg
, &wParam
, &lParam
))
3906 if (editor
->bMouseCaptured
)
3907 ME_MouseMove(editor
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
3908 ME_LinkNotify(editor
,msg
,wParam
,lParam
);
3909 /* Set cursor if mouse is captured, since WM_SETCURSOR won't be received. */
3910 if (editor
->bMouseCaptured
)
3911 ME_SetCursor(editor
);
3914 if (editor
->bMouseCaptured
) {
3915 ITextHost_TxSetCapture(editor
->texthost
, FALSE
);
3916 editor
->bMouseCaptured
= FALSE
;
3918 if (editor
->nSelectionType
== stDocument
)
3919 editor
->nSelectionType
= stPosition
;
3920 if ((editor
->nEventMask
& ENM_MOUSEEVENTS
) &&
3921 !ME_FilterEvent(editor
, msg
, &wParam
, &lParam
))
3925 ME_SetCursor(editor
);
3926 ME_LinkNotify(editor
,msg
,wParam
,lParam
);
3930 case WM_RBUTTONDOWN
:
3931 ME_CommitUndo(editor
); /* End coalesced undos for typed characters */
3932 if ((editor
->nEventMask
& ENM_MOUSEEVENTS
) &&
3933 !ME_FilterEvent(editor
, msg
, &wParam
, &lParam
))
3936 case WM_CONTEXTMENU
:
3937 if (!ME_ShowContextMenu(editor
, (short)LOWORD(lParam
), (short)HIWORD(lParam
)))
3941 editor
->bHaveFocus
= TRUE
;
3942 ME_ShowCaret(editor
);
3943 ME_SendOldNotify(editor
, EN_SETFOCUS
);
3946 ME_CommitUndo(editor
); /* End coalesced undos for typed characters */
3947 editor
->bHaveFocus
= FALSE
;
3948 ME_HideCaret(editor
);
3949 ME_SendOldNotify(editor
, EN_KILLFOCUS
);
3952 TRACE("editor wnd command = %d\n", LOWORD(wParam
));
3955 if ((editor
->nEventMask
& ENM_KEYEVENTS
) &&
3956 !ME_FilterEvent(editor
, msg
, &wParam
, &lParam
))
3960 if ((editor
->nEventMask
& ENM_KEYEVENTS
) &&
3961 !ME_FilterEvent(editor
, msg
, &wParam
, &lParam
))
3963 if (ME_KeyDown(editor
, LOWORD(wParam
)))
3967 return ME_Char(editor
, wParam
, lParam
, unicode
);
3971 if(wParam
== UNICODE_NOCHAR
) return TRUE
;
3972 if(wParam
<= 0x000fffff)
3974 if(wParam
> 0xffff) /* convert to surrogates */
3977 ME_Char(editor
, (wParam
>> 10) + 0xd800, 0, TRUE
);
3978 ME_Char(editor
, (wParam
& 0x03ff) + 0xdc00, 0, TRUE
);
3980 ME_Char(editor
, wParam
, 0, TRUE
);
3986 case EM_STOPGROUPTYPING
:
3987 ME_CommitUndo(editor
); /* End coalesced undos for typed characters */
3991 const int scrollUnit
= 7;
3993 switch(LOWORD(wParam
))
3996 ME_ScrollAbs(editor
, 0, 0);
3999 ME_ScrollAbs(editor
,
4000 editor
->horz_si
.nMax
- (int)editor
->horz_si
.nPage
,
4001 editor
->vert_si
.nMax
- (int)editor
->vert_si
.nPage
);
4004 ME_ScrollLeft(editor
, scrollUnit
);
4007 ME_ScrollRight(editor
, scrollUnit
);
4010 ME_ScrollLeft(editor
, editor
->sizeWindow
.cx
);
4013 ME_ScrollRight(editor
, editor
->sizeWindow
.cx
);
4016 case SB_THUMBPOSITION
:
4019 sbi
.cbSize
= sizeof(sbi
);
4020 sbi
.fMask
= SIF_TRACKPOS
;
4021 /* Try to get 32-bit track position value. */
4022 if (!GetScrollInfo(editor
->hWnd
, SB_HORZ
, &sbi
))
4023 /* GetScrollInfo failed, settle for 16-bit value in wParam. */
4024 sbi
.nTrackPos
= HIWORD(wParam
);
4026 ME_HScrollAbs(editor
, sbi
.nTrackPos
);
4032 case EM_SCROLL
: /* fall through */
4038 origNPos
= editor
->vert_si
.nPos
;
4041 if (editor
->pBuffer
&& editor
->pBuffer
->pDefaultStyle
)
4042 lineHeight
= editor
->pBuffer
->pDefaultStyle
->tm
.tmHeight
;
4043 if (lineHeight
<= 0) lineHeight
= 24;
4045 switch(LOWORD(wParam
))
4048 ME_ScrollAbs(editor
, 0, 0);
4051 ME_ScrollAbs(editor
,
4052 editor
->horz_si
.nMax
- (int)editor
->horz_si
.nPage
,
4053 editor
->vert_si
.nMax
- (int)editor
->vert_si
.nPage
);
4056 ME_ScrollUp(editor
,lineHeight
);
4059 ME_ScrollDown(editor
,lineHeight
);
4062 ME_ScrollUp(editor
,editor
->sizeWindow
.cy
);
4065 ME_ScrollDown(editor
,editor
->sizeWindow
.cy
);
4068 case SB_THUMBPOSITION
:
4071 sbi
.cbSize
= sizeof(sbi
);
4072 sbi
.fMask
= SIF_TRACKPOS
;
4073 /* Try to get 32-bit track position value. */
4074 if (!GetScrollInfo(editor
->hWnd
, SB_VERT
, &sbi
))
4075 /* GetScrollInfo failed, settle for 16-bit value in wParam. */
4076 sbi
.nTrackPos
= HIWORD(wParam
);
4078 ME_VScrollAbs(editor
, sbi
.nTrackPos
);
4082 if (msg
== EM_SCROLL
)
4083 return 0x00010000 | (((editor
->vert_si
.nPos
- origNPos
)/lineHeight
) & 0xffff);
4089 UINT pulScrollLines
;
4092 if ((editor
->nEventMask
& ENM_MOUSEEVENTS
) &&
4093 !ME_FilterEvent(editor
, msg
, &wParam
, &lParam
))
4096 ctrl_is_down
= GetKeyState(VK_CONTROL
) & 0x8000;
4098 gcWheelDelta
= GET_WHEEL_DELTA_WPARAM(wParam
);
4100 if (abs(gcWheelDelta
) >= WHEEL_DELTA
)
4104 if (!editor
->nZoomNumerator
|| !editor
->nZoomDenominator
)
4108 numerator
= editor
->nZoomNumerator
* 100 / editor
->nZoomDenominator
;
4110 numerator
= numerator
+ (gcWheelDelta
/ WHEEL_DELTA
) * 10;
4111 if (numerator
>= 10 && numerator
<= 500)
4112 ME_SetZoom(editor
, numerator
, 100);
4114 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
4115 /* FIXME follow the original */
4117 ME_ScrollDown(editor
,pulScrollLines
* (-gcWheelDelta
/ WHEEL_DELTA
) * 8);
4124 *((RECT
*)lParam
) = editor
->rcFormat
;
4125 if (editor
->bDefaultFormatRect
)
4126 ((RECT
*)lParam
)->left
-= editor
->selofs
;
4136 RECT
*rc
= (RECT
*)lParam
;
4138 border
= editor
->exStyleFlags
& WS_EX_CLIENTEDGE
? 1 : 0;
4139 ITextHost_TxGetClientRect(editor
->texthost
, &clientRect
);
4142 editor
->rcFormat
.top
= max(0, rc
->top
- border
);
4143 editor
->rcFormat
.left
= max(0, rc
->left
- border
);
4144 editor
->rcFormat
.bottom
= min(clientRect
.bottom
, rc
->bottom
);
4145 editor
->rcFormat
.right
= min(clientRect
.right
, rc
->right
+ border
);
4146 } else if (wParam
== 1) {
4147 /* MSDN incorrectly says a wParam value of 1 causes the
4148 * lParam rect to be used as a relative offset,
4149 * however, the tests show it just prevents min/max bound
4151 editor
->rcFormat
.top
= rc
->top
- border
;
4152 editor
->rcFormat
.left
= rc
->left
- border
;
4153 editor
->rcFormat
.bottom
= rc
->bottom
;
4154 editor
->rcFormat
.right
= rc
->right
+ border
;
4158 editor
->bDefaultFormatRect
= FALSE
;
4162 ME_SetDefaultFormatRect(editor
);
4163 editor
->bDefaultFormatRect
= TRUE
;
4165 ME_MarkAllForWrapping(editor
);
4166 ME_WrapMarkedParagraphs(editor
);
4167 ME_UpdateScrollBar(editor
);
4168 if (msg
!= EM_SETRECTNP
)
4172 case EM_REQUESTRESIZE
:
4173 ME_SendRequestResize(editor
, TRUE
);
4181 ITextHost_TxGetClientRect(editor
->texthost
, &clientRect
);
4182 if (editor
->bDefaultFormatRect
) {
4183 ME_SetDefaultFormatRect(editor
);
4185 editor
->rcFormat
.right
+= clientRect
.right
- editor
->prevClientRect
.right
;
4186 editor
->rcFormat
.bottom
+= clientRect
.bottom
- editor
->prevClientRect
.bottom
;
4188 editor
->prevClientRect
= clientRect
;
4189 ME_RewrapRepaint(editor
);
4192 /* IME messages to make richedit controls IME aware */
4193 case WM_IME_SETCONTEXT
:
4194 case WM_IME_CONTROL
:
4196 case WM_IME_COMPOSITIONFULL
:
4198 case WM_IME_STARTCOMPOSITION
:
4200 editor
->imeStartIndex
=ME_GetCursorOfs(editor
,0);
4201 ME_DeleteSelection(editor
);
4202 ME_CommitUndo(editor
);
4203 ME_UpdateRepaint(editor
);
4206 case WM_IME_COMPOSITION
:
4210 ME_Style
*style
= ME_GetInsertStyle(editor
, 0);
4211 hIMC
= ITextHost_TxImmGetContext(editor
->texthost
);
4212 ME_DeleteSelection(editor
);
4213 ME_CommitUndo(editor
);
4214 ME_SaveTempStyle(editor
);
4215 if (lParam
& GCS_RESULTSTR
)
4217 LPWSTR lpCompStr
= NULL
;
4220 dwBufLen
= ImmGetCompositionStringW(hIMC
, GCS_RESULTSTR
, NULL
, 0);
4221 lpCompStr
= HeapAlloc(GetProcessHeap(),0,dwBufLen
+ sizeof(WCHAR
));
4222 ImmGetCompositionStringW(hIMC
, GCS_RESULTSTR
, lpCompStr
, dwBufLen
);
4223 lpCompStr
[dwBufLen
/sizeof(WCHAR
)] = 0;
4224 ME_InsertTextFromCursor(editor
,0,lpCompStr
,dwBufLen
/sizeof(WCHAR
),style
);
4226 else if (lParam
& GCS_COMPSTR
)
4228 LPWSTR lpCompStr
= NULL
;
4231 dwBufLen
= ImmGetCompositionStringW(hIMC
, GCS_COMPSTR
, NULL
, 0);
4232 lpCompStr
= HeapAlloc(GetProcessHeap(),0,dwBufLen
+ sizeof(WCHAR
));
4233 ImmGetCompositionStringW(hIMC
, GCS_COMPSTR
, lpCompStr
, dwBufLen
);
4234 lpCompStr
[dwBufLen
/sizeof(WCHAR
)] = 0;
4236 ME_InsertTextFromCursor(editor
,0,lpCompStr
,dwBufLen
/sizeof(WCHAR
),style
);
4237 ME_SetSelection(editor
,editor
->imeStartIndex
,
4238 editor
->imeStartIndex
+ dwBufLen
/sizeof(WCHAR
));
4240 ME_ReleaseStyle(style
);
4241 ME_UpdateRepaint(editor
);
4244 case WM_IME_ENDCOMPOSITION
:
4246 ME_DeleteSelection(editor
);
4247 editor
->imeStartIndex
=-1;
4250 case EM_GETOLEINTERFACE
:
4252 LPVOID
*ppvObj
= (LPVOID
*) lParam
;
4253 return CreateIRichEditOle(editor
, ppvObj
);
4255 case EM_GETPASSWORDCHAR
:
4257 return editor
->cPasswordMask
;
4259 case EM_SETOLECALLBACK
:
4260 if(editor
->lpOleCallback
)
4261 IUnknown_Release(editor
->lpOleCallback
);
4262 editor
->lpOleCallback
= (LPRICHEDITOLECALLBACK
)lParam
;
4263 if(editor
->lpOleCallback
)
4264 IUnknown_AddRef(editor
->lpOleCallback
);
4266 case EM_GETWORDBREAKPROC
:
4267 return (LRESULT
)editor
->pfnWordBreak
;
4268 case EM_SETWORDBREAKPROC
:
4270 EDITWORDBREAKPROCW pfnOld
= editor
->pfnWordBreak
;
4272 editor
->pfnWordBreak
= (EDITWORDBREAKPROCW
)lParam
;
4273 return (LRESULT
)pfnOld
;
4275 case EM_GETTEXTMODE
:
4276 return editor
->mode
;
4277 case EM_SETTEXTMODE
:
4282 GETTEXTLENGTHEX how
;
4284 /* CR/LF conversion required in 2.0 mode, verbatim in 1.0 mode */
4285 how
.flags
= GTL_CLOSE
| (editor
->bEmulateVersion10
? 0 : GTL_USECRLF
) | GTL_NUMCHARS
;
4286 how
.codepage
= unicode
? 1200 : CP_ACP
;
4287 ret
= ME_GetTextLengthEx(editor
, &how
);
4290 /*Check for valid wParam*/
4291 if ((((wParam
& TM_RICHTEXT
) && ((wParam
& TM_PLAINTEXT
) << 1))) ||
4292 (((wParam
& TM_MULTILEVELUNDO
) && ((wParam
& TM_SINGLELEVELUNDO
) << 1))) ||
4293 (((wParam
& TM_MULTICODEPAGE
) && ((wParam
& TM_SINGLECODEPAGE
) << 1))))
4297 if (wParam
& (TM_RICHTEXT
| TM_PLAINTEXT
))
4299 mask
|= (TM_RICHTEXT
| TM_PLAINTEXT
);
4300 changes
|= (wParam
& (TM_RICHTEXT
| TM_PLAINTEXT
));
4302 /*FIXME: Currently no support for undo level and code page options*/
4303 editor
->mode
= (editor
->mode
& (~mask
)) | changes
;
4309 case EM_SETPASSWORDCHAR
:
4311 editor
->cPasswordMask
= wParam
;
4312 ME_RewrapRepaint(editor
);
4315 case EM_SETTARGETDEVICE
:
4318 BOOL
new = (lParam
== 0 && (editor
->styleFlags
& ES_MULTILINE
));
4319 if (editor
->nAvailWidth
|| editor
->bWordWrap
!= new)
4321 editor
->bWordWrap
= new;
4322 editor
->nAvailWidth
= 0; /* wrap to client area */
4323 ME_RewrapRepaint(editor
);
4326 int width
= max(0, lParam
);
4327 if ((editor
->styleFlags
& ES_MULTILINE
) &&
4328 (!editor
->bWordWrap
|| editor
->nAvailWidth
!= width
))
4330 editor
->nAvailWidth
= width
;
4331 editor
->bWordWrap
= TRUE
;
4332 ME_RewrapRepaint(editor
);
4334 FIXME("EM_SETTARGETDEVICE doesn't use non-NULL target devices\n");
4339 *phresult
= S_FALSE
;
4345 static LRESULT
RichEditWndProc_common(HWND hWnd
, UINT msg
, WPARAM wParam
,
4346 LPARAM lParam
, BOOL unicode
)
4348 ME_TextEditor
*editor
;
4350 LRESULT lresult
= 0;
4352 TRACE("enter hwnd %p msg %04x (%s) %lx %lx, unicode %d\n",
4353 hWnd
, msg
, get_msg_name(msg
), wParam
, lParam
, unicode
);
4355 editor
= (ME_TextEditor
*)GetWindowLongPtrW(hWnd
, 0);
4358 if (msg
== WM_NCCREATE
)
4360 CREATESTRUCTW
*pcs
= (CREATESTRUCTW
*)lParam
;
4361 ITextHost
*texthost
;
4363 TRACE("WM_NCCREATE: hWnd %p style 0x%08x\n", hWnd
, pcs
->style
);
4364 texthost
= ME_CreateTextHost(hWnd
, FALSE
);
4365 return texthost
!= NULL
;
4367 else if (msg
!= WM_NCDESTROY
)
4369 ERR("called with invalid hWnd %p - application bug?\n", hWnd
);
4382 hDC
= BeginPaint(editor
->hWnd
, &ps
);
4383 /* Erase area outside of the formatting rectangle */
4384 if (ps
.rcPaint
.top
< editor
->rcFormat
.top
)
4387 rc
.bottom
= editor
->rcFormat
.top
;
4388 FillRect(hDC
, &rc
, editor
->hbrBackground
);
4389 ps
.rcPaint
.top
= editor
->rcFormat
.top
;
4391 if (ps
.rcPaint
.bottom
> editor
->rcFormat
.bottom
) {
4393 rc
.top
= editor
->rcFormat
.bottom
;
4394 FillRect(hDC
, &rc
, editor
->hbrBackground
);
4395 ps
.rcPaint
.bottom
= editor
->rcFormat
.bottom
;
4397 if (ps
.rcPaint
.left
< editor
->rcFormat
.left
) {
4399 rc
.right
= editor
->rcFormat
.left
;
4400 FillRect(hDC
, &rc
, editor
->hbrBackground
);
4401 ps
.rcPaint
.left
= editor
->rcFormat
.left
;
4403 if (ps
.rcPaint
.right
> editor
->rcFormat
.right
) {
4405 rc
.left
= editor
->rcFormat
.right
;
4406 FillRect(hDC
, &rc
, editor
->hbrBackground
);
4407 ps
.rcPaint
.right
= editor
->rcFormat
.right
;
4410 ME_PaintContent(editor
, hDC
, FALSE
, &ps
.rcPaint
);
4411 EndPaint(editor
->hWnd
, &ps
);
4416 HDC hDC
= (HDC
)wParam
;
4419 if (GetUpdateRect(editor
->hWnd
, &rc
, TRUE
))
4420 FillRect(hDC
, &rc
, editor
->hbrBackground
);
4426 const DWORD mask
= ECO_VERTICAL
| ECO_AUTOHSCROLL
| ECO_AUTOVSCROLL
|
4427 ECO_NOHIDESEL
| ECO_READONLY
| ECO_WANTRETURN
|
4429 lresult
= ME_HandleMessage(editor
, msg
, wParam
, lParam
, unicode
, &hresult
);
4430 dwStyle
= GetWindowLongW(hWnd
, GWL_STYLE
);
4431 dwStyle
= (dwStyle
& ~mask
) | (lresult
& mask
);
4432 SetWindowLongW(hWnd
, GWL_STYLE
, dwStyle
);
4435 case EM_SETREADONLY
:
4438 lresult
= ME_HandleMessage(editor
, msg
, wParam
, lParam
, unicode
, &hresult
);
4439 dwStyle
= GetWindowLongW(hWnd
, GWL_STYLE
);
4440 dwStyle
&= ~ES_READONLY
;
4442 dwStyle
|= ES_READONLY
;
4443 SetWindowLongW(hWnd
, GWL_STYLE
, dwStyle
);
4447 lresult
= ME_HandleMessage(editor
, msg
, wParam
, lParam
, unicode
, &hresult
);
4450 if (hresult
== S_FALSE
)
4451 lresult
= DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
4453 TRACE("exit hwnd %p msg %04x (%s) %lx %lx, unicode %d -> %lu\n",
4454 hWnd
, msg
, get_msg_name(msg
), wParam
, lParam
, unicode
, lresult
);
4459 static LRESULT WINAPI
RichEditWndProcW(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
4461 BOOL unicode
= TRUE
;
4463 /* Under Win9x RichEdit20W returns ANSI strings, see the tests. */
4464 if (msg
== WM_GETTEXT
&& (GetVersion() & 0x80000000))
4467 return RichEditWndProc_common(hWnd
, msg
, wParam
, lParam
, unicode
);
4470 static LRESULT WINAPI
RichEditWndProcA(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
4472 return RichEditWndProc_common(hWnd
, msg
, wParam
, lParam
, FALSE
);
4475 /******************************************************************
4476 * RichEditANSIWndProc (RICHED20.10)
4478 LRESULT WINAPI
RichEditANSIWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
4480 return RichEditWndProcA(hWnd
, msg
, wParam
, lParam
);
4483 /******************************************************************
4484 * RichEdit10ANSIWndProc (RICHED20.9)
4486 LRESULT WINAPI
RichEdit10ANSIWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
4488 if (msg
== WM_NCCREATE
&& !GetWindowLongPtrW(hWnd
, 0))
4490 ITextHost
*texthost
;
4491 CREATESTRUCTW
*pcs
= (CREATESTRUCTW
*)lParam
;
4493 TRACE("WM_NCCREATE: hWnd %p style 0x%08x\n", hWnd
, pcs
->style
);
4494 texthost
= ME_CreateTextHost(hWnd
, TRUE
);
4495 return texthost
!= NULL
;
4497 return RichEditANSIWndProc(hWnd
, msg
, wParam
, lParam
);
4500 void ME_SendOldNotify(ME_TextEditor
*editor
, int nCode
)
4502 ITextHost_TxNotify(editor
->texthost
, nCode
, NULL
);
4505 int ME_CountParagraphsBetween(ME_TextEditor
*editor
, int from
, int to
)
4507 ME_DisplayItem
*item
= ME_FindItemFwd(editor
->pBuffer
->pFirst
, diParagraph
);
4510 while(item
&& item
->member
.para
.next_para
->member
.para
.nCharOfs
<= from
)
4511 item
= item
->member
.para
.next_para
;
4514 while(item
&& item
->member
.para
.next_para
->member
.para
.nCharOfs
<= to
) {
4515 item
= item
->member
.para
.next_para
;
4522 int ME_GetTextW(ME_TextEditor
*editor
, WCHAR
*buffer
, int nStart
,
4523 int nChars
, int bCRLF
)
4525 ME_DisplayItem
*pRun
;
4526 int nOffset
, nWritten
= 0;
4527 WCHAR
*pStart
= buffer
;
4529 ME_RunOfsFromCharOfs(editor
, nStart
, NULL
, &pRun
, &nOffset
);
4531 /* bCRLF flag is only honored in 2.0 and up. 1.0 must always return text verbatim */
4532 if (editor
->bEmulateVersion10
) bCRLF
= 0;
4534 while (nChars
&& pRun
)
4538 if (pRun
->member
.run
.nFlags
& MERF_ENDCELL
&&
4539 pRun
->member
.run
.nFlags
& MERF_ENDPARA
)
4543 } else if (pRun
->member
.run
.nFlags
& MERF_ENDPARA
) {
4544 if (!ME_FindItemFwd(pRun
, diRun
)) {
4545 /* No '\r' is appended to the last paragraph. */
4547 } else if (bCRLF
&& nChars
== 1) {
4551 WCHAR cr_lf
[] = {'\r', '\n', 0};
4559 nLen
= pRun
->member
.run
.strText
->nLen
;
4560 szData
= pRun
->member
.run
.strText
->szData
;
4562 nLen
= min(nChars
, nLen
- nOffset
);
4563 CopyMemory(buffer
, szData
+ nOffset
, sizeof(WCHAR
) * nLen
);
4566 nLen
= min(nChars
, pRun
->member
.run
.strText
->nLen
- nOffset
);
4567 CopyMemory(buffer
, pRun
->member
.run
.strText
->szData
+ nOffset
,
4568 sizeof(WCHAR
) * nLen
);
4575 pRun
= ME_FindItemFwd(pRun
, diRun
);
4578 TRACE("nWritten=%d, actual=%d\n", nWritten
, buffer
-pStart
);
4582 static BOOL
ME_RegisterEditorClass(HINSTANCE hInstance
)
4587 wcW
.style
= CS_DBLCLKS
| CS_HREDRAW
| CS_VREDRAW
| CS_GLOBALCLASS
;
4588 wcW
.lpfnWndProc
= RichEditWndProcW
;
4590 wcW
.cbWndExtra
= sizeof(ME_TextEditor
*);
4591 wcW
.hInstance
= NULL
; /* hInstance would register DLL-local class */
4593 wcW
.hCursor
= LoadCursorW(NULL
, MAKEINTRESOURCEW(IDC_IBEAM
));
4594 wcW
.hbrBackground
= GetStockObject(NULL_BRUSH
);
4595 wcW
.lpszMenuName
= NULL
;
4597 if (is_version_nt())
4599 wcW
.lpszClassName
= RichEdit20W
;
4600 if (!RegisterClassW(&wcW
)) return FALSE
;
4601 wcW
.lpszClassName
= RichEdit50W
;
4602 if (!RegisterClassW(&wcW
)) return FALSE
;
4606 /* WNDCLASSA/W have the same layout */
4607 wcW
.lpszClassName
= (LPCWSTR
)"RichEdit20W";
4608 if (!RegisterClassA((WNDCLASSA
*)&wcW
)) return FALSE
;
4609 wcW
.lpszClassName
= (LPCWSTR
)"RichEdit50W";
4610 if (!RegisterClassA((WNDCLASSA
*)&wcW
)) return FALSE
;
4613 wcA
.style
= CS_DBLCLKS
| CS_HREDRAW
| CS_VREDRAW
| CS_GLOBALCLASS
;
4614 wcA
.lpfnWndProc
= RichEditWndProcA
;
4616 wcA
.cbWndExtra
= sizeof(ME_TextEditor
*);
4617 wcA
.hInstance
= NULL
; /* hInstance would register DLL-local class */
4619 wcA
.hCursor
= LoadCursorW(NULL
, MAKEINTRESOURCEW(IDC_IBEAM
));
4620 wcA
.hbrBackground
= GetStockObject(NULL_BRUSH
);
4621 wcA
.lpszMenuName
= NULL
;
4622 wcA
.lpszClassName
= "RichEdit20A";
4623 if (!RegisterClassA(&wcA
)) return FALSE
;
4624 wcA
.lpszClassName
= "RichEdit50A";
4625 if (!RegisterClassA(&wcA
)) return FALSE
;
4630 static LRESULT WINAPI
REComboWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
) {
4631 /* FIXME: Not implemented */
4632 TRACE("hWnd %p msg %04x (%s) %08lx %08lx\n",
4633 hWnd
, msg
, get_msg_name(msg
), wParam
, lParam
);
4634 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
4637 static LRESULT WINAPI
REListWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
) {
4638 /* FIXME: Not implemented */
4639 TRACE("hWnd %p msg %04x (%s) %08lx %08lx\n",
4640 hWnd
, msg
, get_msg_name(msg
), wParam
, lParam
);
4641 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
4644 /******************************************************************
4645 * REExtendedRegisterClass (RICHED20.8)
4647 * FIXME undocumented
4648 * Need to check for errors and implement controls and callbacks
4650 LRESULT WINAPI
REExtendedRegisterClass(void)
4655 FIXME("semi stub\n");
4659 wcW
.hInstance
= NULL
;
4662 wcW
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+1);
4663 wcW
.lpszMenuName
= NULL
;
4665 if (!ME_ListBoxRegistered
)
4667 wcW
.style
= CS_PARENTDC
| CS_DBLCLKS
| CS_GLOBALCLASS
;
4668 wcW
.lpfnWndProc
= REListWndProc
;
4669 wcW
.lpszClassName
= REListBox20W
;
4670 if (RegisterClassW(&wcW
)) ME_ListBoxRegistered
= TRUE
;
4673 if (!ME_ComboBoxRegistered
)
4675 wcW
.style
= CS_PARENTDC
| CS_DBLCLKS
| CS_GLOBALCLASS
| CS_VREDRAW
| CS_HREDRAW
;
4676 wcW
.lpfnWndProc
= REComboWndProc
;
4677 wcW
.lpszClassName
= REComboBox20W
;
4678 if (RegisterClassW(&wcW
)) ME_ComboBoxRegistered
= TRUE
;
4682 if (ME_ListBoxRegistered
)
4684 if (ME_ComboBoxRegistered
)
4690 static BOOL
isurlspecial(WCHAR c
)
4692 static const WCHAR special_chars
[] = {'.','/','%','@','*','|','\\','+','#',0};
4693 return strchrW( special_chars
, c
) != NULL
;
4697 * This proc takes a selection, and scans it forward in order to select the span
4698 * of a possible URL candidate. A possible URL candidate must start with isalnum
4699 * or one of the following special characters: *|/\+%#@ and must consist entirely
4700 * of the characters allowed to start the URL, plus : (colon) which may occur
4701 * at most once, and not at either end.
4703 * sel_max == -1 indicates scan to end of text.
4705 static BOOL
ME_FindNextURLCandidate(ME_TextEditor
*editor
, int sel_min
, int sel_max
,
4706 int * candidate_min
, int * candidate_max
)
4708 ME_DisplayItem
* item
;
4709 ME_DisplayItem
* para
;
4711 BOOL foundColon
= FALSE
;
4712 WCHAR lastAcceptedChar
= '\0';
4714 TRACE("sel_min = %d sel_max = %d\n", sel_min
, sel_max
);
4716 *candidate_min
= *candidate_max
= -1;
4717 ME_RunOfsFromCharOfs(editor
, sel_min
, ¶
, &item
, &nStart
);
4718 TRACE("nStart = %d\n", nStart
);
4719 if (sel_max
== -1) sel_max
= ME_GetTextLength(editor
);
4720 while (item
&& para
->member
.para
.nCharOfs
+ item
->member
.run
.nCharOfs
+ nStart
< sel_max
)
4722 ME_DisplayItem
* next_item
;
4724 if (!(item
->member
.run
.nFlags
& MERF_ENDPARA
)) {
4725 /* Find start of candidate */
4726 if (*candidate_min
== -1) {
4727 while (nStart
< item
->member
.run
.strText
->nLen
&&
4728 !(isalnumW(item
->member
.run
.strText
->szData
[nStart
]) ||
4729 isurlspecial(item
->member
.run
.strText
->szData
[nStart
]))) {
4732 if (nStart
< item
->member
.run
.strText
->nLen
&&
4733 (isalnumW(item
->member
.run
.strText
->szData
[nStart
]) ||
4734 isurlspecial(item
->member
.run
.strText
->szData
[nStart
]))) {
4735 *candidate_min
= para
->member
.para
.nCharOfs
+ item
->member
.run
.nCharOfs
+ nStart
;
4736 lastAcceptedChar
= item
->member
.run
.strText
->szData
[nStart
];
4741 /* Find end of candidate */
4742 if (*candidate_min
>= 0) {
4743 while (nStart
< item
->member
.run
.strText
->nLen
&&
4744 (isalnumW(item
->member
.run
.strText
->szData
[nStart
]) ||
4745 isurlspecial(item
->member
.run
.strText
->szData
[nStart
]) ||
4746 (!foundColon
&& item
->member
.run
.strText
->szData
[nStart
] == ':') )) {
4747 if (item
->member
.run
.strText
->szData
[nStart
] == ':') foundColon
= TRUE
;
4748 lastAcceptedChar
= item
->member
.run
.strText
->szData
[nStart
];
4751 if (nStart
< item
->member
.run
.strText
->nLen
&&
4752 !(isalnumW(item
->member
.run
.strText
->szData
[nStart
]) ||
4753 isurlspecial(item
->member
.run
.strText
->szData
[nStart
]) )) {
4754 *candidate_max
= para
->member
.para
.nCharOfs
+ item
->member
.run
.nCharOfs
+ nStart
;
4756 if (lastAcceptedChar
== ':') (*candidate_max
)--;
4761 /* End of paragraph: skip it if before candidate span, or terminates
4762 current active span */
4763 if (*candidate_min
>= 0) {
4764 *candidate_max
= para
->member
.para
.nCharOfs
+ item
->member
.run
.nCharOfs
;
4765 if (lastAcceptedChar
== ':') (*candidate_max
)--;
4770 /* Reaching this point means no span was found, so get next span */
4771 next_item
= ME_FindItemFwd(item
, diRun
);
4773 if (*candidate_min
>= 0) {
4774 /* There are no further runs, so take end of text as end of candidate */
4775 *candidate_max
= para
->member
.para
.nCharOfs
+ item
->member
.run
.nCharOfs
+ nStart
;
4776 if (lastAcceptedChar
== ':') (*candidate_max
)--;
4781 para
= ME_GetParagraph(item
);
4786 if (*candidate_min
>= 0) {
4787 /* There are no further runs, so take end of text as end of candidate */
4788 *candidate_max
= para
->member
.para
.nCharOfs
+ item
->member
.run
.nCharOfs
+ nStart
;
4789 if (lastAcceptedChar
== ':') (*candidate_max
)--;
4797 * This proc evaluates the selection and returns TRUE if it can be considered an URL
4799 static BOOL
ME_IsCandidateAnURL(ME_TextEditor
*editor
, int sel_min
, int sel_max
)
4805 /* Code below depends on these being in decreasing length order! */
4819 LPWSTR bufferW
= NULL
;
4823 if (sel_max
== -1) sel_max
= ME_GetTextLength(editor
);
4824 assert(sel_min
<= sel_max
);
4825 for (i
= 0; i
< sizeof(prefixes
) / sizeof(struct prefix_s
); i
++)
4827 if (sel_max
- sel_min
< prefixes
[i
].length
) continue;
4828 if (bufferW
== NULL
) {
4829 bufferW
= heap_alloc((sel_max
- sel_min
+ 1) * sizeof(WCHAR
));
4831 ME_GetTextW(editor
, bufferW
, sel_min
, min(sel_max
- sel_min
, lstrlenA(prefixes
[i
].text
)), 0);
4832 MultiByteToWideChar(CP_ACP
, 0, prefixes
[i
].text
, -1, bufW
, 32);
4833 if (!lstrcmpW(bufW
, bufferW
))
4844 * This proc walks through the indicated selection and evaluates whether each
4845 * section identified by ME_FindNextURLCandidate and in-between sections have
4846 * their proper CFE_LINK attributes set or unset. If the CFE_LINK attribute is
4847 * not what it is supposed to be, this proc sets or unsets it as appropriate.
4849 * Returns TRUE if at least one section was modified.
4851 static BOOL
ME_UpdateLinkAttribute(ME_TextEditor
*editor
, int sel_min
, int sel_max
)
4853 BOOL modified
= FALSE
;
4856 if (!editor
->AutoURLDetect_bEnable
) return FALSE
;
4858 if (sel_max
== -1) sel_max
= ME_GetTextLength(editor
);
4865 if (ME_FindNextURLCandidate(editor
, sel_min
, sel_max
, &cMin
, &cMax
))
4867 /* Section before candidate is not an URL */
4868 beforeURL
[0] = sel_min
;
4869 beforeURL
[1] = cMin
;
4871 if (ME_IsCandidateAnURL(editor
, cMin
, cMax
))
4873 inURL
[0] = cMin
; inURL
[1] = cMax
;
4877 beforeURL
[1] = cMax
;
4878 inURL
[0] = inURL
[1] = -1;
4884 /* No more candidates until end of selection */
4885 beforeURL
[0] = sel_min
;
4886 beforeURL
[1] = sel_max
;
4887 inURL
[0] = inURL
[1] = -1;
4891 if (beforeURL
[0] < beforeURL
[1])
4893 /* CFE_LINK effect should be consistently unset */
4894 link
.cbSize
= sizeof(link
);
4895 ME_GetCharFormat(editor
, beforeURL
[0], beforeURL
[1], &link
);
4896 if (!(link
.dwMask
& CFM_LINK
) || (link
.dwEffects
& CFE_LINK
))
4898 /* CFE_LINK must be unset from this range */
4899 memset(&link
, 0, sizeof(CHARFORMAT2W
));
4900 link
.cbSize
= sizeof(link
);
4901 link
.dwMask
= CFM_LINK
;
4903 ME_SetCharFormat(editor
, beforeURL
[0], beforeURL
[1] - beforeURL
[0], &link
);
4907 if (inURL
[0] < inURL
[1])
4909 /* CFE_LINK effect should be consistently set */
4910 link
.cbSize
= sizeof(link
);
4911 ME_GetCharFormat(editor
, inURL
[0], inURL
[1], &link
);
4912 if (!(link
.dwMask
& CFM_LINK
) || !(link
.dwEffects
& CFE_LINK
))
4914 /* CFE_LINK must be set on this range */
4915 memset(&link
, 0, sizeof(CHARFORMAT2W
));
4916 link
.cbSize
= sizeof(link
);
4917 link
.dwMask
= CFM_LINK
;
4918 link
.dwEffects
= CFE_LINK
;
4919 ME_SetCharFormat(editor
, inURL
[0], inURL
[1] - inURL
[0], &link
);
4923 } while (sel_min
< sel_max
);