]> git.saurik.com Git - wxWidgets.git/blob - src/generic/listctrl.cpp
777322d2222c678f1343f292b07a3f3d735667ed
[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 event.SetEventObject( GetParent() );
1773 if (GetParent()->GetEventHandler()->ProcessEvent( event)) return;
1774
1775 if (!m_current) return;
1776 if (m_dirty) return;
1777 if ( !(event.Dragging() || event.ButtonDown() || event.LeftUp() || event.ButtonDClick()) ) return;
1778
1779 int x = event.GetX();
1780 int y = event.GetY();
1781 CalcUnscrolledPosition( x, y, &x, &y );
1782
1783 /* Did we actually hit an item ? */
1784 long hitResult = 0;
1785 wxListLineData *line = (wxListLineData *) NULL;
1786 for (size_t i = 0; i < m_lines.GetCount(); i++)
1787 {
1788 line = &m_lines[i];
1789 hitResult = line->IsHit( x, y );
1790 if (hitResult) break;
1791 line = (wxListLineData *) NULL;
1792 }
1793
1794 if (event.Dragging())
1795 {
1796 if (m_dragCount == 0)
1797 m_dragStart = wxPoint(x,y);
1798
1799 m_dragCount++;
1800
1801 if (m_dragCount != 3) return;
1802
1803 int command = wxEVT_COMMAND_LIST_BEGIN_DRAG;
1804 if (event.RightIsDown()) command = wxEVT_COMMAND_LIST_BEGIN_RDRAG;
1805
1806 wxListEvent le( command, GetParent()->GetId() );
1807 le.SetEventObject( GetParent() );
1808 le.m_pointDrag = m_dragStart;
1809 GetParent()->GetEventHandler()->ProcessEvent( le );
1810
1811 return;
1812 }
1813 else
1814 {
1815 m_dragCount = 0;
1816 }
1817
1818 if (!line) return;
1819
1820 bool forceClick = FALSE;
1821 if (event.ButtonDClick())
1822 {
1823 m_renameTimer->Stop();
1824 m_lastOnSame = FALSE;
1825
1826 if ( line == m_lineBeforeLastClicked )
1827 {
1828 m_usedKeys = FALSE;
1829
1830 SendNotify( line, wxEVT_COMMAND_LIST_ITEM_ACTIVATED );
1831
1832 return;
1833 }
1834 else
1835 {
1836 // the first click was on another item, so don't interpret this as
1837 // a double click, but as a simple click instead
1838 forceClick = TRUE;
1839 }
1840 }
1841
1842 if (event.LeftUp() && m_lastOnSame)
1843 {
1844 m_usedKeys = FALSE;
1845 if ((line == m_current) &&
1846 (hitResult == wxLIST_HITTEST_ONITEMLABEL) &&
1847 (m_mode & wxLC_EDIT_LABELS) )
1848 {
1849 m_renameTimer->Start( 100, TRUE );
1850 }
1851 m_lastOnSame = FALSE;
1852 return;
1853 }
1854
1855 if (event.RightDown())
1856 {
1857 SendNotify( line, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK );
1858 return;
1859 }
1860
1861 if (event.MiddleDown())
1862 {
1863 SendNotify( line, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK );
1864 return;
1865 }
1866
1867 if ( event.LeftDown() || forceClick )
1868 {
1869 m_lineBeforeLastClicked = m_lineLastClicked;
1870 m_lineLastClicked = line;
1871
1872 m_usedKeys = FALSE;
1873 wxListLineData *oldCurrent = m_current;
1874 if (m_mode & wxLC_SINGLE_SEL)
1875 {
1876 m_current = line;
1877 HilightAll( FALSE );
1878 m_current->ReverseHilight();
1879 RefreshLine( m_current );
1880 }
1881 else
1882 {
1883 if (event.ControlDown())
1884 {
1885 m_current = line;
1886 m_current->ReverseHilight();
1887 RefreshLine( m_current );
1888 }
1889 else if (event.ShiftDown())
1890 {
1891 size_t j;
1892
1893 m_current = line;
1894
1895 int numOfCurrent = -1;
1896 for (j = 0; j < m_lines.GetCount(); j++)
1897 {
1898 wxListLineData *test_line = &m_lines[j];
1899 numOfCurrent++;
1900 if (test_line == oldCurrent) break;
1901 }
1902
1903 int numOfLine = -1;
1904
1905 for (j = 0; j < m_lines.GetCount(); j++)
1906 {
1907 wxListLineData *test_line = &m_lines[j];
1908 numOfLine++;
1909 if (test_line == line) break;
1910 }
1911
1912 if (numOfLine < numOfCurrent)
1913 {
1914 int i = numOfLine;
1915 numOfLine = numOfCurrent;
1916 numOfCurrent = i;
1917 }
1918
1919 for (int i = 0; i <= numOfLine-numOfCurrent; i++)
1920 {
1921 wxListLineData *test_line= &m_lines[numOfCurrent + i];
1922 test_line->Hilight(TRUE);
1923 RefreshLine( test_line );
1924 }
1925 }
1926 else
1927 {
1928 m_current = line;
1929 HilightAll( FALSE );
1930 m_current->ReverseHilight();
1931 RefreshLine( m_current );
1932 }
1933 }
1934 if (m_current != oldCurrent)
1935 {
1936 RefreshLine( oldCurrent );
1937 UnfocusLine( oldCurrent );
1938 FocusLine( m_current );
1939 }
1940
1941 // forceClick is only set if the previous click was on another item
1942 m_lastOnSame = !forceClick && (m_current == oldCurrent);
1943
1944 return;
1945 }
1946 }
1947
1948 void wxListMainWindow::MoveToFocus()
1949 {
1950 if (!m_current) return;
1951
1952 int item_x = 0;
1953 int item_y = 0;
1954 int item_w = 0;
1955 int item_h = 0;
1956 m_current->GetExtent( item_x, item_y, item_w, item_h );
1957
1958 int client_w = 0;
1959 int client_h = 0;
1960 GetClientSize( &client_w, &client_h );
1961
1962 int view_x = m_xScroll*GetScrollPos( wxHORIZONTAL );
1963 int view_y = m_yScroll*GetScrollPos( wxVERTICAL );
1964
1965 if (m_mode & wxLC_REPORT)
1966 {
1967 if (item_y-5 < view_y )
1968 Scroll( -1, (item_y-5)/m_yScroll );
1969 if (item_y+item_h+5 > view_y+client_h)
1970 Scroll( -1, (item_y+item_h-client_h+15)/m_yScroll );
1971 }
1972 else
1973 {
1974 if (item_x-view_x < 5)
1975 Scroll( (item_x-5)/m_xScroll, -1 );
1976 if (item_x+item_w-5 > view_x+client_w)
1977 Scroll( (item_x+item_w-client_w+15)/m_xScroll, -1 );
1978 }
1979 }
1980
1981 void wxListMainWindow::OnArrowChar( wxListLineData *newCurrent, bool shiftDown )
1982 {
1983 if ((m_mode & wxLC_SINGLE_SEL) || (m_usedKeys == FALSE)) m_current->Hilight( FALSE );
1984 wxListLineData *oldCurrent = m_current;
1985 m_current = newCurrent;
1986 if (shiftDown || (m_mode & wxLC_SINGLE_SEL)) m_current->Hilight( TRUE );
1987 RefreshLine( m_current );
1988 RefreshLine( oldCurrent );
1989 FocusLine( m_current );
1990 UnfocusLine( oldCurrent );
1991 MoveToFocus();
1992 }
1993
1994 void wxListMainWindow::OnKeyDown( wxKeyEvent &event )
1995 {
1996 wxWindow *parent = GetParent();
1997
1998 /* we propagate the key event up */
1999 wxKeyEvent ke( wxEVT_KEY_DOWN );
2000 ke.m_shiftDown = event.m_shiftDown;
2001 ke.m_controlDown = event.m_controlDown;
2002 ke.m_altDown = event.m_altDown;
2003 ke.m_metaDown = event.m_metaDown;
2004 ke.m_keyCode = event.m_keyCode;
2005 ke.m_x = event.m_x;
2006 ke.m_y = event.m_y;
2007 ke.SetEventObject( parent );
2008 if (parent->GetEventHandler()->ProcessEvent( ke )) return;
2009
2010 event.Skip();
2011 }
2012
2013 void wxListMainWindow::OnChar( wxKeyEvent &event )
2014 {
2015 wxWindow *parent = GetParent();
2016
2017 /* we send a list_key event up */
2018 if ( m_current )
2019 {
2020 wxListEvent le( wxEVT_COMMAND_LIST_KEY_DOWN, GetParent()->GetId() );
2021 le.m_itemIndex = GetIndexOfLine( m_current );
2022 m_current->GetItem( 0, le.m_item );
2023 le.m_code = (int)event.KeyCode();
2024 le.SetEventObject( parent );
2025 parent->GetEventHandler()->ProcessEvent( le );
2026 }
2027
2028 /* we propagate the char event up */
2029 wxKeyEvent ke( wxEVT_CHAR );
2030 ke.m_shiftDown = event.m_shiftDown;
2031 ke.m_controlDown = event.m_controlDown;
2032 ke.m_altDown = event.m_altDown;
2033 ke.m_metaDown = event.m_metaDown;
2034 ke.m_keyCode = event.m_keyCode;
2035 ke.m_x = event.m_x;
2036 ke.m_y = event.m_y;
2037 ke.SetEventObject( parent );
2038 if (parent->GetEventHandler()->ProcessEvent( ke )) return;
2039
2040 if (event.KeyCode() == WXK_TAB)
2041 {
2042 wxNavigationKeyEvent nevent;
2043 nevent.SetWindowChange( event.ControlDown() );
2044 nevent.SetDirection( !event.ShiftDown() );
2045 nevent.SetEventObject( GetParent()->GetParent() );
2046 nevent.SetCurrentFocus( m_parent );
2047 if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent )) return;
2048 }
2049
2050 /* no item -> nothing to do */
2051 if (!m_current)
2052 {
2053 event.Skip();
2054 return;
2055 }
2056
2057 switch (event.KeyCode())
2058 {
2059 case WXK_UP:
2060 {
2061 int index = m_lines.Index(*m_current);
2062 if (index != wxNOT_FOUND && index > 0)
2063 OnArrowChar( &m_lines[index-1], event.ShiftDown() );
2064 break;
2065 }
2066 case WXK_DOWN:
2067 {
2068 int index = m_lines.Index(*m_current);
2069 if (index != wxNOT_FOUND && (size_t)index < m_lines.GetCount()-1)
2070 OnArrowChar( &m_lines[index+1], event.ShiftDown() );
2071 break;
2072 }
2073 case WXK_END:
2074 {
2075 if (!m_lines.IsEmpty())
2076 OnArrowChar( &m_lines.Last(), event.ShiftDown() );
2077 break;
2078 }
2079 case WXK_HOME:
2080 {
2081 if (!m_lines.IsEmpty())
2082 OnArrowChar( &m_lines[0], event.ShiftDown() );
2083 break;
2084 }
2085 case WXK_PRIOR:
2086 {
2087 int steps = 0;
2088 int index = m_lines.Index(*m_current);
2089 if (m_mode & wxLC_REPORT)
2090 {
2091 steps = m_visibleLines-1;
2092 }
2093 else
2094 {
2095 steps = index % m_visibleLines;
2096 }
2097 if (index != wxNOT_FOUND)
2098 {
2099 index -= steps;
2100 if (index < 0) index = 0;
2101 OnArrowChar( &m_lines[index], event.ShiftDown() );
2102 }
2103 break;
2104 }
2105 case WXK_NEXT:
2106 {
2107 int steps = 0;
2108 int index = m_lines.Index(*m_current);
2109 if (m_mode & wxLC_REPORT)
2110 {
2111 steps = m_visibleLines-1;
2112 }
2113 else
2114 {
2115 steps = m_visibleLines-(index % m_visibleLines)-1;
2116 }
2117
2118 if (index != wxNOT_FOUND)
2119 {
2120 index += steps;
2121 if ((size_t)index >= m_lines.GetCount())
2122 index = m_lines.GetCount()-1;
2123 OnArrowChar( &m_lines[index], event.ShiftDown() );
2124 }
2125 break;
2126 }
2127 case WXK_LEFT:
2128 {
2129 if (!(m_mode & wxLC_REPORT))
2130 {
2131 int index = m_lines.Index(*m_current);
2132 if (index != wxNOT_FOUND)
2133 {
2134 index -= m_visibleLines;
2135 if (index < 0) index = 0;
2136 OnArrowChar( &m_lines[index], event.ShiftDown() );
2137 }
2138 }
2139 break;
2140 }
2141 case WXK_RIGHT:
2142 {
2143 if (!(m_mode & wxLC_REPORT))
2144 {
2145 int index = m_lines.Index(*m_current);
2146 if (index != wxNOT_FOUND)
2147 {
2148 index += m_visibleLines;
2149 if ((size_t)index >= m_lines.GetCount())
2150 index = m_lines.GetCount()-1;
2151 OnArrowChar( &m_lines[index], event.ShiftDown() );
2152 }
2153 }
2154 break;
2155 }
2156 case WXK_SPACE:
2157 {
2158 if (m_mode & wxLC_SINGLE_SEL)
2159 {
2160 wxListEvent le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED, GetParent()->GetId() );
2161 le.SetEventObject( GetParent() );
2162 le.m_itemIndex = GetIndexOfLine( m_current );
2163 m_current->GetItem( 0, le.m_item );
2164 GetParent()->GetEventHandler()->ProcessEvent( le );
2165 }
2166 else
2167 {
2168 m_current->ReverseHilight();
2169 RefreshLine( m_current );
2170 }
2171 break;
2172 }
2173 case WXK_INSERT:
2174 {
2175 if (!(m_mode & wxLC_SINGLE_SEL))
2176 {
2177 wxListLineData *oldCurrent = m_current;
2178 m_current->ReverseHilight();
2179 int index = m_lines.Index( *m_current ) + 1;
2180 if ( (size_t)index < m_lines.GetCount() )
2181 m_current = &m_lines[index];
2182 RefreshLine( oldCurrent );
2183 RefreshLine( m_current );
2184 UnfocusLine( oldCurrent );
2185 FocusLine( m_current );
2186 MoveToFocus();
2187 }
2188 break;
2189 }
2190 case WXK_RETURN:
2191 case WXK_EXECUTE:
2192 {
2193 wxListEvent le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED, GetParent()->GetId() );
2194 le.SetEventObject( GetParent() );
2195 le.m_itemIndex = GetIndexOfLine( m_current );
2196 m_current->GetItem( 0, le.m_item );
2197 GetParent()->GetEventHandler()->ProcessEvent( le );
2198 break;
2199 }
2200 default:
2201 {
2202 event.Skip();
2203 return;
2204 }
2205 }
2206 m_usedKeys = TRUE;
2207 }
2208
2209 #ifdef __WXGTK__
2210 extern wxWindow *g_focusWindow;
2211 #endif
2212
2213 void wxListMainWindow::OnSetFocus( wxFocusEvent &WXUNUSED(event) )
2214 {
2215 m_hasFocus = TRUE;
2216 RefreshLine( m_current );
2217
2218 if (!GetParent()) return;
2219
2220 #ifdef __WXGTK__
2221 g_focusWindow = GetParent();
2222 #endif
2223
2224 wxFocusEvent event( wxEVT_SET_FOCUS, GetParent()->GetId() );
2225 event.SetEventObject( GetParent() );
2226 GetParent()->GetEventHandler()->ProcessEvent( event );
2227 }
2228
2229 void wxListMainWindow::OnKillFocus( wxFocusEvent &WXUNUSED(event) )
2230 {
2231 m_hasFocus = FALSE;
2232 RefreshLine( m_current );
2233 }
2234
2235 void wxListMainWindow::OnSize( wxSizeEvent &WXUNUSED(event) )
2236 {
2237 /*
2238 We don't even allow the wxScrolledWindow::AdjustScrollbars() call
2239
2240 */
2241 m_dirty = TRUE;
2242 }
2243
2244 void wxListMainWindow::DrawImage( int index, wxDC *dc, int x, int y )
2245 {
2246 if ((m_mode & wxLC_ICON) && (m_normal_image_list))
2247 {
2248 m_normal_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT );
2249 return;
2250 }
2251 if ((m_mode & wxLC_SMALL_ICON) && (m_small_image_list))
2252 {
2253 m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT );
2254 }
2255 if ((m_mode & wxLC_LIST) && (m_small_image_list))
2256 {
2257 m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT );
2258 }
2259 if ((m_mode & wxLC_REPORT) && (m_small_image_list))
2260 {
2261 m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT );
2262 return;
2263 }
2264 }
2265
2266 void wxListMainWindow::GetImageSize( int index, int &width, int &height )
2267 {
2268 if ((m_mode & wxLC_ICON) && (m_normal_image_list))
2269 {
2270 m_normal_image_list->GetSize( index, width, height );
2271 return;
2272 }
2273 if ((m_mode & wxLC_SMALL_ICON) && (m_small_image_list))
2274 {
2275 m_small_image_list->GetSize( index, width, height );
2276 return;
2277 }
2278 if ((m_mode & wxLC_LIST) && (m_small_image_list))
2279 {
2280 m_small_image_list->GetSize( index, width, height );
2281 return;
2282 }
2283 if ((m_mode & wxLC_REPORT) && (m_small_image_list))
2284 {
2285 m_small_image_list->GetSize( index, width, height );
2286 return;
2287 }
2288 width = 0;
2289 height = 0;
2290 }
2291
2292 int wxListMainWindow::GetTextLength( wxString &s )
2293 {
2294 wxClientDC dc( this );
2295 wxCoord lw = 0;
2296 wxCoord lh = 0;
2297 dc.GetTextExtent( s, &lw, &lh );
2298 return lw + 6;
2299 }
2300
2301 int wxListMainWindow::GetIndexOfLine( const wxListLineData *line )
2302 {
2303 int i = m_lines.Index(*line);
2304 if (i == wxNOT_FOUND) return -1;
2305 else return i;
2306 }
2307
2308 void wxListMainWindow::SetImageList( wxImageList *imageList, int which )
2309 {
2310 m_dirty = TRUE;
2311
2312 // calc the spacing from the icon size
2313 int width = 0,
2314 height = 0;
2315 if ((imageList) && (imageList->GetImageCount()) )
2316 {
2317 imageList->GetSize(0, width, height);
2318 }
2319
2320 if (which == wxIMAGE_LIST_NORMAL)
2321 {
2322 m_normal_image_list = imageList;
2323 m_normal_spacing = width + 8;
2324 }
2325
2326 if (which == wxIMAGE_LIST_SMALL)
2327 {
2328 m_small_image_list = imageList;
2329 m_small_spacing = width + 14;
2330 }
2331 }
2332
2333 void wxListMainWindow::SetItemSpacing( int spacing, bool isSmall )
2334 {
2335 m_dirty = TRUE;
2336 if (isSmall)
2337 {
2338 m_small_spacing = spacing;
2339 }
2340 else
2341 {
2342 m_normal_spacing = spacing;
2343 }
2344 }
2345
2346 int wxListMainWindow::GetItemSpacing( bool isSmall )
2347 {
2348 return isSmall ? m_small_spacing : m_normal_spacing;
2349 }
2350
2351 void wxListMainWindow::SetColumn( int col, wxListItem &item )
2352 {
2353 m_dirty = TRUE;
2354 wxNode *node = m_columns.Nth( col );
2355 if (node)
2356 {
2357 if (item.m_width == wxLIST_AUTOSIZE_USEHEADER) item.m_width = GetTextLength( item.m_text )+7;
2358 wxListHeaderData *column = (wxListHeaderData*)node->Data();
2359 column->SetItem( item );
2360 }
2361
2362 wxListHeaderWindow *headerWin = ((wxListCtrl*) GetParent())->m_headerWin;
2363 if ( headerWin )
2364 headerWin->m_dirty = TRUE;
2365 }
2366
2367 void wxListMainWindow::SetColumnWidth( int col, int width )
2368 {
2369 wxCHECK_RET( m_mode & wxLC_REPORT,
2370 _T("SetColumnWidth() can only be called in report mode.") );
2371
2372 m_dirty = TRUE;
2373
2374 wxNode *node = (wxNode*) NULL;
2375
2376 if (width == wxLIST_AUTOSIZE_USEHEADER)
2377 {
2378 // TODO do use the header
2379 width = 80;
2380 }
2381 else if (width == wxLIST_AUTOSIZE)
2382 {
2383 wxClientDC dc(this);
2384 dc.SetFont( GetFont() );
2385 int max = 10;
2386
2387 for (size_t i = 0; i < m_lines.GetCount(); i++)
2388 {
2389 wxListLineData *line = &m_lines[i];
2390 wxNode *n = line->m_items.Nth( col );
2391 if (n)
2392 {
2393 wxListItemData *item = (wxListItemData*)n->Data();
2394 int current = 0, ix = 0, iy = 0;
2395 wxCoord lx = 0, ly = 0;
2396 if (item->HasImage())
2397 {
2398 GetImageSize( item->GetImage(), ix, iy );
2399 current = ix + 5;
2400 }
2401 if (item->HasText())
2402 {
2403 wxString str;
2404 item->GetText( str );
2405 dc.GetTextExtent( str, &lx, &ly );
2406 current += lx;
2407 }
2408 if (current > max) max = current;
2409 }
2410 }
2411 width = max+10;
2412 }
2413
2414 node = m_columns.Nth( col );
2415 if (node)
2416 {
2417 wxListHeaderData *column = (wxListHeaderData*)node->Data();
2418 column->SetWidth( width );
2419 }
2420
2421 for (size_t i = 0; i < m_lines.GetCount(); i++)
2422 {
2423 wxListLineData *line = &m_lines[i];
2424 wxNode *n = line->m_items.Nth( col );
2425 if (n)
2426 {
2427 wxListItemData *item = (wxListItemData*)n->Data();
2428 item->SetSize( width, -1 );
2429 }
2430 }
2431
2432 wxListHeaderWindow *headerWin = ((wxListCtrl*) GetParent())->m_headerWin;
2433 if ( headerWin )
2434 headerWin->m_dirty = TRUE;
2435 }
2436
2437 void wxListMainWindow::GetColumn( int col, wxListItem &item )
2438 {
2439 wxNode *node = m_columns.Nth( col );
2440 if (node)
2441 {
2442 wxListHeaderData *column = (wxListHeaderData*)node->Data();
2443 column->GetItem( item );
2444 }
2445 else
2446 {
2447 item.m_format = 0;
2448 item.m_width = 0;
2449 item.m_text = "";
2450 item.m_image = 0;
2451 item.m_data = 0;
2452 }
2453 }
2454
2455 int wxListMainWindow::GetColumnWidth( int col )
2456 {
2457 wxNode *node = m_columns.Nth( col );
2458 if (node)
2459 {
2460 wxListHeaderData *column = (wxListHeaderData*)node->Data();
2461 return column->GetWidth();
2462 }
2463 else
2464 {
2465 return 0;
2466 }
2467 }
2468
2469 int wxListMainWindow::GetColumnCount()
2470 {
2471 return m_columns.Number();
2472 }
2473
2474 int wxListMainWindow::GetCountPerPage()
2475 {
2476 return m_visibleLines;
2477 }
2478
2479 void wxListMainWindow::SetItem( wxListItem &item )
2480 {
2481 m_dirty = TRUE;
2482 if (item.m_itemId >= 0 && (size_t)item.m_itemId < m_lines.GetCount())
2483 {
2484 wxListLineData *line = &m_lines[(size_t)item.m_itemId];
2485 if (m_mode & wxLC_REPORT) item.m_width = GetColumnWidth( item.m_col )-3;
2486 line->SetItem( item.m_col, item );
2487 }
2488 }
2489
2490 void wxListMainWindow::SetItemState( long item, long state, long stateMask )
2491 {
2492 // m_dirty = TRUE; no recalcs needed
2493
2494 wxListLineData *oldCurrent = m_current;
2495
2496 if (stateMask & wxLIST_STATE_FOCUSED)
2497 {
2498 if (item >= 0 && (size_t)item < m_lines.GetCount())
2499 {
2500 wxListLineData *line = &m_lines[(size_t)item];
2501 UnfocusLine( m_current );
2502 m_current = line;
2503 FocusLine( m_current );
2504 if ((m_mode & wxLC_SINGLE_SEL) && oldCurrent) oldCurrent->Hilight( FALSE );
2505 RefreshLine( m_current );
2506 if (oldCurrent) RefreshLine( oldCurrent );
2507 }
2508 }
2509
2510 if (stateMask & wxLIST_STATE_SELECTED)
2511 {
2512 bool on = (state & wxLIST_STATE_SELECTED) != 0;
2513 if (!on && (m_mode & wxLC_SINGLE_SEL)) return;
2514
2515 if (item >= 0 && (size_t)item < m_lines.GetCount())
2516 {
2517 wxListLineData *line = &m_lines[(size_t)item];
2518 if (m_mode & wxLC_SINGLE_SEL)
2519 {
2520 UnfocusLine( m_current );
2521 m_current = line;
2522 FocusLine( m_current );
2523 if (oldCurrent) oldCurrent->Hilight( FALSE );
2524 RefreshLine( m_current );
2525 if (oldCurrent) RefreshLine( oldCurrent );
2526 }
2527 bool on = (state & wxLIST_STATE_SELECTED) != 0;
2528 if (on != line->IsHilighted())
2529 {
2530 line->Hilight( on );
2531 RefreshLine( line );
2532 }
2533 }
2534 }
2535 }
2536
2537 int wxListMainWindow::GetItemState( long item, long stateMask )
2538 {
2539 int ret = wxLIST_STATE_DONTCARE;
2540 if (stateMask & wxLIST_STATE_FOCUSED)
2541 {
2542 if (item >= 0 && (size_t)item < m_lines.GetCount())
2543 {
2544 wxListLineData *line = &m_lines[(size_t)item];
2545 if (line == m_current) ret |= wxLIST_STATE_FOCUSED;
2546 }
2547 }
2548 if (stateMask & wxLIST_STATE_SELECTED)
2549 {
2550 if (item >= 0 && (size_t)item < m_lines.GetCount())
2551 {
2552 wxListLineData *line = &m_lines[(size_t)item];
2553 if (line->IsHilighted()) ret |= wxLIST_STATE_FOCUSED;
2554 }
2555 }
2556 return ret;
2557 }
2558
2559 void wxListMainWindow::GetItem( wxListItem &item )
2560 {
2561 if (item.m_itemId >= 0 && (size_t)item.m_itemId < m_lines.GetCount())
2562 {
2563 wxListLineData *line = &m_lines[(size_t)item.m_itemId];
2564 line->GetItem( item.m_col, item );
2565 }
2566 else
2567 {
2568 item.m_mask = 0;
2569 item.m_text = "";
2570 item.m_image = 0;
2571 item.m_data = 0;
2572 }
2573 }
2574
2575 int wxListMainWindow::GetItemCount()
2576 {
2577 return m_lines.GetCount();
2578 }
2579
2580 void wxListMainWindow::GetItemRect( long index, wxRect &rect )
2581 {
2582 if (index >= 0 && (size_t)index < m_lines.GetCount())
2583 {
2584 m_lines[(size_t)index].GetRect( rect );
2585 }
2586 else
2587 {
2588 rect.x = 0;
2589 rect.y = 0;
2590 rect.width = 0;
2591 rect.height = 0;
2592 }
2593 }
2594
2595 bool wxListMainWindow::GetItemPosition(long item, wxPoint& pos)
2596 {
2597 if (item >= 0 && (size_t)item < m_lines.GetCount())
2598 {
2599 wxRect rect;
2600 m_lines[(size_t)item].GetRect( rect );
2601 pos.x = rect.x;
2602 pos.y = rect.y;
2603 }
2604 else
2605 {
2606 pos.x = 0;
2607 pos.y = 0;
2608 }
2609 return TRUE;
2610 }
2611
2612 int wxListMainWindow::GetSelectedItemCount()
2613 {
2614 int ret = 0;
2615 for (size_t i = 0; i < m_lines.GetCount(); i++)
2616 {
2617 if (m_lines[i].IsHilighted()) ret++;
2618 }
2619 return ret;
2620 }
2621
2622 void wxListMainWindow::SetMode( long mode )
2623 {
2624 m_dirty = TRUE;
2625 m_mode = mode;
2626
2627 DeleteEverything();
2628
2629 if (m_mode & wxLC_REPORT)
2630 {
2631 #if wxUSE_GENERIC_LIST_EXTENSIONS
2632 m_xScroll = 15;
2633 #else
2634 m_xScroll = 0;
2635 #endif
2636 m_yScroll = 15;
2637 }
2638 else
2639 {
2640 m_xScroll = 15;
2641 m_yScroll = 0;
2642 }
2643 }
2644
2645 long wxListMainWindow::GetMode() const
2646 {
2647 return m_mode;
2648 }
2649
2650 void wxListMainWindow::CalculatePositions()
2651 {
2652 if (m_lines.IsEmpty()) return;
2653
2654 wxClientDC dc( this );
2655 dc.SetFont( GetFont() );
2656
2657 int iconSpacing = 0;
2658 if (m_mode & wxLC_ICON) iconSpacing = m_normal_spacing;
2659 if (m_mode & wxLC_SMALL_ICON) iconSpacing = m_small_spacing;
2660
2661 // we take the first line (which also can be an icon or
2662 // an a text item in wxLC_ICON and wxLC_LIST modes) to
2663 // measure the size of the line
2664
2665 int lineWidth = 0;
2666 int lineHeight = 0;
2667 int lineSpacing = 0;
2668
2669 wxListLineData *line = &m_lines[0];
2670 line->CalculateSize( &dc, iconSpacing );
2671 int dummy = 0;
2672 line->GetSize( dummy, lineSpacing );
2673 lineSpacing += 1;
2674
2675 int clientWidth = 0;
2676 int clientHeight = 0;
2677
2678 if (m_mode & wxLC_REPORT)
2679 {
2680 int x = 4;
2681 int y = 1;
2682 int entireHeight = m_lines.GetCount() * lineSpacing + 2;
2683 int scroll_pos = GetScrollPos( wxVERTICAL );
2684 #if wxUSE_GENERIC_LIST_EXTENSIONS
2685 int x_scroll_pos = GetScrollPos( wxHORIZONTAL );
2686 #else
2687 SetScrollbars( m_xScroll, m_yScroll, 0, (entireHeight+15) / m_yScroll, 0, scroll_pos, TRUE );
2688 #endif
2689 GetClientSize( &clientWidth, &clientHeight );
2690
2691 int entireWidth = 0 ;
2692 for (size_t j = 0; j < m_lines.GetCount(); j++)
2693 {
2694 wxListLineData *line = &m_lines[j];
2695 line->CalculateSize( &dc, iconSpacing );
2696 line->SetPosition( &dc, x, y, clientWidth );
2697 int col_x = 2;
2698 for (int i = 0; i < GetColumnCount(); i++)
2699 {
2700 line->SetColumnPosition( i, col_x );
2701 col_x += GetColumnWidth( i );
2702 }
2703 entireWidth = wxMax( entireWidth , col_x ) ;
2704 #if wxUSE_GENERIC_LIST_EXTENSIONS
2705 line->SetPosition( &dc, x, y, col_x );
2706 #endif
2707 y += lineSpacing; // one pixel blank line between items
2708 }
2709 m_visibleLines = clientHeight / lineSpacing;
2710 #if wxUSE_GENERIC_LIST_EXTENSIONS
2711 SetScrollbars( m_xScroll, m_yScroll, entireWidth / m_xScroll , (entireHeight+15) / m_yScroll, x_scroll_pos , scroll_pos, TRUE );
2712 #endif
2713 }
2714 else
2715 {
2716 // at first we try without any scrollbar. if the items don't
2717 // fit into the window, we recalculate after subtracting an
2718 // approximated 15 pt for the horizontal scrollbar
2719
2720 GetSize( &clientWidth, &clientHeight );
2721 clientHeight -= 4; // sunken frame
2722
2723 int entireWidth = 0;
2724
2725 for (int tries = 0; tries < 2; tries++)
2726 {
2727 entireWidth = 0;
2728 int x = 2;
2729 int y = 2;
2730 int maxWidth = 0;
2731 m_visibleLines = 0;
2732 int m_currentVisibleLines = 0;
2733 for (size_t i = 0; i < m_lines.GetCount(); i++)
2734 {
2735 m_currentVisibleLines++;
2736 wxListLineData *line = &m_lines[i];
2737 line->CalculateSize( &dc, iconSpacing );
2738 line->SetPosition( &dc, x, y, clientWidth );
2739 line->GetSize( lineWidth, lineHeight );
2740 if (lineWidth > maxWidth) maxWidth = lineWidth;
2741 y += lineSpacing;
2742 if (m_currentVisibleLines > m_visibleLines)
2743 m_visibleLines = m_currentVisibleLines;
2744 if (y+lineSpacing-6 >= clientHeight) // -6 for earlier "line breaking"
2745 {
2746 m_currentVisibleLines = 0;
2747 y = 2;
2748 x += maxWidth+6;
2749 entireWidth += maxWidth+6;
2750 maxWidth = 0;
2751 }
2752 if (i == m_lines.GetCount()-1) entireWidth += maxWidth;
2753 if ((tries == 0) && (entireWidth > clientWidth))
2754 {
2755 clientHeight -= 15; // scrollbar height
2756 m_visibleLines = 0;
2757 m_currentVisibleLines = 0;
2758 break;
2759 }
2760 if (i == m_lines.GetCount()-1) tries = 1; // everything fits, no second try required
2761 }
2762 }
2763
2764 int scroll_pos = GetScrollPos( wxHORIZONTAL );
2765 SetScrollbars( m_xScroll, m_yScroll, (entireWidth+15) / m_xScroll, 0, scroll_pos, 0, TRUE );
2766 }
2767 }
2768
2769 void wxListMainWindow::RealizeChanges()
2770 {
2771 if (!m_current)
2772 {
2773 if (!m_lines.IsEmpty())
2774 m_current = &m_lines[0];
2775 }
2776 if (m_current)
2777 {
2778 FocusLine( m_current );
2779 // TODO: MSW doesn't automatically hilight the
2780 // first item.
2781 // if (m_mode & wxLC_SINGLE_SEL) m_current->Hilight( TRUE );
2782 }
2783 }
2784
2785 long wxListMainWindow::GetNextItem( long item,
2786 int WXUNUSED(geometry),
2787 int state )
2788 {
2789 long ret = item,
2790 max = GetItemCount();
2791 wxCHECK_MSG( (ret == -1) || (ret < max), -1,
2792 _T("invalid listctrl index in GetNextItem()") );
2793
2794 // notice that we start with the next item (or the first one if item == -1)
2795 // and this is intentional to allow writing a simple loop to iterate over
2796 // all selected items
2797 ret++;
2798 if ( ret == max )
2799 {
2800 // this is not an error because the index was ok initially, just no
2801 // such item
2802 return -1;
2803 }
2804
2805 for (size_t i = (size_t)ret; i < m_lines.GetCount(); i++)
2806 {
2807 wxListLineData *line = &m_lines[i];
2808 if ((state & wxLIST_STATE_FOCUSED) && (line == m_current))
2809 return ret;
2810 if ((state & wxLIST_STATE_SELECTED) && (line->IsHilighted()))
2811 return ret;
2812 if (!state)
2813 return ret;
2814 ret++;
2815 }
2816
2817 return -1;
2818 }
2819
2820 void wxListMainWindow::DeleteItem( long index )
2821 {
2822 m_dirty = TRUE;
2823 if (index >= 0 && (size_t)index < m_lines.GetCount())
2824 {
2825 wxListLineData *line = &m_lines[(size_t)index];
2826 if (m_current == line) m_current = (wxListLineData *) NULL;
2827 DeleteLine( line );
2828 m_lines.RemoveAt( (size_t)index );
2829 }
2830 }
2831
2832 void wxListMainWindow::DeleteColumn( int col )
2833 {
2834 wxCHECK_RET( col < (int)m_columns.GetCount(),
2835 wxT("attempting to delete inexistent column in wxListView") );
2836
2837 m_dirty = TRUE;
2838 wxNode *node = m_columns.Nth( col );
2839 if (node) m_columns.DeleteNode( node );
2840 }
2841
2842 void wxListMainWindow::DeleteAllItems()
2843 {
2844 m_dirty = TRUE;
2845 m_current = (wxListLineData *) NULL;
2846
2847 // to make the deletion of all items faster, we don't send the
2848 // notifications in this case: this is compatible with wxMSW and
2849 // documented in DeleteAllItems() description
2850
2851 wxListEvent event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS, GetParent()->GetId() );
2852 event.SetEventObject( GetParent() );
2853 GetParent()->GetEventHandler()->ProcessEvent( event );
2854
2855 m_lines.Clear();
2856 }
2857
2858 void wxListMainWindow::DeleteEverything()
2859 {
2860 DeleteAllItems();
2861
2862 m_columns.Clear();
2863 }
2864
2865 void wxListMainWindow::EnsureVisible( long index )
2866 {
2867 // We have to call this here because the label in
2868 // question might just have been added and no screen
2869 // update taken place.
2870 if (m_dirty) wxYield();
2871
2872 wxListLineData *oldCurrent = m_current;
2873 m_current = (wxListLineData *) NULL;
2874 if (index >= 0 && (size_t)index < m_lines.GetCount())
2875 m_current = &m_lines[(size_t)index];
2876 if (m_current) MoveToFocus();
2877 m_current = oldCurrent;
2878 }
2879
2880 long wxListMainWindow::FindItem(long start, const wxString& str, bool WXUNUSED(partial) )
2881 {
2882 long pos = start;
2883 wxString tmp = str;
2884 if (pos < 0) pos = 0;
2885 for (size_t i = (size_t)pos; i < m_lines.GetCount(); i++)
2886 {
2887 wxListLineData *line = &m_lines[i];
2888 wxString s = "";
2889 line->GetText( 0, s );
2890 if (s == tmp) return pos;
2891 pos++;
2892 }
2893 return -1;
2894 }
2895
2896 long wxListMainWindow::FindItem(long start, long data)
2897 {
2898 long pos = start;
2899 if (pos < 0) pos = 0;
2900 for (size_t i = (size_t)pos; i < m_lines.GetCount(); i++)
2901 {
2902 wxListLineData *line = &m_lines[i];
2903 wxListItem item;
2904 line->GetItem( 0, item );
2905 if (item.m_data == data) return pos;
2906 pos++;
2907 }
2908 return -1;
2909 }
2910
2911 long wxListMainWindow::HitTest( int x, int y, int &flags )
2912 {
2913 CalcUnscrolledPosition( x, y, &x, &y );
2914
2915 int count = 0;
2916 for (size_t i = 0; i < m_lines.GetCount(); i++)
2917 {
2918 wxListLineData *line = &m_lines[i];
2919 long ret = line->IsHit( x, y );
2920 if (ret & flags)
2921 {
2922 flags = (int)ret;
2923 return count;
2924 }
2925 count++;
2926 }
2927 return -1;
2928 }
2929
2930 void wxListMainWindow::InsertItem( wxListItem &item )
2931 {
2932 m_dirty = TRUE;
2933 int mode = 0;
2934 if (m_mode & wxLC_REPORT) mode = wxLC_REPORT;
2935 else if (m_mode & wxLC_LIST) mode = wxLC_LIST;
2936 else if (m_mode & wxLC_ICON) mode = wxLC_ICON;
2937 else if (m_mode & wxLC_SMALL_ICON) mode = wxLC_ICON; // no typo
2938
2939 wxListLineData *line = new wxListLineData( this, mode, m_hilightBrush );
2940
2941 if (m_mode & wxLC_REPORT)
2942 {
2943 line->InitItems( GetColumnCount() );
2944 item.m_width = GetColumnWidth( 0 )-3;
2945 }
2946 else
2947 {
2948 line->InitItems( 1 );
2949 }
2950
2951 line->SetItem( 0, item );
2952 if ((item.m_itemId >= 0) && ((size_t)item.m_itemId < m_lines.GetCount()))
2953 {
2954 m_lines.Insert( line, (size_t)item.m_itemId );
2955 }
2956 else
2957 {
2958 m_lines.Add( line );
2959 item.m_itemId = m_lines.GetCount();
2960 }
2961 }
2962
2963 void wxListMainWindow::InsertColumn( long col, wxListItem &item )
2964 {
2965 m_dirty = TRUE;
2966 if (m_mode & wxLC_REPORT)
2967 {
2968 if (item.m_width == wxLIST_AUTOSIZE_USEHEADER) item.m_width = GetTextLength( item.m_text );
2969 wxListHeaderData *column = new wxListHeaderData( item );
2970 if ((col >= 0) && (col < (int)m_columns.GetCount()))
2971 {
2972 wxNode *node = m_columns.Nth( (size_t)col );
2973 if (node)
2974 m_columns.Insert( node, column );
2975 }
2976 else
2977 {
2978 m_columns.Append( column );
2979 }
2980 }
2981 }
2982
2983 wxListCtrlCompare list_ctrl_compare_func_2;
2984 long list_ctrl_compare_data;
2985
2986 int LINKAGEMODE list_ctrl_compare_func_1( wxListLineData **arg1, wxListLineData **arg2 )
2987 {
2988 wxListLineData *line1 = *arg1;
2989 wxListLineData *line2 = *arg2;
2990 wxListItem item;
2991 line1->GetItem( 0, item );
2992 long data1 = item.m_data;
2993 line2->GetItem( 0, item );
2994 long data2 = item.m_data;
2995 return list_ctrl_compare_func_2( data1, data2, list_ctrl_compare_data );
2996 }
2997
2998 void wxListMainWindow::SortItems( wxListCtrlCompare fn, long data )
2999 {
3000 list_ctrl_compare_func_2 = fn;
3001 list_ctrl_compare_data = data;
3002 m_lines.Sort( list_ctrl_compare_func_1 );
3003 m_dirty = TRUE;
3004 }
3005
3006 void wxListMainWindow::OnScroll(wxScrollWinEvent& event)
3007 {
3008 wxScrolledWindow::OnScroll( event ) ;
3009 #if wxUSE_GENERIC_LIST_EXTENSIONS
3010
3011 if (event.GetOrientation() == wxHORIZONTAL && ( m_mode & wxLC_REPORT ))
3012 {
3013 wxListCtrl* lc = wxDynamicCast( GetParent() , wxListCtrl ) ;
3014 if ( lc )
3015 {
3016 lc->m_headerWin->Refresh() ;
3017 #ifdef __WXMAC__
3018 lc->m_headerWin->MacUpdateImmediately() ;
3019 #endif
3020 }
3021 }
3022 #endif
3023 }
3024
3025 // -------------------------------------------------------------------------------------
3026 // wxListItem
3027 // -------------------------------------------------------------------------------------
3028
3029 IMPLEMENT_DYNAMIC_CLASS(wxListItem, wxObject)
3030
3031 wxListItem::wxListItem()
3032 {
3033 m_mask = 0;
3034 m_itemId = 0;
3035 m_col = 0;
3036 m_state = 0;
3037 m_stateMask = 0;
3038 m_image = 0;
3039 m_data = 0;
3040 m_format = wxLIST_FORMAT_CENTRE;
3041 m_width = 0;
3042
3043 m_attr = NULL;
3044 }
3045
3046 void wxListItem::Clear()
3047 {
3048 m_mask = 0;
3049 m_itemId = 0;
3050 m_col = 0;
3051 m_state = 0;
3052 m_stateMask = 0;
3053 m_image = 0;
3054 m_data = 0;
3055 m_format = wxLIST_FORMAT_CENTRE;
3056 m_width = 0;
3057 m_text = wxEmptyString;
3058
3059 if (m_attr) delete m_attr;
3060 m_attr = NULL;
3061 }
3062
3063 void wxListItem::ClearAttributes()
3064 {
3065 if (m_attr) delete m_attr;
3066 m_attr = NULL;
3067 }
3068
3069 // -------------------------------------------------------------------------------------
3070 // wxListEvent
3071 // -------------------------------------------------------------------------------------
3072
3073 IMPLEMENT_DYNAMIC_CLASS(wxListEvent, wxNotifyEvent)
3074
3075 wxListEvent::wxListEvent( wxEventType commandType, int id ):
3076 wxNotifyEvent( commandType, id )
3077 {
3078 m_code = 0;
3079 m_itemIndex = 0;
3080 m_oldItemIndex = 0;
3081 m_col = 0;
3082 m_cancelled = FALSE;
3083 m_pointDrag.x = 0;
3084 m_pointDrag.y = 0;
3085 }
3086
3087 void wxListEvent::CopyObject(wxObject& object_dest) const
3088 {
3089 wxListEvent *obj = (wxListEvent *)&object_dest;
3090
3091 wxNotifyEvent::CopyObject(object_dest);
3092
3093 obj->m_code = m_code;
3094 obj->m_itemIndex = m_itemIndex;
3095 obj->m_oldItemIndex = m_oldItemIndex;
3096 obj->m_col = m_col;
3097 obj->m_cancelled = m_cancelled;
3098 obj->m_pointDrag = m_pointDrag;
3099 obj->m_item.m_mask = m_item.m_mask;
3100 obj->m_item.m_itemId = m_item.m_itemId;
3101 obj->m_item.m_col = m_item.m_col;
3102 obj->m_item.m_state = m_item.m_state;
3103 obj->m_item.m_stateMask = m_item.m_stateMask;
3104 obj->m_item.m_text = m_item.m_text;
3105 obj->m_item.m_image = m_item.m_image;
3106 obj->m_item.m_data = m_item.m_data;
3107 obj->m_item.m_format = m_item.m_format;
3108 obj->m_item.m_width = m_item.m_width;
3109
3110 if ( m_item.HasAttributes() )
3111 {
3112 obj->m_item.SetTextColour(m_item.GetTextColour());
3113 }
3114 }
3115
3116 // -------------------------------------------------------------------------------------
3117 // wxListCtrl
3118 // -------------------------------------------------------------------------------------
3119
3120 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl, wxControl)
3121
3122 BEGIN_EVENT_TABLE(wxListCtrl,wxControl)
3123 EVT_SIZE (wxListCtrl::OnSize)
3124 EVT_IDLE (wxListCtrl::OnIdle)
3125 END_EVENT_TABLE()
3126
3127 wxListCtrl::wxListCtrl()
3128 {
3129 m_imageListNormal = (wxImageList *) NULL;
3130 m_imageListSmall = (wxImageList *) NULL;
3131 m_imageListState = (wxImageList *) NULL;
3132 m_mainWin = (wxListMainWindow*) NULL;
3133 m_headerWin = (wxListHeaderWindow*) NULL;
3134 }
3135
3136 wxListCtrl::~wxListCtrl()
3137 {
3138 }
3139
3140 bool wxListCtrl::Create(wxWindow *parent,
3141 wxWindowID id,
3142 const wxPoint &pos,
3143 const wxSize &size,
3144 long style,
3145 const wxValidator &validator,
3146 const wxString &name)
3147 {
3148 m_imageListNormal = (wxImageList *) NULL;
3149 m_imageListSmall = (wxImageList *) NULL;
3150 m_imageListState = (wxImageList *) NULL;
3151 m_mainWin = (wxListMainWindow*) NULL;
3152 m_headerWin = (wxListHeaderWindow*) NULL;
3153
3154 if ( !(style & (wxLC_REPORT | wxLC_LIST | wxLC_ICON)) )
3155 {
3156 style = style | wxLC_LIST;
3157 }
3158
3159 bool ret = wxControl::Create( parent, id, pos, size, style, validator, name );
3160
3161
3162 if (style & wxSUNKEN_BORDER)
3163 style -= wxSUNKEN_BORDER;
3164
3165 m_mainWin = new wxListMainWindow( this, -1, wxPoint(0,0), size, style );
3166
3167 if (HasFlag(wxLC_REPORT))
3168 {
3169 m_headerWin = new wxListHeaderWindow( this, -1, m_mainWin, wxPoint(0,0), wxSize(size.x,23), wxTAB_TRAVERSAL );
3170 if (HasFlag(wxLC_NO_HEADER))
3171 m_headerWin->Show( FALSE );
3172 }
3173 else
3174 {
3175 m_headerWin = (wxListHeaderWindow *) NULL;
3176 }
3177
3178 return ret;
3179 }
3180
3181 void wxListCtrl::OnSize( wxSizeEvent &WXUNUSED(event) )
3182 {
3183 /* handled in OnIdle */
3184
3185 if (m_mainWin) m_mainWin->m_dirty = TRUE;
3186 }
3187
3188 void wxListCtrl::SetSingleStyle( long style, bool add )
3189 {
3190 long flag = GetWindowStyle();
3191
3192 if (add)
3193 {
3194 if (style & wxLC_MASK_TYPE) flag = flag & ~wxLC_MASK_TYPE;
3195 if (style & wxLC_MASK_ALIGN) flag = flag & ~wxLC_MASK_ALIGN;
3196 if (style & wxLC_MASK_SORT) flag = flag & ~wxLC_MASK_SORT;
3197 }
3198
3199 if (add)
3200 {
3201 flag |= style;
3202 }
3203 else
3204 {
3205 if (flag & style) flag -= style;
3206 }
3207
3208 SetWindowStyleFlag( flag );
3209 }
3210
3211 void wxListCtrl::SetWindowStyleFlag( long flag )
3212 {
3213 if (m_mainWin)
3214 {
3215 m_mainWin->DeleteEverything();
3216
3217 int width = 0;
3218 int height = 0;
3219 GetClientSize( &width, &height );
3220
3221 m_mainWin->SetMode( flag );
3222
3223 if (flag & wxLC_REPORT)
3224 {
3225 if (!HasFlag(wxLC_REPORT))
3226 {
3227 if (!m_headerWin)
3228 {
3229 m_headerWin = new wxListHeaderWindow( this, -1, m_mainWin,
3230 wxPoint(0,0), wxSize(width,23), wxTAB_TRAVERSAL );
3231 if (HasFlag(wxLC_NO_HEADER))
3232 m_headerWin->Show( FALSE );
3233 }
3234 else
3235 {
3236 if (flag & wxLC_NO_HEADER)
3237 m_headerWin->Show( FALSE );
3238 else
3239 m_headerWin->Show( TRUE );
3240 }
3241 }
3242 }
3243 else
3244 {
3245 if (HasFlag(wxLC_REPORT) && !(HasFlag(wxLC_NO_HEADER)))
3246 {
3247 m_headerWin->Show( FALSE );
3248 }
3249 }
3250 }
3251
3252 wxWindow::SetWindowStyleFlag( flag );
3253 }
3254
3255 bool wxListCtrl::GetColumn(int col, wxListItem &item) const
3256 {
3257 m_mainWin->GetColumn( col, item );
3258 return TRUE;
3259 }
3260
3261 bool wxListCtrl::SetColumn( int col, wxListItem& item )
3262 {
3263 m_mainWin->SetColumn( col, item );
3264 return TRUE;
3265 }
3266
3267 int wxListCtrl::GetColumnWidth( int col ) const
3268 {
3269 return m_mainWin->GetColumnWidth( col );
3270 }
3271
3272 bool wxListCtrl::SetColumnWidth( int col, int width )
3273 {
3274 m_mainWin->SetColumnWidth( col, width );
3275 return TRUE;
3276 }
3277
3278 int wxListCtrl::GetCountPerPage() const
3279 {
3280 return m_mainWin->GetCountPerPage(); // different from Windows ?
3281 }
3282
3283 bool wxListCtrl::GetItem( wxListItem &info ) const
3284 {
3285 m_mainWin->GetItem( info );
3286 return TRUE;
3287 }
3288
3289 bool wxListCtrl::SetItem( wxListItem &info )
3290 {
3291 m_mainWin->SetItem( info );
3292 return TRUE;
3293 }
3294
3295 long wxListCtrl::SetItem( long index, int col, const wxString& label, int imageId )
3296 {
3297 wxListItem info;
3298 info.m_text = label;
3299 info.m_mask = wxLIST_MASK_TEXT;
3300 info.m_itemId = index;
3301 info.m_col = col;
3302 if ( imageId > -1 )
3303 {
3304 info.m_image = imageId;
3305 info.m_mask |= wxLIST_MASK_IMAGE;
3306 };
3307 m_mainWin->SetItem(info);
3308 return TRUE;
3309 }
3310
3311 int wxListCtrl::GetItemState( long item, long stateMask ) const
3312 {
3313 return m_mainWin->GetItemState( item, stateMask );
3314 }
3315
3316 bool wxListCtrl::SetItemState( long item, long state, long stateMask )
3317 {
3318 m_mainWin->SetItemState( item, state, stateMask );
3319 return TRUE;
3320 }
3321
3322 bool wxListCtrl::SetItemImage( long item, int image, int WXUNUSED(selImage) )
3323 {
3324 wxListItem info;
3325 info.m_image = image;
3326 info.m_mask = wxLIST_MASK_IMAGE;
3327 info.m_itemId = item;
3328 m_mainWin->SetItem( info );
3329 return TRUE;
3330 }
3331
3332 wxString wxListCtrl::GetItemText( long item ) const
3333 {
3334 wxListItem info;
3335 info.m_itemId = item;
3336 m_mainWin->GetItem( info );
3337 return info.m_text;
3338 }
3339
3340 void wxListCtrl::SetItemText( long item, const wxString &str )
3341 {
3342 wxListItem info;
3343 info.m_mask = wxLIST_MASK_TEXT;
3344 info.m_itemId = item;
3345 info.m_text = str;
3346 m_mainWin->SetItem( info );
3347 }
3348
3349 long wxListCtrl::GetItemData( long item ) const
3350 {
3351 wxListItem info;
3352 info.m_itemId = item;
3353 m_mainWin->GetItem( info );
3354 return info.m_data;
3355 }
3356
3357 bool wxListCtrl::SetItemData( long item, long data )
3358 {
3359 wxListItem info;
3360 info.m_mask = wxLIST_MASK_DATA;
3361 info.m_itemId = item;
3362 info.m_data = data;
3363 m_mainWin->SetItem( info );
3364 return TRUE;
3365 }
3366
3367 bool wxListCtrl::GetItemRect( long item, wxRect &rect, int WXUNUSED(code) ) const
3368 {
3369 m_mainWin->GetItemRect( item, rect );
3370 return TRUE;
3371 }
3372
3373 bool wxListCtrl::GetItemPosition( long item, wxPoint& pos ) const
3374 {
3375 m_mainWin->GetItemPosition( item, pos );
3376 return TRUE;
3377 }
3378
3379 bool wxListCtrl::SetItemPosition( long WXUNUSED(item), const wxPoint& WXUNUSED(pos) )
3380 {
3381 return 0;
3382 }
3383
3384 int wxListCtrl::GetItemCount() const
3385 {
3386 return m_mainWin->GetItemCount();
3387 }
3388
3389 int wxListCtrl::GetColumnCount() const
3390 {
3391 return m_mainWin->GetColumnCount();
3392 }
3393
3394 void wxListCtrl::SetItemSpacing( int spacing, bool isSmall )
3395 {
3396 m_mainWin->SetItemSpacing( spacing, isSmall );
3397 }
3398
3399 int wxListCtrl::GetItemSpacing( bool isSmall ) const
3400 {
3401 return m_mainWin->GetItemSpacing( isSmall );
3402 }
3403
3404 int wxListCtrl::GetSelectedItemCount() const
3405 {
3406 return m_mainWin->GetSelectedItemCount();
3407 }
3408
3409 wxColour wxListCtrl::GetTextColour() const
3410 {
3411 return GetForegroundColour();
3412 }
3413
3414 void wxListCtrl::SetTextColour(const wxColour& col)
3415 {
3416 SetForegroundColour(col);
3417 }
3418
3419 long wxListCtrl::GetTopItem() const
3420 {
3421 return 0;
3422 }
3423
3424 long wxListCtrl::GetNextItem( long item, int geom, int state ) const
3425 {
3426 return m_mainWin->GetNextItem( item, geom, state );
3427 }
3428
3429 wxImageList *wxListCtrl::GetImageList(int which) const
3430 {
3431 if (which == wxIMAGE_LIST_NORMAL)
3432 {
3433 return m_imageListNormal;
3434 }
3435 else if (which == wxIMAGE_LIST_SMALL)
3436 {
3437 return m_imageListSmall;
3438 }
3439 else if (which == wxIMAGE_LIST_STATE)
3440 {
3441 return m_imageListState;
3442 }
3443 return (wxImageList *) NULL;
3444 }
3445
3446 void wxListCtrl::SetImageList( wxImageList *imageList, int which )
3447 {
3448 m_mainWin->SetImageList( imageList, which );
3449 }
3450
3451 bool wxListCtrl::Arrange( int WXUNUSED(flag) )
3452 {
3453 return 0;
3454 }
3455
3456 bool wxListCtrl::DeleteItem( long item )
3457 {
3458 m_mainWin->DeleteItem( item );
3459 return TRUE;
3460 }
3461
3462 bool wxListCtrl::DeleteAllItems()
3463 {
3464 m_mainWin->DeleteAllItems();
3465 return TRUE;
3466 }
3467
3468 bool wxListCtrl::DeleteAllColumns()
3469 {
3470 for ( size_t n = 0; n < m_mainWin->m_columns.GetCount(); n++ )
3471 DeleteColumn(n);
3472
3473 return TRUE;
3474 }
3475
3476 void wxListCtrl::ClearAll()
3477 {
3478 m_mainWin->DeleteEverything();
3479 }
3480
3481 bool wxListCtrl::DeleteColumn( int col )
3482 {
3483 m_mainWin->DeleteColumn( col );
3484 return TRUE;
3485 }
3486
3487 void wxListCtrl::Edit( long item )
3488 {
3489 m_mainWin->Edit( item );
3490 }
3491
3492 bool wxListCtrl::EnsureVisible( long item )
3493 {
3494 m_mainWin->EnsureVisible( item );
3495 return TRUE;
3496 }
3497
3498 long wxListCtrl::FindItem( long start, const wxString& str, bool partial )
3499 {
3500 return m_mainWin->FindItem( start, str, partial );
3501 }
3502
3503 long wxListCtrl::FindItem( long start, long data )
3504 {
3505 return m_mainWin->FindItem( start, data );
3506 }
3507
3508 long wxListCtrl::FindItem( long WXUNUSED(start), const wxPoint& WXUNUSED(pt),
3509 int WXUNUSED(direction))
3510 {
3511 return 0;
3512 }
3513
3514 long wxListCtrl::HitTest( const wxPoint &point, int &flags )
3515 {
3516 return m_mainWin->HitTest( (int)point.x, (int)point.y, flags );
3517 }
3518
3519 long wxListCtrl::InsertItem( wxListItem& info )
3520 {
3521 m_mainWin->InsertItem( info );
3522 return info.m_itemId;
3523 }
3524
3525 long wxListCtrl::InsertItem( long index, const wxString &label )
3526 {
3527 wxListItem info;
3528 info.m_text = label;
3529 info.m_mask = wxLIST_MASK_TEXT;
3530 info.m_itemId = index;
3531 return InsertItem( info );
3532 }
3533
3534 long wxListCtrl::InsertItem( long index, int imageIndex )
3535 {
3536 wxListItem info;
3537 info.m_mask = wxLIST_MASK_IMAGE;
3538 info.m_image = imageIndex;
3539 info.m_itemId = index;
3540 return InsertItem( info );
3541 }
3542
3543 long wxListCtrl::InsertItem( long index, const wxString &label, int imageIndex )
3544 {
3545 wxListItem info;
3546 info.m_text = label;
3547 info.m_image = imageIndex;
3548 info.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_IMAGE;
3549 info.m_itemId = index;
3550 return InsertItem( info );
3551 }
3552
3553 long wxListCtrl::InsertColumn( long col, wxListItem &item )
3554 {
3555 wxASSERT( m_headerWin );
3556 m_mainWin->InsertColumn( col, item );
3557 m_headerWin->Refresh();
3558
3559 return 0;
3560 }
3561
3562 long wxListCtrl::InsertColumn( long col, const wxString &heading,
3563 int format, int width )
3564 {
3565 wxListItem item;
3566 item.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_FORMAT;
3567 item.m_text = heading;
3568 if (width >= -2)
3569 {
3570 item.m_mask |= wxLIST_MASK_WIDTH;
3571 item.m_width = width;
3572 }
3573 item.m_format = format;
3574
3575 return InsertColumn( col, item );
3576 }
3577
3578 bool wxListCtrl::ScrollList( int WXUNUSED(dx), int WXUNUSED(dy) )
3579 {
3580 return 0;
3581 }
3582
3583 // Sort items.
3584 // fn is a function which takes 3 long arguments: item1, item2, data.
3585 // item1 is the long data associated with a first item (NOT the index).
3586 // item2 is the long data associated with a second item (NOT the index).
3587 // data is the same value as passed to SortItems.
3588 // The return value is a negative number if the first item should precede the second
3589 // item, a positive number of the second item should precede the first,
3590 // or zero if the two items are equivalent.
3591 // data is arbitrary data to be passed to the sort function.
3592
3593 bool wxListCtrl::SortItems( wxListCtrlCompare fn, long data )
3594 {
3595 m_mainWin->SortItems( fn, data );
3596 return TRUE;
3597 }
3598
3599 void wxListCtrl::OnIdle( wxIdleEvent &WXUNUSED(event) )
3600 {
3601 if (!m_mainWin->m_dirty) return;
3602
3603 int cw = 0;
3604 int ch = 0;
3605 GetClientSize( &cw, &ch );
3606
3607 int x = 0;
3608 int y = 0;
3609 int w = 0;
3610 int h = 0;
3611
3612 if (HasFlag(wxLC_REPORT) && !HasFlag(wxLC_NO_HEADER))
3613 {
3614 m_headerWin->GetPosition( &x, &y );
3615 m_headerWin->GetSize( &w, &h );
3616 if ((x != 0) || (y != 0) || (w != cw) || (h != 23))
3617 m_headerWin->SetSize( 0, 0, cw, 23 );
3618
3619 m_mainWin->GetPosition( &x, &y );
3620 m_mainWin->GetSize( &w, &h );
3621 if ((x != 0) || (y != 24) || (w != cw) || (h != ch-24))
3622 m_mainWin->SetSize( 0, 24, cw, ch-24 );
3623 }
3624 else
3625 {
3626 m_mainWin->GetPosition( &x, &y );
3627 m_mainWin->GetSize( &w, &h );
3628 if ((x != 0) || (y != 24) || (w != cw) || (h != ch))
3629 m_mainWin->SetSize( 0, 0, cw, ch );
3630 }
3631
3632 m_mainWin->CalculatePositions();
3633 m_mainWin->RealizeChanges();
3634 m_mainWin->m_dirty = FALSE;
3635 m_mainWin->Refresh();
3636
3637 if ( m_headerWin && m_headerWin->m_dirty )
3638 {
3639 m_headerWin->m_dirty = FALSE;
3640 m_headerWin->Refresh();
3641 }
3642 }
3643
3644 bool wxListCtrl::SetBackgroundColour( const wxColour &colour )
3645 {
3646 if (m_mainWin)
3647 {
3648 m_mainWin->SetBackgroundColour( colour );
3649 m_mainWin->m_dirty = TRUE;
3650 }
3651
3652 return TRUE;
3653 }
3654
3655 bool wxListCtrl::SetForegroundColour( const wxColour &colour )
3656 {
3657 if ( !wxWindow::SetForegroundColour( colour ) )
3658 return FALSE;
3659
3660 if (m_mainWin)
3661 {
3662 m_mainWin->SetForegroundColour( colour );
3663 m_mainWin->m_dirty = TRUE;
3664 }
3665
3666 if (m_headerWin)
3667 {
3668 m_headerWin->SetForegroundColour( colour );
3669 }
3670
3671 return TRUE;
3672 }
3673
3674 bool wxListCtrl::SetFont( const wxFont &font )
3675 {
3676 if ( !wxWindow::SetFont( font ) )
3677 return FALSE;
3678
3679 if (m_mainWin)
3680 {
3681 m_mainWin->SetFont( font );
3682 m_mainWin->m_dirty = TRUE;
3683 }
3684
3685 if (m_headerWin)
3686 {
3687 m_headerWin->SetFont( font );
3688 }
3689
3690 return TRUE;
3691 }
3692
3693 #if wxUSE_DRAG_AND_DROP
3694
3695 void wxListCtrl::SetDropTarget( wxDropTarget *dropTarget )
3696 {
3697 m_mainWin->SetDropTarget( dropTarget );
3698 }
3699
3700 wxDropTarget *wxListCtrl::GetDropTarget() const
3701 {
3702 return m_mainWin->GetDropTarget();
3703 }
3704
3705 #endif // wxUSE_DRAG_AND_DROP
3706
3707 bool wxListCtrl::SetCursor( const wxCursor &cursor )
3708 {
3709 return m_mainWin ? m_mainWin->wxWindow::SetCursor(cursor) : FALSE;
3710 }
3711
3712 wxColour wxListCtrl::GetBackgroundColour() const
3713 {
3714 return m_mainWin ? m_mainWin->GetBackgroundColour() : wxColour();
3715 }
3716
3717 wxColour wxListCtrl::GetForegroundColour() const
3718 {
3719 return m_mainWin ? m_mainWin->GetForegroundColour() : wxColour();
3720 }
3721
3722 bool wxListCtrl::DoPopupMenu( wxMenu *menu, int x, int y )
3723 {
3724 return m_mainWin->PopupMenu( menu, x, y );
3725 }
3726
3727 void wxListCtrl::SetFocus()
3728 {
3729 /* The test in window.cpp fails as we are a composite
3730 window, so it checks against "this", but not m_mainWin. */
3731 if ( FindFocus() != this )
3732 m_mainWin->SetFocus();
3733 }