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