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