Menu

[a01819]: / src / GraphicsWindow.cpp  Maximize  Restore  History

Download this file

122 lines (103 with data), 4.1 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
/*
* File: GraphicsWindow.cpp
* Author: amz
*
* Created on 12 marzec 2014, 10:48
*/
#include "GraphicsWindow.h"
#include <wx/wfstream.h>
#include <wx/textctrl.h>
GraphicsWindow::GraphicsWindow(const wxString& title)
: wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(650, 350)) {
text = new wxTextCtrl(this, TEXT_Main, "", wxDefaultPosition, wxDefaultSize,
wxTE_MULTILINE , wxTextValidator(wxFILTER_ALPHANUMERIC), wxTextCtrlNameStr);
Connect(wxID_EXIT, wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(GraphicsWindow::OnQuit));
Connect(wxID_EXECUTE, wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(GraphicsWindow::OnExecute));
text->Connect(wxEVT_KEY_DOWN, wxKeyEventHandler(GraphicsWindow::onKeyDown));
text->Connect(wxEVT_KEY_UP, wxKeyEventHandler(GraphicsWindow::onKeyUp));
text->Connect(wxEVT_CHAR, wxKeyEventHandler(GraphicsWindow::onChar));
text->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(GraphicsWindow::onMouseClick));
text->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(GraphicsWindow::onMouseClick));
text->Connect(wxEVT_RIGHT_DOWN, wxMouseEventHandler(GraphicsWindow::onMouseClick));
text->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(GraphicsWindow::onMouseClick));
text->Connect(wxEVT_LEFT_DCLICK, wxMouseEventHandler(GraphicsWindow::onMouseClick));
text->Connect(wxEVT_RIGHT_DCLICK, wxMouseEventHandler(GraphicsWindow::onMouseClick));
Centre();
}
void GraphicsWindow::onMouseClick(wxMouseEvent& aEvent)
{
wxLogMessage(wxString::Format(_("GraphicsWindow::onMouseClick\n")));
//aEvent.ResumePropagation(1);
//aEvent.Skip();
aEvent.StopPropagation();
}
void GraphicsWindow::onKeyDown(wxKeyEvent& aEvent)
{
wxLogMessage(wxString::Format(_("GraphicsWindow::onKeyDown\n")));
aEvent.ResumePropagation(1);
aEvent.Skip();
//aEvent.StopPropagation();
}
void GraphicsWindow::onKeyUp(wxKeyEvent& aEvent)
{
wxLogMessage(wxString::Format(_("GraphicsWindow::onKeyUp \"%c\" %d %d\n"),aEvent.GetUnicodeKey(), aEvent.GetKeyCode(), aEvent.GetModifiers() ));
aEvent.ResumePropagation(1);
aEvent.Skip();
//aEvent.StopPropagation();
}
void GraphicsWindow::onChar(wxKeyEvent& aEvent)
{
wxLogMessage(wxString::Format(_("GraphicsWindow::onChar \"%c\" %d\n"),aEvent.GetUnicodeKey(), aEvent.GetKeyCode() ));
//aEvent.ResumePropagation(1);
//aEvent.Skip();
aEvent.StopPropagation();
}
void GraphicsWindow::OnQuit(wxCommandEvent& WXUNUSED(event)) {
Close(FALSE);
}
void GraphicsWindow::OnClose(wxCloseEvent& event) {
this->Destroy();return;
if (showQuitDialog() == wxID_YES) {
this->Destroy();
} else {
if (event.CanVeto()) {
event.Veto();
}
}
}
int GraphicsWindow::showQuitDialog() {
wxMessageDialog *dial = new wxMessageDialog(NULL,
wxT("Are you sure to quit?"), wxT("Question"),
wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION);
int ret = dial->ShowModal();
dial->Destroy();
wxLogMessage(wxString::Format(_("[GraphicsWindow::showQuitDialog] Show Dialog returns %d."), ret));
return ret;
}
void GraphicsWindow::OnExecute(wxCommandEvent& WXUNUSED(event)) {
wxFileDialog
openFileDialog(this, _("Open Loglan file"), "", "",
"log files (*.log)|*.log", wxFD_OPEN | wxFD_FILE_MUST_EXIST);
if (openFileDialog.ShowModal() == wxID_CANCEL)
return; // the user changed idea...
// proceed loading the file chosen by the user;
// this can be done with e.g. wxWidgets input streams:
wxFileInputStream input_stream(openFileDialog.GetPath());
if (!input_stream.IsOk()) {
wxLog* target = wxLog::GetActiveTarget();
wxLog::SetActiveTarget(NULL);
wxLogMessage("[GraphicsWindow::showQuitDialog] Cannot open file '%s'.", openFileDialog.GetPath());
wxLog::SetActiveTarget(target);
return;
}
}
GraphicsWindow::~GraphicsWindow(){
}
BEGIN_EVENT_TABLE(GraphicsWindow, wxFrame)
EVT_CLOSE(GraphicsWindow::OnClose)
END_EVENT_TABLE()
void GraphicsWindow::PutChar(char ch) {
(*text) << ch;
}