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

1.1       root        1: //
                      2: // nono
                      3: // Copyright (C) 2020 nono project
                      4: // Licensed under nono-license.txt
                      5: //
                      6: 
1.1.1.5 ! root        7: //
        !             8: // 履歴モニタ
        !             9: //
        !            10: 
1.1       root       11: #include "wxhistmonitor.h"
1.1.1.5 ! root       12: #include "wxtextscreen.h"
1.1       root       13: 
                     14: //
                     15: // 履歴モニタ (共通部分)
                     16: //
                     17: 
                     18: // イベントテーブル
                     19: wxBEGIN_EVENT_TABLE(WXHistoryMonitor, inherited)
                     20:        EVT_SIZE(WXHistoryMonitor::OnSize)
                     21: wxEND_EVENT_TABLE()
                     22: 
                     23: // コンストラクタ
1.1.1.3   root       24: WXHistoryMonitor::WXHistoryMonitor(wxWindow *parent, const wxString& name,
                     25:        Monitor& monitor_)
                     26:        : inherited(parent, wxID_ANY, name)
1.1       root       27: {
                     28:        // →
1.1.1.5 ! root       29:        // +------------+---------+
        !            30:        // | TextScreen | VScroll |
        !            31:        // +------------+---------+
1.1       root       32: 
1.1.1.4   root       33:        wxBoxSizer *topsizer = new wxBoxSizer(wxHORIZONTAL);
1.1       root       34: 
1.1.1.5 ! root       35:        // テキストスクリーン
        !            36:        screen = new WXTextScreen(this, monitor_);
        !            37:        topsizer->Add(screen, 1, wxEXPAND);
1.1       root       38: 
                     39:        // スクロールバー
1.1.1.5 ! root       40:        vscroll = new WXScrollBar(this, wxID_ANY, wxSB_VERTICAL);
1.1       root       41:        topsizer->Add(vscroll, 0, wxEXPAND);
                     42: 
                     43:        SetSizer(topsizer);
                     44: 
                     45:        // ウィンドウサイズを確定させる
                     46:        DoSize();
                     47: 
                     48:        // スクロールのために (パネル領域での) MouseWheel イベントもここで
1.1.1.5 ! root       49:        // 受け取りたい。スクロールバー上のマウスホイール操作はスクロールバーが
        !            50:        // 処理しているので問題ないが、パネル領域でのマウスホイール操作はここ
        !            51:        // (wxFrame)ではなくパネルに対して飛んでくる。
1.1       root       52:        // ここで一緒に処理したほうが楽なので、こちらに回す。
                     53:        screen->Connect(wxEVT_MOUSEWHEEL,
                     54:                wxMouseEventHandler(WXHistoryMonitor::OnMouseWheel), NULL, this);
1.1.1.5 ! root       55: 
        !            56:        // スクロールバーからの位置変更通知
        !            57:        vscroll->Connect(NONO_EVT_SCROLL,
        !            58:                wxScrollEventHandler(WXHistoryMonitor::OnScroll), NULL, this);
1.1       root       59: }
                     60: 
                     61: // デストラクタ
                     62: WXHistoryMonitor::~WXHistoryMonitor()
                     63: {
                     64: }
                     65: 
                     66: // サイズ変更イベント
                     67: void
                     68: WXHistoryMonitor::OnSize(wxSizeEvent& event)
                     69: {
                     70:        inherited::OnSize(event);
                     71: 
                     72:        // スクロールバーを再設定
                     73:        int pos = (int)screen->GetUserData();
1.1.1.3   root       74:        int thumbsize = screen->GetRow() - 1; // 常にヘッダ1行表示している
1.1       root       75:        int range = 256;        // XXX 拾ってくるべき
                     76:        int pagesize = thumbsize - 1;
                     77:        if (pos > range - thumbsize) {
                     78:                pos = range - thumbsize;
                     79:        }
1.1.1.5 ! root       80:        vscroll->SetScrollParam(pos, thumbsize, range, pagesize);
1.1       root       81: }
                     82: 
                     83: // マウスホイールイベント (WXTextScreen 上で起きたやつをこっちに回してある)
                     84: void
                     85: WXHistoryMonitor::OnMouseWheel(wxMouseEvent& event)
                     86: {
                     87:        // GetWheelRotation() は上(奥)向きに回すと +120、下(手前)に回すと -120。
                     88:        // どこの決まりか知らんけど、スクロールバーのほうはホイール1段階で3行
                     89:        // スクロールするのでそれに合わせる。
                     90:        int pos = (int)screen->GetUserData();
                     91:        pos = pos - event.GetWheelRotation() / 40;
                     92: 
                     93:        int maxpos = vscroll->GetRange() - vscroll->GetThumbSize();
                     94:        if (pos < 0)
                     95:                pos = 0;
                     96:        if (pos > maxpos)
                     97:                pos = maxpos;
                     98: 
                     99:        DoScroll(pos);
1.1.1.5 ! root      100:        // スクロールバーの位置を追従
        !           101:        vscroll->SetThumbPosition(pos);
1.1       root      102: }
                    103: 
1.1.1.5 ! root      104: // スクロールバーからの通知イベント
1.1       root      105: void
                    106: WXHistoryMonitor::OnScroll(wxScrollEvent& event)
                    107: {
                    108:        DoScroll(event.GetPosition());
                    109: }
                    110: 
                    111: // スクロール処理 (OnScroll() と OnMouseWheel() から呼ばれる)
                    112: void
                    113: WXHistoryMonitor::DoScroll(int pos)
                    114: {
                    115:        // BranchHistory モニタは userdata が表示開始位置になっている
1.1.1.5 ! root      116:        screen->SetUserData(pos);
1.1       root      117: }
                    118: 
1.1.1.5 ! root      119: 
1.1       root      120: //
                    121: // ブランチ履歴モニタ
                    122: //
                    123: 
                    124: // コンストラクタ
1.1.1.3   root      125: WXBranchHistoryMonitor::WXBranchHistoryMonitor(wxWindow *parent,
                    126:        Monitor& monitor)
                    127:        : inherited(parent, _("Branch History"), monitor)
1.1       root      128: {
                    129: }
                    130: 
                    131: // デストラクタ
                    132: WXBranchHistoryMonitor::~WXBranchHistoryMonitor()
                    133: {
                    134: }
                    135: 
1.1.1.5 ! root      136: 
1.1       root      137: //
                    138: // 例外履歴モニタ
                    139: //
                    140: 
                    141: // コンストラクタ
                    142: WXExceptionHistoryMonitor::WXExceptionHistoryMonitor(wxWindow *parent,
1.1.1.3   root      143:        Monitor& monitor)
                    144:        : inherited(parent, _("Exception History"), monitor)
1.1       root      145: {
                    146: }
                    147: 
                    148: // デストラクタ
                    149: WXExceptionHistoryMonitor::~WXExceptionHistoryMonitor()
                    150: {
                    151: }

unix.superglobalmegacorp.com

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