]> git.saurik.com Git - wxWidgets.git/blob - src/generic/listctrl.cpp
Various things related to wxFileDialog and attributes.
[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
857 // do *not* use the listctrl colour for headers - one day we will have a
858 // function to set it separately
859
860 x = 1;
861 y = 1;
862 int numColumns = m_owner->GetColumnCount();
863 wxListItem item;
864 for (int i = 0; i < numColumns; i++)
865 {
866 m_owner->GetColumn( i, item );
867 int cw = item.m_width-2;
868 #if wxUSE_GENERIC_LIST_EXTENSIONS
869 if ((i+1 == numColumns) || ( dc.LogicalToDeviceX(x+item.m_width) > w-5))
870 cw = dc.DeviceToLogicalX(w)-x-1;
871 #else
872 if ((i+1 == numColumns) || (x+item.m_width > w-5)) cw = w-x-1;
873 #endif
874 dc.SetPen( *wxWHITE_PEN );
875
876 DoDrawRect( &dc, x, y, cw, h-2 );
877 dc.SetClippingRegion( x, y, cw-5, h-4 );
878 dc.DrawText( item.m_text, x+4, y+3 );
879 dc.DestroyClippingRegion();
880 x += item.m_width;
881 #if wxUSE_GENERIC_LIST_EXTENSIONS
882 if (dc.LogicalToDeviceX(x) > w+5) break;
883 #else
884 if (x > w+5) break;
885 #endif
886 }
887 dc.EndDrawing();
888 }
889
890 void wxListHeaderWindow::DrawCurrent()
891 {
892 int x1 = m_currentX;
893 int y1 = 0;
894 int x2 = m_currentX-1;
895 int y2 = 0;
896 int dummy;
897 m_owner->GetClientSize( &dummy, &y2 );
898 ClientToScreen( &x1, &y1 );
899 m_owner->ClientToScreen( &x2, &y2 );
900
901 wxScreenDC dc;
902 dc.SetLogicalFunction( wxINVERT );
903 dc.SetPen( wxPen( *wxBLACK, 2, wxSOLID ) );
904 dc.SetBrush( *wxTRANSPARENT_BRUSH );
905
906 dc.DrawLine( x1, y1, x2, y2 );
907
908 dc.SetLogicalFunction( wxCOPY );
909
910 dc.SetPen( wxNullPen );
911 dc.SetBrush( wxNullBrush );
912 }
913
914 void wxListHeaderWindow::OnMouse( wxMouseEvent &event )
915 {
916 int x = event.GetX();
917 int y = event.GetY();
918 if (m_isDragging)
919 {
920 DrawCurrent();
921 if (event.ButtonUp())
922 {
923 ReleaseMouse();
924 m_isDragging = FALSE;
925 m_owner->SetColumnWidth( m_column, m_currentX-m_minX );
926 }
927 else
928 {
929 int size_x = 0;
930 int dummy;
931 GetClientSize( &size_x, & dummy );
932 if (x > m_minX+7)
933 m_currentX = x;
934 else
935 m_currentX = m_minX+7;
936 if (m_currentX > size_x-7) m_currentX = size_x-7;
937 DrawCurrent();
938 }
939 return;
940 }
941
942 m_minX = 0;
943 bool hit_border = FALSE;
944 int xpos = 0;
945 for (int j = 0; j < m_owner->GetColumnCount()-1; j++)
946 {
947 xpos += m_owner->GetColumnWidth( j );
948 m_column = j;
949 if ((abs(x-xpos) < 3) && (y < 22))
950 {
951 hit_border = TRUE;
952 break;
953 }
954 if (x-xpos < 0)
955 {
956 break;
957 }
958 m_minX = xpos;
959 }
960
961 if (event.LeftDown())
962 {
963 if (hit_border)
964 {
965 m_isDragging = TRUE;
966 m_currentX = x;
967 DrawCurrent();
968 CaptureMouse();
969 return;
970 }
971 else
972 {
973 wxListEvent le( wxEVT_COMMAND_LIST_COL_CLICK, GetParent()->GetId() );
974 le.SetEventObject( GetParent() );
975 le.m_col = m_column;
976 GetParent()->GetEventHandler()->ProcessEvent( le );
977 return;
978 }
979 }
980
981 if (event.Moving())
982 {
983 if (hit_border)
984 {
985 if (m_currentCursor == wxSTANDARD_CURSOR) SetCursor( * m_resizeCursor );
986 m_currentCursor = m_resizeCursor;
987 }
988 else
989 {
990 if (m_currentCursor != wxSTANDARD_CURSOR) SetCursor( * wxSTANDARD_CURSOR );
991 m_currentCursor = wxSTANDARD_CURSOR;
992 }
993 }
994 }
995
996 void wxListHeaderWindow::OnSetFocus( wxFocusEvent &WXUNUSED(event) )
997 {
998 m_owner->SetFocus();
999 }
1000
1001 //-----------------------------------------------------------------------------
1002 // wxListRenameTimer (internal)
1003 //-----------------------------------------------------------------------------
1004
1005 wxListRenameTimer::wxListRenameTimer( wxListMainWindow *owner )
1006 {
1007 m_owner = owner;
1008 }
1009
1010 void wxListRenameTimer::Notify()
1011 {
1012 m_owner->OnRenameTimer();
1013 }
1014
1015 //-----------------------------------------------------------------------------
1016 // wxListTextCtrl (internal)
1017 //-----------------------------------------------------------------------------
1018
1019 IMPLEMENT_DYNAMIC_CLASS(wxListTextCtrl,wxTextCtrl);
1020
1021 BEGIN_EVENT_TABLE(wxListTextCtrl,wxTextCtrl)
1022 EVT_CHAR (wxListTextCtrl::OnChar)
1023 EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus)
1024 END_EVENT_TABLE()
1025
1026 wxListTextCtrl::wxListTextCtrl( wxWindow *parent, const wxWindowID id,
1027 bool *accept, wxString *res, wxListMainWindow *owner,
1028 const wxString &value, const wxPoint &pos, const wxSize &size,
1029 #if wxUSE_VALIDATORS
1030 int style, const wxValidator& validator, const wxString &name ) :
1031 #endif
1032 wxTextCtrl( parent, id, value, pos, size, style, validator, name )
1033 {
1034 m_res = res;
1035 m_accept = accept;
1036 m_owner = owner;
1037 (*m_accept) = FALSE;
1038 (*m_res) = "";
1039 m_startValue = value;
1040 }
1041
1042 void wxListTextCtrl::OnChar( wxKeyEvent &event )
1043 {
1044 if (event.m_keyCode == WXK_RETURN)
1045 {
1046 (*m_accept) = TRUE;
1047 (*m_res) = GetValue();
1048 m_owner->SetFocus();
1049 return;
1050 }
1051 if (event.m_keyCode == WXK_ESCAPE)
1052 {
1053 (*m_accept) = FALSE;
1054 (*m_res) = "";
1055 m_owner->SetFocus();
1056 return;
1057 }
1058 event.Skip();
1059 }
1060
1061 void wxListTextCtrl::OnKillFocus( wxFocusEvent &WXUNUSED(event) )
1062 {
1063 if (wxPendingDelete.Member(this)) return;
1064
1065 wxPendingDelete.Append(this);
1066
1067 if ((*m_accept) && ((*m_res) != m_startValue))
1068 m_owner->OnRenameAccept();
1069 }
1070
1071 //-----------------------------------------------------------------------------
1072 // wxListMainWindow
1073 //-----------------------------------------------------------------------------
1074
1075 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow,wxScrolledWindow);
1076
1077 BEGIN_EVENT_TABLE(wxListMainWindow,wxScrolledWindow)
1078 EVT_PAINT (wxListMainWindow::OnPaint)
1079 EVT_SIZE (wxListMainWindow::OnSize)
1080 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse)
1081 EVT_CHAR (wxListMainWindow::OnChar)
1082 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown)
1083 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus)
1084 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus)
1085 EVT_SCROLLWIN (wxListMainWindow::OnScroll)
1086 END_EVENT_TABLE()
1087
1088 wxListMainWindow::wxListMainWindow()
1089 {
1090 m_mode = 0;
1091 m_lines.DeleteContents( TRUE );
1092 m_columns.DeleteContents( TRUE );
1093 m_current = (wxListLineData *) NULL;
1094 m_visibleLines = 0;
1095 m_hilightBrush = (wxBrush *) NULL;
1096 m_xScroll = 0;
1097 m_yScroll = 0;
1098 m_dirty = TRUE;
1099 m_small_image_list = (wxImageList *) NULL;
1100 m_normal_image_list = (wxImageList *) NULL;
1101 m_small_spacing = 30;
1102 m_normal_spacing = 40;
1103 m_hasFocus = FALSE;
1104 m_usedKeys = TRUE;
1105 m_lastOnSame = FALSE;
1106 m_renameTimer = new wxListRenameTimer( this );
1107 m_isCreated = FALSE;
1108 m_dragCount = 0;
1109 }
1110
1111 wxListMainWindow::wxListMainWindow( wxWindow *parent, wxWindowID id,
1112 const wxPoint &pos, const wxSize &size,
1113 long style, const wxString &name ) :
1114 wxScrolledWindow( parent, id, pos, size, style|wxHSCROLL|wxVSCROLL, name )
1115 {
1116 m_mode = style;
1117 m_lines.DeleteContents( TRUE );
1118 m_columns.DeleteContents( TRUE );
1119 m_current = (wxListLineData *) NULL;
1120 m_dirty = TRUE;
1121 m_visibleLines = 0;
1122 m_hilightBrush = new wxBrush( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT), wxSOLID );
1123 m_small_image_list = (wxImageList *) NULL;
1124 m_normal_image_list = (wxImageList *) NULL;
1125 m_small_spacing = 30;
1126 m_normal_spacing = 40;
1127 m_hasFocus = FALSE;
1128 m_dragCount = 0;
1129 m_isCreated = FALSE;
1130 wxSize sz = size;
1131 sz.y = 25;
1132
1133 if (m_mode & wxLC_REPORT)
1134 {
1135 #if wxUSE_GENERIC_LIST_EXTENSIONS
1136 m_xScroll = 15;
1137 #else
1138 m_xScroll = 0;
1139 #endif
1140 m_yScroll = 15;
1141 }
1142 else
1143 {
1144 m_xScroll = 15;
1145 m_yScroll = 0;
1146 }
1147 SetScrollbars( m_xScroll, m_yScroll, 0, 0, 0, 0 );
1148
1149 m_usedKeys = TRUE;
1150 m_lastOnSame = FALSE;
1151 m_renameTimer = new wxListRenameTimer( this );
1152 m_renameAccept = FALSE;
1153
1154 SetBackgroundColour( *wxWHITE );
1155 }
1156
1157 wxListMainWindow::~wxListMainWindow()
1158 {
1159 if (m_hilightBrush) delete m_hilightBrush;
1160
1161 delete m_renameTimer;
1162 }
1163
1164 void wxListMainWindow::RefreshLine( wxListLineData *line )
1165 {
1166 int x = 0;
1167 int y = 0;
1168 int w = 0;
1169 int h = 0;
1170 if (line)
1171 {
1172 wxClientDC dc(this);
1173 PrepareDC( dc );
1174 line->GetExtent( x, y, w, h );
1175 wxRect rect(
1176 dc.LogicalToDeviceX(x-3),
1177 dc.LogicalToDeviceY(y-3),
1178 dc.LogicalToDeviceXRel(w+6),
1179 dc.LogicalToDeviceXRel(h+6) );
1180 Refresh( TRUE, &rect );
1181 }
1182 }
1183
1184 void wxListMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
1185 {
1186 // Note: a wxPaintDC must be constructed even if no drawing is
1187 // done (a Windows requirement).
1188 wxPaintDC dc( this );
1189 PrepareDC( dc );
1190
1191 if (m_dirty) return;
1192
1193 if (m_lines.GetCount() == 0) return;
1194
1195 dc.BeginDrawing();
1196
1197 dc.SetFont( GetFont() );
1198
1199 if (m_mode & wxLC_REPORT)
1200 {
1201 int lineSpacing = 0;
1202 wxListLineData *line = (wxListLineData*)m_lines.First()->Data();
1203 int dummy = 0;
1204 line->GetSize( dummy, lineSpacing );
1205 lineSpacing += 1;
1206
1207 int y_s = m_yScroll*GetScrollPos( wxVERTICAL );
1208
1209 wxNode *node = m_lines.Nth( y_s / lineSpacing );
1210 for (int i = 0; i < m_visibleLines+2; i++)
1211 {
1212 if (!node) break;
1213
1214 line = (wxListLineData*)node->Data();
1215 line->Draw( &dc );
1216 node = node->Next();
1217 }
1218 }
1219 else
1220 {
1221 wxNode *node = m_lines.First();
1222 while (node)
1223 {
1224 wxListLineData *line = (wxListLineData*)node->Data();
1225 line->Draw( &dc );
1226 node = node->Next();
1227 }
1228 }
1229
1230 if (m_current) m_current->DrawRubberBand( &dc, m_hasFocus );
1231
1232 dc.EndDrawing();
1233 }
1234
1235 void wxListMainWindow::HilightAll( bool on )
1236 {
1237 wxNode *node = m_lines.First();
1238 while (node)
1239 {
1240 wxListLineData *line = (wxListLineData *)node->Data();
1241 if (line->IsHilighted() != on)
1242 {
1243 line->Hilight( on );
1244 RefreshLine( line );
1245 }
1246 node = node->Next();
1247 }
1248 }
1249
1250 void wxListMainWindow::SendNotify( wxListLineData *line, wxEventType command )
1251 {
1252 wxListEvent le( command, GetParent()->GetId() );
1253 le.SetEventObject( GetParent() );
1254 le.m_itemIndex = GetIndexOfLine( line );
1255 line->GetItem( 0, le.m_item );
1256 // GetParent()->GetEventHandler()->ProcessEvent( le );
1257 GetParent()->GetEventHandler()->AddPendingEvent( le );
1258 }
1259
1260 void wxListMainWindow::FocusLine( wxListLineData *WXUNUSED(line) )
1261 {
1262 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_FOCUSSED );
1263 }
1264
1265 void wxListMainWindow::UnfocusLine( wxListLineData *WXUNUSED(line) )
1266 {
1267 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_UNFOCUSSED );
1268 }
1269
1270 void wxListMainWindow::SelectLine( wxListLineData *line )
1271 {
1272 SendNotify( line, wxEVT_COMMAND_LIST_ITEM_SELECTED );
1273 }
1274
1275 void wxListMainWindow::DeselectLine( wxListLineData *line )
1276 {
1277 SendNotify( line, wxEVT_COMMAND_LIST_ITEM_DESELECTED );
1278 }
1279
1280 void wxListMainWindow::DeleteLine( wxListLineData *line )
1281 {
1282 SendNotify( line, wxEVT_COMMAND_LIST_DELETE_ITEM );
1283 }
1284
1285 /* *** */
1286
1287 void wxListMainWindow::EditLabel( long item )
1288 {
1289 wxNode *node = m_lines.Nth( item );
1290 wxCHECK_RET( node, wxT("wrong index in wxListCtrl::Edit()") );
1291
1292 m_currentEdit = (wxListLineData*) node->Data();
1293
1294 wxListEvent le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT, GetParent()->GetId() );
1295 le.SetEventObject( GetParent() );
1296 le.m_itemIndex = GetIndexOfLine( m_currentEdit );
1297 m_currentEdit->GetItem( 0, le.m_item );
1298 GetParent()->GetEventHandler()->ProcessEvent( le );
1299
1300 if (!le.IsAllowed())
1301 return;
1302
1303 // We have to call this here because the label in
1304 // question might just have been added and no screen
1305 // update taken place.
1306 if (m_dirty) wxYield();
1307
1308 wxString s;
1309 m_currentEdit->GetText( 0, s );
1310 int x = 0;
1311 int y = 0;
1312 int w = 0;
1313 int h = 0;
1314 m_currentEdit->GetLabelExtent( x, y, w, h );
1315
1316 wxClientDC dc(this);
1317 PrepareDC( dc );
1318 x = dc.LogicalToDeviceX( x );
1319 y = dc.LogicalToDeviceY( y );
1320
1321 wxListTextCtrl *text = new wxListTextCtrl(
1322 this, -1, &m_renameAccept, &m_renameRes, this, s, wxPoint(x-4,y-4), wxSize(w+11,h+8) );
1323 text->SetFocus();
1324 }
1325
1326 void wxListMainWindow::OnRenameTimer()
1327 {
1328 wxCHECK_RET( m_current, wxT("invalid m_current") );
1329
1330 Edit( m_lines.IndexOf( m_current ) );
1331 }
1332
1333 void wxListMainWindow::OnRenameAccept()
1334 {
1335 wxListEvent le( wxEVT_COMMAND_LIST_END_LABEL_EDIT, GetParent()->GetId() );
1336 le.SetEventObject( GetParent() );
1337 le.m_itemIndex = GetIndexOfLine( m_currentEdit );
1338 m_currentEdit->GetItem( 0, le.m_item );
1339 le.m_item.m_text = m_renameRes;
1340 GetParent()->GetEventHandler()->ProcessEvent( le );
1341
1342 if (!le.IsAllowed()) return;
1343
1344 wxListItem info;
1345 info.m_mask = wxLIST_MASK_TEXT;
1346 info.m_itemId = le.m_itemIndex;
1347 info.m_text = m_renameRes;
1348 info.SetTextColour(le.m_item.GetTextColour());
1349 SetItem( info );
1350 }
1351
1352 void wxListMainWindow::OnMouse( wxMouseEvent &event )
1353 {
1354 if (GetParent()->GetEventHandler()->ProcessEvent( event)) return;
1355
1356 if (!m_current) return;
1357 if (m_dirty) return;
1358 if ( !(event.Dragging() || event.ButtonDown() || event.LeftUp() || event.ButtonDClick()) ) return;
1359
1360 wxClientDC dc(this);
1361 PrepareDC(dc);
1362 long x = dc.DeviceToLogicalX( (long)event.GetX() );
1363 long y = dc.DeviceToLogicalY( (long)event.GetY() );
1364
1365 /* Did we actually hit an item ? */
1366 long hitResult = 0;
1367 wxNode *node = m_lines.First();
1368 wxListLineData *line = (wxListLineData *) NULL;
1369 while (node)
1370 {
1371 line = (wxListLineData*)node->Data();
1372 hitResult = line->IsHit( x, y );
1373 if (hitResult) break;
1374 line = (wxListLineData *) NULL;
1375 node = node->Next();
1376 }
1377
1378 if (event.Dragging())
1379 {
1380 if (m_dragCount == 0)
1381 m_dragStart = wxPoint(x,y);
1382
1383 m_dragCount++;
1384
1385 if (m_dragCount != 3) return;
1386
1387 int command = wxEVT_COMMAND_LIST_BEGIN_DRAG;
1388 if (event.RightIsDown()) command = wxEVT_COMMAND_LIST_BEGIN_RDRAG;
1389
1390 wxListEvent le( command, GetParent()->GetId() );
1391 le.SetEventObject( GetParent() );
1392 le.m_pointDrag = m_dragStart;
1393 GetParent()->GetEventHandler()->ProcessEvent( le );
1394
1395 return;
1396 }
1397 else
1398 {
1399 m_dragCount = 0;
1400 }
1401
1402 if (!line) return;
1403
1404 if (event.ButtonDClick())
1405 {
1406 m_usedKeys = FALSE;
1407 m_lastOnSame = FALSE;
1408 m_renameTimer->Stop();
1409
1410 SendNotify( line, wxEVT_COMMAND_LIST_ITEM_ACTIVATED );
1411
1412 return;
1413 }
1414
1415 if (event.LeftUp() && m_lastOnSame)
1416 {
1417 m_usedKeys = FALSE;
1418 if ((line == m_current) &&
1419 (hitResult == wxLIST_HITTEST_ONITEMLABEL) &&
1420 (m_mode & wxLC_EDIT_LABELS) )
1421 {
1422 m_renameTimer->Start( 100, TRUE );
1423 }
1424 m_lastOnSame = FALSE;
1425 return;
1426 }
1427
1428 if (event.RightDown())
1429 {
1430 SendNotify( line, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK );
1431 return;
1432 }
1433
1434 if (event.MiddleDown())
1435 {
1436 SendNotify( line, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK );
1437 return;
1438 }
1439
1440 if (event.LeftDown())
1441 {
1442 m_usedKeys = FALSE;
1443 wxListLineData *oldCurrent = m_current;
1444 if (m_mode & wxLC_SINGLE_SEL)
1445 {
1446 m_current = line;
1447 HilightAll( FALSE );
1448 m_current->ReverseHilight();
1449 RefreshLine( m_current );
1450 }
1451 else
1452 {
1453 if (event.ShiftDown())
1454 {
1455 m_current = line;
1456 m_current->ReverseHilight();
1457 RefreshLine( m_current );
1458 }
1459 else if (event.ControlDown())
1460 {
1461 m_current = line;
1462
1463 int numOfCurrent = -1;
1464 node = m_lines.First();
1465 while (node)
1466 {
1467 wxListLineData *test_line = (wxListLineData*)node->Data();
1468 numOfCurrent++;
1469 if (test_line == oldCurrent) break;
1470 node = node->Next();
1471 }
1472
1473 int numOfLine = -1;
1474 node = m_lines.First();
1475 while (node)
1476 {
1477 wxListLineData *test_line = (wxListLineData*)node->Data();
1478 numOfLine++;
1479 if (test_line == line) break;
1480 node = node->Next();
1481 }
1482
1483 if (numOfLine < numOfCurrent)
1484 {
1485 int i = numOfLine;
1486 numOfLine = numOfCurrent;
1487 numOfCurrent = i;
1488 }
1489
1490 wxNode *node = m_lines.Nth( numOfCurrent );
1491 for (int i = 0; i <= numOfLine-numOfCurrent; i++)
1492 {
1493 wxListLineData *test_line= (wxListLineData*)node->Data();
1494 test_line->Hilight(TRUE);
1495 RefreshLine( test_line );
1496 node = node->Next();
1497 }
1498 }
1499 else
1500 {
1501 m_current = line;
1502 HilightAll( FALSE );
1503 m_current->ReverseHilight();
1504 RefreshLine( m_current );
1505 }
1506 }
1507 if (m_current != oldCurrent)
1508 {
1509 RefreshLine( oldCurrent );
1510 UnfocusLine( oldCurrent );
1511 FocusLine( m_current );
1512 }
1513 m_lastOnSame = (m_current == oldCurrent);
1514 return;
1515 }
1516 }
1517
1518 void wxListMainWindow::MoveToFocus()
1519 {
1520 if (!m_current) return;
1521
1522 int x = 0;
1523 int y = 0;
1524 int w = 0;
1525 int h = 0;
1526 m_current->GetExtent( x, y, w, h );
1527
1528 int w_p = 0;
1529 int h_p = 0;
1530 GetClientSize( &w_p, &h_p );
1531
1532 if (m_mode & wxLC_REPORT)
1533 {
1534 int y_s = m_yScroll*GetScrollPos( wxVERTICAL );
1535 if ((y > y_s) && (y+h < y_s+h_p)) return;
1536 if (y-y_s < 5) { Scroll( -1, (y-5-h_p/2)/m_yScroll ); }
1537 if (y+h+5 > y_s+h_p) { Scroll( -1, (y+h-h_p/2+h+15)/m_yScroll); }
1538 }
1539 else
1540 {
1541 int x_s = m_xScroll*GetScrollPos( wxHORIZONTAL );
1542 if ((x > x_s) && (x+w < x_s+w_p)) return;
1543 if (x-x_s < 5) { Scroll( (x-5)/m_xScroll, -1 ); }
1544 if (x+w-5 > x_s+w_p) { Scroll( (x+w-w_p+15)/m_xScroll, -1 ); }
1545 }
1546 }
1547
1548 void wxListMainWindow::OnArrowChar( wxListLineData *newCurrent, bool shiftDown )
1549 {
1550 if ((m_mode & wxLC_SINGLE_SEL) || (m_usedKeys == FALSE)) m_current->Hilight( FALSE );
1551 wxListLineData *oldCurrent = m_current;
1552 m_current = newCurrent;
1553 MoveToFocus();
1554 if (shiftDown || (m_mode & wxLC_SINGLE_SEL)) m_current->Hilight( TRUE );
1555 RefreshLine( m_current );
1556 RefreshLine( oldCurrent );
1557 FocusLine( m_current );
1558 UnfocusLine( oldCurrent );
1559 }
1560
1561 void wxListMainWindow::OnKeyDown( wxKeyEvent &event )
1562 {
1563 wxWindow *parent = GetParent();
1564
1565 /* we propagate the key event up */
1566 wxKeyEvent ke( wxEVT_KEY_DOWN );
1567 ke.m_shiftDown = event.m_shiftDown;
1568 ke.m_controlDown = event.m_controlDown;
1569 ke.m_altDown = event.m_altDown;
1570 ke.m_metaDown = event.m_metaDown;
1571 ke.m_keyCode = event.m_keyCode;
1572 ke.m_x = event.m_x;
1573 ke.m_y = event.m_y;
1574 ke.SetEventObject( parent );
1575 if (parent->GetEventHandler()->ProcessEvent( ke )) return;
1576
1577 event.Skip();
1578 }
1579
1580 void wxListMainWindow::OnChar( wxKeyEvent &event )
1581 {
1582 wxWindow *parent = GetParent();
1583
1584 /* we send a list_key event up */
1585 wxListEvent le( wxEVT_COMMAND_LIST_KEY_DOWN, GetParent()->GetId() );
1586 le.m_code = event.KeyCode();
1587 le.SetEventObject( parent );
1588 parent->GetEventHandler()->ProcessEvent( le );
1589
1590 /* we propagate the char event up */
1591 wxKeyEvent ke( wxEVT_CHAR );
1592 ke.m_shiftDown = event.m_shiftDown;
1593 ke.m_controlDown = event.m_controlDown;
1594 ke.m_altDown = event.m_altDown;
1595 ke.m_metaDown = event.m_metaDown;
1596 ke.m_keyCode = event.m_keyCode;
1597 ke.m_x = event.m_x;
1598 ke.m_y = event.m_y;
1599 ke.SetEventObject( parent );
1600 if (parent->GetEventHandler()->ProcessEvent( ke )) return;
1601
1602 if (event.KeyCode() == WXK_TAB)
1603 {
1604 wxNavigationKeyEvent nevent;
1605 nevent.SetDirection( !event.ShiftDown() );
1606 nevent.SetCurrentFocus( m_parent );
1607 if (m_parent->GetEventHandler()->ProcessEvent( nevent )) return;
1608 }
1609
1610 /* no item -> nothing to do */
1611 if (!m_current)
1612 {
1613 event.Skip();
1614 return;
1615 }
1616
1617 switch (event.KeyCode())
1618 {
1619 case WXK_UP:
1620 {
1621 wxNode *node = m_lines.Member( m_current )->Previous();
1622 if (node) OnArrowChar( (wxListLineData*)node->Data(), event.ShiftDown() );
1623 break;
1624 }
1625 case WXK_DOWN:
1626 {
1627 wxNode *node = m_lines.Member( m_current )->Next();
1628 if (node) OnArrowChar( (wxListLineData*)node->Data(), event.ShiftDown() );
1629 break;
1630 }
1631 case WXK_END:
1632 {
1633 wxNode *node = m_lines.Last();
1634 OnArrowChar( (wxListLineData*)node->Data(), event.ShiftDown() );
1635 break;
1636 }
1637 case WXK_HOME:
1638 {
1639 wxNode *node = m_lines.First();
1640 OnArrowChar( (wxListLineData*)node->Data(), event.ShiftDown() );
1641 break;
1642 }
1643 case WXK_PRIOR:
1644 {
1645 int steps = 0;
1646 if (m_mode & wxLC_REPORT)
1647 {
1648 steps = m_visibleLines-1;
1649 }
1650 else
1651 {
1652 int pos = 0;
1653 wxNode *node = m_lines.First();
1654 for (;;) { if (m_current == (wxListLineData*)node->Data()) break; pos++; node = node->Next(); }
1655 steps = pos % m_visibleLines;
1656 }
1657 wxNode *node = m_lines.Member( m_current );
1658 for (int i = 0; i < steps; i++) if (node->Previous()) node = node->Previous();
1659 if (node) OnArrowChar( (wxListLineData*)node->Data(), event.ShiftDown() );
1660 break;
1661 }
1662 case WXK_NEXT:
1663 {
1664 int steps = 0;
1665 if (m_mode & wxLC_REPORT)
1666 {
1667 steps = m_visibleLines-1;
1668 }
1669 else
1670 {
1671 int pos = 0; wxNode *node = m_lines.First();
1672 for (;;) { if (m_current == (wxListLineData*)node->Data()) break; pos++; node = node->Next(); }
1673 steps = m_visibleLines-(pos % m_visibleLines)-1;
1674 }
1675 wxNode *node = m_lines.Member( m_current );
1676 for (int i = 0; i < steps; i++) if (node->Next()) node = node->Next();
1677 if (node) OnArrowChar( (wxListLineData*)node->Data(), event.ShiftDown() );
1678 break;
1679 }
1680 case WXK_LEFT:
1681 {
1682 if (!(m_mode & wxLC_REPORT))
1683 {
1684 wxNode *node = m_lines.Member( m_current );
1685 for (int i = 0; i <m_visibleLines; i++) if (node->Previous()) node = node->Previous();
1686 if (node) OnArrowChar( (wxListLineData*)node->Data(), event.ShiftDown() );
1687 }
1688 break;
1689 }
1690 case WXK_RIGHT:
1691 {
1692 if (!(m_mode & wxLC_REPORT))
1693 {
1694 wxNode *node = m_lines.Member( m_current );
1695 for (int i = 0; i <m_visibleLines; i++) if (node->Next()) node = node->Next();
1696 if (node) OnArrowChar( (wxListLineData*)node->Data(), event.ShiftDown() );
1697 }
1698 break;
1699 }
1700 case WXK_SPACE:
1701 {
1702 m_current->ReverseHilight();
1703 RefreshLine( m_current );
1704 break;
1705 }
1706 case WXK_INSERT:
1707 {
1708 if (!(m_mode & wxLC_SINGLE_SEL))
1709 {
1710 wxListLineData *oldCurrent = m_current;
1711 m_current->ReverseHilight();
1712 wxNode *node = m_lines.Member( m_current )->Next();
1713 if (node) m_current = (wxListLineData*)node->Data();
1714 MoveToFocus();
1715 RefreshLine( oldCurrent );
1716 RefreshLine( m_current );
1717 UnfocusLine( oldCurrent );
1718 FocusLine( m_current );
1719 }
1720 break;
1721 }
1722 case WXK_RETURN:
1723 case WXK_EXECUTE:
1724 {
1725 wxListEvent le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED, GetParent()->GetId() );
1726 le.SetEventObject( GetParent() );
1727 le.m_itemIndex = GetIndexOfLine( m_current );
1728 m_current->GetItem( 0, le.m_item );
1729 GetParent()->GetEventHandler()->ProcessEvent( le );
1730 break;
1731 }
1732 default:
1733 {
1734 event.Skip();
1735 return;
1736 }
1737 }
1738 m_usedKeys = TRUE;
1739 }
1740
1741 #ifdef __WXGTK__
1742 extern wxWindow *g_focusWindow;
1743 #endif
1744
1745 void wxListMainWindow::OnSetFocus( wxFocusEvent &WXUNUSED(event) )
1746 {
1747 m_hasFocus = TRUE;
1748 RefreshLine( m_current );
1749
1750 if (!GetParent()) return;
1751
1752 #ifdef __WXGTK__
1753 g_focusWindow = GetParent();
1754 #endif
1755
1756 wxFocusEvent event( wxEVT_SET_FOCUS, GetParent()->GetId() );
1757 event.SetEventObject( GetParent() );
1758 GetParent()->GetEventHandler()->ProcessEvent( event );
1759 }
1760
1761 void wxListMainWindow::OnKillFocus( wxFocusEvent &WXUNUSED(event) )
1762 {
1763 m_hasFocus = FALSE;
1764 RefreshLine( m_current );
1765 }
1766
1767 void wxListMainWindow::OnSize( wxSizeEvent &WXUNUSED(event) )
1768 {
1769 /*
1770 We don't even allow the wxScrolledWindow::AdjustScrollbars() call
1771
1772 */
1773 }
1774
1775 void wxListMainWindow::DrawImage( int index, wxDC *dc, int x, int y )
1776 {
1777 if ((m_mode & wxLC_ICON) && (m_normal_image_list))
1778 {
1779 m_normal_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT );
1780 return;
1781 }
1782 if ((m_mode & wxLC_SMALL_ICON) && (m_small_image_list))
1783 {
1784 m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT );
1785 }
1786 if ((m_mode & wxLC_LIST) && (m_small_image_list))
1787 {
1788 m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT );
1789 }
1790 if ((m_mode & wxLC_REPORT) && (m_small_image_list))
1791 {
1792 m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT );
1793 return;
1794 }
1795 }
1796
1797 void wxListMainWindow::GetImageSize( int index, int &width, int &height )
1798 {
1799 if ((m_mode & wxLC_ICON) && (m_normal_image_list))
1800 {
1801 m_normal_image_list->GetSize( index, width, height );
1802 return;
1803 }
1804 if ((m_mode & wxLC_SMALL_ICON) && (m_small_image_list))
1805 {
1806 m_small_image_list->GetSize( index, width, height );
1807 return;
1808 }
1809 if ((m_mode & wxLC_LIST) && (m_small_image_list))
1810 {
1811 m_small_image_list->GetSize( index, width, height );
1812 return;
1813 }
1814 if ((m_mode & wxLC_REPORT) && (m_small_image_list))
1815 {
1816 m_small_image_list->GetSize( index, width, height );
1817 return;
1818 }
1819 width = 0;
1820 height = 0;
1821 }
1822
1823 int wxListMainWindow::GetTextLength( wxString &s )
1824 {
1825 wxClientDC dc( this );
1826 long lw = 0;
1827 long lh = 0;
1828 dc.GetTextExtent( s, &lw, &lh );
1829 return lw + 6;
1830 }
1831
1832 int wxListMainWindow::GetIndexOfLine( const wxListLineData *line )
1833 {
1834 int i = 0;
1835 wxNode *node = m_lines.First();
1836 while (node)
1837 {
1838 if (line == (wxListLineData*)node->Data()) return i;
1839 i++;
1840 node = node->Next();
1841 }
1842 return -1;
1843 }
1844
1845 void wxListMainWindow::SetImageList( wxImageList *imageList, int which )
1846 {
1847 m_dirty = TRUE;
1848 if (which == wxIMAGE_LIST_NORMAL) m_normal_image_list = imageList;
1849 if (which == wxIMAGE_LIST_SMALL) m_small_image_list = imageList;
1850 }
1851
1852 void wxListMainWindow::SetItemSpacing( int spacing, bool isSmall )
1853 {
1854 m_dirty = TRUE;
1855 if (isSmall)
1856 {
1857 m_small_spacing = spacing;
1858 }
1859 else
1860 {
1861 m_normal_spacing = spacing;
1862 }
1863 }
1864
1865 int wxListMainWindow::GetItemSpacing( bool isSmall )
1866 {
1867 if (isSmall) return m_small_spacing; else return m_normal_spacing;
1868 }
1869
1870 void wxListMainWindow::SetColumn( int col, wxListItem &item )
1871 {
1872 m_dirty = TRUE;
1873 wxNode *node = m_columns.Nth( col );
1874 if (node)
1875 {
1876 if (item.m_width == wxLIST_AUTOSIZE_USEHEADER) item.m_width = GetTextLength( item.m_text )+7;
1877 wxListHeaderData *column = (wxListHeaderData*)node->Data();
1878 column->SetItem( item );
1879 }
1880 wxListCtrl *lc = (wxListCtrl*) GetParent();
1881 if (lc->m_headerWin) lc->m_headerWin->Refresh();
1882 }
1883
1884 void wxListMainWindow::SetColumnWidth( int col, int width )
1885 {
1886 if (!(m_mode & wxLC_REPORT)) return;
1887
1888 m_dirty = TRUE;
1889
1890 wxNode *node = (wxNode*) NULL;
1891
1892 if (width == wxLIST_AUTOSIZE_USEHEADER) width = 80;
1893 if (width == wxLIST_AUTOSIZE)
1894 {
1895 wxClientDC dc(this);
1896 dc.SetFont( GetFont() );
1897 int max = 10;
1898 node = m_lines.First();
1899 while (node)
1900 {
1901 wxListLineData *line = (wxListLineData*)node->Data();
1902 wxNode *n = line->m_items.Nth( col );
1903 if (n)
1904 {
1905 wxListItemData *item = (wxListItemData*)n->Data();
1906 int current = 0, ix = 0, iy = 0;
1907 long lx = 0, ly = 0;
1908 if (item->HasImage())
1909 {
1910 GetImageSize( item->GetImage(), ix, iy );
1911 current = ix + 5;
1912 }
1913 if (item->HasText())
1914 {
1915 wxString str;
1916 item->GetText( str );
1917 dc.GetTextExtent( str, &lx, &ly );
1918 current += lx;
1919 }
1920 if (current > max) max = current;
1921 }
1922 node = node->Next();
1923 }
1924 width = max+10;
1925 }
1926
1927 node = m_columns.Nth( col );
1928 if (node)
1929 {
1930 wxListHeaderData *column = (wxListHeaderData*)node->Data();
1931 column->SetWidth( width );
1932 }
1933
1934 node = m_lines.First();
1935 while (node)
1936 {
1937 wxListLineData *line = (wxListLineData*)node->Data();
1938 wxNode *n = line->m_items.Nth( col );
1939 if (n)
1940 {
1941 wxListItemData *item = (wxListItemData*)n->Data();
1942 item->SetSize( width, -1 );
1943 }
1944 node = node->Next();
1945 }
1946
1947 wxListCtrl *lc = (wxListCtrl*) GetParent();
1948 if (lc->m_headerWin) lc->m_headerWin->Refresh();
1949 }
1950
1951 void wxListMainWindow::GetColumn( int col, wxListItem &item )
1952 {
1953 wxNode *node = m_columns.Nth( col );
1954 if (node)
1955 {
1956 wxListHeaderData *column = (wxListHeaderData*)node->Data();
1957 column->GetItem( item );
1958 }
1959 else
1960 {
1961 item.m_format = 0;
1962 item.m_width = 0;
1963 item.m_text = "";
1964 item.m_image = 0;
1965 item.m_data = 0;
1966 }
1967 }
1968
1969 int wxListMainWindow::GetColumnWidth( int col )
1970 {
1971 wxNode *node = m_columns.Nth( col );
1972 if (node)
1973 {
1974 wxListHeaderData *column = (wxListHeaderData*)node->Data();
1975 return column->GetWidth();
1976 }
1977 else
1978 {
1979 return 0;
1980 }
1981 }
1982
1983 int wxListMainWindow::GetColumnCount()
1984 {
1985 return m_columns.Number();
1986 }
1987
1988 int wxListMainWindow::GetCountPerPage()
1989 {
1990 return m_visibleLines;
1991 }
1992
1993 void wxListMainWindow::SetItem( wxListItem &item )
1994 {
1995 m_dirty = TRUE;
1996 wxNode *node = m_lines.Nth( item.m_itemId );
1997 if (node)
1998 {
1999 wxListLineData *line = (wxListLineData*)node->Data();
2000 if (m_mode & wxLC_REPORT) item.m_width = GetColumnWidth( item.m_col )-3;
2001 line->SetItem( item.m_col, item );
2002 }
2003 }
2004
2005 void wxListMainWindow::SetItemState( long item, long state, long stateMask )
2006 {
2007 // m_dirty = TRUE; no recalcs needed
2008
2009 wxListLineData *oldCurrent = m_current;
2010
2011 if (stateMask & wxLIST_STATE_FOCUSED)
2012 {
2013 wxNode *node = m_lines.Nth( item );
2014 if (node)
2015 {
2016 wxListLineData *line = (wxListLineData*)node->Data();
2017 UnfocusLine( m_current );
2018 m_current = line;
2019 FocusLine( m_current );
2020 RefreshLine( m_current );
2021 if (oldCurrent) RefreshLine( oldCurrent );
2022 }
2023 }
2024
2025 if (stateMask & wxLIST_STATE_SELECTED)
2026 {
2027 bool on = state & wxLIST_STATE_SELECTED;
2028 if (!on && (m_mode & wxLC_SINGLE_SEL)) return;
2029
2030 wxNode *node = m_lines.Nth( item );
2031 if (node)
2032 {
2033 wxListLineData *line = (wxListLineData*)node->Data();
2034 if (m_mode & wxLC_SINGLE_SEL)
2035 {
2036 UnfocusLine( m_current );
2037 m_current = line;
2038 FocusLine( m_current );
2039 if (oldCurrent) oldCurrent->Hilight( FALSE );
2040 RefreshLine( m_current );
2041 if (oldCurrent) RefreshLine( oldCurrent );
2042 }
2043 bool on = state & wxLIST_STATE_SELECTED;
2044 if (on != line->IsHilighted())
2045 {
2046 line->Hilight( on );
2047 RefreshLine( line );
2048 }
2049 }
2050 }
2051 }
2052
2053 int wxListMainWindow::GetItemState( long item, long stateMask )
2054 {
2055 int ret = wxLIST_STATE_DONTCARE;
2056 if (stateMask & wxLIST_STATE_FOCUSED)
2057 {
2058 wxNode *node = m_lines.Nth( item );
2059 if (node)
2060 {
2061 wxListLineData *line = (wxListLineData*)node->Data();
2062 if (line == m_current) ret |= wxLIST_STATE_FOCUSED;
2063 }
2064 }
2065 if (stateMask & wxLIST_STATE_SELECTED)
2066 {
2067 wxNode *node = m_lines.Nth( item );
2068 if (node)
2069 {
2070 wxListLineData *line = (wxListLineData*)node->Data();
2071 if (line->IsHilighted()) ret |= wxLIST_STATE_FOCUSED;
2072 }
2073 }
2074 return ret;
2075 }
2076
2077 void wxListMainWindow::GetItem( wxListItem &item )
2078 {
2079 wxNode *node = m_lines.Nth( item.m_itemId );
2080 if (node)
2081 {
2082 wxListLineData *line = (wxListLineData*)node->Data();
2083 line->GetItem( item.m_col, item );
2084 }
2085 else
2086 {
2087 item.m_mask = 0;
2088 item.m_text = "";
2089 item.m_image = 0;
2090 item.m_data = 0;
2091 }
2092 }
2093
2094 int wxListMainWindow::GetItemCount()
2095 {
2096 return m_lines.Number();
2097 }
2098
2099 void wxListMainWindow::GetItemRect( long index, wxRect &rect )
2100 {
2101 wxNode *node = m_lines.Nth( index );
2102 if (node)
2103 {
2104 wxListLineData *line = (wxListLineData*)node->Data();
2105 line->GetRect( rect );
2106 }
2107 else
2108 {
2109 rect.x = 0;
2110 rect.y = 0;
2111 rect.width = 0;
2112 rect.height = 0;
2113 }
2114 }
2115
2116 bool wxListMainWindow::GetItemPosition(long item, wxPoint& pos)
2117 {
2118 wxNode *node = m_lines.Nth( item );
2119 if (node)
2120 {
2121 wxRect rect;
2122 wxListLineData *line = (wxListLineData*)node->Data();
2123 line->GetRect( rect );
2124 pos.x = rect.x;
2125 pos.y = rect.y;
2126 }
2127 else
2128 {
2129 pos.x = 0;
2130 pos.y = 0;
2131 }
2132 return TRUE;
2133 }
2134
2135 int wxListMainWindow::GetSelectedItemCount()
2136 {
2137 int ret = 0;
2138 wxNode *node = m_lines.First();
2139 while (node)
2140 {
2141 wxListLineData *line = (wxListLineData*)node->Data();
2142 if (line->IsHilighted()) ret++;
2143 node = node->Next();
2144 }
2145 return ret;
2146 }
2147
2148 void wxListMainWindow::SetMode( long mode )
2149 {
2150 m_dirty = TRUE;
2151 m_mode = mode;
2152
2153 DeleteEverything();
2154
2155 if (m_mode & wxLC_REPORT)
2156 {
2157 #if wxUSE_GENERIC_LIST_EXTENSIONS
2158 m_xScroll = 15;
2159 #else
2160 m_xScroll = 0;
2161 #endif
2162 m_yScroll = 15;
2163 }
2164 else
2165 {
2166 m_xScroll = 15;
2167 m_yScroll = 0;
2168 }
2169 }
2170
2171 long wxListMainWindow::GetMode() const
2172 {
2173 return m_mode;
2174 }
2175
2176 void wxListMainWindow::CalculatePositions()
2177 {
2178 if (!m_lines.First()) return;
2179
2180 wxClientDC dc( this );
2181 dc.SetFont( GetFont() );
2182
2183 int iconSpacing = 0;
2184 if (m_mode & wxLC_ICON) iconSpacing = m_normal_spacing;
2185 if (m_mode & wxLC_SMALL_ICON) iconSpacing = m_small_spacing;
2186
2187 // we take the first line (which also can be an icon or
2188 // an a text item in wxLC_ICON and wxLC_LIST modes) to
2189 // measure the size of the line
2190
2191 int lineWidth = 0;
2192 int lineHeight = 0;
2193 int lineSpacing = 0;
2194
2195 wxListLineData *line = (wxListLineData*)m_lines.First()->Data();
2196 line->CalculateSize( &dc, iconSpacing );
2197 int dummy = 0;
2198 line->GetSize( dummy, lineSpacing );
2199 lineSpacing += 4;
2200
2201 int clientWidth = 0;
2202 int clientHeight = 0;
2203
2204 if (m_mode & wxLC_REPORT)
2205 {
2206 int x = 4;
2207 int y = 1;
2208 int entireHeight = m_lines.Number() * lineSpacing + 2;
2209 int scroll_pos = GetScrollPos( wxVERTICAL );
2210 #if wxUSE_GENERIC_LIST_EXTENSIONS
2211 int x_scroll_pos = GetScrollPos( wxHORIZONTAL );
2212 #else
2213 SetScrollbars( m_xScroll, m_yScroll, 0, (entireHeight+15) / m_yScroll, 0, scroll_pos, TRUE );
2214 #endif
2215 GetClientSize( &clientWidth, &clientHeight );
2216
2217 wxNode* node = m_lines.First();
2218 int entireWidth = 0 ;
2219 while (node)
2220 {
2221 wxListLineData *line = (wxListLineData*)node->Data();
2222 line->CalculateSize( &dc, iconSpacing );
2223 line->SetPosition( &dc, x, y, clientWidth );
2224 int col_x = 2;
2225 for (int i = 0; i < GetColumnCount(); i++)
2226 {
2227 line->SetColumnPosition( i, col_x );
2228 col_x += GetColumnWidth( i );
2229 }
2230 entireWidth = wxMax( entireWidth , col_x ) ;
2231 #if wxUSE_GENERIC_LIST_EXTENSIONS
2232 line->SetPosition( &dc, x, y, col_x );
2233 #endif
2234 y += lineSpacing; // one pixel blank line between items
2235 node = node->Next();
2236 }
2237 m_visibleLines = clientHeight / lineSpacing;
2238 #if wxUSE_GENERIC_LIST_EXTENSIONS
2239 SetScrollbars( m_xScroll, m_yScroll, entireWidth / m_xScroll , (entireHeight+15) / m_yScroll, x_scroll_pos , scroll_pos, TRUE );
2240 #endif
2241 }
2242 else
2243 {
2244 // at first we try without any scrollbar. if the items don't
2245 // fit into the window, we recalculate after subtracting an
2246 // approximated 15 pt for the horizontal scrollbar
2247
2248 GetSize( &clientWidth, &clientHeight );
2249 clientHeight -= 4; // sunken frame
2250
2251 int entireWidth = 0;
2252
2253 for (int tries = 0; tries < 2; tries++)
2254 {
2255 entireWidth = 0;
2256 int x = 5; // painting is done at x-2
2257 int y = 5; // painting is done at y-2
2258 int maxWidth = 0;
2259 m_visibleLines = 0;
2260 int m_currentVisibleLines = 0;
2261 wxNode *node = m_lines.First();
2262 while (node)
2263 {
2264 m_currentVisibleLines++;
2265 wxListLineData *line = (wxListLineData*)node->Data();
2266 line->CalculateSize( &dc, iconSpacing );
2267 line->SetPosition( &dc, x, y, clientWidth );
2268 line->GetSize( lineWidth, lineHeight );
2269 if (lineWidth > maxWidth) maxWidth = lineWidth;
2270 y += lineSpacing;
2271 if (m_currentVisibleLines > m_visibleLines)
2272 m_visibleLines = m_currentVisibleLines;
2273 if (y+lineSpacing-6 >= clientHeight) // -6 for earlier "line breaking"
2274 {
2275 m_currentVisibleLines = 0;
2276 y = 5;
2277 x += maxWidth+6;
2278 entireWidth += maxWidth+6;
2279 maxWidth = 0;
2280 }
2281 node = node->Next();
2282 if (!node) entireWidth += maxWidth;
2283 if ((tries == 0) && (entireWidth > clientWidth))
2284 {
2285 clientHeight -= 15; // scrollbar height
2286 m_visibleLines = 0;
2287 m_currentVisibleLines = 0;
2288 break;
2289 }
2290 if (!node) tries = 1; // everything fits, no second try required
2291 }
2292 }
2293
2294 int scroll_pos = GetScrollPos( wxHORIZONTAL );
2295 SetScrollbars( m_xScroll, m_yScroll, (entireWidth+15) / m_xScroll, 0, scroll_pos, 0, TRUE );
2296 }
2297 }
2298
2299 void wxListMainWindow::RealizeChanges( void )
2300 {
2301 if (!m_current)
2302 {
2303 wxNode *node = m_lines.First();
2304 if (node) m_current = (wxListLineData*)node->Data();
2305 }
2306 if (m_current)
2307 {
2308 FocusLine( m_current );
2309 if (m_mode & wxLC_SINGLE_SEL) m_current->Hilight( TRUE );
2310 }
2311 }
2312
2313 long wxListMainWindow::GetNextItem( long item, int WXUNUSED(geometry), int state )
2314 {
2315 long ret = 0;
2316 if (item > 0) ret = item;
2317 if(ret >= GetItemCount()) return -1;
2318 wxNode *node = m_lines.Nth( ret );
2319 while (node)
2320 {
2321 wxListLineData *line = (wxListLineData*)node->Data();
2322 if ((state & wxLIST_STATE_FOCUSED) && (line == m_current)) return ret;
2323 if ((state & wxLIST_STATE_SELECTED) && (line->IsHilighted())) return ret;
2324 if (!state) return ret;
2325 ret++;
2326 node = node->Next();
2327 }
2328 return -1;
2329 }
2330
2331 void wxListMainWindow::DeleteItem( long index )
2332 {
2333 m_dirty = TRUE;
2334 wxNode *node = m_lines.Nth( index );
2335 if (node)
2336 {
2337 wxListLineData *line = (wxListLineData*)node->Data();
2338 if (m_current == line) m_current = (wxListLineData *) NULL;
2339 DeleteLine( line );
2340 m_lines.DeleteNode( node );
2341 }
2342 }
2343
2344 void wxListMainWindow::DeleteColumn( int col )
2345 {
2346 wxCHECK_RET( col < (int)m_columns.GetCount(),
2347 wxT("attempting to delete inexistent column in wxListView") );
2348
2349 m_dirty = TRUE;
2350 wxNode *node = m_columns.Nth( col );
2351 if (node) m_columns.DeleteNode( node );
2352 }
2353
2354 void wxListMainWindow::DeleteAllItems( void )
2355 {
2356 m_dirty = TRUE;
2357 m_current = (wxListLineData *) NULL;
2358
2359 // to make the deletion of all items faster, we don't send the
2360 // notifications in this case: this is compatible with wxMSW and
2361 // documented in DeleteAllItems() description
2362 #if 0
2363 wxNode *node = m_lines.First();
2364 while (node)
2365 {
2366 wxListLineData *line = (wxListLineData*)node->Data();
2367
2368 DeleteLine( line );
2369
2370 node = node->Next();
2371 }
2372 #endif // 0
2373
2374 m_lines.Clear();
2375 }
2376
2377 void wxListMainWindow::DeleteEverything( void )
2378 {
2379 m_dirty = TRUE;
2380 m_current = (wxListLineData *) NULL;
2381 wxNode *node = m_lines.First();
2382 while (node)
2383 {
2384 wxListLineData *line = (wxListLineData*)node->Data();
2385 DeleteLine( line );
2386 node = node->Next();
2387 }
2388 m_lines.Clear();
2389 m_current = (wxListLineData *) NULL;
2390 m_columns.Clear();
2391 }
2392
2393 void wxListMainWindow::EnsureVisible( long index )
2394 {
2395 // We have to call this here because the label in
2396 // question might just have been added and no screen
2397 // update taken place.
2398 if (m_dirty) wxYield();
2399
2400 wxListLineData *oldCurrent = m_current;
2401 m_current = (wxListLineData *) NULL;
2402 int i = index;
2403 wxNode *node = m_lines.Nth( i );
2404 if (node) m_current = (wxListLineData*)node->Data();
2405 if (m_current) MoveToFocus();
2406 m_current = oldCurrent;
2407 }
2408
2409 long wxListMainWindow::FindItem(long start, const wxString& str, bool WXUNUSED(partial) )
2410 {
2411 long pos = start;
2412 wxString tmp = str;
2413 if (pos < 0) pos = 0;
2414 wxNode *node = m_lines.Nth( pos );
2415 while (node)
2416 {
2417 wxListLineData *line = (wxListLineData*)node->Data();
2418 wxString s = "";
2419 line->GetText( 0, s );
2420 if (s == tmp) return pos;
2421 node = node->Next();
2422 pos++;
2423 }
2424 return -1;
2425 }
2426
2427 long wxListMainWindow::FindItem(long start, long data)
2428 {
2429 long pos = start;
2430 if (pos < 0) pos = 0;
2431 wxNode *node = m_lines.Nth( pos );
2432 while (node)
2433 {
2434 wxListLineData *line = (wxListLineData*)node->Data();
2435 wxListItem item;
2436 line->GetItem( 0, item );
2437 if (item.m_data == data) return pos;
2438 node = node->Next();
2439 pos++;
2440 }
2441 return -1;
2442 }
2443
2444 long wxListMainWindow::HitTest( int x, int y, int &flags )
2445 {
2446 wxNode *node = m_lines.First();
2447 int count = 0;
2448 while (node)
2449 {
2450 wxListLineData *line = (wxListLineData*)node->Data();
2451 long ret = line->IsHit( x, y );
2452 if (ret & flags)
2453 {
2454 flags = ret;
2455 return count;
2456 }
2457 node = node->Next();
2458 count++;
2459 }
2460 return -1;
2461 }
2462
2463 void wxListMainWindow::InsertItem( wxListItem &item )
2464 {
2465 m_dirty = TRUE;
2466 int mode = 0;
2467 if (m_mode & wxLC_REPORT) mode = wxLC_REPORT;
2468 else if (m_mode & wxLC_LIST) mode = wxLC_LIST;
2469 else if (m_mode & wxLC_ICON) mode = wxLC_ICON;
2470 else if (m_mode & wxLC_SMALL_ICON) mode = wxLC_ICON; // no typo
2471
2472 wxListLineData *line = new wxListLineData( this, mode, m_hilightBrush );
2473
2474 if (m_mode & wxLC_REPORT)
2475 {
2476 line->InitItems( GetColumnCount() );
2477 item.m_width = GetColumnWidth( 0 )-3;
2478 }
2479 else
2480 {
2481 line->InitItems( 1 );
2482 }
2483
2484 line->SetItem( 0, item );
2485 if ((item.m_itemId >= 0) && (item.m_itemId < (int)m_lines.GetCount()))
2486 {
2487 wxNode *node = m_lines.Nth( item.m_itemId );
2488 if (node) m_lines.Insert( node, line );
2489 }
2490 else
2491 {
2492 m_lines.Append( line );
2493 }
2494 }
2495
2496 void wxListMainWindow::InsertColumn( long col, wxListItem &item )
2497 {
2498 m_dirty = TRUE;
2499 if (m_mode & wxLC_REPORT)
2500 {
2501 if (item.m_width == wxLIST_AUTOSIZE_USEHEADER) item.m_width = GetTextLength( item.m_text );
2502 wxListHeaderData *column = new wxListHeaderData( item );
2503 if ((col >= 0) && (col < (int)m_columns.GetCount()))
2504 {
2505 wxNode *node = m_columns.Nth( col );
2506 if (node)
2507 m_columns.Insert( node, column );
2508 }
2509 else
2510 {
2511 m_columns.Append( column );
2512 }
2513 }
2514 }
2515
2516 wxListCtrlCompare list_ctrl_compare_func_2;
2517 long list_ctrl_compare_data;
2518
2519 int LINKAGEMODE list_ctrl_compare_func_1( const void *arg1, const void *arg2 )
2520 {
2521 wxListLineData *line1 = *((wxListLineData**)arg1);
2522 wxListLineData *line2 = *((wxListLineData**)arg2);
2523 wxListItem item;
2524 line1->GetItem( 0, item );
2525 long data1 = item.m_data;
2526 line2->GetItem( 0, item );
2527 long data2 = item.m_data;
2528 return list_ctrl_compare_func_2( data1, data2, list_ctrl_compare_data );
2529 }
2530
2531 void wxListMainWindow::SortItems( wxListCtrlCompare fn, long data )
2532 {
2533 list_ctrl_compare_func_2 = fn;
2534 list_ctrl_compare_data = data;
2535 m_lines.Sort( list_ctrl_compare_func_1 );
2536 }
2537
2538 void wxListMainWindow::OnScroll(wxScrollWinEvent& event)
2539 {
2540 wxScrolledWindow::OnScroll( event ) ;
2541 #if wxUSE_GENERIC_LIST_EXTENSIONS
2542
2543 if (event.GetOrientation() == wxHORIZONTAL && ( m_mode & wxLC_REPORT ))
2544 {
2545 wxListCtrl* lc = wxDynamicCast( GetParent() , wxListCtrl ) ;
2546 if ( lc )
2547 {
2548 lc->m_headerWin->Refresh() ;
2549 #ifdef __WXMAC__
2550 lc->m_headerWin->MacUpdateImmediately() ;
2551 #endif
2552 }
2553 }
2554 #endif
2555 }
2556
2557 // -------------------------------------------------------------------------------------
2558 // wxListItem
2559 // -------------------------------------------------------------------------------------
2560
2561 IMPLEMENT_DYNAMIC_CLASS(wxListItem, wxObject)
2562
2563 wxListItem::wxListItem()
2564 {
2565 m_mask = 0;
2566 m_itemId = 0;
2567 m_col = 0;
2568 m_state = 0;
2569 m_stateMask = 0;
2570 m_image = 0;
2571 m_data = 0;
2572 m_format = wxLIST_FORMAT_CENTRE;
2573 m_width = 0;
2574
2575 m_attr = NULL;
2576 }
2577
2578 void wxListItem::Clear()
2579 {
2580 m_mask = 0;
2581 m_itemId = 0;
2582 m_col = 0;
2583 m_state = 0;
2584 m_stateMask = 0;
2585 m_image = 0;
2586 m_data = 0;
2587 m_format = wxLIST_FORMAT_CENTRE;
2588 m_width = 0;
2589 m_text = wxEmptyString;
2590
2591 if (m_attr) delete m_attr;
2592 m_attr = NULL;
2593 }
2594
2595 void wxListItem::ClearAttributes()
2596 {
2597 if (m_attr) delete m_attr;
2598 m_attr = NULL;
2599 }
2600
2601 // -------------------------------------------------------------------------------------
2602 // wxListEvent
2603 // -------------------------------------------------------------------------------------
2604
2605 IMPLEMENT_DYNAMIC_CLASS(wxListEvent, wxNotifyEvent)
2606
2607 wxListEvent::wxListEvent( wxEventType commandType, int id ):
2608 wxNotifyEvent( commandType, id )
2609 {
2610 m_code = 0;
2611 m_itemIndex = 0;
2612 m_oldItemIndex = 0;
2613 m_col = 0;
2614 m_cancelled = FALSE;
2615 m_pointDrag.x = 0;
2616 m_pointDrag.y = 0;
2617 }
2618
2619 void wxListEvent::CopyObject(wxObject& object_dest) const
2620 {
2621 wxListEvent *obj = (wxListEvent *)&object_dest;
2622
2623 wxNotifyEvent::CopyObject(object_dest);
2624
2625 obj->m_code = m_code;
2626 obj->m_itemIndex = m_itemIndex;
2627 obj->m_oldItemIndex = m_oldItemIndex;
2628 obj->m_col = m_col;
2629 obj->m_cancelled = m_cancelled;
2630 obj->m_pointDrag = m_pointDrag;
2631 obj->m_item.m_mask = m_item.m_mask;
2632 obj->m_item.m_itemId = m_item.m_itemId;
2633 obj->m_item.m_col = m_item.m_col;
2634 obj->m_item.m_state = m_item.m_state;
2635 obj->m_item.m_stateMask = m_item.m_stateMask;
2636 obj->m_item.m_text = m_item.m_text;
2637 obj->m_item.m_image = m_item.m_image;
2638 obj->m_item.m_data = m_item.m_data;
2639 obj->m_item.m_format = m_item.m_format;
2640 obj->m_item.m_width = m_item.m_width;
2641
2642 if ( m_item.HasAttributes() )
2643 {
2644 obj->m_item.SetTextColour(m_item.GetTextColour());
2645 }
2646 }
2647
2648 // -------------------------------------------------------------------------------------
2649 // wxListCtrl
2650 // -------------------------------------------------------------------------------------
2651
2652 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl, wxControl)
2653
2654 BEGIN_EVENT_TABLE(wxListCtrl,wxControl)
2655 EVT_SIZE (wxListCtrl::OnSize)
2656 EVT_IDLE (wxListCtrl::OnIdle)
2657 END_EVENT_TABLE()
2658
2659 wxListCtrl::wxListCtrl()
2660 {
2661 m_imageListNormal = (wxImageList *) NULL;
2662 m_imageListSmall = (wxImageList *) NULL;
2663 m_imageListState = (wxImageList *) NULL;
2664 m_mainWin = (wxListMainWindow*) NULL;
2665 m_headerWin = (wxListHeaderWindow*) NULL;
2666 }
2667
2668 wxListCtrl::~wxListCtrl()
2669 {
2670 }
2671
2672 bool wxListCtrl::Create( wxWindow *parent, wxWindowID id,
2673 const wxPoint &pos, const wxSize &size,
2674 #if wxUSE_VALIDATORS
2675 long style, const wxValidator &validator,
2676 #endif
2677 const wxString &name )
2678 {
2679 m_imageListNormal = (wxImageList *) NULL;
2680 m_imageListSmall = (wxImageList *) NULL;
2681 m_imageListState = (wxImageList *) NULL;
2682 m_mainWin = (wxListMainWindow*) NULL;
2683 m_headerWin = (wxListHeaderWindow*) NULL;
2684
2685 long s = style;
2686
2687 #ifdef __VMS__
2688 #pragma message disable codcauunr
2689 // VMS reports on this part the warning:
2690 // statement either is unreachable or causes unreachable code
2691 #endif
2692 if ((s & wxLC_REPORT == 0) &&
2693 (s & wxLC_LIST == 0) &&
2694 (s & wxLC_ICON == 0))
2695 {
2696 s = s | wxLC_LIST;
2697 }
2698 #ifdef __VMS__
2699 #pragma message enable codcauunr
2700 #endif
2701
2702 bool ret = wxControl::Create( parent, id, pos, size, s, name );
2703
2704 #if wxUSE_VALIDATORS
2705 SetValidator( validator );
2706 #endif
2707
2708 if (s & wxSUNKEN_BORDER) s -= wxSUNKEN_BORDER;
2709
2710 m_mainWin = new wxListMainWindow( this, -1, wxPoint(0,0), size, s );
2711
2712 if (HasFlag(wxLC_REPORT))
2713 m_headerWin = new wxListHeaderWindow( this, -1, m_mainWin, wxPoint(0,0), wxSize(size.x,23), wxTAB_TRAVERSAL );
2714 else
2715 m_headerWin = (wxListHeaderWindow *) NULL;
2716
2717 SetBackgroundColour( *wxWHITE );
2718
2719 return ret;
2720 }
2721
2722 void wxListCtrl::OnSize( wxSizeEvent &WXUNUSED(event) )
2723 {
2724 /* handled in OnIdle */
2725
2726 if (m_mainWin) m_mainWin->m_dirty = TRUE;
2727 }
2728
2729 void wxListCtrl::SetSingleStyle( long style, bool add )
2730 {
2731 long flag = GetWindowStyle();
2732
2733 if (add)
2734 {
2735 if (style & wxLC_MASK_TYPE) flag = flag & ~wxLC_MASK_TYPE;
2736 if (style & wxLC_MASK_ALIGN) flag = flag & ~wxLC_MASK_ALIGN;
2737 if (style & wxLC_MASK_SORT) flag = flag & ~wxLC_MASK_SORT;
2738 }
2739
2740 if (add)
2741 {
2742 flag |= style;
2743 }
2744 else
2745 {
2746 if (flag & style) flag -= style;
2747 }
2748
2749 SetWindowStyleFlag( flag );
2750 }
2751
2752 void wxListCtrl::SetWindowStyleFlag( long flag )
2753 {
2754 if (m_mainWin)
2755 {
2756 m_mainWin->DeleteEverything();
2757
2758 int width = 0;
2759 int height = 0;
2760 GetClientSize( &width, &height );
2761
2762 m_mainWin->SetMode( flag );
2763
2764 if (flag & wxLC_REPORT)
2765 {
2766 if (!HasFlag(wxLC_REPORT))
2767 {
2768 if (!m_headerWin)
2769 {
2770 m_headerWin = new wxListHeaderWindow( this, -1, m_mainWin,
2771 wxPoint(0,0), wxSize(width,23), wxTAB_TRAVERSAL );
2772 if (HasFlag(wxLC_NO_HEADER))
2773 m_headerWin->Show( FALSE );
2774 }
2775 else
2776 {
2777 if (flag & wxLC_NO_HEADER)
2778 m_headerWin->Show( FALSE );
2779 else
2780 m_headerWin->Show( TRUE );
2781 }
2782 }
2783 }
2784 else
2785 {
2786 if (HasFlag(wxLC_REPORT) && !(HasFlag(wxLC_NO_HEADER)))
2787 {
2788 m_headerWin->Show( FALSE );
2789 }
2790 }
2791 }
2792
2793 wxWindow::SetWindowStyleFlag( flag );
2794 }
2795
2796 bool wxListCtrl::GetColumn(int col, wxListItem &item) const
2797 {
2798 m_mainWin->GetColumn( col, item );
2799 return TRUE;
2800 }
2801
2802 bool wxListCtrl::SetColumn( int col, wxListItem& item )
2803 {
2804 m_mainWin->SetColumn( col, item );
2805 return TRUE;
2806 }
2807
2808 int wxListCtrl::GetColumnWidth( int col ) const
2809 {
2810 return m_mainWin->GetColumnWidth( col );
2811 }
2812
2813 bool wxListCtrl::SetColumnWidth( int col, int width )
2814 {
2815 m_mainWin->SetColumnWidth( col, width );
2816 return TRUE;
2817 }
2818
2819 int wxListCtrl::GetCountPerPage() const
2820 {
2821 return m_mainWin->GetCountPerPage(); // different from Windows ?
2822 }
2823
2824 bool wxListCtrl::GetItem( wxListItem &info ) const
2825 {
2826 m_mainWin->GetItem( info );
2827 return TRUE;
2828 }
2829
2830 bool wxListCtrl::SetItem( wxListItem &info )
2831 {
2832 m_mainWin->SetItem( info );
2833 return TRUE;
2834 }
2835
2836 long wxListCtrl::SetItem( long index, int col, const wxString& label, int imageId )
2837 {
2838 wxListItem info;
2839 info.m_text = label;
2840 info.m_mask = wxLIST_MASK_TEXT;
2841 info.m_itemId = index;
2842 info.m_col = col;
2843 if ( imageId > -1 )
2844 {
2845 info.m_image = imageId;
2846 info.m_mask |= wxLIST_MASK_IMAGE;
2847 };
2848 m_mainWin->SetItem(info);
2849 return TRUE;
2850 }
2851
2852 int wxListCtrl::GetItemState( long item, long stateMask ) const
2853 {
2854 return m_mainWin->GetItemState( item, stateMask );
2855 }
2856
2857 bool wxListCtrl::SetItemState( long item, long state, long stateMask )
2858 {
2859 m_mainWin->SetItemState( item, state, stateMask );
2860 return TRUE;
2861 }
2862
2863 bool wxListCtrl::SetItemImage( long item, int image, int WXUNUSED(selImage) )
2864 {
2865 wxListItem info;
2866 info.m_image = image;
2867 info.m_mask = wxLIST_MASK_IMAGE;
2868 info.m_itemId = item;
2869 m_mainWin->SetItem( info );
2870 return TRUE;
2871 }
2872
2873 wxString wxListCtrl::GetItemText( long item ) const
2874 {
2875 wxListItem info;
2876 info.m_itemId = item;
2877 m_mainWin->GetItem( info );
2878 return info.m_text;
2879 }
2880
2881 void wxListCtrl::SetItemText( long item, const wxString &str )
2882 {
2883 wxListItem info;
2884 info.m_mask = wxLIST_MASK_TEXT;
2885 info.m_itemId = item;
2886 info.m_text = str;
2887 m_mainWin->SetItem( info );
2888 }
2889
2890 long wxListCtrl::GetItemData( long item ) const
2891 {
2892 wxListItem info;
2893 info.m_itemId = item;
2894 m_mainWin->GetItem( info );
2895 return info.m_data;
2896 }
2897
2898 bool wxListCtrl::SetItemData( long item, long data )
2899 {
2900 wxListItem info;
2901 info.m_mask = wxLIST_MASK_DATA;
2902 info.m_itemId = item;
2903 info.m_data = data;
2904 m_mainWin->SetItem( info );
2905 return TRUE;
2906 }
2907
2908 bool wxListCtrl::GetItemRect( long item, wxRect &rect, int WXUNUSED(code) ) const
2909 {
2910 m_mainWin->GetItemRect( item, rect );
2911 return TRUE;
2912 }
2913
2914 bool wxListCtrl::GetItemPosition( long item, wxPoint& pos ) const
2915 {
2916 m_mainWin->GetItemPosition( item, pos );
2917 return TRUE;
2918 }
2919
2920 bool wxListCtrl::SetItemPosition( long WXUNUSED(item), const wxPoint& WXUNUSED(pos) )
2921 {
2922 return 0;
2923 }
2924
2925 int wxListCtrl::GetItemCount() const
2926 {
2927 return m_mainWin->GetItemCount();
2928 }
2929
2930 int wxListCtrl::GetColumnCount() const
2931 {
2932 return m_mainWin->GetColumnCount();
2933 }
2934
2935 void wxListCtrl::SetItemSpacing( int spacing, bool isSmall )
2936 {
2937 m_mainWin->SetItemSpacing( spacing, isSmall );
2938 }
2939
2940 int wxListCtrl::GetItemSpacing( bool isSmall ) const
2941 {
2942 return m_mainWin->GetItemSpacing( isSmall );
2943 }
2944
2945 int wxListCtrl::GetSelectedItemCount() const
2946 {
2947 return m_mainWin->GetSelectedItemCount();
2948 }
2949
2950 wxColour wxListCtrl::GetTextColour() const
2951 {
2952 return GetForegroundColour();
2953 }
2954
2955 void wxListCtrl::SetTextColour(const wxColour& col)
2956 {
2957 SetForegroundColour(col);
2958 }
2959
2960 long wxListCtrl::GetTopItem() const
2961 {
2962 return 0;
2963 }
2964
2965 long wxListCtrl::GetNextItem( long item, int geom, int state ) const
2966 {
2967 return m_mainWin->GetNextItem( item, geom, state );
2968 }
2969
2970 wxImageList *wxListCtrl::GetImageList(int which) const
2971 {
2972 if (which == wxIMAGE_LIST_NORMAL)
2973 {
2974 return m_imageListNormal;
2975 }
2976 else if (which == wxIMAGE_LIST_SMALL)
2977 {
2978 return m_imageListSmall;
2979 }
2980 else if (which == wxIMAGE_LIST_STATE)
2981 {
2982 return m_imageListState;
2983 }
2984 return (wxImageList *) NULL;
2985 }
2986
2987 void wxListCtrl::SetImageList( wxImageList *imageList, int which )
2988 {
2989 m_mainWin->SetImageList( imageList, which );
2990 }
2991
2992 bool wxListCtrl::Arrange( int WXUNUSED(flag) )
2993 {
2994 return 0;
2995 }
2996
2997 bool wxListCtrl::DeleteItem( long item )
2998 {
2999 m_mainWin->DeleteItem( item );
3000 return TRUE;
3001 }
3002
3003 bool wxListCtrl::DeleteAllItems()
3004 {
3005 m_mainWin->DeleteAllItems();
3006 return TRUE;
3007 }
3008
3009 bool wxListCtrl::DeleteAllColumns()
3010 {
3011 for ( size_t n = 0; n < m_mainWin->m_columns.GetCount(); n++ )
3012 DeleteColumn(n);
3013
3014 return TRUE;
3015 }
3016
3017 void wxListCtrl::ClearAll()
3018 {
3019 m_mainWin->DeleteEverything();
3020 }
3021
3022 bool wxListCtrl::DeleteColumn( int col )
3023 {
3024 m_mainWin->DeleteColumn( col );
3025 return TRUE;
3026 }
3027
3028 void wxListCtrl::Edit( long item )
3029 {
3030 m_mainWin->Edit( item );
3031 }
3032
3033 bool wxListCtrl::EnsureVisible( long item )
3034 {
3035 m_mainWin->EnsureVisible( item );
3036 return TRUE;
3037 }
3038
3039 long wxListCtrl::FindItem( long start, const wxString& str, bool partial )
3040 {
3041 return m_mainWin->FindItem( start, str, partial );
3042 }
3043
3044 long wxListCtrl::FindItem( long start, long data )
3045 {
3046 return m_mainWin->FindItem( start, data );
3047 }
3048
3049 long wxListCtrl::FindItem( long WXUNUSED(start), const wxPoint& WXUNUSED(pt),
3050 int WXUNUSED(direction))
3051 {
3052 return 0;
3053 }
3054
3055 long wxListCtrl::HitTest( const wxPoint &point, int &flags )
3056 {
3057 return m_mainWin->HitTest( (int)point.x, (int)point.y, flags );
3058 }
3059
3060 long wxListCtrl::InsertItem( wxListItem& info )
3061 {
3062 m_mainWin->InsertItem( info );
3063 return info.m_itemId;
3064 }
3065
3066 long wxListCtrl::InsertItem( long index, const wxString &label )
3067 {
3068 wxListItem info;
3069 info.m_text = label;
3070 info.m_mask = wxLIST_MASK_TEXT;
3071 info.m_itemId = index;
3072 return InsertItem( info );
3073 }
3074
3075 long wxListCtrl::InsertItem( long index, int imageIndex )
3076 {
3077 wxListItem info;
3078 info.m_mask = wxLIST_MASK_IMAGE;
3079 info.m_image = imageIndex;
3080 info.m_itemId = index;
3081 return InsertItem( info );
3082 }
3083
3084 long wxListCtrl::InsertItem( long index, const wxString &label, int imageIndex )
3085 {
3086 wxListItem info;
3087 info.m_text = label;
3088 info.m_image = imageIndex;
3089 info.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_IMAGE;
3090 info.m_itemId = index;
3091 return InsertItem( info );
3092 }
3093
3094 long wxListCtrl::InsertColumn( long col, wxListItem &item )
3095 {
3096 m_mainWin->InsertColumn( col, item );
3097 return 0;
3098 }
3099
3100 long wxListCtrl::InsertColumn( long col, const wxString &heading,
3101 int format, int width )
3102 {
3103 wxListItem item;
3104 item.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_FORMAT;
3105 item.m_text = heading;
3106 if (width >= -2)
3107 {
3108 item.m_mask |= wxLIST_MASK_WIDTH;
3109 item.m_width = width;
3110 }
3111 item.m_format = format;
3112
3113 return InsertColumn( col, item );
3114 }
3115
3116 bool wxListCtrl::ScrollList( int WXUNUSED(dx), int WXUNUSED(dy) )
3117 {
3118 return 0;
3119 }
3120
3121 // Sort items.
3122 // fn is a function which takes 3 long arguments: item1, item2, data.
3123 // item1 is the long data associated with a first item (NOT the index).
3124 // item2 is the long data associated with a second item (NOT the index).
3125 // data is the same value as passed to SortItems.
3126 // The return value is a negative number if the first item should precede the second
3127 // item, a positive number of the second item should precede the first,
3128 // or zero if the two items are equivalent.
3129 // data is arbitrary data to be passed to the sort function.
3130
3131 bool wxListCtrl::SortItems( wxListCtrlCompare fn, long data )
3132 {
3133 m_mainWin->SortItems( fn, data );
3134 return TRUE;
3135 }
3136
3137 void wxListCtrl::OnIdle( wxIdleEvent &WXUNUSED(event) )
3138 {
3139 if (!m_mainWin->m_dirty) return;
3140
3141 int cw = 0;
3142 int ch = 0;
3143 GetClientSize( &cw, &ch );
3144
3145 int x = 0;
3146 int y = 0;
3147 int w = 0;
3148 int h = 0;
3149
3150 if (HasFlag(wxLC_REPORT) && !HasFlag(wxLC_NO_HEADER))
3151 {
3152 m_headerWin->GetPosition( &x, &y );
3153 m_headerWin->GetSize( &w, &h );
3154 if ((x != 0) || (y != 0) || (w != cw) || (h != 23))
3155 m_headerWin->SetSize( 0, 0, cw, 23 );
3156
3157 m_mainWin->GetPosition( &x, &y );
3158 m_mainWin->GetSize( &w, &h );
3159 if ((x != 0) || (y != 24) || (w != cw) || (h != ch-24))
3160 m_mainWin->SetSize( 0, 24, cw, ch-24 );
3161 }
3162 else
3163 {
3164 m_mainWin->GetPosition( &x, &y );
3165 m_mainWin->GetSize( &w, &h );
3166 if ((x != 0) || (y != 24) || (w != cw) || (h != ch))
3167 m_mainWin->SetSize( 0, 0, cw, ch );
3168 }
3169
3170 m_mainWin->CalculatePositions();
3171 m_mainWin->RealizeChanges();
3172 m_mainWin->m_dirty = FALSE;
3173 m_mainWin->Refresh();
3174 }
3175
3176 bool wxListCtrl::SetBackgroundColour( const wxColour &colour )
3177 {
3178 if ( !wxWindow::SetBackgroundColour( colour ) )
3179 return FALSE;
3180
3181 if (m_mainWin)
3182 {
3183 m_mainWin->SetBackgroundColour( colour );
3184 m_mainWin->m_dirty = TRUE;
3185 }
3186
3187 if (m_headerWin)
3188 {
3189 // m_headerWin->SetBackgroundColour( colour );
3190 }
3191
3192 return TRUE;
3193 }
3194
3195 bool wxListCtrl::SetForegroundColour( const wxColour &colour )
3196 {
3197 if ( !wxWindow::SetForegroundColour( colour ) )
3198 return FALSE;
3199
3200 if (m_mainWin)
3201 {
3202 m_mainWin->SetForegroundColour( colour );
3203 m_mainWin->m_dirty = TRUE;
3204 }
3205
3206 if (m_headerWin)
3207 {
3208 m_headerWin->SetForegroundColour( colour );
3209 }
3210
3211 return TRUE;
3212 }
3213
3214 bool wxListCtrl::SetFont( const wxFont &font )
3215 {
3216 if ( !wxWindow::SetFont( font ) )
3217 return FALSE;
3218
3219 if (m_mainWin)
3220 {
3221 m_mainWin->SetFont( font );
3222 m_mainWin->m_dirty = TRUE;
3223 }
3224
3225 if (m_headerWin)
3226 {
3227 m_headerWin->SetFont( font );
3228 }
3229
3230 return TRUE;
3231 }
3232