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