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