--- nono/util/viewcgrom/viewcgrom.cpp 2026/04/29 17:04:28 1.1 +++ nono/util/viewcgrom/viewcgrom.cpp 2026/04/29 17:05:58 1.1.1.8 @@ -1,18 +1,22 @@ // // X680x0 CGROM ビューア // -// Copyright (C) 2012-2019 isaki@NetBSD.org +// Copyright (C) 2012-2019 Tetsuya Isaki // -#include +#include "wxheader.h" +PRAGMA_PUSH_WARNINGS #include #include #include #include #include +PRAGMA_POP_WARNINGS +#include +#include -#define TITLE "X680x0 CGROMビューア" -#define COPYRIGHT "Copyright (C) 2012-2019 isaki@NetBSD.org" +#define TITLE wxT("X680x0 CGROMビューア") +#define COPYRIGHT wxT("Copyright (C) 2012-2019 Tetsuya Isaki") /* CGROM.DAT の大きさ(バイト単位) */ #define CGROM_SIZE (768 * 1024) @@ -29,16 +33,12 @@ #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 { int id; int addr; - const char *label; + wxString label; int size; }; @@ -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,18 +196,18 @@ 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[] = { - { ID_FONT_16x16, 0x00000, "16x16フォント", SIZE_16x16, }, - { ID_FONT_8x8, 0x3a000, "8x8フォント", SIZE_8x8, }, - { ID_FONT_8x16, 0x3a800, "8x16フォント", SIZE_8x16, }, - { ID_FONT_12x12, 0x3b800, "12x12フォント", SIZE_12x12, }, - { ID_FONT_12x24, 0x3d000, "12x24フォント", SIZE_12x24, }, - { ID_FONT_24x24, 0x40000, "24x24フォント", SIZE_24x24, }, - { ID_FONT_6x12, 0xbf400, "6x12フォント", SIZE_6x12, }, + { ID_FONT_16x16, 0x00000, wxT("16x16フォント"), SIZE_16x16, }, + { ID_FONT_8x8, 0x3a000, wxT("8x8フォント"), SIZE_8x8, }, + { ID_FONT_8x16, 0x3a800, wxT("8x16フォント"), SIZE_8x16, }, + { ID_FONT_12x12, 0x3b800, wxT("12x12フォント"), SIZE_12x12, }, + { ID_FONT_12x24, 0x3d000, wxT("12x24フォント"), SIZE_12x24, }, + { ID_FONT_24x24, 0x40000, wxT("24x24フォント"), SIZE_24x24, }, + { ID_FONT_6x12, 0xbf400, wxT("6x12フォント"), SIZE_6x12, }, }; // コンストラクタ @@ -255,24 +258,24 @@ MyFrame::MyFrame() ctrlbox->Add(new wxStaticText(panel, wxID_ANY, wxT("開始アドレス"))); /* 開始アドレス(コントロール) */ - addrctrl = new wxTextCtrl(panel, ID_ADDRBOX, "", + addrctrl = new wxTextCtrl(panel, ID_ADDRBOX, wxT(""), wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER); ctrlbox->Add(addrctrl); ctrlbox->AddSpacer(5); /* フォントサイズ */ - ctrlbox->Add(new wxStaticText(panel, wxID_ANY, "フォントサイズ")); + ctrlbox->Add(new wxStaticText(panel, wxID_ANY, wxT("フォントサイズ"))); /* フォントサイズ(コントロール) */ wxString sizelist[] = { - "8x8", - "8x16", - "12x12", - "12x24", - "16x16", - "24x24", - "6x12", + wxT("8x8"), + wxT("8x16"), + wxT("12x12"), + wxT("12x24"), + wxT("16x16"), + wxT("24x24"), + wxT("6x12"), }; sizectrl = new wxChoice(panel, ID_SIZEBOX, wxDefaultPosition, wxDefaultSize, @@ -288,7 +291,7 @@ MyFrame::MyFrame() ctxmenu_t *c = &ctxmenu[i]; wxString label; - label.Printf("%05X: ", c->addr); + label.Printf(wxT("%05X: "), c->addr); label += c->label; wxButton *btn = new wxButton(panel, c->id, label, wxDefaultPosition, wxDefaultSize, wxBU_LEFT); @@ -297,14 +300,14 @@ MyFrame::MyFrame() ctrlbox->AddSpacer(5); ctrlbox->Add(new wxStaticText(panel, wxID_ANY, - "(6x12 フォントは\nX68030 のみ)")); + wxT("(6x12 フォントは\nX68030 のみ)"))); panel->SetSizer(hbox); hbox->SetSizeHints(this); /* コンテキストメニュー */ menu = new wxMenu(); - menu->Append(ID_RELOAD, "リロード"); + menu->Append(ID_RELOAD, wxT("リロード")); /* 固定地 */ num.x = 16; @@ -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)); } // オープン @@ -347,9 +353,9 @@ MyFrame::OnOpen(wxCommandEvent& event) void MyFrame::DoOpenDialog() { - wxFileDialog dialog(this, "Select a file", + wxFileDialog dialog(this, wxT("Select a file"), ::wxGetCwd(), wxEmptyString, - "DAT files (*.DAT)|*.DAT;*.dat|すべてのファイル (*.*)|*.*"); + wxT("DAT files (*.DAT)|*.DAT;*.dat|すべてのファイル (*.*)|*.*")); if (dialog.ShowModal() != wxID_OK) { return; @@ -381,7 +387,7 @@ MyFrame::DoOpen() /* オープンできたのでタイトルを変更 */ wxString title; title = TITLE; - title += " - "; + title += wxT(" - "); title += filename; SetTitle(title); @@ -401,8 +407,8 @@ MyFrame::OnAbout(wxCommandEvent& event) { wxAboutDialogInfo ab; - ab.SetName("viewcgrom"); - ab.SetVersion("1.1"); + ab.SetName(wxT("viewcgrom")); + ab.SetVersion(wxT("1.1")); ab.SetDescription(TITLE); ab.SetCopyright(COPYRIGHT); @@ -606,7 +612,7 @@ MyFrame::DoUpdateAddr() /* アドレス欄に反映 */ wxString str; - str.Printf("%05X", addr); + str.Printf(wxT("%05X"), addr); addrctrl->SetValue(str); /* スクロールバーに反映 */ @@ -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)