]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: listctrl.cpp | |
3 | // Purpose: | |
4 | // Author: Robert Roebling | |
0208334d RR |
5 | // Id: $Id$ |
6 | // Copyright: (c) 1998 Robert Roebling | |
bd8289c1 | 7 | // Licence: wxWindows licence |
c801d85f KB |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
10 | #ifdef __GNUG__ | |
11 | #pragma implementation "listctrl.h" | |
12 | #endif | |
13 | ||
1e6d9499 JS |
14 | // For compilers that support precompilation, includes "wx.h". |
15 | #include "wx/wxprec.h" | |
16 | ||
17 | #ifdef __BORLANDC__ | |
18 | #pragma hdrstop | |
19 | #endif | |
20 | ||
0208334d RR |
21 | #include "wx/dcscreen.h" |
22 | #include "wx/app.h" | |
02527779 | 23 | #include "wx/listctrl.h" |
f60d0f94 | 24 | #include "wx/generic/imaglist.h" |
c801d85f | 25 | |
7c74e7fe SC |
26 | #ifndef wxUSE_GENERIC_LIST_EXTENSIONS |
27 | #define wxUSE_GENERIC_LIST_EXTENSIONS 0 | |
28 | #endif | |
29 | ||
c801d85f KB |
30 | //----------------------------------------------------------------------------- |
31 | // wxListItemData | |
32 | //----------------------------------------------------------------------------- | |
33 | ||
34 | IMPLEMENT_DYNAMIC_CLASS(wxListItemData,wxObject); | |
35 | ||
fd9811b1 | 36 | wxListItemData::wxListItemData() |
c801d85f | 37 | { |
92976ab6 RR |
38 | m_image = -1; |
39 | m_data = 0; | |
40 | m_xpos = 0; | |
41 | m_ypos = 0; | |
42 | m_width = 0; | |
43 | m_height = 0; | |
0530737d | 44 | m_attr = NULL; |
e1e955e1 | 45 | } |
c801d85f KB |
46 | |
47 | wxListItemData::wxListItemData( const wxListItem &info ) | |
48 | { | |
92976ab6 RR |
49 | m_image = -1; |
50 | m_data = 0; | |
0530737d VZ |
51 | m_attr = NULL; |
52 | ||
92976ab6 | 53 | SetItem( info ); |
e1e955e1 | 54 | } |
c801d85f KB |
55 | |
56 | void wxListItemData::SetItem( const wxListItem &info ) | |
57 | { | |
92976ab6 RR |
58 | if (info.m_mask & wxLIST_MASK_TEXT) m_text = info.m_text; |
59 | if (info.m_mask & wxLIST_MASK_IMAGE) m_image = info.m_image; | |
60 | if (info.m_mask & wxLIST_MASK_DATA) m_data = info.m_data; | |
0530737d VZ |
61 | |
62 | if ( info.HasAttributes() ) | |
63 | { | |
64 | if ( m_attr ) | |
65 | *m_attr = *info.GetAttributes(); | |
66 | else | |
67 | m_attr = new wxListItemAttr(*info.GetAttributes()); | |
68 | } | |
69 | ||
92976ab6 RR |
70 | m_xpos = 0; |
71 | m_ypos = 0; | |
72 | m_width = info.m_width; | |
73 | m_height = 0; | |
e1e955e1 | 74 | } |
c801d85f KB |
75 | |
76 | void wxListItemData::SetText( const wxString &s ) | |
77 | { | |
92976ab6 | 78 | m_text = s; |
e1e955e1 | 79 | } |
c801d85f | 80 | |
debe6624 | 81 | void wxListItemData::SetImage( int image ) |
c801d85f | 82 | { |
92976ab6 | 83 | m_image = image; |
e1e955e1 | 84 | } |
c801d85f | 85 | |
debe6624 | 86 | void wxListItemData::SetData( long data ) |
c801d85f | 87 | { |
92976ab6 | 88 | m_data = data; |
e1e955e1 | 89 | } |
c801d85f | 90 | |
debe6624 | 91 | void wxListItemData::SetPosition( int x, int y ) |
c801d85f | 92 | { |
92976ab6 RR |
93 | m_xpos = x; |
94 | m_ypos = y; | |
e1e955e1 | 95 | } |
c801d85f | 96 | |
1e6d9499 | 97 | void wxListItemData::SetSize( int width, int height ) |
c801d85f | 98 | { |
92976ab6 RR |
99 | if (width != -1) m_width = width; |
100 | if (height != -1) m_height = height; | |
e1e955e1 | 101 | } |
c801d85f | 102 | |
fd9811b1 | 103 | bool wxListItemData::HasImage() const |
c801d85f | 104 | { |
92976ab6 | 105 | return (m_image >= 0); |
e1e955e1 | 106 | } |
c801d85f | 107 | |
fd9811b1 | 108 | bool wxListItemData::HasText() const |
c801d85f | 109 | { |
92976ab6 | 110 | return (!m_text.IsNull()); |
e1e955e1 | 111 | } |
c801d85f | 112 | |
debe6624 | 113 | bool wxListItemData::IsHit( int x, int y ) const |
c801d85f | 114 | { |
92976ab6 | 115 | return ((x >= m_xpos) && (x <= m_xpos+m_width) && (y >= m_ypos) && (y <= m_ypos+m_height)); |
e1e955e1 | 116 | } |
c801d85f KB |
117 | |
118 | void wxListItemData::GetText( wxString &s ) | |
119 | { | |
92976ab6 | 120 | s = m_text; |
e1e955e1 | 121 | } |
c801d85f | 122 | |
fd9811b1 | 123 | int wxListItemData::GetX() const |
c801d85f | 124 | { |
92976ab6 | 125 | return m_xpos; |
e1e955e1 | 126 | } |
c801d85f | 127 | |
fd9811b1 | 128 | int wxListItemData::GetY() const |
c801d85f | 129 | { |
92976ab6 | 130 | return m_ypos; |
e1e955e1 | 131 | } |
c801d85f | 132 | |
fd9811b1 | 133 | int wxListItemData::GetWidth() const |
c801d85f | 134 | { |
92976ab6 | 135 | return m_width; |
e1e955e1 | 136 | } |
c801d85f | 137 | |
fd9811b1 | 138 | int wxListItemData::GetHeight() const |
c801d85f | 139 | { |
92976ab6 | 140 | return m_height; |
e1e955e1 | 141 | } |
c801d85f | 142 | |
fd9811b1 | 143 | int wxListItemData::GetImage() const |
c801d85f | 144 | { |
92976ab6 | 145 | return m_image; |
e1e955e1 | 146 | } |
c801d85f | 147 | |
0530737d | 148 | void wxListItemData::GetItem( wxListItem &info ) const |
c801d85f | 149 | { |
92976ab6 RR |
150 | info.m_text = m_text; |
151 | info.m_image = m_image; | |
152 | info.m_data = m_data; | |
c801d85f | 153 | |
0530737d VZ |
154 | if ( m_attr ) |
155 | { | |
156 | if ( m_attr->HasTextColour() ) | |
157 | info.SetTextColour(m_attr->GetTextColour()); | |
158 | if ( m_attr->HasBackgroundColour() ) | |
159 | info.SetBackgroundColour(m_attr->GetBackgroundColour()); | |
160 | if ( m_attr->HasFont() ) | |
161 | info.SetFont(m_attr->GetFont()); | |
162 | } | |
e1e955e1 | 163 | } |
c801d85f KB |
164 | |
165 | //----------------------------------------------------------------------------- | |
166 | // wxListHeaderData | |
167 | //----------------------------------------------------------------------------- | |
168 | ||
169 | IMPLEMENT_DYNAMIC_CLASS(wxListHeaderData,wxObject); | |
170 | ||
fd9811b1 | 171 | wxListHeaderData::wxListHeaderData() |
c801d85f | 172 | { |
92976ab6 RR |
173 | m_mask = 0; |
174 | m_image = 0; | |
175 | m_format = 0; | |
176 | m_width = 0; | |
177 | m_xpos = 0; | |
178 | m_ypos = 0; | |
179 | m_height = 0; | |
e1e955e1 | 180 | } |
c801d85f KB |
181 | |
182 | wxListHeaderData::wxListHeaderData( const wxListItem &item ) | |
183 | { | |
92976ab6 RR |
184 | SetItem( item ); |
185 | m_xpos = 0; | |
186 | m_ypos = 0; | |
187 | m_height = 0; | |
e1e955e1 | 188 | } |
c801d85f KB |
189 | |
190 | void wxListHeaderData::SetItem( const wxListItem &item ) | |
191 | { | |
92976ab6 RR |
192 | m_mask = item.m_mask; |
193 | m_text = item.m_text; | |
194 | m_image = item.m_image; | |
195 | m_format = item.m_format; | |
196 | m_width = item.m_width; | |
197 | if (m_width < 0) m_width = 80; | |
198 | if (m_width < 6) m_width = 6; | |
e1e955e1 | 199 | } |
c801d85f | 200 | |
debe6624 | 201 | void wxListHeaderData::SetPosition( int x, int y ) |
c801d85f | 202 | { |
92976ab6 RR |
203 | m_xpos = x; |
204 | m_ypos = y; | |
e1e955e1 | 205 | } |
c801d85f | 206 | |
debe6624 | 207 | void wxListHeaderData::SetHeight( int h ) |
c801d85f | 208 | { |
92976ab6 | 209 | m_height = h; |
e1e955e1 | 210 | } |
c801d85f | 211 | |
debe6624 | 212 | void wxListHeaderData::SetWidth( int w ) |
c801d85f | 213 | { |
92976ab6 RR |
214 | m_width = w; |
215 | if (m_width < 0) m_width = 80; | |
216 | if (m_width < 6) m_width = 6; | |
e1e955e1 | 217 | } |
c801d85f | 218 | |
debe6624 | 219 | void wxListHeaderData::SetFormat( int format ) |
c801d85f | 220 | { |
92976ab6 | 221 | m_format = format; |
e1e955e1 | 222 | } |
c801d85f | 223 | |
fd9811b1 | 224 | bool wxListHeaderData::HasImage() const |
c801d85f | 225 | { |
92976ab6 | 226 | return (m_image != 0); |
e1e955e1 | 227 | } |
c801d85f | 228 | |
fd9811b1 | 229 | bool wxListHeaderData::HasText() const |
c801d85f | 230 | { |
92976ab6 | 231 | return (m_text.Length() > 0); |
e1e955e1 | 232 | } |
c801d85f KB |
233 | |
234 | bool wxListHeaderData::IsHit( int x, int y ) const | |
235 | { | |
92976ab6 | 236 | return ((x >= m_xpos) && (x <= m_xpos+m_width) && (y >= m_ypos) && (y <= m_ypos+m_height)); |
e1e955e1 | 237 | } |
c801d85f KB |
238 | |
239 | void wxListHeaderData::GetItem( wxListItem &item ) | |
240 | { | |
92976ab6 RR |
241 | item.m_mask = m_mask; |
242 | item.m_text = m_text; | |
243 | item.m_image = m_image; | |
244 | item.m_format = m_format; | |
245 | item.m_width = m_width; | |
e1e955e1 | 246 | } |
c801d85f KB |
247 | |
248 | void wxListHeaderData::GetText( wxString &s ) | |
249 | { | |
92976ab6 | 250 | s = m_text; |
e1e955e1 | 251 | } |
c801d85f | 252 | |
fd9811b1 | 253 | int wxListHeaderData::GetImage() const |
c801d85f | 254 | { |
92976ab6 | 255 | return m_image; |
e1e955e1 | 256 | } |
c801d85f | 257 | |
fd9811b1 | 258 | int wxListHeaderData::GetWidth() const |
c801d85f | 259 | { |
92976ab6 | 260 | return m_width; |
e1e955e1 | 261 | } |
c801d85f | 262 | |
fd9811b1 | 263 | int wxListHeaderData::GetFormat() const |
c801d85f | 264 | { |
92976ab6 | 265 | return m_format; |
e1e955e1 | 266 | } |
c801d85f KB |
267 | |
268 | //----------------------------------------------------------------------------- | |
269 | // wxListLineData | |
270 | //----------------------------------------------------------------------------- | |
271 | ||
272 | IMPLEMENT_DYNAMIC_CLASS(wxListLineData,wxObject); | |
273 | ||
debe6624 | 274 | wxListLineData::wxListLineData( wxListMainWindow *owner, int mode, wxBrush *hilightBrush ) |
c801d85f | 275 | { |
92976ab6 RR |
276 | m_mode = mode; |
277 | m_hilighted = FALSE; | |
278 | m_owner = owner; | |
279 | m_hilightBrush = hilightBrush; | |
280 | m_items.DeleteContents( TRUE ); | |
281 | m_spacing = 0; | |
e1e955e1 | 282 | } |
c801d85f | 283 | |
1e6d9499 | 284 | void wxListLineData::CalculateSize( wxDC *dc, int spacing ) |
c801d85f | 285 | { |
92976ab6 RR |
286 | m_spacing = spacing; |
287 | switch (m_mode) | |
c801d85f | 288 | { |
92976ab6 RR |
289 | case wxLC_ICON: |
290 | { | |
291 | m_bound_all.width = m_spacing; | |
292 | m_bound_all.height = m_spacing+13; | |
293 | wxNode *node = m_items.First(); | |
294 | if (node) | |
295 | { | |
296 | wxListItemData *item = (wxListItemData*)node->Data(); | |
0530737d | 297 | wxString s = item->GetText(); |
13111b2a | 298 | wxCoord lw,lh; |
92976ab6 RR |
299 | dc->GetTextExtent( s, &lw, &lh ); |
300 | if (lw > m_spacing) m_bound_all.width = lw; | |
301 | } | |
302 | break; | |
303 | } | |
304 | case wxLC_LIST: | |
305 | { | |
306 | wxNode *node = m_items.First(); | |
307 | if (node) | |
308 | { | |
309 | wxListItemData *item = (wxListItemData*)node->Data(); | |
0530737d | 310 | wxString s = item->GetText(); |
13111b2a | 311 | wxCoord lw,lh; |
92976ab6 RR |
312 | dc->GetTextExtent( s, &lw, &lh ); |
313 | m_bound_all.width = lw; | |
314 | m_bound_all.height = lh; | |
0b855868 RR |
315 | if (item->HasImage()) |
316 | { | |
13111b2a VZ |
317 | wxCoord w = 0; |
318 | wxCoord h = 0; | |
0b855868 | 319 | m_owner->GetImageSize( item->GetImage(), w, h ); |
bffa1c77 VZ |
320 | m_bound_all.width += 4 + w; |
321 | if (h > m_bound_all.height) m_bound_all.height = h; | |
322 | } | |
92976ab6 RR |
323 | } |
324 | break; | |
325 | } | |
326 | case wxLC_REPORT: | |
327 | { | |
328 | m_bound_all.width = 0; | |
329 | m_bound_all.height = 0; | |
330 | wxNode *node = m_items.First(); | |
331 | while (node) | |
332 | { | |
333 | wxListItemData *item = (wxListItemData*)node->Data(); | |
334 | wxString s; | |
335 | item->GetText( s ); | |
336 | if (s.IsNull()) s = "H"; | |
13111b2a | 337 | wxCoord lw,lh; |
7c74e7fe | 338 | dc->GetTextExtent( s, &lw, &lh ); |
92976ab6 | 339 | item->SetSize( item->GetWidth(), lh ); |
7c74e7fe | 340 | m_bound_all.width += lw; |
92976ab6 RR |
341 | m_bound_all.height = lh; |
342 | node = node->Next(); | |
343 | } | |
344 | break; | |
345 | } | |
e1e955e1 | 346 | } |
e1e955e1 | 347 | } |
c801d85f | 348 | |
1e6d9499 | 349 | void wxListLineData::SetPosition( wxDC *dc, int x, int y, int window_width ) |
c801d85f | 350 | { |
0b855868 RR |
351 | m_bound_all.x = x; |
352 | m_bound_all.y = y; | |
353 | switch (m_mode) | |
354 | { | |
355 | case wxLC_ICON: | |
c801d85f | 356 | { |
0b855868 RR |
357 | AssignRect( m_bound_icon, 0, 0, 0, 0 ); |
358 | AssignRect( m_bound_label, 0, 0, 0, 0 ); | |
359 | AssignRect( m_bound_hilight, m_bound_all ); | |
360 | wxNode *node = m_items.First(); | |
361 | if (node) | |
362 | { | |
363 | wxListItemData *item = (wxListItemData*)node->Data(); | |
364 | if (item->HasImage()) | |
365 | { | |
366 | wxListItemData *item = (wxListItemData*)node->Data(); | |
367 | int w = 0; | |
368 | int h = 0; | |
369 | m_owner->GetImageSize( item->GetImage(), w, h ); | |
370 | m_bound_icon.x = m_bound_all.x + (m_spacing/2) - (w/2); | |
371 | m_bound_icon.y = m_bound_all.y + m_spacing - h - 5; | |
372 | m_bound_icon.width = w; | |
373 | m_bound_icon.height = h; | |
374 | if (!item->HasText()) | |
375 | { | |
376 | AssignRect( m_bound_hilight, m_bound_icon ); | |
377 | m_bound_hilight.x -= 5; | |
378 | m_bound_hilight.y -= 5; | |
379 | m_bound_hilight.width += 9; | |
380 | m_bound_hilight.height += 9; | |
381 | } | |
382 | } | |
383 | if (item->HasText()) | |
384 | { | |
385 | wxString s; | |
386 | item->GetText( s ); | |
13111b2a | 387 | wxCoord lw,lh; |
0b855868 RR |
388 | dc->GetTextExtent( s, &lw, &lh ); |
389 | if (m_bound_all.width > m_spacing) | |
390 | m_bound_label.x = m_bound_all.x; | |
391 | else | |
392 | m_bound_label.x = m_bound_all.x + (m_spacing/2) - lw/2; | |
393 | m_bound_label.y = m_bound_all.y + m_bound_all.height - lh; | |
394 | m_bound_label.width = lw; | |
395 | m_bound_label.height = lh; | |
396 | AssignRect( m_bound_hilight, m_bound_label ); | |
397 | m_bound_hilight.x -= 2; | |
398 | m_bound_hilight.y -= 2; | |
399 | m_bound_hilight.width += 4; | |
400 | m_bound_hilight.height += 4; | |
401 | } | |
402 | } | |
403 | break; | |
e1e955e1 | 404 | } |
0b855868 | 405 | case wxLC_LIST: |
c801d85f | 406 | { |
0b855868 RR |
407 | AssignRect( m_bound_label, m_bound_all ); |
408 | m_bound_all.x -= 2; | |
409 | m_bound_all.y -= 2; | |
410 | m_bound_all.width += 4; | |
411 | m_bound_all.height += 3; | |
412 | AssignRect( m_bound_hilight, m_bound_all ); | |
413 | AssignRect( m_bound_icon, 0, 0, 0, 0 ); | |
414 | wxNode *node = m_items.First(); | |
415 | if (node) | |
416 | { | |
417 | wxListItemData *item = (wxListItemData*)node->Data(); | |
418 | if (item->HasImage()) | |
bffa1c77 | 419 | { |
0b855868 RR |
420 | m_bound_icon.x = m_bound_all.x + 2; |
421 | m_bound_icon.y = m_bound_all.y + 2; | |
bffa1c77 VZ |
422 | int w; |
423 | int h; | |
0b855868 RR |
424 | m_owner->GetImageSize( item->GetImage(), w, h ); |
425 | m_bound_icon.width = w; | |
426 | m_bound_icon.height = h; | |
bffa1c77 VZ |
427 | m_bound_label.x += 4 + w; |
428 | m_bound_label.width -= 4 + w; | |
429 | } | |
430 | } | |
0b855868 RR |
431 | break; |
432 | } | |
433 | case wxLC_REPORT: | |
434 | { | |
13111b2a | 435 | wxCoord lw,lh; |
0b855868 RR |
436 | dc->GetTextExtent( "H", &lw, &lh ); |
437 | m_bound_all.x = 0; | |
438 | m_bound_all.y -= 0; | |
439 | m_bound_all.height = lh+3; | |
440 | m_bound_all.width = window_width; | |
441 | AssignRect( m_bound_hilight, m_bound_all ); | |
442 | AssignRect( m_bound_label, m_bound_all ); | |
443 | AssignRect( m_bound_icon, 0, 0, 0, 0 ); | |
444 | wxNode *node = m_items.First(); | |
445 | if (node) | |
446 | { | |
447 | wxListItemData *item = (wxListItemData*)node->Data(); | |
448 | wxString s; | |
449 | item->GetText( s ); | |
bffa1c77 | 450 | if (s.IsEmpty()) s = wxT("H"); |
13111b2a | 451 | wxCoord lw,lh; |
0b855868 | 452 | dc->GetTextExtent( s, &lw, &lh ); |
bffa1c77 VZ |
453 | m_bound_label.width = lw; |
454 | m_bound_label.height = lh; | |
455 | if (item->HasImage()) | |
456 | { | |
0b855868 RR |
457 | m_bound_icon.x = m_bound_all.x + 2; |
458 | m_bound_icon.y = m_bound_all.y + 2; | |
bffa1c77 VZ |
459 | int w; |
460 | int h; | |
0b855868 RR |
461 | m_owner->GetImageSize( item->GetImage(), w, h ); |
462 | m_bound_icon.width = w; | |
463 | m_bound_icon.height = h; | |
bffa1c77 VZ |
464 | m_bound_label.x += 4 + w; |
465 | } | |
466 | } | |
0b855868 | 467 | break; |
e1e955e1 | 468 | } |
e1e955e1 | 469 | } |
e1e955e1 | 470 | } |
c801d85f | 471 | |
debe6624 | 472 | void wxListLineData::SetColumnPosition( int index, int x ) |
c801d85f | 473 | { |
6f2a55e3 | 474 | wxNode *node = m_items.Nth( (size_t)index ); |
92976ab6 RR |
475 | if (node) |
476 | { | |
477 | wxListItemData *item = (wxListItemData*)node->Data(); | |
478 | item->SetPosition( x, m_bound_all.y+1 ); | |
479 | } | |
e1e955e1 | 480 | } |
c801d85f KB |
481 | |
482 | void wxListLineData::GetSize( int &width, int &height ) | |
483 | { | |
139adb6a RR |
484 | width = m_bound_all.width; |
485 | height = m_bound_all.height; | |
e1e955e1 | 486 | } |
c801d85f KB |
487 | |
488 | void wxListLineData::GetExtent( int &x, int &y, int &width, int &height ) | |
489 | { | |
139adb6a RR |
490 | x = m_bound_all.x; |
491 | y = m_bound_all.y; | |
492 | width = m_bound_all.width; | |
493 | height = m_bound_all.height; | |
e1e955e1 | 494 | } |
c801d85f KB |
495 | |
496 | void wxListLineData::GetLabelExtent( int &x, int &y, int &width, int &height ) | |
497 | { | |
139adb6a RR |
498 | x = m_bound_label.x; |
499 | y = m_bound_label.y; | |
500 | width = m_bound_label.width; | |
501 | height = m_bound_label.height; | |
e1e955e1 | 502 | } |
c801d85f | 503 | |
0a240683 | 504 | void wxListLineData::GetRect( wxRect &rect ) |
c801d85f | 505 | { |
139adb6a | 506 | AssignRect( rect, m_bound_all ); |
e1e955e1 | 507 | } |
c801d85f | 508 | |
debe6624 | 509 | long wxListLineData::IsHit( int x, int y ) |
c801d85f | 510 | { |
139adb6a RR |
511 | wxNode *node = m_items.First(); |
512 | if (node) | |
513 | { | |
514 | wxListItemData *item = (wxListItemData*)node->Data(); | |
515 | if (item->HasImage() && IsInRect( x, y, m_bound_icon )) return wxLIST_HITTEST_ONITEMICON; | |
516 | if (item->HasText() && IsInRect( x, y, m_bound_label )) return wxLIST_HITTEST_ONITEMLABEL; | |
517 | // if (!(item->HasImage() || item->HasText())) return 0; | |
518 | } | |
519 | // if there is no icon or text = empty | |
520 | if (IsInRect( x, y, m_bound_all )) return wxLIST_HITTEST_ONITEMICON; | |
521 | return 0; | |
e1e955e1 | 522 | } |
c801d85f | 523 | |
debe6624 | 524 | void wxListLineData::InitItems( int num ) |
c801d85f | 525 | { |
139adb6a | 526 | for (int i = 0; i < num; i++) m_items.Append( new wxListItemData() ); |
e1e955e1 | 527 | } |
c801d85f | 528 | |
debe6624 | 529 | void wxListLineData::SetItem( int index, const wxListItem &info ) |
c801d85f | 530 | { |
139adb6a RR |
531 | wxNode *node = m_items.Nth( index ); |
532 | if (node) | |
533 | { | |
534 | wxListItemData *item = (wxListItemData*)node->Data(); | |
535 | item->SetItem( info ); | |
536 | } | |
e1e955e1 | 537 | } |
c801d85f | 538 | |
1e6d9499 | 539 | void wxListLineData::GetItem( int index, wxListItem &info ) |
c801d85f | 540 | { |
139adb6a RR |
541 | int i = index; |
542 | wxNode *node = m_items.Nth( i ); | |
543 | if (node) | |
544 | { | |
545 | wxListItemData *item = (wxListItemData*)node->Data(); | |
546 | item->GetItem( info ); | |
547 | } | |
e1e955e1 | 548 | } |
c801d85f | 549 | |
debe6624 | 550 | void wxListLineData::GetText( int index, wxString &s ) |
c801d85f | 551 | { |
139adb6a RR |
552 | int i = index; |
553 | wxNode *node = m_items.Nth( i ); | |
554 | s = ""; | |
555 | if (node) | |
556 | { | |
557 | wxListItemData *item = (wxListItemData*)node->Data(); | |
558 | item->GetText( s ); | |
559 | } | |
e1e955e1 | 560 | } |
c801d85f | 561 | |
debe6624 | 562 | void wxListLineData::SetText( int index, const wxString s ) |
c801d85f | 563 | { |
139adb6a RR |
564 | int i = index; |
565 | wxNode *node = m_items.Nth( i ); | |
566 | if (node) | |
567 | { | |
568 | wxListItemData *item = (wxListItemData*)node->Data(); | |
569 | item->SetText( s ); | |
570 | } | |
e1e955e1 | 571 | } |
c801d85f | 572 | |
debe6624 | 573 | int wxListLineData::GetImage( int index ) |
c801d85f | 574 | { |
139adb6a RR |
575 | int i = index; |
576 | wxNode *node = m_items.Nth( i ); | |
577 | if (node) | |
578 | { | |
579 | wxListItemData *item = (wxListItemData*)node->Data(); | |
580 | return item->GetImage(); | |
581 | } | |
582 | return -1; | |
e1e955e1 | 583 | } |
c801d85f | 584 | |
0530737d VZ |
585 | void wxListLineData::SetAttributes(wxDC *dc, |
586 | const wxListItemAttr *attr, | |
587 | const wxColour& colText, | |
470caaf9 VZ |
588 | const wxFont& font, |
589 | bool hilight) | |
0530737d | 590 | { |
470caaf9 VZ |
591 | // don't use foregroud colour for drawing highlighted items - this might |
592 | // make them completely invisible (and there is no way to do bit | |
593 | // arithmetics on wxColour, unfortunately) | |
594 | if ( !hilight && attr && attr->HasTextColour() ) | |
0530737d VZ |
595 | { |
596 | dc->SetTextForeground(attr->GetTextColour()); | |
597 | } | |
598 | else | |
599 | { | |
600 | dc->SetTextForeground(colText); | |
601 | } | |
602 | ||
603 | if ( attr && attr->HasFont() ) | |
604 | { | |
605 | dc->SetFont(attr->GetFont()); | |
606 | } | |
607 | else | |
608 | { | |
609 | dc->SetFont(font); | |
610 | } | |
611 | } | |
612 | ||
1e6d9499 | 613 | void wxListLineData::DoDraw( wxDC *dc, bool hilight, bool paintBG ) |
c801d85f | 614 | { |
6f2a55e3 VZ |
615 | wxCoord dev_x = dc->LogicalToDeviceX( m_bound_all.x-2 ); |
616 | wxCoord dev_y = dc->LogicalToDeviceY( m_bound_all.y-2 ); | |
617 | wxCoord dev_w = dc->LogicalToDeviceXRel( m_bound_all.width+4 ); | |
618 | wxCoord dev_h = dc->LogicalToDeviceYRel( m_bound_all.height+4 ); | |
004fd0c8 | 619 | |
139adb6a | 620 | if (!m_owner->IsExposed( dev_x, dev_y, dev_w, dev_h )) |
004fd0c8 | 621 | { |
139adb6a RR |
622 | return; |
623 | } | |
bd8289c1 | 624 | |
0530737d VZ |
625 | wxWindow *listctrl = m_owner->GetParent(); |
626 | ||
627 | // default foreground colour | |
628 | wxColour colText; | |
629 | if ( hilight ) | |
630 | { | |
631 | colText = wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT ); | |
632 | } | |
633 | else | |
634 | { | |
635 | colText = listctrl->GetForegroundColour(); | |
636 | } | |
637 | ||
638 | // default font | |
639 | wxFont font = listctrl->GetFont(); | |
640 | ||
641 | // VZ: currently we set the colours/fonts only once, but like this (i.e. | |
642 | // using SetAttributes() inside the loop), it will be trivial to | |
643 | // customize the subitems (in report mode) too. | |
644 | wxListItemData *item = (wxListItemData*)m_items.First()->Data(); | |
645 | wxListItemAttr *attr = item->GetAttributes(); | |
470caaf9 | 646 | SetAttributes(dc, attr, colText, font, hilight); |
0530737d VZ |
647 | |
648 | bool hasBgCol = attr && attr->HasBackgroundColour(); | |
649 | if ( paintBG || hasBgCol ) | |
c801d85f | 650 | { |
63852e78 RR |
651 | if (hilight) |
652 | { | |
653 | dc->SetBrush( * m_hilightBrush ); | |
63852e78 RR |
654 | } |
655 | else | |
656 | { | |
0530737d VZ |
657 | if ( hasBgCol ) |
658 | dc->SetBrush(wxBrush(attr->GetBackgroundColour(), wxSOLID)); | |
659 | else | |
660 | dc->SetBrush( * wxWHITE_BRUSH ); | |
63852e78 | 661 | } |
0530737d VZ |
662 | |
663 | dc->SetPen( * wxTRANSPARENT_PEN ); | |
63852e78 RR |
664 | dc->DrawRectangle( m_bound_hilight.x, m_bound_hilight.y, |
665 | m_bound_hilight.width, m_bound_hilight.height ); | |
e1e955e1 | 666 | } |
004fd0c8 | 667 | |
63852e78 | 668 | if (m_mode == wxLC_REPORT) |
c801d85f | 669 | { |
63852e78 RR |
670 | wxNode *node = m_items.First(); |
671 | while (node) | |
672 | { | |
673 | wxListItemData *item = (wxListItemData*)node->Data(); | |
674 | dc->SetClippingRegion( item->GetX(), item->GetY(), item->GetWidth()-3, item->GetHeight() ); | |
675 | int x = item->GetX(); | |
676 | if (item->HasImage()) | |
677 | { | |
678 | int y = 0; | |
679 | m_owner->DrawImage( item->GetImage(), dc, x, item->GetY() ); | |
680 | m_owner->GetImageSize( item->GetImage(), x, y ); | |
681 | x += item->GetX() + 5; | |
682 | } | |
683 | if (item->HasText()) | |
684 | { | |
0530737d | 685 | dc->DrawText( item->GetText(), x, item->GetY() ); |
63852e78 RR |
686 | } |
687 | dc->DestroyClippingRegion(); | |
688 | node = node->Next(); | |
689 | } | |
e1e955e1 | 690 | } |
63852e78 | 691 | else |
c801d85f | 692 | { |
63852e78 RR |
693 | wxNode *node = m_items.First(); |
694 | if (node) | |
695 | { | |
696 | wxListItemData *item = (wxListItemData*)node->Data(); | |
697 | if (item->HasImage()) | |
698 | { | |
699 | m_owner->DrawImage( item->GetImage(), dc, m_bound_icon.x, m_bound_icon.y ); | |
700 | } | |
701 | if (item->HasText()) | |
702 | { | |
0530737d | 703 | dc->DrawText( item->GetText(), m_bound_label.x, m_bound_label.y ); |
63852e78 RR |
704 | } |
705 | } | |
e1e955e1 | 706 | } |
e1e955e1 | 707 | } |
c801d85f | 708 | |
debe6624 | 709 | void wxListLineData::Hilight( bool on ) |
c801d85f | 710 | { |
63852e78 | 711 | if (on == m_hilighted) return; |
6e228e42 | 712 | m_hilighted = on; |
63852e78 RR |
713 | if (on) |
714 | m_owner->SelectLine( this ); | |
715 | else | |
716 | m_owner->DeselectLine( this ); | |
e1e955e1 | 717 | } |
c801d85f KB |
718 | |
719 | void wxListLineData::ReverseHilight( void ) | |
720 | { | |
63852e78 RR |
721 | m_hilighted = !m_hilighted; |
722 | if (m_hilighted) | |
723 | m_owner->SelectLine( this ); | |
724 | else | |
725 | m_owner->DeselectLine( this ); | |
e1e955e1 | 726 | } |
c801d85f | 727 | |
1e6d9499 | 728 | void wxListLineData::DrawRubberBand( wxDC *dc, bool on ) |
c801d85f | 729 | { |
63852e78 RR |
730 | if (on) |
731 | { | |
732 | dc->SetPen( * wxBLACK_PEN ); | |
733 | dc->SetBrush( * wxTRANSPARENT_BRUSH ); | |
734 | dc->DrawRectangle( m_bound_hilight.x, m_bound_hilight.y, | |
735 | m_bound_hilight.width, m_bound_hilight.height ); | |
736 | } | |
e1e955e1 | 737 | } |
c801d85f | 738 | |
1e6d9499 | 739 | void wxListLineData::Draw( wxDC *dc ) |
c801d85f | 740 | { |
63852e78 | 741 | DoDraw( dc, m_hilighted, m_hilighted ); |
e1e955e1 | 742 | } |
c801d85f | 743 | |
0a240683 | 744 | bool wxListLineData::IsInRect( int x, int y, const wxRect &rect ) |
c801d85f | 745 | { |
004fd0c8 | 746 | return ((x >= rect.x) && (x <= rect.x+rect.width) && |
63852e78 | 747 | (y >= rect.y) && (y <= rect.y+rect.height)); |
e1e955e1 | 748 | } |
c801d85f KB |
749 | |
750 | bool wxListLineData::IsHilighted( void ) | |
751 | { | |
63852e78 | 752 | return m_hilighted; |
e1e955e1 | 753 | } |
c801d85f | 754 | |
0a240683 | 755 | void wxListLineData::AssignRect( wxRect &dest, int x, int y, int width, int height ) |
c801d85f | 756 | { |
63852e78 RR |
757 | dest.x = x; |
758 | dest.y = y; | |
759 | dest.width = width; | |
760 | dest.height = height; | |
e1e955e1 | 761 | } |
c801d85f | 762 | |
0a240683 | 763 | void wxListLineData::AssignRect( wxRect &dest, const wxRect &source ) |
c801d85f | 764 | { |
63852e78 RR |
765 | dest.x = source.x; |
766 | dest.y = source.y; | |
767 | dest.width = source.width; | |
768 | dest.height = source.height; | |
e1e955e1 | 769 | } |
c801d85f KB |
770 | |
771 | //----------------------------------------------------------------------------- | |
772 | // wxListHeaderWindow | |
773 | //----------------------------------------------------------------------------- | |
774 | ||
775 | IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow,wxWindow); | |
776 | ||
777 | BEGIN_EVENT_TABLE(wxListHeaderWindow,wxWindow) | |
63852e78 RR |
778 | EVT_PAINT (wxListHeaderWindow::OnPaint) |
779 | EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse) | |
780 | EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus) | |
c801d85f KB |
781 | END_EVENT_TABLE() |
782 | ||
783 | wxListHeaderWindow::wxListHeaderWindow( void ) | |
784 | { | |
63852e78 RR |
785 | m_owner = (wxListMainWindow *) NULL; |
786 | m_currentCursor = (wxCursor *) NULL; | |
787 | m_resizeCursor = (wxCursor *) NULL; | |
cfb50f14 | 788 | m_isDragging = FALSE; |
e1e955e1 | 789 | } |
c801d85f | 790 | |
bd8289c1 | 791 | wxListHeaderWindow::wxListHeaderWindow( wxWindow *win, wxWindowID id, wxListMainWindow *owner, |
debe6624 JS |
792 | const wxPoint &pos, const wxSize &size, |
793 | long style, const wxString &name ) : | |
c801d85f KB |
794 | wxWindow( win, id, pos, size, style, name ) |
795 | { | |
63852e78 | 796 | m_owner = owner; |
c801d85f | 797 | // m_currentCursor = wxSTANDARD_CURSOR; |
63852e78 RR |
798 | m_currentCursor = (wxCursor *) NULL; |
799 | m_resizeCursor = new wxCursor( wxCURSOR_SIZEWE ); | |
cfb50f14 RR |
800 | m_isDragging = FALSE; |
801 | SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE ) ); | |
e1e955e1 | 802 | } |
c801d85f | 803 | |
a367b9b3 JS |
804 | wxListHeaderWindow::~wxListHeaderWindow( void ) |
805 | { | |
63852e78 | 806 | delete m_resizeCursor; |
a367b9b3 JS |
807 | } |
808 | ||
1e6d9499 | 809 | void wxListHeaderWindow::DoDrawRect( wxDC *dc, int x, int y, int w, int h ) |
c801d85f | 810 | { |
63852e78 | 811 | const int m_corner = 1; |
c801d85f | 812 | |
63852e78 | 813 | dc->SetBrush( *wxTRANSPARENT_BRUSH ); |
c801d85f | 814 | |
63852e78 RR |
815 | dc->SetPen( *wxBLACK_PEN ); |
816 | dc->DrawLine( x+w-m_corner+1, y, x+w, y+h ); // right (outer) | |
17867d61 | 817 | dc->DrawRectangle( x, y+h, w+1, 1 ); // bottom (outer) |
bd8289c1 | 818 | |
63852e78 | 819 | wxPen pen( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNSHADOW ), 1, wxSOLID ); |
004fd0c8 | 820 | |
63852e78 RR |
821 | dc->SetPen( pen ); |
822 | dc->DrawLine( x+w-m_corner, y, x+w-1, y+h ); // right (inner) | |
823 | dc->DrawRectangle( x+1, y+h-1, w-2, 1 ); // bottom (inner) | |
bd8289c1 | 824 | |
63852e78 RR |
825 | dc->SetPen( *wxWHITE_PEN ); |
826 | dc->DrawRectangle( x, y, w-m_corner+1, 1 ); // top (outer) | |
827 | dc->DrawRectangle( x, y, 1, h ); // left (outer) | |
828 | dc->DrawLine( x, y+h-1, x+1, y+h-1 ); | |
829 | dc->DrawLine( x+w-1, y, x+w-1, y+1 ); | |
e1e955e1 | 830 | } |
c801d85f KB |
831 | |
832 | void wxListHeaderWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) | |
833 | { | |
63852e78 RR |
834 | wxPaintDC dc( this ); |
835 | PrepareDC( dc ); | |
7c74e7fe | 836 | #if wxUSE_GENERIC_LIST_EXTENSIONS |
bffa1c77 VZ |
837 | if ( m_owner->GetMode() & wxLC_REPORT ) |
838 | { | |
839 | int x , y ; | |
840 | int xpix , ypix ; | |
841 | ||
842 | m_owner->GetScrollPixelsPerUnit( &xpix , &ypix ) ; | |
843 | m_owner->ViewStart( &x, &y ) ; | |
844 | dc.SetDeviceOrigin( -x * xpix, 0 ); | |
845 | } | |
7c74e7fe | 846 | #endif |
63852e78 | 847 | dc.BeginDrawing(); |
bd8289c1 | 848 | |
63852e78 | 849 | dc.SetFont( GetFont() ); |
bd8289c1 | 850 | |
63852e78 RR |
851 | int w = 0; |
852 | int h = 0; | |
853 | int x = 0; | |
854 | int y = 0; | |
855 | GetClientSize( &w, &h ); | |
c801d85f | 856 | |
f60d0f94 | 857 | dc.SetBackgroundMode(wxTRANSPARENT); |
63852e78 | 858 | dc.SetTextForeground( *wxBLACK ); |
70846f0a VZ |
859 | |
860 | // do *not* use the listctrl colour for headers - one day we will have a | |
861 | // function to set it separately | |
c801d85f | 862 | |
63852e78 RR |
863 | x = 1; |
864 | y = 1; | |
865 | int numColumns = m_owner->GetColumnCount(); | |
866 | wxListItem item; | |
867 | for (int i = 0; i < numColumns; i++) | |
868 | { | |
869 | m_owner->GetColumn( i, item ); | |
870 | int cw = item.m_width-2; | |
7c74e7fe | 871 | #if wxUSE_GENERIC_LIST_EXTENSIONS |
bffa1c77 | 872 | if ((i+1 == numColumns) || ( dc.LogicalToDeviceX(x+item.m_width) > w-5)) |
470caaf9 | 873 | cw = dc.DeviceToLogicalX(w)-x-1; |
7c74e7fe | 874 | #else |
470caaf9 VZ |
875 | if ((i+1 == numColumns) || (x+item.m_width > w-5)) |
876 | cw = w-x-1; | |
7c74e7fe | 877 | #endif |
63852e78 | 878 | dc.SetPen( *wxWHITE_PEN ); |
c801d85f | 879 | |
63852e78 RR |
880 | DoDrawRect( &dc, x, y, cw, h-2 ); |
881 | dc.SetClippingRegion( x, y, cw-5, h-4 ); | |
882 | dc.DrawText( item.m_text, x+4, y+3 ); | |
883 | dc.DestroyClippingRegion(); | |
884 | x += item.m_width; | |
7c74e7fe SC |
885 | #if wxUSE_GENERIC_LIST_EXTENSIONS |
886 | if (dc.LogicalToDeviceX(x) > w+5) break; | |
887 | #else | |
63852e78 | 888 | if (x > w+5) break; |
7c74e7fe | 889 | #endif |
63852e78 RR |
890 | } |
891 | dc.EndDrawing(); | |
e1e955e1 | 892 | } |
c801d85f | 893 | |
0208334d RR |
894 | void wxListHeaderWindow::DrawCurrent() |
895 | { | |
63852e78 RR |
896 | int x1 = m_currentX; |
897 | int y1 = 0; | |
898 | int x2 = m_currentX-1; | |
899 | int y2 = 0; | |
900 | int dummy; | |
901 | m_owner->GetClientSize( &dummy, &y2 ); | |
902 | ClientToScreen( &x1, &y1 ); | |
903 | m_owner->ClientToScreen( &x2, &y2 ); | |
0208334d | 904 | |
63852e78 | 905 | wxScreenDC dc; |
3c679789 | 906 | dc.SetLogicalFunction( wxINVERT ); |
63852e78 RR |
907 | dc.SetPen( wxPen( *wxBLACK, 2, wxSOLID ) ); |
908 | dc.SetBrush( *wxTRANSPARENT_BRUSH ); | |
0208334d | 909 | |
63852e78 | 910 | dc.DrawLine( x1, y1, x2, y2 ); |
0208334d | 911 | |
63852e78 | 912 | dc.SetLogicalFunction( wxCOPY ); |
0208334d | 913 | |
63852e78 RR |
914 | dc.SetPen( wxNullPen ); |
915 | dc.SetBrush( wxNullBrush ); | |
0208334d RR |
916 | } |
917 | ||
c801d85f KB |
918 | void wxListHeaderWindow::OnMouse( wxMouseEvent &event ) |
919 | { | |
6f2a55e3 VZ |
920 | wxCoord x = (wxCoord)event.GetX(); |
921 | wxCoord y = (wxCoord)event.GetY(); | |
cfb50f14 | 922 | if (m_isDragging) |
0208334d | 923 | { |
63852e78 RR |
924 | DrawCurrent(); |
925 | if (event.ButtonUp()) | |
926 | { | |
927 | ReleaseMouse(); | |
cfb50f14 | 928 | m_isDragging = FALSE; |
63852e78 RR |
929 | m_owner->SetColumnWidth( m_column, m_currentX-m_minX ); |
930 | } | |
931 | else | |
932 | { | |
933 | int size_x = 0; | |
934 | int dummy; | |
935 | GetClientSize( &size_x, & dummy ); | |
936 | if (x > m_minX+7) | |
937 | m_currentX = x; | |
938 | else | |
939 | m_currentX = m_minX+7; | |
940 | if (m_currentX > size_x-7) m_currentX = size_x-7; | |
941 | DrawCurrent(); | |
942 | } | |
943 | return; | |
0208334d | 944 | } |
bd8289c1 | 945 | |
63852e78 RR |
946 | m_minX = 0; |
947 | bool hit_border = FALSE; | |
948 | int xpos = 0; | |
4b59bea3 | 949 | for (int j = 0; j < m_owner->GetColumnCount()-1; j++) |
bd8289c1 | 950 | { |
63852e78 | 951 | xpos += m_owner->GetColumnWidth( j ); |
8636aed8 | 952 | m_column = j; |
63852e78 RR |
953 | if ((abs(x-xpos) < 3) && (y < 22)) |
954 | { | |
955 | hit_border = TRUE; | |
63852e78 RR |
956 | break; |
957 | } | |
bffa1c77 VZ |
958 | if (x-xpos < 0) |
959 | { | |
960 | break; | |
961 | } | |
63852e78 | 962 | m_minX = xpos; |
0208334d | 963 | } |
bd8289c1 | 964 | |
8636aed8 | 965 | if (event.LeftDown()) |
c801d85f | 966 | { |
8636aed8 | 967 | if (hit_border) |
bffa1c77 | 968 | { |
8636aed8 RR |
969 | m_isDragging = TRUE; |
970 | m_currentX = x; | |
971 | DrawCurrent(); | |
972 | CaptureMouse(); | |
973 | return; | |
bffa1c77 VZ |
974 | } |
975 | else | |
976 | { | |
8636aed8 RR |
977 | wxListEvent le( wxEVT_COMMAND_LIST_COL_CLICK, GetParent()->GetId() ); |
978 | le.SetEventObject( GetParent() ); | |
bffa1c77 | 979 | le.m_col = m_column; |
8636aed8 | 980 | GetParent()->GetEventHandler()->ProcessEvent( le ); |
bffa1c77 VZ |
981 | return; |
982 | } | |
c801d85f | 983 | } |
63852e78 RR |
984 | |
985 | if (event.Moving()) | |
c801d85f | 986 | { |
63852e78 RR |
987 | if (hit_border) |
988 | { | |
989 | if (m_currentCursor == wxSTANDARD_CURSOR) SetCursor( * m_resizeCursor ); | |
990 | m_currentCursor = m_resizeCursor; | |
991 | } | |
992 | else | |
993 | { | |
994 | if (m_currentCursor != wxSTANDARD_CURSOR) SetCursor( * wxSTANDARD_CURSOR ); | |
995 | m_currentCursor = wxSTANDARD_CURSOR; | |
996 | } | |
e1e955e1 | 997 | } |
e1e955e1 | 998 | } |
c801d85f KB |
999 | |
1000 | void wxListHeaderWindow::OnSetFocus( wxFocusEvent &WXUNUSED(event) ) | |
1001 | { | |
63852e78 | 1002 | m_owner->SetFocus(); |
e1e955e1 | 1003 | } |
c801d85f KB |
1004 | |
1005 | //----------------------------------------------------------------------------- | |
1006 | // wxListRenameTimer (internal) | |
1007 | //----------------------------------------------------------------------------- | |
1008 | ||
bd8289c1 VZ |
1009 | wxListRenameTimer::wxListRenameTimer( wxListMainWindow *owner ) |
1010 | { | |
63852e78 | 1011 | m_owner = owner; |
e1e955e1 | 1012 | } |
c801d85f | 1013 | |
bd8289c1 VZ |
1014 | void wxListRenameTimer::Notify() |
1015 | { | |
63852e78 | 1016 | m_owner->OnRenameTimer(); |
e1e955e1 | 1017 | } |
c801d85f | 1018 | |
ee7ee469 RR |
1019 | //----------------------------------------------------------------------------- |
1020 | // wxListTextCtrl (internal) | |
1021 | //----------------------------------------------------------------------------- | |
1022 | ||
1023 | IMPLEMENT_DYNAMIC_CLASS(wxListTextCtrl,wxTextCtrl); | |
bd8289c1 | 1024 | |
ee7ee469 | 1025 | BEGIN_EVENT_TABLE(wxListTextCtrl,wxTextCtrl) |
63852e78 RR |
1026 | EVT_CHAR (wxListTextCtrl::OnChar) |
1027 | EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus) | |
ee7ee469 RR |
1028 | END_EVENT_TABLE() |
1029 | ||
674ac8b9 VZ |
1030 | wxListTextCtrl::wxListTextCtrl( wxWindow *parent, |
1031 | const wxWindowID id, | |
1032 | bool *accept, | |
1033 | wxString *res, | |
1034 | wxListMainWindow *owner, | |
1035 | const wxString &value, | |
1036 | const wxPoint &pos, | |
1037 | const wxSize &size, | |
1038 | int style, | |
1039 | const wxValidator& validator, | |
1040 | const wxString &name ) | |
1041 | : wxTextCtrl( parent, id, value, pos, size, style, validator, name ) | |
ee7ee469 | 1042 | { |
63852e78 RR |
1043 | m_res = res; |
1044 | m_accept = accept; | |
1045 | m_owner = owner; | |
5f1ea0ee RR |
1046 | (*m_accept) = FALSE; |
1047 | (*m_res) = ""; | |
1048 | m_startValue = value; | |
ee7ee469 RR |
1049 | } |
1050 | ||
1051 | void wxListTextCtrl::OnChar( wxKeyEvent &event ) | |
1052 | { | |
63852e78 RR |
1053 | if (event.m_keyCode == WXK_RETURN) |
1054 | { | |
1055 | (*m_accept) = TRUE; | |
1056 | (*m_res) = GetValue(); | |
bffa1c77 | 1057 | m_owner->SetFocus(); |
63852e78 RR |
1058 | return; |
1059 | } | |
1060 | if (event.m_keyCode == WXK_ESCAPE) | |
1061 | { | |
1062 | (*m_accept) = FALSE; | |
1063 | (*m_res) = ""; | |
bffa1c77 | 1064 | m_owner->SetFocus(); |
63852e78 RR |
1065 | return; |
1066 | } | |
1067 | event.Skip(); | |
1068 | } | |
1069 | ||
1070 | void wxListTextCtrl::OnKillFocus( wxFocusEvent &WXUNUSED(event) ) | |
1071 | { | |
5f1ea0ee RR |
1072 | if (wxPendingDelete.Member(this)) return; |
1073 | ||
1074 | wxPendingDelete.Append(this); | |
004fd0c8 | 1075 | |
5f1ea0ee RR |
1076 | if ((*m_accept) && ((*m_res) != m_startValue)) |
1077 | m_owner->OnRenameAccept(); | |
ee7ee469 RR |
1078 | } |
1079 | ||
c801d85f KB |
1080 | //----------------------------------------------------------------------------- |
1081 | // wxListMainWindow | |
1082 | //----------------------------------------------------------------------------- | |
1083 | ||
1084 | IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow,wxScrolledWindow); | |
bd8289c1 | 1085 | |
c801d85f KB |
1086 | BEGIN_EVENT_TABLE(wxListMainWindow,wxScrolledWindow) |
1087 | EVT_PAINT (wxListMainWindow::OnPaint) | |
1088 | EVT_SIZE (wxListMainWindow::OnSize) | |
1089 | EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse) | |
1090 | EVT_CHAR (wxListMainWindow::OnChar) | |
3dfb93fd | 1091 | EVT_KEY_DOWN (wxListMainWindow::OnKeyDown) |
c801d85f KB |
1092 | EVT_SET_FOCUS (wxListMainWindow::OnSetFocus) |
1093 | EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus) | |
bffa1c77 | 1094 | EVT_SCROLLWIN (wxListMainWindow::OnScroll) |
c801d85f KB |
1095 | END_EVENT_TABLE() |
1096 | ||
fd9811b1 | 1097 | wxListMainWindow::wxListMainWindow() |
c801d85f | 1098 | { |
139adb6a RR |
1099 | m_mode = 0; |
1100 | m_lines.DeleteContents( TRUE ); | |
1101 | m_columns.DeleteContents( TRUE ); | |
1102 | m_current = (wxListLineData *) NULL; | |
1103 | m_visibleLines = 0; | |
1104 | m_hilightBrush = (wxBrush *) NULL; | |
1105 | m_xScroll = 0; | |
1106 | m_yScroll = 0; | |
1107 | m_dirty = TRUE; | |
1108 | m_small_image_list = (wxImageList *) NULL; | |
1109 | m_normal_image_list = (wxImageList *) NULL; | |
1110 | m_small_spacing = 30; | |
1111 | m_normal_spacing = 40; | |
1112 | m_hasFocus = FALSE; | |
1113 | m_usedKeys = TRUE; | |
1114 | m_lastOnSame = FALSE; | |
1115 | m_renameTimer = new wxListRenameTimer( this ); | |
1116 | m_isCreated = FALSE; | |
1117 | m_dragCount = 0; | |
e1e955e1 | 1118 | } |
c801d85f | 1119 | |
bd8289c1 | 1120 | wxListMainWindow::wxListMainWindow( wxWindow *parent, wxWindowID id, |
c801d85f | 1121 | const wxPoint &pos, const wxSize &size, |
debe6624 | 1122 | long style, const wxString &name ) : |
a367b9b3 | 1123 | wxScrolledWindow( parent, id, pos, size, style|wxHSCROLL|wxVSCROLL, name ) |
c801d85f | 1124 | { |
139adb6a RR |
1125 | m_mode = style; |
1126 | m_lines.DeleteContents( TRUE ); | |
1127 | m_columns.DeleteContents( TRUE ); | |
1128 | m_current = (wxListLineData *) NULL; | |
1129 | m_dirty = TRUE; | |
1130 | m_visibleLines = 0; | |
1131 | m_hilightBrush = new wxBrush( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT), wxSOLID ); | |
1132 | m_small_image_list = (wxImageList *) NULL; | |
1133 | m_normal_image_list = (wxImageList *) NULL; | |
1134 | m_small_spacing = 30; | |
1135 | m_normal_spacing = 40; | |
1136 | m_hasFocus = FALSE; | |
1137 | m_dragCount = 0; | |
1138 | m_isCreated = FALSE; | |
1139 | wxSize sz = size; | |
1140 | sz.y = 25; | |
bd8289c1 | 1141 | |
139adb6a RR |
1142 | if (m_mode & wxLC_REPORT) |
1143 | { | |
7c74e7fe SC |
1144 | #if wxUSE_GENERIC_LIST_EXTENSIONS |
1145 | m_xScroll = 15; | |
1146 | #else | |
139adb6a | 1147 | m_xScroll = 0; |
7c74e7fe | 1148 | #endif |
139adb6a RR |
1149 | m_yScroll = 15; |
1150 | } | |
1151 | else | |
1152 | { | |
1153 | m_xScroll = 15; | |
1154 | m_yScroll = 0; | |
1155 | } | |
1156 | SetScrollbars( m_xScroll, m_yScroll, 0, 0, 0, 0 ); | |
bd8289c1 | 1157 | |
139adb6a RR |
1158 | m_usedKeys = TRUE; |
1159 | m_lastOnSame = FALSE; | |
1160 | m_renameTimer = new wxListRenameTimer( this ); | |
1161 | m_renameAccept = FALSE; | |
c801d85f | 1162 | |
139adb6a | 1163 | SetBackgroundColour( *wxWHITE ); |
e1e955e1 | 1164 | } |
c801d85f | 1165 | |
fd9811b1 | 1166 | wxListMainWindow::~wxListMainWindow() |
c801d85f | 1167 | { |
139adb6a | 1168 | if (m_hilightBrush) delete m_hilightBrush; |
004fd0c8 | 1169 | |
139adb6a | 1170 | delete m_renameTimer; |
e1e955e1 | 1171 | } |
c801d85f KB |
1172 | |
1173 | void wxListMainWindow::RefreshLine( wxListLineData *line ) | |
1174 | { | |
e6527f9d | 1175 | if (m_dirty) return; |
25e3a937 | 1176 | |
139adb6a RR |
1177 | int x = 0; |
1178 | int y = 0; | |
1179 | int w = 0; | |
1180 | int h = 0; | |
1181 | if (line) | |
1182 | { | |
1183 | wxClientDC dc(this); | |
1184 | PrepareDC( dc ); | |
1185 | line->GetExtent( x, y, w, h ); | |
0a240683 | 1186 | wxRect rect( |
139adb6a RR |
1187 | dc.LogicalToDeviceX(x-3), |
1188 | dc.LogicalToDeviceY(y-3), | |
1189 | dc.LogicalToDeviceXRel(w+6), | |
1190 | dc.LogicalToDeviceXRel(h+6) ); | |
1191 | Refresh( TRUE, &rect ); | |
1192 | } | |
e1e955e1 | 1193 | } |
c801d85f KB |
1194 | |
1195 | void wxListMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) | |
1196 | { | |
f60d0f94 JS |
1197 | // Note: a wxPaintDC must be constructed even if no drawing is |
1198 | // done (a Windows requirement). | |
1199 | wxPaintDC dc( this ); | |
1200 | PrepareDC( dc ); | |
1201 | ||
139adb6a | 1202 | if (m_dirty) return; |
004fd0c8 | 1203 | |
139adb6a | 1204 | if (m_lines.GetCount() == 0) return; |
bd8289c1 | 1205 | |
139adb6a | 1206 | dc.BeginDrawing(); |
c801d85f | 1207 | |
139adb6a | 1208 | dc.SetFont( GetFont() ); |
004fd0c8 | 1209 | |
139adb6a RR |
1210 | if (m_mode & wxLC_REPORT) |
1211 | { | |
1212 | int lineSpacing = 0; | |
1213 | wxListLineData *line = (wxListLineData*)m_lines.First()->Data(); | |
1214 | int dummy = 0; | |
1215 | line->GetSize( dummy, lineSpacing ); | |
1216 | lineSpacing += 1; | |
bffa1c77 | 1217 | |
139adb6a | 1218 | int y_s = m_yScroll*GetScrollPos( wxVERTICAL ); |
bffa1c77 | 1219 | |
139adb6a | 1220 | wxNode *node = m_lines.Nth( y_s / lineSpacing ); |
bffa1c77 VZ |
1221 | for (int i = 0; i < m_visibleLines+2; i++) |
1222 | { | |
1223 | if (!node) break; | |
1224 | ||
139adb6a RR |
1225 | line = (wxListLineData*)node->Data(); |
1226 | line->Draw( &dc ); | |
1227 | node = node->Next(); | |
bffa1c77 | 1228 | } |
139adb6a RR |
1229 | } |
1230 | else | |
1231 | { | |
1232 | wxNode *node = m_lines.First(); | |
1233 | while (node) | |
1234 | { | |
1235 | wxListLineData *line = (wxListLineData*)node->Data(); | |
1236 | line->Draw( &dc ); | |
1237 | node = node->Next(); | |
1238 | } | |
1239 | } | |
004fd0c8 | 1240 | |
139adb6a | 1241 | if (m_current) m_current->DrawRubberBand( &dc, m_hasFocus ); |
c801d85f | 1242 | |
139adb6a | 1243 | dc.EndDrawing(); |
e1e955e1 | 1244 | } |
c801d85f | 1245 | |
debe6624 | 1246 | void wxListMainWindow::HilightAll( bool on ) |
c801d85f | 1247 | { |
139adb6a RR |
1248 | wxNode *node = m_lines.First(); |
1249 | while (node) | |
c801d85f | 1250 | { |
139adb6a RR |
1251 | wxListLineData *line = (wxListLineData *)node->Data(); |
1252 | if (line->IsHilighted() != on) | |
1253 | { | |
1254 | line->Hilight( on ); | |
1255 | RefreshLine( line ); | |
1256 | } | |
1257 | node = node->Next(); | |
e1e955e1 | 1258 | } |
e1e955e1 | 1259 | } |
c801d85f | 1260 | |
7798a18e | 1261 | void wxListMainWindow::SendNotify( wxListLineData *line, wxEventType command ) |
c801d85f | 1262 | { |
139adb6a RR |
1263 | wxListEvent le( command, GetParent()->GetId() ); |
1264 | le.SetEventObject( GetParent() ); | |
1265 | le.m_itemIndex = GetIndexOfLine( line ); | |
1266 | line->GetItem( 0, le.m_item ); | |
6e228e42 RR |
1267 | GetParent()->GetEventHandler()->ProcessEvent( le ); |
1268 | // GetParent()->GetEventHandler()->AddPendingEvent( le ); | |
e1e955e1 | 1269 | } |
c801d85f KB |
1270 | |
1271 | void wxListMainWindow::FocusLine( wxListLineData *WXUNUSED(line) ) | |
1272 | { | |
1273 | // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_FOCUSSED ); | |
e1e955e1 | 1274 | } |
c801d85f KB |
1275 | |
1276 | void wxListMainWindow::UnfocusLine( wxListLineData *WXUNUSED(line) ) | |
1277 | { | |
1278 | // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_UNFOCUSSED ); | |
e1e955e1 | 1279 | } |
c801d85f KB |
1280 | |
1281 | void wxListMainWindow::SelectLine( wxListLineData *line ) | |
1282 | { | |
139adb6a | 1283 | SendNotify( line, wxEVT_COMMAND_LIST_ITEM_SELECTED ); |
e1e955e1 | 1284 | } |
c801d85f KB |
1285 | |
1286 | void wxListMainWindow::DeselectLine( wxListLineData *line ) | |
1287 | { | |
139adb6a | 1288 | SendNotify( line, wxEVT_COMMAND_LIST_ITEM_DESELECTED ); |
e1e955e1 | 1289 | } |
c801d85f KB |
1290 | |
1291 | void wxListMainWindow::DeleteLine( wxListLineData *line ) | |
1292 | { | |
139adb6a | 1293 | SendNotify( line, wxEVT_COMMAND_LIST_DELETE_ITEM ); |
e1e955e1 | 1294 | } |
c801d85f | 1295 | |
e179bd65 | 1296 | /* *** */ |
ee7ee469 | 1297 | |
5f1ea0ee | 1298 | void wxListMainWindow::EditLabel( long item ) |
c801d85f | 1299 | { |
6f2a55e3 | 1300 | wxNode *node = m_lines.Nth( (size_t)item ); |
223d09f6 | 1301 | wxCHECK_RET( node, wxT("wrong index in wxListCtrl::Edit()") ); |
004fd0c8 | 1302 | |
e179bd65 RR |
1303 | m_currentEdit = (wxListLineData*) node->Data(); |
1304 | ||
fd9811b1 | 1305 | wxListEvent le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT, GetParent()->GetId() ); |
139adb6a | 1306 | le.SetEventObject( GetParent() ); |
e179bd65 RR |
1307 | le.m_itemIndex = GetIndexOfLine( m_currentEdit ); |
1308 | m_currentEdit->GetItem( 0, le.m_item ); | |
139adb6a | 1309 | GetParent()->GetEventHandler()->ProcessEvent( le ); |
004fd0c8 | 1310 | |
86f975a8 | 1311 | if (!le.IsAllowed()) |
5f1ea0ee | 1312 | return; |
004fd0c8 | 1313 | |
dc6c62a9 RR |
1314 | // We have to call this here because the label in |
1315 | // question might just have been added and no screen | |
1316 | // update taken place. | |
1317 | if (m_dirty) wxYield(); | |
1318 | ||
92976ab6 | 1319 | wxString s; |
e179bd65 | 1320 | m_currentEdit->GetText( 0, s ); |
92976ab6 RR |
1321 | int x = 0; |
1322 | int y = 0; | |
1323 | int w = 0; | |
1324 | int h = 0; | |
e179bd65 | 1325 | m_currentEdit->GetLabelExtent( x, y, w, h ); |
004fd0c8 | 1326 | |
92976ab6 RR |
1327 | wxClientDC dc(this); |
1328 | PrepareDC( dc ); | |
1329 | x = dc.LogicalToDeviceX( x ); | |
1330 | y = dc.LogicalToDeviceY( y ); | |
bd8289c1 | 1331 | |
92976ab6 RR |
1332 | wxListTextCtrl *text = new wxListTextCtrl( |
1333 | this, -1, &m_renameAccept, &m_renameRes, this, s, wxPoint(x-4,y-4), wxSize(w+11,h+8) ); | |
1334 | text->SetFocus(); | |
e1e955e1 | 1335 | } |
c801d85f | 1336 | |
e179bd65 RR |
1337 | void wxListMainWindow::OnRenameTimer() |
1338 | { | |
223d09f6 | 1339 | wxCHECK_RET( m_current, wxT("invalid m_current") ); |
004fd0c8 | 1340 | |
e179bd65 RR |
1341 | Edit( m_lines.IndexOf( m_current ) ); |
1342 | } | |
1343 | ||
c801d85f KB |
1344 | void wxListMainWindow::OnRenameAccept() |
1345 | { | |
e179bd65 RR |
1346 | wxListEvent le( wxEVT_COMMAND_LIST_END_LABEL_EDIT, GetParent()->GetId() ); |
1347 | le.SetEventObject( GetParent() ); | |
1348 | le.m_itemIndex = GetIndexOfLine( m_currentEdit ); | |
1349 | m_currentEdit->GetItem( 0, le.m_item ); | |
1350 | le.m_item.m_text = m_renameRes; | |
1351 | GetParent()->GetEventHandler()->ProcessEvent( le ); | |
004fd0c8 | 1352 | |
e179bd65 | 1353 | if (!le.IsAllowed()) return; |
004fd0c8 | 1354 | |
5f1ea0ee RR |
1355 | wxListItem info; |
1356 | info.m_mask = wxLIST_MASK_TEXT; | |
1357 | info.m_itemId = le.m_itemIndex; | |
1358 | info.m_text = m_renameRes; | |
aaa37c0d | 1359 | info.SetTextColour(le.m_item.GetTextColour()); |
5f1ea0ee | 1360 | SetItem( info ); |
e1e955e1 | 1361 | } |
c801d85f KB |
1362 | |
1363 | void wxListMainWindow::OnMouse( wxMouseEvent &event ) | |
1364 | { | |
92976ab6 | 1365 | if (GetParent()->GetEventHandler()->ProcessEvent( event)) return; |
e3e65dac | 1366 | |
92976ab6 RR |
1367 | if (!m_current) return; |
1368 | if (m_dirty) return; | |
0b855868 | 1369 | if ( !(event.Dragging() || event.ButtonDown() || event.LeftUp() || event.ButtonDClick()) ) return; |
c801d85f | 1370 | |
92976ab6 RR |
1371 | wxClientDC dc(this); |
1372 | PrepareDC(dc); | |
6f2a55e3 VZ |
1373 | wxCoord x = dc.DeviceToLogicalX( (wxCoord)event.GetX() ); |
1374 | wxCoord y = dc.DeviceToLogicalY( (wxCoord)event.GetY() ); | |
004fd0c8 | 1375 | |
51cc4dad | 1376 | /* Did we actually hit an item ? */ |
92976ab6 RR |
1377 | long hitResult = 0; |
1378 | wxNode *node = m_lines.First(); | |
1379 | wxListLineData *line = (wxListLineData *) NULL; | |
1380 | while (node) | |
1381 | { | |
1382 | line = (wxListLineData*)node->Data(); | |
1383 | hitResult = line->IsHit( x, y ); | |
1384 | if (hitResult) break; | |
1385 | line = (wxListLineData *) NULL; | |
1386 | node = node->Next(); | |
1387 | } | |
bd8289c1 | 1388 | |
fd9811b1 | 1389 | if (event.Dragging()) |
92976ab6 | 1390 | { |
fd9811b1 | 1391 | if (m_dragCount == 0) |
bffa1c77 VZ |
1392 | m_dragStart = wxPoint(x,y); |
1393 | ||
fd9811b1 | 1394 | m_dragCount++; |
bffa1c77 VZ |
1395 | |
1396 | if (m_dragCount != 3) return; | |
1397 | ||
1398 | int command = wxEVT_COMMAND_LIST_BEGIN_DRAG; | |
1399 | if (event.RightIsDown()) command = wxEVT_COMMAND_LIST_BEGIN_RDRAG; | |
1400 | ||
fd9811b1 | 1401 | wxListEvent le( command, GetParent()->GetId() ); |
92976ab6 | 1402 | le.SetEventObject( GetParent() ); |
bffa1c77 VZ |
1403 | le.m_pointDrag = m_dragStart; |
1404 | GetParent()->GetEventHandler()->ProcessEvent( le ); | |
1405 | ||
1406 | return; | |
92976ab6 | 1407 | } |
fd9811b1 RR |
1408 | else |
1409 | { | |
1410 | m_dragCount = 0; | |
1411 | } | |
bd8289c1 | 1412 | |
92976ab6 | 1413 | if (!line) return; |
bd8289c1 | 1414 | |
92976ab6 RR |
1415 | if (event.ButtonDClick()) |
1416 | { | |
1417 | m_usedKeys = FALSE; | |
1418 | m_lastOnSame = FALSE; | |
1419 | m_renameTimer->Stop(); | |
004fd0c8 | 1420 | |
435fe83e | 1421 | SendNotify( line, wxEVT_COMMAND_LIST_ITEM_ACTIVATED ); |
004fd0c8 | 1422 | |
92976ab6 RR |
1423 | return; |
1424 | } | |
bd8289c1 | 1425 | |
92976ab6 | 1426 | if (event.LeftUp() && m_lastOnSame) |
c801d85f | 1427 | { |
92976ab6 RR |
1428 | m_usedKeys = FALSE; |
1429 | if ((line == m_current) && | |
1430 | (hitResult == wxLIST_HITTEST_ONITEMLABEL) && | |
1431 | (m_mode & wxLC_EDIT_LABELS) ) | |
1432 | { | |
1433 | m_renameTimer->Start( 100, TRUE ); | |
1434 | } | |
1435 | m_lastOnSame = FALSE; | |
1436 | return; | |
e1e955e1 | 1437 | } |
bd8289c1 | 1438 | |
92976ab6 | 1439 | if (event.RightDown()) |
b204641e | 1440 | { |
92976ab6 RR |
1441 | SendNotify( line, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK ); |
1442 | return; | |
b204641e | 1443 | } |
004fd0c8 | 1444 | |
92976ab6 | 1445 | if (event.MiddleDown()) |
b204641e | 1446 | { |
92976ab6 RR |
1447 | SendNotify( line, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK ); |
1448 | return; | |
1449 | } | |
004fd0c8 | 1450 | |
92976ab6 RR |
1451 | if (event.LeftDown()) |
1452 | { | |
1453 | m_usedKeys = FALSE; | |
1454 | wxListLineData *oldCurrent = m_current; | |
1455 | if (m_mode & wxLC_SINGLE_SEL) | |
b204641e | 1456 | { |
92976ab6 RR |
1457 | m_current = line; |
1458 | HilightAll( FALSE ); | |
1459 | m_current->ReverseHilight(); | |
1460 | RefreshLine( m_current ); | |
e1e955e1 | 1461 | } |
92976ab6 | 1462 | else |
b204641e | 1463 | { |
92976ab6 RR |
1464 | if (event.ShiftDown()) |
1465 | { | |
1466 | m_current = line; | |
1467 | m_current->ReverseHilight(); | |
1468 | RefreshLine( m_current ); | |
1469 | } | |
1470 | else if (event.ControlDown()) | |
1471 | { | |
1472 | m_current = line; | |
bffa1c77 | 1473 | |
92976ab6 RR |
1474 | int numOfCurrent = -1; |
1475 | node = m_lines.First(); | |
1476 | while (node) | |
1477 | { | |
1478 | wxListLineData *test_line = (wxListLineData*)node->Data(); | |
1479 | numOfCurrent++; | |
1480 | if (test_line == oldCurrent) break; | |
1481 | node = node->Next(); | |
1482 | } | |
bffa1c77 | 1483 | |
92976ab6 RR |
1484 | int numOfLine = -1; |
1485 | node = m_lines.First(); | |
1486 | while (node) | |
1487 | { | |
1488 | wxListLineData *test_line = (wxListLineData*)node->Data(); | |
1489 | numOfLine++; | |
1490 | if (test_line == line) break; | |
1491 | node = node->Next(); | |
1492 | } | |
1493 | ||
1494 | if (numOfLine < numOfCurrent) | |
004fd0c8 | 1495 | { |
bffa1c77 VZ |
1496 | int i = numOfLine; |
1497 | numOfLine = numOfCurrent; | |
1498 | numOfCurrent = i; | |
1499 | } | |
1500 | ||
92976ab6 RR |
1501 | wxNode *node = m_lines.Nth( numOfCurrent ); |
1502 | for (int i = 0; i <= numOfLine-numOfCurrent; i++) | |
1503 | { | |
1504 | wxListLineData *test_line= (wxListLineData*)node->Data(); | |
1505 | test_line->Hilight(TRUE); | |
1506 | RefreshLine( test_line ); | |
1507 | node = node->Next(); | |
1508 | } | |
1509 | } | |
1510 | else | |
1511 | { | |
1512 | m_current = line; | |
1513 | HilightAll( FALSE ); | |
1514 | m_current->ReverseHilight(); | |
1515 | RefreshLine( m_current ); | |
1516 | } | |
e1e955e1 | 1517 | } |
92976ab6 RR |
1518 | if (m_current != oldCurrent) |
1519 | { | |
1520 | RefreshLine( oldCurrent ); | |
1521 | UnfocusLine( oldCurrent ); | |
1522 | FocusLine( m_current ); | |
1523 | } | |
1524 | m_lastOnSame = (m_current == oldCurrent); | |
1525 | return; | |
e1e955e1 | 1526 | } |
e1e955e1 | 1527 | } |
c801d85f | 1528 | |
e179bd65 | 1529 | void wxListMainWindow::MoveToFocus() |
c801d85f | 1530 | { |
92976ab6 | 1531 | if (!m_current) return; |
004fd0c8 | 1532 | |
92976ab6 RR |
1533 | int x = 0; |
1534 | int y = 0; | |
1535 | int w = 0; | |
1536 | int h = 0; | |
1537 | m_current->GetExtent( x, y, w, h ); | |
004fd0c8 | 1538 | |
92976ab6 RR |
1539 | int w_p = 0; |
1540 | int h_p = 0; | |
1541 | GetClientSize( &w_p, &h_p ); | |
004fd0c8 | 1542 | |
92976ab6 RR |
1543 | if (m_mode & wxLC_REPORT) |
1544 | { | |
92976ab6 RR |
1545 | int y_s = m_yScroll*GetScrollPos( wxVERTICAL ); |
1546 | if ((y > y_s) && (y+h < y_s+h_p)) return; | |
5e014a0c RR |
1547 | if (y-y_s < 5) { Scroll( -1, (y-5-h_p/2)/m_yScroll ); } |
1548 | if (y+h+5 > y_s+h_p) { Scroll( -1, (y+h-h_p/2+h+15)/m_yScroll); } | |
92976ab6 RR |
1549 | } |
1550 | else | |
1551 | { | |
92976ab6 RR |
1552 | int x_s = m_xScroll*GetScrollPos( wxHORIZONTAL ); |
1553 | if ((x > x_s) && (x+w < x_s+w_p)) return; | |
5e014a0c RR |
1554 | if (x-x_s < 5) { Scroll( (x-5)/m_xScroll, -1 ); } |
1555 | if (x+w-5 > x_s+w_p) { Scroll( (x+w-w_p+15)/m_xScroll, -1 ); } | |
92976ab6 | 1556 | } |
e1e955e1 | 1557 | } |
c801d85f KB |
1558 | |
1559 | void wxListMainWindow::OnArrowChar( wxListLineData *newCurrent, bool shiftDown ) | |
1560 | { | |
92976ab6 RR |
1561 | if ((m_mode & wxLC_SINGLE_SEL) || (m_usedKeys == FALSE)) m_current->Hilight( FALSE ); |
1562 | wxListLineData *oldCurrent = m_current; | |
1563 | m_current = newCurrent; | |
1564 | MoveToFocus(); | |
1565 | if (shiftDown || (m_mode & wxLC_SINGLE_SEL)) m_current->Hilight( TRUE ); | |
1566 | RefreshLine( m_current ); | |
1567 | RefreshLine( oldCurrent ); | |
1568 | FocusLine( m_current ); | |
1569 | UnfocusLine( oldCurrent ); | |
e1e955e1 | 1570 | } |
c801d85f | 1571 | |
3dfb93fd RR |
1572 | void wxListMainWindow::OnKeyDown( wxKeyEvent &event ) |
1573 | { | |
1574 | wxWindow *parent = GetParent(); | |
004fd0c8 | 1575 | |
3dfb93fd RR |
1576 | /* we propagate the key event up */ |
1577 | wxKeyEvent ke( wxEVT_KEY_DOWN ); | |
1578 | ke.m_shiftDown = event.m_shiftDown; | |
1579 | ke.m_controlDown = event.m_controlDown; | |
1580 | ke.m_altDown = event.m_altDown; | |
1581 | ke.m_metaDown = event.m_metaDown; | |
1582 | ke.m_keyCode = event.m_keyCode; | |
1583 | ke.m_x = event.m_x; | |
1584 | ke.m_y = event.m_y; | |
1585 | ke.SetEventObject( parent ); | |
1586 | if (parent->GetEventHandler()->ProcessEvent( ke )) return; | |
004fd0c8 | 1587 | |
3dfb93fd RR |
1588 | event.Skip(); |
1589 | } | |
004fd0c8 | 1590 | |
c801d85f KB |
1591 | void wxListMainWindow::OnChar( wxKeyEvent &event ) |
1592 | { | |
51cc4dad | 1593 | wxWindow *parent = GetParent(); |
004fd0c8 | 1594 | |
51cc4dad RR |
1595 | /* we send a list_key event up */ |
1596 | wxListEvent le( wxEVT_COMMAND_LIST_KEY_DOWN, GetParent()->GetId() ); | |
6f2a55e3 | 1597 | le.m_code = (int)event.KeyCode(); |
51cc4dad RR |
1598 | le.SetEventObject( parent ); |
1599 | parent->GetEventHandler()->ProcessEvent( le ); | |
1600 | ||
3dfb93fd RR |
1601 | /* we propagate the char event up */ |
1602 | wxKeyEvent ke( wxEVT_CHAR ); | |
51cc4dad RR |
1603 | ke.m_shiftDown = event.m_shiftDown; |
1604 | ke.m_controlDown = event.m_controlDown; | |
1605 | ke.m_altDown = event.m_altDown; | |
1606 | ke.m_metaDown = event.m_metaDown; | |
1607 | ke.m_keyCode = event.m_keyCode; | |
1608 | ke.m_x = event.m_x; | |
1609 | ke.m_y = event.m_y; | |
1610 | ke.SetEventObject( parent ); | |
1611 | if (parent->GetEventHandler()->ProcessEvent( ke )) return; | |
004fd0c8 | 1612 | |
012a03e0 RR |
1613 | if (event.KeyCode() == WXK_TAB) |
1614 | { | |
1615 | wxNavigationKeyEvent nevent; | |
1616 | nevent.SetDirection( !event.ShiftDown() ); | |
1617 | nevent.SetCurrentFocus( m_parent ); | |
1618 | if (m_parent->GetEventHandler()->ProcessEvent( nevent )) return; | |
1619 | } | |
004fd0c8 | 1620 | |
51cc4dad RR |
1621 | /* no item -> nothing to do */ |
1622 | if (!m_current) | |
c801d85f | 1623 | { |
51cc4dad RR |
1624 | event.Skip(); |
1625 | return; | |
e1e955e1 | 1626 | } |
51cc4dad RR |
1627 | |
1628 | switch (event.KeyCode()) | |
c801d85f | 1629 | { |
51cc4dad RR |
1630 | case WXK_UP: |
1631 | { | |
1632 | wxNode *node = m_lines.Member( m_current )->Previous(); | |
1633 | if (node) OnArrowChar( (wxListLineData*)node->Data(), event.ShiftDown() ); | |
1634 | break; | |
1635 | } | |
1636 | case WXK_DOWN: | |
1637 | { | |
1638 | wxNode *node = m_lines.Member( m_current )->Next(); | |
1639 | if (node) OnArrowChar( (wxListLineData*)node->Data(), event.ShiftDown() ); | |
1640 | break; | |
1641 | } | |
1642 | case WXK_END: | |
1643 | { | |
1644 | wxNode *node = m_lines.Last(); | |
1645 | OnArrowChar( (wxListLineData*)node->Data(), event.ShiftDown() ); | |
1646 | break; | |
1647 | } | |
1648 | case WXK_HOME: | |
1649 | { | |
1650 | wxNode *node = m_lines.First(); | |
1651 | OnArrowChar( (wxListLineData*)node->Data(), event.ShiftDown() ); | |
1652 | break; | |
1653 | } | |
1654 | case WXK_PRIOR: | |
1655 | { | |
1656 | int steps = 0; | |
004fd0c8 | 1657 | if (m_mode & wxLC_REPORT) |
bffa1c77 VZ |
1658 | { |
1659 | steps = m_visibleLines-1; | |
1660 | } | |
51cc4dad RR |
1661 | else |
1662 | { | |
1663 | int pos = 0; | |
1664 | wxNode *node = m_lines.First(); | |
1665 | for (;;) { if (m_current == (wxListLineData*)node->Data()) break; pos++; node = node->Next(); } | |
1666 | steps = pos % m_visibleLines; | |
1667 | } | |
1668 | wxNode *node = m_lines.Member( m_current ); | |
1669 | for (int i = 0; i < steps; i++) if (node->Previous()) node = node->Previous(); | |
1670 | if (node) OnArrowChar( (wxListLineData*)node->Data(), event.ShiftDown() ); | |
1671 | break; | |
1672 | } | |
1673 | case WXK_NEXT: | |
1674 | { | |
1675 | int steps = 0; | |
004fd0c8 | 1676 | if (m_mode & wxLC_REPORT) |
bffa1c77 VZ |
1677 | { |
1678 | steps = m_visibleLines-1; | |
1679 | } | |
51cc4dad RR |
1680 | else |
1681 | { | |
1682 | int pos = 0; wxNode *node = m_lines.First(); | |
1683 | for (;;) { if (m_current == (wxListLineData*)node->Data()) break; pos++; node = node->Next(); } | |
1684 | steps = m_visibleLines-(pos % m_visibleLines)-1; | |
1685 | } | |
1686 | wxNode *node = m_lines.Member( m_current ); | |
1687 | for (int i = 0; i < steps; i++) if (node->Next()) node = node->Next(); | |
1688 | if (node) OnArrowChar( (wxListLineData*)node->Data(), event.ShiftDown() ); | |
1689 | break; | |
1690 | } | |
1691 | case WXK_LEFT: | |
1692 | { | |
1693 | if (!(m_mode & wxLC_REPORT)) | |
1694 | { | |
1695 | wxNode *node = m_lines.Member( m_current ); | |
1696 | for (int i = 0; i <m_visibleLines; i++) if (node->Previous()) node = node->Previous(); | |
1697 | if (node) OnArrowChar( (wxListLineData*)node->Data(), event.ShiftDown() ); | |
1698 | } | |
1699 | break; | |
1700 | } | |
1701 | case WXK_RIGHT: | |
1702 | { | |
1703 | if (!(m_mode & wxLC_REPORT)) | |
1704 | { | |
1705 | wxNode *node = m_lines.Member( m_current ); | |
1706 | for (int i = 0; i <m_visibleLines; i++) if (node->Next()) node = node->Next(); | |
1707 | if (node) OnArrowChar( (wxListLineData*)node->Data(), event.ShiftDown() ); | |
1708 | } | |
1709 | break; | |
1710 | } | |
1711 | case WXK_SPACE: | |
1712 | { | |
1713 | m_current->ReverseHilight(); | |
1714 | RefreshLine( m_current ); | |
1715 | break; | |
1716 | } | |
1717 | case WXK_INSERT: | |
1718 | { | |
1719 | if (!(m_mode & wxLC_SINGLE_SEL)) | |
1720 | { | |
1721 | wxListLineData *oldCurrent = m_current; | |
1722 | m_current->ReverseHilight(); | |
1723 | wxNode *node = m_lines.Member( m_current )->Next(); | |
1724 | if (node) m_current = (wxListLineData*)node->Data(); | |
1725 | MoveToFocus(); | |
1726 | RefreshLine( oldCurrent ); | |
1727 | RefreshLine( m_current ); | |
1728 | UnfocusLine( oldCurrent ); | |
1729 | FocusLine( m_current ); | |
1730 | } | |
1731 | break; | |
1732 | } | |
1733 | case WXK_RETURN: | |
1734 | case WXK_EXECUTE: | |
1735 | { | |
1736 | wxListEvent le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED, GetParent()->GetId() ); | |
1737 | le.SetEventObject( GetParent() ); | |
1738 | le.m_itemIndex = GetIndexOfLine( m_current ); | |
1739 | m_current->GetItem( 0, le.m_item ); | |
1740 | GetParent()->GetEventHandler()->ProcessEvent( le ); | |
1741 | break; | |
1742 | } | |
1743 | default: | |
1744 | { | |
1745 | event.Skip(); | |
1746 | return; | |
1747 | } | |
e1e955e1 | 1748 | } |
51cc4dad | 1749 | m_usedKeys = TRUE; |
e1e955e1 | 1750 | } |
c801d85f | 1751 | |
cae5359f RR |
1752 | #ifdef __WXGTK__ |
1753 | extern wxWindow *g_focusWindow; | |
1754 | #endif | |
1755 | ||
c801d85f KB |
1756 | void wxListMainWindow::OnSetFocus( wxFocusEvent &WXUNUSED(event) ) |
1757 | { | |
63852e78 RR |
1758 | m_hasFocus = TRUE; |
1759 | RefreshLine( m_current ); | |
bd8289c1 | 1760 | |
63852e78 | 1761 | if (!GetParent()) return; |
004fd0c8 | 1762 | |
cae5359f RR |
1763 | #ifdef __WXGTK__ |
1764 | g_focusWindow = GetParent(); | |
1765 | #endif | |
bd8289c1 | 1766 | |
63852e78 RR |
1767 | wxFocusEvent event( wxEVT_SET_FOCUS, GetParent()->GetId() ); |
1768 | event.SetEventObject( GetParent() ); | |
1769 | GetParent()->GetEventHandler()->ProcessEvent( event ); | |
e1e955e1 | 1770 | } |
c801d85f KB |
1771 | |
1772 | void wxListMainWindow::OnKillFocus( wxFocusEvent &WXUNUSED(event) ) | |
1773 | { | |
63852e78 RR |
1774 | m_hasFocus = FALSE; |
1775 | RefreshLine( m_current ); | |
e1e955e1 | 1776 | } |
c801d85f KB |
1777 | |
1778 | void wxListMainWindow::OnSize( wxSizeEvent &WXUNUSED(event) ) | |
1779 | { | |
1780 | /* | |
1781 | We don't even allow the wxScrolledWindow::AdjustScrollbars() call | |
004fd0c8 | 1782 | |
c801d85f | 1783 | */ |
e1e955e1 | 1784 | } |
c801d85f | 1785 | |
1e6d9499 | 1786 | void wxListMainWindow::DrawImage( int index, wxDC *dc, int x, int y ) |
c801d85f | 1787 | { |
63852e78 RR |
1788 | if ((m_mode & wxLC_ICON) && (m_normal_image_list)) |
1789 | { | |
1790 | m_normal_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT ); | |
1791 | return; | |
1792 | } | |
1793 | if ((m_mode & wxLC_SMALL_ICON) && (m_small_image_list)) | |
1794 | { | |
1795 | m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT ); | |
1796 | } | |
0b855868 RR |
1797 | if ((m_mode & wxLC_LIST) && (m_small_image_list)) |
1798 | { | |
1799 | m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT ); | |
1800 | } | |
63852e78 RR |
1801 | if ((m_mode & wxLC_REPORT) && (m_small_image_list)) |
1802 | { | |
1803 | m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT ); | |
1804 | return; | |
1805 | } | |
e1e955e1 | 1806 | } |
c801d85f KB |
1807 | |
1808 | void wxListMainWindow::GetImageSize( int index, int &width, int &height ) | |
1809 | { | |
63852e78 RR |
1810 | if ((m_mode & wxLC_ICON) && (m_normal_image_list)) |
1811 | { | |
1812 | m_normal_image_list->GetSize( index, width, height ); | |
1813 | return; | |
1814 | } | |
1815 | if ((m_mode & wxLC_SMALL_ICON) && (m_small_image_list)) | |
1816 | { | |
1817 | m_small_image_list->GetSize( index, width, height ); | |
1818 | return; | |
1819 | } | |
0b855868 RR |
1820 | if ((m_mode & wxLC_LIST) && (m_small_image_list)) |
1821 | { | |
1822 | m_small_image_list->GetSize( index, width, height ); | |
1823 | return; | |
1824 | } | |
63852e78 RR |
1825 | if ((m_mode & wxLC_REPORT) && (m_small_image_list)) |
1826 | { | |
1827 | m_small_image_list->GetSize( index, width, height ); | |
1828 | return; | |
1829 | } | |
1830 | width = 0; | |
1831 | height = 0; | |
e1e955e1 | 1832 | } |
c801d85f KB |
1833 | |
1834 | int wxListMainWindow::GetTextLength( wxString &s ) | |
1835 | { | |
1e6d9499 | 1836 | wxClientDC dc( this ); |
13111b2a VZ |
1837 | wxCoord lw = 0; |
1838 | wxCoord lh = 0; | |
139adb6a RR |
1839 | dc.GetTextExtent( s, &lw, &lh ); |
1840 | return lw + 6; | |
e1e955e1 | 1841 | } |
c801d85f KB |
1842 | |
1843 | int wxListMainWindow::GetIndexOfLine( const wxListLineData *line ) | |
1844 | { | |
139adb6a RR |
1845 | int i = 0; |
1846 | wxNode *node = m_lines.First(); | |
1847 | while (node) | |
1848 | { | |
1849 | if (line == (wxListLineData*)node->Data()) return i; | |
1850 | i++; | |
1851 | node = node->Next(); | |
1852 | } | |
1853 | return -1; | |
e1e955e1 | 1854 | } |
c801d85f | 1855 | |
debe6624 | 1856 | void wxListMainWindow::SetImageList( wxImageList *imageList, int which ) |
c801d85f | 1857 | { |
139adb6a RR |
1858 | m_dirty = TRUE; |
1859 | if (which == wxIMAGE_LIST_NORMAL) m_normal_image_list = imageList; | |
1860 | if (which == wxIMAGE_LIST_SMALL) m_small_image_list = imageList; | |
e1e955e1 | 1861 | } |
c801d85f | 1862 | |
debe6624 | 1863 | void wxListMainWindow::SetItemSpacing( int spacing, bool isSmall ) |
c801d85f | 1864 | { |
139adb6a RR |
1865 | m_dirty = TRUE; |
1866 | if (isSmall) | |
1867 | { | |
1868 | m_small_spacing = spacing; | |
1869 | } | |
1870 | else | |
1871 | { | |
1872 | m_normal_spacing = spacing; | |
1873 | } | |
e1e955e1 | 1874 | } |
c801d85f | 1875 | |
debe6624 | 1876 | int wxListMainWindow::GetItemSpacing( bool isSmall ) |
c801d85f | 1877 | { |
139adb6a | 1878 | if (isSmall) return m_small_spacing; else return m_normal_spacing; |
e1e955e1 | 1879 | } |
c801d85f | 1880 | |
debe6624 | 1881 | void wxListMainWindow::SetColumn( int col, wxListItem &item ) |
c801d85f | 1882 | { |
63852e78 RR |
1883 | m_dirty = TRUE; |
1884 | wxNode *node = m_columns.Nth( col ); | |
1885 | if (node) | |
1886 | { | |
1887 | if (item.m_width == wxLIST_AUTOSIZE_USEHEADER) item.m_width = GetTextLength( item.m_text )+7; | |
1888 | wxListHeaderData *column = (wxListHeaderData*)node->Data(); | |
1889 | column->SetItem( item ); | |
1890 | } | |
1891 | wxListCtrl *lc = (wxListCtrl*) GetParent(); | |
1892 | if (lc->m_headerWin) lc->m_headerWin->Refresh(); | |
e1e955e1 | 1893 | } |
c801d85f | 1894 | |
debe6624 | 1895 | void wxListMainWindow::SetColumnWidth( int col, int width ) |
c801d85f | 1896 | { |
63852e78 | 1897 | if (!(m_mode & wxLC_REPORT)) return; |
0208334d | 1898 | |
63852e78 | 1899 | m_dirty = TRUE; |
bd8289c1 | 1900 | |
0180dad6 RR |
1901 | wxNode *node = (wxNode*) NULL; |
1902 | ||
1903 | if (width == wxLIST_AUTOSIZE_USEHEADER) width = 80; | |
1904 | if (width == wxLIST_AUTOSIZE) | |
1905 | { | |
1906 | wxClientDC dc(this); | |
1907 | dc.SetFont( GetFont() ); | |
1908 | int max = 10; | |
1909 | node = m_lines.First(); | |
1910 | while (node) | |
1911 | { | |
1912 | wxListLineData *line = (wxListLineData*)node->Data(); | |
1913 | wxNode *n = line->m_items.Nth( col ); | |
1914 | if (n) | |
1915 | { | |
1916 | wxListItemData *item = (wxListItemData*)n->Data(); | |
bffa1c77 | 1917 | int current = 0, ix = 0, iy = 0; |
13111b2a | 1918 | wxCoord lx = 0, ly = 0; |
bffa1c77 VZ |
1919 | if (item->HasImage()) |
1920 | { | |
0180dad6 | 1921 | GetImageSize( item->GetImage(), ix, iy ); |
bffa1c77 VZ |
1922 | current = ix + 5; |
1923 | } | |
1924 | if (item->HasText()) | |
1925 | { | |
1926 | wxString str; | |
1927 | item->GetText( str ); | |
1928 | dc.GetTextExtent( str, &lx, &ly ); | |
1929 | current += lx; | |
1930 | } | |
1931 | if (current > max) max = current; | |
0180dad6 RR |
1932 | } |
1933 | node = node->Next(); | |
1934 | } | |
bffa1c77 | 1935 | width = max+10; |
0180dad6 RR |
1936 | } |
1937 | ||
1938 | node = m_columns.Nth( col ); | |
63852e78 RR |
1939 | if (node) |
1940 | { | |
1941 | wxListHeaderData *column = (wxListHeaderData*)node->Data(); | |
1942 | column->SetWidth( width ); | |
1943 | } | |
bd8289c1 | 1944 | |
63852e78 RR |
1945 | node = m_lines.First(); |
1946 | while (node) | |
0208334d | 1947 | { |
63852e78 RR |
1948 | wxListLineData *line = (wxListLineData*)node->Data(); |
1949 | wxNode *n = line->m_items.Nth( col ); | |
1950 | if (n) | |
1951 | { | |
1952 | wxListItemData *item = (wxListItemData*)n->Data(); | |
1953 | item->SetSize( width, -1 ); | |
1954 | } | |
1955 | node = node->Next(); | |
0208334d | 1956 | } |
bd8289c1 | 1957 | |
63852e78 RR |
1958 | wxListCtrl *lc = (wxListCtrl*) GetParent(); |
1959 | if (lc->m_headerWin) lc->m_headerWin->Refresh(); | |
e1e955e1 | 1960 | } |
c801d85f | 1961 | |
debe6624 | 1962 | void wxListMainWindow::GetColumn( int col, wxListItem &item ) |
c801d85f | 1963 | { |
63852e78 RR |
1964 | wxNode *node = m_columns.Nth( col ); |
1965 | if (node) | |
1966 | { | |
1967 | wxListHeaderData *column = (wxListHeaderData*)node->Data(); | |
1968 | column->GetItem( item ); | |
1969 | } | |
1970 | else | |
1971 | { | |
1972 | item.m_format = 0; | |
1973 | item.m_width = 0; | |
1974 | item.m_text = ""; | |
1975 | item.m_image = 0; | |
1976 | item.m_data = 0; | |
1977 | } | |
e1e955e1 | 1978 | } |
c801d85f | 1979 | |
bd8289c1 | 1980 | int wxListMainWindow::GetColumnWidth( int col ) |
c801d85f | 1981 | { |
92976ab6 RR |
1982 | wxNode *node = m_columns.Nth( col ); |
1983 | if (node) | |
1984 | { | |
1985 | wxListHeaderData *column = (wxListHeaderData*)node->Data(); | |
1986 | return column->GetWidth(); | |
1987 | } | |
1988 | else | |
1989 | { | |
004fd0c8 | 1990 | return 0; |
92976ab6 | 1991 | } |
e1e955e1 | 1992 | } |
c801d85f | 1993 | |
e179bd65 | 1994 | int wxListMainWindow::GetColumnCount() |
c801d85f | 1995 | { |
92976ab6 | 1996 | return m_columns.Number(); |
e1e955e1 | 1997 | } |
c801d85f | 1998 | |
e179bd65 | 1999 | int wxListMainWindow::GetCountPerPage() |
c801d85f | 2000 | { |
92976ab6 | 2001 | return m_visibleLines; |
e1e955e1 | 2002 | } |
c801d85f KB |
2003 | |
2004 | void wxListMainWindow::SetItem( wxListItem &item ) | |
2005 | { | |
92976ab6 | 2006 | m_dirty = TRUE; |
6f2a55e3 | 2007 | wxNode *node = m_lines.Nth( (size_t)item.m_itemId ); |
92976ab6 RR |
2008 | if (node) |
2009 | { | |
2010 | wxListLineData *line = (wxListLineData*)node->Data(); | |
2011 | if (m_mode & wxLC_REPORT) item.m_width = GetColumnWidth( item.m_col )-3; | |
2012 | line->SetItem( item.m_col, item ); | |
2013 | } | |
e1e955e1 | 2014 | } |
c801d85f | 2015 | |
debe6624 | 2016 | void wxListMainWindow::SetItemState( long item, long state, long stateMask ) |
c801d85f | 2017 | { |
92976ab6 | 2018 | // m_dirty = TRUE; no recalcs needed |
bd8289c1 | 2019 | |
92976ab6 | 2020 | wxListLineData *oldCurrent = m_current; |
bd8289c1 | 2021 | |
92976ab6 | 2022 | if (stateMask & wxLIST_STATE_FOCUSED) |
c801d85f | 2023 | { |
6f2a55e3 | 2024 | wxNode *node = m_lines.Nth( (size_t)item ); |
92976ab6 RR |
2025 | if (node) |
2026 | { | |
2027 | wxListLineData *line = (wxListLineData*)node->Data(); | |
2028 | UnfocusLine( m_current ); | |
2029 | m_current = line; | |
2030 | FocusLine( m_current ); | |
2031 | RefreshLine( m_current ); | |
00a39542 | 2032 | if (oldCurrent) RefreshLine( oldCurrent ); |
92976ab6 | 2033 | } |
e1e955e1 | 2034 | } |
bd8289c1 | 2035 | |
92976ab6 | 2036 | if (stateMask & wxLIST_STATE_SELECTED) |
c801d85f | 2037 | { |
6f2a55e3 | 2038 | bool on = (state & wxLIST_STATE_SELECTED) != 0; |
92976ab6 RR |
2039 | if (!on && (m_mode & wxLC_SINGLE_SEL)) return; |
2040 | ||
6f2a55e3 | 2041 | wxNode *node = m_lines.Nth( (size_t)item ); |
92976ab6 RR |
2042 | if (node) |
2043 | { | |
2044 | wxListLineData *line = (wxListLineData*)node->Data(); | |
2045 | if (m_mode & wxLC_SINGLE_SEL) | |
2046 | { | |
2047 | UnfocusLine( m_current ); | |
2048 | m_current = line; | |
2049 | FocusLine( m_current ); | |
00a39542 | 2050 | if (oldCurrent) oldCurrent->Hilight( FALSE ); |
92976ab6 | 2051 | RefreshLine( m_current ); |
00a39542 | 2052 | if (oldCurrent) RefreshLine( oldCurrent ); |
92976ab6 | 2053 | } |
6f2a55e3 | 2054 | bool on = (state & wxLIST_STATE_SELECTED) != 0; |
bffa1c77 VZ |
2055 | if (on != line->IsHilighted()) |
2056 | { | |
139adb6a RR |
2057 | line->Hilight( on ); |
2058 | RefreshLine( line ); | |
bffa1c77 | 2059 | } |
92976ab6 | 2060 | } |
e1e955e1 | 2061 | } |
e1e955e1 | 2062 | } |
c801d85f | 2063 | |
debe6624 | 2064 | int wxListMainWindow::GetItemState( long item, long stateMask ) |
c801d85f | 2065 | { |
92976ab6 RR |
2066 | int ret = wxLIST_STATE_DONTCARE; |
2067 | if (stateMask & wxLIST_STATE_FOCUSED) | |
c801d85f | 2068 | { |
6f2a55e3 | 2069 | wxNode *node = m_lines.Nth( (size_t)item ); |
92976ab6 RR |
2070 | if (node) |
2071 | { | |
2072 | wxListLineData *line = (wxListLineData*)node->Data(); | |
2073 | if (line == m_current) ret |= wxLIST_STATE_FOCUSED; | |
2074 | } | |
e1e955e1 | 2075 | } |
92976ab6 | 2076 | if (stateMask & wxLIST_STATE_SELECTED) |
c801d85f | 2077 | { |
6f2a55e3 | 2078 | wxNode *node = m_lines.Nth( (size_t)item ); |
92976ab6 RR |
2079 | if (node) |
2080 | { | |
2081 | wxListLineData *line = (wxListLineData*)node->Data(); | |
2082 | if (line->IsHilighted()) ret |= wxLIST_STATE_FOCUSED; | |
2083 | } | |
e1e955e1 | 2084 | } |
92976ab6 | 2085 | return ret; |
e1e955e1 | 2086 | } |
c801d85f KB |
2087 | |
2088 | void wxListMainWindow::GetItem( wxListItem &item ) | |
2089 | { | |
6f2a55e3 | 2090 | wxNode *node = m_lines.Nth( (size_t)item.m_itemId ); |
92976ab6 RR |
2091 | if (node) |
2092 | { | |
2093 | wxListLineData *line = (wxListLineData*)node->Data(); | |
2094 | line->GetItem( item.m_col, item ); | |
2095 | } | |
2096 | else | |
2097 | { | |
2098 | item.m_mask = 0; | |
2099 | item.m_text = ""; | |
2100 | item.m_image = 0; | |
2101 | item.m_data = 0; | |
2102 | } | |
e1e955e1 | 2103 | } |
c801d85f | 2104 | |
e179bd65 | 2105 | int wxListMainWindow::GetItemCount() |
c801d85f | 2106 | { |
92976ab6 | 2107 | return m_lines.Number(); |
e1e955e1 | 2108 | } |
c801d85f | 2109 | |
0a240683 | 2110 | void wxListMainWindow::GetItemRect( long index, wxRect &rect ) |
c801d85f | 2111 | { |
6f2a55e3 | 2112 | wxNode *node = m_lines.Nth( (size_t)index ); |
92976ab6 RR |
2113 | if (node) |
2114 | { | |
2115 | wxListLineData *line = (wxListLineData*)node->Data(); | |
2116 | line->GetRect( rect ); | |
2117 | } | |
2118 | else | |
2119 | { | |
2120 | rect.x = 0; | |
2121 | rect.y = 0; | |
2122 | rect.width = 0; | |
2123 | rect.height = 0; | |
2124 | } | |
e1e955e1 | 2125 | } |
c801d85f | 2126 | |
e3e65dac RR |
2127 | bool wxListMainWindow::GetItemPosition(long item, wxPoint& pos) |
2128 | { | |
6f2a55e3 | 2129 | wxNode *node = m_lines.Nth( (size_t)item ); |
92976ab6 RR |
2130 | if (node) |
2131 | { | |
0a240683 | 2132 | wxRect rect; |
92976ab6 RR |
2133 | wxListLineData *line = (wxListLineData*)node->Data(); |
2134 | line->GetRect( rect ); | |
2135 | pos.x = rect.x; | |
2136 | pos.y = rect.y; | |
2137 | } | |
2138 | else | |
2139 | { | |
2140 | pos.x = 0; | |
2141 | pos.y = 0; | |
2142 | } | |
2143 | return TRUE; | |
e1e955e1 | 2144 | } |
e3e65dac | 2145 | |
e179bd65 | 2146 | int wxListMainWindow::GetSelectedItemCount() |
c801d85f | 2147 | { |
92976ab6 RR |
2148 | int ret = 0; |
2149 | wxNode *node = m_lines.First(); | |
2150 | while (node) | |
2151 | { | |
2152 | wxListLineData *line = (wxListLineData*)node->Data(); | |
2153 | if (line->IsHilighted()) ret++; | |
2154 | node = node->Next(); | |
2155 | } | |
2156 | return ret; | |
e1e955e1 | 2157 | } |
c801d85f | 2158 | |
debe6624 | 2159 | void wxListMainWindow::SetMode( long mode ) |
c801d85f | 2160 | { |
92976ab6 RR |
2161 | m_dirty = TRUE; |
2162 | m_mode = mode; | |
bd8289c1 | 2163 | |
92976ab6 | 2164 | DeleteEverything(); |
bd8289c1 | 2165 | |
92976ab6 RR |
2166 | if (m_mode & wxLC_REPORT) |
2167 | { | |
7c74e7fe SC |
2168 | #if wxUSE_GENERIC_LIST_EXTENSIONS |
2169 | m_xScroll = 15; | |
2170 | #else | |
92976ab6 | 2171 | m_xScroll = 0; |
7c74e7fe | 2172 | #endif |
92976ab6 RR |
2173 | m_yScroll = 15; |
2174 | } | |
2175 | else | |
2176 | { | |
2177 | m_xScroll = 15; | |
2178 | m_yScroll = 0; | |
2179 | } | |
e1e955e1 | 2180 | } |
c801d85f | 2181 | |
e179bd65 | 2182 | long wxListMainWindow::GetMode() const |
c801d85f | 2183 | { |
63852e78 | 2184 | return m_mode; |
e1e955e1 | 2185 | } |
c801d85f | 2186 | |
e179bd65 | 2187 | void wxListMainWindow::CalculatePositions() |
c801d85f | 2188 | { |
92976ab6 | 2189 | if (!m_lines.First()) return; |
e487524e | 2190 | |
1e6d9499 | 2191 | wxClientDC dc( this ); |
92976ab6 | 2192 | dc.SetFont( GetFont() ); |
c801d85f | 2193 | |
92976ab6 RR |
2194 | int iconSpacing = 0; |
2195 | if (m_mode & wxLC_ICON) iconSpacing = m_normal_spacing; | |
2196 | if (m_mode & wxLC_SMALL_ICON) iconSpacing = m_small_spacing; | |
004fd0c8 | 2197 | |
92976ab6 RR |
2198 | // we take the first line (which also can be an icon or |
2199 | // an a text item in wxLC_ICON and wxLC_LIST modes) to | |
2200 | // measure the size of the line | |
004fd0c8 | 2201 | |
92976ab6 RR |
2202 | int lineWidth = 0; |
2203 | int lineHeight = 0; | |
2204 | int lineSpacing = 0; | |
c801d85f | 2205 | |
92976ab6 RR |
2206 | wxListLineData *line = (wxListLineData*)m_lines.First()->Data(); |
2207 | line->CalculateSize( &dc, iconSpacing ); | |
2208 | int dummy = 0; | |
2209 | line->GetSize( dummy, lineSpacing ); | |
2210 | lineSpacing += 4; | |
bd8289c1 | 2211 | |
92976ab6 RR |
2212 | int clientWidth = 0; |
2213 | int clientHeight = 0; | |
bd8289c1 | 2214 | |
92976ab6 | 2215 | if (m_mode & wxLC_REPORT) |
c801d85f | 2216 | { |
92976ab6 RR |
2217 | int x = 4; |
2218 | int y = 1; | |
2219 | int entireHeight = m_lines.Number() * lineSpacing + 2; | |
2220 | int scroll_pos = GetScrollPos( wxVERTICAL ); | |
7c74e7fe | 2221 | #if wxUSE_GENERIC_LIST_EXTENSIONS |
7c0ea335 | 2222 | int x_scroll_pos = GetScrollPos( wxHORIZONTAL ); |
7c74e7fe | 2223 | #else |
8b53e5a2 | 2224 | SetScrollbars( m_xScroll, m_yScroll, 0, (entireHeight+15) / m_yScroll, 0, scroll_pos, TRUE ); |
7c74e7fe | 2225 | #endif |
92976ab6 RR |
2226 | GetClientSize( &clientWidth, &clientHeight ); |
2227 | ||
2228 | wxNode* node = m_lines.First(); | |
7c74e7fe | 2229 | int entireWidth = 0 ; |
92976ab6 RR |
2230 | while (node) |
2231 | { | |
2232 | wxListLineData *line = (wxListLineData*)node->Data(); | |
2233 | line->CalculateSize( &dc, iconSpacing ); | |
2234 | line->SetPosition( &dc, x, y, clientWidth ); | |
2235 | int col_x = 2; | |
2236 | for (int i = 0; i < GetColumnCount(); i++) | |
2237 | { | |
2238 | line->SetColumnPosition( i, col_x ); | |
2239 | col_x += GetColumnWidth( i ); | |
2240 | } | |
7c74e7fe SC |
2241 | entireWidth = wxMax( entireWidth , col_x ) ; |
2242 | #if wxUSE_GENERIC_LIST_EXTENSIONS | |
2243 | line->SetPosition( &dc, x, y, col_x ); | |
2244 | #endif | |
92976ab6 RR |
2245 | y += lineSpacing; // one pixel blank line between items |
2246 | node = node->Next(); | |
2247 | } | |
bffa1c77 | 2248 | m_visibleLines = clientHeight / lineSpacing; |
7c74e7fe | 2249 | #if wxUSE_GENERIC_LIST_EXTENSIONS |
bffa1c77 | 2250 | SetScrollbars( m_xScroll, m_yScroll, entireWidth / m_xScroll , (entireHeight+15) / m_yScroll, x_scroll_pos , scroll_pos, TRUE ); |
7c74e7fe | 2251 | #endif |
e1e955e1 | 2252 | } |
92976ab6 RR |
2253 | else |
2254 | { | |
2255 | // at first we try without any scrollbar. if the items don't | |
2256 | // fit into the window, we recalculate after subtracting an | |
2257 | // approximated 15 pt for the horizontal scrollbar | |
004fd0c8 | 2258 | |
92976ab6 | 2259 | GetSize( &clientWidth, &clientHeight ); |
bffa1c77 | 2260 | clientHeight -= 4; // sunken frame |
bd8289c1 | 2261 | |
92976ab6 | 2262 | int entireWidth = 0; |
bd8289c1 | 2263 | |
92976ab6 | 2264 | for (int tries = 0; tries < 2; tries++) |
e487524e | 2265 | { |
92976ab6 RR |
2266 | entireWidth = 0; |
2267 | int x = 5; // painting is done at x-2 | |
2268 | int y = 5; // painting is done at y-2 | |
2269 | int maxWidth = 0; | |
0b855868 | 2270 | m_visibleLines = 0; |
bffa1c77 | 2271 | int m_currentVisibleLines = 0; |
92976ab6 RR |
2272 | wxNode *node = m_lines.First(); |
2273 | while (node) | |
2274 | { | |
bffa1c77 | 2275 | m_currentVisibleLines++; |
92976ab6 RR |
2276 | wxListLineData *line = (wxListLineData*)node->Data(); |
2277 | line->CalculateSize( &dc, iconSpacing ); | |
2278 | line->SetPosition( &dc, x, y, clientWidth ); | |
2279 | line->GetSize( lineWidth, lineHeight ); | |
2280 | if (lineWidth > maxWidth) maxWidth = lineWidth; | |
2281 | y += lineSpacing; | |
bffa1c77 VZ |
2282 | if (m_currentVisibleLines > m_visibleLines) |
2283 | m_visibleLines = m_currentVisibleLines; | |
8b53e5a2 | 2284 | if (y+lineSpacing-6 >= clientHeight) // -6 for earlier "line breaking" |
92976ab6 | 2285 | { |
bffa1c77 | 2286 | m_currentVisibleLines = 0; |
92976ab6 | 2287 | y = 5; |
8b53e5a2 RR |
2288 | x += maxWidth+6; |
2289 | entireWidth += maxWidth+6; | |
92976ab6 RR |
2290 | maxWidth = 0; |
2291 | } | |
2292 | node = node->Next(); | |
2293 | if (!node) entireWidth += maxWidth; | |
2294 | if ((tries == 0) && (entireWidth > clientWidth)) | |
2295 | { | |
2296 | clientHeight -= 15; // scrollbar height | |
0b855868 | 2297 | m_visibleLines = 0; |
bffa1c77 | 2298 | m_currentVisibleLines = 0; |
92976ab6 RR |
2299 | break; |
2300 | } | |
2301 | if (!node) tries = 1; // everything fits, no second try required | |
2302 | } | |
e487524e | 2303 | } |
bffa1c77 | 2304 | |
92976ab6 RR |
2305 | int scroll_pos = GetScrollPos( wxHORIZONTAL ); |
2306 | SetScrollbars( m_xScroll, m_yScroll, (entireWidth+15) / m_xScroll, 0, scroll_pos, 0, TRUE ); | |
e1e955e1 | 2307 | } |
e1e955e1 | 2308 | } |
c801d85f KB |
2309 | |
2310 | void wxListMainWindow::RealizeChanges( void ) | |
2311 | { | |
92976ab6 RR |
2312 | if (!m_current) |
2313 | { | |
2314 | wxNode *node = m_lines.First(); | |
2315 | if (node) m_current = (wxListLineData*)node->Data(); | |
2316 | } | |
2317 | if (m_current) | |
2318 | { | |
2319 | FocusLine( m_current ); | |
2320 | if (m_mode & wxLC_SINGLE_SEL) m_current->Hilight( TRUE ); | |
2321 | } | |
e1e955e1 | 2322 | } |
c801d85f | 2323 | |
debe6624 | 2324 | long wxListMainWindow::GetNextItem( long item, int WXUNUSED(geometry), int state ) |
c801d85f | 2325 | { |
63852e78 RR |
2326 | long ret = 0; |
2327 | if (item > 0) ret = item; | |
d9081042 | 2328 | if(ret >= GetItemCount()) return -1; |
6f2a55e3 | 2329 | wxNode *node = m_lines.Nth( (size_t)ret ); |
63852e78 RR |
2330 | while (node) |
2331 | { | |
2332 | wxListLineData *line = (wxListLineData*)node->Data(); | |
2333 | if ((state & wxLIST_STATE_FOCUSED) && (line == m_current)) return ret; | |
2334 | if ((state & wxLIST_STATE_SELECTED) && (line->IsHilighted())) return ret; | |
2335 | if (!state) return ret; | |
2336 | ret++; | |
2337 | node = node->Next(); | |
2338 | } | |
2339 | return -1; | |
e1e955e1 | 2340 | } |
c801d85f | 2341 | |
debe6624 | 2342 | void wxListMainWindow::DeleteItem( long index ) |
c801d85f | 2343 | { |
63852e78 | 2344 | m_dirty = TRUE; |
6f2a55e3 | 2345 | wxNode *node = m_lines.Nth( (size_t)index ); |
63852e78 RR |
2346 | if (node) |
2347 | { | |
2348 | wxListLineData *line = (wxListLineData*)node->Data(); | |
2349 | if (m_current == line) m_current = (wxListLineData *) NULL; | |
2350 | DeleteLine( line ); | |
2351 | m_lines.DeleteNode( node ); | |
2352 | } | |
e1e955e1 | 2353 | } |
c801d85f | 2354 | |
debe6624 | 2355 | void wxListMainWindow::DeleteColumn( int col ) |
c801d85f | 2356 | { |
5b077d48 | 2357 | wxCHECK_RET( col < (int)m_columns.GetCount(), |
223d09f6 | 2358 | wxT("attempting to delete inexistent column in wxListView") ); |
bd8289c1 | 2359 | |
5b077d48 RR |
2360 | m_dirty = TRUE; |
2361 | wxNode *node = m_columns.Nth( col ); | |
2362 | if (node) m_columns.DeleteNode( node ); | |
e1e955e1 | 2363 | } |
c801d85f KB |
2364 | |
2365 | void wxListMainWindow::DeleteAllItems( void ) | |
2366 | { | |
5b077d48 RR |
2367 | m_dirty = TRUE; |
2368 | m_current = (wxListLineData *) NULL; | |
7c0ea335 VZ |
2369 | |
2370 | // to make the deletion of all items faster, we don't send the | |
2371 | // notifications in this case: this is compatible with wxMSW and | |
2372 | // documented in DeleteAllItems() description | |
2373 | #if 0 | |
5b077d48 RR |
2374 | wxNode *node = m_lines.First(); |
2375 | while (node) | |
2376 | { | |
2377 | wxListLineData *line = (wxListLineData*)node->Data(); | |
bffa1c77 | 2378 | |
7c0ea335 | 2379 | DeleteLine( line ); |
bffa1c77 | 2380 | |
5b077d48 RR |
2381 | node = node->Next(); |
2382 | } | |
7c0ea335 VZ |
2383 | #endif // 0 |
2384 | ||
5b077d48 | 2385 | m_lines.Clear(); |
e1e955e1 | 2386 | } |
c801d85f KB |
2387 | |
2388 | void wxListMainWindow::DeleteEverything( void ) | |
2389 | { | |
5b077d48 RR |
2390 | m_dirty = TRUE; |
2391 | m_current = (wxListLineData *) NULL; | |
2392 | wxNode *node = m_lines.First(); | |
2393 | while (node) | |
2394 | { | |
2395 | wxListLineData *line = (wxListLineData*)node->Data(); | |
2396 | DeleteLine( line ); | |
2397 | node = node->Next(); | |
2398 | } | |
2399 | m_lines.Clear(); | |
2400 | m_current = (wxListLineData *) NULL; | |
2401 | m_columns.Clear(); | |
e1e955e1 | 2402 | } |
c801d85f | 2403 | |
debe6624 | 2404 | void wxListMainWindow::EnsureVisible( long index ) |
c801d85f | 2405 | { |
dc6c62a9 RR |
2406 | // We have to call this here because the label in |
2407 | // question might just have been added and no screen | |
2408 | // update taken place. | |
2409 | if (m_dirty) wxYield(); | |
2410 | ||
5b077d48 RR |
2411 | wxListLineData *oldCurrent = m_current; |
2412 | m_current = (wxListLineData *) NULL; | |
6f2a55e3 | 2413 | wxNode *node = m_lines.Nth( (size_t)index ); |
5b077d48 RR |
2414 | if (node) m_current = (wxListLineData*)node->Data(); |
2415 | if (m_current) MoveToFocus(); | |
2416 | m_current = oldCurrent; | |
e1e955e1 | 2417 | } |
c801d85f | 2418 | |
debe6624 | 2419 | long wxListMainWindow::FindItem(long start, const wxString& str, bool WXUNUSED(partial) ) |
c801d85f | 2420 | { |
5b077d48 RR |
2421 | long pos = start; |
2422 | wxString tmp = str; | |
2423 | if (pos < 0) pos = 0; | |
6f2a55e3 | 2424 | wxNode *node = m_lines.Nth( (size_t)pos ); |
5b077d48 RR |
2425 | while (node) |
2426 | { | |
2427 | wxListLineData *line = (wxListLineData*)node->Data(); | |
2428 | wxString s = ""; | |
2429 | line->GetText( 0, s ); | |
2430 | if (s == tmp) return pos; | |
2431 | node = node->Next(); | |
2432 | pos++; | |
2433 | } | |
2434 | return -1; | |
e1e955e1 | 2435 | } |
c801d85f | 2436 | |
debe6624 | 2437 | long wxListMainWindow::FindItem(long start, long data) |
c801d85f | 2438 | { |
5b077d48 RR |
2439 | long pos = start; |
2440 | if (pos < 0) pos = 0; | |
6f2a55e3 | 2441 | wxNode *node = m_lines.Nth( (size_t)pos ); |
5b077d48 RR |
2442 | while (node) |
2443 | { | |
2444 | wxListLineData *line = (wxListLineData*)node->Data(); | |
2445 | wxListItem item; | |
2446 | line->GetItem( 0, item ); | |
2447 | if (item.m_data == data) return pos; | |
2448 | node = node->Next(); | |
2449 | pos++; | |
2450 | } | |
2451 | return -1; | |
e1e955e1 | 2452 | } |
c801d85f | 2453 | |
debe6624 | 2454 | long wxListMainWindow::HitTest( int x, int y, int &flags ) |
c801d85f | 2455 | { |
5b077d48 RR |
2456 | wxNode *node = m_lines.First(); |
2457 | int count = 0; | |
2458 | while (node) | |
c801d85f | 2459 | { |
5b077d48 RR |
2460 | wxListLineData *line = (wxListLineData*)node->Data(); |
2461 | long ret = line->IsHit( x, y ); | |
2462 | if (ret & flags) | |
2463 | { | |
6f2a55e3 | 2464 | flags = (int)ret; |
5b077d48 RR |
2465 | return count; |
2466 | } | |
2467 | node = node->Next(); | |
2468 | count++; | |
e1e955e1 | 2469 | } |
5b077d48 | 2470 | return -1; |
e1e955e1 | 2471 | } |
c801d85f KB |
2472 | |
2473 | void wxListMainWindow::InsertItem( wxListItem &item ) | |
2474 | { | |
5b077d48 RR |
2475 | m_dirty = TRUE; |
2476 | int mode = 0; | |
2477 | if (m_mode & wxLC_REPORT) mode = wxLC_REPORT; | |
2478 | else if (m_mode & wxLC_LIST) mode = wxLC_LIST; | |
2479 | else if (m_mode & wxLC_ICON) mode = wxLC_ICON; | |
2480 | else if (m_mode & wxLC_SMALL_ICON) mode = wxLC_ICON; // no typo | |
004fd0c8 | 2481 | |
5b077d48 | 2482 | wxListLineData *line = new wxListLineData( this, mode, m_hilightBrush ); |
004fd0c8 | 2483 | |
5b077d48 RR |
2484 | if (m_mode & wxLC_REPORT) |
2485 | { | |
2486 | line->InitItems( GetColumnCount() ); | |
2487 | item.m_width = GetColumnWidth( 0 )-3; | |
2488 | } | |
2489 | else | |
2490 | { | |
2491 | line->InitItems( 1 ); | |
2492 | } | |
004fd0c8 | 2493 | |
5b077d48 RR |
2494 | line->SetItem( 0, item ); |
2495 | if ((item.m_itemId >= 0) && (item.m_itemId < (int)m_lines.GetCount())) | |
2496 | { | |
6f2a55e3 | 2497 | wxNode *node = m_lines.Nth( (size_t)item.m_itemId ); |
5b077d48 RR |
2498 | if (node) m_lines.Insert( node, line ); |
2499 | } | |
2500 | else | |
2501 | { | |
2502 | m_lines.Append( line ); | |
2503 | } | |
e1e955e1 | 2504 | } |
c801d85f | 2505 | |
debe6624 | 2506 | void wxListMainWindow::InsertColumn( long col, wxListItem &item ) |
c801d85f | 2507 | { |
5b077d48 RR |
2508 | m_dirty = TRUE; |
2509 | if (m_mode & wxLC_REPORT) | |
3db7be80 | 2510 | { |
5b077d48 RR |
2511 | if (item.m_width == wxLIST_AUTOSIZE_USEHEADER) item.m_width = GetTextLength( item.m_text ); |
2512 | wxListHeaderData *column = new wxListHeaderData( item ); | |
2513 | if ((col >= 0) && (col < (int)m_columns.GetCount())) | |
2514 | { | |
6f2a55e3 | 2515 | wxNode *node = m_columns.Nth( (size_t)col ); |
5b077d48 RR |
2516 | if (node) |
2517 | m_columns.Insert( node, column ); | |
2518 | } | |
2519 | else | |
2520 | { | |
2521 | m_columns.Append( column ); | |
2522 | } | |
3db7be80 | 2523 | } |
e1e955e1 | 2524 | } |
c801d85f KB |
2525 | |
2526 | wxListCtrlCompare list_ctrl_compare_func_2; | |
2527 | long list_ctrl_compare_data; | |
2528 | ||
004fd0c8 | 2529 | int LINKAGEMODE list_ctrl_compare_func_1( const void *arg1, const void *arg2 ) |
c801d85f | 2530 | { |
5b077d48 RR |
2531 | wxListLineData *line1 = *((wxListLineData**)arg1); |
2532 | wxListLineData *line2 = *((wxListLineData**)arg2); | |
2533 | wxListItem item; | |
2534 | line1->GetItem( 0, item ); | |
2535 | long data1 = item.m_data; | |
2536 | line2->GetItem( 0, item ); | |
2537 | long data2 = item.m_data; | |
2538 | return list_ctrl_compare_func_2( data1, data2, list_ctrl_compare_data ); | |
e1e955e1 | 2539 | } |
c801d85f KB |
2540 | |
2541 | void wxListMainWindow::SortItems( wxListCtrlCompare fn, long data ) | |
2542 | { | |
5b077d48 RR |
2543 | list_ctrl_compare_func_2 = fn; |
2544 | list_ctrl_compare_data = data; | |
2545 | m_lines.Sort( list_ctrl_compare_func_1 ); | |
e1e955e1 | 2546 | } |
c801d85f | 2547 | |
7c74e7fe SC |
2548 | void wxListMainWindow::OnScroll(wxScrollWinEvent& event) |
2549 | { | |
bffa1c77 | 2550 | wxScrolledWindow::OnScroll( event ) ; |
7c74e7fe SC |
2551 | #if wxUSE_GENERIC_LIST_EXTENSIONS |
2552 | ||
2553 | if (event.GetOrientation() == wxHORIZONTAL && ( m_mode & wxLC_REPORT )) | |
2554 | { | |
bffa1c77 VZ |
2555 | wxListCtrl* lc = wxDynamicCast( GetParent() , wxListCtrl ) ; |
2556 | if ( lc ) | |
2557 | { | |
2558 | lc->m_headerWin->Refresh() ; | |
7c74e7fe | 2559 | #ifdef __WXMAC__ |
bffa1c77 | 2560 | lc->m_headerWin->MacUpdateImmediately() ; |
7c74e7fe | 2561 | #endif |
bffa1c77 | 2562 | } |
7c74e7fe SC |
2563 | } |
2564 | #endif | |
2565 | } | |
2566 | ||
c801d85f KB |
2567 | // ------------------------------------------------------------------------------------- |
2568 | // wxListItem | |
2569 | // ------------------------------------------------------------------------------------- | |
2570 | ||
2571 | IMPLEMENT_DYNAMIC_CLASS(wxListItem, wxObject) | |
2572 | ||
fd9811b1 | 2573 | wxListItem::wxListItem() |
c801d85f | 2574 | { |
63852e78 RR |
2575 | m_mask = 0; |
2576 | m_itemId = 0; | |
2577 | m_col = 0; | |
2578 | m_state = 0; | |
2579 | m_stateMask = 0; | |
2580 | m_image = 0; | |
2581 | m_data = 0; | |
2582 | m_format = wxLIST_FORMAT_CENTRE; | |
2583 | m_width = 0; | |
aaa37c0d VZ |
2584 | |
2585 | m_attr = NULL; | |
c801d85f KB |
2586 | } |
2587 | ||
9b00bb16 RR |
2588 | void wxListItem::Clear() |
2589 | { | |
2590 | m_mask = 0; | |
2591 | m_itemId = 0; | |
2592 | m_col = 0; | |
2593 | m_state = 0; | |
2594 | m_stateMask = 0; | |
2595 | m_image = 0; | |
2596 | m_data = 0; | |
2597 | m_format = wxLIST_FORMAT_CENTRE; | |
2598 | m_width = 0; | |
2599 | m_text = wxEmptyString; | |
2600 | ||
2601 | if (m_attr) delete m_attr; | |
2602 | m_attr = NULL; | |
2603 | } | |
2604 | ||
2605 | void wxListItem::ClearAttributes() | |
2606 | { | |
2607 | if (m_attr) delete m_attr; | |
2608 | m_attr = NULL; | |
2609 | } | |
2610 | ||
c801d85f KB |
2611 | // ------------------------------------------------------------------------------------- |
2612 | // wxListEvent | |
2613 | // ------------------------------------------------------------------------------------- | |
2614 | ||
92976ab6 | 2615 | IMPLEMENT_DYNAMIC_CLASS(wxListEvent, wxNotifyEvent) |
c801d85f | 2616 | |
8f79098a | 2617 | wxListEvent::wxListEvent( wxEventType commandType, int id ): |
92976ab6 | 2618 | wxNotifyEvent( commandType, id ) |
c801d85f | 2619 | { |
5b077d48 RR |
2620 | m_code = 0; |
2621 | m_itemIndex = 0; | |
2622 | m_oldItemIndex = 0; | |
2623 | m_col = 0; | |
2624 | m_cancelled = FALSE; | |
2625 | m_pointDrag.x = 0; | |
2626 | m_pointDrag.y = 0; | |
e1e955e1 | 2627 | } |
c801d85f | 2628 | |
72a7edf0 RR |
2629 | void wxListEvent::CopyObject(wxObject& object_dest) const |
2630 | { | |
2631 | wxListEvent *obj = (wxListEvent *)&object_dest; | |
2632 | ||
2633 | wxNotifyEvent::CopyObject(object_dest); | |
2634 | ||
2635 | obj->m_code = m_code; | |
2636 | obj->m_itemIndex = m_itemIndex; | |
2637 | obj->m_oldItemIndex = m_oldItemIndex; | |
2638 | obj->m_col = m_col; | |
2639 | obj->m_cancelled = m_cancelled; | |
2640 | obj->m_pointDrag = m_pointDrag; | |
2641 | obj->m_item.m_mask = m_item.m_mask; | |
2642 | obj->m_item.m_itemId = m_item.m_itemId; | |
2643 | obj->m_item.m_col = m_item.m_col; | |
2644 | obj->m_item.m_state = m_item.m_state; | |
2645 | obj->m_item.m_stateMask = m_item.m_stateMask; | |
2646 | obj->m_item.m_text = m_item.m_text; | |
2647 | obj->m_item.m_image = m_item.m_image; | |
2648 | obj->m_item.m_data = m_item.m_data; | |
2649 | obj->m_item.m_format = m_item.m_format; | |
2650 | obj->m_item.m_width = m_item.m_width; | |
aaa37c0d VZ |
2651 | |
2652 | if ( m_item.HasAttributes() ) | |
2653 | { | |
2654 | obj->m_item.SetTextColour(m_item.GetTextColour()); | |
2655 | } | |
72a7edf0 RR |
2656 | } |
2657 | ||
c801d85f KB |
2658 | // ------------------------------------------------------------------------------------- |
2659 | // wxListCtrl | |
2660 | // ------------------------------------------------------------------------------------- | |
2661 | ||
2662 | IMPLEMENT_DYNAMIC_CLASS(wxListCtrl, wxControl) | |
2663 | ||
2664 | BEGIN_EVENT_TABLE(wxListCtrl,wxControl) | |
2665 | EVT_SIZE (wxListCtrl::OnSize) | |
53010e52 | 2666 | EVT_IDLE (wxListCtrl::OnIdle) |
c801d85f KB |
2667 | END_EVENT_TABLE() |
2668 | ||
fd9811b1 | 2669 | wxListCtrl::wxListCtrl() |
c801d85f | 2670 | { |
5b077d48 RR |
2671 | m_imageListNormal = (wxImageList *) NULL; |
2672 | m_imageListSmall = (wxImageList *) NULL; | |
2673 | m_imageListState = (wxImageList *) NULL; | |
2674 | m_mainWin = (wxListMainWindow*) NULL; | |
2675 | m_headerWin = (wxListHeaderWindow*) NULL; | |
c801d85f KB |
2676 | } |
2677 | ||
fd9811b1 | 2678 | wxListCtrl::~wxListCtrl() |
c801d85f KB |
2679 | { |
2680 | } | |
2681 | ||
25e3a937 VZ |
2682 | bool wxListCtrl::Create(wxWindow *parent, |
2683 | wxWindowID id, | |
2684 | const wxPoint &pos, | |
2685 | const wxSize &size, | |
2686 | long style, | |
25e3a937 | 2687 | const wxValidator &validator, |
25e3a937 | 2688 | const wxString &name) |
c801d85f | 2689 | { |
5b077d48 RR |
2690 | m_imageListNormal = (wxImageList *) NULL; |
2691 | m_imageListSmall = (wxImageList *) NULL; | |
2692 | m_imageListState = (wxImageList *) NULL; | |
2693 | m_mainWin = (wxListMainWindow*) NULL; | |
2694 | m_headerWin = (wxListHeaderWindow*) NULL; | |
bd8289c1 | 2695 | |
25e3a937 | 2696 | if ( !(style & (wxLC_REPORT | wxLC_LIST | wxLC_ICON)) ) |
5b077d48 | 2697 | { |
25e3a937 | 2698 | style = style | wxLC_LIST; |
5b077d48 | 2699 | } |
098963c3 BJ |
2700 | |
2701 | bool ret = wxControl::Create( parent, id, pos, size, style, validator, name ); | |
2702 | ||
fc3463cc | 2703 | |
25e3a937 VZ |
2704 | if (style & wxSUNKEN_BORDER) |
2705 | style -= wxSUNKEN_BORDER; | |
bd8289c1 | 2706 | |
25e3a937 | 2707 | m_mainWin = new wxListMainWindow( this, -1, wxPoint(0,0), size, style ); |
bd8289c1 | 2708 | |
f03fc89f | 2709 | if (HasFlag(wxLC_REPORT)) |
5b077d48 RR |
2710 | m_headerWin = new wxListHeaderWindow( this, -1, m_mainWin, wxPoint(0,0), wxSize(size.x,23), wxTAB_TRAVERSAL ); |
2711 | else | |
2712 | m_headerWin = (wxListHeaderWindow *) NULL; | |
bd8289c1 | 2713 | |
58dea4b0 RR |
2714 | SetBackgroundColour( *wxWHITE ); |
2715 | ||
5b077d48 | 2716 | return ret; |
e1e955e1 | 2717 | } |
c801d85f KB |
2718 | |
2719 | void wxListCtrl::OnSize( wxSizeEvent &WXUNUSED(event) ) | |
2720 | { | |
5b077d48 | 2721 | /* handled in OnIdle */ |
bd8289c1 | 2722 | |
5b077d48 | 2723 | if (m_mainWin) m_mainWin->m_dirty = TRUE; |
e1e955e1 | 2724 | } |
c801d85f | 2725 | |
debe6624 | 2726 | void wxListCtrl::SetSingleStyle( long style, bool add ) |
c801d85f | 2727 | { |
f03fc89f | 2728 | long flag = GetWindowStyle(); |
bd8289c1 | 2729 | |
5b077d48 RR |
2730 | if (add) |
2731 | { | |
2732 | if (style & wxLC_MASK_TYPE) flag = flag & ~wxLC_MASK_TYPE; | |
2733 | if (style & wxLC_MASK_ALIGN) flag = flag & ~wxLC_MASK_ALIGN; | |
2734 | if (style & wxLC_MASK_SORT) flag = flag & ~wxLC_MASK_SORT; | |
2735 | } | |
c801d85f | 2736 | |
5b077d48 RR |
2737 | if (add) |
2738 | { | |
2739 | flag |= style; | |
2740 | } | |
2741 | else | |
2742 | { | |
2743 | if (flag & style) flag -= style; | |
2744 | } | |
bd8289c1 | 2745 | |
5b077d48 | 2746 | SetWindowStyleFlag( flag ); |
e1e955e1 | 2747 | } |
c801d85f | 2748 | |
debe6624 | 2749 | void wxListCtrl::SetWindowStyleFlag( long flag ) |
c801d85f | 2750 | { |
121a3581 RR |
2751 | if (m_mainWin) |
2752 | { | |
2753 | m_mainWin->DeleteEverything(); | |
c801d85f | 2754 | |
121a3581 RR |
2755 | int width = 0; |
2756 | int height = 0; | |
2757 | GetClientSize( &width, &height ); | |
c801d85f | 2758 | |
121a3581 | 2759 | m_mainWin->SetMode( flag ); |
bd8289c1 | 2760 | |
121a3581 | 2761 | if (flag & wxLC_REPORT) |
5b077d48 | 2762 | { |
121a3581 | 2763 | if (!HasFlag(wxLC_REPORT)) |
5b077d48 | 2764 | { |
121a3581 RR |
2765 | if (!m_headerWin) |
2766 | { | |
004fd0c8 | 2767 | m_headerWin = new wxListHeaderWindow( this, -1, m_mainWin, |
bffa1c77 VZ |
2768 | wxPoint(0,0), wxSize(width,23), wxTAB_TRAVERSAL ); |
2769 | if (HasFlag(wxLC_NO_HEADER)) | |
2770 | m_headerWin->Show( FALSE ); | |
121a3581 RR |
2771 | } |
2772 | else | |
004fd0c8 | 2773 | { |
bffa1c77 VZ |
2774 | if (flag & wxLC_NO_HEADER) |
2775 | m_headerWin->Show( FALSE ); | |
2776 | else | |
8636aed8 | 2777 | m_headerWin->Show( TRUE ); |
004fd0c8 | 2778 | } |
5b077d48 RR |
2779 | } |
2780 | } | |
121a3581 | 2781 | else |
5b077d48 | 2782 | { |
8636aed8 | 2783 | if (HasFlag(wxLC_REPORT) && !(HasFlag(wxLC_NO_HEADER))) |
121a3581 RR |
2784 | { |
2785 | m_headerWin->Show( FALSE ); | |
2786 | } | |
bffa1c77 | 2787 | } |
e1e955e1 | 2788 | } |
004fd0c8 | 2789 | |
5b077d48 | 2790 | wxWindow::SetWindowStyleFlag( flag ); |
e1e955e1 | 2791 | } |
c801d85f | 2792 | |
e487524e | 2793 | bool wxListCtrl::GetColumn(int col, wxListItem &item) const |
c801d85f | 2794 | { |
5b077d48 RR |
2795 | m_mainWin->GetColumn( col, item ); |
2796 | return TRUE; | |
e1e955e1 | 2797 | } |
c801d85f | 2798 | |
debe6624 | 2799 | bool wxListCtrl::SetColumn( int col, wxListItem& item ) |
c801d85f | 2800 | { |
5b077d48 RR |
2801 | m_mainWin->SetColumn( col, item ); |
2802 | return TRUE; | |
e1e955e1 | 2803 | } |
c801d85f | 2804 | |
e487524e | 2805 | int wxListCtrl::GetColumnWidth( int col ) const |
c801d85f | 2806 | { |
5b077d48 | 2807 | return m_mainWin->GetColumnWidth( col ); |
e1e955e1 | 2808 | } |
c801d85f | 2809 | |
debe6624 | 2810 | bool wxListCtrl::SetColumnWidth( int col, int width ) |
c801d85f | 2811 | { |
5b077d48 RR |
2812 | m_mainWin->SetColumnWidth( col, width ); |
2813 | return TRUE; | |
e1e955e1 | 2814 | } |
c801d85f | 2815 | |
fd9811b1 | 2816 | int wxListCtrl::GetCountPerPage() const |
c801d85f KB |
2817 | { |
2818 | return m_mainWin->GetCountPerPage(); // different from Windows ? | |
e1e955e1 | 2819 | } |
c801d85f | 2820 | |
e487524e | 2821 | bool wxListCtrl::GetItem( wxListItem &info ) const |
c801d85f | 2822 | { |
5b077d48 RR |
2823 | m_mainWin->GetItem( info ); |
2824 | return TRUE; | |
e1e955e1 | 2825 | } |
c801d85f KB |
2826 | |
2827 | bool wxListCtrl::SetItem( wxListItem &info ) | |
2828 | { | |
5b077d48 RR |
2829 | m_mainWin->SetItem( info ); |
2830 | return TRUE; | |
e1e955e1 | 2831 | } |
c801d85f | 2832 | |
debe6624 | 2833 | long wxListCtrl::SetItem( long index, int col, const wxString& label, int imageId ) |
c801d85f | 2834 | { |
5b077d48 RR |
2835 | wxListItem info; |
2836 | info.m_text = label; | |
2837 | info.m_mask = wxLIST_MASK_TEXT; | |
2838 | info.m_itemId = index; | |
2839 | info.m_col = col; | |
2840 | if ( imageId > -1 ) | |
2841 | { | |
2842 | info.m_image = imageId; | |
2843 | info.m_mask |= wxLIST_MASK_IMAGE; | |
2844 | }; | |
2845 | m_mainWin->SetItem(info); | |
2846 | return TRUE; | |
e1e955e1 | 2847 | } |
c801d85f | 2848 | |
e487524e | 2849 | int wxListCtrl::GetItemState( long item, long stateMask ) const |
c801d85f | 2850 | { |
5b077d48 | 2851 | return m_mainWin->GetItemState( item, stateMask ); |
e1e955e1 | 2852 | } |
c801d85f | 2853 | |
debe6624 | 2854 | bool wxListCtrl::SetItemState( long item, long state, long stateMask ) |
c801d85f | 2855 | { |
5b077d48 RR |
2856 | m_mainWin->SetItemState( item, state, stateMask ); |
2857 | return TRUE; | |
e1e955e1 | 2858 | } |
c801d85f | 2859 | |
debe6624 | 2860 | bool wxListCtrl::SetItemImage( long item, int image, int WXUNUSED(selImage) ) |
c801d85f | 2861 | { |
5b077d48 RR |
2862 | wxListItem info; |
2863 | info.m_image = image; | |
2864 | info.m_mask = wxLIST_MASK_IMAGE; | |
2865 | info.m_itemId = item; | |
2866 | m_mainWin->SetItem( info ); | |
2867 | return TRUE; | |
e1e955e1 | 2868 | } |
c801d85f | 2869 | |
e487524e | 2870 | wxString wxListCtrl::GetItemText( long item ) const |
c801d85f | 2871 | { |
5b077d48 RR |
2872 | wxListItem info; |
2873 | info.m_itemId = item; | |
2874 | m_mainWin->GetItem( info ); | |
2875 | return info.m_text; | |
e1e955e1 | 2876 | } |
c801d85f | 2877 | |
debe6624 | 2878 | void wxListCtrl::SetItemText( long item, const wxString &str ) |
c801d85f | 2879 | { |
5b077d48 RR |
2880 | wxListItem info; |
2881 | info.m_mask = wxLIST_MASK_TEXT; | |
2882 | info.m_itemId = item; | |
2883 | info.m_text = str; | |
2884 | m_mainWin->SetItem( info ); | |
e1e955e1 | 2885 | } |
c801d85f | 2886 | |
e487524e | 2887 | long wxListCtrl::GetItemData( long item ) const |
c801d85f | 2888 | { |
5b077d48 RR |
2889 | wxListItem info; |
2890 | info.m_itemId = item; | |
2891 | m_mainWin->GetItem( info ); | |
2892 | return info.m_data; | |
e1e955e1 | 2893 | } |
c801d85f | 2894 | |
debe6624 | 2895 | bool wxListCtrl::SetItemData( long item, long data ) |
c801d85f | 2896 | { |
5b077d48 RR |
2897 | wxListItem info; |
2898 | info.m_mask = wxLIST_MASK_DATA; | |
2899 | info.m_itemId = item; | |
2900 | info.m_data = data; | |
2901 | m_mainWin->SetItem( info ); | |
2902 | return TRUE; | |
e1e955e1 | 2903 | } |
c801d85f | 2904 | |
0a240683 | 2905 | bool wxListCtrl::GetItemRect( long item, wxRect &rect, int WXUNUSED(code) ) const |
c801d85f | 2906 | { |
5b077d48 RR |
2907 | m_mainWin->GetItemRect( item, rect ); |
2908 | return TRUE; | |
e1e955e1 | 2909 | } |
c801d85f | 2910 | |
e487524e | 2911 | bool wxListCtrl::GetItemPosition( long item, wxPoint& pos ) const |
c801d85f | 2912 | { |
5b077d48 RR |
2913 | m_mainWin->GetItemPosition( item, pos ); |
2914 | return TRUE; | |
e1e955e1 | 2915 | } |
c801d85f | 2916 | |
debe6624 | 2917 | bool wxListCtrl::SetItemPosition( long WXUNUSED(item), const wxPoint& WXUNUSED(pos) ) |
c801d85f | 2918 | { |
5b077d48 | 2919 | return 0; |
e1e955e1 | 2920 | } |
c801d85f | 2921 | |
fd9811b1 | 2922 | int wxListCtrl::GetItemCount() const |
c801d85f | 2923 | { |
5b077d48 | 2924 | return m_mainWin->GetItemCount(); |
e1e955e1 | 2925 | } |
c801d85f | 2926 | |
fd9811b1 | 2927 | int wxListCtrl::GetColumnCount() const |
92976ab6 | 2928 | { |
5b077d48 | 2929 | return m_mainWin->GetColumnCount(); |
92976ab6 RR |
2930 | } |
2931 | ||
33d0b396 RR |
2932 | void wxListCtrl::SetItemSpacing( int spacing, bool isSmall ) |
2933 | { | |
5b077d48 | 2934 | m_mainWin->SetItemSpacing( spacing, isSmall ); |
e1e955e1 | 2935 | } |
33d0b396 | 2936 | |
e487524e | 2937 | int wxListCtrl::GetItemSpacing( bool isSmall ) const |
c801d85f | 2938 | { |
5b077d48 | 2939 | return m_mainWin->GetItemSpacing( isSmall ); |
e1e955e1 | 2940 | } |
c801d85f | 2941 | |
fd9811b1 | 2942 | int wxListCtrl::GetSelectedItemCount() const |
c801d85f | 2943 | { |
5b077d48 | 2944 | return m_mainWin->GetSelectedItemCount(); |
e1e955e1 | 2945 | } |
c801d85f | 2946 | |
fd9811b1 | 2947 | wxColour wxListCtrl::GetTextColour() const |
c801d85f | 2948 | { |
0530737d | 2949 | return GetForegroundColour(); |
e1e955e1 | 2950 | } |
c801d85f | 2951 | |
0530737d | 2952 | void wxListCtrl::SetTextColour(const wxColour& col) |
c801d85f | 2953 | { |
0530737d | 2954 | SetForegroundColour(col); |
e1e955e1 | 2955 | } |
c801d85f | 2956 | |
fd9811b1 | 2957 | long wxListCtrl::GetTopItem() const |
c801d85f | 2958 | { |
5b077d48 | 2959 | return 0; |
e1e955e1 | 2960 | } |
c801d85f | 2961 | |
6de97a3b | 2962 | long wxListCtrl::GetNextItem( long item, int geom, int state ) const |
c801d85f | 2963 | { |
5b077d48 | 2964 | return m_mainWin->GetNextItem( item, geom, state ); |
e1e955e1 | 2965 | } |
c801d85f | 2966 | |
e487524e | 2967 | wxImageList *wxListCtrl::GetImageList(int which) const |
c801d85f | 2968 | { |
5b077d48 RR |
2969 | if (which == wxIMAGE_LIST_NORMAL) |
2970 | { | |
2971 | return m_imageListNormal; | |
2972 | } | |
2973 | else if (which == wxIMAGE_LIST_SMALL) | |
2974 | { | |
2975 | return m_imageListSmall; | |
2976 | } | |
2977 | else if (which == wxIMAGE_LIST_STATE) | |
2978 | { | |
2979 | return m_imageListState; | |
2980 | } | |
2981 | return (wxImageList *) NULL; | |
e1e955e1 | 2982 | } |
c801d85f | 2983 | |
debe6624 | 2984 | void wxListCtrl::SetImageList( wxImageList *imageList, int which ) |
c801d85f | 2985 | { |
5b077d48 | 2986 | m_mainWin->SetImageList( imageList, which ); |
e1e955e1 | 2987 | } |
c801d85f | 2988 | |
debe6624 | 2989 | bool wxListCtrl::Arrange( int WXUNUSED(flag) ) |
c801d85f | 2990 | { |
5b077d48 | 2991 | return 0; |
e1e955e1 | 2992 | } |
c801d85f | 2993 | |
debe6624 | 2994 | bool wxListCtrl::DeleteItem( long item ) |
c801d85f | 2995 | { |
5b077d48 RR |
2996 | m_mainWin->DeleteItem( item ); |
2997 | return TRUE; | |
e1e955e1 | 2998 | } |
c801d85f | 2999 | |
fd9811b1 | 3000 | bool wxListCtrl::DeleteAllItems() |
c801d85f | 3001 | { |
5b077d48 RR |
3002 | m_mainWin->DeleteAllItems(); |
3003 | return TRUE; | |
e1e955e1 | 3004 | } |
c801d85f | 3005 | |
4f22cf8d | 3006 | bool wxListCtrl::DeleteAllColumns() |
bd8289c1 VZ |
3007 | { |
3008 | for ( size_t n = 0; n < m_mainWin->m_columns.GetCount(); n++ ) | |
3009 | DeleteColumn(n); | |
bffa1c77 | 3010 | |
5b077d48 | 3011 | return TRUE; |
4f22cf8d RR |
3012 | } |
3013 | ||
3014 | void wxListCtrl::ClearAll() | |
3015 | { | |
5b077d48 | 3016 | m_mainWin->DeleteEverything(); |
bd8289c1 VZ |
3017 | } |
3018 | ||
debe6624 | 3019 | bool wxListCtrl::DeleteColumn( int col ) |
c801d85f | 3020 | { |
5b077d48 RR |
3021 | m_mainWin->DeleteColumn( col ); |
3022 | return TRUE; | |
e1e955e1 | 3023 | } |
c801d85f | 3024 | |
e179bd65 | 3025 | void wxListCtrl::Edit( long item ) |
c801d85f | 3026 | { |
e179bd65 | 3027 | m_mainWin->Edit( item ); |
e1e955e1 | 3028 | } |
c801d85f | 3029 | |
debe6624 | 3030 | bool wxListCtrl::EnsureVisible( long item ) |
c801d85f | 3031 | { |
5b077d48 RR |
3032 | m_mainWin->EnsureVisible( item ); |
3033 | return TRUE; | |
e1e955e1 | 3034 | } |
c801d85f | 3035 | |
debe6624 | 3036 | long wxListCtrl::FindItem( long start, const wxString& str, bool partial ) |
c801d85f | 3037 | { |
5b077d48 | 3038 | return m_mainWin->FindItem( start, str, partial ); |
e1e955e1 | 3039 | } |
c801d85f | 3040 | |
debe6624 | 3041 | long wxListCtrl::FindItem( long start, long data ) |
c801d85f | 3042 | { |
5b077d48 | 3043 | return m_mainWin->FindItem( start, data ); |
e1e955e1 | 3044 | } |
c801d85f | 3045 | |
bd8289c1 | 3046 | long wxListCtrl::FindItem( long WXUNUSED(start), const wxPoint& WXUNUSED(pt), |
debe6624 | 3047 | int WXUNUSED(direction)) |
c801d85f | 3048 | { |
5b077d48 | 3049 | return 0; |
e1e955e1 | 3050 | } |
c801d85f KB |
3051 | |
3052 | long wxListCtrl::HitTest( const wxPoint &point, int &flags ) | |
3053 | { | |
5b077d48 | 3054 | return m_mainWin->HitTest( (int)point.x, (int)point.y, flags ); |
e1e955e1 | 3055 | } |
c801d85f KB |
3056 | |
3057 | long wxListCtrl::InsertItem( wxListItem& info ) | |
3058 | { | |
5b077d48 | 3059 | m_mainWin->InsertItem( info ); |
2ebcd5f5 | 3060 | return info.m_itemId; |
e1e955e1 | 3061 | } |
c801d85f | 3062 | |
debe6624 | 3063 | long wxListCtrl::InsertItem( long index, const wxString &label ) |
c801d85f | 3064 | { |
51cc4dad RR |
3065 | wxListItem info; |
3066 | info.m_text = label; | |
3067 | info.m_mask = wxLIST_MASK_TEXT; | |
3068 | info.m_itemId = index; | |
3069 | return InsertItem( info ); | |
e1e955e1 | 3070 | } |
c801d85f | 3071 | |
debe6624 | 3072 | long wxListCtrl::InsertItem( long index, int imageIndex ) |
c801d85f | 3073 | { |
51cc4dad RR |
3074 | wxListItem info; |
3075 | info.m_mask = wxLIST_MASK_IMAGE; | |
3076 | info.m_image = imageIndex; | |
3077 | info.m_itemId = index; | |
3078 | return InsertItem( info ); | |
e1e955e1 | 3079 | } |
c801d85f | 3080 | |
debe6624 | 3081 | long wxListCtrl::InsertItem( long index, const wxString &label, int imageIndex ) |
c801d85f | 3082 | { |
51cc4dad RR |
3083 | wxListItem info; |
3084 | info.m_text = label; | |
3085 | info.m_image = imageIndex; | |
3086 | info.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_IMAGE; | |
3087 | info.m_itemId = index; | |
3088 | return InsertItem( info ); | |
e1e955e1 | 3089 | } |
c801d85f | 3090 | |
debe6624 | 3091 | long wxListCtrl::InsertColumn( long col, wxListItem &item ) |
c801d85f | 3092 | { |
d3e90957 | 3093 | wxASSERT( m_headerWin ); |
51cc4dad | 3094 | m_mainWin->InsertColumn( col, item ); |
d3e90957 | 3095 | m_headerWin->Refresh(); |
25e3a937 | 3096 | |
51cc4dad | 3097 | return 0; |
e1e955e1 | 3098 | } |
c801d85f | 3099 | |
debe6624 JS |
3100 | long wxListCtrl::InsertColumn( long col, const wxString &heading, |
3101 | int format, int width ) | |
c801d85f | 3102 | { |
51cc4dad RR |
3103 | wxListItem item; |
3104 | item.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_FORMAT; | |
3105 | item.m_text = heading; | |
3106 | if (width >= -2) | |
3107 | { | |
3108 | item.m_mask |= wxLIST_MASK_WIDTH; | |
3109 | item.m_width = width; | |
3110 | } | |
3111 | item.m_format = format; | |
c801d85f | 3112 | |
51cc4dad | 3113 | return InsertColumn( col, item ); |
e1e955e1 | 3114 | } |
c801d85f | 3115 | |
debe6624 | 3116 | bool wxListCtrl::ScrollList( int WXUNUSED(dx), int WXUNUSED(dy) ) |
c801d85f | 3117 | { |
51cc4dad | 3118 | return 0; |
e1e955e1 | 3119 | } |
c801d85f KB |
3120 | |
3121 | // Sort items. | |
3122 | // fn is a function which takes 3 long arguments: item1, item2, data. | |
3123 | // item1 is the long data associated with a first item (NOT the index). | |
3124 | // item2 is the long data associated with a second item (NOT the index). | |
3125 | // data is the same value as passed to SortItems. | |
3126 | // The return value is a negative number if the first item should precede the second | |
3127 | // item, a positive number of the second item should precede the first, | |
3128 | // or zero if the two items are equivalent. | |
3129 | // data is arbitrary data to be passed to the sort function. | |
3130 | ||
3131 | bool wxListCtrl::SortItems( wxListCtrlCompare fn, long data ) | |
3132 | { | |
51cc4dad RR |
3133 | m_mainWin->SortItems( fn, data ); |
3134 | return TRUE; | |
e1e955e1 | 3135 | } |
c801d85f | 3136 | |
e3e65dac | 3137 | void wxListCtrl::OnIdle( wxIdleEvent &WXUNUSED(event) ) |
53010e52 | 3138 | { |
51cc4dad | 3139 | if (!m_mainWin->m_dirty) return; |
53010e52 | 3140 | |
51cc4dad RR |
3141 | int cw = 0; |
3142 | int ch = 0; | |
3143 | GetClientSize( &cw, &ch ); | |
bd8289c1 | 3144 | |
51cc4dad RR |
3145 | int x = 0; |
3146 | int y = 0; | |
3147 | int w = 0; | |
3148 | int h = 0; | |
bd8289c1 | 3149 | |
8636aed8 | 3150 | if (HasFlag(wxLC_REPORT) && !HasFlag(wxLC_NO_HEADER)) |
51cc4dad RR |
3151 | { |
3152 | m_headerWin->GetPosition( &x, &y ); | |
3153 | m_headerWin->GetSize( &w, &h ); | |
3154 | if ((x != 0) || (y != 0) || (w != cw) || (h != 23)) | |
3155 | m_headerWin->SetSize( 0, 0, cw, 23 ); | |
3156 | ||
3157 | m_mainWin->GetPosition( &x, &y ); | |
3158 | m_mainWin->GetSize( &w, &h ); | |
3159 | if ((x != 0) || (y != 24) || (w != cw) || (h != ch-24)) | |
3160 | m_mainWin->SetSize( 0, 24, cw, ch-24 ); | |
3161 | } | |
3162 | else | |
3163 | { | |
3164 | m_mainWin->GetPosition( &x, &y ); | |
3165 | m_mainWin->GetSize( &w, &h ); | |
3166 | if ((x != 0) || (y != 24) || (w != cw) || (h != ch)) | |
3167 | m_mainWin->SetSize( 0, 0, cw, ch ); | |
3168 | } | |
bd8289c1 | 3169 | |
51cc4dad RR |
3170 | m_mainWin->CalculatePositions(); |
3171 | m_mainWin->RealizeChanges(); | |
3172 | m_mainWin->m_dirty = FALSE; | |
3173 | m_mainWin->Refresh(); | |
e1e955e1 | 3174 | } |
53010e52 | 3175 | |
f03fc89f | 3176 | bool wxListCtrl::SetBackgroundColour( const wxColour &colour ) |
bd8289c1 | 3177 | { |
f03fc89f VZ |
3178 | if ( !wxWindow::SetBackgroundColour( colour ) ) |
3179 | return FALSE; | |
58dea4b0 | 3180 | |
51cc4dad RR |
3181 | if (m_mainWin) |
3182 | { | |
3183 | m_mainWin->SetBackgroundColour( colour ); | |
3184 | m_mainWin->m_dirty = TRUE; | |
3185 | } | |
004fd0c8 | 3186 | |
51cc4dad RR |
3187 | if (m_headerWin) |
3188 | { | |
cfb50f14 | 3189 | // m_headerWin->SetBackgroundColour( colour ); |
51cc4dad | 3190 | } |
f03fc89f VZ |
3191 | |
3192 | return TRUE; | |
e4d06860 RR |
3193 | } |
3194 | ||
f03fc89f | 3195 | bool wxListCtrl::SetForegroundColour( const wxColour &colour ) |
bd8289c1 | 3196 | { |
f03fc89f VZ |
3197 | if ( !wxWindow::SetForegroundColour( colour ) ) |
3198 | return FALSE; | |
004fd0c8 | 3199 | |
51cc4dad RR |
3200 | if (m_mainWin) |
3201 | { | |
3202 | m_mainWin->SetForegroundColour( colour ); | |
3203 | m_mainWin->m_dirty = TRUE; | |
3204 | } | |
004fd0c8 | 3205 | |
51cc4dad RR |
3206 | if (m_headerWin) |
3207 | { | |
3208 | m_headerWin->SetForegroundColour( colour ); | |
3209 | } | |
f03fc89f VZ |
3210 | |
3211 | return TRUE; | |
e4d06860 | 3212 | } |
bd8289c1 | 3213 | |
f03fc89f | 3214 | bool wxListCtrl::SetFont( const wxFont &font ) |
bd8289c1 | 3215 | { |
f03fc89f VZ |
3216 | if ( !wxWindow::SetFont( font ) ) |
3217 | return FALSE; | |
004fd0c8 | 3218 | |
51cc4dad RR |
3219 | if (m_mainWin) |
3220 | { | |
3221 | m_mainWin->SetFont( font ); | |
3222 | m_mainWin->m_dirty = TRUE; | |
3223 | } | |
004fd0c8 | 3224 | |
51cc4dad RR |
3225 | if (m_headerWin) |
3226 | { | |
3227 | m_headerWin->SetFont( font ); | |
3228 | } | |
f03fc89f VZ |
3229 | |
3230 | return TRUE; | |
e4d06860 | 3231 | } |
c801d85f | 3232 |