MCPcopy Create free account
hub / github.com/ProgerXP/Notepad2e / EditConvertText

Function EditConvertText

src/Edit.c:314–360  ·  view source on GitHub ↗

============================================================================= EditConvertText()

Source from the content-addressed store, hash-verified

312// EditConvertText()
313//
314BOOL EditConvertText ( HWND hwnd, UINT cpSource, UINT cpDest, BOOL bSetSavePoint )
315{
316 struct TextRange tr = { { 0, -1 }, NULL };
317 int length, cbText, cbwText;
318 char *pchText;
319 WCHAR *pwchText;
320 if ( cpSource == cpDest ) {
321 return ( TRUE );
322 }
323 length = ( int ) SendMessage ( hwnd, SCI_GETLENGTH, 0, 0 );
324 if ( length == 0 ) {
325 SendMessage ( hwnd, SCI_CANCEL, 0, 0 );
326 SendMessage ( hwnd, SCI_SETUNDOCOLLECTION, 0, 0 );
327 SendMessage ( hwnd, SCI_EMPTYUNDOBUFFER, 0, 0 );
328 SendMessage ( hwnd, SCI_CLEARALL, 0, 0 );
329 SendMessage ( hwnd, SCI_MARKERDELETEALL, ( WPARAM ) - 1, 0 );
330 SendMessage ( hwnd, SCI_SETCODEPAGE, cpDest, 0 );
331 SendMessage ( hwnd, SCI_SETUNDOCOLLECTION, 1, 0 );
332 SendMessage ( hwnd, EM_EMPTYUNDOBUFFER, 0, 0 );
333 SendMessage ( hwnd, SCI_GOTOPOS, 0, 0 );
334 SendMessage ( hwnd, SCI_CHOOSECARETX, 0, 0 );
335 if ( bSetSavePoint ) {
336 SendMessage ( hwnd, SCI_SETSAVEPOINT, 0, 0 );
337 }
338 } else {
339 pchText = GlobalAlloc ( GPTR, length * 5 + 2 );
340 tr.lpstrText = pchText;
341 SendMessage ( hwnd, SCI_GETTEXTRANGE, 0, ( LPARAM ) &tr );
342 pwchText = GlobalAlloc ( GPTR, length * 3 + 2 );
343 cbwText = MultiByteToWideChar ( cpSource, 0, pchText, length, pwchText, length * 3 + 2 );
344 cbText = WideCharToMultiByte ( cpDest, 0, pwchText, cbwText, pchText, length * 5 + 2, NULL, NULL );
345 SendMessage ( hwnd, SCI_CANCEL, 0, 0 );
346 SendMessage ( hwnd, SCI_SETUNDOCOLLECTION, 0, 0 );
347 SendMessage ( hwnd, SCI_EMPTYUNDOBUFFER, 0, 0 );
348 SendMessage ( hwnd, SCI_CLEARALL, 0, 0 );
349 SendMessage ( hwnd, SCI_MARKERDELETEALL, ( WPARAM ) - 1, 0 );
350 SendMessage ( hwnd, SCI_SETCODEPAGE, cpDest, 0 );
351 SendMessage ( hwnd, SCI_ADDTEXT, cbText, ( LPARAM ) pchText );
352 SendMessage ( hwnd, SCI_EMPTYUNDOBUFFER, 0, 0 );
353 SendMessage ( hwnd, SCI_SETUNDOCOLLECTION, 1, 0 );
354 SendMessage ( hwnd, SCI_GOTOPOS, 0, 0 );
355 SendMessage ( hwnd, SCI_CHOOSECARETX, 0, 0 );
356 GlobalFree ( pchText );
357 GlobalFree ( pwchText );
358 }
359 return ( TRUE );
360}
361
362
363//=============================================================================

Callers 1

EditSetNewEncodingFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected