Fixed a possible memory corruption.
[wine] / dlls / richedit / richedit.c
1 /*
2  * RichEdit32  functions
3  *
4  * This module is a simple wrapper for the edit controls.
5  * At the point, it is good only for application who use the RICHEDIT
6  * control to display RTF text.
7  *
8  * Copyright 2000 by Jean-Claude Batista
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 2.1 of the License, or (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with this library; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23  */
24
25 #include <string.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "wingdi.h"
29 #include "winreg.h"
30 #include "winerror.h"
31 #include "riched32.h"
32 #include "richedit.h"
33 #include "charlist.h"
34 #define NO_SHLWAPI_STREAM
35 #include "shlwapi.h"
36
37 #include "rtf.h"
38 #include "rtf2text.h"
39 #include "wine/debug.h"
40
41 #define ID_EDIT      1
42
43 WINE_DEFAULT_DEBUG_CHANNEL(richedit);
44
45 HANDLE RICHED32_hHeap = NULL;
46 /* LPSTR  RICHED32_aSubclass = NULL; */
47
48 #define TRACE_EDIT_MSG32(str) \
49         TRACE(\
50                      "32 bit : " str ": hwnd=%p, wParam=%08x, lParam=%08x\n"\
51                      , \
52                      hwnd, (UINT)wParam, (UINT)lParam)
53
54
55 /***********************************************************************
56  * DllMain [Internal] Initializes the internal 'RICHED32.DLL'.
57  *
58  * PARAMS
59  *     hinstDLL    [I] handle to the DLL's instance
60  *     fdwReason   [I]
61  *     lpvReserved [I] reserved, must be NULL
62  *
63  * RETURNS
64  *     Success: TRUE
65  *     Failure: FALSE
66  */
67
68 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
69 {
70     TRACE("\n");
71     switch (fdwReason)
72     {
73     case DLL_PROCESS_ATTACH:
74         /* create private heap */
75         RICHED32_hHeap = HeapCreate (0, 0x10000, 0);
76         /* register the Rich Edit class */
77         RICHED32_Register ();
78         break;
79
80     case DLL_PROCESS_DETACH:
81         /* unregister all common control classes */
82         RICHED32_Unregister ();
83         HeapDestroy (RICHED32_hHeap);
84         RICHED32_hHeap = NULL;
85         break;
86     }
87     return TRUE;
88 }
89
90 /* Support routines for window procedure */
91    INT RICHEDIT_GetTextRange(HWND hwnd,TEXTRANGEA *tr);
92    INT RICHEDIT_GetSelText(HWND hwnd,LPSTR lpstrBuffer);
93
94
95 /*
96  *
97  * DESCRIPTION:
98  * Window procedure of the RichEdit control.
99  *
100  */
101 static LRESULT WINAPI RICHED32_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,
102                                    LPARAM lParam)
103 {
104     int RTFToBuffer(char* pBuffer, int nBufferSize);
105     LONG newstyle = 0;
106     LONG style = 0;
107
108     static HWND hwndEdit;
109     static HWND hwndParent;
110     static char* rtfBuffer;
111     int rtfBufferSize;
112
113     CHARRANGE *cr;
114     TRACE("previous hwndEdit: %p hwndParent %p\n",hwndEdit,hwndParent);
115     hwndEdit = GetWindow(hwnd,GW_CHILD);
116     TRACE("uMsg: 0x%x hwnd: %p hwndEdit: %p\n",uMsg,hwnd,hwndEdit);
117
118     switch (uMsg)
119     {
120
121     case WM_CREATE:
122             TRACE_EDIT_MSG32("WM_CREATE Passed to default");
123             DefWindowProcA( hwnd,uMsg,wParam,lParam);
124             return 0 ;
125         
126     case WM_NCCREATE :
127             TRACE_EDIT_MSG32("WM_NCCREATE");
128
129             /* remove SCROLLBARS from the current window style */
130             hwndParent = ((LPCREATESTRUCTA) lParam)->hwndParent;
131
132             newstyle = style = ((LPCREATESTRUCTA) lParam)->style;
133             newstyle &= ~WS_HSCROLL;
134             newstyle &= ~WS_VSCROLL;
135             newstyle &= ~ES_AUTOHSCROLL;
136             newstyle &= ~ES_AUTOVSCROLL;
137             SetWindowLongA(hwnd,GWL_STYLE, newstyle);
138
139     TRACE("previous hwndEdit: %p\n",hwndEdit);
140             hwndEdit = CreateWindowA ("edit", ((LPCREATESTRUCTA) lParam)->lpszName,
141                                    style, 0, 0, 0, 0,
142                                    hwnd, (HMENU) ID_EDIT,
143                                    ((LPCREATESTRUCTA) lParam)->hInstance, NULL) ;
144     TRACE("hwndEdit: %p hwnd: %p\n",hwndEdit,hwnd);
145
146             if (hwndEdit)
147                 return TRUE ;
148             else
149                 return FALSE ;
150
151     case WM_SETFOCUS :
152             TRACE_EDIT_MSG32("WM_SETFOCUS");
153             SetFocus (hwndEdit) ;
154             return 0 ;
155
156     case WM_SIZE :
157             TRACE_EDIT_MSG32("WM_SIZE");
158             MoveWindow (hwndEdit, 0, 0, LOWORD (lParam), HIWORD (lParam), TRUE) ;
159             return 0 ;
160
161     case WM_COMMAND :
162         TRACE_EDIT_MSG32("WM_COMMAND");
163         switch(HIWORD(wParam)) {
164                 case EN_CHANGE:
165                 case EN_HSCROLL:
166                 case EN_KILLFOCUS:
167                 case EN_SETFOCUS:
168                 case EN_UPDATE:
169                 case EN_VSCROLL:
170                         return SendMessageA(hwndParent, WM_COMMAND,
171                                 wParam, (LPARAM)(hwnd));
172
173                 case EN_ERRSPACE:
174                 case EN_MAXTEXT:
175                         MessageBoxA (hwnd, "RichEdit control out of space.",
176                                   "ERROR", MB_OK | MB_ICONSTOP) ;
177                         return 0 ;
178                 }
179
180     case EM_STREAMIN:
181             TRACE_EDIT_MSG32("EM_STREAMIN");
182
183             /* setup the RTF parser */
184             RTFSetEditStream(( EDITSTREAM*)lParam);
185             rtfFormat = wParam&(SF_TEXT|SF_RTF);
186             WriterInit();
187             RTFInit ();
188             BeginFile();
189
190             /* do the parsing */
191             RTFRead ();
192
193             rtfBufferSize = RTFToBuffer(NULL, 0);
194             rtfBuffer = HeapAlloc(RICHED32_hHeap, 0,rtfBufferSize*sizeof(char));
195             if(rtfBuffer)
196             {
197                 RTFToBuffer(rtfBuffer, rtfBufferSize);
198                 SetWindowTextA(hwndEdit,rtfBuffer);
199                 HeapFree(RICHED32_hHeap, 0,rtfBuffer);
200             }
201             else
202                 WARN("Not enough memory for a allocating rtfBuffer\n");
203
204             return 0;
205
206 /* Messages specific to Richedit controls */
207
208     case EM_AUTOURLDETECT:
209             TRACE_EDIT_MSG32("EM_AUTOURLDETECT Ignored");
210             return 0;
211
212     case EM_CANPASTE:
213             TRACE_EDIT_MSG32("EM_CANPASTE Ignored");
214             return 0;
215
216     case EM_CANREDO:
217             TRACE_EDIT_MSG32("EM_CANREDO Ignored");
218             return 0;
219
220     case EM_DISPLAYBAND:
221             TRACE_EDIT_MSG32("EM_DISPLAYBAND Ignored");
222             return 0;
223
224     case EM_EXGETSEL:
225             TRACE_EDIT_MSG32("EM_EXGETSEL -> EM_GETSEL");
226             cr = (VOID *) lParam;
227             if (hwndEdit) SendMessageA( hwndEdit, EM_GETSEL, (INT)&cr->cpMin, (INT)&cr->cpMax);
228             TRACE("cpMin: 0x%x cpMax: 0x%x\n",(INT)cr->cpMin,(INT)cr->cpMax);
229             return 0;
230
231     case EM_EXLIMITTEXT:
232         {
233            DWORD limit = lParam;
234            TRACE_EDIT_MSG32("EM_EXLIMITTEXT");
235            if (limit > 65534)
236            {
237                 limit = 0xFFFFFFFF;
238            }
239            return SendMessageA(hwndEdit,EM_SETLIMITTEXT,limit,0);
240         }
241
242     case EM_EXLINEFROMCHAR:
243             TRACE_EDIT_MSG32("EM_EXLINEFROMCHAR -> LINEFROMCHAR");
244             if (hwndEdit) return SendMessageA( hwndEdit, EM_LINEFROMCHAR, lParam, wParam);
245             return 0;
246
247     case EM_EXSETSEL:
248             TRACE_EDIT_MSG32("EM_EXSETSEL -> EM_SETSEL");
249             cr = (VOID *) lParam;
250             if (hwndEdit) SendMessageA( hwndEdit, EM_SETSEL, cr->cpMin, cr->cpMax);
251             return 0;
252
253     case EM_FINDTEXT:
254             TRACE_EDIT_MSG32("EM_FINDTEXT Ignored");
255             return 0;
256
257     case EM_FINDTEXTEX:
258             TRACE_EDIT_MSG32("EM_FINDTEXTEX Ignored");
259             return 0;
260
261     case EM_FINDTEXTEXW:
262             TRACE_EDIT_MSG32("EM_FINDTEXTEXW Ignored");
263             return 0;
264
265     case EM_FINDTEXTW:
266             TRACE_EDIT_MSG32("EM_FINDTEXTW Ignored");
267             return 0;
268
269     case EM_FINDWORDBREAK:
270             TRACE_EDIT_MSG32("EM_FINDWORDBREAK Ignored");
271             return 0;
272
273     case EM_FORMATRANGE:
274             TRACE_EDIT_MSG32("EM_FORMATRANGE Ignored");
275             return 0;
276
277     case EM_GETAUTOURLDETECT:
278             TRACE_EDIT_MSG32("EM_GETAUTOURLDETECT Ignored");
279             return 0;
280
281     case EM_GETBIDIOPTIONS:
282             TRACE_EDIT_MSG32("EM_GETBIDIOPTIONS Ignored");
283             return 0;
284
285     case EM_GETCHARFORMAT:
286             TRACE_EDIT_MSG32("EM_GETCHARFORMAT Ignored");
287             return 0;
288
289     case EM_GETEDITSTYLE:
290             TRACE_EDIT_MSG32("EM_GETEDITSTYLE Ignored");
291             return 0;
292
293     case EM_GETEVENTMASK:
294             TRACE_EDIT_MSG32("EM_GETEVENTMASK Ignored");
295             return 0;
296
297     case EM_GETIMECOLOR:
298             TRACE_EDIT_MSG32("EM_GETIMECOLOR Ignored");
299             return 0;
300
301     case EM_GETIMECOMPMODE:
302             TRACE_EDIT_MSG32("EM_GETIMECOMPMODE Ignored");
303             return 0;
304
305     case EM_GETIMEOPTIONS:
306             TRACE_EDIT_MSG32("EM_GETIMEOPTIONS Ignored");
307             return 0;
308
309     case EM_GETLANGOPTIONS:
310             TRACE_EDIT_MSG32("STUB: EM_GETLANGOPTIONS");
311             return 0;
312
313     case EM_GETOLEINTERFACE:
314             TRACE_EDIT_MSG32("EM_GETOLEINTERFACE Ignored");
315             return 0;
316
317     case EM_GETOPTIONS:
318             TRACE_EDIT_MSG32("EM_GETOPTIONS Ignored");
319             return 0;
320
321     case EM_GETPARAFORMAT:
322             TRACE_EDIT_MSG32("EM_GETPARAFORMAT Ignored");
323             return 0;
324
325     case EM_GETPUNCTUATION:
326             TRACE_EDIT_MSG32("EM_GETPUNCTUATION Ignored");
327             return 0;
328
329     case EM_GETREDONAME:
330             TRACE_EDIT_MSG32("EM_GETREDONAME Ignored");
331             return 0;
332
333     case EM_GETSCROLLPOS:
334             TRACE_EDIT_MSG32("EM_GETSCROLLPOS Ignored");
335             return 0;
336
337     case EM_GETSELTEXT:
338             TRACE_EDIT_MSG32("EM_GETSELTEXT");
339             return RICHEDIT_GetSelText(hwndEdit,(void *)lParam);
340
341     case EM_GETTEXTEX:
342             TRACE_EDIT_MSG32("EM_GETTEXTEX Ignored");
343             return 0;
344
345     case EM_GETTEXTLENGTHEX:
346             TRACE_EDIT_MSG32("EM_GETTEXTLENGTHEX Ignored");
347             return 0;
348
349     case EM_GETTEXTMODE:
350             TRACE_EDIT_MSG32("EM_GETTEXTMODE Ignored");
351             return 0;
352
353     case EM_GETTEXTRANGE:
354             TRACE_EDIT_MSG32("EM_GETTEXTRANGE");
355             return RICHEDIT_GetTextRange(hwndEdit,(TEXTRANGEA *)lParam);
356
357     case EM_GETTYPOGRAPHYOPTIONS:
358             TRACE_EDIT_MSG32("EM_GETTYPOGRAPHYOPTIONS Ignored");
359             return 0;
360
361     case EM_GETUNDONAME:
362             TRACE_EDIT_MSG32("EM_GETUNDONAME Ignored");
363             return 0;
364
365     case EM_GETWORDBREAKPROCEX:
366             TRACE_EDIT_MSG32("EM_GETWORDBREAKPROCEX Ignored");
367             return 0;
368
369     case EM_GETWORDWRAPMODE:
370             TRACE_EDIT_MSG32("EM_GETWORDWRAPMODE Ignored");
371             return 0;
372
373     case EM_GETZOOM:
374             TRACE_EDIT_MSG32("EM_GETZOOM Ignored");
375             return 0;
376
377     case EM_HIDESELECTION:
378             TRACE_EDIT_MSG32("EM_HIDESELECTION Ignored");
379             return 0;
380
381     case EM_PASTESPECIAL:
382             TRACE_EDIT_MSG32("EM_PASTESPECIAL Ignored");
383             return 0;
384
385     case EM_RECONVERSION:
386             TRACE_EDIT_MSG32("EM_RECONVERSION Ignored");
387             return 0;
388
389     case EM_REDO:
390             TRACE_EDIT_MSG32("EM_REDO Ignored");
391             return 0;
392
393     case EM_REQUESTRESIZE:
394             TRACE_EDIT_MSG32("EM_REQUESTRESIZE Ignored");
395             return 0;
396
397     case EM_SELECTIONTYPE:
398             TRACE_EDIT_MSG32("EM_SELECTIONTYPE Ignored");
399             return 0;
400
401     case EM_SETBIDIOPTIONS:
402             TRACE_EDIT_MSG32("EM_SETBIDIOPTIONS Ignored");
403             return 0;
404
405     case EM_SETBKGNDCOLOR:
406             TRACE_EDIT_MSG32("EM_SETBKGNDCOLOR Ignored");
407             return 0;
408
409     case EM_SETCHARFORMAT:
410             TRACE_EDIT_MSG32("EM_SETCHARFORMAT Ignored");
411             return 0;
412
413     case EM_SETEDITSTYLE:
414             TRACE_EDIT_MSG32("EM_SETEDITSTYLE Ignored");
415             return 0;
416
417     case EM_SETEVENTMASK:
418             TRACE_EDIT_MSG32("EM_SETEVENTMASK Ignored");
419             return 0;
420
421     case EM_SETFONTSIZE:
422             TRACE_EDIT_MSG32("EM_SETFONTSIZE Ignored");
423             return 0;
424
425     case EM_SETIMECOLOR:
426             TRACE_EDIT_MSG32("EM_SETIMECOLO Ignored");
427             return 0;
428
429     case EM_SETIMEOPTIONS:
430             TRACE_EDIT_MSG32("EM_SETIMEOPTIONS Ignored");
431             return 0;
432
433     case EM_SETLANGOPTIONS:
434             TRACE_EDIT_MSG32("EM_SETLANGOPTIONS Ignored");
435             return 0;
436
437     case EM_SETOLECALLBACK:
438             TRACE_EDIT_MSG32("EM_SETOLECALLBACK Ignored");
439             return 0;
440
441     case EM_SETOPTIONS:
442             TRACE_EDIT_MSG32("EM_SETOPTIONS Ignored");
443             return 0;
444
445     case EM_SETPALETTE:
446             TRACE_EDIT_MSG32("EM_SETPALETTE Ignored");
447             return 0;
448
449     case EM_SETPARAFORMAT:
450             TRACE_EDIT_MSG32("EM_SETPARAFORMAT Ignored");
451             return 0;
452
453     case EM_SETPUNCTUATION:
454             TRACE_EDIT_MSG32("EM_SETPUNCTUATION Ignored");
455             return 0;
456
457     case EM_SETSCROLLPOS:
458             TRACE_EDIT_MSG32("EM_SETSCROLLPOS Ignored");
459             return 0;
460
461     case EM_SETTARGETDEVICE:
462             TRACE_EDIT_MSG32("EM_SETTARGETDEVICE Ignored");
463             return 0;
464
465     case EM_SETTEXTEX:
466             TRACE_EDIT_MSG32("EM_SETTEXTEX Ignored");
467             return 0;
468
469     case EM_SETTEXTMODE:
470             TRACE_EDIT_MSG32("EM_SETTEXTMODE Ignored");
471             return 0;
472
473     case EM_SETTYPOGRAPHYOPTIONS:
474             TRACE_EDIT_MSG32("EM_SETTYPOGRAPHYOPTIONS Ignored");
475             return 0;
476
477     case EM_SETUNDOLIMIT:
478             TRACE_EDIT_MSG32("EM_SETUNDOLIMIT Ignored");
479             return 0;
480
481     case EM_SETWORDBREAKPROCEX:
482             TRACE_EDIT_MSG32("EM_SETWORDBREAKPROCEX Ignored");
483             return 0;
484
485     case EM_SETWORDWRAPMODE:
486             TRACE_EDIT_MSG32("EM_SETWORDWRAPMODE Ignored");
487             return 0;
488
489     case EM_SETZOOM:
490             TRACE_EDIT_MSG32("EM_SETZOOM Ignored");
491             return 0;
492
493     case EM_SHOWSCROLLBAR:
494             TRACE_EDIT_MSG32("EM_SHOWSCROLLBAR Ignored");
495             return 0;
496
497     case EM_STOPGROUPTYPING:
498             TRACE_EDIT_MSG32("EM_STOPGROUPTYPING Ignored");
499             return 0;
500
501     case EM_STREAMOUT:
502             TRACE_EDIT_MSG32("EM_STREAMOUT Ignored");
503             return 0;
504
505 /* Messages dispatched to the edit control */
506      case EM_CANUNDO:
507             TRACE_EDIT_MSG32("EM_CANUNDO Passed to edit control");
508             return SendMessageA( hwndEdit, uMsg, wParam, lParam);
509      case EM_CHARFROMPOS:
510             TRACE_EDIT_MSG32("EM_CHARFROMPOS Passed to edit control");
511             return SendMessageA( hwndEdit, uMsg, wParam, lParam);
512      case EM_EMPTYUNDOBUFFER:
513             TRACE_EDIT_MSG32("EM_EMPTYUNDOBUFFER Passed to edit control");
514             return SendMessageA( hwndEdit, uMsg, wParam, lParam);
515      case EM_FMTLINES:
516             TRACE_EDIT_MSG32("EM_FMTLINES Passed to edit control");
517             return SendMessageA( hwndEdit, uMsg, wParam, lParam);
518      case EM_GETFIRSTVISIBLELINE:
519             TRACE_EDIT_MSG32("EM_GETFIRSTVISIBLELINE Passed to edit control");
520             return SendMessageA( hwndEdit, uMsg, wParam, lParam);
521      case EM_GETHANDLE:
522             TRACE_EDIT_MSG32("EM_GETHANDLE Passed to edit control");
523             return SendMessageA( hwndEdit, uMsg, wParam, lParam);
524  /*    case EM_GETIMESTATUS:*/
525      case EM_GETLIMITTEXT:
526             TRACE_EDIT_MSG32("EM_GETLIMITTEXT Passed to edit control");
527             return SendMessageA( hwndEdit, uMsg, wParam, lParam);
528      case EM_GETLINE:
529             TRACE_EDIT_MSG32("EM_GETLINE Passed to edit control");
530             return SendMessageA( hwndEdit, uMsg, wParam, lParam);
531      case EM_GETLINECOUNT:
532             TRACE_EDIT_MSG32("EM_GETLINECOUNT Passed to edit control");
533             return SendMessageA( hwndEdit, uMsg, wParam, lParam);
534      case EM_GETMARGINS:
535             TRACE_EDIT_MSG32("EM_GETMARGINS Passed to edit control");
536             return SendMessageA( hwndEdit, uMsg, wParam, lParam);
537      case EM_GETMODIFY:
538             TRACE_EDIT_MSG32("EM_GETMODIFY Passed to edit control");
539             return SendMessageA( hwndEdit, uMsg, wParam, lParam);
540      case EM_GETPASSWORDCHAR:
541             TRACE_EDIT_MSG32("EM_GETPASSWORDCHAR Passed to edit control");
542             return SendMessageA( hwndEdit, uMsg, wParam, lParam);
543      case EM_GETRECT:
544             TRACE_EDIT_MSG32("EM_GETRECT Passed to edit control");
545             return SendMessageA( hwndEdit, uMsg, wParam, lParam);
546      case EM_GETSEL:
547             TRACE_EDIT_MSG32("EM_GETSEL Passed to edit control");
548             return SendMessageA( hwndEdit, uMsg, wParam, lParam);
549      case EM_GETTHUMB:
550             TRACE_EDIT_MSG32("EM_GETTHUMB Passed to edit control");
551             return SendMessageA( hwndEdit, uMsg, wParam, lParam);
552      case EM_GETWORDBREAKPROC:
553             TRACE_EDIT_MSG32("EM_GETWORDBREAKPROC Passed to edit control");
554             return SendMessageA( hwndEdit, uMsg, wParam, lParam);
555      case EM_LINEFROMCHAR:
556             TRACE_EDIT_MSG32("EM_LINEFROMCHAR Passed to edit control");
557             return SendMessageA( hwndEdit, uMsg, wParam, lParam);
558      case EM_LINEINDEX:
559             TRACE_EDIT_MSG32("EM_LINEINDEX Passed to edit control");
560             return SendMessageA( hwndEdit, uMsg, wParam, lParam);
561      case EM_LINELENGTH:
562             TRACE_EDIT_MSG32("EM_LINELENGTH Passed to edit control");
563             return SendMessageA( hwndEdit, uMsg, wParam, lParam);
564      case EM_LINESCROLL:
565             TRACE_EDIT_MSG32("EM_LINESCROLL Passed to edit control");
566             return SendMessageA( hwndEdit, uMsg, wParam, lParam);
567      case EM_POSFROMCHAR:
568             TRACE_EDIT_MSG32("EM_POSFROMCHAR Passed to edit control");
569             return SendMessageA( hwndEdit, uMsg, wParam, lParam);
570      case EM_REPLACESEL:
571             TRACE_EDIT_MSG32("case EM_REPLACESEL Passed to edit control");
572             return SendMessageA( hwndEdit, uMsg, wParam, lParam);
573      case EM_SCROLL:
574             TRACE_EDIT_MSG32("case EM_SCROLL Passed to edit control");
575             return SendMessageA( hwndEdit, uMsg, wParam, lParam);
576      case EM_SCROLLCARET:
577             TRACE_EDIT_MSG32("EM_SCROLLCARET Passed to edit control");
578             return SendMessageA( hwndEdit, uMsg, wParam, lParam);
579      case EM_SETHANDLE:
580             TRACE_EDIT_MSG32("EM_SETHANDLE Passed to edit control");
581             return SendMessageA( hwndEdit, uMsg, wParam, lParam);
582  /*    case EM_SETIMESTATUS:*/
583      case EM_SETLIMITTEXT:
584             TRACE_EDIT_MSG32("EM_SETLIMITTEXT Passed to edit control");
585             return SendMessageA( hwndEdit, uMsg, wParam, lParam);
586      case EM_SETMARGINS:
587             TRACE_EDIT_MSG32("case EM_SETMARGINS Passed to edit control");
588             return SendMessageA( hwndEdit, uMsg, wParam, lParam);
589      case EM_SETMODIFY:
590             TRACE_EDIT_MSG32("EM_SETMODIFY Passed to edit control");
591             return SendMessageA( hwndEdit, uMsg, wParam, lParam);
592      case EM_SETPASSWORDCHAR:
593             TRACE_EDIT_MSG32("EM_SETPASSWORDCHAR Passed to edit control");
594             return SendMessageA( hwndEdit, uMsg, wParam, lParam);
595      case EM_SETREADONLY:
596             TRACE_EDIT_MSG32("EM_SETREADONLY Passed to edit control");
597             return SendMessageA( hwndEdit, uMsg, wParam, lParam);
598      case EM_SETRECT:
599             TRACE_EDIT_MSG32("EM_SETRECT Passed to edit control");
600             return SendMessageA( hwndEdit, uMsg, wParam, lParam);
601      case EM_SETRECTNP:
602             TRACE_EDIT_MSG32("EM_SETRECTNP Passed to edit control");
603             return SendMessageA( hwndEdit, uMsg, wParam, lParam);
604      case EM_SETSEL:
605             TRACE_EDIT_MSG32("EM_SETSEL Passed to edit control");
606             return SendMessageA( hwndEdit, uMsg, wParam, lParam);
607      case EM_SETTABSTOPS:
608             TRACE_EDIT_MSG32("EM_SETTABSTOPS Passed to edit control");
609             return SendMessageA( hwndEdit, uMsg, wParam, lParam);
610      case EM_SETWORDBREAKPROC:
611             TRACE_EDIT_MSG32("EM_SETWORDBREAKPROC Passed to edit control");
612             return SendMessageA( hwndEdit, uMsg, wParam, lParam);
613      case EM_UNDO:
614             TRACE_EDIT_MSG32("EM_UNDO Passed to edit control");
615             return SendMessageA( hwndEdit, uMsg, wParam, lParam);
616
617      case WM_STYLECHANGING:
618             TRACE_EDIT_MSG32("WM_STYLECHANGING Passed to edit control");
619             return SendMessageA( hwndEdit, uMsg, wParam, lParam);
620      case WM_STYLECHANGED:
621             TRACE_EDIT_MSG32("WM_STYLECHANGED Passed to edit control");
622             return SendMessageA( hwndEdit, uMsg, wParam, lParam);
623      case WM_GETTEXT:
624             TRACE_EDIT_MSG32("WM_GETTEXT Passed to edit control");
625             return SendMessageA( hwndEdit, uMsg, wParam, lParam);
626      case WM_GETTEXTLENGTH:
627             TRACE_EDIT_MSG32("WM_GETTEXTLENGTH Passed to edit control");
628             return SendMessageA( hwndEdit, uMsg, wParam, lParam);
629      case WM_SETTEXT:
630             TRACE_EDIT_MSG32("WM_SETTEXT Passed to edit control");
631             return SendMessageA( hwndEdit, uMsg, wParam, lParam);
632      case WM_CUT:
633             TRACE_EDIT_MSG32("WM_CUT Passed to edit control");
634             return SendMessageA( hwndEdit, uMsg, wParam, lParam);
635      case WM_COPY:
636             TRACE_EDIT_MSG32("WM_COPY Passed to edit control");
637             return SendMessageA( hwndEdit, uMsg, wParam, lParam);
638     case WM_PASTE:
639             TRACE_EDIT_MSG32("WM_PASTE Passed to edit control");
640             return SendMessageA( hwndEdit, uMsg, wParam, lParam);
641
642     /* Messages passed to default handler. */
643     case WM_NCCALCSIZE:
644         /* A fundamental problem with embedding an edit control within another
645            window to emulate the richedit control, is that normally, the 
646            WM_NCCALCSIZE message window would return the client area of the 
647            edit control.
648            
649            While we could send a message to the edit control here to get that size
650            and return that value, this causes problems with the WM_SIZE message.
651            That is because the WM_SIZE message uses the returned value of
652            WM_NCCALCSIZE (via X11DRV_SetWindowSize) to determine the size to make 
653            the edit control. If we return the size of the edit control client area
654            here, the result is the symptom of the edit control being inset on the 
655            right and bottom by the width of any existing scrollbars.
656            
657            The easy fix is to have WM_NCCALCSIZE return the true size of this 
658            enclosing window, which is what we have done here. The more difficult 
659            fix is to create a custom Richedit MoveWindow procedure for use in the 
660            WM_SIZE message above. Since it is very unlikely that an app would call
661            and use the WM_NCCALCSIZE message, we stick with the easy fix for now.
662          */
663         TRACE_EDIT_MSG32("WM_NCCALCSIZE Passed to default");
664         return DefWindowProcA( hwnd,uMsg,wParam,lParam);
665     case WM_NCPAINT:
666         TRACE_EDIT_MSG32("WM_NCPAINT Passed to default");
667         return DefWindowProcA( hwnd,uMsg,wParam,lParam);
668     case WM_PAINT:
669         TRACE_EDIT_MSG32("WM_PAINT Passed to default");
670         return DefWindowProcA( hwnd,uMsg,wParam,lParam);
671     case WM_ERASEBKGND:
672         TRACE_EDIT_MSG32("WM_ERASEBKGND Passed to default");
673         return DefWindowProcA( hwnd,uMsg,wParam,lParam);
674     case WM_KILLFOCUS:
675         TRACE_EDIT_MSG32("WM_KILLFOCUS Passed to default");
676         return DefWindowProcA( hwnd,uMsg,wParam,lParam);
677     case WM_DESTROY:
678         TRACE_EDIT_MSG32("WM_DESTROY Passed to default");
679         return DefWindowProcA( hwnd,uMsg,wParam,lParam);
680     case WM_CHILDACTIVATE:
681         TRACE_EDIT_MSG32("WM_CHILDACTIVATE Passed to default");
682         return DefWindowProcA( hwnd,uMsg,wParam,lParam);
683
684     case WM_WINDOWPOSCHANGING:
685         TRACE_EDIT_MSG32("WM_WINDOWPOSCHANGING Passed to default");
686         return DefWindowProcA( hwnd,uMsg,wParam,lParam);
687     case WM_WINDOWPOSCHANGED:
688         TRACE_EDIT_MSG32("WM_WINDOWPOSCHANGED Passed to default");
689         return DefWindowProcA( hwnd,uMsg,wParam,lParam);
690 /*    case WM_INITIALUPDATE:
691         TRACE_EDIT_MSG32("WM_INITIALUPDATE Passed to default");
692         return DefWindowProcA( hwnd,uMsg,wParam,lParam); */
693     case WM_CTLCOLOREDIT:
694         TRACE_EDIT_MSG32("WM_CTLCOLOREDIT Passed to default");
695         return DefWindowProcA( hwnd,uMsg,wParam,lParam);
696     case WM_SETCURSOR:
697         TRACE_EDIT_MSG32("WM_SETCURSOR Passed to default");
698         return DefWindowProcA( hwnd,uMsg,wParam,lParam);
699     case WM_MOVE:
700         TRACE_EDIT_MSG32("WM_MOVE Passed to default");
701         return DefWindowProcA( hwnd,uMsg,wParam,lParam);
702     case WM_SHOWWINDOW:
703         TRACE_EDIT_MSG32("WM_SHOWWINDOW Passed to default");
704         return DefWindowProcA( hwnd,uMsg,wParam,lParam);
705     case WM_PARENTNOTIFY:
706         TRACE_EDIT_MSG32("WM_PARENTNOTIFY Passed to default");
707         return DefWindowProcA( hwnd,uMsg,wParam,lParam);
708     case WM_SETREDRAW:
709         TRACE_EDIT_MSG32("WM_SETREDRAW Passed to default");
710         return DefWindowProcA( hwnd,uMsg,wParam,lParam);
711     case WM_NCDESTROY:
712         TRACE_EDIT_MSG32("WM_NCDESTROY Passed to default");
713         return DefWindowProcA( hwnd,uMsg,wParam,lParam);
714     case WM_NCHITTEST:
715         TRACE_EDIT_MSG32("WM_NCHITTEST Passed to default");
716         return DefWindowProcA( hwnd,uMsg,wParam,lParam);
717     case WM_CTLCOLORSTATIC:
718         TRACE_EDIT_MSG32("WM_CTLCOLORSTATIC Passed to default");
719         return DefWindowProcA( hwnd,uMsg,wParam,lParam);
720     case WM_NCMOUSEMOVE:
721         TRACE_EDIT_MSG32("WM_NCMOUSEMOVE Passed to default");
722         return DefWindowProcA( hwnd,uMsg,wParam,lParam);
723     case WM_CLEAR:
724         TRACE_EDIT_MSG32("WM_CLEAR Passed to default");
725         return DefWindowProcA( hwnd,uMsg,wParam,lParam);
726    /*
727     * used by IE in the EULA box
728     */
729     case WM_ALTTABACTIVE:
730         TRACE_EDIT_MSG32("WM_ALTTABACTIVE");
731         return DefWindowProcA( hwnd,uMsg,wParam,lParam);
732     case WM_GETDLGCODE:
733         TRACE_EDIT_MSG32("WM_GETDLGCODE");
734         return DefWindowProcA( hwnd,uMsg,wParam,lParam);
735     case WM_SETFONT:
736         TRACE_EDIT_MSG32("WM_SETFONT");
737         return DefWindowProcA( hwnd,uMsg,wParam,lParam);
738
739     }
740
741     if ((uMsg >= WM_USER) && (uMsg < WM_APP)) {
742         FIXME("Unknown message 0x%x Passed to default hwnd=%p, wParam=%08x, lParam=%08x\n",
743                uMsg, hwnd, (UINT)wParam, (UINT)lParam);
744     }
745
746    return DefWindowProcA( hwnd,uMsg,wParam,lParam);
747 }
748
749 /***********************************************************************
750  * DllGetVersion [RICHED32.2]
751  *
752  * Retrieves version information of the 'RICHED32.DLL'
753  *
754  * PARAMS
755  *     pdvi [O] pointer to version information structure.
756  *
757  * RETURNS
758  *     Success: S_OK
759  *     Failure: E_INVALIDARG
760  *
761  * NOTES
762  *     Returns version of a comctl32.dll from IE4.01 SP1.
763  */
764
765 HRESULT WINAPI
766 RICHED32_DllGetVersion (DLLVERSIONINFO *pdvi)
767 {
768     TRACE("\n");
769
770     if (pdvi->cbSize != sizeof(DLLVERSIONINFO)) {
771
772         return E_INVALIDARG;
773     }
774
775     pdvi->dwMajorVersion = 4;
776     pdvi->dwMinorVersion = 0;
777     pdvi->dwBuildNumber = 0;
778     pdvi->dwPlatformID = 0;
779
780     return S_OK;
781 }
782
783 /***
784  * DESCRIPTION:
785  * Registers the window class.
786  *
787  * PARAMETER(S):
788  * None
789  *
790  * RETURN:
791  * None
792  */
793 VOID RICHED32_Register(void)
794 {
795     WNDCLASSA wndClass;
796
797     TRACE("\n");
798
799     ZeroMemory(&wndClass, sizeof(WNDCLASSA));
800     wndClass.style = CS_HREDRAW | CS_VREDRAW | CS_GLOBALCLASS;
801     wndClass.lpfnWndProc = (WNDPROC)RICHED32_WindowProc;
802     wndClass.cbClsExtra = 0;
803     wndClass.cbWndExtra = 0; /*(sizeof(RICHED32_INFO *);*/
804     wndClass.hCursor = LoadCursorA(0, IDC_ARROWA);
805     wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
806     wndClass.lpszClassName = RICHEDIT_CLASS10A; /* WC_RICHED32A; */
807
808     RegisterClassA (&wndClass);
809 }
810
811 /***
812  * DESCRIPTION:
813  * Unregisters the window class.
814  *
815  * PARAMETER(S):
816  * None
817  *
818  * RETURN:
819  * None
820  */
821 VOID RICHED32_Unregister(void)
822 {
823     TRACE("\n");
824
825     UnregisterClassA(RICHEDIT_CLASS10A, NULL);
826 }
827
828 INT RICHEDIT_GetTextRange(HWND hwnd,TEXTRANGEA *tr)
829 {
830     UINT alloc_size, text_size, range_size;
831     char *text;
832
833     TRACE("start: 0x%x stop: 0x%x\n",(INT)tr->chrg.cpMin,(INT)tr->chrg.cpMax);
834
835     if (!(alloc_size = SendMessageA(hwnd,WM_GETTEXTLENGTH,0,0))) return FALSE;
836     if (!(text = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (alloc_size+1))))
837                 return FALSE;
838     text_size = SendMessageA(hwnd,WM_GETTEXT,alloc_size,(INT)text);
839
840     if (text_size > tr->chrg.cpMin)
841     {
842        range_size = (text_size> tr->chrg.cpMax) ? (tr->chrg.cpMax - tr->chrg.cpMin) : (text_size - tr->chrg.cpMin);
843        TRACE("EditText: %.30s ...\n",text+tr->chrg.cpMin);
844        memcpy(tr->lpstrText,text+tr->chrg.cpMin,range_size);
845     }
846     else range_size = 0;
847     HeapFree(GetProcessHeap(), 0, text);
848
849     return range_size;
850 }
851
852 INT RICHEDIT_GetSelText(HWND hwnd,LPSTR lpstrBuffer)
853 {
854     TEXTRANGEA textrange;
855
856     textrange.lpstrText = lpstrBuffer;
857     SendMessageA(hwnd,EM_GETSEL,(INT)&textrange.chrg.cpMin,(INT)&textrange.chrg.cpMax);
858     return RICHEDIT_GetTextRange(hwnd,&textrange);
859 }