1 | /* cavernlog.h |
---|
2 | * Run cavern inside an Aven window |
---|
3 | * |
---|
4 | * Copyright (C) 2005-2022 Olly Betts |
---|
5 | * |
---|
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. |
---|
10 | * |
---|
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. |
---|
15 | * |
---|
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 |
---|
19 | */ |
---|
20 | |
---|
21 | #ifndef SURVEX_CAVERNLOG_H |
---|
22 | #define SURVEX_CAVERNLOG_H |
---|
23 | |
---|
24 | #include "wx.h" |
---|
25 | #include <wx/html/htmlwin.h> |
---|
26 | #include <wx/process.h> |
---|
27 | |
---|
28 | #include <string> |
---|
29 | |
---|
30 | // We probably want to use a thread if we can - that way we can use a blocking |
---|
31 | // read from cavern rather than busy-waiting via idle events. |
---|
32 | #ifdef wxUSE_THREADS |
---|
33 | # define CAVERNLOG_USE_THREADS |
---|
34 | #endif |
---|
35 | |
---|
36 | #ifdef CAVERNLOG_USE_THREADS |
---|
37 | class CavernThread; |
---|
38 | #endif |
---|
39 | class MainFrm; |
---|
40 | |
---|
41 | class CavernLogWindow : public wxHtmlWindow { |
---|
42 | #ifdef CAVERNLOG_USE_THREADS |
---|
43 | friend class CavernThread; |
---|
44 | #endif |
---|
45 | |
---|
46 | wxString filename; |
---|
47 | |
---|
48 | MainFrm * mainfrm; |
---|
49 | |
---|
50 | wxProcess * cavern_out = nullptr; |
---|
51 | wxString cur; |
---|
52 | wxString source_line; |
---|
53 | const wxChar * highlight = nullptr; |
---|
54 | int info_count = 0; |
---|
55 | int link_count = 0; |
---|
56 | unsigned char buf[1024]; |
---|
57 | unsigned char * end; |
---|
58 | |
---|
59 | bool init_done = false; |
---|
60 | |
---|
61 | wxString survey; |
---|
62 | |
---|
63 | std::string log_txt; |
---|
64 | |
---|
65 | #ifdef CAVERNLOG_USE_THREADS |
---|
66 | void stop_thread(); |
---|
67 | |
---|
68 | CavernThread * thread = nullptr; |
---|
69 | |
---|
70 | wxCriticalSection thread_lock; |
---|
71 | #endif |
---|
72 | |
---|
73 | public: |
---|
74 | CavernLogWindow(MainFrm * mainfrm_, const wxString & survey_, wxWindow * parent); |
---|
75 | |
---|
76 | ~CavernLogWindow(); |
---|
77 | |
---|
78 | /** Start to process survey data in file. */ |
---|
79 | void process(const wxString &file); |
---|
80 | |
---|
81 | virtual void OnLinkClicked(const wxHtmlLinkInfo &link); |
---|
82 | |
---|
83 | void OnReprocess(wxCommandEvent &); |
---|
84 | |
---|
85 | void OnSave(wxCommandEvent &); |
---|
86 | |
---|
87 | void OnOK(wxCommandEvent &); |
---|
88 | |
---|
89 | void OnCavernOutput(wxCommandEvent & e); |
---|
90 | |
---|
91 | #ifdef CAVERNLOG_USE_THREADS |
---|
92 | void OnClose(wxCloseEvent &); |
---|
93 | #else |
---|
94 | void OnIdle(wxIdleEvent &); |
---|
95 | #endif |
---|
96 | |
---|
97 | void OnEndProcess(wxProcessEvent & e); |
---|
98 | |
---|
99 | DECLARE_EVENT_TABLE() |
---|
100 | }; |
---|
101 | |
---|
102 | wxString escape_for_shell(wxString s, bool protect_dash = false); |
---|
103 | wxString get_command_path(const wxChar * command_name); |
---|
104 | |
---|
105 | #endif |
---|