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