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