The send logic updated to support separate shortcuts for composition and decomposition

This commit is contained in:
Simon Rozman 2016-02-08 15:31:51 +01:00
parent 3f94c919ba
commit 80ad8f50b3
3 changed files with 112 additions and 39 deletions

View File

@ -22,12 +22,6 @@
#include "zrcolagui.h" #include "zrcolagui.h"
///
/// Global hotkey message identifiers
///
#define wxZRColaHKID_INVOKE 0
/// ///
/// ZRCola composer panel /// ZRCola composer panel
/// ///

View File

@ -25,15 +25,19 @@
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
wxBEGIN_EVENT_TABLE(wxZRColaFrame, wxZRColaFrameBase) wxBEGIN_EVENT_TABLE(wxZRColaFrame, wxZRColaFrameBase)
EVT_UPDATE_UI(wxZRColaFrame::wxID_SEND_COMPOSED, wxZRColaFrame::OnSendComposedUpdate) EVT_UPDATE_UI_RANGE(wxZRColaFrame::wxID_SEND, wxZRColaFrame::wxID_SEND_DECOMPOSED, wxZRColaFrame::OnSendUpdate)
EVT_MENU (wxZRColaFrame::wxID_SEND_COMPOSED, wxZRColaFrame::OnSendComposed )
EVT_MENU (wxZRColaFrame::wxID_SEND_ABORT , wxZRColaFrame::OnSendAbort ) EVT_MENU(wxZRColaFrame::wxID_SEND , wxZRColaFrame::OnSend )
EVT_MENU ( wxID_ABOUT , wxZRColaFrame::OnAbout ) EVT_MENU(wxZRColaFrame::wxID_SEND_COMPOSED , wxZRColaFrame::OnSendComposed )
EVT_MENU(wxZRColaFrame::wxID_SEND_DECOMPOSED, wxZRColaFrame::OnSendDecomposed)
EVT_MENU(wxZRColaFrame::wxID_SEND_ABORT , wxZRColaFrame::OnSendAbort )
EVT_MENU( wxID_ABOUT , wxZRColaFrame::OnAbout )
wxEND_EVENT_TABLE() wxEND_EVENT_TABLE()
wxZRColaFrame::wxZRColaFrame() : wxZRColaFrame::wxZRColaFrame() :
m_hWndSource(NULL), m_hWndSource(NULL),
m_hotkey(-1),
wxZRColaFrameBase(NULL) wxZRColaFrameBase(NULL)
{ {
// Load main window icons. // Load main window icons.
@ -50,13 +54,15 @@ wxZRColaFrame::wxZRColaFrame() :
m_panel = new wxZRColaComposerPanel(this); m_panel = new wxZRColaComposerPanel(this);
// Register global hotkey(s). // Register global hotkey(s).
if (!RegisterHotKey(wxZRColaHKID_INVOKE, MOD_ALT | MOD_CONTROL, 'Z')) if (!RegisterHotKey(wxZRColaHKID_INVOKE_COMPOSE, MOD_ALT | MOD_CONTROL, 'Z'))
wxMessageBox(_("ZRCola keyboard shortcut Ctrl+Alt+Z could not be registered. Some functionality will not be available."), _("Warning"), wxOK | wxICON_WARNING); wxMessageBox(_("ZRCola keyboard shortcut Ctrl+Alt+Z could not be registered. Some functionality will not be available."), _("Warning"), wxOK | wxICON_WARNING);
if (!RegisterHotKey(wxZRColaHKID_INVOKE_DECOMPOSE, MOD_ALT | MOD_CONTROL | MOD_SHIFT, 'Z'))
wxMessageBox(_("ZRCola keyboard shortcut Ctrl+Alt+Shift+Z could not be registered. Some functionality will not be available."), _("Warning"), wxOK | wxICON_WARNING);
// Register frame specific hotkey(s). // Register frame specific hotkey(s).
{ {
wxAcceleratorEntry entries[2]; wxAcceleratorEntry entries[2];
entries[0].Set(wxACCEL_NORMAL, WXK_RETURN, wxID_SEND_COMPOSED); entries[0].Set(wxACCEL_NORMAL, WXK_RETURN, wxID_SEND);
entries[1].Set(wxACCEL_NORMAL, WXK_ESCAPE, wxID_SEND_ABORT); entries[1].Set(wxACCEL_NORMAL, WXK_ESCAPE, wxID_SEND_ABORT);
SetAcceleratorTable(wxAcceleratorTable(_countof(entries), entries)); SetAcceleratorTable(wxAcceleratorTable(_countof(entries), entries));
} }
@ -66,43 +72,93 @@ wxZRColaFrame::wxZRColaFrame() :
wxZRColaFrame::~wxZRColaFrame() wxZRColaFrame::~wxZRColaFrame()
{ {
// Unregister global hotkey(s). // Unregister global hotkey(s).
UnregisterHotKey(wxZRColaHKID_INVOKE); UnregisterHotKey(wxZRColaHKID_INVOKE_DECOMPOSE);
UnregisterHotKey(wxZRColaHKID_INVOKE_COMPOSE);
} }
void wxZRColaFrame::OnSendComposedUpdate(wxUpdateUIEvent& event) void wxZRColaFrame::OnSendUpdate(wxUpdateUIEvent& event)
{ {
event.Enable(m_hWndSource ? true : false); event.Enable(m_hWndSource ? true : false);
} }
void wxZRColaFrame::OnSend(wxCommandEvent& event)
{
switch (m_hotkey) {
case wxZRColaHKID_INVOKE_COMPOSE : wxZRColaFrame::OnSendComposed (event); break;
case wxZRColaHKID_INVOKE_DECOMPOSE: wxZRColaFrame::OnSendDecomposed(event); break;
default : event.Skip();
}
}
void wxZRColaFrame::OnSendComposed(wxCommandEvent& event) void wxZRColaFrame::OnSendComposed(wxCommandEvent& event)
{ {
if (m_hWndSource) { if (m_hWndSource) {
// Get text and its length (in Unicode characters). Prepare the INPUT table. // Get text and its length (in Unicode characters). Prepare the INPUT table.
wxString text = m_panel->m_composed->GetValue(); wxString text = m_panel->m_composed->GetValue();
std::vector<INPUT>::size_type i = 0, n = text.length(); std::vector<INPUT>::size_type n = text.length();
wxString::const_iterator i_text = text.begin(); if (n) {
std::vector<INPUT> input(n); wxString::const_iterator i_text = text.begin();
for (; i < n; i++, i_text++) { std::vector<INPUT> input(n);
INPUT &inp = input[i]; for (std::vector<INPUT>::size_type i = 0; i < n; i++, i_text++) {
inp.type = INPUT_KEYBOARD; INPUT &inp = input[i];
inp.ki.wVk = 0; inp.type = INPUT_KEYBOARD;
inp.ki.wScan = *i_text; inp.ki.wVk = 0;
inp.ki.dwFlags = KEYEVENTF_UNICODE; inp.ki.wScan = *i_text;
inp.ki.time = 0; inp.ki.dwFlags = KEYEVENTF_UNICODE;
inp.ki.dwExtraInfo = 0; inp.ki.time = 0;
inp.ki.dwExtraInfo = 0;
}
// Return focus to the source window and send the input.
::SetActiveWindow(m_hWndSource);
::SetForegroundWindow(m_hWndSource);
::SendInput(n, input.data(), sizeof(INPUT));
m_hWndSource = NULL;
m_hotkey = -1;
// Select all input in composer and decomposed to prepare for the overwrite next time.
m_panel->m_decomposed->SelectAll();
m_panel->m_composed->SelectAll();
} }
}
// Return focus to the source window and send the input. event.Skip();
::SetActiveWindow(m_hWndSource); }
::SetForegroundWindow(m_hWndSource);
::SendInput(n, &input[0], sizeof(INPUT));
m_hWndSource = NULL;
// Select all input in composer to prepare for the overwrite next time.
m_panel->m_decomposed->SelectAll(); void wxZRColaFrame::OnSendDecomposed(wxCommandEvent& event)
m_panel->m_composed->SelectAll(); {
if (m_hWndSource) {
// Get text and its length (in Unicode characters). Prepare the INPUT table.
wxString text = m_panel->m_decomposed->GetValue();
std::vector<INPUT>::size_type n = text.length();
if (n) {
wxString::const_iterator i_text = text.begin();
std::vector<INPUT> input(n);
for (std::vector<INPUT>::size_type i = 0; i < n; i++, i_text++) {
INPUT &inp = input[i];
inp.type = INPUT_KEYBOARD;
inp.ki.wVk = 0;
inp.ki.wScan = *i_text;
inp.ki.dwFlags = KEYEVENTF_UNICODE;
inp.ki.time = 0;
inp.ki.dwExtraInfo = 0;
}
// Return focus to the source window and send the input.
::SetActiveWindow(m_hWndSource);
::SetForegroundWindow(m_hWndSource);
::SendInput(n, input.data(), sizeof(INPUT));
m_hWndSource = NULL;
m_hotkey = -1;
// Select all input in composer and decomposed to prepare for the overwrite next time.
m_panel->m_decomposed->SelectAll();
m_panel->m_composed->SelectAll();
}
} }
event.Skip(); event.Skip();
@ -116,6 +172,7 @@ void wxZRColaFrame::OnSendAbort(wxCommandEvent& event)
::SetActiveWindow(m_hWndSource); ::SetActiveWindow(m_hWndSource);
::SetForegroundWindow(m_hWndSource); ::SetForegroundWindow(m_hWndSource);
m_hWndSource = NULL; m_hWndSource = NULL;
m_hotkey = -1;
// Select all input in composer to prepare for the overwrite next time. // Select all input in composer to prepare for the overwrite next time.
m_panel->m_decomposed->SelectAll(); m_panel->m_decomposed->SelectAll();
@ -134,11 +191,26 @@ void wxZRColaFrame::OnAbout(wxCommandEvent& event)
WXLRESULT wxZRColaFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) WXLRESULT wxZRColaFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
{ {
if (message == WM_HOTKEY && wParam == wxZRColaHKID_INVOKE) { if (message == WM_HOTKEY) {
// ZRCola hotkey was pressed. Remember the source window and focus ours. // ZRCola hotkey was pressed. Remember the source window and focus ours.
m_hWndSource = ::GetForegroundWindow(); WXHWND hWndSource = ::GetForegroundWindow();
switch (wParam) {
case wxZRColaHKID_INVOKE_COMPOSE : m_panel->m_decomposed->SetFocus(); break;
case wxZRColaHKID_INVOKE_DECOMPOSE: m_panel->m_composed ->SetFocus(); break;
default:
wxFAIL_MSG(wxT("not our registered shortcut"));
return wxZRColaFrameBase::MSWWindowProc(message, wParam, lParam);
}
if (hWndSource == m_hWnd) {
// This is our window user pressed the hotkey (again).
return wxZRColaFrameBase::MSWWindowProc(message, wParam, lParam);
}
m_hWndSource = hWndSource;
m_hotkey = wParam;
m_panel->m_decomposed->SetFocus();
//if (m_state == wxABS_FLOAT) { //if (m_state == wxABS_FLOAT) {
if (IsIconized()) { if (IsIconized()) {
::SendMessage(m_hWnd, WM_SYSCOMMAND, SC_RESTORE, 0); ::SendMessage(m_hWnd, WM_SYSCOMMAND, SC_RESTORE, 0);

View File

@ -22,10 +22,12 @@
#include "zrcolagui.h" #include "zrcolagui.h"
#include "zrcolacomppnl.h" #include "zrcolacomppnl.h"
/// ///
/// Global hotkey message identifiers /// Global hotkey message identifiers
/// ///
#define wxZRColaHKID_INVOKE 0 #define wxZRColaHKID_INVOKE_COMPOSE 0
#define wxZRColaHKID_INVOKE_DECOMPOSE 1
/// ///
@ -35,7 +37,9 @@ class wxZRColaFrame : public wxZRColaFrameBase
{ {
protected: protected:
enum { enum {
wxID_SEND_COMPOSED = wxID_HIGHEST, wxID_SEND = wxID_HIGHEST,
wxID_SEND_COMPOSED,
wxID_SEND_DECOMPOSED,
wxID_SEND_ABORT, wxID_SEND_ABORT,
}; };
@ -44,8 +48,10 @@ public:
virtual ~wxZRColaFrame(); virtual ~wxZRColaFrame();
protected: protected:
void OnSendComposedUpdate(wxUpdateUIEvent& event); void OnSendUpdate(wxUpdateUIEvent& event);
void OnSend(wxCommandEvent& event);
void OnSendComposed(wxCommandEvent& event); void OnSendComposed(wxCommandEvent& event);
void OnSendDecomposed(wxCommandEvent& event);
void OnSendAbort(wxCommandEvent& event); void OnSendAbort(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event); void OnAbout(wxCommandEvent& event);
wxDECLARE_EVENT_TABLE(); wxDECLARE_EVENT_TABLE();
@ -55,5 +61,6 @@ protected:
protected: protected:
WXHWND m_hWndSource; ///< handle of the active window, when the ZRCola hotkey was pressed WXHWND m_hWndSource; ///< handle of the active window, when the ZRCola hotkey was pressed
int m_hotkey; ///< hotkey ID that was pressed
wxZRColaComposerPanel *m_panel; ///< composer panel wxZRColaComposerPanel *m_panel; ///< composer panel
}; };