// selects all text in an edit box if it's selected either // through a keyboard shortcut or a non-selecting mouse click // (or responds to Ctrl+Backspace as nowadays expected) bool ExtendedEditWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { UNUSED(lParam); static bool delayFocus = false; switch (message) { case WM_LBUTTONDOWN: delayFocus = GetFocus() != hwnd; return true; case WM_LBUTTONUP: if (delayFocus) { DWORD sel = Edit_GetSel(hwnd); if (LOWORD(sel) == HIWORD(sel)) PostMessage(hwnd, UWM_DELAYED_SET_FOCUS, 0, 0); delayFocus = false; } return true; case WM_KILLFOCUS: return false; // for easier debugging (make setting a breakpoint possible) case WM_SETFOCUS: if (!delayFocus) PostMessage(hwnd, UWM_DELAYED_SET_FOCUS, 0, 0); return true; case UWM_DELAYED_SET_FOCUS: Edit_SelectAll(hwnd); return true; case WM_KEYDOWN: if (VK_BACK != wParam || !IsCtrlPressed() || IsShiftPressed()) return false; PostMessage(hwnd, UWM_DELAYED_CTRL_BACK, 0, 0); return true; case UWM_DELAYED_CTRL_BACK: { ScopedMem<WCHAR> text(win::GetText(hwnd)); int selStart = LOWORD(Edit_GetSel(hwnd)), selEnd = selStart; // remove the rectangle produced by Ctrl+Backspace if (selStart > 0 && text[selStart - 1] == '\x7F') { memmove(text + selStart - 1, text + selStart, str::Len(text + selStart - 1) * sizeof(WCHAR)); win::SetText(hwnd, text); selStart = selEnd = selStart - 1; } // remove the previous word (and any spacing after it) for (; selStart > 0 && str::IsWs(text[selStart - 1]); selStart--); for (; selStart > 0 && !str::IsWs(text[selStart - 1]); selStart--); Edit_SetSel(hwnd, selStart, selEnd); SendMessage(hwnd, WM_CLEAR, 0, 0); } return true; default: return false; } }
static INT_PTR CALLBACK Dialog_GoToPage_Proc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { HWND editPageNo; Dialog_GoToPage_Data * data; //[ ACCESSKEY_GROUP GoTo Page Dialog if (WM_INITDIALOG == msg) { data = (Dialog_GoToPage_Data*)lParam; assert(data); SetWindowLongPtr(hDlg, GWLP_USERDATA, (LONG_PTR)data); win::SetText(hDlg, _TR("Go to page")); editPageNo = GetDlgItem(hDlg, IDC_GOTO_PAGE_EDIT); if (!data->onlyNumeric) SetWindowLong(editPageNo, GWL_STYLE, GetWindowLong(editPageNo, GWL_STYLE) & ~ES_NUMBER); assert(data->currPageLabel); SetDlgItemText(hDlg, IDC_GOTO_PAGE_EDIT, data->currPageLabel); ScopedMem<WCHAR> totalCount(str::Format(_TR("(of %d)"), data->pageCount)); SetDlgItemText(hDlg, IDC_GOTO_PAGE_LABEL_OF, totalCount); Edit_SelectAll(editPageNo); SetDlgItemText(hDlg, IDC_STATIC, _TR("&Go to page:")); SetDlgItemText(hDlg, IDOK, _TR("Go to page")); SetDlgItemText(hDlg, IDCANCEL, _TR("Cancel")); CenterDialog(hDlg); SetFocus(editPageNo); return FALSE; } //] ACCESSKEY_GROUP GoTo Page Dialog switch (msg) { case WM_COMMAND: switch (LOWORD(wParam)) { case IDOK: data = (Dialog_GoToPage_Data*)GetWindowLongPtr(hDlg, GWLP_USERDATA); assert(data); editPageNo = GetDlgItem(hDlg, IDC_GOTO_PAGE_EDIT); data->newPageLabel = win::GetText(editPageNo); EndDialog(hDlg, IDOK); return TRUE; case IDCANCEL: EndDialog(hDlg, IDCANCEL); return TRUE; } break; } return FALSE; }
static INT_PTR CALLBACK Dialog_Find_Proc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { Dialog_Find_Data * data; switch (msg) { case WM_INITDIALOG: //[ ACCESSKEY_GROUP Find Dialog data = (Dialog_Find_Data*)lParam; assert(data); SetWindowLongPtr(hDlg, GWLP_USERDATA, (LONG_PTR)data); win::SetText(hDlg, _TR("Find")); SetDlgItemText(hDlg, IDC_STATIC, _TR("&Find what:")); SetDlgItemText(hDlg, IDC_MATCH_CASE, _TR("&Match case")); SetDlgItemText(hDlg, IDC_FIND_NEXT_HINT, _TR("Hint: Use the F3 key for finding again")); SetDlgItemText(hDlg, IDOK, _TR("Find")); SetDlgItemText(hDlg, IDCANCEL, _TR("Cancel")); if (data->searchTerm) SetDlgItemText(hDlg, IDC_FIND_EDIT, data->searchTerm); CheckDlgButton(hDlg, IDC_MATCH_CASE, data->matchCase ? BST_CHECKED : BST_UNCHECKED); data->editWndProc = (WNDPROC)SetWindowLongPtr(GetDlgItem(hDlg, IDC_FIND_EDIT), GWLP_WNDPROC, (LONG_PTR)Dialog_Find_Edit_Proc); Edit_SelectAll(GetDlgItem(hDlg, IDC_FIND_EDIT)); CenterDialog(hDlg); SetFocus(GetDlgItem(hDlg, IDC_FIND_EDIT)); return FALSE; //] ACCESSKEY_GROUP Find Dialog case WM_COMMAND: switch (LOWORD(wParam)) { case IDOK: data = (Dialog_Find_Data*)GetWindowLongPtr(hDlg, GWLP_USERDATA); assert(data); data->searchTerm = win::GetText(GetDlgItem(hDlg, IDC_FIND_EDIT)); data->matchCase = BST_CHECKED == IsDlgButtonChecked(hDlg, IDC_MATCH_CASE); EndDialog(hDlg, IDOK); return TRUE; case IDCANCEL: EndDialog(hDlg, IDCANCEL); return TRUE; } break; } return FALSE; }
static INT_PTR CALLBACK Dialog_AddFav_Proc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { if (WM_INITDIALOG == msg) { Dialog_AddFav_Data *data = (Dialog_AddFav_Data *)lParam; assert(data); SetWindowLongPtr(hDlg, GWLP_USERDATA, (LONG_PTR)data); win::SetText(hDlg, _TR("Add Favorite")); ScopedMem<WCHAR> s(str::Format(_TR("Add page %s to favorites with (optional) name:"), data->pageNo)); SetDlgItemText(hDlg, IDC_ADD_PAGE_STATIC, s); SetDlgItemText(hDlg, IDOK, _TR("OK")); SetDlgItemText(hDlg, IDCANCEL, _TR("Cancel")); if (data->favName) { SetDlgItemText(hDlg, IDC_FAV_NAME_EDIT, data->favName); Edit_SelectAll(GetDlgItem(hDlg, IDC_FAV_NAME_EDIT)); } CenterDialog(hDlg); SetFocus(GetDlgItem(hDlg, IDC_FAV_NAME_EDIT)); return FALSE; } if (WM_COMMAND == msg) { Dialog_AddFav_Data *data = (Dialog_AddFav_Data *)GetWindowLongPtr(hDlg, GWLP_USERDATA); assert(data); WORD cmd = LOWORD(wParam); if (IDOK == cmd) { ScopedMem<WCHAR> name(win::GetText(GetDlgItem(hDlg, IDC_FAV_NAME_EDIT))); str::TrimWS(name); if (!str::IsEmpty(name.Get())) data->favName = name.StealData(); else data->favName = NULL; EndDialog(hDlg, IDOK); return TRUE; } else if (IDCANCEL == cmd) { EndDialog(hDlg, IDCANCEL); return TRUE; } } return FALSE; }