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