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