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

Function EditInvertCase

src/Edit.c:1464–1511  ·  view source on GitHub ↗

============================================================================= EditInvertCase()

Source from the content-addressed store, hash-verified

1462// EditInvertCase()
1463//
1464void EditInvertCase ( HWND hwnd )
1465{
1466 int cchTextW;
1467 int iCurPos;
1468 int iAnchorPos;
1469 UINT cpEdit;
1470 int i;
1471 BOOL bChanged = FALSE;
1472 iCurPos = ( int ) SendMessage ( hwnd, SCI_GETCURRENTPOS, 0, 0 );
1473 iAnchorPos = ( int ) SendMessage ( hwnd, SCI_GETANCHOR, 0, 0 );
1474 if ( iCurPos != iAnchorPos ) {
1475 if ( SC_SEL_RECTANGLE != SendMessage ( hwnd, SCI_GETSELECTIONMODE, 0, 0 ) ) {
1476 int iSelCount = ( int ) SendMessage ( hwnd, SCI_GETSELECTIONEND, 0, 0 ) -
1477 ( int ) SendMessage ( hwnd, SCI_GETSELECTIONSTART, 0, 0 );
1478 char *pszText = GlobalAlloc ( GPTR, ( iSelCount ) + 2 );
1479 LPWSTR pszTextW = GlobalAlloc ( GPTR, ( iSelCount * 2 ) + 2 );
1480 if ( pszText == NULL || pszTextW == NULL ) {
1481 GlobalFree ( pszText );
1482 GlobalFree ( pszTextW );
1483 return;
1484 }
1485 SendMessage ( hwnd, SCI_GETSELTEXT, 0, ( LPARAM ) pszText );
1486 cpEdit = ( UINT ) SendMessage ( hwnd, SCI_GETCODEPAGE, 0, 0 );
1487 cchTextW = MultiByteToWideChar ( cpEdit, 0, pszText, iSelCount, pszTextW, ( int ) GlobalSize ( pszTextW ) / sizeof ( WCHAR ) );
1488 for ( i = 0; i < cchTextW; i++ ) {
1489 if ( IsCharUpperW ( pszTextW[i] ) ) {
1490 pszTextW[i] = LOWORD ( CharLowerW ( ( LPWSTR ) ( LONG_PTR ) MAKELONG ( pszTextW[i], 0 ) ) );
1491 bChanged = TRUE;
1492 } else if ( IsCharLowerW ( pszTextW[i] ) ) {
1493 pszTextW[i] = LOWORD ( CharUpperW ( ( LPWSTR ) ( LONG_PTR ) MAKELONG ( pszTextW[i], 0 ) ) );
1494 bChanged = TRUE;
1495 }
1496 }
1497 if ( bChanged ) {
1498 WideCharToMultiByte ( cpEdit, 0, pszTextW, cchTextW, pszText, ( int ) GlobalSize ( pszText ), NULL, NULL );
1499 SendMessage ( hwnd, SCI_BEGINUNDOACTION, 0, 0 );
1500 SendMessage ( hwnd, SCI_CLEAR, 0, 0 );
1501 SendMessage ( hwnd, SCI_ADDTEXT, ( WPARAM ) iSelCount, ( LPARAM ) pszText );
1502 SendMessage ( hwnd, SCI_SETSEL, ( WPARAM ) iAnchorPos, ( LPARAM ) iCurPos );
1503 SendMessage ( hwnd, SCI_ENDUNDOACTION, 0, 0 );
1504 }
1505 GlobalFree ( pszText );
1506 GlobalFree ( pszTextW );
1507 } else {
1508 MsgBox ( MBINFO, IDS_SELRECT );
1509 }
1510 }
1511}
1512
1513
1514//=============================================================================

Callers 1

MsgCommandFunction · 0.85

Calls 1

MsgBoxFunction · 0.85

Tested by

no test coverage detected