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

Last change on this file since 3922 was 3922, checked in by bird, 25 years ago

Added the CVS Id keyword.

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