Annotation of nono/wx/wxhistmonitor.cpp, revision 1.1.1.1

1.1       root        1: //
                      2: // nono
                      3: // Copyright (C) 2020 nono project
                      4: // Licensed under nono-license.txt
                      5: //
                      6: 
                      7: #include "wxhistmonitor.h"
                      8: 
                      9: //
                     10: // 履歴モニタ (共通部分)
                     11: //
                     12: 
                     13: // イベントテーブル
                     14: wxBEGIN_EVENT_TABLE(WXHistoryMonitor, inherited)
                     15:        EVT_SIZE(WXHistoryMonitor::OnSize)
                     16:        EVT_SCROLL(WXHistoryMonitor::OnScroll)
                     17: wxEND_EVENT_TABLE()
                     18: 
                     19: // コンストラクタ
                     20: WXHistoryMonitor::WXHistoryMonitor(wxWindow *parent, wxWindowID id,
                     21:        const wxString& name, IMonitor& monitor_)
                     22:        : inherited(parent, id, name)
                     23: {
                     24:        // →
                     25:        // +--+-----------------------+--+--+
                     26:        // |  |↓+------------------+ |  |  |
                     27:        // |  |  | 上余白(padding1) | |  |  |
                     28:        // |左|  +------------------+ |右|  |
                     29:        // |余|  | TextScreen       | |余| <- VScroll
                     30:        // |白|  +------------------+ |白|  |
                     31:        // |  |  | 下余白(padding2) | |  |  |
                     32:        // |  |  +------------------+ |  |  |
                     33:        // +--+-----------------------+--+--+
                     34: 
                     35:        topsizer = new wxBoxSizer(wxHORIZONTAL);
                     36:        // 左余白
                     37:        topsizer->AddSpacer(DefaultPadding);
                     38:        // 中列の縦 sizer
                     39:        auto *vbox = new wxBoxSizer(wxVERTICAL);
                     40:        topsizer->Add(vbox, 0, wxEXPAND);
                     41: 
                     42:        // パディングパネル(上下)
                     43:        // ウィンドウを1行ずつ伸縮させるためには、クライアント領域がフォント高さの
                     44:        // 整数倍になってないといけない。TextScreen はそれ自身が行の整数倍の大きさ
                     45:        // だが、上下の余白はその時点のフォントサイズによって変更する必要がある。
                     46:        // 先にサイズ不定のパネルだけ置いといて、フォントサイズ確定後に大きさを
                     47:        // 確定させる。DoSize() 参照。
                     48:        padding1 = new wxPanel(this, wxID_ANY);
                     49:        padding2 = new wxPanel(this, wxID_ANY);
                     50:        vbox->Add(padding1);
                     51:        screen = new WXTextScreen(this, monitor_);
                     52:        vbox->Add(screen, 1, wxEXPAND);
                     53:        vbox->Add(padding2);
                     54: 
                     55:        // 右余白
                     56:        topsizer->AddSpacer(DefaultPadding);
                     57: 
                     58:        // スクロールバー
                     59:        vscroll = new wxScrollBar(this, wxID_ANY, wxDefaultPosition,
                     60:                wxDefaultSize, wxSB_VERTICAL);
                     61:        topsizer->Add(vscroll, 0, wxEXPAND);
                     62: 
                     63:        SetSizer(topsizer);
                     64: 
                     65:        // ウィンドウサイズを確定させる
                     66:        DoSize();
                     67: 
                     68:        // スクロールのために (パネル領域での) MouseWheel イベントもここで
                     69:        // 受け取りたい。スクロールバー上のマウスホイール操作は最初から Scroll
                     70:        // イベントとして処理されているので問題ないが、パネル領域でのマウス
                     71:        // ホイール操作はここ(wxFrame)ではなくパネルに対して飛んでくる。
                     72:        // ここで一緒に処理したほうが楽なので、こちらに回す。
                     73:        screen->Connect(wxEVT_MOUSEWHEEL,
                     74:                wxMouseEventHandler(WXHistoryMonitor::OnMouseWheel), NULL, this);
                     75: }
                     76: 
                     77: // デストラクタ
                     78: WXHistoryMonitor::~WXHistoryMonitor()
                     79: {
                     80: }
                     81: 
                     82: // フォントサイズが確定したら、それによってウィンドウサイズを再計算する。
                     83: void
                     84: WXHistoryMonitor::DoSize()
                     85: {
                     86:        CalcVSize(0);
                     87: }
                     88: 
                     89: // サイズ変更イベント
                     90: void
                     91: WXHistoryMonitor::OnSize(wxSizeEvent& event)
                     92: {
                     93:        inherited::OnSize(event);
                     94: 
                     95:        // スクロールバーを再設定
                     96:        int pos = (int)screen->GetUserData();
                     97:        const wxSize& size = screen->GetSize();
                     98:        int thumbsize = size.GetHeight() - 1; // 常にヘッダ1行表示している
                     99:        int range = 256;        // XXX 拾ってくるべき
                    100:        int pagesize = thumbsize - 1;
                    101:        if (pos > range - thumbsize) {
                    102:                pos = range - thumbsize;
                    103:        }
                    104:        vscroll->SetScrollbar(pos, thumbsize, range, pagesize);
                    105: }
                    106: 
                    107: // マウスホイールイベント (WXTextScreen 上で起きたやつをこっちに回してある)
                    108: void
                    109: WXHistoryMonitor::OnMouseWheel(wxMouseEvent& event)
                    110: {
                    111:        // GetWheelRotation() は上(奥)向きに回すと +120、下(手前)に回すと -120。
                    112:        // どこの決まりか知らんけど、スクロールバーのほうはホイール1段階で3行
                    113:        // スクロールするのでそれに合わせる。
                    114:        int pos = (int)screen->GetUserData();
                    115:        pos = pos - event.GetWheelRotation() / 40;
                    116: 
                    117:        int maxpos = vscroll->GetRange() - vscroll->GetThumbSize();
                    118:        if (pos < 0)
                    119:                pos = 0;
                    120:        if (pos > maxpos)
                    121:                pos = maxpos;
                    122: 
                    123:        DoScroll(pos);
                    124: }
                    125: 
                    126: // スクロールイベント (全部入り)
                    127: void
                    128: WXHistoryMonitor::OnScroll(wxScrollEvent& event)
                    129: {
                    130:        DoScroll(event.GetPosition());
                    131: }
                    132: 
                    133: // スクロール処理 (OnScroll() と OnMouseWheel() から呼ばれる)
                    134: void
                    135: WXHistoryMonitor::DoScroll(int pos)
                    136: {
                    137:        // BranchHistory モニタは userdata が表示開始位置になっている
                    138:        screen->SetUserData(exflag | pos);
                    139:        vscroll->SetThumbPosition(pos);
                    140: }
                    141: 
                    142: //
                    143: // ブランチ履歴モニタ
                    144: //
                    145: 
                    146: // コンストラクタ
                    147: WXBranchHistoryMonitor::WXBranchHistoryMonitor(wxWindow *parent, wxWindowID id,
                    148:        IMonitor& monitor)
                    149:        : inherited(parent, id, _("Branch History"), monitor)
                    150: {
                    151:        exflag = 0;
                    152:        screen->SetUserData(exflag);
                    153: }
                    154: 
                    155: // デストラクタ
                    156: WXBranchHistoryMonitor::~WXBranchHistoryMonitor()
                    157: {
                    158: }
                    159: 
                    160: //
                    161: // 例外履歴モニタ
                    162: //
                    163: 
                    164: // コンストラクタ
                    165: WXExceptionHistoryMonitor::WXExceptionHistoryMonitor(wxWindow *parent,
                    166:        wxWindowID id, IMonitor& monitor)
                    167:        : inherited(parent, id, _("Exception History"), monitor)
                    168: {
                    169:        exflag = 1ULL << 63;
                    170:        screen->SetUserData(exflag);
                    171: }
                    172: 
                    173: // デストラクタ
                    174: WXExceptionHistoryMonitor::~WXExceptionHistoryMonitor()
                    175: {
                    176: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.