00001 #include "TerminalGui.h"
00002 #include "Connessione.h"
00003 #include <wx/font.h>
00004
00005
00006
00007
00008 BEGIN_EVENT_TABLE(TerminalGui,CHILD_FRAME)
00009
00010 EVT_TEXT_ENTER(COMMAND_LINE,TerminalGui::EnterCommand)
00011
00012
00013 EVT_CLOSE(TerminalGui::TerminalGuiClose)
00014 END_EVENT_TABLE()
00015
00016
00017 TerminalGui::TerminalGui(Connessione* connection, PARENT_FRAME* parent,
00018 wxWindowID id, const wxString& title,
00019 const wxPoint& position, const wxSize& size,
00020 long style, const wxString& name)
00021 : CHILD_FRAME(parent, id, title, position,
00022 size, style, name), connessione(connection)
00023 {
00024 CreateGUIControls();
00025 }
00026
00027 TerminalGui::~TerminalGui()
00028 {
00029 StoreFrameSize(GetRect());
00030 }
00031
00032 void TerminalGui::CreateGUIControls()
00033 {
00034 #ifdef _WIN32
00035 this->SetIcon(wxICON(B));
00036 #else
00037 #include "res/Terminals.xpm"
00038 SetIcon( wxIcon(Terminals_xpm) );
00039 #endif
00040
00041
00042
00043 viewer = new wxTextCtrl(this, VIEWER, _(""), wxPoint(0,0),
00044 wxSize(TERMINALWIDTH, TERMINALHEIGHT-20),
00045 wxTE_MULTILINE|wxTE_READONLY|wxTE_RICH);
00046
00047
00048
00049 commandline = new wxTextCtrl(this, COMMAND_LINE, _(""),
00050 wxPoint(0, TERMINALHEIGHT-20),
00051 wxSize(TERMINALWIDTH, 20), wxTE_PROCESS_ENTER);
00052 USE_FONT;
00053 viewer->SetFont(FONT);
00054 commandline->SetFont(FONT);
00055 }
00056
00057 void TerminalGui::SetLayout()
00058 {
00059
00060
00061 wxBoxSizer *columnsizer = new wxBoxSizer(wxVERTICAL);
00062
00063 columnsizer->Add(viewer, 1, wxEXPAND);
00064
00065 columnsizer->Add(commandline, 0, wxEXPAND);
00066
00067
00068
00069 SetAutoLayout(TRUE);
00070 SetSizer(columnsizer);
00071
00072 columnsizer->Fit(this);
00073 columnsizer->SetSizeHints(this);
00074 }
00075
00076 void TerminalGui::receiveMsg(wxString message, wxTextAttr style)
00077 {
00078 viewer->SetDefaultStyle(style);
00079
00080 viewer->AppendText(message);
00081 viewer->SetDefaultStyle(STYLE_DEFAULT);
00082
00083 }
00084
00085 void TerminalGui::TerminalGuiClose(wxCloseEvent& event)
00086 {
00087
00088
00089 connessione->DeleteTerminal(GetName());
00090 }
00091
00092 void TerminalGui::EnterCommand(wxCommandEvent& event)
00093 {
00094 wxString cmd = commandline->GetValue();
00095 if(cmd.Len() < 1)
00096 return;
00097 if(cmd.GetChar(0) != '/' ){
00098
00099
00100
00101 viewer->SetDefaultStyle(STYLE_ITALIC);
00102 *viewer << "<" + connessione->GetMyNick() + "> ";
00103 viewer->SetDefaultStyle(STYLE_DEFAULT);
00104 *viewer << cmd;
00105 *viewer << _("\n");
00106 }
00107
00108
00109 connessione->getParserOut()->sendMessage(cmd,GetName());
00110 commandline->Clear();
00111 }
00112
00113
00114
00115 unsigned int TerminalGui::offset = 0;
00116
00117
00118 wxRect TerminalGui::DetermineFrameSize(wxConfig* config)
00119 {
00120 const int minFrameWidth = TERMINALWIDTH;
00121
00122 const int minFrameHeight = TERMINALHEIGHT;
00123 wxSize scr = wxGetDisplaySize();
00124
00125 wxRect rect;
00126 wxConfig* cfg = config;
00127 if (!config) cfg = new wxConfig(_("Quirck"));
00128
00129 wxString key = T_LOCATION;
00130 if (cfg->Exists(key)){
00131
00132 rect.x = cfg->Read(key + _("/") + T_LOCATION_X, rect.x) + offset;
00133 rect.y = cfg->Read(key + _("/") + T_LOCATION_Y, rect.y) + offset;
00134 rect.width = cfg->Read(key + _("/") + T_LOCATION_W, rect.width);
00135 rect.height = cfg->Read(key + _("/") + T_LOCATION_H, rect.height);
00136 }
00137
00138 if (!config) delete cfg;
00139
00140
00141
00142 rect.x = wxMin(abs(rect.x), (scr.x - minFrameWidth));
00143 rect.y = wxMin(abs(rect.y), (scr.y - minFrameHeight));
00144 rect.width = wxMax(abs(rect.width), (minFrameWidth));
00145 rect.width = wxMin(abs(rect.width), (scr.x - rect.x));
00146 rect.height = wxMax(abs(rect.height), (minFrameHeight));
00147 rect.height = wxMin(abs(rect.height), (scr.y - rect.y));
00148
00149 offset += 15;
00150
00151 return rect;
00152 }
00153
00154 void TerminalGui::StoreFrameSize(wxRect rect, wxConfig* config)
00155 {
00156 wxConfig* cfg = config;
00157 if (!config) cfg = new wxConfig(_("Quirck"));
00158
00159 wxString key = T_LOCATION;
00160 cfg->Write(key + _("/") + T_LOCATION_X, rect.x);
00161 cfg->Write(key + _("/") + T_LOCATION_Y, rect.y);
00162 cfg->Write(key + _("/") + T_LOCATION_W, rect.width);
00163 cfg->Write(key + _("/") + T_LOCATION_H, rect.height);
00164 if (!config) delete cfg;
00165 }
00166