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