--- nono/wx/wxlogmonitor.cpp 2026/04/29 17:04:53 1.1.1.6 +++ nono/wx/wxlogmonitor.cpp 2026/04/29 17:04:56 1.1.1.7 @@ -19,15 +19,18 @@ wxBEGIN_EVENT_TABLE(WXLogMonitor, inheri wxEND_EVENT_TABLE() // コンストラクタ -WXLogMonitor::WXLogMonitor(wxWindow *parent, wxWindowID id) - : inherited(parent, id, _("Log")) +WXLogMonitor::WXLogMonitor(wxWindow *parent) + : inherited(parent, wxID_ANY, _("Log")) { col = 80; row = 40; - // バックログは今の所固定長 - logbuf.Init(col, backlog); - logbuf.Mode = TextScreen::Ring; + monitor.obj = &log; + monitor.func = (MonitorCallback_t)&LogMonitor::MonitorUpdate; + monitor.SetSize(col, row); + // プライベート利用なので Regist() は不要 + + log.Init(this); // → // +--+-----------------------+--+--+ @@ -55,7 +58,7 @@ WXLogMonitor::WXLogMonitor(wxWindow *par // 確定させる。DoSize() 参照。 padding1 = new WXPaddingPanel(this); padding2 = new WXPaddingPanel(this); - screen = new WXTextScreen(this, *this); + screen = new WXTextScreen(this, monitor); vbox->Add(padding1, 0, wxEXPAND); vbox->Add(screen, 1, wxEXPAND); vbox->Add(padding2, 0, wxEXPAND); @@ -112,8 +115,7 @@ WXLogMonitor::SetScroll() int range; int pagesize; - const wxSize& size = screen->GetSize(); - row = size.GetHeight(); + row = screen->GetRow(); if (lines <= row) { pos = 0; @@ -185,25 +187,43 @@ WXLogMonitor::DoScroll(int pos) vscroll->SetThumbPosition(pos); } -// モニターサイズ取得 -nnSize -WXLogMonitor::GetMonitorSize() +// +// モニターオブジェクト +// + +// コンストラクタ +LogMonitor::LogMonitor() + : inherited("LogMonitor") +{ +} + +// デストラクタ +LogMonitor::~LogMonitor() { - return nnSize(col, row); +} + +void +LogMonitor::Init(WXLogMonitor *parent_) +{ + parent = parent_; + + // バックログは今の所固定長 + logbuf.Init(parent->col, backlog); + logbuf.Mode = TextScreen::Ring; } // モニターテキストを更新 void -WXLogMonitor::MonitorUpdate(TextScreen& text) +LogMonitor::MonitorUpdate(Monitor *, TextScreen& screen) { char buf[1024]; // どこでどうするかはあるけど、 // とりあえず row は常に現在の TextScreen の高さということにしておく - row = text.GetRow(); + parent->row = screen.GetRow(); // XXX: 生成時にやるべき - text.Mode = TextScreen::Ring; + screen.Mode = TextScreen::Ring; // キューから読めるだけバックログに書き込む。 // 読めるだけと言っても while ループで読めるだけ読んでしまうと、 @@ -211,53 +231,53 @@ WXLogMonitor::MonitorUpdate(TextScreen& // (可能性としては) あるので、適当に1画面分くらいで打ち切る。 // 取り込み残した分は次回取り込まれるし、その流速も上回るようだと // どのみち gLogger の固定長キューで落ちる。 - for (int i = 0; i < row; i++) { + for (int i = 0; i < parent->row; i++) { if (gLogger.Read(buf, sizeof(buf)) == false) break; Append(buf); } - text.Clear(); + screen.Clear(); // スクロールバー(vpos)による表示位置計算 // vpos は行数、v は logbuf の Y 座標 - int v = cursor - vpos; + int v = cursor - parent->vpos; if (v < 0) { v += backlog; } // 表示位置(v)の Row 行分手前から順に表示 - int srcY = v - row; + int srcY = v - parent->row; if (srcY < 0) { srcY += backlog; } // 画面コピー logbuf.Locate(0, srcY); - for (int i = 0; i < col * row; i++) { - text.Putc(logbuf.Getc()); + for (int i = 0; i < parent->col * parent->row; i++) { + screen.Putc(logbuf.Getc()); } } // 1行追加された時の共通処理 void -WXLogMonitor::IncLines() +LogMonitor::IncLines() { // スクロールバーが下端にない時(バックログを見ている時)は // ログが追加されても現在位置をキープする。 - if (vpos > 0) { + if (parent->vpos > 0) { // 上端に達したら増加させない - if (vpos < backlog - vscroll->GetThumbSize()) { - vpos++; + if (parent->vpos < backlog - parent->vscroll->GetThumbSize()) { + parent->vpos++; } } // 有効行数を増やす - if (lines < backlog) { - lines++; + if (parent->lines < backlog) { + parent->lines++; // 行数が変わったのでスクロールバーを更新 - SetScroll(); + parent->SetScroll(); } } @@ -281,7 +301,7 @@ WXLogMonitor::IncLines() // | // +------------------------ void -WXLogMonitor::Append(const char *utfbuf) +LogMonitor::Append(const char *utfbuf) { const char *sjis; const char *s; @@ -298,7 +318,7 @@ WXLogMonitor::Append(const char *utfbuf) // 代わりに1文字空白を入れる (それによってこの後改行が起きる) if (SJIS::IsZenkaku(*s)) { // 漢字ならば 2 バイトセットで扱う - if (logbuf.GetX() >= col - 1) { + if (logbuf.GetX() >= parent->col - 1) { // 最終桁には出せないので空白で次の行に送る logbuf.Putc(' '); IncLines();