============================================================================= EditGetExcerpt()
| 4209 | // EditGetExcerpt() |
| 4210 | // |
| 4211 | void EditGetExcerpt ( HWND hwnd, LPWSTR lpszExcerpt, DWORD cchExcerpt ) |
| 4212 | { |
| 4213 | WCHAR tch[256] = L""; |
| 4214 | WCHAR *p; |
| 4215 | DWORD cch = 0; |
| 4216 | UINT cpEdit; |
| 4217 | struct TextRange tr; |
| 4218 | char *pszText; |
| 4219 | LPWSTR pszTextW; |
| 4220 | int iCurPos = ( int ) SendMessage ( hwnd, SCI_GETCURRENTPOS, 0, 0 ); |
| 4221 | int iAnchorPos = ( int ) SendMessage ( hwnd, SCI_GETANCHOR, 0, 0 ); |
| 4222 | if ( iCurPos == iAnchorPos || SC_SEL_RECTANGLE == SendMessage ( hwnd, SCI_GETSELECTIONMODE, 0, 0 ) ) { |
| 4223 | lstrcpy ( lpszExcerpt, L"" ); |
| 4224 | return; |
| 4225 | } |
| 4226 | /*if (iCurPos != iAnchorPos && SC_SEL_RECTANGLE != SendMessage(hwnd,SCI_GETSELECTIONMODE,0,0)) {*/ |
| 4227 | tr.chrg.cpMin = ( int ) SendMessage ( hwnd, SCI_GETSELECTIONSTART, 0, 0 ); |
| 4228 | tr.chrg.cpMax = min ( ( int ) SendMessage ( hwnd, SCI_GETSELECTIONEND, 0, 0 ), ( LONG ) ( tr.chrg.cpMin + COUNTOF ( tch ) ) ); |
| 4229 | /*} |
| 4230 | else { |
| 4231 | |
| 4232 | int iLine = SendMessage(hwnd,SCI_LINEFROMPOSITION,(WPARAM)iCurPos,0); |
| 4233 | tr.chrg.cpMin = SendMessage(hwnd,SCI_POSITIONFROMLINE,(WPARAM)iLine,0); |
| 4234 | tr.chrg.cpMax = min(SendMessage(hwnd,SCI_GETLINEENDPOSITION,(WPARAM)iLine,0),(LONG)(tr.chrg.cpMin + COUNTOF(tch))); |
| 4235 | }*/ |
| 4236 | tr.chrg.cpMax = min ( ( int ) SendMessage ( hwnd, SCI_GETLENGTH, 0, 0 ), tr.chrg.cpMax ); |
| 4237 | pszText = LocalAlloc ( LPTR, ( tr.chrg.cpMax - tr.chrg.cpMin ) + 2 ); |
| 4238 | pszTextW = LocalAlloc ( LPTR, ( ( tr.chrg.cpMax - tr.chrg.cpMin ) * 2 ) + 2 ); |
| 4239 | if ( pszText && pszTextW ) { |
| 4240 | tr.lpstrText = pszText; |
| 4241 | SendMessage ( hwnd, SCI_GETTEXTRANGE, 0, ( LPARAM ) &tr ); |
| 4242 | cpEdit = ( UINT ) SendMessage ( hwnd, SCI_GETCODEPAGE, 0, 0 ); |
| 4243 | MultiByteToWideChar ( cpEdit, 0, pszText, tr.chrg.cpMax - tr.chrg.cpMin, pszTextW, ( int ) GlobalSize ( pszTextW ) / sizeof ( WCHAR ) ); |
| 4244 | for ( p = pszTextW; *p && cch < COUNTOF ( tch ) - 1; p++ ) { |
| 4245 | if ( *p == L'\r' || *p == L'\n' || *p == L'\t' || *p == L' ' ) { |
| 4246 | tch[cch++] = L' '; |
| 4247 | while ( * ( p + 1 ) == L'\r' || * ( p + 1 ) == L'\n' || * ( p + 1 ) == L'\t' || * ( p + 1 ) == L' ' ) { |
| 4248 | p++; |
| 4249 | } |
| 4250 | } else { |
| 4251 | tch[cch++] = *p; |
| 4252 | } |
| 4253 | } |
| 4254 | tch[cch++] = L'\0'; |
| 4255 | StrTrim ( tch, L" " ); |
| 4256 | } |
| 4257 | if ( cch == 1 ) { |
| 4258 | lstrcpy ( tch, L" ... " ); |
| 4259 | } |
| 4260 | if ( cch > cchExcerpt ) { |
| 4261 | tch[cchExcerpt - 2] = L'.'; |
| 4262 | tch[cchExcerpt - 3] = L'.'; |
| 4263 | tch[cchExcerpt - 4] = L'.'; |
| 4264 | } |
| 4265 | StrCpyN ( lpszExcerpt, tch, cchExcerpt ); |
| 4266 | if ( pszText ) { |
| 4267 | LocalFree ( pszText ); |
| 4268 | } |