]> git.saurik.com Git - wxWidgets.git/blame - src/generic/listctrl.cpp
Minor corrections to be able to compile with VC++ 1.5C and VC++ 4.1
[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
RR
877 xpos += m_owner->GetColumnWidth( j );
878 if ((abs(x-xpos) < 3) && (y < 22))
879 {
880 hit_border = TRUE;
881 m_column = j;
882 break;
883 }
884 m_minX = xpos;
0208334d 885 }
bd8289c1 886
63852e78 887 if (event.LeftDown() && hit_border)
c801d85f 888 {
cfb50f14 889 m_isDragging = TRUE;
63852e78
RR
890 m_currentX = x;
891 DrawCurrent();
892 CaptureMouse();
893 return;
c801d85f 894 }
63852e78
RR
895
896 if (event.Moving())
c801d85f 897 {
63852e78
RR
898 if (hit_border)
899 {
900 if (m_currentCursor == wxSTANDARD_CURSOR) SetCursor( * m_resizeCursor );
901 m_currentCursor = m_resizeCursor;
902 }
903 else
904 {
905 if (m_currentCursor != wxSTANDARD_CURSOR) SetCursor( * wxSTANDARD_CURSOR );
906 m_currentCursor = wxSTANDARD_CURSOR;
907 }
e1e955e1 908 }
e1e955e1 909}
c801d85f
KB
910
911void wxListHeaderWindow::OnSetFocus( wxFocusEvent &WXUNUSED(event) )
912{
63852e78 913 m_owner->SetFocus();
e1e955e1 914}
c801d85f
KB
915
916//-----------------------------------------------------------------------------
917// wxListRenameTimer (internal)
918//-----------------------------------------------------------------------------
919
bd8289c1
VZ
920wxListRenameTimer::wxListRenameTimer( wxListMainWindow *owner )
921{
63852e78 922 m_owner = owner;
e1e955e1 923}
c801d85f 924
bd8289c1
VZ
925void wxListRenameTimer::Notify()
926{
63852e78 927 m_owner->OnRenameTimer();
e1e955e1 928}
c801d85f 929
ee7ee469
RR
930//-----------------------------------------------------------------------------
931// wxListTextCtrl (internal)
932//-----------------------------------------------------------------------------
933
934IMPLEMENT_DYNAMIC_CLASS(wxListTextCtrl,wxTextCtrl);
bd8289c1 935
ee7ee469 936BEGIN_EVENT_TABLE(wxListTextCtrl,wxTextCtrl)
63852e78
RR
937 EVT_CHAR (wxListTextCtrl::OnChar)
938 EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus)
ee7ee469
RR
939END_EVENT_TABLE()
940
bd8289c1 941wxListTextCtrl::wxListTextCtrl( wxWindow *parent, const wxWindowID id,
ee7ee469
RR
942 bool *accept, wxString *res, wxListMainWindow *owner,
943 const wxString &value, const wxPoint &pos, const wxSize &size,
944 int style, const wxValidator& validator, const wxString &name ) :
945 wxTextCtrl( parent, id, value, pos, size, style, validator, name )
946{
63852e78
RR
947 m_res = res;
948 m_accept = accept;
949 m_owner = owner;
5f1ea0ee
RR
950 (*m_accept) = FALSE;
951 (*m_res) = "";
952 m_startValue = value;
ee7ee469
RR
953}
954
955void wxListTextCtrl::OnChar( wxKeyEvent &event )
956{
63852e78
RR
957 if (event.m_keyCode == WXK_RETURN)
958 {
959 (*m_accept) = TRUE;
960 (*m_res) = GetValue();
5f1ea0ee 961 m_owner->SetFocus();
63852e78
RR
962 return;
963 }
964 if (event.m_keyCode == WXK_ESCAPE)
965 {
966 (*m_accept) = FALSE;
967 (*m_res) = "";
5f1ea0ee 968 m_owner->SetFocus();
63852e78
RR
969 return;
970 }
971 event.Skip();
972}
973
974void wxListTextCtrl::OnKillFocus( wxFocusEvent &WXUNUSED(event) )
975{
5f1ea0ee
RR
976 if (wxPendingDelete.Member(this)) return;
977
978 wxPendingDelete.Append(this);
979
980 if ((*m_accept) && ((*m_res) != m_startValue))
981 m_owner->OnRenameAccept();
ee7ee469
RR
982}
983
c801d85f
KB
984//-----------------------------------------------------------------------------
985// wxListMainWindow
986//-----------------------------------------------------------------------------
987
988IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow,wxScrolledWindow);
bd8289c1 989
c801d85f
KB
990BEGIN_EVENT_TABLE(wxListMainWindow,wxScrolledWindow)
991 EVT_PAINT (wxListMainWindow::OnPaint)
992 EVT_SIZE (wxListMainWindow::OnSize)
993 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse)
994 EVT_CHAR (wxListMainWindow::OnChar)
3dfb93fd 995 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown)
c801d85f
KB
996 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus)
997 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus)
998END_EVENT_TABLE()
999
fd9811b1 1000wxListMainWindow::wxListMainWindow()
c801d85f 1001{
139adb6a
RR
1002 m_mode = 0;
1003 m_lines.DeleteContents( TRUE );
1004 m_columns.DeleteContents( TRUE );
1005 m_current = (wxListLineData *) NULL;
1006 m_visibleLines = 0;
1007 m_hilightBrush = (wxBrush *) NULL;
1008 m_xScroll = 0;
1009 m_yScroll = 0;
1010 m_dirty = TRUE;
1011 m_small_image_list = (wxImageList *) NULL;
1012 m_normal_image_list = (wxImageList *) NULL;
1013 m_small_spacing = 30;
1014 m_normal_spacing = 40;
1015 m_hasFocus = FALSE;
1016 m_usedKeys = TRUE;
1017 m_lastOnSame = FALSE;
1018 m_renameTimer = new wxListRenameTimer( this );
1019 m_isCreated = FALSE;
1020 m_dragCount = 0;
e1e955e1 1021}
c801d85f 1022
bd8289c1 1023wxListMainWindow::wxListMainWindow( wxWindow *parent, wxWindowID id,
c801d85f 1024 const wxPoint &pos, const wxSize &size,
debe6624 1025 long style, const wxString &name ) :
a367b9b3 1026 wxScrolledWindow( parent, id, pos, size, style|wxHSCROLL|wxVSCROLL, name )
c801d85f 1027{
139adb6a
RR
1028 m_mode = style;
1029 m_lines.DeleteContents( TRUE );
1030 m_columns.DeleteContents( TRUE );
1031 m_current = (wxListLineData *) NULL;
1032 m_dirty = TRUE;
1033 m_visibleLines = 0;
1034 m_hilightBrush = new wxBrush( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT), wxSOLID );
1035 m_small_image_list = (wxImageList *) NULL;
1036 m_normal_image_list = (wxImageList *) NULL;
1037 m_small_spacing = 30;
1038 m_normal_spacing = 40;
1039 m_hasFocus = FALSE;
1040 m_dragCount = 0;
1041 m_isCreated = FALSE;
1042 wxSize sz = size;
1043 sz.y = 25;
bd8289c1 1044
139adb6a
RR
1045 if (m_mode & wxLC_REPORT)
1046 {
1047 m_xScroll = 0;
1048 m_yScroll = 15;
1049 }
1050 else
1051 {
1052 m_xScroll = 15;
1053 m_yScroll = 0;
1054 }
1055 SetScrollbars( m_xScroll, m_yScroll, 0, 0, 0, 0 );
bd8289c1 1056
139adb6a
RR
1057 m_usedKeys = TRUE;
1058 m_lastOnSame = FALSE;
1059 m_renameTimer = new wxListRenameTimer( this );
1060 m_renameAccept = FALSE;
c801d85f 1061
139adb6a 1062 SetBackgroundColour( *wxWHITE );
e1e955e1 1063}
c801d85f 1064
fd9811b1 1065wxListMainWindow::~wxListMainWindow()
c801d85f 1066{
139adb6a
RR
1067 if (m_hilightBrush) delete m_hilightBrush;
1068
1069 delete m_renameTimer;
e1e955e1 1070}
c801d85f
KB
1071
1072void wxListMainWindow::RefreshLine( wxListLineData *line )
1073{
139adb6a
RR
1074 int x = 0;
1075 int y = 0;
1076 int w = 0;
1077 int h = 0;
1078 if (line)
1079 {
1080 wxClientDC dc(this);
1081 PrepareDC( dc );
1082 line->GetExtent( x, y, w, h );
0a240683 1083 wxRect rect(
139adb6a
RR
1084 dc.LogicalToDeviceX(x-3),
1085 dc.LogicalToDeviceY(y-3),
1086 dc.LogicalToDeviceXRel(w+6),
1087 dc.LogicalToDeviceXRel(h+6) );
1088 Refresh( TRUE, &rect );
1089 }
e1e955e1 1090}
c801d85f
KB
1091
1092void wxListMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
1093{
f60d0f94
JS
1094 // Note: a wxPaintDC must be constructed even if no drawing is
1095 // done (a Windows requirement).
1096 wxPaintDC dc( this );
1097 PrepareDC( dc );
1098
139adb6a
RR
1099 if (m_dirty) return;
1100
1101 if (m_lines.GetCount() == 0) return;
bd8289c1 1102
139adb6a 1103 dc.BeginDrawing();
c801d85f 1104
139adb6a
RR
1105 dc.SetFont( GetFont() );
1106
1107 if (m_mode & wxLC_REPORT)
1108 {
1109 int lineSpacing = 0;
1110 wxListLineData *line = (wxListLineData*)m_lines.First()->Data();
1111 int dummy = 0;
1112 line->GetSize( dummy, lineSpacing );
1113 lineSpacing += 1;
1114
1115 int y_s = m_yScroll*GetScrollPos( wxVERTICAL );
1116
1117 wxNode *node = m_lines.Nth( y_s / lineSpacing );
1118 for (int i = 0; i < m_visibleLines+2; i++)
1119 {
1120 if (!node) break;
1121
1122 line = (wxListLineData*)node->Data();
1123 line->Draw( &dc );
1124 node = node->Next();
1125 }
1126 }
1127 else
1128 {
1129 wxNode *node = m_lines.First();
1130 while (node)
1131 {
1132 wxListLineData *line = (wxListLineData*)node->Data();
1133 line->Draw( &dc );
1134 node = node->Next();
1135 }
1136 }
1137
1138 if (m_current) m_current->DrawRubberBand( &dc, m_hasFocus );
c801d85f 1139
139adb6a 1140 dc.EndDrawing();
e1e955e1 1141}
c801d85f 1142
debe6624 1143void wxListMainWindow::HilightAll( bool on )
c801d85f 1144{
139adb6a
RR
1145 wxNode *node = m_lines.First();
1146 while (node)
c801d85f 1147 {
139adb6a
RR
1148 wxListLineData *line = (wxListLineData *)node->Data();
1149 if (line->IsHilighted() != on)
1150 {
1151 line->Hilight( on );
1152 RefreshLine( line );
1153 }
1154 node = node->Next();
e1e955e1 1155 }
e1e955e1 1156}
c801d85f 1157
7798a18e 1158void wxListMainWindow::SendNotify( wxListLineData *line, wxEventType command )
c801d85f 1159{
139adb6a
RR
1160 wxListEvent le( command, GetParent()->GetId() );
1161 le.SetEventObject( GetParent() );
1162 le.m_itemIndex = GetIndexOfLine( line );
1163 line->GetItem( 0, le.m_item );
1164 GetParent()->GetEventHandler()->ProcessEvent( le );
e1e955e1 1165}
c801d85f
KB
1166
1167void wxListMainWindow::FocusLine( wxListLineData *WXUNUSED(line) )
1168{
1169// SendNotify( line, wxEVT_COMMAND_LIST_ITEM_FOCUSSED );
e1e955e1 1170}
c801d85f
KB
1171
1172void wxListMainWindow::UnfocusLine( wxListLineData *WXUNUSED(line) )
1173{
1174// SendNotify( line, wxEVT_COMMAND_LIST_ITEM_UNFOCUSSED );
e1e955e1 1175}
c801d85f
KB
1176
1177void wxListMainWindow::SelectLine( wxListLineData *line )
1178{
139adb6a 1179 SendNotify( line, wxEVT_COMMAND_LIST_ITEM_SELECTED );
e1e955e1 1180}
c801d85f
KB
1181
1182void wxListMainWindow::DeselectLine( wxListLineData *line )
1183{
139adb6a 1184 SendNotify( line, wxEVT_COMMAND_LIST_ITEM_DESELECTED );
e1e955e1 1185}
c801d85f
KB
1186
1187void wxListMainWindow::DeleteLine( wxListLineData *line )
1188{
139adb6a 1189 SendNotify( line, wxEVT_COMMAND_LIST_DELETE_ITEM );
e1e955e1 1190}
c801d85f 1191
e179bd65 1192/* *** */
ee7ee469 1193
5f1ea0ee 1194void wxListMainWindow::EditLabel( long item )
c801d85f 1195{
e179bd65 1196 wxNode *node = m_lines.Nth( item );
813c20a6 1197 wxCHECK_RET( node, _T("wrong index in wxListCtrl::Edit()") );
e179bd65
RR
1198
1199 m_currentEdit = (wxListLineData*) node->Data();
1200
fd9811b1 1201 wxListEvent le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT, GetParent()->GetId() );
139adb6a 1202 le.SetEventObject( GetParent() );
e179bd65
RR
1203 le.m_itemIndex = GetIndexOfLine( m_currentEdit );
1204 m_currentEdit->GetItem( 0, le.m_item );
139adb6a 1205 GetParent()->GetEventHandler()->ProcessEvent( le );
e179bd65 1206
86f975a8 1207 if (!le.IsAllowed())
5f1ea0ee 1208 return;
e179bd65 1209
dc6c62a9
RR
1210 // We have to call this here because the label in
1211 // question might just have been added and no screen
1212 // update taken place.
1213 if (m_dirty) wxYield();
1214
92976ab6 1215 wxString s;
e179bd65 1216 m_currentEdit->GetText( 0, s );
92976ab6
RR
1217 int x = 0;
1218 int y = 0;
1219 int w = 0;
1220 int h = 0;
e179bd65 1221 m_currentEdit->GetLabelExtent( x, y, w, h );
0b855868 1222
92976ab6
RR
1223 wxClientDC dc(this);
1224 PrepareDC( dc );
1225 x = dc.LogicalToDeviceX( x );
1226 y = dc.LogicalToDeviceY( y );
bd8289c1 1227
92976ab6
RR
1228 wxListTextCtrl *text = new wxListTextCtrl(
1229 this, -1, &m_renameAccept, &m_renameRes, this, s, wxPoint(x-4,y-4), wxSize(w+11,h+8) );
1230 text->SetFocus();
e1e955e1 1231}
c801d85f 1232
e179bd65
RR
1233void wxListMainWindow::OnRenameTimer()
1234{
24bd64ee 1235 wxCHECK_RET( m_current, _T("invalid m_current") );
e179bd65
RR
1236
1237 Edit( m_lines.IndexOf( m_current ) );
1238}
1239
c801d85f
KB
1240void wxListMainWindow::OnRenameAccept()
1241{
e179bd65
RR
1242 wxListEvent le( wxEVT_COMMAND_LIST_END_LABEL_EDIT, GetParent()->GetId() );
1243 le.SetEventObject( GetParent() );
1244 le.m_itemIndex = GetIndexOfLine( m_currentEdit );
1245 m_currentEdit->GetItem( 0, le.m_item );
1246 le.m_item.m_text = m_renameRes;
1247 GetParent()->GetEventHandler()->ProcessEvent( le );
1248
1249 if (!le.IsAllowed()) return;
1250
5f1ea0ee
RR
1251 wxListItem info;
1252 info.m_mask = wxLIST_MASK_TEXT;
1253 info.m_itemId = le.m_itemIndex;
1254 info.m_text = m_renameRes;
0b855868 1255 info.m_colour = le.m_item.m_colour;
5f1ea0ee 1256 SetItem( info );
e1e955e1 1257}
c801d85f
KB
1258
1259void wxListMainWindow::OnMouse( wxMouseEvent &event )
1260{
92976ab6 1261 if (GetParent()->GetEventHandler()->ProcessEvent( event)) return;
e3e65dac 1262
92976ab6
RR
1263 if (!m_current) return;
1264 if (m_dirty) return;
0b855868 1265 if ( !(event.Dragging() || event.ButtonDown() || event.LeftUp() || event.ButtonDClick()) ) return;
c801d85f 1266
92976ab6
RR
1267 wxClientDC dc(this);
1268 PrepareDC(dc);
1269 long x = dc.DeviceToLogicalX( (long)event.GetX() );
1270 long y = dc.DeviceToLogicalY( (long)event.GetY() );
1271
51cc4dad 1272 /* Did we actually hit an item ? */
92976ab6
RR
1273 long hitResult = 0;
1274 wxNode *node = m_lines.First();
1275 wxListLineData *line = (wxListLineData *) NULL;
1276 while (node)
1277 {
1278 line = (wxListLineData*)node->Data();
1279 hitResult = line->IsHit( x, y );
1280 if (hitResult) break;
1281 line = (wxListLineData *) NULL;
1282 node = node->Next();
1283 }
bd8289c1 1284
fd9811b1 1285 if (event.Dragging())
92976ab6 1286 {
fd9811b1
RR
1287 if (m_dragCount == 0)
1288 m_dragStart = wxPoint(x,y);
1289
1290 m_dragCount++;
1291
1292 if (m_dragCount != 3) return;
92976ab6 1293
fd9811b1
RR
1294 int command = wxEVT_COMMAND_LIST_BEGIN_DRAG;
1295 if (event.RightIsDown()) command = wxEVT_COMMAND_LIST_BEGIN_RDRAG;
1296
1297 wxListEvent le( command, GetParent()->GetId() );
92976ab6 1298 le.SetEventObject( GetParent() );
fd9811b1 1299 le.m_pointDrag = m_dragStart;
92976ab6
RR
1300 GetParent()->GetEventHandler()->ProcessEvent( le );
1301
1302 return;
1303 }
fd9811b1
RR
1304 else
1305 {
1306 m_dragCount = 0;
1307 }
bd8289c1 1308
92976ab6 1309 if (!line) return;
bd8289c1 1310
92976ab6
RR
1311 if (event.ButtonDClick())
1312 {
1313 m_usedKeys = FALSE;
1314 m_lastOnSame = FALSE;
1315 m_renameTimer->Stop();
1316
435fe83e 1317 SendNotify( line, wxEVT_COMMAND_LIST_ITEM_ACTIVATED );
92976ab6
RR
1318
1319 return;
1320 }
bd8289c1 1321
92976ab6 1322 if (event.LeftUp() && m_lastOnSame)
c801d85f 1323 {
92976ab6
RR
1324 m_usedKeys = FALSE;
1325 if ((line == m_current) &&
1326 (hitResult == wxLIST_HITTEST_ONITEMLABEL) &&
1327 (m_mode & wxLC_EDIT_LABELS) )
1328 {
1329 m_renameTimer->Start( 100, TRUE );
1330 }
1331 m_lastOnSame = FALSE;
1332 return;
e1e955e1 1333 }
bd8289c1 1334
92976ab6 1335 if (event.RightDown())
b204641e 1336 {
92976ab6
RR
1337 SendNotify( line, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK );
1338 return;
b204641e 1339 }
92976ab6
RR
1340
1341 if (event.MiddleDown())
b204641e 1342 {
92976ab6
RR
1343 SendNotify( line, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK );
1344 return;
1345 }
1346
1347 if (event.LeftDown())
1348 {
1349 m_usedKeys = FALSE;
1350 wxListLineData *oldCurrent = m_current;
1351 if (m_mode & wxLC_SINGLE_SEL)
b204641e 1352 {
92976ab6
RR
1353 m_current = line;
1354 HilightAll( FALSE );
1355 m_current->ReverseHilight();
1356 RefreshLine( m_current );
e1e955e1 1357 }
92976ab6 1358 else
b204641e 1359 {
92976ab6
RR
1360 if (event.ShiftDown())
1361 {
1362 m_current = line;
1363 m_current->ReverseHilight();
1364 RefreshLine( m_current );
1365 }
1366 else if (event.ControlDown())
1367 {
1368 m_current = line;
1369
1370 int numOfCurrent = -1;
1371 node = m_lines.First();
1372 while (node)
1373 {
1374 wxListLineData *test_line = (wxListLineData*)node->Data();
1375 numOfCurrent++;
1376 if (test_line == oldCurrent) break;
1377 node = node->Next();
1378 }
1379
1380 int numOfLine = -1;
1381 node = m_lines.First();
1382 while (node)
1383 {
1384 wxListLineData *test_line = (wxListLineData*)node->Data();
1385 numOfLine++;
1386 if (test_line == line) break;
1387 node = node->Next();
1388 }
1389
1390 if (numOfLine < numOfCurrent)
1391 {
1392 int i = numOfLine;
1393 numOfLine = numOfCurrent;
1394 numOfCurrent = i;
1395 }
1396
1397 wxNode *node = m_lines.Nth( numOfCurrent );
1398 for (int i = 0; i <= numOfLine-numOfCurrent; i++)
1399 {
1400 wxListLineData *test_line= (wxListLineData*)node->Data();
1401 test_line->Hilight(TRUE);
1402 RefreshLine( test_line );
1403 node = node->Next();
1404 }
1405 }
1406 else
1407 {
1408 m_current = line;
1409 HilightAll( FALSE );
1410 m_current->ReverseHilight();
1411 RefreshLine( m_current );
1412 }
e1e955e1 1413 }
92976ab6
RR
1414 if (m_current != oldCurrent)
1415 {
1416 RefreshLine( oldCurrent );
1417 UnfocusLine( oldCurrent );
1418 FocusLine( m_current );
1419 }
1420 m_lastOnSame = (m_current == oldCurrent);
1421 return;
e1e955e1 1422 }
e1e955e1 1423}
c801d85f 1424
e179bd65 1425void wxListMainWindow::MoveToFocus()
c801d85f 1426{
92976ab6 1427 if (!m_current) return;
e487524e 1428
92976ab6
RR
1429 int x = 0;
1430 int y = 0;
1431 int w = 0;
1432 int h = 0;
1433 m_current->GetExtent( x, y, w, h );
139adb6a 1434
92976ab6
RR
1435 int w_p = 0;
1436 int h_p = 0;
1437 GetClientSize( &w_p, &h_p );
139adb6a 1438
92976ab6
RR
1439 if (m_mode & wxLC_REPORT)
1440 {
92976ab6
RR
1441 int y_s = m_yScroll*GetScrollPos( wxVERTICAL );
1442 if ((y > y_s) && (y+h < y_s+h_p)) return;
aab3e197
KB
1443 if (y-y_s < 5) { Scroll( -1, (y-5-h_p/2)/m_yScroll ); Refresh(); }
1444 if (y+h+5 > y_s+h_p) { Scroll( -1, (y+h-h_p/2+h+15)/m_yScroll); Refresh(); }
92976ab6
RR
1445 }
1446 else
1447 {
92976ab6
RR
1448 int x_s = m_xScroll*GetScrollPos( wxHORIZONTAL );
1449 if ((x > x_s) && (x+w < x_s+w_p)) return;
aab3e197
KB
1450 if (x-x_s < 5) { Scroll( (x-5)/m_xScroll, -1 ); Refresh(); }
1451 if (x+w-5 > x_s+w_p) { Scroll( (x+w-w_p+15)/m_xScroll, -1 ); Refresh(); }
92976ab6 1452 }
e1e955e1 1453}
c801d85f
KB
1454
1455void wxListMainWindow::OnArrowChar( wxListLineData *newCurrent, bool shiftDown )
1456{
92976ab6
RR
1457 if ((m_mode & wxLC_SINGLE_SEL) || (m_usedKeys == FALSE)) m_current->Hilight( FALSE );
1458 wxListLineData *oldCurrent = m_current;
1459 m_current = newCurrent;
1460 MoveToFocus();
1461 if (shiftDown || (m_mode & wxLC_SINGLE_SEL)) m_current->Hilight( TRUE );
1462 RefreshLine( m_current );
1463 RefreshLine( oldCurrent );
1464 FocusLine( m_current );
1465 UnfocusLine( oldCurrent );
e1e955e1 1466}
c801d85f 1467
3dfb93fd
RR
1468void wxListMainWindow::OnKeyDown( wxKeyEvent &event )
1469{
1470 wxWindow *parent = GetParent();
1471
1472 /* we propagate the key event up */
1473 wxKeyEvent ke( wxEVT_KEY_DOWN );
1474 ke.m_shiftDown = event.m_shiftDown;
1475 ke.m_controlDown = event.m_controlDown;
1476 ke.m_altDown = event.m_altDown;
1477 ke.m_metaDown = event.m_metaDown;
1478 ke.m_keyCode = event.m_keyCode;
1479 ke.m_x = event.m_x;
1480 ke.m_y = event.m_y;
1481 ke.SetEventObject( parent );
1482 if (parent->GetEventHandler()->ProcessEvent( ke )) return;
1483
1484 event.Skip();
1485}
1486
c801d85f
KB
1487void wxListMainWindow::OnChar( wxKeyEvent &event )
1488{
51cc4dad 1489 wxWindow *parent = GetParent();
435fe83e 1490
51cc4dad
RR
1491 /* we send a list_key event up */
1492 wxListEvent le( wxEVT_COMMAND_LIST_KEY_DOWN, GetParent()->GetId() );
1493 le.m_code = event.KeyCode();
1494 le.SetEventObject( parent );
1495 parent->GetEventHandler()->ProcessEvent( le );
1496
3dfb93fd
RR
1497 /* we propagate the char event up */
1498 wxKeyEvent ke( wxEVT_CHAR );
51cc4dad
RR
1499 ke.m_shiftDown = event.m_shiftDown;
1500 ke.m_controlDown = event.m_controlDown;
1501 ke.m_altDown = event.m_altDown;
1502 ke.m_metaDown = event.m_metaDown;
1503 ke.m_keyCode = event.m_keyCode;
1504 ke.m_x = event.m_x;
1505 ke.m_y = event.m_y;
1506 ke.SetEventObject( parent );
1507 if (parent->GetEventHandler()->ProcessEvent( ke )) return;
1508
012a03e0
RR
1509 if (event.KeyCode() == WXK_TAB)
1510 {
1511 wxNavigationKeyEvent nevent;
1512 nevent.SetDirection( !event.ShiftDown() );
1513 nevent.SetCurrentFocus( m_parent );
1514 if (m_parent->GetEventHandler()->ProcessEvent( nevent )) return;
1515 }
1516
51cc4dad
RR
1517 /* no item -> nothing to do */
1518 if (!m_current)
c801d85f 1519 {
51cc4dad
RR
1520 event.Skip();
1521 return;
e1e955e1 1522 }
51cc4dad
RR
1523
1524 switch (event.KeyCode())
c801d85f 1525 {
51cc4dad
RR
1526 case WXK_UP:
1527 {
1528 wxNode *node = m_lines.Member( m_current )->Previous();
1529 if (node) OnArrowChar( (wxListLineData*)node->Data(), event.ShiftDown() );
1530 break;
1531 }
1532 case WXK_DOWN:
1533 {
1534 wxNode *node = m_lines.Member( m_current )->Next();
1535 if (node) OnArrowChar( (wxListLineData*)node->Data(), event.ShiftDown() );
1536 break;
1537 }
1538 case WXK_END:
1539 {
1540 wxNode *node = m_lines.Last();
1541 OnArrowChar( (wxListLineData*)node->Data(), event.ShiftDown() );
1542 break;
1543 }
1544 case WXK_HOME:
1545 {
1546 wxNode *node = m_lines.First();
1547 OnArrowChar( (wxListLineData*)node->Data(), event.ShiftDown() );
1548 break;
1549 }
1550 case WXK_PRIOR:
1551 {
1552 int steps = 0;
1553 if (m_mode & wxLC_REPORT)
1554 {
1555 steps = m_visibleLines-1;
1556 }
1557 else
1558 {
1559 int pos = 0;
1560 wxNode *node = m_lines.First();
1561 for (;;) { if (m_current == (wxListLineData*)node->Data()) break; pos++; node = node->Next(); }
1562 steps = pos % m_visibleLines;
1563 }
1564 wxNode *node = m_lines.Member( m_current );
1565 for (int i = 0; i < steps; i++) if (node->Previous()) node = node->Previous();
1566 if (node) OnArrowChar( (wxListLineData*)node->Data(), event.ShiftDown() );
1567 break;
1568 }
1569 case WXK_NEXT:
1570 {
1571 int steps = 0;
1572 if (m_mode & wxLC_REPORT)
1573 {
1574 steps = m_visibleLines-1;
1575 }
1576 else
1577 {
1578 int pos = 0; wxNode *node = m_lines.First();
1579 for (;;) { if (m_current == (wxListLineData*)node->Data()) break; pos++; node = node->Next(); }
1580 steps = m_visibleLines-(pos % m_visibleLines)-1;
1581 }
1582 wxNode *node = m_lines.Member( m_current );
1583 for (int i = 0; i < steps; i++) if (node->Next()) node = node->Next();
1584 if (node) OnArrowChar( (wxListLineData*)node->Data(), event.ShiftDown() );
1585 break;
1586 }
1587 case WXK_LEFT:
1588 {
1589 if (!(m_mode & wxLC_REPORT))
1590 {
1591 wxNode *node = m_lines.Member( m_current );
1592 for (int i = 0; i <m_visibleLines; i++) if (node->Previous()) node = node->Previous();
1593 if (node) OnArrowChar( (wxListLineData*)node->Data(), event.ShiftDown() );
1594 }
1595 break;
1596 }
1597 case WXK_RIGHT:
1598 {
1599 if (!(m_mode & wxLC_REPORT))
1600 {
1601 wxNode *node = m_lines.Member( m_current );
1602 for (int i = 0; i <m_visibleLines; i++) if (node->Next()) node = node->Next();
1603 if (node) OnArrowChar( (wxListLineData*)node->Data(), event.ShiftDown() );
1604 }
1605 break;
1606 }
1607 case WXK_SPACE:
1608 {
1609 m_current->ReverseHilight();
1610 RefreshLine( m_current );
1611 break;
1612 }
1613 case WXK_INSERT:
1614 {
1615 if (!(m_mode & wxLC_SINGLE_SEL))
1616 {
1617 wxListLineData *oldCurrent = m_current;
1618 m_current->ReverseHilight();
1619 wxNode *node = m_lines.Member( m_current )->Next();
1620 if (node) m_current = (wxListLineData*)node->Data();
1621 MoveToFocus();
1622 RefreshLine( oldCurrent );
1623 RefreshLine( m_current );
1624 UnfocusLine( oldCurrent );
1625 FocusLine( m_current );
1626 }
1627 break;
1628 }
1629 case WXK_RETURN:
1630 case WXK_EXECUTE:
1631 {
1632 wxListEvent le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED, GetParent()->GetId() );
1633 le.SetEventObject( GetParent() );
1634 le.m_itemIndex = GetIndexOfLine( m_current );
1635 m_current->GetItem( 0, le.m_item );
1636 GetParent()->GetEventHandler()->ProcessEvent( le );
1637 break;
1638 }
1639 default:
1640 {
1641 event.Skip();
1642 return;
1643 }
e1e955e1 1644 }
51cc4dad 1645 m_usedKeys = TRUE;
e1e955e1 1646}
c801d85f 1647
cae5359f
RR
1648#ifdef __WXGTK__
1649extern wxWindow *g_focusWindow;
1650#endif
1651
c801d85f
KB
1652void wxListMainWindow::OnSetFocus( wxFocusEvent &WXUNUSED(event) )
1653{
63852e78
RR
1654 m_hasFocus = TRUE;
1655 RefreshLine( m_current );
bd8289c1 1656
63852e78 1657 if (!GetParent()) return;
cae5359f
RR
1658
1659#ifdef __WXGTK__
1660 g_focusWindow = GetParent();
1661#endif
bd8289c1 1662
63852e78
RR
1663 wxFocusEvent event( wxEVT_SET_FOCUS, GetParent()->GetId() );
1664 event.SetEventObject( GetParent() );
1665 GetParent()->GetEventHandler()->ProcessEvent( event );
e1e955e1 1666}
c801d85f
KB
1667
1668void wxListMainWindow::OnKillFocus( wxFocusEvent &WXUNUSED(event) )
1669{
63852e78
RR
1670 m_hasFocus = FALSE;
1671 RefreshLine( m_current );
e1e955e1 1672}
c801d85f
KB
1673
1674void wxListMainWindow::OnSize( wxSizeEvent &WXUNUSED(event) )
1675{
1676/*
1677 We don't even allow the wxScrolledWindow::AdjustScrollbars() call
63852e78 1678
c801d85f 1679*/
e1e955e1 1680}
c801d85f 1681
1e6d9499 1682void wxListMainWindow::DrawImage( int index, wxDC *dc, int x, int y )
c801d85f 1683{
63852e78
RR
1684 if ((m_mode & wxLC_ICON) && (m_normal_image_list))
1685 {
1686 m_normal_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT );
1687 return;
1688 }
1689 if ((m_mode & wxLC_SMALL_ICON) && (m_small_image_list))
1690 {
1691 m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT );
1692 }
0b855868
RR
1693 if ((m_mode & wxLC_LIST) && (m_small_image_list))
1694 {
1695 m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT );
1696 }
63852e78
RR
1697 if ((m_mode & wxLC_REPORT) && (m_small_image_list))
1698 {
1699 m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT );
1700 return;
1701 }
e1e955e1 1702}
c801d85f
KB
1703
1704void wxListMainWindow::GetImageSize( int index, int &width, int &height )
1705{
63852e78
RR
1706 if ((m_mode & wxLC_ICON) && (m_normal_image_list))
1707 {
1708 m_normal_image_list->GetSize( index, width, height );
1709 return;
1710 }
1711 if ((m_mode & wxLC_SMALL_ICON) && (m_small_image_list))
1712 {
1713 m_small_image_list->GetSize( index, width, height );
1714 return;
1715 }
0b855868
RR
1716 if ((m_mode & wxLC_LIST) && (m_small_image_list))
1717 {
1718 m_small_image_list->GetSize( index, width, height );
1719 return;
1720 }
63852e78
RR
1721 if ((m_mode & wxLC_REPORT) && (m_small_image_list))
1722 {
1723 m_small_image_list->GetSize( index, width, height );
1724 return;
1725 }
1726 width = 0;
1727 height = 0;
e1e955e1 1728}
c801d85f
KB
1729
1730int wxListMainWindow::GetTextLength( wxString &s )
1731{
1e6d9499 1732 wxClientDC dc( this );
139adb6a
RR
1733 long lw = 0;
1734 long lh = 0;
1735 dc.GetTextExtent( s, &lw, &lh );
1736 return lw + 6;
e1e955e1 1737}
c801d85f
KB
1738
1739int wxListMainWindow::GetIndexOfLine( const wxListLineData *line )
1740{
139adb6a
RR
1741 int i = 0;
1742 wxNode *node = m_lines.First();
1743 while (node)
1744 {
1745 if (line == (wxListLineData*)node->Data()) return i;
1746 i++;
1747 node = node->Next();
1748 }
1749 return -1;
e1e955e1 1750}
c801d85f 1751
debe6624 1752void wxListMainWindow::SetImageList( wxImageList *imageList, int which )
c801d85f 1753{
139adb6a
RR
1754 m_dirty = TRUE;
1755 if (which == wxIMAGE_LIST_NORMAL) m_normal_image_list = imageList;
1756 if (which == wxIMAGE_LIST_SMALL) m_small_image_list = imageList;
e1e955e1 1757}
c801d85f 1758
debe6624 1759void wxListMainWindow::SetItemSpacing( int spacing, bool isSmall )
c801d85f 1760{
139adb6a
RR
1761 m_dirty = TRUE;
1762 if (isSmall)
1763 {
1764 m_small_spacing = spacing;
1765 }
1766 else
1767 {
1768 m_normal_spacing = spacing;
1769 }
e1e955e1 1770}
c801d85f 1771
debe6624 1772int wxListMainWindow::GetItemSpacing( bool isSmall )
c801d85f 1773{
139adb6a 1774 if (isSmall) return m_small_spacing; else return m_normal_spacing;
e1e955e1 1775}
c801d85f 1776
debe6624 1777void wxListMainWindow::SetColumn( int col, wxListItem &item )
c801d85f 1778{
63852e78
RR
1779 m_dirty = TRUE;
1780 wxNode *node = m_columns.Nth( col );
1781 if (node)
1782 {
1783 if (item.m_width == wxLIST_AUTOSIZE_USEHEADER) item.m_width = GetTextLength( item.m_text )+7;
1784 wxListHeaderData *column = (wxListHeaderData*)node->Data();
1785 column->SetItem( item );
1786 }
1787 wxListCtrl *lc = (wxListCtrl*) GetParent();
1788 if (lc->m_headerWin) lc->m_headerWin->Refresh();
e1e955e1 1789}
c801d85f 1790
debe6624 1791void wxListMainWindow::SetColumnWidth( int col, int width )
c801d85f 1792{
63852e78 1793 if (!(m_mode & wxLC_REPORT)) return;
0208334d 1794
63852e78 1795 m_dirty = TRUE;
bd8289c1 1796
0180dad6
RR
1797 wxNode *node = (wxNode*) NULL;
1798
1799 if (width == wxLIST_AUTOSIZE_USEHEADER) width = 80;
1800 if (width == wxLIST_AUTOSIZE)
1801 {
1802 wxClientDC dc(this);
1803 dc.SetFont( GetFont() );
1804 int max = 10;
1805 node = m_lines.First();
1806 while (node)
1807 {
1808 wxListLineData *line = (wxListLineData*)node->Data();
1809 wxNode *n = line->m_items.Nth( col );
1810 if (n)
1811 {
1812 wxListItemData *item = (wxListItemData*)n->Data();
1813 int current = 0, ix = 0, iy = 0;
1814 long lx = 0, ly = 0;
1815 if (item->HasImage())
1816 {
1817 GetImageSize( item->GetImage(), ix, iy );
1818 current = ix + 5;
1819 }
1820 if (item->HasText())
1821 {
1822 wxString str;
1823 item->GetText( str );
1824 dc.GetTextExtent( str, &lx, &ly );
1825 current += lx;
1826 }
1827 if (current > max) max = current;
1828 }
1829 node = node->Next();
1830 }
1831 width = max+10;
1832 }
1833
1834 node = m_columns.Nth( col );
63852e78
RR
1835 if (node)
1836 {
1837 wxListHeaderData *column = (wxListHeaderData*)node->Data();
1838 column->SetWidth( width );
1839 }
bd8289c1 1840
63852e78
RR
1841 node = m_lines.First();
1842 while (node)
0208334d 1843 {
63852e78
RR
1844 wxListLineData *line = (wxListLineData*)node->Data();
1845 wxNode *n = line->m_items.Nth( col );
1846 if (n)
1847 {
1848 wxListItemData *item = (wxListItemData*)n->Data();
1849 item->SetSize( width, -1 );
1850 }
1851 node = node->Next();
0208334d 1852 }
bd8289c1 1853
63852e78
RR
1854 wxListCtrl *lc = (wxListCtrl*) GetParent();
1855 if (lc->m_headerWin) lc->m_headerWin->Refresh();
e1e955e1 1856}
c801d85f 1857
debe6624 1858void wxListMainWindow::GetColumn( int col, wxListItem &item )
c801d85f 1859{
63852e78
RR
1860 wxNode *node = m_columns.Nth( col );
1861 if (node)
1862 {
1863 wxListHeaderData *column = (wxListHeaderData*)node->Data();
1864 column->GetItem( item );
1865 }
1866 else
1867 {
1868 item.m_format = 0;
1869 item.m_width = 0;
1870 item.m_text = "";
1871 item.m_image = 0;
1872 item.m_data = 0;
1873 }
e1e955e1 1874}
c801d85f 1875
bd8289c1 1876int wxListMainWindow::GetColumnWidth( int col )
c801d85f 1877{
92976ab6
RR
1878 wxNode *node = m_columns.Nth( col );
1879 if (node)
1880 {
1881 wxListHeaderData *column = (wxListHeaderData*)node->Data();
1882 return column->GetWidth();
1883 }
1884 else
1885 {
1886 return 0;
1887 }
e1e955e1 1888}
c801d85f 1889
e179bd65 1890int wxListMainWindow::GetColumnCount()
c801d85f 1891{
92976ab6 1892 return m_columns.Number();
e1e955e1 1893}
c801d85f 1894
e179bd65 1895int wxListMainWindow::GetCountPerPage()
c801d85f 1896{
92976ab6 1897 return m_visibleLines;
e1e955e1 1898}
c801d85f
KB
1899
1900void wxListMainWindow::SetItem( wxListItem &item )
1901{
92976ab6
RR
1902 m_dirty = TRUE;
1903 wxNode *node = m_lines.Nth( item.m_itemId );
1904 if (node)
1905 {
1906 wxListLineData *line = (wxListLineData*)node->Data();
1907 if (m_mode & wxLC_REPORT) item.m_width = GetColumnWidth( item.m_col )-3;
1908 line->SetItem( item.m_col, item );
1909 }
e1e955e1 1910}
c801d85f 1911
debe6624 1912void wxListMainWindow::SetItemState( long item, long state, long stateMask )
c801d85f 1913{
92976ab6 1914 // m_dirty = TRUE; no recalcs needed
bd8289c1 1915
92976ab6 1916 wxListLineData *oldCurrent = m_current;
bd8289c1 1917
92976ab6 1918 if (stateMask & wxLIST_STATE_FOCUSED)
c801d85f 1919 {
92976ab6
RR
1920 wxNode *node = m_lines.Nth( item );
1921 if (node)
1922 {
1923 wxListLineData *line = (wxListLineData*)node->Data();
1924 UnfocusLine( m_current );
1925 m_current = line;
1926 FocusLine( m_current );
1927 RefreshLine( m_current );
00a39542 1928 if (oldCurrent) RefreshLine( oldCurrent );
92976ab6 1929 }
e1e955e1 1930 }
bd8289c1 1931
92976ab6 1932 if (stateMask & wxLIST_STATE_SELECTED)
c801d85f 1933 {
92976ab6
RR
1934 bool on = state & wxLIST_STATE_SELECTED;
1935 if (!on && (m_mode & wxLC_SINGLE_SEL)) return;
1936
1937 wxNode *node = m_lines.Nth( item );
1938 if (node)
1939 {
1940 wxListLineData *line = (wxListLineData*)node->Data();
1941 if (m_mode & wxLC_SINGLE_SEL)
1942 {
1943 UnfocusLine( m_current );
1944 m_current = line;
1945 FocusLine( m_current );
00a39542 1946 if (oldCurrent) oldCurrent->Hilight( FALSE );
92976ab6 1947 RefreshLine( m_current );
00a39542 1948 if (oldCurrent) RefreshLine( oldCurrent );
92976ab6
RR
1949 }
1950 bool on = state & wxLIST_STATE_SELECTED;
139adb6a
RR
1951 if (on != line->IsHilighted())
1952 {
1953 line->Hilight( on );
1954 RefreshLine( line );
1955 }
92976ab6 1956 }
e1e955e1 1957 }
e1e955e1 1958}
c801d85f 1959
debe6624 1960int wxListMainWindow::GetItemState( long item, long stateMask )
c801d85f 1961{
92976ab6
RR
1962 int ret = wxLIST_STATE_DONTCARE;
1963 if (stateMask & wxLIST_STATE_FOCUSED)
c801d85f 1964 {
92976ab6
RR
1965 wxNode *node = m_lines.Nth( item );
1966 if (node)
1967 {
1968 wxListLineData *line = (wxListLineData*)node->Data();
1969 if (line == m_current) ret |= wxLIST_STATE_FOCUSED;
1970 }
e1e955e1 1971 }
92976ab6 1972 if (stateMask & wxLIST_STATE_SELECTED)
c801d85f 1973 {
92976ab6
RR
1974 wxNode *node = m_lines.Nth( item );
1975 if (node)
1976 {
1977 wxListLineData *line = (wxListLineData*)node->Data();
1978 if (line->IsHilighted()) ret |= wxLIST_STATE_FOCUSED;
1979 }
e1e955e1 1980 }
92976ab6 1981 return ret;
e1e955e1 1982}
c801d85f
KB
1983
1984void wxListMainWindow::GetItem( wxListItem &item )
1985{
92976ab6
RR
1986 wxNode *node = m_lines.Nth( item.m_itemId );
1987 if (node)
1988 {
1989 wxListLineData *line = (wxListLineData*)node->Data();
1990 line->GetItem( item.m_col, item );
1991 }
1992 else
1993 {
1994 item.m_mask = 0;
1995 item.m_text = "";
1996 item.m_image = 0;
1997 item.m_data = 0;
1998 }
e1e955e1 1999}
c801d85f 2000
e179bd65 2001int wxListMainWindow::GetItemCount()
c801d85f 2002{
92976ab6 2003 return m_lines.Number();
e1e955e1 2004}
c801d85f 2005
0a240683 2006void wxListMainWindow::GetItemRect( long index, wxRect &rect )
c801d85f 2007{
92976ab6
RR
2008 wxNode *node = m_lines.Nth( index );
2009 if (node)
2010 {
2011 wxListLineData *line = (wxListLineData*)node->Data();
2012 line->GetRect( rect );
2013 }
2014 else
2015 {
2016 rect.x = 0;
2017 rect.y = 0;
2018 rect.width = 0;
2019 rect.height = 0;
2020 }
e1e955e1 2021}
c801d85f 2022
e3e65dac
RR
2023bool wxListMainWindow::GetItemPosition(long item, wxPoint& pos)
2024{
92976ab6
RR
2025 wxNode *node = m_lines.Nth( item );
2026 if (node)
2027 {
0a240683 2028 wxRect rect;
92976ab6
RR
2029 wxListLineData *line = (wxListLineData*)node->Data();
2030 line->GetRect( rect );
2031 pos.x = rect.x;
2032 pos.y = rect.y;
2033 }
2034 else
2035 {
2036 pos.x = 0;
2037 pos.y = 0;
2038 }
2039 return TRUE;
e1e955e1 2040}
e3e65dac 2041
e179bd65 2042int wxListMainWindow::GetSelectedItemCount()
c801d85f 2043{
92976ab6
RR
2044 int ret = 0;
2045 wxNode *node = m_lines.First();
2046 while (node)
2047 {
2048 wxListLineData *line = (wxListLineData*)node->Data();
2049 if (line->IsHilighted()) ret++;
2050 node = node->Next();
2051 }
2052 return ret;
e1e955e1 2053}
c801d85f 2054
debe6624 2055void wxListMainWindow::SetMode( long mode )
c801d85f 2056{
92976ab6
RR
2057 m_dirty = TRUE;
2058 m_mode = mode;
bd8289c1 2059
92976ab6 2060 DeleteEverything();
bd8289c1 2061
92976ab6
RR
2062 if (m_mode & wxLC_REPORT)
2063 {
2064 m_xScroll = 0;
2065 m_yScroll = 15;
2066 }
2067 else
2068 {
2069 m_xScroll = 15;
2070 m_yScroll = 0;
2071 }
e1e955e1 2072}
c801d85f 2073
e179bd65 2074long wxListMainWindow::GetMode() const
c801d85f 2075{
63852e78 2076 return m_mode;
e1e955e1 2077}
c801d85f 2078
e179bd65 2079void wxListMainWindow::CalculatePositions()
c801d85f 2080{
92976ab6 2081 if (!m_lines.First()) return;
e487524e 2082
1e6d9499 2083 wxClientDC dc( this );
92976ab6 2084 dc.SetFont( GetFont() );
c801d85f 2085
92976ab6
RR
2086 int iconSpacing = 0;
2087 if (m_mode & wxLC_ICON) iconSpacing = m_normal_spacing;
2088 if (m_mode & wxLC_SMALL_ICON) iconSpacing = m_small_spacing;
e487524e 2089
92976ab6
RR
2090 // we take the first line (which also can be an icon or
2091 // an a text item in wxLC_ICON and wxLC_LIST modes) to
2092 // measure the size of the line
e487524e 2093
92976ab6
RR
2094 int lineWidth = 0;
2095 int lineHeight = 0;
2096 int lineSpacing = 0;
c801d85f 2097
92976ab6
RR
2098 wxListLineData *line = (wxListLineData*)m_lines.First()->Data();
2099 line->CalculateSize( &dc, iconSpacing );
2100 int dummy = 0;
2101 line->GetSize( dummy, lineSpacing );
2102 lineSpacing += 4;
bd8289c1 2103
92976ab6
RR
2104 int clientWidth = 0;
2105 int clientHeight = 0;
bd8289c1 2106
92976ab6 2107 if (m_mode & wxLC_REPORT)
c801d85f 2108 {
92976ab6
RR
2109 int x = 4;
2110 int y = 1;
2111 int entireHeight = m_lines.Number() * lineSpacing + 2;
2112 int scroll_pos = GetScrollPos( wxVERTICAL );
8b53e5a2 2113 SetScrollbars( m_xScroll, m_yScroll, 0, (entireHeight+15) / m_yScroll, 0, scroll_pos, TRUE );
92976ab6
RR
2114 GetClientSize( &clientWidth, &clientHeight );
2115
2116 wxNode* node = m_lines.First();
2117 while (node)
2118 {
2119 wxListLineData *line = (wxListLineData*)node->Data();
2120 line->CalculateSize( &dc, iconSpacing );
2121 line->SetPosition( &dc, x, y, clientWidth );
2122 int col_x = 2;
2123 for (int i = 0; i < GetColumnCount(); i++)
2124 {
2125 line->SetColumnPosition( i, col_x );
2126 col_x += GetColumnWidth( i );
2127 }
2128 y += lineSpacing; // one pixel blank line between items
2129 node = node->Next();
2130 }
139adb6a 2131 m_visibleLines = clientHeight / lineSpacing;
e1e955e1 2132 }
92976ab6
RR
2133 else
2134 {
2135 // at first we try without any scrollbar. if the items don't
2136 // fit into the window, we recalculate after subtracting an
2137 // approximated 15 pt for the horizontal scrollbar
e487524e 2138
92976ab6
RR
2139 GetSize( &clientWidth, &clientHeight );
2140 clientHeight -= 4; // sunken frame
bd8289c1 2141
92976ab6 2142 int entireWidth = 0;
bd8289c1 2143
92976ab6 2144 for (int tries = 0; tries < 2; tries++)
e487524e 2145 {
92976ab6
RR
2146 entireWidth = 0;
2147 int x = 5; // painting is done at x-2
2148 int y = 5; // painting is done at y-2
2149 int maxWidth = 0;
0b855868
RR
2150 m_visibleLines = 0;
2151 int m_currentVisibleLines = 0;
92976ab6
RR
2152 wxNode *node = m_lines.First();
2153 while (node)
2154 {
0b855868 2155 m_currentVisibleLines++;
92976ab6
RR
2156 wxListLineData *line = (wxListLineData*)node->Data();
2157 line->CalculateSize( &dc, iconSpacing );
2158 line->SetPosition( &dc, x, y, clientWidth );
2159 line->GetSize( lineWidth, lineHeight );
2160 if (lineWidth > maxWidth) maxWidth = lineWidth;
2161 y += lineSpacing;
8b53e5a2 2162 if (y+lineSpacing-6 >= clientHeight) // -6 for earlier "line breaking"
92976ab6 2163 {
0b855868
RR
2164 if (m_currentVisibleLines > m_visibleLines)
2165 m_visibleLines = m_currentVisibleLines;
2166 m_currentVisibleLines = 0;
92976ab6 2167 y = 5;
8b53e5a2
RR
2168 x += maxWidth+6;
2169 entireWidth += maxWidth+6;
92976ab6
RR
2170 maxWidth = 0;
2171 }
2172 node = node->Next();
2173 if (!node) entireWidth += maxWidth;
2174 if ((tries == 0) && (entireWidth > clientWidth))
2175 {
2176 clientHeight -= 15; // scrollbar height
0b855868
RR
2177 m_visibleLines = 0;
2178 m_currentVisibleLines = 0;
92976ab6
RR
2179 break;
2180 }
2181 if (!node) tries = 1; // everything fits, no second try required
2182 }
e487524e 2183 }
0b855868 2184// m_visibleLines = (5+clientHeight+6) / (lineSpacing); // +6 for earlier "line breaking"
92976ab6
RR
2185
2186 int scroll_pos = GetScrollPos( wxHORIZONTAL );
2187 SetScrollbars( m_xScroll, m_yScroll, (entireWidth+15) / m_xScroll, 0, scroll_pos, 0, TRUE );
e1e955e1 2188 }
e1e955e1 2189}
c801d85f
KB
2190
2191void wxListMainWindow::RealizeChanges( void )
2192{
92976ab6
RR
2193 if (!m_current)
2194 {
2195 wxNode *node = m_lines.First();
2196 if (node) m_current = (wxListLineData*)node->Data();
2197 }
2198 if (m_current)
2199 {
2200 FocusLine( m_current );
2201 if (m_mode & wxLC_SINGLE_SEL) m_current->Hilight( TRUE );
2202 }
e1e955e1 2203}
c801d85f 2204
debe6624 2205long wxListMainWindow::GetNextItem( long item, int WXUNUSED(geometry), int state )
c801d85f 2206{
63852e78
RR
2207 long ret = 0;
2208 if (item > 0) ret = item;
d9081042 2209 if(ret >= GetItemCount()) return -1;
63852e78
RR
2210 wxNode *node = m_lines.Nth( ret );
2211 while (node)
2212 {
2213 wxListLineData *line = (wxListLineData*)node->Data();
2214 if ((state & wxLIST_STATE_FOCUSED) && (line == m_current)) return ret;
2215 if ((state & wxLIST_STATE_SELECTED) && (line->IsHilighted())) return ret;
2216 if (!state) return ret;
2217 ret++;
2218 node = node->Next();
2219 }
2220 return -1;
e1e955e1 2221}
c801d85f 2222
debe6624 2223void wxListMainWindow::DeleteItem( long index )
c801d85f 2224{
63852e78
RR
2225 m_dirty = TRUE;
2226 wxNode *node = m_lines.Nth( index );
2227 if (node)
2228 {
2229 wxListLineData *line = (wxListLineData*)node->Data();
2230 if (m_current == line) m_current = (wxListLineData *) NULL;
2231 DeleteLine( line );
2232 m_lines.DeleteNode( node );
2233 }
e1e955e1 2234}
c801d85f 2235
debe6624 2236void wxListMainWindow::DeleteColumn( int col )
c801d85f 2237{
5b077d48 2238 wxCHECK_RET( col < (int)m_columns.GetCount(),
87138c52 2239 _T("attempting to delete inexistent column in wxListView") );
bd8289c1 2240
5b077d48
RR
2241 m_dirty = TRUE;
2242 wxNode *node = m_columns.Nth( col );
2243 if (node) m_columns.DeleteNode( node );
e1e955e1 2244}
c801d85f
KB
2245
2246void wxListMainWindow::DeleteAllItems( void )
2247{
5b077d48
RR
2248 m_dirty = TRUE;
2249 m_current = (wxListLineData *) NULL;
2250 wxNode *node = m_lines.First();
2251 while (node)
2252 {
2253 wxListLineData *line = (wxListLineData*)node->Data();
2254 DeleteLine( line );
2255 node = node->Next();
2256 }
2257 m_lines.Clear();
e1e955e1 2258}
c801d85f
KB
2259
2260void wxListMainWindow::DeleteEverything( void )
2261{
5b077d48
RR
2262 m_dirty = TRUE;
2263 m_current = (wxListLineData *) NULL;
2264 wxNode *node = m_lines.First();
2265 while (node)
2266 {
2267 wxListLineData *line = (wxListLineData*)node->Data();
2268 DeleteLine( line );
2269 node = node->Next();
2270 }
2271 m_lines.Clear();
2272 m_current = (wxListLineData *) NULL;
2273 m_columns.Clear();
e1e955e1 2274}
c801d85f 2275
debe6624 2276void wxListMainWindow::EnsureVisible( long index )
c801d85f 2277{
dc6c62a9
RR
2278 // We have to call this here because the label in
2279 // question might just have been added and no screen
2280 // update taken place.
2281 if (m_dirty) wxYield();
2282
5b077d48
RR
2283 wxListLineData *oldCurrent = m_current;
2284 m_current = (wxListLineData *) NULL;
2285 int i = index;
2286 wxNode *node = m_lines.Nth( i );
2287 if (node) m_current = (wxListLineData*)node->Data();
2288 if (m_current) MoveToFocus();
2289 m_current = oldCurrent;
e1e955e1 2290}
c801d85f 2291
debe6624 2292long wxListMainWindow::FindItem(long start, const wxString& str, bool WXUNUSED(partial) )
c801d85f 2293{
5b077d48
RR
2294 long pos = start;
2295 wxString tmp = str;
2296 if (pos < 0) pos = 0;
2297 wxNode *node = m_lines.Nth( pos );
2298 while (node)
2299 {
2300 wxListLineData *line = (wxListLineData*)node->Data();
2301 wxString s = "";
2302 line->GetText( 0, s );
2303 if (s == tmp) return pos;
2304 node = node->Next();
2305 pos++;
2306 }
2307 return -1;
e1e955e1 2308}
c801d85f 2309
debe6624 2310long wxListMainWindow::FindItem(long start, long data)
c801d85f 2311{
5b077d48
RR
2312 long pos = start;
2313 if (pos < 0) pos = 0;
2314 wxNode *node = m_lines.Nth( pos );
2315 while (node)
2316 {
2317 wxListLineData *line = (wxListLineData*)node->Data();
2318 wxListItem item;
2319 line->GetItem( 0, item );
2320 if (item.m_data == data) return pos;
2321 node = node->Next();
2322 pos++;
2323 }
2324 return -1;
e1e955e1 2325}
c801d85f 2326
debe6624 2327long wxListMainWindow::HitTest( int x, int y, int &flags )
c801d85f 2328{
5b077d48
RR
2329 wxNode *node = m_lines.First();
2330 int count = 0;
2331 while (node)
c801d85f 2332 {
5b077d48
RR
2333 wxListLineData *line = (wxListLineData*)node->Data();
2334 long ret = line->IsHit( x, y );
2335 if (ret & flags)
2336 {
2337 flags = ret;
2338 return count;
2339 }
2340 node = node->Next();
2341 count++;
e1e955e1 2342 }
5b077d48 2343 return -1;
e1e955e1 2344}
c801d85f
KB
2345
2346void wxListMainWindow::InsertItem( wxListItem &item )
2347{
5b077d48
RR
2348 m_dirty = TRUE;
2349 int mode = 0;
2350 if (m_mode & wxLC_REPORT) mode = wxLC_REPORT;
2351 else if (m_mode & wxLC_LIST) mode = wxLC_LIST;
2352 else if (m_mode & wxLC_ICON) mode = wxLC_ICON;
2353 else if (m_mode & wxLC_SMALL_ICON) mode = wxLC_ICON; // no typo
2354
2355 wxListLineData *line = new wxListLineData( this, mode, m_hilightBrush );
2356
2357 if (m_mode & wxLC_REPORT)
2358 {
2359 line->InitItems( GetColumnCount() );
2360 item.m_width = GetColumnWidth( 0 )-3;
2361 }
2362 else
2363 {
2364 line->InitItems( 1 );
2365 }
2366
2367 line->SetItem( 0, item );
2368 if ((item.m_itemId >= 0) && (item.m_itemId < (int)m_lines.GetCount()))
2369 {
2370 wxNode *node = m_lines.Nth( item.m_itemId );
2371 if (node) m_lines.Insert( node, line );
2372 }
2373 else
2374 {
2375 m_lines.Append( line );
2376 }
e1e955e1 2377}
c801d85f 2378
debe6624 2379void wxListMainWindow::InsertColumn( long col, wxListItem &item )
c801d85f 2380{
5b077d48
RR
2381 m_dirty = TRUE;
2382 if (m_mode & wxLC_REPORT)
3db7be80 2383 {
5b077d48
RR
2384 if (item.m_width == wxLIST_AUTOSIZE_USEHEADER) item.m_width = GetTextLength( item.m_text );
2385 wxListHeaderData *column = new wxListHeaderData( item );
2386 if ((col >= 0) && (col < (int)m_columns.GetCount()))
2387 {
2388 wxNode *node = m_columns.Nth( col );
2389 if (node)
2390 m_columns.Insert( node, column );
2391 }
2392 else
2393 {
2394 m_columns.Append( column );
2395 }
3db7be80 2396 }
e1e955e1 2397}
c801d85f
KB
2398
2399wxListCtrlCompare list_ctrl_compare_func_2;
2400long list_ctrl_compare_data;
2401
2402int list_ctrl_compare_func_1( const void *arg1, const void *arg2 )
2403{
5b077d48
RR
2404 wxListLineData *line1 = *((wxListLineData**)arg1);
2405 wxListLineData *line2 = *((wxListLineData**)arg2);
2406 wxListItem item;
2407 line1->GetItem( 0, item );
2408 long data1 = item.m_data;
2409 line2->GetItem( 0, item );
2410 long data2 = item.m_data;
2411 return list_ctrl_compare_func_2( data1, data2, list_ctrl_compare_data );
e1e955e1 2412}
c801d85f
KB
2413
2414void wxListMainWindow::SortItems( wxListCtrlCompare fn, long data )
2415{
5b077d48
RR
2416 list_ctrl_compare_func_2 = fn;
2417 list_ctrl_compare_data = data;
2418 m_lines.Sort( list_ctrl_compare_func_1 );
e1e955e1 2419}
c801d85f 2420
c801d85f
KB
2421// -------------------------------------------------------------------------------------
2422// wxListItem
2423// -------------------------------------------------------------------------------------
2424
2425IMPLEMENT_DYNAMIC_CLASS(wxListItem, wxObject)
2426
fd9811b1 2427wxListItem::wxListItem()
c801d85f 2428{
63852e78
RR
2429 m_mask = 0;
2430 m_itemId = 0;
2431 m_col = 0;
2432 m_state = 0;
2433 m_stateMask = 0;
2434 m_image = 0;
2435 m_data = 0;
2436 m_format = wxLIST_FORMAT_CENTRE;
2437 m_width = 0;
2438 m_colour = wxBLACK;
c801d85f
KB
2439}
2440
2441// -------------------------------------------------------------------------------------
2442// wxListEvent
2443// -------------------------------------------------------------------------------------
2444
92976ab6 2445IMPLEMENT_DYNAMIC_CLASS(wxListEvent, wxNotifyEvent)
c801d85f 2446
8f79098a 2447wxListEvent::wxListEvent( wxEventType commandType, int id ):
92976ab6 2448 wxNotifyEvent( commandType, id )
c801d85f 2449{
5b077d48
RR
2450 m_code = 0;
2451 m_itemIndex = 0;
2452 m_oldItemIndex = 0;
2453 m_col = 0;
2454 m_cancelled = FALSE;
2455 m_pointDrag.x = 0;
2456 m_pointDrag.y = 0;
e1e955e1 2457}
c801d85f
KB
2458
2459// -------------------------------------------------------------------------------------
2460// wxListCtrl
2461// -------------------------------------------------------------------------------------
2462
2463IMPLEMENT_DYNAMIC_CLASS(wxListCtrl, wxControl)
2464
2465BEGIN_EVENT_TABLE(wxListCtrl,wxControl)
2466 EVT_SIZE (wxListCtrl::OnSize)
53010e52 2467 EVT_IDLE (wxListCtrl::OnIdle)
c801d85f
KB
2468END_EVENT_TABLE()
2469
fd9811b1 2470wxListCtrl::wxListCtrl()
c801d85f 2471{
5b077d48
RR
2472 m_imageListNormal = (wxImageList *) NULL;
2473 m_imageListSmall = (wxImageList *) NULL;
2474 m_imageListState = (wxImageList *) NULL;
2475 m_mainWin = (wxListMainWindow*) NULL;
2476 m_headerWin = (wxListHeaderWindow*) NULL;
c801d85f
KB
2477}
2478
fd9811b1 2479wxListCtrl::~wxListCtrl()
c801d85f
KB
2480{
2481}
2482
bd8289c1 2483bool wxListCtrl::Create( wxWindow *parent, wxWindowID id,
debe6624 2484 const wxPoint &pos, const wxSize &size,
bd8289c1 2485 long style, const wxValidator &validator,
32e9da8b 2486 const wxString &name )
c801d85f 2487{
5b077d48
RR
2488 m_imageListNormal = (wxImageList *) NULL;
2489 m_imageListSmall = (wxImageList *) NULL;
2490 m_imageListState = (wxImageList *) NULL;
2491 m_mainWin = (wxListMainWindow*) NULL;
2492 m_headerWin = (wxListHeaderWindow*) NULL;
bd8289c1 2493
5b077d48 2494 long s = style;
bd8289c1 2495
5b077d48
RR
2496 if ((s & wxLC_REPORT == 0) &&
2497 (s & wxLC_LIST == 0) &&
2498 (s & wxLC_ICON == 0))
2499 {
2500 s = s | wxLC_LIST;
2501 }
bd8289c1 2502
5b077d48 2503 bool ret = wxControl::Create( parent, id, pos, size, s, name );
bd8289c1 2504
ce4169a4 2505#if wxUSE_VALIDATORS
5b077d48 2506 SetValidator( validator );
ce4169a4 2507#endif
907789a0 2508
5b077d48 2509 if (s & wxSUNKEN_BORDER) s -= wxSUNKEN_BORDER;
bd8289c1 2510
5b077d48 2511 m_mainWin = new wxListMainWindow( this, -1, wxPoint(0,0), size, s );
bd8289c1 2512
f03fc89f 2513 if (HasFlag(wxLC_REPORT))
5b077d48
RR
2514 m_headerWin = new wxListHeaderWindow( this, -1, m_mainWin, wxPoint(0,0), wxSize(size.x,23), wxTAB_TRAVERSAL );
2515 else
2516 m_headerWin = (wxListHeaderWindow *) NULL;
bd8289c1 2517
58dea4b0
RR
2518 SetBackgroundColour( *wxWHITE );
2519
5b077d48 2520 return ret;
e1e955e1 2521}
c801d85f
KB
2522
2523void wxListCtrl::OnSize( wxSizeEvent &WXUNUSED(event) )
2524{
5b077d48 2525 /* handled in OnIdle */
bd8289c1 2526
5b077d48 2527 if (m_mainWin) m_mainWin->m_dirty = TRUE;
e1e955e1 2528}
c801d85f 2529
debe6624 2530void wxListCtrl::SetSingleStyle( long style, bool add )
c801d85f 2531{
f03fc89f 2532 long flag = GetWindowStyle();
bd8289c1 2533
5b077d48
RR
2534 if (add)
2535 {
2536 if (style & wxLC_MASK_TYPE) flag = flag & ~wxLC_MASK_TYPE;
2537 if (style & wxLC_MASK_ALIGN) flag = flag & ~wxLC_MASK_ALIGN;
2538 if (style & wxLC_MASK_SORT) flag = flag & ~wxLC_MASK_SORT;
2539 }
c801d85f 2540
5b077d48
RR
2541 if (add)
2542 {
2543 flag |= style;
2544 }
2545 else
2546 {
2547 if (flag & style) flag -= style;
2548 }
bd8289c1 2549
5b077d48 2550 SetWindowStyleFlag( flag );
e1e955e1 2551}
c801d85f 2552
debe6624 2553void wxListCtrl::SetWindowStyleFlag( long flag )
c801d85f 2554{
121a3581
RR
2555 if (m_mainWin)
2556 {
2557 m_mainWin->DeleteEverything();
c801d85f 2558
121a3581
RR
2559 int width = 0;
2560 int height = 0;
2561 GetClientSize( &width, &height );
c801d85f 2562
121a3581 2563 m_mainWin->SetMode( flag );
bd8289c1 2564
121a3581 2565 if (flag & wxLC_REPORT)
5b077d48 2566 {
121a3581 2567 if (!HasFlag(wxLC_REPORT))
5b077d48 2568 {
121a3581
RR
2569 if (!m_headerWin)
2570 {
2571 m_headerWin = new wxListHeaderWindow( this, -1, m_mainWin,
2572 wxPoint(0,0), wxSize(width,23), wxTAB_TRAVERSAL );
2573 }
2574 else
2575 {
2576 m_headerWin->Show( TRUE );
2577 }
5b077d48
RR
2578 }
2579 }
121a3581 2580 else
5b077d48 2581 {
121a3581
RR
2582 if (HasFlag(wxLC_REPORT))
2583 {
2584 m_headerWin->Show( FALSE );
2585 }
2586 }
e1e955e1 2587 }
121a3581 2588
5b077d48 2589 wxWindow::SetWindowStyleFlag( flag );
e1e955e1 2590}
c801d85f 2591
e487524e 2592bool wxListCtrl::GetColumn(int col, wxListItem &item) const
c801d85f 2593{
5b077d48
RR
2594 m_mainWin->GetColumn( col, item );
2595 return TRUE;
e1e955e1 2596}
c801d85f 2597
debe6624 2598bool wxListCtrl::SetColumn( int col, wxListItem& item )
c801d85f 2599{
5b077d48
RR
2600 m_mainWin->SetColumn( col, item );
2601 return TRUE;
e1e955e1 2602}
c801d85f 2603
e487524e 2604int wxListCtrl::GetColumnWidth( int col ) const
c801d85f 2605{
5b077d48 2606 return m_mainWin->GetColumnWidth( col );
e1e955e1 2607}
c801d85f 2608
debe6624 2609bool wxListCtrl::SetColumnWidth( int col, int width )
c801d85f 2610{
5b077d48
RR
2611 m_mainWin->SetColumnWidth( col, width );
2612 return TRUE;
e1e955e1 2613}
c801d85f 2614
fd9811b1 2615int wxListCtrl::GetCountPerPage() const
c801d85f
KB
2616{
2617 return m_mainWin->GetCountPerPage(); // different from Windows ?
e1e955e1 2618}
c801d85f 2619
e487524e 2620bool wxListCtrl::GetItem( wxListItem &info ) const
c801d85f 2621{
5b077d48
RR
2622 m_mainWin->GetItem( info );
2623 return TRUE;
e1e955e1 2624}
c801d85f
KB
2625
2626bool wxListCtrl::SetItem( wxListItem &info )
2627{
5b077d48
RR
2628 m_mainWin->SetItem( info );
2629 return TRUE;
e1e955e1 2630}
c801d85f 2631
debe6624 2632long wxListCtrl::SetItem( long index, int col, const wxString& label, int imageId )
c801d85f 2633{
5b077d48
RR
2634 wxListItem info;
2635 info.m_text = label;
2636 info.m_mask = wxLIST_MASK_TEXT;
2637 info.m_itemId = index;
2638 info.m_col = col;
2639 if ( imageId > -1 )
2640 {
2641 info.m_image = imageId;
2642 info.m_mask |= wxLIST_MASK_IMAGE;
2643 };
2644 m_mainWin->SetItem(info);
2645 return TRUE;
e1e955e1 2646}
c801d85f 2647
e487524e 2648int wxListCtrl::GetItemState( long item, long stateMask ) const
c801d85f 2649{
5b077d48 2650 return m_mainWin->GetItemState( item, stateMask );
e1e955e1 2651}
c801d85f 2652
debe6624 2653bool wxListCtrl::SetItemState( long item, long state, long stateMask )
c801d85f 2654{
5b077d48
RR
2655 m_mainWin->SetItemState( item, state, stateMask );
2656 return TRUE;
e1e955e1 2657}
c801d85f 2658
debe6624 2659bool wxListCtrl::SetItemImage( long item, int image, int WXUNUSED(selImage) )
c801d85f 2660{
5b077d48
RR
2661 wxListItem info;
2662 info.m_image = image;
2663 info.m_mask = wxLIST_MASK_IMAGE;
2664 info.m_itemId = item;
2665 m_mainWin->SetItem( info );
2666 return TRUE;
e1e955e1 2667}
c801d85f 2668
e487524e 2669wxString wxListCtrl::GetItemText( long item ) const
c801d85f 2670{
5b077d48
RR
2671 wxListItem info;
2672 info.m_itemId = item;
2673 m_mainWin->GetItem( info );
2674 return info.m_text;
e1e955e1 2675}
c801d85f 2676
debe6624 2677void wxListCtrl::SetItemText( long item, const wxString &str )
c801d85f 2678{
5b077d48
RR
2679 wxListItem info;
2680 info.m_mask = wxLIST_MASK_TEXT;
2681 info.m_itemId = item;
2682 info.m_text = str;
2683 m_mainWin->SetItem( info );
e1e955e1 2684}
c801d85f 2685
e487524e 2686long wxListCtrl::GetItemData( long item ) const
c801d85f 2687{
5b077d48
RR
2688 wxListItem info;
2689 info.m_itemId = item;
2690 m_mainWin->GetItem( info );
2691 return info.m_data;
e1e955e1 2692}
c801d85f 2693
debe6624 2694bool wxListCtrl::SetItemData( long item, long data )
c801d85f 2695{
5b077d48
RR
2696 wxListItem info;
2697 info.m_mask = wxLIST_MASK_DATA;
2698 info.m_itemId = item;
2699 info.m_data = data;
2700 m_mainWin->SetItem( info );
2701 return TRUE;
e1e955e1 2702}
c801d85f 2703
0a240683 2704bool wxListCtrl::GetItemRect( long item, wxRect &rect, int WXUNUSED(code) ) const
c801d85f 2705{
5b077d48
RR
2706 m_mainWin->GetItemRect( item, rect );
2707 return TRUE;
e1e955e1 2708}
c801d85f 2709
e487524e 2710bool wxListCtrl::GetItemPosition( long item, wxPoint& pos ) const
c801d85f 2711{
5b077d48
RR
2712 m_mainWin->GetItemPosition( item, pos );
2713 return TRUE;
e1e955e1 2714}
c801d85f 2715
debe6624 2716bool wxListCtrl::SetItemPosition( long WXUNUSED(item), const wxPoint& WXUNUSED(pos) )
c801d85f 2717{
5b077d48 2718 return 0;
e1e955e1 2719}
c801d85f 2720
fd9811b1 2721int wxListCtrl::GetItemCount() const
c801d85f 2722{
5b077d48 2723 return m_mainWin->GetItemCount();
e1e955e1 2724}
c801d85f 2725
fd9811b1 2726int wxListCtrl::GetColumnCount() const
92976ab6 2727{
5b077d48 2728 return m_mainWin->GetColumnCount();
92976ab6
RR
2729}
2730
33d0b396
RR
2731void wxListCtrl::SetItemSpacing( int spacing, bool isSmall )
2732{
5b077d48 2733 m_mainWin->SetItemSpacing( spacing, isSmall );
e1e955e1 2734}
33d0b396 2735
e487524e 2736int wxListCtrl::GetItemSpacing( bool isSmall ) const
c801d85f 2737{
5b077d48 2738 return m_mainWin->GetItemSpacing( isSmall );
e1e955e1 2739}
c801d85f 2740
fd9811b1 2741int wxListCtrl::GetSelectedItemCount() const
c801d85f 2742{
5b077d48 2743 return m_mainWin->GetSelectedItemCount();
e1e955e1 2744}
c801d85f
KB
2745
2746/*
fd9811b1 2747wxColour wxListCtrl::GetTextColour() const
c801d85f 2748{
e1e955e1 2749}
c801d85f
KB
2750
2751void wxListCtrl::SetTextColour(const wxColour& WXUNUSED(col))
2752{
e1e955e1 2753}
c801d85f
KB
2754*/
2755
fd9811b1 2756long wxListCtrl::GetTopItem() const
c801d85f 2757{
5b077d48 2758 return 0;
e1e955e1 2759}
c801d85f 2760
6de97a3b 2761long wxListCtrl::GetNextItem( long item, int geom, int state ) const
c801d85f 2762{
5b077d48 2763 return m_mainWin->GetNextItem( item, geom, state );
e1e955e1 2764}
c801d85f 2765
e487524e 2766wxImageList *wxListCtrl::GetImageList(int which) const
c801d85f 2767{
5b077d48
RR
2768 if (which == wxIMAGE_LIST_NORMAL)
2769 {
2770 return m_imageListNormal;
2771 }
2772 else if (which == wxIMAGE_LIST_SMALL)
2773 {
2774 return m_imageListSmall;
2775 }
2776 else if (which == wxIMAGE_LIST_STATE)
2777 {
2778 return m_imageListState;
2779 }
2780 return (wxImageList *) NULL;
e1e955e1 2781}
c801d85f 2782
debe6624 2783void wxListCtrl::SetImageList( wxImageList *imageList, int which )
c801d85f 2784{
5b077d48 2785 m_mainWin->SetImageList( imageList, which );
e1e955e1 2786}
c801d85f 2787
debe6624 2788bool wxListCtrl::Arrange( int WXUNUSED(flag) )
c801d85f 2789{
5b077d48 2790 return 0;
e1e955e1 2791}
c801d85f 2792
debe6624 2793bool wxListCtrl::DeleteItem( long item )
c801d85f 2794{
5b077d48
RR
2795 m_mainWin->DeleteItem( item );
2796 return TRUE;
e1e955e1 2797}
c801d85f 2798
fd9811b1 2799bool wxListCtrl::DeleteAllItems()
c801d85f 2800{
5b077d48
RR
2801 m_mainWin->DeleteAllItems();
2802 return TRUE;
e1e955e1 2803}
c801d85f 2804
4f22cf8d 2805bool wxListCtrl::DeleteAllColumns()
bd8289c1
VZ
2806{
2807 for ( size_t n = 0; n < m_mainWin->m_columns.GetCount(); n++ )
2808 DeleteColumn(n);
4f22cf8d 2809
5b077d48 2810 return TRUE;
4f22cf8d
RR
2811}
2812
2813void wxListCtrl::ClearAll()
2814{
5b077d48 2815 m_mainWin->DeleteEverything();
bd8289c1
VZ
2816}
2817
debe6624 2818bool wxListCtrl::DeleteColumn( int col )
c801d85f 2819{
5b077d48
RR
2820 m_mainWin->DeleteColumn( col );
2821 return TRUE;
e1e955e1 2822}
c801d85f 2823
e179bd65 2824void wxListCtrl::Edit( long item )
c801d85f 2825{
e179bd65 2826 m_mainWin->Edit( item );
e1e955e1 2827}
c801d85f 2828
debe6624 2829bool wxListCtrl::EnsureVisible( long item )
c801d85f 2830{
5b077d48
RR
2831 m_mainWin->EnsureVisible( item );
2832 return TRUE;
e1e955e1 2833}
c801d85f 2834
debe6624 2835long wxListCtrl::FindItem( long start, const wxString& str, bool partial )
c801d85f 2836{
5b077d48 2837 return m_mainWin->FindItem( start, str, partial );
e1e955e1 2838}
c801d85f 2839
debe6624 2840long wxListCtrl::FindItem( long start, long data )
c801d85f 2841{
5b077d48 2842 return m_mainWin->FindItem( start, data );
e1e955e1 2843}
c801d85f 2844
bd8289c1 2845long wxListCtrl::FindItem( long WXUNUSED(start), const wxPoint& WXUNUSED(pt),
debe6624 2846 int WXUNUSED(direction))
c801d85f 2847{
5b077d48 2848 return 0;
e1e955e1 2849}
c801d85f
KB
2850
2851long wxListCtrl::HitTest( const wxPoint &point, int &flags )
2852{
5b077d48 2853 return m_mainWin->HitTest( (int)point.x, (int)point.y, flags );
e1e955e1 2854}
c801d85f
KB
2855
2856long wxListCtrl::InsertItem( wxListItem& info )
2857{
5b077d48
RR
2858 m_mainWin->InsertItem( info );
2859 return 0;
e1e955e1 2860}
c801d85f 2861
debe6624 2862long wxListCtrl::InsertItem( long index, const wxString &label )
c801d85f 2863{
51cc4dad
RR
2864 wxListItem info;
2865 info.m_text = label;
2866 info.m_mask = wxLIST_MASK_TEXT;
2867 info.m_itemId = index;
2868 return InsertItem( info );
e1e955e1 2869}
c801d85f 2870
debe6624 2871long wxListCtrl::InsertItem( long index, int imageIndex )
c801d85f 2872{
51cc4dad
RR
2873 wxListItem info;
2874 info.m_mask = wxLIST_MASK_IMAGE;
2875 info.m_image = imageIndex;
2876 info.m_itemId = index;
2877 return InsertItem( info );
e1e955e1 2878}
c801d85f 2879
debe6624 2880long wxListCtrl::InsertItem( long index, const wxString &label, int imageIndex )
c801d85f 2881{
51cc4dad
RR
2882 wxListItem info;
2883 info.m_text = label;
2884 info.m_image = imageIndex;
2885 info.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_IMAGE;
2886 info.m_itemId = index;
2887 return InsertItem( info );
e1e955e1 2888}
c801d85f 2889
debe6624 2890long wxListCtrl::InsertColumn( long col, wxListItem &item )
c801d85f 2891{
51cc4dad
RR
2892 m_mainWin->InsertColumn( col, item );
2893 return 0;
e1e955e1 2894}
c801d85f 2895
debe6624
JS
2896long wxListCtrl::InsertColumn( long col, const wxString &heading,
2897 int format, int width )
c801d85f 2898{
51cc4dad
RR
2899 wxListItem item;
2900 item.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_FORMAT;
2901 item.m_text = heading;
2902 if (width >= -2)
2903 {
2904 item.m_mask |= wxLIST_MASK_WIDTH;
2905 item.m_width = width;
2906 }
2907 item.m_format = format;
c801d85f 2908
51cc4dad 2909 return InsertColumn( col, item );
e1e955e1 2910}
c801d85f 2911
debe6624 2912bool wxListCtrl::ScrollList( int WXUNUSED(dx), int WXUNUSED(dy) )
c801d85f 2913{
51cc4dad 2914 return 0;
e1e955e1 2915}
c801d85f
KB
2916
2917// Sort items.
2918// fn is a function which takes 3 long arguments: item1, item2, data.
2919// item1 is the long data associated with a first item (NOT the index).
2920// item2 is the long data associated with a second item (NOT the index).
2921// data is the same value as passed to SortItems.
2922// The return value is a negative number if the first item should precede the second
2923// item, a positive number of the second item should precede the first,
2924// or zero if the two items are equivalent.
2925// data is arbitrary data to be passed to the sort function.
2926
2927bool wxListCtrl::SortItems( wxListCtrlCompare fn, long data )
2928{
51cc4dad
RR
2929 m_mainWin->SortItems( fn, data );
2930 return TRUE;
e1e955e1 2931}
c801d85f 2932
e3e65dac 2933void wxListCtrl::OnIdle( wxIdleEvent &WXUNUSED(event) )
53010e52 2934{
51cc4dad 2935 if (!m_mainWin->m_dirty) return;
53010e52 2936
51cc4dad
RR
2937 int cw = 0;
2938 int ch = 0;
2939 GetClientSize( &cw, &ch );
bd8289c1 2940
51cc4dad
RR
2941 int x = 0;
2942 int y = 0;
2943 int w = 0;
2944 int h = 0;
bd8289c1 2945
f03fc89f 2946 if (HasFlag(wxLC_REPORT))
51cc4dad
RR
2947 {
2948 m_headerWin->GetPosition( &x, &y );
2949 m_headerWin->GetSize( &w, &h );
2950 if ((x != 0) || (y != 0) || (w != cw) || (h != 23))
2951 m_headerWin->SetSize( 0, 0, cw, 23 );
2952
2953 m_mainWin->GetPosition( &x, &y );
2954 m_mainWin->GetSize( &w, &h );
2955 if ((x != 0) || (y != 24) || (w != cw) || (h != ch-24))
2956 m_mainWin->SetSize( 0, 24, cw, ch-24 );
2957 }
2958 else
2959 {
2960 m_mainWin->GetPosition( &x, &y );
2961 m_mainWin->GetSize( &w, &h );
2962 if ((x != 0) || (y != 24) || (w != cw) || (h != ch))
2963 m_mainWin->SetSize( 0, 0, cw, ch );
2964 }
bd8289c1 2965
51cc4dad
RR
2966 m_mainWin->CalculatePositions();
2967 m_mainWin->RealizeChanges();
2968 m_mainWin->m_dirty = FALSE;
2969 m_mainWin->Refresh();
e1e955e1 2970}
53010e52 2971
f03fc89f 2972bool wxListCtrl::SetBackgroundColour( const wxColour &colour )
bd8289c1 2973{
f03fc89f
VZ
2974 if ( !wxWindow::SetBackgroundColour( colour ) )
2975 return FALSE;
58dea4b0 2976
51cc4dad
RR
2977 if (m_mainWin)
2978 {
2979 m_mainWin->SetBackgroundColour( colour );
2980 m_mainWin->m_dirty = TRUE;
2981 }
2982
2983 if (m_headerWin)
2984 {
cfb50f14 2985// m_headerWin->SetBackgroundColour( colour );
51cc4dad 2986 }
f03fc89f
VZ
2987
2988 return TRUE;
e4d06860
RR
2989}
2990
f03fc89f 2991bool wxListCtrl::SetForegroundColour( const wxColour &colour )
bd8289c1 2992{
f03fc89f
VZ
2993 if ( !wxWindow::SetForegroundColour( colour ) )
2994 return FALSE;
58dea4b0 2995
51cc4dad
RR
2996 if (m_mainWin)
2997 {
2998 m_mainWin->SetForegroundColour( colour );
2999 m_mainWin->m_dirty = TRUE;
3000 }
3001
3002 if (m_headerWin)
3003 {
3004 m_headerWin->SetForegroundColour( colour );
3005 }
f03fc89f
VZ
3006
3007 return TRUE;
e4d06860 3008}
bd8289c1 3009
f03fc89f 3010bool wxListCtrl::SetFont( const wxFont &font )
bd8289c1 3011{
f03fc89f
VZ
3012 if ( !wxWindow::SetFont( font ) )
3013 return FALSE;
58dea4b0 3014
51cc4dad
RR
3015 if (m_mainWin)
3016 {
3017 m_mainWin->SetFont( font );
3018 m_mainWin->m_dirty = TRUE;
3019 }
3020
3021 if (m_headerWin)
3022 {
3023 m_headerWin->SetFont( font );
3024 }
f03fc89f
VZ
3025
3026 return TRUE;
e4d06860 3027}
c801d85f 3028