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