]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: listctrl.cpp | |
3 | // Purpose: | |
4 | // Author: Robert Roebling | |
0208334d RR |
5 | // Id: $Id$ |
6 | // Copyright: (c) 1998 Robert Roebling | |
bd8289c1 | 7 | // Licence: wxWindows licence |
c801d85f KB |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
10 | #ifdef __GNUG__ | |
11 | #pragma implementation "listctrl.h" | |
12 | #endif | |
13 | ||
1e6d9499 JS |
14 | // For compilers that support precompilation, includes "wx.h". |
15 | #include "wx/wxprec.h" | |
16 | ||
17 | #ifdef __BORLANDC__ | |
18 | #pragma hdrstop | |
19 | #endif | |
20 | ||
0208334d RR |
21 | #include "wx/dcscreen.h" |
22 | #include "wx/app.h" | |
f60d0f94 JS |
23 | #include "wx/generic/listctrl.h" |
24 | #include "wx/generic/imaglist.h" | |
c801d85f KB |
25 | |
26 | //----------------------------------------------------------------------------- | |
27 | // wxListItemData | |
28 | //----------------------------------------------------------------------------- | |
29 | ||
30 | IMPLEMENT_DYNAMIC_CLASS(wxListItemData,wxObject); | |
31 | ||
32 | wxListItemData::wxListItemData(void) | |
33 | { | |
92976ab6 RR |
34 | m_image = -1; |
35 | m_data = 0; | |
36 | m_xpos = 0; | |
37 | m_ypos = 0; | |
38 | m_width = 0; | |
39 | m_height = 0; | |
40 | m_colour = wxBLACK; | |
e1e955e1 | 41 | } |
c801d85f KB |
42 | |
43 | wxListItemData::wxListItemData( const wxListItem &info ) | |
44 | { | |
92976ab6 RR |
45 | m_image = -1; |
46 | m_data = 0; | |
47 | m_colour = info.m_colour; | |
48 | SetItem( info ); | |
e1e955e1 | 49 | } |
c801d85f KB |
50 | |
51 | void wxListItemData::SetItem( const wxListItem &info ) | |
52 | { | |
92976ab6 RR |
53 | if (info.m_mask & wxLIST_MASK_TEXT) m_text = info.m_text; |
54 | if (info.m_mask & wxLIST_MASK_IMAGE) m_image = info.m_image; | |
55 | if (info.m_mask & wxLIST_MASK_DATA) m_data = info.m_data; | |
56 | m_colour = info.m_colour; | |
57 | m_xpos = 0; | |
58 | m_ypos = 0; | |
59 | m_width = info.m_width; | |
60 | m_height = 0; | |
e1e955e1 | 61 | } |
c801d85f KB |
62 | |
63 | void wxListItemData::SetText( const wxString &s ) | |
64 | { | |
92976ab6 | 65 | m_text = s; |
e1e955e1 | 66 | } |
c801d85f | 67 | |
debe6624 | 68 | void wxListItemData::SetImage( int image ) |
c801d85f | 69 | { |
92976ab6 | 70 | m_image = image; |
e1e955e1 | 71 | } |
c801d85f | 72 | |
debe6624 | 73 | void wxListItemData::SetData( long data ) |
c801d85f | 74 | { |
92976ab6 | 75 | m_data = data; |
e1e955e1 | 76 | } |
c801d85f | 77 | |
debe6624 | 78 | void wxListItemData::SetPosition( int x, int y ) |
c801d85f | 79 | { |
92976ab6 RR |
80 | m_xpos = x; |
81 | m_ypos = y; | |
e1e955e1 | 82 | } |
c801d85f | 83 | |
1e6d9499 | 84 | void wxListItemData::SetSize( int width, int height ) |
c801d85f | 85 | { |
92976ab6 RR |
86 | if (width != -1) m_width = width; |
87 | if (height != -1) m_height = height; | |
e1e955e1 | 88 | } |
c801d85f KB |
89 | |
90 | void wxListItemData::SetColour( wxColour *col ) | |
91 | { | |
92976ab6 | 92 | m_colour = col; |
e1e955e1 | 93 | } |
c801d85f KB |
94 | |
95 | bool wxListItemData::HasImage(void) const | |
96 | { | |
92976ab6 | 97 | return (m_image >= 0); |
e1e955e1 | 98 | } |
c801d85f KB |
99 | |
100 | bool wxListItemData::HasText(void) const | |
101 | { | |
92976ab6 | 102 | return (!m_text.IsNull()); |
e1e955e1 | 103 | } |
c801d85f | 104 | |
debe6624 | 105 | bool wxListItemData::IsHit( int x, int y ) const |
c801d85f | 106 | { |
92976ab6 | 107 | return ((x >= m_xpos) && (x <= m_xpos+m_width) && (y >= m_ypos) && (y <= m_ypos+m_height)); |
e1e955e1 | 108 | } |
c801d85f KB |
109 | |
110 | void wxListItemData::GetText( wxString &s ) | |
111 | { | |
92976ab6 | 112 | s = m_text; |
e1e955e1 | 113 | } |
c801d85f KB |
114 | |
115 | int wxListItemData::GetX( void ) const | |
116 | { | |
92976ab6 | 117 | return m_xpos; |
e1e955e1 | 118 | } |
c801d85f KB |
119 | |
120 | int wxListItemData::GetY( void ) const | |
121 | { | |
92976ab6 | 122 | return m_ypos; |
e1e955e1 | 123 | } |
c801d85f KB |
124 | |
125 | int wxListItemData::GetWidth(void) const | |
126 | { | |
92976ab6 | 127 | return m_width; |
e1e955e1 | 128 | } |
c801d85f KB |
129 | |
130 | int wxListItemData::GetHeight(void) const | |
131 | { | |
92976ab6 | 132 | return m_height; |
e1e955e1 | 133 | } |
c801d85f KB |
134 | |
135 | int wxListItemData::GetImage(void) const | |
136 | { | |
92976ab6 | 137 | return m_image; |
e1e955e1 | 138 | } |
c801d85f KB |
139 | |
140 | void wxListItemData::GetItem( wxListItem &info ) | |
141 | { | |
92976ab6 RR |
142 | info.m_text = m_text; |
143 | info.m_image = m_image; | |
144 | info.m_data = m_data; | |
e1e955e1 | 145 | } |
c801d85f KB |
146 | |
147 | wxColour *wxListItemData::GetColour(void) | |
148 | { | |
92976ab6 | 149 | return m_colour; |
e1e955e1 | 150 | } |
c801d85f KB |
151 | |
152 | //----------------------------------------------------------------------------- | |
153 | // wxListHeaderData | |
154 | //----------------------------------------------------------------------------- | |
155 | ||
156 | IMPLEMENT_DYNAMIC_CLASS(wxListHeaderData,wxObject); | |
157 | ||
158 | wxListHeaderData::wxListHeaderData(void) | |
159 | { | |
92976ab6 RR |
160 | m_mask = 0; |
161 | m_image = 0; | |
162 | m_format = 0; | |
163 | m_width = 0; | |
164 | m_xpos = 0; | |
165 | m_ypos = 0; | |
166 | m_height = 0; | |
e1e955e1 | 167 | } |
c801d85f KB |
168 | |
169 | wxListHeaderData::wxListHeaderData( const wxListItem &item ) | |
170 | { | |
92976ab6 RR |
171 | SetItem( item ); |
172 | m_xpos = 0; | |
173 | m_ypos = 0; | |
174 | m_height = 0; | |
e1e955e1 | 175 | } |
c801d85f KB |
176 | |
177 | void wxListHeaderData::SetItem( const wxListItem &item ) | |
178 | { | |
92976ab6 RR |
179 | m_mask = item.m_mask; |
180 | m_text = item.m_text; | |
181 | m_image = item.m_image; | |
182 | m_format = item.m_format; | |
183 | m_width = item.m_width; | |
184 | if (m_width < 0) m_width = 80; | |
185 | if (m_width < 6) m_width = 6; | |
e1e955e1 | 186 | } |
c801d85f | 187 | |
debe6624 | 188 | void wxListHeaderData::SetPosition( int x, int y ) |
c801d85f | 189 | { |
92976ab6 RR |
190 | m_xpos = x; |
191 | m_ypos = y; | |
e1e955e1 | 192 | } |
c801d85f | 193 | |
debe6624 | 194 | void wxListHeaderData::SetHeight( int h ) |
c801d85f | 195 | { |
92976ab6 | 196 | m_height = h; |
e1e955e1 | 197 | } |
c801d85f | 198 | |
debe6624 | 199 | void wxListHeaderData::SetWidth( int w ) |
c801d85f | 200 | { |
92976ab6 RR |
201 | m_width = w; |
202 | if (m_width < 0) m_width = 80; | |
203 | if (m_width < 6) m_width = 6; | |
e1e955e1 | 204 | } |
c801d85f | 205 | |
debe6624 | 206 | void wxListHeaderData::SetFormat( int format ) |
c801d85f | 207 | { |
92976ab6 | 208 | m_format = format; |
e1e955e1 | 209 | } |
c801d85f KB |
210 | |
211 | bool wxListHeaderData::HasImage(void) const | |
212 | { | |
92976ab6 | 213 | return (m_image != 0); |
e1e955e1 | 214 | } |
c801d85f KB |
215 | |
216 | bool wxListHeaderData::HasText(void) const | |
217 | { | |
92976ab6 | 218 | return (m_text.Length() > 0); |
e1e955e1 | 219 | } |
c801d85f KB |
220 | |
221 | bool wxListHeaderData::IsHit( int x, int y ) const | |
222 | { | |
92976ab6 | 223 | return ((x >= m_xpos) && (x <= m_xpos+m_width) && (y >= m_ypos) && (y <= m_ypos+m_height)); |
e1e955e1 | 224 | } |
c801d85f KB |
225 | |
226 | void wxListHeaderData::GetItem( wxListItem &item ) | |
227 | { | |
92976ab6 RR |
228 | item.m_mask = m_mask; |
229 | item.m_text = m_text; | |
230 | item.m_image = m_image; | |
231 | item.m_format = m_format; | |
232 | item.m_width = m_width; | |
e1e955e1 | 233 | } |
c801d85f KB |
234 | |
235 | void wxListHeaderData::GetText( wxString &s ) | |
236 | { | |
92976ab6 | 237 | s = m_text; |
e1e955e1 | 238 | } |
c801d85f KB |
239 | |
240 | int wxListHeaderData::GetImage(void) const | |
241 | { | |
92976ab6 | 242 | return m_image; |
e1e955e1 | 243 | } |
c801d85f KB |
244 | |
245 | int wxListHeaderData::GetWidth(void) const | |
246 | { | |
92976ab6 | 247 | return m_width; |
e1e955e1 | 248 | } |
c801d85f KB |
249 | |
250 | int wxListHeaderData::GetFormat(void) const | |
251 | { | |
92976ab6 | 252 | return m_format; |
e1e955e1 | 253 | } |
c801d85f KB |
254 | |
255 | //----------------------------------------------------------------------------- | |
256 | // wxListLineData | |
257 | //----------------------------------------------------------------------------- | |
258 | ||
259 | IMPLEMENT_DYNAMIC_CLASS(wxListLineData,wxObject); | |
260 | ||
debe6624 | 261 | wxListLineData::wxListLineData( wxListMainWindow *owner, int mode, wxBrush *hilightBrush ) |
c801d85f | 262 | { |
92976ab6 RR |
263 | m_mode = mode; |
264 | m_hilighted = FALSE; | |
265 | m_owner = owner; | |
266 | m_hilightBrush = hilightBrush; | |
267 | m_items.DeleteContents( TRUE ); | |
268 | m_spacing = 0; | |
e1e955e1 | 269 | } |
c801d85f | 270 | |
1e6d9499 | 271 | void wxListLineData::CalculateSize( wxDC *dc, int spacing ) |
c801d85f | 272 | { |
92976ab6 RR |
273 | m_spacing = spacing; |
274 | switch (m_mode) | |
c801d85f | 275 | { |
92976ab6 RR |
276 | case wxLC_ICON: |
277 | { | |
278 | m_bound_all.width = m_spacing; | |
279 | m_bound_all.height = m_spacing+13; | |
280 | wxNode *node = m_items.First(); | |
281 | if (node) | |
282 | { | |
283 | wxListItemData *item = (wxListItemData*)node->Data(); | |
284 | wxString s; | |
285 | item->GetText( s ); | |
286 | long lw,lh; | |
287 | dc->GetTextExtent( s, &lw, &lh ); | |
288 | if (lw > m_spacing) m_bound_all.width = lw; | |
289 | } | |
290 | break; | |
291 | } | |
292 | case wxLC_LIST: | |
293 | { | |
294 | wxNode *node = m_items.First(); | |
295 | if (node) | |
296 | { | |
297 | wxListItemData *item = (wxListItemData*)node->Data(); | |
298 | wxString s; | |
299 | item->GetText( s ); | |
300 | long lw,lh; | |
301 | dc->GetTextExtent( s, &lw, &lh ); | |
302 | m_bound_all.width = lw; | |
303 | m_bound_all.height = lh; | |
304 | } | |
305 | break; | |
306 | } | |
307 | case wxLC_REPORT: | |
308 | { | |
309 | m_bound_all.width = 0; | |
310 | m_bound_all.height = 0; | |
311 | wxNode *node = m_items.First(); | |
312 | while (node) | |
313 | { | |
314 | wxListItemData *item = (wxListItemData*)node->Data(); | |
315 | wxString s; | |
316 | item->GetText( s ); | |
317 | if (s.IsNull()) s = "H"; | |
318 | long lw,lh; | |
319 | dc->GetTextExtent( s, &lw, &lh ); | |
320 | item->SetSize( item->GetWidth(), lh ); | |
321 | m_bound_all.width += lw; | |
322 | m_bound_all.height = lh; | |
323 | node = node->Next(); | |
324 | } | |
325 | break; | |
326 | } | |
e1e955e1 | 327 | } |
e1e955e1 | 328 | } |
c801d85f | 329 | |
1e6d9499 | 330 | void wxListLineData::SetPosition( wxDC *dc, int x, int y, int window_width ) |
c801d85f KB |
331 | { |
332 | m_bound_all.x = x; | |
333 | m_bound_all.y = y; | |
334 | switch (m_mode) | |
335 | { | |
336 | case wxLC_ICON: | |
337 | { | |
338 | AssignRect( m_bound_icon, 0, 0, 0, 0 ); | |
339 | AssignRect( m_bound_label, 0, 0, 0, 0 ); | |
340 | AssignRect( m_bound_hilight, m_bound_all ); | |
341 | wxNode *node = m_items.First(); | |
342 | if (node) | |
343 | { | |
344 | wxListItemData *item = (wxListItemData*)node->Data(); | |
345 | if (item->HasImage()) | |
346 | { | |
347 | wxListItemData *item = (wxListItemData*)node->Data(); | |
348 | int w = 0; | |
349 | int h = 0; | |
350 | m_owner->GetImageSize( item->GetImage(), w, h ); | |
351 | m_bound_icon.x = m_bound_all.x + (m_spacing/2) - (w/2); | |
352 | m_bound_icon.y = m_bound_all.y + m_spacing - h - 5; | |
353 | m_bound_icon.width = w; | |
354 | m_bound_icon.height = h; | |
355 | if (!item->HasText()) | |
356 | { | |
357 | AssignRect( m_bound_hilight, m_bound_icon ); | |
3db7be80 RR |
358 | m_bound_hilight.x -= 5; |
359 | m_bound_hilight.y -= 5; | |
360 | m_bound_hilight.width += 9; | |
361 | m_bound_hilight.height += 9; | |
e1e955e1 RR |
362 | } |
363 | } | |
c801d85f KB |
364 | if (item->HasText()) |
365 | { | |
366 | wxString s; | |
367 | item->GetText( s ); | |
368 | long lw,lh; | |
369 | dc->GetTextExtent( s, &lw, &lh ); | |
370 | if (m_bound_all.width > m_spacing) | |
371 | m_bound_label.x = m_bound_all.x; | |
372 | else | |
373 | m_bound_label.x = m_bound_all.x + (m_spacing/2) - lw/2; | |
374 | m_bound_label.y = m_bound_all.y + m_bound_all.height - lh; | |
375 | m_bound_label.width = lw; | |
376 | m_bound_label.height = lh; | |
377 | AssignRect( m_bound_hilight, m_bound_label ); | |
3db7be80 RR |
378 | m_bound_hilight.x -= 2; |
379 | m_bound_hilight.y -= 2; | |
380 | m_bound_hilight.width += 4; | |
381 | m_bound_hilight.height += 4; | |
e1e955e1 RR |
382 | } |
383 | } | |
c801d85f | 384 | break; |
e1e955e1 | 385 | } |
c801d85f KB |
386 | case wxLC_LIST: |
387 | { | |
388 | AssignRect( m_bound_label, m_bound_all ); | |
3db7be80 RR |
389 | m_bound_all.x -= 2; |
390 | m_bound_all.y -= 2; | |
391 | m_bound_all.width += 4; | |
92976ab6 | 392 | m_bound_all.height += 3; |
c801d85f KB |
393 | AssignRect( m_bound_hilight, m_bound_all ); |
394 | AssignRect( m_bound_icon, 0, 0, 0, 0 ); | |
395 | break; | |
e1e955e1 | 396 | } |
c801d85f KB |
397 | case wxLC_REPORT: |
398 | { | |
399 | long lw,lh; | |
400 | dc->GetTextExtent( "H", &lw, &lh ); | |
3db7be80 RR |
401 | m_bound_all.x = 0; |
402 | m_bound_all.y -= 0; | |
403 | m_bound_all.height = lh+3; | |
c801d85f | 404 | m_bound_all.width = window_width; |
c801d85f | 405 | AssignRect( m_bound_hilight, m_bound_all ); |
3db7be80 | 406 | AssignRect( m_bound_label, 0, 0, 0 ,0 ); |
c801d85f | 407 | AssignRect( m_bound_icon, 0, 0, 0, 0 ); |
c801d85f | 408 | break; |
e1e955e1 RR |
409 | } |
410 | } | |
411 | } | |
c801d85f | 412 | |
debe6624 | 413 | void wxListLineData::SetColumnPosition( int index, int x ) |
c801d85f | 414 | { |
92976ab6 RR |
415 | int i = index; |
416 | wxNode *node = m_items.Nth( i ); | |
417 | if (node) | |
418 | { | |
419 | wxListItemData *item = (wxListItemData*)node->Data(); | |
420 | item->SetPosition( x, m_bound_all.y+1 ); | |
421 | } | |
e1e955e1 | 422 | } |
c801d85f KB |
423 | |
424 | void wxListLineData::GetSize( int &width, int &height ) | |
425 | { | |
139adb6a RR |
426 | width = m_bound_all.width; |
427 | height = m_bound_all.height; | |
e1e955e1 | 428 | } |
c801d85f KB |
429 | |
430 | void wxListLineData::GetExtent( int &x, int &y, int &width, int &height ) | |
431 | { | |
139adb6a RR |
432 | x = m_bound_all.x; |
433 | y = m_bound_all.y; | |
434 | width = m_bound_all.width; | |
435 | height = m_bound_all.height; | |
e1e955e1 | 436 | } |
c801d85f KB |
437 | |
438 | void wxListLineData::GetLabelExtent( int &x, int &y, int &width, int &height ) | |
439 | { | |
139adb6a RR |
440 | x = m_bound_label.x; |
441 | y = m_bound_label.y; | |
442 | width = m_bound_label.width; | |
443 | height = m_bound_label.height; | |
e1e955e1 | 444 | } |
c801d85f | 445 | |
0a240683 | 446 | void wxListLineData::GetRect( wxRect &rect ) |
c801d85f | 447 | { |
139adb6a | 448 | AssignRect( rect, m_bound_all ); |
e1e955e1 | 449 | } |
c801d85f | 450 | |
debe6624 | 451 | long wxListLineData::IsHit( int x, int y ) |
c801d85f | 452 | { |
139adb6a RR |
453 | wxNode *node = m_items.First(); |
454 | if (node) | |
455 | { | |
456 | wxListItemData *item = (wxListItemData*)node->Data(); | |
457 | if (item->HasImage() && IsInRect( x, y, m_bound_icon )) return wxLIST_HITTEST_ONITEMICON; | |
458 | if (item->HasText() && IsInRect( x, y, m_bound_label )) return wxLIST_HITTEST_ONITEMLABEL; | |
459 | // if (!(item->HasImage() || item->HasText())) return 0; | |
460 | } | |
461 | // if there is no icon or text = empty | |
462 | if (IsInRect( x, y, m_bound_all )) return wxLIST_HITTEST_ONITEMICON; | |
463 | return 0; | |
e1e955e1 | 464 | } |
c801d85f | 465 | |
debe6624 | 466 | void wxListLineData::InitItems( int num ) |
c801d85f | 467 | { |
139adb6a | 468 | for (int i = 0; i < num; i++) m_items.Append( new wxListItemData() ); |
e1e955e1 | 469 | } |
c801d85f | 470 | |
debe6624 | 471 | void wxListLineData::SetItem( int index, const wxListItem &info ) |
c801d85f | 472 | { |
139adb6a RR |
473 | wxNode *node = m_items.Nth( index ); |
474 | if (node) | |
475 | { | |
476 | wxListItemData *item = (wxListItemData*)node->Data(); | |
477 | item->SetItem( info ); | |
478 | } | |
e1e955e1 | 479 | } |
c801d85f | 480 | |
1e6d9499 | 481 | void wxListLineData::GetItem( int index, wxListItem &info ) |
c801d85f | 482 | { |
139adb6a RR |
483 | int i = index; |
484 | wxNode *node = m_items.Nth( i ); | |
485 | if (node) | |
486 | { | |
487 | wxListItemData *item = (wxListItemData*)node->Data(); | |
488 | item->GetItem( info ); | |
489 | } | |
e1e955e1 | 490 | } |
c801d85f | 491 | |
debe6624 | 492 | void wxListLineData::GetText( int index, wxString &s ) |
c801d85f | 493 | { |
139adb6a RR |
494 | int i = index; |
495 | wxNode *node = m_items.Nth( i ); | |
496 | s = ""; | |
497 | if (node) | |
498 | { | |
499 | wxListItemData *item = (wxListItemData*)node->Data(); | |
500 | item->GetText( s ); | |
501 | } | |
e1e955e1 | 502 | } |
c801d85f | 503 | |
debe6624 | 504 | void wxListLineData::SetText( int index, const wxString s ) |
c801d85f | 505 | { |
139adb6a RR |
506 | int i = index; |
507 | wxNode *node = m_items.Nth( i ); | |
508 | if (node) | |
509 | { | |
510 | wxListItemData *item = (wxListItemData*)node->Data(); | |
511 | item->SetText( s ); | |
512 | } | |
e1e955e1 | 513 | } |
c801d85f | 514 | |
debe6624 | 515 | int wxListLineData::GetImage( int index ) |
c801d85f | 516 | { |
139adb6a RR |
517 | int i = index; |
518 | wxNode *node = m_items.Nth( i ); | |
519 | if (node) | |
520 | { | |
521 | wxListItemData *item = (wxListItemData*)node->Data(); | |
522 | return item->GetImage(); | |
523 | } | |
524 | return -1; | |
e1e955e1 | 525 | } |
c801d85f | 526 | |
1e6d9499 | 527 | void wxListLineData::DoDraw( wxDC *dc, bool hilight, bool paintBG ) |
c801d85f | 528 | { |
139adb6a RR |
529 | long dev_x = dc->LogicalToDeviceX( m_bound_all.x-2 ); |
530 | long dev_y = dc->LogicalToDeviceY( m_bound_all.y-2 ); | |
531 | long dev_w = dc->LogicalToDeviceXRel( m_bound_all.width+4 ); | |
532 | long dev_h = dc->LogicalToDeviceYRel( m_bound_all.height+4 ); | |
533 | ||
534 | if (!m_owner->IsExposed( dev_x, dev_y, dev_w, dev_h )) | |
535 | { | |
536 | return; | |
537 | } | |
bd8289c1 | 538 | |
63852e78 | 539 | if (paintBG) |
c801d85f | 540 | { |
63852e78 RR |
541 | if (hilight) |
542 | { | |
543 | dc->SetBrush( * m_hilightBrush ); | |
544 | dc->SetPen( * wxTRANSPARENT_PEN ); | |
545 | } | |
546 | else | |
547 | { | |
548 | dc->SetBrush( * wxWHITE_BRUSH ); | |
549 | dc->SetPen( * wxTRANSPARENT_PEN ); | |
550 | } | |
551 | dc->DrawRectangle( m_bound_hilight.x, m_bound_hilight.y, | |
552 | m_bound_hilight.width, m_bound_hilight.height ); | |
e1e955e1 | 553 | } |
63852e78 | 554 | |
f60d0f94 | 555 | dc->SetBackgroundMode(wxTRANSPARENT); |
63852e78 | 556 | if (m_mode == wxLC_REPORT) |
c801d85f | 557 | { |
63852e78 RR |
558 | wxString s; |
559 | wxNode *node = m_items.First(); | |
560 | while (node) | |
561 | { | |
562 | wxListItemData *item = (wxListItemData*)node->Data(); | |
563 | dc->SetClippingRegion( item->GetX(), item->GetY(), item->GetWidth()-3, item->GetHeight() ); | |
564 | int x = item->GetX(); | |
565 | if (item->HasImage()) | |
566 | { | |
567 | int y = 0; | |
568 | m_owner->DrawImage( item->GetImage(), dc, x, item->GetY() ); | |
569 | m_owner->GetImageSize( item->GetImage(), x, y ); | |
570 | x += item->GetX() + 5; | |
571 | } | |
572 | if (item->HasText()) | |
573 | { | |
574 | item->GetText( s ); | |
575 | if (hilight) | |
576 | dc->SetTextForeground( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT ) ); | |
577 | else | |
578 | dc->SetTextForeground( *item->GetColour() ); | |
579 | dc->DrawText( s, x, item->GetY() ); | |
580 | } | |
581 | dc->DestroyClippingRegion(); | |
582 | node = node->Next(); | |
583 | } | |
e1e955e1 | 584 | } |
63852e78 | 585 | else |
c801d85f | 586 | { |
63852e78 RR |
587 | wxNode *node = m_items.First(); |
588 | if (node) | |
589 | { | |
590 | wxListItemData *item = (wxListItemData*)node->Data(); | |
591 | if (item->HasImage()) | |
592 | { | |
593 | m_owner->DrawImage( item->GetImage(), dc, m_bound_icon.x, m_bound_icon.y ); | |
594 | } | |
595 | if (item->HasText()) | |
596 | { | |
597 | wxString s; | |
598 | item->GetText( s ); | |
599 | if (hilight) | |
600 | dc->SetTextForeground( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT ) ); | |
601 | else | |
602 | dc->SetTextForeground( * item->GetColour() ); | |
603 | dc->DrawText( s, m_bound_label.x, m_bound_label.y ); | |
604 | } | |
605 | } | |
e1e955e1 | 606 | } |
e1e955e1 | 607 | } |
c801d85f | 608 | |
debe6624 | 609 | void wxListLineData::Hilight( bool on ) |
c801d85f | 610 | { |
63852e78 RR |
611 | if (on == m_hilighted) return; |
612 | if (on) | |
613 | m_owner->SelectLine( this ); | |
614 | else | |
615 | m_owner->DeselectLine( this ); | |
616 | m_hilighted = on; | |
e1e955e1 | 617 | } |
c801d85f KB |
618 | |
619 | void wxListLineData::ReverseHilight( void ) | |
620 | { | |
63852e78 RR |
621 | m_hilighted = !m_hilighted; |
622 | if (m_hilighted) | |
623 | m_owner->SelectLine( this ); | |
624 | else | |
625 | m_owner->DeselectLine( this ); | |
e1e955e1 | 626 | } |
c801d85f | 627 | |
1e6d9499 | 628 | void wxListLineData::DrawRubberBand( wxDC *dc, bool on ) |
c801d85f | 629 | { |
63852e78 RR |
630 | if (on) |
631 | { | |
632 | dc->SetPen( * wxBLACK_PEN ); | |
633 | dc->SetBrush( * wxTRANSPARENT_BRUSH ); | |
634 | dc->DrawRectangle( m_bound_hilight.x, m_bound_hilight.y, | |
635 | m_bound_hilight.width, m_bound_hilight.height ); | |
636 | } | |
e1e955e1 | 637 | } |
c801d85f | 638 | |
1e6d9499 | 639 | void wxListLineData::Draw( wxDC *dc ) |
c801d85f | 640 | { |
63852e78 | 641 | DoDraw( dc, m_hilighted, m_hilighted ); |
e1e955e1 | 642 | } |
c801d85f | 643 | |
0a240683 | 644 | bool wxListLineData::IsInRect( int x, int y, const wxRect &rect ) |
c801d85f | 645 | { |
63852e78 RR |
646 | return ((x >= rect.x) && (x <= rect.x+rect.width) && |
647 | (y >= rect.y) && (y <= rect.y+rect.height)); | |
e1e955e1 | 648 | } |
c801d85f KB |
649 | |
650 | bool wxListLineData::IsHilighted( void ) | |
651 | { | |
63852e78 | 652 | return m_hilighted; |
e1e955e1 | 653 | } |
c801d85f | 654 | |
0a240683 | 655 | void wxListLineData::AssignRect( wxRect &dest, int x, int y, int width, int height ) |
c801d85f | 656 | { |
63852e78 RR |
657 | dest.x = x; |
658 | dest.y = y; | |
659 | dest.width = width; | |
660 | dest.height = height; | |
e1e955e1 | 661 | } |
c801d85f | 662 | |
0a240683 | 663 | void wxListLineData::AssignRect( wxRect &dest, const wxRect &source ) |
c801d85f | 664 | { |
63852e78 RR |
665 | dest.x = source.x; |
666 | dest.y = source.y; | |
667 | dest.width = source.width; | |
668 | dest.height = source.height; | |
e1e955e1 | 669 | } |
c801d85f KB |
670 | |
671 | //----------------------------------------------------------------------------- | |
672 | // wxListHeaderWindow | |
673 | //----------------------------------------------------------------------------- | |
674 | ||
675 | IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow,wxWindow); | |
676 | ||
677 | BEGIN_EVENT_TABLE(wxListHeaderWindow,wxWindow) | |
63852e78 RR |
678 | EVT_PAINT (wxListHeaderWindow::OnPaint) |
679 | EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse) | |
680 | EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus) | |
c801d85f KB |
681 | END_EVENT_TABLE() |
682 | ||
683 | wxListHeaderWindow::wxListHeaderWindow( void ) | |
684 | { | |
63852e78 RR |
685 | m_owner = (wxListMainWindow *) NULL; |
686 | m_currentCursor = (wxCursor *) NULL; | |
687 | m_resizeCursor = (wxCursor *) NULL; | |
cfb50f14 | 688 | m_isDragging = FALSE; |
e1e955e1 | 689 | } |
c801d85f | 690 | |
bd8289c1 | 691 | wxListHeaderWindow::wxListHeaderWindow( wxWindow *win, wxWindowID id, wxListMainWindow *owner, |
debe6624 JS |
692 | const wxPoint &pos, const wxSize &size, |
693 | long style, const wxString &name ) : | |
c801d85f KB |
694 | wxWindow( win, id, pos, size, style, name ) |
695 | { | |
63852e78 | 696 | m_owner = owner; |
c801d85f | 697 | // m_currentCursor = wxSTANDARD_CURSOR; |
63852e78 RR |
698 | m_currentCursor = (wxCursor *) NULL; |
699 | m_resizeCursor = new wxCursor( wxCURSOR_SIZEWE ); | |
cfb50f14 RR |
700 | m_isDragging = FALSE; |
701 | SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE ) ); | |
e1e955e1 | 702 | } |
c801d85f | 703 | |
a367b9b3 JS |
704 | wxListHeaderWindow::~wxListHeaderWindow( void ) |
705 | { | |
63852e78 | 706 | delete m_resizeCursor; |
a367b9b3 JS |
707 | } |
708 | ||
1e6d9499 | 709 | void wxListHeaderWindow::DoDrawRect( wxDC *dc, int x, int y, int w, int h ) |
c801d85f | 710 | { |
63852e78 | 711 | const int m_corner = 1; |
c801d85f | 712 | |
63852e78 | 713 | dc->SetBrush( *wxTRANSPARENT_BRUSH ); |
c801d85f | 714 | |
63852e78 RR |
715 | dc->SetPen( *wxBLACK_PEN ); |
716 | dc->DrawLine( x+w-m_corner+1, y, x+w, y+h ); // right (outer) | |
17867d61 | 717 | dc->DrawRectangle( x, y+h, w+1, 1 ); // bottom (outer) |
bd8289c1 | 718 | |
63852e78 | 719 | wxPen pen( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNSHADOW ), 1, wxSOLID ); |
907789a0 | 720 | |
63852e78 RR |
721 | dc->SetPen( pen ); |
722 | dc->DrawLine( x+w-m_corner, y, x+w-1, y+h ); // right (inner) | |
723 | dc->DrawRectangle( x+1, y+h-1, w-2, 1 ); // bottom (inner) | |
bd8289c1 | 724 | |
63852e78 RR |
725 | dc->SetPen( *wxWHITE_PEN ); |
726 | dc->DrawRectangle( x, y, w-m_corner+1, 1 ); // top (outer) | |
727 | dc->DrawRectangle( x, y, 1, h ); // left (outer) | |
728 | dc->DrawLine( x, y+h-1, x+1, y+h-1 ); | |
729 | dc->DrawLine( x+w-1, y, x+w-1, y+1 ); | |
e1e955e1 | 730 | } |
c801d85f KB |
731 | |
732 | void wxListHeaderWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) | |
733 | { | |
63852e78 RR |
734 | wxPaintDC dc( this ); |
735 | PrepareDC( dc ); | |
736 | ||
737 | dc.BeginDrawing(); | |
bd8289c1 | 738 | |
63852e78 | 739 | dc.SetFont( GetFont() ); |
bd8289c1 | 740 | |
63852e78 RR |
741 | int w = 0; |
742 | int h = 0; | |
743 | int x = 0; | |
744 | int y = 0; | |
745 | GetClientSize( &w, &h ); | |
c801d85f | 746 | |
f60d0f94 | 747 | dc.SetBackgroundMode(wxTRANSPARENT); |
63852e78 RR |
748 | dc.SetTextForeground( *wxBLACK ); |
749 | if (m_foregroundColour.Ok()) dc.SetTextForeground( m_foregroundColour ); | |
c801d85f | 750 | |
63852e78 RR |
751 | x = 1; |
752 | y = 1; | |
753 | int numColumns = m_owner->GetColumnCount(); | |
754 | wxListItem item; | |
755 | for (int i = 0; i < numColumns; i++) | |
756 | { | |
757 | m_owner->GetColumn( i, item ); | |
758 | int cw = item.m_width-2; | |
759 | if ((i+1 == numColumns) || (x+item.m_width > w-5)) cw = w-x-1; | |
760 | dc.SetPen( *wxWHITE_PEN ); | |
c801d85f | 761 | |
63852e78 RR |
762 | DoDrawRect( &dc, x, y, cw, h-2 ); |
763 | dc.SetClippingRegion( x, y, cw-5, h-4 ); | |
764 | dc.DrawText( item.m_text, x+4, y+3 ); | |
765 | dc.DestroyClippingRegion(); | |
766 | x += item.m_width; | |
767 | if (x > w+5) break; | |
768 | } | |
769 | dc.EndDrawing(); | |
e1e955e1 | 770 | } |
c801d85f | 771 | |
0208334d RR |
772 | void wxListHeaderWindow::DrawCurrent() |
773 | { | |
63852e78 RR |
774 | int x1 = m_currentX; |
775 | int y1 = 0; | |
776 | int x2 = m_currentX-1; | |
777 | int y2 = 0; | |
778 | int dummy; | |
779 | m_owner->GetClientSize( &dummy, &y2 ); | |
780 | ClientToScreen( &x1, &y1 ); | |
781 | m_owner->ClientToScreen( &x2, &y2 ); | |
0208334d | 782 | |
63852e78 | 783 | wxScreenDC dc; |
3c679789 | 784 | dc.SetLogicalFunction( wxINVERT ); |
63852e78 RR |
785 | dc.SetPen( wxPen( *wxBLACK, 2, wxSOLID ) ); |
786 | dc.SetBrush( *wxTRANSPARENT_BRUSH ); | |
0208334d | 787 | |
63852e78 | 788 | dc.DrawLine( x1, y1, x2, y2 ); |
0208334d | 789 | |
63852e78 | 790 | dc.SetLogicalFunction( wxCOPY ); |
0208334d | 791 | |
63852e78 RR |
792 | dc.SetPen( wxNullPen ); |
793 | dc.SetBrush( wxNullBrush ); | |
0208334d RR |
794 | } |
795 | ||
c801d85f KB |
796 | void wxListHeaderWindow::OnMouse( wxMouseEvent &event ) |
797 | { | |
63852e78 RR |
798 | int x = event.GetX(); |
799 | int y = event.GetY(); | |
cfb50f14 | 800 | if (m_isDragging) |
0208334d | 801 | { |
63852e78 RR |
802 | DrawCurrent(); |
803 | if (event.ButtonUp()) | |
804 | { | |
805 | ReleaseMouse(); | |
cfb50f14 | 806 | m_isDragging = FALSE; |
63852e78 RR |
807 | m_owner->SetColumnWidth( m_column, m_currentX-m_minX ); |
808 | } | |
809 | else | |
810 | { | |
811 | int size_x = 0; | |
812 | int dummy; | |
813 | GetClientSize( &size_x, & dummy ); | |
814 | if (x > m_minX+7) | |
815 | m_currentX = x; | |
816 | else | |
817 | m_currentX = m_minX+7; | |
818 | if (m_currentX > size_x-7) m_currentX = size_x-7; | |
819 | DrawCurrent(); | |
820 | } | |
821 | return; | |
0208334d | 822 | } |
bd8289c1 | 823 | |
63852e78 RR |
824 | m_minX = 0; |
825 | bool hit_border = FALSE; | |
826 | int xpos = 0; | |
827 | for (int j = 0; j < m_owner->GetColumnCount(); j++) | |
bd8289c1 | 828 | { |
63852e78 RR |
829 | xpos += m_owner->GetColumnWidth( j ); |
830 | if ((abs(x-xpos) < 3) && (y < 22)) | |
831 | { | |
832 | hit_border = TRUE; | |
833 | m_column = j; | |
834 | break; | |
835 | } | |
836 | m_minX = xpos; | |
0208334d | 837 | } |
bd8289c1 | 838 | |
63852e78 | 839 | if (event.LeftDown() && hit_border) |
c801d85f | 840 | { |
cfb50f14 | 841 | m_isDragging = TRUE; |
63852e78 RR |
842 | m_currentX = x; |
843 | DrawCurrent(); | |
844 | CaptureMouse(); | |
845 | return; | |
c801d85f | 846 | } |
63852e78 RR |
847 | |
848 | if (event.Moving()) | |
c801d85f | 849 | { |
63852e78 RR |
850 | if (hit_border) |
851 | { | |
852 | if (m_currentCursor == wxSTANDARD_CURSOR) SetCursor( * m_resizeCursor ); | |
853 | m_currentCursor = m_resizeCursor; | |
854 | } | |
855 | else | |
856 | { | |
857 | if (m_currentCursor != wxSTANDARD_CURSOR) SetCursor( * wxSTANDARD_CURSOR ); | |
858 | m_currentCursor = wxSTANDARD_CURSOR; | |
859 | } | |
e1e955e1 | 860 | } |
e1e955e1 | 861 | } |
c801d85f KB |
862 | |
863 | void wxListHeaderWindow::OnSetFocus( wxFocusEvent &WXUNUSED(event) ) | |
864 | { | |
63852e78 | 865 | m_owner->SetFocus(); |
e1e955e1 | 866 | } |
c801d85f KB |
867 | |
868 | //----------------------------------------------------------------------------- | |
869 | // wxListRenameTimer (internal) | |
870 | //----------------------------------------------------------------------------- | |
871 | ||
bd8289c1 VZ |
872 | wxListRenameTimer::wxListRenameTimer( wxListMainWindow *owner ) |
873 | { | |
63852e78 | 874 | m_owner = owner; |
e1e955e1 | 875 | } |
c801d85f | 876 | |
bd8289c1 VZ |
877 | void wxListRenameTimer::Notify() |
878 | { | |
63852e78 | 879 | m_owner->OnRenameTimer(); |
e1e955e1 | 880 | } |
c801d85f | 881 | |
ee7ee469 RR |
882 | //----------------------------------------------------------------------------- |
883 | // wxListTextCtrl (internal) | |
884 | //----------------------------------------------------------------------------- | |
885 | ||
886 | IMPLEMENT_DYNAMIC_CLASS(wxListTextCtrl,wxTextCtrl); | |
bd8289c1 | 887 | |
ee7ee469 | 888 | BEGIN_EVENT_TABLE(wxListTextCtrl,wxTextCtrl) |
63852e78 RR |
889 | EVT_CHAR (wxListTextCtrl::OnChar) |
890 | EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus) | |
ee7ee469 RR |
891 | END_EVENT_TABLE() |
892 | ||
bd8289c1 | 893 | wxListTextCtrl::wxListTextCtrl( wxWindow *parent, const wxWindowID id, |
ee7ee469 RR |
894 | bool *accept, wxString *res, wxListMainWindow *owner, |
895 | const wxString &value, const wxPoint &pos, const wxSize &size, | |
896 | int style, const wxValidator& validator, const wxString &name ) : | |
897 | wxTextCtrl( parent, id, value, pos, size, style, validator, name ) | |
898 | { | |
63852e78 RR |
899 | m_res = res; |
900 | m_accept = accept; | |
901 | m_owner = owner; | |
ee7ee469 RR |
902 | } |
903 | ||
904 | void wxListTextCtrl::OnChar( wxKeyEvent &event ) | |
905 | { | |
63852e78 RR |
906 | if (event.m_keyCode == WXK_RETURN) |
907 | { | |
908 | (*m_accept) = TRUE; | |
909 | (*m_res) = GetValue(); | |
910 | m_owner->OnRenameAccept(); | |
911 | // Show( FALSE ); | |
912 | Destroy(); | |
913 | return; | |
914 | } | |
915 | if (event.m_keyCode == WXK_ESCAPE) | |
916 | { | |
917 | (*m_accept) = FALSE; | |
918 | (*m_res) = ""; | |
919 | // Show( FALSE ); | |
920 | Destroy(); | |
921 | return; | |
922 | } | |
923 | event.Skip(); | |
924 | } | |
925 | ||
926 | void wxListTextCtrl::OnKillFocus( wxFocusEvent &WXUNUSED(event) ) | |
927 | { | |
ee7ee469 RR |
928 | (*m_accept) = FALSE; |
929 | (*m_res) = ""; | |
930 | // Show( FALSE ); | |
931 | Destroy(); | |
932 | return; | |
ee7ee469 RR |
933 | } |
934 | ||
c801d85f KB |
935 | //----------------------------------------------------------------------------- |
936 | // wxListMainWindow | |
937 | //----------------------------------------------------------------------------- | |
938 | ||
939 | IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow,wxScrolledWindow); | |
bd8289c1 | 940 | |
c801d85f KB |
941 | BEGIN_EVENT_TABLE(wxListMainWindow,wxScrolledWindow) |
942 | EVT_PAINT (wxListMainWindow::OnPaint) | |
943 | EVT_SIZE (wxListMainWindow::OnSize) | |
944 | EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse) | |
945 | EVT_CHAR (wxListMainWindow::OnChar) | |
3dfb93fd | 946 | EVT_KEY_DOWN (wxListMainWindow::OnKeyDown) |
c801d85f KB |
947 | EVT_SET_FOCUS (wxListMainWindow::OnSetFocus) |
948 | EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus) | |
949 | END_EVENT_TABLE() | |
950 | ||
951 | wxListMainWindow::wxListMainWindow( void ) | |
952 | { | |
139adb6a RR |
953 | m_mode = 0; |
954 | m_lines.DeleteContents( TRUE ); | |
955 | m_columns.DeleteContents( TRUE ); | |
956 | m_current = (wxListLineData *) NULL; | |
957 | m_visibleLines = 0; | |
958 | m_hilightBrush = (wxBrush *) NULL; | |
959 | m_xScroll = 0; | |
960 | m_yScroll = 0; | |
961 | m_dirty = TRUE; | |
962 | m_small_image_list = (wxImageList *) NULL; | |
963 | m_normal_image_list = (wxImageList *) NULL; | |
964 | m_small_spacing = 30; | |
965 | m_normal_spacing = 40; | |
966 | m_hasFocus = FALSE; | |
967 | m_usedKeys = TRUE; | |
968 | m_lastOnSame = FALSE; | |
969 | m_renameTimer = new wxListRenameTimer( this ); | |
970 | m_isCreated = FALSE; | |
971 | m_dragCount = 0; | |
e1e955e1 | 972 | } |
c801d85f | 973 | |
bd8289c1 | 974 | wxListMainWindow::wxListMainWindow( wxWindow *parent, wxWindowID id, |
c801d85f | 975 | const wxPoint &pos, const wxSize &size, |
debe6624 | 976 | long style, const wxString &name ) : |
a367b9b3 | 977 | wxScrolledWindow( parent, id, pos, size, style|wxHSCROLL|wxVSCROLL, name ) |
c801d85f | 978 | { |
139adb6a RR |
979 | m_mode = style; |
980 | m_lines.DeleteContents( TRUE ); | |
981 | m_columns.DeleteContents( TRUE ); | |
982 | m_current = (wxListLineData *) NULL; | |
983 | m_dirty = TRUE; | |
984 | m_visibleLines = 0; | |
985 | m_hilightBrush = new wxBrush( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT), wxSOLID ); | |
986 | m_small_image_list = (wxImageList *) NULL; | |
987 | m_normal_image_list = (wxImageList *) NULL; | |
988 | m_small_spacing = 30; | |
989 | m_normal_spacing = 40; | |
990 | m_hasFocus = FALSE; | |
991 | m_dragCount = 0; | |
992 | m_isCreated = FALSE; | |
993 | wxSize sz = size; | |
994 | sz.y = 25; | |
bd8289c1 | 995 | |
139adb6a RR |
996 | if (m_mode & wxLC_REPORT) |
997 | { | |
998 | m_xScroll = 0; | |
999 | m_yScroll = 15; | |
1000 | } | |
1001 | else | |
1002 | { | |
1003 | m_xScroll = 15; | |
1004 | m_yScroll = 0; | |
1005 | } | |
1006 | SetScrollbars( m_xScroll, m_yScroll, 0, 0, 0, 0 ); | |
bd8289c1 | 1007 | |
139adb6a RR |
1008 | m_usedKeys = TRUE; |
1009 | m_lastOnSame = FALSE; | |
1010 | m_renameTimer = new wxListRenameTimer( this ); | |
1011 | m_renameAccept = FALSE; | |
c801d85f | 1012 | |
139adb6a | 1013 | SetBackgroundColour( *wxWHITE ); |
e1e955e1 | 1014 | } |
c801d85f KB |
1015 | |
1016 | wxListMainWindow::~wxListMainWindow( void ) | |
1017 | { | |
139adb6a RR |
1018 | if (m_hilightBrush) delete m_hilightBrush; |
1019 | ||
1020 | delete m_renameTimer; | |
e1e955e1 | 1021 | } |
c801d85f KB |
1022 | |
1023 | void wxListMainWindow::RefreshLine( wxListLineData *line ) | |
1024 | { | |
139adb6a RR |
1025 | int x = 0; |
1026 | int y = 0; | |
1027 | int w = 0; | |
1028 | int h = 0; | |
1029 | if (line) | |
1030 | { | |
1031 | wxClientDC dc(this); | |
1032 | PrepareDC( dc ); | |
1033 | line->GetExtent( x, y, w, h ); | |
0a240683 | 1034 | wxRect rect( |
139adb6a RR |
1035 | dc.LogicalToDeviceX(x-3), |
1036 | dc.LogicalToDeviceY(y-3), | |
1037 | dc.LogicalToDeviceXRel(w+6), | |
1038 | dc.LogicalToDeviceXRel(h+6) ); | |
1039 | Refresh( TRUE, &rect ); | |
1040 | } | |
e1e955e1 | 1041 | } |
c801d85f KB |
1042 | |
1043 | void wxListMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) | |
1044 | { | |
f60d0f94 JS |
1045 | // Note: a wxPaintDC must be constructed even if no drawing is |
1046 | // done (a Windows requirement). | |
1047 | wxPaintDC dc( this ); | |
1048 | PrepareDC( dc ); | |
1049 | ||
139adb6a RR |
1050 | if (m_dirty) return; |
1051 | ||
1052 | if (m_lines.GetCount() == 0) return; | |
bd8289c1 | 1053 | |
139adb6a | 1054 | dc.BeginDrawing(); |
c801d85f | 1055 | |
139adb6a RR |
1056 | dc.SetFont( GetFont() ); |
1057 | ||
1058 | if (m_mode & wxLC_REPORT) | |
1059 | { | |
1060 | int lineSpacing = 0; | |
1061 | wxListLineData *line = (wxListLineData*)m_lines.First()->Data(); | |
1062 | int dummy = 0; | |
1063 | line->GetSize( dummy, lineSpacing ); | |
1064 | lineSpacing += 1; | |
1065 | ||
1066 | int y_s = m_yScroll*GetScrollPos( wxVERTICAL ); | |
1067 | ||
1068 | wxNode *node = m_lines.Nth( y_s / lineSpacing ); | |
1069 | for (int i = 0; i < m_visibleLines+2; i++) | |
1070 | { | |
1071 | if (!node) break; | |
1072 | ||
1073 | line = (wxListLineData*)node->Data(); | |
1074 | line->Draw( &dc ); | |
1075 | node = node->Next(); | |
1076 | } | |
1077 | } | |
1078 | else | |
1079 | { | |
1080 | wxNode *node = m_lines.First(); | |
1081 | while (node) | |
1082 | { | |
1083 | wxListLineData *line = (wxListLineData*)node->Data(); | |
1084 | line->Draw( &dc ); | |
1085 | node = node->Next(); | |
1086 | } | |
1087 | } | |
1088 | ||
1089 | if (m_current) m_current->DrawRubberBand( &dc, m_hasFocus ); | |
c801d85f | 1090 | |
139adb6a | 1091 | dc.EndDrawing(); |
e1e955e1 | 1092 | } |
c801d85f | 1093 | |
debe6624 | 1094 | void wxListMainWindow::HilightAll( bool on ) |
c801d85f | 1095 | { |
139adb6a RR |
1096 | wxNode *node = m_lines.First(); |
1097 | while (node) | |
c801d85f | 1098 | { |
139adb6a RR |
1099 | wxListLineData *line = (wxListLineData *)node->Data(); |
1100 | if (line->IsHilighted() != on) | |
1101 | { | |
1102 | line->Hilight( on ); | |
1103 | RefreshLine( line ); | |
1104 | } | |
1105 | node = node->Next(); | |
e1e955e1 | 1106 | } |
e1e955e1 | 1107 | } |
c801d85f | 1108 | |
7798a18e | 1109 | void wxListMainWindow::SendNotify( wxListLineData *line, wxEventType command ) |
c801d85f | 1110 | { |
139adb6a RR |
1111 | wxListEvent le( command, GetParent()->GetId() ); |
1112 | le.SetEventObject( GetParent() ); | |
1113 | le.m_itemIndex = GetIndexOfLine( line ); | |
1114 | line->GetItem( 0, le.m_item ); | |
1115 | GetParent()->GetEventHandler()->ProcessEvent( le ); | |
e1e955e1 | 1116 | } |
c801d85f KB |
1117 | |
1118 | void wxListMainWindow::FocusLine( wxListLineData *WXUNUSED(line) ) | |
1119 | { | |
1120 | // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_FOCUSSED ); | |
e1e955e1 | 1121 | } |
c801d85f KB |
1122 | |
1123 | void wxListMainWindow::UnfocusLine( wxListLineData *WXUNUSED(line) ) | |
1124 | { | |
1125 | // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_UNFOCUSSED ); | |
e1e955e1 | 1126 | } |
c801d85f KB |
1127 | |
1128 | void wxListMainWindow::SelectLine( wxListLineData *line ) | |
1129 | { | |
139adb6a | 1130 | SendNotify( line, wxEVT_COMMAND_LIST_ITEM_SELECTED ); |
e1e955e1 | 1131 | } |
c801d85f KB |
1132 | |
1133 | void wxListMainWindow::DeselectLine( wxListLineData *line ) | |
1134 | { | |
139adb6a | 1135 | SendNotify( line, wxEVT_COMMAND_LIST_ITEM_DESELECTED ); |
e1e955e1 | 1136 | } |
c801d85f KB |
1137 | |
1138 | void wxListMainWindow::DeleteLine( wxListLineData *line ) | |
1139 | { | |
139adb6a | 1140 | SendNotify( line, wxEVT_COMMAND_LIST_DELETE_ITEM ); |
e1e955e1 | 1141 | } |
c801d85f | 1142 | |
ee7ee469 RR |
1143 | void wxListMainWindow::StartLabelEdit( wxListLineData *line ) |
1144 | { | |
139adb6a | 1145 | SendNotify( line, wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT ); |
e1e955e1 | 1146 | } |
ee7ee469 | 1147 | |
c801d85f KB |
1148 | void wxListMainWindow::RenameLine( wxListLineData *line, const wxString &newName ) |
1149 | { | |
139adb6a RR |
1150 | wxListEvent le( wxEVT_COMMAND_LIST_END_LABEL_EDIT, GetParent()->GetId() ); |
1151 | le.SetEventObject( GetParent() ); | |
1152 | le.m_itemIndex = GetIndexOfLine( line ); | |
1153 | line->GetItem( 0, le.m_item ); | |
1154 | le.m_item.m_text = newName; | |
1155 | GetParent()->GetEventHandler()->ProcessEvent( le ); | |
e1e955e1 | 1156 | } |
c801d85f KB |
1157 | |
1158 | void wxListMainWindow::OnRenameTimer() | |
1159 | { | |
92976ab6 RR |
1160 | StartLabelEdit( m_current ); |
1161 | wxString s; | |
1162 | m_current->GetText( 0, s ); | |
1163 | int x = 0; | |
1164 | int y = 0; | |
1165 | int w = 0; | |
1166 | int h = 0; | |
1167 | m_current->GetLabelExtent( x, y, w, h ); | |
bd8289c1 | 1168 | |
92976ab6 RR |
1169 | wxClientDC dc(this); |
1170 | PrepareDC( dc ); | |
1171 | x = dc.LogicalToDeviceX( x ); | |
1172 | y = dc.LogicalToDeviceY( y ); | |
bd8289c1 | 1173 | |
92976ab6 RR |
1174 | wxListTextCtrl *text = new wxListTextCtrl( |
1175 | this, -1, &m_renameAccept, &m_renameRes, this, s, wxPoint(x-4,y-4), wxSize(w+11,h+8) ); | |
1176 | text->SetFocus(); | |
e1e955e1 | 1177 | } |
c801d85f KB |
1178 | |
1179 | void wxListMainWindow::OnRenameAccept() | |
1180 | { | |
92976ab6 | 1181 | RenameLine( m_current, m_renameRes ); |
e1e955e1 | 1182 | } |
c801d85f KB |
1183 | |
1184 | void wxListMainWindow::OnMouse( wxMouseEvent &event ) | |
1185 | { | |
92976ab6 | 1186 | if (GetParent()->GetEventHandler()->ProcessEvent( event)) return; |
e3e65dac | 1187 | |
92976ab6 RR |
1188 | if (!m_current) return; |
1189 | if (m_dirty) return; | |
c801d85f | 1190 | |
92976ab6 RR |
1191 | wxClientDC dc(this); |
1192 | PrepareDC(dc); | |
1193 | long x = dc.DeviceToLogicalX( (long)event.GetX() ); | |
1194 | long y = dc.DeviceToLogicalY( (long)event.GetY() ); | |
1195 | ||
51cc4dad | 1196 | /* Did we actually hit an item ? */ |
92976ab6 RR |
1197 | long hitResult = 0; |
1198 | wxNode *node = m_lines.First(); | |
1199 | wxListLineData *line = (wxListLineData *) NULL; | |
1200 | while (node) | |
1201 | { | |
1202 | line = (wxListLineData*)node->Data(); | |
1203 | hitResult = line->IsHit( x, y ); | |
1204 | if (hitResult) break; | |
1205 | line = (wxListLineData *) NULL; | |
1206 | node = node->Next(); | |
1207 | } | |
bd8289c1 | 1208 | |
92976ab6 RR |
1209 | if (!event.Dragging()) |
1210 | m_dragCount = 0; | |
1211 | else | |
1212 | m_dragCount++; | |
bd8289c1 | 1213 | |
92976ab6 RR |
1214 | if (event.Dragging() && (m_dragCount > 3)) |
1215 | { | |
1216 | m_dragCount = 0; | |
1217 | ||
1218 | wxListEvent le( wxEVT_COMMAND_LIST_BEGIN_DRAG, GetParent()->GetId() ); | |
1219 | le.SetEventObject( GetParent() ); | |
1220 | le.m_pointDrag.x = x; | |
1221 | le.m_pointDrag.y = y; | |
1222 | GetParent()->GetEventHandler()->ProcessEvent( le ); | |
1223 | ||
1224 | return; | |
1225 | } | |
bd8289c1 | 1226 | |
92976ab6 | 1227 | if (!line) return; |
bd8289c1 | 1228 | |
92976ab6 RR |
1229 | if (event.ButtonDClick()) |
1230 | { | |
1231 | m_usedKeys = FALSE; | |
1232 | m_lastOnSame = FALSE; | |
1233 | m_renameTimer->Stop(); | |
1234 | ||
435fe83e | 1235 | SendNotify( line, wxEVT_COMMAND_LIST_ITEM_ACTIVATED ); |
92976ab6 RR |
1236 | |
1237 | return; | |
1238 | } | |
bd8289c1 | 1239 | |
92976ab6 | 1240 | if (event.LeftUp() && m_lastOnSame) |
c801d85f | 1241 | { |
92976ab6 RR |
1242 | m_usedKeys = FALSE; |
1243 | if ((line == m_current) && | |
1244 | (hitResult == wxLIST_HITTEST_ONITEMLABEL) && | |
1245 | (m_mode & wxLC_EDIT_LABELS) ) | |
1246 | { | |
1247 | m_renameTimer->Start( 100, TRUE ); | |
1248 | } | |
1249 | m_lastOnSame = FALSE; | |
1250 | return; | |
e1e955e1 | 1251 | } |
bd8289c1 | 1252 | |
92976ab6 | 1253 | if (event.RightDown()) |
b204641e | 1254 | { |
92976ab6 RR |
1255 | SendNotify( line, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK ); |
1256 | return; | |
b204641e | 1257 | } |
92976ab6 RR |
1258 | |
1259 | if (event.MiddleDown()) | |
b204641e | 1260 | { |
92976ab6 RR |
1261 | SendNotify( line, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK ); |
1262 | return; | |
1263 | } | |
1264 | ||
1265 | if (event.LeftDown()) | |
1266 | { | |
1267 | m_usedKeys = FALSE; | |
1268 | wxListLineData *oldCurrent = m_current; | |
1269 | if (m_mode & wxLC_SINGLE_SEL) | |
b204641e | 1270 | { |
92976ab6 RR |
1271 | m_current = line; |
1272 | HilightAll( FALSE ); | |
1273 | m_current->ReverseHilight(); | |
1274 | RefreshLine( m_current ); | |
e1e955e1 | 1275 | } |
92976ab6 | 1276 | else |
b204641e | 1277 | { |
92976ab6 RR |
1278 | if (event.ShiftDown()) |
1279 | { | |
1280 | m_current = line; | |
1281 | m_current->ReverseHilight(); | |
1282 | RefreshLine( m_current ); | |
1283 | } | |
1284 | else if (event.ControlDown()) | |
1285 | { | |
1286 | m_current = line; | |
1287 | ||
1288 | int numOfCurrent = -1; | |
1289 | node = m_lines.First(); | |
1290 | while (node) | |
1291 | { | |
1292 | wxListLineData *test_line = (wxListLineData*)node->Data(); | |
1293 | numOfCurrent++; | |
1294 | if (test_line == oldCurrent) break; | |
1295 | node = node->Next(); | |
1296 | } | |
1297 | ||
1298 | int numOfLine = -1; | |
1299 | node = m_lines.First(); | |
1300 | while (node) | |
1301 | { | |
1302 | wxListLineData *test_line = (wxListLineData*)node->Data(); | |
1303 | numOfLine++; | |
1304 | if (test_line == line) break; | |
1305 | node = node->Next(); | |
1306 | } | |
1307 | ||
1308 | if (numOfLine < numOfCurrent) | |
1309 | { | |
1310 | int i = numOfLine; | |
1311 | numOfLine = numOfCurrent; | |
1312 | numOfCurrent = i; | |
1313 | } | |
1314 | ||
1315 | wxNode *node = m_lines.Nth( numOfCurrent ); | |
1316 | for (int i = 0; i <= numOfLine-numOfCurrent; i++) | |
1317 | { | |
1318 | wxListLineData *test_line= (wxListLineData*)node->Data(); | |
1319 | test_line->Hilight(TRUE); | |
1320 | RefreshLine( test_line ); | |
1321 | node = node->Next(); | |
1322 | } | |
1323 | } | |
1324 | else | |
1325 | { | |
1326 | m_current = line; | |
1327 | HilightAll( FALSE ); | |
1328 | m_current->ReverseHilight(); | |
1329 | RefreshLine( m_current ); | |
1330 | } | |
e1e955e1 | 1331 | } |
92976ab6 RR |
1332 | if (m_current != oldCurrent) |
1333 | { | |
1334 | RefreshLine( oldCurrent ); | |
1335 | UnfocusLine( oldCurrent ); | |
1336 | FocusLine( m_current ); | |
1337 | } | |
1338 | m_lastOnSame = (m_current == oldCurrent); | |
1339 | return; | |
e1e955e1 | 1340 | } |
e1e955e1 | 1341 | } |
c801d85f KB |
1342 | |
1343 | void wxListMainWindow::MoveToFocus( void ) | |
1344 | { | |
92976ab6 | 1345 | if (!m_current) return; |
e487524e | 1346 | |
92976ab6 RR |
1347 | int x = 0; |
1348 | int y = 0; | |
1349 | int w = 0; | |
1350 | int h = 0; | |
1351 | m_current->GetExtent( x, y, w, h ); | |
139adb6a | 1352 | |
92976ab6 RR |
1353 | int w_p = 0; |
1354 | int h_p = 0; | |
1355 | GetClientSize( &w_p, &h_p ); | |
139adb6a | 1356 | |
92976ab6 RR |
1357 | if (m_mode & wxLC_REPORT) |
1358 | { | |
92976ab6 RR |
1359 | int y_s = m_yScroll*GetScrollPos( wxVERTICAL ); |
1360 | if ((y > y_s) && (y+h < y_s+h_p)) return; | |
aab3e197 KB |
1361 | if (y-y_s < 5) { Scroll( -1, (y-5-h_p/2)/m_yScroll ); Refresh(); } |
1362 | if (y+h+5 > y_s+h_p) { Scroll( -1, (y+h-h_p/2+h+15)/m_yScroll); Refresh(); } | |
92976ab6 RR |
1363 | } |
1364 | else | |
1365 | { | |
92976ab6 RR |
1366 | int x_s = m_xScroll*GetScrollPos( wxHORIZONTAL ); |
1367 | if ((x > x_s) && (x+w < x_s+w_p)) return; | |
aab3e197 KB |
1368 | if (x-x_s < 5) { Scroll( (x-5)/m_xScroll, -1 ); Refresh(); } |
1369 | if (x+w-5 > x_s+w_p) { Scroll( (x+w-w_p+15)/m_xScroll, -1 ); Refresh(); } | |
92976ab6 | 1370 | } |
e1e955e1 | 1371 | } |
c801d85f KB |
1372 | |
1373 | void wxListMainWindow::OnArrowChar( wxListLineData *newCurrent, bool shiftDown ) | |
1374 | { | |
92976ab6 RR |
1375 | if ((m_mode & wxLC_SINGLE_SEL) || (m_usedKeys == FALSE)) m_current->Hilight( FALSE ); |
1376 | wxListLineData *oldCurrent = m_current; | |
1377 | m_current = newCurrent; | |
1378 | MoveToFocus(); | |
1379 | if (shiftDown || (m_mode & wxLC_SINGLE_SEL)) m_current->Hilight( TRUE ); | |
1380 | RefreshLine( m_current ); | |
1381 | RefreshLine( oldCurrent ); | |
1382 | FocusLine( m_current ); | |
1383 | UnfocusLine( oldCurrent ); | |
e1e955e1 | 1384 | } |
c801d85f | 1385 | |
3dfb93fd RR |
1386 | void wxListMainWindow::OnKeyDown( wxKeyEvent &event ) |
1387 | { | |
1388 | wxWindow *parent = GetParent(); | |
1389 | ||
1390 | /* we propagate the key event up */ | |
1391 | wxKeyEvent ke( wxEVT_KEY_DOWN ); | |
1392 | ke.m_shiftDown = event.m_shiftDown; | |
1393 | ke.m_controlDown = event.m_controlDown; | |
1394 | ke.m_altDown = event.m_altDown; | |
1395 | ke.m_metaDown = event.m_metaDown; | |
1396 | ke.m_keyCode = event.m_keyCode; | |
1397 | ke.m_x = event.m_x; | |
1398 | ke.m_y = event.m_y; | |
1399 | ke.SetEventObject( parent ); | |
1400 | if (parent->GetEventHandler()->ProcessEvent( ke )) return; | |
1401 | ||
1402 | event.Skip(); | |
1403 | } | |
1404 | ||
c801d85f KB |
1405 | void wxListMainWindow::OnChar( wxKeyEvent &event ) |
1406 | { | |
51cc4dad | 1407 | wxWindow *parent = GetParent(); |
435fe83e | 1408 | |
51cc4dad RR |
1409 | /* we send a list_key event up */ |
1410 | wxListEvent le( wxEVT_COMMAND_LIST_KEY_DOWN, GetParent()->GetId() ); | |
1411 | le.m_code = event.KeyCode(); | |
1412 | le.SetEventObject( parent ); | |
1413 | parent->GetEventHandler()->ProcessEvent( le ); | |
1414 | ||
3dfb93fd RR |
1415 | /* we propagate the char event up */ |
1416 | wxKeyEvent ke( wxEVT_CHAR ); | |
51cc4dad RR |
1417 | ke.m_shiftDown = event.m_shiftDown; |
1418 | ke.m_controlDown = event.m_controlDown; | |
1419 | ke.m_altDown = event.m_altDown; | |
1420 | ke.m_metaDown = event.m_metaDown; | |
1421 | ke.m_keyCode = event.m_keyCode; | |
1422 | ke.m_x = event.m_x; | |
1423 | ke.m_y = event.m_y; | |
1424 | ke.SetEventObject( parent ); | |
1425 | if (parent->GetEventHandler()->ProcessEvent( ke )) return; | |
1426 | ||
012a03e0 RR |
1427 | if (event.KeyCode() == WXK_TAB) |
1428 | { | |
1429 | wxNavigationKeyEvent nevent; | |
1430 | nevent.SetDirection( !event.ShiftDown() ); | |
1431 | nevent.SetCurrentFocus( m_parent ); | |
1432 | if (m_parent->GetEventHandler()->ProcessEvent( nevent )) return; | |
1433 | } | |
1434 | ||
51cc4dad RR |
1435 | /* no item -> nothing to do */ |
1436 | if (!m_current) | |
c801d85f | 1437 | { |
51cc4dad RR |
1438 | event.Skip(); |
1439 | return; | |
e1e955e1 | 1440 | } |
51cc4dad RR |
1441 | |
1442 | switch (event.KeyCode()) | |
c801d85f | 1443 | { |
51cc4dad RR |
1444 | case WXK_UP: |
1445 | { | |
1446 | wxNode *node = m_lines.Member( m_current )->Previous(); | |
1447 | if (node) OnArrowChar( (wxListLineData*)node->Data(), event.ShiftDown() ); | |
1448 | break; | |
1449 | } | |
1450 | case WXK_DOWN: | |
1451 | { | |
1452 | wxNode *node = m_lines.Member( m_current )->Next(); | |
1453 | if (node) OnArrowChar( (wxListLineData*)node->Data(), event.ShiftDown() ); | |
1454 | break; | |
1455 | } | |
1456 | case WXK_END: | |
1457 | { | |
1458 | wxNode *node = m_lines.Last(); | |
1459 | OnArrowChar( (wxListLineData*)node->Data(), event.ShiftDown() ); | |
1460 | break; | |
1461 | } | |
1462 | case WXK_HOME: | |
1463 | { | |
1464 | wxNode *node = m_lines.First(); | |
1465 | OnArrowChar( (wxListLineData*)node->Data(), event.ShiftDown() ); | |
1466 | break; | |
1467 | } | |
1468 | case WXK_PRIOR: | |
1469 | { | |
1470 | int steps = 0; | |
1471 | if (m_mode & wxLC_REPORT) | |
1472 | { | |
1473 | steps = m_visibleLines-1; | |
1474 | } | |
1475 | else | |
1476 | { | |
1477 | int pos = 0; | |
1478 | wxNode *node = m_lines.First(); | |
1479 | for (;;) { if (m_current == (wxListLineData*)node->Data()) break; pos++; node = node->Next(); } | |
1480 | steps = pos % m_visibleLines; | |
1481 | } | |
1482 | wxNode *node = m_lines.Member( m_current ); | |
1483 | for (int i = 0; i < steps; i++) if (node->Previous()) node = node->Previous(); | |
1484 | if (node) OnArrowChar( (wxListLineData*)node->Data(), event.ShiftDown() ); | |
1485 | break; | |
1486 | } | |
1487 | case WXK_NEXT: | |
1488 | { | |
1489 | int steps = 0; | |
1490 | if (m_mode & wxLC_REPORT) | |
1491 | { | |
1492 | steps = m_visibleLines-1; | |
1493 | } | |
1494 | else | |
1495 | { | |
1496 | int pos = 0; wxNode *node = m_lines.First(); | |
1497 | for (;;) { if (m_current == (wxListLineData*)node->Data()) break; pos++; node = node->Next(); } | |
1498 | steps = m_visibleLines-(pos % m_visibleLines)-1; | |
1499 | } | |
1500 | wxNode *node = m_lines.Member( m_current ); | |
1501 | for (int i = 0; i < steps; i++) if (node->Next()) node = node->Next(); | |
1502 | if (node) OnArrowChar( (wxListLineData*)node->Data(), event.ShiftDown() ); | |
1503 | break; | |
1504 | } | |
1505 | case WXK_LEFT: | |
1506 | { | |
1507 | if (!(m_mode & wxLC_REPORT)) | |
1508 | { | |
1509 | wxNode *node = m_lines.Member( m_current ); | |
1510 | for (int i = 0; i <m_visibleLines; i++) if (node->Previous()) node = node->Previous(); | |
1511 | if (node) OnArrowChar( (wxListLineData*)node->Data(), event.ShiftDown() ); | |
1512 | } | |
1513 | break; | |
1514 | } | |
1515 | case WXK_RIGHT: | |
1516 | { | |
1517 | if (!(m_mode & wxLC_REPORT)) | |
1518 | { | |
1519 | wxNode *node = m_lines.Member( m_current ); | |
1520 | for (int i = 0; i <m_visibleLines; i++) if (node->Next()) node = node->Next(); | |
1521 | if (node) OnArrowChar( (wxListLineData*)node->Data(), event.ShiftDown() ); | |
1522 | } | |
1523 | break; | |
1524 | } | |
1525 | case WXK_SPACE: | |
1526 | { | |
1527 | m_current->ReverseHilight(); | |
1528 | RefreshLine( m_current ); | |
1529 | break; | |
1530 | } | |
1531 | case WXK_INSERT: | |
1532 | { | |
1533 | if (!(m_mode & wxLC_SINGLE_SEL)) | |
1534 | { | |
1535 | wxListLineData *oldCurrent = m_current; | |
1536 | m_current->ReverseHilight(); | |
1537 | wxNode *node = m_lines.Member( m_current )->Next(); | |
1538 | if (node) m_current = (wxListLineData*)node->Data(); | |
1539 | MoveToFocus(); | |
1540 | RefreshLine( oldCurrent ); | |
1541 | RefreshLine( m_current ); | |
1542 | UnfocusLine( oldCurrent ); | |
1543 | FocusLine( m_current ); | |
1544 | } | |
1545 | break; | |
1546 | } | |
1547 | case WXK_RETURN: | |
1548 | case WXK_EXECUTE: | |
1549 | { | |
1550 | wxListEvent le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED, GetParent()->GetId() ); | |
1551 | le.SetEventObject( GetParent() ); | |
1552 | le.m_itemIndex = GetIndexOfLine( m_current ); | |
1553 | m_current->GetItem( 0, le.m_item ); | |
1554 | GetParent()->GetEventHandler()->ProcessEvent( le ); | |
1555 | break; | |
1556 | } | |
1557 | default: | |
1558 | { | |
1559 | event.Skip(); | |
1560 | return; | |
1561 | } | |
e1e955e1 | 1562 | } |
51cc4dad | 1563 | m_usedKeys = TRUE; |
e1e955e1 | 1564 | } |
c801d85f KB |
1565 | |
1566 | void wxListMainWindow::OnSetFocus( wxFocusEvent &WXUNUSED(event) ) | |
1567 | { | |
63852e78 RR |
1568 | m_hasFocus = TRUE; |
1569 | RefreshLine( m_current ); | |
bd8289c1 | 1570 | |
63852e78 | 1571 | if (!GetParent()) return; |
bd8289c1 | 1572 | |
63852e78 RR |
1573 | wxFocusEvent event( wxEVT_SET_FOCUS, GetParent()->GetId() ); |
1574 | event.SetEventObject( GetParent() ); | |
1575 | GetParent()->GetEventHandler()->ProcessEvent( event ); | |
e1e955e1 | 1576 | } |
c801d85f KB |
1577 | |
1578 | void wxListMainWindow::OnKillFocus( wxFocusEvent &WXUNUSED(event) ) | |
1579 | { | |
63852e78 RR |
1580 | m_hasFocus = FALSE; |
1581 | RefreshLine( m_current ); | |
e1e955e1 | 1582 | } |
c801d85f KB |
1583 | |
1584 | void wxListMainWindow::OnSize( wxSizeEvent &WXUNUSED(event) ) | |
1585 | { | |
1586 | /* | |
1587 | We don't even allow the wxScrolledWindow::AdjustScrollbars() call | |
63852e78 | 1588 | |
c801d85f | 1589 | */ |
e1e955e1 | 1590 | } |
c801d85f | 1591 | |
1e6d9499 | 1592 | void wxListMainWindow::DrawImage( int index, wxDC *dc, int x, int y ) |
c801d85f | 1593 | { |
63852e78 RR |
1594 | if ((m_mode & wxLC_ICON) && (m_normal_image_list)) |
1595 | { | |
1596 | m_normal_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT ); | |
1597 | return; | |
1598 | } | |
1599 | if ((m_mode & wxLC_SMALL_ICON) && (m_small_image_list)) | |
1600 | { | |
1601 | m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT ); | |
1602 | } | |
1603 | if ((m_mode & wxLC_REPORT) && (m_small_image_list)) | |
1604 | { | |
1605 | m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT ); | |
1606 | return; | |
1607 | } | |
e1e955e1 | 1608 | } |
c801d85f KB |
1609 | |
1610 | void wxListMainWindow::GetImageSize( int index, int &width, int &height ) | |
1611 | { | |
63852e78 RR |
1612 | if ((m_mode & wxLC_ICON) && (m_normal_image_list)) |
1613 | { | |
1614 | m_normal_image_list->GetSize( index, width, height ); | |
1615 | return; | |
1616 | } | |
1617 | if ((m_mode & wxLC_SMALL_ICON) && (m_small_image_list)) | |
1618 | { | |
1619 | m_small_image_list->GetSize( index, width, height ); | |
1620 | return; | |
1621 | } | |
1622 | if ((m_mode & wxLC_REPORT) && (m_small_image_list)) | |
1623 | { | |
1624 | m_small_image_list->GetSize( index, width, height ); | |
1625 | return; | |
1626 | } | |
1627 | width = 0; | |
1628 | height = 0; | |
e1e955e1 | 1629 | } |
c801d85f KB |
1630 | |
1631 | int wxListMainWindow::GetTextLength( wxString &s ) | |
1632 | { | |
1e6d9499 | 1633 | wxClientDC dc( this ); |
139adb6a RR |
1634 | long lw = 0; |
1635 | long lh = 0; | |
1636 | dc.GetTextExtent( s, &lw, &lh ); | |
1637 | return lw + 6; | |
e1e955e1 | 1638 | } |
c801d85f KB |
1639 | |
1640 | int wxListMainWindow::GetIndexOfLine( const wxListLineData *line ) | |
1641 | { | |
139adb6a RR |
1642 | int i = 0; |
1643 | wxNode *node = m_lines.First(); | |
1644 | while (node) | |
1645 | { | |
1646 | if (line == (wxListLineData*)node->Data()) return i; | |
1647 | i++; | |
1648 | node = node->Next(); | |
1649 | } | |
1650 | return -1; | |
e1e955e1 | 1651 | } |
c801d85f | 1652 | |
debe6624 | 1653 | void wxListMainWindow::SetImageList( wxImageList *imageList, int which ) |
c801d85f | 1654 | { |
139adb6a RR |
1655 | m_dirty = TRUE; |
1656 | if (which == wxIMAGE_LIST_NORMAL) m_normal_image_list = imageList; | |
1657 | if (which == wxIMAGE_LIST_SMALL) m_small_image_list = imageList; | |
e1e955e1 | 1658 | } |
c801d85f | 1659 | |
debe6624 | 1660 | void wxListMainWindow::SetItemSpacing( int spacing, bool isSmall ) |
c801d85f | 1661 | { |
139adb6a RR |
1662 | m_dirty = TRUE; |
1663 | if (isSmall) | |
1664 | { | |
1665 | m_small_spacing = spacing; | |
1666 | } | |
1667 | else | |
1668 | { | |
1669 | m_normal_spacing = spacing; | |
1670 | } | |
e1e955e1 | 1671 | } |
c801d85f | 1672 | |
debe6624 | 1673 | int wxListMainWindow::GetItemSpacing( bool isSmall ) |
c801d85f | 1674 | { |
139adb6a | 1675 | if (isSmall) return m_small_spacing; else return m_normal_spacing; |
e1e955e1 | 1676 | } |
c801d85f | 1677 | |
debe6624 | 1678 | void wxListMainWindow::SetColumn( int col, wxListItem &item ) |
c801d85f | 1679 | { |
63852e78 RR |
1680 | m_dirty = TRUE; |
1681 | wxNode *node = m_columns.Nth( col ); | |
1682 | if (node) | |
1683 | { | |
1684 | if (item.m_width == wxLIST_AUTOSIZE_USEHEADER) item.m_width = GetTextLength( item.m_text )+7; | |
1685 | wxListHeaderData *column = (wxListHeaderData*)node->Data(); | |
1686 | column->SetItem( item ); | |
1687 | } | |
1688 | wxListCtrl *lc = (wxListCtrl*) GetParent(); | |
1689 | if (lc->m_headerWin) lc->m_headerWin->Refresh(); | |
e1e955e1 | 1690 | } |
c801d85f | 1691 | |
debe6624 | 1692 | void wxListMainWindow::SetColumnWidth( int col, int width ) |
c801d85f | 1693 | { |
63852e78 | 1694 | if (!(m_mode & wxLC_REPORT)) return; |
0208334d | 1695 | |
63852e78 | 1696 | m_dirty = TRUE; |
bd8289c1 | 1697 | |
63852e78 RR |
1698 | wxNode *node = m_columns.Nth( col ); |
1699 | if (node) | |
1700 | { | |
1701 | wxListHeaderData *column = (wxListHeaderData*)node->Data(); | |
1702 | column->SetWidth( width ); | |
1703 | } | |
bd8289c1 | 1704 | |
63852e78 RR |
1705 | node = m_lines.First(); |
1706 | while (node) | |
0208334d | 1707 | { |
63852e78 RR |
1708 | wxListLineData *line = (wxListLineData*)node->Data(); |
1709 | wxNode *n = line->m_items.Nth( col ); | |
1710 | if (n) | |
1711 | { | |
1712 | wxListItemData *item = (wxListItemData*)n->Data(); | |
1713 | item->SetSize( width, -1 ); | |
1714 | } | |
1715 | node = node->Next(); | |
0208334d | 1716 | } |
bd8289c1 | 1717 | |
63852e78 RR |
1718 | wxListCtrl *lc = (wxListCtrl*) GetParent(); |
1719 | if (lc->m_headerWin) lc->m_headerWin->Refresh(); | |
e1e955e1 | 1720 | } |
c801d85f | 1721 | |
debe6624 | 1722 | void wxListMainWindow::GetColumn( int col, wxListItem &item ) |
c801d85f | 1723 | { |
63852e78 RR |
1724 | wxNode *node = m_columns.Nth( col ); |
1725 | if (node) | |
1726 | { | |
1727 | wxListHeaderData *column = (wxListHeaderData*)node->Data(); | |
1728 | column->GetItem( item ); | |
1729 | } | |
1730 | else | |
1731 | { | |
1732 | item.m_format = 0; | |
1733 | item.m_width = 0; | |
1734 | item.m_text = ""; | |
1735 | item.m_image = 0; | |
1736 | item.m_data = 0; | |
1737 | } | |
e1e955e1 | 1738 | } |
c801d85f | 1739 | |
bd8289c1 | 1740 | int wxListMainWindow::GetColumnWidth( int col ) |
c801d85f | 1741 | { |
92976ab6 RR |
1742 | wxNode *node = m_columns.Nth( col ); |
1743 | if (node) | |
1744 | { | |
1745 | wxListHeaderData *column = (wxListHeaderData*)node->Data(); | |
1746 | return column->GetWidth(); | |
1747 | } | |
1748 | else | |
1749 | { | |
1750 | return 0; | |
1751 | } | |
e1e955e1 | 1752 | } |
c801d85f KB |
1753 | |
1754 | int wxListMainWindow::GetColumnCount( void ) | |
1755 | { | |
92976ab6 | 1756 | return m_columns.Number(); |
e1e955e1 | 1757 | } |
c801d85f KB |
1758 | |
1759 | int wxListMainWindow::GetCountPerPage( void ) | |
1760 | { | |
92976ab6 | 1761 | return m_visibleLines; |
e1e955e1 | 1762 | } |
c801d85f KB |
1763 | |
1764 | void wxListMainWindow::SetItem( wxListItem &item ) | |
1765 | { | |
92976ab6 RR |
1766 | m_dirty = TRUE; |
1767 | wxNode *node = m_lines.Nth( item.m_itemId ); | |
1768 | if (node) | |
1769 | { | |
1770 | wxListLineData *line = (wxListLineData*)node->Data(); | |
1771 | if (m_mode & wxLC_REPORT) item.m_width = GetColumnWidth( item.m_col )-3; | |
1772 | line->SetItem( item.m_col, item ); | |
1773 | } | |
e1e955e1 | 1774 | } |
c801d85f | 1775 | |
debe6624 | 1776 | void wxListMainWindow::SetItemState( long item, long state, long stateMask ) |
c801d85f | 1777 | { |
92976ab6 | 1778 | // m_dirty = TRUE; no recalcs needed |
bd8289c1 | 1779 | |
92976ab6 | 1780 | wxListLineData *oldCurrent = m_current; |
bd8289c1 | 1781 | |
92976ab6 | 1782 | if (stateMask & wxLIST_STATE_FOCUSED) |
c801d85f | 1783 | { |
92976ab6 RR |
1784 | wxNode *node = m_lines.Nth( item ); |
1785 | if (node) | |
1786 | { | |
1787 | wxListLineData *line = (wxListLineData*)node->Data(); | |
1788 | UnfocusLine( m_current ); | |
1789 | m_current = line; | |
1790 | FocusLine( m_current ); | |
1791 | RefreshLine( m_current ); | |
00a39542 | 1792 | if (oldCurrent) RefreshLine( oldCurrent ); |
92976ab6 | 1793 | } |
e1e955e1 | 1794 | } |
bd8289c1 | 1795 | |
92976ab6 | 1796 | if (stateMask & wxLIST_STATE_SELECTED) |
c801d85f | 1797 | { |
92976ab6 RR |
1798 | bool on = state & wxLIST_STATE_SELECTED; |
1799 | if (!on && (m_mode & wxLC_SINGLE_SEL)) return; | |
1800 | ||
1801 | wxNode *node = m_lines.Nth( item ); | |
1802 | if (node) | |
1803 | { | |
1804 | wxListLineData *line = (wxListLineData*)node->Data(); | |
1805 | if (m_mode & wxLC_SINGLE_SEL) | |
1806 | { | |
1807 | UnfocusLine( m_current ); | |
1808 | m_current = line; | |
1809 | FocusLine( m_current ); | |
00a39542 | 1810 | if (oldCurrent) oldCurrent->Hilight( FALSE ); |
92976ab6 | 1811 | RefreshLine( m_current ); |
00a39542 | 1812 | if (oldCurrent) RefreshLine( oldCurrent ); |
92976ab6 RR |
1813 | } |
1814 | bool on = state & wxLIST_STATE_SELECTED; | |
139adb6a RR |
1815 | if (on != line->IsHilighted()) |
1816 | { | |
1817 | line->Hilight( on ); | |
1818 | RefreshLine( line ); | |
1819 | } | |
92976ab6 | 1820 | } |
e1e955e1 | 1821 | } |
e1e955e1 | 1822 | } |
c801d85f | 1823 | |
debe6624 | 1824 | int wxListMainWindow::GetItemState( long item, long stateMask ) |
c801d85f | 1825 | { |
92976ab6 RR |
1826 | int ret = wxLIST_STATE_DONTCARE; |
1827 | if (stateMask & wxLIST_STATE_FOCUSED) | |
c801d85f | 1828 | { |
92976ab6 RR |
1829 | wxNode *node = m_lines.Nth( item ); |
1830 | if (node) | |
1831 | { | |
1832 | wxListLineData *line = (wxListLineData*)node->Data(); | |
1833 | if (line == m_current) ret |= wxLIST_STATE_FOCUSED; | |
1834 | } | |
e1e955e1 | 1835 | } |
92976ab6 | 1836 | if (stateMask & wxLIST_STATE_SELECTED) |
c801d85f | 1837 | { |
92976ab6 RR |
1838 | wxNode *node = m_lines.Nth( item ); |
1839 | if (node) | |
1840 | { | |
1841 | wxListLineData *line = (wxListLineData*)node->Data(); | |
1842 | if (line->IsHilighted()) ret |= wxLIST_STATE_FOCUSED; | |
1843 | } | |
e1e955e1 | 1844 | } |
92976ab6 | 1845 | return ret; |
e1e955e1 | 1846 | } |
c801d85f KB |
1847 | |
1848 | void wxListMainWindow::GetItem( wxListItem &item ) | |
1849 | { | |
92976ab6 RR |
1850 | wxNode *node = m_lines.Nth( item.m_itemId ); |
1851 | if (node) | |
1852 | { | |
1853 | wxListLineData *line = (wxListLineData*)node->Data(); | |
1854 | line->GetItem( item.m_col, item ); | |
1855 | } | |
1856 | else | |
1857 | { | |
1858 | item.m_mask = 0; | |
1859 | item.m_text = ""; | |
1860 | item.m_image = 0; | |
1861 | item.m_data = 0; | |
1862 | } | |
e1e955e1 | 1863 | } |
c801d85f KB |
1864 | |
1865 | int wxListMainWindow::GetItemCount( void ) | |
1866 | { | |
92976ab6 | 1867 | return m_lines.Number(); |
e1e955e1 | 1868 | } |
c801d85f | 1869 | |
0a240683 | 1870 | void wxListMainWindow::GetItemRect( long index, wxRect &rect ) |
c801d85f | 1871 | { |
92976ab6 RR |
1872 | wxNode *node = m_lines.Nth( index ); |
1873 | if (node) | |
1874 | { | |
1875 | wxListLineData *line = (wxListLineData*)node->Data(); | |
1876 | line->GetRect( rect ); | |
1877 | } | |
1878 | else | |
1879 | { | |
1880 | rect.x = 0; | |
1881 | rect.y = 0; | |
1882 | rect.width = 0; | |
1883 | rect.height = 0; | |
1884 | } | |
e1e955e1 | 1885 | } |
c801d85f | 1886 | |
e3e65dac RR |
1887 | bool wxListMainWindow::GetItemPosition(long item, wxPoint& pos) |
1888 | { | |
92976ab6 RR |
1889 | wxNode *node = m_lines.Nth( item ); |
1890 | if (node) | |
1891 | { | |
0a240683 | 1892 | wxRect rect; |
92976ab6 RR |
1893 | wxListLineData *line = (wxListLineData*)node->Data(); |
1894 | line->GetRect( rect ); | |
1895 | pos.x = rect.x; | |
1896 | pos.y = rect.y; | |
1897 | } | |
1898 | else | |
1899 | { | |
1900 | pos.x = 0; | |
1901 | pos.y = 0; | |
1902 | } | |
1903 | return TRUE; | |
e1e955e1 | 1904 | } |
e3e65dac | 1905 | |
c801d85f KB |
1906 | int wxListMainWindow::GetSelectedItemCount( void ) |
1907 | { | |
92976ab6 RR |
1908 | int ret = 0; |
1909 | wxNode *node = m_lines.First(); | |
1910 | while (node) | |
1911 | { | |
1912 | wxListLineData *line = (wxListLineData*)node->Data(); | |
1913 | if (line->IsHilighted()) ret++; | |
1914 | node = node->Next(); | |
1915 | } | |
1916 | return ret; | |
e1e955e1 | 1917 | } |
c801d85f | 1918 | |
debe6624 | 1919 | void wxListMainWindow::SetMode( long mode ) |
c801d85f | 1920 | { |
92976ab6 RR |
1921 | m_dirty = TRUE; |
1922 | m_mode = mode; | |
bd8289c1 | 1923 | |
92976ab6 | 1924 | DeleteEverything(); |
bd8289c1 | 1925 | |
92976ab6 RR |
1926 | if (m_mode & wxLC_REPORT) |
1927 | { | |
1928 | m_xScroll = 0; | |
1929 | m_yScroll = 15; | |
1930 | } | |
1931 | else | |
1932 | { | |
1933 | m_xScroll = 15; | |
1934 | m_yScroll = 0; | |
1935 | } | |
e1e955e1 | 1936 | } |
c801d85f KB |
1937 | |
1938 | long wxListMainWindow::GetMode( void ) const | |
1939 | { | |
63852e78 | 1940 | return m_mode; |
e1e955e1 | 1941 | } |
c801d85f KB |
1942 | |
1943 | void wxListMainWindow::CalculatePositions( void ) | |
1944 | { | |
92976ab6 | 1945 | if (!m_lines.First()) return; |
e487524e | 1946 | |
1e6d9499 | 1947 | wxClientDC dc( this ); |
92976ab6 | 1948 | dc.SetFont( GetFont() ); |
c801d85f | 1949 | |
92976ab6 RR |
1950 | int iconSpacing = 0; |
1951 | if (m_mode & wxLC_ICON) iconSpacing = m_normal_spacing; | |
1952 | if (m_mode & wxLC_SMALL_ICON) iconSpacing = m_small_spacing; | |
e487524e | 1953 | |
92976ab6 RR |
1954 | // we take the first line (which also can be an icon or |
1955 | // an a text item in wxLC_ICON and wxLC_LIST modes) to | |
1956 | // measure the size of the line | |
e487524e | 1957 | |
92976ab6 RR |
1958 | int lineWidth = 0; |
1959 | int lineHeight = 0; | |
1960 | int lineSpacing = 0; | |
c801d85f | 1961 | |
92976ab6 RR |
1962 | wxListLineData *line = (wxListLineData*)m_lines.First()->Data(); |
1963 | line->CalculateSize( &dc, iconSpacing ); | |
1964 | int dummy = 0; | |
1965 | line->GetSize( dummy, lineSpacing ); | |
1966 | lineSpacing += 4; | |
bd8289c1 | 1967 | |
92976ab6 RR |
1968 | int clientWidth = 0; |
1969 | int clientHeight = 0; | |
bd8289c1 | 1970 | |
92976ab6 | 1971 | if (m_mode & wxLC_REPORT) |
c801d85f | 1972 | { |
92976ab6 RR |
1973 | int x = 4; |
1974 | int y = 1; | |
1975 | int entireHeight = m_lines.Number() * lineSpacing + 2; | |
1976 | int scroll_pos = GetScrollPos( wxVERTICAL ); | |
8b53e5a2 | 1977 | SetScrollbars( m_xScroll, m_yScroll, 0, (entireHeight+15) / m_yScroll, 0, scroll_pos, TRUE ); |
92976ab6 RR |
1978 | GetClientSize( &clientWidth, &clientHeight ); |
1979 | ||
1980 | wxNode* node = m_lines.First(); | |
1981 | while (node) | |
1982 | { | |
1983 | wxListLineData *line = (wxListLineData*)node->Data(); | |
1984 | line->CalculateSize( &dc, iconSpacing ); | |
1985 | line->SetPosition( &dc, x, y, clientWidth ); | |
1986 | int col_x = 2; | |
1987 | for (int i = 0; i < GetColumnCount(); i++) | |
1988 | { | |
1989 | line->SetColumnPosition( i, col_x ); | |
1990 | col_x += GetColumnWidth( i ); | |
1991 | } | |
1992 | y += lineSpacing; // one pixel blank line between items | |
1993 | node = node->Next(); | |
1994 | } | |
139adb6a | 1995 | m_visibleLines = clientHeight / lineSpacing; |
e1e955e1 | 1996 | } |
92976ab6 RR |
1997 | else |
1998 | { | |
1999 | // at first we try without any scrollbar. if the items don't | |
2000 | // fit into the window, we recalculate after subtracting an | |
2001 | // approximated 15 pt for the horizontal scrollbar | |
e487524e | 2002 | |
92976ab6 RR |
2003 | GetSize( &clientWidth, &clientHeight ); |
2004 | clientHeight -= 4; // sunken frame | |
bd8289c1 | 2005 | |
92976ab6 | 2006 | int entireWidth = 0; |
bd8289c1 | 2007 | |
92976ab6 | 2008 | for (int tries = 0; tries < 2; tries++) |
e487524e | 2009 | { |
92976ab6 RR |
2010 | entireWidth = 0; |
2011 | int x = 5; // painting is done at x-2 | |
2012 | int y = 5; // painting is done at y-2 | |
2013 | int maxWidth = 0; | |
2014 | wxNode *node = m_lines.First(); | |
2015 | while (node) | |
2016 | { | |
2017 | wxListLineData *line = (wxListLineData*)node->Data(); | |
2018 | line->CalculateSize( &dc, iconSpacing ); | |
2019 | line->SetPosition( &dc, x, y, clientWidth ); | |
2020 | line->GetSize( lineWidth, lineHeight ); | |
2021 | if (lineWidth > maxWidth) maxWidth = lineWidth; | |
2022 | y += lineSpacing; | |
8b53e5a2 | 2023 | if (y+lineSpacing-6 >= clientHeight) // -6 for earlier "line breaking" |
92976ab6 RR |
2024 | { |
2025 | y = 5; | |
8b53e5a2 RR |
2026 | x += maxWidth+6; |
2027 | entireWidth += maxWidth+6; | |
92976ab6 RR |
2028 | maxWidth = 0; |
2029 | } | |
2030 | node = node->Next(); | |
2031 | if (!node) entireWidth += maxWidth; | |
2032 | if ((tries == 0) && (entireWidth > clientWidth)) | |
2033 | { | |
2034 | clientHeight -= 15; // scrollbar height | |
2035 | break; | |
2036 | } | |
2037 | if (!node) tries = 1; // everything fits, no second try required | |
2038 | } | |
e487524e | 2039 | } |
8b53e5a2 | 2040 | m_visibleLines = (clientHeight+6) / (lineSpacing); // +6 for earlier "line breaking" |
92976ab6 RR |
2041 | |
2042 | int scroll_pos = GetScrollPos( wxHORIZONTAL ); | |
2043 | SetScrollbars( m_xScroll, m_yScroll, (entireWidth+15) / m_xScroll, 0, scroll_pos, 0, TRUE ); | |
e1e955e1 | 2044 | } |
e1e955e1 | 2045 | } |
c801d85f KB |
2046 | |
2047 | void wxListMainWindow::RealizeChanges( void ) | |
2048 | { | |
92976ab6 RR |
2049 | if (!m_current) |
2050 | { | |
2051 | wxNode *node = m_lines.First(); | |
2052 | if (node) m_current = (wxListLineData*)node->Data(); | |
2053 | } | |
2054 | if (m_current) | |
2055 | { | |
2056 | FocusLine( m_current ); | |
2057 | if (m_mode & wxLC_SINGLE_SEL) m_current->Hilight( TRUE ); | |
2058 | } | |
e1e955e1 | 2059 | } |
c801d85f | 2060 | |
debe6624 | 2061 | long wxListMainWindow::GetNextItem( long item, int WXUNUSED(geometry), int state ) |
c801d85f | 2062 | { |
63852e78 RR |
2063 | long ret = 0; |
2064 | if (item > 0) ret = item; | |
d9081042 | 2065 | if(ret >= GetItemCount()) return -1; |
63852e78 RR |
2066 | wxNode *node = m_lines.Nth( ret ); |
2067 | while (node) | |
2068 | { | |
2069 | wxListLineData *line = (wxListLineData*)node->Data(); | |
2070 | if ((state & wxLIST_STATE_FOCUSED) && (line == m_current)) return ret; | |
2071 | if ((state & wxLIST_STATE_SELECTED) && (line->IsHilighted())) return ret; | |
2072 | if (!state) return ret; | |
2073 | ret++; | |
2074 | node = node->Next(); | |
2075 | } | |
2076 | return -1; | |
e1e955e1 | 2077 | } |
c801d85f | 2078 | |
debe6624 | 2079 | void wxListMainWindow::DeleteItem( long index ) |
c801d85f | 2080 | { |
63852e78 RR |
2081 | m_dirty = TRUE; |
2082 | wxNode *node = m_lines.Nth( index ); | |
2083 | if (node) | |
2084 | { | |
2085 | wxListLineData *line = (wxListLineData*)node->Data(); | |
2086 | if (m_current == line) m_current = (wxListLineData *) NULL; | |
2087 | DeleteLine( line ); | |
2088 | m_lines.DeleteNode( node ); | |
2089 | } | |
e1e955e1 | 2090 | } |
c801d85f | 2091 | |
debe6624 | 2092 | void wxListMainWindow::DeleteColumn( int col ) |
c801d85f | 2093 | { |
5b077d48 | 2094 | wxCHECK_RET( col < (int)m_columns.GetCount(), |
87138c52 | 2095 | _T("attempting to delete inexistent column in wxListView") ); |
bd8289c1 | 2096 | |
5b077d48 RR |
2097 | m_dirty = TRUE; |
2098 | wxNode *node = m_columns.Nth( col ); | |
2099 | if (node) m_columns.DeleteNode( node ); | |
e1e955e1 | 2100 | } |
c801d85f KB |
2101 | |
2102 | void wxListMainWindow::DeleteAllItems( void ) | |
2103 | { | |
5b077d48 RR |
2104 | m_dirty = TRUE; |
2105 | m_current = (wxListLineData *) NULL; | |
2106 | wxNode *node = m_lines.First(); | |
2107 | while (node) | |
2108 | { | |
2109 | wxListLineData *line = (wxListLineData*)node->Data(); | |
2110 | DeleteLine( line ); | |
2111 | node = node->Next(); | |
2112 | } | |
2113 | m_lines.Clear(); | |
e1e955e1 | 2114 | } |
c801d85f KB |
2115 | |
2116 | void wxListMainWindow::DeleteEverything( void ) | |
2117 | { | |
5b077d48 RR |
2118 | m_dirty = TRUE; |
2119 | m_current = (wxListLineData *) NULL; | |
2120 | wxNode *node = m_lines.First(); | |
2121 | while (node) | |
2122 | { | |
2123 | wxListLineData *line = (wxListLineData*)node->Data(); | |
2124 | DeleteLine( line ); | |
2125 | node = node->Next(); | |
2126 | } | |
2127 | m_lines.Clear(); | |
2128 | m_current = (wxListLineData *) NULL; | |
2129 | m_columns.Clear(); | |
e1e955e1 | 2130 | } |
c801d85f | 2131 | |
debe6624 | 2132 | void wxListMainWindow::EnsureVisible( long index ) |
c801d85f | 2133 | { |
5b077d48 RR |
2134 | wxListLineData *oldCurrent = m_current; |
2135 | m_current = (wxListLineData *) NULL; | |
2136 | int i = index; | |
2137 | wxNode *node = m_lines.Nth( i ); | |
2138 | if (node) m_current = (wxListLineData*)node->Data(); | |
2139 | if (m_current) MoveToFocus(); | |
2140 | m_current = oldCurrent; | |
e1e955e1 | 2141 | } |
c801d85f | 2142 | |
debe6624 | 2143 | long wxListMainWindow::FindItem(long start, const wxString& str, bool WXUNUSED(partial) ) |
c801d85f | 2144 | { |
5b077d48 RR |
2145 | long pos = start; |
2146 | wxString tmp = str; | |
2147 | if (pos < 0) pos = 0; | |
2148 | wxNode *node = m_lines.Nth( pos ); | |
2149 | while (node) | |
2150 | { | |
2151 | wxListLineData *line = (wxListLineData*)node->Data(); | |
2152 | wxString s = ""; | |
2153 | line->GetText( 0, s ); | |
2154 | if (s == tmp) return pos; | |
2155 | node = node->Next(); | |
2156 | pos++; | |
2157 | } | |
2158 | return -1; | |
e1e955e1 | 2159 | } |
c801d85f | 2160 | |
debe6624 | 2161 | long wxListMainWindow::FindItem(long start, long data) |
c801d85f | 2162 | { |
5b077d48 RR |
2163 | long pos = start; |
2164 | if (pos < 0) pos = 0; | |
2165 | wxNode *node = m_lines.Nth( pos ); | |
2166 | while (node) | |
2167 | { | |
2168 | wxListLineData *line = (wxListLineData*)node->Data(); | |
2169 | wxListItem item; | |
2170 | line->GetItem( 0, item ); | |
2171 | if (item.m_data == data) return pos; | |
2172 | node = node->Next(); | |
2173 | pos++; | |
2174 | } | |
2175 | return -1; | |
e1e955e1 | 2176 | } |
c801d85f | 2177 | |
debe6624 | 2178 | long wxListMainWindow::HitTest( int x, int y, int &flags ) |
c801d85f | 2179 | { |
5b077d48 RR |
2180 | wxNode *node = m_lines.First(); |
2181 | int count = 0; | |
2182 | while (node) | |
c801d85f | 2183 | { |
5b077d48 RR |
2184 | wxListLineData *line = (wxListLineData*)node->Data(); |
2185 | long ret = line->IsHit( x, y ); | |
2186 | if (ret & flags) | |
2187 | { | |
2188 | flags = ret; | |
2189 | return count; | |
2190 | } | |
2191 | node = node->Next(); | |
2192 | count++; | |
e1e955e1 | 2193 | } |
5b077d48 | 2194 | return -1; |
e1e955e1 | 2195 | } |
c801d85f KB |
2196 | |
2197 | void wxListMainWindow::InsertItem( wxListItem &item ) | |
2198 | { | |
5b077d48 RR |
2199 | m_dirty = TRUE; |
2200 | int mode = 0; | |
2201 | if (m_mode & wxLC_REPORT) mode = wxLC_REPORT; | |
2202 | else if (m_mode & wxLC_LIST) mode = wxLC_LIST; | |
2203 | else if (m_mode & wxLC_ICON) mode = wxLC_ICON; | |
2204 | else if (m_mode & wxLC_SMALL_ICON) mode = wxLC_ICON; // no typo | |
2205 | ||
2206 | wxListLineData *line = new wxListLineData( this, mode, m_hilightBrush ); | |
2207 | ||
2208 | if (m_mode & wxLC_REPORT) | |
2209 | { | |
2210 | line->InitItems( GetColumnCount() ); | |
2211 | item.m_width = GetColumnWidth( 0 )-3; | |
2212 | } | |
2213 | else | |
2214 | { | |
2215 | line->InitItems( 1 ); | |
2216 | } | |
2217 | ||
2218 | line->SetItem( 0, item ); | |
2219 | if ((item.m_itemId >= 0) && (item.m_itemId < (int)m_lines.GetCount())) | |
2220 | { | |
2221 | wxNode *node = m_lines.Nth( item.m_itemId ); | |
2222 | if (node) m_lines.Insert( node, line ); | |
2223 | } | |
2224 | else | |
2225 | { | |
2226 | m_lines.Append( line ); | |
2227 | } | |
e1e955e1 | 2228 | } |
c801d85f | 2229 | |
debe6624 | 2230 | void wxListMainWindow::InsertColumn( long col, wxListItem &item ) |
c801d85f | 2231 | { |
5b077d48 RR |
2232 | m_dirty = TRUE; |
2233 | if (m_mode & wxLC_REPORT) | |
3db7be80 | 2234 | { |
5b077d48 RR |
2235 | if (item.m_width == wxLIST_AUTOSIZE_USEHEADER) item.m_width = GetTextLength( item.m_text ); |
2236 | wxListHeaderData *column = new wxListHeaderData( item ); | |
2237 | if ((col >= 0) && (col < (int)m_columns.GetCount())) | |
2238 | { | |
2239 | wxNode *node = m_columns.Nth( col ); | |
2240 | if (node) | |
2241 | m_columns.Insert( node, column ); | |
2242 | } | |
2243 | else | |
2244 | { | |
2245 | m_columns.Append( column ); | |
2246 | } | |
3db7be80 | 2247 | } |
e1e955e1 | 2248 | } |
c801d85f KB |
2249 | |
2250 | wxListCtrlCompare list_ctrl_compare_func_2; | |
2251 | long list_ctrl_compare_data; | |
2252 | ||
2253 | int list_ctrl_compare_func_1( const void *arg1, const void *arg2 ) | |
2254 | { | |
5b077d48 RR |
2255 | wxListLineData *line1 = *((wxListLineData**)arg1); |
2256 | wxListLineData *line2 = *((wxListLineData**)arg2); | |
2257 | wxListItem item; | |
2258 | line1->GetItem( 0, item ); | |
2259 | long data1 = item.m_data; | |
2260 | line2->GetItem( 0, item ); | |
2261 | long data2 = item.m_data; | |
2262 | return list_ctrl_compare_func_2( data1, data2, list_ctrl_compare_data ); | |
e1e955e1 | 2263 | } |
c801d85f KB |
2264 | |
2265 | void wxListMainWindow::SortItems( wxListCtrlCompare fn, long data ) | |
2266 | { | |
5b077d48 RR |
2267 | list_ctrl_compare_func_2 = fn; |
2268 | list_ctrl_compare_data = data; | |
2269 | m_lines.Sort( list_ctrl_compare_func_1 ); | |
e1e955e1 | 2270 | } |
c801d85f | 2271 | |
c801d85f KB |
2272 | // ------------------------------------------------------------------------------------- |
2273 | // wxListItem | |
2274 | // ------------------------------------------------------------------------------------- | |
2275 | ||
2276 | IMPLEMENT_DYNAMIC_CLASS(wxListItem, wxObject) | |
2277 | ||
2278 | wxListItem::wxListItem(void) | |
2279 | { | |
63852e78 RR |
2280 | m_mask = 0; |
2281 | m_itemId = 0; | |
2282 | m_col = 0; | |
2283 | m_state = 0; | |
2284 | m_stateMask = 0; | |
2285 | m_image = 0; | |
2286 | m_data = 0; | |
2287 | m_format = wxLIST_FORMAT_CENTRE; | |
2288 | m_width = 0; | |
2289 | m_colour = wxBLACK; | |
c801d85f KB |
2290 | } |
2291 | ||
2292 | // ------------------------------------------------------------------------------------- | |
2293 | // wxListEvent | |
2294 | // ------------------------------------------------------------------------------------- | |
2295 | ||
92976ab6 | 2296 | IMPLEMENT_DYNAMIC_CLASS(wxListEvent, wxNotifyEvent) |
c801d85f | 2297 | |
8f79098a | 2298 | wxListEvent::wxListEvent( wxEventType commandType, int id ): |
92976ab6 | 2299 | wxNotifyEvent( commandType, id ) |
c801d85f | 2300 | { |
5b077d48 RR |
2301 | m_code = 0; |
2302 | m_itemIndex = 0; | |
2303 | m_oldItemIndex = 0; | |
2304 | m_col = 0; | |
2305 | m_cancelled = FALSE; | |
2306 | m_pointDrag.x = 0; | |
2307 | m_pointDrag.y = 0; | |
e1e955e1 | 2308 | } |
c801d85f KB |
2309 | |
2310 | // ------------------------------------------------------------------------------------- | |
2311 | // wxListCtrl | |
2312 | // ------------------------------------------------------------------------------------- | |
2313 | ||
2314 | IMPLEMENT_DYNAMIC_CLASS(wxListCtrl, wxControl) | |
2315 | ||
2316 | BEGIN_EVENT_TABLE(wxListCtrl,wxControl) | |
2317 | EVT_SIZE (wxListCtrl::OnSize) | |
53010e52 | 2318 | EVT_IDLE (wxListCtrl::OnIdle) |
c801d85f KB |
2319 | END_EVENT_TABLE() |
2320 | ||
2321 | wxListCtrl::wxListCtrl(void) | |
2322 | { | |
5b077d48 RR |
2323 | m_imageListNormal = (wxImageList *) NULL; |
2324 | m_imageListSmall = (wxImageList *) NULL; | |
2325 | m_imageListState = (wxImageList *) NULL; | |
2326 | m_mainWin = (wxListMainWindow*) NULL; | |
2327 | m_headerWin = (wxListHeaderWindow*) NULL; | |
c801d85f KB |
2328 | } |
2329 | ||
c801d85f KB |
2330 | wxListCtrl::~wxListCtrl(void) |
2331 | { | |
2332 | } | |
2333 | ||
bd8289c1 | 2334 | bool wxListCtrl::Create( wxWindow *parent, wxWindowID id, |
debe6624 | 2335 | const wxPoint &pos, const wxSize &size, |
bd8289c1 | 2336 | long style, const wxValidator &validator, |
32e9da8b | 2337 | const wxString &name ) |
c801d85f | 2338 | { |
5b077d48 RR |
2339 | m_imageListNormal = (wxImageList *) NULL; |
2340 | m_imageListSmall = (wxImageList *) NULL; | |
2341 | m_imageListState = (wxImageList *) NULL; | |
2342 | m_mainWin = (wxListMainWindow*) NULL; | |
2343 | m_headerWin = (wxListHeaderWindow*) NULL; | |
bd8289c1 | 2344 | |
5b077d48 | 2345 | long s = style; |
bd8289c1 | 2346 | |
5b077d48 RR |
2347 | if ((s & wxLC_REPORT == 0) && |
2348 | (s & wxLC_LIST == 0) && | |
2349 | (s & wxLC_ICON == 0)) | |
2350 | { | |
2351 | s = s | wxLC_LIST; | |
2352 | } | |
bd8289c1 | 2353 | |
5b077d48 | 2354 | bool ret = wxControl::Create( parent, id, pos, size, s, name ); |
bd8289c1 | 2355 | |
5b077d48 | 2356 | SetValidator( validator ); |
907789a0 | 2357 | |
5b077d48 | 2358 | if (s & wxSUNKEN_BORDER) s -= wxSUNKEN_BORDER; |
bd8289c1 | 2359 | |
5b077d48 | 2360 | m_mainWin = new wxListMainWindow( this, -1, wxPoint(0,0), size, s ); |
bd8289c1 | 2361 | |
f03fc89f | 2362 | if (HasFlag(wxLC_REPORT)) |
5b077d48 RR |
2363 | m_headerWin = new wxListHeaderWindow( this, -1, m_mainWin, wxPoint(0,0), wxSize(size.x,23), wxTAB_TRAVERSAL ); |
2364 | else | |
2365 | m_headerWin = (wxListHeaderWindow *) NULL; | |
bd8289c1 | 2366 | |
58dea4b0 RR |
2367 | SetBackgroundColour( *wxWHITE ); |
2368 | ||
5b077d48 | 2369 | return ret; |
e1e955e1 | 2370 | } |
c801d85f KB |
2371 | |
2372 | void wxListCtrl::OnSize( wxSizeEvent &WXUNUSED(event) ) | |
2373 | { | |
5b077d48 | 2374 | /* handled in OnIdle */ |
bd8289c1 | 2375 | |
5b077d48 | 2376 | if (m_mainWin) m_mainWin->m_dirty = TRUE; |
e1e955e1 | 2377 | } |
c801d85f | 2378 | |
debe6624 | 2379 | void wxListCtrl::SetSingleStyle( long style, bool add ) |
c801d85f | 2380 | { |
f03fc89f | 2381 | long flag = GetWindowStyle(); |
bd8289c1 | 2382 | |
5b077d48 RR |
2383 | if (add) |
2384 | { | |
2385 | if (style & wxLC_MASK_TYPE) flag = flag & ~wxLC_MASK_TYPE; | |
2386 | if (style & wxLC_MASK_ALIGN) flag = flag & ~wxLC_MASK_ALIGN; | |
2387 | if (style & wxLC_MASK_SORT) flag = flag & ~wxLC_MASK_SORT; | |
2388 | } | |
c801d85f | 2389 | |
5b077d48 RR |
2390 | if (add) |
2391 | { | |
2392 | flag |= style; | |
2393 | } | |
2394 | else | |
2395 | { | |
2396 | if (flag & style) flag -= style; | |
2397 | } | |
bd8289c1 | 2398 | |
5b077d48 | 2399 | SetWindowStyleFlag( flag ); |
e1e955e1 | 2400 | } |
c801d85f | 2401 | |
debe6624 | 2402 | void wxListCtrl::SetWindowStyleFlag( long flag ) |
c801d85f | 2403 | { |
121a3581 RR |
2404 | if (m_mainWin) |
2405 | { | |
2406 | m_mainWin->DeleteEverything(); | |
c801d85f | 2407 | |
121a3581 RR |
2408 | int width = 0; |
2409 | int height = 0; | |
2410 | GetClientSize( &width, &height ); | |
c801d85f | 2411 | |
121a3581 | 2412 | m_mainWin->SetMode( flag ); |
bd8289c1 | 2413 | |
121a3581 | 2414 | if (flag & wxLC_REPORT) |
5b077d48 | 2415 | { |
121a3581 | 2416 | if (!HasFlag(wxLC_REPORT)) |
5b077d48 | 2417 | { |
121a3581 RR |
2418 | if (!m_headerWin) |
2419 | { | |
2420 | m_headerWin = new wxListHeaderWindow( this, -1, m_mainWin, | |
2421 | wxPoint(0,0), wxSize(width,23), wxTAB_TRAVERSAL ); | |
2422 | } | |
2423 | else | |
2424 | { | |
2425 | m_headerWin->Show( TRUE ); | |
2426 | } | |
5b077d48 RR |
2427 | } |
2428 | } | |
121a3581 | 2429 | else |
5b077d48 | 2430 | { |
121a3581 RR |
2431 | if (HasFlag(wxLC_REPORT)) |
2432 | { | |
2433 | m_headerWin->Show( FALSE ); | |
2434 | } | |
2435 | } | |
e1e955e1 | 2436 | } |
121a3581 | 2437 | |
5b077d48 | 2438 | wxWindow::SetWindowStyleFlag( flag ); |
e1e955e1 | 2439 | } |
c801d85f | 2440 | |
e487524e | 2441 | bool wxListCtrl::GetColumn(int col, wxListItem &item) const |
c801d85f | 2442 | { |
5b077d48 RR |
2443 | m_mainWin->GetColumn( col, item ); |
2444 | return TRUE; | |
e1e955e1 | 2445 | } |
c801d85f | 2446 | |
debe6624 | 2447 | bool wxListCtrl::SetColumn( int col, wxListItem& item ) |
c801d85f | 2448 | { |
5b077d48 RR |
2449 | m_mainWin->SetColumn( col, item ); |
2450 | return TRUE; | |
e1e955e1 | 2451 | } |
c801d85f | 2452 | |
e487524e | 2453 | int wxListCtrl::GetColumnWidth( int col ) const |
c801d85f | 2454 | { |
5b077d48 | 2455 | return m_mainWin->GetColumnWidth( col ); |
e1e955e1 | 2456 | } |
c801d85f | 2457 | |
debe6624 | 2458 | bool wxListCtrl::SetColumnWidth( int col, int width ) |
c801d85f | 2459 | { |
5b077d48 RR |
2460 | m_mainWin->SetColumnWidth( col, width ); |
2461 | return TRUE; | |
e1e955e1 | 2462 | } |
c801d85f | 2463 | |
e487524e | 2464 | int wxListCtrl::GetCountPerPage(void) const |
c801d85f KB |
2465 | { |
2466 | return m_mainWin->GetCountPerPage(); // different from Windows ? | |
e1e955e1 | 2467 | } |
c801d85f KB |
2468 | |
2469 | /* | |
2470 | wxText& wxListCtrl::GetEditControl(void) const | |
2471 | { | |
e1e955e1 | 2472 | } |
c801d85f KB |
2473 | */ |
2474 | ||
e487524e | 2475 | bool wxListCtrl::GetItem( wxListItem &info ) const |
c801d85f | 2476 | { |
5b077d48 RR |
2477 | m_mainWin->GetItem( info ); |
2478 | return TRUE; | |
e1e955e1 | 2479 | } |
c801d85f KB |
2480 | |
2481 | bool wxListCtrl::SetItem( wxListItem &info ) | |
2482 | { | |
5b077d48 RR |
2483 | m_mainWin->SetItem( info ); |
2484 | return TRUE; | |
e1e955e1 | 2485 | } |
c801d85f | 2486 | |
debe6624 | 2487 | long wxListCtrl::SetItem( long index, int col, const wxString& label, int imageId ) |
c801d85f | 2488 | { |
5b077d48 RR |
2489 | wxListItem info; |
2490 | info.m_text = label; | |
2491 | info.m_mask = wxLIST_MASK_TEXT; | |
2492 | info.m_itemId = index; | |
2493 | info.m_col = col; | |
2494 | if ( imageId > -1 ) | |
2495 | { | |
2496 | info.m_image = imageId; | |
2497 | info.m_mask |= wxLIST_MASK_IMAGE; | |
2498 | }; | |
2499 | m_mainWin->SetItem(info); | |
2500 | return TRUE; | |
e1e955e1 | 2501 | } |
c801d85f | 2502 | |
e487524e | 2503 | int wxListCtrl::GetItemState( long item, long stateMask ) const |
c801d85f | 2504 | { |
5b077d48 | 2505 | return m_mainWin->GetItemState( item, stateMask ); |
e1e955e1 | 2506 | } |
c801d85f | 2507 | |
debe6624 | 2508 | bool wxListCtrl::SetItemState( long item, long state, long stateMask ) |
c801d85f | 2509 | { |
5b077d48 RR |
2510 | m_mainWin->SetItemState( item, state, stateMask ); |
2511 | return TRUE; | |
e1e955e1 | 2512 | } |
c801d85f | 2513 | |
debe6624 | 2514 | bool wxListCtrl::SetItemImage( long item, int image, int WXUNUSED(selImage) ) |
c801d85f | 2515 | { |
5b077d48 RR |
2516 | wxListItem info; |
2517 | info.m_image = image; | |
2518 | info.m_mask = wxLIST_MASK_IMAGE; | |
2519 | info.m_itemId = item; | |
2520 | m_mainWin->SetItem( info ); | |
2521 | return TRUE; | |
e1e955e1 | 2522 | } |
c801d85f | 2523 | |
e487524e | 2524 | wxString wxListCtrl::GetItemText( long item ) const |
c801d85f | 2525 | { |
5b077d48 RR |
2526 | wxListItem info; |
2527 | info.m_itemId = item; | |
2528 | m_mainWin->GetItem( info ); | |
2529 | return info.m_text; | |
e1e955e1 | 2530 | } |
c801d85f | 2531 | |
debe6624 | 2532 | void wxListCtrl::SetItemText( long item, const wxString &str ) |
c801d85f | 2533 | { |
5b077d48 RR |
2534 | wxListItem info; |
2535 | info.m_mask = wxLIST_MASK_TEXT; | |
2536 | info.m_itemId = item; | |
2537 | info.m_text = str; | |
2538 | m_mainWin->SetItem( info ); | |
e1e955e1 | 2539 | } |
c801d85f | 2540 | |
e487524e | 2541 | long wxListCtrl::GetItemData( long item ) const |
c801d85f | 2542 | { |
5b077d48 RR |
2543 | wxListItem info; |
2544 | info.m_itemId = item; | |
2545 | m_mainWin->GetItem( info ); | |
2546 | return info.m_data; | |
e1e955e1 | 2547 | } |
c801d85f | 2548 | |
debe6624 | 2549 | bool wxListCtrl::SetItemData( long item, long data ) |
c801d85f | 2550 | { |
5b077d48 RR |
2551 | wxListItem info; |
2552 | info.m_mask = wxLIST_MASK_DATA; | |
2553 | info.m_itemId = item; | |
2554 | info.m_data = data; | |
2555 | m_mainWin->SetItem( info ); | |
2556 | return TRUE; | |
e1e955e1 | 2557 | } |
c801d85f | 2558 | |
0a240683 | 2559 | bool wxListCtrl::GetItemRect( long item, wxRect &rect, int WXUNUSED(code) ) const |
c801d85f | 2560 | { |
5b077d48 RR |
2561 | m_mainWin->GetItemRect( item, rect ); |
2562 | return TRUE; | |
e1e955e1 | 2563 | } |
c801d85f | 2564 | |
e487524e | 2565 | bool wxListCtrl::GetItemPosition( long item, wxPoint& pos ) const |
c801d85f | 2566 | { |
5b077d48 RR |
2567 | m_mainWin->GetItemPosition( item, pos ); |
2568 | return TRUE; | |
e1e955e1 | 2569 | } |
c801d85f | 2570 | |
debe6624 | 2571 | bool wxListCtrl::SetItemPosition( long WXUNUSED(item), const wxPoint& WXUNUSED(pos) ) |
c801d85f | 2572 | { |
5b077d48 | 2573 | return 0; |
e1e955e1 | 2574 | } |
c801d85f | 2575 | |
e487524e | 2576 | int wxListCtrl::GetItemCount(void) const |
c801d85f | 2577 | { |
5b077d48 | 2578 | return m_mainWin->GetItemCount(); |
e1e955e1 | 2579 | } |
c801d85f | 2580 | |
92976ab6 RR |
2581 | int wxListCtrl::GetColumnCount(void) const |
2582 | { | |
5b077d48 | 2583 | return m_mainWin->GetColumnCount(); |
92976ab6 RR |
2584 | } |
2585 | ||
33d0b396 RR |
2586 | void wxListCtrl::SetItemSpacing( int spacing, bool isSmall ) |
2587 | { | |
5b077d48 | 2588 | m_mainWin->SetItemSpacing( spacing, isSmall ); |
e1e955e1 | 2589 | } |
33d0b396 | 2590 | |
e487524e | 2591 | int wxListCtrl::GetItemSpacing( bool isSmall ) const |
c801d85f | 2592 | { |
5b077d48 | 2593 | return m_mainWin->GetItemSpacing( isSmall ); |
e1e955e1 | 2594 | } |
c801d85f | 2595 | |
e487524e | 2596 | int wxListCtrl::GetSelectedItemCount(void) const |
c801d85f | 2597 | { |
5b077d48 | 2598 | return m_mainWin->GetSelectedItemCount(); |
e1e955e1 | 2599 | } |
c801d85f KB |
2600 | |
2601 | /* | |
2602 | wxColour wxListCtrl::GetTextColour(void) const | |
2603 | { | |
e1e955e1 | 2604 | } |
c801d85f KB |
2605 | |
2606 | void wxListCtrl::SetTextColour(const wxColour& WXUNUSED(col)) | |
2607 | { | |
e1e955e1 | 2608 | } |
c801d85f KB |
2609 | */ |
2610 | ||
e487524e | 2611 | long wxListCtrl::GetTopItem(void) const |
c801d85f | 2612 | { |
5b077d48 | 2613 | return 0; |
e1e955e1 | 2614 | } |
c801d85f | 2615 | |
6de97a3b | 2616 | long wxListCtrl::GetNextItem( long item, int geom, int state ) const |
c801d85f | 2617 | { |
5b077d48 | 2618 | return m_mainWin->GetNextItem( item, geom, state ); |
e1e955e1 | 2619 | } |
c801d85f | 2620 | |
e487524e | 2621 | wxImageList *wxListCtrl::GetImageList(int which) const |
c801d85f | 2622 | { |
5b077d48 RR |
2623 | if (which == wxIMAGE_LIST_NORMAL) |
2624 | { | |
2625 | return m_imageListNormal; | |
2626 | } | |
2627 | else if (which == wxIMAGE_LIST_SMALL) | |
2628 | { | |
2629 | return m_imageListSmall; | |
2630 | } | |
2631 | else if (which == wxIMAGE_LIST_STATE) | |
2632 | { | |
2633 | return m_imageListState; | |
2634 | } | |
2635 | return (wxImageList *) NULL; | |
e1e955e1 | 2636 | } |
c801d85f | 2637 | |
debe6624 | 2638 | void wxListCtrl::SetImageList( wxImageList *imageList, int which ) |
c801d85f | 2639 | { |
5b077d48 | 2640 | m_mainWin->SetImageList( imageList, which ); |
e1e955e1 | 2641 | } |
c801d85f | 2642 | |
debe6624 | 2643 | bool wxListCtrl::Arrange( int WXUNUSED(flag) ) |
c801d85f | 2644 | { |
5b077d48 | 2645 | return 0; |
e1e955e1 | 2646 | } |
c801d85f | 2647 | |
debe6624 | 2648 | bool wxListCtrl::DeleteItem( long item ) |
c801d85f | 2649 | { |
5b077d48 RR |
2650 | m_mainWin->DeleteItem( item ); |
2651 | return TRUE; | |
e1e955e1 | 2652 | } |
c801d85f KB |
2653 | |
2654 | bool wxListCtrl::DeleteAllItems(void) | |
2655 | { | |
5b077d48 RR |
2656 | m_mainWin->DeleteAllItems(); |
2657 | return TRUE; | |
e1e955e1 | 2658 | } |
c801d85f | 2659 | |
4f22cf8d | 2660 | bool wxListCtrl::DeleteAllColumns() |
bd8289c1 VZ |
2661 | { |
2662 | for ( size_t n = 0; n < m_mainWin->m_columns.GetCount(); n++ ) | |
2663 | DeleteColumn(n); | |
4f22cf8d | 2664 | |
5b077d48 | 2665 | return TRUE; |
4f22cf8d RR |
2666 | } |
2667 | ||
2668 | void wxListCtrl::ClearAll() | |
2669 | { | |
5b077d48 | 2670 | m_mainWin->DeleteEverything(); |
bd8289c1 VZ |
2671 | } |
2672 | ||
debe6624 | 2673 | bool wxListCtrl::DeleteColumn( int col ) |
c801d85f | 2674 | { |
5b077d48 RR |
2675 | m_mainWin->DeleteColumn( col ); |
2676 | return TRUE; | |
e1e955e1 | 2677 | } |
c801d85f KB |
2678 | |
2679 | /* | |
debe6624 | 2680 | wxText& wxListCtrl::Edit( long WXUNUSED(item ) ) |
c801d85f | 2681 | { |
e1e955e1 | 2682 | } |
c801d85f KB |
2683 | */ |
2684 | ||
debe6624 | 2685 | bool wxListCtrl::EnsureVisible( long item ) |
c801d85f | 2686 | { |
5b077d48 RR |
2687 | m_mainWin->EnsureVisible( item ); |
2688 | return TRUE; | |
e1e955e1 | 2689 | } |
c801d85f | 2690 | |
debe6624 | 2691 | long wxListCtrl::FindItem( long start, const wxString& str, bool partial ) |
c801d85f | 2692 | { |
5b077d48 | 2693 | return m_mainWin->FindItem( start, str, partial ); |
e1e955e1 | 2694 | } |
c801d85f | 2695 | |
debe6624 | 2696 | long wxListCtrl::FindItem( long start, long data ) |
c801d85f | 2697 | { |
5b077d48 | 2698 | return m_mainWin->FindItem( start, data ); |
e1e955e1 | 2699 | } |
c801d85f | 2700 | |
bd8289c1 | 2701 | long wxListCtrl::FindItem( long WXUNUSED(start), const wxPoint& WXUNUSED(pt), |
debe6624 | 2702 | int WXUNUSED(direction)) |
c801d85f | 2703 | { |
5b077d48 | 2704 | return 0; |
e1e955e1 | 2705 | } |
c801d85f KB |
2706 | |
2707 | long wxListCtrl::HitTest( const wxPoint &point, int &flags ) | |
2708 | { | |
5b077d48 | 2709 | return m_mainWin->HitTest( (int)point.x, (int)point.y, flags ); |
e1e955e1 | 2710 | } |
c801d85f KB |
2711 | |
2712 | long wxListCtrl::InsertItem( wxListItem& info ) | |
2713 | { | |
5b077d48 RR |
2714 | m_mainWin->InsertItem( info ); |
2715 | return 0; | |
e1e955e1 | 2716 | } |
c801d85f | 2717 | |
debe6624 | 2718 | long wxListCtrl::InsertItem( long index, const wxString &label ) |
c801d85f | 2719 | { |
51cc4dad RR |
2720 | wxListItem info; |
2721 | info.m_text = label; | |
2722 | info.m_mask = wxLIST_MASK_TEXT; | |
2723 | info.m_itemId = index; | |
2724 | return InsertItem( info ); | |
e1e955e1 | 2725 | } |
c801d85f | 2726 | |
debe6624 | 2727 | long wxListCtrl::InsertItem( long index, int imageIndex ) |
c801d85f | 2728 | { |
51cc4dad RR |
2729 | wxListItem info; |
2730 | info.m_mask = wxLIST_MASK_IMAGE; | |
2731 | info.m_image = imageIndex; | |
2732 | info.m_itemId = index; | |
2733 | return InsertItem( info ); | |
e1e955e1 | 2734 | } |
c801d85f | 2735 | |
debe6624 | 2736 | long wxListCtrl::InsertItem( long index, const wxString &label, int imageIndex ) |
c801d85f | 2737 | { |
51cc4dad RR |
2738 | wxListItem info; |
2739 | info.m_text = label; | |
2740 | info.m_image = imageIndex; | |
2741 | info.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_IMAGE; | |
2742 | info.m_itemId = index; | |
2743 | return InsertItem( info ); | |
e1e955e1 | 2744 | } |
c801d85f | 2745 | |
debe6624 | 2746 | long wxListCtrl::InsertColumn( long col, wxListItem &item ) |
c801d85f | 2747 | { |
51cc4dad RR |
2748 | m_mainWin->InsertColumn( col, item ); |
2749 | return 0; | |
e1e955e1 | 2750 | } |
c801d85f | 2751 | |
debe6624 JS |
2752 | long wxListCtrl::InsertColumn( long col, const wxString &heading, |
2753 | int format, int width ) | |
c801d85f | 2754 | { |
51cc4dad RR |
2755 | wxListItem item; |
2756 | item.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_FORMAT; | |
2757 | item.m_text = heading; | |
2758 | if (width >= -2) | |
2759 | { | |
2760 | item.m_mask |= wxLIST_MASK_WIDTH; | |
2761 | item.m_width = width; | |
2762 | } | |
2763 | item.m_format = format; | |
c801d85f | 2764 | |
51cc4dad | 2765 | return InsertColumn( col, item ); |
e1e955e1 | 2766 | } |
c801d85f | 2767 | |
debe6624 | 2768 | bool wxListCtrl::ScrollList( int WXUNUSED(dx), int WXUNUSED(dy) ) |
c801d85f | 2769 | { |
51cc4dad | 2770 | return 0; |
e1e955e1 | 2771 | } |
c801d85f KB |
2772 | |
2773 | // Sort items. | |
2774 | // fn is a function which takes 3 long arguments: item1, item2, data. | |
2775 | // item1 is the long data associated with a first item (NOT the index). | |
2776 | // item2 is the long data associated with a second item (NOT the index). | |
2777 | // data is the same value as passed to SortItems. | |
2778 | // The return value is a negative number if the first item should precede the second | |
2779 | // item, a positive number of the second item should precede the first, | |
2780 | // or zero if the two items are equivalent. | |
2781 | // data is arbitrary data to be passed to the sort function. | |
2782 | ||
2783 | bool wxListCtrl::SortItems( wxListCtrlCompare fn, long data ) | |
2784 | { | |
51cc4dad RR |
2785 | m_mainWin->SortItems( fn, data ); |
2786 | return TRUE; | |
e1e955e1 | 2787 | } |
c801d85f | 2788 | |
e3e65dac | 2789 | void wxListCtrl::OnIdle( wxIdleEvent &WXUNUSED(event) ) |
53010e52 | 2790 | { |
51cc4dad | 2791 | if (!m_mainWin->m_dirty) return; |
53010e52 | 2792 | |
51cc4dad RR |
2793 | int cw = 0; |
2794 | int ch = 0; | |
2795 | GetClientSize( &cw, &ch ); | |
bd8289c1 | 2796 | |
51cc4dad RR |
2797 | int x = 0; |
2798 | int y = 0; | |
2799 | int w = 0; | |
2800 | int h = 0; | |
bd8289c1 | 2801 | |
f03fc89f | 2802 | if (HasFlag(wxLC_REPORT)) |
51cc4dad RR |
2803 | { |
2804 | m_headerWin->GetPosition( &x, &y ); | |
2805 | m_headerWin->GetSize( &w, &h ); | |
2806 | if ((x != 0) || (y != 0) || (w != cw) || (h != 23)) | |
2807 | m_headerWin->SetSize( 0, 0, cw, 23 ); | |
2808 | ||
2809 | m_mainWin->GetPosition( &x, &y ); | |
2810 | m_mainWin->GetSize( &w, &h ); | |
2811 | if ((x != 0) || (y != 24) || (w != cw) || (h != ch-24)) | |
2812 | m_mainWin->SetSize( 0, 24, cw, ch-24 ); | |
2813 | } | |
2814 | else | |
2815 | { | |
2816 | m_mainWin->GetPosition( &x, &y ); | |
2817 | m_mainWin->GetSize( &w, &h ); | |
2818 | if ((x != 0) || (y != 24) || (w != cw) || (h != ch)) | |
2819 | m_mainWin->SetSize( 0, 0, cw, ch ); | |
2820 | } | |
bd8289c1 | 2821 | |
51cc4dad RR |
2822 | m_mainWin->CalculatePositions(); |
2823 | m_mainWin->RealizeChanges(); | |
2824 | m_mainWin->m_dirty = FALSE; | |
2825 | m_mainWin->Refresh(); | |
e1e955e1 | 2826 | } |
53010e52 | 2827 | |
f03fc89f | 2828 | bool wxListCtrl::SetBackgroundColour( const wxColour &colour ) |
bd8289c1 | 2829 | { |
f03fc89f VZ |
2830 | if ( !wxWindow::SetBackgroundColour( colour ) ) |
2831 | return FALSE; | |
58dea4b0 | 2832 | |
51cc4dad RR |
2833 | if (m_mainWin) |
2834 | { | |
2835 | m_mainWin->SetBackgroundColour( colour ); | |
2836 | m_mainWin->m_dirty = TRUE; | |
2837 | } | |
2838 | ||
2839 | if (m_headerWin) | |
2840 | { | |
cfb50f14 | 2841 | // m_headerWin->SetBackgroundColour( colour ); |
51cc4dad | 2842 | } |
f03fc89f VZ |
2843 | |
2844 | return TRUE; | |
e4d06860 RR |
2845 | } |
2846 | ||
f03fc89f | 2847 | bool wxListCtrl::SetForegroundColour( const wxColour &colour ) |
bd8289c1 | 2848 | { |
f03fc89f VZ |
2849 | if ( !wxWindow::SetForegroundColour( colour ) ) |
2850 | return FALSE; | |
58dea4b0 | 2851 | |
51cc4dad RR |
2852 | if (m_mainWin) |
2853 | { | |
2854 | m_mainWin->SetForegroundColour( colour ); | |
2855 | m_mainWin->m_dirty = TRUE; | |
2856 | } | |
2857 | ||
2858 | if (m_headerWin) | |
2859 | { | |
2860 | m_headerWin->SetForegroundColour( colour ); | |
2861 | } | |
f03fc89f VZ |
2862 | |
2863 | return TRUE; | |
e4d06860 | 2864 | } |
bd8289c1 | 2865 | |
f03fc89f | 2866 | bool wxListCtrl::SetFont( const wxFont &font ) |
bd8289c1 | 2867 | { |
f03fc89f VZ |
2868 | if ( !wxWindow::SetFont( font ) ) |
2869 | return FALSE; | |
58dea4b0 | 2870 | |
51cc4dad RR |
2871 | if (m_mainWin) |
2872 | { | |
2873 | m_mainWin->SetFont( font ); | |
2874 | m_mainWin->m_dirty = TRUE; | |
2875 | } | |
2876 | ||
2877 | if (m_headerWin) | |
2878 | { | |
2879 | m_headerWin->SetFont( font ); | |
2880 | } | |
f03fc89f VZ |
2881 | |
2882 | return TRUE; | |
e4d06860 | 2883 | } |
c801d85f | 2884 |