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