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