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