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