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