| 1 | /* $Id: richedit.c,v 1.4 2000-10-02 13:36:39 sandervl 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 |
|
|---|
| 27 | DEFAULT_DEBUG_CHANNEL(richedit)
|
|---|
| 28 |
|
|---|
| 29 | HANDLE RICHED32_hHeap = (HANDLE)NULL;
|
|---|
| 30 | DWORD RICHED32_dwProcessesAttached = 0;
|
|---|
| 31 | /* LPSTR RICHED32_aSubclass = (LPSTR)NULL; */
|
|---|
| 32 | HMODULE 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 |
|
|---|
| 47 | BOOL WINAPI
|
|---|
| 48 | RICHED32_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 | */
|
|---|
| 92 | static 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 | #ifdef __WIN32OS2__
|
|---|
| 144 | case WM_SETTEXT:
|
|---|
| 145 | return SetWindowTextA(hwndEdit, lParam);
|
|---|
| 146 | #endif
|
|---|
| 147 |
|
|---|
| 148 | case EM_STREAMIN:
|
|---|
| 149 |
|
|---|
| 150 | /* setup the RTF parser */
|
|---|
| 151 | RTFSetEditStream(( EDITSTREAM*)lParam);
|
|---|
| 152 | WriterInit();
|
|---|
| 153 | RTFInit ();
|
|---|
| 154 | BeginFile();
|
|---|
| 155 |
|
|---|
| 156 | /* do the parsing */
|
|---|
| 157 | RTFRead ();
|
|---|
| 158 |
|
|---|
| 159 | rtfBufferSize = RTFToBuffer(NULL, 0);
|
|---|
| 160 | rtfBuffer = HeapAlloc(RICHED32_hHeap, 0,rtfBufferSize*sizeof(char));
|
|---|
| 161 | if(rtfBuffer)
|
|---|
| 162 | {
|
|---|
| 163 | RTFToBuffer(rtfBuffer, rtfBufferSize);
|
|---|
| 164 | SetWindowTextA(hwndEdit,rtfBuffer);
|
|---|
| 165 | HeapFree(RICHED32_hHeap, 0,rtfBuffer);
|
|---|
| 166 | }
|
|---|
| 167 | else
|
|---|
| 168 | WARN("Not enough memory for a allocating rtfBuffer\n");
|
|---|
| 169 |
|
|---|
| 170 | return 0;
|
|---|
| 171 | }
|
|---|
| 172 | /*return SendMessageA( hwndEdit,uMsg,wParam,lParam);*/
|
|---|
| 173 | return DefWindowProcA( hwnd,uMsg,wParam,lParam);
|
|---|
| 174 | }
|
|---|
| 175 |
|
|---|
| 176 | /*
|
|---|
| 177 | * DllGetVersion [COMCTL32.25]
|
|---|
| 178 | *
|
|---|
| 179 | * Retrieves version information of the 'COMCTL32.DLL'
|
|---|
| 180 | *
|
|---|
| 181 | * PARAMS
|
|---|
| 182 | * pdvi [O] pointer to version information structure.
|
|---|
| 183 | *
|
|---|
| 184 | * RETURNS
|
|---|
| 185 | * Success: S_OK
|
|---|
| 186 | * Failure: E_INVALIDARG
|
|---|
| 187 | *
|
|---|
| 188 | * NOTES
|
|---|
| 189 | * Returns version of a comctl32.dll from IE4.01 SP1.
|
|---|
| 190 | */
|
|---|
| 191 |
|
|---|
| 192 | HRESULT WINAPI
|
|---|
| 193 | RICHED32_DllGetVersion (DLLVERSIONINFO *pdvi)
|
|---|
| 194 | {
|
|---|
| 195 | if (pdvi->cbSize != sizeof(DLLVERSIONINFO)) {
|
|---|
| 196 |
|
|---|
| 197 | return E_INVALIDARG;
|
|---|
| 198 | }
|
|---|
| 199 |
|
|---|
| 200 | pdvi->dwMajorVersion = 4;
|
|---|
| 201 | pdvi->dwMinorVersion = 0;
|
|---|
| 202 | pdvi->dwBuildNumber = 0;
|
|---|
| 203 | pdvi->dwPlatformID = 0;
|
|---|
| 204 |
|
|---|
| 205 | return S_OK;
|
|---|
| 206 | }
|
|---|
| 207 |
|
|---|
| 208 | /***
|
|---|
| 209 | * DESCRIPTION:
|
|---|
| 210 | * Registers the window class.
|
|---|
| 211 | *
|
|---|
| 212 | * PARAMETER(S):
|
|---|
| 213 | * None
|
|---|
| 214 | *
|
|---|
| 215 | * RETURN:
|
|---|
| 216 | * None
|
|---|
| 217 | */
|
|---|
| 218 | VOID RICHED32_Register(void)
|
|---|
| 219 | {
|
|---|
| 220 | WNDCLASSA wndClass;
|
|---|
| 221 |
|
|---|
| 222 | ZeroMemory(&wndClass, sizeof(WNDCLASSA));
|
|---|
| 223 | wndClass.style = CS_HREDRAW | CS_VREDRAW | CS_GLOBALCLASS;
|
|---|
| 224 | wndClass.lpfnWndProc = (WNDPROC)RICHED32_WindowProc;
|
|---|
| 225 | wndClass.cbClsExtra = 0;
|
|---|
| 226 | wndClass.cbWndExtra = 0; /*(sizeof(RICHED32_INFO *);*/
|
|---|
| 227 | wndClass.hCursor = LoadCursorA(0, IDC_ARROWA);
|
|---|
| 228 | wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
|
|---|
| 229 | wndClass.lpszClassName = RICHEDIT_CLASS10A;//WC_RICHED32A;
|
|---|
| 230 |
|
|---|
| 231 | RegisterClassA (&wndClass);
|
|---|
| 232 | }
|
|---|
| 233 |
|
|---|
| 234 | /***
|
|---|
| 235 | * DESCRIPTION:
|
|---|
| 236 | * Unregisters the window class.
|
|---|
| 237 | *
|
|---|
| 238 | * PARAMETER(S):
|
|---|
| 239 | * None
|
|---|
| 240 | *
|
|---|
| 241 | * RETURN:
|
|---|
| 242 | * None
|
|---|
| 243 | */
|
|---|
| 244 | VOID RICHED32_Unregister(void)
|
|---|
| 245 | {
|
|---|
| 246 | UnregisterClassA(RICHEDIT_CLASS10A, (HINSTANCE)NULL);
|
|---|
| 247 | }
|
|---|