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