--- nono/util/viewcgrom/viewcgrom.cpp 2026/04/29 17:04:52 1.1.1.2 +++ nono/util/viewcgrom/viewcgrom.cpp 2026/04/29 17:05:40 1.1.1.7 @@ -4,12 +4,16 @@ // Copyright (C) 2012-2019 isaki@NetBSD.org // -#include +#include "wxheader.h" +PRAGMA_PUSH_WARNINGS #include #include #include #include #include +PRAGMA_POP_WARNINGS +#include +#include #define TITLE wxT("X680x0 CGROMビューア") #define COPYRIGHT wxT("Copyright (C) 2012-2019 isaki@NetBSD.org") @@ -29,10 +33,6 @@ #define ROUND(x, y) (((x) + (y - 1)) / (y)) #define ROUND8(x) ROUND(x, 8) -/* 独自のイベントタイプ */ -DECLARE_EVENT_TYPE(WXEVT_CREATE, -1); -DEFINE_EVENT_TYPE(WXEVT_CREATE); - class MyFrame; struct ctxmenu_t { @@ -53,7 +53,7 @@ class ViewCtrl : public wxWindow unsigned char *imagebuf; private: void OnPaint(wxPaintEvent& event); - DECLARE_EVENT_TABLE(); + wxDECLARE_EVENT_TABLE(); }; class MyFrame : public wxFrame @@ -63,7 +63,7 @@ class MyFrame : public wxFrame MyFrame(); private: - void OnCreate(wxCommandEvent& event); + void OnWindowCreate(wxWindowCreateEvent& event); void OnOpen(wxCommandEvent& event); void DoOpenDialog(); void DoOpen(); @@ -105,13 +105,13 @@ class MyFrame : public wxFrame static ctxmenu_t ctxmenu[]; - DECLARE_EVENT_TABLE(); + wxDECLARE_EVENT_TABLE(); }; class MyApp : public wxApp { public: - virtual bool OnInit(); + bool OnInit() override; wxString filename; private: @@ -119,7 +119,10 @@ class MyApp : public wxApp static const wxCmdLineEntryDesc desc[]; }; +// IMPLEMENT_APP() は闇マクロすぎて clang のちからには耐えられない +PRAGMA_PUSH_WARNINGS IMPLEMENT_APP(MyApp) +PRAGMA_POP_WARNINGS // --- @@ -175,7 +178,7 @@ bool MyApp::OnInit() } // イベントテーブル -BEGIN_EVENT_TABLE(MyFrame, inherited) +wxBEGIN_EVENT_TABLE(MyFrame, inherited) EVT_CONTEXT_MENU(MyFrame::OnContextMenu) EVT_MENU(ID_RELOAD, MyFrame::OnReload) EVT_UPDATE_UI(ID_RELOAD, MyFrame::OnReloadUI) @@ -193,8 +196,8 @@ BEGIN_EVENT_TABLE(MyFrame, inherited) EVT_MENU(wxID_OPEN, MyFrame::OnOpen) EVT_MENU(wxID_EXIT, MyFrame::OnExit) EVT_MENU(wxID_ABOUT, MyFrame::OnAbout) - EVT_COMMAND(wxID_ANY, WXEVT_CREATE, MyFrame::OnCreate) -END_EVENT_TABLE() + EVT_WINDOW_CREATE(MyFrame::OnWindowCreate) +wxEND_EVENT_TABLE() // ショートカット用データ struct ctxmenu_t MyFrame::ctxmenu[] = { @@ -317,14 +320,13 @@ MyFrame::MyFrame() line = -1; DoUpdateAddr(); - /* すぐに OnCreate を呼ぶように仕掛けておく */ - wxCommandEvent event(WXEVT_CREATE); - AddPendingEvent(event); + Connect(wxEVT_CREATE, + wxWindowCreateEventHandler(MyFrame::OnWindowCreate), NULL, this); } -// ウィンドウ作成イベントのつもり +// ウィンドウ作成イベント void -MyFrame::OnCreate(wxCommandEvent& event) +MyFrame::OnWindowCreate(wxWindowCreateEvent& event) { if (!::wxGetApp().filename.IsEmpty()) { /* 引数でファイルが指定されていればそれを使う */ @@ -333,6 +335,10 @@ MyFrame::OnCreate(wxCommandEvent& event) /* ファイルオープン */ DoOpen(); } + + // 一度処理したら抜いておく (こうしないと複数回呼ばれる) + Disconnect(wxEVT_CREATE, + wxWindowCreateEventHandler(MyFrame::OnWindowCreate)); } // オープン @@ -624,7 +630,7 @@ bool MyFrame::CreateImage() { unsigned char *imagebuf; - unsigned char buf[bytes]; + std::vector buf(bytes); size_t n; int minus_addr; @@ -652,7 +658,7 @@ MyFrame::CreateImage() &imagebuf[((view.x * bdsz.y) * cy + bdsz.x * cx) * 3]; /* ファイルオフセットが正なら1文字分読み込み */ if (minus_addr >= 0) { - n = file.Read(buf, bytes); + n = file.Read(buf.data(), buf.size()); } else { /* 負なら0バイト読んだことにしてカウントだけする */ /* 文字の途中でプラスに転じるケースは面倒なので無視 */ @@ -702,9 +708,9 @@ MyFrame::CreateImage() } // イベントテーブル -BEGIN_EVENT_TABLE(ViewCtrl, inherited) +wxBEGIN_EVENT_TABLE(ViewCtrl, inherited) EVT_PAINT(ViewCtrl::OnPaint) -END_EVENT_TABLE() +wxEND_EVENT_TABLE() // コンストラクタ ViewCtrl::ViewCtrl(wxWindow *parent)