]>
Commit | Line | Data |
---|---|---|
1 | /////////////////////////////////////////////////////////////////////////////// | |
2 | // Name: checklst.cpp | |
3 | // Purpose: wxCheckListBox sample | |
4 | // Author: Vadim Zeitlin | |
5 | // Modified by: | |
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 | ||
12 | #ifdef __GNUG__ | |
13 | //#pragma implementation | |
14 | #endif | |
15 | ||
16 | // For compilers that support precompilation, includes "wx.h". | |
17 | #include "wx/wxprec.h" | |
18 | ||
19 | #ifdef __BORLANDC__ | |
20 | #pragma hdrstop | |
21 | #endif | |
22 | ||
23 | #ifndef WX_PRECOMP | |
24 | #include "wx/wx.h" | |
25 | #endif | |
26 | ||
27 | #ifdef __WXMSW__ | |
28 | #include "wx/ownerdrw.h" | |
29 | #endif | |
30 | ||
31 | #include "wx/log.h" | |
32 | ||
33 | #include "wx/menuitem.h" | |
34 | #include "wx/checklst.h" | |
35 | ||
36 | // Define a new application type | |
37 | class CheckListBoxApp: public wxApp | |
38 | { | |
39 | public: | |
40 | bool OnInit(); | |
41 | }; | |
42 | ||
43 | // Define a new frame type | |
44 | class CheckListBoxFrame : public wxFrame | |
45 | { | |
46 | public: | |
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); | |
60 | ||
61 | private: | |
62 | void OnButtonMove(bool up); | |
63 | ||
64 | wxCheckListBox *m_pListBox; | |
65 | ||
66 | DECLARE_EVENT_TABLE() | |
67 | }; | |
68 | ||
69 | enum | |
70 | { | |
71 | Menu_Quit = 1, | |
72 | Control_First = 1000, | |
73 | Control_Listbox, | |
74 | Btn_Up, | |
75 | Btn_Down | |
76 | }; | |
77 | ||
78 | BEGIN_EVENT_TABLE(CheckListBoxFrame, wxFrame) | |
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) | |
87 | END_EVENT_TABLE() | |
88 | ||
89 | IMPLEMENT_APP(CheckListBoxApp); | |
90 | ||
91 | // init our app: create windows | |
92 | bool CheckListBoxApp::OnInit(void) | |
93 | { | |
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; | |
103 | } | |
104 | ||
105 | // main frame constructor | |
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)) | |
110 | { | |
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 | |
150 | wxSize(400, 200), // listbox size | |
151 | WXSIZEOF(aszChoices), // number of strings | |
152 | astrChoices // array of strings | |
153 | ); | |
154 | ||
155 | //m_pListBox->SetBackgroundColour(*wxGREEN); | |
156 | ||
157 | delete [] astrChoices; | |
158 | ||
159 | // not implemented in other ports yet | |
160 | #ifdef __WXMSW__ | |
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 | } | |
165 | #endif // wxGTK | |
166 | ||
167 | m_pListBox->Check(2); | |
168 | ||
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); | |
174 | } | |
175 | ||
176 | CheckListBoxFrame::~CheckListBoxFrame() | |
177 | { | |
178 | } | |
179 | ||
180 | void CheckListBoxFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) | |
181 | { | |
182 | Close(TRUE); | |
183 | } | |
184 | ||
185 | void CheckListBoxFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) | |
186 | { | |
187 | wxMessageBox("Demo of wxCheckListBox control\n" | |
188 |