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