]> git.saurik.com Git - wxWidgets.git/blob - src/generic/listctrl.cpp
Fixed optical bug in wxListCtrl,
[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 #endif
13
14 // For compilers that support precompilation, includes "wx.h".
15 #include "wx/wxprec.h"
16
17 #ifdef __BORLANDC__
18 #pragma hdrstop
19 #endif
20
21 #include "wx/dcscreen.h"
22 #include "wx/app.h"
23 #include "wx/listctrl.h"
24 #include "wx/generic/imaglist.h"
25
26 //-----------------------------------------------------------------------------
27 // wxListItemData
28 //-----------------------------------------------------------------------------
29
30 IMPLEMENT_DYNAMIC_CLASS(wxListItemData,wxObject);
31
32 wxListItemData::wxListItemData()
33 {
34 m_image = -1;
35 m_data = 0;
36 m_xpos = 0;
37 m_ypos = 0;
38 m_width = 0;
39 m_height = 0;
40 m_colour = wxBLACK;
41 }
42
43 wxListItemData::wxListItemData( const wxListItem &info )
44 {
45 m_image = -1;
46 m_data = 0;
47 m_colour = info.m_colour;
48 SetItem( info );
49 }
50
51 void wxListItemData::SetItem( const wxListItem &info )
52 {
53 if (info.m_mask & wxLIST_MASK_TEXT) m_text = info.m_text;
54 if (info.m_mask & wxLIST_MASK_IMAGE) m_image = info.m_image;
55 if (info.m_mask & wxLIST_MASK_DATA) m_data = info.m_data;
56 m_colour = info.m_colour;
57 m_xpos = 0;
58 m_ypos = 0;
59 m_width = info.m_width;
60 m_height = 0;
61 }
62
63 void wxListItemData::SetText( const wxString &s )
64 {
65 m_text = s;
66 }
67
68 void wxListItemData::SetImage( int image )
69 {
70 m_image = image;
71 }
72
73 void wxListItemData::SetData( long data )
74 {
75 m_data = data;
76 }
77
78 void wxListItemData::SetPosition( int x, int y )
79 {
80 m_xpos = x;
81 m_ypos = y;
82 }
83
84 void wxListItemData::SetSize( int width, int height )
85 {
86 if (width != -1) m_width = width;
87 if (height != -1) m_height = height;
88 }
89
90 void wxListItemData::SetColour( wxColour *col )
91 {
92 m_colour = col;
93 }
94
95 bool wxListItemData::HasImage() const
96 {
97 return (m_image >= 0);
98 }
99
100 bool wxListItemData::HasText() const
101 {
102 return (!m_text.IsNull());
103 }
104
105 bool wxListItemData::IsHit( int x, int y ) const
106 {
107 return ((x >= m_xpos) && (x <= m_xpos+m_width) && (y >= m_ypos) && (y <= m_ypos+m_height));
108 }
109
110 void wxListItemData::GetText( wxString &s )
111 {
112 s = m_text;
113 }
114
115 int wxListItemData::GetX() const
116 {
117 return m_xpos;
118 }
119
120 int wxListItemData::GetY() const
121 {
122 return m_ypos;
123 }
124
125 int wxListItemData::GetWidth() const
126 {
127 return m_width;
128 }
129
130 int wxListItemData::GetHeight() const
131 {
132 return m_height;
133 }
134
135 int wxListItemData::GetImage() const
136 {
137 return m_image;
138 }
139
140 void wxListItemData::GetItem( wxListItem &info )
141 {
142 info.m_text = m_text;
143 info.m_image = m_image;
144 info.m_data = m_data;
145 info.m_colour = m_colour;
146 }
147
148 wxColour *wxListItemData::GetColour()
149 {
150 return m_colour;
151 }
152
153 //-----------------------------------------------------------------------------
154 // wxListHeaderData
155 //-----------------------------------------------------------------------------
156
157 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderData,wxObject);
158
159 wxListHeaderData::wxListHeaderData()
160 {
161 m_mask = 0;
162 m_image = 0;
163 m_format = 0;
164 m_width = 0;
165 m_xpos = 0;
166 m_ypos = 0;
167 m_height = 0;
168 }
169
170 wxListHeaderData::wxListHeaderData( const wxListItem &item )
171 {
172 SetItem( item );
173 m_xpos = 0;
174 m_ypos = 0;
175 m_height = 0;
176 }
177
178 void wxListHeaderData::SetItem( const wxListItem &item )
179 {
180 m_mask = item.m_mask;
181 m_text = item.m_text;
182 m_image = item.m_image;
183 m_format = item.m_format;
184 m_width = item.m_width;
185 if (m_width < 0) m_width = 80;
186 if (m_width < 6) m_width = 6;
187 }
188
189 void wxListHeaderData::SetPosition( int x, int y )
190 {
191 m_xpos = x;
192 m_ypos = y;
193 }
194
195 void wxListHeaderData::SetHeight( int h )
196 {
197 m_height = h;
198 }
199
200 void wxListHeaderData::SetWidth( int w )
201 {
202 m_width = w;
203 if (m_width < 0) m_width = 80;
204 if (m_width < 6) m_width = 6;
205 }
206
207 void wxListHeaderData::SetFormat( int format )
208 {
209 m_format = format;
210 }
211
212 bool wxListHeaderData::HasImage() const
213 {
214 return (m_image != 0);
215 }
216
217 bool wxListHeaderData::HasText() const
218 {
219 return (m_text.Length() > 0);
220 }
221
222 bool wxListHeaderData::IsHit( int x, int y ) const
223 {
224 return ((x >= m_xpos) && (x <= m_xpos+m_width) && (y >= m_ypos) && (y <= m_ypos+m_height));
225 }
226
227 void wxListHeaderData::GetItem( wxListItem &item )
228 {
229 item.m_mask = m_mask;
230 item.m_text = m_text;
231 item.m_image = m_image;
232 item.m_format = m_format;
233 item.m_width = m_width;
234 }
235
236 void wxListHeaderData::GetText( wxString &s )
237 {
238 s = m_text;
239 }
240
241 int wxListHeaderData::GetImage() const
242 {
243 return m_image;
244 }
245
246 int wxListHeaderData::GetWidth() const
247 {
248 return m_width;
249 }
250
251 int wxListHeaderData::GetFormat() const
252 {
253 return m_format;
254 }
255
256 //-----------------------------------------------------------------------------
257 // wxListLineData
258 //-----------------------------------------------------------------------------
259
260 IMPLEMENT_DYNAMIC_CLASS(wxListLineData,wxObject);
261
262 wxListLineData::wxListLineData( wxListMainWindow *owner, int mode, wxBrush *hilightBrush )
263 {
264 m_mode = mode;
265 m_hilighted = FALSE;
266 m_owner = owner;
267 m_hilightBrush = hilightBrush;
268 m_items.DeleteContents( TRUE );
269 m_spacing = 0;
270 }
271
272 void wxListLineData::CalculateSize( wxDC *dc, int spacing )
273 {
274 m_spacing = spacing;
275 switch (m_mode)
276 {
277 case wxLC_ICON:
278 {
279 m_bound_all.width = m_spacing;
280 m_bound_all.height = m_spacing+13;
281 wxNode *node = m_items.First();
282 if (node)
283 {
284 wxListItemData *item = (wxListItemData*)node->Data();
285 wxString s;
286 item->GetText( s );
287 long lw,lh;
288 dc->GetTextExtent( s, &lw, &lh );
289 if (lw > m_spacing) m_bound_all.width = lw;
290 }
291 break;
292 }
293 case wxLC_LIST:
294 {
295 wxNode *node = m_items.First();
296 if (node)
297 {
298 wxListItemData *item = (wxListItemData*)node->Data();
299 wxString s;
300 item->GetText( s );
301 long lw,lh;
302 dc->GetTextExtent( s, &lw, &lh );
303 m_bound_all.width = lw;
304 m_bound_all.height = lh;
305 if (item->HasImage())
306 {
307 int w = 0;
308 int h = 0;
309 m_owner->GetImageSize( item->GetImage(), w, h );
310 m_bound_all.width += 4 + w;
311 if (h > m_bound_all.height) m_bound_all.height = h;
312 }
313 }
314 break;
315 }
316 case wxLC_REPORT:
317 {
318 m_bound_all.width = 0;
319 m_bound_all.height = 0;
320 wxNode *node = m_items.First();
321 while (node)
322 {
323 wxListItemData *item = (wxListItemData*)node->Data();
324 wxString s;
325 item->GetText( s );
326 if (s.IsNull()) s = "H";
327 long lh;
328 dc->GetTextExtent( s, (long*) NULL, &lh );
329 item->SetSize( item->GetWidth(), lh );
330 m_bound_all.height = lh;
331 node = node->Next();
332 }
333 break;
334 }
335 }
336 }
337
338 void wxListLineData::SetPosition( wxDC *dc, int x, int y, int window_width )
339 {
340 m_bound_all.x = x;
341 m_bound_all.y = y;
342 switch (m_mode)
343 {
344 case wxLC_ICON:
345 {
346 AssignRect( m_bound_icon, 0, 0, 0, 0 );
347 AssignRect( m_bound_label, 0, 0, 0, 0 );
348 AssignRect( m_bound_hilight, m_bound_all );
349 wxNode *node = m_items.First();
350 if (node)
351 {
352 wxListItemData *item = (wxListItemData*)node->Data();
353 if (item->HasImage())
354 {
355 wxListItemData *item = (wxListItemData*)node->Data();
356 int w = 0;
357 int h = 0;
358 m_owner->GetImageSize( item->GetImage(), w, h );
359 m_bound_icon.x = m_bound_all.x + (m_spacing/2) - (w/2);
360 m_bound_icon.y = m_bound_all.y + m_spacing - h - 5;
361 m_bound_icon.width = w;
362 m_bound_icon.height = h;
363 if (!item->HasText())
364 {
365 AssignRect( m_bound_hilight, m_bound_icon );
366 m_bound_hilight.x -= 5;
367 m_bound_hilight.y -= 5;
368 m_bound_hilight.width += 9;
369 m_bound_hilight.height += 9;
370 }
371 }
372 if (item->HasText())
373 {
374 wxString s;
375 item->GetText( s );
376 long lw,lh;
377 dc->GetTextExtent( s, &lw, &lh );
378 if (m_bound_all.width > m_spacing)
379 m_bound_label.x = m_bound_all.x;
380 else
381 m_bound_label.x = m_bound_all.x + (m_spacing/2) - lw/2;
382 m_bound_label.y = m_bound_all.y + m_bound_all.height - lh;
383 m_bound_label.width = lw;
384 m_bound_label.height = lh;
385 AssignRect( m_bound_hilight, m_bound_label );
386 m_bound_hilight.x -= 2;
387 m_bound_hilight.y -= 2;
388 m_bound_hilight.width += 4;
389 m_bound_hilight.height += 4;
390 }
391 }
392 break;
393 }
394 case wxLC_LIST:
395 {
396 AssignRect( m_bound_label, m_bound_all );
397 m_bound_all.x -= 2;
398 m_bound_all.y -= 2;
399 m_bound_all.width += 4;
400 m_bound_all.height += 3;
401 AssignRect( m_bound_hilight, m_bound_all );
402 AssignRect( m_bound_icon, 0, 0, 0, 0 );
403 wxNode *node = m_items.First();
404 if (node)
405 {
406 wxListItemData *item = (wxListItemData*)node->Data();
407 if (item->HasImage())
408 {
409 m_bound_icon.x = m_bound_all.x + 2;
410 m_bound_icon.y = m_bound_all.y + 2;
411 int w;
412 int h;
413 m_owner->GetImageSize( item->GetImage(), w, h );
414 m_bound_icon.width = w;
415 m_bound_icon.height = h;
416 m_bound_label.x += 4 + w;
417 m_bound_label.width -= 4 + w;
418 }
419 }
420 break;
421 }
422 case wxLC_REPORT:
423 {
424 long lw,lh;
425 dc->GetTextExtent( "H", &lw, &lh );
426 m_bound_all.x = 0;
427 m_bound_all.y -= 0;
428 m_bound_all.height = lh+3;
429 m_bound_all.width = window_width;
430 AssignRect( m_bound_hilight, m_bound_all );
431 AssignRect( m_bound_label, m_bound_all );
432 AssignRect( m_bound_icon, 0, 0, 0, 0 );
433 wxNode *node = m_items.First();
434 if (node)
435 {
436 wxListItemData *item = (wxListItemData*)node->Data();
437 wxString s;
438 item->GetText( s );
439 if (s.IsEmpty()) s = wxT("H");
440 long lw,lh;
441 dc->GetTextExtent( s, &lw, &lh );
442 m_bound_label.width = lw;
443 m_bound_label.height = lh;
444 if (item->HasImage())
445 {
446 m_bound_icon.x = m_bound_all.x + 2;
447 m_bound_icon.y = m_bound_all.y + 2;
448 int w;
449 int h;
450 m_owner->GetImageSize( item->GetImage(), w, h );
451 m_bound_icon.width = w;
452 m_bound_icon.height = h;
453 m_bound_label.x += 4 + w;
454 }
455 }
456 break;
457 }
458 }
459 }
460
461 void wxListLineData::SetColumnPosition( int index, int x )
462 {
463 int i = index;
464 wxNode *node = m_items.Nth( i );
465 if (node)
466 {
467 wxListItemData *item = (wxListItemData*)node->Data();
468 item->SetPosition( x, m_bound_all.y+1 );
469 }
470 }
471
472 void wxListLineData::GetSize( int &width, int &height )
473 {
474 width = m_bound_all.width;
475 height = m_bound_all.height;
476 }
477
478 void wxListLineData::GetExtent( int &x, int &y, int &width, int &height )
479 {
480 x = m_bound_all.x;
481 y = m_bound_all.y;
482 width = m_bound_all.width;
483 height = m_bound_all.height;
484 }
485
486 void wxListLineData::GetLabelExtent( int &x, int &y, int &width, int &height )
487 {
488 x = m_bound_label.x;
489 y = m_bound_label.y;
490 width = m_bound_label.width;
491 height = m_bound_label.height;
492 }
493
494 void wxListLineData::GetRect( wxRect &rect )
495 {
496 AssignRect( rect, m_bound_all );
497 }
498
499 long wxListLineData::IsHit( int x, int y )
500 {
501 wxNode *node = m_items.First();
502 if (node)
503 {
504 wxListItemData *item = (wxListItemData*)node->Data();
505 if (item->HasImage() && IsInRect( x, y, m_bound_icon )) return wxLIST_HITTEST_ONITEMICON;
506 if (item->HasText() && IsInRect( x, y, m_bound_label )) return wxLIST_HITTEST_ONITEMLABEL;
507 // if (!(item->HasImage() || item->HasText())) return 0;
508 }
509 // if there is no icon or text = empty
510 if (IsInRect( x, y, m_bound_all )) return wxLIST_HITTEST_ONITEMICON;
511 return 0;
512 }
513
514 void wxListLineData::InitItems( int num )
515 {
516 for (int i = 0; i < num; i++) m_items.Append( new wxListItemData() );
517 }
518
519 void wxListLineData::SetItem( int index, const wxListItem &info )
520 {
521 wxNode *node = m_items.Nth( index );
522 if (node)
523 {
524 wxListItemData *item = (wxListItemData*)node->Data();
525 item->SetItem( info );
526 }
527 }
528
529 void wxListLineData::GetItem( int index, wxListItem &info )
530 {
531 int i = index;
532 wxNode *node = m_items.Nth( i );
533 if (node)
534 {
535 wxListItemData *item = (wxListItemData*)node->Data();
536 item->GetItem( info );
537 }
538 }
539
540 void wxListLineData::GetText( int index, wxString &s )
541 {
542 int i = index;
543 wxNode *node = m_items.Nth( i );
544 s = "";
545 if (node)
546 {
547 wxListItemData *item = (wxListItemData*)node->Data();
548 item->GetText( s );
549 }
550 }
551
552 void wxListLineData::SetText( int index, const wxString s )
553 {
554 int i = index;
555 wxNode *node = m_items.Nth( i );
556 if (node)
557 {
558 wxListItemData *item = (wxListItemData*)node->Data();
559 item->SetText( s );
560 }
561 }
562
563 int wxListLineData::GetImage( int index )
564 {
565 int i = index;
566 wxNode *node = m_items.Nth( i );
567 if (node)
568 {
569 wxListItemData *item = (wxListItemData*)node->Data();
570 return item->GetImage();
571 }
572 return -1;
573 }
574
575 void wxListLineData::DoDraw( wxDC *dc, bool hilight, bool paintBG )
576 {
577 long dev_x = dc->LogicalToDeviceX( m_bound_all.x-2 );
578 long dev_y = dc->LogicalToDeviceY( m_bound_all.y-2 );
579 long dev_w = dc->LogicalToDeviceXRel( m_bound_all.width+4 );
580 long dev_h = dc->LogicalToDeviceYRel( m_bound_all.height+4 );
581
582 if (!m_owner->IsExposed( dev_x, dev_y, dev_w, dev_h ))
583 {
584 return;
585 }
586
587 if (paintBG)
588 {
589 if (hilight)
590 {
591 dc->SetBrush( * m_hilightBrush );
592 dc->SetPen( * wxTRANSPARENT_PEN );
593 }
594 else
595 {
596 dc->SetBrush( * wxWHITE_BRUSH );
597 dc->SetPen( * wxTRANSPARENT_PEN );
598 }
599 dc->DrawRectangle( m_bound_hilight.x, m_bound_hilight.y,
600 m_bound_hilight.width, m_bound_hilight.height );
601 }
602
603 dc->SetBackgroundMode(wxTRANSPARENT);
604 if (m_mode == wxLC_REPORT)
605 {
606 wxString s;
607 wxNode *node = m_items.First();
608 while (node)
609 {
610 wxListItemData *item = (wxListItemData*)node->Data();
611 dc->SetClippingRegion( item->GetX(), item->GetY(), item->GetWidth()-3, item->GetHeight() );
612 int x = item->GetX();
613 if (item->HasImage())
614 {
615 int y = 0;
616 m_owner->DrawImage( item->GetImage(), dc, x, item->GetY() );
617 m_owner->GetImageSize( item->GetImage(), x, y );
618 x += item->GetX() + 5;
619 }
620 if (item->HasText())
621 {
622 item->GetText( s );
623 if (hilight)
624 dc->SetTextForeground( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT ) );
625 else
626 dc->SetTextForeground( *item->GetColour() );
627 dc->DrawText( s, x, item->GetY() );
628 }
629 dc->DestroyClippingRegion();
630 node = node->Next();
631 }
632 }
633 else
634 {
635 wxNode *node = m_items.First();
636 if (node)
637 {
638 wxListItemData *item = (wxListItemData*)node->Data();
639 if (item->HasImage())
640 {
641 m_owner->DrawImage( item->GetImage(), dc, m_bound_icon.x, m_bound_icon.y );
642 }
643 if (item->HasText())
644 {
645 wxString s;
646 item->GetText( s );
647 if (hilight)
648 dc->SetTextForeground( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT ) );
649 else
650 dc->SetTextForeground( * item->GetColour() );
651 dc->DrawText( s, m_bound_label.x, m_bound_label.y );
652 }
653 }
654 }
655 }
656
657 void wxListLineData::Hilight( bool on )
658 {
659 if (on == m_hilighted) return;
660 if (on)
661 m_owner->SelectLine( this );
662 else
663 m_owner->DeselectLine( this );
664 m_hilighted = on;
665 }
666
667 void wxListLineData::ReverseHilight( void )
668 {
669 m_hilighted = !m_hilighted;
670 if (m_hilighted)
671 m_owner->SelectLine( this );
672 else
673 m_owner->DeselectLine( this );
674 }
675
676 void wxListLineData::DrawRubberBand( wxDC *dc, bool on )
677 {
678 if (on)
679 {
680 dc->SetPen( * wxBLACK_PEN );
681 dc->SetBrush( * wxTRANSPARENT_BRUSH );
682 dc->DrawRectangle( m_bound_hilight.x, m_bound_hilight.y,
683 m_bound_hilight.width, m_bound_hilight.height );
684 }
685 }
686
687 void wxListLineData::Draw( wxDC *dc )
688 {
689 DoDraw( dc, m_hilighted, m_hilighted );
690 }
691
692 bool wxListLineData::IsInRect( int x, int y, const wxRect &rect )
693 {
694 return ((x >= rect.x) && (x <= rect.x+rect.width) &&
695 (y >= rect.y) && (y <= rect.y+rect.height));
696 }
697
698 bool wxListLineData::IsHilighted( void )
699 {
700 return m_hilighted;
701 }
702
703 void wxListLineData::AssignRect( wxRect &dest, int x, int y, int width, int height )
704 {
705 dest.x = x;
706 dest.y = y;
707 dest.width = width;
708 dest.height = height;
709 }
710
711 void wxListLineData::AssignRect( wxRect &dest, const wxRect &source )
712 {
713 dest.x = source.x;
714 dest.y = source.y;
715 dest.width = source.width;
716 dest.height = source.height;
717 }
718
719 //-----------------------------------------------------------------------------
720 // wxListHeaderWindow
721 //-----------------------------------------------------------------------------
722
723 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow,wxWindow);
724
725 BEGIN_EVENT_TABLE(wxListHeaderWindow,wxWindow)
726 EVT_PAINT (wxListHeaderWindow::OnPaint)
727 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse)
728 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus)
729 END_EVENT_TABLE()
730
731 wxListHeaderWindow::wxListHeaderWindow( void )
732 {
733 m_owner = (wxListMainWindow *) NULL;
734 m_currentCursor = (wxCursor *) NULL;
735 m_resizeCursor = (wxCursor *) NULL;
736 m_isDragging = FALSE;
737 }
738
739 wxListHeaderWindow::wxListHeaderWindow( wxWindow *win, wxWindowID id, wxListMainWindow *owner,
740 const wxPoint &pos, const wxSize &size,
741 long style, const wxString &name ) :
742 wxWindow( win, id, pos, size, style, name )
743 {
744 m_owner = owner;
745 // m_currentCursor = wxSTANDARD_CURSOR;
746 m_currentCursor = (wxCursor *) NULL;
747 m_resizeCursor = new wxCursor( wxCURSOR_SIZEWE );
748 m_isDragging = FALSE;
749 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE ) );
750 }
751
752 wxListHeaderWindow::~wxListHeaderWindow( void )
753 {
754 delete m_resizeCursor;
755 }
756
757 void wxListHeaderWindow::DoDrawRect( wxDC *dc, int x, int y, int w, int h )
758 {
759 const int m_corner = 1;
760
761 dc->SetBrush( *wxTRANSPARENT_BRUSH );
762
763 dc->SetPen( *wxBLACK_PEN );
764 dc->DrawLine( x+w-m_corner+1, y, x+w, y+h ); // right (outer)
765 dc->DrawRectangle( x, y+h, w+1, 1 ); // bottom (outer)
766
767 wxPen pen( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNSHADOW ), 1, wxSOLID );
768
769 dc->SetPen( pen );
770 dc->DrawLine( x+w-m_corner, y, x+w-1, y+h ); // right (inner)
771 dc->DrawRectangle( x+1, y+h-1, w-2, 1 ); // bottom (inner)
772
773 dc->SetPen( *wxWHITE_PEN );
774 dc->DrawRectangle( x, y, w-m_corner+1, 1 ); // top (outer)
775 dc->DrawRectangle( x, y, 1, h ); // left (outer)
776 dc->DrawLine( x, y+h-1, x+1, y+h-1 );
777 dc->DrawLine( x+w-1, y, x+w-1, y+1 );
778 }
779
780 void wxListHeaderWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
781 {
782 wxPaintDC dc( this );
783 PrepareDC( dc );
784
785 dc.BeginDrawing();
786
787 dc.SetFont( GetFont() );
788
789 int w = 0;
790 int h = 0;
791 int x = 0;
792 int y = 0;
793 GetClientSize( &w, &h );
794
795 dc.SetBackgroundMode(wxTRANSPARENT);
796 dc.SetTextForeground( *wxBLACK );
797 if (m_foregroundColour.Ok()) dc.SetTextForeground( m_foregroundColour );
798
799 x = 1;
800 y = 1;
801 int numColumns = m_owner->GetColumnCount();
802 wxListItem item;
803 for (int i = 0; i < numColumns; i++)
804 {
805 m_owner->GetColumn( i, item );
806 int cw = item.m_width-2;
807 if ((i+1 == numColumns) || (x+item.m_width > w-5)) cw = w-x-1;
808 dc.SetPen( *wxWHITE_PEN );
809
810 DoDrawRect( &dc, x, y, cw, h-2 );
811 dc.SetClippingRegion( x, y, cw-5, h-4 );
812 dc.DrawText( item.m_text, x+4, y+3 );
813 dc.DestroyClippingRegion();
814 x += item.m_width;
815 if (x > w+5) break;
816 }
817 dc.EndDrawing();
818 }
819
820 void wxListHeaderWindow::DrawCurrent()
821 {
822 int x1 = m_currentX;
823 int y1 = 0;
824 int x2 = m_currentX-1;
825 int y2 = 0;
826 int dummy;
827 m_owner->GetClientSize( &dummy, &y2 );
828 ClientToScreen( &x1, &y1 );
829 m_owner->ClientToScreen( &x2, &y2 );
830
831 wxScreenDC dc;
832 dc.SetLogicalFunction( wxINVERT );
833 dc.SetPen( wxPen( *wxBLACK, 2, wxSOLID ) );
834 dc.SetBrush( *wxTRANSPARENT_BRUSH );
835
836 dc.DrawLine( x1, y1, x2, y2 );
837
838 dc.SetLogicalFunction( wxCOPY );
839
840 dc.SetPen( wxNullPen );
841 dc.SetBrush( wxNullBrush );
842 }
843
844 void wxListHeaderWindow::OnMouse( wxMouseEvent &event )
845 {
846 int x = event.GetX();
847 int y = event.GetY();
848 if (m_isDragging)
849 {
850 DrawCurrent();
851 if (event.ButtonUp())
852 {
853 ReleaseMouse();
854 m_isDragging = FALSE;
855 m_owner->SetColumnWidth( m_column, m_currentX-m_minX );
856 }
857 else
858 {
859 int size_x = 0;
860 int dummy;
861 GetClientSize( &size_x, & dummy );
862 if (x > m_minX+7)
863 m_currentX = x;
864 else
865 m_currentX = m_minX+7;
866 if (m_currentX > size_x-7) m_currentX = size_x-7;
867 DrawCurrent();
868 }
869 return;
870 }
871
872 m_minX = 0;
873 bool hit_border = FALSE;
874 int xpos = 0;
875 for (int j = 0; j < m_owner->GetColumnCount()-1; j++)
876 {
877 xpos += m_owner->GetColumnWidth( j );
878 m_column = j;
879 if ((abs(x-xpos) < 3) && (y < 22))
880 {
881 hit_border = TRUE;
882 break;
883 }
884 if (x-xpos < 0)
885 {
886 break;
887 }
888 m_minX = xpos;
889 }
890
891 if (event.LeftDown())
892 {
893 if (hit_border)
894 {
895 m_isDragging = TRUE;
896 m_currentX = x;
897 DrawCurrent();
898 CaptureMouse();
899 return;
900 }
901 else
902 {
903 wxListEvent le( wxEVT_COMMAND_LIST_COL_CLICK, GetParent()->GetId() );
904 le.SetEventObject( GetParent() );
905 le.m_col = m_column;
906 GetParent()->GetEventHandler()->ProcessEvent( le );
907 return;
908 }
909 }
910
911 if (event.Moving())
912 {
913 if (hit_border)
914 {
915 if (m_currentCursor == wxSTANDARD_CURSOR) SetCursor( * m_resizeCursor );
916 m_currentCursor = m_resizeCursor;
917 }
918 else
919 {
920 if (m_currentCursor != wxSTANDARD_CURSOR) SetCursor( * wxSTANDARD_CURSOR );
921 m_currentCursor = wxSTANDARD_CURSOR;
922 }
923 }
924 }
925
926 void wxListHeaderWindow::OnSetFocus( wxFocusEvent &WXUNUSED(event) )
927 {
928 m_owner->SetFocus();
929 }
930
931 //-----------------------------------------------------------------------------
932 // wxListRenameTimer (internal)
933 //-----------------------------------------------------------------------------
934
935 wxListRenameTimer::wxListRenameTimer( wxListMainWindow *owner )
936 {
937 m_owner = owner;
938 }
939
940 void wxListRenameTimer::Notify()
941 {
942 m_owner->OnRenameTimer();
943 }
944
945 //-----------------------------------------------------------------------------
946 // wxListTextCtrl (internal)
947 //-----------------------------------------------------------------------------
948
949 IMPLEMENT_DYNAMIC_CLASS(wxListTextCtrl,wxTextCtrl);
950
951 BEGIN_EVENT_TABLE(wxListTextCtrl,wxTextCtrl)
952 EVT_CHAR (wxListTextCtrl::OnChar)
953 EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus)
954 END_EVENT_TABLE()
955
956 wxListTextCtrl::wxListTextCtrl( wxWindow *parent, const wxWindowID id,
957 bool *accept, wxString *res, wxListMainWindow *owner,
958 const wxString &value, const wxPoint &pos, const wxSize &size,
959 #if wxUSE_VALIDATORS
960 # if defined(__VISAGECPP__)
961 int style, const wxValidator* validator, const wxString &name ) :
962 # else
963 int style, const wxValidator& validator, const wxString &name ) :
964 # endif
965 #endif
966 wxTextCtrl( parent, id, value, pos, size, style, validator, name )
967 {
968 m_res = res;
969 m_accept = accept;
970 m_owner = owner;
971 (*m_accept) = FALSE;
972 (*m_res) = "";
973 m_startValue = value;
974 }
975
976 void wxListTextCtrl::OnChar( wxKeyEvent &event )
977 {
978 if (event.m_keyCode == WXK_RETURN)
979 {
980 (*m_accept) = TRUE;
981 (*m_res) = GetValue();
982 m_owner->SetFocus();
983 return;
984 }
985 if (event.m_keyCode == WXK_ESCAPE)
986 {
987 (*m_accept) = FALSE;
988 (*m_res) = "";
989 m_owner->SetFocus();
990 return;
991 }
992 event.Skip();
993 }
994
995 void wxListTextCtrl::OnKillFocus( wxFocusEvent &WXUNUSED(event) )
996 {
997 if (wxPendingDelete.Member(this)) return;
998
999 wxPendingDelete.Append(this);
1000
1001 if ((*m_accept) && ((*m_res) != m_startValue))
1002 m_owner->OnRenameAccept();
1003 }
1004
1005 //-----------------------------------------------------------------------------
1006 // wxListMainWindow
1007 //-----------------------------------------------------------------------------
1008
1009 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow,wxScrolledWindow);
1010
1011 BEGIN_EVENT_TABLE(wxListMainWindow,wxScrolledWindow)
1012 EVT_PAINT (wxListMainWindow::OnPaint)
1013 EVT_SIZE (wxListMainWindow::OnSize)
1014 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse)
1015 EVT_CHAR (wxListMainWindow::OnChar)
1016 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown)
1017 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus)
1018 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus)
1019 END_EVENT_TABLE()
1020
1021 wxListMainWindow::wxListMainWindow()
1022 {
1023 m_mode = 0;
1024 m_lines.DeleteContents( TRUE );
1025 m_columns.DeleteContents( TRUE );
1026 m_current = (wxListLineData *) NULL;
1027 m_visibleLines = 0;
1028 m_hilightBrush = (wxBrush *) NULL;
1029 m_xScroll = 0;
1030 m_yScroll = 0;
1031 m_dirty = TRUE;
1032 m_small_image_list = (wxImageList *) NULL;
1033 m_normal_image_list = (wxImageList *) NULL;
1034 m_small_spacing = 30;
1035 m_normal_spacing = 40;
1036 m_hasFocus = FALSE;
1037 m_usedKeys = TRUE;
1038 m_lastOnSame = FALSE;
1039 m_renameTimer = new wxListRenameTimer( this );
1040 m_isCreated = FALSE;
1041 m_dragCount = 0;
1042 }
1043
1044 wxListMainWindow::wxListMainWindow( wxWindow *parent, wxWindowID id,
1045 const wxPoint &pos, const wxSize &size,
1046 long style, const wxString &name ) :
1047 wxScrolledWindow( parent, id, pos, size, style|wxHSCROLL|wxVSCROLL, name )
1048 {
1049 m_mode = style;
1050 m_lines.DeleteContents( TRUE );
1051 m_columns.DeleteContents( TRUE );
1052 m_current = (wxListLineData *) NULL;
1053 m_dirty = TRUE;
1054 m_visibleLines = 0;
1055 m_hilightBrush = new wxBrush( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT), wxSOLID );
1056 m_small_image_list = (wxImageList *) NULL;
1057 m_normal_image_list = (wxImageList *) NULL;
1058 m_small_spacing = 30;
1059 m_normal_spacing = 40;
1060 m_hasFocus = FALSE;
1061 m_dragCount = 0;
1062 m_isCreated = FALSE;
1063 wxSize sz = size;
1064 sz.y = 25;
1065
1066 if (m_mode & wxLC_REPORT)
1067 {
1068 m_xScroll = 0;
1069 m_yScroll = 15;
1070 }
1071 else
1072 {
1073 m_xScroll = 15;
1074 m_yScroll = 0;
1075 }
1076 SetScrollbars( m_xScroll, m_yScroll, 0, 0, 0, 0 );
1077
1078 m_usedKeys = TRUE;
1079 m_lastOnSame = FALSE;
1080 m_renameTimer = new wxListRenameTimer( this );
1081 m_renameAccept = FALSE;
1082
1083 SetBackgroundColour( *wxWHITE );
1084 }
1085
1086 wxListMainWindow::~wxListMainWindow()
1087 {
1088 if (m_hilightBrush) delete m_hilightBrush;
1089
1090 delete m_renameTimer;
1091 }
1092
1093 void wxListMainWindow::RefreshLine( wxListLineData *line )
1094 {
1095 int x = 0;
1096 int y = 0;
1097 int w = 0;
1098 int h = 0;
1099 if (line)
1100 {
1101 wxClientDC dc(this);
1102 PrepareDC( dc );
1103 line->GetExtent( x, y, w, h );
1104 wxRect rect(
1105 dc.LogicalToDeviceX(x-3),
1106 dc.LogicalToDeviceY(y-3),
1107 dc.LogicalToDeviceXRel(w+6),
1108 dc.LogicalToDeviceXRel(h+6) );
1109 Refresh( TRUE, &rect );
1110 }
1111 }
1112
1113 void wxListMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
1114 {
1115 // Note: a wxPaintDC must be constructed even if no drawing is
1116 // done (a Windows requirement).
1117 wxPaintDC dc( this );
1118 PrepareDC( dc );
1119
1120 if (m_dirty) return;
1121
1122 if (m_lines.GetCount() == 0) return;
1123
1124 dc.BeginDrawing();
1125
1126 dc.SetFont( GetFont() );
1127
1128 if (m_mode & wxLC_REPORT)
1129 {
1130 int lineSpacing = 0;
1131 wxListLineData *line = (wxListLineData*)m_lines.First()->Data();
1132 int dummy = 0;
1133 line->GetSize( dummy, lineSpacing );
1134 lineSpacing += 1;
1135
1136 int y_s = m_yScroll*GetScrollPos( wxVERTICAL );
1137
1138 wxNode *node = m_lines.Nth( y_s / lineSpacing );
1139 for (int i = 0; i < m_visibleLines+2; i++)
1140 {
1141 if (!node) break;
1142
1143 line = (wxListLineData*)node->Data();
1144 line->Draw( &dc );
1145 node = node->Next();
1146 }
1147 }
1148 else
1149 {
1150 wxNode *node = m_lines.First();
1151 while (node)
1152 {
1153 wxListLineData *line = (wxListLineData*)node->Data();
1154 line->Draw( &dc );
1155 node = node->Next();
1156 }
1157 }
1158
1159 if (m_current) m_current->DrawRubberBand( &dc, m_hasFocus );
1160
1161 dc.EndDrawing();
1162 }
1163
1164 void wxListMainWindow::HilightAll( bool on )
1165 {
1166 wxNode *node = m_lines.First();
1167 while (node)
1168 {
1169 wxListLineData *line = (wxListLineData *)node->Data();
1170 if (line->IsHilighted() != on)
1171 {
1172 line->Hilight( on );
1173 RefreshLine( line );
1174 }
1175 node = node->Next();
1176 }
1177 }
1178
1179 void wxListMainWindow::SendNotify( wxListLineData *line, wxEventType command )
1180 {
1181 wxListEvent le( command, GetParent()->GetId() );
1182 le.SetEventObject( GetParent() );
1183 le.m_itemIndex = GetIndexOfLine( line );
1184 line->GetItem( 0, le.m_item );
1185 GetParent()->GetEventHandler()->ProcessEvent( le );
1186 }
1187
1188 void wxListMainWindow::FocusLine( wxListLineData *WXUNUSED(line) )
1189 {
1190 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_FOCUSSED );
1191 }
1192
1193 void wxListMainWindow::UnfocusLine( wxListLineData *WXUNUSED(line) )
1194 {
1195 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_UNFOCUSSED );
1196 }
1197
1198 void wxListMainWindow::SelectLine( wxListLineData *line )
1199 {
1200 SendNotify( line, wxEVT_COMMAND_LIST_ITEM_SELECTED );
1201 }
1202
1203 void wxListMainWindow::DeselectLine( wxListLineData *line )
1204 {
1205 SendNotify( line, wxEVT_COMMAND_LIST_ITEM_DESELECTED );
1206 }
1207
1208 void wxListMainWindow::DeleteLine( wxListLineData *line )
1209 {
1210 SendNotify( line, wxEVT_COMMAND_LIST_DELETE_ITEM );
1211 }
1212
1213 /* *** */
1214
1215 void wxListMainWindow::EditLabel( long item )
1216 {
1217 wxNode *node = m_lines.Nth( item );
1218 wxCHECK_RET( node, wxT("wrong index in wxListCtrl::Edit()") );
1219
1220 m_currentEdit = (wxListLineData*) node->Data();
1221
1222 wxListEvent le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT, GetParent()->GetId() );
1223 le.SetEventObject( GetParent() );
1224 le.m_itemIndex = GetIndexOfLine( m_currentEdit );
1225 m_currentEdit->GetItem( 0, le.m_item );
1226 GetParent()->GetEventHandler()->ProcessEvent( le );
1227
1228 if (!le.IsAllowed())
1229 return;
1230
1231 // We have to call this here because the label in
1232 // question might just have been added and no screen
1233 // update taken place.
1234 if (m_dirty) wxYield();
1235
1236 wxString s;
1237 m_currentEdit->GetText( 0, s );
1238 int x = 0;
1239 int y = 0;
1240 int w = 0;
1241 int h = 0;
1242 m_currentEdit->GetLabelExtent( x, y, w, h );
1243
1244 wxClientDC dc(this);
1245 PrepareDC( dc );
1246 x = dc.LogicalToDeviceX( x );
1247 y = dc.LogicalToDeviceY( y );
1248
1249 wxListTextCtrl *text = new wxListTextCtrl(
1250 this, -1, &m_renameAccept, &m_renameRes, this, s, wxPoint(x-4,y-4), wxSize(w+11,h+8) );
1251 text->SetFocus();
1252 }
1253
1254 void wxListMainWindow::OnRenameTimer()
1255 {
1256 wxCHECK_RET( m_current, wxT("invalid m_current") );
1257
1258 Edit( m_lines.IndexOf( m_current ) );
1259 }
1260
1261 void wxListMainWindow::OnRenameAccept()
1262 {
1263 wxListEvent le( wxEVT_COMMAND_LIST_END_LABEL_EDIT, GetParent()->GetId() );
1264 le.SetEventObject( GetParent() );
1265 le.m_itemIndex = GetIndexOfLine( m_currentEdit );
1266 m_currentEdit->GetItem( 0, le.m_item );
1267 le.m_item.m_text = m_renameRes;
1268 GetParent()->GetEventHandler()->ProcessEvent( le );
1269
1270 if (!le.IsAllowed()) return;
1271
1272 wxListItem info;
1273 info.m_mask = wxLIST_MASK_TEXT;
1274 info.m_itemId = le.m_itemIndex;
1275 info.m_text = m_renameRes;
1276 info.m_colour = le.m_item.m_colour;
1277 SetItem( info );
1278 }
1279
1280 void wxListMainWindow::OnMouse( wxMouseEvent &event )
1281 {
1282 if (GetParent()->GetEventHandler()->ProcessEvent( event)) return;
1283
1284 if (!m_current) return;
1285 if (m_dirty) return;
1286 if ( !(event.Dragging() || event.ButtonDown() || event.LeftUp() || event.ButtonDClick()) ) return;
1287
1288 wxClientDC dc(this);
1289 PrepareDC(dc);
1290 long x = dc.DeviceToLogicalX( (long)event.GetX() );
1291 long y = dc.DeviceToLogicalY( (long)event.GetY() );
1292
1293 /* Did we actually hit an item ? */
1294 long hitResult = 0;
1295 wxNode *node = m_lines.First();
1296 wxListLineData *line = (wxListLineData *) NULL;
1297 while (node)
1298 {
1299 line = (wxListLineData*)node->Data();
1300 hitResult = line->IsHit( x, y );
1301 if (hitResult) break;
1302 line = (wxListLineData *) NULL;
1303 node = node->Next();
1304 }
1305
1306 if (event.Dragging())
1307 {
1308 if (m_dragCount == 0)
1309 m_dragStart = wxPoint(x,y);
1310
1311 m_dragCount++;
1312
1313 if (m_dragCount != 3) return;
1314
1315 int command = wxEVT_COMMAND_LIST_BEGIN_DRAG;
1316 if (event.RightIsDown()) command = wxEVT_COMMAND_LIST_BEGIN_RDRAG;
1317
1318 wxListEvent le( command, GetParent()->GetId() );
1319 le.SetEventObject( GetParent() );
1320 le.m_pointDrag = m_dragStart;
1321 GetParent()->GetEventHandler()->ProcessEvent( le );
1322
1323 return;
1324 }
1325 else
1326 {
1327 m_dragCount = 0;
1328 }
1329
1330 if (!line) return;
1331
1332 if (event.ButtonDClick())
1333 {
1334 m_usedKeys = FALSE;
1335 m_lastOnSame = FALSE;
1336 m_renameTimer->Stop();
1337
1338 SendNotify( line, wxEVT_COMMAND_LIST_ITEM_ACTIVATED );
1339
1340 return;
1341 }
1342
1343 if (event.LeftUp() && m_lastOnSame)
1344 {
1345 m_usedKeys = FALSE;
1346 if ((line == m_current) &&
1347 (hitResult == wxLIST_HITTEST_ONITEMLABEL) &&
1348 (m_mode & wxLC_EDIT_LABELS) )
1349 {
1350 m_renameTimer->Start( 100, TRUE );
1351 }
1352 m_lastOnSame = FALSE;
1353 return;
1354 }
1355
1356 if (event.RightDown())
1357 {
1358 SendNotify( line, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK );
1359 return;
1360 }
1361
1362 if (event.MiddleDown())
1363 {
1364 SendNotify( line, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK );
1365 return;
1366 }
1367
1368 if (event.LeftDown())
1369 {
1370 m_usedKeys = FALSE;
1371 wxListLineData *oldCurrent = m_current;
1372 if (m_mode & wxLC_SINGLE_SEL)
1373 {
1374 m_current = line;
1375 HilightAll( FALSE );
1376 m_current->ReverseHilight();
1377 RefreshLine( m_current );
1378 }
1379 else
1380 {
1381 if (event.ShiftDown())
1382 {
1383 m_current = line;
1384 m_current->ReverseHilight();
1385 RefreshLine( m_current );
1386 }
1387 else if (event.ControlDown())
1388 {
1389 m_current = line;
1390
1391 int numOfCurrent = -1;
1392 node = m_lines.First();
1393 while (node)
1394 {
1395 wxListLineData *test_line = (wxListLineData*)node->Data();
1396 numOfCurrent++;
1397 if (test_line == oldCurrent) break;
1398 node = node->Next();
1399 }
1400
1401 int numOfLine = -1;
1402 node = m_lines.First();
1403 while (node)
1404 {
1405 wxListLineData *test_line = (wxListLineData*)node->Data();
1406 numOfLine++;
1407 if (test_line == line) break;
1408 node = node->Next();
1409 }
1410
1411 if (numOfLine < numOfCurrent)
1412 {
1413 int i = numOfLine;
1414 numOfLine = numOfCurrent;
1415 numOfCurrent = i;
1416 }
1417
1418 wxNode *node = m_lines.Nth( numOfCurrent );
1419 for (int i = 0; i <= numOfLine-numOfCurrent; i++)
1420 {
1421 wxListLineData *test_line= (wxListLineData*)node->Data();
1422 test_line->Hilight(TRUE);
1423 RefreshLine( test_line );
1424 node = node->Next();
1425 }
1426 }
1427 else
1428 {
1429 m_current = line;
1430 HilightAll( FALSE );
1431 m_current->ReverseHilight();
1432 RefreshLine( m_current );
1433 }
1434 }
1435 if (m_current != oldCurrent)
1436 {
1437 RefreshLine( oldCurrent );
1438 UnfocusLine( oldCurrent );
1439 FocusLine( m_current );
1440 }
1441 m_lastOnSame = (m_current == oldCurrent);
1442 return;
1443 }
1444 }
1445
1446 void wxListMainWindow::MoveToFocus()
1447 {
1448 if (!m_current) return;
1449
1450 int x = 0;
1451 int y = 0;
1452 int w = 0;
1453 int h = 0;
1454 m_current->GetExtent( x, y, w, h );
1455
1456 int w_p = 0;
1457 int h_p = 0;
1458 GetClientSize( &w_p, &h_p );
1459
1460 if (m_mode & wxLC_REPORT)
1461 {
1462 int y_s = m_yScroll*GetScrollPos( wxVERTICAL );
1463 if ((y > y_s) && (y+h < y_s+h_p)) return;
1464 if (y-y_s < 5) { Scroll( -1, (y-5-h_p/2)/m_yScroll ); }
1465 if (y+h+5 > y_s+h_p) { Scroll( -1, (y+h-h_p/2+h+15)/m_yScroll); }
1466 }
1467 else
1468 {
1469 int x_s = m_xScroll*GetScrollPos( wxHORIZONTAL );
1470 if ((x > x_s) && (x+w < x_s+w_p)) return;
1471 if (x-x_s < 5) { Scroll( (x-5)/m_xScroll, -1 ); }
1472 if (x+w-5 > x_s+w_p) { Scroll( (x+w-w_p+15)/m_xScroll, -1 ); }
1473 }
1474 }
1475
1476 void wxListMainWindow::OnArrowChar( wxListLineData *newCurrent, bool shiftDown )
1477 {
1478 if ((m_mode & wxLC_SINGLE_SEL) || (m_usedKeys == FALSE)) m_current->Hilight( FALSE );
1479 wxListLineData *oldCurrent = m_current;
1480 m_current = newCurrent;
1481 MoveToFocus();
1482 if (shiftDown || (m_mode & wxLC_SINGLE_SEL)) m_current->Hilight( TRUE );
1483 RefreshLine( m_current );
1484 RefreshLine( oldCurrent );
1485 FocusLine( m_current );
1486 UnfocusLine( oldCurrent );
1487 }
1488
1489 void wxListMainWindow::OnKeyDown( wxKeyEvent &event )
1490 {
1491 wxWindow *parent = GetParent();
1492
1493 /* we propagate the key event up */
1494 wxKeyEvent ke( wxEVT_KEY_DOWN );
1495 ke.m_shiftDown = event.m_shiftDown;
1496 ke.m_controlDown = event.m_controlDown;
1497 ke.m_altDown = event.m_altDown;
1498 ke.m_metaDown = event.m_metaDown;
1499 ke.m_keyCode = event.m_keyCode;
1500 ke.m_x = event.m_x;
1501 ke.m_y = event.m_y;
1502 ke.SetEventObject( parent );
1503 if (parent->GetEventHandler()->ProcessEvent( ke )) return;
1504
1505 event.Skip();
1506 }
1507
1508 void wxListMainWindow::OnChar( wxKeyEvent &event )
1509 {
1510 wxWindow *parent = GetParent();
1511
1512 /* we send a list_key event up */
1513 wxListEvent le( wxEVT_COMMAND_LIST_KEY_DOWN, GetParent()->GetId() );
1514 le.m_code = event.KeyCode();
1515 le.SetEventObject( parent );
1516 parent->GetEventHandler()->ProcessEvent( le );
1517
1518 /* we propagate the char event up */
1519 wxKeyEvent ke( wxEVT_CHAR );
1520 ke.m_shiftDown = event.m_shiftDown;
1521 ke.m_controlDown = event.m_controlDown;
1522 ke.m_altDown = event.m_altDown;
1523 ke.m_metaDown = event.m_metaDown;
1524 ke.m_keyCode = event.m_keyCode;
1525 ke.m_x = event.m_x;
1526 ke.m_y = event.m_y;
1527 ke.SetEventObject( parent );
1528 if (parent->GetEventHandler()->ProcessEvent( ke )) return;
1529
1530 if (event.KeyCode() == WXK_TAB)
1531 {
1532 wxNavigationKeyEvent nevent;
1533 nevent.SetDirection( !event.ShiftDown() );
1534 nevent.SetCurrentFocus( m_parent );
1535 if (m_parent->GetEventHandler()->ProcessEvent( nevent )) return;
1536 }
1537
1538 /* no item -> nothing to do */
1539 if (!m_current)
1540 {
1541 event.Skip();
1542 return;
1543 }
1544
1545 switch (event.KeyCode())
1546 {
1547 case WXK_UP:
1548 {
1549 wxNode *node = m_lines.Member( m_current )->Previous();
1550 if (node) OnArrowChar( (wxListLineData*)node->Data(), event.ShiftDown() );
1551 break;
1552 }
1553 case WXK_DOWN:
1554 {
1555 wxNode *node = m_lines.Member( m_current )->Next();
1556 if (node) OnArrowChar( (wxListLineData*)node->Data(), event.ShiftDown() );
1557 break;
1558 }
1559 case WXK_END:
1560 {
1561 wxNode *node = m_lines.Last();
1562 OnArrowChar( (wxListLineData*)node->Data(), event.ShiftDown() );
1563 break;
1564 }
1565 case WXK_HOME:
1566 {
1567 wxNode *node = m_lines.First();
1568 OnArrowChar( (wxListLineData*)node->Data(), event.ShiftDown() );
1569 break;
1570 }
1571 case WXK_PRIOR:
1572 {
1573 int steps = 0;
1574 if (m_mode & wxLC_REPORT)
1575 {
1576 steps = m_visibleLines-1;
1577 }
1578 else
1579 {
1580 int pos = 0;
1581 wxNode *node = m_lines.First();
1582 for (;;) { if (m_current == (wxListLineData*)node->Data()) break; pos++; node = node->Next(); }
1583 steps = pos % m_visibleLines;
1584 }
1585 wxNode *node = m_lines.Member( m_current );
1586 for (int i = 0; i < steps; i++) if (node->Previous()) node = node->Previous();
1587 if (node) OnArrowChar( (wxListLineData*)node->Data(), event.ShiftDown() );
1588 break;
1589 }
1590 case WXK_NEXT:
1591 {
1592 int steps = 0;
1593 if (m_mode & wxLC_REPORT)
1594 {
1595 steps = m_visibleLines-1;
1596 }
1597 else
1598 {
1599 int pos = 0; wxNode *node = m_lines.First();
1600 for (;;) { if (m_current == (wxListLineData*)node->Data()) break; pos++; node = node->Next(); }
1601 steps = m_visibleLines-(pos % m_visibleLines)-1;
1602 }
1603 wxNode *node = m_lines.Member( m_current );
1604 for (int i = 0; i < steps; i++) if (node->Next()) node = node->Next();
1605 if (node) OnArrowChar( (wxListLineData*)node->Data(), event.ShiftDown() );
1606 break;
1607 }
1608 case WXK_LEFT:
1609 {
1610 if (!(m_mode & wxLC_REPORT))
1611 {
1612 wxNode *node = m_lines.Member( m_current );
1613 for (int i = 0; i <m_visibleLines; i++) if (node->Previous()) node = node->Previous();
1614 if (node) OnArrowChar( (wxListLineData*)node->Data(), event.ShiftDown() );
1615 }
1616 break;
1617 }
1618 case WXK_RIGHT:
1619 {
1620 if (!(m_mode & wxLC_REPORT))
1621 {
1622 wxNode *node = m_lines.Member( m_current );
1623 for (int i = 0; i <m_visibleLines; i++) if (node->Next()) node = node->Next();
1624 if (node) OnArrowChar( (wxListLineData*)node->Data(), event.ShiftDown() );
1625 }
1626 break;
1627 }
1628 case WXK_SPACE:
1629 {
1630 m_current->ReverseHilight();
1631 RefreshLine( m_current );
1632 break;
1633 }
1634 case WXK_INSERT:
1635 {
1636 if (!(m_mode & wxLC_SINGLE_SEL))
1637 {
1638 wxListLineData *oldCurrent = m_current;
1639 m_current->ReverseHilight();
1640 wxNode *node = m_lines.Member( m_current )->Next();
1641 if (node) m_current = (wxListLineData*)node->Data();
1642 MoveToFocus();
1643 RefreshLine( oldCurrent );
1644 RefreshLine( m_current );
1645 UnfocusLine( oldCurrent );
1646 FocusLine( m_current );
1647 }
1648 break;
1649 }
1650 case WXK_RETURN:
1651 case WXK_EXECUTE:
1652 {
1653 wxListEvent le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED, GetParent()->GetId() );
1654 le.SetEventObject( GetParent() );
1655 le.m_itemIndex = GetIndexOfLine( m_current );
1656 m_current->GetItem( 0, le.m_item );
1657 GetParent()->GetEventHandler()->ProcessEvent( le );
1658 break;
1659 }
1660 default:
1661 {
1662 event.Skip();
1663 return;
1664 }
1665 }
1666 m_usedKeys = TRUE;
1667 }
1668
1669 #ifdef __WXGTK__
1670 extern wxWindow *g_focusWindow;
1671 #endif
1672
1673 void wxListMainWindow::OnSetFocus( wxFocusEvent &WXUNUSED(event) )
1674 {
1675 m_hasFocus = TRUE;
1676 RefreshLine( m_current );
1677
1678 if (!GetParent()) return;
1679
1680 #ifdef __WXGTK__
1681 g_focusWindow = GetParent();
1682 #endif
1683
1684 wxFocusEvent event( wxEVT_SET_FOCUS, GetParent()->GetId() );
1685 event.SetEventObject( GetParent() );
1686 GetParent()->GetEventHandler()->ProcessEvent( event );
1687 }
1688
1689 void wxListMainWindow::OnKillFocus( wxFocusEvent &WXUNUSED(event) )
1690 {
1691 m_hasFocus = FALSE;
1692 RefreshLine( m_current );
1693 }
1694
1695 void wxListMainWindow::OnSize( wxSizeEvent &WXUNUSED(event) )
1696 {
1697 /*
1698 We don't even allow the wxScrolledWindow::AdjustScrollbars() call
1699
1700 */
1701 }
1702
1703 void wxListMainWindow::DrawImage( int index, wxDC *dc, int x, int y )
1704 {
1705 if ((m_mode & wxLC_ICON) && (m_normal_image_list))
1706 {
1707 m_normal_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT );
1708 return;
1709 }
1710 if ((m_mode & wxLC_SMALL_ICON) && (m_small_image_list))
1711 {
1712 m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT );
1713 }
1714 if ((m_mode & wxLC_LIST) && (m_small_image_list))
1715 {
1716 m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT );
1717 }
1718 if ((m_mode & wxLC_REPORT) && (m_small_image_list))
1719 {
1720 m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT );
1721 return;
1722 }
1723 }
1724
1725 void wxListMainWindow::GetImageSize( int index, int &width, int &height )
1726 {
1727 if ((m_mode & wxLC_ICON) && (m_normal_image_list))
1728 {
1729 m_normal_image_list->GetSize( index, width, height );
1730 return;
1731 }
1732 if ((m_mode & wxLC_SMALL_ICON) && (m_small_image_list))
1733 {
1734 m_small_image_list->GetSize( index, width, height );
1735 return;
1736 }
1737 if ((m_mode & wxLC_LIST) && (m_small_image_list))
1738 {
1739 m_small_image_list->GetSize( index, width, height );
1740 return;
1741 }
1742 if ((m_mode & wxLC_REPORT) && (m_small_image_list))
1743 {
1744 m_small_image_list->GetSize( index, width, height );
1745 return;
1746 }
1747 width = 0;
1748 height = 0;
1749 }
1750
1751 int wxListMainWindow::GetTextLength( wxString &s )
1752 {
1753 wxClientDC dc( this );
1754 long lw = 0;
1755 long lh = 0;
1756 dc.GetTextExtent( s, &lw, &lh );
1757 return lw + 6;
1758 }
1759
1760 int wxListMainWindow::GetIndexOfLine( const wxListLineData *line )
1761 {
1762 int i = 0;
1763 wxNode *node = m_lines.First();
1764 while (node)
1765 {
1766 if (line == (wxListLineData*)node->Data()) return i;
1767 i++;
1768 node = node->Next();
1769 }
1770 return -1;
1771 }
1772
1773 void wxListMainWindow::SetImageList( wxImageList *imageList, int which )
1774 {
1775 m_dirty = TRUE;
1776 if (which == wxIMAGE_LIST_NORMAL) m_normal_image_list = imageList;
1777 if (which == wxIMAGE_LIST_SMALL) m_small_image_list = imageList;
1778 }
1779
1780 void wxListMainWindow::SetItemSpacing( int spacing, bool isSmall )
1781 {
1782 m_dirty = TRUE;
1783 if (isSmall)
1784 {
1785 m_small_spacing = spacing;
1786 }
1787 else
1788 {
1789 m_normal_spacing = spacing;
1790 }
1791 }
1792
1793 int wxListMainWindow::GetItemSpacing( bool isSmall )
1794 {
1795 if (isSmall) return m_small_spacing; else return m_normal_spacing;
1796 }
1797
1798 void wxListMainWindow::SetColumn( int col, wxListItem &item )
1799 {
1800 m_dirty = TRUE;
1801 wxNode *node = m_columns.Nth( col );
1802 if (node)
1803 {
1804 if (item.m_width == wxLIST_AUTOSIZE_USEHEADER) item.m_width = GetTextLength( item.m_text )+7;
1805 wxListHeaderData *column = (wxListHeaderData*)node->Data();
1806 column->SetItem( item );
1807 }
1808 wxListCtrl *lc = (wxListCtrl*) GetParent();
1809 if (lc->m_headerWin) lc->m_headerWin->Refresh();
1810 }
1811
1812 void wxListMainWindow::SetColumnWidth( int col, int width )
1813 {
1814 if (!(m_mode & wxLC_REPORT)) return;
1815
1816 m_dirty = TRUE;
1817
1818 wxNode *node = (wxNode*) NULL;
1819
1820 if (width == wxLIST_AUTOSIZE_USEHEADER) width = 80;
1821 if (width == wxLIST_AUTOSIZE)
1822 {
1823 wxClientDC dc(this);
1824 dc.SetFont( GetFont() );
1825 int max = 10;
1826 node = m_lines.First();
1827 while (node)
1828 {
1829 wxListLineData *line = (wxListLineData*)node->Data();
1830 wxNode *n = line->m_items.Nth( col );
1831 if (n)
1832 {
1833 wxListItemData *item = (wxListItemData*)n->Data();
1834 int current = 0, ix = 0, iy = 0;
1835 long lx = 0, ly = 0;
1836 if (item->HasImage())
1837 {
1838 GetImageSize( item->GetImage(), ix, iy );
1839 current = ix + 5;
1840 }
1841 if (item->HasText())
1842 {
1843 wxString str;
1844 item->GetText( str );
1845 dc.GetTextExtent( str, &lx, &ly );
1846 current += lx;
1847 }
1848 if (current > max) max = current;
1849 }
1850 node = node->Next();
1851 }
1852 width = max+10;
1853 }
1854
1855 node = m_columns.Nth( col );
1856 if (node)
1857 {
1858 wxListHeaderData *column = (wxListHeaderData*)node->Data();
1859 column->SetWidth( width );
1860 }
1861
1862 node = m_lines.First();
1863 while (node)
1864 {
1865 wxListLineData *line = (wxListLineData*)node->Data();
1866 wxNode *n = line->m_items.Nth( col );
1867 if (n)
1868 {
1869 wxListItemData *item = (wxListItemData*)n->Data();
1870 item->SetSize( width, -1 );
1871 }
1872 node = node->Next();
1873 }
1874
1875 wxListCtrl *lc = (wxListCtrl*) GetParent();
1876 if (lc->m_headerWin) lc->m_headerWin->Refresh();
1877 }
1878
1879 void wxListMainWindow::GetColumn( int col, wxListItem &item )
1880 {
1881 wxNode *node = m_columns.Nth( col );
1882 if (node)
1883 {
1884 wxListHeaderData *column = (wxListHeaderData*)node->Data();
1885 column->GetItem( item );
1886 }
1887 else
1888 {
1889 item.m_format = 0;
1890 item.m_width = 0;
1891 item.m_text = "";
1892 item.m_image = 0;
1893 item.m_data = 0;
1894 }
1895 }
1896
1897 int wxListMainWindow::GetColumnWidth( int col )
1898 {
1899 wxNode *node = m_columns.Nth( col );
1900 if (node)
1901 {
1902 wxListHeaderData *column = (wxListHeaderData*)node->Data();
1903 return column->GetWidth();
1904 }
1905 else
1906 {
1907 return 0;
1908 }
1909 }
1910
1911 int wxListMainWindow::GetColumnCount()
1912 {
1913 return m_columns.Number();
1914 }
1915
1916 int wxListMainWindow::GetCountPerPage()
1917 {
1918 return m_visibleLines;
1919 }
1920
1921 void wxListMainWindow::SetItem( wxListItem &item )
1922 {
1923 m_dirty = TRUE;
1924 wxNode *node = m_lines.Nth( item.m_itemId );
1925 if (node)
1926 {
1927 wxListLineData *line = (wxListLineData*)node->Data();
1928 if (m_mode & wxLC_REPORT) item.m_width = GetColumnWidth( item.m_col )-3;
1929 line->SetItem( item.m_col, item );
1930 }
1931 }
1932
1933 void wxListMainWindow::SetItemState( long item, long state, long stateMask )
1934 {
1935 // m_dirty = TRUE; no recalcs needed
1936
1937 wxListLineData *oldCurrent = m_current;
1938
1939 if (stateMask & wxLIST_STATE_FOCUSED)
1940 {
1941 wxNode *node = m_lines.Nth( item );
1942 if (node)
1943 {
1944 wxListLineData *line = (wxListLineData*)node->Data();
1945 UnfocusLine( m_current );
1946 m_current = line;
1947 FocusLine( m_current );
1948 RefreshLine( m_current );
1949 if (oldCurrent) RefreshLine( oldCurrent );
1950 }
1951 }
1952
1953 if (stateMask & wxLIST_STATE_SELECTED)
1954 {
1955 bool on = state & wxLIST_STATE_SELECTED;
1956 if (!on && (m_mode & wxLC_SINGLE_SEL)) return;
1957
1958 wxNode *node = m_lines.Nth( item );
1959 if (node)
1960 {
1961 wxListLineData *line = (wxListLineData*)node->Data();
1962 if (m_mode & wxLC_SINGLE_SEL)
1963 {
1964 UnfocusLine( m_current );
1965 m_current = line;
1966 FocusLine( m_current );
1967 if (oldCurrent) oldCurrent->Hilight( FALSE );
1968 RefreshLine( m_current );
1969 if (oldCurrent) RefreshLine( oldCurrent );
1970 }
1971 bool on = state & wxLIST_STATE_SELECTED;
1972 if (on != line->IsHilighted())
1973 {
1974 line->Hilight( on );
1975 RefreshLine( line );
1976 }
1977 }
1978 }
1979 }
1980
1981 int wxListMainWindow::GetItemState( long item, long stateMask )
1982 {
1983 int ret = wxLIST_STATE_DONTCARE;
1984 if (stateMask & wxLIST_STATE_FOCUSED)
1985 {
1986 wxNode *node = m_lines.Nth( item );
1987 if (node)
1988 {
1989 wxListLineData *line = (wxListLineData*)node->Data();
1990 if (line == m_current) ret |= wxLIST_STATE_FOCUSED;
1991 }
1992 }
1993 if (stateMask & wxLIST_STATE_SELECTED)
1994 {
1995 wxNode *node = m_lines.Nth( item );
1996 if (node)
1997 {
1998 wxListLineData *line = (wxListLineData*)node->Data();
1999 if (line->IsHilighted()) ret |= wxLIST_STATE_FOCUSED;
2000 }
2001 }
2002 return ret;
2003 }
2004
2005 void wxListMainWindow::GetItem( wxListItem &item )
2006 {
2007 wxNode *node = m_lines.Nth( item.m_itemId );
2008 if (node)
2009 {
2010 wxListLineData *line = (wxListLineData*)node->Data();
2011 line->GetItem( item.m_col, item );
2012 }
2013 else
2014 {
2015 item.m_mask = 0;
2016 item.m_text = "";
2017 item.m_image = 0;
2018 item.m_data = 0;
2019 }
2020 }
2021
2022 int wxListMainWindow::GetItemCount()
2023 {
2024 return m_lines.Number();
2025 }
2026
2027 void wxListMainWindow::GetItemRect( long index, wxRect &rect )
2028 {
2029 wxNode *node = m_lines.Nth( index );
2030 if (node)
2031 {
2032 wxListLineData *line = (wxListLineData*)node->Data();
2033 line->GetRect( rect );
2034 }
2035 else
2036 {
2037 rect.x = 0;
2038 rect.y = 0;
2039 rect.width = 0;
2040 rect.height = 0;
2041 }
2042 }
2043
2044 bool wxListMainWindow::GetItemPosition(long item, wxPoint& pos)
2045 {
2046 wxNode *node = m_lines.Nth( item );
2047 if (node)
2048 {
2049 wxRect rect;
2050 wxListLineData *line = (wxListLineData*)node->Data();
2051 line->GetRect( rect );
2052 pos.x = rect.x;
2053 pos.y = rect.y;
2054 }
2055 else
2056 {
2057 pos.x = 0;
2058 pos.y = 0;
2059 }
2060 return TRUE;
2061 }
2062
2063 int wxListMainWindow::GetSelectedItemCount()
2064 {
2065 int ret = 0;
2066 wxNode *node = m_lines.First();
2067 while (node)
2068 {
2069 wxListLineData *line = (wxListLineData*)node->Data();
2070 if (line->IsHilighted()) ret++;
2071 node = node->Next();
2072 }
2073 return ret;
2074 }
2075
2076 void wxListMainWindow::SetMode( long mode )
2077 {
2078 m_dirty = TRUE;
2079 m_mode = mode;
2080
2081 DeleteEverything();
2082
2083 if (m_mode & wxLC_REPORT)
2084 {
2085 m_xScroll = 0;
2086 m_yScroll = 15;
2087 }
2088 else
2089 {
2090 m_xScroll = 15;
2091 m_yScroll = 0;
2092 }
2093 }
2094
2095 long wxListMainWindow::GetMode() const
2096 {
2097 return m_mode;
2098 }
2099
2100 void wxListMainWindow::CalculatePositions()
2101 {
2102 if (!m_lines.First()) return;
2103
2104 wxClientDC dc( this );
2105 dc.SetFont( GetFont() );
2106
2107 int iconSpacing = 0;
2108 if (m_mode & wxLC_ICON) iconSpacing = m_normal_spacing;
2109 if (m_mode & wxLC_SMALL_ICON) iconSpacing = m_small_spacing;
2110
2111 // we take the first line (which also can be an icon or
2112 // an a text item in wxLC_ICON and wxLC_LIST modes) to
2113 // measure the size of the line
2114
2115 int lineWidth = 0;
2116 int lineHeight = 0;
2117 int lineSpacing = 0;
2118
2119 wxListLineData *line = (wxListLineData*)m_lines.First()->Data();
2120 line->CalculateSize( &dc, iconSpacing );
2121 int dummy = 0;
2122 line->GetSize( dummy, lineSpacing );
2123 lineSpacing += 4;
2124
2125 int clientWidth = 0;
2126 int clientHeight = 0;
2127
2128 if (m_mode & wxLC_REPORT)
2129 {
2130 int x = 4;
2131 int y = 1;
2132 int entireHeight = m_lines.Number() * lineSpacing + 2;
2133 int scroll_pos = GetScrollPos( wxVERTICAL );
2134 SetScrollbars( m_xScroll, m_yScroll, 0, (entireHeight+15) / m_yScroll, 0, scroll_pos, TRUE );
2135 GetClientSize( &clientWidth, &clientHeight );
2136
2137 wxNode* node = m_lines.First();
2138 while (node)
2139 {
2140 wxListLineData *line = (wxListLineData*)node->Data();
2141 line->CalculateSize( &dc, iconSpacing );
2142 line->SetPosition( &dc, x, y, clientWidth );
2143 int col_x = 2;
2144 for (int i = 0; i < GetColumnCount(); i++)
2145 {
2146 line->SetColumnPosition( i, col_x );
2147 col_x += GetColumnWidth( i );
2148 }
2149 y += lineSpacing; // one pixel blank line between items
2150 node = node->Next();
2151 }
2152 m_visibleLines = clientHeight / lineSpacing;
2153 }
2154 else
2155 {
2156 // at first we try without any scrollbar. if the items don't
2157 // fit into the window, we recalculate after subtracting an
2158 // approximated 15 pt for the horizontal scrollbar
2159
2160 GetSize( &clientWidth, &clientHeight );
2161 clientHeight -= 4; // sunken frame
2162
2163 int entireWidth = 0;
2164
2165 for (int tries = 0; tries < 2; tries++)
2166 {
2167 entireWidth = 0;
2168 int x = 5; // painting is done at x-2
2169 int y = 5; // painting is done at y-2
2170 int maxWidth = 0;
2171 m_visibleLines = 0;
2172 int m_currentVisibleLines = 0;
2173 wxNode *node = m_lines.First();
2174 while (node)
2175 {
2176 m_currentVisibleLines++;
2177 wxListLineData *line = (wxListLineData*)node->Data();
2178 line->CalculateSize( &dc, iconSpacing );
2179 line->SetPosition( &dc, x, y, clientWidth );
2180 line->GetSize( lineWidth, lineHeight );
2181 if (lineWidth > maxWidth) maxWidth = lineWidth;
2182 y += lineSpacing;
2183 if (y+lineSpacing-6 >= clientHeight) // -6 for earlier "line breaking"
2184 {
2185 if (m_currentVisibleLines > m_visibleLines)
2186 m_visibleLines = m_currentVisibleLines;
2187 m_currentVisibleLines = 0;
2188 y = 5;
2189 x += maxWidth+6;
2190 entireWidth += maxWidth+6;
2191 maxWidth = 0;
2192 }
2193 node = node->Next();
2194 if (!node) entireWidth += maxWidth;
2195 if ((tries == 0) && (entireWidth > clientWidth))
2196 {
2197 clientHeight -= 15; // scrollbar height
2198 m_visibleLines = 0;
2199 m_currentVisibleLines = 0;
2200 break;
2201 }
2202 if (!node) tries = 1; // everything fits, no second try required
2203 }
2204 }
2205 // m_visibleLines = (5+clientHeight+6) / (lineSpacing); // +6 for earlier "line breaking"
2206
2207 int scroll_pos = GetScrollPos( wxHORIZONTAL );
2208 SetScrollbars( m_xScroll, m_yScroll, (entireWidth+15) / m_xScroll, 0, scroll_pos, 0, TRUE );
2209 }
2210 }
2211
2212 void wxListMainWindow::RealizeChanges( void )
2213 {
2214 if (!m_current)
2215 {
2216 wxNode *node = m_lines.First();
2217 if (node) m_current = (wxListLineData*)node->Data();
2218 }
2219 if (m_current)
2220 {
2221 FocusLine( m_current );
2222 if (m_mode & wxLC_SINGLE_SEL) m_current->Hilight( TRUE );
2223 }
2224 }
2225
2226 long wxListMainWindow::GetNextItem( long item, int WXUNUSED(geometry), int state )
2227 {
2228 long ret = 0;
2229 if (item > 0) ret = item;
2230 if(ret >= GetItemCount()) return -1;
2231 wxNode *node = m_lines.Nth( ret );
2232 while (node)
2233 {
2234 wxListLineData *line = (wxListLineData*)node->Data();
2235 if ((state & wxLIST_STATE_FOCUSED) && (line == m_current)) return ret;
2236 if ((state & wxLIST_STATE_SELECTED) && (line->IsHilighted())) return ret;
2237 if (!state) return ret;
2238 ret++;
2239 node = node->Next();
2240 }
2241 return -1;
2242 }
2243
2244 void wxListMainWindow::DeleteItem( long index )
2245 {
2246 m_dirty = TRUE;
2247 wxNode *node = m_lines.Nth( index );
2248 if (node)
2249 {
2250 wxListLineData *line = (wxListLineData*)node->Data();
2251 if (m_current == line) m_current = (wxListLineData *) NULL;
2252 DeleteLine( line );
2253 m_lines.DeleteNode( node );
2254 }
2255 }
2256
2257 void wxListMainWindow::DeleteColumn( int col )
2258 {
2259 wxCHECK_RET( col < (int)m_columns.GetCount(),
2260 wxT("attempting to delete inexistent column in wxListView") );
2261
2262 m_dirty = TRUE;
2263 wxNode *node = m_columns.Nth( col );
2264 if (node) m_columns.DeleteNode( node );
2265 }
2266
2267 void wxListMainWindow::DeleteAllItems( void )
2268 {
2269 m_dirty = TRUE;
2270 m_current = (wxListLineData *) NULL;
2271 wxNode *node = m_lines.First();
2272 while (node)
2273 {
2274 wxListLineData *line = (wxListLineData*)node->Data();
2275 DeleteLine( line );
2276 node = node->Next();
2277 }
2278 m_lines.Clear();
2279 }
2280
2281 void wxListMainWindow::DeleteEverything( void )
2282 {
2283 m_dirty = TRUE;
2284 m_current = (wxListLineData *) NULL;
2285 wxNode *node = m_lines.First();
2286 while (node)
2287 {
2288 wxListLineData *line = (wxListLineData*)node->Data();
2289 DeleteLine( line );
2290 node = node->Next();
2291 }
2292 m_lines.Clear();
2293 m_current = (wxListLineData *) NULL;
2294 m_columns.Clear();
2295 }
2296
2297 void wxListMainWindow::EnsureVisible( long index )
2298 {
2299 // We have to call this here because the label in
2300 // question might just have been added and no screen
2301 // update taken place.
2302 if (m_dirty) wxYield();
2303
2304 wxListLineData *oldCurrent = m_current;
2305 m_current = (wxListLineData *) NULL;
2306 int i = index;
2307 wxNode *node = m_lines.Nth( i );
2308 if (node) m_current = (wxListLineData*)node->Data();
2309 if (m_current) MoveToFocus();
2310 m_current = oldCurrent;
2311 }
2312
2313 long wxListMainWindow::FindItem(long start, const wxString& str, bool WXUNUSED(partial) )
2314 {
2315 long pos = start;
2316 wxString tmp = str;
2317 if (pos < 0) pos = 0;
2318 wxNode *node = m_lines.Nth( pos );
2319 while (node)
2320 {
2321 wxListLineData *line = (wxListLineData*)node->Data();
2322 wxString s = "";
2323 line->GetText( 0, s );
2324 if (s == tmp) return pos;
2325 node = node->Next();
2326 pos++;
2327 }
2328 return -1;
2329 }
2330
2331 long wxListMainWindow::FindItem(long start, long data)
2332 {
2333 long pos = start;
2334 if (pos < 0) pos = 0;
2335 wxNode *node = m_lines.Nth( pos );
2336 while (node)
2337 {
2338 wxListLineData *line = (wxListLineData*)node->Data();
2339 wxListItem item;
2340 line->GetItem( 0, item );
2341 if (item.m_data == data) return pos;
2342 node = node->Next();
2343 pos++;
2344 }
2345 return -1;
2346 }
2347
2348 long wxListMainWindow::HitTest( int x, int y, int &flags )
2349 {
2350 wxNode *node = m_lines.First();
2351 int count = 0;
2352 while (node)
2353 {
2354 wxListLineData *line = (wxListLineData*)node->Data();
2355 long ret = line->IsHit( x, y );
2356 if (ret & flags)
2357 {
2358 flags = ret;
2359 return count;
2360 }
2361 node = node->Next();
2362 count++;
2363 }
2364 return -1;
2365 }
2366
2367 void wxListMainWindow::InsertItem( wxListItem &item )
2368 {
2369 m_dirty = TRUE;
2370 int mode = 0;
2371 if (m_mode & wxLC_REPORT) mode = wxLC_REPORT;
2372 else if (m_mode & wxLC_LIST) mode = wxLC_LIST;
2373 else if (m_mode & wxLC_ICON) mode = wxLC_ICON;
2374 else if (m_mode & wxLC_SMALL_ICON) mode = wxLC_ICON; // no typo
2375
2376 wxListLineData *line = new wxListLineData( this, mode, m_hilightBrush );
2377
2378 if (m_mode & wxLC_REPORT)
2379 {
2380 line->InitItems( GetColumnCount() );
2381 item.m_width = GetColumnWidth( 0 )-3;
2382 }
2383 else
2384 {
2385 line->InitItems( 1 );
2386 }
2387
2388 line->SetItem( 0, item );
2389 if ((item.m_itemId >= 0) && (item.m_itemId < (int)m_lines.GetCount()))
2390 {
2391 wxNode *node = m_lines.Nth( item.m_itemId );
2392 if (node) m_lines.Insert( node, line );
2393 }
2394 else
2395 {
2396 m_lines.Append( line );
2397 }
2398 }
2399
2400 void wxListMainWindow::InsertColumn( long col, wxListItem &item )
2401 {
2402 m_dirty = TRUE;
2403 if (m_mode & wxLC_REPORT)
2404 {
2405 if (item.m_width == wxLIST_AUTOSIZE_USEHEADER) item.m_width = GetTextLength( item.m_text );
2406 wxListHeaderData *column = new wxListHeaderData( item );
2407 if ((col >= 0) && (col < (int)m_columns.GetCount()))
2408 {
2409 wxNode *node = m_columns.Nth( col );
2410 if (node)
2411 m_columns.Insert( node, column );
2412 }
2413 else
2414 {
2415 m_columns.Append( column );
2416 }
2417 }
2418 }
2419
2420 wxListCtrlCompare list_ctrl_compare_func_2;
2421 long list_ctrl_compare_data;
2422
2423 int LINKAGEMODE list_ctrl_compare_func_1( const void *arg1, const void *arg2 )
2424 {
2425 wxListLineData *line1 = *((wxListLineData**)arg1);
2426 wxListLineData *line2 = *((wxListLineData**)arg2);
2427 wxListItem item;
2428 line1->GetItem( 0, item );
2429 long data1 = item.m_data;
2430 line2->GetItem( 0, item );
2431 long data2 = item.m_data;
2432 return list_ctrl_compare_func_2( data1, data2, list_ctrl_compare_data );
2433 }
2434
2435 void wxListMainWindow::SortItems( wxListCtrlCompare fn, long data )
2436 {
2437 list_ctrl_compare_func_2 = fn;
2438 list_ctrl_compare_data = data;
2439 m_lines.Sort( list_ctrl_compare_func_1 );
2440 }
2441
2442 // -------------------------------------------------------------------------------------
2443 // wxListItem
2444 // -------------------------------------------------------------------------------------
2445
2446 IMPLEMENT_DYNAMIC_CLASS(wxListItem, wxObject)
2447
2448 wxListItem::wxListItem()
2449 {
2450 m_mask = 0;
2451 m_itemId = 0;
2452 m_col = 0;
2453 m_state = 0;
2454 m_stateMask = 0;
2455 m_image = 0;
2456 m_data = 0;
2457 m_format = wxLIST_FORMAT_CENTRE;
2458 m_width = 0;
2459 m_colour = wxBLACK;
2460 }
2461
2462 // -------------------------------------------------------------------------------------
2463 // wxListEvent
2464 // -------------------------------------------------------------------------------------
2465
2466 IMPLEMENT_DYNAMIC_CLASS(wxListEvent, wxNotifyEvent)
2467
2468 wxListEvent::wxListEvent( wxEventType commandType, int id ):
2469 wxNotifyEvent( commandType, id )
2470 {
2471 m_code = 0;
2472 m_itemIndex = 0;
2473 m_oldItemIndex = 0;
2474 m_col = 0;
2475 m_cancelled = FALSE;
2476 m_pointDrag.x = 0;
2477 m_pointDrag.y = 0;
2478 }
2479
2480 // -------------------------------------------------------------------------------------
2481 // wxListCtrl
2482 // -------------------------------------------------------------------------------------
2483
2484 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl, wxControl)
2485
2486 BEGIN_EVENT_TABLE(wxListCtrl,wxControl)
2487 EVT_SIZE (wxListCtrl::OnSize)
2488 EVT_IDLE (wxListCtrl::OnIdle)
2489 END_EVENT_TABLE()
2490
2491 wxListCtrl::wxListCtrl()
2492 {
2493 m_imageListNormal = (wxImageList *) NULL;
2494 m_imageListSmall = (wxImageList *) NULL;
2495 m_imageListState = (wxImageList *) NULL;
2496 m_mainWin = (wxListMainWindow*) NULL;
2497 m_headerWin = (wxListHeaderWindow*) NULL;
2498 }
2499
2500 wxListCtrl::~wxListCtrl()
2501 {
2502 }
2503
2504 bool wxListCtrl::Create( wxWindow *parent, wxWindowID id,
2505 const wxPoint &pos, const wxSize &size,
2506 #if wxUSE_VALIDATORS
2507 # if defined(__VISAGECPP__)
2508 long style, const wxValidator *validator,
2509 # else
2510 long style, const wxValidator &validator,
2511 # endif
2512 #endif
2513 const wxString &name )
2514 {
2515 m_imageListNormal = (wxImageList *) NULL;
2516 m_imageListSmall = (wxImageList *) NULL;
2517 m_imageListState = (wxImageList *) NULL;
2518 m_mainWin = (wxListMainWindow*) NULL;
2519 m_headerWin = (wxListHeaderWindow*) NULL;
2520
2521 long s = style;
2522
2523 if ((s & wxLC_REPORT == 0) &&
2524 (s & wxLC_LIST == 0) &&
2525 (s & wxLC_ICON == 0))
2526 {
2527 s = s | wxLC_LIST;
2528 }
2529
2530 bool ret = wxControl::Create( parent, id, pos, size, s, name );
2531
2532 #if wxUSE_VALIDATORS
2533 SetValidator( validator );
2534 #endif
2535
2536 if (s & wxSUNKEN_BORDER) s -= wxSUNKEN_BORDER;
2537
2538 m_mainWin = new wxListMainWindow( this, -1, wxPoint(0,0), size, s );
2539
2540 if (HasFlag(wxLC_REPORT))
2541 m_headerWin = new wxListHeaderWindow( this, -1, m_mainWin, wxPoint(0,0), wxSize(size.x,23), wxTAB_TRAVERSAL );
2542 else
2543 m_headerWin = (wxListHeaderWindow *) NULL;
2544
2545 SetBackgroundColour( *wxWHITE );
2546
2547 return ret;
2548 }
2549
2550 void wxListCtrl::OnSize( wxSizeEvent &WXUNUSED(event) )
2551 {
2552 /* handled in OnIdle */
2553
2554 if (m_mainWin) m_mainWin->m_dirty = TRUE;
2555 }
2556
2557 void wxListCtrl::SetSingleStyle( long style, bool add )
2558 {
2559 long flag = GetWindowStyle();
2560
2561 if (add)
2562 {
2563 if (style & wxLC_MASK_TYPE) flag = flag & ~wxLC_MASK_TYPE;
2564 if (style & wxLC_MASK_ALIGN) flag = flag & ~wxLC_MASK_ALIGN;
2565 if (style & wxLC_MASK_SORT) flag = flag & ~wxLC_MASK_SORT;
2566 }
2567
2568 if (add)
2569 {
2570 flag |= style;
2571 }
2572 else
2573 {
2574 if (flag & style) flag -= style;
2575 }
2576
2577 SetWindowStyleFlag( flag );
2578 }
2579
2580 void wxListCtrl::SetWindowStyleFlag( long flag )
2581 {
2582 if (m_mainWin)
2583 {
2584 m_mainWin->DeleteEverything();
2585
2586 int width = 0;
2587 int height = 0;
2588 GetClientSize( &width, &height );
2589
2590 m_mainWin->SetMode( flag );
2591
2592 if (flag & wxLC_REPORT)
2593 {
2594 if (!HasFlag(wxLC_REPORT))
2595 {
2596 if (!m_headerWin)
2597 {
2598 m_headerWin = new wxListHeaderWindow( this, -1, m_mainWin,
2599 wxPoint(0,0), wxSize(width,23), wxTAB_TRAVERSAL );
2600 if (HasFlag(wxLC_NO_HEADER))
2601 m_headerWin->Show( FALSE );
2602 }
2603 else
2604 {
2605 if (flag & wxLC_NO_HEADER)
2606 m_headerWin->Show( FALSE );
2607 else
2608 m_headerWin->Show( TRUE );
2609 }
2610 }
2611 }
2612 else
2613 {
2614 if (HasFlag(wxLC_REPORT) && !(HasFlag(wxLC_NO_HEADER)))
2615 {
2616 m_headerWin->Show( FALSE );
2617 }
2618 }
2619 }
2620
2621 wxWindow::SetWindowStyleFlag( flag );
2622 }
2623
2624 bool wxListCtrl::GetColumn(int col, wxListItem &item) const
2625 {
2626 m_mainWin->GetColumn( col, item );
2627 return TRUE;
2628 }
2629
2630 bool wxListCtrl::SetColumn( int col, wxListItem& item )
2631 {
2632 m_mainWin->SetColumn( col, item );
2633 return TRUE;
2634 }
2635
2636 int wxListCtrl::GetColumnWidth( int col ) const
2637 {
2638 return m_mainWin->GetColumnWidth( col );
2639 }
2640
2641 bool wxListCtrl::SetColumnWidth( int col, int width )
2642 {
2643 m_mainWin->SetColumnWidth( col, width );
2644 return TRUE;
2645 }
2646
2647 int wxListCtrl::GetCountPerPage() const
2648 {
2649 return m_mainWin->GetCountPerPage(); // different from Windows ?
2650 }
2651
2652 bool wxListCtrl::GetItem( wxListItem &info ) const
2653 {
2654 m_mainWin->GetItem( info );
2655 return TRUE;
2656 }
2657
2658 bool wxListCtrl::SetItem( wxListItem &info )
2659 {
2660 m_mainWin->SetItem( info );
2661 return TRUE;
2662 }
2663
2664 long wxListCtrl::SetItem( long index, int col, const wxString& label, int imageId )
2665 {
2666 wxListItem info;
2667 info.m_text = label;
2668 info.m_mask = wxLIST_MASK_TEXT;
2669 info.m_itemId = index;
2670 info.m_col = col;
2671 if ( imageId > -1 )
2672 {
2673 info.m_image = imageId;
2674 info.m_mask |= wxLIST_MASK_IMAGE;
2675 };
2676 m_mainWin->SetItem(info);
2677 return TRUE;
2678 }
2679
2680 int wxListCtrl::GetItemState( long item, long stateMask ) const
2681 {
2682 return m_mainWin->GetItemState( item, stateMask );
2683 }
2684
2685 bool wxListCtrl::SetItemState( long item, long state, long stateMask )
2686 {
2687 m_mainWin->SetItemState( item, state, stateMask );
2688 return TRUE;
2689 }
2690
2691 bool wxListCtrl::SetItemImage( long item, int image, int WXUNUSED(selImage) )
2692 {
2693 wxListItem info;
2694 info.m_image = image;
2695 info.m_mask = wxLIST_MASK_IMAGE;
2696 info.m_itemId = item;
2697 m_mainWin->SetItem( info );
2698 return TRUE;
2699 }
2700
2701 wxString wxListCtrl::GetItemText( long item ) const
2702 {
2703 wxListItem info;
2704 info.m_itemId = item;
2705 m_mainWin->GetItem( info );
2706 return info.m_text;
2707 }
2708
2709 void wxListCtrl::SetItemText( long item, const wxString &str )
2710 {
2711 wxListItem info;
2712 info.m_mask = wxLIST_MASK_TEXT;
2713 info.m_itemId = item;
2714 info.m_text = str;
2715 m_mainWin->SetItem( info );
2716 }
2717
2718 long wxListCtrl::GetItemData( long item ) const
2719 {
2720 wxListItem info;
2721 info.m_itemId = item;
2722 m_mainWin->GetItem( info );
2723 return info.m_data;
2724 }
2725
2726 bool wxListCtrl::SetItemData( long item, long data )
2727 {
2728 wxListItem info;
2729 info.m_mask = wxLIST_MASK_DATA;
2730 info.m_itemId = item;
2731 info.m_data = data;
2732 m_mainWin->SetItem( info );
2733 return TRUE;
2734 }
2735
2736 bool wxListCtrl::GetItemRect( long item, wxRect &rect, int WXUNUSED(code) ) const
2737 {
2738 m_mainWin->GetItemRect( item, rect );
2739 return TRUE;
2740 }
2741
2742 bool wxListCtrl::GetItemPosition( long item, wxPoint& pos ) const
2743 {
2744 m_mainWin->GetItemPosition( item, pos );
2745 return TRUE;
2746 }
2747
2748 bool wxListCtrl::SetItemPosition( long WXUNUSED(item), const wxPoint& WXUNUSED(pos) )
2749 {
2750 return 0;
2751 }
2752
2753 int wxListCtrl::GetItemCount() const
2754 {
2755 return m_mainWin->GetItemCount();
2756 }
2757
2758 int wxListCtrl::GetColumnCount() const
2759 {
2760 return m_mainWin->GetColumnCount();
2761 }
2762
2763 void wxListCtrl::SetItemSpacing( int spacing, bool isSmall )
2764 {
2765 m_mainWin->SetItemSpacing( spacing, isSmall );
2766 }
2767
2768 int wxListCtrl::GetItemSpacing( bool isSmall ) const
2769 {
2770 return m_mainWin->GetItemSpacing( isSmall );
2771 }
2772
2773 int wxListCtrl::GetSelectedItemCount() const
2774 {
2775 return m_mainWin->GetSelectedItemCount();
2776 }
2777
2778 /*
2779 wxColour wxListCtrl::GetTextColour() const
2780 {
2781 }
2782
2783 void wxListCtrl::SetTextColour(const wxColour& WXUNUSED(col))
2784 {
2785 }
2786 */
2787
2788 long wxListCtrl::GetTopItem() const
2789 {
2790 return 0;
2791 }
2792
2793 long wxListCtrl::GetNextItem( long item, int geom, int state ) const
2794 {
2795 return m_mainWin->GetNextItem( item, geom, state );
2796 }
2797
2798 wxImageList *wxListCtrl::GetImageList(int which) const
2799 {
2800 if (which == wxIMAGE_LIST_NORMAL)
2801 {
2802 return m_imageListNormal;
2803 }
2804 else if (which == wxIMAGE_LIST_SMALL)
2805 {
2806 return m_imageListSmall;
2807 }
2808 else if (which == wxIMAGE_LIST_STATE)
2809 {
2810 return m_imageListState;
2811 }
2812 return (wxImageList *) NULL;
2813 }
2814
2815 void wxListCtrl::SetImageList( wxImageList *imageList, int which )
2816 {
2817 m_mainWin->SetImageList( imageList, which );
2818 }
2819
2820 bool wxListCtrl::Arrange( int WXUNUSED(flag) )
2821 {
2822 return 0;
2823 }
2824
2825 bool wxListCtrl::DeleteItem( long item )
2826 {
2827 m_mainWin->DeleteItem( item );
2828 return TRUE;
2829 }
2830
2831 bool wxListCtrl::DeleteAllItems()
2832 {
2833 m_mainWin->DeleteAllItems();
2834 return TRUE;
2835 }
2836
2837 bool wxListCtrl::DeleteAllColumns()
2838 {
2839 for ( size_t n = 0; n < m_mainWin->m_columns.GetCount(); n++ )
2840 DeleteColumn(n);
2841
2842 return TRUE;
2843 }
2844
2845 void wxListCtrl::ClearAll()
2846 {
2847 m_mainWin->DeleteEverything();
2848 }
2849
2850 bool wxListCtrl::DeleteColumn( int col )
2851 {
2852 m_mainWin->DeleteColumn( col );
2853 return TRUE;
2854 }
2855
2856 void wxListCtrl::Edit( long item )
2857 {
2858 m_mainWin->Edit( item );
2859 }
2860
2861 bool wxListCtrl::EnsureVisible( long item )
2862 {
2863 m_mainWin->EnsureVisible( item );
2864 return TRUE;
2865 }
2866
2867 long wxListCtrl::FindItem( long start, const wxString& str, bool partial )
2868 {
2869 return m_mainWin->FindItem( start, str, partial );
2870 }
2871
2872 long wxListCtrl::FindItem( long start, long data )
2873 {
2874 return m_mainWin->FindItem( start, data );
2875 }
2876
2877 long wxListCtrl::FindItem( long WXUNUSED(start), const wxPoint& WXUNUSED(pt),
2878 int WXUNUSED(direction))
2879 {
2880 return 0;
2881 }
2882
2883 long wxListCtrl::HitTest( const wxPoint &point, int &flags )
2884 {
2885 return m_mainWin->HitTest( (int)point.x, (int)point.y, flags );
2886 }
2887
2888 long wxListCtrl::InsertItem( wxListItem& info )
2889 {
2890 m_mainWin->InsertItem( info );
2891 return info.m_itemId;
2892 }
2893
2894 long wxListCtrl::InsertItem( long index, const wxString &label )
2895 {
2896 wxListItem info;
2897 info.m_text = label;
2898 info.m_mask = wxLIST_MASK_TEXT;
2899 info.m_itemId = index;
2900 return InsertItem( info );
2901 }
2902
2903 long wxListCtrl::InsertItem( long index, int imageIndex )
2904 {
2905 wxListItem info;
2906 info.m_mask = wxLIST_MASK_IMAGE;
2907 info.m_image = imageIndex;
2908 info.m_itemId = index;
2909 return InsertItem( info );
2910 }
2911
2912 long wxListCtrl::InsertItem( long index, const wxString &label, int imageIndex )
2913 {
2914 wxListItem info;
2915 info.m_text = label;
2916 info.m_image = imageIndex;
2917 info.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_IMAGE;
2918 info.m_itemId = index;
2919 return InsertItem( info );
2920 }
2921
2922 long wxListCtrl::InsertColumn( long col, wxListItem &item )
2923 {
2924 m_mainWin->InsertColumn( col, item );
2925 return 0;
2926 }
2927
2928 long wxListCtrl::InsertColumn( long col, const wxString &heading,
2929 int format, int width )
2930 {
2931 wxListItem item;
2932 item.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_FORMAT;
2933 item.m_text = heading;
2934 if (width >= -2)
2935 {
2936 item.m_mask |= wxLIST_MASK_WIDTH;
2937 item.m_width = width;
2938 }
2939 item.m_format = format;
2940
2941 return InsertColumn( col, item );
2942 }
2943
2944 bool wxListCtrl::ScrollList( int WXUNUSED(dx), int WXUNUSED(dy) )
2945 {
2946 return 0;
2947 }
2948
2949 // Sort items.
2950 // fn is a function which takes 3 long arguments: item1, item2, data.
2951 // item1 is the long data associated with a first item (NOT the index).
2952 // item2 is the long data associated with a second item (NOT the index).
2953 // data is the same value as passed to SortItems.
2954 // The return value is a negative number if the first item should precede the second
2955 // item, a positive number of the second item should precede the first,
2956 // or zero if the two items are equivalent.
2957 // data is arbitrary data to be passed to the sort function.
2958
2959 bool wxListCtrl::SortItems( wxListCtrlCompare fn, long data )
2960 {
2961 m_mainWin->SortItems( fn, data );
2962 return TRUE;
2963 }
2964
2965 void wxListCtrl::OnIdle( wxIdleEvent &WXUNUSED(event) )
2966 {
2967 if (!m_mainWin->m_dirty) return;
2968
2969 int cw = 0;
2970 int ch = 0;
2971 GetClientSize( &cw, &ch );
2972
2973 int x = 0;
2974 int y = 0;
2975 int w = 0;
2976 int h = 0;
2977
2978 if (HasFlag(wxLC_REPORT) && !HasFlag(wxLC_NO_HEADER))
2979 {
2980 m_headerWin->GetPosition( &x, &y );
2981 m_headerWin->GetSize( &w, &h );
2982 if ((x != 0) || (y != 0) || (w != cw) || (h != 23))
2983 m_headerWin->SetSize( 0, 0, cw, 23 );
2984
2985 m_mainWin->GetPosition( &x, &y );
2986 m_mainWin->GetSize( &w, &h );
2987 if ((x != 0) || (y != 24) || (w != cw) || (h != ch-24))
2988 m_mainWin->SetSize( 0, 24, cw, ch-24 );
2989 }
2990 else
2991 {
2992 m_mainWin->GetPosition( &x, &y );
2993 m_mainWin->GetSize( &w, &h );
2994 if ((x != 0) || (y != 24) || (w != cw) || (h != ch))
2995 m_mainWin->SetSize( 0, 0, cw, ch );
2996 }
2997
2998 m_mainWin->CalculatePositions();
2999 m_mainWin->RealizeChanges();
3000 m_mainWin->m_dirty = FALSE;
3001 m_mainWin->Refresh();
3002 }
3003
3004 bool wxListCtrl::SetBackgroundColour( const wxColour &colour )
3005 {
3006 if ( !wxWindow::SetBackgroundColour( colour ) )
3007 return FALSE;
3008
3009 if (m_mainWin)
3010 {
3011 m_mainWin->SetBackgroundColour( colour );
3012 m_mainWin->m_dirty = TRUE;
3013 }
3014
3015 if (m_headerWin)
3016 {
3017 // m_headerWin->SetBackgroundColour( colour );
3018 }
3019
3020 return TRUE;
3021 }
3022
3023 bool wxListCtrl::SetForegroundColour( const wxColour &colour )
3024 {
3025 if ( !wxWindow::SetForegroundColour( colour ) )
3026 return FALSE;
3027
3028 if (m_mainWin)
3029 {
3030 m_mainWin->SetForegroundColour( colour );
3031 m_mainWin->m_dirty = TRUE;
3032 }
3033
3034 if (m_headerWin)
3035 {
3036 m_headerWin->SetForegroundColour( colour );
3037 }
3038
3039 return TRUE;
3040 }
3041
3042 bool wxListCtrl::SetFont( const wxFont &font )
3043 {
3044 if ( !wxWindow::SetFont( font ) )
3045 return FALSE;
3046
3047 if (m_mainWin)
3048 {
3049 m_mainWin->SetFont( font );
3050 m_mainWin->m_dirty = TRUE;
3051 }
3052
3053 if (m_headerWin)
3054 {
3055 m_headerWin->SetFont( font );
3056 }
3057
3058 return TRUE;
3059 }
3060