The send logic updated to support separate shortcuts for composition and decomposition
This commit is contained in:
parent
3f94c919ba
commit
80ad8f50b3
@ -22,12 +22,6 @@
|
||||
#include "zrcolagui.h"
|
||||
|
||||
|
||||
///
|
||||
/// Global hotkey message identifiers
|
||||
///
|
||||
#define wxZRColaHKID_INVOKE 0
|
||||
|
||||
|
||||
///
|
||||
/// ZRCola composer panel
|
||||
///
|
||||
|
@ -25,8 +25,11 @@
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
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 , wxZRColaFrame::OnSend )
|
||||
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()
|
||||
@ -34,6 +37,7 @@ wxEND_EVENT_TABLE()
|
||||
|
||||
wxZRColaFrame::wxZRColaFrame() :
|
||||
m_hWndSource(NULL),
|
||||
m_hotkey(-1),
|
||||
wxZRColaFrameBase(NULL)
|
||||
{
|
||||
// Load main window icons.
|
||||
@ -50,13 +54,15 @@ wxZRColaFrame::wxZRColaFrame() :
|
||||
m_panel = new wxZRColaComposerPanel(this);
|
||||
|
||||
// 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);
|
||||
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).
|
||||
{
|
||||
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);
|
||||
SetAcceleratorTable(wxAcceleratorTable(_countof(entries), entries));
|
||||
}
|
||||
@ -66,25 +72,37 @@ wxZRColaFrame::wxZRColaFrame() :
|
||||
wxZRColaFrame::~wxZRColaFrame()
|
||||
{
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
if (m_hWndSource) {
|
||||
// Get text and its length (in Unicode characters). Prepare the INPUT table.
|
||||
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();
|
||||
if (n) {
|
||||
wxString::const_iterator i_text = text.begin();
|
||||
std::vector<INPUT> input(n);
|
||||
for (; i < n; i++, i_text++) {
|
||||
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;
|
||||
@ -97,13 +115,51 @@ void wxZRColaFrame::OnSendComposed(wxCommandEvent& event)
|
||||
// Return focus to the source window and send the input.
|
||||
::SetActiveWindow(m_hWndSource);
|
||||
::SetForegroundWindow(m_hWndSource);
|
||||
::SendInput(n, &input[0], sizeof(INPUT));
|
||||
::SendInput(n, input.data(), sizeof(INPUT));
|
||||
m_hWndSource = NULL;
|
||||
m_hotkey = -1;
|
||||
|
||||
// Select all input in composer to prepare for the overwrite next time.
|
||||
// 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();
|
||||
}
|
||||
|
||||
|
||||
void wxZRColaFrame::OnSendDecomposed(wxCommandEvent& event)
|
||||
{
|
||||
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();
|
||||
}
|
||||
@ -116,6 +172,7 @@ void wxZRColaFrame::OnSendAbort(wxCommandEvent& event)
|
||||
::SetActiveWindow(m_hWndSource);
|
||||
::SetForegroundWindow(m_hWndSource);
|
||||
m_hWndSource = NULL;
|
||||
m_hotkey = -1;
|
||||
|
||||
// Select all input in composer to prepare for the overwrite next time.
|
||||
m_panel->m_decomposed->SelectAll();
|
||||
@ -134,11 +191,26 @@ void wxZRColaFrame::OnAbout(wxCommandEvent& event)
|
||||
|
||||
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.
|
||||
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 (IsIconized()) {
|
||||
::SendMessage(m_hWnd, WM_SYSCOMMAND, SC_RESTORE, 0);
|
||||
|
@ -22,10 +22,12 @@
|
||||
#include "zrcolagui.h"
|
||||
#include "zrcolacomppnl.h"
|
||||
|
||||
|
||||
///
|
||||
/// 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:
|
||||
enum {
|
||||
wxID_SEND_COMPOSED = wxID_HIGHEST,
|
||||
wxID_SEND = wxID_HIGHEST,
|
||||
wxID_SEND_COMPOSED,
|
||||
wxID_SEND_DECOMPOSED,
|
||||
wxID_SEND_ABORT,
|
||||
};
|
||||
|
||||
@ -44,8 +48,10 @@ public:
|
||||
virtual ~wxZRColaFrame();
|
||||
|
||||
protected:
|
||||
void OnSendComposedUpdate(wxUpdateUIEvent& event);
|
||||
void OnSendUpdate(wxUpdateUIEvent& event);
|
||||
void OnSend(wxCommandEvent& event);
|
||||
void OnSendComposed(wxCommandEvent& event);
|
||||
void OnSendDecomposed(wxCommandEvent& event);
|
||||
void OnSendAbort(wxCommandEvent& event);
|
||||
void OnAbout(wxCommandEvent& event);
|
||||
wxDECLARE_EVENT_TABLE();
|
||||
@ -55,5 +61,6 @@ protected:
|
||||
|
||||
protected:
|
||||
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
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user