|
|
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: // コンストラクタ
1.1.1.3 ! root 20: WXHistoryMonitor::WXHistoryMonitor(wxWindow *parent, const wxString& name,
! 21: Monitor& monitor_)
! 22: : inherited(parent, wxID_ANY, name)
1.1 root 23: {
24: // →
25: // +--+-----------------------+--+--+
26: // | |↓+------------------+ | | |
27: // | | | 上余白(padding1) | | | |
28: // |左| +------------------+ |右| |
29: // |余| | TextScreen | |余| <- VScroll
30: // |白| +------------------+ |白| |
31: // | | | 下余白(padding2) | | | |
32: // | | +------------------+ | | |
33: // +--+-----------------------+--+--+
34:
35: topsizer = new wxBoxSizer(wxHORIZONTAL);
36: // 左余白
1.1.1.2 root 37: topsizer->Add(new WXPaddingPanel(this), 0, wxEXPAND);
1.1 root 38: // 中列の縦 sizer
39: auto *vbox = new wxBoxSizer(wxVERTICAL);
40: topsizer->Add(vbox, 0, wxEXPAND);
41:
42: // パディングパネル(上下)
43: // ウィンドウを1行ずつ伸縮させるためには、クライアント領域がフォント高さの
44: // 整数倍になってないといけない。TextScreen はそれ自身が行の整数倍の大きさ
45: // だが、上下の余白はその時点のフォントサイズによって変更する必要がある。
46: // 先にサイズ不定のパネルだけ置いといて、フォントサイズ確定後に大きさを
47: // 確定させる。DoSize() 参照。
1.1.1.2 root 48: padding1 = new WXPaddingPanel(this);
49: padding2 = new WXPaddingPanel(this);
1.1 root 50: screen = new WXTextScreen(this, monitor_);
1.1.1.2 root 51: vbox->Add(padding1, 0, wxEXPAND);
1.1 root 52: vbox->Add(screen, 1, wxEXPAND);
1.1.1.2 root 53: vbox->Add(padding2, 0, wxEXPAND);
1.1 root 54:
55: // 右余白
1.1.1.2 root 56: topsizer->Add(new WXPaddingPanel(this), 0, wxEXPAND);
1.1 root 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();
1.1.1.3 ! root 97: int thumbsize = screen->GetRow() - 1; // 常にヘッダ1行表示している
1.1 root 98: int range = 256; // XXX 拾ってくるべき
99: int pagesize = thumbsize - 1;
100: if (pos > range - thumbsize) {
101: pos = range - thumbsize;
102: }
103: vscroll->SetScrollbar(pos, thumbsize, range, pagesize);
104: }
105:
106: // マウスホイールイベント (WXTextScreen 上で起きたやつをこっちに回してある)
107: void
108: WXHistoryMonitor::OnMouseWheel(wxMouseEvent& event)
109: {
110: // GetWheelRotation() は上(奥)向きに回すと +120、下(手前)に回すと -120。
111: // どこの決まりか知らんけど、スクロールバーのほうはホイール1段階で3行
112: // スクロールするのでそれに合わせる。
113: int pos = (int)screen->GetUserData();
114: pos = pos - event.GetWheelRotation() / 40;
115:
116: int maxpos = vscroll->GetRange() - vscroll->GetThumbSize();
117: if (pos < 0)
118: pos = 0;
119: if (pos > maxpos)
120: pos = maxpos;
121:
122: DoScroll(pos);
123: }
124:
125: // スクロールイベント (全部入り)
126: void
127: WXHistoryMonitor::OnScroll(wxScrollEvent& event)
128: {
129: DoScroll(event.GetPosition());
130: }
131:
132: // スクロール処理 (OnScroll() と OnMouseWheel() から呼ばれる)
133: void
134: WXHistoryMonitor::DoScroll(int pos)
135: {
136: // BranchHistory モニタは userdata が表示開始位置になっている
137: screen->SetUserData(exflag | pos);
138: vscroll->SetThumbPosition(pos);
139: }
140:
141: //
142: // ブランチ履歴モニタ
143: //
144:
145: // コンストラクタ
1.1.1.3 ! root 146: WXBranchHistoryMonitor::WXBranchHistoryMonitor(wxWindow *parent,
! 147: Monitor& monitor)
! 148: : inherited(parent, _("Branch History"), monitor)
1.1 root 149: {
150: exflag = 0;
151: screen->SetUserData(exflag);
152: }
153:
154: // デストラクタ
155: WXBranchHistoryMonitor::~WXBranchHistoryMonitor()
156: {
157: }
158:
159: //
160: // 例外履歴モニタ
161: //
162:
163: // コンストラクタ
164: WXExceptionHistoryMonitor::WXExceptionHistoryMonitor(wxWindow *parent,
1.1.1.3 ! root 165: Monitor& monitor)
! 166: : inherited(parent, _("Exception History"), monitor)
1.1 root 167: {
168: exflag = 1ULL << 63;
169: screen->SetUserData(exflag);
170: }
171:
172: // デストラクタ
173: WXExceptionHistoryMonitor::~WXExceptionHistoryMonitor()
174: {
175: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.