2 * RichEdit - functions dealing with editor object
4 * Copyright 2004 by Krzysztof Foltman
5 * Copyright 2005 by Cihan Altinay
6 * Copyright 2005 by Phil Krylov
7 * Copyright 2008 Eric Pouech
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 API implementation status:
27 Messages (ANSI versions not done yet)
28 + EM_AUTOURLDETECT 2.0
39 + EM_FINDTEXT (only FR_DOWN flag implemented)
40 + EM_FINDTEXTEX (only FR_DOWN flag implemented)
44 + EM_GETAUTOURLDETECT 2.0
45 - EM_GETBIDIOPTIONS 3.0
46 - EM_GETCHARFORMAT (partly done)
49 + EM_GETFIRSTVISIBLELINE (can be optimized if needed)
50 - EM_GETIMECOLOR 1.0asian
51 - EM_GETIMECOMPMODE 2.0
52 - EM_GETIMEOPTIONS 1.0asian
54 - EM_GETLANGOPTIONS 2.0
57 + EM_GETLINECOUNT returns number of rows, not of paragraphs
62 + EM_GETPASSWORDCHAR 2.0
63 - EM_GETPUNCTUATION 1.0asian
67 + EM_GETSELTEXT (ANSI&Unicode)
68 + EM_GETSCROLLPOS 3.0 (only Y value valid)
71 + EM_GETTEXTLENGTHEX (GTL_PRECISE unimplemented)
73 ? + EM_GETTEXTRANGE (ANSI&Unicode)
74 - EM_GETTYPOGRAPHYOPTIONS 3.0
77 - EM_GETWORDBREAKPROCEX
78 - EM_GETWORDWRAPMODE 1.0asian
81 + EM_LIMITTEXT (Also called EM_SETLIMITTEXT)
90 + EM_REPLACESEL (proper style?) ANSI&Unicode
94 - EM_SETBIDIOPTIONS 3.0
96 + EM_SETCHARFORMAT (partly done, no ANSI)
98 + EM_SETEVENTMASK (few notifications supported)
100 - EM_SETIMECOLOR 1.0asian
101 - EM_SETIMEOPTIONS 1.0asian
102 - EM_SETLANGOPTIONS 2.0
105 + EM_SETMODIFY (not sure if implementation is correct)
107 + EM_SETOPTIONS (partially implemented)
110 + EM_SETPASSWORDCHAR 2.0
111 - EM_SETPUNCTUATION 1.0asian
112 + EM_SETREADONLY no beep on modification attempt
114 + EM_SETRECTNP (EM_SETRECT without repainting)
116 + EM_SETSCROLLPOS 3.0
118 - EM_SETTARGETDEVICE (partial)
119 + EM_SETTEXTEX 3.0 (proper style?)
121 - EM_SETTYPOGRAPHYOPTIONS 3.0
122 + EM_SETUNDOLIMIT 2.0
123 + EM_SETWORDBREAKPROC (used only for word movement at the moment)
124 - EM_SETWORDBREAKPROCEX
125 - EM_SETWORDWRAPMODE 1.0asian
127 + EM_SHOWSCROLLBAR 2.0
128 + EM_STOPGROUPTYPING 2.0
136 + WM_GETDLGCODE (the current implementation is incomplete)
137 + WM_GETTEXT (ANSI&Unicode)
138 + WM_GETTEXTLENGTH (ANSI version sucks)
141 + WM_SETTEXT (resets undo stack !) (proper style?) ANSI&Unicode
143 - WM_STYLECHANGED (things like read-only flag)
148 * EN_CHANGE (sent from the wrong place)
165 * EN_UPDATE (sent from the wrong place)
173 + ES_DISABLENOSCROLL (scrollbar is always visible)
174 - ES_EX_NOCALLOLEINIT
176 - ES_MULTILINE (currently single line controls aren't supported)
178 - ES_READONLY (I'm not sure if beeping is the proper behaviour)
184 - ES_WANTRETURN (don't know how to do WM_GETDLGCODE part)
191 * RICHED20 TODO (incomplete):
193 * - messages/styles/notifications listed above
194 * - add remaining CHARFORMAT/PARAFORMAT fields
195 * - right/center align should strip spaces from the beginning
196 * - pictures/OLE objects (not just smiling faces that lack API support ;-) )
197 * - COM interface (looks like a major pain in the TODO list)
198 * - calculate heights of pictures (half-done)
199 * - horizontal scrolling (not even started)
200 * - hysteresis during wrapping (related to scrollbars appearing/disappearing)
202 * - how to implement EM_FORMATRANGE and EM_DISPLAYBAND ? (Mission Impossible)
203 * - italic caret with italic fonts
205 * - most notifications aren't sent at all (the most important ones are)
206 * - when should EN_SELCHANGE be sent after text change ? (before/after EN_UPDATE?)
207 * - WM_SETTEXT may use wrong style (but I'm 80% sure it's OK)
208 * - EM_GETCHARFORMAT with SCF_SELECTION may not behave 100% like in original (but very close)
209 * - full justification
212 * - ListBox & ComboBox not implemented
214 * Bugs that are probably fixed, but not so easy to verify:
215 * - EN_UPDATE/EN_CHANGE are handled very incorrectly (should be OK now)
216 * - undo for ME_JoinParagraphs doesn't store paragraph format ? (it does)
217 * - check/fix artificial EOL logic (bCursorAtEnd, hardly logical)
218 * - caret shouldn't be displayed when selection isn't empty
219 * - check refcounting in style management functions (looks perfect now, but no bugs is suspicious)
220 * - undo for setting default format (done, might be buggy)
221 * - styles might be not released properly (looks like they work like charm, but who knows?
228 #define NO_SHLWAPI_STREAM
234 #define STACK_SIZE_DEFAULT 100
235 #define STACK_SIZE_MAX 1000
237 #define TEXT_LIMIT_DEFAULT 32767
239 WINE_DEFAULT_DEBUG_CHANNEL(richedit
);
241 static BOOL
ME_RegisterEditorClass(HINSTANCE
);
243 static const WCHAR RichEdit20W
[] = {'R', 'i', 'c', 'h', 'E', 'd', 'i', 't', '2', '0', 'W', 0};
244 static const WCHAR RichEdit50W
[] = {'R', 'i', 'c', 'h', 'E', 'd', 'i', 't', '5', '0', 'W', 0};
245 static const WCHAR REListBox20W
[] = {'R','E','L','i','s','t','B','o','x','2','0','W', 0};
246 static const WCHAR REComboBox20W
[] = {'R','E','C','o','m','b','o','B','o','x','2','0','W', 0};
247 static HCURSOR hLeft
;
250 HANDLE me_heap
= NULL
;
252 static BOOL ME_ListBoxRegistered
= FALSE
;
253 static BOOL ME_ComboBoxRegistered
= FALSE
;
255 static inline int is_version_nt(void)
257 return !(GetVersion() & 0x80000000);
260 static ME_TextBuffer
*ME_MakeText(void) {
262 ME_TextBuffer
*buf
= ALLOC_OBJ(ME_TextBuffer
);
264 ME_DisplayItem
*p1
= ME_MakeDI(diTextStart
);
265 ME_DisplayItem
*p2
= ME_MakeDI(diTextEnd
);
271 p1
->member
.para
.next_para
= p2
;
272 p2
->member
.para
.prev_para
= p1
;
273 p2
->member
.para
.nCharOfs
= 0;
277 buf
->pCharStyle
= NULL
;
283 static LRESULT
ME_StreamInText(ME_TextEditor
*editor
, DWORD dwFormat
, ME_InStream
*stream
, ME_Style
*style
)
285 WCHAR wszText
[STREAMIN_BUFFER_SIZE
+1];
288 TRACE("%08x %p\n", dwFormat
, stream
);
295 ME_StreamInFill(stream
);
296 if (stream
->editstream
->dwError
)
302 if (!(dwFormat
& SF_UNICODE
))
304 /* FIXME? this is doomed to fail on true MBCS like UTF-8, luckily they're unlikely to be used as CP_ACP */
305 nWideChars
= MultiByteToWideChar(CP_ACP
, 0, stream
->buffer
, stream
->dwSize
, wszText
, STREAMIN_BUFFER_SIZE
);
310 nWideChars
= stream
->dwSize
>> 1;
311 pText
= (WCHAR
*)stream
->buffer
;
314 ME_InsertTextFromCursor(editor
, 0, pText
, nWideChars
, style
);
315 if (stream
->dwSize
== 0)
319 ME_CommitUndo(editor
);
320 ME_UpdateRepaint(editor
);
324 static void ME_ApplyBorderProperties(RTF_Info
*info
,
325 ME_BorderRect
*borderRect
,
326 RTFBorder
*borderDef
)
329 ME_Border
*pBorders
[] = {&borderRect
->top
,
333 for (i
= 0; i
< 4; i
++)
335 RTFColor
*colorDef
= info
->colorList
;
336 pBorders
[i
]->width
= borderDef
[i
].width
;
337 colorNum
= borderDef
[i
].color
;
338 while (colorDef
&& colorDef
->rtfCNum
!= colorNum
)
339 colorDef
= colorDef
->rtfNextColor
;
341 pBorders
[i
]->colorRef
= RGB(
342 colorDef
->rtfCRed
>= 0 ? colorDef
->rtfCRed
: 0,
343 colorDef
->rtfCGreen
>= 0 ? colorDef
->rtfCGreen
: 0,
344 colorDef
->rtfCBlue
>= 0 ? colorDef
->rtfCBlue
: 0);
346 pBorders
[i
]->colorRef
= RGB(0, 0, 0);
350 void ME_RTFCharAttrHook(RTF_Info
*info
)
353 fmt
.cbSize
= sizeof(fmt
);
357 switch(info
->rtfMinor
)
360 /* FIXME add more flags once they're implemented */
361 fmt
.dwMask
= CFM_BOLD
| CFM_ITALIC
| CFM_UNDERLINETYPE
| CFM_STRIKEOUT
| CFM_COLOR
| CFM_BACKCOLOR
| CFM_SIZE
| CFM_WEIGHT
;
362 fmt
.dwEffects
= CFE_AUTOCOLOR
| CFE_AUTOBACKCOLOR
;
363 fmt
.yHeight
= 12*20; /* 12pt */
364 fmt
.wWeight
= FW_NORMAL
;
365 fmt
.bUnderlineType
= CFU_UNDERLINENONE
;
368 fmt
.dwMask
= CFM_BOLD
| CFM_WEIGHT
;
369 fmt
.dwEffects
= info
->rtfParam
? CFE_BOLD
: 0;
370 fmt
.wWeight
= info
->rtfParam
? FW_BOLD
: FW_NORMAL
;
373 fmt
.dwMask
= CFM_ITALIC
;
374 fmt
.dwEffects
= info
->rtfParam
? fmt
.dwMask
: 0;
377 fmt
.dwMask
= CFM_UNDERLINETYPE
;
378 fmt
.bUnderlineType
= info
->rtfParam
? CFU_CF1UNDERLINE
: CFU_UNDERLINENONE
;
380 case rtfDotUnderline
:
381 fmt
.dwMask
= CFM_UNDERLINETYPE
;
382 fmt
.bUnderlineType
= info
->rtfParam
? CFU_UNDERLINEDOTTED
: CFU_UNDERLINENONE
;
385 fmt
.dwMask
= CFM_UNDERLINETYPE
;
386 fmt
.bUnderlineType
= info
->rtfParam
? CFU_UNDERLINEDOUBLE
: CFU_UNDERLINENONE
;
388 case rtfWordUnderline
:
389 fmt
.dwMask
= CFM_UNDERLINETYPE
;
390 fmt
.bUnderlineType
= info
->rtfParam
? CFU_UNDERLINEWORD
: CFU_UNDERLINENONE
;
393 fmt
.dwMask
= CFM_UNDERLINETYPE
;
394 fmt
.bUnderlineType
= CFU_UNDERLINENONE
;
397 fmt
.dwMask
= CFM_STRIKEOUT
;
398 fmt
.dwEffects
= info
->rtfParam
? fmt
.dwMask
: 0;
402 case rtfSubScrShrink
:
403 case rtfSuperScrShrink
:
405 fmt
.dwMask
= CFM_SUBSCRIPT
|CFM_SUPERSCRIPT
;
406 if (info
->rtfMinor
== rtfSubScrShrink
) fmt
.dwEffects
= CFE_SUBSCRIPT
;
407 if (info
->rtfMinor
== rtfSuperScrShrink
) fmt
.dwEffects
= CFE_SUPERSCRIPT
;
408 if (info
->rtfMinor
== rtfNoSuperSub
) fmt
.dwEffects
= 0;
411 fmt
.dwMask
= CFM_HIDDEN
;
412 fmt
.dwEffects
= info
->rtfParam
? fmt
.dwMask
: 0;
415 fmt
.dwMask
= CFM_BACKCOLOR
;
417 if (info
->rtfParam
== 0)
418 fmt
.dwEffects
= CFE_AUTOBACKCOLOR
;
419 else if (info
->rtfParam
!= rtfNoParam
)
421 RTFColor
*c
= RTFGetColor(info
, info
->rtfParam
);
422 fmt
.crTextColor
= (c
->rtfCBlue
<<16)|(c
->rtfCGreen
<<8)|(c
->rtfCRed
);
426 fmt
.dwMask
= CFM_COLOR
;
428 if (info
->rtfParam
== 0)
429 fmt
.dwEffects
= CFE_AUTOCOLOR
;
430 else if (info
->rtfParam
!= rtfNoParam
)
432 RTFColor
*c
= RTFGetColor(info
, info
->rtfParam
);
434 fmt
.crTextColor
= (c
->rtfCBlue
<<16)|(c
->rtfCGreen
<<8)|(c
->rtfCRed
);
440 if (info
->rtfParam
!= rtfNoParam
)
442 RTFFont
*f
= RTFGetFont(info
, info
->rtfParam
);
445 MultiByteToWideChar(CP_ACP
, 0, f
->rtfFName
, -1, fmt
.szFaceName
, sizeof(fmt
.szFaceName
)/sizeof(WCHAR
));
446 fmt
.szFaceName
[sizeof(fmt
.szFaceName
)/sizeof(WCHAR
)-1] = '\0';
447 fmt
.bCharSet
= f
->rtfFCharSet
;
448 fmt
.dwMask
= CFM_FACE
| CFM_CHARSET
;
449 fmt
.bPitchAndFamily
= f
->rtfFPitch
| (f
->rtfFFamily
<< 4);
454 fmt
.dwMask
= CFM_SIZE
;
455 if (info
->rtfParam
!= rtfNoParam
)
456 fmt
.yHeight
= info
->rtfParam
*10;
461 RTFFlushOutputBuffer(info
);
462 /* FIXME too slow ? how come ? */
463 style2
= ME_ApplyStyle(info
->style
, &fmt
);
464 ME_ReleaseStyle(info
->style
);
465 info
->style
= style2
;
466 info
->styleChanged
= TRUE
;
470 /* FIXME this function doesn't get any information about context of the RTF tag, which is very bad,
471 the same tags mean different things in different contexts */
472 void ME_RTFParAttrHook(RTF_Info
*info
)
475 fmt
.cbSize
= sizeof(fmt
);
478 switch(info
->rtfMinor
)
480 case rtfParDef
: /* restores default paragraph attributes */
481 if (!info
->editor
->bEmulateVersion10
) /* v4.1 */
482 info
->borderType
= RTFBorderParaLeft
;
483 else /* v1.0 - 3.0 */
484 info
->borderType
= RTFBorderParaTop
;
485 fmt
.dwMask
= PFM_ALIGNMENT
| PFM_BORDER
| PFM_LINESPACING
| PFM_TABSTOPS
|
486 PFM_OFFSET
| PFM_RIGHTINDENT
| PFM_SPACEAFTER
| PFM_SPACEBEFORE
|
488 /* TODO: numbering, shading */
489 fmt
.wAlignment
= PFA_LEFT
;
491 fmt
.dxOffset
= fmt
.dxStartIndent
= fmt
.dxRightIndent
= 0;
492 fmt
.wBorderWidth
= fmt
.wBorders
= 0;
493 fmt
.wBorderSpace
= 0;
494 fmt
.bLineSpacingRule
= 0;
495 fmt
.dySpaceBefore
= fmt
.dySpaceAfter
= 0;
496 fmt
.dyLineSpacing
= 0;
497 if (!info
->editor
->bEmulateVersion10
) /* v4.1 */
499 if (info
->tableDef
&& info
->tableDef
->tableRowStart
&&
500 info
->tableDef
->tableRowStart
->member
.para
.nFlags
& MEPF_ROWEND
)
503 ME_DisplayItem
*para
;
504 /* We are just after a table row. */
505 RTFFlushOutputBuffer(info
);
506 cursor
= info
->editor
->pCursors
[0];
507 para
= ME_GetParagraph(cursor
.pRun
);
508 if (para
== info
->tableDef
->tableRowStart
->member
.para
.next_para
509 && !cursor
.nOffset
&& !cursor
.pRun
->member
.run
.nCharOfs
)
511 /* Since the table row end, no text has been inserted, and the \intbl
512 * control word has not be used. We can confirm that we are not in a
515 info
->tableDef
->tableRowStart
= NULL
;
516 info
->canInheritInTbl
= FALSE
;
519 } else { /* v1.0 - v3.0 */
520 fmt
.dwMask
|= PFM_TABLE
;
521 fmt
.wEffects
&= ~PFE_TABLE
;
525 if (!info
->editor
->bEmulateVersion10
) /* v4.1 */
527 while (info
->rtfParam
> info
->nestingLevel
) {
528 RTFTable
*tableDef
= ALLOC_OBJ(RTFTable
);
529 ZeroMemory(tableDef
, sizeof(RTFTable
));
530 tableDef
->parent
= info
->tableDef
;
531 info
->tableDef
= tableDef
;
533 RTFFlushOutputBuffer(info
);
534 if (tableDef
->tableRowStart
&&
535 tableDef
->tableRowStart
->member
.para
.nFlags
& MEPF_ROWEND
)
537 ME_DisplayItem
*para
= tableDef
->tableRowStart
;
538 para
= para
->member
.para
.next_para
;
539 para
= ME_InsertTableRowStartAtParagraph(info
->editor
, para
);
540 tableDef
->tableRowStart
= para
;
544 cursor
= info
->editor
->pCursors
[0];
545 if (cursor
.nOffset
|| cursor
.pRun
->member
.run
.nCharOfs
)
546 ME_InsertTextFromCursor(info
->editor
, 0, &endl
, 1, info
->style
);
547 tableDef
->tableRowStart
= ME_InsertTableRowStartFromCursor(info
->editor
);
550 info
->nestingLevel
++;
552 info
->canInheritInTbl
= FALSE
;
557 if (!info
->editor
->bEmulateVersion10
) /* v4.1 */
559 if (info
->nestingLevel
< 1)
564 info
->tableDef
= ALLOC_OBJ(RTFTable
);
565 ZeroMemory(info
->tableDef
, sizeof(RTFTable
));
567 tableDef
= info
->tableDef
;
568 RTFFlushOutputBuffer(info
);
569 if (tableDef
->tableRowStart
&&
570 tableDef
->tableRowStart
->member
.para
.nFlags
& MEPF_ROWEND
)
572 ME_DisplayItem
*para
= tableDef
->tableRowStart
;
573 para
= para
->member
.para
.next_para
;
574 para
= ME_InsertTableRowStartAtParagraph(info
->editor
, para
);
575 tableDef
->tableRowStart
= para
;
579 cursor
= info
->editor
->pCursors
[0];
580 if (cursor
.nOffset
|| cursor
.pRun
->member
.run
.nCharOfs
)
581 ME_InsertTextFromCursor(info
->editor
, 0, &endl
, 1, info
->style
);
582 tableDef
->tableRowStart
= ME_InsertTableRowStartFromCursor(info
->editor
);
584 info
->nestingLevel
= 1;
585 info
->canInheritInTbl
= TRUE
;
588 } else { /* v1.0 - v3.0 */
589 fmt
.dwMask
|= PFM_TABLE
;
590 fmt
.wEffects
|= PFE_TABLE
;
595 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
596 fmt
.dwMask
= PFM_STARTINDENT
| PFM_OFFSET
;
597 fmt
.dxStartIndent
+= fmt
.dxOffset
+ info
->rtfParam
;
598 fmt
.dxOffset
= -info
->rtfParam
;
601 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
602 fmt
.dwMask
= PFM_STARTINDENT
;
603 fmt
.dxStartIndent
= info
->rtfParam
- fmt
.dxOffset
;
606 fmt
.dwMask
= PFM_RIGHTINDENT
;
607 fmt
.dxRightIndent
= info
->rtfParam
;
611 fmt
.dwMask
= PFM_ALIGNMENT
;
612 fmt
.wAlignment
= PFA_LEFT
;
615 fmt
.dwMask
= PFM_ALIGNMENT
;
616 fmt
.wAlignment
= PFA_RIGHT
;
619 fmt
.dwMask
= PFM_ALIGNMENT
;
620 fmt
.wAlignment
= PFA_CENTER
;
623 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
624 if (!(fmt
.dwMask
& PFM_TABSTOPS
))
628 if (fmt
.cTabCount
< MAX_TAB_STOPS
&& info
->rtfParam
< 0x1000000)
629 fmt
.rgxTabs
[fmt
.cTabCount
++] = info
->rtfParam
;
630 fmt
.dwMask
= PFM_TABSTOPS
;
633 fmt
.dwMask
= PFM_KEEP
;
634 fmt
.wEffects
= PFE_KEEP
;
636 case rtfNoWidowControl
:
637 fmt
.dwMask
= PFM_NOWIDOWCONTROL
;
638 fmt
.wEffects
= PFE_NOWIDOWCONTROL
;
641 fmt
.dwMask
= PFM_KEEPNEXT
;
642 fmt
.wEffects
= PFE_KEEPNEXT
;
645 fmt
.dwMask
= PFM_SPACEAFTER
;
646 fmt
.dySpaceAfter
= info
->rtfParam
;
649 fmt
.dwMask
= PFM_SPACEBEFORE
;
650 fmt
.dySpaceBefore
= info
->rtfParam
;
652 case rtfSpaceBetween
:
653 fmt
.dwMask
= PFM_LINESPACING
;
654 if ((int)info
->rtfParam
> 0)
656 fmt
.dyLineSpacing
= info
->rtfParam
;
657 fmt
.bLineSpacingRule
= 3;
661 fmt
.dyLineSpacing
= info
->rtfParam
;
662 fmt
.bLineSpacingRule
= 4;
664 case rtfSpaceMultiply
:
665 fmt
.dwMask
= PFM_LINESPACING
;
666 fmt
.dyLineSpacing
= info
->rtfParam
* 20;
667 fmt
.bLineSpacingRule
= 5;
670 fmt
.dwMask
= PFM_NUMBERING
;
671 fmt
.wNumbering
= PFN_BULLET
;
674 fmt
.dwMask
= PFM_NUMBERING
;
675 fmt
.wNumbering
= 2; /* FIXME: MSDN says it's not used ?? */
677 case rtfParNumDecimal
:
678 fmt
.dwMask
= PFM_NUMBERING
;
679 fmt
.wNumbering
= 2; /* FIXME: MSDN says it's not used ?? */
681 case rtfParNumIndent
:
682 fmt
.dwMask
= PFM_NUMBERINGTAB
;
683 fmt
.wNumberingTab
= info
->rtfParam
;
685 case rtfParNumStartAt
:
686 fmt
.dwMask
= PFM_NUMBERINGSTART
;
687 fmt
.wNumberingStart
= info
->rtfParam
;
690 info
->borderType
= RTFBorderParaLeft
;
691 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
692 if (!(fmt
.dwMask
& PFM_BORDER
))
694 fmt
.wBorderSpace
= 0;
695 fmt
.wBorderWidth
= 1;
699 fmt
.dwMask
= PFM_BORDER
;
702 info
->borderType
= RTFBorderParaRight
;
703 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
704 if (!(fmt
.dwMask
& PFM_BORDER
))
706 fmt
.wBorderSpace
= 0;
707 fmt
.wBorderWidth
= 1;
711 fmt
.dwMask
= PFM_BORDER
;
714 info
->borderType
= RTFBorderParaTop
;
715 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
716 if (!(fmt
.dwMask
& PFM_BORDER
))
718 fmt
.wBorderSpace
= 0;
719 fmt
.wBorderWidth
= 1;
723 fmt
.dwMask
= PFM_BORDER
;
725 case rtfBorderBottom
:
726 info
->borderType
= RTFBorderParaBottom
;
727 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
728 if (!(fmt
.dwMask
& PFM_BORDER
))
730 fmt
.wBorderSpace
= 0;
731 fmt
.wBorderWidth
= 1;
735 fmt
.dwMask
= PFM_BORDER
;
737 case rtfBorderSingle
:
738 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
739 /* we assume that borders have been created before (RTF spec) */
740 fmt
.wBorders
&= ~0x700;
741 fmt
.wBorders
|= 1 << 8;
742 fmt
.dwMask
= PFM_BORDER
;
745 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
746 /* we assume that borders have been created before (RTF spec) */
747 fmt
.wBorders
&= ~0x700;
748 fmt
.wBorders
|= 2 << 8;
749 fmt
.dwMask
= PFM_BORDER
;
751 case rtfBorderShadow
:
752 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
753 /* we assume that borders have been created before (RTF spec) */
754 fmt
.wBorders
&= ~0x700;
755 fmt
.wBorders
|= 10 << 8;
756 fmt
.dwMask
= PFM_BORDER
;
758 case rtfBorderDouble
:
759 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
760 /* we assume that borders have been created before (RTF spec) */
761 fmt
.wBorders
&= ~0x700;
762 fmt
.wBorders
|= 7 << 8;
763 fmt
.dwMask
= PFM_BORDER
;
766 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
767 /* we assume that borders have been created before (RTF spec) */
768 fmt
.wBorders
&= ~0x700;
769 fmt
.wBorders
|= 11 << 8;
770 fmt
.dwMask
= PFM_BORDER
;
774 int borderSide
= info
->borderType
& RTFBorderSideMask
;
775 RTFTable
*tableDef
= info
->tableDef
;
776 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
777 /* we assume that borders have been created before (RTF spec) */
778 fmt
.wBorderWidth
|= ((info
->rtfParam
/ 15) & 7) << 8;
779 if ((info
->borderType
& RTFBorderTypeMask
) == RTFBorderTypeCell
)
782 if (!tableDef
|| tableDef
->numCellsDefined
>= MAX_TABLE_CELLS
)
784 border
= &tableDef
->cells
[tableDef
->numCellsDefined
].border
[borderSide
];
785 border
->width
= info
->rtfParam
;
788 fmt
.dwMask
= PFM_BORDER
;
792 ME_GetSelectionParaFormat(info
->editor
, &fmt
);
793 /* we assume that borders have been created before (RTF spec) */
794 fmt
.wBorderSpace
= info
->rtfParam
;
795 fmt
.dwMask
= PFM_BORDER
;
799 RTFTable
*tableDef
= info
->tableDef
;
800 int borderSide
= info
->borderType
& RTFBorderSideMask
;
801 int borderType
= info
->borderType
& RTFBorderTypeMask
;
804 case RTFBorderTypePara
:
805 if (!info
->editor
->bEmulateVersion10
) /* v4.1 */
807 /* v1.0 - 3.0 treat paragraph and row borders the same. */
808 case RTFBorderTypeRow
:
810 tableDef
->border
[borderSide
].color
= info
->rtfParam
;
813 case RTFBorderTypeCell
:
814 if (tableDef
&& tableDef
->numCellsDefined
< MAX_TABLE_CELLS
) {
815 tableDef
->cells
[tableDef
->numCellsDefined
].border
[borderSide
].color
= info
->rtfParam
;
823 RTFFlushOutputBuffer(info
);
824 /* FIXME too slow ? how come ?*/
825 ME_SetSelectionParaFormat(info
->editor
, &fmt
);
829 void ME_RTFTblAttrHook(RTF_Info
*info
)
831 switch (info
->rtfMinor
)
835 if (!info
->editor
->bEmulateVersion10
) /* v4.1 */
836 info
->borderType
= 0; /* Not sure */
837 else /* v1.0 - 3.0 */
838 info
->borderType
= RTFBorderRowTop
;
839 if (!info
->tableDef
) {
840 info
->tableDef
= ME_MakeTableDef(info
->editor
);
842 ME_InitTableDef(info
->editor
, info
->tableDef
);
851 info
->tableDef
= ME_MakeTableDef(info
->editor
);
853 cellNum
= info
->tableDef
->numCellsDefined
;
854 if (cellNum
>= MAX_TABLE_CELLS
)
856 info
->tableDef
->cells
[cellNum
].rightBoundary
= info
->rtfParam
;
857 if (cellNum
< MAX_TAB_STOPS
) {
858 /* Tab stops were used to store cell positions before v4.1 but v4.1
859 * still seems to set the tabstops without using them. */
860 ME_DisplayItem
*para
= ME_GetParagraph(info
->editor
->pCursors
[0].pRun
);
861 PARAFORMAT2
*pFmt
= para
->member
.para
.pFmt
;
862 pFmt
->rgxTabs
[cellNum
] &= ~0x00FFFFFF;
863 pFmt
->rgxTabs
[cellNum
] = 0x00FFFFFF & info
->rtfParam
;
865 info
->tableDef
->numCellsDefined
++;
869 info
->borderType
= RTFBorderRowTop
;
872 info
->borderType
= RTFBorderRowLeft
;
874 case rtfRowBordBottom
:
875 info
->borderType
= RTFBorderRowBottom
;
877 case rtfRowBordRight
:
878 info
->borderType
= RTFBorderRowRight
;
881 info
->borderType
= RTFBorderCellTop
;
883 case rtfCellBordLeft
:
884 info
->borderType
= RTFBorderCellLeft
;
886 case rtfCellBordBottom
:
887 info
->borderType
= RTFBorderCellBottom
;
889 case rtfCellBordRight
:
890 info
->borderType
= RTFBorderCellRight
;
894 info
->tableDef
->gapH
= info
->rtfParam
;
898 info
->tableDef
->leftEdge
= info
->rtfParam
;
903 void ME_RTFSpecialCharHook(RTF_Info
*info
)
905 RTFTable
*tableDef
= info
->tableDef
;
906 switch (info
->rtfMinor
)
909 if (info
->editor
->bEmulateVersion10
) /* v1.0 - v3.0 */
911 /* else fall through since v4.1 treats rtfNestCell and rtfCell the same */
915 RTFFlushOutputBuffer(info
);
916 if (!info
->editor
->bEmulateVersion10
) { /* v4.1 */
917 if (tableDef
->tableRowStart
)
919 if (!info
->nestingLevel
&&
920 tableDef
->tableRowStart
->member
.para
.nFlags
& MEPF_ROWEND
)
922 ME_DisplayItem
*para
= tableDef
->tableRowStart
;
923 para
= para
->member
.para
.next_para
;
924 para
= ME_InsertTableRowStartAtParagraph(info
->editor
, para
);
925 tableDef
->tableRowStart
= para
;
926 info
->nestingLevel
= 1;
928 ME_InsertTableCellFromCursor(info
->editor
);
930 } else { /* v1.0 - v3.0 */
931 ME_DisplayItem
*para
= ME_GetParagraph(info
->editor
->pCursors
[0].pRun
);
932 PARAFORMAT2
*pFmt
= para
->member
.para
.pFmt
;
933 if (pFmt
->dwMask
& PFM_TABLE
&& pFmt
->wEffects
& PFE_TABLE
&&
934 tableDef
->numCellsInserted
< tableDef
->numCellsDefined
)
937 ME_InsertTextFromCursor(info
->editor
, 0, &tab
, 1, info
->style
);
938 tableDef
->numCellsInserted
++;
943 if (info
->editor
->bEmulateVersion10
) /* v1.0 - v3.0 */
945 /* else fall through since v4.1 treats rtfNestRow and rtfRow the same */
948 ME_DisplayItem
*para
, *cell
, *run
;
953 RTFFlushOutputBuffer(info
);
954 if (!info
->editor
->bEmulateVersion10
) { /* v4.1 */
955 if (!tableDef
->tableRowStart
)
957 if (!info
->nestingLevel
&&
958 tableDef
->tableRowStart
->member
.para
.nFlags
& MEPF_ROWEND
)
960 para
= tableDef
->tableRowStart
;
961 para
= para
->member
.para
.next_para
;
962 para
= ME_InsertTableRowStartAtParagraph(info
->editor
, para
);
963 tableDef
->tableRowStart
= para
;
964 info
->nestingLevel
++;
966 para
= tableDef
->tableRowStart
;
967 cell
= ME_FindItemFwd(para
, diCell
);
968 assert(cell
&& !cell
->member
.cell
.prev_cell
);
969 if (tableDef
->numCellsDefined
< 1)
971 /* 2000 twips appears to be the cell size that native richedit uses
972 * when no cell sizes are specified. */
973 const int defaultCellSize
= 2000;
974 int nRightBoundary
= defaultCellSize
;
975 cell
->member
.cell
.nRightBoundary
= nRightBoundary
;
976 while (cell
->member
.cell
.next_cell
) {
977 cell
= cell
->member
.cell
.next_cell
;
978 nRightBoundary
+= defaultCellSize
;
979 cell
->member
.cell
.nRightBoundary
= nRightBoundary
;
981 para
= ME_InsertTableCellFromCursor(info
->editor
);
982 cell
= para
->member
.para
.pCell
;
983 cell
->member
.cell
.nRightBoundary
= nRightBoundary
;
985 for (i
= 0; i
< tableDef
->numCellsDefined
; i
++)
987 RTFCell
*cellDef
= &tableDef
->cells
[i
];
988 cell
->member
.cell
.nRightBoundary
= cellDef
->rightBoundary
;
989 ME_ApplyBorderProperties(info
, &cell
->member
.cell
.border
,
991 cell
= cell
->member
.cell
.next_cell
;
994 para
= ME_InsertTableCellFromCursor(info
->editor
);
995 cell
= para
->member
.para
.pCell
;
998 /* Cell for table row delimiter is empty */
999 cell
->member
.cell
.nRightBoundary
= tableDef
->cells
[i
-1].rightBoundary
;
1002 run
= ME_FindItemFwd(cell
, diRun
);
1003 if (info
->editor
->pCursors
[0].pRun
!= run
||
1004 info
->editor
->pCursors
[0].nOffset
)
1007 /* Delete inserted cells that aren't defined. */
1008 info
->editor
->pCursors
[1].pRun
= run
;
1009 info
->editor
->pCursors
[1].nOffset
= 0;
1010 nOfs
= ME_GetCursorOfs(info
->editor
, 1);
1011 nChars
= ME_GetCursorOfs(info
->editor
, 0) - nOfs
;
1012 ME_InternalDeleteText(info
->editor
, nOfs
, nChars
, TRUE
);
1015 para
= ME_InsertTableRowEndFromCursor(info
->editor
);
1016 para
->member
.para
.pFmt
->dxOffset
= abs(info
->tableDef
->gapH
);
1017 para
->member
.para
.pFmt
->dxStartIndent
= info
->tableDef
->leftEdge
;
1018 ME_ApplyBorderProperties(info
, ¶
->member
.para
.border
,
1020 info
->nestingLevel
--;
1021 if (!info
->nestingLevel
)
1023 if (info
->canInheritInTbl
) {
1024 tableDef
->tableRowStart
= para
;
1026 while (info
->tableDef
) {
1027 tableDef
= info
->tableDef
;
1028 info
->tableDef
= tableDef
->parent
;
1029 heap_free(tableDef
);
1033 info
->tableDef
= tableDef
->parent
;
1034 heap_free(tableDef
);
1036 } else { /* v1.0 - v3.0 */
1038 ME_DisplayItem
*para
= ME_GetParagraph(info
->editor
->pCursors
[0].pRun
);
1039 PARAFORMAT2
*pFmt
= para
->member
.para
.pFmt
;
1040 pFmt
->dxOffset
= info
->tableDef
->gapH
;
1041 pFmt
->dxStartIndent
= info
->tableDef
->leftEdge
;
1043 para
= ME_GetParagraph(info
->editor
->pCursors
[0].pRun
);
1044 ME_ApplyBorderProperties(info
, ¶
->member
.para
.border
,
1046 while (tableDef
->numCellsInserted
< tableDef
->numCellsDefined
)
1049 ME_InsertTextFromCursor(info
->editor
, 0, &tab
, 1, info
->style
);
1050 tableDef
->numCellsInserted
++;
1052 pFmt
->cTabCount
= min(tableDef
->numCellsDefined
, MAX_TAB_STOPS
);
1053 if (!tableDef
->numCellsDefined
)
1054 pFmt
->wEffects
&= ~PFE_TABLE
;
1055 ME_InsertTextFromCursor(info
->editor
, 0, &endl
, 1, info
->style
);
1056 tableDef
->numCellsInserted
= 0;
1062 if (info
->editor
->bEmulateVersion10
) { /* v1.0 - 3.0 */
1063 ME_DisplayItem
*para
;
1065 RTFFlushOutputBuffer(info
);
1066 para
= ME_GetParagraph(info
->editor
->pCursors
[0].pRun
);
1067 pFmt
= para
->member
.para
.pFmt
;
1068 if (pFmt
->dwMask
& PFM_TABLE
&& pFmt
->wEffects
& PFE_TABLE
)
1070 /* rtfPar is treated like a space within a table. */
1071 info
->rtfClass
= rtfText
;
1072 info
->rtfMajor
= ' ';
1074 else if (info
->rtfMinor
== rtfPar
&& tableDef
)
1075 tableDef
->numCellsInserted
= 0;
1081 static BOOL
ME_RTFInsertOleObject(RTF_Info
*info
, HENHMETAFILE hemf
, HBITMAP hbmp
,
1084 LPOLEOBJECT lpObject
= NULL
;
1085 LPSTORAGE lpStorage
= NULL
;
1086 LPOLECLIENTSITE lpClientSite
= NULL
;
1087 LPDATAOBJECT lpDataObject
= NULL
;
1088 LPOLECACHE lpOleCache
= NULL
;
1097 stgm
.tymed
= TYMED_ENHMF
;
1098 stgm
.u
.hEnhMetaFile
= hemf
;
1099 fm
.cfFormat
= CF_ENHMETAFILE
;
1103 stgm
.tymed
= TYMED_GDI
;
1104 stgm
.u
.hBitmap
= hbmp
;
1105 fm
.cfFormat
= CF_BITMAP
;
1107 stgm
.pUnkForRelease
= NULL
;
1110 fm
.dwAspect
= DVASPECT_CONTENT
;
1112 fm
.tymed
= stgm
.tymed
;
1114 if (!info
->lpRichEditOle
)
1116 CreateIRichEditOle(info
->editor
, (VOID
**)&info
->lpRichEditOle
);
1119 if (OleCreateDefaultHandler(&CLSID_NULL
, NULL
, &IID_IOleObject
, (void**)&lpObject
) == S_OK
&&
1121 /* FIXME: enable it when rich-edit properly implements this method */
1122 IRichEditOle_GetClientSite(info
->lpRichEditOle
, &lpClientSite
) == S_OK
&&
1123 IOleObject_SetClientSite(lpObject
, lpClientSite
) == S_OK
&&
1125 IOleObject_GetUserClassID(lpObject
, &clsid
) == S_OK
&&
1126 IOleObject_QueryInterface(lpObject
, &IID_IOleCache
, (void**)&lpOleCache
) == S_OK
&&
1127 IOleCache_Cache(lpOleCache
, &fm
, 0, &conn
) == S_OK
&&
1128 IOleObject_QueryInterface(lpObject
, &IID_IDataObject
, (void**)&lpDataObject
) == S_OK
&&
1129 IDataObject_SetData(lpDataObject
, &fm
, &stgm
, TRUE
) == S_OK
)
1133 reobject
.cbStruct
= sizeof(reobject
);
1134 reobject
.cp
= REO_CP_SELECTION
;
1135 reobject
.clsid
= clsid
;
1136 reobject
.poleobj
= lpObject
;
1137 reobject
.pstg
= lpStorage
;
1138 reobject
.polesite
= lpClientSite
;
1139 /* convert from twips to .01 mm */
1140 reobject
.sizel
.cx
= MulDiv(sz
->cx
, 254, 144);
1141 reobject
.sizel
.cy
= MulDiv(sz
->cy
, 254, 144);
1142 reobject
.dvaspect
= DVASPECT_CONTENT
;
1143 reobject
.dwFlags
= 0; /* FIXME */
1144 reobject
.dwUser
= 0;
1146 /* FIXME: could be simpler */
1147 ret
= IRichEditOle_InsertObject(info
->lpRichEditOle
, &reobject
) == S_OK
;
1150 if (lpObject
) IOleObject_Release(lpObject
);
1151 if (lpClientSite
) IOleClientSite_Release(lpClientSite
);
1152 if (lpStorage
) IStorage_Release(lpStorage
);
1153 if (lpDataObject
) IDataObject_Release(lpDataObject
);
1154 if (lpOleCache
) IOleCache_Release(lpOleCache
);
1159 static void ME_RTFReadPictGroup(RTF_Info
*info
)
1162 BYTE
* buffer
= NULL
;
1163 unsigned bufsz
, bufidx
;
1169 enum gfxkind
{gfx_unknown
= 0, gfx_enhmetafile
, gfx_metafile
, gfx_dib
} gfx
= gfx_unknown
;
1172 if (info
->rtfClass
== rtfEOF
)
1175 /* fetch picture type */
1176 if (RTFCheckMM (info
, rtfPictAttr
, rtfWinMetafile
))
1178 mfp
.mm
= info
->rtfParam
;
1181 else if (RTFCheckMM (info
, rtfPictAttr
, rtfDevIndBitmap
))
1183 if (info
->rtfParam
!= 0) FIXME("dibitmap should be 0 (%d)\n", info
->rtfParam
);
1186 else if (RTFCheckMM (info
, rtfPictAttr
, rtfEmfBlip
))
1188 gfx
= gfx_enhmetafile
;
1192 FIXME("%d %d\n", info
->rtfMajor
, info
->rtfMinor
);
1196 /* fetch picture attributes */
1200 if (info
->rtfClass
== rtfEOF
)
1202 if (info
->rtfClass
== rtfText
)
1204 if (!RTFCheckCM (info
, rtfControl
, rtfPictAttr
))
1206 ERR("Expected picture attribute (%d %d)\n",
1207 info
->rtfClass
, info
->rtfMajor
);
1210 else if (RTFCheckMM (info
, rtfPictAttr
, rtfPicWid
))
1212 if (gfx
== gfx_metafile
) mfp
.xExt
= info
->rtfParam
;
1214 else if (RTFCheckMM (info
, rtfPictAttr
, rtfPicHt
))
1216 if (gfx
== gfx_metafile
) mfp
.yExt
= info
->rtfParam
;
1218 else if (RTFCheckMM (info
, rtfPictAttr
, rtfPicGoalWid
))
1219 sz
.cx
= info
->rtfParam
;
1220 else if (RTFCheckMM (info
, rtfPictAttr
, rtfPicGoalHt
))
1221 sz
.cy
= info
->rtfParam
;
1223 FIXME("Non supported attribute: %d %d %d\n", info
->rtfClass
, info
->rtfMajor
, info
->rtfMinor
);
1225 /* fetch picture data */
1228 buffer
= HeapAlloc(GetProcessHeap(), 0, bufsz
);
1229 val
= info
->rtfMajor
;
1230 for (flip
= TRUE
;; flip
= !flip
)
1233 if (info
->rtfClass
== rtfEOF
)
1235 HeapFree(GetProcessHeap(), 0, buffer
);
1236 return; /* Warn ?? */
1238 if (RTFCheckCM(info
, rtfGroup
, rtfEndGroup
))
1240 if (info
->rtfClass
!= rtfText
) goto skip_group
;
1243 if (bufidx
>= bufsz
&&
1244 !(buffer
= HeapReAlloc(GetProcessHeap(), 0, buffer
, bufsz
+= 1024)))
1246 buffer
[bufidx
++] = RTFCharToHex(val
) * 16 + RTFCharToHex(info
->rtfMajor
);
1249 val
= info
->rtfMajor
;
1251 if (flip
) FIXME("wrong hex string\n");
1255 case gfx_enhmetafile
:
1256 if ((hemf
= SetEnhMetaFileBits(bufidx
, buffer
)))
1257 ME_RTFInsertOleObject(info
, hemf
, NULL
, &sz
);
1260 if ((hemf
= SetWinMetaFileBits(bufidx
, buffer
, NULL
, &mfp
)))
1261 ME_RTFInsertOleObject(info
, hemf
, NULL
, &sz
);
1265 BITMAPINFO
* bi
= (BITMAPINFO
*)buffer
;
1267 unsigned nc
= bi
->bmiHeader
.biClrUsed
;
1269 /* not quite right, especially for bitfields type of compression */
1270 if (!nc
&& bi
->bmiHeader
.biBitCount
<= 8)
1271 nc
= 1 << bi
->bmiHeader
.biBitCount
;
1272 if ((hbmp
= CreateDIBitmap(hdc
, &bi
->bmiHeader
,
1273 CBM_INIT
, (char*)(bi
+ 1) + nc
* sizeof(RGBQUAD
),
1274 bi
, DIB_RGB_COLORS
)))
1275 ME_RTFInsertOleObject(info
, NULL
, hbmp
, &sz
);
1282 HeapFree(GetProcessHeap(), 0, buffer
);
1283 RTFRouteToken (info
); /* feed "}" back to router */
1286 HeapFree(GetProcessHeap(), 0, buffer
);
1288 RTFRouteToken(info
); /* feed "}" back to router */
1291 /* for now, lookup the \result part and use it, whatever the object */
1292 static void ME_RTFReadObjectGroup(RTF_Info
*info
)
1297 if (info
->rtfClass
== rtfEOF
)
1299 if (RTFCheckCM(info
, rtfGroup
, rtfEndGroup
))
1301 if (RTFCheckCM(info
, rtfGroup
, rtfBeginGroup
))
1304 if (info
->rtfClass
== rtfEOF
)
1306 if (RTFCheckCMM(info
, rtfControl
, rtfDestination
, rtfObjResult
))
1310 while (RTFGetToken (info
) != rtfEOF
)
1312 if (info
->rtfClass
== rtfGroup
)
1314 if (info
->rtfMajor
== rtfBeginGroup
) level
++;
1315 else if (info
->rtfMajor
== rtfEndGroup
&& --level
< 0) break;
1317 RTFRouteToken(info
);
1320 else RTFSkipGroup(info
);
1323 if (!RTFCheckCM (info
, rtfControl
, rtfObjAttr
))
1325 FIXME("Non supported attribute: %d %d %d\n", info
->rtfClass
, info
->rtfMajor
, info
->rtfMinor
);
1329 RTFRouteToken(info
); /* feed "}" back to router */
1332 static void ME_RTFReadHook(RTF_Info
*info
)
1334 switch(info
->rtfClass
)
1337 switch(info
->rtfMajor
)
1340 if (info
->stackTop
< maxStack
) {
1341 info
->stack
[info
->stackTop
].fmt
= info
->style
->fmt
;
1342 info
->stack
[info
->stackTop
].codePage
= info
->codePage
;
1343 info
->stack
[info
->stackTop
].unicodeLength
= info
->unicodeLength
;
1346 info
->styleChanged
= FALSE
;
1351 RTFFlushOutputBuffer(info
);
1353 if (info
->stackTop
<=0) {
1354 info
->rtfClass
= rtfEOF
;
1357 assert(info
->stackTop
>= 0);
1358 if (info
->styleChanged
)
1360 /* FIXME too slow ? how come ? */
1361 s
= ME_ApplyStyle(info
->style
, &info
->stack
[info
->stackTop
].fmt
);
1362 ME_ReleaseStyle(info
->style
);
1364 info
->codePage
= info
->stack
[info
->stackTop
].codePage
;
1365 info
->unicodeLength
= info
->stack
[info
->stackTop
].unicodeLength
;
1375 ME_StreamInFill(ME_InStream
*stream
)
1377 stream
->editstream
->dwError
= stream
->editstream
->pfnCallback(stream
->editstream
->dwCookie
,
1378 (BYTE
*)stream
->buffer
,
1379 sizeof(stream
->buffer
),
1380 (LONG
*)&stream
->dwSize
);
1384 static LRESULT
ME_StreamIn(ME_TextEditor
*editor
, DWORD format
, EDITSTREAM
*stream
, BOOL stripLastCR
)
1388 int from
, to
, to2
, nUndoMode
;
1389 int nEventMask
= editor
->nEventMask
;
1390 ME_InStream inStream
;
1391 BOOL invalidRTF
= FALSE
;
1393 TRACE("stream==%p hWnd==%p format==0x%X\n", stream
, editor
->hWnd
, format
);
1394 editor
->nEventMask
= 0;
1396 ME_GetSelection(editor
, &from
, &to
);
1397 if ((format
& SFF_SELECTION
) && (editor
->mode
& TM_RICHTEXT
)) {
1398 style
= ME_GetSelectionInsertStyle(editor
);
1400 ME_InternalDeleteText(editor
, from
, to
-from
, FALSE
);
1402 /* Don't insert text at the end of the table row */
1403 if (!editor
->bEmulateVersion10
) { /* v4.1 */
1404 ME_DisplayItem
*para
= ME_GetParagraph(editor
->pCursors
->pRun
);
1405 if (para
->member
.para
.nFlags
& MEPF_ROWEND
)
1407 para
= para
->member
.para
.next_para
;
1408 editor
->pCursors
[0].pRun
= ME_FindItemFwd(para
, diRun
);
1409 editor
->pCursors
[0].nOffset
= 0;
1411 if (para
->member
.para
.nFlags
& MEPF_ROWSTART
)
1413 para
= para
->member
.para
.next_para
;
1414 editor
->pCursors
[0].pRun
= ME_FindItemFwd(para
, diRun
);
1415 editor
->pCursors
[0].nOffset
= 0;
1417 editor
->pCursors
[1] = editor
->pCursors
[0];
1418 } else { /* v1.0 - 3.0 */
1419 if (editor
->pCursors
[0].pRun
->member
.run
.nFlags
& MERF_ENDPARA
&&
1420 ME_IsInTable(editor
->pCursors
[0].pRun
))
1425 ME_DisplayItem
*para_item
;
1426 style
= editor
->pBuffer
->pDefaultStyle
;
1427 ME_AddRefStyle(style
);
1428 SendMessageA(editor
->hWnd
, EM_SETSEL
, 0, 0);
1429 ME_InternalDeleteText(editor
, 0, ME_GetTextLength(editor
), FALSE
);
1431 ME_ClearTempStyle(editor
);
1433 para_item
= ME_GetParagraph(editor
->pCursors
[0].pRun
);
1434 ME_SetDefaultParaFormat(para_item
->member
.para
.pFmt
);
1438 /* Back up undo mode to a local variable */
1439 nUndoMode
= editor
->nUndoMode
;
1441 /* Only create an undo if SFF_SELECTION is set */
1442 if (!(format
& SFF_SELECTION
))
1443 editor
->nUndoMode
= umIgnore
;
1445 inStream
.editstream
= stream
;
1446 inStream
.editstream
->dwError
= 0;
1447 inStream
.dwSize
= 0;
1448 inStream
.dwUsed
= 0;
1450 if (format
& SF_RTF
)
1452 /* Check if it's really RTF, and if it is not, use plain text */
1453 ME_StreamInFill(&inStream
);
1454 if (!inStream
.editstream
->dwError
)
1456 if ((!editor
->bEmulateVersion10
&& strncmp(inStream
.buffer
, "{\\rtf", 5) && strncmp(inStream
.buffer
, "{\\urtf", 6))
1457 || (editor
->bEmulateVersion10
&& *inStream
.buffer
!= '{'))
1460 inStream
.editstream
->dwError
= -16;
1465 if (!invalidRTF
&& !inStream
.editstream
->dwError
)
1467 if (format
& SF_RTF
) {
1468 /* setup the RTF parser */
1469 memset(&parser
, 0, sizeof parser
);
1470 RTFSetEditStream(&parser
, &inStream
);
1471 parser
.rtfFormat
= format
&(SF_TEXT
|SF_RTF
);
1472 parser
.hwndEdit
= editor
->hWnd
;
1473 parser
.editor
= editor
;
1474 parser
.style
= style
;
1475 WriterInit(&parser
);
1477 RTFSetReadHook(&parser
, ME_RTFReadHook
);
1478 RTFSetDestinationCallback(&parser
, rtfPict
, ME_RTFReadPictGroup
);
1479 RTFSetDestinationCallback(&parser
, rtfObject
, ME_RTFReadObjectGroup
);
1480 if (!parser
.editor
->bEmulateVersion10
) /* v4.1 */
1482 RTFSetDestinationCallback(&parser
, rtfNoNestTables
, RTFSkipGroup
);
1483 RTFSetDestinationCallback(&parser
, rtfNestTableProps
, RTFReadGroup
);
1487 /* do the parsing */
1489 RTFFlushOutputBuffer(&parser
);
1490 if (!editor
->bEmulateVersion10
) { /* v4.1 */
1491 if (parser
.tableDef
&& parser
.tableDef
->tableRowStart
&&
1492 (parser
.nestingLevel
> 0 || parser
.canInheritInTbl
))
1494 /* Delete any incomplete table row at the end of the rich text. */
1496 ME_DisplayItem
*pCell
;
1497 ME_DisplayItem
*para
;
1499 parser
.rtfMinor
= rtfRow
;
1500 /* Complete the table row before deleting it.
1501 * By doing it this way we will have the current paragraph format set
1502 * properly to reflect that is not in the complete table, and undo items
1503 * will be added for this change to the current paragraph format. */
1504 if (parser
.nestingLevel
> 0)
1506 while (parser
.nestingLevel
> 1)
1507 ME_RTFSpecialCharHook(&parser
); /* Decrements nestingLevel */
1508 para
= parser
.tableDef
->tableRowStart
;
1509 ME_RTFSpecialCharHook(&parser
);
1511 para
= parser
.tableDef
->tableRowStart
;
1512 ME_RTFSpecialCharHook(&parser
);
1513 assert(para
->member
.para
.nFlags
& MEPF_ROWEND
);
1514 para
= para
->member
.para
.next_para
;
1516 pCell
= para
->member
.para
.pCell
;
1518 editor
->pCursors
[1].pRun
= ME_FindItemFwd(para
, diRun
);
1519 editor
->pCursors
[1].nOffset
= 0;
1520 nOfs
= ME_GetCursorOfs(editor
, 1);
1521 nChars
= ME_GetCursorOfs(editor
, 0) - nOfs
;
1522 ME_InternalDeleteText(editor
, nOfs
, nChars
, TRUE
);
1523 if (parser
.tableDef
)
1524 parser
.tableDef
->tableRowStart
= NULL
;
1527 ME_CheckTablesForCorruption(editor
);
1528 RTFDestroy(&parser
);
1529 if (parser
.lpRichEditOle
)
1530 IRichEditOle_Release(parser
.lpRichEditOle
);
1532 if (!inStream
.editstream
->dwError
&& parser
.stackTop
> 0)
1533 inStream
.editstream
->dwError
= HRESULT_FROM_WIN32(ERROR_HANDLE_EOF
);
1535 /* Remove last line break, as mandated by tests. This is not affected by
1536 CR/LF counters, since RTF streaming presents only \para tokens, which
1537 are converted according to the standard rules: \r for 2.0, \r\n for 1.0
1541 ME_GetSelection(editor
, &newfrom
, &newto
);
1542 if (newto
> to
+ (editor
->bEmulateVersion10
? 1 : 0)) {
1543 WCHAR lastchar
[3] = {'\0', '\0'};
1544 int linebreakSize
= editor
->bEmulateVersion10
? 2 : 1;
1546 ME_GetTextW(editor
, lastchar
, newto
- linebreakSize
, linebreakSize
, 0);
1547 if (lastchar
[0] == '\r' && (lastchar
[1] == '\n' || lastchar
[1] == '\0')) {
1548 ME_InternalDeleteText(editor
, newto
- linebreakSize
, linebreakSize
, FALSE
);
1553 style
= parser
.style
;
1555 else if (format
& SF_TEXT
)
1556 ME_StreamInText(editor
, format
, &inStream
, style
);
1558 ERR("EM_STREAMIN without SF_TEXT or SF_RTF\n");
1559 ME_GetSelection(editor
, &to
, &to2
);
1560 /* put the cursor at the top */
1561 if (!(format
& SFF_SELECTION
))
1562 SendMessageA(editor
->hWnd
, EM_SETSEL
, 0, 0);
1565 /* Restore saved undo mode */
1566 editor
->nUndoMode
= nUndoMode
;
1568 /* even if we didn't add an undo, we need to commit anything on the stack */
1569 ME_CommitUndo(editor
);
1571 /* If SFF_SELECTION isn't set, delete any undos from before we started too */
1572 if (!(format
& SFF_SELECTION
))
1573 ME_EmptyUndoStack(editor
);
1575 ME_ReleaseStyle(style
);
1576 editor
->nEventMask
= nEventMask
;
1577 ME_UpdateRepaint(editor
);
1578 if (!(format
& SFF_SELECTION
)) {
1579 ME_ClearTempStyle(editor
);
1581 HideCaret(editor
->hWnd
);
1582 ME_MoveCaret(editor
);
1583 ShowCaret(editor
->hWnd
);
1584 ME_SendSelChange(editor
);
1585 ME_SendRequestResize(editor
, FALSE
);
1591 typedef struct tagME_RTFStringStreamStruct
1596 } ME_RTFStringStreamStruct
;
1598 static DWORD CALLBACK
ME_ReadFromRTFString(DWORD_PTR dwCookie
, LPBYTE lpBuff
, LONG cb
, LONG
*pcb
)
1600 ME_RTFStringStreamStruct
*pStruct
= (ME_RTFStringStreamStruct
*)dwCookie
;
1603 count
= min(cb
, pStruct
->length
- pStruct
->pos
);
1604 memmove(lpBuff
, pStruct
->string
+ pStruct
->pos
, count
);
1605 pStruct
->pos
+= count
;
1611 ME_StreamInRTFString(ME_TextEditor
*editor
, BOOL selection
, char *string
)
1614 ME_RTFStringStreamStruct data
;
1616 data
.string
= string
;
1617 data
.length
= strlen(string
);
1619 es
.dwCookie
= (DWORD
)&data
;
1620 es
.pfnCallback
= ME_ReadFromRTFString
;
1621 ME_StreamIn(editor
, SF_RTF
| (selection
? SFF_SELECTION
: 0), &es
, FALSE
);
1626 ME_FindItemAtOffset(ME_TextEditor
*editor
, ME_DIType nItemType
, int nOffset
, int *nItemOffset
)
1628 ME_DisplayItem
*item
= ME_FindItemFwd(editor
->pBuffer
->pFirst
, diParagraph
);
1631 while (item
&& item
->member
.para
.next_para
->member
.para
.nCharOfs
<= nOffset
)
1632 item
= ME_FindItemFwd(item
, diParagraph
);
1637 nOffset
-= item
->member
.para
.nCharOfs
;
1638 if (nItemType
== diParagraph
) {
1640 *nItemOffset
= nOffset
;
1645 item
= ME_FindItemFwd(item
, diRun
);
1646 runLength
= ME_StrLen(item
->member
.run
.strText
);
1647 if (item
->member
.run
.nFlags
& MERF_ENDPARA
)
1648 runLength
= item
->member
.run
.nCR
+ item
->member
.run
.nLF
;
1649 } while (item
&& (item
->member
.run
.nCharOfs
+ runLength
<= nOffset
));
1651 nOffset
-= item
->member
.run
.nCharOfs
;
1653 /* Special case: nOffset may not point exactly at the division between the
1654 \r and the \n in 1.0 emulation. If such a case happens, it is sent
1655 into the next run, if one exists
1657 if ( item
->member
.run
.nFlags
& MERF_ENDPARA
1658 && nOffset
== item
->member
.run
.nCR
1659 && item
->member
.run
.nLF
> 0) {
1660 ME_DisplayItem
*nextItem
;
1661 nextItem
= ME_FindItemFwd(item
, diRun
);
1668 *nItemOffset
= nOffset
;
1675 ME_FindText(ME_TextEditor
*editor
, DWORD flags
, const CHARRANGE
*chrg
, const WCHAR
*text
, CHARRANGE
*chrgText
)
1677 const int nLen
= lstrlenW(text
);
1678 const int nTextLen
= ME_GetTextLength(editor
);
1681 ME_DisplayItem
*item
;
1682 ME_DisplayItem
*para
;
1683 WCHAR wLastChar
= ' ';
1685 TRACE("flags==0x%08x, chrg->cpMin==%d, chrg->cpMax==%d text==%s\n",
1686 flags
, chrg
->cpMin
, chrg
->cpMax
, debugstr_w(text
));
1688 if (flags
& ~(FR_DOWN
| FR_MATCHCASE
| FR_WHOLEWORD
))
1689 FIXME("Flags 0x%08x not implemented\n",
1690 flags
& ~(FR_DOWN
| FR_MATCHCASE
| FR_WHOLEWORD
));
1693 if (chrg
->cpMax
== -1)
1696 nMax
= chrg
->cpMax
> nTextLen
? nTextLen
: chrg
->cpMax
;
1698 /* In 1.0 emulation, if cpMax reaches end of text, add the FR_DOWN flag */
1699 if (editor
->bEmulateVersion10
&& nMax
== nTextLen
)
1704 /* In 1.0 emulation, cpMin must always be no greater than cpMax */
1705 if (editor
->bEmulateVersion10
&& nMax
< nMin
)
1709 chrgText
->cpMin
= -1;
1710 chrgText
->cpMax
= -1;
1715 /* when searching up, if cpMin < cpMax, then instead of searching
1716 * on [cpMin,cpMax], we search on [0,cpMin], otherwise, search on
1717 * [cpMax, cpMin]. The exception is when cpMax is -1, in which
1718 * case, it is always bigger than cpMin.
1720 if (!editor
->bEmulateVersion10
&& !(flags
& FR_DOWN
))
1724 nMax
= nMin
> nTextLen
? nTextLen
: nMin
;
1725 if (nMin
< nSwap
|| chrg
->cpMax
== -1)
1731 if (!nLen
|| nMin
< 0 || nMax
< 0 || nMax
< nMin
)
1734 chrgText
->cpMin
= chrgText
->cpMax
= -1;
1738 if (flags
& FR_DOWN
) /* Forward search */
1740 /* If possible, find the character before where the search starts */
1741 if ((flags
& FR_WHOLEWORD
) && nMin
)
1744 item
= ME_FindItemAtOffset(editor
, diRun
, nStart
, &nStart
);
1748 chrgText
->cpMin
= chrgText
->cpMax
= -1;
1751 wLastChar
= item
->member
.run
.strText
->szData
[nStart
];
1755 item
= ME_FindItemAtOffset(editor
, diRun
, nStart
, &nStart
);
1759 chrgText
->cpMin
= chrgText
->cpMax
= -1;
1763 para
= ME_GetParagraph(item
);
1765 && para
->member
.para
.nCharOfs
+ item
->member
.run
.nCharOfs
+ nStart
+ nLen
<= nMax
)
1767 ME_DisplayItem
*pCurItem
= item
;
1768 int nCurStart
= nStart
;
1771 while (pCurItem
&& ME_CharCompare(pCurItem
->member
.run
.strText
->szData
[nCurStart
+ nMatched
], text
[nMatched
], (flags
& FR_MATCHCASE
)))
1773 if ((flags
& FR_WHOLEWORD
) && isalnumW(wLastChar
))
1777 if (nMatched
== nLen
)
1779 ME_DisplayItem
*pNextItem
= pCurItem
;
1780 int nNextStart
= nCurStart
;
1783 /* Check to see if next character is a whitespace */
1784 if (flags
& FR_WHOLEWORD
)
1786 if (nCurStart
+ nMatched
== ME_StrLen(pCurItem
->member
.run
.strText
))
1788 pNextItem
= ME_FindItemFwd(pCurItem
, diRun
);
1789 nNextStart
= -nMatched
;
1793 wNextChar
= pNextItem
->member
.run
.strText
->szData
[nNextStart
+ nMatched
];
1797 if (isalnumW(wNextChar
))
1801 nStart
+= para
->member
.para
.nCharOfs
+ item
->member
.run
.nCharOfs
;
1804 chrgText
->cpMin
= nStart
;
1805 chrgText
->cpMax
= nStart
+ nLen
;
1807 TRACE("found at %d-%d\n", nStart
, nStart
+ nLen
);
1810 if (nCurStart
+ nMatched
== ME_StrLen(pCurItem
->member
.run
.strText
))
1812 pCurItem
= ME_FindItemFwd(pCurItem
, diRun
);
1813 para
= ME_GetParagraph(pCurItem
);
1814 nCurStart
= -nMatched
;
1818 wLastChar
= pCurItem
->member
.run
.strText
->szData
[nCurStart
+ nMatched
];
1823 if (nStart
== ME_StrLen(item
->member
.run
.strText
))
1825 item
= ME_FindItemFwd(item
, diRun
);
1826 para
= ME_GetParagraph(item
);
1831 else /* Backward search */
1833 /* If possible, find the character after where the search ends */
1834 if ((flags
& FR_WHOLEWORD
) && nMax
< nTextLen
- 1)
1837 item
= ME_FindItemAtOffset(editor
, diRun
, nEnd
, &nEnd
);
1841 chrgText
->cpMin
= chrgText
->cpMax
= -1;
1844 wLastChar
= item
->member
.run
.strText
->szData
[nEnd
];
1848 item
= ME_FindItemAtOffset(editor
, diRun
, nEnd
, &nEnd
);
1852 chrgText
->cpMin
= chrgText
->cpMax
= -1;
1856 para
= ME_GetParagraph(item
);
1859 && para
->member
.para
.nCharOfs
+ item
->member
.run
.nCharOfs
+ nEnd
- nLen
>= nMin
)
1861 ME_DisplayItem
*pCurItem
= item
;
1865 if (nCurEnd
- nMatched
== 0)
1867 pCurItem
= ME_FindItemBack(pCurItem
, diRun
);
1868 para
= ME_GetParagraph(pCurItem
);
1869 nCurEnd
= ME_StrLen(pCurItem
->member
.run
.strText
) + nMatched
;
1872 while (pCurItem
&& ME_CharCompare(pCurItem
->member
.run
.strText
->szData
[nCurEnd
- nMatched
- 1], text
[nLen
- nMatched
- 1], (flags
& FR_MATCHCASE
)))
1874 if ((flags
& FR_WHOLEWORD
) && isalnumW(wLastChar
))
1878 if (nMatched
== nLen
)
1880 ME_DisplayItem
*pPrevItem
= pCurItem
;
1881 int nPrevEnd
= nCurEnd
;
1884 /* Check to see if previous character is a whitespace */
1885 if (flags
& FR_WHOLEWORD
)
1887 if (nPrevEnd
- nMatched
== 0)
1889 pPrevItem
= ME_FindItemBack(pCurItem
, diRun
);
1891 nPrevEnd
= ME_StrLen(pPrevItem
->member
.run
.strText
) + nMatched
;
1895 wPrevChar
= pPrevItem
->member
.run
.strText
->szData
[nPrevEnd
- nMatched
- 1];
1899 if (isalnumW(wPrevChar
))
1903 nStart
= para
->member
.para
.nCharOfs
+ pCurItem
->member
.run
.nCharOfs
+ nCurEnd
- nMatched
;
1906 chrgText
->cpMin
= nStart
;
1907 chrgText
->cpMax
= nStart
+ nLen
;
1909 TRACE("found at %d-%d\n", nStart
, nStart
+ nLen
);
1912 if (nCurEnd
- nMatched
== 0)
1914 pCurItem
= ME_FindItemBack(pCurItem
, diRun
);
1915 /* Don't care about pCurItem becoming NULL here; it's already taken
1916 * care of in the exterior loop condition */
1917 para
= ME_GetParagraph(pCurItem
);
1918 nCurEnd
= ME_StrLen(pCurItem
->member
.run
.strText
) + nMatched
;
1922 wLastChar
= pCurItem
->member
.run
.strText
->szData
[nCurEnd
- nMatched
- 1];
1929 item
= ME_FindItemBack(item
, diRun
);
1930 para
= ME_GetParagraph(item
);
1931 nEnd
= ME_StrLen(item
->member
.run
.strText
);
1935 TRACE("not found\n");
1937 chrgText
->cpMin
= chrgText
->cpMax
= -1;
1941 /* helper to send a msg filter notification */
1943 ME_FilterEvent(ME_TextEditor
*editor
, UINT msg
, WPARAM
* wParam
, LPARAM
* lParam
)
1947 msgf
.nmhdr
.hwndFrom
= editor
->hWnd
;
1948 msgf
.nmhdr
.idFrom
= GetWindowLongW(editor
->hWnd
, GWLP_ID
);
1949 msgf
.nmhdr
.code
= EN_MSGFILTER
;
1952 msgf
.wParam
= *wParam
;
1953 msgf
.lParam
= *lParam
;
1954 if (SendMessageW(GetParent(editor
->hWnd
), WM_NOTIFY
, msgf
.nmhdr
.idFrom
, (LPARAM
)&msgf
))
1956 *wParam
= msgf
.wParam
;
1957 *lParam
= msgf
.lParam
;
1958 msgf
.wParam
= *wParam
;
1964 ME_KeyDown(ME_TextEditor
*editor
, WORD nKey
)
1966 BOOL ctrl_is_down
= GetKeyState(VK_CONTROL
) & 0x8000;
1967 BOOL shift_is_down
= GetKeyState(VK_SHIFT
) & 0x8000;
1969 if (nKey
!= VK_SHIFT
&& nKey
!= VK_CONTROL
&& nKey
!= VK_MENU
)
1970 editor
->nSelectionType
= stPosition
;
1978 editor
->nUDArrowX
= -1;
1984 ME_CommitUndo(editor
); /* End coalesced undos for typed characters */
1985 ME_ArrowKey(editor
, nKey
, shift_is_down
, ctrl_is_down
);
1989 editor
->nUDArrowX
= -1;
1990 /* FIXME backspace and delete aren't the same, they act different wrt paragraph style of the merged paragraph */
1991 if (GetWindowLongW(editor
->hWnd
, GWL_STYLE
) & ES_READONLY
)
1993 if (ME_IsSelection(editor
))
1995 ME_DeleteSelection(editor
);
1996 ME_CommitUndo(editor
);
1998 else if (nKey
== VK_DELETE
)
2000 /* Delete stops group typing.
2001 * (See MSDN remarks on EM_STOPGROUPTYPING message) */
2002 ME_DeleteTextAtCursor(editor
, 1, 1);
2003 ME_CommitUndo(editor
);
2005 else if (ME_ArrowKey(editor
, VK_LEFT
, FALSE
, FALSE
))
2007 BOOL bDeletionSucceeded
;
2008 /* Backspace can be grouped for a single undo */
2009 ME_ContinueCoalescingTransaction(editor
);
2010 bDeletionSucceeded
= ME_DeleteTextAtCursor(editor
, 1, 1);
2011 if (!bDeletionSucceeded
&& !editor
->bEmulateVersion10
) { /* v4.1 */
2012 /* Deletion was prevented so the cursor is moved back to where it was.
2013 * (e.g. this happens when trying to delete cell boundaries)
2015 ME_ArrowKey(editor
, VK_RIGHT
, FALSE
, FALSE
);
2017 ME_CommitCoalescingUndo(editor
);
2021 ME_MoveCursorFromTableRowStartParagraph(editor
);
2022 ME_UpdateSelectionLinkAttribute(editor
);
2023 ME_UpdateRepaint(editor
);
2024 ME_SendRequestResize(editor
, FALSE
);
2028 if (nKey
!= VK_SHIFT
&& nKey
!= VK_CONTROL
&& nKey
&& nKey
!= VK_MENU
)
2029 editor
->nUDArrowX
= -1;
2036 chf
.cbSize
= sizeof(chf
);
2038 ME_GetSelectionCharFormat(editor
, &chf
);
2039 ME_DumpStyleToBuf(&chf
, buf
);
2040 MessageBoxA(NULL
, buf
, "Style dump", MB_OK
);
2044 ME_CheckCharOffsets(editor
);
2051 /* Process the message and calculate the new click count.
2053 * returns: The click count if it is mouse down event, else returns 0. */
2054 static int ME_CalculateClickCount(HWND hWnd
, UINT msg
, WPARAM wParam
,
2057 static int clickNum
= 0;
2058 if (msg
< WM_MOUSEFIRST
|| msg
> WM_MOUSELAST
)
2061 if ((msg
== WM_LBUTTONDBLCLK
) ||
2062 (msg
== WM_RBUTTONDBLCLK
) ||
2063 (msg
== WM_MBUTTONDBLCLK
) ||
2064 (msg
== WM_XBUTTONDBLCLK
))
2066 msg
-= (WM_LBUTTONDBLCLK
- WM_LBUTTONDOWN
);
2069 if ((msg
== WM_LBUTTONDOWN
) ||
2070 (msg
== WM_RBUTTONDOWN
) ||
2071 (msg
== WM_MBUTTONDOWN
) ||
2072 (msg
== WM_XBUTTONDOWN
))
2074 static MSG prevClickMsg
;
2076 clickMsg
.hwnd
= hWnd
;
2077 clickMsg
.message
= msg
;
2078 clickMsg
.wParam
= wParam
;
2079 clickMsg
.lParam
= lParam
;
2080 clickMsg
.time
= GetMessageTime();
2081 clickMsg
.pt
.x
= (short)LOWORD(lParam
);
2082 clickMsg
.pt
.y
= (short)HIWORD(lParam
);
2083 if ((clickNum
!= 0) &&
2084 (clickMsg
.message
== prevClickMsg
.message
) &&
2085 (clickMsg
.hwnd
== prevClickMsg
.hwnd
) &&
2086 (clickMsg
.wParam
== prevClickMsg
.wParam
) &&
2087 (clickMsg
.time
- prevClickMsg
.time
< GetDoubleClickTime()) &&
2088 (abs(clickMsg
.pt
.x
- prevClickMsg
.pt
.x
) < GetSystemMetrics(SM_CXDOUBLECLK
)/2) &&
2089 (abs(clickMsg
.pt
.y
- prevClickMsg
.pt
.y
) < GetSystemMetrics(SM_CYDOUBLECLK
)/2))
2095 prevClickMsg
= clickMsg
;
2102 static BOOL
ME_SetCursor(ME_TextEditor
*editor
)
2108 DWORD messagePos
= GetMessagePos();
2109 pt
.x
= (short)LOWORD(messagePos
);
2110 pt
.y
= (short)HIWORD(messagePos
);
2112 sbi
.cbSize
= sizeof(sbi
);
2113 GetScrollBarInfo(editor
->hWnd
, OBJID_HSCROLL
, &sbi
);
2114 if (!(sbi
.rgstate
[0] & (STATE_SYSTEM_INVISIBLE
|STATE_SYSTEM_OFFSCREEN
)) &&
2115 PtInRect(&sbi
.rcScrollBar
, pt
))
2117 SetCursor(LoadCursorW(NULL
, (WCHAR
*)IDC_ARROW
));
2120 sbi
.cbSize
= sizeof(sbi
);
2121 GetScrollBarInfo(editor
->hWnd
, OBJID_VSCROLL
, &sbi
);
2122 if (!(sbi
.rgstate
[0] & (STATE_SYSTEM_INVISIBLE
|STATE_SYSTEM_OFFSCREEN
)) &&
2123 PtInRect(&sbi
.rcScrollBar
, pt
))
2125 SetCursor(LoadCursorW(NULL
, (WCHAR
*)IDC_ARROW
));
2128 ScreenToClient(editor
->hWnd
, &pt
);
2130 if ((GetWindowLongW(editor
->hWnd
, GWL_STYLE
) & ES_SELECTIONBAR
) &&
2131 (pt
.x
< editor
->selofs
||
2132 (editor
->nSelectionType
== stLine
&& GetCapture() == editor
->hWnd
)))
2137 offset
= ME_CharFromPos(editor
, pt
.x
, pt
.y
, &isExact
);
2140 if (editor
->AutoURLDetect_bEnable
)
2144 ME_CursorFromCharOfs(editor
, offset
, &cursor
);
2145 run
= &cursor
.pRun
->member
.run
;
2146 if (editor
->AutoURLDetect_bEnable
&&
2147 run
->style
->fmt
.dwMask
& CFM_LINK
&&
2148 run
->style
->fmt
.dwEffects
& CFE_LINK
)
2150 SetCursor(LoadCursorW(NULL
, (WCHAR
*)IDC_HAND
));
2154 if (ME_IsSelection(editor
))
2156 int selStart
, selEnd
;
2157 ME_GetSelection(editor
, &selStart
, &selEnd
);
2158 if (selStart
<= offset
&& selEnd
>= offset
) {
2159 SetCursor(LoadCursorW(NULL
, (WCHAR
*)IDC_ARROW
));
2164 SetCursor(LoadCursorW(NULL
, (WCHAR
*)IDC_IBEAM
));
2168 static BOOL
ME_ShowContextMenu(ME_TextEditor
*editor
, int x
, int y
)
2173 if(!editor
->lpOleCallback
)
2175 ME_GetSelection(editor
, &selrange
.cpMin
, &selrange
.cpMax
);
2176 if(selrange
.cpMin
== selrange
.cpMax
)
2177 seltype
|= SEL_EMPTY
;
2180 /* FIXME: Handle objects */
2181 seltype
|= SEL_TEXT
;
2182 if(selrange
.cpMax
-selrange
.cpMin
> 1)
2183 seltype
|= SEL_MULTICHAR
;
2185 if(SUCCEEDED(IRichEditOleCallback_GetContextMenu(editor
->lpOleCallback
, seltype
, NULL
, &selrange
, &menu
)))
2187 TrackPopupMenu(menu
, TPM_LEFTALIGN
| TPM_RIGHTBUTTON
, x
, y
, 0, GetParent(editor
->hWnd
), NULL
);
2193 ME_TextEditor
*ME_MakeEditor(HWND hWnd
) {
2194 ME_TextEditor
*ed
= ALLOC_OBJ(ME_TextEditor
);
2197 ed
->bEmulateVersion10
= FALSE
;
2198 ed
->pBuffer
= ME_MakeText();
2199 ed
->nZoomNumerator
= ed
->nZoomDenominator
= 0;
2200 ME_MakeFirstParagraph(ed
);
2201 /* The four cursors are for:
2202 * 0 - The position where the caret is shown
2203 * 1 - The anchored end of the selection (for normal selection)
2204 * 2 & 3 - The anchored start and end respectively for word, line,
2205 * or paragraph selection.
2208 ed
->pCursors
= ALLOC_N_OBJ(ME_Cursor
, ed
->nCursors
);
2209 ed
->pCursors
[0].pRun
= ME_FindItemFwd(ed
->pBuffer
->pFirst
, diRun
);
2210 ed
->pCursors
[0].nOffset
= 0;
2211 ed
->pCursors
[1].pRun
= ME_FindItemFwd(ed
->pBuffer
->pFirst
, diRun
);
2212 ed
->pCursors
[1].nOffset
= 0;
2213 ed
->pCursors
[2] = ed
->pCursors
[0];
2214 ed
->pCursors
[3] = ed
->pCursors
[1];
2215 ed
->nLastTotalLength
= ed
->nTotalLength
= 0;
2219 ed
->rgbBackColor
= -1;
2220 ed
->hbrBackground
= GetSysColorBrush(COLOR_WINDOW
);
2221 ed
->bCaretAtEnd
= FALSE
;
2223 ed
->nModifyStep
= 0;
2224 ed
->nTextLimit
= TEXT_LIMIT_DEFAULT
;
2225 ed
->pUndoStack
= ed
->pRedoStack
= ed
->pUndoStackBottom
= NULL
;
2226 ed
->nUndoStackSize
= 0;
2227 ed
->nUndoLimit
= STACK_SIZE_DEFAULT
;
2228 ed
->nUndoMode
= umAddToUndo
;
2229 ed
->nParagraphs
= 1;
2230 ed
->nLastSelStart
= ed
->nLastSelEnd
= 0;
2231 ed
->pLastSelStartPara
= ed
->pLastSelEndPara
= ME_FindItemFwd(ed
->pBuffer
->pFirst
, diParagraph
);
2233 ed
->bWordWrap
= (GetWindowLongW(hWnd
, GWL_STYLE
) & (WS_HSCROLL
|ES_AUTOHSCROLL
)) ? FALSE
: TRUE
;
2234 ed
->bHideSelection
= FALSE
;
2235 ed
->nInvalidOfs
= -1;
2236 ed
->pfnWordBreak
= NULL
;
2237 ed
->lpOleCallback
= NULL
;
2238 ed
->mode
= TM_RICHTEXT
| TM_MULTILEVELUNDO
| TM_MULTICODEPAGE
;
2239 ed
->AutoURLDetect_bEnable
= FALSE
;
2240 ed
->bHaveFocus
= FALSE
;
2241 for (i
=0; i
<HFONT_CACHE_SIZE
; i
++)
2243 ed
->pFontCache
[i
].nRefs
= 0;
2244 ed
->pFontCache
[i
].nAge
= 0;
2245 ed
->pFontCache
[i
].hFont
= NULL
;
2248 ME_CheckCharOffsets(ed
);
2249 if (GetWindowLongW(hWnd
, GWL_STYLE
) & ES_SELECTIONBAR
)
2250 ed
->selofs
= SELECTIONBAR_WIDTH
;
2253 ed
->nSelectionType
= stPosition
;
2255 if (GetWindowLongW(hWnd
, GWL_STYLE
) & ES_PASSWORD
)
2256 ed
->cPasswordMask
= '*';
2258 ed
->cPasswordMask
= 0;
2260 ed
->notified_cr
.cpMin
= ed
->notified_cr
.cpMax
= 0;
2262 /* Default vertical scrollbar information */
2263 ed
->vert_si
.cbSize
= sizeof(SCROLLINFO
);
2264 ed
->vert_si
.nMin
= 0;
2265 ed
->vert_si
.nMax
= 0;
2266 ed
->vert_si
.nPage
= 0;
2267 ed
->vert_si
.nPos
= 0;
2269 OleInitialize(NULL
);
2274 typedef struct tagME_GlobalDestStruct
2278 } ME_GlobalDestStruct
;
2280 static DWORD CALLBACK
ME_ReadFromHGLOBALUnicode(DWORD_PTR dwCookie
, LPBYTE lpBuff
, LONG cb
, LONG
*pcb
)
2282 ME_GlobalDestStruct
*pData
= (ME_GlobalDestStruct
*)dwCookie
;
2287 pDest
= (WORD
*)lpBuff
;
2288 pSrc
= (WORD
*)GlobalLock(pData
->hData
);
2289 for (i
= 0; i
<cb
&& pSrc
[pData
->nLength
+i
]; i
++) {
2290 pDest
[i
] = pSrc
[pData
->nLength
+i
];
2292 pData
->nLength
+= i
;
2294 GlobalUnlock(pData
->hData
);
2298 static DWORD CALLBACK
ME_ReadFromHGLOBALRTF(DWORD_PTR dwCookie
, LPBYTE lpBuff
, LONG cb
, LONG
*pcb
)
2300 ME_GlobalDestStruct
*pData
= (ME_GlobalDestStruct
*)dwCookie
;
2305 pSrc
= (BYTE
*)GlobalLock(pData
->hData
);
2306 for (i
= 0; i
<cb
&& pSrc
[pData
->nLength
+i
]; i
++) {
2307 pDest
[i
] = pSrc
[pData
->nLength
+i
];
2309 pData
->nLength
+= i
;
2311 GlobalUnlock(pData
->hData
);
2316 void ME_DestroyEditor(ME_TextEditor
*editor
)
2318 ME_DisplayItem
*pFirst
= editor
->pBuffer
->pFirst
;
2319 ME_DisplayItem
*p
= pFirst
, *pNext
= NULL
;
2322 ME_ClearTempStyle(editor
);
2323 ME_EmptyUndoStack(editor
);
2326 ME_DestroyDisplayItem(p
);
2329 ME_ReleaseStyle(editor
->pBuffer
->pDefaultStyle
);
2330 for (i
=0; i
<HFONT_CACHE_SIZE
; i
++)
2332 if (editor
->pFontCache
[i
].hFont
)
2333 DeleteObject(editor
->pFontCache
[i
].hFont
);
2335 if (editor
->rgbBackColor
!= -1)
2336 DeleteObject(editor
->hbrBackground
);
2337 if(editor
->lpOleCallback
)
2338 IUnknown_Release(editor
->lpOleCallback
);
2341 FREE_OBJ(editor
->pBuffer
);
2342 FREE_OBJ(editor
->pCursors
);
2347 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
2352 case DLL_PROCESS_ATTACH
:
2353 DisableThreadLibraryCalls(hinstDLL
);
2354 me_heap
= HeapCreate (0, 0x10000, 0);
2355 if (!ME_RegisterEditorClass(hinstDLL
)) return FALSE
;
2356 hLeft
= LoadCursorW(hinstDLL
, MAKEINTRESOURCEW(OCR_REVERSE
));
2360 case DLL_PROCESS_DETACH
:
2361 UnregisterClassW(RichEdit20W
, 0);
2362 UnregisterClassW(RichEdit50W
, 0);
2363 UnregisterClassA("RichEdit20A", 0);
2364 UnregisterClassA("RichEdit50A", 0);
2365 if (ME_ListBoxRegistered
)
2366 UnregisterClassW(REListBox20W
, 0);
2367 if (ME_ComboBoxRegistered
)
2368 UnregisterClassW(REComboBox20W
, 0);
2370 HeapDestroy (me_heap
);
2378 #define UNSUPPORTED_MSG(e) \
2380 FIXME(#e ": stub\n"); \
2381 return DefWindowProcW(hWnd, msg, wParam, lParam);
2383 static const char * const edit_messages
[] = {
2412 "EM_SETPASSWORDCHAR",
2413 "EM_EMPTYUNDOBUFFER",
2414 "EM_GETFIRSTVISIBLELINE",
2416 "EM_SETWORDBREAKPROC",
2417 "EM_GETWORDBREAKPROC",
2418 "EM_GETPASSWORDCHAR",
2426 static const char * const richedit_messages
[] = {
2431 "EM_EXLINEFROMCHAR",
2437 "EM_GETOLEINTERFACE",
2447 "EM_SETOLECALLBACK",
2449 "EM_SETTARGETDEVICE",
2457 "EM_GETWORDBREAKPROCEX",
2458 "EM_SETWORDBREAKPROCEX",
2460 "EM_UNKNOWN_USER_83",
2465 "EM_STOPGROUPTYPING",
2469 "EM_GETAUTOURLDETECT",
2472 "EM_GETTEXTLENGTHEX",
2475 "EM_UNKNOWN_USER_98",
2476 "EM_UNKNOWN_USER_99",
2477 "EM_SETPUNCTUATION",
2478 "EM_GETPUNCTUATION",
2479 "EM_SETWORDWRAPMODE",
2480 "EM_GETWORDWRAPMODE",
2486 "EM_UNKNOWN_USER_109",
2487 "EM_UNKNOWN_USER_110",
2488 "EM_UNKNOWN_USER_111",
2489 "EM_UNKNOWN_USER_112",
2490 "EM_UNKNOWN_USER_113",
2491 "EM_UNKNOWN_USER_114",
2492 "EM_UNKNOWN_USER_115",
2493 "EM_UNKNOWN_USER_116",
2494 "EM_UNKNOWN_USER_117",
2495 "EM_UNKNOWN_USER_118",
2496 "EM_UNKNOWN_USER_119",
2497 "EM_SETLANGOPTIONS",
2498 "EM_GETLANGOPTIONS",
2499 "EM_GETIMECOMPMODE",
2503 "EM_SETIMEMODEBIAS",
2508 get_msg_name(UINT msg
)
2510 if (msg
>= EM_GETSEL
&& msg
<= EM_CHARFROMPOS
)
2511 return edit_messages
[msg
- EM_GETSEL
];
2512 if (msg
>= EM_CANPASTE
&& msg
<= EM_GETIMEMODEBIAS
)
2513 return richedit_messages
[msg
- EM_CANPASTE
];
2517 static LRESULT
RichEditWndProc_common(HWND hWnd
, UINT msg
, WPARAM wParam
,
2518 LPARAM lParam
, BOOL unicode
)
2520 ME_TextEditor
*editor
= (ME_TextEditor
*)GetWindowLongPtrW(hWnd
, 0);
2522 TRACE("hwnd %p msg %04x (%s) %lx %lx, unicode %d\n",
2523 hWnd
, msg
, get_msg_name(msg
), wParam
, lParam
, unicode
);
2525 if (!editor
&& msg
!= WM_NCCREATE
&& msg
!= WM_NCDESTROY
) {
2526 ERR("called with invalid hWnd %p - application bug?\n", hWnd
);
2532 UNSUPPORTED_MSG(EM_DISPLAYBAND
)
2533 UNSUPPORTED_MSG(EM_FINDWORDBREAK
)
2534 UNSUPPORTED_MSG(EM_FMTLINES
)
2535 UNSUPPORTED_MSG(EM_FORMATRANGE
)
2536 UNSUPPORTED_MSG(EM_GETBIDIOPTIONS
)
2537 UNSUPPORTED_MSG(EM_GETEDITSTYLE
)
2538 UNSUPPORTED_MSG(EM_GETIMECOMPMODE
)
2539 /* UNSUPPORTED_MSG(EM_GETIMESTATUS) missing in Wine headers */
2540 UNSUPPORTED_MSG(EM_GETLANGOPTIONS
)
2541 /* UNSUPPORTED_MSG(EM_GETOLEINTERFACE) separate stub */
2542 UNSUPPORTED_MSG(EM_GETREDONAME
)
2543 UNSUPPORTED_MSG(EM_GETTEXTMODE
)
2544 UNSUPPORTED_MSG(EM_GETTYPOGRAPHYOPTIONS
)
2545 UNSUPPORTED_MSG(EM_GETUNDONAME
)
2546 UNSUPPORTED_MSG(EM_GETWORDBREAKPROCEX
)
2547 UNSUPPORTED_MSG(EM_PASTESPECIAL
)
2548 UNSUPPORTED_MSG(EM_SELECTIONTYPE
)
2549 UNSUPPORTED_MSG(EM_SETBIDIOPTIONS
)
2550 UNSUPPORTED_MSG(EM_SETEDITSTYLE
)
2551 UNSUPPORTED_MSG(EM_SETFONTSIZE
)
2552 UNSUPPORTED_MSG(EM_SETLANGOPTIONS
)
2553 UNSUPPORTED_MSG(EM_SETMARGINS
)
2554 UNSUPPORTED_MSG(EM_SETPALETTE
)
2555 UNSUPPORTED_MSG(EM_SETTABSTOPS
)
2556 UNSUPPORTED_MSG(EM_SETTYPOGRAPHYOPTIONS
)
2557 UNSUPPORTED_MSG(EM_SETWORDBREAKPROCEX
)
2558 UNSUPPORTED_MSG(WM_STYLECHANGING
)
2559 UNSUPPORTED_MSG(WM_STYLECHANGED
)
2561 /* Messages specific to Richedit controls */
2564 return ME_StreamIn(editor
, wParam
, (EDITSTREAM
*)lParam
, TRUE
);
2566 return ME_StreamOut(editor
, wParam
, (EDITSTREAM
*)lParam
);
2569 UINT code
= DLGC_WANTCHARS
|DLGC_WANTARROWS
;
2570 if(lParam
&& (((LPMSG
)lParam
)->message
== WM_KEYDOWN
))
2572 int vk
= (int)((LPMSG
)lParam
)->wParam
;
2573 /* if style says we want return key */
2574 if((vk
== VK_RETURN
) && (GetWindowLongW(hWnd
, GWL_STYLE
) & ES_WANTRETURN
))
2576 code
|= DLGC_WANTMESSAGE
;
2578 /* we always handle ctrl-tab */
2579 if((vk
== VK_TAB
) && (GetKeyState(VK_CONTROL
) & 0x8000))
2581 code
|= DLGC_WANTMESSAGE
;
2588 CREATESTRUCTW
*pcs
= (CREATESTRUCTW
*)lParam
;
2589 TRACE("WM_NCCREATE: style 0x%08x\n", pcs
->style
);
2590 editor
= ME_MakeEditor(hWnd
);
2591 SetWindowLongPtrW(hWnd
, 0, (LONG_PTR
)editor
);
2594 case EM_EMPTYUNDOBUFFER
:
2595 ME_EmptyUndoStack(editor
);
2599 /* Note: wParam/lParam can be NULL */
2601 PUINT pfrom
= wParam
? (PUINT
)wParam
: &from
;
2602 PUINT pto
= lParam
? (PUINT
)lParam
: &to
;
2603 ME_GetSelection(editor
, (int *)pfrom
, (int *)pto
);
2604 if ((*pfrom
|*pto
) & 0xFFFF0000)
2606 return MAKELONG(*pfrom
,*pto
);
2610 CHARRANGE
*pRange
= (CHARRANGE
*)lParam
;
2611 ME_GetSelection(editor
, &pRange
->cpMin
, &pRange
->cpMax
);
2612 TRACE("EM_EXGETSEL = (%d,%d)\n", pRange
->cpMin
, pRange
->cpMax
);
2615 case EM_SETUNDOLIMIT
:
2617 if ((int)wParam
< 0)
2618 editor
->nUndoLimit
= STACK_SIZE_DEFAULT
;
2620 editor
->nUndoLimit
= min(wParam
, STACK_SIZE_MAX
);
2621 /* Setting a max stack size keeps wine from getting killed
2622 for hogging memory. Windows allocates all this memory at once, so
2623 no program would realistically set a value above our maximum. */
2624 return editor
->nUndoLimit
;
2627 return editor
->pUndoStack
!= NULL
;
2629 return editor
->pRedoStack
!= NULL
;
2630 case WM_UNDO
: /* FIXME: actually not the same */
2632 return ME_Undo(editor
);
2634 return ME_Redo(editor
);
2637 /* these flags are equivalent to the ES_* counterparts */
2638 DWORD mask
= ECO_VERTICAL
| ECO_AUTOHSCROLL
| ECO_AUTOVSCROLL
|
2639 ECO_NOHIDESEL
| ECO_READONLY
| ECO_WANTRETURN
;
2640 DWORD settings
= GetWindowLongW(hWnd
, GWL_STYLE
) & mask
;
2646 /* these flags are equivalent to ES_* counterparts
2647 * ECO_READONLY is already implemented in the code, only requires
2648 * setting the bit to work
2650 DWORD mask
= ECO_VERTICAL
| ECO_AUTOHSCROLL
| ECO_AUTOVSCROLL
|
2651 ECO_NOHIDESEL
| ECO_READONLY
| ECO_WANTRETURN
| ECO_SELECTIONBAR
;
2652 DWORD raw
= GetWindowLongW(hWnd
, GWL_STYLE
);
2653 DWORD settings
= mask
& raw
;
2669 SetWindowLongW(hWnd
, GWL_STYLE
, (raw
& ~mask
) | (settings
& mask
));
2671 if (settings
& ECO_AUTOWORDSELECTION
)
2672 FIXME("ECO_AUTOWORDSELECTION not implemented yet!\n");
2673 if (settings
& ECO_SELECTIONBAR
)
2674 editor
->selofs
= SELECTIONBAR_WIDTH
;
2677 ME_WrapMarkedParagraphs(editor
);
2679 if (settings
& ECO_VERTICAL
)
2680 FIXME("ECO_VERTICAL not implemented yet!\n");
2681 if (settings
& ECO_AUTOHSCROLL
)
2682 FIXME("ECO_AUTOHSCROLL not implemented yet!\n");
2683 if (settings
& ECO_AUTOVSCROLL
)
2684 FIXME("ECO_AUTOVSCROLL not implemented yet!\n");
2685 if (settings
& ECO_NOHIDESEL
)
2686 FIXME("ECO_NOHIDESEL not implemented yet!\n");
2687 if (settings
& ECO_WANTRETURN
)
2688 FIXME("ECO_WANTRETURN not implemented yet!\n");
2694 ME_InvalidateSelection(editor
);
2695 ME_SetSelection(editor
, wParam
, lParam
);
2696 ME_InvalidateSelection(editor
);
2697 HideCaret(editor
->hWnd
);
2698 ME_ShowCaret(editor
);
2699 ME_SendSelChange(editor
);
2702 case EM_SETSCROLLPOS
:
2704 POINT
*point
= (POINT
*)lParam
;
2705 ME_ScrollAbs(editor
, point
->y
);
2708 case EM_AUTOURLDETECT
:
2710 if (wParam
==1 || wParam
==0)
2712 editor
->AutoURLDetect_bEnable
= (BOOL
)wParam
;
2715 return E_INVALIDARG
;
2717 case EM_GETAUTOURLDETECT
:
2719 return editor
->AutoURLDetect_bEnable
;
2724 CHARRANGE range
= *(CHARRANGE
*)lParam
;
2726 TRACE("EM_EXSETSEL (%d,%d)\n", range
.cpMin
, range
.cpMax
);
2728 ME_InvalidateSelection(editor
);
2729 end
= ME_SetSelection(editor
, range
.cpMin
, range
.cpMax
);
2730 ME_InvalidateSelection(editor
);
2731 HideCaret(editor
->hWnd
);
2732 ME_ShowCaret(editor
);
2733 ME_SendSelChange(editor
);
2737 case EM_SHOWSCROLLBAR
:
2739 ShowScrollBar(editor
->hWnd
, wParam
, lParam
);
2745 SETTEXTEX
*pStruct
= (SETTEXTEX
*)wParam
;
2749 int oldModify
= editor
->nModifyStep
;
2751 if (!pStruct
) return 0;
2753 TRACE("EM_SETTEXTEX - %s, flags %d, cp %d\n",
2754 pStruct
->codepage
== 1200 ? debugstr_w((LPCWSTR
)lParam
) : debugstr_a((LPCSTR
)lParam
),
2755 pStruct
->flags
, pStruct
->codepage
);
2757 /* FIXME: make use of pStruct->codepage in the to unicode translation */
2758 wszText
= lParam
? ME_ToUnicode(pStruct
->codepage
== 1200, (void *)lParam
) : NULL
;
2759 len
= wszText
? lstrlenW(wszText
) : 0;
2761 if (pStruct
->flags
& ST_SELECTION
) {
2762 ME_GetSelection(editor
, &from
, &to
);
2763 style
= ME_GetSelectionInsertStyle(editor
);
2764 ME_InternalDeleteText(editor
, from
, to
- from
, FALSE
);
2765 if (pStruct
->codepage
!= 1200 && lParam
&&
2766 (!strncmp((char *)lParam
, "{\\rtf", 5) || !strncmp((char *)lParam
, "{\\urtf}", 6)))
2767 ME_StreamInRTFString(editor
, 1, (char *)lParam
);
2768 else ME_InsertTextFromCursor(editor
, 0, wszText
, len
, style
);
2769 ME_ReleaseStyle(style
);
2771 if (editor
->AutoURLDetect_bEnable
) ME_UpdateSelectionLinkAttribute(editor
);
2774 ME_InternalDeleteText(editor
, 0, ME_GetTextLength(editor
), FALSE
);
2775 if (pStruct
->codepage
!= 1200 && lParam
&&
2776 (!strncmp((char *)lParam
, "{\\rtf", 5) || !strncmp((char *)lParam
, "{\\urtf}", 6)))
2777 ME_StreamInRTFString(editor
, 0, (char *)lParam
);
2778 else ME_InsertTextFromCursor(editor
, 0, wszText
, len
, editor
->pBuffer
->pDefaultStyle
);
2781 if (editor
->AutoURLDetect_bEnable
) ME_UpdateLinkAttribute(editor
, 0, -1);
2783 ME_CommitUndo(editor
);
2784 if (!(pStruct
->flags
& ST_KEEPUNDO
))
2786 editor
->nModifyStep
= oldModify
;
2787 ME_EmptyUndoStack(editor
);
2789 ME_UpdateRepaint(editor
);
2792 case EM_SETBKGNDCOLOR
:
2795 if (editor
->rgbBackColor
!= -1) {
2796 DeleteObject(editor
->hbrBackground
);
2797 lColor
= editor
->rgbBackColor
;
2799 else lColor
= GetSysColor(COLOR_WINDOW
);
2803 editor
->rgbBackColor
= -1;
2804 editor
->hbrBackground
= GetSysColorBrush(COLOR_WINDOW
);
2808 editor
->rgbBackColor
= lParam
;
2809 editor
->hbrBackground
= CreateSolidBrush(editor
->rgbBackColor
);
2811 if (editor
->bRedraw
)
2813 InvalidateRect(hWnd
, NULL
, TRUE
);
2819 return editor
->nModifyStep
== 0 ? 0 : -1;
2823 editor
->nModifyStep
= 1;
2825 editor
->nModifyStep
= 0;
2829 case EM_SETREADONLY
:
2831 long nStyle
= GetWindowLongW(hWnd
, GWL_STYLE
);
2833 nStyle
|= ES_READONLY
;
2835 nStyle
&= ~ES_READONLY
;
2836 SetWindowLongW(hWnd
, GWL_STYLE
, nStyle
);
2839 case EM_SETEVENTMASK
:
2841 DWORD nOldMask
= editor
->nEventMask
;
2843 editor
->nEventMask
= lParam
;
2846 case EM_GETEVENTMASK
:
2847 return editor
->nEventMask
;
2848 case EM_SETCHARFORMAT
:
2850 CHARFORMAT2W buf
, *p
;
2851 BOOL bRepaint
= TRUE
;
2852 p
= ME_ToCF2W(&buf
, (CHARFORMAT2W
*)lParam
);
2853 if (p
== NULL
) return 0;
2855 ME_SetDefaultCharFormat(editor
, p
);
2856 else if (wParam
== (SCF_WORD
| SCF_SELECTION
)) {
2857 FIXME("EM_SETCHARFORMAT: word selection not supported\n");
2859 } else if (wParam
== SCF_ALL
) {
2860 if (editor
->mode
& TM_PLAINTEXT
)
2861 ME_SetDefaultCharFormat(editor
, p
);
2863 ME_SetCharFormat(editor
, 0, ME_GetTextLength(editor
), p
);
2864 editor
->nModifyStep
= 1;
2866 } else if (editor
->mode
& TM_PLAINTEXT
) {
2870 ME_GetSelection(editor
, &from
, &to
);
2871 bRepaint
= (from
!= to
);
2872 ME_SetSelectionCharFormat(editor
, p
);
2873 if (from
!= to
) editor
->nModifyStep
= 1;
2875 ME_CommitUndo(editor
);
2877 ME_RewrapRepaint(editor
);
2880 case EM_GETCHARFORMAT
:
2882 CHARFORMAT2W tmp
, *dst
= (CHARFORMAT2W
*)lParam
;
2883 if (dst
->cbSize
!= sizeof(CHARFORMATA
) &&
2884 dst
->cbSize
!= sizeof(CHARFORMATW
) &&
2885 dst
->cbSize
!= sizeof(CHARFORMAT2A
) &&
2886 dst
->cbSize
!= sizeof(CHARFORMAT2W
))
2888 tmp
.cbSize
= sizeof(tmp
);
2890 ME_GetDefaultCharFormat(editor
, &tmp
);
2892 ME_GetSelectionCharFormat(editor
, &tmp
);
2893 ME_CopyToCFAny(dst
, &tmp
);
2896 case EM_SETPARAFORMAT
:
2898 BOOL result
= ME_SetSelectionParaFormat(editor
, (PARAFORMAT2
*)lParam
);
2899 ME_RewrapRepaint(editor
);
2900 ME_CommitUndo(editor
);
2903 case EM_GETPARAFORMAT
:
2904 ME_GetSelectionParaFormat(editor
, (PARAFORMAT2
*)lParam
);
2905 return ((PARAFORMAT2
*)lParam
)->dwMask
;
2906 case EM_GETFIRSTVISIBLELINE
:
2908 ME_DisplayItem
*p
= editor
->pBuffer
->pFirst
;
2909 int y
= ME_GetYScrollPos(editor
);
2914 p
= ME_FindItemFwd(p
, diStartRowOrParagraphOrEnd
);
2915 if (p
->type
== diTextEnd
)
2917 if (p
->type
== diParagraph
) {
2918 ypara
= p
->member
.para
.pt
.y
;
2921 ystart
= ypara
+ p
->member
.row
.pt
.y
;
2922 yend
= ystart
+ p
->member
.row
.nHeight
;
2930 case EM_HIDESELECTION
:
2932 editor
->bHideSelection
= (wParam
!= 0);
2933 ME_InvalidateSelection(editor
);
2938 ME_ScrollDown(editor
, lParam
* 8); /* FIXME follow the original */
2939 return TRUE
; /* Should return false if a single line richedit control */
2944 ME_GetSelection(editor
, &from
, &to
);
2945 ME_InternalDeleteText(editor
, from
, to
-from
, FALSE
);
2946 ME_CommitUndo(editor
);
2947 ME_UpdateRepaint(editor
);
2954 LPWSTR wszText
= lParam
? ME_ToUnicode(unicode
, (void *)lParam
) : NULL
;
2955 size_t len
= wszText
? lstrlenW(wszText
) : 0;
2956 TRACE("EM_REPLACESEL - %s\n", debugstr_w(wszText
));
2958 ME_GetSelection(editor
, &from
, &to
);
2959 style
= ME_GetSelectionInsertStyle(editor
);
2960 ME_InternalDeleteText(editor
, from
, to
-from
, FALSE
);
2961 ME_InsertTextFromCursor(editor
, 0, wszText
, len
, style
);
2962 ME_ReleaseStyle(style
);
2963 /* drop temporary style if line end */
2965 * FIXME question: does abc\n mean: put abc,
2966 * clear temp style, put \n? (would require a change)
2968 if (len
>0 && wszText
[len
-1] == '\n')
2969 ME_ClearTempStyle(editor
);
2970 ME_EndToUnicode(unicode
, wszText
);
2971 ME_CommitUndo(editor
);
2972 if (editor
->AutoURLDetect_bEnable
) ME_UpdateSelectionLinkAttribute(editor
);
2974 ME_EmptyUndoStack(editor
);
2975 ME_UpdateRepaint(editor
);
2978 case EM_SCROLLCARET
:
2980 int top
, bottom
; /* row's edges relative to document top */
2982 ME_DisplayItem
*para
, *row
;
2984 nPos
= ME_GetYScrollPos(editor
);
2985 row
= ME_RowStart(editor
->pCursors
[0].pRun
);
2986 para
= ME_GetParagraph(row
);
2987 top
= para
->member
.para
.pt
.y
+ row
->member
.row
.pt
.y
;
2988 bottom
= top
+ row
->member
.row
.nHeight
;
2990 if (top
< nPos
) /* caret above window */
2991 ME_ScrollAbs(editor
, top
);
2992 else if (nPos
+ editor
->sizeWindow
.cy
< bottom
) /*below*/
2993 ME_ScrollAbs(editor
, bottom
- editor
->sizeWindow
.cy
);
3001 BOOL bRepaint
= LOWORD(lParam
);
3004 wParam
= (WPARAM
)GetStockObject(SYSTEM_FONT
);
3005 GetObjectW((HGDIOBJ
)wParam
, sizeof(LOGFONTW
), &lf
);
3007 ME_CharFormatFromLogFont(hDC
, &lf
, &fmt
);
3008 ReleaseDC(hWnd
, hDC
);
3009 ME_SetCharFormat(editor
, 0, ME_GetTextLength(editor
), &fmt
);
3010 ME_SetDefaultCharFormat(editor
, &fmt
);
3012 ME_CommitUndo(editor
);
3014 ME_RewrapRepaint(editor
);
3019 ME_InternalDeleteText(editor
, 0, ME_GetTextLength(editor
), FALSE
);
3022 TRACE("WM_SETTEXT lParam==%lx\n",lParam
);
3023 if (!unicode
&& !strncmp((char *)lParam
, "{\\rtf", 5))
3025 /* Undocumented: WM_SETTEXT supports RTF text */
3026 ME_StreamInRTFString(editor
, 0, (char *)lParam
);
3030 LPWSTR wszText
= ME_ToUnicode(unicode
, (void *)lParam
);
3031 TRACE("WM_SETTEXT - %s\n", debugstr_w(wszText
)); /* debugstr_w() */
3032 if (lstrlenW(wszText
) > 0)
3036 /* uses default style! */
3037 if (!(GetWindowLongW(hWnd
, GWL_STYLE
) & ES_MULTILINE
))
3042 while (*p
!= '\0' && *p
!= '\r' && *p
!= '\n') p
++;
3045 ME_InsertTextFromCursor(editor
, 0, wszText
, len
, editor
->pBuffer
->pDefaultStyle
);
3047 ME_EndToUnicode(unicode
, wszText
);
3051 TRACE("WM_SETTEXT - NULL\n");
3052 if (editor
->AutoURLDetect_bEnable
)
3054 ME_UpdateLinkAttribute(editor
, 0, -1);
3056 ME_SetSelection(editor
, 0, 0);
3057 editor
->nModifyStep
= 0;
3058 ME_CommitUndo(editor
);
3059 ME_EmptyUndoStack(editor
);
3060 ME_UpdateRepaint(editor
);
3065 UINT nRTFFormat
= RegisterClipboardFormatA("Rich Text Format");
3066 if (IsClipboardFormatAvailable(nRTFFormat
))
3068 if (IsClipboardFormatAvailable(CF_UNICODETEXT
))
3076 ME_GlobalDestStruct gds
;
3077 UINT nRTFFormat
= RegisterClipboardFormatA("Rich Text Format");
3080 if (IsClipboardFormatAvailable(nRTFFormat
))
3081 cf
= nRTFFormat
, dwFormat
= SF_RTF
;
3082 else if (IsClipboardFormatAvailable(CF_UNICODETEXT
))
3083 cf
= CF_UNICODETEXT
, dwFormat
= SF_TEXT
|SF_UNICODE
;
3087 if (!OpenClipboard(hWnd
))
3089 gds
.hData
= GetClipboardData(cf
);
3091 es
.dwCookie
= (DWORD
)&gds
;
3092 es
.pfnCallback
= dwFormat
== SF_RTF
? ME_ReadFromHGLOBALRTF
: ME_ReadFromHGLOBALUnicode
;
3093 ME_StreamIn(editor
, dwFormat
|SFF_SELECTION
, &es
, FALSE
);
3101 LPDATAOBJECT dataObj
= NULL
;
3105 if (editor
->cPasswordMask
)
3106 return 0; /* Copying or Cutting masked text isn't allowed */
3108 ME_GetSelection(editor
, &range
.cpMin
, &range
.cpMax
);
3109 if(editor
->lpOleCallback
)
3110 hr
= IRichEditOleCallback_GetClipboardData(editor
->lpOleCallback
, &range
, RECO_COPY
, &dataObj
);
3111 if(FAILED(hr
) || !dataObj
)
3112 hr
= ME_GetDataObject(editor
, &range
, &dataObj
);
3114 hr
= OleSetClipboard(dataObj
);
3115 IDataObject_Release(dataObj
);
3117 if (SUCCEEDED(hr
) && msg
== WM_CUT
)
3119 ME_InternalDeleteText(editor
, range
.cpMin
, range
.cpMax
-range
.cpMin
, FALSE
);
3120 ME_CommitUndo(editor
);
3121 ME_UpdateRepaint(editor
);
3125 case WM_GETTEXTLENGTH
:
3127 GETTEXTLENGTHEX how
;
3129 /* CR/LF conversion required in 2.0 mode, verbatim in 1.0 mode */
3130 how
.flags
= GTL_CLOSE
| (editor
->bEmulateVersion10
? 0 : GTL_USECRLF
) | GTL_NUMCHARS
;
3131 how
.codepage
= unicode
? 1200 : CP_ACP
;
3132 return ME_GetTextLengthEx(editor
, &how
);
3134 case EM_GETTEXTLENGTHEX
:
3135 return ME_GetTextLengthEx(editor
, (GETTEXTLENGTHEX
*)wParam
);
3140 LPSTR bufferA
= NULL
;
3141 LPWSTR bufferW
= NULL
;
3144 bufferW
= heap_alloc((wParam
+ 2) * sizeof(WCHAR
));
3146 bufferA
= heap_alloc(wParam
+ 2);
3148 ex
.cb
= (wParam
+ 2) * (unicode
? sizeof(WCHAR
) : sizeof(CHAR
));
3149 ex
.flags
= GT_USECRLF
;
3150 ex
.codepage
= unicode
? 1200 : CP_ACP
;
3151 ex
.lpDefaultChar
= NULL
;
3152 ex
.lpUsedDefChar
= NULL
;
3153 rc
= RichEditWndProc_common(hWnd
, EM_GETTEXTEX
, (WPARAM
)&ex
, unicode
? (LPARAM
)bufferW
: (LPARAM
)bufferA
, unicode
);
3157 memcpy((LPWSTR
)lParam
, bufferW
, wParam
* sizeof(WCHAR
));
3158 if (lstrlenW(bufferW
) >= wParam
) rc
= 0;
3162 memcpy((LPSTR
)lParam
, bufferA
, wParam
);
3163 if (strlen(bufferA
) >= wParam
) rc
= 0;
3171 GETTEXTEX
*ex
= (GETTEXTEX
*)wParam
;
3172 int nStart
, nCount
; /* in chars */
3174 if (ex
->flags
& ~(GT_SELECTION
| GT_USECRLF
))
3175 FIXME("GETTEXTEX flags 0x%08x not supported\n", ex
->flags
& ~(GT_SELECTION
| GT_USECRLF
));
3177 if (ex
->flags
& GT_SELECTION
)
3179 ME_GetSelection(editor
, &nStart
, &nCount
);
3185 nCount
= 0x7fffffff;
3187 if (ex
->codepage
== 1200)
3189 nCount
= min(nCount
, ex
->cb
/ sizeof(WCHAR
) - 1);
3190 return ME_GetTextW(editor
, (LPWSTR
)lParam
, nStart
, nCount
, ex
->flags
& GT_USECRLF
);
3194 /* potentially each char may be a CR, why calculate the exact value with O(N) when
3195 we can just take a bigger buffer? :)
3196 The above assumption still holds with CR/LF counters, since CR->CRLF expansion
3197 occurs only in richedit 2.0 mode, in which line breaks have only one CR
3199 int crlfmul
= (ex
->flags
& GT_USECRLF
) ? 2 : 1;
3201 DWORD buflen
= ex
->cb
;
3205 nCount
= min(nCount
, ex
->cb
- 1);
3206 buffer
= heap_alloc((crlfmul
*nCount
+ 1) * sizeof(WCHAR
));
3208 buflen
= ME_GetTextW(editor
, buffer
, nStart
, nCount
, ex
->flags
& GT_USECRLF
);
3209 rc
= WideCharToMultiByte(ex
->codepage
, flags
, buffer
, buflen
+1, (LPSTR
)lParam
, ex
->cb
, ex
->lpDefaultChar
, ex
->lpUsedDefChar
);
3210 if (rc
) rc
--; /* do not count 0 terminator */
3219 TEXTRANGEW tr
; /* W and A differ only by rng->lpstrText */
3220 ME_GetSelection(editor
, &from
, &to
);
3221 tr
.chrg
.cpMin
= from
;
3223 tr
.lpstrText
= (WCHAR
*)lParam
;
3224 return RichEditWndProc_common(hWnd
, EM_GETTEXTRANGE
, 0, (LPARAM
)&tr
, unicode
);
3226 case EM_GETSCROLLPOS
:
3228 POINT
*point
= (POINT
*)lParam
;
3229 point
->x
= 0; /* FIXME side scrolling not implemented */
3230 point
->y
= ME_GetYScrollPos(editor
);
3233 case EM_GETTEXTRANGE
:
3235 TEXTRANGEW
*rng
= (TEXTRANGEW
*)lParam
;
3236 TRACE("EM_GETTEXTRANGE min=%d max=%d unicode=%d emul1.0=%d length=%d\n",
3237 rng
->chrg
.cpMin
, rng
->chrg
.cpMax
, unicode
,
3238 editor
->bEmulateVersion10
, ME_GetTextLength(editor
));
3240 return ME_GetTextW(editor
, rng
->lpstrText
, rng
->chrg
.cpMin
, rng
->chrg
.cpMax
-rng
->chrg
.cpMin
, 0);
3243 int nLen
= rng
->chrg
.cpMax
-rng
->chrg
.cpMin
;
3244 WCHAR
*p
= ALLOC_N_OBJ(WCHAR
, nLen
+1);
3245 int nChars
= ME_GetTextW(editor
, p
, rng
->chrg
.cpMin
, nLen
, 0);
3246 /* FIXME this is a potential security hole (buffer overrun)
3247 if you know more about wchar->mbyte conversion please explain
3249 WideCharToMultiByte(CP_ACP
, 0, p
, nChars
+1, (char *)rng
->lpstrText
, nLen
+1, NULL
, NULL
);
3256 ME_DisplayItem
*run
;
3257 const unsigned int nMaxChars
= *(WORD
*) lParam
;
3258 unsigned int nCharsLeft
= nMaxChars
;
3259 char *dest
= (char *) lParam
;
3260 BOOL wroteNull
= FALSE
;
3262 TRACE("EM_GETLINE: row=%d, nMaxChars=%d (%s)\n", (int) wParam
, nMaxChars
,
3263 unicode
? "Unicode" : "Ansi");
3265 run
= ME_FindRowWithNumber(editor
, wParam
);
3269 while (nCharsLeft
&& (run
= ME_FindItemFwd(run
, diRunOrStartRow
))
3270 && !(run
->member
.run
.nFlags
& MERF_ENDPARA
))
3274 if (run
->type
!= diRun
)
3276 strText
= run
->member
.run
.strText
;
3277 nCopy
= min(nCharsLeft
, strText
->nLen
);
3280 lstrcpynW((LPWSTR
) dest
, strText
->szData
, nCopy
);
3282 nCopy
= WideCharToMultiByte(CP_ACP
, 0, strText
->szData
, nCopy
, dest
,
3283 nCharsLeft
, NULL
, NULL
);
3284 dest
+= nCopy
* (unicode
? sizeof(WCHAR
) : 1);
3285 nCharsLeft
-= nCopy
;
3288 /* append line termination, space allowing */
3291 if (run
&& (run
->member
.run
.nFlags
& MERF_ENDPARA
))
3294 /* Write as many \r as encoded in end-of-paragraph, space allowing */
3295 for (i
= 0; i
< run
->member
.run
.nCR
&& nCharsLeft
> 0; i
++, nCharsLeft
--)
3297 *((WCHAR
*)dest
) = '\r';
3298 dest
+= unicode
? sizeof(WCHAR
) : 1;
3300 /* Write as many \n as encoded in end-of-paragraph, space allowing */
3301 for (i
= 0; i
< run
->member
.run
.nLF
&& nCharsLeft
> 0; i
++, nCharsLeft
--)
3303 *((WCHAR
*)dest
) = '\n';
3304 dest
+= unicode
? sizeof(WCHAR
) : 1;
3310 *((WCHAR
*)dest
) = '\0';
3318 TRACE("EM_GETLINE: got %u characters\n", nMaxChars
- nCharsLeft
);
3319 return nMaxChars
- nCharsLeft
- (wroteNull
? 1 : 0);
3321 case EM_GETLINECOUNT
:
3323 ME_DisplayItem
*item
= editor
->pBuffer
->pFirst
->next
;
3326 ME_DisplayItem
*prev_para
= NULL
, *last_para
= NULL
;
3328 while (item
!= editor
->pBuffer
->pLast
)
3330 assert(item
->type
== diParagraph
);
3331 prev_para
= ME_FindItemBack(item
, diRun
);
3333 assert(prev_para
->member
.run
.nFlags
& MERF_ENDPARA
);
3335 nRows
+= item
->member
.para
.nRows
;
3336 item
= item
->member
.para
.next_para
;
3338 last_para
= ME_FindItemBack(item
, diRun
);
3340 assert(last_para
->member
.run
.nFlags
& MERF_ENDPARA
);
3341 if (editor
->bEmulateVersion10
&& prev_para
&& last_para
->member
.run
.nCharOfs
== 0
3342 && prev_para
->member
.run
.nCR
== 1 && prev_para
->member
.run
.nLF
== 0)
3344 /* In 1.0 emulation, the last solitary \r at the very end of the text
3345 (if one exists) is NOT a line break.
3346 FIXME: this is an ugly hack. This should have a more regular model. */
3350 TRACE("EM_GETLINECOUNT: nRows==%d\n", nRows
);
3351 return max(1, nRows
);
3353 case EM_LINEFROMCHAR
:
3356 return ME_RowNumberFromCharOfs(editor
, ME_GetCursorOfs(editor
, 1));
3358 return ME_RowNumberFromCharOfs(editor
, wParam
);
3360 case EM_EXLINEFROMCHAR
:
3363 return ME_RowNumberFromCharOfs(editor
, ME_GetCursorOfs(editor
,1));
3365 return ME_RowNumberFromCharOfs(editor
, lParam
);
3369 ME_DisplayItem
*item
, *para
;
3373 item
= ME_FindItemBack(editor
->pCursors
[0].pRun
, diStartRow
);
3375 item
= ME_FindRowWithNumber(editor
, wParam
);
3378 para
= ME_GetParagraph(item
);
3379 item
= ME_FindItemFwd(item
, diRun
);
3380 nCharOfs
= para
->member
.para
.nCharOfs
+ item
->member
.run
.nCharOfs
;
3381 TRACE("EM_LINEINDEX: nCharOfs==%d\n", nCharOfs
);
3386 ME_DisplayItem
*item
, *item_end
;
3387 int nChars
= 0, nThisLineOfs
= 0, nNextLineOfs
= 0;
3389 if (wParam
> ME_GetTextLength(editor
))
3393 FIXME("EM_LINELENGTH: returning number of unselected characters on lines with selection unsupported.\n");
3396 item
= ME_FindItemAtOffset(editor
, diRun
, wParam
, NULL
);
3397 item
= ME_RowStart(item
);
3398 nThisLineOfs
= ME_CharOfsFromRunOfs(editor
, ME_FindItemFwd(item
, diRun
), 0);
3399 item_end
= ME_FindItemFwd(item
, diStartRowOrParagraphOrEnd
);
3400 if (item_end
->type
== diStartRow
)
3401 nNextLineOfs
= ME_CharOfsFromRunOfs(editor
, ME_FindItemFwd(item_end
, diRun
), 0);
3404 ME_DisplayItem
*endPara
;
3406 nNextLineOfs
= ME_FindItemFwd(item
, diParagraphOrEnd
)->member
.para
.nCharOfs
;
3407 endPara
= ME_FindItemFwd(item
, diParagraphOrEnd
);
3408 endPara
= ME_FindItemBack(endPara
, diRun
);
3410 assert(endPara
->type
== diRun
);
3411 assert(endPara
->member
.run
.nFlags
& MERF_ENDPARA
);
3412 nNextLineOfs
-= endPara
->member
.run
.nCR
+ endPara
->member
.run
.nLF
;
3414 nChars
= nNextLineOfs
- nThisLineOfs
;
3415 TRACE("EM_LINELENGTH(%ld)==%d\n",wParam
, nChars
);
3418 case EM_EXLIMITTEXT
:
3420 if ((int)lParam
< 0)
3423 editor
->nTextLimit
= 65536;
3425 editor
->nTextLimit
= (int) lParam
;
3431 editor
->nTextLimit
= 65536;
3433 editor
->nTextLimit
= (int) wParam
;
3436 case EM_GETLIMITTEXT
:
3438 return editor
->nTextLimit
;
3442 FINDTEXTA
*ft
= (FINDTEXTA
*)lParam
;
3443 int nChars
= MultiByteToWideChar(CP_ACP
, 0, ft
->lpstrText
, -1, NULL
, 0);
3447 if ((tmp
= ALLOC_N_OBJ(WCHAR
, nChars
)) != NULL
)
3448 MultiByteToWideChar(CP_ACP
, 0, ft
->lpstrText
, -1, tmp
, nChars
);
3449 r
= ME_FindText(editor
, wParam
, &ft
->chrg
, tmp
, NULL
);
3455 FINDTEXTEXA
*ex
= (FINDTEXTEXA
*)lParam
;
3456 int nChars
= MultiByteToWideChar(CP_ACP
, 0, ex
->lpstrText
, -1, NULL
, 0);
3460 if ((tmp
= ALLOC_N_OBJ(WCHAR
, nChars
)) != NULL
)
3461 MultiByteToWideChar(CP_ACP
, 0, ex
->lpstrText
, -1, tmp
, nChars
);
3462 r
= ME_FindText(editor
, wParam
, &ex
->chrg
, tmp
, &ex
->chrgText
);
3468 FINDTEXTW
*ft
= (FINDTEXTW
*)lParam
;
3469 return ME_FindText(editor
, wParam
, &ft
->chrg
, ft
->lpstrText
, NULL
);
3471 case EM_FINDTEXTEXW
:
3473 FINDTEXTEXW
*ex
= (FINDTEXTEXW
*)lParam
;
3474 return ME_FindText(editor
, wParam
, &ex
->chrg
, ex
->lpstrText
, &ex
->chrgText
);
3477 if (!wParam
|| !lParam
)
3479 *(int *)wParam
= editor
->nZoomNumerator
;
3480 *(int *)lParam
= editor
->nZoomDenominator
;
3483 return ME_SetZoom(editor
, wParam
, lParam
);
3484 case EM_CHARFROMPOS
:
3485 return ME_CharFromPos(editor
, ((POINTL
*)lParam
)->x
, ((POINTL
*)lParam
)->y
, NULL
);
3486 case EM_POSFROMCHAR
:
3488 ME_DisplayItem
*pRun
;
3489 int nCharOfs
, nOffset
, nLength
;
3494 /* detect which API version we're dealing with */
3495 if (wParam
>= 0x40000)
3497 nLength
= ME_GetTextLength(editor
);
3499 if (nCharOfs
< nLength
) {
3500 ME_RunOfsFromCharOfs(editor
, nCharOfs
, &pRun
, &nOffset
);
3501 assert(pRun
->type
== diRun
);
3502 pt
.y
= pRun
->member
.run
.pt
.y
;
3503 pt
.x
= pRun
->member
.run
.pt
.x
+ ME_PointFromChar(editor
, &pRun
->member
.run
, nOffset
);
3504 pt
.y
+= ME_GetParagraph(pRun
)->member
.para
.pt
.y
;
3507 pt
.y
= editor
->pBuffer
->pLast
->member
.para
.pt
.y
;
3509 pt
.x
+= editor
->selofs
;
3511 si
.cbSize
= sizeof(si
);
3513 if (GetScrollInfo(editor
->hWnd
, SB_VERT
, &si
)) pt
.y
-= si
.nPos
;
3514 si
.cbSize
= sizeof(si
);
3516 if (GetScrollInfo(editor
->hWnd
, SB_HORZ
, &si
)) pt
.x
-= si
.nPos
;
3518 if (wParam
>= 0x40000) {
3519 *(POINTL
*)wParam
= pt
;
3521 return (wParam
>= 0x40000) ? 0 : MAKELONG( pt
.x
, pt
.y
);
3527 GetClientRect(hWnd
, &editor
->rcFormat
);
3528 if (GetWindowLongW(hWnd
, GWL_STYLE
) & WS_HSCROLL
)
3529 { /* Squelch the default horizontal scrollbar it would make */
3530 ShowScrollBar(editor
->hWnd
, SB_HORZ
, FALSE
);
3533 si
.cbSize
= sizeof(si
);
3534 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
3535 if (GetWindowLongW(hWnd
, GWL_STYLE
) & ES_DISABLENOSCROLL
)
3536 si
.fMask
|= SIF_DISABLENOSCROLL
;
3537 si
.nMax
= (si
.fMask
& SIF_DISABLENOSCROLL
) ? 1 : 0;
3540 SetScrollInfo(hWnd
, SB_VERT
, &si
, TRUE
);
3542 ME_CommitUndo(editor
);
3543 ME_WrapMarkedParagraphs(editor
);
3544 ME_MoveCaret(editor
);
3548 ME_DestroyEditor(editor
);
3549 SetWindowLongPtrW(hWnd
, 0, 0);
3553 return ME_SetCursor(editor
);
3555 case WM_LBUTTONDBLCLK
:
3556 case WM_LBUTTONDOWN
:
3558 ME_CommitUndo(editor
); /* End coalesced undos for typed characters */
3559 if ((editor
->nEventMask
& ENM_MOUSEEVENTS
) &&
3560 !ME_FilterEvent(editor
, msg
, &wParam
, &lParam
))
3563 ME_LButtonDown(editor
, (short)LOWORD(lParam
), (short)HIWORD(lParam
),
3564 ME_CalculateClickCount(hWnd
, msg
, wParam
, lParam
));
3566 ME_LinkNotify(editor
,msg
,wParam
,lParam
);
3567 if (!ME_SetCursor(editor
)) goto do_default
;
3571 if ((editor
->nEventMask
& ENM_MOUSEEVENTS
) &&
3572 !ME_FilterEvent(editor
, msg
, &wParam
, &lParam
))
3574 if (GetCapture() == hWnd
)
3575 ME_MouseMove(editor
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
3576 ME_LinkNotify(editor
,msg
,wParam
,lParam
);
3577 /* Set cursor if mouse is captured, since WM_SETCURSOR won't be received. */
3578 if (GetCapture() == hWnd
)
3579 ME_SetCursor(editor
);
3582 if (GetCapture() == hWnd
)
3584 if (editor
->nSelectionType
== stDocument
)
3585 editor
->nSelectionType
= stPosition
;
3586 if ((editor
->nEventMask
& ENM_MOUSEEVENTS
) &&
3587 !ME_FilterEvent(editor
, msg
, &wParam
, &lParam
))
3591 ME_SetCursor(editor
);
3592 ME_LinkNotify(editor
,msg
,wParam
,lParam
);
3596 case WM_RBUTTONDOWN
:
3597 ME_CommitUndo(editor
); /* End coalesced undos for typed characters */
3598 if ((editor
->nEventMask
& ENM_MOUSEEVENTS
) &&
3599 !ME_FilterEvent(editor
, msg
, &wParam
, &lParam
))
3602 case WM_CONTEXTMENU
:
3603 if (!ME_ShowContextMenu(editor
, (short)LOWORD(lParam
), (short)HIWORD(lParam
)))
3607 if (editor
->bRedraw
)
3612 hDC
= BeginPaint(hWnd
, &ps
);
3613 ME_PaintContent(editor
, hDC
, FALSE
, &ps
.rcPaint
);
3614 EndPaint(hWnd
, &ps
);
3618 editor
->bHaveFocus
= TRUE
;
3619 ME_ShowCaret(editor
);
3620 ME_SendOldNotify(editor
, EN_SETFOCUS
);
3623 ME_CommitUndo(editor
); /* End coalesced undos for typed characters */
3624 editor
->bHaveFocus
= FALSE
;
3625 ME_HideCaret(editor
);
3626 ME_SendOldNotify(editor
, EN_KILLFOCUS
);
3630 if (editor
->bRedraw
)
3632 HDC hDC
= (HDC
)wParam
;
3634 if (GetUpdateRect(hWnd
,&rc
,TRUE
))
3636 FillRect(hDC
, &rc
, editor
->hbrBackground
);
3642 TRACE("editor wnd command = %d\n", LOWORD(wParam
));
3645 if ((editor
->nEventMask
& ENM_KEYEVENTS
) &&
3646 !ME_FilterEvent(editor
, msg
, &wParam
, &lParam
))
3650 if ((editor
->nEventMask
& ENM_KEYEVENTS
) &&
3651 !ME_FilterEvent(editor
, msg
, &wParam
, &lParam
))
3653 if (ME_KeyDown(editor
, LOWORD(wParam
)))
3661 wstr
= (WCHAR
)wParam
;
3664 CHAR charA
= wParam
;
3665 MultiByteToWideChar(CP_ACP
, 0, &charA
, 1, &wstr
, 1);
3670 case 1: /* Ctrl-A */
3671 ME_SetSelection(editor
, 0, -1);
3673 case 3: /* Ctrl-C */
3674 SendMessageW(editor
->hWnd
, WM_COPY
, 0, 0);
3678 if (GetWindowLongW(editor
->hWnd
, GWL_STYLE
) & ES_READONLY
) {
3679 MessageBeep(MB_ICONERROR
);
3680 return 0; /* FIXME really 0 ? */
3685 case 22: /* Ctrl-V */
3686 SendMessageW(editor
->hWnd
, WM_PASTE
, 0, 0);
3688 case 24: /* Ctrl-X */
3689 SendMessageW(editor
->hWnd
, WM_CUT
, 0, 0);
3691 case 25: /* Ctrl-Y */
3692 SendMessageW(editor
->hWnd
, EM_REDO
, 0, 0);
3694 case 26: /* Ctrl-Z */
3695 SendMessageW(editor
->hWnd
, EM_UNDO
, 0, 0);
3698 if (((unsigned)wstr
)>=' '
3699 || (wstr
=='\r' && (GetWindowLongW(hWnd
, GWL_STYLE
) & ES_MULTILINE
))
3701 ME_Cursor cursor
= editor
->pCursors
[0];
3702 ME_DisplayItem
*para
= ME_GetParagraph(cursor
.pRun
);
3704 BOOL ctrl_is_down
= GetKeyState(VK_CONTROL
) & 0x8000;
3705 ME_GetSelection(editor
, &from
, &to
);
3707 /* v4.1 allows tabs to be inserted with ctrl key down */
3708 && !(ctrl_is_down
&& !editor
->bEmulateVersion10
)
3711 ME_DisplayItem
*para
;
3712 BOOL bSelectedRow
= FALSE
;
3714 para
= ME_GetParagraph(cursor
.pRun
);
3715 if (ME_IsSelection(editor
) &&
3716 cursor
.pRun
->member
.run
.nCharOfs
+ cursor
.nOffset
== 0 &&
3717 to
== ME_GetCursorOfs(editor
, 0) &&
3718 para
->member
.para
.prev_para
->type
== diParagraph
)
3720 para
= para
->member
.para
.prev_para
;
3721 bSelectedRow
= TRUE
;
3723 if (ME_IsInTable(para
))
3725 ME_TabPressedInTable(editor
, bSelectedRow
);
3726 ME_CommitUndo(editor
);
3729 } else if (!editor
->bEmulateVersion10
) { /* v4.1 */
3730 if (para
->member
.para
.nFlags
& MEPF_ROWEND
) {
3732 /* Add a new table row after this row. */
3733 para
= ME_AppendTableRow(editor
, para
);
3734 para
= para
->member
.para
.next_para
;
3735 editor
->pCursors
[0].pRun
= ME_FindItemFwd(para
, diRun
);
3736 editor
->pCursors
[0].nOffset
= 0;
3737 editor
->pCursors
[1] = editor
->pCursors
[0];
3738 ME_CommitUndo(editor
);
3739 ME_CheckTablesForCorruption(editor
);
3740 ME_UpdateRepaint(editor
);
3742 } else if (from
== to
) {
3743 para
= para
->member
.para
.next_para
;
3744 if (para
->member
.para
.nFlags
& MEPF_ROWSTART
)
3745 para
= para
->member
.para
.next_para
;
3746 editor
->pCursors
[0].pRun
= ME_FindItemFwd(para
, diRun
);
3747 editor
->pCursors
[0].nOffset
= 0;
3748 editor
->pCursors
[1] = editor
->pCursors
[0];
3751 else if (para
== ME_GetParagraph(editor
->pCursors
[1].pRun
) &&
3752 cursor
.nOffset
+ cursor
.pRun
->member
.run
.nCharOfs
== 0 &&
3753 para
->member
.para
.prev_para
->member
.para
.nFlags
& MEPF_ROWSTART
&&
3754 !para
->member
.para
.prev_para
->member
.para
.nCharOfs
)
3756 /* Insert a newline before the table. */
3758 para
= para
->member
.para
.prev_para
;
3759 para
->member
.para
.nFlags
&= ~MEPF_ROWSTART
;
3760 editor
->pCursors
[0].pRun
= ME_FindItemFwd(para
, diRun
);
3761 editor
->pCursors
[1] = editor
->pCursors
[0];
3762 ME_InsertTextFromCursor(editor
, 0, &endl
, 1,
3763 editor
->pCursors
[0].pRun
->member
.run
.style
);
3764 para
= editor
->pBuffer
->pFirst
->member
.para
.next_para
;
3765 ME_SetDefaultParaFormat(para
->member
.para
.pFmt
);
3766 para
->member
.para
.nFlags
= MEPF_REWRAP
;
3767 editor
->pCursors
[0].pRun
= ME_FindItemFwd(para
, diRun
);
3768 editor
->pCursors
[1] = editor
->pCursors
[0];
3769 para
->member
.para
.next_para
->member
.para
.nFlags
|= MEPF_ROWSTART
;
3770 ME_CommitCoalescingUndo(editor
);
3771 ME_CheckTablesForCorruption(editor
);
3772 ME_UpdateRepaint(editor
);
3775 } else { /* v1.0 - 3.0 */
3776 ME_DisplayItem
*para
= ME_GetParagraph(cursor
.pRun
);
3777 if (ME_IsInTable(cursor
.pRun
))
3779 if (cursor
.pRun
->member
.run
.nFlags
& MERF_ENDPARA
)
3783 ME_ContinueCoalescingTransaction(editor
);
3784 para
= ME_AppendTableRow(editor
, para
);
3785 editor
->pCursors
[0].pRun
= ME_FindItemFwd(para
, diRun
);
3786 editor
->pCursors
[0].nOffset
= 0;
3787 editor
->pCursors
[1] = editor
->pCursors
[0];
3788 ME_CommitCoalescingUndo(editor
);
3789 ME_UpdateRepaint(editor
);
3791 /* Text should not be inserted at the end of the table. */
3796 } else if (wstr
== '\r') {
3797 ME_ContinueCoalescingTransaction(editor
);
3798 if (cursor
.pRun
->member
.run
.nCharOfs
+ cursor
.nOffset
== 0 &&
3799 !ME_IsInTable(para
->member
.para
.prev_para
))
3801 /* Insert newline before table */
3803 cursor
.pRun
= ME_FindItemBack(para
, diRun
);
3805 editor
->pCursors
[0].pRun
= cursor
.pRun
;
3806 editor
->pCursors
[0].nOffset
= 0;
3807 editor
->pCursors
[1] = editor
->pCursors
[0];
3808 ME_InsertTextFromCursor(editor
, 0, &endl
, 1,
3809 editor
->pCursors
[0].pRun
->member
.run
.style
);
3811 editor
->pCursors
[1] = editor
->pCursors
[0];
3812 para
= ME_AppendTableRow(editor
, para
);
3813 editor
->pCursors
[0].pRun
= ME_FindItemFwd(para
, diRun
);
3814 editor
->pCursors
[0].nOffset
= 0;
3815 editor
->pCursors
[1] = editor
->pCursors
[0];
3817 ME_CommitCoalescingUndo(editor
);
3818 ME_UpdateRepaint(editor
);
3823 /* FIXME maybe it would make sense to call EM_REPLACESEL instead ? */
3824 /* WM_CHAR is restricted to nTextLimit */
3825 if(editor
->nTextLimit
> ME_GetTextLength(editor
) - (to
-from
))
3827 ME_Style
*style
= ME_GetInsertStyle(editor
, 0);
3828 ME_SaveTempStyle(editor
);
3829 ME_ContinueCoalescingTransaction(editor
);
3830 if (wstr
== '\r' && (GetKeyState(VK_SHIFT
) & 0x8000))
3831 ME_InsertEndRowFromCursor(editor
, 0);
3833 ME_InsertTextFromCursor(editor
, 0, &wstr
, 1, style
);
3834 ME_ReleaseStyle(style
);
3835 ME_CommitCoalescingUndo(editor
);
3839 if (editor
->AutoURLDetect_bEnable
) ME_UpdateSelectionLinkAttribute(editor
);
3841 ME_UpdateRepaint(editor
);
3848 if(wParam
== UNICODE_NOCHAR
) return TRUE
;
3849 if(wParam
<= 0x000fffff)
3851 if(wParam
> 0xffff) /* convert to surrogates */
3854 SendMessageW(editor
->hWnd
, WM_CHAR
, (wParam
>> 10) + 0xd800, 0);
3855 SendMessageW(editor
->hWnd
, WM_CHAR
, (wParam
& 0x03ff) + 0xdc00, 0);
3857 else SendMessageW(editor
->hWnd
, WM_CHAR
, wParam
, 0);
3862 case EM_STOPGROUPTYPING
:
3863 ME_CommitUndo(editor
); /* End coalesced undos for typed characters */
3865 case EM_SCROLL
: /* fall through */
3871 origNPos
= ME_GetYScrollPos(editor
);
3874 if (editor
&& editor
->pBuffer
&& editor
->pBuffer
->pDefaultStyle
)
3875 lineHeight
= editor
->pBuffer
->pDefaultStyle
->tm
.tmHeight
;
3876 if (lineHeight
<= 0) lineHeight
= 24;
3878 switch(LOWORD(wParam
))
3881 ME_ScrollUp(editor
,lineHeight
);
3884 ME_ScrollDown(editor
,lineHeight
);
3887 ME_ScrollUp(editor
,editor
->sizeWindow
.cy
);
3890 ME_ScrollDown(editor
,editor
->sizeWindow
.cy
);
3893 case SB_THUMBPOSITION
:
3894 ME_ScrollAbs(editor
,HIWORD(wParam
));
3897 if (msg
== EM_SCROLL
)
3898 return 0x00010000 | (((ME_GetYScrollPos(editor
) - origNPos
)/lineHeight
) & 0xffff);
3904 UINT pulScrollLines
;
3906 if ((editor
->nEventMask
& ENM_MOUSEEVENTS
) &&
3907 !ME_FilterEvent(editor
, msg
, &wParam
, &lParam
))
3910 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
3911 gcWheelDelta
= -GET_WHEEL_DELTA_WPARAM(wParam
);
3913 if (abs(gcWheelDelta
) >= WHEEL_DELTA
&& pulScrollLines
)
3915 /* FIXME follow the original */
3916 ME_ScrollDown(editor
,pulScrollLines
* (gcWheelDelta
/ WHEEL_DELTA
) * 8);
3922 *((RECT
*)lParam
) = editor
->rcFormat
;
3930 RECT
*rc
= (RECT
*)lParam
;
3934 editor
->rcFormat
.left
+= rc
->left
;
3935 editor
->rcFormat
.top
+= rc
->top
;
3936 editor
->rcFormat
.right
+= rc
->right
;
3937 editor
->rcFormat
.bottom
+= rc
->bottom
;
3941 editor
->rcFormat
= *rc
;
3946 GetClientRect(hWnd
, &editor
->rcFormat
);
3948 if (msg
!= EM_SETRECTNP
)
3949 ME_RewrapRepaint(editor
);
3952 case EM_REQUESTRESIZE
:
3953 ME_SendRequestResize(editor
, TRUE
);
3956 if ((editor
->bRedraw
= wParam
))
3957 ME_RewrapRepaint(editor
);
3961 GetClientRect(hWnd
, &editor
->rcFormat
);
3962 ME_RewrapRepaint(editor
);
3963 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
3965 /* IME messages to make richedit controls IME aware */
3966 case WM_IME_SETCONTEXT
:
3967 case WM_IME_CONTROL
:
3969 case WM_IME_COMPOSITIONFULL
:
3971 case WM_IME_STARTCOMPOSITION
:
3973 editor
->imeStartIndex
=ME_GetCursorOfs(editor
,0);
3974 ME_DeleteSelection(editor
);
3975 ME_CommitUndo(editor
);
3976 ME_UpdateRepaint(editor
);
3979 case WM_IME_COMPOSITION
:
3983 ME_Style
*style
= ME_GetInsertStyle(editor
, 0);
3984 hIMC
= ImmGetContext(hWnd
);
3985 ME_DeleteSelection(editor
);
3986 ME_CommitUndo(editor
);
3987 ME_SaveTempStyle(editor
);
3988 if (lParam
& GCS_RESULTSTR
)
3990 LPWSTR lpCompStr
= NULL
;
3993 dwBufLen
= ImmGetCompositionStringW(hIMC
, GCS_RESULTSTR
, NULL
, 0);
3994 lpCompStr
= HeapAlloc(GetProcessHeap(),0,dwBufLen
+ sizeof(WCHAR
));
3995 ImmGetCompositionStringW(hIMC
, GCS_RESULTSTR
, lpCompStr
, dwBufLen
);
3996 lpCompStr
[dwBufLen
/sizeof(WCHAR
)] = 0;
3997 ME_InsertTextFromCursor(editor
,0,lpCompStr
,dwBufLen
/sizeof(WCHAR
),style
);
3999 else if (lParam
& GCS_COMPSTR
)
4001 LPWSTR lpCompStr
= NULL
;
4004 dwBufLen
= ImmGetCompositionStringW(hIMC
, GCS_COMPSTR
, NULL
, 0);
4005 lpCompStr
= HeapAlloc(GetProcessHeap(),0,dwBufLen
+ sizeof(WCHAR
));
4006 ImmGetCompositionStringW(hIMC
, GCS_COMPSTR
, lpCompStr
, dwBufLen
);
4007 lpCompStr
[dwBufLen
/sizeof(WCHAR
)] = 0;
4009 ME_InsertTextFromCursor(editor
,0,lpCompStr
,dwBufLen
/sizeof(WCHAR
),style
);
4010 ME_SetSelection(editor
,editor
->imeStartIndex
,
4011 editor
->imeStartIndex
+ dwBufLen
/sizeof(WCHAR
));
4013 ME_ReleaseStyle(style
);
4014 ME_UpdateRepaint(editor
);
4017 case WM_IME_ENDCOMPOSITION
:
4019 ME_DeleteSelection(editor
);
4020 editor
->imeStartIndex
=-1;
4023 case EM_GETOLEINTERFACE
:
4025 LPVOID
*ppvObj
= (LPVOID
*) lParam
;
4026 return CreateIRichEditOle(editor
, ppvObj
);
4028 case EM_GETPASSWORDCHAR
:
4030 return editor
->cPasswordMask
;
4032 case EM_SETOLECALLBACK
:
4033 if(editor
->lpOleCallback
)
4034 IUnknown_Release(editor
->lpOleCallback
);
4035 editor
->lpOleCallback
= (LPRICHEDITOLECALLBACK
)lParam
;
4036 if(editor
->lpOleCallback
)
4037 IUnknown_AddRef(editor
->lpOleCallback
);
4039 case EM_GETWORDBREAKPROC
:
4040 return (LRESULT
)editor
->pfnWordBreak
;
4041 case EM_SETWORDBREAKPROC
:
4043 EDITWORDBREAKPROCW pfnOld
= editor
->pfnWordBreak
;
4045 editor
->pfnWordBreak
= (EDITWORDBREAKPROCW
)lParam
;
4046 return (LRESULT
)pfnOld
;
4048 case EM_SETTEXTMODE
:
4053 ret
= RichEditWndProc_common(hWnd
, WM_GETTEXTLENGTH
, 0, 0, unicode
);
4056 /*Check for valid wParam*/
4057 if ((((wParam
& TM_RICHTEXT
) && ((wParam
& TM_PLAINTEXT
) << 1))) ||
4058 (((wParam
& TM_MULTILEVELUNDO
) && ((wParam
& TM_SINGLELEVELUNDO
) << 1))) ||
4059 (((wParam
& TM_MULTICODEPAGE
) && ((wParam
& TM_SINGLECODEPAGE
) << 1))))
4063 if (wParam
& (TM_RICHTEXT
| TM_PLAINTEXT
))
4065 mask
|= (TM_RICHTEXT
| TM_PLAINTEXT
);
4066 changes
|= (wParam
& (TM_RICHTEXT
| TM_PLAINTEXT
));
4068 /*FIXME: Currently no support for undo level and code page options*/
4069 editor
->mode
= (editor
->mode
& (~mask
)) | changes
;
4075 case EM_SETPASSWORDCHAR
:
4077 editor
->cPasswordMask
= wParam
;
4078 ME_RewrapRepaint(editor
);
4081 case EM_SETTARGETDEVICE
:
4084 BOOL
new = (lParam
== 0);
4085 if (editor
->bWordWrap
!= new)
4087 editor
->bWordWrap
= new;
4088 ME_RewrapRepaint(editor
);
4091 else FIXME("Unsupported yet non NULL device in EM_SETTARGETDEVICE\n");
4095 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
4100 static LRESULT WINAPI
RichEditWndProcW(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
4102 BOOL unicode
= TRUE
;
4104 /* Under Win9x RichEdit20W returns ANSI strings, see the tests. */
4105 if (msg
== WM_GETTEXT
&& (GetVersion() & 0x80000000))
4108 return RichEditWndProc_common(hWnd
, msg
, wParam
, lParam
, unicode
);
4111 static LRESULT WINAPI
RichEditWndProcA(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
4113 return RichEditWndProc_common(hWnd
, msg
, wParam
, lParam
, FALSE
);
4116 /******************************************************************
4117 * RichEditANSIWndProc (RICHED20.10)
4119 LRESULT WINAPI
RichEditANSIWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
4121 return RichEditWndProcA(hWnd
, msg
, wParam
, lParam
);
4124 /******************************************************************
4125 * RichEdit10ANSIWndProc (RICHED20.9)
4127 LRESULT WINAPI
RichEdit10ANSIWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
4131 /* FIXME: this is NOT the same as 2.0 version */
4132 result
= RichEditANSIWndProc(hWnd
, msg
, wParam
, lParam
);
4133 if (msg
== WM_NCCREATE
)
4135 ME_TextEditor
*editor
= (ME_TextEditor
*)GetWindowLongPtrW(hWnd
, 0);
4137 editor
->bEmulateVersion10
= TRUE
;
4138 editor
->pBuffer
->pLast
->member
.para
.nCharOfs
= 2;
4139 assert(editor
->pBuffer
->pLast
->prev
->type
== diRun
);
4140 assert(editor
->pBuffer
->pLast
->prev
->member
.run
.nFlags
& MERF_ENDPARA
);
4141 editor
->pBuffer
->pLast
->prev
->member
.run
.nLF
= 1;
4146 void ME_SendOldNotify(ME_TextEditor
*editor
, int nCode
)
4148 HWND hWnd
= editor
->hWnd
;
4149 SendMessageA(GetParent(hWnd
), WM_COMMAND
, (nCode
<<16)|GetWindowLongW(hWnd
, GWLP_ID
), (LPARAM
)hWnd
);
4152 void ME_LinkNotify(ME_TextEditor
*editor
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
4155 ME_Cursor tmpCursor
;
4157 int nCharOfs
; /* The start of the clicked text. Absolute character offset */
4162 x
= (short)LOWORD(lParam
);
4163 y
= (short)HIWORD(lParam
);
4164 nCharOfs
= ME_CharFromPos(editor
, x
, y
, &isExact
);
4165 if (!isExact
) return;
4167 ME_CursorFromCharOfs(editor
, nCharOfs
, &tmpCursor
);
4168 tmpRun
= &tmpCursor
.pRun
->member
.run
;
4170 if ((tmpRun
->style
->fmt
.dwMask
& CFM_LINK
)
4171 && (tmpRun
->style
->fmt
.dwEffects
& CFE_LINK
))
4172 { /* The clicked run has CFE_LINK set */
4173 info
.nmhdr
.hwndFrom
= editor
->hWnd
;
4174 info
.nmhdr
.idFrom
= GetWindowLongW(editor
->hWnd
, GWLP_ID
);
4175 info
.nmhdr
.code
= EN_LINK
;
4177 info
.wParam
= wParam
;
4178 info
.lParam
= lParam
;
4179 info
.chrg
.cpMin
= ME_CharOfsFromRunOfs(editor
,tmpCursor
.pRun
,0);
4180 info
.chrg
.cpMax
= info
.chrg
.cpMin
+ ME_StrVLen(tmpRun
->strText
);
4181 SendMessageW(GetParent(editor
->hWnd
), WM_NOTIFY
,info
.nmhdr
.idFrom
, (LPARAM
)&info
);
4185 int ME_CountParagraphsBetween(ME_TextEditor
*editor
, int from
, int to
)
4187 ME_DisplayItem
*item
= ME_FindItemFwd(editor
->pBuffer
->pFirst
, diParagraph
);
4190 while(item
&& item
->member
.para
.next_para
->member
.para
.nCharOfs
<= from
)
4191 item
= item
->member
.para
.next_para
;
4194 while(item
&& item
->member
.para
.next_para
->member
.para
.nCharOfs
<= to
) {
4195 item
= item
->member
.para
.next_para
;
4202 int ME_GetTextW(ME_TextEditor
*editor
, WCHAR
*buffer
, int nStart
, int nChars
, int bCRLF
)
4204 ME_DisplayItem
*item
= ME_FindItemAtOffset(editor
, diRun
, nStart
, &nStart
);
4206 WCHAR
*pStart
= buffer
;
4213 /* bCRLF flag is only honored in 2.0 and up. 1.0 must always return text verbatim */
4214 if (editor
->bEmulateVersion10
) bCRLF
= 0;
4218 int nLen
= ME_StrLen(item
->member
.run
.strText
) - nStart
;
4221 CopyMemory(buffer
, item
->member
.run
.strText
->szData
+ nStart
, sizeof(WCHAR
)*nLen
);
4230 item
= ME_FindItemFwd(item
, diRun
);
4233 while(nChars
&& item
)
4235 int nLen
= ME_StrLen(item
->member
.run
.strText
);
4236 if (item
->member
.run
.nFlags
& MERF_ENDPARA
)
4237 nLen
= item
->member
.run
.nCR
+ item
->member
.run
.nLF
;
4241 if (item
->member
.run
.nFlags
& MERF_ENDCELL
&&
4242 item
->member
.run
.nFlags
& MERF_ENDPARA
)
4246 else if (item
->member
.run
.nFlags
& MERF_ENDPARA
)
4248 if (!ME_FindItemFwd(item
, diRun
))
4249 /* No '\r' is appended to the last paragraph. */
4251 else if (bCRLF
&& nChars
== 1) {
4257 /* richedit 2.0 case - actual line-break is \r but should report \r\n */
4258 if (ME_GetParagraph(item
)->member
.para
.nFlags
& (MEPF_ROWSTART
|MEPF_ROWEND
))
4263 *buffer
= '\n'; /* Later updated by nLen==1 at the end of the loop */
4273 /* richedit 2.0 verbatim has only \r. richedit 1.0 should honor encodings */
4275 while (nChars
- i
> 0 && i
< item
->member
.run
.nCR
)
4277 buffer
[i
] = '\r'; i
++;
4280 while (nChars
- i
- j
> 0 && j
< item
->member
.run
.nLF
)
4282 buffer
[i
+j
] = '\n'; j
++;
4288 CopyMemory(buffer
, item
->member
.run
.strText
->szData
, sizeof(WCHAR
)*nLen
);
4295 TRACE("nWritten=%d, actual=%d\n", nWritten
, buffer
-pStart
);
4299 item
= ME_FindItemFwd(item
, diRun
);
4302 TRACE("nWritten=%d, actual=%d\n", nWritten
, buffer
-pStart
);
4306 static BOOL
ME_RegisterEditorClass(HINSTANCE hInstance
)
4311 wcW
.style
= CS_DBLCLKS
| CS_HREDRAW
| CS_VREDRAW
| CS_GLOBALCLASS
;
4312 wcW
.lpfnWndProc
= RichEditWndProcW
;
4314 wcW
.cbWndExtra
= sizeof(ME_TextEditor
*);
4315 wcW
.hInstance
= NULL
; /* hInstance would register DLL-local class */
4317 wcW
.hCursor
= LoadCursorW(NULL
, MAKEINTRESOURCEW(IDC_IBEAM
));
4318 wcW
.hbrBackground
= (HBRUSH
)GetStockObject(NULL_BRUSH
);
4319 wcW
.lpszMenuName
= NULL
;
4321 if (is_version_nt())
4323 wcW
.lpszClassName
= RichEdit20W
;
4324 if (!RegisterClassW(&wcW
)) return FALSE
;
4325 wcW
.lpszClassName
= RichEdit50W
;
4326 if (!RegisterClassW(&wcW
)) return FALSE
;
4330 /* WNDCLASSA/W have the same layout */
4331 wcW
.lpszClassName
= (LPCWSTR
)"RichEdit20W";
4332 if (!RegisterClassA((WNDCLASSA
*)&wcW
)) return FALSE
;
4333 wcW
.lpszClassName
= (LPCWSTR
)"RichEdit50W";
4334 if (!RegisterClassA((WNDCLASSA
*)&wcW
)) return FALSE
;
4337 wcA
.style
= CS_DBLCLKS
| CS_HREDRAW
| CS_VREDRAW
| CS_GLOBALCLASS
;
4338 wcA
.lpfnWndProc
= RichEditWndProcA
;
4340 wcA
.cbWndExtra
= sizeof(ME_TextEditor
*);
4341 wcA
.hInstance
= NULL
; /* hInstance would register DLL-local class */
4343 wcA
.hCursor
= LoadCursorW(NULL
, MAKEINTRESOURCEW(IDC_IBEAM
));
4344 wcA
.hbrBackground
= (HBRUSH
)GetStockObject(NULL_BRUSH
);
4345 wcA
.lpszMenuName
= NULL
;
4346 wcA
.lpszClassName
= "RichEdit20A";
4347 if (!RegisterClassA(&wcA
)) return FALSE
;
4348 wcA
.lpszClassName
= "RichEdit50A";
4349 if (!RegisterClassA(&wcA
)) return FALSE
;
4354 LRESULT WINAPI
REComboWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
) {
4355 /* FIXME: Not implemented */
4356 TRACE("hWnd %p msg %04x (%s) %08lx %08lx\n",
4357 hWnd
, msg
, get_msg_name(msg
), wParam
, lParam
);
4358 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
4361 LRESULT WINAPI
REListWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
) {
4362 /* FIXME: Not implemented */
4363 TRACE("hWnd %p msg %04x (%s) %08lx %08lx\n",
4364 hWnd
, msg
, get_msg_name(msg
), wParam
, lParam
);
4365 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
4368 /******************************************************************
4369 * REExtendedRegisterClass (RICHED20.8)
4371 * FIXME undocumented
4372 * Need to check for errors and implement controls and callbacks
4374 LRESULT WINAPI
REExtendedRegisterClass(void)
4379 FIXME("semi stub\n");
4383 wcW
.hInstance
= NULL
;
4386 wcW
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+1);
4387 wcW
.lpszMenuName
= NULL
;
4389 if (!ME_ListBoxRegistered
)
4391 wcW
.style
= CS_PARENTDC
| CS_DBLCLKS
| CS_GLOBALCLASS
;
4392 wcW
.lpfnWndProc
= REListWndProc
;
4393 wcW
.lpszClassName
= REListBox20W
;
4394 if (RegisterClassW(&wcW
)) ME_ListBoxRegistered
= TRUE
;
4397 if (!ME_ComboBoxRegistered
)
4399 wcW
.style
= CS_PARENTDC
| CS_DBLCLKS
| CS_GLOBALCLASS
| CS_VREDRAW
| CS_HREDRAW
;
4400 wcW
.lpfnWndProc
= REComboWndProc
;
4401 wcW
.lpszClassName
= REComboBox20W
;
4402 if (RegisterClassW(&wcW
)) ME_ComboBoxRegistered
= TRUE
;
4406 if (ME_ListBoxRegistered
)
4408 if (ME_ComboBoxRegistered
)
4414 int ME_AutoURLDetect(ME_TextEditor
*editor
, WCHAR curChar
)
4434 int curf_ef
, link_ef
, def_ef
;
4435 int cur_prefx
, prefx_cnt
;
4436 int sel_min
, sel_max
;
4439 int URLmin
, URLmax
= 0;
4441 CHARFORMAT2W cur_format
;
4442 CHARFORMAT2W default_format
;
4444 RichEditANSIWndProc(editor
->hWnd
, EM_EXGETSEL
, (WPARAM
) 0, (LPARAM
) &ins_pt
);
4445 sel_min
= ins_pt
.cpMin
;
4446 sel_max
= ins_pt
.cpMax
;
4447 if (sel_min
==sel_max
)
4449 if (sel_min
!=sel_max
)
4450 car_pos
= ME_GetTextLength(editor
)+1;
4451 cur_format
.cbSize
= sizeof(cur_format
);
4452 default_format
.cbSize
= sizeof(default_format
);
4453 RichEditANSIWndProc(editor
->hWnd
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
) &cur_format
);
4454 RichEditANSIWndProc(editor
->hWnd
, EM_GETCHARFORMAT
, SCF_DEFAULT
, (LPARAM
) &default_format
);
4455 link
.cbSize
= sizeof(link
);
4456 link
.dwMask
= CFM_LINK
;
4457 link
.dwEffects
= CFE_LINK
;
4458 curf_ef
= cur_format
.dwEffects
& link
.dwEffects
;
4459 def_ef
= default_format
.dwEffects
& link
.dwEffects
;
4460 link_ef
= link
.dwEffects
& link
.dwEffects
;
4461 if (curf_ef
== link_ef
)
4463 if( curChar
== '\n' || curChar
=='\r' || curChar
==' ')
4465 ME_SetSelection(editor
, car_pos
, car_pos
);
4466 RichEditANSIWndProc(editor
->hWnd
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
) &default_format
);
4471 if (curf_ef
== def_ef
)
4474 prefx_cnt
= (sizeof(prefixes
)/sizeof(struct prefix_s
))-1;
4475 while (cur_prefx
<=prefx_cnt
)
4479 ft
.lpstrText
= prefixes
[cur_prefx
].text
;
4480 URLmin
=max(0,(car_pos
-prefixes
[cur_prefx
].length
));
4481 URLmax
=max(0, car_pos
);
4482 if ((car_pos
== 0) && (ME_GetTextLength(editor
) != 0))
4484 URLmax
= ME_GetTextLength(editor
)+1;
4486 ft
.chrg
.cpMin
= URLmin
;
4487 ft
.chrg
.cpMax
= URLmax
;
4488 text_pos
=RichEditANSIWndProc(editor
->hWnd
, EM_FINDTEXT
, FR_DOWN
, (LPARAM
)&ft
);
4493 ME_SetCharFormat(editor
, text_pos
, (URLmax
-text_pos
), &link
);
4494 ME_RewrapRepaint(editor
);
4503 static BOOL
isurlspecial(WCHAR c
)
4505 static const WCHAR special_chars
[] = {'.','/','%','@','*','|','\\','+','#',0};
4506 return strchrW( special_chars
, c
) != NULL
;
4510 * This proc takes a selection, and scans it forward in order to select the span
4511 * of a possible URL candidate. A possible URL candidate must start with isalnum
4512 * or one of the following special characters: *|/\+%#@ and must consist entirely
4513 * of the characters allowed to start the URL, plus : (colon) which may occur
4514 * at most once, and not at either end.
4516 * sel_max == -1 indicates scan to end of text.
4518 BOOL
ME_FindNextURLCandidate(ME_TextEditor
*editor
, int sel_min
, int sel_max
,
4519 int * candidate_min
, int * candidate_max
)
4521 ME_DisplayItem
* item
;
4522 ME_DisplayItem
* para
;
4524 BOOL foundColon
= FALSE
;
4525 WCHAR lastAcceptedChar
= '\0';
4527 TRACE("sel_min = %d sel_max = %d\n", sel_min
, sel_max
);
4529 *candidate_min
= *candidate_max
= -1;
4530 item
= ME_FindItemAtOffset(editor
, diRun
, sel_min
, &nStart
);
4531 if (!item
) return FALSE
;
4532 TRACE("nStart = %d\n", nStart
);
4533 para
= ME_GetParagraph(item
);
4534 if (sel_max
== -1) sel_max
= ME_GetTextLength(editor
);
4535 while (item
&& para
->member
.para
.nCharOfs
+ item
->member
.run
.nCharOfs
+ nStart
< sel_max
)
4537 ME_DisplayItem
* next_item
;
4539 if (!(item
->member
.run
.nFlags
& MERF_ENDPARA
)) {
4540 /* Find start of candidate */
4541 if (*candidate_min
== -1) {
4542 while (nStart
< ME_StrLen(item
->member
.run
.strText
) &&
4543 !(isalnumW(item
->member
.run
.strText
->szData
[nStart
]) ||
4544 isurlspecial(item
->member
.run
.strText
->szData
[nStart
]))) {
4547 if (nStart
< ME_StrLen(item
->member
.run
.strText
) &&
4548 (isalnumW(item
->member
.run
.strText
->szData
[nStart
]) ||
4549 isurlspecial(item
->member
.run
.strText
->szData
[nStart
]))) {
4550 *candidate_min
= para
->member
.para
.nCharOfs
+ item
->member
.run
.nCharOfs
+ nStart
;
4551 lastAcceptedChar
= item
->member
.run
.strText
->szData
[nStart
];
4556 /* Find end of candidate */
4557 if (*candidate_min
>= 0) {
4558 while (nStart
< ME_StrLen(item
->member
.run
.strText
) &&
4559 (isalnumW(item
->member
.run
.strText
->szData
[nStart
]) ||
4560 isurlspecial(item
->member
.run
.strText
->szData
[nStart
]) ||
4561 (!foundColon
&& item
->member
.run
.strText
->szData
[nStart
] == ':') )) {
4562 if (item
->member
.run
.strText
->szData
[nStart
] == ':') foundColon
= TRUE
;
4563 lastAcceptedChar
= item
->member
.run
.strText
->szData
[nStart
];
4566 if (nStart
< ME_StrLen(item
->member
.run
.strText
) &&
4567 !(isalnumW(item
->member
.run
.strText
->szData
[nStart
]) ||
4568 isurlspecial(item
->member
.run
.strText
->szData
[nStart
]) )) {
4569 *candidate_max
= para
->member
.para
.nCharOfs
+ item
->member
.run
.nCharOfs
+ nStart
;
4571 if (lastAcceptedChar
== ':') (*candidate_max
)--;
4576 /* End of paragraph: skip it if before candidate span, or terminates
4577 current active span */
4578 if (*candidate_min
>= 0) {
4579 *candidate_max
= para
->member
.para
.nCharOfs
+ item
->member
.run
.nCharOfs
;
4580 if (lastAcceptedChar
== ':') (*candidate_max
)--;
4585 /* Reaching this point means no span was found, so get next span */
4586 next_item
= ME_FindItemFwd(item
, diRun
);
4588 if (*candidate_min
>= 0) {
4589 /* There are no further runs, so take end of text as end of candidate */
4590 *candidate_max
= para
->member
.para
.nCharOfs
+ item
->member
.run
.nCharOfs
+ nStart
;
4591 if (lastAcceptedChar
== ':') (*candidate_max
)--;
4596 para
= ME_GetParagraph(item
);
4601 if (*candidate_min
>= 0) {
4602 /* There are no further runs, so take end of text as end of candidate */
4603 *candidate_max
= para
->member
.para
.nCharOfs
+ item
->member
.run
.nCharOfs
+ nStart
;
4604 if (lastAcceptedChar
== ':') (*candidate_max
)--;
4612 * This proc evaluates the selection and returns TRUE if it can be considered an URL
4614 BOOL
ME_IsCandidateAnURL(ME_TextEditor
*editor
, int sel_min
, int sel_max
)
4620 /* Code below depends on these being in decreasing length order! */
4634 LPWSTR bufferW
= NULL
;
4638 if (sel_max
== -1) sel_max
= ME_GetTextLength(editor
);
4639 assert(sel_min
<= sel_max
);
4640 for (i
= 0; i
< sizeof(prefixes
) / sizeof(struct prefix_s
); i
++)
4642 if (sel_max
- sel_min
< prefixes
[i
].length
) continue;
4643 if (bufferW
== NULL
) {
4644 bufferW
= (LPWSTR
)heap_alloc((sel_max
- sel_min
+ 1) * sizeof(WCHAR
));
4646 ME_GetTextW(editor
, bufferW
, sel_min
, min(sel_max
- sel_min
, strlen(prefixes
[i
].text
)), 0);
4647 MultiByteToWideChar(CP_ACP
, 0, prefixes
[i
].text
, -1, bufW
, 32);
4648 if (!lstrcmpW(bufW
, bufferW
))
4659 * This proc walks through the indicated selection and evaluates whether each
4660 * section identified by ME_FindNextURLCandidate and in-between sections have
4661 * their proper CFE_LINK attributes set or unset. If the CFE_LINK attribute is
4662 * not what it is supposed to be, this proc sets or unsets it as appropriate.
4664 * Returns TRUE if at least one section was modified.
4666 BOOL
ME_UpdateLinkAttribute(ME_TextEditor
*editor
, int sel_min
, int sel_max
)
4668 BOOL modified
= FALSE
;
4671 if (sel_max
== -1) sel_max
= ME_GetTextLength(editor
);
4678 if (ME_FindNextURLCandidate(editor
, sel_min
, sel_max
, &cMin
, &cMax
))
4680 /* Section before candidate is not an URL */
4681 beforeURL
[0] = sel_min
;
4682 beforeURL
[1] = cMin
;
4684 if (ME_IsCandidateAnURL(editor
, cMin
, cMax
))
4686 inURL
[0] = cMin
; inURL
[1] = cMax
;
4690 beforeURL
[1] = cMax
;
4691 inURL
[0] = inURL
[1] = -1;
4697 /* No more candidates until end of selection */
4698 beforeURL
[0] = sel_min
;
4699 beforeURL
[1] = sel_max
;
4700 inURL
[0] = inURL
[1] = -1;
4704 if (beforeURL
[0] < beforeURL
[1])
4706 /* CFE_LINK effect should be consistently unset */
4707 link
.cbSize
= sizeof(link
);
4708 ME_GetCharFormat(editor
, beforeURL
[0], beforeURL
[1], &link
);
4709 if (!(link
.dwMask
& CFM_LINK
) || (link
.dwEffects
& CFE_LINK
))
4711 /* CFE_LINK must be unset from this range */
4712 memset(&link
, 0, sizeof(CHARFORMAT2W
));
4713 link
.cbSize
= sizeof(link
);
4714 link
.dwMask
= CFM_LINK
;
4716 ME_SetCharFormat(editor
, beforeURL
[0], beforeURL
[1] - beforeURL
[0], &link
);
4720 if (inURL
[0] < inURL
[1])
4722 /* CFE_LINK effect should be consistently set */
4723 link
.cbSize
= sizeof(link
);
4724 ME_GetCharFormat(editor
, inURL
[0], inURL
[1], &link
);
4725 if (!(link
.dwMask
& CFM_LINK
) || !(link
.dwEffects
& CFE_LINK
))
4727 /* CFE_LINK must be set on this range */
4728 memset(&link
, 0, sizeof(CHARFORMAT2W
));
4729 link
.cbSize
= sizeof(link
);
4730 link
.dwMask
= CFM_LINK
;
4731 link
.dwEffects
= CFE_LINK
;
4732 ME_SetCharFormat(editor
, inURL
[0], inURL
[1] - inURL
[0], &link
);
4736 } while (sel_min
< sel_max
);
4740 void ME_UpdateSelectionLinkAttribute(ME_TextEditor
*editor
)
4742 ME_DisplayItem
* startPara
, * endPara
;
4743 ME_DisplayItem
* item
;
4747 ME_GetSelection(editor
, &from
, &to
);
4748 if (from
> to
) from
^= to
, to
^=from
, from
^= to
;
4749 startPara
= NULL
; endPara
= NULL
;
4751 /* Find paragraph previous to the one that contains start cursor */
4752 item
= ME_FindItemAtOffset(editor
, diRun
, from
, &dummy
);
4754 startPara
= ME_FindItemBack(item
, diParagraph
);
4755 item
= ME_FindItemBack(startPara
, diParagraph
);
4756 if (item
) startPara
= item
;
4759 /* Find paragraph that contains end cursor */
4760 item
= ME_FindItemAtOffset(editor
, diRun
, to
, &dummy
);
4762 endPara
= ME_FindItemFwd(item
, diParagraph
);
4765 if (startPara
&& endPara
) {
4766 ME_UpdateLinkAttribute(editor
,
4767 startPara
->member
.para
.nCharOfs
,
4768 endPara
->member
.para
.nCharOfs
);
4769 } else if (startPara
) {
4770 ME_UpdateLinkAttribute(editor
,
4771 startPara
->member
.para
.nCharOfs
,