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