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