]> git.saurik.com Git - wxWidgets.git/blame - samples/checklst/checklst.cpp
Tcl regex lib
[wxWidgets.git] / samples / checklst / checklst.cpp
CommitLineData
457814b5
JS
1///////////////////////////////////////////////////////////////////////////////
2// Name: checklst.cpp
3// Purpose: wxCheckListBox sample
4// Author: Vadim Zeitlin
655822f3 5// Modified by:
457814b5
JS
6// Created: 13.11.97
7// RCS-ID: $Id$
8// Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9// Licence: wxWindows license
10///////////////////////////////////////////////////////////////////////////////
11
3349fe92 12#ifdef __GNUG__
bbdbfb0e 13 //#pragma implementation
3349fe92 14#endif
457814b5
JS
15
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#ifdef __BORLANDC__
bbdbfb0e 20 #pragma hdrstop
457814b5
JS
21#endif
22
23#ifndef WX_PRECOMP
bbdbfb0e 24#include "wx/wx.h"
457814b5
JS
25#endif
26
b292e2f5 27#ifdef __WXMSW__
bbdbfb0e 28 #include "wx/ownerdrw.h"
b292e2f5 29#endif
bbdbfb0e
VZ
30
31#include "wx/log.h"
32
d8d474af 33#include "wx/sizer.h"
457814b5 34#include "wx/menuitem.h"
b292e2f5
RR
35#include "wx/checklst.h"
36
457814b5
JS
37// Define a new application type
38class CheckListBoxApp: public wxApp
39{
40public:
bbdbfb0e 41 bool OnInit();
457814b5
JS
42};
43
44// Define a new frame type
45class CheckListBoxFrame : public wxFrame
46{
47public:
bbdbfb0e
VZ
48 // ctor & dtor
49 CheckListBoxFrame(wxFrame *frame, const char *title,
df7d383f
VZ
50 int x, int y, int w, int h);
51 virtual ~CheckListBoxFrame();
bbdbfb0e
VZ
52
53 // notifications
54 void OnQuit (wxCommandEvent& event);
55 void OnAbout (wxCommandEvent& event);
df7d383f 56 void OnToggleSelection(wxCommandEvent& event);
bbdbfb0e
VZ
57 void OnListboxSelect (wxCommandEvent& event);
58 void OnCheckboxToggle (wxCommandEvent& event);
59 void OnListboxDblClick(wxCommandEvent& event);
60 void OnButtonUp (wxCommandEvent& event);
61 void OnButtonDown (wxCommandEvent& event);
457814b5 62
bbdbfb0e 63private:
df7d383f
VZ
64 void CreateCheckListbox(long flags = 0);
65
bbdbfb0e 66 void OnButtonMove(bool up);
457814b5 67
f048e32f
VZ
68 void AdjustColour(size_t index);
69
df7d383f
VZ
70 wxPanel *m_panel;
71
bbdbfb0e 72 wxCheckListBox *m_pListBox;
457814b5 73
bbdbfb0e 74 DECLARE_EVENT_TABLE()
457814b5
JS
75};
76
655822f3
VZ
77enum
78{
df7d383f
VZ
79 Menu_About = 100,
80 Menu_Quit,
81 Menu_Selection,
82
bbdbfb0e
VZ
83 Control_First = 1000,
84 Control_Listbox,
85 Btn_Up,
86 Btn_Down
457814b5
JS
87};
88
89BEGIN_EVENT_TABLE(CheckListBoxFrame, wxFrame)
df7d383f 90 EVT_MENU(Menu_About, CheckListBoxFrame::OnAbout)
bbdbfb0e
VZ
91 EVT_MENU(Menu_Quit, CheckListBoxFrame::OnQuit)
92
df7d383f
VZ
93 EVT_MENU(Menu_Selection, CheckListBoxFrame::OnToggleSelection)
94
bbdbfb0e
VZ
95 EVT_LISTBOX(Control_Listbox, CheckListBoxFrame::OnListboxSelect)
96 EVT_CHECKLISTBOX(Control_Listbox, CheckListBoxFrame::OnCheckboxToggle)
97 EVT_LISTBOX_DCLICK(Control_Listbox, CheckListBoxFrame::OnListboxDblClick)
98
99 EVT_BUTTON(Btn_Up, CheckListBoxFrame::OnButtonUp)
100 EVT_BUTTON(Btn_Down, CheckListBoxFrame::OnButtonDown)
457814b5
JS
101END_EVENT_TABLE()
102
103IMPLEMENT_APP(CheckListBoxApp);
104
105// init our app: create windows
106bool CheckListBoxApp::OnInit(void)
107{
bbdbfb0e
VZ
108 CheckListBoxFrame *pFrame = new CheckListBoxFrame
109 (
110 NULL,
df7d383f 111 _T("wxWindows Checklistbox Sample"),
bbdbfb0e
VZ
112 50, 50, 480, 320
113 );
114 SetTopWindow(pFrame);
115
116 return TRUE;
457814b5
JS
117}
118
119// main frame constructor
bbdbfb0e 120CheckListBoxFrame::CheckListBoxFrame(wxFrame *frame,
df7d383f
VZ
121 const wxChar *title,
122 int x, int y, int w, int h)
123 : wxFrame(frame, -1, title, wxPoint(x, y), wxSize(w, h))
457814b5 124{
bbdbfb0e
VZ
125 // create the status line
126 const int widths[] = { -1, 60 };
127 CreateStatusBar(2);
128 SetStatusWidths(2, widths);
befa6d98 129 wxLogStatus(this, _T("no selection"));
bbdbfb0e
VZ
130
131 // Make a menubar
df7d383f 132 // --------------
bbdbfb0e 133
df7d383f
VZ
134 // file submenu
135 wxMenu *menuFile = new wxMenu;
136 menuFile->Append(Menu_About, _T("&About...\tF1"));
137 menuFile->AppendSeparator();
138 menuFile->Append(Menu_Quit, _T("E&xit\tAlt-X"));
bbdbfb0e 139
df7d383f
VZ
140 // listbox submenu
141 wxMenu *menuList = new wxMenu;
142 menuList->AppendCheckItem(Menu_Selection, _T("Multiple selection\tCtrl-M"));
143
144 // put it all together
bbdbfb0e 145 wxMenuBar *menu_bar = new wxMenuBar;
df7d383f
VZ
146 menu_bar->Append(menuFile, _T("&File"));
147 menu_bar->Append(menuList, _T("&List"));
bbdbfb0e
VZ
148 SetMenuBar(menu_bar);
149
150 // make a panel with some controls
df7d383f
VZ
151 m_panel = new wxPanel(this, -1, wxPoint(0, 0),
152 wxSize(400, 200), wxTAB_TRAVERSAL);
153
154 CreateCheckListbox();
155
156 // create buttons for moving the items around
157 wxButton *button1 = new wxButton(m_panel, Btn_Up, _T(" &Up "), wxPoint(420, 90));
158 wxButton *button2 = new wxButton(m_panel, Btn_Down, _T("&Down"), wxPoint(420, 120));
159
160
161 wxBoxSizer *mainsizer = new wxBoxSizer( wxVERTICAL );
162
163 mainsizer->Add( m_pListBox, 1, wxGROW|wxALL, 10 );
bbdbfb0e 164
df7d383f
VZ
165 wxBoxSizer *bottomsizer = new wxBoxSizer( wxHORIZONTAL );
166
167 bottomsizer->Add( button1, 0, wxALL, 10 );
168 bottomsizer->Add( button2, 0, wxALL, 10 );
169
170 mainsizer->Add( bottomsizer, 0, wxCENTER );
171
172 // tell frame to make use of sizer (or constraints, if any)
173 m_panel->SetAutoLayout( TRUE );
174 m_panel->SetSizer( mainsizer );
175
176 // don't allow frame to get smaller than what the sizers tell ye
177 mainsizer->SetSizeHints( this );
178
179 Show(TRUE);
180}
181
182void CheckListBoxFrame::CreateCheckListbox(long flags)
183{
bbdbfb0e 184 // check list box
df7d383f 185 static const wxChar *aszChoices[] =
bbdbfb0e 186 {
df7d383f
VZ
187 _T("Zeroth"),
188 _T("First"), _T("Second"), _T("Third"),
189 _T("Fourth"), _T("Fifth"), _T("Sixth"),
190 _T("Seventh"), _T("Eighth"), _T("Nineth")
bbdbfb0e
VZ
191 };
192
193 wxString *astrChoices = new wxString[WXSIZEOF(aszChoices)];
194 unsigned int ui;
195 for ( ui = 0; ui < WXSIZEOF(aszChoices); ui++ )
196 astrChoices[ui] = aszChoices[ui];
197
198 m_pListBox = new wxCheckListBox
199 (
df7d383f 200 m_panel, // parent
bbdbfb0e
VZ
201 Control_Listbox, // control id
202 wxPoint(10, 10), // listbox poistion
8e1d4f96 203 wxSize(400, 100), // listbox size
bbdbfb0e 204 WXSIZEOF(aszChoices), // number of strings
df7d383f
VZ
205 astrChoices, // array of strings
206 flags
bbdbfb0e
VZ
207 );
208
209 //m_pListBox->SetBackgroundColour(*wxGREEN);
210
211 delete [] astrChoices;
212
bbdbfb0e
VZ
213 // set grey background for every second entry
214 for ( ui = 0; ui < WXSIZEOF(aszChoices); ui += 2 ) {
f048e32f 215 AdjustColour(ui);
bbdbfb0e 216 }
457814b5 217
bbdbfb0e 218 m_pListBox->Check(2);
df7d383f 219 m_pListBox->Select(3);
457814b5
JS
220}
221
222CheckListBoxFrame::~CheckListBoxFrame()
223{
224}
225
4f22cf8d 226void CheckListBoxFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
457814b5 227{
bbdbfb0e 228 Close(TRUE);
457814b5
JS
229}
230
4f22cf8d 231void CheckListBoxFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
457814b5 232{
df7d383f 233