--- nono/wx/wxhistmonitor.cpp 2026/04/29 17:04:39 1.1 +++ nono/wx/wxhistmonitor.cpp 2026/04/29 17:05:09 1.1.1.5 @@ -4,7 +4,12 @@ // Licensed under nono-license.txt // +// +// 履歴モニタ +// + #include "wxhistmonitor.h" +#include "wxtextscreen.h" // // 履歴モニタ (共通部分) @@ -13,51 +18,26 @@ // イベントテーブル wxBEGIN_EVENT_TABLE(WXHistoryMonitor, inherited) EVT_SIZE(WXHistoryMonitor::OnSize) - EVT_SCROLL(WXHistoryMonitor::OnScroll) wxEND_EVENT_TABLE() // コンストラクタ -WXHistoryMonitor::WXHistoryMonitor(wxWindow *parent, wxWindowID id, - const wxString& name, IMonitor& monitor_) - : inherited(parent, id, name) +WXHistoryMonitor::WXHistoryMonitor(wxWindow *parent, const wxString& name, + Monitor& monitor_) + : inherited(parent, wxID_ANY, name) { // → - // +--+-----------------------+--+--+ - // | |↓+------------------+ | | | - // | | | 上余白(padding1) | | | | - // |左| +------------------+ |右| | - // |余| | TextScreen | |余| <- VScroll - // |白| +------------------+ |白| | - // | | | 下余白(padding2) | | | | - // | | +------------------+ | | | - // +--+-----------------------+--+--+ - - topsizer = new wxBoxSizer(wxHORIZONTAL); - // 左余白 - topsizer->AddSpacer(DefaultPadding); - // 中列の縦 sizer - auto *vbox = new wxBoxSizer(wxVERTICAL); - topsizer->Add(vbox, 0, wxEXPAND); - - // パディングパネル(上下) - // ウィンドウを1行ずつ伸縮させるためには、クライアント領域がフォント高さの - // 整数倍になってないといけない。TextScreen はそれ自身が行の整数倍の大きさ - // だが、上下の余白はその時点のフォントサイズによって変更する必要がある。 - // 先にサイズ不定のパネルだけ置いといて、フォントサイズ確定後に大きさを - // 確定させる。DoSize() 参照。 - padding1 = new wxPanel(this, wxID_ANY); - padding2 = new wxPanel(this, wxID_ANY); - vbox->Add(padding1); - screen = new WXTextScreen(this, monitor_); - vbox->Add(screen, 1, wxEXPAND); - vbox->Add(padding2); + // +------------+---------+ + // | TextScreen | VScroll | + // +------------+---------+ - // 右余白 - topsizer->AddSpacer(DefaultPadding); + wxBoxSizer *topsizer = new wxBoxSizer(wxHORIZONTAL); + + // テキストスクリーン + screen = new WXTextScreen(this, monitor_); + topsizer->Add(screen, 1, wxEXPAND); // スクロールバー - vscroll = new wxScrollBar(this, wxID_ANY, wxDefaultPosition, - wxDefaultSize, wxSB_VERTICAL); + vscroll = new WXScrollBar(this, wxID_ANY, wxSB_VERTICAL); topsizer->Add(vscroll, 0, wxEXPAND); SetSizer(topsizer); @@ -66,12 +46,16 @@ WXHistoryMonitor::WXHistoryMonitor(wxWin DoSize(); // スクロールのために (パネル領域での) MouseWheel イベントもここで - // 受け取りたい。スクロールバー上のマウスホイール操作は最初から Scroll - // イベントとして処理されているので問題ないが、パネル領域でのマウス - // ホイール操作はここ(wxFrame)ではなくパネルに対して飛んでくる。 + // 受け取りたい。スクロールバー上のマウスホイール操作はスクロールバーが + // 処理しているので問題ないが、パネル領域でのマウスホイール操作はここ + // (wxFrame)ではなくパネルに対して飛んでくる。 // ここで一緒に処理したほうが楽なので、こちらに回す。 screen->Connect(wxEVT_MOUSEWHEEL, wxMouseEventHandler(WXHistoryMonitor::OnMouseWheel), NULL, this); + + // スクロールバーからの位置変更通知 + vscroll->Connect(NONO_EVT_SCROLL, + wxScrollEventHandler(WXHistoryMonitor::OnScroll), NULL, this); } // デストラクタ @@ -79,13 +63,6 @@ WXHistoryMonitor::~WXHistoryMonitor() { } -// フォントサイズが確定したら、それによってウィンドウサイズを再計算する。 -void -WXHistoryMonitor::DoSize() -{ - CalcVSize(0); -} - // サイズ変更イベント void WXHistoryMonitor::OnSize(wxSizeEvent& event) @@ -94,14 +71,13 @@ WXHistoryMonitor::OnSize(wxSizeEvent& ev // スクロールバーを再設定 int pos = (int)screen->GetUserData(); - const wxSize& size = screen->GetSize(); - int thumbsize = size.GetHeight() - 1; // 常にヘッダ1行表示している + int thumbsize = screen->GetRow() - 1; // 常にヘッダ1行表示している int range = 256; // XXX 拾ってくるべき int pagesize = thumbsize - 1; if (pos > range - thumbsize) { pos = range - thumbsize; } - vscroll->SetScrollbar(pos, thumbsize, range, pagesize); + vscroll->SetScrollParam(pos, thumbsize, range, pagesize); } // マウスホイールイベント (WXTextScreen 上で起きたやつをこっちに回してある) @@ -121,9 +97,11 @@ WXHistoryMonitor::OnMouseWheel(wxMouseEv pos = maxpos; DoScroll(pos); + // スクロールバーの位置を追従 + vscroll->SetThumbPosition(pos); } -// スクロールイベント (全部入り) +// スクロールバーからの通知イベント void WXHistoryMonitor::OnScroll(wxScrollEvent& event) { @@ -135,21 +113,19 @@ void WXHistoryMonitor::DoScroll(int pos) { // BranchHistory モニタは userdata が表示開始位置になっている - screen->SetUserData(exflag | pos); - vscroll->SetThumbPosition(pos); + screen->SetUserData(pos); } + // // ブランチ履歴モニタ // // コンストラクタ -WXBranchHistoryMonitor::WXBranchHistoryMonitor(wxWindow *parent, wxWindowID id, - IMonitor& monitor) - : inherited(parent, id, _("Branch History"), monitor) +WXBranchHistoryMonitor::WXBranchHistoryMonitor(wxWindow *parent, + Monitor& monitor) + : inherited(parent, _("Branch History"), monitor) { - exflag = 0; - screen->SetUserData(exflag); } // デストラクタ @@ -157,17 +133,16 @@ WXBranchHistoryMonitor::~WXBranchHistory { } + // // 例外履歴モニタ // // コンストラクタ WXExceptionHistoryMonitor::WXExceptionHistoryMonitor(wxWindow *parent, - wxWindowID id, IMonitor& monitor) - : inherited(parent, id, _("Exception History"), monitor) + Monitor& monitor) + : inherited(parent, _("Exception History"), monitor) { - exflag = 1ULL << 63; - screen->SetUserData(exflag); } // デストラクタ