Jean-Claude Batista
[wine.git] / dlls / richedit / richedit.c
blob2e2de8b54170f4b0030e5bc7f62f70cbe491f7d1
1 /*
2 * RichEdit32 functions
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.
8 * Copyright 2000 by Jean-Claude Batista
9 *
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"
21 #include "rtf.h"
22 #include "rtf2text.h"
24 #define ID_EDIT 1
26 DEFAULT_DEBUG_CHANNEL(richedit)
28 HANDLE RICHED32_hHeap = (HANDLE)NULL;
29 DWORD RICHED32_dwProcessesAttached = 0;
30 /* LPSTR RICHED32_aSubclass = (LPSTR)NULL; */
31 HMODULE RICHED32_hModule = 0;
34 * RICHED32_LibMain [Internal] Initializes the internal 'RICHED32.DLL'.
36 * PARAMS
37 * hinstDLL [I] handle to the 'dlls' instance
38 * fdwReason [I]
39 * lpvReserved [I] reserverd, must be NULL
41 * RETURNS
42 * Success: TRUE
43 * Failure: FALSE
46 BOOL WINAPI
47 RICHED32_LibMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
50 switch (fdwReason) {
51 case DLL_PROCESS_ATTACH:
53 if (RICHED32_dwProcessesAttached == 0) {
55 /* This will be wrong for any other process attching in this address-space! */
56 RICHED32_hModule = (HMODULE)hinstDLL;
58 /* create private heap */
59 RICHED32_hHeap = HeapCreate (0, 0x10000, 0);
63 /* register the Rich Edit class */
64 RICHED32_Register ();
66 RICHED32_dwProcessesAttached++;
67 break;
69 case DLL_PROCESS_DETACH:
70 RICHED32_dwProcessesAttached--;
72 /* unregister all common control classes */
73 RICHED32_Unregister ();
75 if (RICHED32_dwProcessesAttached == 0) {
76 HeapDestroy (RICHED32_hHeap);
77 RICHED32_hHeap = (HANDLE)NULL;
79 break;
82 return TRUE;
87 * DESCRIPTION:
88 * Window procedure of the RichEdit control.
91 static LRESULT WINAPI RICHED32_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,
92 LPARAM lParam)
94 int RTFToBuffer(char* pBuffer, int nBufferSize);
95 LONG newstyle = 0;
96 LONG style = 0;
98 static HWND hwndEdit;
99 static char* rtfBuffer;
100 int rtfBufferSize;
102 switch (uMsg)
105 case WM_CREATE :
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;
114 hwndEdit = CreateWindowA ("edit", ((LPCREATESTRUCTA) lParam)->lpszName,
115 style, 0, 0, 0, 0,
116 hwnd, (HMENU) ID_EDIT,
117 ((LPCREATESTRUCTA) lParam)->hInstance, NULL) ;
119 SetWindowLongA(hwnd,GWL_STYLE, newstyle);
120 return 0 ;
122 case WM_SETFOCUS :
123 SetFocus (hwndEdit) ;
124 return 0 ;
126 case WM_SIZE :
127 MoveWindow (hwndEdit, 0, 0, LOWORD (lParam), HIWORD (lParam), TRUE) ;
128 return 0 ;
130 case WM_COMMAND :
131 if (LOWORD (wParam) == ID_EDIT)
132 if (HIWORD (wParam) == EN_ERRSPACE ||
133 HIWORD (wParam) == EN_MAXTEXT)
135 MessageBoxA (hwnd, "RichEdit control out of space.",
136 "ERROR", MB_OK | MB_ICONSTOP) ;
137 return 0 ;
139 case EM_STREAMIN:
141 /* setup the RTF parser */
142 RTFSetEditStream(( EDITSTREAM*)lParam);
143 WriterInit();
144 RTFInit ();
145 BeginFile();
147 /* do the parsing */
148 RTFRead ();
150 rtfBufferSize = RTFToBuffer(NULL, 0);
151 rtfBuffer = HeapAlloc(RICHED32_hHeap, 0,rtfBufferSize*sizeof(char));
152 if(rtfBuffer)
154 RTFToBuffer(rtfBuffer, rtfBufferSize);
155 SetWindowTextA(hwndEdit,rtfBuffer);
156 HeapFree(RICHED32_hHeap, 0,rtfBuffer);
158 else
159 WARN("Not enough memory for a allocating rtfBuffer\n");
161 return 0;
163 /*return SendMessageA( hwndEdit,uMsg,wParam,lParam);*/
164 return DefWindowProcA( hwnd,uMsg,wParam,lParam);
168 * DllGetVersion [COMCTL32.25]
170 * Retrieves version information of the 'COMCTL32.DLL'
172 * PARAMS
173 * pdvi [O] pointer to version information structure.
175 * RETURNS
176 * Success: S_OK
177 * Failure: E_INVALIDARG
179 * NOTES
180 * Returns version of a comctl32.dll from IE4.01 SP1.
183 HRESULT WINAPI
184 RICHED32_DllGetVersion (DLLVERSIONINFO *pdvi)
186 if (pdvi->cbSize != sizeof(DLLVERSIONINFO)) {
188 return E_INVALIDARG;
191 pdvi->dwMajorVersion = 4;
192 pdvi->dwMinorVersion = 0;
193 pdvi->dwBuildNumber = 0;
194 pdvi->dwPlatformID = 0;
196 return S_OK;
199 /***
200 * DESCRIPTION:
201 * Registers the window class.
203 * PARAMETER(S):
204 * None
206 * RETURN:
207 * None
209 VOID RICHED32_Register(void)
211 WNDCLASSA wndClass;
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;
222 RegisterClassA (&wndClass);
225 /***
226 * DESCRIPTION:
227 * Unregisters the window class.
229 * PARAMETER(S):
230 * None
232 * RETURN:
233 * None
235 VOID RICHED32_Unregister(void)
237 UnregisterClassA(RICHEDIT_CLASS10A, (HINSTANCE)NULL);