Revisão | 28943 (tree) |
---|---|
Hora | 2020-06-26 04:23:15 |
Autor | stefankueng |
check for all keys: only select text if focus changed due to user interaction.
@@ -436,10 +436,24 @@ | ||
436 | 436 | |
437 | 437 | void CFilterEdit::OnEnSetfocus() |
438 | 438 | { |
439 | - if ((GetKeyState(VK_LBUTTON)&0x8000) || | |
440 | - (GetKeyState(VK_MBUTTON) & 0x8000) || | |
441 | - (GetKeyState(VK_RBUTTON) & 0x8000) || | |
442 | - (GetKeyState(VK_TAB) & 0x8000)) | |
439 | + // we don't want to select the entered text | |
440 | + // if the focus is set programmatically, because | |
441 | + // we set the focus back to the filter control | |
442 | + // after the filter-timer runs out and we apply | |
443 | + // the filter: if the user is slow to type, that | |
444 | + // could happen *while* typing and we must not | |
445 | + // select the partly entered word. | |
446 | + // | |
447 | + // so we check whether there's any key pressed | |
448 | + // that might be part of a accelerator/shortcut, | |
449 | + // and also if any mouse pointer is pressed: | |
450 | + // that would mean a focus change due to specific | |
451 | + // user interaction and we then *can* select the | |
452 | + // entered text. | |
453 | + bool keyPressed = false; | |
454 | + for (int k = 0x00; !keyPressed && (k <= 0xFF); ++k) | |
455 | + keyPressed |= ((GetKeyState(k) & 0x8000) != 0); | |
456 | + if (keyPressed) | |
443 | 457 | SetSel(0, -1); |
444 | 458 | InvalidateRect(NULL); |
445 | 459 | } |