============================================================================= EditSentenceCase()
| 1596 | // EditSentenceCase() |
| 1597 | // |
| 1598 | void EditSentenceCase ( HWND hwnd ) |
| 1599 | { |
| 1600 | int cchTextW; |
| 1601 | int iCurPos; |
| 1602 | int iAnchorPos; |
| 1603 | UINT cpEdit; |
| 1604 | int i; |
| 1605 | BOOL bNewSentence = TRUE; |
| 1606 | BOOL bChanged = FALSE; |
| 1607 | iCurPos = ( int ) SendMessage ( hwnd, SCI_GETCURRENTPOS, 0, 0 ); |
| 1608 | iAnchorPos = ( int ) SendMessage ( hwnd, SCI_GETANCHOR, 0, 0 ); |
| 1609 | if ( iCurPos != iAnchorPos ) { |
| 1610 | if ( SC_SEL_RECTANGLE != SendMessage ( hwnd, SCI_GETSELECTIONMODE, 0, 0 ) ) { |
| 1611 | int iSelCount = ( int ) SendMessage ( hwnd, SCI_GETSELECTIONEND, 0, 0 ) - |
| 1612 | ( int ) SendMessage ( hwnd, SCI_GETSELECTIONSTART, 0, 0 ); |
| 1613 | char *pszText = GlobalAlloc ( GPTR, ( iSelCount ) + 2 ); |
| 1614 | LPWSTR pszTextW = GlobalAlloc ( GPTR, ( iSelCount * 2 ) + 2 ); |
| 1615 | if ( pszText == NULL || pszTextW == NULL ) { |
| 1616 | GlobalFree ( pszText ); |
| 1617 | GlobalFree ( pszTextW ); |
| 1618 | return; |
| 1619 | } |
| 1620 | SendMessage ( hwnd, SCI_GETSELTEXT, 0, ( LPARAM ) pszText ); |
| 1621 | cpEdit = ( UINT ) SendMessage ( hwnd, SCI_GETCODEPAGE, 0, 0 ); |
| 1622 | cchTextW = MultiByteToWideChar ( cpEdit, 0, pszText, iSelCount, pszTextW, ( int ) GlobalSize ( pszTextW ) / sizeof ( WCHAR ) ); |
| 1623 | for ( i = 0; i < cchTextW; i++ ) { |
| 1624 | if ( StrChr ( L".;!?\r\n", pszTextW[i] ) ) { |
| 1625 | bNewSentence = TRUE; |
| 1626 | } else { |
| 1627 | if ( IsCharAlphaNumericW ( pszTextW[i] ) ) { |
| 1628 | if ( bNewSentence ) { |
| 1629 | if ( IsCharLowerW ( pszTextW[i] ) ) { |
| 1630 | pszTextW[i] = LOWORD ( CharUpperW ( ( LPWSTR ) ( LONG_PTR ) MAKELONG ( pszTextW[i], 0 ) ) ); |
| 1631 | bChanged = TRUE; |
| 1632 | } |
| 1633 | bNewSentence = FALSE; |
| 1634 | } else { |
| 1635 | if ( IsCharUpperW ( pszTextW[i] ) ) { |
| 1636 | pszTextW[i] = LOWORD ( CharLowerW ( ( LPWSTR ) ( LONG_PTR ) MAKELONG ( pszTextW[i], 0 ) ) ); |
| 1637 | bChanged = TRUE; |
| 1638 | } |
| 1639 | } |
| 1640 | } |
| 1641 | } |
| 1642 | } |
| 1643 | if ( bChanged ) { |
| 1644 | WideCharToMultiByte ( cpEdit, 0, pszTextW, cchTextW, pszText, ( int ) GlobalSize ( pszText ), NULL, NULL ); |
| 1645 | SendMessage ( hwnd, SCI_BEGINUNDOACTION, 0, 0 ); |
| 1646 | SendMessage ( hwnd, SCI_CLEAR, 0, 0 ); |
| 1647 | SendMessage ( hwnd, SCI_ADDTEXT, ( WPARAM ) iSelCount, ( LPARAM ) pszText ); |
| 1648 | SendMessage ( hwnd, SCI_SETSEL, ( WPARAM ) iAnchorPos, ( LPARAM ) iCurPos ); |
| 1649 | SendMessage ( hwnd, SCI_ENDUNDOACTION, 0, 0 ); |
| 1650 | } |
| 1651 | GlobalFree ( pszText ); |
| 1652 | GlobalFree ( pszTextW ); |
| 1653 | } else { |
| 1654 | MsgBox ( MBINFO, IDS_SELRECT ); |
| 1655 | } |