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