From c6f1e8a251f6cf35e9576be6125fd062eb5015a0 Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Wed, 2 Mar 2016 14:44:32 +0100 Subject: [PATCH] Temporary special character insertion replaced with a first version of a dynamic one --- ZRCola/ZRCola.fbp | 69 --------------------------------- ZRCola/ZRCola.vcxproj | 3 ++ ZRCola/zrcolacomppnl.cpp | 82 +++++++++++++++++++++++++++++++++++----- ZRCola/zrcolacomppnl.h | 27 ++++++++++++- ZRCola/zrcolafrm.cpp | 28 -------------- ZRCola/zrcolafrm.h | 4 -- ZRCola/zrcolagui.cpp | 21 ---------- ZRCola/zrcolagui.h | 9 ----- lib/stdex | 2 +- 9 files changed, 102 insertions(+), 143 deletions(-) diff --git a/ZRCola/ZRCola.fbp b/ZRCola/ZRCola.fbp index 482161d..f62bf2b 100644 --- a/ZRCola/ZRCola.fbp +++ b/ZRCola/ZRCola.fbp @@ -153,75 +153,6 @@ - - &Accents - m_menuAccents - protected - - - 0 - 1 - - wxID_INSERT_GRAVE - wxITEM_NORMAL - Grave &7 - m_menuItemGrave - none - - - - - - - - 0 - 1 - - wxID_INSERT_ACUTE - wxITEM_NORMAL - Acute &9 - m_menuItemAcute - none - - - - - - - - 0 - 1 - - wxID_INSERT_CIRCUMFLEX - wxITEM_NORMAL - Circumflex &3 - m_menuItemCircumflex - none - - - - - - - m_separator2 - none - - - - 0 - 1 - - wxID_INSERT_INV_BREVE_BELOW - wxITEM_NORMAL - Inverted &breve - m_menuItemInvBreveBelow - none - - - - - - &Help m_menuHelp diff --git a/ZRCola/ZRCola.vcxproj b/ZRCola/ZRCola.vcxproj index fb4cc6b..1b2d895 100644 --- a/ZRCola/ZRCola.vcxproj +++ b/ZRCola/ZRCola.vcxproj @@ -93,6 +93,9 @@ + + {c0a84bd2-3870-4cd6-b281-0ab322e3c579} + {3c61929e-7289-4101-8d0a-da22d6e1aea8} diff --git a/ZRCola/zrcolacomppnl.cpp b/ZRCola/zrcolacomppnl.cpp index 83d9e40..2c74877 100644 --- a/ZRCola/zrcolacomppnl.cpp +++ b/ZRCola/zrcolacomppnl.cpp @@ -20,6 +20,32 @@ #include "stdafx.h" +////////////////////////////////////////////////////////////////////////// +// wxZRColaComposerPanelEvtHandler +////////////////////////////////////////////////////////////////////////// + +wxZRColaComposerPanelEvtHandler::wxZRColaComposerPanelEvtHandler(wxZRColaComposerPanel *target) : + m_target(target), + wxEvtHandler() +{ +} + + +bool wxZRColaComposerPanelEvtHandler::ProcessEvent(wxEvent& event) +{ + if (m_target && event.IsCommandEvent()) { + int id = event.GetId(); + if (wxZRColaComposerPanel::wxID_ACCEL <= id && id < wxZRColaComposerPanel::wxID_ACCEL + m_target->m_ks_db.idxKey.size()) { + const ZRCola::keyseq_db::keyseq &ks = (const ZRCola::keyseq_db::keyseq&)m_target->m_ks_db.data[m_target->m_ks_db.idxKey[id - wxZRColaComposerPanel::wxID_ACCEL]]; + m_target->m_decomposed->WriteText(ks.chr); + return true; + } + } + + return wxEvtHandler::ProcessEvent(event); +} + + ////////////////////////////////////////////////////////////////////////// // wxZRColaComposerPanel ////////////////////////////////////////////////////////////////////////// @@ -28,6 +54,7 @@ wxZRColaComposerPanel::wxZRColaComposerPanel(wxWindow* parent) : m_progress(false), m_selDecomposed(0, 0), m_selComposed(0, 0), + eh(this), wxZRColaComposerPanelBase(parent) { wxString sPath(wxPathOnly(wxTheApp->argv[0])); @@ -39,26 +66,63 @@ wxZRColaComposerPanel::wxZRColaComposerPanel(wxWindow* parent) : ZRCola::recordsize_t size; dat.read((char*)&size, sizeof(ZRCola::recordsize_t)); if (dat.good()) { - ZRCola::translation_rec r_rec(m_t_db); - if (r_rec.find(dat, size)) { - dat >> r_rec; - if (!dat.good()) { - wxFAIL_MSG(wxT("Error reading translation data from ZRCola.zrcdb.")); - m_t_db.idxComp .clear(); - m_t_db.idxDecomp.clear(); - m_t_db.data .clear(); + bool has_translation_data = false; + + for (;;) { + ZRCola::recordid_t id; + if (!stdex::idrec::read_id(dat, id, size)) break; + + if (id == ZRCola::translation_rec::id) { + dat >> ZRCola::translation_rec(m_t_db); + if (dat.good()) { + has_translation_data = true; + } else { + wxFAIL_MSG(wxT("Error reading translation data from ZRCola.zrcdb.")); + m_t_db.idxComp .clear(); + m_t_db.idxDecomp.clear(); + m_t_db.data .clear(); + } + } else if (id == ZRCola::keyseq_rec::id) { + dat >> ZRCola::keyseq_rec(m_ks_db); + if (!dat.good()) { + wxFAIL_MSG(wxT("Error reading key sequence data from ZRCola.zrcdb.")); + m_ks_db.idxChr.clear(); + m_ks_db.idxKey.clear(); + m_ks_db.data .clear(); + } } - } else + } + + if (!has_translation_data) wxFAIL_MSG(wxT("ZRCola.zrcdb has no translation data.")); } } else wxFAIL_MSG(wxT("ZRCola.zrcdb is not a valid ZRCola database.")); } + + std::vector::size_type n = m_ks_db.idxKey.size(); + std::vector entries; + entries.reserve(n); + for (std::vector::size_type i = 0; i < n; i++) { + const ZRCola::keyseq_db::keyseq &ks = (const ZRCola::keyseq_db::keyseq&)m_ks_db.data[m_ks_db.idxKey[i]]; + if (ks.seq_len == 1) { + // The key sequence is trivial. + entries.push_back(wxAcceleratorEntry( + ((ks.seq[0].modifiers & ZRCola::keyseq_db::keyseq::SHIFT) ? wxACCEL_SHIFT : 0) | + ((ks.seq[0].modifiers & ZRCola::keyseq_db::keyseq::CTRL ) ? wxACCEL_CTRL : 0) | + ((ks.seq[0].modifiers & ZRCola::keyseq_db::keyseq::ALT ) ? wxACCEL_ALT : 0), ks.seq[0].key, wxID_ACCEL + i)); + } + } + wxAcceleratorTable accel(entries.size(), entries.data()); + SetAcceleratorTable(accel); + + PushEventHandler(&eh); } wxZRColaComposerPanel::~wxZRColaComposerPanel() { + PopEventHandler(); } diff --git a/ZRCola/zrcolacomppnl.h b/ZRCola/zrcolacomppnl.h index 05ecce7..d9bc0bc 100644 --- a/ZRCola/zrcolacomppnl.h +++ b/ZRCola/zrcolacomppnl.h @@ -20,6 +20,7 @@ /// /// Forward declarations /// +class wxZRColaComposerPanelEvtHandler; class wxZRColaComposerPanel; @@ -27,20 +28,40 @@ class wxZRColaComposerPanel; #include "zrcolagui.h" #include +#include #include +/// +/// ZRCola composer panel event handler +/// +class wxZRColaComposerPanelEvtHandler : public wxEvtHandler +{ +public: + wxZRColaComposerPanelEvtHandler(wxZRColaComposerPanel *target); + + virtual bool ProcessEvent(wxEvent& event); + +public: + wxZRColaComposerPanel *m_target; ///< Composer panel window +}; + + /// /// ZRCola composer panel /// class wxZRColaComposerPanel : public wxZRColaComposerPanelBase { + enum { + wxID_ACCEL = wxID_HIGHEST + }; + public: wxZRColaComposerPanel(wxWindow* parent); virtual ~wxZRColaComposerPanel(); - // Allow main frame direct access to our members. - friend class wxZRColaFrame; + friend class wxZRColaFrame; // Allow main frame direct access to our members. + friend class wxZRColaComposerPanelEvtHandler; // Allow own event handler direct access to our members. protected: virtual void OnDecomposedPaint(wxPaintEvent& event); @@ -50,9 +71,11 @@ protected: protected: ZRCola::translation_db m_t_db; ///< Translation database + ZRCola::keyseq_db m_ks_db; ///< Key sequence database bool m_progress; ///< Boolean flag to avoid recursive updates of composed and decomposed text controls ZRCola::mapping_vector m_mapping; ///< Character index mapping vector between composed and decomposed text std::pair m_selDecomposed, ///< Character index of selected text in decomposed text control m_selComposed; ///< Character index of selected text in composed text control + wxZRColaComposerPanelEvtHandler eh; ///< Event handler }; diff --git a/ZRCola/zrcolafrm.cpp b/ZRCola/zrcolafrm.cpp index 0613a70..7a4b939 100644 --- a/ZRCola/zrcolafrm.cpp +++ b/ZRCola/zrcolafrm.cpp @@ -32,10 +32,6 @@ wxBEGIN_EVENT_TABLE(wxZRColaFrame, wxZRColaFrameBase) EVT_MENU(wxZRColaFrame::wxID_SEND_DECOMPOSED , wxZRColaFrame::OnSendDecomposed ) EVT_MENU(wxZRColaFrame::wxID_SEND_ABORT , wxZRColaFrame::OnSendAbort ) EVT_MENU( wxID_EXIT , wxZRColaFrame::OnExit ) - EVT_MENU( wxID_INSERT_GRAVE , wxZRColaFrame::OnInsertGrave ) - EVT_MENU( wxID_INSERT_ACUTE , wxZRColaFrame::OnInsertAcute ) - EVT_MENU( wxID_INSERT_CIRCUMFLEX , wxZRColaFrame::OnInsertCircumflex ) - EVT_MENU( wxID_INSERT_INV_BREVE_BELOW, wxZRColaFrame::OnInsertInvertedBreveBelow) EVT_MENU( wxID_ABOUT , wxZRColaFrame::OnAbout ) wxEND_EVENT_TABLE() @@ -139,30 +135,6 @@ void wxZRColaFrame::OnExit(wxCommandEvent& event) } -void wxZRColaFrame::OnInsertGrave(wxCommandEvent& event) -{ - m_panel->m_decomposed->WriteText(L"\xE000"); -} - - -void wxZRColaFrame::OnInsertAcute(wxCommandEvent& event) -{ - m_panel->m_decomposed->WriteText(L"\xE001"); -} - - -void wxZRColaFrame::OnInsertCircumflex(wxCommandEvent& event) -{ - m_panel->m_decomposed->WriteText(L"\xE002"); -} - - -void wxZRColaFrame::OnInsertInvertedBreveBelow(wxCommandEvent& event) -{ - m_panel->m_decomposed->WriteText(L"\xE02F"); -} - - 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); diff --git a/ZRCola/zrcolafrm.h b/ZRCola/zrcolafrm.h index 0b7735f..94c0cb0 100644 --- a/ZRCola/zrcolafrm.h +++ b/ZRCola/zrcolafrm.h @@ -60,10 +60,6 @@ protected: void OnSendDecomposed(wxCommandEvent& event); void OnSendAbort(wxCommandEvent& event); void OnExit(wxCommandEvent& event); - void OnInsertGrave(wxCommandEvent& event); - void OnInsertAcute(wxCommandEvent& event); - void OnInsertCircumflex(wxCommandEvent& event); - void OnInsertInvertedBreveBelow(wxCommandEvent& event); void OnAbout(wxCommandEvent& event); wxDECLARE_EVENT_TABLE(); diff --git a/ZRCola/zrcolagui.cpp b/ZRCola/zrcolagui.cpp index 6c853eb..d31150a 100644 --- a/ZRCola/zrcolagui.cpp +++ b/ZRCola/zrcolagui.cpp @@ -34,27 +34,6 @@ wxZRColaFrameBase::wxZRColaFrameBase( wxWindow* parent, wxWindowID id, const wxS m_menubar->Append( m_menuFile, _("&File") ); - m_menuAccents = new wxMenu(); - wxMenuItem* m_menuItemGrave; - m_menuItemGrave = new wxMenuItem( m_menuAccents, wxID_INSERT_GRAVE, wxString( _("Grave\t&7") ) , wxEmptyString, wxITEM_NORMAL ); - m_menuAccents->Append( m_menuItemGrave ); - - wxMenuItem* m_menuItemAcute; - m_menuItemAcute = new wxMenuItem( m_menuAccents, wxID_INSERT_ACUTE, wxString( _("Acute\t&9") ) , wxEmptyString, wxITEM_NORMAL ); - m_menuAccents->Append( m_menuItemAcute ); - - wxMenuItem* m_menuItemCircumflex; - m_menuItemCircumflex = new wxMenuItem( m_menuAccents, wxID_INSERT_CIRCUMFLEX, wxString( _("Circumflex\t&3") ) , wxEmptyString, wxITEM_NORMAL ); - m_menuAccents->Append( m_menuItemCircumflex ); - - m_menuAccents->AppendSeparator(); - - wxMenuItem* m_menuItemInvBreveBelow; - m_menuItemInvBreveBelow = new wxMenuItem( m_menuAccents, wxID_INSERT_INV_BREVE_BELOW, wxString( _("Inverted &breve") ) , wxEmptyString, wxITEM_NORMAL ); - m_menuAccents->Append( m_menuItemInvBreveBelow ); - - m_menubar->Append( m_menuAccents, _("&Accents") ); - m_menuHelp = new wxMenu(); wxMenuItem* m_menuItemAbout; m_menuItemAbout = new wxMenuItem( m_menuHelp, wxID_ABOUT, wxString( _("&About") ) , wxEmptyString, wxITEM_NORMAL ); diff --git a/ZRCola/zrcolagui.h b/ZRCola/zrcolagui.h index d25b6a3..71d7cab 100644 --- a/ZRCola/zrcolagui.h +++ b/ZRCola/zrcolagui.h @@ -37,17 +37,8 @@ class wxZRColaFrameBase : public wxFrame private: protected: - enum - { - wxID_INSERT_GRAVE = 1000, - wxID_INSERT_ACUTE, - wxID_INSERT_CIRCUMFLEX, - wxID_INSERT_INV_BREVE_BELOW - }; - wxMenuBar* m_menubar; wxMenu* m_menuFile; - wxMenu* m_menuAccents; wxMenu* m_menuHelp; wxZRColaComposerPanel* m_panel; diff --git a/lib/stdex b/lib/stdex index fbb20a2..f413026 160000 --- a/lib/stdex +++ b/lib/stdex @@ -1 +1 @@ -Subproject commit fbb20a204206e644140a653d518c3257bc872c47 +Subproject commit f413026bbc51ad960b731f12cb7cb2b1c2feeacc