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