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