]> git.saurik.com Git - wxWidgets.git/blame - samples/checklst/checklst.cpp
NO C++ COMMENTS IN THIS FILE PLEASE
[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,
50 int x, int y, int w, int h);
51 ~CheckListBoxFrame();
52
53 // notifications
54 void OnQuit (wxCommandEvent& event);
55 void OnAbout (wxCommandEvent& event);
56 void OnListboxSelect (wxCommandEvent& event);
57 void OnCheckboxToggle (wxCommandEvent& event);
58 void OnListboxDblClick(wxCommandEvent& event);
59 void OnButtonUp (wxCommandEvent& event);
60 void OnButtonDown (wxCommandEvent& event);
457814b5 61
bbdbfb0e
VZ
62private:
63 void OnButtonMove(bool up);
457814b5 64
bbdbfb0e 65 wxCheckListBox *m_pListBox;
457814b5 66
bbdbfb0e 67 DECLARE_EVENT_TABLE()
457814b5
JS
68};
69
655822f3
VZ
70enum
71{
bbdbfb0e
VZ
72 Menu_Quit = 1,
73 Control_First = 1000,
74 Control_Listbox,
75 Btn_Up,
76 Btn_Down
457814b5
JS
77};
78
79BEGIN_EVENT_TABLE(CheckListBoxFrame, wxFrame)
bbdbfb0e
VZ
80 EVT_MENU(Menu_Quit, CheckListBoxFrame::OnQuit)
81
82 EVT_LISTBOX(Control_Listbox, CheckListBoxFrame::OnListboxSelect)
83 EVT_CHECKLISTBOX(Control_Listbox, CheckListBoxFrame::OnCheckboxToggle)
84 EVT_LISTBOX_DCLICK(Control_Listbox, CheckListBoxFrame::OnListboxDblClick)
85
86 EVT_BUTTON(Btn_Up, CheckListBoxFrame::OnButtonUp)
87 EVT_BUTTON(Btn_Down, CheckListBoxFrame::OnButtonDown)
457814b5
JS
88END_EVENT_TABLE()
89
90IMPLEMENT_APP(CheckListBoxApp);
91
92// init our app: create windows
93bool CheckListBoxApp::OnInit(void)
94{
bbdbfb0e
VZ
95 CheckListBoxFrame *pFrame = new CheckListBoxFrame
96 (
97 NULL,
98 "wxWindows Checklistbox Sample",
99 50, 50, 480, 320
100 );
101 SetTopWindow(pFrame);
102
103 return TRUE;
457814b5
JS
104}
105
106// main frame constructor
bbdbfb0e
VZ
107CheckListBoxFrame::CheckListBoxFrame(wxFrame *frame,
108 const char *title,
109 int x, int y, int w, int h)
110: wxFrame(frame, -1, title, wxPoint(x, y), wxSize(w, h))
457814b5 111{
bbdbfb0e
VZ
112 // create the status line
113 const int widths[] = { -1, 60 };
114 CreateStatusBar(2);
115 SetStatusWidths(2, widths);
befa6d98 116 wxLogStatus(this, _T("no selection"));
bbdbfb0e
VZ
117
118 // Make a menubar
119 wxMenu *file_menu = new wxMenu;
120
121 // construct submenu
122 file_menu->Append(Menu_Quit, "E&xit");
123
124 wxMenuBar *menu_bar = new wxMenuBar;
125 menu_bar->Append(file_menu, "&File");
126 SetMenuBar(menu_bar);
127
128 // make a panel with some controls
2f073eb2 129 wxPanel *panel = new wxPanel(this, -1, wxPoint(0, 0),
bbdbfb0e
VZ
130 wxSize(400, 200), wxTAB_TRAVERSAL);
131
132 // check list box
133 static const char* aszChoices[] =
134 {
135 "Zeroth",
136 "First", "Second", "Third",
137 "Fourth", "Fifth", "Sixth",
138 "Seventh", "Eighth", "Nineth"
139 };
140
141 wxString *astrChoices = new wxString[WXSIZEOF(aszChoices)];
142 unsigned int ui;
143 for ( ui = 0; ui < WXSIZEOF(aszChoices); ui++ )
144 astrChoices[ui] = aszChoices[ui];
145
146 m_pListBox = new wxCheckListBox
147 (
148 panel, // parent
149 Control_Listbox, // control id
150 wxPoint(10, 10), // listbox poistion
8e1d4f96 151 wxSize(400, 100), // listbox size
bbdbfb0e
VZ
152 WXSIZEOF(aszChoices), // number of strings
153 astrChoices // array of strings
154 );
155
156 //m_pListBox->SetBackgroundColour(*wxGREEN);
157
158 delete [] astrChoices;
159
c386222c
VZ
160 // not implemented in other ports yet
161#ifdef __WXMSW__
bbdbfb0e
VZ
162 // set grey background for every second entry
163 for ( ui = 0; ui < WXSIZEOF(aszChoices); ui += 2 ) {
164 m_pListBox->GetItem(ui)->SetBackgroundColour(wxColor(200, 200, 200));
165 }
ccfd0a25 166#endif // wxGTK
457814b5 167
bbdbfb0e 168 m_pListBox->Check(2);
457814b5 169
bbdbfb0e 170 // create buttons for moving the items around
d8d474af
RR
171 wxButton *button1 = new wxButton(panel, Btn_Up, " &Up ", wxPoint(420, 90));
172 wxButton *button2 = new wxButton(panel, Btn_Down, "&Down", wxPoint(420, 120));
173
174
175 wxBoxSizer *mainsizer = new wxBoxSizer( wxVERTICAL );
176
177 mainsizer->Add( m_pListBox, 1, wxGROW|wxALL, 10 );
178
179 wxBoxSizer *bottomsizer = new wxBoxSizer( wxHORIZONTAL );
180
181 bottomsizer->Add( button1, 0, wxALL, 10 );
182 bottomsizer->Add( button2, 0, wxALL, 10 );
183
184 mainsizer->Add( bottomsizer, 0, wxCENTER );
185
186 // tell frame to make use of sizer (or constraints, if any)
eb38f734
RR
187 panel->SetAutoLayout( TRUE );
188 panel->SetSizer( mainsizer );
d8d474af 189
d8d474af
RR
190 // don't allow frame to get smaller than what the sizers tell ye
191 mainsizer->SetSizeHints( this );
d8d474af
RR
192
193
bbdbfb0e 194 Show(TRUE);
457814b5
JS
195}
196
197CheckListBoxFrame::~CheckListBoxFrame()
198{
199}
200
4f22cf8d 201void CheckListBoxFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
457814b5 202{
bbdbfb0e 203 Close(TRUE);
457814b5
JS
204}
205
4f22cf8d 206void CheckListBoxFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
457814b5 207{
befa6d98
OK
208 wxMessageBox(_T("Demo of wxCheckListBox control\n"
209