|
|
1.1 root 1: //
2: // nono
1.1.1.3 root 3: // Copyright (C) 2020 nono project
4: // Licensed under nono-license.txt
1.1 root 5: //
6:
7: //
8: // ログモニター
9: //
10:
1.1.1.9 root 11: #include "wxlogmonitor.h"
12: #include "logger.h"
13: #include "mainapp.h"
1.1.1.12 root 14: #include "monitor.h"
1.1.1.9 root 15: #include "sjis.h"
16:
1.1.1.13 root 17: //#define WINDOW_DEBUG 1
18:
19: #if defined(WINDOW_DEBUG)
20: #define DPRINTF(fmt...) printf(fmt)
21: #else
22: #define DPRINTF(fmt...) /**/
23: #endif
1.1 root 24:
25: // コンストラクタ
1.1.1.7 root 26: WXLogMonitor::WXLogMonitor(wxWindow *parent)
1.1.1.10 root 27: : inherited(parent, wxID_ANY, _("Log"), DEFAULT_STYLE | wxRESIZE_BORDER)
1.1 root 28: {
1.1.1.13 root 29: DPRINTF("%s begin\n", __method__);
1.1 root 30:
1.1.1.14! root 31: // +-----------------+---------+
! 32: // | LogMonitorPanel | VScroll |
! 33: // +-----------------+---------+
1.1.1.4 root 34:
1.1.1.14! root 35: // モニタ
! 36: logger = gMainApp.GetLogger();
! 37: screen = new LogMonitorPanel(this, logger->GetMonitor());
1.1.1.4 root 38:
39: // スクロールバー
1.1.1.9 root 40: vscroll = new WXScrollBar(this, wxID_ANY, wxSB_VERTICAL);
1.1.1.3 root 41:
1.1.1.14! root 42: // 自前レイアウト。
! 43: SetMyLayout();
1.1.1.13 root 44:
1.1.1.4 root 45: // ウィンドウサイズを確定させる
1.1.1.13 root 46: FontChanged();
1.1.1.4 root 47:
48: // スクロールのために (パネル領域での) MouseWheel イベントもここで
1.1.1.9 root 49: // 受け取りたい。スクロールバー上のマウスホイール操作はスクロールバーが
50: // 処理しているので問題ないが、パネル領域でのマウスホイール操作はここ
51: // (wxFrame)ではなくパネルに対して飛んでくる。
1.1.1.4 root 52: // ここで一緒に処理したほうが楽なので、こちらに回す。
53: screen->Connect(wxEVT_MOUSEWHEEL,
54: wxMouseEventHandler(WXLogMonitor::OnMouseWheel), NULL, this);
1.1.1.9 root 55:
1.1.1.13 root 56: // スクロールバーからの位置変更通知イベントは表示パネルへ回す。
1.1.1.9 root 57: vscroll->Connect(NONO_EVT_SCROLL,
58: wxScrollEventHandler(WXLogMonitor::OnScroll), NULL, this);
59:
60: // XXX ログウィンドウのコピーはまだ動いてない
61: screen->DisconnectContextMenu();
1.1.1.13 root 62: DPRINTF("%s done\n", __method__);
1.1 root 63: }
64:
65: // デストラクタ
66: WXLogMonitor::~WXLogMonitor()
67: {
68: }
69:
1.1.1.13 root 70: void
71: WXLogMonitor::FontChanged()
1.1.1.10 root 72: {
1.1.1.13 root 73: screen->FontChanged();
74: vscroll->FontChanged();
75: DPRINTF("%s %d\n", __method__, screen->GetFontHeight());
76:
77: Fit();
1.1.1.10 root 78: }
79:
1.1.1.14! root 80: // 自前レイアウト方式のサイズに関する情報を返す。
1.1.1.13 root 81: bool
1.1.1.14! root 82: WXLogMonitor::GetMySizeHints(wxSize *newp, wxSize *minp, wxSize *maxp,
! 83: wxSize *incp)
1.1.1.13 root 84: {
85: auto ssize = screen->GetSize();
86: auto vsize = vscroll->GetSize();
87:
88: int x = ssize.x + vsize.x;
89: int min_y = std::max(vscroll->GetMinSize().y, screen->GetScreenHeight(1));
90: int new_y = std::max(ssize.y, min_y);
1.1.1.14! root 91: wxSize newsize(x, new_y);
1.1.1.13 root 92: wxSize minsize(x, min_y);
93: wxSize maxsize(x, GetMaxClientSize().y);
94: wxSize incsize(0, screen->GetFontHeight());
95:
1.1.1.14! root 96: if (newp) *newp = newsize;
! 97: if (minp) *minp = minsize;
! 98: if (maxp) *maxp = maxsize;
! 99: if (incp) *incp = incsize;
! 100: return true;
! 101: }
! 102:
! 103: bool
! 104: WXLogMonitor::Layout()
! 105: {
! 106: if (MyLayout() == false) {
! 107: // コントロールを配置。
! 108: wxSize client = GetClientSize();
! 109: const wxSize vsize = vscroll->GetSize();
! 110:
! 111: int panel_width = client.x - vsize.x;
! 112: int panel_height = client.y;
! 113: // 最低でも 1px ないと GTK とかに怒られる。今は起きないはず?
! 114: if (__predict_false(panel_width < 1)) {
! 115: panel_width = 1;
! 116: }
! 117: if (__predict_false(panel_height < 1)) {
! 118: panel_height = 1;
! 119: }
! 120:
! 121: screen->SetSize(0, 0, panel_width, panel_height);
! 122: vscroll->SetSize(panel_width, 0, vsize.x, panel_height);
! 123:
! 124: // スクロールバーを再設定
! 125: SetScroll();
! 126: }
! 127: return true;
1.1.1.4 root 128: }
129:
130: // スクロールバーを再設定
131: void
132: WXLogMonitor::SetScroll()
133: {
1.1.1.14! root 134: int displines;
! 135: int row;
1.1.1.4 root 136: int pos;
137: int thumbsize;
138: int range;
139: int pagesize;
140:
1.1.1.14! root 141: displines = logger->GetDispLines();
1.1.1.7 root 142: row = screen->GetRow();
1.1.1.4 root 143:
1.1.1.14! root 144: if (displines <= row) {
1.1.1.4 root 145: pos = 0;
146: range = row;
147: } else {
1.1.1.14! root 148: pos = (displines - row) - screen->GetUserData();
! 149: range = displines;
1.1.1.4 root 150: }
151: thumbsize = row;
152: pagesize = thumbsize - 1;
1.1.1.9 root 153: vscroll->SetScrollParam(pos, thumbsize, range, pagesize);
1.1.1.4 root 154: }
155:
156: // マウスホイールイベント (WXTextScreen 上で起きたやつをこっちに回してある)
1.1 root 157: void
1.1.1.4 root 158: WXLogMonitor::OnMouseWheel(wxMouseEvent& event)
159: {
160: // GetWheelRotation() は上(奥)向きに回すと +120、下(手前)に回すと -120。
161: // どこの決まりか知らんけど、スクロールバーのほうはホイール1段階で3行
162: // スクロールするのでそれに合わせる。
163: int pos = vscroll->GetThumbPosition();
164: pos = pos - event.GetWheelRotation() / 40;
165:
166: int maxpos = vscroll->GetRange() - vscroll->GetThumbSize();
167: if (pos < 0)
168: pos = 0;
169: if (pos > maxpos)
170: pos = maxpos;
171:
172: DoScroll(pos);
1.1.1.9 root 173: // スクロールバーの位置を追従
174: vscroll->SetThumbPosition(pos);
1.1.1.4 root 175: }
176:
1.1.1.9 root 177: // スクロールバーからの通知イベント
1.1.1.4 root 178: void
179: WXLogMonitor::OnScroll(wxScrollEvent& event)
180: {
181: DoScroll(event.GetPosition());
182: }
183:
184: // スクロール処理 (OnScroll() と OnMouseWheel() から呼ばれる)
185: void
186: WXLogMonitor::DoScroll(int pos)
187: {
188: // pos 即ちスクロールバーの Thumb の位置は上端の位置。
189: // 対してログウィンドウでは下端を基準にしたほうが処理しやすい。
1.1.1.14! root 190: // userdata = 0 だと Thumb が下に接していてパネルの最下行が最新行、
! 191: // userdata = 1 だと Thumb が下から1段階分上にありパネルの最下行は
! 192: // 最新行の一つ前の行、となる。
1.1.1.4 root 193: //
194: // Range=6 Range=6
195: // Pos=4 Pos=0
196: // ThumbSz=2 ThumbSz=2
1.1.1.14! root 197: // userdata=0 userdata=4
1.1.1.4 root 198: // △ △
199: // □ ■
200: // □ ■
201: // □ □
202: // □ □
203: // ■ □
204: // ■ □
205: // ▽ ▽
206:
207: // パネル最下行に表示する行の最新行からのオフセット
208: // (0 なら Thumb が下端に接している)
1.1.1.14! root 209: int vpos = vscroll->GetRange() - vscroll->GetThumbSize() - pos;
! 210: screen->SetUserData(vpos);
1.1.1.4 root 211: }
212:
1.1.1.9 root 213:
1.1.1.7 root 214: //
215: // モニターオブジェクト
216: //
217:
218: // コンストラクタ
1.1.1.14! root 219: LogMonitorPanel::LogMonitorPanel(WXLogMonitor *parent_, Monitor *monitor_)
! 220: : inherited(parent_, monitor_)
1.1.1.7 root 221: {
222: parent = parent_;
1.1.1.4 root 223: }
1.1 root 224:
1.1.1.14! root 225: // デストラクタ
! 226: LogMonitorPanel::~LogMonitorPanel()
1.1.1.4 root 227: {
1.1 root 228: }
229:
230: void
1.1.1.14! root 231: LogMonitorPanel::DoRefresh()
1.1 root 232: {
1.1.1.14! root 233: inherited::DoRefresh();
1.1 root 234:
1.1.1.14! root 235: // スクロールバーを再設定。
! 236: parent->SetScroll();
1.1 root 237: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.