Skip to content

Commit

Permalink
Merge branch 'feature-issue127' #127
Browse files Browse the repository at this point in the history
* feature-issue127:
  Implemented support for CTRL+A in CInputBox answer text box. #127
  Fixed InputBox.cpp TAB traversal and focus. #127
  * Fixed issue #127: Question Prompt action does not accept answers longer than the visual textbox.
  • Loading branch information
end2endzone committed Nov 29, 2023
2 parents 6df21c7 + 180587e commit ea3e297
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 13 deletions.
5 changes: 5 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Changes for 0.9.0

* Fixed issue #127: Question Prompt action does not accept answers longer than the visual textbox.


Changes for 0.8.0

**NOTE:** The file name of Shellanything's shell extension is now `sa.shellextension.dll`. If you update from a previous version, make sure you unregister the previous shell extension (formally `shellext.dll`).
Expand Down
53 changes: 40 additions & 13 deletions src/core/InputBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ HFONT CreateInputBoxFont()

CInputBox::CInputBox(HWND hParent) :
m_hInstance(NULL),
m_prevEditProc(NULL),
m_hWindowFont(NULL),
m_hIcon(NULL),
m_hParent(NULL),
Expand Down Expand Up @@ -288,7 +289,7 @@ inline CInputBox* GetInputBoxInstance(HWND hWnd)

LRESULT CALLBACK CInputBox::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
//Get the inputbox saved when WM_CREATE message was processed
//Get the CInputBox instance saved when WM_CREATE message was processed.
CInputBox* pInputBox = GetInputBoxInstance(hWnd);

switch (uMsg)
Expand Down Expand Up @@ -334,7 +335,7 @@ LRESULT CALLBACK CInputBox::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM
// textbox Answer
HWND hTextBoxAnswer = CreateWindowEx(/*WS_EX_STATICEDGE*/ WS_EX_CLIENTEDGE,
"EDIT", "",
WS_VISIBLE | WS_CHILD /*| WS_TABSTOP | ES_AUTOHSCROLL*/,
WS_VISIBLE | WS_CHILD | WS_TABSTOP | ES_LEFT | ES_AUTOHSCROLL | ES_NOHIDESEL,
DEFAULT_HORIZONTAL_PADDING, client_height - DEFAULT_VERTICAL_PADDING - DEFAULT_TEXTBOX_HEIGHT, client_width - 2 * DEFAULT_HORIZONTAL_PADDING, DEFAULT_TEXTBOX_HEIGHT,
hWnd,
NULL,
Expand All @@ -343,6 +344,12 @@ LRESULT CALLBACK CInputBox::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM
pInputBox->SetCtrl(CInputBox::TEXTBOX_ANSWER, hTextBoxAnswer);
SendMessage(hTextBoxAnswer, WM_SETFONT, (WPARAM)hWindowFont, 0);

// Set our custom message handler function
if (!(pInputBox->m_prevEditProc = (WNDPROC)SetWindowLongPtrW(hTextBoxAnswer, GWLP_WNDPROC, (LONG_PTR)(&EditProc))))
{
return ERROR_NOT_SUPPORTED;
}

//default value for anwser
std::wstring default_text = pInputBox->GetTextUnicode();
if (!default_text.empty())
Expand Down Expand Up @@ -488,12 +495,37 @@ LRESULT CALLBACK CInputBox::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM
return (LRESULT)null_brush;
}
break;
case WM_SETFOCUS:
{
HWND focused_ctrl = GetFocus();
HWND thisWindow = pInputBox->GetWindow();

// When the window gets the focus, set the focus on the textbox answer.
HWND hTextBoxAnswer = pInputBox->GetCtrl(TEXTBOX_ANSWER);
SetFocus(hTextBoxAnswer);
}
break;
default:
return DefWindowProcW(hWnd, uMsg, wParam, lParam);
}
return 0;
}

LRESULT CALLBACK CInputBox::EditProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
//Get the CInputBox instance saved when WM_CREATE message was processed.
HWND hMainWnd = GetParent(hWnd);
CInputBox* pInputBox = GetInputBoxInstance(hMainWnd);

if (uMsg == WM_CHAR && wParam == 1) // CTRL+A
{
SendMessage(hWnd, EM_SETSEL, 0, -1);
return 1;
}

return CallWindowProc(pInputBox->m_prevEditProc, hWnd, uMsg, wParam, lParam);
}

bool CInputBox::DoModal(const std::string& caption, const std::string& prompt)
{
std::wstring caption_unicode = ra::unicode::AnsiToUnicode(caption);
Expand Down Expand Up @@ -594,19 +626,14 @@ bool CInputBox::DoModal(const std::wstring& caption, const std::wstring& prompt)
result = true; //OK button
}
break;
case VK_TAB:
{
//Jump to the next focusable element
HWND focused_ctrl = GetFocus();
if (focused_ctrl == m_hTextBoxAnswer) SetFocus(m_hButtonOK);
if (focused_ctrl == m_hButtonOK) SetFocus(m_hButtonCancel);
if (focused_ctrl == m_hButtonCancel) SetFocus(m_hTextBoxAnswer);
}
break;
};
}
TranslateMessage(&msg);
DispatchMessageW(&msg);

if (!IsDialogMessage(m_hInputBox, &msg))
{
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
}

return result;
Expand Down
2 changes: 2 additions & 0 deletions src/core/InputBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,11 @@ class SHELLANYTHING_EXPORT CInputBox

private:
static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
static LRESULT CALLBACK EditProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
BOOL UpdateWindowStyle(HWND hWnd, LONG new_styles);

HINSTANCE m_hInstance;
WNDPROC m_prevEditProc; // previous edit control message process function
HFONT m_hWindowFont; //main font
HFONT m_hPromptFont;
HICON m_hIcon;
Expand Down

0 comments on commit ea3e297

Please sign in to comment.