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