Make reg the default output chanel.
[wine/dcerpc.git] / dlls / richedit / richedit.c
blob6e11225792368753156b46866a4fc801c566dc44
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"
20 #include "shlwapi.h"
22 #include "rtf.h"
23 #include "rtf2text.h"
25 #define ID_EDIT 1
27 DEFAULT_DEBUG_CHANNEL(richedit)
29 HANDLE RICHED32_hHeap = (HANDLE)NULL;
30 DWORD RICHED32_dwProcessesAttached = 0;
31 /* LPSTR RICHED32_aSubclass = (LPSTR)NULL; */
32 HMODULE RICHED32_hModule = 0;
34 /***********************************************************************
35 * RICHED32_LibMain [Internal] Initializes the internal 'RICHED32.DLL'.
37 * PARAMS
38 * hinstDLL [I] handle to the DLL's instance
39 * fdwReason [I]
40 * lpvReserved [I] reserved, must be NULL
42 * RETURNS
43 * Success: TRUE
44 * Failure: FALSE
47 BOOL WINAPI
48 RICHED32_LibMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
51 switch (fdwReason) {
52 case DLL_PROCESS_ATTACH:
54 if (RICHED32_dwProcessesAttached == 0) {
56 /* This will be wrong for any other process attching in this address-space! */
57 RICHED32_hModule = (HMODULE)hinstDLL;
59 /* create private heap */
60 RICHED32_hHeap = HeapCreate (0, 0x10000, 0);
64 /* register the Rich Edit class */
65 RICHED32_Register ();
67 RICHED32_dwProcessesAttached++;
68 break;
70 case DLL_PROCESS_DETACH:
71 RICHED32_dwProcessesAttached--;
73 /* unregister all common control classes */
74 RICHED32_Unregister ();
76 if (RICHED32_dwProcessesAttached == 0) {
77 HeapDestroy (RICHED32_hHeap);
78 RICHED32_hHeap = (HANDLE)NULL;
80 break;
83 return TRUE;
88 * DESCRIPTION:
89 * Window procedure of the RichEdit control.
92 static LRESULT WINAPI RICHED32_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,
93 LPARAM lParam)
95 int RTFToBuffer(char* pBuffer, int nBufferSize);
96 LONG newstyle = 0;
97 LONG style = 0;
99 static HWND hwndEdit;
100 static char* rtfBuffer;
101 int rtfBufferSize;
103 switch (uMsg)
106 case WM_CREATE :
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;
115 hwndEdit = CreateWindowA ("edit", ((LPCREATESTRUCTA) lParam)->lpszName,
116 style, 0, 0, 0, 0,
117 hwnd, (HMENU) ID_EDIT,
118 ((LPCREATESTRUCTA) lParam)->hInstance, NULL) ;
120 SetWindowLongA(hwnd,GWL_STYLE, newstyle);
121 return 0 ;
123 case WM_SETFOCUS :
124 SetFocus (hwndEdit) ;
125 return 0 ;
127 case WM_SIZE :
128 MoveWindow (hwndEdit, 0, 0, LOWORD (lParam), HIWORD (lParam), TRUE) ;
129 return 0 ;
131 case WM_COMMAND :
132 if (LOWORD (wParam) == ID_EDIT)
133 if (HIWORD (wParam) == EN_ERRSPACE ||
134 HIWORD (wParam) == EN_MAXTEXT)
136 MessageBoxA (hwnd, "RichEdit control out of space.",
137 "ERROR", MB_OK | MB_ICONSTOP) ;
138 return 0 ;
140 case EM_STREAMIN:
142 /* setup the RTF parser */
143 RTFSetEditStream(( EDITSTREAM*)lParam);
144 WriterInit();
145 RTFInit ();
146 BeginFile();
148 /* do the parsing */
149 RTFRead ();
151 rtfBufferSize = RTFToBuffer(NULL, 0);
152 rtfBuffer = HeapAlloc(RICHED32_hHeap, 0,rtfBufferSize*sizeof(char));
153 if(rtfBuffer)
155 RTFToBuffer(rtfBuffer, rtfBufferSize);
156 SetWindowTextA(hwndEdit,rtfBuffer);
157 HeapFree(RICHED32_hHeap, 0,rtfBuffer);
159 else
160 WARN("Not enough memory for a allocating rtfBuffer\n");
162 return 0;
164 /*return SendMessageA( hwndEdit,uMsg,wParam,lParam);*/
165 return DefWindowProcA( hwnd,uMsg,wParam,lParam);
168 /***********************************************************************
169 * DllGetVersion [COMCTL32.25]
171 * Retrieves version information of the 'COMCTL32.DLL'
173 * PARAMS
174 * pdvi [O] pointer to version information structure.
176 * RETURNS
177 * Success: S_OK
178 * Failure: E_INVALIDARG
180 * NOTES
181 * Returns version of a comctl32.dll from IE4.01 SP1.
184 HRESULT WINAPI
185 RICHED32_DllGetVersion (DLLVERSIONINFO *pdvi)
187 if (pdvi->cbSize != sizeof(DLLVERSIONINFO)) {
189 return E_INVALIDARG;
192 pdvi->dwMajorVersion = 4;
193 pdvi->dwMinorVersion = 0;
194 pdvi->dwBuildNumber = 0;
195 pdvi->dwPlatformID = 0;
197 return S_OK;
200 /***
201 * DESCRIPTION:
202 * Registers the window class.
204 * PARAMETER(S):
205 * None
207 * RETURN:
208 * None
210 VOID RICHED32_Register(void)
212 WNDCLASSA wndClass;
214 ZeroMemory(&wndClass, sizeof(WNDCLASSA));
215 wndClass.style = CS_HREDRAW | CS_VREDRAW | CS_GLOBALCLASS;
216 wndClass.lpfnWndProc = (WNDPROC)RICHED32_WindowProc;
217 wndClass.cbClsExtra = 0;
218 wndClass.cbWndExtra = 0; /*(sizeof(RICHED32_INFO *);*/
219 wndClass.hCursor = LoadCursorA(0, IDC_ARROWA);
220 wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
221 wndClass.lpszClassName = RICHEDIT_CLASS10A;//WC_RICHED32A;
223 RegisterClassA (&wndClass);
226 /***
227 * DESCRIPTION:
228 * Unregisters the window class.
230 * PARAMETER(S):
231 * None
233 * RETURN:
234 * None
236 VOID RICHED32_Unregister(void)
238 UnregisterClassA(RICHEDIT_CLASS10A, (HINSTANCE)NULL);