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