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