Reimplement aven's cavern log window
[survex.git] / src / cavernlog.h
blob6d0c1ce82b6e7849f0da9943aa8aa5fba1f00a88
1 /* cavernlog.h
2 * Run cavern inside an Aven window
4 * Copyright (C) 2005-2024 Olly Betts
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #ifndef SURVEX_CAVERNLOG_H
22 #define SURVEX_CAVERNLOG_H
24 #include "wx.h"
25 #include <wx/process.h>
27 #include <string>
28 #include <vector>
30 class MainFrm;
32 class CavernLogWindow : public wxScrolledWindow {
33 wxString filename;
35 MainFrm * mainfrm;
37 wxProcess * cavern_out = nullptr;
38 size_t ptr = 0;
39 bool expecting_caret_line = false;
40 int info_count = 0;
41 int link_count = 0;
43 bool init_done = false;
45 wxString survey;
47 wxTimer timer;
49 std::string log_txt;
51 enum { LOG_NONE, LOG_ERROR, LOG_WARNING, LOG_INFO };
53 class LineInfo {
54 public:
55 unsigned start_offset = 0;
56 unsigned len = 0;
57 unsigned link_len = 0;
58 unsigned link_pixel_width = 0;
59 unsigned colour = LOG_NONE;
60 unsigned colour_start = 0;
61 unsigned colour_len = 0;
63 LineInfo() { }
65 explicit LineInfo(unsigned start_offset_)
66 : start_offset(start_offset_) { }
69 std::vector<LineInfo> line_info;
71 wxButton* save_button = nullptr;
72 wxButton* reprocess_button = nullptr;
73 wxButton* ok_button = nullptr;
75 public:
76 CavernLogWindow(MainFrm * mainfrm_, const wxString & survey_, wxWindow * parent);
78 ~CavernLogWindow();
80 /** Start to process survey data in file. */
81 void process(const wxString &file);
83 void OnMouseMove(wxMouseEvent& e);
85 void OnLinkClicked(wxMouseEvent& e);
87 void OnReprocess(wxCommandEvent &);
89 void OnSave(wxCommandEvent &);
91 void OnOK(wxCommandEvent &);
93 void ProcessCavernOutput();
95 void OnCavernOutput(wxCommandEvent&) {
96 ProcessCavernOutput();
97 Update();
98 timer.StartOnce();
101 void CheckForOutput(bool immediate = false);
103 void OnIdle(wxIdleEvent&) { CheckForOutput(); }
105 void OnTimer(wxTimerEvent&) { CheckForOutput(); }
107 int OnPaintButton(wxButton* b, int x);
109 void OnPaint(wxPaintEvent&);
111 void OnEndProcess(wxProcessEvent & e);
113 DECLARE_EVENT_TABLE()
116 wxString escape_for_shell(wxString s, bool protect_dash = false);
117 wxString get_command_path(const wxChar * command_name);
119 #endif