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