Temporary special character insertion replaced with a first version of a dynamic one

This commit is contained in:
Simon Rozman 2016-03-02 14:44:32 +01:00
parent 72c03af0c5
commit c6f1e8a251
9 changed files with 102 additions and 143 deletions

View File

@ -153,75 +153,6 @@
<event name="OnUpdateUI"></event> <event name="OnUpdateUI"></event>
</object> </object>
</object> </object>
<object class="wxMenu" expanded="1">
<property name="label">&amp;Accents</property>
<property name="name">m_menuAccents</property>
<property name="permission">protected</property>
<object class="wxMenuItem" expanded="1">
<property name="bitmap"></property>
<property name="checked">0</property>
<property name="enabled">1</property>
<property name="help"></property>
<property name="id">wxID_INSERT_GRAVE</property>
<property name="kind">wxITEM_NORMAL</property>
<property name="label">Grave&#x09;&amp;7</property>
<property name="name">m_menuItemGrave</property>
<property name="permission">none</property>
<property name="shortcut"></property>
<property name="unchecked_bitmap"></property>
<event name="OnMenuSelection"></event>
<event name="OnUpdateUI"></event>
</object>
<object class="wxMenuItem" expanded="1">
<property name="bitmap"></property>
<property name="checked">0</property>
<property name="enabled">1</property>
<property name="help"></property>
<property name="id">wxID_INSERT_ACUTE</property>
<property name="kind">wxITEM_NORMAL</property>
<property name="label">Acute&#x09;&amp;9</property>
<property name="name">m_menuItemAcute</property>
<property name="permission">none</property>
<property name="shortcut"></property>
<property name="unchecked_bitmap"></property>
<event name="OnMenuSelection"></event>
<event name="OnUpdateUI"></event>
</object>
<object class="wxMenuItem" expanded="1">
<property name="bitmap"></property>
<property name="checked">0</property>
<property name="enabled">1</property>
<property name="help"></property>
<property name="id">wxID_INSERT_CIRCUMFLEX</property>
<property name="kind">wxITEM_NORMAL</property>
<property name="label">Circumflex&#x09;&amp;3</property>
<property name="name">m_menuItemCircumflex</property>
<property name="permission">none</property>
<property name="shortcut"></property>
<property name="unchecked_bitmap"></property>
<event name="OnMenuSelection"></event>
<event name="OnUpdateUI"></event>
</object>
<object class="separator" expanded="1">
<property name="name">m_separator2</property>
<property name="permission">none</property>
</object>
<object class="wxMenuItem" expanded="1">
<property name="bitmap"></property>
<property name="checked">0</property>
<property name="enabled">1</property>
<property name="help"></property>
<property name="id">wxID_INSERT_INV_BREVE_BELOW</property>
<property name="kind">wxITEM_NORMAL</property>
<property name="label">Inverted &amp;breve</property>
<property name="name">m_menuItemInvBreveBelow</property>
<property name="permission">none</property>
<property name="shortcut"></property>
<property name="unchecked_bitmap"></property>
<event name="OnMenuSelection"></event>
<event name="OnUpdateUI"></event>
</object>
</object>
<object class="wxMenu" expanded="1"> <object class="wxMenu" expanded="1">
<property name="label">&amp;Help</property> <property name="label">&amp;Help</property>
<property name="name">m_menuHelp</property> <property name="name">m_menuHelp</property>

View File

@ -93,6 +93,9 @@
<ClInclude Include="zrcolagui.h" /> <ClInclude Include="zrcolagui.h" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\lib\libZRColaUI\build\libZRColaUI.vcxproj">
<Project>{c0a84bd2-3870-4cd6-b281-0ab322e3c579}</Project>
</ProjectReference>
<ProjectReference Include="..\lib\libZRCola\build\libZRCola.vcxproj"> <ProjectReference Include="..\lib\libZRCola\build\libZRCola.vcxproj">
<Project>{3c61929e-7289-4101-8d0a-da22d6e1aea8}</Project> <Project>{3c61929e-7289-4101-8d0a-da22d6e1aea8}</Project>
</ProjectReference> </ProjectReference>

