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

Last change on this file since 9859 was 9859, checked in by sandervl, 22 years ago

Rewrite (no more child window), EM_CHARFROMPOS differs from Edit control, implemented EM_FINDWORDBREAK

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