--- nono/wx/wxlogmonitor.h 2026/04/29 17:04:28 1.1.1.1 +++ nono/wx/wxlogmonitor.h 2026/04/29 17:05:44 1.1.1.11 @@ -1,49 +1,112 @@ // // nono -// Copyright (C) 2018 isaki@NetBSD.org +// Copyright (C) 2020 nono project +// Licensed under nono-license.txt +// + +// +// ログモニター // #pragma once #include "wxsubwindow.h" -#include "wxtextscreen.h" +#include "wxscrollbar.h" +#include "wxmonitor.h" -class WXLogMonitor : public WXSubWindow -{ - typedef WXSubWindow inherited; +class Logger; +class WXLogMonitor; +// モニター部分 +class LogMonitor : public Object +{ + using inherited = Object; public: - WXLogMonitor(wxWindow *, wxWindowID); - virtual ~WXLogMonitor(); + LogMonitor(); + ~LogMonitor() override; - virtual void SetFontSize(fontsize_t fontsize); + void Init(WXLogMonitor *parent_); - private: - void OnTimer(wxTimerEvent& event); + DECLARE_MONITOR_CALLBACK(MonitorUpdate); + // バックログに追加 void Append(const char *); - // テキストスクリーンコントロール - WXTextScreen *screen = NULL; + // 1行追加された時の下請け処理 + void IncLines(); - // テキストスクリーン - TextScreen text; + private: + WXLogMonitor *parent {}; - int col = 0; - int row = 0; + Logger *logger {}; + + // ログ全体の行数(上限) + const int backlog = 10000; // ログバッファ - // ここは属性フィールドを持たないテキストによる循環バッファ - uint8 *logbuf = NULL; + TextScreen logbuf {}; - // 書き込み位置 - int target = 0; + // 今から書き込む行の logbuf でのY座標 + int cursor {}; // UTF-8 -> CP932 変換 wxCSConv conv { "CP932" }; +}; + +// ログウィンドウ +class WXLogMonitor : public WXSubWindow +{ + using inherited = WXSubWindow; + friend class LogMonitor; + + public: + explicit WXLogMonitor(wxWindow *); + ~WXLogMonitor() override; + + void FontChanged() override; + bool Layout() override; + + private: + void Fit() override; + + // 最大/最小サイズ設定 + wxSize DoSizeHints(); + + // マウスホイールイベント + void OnMouseWheel(wxMouseEvent&); + + // スクロールイベント + void OnScroll(wxScrollEvent&); + + // スクロールバー再設定 + void SetScroll(); + + // スクロール処理 + void DoScroll(int pos); + + WXMonitorPanel *screen {}; + + // スクロールバー + WXScrollBar *vscroll {}; + + int col {}; + int row {}; + + // 表示開始位置 + // パネル最下行に表示する行を、最新行からのオフセットで表す。 + // 0 ならパネル最下行は最新行、1 なら一つ手前の行…となる。 + int vpos {}; + + // 現在のログ行数 + int lines {}; + + // モニター + std::unique_ptr monitor /*{}*/; + LogMonitor log {}; - wxTimer timer; + // 前回のウィンドウマージン (クライアント領域の外側) + wxSize oldmargin {}; - // イベントテーブル - wxDECLARE_EVENT_TABLE(); + // 謎のリサイズ対策 + bool layout_pass2 {}; };