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