Code clean-up

This commit is contained in:
Simon Rozman 2016-10-13 10:32:20 +02:00
parent affe7b06a2
commit 891bd624fc
9 changed files with 44 additions and 48 deletions

View File

@ -31,7 +31,7 @@ END_EVENT_TABLE()
wxZRColaCharacterCatalogPanel::wxZRColaCharacterCatalogPanel(wxWindow* parent) : wxZRColaCharacterCatalogPanelBase(parent)
{
std::fstream dat((LPCTSTR)((ZRColaApp*)wxTheApp)->GetDatabaseFilePath(), std::ios_base::in | std::ios_base::binary);
std::fstream dat((LPCTSTR)dynamic_cast<ZRColaApp*>(wxTheApp)->GetDatabaseFilePath(), std::ios_base::in | std::ios_base::binary);
if (dat.good()) {
if (stdex::idrec::find<ZRCola::recordid_t, ZRCola::recordsize_t, ZRCOLA_RECORD_ALIGN>(dat, ZRCOLA_DB_ID, sizeof(ZRCola::recordid_t))) {
ZRCola::recordsize_t size;
@ -96,7 +96,7 @@ void wxZRColaCharacterCatalogPanel::OnChoice(wxCommandEvent& event)
void wxZRColaCharacterCatalogPanel::OnGridClick(wxGridEvent& event)
{
ZRColaApp *app = (ZRColaApp*)wxTheApp;
auto app = dynamic_cast<ZRColaApp*>(wxTheApp);
if (app->m_mainWnd) {
app->m_mainWnd->m_panel->m_decomposed->WriteText(m_grid->GetCellValue(event.GetRow(), event.GetCol()));
app->m_mainWnd->m_panel->m_decomposed->SetFocus();
@ -111,7 +111,7 @@ void wxZRColaCharacterCatalogPanel::OnGridKeyDown(wxKeyEvent& event)
switch (event.GetKeyCode()) {
case WXK_RETURN:
case WXK_NUMPAD_ENTER:
ZRColaApp *app = (ZRColaApp*)wxTheApp;
auto app = dynamic_cast<ZRColaApp*>(wxTheApp);
if (app->m_mainWnd) {
app->m_mainWnd->m_panel->m_decomposed->WriteText(m_grid->GetCellValue(m_grid->GetCursorRow(), m_grid->GetCursorColumn()));
app->m_mainWnd->m_panel->m_decomposed->SetFocus();
@ -137,7 +137,7 @@ void wxZRColaCharacterCatalogPanel::OnShowAll(wxCommandEvent& event)
void wxZRColaCharacterCatalogPanel::OnFocusDecomposed(wxCommandEvent& event)
{
ZRColaApp *app = (ZRColaApp*)wxTheApp;
auto app = dynamic_cast<ZRColaApp*>(wxTheApp);
if (app->m_mainWnd) {
app->m_mainWnd->m_panel->m_decomposed->SetFocus();
@ -193,7 +193,7 @@ wxString wxPersistentZRColaCharacterCatalogPanel::GetKind() const
void wxPersistentZRColaCharacterCatalogPanel::Save() const
{
const wxZRColaCharacterCatalogPanel * const wnd = static_cast<const wxZRColaCharacterCatalogPanel*>(GetWindow());
auto wnd = static_cast<const wxZRColaCharacterCatalogPanel*>(GetWindow()); // dynamic_cast is not reliable as we are typically called late in the wxTopLevelWindowMSW destructor.
SaveValue(wxT("charGroup"), wnd->m_cg_id);
SaveValue(wxT("showAll" ), wnd->m_show_all->GetValue());
@ -202,8 +202,7 @@ void wxPersistentZRColaCharacterCatalogPanel::Save() const
bool wxPersistentZRColaCharacterCatalogPanel::Restore()
{
wxZRColaCharacterCatalogPanel * const wnd = static_cast<wxZRColaCharacterCatalogPanel*>(GetWindow());
auto wnd = dynamic_cast<wxZRColaCharacterCatalogPanel*>(GetWindow());
bool update = false;
// Restore selected character group.

View File

@ -97,7 +97,7 @@ wxString wxZRColaCharGrid::GetToolTipText(int idx)
{
wxASSERT_MSG(idx < (int)m_chars.Length(), wxT("index out of bounds"));
ZRColaApp *app = (ZRColaApp*)wxTheApp;
auto app = dynamic_cast<ZRColaApp*>(wxTheApp);
// See if this character has a key sequence registered.
char ks[sizeof(ZRCola::keyseq_db::keyseq)] = {};

View File

@ -80,7 +80,7 @@ void wxPersistentZRColaCharRequest::Save() const
{
wxPersistentDialog::Save();
const wxZRColaCharRequest * const wnd = static_cast<const wxZRColaCharRequest*>(GetWindow());
auto wnd = static_cast<const wxZRColaCharRequest*>(GetWindow()); // dynamic_cast is not reliable as we are typically called late in the wxTopLevelWindowMSW destructor.
SaveValue(wxT("character"), wnd->m_character->GetValue());
SaveValue(wxT("context"), wnd->m_context->GetValue());
@ -89,7 +89,7 @@ void wxPersistentZRColaCharRequest::Save() const
bool wxPersistentZRColaCharRequest::Restore()
{
wxZRColaCharRequest * const wnd = static_cast<wxZRColaCharRequest*>(GetWindow());
auto wnd = dynamic_cast<wxZRColaCharRequest*>(GetWindow());
wxString str;
if (RestoreValue(wxT("character"), &str))

View File

@ -41,7 +41,7 @@ wxZRColaCharSelect::wxZRColaCharSelect(wxWindow* parent) :
m_unicode->SetValidator(wxHexValidator<wchar_t>(&m_char, wxNUM_VAL_DEFAULT, 4));
// Fill categories.
ZRColaApp *app = (ZRColaApp*)wxTheApp;
auto app = dynamic_cast<ZRColaApp*>(wxTheApp);
for (size_t i = 0, n = app->m_cc_db.idxRnk.size(); i < n; i++) {
const auto &cc = app->m_cc_db.idxRnk[i];
int idx = m_categories->Insert(wxGetTranslation(wxString(cc.name, cc.name_len), wxT("ZRCola-zrcdb")), i);
@ -74,7 +74,7 @@ void wxZRColaCharSelect::OnIdle(wxIdleEvent& event)
if (m_unicodeChanged) {
if (m_unicode->GetValidator()->TransferFromWindow()) {
ZRColaApp *app = (ZRColaApp*)wxTheApp;
auto app = dynamic_cast<ZRColaApp*>(wxTheApp);
m_gridPreview->SetCellValue(wxString(1, m_char), 0, 0);
@ -137,7 +137,7 @@ void wxZRColaCharSelect::OnIdle(wxIdleEvent& event)
wxString val(m_search->GetValue());
if (!val.IsEmpty()) {
ZRColaApp *app = (ZRColaApp*)wxTheApp;
auto app = dynamic_cast<ZRColaApp*>(wxTheApp);
m_searchThread = new SearchThread(this);
@ -191,7 +191,7 @@ void wxZRColaCharSelect::OnCategoriesAll(wxHyperlinkEvent& event)
{
event.StopPropagation();
ZRColaApp *app = (ZRColaApp*)wxTheApp;
auto app = dynamic_cast<ZRColaApp*>(wxTheApp);
for (size_t i = 0, n = app->m_cc_db.idxRnk.size(); i < n; i++)
m_categories->Check(i, true);
@ -203,7 +203,7 @@ void wxZRColaCharSelect::OnCategoriesNone(wxHyperlinkEvent& event)
{
event.StopPropagation();
ZRColaApp *app = (ZRColaApp*)wxTheApp;
auto app = dynamic_cast<ZRColaApp*>(wxTheApp);
for (size_t i = 0, n = app->m_cc_db.idxRnk.size(); i < n; i++)
m_categories->Check(i, false);
@ -215,7 +215,7 @@ void wxZRColaCharSelect::OnCategoriesInvert(wxHyperlinkEvent& event)
{
event.StopPropagation();
ZRColaApp *app = (ZRColaApp*)wxTheApp;
auto app = dynamic_cast<ZRColaApp*>(wxTheApp);
for (size_t i = 0, n = app->m_cc_db.idxRnk.size(); i < n; i++)
m_categories->Check(i, !m_categories->IsChecked(i));
@ -408,7 +408,7 @@ void wxZRColaCharSelect::OnOKButtonClick(wxCommandEvent& event)
void wxZRColaCharSelect::ResetResults()
{
// Fill the results.
ZRColaApp *app = (ZRColaApp*)wxTheApp;
auto app = dynamic_cast<ZRColaApp*>(wxTheApp);
size_t i, n = app->m_chr_db.idxChr.size();
wxString val;
val.reserve(n);
@ -500,7 +500,7 @@ wxZRColaCharSelect::SearchThread::SearchThread(wxZRColaCharSelect *parent) :
wxThread::ExitCode wxZRColaCharSelect::SearchThread::Entry()
{
ZRColaApp *app = (ZRColaApp*)wxTheApp;
auto app = dynamic_cast<ZRColaApp*>(wxTheApp);
std::map<wchar_t, ZRCola::charrank_t> hits;
if (TestDestroy()) return (wxThread::ExitCode)1;
@ -580,11 +580,11 @@ void wxPersistentZRColaCharSelect::Save() const
{
wxPersistentDialog::Save();
const wxZRColaCharSelect * const wnd = static_cast<const wxZRColaCharSelect*>(GetWindow());
auto wnd = static_cast<const wxZRColaCharSelect*>(GetWindow()); // dynamic_cast is not reliable as we are typically called late in the wxTopLevelWindowMSW destructor.
auto app = dynamic_cast<ZRColaApp*>(wxTheApp);
SaveValue(wxT("recentChars"), wnd->m_gridRecent->GetCharacters());
ZRColaApp *app = (ZRColaApp*)wxTheApp;
for (size_t i = 0, n = app->m_cc_db.idxRnk.size(); i < n; i++) {
const auto &cc = app->m_cc_db.idxRnk[i];
wxString name(wxT("category"));
@ -598,13 +598,13 @@ void wxPersistentZRColaCharSelect::Save() const
bool wxPersistentZRColaCharSelect::Restore()
{
wxZRColaCharSelect * const wnd = static_cast<wxZRColaCharSelect*>(GetWindow());
auto wnd = dynamic_cast<wxZRColaCharSelect*>(GetWindow());
auto app = dynamic_cast<ZRColaApp*>(wxTheApp);
wxString recent;
if (RestoreValue(wxT("recentChars"), &recent))
wnd->m_gridRecent->SetCharacters(recent);
ZRColaApp *app = (ZRColaApp*)wxTheApp;
for (size_t i = 0, n = app->m_cc_db.idxRnk.size(); i < n; i++) {
const auto &cc = app->m_cc_db.idxRnk[i];
wxString name(wxT("category"));

View File

@ -86,14 +86,15 @@ void wxZRColaComposerPanel::SynchronizePanels()
if (m_decomposedChanged) {
m_timerSave.Stop();
auto app = dynamic_cast<ZRColaApp*>(wxTheApp);
wxString src;
size_t len = GetValue(m_decomposed, src);
std::wstring norm;
((ZRColaApp*)wxTheApp)->m_t_db.Decompose(src.data(), len, norm, &m_mapping1);
app->m_t_db.Decompose(src.data(), len, norm, &m_mapping1);
std::wstring dst;
((ZRColaApp*)wxTheApp)->m_t_db.Compose(norm.data(), norm.size(), dst, &m_mapping2);
app->m_t_db.Compose(norm.data(), norm.size(), dst, &m_mapping2);
m_decomposed->GetSelection(&m_selDecomposed.first, &m_selDecomposed.second);
@ -115,7 +116,6 @@ void wxZRColaComposerPanel::SynchronizePanels()
wxString src;
size_t len = GetValue(m_composed, src);
ZRColaApp *app = (ZRColaApp*)wxTheApp;
std::wstring dst;
wxZRColaFrame *mainWnd = dynamic_cast<wxZRColaFrame*>(wxGetActiveWindow());
if (mainWnd)
@ -382,7 +382,7 @@ wxString wxPersistentZRColaComposerPanel::GetKind() const
void wxPersistentZRColaComposerPanel::Save() const
{
const wxZRColaComposerPanel * const wnd = static_cast<const wxZRColaComposerPanel*>(GetWindow());
auto const wnd = static_cast<const wxZRColaComposerPanel*>(GetWindow()); // dynamic_cast is not reliable as we are typically called late in the wxTopLevelWindowMSW destructor.
SaveValue(wxT("splitDecomposed"), wnd->m_splitterDecomposed->GetSashPosition());
SaveValue(wxT("splitComposed" ), wnd->m_splitterComposed ->GetSashPosition());
@ -391,7 +391,7 @@ void wxPersistentZRColaComposerPanel::Save() const
bool wxPersistentZRColaComposerPanel::Restore()
{
wxZRColaComposerPanel * const wnd = static_cast<wxZRColaComposerPanel*>(GetWindow());
auto wnd = dynamic_cast<wxZRColaComposerPanel*>(GetWindow());
int sashVal;

View File

@ -365,7 +365,7 @@ void wxZRColaFrame::OnHelpShortcuts(wxCommandEvent& event)
#endif
// Search and try to launch local PDF copy.
ZRColaApp *app = (ZRColaApp*)wxTheApp;
auto app = dynamic_cast<ZRColaApp*>(wxTheApp);
pdf_path = app->GetDatabasePath();
pdf_path += _T("ZRCola_keyboard.pdf");
if (wxFileExists(pdf_path) &&
@ -549,23 +549,21 @@ wxPersistentZRColaFrame::wxPersistentZRColaFrame(wxZRColaFrame *wnd) : wxPersist
void wxPersistentZRColaFrame::Save() const
{
const wxZRColaFrame * const wnd = static_cast<const wxZRColaFrame*>(GetWindow());
wxPersistentTLW::Save();
auto wnd = static_cast<const wxZRColaFrame*>(GetWindow()); // dynamic_cast is not reliable as we are typically called late in the wxTopLevelWindowMSW destructor.
wxPersistentZRColaComposerPanel(wnd->m_panel).Save();
wxPersistentZRColaCharacterCatalogPanel(wnd->m_panelChrCat).Save();
wxPersistentTLW::Save();
}
bool wxPersistentZRColaFrame::Restore()
{
const bool r = wxPersistentTLW::Restore();
wxZRColaFrame * const wnd = static_cast<wxZRColaFrame*>(GetWindow());
auto wnd = dynamic_cast<wxZRColaFrame*>(GetWindow());
wxPersistentZRColaCharacterCatalogPanel(wnd->m_panelChrCat).Restore();
wxPersistentZRColaComposerPanel(wnd->m_panel).Restore();
return r;
return wxPersistentTLW::Restore();
}

View File

@ -39,7 +39,7 @@ bool wxZRColaKeyHandler::ProcessEvent(wxEvent& event)
if (e.GetKeyCode() == WXK_INSERT) {
// Insert key has been pressed.
m_is_insert = true;
wxFrame *pFrame = wxDynamicCast(((ZRColaApp*)wxTheApp)->m_mainWnd, wxFrame);
wxFrame *pFrame = wxDynamicCast(dynamic_cast<ZRColaApp*>(wxTheApp)->m_mainWnd, wxFrame);
if (pFrame && pFrame->GetStatusBar())
pFrame->SetStatusText(_("INS key is pressed. Type the Unicode code of desired character now (up to four hexadecimal digits: 0-9, A-F), then release INS."));
} else if (m_is_insert) {
@ -49,7 +49,7 @@ bool wxZRColaKeyHandler::ProcessEvent(wxEvent& event)
if (WXK_NUMPAD0 <= key && key <= WXK_NUMPAD9)
chr = '0' + (key - WXK_NUMPAD0);
}
wxFrame *pFrame = wxDynamicCast(((ZRColaApp*)wxTheApp)->m_mainWnd, wxFrame);
wxFrame *pFrame = wxDynamicCast(dynamic_cast<ZRColaApp*>(wxTheApp)->m_mainWnd, wxFrame);
if (('0' <= chr && chr <= '9' || 'A' <= chr && chr <= 'F') && m_insert_seq.size() < 4) {
// A hex-digit pressed. Save it.
m_insert_seq.push_back((char)chr);
@ -73,7 +73,7 @@ bool wxZRColaKeyHandler::ProcessEvent(wxEvent& event)
#endif
)
{
ZRColaApp *app = (ZRColaApp*)wxTheApp;
auto app = dynamic_cast<ZRColaApp*>(wxTheApp);
ZRCola::keyseq_db::indexKey::size_type start;
bool found;
wxFrame *pFrame = wxDynamicCast(app->m_mainWnd, wxFrame);
@ -143,7 +143,7 @@ bool wxZRColaKeyHandler::ProcessEvent(wxEvent& event)
wxKeyEvent &e = (wxKeyEvent&)event;
if (m_is_insert && e.GetKeyCode() == WXK_INSERT) {
// Insert key has been depressed.
wxFrame *pFrame = wxDynamicCast(((ZRColaApp*)wxTheApp)->m_mainWnd, wxFrame);
wxFrame *pFrame = wxDynamicCast(dynamic_cast<ZRColaApp*>(wxTheApp)->m_mainWnd, wxFrame);
if (pFrame && pFrame->GetStatusBar())
pFrame->SetStatusText(wxEmptyString);

View File

@ -29,7 +29,7 @@ wxZRColaSettings::wxZRColaSettings(wxWindow* parent) :
m_lang(ZRCola::langid_t::blank),
wxZRColaSettingsBase(parent)
{
ZRColaApp *app = ((ZRColaApp*)wxTheApp);
auto app = dynamic_cast<ZRColaApp*>(wxTheApp);
m_languages->Clear();
for (size_t i = 0, n = app->m_lang_db.idxLng.size(); i < n; i++) {
const auto &lang = app->m_lang_db.idxLng[i];
@ -57,7 +57,7 @@ void wxZRColaSettings::OnInitDialog(wxInitDialogEvent& event)
m_languages->Enable(!m_lang_auto);
(m_lang_auto ? m_langAuto : m_langManual)->SetValue(true);
ZRColaApp *app = ((ZRColaApp*)wxTheApp);
auto app = dynamic_cast<ZRColaApp*>(wxTheApp);
char l[sizeof(ZRCola::language_db::language)] = {};
((ZRCola::language_db::language*)l)->id = m_lang;
ZRCola::language_db::indexLang::size_type start;
@ -121,7 +121,7 @@ void wxZRColaSettings::OnApplyButtonClick(wxCommandEvent& event)
} else {
m_lang_auto = false;
ZRColaApp *app = ((ZRColaApp*)wxTheApp);
auto app = dynamic_cast<ZRColaApp*>(wxTheApp);
const auto &lang = app->m_lang_db.idxLng[m_languages->GetSelection()];
if (m_lang != lang.id) {
@ -155,7 +155,7 @@ void wxPersistentZRColaSettings::Save() const
{
wxPersistentDialog::Save();
const wxZRColaSettings * const wnd = static_cast<const wxZRColaSettings*>(GetWindow());
auto wnd = static_cast<const wxZRColaSettings*>(GetWindow()); // dynamic_cast is not reliable as we are typically called late in the wxTopLevelWindowMSW destructor.
SaveValue(wxT("langAuto"), wnd->m_lang_auto);
SaveValue(wxT("lang" ), wxString::FromAscii(wnd->m_lang.data, _countof(wnd->m_lang.data)));
@ -164,9 +164,8 @@ void wxPersistentZRColaSettings::Save() const
bool wxPersistentZRColaSettings::Restore()
{
wxZRColaSettings * const wnd = static_cast<wxZRColaSettings*>(GetWindow());
ZRColaApp *app = ((ZRColaApp*)wxTheApp);
auto wnd = dynamic_cast<wxZRColaSettings*>(GetWindow());
auto app = dynamic_cast<ZRColaApp*>(wxTheApp);
wxString lang;
// Restore automatic language detection setting first.

View File

@ -40,7 +40,7 @@ wxZRColaUpdater::wxZRColaUpdater(wxWindow* parent) :
//Connect(wxID_ANY, wxEVT_UPDATER_CHECK_COMPLETE, wxThreadEventHandler(wxZRColaUpdater::OnCheckComplete), NULL, this);
// Prepare Updater.
ZRColaApp *app = (ZRColaApp*)wxTheApp;
auto app = dynamic_cast<ZRColaApp*>(wxTheApp);
m_updater = new wxUpdCheckThread(app->m_locale.GetCanonicalName(), this);
//if (m_updater->Run() != wxTHREAD_NO_ERROR) {
// wxFAIL_MSG(wxT("Can't create the thread!"));
@ -95,7 +95,7 @@ void wxZRColaUpdater::OnUpdate(wxCommandEvent& event)
m_updater->LaunchUpdate();
Close(true);
((ZRColaApp*)wxTheApp)->m_mainWnd->Close();
dynamic_cast<ZRColaApp*>(wxTheApp)->m_mainWnd->Close();
}
}
}