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