]>
git.saurik.com Git - wxWidgets.git/blob - samples/controls/controls.cpp
7ecbdf18d92f6d1335d2331459b3317f2a1d267d
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
);
54 wxNotebook
*m_notebook
;
59 class MyFrame
: public wxFrame
63 MyFrame(wxFrame
*frame
, char *title
, int x
, int y
, int w
, int h
);
67 void OnQuit(wxCommandEvent
& event
);
68 void OnAbout(wxCommandEvent
& event
);
69 bool OnClose(void) { return TRUE
; }
74 //----------------------------------------------------------------------
76 //----------------------------------------------------------------------
80 //----------------------------------------------------------------------
82 //----------------------------------------------------------------------
84 const MINIMAL_QUIT
= 100;
85 const MINIMAL_TEXT
= 101;
86 const MINIMAL_ABOUT
= 102;
88 bool MyApp::OnInit(void)
90 // Create the main frame window
91 MyFrame
*frame
= new MyFrame(NULL
, "Controls wxWindows App", 50, 50, 500, 420 );
95 frame
->SetIcon(wxIcon("mondrian"));
98 frame
->SetIcon(wxIcon("aiai.xbm"));
101 wxMenu
*file_menu
= new wxMenu
;
103 file_menu
->Append(MINIMAL_ABOUT
, "&About");
104 file_menu
->Append(MINIMAL_QUIT
, "E&xit");
105 wxMenuBar
*menu_bar
= new wxMenuBar
;
106 menu_bar
->Append(file_menu
, "&File");
107 frame
->SetMenuBar(menu_bar
);
116 //----------------------------------------------------------------------
118 //----------------------------------------------------------------------
120 const ID_NOTEBOOK
= 1000;
122 const ID_LISTBOX
= 130;
123 const ID_LISTBOX_SEL_NUM
= 131;
124 const ID_LISTBOX_SEL_STR
= 132;
125 const ID_LISTBOX_CLEAR
= 133;
126 const ID_LISTBOX_APPEND
= 134;
128 const ID_CHOICE
= 120;
129 const ID_CHOICE_SEL_NUM
= 121;
130 const ID_CHOICE_SEL_STR
= 122;
131 const ID_CHOICE_CLEAR
= 123;
132 const ID_CHOICE_APPEND
= 124;
134 const ID_COMBO
= 140;
138 BEGIN_EVENT_TABLE(MyPanel
, wxPanel
)
139 EVT_SIZE ( MyPanel::OnSize
)
140 EVT_LISTBOX (ID_LISTBOX
, MyPanel::OnListBox
)
141 EVT_BUTTON (ID_LISTBOX_SEL_NUM
, MyPanel::OnListBoxButtons
)
142 EVT_BUTTON (ID_LISTBOX_SEL_STR
, MyPanel::OnListBoxButtons
)
143 EVT_BUTTON (ID_LISTBOX_CLEAR
, MyPanel::OnListBoxButtons
)
144 EVT_BUTTON (ID_LISTBOX_APPEND
, MyPanel::OnListBoxButtons
)
147 MyPanel::MyPanel( wxFrame
*frame
, int x
, int y
, int w
, int h
) :
148 wxPanel( frame
, -1, wxPoint(x
, y
), wxSize(w
, h
) )
150 m_text
= new wxTextCtrl( this, -1, "This is the log window.\n", wxPoint(0,50), wxSize(100,50), wxTE_MULTILINE
);
152 m_notebook
= new wxNotebook( this, ID_NOTEBOOK
, wxPoint(0,0), wxSize(200,150) );
159 "wonderfull example.",
167 wxPanel
*panel
= new wxPanel(m_notebook
);
168 m_listbox
= new wxListBox( panel
, ID_LISTBOX
, wxPoint(10,10), wxSize(120,70), 9, choices
);
169 (void)new wxButton( panel
, ID_LISTBOX_SEL_NUM
, "Select #2", wxPoint(180,30), wxSize(100,30) );
170 (void)new wxButton( panel
, ID_LISTBOX_SEL_STR
, "Select 'This'", wxPoint(300,30), wxSize(100,30) );
171 (void)new wxButton( panel
, ID_LISTBOX_CLEAR
, "Clear", wxPoint(180,80), wxSize(100,30) );
172 (void)new wxButton( panel
, ID_LISTBOX_APPEND
, "Append 'Hi!'", wxPoint(300,80), wxSize(100,30) );
173 m_notebook
->AddPage(panel
, "wxList");
175 panel
= new wxPanel(m_notebook
);
176 m_choice
= new wxChoice( panel
, ID_CHOICE
, wxPoint(10,10), wxSize(120,-1), 9, choices
);
177 m_notebook
->AddPage(panel
, "wxChoice");
179 panel
= new wxPanel(m_notebook
);
180 m_combo
= new wxComboBox( panel
, ID_COMBO
, "This", wxPoint(10,10), wxSize(120,-1), 9, choices
);
181 m_notebook
->AddPage(panel
, "wxComboBox");
183 wxTextCtrl
*text
= new wxTextCtrl( m_notebook
, ID_TEXT
, "Write text here.", wxPoint(10,10), wxSize(120,100), wxTE_MULTILINE
);
184 m_notebook
->AddPage( text
, "wxTextCtrl" );
187 void MyPanel::OnSize( wxSizeEvent
& WXUNUSED(event
) )
191 GetClientSize( &x
, &y
);
193 if (m_notebook
) m_notebook
->SetSize( 2, 2, x
-4, y
/2-4 );
194 if (m_text
) m_text
->SetSize( 2, y
/2+2, x
-4, y
/2-4 );
197 void MyPanel::OnListBox( wxCommandEvent
&event
)
199 m_text
->WriteText( "ListBox Event:\n");
200 m_text
->WriteText( "ListBox selection string is: " );
201 m_text
->WriteText( event
.GetString() );
202 m_text
->WriteText( "\n" );
205 void MyPanel::OnListBoxButtons( wxCommandEvent
&WXUNUSED(event
) )
207 if (m_notebook
->GetPageCount() > 1)
208 m_notebook
->DeletePage( 1 );
211 //----------------------------------------------------------------------
213 //----------------------------------------------------------------------
215 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
216 EVT_MENU(MINIMAL_QUIT
, MyFrame::OnQuit
)
217 EVT_MENU(MINIMAL_ABOUT
, MyFrame::OnAbout
)
220 MyFrame::MyFrame(wxFrame
*frame
, char *title
, int x
, int y
, int w
, int h
):
221 wxFrame(frame
, -1, title
, wxPoint(x
, y
), wxSize(w
, h
))
223 (void*) new MyPanel( this, 10, 10, 300, 100 );
226 void MyFrame::OnQuit (wxCommandEvent
& WXUNUSED(event
) )
231 void MyFrame::OnAbout( wxCommandEvent
& WXUNUSED(event
) )
233 wxMessageDialog
dialog(this, "This is a control sample", "About Controls", wxOK
);