]> git.saurik.com Git - wxWidgets.git/blob - src/generic/listctrl.cpp
1. wxFrame::IsIconized() fixed - seems to work
[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
1652 int lineSpacing = 0;
1653 wxListLineData *line = &m_lines[0];
1654 int dummy = 0;
1655 line->GetSize( dummy, lineSpacing );
1656 lineSpacing += 1;
1657
1658 int y_s = m_yScroll*GetScrollPos( wxVERTICAL );
1659
1660 size_t i_to = y_s / lineSpacing + m_visibleLines+2;
1661 if (i_to >= m_lines.GetCount()) i_to = m_lines.GetCount();
1662 size_t i;
1663 for (i = y_s / lineSpacing; i < i_to; i++)
1664 {
1665 m_lines[i].Draw( &dc );
1666 // Draw horizontal rule if required
1667 if (GetWindowStyle() & wxLC_HRULES)
1668 dc.DrawLine(0, i*lineSpacing, clientSize.x, i*lineSpacing);
1669 }
1670
1671 // Draw last horizontal rule
1672 if ((i > (size_t) (y_s / lineSpacing)) && (GetWindowStyle() & wxLC_HRULES))
1673 dc.DrawLine(0, i*lineSpacing, clientSize.x, i*lineSpacing);
1674
1675 // Draw vertical rules if required
1676 if ((GetWindowStyle() & wxLC_VRULES) && (GetItemCount() > 0))
1677 {
1678 int col = 0;
1679 wxRect firstItemRect;
1680 wxRect lastItemRect;
1681 GetItemRect(0, firstItemRect);
1682 GetItemRect(GetItemCount() - 1, lastItemRect);
1683 int x = firstItemRect.GetX();
1684 for (col = 0; col < GetColumnCount(); col++)
1685 {
1686 int colWidth = GetColumnWidth(col);
1687 x += colWidth ;
1688 dc.DrawLine(x, firstItemRect.GetY() - 1, x, lastItemRect.GetBottom() + 1);
1689 }
1690 }
1691 }
1692 else
1693 {
1694 for (size_t i = 0; i < m_lines.GetCount(); i++)
1695 m_lines[i].Draw( &dc );
1696 }
1697
1698 if (m_current) m_current->DrawRubberBand( &dc, m_hasFocus );
1699
1700 dc.EndDrawing();
1701 }
1702
1703 void wxListMainWindow::HilightAll( bool on )
1704 {
1705 for (size_t i = 0; i < m_lines.GetCount(); i++)
1706 {
1707 wxListLineData *line = &m_lines[i];
1708 if (line->IsHilighted() != on)
1709 {
1710 line->Hilight( on );
1711 RefreshLine( line );
1712 }
1713 }
1714 }
1715
1716 void wxListMainWindow::SendNotify( wxListLineData *line, wxEventType command )
1717 {
1718 wxListEvent le( command, GetParent()->GetId() );
1719 le.SetEventObject( GetParent() );
1720 le.m_itemIndex = GetIndexOfLine( line );
1721 line->GetItem( 0, le.m_item );
1722 GetParent()->GetEventHandler()->ProcessEvent( le );
1723 // GetParent()->GetEventHandler()->AddPendingEvent( le );
1724 }
1725
1726 void wxListMainWindow::FocusLine( wxListLineData *WXUNUSED(line) )
1727 {
1728 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_FOCUSSED );
1729 }
1730
1731 void wxListMainWindow::UnfocusLine( wxListLineData *WXUNUSED(line) )
1732 {
1733 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_UNFOCUSSED );
1734 }
1735
1736 void wxListMainWindow::SelectLine( wxListLineData *line )
1737 {
1738 SendNotify( line, wxEVT_COMMAND_LIST_ITEM_SELECTED );
1739 }
1740
1741 void wxListMainWindow::DeselectLine( wxListLineData *line )
1742 {
1743 SendNotify( line, wxEVT_COMMAND_LIST_ITEM_DESELECTED );
1744 }
1745
1746 void wxListMainWindow::DeleteLine( wxListLineData *line )
1747 {
1748 SendNotify( line, wxEVT_COMMAND_LIST_DELETE_ITEM );
1749 }
1750
1751 /* *** */
1752
1753 void wxListMainWindow::EditLabel( long item )
1754 {
1755 wxCHECK_RET( ((size_t)item < m_lines.GetCount()),
1756 wxT("wrong index in wxListCtrl::Edit()") );
1757
1758 m_currentEdit = &m_lines[(size_t)item];
1759
1760 wxListEvent le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT, GetParent()->GetId() );
1761 le.SetEventObject( GetParent() );
1762 le.m_itemIndex = GetIndexOfLine( m_currentEdit );
1763 m_currentEdit->GetItem( 0, le.m_item );
1764 GetParent()->GetEventHandler()->ProcessEvent( le );
1765
1766 if (!le.IsAllowed())
1767 return;
1768
1769 // We have to call this here because the label in
1770 // question might just have been added and no screen
1771 // update taken place.
1772 if (m_dirty) wxYield();
1773
1774 wxString s;
1775 m_currentEdit->GetText( 0, s );
1776 int x = 0;
1777 int y = 0;
1778 int w = 0;
1779 int h = 0;
1780 m_currentEdit->GetLabelExtent( x, y, w, h );
1781
1782 wxClientDC dc(this);
1783 PrepareDC( dc );
1784 x = dc.LogicalToDeviceX( x );
1785 y = dc.LogicalToDeviceY( y );
1786
1787 wxListTextCtrl *text = new wxListTextCtrl(
1788 this, -1, &m_renameAccept, &m_renameRes, this, s, wxPoint(x-4,y-4), wxSize(w+11,h+8) );
1789 text->SetFocus();
1790 }
1791
1792 void wxListMainWindow::OnRenameTimer()
1793 {
1794 wxCHECK_RET( m_current, wxT("invalid m_current") );
1795
1796 Edit( m_lines.Index( *m_current ) );
1797 }
1798
1799 void wxListMainWindow::OnRenameAccept()
1800 {
1801 wxListEvent le( wxEVT_COMMAND_LIST_END_LABEL_EDIT, GetParent()->GetId() );
1802 le.SetEventObject( GetParent() );
1803 le.m_itemIndex = GetIndexOfLine( m_currentEdit );
1804 m_currentEdit->GetItem( 0, le.m_item );
1805 le.m_item.m_text = m_renameRes;
1806 GetParent()->GetEventHandler()->ProcessEvent( le );
1807
1808 if (!le.IsAllowed()) return;
1809
1810 wxListItem info;
1811 info.m_mask = wxLIST_MASK_TEXT;
1812 info.m_itemId = le.m_itemIndex;
1813 info.m_text = m_renameRes;
1814 info.SetTextColour(le.m_item.GetTextColour());
1815 SetItem( info );
1816 }
1817
1818 void wxListMainWindow::OnMouse( wxMouseEvent &event )
1819 {
1820 event.SetEventObject( GetParent() );
1821 if (GetParent()->GetEventHandler()->ProcessEvent( event)) return;
1822
1823 if (!m_current) return;
1824 if (m_dirty) return;
1825 if ( !(event.Dragging() || event.ButtonDown() || event.LeftUp() || event.ButtonDClick()) ) return;
1826
1827 int x = event.GetX();
1828 int y = event.GetY();
1829 CalcUnscrolledPosition( x, y, &x, &y );
1830
1831 /* Did we actually hit an item ? */
1832 long hitResult = 0;
1833 wxListLineData *line = (wxListLineData *) NULL;
1834 for (size_t i = 0; i < m_lines.GetCount(); i++)
1835 {
1836 line = &m_lines[i];
1837 hitResult = line->IsHit( x, y );
1838 if (hitResult) break;
1839 line = (wxListLineData *) NULL;
1840 }
1841
1842 if (event.Dragging())
1843 {
1844 if (m_dragCount == 0)
1845 m_dragStart = wxPoint(x,y);
1846
1847 m_dragCount++;
1848
1849 if (m_dragCount != 3) return;
1850
1851 int command = wxEVT_COMMAND_LIST_BEGIN_DRAG;
1852 if (event.RightIsDown()) command = wxEVT_COMMAND_LIST_BEGIN_RDRAG;
1853
1854 wxListEvent le( command, GetParent()->GetId() );
1855 le.SetEventObject( GetParent() );
1856 le.m_pointDrag = m_dragStart;
1857 GetParent()->GetEventHandler()->ProcessEvent( le );
1858
1859 return;
1860 }
1861 else
1862 {
1863 m_dragCount = 0;
1864 }
1865
1866 if (!line) return;
1867
1868 bool forceClick = FALSE;
1869 if (event.ButtonDClick())
1870 {
1871 m_renameTimer->Stop();
1872 m_lastOnSame = FALSE;
1873
1874 if ( line == m_lineBeforeLastClicked )
1875 {
1876 m_usedKeys = FALSE;
1877
1878 SendNotify( line, wxEVT_COMMAND_LIST_ITEM_ACTIVATED );
1879
1880 return;
1881 }
1882 else
1883 {
1884 // the first click was on another item, so don't interpret this as
1885 // a double click, but as a simple click instead
1886 forceClick = TRUE;
1887 }
1888 }
1889
1890 if (event.LeftUp() && m_lastOnSame)
1891 {
1892 m_usedKeys = FALSE;
1893 if ((line == m_current) &&
1894 (hitResult == wxLIST_HITTEST_ONITEMLABEL) &&
1895 (m_mode & wxLC_EDIT_LABELS) )
1896 {
1897 m_renameTimer->Start( 100, TRUE );
1898 }
1899 m_lastOnSame = FALSE;
1900 return;
1901 }
1902
1903 if (event.RightDown())
1904 {
1905 SendNotify( line, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK );
1906 return;
1907 }
1908
1909 if (event.MiddleDown())
1910 {
1911 SendNotify( line, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK );
1912 return;
1913 }
1914
1915 if ( event.LeftDown() || forceClick )
1916 {
1917 m_lineBeforeLastClicked = m_lineLastClicked;
1918 m_lineLastClicked = line;
1919
1920 m_usedKeys = FALSE;
1921 wxListLineData *oldCurrent = m_current;
1922 if (m_mode & wxLC_SINGLE_SEL)
1923 {
1924 m_current = line;
1925 HilightAll( FALSE );
1926 m_current->ReverseHilight();
1927 RefreshLine( m_current );
1928 }
1929 else
1930 {
1931 if (event.ControlDown())
1932 {
1933 m_current = line;
1934 m_current->ReverseHilight();
1935 RefreshLine( m_current );
1936 }
1937 else if (event.ShiftDown())
1938 {
1939 size_t j;
1940
1941 m_current = line;
1942
1943 int numOfCurrent = -1;
1944 for (j = 0; j < m_lines.GetCount(); j++)
1945 {
1946 wxListLineData *test_line = &m_lines[j];
1947 numOfCurrent++;
1948 if (test_line == oldCurrent) break;
1949 }
1950
1951 int numOfLine = -1;
1952
1953 for (j = 0; j < m_lines.GetCount(); j++)
1954 {
1955 wxListLineData *test_line = &m_lines[j];
1956 numOfLine++;
1957 if (test_line == line) break;
1958 }
1959
1960 if (numOfLine < numOfCurrent)
1961 {
1962 int i = numOfLine;
1963 numOfLine = numOfCurrent;
1964 numOfCurrent = i;
1965 }
1966
1967 for (int i = 0; i <= numOfLine-numOfCurrent; i++)
1968 {
1969 wxListLineData *test_line= &m_lines[numOfCurrent + i];
1970 test_line->Hilight(TRUE);
1971 RefreshLine( test_line );
1972 }
1973 }
1974 else
1975 {
1976 m_current = line;
1977 HilightAll( FALSE );
1978 m_current->ReverseHilight();
1979 RefreshLine( m_current );
1980 }
1981 }
1982 if (m_current != oldCurrent)
1983 {
1984 RefreshLine( oldCurrent );
1985 UnfocusLine( oldCurrent );
1986 FocusLine( m_current );
1987 }
1988
1989 // forceClick is only set if the previous click was on another item
1990 m_lastOnSame = !forceClick && (m_current == oldCurrent);
1991
1992 return;
1993 }
1994 }
1995
1996 void wxListMainWindow::MoveToFocus()
1997 {
1998 if (!m_current) return;
1999
2000 int item_x = 0;
2001 int item_y = 0;
2002 int item_w = 0;
2003 int item_h = 0;
2004 m_current->GetExtent( item_x, item_y, item_w, item_h );
2005
2006 int client_w = 0;
2007 int client_h = 0;
2008 GetClientSize( &client_w, &client_h );
2009
2010 int view_x = m_xScroll*GetScrollPos( wxHORIZONTAL );
2011 int view_y = m_yScroll*GetScrollPos( wxVERTICAL );
2012
2013 if (m_mode & wxLC_REPORT)
2014 {
2015 if (item_y-5 < view_y )
2016 Scroll( -1, (item_y-5)/m_yScroll );
2017 if (item_y+item_h+5 > view_y+client_h)
2018 Scroll( -1, (item_y+item_h-client_h+15)/m_yScroll );
2019 }
2020 else
2021 {
2022 if (item_x-view_x < 5)
2023 Scroll( (item_x-5)/m_xScroll, -1 );
2024 if (item_x+item_w-5 > view_x+client_w)
2025 Scroll( (item_x+item_w-client_w+15)/m_xScroll, -1 );
2026 }
2027 }
2028
2029 void wxListMainWindow::OnArrowChar( wxListLineData *newCurrent, bool shiftDown )
2030 {
2031 if ((m_mode & wxLC_SINGLE_SEL) || (m_usedKeys == FALSE)) m_current->Hilight( FALSE );
2032 wxListLineData *oldCurrent = m_current;
2033 m_current = newCurrent;
2034 if (shiftDown || (m_mode & wxLC_SINGLE_SEL)) m_current->Hilight( TRUE );
2035 RefreshLine( m_current );
2036 RefreshLine( oldCurrent );
2037 FocusLine( m_current );
2038 UnfocusLine( oldCurrent );
2039 MoveToFocus();
2040 }
2041
2042 void wxListMainWindow::OnKeyDown( wxKeyEvent &event )
2043 {
2044 wxWindow *parent = GetParent();
2045
2046 /* we propagate the key event up */
2047 wxKeyEvent ke( wxEVT_KEY_DOWN );
2048 ke.m_shiftDown = event.m_shiftDown;
2049 ke.m_controlDown = event.m_controlDown;
2050 ke.m_altDown = event.m_altDown;
2051 ke.m_metaDown = event.m_metaDown;
2052 ke.m_keyCode = event.m_keyCode;
2053 ke.m_x = event.m_x;
2054 ke.m_y = event.m_y;
2055 ke.SetEventObject( parent );
2056 if (parent->GetEventHandler()->ProcessEvent( ke )) return;
2057
2058 event.Skip();
2059 }
2060
2061 void wxListMainWindow::OnChar( wxKeyEvent &event )
2062 {
2063 wxWindow *parent = GetParent();
2064
2065 /* we send a list_key event up */
2066 if ( m_current )
2067 {
2068 wxListEvent le( wxEVT_COMMAND_LIST_KEY_DOWN, GetParent()->GetId() );
2069 le.m_itemIndex = GetIndexOfLine( m_current );
2070 m_current->GetItem( 0, le.m_item );
2071 le.m_code = (int)event.KeyCode();
2072 le.SetEventObject( parent );
2073 parent->GetEventHandler()->ProcessEvent( le );
2074 }
2075
2076 /* we propagate the char event up */
2077 wxKeyEvent ke( wxEVT_CHAR );
2078 ke.m_shiftDown = event.m_shiftDown;
2079 ke.m_controlDown = event.m_controlDown;
2080 ke.m_altDown = event.m_altDown;
2081 ke.m_metaDown = event.m_metaDown;
2082 ke.m_keyCode = event.m_keyCode;
2083 ke.m_x = event.m_x;
2084 ke.m_y = event.m_y;
2085 ke.SetEventObject( parent );
2086 if (parent->GetEventHandler()->ProcessEvent( ke )) return;
2087
2088 if (event.KeyCode() == WXK_TAB)
2089 {
2090 wxNavigationKeyEvent nevent;
2091 nevent.SetWindowChange( event.ControlDown() );
2092 nevent.SetDirection( !event.ShiftDown() );
2093 nevent.SetEventObject( GetParent()->GetParent() );
2094 nevent.SetCurrentFocus( m_parent );
2095 if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent )) return;
2096 }
2097
2098 /* no item -> nothing to do */
2099 if (!m_current)
2100 {
2101 event.Skip();
2102 return;
2103 }
2104
2105 switch (event.KeyCode())
2106 {
2107 case WXK_UP:
2108 {
2109 int index = m_lines.Index(*m_current);
2110 if (index != wxNOT_FOUND && index > 0)
2111 OnArrowChar( &m_lines[index-1], event.ShiftDown() );
2112 break;
2113 }
2114 case WXK_DOWN:
2115 {
2116 int index = m_lines.Index(*m_current);
2117 if (index != wxNOT_FOUND && (size_t)index < m_lines.GetCount()-1)
2118 OnArrowChar( &m_lines[index+1], event.ShiftDown() );
2119 break;
2120 }
2121 case WXK_END:
2122 {
2123 if (!m_lines.IsEmpty())
2124 OnArrowChar( &m_lines.Last(), event.ShiftDown() );
2125 break;
2126 }
2127 case WXK_HOME:
2128 {
2129 if (!m_lines.IsEmpty())
2130 OnArrowChar( &m_lines[0], event.ShiftDown() );
2131 break;
2132 }
2133 case WXK_PRIOR:
2134 {
2135 int steps = 0;
2136 int index = m_lines.Index(*m_current);
2137 if (m_mode & wxLC_REPORT)
2138 {
2139 steps = m_visibleLines-1;
2140 }
2141 else
2142 {
2143 steps = index % m_visibleLines;
2144 }
2145 if (index != wxNOT_FOUND)
2146 {
2147 index -= steps;
2148 if (index < 0) index = 0;
2149 OnArrowChar( &m_lines[index], event.ShiftDown() );
2150 }
2151 break;
2152 }
2153 case WXK_NEXT:
2154 {
2155 int steps = 0;
2156 int index = m_lines.Index(*m_current);
2157 if (m_mode & wxLC_REPORT)
2158 {
2159 steps = m_visibleLines-1;
2160 }
2161 else
2162 {
2163 steps = m_visibleLines-(index % m_visibleLines)-1;
2164 }
2165
2166 if (index != wxNOT_FOUND)
2167 {
2168 index += steps;
2169 if ((size_t)index >= m_lines.GetCount())
2170 index = m_lines.GetCount()-1;
2171 OnArrowChar( &m_lines[index], event.ShiftDown() );
2172 }
2173 break;
2174 }
2175 case WXK_LEFT:
2176 {
2177 if (!(m_mode & wxLC_REPORT))
2178 {
2179 int index = m_lines.Index(*m_current);
2180 if (index != wxNOT_FOUND)
2181 {
2182 index -= m_visibleLines;
2183 if (index < 0) index = 0;
2184 OnArrowChar( &m_lines[index], event.ShiftDown() );
2185 }
2186 }
2187 break;
2188 }
2189 case WXK_RIGHT:
2190 {
2191 if (!(m_mode & wxLC_REPORT))
2192 {
2193 int index = m_lines.Index(*m_current);
2194 if (index != wxNOT_FOUND)
2195 {
2196 index += m_visibleLines;
2197 if ((size_t)index >= m_lines.GetCount())
2198 index = m_lines.GetCount()-1;
2199 OnArrowChar( &m_lines[index], event.ShiftDown() );
2200 }
2201 }
2202 break;
2203 }
2204 case WXK_SPACE:
2205 {
2206 if (m_mode & wxLC_SINGLE_SEL)
2207 {
2208 wxListEvent le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED, GetParent()->GetId() );
2209 le.SetEventObject( GetParent() );
2210 le.m_itemIndex = GetIndexOfLine( m_current );
2211 m_current->GetItem( 0, le.m_item );
2212 GetParent()->GetEventHandler()->ProcessEvent( le );
2213 }
2214 else
2215 {
2216 m_current->ReverseHilight();
2217 RefreshLine( m_current );
2218 }
2219 break;
2220 }
2221 case WXK_INSERT:
2222 {
2223 if (!(m_mode & wxLC_SINGLE_SEL))
2224 {
2225 wxListLineData *oldCurrent = m_current;
2226 m_current->ReverseHilight();
2227 int index = m_lines.Index( *m_current ) + 1;
2228 if ( (size_t)index < m_lines.GetCount() )
2229 m_current = &m_lines[index];
2230 RefreshLine( oldCurrent );
2231 RefreshLine( m_current );
2232 UnfocusLine( oldCurrent );
2233 FocusLine( m_current );
2234 MoveToFocus();
2235 }
2236 break;
2237 }
2238 case WXK_RETURN:
2239 case WXK_EXECUTE:
2240 {
2241 wxListEvent le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED, GetParent()->GetId() );
2242 le.SetEventObject( GetParent() );
2243 le.m_itemIndex = GetIndexOfLine( m_current );
2244 m_current->GetItem( 0, le.m_item );
2245 GetParent()->GetEventHandler()->ProcessEvent( le );
2246 break;
2247 }
2248 default:
2249 {
2250 event.Skip();
2251 return;
2252 }
2253 }
2254 m_usedKeys = TRUE;
2255 }
2256
2257 #ifdef __WXGTK__
2258 extern wxWindow *g_focusWindow;
2259 #endif
2260
2261 void wxListMainWindow::OnSetFocus( wxFocusEvent &WXUNUSED(event) )
2262 {
2263 m_hasFocus = TRUE;
2264 RefreshLine( m_current );
2265
2266 if (!GetParent()) return;
2267
2268 #ifdef __WXGTK__
2269 g_focusWindow = GetParent();
2270 #endif
2271
2272 wxFocusEvent event( wxEVT_SET_FOCUS, GetParent()->GetId() );
2273 event.SetEventObject( GetParent() );
2274 GetParent()->GetEventHandler()->ProcessEvent( event );
2275 }
2276
2277 void wxListMainWindow::OnKillFocus( wxFocusEvent &WXUNUSED(event) )
2278 {
2279 m_hasFocus = FALSE;
2280 RefreshLine( m_current );
2281 }
2282
2283 void wxListMainWindow::OnSize( wxSizeEvent &WXUNUSED(event) )
2284 {
2285 /*
2286 We don't even allow the wxScrolledWindow::AdjustScrollbars() call
2287
2288 */
2289 m_dirty = TRUE;
2290 }
2291
2292 void wxListMainWindow::DrawImage( int index, wxDC *dc, int x, int y )
2293 {
2294 if ((m_mode & wxLC_ICON) && (m_normal_image_list))
2295 {
2296 m_normal_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT );
2297 return;
2298 }
2299 if ((m_mode & wxLC_SMALL_ICON) && (m_small_image_list))
2300 {
2301 m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT );
2302 }
2303 if ((m_mode & wxLC_LIST) && (m_small_image_list))
2304 {
2305 m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT );
2306 }
2307 if ((m_mode & wxLC_REPORT) && (m_small_image_list))
2308 {
2309 m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT );
2310 return;
2311 }
2312 }
2313
2314 void wxListMainWindow::GetImageSize( int index, int &width, int &height )
2315 {
2316 if ((m_mode & wxLC_ICON) && (m_normal_image_list))
2317 {
2318 m_normal_image_list->GetSize( index, width, height );
2319 return;
2320 }
2321 if ((m_mode & wxLC_SMALL_ICON) && (m_small_image_list))
2322 {
2323 m_small_image_list->GetSize( index, width, height );
2324 return;
2325 }
2326 if ((m_mode & wxLC_LIST) && (m_small_image_list))
2327 {
2328 m_small_image_list->GetSize( index, width, height );
2329 return;
2330 }
2331 if ((m_mode & wxLC_REPORT) && (m_small_image_list))
2332 {
2333 m_small_image_list->GetSize( index, width, height );
2334 return;
2335 }
2336 width = 0;
2337 height = 0;
2338 }
2339
2340 int wxListMainWindow::GetTextLength( wxString &s )
2341 {
2342 wxClientDC dc( this );
2343 wxCoord lw = 0;
2344 wxCoord lh = 0;
2345 dc.GetTextExtent( s, &lw, &lh );
2346 return lw + 6;
2347 }
2348
2349 int wxListMainWindow::GetIndexOfLine( const wxListLineData *line )
2350 {
2351 int i = m_lines.Index(*line);
2352 if (i == wxNOT_FOUND) return -1;
2353 else return i;
2354 }
2355
2356 void wxListMainWindow::SetImageList( wxImageList *imageList, int which )
2357 {
2358 m_dirty = TRUE;
2359
2360 // calc the spacing from the icon size
2361 int width = 0,
2362 height = 0;
2363 if ((imageList) && (imageList->GetImageCount()) )
2364 {
2365 imageList->GetSize(0, width, height);
2366 }
2367
2368 if (which == wxIMAGE_LIST_NORMAL)
2369 {
2370 m_normal_image_list = imageList;
2371 m_normal_spacing = width + 8;
2372 }
2373
2374 if (which == wxIMAGE_LIST_SMALL)
2375 {
2376 m_small_image_list = imageList;
2377 m_small_spacing = width + 14;
2378 }
2379 }
2380
2381 void wxListMainWindow::SetItemSpacing( int spacing, bool isSmall )
2382 {
2383 m_dirty = TRUE;
2384 if (isSmall)
2385 {
2386 m_small_spacing = spacing;
2387 }
2388 else
2389 {
2390 m_normal_spacing = spacing;
2391 }
2392 }
2393
2394 int wxListMainWindow::GetItemSpacing( bool isSmall )
2395 {
2396 return isSmall ? m_small_spacing : m_normal_spacing;
2397 }
2398
2399 void wxListMainWindow::SetColumn( int col, wxListItem &item )
2400 {
2401 m_dirty = TRUE;
2402 wxNode *node = m_columns.Nth( col );
2403 if (node)
2404 {
2405 if (item.m_width == wxLIST_AUTOSIZE_USEHEADER) item.m_width = GetTextLength( item.m_text )+7;
2406 wxListHeaderData *column = (wxListHeaderData*)node->Data();
2407 column->SetItem( item );
2408 }
2409
2410 wxListHeaderWindow *headerWin = ((wxListCtrl*) GetParent())->m_headerWin;
2411 if ( headerWin )
2412 headerWin->m_dirty = TRUE;
2413 }
2414
2415 void wxListMainWindow::SetColumnWidth( int col, int width )
2416 {
2417 wxCHECK_RET( m_mode & wxLC_REPORT,
2418 _T("SetColumnWidth() can only be called in report mode.") );
2419
2420 m_dirty = TRUE;
2421
2422 wxNode *node = (wxNode*) NULL;
2423
2424 if (width == wxLIST_AUTOSIZE_USEHEADER)
2425 {
2426 // TODO do use the header
2427 width = 80;
2428 }
2429 else if (width == wxLIST_AUTOSIZE)
2430 {
2431 wxClientDC dc(this);
2432 dc.SetFont( GetFont() );
2433 int max = 10;
2434
2435 for (size_t i = 0; i < m_lines.GetCount(); i++)
2436 {
2437 wxListLineData *line = &m_lines[i];
2438 wxNode *n = line->m_items.Nth( col );
2439 if (n)
2440 {
2441 wxListItemData *item = (wxListItemData*)n->Data();
2442 int current = 0, ix = 0, iy = 0;
2443 wxCoord lx = 0, ly = 0;
2444 if (item->HasImage())
2445 {
2446 GetImageSize( item->GetImage(), ix, iy );
2447 current = ix + 5;
2448 }
2449 if (item->HasText())
2450 {
2451 wxString str;
2452 item->GetText( str );
2453 dc.GetTextExtent( str, &lx, &ly );
2454 current += lx;
2455 }
2456 if (current > max) max = current;
2457 }
2458 }
2459 width = max+10;
2460 }
2461
2462 node = m_columns.Nth( col );
2463 if (node)
2464 {
2465 wxListHeaderData *column = (wxListHeaderData*)node->Data();
2466 column->SetWidth( width );
2467 }
2468
2469 for (size_t i = 0; i < m_lines.GetCount(); i++)
2470 {
2471 wxListLineData *line = &m_lines[i];
2472 wxNode *n = line->m_items.Nth( col );
2473 if (n)
2474 {
2475 wxListItemData *item = (wxListItemData*)n->Data();
2476 item->SetSize( width, -1 );
2477 }
2478 }
2479
2480 wxListHeaderWindow *headerWin = ((wxListCtrl*) GetParent())->m_headerWin;
2481 if ( headerWin )
2482 headerWin->m_dirty = TRUE;
2483 }
2484
2485 void wxListMainWindow::GetColumn( int col, wxListItem &item )
2486 {
2487 wxNode *node = m_columns.Nth( col );
2488 if (node)
2489 {
2490 wxListHeaderData *column = (wxListHeaderData*)node->Data();
2491 column->GetItem( item );
2492 }
2493 else
2494 {
2495 item.m_format = 0;
2496 item.m_width = 0;
2497 item.m_text = "";
2498 item.m_image = 0;
2499 item.m_data = 0;
2500 }
2501 }
2502
2503 int wxListMainWindow::GetColumnWidth( int col )
2504 {
2505 wxNode *node = m_columns.Nth( col );
2506 if (node)
2507 {
2508 wxListHeaderData *column = (wxListHeaderData*)node->Data();
2509 return column->GetWidth();
2510 }
2511 else
2512 {
2513 return 0;
2514 }
2515 }
2516
2517 int wxListMainWindow::GetColumnCount()
2518 {
2519 return m_columns.Number();
2520 }
2521
2522 int wxListMainWindow::GetCountPerPage()
2523 {
2524 return m_visibleLines;
2525 }
2526
2527 void wxListMainWindow::SetItem( wxListItem &item )
2528 {
2529 m_dirty = TRUE;
2530 if (item.m_itemId >= 0 && (size_t)item.m_itemId < m_lines.GetCount())
2531 {
2532 wxListLineData *line = &m_lines[(size_t)item.m_itemId];
2533 if (m_mode & wxLC_REPORT) item.m_width = GetColumnWidth( item.m_col )-3;
2534 line->SetItem( item.m_col, item );
2535 }
2536 }
2537
2538 void wxListMainWindow::SetItemState( long item, long state, long stateMask )
2539 {
2540 // m_dirty = TRUE; no recalcs needed
2541
2542 wxListLineData *oldCurrent = m_current;
2543
2544 if (stateMask & wxLIST_STATE_FOCUSED)
2545 {
2546 if (item >= 0 && (size_t)item < m_lines.GetCount())
2547 {
2548 wxListLineData *line = &m_lines[(size_t)item];
2549 UnfocusLine( m_current );
2550 m_current = line;
2551 FocusLine( m_current );
2552 if ((m_mode & wxLC_SINGLE_SEL) && oldCurrent) oldCurrent->Hilight( FALSE );
2553 RefreshLine( m_current );
2554 if (oldCurrent) RefreshLine( oldCurrent );
2555 }
2556 }
2557
2558 if (stateMask & wxLIST_STATE_SELECTED)
2559 {
2560 bool on = (state & wxLIST_STATE_SELECTED) != 0;
2561 if (!on && (m_mode & wxLC_SINGLE_SEL)) return;
2562
2563 if (item >= 0 && (size_t)item < m_lines.GetCount())
2564 {
2565 wxListLineData *line = &m_lines[(size_t)item];
2566 if (m_mode & wxLC_SINGLE_SEL)
2567 {
2568 UnfocusLine( m_current );
2569 m_current = line;
2570 FocusLine( m_current );
2571 if (oldCurrent) oldCurrent->Hilight( FALSE );
2572 RefreshLine( m_current );
2573 if (oldCurrent) RefreshLine( oldCurrent );
2574 }
2575 bool on = (state & wxLIST_STATE_SELECTED) != 0;
2576 if (on != line->IsHilighted())
2577 {
2578 line->Hilight( on );
2579 RefreshLine( line );
2580 }
2581 }
2582 }
2583 }
2584
2585 int wxListMainWindow::GetItemState( long item, long stateMask )
2586 {
2587 int ret = wxLIST_STATE_DONTCARE;
2588 if (stateMask & wxLIST_STATE_FOCUSED)
2589 {
2590 if (item >= 0 && (size_t)item < m_lines.GetCount())
2591 {
2592 wxListLineData *line = &m_lines[(size_t)item];
2593 if (line == m_current) ret |= wxLIST_STATE_FOCUSED;
2594 }
2595 }
2596 if (stateMask & wxLIST_STATE_SELECTED)
2597 {
2598 if (item >= 0 && (size_t)item < m_lines.GetCount())
2599 {
2600 wxListLineData *line = &m_lines[(size_t)item];
2601 if (line->IsHilighted()) ret |= wxLIST_STATE_FOCUSED;
2602 }
2603 }
2604 return ret;
2605 }
2606
2607 void wxListMainWindow::GetItem( wxListItem &item )
2608 {
2609 if (item.m_itemId >= 0 && (size_t)item.m_itemId < m_lines.GetCount())
2610 {
2611 wxListLineData *line = &m_lines[(size_t)item.m_itemId];
2612 line->GetItem( item.m_col, item );
2613 }
2614 else
2615 {
2616 item.m_mask = 0;
2617 item.m_text = "";
2618 item.m_image = 0;
2619 item.m_data = 0;
2620 }
2621 }
2622
2623 int wxListMainWindow::GetItemCount()
2624 {
2625 return m_lines.GetCount();
2626 }
2627
2628 void wxListMainWindow::GetItemRect( long index, wxRect &rect )
2629 {
2630 if (index >= 0 && (size_t)index < m_lines.GetCount())
2631 {
2632 m_lines[(size_t)index].GetRect( rect );
2633 }
2634 else
2635 {
2636 rect.x = 0;
2637 rect.y = 0;
2638 rect.width = 0;
2639 rect.height = 0;
2640 }
2641 }
2642
2643 bool wxListMainWindow::GetItemPosition(long item, wxPoint& pos)
2644 {
2645 if (item >= 0 && (size_t)item < m_lines.GetCount())
2646 {
2647 wxRect rect;
2648 m_lines[(size_t)item].GetRect( rect );
2649 pos.x = rect.x;
2650 pos.y = rect.y;
2651 }
2652 else
2653 {
2654 pos.x = 0;
2655 pos.y = 0;
2656 }
2657 return TRUE;
2658 }
2659
2660 int wxListMainWindow::GetSelectedItemCount()
2661 {
2662 int ret = 0;
2663 for (size_t i = 0; i < m_lines.GetCount(); i++)
2664 {
2665 if (m_lines[i].IsHilighted()) ret++;
2666 }
2667 return ret;
2668 }
2669
2670 void wxListMainWindow::SetMode( long mode )
2671 {
2672 m_dirty = TRUE;
2673 m_mode = mode;
2674
2675 DeleteEverything();
2676
2677 if (m_mode & wxLC_REPORT)
2678 {
2679 #if wxUSE_GENERIC_LIST_EXTENSIONS
2680 m_xScroll = 15;
2681 #else
2682 m_xScroll = 0;
2683 #endif
2684 m_yScroll = 15;
2685 }
2686 else
2687 {
2688 m_xScroll = 15;
2689 m_yScroll = 0;
2690 }
2691 }
2692
2693 long wxListMainWindow::GetMode() const
2694 {
2695 return m_mode;
2696 }
2697
2698 void wxListMainWindow::CalculatePositions()
2699 {
2700 if (m_lines.IsEmpty()) return;
2701
2702 wxClientDC dc( this );
2703 dc.SetFont( GetFont() );
2704
2705 int iconSpacing = 0;
2706 if (m_mode & wxLC_ICON) iconSpacing = m_normal_spacing;
2707 if (m_mode & wxLC_SMALL_ICON) iconSpacing = m_small_spacing;
2708
2709 // we take the first line (which also can be an icon or
2710 // an a text item in wxLC_ICON and wxLC_LIST modes) to
2711 // measure the size of the line
2712
2713 int lineWidth = 0;
2714 int lineHeight = 0;
2715 int lineSpacing = 0;
2716
2717 wxListLineData *line = &m_lines[0];
2718 line->CalculateSize( &dc, iconSpacing );
2719 int dummy = 0;
2720 line->GetSize( dummy, lineSpacing );
2721 lineSpacing += 1;
2722
2723 int clientWidth = 0;
2724 int clientHeight = 0;
2725
2726 if (m_mode & wxLC_REPORT)
2727 {
2728 int x = 4;
2729 int y = 1;
2730 int entireHeight = m_lines.GetCount() * lineSpacing + 2;
2731 int scroll_pos = GetScrollPos( wxVERTICAL );
2732 #if wxUSE_GENERIC_LIST_EXTENSIONS
2733 int x_scroll_pos = GetScrollPos( wxHORIZONTAL );
2734 #else
2735 SetScrollbars( m_xScroll, m_yScroll, 0, (entireHeight+15) / m_yScroll, 0, scroll_pos, TRUE );
2736 #endif
2737 GetClientSize( &clientWidth, &clientHeight );
2738
2739 int entireWidth = 0 ;
2740 for (size_t j = 0; j < m_lines.GetCount(); j++)
2741 {
2742 wxListLineData *line = &m_lines[j];
2743 line->CalculateSize( &dc, iconSpacing );
2744 line->SetPosition( &dc, x, y, clientWidth );
2745 int col_x = 2;
2746 for (int i = 0; i < GetColumnCount(); i++)
2747 {
2748 line->SetColumnPosition( i, col_x );
2749 col_x += GetColumnWidth( i );
2750 }
2751 entireWidth = wxMax( entireWidth , col_x ) ;
2752 #if wxUSE_GENERIC_LIST_EXTENSIONS
2753 line->SetPosition( &dc, x, y, col_x );
2754 #endif
2755 y += lineSpacing; // one pixel blank line between items
2756 }
2757 m_visibleLines = clientHeight / lineSpacing;
2758 #if wxUSE_GENERIC_LIST_EXTENSIONS
2759 SetScrollbars( m_xScroll, m_yScroll, entireWidth / m_xScroll , (entireHeight+15) / m_yScroll, x_scroll_pos , scroll_pos, TRUE );
2760 #endif
2761 }
2762 else
2763 {
2764 // at first we try without any scrollbar. if the items don't
2765 // fit into the window, we recalculate after subtracting an
2766 // approximated 15 pt for the horizontal scrollbar
2767
2768 GetSize( &clientWidth, &clientHeight );
2769 clientHeight -= 4; // sunken frame
2770
2771 int entireWidth = 0;
2772
2773 for (int tries = 0; tries < 2; tries++)
2774 {
2775 entireWidth = 0;
2776 int x = 2;
2777 int y = 2;
2778 int maxWidth = 0;
2779 m_visibleLines = 0;
2780 int m_currentVisibleLines = 0;
2781 for (size_t i = 0; i < m_lines.GetCount(); i++)
2782 {
2783 m_currentVisibleLines++;
2784 wxListLineData *line = &m_lines[i];
2785 line->CalculateSize( &dc, iconSpacing );
2786 line->SetPosition( &dc, x, y, clientWidth );
2787 line->GetSize( lineWidth, lineHeight );
2788 if (lineWidth > maxWidth) maxWidth = lineWidth;
2789 y += lineSpacing;
2790 if (m_currentVisibleLines > m_visibleLines)
2791 m_visibleLines = m_currentVisibleLines;
2792 if (y+lineSpacing-6 >= clientHeight) // -6 for earlier "line breaking"
2793 {
2794 m_currentVisibleLines = 0;
2795 y = 2;
2796 x += maxWidth+6;
2797 entireWidth += maxWidth+6;
2798 maxWidth = 0;
2799 }
2800 if (i == m_lines.GetCount()-1) entireWidth += maxWidth;
2801 if ((tries == 0) && (entireWidth > clientWidth))
2802 {
2803 clientHeight -= 15; // scrollbar height
2804 m_visibleLines = 0;
2805 m_currentVisibleLines = 0;
2806 break;
2807 }
2808 if (i == m_lines.GetCount()-1) tries = 1; // everything fits, no second try required
2809 }
2810 }
2811
2812 int scroll_pos = GetScrollPos( wxHORIZONTAL );
2813 SetScrollbars( m_xScroll, m_yScroll, (entireWidth+15) / m_xScroll, 0, scroll_pos, 0, TRUE );
2814 }
2815 }
2816
2817 void wxListMainWindow::RealizeChanges()
2818 {
2819 if (!m_current)
2820 {
2821 if (!m_lines.IsEmpty())
2822 m_current = &m_lines[0];
2823 }
2824 if (m_current)
2825 {
2826 FocusLine( m_current );
2827 // TODO: MSW doesn't automatically hilight the
2828 // first item.
2829 // if (m_mode & wxLC_SINGLE_SEL) m_current->Hilight( TRUE );
2830 }
2831 }
2832
2833 long wxListMainWindow::GetNextItem( long item,
2834 int WXUNUSED(geometry),
2835 int state )
2836 {
2837 long ret = item,
2838 max = GetItemCount();
2839 wxCHECK_MSG( (ret == -1) || (ret < max), -1,
2840 _T("invalid listctrl index in GetNextItem()") );
2841
2842 // notice that we start with the next item (or the first one if item == -1)
2843 // and this is intentional to allow writing a simple loop to iterate over
2844 // all selected items
2845 ret++;
2846 if ( ret == max )
2847 {
2848 // this is not an error because the index was ok initially, just no
2849 // such item
2850 return -1;
2851 }
2852
2853 for (size_t i = (size_t)ret; i < m_lines.GetCount(); i++)
2854 {
2855 wxListLineData *line = &m_lines[i];
2856 if ((state & wxLIST_STATE_FOCUSED) && (line == m_current))
2857 return ret;
2858 if ((state & wxLIST_STATE_SELECTED) && (line->IsHilighted()))
2859 return ret;
2860 if (!state)
2861 return ret;
2862 ret++;
2863 }
2864
2865 return -1;
2866 }
2867
2868 void wxListMainWindow::DeleteItem( long index )
2869 {
2870 m_dirty = TRUE;
2871 if (index >= 0 && (size_t)index < m_lines.GetCount())
2872 {
2873 wxListLineData *line = &m_lines[(size_t)index];
2874 if (m_current == line) m_current = (wxListLineData *) NULL;
2875 DeleteLine( line );
2876 m_lines.RemoveAt( (size_t)index );
2877 }
2878 }
2879
2880 void wxListMainWindow::DeleteColumn( int col )
2881 {
2882 wxCHECK_RET( col < (int)m_columns.GetCount(),
2883 wxT("attempting to delete inexistent column in wxListView") );
2884
2885 m_dirty = TRUE;
2886 wxNode *node = m_columns.Nth( col );
2887 if (node) m_columns.DeleteNode( node );
2888 }
2889
2890 void wxListMainWindow::DeleteAllItems()
2891 {
2892 m_dirty = TRUE;
2893 m_current = (wxListLineData *) NULL;
2894
2895 // to make the deletion of all items faster, we don't send the
2896 // notifications in this case: this is compatible with wxMSW and
2897 // documented in DeleteAllItems() description
2898
2899 wxListEvent event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS, GetParent()->GetId() );
2900 event.SetEventObject( GetParent() );
2901 GetParent()->GetEventHandler()->ProcessEvent( event );
2902
2903 m_lines.Clear();
2904 }
2905
2906 void wxListMainWindow::DeleteEverything()
2907 {
2908 DeleteAllItems();
2909
2910 m_columns.Clear();
2911 }
2912
2913 void wxListMainWindow::EnsureVisible( long index )
2914 {
2915 // We have to call this here because the label in
2916 // question might just have been added and no screen
2917 // update taken place.
2918 if (m_dirty) wxYield();
2919
2920 wxListLineData *oldCurrent = m_current;
2921 m_current = (wxListLineData *) NULL;
2922 if (index >= 0 && (size_t)index < m_lines.GetCount())
2923 m_current = &m_lines[(size_t)index];
2924 if (m_current) MoveToFocus();
2925 m_current = oldCurrent;
2926 }
2927
2928 long wxListMainWindow::FindItem(long start, const wxString& str, bool WXUNUSED(partial) )
2929 {
2930 long pos = start;
2931 wxString tmp = str;
2932 if (pos < 0) pos = 0;
2933 for (size_t i = (size_t)pos; i < m_lines.GetCount(); i++)
2934 {
2935 wxListLineData *line = &m_lines[i];
2936 wxString s = "";
2937 line->GetText( 0, s );
2938 if (s == tmp) return pos;
2939 pos++;
2940 }
2941 return -1;
2942 }
2943
2944 long wxListMainWindow::FindItem(long start, long data)
2945 {
2946 long pos = start;
2947 if (pos < 0) pos = 0;
2948 for (size_t i = (size_t)pos; i < m_lines.GetCount(); i++)
2949 {
2950 wxListLineData *line = &m_lines[i];
2951 wxListItem item;
2952 line->GetItem( 0, item );
2953 if (item.m_data == data) return pos;
2954 pos++;
2955 }
2956 return -1;
2957 }
2958
2959 long wxListMainWindow::HitTest( int x, int y, int &flags )
2960 {
2961 CalcUnscrolledPosition( x, y, &x, &y );
2962
2963 int count = 0;
2964 for (size_t i = 0; i < m_lines.GetCount(); i++)
2965 {
2966 wxListLineData *line = &m_lines[i];
2967 long ret = line->IsHit( x, y );
2968 if (ret) // & flags) // No: flags is output-only so may be garbage at this point
2969 {
2970 flags = (int)ret;
2971 return count;
2972 }
2973 count++;
2974 }
2975 return -1;
2976 }
2977
2978 void wxListMainWindow::InsertItem( wxListItem &item )
2979 {
2980 m_dirty = TRUE;
2981 int mode = 0;
2982 if (m_mode & wxLC_REPORT) mode = wxLC_REPORT;
2983 else if (m_mode & wxLC_LIST) mode = wxLC_LIST;
2984 else if (m_mode & wxLC_ICON) mode = wxLC_ICON;
2985 else if (m_mode & wxLC_SMALL_ICON) mode = wxLC_ICON; // no typo
2986
2987 wxListLineData *line = new wxListLineData( this, mode, m_hilightBrush );
2988
2989 if (m_mode & wxLC_REPORT)
2990 {
2991 line->InitItems( GetColumnCount() );
2992 item.m_width = GetColumnWidth( 0 )-3;
2993 }
2994 else
2995 {
2996 line->InitItems( 1 );
2997 }
2998
2999 line->SetItem( 0, item );
3000 if ((item.m_itemId >= 0) && ((size_t)item.m_itemId < m_lines.GetCount()))
3001 {
3002 m_lines.Insert( line, (size_t)item.m_itemId );
3003 }
3004 else
3005 {
3006 m_lines.Add( line );
3007 item.m_itemId = m_lines.GetCount();
3008 }
3009 }
3010
3011 void wxListMainWindow::InsertColumn( long col, wxListItem &item )
3012 {
3013 m_dirty = TRUE;
3014 if (m_mode & wxLC_REPORT)
3015 {
3016 if (item.m_width == wxLIST_AUTOSIZE_USEHEADER) item.m_width = GetTextLength( item.m_text );
3017 wxListHeaderData *column = new wxListHeaderData( item );
3018 if ((col >= 0) && (col < (int)m_columns.GetCount()))
3019 {
3020 wxNode *node = m_columns.Nth( (size_t)col );
3021 if (node)
3022 m_columns.Insert( node, column );
3023 }
3024 else
3025 {
3026 m_columns.Append( column );
3027 }
3028 }
3029 }
3030
3031 wxListCtrlCompare list_ctrl_compare_func_2;
3032 long list_ctrl_compare_data;
3033
3034 int LINKAGEMODE list_ctrl_compare_func_1( wxListLineData **arg1, wxListLineData **arg2 )
3035 {
3036 wxListLineData *line1 = *arg1;
3037 wxListLineData *line2 = *arg2;
3038 wxListItem item;
3039 line1->GetItem( 0, item );
3040 long data1 = item.m_data;
3041 line2->GetItem( 0, item );
3042 long data2 = item.m_data;
3043 return list_ctrl_compare_func_2( data1, data2, list_ctrl_compare_data );
3044 }
3045
3046 void wxListMainWindow::SortItems( wxListCtrlCompare fn, long data )
3047 {
3048 list_ctrl_compare_func_2 = fn;
3049 list_ctrl_compare_data = data;
3050 m_lines.Sort( list_ctrl_compare_func_1 );
3051 m_dirty = TRUE;
3052 }
3053
3054 void wxListMainWindow::OnScroll(wxScrollWinEvent& event)
3055 {
3056 wxScrolledWindow::OnScroll( event ) ;
3057 #if wxUSE_GENERIC_LIST_EXTENSIONS
3058
3059 if (event.GetOrientation() == wxHORIZONTAL && ( m_mode & wxLC_REPORT ))
3060 {
3061 wxListCtrl* lc = wxDynamicCast( GetParent() , wxListCtrl ) ;
3062 if ( lc )
3063 {
3064 lc->m_headerWin->Refresh() ;
3065 #ifdef __WXMAC__
3066 lc->m_headerWin->MacUpdateImmediately() ;
3067 #endif
3068 }
3069 }
3070 #endif
3071 }
3072
3073 // -------------------------------------------------------------------------------------
3074 // wxListItem
3075 // -------------------------------------------------------------------------------------
3076
3077 IMPLEMENT_DYNAMIC_CLASS(wxListItem, wxObject)
3078
3079 wxListItem::wxListItem()
3080 {
3081 m_mask = 0;
3082 m_itemId = 0;
3083 m_col = 0;
3084 m_state = 0;
3085 m_stateMask = 0;
3086 m_image = 0;
3087 m_data = 0;
3088 m_format = wxLIST_FORMAT_CENTRE;
3089 m_width = 0;
3090
3091 m_attr = NULL;
3092 }
3093
3094 void wxListItem::Clear()
3095 {
3096 m_mask = 0;
3097 m_itemId = 0;
3098 m_col = 0;
3099 m_state = 0;
3100 m_stateMask = 0;
3101 m_image = 0;
3102 m_data = 0;
3103 m_format = wxLIST_FORMAT_CENTRE;
3104 m_width = 0;
3105 m_text = wxEmptyString;
3106
3107 if (m_attr) delete m_attr;
3108 m_attr = NULL;
3109 }
3110
3111 void wxListItem::ClearAttributes()
3112 {
3113 if (m_attr) delete m_attr;
3114 m_attr = NULL;
3115 }
3116
3117 // -------------------------------------------------------------------------------------
3118 // wxListEvent
3119 // -------------------------------------------------------------------------------------
3120
3121 IMPLEMENT_DYNAMIC_CLASS(wxListEvent, wxNotifyEvent)
3122
3123 wxListEvent::wxListEvent( wxEventType commandType, int id ):
3124 wxNotifyEvent( commandType, id )
3125 {
3126 m_code = 0;
3127 m_itemIndex = 0;
3128 m_oldItemIndex = 0;
3129 m_col = 0;
3130 m_cancelled = FALSE;
3131 m_pointDrag.x = 0;
3132 m_pointDrag.y = 0;
3133 }
3134
3135 void wxListEvent::CopyObject(wxObject& object_dest) const
3136 {
3137 wxListEvent *obj = (wxListEvent *)&object_dest;
3138
3139 wxNotifyEvent::CopyObject(object_dest);
3140
3141 obj->m_code = m_code;
3142 obj->m_itemIndex = m_itemIndex;
3143 obj->m_oldItemIndex = m_oldItemIndex;
3144 obj->m_col = m_col;
3145 obj->m_cancelled = m_cancelled;
3146 obj->m_pointDrag = m_pointDrag;
3147 obj->m_item.m_mask = m_item.m_mask;
3148 obj->m_item.m_itemId = m_item.m_itemId;
3149 obj->m_item.m_col = m_item.m_col;
3150 obj->m_item.m_state = m_item.m_state;
3151 obj->m_item.m_stateMask = m_item.m_stateMask;
3152 obj->m_item.m_text = m_item.m_text;
3153 obj->m_item.m_image = m_item.m_image;
3154 obj->m_item.m_data = m_item.m_data;
3155 obj->m_item.m_format = m_item.m_format;
3156 obj->m_item.m_width = m_item.m_width;
3157
3158 if ( m_item.HasAttributes() )
3159 {
3160 obj->m_item.SetTextColour(m_item.GetTextColour());
3161 }
3162 }
3163
3164 // -------------------------------------------------------------------------------------
3165 // wxListCtrl
3166 // -------------------------------------------------------------------------------------
3167
3168 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl, wxControl)
3169
3170 BEGIN_EVENT_TABLE(wxListCtrl,wxControl)
3171 EVT_SIZE (wxListCtrl::OnSize)
3172 EVT_IDLE (wxListCtrl::OnIdle)
3173 END_EVENT_TABLE()
3174
3175 wxListCtrl::wxListCtrl()
3176 {
3177 m_imageListNormal = (wxImageList *) NULL;
3178 m_imageListSmall = (wxImageList *) NULL;
3179 m_imageListState = (wxImageList *) NULL;
3180 m_mainWin = (wxListMainWindow*) NULL;
3181 m_headerWin = (wxListHeaderWindow*) NULL;
3182 }
3183
3184 wxListCtrl::~wxListCtrl()
3185 {
3186 }
3187
3188 bool wxListCtrl::Create(wxWindow *parent,
3189 wxWindowID id,
3190 const wxPoint &pos,
3191 const wxSize &size,
3192 long style,
3193 const wxValidator &validator,
3194 const wxString &name)
3195 {
3196 m_imageListNormal = (wxImageList *) NULL;
3197 m_imageListSmall = (wxImageList *) NULL;
3198 m_imageListState = (wxImageList *) NULL;
3199 m_mainWin = (wxListMainWindow*) NULL;
3200 m_headerWin = (wxListHeaderWindow*) NULL;
3201
3202 if ( !(style & (wxLC_REPORT | wxLC_LIST | wxLC_ICON)) )
3203 {
3204 style = style | wxLC_LIST;
3205 }
3206
3207 bool ret = wxControl::Create( parent, id, pos, size, style, validator, name );
3208
3209
3210 if (style & wxSUNKEN_BORDER)
3211 style -= wxSUNKEN_BORDER;
3212
3213 m_mainWin = new wxListMainWindow( this, -1, wxPoint(0,0), size, style );
3214
3215 if (HasFlag(wxLC_REPORT))
3216 {
3217 m_headerWin = new wxListHeaderWindow( this, -1, m_mainWin, wxPoint(0,0), wxSize(size.x,23), wxTAB_TRAVERSAL );
3218 if (HasFlag(wxLC_NO_HEADER))
3219 m_headerWin->Show( FALSE );
3220 }
3221 else
3222 {
3223 m_headerWin = (wxListHeaderWindow *) NULL;
3224 }
3225
3226 return ret;
3227 }
3228
3229 void wxListCtrl::OnSize( wxSizeEvent &WXUNUSED(event) )
3230 {
3231 /* handled in OnIdle */
3232
3233 if (m_mainWin) m_mainWin->m_dirty = TRUE;
3234 }
3235
3236 void wxListCtrl::SetSingleStyle( long style, bool add )
3237 {
3238 long flag = GetWindowStyle();
3239
3240 if (add)
3241 {
3242 if (style & wxLC_MASK_TYPE) flag = flag & ~wxLC_MASK_TYPE;
3243 if (style & wxLC_MASK_ALIGN) flag = flag & ~wxLC_MASK_ALIGN;
3244 if (style & wxLC_MASK_SORT) flag = flag & ~wxLC_MASK_SORT;
3245 }
3246
3247 if (add)
3248 {
3249 flag |= style;
3250 }
3251 else
3252 {
3253 if (flag & style) flag -= style;
3254 }
3255
3256 SetWindowStyleFlag( flag );
3257 }
3258
3259 void wxListCtrl::SetWindowStyleFlag( long flag )
3260 {
3261 if (m_mainWin)
3262 {
3263 m_mainWin->DeleteEverything();
3264
3265 int width = 0;
3266 int height = 0;
3267 GetClientSize( &width, &height );
3268
3269 m_mainWin->SetMode( flag );
3270
3271 if (flag & wxLC_REPORT)
3272 {
3273 if (!HasFlag(wxLC_REPORT))
3274 {
3275 if (!m_headerWin)
3276 {
3277 m_headerWin = new wxListHeaderWindow( this, -1, m_mainWin,
3278 wxPoint(0,0), wxSize(width,23), wxTAB_TRAVERSAL );
3279 if (HasFlag(wxLC_NO_HEADER))
3280 m_headerWin->Show( FALSE );
3281 }
3282 else
3283 {
3284 if (flag & wxLC_NO_HEADER)
3285 m_headerWin->Show( FALSE );
3286 else
3287 m_headerWin->Show( TRUE );
3288 }
3289 }
3290 }
3291 else
3292 {
3293 if (HasFlag(wxLC_REPORT) && !(HasFlag(wxLC_NO_HEADER)))
3294 {
3295 m_headerWin->Show( FALSE );
3296 }
3297 }
3298 }
3299
3300 wxWindow::SetWindowStyleFlag( flag );
3301 }
3302
3303 bool wxListCtrl::GetColumn(int col, wxListItem &item) const
3304 {
3305 m_mainWin->GetColumn( col, item );
3306 return TRUE;
3307 }
3308
3309 bool wxListCtrl::SetColumn( int col, wxListItem& item )
3310 {
3311 m_mainWin->SetColumn( col, item );
3312 return TRUE;
3313 }
3314
3315 int wxListCtrl::GetColumnWidth( int col ) const
3316 {
3317 return m_mainWin->GetColumnWidth( col );
3318 }
3319
3320 bool wxListCtrl::SetColumnWidth( int col, int width )
3321 {
3322 m_mainWin->SetColumnWidth( col, width );
3323 return TRUE;
3324 }
3325
3326 int wxListCtrl::GetCountPerPage() const
3327 {
3328 return m_mainWin->GetCountPerPage(); // different from Windows ?
3329 }
3330
3331 bool wxListCtrl::GetItem( wxListItem &info ) const
3332 {
3333 m_mainWin->GetItem( info );
3334 return TRUE;
3335 }
3336
3337 bool wxListCtrl::SetItem( wxListItem &info )
3338 {
3339 m_mainWin->SetItem( info );
3340 return TRUE;
3341 }
3342
3343 long wxListCtrl::SetItem( long index, int col, const wxString& label, int imageId )
3344 {
3345 wxListItem info;
3346 info.m_text = label;
3347 info.m_mask = wxLIST_MASK_TEXT;
3348 info.m_itemId = index;
3349 info.m_col = col;
3350 if ( imageId > -1 )
3351 {
3352 info.m_image = imageId;
3353 info.m_mask |= wxLIST_MASK_IMAGE;
3354 };
3355 m_mainWin->SetItem(info);
3356 return TRUE;
3357 }
3358
3359 int wxListCtrl::GetItemState( long item, long stateMask ) const
3360 {
3361 return m_mainWin->GetItemState( item, stateMask );
3362 }
3363
3364 bool wxListCtrl::SetItemState( long item, long state, long stateMask )
3365 {
3366 m_mainWin->SetItemState( item, state, stateMask );
3367 return TRUE;
3368 }
3369
3370 bool wxListCtrl::SetItemImage( long item, int image, int WXUNUSED(selImage) )
3371 {
3372 wxListItem info;
3373 info.m_image = image;
3374 info.m_mask = wxLIST_MASK_IMAGE;
3375 info.m_itemId = item;
3376 m_mainWin->SetItem( info );
3377 return TRUE;
3378 }
3379
3380 wxString wxListCtrl::GetItemText( long item ) const
3381 {
3382 wxListItem info;
3383 info.m_itemId = item;
3384 m_mainWin->GetItem( info );
3385 return info.m_text;
3386 }
3387
3388 void wxListCtrl::SetItemText( long item, const wxString &str )
3389 {
3390 wxListItem info;
3391 info.m_mask = wxLIST_MASK_TEXT;
3392 info.m_itemId = item;
3393 info.m_text = str;
3394 m_mainWin->SetItem( info );
3395 }
3396
3397 long wxListCtrl::GetItemData( long item ) const
3398 {
3399 wxListItem info;
3400 info.m_itemId = item;
3401 m_mainWin->GetItem( info );
3402 return info.m_data;
3403 }
3404
3405 bool wxListCtrl::SetItemData( long item, long data )
3406 {
3407 wxListItem info;
3408 info.m_mask = wxLIST_MASK_DATA;
3409 info.m_itemId = item;
3410 info.m_data = data;
3411 m_mainWin->SetItem( info );
3412 return TRUE;
3413 }
3414
3415 bool wxListCtrl::GetItemRect( long item, wxRect &rect, int WXUNUSED(code) ) const
3416 {
3417 m_mainWin->GetItemRect( item, rect );
3418 return TRUE;
3419 }
3420
3421 bool wxListCtrl::GetItemPosition( long item, wxPoint& pos ) const
3422 {
3423 m_mainWin->GetItemPosition( item, pos );
3424 return TRUE;
3425 }
3426
3427 bool wxListCtrl::SetItemPosition( long WXUNUSED(item), const wxPoint& WXUNUSED(pos) )
3428 {
3429 return 0;
3430 }
3431
3432 int wxListCtrl::GetItemCount() const
3433 {
3434 return m_mainWin->GetItemCount();
3435 }
3436
3437 int wxListCtrl::GetColumnCount() const
3438 {
3439 return m_mainWin->GetColumnCount();
3440 }
3441
3442 void wxListCtrl::SetItemSpacing( int spacing, bool isSmall )
3443 {
3444 m_mainWin->SetItemSpacing( spacing, isSmall );
3445 }
3446
3447 int wxListCtrl::GetItemSpacing( bool isSmall ) const
3448 {
3449 return m_mainWin->GetItemSpacing( isSmall );
3450 }
3451
3452 int wxListCtrl::GetSelectedItemCount() const
3453 {
3454 return m_mainWin->GetSelectedItemCount();
3455 }
3456
3457 wxColour wxListCtrl::GetTextColour() const
3458 {
3459 return GetForegroundColour();
3460 }
3461
3462 void wxListCtrl::SetTextColour(const wxColour& col)
3463 {
3464 SetForegroundColour(col);
3465 }
3466
3467 long wxListCtrl::GetTopItem() const
3468 {
3469 return 0;
3470 }
3471
3472 long wxListCtrl::GetNextItem( long item, int geom, int state ) const
3473 {
3474 return m_mainWin->GetNextItem( item, geom, state );
3475 }
3476
3477 wxImageList *wxListCtrl::GetImageList(int which) const
3478 {
3479 if (which == wxIMAGE_LIST_NORMAL)
3480 {
3481 return m_imageListNormal;
3482 }
3483 else if (which == wxIMAGE_LIST_SMALL)
3484 {
3485 return m_imageListSmall;
3486 }
3487 else if (which == wxIMAGE_LIST_STATE)
3488 {
3489 return m_imageListState;
3490 }
3491 return (wxImageList *) NULL;
3492 }
3493
3494 void wxListCtrl::SetImageList( wxImageList *imageList, int which )
3495 {
3496 m_mainWin->SetImageList( imageList, which );
3497 }
3498
3499 bool wxListCtrl::Arrange( int WXUNUSED(flag) )
3500 {
3501 return 0;
3502 }
3503
3504 bool wxListCtrl::DeleteItem( long item )
3505 {
3506 m_mainWin->DeleteItem( item );
3507 return TRUE;
3508 }
3509
3510 bool wxListCtrl::DeleteAllItems()
3511 {
3512 m_mainWin->DeleteAllItems();
3513 return TRUE;
3514 }
3515
3516 bool wxListCtrl::DeleteAllColumns()
3517 {
3518 for ( size_t n = 0; n < m_mainWin->m_columns.GetCount(); n++ )
3519 DeleteColumn(n);
3520
3521 return TRUE;
3522 }
3523
3524 void wxListCtrl::ClearAll()
3525 {
3526 m_mainWin->DeleteEverything();
3527 }
3528
3529 bool wxListCtrl::DeleteColumn( int col )
3530 {
3531 m_mainWin->DeleteColumn( col );
3532 return TRUE;
3533 }
3534
3535 void wxListCtrl::Edit( long item )
3536 {
3537 m_mainWin->Edit( item );
3538 }
3539
3540 bool wxListCtrl::EnsureVisible( long item )
3541 {
3542 m_mainWin->EnsureVisible( item );
3543 return TRUE;
3544 }
3545
3546 long wxListCtrl::FindItem( long start, const wxString& str, bool partial )
3547 {
3548 return m_mainWin->FindItem( start, str, partial );
3549 }
3550
3551 long wxListCtrl::FindItem( long start, long data )
3552 {
3553 return m_mainWin->FindItem( start, data );
3554 }
3555
3556 long wxListCtrl::FindItem( long WXUNUSED(start), const wxPoint& WXUNUSED(pt),
3557 int WXUNUSED(direction))
3558 {
3559 return 0;
3560 }
3561
3562 long wxListCtrl::HitTest( const wxPoint &point, int &flags )
3563 {
3564 return m_mainWin->HitTest( (int)point.x, (int)point.y, flags );
3565 }
3566
3567 long wxListCtrl::InsertItem( wxListItem& info )
3568 {
3569 m_mainWin->InsertItem( info );
3570 return info.m_itemId;
3571 }
3572
3573 long wxListCtrl::InsertItem( long index, const wxString &label )
3574 {
3575 wxListItem info;
3576 info.m_text = label;
3577 info.m_mask = wxLIST_MASK_TEXT;
3578 info.m_itemId = index;
3579 return InsertItem( info );
3580 }
3581
3582 long wxListCtrl::InsertItem( long index, int imageIndex )
3583 {
3584 wxListItem info;
3585 info.m_mask = wxLIST_MASK_IMAGE;
3586 info.m_image = imageIndex;
3587 info.m_itemId = index;
3588 return InsertItem( info );
3589 }
3590
3591 long wxListCtrl::InsertItem( long index, const wxString &label, int imageIndex )
3592 {
3593 wxListItem info;
3594 info.m_text = label;
3595 info.m_image = imageIndex;
3596 info.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_IMAGE;
3597 info.m_itemId = index;
3598 return InsertItem( info );
3599 }
3600
3601 long wxListCtrl::InsertColumn( long col, wxListItem &item )
3602 {
3603 wxASSERT( m_headerWin );
3604 m_mainWin->InsertColumn( col, item );
3605 m_headerWin->Refresh();
3606
3607 return 0;
3608 }
3609
3610 long wxListCtrl::InsertColumn( long col, const wxString &heading,
3611 int format, int width )
3612 {
3613 wxListItem item;
3614 item.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_FORMAT;
3615 item.m_text = heading;
3616 if (width >= -2)
3617 {
3618 item.m_mask |= wxLIST_MASK_WIDTH;
3619 item.m_width = width;
3620 }
3621 item.m_format = format;
3622
3623 return InsertColumn( col, item );
3624 }
3625
3626 bool wxListCtrl::ScrollList( int WXUNUSED(dx), int WXUNUSED(dy) )
3627 {
3628 return 0;
3629 }
3630
3631 // Sort items.
3632 // fn is a function which takes 3 long arguments: item1, item2, data.
3633 // item1 is the long data associated with a first item (NOT the index).
3634 // item2 is the long data associated with a second item (NOT the index).
3635 // data is the same value as passed to SortItems.
3636 // The return value is a negative number if the first item should precede the second
3637 // item, a positive number of the second item should precede the first,
3638 // or zero if the two items are equivalent.
3639 // data is arbitrary data to be passed to the sort function.
3640
3641 bool wxListCtrl::SortItems( wxListCtrlCompare fn, long data )
3642 {
3643 m_mainWin->SortItems( fn, data );
3644 return TRUE;
3645 }
3646
3647 void wxListCtrl::OnIdle( wxIdleEvent &WXUNUSED(event) )
3648 {
3649 if (!m_mainWin->m_dirty) return;
3650
3651 int cw = 0;
3652 int ch = 0;
3653 GetClientSize( &cw, &ch );
3654
3655 int x = 0;
3656 int y = 0;
3657 int w = 0;
3658 int h = 0;
3659
3660 if (HasFlag(wxLC_REPORT) && !HasFlag(wxLC_NO_HEADER))
3661 {
3662 m_headerWin->GetPosition( &x, &y );
3663 m_headerWin->GetSize( &w, &h );
3664 if ((x != 0) || (y != 0) || (w != cw) || (h != 23))
3665 m_headerWin->SetSize( 0, 0, cw, 23 );
3666
3667 m_mainWin->GetPosition( &x, &y );
3668 m_mainWin->GetSize( &w, &h );
3669 if ((x != 0) || (y != 24) || (w != cw) || (h != ch-24))
3670 m_mainWin->SetSize( 0, 24, cw, ch-24 );
3671 }
3672 else
3673 {
3674 m_mainWin->GetPosition( &x, &y );
3675 m_mainWin->GetSize( &w, &h );
3676 if ((x != 0) || (y != 24) || (w != cw) || (h != ch))
3677 m_mainWin->SetSize( 0, 0, cw, ch );
3678 }
3679
3680 m_mainWin->CalculatePositions();
3681 m_mainWin->RealizeChanges();
3682 m_mainWin->m_dirty = FALSE;
3683 m_mainWin->Refresh();
3684
3685 if ( m_headerWin && m_headerWin->m_dirty )
3686 {
3687 m_headerWin->m_dirty = FALSE;
3688 m_headerWin->Refresh();
3689 }
3690 }
3691
3692 bool wxListCtrl::SetBackgroundColour( const wxColour &colour )
3693 {
3694 if (m_mainWin)
3695 {
3696 m_mainWin->SetBackgroundColour( colour );
3697 m_mainWin->m_dirty = TRUE;
3698 }
3699
3700 return TRUE;
3701 }
3702
3703 bool wxListCtrl::SetForegroundColour( const wxColour &colour )
3704 {
3705 if ( !wxWindow::SetForegroundColour( colour ) )
3706 return FALSE;
3707
3708 if (m_mainWin)
3709 {
3710 m_mainWin->SetForegroundColour( colour );
3711 m_mainWin->m_dirty = TRUE;
3712 }
3713
3714 if (m_headerWin)
3715 {
3716 m_headerWin->SetForegroundColour( colour );
3717 }
3718
3719 return TRUE;
3720 }
3721
3722 bool wxListCtrl::SetFont( const wxFont &font )
3723 {
3724 if ( !wxWindow::SetFont( font ) )
3725 return FALSE;
3726
3727 if (m_mainWin)
3728 {
3729 m_mainWin->SetFont( font );
3730 m_mainWin->m_dirty = TRUE;
3731 }
3732
3733 if (m_headerWin)
3734 {
3735 m_headerWin->SetFont( font );
3736 }
3737
3738 return TRUE;
3739 }
3740
3741 #if wxUSE_DRAG_AND_DROP
3742
3743 void wxListCtrl::SetDropTarget( wxDropTarget *dropTarget )
3744 {
3745 m_mainWin->SetDropTarget( dropTarget );
3746 }
3747
3748 wxDropTarget *wxListCtrl::GetDropTarget() const
3749 {
3750 return m_mainWin->GetDropTarget();
3751 }
3752
3753 #endif // wxUSE_DRAG_AND_DROP
3754
3755 bool wxListCtrl::SetCursor( const wxCursor &cursor )
3756 {
3757 return m_mainWin ? m_mainWin->wxWindow::SetCursor(cursor) : FALSE;
3758 }
3759
3760 wxColour wxListCtrl::GetBackgroundColour() const
3761 {
3762 return m_mainWin ? m_mainWin->GetBackgroundColour() : wxColour();
3763 }
3764
3765 wxColour wxListCtrl::GetForegroundColour() const
3766 {
3767 return m_mainWin ? m_mainWin->GetForegroundColour() : wxColour();
3768 }
3769
3770 bool wxListCtrl::DoPopupMenu( wxMenu *menu, int x, int y )
3771 {
3772 return m_mainWin->PopupMenu( menu, x, y );
3773 }
3774
3775 void wxListCtrl::SetFocus()
3776 {
3777 /* The test in window.cpp fails as we are a composite
3778 window, so it checks against "this", but not m_mainWin. */
3779 if ( FindFocus() != this )
3780 m_mainWin->SetFocus();
3781 }