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