Created
December 27, 2011 11:00
-
-
Save silv3rm00n/1523283 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifdef WX_PRECOMP | |
#include "wx_pch.h" | |
#endif | |
#ifdef __BORLANDC__ | |
#pragma hdrstop | |
#endif //__BORLANDC__ | |
#include "tcptraceMain.h" | |
#include "turbotrace.h" | |
//helper functions | |
enum wxbuildinfoformat | |
{ | |
short_f, long_f | |
}; | |
/** | |
@details | |
Function to provide the build information | |
*/ | |
wxString wxbuildinfo(wxbuildinfoformat format) | |
{ | |
wxString wxbuild(wxVERSION_STRING); | |
if (format == long_f ) | |
{ | |
#if defined(__WXMSW__) | |
wxbuild << _T("-Windows"); | |
#elif defined(__WXMAC__) | |
wxbuild << _T("-Mac"); | |
#elif defined(__UNIX__) | |
wxbuild << _T("-Linux"); | |
#endif | |
#if wxUSE_UNICODE | |
wxbuild << _T("-Unicode build"); | |
#else | |
wxbuild << _T("-ANSI build"); | |
#endif // wxUSE_UNICODE | |
} | |
return wxbuild; | |
} | |
/** | |
@details | |
Constructor for the Frame , does a couple of things | |
Create menu , statusbar etc | |
*/ | |
tcptraceFrame::tcptraceFrame(wxFrame *frame, const wxString& title) : wxFrame(frame, -1, title) | |
{ | |
//Initialise the User Interface | |
init_ui(); | |
} | |
tcptraceFrame::~tcptraceFrame() | |
{ | |
} | |
void tcptraceFrame::init_ui() | |
{ | |
#if wxUSE_MENUS | |
// create a menu bar | |
wxMenuBar* mbar = new wxMenuBar(); | |
//First file menu | |
wxMenu* menu = new wxMenu( _T("") ); | |
//Add items to file menu | |
wxMenuItem *mi = new wxMenuItem( menu , ::wxNewId() , _("&Quit\tAlt-F4") , _("Quit the application")); | |
menu->Append(mi); | |
this->Connect( mi->GetId() , wxEVT_COMMAND_MENU_SELECTED , (wxObjectEventFunction) &tcptraceFrame::OnQuit ); | |
//ADd the File menu to menubar | |
mbar->Append(menu, _("&File")); | |
//Now the Help Menu | |
menu = new wxMenu(_T("")); | |
//About option in Help Menu | |
mi = new wxMenuItem(menu , ::wxNewId() , _("&About\tF1") , _("Show info about this application") ); | |
menu->Append(mi); | |
this->Connect( mi->GetId() , wxEVT_COMMAND_MENU_SELECTED , (wxObjectEventFunction) &tcptraceFrame::OnAbout ); | |
//Add to menubar | |
mbar->Append(menu , _("&Help")); | |
//Set the main menu bar | |
SetMenuBar(mbar); | |
#endif // wxUSE_MENUS | |
#if wxUSE_STATUSBAR | |
// create a status bar with some information about the used wxWidgets version | |
CreateStatusBar(2); | |
SetStatusText( _("Tcp Traceroute version 1.0") , 0 ); | |
SetStatusText( wxbuildinfo(short_f), 1); | |
#endif // wxUSE_STATUSBAR | |
//Now create panel | |
wxPanel *panel = new wxPanel( this , ::wxNewId() ); | |
wxFlexGridSizer *fgs = new wxFlexGridSizer( 3 , 2 , 9 , 25 ); | |
//Create some static text controls | |
wxStaticText *server = new wxStaticText(panel , -1 , _("Enter Hostname/IP")); | |
wxStaticText *result = new wxStaticText(panel , -1 , _("Results")); | |
//Create some text boxes and buttons , remember they all belong to the panel | |
txt_host = new wxTextCtrl(panel, -1); | |
wxButton *btn_trace = new wxButton(panel , 20 , _("Trace")); | |
//Event handler | |
btn_trace->Connect( btn_trace->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &tcptraceFrame::on_trace ); | |
//btn_trace->SetToolTipString(_("Click to get whois information for the domain name.")); | |
wxTextCtrl *txt_result = new wxTextCtrl(panel , -1 , _("") , wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE); | |
//Add the input field and submit button to a Box Sizer since the must stay together | |
wxBoxSizer *space = new wxBoxSizer(wxHORIZONTAL); | |
//Expandable with right border | |
space->Add( txt_host , 1 , wxRIGHT , 10 ); | |
//Non expandable and align to right | |
space->Add( btn_trace , 0 , wxALIGN_RIGHT); | |
fgs->Add(server); | |
fgs->Add(space , 1 , wxEXPAND); | |
fgs->Add(result); | |
fgs->Add(txt_result , 1 , wxEXPAND); | |
fgs->AddGrowableRow(1, 1); | |
fgs->AddGrowableCol(1, 1); | |
wxBoxSizer *box = new wxBoxSizer(wxHORIZONTAL); | |
box->Add(fgs, 1 , wxEXPAND | wxALL , 20); | |
panel->SetSizer(box); | |
} | |
/** | |
@brief | |
Frame cross button handler | |
*/ | |
void tcptraceFrame::OnClose(wxCloseEvent &event) | |
{ | |
Destroy(); | |
} | |
/** | |
@brief | |
File > Quit Handler | |
*/ | |
void tcptraceFrame::OnQuit(wxCommandEvent &event) | |
{ | |
Destroy(); | |
} | |
/** | |
@brief | |
Help > About Handler | |
*/ | |
void tcptraceFrame::OnAbout(wxCommandEvent &event) | |
{ | |
wxString msg = wxbuildinfo(long_f); | |
wxMessageBox(msg, _("Welcome to...")); | |
} | |
/** | |
@brief | |
Trace button handler | |
*/ | |
void tcptraceFrame::on_trace(wxCommandEvent &event) | |
{ | |
txt_host->GetValue(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment