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