View File

@ -20,6 +20,32 @@
#include "stdafx.h" #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 // wxZRColaComposerPanel
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
@ -28,6 +54,7 @@ wxZRColaComposerPanel::wxZRColaComposerPanel(wxWindow* parent) :
m_progress(false), m_progress(false),
m_selDecomposed(0, 0), m_selDecomposed(0, 0),
m_selComposed(0, 0), m_selComposed(0, 0),
eh(this),
wxZRColaComposerPanelBase(parent) wxZRColaComposerPanelBase(parent)
{ {
wxString sPath(wxPathOnly(wxTheApp->argv[0])); wxString sPath(wxPathOnly(wxTheApp->argv[0]));
@ -39,26 +66,63 @@ wxZRColaComposerPanel::wxZRColaComposerPanel(wxWindow* parent) :
ZRCola::recordsize_t size; ZRCola::recordsize_t size;
dat.read((char*)&size, sizeof(ZRCola::recordsize_t)); dat.read((char*)&size, sizeof(ZRCola::recordsize_t));
if (dat.good()) { if (dat.good()) {
ZRCola::translation_rec r_rec(m_t_db); bool has_translation_data = false;
if (r_rec.find(dat, size)) {
dat >> r_rec; for (;;) {
if (!dat.good()) { ZRCola::recordid_t id;
wxFAIL_MSG(wxT("Error reading translation data from ZRCola.zrcdb.")); if (!stdex::idrec::read_id(dat, id, size)) break;
m_t_db.idxComp .clear();
m_t_db.idxDecomp.clear(); if (id == ZRCola::translation_rec::id) {
m_t_db.data .clear(); 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.")); wxFAIL_MSG(wxT("ZRCola.zrcdb has no translation data."));
} }
} else } else
wxFAIL_MSG(wxT("ZRCola.zrcdb is not a valid ZRCola database.")); wxFAIL_MSG(wxT("ZRCola.zrcdb is not a valid ZRCola database."));
} }
std::vector<unsigned __int32>::size_type n = m_ks_db.idxKey.size();
std::vector<wxAcceleratorEntry> entries;
entries.reserve(n);
for (std::vector<unsigned __int32>::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() wxZRColaComposerPanel::~wxZRColaComposerPanel()
{ {
PopEventHandler();
} }

View File

@ -20,6 +20,7 @@
/// ///
/// Forward declarations /// Forward declarations
/// ///
class wxZRColaComposerPanelEvtHandler;
class wxZRColaComposerPanel; class wxZRColaComposerPanel;
@ -27,20 +28,40 @@ class wxZRColaComposerPanel;
#include "zrcolagui.h" #include "zrcolagui.h"
#include <zrcola/translate.h> #include <zrcola/translate.h>
#include <zrcolaui/keyboard.h>
#include <utility> #include <utility>
///
/// 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 /// ZRCola composer panel
/// ///
class wxZRColaComposerPanel : public wxZRColaComposerPanelBase class wxZRColaComposerPanel : public wxZRColaComposerPanelBase
{ {
enum {
wxID_ACCEL = wxID_HIGHEST
};
public: public:
wxZRColaComposerPanel(wxWindow* parent); wxZRColaComposerPanel(wxWindow* parent);
virtual ~wxZRColaComposerPanel(); virtual ~wxZRColaComposerPanel();
// Allow main frame direct access to our members. friend class wxZRColaFrame; // Allow main frame direct access to our members.
friend class wxZRColaFrame; friend class wxZRColaComposerPanelEvtHandler; // Allow own event handler direct access to our members.
protected: protected:
virtual void OnDecomposedPaint(wxPaintEvent& event); virtual void OnDecomposedPaint(wxPaintEvent& event);
@ -50,9 +71,11 @@ protected:
protected: protected:
ZRCola::translation_db m_t_db; ///< Translation database 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 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 ZRCola::mapping_vector m_mapping; ///< Character index mapping vector between composed and decomposed text
std::pair<long, long> std::pair<long, long>
m_selDecomposed, ///< Character index of selected text in decomposed text control m_selDecomposed, ///< Character index of selected text in decomposed text control
m_selComposed; ///< Character index of selected text in composed text control m_selComposed; ///< Character index of selected text in composed text control
wxZRColaComposerPanelEvtHandler eh; ///< Event handler
}; };

View File

@ -32,10 +32,6 @@ wxBEGIN_EVENT_TABLE(wxZRColaFrame, wxZRColaFrameBase)
EVT_MENU(wxZRColaFrame::wxID_SEND_DECOMPOSED , wxZRColaFrame::OnSendDecomposed ) EVT_MENU(wxZRColaFrame::wxID_SEND_DECOMPOSED , wxZRColaFrame::OnSendDecomposed )
EVT_MENU(wxZRColaFrame::wxID_SEND_ABORT , wxZRColaFrame::OnSendAbort ) EVT_MENU(wxZRColaFrame::wxID_SEND_ABORT , wxZRColaFrame::OnSendAbort )
EVT_MENU( wxID_EXIT , wxZRColaFrame::OnExit ) 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 ) EVT_MENU( wxID_ABOUT , wxZRColaFrame::OnAbout )
wxEND_EVENT_TABLE() 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) 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); wxMessageBox(wxString::Format(_("ZRCola v%s\nCopyright 2015-%s Amebis"), wxT(ZRCOLA_VERSION_STR), wxT(ZRCOLA_BUILD_YEAR_STR)), _("About ZRCola"), wxOK | wxICON_INFORMATION);

