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