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