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