Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***************************************************************
- * Name: CalcApp.h
- * Purpose: Defines Application Class
- * Author: Victor Mello Floriano (victormellof@gmail.com)
- * Created: 2011-02-14
- * Copyright: Victor Mello Floriano ()
- * License:
- **************************************************************/
- #ifndef CALCAPP_H
- #define CALCAPP_H
- #include <wx/app.h>
- class CalcApp : public wxApp
- {
- public:
- virtual bool OnInit();
- };
- #endif // CALCAPP_H
- /***************************************************************
- * Name: CalcApp.cpp
- * Purpose: Code for Application Class
- * Author: Victor Mello Floriano (victormellof@gmail.com)
- * Created: 2011-02-14
- * Copyright: Victor Mello Floriano ()
- * License:
- **************************************************************/
- #include "CalcApp.h"
- //(*AppHeaders
- #include "CalcMain.h"
- #include <wx/image.h>
- //*)
- IMPLEMENT_APP(CalcApp);
- bool CalcApp::OnInit()
- {
- //(*AppInitialize
- bool wxsOK = true;
- wxInitAllImageHandlers();
- if ( wxsOK )
- {
- CalcFrame* Frame = new CalcFrame(0);
- Frame->Show();
- SetTopWindow(Frame);
- }
- //*)
- return wxsOK;
- }
- /***************************************************************
- * Name: CalcMain.h
- * Purpose: Defines Application Frame
- * Author: Victor Mello Floriano (victormellof@gmail.com)
- * Created: 2011-02-14
- * Copyright: Victor Mello Floriano ()
- * License:
- **************************************************************/
- #ifndef CALCMAIN_H
- #define CALCMAIN_H
- //(*Headers(CalcFrame)
- #include <wx/button.h>
- #include <wx/menu.h>
- #include <wx/panel.h>
- #include <wx/statusbr.h>
- #include <wx/frame.h>
- #include <wx/textctrl.h>
- //*)
- class CalcFrame: public wxFrame
- {
- public:
- CalcFrame(wxWindow* parent,wxWindowID id = -1);
- virtual ~CalcFrame();
- double num1, num2;
- char op;
- private:
- //(*Handlers(CalcFrame)
- void OnQuit(wxCommandEvent& event);
- void OnAbout(wxCommandEvent& event);
- void OnButton19Click(wxCommandEvent& event);
- void OnButton9Click(wxCommandEvent& event);
- void OnButton4Click(wxCommandEvent& event);
- void OnButton5Click(wxCommandEvent& event);
- void OnButton6Click(wxCommandEvent& event);
- void OnButton13Click(wxCommandEvent& event);
- void OnButton8Click(wxCommandEvent& event);
- void OnButton10Click(wxCommandEvent& event);
- void OnButton16Click(wxCommandEvent& event);
- void OnButton12Click(wxCommandEvent& event);
- void OnButton1Click(wxCommandEvent& event);
- void OnButton17Click(wxCommandEvent& event);
- void OnButton14Click(wxCommandEvent& event);
- void OnButton3Click(wxCommandEvent& event);
- void OnButton7Click(wxCommandEvent& event);
- void OnButton11Click(wxCommandEvent& event);
- void OnButton18Click(wxCommandEvent& event);
- void OnButton2Click(wxCommandEvent& event);
- void OnButton15Click(wxCommandEvent& event);
- void OnTextCtrl1Text(wxCommandEvent& event);
- //*)
- //(*Identifiers(CalcFrame)
- static const long ID_BUTTON9;
- static const long ID_BUTTON13;
- static const long ID_BUTTON16;
- static const long ID_BUTTON17;
- static const long ID_BUTTON18;
- static const long ID_BUTTON15;
- static const long ID_BUTTON19;
- static const long ID_BUTTON14;
- static const long ID_BUTTON12;
- static const long ID_BUTTON11;
- static const long ID_BUTTON10;
- static const long ID_BUTTON8;
- static const long ID_BUTTON7;
- static const long ID_BUTTON6;
- static const long ID_BUTTON5;
- static const long ID_BUTTON4;
- static const long ID_BUTTON3;
- static const long ID_BUTTON2;
- static const long ID_BUTTON1;
- static const long ID_TEXTCTRL1;
- static const long ID_PANEL1;
- static const long ID_STATUSBAR1;
- //*)
- //(*Declarations(CalcFrame)
- wxPanel* Panel1;
- wxStatusBar* StatusBar1;
- wxButton* Button19;
- wxButton* Button16;
- wxButton* Button4;
- wxButton* Button1;
- wxButton* Button2;
- wxButton* Button3;
- wxButton* Button12;
- wxButton* Button8;
- wxButton* Button5;
- wxButton* Button17;
- wxButton* Button9;
- wxButton* Button15;
- wxButton* Button14;
- wxTextCtrl* TextCtrl1;
- wxButton* Button18;
- wxButton* Button11;
- wxButton* Button7;
- wxButton* Button6;
- wxButton* Button13;
- wxButton* Button10;
- //*)
- DECLARE_EVENT_TABLE()
- };
- #endif // CALCMAIN_H
- /***************************************************************
- * Name: CalcMain.cpp
- * Purpose: Code for Application Frame
- * Author: Victor Mello Floriano (victormellof@gmail.com)
- * Created: 2011-02-14
- * Copyright: Victor Mello Floriano ()
- * License:
- **************************************************************/
- #include "CalcMain.h"
- #include <wx/msgdlg.h>
- //(*InternalHeaders(CalcFrame)
- #include <wx/string.h>
- #include <wx/intl.h>
- #include <wx/font.h>
- //*)
- //helper functions
- enum wxbuildinfoformat {
- short_f, long_f };
- wxString wxbuildinfo(wxbuildinfoformat format)
- {
- wxString wxbuild(wxVERSION_STRING);
- if (format == long_f )
- {
- #if defined(__WXMSW__)
- wxbuild << _T("-Windows");
- #elif defined(__UNIX__)
- wxbuild << _T("-Linux");
- #endif
- #if wxUSE_UNICODE
- wxbuild << _T("-Unicode build");
- #else
- wxbuild << _T("-ANSI build");
- #endif // wxUSE_UNICODE
- }
- return wxbuild;
- }
- //(*IdInit(CalcFrame)
- const long CalcFrame::ID_BUTTON9 = wxNewId();
- const long CalcFrame::ID_BUTTON13 = wxNewId();
- const long CalcFrame::ID_BUTTON16 = wxNewId();
- const long CalcFrame::ID_BUTTON17 = wxNewId();
- const long CalcFrame::ID_BUTTON18 = wxNewId();
- const long CalcFrame::ID_BUTTON15 = wxNewId();
- const long CalcFrame::ID_BUTTON19 = wxNewId();
- const long CalcFrame::ID_BUTTON14 = wxNewId();
- const long CalcFrame::ID_BUTTON12 = wxNewId();
- const long CalcFrame::ID_BUTTON11 = wxNewId();
- const long CalcFrame::ID_BUTTON10 = wxNewId();
- const long CalcFrame::ID_BUTTON8 = wxNewId();
- const long CalcFrame::ID_BUTTON7 = wxNewId();
- const long CalcFrame::ID_BUTTON6 = wxNewId();
- const long CalcFrame::ID_BUTTON5 = wxNewId();
- const long CalcFrame::ID_BUTTON4 = wxNewId();
- const long CalcFrame::ID_BUTTON3 = wxNewId();
- const long CalcFrame::ID_BUTTON2 = wxNewId();
- const long CalcFrame::ID_BUTTON1 = wxNewId();
- const long CalcFrame::ID_TEXTCTRL1 = wxNewId();
- const long CalcFrame::ID_PANEL1 = wxNewId();
- const long CalcFrame::ID_STATUSBAR1 = wxNewId();
- //*)
- BEGIN_EVENT_TABLE(CalcFrame,wxFrame)
- //(*EventTable(CalcFrame)
- //*)
- END_EVENT_TABLE()
- CalcFrame::CalcFrame(wxWindow* parent,wxWindowID id)
- {
- //(*Initialize(CalcFrame)
- wxMenuBar* MenuBar1;
- Create(parent, id, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, _T("id"));
- SetClientSize(wxSize(245,375));
- Panel1 = new wxPanel(this, ID_PANEL1, wxPoint(152,184), wxDefaultSize, wxTAB_TRAVERSAL, _T("ID_PANEL1"));
- Button9 = new wxButton(Panel1, ID_BUTTON9, _("0"), wxPoint(8,280), wxSize(50,50), 0, wxDefaultValidator, _T("ID_BUTTON9"));
- Button13 = new wxButton(Panel1, ID_BUTTON13, _("4"), wxPoint(8,168), wxSize(50,50), 0, wxDefaultValidator, _T("ID_BUTTON13"));
- Button16 = new wxButton(Panel1, ID_BUTTON16, _("7"), wxPoint(8,112), wxSize(50,50), 0, wxDefaultValidator, _T("ID_BUTTON16"));
- Button17 = new wxButton(Panel1, ID_BUTTON17, _("C"), wxPoint(8,56), wxSize(104,50), 0, wxDefaultValidator, _T("ID_BUTTON17"));
- Button18 = new wxButton(Panel1, ID_BUTTON18, _("*"), wxPoint(176,112), wxSize(50,50), 0, wxDefaultValidator, _T("ID_BUTTON18"));
- Button15 = new wxButton(Panel1, ID_BUTTON15, _("+ -"), wxPoint(176,56), wxSize(50,50), 0, wxDefaultValidator, _T("ID_BUTTON15"));
- Button19 = new wxButton(Panel1, ID_BUTTON19, _("9"), wxPoint(120,112), wxSize(50,50), 0, wxDefaultValidator, _T("ID_BUTTON19"));
- Button14 = new wxButton(Panel1, ID_BUTTON14, _("<-"), wxPoint(120,56), wxSize(50,50), 0, wxDefaultValidator, _T("ID_BUTTON14"));
- Button12 = new wxButton(Panel1, ID_BUTTON12, _("8"), wxPoint(64,112), wxSize(50,50), 0, wxDefaultValidator, _T("ID_BUTTON12"));
- Button11 = new wxButton(Panel1, ID_BUTTON11, _("/"), wxPoint(176,168), wxSize(50,50), 0, wxDefaultValidator, _T("ID_BUTTON11"));
- Button10 = new wxButton(Panel1, ID_BUTTON10, _("6"), wxPoint(120,168), wxSize(50,50), 0, wxDefaultValidator, _T("ID_BUTTON10"));
- Button8 = new wxButton(Panel1, ID_BUTTON8, _("5"), wxPoint(64,168), wxSize(50,50), 0, wxDefaultValidator, _T("ID_BUTTON8"));
- Button7 = new wxButton(Panel1, ID_BUTTON7, _("-"), wxPoint(176,224), wxSize(50,50), 0, wxDefaultValidator, _T("ID_BUTTON7"));
- Button6 = new wxButton(Panel1, ID_BUTTON6, _("3"), wxPoint(120,224), wxSize(50,50), 0, wxDefaultValidator, _T("ID_BUTTON6"));
- Button5 = new wxButton(Panel1, ID_BUTTON5, _("2"), wxPoint(64,224), wxSize(50,50), 0, wxDefaultValidator, _T("ID_BUTTON5"));
- Button4 = new wxButton(Panel1, ID_BUTTON4, _("1"), wxPoint(8,224), wxSize(50,50), 0, wxDefaultValidator, _T("ID_BUTTON4"));
- Button3 = new wxButton(Panel1, ID_BUTTON3, _("+"), wxPoint(176,280), wxSize(50,50), 0, wxDefaultValidator, _T("ID_BUTTON3"));
- Button2 = new wxButton(Panel1, ID_BUTTON2, _("="), wxPoint(120,280), wxSize(50,50), 0, wxDefaultValidator, _T("ID_BUTTON2"));
- Button1 = new wxButton(Panel1, ID_BUTTON1, _(","), wxPoint(64,280), wxSize(50,50), 0, wxDefaultValidator, _T("ID_BUTTON1"));
- TextCtrl1 = new wxTextCtrl(Panel1, ID_TEXTCTRL1, wxEmptyString, wxPoint(8,16), wxSize(216,27), 0, wxDefaultValidator, _T("ID_TEXTCTRL1"));
- TextCtrl1->Disable();
- wxFont TextCtrl1Font(12,wxSWISS,wxFONTSTYLE_NORMAL,wxNORMAL,false,_T("Sans"),wxFONTENCODING_DEFAULT);
- TextCtrl1->SetFont(TextCtrl1Font);
- MenuBar1 = new wxMenuBar();
- SetMenuBar(MenuBar1);
- StatusBar1 = new wxStatusBar(this, ID_STATUSBAR1, 0, _T("ID_STATUSBAR1"));
- int __wxStatusBarWidths_1[1] = { -1 };
- int __wxStatusBarStyles_1[1] = { wxSB_NORMAL };
- StatusBar1->SetFieldsCount(1,__wxStatusBarWidths_1);
- StatusBar1->SetStatusStyles(1,__wxStatusBarStyles_1);
- SetStatusBar(StatusBar1);
- Connect(ID_BUTTON9,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&CalcFrame::OnButton9Click);
- Connect(ID_BUTTON13,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&CalcFrame::OnButton13Click);
- Connect(ID_BUTTON16,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&CalcFrame::OnButton16Click);
- Connect(ID_BUTTON17,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&CalcFrame::OnButton17Click);
- Connect(ID_BUTTON18,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&CalcFrame::OnButton18Click);
- Connect(ID_BUTTON15,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&CalcFrame::OnButton15Click);
- Connect(ID_BUTTON19,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&CalcFrame::OnButton19Click);
- Connect(ID_BUTTON14,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&CalcFrame::OnButton14Click);
- Connect(ID_BUTTON12,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&CalcFrame::OnButton12Click);
- Connect(ID_BUTTON11,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&CalcFrame::OnButton11Click);
- Connect(ID_BUTTON10,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&CalcFrame::OnButton10Click);
- Connect(ID_BUTTON8,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&CalcFrame::OnButton8Click);
- Connect(ID_BUTTON7,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&CalcFrame::OnButton7Click);
- Connect(ID_BUTTON6,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&CalcFrame::OnButton6Click);
- Connect(ID_BUTTON5,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&CalcFrame::OnButton5Click);
- Connect(ID_BUTTON4,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&CalcFrame::OnButton4Click);
- Connect(ID_BUTTON3,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&CalcFrame::OnButton3Click);
- Connect(ID_BUTTON2,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&CalcFrame::OnButton2Click);
- Connect(ID_BUTTON1,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&CalcFrame::OnButton1Click);
- Connect(ID_TEXTCTRL1,wxEVT_COMMAND_TEXT_UPDATED,(wxObjectEventFunction)&CalcFrame::OnTextCtrl1Text);
- //*)
- }
- CalcFrame::~CalcFrame()
- {
- //(*Destroy(CalcFrame)
- //*)
- }
- void CalcFrame::OnQuit(wxCommandEvent& event)
- {
- Close();
- }
- void CalcFrame::OnAbout(wxCommandEvent& event)
- {
- wxString msg = wxbuildinfo(long_f);
- wxMessageBox(msg, _("Welcome to..."));
- }
- void CalcFrame::OnButton19Click(wxCommandEvent& event)
- {
- wxString s;
- s=TextCtrl1->GetValue();
- TextCtrl1->SetValue(s+_("9"));
- }
- void CalcFrame::OnButton9Click(wxCommandEvent& event)
- {
- wxString s;
- s=TextCtrl1->GetValue();
- TextCtrl1->SetValue(s+_("0"));
- }
- void CalcFrame::OnButton4Click(wxCommandEvent& event)
- {
- wxString s;
- s=TextCtrl1->GetValue();
- TextCtrl1->SetValue(s+_("1"));
- }
- void CalcFrame::OnButton5Click(wxCommandEvent& event)
- {
- wxString s;
- s=TextCtrl1->GetValue();
- TextCtrl1->SetValue(s+_("2"));
- }
- void CalcFrame::OnButton6Click(wxCommandEvent& event)
- {
- wxString s;
- s=TextCtrl1->GetValue();
- TextCtrl1->SetValue(s+_("3"));
- }
- void CalcFrame::OnButton13Click(wxCommandEvent& event)
- {
- wxString s;
- s=TextCtrl1->GetValue();
- TextCtrl1->SetValue(s+_("4"));
- }
- void CalcFrame::OnButton8Click(wxCommandEvent& event)
- {
- wxString s;
- s=TextCtrl1->GetValue();
- TextCtrl1->SetValue(s+_("5"));
- }
- void CalcFrame::OnButton10Click(wxCommandEvent& event)
- {
- wxString s;
- s=TextCtrl1->GetValue();
- TextCtrl1->SetValue(s+_("6"));
- }
- void CalcFrame::OnButton16Click(wxCommandEvent& event)
- {
- wxString s;
- s=TextCtrl1->GetValue();
- TextCtrl1->SetValue(s+_("7"));
- }
- void CalcFrame::OnButton12Click(wxCommandEvent& event)
- {
- wxString s;
- s=TextCtrl1->GetValue();
- TextCtrl1->SetValue(s+_("8"));
- }
- void CalcFrame::OnButton1Click(wxCommandEvent& event)
- {
- wxString s;
- s=TextCtrl1->GetValue();
- TextCtrl1->SetValue(s+_(","));
- }
- void CalcFrame::OnButton17Click(wxCommandEvent& event)
- {
- wxString s;
- TextCtrl1->SetValue(_(""));
- }
- void CalcFrame::OnButton14Click(wxCommandEvent& event)
- {
- wxString s;
- s=TextCtrl1->GetValue();
- s=s.substr(0,s.length()-1);
- TextCtrl1->SetValue(s);
- }
- void CalcFrame::OnButton3Click(wxCommandEvent& event)
- {
- wxString s;
- s=TextCtrl1->GetValue();
- if (!s.ToDouble(&num1)){}
- op='+';
- TextCtrl1->SetValue(_(""));
- }
- void CalcFrame::OnButton7Click(wxCommandEvent& event)
- {
- wxString s;
- s=TextCtrl1->GetValue();
- if (!s.ToDouble(&num1)){}
- op='-';
- TextCtrl1->SetValue(_(""));
- }
- void CalcFrame::OnButton11Click(wxCommandEvent& event)
- {
- wxString s;
- s=TextCtrl1->GetValue();
- if (!s.ToDouble(&num1)){}
- op='/';
- TextCtrl1->SetValue(_(""));
- }
- void CalcFrame::OnButton18Click(wxCommandEvent& event)
- {
- wxString s;
- s=TextCtrl1->GetValue();
- if (!s.ToDouble(&num1)){}
- op='*';
- TextCtrl1->SetValue(_(""));
- }
- void CalcFrame::OnButton2Click(wxCommandEvent& event)
- {
- wxString s;
- s=TextCtrl1->GetValue();
- if (!s.ToDouble(&num2)){}
- wxString mystring;
- if(op=='+'){mystring = wxString::Format(wxT("%f"), (num1+num2));}
- if(op=='-'){mystring = wxString::Format(wxT("%f"), (num1-num2));}
- if(op=='/'){mystring = wxString::Format(wxT("%f"), (num1/num2));}
- if(op=='*'){mystring = wxString::Format(wxT("%f"), (num1*num2));}
- TextCtrl1->SetValue(mystring);
- }
- void CalcFrame::OnButton15Click(wxCommandEvent& event)
- {
- wxString s;
- double aux;
- s=TextCtrl1->GetValue();
- if (!s.ToDouble(&aux)){}
- aux=aux*-1;
- wxString mystring;
- mystring = wxString::Format(wxT("%f"), (aux));
- TextCtrl1->SetValue(mystring);
- }
- void CalcFrame::OnTextCtrl1Text(wxCommandEvent& event)
- {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement