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

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

created; wine port

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 hwndEdit = CreateWindowA ("edit", ((LPCREATESTRUCTA) lParam)->lpszName,
115 style, 0, 0, 0, 0,
116 hwnd, (HMENU) ID_EDIT,
117 ((LPCREATESTRUCTA) lParam)->hInstance, NULL) ;
118
119 SetWindowLongA(hwnd,GWL_STYLE, newstyle);
120 return 0 ;
121
122 case WM_SETFOCUS :
123 SetFocus (hwndEdit) ;
124 return 0 ;
125
126 case WM_SIZE :
127 MoveWindow (hwndEdit, 0, 0, LOWORD (lParam), HIWORD (lParam), TRUE) ;
128 return 0 ;
129
130 case WM_COMMAND :
131 if (LOWORD (wParam) == ID_EDIT)
132 if (HIWORD (wParam) == EN_ERRSPACE ||
133 HIWORD (wParam) == EN_MAXTEXT)
134
135 MessageBoxA (hwnd, "RichEdit control out of space.",
136 "ERROR", MB_OK | MB_ICONSTOP) ;
137 return 0 ;
138
139 case EM_STREAMIN:
140
141 /* setup the RTF parser */
142 RTFSetEditStream(( EDITSTREAM*)lParam);
143 WriterInit();
144 RTFInit ();
145 BeginFile();
146
147 /* do the parsing */
148 RTFRead ();
149
150 rtfBufferSize = RTFToBuffer(NULL, 0);
151 rtfBuffer = HeapAlloc(RICHED32_hHeap, 0,rtfBufferSize*sizeof(char));
152 if(rtfBuffer)
153 {
154 RTFToBuffer(rtfBuffer, rtfBufferSize);
155 SetWindowTextA(hwndEdit,rtfBuffer);
156 HeapFree(RICHED32_hHeap, 0,rtfBuffer);
157 }
158 else
159 WARN("Not enough memory for a allocating rtfBuffer\n");
160
161 return 0;
162 }
163 /*return SendMessageA( hwndEdit,uMsg,wParam,lParam);*/
164 return DefWindowProcA( hwnd,uMsg,wParam,lParam);
165}
166
167/*
168 * DllGetVersion [COMCTL32.25]
169 *
170 * Retrieves version information of the 'COMCTL32.DLL'
171 *
172 * PARAMS
173 * pdvi [O] pointer to version information structure.
174 *
175 * RETURNS
176 * Success: S_OK
177 * Failure: E_INVALIDARG
178 *
179 * NOTES
180 * Returns version of a comctl32.dll from IE4.01 SP1.
181 */
182
183HRESULT WINAPI
184RICHED32_DllGetVersion (DLLVERSIONINFO *pdvi)
185{
186 if (pdvi->cbSize != sizeof(DLLVERSIONINFO)) {
187
188 return E_INVALIDARG;
189 }
190
191 pdvi->dwMajorVersion = 4;
192 pdvi->dwMinorVersion = 0;
193 pdvi->dwBuildNumber = 0;
194 pdvi->dwPlatformID = 0;
195
196 return S_OK;
197}
198
199/***
200 * DESCRIPTION:
201 * Registers the window class.
202 *
203 * PARAMETER(S):
204 * None
205 *
206 * RETURN:
207 * None
208 */
209VOID RICHED32_Register(void)
210{
211 WNDCLASSA wndClass;
212
213 ZeroMemory(&wndClass, sizeof(WNDCLASSA));
214 wndClass.style = CS_HREDRAW | CS_VREDRAW | CS_GLOBALCLASS;
215 wndClass.lpfnWndProc = (WNDPROC)RICHED32_WindowProc;
216 wndClass.cbClsExtra = 0;
217 wndClass.cbWndExtra = 0; /*(sizeof(RICHED32_INFO *);*/
218 wndClass.hCursor = LoadCursorA(0, IDC_ARROWA);
219 wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
220 wndClass.lpszClassName = RICHEDIT_CLASS10A;//WC_RICHED32A;
221
222 RegisterClassA (&wndClass);
223}
224
225/***
226 * DESCRIPTION:
227 * Unregisters the window class.
228 *
229 * PARAMETER(S):
230 * None
231 *
232 * RETURN:
233 * None
234 */
235VOID RICHED32_Unregister(void)
236{
237 UnregisterClassA(RICHEDIT_CLASS10A, (HINSTANCE)NULL);
238}
Note: See TracBrowser for help on using the repository browser.