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