Work continues...
Global hotkey CTRL+ALT+Z registration added Preview control is now an edit box too (a read-only one for that matter) Send feature implementation
This commit is contained in:
parent
9fb5744891
commit
e6104534d8
@ -27,3 +27,5 @@
|
||||
#include <wx/msgdlg.h>
|
||||
#include <wx/sizer.h>
|
||||
#include <wxex/common.h>
|
||||
|
||||
#include <vector>
|
||||
|
@ -25,11 +25,16 @@
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
wxBEGIN_EVENT_TABLE(wxZRColaFrame, wxAppBarFrame)
|
||||
EVT_MENU(wxID_ABOUT, wxZRColaFrame::OnAbout)
|
||||
EVT_TEXT (wxZRColaFrame::wxID_COMPOSER, wxZRColaFrame::OnCompose )
|
||||
EVT_UPDATE_UI(wxZRColaFrame::wxID_SEND , wxZRColaFrame::OnSendUpdate)
|
||||
EVT_MENU (wxZRColaFrame::wxID_SEND , wxZRColaFrame::OnSend )
|
||||
EVT_MENU ( wxID_ABOUT , wxZRColaFrame::OnAbout )
|
||||
wxEND_EVENT_TABLE()
|
||||
|
||||
|
||||
wxZRColaFrame::wxZRColaFrame() : wxAppBarFrame()
|
||||
wxZRColaFrame::wxZRColaFrame() :
|
||||
m_hWndSource(NULL),
|
||||
wxAppBarFrame()
|
||||
{
|
||||
}
|
||||
|
||||
@ -42,40 +47,134 @@ bool wxZRColaFrame::Create()
|
||||
|
||||
wxFont fontZRCola(20, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, wxT("00 ZRCola"));
|
||||
|
||||
wxCHECK(m_preview.Create(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE), false);
|
||||
m_preview.Wrap(-1);
|
||||
wxCHECK(m_preview.Create(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_CENTRE|wxTE_READONLY), false);
|
||||
m_preview.SetFont(fontZRCola);
|
||||
|
||||
wxCHECK(m_composer.Create(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_CENTRE|wxTE_MULTILINE), false);
|
||||
wxCHECK(m_composer.Create(this, wxID_COMPOSER, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_CENTRE), false);
|
||||
m_composer.SetFont(fontZRCola);
|
||||
|
||||
wxBoxSizer
|
||||
//*boxH = new wxBoxSizer(wxHORIZONTAL),
|
||||
*boxH = new wxBoxSizer(wxHORIZONTAL),
|
||||
*boxV = new wxBoxSizer(wxVERTICAL);
|
||||
|
||||
boxV->Add(&m_preview, 1, wxEXPAND, 5);
|
||||
boxV->Add(&m_composer, 1, wxEXPAND, 5);
|
||||
//boxH->Add(boxV, 1, wxEXPAND, 5);
|
||||
boxH->Add(boxV, 1, wxEXPAND, 5);
|
||||
|
||||
//m_toolBar.Create(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTB_HORIZONTAL);
|
||||
//m_toolBar.AddTool(wxID_ABOUT, _("About"), wxBitmap(wxIcon(wxICON(send.ico))));
|
||||
//m_toolBar.AddTool(wxID_ABOUT, _("About"), wxBitmap(wxIcon(wxICON(send.ico))));
|
||||
//m_toolBar.AddTool(wxID_ABOUT, _("About"), wxBitmap(wxIcon(wxICON(send.ico))));
|
||||
//m_toolBar.AddTool(wxID_ABOUT, _("About"), wxBitmap(wxIcon(wxICON(send.ico))));
|
||||
//m_toolBar.Realize();
|
||||
//Connect(wxID_ABOUT, wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(wxZRColaFrame::OnAbout));
|
||||
m_toolBar.Create(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTB_HORIZONTAL);
|
||||
m_toolBar.AddTool(wxID_SEND, _("Send"), wxBitmap(wxIcon(wxICON(send.ico))));
|
||||
m_toolBar.Realize();
|
||||
|
||||
//boxH->Add(&m_toolBar, 0, wxEXPAND, 5);
|
||||
boxH->Add(&m_toolBar, 0, wxEXPAND, 5);
|
||||
|
||||
SetSizer(boxV);
|
||||
//SetSizer(boxH);
|
||||
SetSizer(boxH);
|
||||
Layout();
|
||||
|
||||
// Register global hotkey(s).
|
||||
if (!RegisterHotKey(wxZRColaHKID_INVOKE, 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);
|
||||
|
||||
// Register frame specific hotkey(s).
|
||||
{
|
||||
wxAcceleratorEntry entries[1];
|
||||
entries[0].Set(wxACCEL_NORMAL, WXK_RETURN, wxID_SEND);
|
||||
SetAcceleratorTable(wxAcceleratorTable(_countof(entries), entries));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool wxZRColaFrame::Destroy()
|
||||
{
|
||||
// Unregister global hotkey(s).
|
||||
UnregisterHotKey(wxZRColaHKID_INVOKE);
|
||||
|
||||
return wxAppBarFrame::Destroy();
|
||||
}
|
||||
|
||||
|
||||
void wxZRColaFrame::OnCompose(wxCommandEvent& event)
|
||||
{
|
||||
// TODO: Do the real ZRCola composition here.
|
||||
m_preview.SetValue(m_composer.GetValue());
|
||||
|
||||
event.Skip();
|
||||
}
|
||||
|
||||
|
||||
void wxZRColaFrame::OnSendUpdate(wxUpdateUIEvent& event)
|
||||
{
|
||||
event.Enable(m_hWndSource ? true : false);
|
||||
}
|
||||
|
||||
|
||||
void wxZRColaFrame::OnSend(wxCommandEvent& event)
|
||||
{
|
||||
if (m_hWndSource) {
|
||||
// Get text and its length (in Unicode characters). Prepare the INPUT table.
|
||||
wxString text = m_preview.GetValue();
|
||||
std::vector<INPUT>::size_type i = 0, n = text.length();
|
||||
wxString::const_iterator i_text = text.begin();
|
||||
std::vector<INPUT> input(n);
|
||||
for (; 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[0], sizeof(INPUT));
|
||||
m_hWndSource = NULL;
|
||||
|
||||
// Select all input in composer to prepare for the overwrite next time.
|
||||
m_composer.SelectAll();
|
||||
}
|
||||
|
||||
event.Skip();
|
||||
}
|
||||
|
||||
|
||||
void wxZRColaFrame::OnAbout(wxCommandEvent& event)
|
||||
{
|
||||
wxMessageBox(wxString::Format(_("ZRCola v%s\nCopyright 2015-%s Amebis"), wxT(ZRCOLA_VERSION_STR), wxT(ZRCOLA_BUILD_YEAR_STR)), _("About ZRCola"), wxOK | wxICON_INFORMATION);
|
||||
}
|
||||
|
||||
|
||||
WXLRESULT wxZRColaFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
|
||||
{
|
||||
if (message == WM_HOTKEY && wParam == wxZRColaHKID_INVOKE) {
|
||||
// ZRCola hotkey was pressed. Remember the source window and focus ours.
|
||||
m_hWndSource = ::GetForegroundWindow();
|
||||
|
||||
m_composer.SetFocus();
|
||||
if (m_state == wxABS_FLOAT) {
|
||||
if (IsIconized()) {
|
||||
::SendMessage(m_hWnd, WM_SYSCOMMAND, SC_RESTORE, 0);
|
||||
} else {
|
||||
::SetActiveWindow(m_hWnd);
|
||||
::SetForegroundWindow(m_hWnd);
|
||||
}
|
||||
} else if (wxAppBarIsDocked(m_state)) {
|
||||
// ZRCola window is currently docked.
|
||||
|
||||
if (GetAutoHidden()) {
|
||||
// Unhide it.
|
||||
ShowAutoHideAppBar();
|
||||
}
|
||||
|
||||
::SetActiveWindow(m_hWnd);
|
||||
::SetForegroundWindow(m_hWnd);
|
||||
} else
|
||||
wxFAIL_MSG(wxT("unsupported application bar state"));
|
||||
|
||||
return 0;
|
||||
} else
|
||||
return wxAppBarFrame::MSWWindowProc(message, wParam, lParam);
|
||||
}
|
||||
|
@ -20,26 +20,46 @@
|
||||
#pragma once
|
||||
|
||||
#include <wxex/appbar.h>
|
||||
#include <wx/stattext.h>
|
||||
#include <wx/textctrl.h>
|
||||
#include <wx/toolbar.h>
|
||||
|
||||
|
||||
///
|
||||
/// Global hotkey message identifiers
|
||||
///
|
||||
#define wxZRColaHKID_INVOKE 0
|
||||
|
||||
|
||||
///
|
||||
/// ZRCola main frame
|
||||
///
|
||||
class wxZRColaFrame : public wxAppBarFrame
|
||||
{
|
||||
protected:
|
||||
enum {
|
||||
wxID_SEND,
|
||||
wxID_COMPOSER,
|
||||
};
|
||||
|
||||
public:
|
||||
wxZRColaFrame();
|
||||
bool Create();
|
||||
virtual bool Destroy();
|
||||
|
||||
protected:
|
||||
void OnCompose(wxCommandEvent& event);
|
||||
void OnSendUpdate(wxUpdateUIEvent& event);
|
||||
void OnSend(wxCommandEvent& event);
|
||||
void OnAbout(wxCommandEvent& event);
|
||||
wxDECLARE_EVENT_TABLE();
|
||||
|
||||
protected:
|
||||
wxStaticText m_preview;
|
||||
virtual WXLRESULT MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam);
|
||||
|
||||
protected:
|
||||
wxTextCtrl m_preview;
|
||||
wxTextCtrl m_composer;
|
||||
wxToolBar m_toolBar;
|
||||
|
||||
WXHWND m_hWndSource; ///< handle of the active window, when the ZRCola hotkey was pressed
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user