source: trunk/src/riched32/richedit.c@ 21308

Last change on this file since 21308 was 21308, checked in by ydario, 16 years ago

Minor updates, backout imm changes.

File size: 23.4 KB
Line 
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
43WINE_DEFAULT_DEBUG_CHANNEL(richedit);
44
45#ifdef __WIN32OS2__
46/** custom build hack. */
47BOOL (* WINAPI pfnCustomRichedHack_EM_STREAMIN)(HWND, LPSTR) = NULL;
48#endif
49
50HANDLE RICHED32_hHeap = (HANDLE)NULL;
51/* LPSTR RICHED32_aSubclass = (LPSTR)NULL; */
52
53#define DPRINTF_EDIT_MSG32(str) \
54 TRACE(\
55 "32 bit : " str ": hwnd=%p, wParam=%08x, lParam=%08x\n"\
56 , \
57 hwnd, (UINT)wParam, (UINT)lParam)
58
59
60static INT CALLBACK EDIT_WordBreakProc(LPWSTR s, INT index, INT count, INT action);
61
62#ifdef __WIN32OS2__
63#include <dbglog.h>
64
65#define RICHEDIT_WND_PROP "RICHEDIT_PROP"
66
67FARPROC pfnEditProcA = (FARPROC)DefWindowProcA;
68FARPROC pfnEditProcW = (FARPROC)DefWindowProcW;
69
70typedef struct {
71 CHARFORMAT2A cf;
72 HBRUSH hbrBackground;
73} RICHEDIT_INFO;
74#endif
75
76/***********************************************************************
77 * DllMain [Internal] Initializes the internal 'RICHED32.DLL'.
78 *
79 * PARAMS
80 * hinstDLL [I] handle to the DLL's instance
81 * fdwReason [I]
82 * lpvReserved [I] reserved, must be NULL
83 *
84 * RETURNS
85 * Success: TRUE
86 * Failure: FALSE
87 */
88
89#ifdef __WIN32OS2__
90BOOL WINAPI RICHED32_LibMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
91#else
92BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
93#endif
94{
95 TRACE("\n");
96 switch (fdwReason)
97 {
98 case DLL_PROCESS_ATTACH:
99 /* create private heap */
100 RICHED32_hHeap = HeapCreate (0, 0x10000, 0);
101 /* register the Rich Edit class */
102 RICHED32_Register ();
103 break;
104
105 case DLL_PROCESS_DETACH:
106 /* unregister all common control classes */
107 RICHED32_Unregister ();
108 HeapDestroy (RICHED32_hHeap);
109 RICHED32_hHeap = (HANDLE)NULL;
110 break;
111 }
112 return TRUE;
113}
114
115/* Support routines for window procedure */
116 INT RICHEDIT_GetTextRange(HWND hwnd,TEXTRANGEA *tr);
117 INT RICHEDIT_GetSelText(HWND hwnd,LPSTR lpstrBuffer);
118
119
120/*
121 *
122 * DESCRIPTION:
123 * Window procedure of the RichEdit control.
124 *
125 */
126static LRESULT WINAPI RICHED32_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,
127 LPARAM lParam)
128{
129 int RTFToBuffer(char* pBuffer, int nBufferSize);
130 LONG newstyle = 0;
131 LONG style = 0;
132
133 HWND hwndParent = GetParent(hwnd);
134 char* rtfBuffer;
135 HANDLE hProp = 0;
136 int rtfBufferSize;
137
138 CHARRANGE *cr;
139 FARPROC pfnEditProc;
140
141 TRACE("uMsg: 0x%x hwnd: %p",uMsg,hwnd);
142
143 if(IsWindowUnicode(hwnd)) {
144 pfnEditProc = pfnEditProcW;
145 }
146 else pfnEditProc = pfnEditProcA;
147
148 switch (uMsg)
149 {
150
151 case WM_CREATE :
152 {
153 RICHEDIT_INFO *prinfo;
154 LRESULT ret;
155
156 DPRINTF_EDIT_MSG32("WM_CREATE");
157
158 ret = pfnEditProc(hwnd, WM_CREATE, wParam, lParam);
159 if(ret) return ret; /* window creation cancelled */
160
161 hProp = GlobalAlloc(GMEM_MOVEABLE|GMEM_ZEROINIT, sizeof(RICHEDIT_INFO));
162 SetPropA(hwnd, RICHEDIT_WND_PROP, hProp);
163 return 0 ;
164 }
165
166 case WM_DESTROY:
167 {
168 RICHEDIT_INFO *prinfo;
169
170 hProp = GetPropA(hwnd, RICHEDIT_WND_PROP);
171 prinfo = (RICHEDIT_INFO *)GlobalLock(hProp);
172 if(prinfo) {
173 //Destroy old brush if present
174 if(prinfo->hbrBackground) DeleteObject(prinfo->hbrBackground);
175 GlobalUnlock(hProp);
176 }
177
178 if(hProp) GlobalFree(hProp);
179 RemovePropA(hwnd, RICHEDIT_WND_PROP);
180
181 return pfnEditProc(hwnd, uMsg, wParam, lParam);
182 }
183
184 /* Messages specific to Richedit controls */
185
186 case EM_STREAMIN:
187 {
188 DPRINTF_EDIT_MSG32("EM_STREAMIN");
189
190 /* setup the RTF parser */
191 RTFSetEditStream(( EDITSTREAM*)lParam);
192 rtfFormat = wParam&(SF_TEXT|SF_RTF);
193 WriterInit();
194 RTFInit ();
195 BeginFile();
196
197 /* do the parsing */
198 RTFRead ();
199
200 rtfBufferSize = RTFToBuffer(NULL, 0);
201 rtfBuffer = HeapAlloc(RICHED32_hHeap, 0,rtfBufferSize*sizeof(char));
202 if(rtfBuffer)
203 {
204 RTFToBuffer(rtfBuffer, rtfBufferSize);
205#ifdef __WIN32OS2__
206 /* This is a very very ugly hack to work around some major parsing errors. */
207 if (pfnCustomRichedHack_EM_STREAMIN)
208 pfnCustomRichedHack_EM_STREAMIN(hwnd, rtfBuffer);
209 else
210#endif
211 SetWindowTextA(hwnd,rtfBuffer);
212 HeapFree(RICHED32_hHeap, 0,rtfBuffer);
213 }
214 else
215 WARN("Not enough memory for a allocating rtfBuffer\n");
216
217 return 0;
218 }
219
220 case EM_AUTOURLDETECT:
221 DPRINTF_EDIT_MSG32("EM_AUTOURLDETECT Ignored");
222 return 0;
223
224 case EM_CANPASTE:
225 DPRINTF_EDIT_MSG32("EM_CANPASTE Ignored");
226 return 0;
227
228 case EM_CANREDO:
229 DPRINTF_EDIT_MSG32("EM_CANREDO Ignored");
230 return 0;
231
232 case EM_DISPLAYBAND:
233 DPRINTF_EDIT_MSG32("EM_DISPLAYBAND Ignored");
234 return 0;
235
236 case EM_EXGETSEL:
237 DPRINTF_EDIT_MSG32("EM_EXGETSEL -> EM_GETSEL");
238 cr = (VOID *) lParam;
239 pfnEditProc( hwnd, EM_GETSEL, (INT)&cr->cpMin, (INT)&cr->cpMax);
240 TRACE("cpMin: 0x%x cpMax: 0x%x\n",(INT)cr->cpMin,(INT)cr->cpMax);
241 return 0;
242
243 case EM_EXLIMITTEXT:
244 {
245 DWORD limit = lParam;
246 DPRINTF_EDIT_MSG32("EM_EXLIMITTEXT");
247 if (limit > 65534)
248 {
249 limit = 0xFFFFFFFF;
250 }
251 return pfnEditProc(hwnd,EM_SETLIMITTEXT,limit,0);
252 }
253
254 case EM_EXLINEFROMCHAR:
255 DPRINTF_EDIT_MSG32("EM_EXLINEFROMCHAR -> LINEFROMCHAR");
256 return pfnEditProc( hwnd, EM_LINEFROMCHAR, lParam, wParam);
257
258 case EM_EXSETSEL:
259 DPRINTF_EDIT_MSG32("EM_EXSETSEL -> EM_SETSEL");
260 cr = (VOID *) lParam;
261 pfnEditProc( hwnd, EM_SETSEL, cr->cpMin, cr->cpMax);
262 return 0;
263
264 case EM_FINDTEXT:
265 DPRINTF_EDIT_MSG32("EM_FINDTEXT Ignored");
266 return 0;
267
268 case EM_FINDTEXTEX:
269 DPRINTF_EDIT_MSG32("EM_FINDTEXTEX Ignored");
270 return 0;
271
272 case EM_FINDTEXTEXW:
273 DPRINTF_EDIT_MSG32("EM_FINDTEXTEXW Ignored");
274 return 0;
275
276 case EM_FINDTEXTW:
277 DPRINTF_EDIT_MSG32("EM_FINDTEXTW Ignored");
278 return 0;
279
280 case EM_FINDWORDBREAK:
281 {
282 DWORD ret = 0;
283 DWORD len = GetWindowTextLengthA(hwnd);
284 LPWSTR lpszText = (LPWSTR)HeapAlloc(RICHED32_hHeap, 0, (len+1)*sizeof(WCHAR));
285
286 if(lpszText == NULL) {
287 DebugInt3();
288 return 0;
289 }
290 lpszText[0] = 0;
291 GetWindowTextW(hwnd, lpszText, len);
292
293 DPRINTF_EDIT_MSG32("EM_FINDWORDBREAK: partly implemented");
294 switch(wParam) {
295 case WB_ISDELIMITER:
296 case WB_LEFT:
297 case WB_RIGHT:
298 ret = EDIT_WordBreakProc(lpszText, lParam, len, wParam);
299 break;
300 }
301 HeapFree(RICHED32_hHeap, 0, lpszText);
302 return ret;
303 }
304
305 case EM_FORMATRANGE:
306 DPRINTF_EDIT_MSG32("EM_FORMATRANGE Ignored");
307 return 0;
308
309 case EM_GETAUTOURLDETECT:
310 DPRINTF_EDIT_MSG32("EM_GETAUTOURLDETECT Ignored");
311 return 0;
312
313 case EM_GETBIDIOPTIONS:
314 DPRINTF_EDIT_MSG32("EM_GETBIDIOPTIONS Ignored");
315 return 0;
316
317 case EM_GETCHARFORMAT:
318 DPRINTF_EDIT_MSG32("EM_GETCHARFORMAT Ignored");
319 return 0;
320
321 case EM_GETEDITSTYLE:
322 DPRINTF_EDIT_MSG32("EM_GETEDITSTYLE Ignored");
323 return 0;
324
325 case EM_GETEVENTMASK:
326 DPRINTF_EDIT_MSG32("EM_GETEVENTMASK Ignored");
327 return 0;
328
329 case EM_GETIMECOLOR:
330 DPRINTF_EDIT_MSG32("EM_GETIMECOLOR Ignored");
331 return 0;
332
333 case EM_GETIMECOMPMODE:
334 DPRINTF_EDIT_MSG32("EM_GETIMECOMPMODE Ignored");
335 return 0;
336
337 case EM_GETIMEOPTIONS:
338 DPRINTF_EDIT_MSG32("EM_GETIMEOPTIONS Ignored");
339 return 0;
340
341 case EM_GETLANGOPTIONS:
342 DPRINTF_EDIT_MSG32("STUB: EM_GETLANGOPTIONS");
343 return 0;
344
345 case EM_GETOLEINTERFACE:
346 DPRINTF_EDIT_MSG32("EM_GETOLEINTERFACE Ignored");
347 return 0;
348
349 case EM_GETOPTIONS:
350 DPRINTF_EDIT_MSG32("EM_GETOPTIONS Ignored");
351 return 0;
352
353 case EM_GETPARAFORMAT:
354 DPRINTF_EDIT_MSG32("EM_GETPARAFORMAT Ignored");
355 return 0;
356
357 case EM_GETPUNCTUATION:
358 DPRINTF_EDIT_MSG32("EM_GETPUNCTUATION Ignored");
359 return 0;
360
361 case EM_GETREDONAME:
362 DPRINTF_EDIT_MSG32("EM_GETREDONAME Ignored");
363 return 0;
364
365 case EM_GETSCROLLPOS:
366 DPRINTF_EDIT_MSG32("EM_GETSCROLLPOS Ignored");
367 return 0;
368
369 case EM_GETSELTEXT:
370 DPRINTF_EDIT_MSG32("EM_GETSELTEXT");
371 return RICHEDIT_GetSelText(hwnd,(void *)lParam);
372
373 case EM_GETTEXTEX:
374 DPRINTF_EDIT_MSG32("EM_GETTEXTEX Ignored");
375 return 0;
376
377 case EM_GETTEXTLENGTHEX:
378 DPRINTF_EDIT_MSG32("EM_GETTEXTLENGTHEX Ignored");
379 return 0;
380
381 case EM_GETTEXTMODE:
382 DPRINTF_EDIT_MSG32("EM_GETTEXTMODE Ignored");
383 return 0;
384
385 case EM_GETTEXTRANGE:
386 DPRINTF_EDIT_MSG32("EM_GETTEXTRANGE");
387 return RICHEDIT_GetTextRange(hwnd,(TEXTRANGEA *)lParam);
388
389 case EM_GETTYPOGRAPHYOPTIONS:
390 DPRINTF_EDIT_MSG32("EM_GETTYPOGRAPHYOPTIONS Ignored");
391 return 0;
392
393 case EM_GETUNDONAME:
394 DPRINTF_EDIT_MSG32("EM_GETUNDONAME Ignored");
395 return 0;
396
397 case EM_GETWORDBREAKPROCEX:
398 DPRINTF_EDIT_MSG32("EM_GETWORDBREAKPROCEX Ignored");
399 return 0;
400
401 case EM_GETWORDWRAPMODE:
402 DPRINTF_EDIT_MSG32("EM_GETWORDWRAPMODE Ignored");
403 return 0;
404
405 case EM_GETZOOM:
406 DPRINTF_EDIT_MSG32("EM_GETZOOM Ignored");
407 return 0;
408
409 case EM_HIDESELECTION:
410 DPRINTF_EDIT_MSG32("EM_HIDESELECTION Ignored");
411 return 0;
412
413 case EM_PASTESPECIAL:
414 DPRINTF_EDIT_MSG32("EM_PASTESPECIAL Ignored");
415 return 0;
416
417 case EM_RECONVERSION:
418 DPRINTF_EDIT_MSG32("EM_RECONVERSION Ignored");
419 return 0;
420
421 case EM_REDO:
422 DPRINTF_EDIT_MSG32("EM_REDO Ignored");
423 return 0;
424
425 case EM_REQUESTRESIZE:
426 DPRINTF_EDIT_MSG32("EM_REQUESTRESIZE Ignored");
427 return 0;
428
429 case EM_SELECTIONTYPE:
430 DPRINTF_EDIT_MSG32("EM_SELECTIONTYPE Ignored");
431 return 0;
432
433 case EM_SETBIDIOPTIONS:
434 DPRINTF_EDIT_MSG32("EM_SETBIDIOPTIONS Ignored");
435 return 0;
436
437 case EM_SETBKGNDCOLOR:
438 {
439 RICHEDIT_INFO *prinfo;
440
441 DPRINTF_EDIT_MSG32("EM_SETBKGNDCOLOR");
442
443 hProp = GetPropA(hwnd, RICHEDIT_WND_PROP);
444 prinfo = (RICHEDIT_INFO *)GlobalLock(hProp);
445 if(prinfo)
446 {
447 prinfo->cf.dwMask |= CFM_BACKCOLOR;
448 prinfo->cf.crBackColor = (wParam) ? GetSysColor(COLOR_BACKGROUND) : (COLORREF)lParam;
449
450 //Destroy old brush if present
451 if(prinfo->hbrBackground) DeleteObject(prinfo->hbrBackground);
452
453 //Create a brush that we return in WM_CTLCOLORSTATIC
454 prinfo->hbrBackground = (DWORD)CreateSolidBrush(prinfo->cf.crBackColor);
455
456 dprintf(("Set background color to %x brush %x", prinfo->cf.crBackColor, prinfo->hbrBackground));
457
458 GlobalUnlock(hProp);
459 }
460 return 0;
461 }
462
463 case EM_SETCHARFORMAT:
464 {
465 CHARFORMAT2A *pnewcf = (CHARFORMAT2A *)lParam;
466 RICHEDIT_INFO *prinfo;
467
468 DPRINTF_EDIT_MSG32("EM_SETCHARFORMAT: not completely implemented!!");
469
470 hProp = GetPropA(hwnd, RICHEDIT_WND_PROP);
471 prinfo = (RICHEDIT_INFO *)GlobalLock(hProp);
472 if(prinfo && pnewcf && pnewcf->cbSize >= sizeof(CHARFORMATA))
473 {
474 if((pnewcf->dwMask & CFM_COLOR) && !(pnewcf->dwEffects & CFE_AUTOCOLOR)) {
475 prinfo->cf.dwMask |= CFM_COLOR;
476 prinfo->cf.crTextColor = pnewcf->crTextColor;
477 dprintf(("Set text color to %x", prinfo->cf.crTextColor));
478 }
479 if(pnewcf->cbSize == sizeof(CHARFORMAT2A))
480 {
481 if((pnewcf->dwMask & CFM_BACKCOLOR) && !(pnewcf->dwEffects & CFE_AUTOBACKCOLOR))
482 {
483 prinfo->cf.dwMask |= CFM_BACKCOLOR;
484 prinfo->cf.crBackColor = pnewcf->crBackColor;
485
486 //Destroy old brush if present
487 if(prinfo->hbrBackground) DeleteObject(prinfo->hbrBackground);
488
489 //Create a brush that we return in WM_CTLCOLORSTATIC
490 prinfo->hbrBackground = (DWORD)CreateSolidBrush(prinfo->cf.crBackColor);
491
492 dprintf(("Set background color to %x brush %x", prinfo->cf.crBackColor, prinfo->hbrBackground));
493 }
494 }
495 }
496
497 if(prinfo) GlobalUnlock(hProp);
498 return 0;
499 }
500
501 case EM_SETEDITSTYLE:
502 DPRINTF_EDIT_MSG32("EM_SETEDITSTYLE Ignored");
503 return 0;
504
505 case EM_SETEVENTMASK:
506 DPRINTF_EDIT_MSG32("EM_SETEVENTMASK Ignored");
507 return 0;
508
509 case EM_SETFONTSIZE:
510 DPRINTF_EDIT_MSG32("EM_SETFONTSIZE Ignored");
511 return 0;
512
513 case EM_SETIMECOLOR:
514 DPRINTF_EDIT_MSG32("EM_SETIMECOLO Ignored");
515 return 0;
516
517 case EM_SETIMEOPTIONS:
518 DPRINTF_EDIT_MSG32("EM_SETIMEOPTIONS Ignored");
519 return 0;
520
521 case EM_SETLANGOPTIONS:
522 DPRINTF_EDIT_MSG32("EM_SETLANGOPTIONS Ignored");
523 return 0;
524
525 case EM_SETOLECALLBACK:
526 DPRINTF_EDIT_MSG32("EM_SETOLECALLBACK Ignored");
527 return 0;
528
529 case EM_SETOPTIONS:
530 DPRINTF_EDIT_MSG32("EM_SETOPTIONS Ignored");
531 return 0;
532
533 case EM_SETPALETTE:
534 DPRINTF_EDIT_MSG32("EM_SETPALETTE Ignored");
535 return 0;
536
537 case EM_SETPARAFORMAT:
538 DPRINTF_EDIT_MSG32("EM_SETPARAFORMAT Ignored");
539 return 0;
540
541 case EM_SETPUNCTUATION:
542 DPRINTF_EDIT_MSG32("EM_SETPUNCTUATION Ignored");
543 return 0;
544
545 case EM_SETSCROLLPOS:
546 DPRINTF_EDIT_MSG32("EM_SETSCROLLPOS Ignored");
547 return 0;
548
549 case EM_SETTARGETDEVICE:
550 DPRINTF_EDIT_MSG32("EM_SETTARGETDEVICE Ignored");
551 return 0;
552
553 case EM_SETTEXTEX:
554 DPRINTF_EDIT_MSG32("EM_SETTEXTEX Ignored");
555 return 0;
556
557 case EM_SETTEXTMODE:
558 DPRINTF_EDIT_MSG32("EM_SETTEXTMODE Ignored");
559 return 0;
560
561 case EM_SETTYPOGRAPHYOPTIONS:
562 DPRINTF_EDIT_MSG32("EM_SETTYPOGRAPHYOPTIONS Ignored");
563 return 0;
564
565 case EM_SETUNDOLIMIT:
566 DPRINTF_EDIT_MSG32("EM_SETUNDOLIMIT Ignored");
567 return 0;
568
569 case EM_SETWORDBREAKPROCEX:
570 DPRINTF_EDIT_MSG32("EM_SETWORDBREAKPROCEX Ignored");
571 return 0;
572
573 case EM_SETWORDWRAPMODE:
574 DPRINTF_EDIT_MSG32("EM_SETWORDWRAPMODE Ignored");
575 return 0;
576
577 case EM_SETZOOM:
578 DPRINTF_EDIT_MSG32("EM_SETZOOM Ignored");
579 return 0;
580
581 case EM_SHOWSCROLLBAR:
582 DPRINTF_EDIT_MSG32("EM_SHOWSCROLLBAR Ignored");
583 return 0;
584
585 case EM_STOPGROUPTYPING:
586 DPRINTF_EDIT_MSG32("EM_STOPGROUPTYPING Ignored");
587 return 0;
588
589 case EM_STREAMOUT:
590 DPRINTF_EDIT_MSG32("EM_STREAMOUT Ignored");
591 return 0;
592
593#if 0
594 case WM_CTLCOLORSTATIC:
595#ifdef __WIN32OS2__
596 case WM_CTLCOLOREDIT:
597 {
598 RICHEDIT_INFO *prinfo;
599 HBRUSH hBrush = 0;
600 HDC hdc = (HDC)wParam;
601
602 hProp = GetPropA(hwnd, RICHEDIT_WND_PROP);
603 prinfo = (RICHEDIT_INFO *)GlobalLock(hProp);
604 if(prinfo)
605 {
606 if(prinfo->cf.dwMask & CFM_BACKCOLOR) {
607 SetBkColor(hdc, prinfo->cf.crBackColor);
608 hBrush = prinfo->hbrBackground;
609 }
610 if(prinfo->cf.dwMask & CFM_COLOR) {
611 SetTextColor(hdc, prinfo->cf.crTextColor);
612 }
613 }
614 if(prinfo) GlobalUnlock(hProp);
615
616 if(hBrush) return hBrush;
617 }
618#endif
619 DPRINTF_EDIT_MSG32("WM_CTLCOLORSTATIC Passed to default");
620 return DefWindowProcA( hwnd,uMsg,wParam,lParam);
621#endif
622
623 /* Edit control messages that are different for RichEdit controls */
624 case EM_CHARFROMPOS:
625 {
626 POINTL *lpPoint = (POINTL *)lParam;
627 DWORD curpos;
628
629 curpos = pfnEditProc(hwnd, EM_CHARFROMPOS, wParam, MAKELPARAM(lpPoint->x, lpPoint->y));
630 TRACE("curpos: 0x%x richedit pos: 0x%x\n", curpos, LOWORD(curpos));
631 return LOWORD(curpos);
632 }
633
634 /*
635 * used by IE in the EULA box
636 */
637 case WM_ALTTABACTIVE:
638 DPRINTF_EDIT_MSG32("WM_ALTTABACTIVE");
639 return DefWindowProcA( hwnd,uMsg,wParam,lParam);
640 }
641
642 /* pass the rest to the edit window procedure */
643 TRACE("Message 0x%x Passed to pfnEditProc hwnd=%p, wParam=%08x, lParam=%08x\n",
644 uMsg, hwnd, (UINT)wParam, (UINT)lParam);
645
646 return pfnEditProc(hwnd,uMsg,wParam,lParam);
647}
648
649/***********************************************************************
650 * DllGetVersion [RICHED32.2]
651 *
652 * Retrieves version information of the 'RICHED32.DLL'
653 *
654 * PARAMS
655 * pdvi [O] pointer to version information structure.
656 *
657 * RETURNS
658 * Success: S_OK
659 * Failure: E_INVALIDARG
660 *
661 * NOTES
662 * Returns version of a comctl32.dll from IE4.01 SP1.
663 */
664
665HRESULT WINAPI
666RICHED32_DllGetVersion (DLLVERSIONINFO *pdvi)
667{
668 TRACE("\n");
669
670 if (pdvi->cbSize != sizeof(DLLVERSIONINFO)) {
671
672 return E_INVALIDARG;
673 }
674
675 pdvi->dwMajorVersion = 4;
676 pdvi->dwMinorVersion = 0;
677 pdvi->dwBuildNumber = 0;
678 pdvi->dwPlatformID = 0;
679
680 return S_OK;
681}
682
683/***
684 * DESCRIPTION:
685 * Registers the window class.
686 *
687 * PARAMETER(S):
688 * None
689 *
690 * RETURN:
691 * None
692 */
693VOID RICHED32_Register(void)
694{
695 WNDCLASSA wndClass;
696
697#ifdef __WIN32OS2__
698 WNDCLASSA classinfoA;
699 WNDCLASSW classinfoW;
700
701 if(GetClassInfoA(NULL, "EDIT", &classinfoA))
702 {
703 pfnEditProcA = classinfoA.lpfnWndProc;
704 }
705 else DebugInt3();
706 if(GetClassInfoW(NULL, L"EDIT", &classinfoW))
707 {
708 pfnEditProcW = classinfoW.lpfnWndProc;
709 }
710 else DebugInt3();
711
712 ZeroMemory(&wndClass, sizeof(WNDCLASSA));
713 wndClass.style = classinfoA.style;
714 wndClass.lpfnWndProc = (WNDPROC)RICHED32_WindowProc;
715 wndClass.cbClsExtra = classinfoA.cbClsExtra;
716 wndClass.cbWndExtra = classinfoA.cbWndExtra;
717 wndClass.hCursor = classinfoA.hCursor;
718 wndClass.hbrBackground = classinfoA.hbrBackground;
719 wndClass.lpszClassName = RICHEDIT_CLASS10A; /* WC_RICHED32A; */
720#else
721 TRACE("\n");
722
723 ZeroMemory(&wndClass, sizeof(WNDCLASSA));
724 wndClass.style = CS_HREDRAW | CS_VREDRAW | CS_GLOBALCLASS;
725 wndClass.lpfnWndProc = (WNDPROC)RICHED32_WindowProc;
726 wndClass.cbClsExtra = 0;
727 wndClass.cbWndExtra = 0; /*(sizeof(RICHED32_INFO *);*/
728 wndClass.hCursor = LoadCursorA(0, IDC_ARROWA);
729 wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
730 wndClass.lpszClassName = RICHEDIT_CLASS10A; /* WC_RICHED32A; */
731#endif
732
733 RegisterClassA (&wndClass);
734}
735
736/***
737 * DESCRIPTION:
738 * Unregisters the window class.
739 *
740 * PARAMETER(S):
741 * None
742 *
743 * RETURN:
744 * None
745 */
746VOID RICHED32_Unregister(void)
747{
748 TRACE("\n");
749
750 UnregisterClassA(RICHEDIT_CLASS10A, (HINSTANCE)NULL);
751
752#ifdef __WIN32OS2__
753 pfnEditProcA = (FARPROC)DefWindowProcA;
754 pfnEditProcW = (FARPROC)DefWindowProcW;
755#endif
756}
757
758INT RICHEDIT_GetTextRange(HWND hwnd,TEXTRANGEA *tr)
759{
760 UINT alloc_size, text_size, range_size;
761 char *text;
762
763 TRACE("start: 0x%x stop: 0x%x\n",(INT)tr->chrg.cpMin,(INT)tr->chrg.cpMax);
764
765 if (!(alloc_size = SendMessageA(hwnd,WM_GETTEXTLENGTH,0,0))) return FALSE;
766 if (!(text = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (alloc_size+1))))
767 return FALSE;
768 text_size = SendMessageA(hwnd,WM_GETTEXT,alloc_size,(INT)text);
769
770 if (text_size > tr->chrg.cpMin)
771 {
772 range_size = (text_size> tr->chrg.cpMax) ? (tr->chrg.cpMax - tr->chrg.cpMin) : (text_size - tr->chrg.cpMin);
773 TRACE("EditText: %.30s ...\n",text+tr->chrg.cpMin);
774 memcpy(tr->lpstrText,text+tr->chrg.cpMin,range_size);
775 }
776 else range_size = 0;
777 HeapFree(GetProcessHeap(), 0, text);
778
779 return range_size;
780}
781
782INT RICHEDIT_GetSelText(HWND hwnd,LPSTR lpstrBuffer)
783{
784 TEXTRANGEA textrange;
785
786 textrange.lpstrText = lpstrBuffer;
787 SendMessageA(hwnd,EM_GETSEL,(INT)&textrange.chrg.cpMin,(INT)&textrange.chrg.cpMax);
788 return RICHEDIT_GetTextRange(hwnd,&textrange);
789}
790
791/*********************************************************************
792 *
793 * EDIT_WordBreakProc
794 *
795 * Find the beginning of words.
796 * Note: unlike the specs for a WordBreakProc, this function only
797 * allows to be called without linebreaks between s[0] upto
798 * s[count - 1]. Remember it is only called
799 * internally, so we can decide this for ourselves.
800 *
801 */
802static INT CALLBACK EDIT_WordBreakProc(LPWSTR s, INT index, INT count, INT action)
803{
804 INT ret = 0;
805
806 TRACE("s=%p, index=%d, count=%d, action=%d\n", s, index, count, action);
807
808 if(!s) return 0;
809
810 switch (action) {
811 case WB_LEFT:
812 if (!count)
813 break;
814 if (index)
815 index--;
816 if (s[index] == ' ') {
817 while (index && (s[index] == ' '))
818 index--;
819 if (index) {
820 while (index && (s[index] != ' '))
821 index--;
822 if (s[index] == ' ')
823 index++;
824 }
825 } else {
826 while (index && (s[index] != ' '))
827 index--;
828 if (s[index] == ' ')
829 index++;
830 }
831 ret = index;
832 break;
833 case WB_RIGHT:
834 if (!count)
835 break;
836 if (index)
837 index--;
838 if (s[index] == ' ')
839 while ((index < count) && (s[index] == ' ')) index++;
840 else {
841 while (s[index] && (s[index] != ' ') && (index < count))
842 index++;
843 while ((s[index] == ' ') && (index < count)) index++;
844 }
845 ret = index;
846 break;
847 case WB_ISDELIMITER:
848 ret = (s[index] == ' ');
849 break;
850 default:
851 ERR("unknown action code, please report !\n");
852 break;
853 }
854 return ret;
855}
856
857
858#ifdef __WIN32OS2__
859/** Enables a callback replacement for the SetWindowTextA call finalizing
860 * the handling of an EM_STREAMIN message.
861 * @remark don't use this hack.
862 */
863BOOL WINAPI ODIN_RichedHack_EM_STREAMIN(BOOL (* WINAPI pfn)(HWND, LPSTR))
864{
865 pfnCustomRichedHack_EM_STREAMIN = pfn;
866 return TRUE;
867}
868#endif
869
Note: See TracBrowser for help on using the repository browser.