1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-15 00:24:19 +00:00

Win32 FileChooser: Fix truncated initial file text

This commit is contained in:
Oli 2023-01-03 13:50:55 +00:00 committed by Oliver James
parent 100fec3830
commit bc26d5cc87

View file

@ -245,10 +245,42 @@ private:
JUCE_COMRESULT OnFolderChanging (IFileDialog* d, IShellItem*) override { return updateHwnd (d); }
JUCE_COMRESULT OnFileOk (IFileDialog* d) override { return updateHwnd (d); }
JUCE_COMRESULT OnFolderChange (IFileDialog* d) override { return updateHwnd (d); }
JUCE_COMRESULT OnSelectionChange (IFileDialog* d) override { return updateHwnd (d); }
JUCE_COMRESULT OnSelectionChange (IFileDialog* d) override { focusWorkaround(); return updateHwnd (d); }
JUCE_COMRESULT OnShareViolation (IFileDialog* d, IShellItem*, FDE_SHAREVIOLATION_RESPONSE*) override { return updateHwnd (d); }
JUCE_COMRESULT OnOverwrite (IFileDialog* d, IShellItem*, FDE_OVERWRITE_RESPONSE*) override { return updateHwnd (d); }
/** Workaround for a bug in Vista+, OpenFileDialog will truncate the initialFile text.
Moving the caret along the full length of the text and back will reveal the full string.
*/
void focusWorkaround()
{
if (! defaultFileNameTextCaretMoved)
{
auto makeKeyInput = [] (WORD vk, bool pressed)
{
INPUT i;
ZeroMemory (&i, sizeof (INPUT));
i.type = INPUT_KEYBOARD;
i.ki.wVk = vk;
i.ki.dwFlags = pressed ? 0 : KEYEVENTF_KEYUP;
return i;
};
INPUT inputs[] = {
makeKeyInput (VK_HOME, true),
makeKeyInput (VK_HOME, false),
makeKeyInput (VK_END, true),
makeKeyInput (VK_END, false),
};
SendInput ((UINT) std::size (inputs), inputs, sizeof (INPUT));
defaultFileNameTextCaretMoved = true;
}
}
JUCE_COMRESULT updateHwnd (IFileDialog* d)
{
HWND hwnd = nullptr;
@ -266,6 +298,7 @@ private:
return S_OK;
}
bool defaultFileNameTextCaretMoved = false;
Win32NativeFileChooser& owner;
};