2 #include <wx/textctrl.h>
6 #include "pipedprocess.h"
11 BEGIN_EVENT_TABLE(ConsolePanel
, wxPanel
)
12 EVT_COMMAND (wxID_ANY
,EVT_PROCESS_INPUT
,ConsolePanel::HandleConsoleInput
)
13 EVT_COMMAND (wxID_ANY
,EVT_PROCESS_OUTPUT
,ConsolePanel::HandleConsoleOutput
)
14 EVT_COMMAND (wxID_ANY
,EVT_PROCESS_CREATED
,ConsolePanel::HandleProcessCreation
)
15 EVT_COMMAND (wxID_ANY
,EVT_PROCESS_TERMINATED
,ConsolePanel::HandleProcessTermination
)
16 EVT_COMMAND (wxID_ANY
,EVT_SOCKET_INPUT
,ConsolePanel::HandleConsoleInput
)
17 EVT_COMMAND (wxID_ANY
,EVT_SOCKET_WRITE
,ConsolePanel::HandleConsoleOutput
)
20 ConsolePanel::ConsolePanel(wxWindow
*parent
,QemuVM
*vm
) : wxPanel(parent
){
22 this->process
= vm
->GetProcess();
23 this->socket
= vm
->GetSocket();
26 process
->AddEventHandler(this);
29 socket
->AddEventHandler(this);
31 console
= new wxTextCtrl(this,-1,wxT(""),wxDefaultPosition
,
32 wxDefaultSize
, wxTE_MULTILINE
|wxTE_READONLY
|
33 wxHSCROLL
|wxTE_LINEWRAP
36 console
->SetFont(wxFont(10, wxFONTFAMILY_TELETYPE
,wxFONTSTYLE_NORMAL
,
37 wxFONTWEIGHT_NORMAL
));
39 input
= new InputTextCtrl(this);
41 sizer
= new wxBoxSizer(wxVERTICAL
);
42 sizer
->Add(console
, 1, wxEXPAND
|wxADJUST_MINSIZE
, 0);
43 sizer
->Add(input
, 0, wxEXPAND
|wxADJUST_MINSIZE
, 0);
48 ConsolePanel::~ConsolePanel(){
51 void ConsolePanel::SetProcess(PipedProcess
*process
){
53 this->process
= process
;
54 process
->AddEventHandler(this);
58 bool ConsolePanel::Notify(const wxString
& cmd
){
60 // will generate an event which is handlet
61 // by HandleConsoleOutput
68 void ConsolePanel::HandleConsoleInput( wxCommandEvent
&event
)
70 AppendConsoleOutput(event
.GetString());
73 void ConsolePanel::HandleConsoleOutput( wxCommandEvent
&event
)
75 AppendConsoleInput(event
.GetString());
78 void ConsolePanel::HandleProcessCreation(wxCommandEvent
& event
){
80 AppendConsoleInput(event
.GetString());
83 void ConsolePanel::HandleProcessTermination(wxCommandEvent
& event
)
86 msg
<< _("Qemu exited with");
87 msg
<< wxT(" ") << event
.GetInt() << wxT(".");
88 AppendConsoleError(msg
);
89 QemuGUI::GetMainFrame()->UpdateState();
92 void ConsolePanel::AppendConsoleInput(const wxString
& cmd
){
94 attr
.SetFont(wxFont(10, wxFONTFAMILY_TELETYPE
,wxFONTSTYLE_NORMAL
,
97 start
= console
->GetLastPosition();
98 console
->AppendText(wxString::Format(wxT(">>%s\n"),cmd
.c_str()));
99 end
= console
->GetLastPosition();
100 console
->SetStyle(start
, end
, attr
);
104 void ConsolePanel::AppendConsoleOutput(const wxString
& cmd
){
105 console
->AppendText(cmd
+ wxT("\n"));
109 void ConsolePanel::AppendConsoleError(const wxString
& cmd
){
110 console
->AppendText(cmd
+ wxT("\n"));
114 void ConsolePanel::ScrollToEnd(){
115 console
->ShowPosition(console
->GetLastPosition());
118 void ConsolePanel::SetState(bool state
){
119 input
->Enable(state
);
122 void InputTextCtrl::OnKeyDown(wxKeyEvent
& event
){
123 switch(event
.GetKeyCode()){
125 case WXK_NUMPAD_ENTER
:
126 const wxString
& cmd
= this->GetValue();
127 if(((ConsolePanel
*)GetParent())->Notify(cmd
))
135 InputTextCtrl::InputTextCtrl(ConsolePanel
*parent
)
136 :wxTextCtrl(parent
, wxID_ANY
, wxT(""), wxDefaultPosition
,
137 wxDefaultSize
, wxTE_PROCESS_ENTER
|wxTE_PROCESS_TAB
){
141 BEGIN_EVENT_TABLE(InputTextCtrl
, wxTextCtrl
)
142 EVT_KEY_DOWN(InputTextCtrl::OnKeyDown
)