001: #include <wx/wx.h>
002:
003: const int ID_SAY_HELLO = 1000;
004: const int ID_SAY_GOODBYE = 1001;
005:
006: /**
007: A frame with buttons that add greetings to a
008: text control.
009: */
010: class ButtonFrame : public wxFrame
011: {
012: public:
013: /**
014: Constructs and lays out the text control and buttons.
015: */
016: ButtonFrame();
017: /**
018: Adds a "Hello, World!" message to the text control.
019: @param event the event descriptor
020: */
021: void OnSayHello(wxCommandEvent& event);
022: /**
023: Adds a "Goodbye, World!" message to the text control.
024: @param event the event descriptor
025: */
026: void OnSayGoodbye(wxCommandEvent& event);
027: private:
028: wxTextCtrl* text;
029: DECLARE_EVENT_TABLE()
030: };
031:
032: /**
033: An application to demonstrate button layout.
034: */
035: class ButtonApp : public wxApp
036: {
037: public:
038: /**
039: Constructs the frame.
040: */
041: ButtonApp();
042: /**
043: Shows the frame.
044: @return true
045: */
046: virtual bool OnInit();
047: private:
048: ButtonFrame* frame;
049: };
050:
051: DECLARE_APP(ButtonApp)
052:
053: IMPLEMENT_APP(ButtonApp)
054:
055: BEGIN_EVENT_TABLE(ButtonFrame, wxFrame)
056: EVT_BUTTON(ID_SAY_HELLO, ButtonFrame::OnSayHello)
057: EVT_BUTTON(ID_SAY_GOODBYE, ButtonFrame::OnSayGoodbye)
058: END_EVENT_TABLE()
059:
060: ButtonFrame::ButtonFrame()
061: : wxFrame(NULL, -1, "ButtonFrame")
062: {
063: text = new wxTextCtrl(this, -1, "",
064: wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE);
065:
066: wxButton* hello_button = new wxButton(this,
067: ID_SAY_HELLO, "Say Hello");
068:
069: wxButton* goodbye_button = new wxButton(this,
070: ID_SAY_GOODBYE, "Say Goodbye");
071:
072: wxBoxSizer* button_sizer = new wxBoxSizer(wxHORIZONTAL);
073: button_sizer->Add(hello_button);
074: button_sizer->Add(goodbye_button);
075:
076: wxBoxSizer* frame_sizer = new wxBoxSizer(wxVERTICAL);
077: frame_sizer->Add(text, 1, wxGROW);
078: frame_sizer->Add(button_sizer, 0, wxALIGN_CENTER);
079:
080: SetAutoLayout(true);
081: SetSizer(frame_sizer);
082: }
083:
084: void ButtonFrame::OnSayHello(wxCommandEvent& event)
085: {
086: text->AppendText("Hello, World!\n");
087: }
088:
089: void ButtonFrame::OnSayGoodbye(wxCommandEvent& event)
090: {
091: text->AppendText("Goodbye, World!\n");
092: }
093:
094: ButtonApp::ButtonApp()
095: {
096: frame = new ButtonFrame();
097: }
098:
099: bool ButtonApp::OnInit()
100: {
101: frame->Show(true);
102: return true;
103: }