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