]>
Commit | Line | Data |
---|---|---|
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 | ||
457814b5 | 33 | #include "wx/menuitem.h" |
b292e2f5 RR |
34 | #include "wx/checklst.h" |
35 | ||
457814b5 JS |
36 | // Define a new application type |
37 | class CheckListBoxApp: public wxApp | |
38 | { | |
39 | public: | |
bbdbfb0e | 40 | bool OnInit(); |
457814b5 JS |
41 | }; |
42 | ||
43 | // Define a new frame type | |
44 | class CheckListBoxFrame : public wxFrame | |
45 | { | |
46 | public: | |
bbdbfb0e VZ |
47 | // ctor & dtor |
48 | CheckListBoxFrame(wxFrame *frame, const char *title, | |
49 | int x, int y, int w, int h); | |
50 | ~CheckListBoxFrame(); | |
51 | ||
52 | // notifications | |
53 | void OnQuit (wxCommandEvent& event); | |
54 | void OnAbout (wxCommandEvent& event); | |
55 | void OnListboxSelect (wxCommandEvent& event); | |
56 | void OnCheckboxToggle (wxCommandEvent& event); | |
57 | void OnListboxDblClick(wxCommandEvent& event); | |
58 | void OnButtonUp (wxCommandEvent& event); | |
59 | void OnButtonDown (wxCommandEvent& event); | |
457814b5 | 60 | |
bbdbfb0e VZ |
61 | private: |
62 | void OnButtonMove(bool up); | |
457814b5 | 63 | |
bbdbfb0e | 64 | wxCheckListBox *m_pListBox; |
457814b5 | 65 | |
bbdbfb0e | 66 | DECLARE_EVENT_TABLE() |
457814b5 JS |
67 | }; |
68 | ||
655822f3 VZ |
69 | enum |
70 | { | |
bbdbfb0e VZ |
71 | Menu_Quit = 1, |
72 | Control_First = 1000, | |
73 | Control_Listbox, | |
74 | Btn_Up, | |
75 | Btn_Down | |
457814b5 JS |
76 | }; |
77 | ||
78 | BEGIN_EVENT_TABLE(CheckListBoxFrame, wxFrame) | |
bbdbfb0e VZ |
79 | EVT_MENU(Menu_Quit, CheckListBoxFrame::OnQuit) |
80 | ||
81 | EVT_LISTBOX(Control_Listbox, CheckListBoxFrame::OnListboxSelect) | |
82 | EVT_CHECKLISTBOX(Control_Listbox, CheckListBoxFrame::OnCheckboxToggle) | |
83 | EVT_LISTBOX_DCLICK(Control_Listbox, CheckListBoxFrame::OnListboxDblClick) | |
84 | ||
85 | EVT_BUTTON(Btn_Up, CheckListBoxFrame::OnButtonUp) | |
86 | EVT_BUTTON(Btn_Down, CheckListBoxFrame::OnButtonDown) | |
457814b5 JS |
87 | END_EVENT_TABLE() |
88 | ||
89 | IMPLEMENT_APP(CheckListBoxApp); | |
90 | ||
91 | // init our app: create windows | |
92 | bool CheckListBoxApp::OnInit(void) | |
93 | { | |
bbdbfb0e VZ |
94 | CheckListBoxFrame *pFrame = new CheckListBoxFrame |
95 | ( | |
96 | NULL, | |
97 | "wxWindows Checklistbox Sample", | |
98 | 50, 50, 480, 320 | |
99 | ); | |
100 | SetTopWindow(pFrame); | |
101 | ||
102 | return TRUE; | |
457814b5 JS |
103 | } |
104 | ||
105 | // main frame constructor | |
bbdbfb0e VZ |
106 | CheckListBoxFrame::CheckListBoxFrame(wxFrame *frame, |
107 | const char *title, | |
108 | int x, int y, int w, int h) | |
109 | : wxFrame(frame, -1, title, wxPoint(x, y), wxSize(w, h)) | |
457814b5 | 110 | { |
bbdbfb0e VZ |
111 | // create the status line |
112 | const int widths[] = { -1, 60 }; | |
113 | CreateStatusBar(2); | |
114 | SetStatusWidths(2, widths); | |
115 | wxLogStatus(this, "no selection"); | |
116 | ||
117 | // Make a menubar | |
118 | wxMenu *file_menu = new wxMenu; | |
119 | ||
120 | // construct submenu | |
121 | file_menu->Append(Menu_Quit, "E&xit"); | |
122 | ||
123 | wxMenuBar *menu_bar = new wxMenuBar; | |
124 | menu_bar->Append(file_menu, "&File"); | |
125 | SetMenuBar(menu_bar); | |
126 | ||
127 | // make a panel with some controls | |
128 | wxPanel *panel = new wxPanel(this, -1, wxPoint(0, 0), | |
129 | wxSize(400, 200), wxTAB_TRAVERSAL); | |
130 | ||
131 | // check list box | |
132 | static const char* aszChoices[] = | |
133 | { | |
134 | "Zeroth", | |
135 | "First", "Second", "Third", | |
136 | "Fourth", "Fifth", "Sixth", | |
137 | "Seventh", "Eighth", "Nineth" | |
138 | }; | |
139 | ||
140 | wxString *astrChoices = new wxString[WXSIZEOF(aszChoices)]; | |
141 | unsigned int ui; | |
142 | for ( ui = 0; ui < WXSIZEOF(aszChoices); ui++ ) | |
143 | astrChoices[ui] = aszChoices[ui]; | |
144 | ||
145 | m_pListBox = new wxCheckListBox | |
146 | ( | |
147 | panel, // parent | |
148 | Control_Listbox, // control id | |
149 | wxPoint(10, 10), // listbox poistion | |
8e1d4f96 | 150 | wxSize(400, 100), // listbox size |
bbdbfb0e VZ |
151 | WXSIZEOF(aszChoices), // number of strings |
152 | astrChoices // array of strings | |
153 | ); | |
154 | ||
155 | //m_pListBox->SetBackgroundColour(*wxGREEN); | |
156 | ||
157 | delete [] astrChoices; | |
158 | ||
c386222c VZ |
159 | // not implemented in other ports yet |
160 | #ifdef __WXMSW__ | |
bbdbfb0e VZ |
161 | // set grey background for every second entry |
162 | for ( ui = 0; ui < WXSIZEOF(aszChoices); ui += 2 ) { | |
163 | m_pListBox->GetItem(ui)->SetBackgroundColour(wxColor(200, 200, 200)); | |
164 | } | |
ccfd0a25 | 165 | #endif // wxGTK |
457814b5 | 166 | |
bbdbfb0e | 167 | m_pListBox->Check(2); |
457814b5 | 168 | |
bbdbfb0e VZ |
169 | // create buttons for moving the items around |
170 | (void)new wxButton(panel, Btn_Up, " &Up ", wxPoint(420, 90)); | |
171 | (void)new wxButton(panel, Btn_Down, "&Down", wxPoint(420, 120)); | |
172 | ||
173 | Show(TRUE); | |
457814b5 JS |
174 | } |
175 | ||
176 | CheckListBoxFrame::~CheckListBoxFrame() | |
177 | { | |
178 | } | |
179 | ||
4f22cf8d | 180 | void CheckListBoxFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) |
457814b5 | 181 | { |
bbdbfb0e | 182 | Close(TRUE); |
457814b5 JS |
183 | } |
184 | ||
4f22cf8d | 185 | void CheckListBoxFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) |
457814b5 | 186 | { |
bbdbfb0e VZ |
187 | wxMessageBox("Demo of wxCheckListBox control\n" |
188 |