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