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