]>
git.saurik.com Git - wxWidgets.git/blob - samples/controls/minimal.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Controls wxWindows sample
4 // Author: Robert Roebling
7 // Copyright: (c) Robert Roebling, Julian Smart and Markus Holzem
8 // Licence: wxWindows license
9 /////////////////////////////////////////////////////////////////////////////
12 #pragma implementation "minimal.cpp"
13 #pragma interface "minimal.cpp"
16 // For compilers that support precompilation, includes "wx/wx.h".
17 #include "wx/wxprec.h"
27 #include "wx/notebook.h"
29 //----------------------------------------------------------------------
31 //----------------------------------------------------------------------
33 class MyApp
: public wxApp
39 class MyPanel
: public wxPanel
43 MyPanel(wxFrame
*frame
, int x
, int y
, int w
, int h
);
45 void OnSize( wxSizeEvent
& event
);
46 void OnListBox( wxCommandEvent
&event
);
47 void OnListBoxButtons( wxCommandEvent
&event
);
52 wxNotebook
*m_notebook
;
57 class MyFrame
: public wxFrame
61 MyFrame(wxFrame
*frame
, char *title
, int x
, int y
, int w
, int h
);
65 void OnQuit(wxCommandEvent
& event
);
66 void OnAbout(wxCommandEvent
& event
);
67 bool OnClose(void) { return TRUE
; }
72 //----------------------------------------------------------------------
74 //----------------------------------------------------------------------
78 //----------------------------------------------------------------------
80 //----------------------------------------------------------------------
82 const MINIMAL_QUIT
= 100;
83 const MINIMAL_TEXT
= 101;
84 const MINIMAL_ABOUT
= 102;
86 bool MyApp::OnInit(void)
88 // Create the main frame window
89 MyFrame
*frame
= new MyFrame(NULL
, "Controls wxWindows App", 50, 50, 500, 420 );
93 frame
->SetIcon(wxIcon("mondrian"));
96 frame
->SetIcon(wxIcon("aiai.xbm"));
99 wxMenu
*file_menu
= new wxMenu
;
101 file_menu
->Append(MINIMAL_ABOUT
, "&About");
102 file_menu
->Append(MINIMAL_QUIT
, "E&xit");
103 wxMenuBar
*menu_bar
= new wxMenuBar
;
104 menu_bar
->Append(file_menu
, "&File");
105 frame
->SetMenuBar(menu_bar
);
114 //----------------------------------------------------------------------
116 //----------------------------------------------------------------------
118 const ID_NOTEBOOK
= 1000;
120 const ID_LISTBOX
= 130;
121 const ID_LISTBOX_SEL_NUM
= 131;
122 const ID_LISTBOX_SEL_STR
= 132;
123 const ID_LISTBOX_CLEAR
= 133;
124 const ID_LISTBOX_APPEND
= 134;
126 BEGIN_EVENT_TABLE(MyPanel
, wxPanel
)
127 EVT_SIZE ( MyPanel::OnSize
)
128 EVT_LISTBOX (ID_LISTBOX
, MyPanel::OnListBox
)
129 EVT_BUTTON (ID_LISTBOX_SEL_NUM
, MyPanel::OnListBoxButtons
)
130 EVT_BUTTON (ID_LISTBOX_SEL_STR
, MyPanel::OnListBoxButtons
)
131 EVT_BUTTON (ID_LISTBOX_CLEAR
, MyPanel::OnListBoxButtons
)
132 EVT_BUTTON (ID_LISTBOX_APPEND
, MyPanel::OnListBoxButtons
)
135 MyPanel::MyPanel( wxFrame
*frame
, int x
, int y
, int w
, int h
) :
136 wxPanel( frame
, -1, wxPoint(x
, y
), wxSize(w
, h
) )
138 m_text
= new wxTextCtrl( this, -1, "This is the log window.\n", wxPoint(0,50), wxSize(100,50), wxTE_MULTILINE
);
140 m_notebook
= new wxNotebook( this, ID_NOTEBOOK
, wxPoint(0,0), wxSize(200,150) );
142 wxString choices
[4] =
147 "wonderfull example."
150 wxPanel
*panel
= m_notebook
->CreatePage( 0, "wxList" );
152 m_listbox
= new wxListBox( panel
, ID_LISTBOX
, wxPoint(10,10), wxSize(120,70), 4, choices
);
153 (void)new wxButton( panel
, ID_LISTBOX_SEL_NUM
, "Select #2", wxPoint(140,30), wxSize(100,30) );
154 (void)new wxButton( panel
, ID_LISTBOX_SEL_STR
, "Select 'This'", wxPoint(260,30), wxSize(100,30) );
155 (void)new wxButton( panel
, ID_LISTBOX_CLEAR
, "Clear", wxPoint(140,80), wxSize(100,30) );
156 (void)new wxButton( panel
, ID_LISTBOX_APPEND
, "Append 'Hi!'", wxPoint(260,80), wxSize(100,30) );
158 m_notebook
->CreatePage( 1, "wxChoice" );
161 void MyPanel::OnSize( wxSizeEvent
& WXUNUSED(event
) )
165 GetClientSize( &x
, &y
);
167 if (m_notebook
) m_notebook
->SetSize( 2, 2, x
-4, y
/2-4 );
168 if (m_text
) m_text
->SetSize( 2, y
/2+2, x
-4, y
/2-4 );
171 void MyPanel::OnListBox( wxCommandEvent
&event
)
173 m_text
->WriteText( "ListBox Event:\n");
174 m_text
->WriteText( "ListBox selection string is: " );
175 m_text
->WriteText( event
.GetString() );
176 m_text
->WriteText( "\n" );
179 void MyPanel::OnListBoxButtons( wxCommandEvent
&WXUNUSED(event
) )
183 //----------------------------------------------------------------------
185 //----------------------------------------------------------------------
187 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
188 EVT_MENU(MINIMAL_QUIT
, MyFrame::OnQuit
)
189 EVT_MENU(MINIMAL_ABOUT
, MyFrame::OnAbout
)
192 MyFrame::MyFrame(wxFrame
*frame
, char *title
, int x
, int y
, int w
, int h
):
193 wxFrame(frame
, -1, title
, wxPoint(x
, y
), wxSize(w
, h
))
195 (void*) new MyPanel( this, 10, 10, 300, 100 );
198 void MyFrame::OnQuit (wxCommandEvent
& WXUNUSED(event
) )
203 void MyFrame::OnAbout( wxCommandEvent
& WXUNUSED(event
) )
205 wxMessageDialog
dialog(this, "This is a control sample", "About Controls", wxOK
);