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