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