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