]> git.saurik.com Git - wxWidgets.git/blob - src/generic/listctrl.cpp
6c6eba0be62fd2caa61a8ee0053d00522d0d1bb1
[wxWidgets.git] / src / generic / listctrl.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: listctrl.cpp
3 // Purpose:
4 // Author: Robert Roebling
5 // Created: 01/02/97
6 // Id:
7 // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifdef __GNUG__
12 #pragma implementation "listctrl.h"
13 #endif
14
15 #include "wx/listctrl.h"
16
17 //-----------------------------------------------------------------------------
18 // wxListItemData
19 //-----------------------------------------------------------------------------
20
21 IMPLEMENT_DYNAMIC_CLASS(wxListItemData,wxObject);
22
23 wxListItemData::wxListItemData(void)
24 {
25 m_image = -1;
26 m_data = 0;
27 m_xpos = 0;
28 m_ypos = 0;
29 m_width = 0;
30 m_height = 0;
31 m_colour = wxBLACK;
32 };
33
34 wxListItemData::wxListItemData( const wxListItem &info )
35 {
36 m_image = -1;
37 m_data = 0;
38 m_colour = info.m_colour;
39 SetItem( info );
40 };
41
42 void wxListItemData::SetItem( const wxListItem &info )
43 {
44 if (info.m_mask & wxLIST_MASK_TEXT) m_text = info.m_text;
45 if (info.m_mask & wxLIST_MASK_IMAGE) m_image = info.m_image;
46 if (info.m_mask & wxLIST_MASK_DATA) m_data = info.m_data;
47 m_colour = info.m_colour;
48 m_xpos = 0;
49 m_ypos = 0;
50 m_width = info.m_width;
51 m_height = 0;
52 };
53
54 void wxListItemData::SetText( const wxString &s )
55 {
56 m_text = s;
57 };
58
59 void wxListItemData::SetImage( int image )
60 {
61 m_image = image;
62 };
63
64 void wxListItemData::SetData( long data )
65 {
66 m_data = data;
67 };
68
69 void wxListItemData::SetPosition( int x, int y )
70 {
71 m_xpos = x;
72 m_ypos = y;
73 };
74
75 void wxListItemData::SetSize( int const width, int height )
76 {
77 m_width = width;
78 m_height = height;
79 };
80
81 void wxListItemData::SetColour( wxColour *col )
82 {
83 m_colour = col;
84 };
85
86 bool wxListItemData::HasImage(void) const
87 {
88 return (m_image >= 0);
89 };
90
91 bool wxListItemData::HasText(void) const
92 {
93 return (!m_text.IsNull());
94 };
95
96 bool wxListItemData::IsHit( int x, int y ) const
97 {
98 return ((x >= m_xpos) && (x <= m_xpos+m_width) && (y >= m_ypos) && (y <= m_ypos+m_height));
99 };
100
101 void wxListItemData::GetText( wxString &s )
102 {
103 s = m_text;
104 };
105
106 int wxListItemData::GetX( void ) const
107 {
108 return m_xpos;
109 };
110
111 int wxListItemData::GetY( void ) const
112 {
113 return m_ypos;
114 };
115
116 int wxListItemData::GetWidth(void) const
117 {
118 return m_width;
119 };
120
121 int wxListItemData::GetHeight(void) const
122 {
123 return m_height;
124 };
125
126 int wxListItemData::GetImage(void) const
127 {
128 return m_image;
129 };
130
131 void wxListItemData::GetItem( wxListItem &info )
132 {
133 info.m_text = m_text;
134 info.m_image = m_image;
135 info.m_data = m_data;
136 };
137
138 wxColour *wxListItemData::GetColour(void)
139 {
140 return m_colour;
141 };
142
143 //-----------------------------------------------------------------------------
144 // wxListHeaderData
145 //-----------------------------------------------------------------------------
146
147 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderData,wxObject);
148
149 wxListHeaderData::wxListHeaderData(void)
150 {
151 m_mask = 0;
152 m_image = 0;
153 m_format = 0;
154 m_width = 0;
155 m_xpos = 0;
156 m_ypos = 0;
157 m_height = 0;
158 };
159
160 wxListHeaderData::wxListHeaderData( const wxListItem &item )
161 {
162 SetItem( item );
163 m_xpos = 0;
164 m_ypos = 0;
165 m_height = 0;
166 };
167
168 void wxListHeaderData::SetItem( const wxListItem &item )
169 {
170 m_mask = item.m_mask;
171 m_text = item.m_text;
172 m_image = item.m_image;
173 m_format = item.m_format;
174 m_width = item.m_width;
175 if (m_width < 0) m_width = 80;
176 if (m_width < 6) m_width = 6;
177 };
178
179 void wxListHeaderData::SetPosition( int x, int y )
180 {
181 m_xpos = x;
182 m_ypos = y;
183 };
184
185 void wxListHeaderData::SetHeight( int h )
186 {
187 m_height = h;
188 };
189
190 void wxListHeaderData::SetWidth( int w )
191 {
192 m_width = w;
193 if (m_width < 0) m_width = 80;
194 if (m_width < 6) m_width = 6;
195 };
196
197 void wxListHeaderData::SetFormat( int format )
198 {
199 m_format = format;
200 };
201
202 bool wxListHeaderData::HasImage(void) const
203 {
204 return (m_image != 0);
205 };
206
207 bool wxListHeaderData::HasText(void) const
208 {
209 return (m_text.Length() > 0);
210 };
211
212 bool wxListHeaderData::IsHit( int x, int y ) const
213 {
214 return ((x >= m_xpos) && (x <= m_xpos+m_width) && (y >= m_ypos) && (y <= m_ypos+m_height));
215 };
216
217 void wxListHeaderData::GetItem( wxListItem &item )
218 {
219 item.m_mask = m_mask;
220 item.m_text = m_text;
221 item.m_image = m_image;
222 item.m_format = m_format;
223 item.m_width = m_width;
224 };
225
226 void wxListHeaderData::GetText( wxString &s )
227 {
228 s = m_text;
229 };
230
231 int wxListHeaderData::GetImage(void) const
232 {
233 return m_image;
234 };
235
236 int wxListHeaderData::GetWidth(void) const
237 {
238 return m_width;
239 };
240
241 int wxListHeaderData::GetFormat(void) const
242 {
243 return m_format;
244 };
245
246 //-----------------------------------------------------------------------------
247 // wxListLineData
248 //-----------------------------------------------------------------------------
249
250 IMPLEMENT_DYNAMIC_CLASS(wxListLineData,wxObject);
251
252 wxListLineData::wxListLineData( wxListMainWindow *owner, int mode, wxBrush *hilightBrush )
253 {
254 m_mode = mode;
255 m_hilighted = FALSE;
256 m_owner = owner;
257 m_hilightBrush = hilightBrush;
258 m_items.DeleteContents( TRUE );
259 m_spacing = 0;
260 };
261
262 void wxListLineData::CalculateSize( wxPaintDC *dc, int spacing )
263 {
264 m_spacing = spacing;
265 switch (m_mode)
266 {
267 case wxLC_ICON:
268 {
269 m_bound_all.width = m_spacing;
270 m_bound_all.height = m_spacing+13;
271 wxNode *node = m_items.First();
272 if (node)
273 {
274 wxListItemData *item = (wxListItemData*)node->Data();
275 wxString s;
276 item->GetText( s );
277 long lw,lh;
278 dc->GetTextExtent( s, &lw, &lh );
279 if (lw > m_spacing) m_bound_all.width = lw;
280 };
281 break;
282 };
283 case wxLC_LIST:
284 {
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 m_bound_all.width = lw;
294 m_bound_all.height = lh;
295 };
296 break;
297 };
298 case wxLC_REPORT:
299 {
300 m_bound_all.width = 0;
301 m_bound_all.height = 0;
302 wxNode *node = m_items.First();
303 while (node)
304 {
305 wxListItemData *item = (wxListItemData*)node->Data();
306 wxString s;
307 item->GetText( s );
308 if (s.IsNull()) s = "H";
309 long lw,lh;
310 dc->GetTextExtent( s, &lw, &lh );
311 item->SetSize( item->GetWidth(), lh );
312 m_bound_all.width += lw;
313 m_bound_all.height = lh;
314 node = node->Next();
315 };
316 break;
317 };
318 };
319 };
320
321 void wxListLineData::SetPosition( wxPaintDC *dc, int x, int y, int window_width )
322 {
323 m_bound_all.x = x;
324 m_bound_all.y = y;
325 switch (m_mode)
326 {
327 case wxLC_ICON:
328 {
329 AssignRect( m_bound_icon, 0, 0, 0, 0 );
330 AssignRect( m_bound_label, 0, 0, 0, 0 );
331 AssignRect( m_bound_hilight, m_bound_all );
332 wxNode *node = m_items.First();
333 if (node)
334 {
335 wxListItemData *item = (wxListItemData*)node->Data();
336 if (item->HasImage())
337 {
338 wxListItemData *item = (wxListItemData*)node->Data();
339 int w = 0;
340 int h = 0;
341 m_owner->GetImageSize( item->GetImage(), w, h );
342 m_bound_icon.x = m_bound_all.x + (m_spacing/2) - (w/2);
343 m_bound_icon.y = m_bound_all.y + m_spacing - h - 5;
344 m_bound_icon.width = w;
345 m_bound_icon.height = h;
346 if (!item->HasText())
347 {
348 AssignRect( m_bound_hilight, m_bound_icon );
349 m_bound_hilight.x -= 3;
350 m_bound_hilight.y -= 3;
351 m_bound_hilight.width += 7;
352 m_bound_hilight.height += 7;
353 };
354 };
355 if (item->HasText())
356 {
357 wxString s;
358 item->GetText( s );
359 long lw,lh;
360 dc->GetTextExtent( s, &lw, &lh );
361 if (m_bound_all.width > m_spacing)
362 m_bound_label.x = m_bound_all.x;
363 else
364 m_bound_label.x = m_bound_all.x + (m_spacing/2) - lw/2;
365 m_bound_label.y = m_bound_all.y + m_bound_all.height - lh;
366 m_bound_label.width = lw;
367 m_bound_label.height = lh;
368 AssignRect( m_bound_hilight, m_bound_label );
369 };
370 };
371 break;
372 };
373 case wxLC_LIST:
374 {
375 AssignRect( m_bound_label, m_bound_all );
376 AssignRect( m_bound_hilight, m_bound_all );
377 AssignRect( m_bound_icon, 0, 0, 0, 0 );
378 break;
379 };
380 case wxLC_REPORT:
381 {
382 long lw,lh;
383 dc->GetTextExtent( "H", &lw, &lh );
384 m_bound_all.height = lh;
385 m_bound_all.width = window_width;
386 AssignRect( m_bound_label, m_bound_all );
387 AssignRect( m_bound_hilight, m_bound_all );
388 AssignRect( m_bound_icon, 0, 0, 0, 0 );
389 m_bound_hilight.width = window_width-10;
390 m_bound_label.width = window_width-10;
391 break;
392 };
393 };
394 };
395
396 void wxListLineData::SetColumnPosition( int index, int x )
397 {
398 int i = index;
399 wxNode *node = m_items.Nth( i );
400 if (node)
401 {
402 wxListItemData *item = (wxListItemData*)node->Data();
403 item->SetPosition( x, m_bound_all.y );
404 };
405 };
406
407 void wxListLineData::GetSize( int &width, int &height )
408 {
409 width = m_bound_all.width;
410 height = m_bound_all.height;
411 };
412
413 void wxListLineData::GetExtent( int &x, int &y, int &width, int &height )
414 {
415 x = m_bound_all.x;
416 y = m_bound_all.y;
417 width = m_bound_all.width;
418 height = m_bound_all.height;
419 };
420
421 void wxListLineData::GetLabelExtent( int &x, int &y, int &width, int &height )
422 {
423 x = m_bound_label.x;
424 y = m_bound_label.y;
425 width = m_bound_label.width;
426 height = m_bound_label.height;
427 };
428
429 void wxListLineData::GetRect( wxRectangle &rect )
430 {
431 AssignRect( rect, m_bound_all );
432 };
433
434 long wxListLineData::IsHit( int x, int y )
435 {
436 wxNode *node = m_items.First();
437 if (node)
438 {
439 wxListItemData *item = (wxListItemData*)node->Data();
440 if (item->HasImage() && IsInRect( x, y, m_bound_icon )) return wxLIST_HITTEST_ONITEMICON;
441 if (item->HasText() && IsInRect( x, y, m_bound_label )) return wxLIST_HITTEST_ONITEMLABEL;
442 // if (!(item->HasImage() || item->HasText())) return 0;
443 };
444 // if there is no icon or text = empty
445 if (IsInRect( x, y, m_bound_all )) return wxLIST_HITTEST_ONITEMICON;
446 return 0;
447 };
448
449 void wxListLineData::InitItems( int num )
450 {
451 for (int i = 0; i < num; i++) m_items.Append( new wxListItemData() );
452 };
453
454 void wxListLineData::SetItem( int index, const wxListItem &info )
455 {
456 wxNode *node = m_items.Nth( index );
457 if (node)
458 {
459 wxListItemData *item = (wxListItemData*)node->Data();
460 item->SetItem( info );
461 };
462 };
463
464 void wxListLineData::GetItem( int const index, wxListItem &info )
465 {
466 int i = index;
467 wxNode *node = m_items.Nth( i );
468 if (node)
469 {
470 wxListItemData *item = (wxListItemData*)node->Data();
471 item->GetItem( info );
472 };
473 };
474
475 void wxListLineData::GetText( int index, wxString &s )
476 {
477 int i = index;
478 wxNode *node = m_items.Nth( i );
479 s = "";
480 if (node)
481 {
482 wxListItemData *item = (wxListItemData*)node->Data();
483 item->GetText( s );
484 };
485 };
486
487 void wxListLineData::SetText( int index, const wxString s )
488 {
489 int i = index;
490 wxNode *node = m_items.Nth( i );
491 if (node)
492 {
493 wxListItemData *item = (wxListItemData*)node->Data();
494 item->SetText( s );
495 };
496 };
497
498 int wxListLineData::GetImage( int index )
499 {
500 int i = index;
501 wxNode *node = m_items.Nth( i );
502 if (node)
503 {
504 wxListItemData *item = (wxListItemData*)node->Data();
505 return item->GetImage();
506 };
507 return -1;
508 };
509
510 void wxListLineData::DoDraw( wxPaintDC *dc, bool hilight, bool paintBG )
511 {
512 long dev_x = dc->LogicalToDeviceX( m_bound_all.x-2 );
513 long dev_y = dc->LogicalToDeviceY( m_bound_all.y-2 );
514 long dev_w = dc->LogicalToDeviceXRel( m_bound_all.width+4 );
515 long dev_h = dc->LogicalToDeviceYRel( m_bound_all.height+4 );
516 if (!m_owner->IsExposed( dev_x, dev_y, dev_w, dev_h ) ) return;
517
518 if (paintBG)
519 {
520 if (hilight)
521 {
522 dc->SetBrush( m_hilightBrush );
523 dc->SetPen( wxTRANSPARENT_PEN );
524 }
525 else
526 {
527 dc->SetBrush( wxWHITE_BRUSH );
528 dc->SetPen( wxTRANSPARENT_PEN );
529 };
530 dc->DrawRectangle( m_bound_hilight.x-2, m_bound_hilight.y-2,
531 m_bound_hilight.width+4, m_bound_hilight.height+4 );
532 };
533 if (m_mode == wxLC_REPORT)
534 {
535 wxString s;
536 wxNode *node = m_items.First();
537 while (node)
538 {
539 wxListItemData *info = (wxListItemData*)node->Data();
540 dc->SetClippingRegion( info->GetX(), info->GetY(), info->GetWidth(), info->GetHeight() );
541 info->GetText( s );
542 if (hilight)
543 dc->SetTextForeground( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT ) );
544 else
545 dc->SetTextForeground( info->GetColour() );
546 dc->DrawText( s, info->GetX()+2, info->GetY() );
547 dc->DestroyClippingRegion();
548 node = node->Next();
549 };
550 }
551 else
552 {
553 wxNode *node = m_items.First();
554 if (node)
555 {
556 wxListItemData *item = (wxListItemData*)node->Data();
557 if (item->HasImage())
558 {
559 m_owner->DrawImage( item->GetImage(), dc, m_bound_icon.x, m_bound_icon.y );
560 };
561 if (item->HasText())
562 {
563 wxString s;
564 item->GetText( s );
565 if (hilight)
566 dc->SetTextForeground( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT ) );
567 else
568 dc->SetTextForeground( item->GetColour() );
569 dc->DrawText( s, m_bound_label.x, m_bound_label.y );
570 };
571 };
572 };
573 };
574
575 void wxListLineData::Hilight( bool on )
576 {
577 if (on == m_hilighted) return;
578 if (on)
579 m_owner->SelectLine( this );
580 else
581 m_owner->DeselectLine( this );
582 m_hilighted = on;
583 };
584
585 void wxListLineData::ReverseHilight( void )
586 {
587 m_hilighted = !m_hilighted;
588 if (m_hilighted)
589 m_owner->SelectLine( this );
590 else
591 m_owner->DeselectLine( this );
592 };
593
594 void wxListLineData::DrawRubberBand( wxPaintDC *dc, bool on )
595 {
596 if (on)
597 {
598 dc->SetPen( wxBLACK_PEN );
599 dc->SetBrush( wxTRANSPARENT_BRUSH );
600 dc->DrawRectangle( m_bound_hilight.x-2, m_bound_hilight.y-2,
601 m_bound_hilight.width+4, m_bound_hilight.height+4 );
602 };
603 };
604
605 void wxListLineData::Draw( wxPaintDC *dc )
606 {
607 DoDraw( dc, m_hilighted, m_hilighted );
608 };
609
610 bool wxListLineData::IsInRect( int x, int y, const wxRectangle &rect )
611 {
612 return ((x >= rect.x) && (x <= rect.x+rect.width) && (y >= rect.y) && (y <= rect.y+rect.height));
613 };
614
615 bool wxListLineData::IsHilighted( void )
616 {
617 return m_hilighted;
618 };
619
620 void wxListLineData::AssignRect( wxRectangle &dest, int x, int y, int width, int height )
621 {
622 dest.x = x;
623 dest.y = y;
624 dest.width = width;
625 dest.height = height;
626 };
627
628 void wxListLineData::AssignRect( wxRectangle &dest, const wxRectangle &source )
629 {
630 dest.x = source.x;
631 dest.y = source.y;
632 dest.width = source.width;
633 dest.height = source.height;
634 };
635
636 //-----------------------------------------------------------------------------
637 // wxListHeaderWindow
638 //-----------------------------------------------------------------------------
639
640 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow,wxWindow);
641
642 BEGIN_EVENT_TABLE(wxListHeaderWindow,wxWindow)
643 EVT_PAINT (wxListHeaderWindow::OnPaint)
644 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse)
645 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus)
646 END_EVENT_TABLE()
647
648 wxListHeaderWindow::wxListHeaderWindow( void )
649 {
650 m_owner = NULL;
651 m_currentCursor = NULL;
652 m_resizeCursor = NULL;
653 };
654
655 wxListHeaderWindow::wxListHeaderWindow( wxWindow *win, wxWindowID id, wxListMainWindow *owner,
656 const wxPoint &pos, const wxSize &size,
657 long style, const wxString &name ) :
658 wxWindow( win, id, pos, size, style, name )
659 {
660 m_owner = owner;
661 // m_currentCursor = wxSTANDARD_CURSOR;
662 m_currentCursor = NULL;
663 m_resizeCursor = new wxCursor( wxCURSOR_SIZEWE );
664 };
665
666 void wxListHeaderWindow::DoDrawRect( wxPaintDC *dc, int x, int y, int w, int h )
667 {
668 const m_corner = 1;
669
670 dc->SetBrush( *wxTRANSPARENT_BRUSH );
671
672 dc->SetPen( *wxBLACK_PEN );
673 dc->DrawLine( x+w-m_corner+1, y, x+w, y+h ); // right (outer)
674 dc->DrawRectangle( x, y+h, w, 1 ); // bottom (outer)
675
676 dc->SetPen( *wxMEDIUM_GREY_PEN );
677 dc->DrawLine( x+w-m_corner, y, x+w-1, y+h ); // right (inner)
678 dc->DrawRectangle( x+1, y+h-1, w-2, 1 ); // bottom (inner)
679
680 dc->SetPen( *wxWHITE_PEN );
681 dc->DrawRectangle( x, y, w-m_corner+1, 1 ); // top (outer)
682 // dc->DrawRectangle( x, y+1, w-m_corner, 1 ); // top (inner)
683 dc->DrawRectangle( x, y, 1, h ); // left (outer)
684 // dc->DrawRectangle( x+1, y, 1, h-1 ); // left (inner)
685 };
686
687 void wxListHeaderWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
688 {
689 wxPaintDC dc( this );
690 PrepareDC( dc );
691
692 dc.BeginDrawing();
693
694 dc.SetFont( wxSystemSettings::GetSystemFont( wxSYS_SYSTEM_FONT ) );
695
696 int w = 0;
697 int h = 0;
698 int x = 0;
699 int y = 0;
700 GetClientSize( &w, &h );
701
702 dc.SetTextForeground( *wxBLACK );
703
704 x = 1;
705 y = 1;
706 int numColumns = m_owner->GetColumnCount();
707 wxListItem item;
708 for (int i = 0; i < numColumns; i++)
709 {
710 m_owner->GetColumn( i, item );
711 int cw = item.m_width-2;
712 if ((i+1 == numColumns) || (x+item.m_width > w-5)) cw = w-x-1;
713 dc.SetPen( *wxWHITE_PEN );
714
715 DoDrawRect( &dc, x, y, cw, h-2 );
716 dc.SetClippingRegion( x, y, cw-5, h-4 );
717 dc.DrawText( item.m_text, x+4, y+3 );
718 dc.DestroyClippingRegion();
719 x += item.m_width;
720 if (x > w+5) break;
721 };
722 dc.EndDrawing();
723 };
724
725 void wxListHeaderWindow::OnMouse( wxMouseEvent &event )
726 {
727 float fx = 0;
728 float fy = 0;
729 event.Position( &fx, &fy );
730 int x = (int)fx;
731 int y = (int)fy;
732 if (event.Moving())
733 {
734 bool hit = FALSE;
735 int xpos = 0;
736 for (int j = 0; j < m_owner->GetColumnCount(); j++)
737 {
738 xpos += m_owner->GetColumnWidth( j );
739 if ((abs(x-xpos) < 2) && (y < 14)) { hit = TRUE; break; }
740 };
741 if (hit)
742 {
743 if (m_currentCursor == wxSTANDARD_CURSOR) SetCursor( m_resizeCursor );
744 m_currentCursor = m_resizeCursor;
745 }
746 else
747 {
748 if (m_currentCursor != wxSTANDARD_CURSOR) SetCursor( wxSTANDARD_CURSOR );
749 m_currentCursor = wxSTANDARD_CURSOR;
750 };
751 };
752 };
753
754 void wxListHeaderWindow::OnSetFocus( wxFocusEvent &WXUNUSED(event) )
755 {
756 m_owner->SetFocus();
757 };
758
759 //-----------------------------------------------------------------------------
760 // wxListRenameTimer (internal)
761 //-----------------------------------------------------------------------------
762
763 wxListRenameTimer::wxListRenameTimer( wxListMainWindow *owner )
764 {
765 m_owner = owner;
766 };
767
768 void wxListRenameTimer::Notify()
769 {
770 m_owner->OnRenameTimer();
771 };
772
773 //-----------------------------------------------------------------------------
774 // wxListMainWindow
775 //-----------------------------------------------------------------------------
776
777 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow,wxScrolledWindow);
778
779 BEGIN_EVENT_TABLE(wxListMainWindow,wxScrolledWindow)
780 EVT_PAINT (wxListMainWindow::OnPaint)
781 EVT_SIZE (wxListMainWindow::OnSize)
782 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse)
783 EVT_CHAR (wxListMainWindow::OnChar)
784 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus)
785 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus)
786 END_EVENT_TABLE()
787
788 wxListMainWindow::wxListMainWindow( void )
789 {
790 m_mode = 0;
791 m_lines.DeleteContents( TRUE );
792 m_columns.DeleteContents( TRUE );
793 m_current = NULL;
794 m_visibleLines = 0;
795 m_hilightBrush = NULL;
796 m_myFont = NULL;
797 m_xScroll = 0;
798 m_yScroll = 0;
799 m_dirty = TRUE;
800 m_small_image_list = NULL;
801 m_normal_image_list = NULL;
802 m_small_spacing = 30;
803 m_normal_spacing = 40;
804 m_hasFocus = FALSE;
805 m_usedKeys = TRUE;
806 m_lastOnSame = FALSE;
807 // m_renameTimer = new wxRenameTimer( this );
808 m_isCreated = FALSE;
809 m_dragCount = 0;
810 };
811
812 wxListMainWindow::wxListMainWindow( wxWindow *parent, wxWindowID id,
813 const wxPoint &pos, const wxSize &size,
814 long style, const wxString &name ) :
815 wxScrolledWindow( parent, id, pos, size, style, name )
816 {
817 m_mode = style;
818 m_lines.DeleteContents( TRUE );
819 m_columns.DeleteContents( TRUE );
820 m_current = NULL;
821 m_dirty = TRUE;
822 m_visibleLines = 0;
823 m_hilightBrush = new wxBrush( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT), wxSOLID );
824 m_small_image_list = NULL;
825 m_normal_image_list = NULL;
826 m_small_spacing = 30;
827 m_normal_spacing = 40;
828 // AllowDoubleClick( TRUE );
829 m_myFont = wxNORMAL_FONT;
830 m_hasFocus = FALSE;
831 m_dragCount = 0;
832 m_isCreated = FALSE;
833 wxSize sz = size;
834 sz.y = 25;
835
836 if (m_mode & wxLC_REPORT)
837 {
838 m_xScroll = 0;
839 m_yScroll = 15;
840 }
841 else
842 {
843 m_xScroll = 15;
844 m_yScroll = 0;
845 };
846 SetScrollbars( m_xScroll, m_yScroll, 0, 0, 0, 0 );
847
848 m_usedKeys = TRUE;
849 m_lastOnSame = FALSE;
850 m_renameTimer = new wxListRenameTimer( this );
851 m_renameAccept = FALSE;
852 // m_text = new wxRawListTextCtrl( GetParent(), "", &m_renameAccept, &m_renameRes, this, 10, 10, 40, 10 );
853 // m_text->Show( FALSE );
854
855 SetBackgroundColour( *wxWHITE );
856
857 /*
858 char *accepted_drop_types[] = { "text/plain" };
859 gtk_widget_dnd_drag_set( m_wxwindow, TRUE, accepted_drop_types, 1 );
860 */
861 };
862
863 wxListMainWindow::~wxListMainWindow( void )
864 {
865 // if (m_hilightColour) delete m_hilightColour;
866 // if (m_hilightBrush) delete m_hilightBrush;
867 // if (m_myFont) delete m_myFont;
868 delete m_renameTimer;
869 // delete m_text;
870 };
871
872 void wxListMainWindow::RefreshLine( wxListLineData *line )
873 {
874 int x = 0;
875 int y = 0;
876 int w = 0;
877 int h = 0;
878 if (line)
879 {
880 wxClientDC dc(this);
881 PrepareDC( dc );
882 line->GetExtent( x, y, w, h );
883 wxRectangle rect(
884 dc.LogicalToDeviceX(x-3),
885 dc.LogicalToDeviceY(y-3),
886 dc.LogicalToDeviceXRel(w+6),
887 dc.LogicalToDeviceXRel(h+6) );
888 Refresh( TRUE, &rect );
889 };
890 };
891
892 void wxListMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
893 {
894 if (m_dirty) return;
895
896 wxPaintDC dc( this );
897 PrepareDC( dc );
898
899 dc.BeginDrawing();
900
901 // dc.SetFont( *m_myFont );
902 dc.SetFont( wxSystemSettings::GetSystemFont( wxSYS_SYSTEM_FONT ) );
903
904 wxNode *node = m_lines.First();
905 while (node)
906 {
907 wxListLineData *line = (wxListLineData*)node->Data();
908 line->Draw( &dc );
909 node = node->Next();
910 };
911 if (m_current) m_current->DrawRubberBand( &dc, m_hasFocus );
912
913 dc.EndDrawing();
914 };
915
916 void wxListMainWindow::HilightAll( bool on )
917 {
918 wxNode *node = m_lines.First();
919 while (node)
920 {
921 wxListLineData *line = (wxListLineData *)node->Data();
922 if (line->IsHilighted() != on)
923 {
924 line->Hilight( on );
925 RefreshLine( line );
926 };
927 node = node->Next();
928 };
929 };
930
931 void wxListMainWindow::ActivateLine( wxListLineData *line )
932 {
933 if (!m_parent) return;
934 wxListEvent le( wxEVT_COMMAND_LIST_KEY_DOWN, m_parent->GetId() );
935 le.SetEventObject( m_parent );
936 le.m_code = 0;
937 le.m_itemIndex = GetIndexOfLine( line );
938 le.m_col = 0;
939 line->GetItem( 0, le.m_item );
940 OnListNotify( le );
941 };
942
943 void wxListMainWindow::SendNotify( wxListLineData *line, wxEventType command )
944 {
945 if (!m_parent) return;
946 wxListEvent le( command, m_parent->GetId() );
947 le.SetEventObject( m_parent );
948 le.m_code = 0;
949 le.m_itemIndex = GetIndexOfLine( line );
950 le.m_col = 0;
951 line->GetItem( 0, le.m_item );
952 OnListNotify( le );
953 };
954
955 void wxListMainWindow::FocusLine( wxListLineData *WXUNUSED(line) )
956 {
957 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_FOCUSSED );
958 };
959
960 void wxListMainWindow::UnfocusLine( wxListLineData *WXUNUSED(line) )
961 {
962 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_UNFOCUSSED );
963 };
964
965 void wxListMainWindow::SelectLine( wxListLineData *line )
966 {
967 SendNotify( line, wxEVT_COMMAND_LIST_ITEM_SELECTED );
968 };
969
970 void wxListMainWindow::DeselectLine( wxListLineData *line )
971 {
972 SendNotify( line, wxEVT_COMMAND_LIST_ITEM_DESELECTED );
973 };
974
975 void wxListMainWindow::DeleteLine( wxListLineData *line )
976 {
977 SendNotify( line, wxEVT_COMMAND_LIST_DELETE_ITEM );
978 };
979
980 void wxListMainWindow::RenameLine( wxListLineData *line, const wxString &newName )
981 {
982 wxListEvent le( wxEVT_COMMAND_LIST_END_LABEL_EDIT );
983 le.m_code = 0;
984 le.m_itemIndex = GetIndexOfLine( line );
985 le.m_col = 0;
986 line->GetItem( 0, le.m_item );
987 le.m_item.m_text = newName;
988 OnListNotify( le );
989 };
990
991 void wxListMainWindow::OnRenameTimer()
992 {
993 return;
994 wxString s;
995 m_current->GetText( 0, s );
996 int x = 0;
997 int y = 0;
998 int w = 0;
999 int h = 0;
1000 m_current->GetLabelExtent( x, y, w, h );
1001 int dx = 0;
1002 int dy = 0;
1003 GetPosition( &dx, &dy );
1004 x += dx;
1005 y += dy;
1006 /*
1007 wxRawListTextCtrl *text = new wxRawListTextCtrl(
1008 GetParent(), s, &m_renameAccept, &m_renameRes, this, x+2, y+2, w+8, h+8 );
1009 text->SetFocus();
1010 */
1011 /*
1012 m_text->SetSize( x+3, y+3, w+6, h+6 );
1013 m_text->SetValue( s );
1014 m_text->Show( TRUE );
1015 m_text->SetFocus();
1016 */
1017 /*
1018 char *res = wxGetTextFromUser( "Enter new name:", "", s );
1019 if (res)
1020 {
1021 m_dirty = TRUE;
1022 s = res;
1023 RenameLine( m_current, s );
1024 };
1025 */
1026 };
1027
1028 void wxListMainWindow::OnRenameAccept()
1029 {
1030 RenameLine( m_current, m_renameRes );
1031 };
1032
1033 void wxListMainWindow::OnMouse( wxMouseEvent &event )
1034 {
1035 if (m_parent->ProcessEvent( event)) return;
1036
1037 if (!m_current) return;
1038 if (m_dirty) return;
1039
1040 wxClientDC dc(this);
1041 PrepareDC(dc);
1042 long x = dc.DeviceToLogicalX( (long)event.GetX() );
1043 long y = dc.DeviceToLogicalY( (long)event.GetY() );
1044
1045 long hitResult = 0;
1046 wxNode *node = m_lines.First();
1047 wxListLineData *line = NULL;
1048 while (node)
1049 {
1050 line = (wxListLineData*)node->Data();
1051 hitResult = line->IsHit( x, y );
1052 if (hitResult) break;
1053 line = NULL;
1054 node = node->Next();
1055 };
1056
1057 if (!event.Dragging())
1058 m_dragCount = 0;
1059 else
1060 m_dragCount++;
1061
1062 if (event.Dragging() && (m_dragCount > 3))
1063 {
1064 m_dragCount = 0;
1065 wxListEvent le( wxEVT_COMMAND_LIST_BEGIN_DRAG, m_parent->GetId() );
1066 le.SetEventObject( this );
1067 le.m_code = 0;
1068 le.m_itemIndex = 0;
1069 le.m_col = 0;
1070 OnListNotify( le );
1071 };
1072
1073 if (!line) return;
1074
1075 if (event.ButtonDClick())
1076 {
1077 m_usedKeys = FALSE;
1078 m_lastOnSame = FALSE;
1079 m_renameTimer->Stop();
1080 ActivateLine( line );
1081 return;
1082 };
1083
1084 if (event.LeftUp() && m_lastOnSame)
1085 {
1086 m_usedKeys = FALSE;
1087 if ((line == m_current) &&
1088 (hitResult == wxLIST_HITTEST_ONITEMLABEL) /* &&
1089 (m_mode & wxLC_ICON) */ )
1090 {
1091 m_renameTimer->Start( 330, TRUE );
1092 };
1093 m_lastOnSame = FALSE;
1094 return;
1095 };
1096
1097 if (event.LeftDown())
1098 {
1099 m_usedKeys = FALSE;
1100 wxListLineData *oldCurrent = m_current;
1101 if (m_mode & wxLC_SINGLE_SEL)
1102 {
1103 m_current = line;
1104 HilightAll( FALSE );
1105 m_current->ReverseHilight();
1106 }
1107 else
1108 {
1109 if (event.ShiftDown())
1110 {
1111 m_current = line;
1112 m_current->ReverseHilight();
1113 }
1114 else if (event.ControlDown())
1115 {
1116 m_current = line;
1117 int numOfCurrent = -1;
1118 node = m_lines.First();
1119 while (node)
1120 {
1121 wxListLineData *test_line = (wxListLineData*)node->Data();
1122 numOfCurrent++;
1123 if (test_line == oldCurrent) break;
1124 node = node->Next();
1125 };
1126 int numOfLine = -1;
1127 node = m_lines.First();
1128 while (node)
1129 {
1130 wxListLineData *test_line = (wxListLineData*)node->Data();
1131 numOfLine++;
1132 if (test_line == line) break;
1133 node = node->Next();
1134 };
1135
1136 if (numOfLine < numOfCurrent)
1137 { int i = numOfLine; numOfLine = numOfCurrent; numOfCurrent = i; }
1138 wxNode *node = m_lines.Nth( numOfCurrent );
1139 for (int i = 0; i <= numOfLine-numOfCurrent; i++)
1140 {
1141 wxListLineData *test_line= (wxListLineData*)node->Data();
1142 test_line->Hilight(TRUE);
1143 RefreshLine( test_line );
1144 node = node->Next();
1145 }
1146 return;
1147 }
1148 else
1149 {
1150 m_current = line;
1151 HilightAll( FALSE );
1152 m_current->ReverseHilight();
1153 }
1154 }
1155 RefreshLine( m_current );
1156 if (m_current != oldCurrent)
1157 {
1158 UnfocusLine( oldCurrent );
1159 FocusLine( m_current );
1160 RefreshLine( oldCurrent );
1161 };
1162 m_lastOnSame = (m_current == oldCurrent);
1163 return;
1164 };
1165
1166 };
1167
1168 void wxListMainWindow::MoveToFocus( void )
1169 {
1170 if (!m_current) return;
1171 /*
1172 int x = 0;
1173 int y = 0;
1174 int w = 0;
1175 int h = 0;
1176 m_current->GetExtent( x, y, w, h );
1177 int w_p = 0;
1178 int h_p = 0;
1179 GetClientSize( &w_p, &h_p );
1180 if (m_mode & wxLC_REPORT)
1181 {
1182 if (GetScrollPos( wxHORIZONTAL ) != 0) SetScrollPos( wxHORIZONTAL, 0);
1183 int y_s = m_yScroll*GetScrollPos( wxVERTICAL );
1184 if ((y > y_s) && (y+h < y_s+h_p)) return;
1185 if (y-y_s < 5) SetScrollPos( wxVERTICAL, (y-5)/m_yScroll );
1186 if (y+h+5 > y_s+h_p) SetScrollPos( wxVERTICAL, (y+h-h_p+h+5)/m_yScroll );
1187 }
1188 else
1189 {
1190 if (GetScrollPos( wxVERTICAL ) != 0) SetScrollPos( wxVERTICAL, 0);
1191 int x_s = m_xScroll*GetScrollPos( wxHORIZONTAL );
1192 if ((x > x_s) && (x+w < x_s+w_p)) return;
1193 if (x-x_s < 5) SetScrollPos( wxHORIZONTAL, (x-5)/m_xScroll );
1194 if (x+w > x_s+w_p) SetScrollPos( wxHORIZONTAL, (x+w-w_p+5)/m_xScroll );
1195 };
1196 */
1197 };
1198
1199 void wxListMainWindow::OnArrowChar( wxListLineData *newCurrent, bool shiftDown )
1200 {
1201 UnfocusLine( m_current );
1202 if ((m_mode & wxLC_SINGLE_SEL) || (m_usedKeys == FALSE)) m_current->Hilight( FALSE );
1203 wxListLineData *oldCurrent = m_current;
1204 m_current = newCurrent;
1205 MoveToFocus();
1206 if (shiftDown || (m_mode & wxLC_SINGLE_SEL)) m_current->Hilight( TRUE );
1207 FocusLine( m_current );
1208 RefreshLine( m_current );
1209 RefreshLine( oldCurrent );
1210 };
1211
1212 void wxListMainWindow::OnChar( wxKeyEvent &event )
1213 {
1214 /*
1215 if (event.KeyCode() == WXK_TAB)
1216 {
1217 if (event.ShiftDown())
1218 TravPrev( &event );
1219 else
1220 TravNext( &event );
1221 return;
1222 };
1223 */
1224 if (!m_current) return;
1225 switch (event.KeyCode())
1226 {
1227 case WXK_UP:
1228 {
1229 wxNode *node = m_lines.Member( m_current )->Previous();
1230 if (node) OnArrowChar( (wxListLineData*)node->Data(), event.ShiftDown() );
1231 break;
1232 };
1233 case WXK_DOWN:
1234 {
1235 wxNode *node = m_lines.Member( m_current )->Next();
1236 if (node) OnArrowChar( (wxListLineData*)node->Data(), event.ShiftDown() );
1237 break;
1238 };
1239 case WXK_END:
1240 {
1241 wxNode *node = m_lines.Last();
1242 OnArrowChar( (wxListLineData*)node->Data(), event.ShiftDown() );
1243 break;
1244 };
1245 case WXK_HOME:
1246 {
1247 wxNode *node = m_lines.First();
1248 OnArrowChar( (wxListLineData*)node->Data(), event.ShiftDown() );
1249 break;
1250 };
1251 case WXK_PRIOR:
1252 {
1253 int steps = 0;
1254 if (m_mode & wxLC_REPORT) { steps = m_visibleLines-1; }
1255 else
1256 {
1257 int pos = 0;
1258 wxNode *node = m_lines.First();
1259 for (;;) { if (m_current == (wxListLineData*)node->Data()) break; pos++; node = node->Next(); };
1260 steps = pos % m_visibleLines;
1261 };
1262 wxNode *node = m_lines.Member( m_current );
1263 for (int i = 0; i < steps; i++) if (node->Previous()) node = node->Previous();
1264 if (node) OnArrowChar( (wxListLineData*)node->Data(), event.ShiftDown() );
1265 break;
1266 };
1267 case WXK_NEXT:
1268 {
1269 int steps = 0;
1270 if (m_mode & wxLC_REPORT) { steps = m_visibleLines-1; }
1271 else
1272 {
1273 int pos = 0; wxNode *node = m_lines.First();
1274 for (;;) { if (m_current == (wxListLineData*)node->Data()) break; pos++; node = node->Next(); };
1275 steps = m_visibleLines-(pos % m_visibleLines)-1;
1276 };
1277 wxNode *node = m_lines.Member( m_current );
1278 for (int i = 0; i < steps; i++) if (node->Next()) node = node->Next();
1279 if (node) OnArrowChar( (wxListLineData*)node->Data(), event.ShiftDown() );
1280 break;
1281 };
1282 case WXK_LEFT:
1283 {
1284 if (!(m_mode & wxLC_REPORT))
1285 {
1286 wxNode *node = m_lines.Member( m_current );
1287 for (int i = 0; i <m_visibleLines; i++) if (node->Previous()) node = node->Previous();
1288 if (node) OnArrowChar( (wxListLineData*)node->Data(), event.ShiftDown() );
1289 };
1290 break;
1291 };
1292 case WXK_RIGHT:
1293 {
1294 if (!(m_mode & wxLC_REPORT))
1295 {
1296 wxNode *node = m_lines.Member( m_current );
1297 for (int i = 0; i <m_visibleLines; i++) if (node->Next()) node = node->Next();
1298 if (node) OnArrowChar( (wxListLineData*)node->Data(), event.ShiftDown() );
1299 };
1300 break;
1301 };
1302 case WXK_SPACE:
1303 {
1304 m_current->ReverseHilight();
1305 RefreshLine( m_current );
1306 };
1307 break;
1308 case WXK_INSERT:
1309 {
1310 if (!(m_mode & wxLC_SINGLE_SEL))
1311 {
1312 wxListLineData *oldCurrent = m_current;
1313 UnfocusLine( m_current );
1314 m_current->ReverseHilight();
1315 wxNode *node = m_lines.Member( m_current )->Next();
1316 if (node) m_current = (wxListLineData*)node->Data();
1317 MoveToFocus();
1318 FocusLine( m_current );
1319 RefreshLine( m_current );
1320 RefreshLine( oldCurrent );
1321 };
1322 };
1323 break;
1324 case WXK_RETURN:
1325 case WXK_EXECUTE:
1326 {
1327 ActivateLine( m_current );
1328 };
1329 break;
1330 default:
1331 {
1332 event.Skip();
1333 return;
1334 };
1335 };
1336 m_usedKeys = TRUE;
1337 };
1338
1339 void wxListMainWindow::OnSetFocus( wxFocusEvent &WXUNUSED(event) )
1340 {
1341 m_hasFocus = TRUE;
1342 RefreshLine( m_current );
1343
1344 if (!m_parent) return;
1345
1346 wxFocusEvent event( wxEVT_SET_FOCUS, m_parent->GetId() );
1347 event.SetEventObject( m_parent );
1348 m_parent->ProcessEvent( event );
1349 };
1350
1351 void wxListMainWindow::OnKillFocus( wxFocusEvent &WXUNUSED(event) )
1352 {
1353 m_hasFocus = FALSE;
1354 RefreshLine( m_current );
1355 };
1356
1357 void wxListMainWindow::OnSize( wxSizeEvent &WXUNUSED(event) )
1358 {
1359 /*
1360 We don't even allow the wxScrolledWindow::AdjustScrollbars() call
1361
1362 CalculatePositions();
1363 printf( "OnSize::Refresh.\n" );
1364 Refresh();
1365 event.Skip();
1366 */
1367 };
1368
1369 wxFont *wxListMainWindow::GetMyFont( void )
1370 {
1371 return m_myFont;
1372 };
1373
1374 void wxListMainWindow::DrawImage( int index, wxPaintDC *dc, int x, int y )
1375 {
1376 if ((m_mode & wxLC_ICON) && (m_normal_image_list))
1377 {
1378 m_normal_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT );
1379 return;
1380 };
1381 if ((m_mode & wxLC_SMALL_ICON) && (m_small_image_list))
1382 {
1383 m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT );
1384 };
1385 };
1386
1387 void wxListMainWindow::GetImageSize( int index, int &width, int &height )
1388 {
1389 if ((m_mode & wxLC_ICON) && (m_normal_image_list))
1390 {
1391 m_normal_image_list->GetSize( index, width, height );
1392 return;
1393 };
1394 if ((m_mode & wxLC_SMALL_ICON) && (m_small_image_list))
1395 {
1396 m_small_image_list->GetSize( index, width, height );
1397 return;
1398 };
1399 width = 0;
1400 height = 0;
1401 };
1402
1403 int wxListMainWindow::GetTextLength( wxString &s )
1404 {
1405 wxPaintDC dc( this );
1406 long lw = 0;
1407 long lh = 0;
1408 dc.GetTextExtent( s, &lw, &lh );
1409 return lw + 6;
1410 };
1411
1412 int wxListMainWindow::GetIndexOfLine( const wxListLineData *line )
1413 {
1414 int i = 0;
1415 wxNode *node = m_lines.First();
1416 while (node)
1417 {
1418 if (line == (wxListLineData*)node->Data()) return i;
1419 i++;
1420 node = node->Next();
1421 };
1422 return -1;
1423 };
1424
1425 void wxListMainWindow::SetImageList( wxImageList *imageList, int which )
1426 {
1427 m_dirty = TRUE;
1428 if (which == wxIMAGE_LIST_NORMAL) m_normal_image_list = imageList;
1429 if (which == wxIMAGE_LIST_SMALL) m_small_image_list = imageList;
1430 };
1431
1432 void wxListMainWindow::SetItemSpacing( int spacing, bool isSmall )
1433 {
1434 m_dirty = TRUE;
1435 if (isSmall)
1436 {
1437 m_small_spacing = spacing;
1438 }
1439 else
1440 {
1441 m_normal_spacing = spacing;
1442 };
1443 };
1444
1445 int wxListMainWindow::GetItemSpacing( bool isSmall )
1446 {
1447 if (isSmall) return m_small_spacing; else return m_normal_spacing;
1448 };
1449
1450 void wxListMainWindow::SetColumn( int col, wxListItem &item )
1451 {
1452 m_dirty = TRUE;
1453 wxNode *node = m_columns.Nth( col );
1454 if (node)
1455 {
1456 if (item.m_width == wxLIST_AUTOSIZE_USEHEADER) item.m_width = GetTextLength( item.m_text )+7;
1457 wxListHeaderData *column = (wxListHeaderData*)node->Data();
1458 column->SetItem( item );
1459 };
1460 };
1461
1462 void wxListMainWindow::SetColumnWidth( int col, int width )
1463 {
1464 m_dirty = TRUE;
1465 wxNode *node = m_columns.Nth( col );
1466 if (node)
1467 {
1468 wxListHeaderData *column = (wxListHeaderData*)node->Data();
1469 column->SetWidth( width );
1470 };
1471 };
1472
1473 void wxListMainWindow::GetColumn( int col, wxListItem &item )
1474 {
1475 wxNode *node = m_columns.Nth( col );
1476 if (node)
1477 {
1478 wxListHeaderData *column = (wxListHeaderData*)node->Data();
1479 column->GetItem( item );
1480 }
1481 else
1482 {
1483 item.m_format = 0;
1484 item.m_width = 0;
1485 item.m_text = "";
1486 item.m_image = 0;
1487 item.m_data = 0;
1488 };
1489 };
1490
1491 int wxListMainWindow::GetColumnWidth( int col )
1492 {
1493 wxNode *node = m_columns.Nth( col );
1494 if (node)
1495 {
1496 wxListHeaderData *column = (wxListHeaderData*)node->Data();
1497 return column->GetWidth();
1498 }
1499 else
1500 return 0;
1501 };
1502
1503 int wxListMainWindow::GetColumnCount( void )
1504 {
1505 return m_columns.Number();
1506 };
1507
1508 int wxListMainWindow::GetCountPerPage( void )
1509 {
1510 return m_visibleLines;
1511 };
1512
1513 void wxListMainWindow::SetItem( wxListItem &item )
1514 {
1515 m_dirty = TRUE;
1516 wxNode *node = m_lines.Nth( item.m_itemId );
1517 if (node)
1518 {
1519 wxListLineData *line = (wxListLineData*)node->Data();
1520 if (m_mode & wxLC_REPORT) item.m_width = GetColumnWidth( item.m_col )-3;
1521 line->SetItem( item.m_col, item );
1522 };
1523 };
1524
1525 void wxListMainWindow::SetItemState( long item, long state, long stateMask )
1526 {
1527 // m_dirty = TRUE; no recalcs needed
1528 wxListLineData *oldCurrent = m_current;
1529 if (stateMask & wxLIST_STATE_FOCUSED)
1530 {
1531 wxNode *node = m_lines.Nth( item );
1532 if (node)
1533 {
1534 wxListLineData *line = (wxListLineData*)node->Data();
1535 UnfocusLine( m_current );
1536 m_current = line;
1537 FocusLine( m_current );
1538 RefreshLine( m_current );
1539 RefreshLine( oldCurrent );
1540 };
1541 };
1542 if (stateMask & wxLIST_STATE_SELECTED)
1543 {
1544 wxNode *node = m_lines.Nth( item );
1545 if (node)
1546 {
1547 wxListLineData *line = (wxListLineData*)node->Data();
1548 bool on = state & wxLIST_STATE_SELECTED;
1549 line->Hilight( on );
1550 RefreshLine( m_current );
1551 RefreshLine( oldCurrent );
1552 };
1553 };
1554 };
1555
1556 int wxListMainWindow::GetItemState( long item, long stateMask )
1557 {
1558 int ret = wxLIST_STATE_DONTCARE;
1559 if (stateMask & wxLIST_STATE_FOCUSED)
1560 {
1561 wxNode *node = m_lines.Nth( item );
1562 if (node)
1563 {
1564 wxListLineData *line = (wxListLineData*)node->Data();
1565 if (line == m_current) ret |= wxLIST_STATE_FOCUSED;
1566 };
1567 };
1568 if (stateMask & wxLIST_STATE_SELECTED)
1569 {
1570 wxNode *node = m_lines.Nth( item );
1571 if (node)
1572 {
1573 wxListLineData *line = (wxListLineData*)node->Data();
1574 if (line->IsHilighted()) ret |= wxLIST_STATE_FOCUSED;
1575 };
1576 };
1577 return ret;
1578 };
1579
1580 void wxListMainWindow::GetItem( wxListItem &item )
1581 {
1582 wxNode *node = m_lines.Nth( item.m_itemId );
1583 if (node)
1584 {
1585 wxListLineData *line = (wxListLineData*)node->Data();
1586 line->GetItem( item.m_col, item );
1587 }
1588 else
1589 {
1590 item.m_mask = 0;
1591 item.m_text = "";
1592 item.m_image = 0;
1593 item.m_data = 0;
1594 };
1595 };
1596
1597 int wxListMainWindow::GetItemCount( void )
1598 {
1599 return m_lines.Number();
1600 };
1601
1602 void wxListMainWindow::GetItemRect( long index, wxRectangle &rect )
1603 {
1604 wxNode *node = m_lines.Nth( index );
1605 if (node)
1606 {
1607 wxListLineData *line = (wxListLineData*)node->Data();
1608 line->GetRect( rect );
1609 }
1610 else
1611 {
1612 rect.x = 0;
1613 rect.y = 0;
1614 rect.width = 0;
1615 rect.height = 0;
1616 };
1617 };
1618
1619 bool wxListMainWindow::GetItemPosition(long item, wxPoint& pos)
1620 {
1621 wxNode *node = m_lines.Nth( item );
1622 if (node)
1623 {
1624 wxRectangle rect;
1625 wxListLineData *line = (wxListLineData*)node->Data();
1626 line->GetRect( rect );
1627 pos.x = rect.x;
1628 pos.y = rect.y;
1629 }
1630 else
1631 {
1632 pos.x = 0;
1633 pos.y = 0;
1634 };
1635 return TRUE;
1636 };
1637
1638 int wxListMainWindow::GetSelectedItemCount( void )
1639 {
1640 int ret = 0;
1641 wxNode *node = m_lines.First();
1642 while (node)
1643 {
1644 wxListLineData *line = (wxListLineData*)node->Data();
1645 if (line->IsHilighted()) ret++;
1646 node = node->Next();
1647 };
1648 return 0;
1649 };
1650
1651 void wxListMainWindow::SetMode( long mode )
1652 {
1653 m_dirty = TRUE;
1654 m_mode = mode;
1655
1656 DeleteEverything();
1657
1658 if (m_mode & wxLC_REPORT)
1659 {
1660 m_xScroll = 0;
1661 m_yScroll = 15;
1662 }
1663 else
1664 {
1665 m_xScroll = 15;
1666 m_yScroll = 0;
1667 };
1668 };
1669
1670 long wxListMainWindow::GetMode( void ) const
1671 {
1672 return m_mode;
1673 };
1674
1675 void wxListMainWindow::CalculatePositions( void )
1676 {
1677 wxPaintDC dc( this );
1678 dc.SetFont( wxSystemSettings::GetSystemFont( wxSYS_SYSTEM_FONT ) );
1679
1680 int iconSpacing = 0;
1681 if (m_mode & wxLC_ICON) iconSpacing = m_normal_spacing;
1682 if (m_mode & wxLC_SMALL_ICON) iconSpacing = m_small_spacing;
1683 wxNode *node = m_lines.First();
1684 while (node)
1685 {
1686 wxListLineData *line = (wxListLineData*)node->Data();
1687 line->CalculateSize( &dc, iconSpacing );
1688 node = node->Next();
1689 };
1690
1691 int lineWidth = 0;
1692 int lineHeight = 0;
1693 int lineSpacing = 0;
1694
1695 node = m_lines.First();
1696 if (node)
1697 {
1698 wxListLineData *line = (wxListLineData*)node->Data();
1699 int dummy = 0;
1700 line->GetSize( dummy, lineSpacing );
1701 lineSpacing += 6;
1702 }
1703 else
1704 {
1705 // just in case
1706 lineSpacing = 6 + (int)dc.GetCharHeight();
1707 };
1708
1709 int clientWidth = 0;
1710 int clientHeight = 0;
1711
1712 if (m_mode & wxLC_REPORT)
1713 {
1714 int x = 5;
1715 int y = 6;
1716 int entireHeight = m_lines.Number() * lineSpacing + 10;
1717 SetScrollbars( m_xScroll, m_yScroll, 0, (entireHeight+10) / m_yScroll, 0, 0, TRUE );
1718 GetClientSize( &clientWidth, &clientHeight );
1719 node = m_lines.First();
1720 while (node)
1721 {
1722 wxListLineData *line = (wxListLineData*)node->Data();
1723 line->SetPosition( &dc, x, y, clientWidth );
1724 int col_x = 3;
1725 for (int i = 0; i < GetColumnCount(); i++)
1726 {
1727 line->SetColumnPosition( i, col_x );
1728 col_x += GetColumnWidth( i );
1729 };
1730 y += lineSpacing;
1731 node = node->Next();
1732 };
1733 }
1734 else
1735 {
1736 // At first, we try without any scrollbar
1737 GetSize( &clientWidth, &clientHeight );
1738
1739 int entireWidth = 0;
1740
1741 for (int tries = 0; tries < 2; tries++)
1742 {
1743 entireWidth = 0;
1744 int x = 5;
1745 int y = 6;
1746 int maxWidth = 0;
1747 node = m_lines.First();
1748 while (node)
1749 {
1750 wxListLineData *line = (wxListLineData*)node->Data();
1751 line->SetPosition( &dc, x, y, clientWidth );
1752 line->GetSize( lineWidth, lineHeight );
1753 if (lineWidth > maxWidth) maxWidth = lineWidth;
1754 y += lineSpacing;
1755 if (y+lineHeight > clientHeight-4)
1756 {
1757 y = 6;
1758 x += maxWidth+13;
1759 entireWidth += maxWidth+13;
1760 maxWidth = 0;
1761 };
1762 node = node->Next();
1763 if (!node) entireWidth += maxWidth;
1764 if ((tries == 0) && (entireWidth > clientWidth))
1765 {
1766 clientHeight -= 14; // scrollbar height
1767 break;
1768 };
1769 if (!node) tries = 1;
1770 };
1771 };
1772 SetScrollbars( m_xScroll, m_yScroll, (entireWidth+15) / m_xScroll, 0, 0, 0, TRUE );
1773 };
1774 m_visibleLines = (clientHeight-4) / (lineSpacing);
1775 };
1776
1777 void wxListMainWindow::RealizeChanges( void )
1778 {
1779 if (!m_current)
1780 {
1781 wxNode *node = m_lines.First();
1782 if (node) m_current = (wxListLineData*)node->Data();
1783 };
1784 if (m_current)
1785 {
1786 FocusLine( m_current );
1787 if (m_mode & wxLC_SINGLE_SEL) m_current->Hilight( TRUE );
1788 };
1789 };
1790
1791 long wxListMainWindow::GetNextItem( long item, int WXUNUSED(geometry), int state )
1792 {
1793 long ret = 0;
1794 if (item > 0) ret = item;
1795 wxNode *node = m_lines.Nth( ret );
1796 while (node)
1797 {
1798 wxListLineData *line = (wxListLineData*)node->Data();
1799 if ((state & wxLIST_STATE_FOCUSED) && (line == m_current)) return ret;
1800 if ((state & wxLIST_STATE_SELECTED) && (line->IsHilighted())) return ret;
1801 if (!state) return ret;
1802 ret++;
1803 node = node->Next();
1804 };
1805 return -1;
1806 };
1807
1808 void wxListMainWindow::DeleteItem( long index )
1809 {
1810 m_dirty = TRUE;
1811 wxNode *node = m_lines.Nth( index );
1812 if (node)
1813 {
1814 wxListLineData *line = (wxListLineData*)node->Data();
1815 if (m_current == line) m_current = NULL;
1816 DeleteLine( line );
1817 m_lines.DeleteNode( node );
1818 };
1819 };
1820
1821 void wxListMainWindow::DeleteColumn( int col )
1822 {
1823 m_dirty = TRUE;
1824 wxNode *node = m_columns.Nth( col );
1825 if (node) m_columns.DeleteNode( node );
1826 };
1827
1828 void wxListMainWindow::DeleteAllItems( void )
1829 {
1830 m_dirty = TRUE;
1831 wxNode *node = m_lines.First();
1832 while (node)
1833 {
1834 wxListLineData *line = (wxListLineData*)node->Data();
1835 DeleteLine( line );
1836 node = node->Next();
1837 };
1838 m_lines.Clear();
1839 m_current = NULL;
1840 };
1841
1842 void wxListMainWindow::DeleteEverything( void )
1843 {
1844 m_dirty = TRUE;
1845 wxNode *node = m_lines.First();
1846 while (node)
1847 {
1848 wxListLineData *line = (wxListLineData*)node->Data();
1849 DeleteLine( line );
1850 node = node->Next();
1851 };
1852 m_lines.Clear();
1853 m_current = NULL;
1854 m_columns.Clear();
1855 };
1856
1857 void wxListMainWindow::EnsureVisible( long index )
1858 {
1859 wxListLineData *oldCurrent = m_current;
1860 m_current = NULL;
1861 int i = index;
1862 wxNode *node = m_lines.Nth( i );
1863 if (node) m_current = (wxListLineData*)node->Data();
1864 if (m_current) MoveToFocus();
1865 m_current = oldCurrent;
1866 };
1867
1868 long wxListMainWindow::FindItem(long start, const wxString& str, bool WXUNUSED(partial) )
1869 {
1870 long pos = start;
1871 wxString tmp = str;
1872 if (pos < 0) pos = 0;
1873 wxNode *node = m_lines.Nth( pos );
1874 while (node)
1875 {
1876 wxListLineData *line = (wxListLineData*)node->Data();
1877 wxString s = "";
1878 line->GetText( 0, s );
1879 if (s == tmp) return pos;
1880 node = node->Next();
1881 pos++;
1882 };
1883 return -1;
1884 };
1885
1886 long wxListMainWindow::FindItem(long start, long data)
1887 {
1888 long pos = start;
1889 if (pos < 0) pos = 0;
1890 wxNode *node = m_lines.Nth( pos );
1891 while (node)
1892 {
1893 wxListLineData *line = (wxListLineData*)node->Data();
1894 wxListItem item;
1895 line->GetItem( 0, item );
1896 if (item.m_data == data) return pos;
1897 node = node->Next();
1898 pos++;
1899 };
1900 return -1;
1901 };
1902
1903 long wxListMainWindow::HitTest( int x, int y, int &flags )
1904 {
1905 wxNode *node = m_lines.First();
1906 int count = 0;
1907 while (node)
1908 {
1909 wxListLineData *line = (wxListLineData*)node->Data();
1910 long ret = line->IsHit( x, y );
1911 if (ret & flags)
1912 {
1913 flags = ret;
1914 return count;
1915 };
1916 node = node->Next();
1917 count++;
1918 };
1919 return -1;
1920 };
1921
1922 void wxListMainWindow::InsertItem( wxListItem &item )
1923 {
1924 m_dirty = TRUE;
1925 int mode = 0;
1926 if (m_mode & wxLC_REPORT) mode = wxLC_REPORT;
1927 else if (m_mode & wxLC_LIST) mode = wxLC_LIST;
1928 else if (m_mode & wxLC_ICON) mode = wxLC_ICON;
1929 else if (m_mode & wxLC_SMALL_ICON) mode = wxLC_ICON; // no typo
1930 wxListLineData *line = new wxListLineData( this, mode, m_hilightBrush );
1931 if (m_mode & wxLC_REPORT)
1932 {
1933 line->InitItems( GetColumnCount() );
1934 item.m_width = GetColumnWidth( 0 )-3;
1935 }
1936 else
1937 line->InitItems( 1 );
1938 line->SetItem( 0, item );
1939 wxNode *node = m_lines.Nth( item.m_itemId );
1940 if (node)
1941 m_lines.Insert( node, line );
1942 else
1943 m_lines.Append( line );
1944 };
1945
1946 void wxListMainWindow::InsertColumn( long col, wxListItem &item )
1947 {
1948 m_dirty = TRUE;
1949 if (m_mode & wxLC_REPORT)
1950 {
1951 if (item.m_width == wxLIST_AUTOSIZE_USEHEADER) item.m_width = GetTextLength( item.m_text );
1952 wxListHeaderData *column = new wxListHeaderData( item );
1953 wxNode *node = m_columns.Nth( col );
1954 if (node)
1955 m_columns.Insert( node, column );
1956 else
1957 m_columns.Append( column );
1958 };
1959 };
1960
1961 wxListCtrlCompare list_ctrl_compare_func_2;
1962 long list_ctrl_compare_data;
1963
1964 int list_ctrl_compare_func_1( const void *arg1, const void *arg2 )
1965 {
1966 wxListLineData *line1 = *((wxListLineData**)arg1);
1967 wxListLineData *line2 = *((wxListLineData**)arg2);
1968 wxListItem item;
1969 line1->GetItem( 0, item );
1970 long data1 = item.m_data;
1971 line2->GetItem( 0, item );
1972 long data2 = item.m_data;
1973 return list_ctrl_compare_func_2( data1, data2, list_ctrl_compare_data );
1974 };
1975
1976 void wxListMainWindow::SortItems( wxListCtrlCompare fn, long data )
1977 {
1978 list_ctrl_compare_func_2 = fn;
1979 list_ctrl_compare_data = data;
1980 m_lines.Sort( list_ctrl_compare_func_1 );
1981 };
1982
1983 bool wxListMainWindow::OnListNotify( wxListEvent &event )
1984 {
1985 if (m_parent) m_parent->ProcessEvent( event );
1986 return FALSE;
1987 };
1988
1989 // -------------------------------------------------------------------------------------
1990 // wxListItem
1991 // -------------------------------------------------------------------------------------
1992
1993 IMPLEMENT_DYNAMIC_CLASS(wxListItem, wxObject)
1994
1995 wxListItem::wxListItem(void)
1996 {
1997 m_mask = 0;
1998 m_itemId = 0;
1999 m_col = 0;
2000 m_state = 0;
2001 m_stateMask = 0;
2002 m_image = 0;
2003 m_data = 0;
2004 m_format = wxLIST_FORMAT_CENTRE;
2005 m_width = 0;
2006 m_colour = wxBLACK;
2007 }
2008
2009 // -------------------------------------------------------------------------------------
2010 // wxListEvent
2011 // -------------------------------------------------------------------------------------
2012
2013 IMPLEMENT_DYNAMIC_CLASS(wxListEvent, wxCommandEvent)
2014
2015 wxListEvent::wxListEvent( wxEventType commandType, int id ):
2016 wxCommandEvent( commandType, id )
2017 {
2018 m_code = 0;
2019 m_itemIndex = 0;
2020 m_col = 0;
2021 m_cancelled = FALSE;
2022 };
2023
2024 // -------------------------------------------------------------------------------------
2025 // wxListCtrl
2026 // -------------------------------------------------------------------------------------
2027
2028 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl, wxControl)
2029
2030 BEGIN_EVENT_TABLE(wxListCtrl,wxControl)
2031 EVT_SIZE (wxListCtrl::OnSize)
2032 EVT_IDLE (wxListCtrl::OnIdle)
2033 END_EVENT_TABLE()
2034
2035 wxListCtrl::wxListCtrl(void)
2036 {
2037 m_imageListNormal = NULL;
2038 m_imageListSmall = NULL;
2039 m_imageListState = NULL;
2040 }
2041
2042 wxListCtrl::wxListCtrl( wxWindow *parent, wxWindowID id,
2043 const wxPoint &pos, const wxSize &size,
2044 long style, const wxString &name )
2045
2046 {
2047 Create( parent, id, pos, size, style, name );
2048 };
2049
2050 wxListCtrl::~wxListCtrl(void)
2051 {
2052 }
2053
2054 bool wxListCtrl::Create( wxWindow *parent, wxWindowID id,
2055 const wxPoint &pos, const wxSize &size,
2056 long style, const wxString &name )
2057 {
2058 m_imageListNormal = NULL;
2059 m_imageListSmall = NULL;
2060 m_imageListState = NULL;
2061
2062 long s = style;
2063
2064 if ((s & wxLC_REPORT == 0) &&
2065 (s & wxLC_LIST == 0) &&
2066 (s & wxLC_ICON == 0))
2067 s = s | wxLC_LIST;
2068
2069 bool ret = wxControl::Create( parent, id, pos, size, s, name );
2070
2071 m_mainWin = new wxListMainWindow( this, -1, wxPoint(0,0), size, s );
2072
2073 if (GetWindowStyleFlag() & wxLC_REPORT)
2074 m_headerWin = new wxListHeaderWindow( this, -1, m_mainWin, wxPoint(0,0), wxSize(size.x,23) );
2075 else
2076 m_headerWin = NULL;
2077
2078 return ret;
2079 };
2080
2081 void wxListCtrl::OnSize( wxSizeEvent &WXUNUSED(event) )
2082 {
2083 // handled in OnIdle
2084
2085 if (m_mainWin) m_mainWin->m_dirty = TRUE;
2086 };
2087
2088 void wxListCtrl::SetSingleStyle( long style, bool add )
2089 {
2090 long flag = GetWindowStyleFlag();
2091
2092 if (add)
2093 {
2094 if (style & wxLC_MASK_TYPE) flag = flag & ~wxLC_MASK_TYPE;
2095 if (style & wxLC_MASK_ALIGN) flag = flag & ~wxLC_MASK_ALIGN;
2096 if (style & wxLC_MASK_SORT) flag = flag & ~wxLC_MASK_SORT;
2097 };
2098
2099 if (add)
2100 {
2101 flag |= style;
2102 }
2103 else
2104 {
2105 if (flag & style) flag -= style;
2106 };
2107
2108 SetWindowStyleFlag( flag );
2109 };
2110
2111 void wxListCtrl::SetWindowStyleFlag( long flag )
2112 {
2113 m_mainWin->DeleteEverything();
2114
2115 int width = 0;
2116 int height = 0;
2117 GetClientSize( &width, &height );
2118
2119 m_mainWin->SetMode( flag );
2120
2121 if (flag & wxLC_REPORT)
2122 {
2123 if (!(GetWindowStyleFlag() & wxLC_REPORT))
2124 {
2125 // m_mainWin->SetSize( 0, 24, width, height-24 );
2126 if (!m_headerWin)
2127 {
2128 m_headerWin = new wxListHeaderWindow( this, -1, m_mainWin, wxPoint(0,0), wxSize(width,23) );
2129 }
2130 else
2131 {
2132 // m_headerWin->SetSize( 0, 0, width, 23 );
2133 m_headerWin->Show( TRUE );
2134 };
2135 };
2136 }
2137 else
2138 {
2139 if (GetWindowStyleFlag() & wxLC_REPORT)
2140 {
2141 // m_mainWin->SetSize( 0, 0, width, height );
2142 m_headerWin->Show( FALSE );
2143 };
2144 };
2145
2146 wxWindow::SetWindowStyleFlag( flag );
2147 };
2148
2149 void wxListCtrl::SetBackgroundColour(const wxColour& col)
2150 {
2151 // This is from Julian. You know.
2152 // Not in wxWin 1.xx ???
2153 wxWindow::SetBackgroundColour( (wxColour&)col );
2154 };
2155
2156 bool wxListCtrl::GetColumn(int col, wxListItem &item)
2157 {
2158 m_mainWin->GetColumn( col, item );
2159 return TRUE;
2160 };
2161
2162 bool wxListCtrl::SetColumn( int col, wxListItem& item )
2163 {
2164 m_mainWin->SetColumn( col, item );
2165 return TRUE;
2166 };
2167
2168 int wxListCtrl::GetColumnWidth( int col )
2169 {
2170 return m_mainWin->GetColumnWidth( col );
2171 };
2172
2173 bool wxListCtrl::SetColumnWidth( int col, int width )
2174 {
2175 m_mainWin->SetColumnWidth( col, width );
2176 return TRUE;
2177 };
2178
2179 int wxListCtrl::GetCountPerPage(void)
2180 {
2181 return m_mainWin->GetCountPerPage(); // different from Windows ?
2182 };
2183
2184 /*
2185 wxText& wxListCtrl::GetEditControl(void) const
2186 {
2187 };
2188 */
2189
2190 bool wxListCtrl::GetItem( wxListItem &info )
2191 {
2192 m_mainWin->GetItem( info );
2193 return TRUE;
2194 };
2195
2196 bool wxListCtrl::SetItem( wxListItem &info )
2197 {
2198 m_mainWin->SetItem( info );
2199 return TRUE;
2200 };
2201
2202 long wxListCtrl::SetItem( long index, int col, const wxString& label, int imageId )
2203 {
2204 wxListItem info;
2205 info.m_text = label;
2206 info.m_mask = wxLIST_MASK_TEXT;
2207 info.m_itemId = index;
2208 info.m_col = col;
2209 if ( imageId > -1 )
2210 {
2211 info.m_image = imageId;
2212 info.m_mask |= wxLIST_MASK_IMAGE;
2213 }
2214 ;
2215 m_mainWin->SetItem(info);
2216 return TRUE;
2217 };
2218
2219 int wxListCtrl::GetItemState( long item, long stateMask )
2220 {
2221 return m_mainWin->GetItemState( item, stateMask );
2222 };
2223
2224 bool wxListCtrl::SetItemState( long item, long state, long stateMask )
2225 {
2226 m_mainWin->SetItemState( item, state, stateMask );
2227 return TRUE;
2228 };
2229
2230 bool wxListCtrl::SetItemImage( long item, int image, int WXUNUSED(selImage) )
2231 {
2232 wxListItem info;
2233 info.m_image = image;
2234 info.m_mask = wxLIST_MASK_IMAGE;
2235 info.m_itemId = item;
2236 m_mainWin->SetItem( info );
2237 return TRUE;
2238 };
2239
2240 wxString wxListCtrl::GetItemText( long item )
2241 {
2242 wxListItem info;
2243 info.m_itemId = item;
2244 m_mainWin->GetItem( info );
2245 return info.m_text;
2246 };
2247
2248 void wxListCtrl::SetItemText( long item, const wxString &str )
2249 {
2250 wxListItem info;
2251 info.m_mask = wxLIST_MASK_TEXT;
2252 info.m_itemId = item;
2253 info.m_text = str;
2254 m_mainWin->SetItem( info );
2255 };
2256
2257 long wxListCtrl::GetItemData( long item )
2258 {
2259 wxListItem info;
2260 info.m_itemId = item;
2261 m_mainWin->GetItem( info );
2262 return info.m_data;
2263 };
2264
2265 bool wxListCtrl::SetItemData( long item, long data )
2266 {
2267 wxListItem info;
2268 info.m_mask = wxLIST_MASK_DATA;
2269 info.m_itemId = item;
2270 info.m_data = data;
2271 m_mainWin->SetItem( info );
2272 return TRUE;
2273 };
2274
2275 bool wxListCtrl::GetItemRect( long item, wxRectangle &rect, int WXUNUSED(code) )
2276 {
2277 m_mainWin->GetItemRect( item, rect );
2278 return TRUE;
2279 };
2280
2281 bool wxListCtrl::GetItemPosition( long item, wxPoint& pos )
2282 {
2283 m_mainWin->GetItemPosition( item, pos );
2284 return TRUE;
2285 };
2286
2287 bool wxListCtrl::SetItemPosition( long WXUNUSED(item), const wxPoint& WXUNUSED(pos) )
2288 {
2289 return 0;
2290 };
2291
2292 int wxListCtrl::GetItemCount(void)
2293 {
2294 return m_mainWin->GetItemCount();
2295 };
2296
2297 void wxListCtrl::SetItemSpacing( int spacing, bool isSmall )
2298 {
2299 m_mainWin->SetItemSpacing( spacing, isSmall );
2300 };
2301
2302 int wxListCtrl::GetItemSpacing( bool isSmall )
2303 {
2304 return m_mainWin->GetItemSpacing( isSmall );
2305 };
2306
2307 int wxListCtrl::GetSelectedItemCount(void)
2308 {
2309 return m_mainWin->GetSelectedItemCount();
2310 };
2311
2312 /*
2313 wxColour wxListCtrl::GetTextColour(void) const
2314 {
2315 };
2316
2317 void wxListCtrl::SetTextColour(const wxColour& WXUNUSED(col))
2318 {
2319 };
2320 */
2321
2322 long wxListCtrl::GetTopItem(void)
2323 {
2324 return 0;
2325 };
2326
2327 long wxListCtrl::GetNextItem( long item, int geom, int state )
2328 {
2329 return m_mainWin->GetNextItem( item, geom, state );
2330 };
2331
2332 wxImageList *wxListCtrl::GetImageList(int which)
2333 {
2334 if (which == wxIMAGE_LIST_NORMAL)
2335 {
2336 return m_imageListNormal;
2337 }
2338 else if (which == wxIMAGE_LIST_SMALL)
2339 {
2340 return m_imageListSmall;
2341 }
2342 else if (which == wxIMAGE_LIST_STATE)
2343 {
2344 return m_imageListState;
2345 };
2346 return NULL;
2347 };
2348
2349 void wxListCtrl::SetImageList( wxImageList *imageList, int which )
2350 {
2351 m_mainWin->SetImageList( imageList, which );
2352 };
2353
2354 bool wxListCtrl::Arrange( int WXUNUSED(flag) )
2355 {
2356 return 0;
2357 };
2358
2359 bool wxListCtrl::DeleteItem( long item )
2360 {
2361 m_mainWin->DeleteItem( item );
2362 return TRUE;
2363 };
2364
2365 bool wxListCtrl::DeleteAllItems(void)
2366 {
2367 m_mainWin->DeleteAllItems();
2368 return TRUE;
2369 };
2370
2371 bool wxListCtrl::DeleteColumn( int col )
2372 {
2373 m_mainWin->DeleteColumn( col );
2374 return TRUE;
2375 };
2376
2377 /*
2378 wxText& wxListCtrl::Edit( long WXUNUSED(item ) )
2379 {
2380 };
2381 */
2382
2383 bool wxListCtrl::EnsureVisible( long item )
2384 {
2385 m_mainWin->EnsureVisible( item );
2386 return TRUE;
2387 };
2388
2389 long wxListCtrl::FindItem( long start, const wxString& str, bool partial )
2390 {
2391 return m_mainWin->FindItem( start, str, partial );
2392 };
2393
2394 long wxListCtrl::FindItem( long start, long data )
2395 {
2396 return m_mainWin->FindItem( start, data );
2397 };
2398
2399 long wxListCtrl::FindItem( long WXUNUSED(start), const wxPoint& WXUNUSED(pt),
2400 int WXUNUSED(direction))
2401 {
2402 return 0;
2403 };
2404
2405 long wxListCtrl::HitTest( const wxPoint &point, int &flags )
2406 {
2407 return m_mainWin->HitTest( (int)point.x, (int)point.y, flags );
2408 };
2409
2410 long wxListCtrl::InsertItem( wxListItem& info )
2411 {
2412 m_mainWin->InsertItem( info );
2413 return 0;
2414 };
2415
2416 long wxListCtrl::InsertItem( long index, const wxString &label )
2417 {
2418 wxListItem info;
2419 info.m_text = label;
2420 info.m_mask = wxLIST_MASK_TEXT;
2421 info.m_itemId = index;
2422 return InsertItem( info );
2423 };
2424
2425 long wxListCtrl::InsertItem( long index, int imageIndex )
2426 {
2427 wxListItem info;
2428 info.m_mask = wxLIST_MASK_IMAGE;
2429 info.m_image = imageIndex;
2430 info.m_itemId = index;
2431 return InsertItem( info );
2432 };
2433
2434 long wxListCtrl::InsertItem( long index, const wxString &label, int imageIndex )
2435 {
2436 wxListItem info;
2437 info.m_text = label;
2438 info.m_image = imageIndex;
2439 info.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_IMAGE;
2440 info.m_itemId = index;
2441 return InsertItem( info );
2442 };
2443
2444 long wxListCtrl::InsertColumn( long col, wxListItem &item )
2445 {
2446 m_mainWin->InsertColumn( col, item );
2447 return 0;
2448 };
2449
2450 long wxListCtrl::InsertColumn( long col, const wxString &heading,
2451 int format, int width )
2452 {
2453 wxListItem item;
2454 item.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_FORMAT;
2455 item.m_text = heading;
2456 if (width >= -2)
2457 {
2458 item.m_mask |= wxLIST_MASK_WIDTH;
2459 item.m_width = width;
2460 }
2461 ;
2462 item.m_format = format;
2463
2464 return InsertColumn( col, item );
2465 };
2466
2467 bool wxListCtrl::ScrollList( int WXUNUSED(dx), int WXUNUSED(dy) )
2468 {
2469 return 0;
2470 };
2471
2472 // Sort items.
2473 // fn is a function which takes 3 long arguments: item1, item2, data.
2474 // item1 is the long data associated with a first item (NOT the index).
2475 // item2 is the long data associated with a second item (NOT the index).
2476 // data is the same value as passed to SortItems.
2477 // The return value is a negative number if the first item should precede the second
2478 // item, a positive number of the second item should precede the first,
2479 // or zero if the two items are equivalent.
2480 // data is arbitrary data to be passed to the sort function.
2481
2482 bool wxListCtrl::SortItems( wxListCtrlCompare fn, long data )
2483 {
2484 m_mainWin->SortItems( fn, data );
2485 return TRUE;
2486 };
2487
2488 void wxListCtrl::OnIdle( wxIdleEvent &WXUNUSED(event) )
2489 {
2490 if (!m_mainWin->m_dirty) return;
2491
2492 int cw = 0;
2493 int ch = 0;
2494 GetClientSize( &cw, &ch );
2495
2496 int x = 0;
2497 int y = 0;
2498 int w = 0;
2499 int h = 0;
2500
2501 if (GetWindowStyleFlag() & wxLC_REPORT)
2502 {
2503 m_headerWin->GetPosition( &x, &y );
2504 m_headerWin->GetSize( &w, &h );
2505 if ((x != 0) || (y != 0) || (w != cw) || (h != 23))
2506 m_headerWin->SetSize( 0, 0, cw, 23 );
2507
2508 m_mainWin->GetPosition( &x, &y );
2509 m_mainWin->GetSize( &w, &h );
2510 if ((x != 0) || (y != 24) || (w != cw) || (h != ch-24))
2511 m_mainWin->SetSize( 0, 24, cw, ch-24 );
2512 }
2513 else
2514 {
2515 m_mainWin->GetPosition( &x, &y );
2516 m_mainWin->GetSize( &w, &h );
2517 if ((x != 0) || (y != 24) || (w != cw) || (h != ch))
2518 m_mainWin->SetSize( 0, 0, cw, ch );
2519 };
2520
2521 m_mainWin->CalculatePositions();
2522 m_mainWin->RealizeChanges();
2523 m_mainWin->m_dirty = FALSE;
2524 m_mainWin->Refresh();
2525 };
2526
2527