-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwxcapoc_console.cpp
More file actions
122 lines (105 loc) · 3.88 KB
/
wxcapoc_console.cpp
File metadata and controls
122 lines (105 loc) · 3.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
*
* Copyright (c) 2019 Mateusz 'mteg' Golicz
*
* Distributed under Apache License version 2.0
*
*/
#include "capengine.h"
#include "caprenderer_ancientgl.h"
#include "capdebug.h"
#include "wxcapoc.h"
#include "wxcapoc_console.h"
wxBEGIN_EVENT_TABLE(wxCapoc_Console, wxDialog)
EVT_BUTTON(ID_ExecButton, wxCapoc_Console::OnExec)
EVT_BUTTON(ID_ClearButton, wxCapoc_Console::OnClear)
EVT_TEXT(ID_CommandEntry, wxCapoc_Console::OnEntry)
EVT_TEXT_ENTER(ID_CommandEntry, wxCapoc_Console::OnExec)
EVT_CHAR_HOOK(wxCapoc_Console::OnKeyUp)
wxEND_EVENT_TABLE()
wxCapoc_Console::wxCapoc_Console(capEngine *engine, wxString title, const char *buffer) :
wxDialog(NULL, -1, title, wxPoint(50, 50), wxSize(600, 400), wxWS_EX_VALIDATE_RECURSIVELY | wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) {
auto *b_box = new wxBoxSizer(wxHORIZONTAL);
auto *v_box = new wxBoxSizer(wxVERTICAL);
auto *mainPanel = new wxPanel(this, wxID_ANY);
this->engine = engine;
if(engine)
{
commandEntry = new wxTextCtrl(mainPanel, ID_CommandEntry, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_TAB | wxTE_PROCESS_ENTER);
execButton = new wxButton(mainPanel, ID_ExecButton, wxT("Exec"));
okButton = new wxButton(mainPanel, wxID_OK, wxT("Close"));
b_box->Add(commandEntry, 8);
b_box->Add(execButton, 1);
b_box->Add(new wxButton(mainPanel, ID_ClearButton, wxT("Clear")), 1);
b_box->Add(okButton, 1);
}
else {
okButton = new wxButton(mainPanel, wxID_OK, wxT("OK"));
b_box->Add(okButton, 1);
}
resultBuffer = new wxTextCtrl(mainPanel, wxID_ANY, buffer, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE);
resultBuffer->SetFont(wxFont(10, wxFONTFAMILY_TELETYPE, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL));
resultBuffer->SetEditable(false);
v_box->Add(resultBuffer, 1, wxEXPAND | wxALIGN_CENTER | wxTOP | wxBOTTOM, 10);
v_box->Add(b_box, 0, wxALIGN_RIGHT | wxTOP | wxBOTTOM, 10);
mainPanel->SetSizer(v_box);
auto* topSizer = new wxBoxSizer(wxHORIZONTAL);
topSizer->Add(mainPanel, 1, wxEXPAND);
SetSizer(topSizer);
SetAutoLayout(true);
}
void wxCapoc_Console::OnExec(wxCommandEvent &event) {
wxString text = commandEntry->GetValue();
text.Append("\n");
resultBuffer->AppendText(engine->execString(text.ToUTF8().data()));
commandEntry->SetValue("");
}
void wxCapoc_Console::OnEntry(wxCommandEvent &event) {
wxString text = commandEntry->GetValue();
if(!text.Len()) return;
wxUniChar t = text.GetChar(text.Len()-1);
if(t == '?')
{
resultBuffer->AppendText(engine->execString(text.ToUTF8().data()));
text.RemoveLast(1);
commandEntry->SetValue(text);
}
else if(t == '\t')
{
text.RemoveLast(1);
commandEntry->SetValue(text);
const char * cmdResult = engine->execString(text.ToUTF8().data());
if(strchr(cmdResult, '\n'))
resultBuffer->AppendText(cmdResult);
else {
commandEntry->SetValue(cmdResult);
commandEntry->SetInsertionPointEnd();
}
}
}
void wxCapoc_Console::OnKeyUp(wxKeyEvent &event) {
int k = event.GetKeyCode();
if(k == WXK_F1)
{
wxString text = commandEntry->GetValue();
text.Append("?");
resultBuffer->AppendText(engine->execString(text.ToUTF8().data()));
}
else if(k == WXK_F2) {
wxString text = commandEntry->GetValue();
text.Append("\t");
const char *cmdResult = engine->execString(text.ToUTF8().data());
if (strchr(cmdResult, '\n'))
resultBuffer->AppendText(cmdResult);
else {
commandEntry->SetValue(cmdResult);
commandEntry->SetInsertionPointEnd();
}
}
else
event.Skip();
}
void wxCapoc_Console::OnClear(wxCommandEvent &event) {
commandEntry->SetValue("");
resultBuffer->SetValue("");
}