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