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