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