]> git.saurik.com Git - wxWidgets.git/blame - src/generic/listctrl.cpp
Fixed wxRichTextCtrl base class
[wxWidgets.git] / src / generic / listctrl.cpp
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
faa94f3e 2// Name: src/generic/listctrl.cpp
54442116 3// Purpose: generic implementation of wxListCtrl
c801d85f 4// Author: Robert Roebling
cf1dfa6b 5// Vadim Zeitlin (virtual list control support)
0208334d
RR
6// Id: $Id$
7// Copyright: (c) 1998 Robert Roebling
65571936 8// Licence: wxWindows licence
c801d85f
KB
9/////////////////////////////////////////////////////////////////////////////
10
277ea1b4
DS
11// TODO
12//
13// 1. we need to implement searching/sorting for virtual controls somehow
ad486020 14// 2. when changing selection the lines are refreshed twice
b54e41c5 15
1370703e 16
1e6d9499
JS
17// For compilers that support precompilation, includes "wx.h".
18#include "wx/wxprec.h"
19
20#ifdef __BORLANDC__
a2e5beee 21 #pragma hdrstop
1e6d9499
JS
22#endif
23
1e6feb95
VZ
24#if wxUSE_LISTCTRL
25
e2bc1d69 26#include "wx/listctrl.h"
2b5f62a0 27
530a427a 28#if ((!defined(__WXMSW__) && !(defined(__WXMAC__) && wxOSX_USE_CARBON)) || defined(__WXUNIVERSAL__))
2b5f62a0
VZ
29 // if we have a native version, its implementation file does all this
30 IMPLEMENT_DYNAMIC_CLASS(wxListItem, wxObject)
31 IMPLEMENT_DYNAMIC_CLASS(wxListView, wxListCtrl)
32 IMPLEMENT_DYNAMIC_CLASS(wxListEvent, wxNotifyEvent)
33
34 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl, wxGenericListCtrl)
e409b62a 35#endif
c801d85f 36
2a673eb1 37#ifndef WX_PRECOMP
e409b62a
PC
38 #include "wx/scrolwin.h"
39 #include "wx/timer.h"
40 #include "wx/settings.h"
2a673eb1 41 #include "wx/dynarray.h"
f7354d92 42 #include "wx/dcclient.h"
2a673eb1 43 #include "wx/dcscreen.h"
18680f86 44 #include "wx/math.h"
5595181f 45 #include "wx/settings.h"
64374d1b 46 #include "wx/sizer.h"
2a673eb1
WS
47#endif
48
e409b62a 49#include "wx/imaglist.h"
9c7f49f5 50#include "wx/renderer.h"
74491934 51#include "wx/generic/private/listctrl.h"
9c7f49f5 52
f89d65ea 53#ifdef __WXMAC__
33ddeaba 54 #include "wx/osx/private.h"
530a427a
SC
55 // for themeing support
56 #include <Carbon/Carbon.h>
f89d65ea 57#endif
e1d1f4bd 58
5d55031c
VZ
59#if defined(__WXMSW__) && !defined(__WXWINCE__) && !defined(__WXUNIVERSAL__)
60 #define "wx/msw/wrapwin.h"
61#endif
8158e0e1 62
e1d1f4bd
RD
63// NOTE: If using the wxListBox visual attributes works everywhere then this can
64// be removed, as well as the #else case below.
65#define _USE_VISATTR 0
66
67
cf1dfa6b
VZ
68// ----------------------------------------------------------------------------
69// constants
70// ----------------------------------------------------------------------------
71
f8252483
JS
72// // the height of the header window (FIXME: should depend on its font!)
73// static const int HEADER_HEIGHT = 23;
cf1dfa6b 74
cf1dfa6b 75static const int SCROLL_UNIT_X = 15;
cf1dfa6b
VZ
76
77// the spacing between the lines (in report mode)
b54e41c5 78static const int LINE_SPACING = 0;
cf1dfa6b
VZ
79
80// extra margins around the text label
ccdbdc89
RR
81#ifdef __WXGTK__
82static const int EXTRA_WIDTH = 6;
83#else
ae7cbd1a 84static const int EXTRA_WIDTH = 4;
ccdbdc89 85#endif
43cb7161
RR
86
87#ifdef __WXGTK__
88static const int EXTRA_HEIGHT = 6;
89#else
cf1dfa6b 90static const int EXTRA_HEIGHT = 4;
43cb7161 91#endif
cf1dfa6b 92
13602ebd
VZ
93// margin between the window and the items
94static const int EXTRA_BORDER_X = 2;
95static const int EXTRA_BORDER_Y = 2;
96
cf1dfa6b 97// offset for the header window
36a03ed8
RR
98static const int HEADER_OFFSET_X = 0;
99static const int HEADER_OFFSET_Y = 0;
cf1dfa6b 100
13602ebd
VZ
101// margin between rows of icons in [small] icon view
102static const int MARGIN_BETWEEN_ROWS = 6;
103
cf1dfa6b
VZ
104// when autosizing the columns, add some slack
105static const int AUTOSIZE_COL_MARGIN = 10;
106
98cb8dcb 107// default width for the header columns
cf1dfa6b 108static const int WIDTH_COL_DEFAULT = 80;
cf1dfa6b 109
06b781c7
VZ
110// the space between the image and the text in the report mode
111static const int IMAGE_MARGIN_IN_REPORT_MODE = 5;
112
936632d3
VZ
113// the space between the image and the text in the report mode in header
114static const int HEADER_IMAGE_MARGIN_IN_REPORT_MODE = 2;
115
efbb7287 116
cf1dfa6b 117
ad486020
FM
118// ----------------------------------------------------------------------------
119// arrays/list implementations
120// ----------------------------------------------------------------------------
efbb7287 121
2c1f73ee 122#include "wx/listimpl.cpp"
17a1ebd1 123WX_DEFINE_LIST(wxListItemDataList)
2c1f73ee 124
f6bcfd97 125#include "wx/arrimpl.cpp"
17a1ebd1 126WX_DEFINE_OBJARRAY(wxListLineDataArray)
f6bcfd97 127
24b9f055 128#include "wx/listimpl.cpp"
17a1ebd1 129WX_DEFINE_LIST(wxListHeaderDataList)
24b9f055 130
efbb7287 131
ad486020
FM
132// ----------------------------------------------------------------------------
133// wxListItemData
134// ----------------------------------------------------------------------------
c801d85f 135
850ed6e7
VZ
136wxListItemData::~wxListItemData()
137{
138 // in the virtual list control the attributes are managed by the main
139 // program, so don't delete them
140 if ( !m_owner->IsVirtual() )
850ed6e7 141 delete m_attr;
850ed6e7
VZ
142
143 delete m_rect;
144}
145
cf1dfa6b 146void wxListItemData::Init()
c801d85f 147{
92976ab6
RR
148 m_image = -1;
149 m_data = 0;
cf1dfa6b 150
0530737d 151 m_attr = NULL;
e1e955e1 152}
c801d85f 153
cf1dfa6b 154wxListItemData::wxListItemData(wxListMainWindow *owner)
c801d85f 155{
cf1dfa6b 156 Init();
0530737d 157
cf1dfa6b
VZ
158 m_owner = owner;
159
850ed6e7 160 if ( owner->InReportView() )
cf1dfa6b 161 m_rect = NULL;
cf1dfa6b 162 else
cf1dfa6b 163 m_rect = new wxRect;
e1e955e1 164}
c801d85f
KB
165
166void wxListItemData::SetItem( const wxListItem &info )
167{
cf1dfa6b 168 if ( info.m_mask & wxLIST_MASK_TEXT )
54442116 169 SetText(info.m_text);
cf1dfa6b 170 if ( info.m_mask & wxLIST_MASK_IMAGE )
54442116 171 m_image = info.m_image;
cf1dfa6b 172 if ( info.m_mask & wxLIST_MASK_DATA )
54442116 173 m_data = info.m_data;
0530737d
VZ
174
175 if ( info.HasAttributes() )
176 {
177 if ( m_attr )
c18fa7a4 178 m_attr->AssignFrom(*info.GetAttributes());
0530737d
VZ
179 else
180 m_attr = new wxListItemAttr(*info.GetAttributes());
181 }
182
cf1dfa6b
VZ
183 if ( m_rect )
184 {
185 m_rect->x =
186 m_rect->y =
187 m_rect->height = 0;
188 m_rect->width = info.m_width;
189 }
e1e955e1 190}
c801d85f 191
debe6624 192void wxListItemData::SetPosition( int x, int y )
c801d85f 193{
cf1dfa6b
VZ
194 wxCHECK_RET( m_rect, _T("unexpected SetPosition() call") );
195
196 m_rect->x = x;
197 m_rect->y = y;
e1e955e1 198}
c801d85f 199
1e6d9499 200void wxListItemData::SetSize( int width, int height )
c801d85f 201{
cf1dfa6b 202 wxCHECK_RET( m_rect, _T("unexpected SetSize() call") );
c801d85f 203
cf1dfa6b
VZ
204 if ( width != -1 )
205 m_rect->width = width;
206 if ( height != -1 )
207 m_rect->height = height;
e1e955e1 208}
c801d85f 209
debe6624 210bool wxListItemData::IsHit( int x, int y ) const
c801d85f 211{
ca65c044 212 wxCHECK_MSG( m_rect, false, _T("can't be called in this mode") );
cf1dfa6b 213
22a35096 214 return wxRect(GetX(), GetY(), GetWidth(), GetHeight()).Contains(x, y);
e1e955e1 215}
c801d85f 216
fd9811b1 217int wxListItemData::GetX() const
c801d85f 218{
cf1dfa6b
VZ
219 wxCHECK_MSG( m_rect, 0, _T("can't be called in this mode") );
220
221 return m_rect->x;
e1e955e1 222}
c801d85f 223
fd9811b1 224int wxListItemData::GetY() const
c801d85f 225{
cf1dfa6b
VZ
226 wxCHECK_MSG( m_rect, 0, _T("can't be called in this mode") );
227
228 return m_rect->y;
e1e955e1 229}
c801d85f 230
fd9811b1 231int wxListItemData::GetWidth() const
c801d85f 232{
cf1dfa6b
VZ
233 wxCHECK_MSG( m_rect, 0, _T("can't be called in this mode") );
234
235 return m_rect->width;
e1e955e1 236}
c801d85f 237
fd9811b1 238int wxListItemData::GetHeight() const
c801d85f 239{
cf1dfa6b 240 wxCHECK_MSG( m_rect, 0, _T("can't be called in this mode") );
c801d85f 241
cf1dfa6b 242 return m_rect->height;
e1e955e1 243}
c801d85f 244
0530737d 245void wxListItemData::GetItem( wxListItem &info ) const
c801d85f 246{
39a7f085
VZ
247 long mask = info.m_mask;
248 if ( !mask )
39a7f085
VZ
249 // by default, get everything for backwards compatibility
250 mask = -1;
39a7f085
VZ
251
252 if ( mask & wxLIST_MASK_TEXT )
253 info.m_text = m_text;
254 if ( mask & wxLIST_MASK_IMAGE )
255 info.m_image = m_image;
256 if ( mask & wxLIST_MASK_DATA )
257 info.m_data = m_data;
c801d85f 258
0530737d
VZ
259 if ( m_attr )
260 {
261 if ( m_attr->HasTextColour() )
262 info.SetTextColour(m_attr->GetTextColour());
263 if ( m_attr->HasBackgroundColour() )
264 info.SetBackgroundColour(m_attr->GetBackgroundColour());
265 if ( m_attr->HasFont() )
266 info.SetFont(m_attr->GetFont());
267 }
e1e955e1 268}
c801d85f
KB
269
270//-----------------------------------------------------------------------------
271// wxListHeaderData
272//-----------------------------------------------------------------------------
273
0a816d95 274void wxListHeaderData::Init()
c801d85f 275{
92976ab6 276 m_mask = 0;
0a816d95 277 m_image = -1;
92976ab6
RR
278 m_format = 0;
279 m_width = 0;
280 m_xpos = 0;
281 m_ypos = 0;
282 m_height = 0;
df0edf44 283 m_state = 0;
e1e955e1 284}
c801d85f 285
0a816d95
VZ
286wxListHeaderData::wxListHeaderData()
287{
288 Init();
289}
290
c801d85f
KB
291wxListHeaderData::wxListHeaderData( const wxListItem &item )
292{
0a816d95
VZ
293 Init();
294
92976ab6 295 SetItem( item );
e1e955e1 296}
c801d85f
KB
297
298void wxListHeaderData::SetItem( const wxListItem &item )
299{
92976ab6 300 m_mask = item.m_mask;
cf1dfa6b 301
0a816d95
VZ
302 if ( m_mask & wxLIST_MASK_TEXT )
303 m_text = item.m_text;
304
305 if ( m_mask & wxLIST_MASK_IMAGE )
306 m_image = item.m_image;
307
308 if ( m_mask & wxLIST_MASK_FORMAT )
309 m_format = item.m_format;
310
311 if ( m_mask & wxLIST_MASK_WIDTH )
312 SetWidth(item.m_width);
6fef2483 313
df0edf44
KO
314 if ( m_mask & wxLIST_MASK_STATE )
315 SetState(item.m_state);
e1e955e1 316}
c801d85f 317
debe6624 318void wxListHeaderData::SetPosition( int x, int y )
c801d85f 319{
92976ab6
RR
320 m_xpos = x;
321 m_ypos = y;
e1e955e1 322}
c801d85f 323
debe6624 324void wxListHeaderData::SetHeight( int h )
c801d85f 325{
92976ab6 326 m_height = h;
e1e955e1 327}
c801d85f 328
debe6624 329void wxListHeaderData::SetWidth( int w )
c801d85f 330{
98cb8dcb 331 m_width = w < 0 ? WIDTH_COL_DEFAULT : w;
e1e955e1 332}
c801d85f 333
df0edf44
KO
334void wxListHeaderData::SetState( int flag )
335{
336 m_state = flag;
337}
338
debe6624 339void wxListHeaderData::SetFormat( int format )
c801d85f 340{
92976ab6 341 m_format = format;
e1e955e1 342}
c801d85f 343
fd9811b1 344bool wxListHeaderData::HasImage() const
c801d85f 345{
0a816d95 346 return m_image != -1;
e1e955e1 347}
c801d85f 348
c801d85f
KB
349bool wxListHeaderData::IsHit( int x, int y ) const
350{
92976ab6 351 return ((x >= m_xpos) && (x <= m_xpos+m_width) && (y >= m_ypos) && (y <= m_ypos+m_height));
e1e955e1 352}
c801d85f 353
0a816d95 354void wxListHeaderData::GetItem( wxListItem& item )
c801d85f 355{
92976ab6
RR
356 item.m_mask = m_mask;
357 item.m_text = m_text;
358 item.m_image = m_image;
359 item.m_format = m_format;
360 item.m_width = m_width;
df0edf44 361 item.m_state = m_state;
e1e955e1 362}
c801d85f 363
fd9811b1 364int wxListHeaderData::GetImage() const
c801d85f 365{
92976ab6 366 return m_image;
e1e955e1 367}
c801d85f 368
fd9811b1 369int wxListHeaderData::GetWidth() const
c801d85f 370{
92976ab6 371 return m_width;
e1e955e1 372}
c801d85f 373
fd9811b1 374int wxListHeaderData::GetFormat() const
c801d85f 375{
92976ab6 376 return m_format;
e1e955e1 377}
c801d85f 378
df0edf44
KO
379int wxListHeaderData::GetState() const
380{
381 return m_state;
382}
383
c801d85f
KB
384//-----------------------------------------------------------------------------
385// wxListLineData
386//-----------------------------------------------------------------------------
387
cf1dfa6b
VZ
388inline int wxListLineData::GetMode() const
389{
b54e41c5 390 return m_owner->GetListCtrl()->GetWindowStyleFlag() & wxLC_MASK_TYPE;
cf1dfa6b 391}
c801d85f 392
cf1dfa6b 393inline bool wxListLineData::InReportView() const
c801d85f 394{
cf1dfa6b 395 return m_owner->HasFlag(wxLC_REPORT);
e1e955e1 396}
c801d85f 397
b54e41c5 398inline bool wxListLineData::IsVirtual() const
c801d85f 399{
cf1dfa6b
VZ
400 return m_owner->IsVirtual();
401}
2c1f73ee 402
5cd89174 403wxListLineData::wxListLineData( wxListMainWindow *owner )
cf1dfa6b
VZ
404{
405 m_owner = owner;
2c1f73ee 406
cf1dfa6b 407 if ( InReportView() )
cf1dfa6b 408 m_gi = NULL;
cf1dfa6b 409 else // !report
cf1dfa6b 410 m_gi = new GeometryInfo;
f6bcfd97 411
ca65c044 412 m_highlighted = false;
f6bcfd97 413
cf1dfa6b
VZ
414 InitItems( GetMode() == wxLC_REPORT ? m_owner->GetColumnCount() : 1 );
415}
f6bcfd97 416
cf1dfa6b
VZ
417void wxListLineData::CalculateSize( wxDC *dc, int spacing )
418{
222ed1d6 419 wxListItemDataList::compatibility_iterator node = m_items.GetFirst();
cf1dfa6b
VZ
420 wxCHECK_RET( node, _T("no subitems at all??") );
421
422 wxListItemData *item = node->GetData();
423
94dd23ae
VZ
424 wxString s;
425 wxCoord lw, lh;
426
cf1dfa6b
VZ
427 switch ( GetMode() )
428 {
429 case wxLC_ICON:
430 case wxLC_SMALL_ICON:
94dd23ae 431 m_gi->m_rectAll.width = spacing;
cf1dfa6b 432
94dd23ae 433 s = item->GetText();
cf1dfa6b 434
94dd23ae
VZ
435 if ( s.empty() )
436 {
437 lh =
438 m_gi->m_rectLabel.width =
439 m_gi->m_rectLabel.height = 0;
92976ab6 440 }
94dd23ae 441 else // has label
92976ab6 442 {
92976ab6 443 dc->GetTextExtent( s, &lw, &lh );
cf1dfa6b
VZ
444 lw += EXTRA_WIDTH;
445 lh += EXTRA_HEIGHT;
2c1f73ee 446
94dd23ae
VZ
447 m_gi->m_rectAll.height = spacing + lh;
448 if (lw > spacing)
449 m_gi->m_rectAll.width = lw;
450
cf1dfa6b
VZ
451 m_gi->m_rectLabel.width = lw;
452 m_gi->m_rectLabel.height = lh;
94dd23ae 453 }
f6bcfd97 454
94dd23ae
VZ
455 if (item->HasImage())
456 {
457 int w, h;
458 m_owner->GetImageSize( item->GetImage(), w, h );
459 m_gi->m_rectIcon.width = w + 8;
460 m_gi->m_rectIcon.height = h + 8;
461
462 if ( m_gi->m_rectIcon.width > m_gi->m_rectAll.width )
463 m_gi->m_rectAll.width = m_gi->m_rectIcon.width;
464 if ( m_gi->m_rectIcon.height + lh > m_gi->m_rectAll.height - 4 )
465 m_gi->m_rectAll.height = m_gi->m_rectIcon.height + lh + 4;
466 }
f6bcfd97 467
94dd23ae
VZ
468 if ( item->HasText() )
469 {
470 m_gi->m_rectHighlight.width = m_gi->m_rectLabel.width;
471 m_gi->m_rectHighlight.height = m_gi->m_rectLabel.height;
472 }
473 else // no text, highlight the icon
474 {
475 m_gi->m_rectHighlight.width = m_gi->m_rectIcon.width;
476 m_gi->m_rectHighlight.height = m_gi->m_rectIcon.height;
477 }
478 break;
479
480 case wxLC_LIST:
481 s = item->GetTextForMeasuring();
482
483 dc->GetTextExtent( s, &lw, &lh );
94dd23ae
VZ
484 lw += EXTRA_WIDTH;
485 lh += EXTRA_HEIGHT;
486
487 m_gi->m_rectLabel.width = lw;
488 m_gi->m_rectLabel.height = lh;
489
490 m_gi->m_rectAll.width = lw;
491 m_gi->m_rectAll.height = lh;
f6bcfd97 492
94dd23ae
VZ
493 if (item->HasImage())
494 {
495 int w, h;
496 m_owner->GetImageSize( item->GetImage(), w, h );
497 m_gi->m_rectIcon.width = w;
498 m_gi->m_rectIcon.height = h;
499
500 m_gi->m_rectAll.width += 4 + w;
501 if (h > m_gi->m_rectAll.height)
502 m_gi->m_rectAll.height = h;
92976ab6 503 }
94dd23ae
VZ
504
505 m_gi->m_rectHighlight.width = m_gi->m_rectAll.width;
506 m_gi->m_rectHighlight.height = m_gi->m_rectAll.height;
92976ab6 507 break;
2c1f73ee 508
cf1dfa6b
VZ
509 case wxLC_REPORT:
510 wxFAIL_MSG( _T("unexpected call to SetSize") );
92976ab6 511 break;
cf1dfa6b
VZ
512
513 default:
514 wxFAIL_MSG( _T("unknown mode") );
277ea1b4 515 break;
e1e955e1 516 }
e1e955e1 517}
c801d85f 518
13602ebd 519void wxListLineData::SetPosition( int x, int y, int spacing )
c801d85f 520{
222ed1d6 521 wxListItemDataList::compatibility_iterator node = m_items.GetFirst();
cf1dfa6b 522 wxCHECK_RET( node, _T("no subitems at all??") );
2c1f73ee 523
cf1dfa6b 524 wxListItemData *item = node->GetData();
2c1f73ee 525
cf1dfa6b 526 switch ( GetMode() )
0b855868
RR
527 {
528 case wxLC_ICON:
cf1dfa6b
VZ
529 case wxLC_SMALL_ICON:
530 m_gi->m_rectAll.x = x;
531 m_gi->m_rectAll.y = y;
532
533 if ( item->HasImage() )
0b855868 534 {
c2569f41
VZ
535 m_gi->m_rectIcon.x = m_gi->m_rectAll.x + 4 +
536 (m_gi->m_rectAll.width - m_gi->m_rectIcon.width) / 2;
cf1dfa6b 537 m_gi->m_rectIcon.y = m_gi->m_rectAll.y + 4;
0b855868 538 }
cf1dfa6b
VZ
539
540 if ( item->HasText() )
0b855868 541 {
cf1dfa6b 542 if (m_gi->m_rectAll.width > spacing)
ccdbdc89 543 m_gi->m_rectLabel.x = m_gi->m_rectAll.x + (EXTRA_WIDTH/2);
5d25c050 544 else
ccdbdc89 545 m_gi->m_rectLabel.x = m_gi->m_rectAll.x + (EXTRA_WIDTH/2) + (spacing / 2) - (m_gi->m_rectLabel.width / 2);
cf1dfa6b 546 m_gi->m_rectLabel.y = m_gi->m_rectAll.y + m_gi->m_rectAll.height + 2 - m_gi->m_rectLabel.height;
b54e41c5
VZ
547 m_gi->m_rectHighlight.x = m_gi->m_rectLabel.x - 2;
548 m_gi->m_rectHighlight.y = m_gi->m_rectLabel.y - 2;
bffa1c77 549 }
cf1dfa6b 550 else // no text, highlight the icon
0b855868 551 {
b54e41c5
VZ
552 m_gi->m_rectHighlight.x = m_gi->m_rectIcon.x - 4;
553 m_gi->m_rectHighlight.y = m_gi->m_rectIcon.y - 4;
bffa1c77 554 }
0b855868 555 break;
c801d85f 556
cf1dfa6b
VZ
557 case wxLC_LIST:
558 m_gi->m_rectAll.x = x;
559 m_gi->m_rectAll.y = y;
c801d85f 560
b54e41c5
VZ
561 m_gi->m_rectHighlight.x = m_gi->m_rectAll.x;
562 m_gi->m_rectHighlight.y = m_gi->m_rectAll.y;
cf1dfa6b 563 m_gi->m_rectLabel.y = m_gi->m_rectAll.y + 2;
c801d85f 564
cf1dfa6b
VZ
565 if (item->HasImage())
566 {
567 m_gi->m_rectIcon.x = m_gi->m_rectAll.x + 2;
568 m_gi->m_rectIcon.y = m_gi->m_rectAll.y + 2;
ccdbdc89 569 m_gi->m_rectLabel.x = m_gi->m_rectAll.x + 4 + (EXTRA_WIDTH/2) + m_gi->m_rectIcon.width;
cf1dfa6b
VZ
570 }
571 else
572 {
ccdbdc89 573 m_gi->m_rectLabel.x = m_gi->m_rectAll.x + (EXTRA_WIDTH/2);
cf1dfa6b
VZ
574 }
575 break;
c801d85f 576
cf1dfa6b
VZ
577 case wxLC_REPORT:
578 wxFAIL_MSG( _T("unexpected call to SetPosition") );
579 break;
c801d85f 580
cf1dfa6b
VZ
581 default:
582 wxFAIL_MSG( _T("unknown mode") );
277ea1b4 583 break;
cf1dfa6b 584 }
e1e955e1 585}
c801d85f 586
debe6624 587void wxListLineData::InitItems( int num )
c801d85f 588{
2c1f73ee 589 for (int i = 0; i < num; i++)
cf1dfa6b 590 m_items.Append( new wxListItemData(m_owner) );
e1e955e1 591}
c801d85f 592
debe6624 593void wxListLineData::SetItem( int index, const wxListItem &info )
c801d85f 594{
222ed1d6 595 wxListItemDataList::compatibility_iterator node = m_items.Item( index );
1370703e
VZ
596 wxCHECK_RET( node, _T("invalid column index in SetItem") );
597
598 wxListItemData *item = node->GetData();
599 item->SetItem( info );
e1e955e1 600}
c801d85f 601
1e6d9499 602void wxListLineData::GetItem( int index, wxListItem &info )
c801d85f 603{
222ed1d6 604 wxListItemDataList::compatibility_iterator node = m_items.Item( index );
139adb6a
RR
605 if (node)
606 {
2c1f73ee 607 wxListItemData *item = node->GetData();
139adb6a
RR
608 item->GetItem( info );
609 }
e1e955e1 610}
c801d85f 611
54442116 612wxString wxListLineData::GetText(int index) const
c801d85f 613{
54442116
VZ
614 wxString s;
615
222ed1d6 616 wxListItemDataList::compatibility_iterator node = m_items.Item( index );
139adb6a
RR
617 if (node)
618 {
2c1f73ee 619 wxListItemData *item = node->GetData();
54442116 620 s = item->GetText();
139adb6a 621 }
54442116
VZ
622
623 return s;
e1e955e1 624}
c801d85f 625
fbfb8bcc 626void wxListLineData::SetText( int index, const wxString& s )
c801d85f 627{
222ed1d6 628 wxListItemDataList::compatibility_iterator node = m_items.Item( index );
139adb6a
RR
629 if (node)
630 {
2c1f73ee 631 wxListItemData *item = node->GetData();
139adb6a
RR
632 item->SetText( s );
633 }
e1e955e1 634}
c801d85f 635
cf1dfa6b 636void wxListLineData::SetImage( int index, int image )
c801d85f 637{
222ed1d6 638 wxListItemDataList::compatibility_iterator node = m_items.Item( index );
cf1dfa6b
VZ
639 wxCHECK_RET( node, _T("invalid column index in SetImage()") );
640
641 wxListItemData *item = node->GetData();
642 item->SetImage(image);
643}
644
645int wxListLineData::GetImage( int index ) const
646{
222ed1d6 647 wxListItemDataList::compatibility_iterator node = m_items.Item( index );
cf1dfa6b
VZ
648 wxCHECK_MSG( node, -1, _T("invalid column index in GetImage()") );
649
650 wxListItemData *item = node->GetData();
651 return item->GetImage();
e1e955e1 652}
c801d85f 653
6c02c329
VZ
654wxListItemAttr *wxListLineData::GetAttr() const
655{
222ed1d6 656 wxListItemDataList::compatibility_iterator node = m_items.GetFirst();
6c02c329
VZ
657 wxCHECK_MSG( node, NULL, _T("invalid column index in GetAttr()") );
658
659 wxListItemData *item = node->GetData();
660 return item->GetAttr();
661}
662
663void wxListLineData::SetAttr(wxListItemAttr *attr)
664{
222ed1d6 665 wxListItemDataList::compatibility_iterator node = m_items.GetFirst();
6c02c329
VZ
666 wxCHECK_RET( node, _T("invalid column index in SetAttr()") );
667
668 wxListItemData *item = node->GetData();
669 item->SetAttr(attr);
670}
671
0e980f91 672bool wxListLineData::SetAttributes(wxDC *dc,
0530737d 673 const wxListItemAttr *attr,
0e980f91 674 bool highlighted)
0530737d 675{
0e980f91
VZ
676 wxWindow *listctrl = m_owner->GetParent();
677
678 // fg colour
679
680 // don't use foreground colour for drawing highlighted items - this might
470caaf9
VZ
681 // make them completely invisible (and there is no way to do bit
682 // arithmetics on wxColour, unfortunately)
0e980f91
VZ
683 wxColour colText;
684 if ( highlighted )
4b8fa634 685#ifdef __WXMAC__
d6d8b172 686 {
ed9a7a63 687 if (m_owner->HasFocus()
569bb120 688#if !defined(__WXUNIVERSAL__) && wxOSX_USE_CARBON
ed9a7a63
KO
689 && IsControlActive( (ControlRef)m_owner->GetHandle() )
690#endif
691 )
d6d8b172
KO
692 colText = *wxWHITE;
693 else
694 colText = *wxBLACK;
695 }
4b8fa634 696#else
a756f210 697 colText = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT);
4b8fa634 698#endif
277ea1b4
DS
699 else if ( attr && attr->HasTextColour() )
700 colText = attr->GetTextColour();
0530737d 701 else
277ea1b4 702 colText = listctrl->GetForegroundColour();
0530737d 703
0e980f91
VZ
704 dc->SetTextForeground(colText);
705
706 // font
707 wxFont font;
0530737d 708 if ( attr && attr->HasFont() )
0e980f91 709 font = attr->GetFont();
0530737d 710 else
0e980f91 711 font = listctrl->GetFont();
0e980f91
VZ
712
713 dc->SetFont(font);
714
715 // bg colour
716 bool hasBgCol = attr && attr->HasBackgroundColour();
717 if ( highlighted || hasBgCol )
718 {
719 if ( highlighted )
49ecb029 720 dc->SetBrush( *m_owner->GetHighlightBrush() );
0e980f91 721 else
04ee05f9 722 dc->SetBrush(wxBrush(attr->GetBackgroundColour(), wxBRUSHSTYLE_SOLID));
0e980f91
VZ
723
724 dc->SetPen( *wxTRANSPARENT_PEN );
725
ca65c044 726 return true;
0e980f91
VZ
727 }
728
ca65c044 729 return false;
0530737d
VZ
730}
731
5cd89174
VZ
732void wxListLineData::Draw( wxDC *dc )
733{
222ed1d6 734 wxListItemDataList::compatibility_iterator node = m_items.GetFirst();
5cd89174
VZ
735 wxCHECK_RET( node, _T("no subitems at all??") );
736
0e980f91
VZ
737 bool highlighted = IsHighlighted();
738
739 wxListItemAttr *attr = GetAttr();
740
741 if ( SetAttributes(dc, attr, highlighted) )
df0edf44 742#if ( !defined(__WXGTK20__) && !defined(__WXMAC__) )
ccdbdc89 743 {
0e980f91 744 dc->DrawRectangle( m_gi->m_rectHighlight );
ccdbdc89
RR
745 }
746#else
747 {
748 if (highlighted)
749 {
05d97538 750 int flags = wxCONTROL_SELECTED;
ed9a7a63 751 if (m_owner->HasFocus()
569bb120 752#if defined( __WXMAC__ ) && !defined(__WXUNIVERSAL__) && wxOSX_USE_CARBON
ed9a7a63
KO
753 && IsControlActive( (ControlRef)m_owner->GetHandle() )
754#endif
755 )
05d97538
RR
756 flags |= wxCONTROL_FOCUSED;
757 wxRendererNative::Get().DrawItemSelectionRect( m_owner, *dc, m_gi->m_rectHighlight, flags );
6fef2483 758
ccdbdc89
RR
759 }
760 else
761 {
762 dc->DrawRectangle( m_gi->m_rectHighlight );
763 }
764 }
765#endif
0e980f91 766
94dd23ae
VZ
767 // just for debugging to better see where the items are
768#if 0
769 dc->SetPen(*wxRED_PEN);
770 dc->SetBrush(*wxTRANSPARENT_BRUSH);
771 dc->DrawRectangle( m_gi->m_rectAll );
772 dc->SetPen(*wxGREEN_PEN);
773 dc->DrawRectangle( m_gi->m_rectIcon );
277ea1b4 774#endif
94dd23ae 775
5cd89174
VZ
776 wxListItemData *item = node->GetData();
777 if (item->HasImage())
778 {
94dd23ae
VZ
779 // centre the image inside our rectangle, this looks nicer when items
780 // ae aligned in a row
781 const wxRect& rectIcon = m_gi->m_rectIcon;
782
783 m_owner->DrawImage(item->GetImage(), dc, rectIcon.x, rectIcon.y);
5cd89174
VZ
784 }
785
786 if (item->HasText())
787 {
94dd23ae 788 const wxRect& rectLabel = m_gi->m_rectLabel;
06b781c7
VZ
789
790 wxDCClipper clipper(*dc, rectLabel);
94dd23ae 791 dc->DrawText(item->GetText(), rectLabel.x, rectLabel.y);
5cd89174
VZ
792 }
793}
794
795void wxListLineData::DrawInReportMode( wxDC *dc,
938b652b 796 const wxRect& rect,
5cd89174 797 const wxRect& rectHL,
32fc355f
RR
798 bool highlighted,
799 bool current )
c801d85f 800{
6c02c329
VZ
801 // TODO: later we should support setting different attributes for
802 // different columns - to do it, just add "col" argument to
0e980f91 803 // GetAttr() and move these lines into the loop below
6c02c329 804 wxListItemAttr *attr = GetAttr();
0e980f91 805 if ( SetAttributes(dc, attr, highlighted) )
df0edf44 806#if ( !defined(__WXGTK20__) && !defined(__WXMAC__) )
ccdbdc89 807 {
5cd89174 808 dc->DrawRectangle( rectHL );
5d55031c
VZ
809
810 wxUnusedVar(current);
ccdbdc89
RR
811 }
812#else
813 {
814 if (highlighted)
815 {
05d97538 816 int flags = wxCONTROL_SELECTED;
ce0cf2b8 817 if (m_owner->HasFocus())
05d97538 818 flags |= wxCONTROL_FOCUSED;
32fc355f
RR
819 if (current)
820 flags |= wxCONTROL_CURRENT;
05d97538 821 wxRendererNative::Get().DrawItemSelectionRect( m_owner, *dc, rectHL, flags );
ccdbdc89
RR
822 }
823 else
824 {
825 dc->DrawRectangle( rectHL );
826 }
827 }
828#endif
004fd0c8 829
938b652b 830 wxCoord x = rect.x + HEADER_OFFSET_X,
ebadbb76 831 yMid = rect.y + rect.height/2;
ccdbdc89
RR
832#ifdef __WXGTK__
833 // This probably needs to be done
834 // on all platforms as the icons
835 // otherwise nearly touch the border
836 x += 2;
837#endif
cf1dfa6b 838
904ccf52 839 size_t col = 0;
222ed1d6 840 for ( wxListItemDataList::compatibility_iterator node = m_items.GetFirst();
904ccf52
VZ
841 node;
842 node = node->GetNext(), col++ )
5cd89174
VZ
843 {
844 wxListItemData *item = node->GetData();
cf1dfa6b 845
904ccf52 846 int width = m_owner->GetColumnWidth(col);
5cd89174 847 int xOld = x;
06b781c7 848 x += width;
cf1dfa6b 849
f9f37ee2
VZ
850 const int wText = width - 8;
851 wxDCClipper clipper(*dc, xOld, rect.y, wText, rect.height);
852
5cd89174
VZ
853 if ( item->HasImage() )
854 {
855 int ix, iy;
5cd89174 856 m_owner->GetImageSize( item->GetImage(), ix, iy );
ebadbb76 857 m_owner->DrawImage( item->GetImage(), dc, xOld, yMid - iy/2 );
cf1dfa6b 858
06b781c7 859 ix += IMAGE_MARGIN_IN_REPORT_MODE;
cf1dfa6b 860
06b781c7
VZ
861 xOld += ix;
862 width -= ix;
863 }
864
5cd89174 865 if ( item->HasText() )
f9f37ee2 866 DrawTextFormatted(dc, item->GetText(), col, xOld, yMid, wText);
2b5f62a0
VZ
867 }
868}
869
870void wxListLineData::DrawTextFormatted(wxDC *dc,
359fb29e 871 const wxString& textOrig,
2b5f62a0
VZ
872 int col,
873 int x,
ebadbb76 874 int yMid,
2b5f62a0
VZ
875 int width)
876{
359fb29e
VZ
877 // we don't support displaying multiple lines currently (and neither does
878 // wxMSW FWIW) so just merge all the lines
879 wxString text(textOrig);
880 text.Replace(_T("\n"), _T(" "));
881
ebadbb76
VZ
882 wxCoord w, h;
883 dc->GetTextExtent(text, &w, &h);
884
885 const wxCoord y = yMid - (h + 1)/2;
886
887 wxDCClipper clipper(*dc, x, y, width, h);
2b5f62a0
VZ
888
889 // determine if the string can fit inside the current width
2b5f62a0
VZ
890 if (w <= width)
891 {
e1e1272f 892 // it can, draw it using the items alignment
ebadbb76 893 wxListItem item;
2b5f62a0 894 m_owner->GetColumn(col, item);
e1e1272f
VZ
895 switch ( item.GetAlign() )
896 {
e1e1272f
VZ
897 case wxLIST_FORMAT_LEFT:
898 // nothing to do
899 break;
900
901 case wxLIST_FORMAT_RIGHT:
902 x += width - w;
903 break;
904
905 case wxLIST_FORMAT_CENTER:
906 x += (width - w) / 2;
907 break;
277ea1b4
DS
908
909 default:
910 wxFAIL_MSG( _T("unknown list item format") );
911 break;
e1e1272f
VZ
912 }
913
914 dc->DrawText(text, x, y);
2b5f62a0
VZ
915 }
916 else // otherwise, truncate and add an ellipsis if possible
917 {
918 // determine the base width
ebadbb76
VZ
919 wxString ellipsis(wxT("..."));
920 wxCoord base_w;
2b5f62a0
VZ
921 dc->GetTextExtent(ellipsis, &base_w, &h);
922
923 // continue until we have enough space or only one character left
5175dbbd 924 wxCoord w_c, h_c;
faa94f3e 925 size_t len = text.length();
ebadbb76 926 wxString drawntext = text.Left(len);
5175dbbd 927 while (len > 1)
2b5f62a0 928 {
5175dbbd
VS
929 dc->GetTextExtent(drawntext.Last(), &w_c, &h_c);
930 drawntext.RemoveLast();
931 len--;
932 w -= w_c;
2b5f62a0
VZ
933 if (w + base_w <= width)
934 break;
2b5f62a0
VZ
935 }
936
937 // if still not enough space, remove ellipsis characters
faa94f3e 938 while (ellipsis.length() > 0 && w + base_w > width)
2b5f62a0 939 {
faa94f3e 940 ellipsis = ellipsis.Left(ellipsis.length() - 1);
2b5f62a0 941 dc->GetTextExtent(ellipsis, &base_w, &h);
5cd89174 942 }
2b5f62a0
VZ
943
944 // now draw the text
945 dc->DrawText(drawntext, x, y);
946 dc->DrawText(ellipsis, x + w, y);
e1e955e1 947 }
e1e955e1 948}
c801d85f 949
b54e41c5 950bool wxListLineData::Highlight( bool on )
c801d85f 951{
ca65c044 952 wxCHECK_MSG( !IsVirtual(), false, _T("unexpected call to Highlight") );
c801d85f 953
b54e41c5 954 if ( on == m_highlighted )
ca65c044 955 return false;
c801d85f 956
b54e41c5 957 m_highlighted = on;
c801d85f 958
ca65c044 959 return true;
e1e955e1 960}
c801d85f 961
b54e41c5 962void wxListLineData::ReverseHighlight( void )
c801d85f 963{
b54e41c5 964 Highlight(!IsHighlighted());
e1e955e1 965}
c801d85f
KB
966
967//-----------------------------------------------------------------------------
968// wxListHeaderWindow
969//-----------------------------------------------------------------------------
970
c801d85f 971BEGIN_EVENT_TABLE(wxListHeaderWindow,wxWindow)
63852e78
RR
972 EVT_PAINT (wxListHeaderWindow::OnPaint)
973 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse)
974 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus)
c801d85f
KB
975END_EVENT_TABLE()
976
0a816d95 977void wxListHeaderWindow::Init()
c801d85f 978{
d3b9f782 979 m_currentCursor = NULL;
ca65c044
WS
980 m_isDragging = false;
981 m_dirty = false;
06cd40a8 982 m_sendSetColumnWidth = false;
0a816d95
VZ
983}
984
985wxListHeaderWindow::wxListHeaderWindow()
986{
987 Init();
988
d3b9f782
VZ
989 m_owner = NULL;
990 m_resizeCursor = NULL;
e1e955e1 991}
c801d85f 992
0a816d95
VZ
993wxListHeaderWindow::wxListHeaderWindow( wxWindow *win,
994 wxWindowID id,
995 wxListMainWindow *owner,
996 const wxPoint& pos,
997 const wxSize& size,
998 long style,
999 const wxString &name )
1000 : wxWindow( win, id, pos, size, style, name )
c801d85f 1001{
0a816d95
VZ
1002 Init();
1003
63852e78 1004 m_owner = owner;
63852e78 1005 m_resizeCursor = new wxCursor( wxCURSOR_SIZEWE );
f6bcfd97 1006
35d4c967 1007#if _USE_VISATTR
ca65c044 1008 wxVisualAttributes attr = wxPanel::GetClassDefaultAttributes();
fa47d7a7
VS
1009 SetOwnForegroundColour( attr.colFg );
1010 SetOwnBackgroundColour( attr.colBg );
92a4e4de
VZ
1011 if (!m_hasFont)
1012 SetOwnFont( attr.font );
35d4c967 1013#else
fa47d7a7
VS
1014 SetOwnForegroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
1015 SetOwnBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE));
92a4e4de
VZ
1016 if (!m_hasFont)
1017 SetOwnFont( wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT ));
35d4c967 1018#endif
e1e955e1 1019}
c801d85f 1020
0a816d95 1021wxListHeaderWindow::~wxListHeaderWindow()
a367b9b3 1022{
63852e78 1023 delete m_resizeCursor;
a367b9b3
JS
1024}
1025
2b5f62a0
VZ
1026#ifdef __WXUNIVERSAL__
1027#include "wx/univ/renderer.h"
1028#include "wx/univ/theme.h"
1029#endif
1030
f6bcfd97
BP
1031// shift the DC origin to match the position of the main window horz
1032// scrollbar: this allows us to always use logical coords
1033void wxListHeaderWindow::AdjustDC(wxDC& dc)
1034{
06cd40a8
RR
1035 wxGenericListCtrl *parent = m_owner->GetListCtrl();
1036
f6bcfd97 1037 int xpix;
06cd40a8 1038 parent->GetScrollPixelsPerUnit( &xpix, NULL );
f6bcfd97 1039
5eefe029 1040 int view_start;
06cd40a8 1041 parent->GetViewStart( &view_start, NULL );
5eefe029 1042
5eefe029
RR
1043
1044 int org_x = 0;
1045 int org_y = 0;
1046 dc.GetDeviceOrigin( &org_x, &org_y );
f6bcfd97
BP
1047
1048 // account for the horz scrollbar offset
807a572e
RR
1049#ifdef __WXGTK__
1050 if (GetLayoutDirection() == wxLayout_RightToLeft)
1051 {
1052 // Maybe we just have to check for m_signX
1053 // in the DC, but I leave the #ifdef __WXGTK__
1054 // for now
1055 dc.SetDeviceOrigin( org_x + (view_start * xpix), org_y );
1056 }
1057 else
1058#endif
1059 dc.SetDeviceOrigin( org_x - (view_start * xpix), org_y );
f6bcfd97
BP
1060}
1061
c801d85f
KB
1062void wxListHeaderWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
1063{
06cd40a8 1064 wxGenericListCtrl *parent = m_owner->GetListCtrl();
7d7b3f69 1065
63852e78 1066 wxPaintDC dc( this );
10bd0724 1067
f6bcfd97 1068 AdjustDC( dc );
bffa1c77 1069
63852e78 1070 dc.SetFont( GetFont() );
bd8289c1 1071
f6bcfd97
BP
1072 // width and height of the entire header window
1073 int w, h;
63852e78 1074 GetClientSize( &w, &h );
06cd40a8 1075 parent->CalcUnscrolledPosition(w, 0, &w, NULL);
c801d85f 1076
04ee05f9 1077 dc.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT);
35d4c967 1078 dc.SetTextForeground(GetForegroundColour());
ca65c044 1079
cf1dfa6b 1080 int x = HEADER_OFFSET_X;
63852e78
RR
1081 int numColumns = m_owner->GetColumnCount();
1082 wxListItem item;
c5b7bb59 1083 for ( int i = 0; i < numColumns && x < w; i++ )
63852e78
RR
1084 {
1085 m_owner->GetColumn( i, item );
f6bcfd97 1086 int wCol = item.m_width;
f6bcfd97 1087
277ea1b4
DS
1088 int cw = wCol;
1089 int ch = h;
277ea1b4 1090
df0edf44
KO
1091 int flags = 0;
1092 if (!m_parent->IsEnabled())
1093 flags |= wxCONTROL_DISABLED;
1094
6fef2483 1095// NB: The code below is not really Mac-specific, but since we are close
df0edf44
KO
1096// to 2.8 release and I don't have time to test on other platforms, I
1097// defined this only for wxMac. If this behavior is desired on
1098// other platforms, please go ahead and revise or remove the #ifdef.
1099#ifdef __WXMAC__
6fef2483 1100 if ( !m_owner->IsVirtual() && (item.m_mask & wxLIST_MASK_STATE) &&
df0edf44
KO
1101 (item.m_state & wxLIST_STATE_SELECTED) )
1102 flags |= wxCONTROL_SELECTED;
1103#endif
1104
06cd40a8
RR
1105 if (i == 0)
1106 flags |= wxCONTROL_SPECIAL; // mark as first column
1107
9c7f49f5
VZ
1108 wxRendererNative::Get().DrawHeaderButton
1109 (
1110 this,
1111 dc,
d108f236 1112 wxRect(x, HEADER_OFFSET_Y, cw, ch),
df0edf44 1113 flags
9c7f49f5 1114 );
0a816d95 1115
e1e1272f
VZ
1116 // see if we have enough space for the column label
1117
1118 // for this we need the width of the text
1119 wxCoord wLabel;
ca65c044 1120 wxCoord hLabel;
cabeffb0 1121 dc.GetTextExtent(item.GetText(), &wLabel, &hLabel);
277ea1b4 1122 wLabel += 2 * EXTRA_WIDTH;
e1e1272f
VZ
1123
1124 // and the width of the icon, if any
277ea1b4 1125 int ix = 0, iy = 0; // init them just to suppress the compiler warnings
e1e1272f 1126 const int image = item.m_image;
8a3e173a 1127 wxImageList *imageList;
0a816d95
VZ
1128 if ( image != -1 )
1129 {
ad486020 1130 imageList = m_owner->GetSmallImageList();
0a816d95
VZ
1131 if ( imageList )
1132 {
0a816d95 1133 imageList->GetSize(image, ix, iy);
936632d3 1134 wLabel += ix + HEADER_IMAGE_MARGIN_IN_REPORT_MODE;
e1e1272f
VZ
1135 }
1136 }
1137 else
1138 {
1139 imageList = NULL;
1140 }
1141
1142 // ignore alignment if there is not enough space anyhow
1143 int xAligned;
1144 switch ( wLabel < cw ? item.GetAlign() : wxLIST_FORMAT_LEFT )
1145 {
1146 default:
1147 wxFAIL_MSG( _T("unknown list item format") );
1148 // fall through
0a816d95 1149
e1e1272f
VZ
1150 case wxLIST_FORMAT_LEFT:
1151 xAligned = x;
1152 break;
0a816d95 1153
e1e1272f
VZ
1154 case wxLIST_FORMAT_RIGHT:
1155 xAligned = x + cw - wLabel;
1156 break;
1157
1158 case wxLIST_FORMAT_CENTER:
1159 xAligned = x + (cw - wLabel) / 2;
1160 break;
1161 }
1162
936632d3
VZ
1163 // draw the text and image clipping them so that they
1164 // don't overwrite the column boundary
1165 wxDCClipper clipper(dc, x, HEADER_OFFSET_Y, cw, h - 4 );
1166
e1e1272f
VZ
1167 // if we have an image, draw it on the right of the label
1168 if ( imageList )
1169 {
1170 imageList->Draw
1171 (
1172 image,
1173 dc,
936632d3 1174 xAligned + wLabel - ix - HEADER_IMAGE_MARGIN_IN_REPORT_MODE,
e1e1272f
VZ
1175 HEADER_OFFSET_Y + (h - 4 - iy)/2,
1176 wxIMAGELIST_DRAW_TRANSPARENT
1177 );
0a816d95
VZ
1178 }
1179
06b781c7 1180 dc.DrawText( item.GetText(),
cabeffb0 1181 xAligned + EXTRA_WIDTH, h / 2 - hLabel / 2 ); //HEADER_OFFSET_Y + EXTRA_HEIGHT );
06b781c7 1182
0a816d95 1183 x += wCol;
63852e78 1184 }
4a5ed5bf
VZ
1185
1186 // Fill in what's missing to the right of the columns, otherwise we will
1187 // leave an unpainted area when columns are removed (and it looks better)
1188 if ( x < w )
1189 {
1190 wxRendererNative::Get().DrawHeaderButton
1191 (
1192 this,
1193 dc,
1194 wxRect(x, HEADER_OFFSET_Y, w - x, h),
06cd40a8 1195 wxCONTROL_DIRTY // mark as last column
4a5ed5bf
VZ
1196 );
1197 }
e1e955e1 1198}
c801d85f 1199
06cd40a8
RR
1200void wxListHeaderWindow::OnInternalIdle()
1201{
1202 wxWindow::OnInternalIdle();
7d7b3f69 1203
06cd40a8
RR
1204 if (m_sendSetColumnWidth)
1205 {
1206 m_owner->SetColumnWidth( m_colToSend, m_widthToSend );
1207 m_sendSetColumnWidth = false;
1208 }
1209}
1210
0208334d
RR
1211void wxListHeaderWindow::DrawCurrent()
1212{
b46ea782 1213#if 1
06cd40a8
RR
1214 // m_owner->SetColumnWidth( m_column, m_currentX - m_minX );
1215 m_sendSetColumnWidth = true;
1216 m_colToSend = m_column;
1217 m_widthToSend = m_currentX - m_minX;
b46ea782 1218#else
63852e78
RR
1219 int x1 = m_currentX;
1220 int y1 = 0;
f16ba4e6 1221 m_owner->ClientToScreen( &x1, &y1 );
f6bcfd97 1222
f16ba4e6 1223 int x2 = m_currentX;
63852e78 1224 int y2 = 0;
f6bcfd97 1225 m_owner->GetClientSize( NULL, &y2 );
63852e78 1226 m_owner->ClientToScreen( &x2, &y2 );
0208334d 1227
63852e78 1228 wxScreenDC dc;
3c679789 1229 dc.SetLogicalFunction( wxINVERT );
fd1dc2a7 1230 dc.SetPen( wxPen(*wxBLACK, 2) );
63852e78 1231 dc.SetBrush( *wxTRANSPARENT_BRUSH );
0208334d 1232
f6bcfd97
BP
1233 AdjustDC(dc);
1234
63852e78 1235 dc.DrawLine( x1, y1, x2, y2 );
0208334d 1236
63852e78 1237 dc.SetLogicalFunction( wxCOPY );
0208334d 1238
63852e78
RR
1239 dc.SetPen( wxNullPen );
1240 dc.SetBrush( wxNullBrush );
b46ea782 1241#endif
0208334d
RR
1242}
1243
c801d85f
KB
1244void wxListHeaderWindow::OnMouse( wxMouseEvent &event )
1245{
06cd40a8 1246 wxGenericListCtrl *parent = m_owner->GetListCtrl();
7d7b3f69 1247
f6bcfd97 1248 // we want to work with logical coords
3ca6a5f0 1249 int x;
06cd40a8 1250 parent->CalcUnscrolledPosition(event.GetX(), 0, &x, NULL);
3ca6a5f0 1251 int y = event.GetY();
f6bcfd97 1252
cfb50f14 1253 if (m_isDragging)
0208334d 1254 {
355f2407 1255 SendListEvent(wxEVT_COMMAND_LIST_COL_DRAGGING, event.GetPosition());
a77ec46d 1256
f6bcfd97
BP
1257 // we don't draw the line beyond our window, but we allow dragging it
1258 // there
1259 int w = 0;
1260 GetClientSize( &w, NULL );
06cd40a8 1261 parent->CalcUnscrolledPosition(w, 0, &w, NULL);
f6bcfd97
BP
1262 w -= 6;
1263
1264 // erase the line if it was drawn
1265 if ( m_currentX < w )
1266 DrawCurrent();
1267
63852e78
RR
1268 if (event.ButtonUp())
1269 {
1270 ReleaseMouse();
ca65c044
WS
1271 m_isDragging = false;
1272 m_dirty = true;
f6bcfd97 1273 m_owner->SetColumnWidth( m_column, m_currentX - m_minX );
355f2407 1274 SendListEvent(wxEVT_COMMAND_LIST_COL_END_DRAG, event.GetPosition());
63852e78
RR
1275 }
1276 else
1277 {
f6bcfd97 1278 if (x > m_minX + 7)
63852e78
RR
1279 m_currentX = x;
1280 else
f6bcfd97 1281 m_currentX = m_minX + 7;
bd8289c1 1282
f6bcfd97
BP
1283 // draw in the new location
1284 if ( m_currentX < w )
1285 DrawCurrent();
bffa1c77 1286 }
0208334d 1287 }
f6bcfd97 1288 else // not dragging
c801d85f 1289 {
f6bcfd97 1290 m_minX = 0;
ca65c044 1291 bool hit_border = false;
f6bcfd97
BP
1292
1293 // end of the current column
1294 int xpos = 0;
1295
3103e8a9 1296 // find the column where this event occurred
62313c27
VZ
1297 int col,
1298 countCol = m_owner->GetColumnCount();
1299 for (col = 0; col < countCol; col++)
bffa1c77 1300 {
cf1dfa6b
VZ
1301 xpos += m_owner->GetColumnWidth( col );
1302 m_column = col;
f6bcfd97
BP
1303
1304 if ( (abs(x-xpos) < 3) && (y < 22) )
1305 {
1306 // near the column border
ca65c044 1307 hit_border = true;
f6bcfd97
BP
1308 break;
1309 }
1310
1311 if ( x < xpos )
1312 {
1313 // inside the column
1314 break;
1315 }
1316
1317 m_minX = xpos;
bffa1c77 1318 }
63852e78 1319
62313c27
VZ
1320 if ( col == countCol )
1321 m_column = -1;
1322
11358d39 1323 if (event.LeftDown() || event.RightUp())
63852e78 1324 {
11358d39 1325 if (hit_border && event.LeftDown())
f6bcfd97 1326 {
355f2407
VZ
1327 if ( SendListEvent(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG,
1328 event.GetPosition()) )
1329 {
ca65c044 1330 m_isDragging = true;
355f2407 1331 m_currentX = x;
355f2407 1332 CaptureMouse();
03eccb83 1333 DrawCurrent();
355f2407
VZ
1334 }
1335 //else: column resizing was vetoed by the user code
f6bcfd97 1336 }
11358d39 1337 else // click on a column
f6bcfd97 1338 {
df0edf44
KO
1339 // record the selected state of the columns
1340 if (event.LeftDown())
1341 {
1342 for (int i=0; i < m_owner->GetColumnCount(); i++)
1343 {
1344 wxListItem colItem;
1345 m_owner->GetColumn(i, colItem);
6fef2483 1346 long state = colItem.GetState();
df0edf44
KO
1347 if (i == m_column)
1348 colItem.SetState(state | wxLIST_STATE_SELECTED);
1349 else
1350 colItem.SetState(state & ~wxLIST_STATE_SELECTED);
1351 m_owner->SetColumn(i, colItem);
1352 }
1353 }
6fef2483 1354
a77ec46d 1355 SendListEvent( event.LeftDown()
11358d39
VZ
1356 ? wxEVT_COMMAND_LIST_COL_CLICK
1357 : wxEVT_COMMAND_LIST_COL_RIGHT_CLICK,
a77ec46d 1358 event.GetPosition());
f6bcfd97 1359 }
63852e78 1360 }
f6bcfd97 1361 else if (event.Moving())
63852e78 1362 {
f6bcfd97
BP
1363 bool setCursor;
1364 if (hit_border)
1365 {
1366 setCursor = m_currentCursor == wxSTANDARD_CURSOR;
1367 m_currentCursor = m_resizeCursor;
1368 }
1369 else
1370 {
1371 setCursor = m_currentCursor != wxSTANDARD_CURSOR;
1372 m_currentCursor = wxSTANDARD_CURSOR;
1373 }
1374
1375 if ( setCursor )
1376 SetCursor(*m_currentCursor);
63852e78 1377 }
e1e955e1 1378 }
e1e955e1 1379}
c801d85f
KB
1380
1381void wxListHeaderWindow::OnSetFocus( wxFocusEvent &WXUNUSED(event) )
1382{
63852e78 1383 m_owner->SetFocus();
03eccb83 1384 m_owner->Update();
e1e955e1 1385}
c801d85f 1386
fbfb8bcc 1387bool wxListHeaderWindow::SendListEvent(wxEventType type, const wxPoint& pos)
a77ec46d
RD
1388{
1389 wxWindow *parent = GetParent();
1390 wxListEvent le( type, parent->GetId() );
1391 le.SetEventObject( parent );
1392 le.m_pointDrag = pos;
1393
1394 // the position should be relative to the parent window, not
1395 // this one for compatibility with MSW and common sense: the
1396 // user code doesn't know anything at all about this header
1397 // window, so why should it get positions relative to it?
1398 le.m_pointDrag.y -= GetSize().y;
1399
1400 le.m_col = m_column;
355f2407 1401 return !parent->GetEventHandler()->ProcessEvent( le ) || le.IsAllowed();
a77ec46d
RD
1402}
1403
c801d85f
KB
1404//-----------------------------------------------------------------------------
1405// wxListRenameTimer (internal)
1406//-----------------------------------------------------------------------------
1407
bd8289c1
VZ
1408wxListRenameTimer::wxListRenameTimer( wxListMainWindow *owner )
1409{
63852e78 1410 m_owner = owner;
e1e955e1 1411}
c801d85f 1412
bd8289c1
VZ
1413void wxListRenameTimer::Notify()
1414{
63852e78 1415 m_owner->OnRenameTimer();
e1e955e1 1416}
c801d85f 1417
ee7ee469 1418//-----------------------------------------------------------------------------
26e8da41 1419// wxListTextCtrlWrapper (internal)
ee7ee469
RR
1420//-----------------------------------------------------------------------------
1421
26e8da41
VZ
1422BEGIN_EVENT_TABLE(wxListTextCtrlWrapper, wxEvtHandler)
1423 EVT_CHAR (wxListTextCtrlWrapper::OnChar)
1424 EVT_KEY_UP (wxListTextCtrlWrapper::OnKeyUp)
1425 EVT_KILL_FOCUS (wxListTextCtrlWrapper::OnKillFocus)
ee7ee469
RR
1426END_EVENT_TABLE()
1427
26e8da41
VZ
1428wxListTextCtrlWrapper::wxListTextCtrlWrapper(wxListMainWindow *owner,
1429 wxTextCtrl *text,
1430 size_t itemEdit)
62d89eb4
VZ
1431 : m_startValue(owner->GetItemText(itemEdit)),
1432 m_itemEdited(itemEdit)
1433{
63852e78 1434 m_owner = owner;
26e8da41 1435 m_text = text;
33fe475a 1436 m_aboutToFinish = false;
62d89eb4 1437
06cd40a8
RR
1438 wxGenericListCtrl *parent = m_owner->GetListCtrl();
1439
62d89eb4
VZ
1440 wxRect rectLabel = owner->GetLineLabelRect(itemEdit);
1441
06cd40a8 1442 parent->CalcScrolledPosition(rectLabel.x, rectLabel.y,
62d89eb4
VZ
1443 &rectLabel.x, &rectLabel.y);
1444
26e8da41
VZ
1445 m_text->Create(owner, wxID_ANY, m_startValue,
1446 wxPoint(rectLabel.x-4,rectLabel.y-4),
1447 wxSize(rectLabel.width+11,rectLabel.height+8));
3603a389 1448 m_text->SetFocus();
cf76cd4e 1449
26e8da41 1450 m_text->PushEventHandler(this);
ee7ee469
RR
1451}
1452
a8a89154 1453void wxListTextCtrlWrapper::EndEdit(bool discardChanges)
ee7ee469 1454{
a8a89154 1455 m_aboutToFinish = true;
3e6858cd 1456
a8a89154 1457 if ( discardChanges )
63852e78 1458 {
a8a89154 1459 m_owner->OnRenameCancelled(m_itemEdited);
3e6858cd 1460
a8a89154
RR
1461 Finish( true );
1462 }
1463 else
1464 {
1465 // Notify the owner about the changes
1466 AcceptChanges();
26e8da41 1467
a8a89154
RR
1468 // Even if vetoed, close the control (consistent with MSW)
1469 Finish( true );
62d89eb4
VZ
1470 }
1471}
dd5a32cc 1472
a8a89154
RR
1473void wxListTextCtrlWrapper::Finish( bool setfocus )
1474{
1475 m_text->RemoveEventHandler(this);
1476 m_owner->ResetTextControl( m_text );
1477
1478 wxPendingDelete.Append( this );
3e6858cd 1479
a8a89154 1480 if (setfocus)
16361ec9 1481 m_owner->SetFocus();
a8a89154
RR
1482}
1483
26e8da41 1484bool wxListTextCtrlWrapper::AcceptChanges()
62d89eb4 1485{
26e8da41 1486 const wxString value = m_text->GetValue();
62d89eb4 1487
0a904ed2
VZ
1488 // notice that we should always call OnRenameAccept() to generate the "end
1489 // label editing" event, even if the user hasn't really changed anything
62d89eb4 1490 if ( !m_owner->OnRenameAccept(m_itemEdited, value) )
0a904ed2 1491 {
62d89eb4 1492 // vetoed by the user
ca65c044 1493 return false;
0a904ed2 1494 }
f6bcfd97 1495
0a904ed2
VZ
1496 // accepted, do rename the item (unless nothing changed)
1497 if ( value != m_startValue )
1498 m_owner->SetItemText(m_itemEdited, value);
f6bcfd97 1499
ca65c044 1500 return true;
62d89eb4 1501}
dd5a32cc 1502
26e8da41 1503void wxListTextCtrlWrapper::OnChar( wxKeyEvent &event )
62d89eb4
VZ
1504{
1505 switch ( event.m_keyCode )
1506 {
1507 case WXK_RETURN:
a8a89154 1508 EndEdit( false );
768276f6 1509 break;
f6bcfd97 1510
62d89eb4 1511 case WXK_ESCAPE:
a8a89154 1512 EndEdit( true );
62d89eb4
VZ
1513 break;
1514
1515 default:
1516 event.Skip();
1517 }
63852e78
RR
1518}
1519
26e8da41 1520void wxListTextCtrlWrapper::OnKeyUp( wxKeyEvent &event )
c13cace1 1521{
a8a89154
RR
1522 if (m_aboutToFinish)
1523 {
1524 // auto-grow the textctrl:
1525 wxSize parentSize = m_owner->GetSize();
1526 wxPoint myPos = m_text->GetPosition();
1527 wxSize mySize = m_text->GetSize();
1528 int sx, sy;
1529 m_text->GetTextExtent(m_text->GetValue() + _T("MM"), &sx, &sy);
1530 if (myPos.x + sx > parentSize.x)
1531 sx = parentSize.x - myPos.x;
1532 if (mySize.x > sx)
1533 sx = mySize.x;
1534 m_text->SetSize(sx, wxDefaultCoord);
1535 }
3e6858cd 1536
c13cace1
VS
1537 event.Skip();
1538}
1539
26e8da41 1540void wxListTextCtrlWrapper::OnKillFocus( wxFocusEvent &event )
63852e78 1541{
a8a89154 1542 if ( !m_aboutToFinish )
dd5a32cc 1543 {
86586459
RR
1544 if ( !AcceptChanges() )
1545 m_owner->OnRenameCancelled( m_itemEdited );
cf76cd4e 1546
a8a89154 1547 Finish( false );
62d89eb4 1548 }
86351e4a 1549
3603a389 1550 // We must let the native text control handle focus
62d89eb4 1551 event.Skip();
ee7ee469
RR
1552}
1553
c801d85f
KB
1554//-----------------------------------------------------------------------------
1555// wxListMainWindow
1556//-----------------------------------------------------------------------------
1557
fd1dc2a7 1558BEGIN_EVENT_TABLE(wxListMainWindow, wxWindow)
c801d85f 1559 EVT_PAINT (wxListMainWindow::OnPaint)
c801d85f
KB
1560 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse)
1561 EVT_CHAR (wxListMainWindow::OnChar)
3dfb93fd 1562 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown)
6fef2483 1563 EVT_KEY_UP (wxListMainWindow::OnKeyUp)
c801d85f
KB
1564 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus)
1565 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus)
2fa7c206 1566 EVT_SCROLLWIN (wxListMainWindow::OnScroll)
c2cbae6b 1567 EVT_CHILD_FOCUS (wxListMainWindow::OnChildFocus)
c801d85f
KB
1568END_EVENT_TABLE()
1569
1370703e 1570void wxListMainWindow::Init()
c801d85f 1571{
ca65c044 1572 m_dirty = true;
cf1dfa6b
VZ
1573 m_countVirt = 0;
1574 m_lineFrom =
b54e41c5 1575 m_lineTo = (size_t)-1;
cf1dfa6b
VZ
1576 m_linesPerPage = 0;
1577
1578 m_headerWidth =
1579 m_lineHeight = 0;
1370703e 1580
d3b9f782
VZ
1581 m_small_image_list = NULL;
1582 m_normal_image_list = NULL;
1370703e 1583
139adb6a
RR
1584 m_small_spacing = 30;
1585 m_normal_spacing = 40;
1370703e 1586
ca65c044 1587 m_hasFocus = false;
1370703e 1588 m_dragCount = 0;
ca65c044 1589 m_isCreated = false;
1370703e 1590
ca65c044 1591 m_lastOnSame = false;
139adb6a 1592 m_renameTimer = new wxListRenameTimer( this );
26e8da41 1593 m_textctrlWrapper = NULL;
277ea1b4 1594
cf1dfa6b 1595 m_current =
efbb7287 1596 m_lineLastClicked =
8df44392 1597 m_lineSelectSingleOnUp =
1370703e 1598 m_lineBeforeLastClicked = (size_t)-1;
e1e955e1 1599}
c801d85f 1600
1370703e 1601wxListMainWindow::wxListMainWindow()
c801d85f 1602{
1370703e
VZ
1603 Init();
1604
49ecb029 1605 m_highlightBrush =
d3b9f782 1606 m_highlightUnfocusedBrush = NULL;
1370703e
VZ
1607}
1608
1609wxListMainWindow::wxListMainWindow( wxWindow *parent,
1610 wxWindowID id,
1611 const wxPoint& pos,
1612 const wxSize& size,
1613 long style,
1614 const wxString &name )
06cd40a8 1615 : wxWindow( parent, id, pos, size, style, name )
1370703e
VZ
1616{
1617 Init();
1618
49ecb029 1619 m_highlightBrush = new wxBrush
4b8fa634 1620 (
a756f210 1621 wxSystemSettings::GetColour
49ecb029
VZ
1622 (
1623 wxSYS_COLOUR_HIGHLIGHT
1624 ),
04ee05f9 1625 wxBRUSHSTYLE_SOLID
4b8fa634 1626 );
6fef2483 1627
49ecb029 1628 m_highlightUnfocusedBrush = new wxBrush
4b8fa634
KO
1629 (
1630 wxSystemSettings::GetColour
1631 (
1632 wxSYS_COLOUR_BTNSHADOW
1633 ),
04ee05f9 1634 wxBRUSHSTYLE_SOLID
4b8fa634 1635 );
49ecb029 1636
ca65c044 1637 wxVisualAttributes attr = wxGenericListCtrl::GetClassDefaultAttributes();
fa47d7a7
VS
1638 SetOwnForegroundColour( attr.colFg );
1639 SetOwnBackgroundColour( attr.colBg );
92a4e4de
VZ
1640 if (!m_hasFont)
1641 SetOwnFont( attr.font );
e1e955e1 1642}
c801d85f 1643
fd9811b1 1644wxListMainWindow::~wxListMainWindow()
c801d85f 1645{
5fe143df 1646 DoDeleteAllItems();
222ed1d6 1647 WX_CLEAR_LIST(wxListHeaderDataList, m_columns);
8d36b216 1648 WX_CLEAR_ARRAY(m_aColWidths);
12c1b46a 1649
b54e41c5 1650 delete m_highlightBrush;
49ecb029 1651 delete m_highlightUnfocusedBrush;
139adb6a 1652 delete m_renameTimer;
e1e955e1 1653}
c801d85f 1654
cf1dfa6b 1655void wxListMainWindow::CacheLineData(size_t line)
c801d85f 1656{
3cd94a0d 1657 wxGenericListCtrl *listctrl = GetListCtrl();
25e3a937 1658
b54e41c5 1659 wxListLineData *ld = GetDummyLine();
f6bcfd97 1660
cf1dfa6b
VZ
1661 size_t countCol = GetColumnCount();
1662 for ( size_t col = 0; col < countCol; col++ )
1663 {
1664 ld->SetText(col, listctrl->OnGetItemText(line, col));
e062c6a4 1665 ld->SetImage(col, listctrl->OnGetItemColumnImage(line, col));
cf1dfa6b
VZ
1666 }
1667
6c02c329 1668 ld->SetAttr(listctrl->OnGetItemAttr(line));
e1e955e1 1669}
c801d85f 1670
b54e41c5 1671wxListLineData *wxListMainWindow::GetDummyLine() const
c801d85f 1672{
cf1dfa6b 1673 wxASSERT_MSG( !IsEmpty(), _T("invalid line index") );
904ccf52
VZ
1674 wxASSERT_MSG( IsVirtual(), _T("GetDummyLine() shouldn't be called") );
1675
1676 wxListMainWindow *self = wxConstCast(this, wxListMainWindow);
1677
1678 // we need to recreate the dummy line if the number of columns in the
1679 // control changed as it would have the incorrect number of fields
1680 // otherwise
1681 if ( !m_lines.IsEmpty() &&
1682 m_lines[0].m_items.GetCount() != (size_t)GetColumnCount() )
2c1f73ee 1683 {
904ccf52
VZ
1684 self->m_lines.Clear();
1685 }
cf1dfa6b 1686
904ccf52
VZ
1687 if ( m_lines.IsEmpty() )
1688 {
5cd89174 1689 wxListLineData *line = new wxListLineData(self);
cf1dfa6b 1690 self->m_lines.Add(line);
904ccf52
VZ
1691
1692 // don't waste extra memory -- there never going to be anything
1693 // else/more in this array
1694 self->m_lines.Shrink();
2c1f73ee
VZ
1695 }
1696
cf1dfa6b
VZ
1697 return &m_lines[0];
1698}
1699
5cd89174
VZ
1700// ----------------------------------------------------------------------------
1701// line geometry (report mode only)
1702// ----------------------------------------------------------------------------
1703
cf1dfa6b
VZ
1704wxCoord wxListMainWindow::GetLineHeight() const
1705{
cf1dfa6b
VZ
1706 // we cache the line height as calling GetTextExtent() is slow
1707 if ( !m_lineHeight )
2c1f73ee 1708 {
cf1dfa6b 1709 wxListMainWindow *self = wxConstCast(this, wxListMainWindow);
bd8289c1 1710
cf1dfa6b
VZ
1711 wxClientDC dc( self );
1712 dc.SetFont( GetFont() );
c801d85f 1713
cf1dfa6b
VZ
1714 wxCoord y;
1715 dc.GetTextExtent(_T("H"), NULL, &y);
004fd0c8 1716
ca7353de
RD
1717 if ( m_small_image_list && m_small_image_list->GetImageCount() )
1718 {
277ea1b4 1719 int iw = 0, ih = 0;
ca7353de
RD
1720 m_small_image_list->GetSize(0, iw, ih);
1721 y = wxMax(y, ih);
1722 }
1723
1724 y += EXTRA_HEIGHT;
cf1dfa6b
VZ
1725 self->m_lineHeight = y + LINE_SPACING;
1726 }
bffa1c77 1727
cf1dfa6b
VZ
1728 return m_lineHeight;
1729}
bffa1c77 1730
cf1dfa6b
VZ
1731wxCoord wxListMainWindow::GetLineY(size_t line) const
1732{
b5d43d1d 1733 wxASSERT_MSG( InReportView(), _T("only works in report mode") );
1370703e 1734
277ea1b4 1735 return LINE_SPACING + line * GetLineHeight();
cf1dfa6b 1736}
206b0a67 1737
5cd89174
VZ
1738wxRect wxListMainWindow::GetLineRect(size_t line) const
1739{
1740 if ( !InReportView() )
1741 return GetLine(line)->m_gi->m_rectAll;
1742
1743 wxRect rect;
1744 rect.x = HEADER_OFFSET_X;
1745 rect.y = GetLineY(line);
1746 rect.width = GetHeaderWidth();
1747 rect.height = GetLineHeight();
1748
1749 return rect;
1750}
1751
1752wxRect wxListMainWindow::GetLineLabelRect(size_t line) const
1753{
1754 if ( !InReportView() )
1755 return GetLine(line)->m_gi->m_rectLabel;
1756
a70598d5
RR
1757 int image_x = 0;
1758 wxListLineData *data = GetLine(line);
1759 wxListItemDataList::compatibility_iterator node = data->m_items.GetFirst();
1760 if (node)
1761 {
1762 wxListItemData *item = node->GetData();
1763 if ( item->HasImage() )
1764 {
1765 int ix, iy;
1766 GetImageSize( item->GetImage(), ix, iy );
1767 image_x = 3 + ix + IMAGE_MARGIN_IN_REPORT_MODE;
1768 }
1769 }
a9aead31 1770
5cd89174 1771 wxRect rect;
edddffb5 1772 rect.x = image_x + HEADER_OFFSET_X;
5cd89174 1773 rect.y = GetLineY(line);
edddffb5 1774 rect.width = GetColumnWidth(0) - image_x;
5cd89174
VZ
1775 rect.height = GetLineHeight();
1776
1777 return rect;
1778}
1779
1780wxRect wxListMainWindow::GetLineIconRect(size_t line) const
1781{
1782 if ( !InReportView() )
1783 return GetLine(line)->m_gi->m_rectIcon;
1784
1785 wxListLineData *ld = GetLine(line);
1786 wxASSERT_MSG( ld->HasImage(), _T("should have an image") );
1787
1788 wxRect rect;
1789 rect.x = HEADER_OFFSET_X;
1790 rect.y = GetLineY(line);
1791 GetImageSize(ld->GetImage(), rect.width, rect.height);
1792
1793 return rect;
1794}
1795
1796wxRect wxListMainWindow::GetLineHighlightRect(size_t line) const
1797{
1798 return InReportView() ? GetLineRect(line)
1799 : GetLine(line)->m_gi->m_rectHighlight;
1800}
1801
1802long wxListMainWindow::HitTestLine(size_t line, int x, int y) const
1803{
fc4f1d5f
VZ
1804 wxASSERT_MSG( line < GetItemCount(), _T("invalid line in HitTestLine") );
1805
5cd89174
VZ
1806 wxListLineData *ld = GetLine(line);
1807
22a35096 1808 if ( ld->HasImage() && GetLineIconRect(line).Contains(x, y) )
5cd89174
VZ
1809 return wxLIST_HITTEST_ONITEMICON;
1810
acf4d858
VS
1811 // VS: Testing for "ld->HasText() || InReportView()" instead of
1812 // "ld->HasText()" is needed to make empty lines in report view
1813 // possible
1814 if ( ld->HasText() || InReportView() )
5cd89174
VZ
1815 {
1816 wxRect rect = InReportView() ? GetLineRect(line)
1817 : GetLineLabelRect(line);
1818
22a35096 1819 if ( rect.Contains(x, y) )
5cd89174
VZ
1820 return wxLIST_HITTEST_ONITEMLABEL;
1821 }
1822
1823 return 0;
1824}
1825
1826// ----------------------------------------------------------------------------
1827// highlight (selection) handling
1828// ----------------------------------------------------------------------------
1829
b54e41c5 1830bool wxListMainWindow::IsHighlighted(size_t line) const
cf1dfa6b
VZ
1831{
1832 if ( IsVirtual() )
1833 {
b54e41c5 1834 return m_selStore.IsSelected(line);
cf1dfa6b
VZ
1835 }
1836 else // !virtual
1837 {
1838 wxListLineData *ld = GetLine(line);
ca65c044 1839 wxCHECK_MSG( ld, false, _T("invalid index in IsHighlighted") );
cf1dfa6b 1840
b54e41c5 1841 return ld->IsHighlighted();
cf1dfa6b
VZ
1842 }
1843}
1844
68a9ef0e
VZ
1845void wxListMainWindow::HighlightLines( size_t lineFrom,
1846 size_t lineTo,
1847 bool highlight )
cf1dfa6b 1848{
cf1dfa6b
VZ
1849 if ( IsVirtual() )
1850 {
68a9ef0e
VZ
1851 wxArrayInt linesChanged;
1852 if ( !m_selStore.SelectRange(lineFrom, lineTo, highlight,
1853 &linesChanged) )
1854 {
1855 // meny items changed state, refresh everything
1856 RefreshLines(lineFrom, lineTo);
1857 }
1858 else // only a few items changed state, refresh only them
1859 {
1860 size_t count = linesChanged.GetCount();
1861 for ( size_t n = 0; n < count; n++ )
1862 {
1863 RefreshLine(linesChanged[n]);
1864 }
1865 }
b54e41c5 1866 }
68a9ef0e 1867 else // iterate over all items in non report view
b54e41c5 1868 {
b54e41c5 1869 for ( size_t line = lineFrom; line <= lineTo; line++ )
cf1dfa6b 1870 {
b54e41c5 1871 if ( HighlightLine(line, highlight) )
68a9ef0e 1872 RefreshLine(line);
cf1dfa6b 1873 }
b54e41c5
VZ
1874 }
1875}
1876
1877bool wxListMainWindow::HighlightLine( size_t line, bool highlight )
1878{
1879 bool changed;
1880
1881 if ( IsVirtual() )
1882 {
1883 changed = m_selStore.SelectItem(line, highlight);
cf1dfa6b
VZ
1884 }
1885 else // !virtual
1886 {
1887 wxListLineData *ld = GetLine(line);
ca65c044 1888 wxCHECK_MSG( ld, false, _T("invalid index in HighlightLine") );
cf1dfa6b 1889
b54e41c5 1890 changed = ld->Highlight(highlight);
cf1dfa6b
VZ
1891 }
1892
1893 if ( changed )
1894 {
b54e41c5 1895 SendNotify( line, highlight ? wxEVT_COMMAND_LIST_ITEM_SELECTED
5cd89174 1896 : wxEVT_COMMAND_LIST_ITEM_DESELECTED );
cf1dfa6b
VZ
1897 }
1898
1899 return changed;
1900}
1901
1902void wxListMainWindow::RefreshLine( size_t line )
1903{
b5d43d1d 1904 if ( InReportView() )
6ea1323a
VZ
1905 {
1906 size_t visibleFrom, visibleTo;
1907 GetVisibleLinesRange(&visibleFrom, &visibleTo);
c1c4c551 1908
6ea1323a
VZ
1909 if ( line < visibleFrom || line > visibleTo )
1910 return;
1911 }
c1c4c551 1912
5cd89174 1913 wxRect rect = GetLineRect(line);
cf1dfa6b 1914
06cd40a8 1915 GetListCtrl()->CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
cf1dfa6b
VZ
1916 RefreshRect( rect );
1917}
1918
1919void wxListMainWindow::RefreshLines( size_t lineFrom, size_t lineTo )
1920{
1921 // we suppose that they are ordered by caller
1922 wxASSERT_MSG( lineFrom <= lineTo, _T("indices in disorder") );
1923
6b4a8d93
VZ
1924 wxASSERT_MSG( lineTo < GetItemCount(), _T("invalid line range") );
1925
b5d43d1d 1926 if ( InReportView() )
cf1dfa6b 1927 {
b54e41c5
VZ
1928 size_t visibleFrom, visibleTo;
1929 GetVisibleLinesRange(&visibleFrom, &visibleTo);
1930
1931 if ( lineFrom < visibleFrom )
1932 lineFrom = visibleFrom;
1933 if ( lineTo > visibleTo )
1934 lineTo = visibleTo;
cf1dfa6b
VZ
1935
1936 wxRect rect;
1937 rect.x = 0;
1938 rect.y = GetLineY(lineFrom);
1939 rect.width = GetClientSize().x;
91c6cc0e 1940 rect.height = GetLineY(lineTo) - rect.y + GetLineHeight();
cf1dfa6b 1941
06cd40a8 1942 GetListCtrl()->CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
cf1dfa6b
VZ
1943 RefreshRect( rect );
1944 }
1945 else // !report
1946 {
1947 // TODO: this should be optimized...
1948 for ( size_t line = lineFrom; line <= lineTo; line++ )
1949 {
1950 RefreshLine(line);
1951 }
1952 }
1953}
1954
6b4a8d93
VZ
1955void wxListMainWindow::RefreshAfter( size_t lineFrom )
1956{
b5d43d1d 1957 if ( InReportView() )
6b4a8d93 1958 {
c29582d0
JS
1959 size_t visibleFrom, visibleTo;
1960 GetVisibleLinesRange(&visibleFrom, &visibleTo);
6b4a8d93
VZ
1961
1962 if ( lineFrom < visibleFrom )
1963 lineFrom = visibleFrom;
c29582d0
JS
1964 else if ( lineFrom > visibleTo )
1965 return;
6b4a8d93
VZ
1966
1967 wxRect rect;
1968 rect.x = 0;
1969 rect.y = GetLineY(lineFrom);
06cd40a8 1970 GetListCtrl()->CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
6b4a8d93
VZ
1971
1972 wxSize size = GetClientSize();
1973 rect.width = size.x;
277ea1b4 1974
6b4a8d93
VZ
1975 // refresh till the bottom of the window
1976 rect.height = size.y - rect.y;
1977
6b4a8d93 1978 RefreshRect( rect );
6b4a8d93
VZ
1979 }
1980 else // !report
1981 {
1982 // TODO: how to do it more efficiently?
ca65c044 1983 m_dirty = true;
6b4a8d93
VZ
1984 }
1985}
1986
49ecb029
VZ
1987void wxListMainWindow::RefreshSelected()
1988{
1989 if ( IsEmpty() )
1990 return;
1991
1992 size_t from, to;
1993 if ( InReportView() )
1994 {
1995 GetVisibleLinesRange(&from, &to);
1996 }
1997 else // !virtual
1998 {
1999 from = 0;
2000 to = GetItemCount() - 1;
2001 }
2002
cf30ae13 2003 if ( HasCurrent() && m_current >= from && m_current <= to )
49ecb029 2004 RefreshLine(m_current);
49ecb029
VZ
2005
2006 for ( size_t line = from; line <= to; line++ )
2007 {
2008 // NB: the test works as expected even if m_current == -1
2009 if ( line != m_current && IsHighlighted(line) )
49ecb029 2010 RefreshLine(line);
49ecb029
VZ
2011 }
2012}
2013
cf1dfa6b
VZ
2014void wxListMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
2015{
2016 // Note: a wxPaintDC must be constructed even if no drawing is
2017 // done (a Windows requirement).
2018 wxPaintDC dc( this );
2019
03138b27 2020 if ( IsEmpty() )
17808a75 2021 {
c5c528fc 2022 // nothing to draw or not the moment to draw it
cf1dfa6b 2023 return;
17808a75 2024 }
cf1dfa6b 2025
1e4d446b 2026 if ( m_dirty )
06cd40a8 2027 RecalculatePositions( false );
1e4d446b 2028
06cd40a8 2029 GetListCtrl()->PrepareDC( dc );
cf1dfa6b
VZ
2030
2031 int dev_x, dev_y;
06cd40a8 2032 GetListCtrl()->CalcScrolledPosition( 0, 0, &dev_x, &dev_y );
cf1dfa6b 2033
cf1dfa6b
VZ
2034 dc.SetFont( GetFont() );
2035
b5d43d1d 2036 if ( InReportView() )
cf1dfa6b 2037 {
b54e41c5 2038 int lineHeight = GetLineHeight();
cf1dfa6b 2039
b54e41c5
VZ
2040 size_t visibleFrom, visibleTo;
2041 GetVisibleLinesRange(&visibleFrom, &visibleTo);
b84839ae
VZ
2042
2043 wxRect rectLine;
5eefe029
RR
2044 int xOrig = dc.LogicalToDeviceX( 0 );
2045 int yOrig = dc.LogicalToDeviceY( 0 );
6fef2483 2046
ff3d11a0 2047 // tell the caller cache to cache the data
91c6cc0e
VZ
2048 if ( IsVirtual() )
2049 {
2050 wxListEvent evCache(wxEVT_COMMAND_LIST_CACHE_HINT,
2051 GetParent()->GetId());
2052 evCache.SetEventObject( GetParent() );
2053 evCache.m_oldItemIndex = visibleFrom;
2054 evCache.m_itemIndex = visibleTo;
2055 GetParent()->GetEventHandler()->ProcessEvent( evCache );
2056 }
ff3d11a0 2057
b54e41c5 2058 for ( size_t line = visibleFrom; line <= visibleTo; line++ )
cf1dfa6b 2059 {
b84839ae
VZ
2060 rectLine = GetLineRect(line);
2061
5eefe029
RR
2062
2063 if ( !IsExposed(rectLine.x + xOrig, rectLine.y + yOrig,
b84839ae
VZ
2064 rectLine.width, rectLine.height) )
2065 {
2066 // don't redraw unaffected lines to avoid flicker
2067 continue;
2068 }
2069
5cd89174 2070 GetLine(line)->DrawInReportMode( &dc,
b84839ae 2071 rectLine,
5cd89174 2072 GetLineHighlightRect(line),
ad486020 2073 IsHighlighted(line),
32fc355f 2074 line == m_current );
cf1dfa6b
VZ
2075 }
2076
2077 if ( HasFlag(wxLC_HRULES) )
2078 {
04ee05f9 2079 wxPen pen(GetRuleColour(), 1, wxPENSTYLE_SOLID);
cf1dfa6b
VZ
2080 wxSize clientSize = GetClientSize();
2081
696a18c7
RR
2082 size_t i = visibleFrom;
2083 if (i == 0) i = 1; // Don't draw the first one
2084 for ( ; i <= visibleTo; i++ )
cf1dfa6b
VZ
2085 {
2086 dc.SetPen(pen);
2087 dc.SetBrush( *wxTRANSPARENT_BRUSH );
277ea1b4
DS
2088 dc.DrawLine(0 - dev_x, i * lineHeight,
2089 clientSize.x - dev_x, i * lineHeight);
cf1dfa6b
VZ
2090 }
2091
2092 // Draw last horizontal rule
e7d073c3 2093 if ( visibleTo == GetItemCount() - 1 )
cf1dfa6b 2094 {
277ea1b4 2095 dc.SetPen( pen );
cf1dfa6b 2096 dc.SetBrush( *wxTRANSPARENT_BRUSH );
277ea1b4
DS
2097 dc.DrawLine(0 - dev_x, (m_lineTo + 1) * lineHeight,
2098 clientSize.x - dev_x , (m_lineTo + 1) * lineHeight );
cf1dfa6b 2099 }
2c1f73ee 2100 }
206b0a67
JS
2101
2102 // Draw vertical rules if required
cf1dfa6b 2103 if ( HasFlag(wxLC_VRULES) && !IsEmpty() )
206b0a67 2104 {
04ee05f9 2105 wxPen pen(GetRuleColour(), 1, wxPENSTYLE_SOLID);
277ea1b4 2106 wxRect firstItemRect, lastItemRect;
cf1dfa6b 2107
e7d073c3
RD
2108 GetItemRect(visibleFrom, firstItemRect);
2109 GetItemRect(visibleTo, lastItemRect);
206b0a67 2110 int x = firstItemRect.GetX();
673dfcfa
JS
2111 dc.SetPen(pen);
2112 dc.SetBrush(* wxTRANSPARENT_BRUSH);
277ea1b4 2113
999836aa 2114 for (int col = 0; col < GetColumnCount(); col++)
206b0a67
JS
2115 {
2116 int colWidth = GetColumnWidth(col);
cf1dfa6b 2117 x += colWidth;
696a18c7
RR
2118 int x_pos = x - dev_x;
2119 if (col < GetColumnCount()-1) x_pos -= 2;
2120 dc.DrawLine(x_pos, firstItemRect.GetY() - 1 - dev_y,
2121 x_pos, lastItemRect.GetBottom() + 1 - dev_y);
206b0a67 2122 }
d786bf87 2123 }
139adb6a 2124 }
cf1dfa6b 2125 else // !report
139adb6a 2126 {
1370703e 2127 size_t count = GetItemCount();
cf1dfa6b
VZ
2128 for ( size_t i = 0; i < count; i++ )
2129 {
2130 GetLine(i)->Draw( &dc );
2131 }
139adb6a 2132 }
004fd0c8 2133
32fc355f 2134#if !defined( __WXMAC__) && !defined(__WXGTK20__)
65a1f350 2135 // Don't draw rect outline under Mac at all.
32fc355f 2136 // Draw it elsewhere under GTK.
c25f61f1 2137 if ( HasCurrent() )
cf1dfa6b 2138 {
49ecb029 2139 if ( m_hasFocus )
c25f61f1 2140 {
ccdbdc89 2141 wxRect rect( GetLineHighlightRect( m_current ) );
c25f61f1
VZ
2142 dc.SetPen( *wxBLACK_PEN );
2143 dc.SetBrush( *wxTRANSPARENT_BRUSH );
ccdbdc89 2144 dc.DrawRectangle( rect );
c25f61f1 2145 }
cf1dfa6b 2146 }
65a1f350 2147#endif
e1e955e1 2148}
c801d85f 2149
b54e41c5 2150void wxListMainWindow::HighlightAll( bool on )
c801d85f 2151{
b54e41c5 2152 if ( IsSingleSel() )
c801d85f 2153 {
277ea1b4 2154 wxASSERT_MSG( !on, _T("can't do this in a single selection control") );
b54e41c5
VZ
2155
2156 // we just have one item to turn off
2157 if ( HasCurrent() && IsHighlighted(m_current) )
139adb6a 2158 {
ca65c044 2159 HighlightLine(m_current, false);
b54e41c5 2160 RefreshLine(m_current);
139adb6a 2161 }
e1e955e1 2162 }
b6423e8b 2163 else // multi selection
cf1dfa6b 2164 {
b6423e8b
VZ
2165 if ( !IsEmpty() )
2166 HighlightLines(0, GetItemCount() - 1, on);
cf1dfa6b 2167 }
e1e955e1 2168}
c801d85f 2169
78806f0c 2170void wxListMainWindow::OnChildFocus(wxChildFocusEvent& WXUNUSED(event))
c2cbae6b 2171{
78806f0c
RD
2172 // Do nothing here. This prevents the default handler in wxScrolledWindow
2173 // from needlessly scrolling the window when the edit control is
2174 // dismissed. See ticket #9563.
c2cbae6b
RD
2175}
2176
cf1dfa6b 2177void wxListMainWindow::SendNotify( size_t line,
05a7f61d 2178 wxEventType command,
fbfb8bcc 2179 const wxPoint& point )
c801d85f 2180{
139adb6a
RR
2181 wxListEvent le( command, GetParent()->GetId() );
2182 le.SetEventObject( GetParent() );
6fef2483 2183
cf1dfa6b 2184 le.m_itemIndex = line;
05a7f61d
VZ
2185
2186 // set only for events which have position
2187 if ( point != wxDefaultPosition )
2188 le.m_pointDrag = point;
2189
c1c4c551
VZ
2190 // don't try to get the line info for virtual list controls: the main
2191 // program has it anyhow and if we did it would result in accessing all
2192 // the lines, even those which are not visible now and this is precisely
2193 // what we're trying to avoid
a95d5751 2194 if ( !IsVirtual() )
91c6cc0e 2195 {
0ddefeb0
VZ
2196 if ( line != (size_t)-1 )
2197 {
2198 GetLine(line)->GetItem( 0, le.m_item );
2199 }
2200 //else: this happens for wxEVT_COMMAND_LIST_ITEM_FOCUSED event
91c6cc0e
VZ
2201 }
2202 //else: there may be no more such item
2203
6e228e42 2204 GetParent()->GetEventHandler()->ProcessEvent( le );
e1e955e1 2205}
c801d85f 2206
0ddefeb0 2207void wxListMainWindow::ChangeCurrent(size_t current)
c801d85f 2208{
0ddefeb0 2209 m_current = current;
c801d85f 2210
6fef2483
VZ
2211 // as the current item changed, we shouldn't start editing it when the
2212 // "slow click" timer expires as the click happened on another item
2213 if ( m_renameTimer->IsRunning() )
2214 m_renameTimer->Stop();
2215
0ddefeb0 2216 SendNotify(current, wxEVT_COMMAND_LIST_ITEM_FOCUSED);
e1e955e1 2217}
c801d85f 2218
26e8da41 2219wxTextCtrl *wxListMainWindow::EditLabel(long item, wxClassInfo* textControlClass)
c801d85f 2220{
26e8da41 2221 wxCHECK_MSG( (item >= 0) && ((size_t)item < GetItemCount()), NULL,
3cd94a0d 2222 wxT("wrong index in wxGenericListCtrl::EditLabel()") );
004fd0c8 2223
26e8da41
VZ
2224 wxASSERT_MSG( textControlClass->IsKindOf(CLASSINFO(wxTextCtrl)),
2225 wxT("EditLabel() needs a text control") );
2226
62d89eb4 2227 size_t itemEdit = (size_t)item;
e179bd65 2228
fd9811b1 2229 wxListEvent le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT, GetParent()->GetId() );
139adb6a 2230 le.SetEventObject( GetParent() );
1370703e 2231 le.m_itemIndex = item;
62d89eb4 2232 wxListLineData *data = GetLine(itemEdit);
26e8da41 2233 wxCHECK_MSG( data, NULL, _T("invalid index in EditLabel()") );
1370703e 2234 data->GetItem( 0, le.m_item );
277ea1b4 2235
62d89eb4 2236 if ( GetParent()->GetEventHandler()->ProcessEvent( le ) && !le.IsAllowed() )
26e8da41 2237 {
62d89eb4 2238 // vetoed by user code
26e8da41
VZ
2239 return NULL;
2240 }
004fd0c8 2241
cf1dfa6b
VZ
2242 // We have to call this here because the label in question might just have
2243 // been added and no screen update taken place.
62d89eb4 2244 if ( m_dirty )
a502b284 2245 {
977a41ec
FM
2246 // TODO: use wxTheApp->SafeYieldFor(NULL, wxEVT_CATEGORY_UI) instead
2247 // so that no pending events may change the item count (see below)
2248 // IMPORTANT: needs to be tested!
cf1dfa6b 2249 wxSafeYield();
004fd0c8 2250
a502b284
VZ
2251 // Pending events dispatched by wxSafeYield might have changed the item
2252 // count
2253 if ( (size_t)item >= GetItemCount() )
2254 return NULL;
2255 }
2256
26e8da41
VZ
2257 wxTextCtrl * const text = (wxTextCtrl *)textControlClass->CreateObject();
2258 m_textctrlWrapper = new wxListTextCtrlWrapper(this, text, item);
2259 return m_textctrlWrapper->GetText();
e1e955e1 2260}
c801d85f 2261
e179bd65
RR
2262void wxListMainWindow::OnRenameTimer()
2263{
cf1dfa6b 2264 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") );
004fd0c8 2265
cf1dfa6b 2266 EditLabel( m_current );
e179bd65
RR
2267}
2268
62d89eb4 2269bool wxListMainWindow::OnRenameAccept(size_t itemEdit, const wxString& value)
c801d85f 2270{
e179bd65
RR
2271 wxListEvent le( wxEVT_COMMAND_LIST_END_LABEL_EDIT, GetParent()->GetId() );
2272 le.SetEventObject( GetParent() );
62d89eb4 2273 le.m_itemIndex = itemEdit;
1370703e 2274
62d89eb4 2275 wxListLineData *data = GetLine(itemEdit);
277ea1b4 2276
ca65c044 2277 wxCHECK_MSG( data, false, _T("invalid index in OnRenameAccept()") );
1370703e
VZ
2278
2279 data->GetItem( 0, le.m_item );
62d89eb4
VZ
2280 le.m_item.m_text = value;
2281 return !GetParent()->GetEventHandler()->ProcessEvent( le ) ||
2282 le.IsAllowed();
e1e955e1 2283}
c801d85f 2284
18dd54e3 2285void wxListMainWindow::OnRenameCancelled(size_t itemEdit)
86586459 2286{
86586459
RR
2287 // let owner know that the edit was cancelled
2288 wxListEvent le( wxEVT_COMMAND_LIST_END_LABEL_EDIT, GetParent()->GetId() );
86351e4a 2289
ca65c044 2290 le.SetEditCanceled(true);
86351e4a 2291
86586459
RR
2292 le.SetEventObject( GetParent() );
2293 le.m_itemIndex = itemEdit;
2294
2295 wxListLineData *data = GetLine(itemEdit);
2296 wxCHECK_RET( data, _T("invalid index in OnRenameCancelled()") );
2297
2298 data->GetItem( 0, le.m_item );
86586459
RR
2299 GetEventHandler()->ProcessEvent( le );
2300}
2301
c801d85f
KB
2302void wxListMainWindow::OnMouse( wxMouseEvent &event )
2303{
b6bc47ef
RD
2304#ifdef __WXMAC__
2305 // On wxMac we can't depend on the EVT_KILL_FOCUS event to properly
2306 // shutdown the edit control when the mouse is clicked elsewhere on the
2307 // listctrl because the order of events is different (or something like
277ea1b4 2308 // that), so explicitly end the edit if it is active.
26e8da41 2309 if ( event.LeftDown() && m_textctrlWrapper )
a8a89154 2310 m_textctrlWrapper->EndEdit( false );
26e8da41 2311#endif // __WXMAC__
277ea1b4 2312
8d4b048e 2313 if ( event.LeftDown() )
16361ec9 2314 SetFocus();
6fef2483 2315
3e1c4e00 2316 event.SetEventObject( GetParent() );
cf1dfa6b
VZ
2317 if ( GetParent()->GetEventHandler()->ProcessEvent( event) )
2318 return;
2319
185f6036
RD
2320 if (event.GetEventType() == wxEVT_MOUSEWHEEL)
2321 {
64894596 2322 // let the base class handle mouse wheel events.
185f6036
RD
2323 event.Skip();
2324 return;
2325 }
2ac08aeb 2326
cf1dfa6b 2327 if ( !HasCurrent() || IsEmpty() )
8b1464af
RR
2328 {
2329 if (event.RightDown())
2330 {
2331 SendNotify( (size_t)-1, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, event.GetPosition() );
b6423e8b 2332
64894596
FM
2333 wxContextMenuEvent evtCtx(wxEVT_CONTEXT_MENU,
2334 GetParent()->GetId(),
2335 ClientToScreen(event.GetPosition()));
fc694caa
RR
2336 evtCtx.SetEventObject(GetParent());
2337 GetParent()->GetEventHandler()->ProcessEvent(evtCtx);
8b1464af 2338 }
cf1dfa6b 2339 return;
8b1464af 2340 }
cf1dfa6b
VZ
2341
2342 if (m_dirty)
2343 return;
e3e65dac 2344
cf1dfa6b
VZ
2345 if ( !(event.Dragging() || event.ButtonDown() || event.LeftUp() ||
2346 event.ButtonDClick()) )
2347 return;
c801d85f 2348
aaef15bf
RR
2349 int x = event.GetX();
2350 int y = event.GetY();
06cd40a8 2351 GetListCtrl()->CalcUnscrolledPosition( x, y, &x, &y );
004fd0c8 2352
cc734310 2353 // where did we hit it (if we did)?
92976ab6 2354 long hitResult = 0;
1370703e 2355
cf1dfa6b
VZ
2356 size_t count = GetItemCount(),
2357 current;
2358
b5d43d1d 2359 if ( InReportView() )
92976ab6 2360 {
5cd89174 2361 current = y / GetLineHeight();
cc734310
VZ
2362 if ( current < count )
2363 hitResult = HitTestLine(current, x, y);
cf1dfa6b
VZ
2364 }
2365 else // !report
2366 {
2367 // TODO: optimize it too! this is less simple than for report view but
2368 // enumerating all items is still not a way to do it!!
4e3ace65 2369 for ( current = 0; current < count; current++ )
cf1dfa6b 2370 {
5cd89174 2371 hitResult = HitTestLine(current, x, y);
4e3ace65
VZ
2372 if ( hitResult )
2373 break;
cf1dfa6b 2374 }
92976ab6 2375 }
bd8289c1 2376
fd9811b1 2377 if (event.Dragging())
92976ab6 2378 {
fd9811b1 2379 if (m_dragCount == 0)
8d1d2284
VZ
2380 {
2381 // we have to report the raw, physical coords as we want to be
2382 // able to call HitTest(event.m_pointDrag) from the user code to
2383 // get the item being dragged
2384 m_dragStart = event.GetPosition();
2385 }
bffa1c77 2386
fd9811b1 2387 m_dragCount++;
bffa1c77 2388
cf1dfa6b
VZ
2389 if (m_dragCount != 3)
2390 return;
bffa1c77 2391
05a7f61d
VZ
2392 int command = event.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAG
2393 : wxEVT_COMMAND_LIST_BEGIN_DRAG;
bffa1c77 2394
fd9811b1 2395 wxListEvent le( command, GetParent()->GetId() );
92976ab6 2396 le.SetEventObject( GetParent() );
8df44392 2397 le.m_itemIndex = m_lineLastClicked;
bffa1c77
VZ
2398 le.m_pointDrag = m_dragStart;
2399 GetParent()->GetEventHandler()->ProcessEvent( le );
2400
2401 return;
92976ab6 2402 }
fd9811b1
RR
2403 else
2404 {
2405 m_dragCount = 0;
2406 }
bd8289c1 2407
cf1dfa6b
VZ
2408 if ( !hitResult )
2409 {
8b1464af
RR
2410 // outside of any item
2411 if (event.RightDown())
2412 {
2413 SendNotify( (size_t) -1, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, event.GetPosition() );
b6423e8b 2414
fc694caa
RR
2415 wxContextMenuEvent evtCtx(
2416 wxEVT_CONTEXT_MENU,
2417 GetParent()->GetId(),
2418 ClientToScreen(event.GetPosition()));
2419 evtCtx.SetEventObject(GetParent());
2420 GetParent()->GetEventHandler()->ProcessEvent(evtCtx);
8b1464af
RR
2421 }
2422 else
2423 {
2424 // reset the selection and bail out
2425 HighlightAll(false);
2426 }
cf76cd4e 2427
cf1dfa6b
VZ
2428 return;
2429 }
bd8289c1 2430
ca65c044 2431 bool forceClick = false;
92976ab6
RR
2432 if (event.ButtonDClick())
2433 {
6fef2483
VZ
2434 if ( m_renameTimer->IsRunning() )
2435 m_renameTimer->Stop();
2436
ca65c044 2437 m_lastOnSame = false;
efbb7287 2438
ddba340d 2439 if ( current == m_lineLastClicked )
efbb7287 2440 {
cf1dfa6b 2441 SendNotify( current, wxEVT_COMMAND_LIST_ITEM_ACTIVATED );
004fd0c8 2442
efbb7287
VZ
2443 return;
2444 }
2445 else
2446 {
8df44392 2447 // The first click was on another item, so don't interpret this as
efbb7287 2448 // a double click, but as a simple click instead
ca65c044 2449 forceClick = true;
efbb7287 2450 }
92976ab6 2451 }
bd8289c1 2452
8df44392 2453 if (event.LeftUp())
c801d85f 2454 {
277ea1b4 2455 if (m_lineSelectSingleOnUp != (size_t)-1)
92976ab6 2456 {
8df44392
RR
2457 // select single line
2458 HighlightAll( false );
2459 ReverseHighlight(m_lineSelectSingleOnUp);
2460 }
277ea1b4 2461
2cb1f3da 2462 if (m_lastOnSame)
8df44392
RR
2463 {
2464 if ((current == m_current) &&
2465 (hitResult == wxLIST_HITTEST_ONITEMLABEL) &&
2cb1f3da 2466 HasFlag(wxLC_EDIT_LABELS) )
8df44392 2467 {
5595181f
VZ
2468 if ( !InReportView() ||
2469 GetLineLabelRect(current).Contains(x, y) )
a70598d5 2470 {
5595181f
VZ
2471 int dclick = wxSystemSettings::GetMetric(wxSYS_DCLICK_MSEC);
2472 m_renameTimer->Start(dclick > 0 ? dclick : 250, true);
a70598d5 2473 }
8df44392 2474 }
92976ab6 2475 }
277ea1b4 2476
ca65c044 2477 m_lastOnSame = false;
277ea1b4 2478 m_lineSelectSingleOnUp = (size_t)-1;
8df44392
RR
2479 }
2480 else
2481 {
3103e8a9 2482 // This is necessary, because after a DnD operation in
2997ca30 2483 // from and to ourself, the up event is swallowed by the
8df44392
RR
2484 // DnD code. So on next non-up event (which means here and
2485 // now) m_lineSelectSingleOnUp should be reset.
277ea1b4 2486 m_lineSelectSingleOnUp = (size_t)-1;
e1e955e1 2487 }
8df44392 2488 if (event.RightDown())
b204641e 2489 {
8df44392
RR
2490 m_lineBeforeLastClicked = m_lineLastClicked;
2491 m_lineLastClicked = current;
277ea1b4 2492
eaefbb88
KH
2493 // If the item is already selected, do not update the selection.
2494 // Multi-selections should not be cleared if a selected item is clicked.
2495 if (!IsHighlighted(current))
2496 {
2497 HighlightAll(false);
2498 ChangeCurrent(current);
2499 ReverseHighlight(m_current);
2500 }
277ea1b4
DS
2501
2502 SendNotify( current, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, event.GetPosition() );
2503
18216ae3
RR
2504 // Allow generation of context menu event
2505 event.Skip();
b204641e 2506 }
cf1dfa6b 2507 else if (event.MiddleDown())
b204641e 2508 {
cf1dfa6b 2509 SendNotify( current, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK );
92976ab6 2510 }
cf1dfa6b 2511 else if ( event.LeftDown() || forceClick )
92976ab6 2512 {
efbb7287 2513 m_lineBeforeLastClicked = m_lineLastClicked;
cf1dfa6b
VZ
2514 m_lineLastClicked = current;
2515
2516 size_t oldCurrent = m_current;
2cb1f3da
JS
2517 bool oldWasSelected = IsHighlighted(m_current);
2518
39e39d39 2519 bool cmdModifierDown = event.CmdDown();
2fe417e4 2520 if ( IsSingleSel() || !(cmdModifierDown || event.ShiftDown()) )
8df44392 2521 {
277ea1b4 2522 if ( IsSingleSel() || !IsHighlighted(current) )
eb3d60a2
KH
2523 {
2524 HighlightAll( false );
0ddefeb0 2525
eb3d60a2 2526 ChangeCurrent(current);
cf1dfa6b 2527
eb3d60a2
KH
2528 ReverseHighlight(m_current);
2529 }
2530 else // multi sel & current is highlighted & no mod keys
8df44392 2531 {
2997ca30 2532 m_lineSelectSingleOnUp = current;
8df44392
RR
2533 ChangeCurrent(current); // change focus
2534 }
e1e955e1 2535 }
b54e41c5 2536 else // multi sel & either ctrl or shift is down
b204641e 2537 {
015fd9ef 2538 if (cmdModifierDown)
92976ab6 2539 {
0ddefeb0 2540 ChangeCurrent(current);
cf1dfa6b 2541
b54e41c5 2542 ReverseHighlight(m_current);
92976ab6 2543 }
473d087e 2544 else if (event.ShiftDown())
92976ab6 2545 {
0ddefeb0 2546 ChangeCurrent(current);
bffa1c77 2547
cf1dfa6b
VZ
2548 size_t lineFrom = oldCurrent,
2549 lineTo = current;
f6bcfd97 2550
cf1dfa6b 2551 if ( lineTo < lineFrom )
92976ab6 2552 {
cf1dfa6b
VZ
2553 lineTo = lineFrom;
2554 lineFrom = m_current;
92976ab6
RR
2555 }
2556
b54e41c5 2557 HighlightLines(lineFrom, lineTo);
92976ab6 2558 }
cf1dfa6b 2559 else // !ctrl, !shift
92976ab6 2560 {
cf1dfa6b
VZ
2561 // test in the enclosing if should make it impossible
2562 wxFAIL_MSG( _T("how did we get here?") );
92976ab6 2563 }
e1e955e1 2564 }
cf1dfa6b 2565
92976ab6 2566 if (m_current != oldCurrent)
92976ab6 2567 RefreshLine( oldCurrent );
efbb7287
VZ
2568
2569 // forceClick is only set if the previous click was on another item
2cb1f3da 2570 m_lastOnSame = !forceClick && (m_current == oldCurrent) && oldWasSelected;
e1e955e1 2571 }
e1e955e1 2572}
c801d85f 2573
34bbbc27 2574void wxListMainWindow::MoveToItem(size_t item)
c801d85f 2575{
34bbbc27 2576 if ( item == (size_t)-1 )
cf1dfa6b 2577 return;
004fd0c8 2578
34bbbc27 2579 wxRect rect = GetLineRect(item);
cf3da716 2580
cf1dfa6b 2581 int client_w, client_h;
cf3da716 2582 GetClientSize( &client_w, &client_h );
f6bcfd97 2583
6d78bbe6
VZ
2584 const int hLine = GetLineHeight();
2585
edea2c4a
RR
2586 int view_x = SCROLL_UNIT_X * GetListCtrl()->GetScrollPos( wxHORIZONTAL );
2587 int view_y = hLine * GetListCtrl()->GetScrollPos( wxVERTICAL );
004fd0c8 2588
b5d43d1d 2589 if ( InReportView() )
92976ab6 2590 {
277ea1b4
DS
2591 // the next we need the range of lines shown it might be different,
2592 // so recalculate it
b54e41c5
VZ
2593 ResetVisibleLinesRange();
2594
277ea1b4 2595 if (rect.y < view_y)
06cd40a8 2596 GetListCtrl()->Scroll( -1, rect.y / hLine );
277ea1b4 2597 if (rect.y + rect.height + 5 > view_y + client_h)
06cd40a8 2598 GetListCtrl()->Scroll( -1, (rect.y + rect.height - client_h + hLine) / hLine );
35a7f94b
RD
2599
2600#ifdef __WXMAC__
2601 // At least on Mac the visible lines value will get reset inside of
2602 // Scroll *before* it actually scrolls the window because of the
2603 // Update() that happens there, so it will still have the wrong value.
2604 // So let's reset it again and wait for it to be recalculated in the
2605 // next paint event. I would expect this problem to show up in wxGTK
2606 // too but couldn't duplicate it there. Perhaps the order of events
2607 // is different... --Robin
2608 ResetVisibleLinesRange();
2609#endif
92976ab6 2610 }
b54e41c5 2611 else // !report
92976ab6 2612 {
e81fa385
VZ
2613 int sx = -1,
2614 sy = -1;
2615
807a572e 2616 if (rect.x-view_x < 5)
e81fa385 2617 sx = (rect.x - 5) / SCROLL_UNIT_X;
807a572e 2618 if (rect.x + rect.width - 5 > view_x + client_w)
e81fa385
VZ
2619 sx = (rect.x + rect.width - client_w + SCROLL_UNIT_X) / SCROLL_UNIT_X;
2620
2621 if (rect.y-view_y < 5)
2622 sy = (rect.y - 5) / hLine;
2623 if (rect.y + rect.height - 5 > view_y + client_h)
2624 sy = (rect.y + rect.height - client_h + hLine) / hLine;
2625
06cd40a8 2626 GetListCtrl()->Scroll(sx, sy);
92976ab6 2627 }
e1e955e1 2628}
c801d85f 2629
66a9201d
VZ
2630bool wxListMainWindow::ScrollList(int WXUNUSED(dx), int dy)
2631{
2632 if ( !InReportView() )
2633 {
2634 // TODO: this should work in all views but is not implemented now
2635 return false;
2636 }
2637
2638 size_t top, bottom;
2639 GetVisibleLinesRange(&top, &bottom);
2640
2641 if ( bottom == (size_t)-1 )
2642 return 0;
2643
2644 ResetVisibleLinesRange();
2645
2646 int hLine = GetLineHeight();
2647
06cd40a8 2648 GetListCtrl()->Scroll(-1, top + dy / hLine);
66a9201d
VZ
2649
2650#ifdef __WXMAC__
2651 // see comment in MoveToItem() for why we do this
2652 ResetVisibleLinesRange();
2653#endif
2654
2655 return true;
2656}
2657
cf1dfa6b
VZ
2658// ----------------------------------------------------------------------------
2659// keyboard handling
2660// ----------------------------------------------------------------------------
2661
2662void wxListMainWindow::OnArrowChar(size_t newCurrent, const wxKeyEvent& event)
c801d85f 2663{
cf1dfa6b
VZ
2664 wxCHECK_RET( newCurrent < (size_t)GetItemCount(),
2665 _T("invalid item index in OnArrowChar()") );
2666
2667 size_t oldCurrent = m_current;
2668
2669 // in single selection we just ignore Shift as we can't select several
2670 // items anyhow
b54e41c5 2671 if ( event.ShiftDown() && !IsSingleSel() )
cf1dfa6b 2672 {
0ddefeb0 2673 ChangeCurrent(newCurrent);
cf1dfa6b 2674
65a1f350
RR
2675 // refresh the old focus to remove it
2676 RefreshLine( oldCurrent );
2677
cf1dfa6b
VZ
2678 // select all the items between the old and the new one
2679 if ( oldCurrent > newCurrent )
2680 {
2681 newCurrent = oldCurrent;
2682 oldCurrent = m_current;
2683 }
2684
b54e41c5 2685 HighlightLines(oldCurrent, newCurrent);
cf1dfa6b
VZ
2686 }
2687 else // !shift
2688 {
b54e41c5 2689 // all previously selected items are unselected unless ctrl is held
a9aead31
VZ
2690 // in a multiselection control
2691 if ( !event.ControlDown() || IsSingleSel() )
ca65c044 2692 HighlightAll(false);
b54e41c5 2693
0ddefeb0 2694 ChangeCurrent(newCurrent);
ca65c044 2695
65a1f350
RR
2696 // refresh the old focus to remove it
2697 RefreshLine( oldCurrent );
cf1dfa6b 2698
a9aead31
VZ
2699 // in single selection mode we must always have a selected item
2700 if ( !event.ControlDown() || IsSingleSel() )
ca65c044 2701 HighlightLine( m_current, true );
cf1dfa6b 2702 }
ca65c044 2703
92976ab6 2704 RefreshLine( m_current );
cf1dfa6b 2705
cf3da716 2706 MoveToFocus();
e1e955e1 2707}
c801d85f 2708
3dfb93fd
RR
2709void wxListMainWindow::OnKeyDown( wxKeyEvent &event )
2710{
2711 wxWindow *parent = GetParent();
004fd0c8 2712
277ea1b4 2713 // propagate the key event upwards
101198ba 2714 wxKeyEvent ke(event);
3dfb93fd 2715 ke.SetEventObject( parent );
101198ba
VZ
2716 if (parent->GetEventHandler()->ProcessEvent( ke ))
2717 return;
004fd0c8 2718
3dfb93fd
RR
2719 event.Skip();
2720}
004fd0c8 2721
9fe25f13
KO
2722void wxListMainWindow::OnKeyUp( wxKeyEvent &event )
2723{
2724 wxWindow *parent = GetParent();
2725
2726 // propagate the key event upwards
101198ba
VZ
2727 wxKeyEvent ke(event);
2728 if (parent->GetEventHandler()->ProcessEvent( ke ))
2729 return;
9fe25f13
KO
2730
2731 event.Skip();
2732}
2733
c801d85f
KB
2734void wxListMainWindow::OnChar( wxKeyEvent &event )
2735{
51cc4dad 2736 wxWindow *parent = GetParent();
004fd0c8 2737
277ea1b4 2738 // send a list_key event up
cf1dfa6b 2739 if ( HasCurrent() )
f6bcfd97
BP
2740 {
2741 wxListEvent le( wxEVT_COMMAND_LIST_KEY_DOWN, GetParent()->GetId() );
cf1dfa6b
VZ
2742 le.m_itemIndex = m_current;
2743 GetLine(m_current)->GetItem( 0, le.m_item );
12a3f227 2744 le.m_code = event.GetKeyCode();
f6bcfd97
BP
2745 le.SetEventObject( parent );
2746 parent->GetEventHandler()->ProcessEvent( le );
2747 }
51cc4dad 2748
8be0b888
RR
2749 if ( (event.GetKeyCode() != WXK_UP) &&
2750 (event.GetKeyCode() != WXK_DOWN) &&
2751 (event.GetKeyCode() != WXK_RIGHT) &&
2752 (event.GetKeyCode() != WXK_LEFT) &&
2753 (event.GetKeyCode() != WXK_PAGEUP) &&
2754 (event.GetKeyCode() != WXK_PAGEDOWN) &&
2755 (event.GetKeyCode() != WXK_END) &&
2756 (event.GetKeyCode() != WXK_HOME) )
2757 {
2758 // propagate the char event upwards
2759 wxKeyEvent ke(event);
2760 ke.SetEventObject( parent );
2761 if (parent->GetEventHandler()->ProcessEvent( ke ))
2762 return;
2763 }
004fd0c8 2764
f029f1d1
VS
2765 if ( HandleAsNavigationKey(event) )
2766 return;
004fd0c8 2767
277ea1b4 2768 // no item -> nothing to do
cf1dfa6b 2769 if (!HasCurrent())
c801d85f 2770 {
51cc4dad
RR
2771 event.Skip();
2772 return;
e1e955e1 2773 }
51cc4dad 2774
cf76cd4e
VZ
2775 // don't use m_linesPerPage directly as it might not be computed yet
2776 const int pageSize = GetCountPerPage();
2777 wxCHECK_RET( pageSize, _T("should have non zero page size") );
2778
03703fc0
RR
2779 if (GetLayoutDirection() == wxLayout_RightToLeft)
2780 {
2781 if (event.GetKeyCode() == WXK_RIGHT)
2782 event.m_keyCode = WXK_LEFT;
2783 else if (event.GetKeyCode() == WXK_LEFT)
2784 event.m_keyCode = WXK_RIGHT;
2785 }
2786
cf76cd4e 2787 switch ( event.GetKeyCode() )
c801d85f 2788 {
51cc4dad 2789 case WXK_UP:
cf1dfa6b
VZ
2790 if ( m_current > 0 )
2791 OnArrowChar( m_current - 1, event );
51cc4dad 2792 break;
cf1dfa6b 2793
51cc4dad 2794 case WXK_DOWN:
cf1dfa6b
VZ
2795 if ( m_current < (size_t)GetItemCount() - 1 )
2796 OnArrowChar( m_current + 1, event );
51cc4dad 2797 break;
cf1dfa6b 2798
51cc4dad 2799 case WXK_END:
1370703e 2800 if (!IsEmpty())
cf1dfa6b 2801 OnArrowChar( GetItemCount() - 1, event );
51cc4dad 2802 break;
cf1dfa6b 2803
51cc4dad 2804 case WXK_HOME:
1370703e 2805 if (!IsEmpty())
cf1dfa6b 2806 OnArrowChar( 0, event );
51cc4dad 2807 break;
cf1dfa6b 2808
faa94f3e 2809 case WXK_PAGEUP:
f6bcfd97 2810 {
cf76cd4e
VZ
2811 int steps = InReportView() ? pageSize - 1
2812 : m_current % pageSize;
cf1dfa6b
VZ
2813
2814 int index = m_current - steps;
2815 if (index < 0)
2816 index = 0;
2817
2818 OnArrowChar( index, event );
51cc4dad 2819 }
51cc4dad 2820 break;
cf1dfa6b 2821
faa94f3e 2822 case WXK_PAGEDOWN:
bffa1c77 2823 {
b5d43d1d 2824 int steps = InReportView()
cf76cd4e
VZ
2825 ? pageSize - 1
2826 : pageSize - (m_current % pageSize) - 1;
f6bcfd97 2827
cf1dfa6b
VZ
2828 size_t index = m_current + steps;
2829 size_t count = GetItemCount();
2830 if ( index >= count )
2831 index = count - 1;
2832
2833 OnArrowChar( index, event );
51cc4dad 2834 }
51cc4dad 2835 break;
cf1dfa6b 2836
51cc4dad 2837 case WXK_LEFT:
b5d43d1d 2838 if ( !InReportView() )
51cc4dad 2839 {
cf76cd4e 2840 int index = m_current - pageSize;
cf1dfa6b
VZ
2841 if (index < 0)
2842 index = 0;
2843
2844 OnArrowChar( index, event );
51cc4dad
RR
2845 }
2846 break;
cf1dfa6b 2847
51cc4dad 2848 case WXK_RIGHT:
b5d43d1d 2849 if ( !InReportView() )
51cc4dad 2850 {
cf76cd4e 2851 size_t index = m_current + pageSize;
cf1dfa6b
VZ
2852
2853 size_t count = GetItemCount();
2854 if ( index >= count )
2855 index = count - 1;
2856
2857 OnArrowChar( index, event );
51cc4dad
RR
2858 }
2859 break;
cf1dfa6b 2860
51cc4dad 2861 case WXK_SPACE:
b54e41c5 2862 if ( IsSingleSel() )
33d0e17c 2863 {
a9aead31
VZ
2864 if ( event.ControlDown() )
2865 {
2866 ReverseHighlight(m_current);
2867 }
2868 else // normal space press
70541533 2869 {
a9aead31 2870 SendNotify( m_current, wxEVT_COMMAND_LIST_ITEM_ACTIVATED );
70541533 2871 }
33d0e17c 2872 }
a9aead31
VZ
2873 else // multiple selection
2874 {
2875 ReverseHighlight(m_current);
2876 }
51cc4dad 2877 break;
cf1dfa6b 2878
51cc4dad
RR
2879 case WXK_RETURN:
2880 case WXK_EXECUTE:
87948f22 2881 SendNotify( m_current, wxEVT_COMMAND_LIST_ITEM_ACTIVATED );
51cc4dad 2882 break;
cf1dfa6b 2883
51cc4dad 2884 default:
51cc4dad 2885 event.Skip();
e1e955e1 2886 }
e1e955e1 2887}
c801d85f 2888
cf1dfa6b
VZ
2889// ----------------------------------------------------------------------------
2890// focus handling
2891// ----------------------------------------------------------------------------
2892
c801d85f
KB
2893void wxListMainWindow::OnSetFocus( wxFocusEvent &WXUNUSED(event) )
2894{
dc76287d
RD
2895 if ( GetParent() )
2896 {
2897 wxFocusEvent event( wxEVT_SET_FOCUS, GetParent()->GetId() );
2898 event.SetEventObject( GetParent() );
2899 if ( GetParent()->GetEventHandler()->ProcessEvent( event) )
2900 return;
2901 }
2902
bde9072f
VZ
2903 // wxGTK sends us EVT_SET_FOCUS events even if we had never got
2904 // EVT_KILL_FOCUS before which means that we finish by redrawing the items
2905 // which are already drawn correctly resulting in horrible flicker - avoid
2906 // it
47724389
VZ
2907 if ( !m_hasFocus )
2908 {
ca65c044 2909 m_hasFocus = true;
bde9072f 2910
47724389
VZ
2911 RefreshSelected();
2912 }
e1e955e1 2913}
c801d85f
KB
2914
2915void wxListMainWindow::OnKillFocus( wxFocusEvent &WXUNUSED(event) )
2916{
dc76287d
RD
2917 if ( GetParent() )
2918 {
2919 wxFocusEvent event( wxEVT_KILL_FOCUS, GetParent()->GetId() );
2920 event.SetEventObject( GetParent() );
2921 if ( GetParent()->GetEventHandler()->ProcessEvent( event) )
2922 return;
2923 }
277ea1b4 2924
ca65c044 2925 m_hasFocus = false;
49ecb029 2926 RefreshSelected();
e1e955e1 2927}
c801d85f 2928
1e6d9499 2929void wxListMainWindow::DrawImage( int index, wxDC *dc, int x, int y )
c801d85f 2930{
cf1dfa6b 2931 if ( HasFlag(wxLC_ICON) && (m_normal_image_list))
63852e78
RR
2932 {
2933 m_normal_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT );
63852e78 2934 }
cf1dfa6b 2935 else if ( HasFlag(wxLC_SMALL_ICON) && (m_small_image_list))
63852e78
RR
2936 {
2937 m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT );
2938 }
cf1dfa6b 2939 else if ( HasFlag(wxLC_LIST) && (m_small_image_list))
0b855868
RR
2940 {
2941 m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT );
2942 }
b5d43d1d 2943 else if ( InReportView() && (m_small_image_list))
63852e78
RR
2944 {
2945 m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT );
63852e78 2946 }
e1e955e1 2947}
c801d85f 2948
5cd89174 2949void wxListMainWindow::GetImageSize( int index, int &width, int &height ) const
c801d85f 2950{
cf1dfa6b 2951 if ( HasFlag(wxLC_ICON) && m_normal_image_list )
63852e78
RR
2952 {
2953 m_normal_image_list->GetSize( index, width, height );
63852e78 2954 }
cf1dfa6b 2955 else if ( HasFlag(wxLC_SMALL_ICON) && m_small_image_list )
63852e78
RR
2956 {
2957 m_small_image_list->GetSize( index, width, height );
63852e78 2958 }
cf1dfa6b 2959 else if ( HasFlag(wxLC_LIST) && m_small_image_list )
0b855868
RR
2960 {
2961 m_small_image_list->GetSize( index, width, height );
0b855868 2962 }
b5d43d1d 2963 else if ( InReportView() && m_small_image_list )
63852e78
RR
2964 {
2965 m_small_image_list->GetSize( index, width, height );
63852e78 2966 }
cf1dfa6b
VZ
2967 else
2968 {
2969 width =
2970 height = 0;
2971 }
e1e955e1 2972}
c801d85f 2973
5cd89174 2974int wxListMainWindow::GetTextLength( const wxString &s ) const
c801d85f 2975{
5cd89174 2976 wxClientDC dc( wxConstCast(this, wxListMainWindow) );
cf1dfa6b 2977 dc.SetFont( GetFont() );
c801d85f 2978
cf1dfa6b
VZ
2979 wxCoord lw;
2980 dc.GetTextExtent( s, &lw, NULL );
2981
2982 return lw + AUTOSIZE_COL_MARGIN;
e1e955e1 2983}
c801d85f 2984
8a3e173a 2985void wxListMainWindow::SetImageList( wxImageList *imageList, int which )
c801d85f 2986{
ca65c044 2987 m_dirty = true;
f6bcfd97
BP
2988
2989 // calc the spacing from the icon size
277ea1b4
DS
2990 int width = 0, height = 0;
2991
f6bcfd97 2992 if ((imageList) && (imageList->GetImageCount()) )
f6bcfd97 2993 imageList->GetSize(0, width, height);
f6bcfd97
BP
2994
2995 if (which == wxIMAGE_LIST_NORMAL)
2996 {
2997 m_normal_image_list = imageList;
2998 m_normal_spacing = width + 8;
2999 }
3000
3001 if (which == wxIMAGE_LIST_SMALL)
3002 {
3003 m_small_image_list = imageList;
3004 m_small_spacing = width + 14;
ca7353de 3005 m_lineHeight = 0; // ensure that the line height will be recalc'd
f6bcfd97 3006 }
e1e955e1 3007}
c801d85f 3008
debe6624 3009void wxListMainWindow::SetItemSpacing( int spacing, bool isSmall )
c801d85f 3010{
ca65c044 3011 m_dirty = true;
139adb6a 3012 if (isSmall)
139adb6a 3013 m_small_spacing = spacing;
139adb6a 3014 else
139adb6a 3015 m_normal_spacing = spacing;
e1e955e1 3016}
c801d85f 3017
debe6624 3018int wxListMainWindow::GetItemSpacing( bool isSmall )
c801d85f 3019{
f6bcfd97 3020 return isSmall ? m_small_spacing : m_normal_spacing;
e1e955e1 3021}
c801d85f 3022
cf1dfa6b
VZ
3023// ----------------------------------------------------------------------------
3024// columns
3025// ----------------------------------------------------------------------------
3026
debe6624 3027void wxListMainWindow::SetColumn( int col, wxListItem &item )
c801d85f 3028{
222ed1d6 3029 wxListHeaderDataList::compatibility_iterator node = m_columns.Item( col );
f6bcfd97 3030
cf1dfa6b
VZ
3031 wxCHECK_RET( node, _T("invalid column index in SetColumn") );
3032
3033 if ( item.m_width == wxLIST_AUTOSIZE_USEHEADER )
3034 item.m_width = GetTextLength( item.m_text );
3035
3036 wxListHeaderData *column = node->GetData();
3037 column->SetItem( item );
3038
3039 wxListHeaderWindow *headerWin = GetListCtrl()->m_headerWin;
f6bcfd97 3040 if ( headerWin )
ca65c044 3041 headerWin->m_dirty = true;
cf1dfa6b 3042
ca65c044 3043 m_dirty = true;
cf1dfa6b
VZ
3044
3045 // invalidate it as it has to be recalculated
3046 m_headerWidth = 0;
e1e955e1 3047}
c801d85f 3048
debe6624 3049void wxListMainWindow::SetColumnWidth( int col, int width )
c801d85f 3050{
cf1dfa6b
VZ
3051 wxCHECK_RET( col >= 0 && col < GetColumnCount(),
3052 _T("invalid column index") );
3053
b5d43d1d 3054 wxCHECK_RET( InReportView(),
f6bcfd97 3055 _T("SetColumnWidth() can only be called in report mode.") );
7d7b3f69 3056
ca65c044 3057 m_dirty = true;
06cd40a8 3058
abe4a4f1
VS
3059 wxListHeaderWindow *headerWin = GetListCtrl()->m_headerWin;
3060 if ( headerWin )
ca65c044 3061 headerWin->m_dirty = true;
bd8289c1 3062
222ed1d6 3063 wxListHeaderDataList::compatibility_iterator node = m_columns.Item( col );
cf1dfa6b
VZ
3064 wxCHECK_RET( node, _T("no column?") );
3065
3066 wxListHeaderData *column = node->GetData();
3067
3068 size_t count = GetItemCount();
3069
f6bcfd97
BP
3070 if (width == wxLIST_AUTOSIZE_USEHEADER)
3071 {
cf1dfa6b 3072 width = GetTextLength(column->GetText());
d63c9ecf
VZ
3073 width += 2*EXTRA_WIDTH;
3074
3075 // check for column header's image availability
3076 const int image = column->GetImage();
3077 if ( image != -1 )
3078 {
3079 if ( m_small_image_list )
3080 {
3081 int ix = 0, iy = 0;
3082 m_small_image_list->GetSize(image, ix, iy);
3083 width += ix + HEADER_IMAGE_MARGIN_IN_REPORT_MODE;
3084 }
3085 }
f6bcfd97 3086 }
cf1dfa6b 3087 else if ( width == wxLIST_AUTOSIZE )
0180dad6 3088 {
cf1dfa6b
VZ
3089 if ( IsVirtual() )
3090 {
3091 // TODO: determine the max width somehow...
3092 width = WIDTH_COL_DEFAULT;
3093 }
3094 else // !virtual
0180dad6 3095 {
cf1dfa6b
VZ
3096 wxClientDC dc(this);
3097 dc.SetFont( GetFont() );
3098
3099 int max = AUTOSIZE_COL_MARGIN;
3100
7d4813a0
VZ
3101 // if the cached column width isn't valid then recalculate it
3102 if (m_aColWidths.Item(col)->bNeedsUpdate)
0180dad6 3103 {
7d4813a0
VZ
3104 for (size_t i = 0; i < count; i++)
3105 {
277ea1b4 3106 wxListLineData *line = GetLine( i );
7d4813a0 3107 wxListItemDataList::compatibility_iterator n = line->m_items.Item( col );
cf1dfa6b 3108
7d4813a0 3109 wxCHECK_RET( n, _T("no subitem?") );
cf1dfa6b 3110
7d4813a0
VZ
3111 wxListItemData *itemData = n->GetData();
3112 wxListItem item;
cf1dfa6b 3113
7d4813a0
VZ
3114 itemData->GetItem(item);
3115 int itemWidth = GetItemWidthWithImage(&item);
3116 if (itemWidth > max)
3117 max = itemWidth;
bffa1c77 3118 }
cf1dfa6b 3119
7d4813a0
VZ
3120 m_aColWidths.Item(col)->bNeedsUpdate = false;
3121 m_aColWidths.Item(col)->nMaxWidth = max;
0180dad6 3122 }
cf1dfa6b 3123
7d4813a0 3124 max = m_aColWidths.Item(col)->nMaxWidth;
cf1dfa6b 3125 width = max + AUTOSIZE_COL_MARGIN;
0180dad6 3126 }
0180dad6
RR
3127 }
3128
cf1dfa6b 3129 column->SetWidth( width );
bd8289c1 3130
cf1dfa6b
VZ
3131 // invalidate it as it has to be recalculated
3132 m_headerWidth = 0;
3133}
3134
3135int wxListMainWindow::GetHeaderWidth() const
3136{
3137 if ( !m_headerWidth )
0208334d 3138 {
cf1dfa6b
VZ
3139 wxListMainWindow *self = wxConstCast(this, wxListMainWindow);
3140
3141 size_t count = GetColumnCount();
3142 for ( size_t col = 0; col < count; col++ )
63852e78 3143 {
cf1dfa6b 3144 self->m_headerWidth += GetColumnWidth(col);
63852e78 3145 }
0208334d 3146 }
bd8289c1 3147
cf1dfa6b 3148 return m_headerWidth;
e1e955e1 3149}
c801d85f 3150
cf1dfa6b 3151void wxListMainWindow::GetColumn( int col, wxListItem &item ) const
c801d85f 3152{
222ed1d6 3153 wxListHeaderDataList::compatibility_iterator node = m_columns.Item( col );
cf1dfa6b
VZ
3154 wxCHECK_RET( node, _T("invalid column index in GetColumn") );
3155
3156 wxListHeaderData *column = node->GetData();
3157 column->GetItem( item );
e1e955e1 3158}
c801d85f 3159
cf1dfa6b 3160int wxListMainWindow::GetColumnWidth( int col ) const
c801d85f 3161{
222ed1d6 3162 wxListHeaderDataList::compatibility_iterator node = m_columns.Item( col );
24b9f055
VZ
3163 wxCHECK_MSG( node, 0, _T("invalid column index") );
3164
3165 wxListHeaderData *column = node->GetData();
3166 return column->GetWidth();
e1e955e1 3167}
c801d85f 3168
cf1dfa6b
VZ
3169// ----------------------------------------------------------------------------
3170// item state
3171// ----------------------------------------------------------------------------
c801d85f
KB
3172
3173void wxListMainWindow::SetItem( wxListItem &item )
3174{
cf1dfa6b
VZ
3175 long id = item.m_itemId;
3176 wxCHECK_RET( id >= 0 && (size_t)id < GetItemCount(),
3177 _T("invalid item index in SetItem") );
3178
6c02c329
VZ
3179 if ( !IsVirtual() )
3180 {
3181 wxListLineData *line = GetLine((size_t)id);
3182 line->SetItem( item.m_col, item );
7d4813a0 3183
39a7f085
VZ
3184 // Set item state if user wants
3185 if ( item.m_mask & wxLIST_MASK_STATE )
3186 SetItemState( item.m_itemId, item.m_state, item.m_state );
3187
7d4813a0
VZ
3188 if (InReportView())
3189 {
3190 // update the Max Width Cache if needed
3191 int width = GetItemWidthWithImage(&item);
3192
3193 if (width > m_aColWidths.Item(item.m_col)->nMaxWidth)
3194 m_aColWidths.Item(item.m_col)->nMaxWidth = width;
3195 }
6c02c329
VZ
3196 }
3197
285013b3
VZ
3198 // update the item on screen
3199 wxRect rectItem;
3200 GetItemRect(id, rectItem);
3201 RefreshRect(rectItem);
e1e955e1 3202}
c801d85f 3203
0afa5859
VZ
3204void wxListMainWindow::SetItemStateAll(long state, long stateMask)
3205{
3206 if ( IsEmpty() )
3207 return;
3208
3209 // first deal with selection
3210 if ( stateMask & wxLIST_STATE_SELECTED )
3211 {
3212 // set/clear select state
3213 if ( IsVirtual() )
3214 {
3215 // optimized version for virtual listctrl.
3216 m_selStore.SelectRange(0, GetItemCount() - 1, state == wxLIST_STATE_SELECTED);
3217 Refresh();
3218 }
3219 else if ( state & wxLIST_STATE_SELECTED )
3220 {
3221 const long count = GetItemCount();
3222 for( long i = 0; i < count; i++ )
3223 {
3224 SetItemState( i, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
3225 }
3226
3227 }
3228 else
3229 {
3230 // clear for non virtual (somewhat optimized by using GetNextItem())
3231 long i = -1;
3232 while ( (i = GetNextItem(i, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED)) != -1 )
3233 {
3234 SetItemState( i, 0, wxLIST_STATE_SELECTED );
3235 }
3236 }
3237 }
3238
3239 if ( HasCurrent() && (state == 0) && (stateMask & wxLIST_STATE_FOCUSED) )
3240 {
3241 // unfocus all: only one item can be focussed, so clearing focus for
3242 // all items is simply clearing focus of the focussed item.
3243 SetItemState(m_current, state, stateMask);
3244 }
3245 //(setting focus to all items makes no sense, so it is not handled here.)
3246}
3247
cf1dfa6b 3248void wxListMainWindow::SetItemState( long litem, long state, long stateMask )
c801d85f 3249{
0afa5859
VZ
3250 if ( litem == -1 )
3251 {
3252 SetItemStateAll(state, stateMask);
3253 return;
3254 }
3255
7448de8d
WS
3256 wxCHECK_RET( litem >= 0 && (size_t)litem < GetItemCount(),
3257 _T("invalid list ctrl item index in SetItem") );
54442116 3258
cf1dfa6b 3259 size_t oldCurrent = m_current;
88b792af 3260 size_t item = (size_t)litem; // safe because of the check above
bd8289c1 3261
88b792af 3262 // do we need to change the focus?
54442116 3263 if ( stateMask & wxLIST_STATE_FOCUSED )
c801d85f 3264 {
54442116 3265 if ( state & wxLIST_STATE_FOCUSED )
92976ab6 3266 {
54442116 3267 // don't do anything if this item is already focused
cf1dfa6b 3268 if ( item != m_current )
92976ab6 3269 {
0ddefeb0 3270 ChangeCurrent(item);
cf1dfa6b 3271
88b792af 3272 if ( oldCurrent != (size_t)-1 )
cf1dfa6b 3273 {
88b792af
VZ
3274 if ( IsSingleSel() )
3275 {
ca65c044 3276 HighlightLine(oldCurrent, false);
88b792af
VZ
3277 }
3278
cf1dfa6b
VZ
3279 RefreshLine(oldCurrent);
3280 }
54442116 3281
92976ab6 3282 RefreshLine( m_current );
92976ab6 3283 }
54442116
VZ
3284 }
3285 else // unfocus
3286 {
3287 // don't do anything if this item is not focused
cf1dfa6b 3288 if ( item == m_current )
bffa1c77 3289 {
0ddefeb0 3290 ResetCurrent();
88b792af 3291
943f6ad3
VZ
3292 if ( IsSingleSel() )
3293 {
3294 // we must unselect the old current item as well or we
3295 // might end up with more than one selected item in a
3296 // single selection control
ca65c044 3297 HighlightLine(oldCurrent, false);
943f6ad3
VZ
3298 }
3299
88b792af 3300 RefreshLine( oldCurrent );
bffa1c77 3301 }
92976ab6 3302 }
e1e955e1 3303 }
54442116 3304
88b792af 3305 // do we need to change the selection state?
54442116
VZ
3306 if ( stateMask & wxLIST_STATE_SELECTED )
3307 {
3308 bool on = (state & wxLIST_STATE_SELECTED) != 0;
54442116 3309
b54e41c5 3310 if ( IsSingleSel() )
54442116 3311 {
cf1dfa6b
VZ
3312 if ( on )
3313 {
3314 // selecting the item also makes it the focused one in the
3315 // single sel mode
3316 if ( m_current != item )
3317 {
0ddefeb0 3318 ChangeCurrent(item);
cf1dfa6b
VZ
3319
3320 if ( oldCurrent != (size_t)-1 )
3321 {
ca65c044 3322 HighlightLine( oldCurrent, false );
cf1dfa6b
VZ
3323 RefreshLine( oldCurrent );
3324 }
3325 }
3326 }
3327 else // off
3328 {
3329 // only the current item may be selected anyhow
3330 if ( item != m_current )
3331 return;
3332 }
54442116
VZ
3333 }
3334
b54e41c5 3335 if ( HighlightLine(item, on) )
54442116 3336 {
cf1dfa6b 3337 RefreshLine(item);
54442116
VZ
3338 }
3339 }
e1e955e1 3340}
c801d85f 3341
62d89eb4 3342int wxListMainWindow::GetItemState( long item, long stateMask ) const
c801d85f 3343{
cf1dfa6b
VZ
3344 wxCHECK_MSG( item >= 0 && (size_t)item < GetItemCount(), 0,
3345 _T("invalid list ctrl item index in GetItemState()") );
3346
92976ab6 3347 int ret = wxLIST_STATE_DONTCARE;
cf1dfa6b
VZ
3348
3349 if ( stateMask & wxLIST_STATE_FOCUSED )
c801d85f 3350 {
cf1dfa6b
VZ
3351 if ( (size_t)item == m_current )
3352 ret |= wxLIST_STATE_FOCUSED;
e1e955e1 3353 }
cf1dfa6b
VZ
3354
3355 if ( stateMask & wxLIST_STATE_SELECTED )
c801d85f 3356 {
b54e41c5 3357 if ( IsHighlighted(item) )
cf1dfa6b 3358 ret |= wxLIST_STATE_SELECTED;
e1e955e1 3359 }
cf1dfa6b 3360
92976ab6 3361 return ret;
e1e955e1 3362}
c801d85f 3363
62d89eb4 3364void wxListMainWindow::GetItem( wxListItem &item ) const
c801d85f 3365{
cf1dfa6b
VZ
3366 wxCHECK_RET( item.m_itemId >= 0 && (size_t)item.m_itemId < GetItemCount(),
3367 _T("invalid item index in GetItem") );
3368
3369 wxListLineData *line = GetLine((size_t)item.m_itemId);
3370 line->GetItem( item.m_col, item );
39a7f085
VZ
3371
3372 // Get item state if user wants it
3373 if ( item.m_mask & wxLIST_MASK_STATE )
3374 item.m_state = GetItemState( item.m_itemId, wxLIST_STATE_SELECTED |
3375 wxLIST_STATE_FOCUSED );
e1e955e1 3376}
c801d85f 3377
cf1dfa6b
VZ
3378// ----------------------------------------------------------------------------
3379// item count
3380// ----------------------------------------------------------------------------
3381
3382size_t wxListMainWindow::GetItemCount() const
1370703e
VZ
3383{
3384 return IsVirtual() ? m_countVirt : m_lines.GetCount();
3385}
3386
3387void wxListMainWindow::SetItemCount(long count)
c801d85f 3388{
b54e41c5 3389 m_selStore.SetItemCount(count);
1370703e
VZ
3390 m_countVirt = count;
3391
850ed6e7
VZ
3392 ResetVisibleLinesRange();
3393
5fe143df 3394 // scrollbars must be reset
ca65c044 3395 m_dirty = true;
e1e955e1 3396}
c801d85f 3397
62d89eb4 3398int wxListMainWindow::GetSelectedItemCount() const
c801d85f 3399{
cf1dfa6b 3400 // deal with the quick case first
b54e41c5 3401 if ( IsSingleSel() )
ca65c044 3402 return HasCurrent() ? IsHighlighted(m_current) : false;
cf1dfa6b
VZ
3403
3404 // virtual controls remmebers all its selections itself
3405 if ( IsVirtual() )
b54e41c5 3406 return m_selStore.GetSelectedCount();
cf1dfa6b
VZ
3407
3408 // TODO: we probably should maintain the number of items selected even for
3409 // non virtual controls as enumerating all lines is really slow...
3410 size_t countSel = 0;
3411 size_t count = GetItemCount();
3412 for ( size_t line = 0; line < count; line++ )
92976ab6 3413 {
b54e41c5 3414 if ( GetLine(line)->IsHighlighted() )
cf1dfa6b 3415 countSel++;
92976ab6 3416 }
c801d85f 3417
cf1dfa6b 3418 return countSel;
e1e955e1 3419}
e3e65dac 3420
cf1dfa6b
VZ
3421// ----------------------------------------------------------------------------
3422// item position/size
3423// ----------------------------------------------------------------------------
3424
11ebea16
VZ
3425wxRect wxListMainWindow::GetViewRect() const
3426{
929b7901 3427 wxASSERT_MSG( !HasFlag(wxLC_LIST), "not implemented for list view" );
11ebea16
VZ
3428
3429 // we need to find the longest/tallest label
277ea1b4 3430 wxCoord xMax = 0, yMax = 0;
11ebea16
VZ
3431 const int count = GetItemCount();
3432 if ( count )
3433 {
3434 for ( int i = 0; i < count; i++ )
3435 {
ebf82d2b
VZ
3436 // we need logical, not physical, coordinates here, so use
3437 // GetLineRect() instead of GetItemRect()
3438 wxRect r = GetLineRect(i);
11ebea16
VZ
3439
3440 wxCoord x = r.GetRight(),
3441 y = r.GetBottom();
3442
3443 if ( x > xMax )
3444 xMax = x;
3445 if ( y > yMax )
3446 yMax = y;
3447 }
3448 }
3449
eb6c4508 3450 // some fudge needed to make it look prettier
277ea1b4
DS
3451 xMax += 2 * EXTRA_BORDER_X;
3452 yMax += 2 * EXTRA_BORDER_Y;
eb6c4508
VZ
3453
3454 // account for the scrollbars if necessary
3455 const wxSize sizeAll = GetClientSize();
3456 if ( xMax > sizeAll.x )
3457 yMax += wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y);
3458 if ( yMax > sizeAll.y )
3459 xMax += wxSystemSettings::GetMetric(wxSYS_VSCROLL_X);
11ebea16
VZ
3460
3461 return wxRect(0, 0, xMax, yMax);
3462}
3463
e974c5d2
VZ
3464bool
3465wxListMainWindow::GetSubItemRect(long item, long subItem, wxRect& rect) const
c801d85f 3466{
b8e57034
VZ
3467 wxCHECK_MSG( subItem == wxLIST_GETSUBITEMRECT_WHOLEITEM || InReportView(),
3468 false,
e974c5d2
VZ
3469 _T("GetSubItemRect only meaningful in report view") );
3470 wxCHECK_MSG( item >= 0 && (size_t)item < GetItemCount(), false,
3471 _T("invalid item in GetSubItemRect") );
cf1dfa6b 3472
1e54be64
VZ
3473 // ensure that we're laid out, otherwise we could return nonsense
3474 if ( m_dirty )
3475 {
3476 wxConstCast(this, wxListMainWindow)->
ca65c044 3477 RecalculatePositions(true /* no refresh */);
1e54be64
VZ
3478 }
3479
e974c5d2
VZ
3480 rect = GetLineRect((size_t)item);
3481
3482 // Adjust rect to specified column
3483 if ( subItem != wxLIST_GETSUBITEMRECT_WHOLEITEM )
3484 {
3485 wxCHECK_MSG( subItem >= 0 && subItem < GetColumnCount(), false,
3486 _T("invalid subItem in GetSubItemRect") );
3487
3488 for (int i = 0; i < subItem; i++)
3489 {
3490 rect.x += GetColumnWidth(i);
3491 }
3492 rect.width = GetColumnWidth(subItem);
3493 }
b54e41c5 3494
06cd40a8 3495 GetListCtrl()->CalcScrolledPosition(rect.x, rect.y, &rect.x, &rect.y);
e974c5d2
VZ
3496
3497 return true;
e1e955e1 3498}
c801d85f 3499
62d89eb4 3500bool wxListMainWindow::GetItemPosition(long item, wxPoint& pos) const
c801d85f 3501{
cf1dfa6b
VZ
3502 wxRect rect;
3503 GetItemRect(item, rect);
bd8289c1 3504
cf1dfa6b
VZ
3505 pos.x = rect.x;
3506 pos.y = rect.y;
bd8289c1 3507
ca65c044 3508 return true;
e1e955e1 3509}
c801d85f 3510
cf1dfa6b
VZ
3511// ----------------------------------------------------------------------------
3512// geometry calculation
3513// ----------------------------------------------------------------------------
3514
34bbbc27 3515void wxListMainWindow::RecalculatePositions(bool noRefresh)
c801d85f 3516{
6d6d86a6
RD
3517 const int lineHeight = GetLineHeight();
3518
1e6d9499 3519 wxClientDC dc( this );
92976ab6 3520 dc.SetFont( GetFont() );
c801d85f 3521
13602ebd
VZ
3522 const size_t count = GetItemCount();
3523
cf1dfa6b 3524 int iconSpacing;
026d7276 3525 if ( HasFlag(wxLC_ICON) && m_normal_image_list )
cf1dfa6b 3526 iconSpacing = m_normal_spacing;
026d7276 3527 else if ( HasFlag(wxLC_SMALL_ICON) && m_small_image_list )
cf1dfa6b
VZ
3528 iconSpacing = m_small_spacing;
3529 else
3530 iconSpacing = 0;
004fd0c8 3531
bf632edd 3532 // Note that we do not call GetClientSize() here but
34621cc5 3533 // GetSize() and subtract the border size for sunken
bf632edd
RR
3534 // borders manually. This is technically incorrect,
3535 // but we need to know the client area's size WITHOUT
3536 // scrollbars here. Since we don't know if there are
3537 // any scrollbars, we use GetSize() instead. Another
3538 // solution would be to call SetScrollbars() here to
3539 // remove the scrollbars and call GetClientSize() then,
3540 // but this might result in flicker and - worse - will
3541 // reset the scrollbars to 0 which is not good at all
3542 // if you resize a dialog/window, but don't want to
3543 // reset the window scrolling. RR.
3544 // Furthermore, we actually do NOT subtract the border
3545 // width as 2 pixels is just the extra space which we
3546 // need around the actual content in the window. Other-
3547 // wise the text would e.g. touch the upper border. RR.
cf1dfa6b
VZ
3548 int clientWidth,
3549 clientHeight;
bf632edd 3550 GetSize( &clientWidth, &clientHeight );
a77ec46d 3551
b5d43d1d 3552 if ( InReportView() )
cf1dfa6b 3553 {
13602ebd 3554 // all lines have the same height and we scroll one line per step
277ea1b4 3555 int entireHeight = count * lineHeight + LINE_SPACING;
bd8289c1 3556
b54e41c5
VZ
3557 m_linesPerPage = clientHeight / lineHeight;
3558
3559 ResetVisibleLinesRange();
2c1f73ee 3560
06cd40a8 3561 GetListCtrl()->SetScrollbars( SCROLL_UNIT_X, lineHeight,
13602ebd
VZ
3562 GetHeaderWidth() / SCROLL_UNIT_X,
3563 (entireHeight + lineHeight - 1) / lineHeight,
06cd40a8
RR
3564 GetListCtrl()->GetScrollPos(wxHORIZONTAL),
3565 GetListCtrl()->GetScrollPos(wxVERTICAL),
ca65c044 3566 true );
e1e955e1 3567 }
cf1dfa6b 3568 else // !report
92976ab6 3569 {
13602ebd
VZ
3570 // we have 3 different layout strategies: either layout all items
3571 // horizontally/vertically (wxLC_ALIGN_XXX styles explicitly given) or
3572 // to arrange them in top to bottom, left to right (don't ask me why
3573 // not the other way round...) order
3574 if ( HasFlag(wxLC_ALIGN_LEFT | wxLC_ALIGN_TOP) )
e487524e 3575 {
13602ebd
VZ
3576 int x = EXTRA_BORDER_X;
3577 int y = EXTRA_BORDER_Y;
cf1dfa6b 3578
94dd23ae
VZ
3579 wxCoord widthMax = 0;
3580
3581 size_t i;
3582 for ( i = 0; i < count; i++ )
92976ab6 3583 {
cf1dfa6b 3584 wxListLineData *line = GetLine(i);
92976ab6 3585 line->CalculateSize( &dc, iconSpacing );
13602ebd 3586 line->SetPosition( x, y, iconSpacing );
cf1dfa6b 3587
5cd89174 3588 wxSize sizeLine = GetLineSize(i);
cf1dfa6b 3589
13602ebd
VZ
3590 if ( HasFlag(wxLC_ALIGN_TOP) )
3591 {
94dd23ae
VZ
3592 if ( sizeLine.x > widthMax )
3593 widthMax = sizeLine.x;
3594
13602ebd
VZ
3595 y += sizeLine.y;
3596 }
3597 else // wxLC_ALIGN_LEFT
3598 {
3599 x += sizeLine.x + MARGIN_BETWEEN_ROWS;
3600 }
3601 }
3602
94dd23ae
VZ
3603 if ( HasFlag(wxLC_ALIGN_TOP) )
3604 {
3605 // traverse the items again and tweak their sizes so that they are
3606 // all the same in a row
3607 for ( i = 0; i < count; i++ )
3608 {
3609 wxListLineData *line = GetLine(i);
3610 line->m_gi->ExtendWidth(widthMax);
3611 }
3612 }
3613
06cd40a8 3614 GetListCtrl()->SetScrollbars
13602ebd
VZ
3615 (
3616 SCROLL_UNIT_X,
6d78bbe6 3617 lineHeight,
13602ebd 3618 (x + SCROLL_UNIT_X) / SCROLL_UNIT_X,
6d78bbe6 3619 (y + lineHeight) / lineHeight,
06cd40a8
RR
3620 GetListCtrl()->GetScrollPos( wxHORIZONTAL ),
3621 GetListCtrl()->GetScrollPos( wxVERTICAL ),
ca65c044 3622 true
13602ebd
VZ
3623 );
3624 }
3625 else // "flowed" arrangement, the most complicated case
3626 {
3627 // at first we try without any scrollbars, if the items don't fit into
3628 // the window, we recalculate after subtracting the space taken by the
3629 // scrollbar
3630
8a39593e 3631 int entireWidth = 0;
cf1dfa6b 3632
13602ebd
VZ
3633 for (int tries = 0; tries < 2; tries++)
3634 {
277ea1b4 3635 entireWidth = 2 * EXTRA_BORDER_X;
cf1dfa6b 3636
13602ebd 3637 if (tries == 1)
92976ab6 3638 {
13602ebd
VZ
3639 // Now we have decided that the items do not fit into the
3640 // client area, so we need a scrollbar
3641 entireWidth += SCROLL_UNIT_X;
92976ab6 3642 }
a77ec46d 3643
13602ebd
VZ
3644 int x = EXTRA_BORDER_X;
3645 int y = EXTRA_BORDER_Y;
3646 int maxWidthInThisRow = 0;
3647
3648 m_linesPerPage = 0;
3649 int currentlyVisibleLines = 0;
a77ec46d 3650
13602ebd 3651 for (size_t i = 0; i < count; i++)
92976ab6 3652 {
13602ebd 3653 currentlyVisibleLines++;
277ea1b4 3654 wxListLineData *line = GetLine( i );
13602ebd
VZ
3655 line->CalculateSize( &dc, iconSpacing );
3656 line->SetPosition( x, y, iconSpacing );
3657
277ea1b4 3658 wxSize sizeLine = GetLineSize( i );
a77ec46d 3659
13602ebd
VZ
3660 if ( maxWidthInThisRow < sizeLine.x )
3661 maxWidthInThisRow = sizeLine.x;
3662
3663 y += sizeLine.y;
3664 if (currentlyVisibleLines > m_linesPerPage)
3665 m_linesPerPage = currentlyVisibleLines;
3666
3667 if ( y + sizeLine.y >= clientHeight )
3668 {
3669 currentlyVisibleLines = 0;
3670 y = EXTRA_BORDER_Y;
3671 maxWidthInThisRow += MARGIN_BETWEEN_ROWS;
3672 x += maxWidthInThisRow;
3673 entireWidth += maxWidthInThisRow;
3674 maxWidthInThisRow = 0;
3675 }
3676
3677 // We have reached the last item.
3678 if ( i == count - 1 )
3679 entireWidth += maxWidthInThisRow;
3680
3681 if ( (tries == 0) &&
3682 (entireWidth + SCROLL_UNIT_X > clientWidth) )
3683 {
3684 clientHeight -= wxSystemSettings::
3685 GetMetric(wxSYS_HSCROLL_Y);
3686 m_linesPerPage = 0;
13602ebd
VZ
3687 break;
3688 }
3689
3690 if ( i == count - 1 )
3691 tries = 1; // Everything fits, no second try required.
3692 }
92976ab6 3693 }
bffa1c77 3694
06cd40a8 3695 GetListCtrl()->SetScrollbars
13602ebd
VZ
3696 (
3697 SCROLL_UNIT_X,
6d78bbe6 3698 lineHeight,
13602ebd
VZ
3699 (entireWidth + SCROLL_UNIT_X) / SCROLL_UNIT_X,
3700 0,
06cd40a8 3701 GetListCtrl()->GetScrollPos( wxHORIZONTAL ),
13602ebd 3702 0,
ca65c044 3703 true
13602ebd
VZ
3704 );
3705 }
e1e955e1 3706 }
cf1dfa6b 3707
34bbbc27
VZ
3708 if ( !noRefresh )
3709 {
3710 // FIXME: why should we call it from here?
3711 UpdateCurrent();
b54e41c5 3712
34bbbc27
VZ
3713 RefreshAll();
3714 }
b54e41c5
VZ
3715}
3716
3717void wxListMainWindow::RefreshAll()
3718{
ca65c044 3719 m_dirty = false;
b54e41c5
VZ
3720 Refresh();
3721
3722 wxListHeaderWindow *headerWin = GetListCtrl()->m_headerWin;
70541533 3723 if ( headerWin && headerWin->m_dirty )
b54e41c5 3724 {
ca65c044 3725 headerWin->m_dirty = false;
b54e41c5
VZ
3726 headerWin->Refresh();
3727 }
e1e955e1 3728}
c801d85f 3729
cf1dfa6b 3730void wxListMainWindow::UpdateCurrent()
c801d85f 3731{
b54e41c5 3732 if ( !HasCurrent() && !IsEmpty() )
0ddefeb0 3733 ChangeCurrent(0);
e1e955e1 3734}
c801d85f 3735
19695fbd
VZ
3736long wxListMainWindow::GetNextItem( long item,
3737 int WXUNUSED(geometry),
62d89eb4 3738 int state ) const
c801d85f 3739{
d1022fd6
VZ
3740 long ret = item,
3741 max = GetItemCount();
3742 wxCHECK_MSG( (ret == -1) || (ret < max), -1,
13771c08 3743 _T("invalid listctrl index in GetNextItem()") );
19695fbd
VZ
3744
3745 // notice that we start with the next item (or the first one if item == -1)
3746 // and this is intentional to allow writing a simple loop to iterate over
3747 // all selected items
d1022fd6
VZ
3748 ret++;
3749 if ( ret == max )
277ea1b4
DS
3750 // this is not an error because the index was OK initially,
3751 // just no such item
d1022fd6 3752 return -1;
d1022fd6 3753
cf1dfa6b 3754 if ( !state )
cf1dfa6b
VZ
3755 // any will do
3756 return (size_t)ret;
cf1dfa6b
VZ
3757
3758 size_t count = GetItemCount();
3759 for ( size_t line = (size_t)ret; line < count; line++ )
63852e78 3760 {
cf1dfa6b
VZ
3761 if ( (state & wxLIST_STATE_FOCUSED) && (line == m_current) )
3762 return line;
3763
b54e41c5 3764 if ( (state & wxLIST_STATE_SELECTED) && IsHighlighted(line) )
cf1dfa6b 3765 return line;
63852e78 3766 }
19695fbd 3767
63852e78 3768 return -1;
e1e955e1 3769}
c801d85f 3770
cf1dfa6b
VZ
3771// ----------------------------------------------------------------------------
3772// deleting stuff
3773// ----------------------------------------------------------------------------
3774
b54e41c5 3775void wxListMainWindow::DeleteItem( long lindex )
c801d85f 3776{
cf1dfa6b
VZ
3777 size_t count = GetItemCount();
3778
b54e41c5 3779 wxCHECK_RET( (lindex >= 0) && ((size_t)lindex < count),
cf1dfa6b
VZ
3780 _T("invalid item index in DeleteItem") );
3781
b54e41c5
VZ
3782 size_t index = (size_t)lindex;
3783
d6ddcd57
VZ
3784 // we don't need to adjust the index for the previous items
3785 if ( HasCurrent() && m_current >= index )
cf1dfa6b 3786 {
d6ddcd57
VZ
3787 // if the current item is being deleted, we want the next one to
3788 // become selected - unless there is no next one - so don't adjust
3789 // m_current in this case
3790 if ( m_current != index || m_current == count - 1 )
d6ddcd57 3791 m_current--;
cf1dfa6b 3792 }
6fef2483 3793
938b652b 3794 if ( InReportView() )
63852e78 3795 {
a95d5751
RR
3796 // mark the Column Max Width cache as dirty if the items in the line
3797 // we're deleting contain the Max Column Width
7d4813a0
VZ
3798 wxListLineData * const line = GetLine(index);
3799 wxListItemDataList::compatibility_iterator n;
3800 wxListItemData *itemData;
3801 wxListItem item;
3802 int itemWidth;
3803
3804 for (size_t i = 0; i < m_columns.GetCount(); i++)
3805 {
3806 n = line->m_items.Item( i );
3807 itemData = n->GetData();
3808 itemData->GetItem(item);
3809
3810 itemWidth = GetItemWidthWithImage(&item);
3811
3812 if (itemWidth >= m_aColWidths.Item(i)->nMaxWidth)
3813 m_aColWidths.Item(i)->bNeedsUpdate = true;
3814 }
3815
6b4a8d93 3816 ResetVisibleLinesRange();
938b652b
VZ
3817 }
3818
a95d5751
RR
3819 SendNotify( index, wxEVT_COMMAND_LIST_DELETE_ITEM, wxDefaultPosition );
3820
938b652b
VZ
3821 if ( IsVirtual() )
3822 {
3823 m_countVirt--;
b54e41c5
VZ
3824 m_selStore.OnItemDelete(index);
3825 }
3826 else
3827 {
3828 m_lines.RemoveAt( index );
63852e78 3829 }
6b4a8d93 3830
70541533 3831 // we need to refresh the (vert) scrollbar as the number of items changed
ca65c044 3832 m_dirty = true;
91c6cc0e 3833
6b4a8d93 3834 RefreshAfter(index);
e1e955e1 3835}
c801d85f 3836
debe6624 3837void wxListMainWindow::DeleteColumn( int col )
c801d85f 3838{
222ed1d6 3839 wxListHeaderDataList::compatibility_iterator node = m_columns.Item( col );
24b9f055
VZ
3840
3841 wxCHECK_RET( node, wxT("invalid column index in DeleteColumn()") );
bd8289c1 3842
ca65c044 3843 m_dirty = true;
222ed1d6
MB
3844 delete node->GetData();
3845 m_columns.Erase( node );
ae409cb8 3846
df6f82f0
VZ
3847 if ( !IsVirtual() )
3848 {
3849 // update all the items
3850 for ( size_t i = 0; i < m_lines.GetCount(); i++ )
3851 {
3852 wxListLineData * const line = GetLine(i);
222ed1d6
MB
3853 wxListItemDataList::compatibility_iterator n = line->m_items.Item( col );
3854 delete n->GetData();
3855 line->m_items.Erase(n);
df6f82f0
VZ
3856 }
3857 }
3858
7d4813a0
VZ
3859 if ( InReportView() ) // we only cache max widths when in Report View
3860 {
3861 delete m_aColWidths.Item(col);
3862 m_aColWidths.RemoveAt(col);
3863 }
3864
ae409cb8
VZ
3865 // invalidate it as it has to be recalculated
3866 m_headerWidth = 0;
e1e955e1 3867}
c801d85f 3868
5fe143df 3869void wxListMainWindow::DoDeleteAllItems()
c801d85f 3870{
cf1dfa6b 3871 if ( IsEmpty() )
cf1dfa6b
VZ
3872 // nothing to do - in particular, don't send the event
3873 return;
cf1dfa6b 3874
b54e41c5 3875 ResetCurrent();
7c0ea335
VZ
3876
3877 // to make the deletion of all items faster, we don't send the
cf1dfa6b
VZ
3878 // notifications for each item deletion in this case but only one event
3879 // for all of them: this is compatible with wxMSW and documented in
3880 // DeleteAllItems() description
bffa1c77 3881
12c1b46a
RR
3882 wxListEvent event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS, GetParent()->GetId() );
3883 event.SetEventObject( GetParent() );
3884 GetParent()->GetEventHandler()->ProcessEvent( event );
7c0ea335 3885
b54e41c5
VZ
3886 if ( IsVirtual() )
3887 {
3888 m_countVirt = 0;
850ed6e7 3889 m_selStore.Clear();
b54e41c5
VZ
3890 }
3891
6b4a8d93
VZ
3892 if ( InReportView() )
3893 {
3894 ResetVisibleLinesRange();
7d4813a0
VZ
3895 for (size_t i = 0; i < m_aColWidths.GetCount(); i++)
3896 {
8d36b216 3897 m_aColWidths.Item(i)->bNeedsUpdate = true;
7d4813a0 3898 }
6b4a8d93
VZ
3899 }
3900
5b077d48 3901 m_lines.Clear();
5fe143df 3902}
cf1dfa6b 3903
5fe143df
VZ
3904void wxListMainWindow::DeleteAllItems()
3905{
3906 DoDeleteAllItems();
3907
3908 RecalculatePositions();
e1e955e1 3909}
c801d85f 3910
12c1b46a 3911void wxListMainWindow::DeleteEverything()
c801d85f 3912{
222ed1d6 3913 WX_CLEAR_LIST(wxListHeaderDataList, m_columns);
8d36b216 3914 WX_CLEAR_ARRAY(m_aColWidths);
904ccf52
VZ
3915
3916 DeleteAllItems();
e1e955e1 3917}
c801d85f 3918
cf1dfa6b
VZ
3919// ----------------------------------------------------------------------------
3920// scanning for an item
3921// ----------------------------------------------------------------------------
3922
debe6624 3923void wxListMainWindow::EnsureVisible( long index )
c801d85f 3924{
cf1dfa6b
VZ
3925 wxCHECK_RET( index >= 0 && (size_t)index < GetItemCount(),
3926 _T("invalid index in EnsureVisible") );
3927
3928 // We have to call this here because the label in question might just have
34bbbc27
VZ
3929 // been added and its position is not known yet
3930 if ( m_dirty )
ca65c044 3931 RecalculatePositions(true /* no refresh */);
34bbbc27
VZ
3932
3933 MoveToItem((size_t)index);
e1e955e1 3934}
c801d85f 3935
23739465 3936long wxListMainWindow::FindItem(long start, const wxString& str, bool partial )
c801d85f 3937{
23739465
RR
3938 if (str.empty())
3939 return wxNOT_FOUND;
6fef2483 3940
5b077d48 3941 long pos = start;
23739465 3942 wxString str_upper = str.Upper();
cf1dfa6b
VZ
3943 if (pos < 0)
3944 pos = 0;
54442116 3945
cf1dfa6b
VZ
3946 size_t count = GetItemCount();
3947 for ( size_t i = (size_t)pos; i < count; i++ )
3948 {
3949 wxListLineData *line = GetLine(i);
23739465
RR
3950 wxString line_upper = line->GetText(0).Upper();
3951 if (!partial)
3952 {
3953 if (line_upper == str_upper )
3954 return i;
3955 }
3956 else
3957 {
3958 if (line_upper.find(str_upper) == 0)
3959 return i;
3960 }
5b077d48 3961 }
cf1dfa6b
VZ
3962
3963 return wxNOT_FOUND;
e1e955e1 3964}
c801d85f 3965
81ce36aa 3966long wxListMainWindow::FindItem(long start, wxUIntPtr data)
c801d85f 3967{
5b077d48 3968 long pos = start;
cf1dfa6b
VZ
3969 if (pos < 0)
3970 pos = 0;
3971
3972 size_t count = GetItemCount();
3973 for (size_t i = (size_t)pos; i < count; i++)
5b077d48 3974 {
cf1dfa6b 3975 wxListLineData *line = GetLine(i);
5b077d48
RR
3976 wxListItem item;
3977 line->GetItem( 0, item );
cf1dfa6b
VZ
3978 if (item.m_data == data)
3979 return i;
5b077d48 3980 }
cf1dfa6b
VZ
3981
3982 return wxNOT_FOUND;
e1e955e1 3983}
c801d85f 3984
8158e0e1
VZ
3985long wxListMainWindow::FindItem( const wxPoint& pt )
3986{
e6bf9573 3987 size_t topItem;
277ea1b4 3988 GetVisibleLinesRange( &topItem, NULL );
8158e0e1 3989
e6bf9573 3990 wxPoint p;
277ea1b4
DS
3991 GetItemPosition( GetItemCount() - 1, p );
3992 if ( p.y == 0 )
e6bf9573 3993 return topItem;
277ea1b4
DS
3994
3995 long id = (long)floor( pt.y * double(GetItemCount() - topItem - 1) / p.y + topItem );
3996 if ( id >= 0 && id < (long)GetItemCount() )
e6bf9573 3997 return id;
8158e0e1 3998
e6bf9573 3999 return wxNOT_FOUND;
8158e0e1
VZ
4000}
4001
be0e5d69 4002long wxListMainWindow::HitTest( int x, int y, int &flags ) const
c801d85f 4003{
06cd40a8 4004 GetListCtrl()->CalcUnscrolledPosition( x, y, &x, &y );
e8741cca 4005
fc4f1d5f
VZ
4006 size_t count = GetItemCount();
4007
b5d43d1d 4008 if ( InReportView() )
c801d85f 4009 {
5cd89174 4010 size_t current = y / GetLineHeight();
fc4f1d5f
VZ
4011 if ( current < count )
4012 {
4013 flags = HitTestLine(current, x, y);
4014 if ( flags )
4015 return current;
4016 }
5cd89174
VZ
4017 }
4018 else // !report
4019 {
4020 // TODO: optimize it too! this is less simple than for report view but
4021 // enumerating all items is still not a way to do it!!
5cd89174 4022 for ( size_t current = 0; current < count; current++ )
5b077d48 4023 {
5cd89174
VZ
4024 flags = HitTestLine(current, x, y);
4025 if ( flags )
4026 return current;
5b077d48 4027 }
e1e955e1 4028 }
cf1dfa6b
VZ
4029
4030 return wxNOT_FOUND;
e1e955e1 4031}
c801d85f 4032
cf1dfa6b
VZ
4033// ----------------------------------------------------------------------------
4034// adding stuff
4035// ----------------------------------------------------------------------------
4036
c801d85f
KB
4037void wxListMainWindow::InsertItem( wxListItem &item )
4038{
cf1dfa6b
VZ
4039 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual control") );
4040
c7cf7a78 4041 int count = GetItemCount();
33c956e6 4042 wxCHECK_RET( item.m_itemId >= 0, _T("invalid item index") );
cf1dfa6b 4043
33c956e6
RD
4044 if (item.m_itemId > count)
4045 item.m_itemId = count;
b713f891 4046
cf1dfa6b
VZ
4047 size_t id = item.m_itemId;
4048
ca65c044 4049 m_dirty = true;
cf1dfa6b 4050
b5d43d1d 4051 if ( InReportView() )
2b5f62a0 4052 {
2b5f62a0 4053 ResetVisibleLinesRange();
7d4813a0
VZ
4054
4055 // calculate the width of the item and adjust the max column width
4056 wxColWidthInfo *pWidthInfo = m_aColWidths.Item(item.GetColumn());
f5c479cc 4057 int width = GetItemWidthWithImage(&item);
7d4813a0
VZ
4058 item.SetWidth(width);
4059 if (width > pWidthInfo->nMaxWidth)
4060 pWidthInfo->nMaxWidth = width;
1370703e 4061 }
004fd0c8 4062
5cd89174 4063 wxListLineData *line = new wxListLineData(this);
004fd0c8 4064
1e6601c7 4065 line->SetItem( item.m_col, item );
cf1dfa6b
VZ
4066
4067 m_lines.Insert( line, id );
5cd89174 4068
ca65c044 4069 m_dirty = true;
a67e6e54 4070
ab96d680
VZ
4071 // If an item is selected at or below the point of insertion, we need to
4072 // increment the member variables because the current row's index has gone
4073 // up by one
4074 if ( HasCurrent() && m_current >= id )
ab96d680 4075 m_current++;
ab96d680 4076
a67e6e54
VZ
4077 SendNotify(id, wxEVT_COMMAND_LIST_INSERT_ITEM);
4078
5cd89174 4079 RefreshLines(id, GetItemCount() - 1);
e1e955e1 4080}
c801d85f 4081
debe6624 4082void wxListMainWindow::InsertColumn( long col, wxListItem &item )
c801d85f 4083{
ca65c044 4084 m_dirty = true;
b5d43d1d 4085 if ( InReportView() )
3db7be80 4086 {
54442116
VZ
4087 if (item.m_width == wxLIST_AUTOSIZE_USEHEADER)
4088 item.m_width = GetTextLength( item.m_text );
df6f82f0 4089
5b077d48 4090 wxListHeaderData *column = new wxListHeaderData( item );
7d4813a0
VZ
4091 wxColWidthInfo *colWidthInfo = new wxColWidthInfo();
4092
df6f82f0
VZ
4093 bool insert = (col >= 0) && ((size_t)col < m_columns.GetCount());
4094 if ( insert )
5b077d48 4095 {
7d4813a0
VZ
4096 wxListHeaderDataList::compatibility_iterator
4097 node = m_columns.Item( col );
24b9f055 4098 m_columns.Insert( node, column );
7d4813a0 4099 m_aColWidths.Insert( colWidthInfo, col );
5b077d48
RR
4100 }
4101 else
4102 {
4103 m_columns.Append( column );
7d4813a0 4104 m_aColWidths.Add( colWidthInfo );
5b077d48 4105 }
ae409cb8 4106
df6f82f0
VZ
4107 if ( !IsVirtual() )
4108 {
4109 // update all the items
4110 for ( size_t i = 0; i < m_lines.GetCount(); i++ )
4111 {
4112 wxListLineData * const line = GetLine(i);
4113 wxListItemData * const data = new wxListItemData(this);
4114 if ( insert )
4115 line->m_items.Insert(col, data);
4116 else
4117 line->m_items.Append(data);
4118 }
4119 }
4120
ae409cb8
VZ
4121 // invalidate it as it has to be recalculated
4122 m_headerWidth = 0;
3db7be80 4123 }
e1e955e1 4124}
c801d85f 4125
7d4813a0
VZ
4126int wxListMainWindow::GetItemWidthWithImage(wxListItem * item)
4127{
4128 int width = 0;
4129 wxClientDC dc(this);
4130
4131 dc.SetFont( GetFont() );
4132
4133 if (item->GetImage() != -1)
4134 {
4135 int ix, iy;
4136 GetImageSize( item->GetImage(), ix, iy );
4137 width += ix + 5;
4138 }
4139
4140 if (!item->GetText().empty())
4141 {
4142 wxCoord w;
4143 dc.GetTextExtent( item->GetText(), &w, NULL );
4144 width += w;
4145 }
4146
4147 return width;
4148}
4149
cf1dfa6b
VZ
4150// ----------------------------------------------------------------------------
4151// sorting
4152// ----------------------------------------------------------------------------
4153
7d7b3f69
FM
4154static wxListCtrlCompare list_ctrl_compare_func_2;
4155static long list_ctrl_compare_data;
c801d85f 4156
f6bcfd97 4157int LINKAGEMODE list_ctrl_compare_func_1( wxListLineData **arg1, wxListLineData **arg2 )
c801d85f 4158{
f6bcfd97
BP
4159 wxListLineData *line1 = *arg1;
4160 wxListLineData *line2 = *arg2;
5b077d48
RR
4161 wxListItem item;
4162 line1->GetItem( 0, item );
81ce36aa 4163 wxUIntPtr data1 = item.m_data;
5b077d48 4164 line2->GetItem( 0, item );
81ce36aa 4165 wxUIntPtr data2 = item.m_data;
5b077d48 4166 return list_ctrl_compare_func_2( data1, data2, list_ctrl_compare_data );
e1e955e1 4167}
c801d85f
KB
4168
4169void wxListMainWindow::SortItems( wxListCtrlCompare fn, long data )
4170{
6b06a727
VZ
4171 // selections won't make sense any more after sorting the items so reset
4172 // them
4173 HighlightAll(false);
4174 ResetCurrent();
4175
5b077d48
RR
4176 list_ctrl_compare_func_2 = fn;
4177 list_ctrl_compare_data = data;
4178 m_lines.Sort( list_ctrl_compare_func_1 );
ca65c044 4179 m_dirty = true;
e1e955e1 4180}
c801d85f 4181
cf1dfa6b
VZ
4182// ----------------------------------------------------------------------------
4183// scrolling
4184// ----------------------------------------------------------------------------
4185
7c74e7fe
SC
4186void wxListMainWindow::OnScroll(wxScrollWinEvent& event)
4187{
602e3365
RR
4188 // update our idea of which lines are shown when we redraw the window the
4189 // next time
4190 ResetVisibleLinesRange();
a9aead31 4191
cf1dfa6b 4192 if ( event.GetOrientation() == wxHORIZONTAL && HasHeader() )
7c74e7fe 4193 {
3cd94a0d 4194 wxGenericListCtrl* lc = GetListCtrl();
cf1dfa6b
VZ
4195 wxCHECK_RET( lc, _T("no listctrl window?") );
4196
52d2a5e4
FM
4197 if (lc->m_headerWin) // when we use wxLC_NO_HEADER, m_headerWin==NULL
4198 {
4199 lc->m_headerWin->Refresh();
4200 lc->m_headerWin->Update();
4201 }
7c74e7fe 4202 }
cf1dfa6b
VZ
4203}
4204
5cd89174
VZ
4205int wxListMainWindow::GetCountPerPage() const
4206{
4207 if ( !m_linesPerPage )
4208 {
4209 wxConstCast(this, wxListMainWindow)->
4210 m_linesPerPage = GetClientSize().y / GetLineHeight();
4211 }
4212
4213 return m_linesPerPage;
4214}
4215
b54e41c5 4216void wxListMainWindow::GetVisibleLinesRange(size_t *from, size_t *to)
cf1dfa6b 4217{
b5d43d1d 4218 wxASSERT_MSG( InReportView(), _T("this is for report mode only") );
cf1dfa6b 4219
b54e41c5
VZ
4220 if ( m_lineFrom == (size_t)-1 )
4221 {
b54e41c5 4222 size_t count = GetItemCount();
6522713c
VZ
4223 if ( count )
4224 {
e5d28ed4 4225 m_lineFrom = GetListCtrl()->GetScrollPos(wxVERTICAL);
cf1dfa6b 4226
152c57f2
VZ
4227 // this may happen if SetScrollbars() hadn't been called yet
4228 if ( m_lineFrom >= count )
bcc0da5c 4229 m_lineFrom = count - 1;
cf1dfa6b 4230
6522713c
VZ
4231 // we redraw one extra line but this is needed to make the redrawing
4232 // logic work when there is a fractional number of lines on screen
4233 m_lineTo = m_lineFrom + m_linesPerPage;
4234 if ( m_lineTo >= count )
4235 m_lineTo = count - 1;
4236 }
4237 else // empty control
4238 {
4239 m_lineFrom = 0;
4240 m_lineTo = (size_t)-1;
4241 }
cf1dfa6b 4242 }
b54e41c5 4243
ae167d2f
VZ
4244 wxASSERT_MSG( IsEmpty() ||
4245 (m_lineFrom <= m_lineTo && m_lineTo < GetItemCount()),
6b4a8d93
VZ
4246 _T("GetVisibleLinesRange() returns incorrect result") );
4247
b54e41c5
VZ
4248 if ( from )
4249 *from = m_lineFrom;
4250 if ( to )
4251 *to = m_lineTo;
7c74e7fe
SC
4252}
4253
c801d85f 4254// -------------------------------------------------------------------------------------
3cd94a0d 4255// wxGenericListCtrl
c801d85f
KB
4256// -------------------------------------------------------------------------------------
4257
3cd94a0d
JS
4258IMPLEMENT_DYNAMIC_CLASS(wxGenericListCtrl, wxControl)
4259
3cd94a0d
JS
4260BEGIN_EVENT_TABLE(wxGenericListCtrl,wxControl)
4261 EVT_SIZE(wxGenericListCtrl::OnSize)
06cd40a8 4262 EVT_SCROLLWIN(wxGenericListCtrl::OnScroll)
c801d85f
KB
4263END_EVENT_TABLE()
4264
06cd40a8 4265void wxGenericListCtrl::Init()
c801d85f 4266{
d3b9f782
VZ
4267 m_imageListNormal = NULL;
4268 m_imageListSmall = NULL;
4269 m_imageListState = NULL;
cf1dfa6b
VZ
4270
4271 m_ownsImageListNormal =
4272 m_ownsImageListSmall =
ca65c044 4273 m_ownsImageListState = false;
cf1dfa6b 4274
d3b9f782
VZ
4275 m_mainWin = NULL;
4276 m_headerWin = NULL;
06cd40a8 4277 m_headerHeight = wxRendererNative::Get().GetHeaderButtonHeight(this);
c801d85f
KB
4278}
4279
3cd94a0d 4280wxGenericListCtrl::~wxGenericListCtrl()
c801d85f 4281{
cf1dfa6b
VZ
4282 if (m_ownsImageListNormal)
4283 delete m_imageListNormal;
4284 if (m_ownsImageListSmall)
4285 delete m_imageListSmall;
4286 if (m_ownsImageListState)
4287 delete m_imageListState;
4288}
4289
06cd40a8 4290void wxGenericListCtrl::CreateOrDestroyHeaderWindowAsNeeded()
f8252483 4291{
06cd40a8
RR
4292 bool needs_header = HasHeader();
4293 bool has_header = (m_headerWin != NULL);
7d7b3f69 4294
06cd40a8
RR
4295 if (needs_header == has_header)
4296 return;
f8252483 4297
06cd40a8
RR
4298 if (needs_header)
4299 {
4300 m_headerWin = new wxListHeaderWindow
cf1dfa6b 4301 (
ca65c044 4302 this, wxID_ANY, m_mainWin,
c47addef 4303 wxPoint(0,0),
f8252483 4304 wxSize(GetClientSize().x, m_headerHeight),
cf1dfa6b
VZ
4305 wxTAB_TRAVERSAL
4306 );
7d7b3f69 4307
06cd40a8
RR
4308#if defined( __WXMAC__ ) && wxOSX_USE_COCOA_OR_CARBON
4309 wxFont font;
4310#if wxOSX_USE_ATSU_TEXT
4311 font.MacCreateFromThemeFont( kThemeSmallSystemFont );
4312#else
4313 font.MacCreateFromUIFont( kCTFontSystemFontType );
4314#endif
4315 m_headerWin->SetFont( font );
4316#endif
7d7b3f69 4317
06cd40a8
RR
4318 GetSizer()->Prepend( m_headerWin, 0, wxGROW );
4319 }
4320 else
4321 {
4322 GetSizer()->Detach( m_headerWin );
7d7b3f69 4323
06cd40a8 4324 delete m_headerWin;
7d7b3f69 4325
06cd40a8
RR
4326 m_headerWin = NULL;
4327 }
c801d85f
KB
4328}
4329
3cd94a0d 4330bool wxGenericListCtrl::Create(wxWindow *parent,
25e3a937
VZ
4331 wxWindowID id,
4332 const wxPoint &pos,
4333 const wxSize &size,
4334 long style,
25e3a937 4335 const wxValidator &validator,
25e3a937 4336 const wxString &name)
c801d85f 4337{
06cd40a8 4338 Init();
3fc93ebd 4339
c615d649 4340 // just like in other ports, an assert will fail if the user doesn't give any type style:
5ac526c4 4341 wxASSERT_MSG( (style & wxLC_MASK_TYPE),
c615d649 4342 _T("wxListCtrl style should have exactly one mode bit set") );
f6bcfd97 4343
06cd40a8 4344 if ( !wxControl::Create( parent, id, pos, size, style|wxVSCROLL|wxHSCROLL, validator, name ) )
ca65c044 4345 return false;
f6bcfd97 4346
dff750b4
RR
4347#ifdef __WXGTK__
4348 style &= ~wxBORDER_MASK;
4349 style |= wxBORDER_THEME;
7d7b3f69 4350#endif
bd8289c1 4351
277ea1b4 4352 m_mainWin = new wxListMainWindow( this, wxID_ANY, wxPoint(0, 0), size, style );
bd8289c1 4353
06cd40a8 4354 SetTargetWindow( m_mainWin );
7d7b3f69 4355
06cd40a8
RR
4356 wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
4357 sizer->Add( m_mainWin, 1, wxGROW );
4358 SetSizer( sizer );
7d7b3f69 4359
06cd40a8
RR
4360 CreateOrDestroyHeaderWindowAsNeeded();
4361
4362 SetInitialSize(size);
4363
4364 return true;
4365}
4366
4367wxBorder wxGenericListCtrl::GetDefaultBorder() const
4368{
4369 return wxBORDER_THEME;
4370}
4371
5d55031c 4372#if defined(__WXMSW__) && !defined(__WXWINCE__) && !defined(__WXUNIVERSAL__)
06cd40a8
RR
4373WXLRESULT wxGenericListCtrl::MSWWindowProc(WXUINT nMsg,
4374 WXWPARAM wParam,
4375 WXLPARAM lParam)
4376{
4377 WXLRESULT rc = wxControl::MSWWindowProc(nMsg, wParam, lParam);
4378
06cd40a8
RR
4379 // we need to process arrows ourselves for scrolling
4380 if ( nMsg == WM_GETDLGCODE )
309e4c14 4381 {
06cd40a8 4382 rc |= DLGC_WANTARROWS;
309e4c14 4383 }
277ea1b4 4384
06cd40a8
RR
4385 return rc;
4386}
5d55031c 4387#endif // __WXMSW__
277ea1b4 4388
06cd40a8
RR
4389wxSize wxGenericListCtrl::GetSizeAvailableForScrollTarget(const wxSize& size)
4390{
4391 wxSize newsize = size;
4392 if (m_headerWin)
4393 newsize.y -= m_headerWin->GetSize().y;
bd8289c1 4394
06cd40a8
RR
4395 return newsize;
4396}
ca65c044 4397
06cd40a8
RR
4398void wxGenericListCtrl::OnScroll(wxScrollWinEvent& event)
4399{
4400 // update our idea of which lines are shown when we redraw
4401 // the window the next time
4402 m_mainWin->ResetVisibleLinesRange();
4403
4404 HandleOnScroll( event );
4405
4406 if ( event.GetOrientation() == wxHORIZONTAL && HasHeader() )
4407 {
4408 m_headerWin->Refresh();
4409 m_headerWin->Update();
4410 }
e1e955e1 4411}
c801d85f 4412
3cd94a0d 4413void wxGenericListCtrl::SetSingleStyle( long style, bool add )
c801d85f 4414{
b54e41c5
VZ
4415 wxASSERT_MSG( !(style & wxLC_VIRTUAL),
4416 _T("wxLC_VIRTUAL can't be [un]set") );
4417
f03fc89f 4418 long flag = GetWindowStyle();
bd8289c1 4419
5b077d48
RR
4420 if (add)
4421 {
cf1dfa6b 4422 if (style & wxLC_MASK_TYPE)
b54e41c5 4423 flag &= ~(wxLC_MASK_TYPE | wxLC_VIRTUAL);
cf1dfa6b
VZ
4424 if (style & wxLC_MASK_ALIGN)
4425 flag &= ~wxLC_MASK_ALIGN;
4426 if (style & wxLC_MASK_SORT)
4427 flag &= ~wxLC_MASK_SORT;
5b077d48 4428 }
c801d85f 4429
5b077d48 4430 if (add)
5b077d48 4431 flag |= style;
5b077d48 4432 else
cf1dfa6b 4433 flag &= ~style;
bd8289c1 4434
b119ee87
VZ
4435 // some styles can be set without recreating everything (as happens in
4436 // SetWindowStyleFlag() which calls wxListMainWindow::DeleteEverything())
4437 if ( !(style & ~(wxLC_HRULES | wxLC_VRULES)) )
4438 {
4439 Refresh();
4440 wxWindow::SetWindowStyleFlag(flag);
4441 }
4442 else
4443 {
4444 SetWindowStyleFlag( flag );
4445 }
e1e955e1 4446}
c801d85f 4447
3cd94a0d 4448void wxGenericListCtrl::SetWindowStyleFlag( long flag )
c801d85f 4449{
121a3581
RR
4450 if (m_mainWin)
4451 {
06cd40a8 4452 // m_mainWin->DeleteEverything(); wxMSW doesn't do that
a95cdab8 4453
06cd40a8 4454 CreateOrDestroyHeaderWindowAsNeeded();
7d7b3f69 4455
06cd40a8 4456 GetSizer()->Layout();
e1e955e1 4457 }
004fd0c8 4458
5b077d48 4459 wxWindow::SetWindowStyleFlag( flag );
e1e955e1 4460}
c801d85f 4461
3cd94a0d 4462bool wxGenericListCtrl::GetColumn(int col, wxListItem &item) const
c801d85f 4463{
5b077d48 4464 m_mainWin->GetColumn( col, item );
ca65c044 4465 return true;
e1e955e1 4466}
c801d85f 4467
3cd94a0d 4468bool wxGenericListCtrl::SetColumn( int col, wxListItem& item )
c801d85f 4469{
5b077d48 4470 m_mainWin->SetColumn( col, item );
ca65c044 4471 return true;
e1e955e1 4472}
c801d85f 4473
3cd94a0d 4474int wxGenericListCtrl::GetColumnWidth( int col ) const
c801d85f 4475{
5b077d48 4476 return m_mainWin->GetColumnWidth( col );
e1e955e1 4477}
c801d85f 4478
3cd94a0d 4479bool wxGenericListCtrl::SetColumnWidth( int col, int width )
c801d85f 4480{
5b077d48 4481 m_mainWin->SetColumnWidth( col, width );
ca65c044 4482 return true;
e1e955e1 4483}
c801d85f 4484
3cd94a0d 4485int wxGenericListCtrl::GetCountPerPage() const
c801d85f
KB
4486{
4487 return m_mainWin->GetCountPerPage(); // different from Windows ?
e1e955e1 4488}
c801d85f 4489
3cd94a0d 4490bool wxGenericListCtrl::GetItem( wxListItem &info ) const
c801d85f 4491{
5b077d48 4492 m_mainWin->GetItem( info );
ca65c044 4493 return true;
e1e955e1 4494}
c801d85f 4495
3cd94a0d 4496bool wxGenericListCtrl::SetItem( wxListItem &info )
c801d85f 4497{
5b077d48 4498 m_mainWin->SetItem( info );
ca65c044 4499 return true;
e1e955e1 4500}
c801d85f 4501
3cd94a0d 4502long wxGenericListCtrl::SetItem( long index, int col, const wxString& label, int imageId )
c801d85f 4503{
5b077d48
RR
4504 wxListItem info;
4505 info.m_text = label;
4506 info.m_mask = wxLIST_MASK_TEXT;
4507 info.m_itemId = index;
4508 info.m_col = col;
4509 if ( imageId > -1 )
4510 {
4511 info.m_image = imageId;
4512 info.m_mask |= wxLIST_MASK_IMAGE;
277ea1b4
DS
4513 }
4514
5b077d48 4515 m_mainWin->SetItem(info);
ca65c044 4516 return true;
e1e955e1 4517}
c801d85f 4518
3cd94a0d 4519int wxGenericListCtrl::GetItemState( long item, long stateMask ) const
c801d85f 4520{
5b077d48 4521 return m_mainWin->GetItemState( item, stateMask );
e1e955e1 4522}
c801d85f 4523
3cd94a0d 4524bool wxGenericListCtrl::SetItemState( long item, long state, long stateMask )
c801d85f 4525{
5b077d48 4526 m_mainWin->SetItemState( item, state, stateMask );
ca65c044 4527 return true;
e1e955e1 4528}
c801d85f 4529
aba3d35e
VZ
4530bool
4531wxGenericListCtrl::SetItemImage( long item, int image, int WXUNUSED(selImage) )
06db67bc
RD
4532{
4533 return SetItemColumnImage(item, 0, image);
4534}
4535
4536bool
4537wxGenericListCtrl::SetItemColumnImage( long item, long column, int image )
c3627a00
JS
4538{
4539 wxListItem info;
4540 info.m_image = image;
4541 info.m_mask = wxLIST_MASK_IMAGE;
4542 info.m_itemId = item;
06db67bc 4543 info.m_col = column;
c3627a00
JS
4544 m_mainWin->SetItem( info );
4545 return true;
4546}
c801d85f 4547
3cd94a0d 4548wxString wxGenericListCtrl::GetItemText( long item ) const
c801d85f 4549{
62d89eb4 4550 return m_mainWin->GetItemText(item);
e1e955e1 4551}
c801d85f 4552
3cd94a0d 4553void wxGenericListCtrl::SetItemText( long item, const wxString& str )
c801d85f 4554{
62d89eb4 4555 m_mainWin->SetItemText(item, str);
e1e955e1 4556}
c801d85f 4557
81ce36aa 4558wxUIntPtr wxGenericListCtrl::GetItemData( long item ) const
c801d85f 4559{
5b077d48 4560 wxListItem info;
39a7f085 4561 info.m_mask = wxLIST_MASK_DATA;
5b077d48
RR
4562 info.m_itemId = item;
4563 m_mainWin->GetItem( info );
4564 return info.m_data;
e1e955e1 4565}
c801d85f 4566
9fcd0bf7 4567bool wxGenericListCtrl::SetItemPtrData( long item, wxUIntPtr data )
c801d85f 4568{
5b077d48
RR
4569 wxListItem info;
4570 info.m_mask = wxLIST_MASK_DATA;
4571 info.m_itemId = item;
4572 info.m_data = data;
4573 m_mainWin->SetItem( info );
ca65c044 4574 return true;
e1e955e1 4575}
c801d85f 4576
11ebea16
VZ
4577wxRect wxGenericListCtrl::GetViewRect() const
4578{
4579 return m_mainWin->GetViewRect();
4580}
4581
e974c5d2
VZ
4582bool wxGenericListCtrl::GetItemRect(long item, wxRect& rect, int code) const
4583{
4584 return GetSubItemRect(item, wxLIST_GETSUBITEMRECT_WHOLEITEM, rect, code);
4585}
4586
4587bool wxGenericListCtrl::GetSubItemRect(long item,
4588 long subItem,
4589 wxRect& rect,
4590 int WXUNUSED(code)) const
c801d85f 4591{
e974c5d2
VZ
4592 if ( !m_mainWin->GetSubItemRect( item, subItem, rect ) )
4593 return false;
4594
7e6874c0 4595 if ( m_mainWin->HasHeader() )
f8252483 4596 rect.y += m_headerHeight + 1;
e974c5d2 4597
ca65c044 4598 return true;
e1e955e1 4599}
c801d85f 4600
3cd94a0d 4601bool wxGenericListCtrl::GetItemPosition( long item, wxPoint& pos ) const
c801d85f 4602{
5b077d48 4603 m_mainWin->GetItemPosition( item, pos );
ca65c044 4604 return true;
e1e955e1 4605}
c801d85f 4606
3cd94a0d 4607bool wxGenericListCtrl::SetItemPosition( long WXUNUSED(item), const wxPoint& WXUNUSED(pos) )
c801d85f 4608{
e974c5d2 4609 return false;
e1e955e1 4610}
c801d85f 4611
3cd94a0d 4612int wxGenericListCtrl::GetItemCount() const
c801d85f 4613{
5b077d48 4614 return m_mainWin->GetItemCount();
e1e955e1 4615}
c801d85f 4616
3cd94a0d 4617int wxGenericListCtrl::GetColumnCount() const
92976ab6 4618{
5b077d48 4619 return m_mainWin->GetColumnCount();
92976ab6
RR
4620}
4621
3cd94a0d 4622void wxGenericListCtrl::SetItemSpacing( int spacing, bool isSmall )
33d0b396 4623{
5b077d48 4624 m_mainWin->SetItemSpacing( spacing, isSmall );
e1e955e1 4625}
33d0b396 4626
5db8d758
VZ
4627wxSize wxGenericListCtrl::GetItemSpacing() const
4628{
f58fc140 4629 const int spacing = m_mainWin->GetItemSpacing(HasFlag(wxLC_SMALL_ICON));
5db8d758
VZ
4630
4631 return wxSize(spacing, spacing);
4632}
4633
82d492f1 4634#if WXWIN_COMPATIBILITY_2_6
3cd94a0d 4635int wxGenericListCtrl::GetItemSpacing( bool isSmall ) const
c801d85f 4636{
5b077d48 4637 return m_mainWin->GetItemSpacing( isSmall );
e1e955e1 4638}
82d492f1 4639#endif // WXWIN_COMPATIBILITY_2_6
c801d85f 4640
3cd94a0d 4641void wxGenericListCtrl::SetItemTextColour( long item, const wxColour &col )
5b98eb2f
RL
4642{
4643 wxListItem info;
4644 info.m_itemId = item;
4645 info.SetTextColour( col );
4646 m_mainWin->SetItem( info );
4647}
4648
3cd94a0d 4649wxColour wxGenericListCtrl::GetItemTextColour( long item ) const
5b98eb2f
RL
4650{
4651 wxListItem info;
4652 info.m_itemId = item;
4653 m_mainWin->GetItem( info );
4654 return info.GetTextColour();
4655}
4656
3cd94a0d 4657void wxGenericListCtrl::SetItemBackgroundColour( long item, const wxColour &col )
5b98eb2f
RL
4658{
4659 wxListItem info;
4660 info.m_itemId = item;
4661 info.SetBackgroundColour( col );
4662 m_mainWin->SetItem( info );
4663}
4664
3cd94a0d 4665wxColour wxGenericListCtrl::GetItemBackgroundColour( long item ) const
5b98eb2f
RL
4666{
4667 wxListItem info;
4668 info.m_itemId = item;
4669 m_mainWin->GetItem( info );
4670 return info.GetBackgroundColour();
4671}
4672
35c2acd4
MW
4673void wxGenericListCtrl::SetItemFont( long item, const wxFont &f )
4674{
4675 wxListItem info;
4676 info.m_itemId = item;
4677 info.SetFont( f );
4678 m_mainWin->SetItem( info );
4679}
4680
4681wxFont wxGenericListCtrl::GetItemFont( long item ) const
4682{
4683 wxListItem info;
4684 info.m_itemId = item;
4685 m_mainWin->GetItem( info );
4686 return info.GetFont();
4687}
4688
3cd94a0d 4689int wxGenericListCtrl::GetSelectedItemCount() const
c801d85f 4690{
5b077d48 4691 return m_mainWin->GetSelectedItemCount();
e1e955e1 4692}
c801d85f 4693
3cd94a0d 4694wxColour wxGenericListCtrl::GetTextColour() const
c801d85f 4695{
0530737d 4696 return GetForegroundColour();
e1e955e1 4697}
c801d85f 4698
3cd94a0d 4699void wxGenericListCtrl::SetTextColour(const wxColour& col)
c801d85f 4700{
0530737d 4701 SetForegroundColour(col);
e1e955e1 4702}
c801d85f 4703
3cd94a0d 4704long wxGenericListCtrl::GetTopItem() const
c801d85f 4705{
2b5f62a0
VZ
4706 size_t top;
4707 m_mainWin->GetVisibleLinesRange(&top, NULL);
4708 return (long)top;
e1e955e1 4709}
c801d85f 4710
3cd94a0d 4711long wxGenericListCtrl::GetNextItem( long item, int geom, int state ) const
c801d85f 4712{
5b077d48 4713 return m_mainWin->GetNextItem( item, geom, state );
e1e955e1 4714}
c801d85f 4715
8a3e173a 4716wxImageList *wxGenericListCtrl::GetImageList(int which) const
c801d85f 4717{
5b077d48 4718 if (which == wxIMAGE_LIST_NORMAL)
5b077d48 4719 return m_imageListNormal;
5b077d48 4720 else if (which == wxIMAGE_LIST_SMALL)
5b077d48 4721 return m_imageListSmall;
5b077d48 4722 else if (which == wxIMAGE_LIST_STATE)
5b077d48 4723 return m_imageListState;
277ea1b4 4724
d3b9f782 4725 return NULL;
e1e955e1 4726}
c801d85f 4727
8a3e173a 4728void wxGenericListCtrl::SetImageList( wxImageList *imageList, int which )
c801d85f 4729{
2e12c11a
VS
4730 if ( which == wxIMAGE_LIST_NORMAL )
4731 {
277ea1b4
DS
4732 if (m_ownsImageListNormal)
4733 delete m_imageListNormal;
2e12c11a 4734 m_imageListNormal = imageList;
ca65c044 4735 m_ownsImageListNormal = false;
2e12c11a
VS
4736 }
4737 else if ( which == wxIMAGE_LIST_SMALL )
4738 {
277ea1b4
DS
4739 if (m_ownsImageListSmall)
4740 delete m_imageListSmall;
2e12c11a 4741 m_imageListSmall = imageList;
ca65c044 4742 m_ownsImageListSmall = false;
2e12c11a
VS
4743 }
4744 else if ( which == wxIMAGE_LIST_STATE )
4745 {
277ea1b4
DS
4746 if (m_ownsImageListState)
4747 delete m_imageListState;
2e12c11a 4748 m_imageListState = imageList;
ca65c044 4749 m_ownsImageListState = false;
2e12c11a
VS
4750 }
4751
5b077d48 4752 m_mainWin->SetImageList( imageList, which );
e1e955e1 4753}
c801d85f 4754
8a3e173a 4755void wxGenericListCtrl::AssignImageList(wxImageList *imageList, int which)
2e12c11a
VS
4756{
4757 SetImageList(imageList, which);
4758 if ( which == wxIMAGE_LIST_NORMAL )
ca65c044 4759 m_ownsImageListNormal = true;
2e12c11a 4760 else if ( which == wxIMAGE_LIST_SMALL )
ca65c044 4761 m_ownsImageListSmall = true;
2e12c11a 4762 else if ( which == wxIMAGE_LIST_STATE )
ca65c044 4763 m_ownsImageListState = true;
2e12c11a
VS
4764}
4765
3cd94a0d 4766bool wxGenericListCtrl::Arrange( int WXUNUSED(flag) )
c801d85f 4767{
5b077d48 4768 return 0;
e1e955e1 4769}
c801d85f 4770
3cd94a0d 4771bool wxGenericListCtrl::DeleteItem( long item )
c801d85f 4772{
5b077d48 4773 m_mainWin->DeleteItem( item );
ca65c044 4774 return true;
e1e955e1 4775}
c801d85f 4776
3cd94a0d 4777bool wxGenericListCtrl::DeleteAllItems()
c801d85f 4778{
5b077d48 4779 m_mainWin->DeleteAllItems();
ca65c044 4780 return true;
e1e955e1 4781}
c801d85f 4782
3cd94a0d 4783bool wxGenericListCtrl::DeleteAllColumns()
bd8289c1 4784{
24b9f055
VZ
4785 size_t count = m_mainWin->m_columns.GetCount();
4786 for ( size_t n = 0; n < count; n++ )
277ea1b4 4787 DeleteColumn( 0 );
ca65c044 4788 return true;
4f22cf8d
RR
4789}
4790
3cd94a0d 4791void wxGenericListCtrl::ClearAll()
4f22cf8d 4792{
5b077d48 4793 m_mainWin->DeleteEverything();
bd8289c1
VZ
4794}
4795
3cd94a0d 4796bool wxGenericListCtrl::DeleteColumn( int col )
c801d85f 4797{
5b077d48 4798 m_mainWin->DeleteColumn( col );
40c08808
VZ
4799
4800 // if we don't have the header any longer, we need to relayout the window
06cd40a8 4801 // if ( !GetColumnCount() )
7d7b3f69 4802
ca65c044 4803 return true;
e1e955e1 4804}
c801d85f 4805
26e8da41
VZ
4806wxTextCtrl *wxGenericListCtrl::EditLabel(long item,
4807 wxClassInfo* textControlClass)
4808{
4809 return m_mainWin->EditLabel( item, textControlClass );
4810}
4811
4812wxTextCtrl *wxGenericListCtrl::GetEditControl() const
c801d85f 4813{
26e8da41 4814 return m_mainWin->GetEditControl();
e1e955e1 4815}
c801d85f 4816
3cd94a0d 4817bool wxGenericListCtrl::EnsureVisible( long item )
c801d85f 4818{
5b077d48 4819 m_mainWin->EnsureVisible( item );
ca65c044 4820 return true;
e1e955e1 4821}
c801d85f 4822
277ea1b4 4823long wxGenericListCtrl::FindItem( long start, const wxString& str, bool partial )
c801d85f 4824{
5b077d48 4825 return m_mainWin->FindItem( start, str, partial );
e1e955e1 4826}
c801d85f 4827
81ce36aa 4828long wxGenericListCtrl::FindItem( long start, wxUIntPtr data )
c801d85f 4829{
5b077d48 4830 return m_mainWin->FindItem( start, data );
e1e955e1 4831}
c801d85f 4832
8158e0e1 4833long wxGenericListCtrl::FindItem( long WXUNUSED(start), const wxPoint& pt,
debe6624 4834 int WXUNUSED(direction))
c801d85f 4835{
8158e0e1 4836 return m_mainWin->FindItem( pt );
e1e955e1 4837}
c801d85f 4838
164a7972 4839// TODO: sub item hit testing
be0e5d69 4840long wxGenericListCtrl::HitTest(const wxPoint& point, int& flags, long *) const
c801d85f 4841{
5b077d48 4842 return m_mainWin->HitTest( (int)point.x, (int)point.y, flags );
e1e955e1 4843}
c801d85f 4844
3cd94a0d 4845long wxGenericListCtrl::InsertItem( wxListItem& info )
c801d85f 4846{
5b077d48 4847 m_mainWin->InsertItem( info );
2ebcd5f5 4848 return info.m_itemId;
e1e955e1 4849}
c801d85f 4850
3cd94a0d 4851long wxGenericListCtrl::InsertItem( long index, const wxString &label )
c801d85f 4852{
51cc4dad
RR
4853 wxListItem info;
4854 info.m_text = label;
4855 info.m_mask = wxLIST_MASK_TEXT;
4856 info.m_itemId = index;
4857 return InsertItem( info );
e1e955e1 4858}
c801d85f 4859
3cd94a0d 4860long wxGenericListCtrl::InsertItem( long index, int imageIndex )
c801d85f 4861{
51cc4dad
RR
4862 wxListItem info;
4863 info.m_mask = wxLIST_MASK_IMAGE;
4864 info.m_image = imageIndex;
4865 info.m_itemId = index;
4866 return InsertItem( info );
e1e955e1 4867}
c801d85f 4868
3cd94a0d 4869long wxGenericListCtrl::InsertItem( long index, const wxString &label, int imageIndex )
c801d85f 4870{
51cc4dad
RR
4871 wxListItem info;
4872 info.m_text = label;
4873 info.m_image = imageIndex;
4874 info.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_IMAGE;
4875 info.m_itemId = index;
4876 return InsertItem( info );
e1e955e1 4877}
c801d85f 4878
3cd94a0d 4879long wxGenericListCtrl::InsertColumn( long col, wxListItem &item )
c801d85f 4880{
52d2a5e4 4881 wxCHECK_MSG( InReportView(), -1, _T("can't add column in non report mode") );
40c08808 4882
51cc4dad 4883 m_mainWin->InsertColumn( col, item );
40c08808 4884
52d2a5e4
FM
4885 // NOTE: if wxLC_NO_HEADER was given, then we are in report view mode but
4886 // still have m_headerWin==NULL
4887 if (m_headerWin)
4888 m_headerWin->Refresh();
25e3a937 4889
51cc4dad 4890 return 0;
e1e955e1 4891}
c801d85f 4892
3cd94a0d 4893long wxGenericListCtrl::InsertColumn( long col, const wxString &heading,
debe6624 4894 int format, int width )
c801d85f 4895{
51cc4dad
RR
4896 wxListItem item;
4897 item.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_FORMAT;
4898 item.m_text = heading;
4899 if (width >= -2)
4900 {
4901 item.m_mask |= wxLIST_MASK_WIDTH;
4902 item.m_width = width;
4903 }
277ea1b4 4904
51cc4dad 4905 item.m_format = format;
c801d85f 4906
51cc4dad 4907 return InsertColumn( col, item );
e1e955e1 4908}
c801d85f 4909
66a9201d 4910bool wxGenericListCtrl::ScrollList( int dx, int dy )
c801d85f 4911{
66a9201d 4912 return m_mainWin->ScrollList(dx, dy);
e1e955e1 4913}
c801d85f
KB
4914
4915// Sort items.
4916// fn is a function which takes 3 long arguments: item1, item2, data.
4917// item1 is the long data associated with a first item (NOT the index).
4918// item2 is the long data associated with a second item (NOT the index).
4919// data is the same value as passed to SortItems.
4920// The return value is a negative number if the first item should precede the second
4921// item, a positive number of the second item should precede the first,
4922// or zero if the two items are equivalent.
4923// data is arbitrary data to be passed to the sort function.
4924
3cd94a0d 4925bool wxGenericListCtrl::SortItems( wxListCtrlCompare fn, long data )
c801d85f 4926{
51cc4dad 4927 m_mainWin->SortItems( fn, data );
ca65c044 4928 return true;
e1e955e1 4929}
c801d85f 4930
cf1dfa6b 4931// ----------------------------------------------------------------------------
b54e41c5 4932// event handlers
cf1dfa6b
VZ
4933// ----------------------------------------------------------------------------
4934
3cd94a0d 4935void wxGenericListCtrl::OnSize(wxSizeEvent& WXUNUSED(event))
53010e52 4936{
06cd40a8 4937 if (!m_mainWin) return;
53010e52 4938
06cd40a8
RR
4939 // We need to override OnSize so that our scrolled
4940 // window a) does call Layout() to use sizers for
4941 // positioning the controls but b) does not query
4942 // the sizer for their size and use that for setting
4943 // the scrollable area as set that ourselves by
4944 // calling SetScrollbar() further down.
a95cdab8 4945
06cd40a8 4946 Layout();
bd8289c1 4947
06cd40a8 4948 m_mainWin->RecalculatePositions();
7d7b3f69 4949
06cd40a8 4950 AdjustScrollbars();
b54e41c5 4951}
cf1dfa6b 4952
5180055b 4953void wxGenericListCtrl::OnInternalIdle()
b54e41c5 4954{
5180055b 4955 wxWindow::OnInternalIdle();
86351e4a 4956
06cd40a8
RR
4957 if (m_mainWin->m_dirty)
4958 m_mainWin->RecalculatePositions();
e1e955e1 4959}
53010e52 4960
cf1dfa6b
VZ
4961// ----------------------------------------------------------------------------
4962// font/colours
4963// ----------------------------------------------------------------------------
4964
3cd94a0d 4965bool wxGenericListCtrl::SetBackgroundColour( const wxColour &colour )
bd8289c1 4966{
51cc4dad
RR
4967 if (m_mainWin)
4968 {
4969 m_mainWin->SetBackgroundColour( colour );
ca65c044 4970 m_mainWin->m_dirty = true;
51cc4dad 4971 }
004fd0c8 4972
ca65c044 4973 return true;
e4d06860
RR
4974}
4975
3cd94a0d 4976bool wxGenericListCtrl::SetForegroundColour( const wxColour &colour )
bd8289c1 4977{
f03fc89f 4978 if ( !wxWindow::SetForegroundColour( colour ) )
ca65c044 4979 return false;
004fd0c8 4980
51cc4dad
RR
4981 if (m_mainWin)
4982 {
4983 m_mainWin->SetForegroundColour( colour );
ca65c044 4984 m_mainWin->m_dirty = true;
51cc4dad 4985 }
004fd0c8 4986
51cc4dad 4987 if (m_headerWin)
51cc4dad 4988 m_headerWin->SetForegroundColour( colour );
f03fc89f 4989
ca65c044 4990 return true;
e4d06860 4991}
bd8289c1 4992
3cd94a0d 4993bool wxGenericListCtrl::SetFont( const wxFont &font )
bd8289c1 4994{
f03fc89f 4995 if ( !wxWindow::SetFont( font ) )
ca65c044 4996 return false;
004fd0c8 4997
51cc4dad
RR
4998 if (m_mainWin)
4999 {
5000 m_mainWin->SetFont( font );
ca65c044 5001 m_mainWin->m_dirty = true;
51cc4dad 5002 }
004fd0c8 5003
51cc4dad
RR
5004 if (m_headerWin)
5005 {
5006 m_headerWin->SetFont( font );
06cd40a8 5007 // CalculateAndSetHeaderHeight();
51cc4dad 5008 }
f03fc89f 5009
f8252483
JS
5010 Refresh();
5011
ca65c044 5012 return true;
e4d06860 5013}
c801d85f 5014
277ea1b4 5015// static
35d4c967
RD
5016wxVisualAttributes
5017wxGenericListCtrl::GetClassDefaultAttributes(wxWindowVariant variant)
5018{
5019#if _USE_VISATTR
5020 // Use the same color scheme as wxListBox
5021 return wxListBox::GetClassDefaultAttributes(variant);
5022#else
e7045784 5023 wxUnusedVar(variant);
35d4c967 5024 wxVisualAttributes attr;
9f2968ad 5025 attr.colFg = wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOXTEXT);
35d4c967
RD
5026 attr.colBg = wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX);
5027 attr.font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
5028 return attr;
5029#endif
5030}
5031
cf1dfa6b
VZ
5032// ----------------------------------------------------------------------------
5033// methods forwarded to m_mainWin
5034// ----------------------------------------------------------------------------
5035
efbb7287
VZ
5036#if wxUSE_DRAG_AND_DROP
5037
3cd94a0d 5038void wxGenericListCtrl::SetDropTarget( wxDropTarget *dropTarget )
efbb7287
VZ
5039{
5040 m_mainWin->SetDropTarget( dropTarget );
5041}
5042
3cd94a0d 5043wxDropTarget *wxGenericListCtrl::GetDropTarget() const
efbb7287
VZ
5044{
5045 return m_mainWin->GetDropTarget();
5046}
5047
277ea1b4 5048#endif
efbb7287 5049
3cd94a0d 5050bool wxGenericListCtrl::SetCursor( const wxCursor &cursor )
efbb7287 5051{
ca65c044 5052 return m_mainWin ? m_mainWin->wxWindow::SetCursor(cursor) : false;
efbb7287
VZ
5053}
5054
3cd94a0d 5055wxColour wxGenericListCtrl::GetBackgroundColour() const
efbb7287
VZ
5056{
5057 return m_mainWin ? m_mainWin->GetBackgroundColour() : wxColour();
5058}
5059
3cd94a0d 5060wxColour wxGenericListCtrl::GetForegroundColour() const
efbb7287
VZ
5061{
5062 return m_mainWin ? m_mainWin->GetForegroundColour() : wxColour();
5063}
5064
3cd94a0d 5065bool wxGenericListCtrl::DoPopupMenu( wxMenu *menu, int x, int y )
efbb7287 5066{
3a8c693a 5067#if wxUSE_MENUS
efbb7287 5068 return m_mainWin->PopupMenu( menu, x, y );
3a8c693a 5069#else
ca65c044 5070 return false;
277ea1b4 5071#endif
efbb7287
VZ
5072}
5073
7447bdd7
VZ
5074void wxGenericListCtrl::DoClientToScreen( int *x, int *y ) const
5075{
5d584acb 5076 m_mainWin->DoClientToScreen(x, y);
7447bdd7
VZ
5077}
5078
5079void wxGenericListCtrl::DoScreenToClient( int *x, int *y ) const
5080{
5d584acb 5081 m_mainWin->DoScreenToClient(x, y);
7447bdd7
VZ
5082}
5083
3cd94a0d 5084void wxGenericListCtrl::SetFocus()
efbb7287 5085{
277ea1b4
DS
5086 // The test in window.cpp fails as we are a composite
5087 // window, so it checks against "this", but not m_mainWin.
66370e38 5088 if ( DoFindFocus() != this )
efbb7287
VZ
5089 m_mainWin->SetFocus();
5090}
1e6feb95 5091
3872d96d
RD
5092wxSize wxGenericListCtrl::DoGetBestSize() const
5093{
5094 // Something is better than nothing...
5095 // 100x80 is what the MSW version will get from the default
5096 // wxControl::DoGetBestSize
277ea1b4 5097 return wxSize(100, 80);
3872d96d
RD
5098}
5099
2c1f73ee
VZ
5100// ----------------------------------------------------------------------------
5101// virtual list control support
5102// ----------------------------------------------------------------------------
5103
3cd94a0d 5104wxString wxGenericListCtrl::OnGetItemText(long WXUNUSED(item), long WXUNUSED(col)) const
2c1f73ee
VZ
5105{
5106 // this is a pure virtual function, in fact - which is not really pure
5107 // because the controls which are not virtual don't need to implement it
3cd94a0d 5108 wxFAIL_MSG( _T("wxGenericListCtrl::OnGetItemText not supposed to be called") );
2c1f73ee
VZ
5109
5110 return wxEmptyString;
5111}
5112
3cd94a0d 5113int wxGenericListCtrl::OnGetItemImage(long WXUNUSED(item)) const
2c1f73ee 5114{
611a725e
RD
5115 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL),
5116 -1,
208458a7 5117 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
2c1f73ee
VZ
5118 return -1;
5119}
5120
208458a7
RD
5121int wxGenericListCtrl::OnGetItemColumnImage(long item, long column) const
5122{
5123 if (!column)
5124 return OnGetItemImage(item);
5125
5126 return -1;
08a175ce 5127}
208458a7 5128
999836aa
VZ
5129wxListItemAttr *
5130wxGenericListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item)) const
6c02c329
VZ
5131{
5132 wxASSERT_MSG( item >= 0 && item < GetItemCount(),
5133 _T("invalid item index in OnGetItemAttr()") );
5134
5135 // no attributes by default
5136 return NULL;
5137}
5138
3cd94a0d 5139void wxGenericListCtrl::SetItemCount(long count)
2c1f73ee
VZ
5140{
5141 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
5142
5143 m_mainWin->SetItemCount(count);
5144}
5145
3cd94a0d 5146void wxGenericListCtrl::RefreshItem(long item)
1a6cb56f
VZ
5147{
5148 m_mainWin->RefreshLine(item);
5149}
5150
3cd94a0d 5151void wxGenericListCtrl::RefreshItems(long itemFrom, long itemTo)
1a6cb56f
VZ
5152{
5153 m_mainWin->RefreshLines(itemFrom, itemTo);
5154}
5155
277ea1b4
DS
5156// Generic wxListCtrl is more or less a container for two other
5157// windows which drawings are done upon. These are namely
5158// 'm_headerWin' and 'm_mainWin'.
5159// Here we override 'virtual wxWindow::Refresh()' to mimic the
5160// behaviour wxListCtrl has under wxMSW.
5161//
2f1e3c46
VZ
5162void wxGenericListCtrl::Refresh(bool eraseBackground, const wxRect *rect)
5163{
5164 if (!rect)
5165 {
5166 // The easy case, no rectangle specified.
5167 if (m_headerWin)
5168 m_headerWin->Refresh(eraseBackground);
5169
5170 if (m_mainWin)
5171 m_mainWin->Refresh(eraseBackground);
5172 }
5173 else
5174 {
5175 // Refresh the header window
5176 if (m_headerWin)
5177 {
5178 wxRect rectHeader = m_headerWin->GetRect();
5179 rectHeader.Intersect(*rect);
5180 if (rectHeader.GetWidth() && rectHeader.GetHeight())
5181 {
5182 int x, y;
5183 m_headerWin->GetPosition(&x, &y);
5184 rectHeader.Offset(-x, -y);
5185 m_headerWin->Refresh(eraseBackground, &rectHeader);
5186 }
2f1e3c46
VZ
5187 }
5188
5189 // Refresh the main window
5190 if (m_mainWin)
5191 {
5192 wxRect rectMain = m_mainWin->GetRect();
5193 rectMain.Intersect(*rect);
5194 if (rectMain.GetWidth() && rectMain.GetHeight())
5195 {
5196 int x, y;
5197 m_mainWin->GetPosition(&x, &y);
5198 rectMain.Offset(-x, -y);
5199 m_mainWin->Refresh(eraseBackground, &rectMain);
5200 }
5201 }
5202 }
5203}
5204
1e6feb95 5205#endif // wxUSE_LISTCTRL