View File

@ -60,10 +60,6 @@ protected:
void OnSendDecomposed(wxCommandEvent& event); void OnSendDecomposed(wxCommandEvent& event);
void OnSendAbort(wxCommandEvent& event); void OnSendAbort(wxCommandEvent& event);
void OnExit(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); void OnAbout(wxCommandEvent& event);
wxDECLARE_EVENT_TABLE(); wxDECLARE_EVENT_TABLE();

View File

@ -34,27 +34,6 @@ wxZRColaFrameBase::wxZRColaFrameBase( wxWindow* parent, wxWindowID id, const wxS
m_menubar->Append( m_menuFile, _("&File") ); 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(); m_menuHelp = new wxMenu();
wxMenuItem* m_menuItemAbout; wxMenuItem* m_menuItemAbout;
m_menuItemAbout = new wxMenuItem( m_menuHelp, wxID_ABOUT, wxString( _("&About") ) , wxEmptyString, wxITEM_NORMAL ); m_menuItemAbout = new wxMenuItem( m_menuHelp, wxID_ABOUT, wxString( _("&About") ) , wxEmptyString, wxITEM_NORMAL );

View File

@ -37,17 +37,8 @@ class wxZRColaFrameBase : public wxFrame
private: private:
protected: protected:
enum
{
wxID_INSERT_GRAVE = 1000,
wxID_INSERT_ACUTE,
wxID_INSERT_CIRCUMFLEX,
wxID_INSERT_INV_BREVE_BELOW
};
wxMenuBar* m_menubar; wxMenuBar* m_menubar;
wxMenu* m_menuFile; wxMenu* m_menuFile;
wxMenu* m_menuAccents;
wxMenu* m_menuHelp; wxMenu* m_menuHelp;
wxZRColaComposerPanel* m_panel; wxZRColaComposerPanel* m_panel;

@ -1 +1 @@
Subproject commit fbb20a204206e644140a653d518c3257bc872c47 Subproject commit f413026bbc51ad960b731f12cb7cb2b1c2feeacc