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

Last change on this file since 3787 was 3787, checked in by sandervl, 25 years ago

edit window creation fix (child)

File size: 5.7 KB
Line 
1/*
2 * RichEdit32 functions
3 *
4 * This module is a simple wrap-arround the edit controls.
5 * At the point, it is good only for application who use the RICHEDIT control to
6 * display RTF text.
7 *
8 * Copyright 2000 by Jean-Claude Batista
9 *
10 */
11
12#include "windows.h"
13#include "winbase.h"
14#include "heap.h"
15#include "debugtools.h"
16#include "winerror.h"
17#include "riched32.h"
18#include "richedit.h"
19#include "charlist.h"
20
21#include "rtf.h"
22#include "rtf2text.h"
23
24#define ID_EDIT 1
25
26DEFAULT_DEBUG_CHANNEL(richedit)
27
28HANDLE RICHED32_hHeap = (HANDLE)NULL;
29DWORD RICHED32_dwProcessesAttached = 0;
30/* LPSTR RICHED32_aSubclass = (LPSTR)NULL; */
31HMODULE RICHED32_hModule = 0;
32
33/*
34 * RICHED32_LibMain [Internal] Initializes the internal 'RICHED32.DLL'.
35 *
36 * PARAMS
37 * hinstDLL [I] handle to the 'dlls' instance
38 * fdwReason [I]
39 * lpvReserved [I] reserverd, must be NULL
40 *
41 * RETURNS
42 * Success: TRUE
43 * Failure: FALSE
44 */
45
46BOOL WINAPI
47RICHED32_LibMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
48{
49
50 switch (fdwReason) {
51 case DLL_PROCESS_ATTACH:
52
53 if (RICHED32_dwProcessesAttached == 0) {
54
55 /* This will be wrong for any other process attching in this address-space! */
56 RICHED32_hModule = (HMODULE)hinstDLL;
57
58 /* create private heap */
59 RICHED32_hHeap = HeapCreate (0, 0x10000, 0);
60
61 }
62
63 /* register the Rich Edit class */
64 RICHED32_Register ();
65
66 RICHED32_dwProcessesAttached++;
67 break;
68
69 case DLL_PROCESS_DETACH:
70 RICHED32_dwProcessesAttached--;
71
72 /* unregister all common control classes */
73 RICHED32_Unregister ();
74
75 if (RICHED32_dwProcessesAttached == 0) {
76 HeapDestroy (RICHED32_hHeap);
77 RICHED32_hHeap = (HANDLE)NULL;
78 }
79 break;
80 }
81
82 return TRUE;
83}
84
85/*
86 *
87 * DESCRIPTION:
88 * Window procedure of the RichEdit control.
89 *
90 */
91static LRESULT WINAPI RICHED32_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,
92 LPARAM lParam)
93{
94 int RTFToBuffer(char* pBuffer, int nBufferSize);
95 LONG newstyle = 0;
96 LONG style = 0;
97
98 static HWND hwndEdit;
99 static char* rtfBuffer;
100 int rtfBufferSize;
101
102 switch (uMsg)
103 {
104
105 case WM_CREATE :
106
107 /* remove SCROLLBARS from the current window style */
108 newstyle = style = ((LPCREATESTRUCTA) lParam)->style;
109 newstyle &= ~WS_HSCROLL;
110 newstyle &= ~WS_VSCROLL;
111 newstyle &= ~ES_AUTOHSCROLL;
112 newstyle &= ~ES_AUTOVSCROLL;
113
114#ifdef __WIN32OS2__
115 style |= WS_CHILD;
116#endif
117 hwndEdit = CreateWindowA ("edit", ((LPCREATESTRUCTA) lParam)->lpszName,
118 style, 0, 0, 0, 0,
119 hwnd, (HMENU) ID_EDIT,
120 ((LPCREATESTRUCTA) lParam)->hInstance, NULL) ;
121
122 SetWindowLongA(hwnd,GWL_STYLE, newstyle);
123 return 0 ;
124
125 case WM_SETFOCUS :
126 SetFocus (hwndEdit) ;
127 return 0 ;
128
129 case WM_SIZE :
130 MoveWindow (hwndEdit, 0, 0, LOWORD (lParam), HIWORD (lParam), TRUE) ;
131 return 0 ;
132
133 case WM_COMMAND :
134 if (LOWORD (wParam) == ID_EDIT)
135 if (HIWORD (wParam) == EN_ERRSPACE ||
136 HIWORD (wParam) == EN_MAXTEXT)
137
138 MessageBoxA (hwnd, "RichEdit control out of space.",
139 "ERROR", MB_OK | MB_ICONSTOP) ;
140 return 0 ;
141
142 case EM_STREAMIN:
143
144 /* setup the RTF parser */
145 RTFSetEditStream(( EDITSTREAM*)lParam);
146 WriterInit();
147 RTFInit ();
148 BeginFile();
149
150 /* do the parsing */
151 RTFRead ();
152
153 rtfBufferSize = RTFToBuffer(NULL, 0);
154 rtfBuffer = HeapAlloc(RICHED32_hHeap, 0,rtfBufferSize*sizeof(char));
155 if(rtfBuffer)
156 {
157 RTFToBuffer(rtfBuffer, rtfBufferSize);
158 SetWindowTextA(hwndEdit,rtfBuffer);
159 HeapFree(RICHED32_hHeap, 0,rtfBuffer);
160 }
161 else
162 WARN("Not enough memory for a allocating rtfBuffer\n");
163
164 return 0;
165 }
166 /*return SendMessageA( hwndEdit,uMsg,wParam,lParam);*/
167 return DefWindowProcA( hwnd,uMsg,wParam,lParam);
168}
169
170/*
171 * DllGetVersion [COMCTL32.25]
172 *
173 * Retrieves version information of the 'COMCTL32.DLL'
174 *
175 * PARAMS
176 * pdvi [O] pointer to version information structure.
177 *
178 * RETURNS
179 * Success: S_OK
180 * Failure: E_INVALIDARG
181 *
182 * NOTES
183 * Returns version of a comctl32.dll from IE4.01 SP1.
184 */
185
186HRESULT WINAPI
187RICHED32_DllGetVersion (DLLVERSIONINFO *pdvi)
188{
189 if (pdvi->cbSize != sizeof(DLLVERSIONINFO)) {
190
191 return E_INVALIDARG;
192 }
193
194 pdvi->dwMajorVersion = 4;
195 pdvi->dwMinorVersion = 0;
196 pdvi->dwBuildNumber = 0;
197 pdvi->dwPlatformID = 0;
198
199 return S_OK;
200}
201
202/***
203 * DESCRIPTION:
204 * Registers the window class.
205 *
206 * PARAMETER(S):
207 * None
208 *
209 * RETURN:
210 * None
211 */
212VOID RICHED32_Register(void)
213{
214 WNDCLASSA wndClass;
215
216 ZeroMemory(&wndClass, sizeof(WNDCLASSA));
217 wndClass.style = CS_HREDRAW | CS_VREDRAW | CS_GLOBALCLASS;
218 wndClass.lpfnWndProc = (WNDPROC)RICHED32_WindowProc;
219 wndClass.cbClsExtra = 0;
220 wndClass.cbWndExtra = 0; /*(sizeof(RICHED32_INFO *);*/
221 wndClass.hCursor = LoadCursorA(0, IDC_ARROWA);
222 wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
223 wndClass.lpszClassName = RICHEDIT_CLASS10A;//WC_RICHED32A;
224
225 RegisterClassA (&wndClass);
226}
227
228/***
229 * DESCRIPTION:
230 * Unregisters the window class.
231 *
232 * PARAMETER(S):
233 * None
234 *
235 * RETURN:
236 * None
237 */
238VOID RICHED32_Unregister(void)
239{
240 UnregisterClassA(RICHEDIT_CLASS10A, (HINSTANCE)NULL);
241}
Note: See TracBrowser for help on using the repository browser.