Advertisement
Guest User

Untitled

a guest
Dec 12th, 2018
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.23 KB | None | 0 0
  1. /***************************************************************
  2.  * Name:      Zadanie_2Main.cpp
  3.  * Purpose:   Code for Application Frame
  4.  * Author:    Bartłomiej K. (bkotarski1@gmail.com)
  5.  * Created:   2018-12-10
  6.  * Copyright: Bartłomiej K. ()
  7.  * License:
  8.  **************************************************************/
  9.  
  10. #include "Zadanie_2Main.h"
  11. #include <wx/msgdlg.h>
  12.  
  13. //(*InternalHeaders(Zadanie_2Frame)
  14. #include <wx/settings.h>
  15. #include <wx/intl.h>
  16. #include <wx/string.h>
  17. //*)
  18.  
  19. //helper functions
  20. enum wxbuildinfoformat {
  21.     short_f, long_f };
  22.  
  23. wxString wxbuildinfo(wxbuildinfoformat format)
  24. {
  25.     wxString wxbuild(wxVERSION_STRING);
  26.  
  27.     if (format == long_f )
  28.     {
  29. #if defined(__WXMSW__)
  30.         wxbuild << _T("-Windows");
  31. #elif defined(__UNIX__)
  32.         wxbuild << _T("-Linux");
  33. #endif
  34.  
  35. #if wxUSE_UNICODE
  36.         wxbuild << _T("-Unicode build");
  37. #else
  38.         wxbuild << _T("-ANSI build");
  39. #endif // wxUSE_UNICODE
  40.     }
  41.  
  42.     return wxbuild;
  43. }
  44.  
  45. //(*IdInit(Zadanie_2Frame)
  46. const long Zadanie_2Frame::ID_TEXTCTRL1 = wxNewId();
  47. const long Zadanie_2Frame::ID_STATICTEXT1 = wxNewId();
  48. const long Zadanie_2Frame::ID_TEXTCTRL2 = wxNewId();
  49. const long Zadanie_2Frame::ID_STATICTEXT2 = wxNewId();
  50. const long Zadanie_2Frame::ID_BUTTON1 = wxNewId();
  51. const long Zadanie_2Frame::ID_TEXTCTRL3 = wxNewId();
  52. const long Zadanie_2Frame::ID_STATICTEXT3 = wxNewId();
  53. const long Zadanie_2Frame::ID_BUTTON2 = wxNewId();
  54. const long Zadanie_2Frame::ID_BUTTON3 = wxNewId();
  55. const long Zadanie_2Frame::ID_BUTTON4 = wxNewId();
  56. const long Zadanie_2Frame::idMenuQuit = wxNewId();
  57. const long Zadanie_2Frame::idMenuAbout = wxNewId();
  58. const long Zadanie_2Frame::ID_STATUSBAR1 = wxNewId();
  59. //*)
  60.  
  61. BEGIN_EVENT_TABLE(Zadanie_2Frame,wxFrame)
  62.     //(*EventTable(Zadanie_2Frame)
  63.     //*)
  64. END_EVENT_TABLE()
  65.  
  66. Zadanie_2Frame::Zadanie_2Frame(wxWindow* parent,wxWindowID id)
  67. {
  68.     //(*Initialize(Zadanie_2Frame)
  69.     wxMenuItem* MenuItem2;
  70.     wxMenuItem* MenuItem1;
  71.     wxMenu* Menu1;
  72.     wxMenuBar* MenuBar1;
  73.     wxMenu* Menu2;
  74.  
  75.     Create(parent, wxID_ANY, _("Kalkulator"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, _T("wxID_ANY"));
  76.     SetClientSize(wxSize(400,300));
  77.     SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT));
  78.     TextCtrl1 = new wxTextCtrl(this, ID_TEXTCTRL1, wxEmptyString, wxPoint(48,40), wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL1"));
  79.     TextCtrl1->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_GRADIENTINACTIVECAPTION));
  80.     StaticText1 = new wxStaticText(this, ID_STATICTEXT1, _("X"), wxPoint(24,48), wxSize(16,13), 0, _T("ID_STATICTEXT1"));
  81.     TextCtrl2 = new wxTextCtrl(this, ID_TEXTCTRL2, wxEmptyString, wxPoint(48,80), wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL2"));
  82.     TextCtrl2->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_GRADIENTINACTIVECAPTION));
  83.     StaticText2 = new wxStaticText(this, ID_STATICTEXT2, _("Y"), wxPoint(24,80), wxDefaultSize, 0, _T("ID_STATICTEXT2"));
  84.     Button1 = new wxButton(this, ID_BUTTON1, _("+"), wxPoint(264,40), wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON1"));
  85.     Button1->SetForegroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT));
  86.     Button1->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BACKGROUND));
  87.     TextCtrl3 = new wxTextCtrl(this, ID_TEXTCTRL3, wxEmptyString, wxPoint(48,160), wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL3"));
  88.     StaticText3 = new wxStaticText(this, ID_STATICTEXT3, _("Result"), wxPoint(8,168), wxDefaultSize, 0, _T("ID_STATICTEXT3"));
  89.     Button2 = new wxButton(this, ID_BUTTON2, _("-"), wxPoint(264,72), wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON2"));
  90.     Button2->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BACKGROUND));
  91.     Button3 = new wxButton(this, ID_BUTTON3, _("*"), wxPoint(264,104), wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON3"));
  92.     Button3->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BACKGROUND));
  93.     Button4 = new wxButton(this, ID_BUTTON4, _("/"), wxPoint(264,136), wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON4"));
  94.     Button4->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BACKGROUND));
  95.     MenuBar1 = new wxMenuBar();
  96.     Menu1 = new wxMenu();
  97.     MenuItem1 = new wxMenuItem(Menu1, idMenuQuit, _("Quit\tAlt-F4"), _("Quit the application"), wxITEM_NORMAL);
  98.     Menu1->Append(MenuItem1);
  99.     MenuBar1->Append(Menu1, _("&File"));
  100.     Menu2 = new wxMenu();
  101.     MenuItem2 = new wxMenuItem(Menu2, idMenuAbout, _("About\tF1"), _("Show info about this application"), wxITEM_NORMAL);
  102.     Menu2->Append(MenuItem2);
  103.     MenuBar1->Append(Menu2, _("Help"));
  104.     SetMenuBar(MenuBar1);
  105.     StatusBar1 = new wxStatusBar(this, ID_STATUSBAR1, 0, _T("ID_STATUSBAR1"));
  106.     int __wxStatusBarWidths_1[1] = { -1 };
  107.     int __wxStatusBarStyles_1[1] = { wxSB_NORMAL };
  108.     StatusBar1->SetFieldsCount(1,__wxStatusBarWidths_1);
  109.     StatusBar1->SetStatusStyles(1,__wxStatusBarStyles_1);
  110.     SetStatusBar(StatusBar1);
  111.     Center();
  112.  
  113.     Connect(ID_BUTTON1,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&Zadanie_2Frame::OnButton1Click);
  114.     Connect(ID_BUTTON2,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&Zadanie_2Frame::OnButton2Click);
  115.     Connect(ID_BUTTON3,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&Zadanie_2Frame::OnButton3Click);
  116.     Connect(ID_BUTTON4,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&Zadanie_2Frame::OnButton4Click);
  117.     Connect(idMenuQuit,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&Zadanie_2Frame::OnQuit);
  118.     Connect(idMenuAbout,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&Zadanie_2Frame::OnAbout);
  119.     //*)
  120. }
  121.  
  122. Zadanie_2Frame::~Zadanie_2Frame()
  123. {
  124.     //(*Destroy(Zadanie_2Frame)
  125.     //*)
  126. }
  127.  
  128. void Zadanie_2Frame::OnQuit(wxCommandEvent& event)
  129. {
  130.     Close();
  131. }
  132.  
  133. void Zadanie_2Frame::OnAbout(wxCommandEvent& event)
  134. {
  135.     wxString msg = wxbuildinfo(long_f);
  136.     wxMessageBox(msg, _("Welcome to..."));
  137. }
  138.  
  139. void Zadanie_2Frame::OnButton1Click(wxCommandEvent& event)
  140. {
  141.     long x =0, y=0;
  142.     wxString res = wxT("");
  143.     if(TextCtrl1->GetValue().ToLong((&x)) && TextCtrl2->GetValue().ToLong((&y)))
  144.     {
  145.         res << x+y;
  146.         TextCtrl3 -> SetValue(res);
  147.     }else wxMessageBox(wxT("Error"));
  148. }
  149.  
  150. void Zadanie_2Frame::OnButton2Click(wxCommandEvent& event)
  151. {
  152.     long x =0, y=0;
  153.     wxString res = wxT("");
  154.     if(TextCtrl1->GetValue().ToLong((&x)) && TextCtrl2->GetValue().ToLong((&y)))
  155.     {
  156.         res << x-y;
  157.         TextCtrl3 -> SetValue(res);
  158.     }else wxMessageBox(wxT("Error"));
  159. }
  160.  
  161. void Zadanie_2Frame::OnButton3Click(wxCommandEvent& event)
  162. {
  163.      long x =0, y=0;
  164.     wxString res = wxT("");
  165.     if(TextCtrl1->GetValue().ToLong((&x)) && TextCtrl2->GetValue().ToLong((&y)))
  166.     {
  167.         res << x*y;
  168.         TextCtrl3 -> SetValue(res);
  169.     }else wxMessageBox(wxT("Error"));
  170. }
  171.  
  172. void Zadanie_2Frame::OnButton4Click(wxCommandEvent& event)
  173. {
  174.     long x =0, y=0;
  175.     wxString res = wxT("");
  176.     if(TextCtrl1->GetValue().ToLong((&x)) && TextCtrl2->GetValue().ToLong((&y)))
  177.     {
  178.         if(y == 0)
  179.             wxMessageBox(wxT("Nie dziel przez 0"));
  180.         else
  181.         {
  182.             res << x/y;
  183.             TextCtrl3 -> SetValue(res);
  184.         }
  185.     }else wxMessageBox(wxT("Error"));
  186. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement