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