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