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