|
|
nono 0.3.0
//
// nono
// Copyright (C) 2020 nono project
// Licensed under nono-license.txt
//
//
// 履歴モニタ
//
#include "wxhistmonitor.h"
#include "wxtextscreen.h"
//
// 履歴モニタ (共通部分)
//
// イベントテーブル
wxBEGIN_EVENT_TABLE(WXHistoryMonitor, inherited)
EVT_SIZE(WXHistoryMonitor::OnSize)
wxEND_EVENT_TABLE()
// コンストラクタ
WXHistoryMonitor::WXHistoryMonitor(wxWindow *parent, const wxString& name,
Monitor& monitor_)
: inherited(parent, wxID_ANY, name)
{
// →
// +------------+---------+
// | TextScreen | VScroll |
// +------------+---------+
wxBoxSizer *topsizer = new wxBoxSizer(wxHORIZONTAL);
// テキストスクリーン
screen = new WXTextScreen(this, monitor_);
topsizer->Add(screen, 1, wxEXPAND);
// スクロールバー
vscroll = new WXScrollBar(this, wxID_ANY, wxSB_VERTICAL);
topsizer->Add(vscroll, 0, wxEXPAND);
SetSizer(topsizer);
// ウィンドウサイズを確定させる
DoSize();
// スクロールのために (パネル領域での) MouseWheel イベントもここで
// 受け取りたい。スクロールバー上のマウスホイール操作はスクロールバーが
// 処理しているので問題ないが、パネル領域でのマウスホイール操作はここ
// (wxFrame)ではなくパネルに対して飛んでくる。
// ここで一緒に処理したほうが楽なので、こちらに回す。
screen->Connect(wxEVT_MOUSEWHEEL,
wxMouseEventHandler(WXHistoryMonitor::OnMouseWheel), NULL, this);
// スクロールバーからの位置変更通知
vscroll->Connect(NONO_EVT_SCROLL,
wxScrollEventHandler(WXHistoryMonitor::OnScroll), NULL, this);
}
// デストラクタ
WXHistoryMonitor::~WXHistoryMonitor()
{
}
// サイズ変更イベント
void
WXHistoryMonitor::OnSize(wxSizeEvent& event)
{
inherited::OnSize(event);
// スクロールバーを再設定
int pos = (int)screen->GetUserData();
int thumbsize = screen->GetRow() - 1; // 常にヘッダ1行表示している
int range = 256; // XXX 拾ってくるべき
int pagesize = thumbsize - 1;
if (pos > range - thumbsize) {
pos = range - thumbsize;
}
vscroll->SetScrollParam(pos, thumbsize, range, pagesize);
}
// マウスホイールイベント (WXTextScreen 上で起きたやつをこっちに回してある)
void
WXHistoryMonitor::OnMouseWheel(wxMouseEvent& event)
{
// GetWheelRotation() は上(奥)向きに回すと +120、下(手前)に回すと -120。
// どこの決まりか知らんけど、スクロールバーのほうはホイール1段階で3行
// スクロールするのでそれに合わせる。
int pos = (int)screen->GetUserData();
pos = pos - event.GetWheelRotation() / 40;
int maxpos = vscroll->GetRange() - vscroll->GetThumbSize();
if (pos < 0)
pos = 0;
if (pos > maxpos)
pos = maxpos;
DoScroll(pos);
// スクロールバーの位置を追従
vscroll->SetThumbPosition(pos);
}
// スクロールバーからの通知イベント
void
WXHistoryMonitor::OnScroll(wxScrollEvent& event)
{
DoScroll(event.GetPosition());
}
// スクロール処理 (OnScroll() と OnMouseWheel() から呼ばれる)
void
WXHistoryMonitor::DoScroll(int pos)
{
// BranchHistory モニタは userdata が表示開始位置になっている
screen->SetUserData(pos);
}
//
// ブランチ履歴モニタ
//
// コンストラクタ
WXBranchHistoryMonitor::WXBranchHistoryMonitor(wxWindow *parent,
Monitor& monitor)
: inherited(parent, _("Branch History"), monitor)
{
}
// デストラクタ
WXBranchHistoryMonitor::~WXBranchHistoryMonitor()
{
}
//
// 例外履歴モニタ
//
// コンストラクタ
WXExceptionHistoryMonitor::WXExceptionHistoryMonitor(wxWindow *parent,
Monitor& monitor)
: inherited(parent, _("Exception History"), monitor)
{
}
// デストラクタ
WXExceptionHistoryMonitor::~WXExceptionHistoryMonitor()
{
}
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.