]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: listctrl.cpp | |
3 | // Purpose: | |
4 | // Author: Robert Roebling | |
0208334d RR |
5 | // Id: $Id$ |
6 | // Copyright: (c) 1998 Robert Roebling | |
bd8289c1 | 7 | // Licence: wxWindows licence |
c801d85f KB |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
10 | #ifdef __GNUG__ | |
11 | #pragma implementation "listctrl.h" | |
12 | #endif | |
13 | ||
1e6d9499 JS |
14 | // For compilers that support precompilation, includes "wx.h". |
15 | #include "wx/wxprec.h" | |
16 | ||
17 | #ifdef __BORLANDC__ | |
18 | #pragma hdrstop | |
19 | #endif | |
20 | ||
0208334d RR |
21 | #include "wx/dcscreen.h" |
22 | #include "wx/app.h" | |
02527779 | 23 | #include "wx/listctrl.h" |
f60d0f94 | 24 | #include "wx/generic/imaglist.h" |
c801d85f 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; | |
5f1ea0ee RR |
902 | (*m_accept) = FALSE; |
903 | (*m_res) = ""; | |
904 | m_startValue = value; | |
ee7ee469 RR |
905 | } |
906 | ||
907 | void wxListTextCtrl::OnChar( wxKeyEvent &event ) | |
908 | { | |
63852e78 RR |
909 | if (event.m_keyCode == WXK_RETURN) |
910 | { | |
911 | (*m_accept) = TRUE; | |
912 | (*m_res) = GetValue(); | |
5f1ea0ee | 913 | m_owner->SetFocus(); |
63852e78 RR |
914 | return; |
915 | } | |
916 | if (event.m_keyCode == WXK_ESCAPE) | |
917 | { | |
918 | (*m_accept) = FALSE; | |
919 | (*m_res) = ""; | |
5f1ea0ee | 920 | m_owner->SetFocus(); |
63852e78 RR |
921 | return; |
922 | } | |
923 | event.Skip(); | |
924 | } | |
925 | ||
926 | void wxListTextCtrl::OnKillFocus( wxFocusEvent &WXUNUSED(event) ) | |
927 | { | |
5f1ea0ee RR |
928 | if (wxPendingDelete.Member(this)) return; |
929 | ||
930 | wxPendingDelete.Append(this); | |
931 | ||
932 | if ((*m_accept) && ((*m_res) != m_startValue)) | |
933 | m_owner->OnRenameAccept(); | |
ee7ee469 RR |
934 | } |
935 | ||
c801d85f KB |
936 | //----------------------------------------------------------------------------- |
937 | // wxListMainWindow | |
938 | //----------------------------------------------------------------------------- | |
939 | ||
940 | IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow,wxScrolledWindow); | |
bd8289c1 | 941 | |
c801d85f KB |
942 | BEGIN_EVENT_TABLE(wxListMainWindow,wxScrolledWindow) |
943 | EVT_PAINT (wxListMainWindow::OnPaint) | |
944 | EVT_SIZE (wxListMainWindow::OnSize) | |
945 | EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse) | |
946 | EVT_CHAR (wxListMainWindow::OnChar) | |
3dfb93fd | 947 | EVT_KEY_DOWN (wxListMainWindow::OnKeyDown) |
c801d85f KB |
948 | EVT_SET_FOCUS (wxListMainWindow::OnSetFocus) |
949 | EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus) | |
950 | END_EVENT_TABLE() | |
951 | ||
952 | wxListMainWindow::wxListMainWindow( void ) | |
953 | { | |
139adb6a RR |
954 | m_mode = 0; |
955 | m_lines.DeleteContents( TRUE ); | |
956 | m_columns.DeleteContents( TRUE ); | |
957 | m_current = (wxListLineData *) NULL; | |
958 | m_visibleLines = 0; | |
959 | m_hilightBrush = (wxBrush *) NULL; | |
960 | m_xScroll = 0; | |
961 | m_yScroll = 0; | |
962 | m_dirty = TRUE; | |
963 | m_small_image_list = (wxImageList *) NULL; | |
964 | m_normal_image_list = (wxImageList *) NULL; | |
965 | m_small_spacing = 30; | |
966 | m_normal_spacing = 40; | |
967 | m_hasFocus = FALSE; | |
968 | m_usedKeys = TRUE; | |
969 | m_lastOnSame = FALSE; | |
970 | m_renameTimer = new wxListRenameTimer( this ); | |
971 | m_isCreated = FALSE; | |
972 | m_dragCount = 0; | |
e1e955e1 | 973 | } |
c801d85f | 974 | |
bd8289c1 | 975 | wxListMainWindow::wxListMainWindow( wxWindow *parent, wxWindowID id, |
c801d85f | 976 | const wxPoint &pos, const wxSize &size, |
debe6624 | 977 | long style, const wxString &name ) : |
a367b9b3 | 978 | wxScrolledWindow( parent, id, pos, size, style|wxHSCROLL|wxVSCROLL, name ) |
c801d85f | 979 | { |
139adb6a RR |
980 | m_mode = style; |
981 | m_lines.DeleteContents( TRUE ); | |
982 | m_columns.DeleteContents( TRUE ); | |
983 | m_current = (wxListLineData *) NULL; | |
984 | m_dirty = TRUE; | |
985 | m_visibleLines = 0; | |
986 | m_hilightBrush = new wxBrush( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT), wxSOLID ); | |
987 | m_small_image_list = (wxImageList *) NULL; | |
988 | m_normal_image_list = (wxImageList *) NULL; | |
989 | m_small_spacing = 30; | |
990 | m_normal_spacing = 40; | |
991 | m_hasFocus = FALSE; | |
992 | m_dragCount = 0; | |
993 | m_isCreated = FALSE; | |
994 | wxSize sz = size; | |
995 | sz.y = 25; | |
bd8289c1 | 996 | |
139adb6a RR |
997 | if (m_mode & wxLC_REPORT) |
998 | { | |
999 | m_xScroll = 0; | |
1000 | m_yScroll = 15; | |
1001 | } | |
1002 | else | |
1003 | { | |
1004 | m_xScroll = 15; | |
1005 | m_yScroll = 0; | |
1006 | } | |
1007 | SetScrollbars( m_xScroll, m_yScroll, 0, 0, 0, 0 ); | |
bd8289c1 | 1008 | |
139adb6a RR |
1009 | m_usedKeys = TRUE; |
1010 | m_lastOnSame = FALSE; | |
1011 | m_renameTimer = new wxListRenameTimer( this ); | |
1012 | m_renameAccept = FALSE; | |
c801d85f | 1013 | |
139adb6a | 1014 | SetBackgroundColour( *wxWHITE ); |
e1e955e1 | 1015 | } |
c801d85f KB |
1016 | |
1017 | wxListMainWindow::~wxListMainWindow( void ) | |
1018 | { | |
139adb6a RR |
1019 | if (m_hilightBrush) delete m_hilightBrush; |
1020 | ||
1021 | delete m_renameTimer; | |
e1e955e1 | 1022 | } |
c801d85f KB |
1023 | |
1024 | void wxListMainWindow::RefreshLine( wxListLineData *line ) | |
1025 | { | |
139adb6a RR |
1026 | int x = 0; |
1027 | int y = 0; | |
1028 | int w = 0; | |
1029 | int h = 0; | |
1030 | if (line) | |
1031 | { | |
1032 | wxClientDC dc(this); | |
1033 | PrepareDC( dc ); | |
1034 | line->GetExtent( x, y, w, h ); | |
0a240683 | 1035 | wxRect rect( |
139adb6a RR |
1036 | dc.LogicalToDeviceX(x-3), |
1037 | dc.LogicalToDeviceY(y-3), | |
1038 | dc.LogicalToDeviceXRel(w+6), | |
1039 | dc.LogicalToDeviceXRel(h+6) ); | |
1040 | Refresh( TRUE, &rect ); | |
1041 | } | |
e1e955e1 | 1042 | } |
c801d85f KB |
1043 | |
1044 | void wxListMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) | |
1045 | { | |
f60d0f94 JS |
1046 | // Note: a wxPaintDC must be constructed even if no drawing is |
1047 | // done (a Windows requirement). | |
1048 | wxPaintDC dc( this ); | |
1049 | PrepareDC( dc ); | |
1050 | ||
139adb6a RR |
1051 | if (m_dirty) return; |
1052 | ||
1053 | if (m_lines.GetCount() == 0) return; | |
bd8289c1 | 1054 | |
139adb6a | 1055 | dc.BeginDrawing(); |
c801d85f | 1056 | |
139adb6a RR |
1057 | dc.SetFont( GetFont() ); |
1058 | ||
1059 | if (m_mode & wxLC_REPORT) | |
1060 | { | |
1061 | int lineSpacing = 0; | |
1062 | wxListLineData *line = (wxListLineData*)m_lines.First()->Data(); | |
1063 | int dummy = 0; | |
1064 | line->GetSize( dummy, lineSpacing ); | |
1065 | lineSpacing += 1; | |
1066 | ||
1067 | int y_s = m_yScroll*GetScrollPos( wxVERTICAL ); | |
1068 | ||
1069 | wxNode *node = m_lines.Nth( y_s / lineSpacing ); | |
1070 | for (int i = 0; i < m_visibleLines+2; i++) | |
1071 | { | |
1072 | if (!node) break; | |
1073 | ||
1074 | line = (wxListLineData*)node->Data(); | |
1075 | line->Draw( &dc ); | |
1076 | node = node->Next(); | |
1077 | } | |
1078 | } | |
1079 | else | |
1080 | { | |
1081 | wxNode *node = m_lines.First(); | |
1082 | while (node) | |
1083 | { | |
1084 | wxListLineData *line = (wxListLineData*)node->Data(); | |
1085 | line->Draw( &dc ); | |
1086 | node = node->Next(); | |
1087 | } | |
1088 | } | |
1089 | ||
1090 | if (m_current) m_current->DrawRubberBand( &dc, m_hasFocus ); | |
c801d85f | 1091 | |
139adb6a | 1092 | dc.EndDrawing(); |
e1e955e1 | 1093 | } |
c801d85f | 1094 | |
debe6624 | 1095 | void wxListMainWindow::HilightAll( bool on ) |
c801d85f | 1096 | { |
139adb6a RR |
1097 | wxNode *node = m_lines.First(); |
1098 | while (node) | |
c801d85f | 1099 | { |
139adb6a RR |
1100 | wxListLineData *line = (wxListLineData *)node->Data(); |
1101 | if (line->IsHilighted() != on) | |
1102 | { | |
1103 | line->Hilight( on ); | |
1104 | RefreshLine( line ); | |
1105 | } | |
1106 | node = node->Next(); | |
e1e955e1 | 1107 | } |
e1e955e1 | 1108 | } |
c801d85f | 1109 | |
7798a18e | 1110 | void wxListMainWindow::SendNotify( wxListLineData *line, wxEventType command ) |
c801d85f | 1111 | { |
139adb6a RR |
1112 | wxListEvent le( command, GetParent()->GetId() ); |
1113 | le.SetEventObject( GetParent() ); | |
1114 | le.m_itemIndex = GetIndexOfLine( line ); | |
1115 | line->GetItem( 0, le.m_item ); | |
1116 | GetParent()->GetEventHandler()->ProcessEvent( le ); | |
e1e955e1 | 1117 | } |
c801d85f KB |
1118 | |
1119 | void wxListMainWindow::FocusLine( wxListLineData *WXUNUSED(line) ) | |
1120 | { | |
1121 | // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_FOCUSSED ); | |
e1e955e1 | 1122 | } |
c801d85f KB |
1123 | |
1124 | void wxListMainWindow::UnfocusLine( wxListLineData *WXUNUSED(line) ) | |
1125 | { | |
1126 | // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_UNFOCUSSED ); | |
e1e955e1 | 1127 | } |
c801d85f KB |
1128 | |
1129 | void wxListMainWindow::SelectLine( wxListLineData *line ) | |
1130 | { | |
139adb6a | 1131 | SendNotify( line, wxEVT_COMMAND_LIST_ITEM_SELECTED ); |
e1e955e1 | 1132 | } |
c801d85f KB |
1133 | |
1134 | void wxListMainWindow::DeselectLine( wxListLineData *line ) | |
1135 | { | |
139adb6a | 1136 | SendNotify( line, wxEVT_COMMAND_LIST_ITEM_DESELECTED ); |
e1e955e1 | 1137 | } |
c801d85f KB |
1138 | |
1139 | void wxListMainWindow::DeleteLine( wxListLineData *line ) | |
1140 | { | |
139adb6a | 1141 | SendNotify( line, wxEVT_COMMAND_LIST_DELETE_ITEM ); |
e1e955e1 | 1142 | } |
c801d85f | 1143 | |
e179bd65 | 1144 | /* *** */ |
ee7ee469 | 1145 | |
5f1ea0ee | 1146 | void wxListMainWindow::EditLabel( long item ) |
c801d85f | 1147 | { |
e179bd65 | 1148 | wxNode *node = m_lines.Nth( item ); |
813c20a6 | 1149 | wxCHECK_RET( node, _T("wrong index in wxListCtrl::Edit()") ); |
e179bd65 RR |
1150 | |
1151 | m_currentEdit = (wxListLineData*) node->Data(); | |
1152 | ||
139adb6a RR |
1153 | wxListEvent le( wxEVT_COMMAND_LIST_END_LABEL_EDIT, GetParent()->GetId() ); |
1154 | le.SetEventObject( GetParent() ); | |
e179bd65 RR |
1155 | le.m_itemIndex = GetIndexOfLine( m_currentEdit ); |
1156 | m_currentEdit->GetItem( 0, le.m_item ); | |
139adb6a | 1157 | GetParent()->GetEventHandler()->ProcessEvent( le ); |
e179bd65 | 1158 | |
86f975a8 | 1159 | if (!le.IsAllowed()) |
5f1ea0ee | 1160 | return; |
e179bd65 | 1161 | |
92976ab6 | 1162 | wxString s; |
e179bd65 | 1163 | m_currentEdit->GetText( 0, s ); |
92976ab6 RR |
1164 | int x = 0; |
1165 | int y = 0; | |
1166 | int w = 0; | |
1167 | int h = 0; | |
e179bd65 | 1168 | m_currentEdit->GetLabelExtent( x, y, w, h ); |
bd8289c1 | 1169 | |
92976ab6 RR |
1170 | wxClientDC dc(this); |
1171 | PrepareDC( dc ); | |
1172 | x = dc.LogicalToDeviceX( x ); | |
1173 | y = dc.LogicalToDeviceY( y ); | |
bd8289c1 | 1174 | |
92976ab6 RR |
1175 | wxListTextCtrl *text = new wxListTextCtrl( |
1176 | this, -1, &m_renameAccept, &m_renameRes, this, s, wxPoint(x-4,y-4), wxSize(w+11,h+8) ); | |
1177 | text->SetFocus(); | |
e1e955e1 | 1178 | } |
c801d85f | 1179 | |
e179bd65 RR |
1180 | void wxListMainWindow::OnRenameTimer() |
1181 | { | |
24bd64ee | 1182 | wxCHECK_RET( m_current, _T("invalid m_current") ); |
e179bd65 RR |
1183 | |
1184 | Edit( m_lines.IndexOf( m_current ) ); | |
1185 | } | |
1186 | ||
c801d85f KB |
1187 | void wxListMainWindow::OnRenameAccept() |
1188 | { | |
e179bd65 RR |
1189 | wxListEvent le( wxEVT_COMMAND_LIST_END_LABEL_EDIT, GetParent()->GetId() ); |
1190 | le.SetEventObject( GetParent() ); | |
1191 | le.m_itemIndex = GetIndexOfLine( m_currentEdit ); | |
1192 | m_currentEdit->GetItem( 0, le.m_item ); | |
1193 | le.m_item.m_text = m_renameRes; | |
1194 | GetParent()->GetEventHandler()->ProcessEvent( le ); | |
1195 | ||
1196 | if (!le.IsAllowed()) return; | |
1197 | ||
5f1ea0ee RR |
1198 | wxListItem info; |
1199 | info.m_mask = wxLIST_MASK_TEXT; | |
1200 | info.m_itemId = le.m_itemIndex; | |
1201 | info.m_text = m_renameRes; | |
1202 | SetItem( info ); | |
e1e955e1 | 1203 | } |
c801d85f KB |
1204 | |
1205 | void wxListMainWindow::OnMouse( wxMouseEvent &event ) | |
1206 | { | |
92976ab6 | 1207 | if (GetParent()->GetEventHandler()->ProcessEvent( event)) return; |
e3e65dac | 1208 | |
92976ab6 RR |
1209 | if (!m_current) return; |
1210 | if (m_dirty) return; | |
c801d85f | 1211 | |
92976ab6 RR |
1212 | wxClientDC dc(this); |
1213 | PrepareDC(dc); | |
1214 | long x = dc.DeviceToLogicalX( (long)event.GetX() ); | |
1215 | long y = dc.DeviceToLogicalY( (long)event.GetY() ); | |
1216 | ||
51cc4dad | 1217 | /* Did we actually hit an item ? */ |
92976ab6 RR |
1218 | long hitResult = 0; |
1219 | wxNode *node = m_lines.First(); | |
1220 | wxListLineData *line = (wxListLineData *) NULL; | |
1221 | while (node) | |
1222 | { | |
1223 | line = (wxListLineData*)node->Data(); | |
1224 | hitResult = line->IsHit( x, y ); | |
1225 | if (hitResult) break; | |
1226 | line = (wxListLineData *) NULL; | |
1227 | node = node->Next(); | |
1228 | } | |
bd8289c1 | 1229 | |
92976ab6 RR |
1230 | if (!event.Dragging()) |
1231 | m_dragCount = 0; | |
1232 | else | |
1233 | m_dragCount++; | |
bd8289c1 | 1234 | |
92976ab6 RR |
1235 | if (event.Dragging() && (m_dragCount > 3)) |
1236 | { | |
1237 | m_dragCount = 0; | |
1238 | ||
1239 | wxListEvent le( wxEVT_COMMAND_LIST_BEGIN_DRAG, GetParent()->GetId() ); | |
1240 | le.SetEventObject( GetParent() ); | |
1241 | le.m_pointDrag.x = x; | |
1242 | le.m_pointDrag.y = y; | |
1243 | GetParent()->GetEventHandler()->ProcessEvent( le ); | |
1244 | ||
1245 | return; | |
1246 | } | |
bd8289c1 | 1247 | |
92976ab6 | 1248 | if (!line) return; |
bd8289c1 | 1249 | |
92976ab6 RR |
1250 | if (event.ButtonDClick()) |
1251 | { | |
1252 | m_usedKeys = FALSE; | |
1253 | m_lastOnSame = FALSE; | |
1254 | m_renameTimer->Stop(); | |
1255 | ||
435fe83e | 1256 | SendNotify( line, wxEVT_COMMAND_LIST_ITEM_ACTIVATED ); |
92976ab6 RR |
1257 | |
1258 | return; | |
1259 | } | |
bd8289c1 | 1260 | |
92976ab6 | 1261 | if (event.LeftUp() && m_lastOnSame) |
c801d85f | 1262 | { |
92976ab6 RR |
1263 | m_usedKeys = FALSE; |
1264 | if ((line == m_current) && | |
1265 | (hitResult == wxLIST_HITTEST_ONITEMLABEL) && | |
1266 | (m_mode & wxLC_EDIT_LABELS) ) | |
1267 | { | |
1268 | m_renameTimer->Start( 100, TRUE ); | |
1269 | } | |
1270 | m_lastOnSame = FALSE; | |
1271 | return; | |
e1e955e1 | 1272 | } |
bd8289c1 | 1273 | |
92976ab6 | 1274 | if (event.RightDown()) |
b204641e | 1275 | { |
92976ab6 RR |
1276 | SendNotify( line, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK ); |
1277 | return; | |
b204641e | 1278 | } |
92976ab6 RR |
1279 | |
1280 | if (event.MiddleDown()) | |
b204641e | 1281 | { |
92976ab6 RR |
1282 | SendNotify( line, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK ); |
1283 | return; | |
1284 | } | |
1285 | ||
1286 | if (event.LeftDown()) | |
1287 | { | |
1288 | m_usedKeys = FALSE; | |
1289 | wxListLineData *oldCurrent = m_current; | |
1290 | if (m_mode & wxLC_SINGLE_SEL) | |
b204641e | 1291 | { |
92976ab6 RR |
1292 | m_current = line; |
1293 | HilightAll( FALSE ); | |
1294 | m_current->ReverseHilight(); | |
1295 | RefreshLine( m_current ); | |
e1e955e1 | 1296 | } |
92976ab6 | 1297 | else |
b204641e | 1298 | { |
92976ab6 RR |
1299 | if (event.ShiftDown()) |
1300 | { | |
1301 | m_current = line; | |
1302 | m_current->ReverseHilight(); | |
1303 | RefreshLine( m_current ); | |
1304 | } | |
1305 | else if (event.ControlDown()) | |
1306 | { | |
1307 | m_current = line; | |
1308 | ||
1309 | int numOfCurrent = -1; | |
1310 | node = m_lines.First(); | |
1311 | while (node) | |
1312 | { | |
1313 | wxListLineData *test_line = (wxListLineData*)node->Data(); | |
1314 | numOfCurrent++; | |
1315 | if (test_line == oldCurrent) break; | |
1316 | node = node->Next(); | |
1317 | } | |
1318 | ||
1319 | int numOfLine = -1; | |
1320 | node = m_lines.First(); | |
1321 | while (node) | |
1322 | { | |
1323 | wxListLineData *test_line = (wxListLineData*)node->Data(); | |
1324 | numOfLine++; | |
1325 | if (test_line == line) break; | |
1326 | node = node->Next(); | |
1327 | } | |
1328 | ||
1329 | if (numOfLine < numOfCurrent) | |
1330 | { | |
1331 | int i = numOfLine; | |
1332 | numOfLine = numOfCurrent; | |
1333 | numOfCurrent = i; | |
1334 | } | |
1335 | ||
1336 | wxNode *node = m_lines.Nth( numOfCurrent ); | |
1337 | for (int i = 0; i <= numOfLine-numOfCurrent; i++) | |
1338 | { | |
1339 | wxListLineData *test_line= (wxListLineData*)node->Data(); | |
1340 | test_line->Hilight(TRUE); | |
1341 | RefreshLine( test_line ); | |
1342 | node = node->Next(); | |
1343 | } | |
1344 | } | |
1345 | else | |
1346 | { | |
1347 | m_current = line; | |
1348 | HilightAll( FALSE ); | |
1349 | m_current->ReverseHilight(); | |
1350 | RefreshLine( m_current ); | |
1351 | } | |
e1e955e1 | 1352 | } |
92976ab6 RR |
1353 | if (m_current != oldCurrent) |
1354 | { | |
1355 | RefreshLine( oldCurrent ); | |
1356 | UnfocusLine( oldCurrent ); | |
1357 | FocusLine( m_current ); | |
1358 | } | |
1359 | m_lastOnSame = (m_current == oldCurrent); | |
1360 | return; | |
e1e955e1 | 1361 | } |
e1e955e1 | 1362 | } |
c801d85f | 1363 | |
e179bd65 | 1364 | void wxListMainWindow::MoveToFocus() |
c801d85f | 1365 | { |
92976ab6 | 1366 | if (!m_current) return; |
e487524e | 1367 | |
92976ab6 RR |
1368 | int x = 0; |
1369 | int y = 0; | |
1370 | int w = 0; | |
1371 | int h = 0; | |
1372 | m_current->GetExtent( x, y, w, h ); | |
139adb6a | 1373 | |
92976ab6 RR |
1374 | int w_p = 0; |
1375 | int h_p = 0; | |
1376 | GetClientSize( &w_p, &h_p ); | |
139adb6a | 1377 | |
92976ab6 RR |
1378 | if (m_mode & wxLC_REPORT) |
1379 | { | |
92976ab6 RR |
1380 | int y_s = m_yScroll*GetScrollPos( wxVERTICAL ); |
1381 | if ((y > y_s) && (y+h < y_s+h_p)) return; | |
aab3e197 KB |
1382 | if (y-y_s < 5) { Scroll( -1, (y-5-h_p/2)/m_yScroll ); Refresh(); } |
1383 | if (y+h+5 > y_s+h_p) { Scroll( -1, (y+h-h_p/2+h+15)/m_yScroll); Refresh(); } | |
92976ab6 RR |
1384 | } |
1385 | else | |
1386 | { | |
92976ab6 RR |
1387 | int x_s = m_xScroll*GetScrollPos( wxHORIZONTAL ); |
1388 | if ((x > x_s) && (x+w < x_s+w_p)) return; | |
aab3e197 KB |
1389 | if (x-x_s < 5) { Scroll( (x-5)/m_xScroll, -1 ); Refresh(); } |
1390 | if (x+w-5 > x_s+w_p) { Scroll( (x+w-w_p+15)/m_xScroll, -1 ); Refresh(); } | |
92976ab6 | 1391 | } |
e1e955e1 | 1392 | } |
c801d85f KB |
1393 | |
1394 | void wxListMainWindow::OnArrowChar( wxListLineData *newCurrent, bool shiftDown ) | |
1395 | { | |
92976ab6 RR |
1396 | if ((m_mode & wxLC_SINGLE_SEL) || (m_usedKeys == FALSE)) m_current->Hilight( FALSE ); |
1397 | wxListLineData *oldCurrent = m_current; | |
1398 | m_current = newCurrent; | |
1399 | MoveToFocus(); | |
1400 | if (shiftDown || (m_mode & wxLC_SINGLE_SEL)) m_current->Hilight( TRUE ); | |
1401 | RefreshLine( m_current ); | |
1402 | RefreshLine( oldCurrent ); | |
1403 | FocusLine( m_current ); | |
1404 | UnfocusLine( oldCurrent ); | |
e1e955e1 | 1405 | } |
c801d85f | 1406 | |
3dfb93fd RR |
1407 | void wxListMainWindow::OnKeyDown( wxKeyEvent &event ) |
1408 | { | |
1409 | wxWindow *parent = GetParent(); | |
1410 | ||
1411 | /* we propagate the key event up */ | |
1412 | wxKeyEvent ke( wxEVT_KEY_DOWN ); | |
1413 | ke.m_shiftDown = event.m_shiftDown; | |
1414 | ke.m_controlDown = event.m_controlDown; | |
1415 | ke.m_altDown = event.m_altDown; | |
1416 | ke.m_metaDown = event.m_metaDown; | |
1417 | ke.m_keyCode = event.m_keyCode; | |
1418 | ke.m_x = event.m_x; | |
1419 | ke.m_y = event.m_y; | |
1420 | ke.SetEventObject( parent ); | |
1421 | if (parent->GetEventHandler()->ProcessEvent( ke )) return; | |
1422 | ||
1423 | event.Skip(); | |
1424 | } | |
1425 | ||
c801d85f KB |
1426 | void wxListMainWindow::OnChar( wxKeyEvent &event ) |
1427 | { | |
51cc4dad | 1428 | wxWindow *parent = GetParent(); |
435fe83e | 1429 | |
51cc4dad RR |
1430 | /* we send a list_key event up */ |
1431 | wxListEvent le( wxEVT_COMMAND_LIST_KEY_DOWN, GetParent()->GetId() ); | |
1432 | le.m_code = event.KeyCode(); | |
1433 | le.SetEventObject( parent ); | |
1434 | parent->GetEventHandler()->ProcessEvent( le ); | |
1435 | ||
3dfb93fd RR |
1436 | /* we propagate the char event up */ |
1437 | wxKeyEvent ke( wxEVT_CHAR ); | |
51cc4dad RR |
1438 | ke.m_shiftDown = event.m_shiftDown; |
1439 | ke.m_controlDown = event.m_controlDown; | |
1440 | ke.m_altDown = event.m_altDown; | |
1441 | ke.m_metaDown = event.m_metaDown; | |
1442 | ke.m_keyCode = event.m_keyCode; | |
1443 | ke.m_x = event.m_x; | |
1444 | ke.m_y = event.m_y; | |
1445 | ke.SetEventObject( parent ); | |
1446 | if (parent->GetEventHandler()->ProcessEvent( ke )) return; | |
1447 | ||
012a03e0 RR |
1448 | if (event.KeyCode() == WXK_TAB) |
1449 | { | |
1450 | wxNavigationKeyEvent nevent; | |
1451 | nevent.SetDirection( !event.ShiftDown() ); | |
1452 | nevent.SetCurrentFocus( m_parent ); | |
1453 | if (m_parent->GetEventHandler()->ProcessEvent( nevent )) return; | |
1454 | } | |
1455 | ||
51cc4dad RR |
1456 | /* no item -> nothing to do */ |
1457 | if (!m_current) | |
c801d85f | 1458 | { |
51cc4dad RR |
1459 | event.Skip(); |
1460 | return; | |
e1e955e1 | 1461 | } |
51cc4dad RR |
1462 | |
1463 | switch (event.KeyCode()) | |
c801d85f | 1464 | { |
51cc4dad RR |
1465 | case WXK_UP: |
1466 | { | |
1467 | wxNode *node = m_lines.Member( m_current )->Previous(); | |
1468 | if (node) OnArrowChar( (wxListLineData*)node->Data(), event.ShiftDown() ); | |
1469 | break; | |
1470 | } | |
1471 | case WXK_DOWN: | |
1472 | { | |
1473 | wxNode *node = m_lines.Member( m_current )->Next(); | |
1474 | if (node) OnArrowChar( (wxListLineData*)node->Data(), event.ShiftDown() ); | |
1475 | break; | |
1476 | } | |
1477 | case WXK_END: | |
1478 | { | |
1479 | wxNode *node = m_lines.Last(); | |
1480 | OnArrowChar( (wxListLineData*)node->Data(), event.ShiftDown() ); | |
1481 | break; | |
1482 | } | |
1483 | case WXK_HOME: | |
1484 | { | |
1485 | wxNode *node = m_lines.First(); | |
1486 | OnArrowChar( (wxListLineData*)node->Data(), event.ShiftDown() ); | |
1487 | break; | |
1488 | } | |
1489 | case WXK_PRIOR: | |
1490 | { | |
1491 | int steps = 0; | |
1492 | if (m_mode & wxLC_REPORT) | |
1493 | { | |
1494 | steps = m_visibleLines-1; | |
1495 | } | |
1496 | else | |
1497 | { | |
1498 | int pos = 0; | |
1499 | wxNode *node = m_lines.First(); | |
1500 | for (;;) { if (m_current == (wxListLineData*)node->Data()) break; pos++; node = node->Next(); } | |
1501 | steps = pos % m_visibleLines; | |
1502 | } | |
1503 | wxNode *node = m_lines.Member( m_current ); | |
1504 | for (int i = 0; i < steps; i++) if (node->Previous()) node = node->Previous(); | |
1505 | if (node) OnArrowChar( (wxListLineData*)node->Data(), event.ShiftDown() ); | |
1506 | break; | |
1507 | } | |
1508 | case WXK_NEXT: | |
1509 | { | |
1510 | int steps = 0; | |
1511 | if (m_mode & wxLC_REPORT) | |
1512 | { | |
1513 | steps = m_visibleLines-1; | |
1514 | } | |
1515 | else | |
1516 | { | |
1517 | int pos = 0; wxNode *node = m_lines.First(); | |
1518 | for (;;) { if (m_current == (wxListLineData*)node->Data()) break; pos++; node = node->Next(); } | |
1519 | steps = m_visibleLines-(pos % m_visibleLines)-1; | |
1520 | } | |
1521 | wxNode *node = m_lines.Member( m_current ); | |
1522 | for (int i = 0; i < steps; i++) if (node->Next()) node = node->Next(); | |
1523 | if (node) OnArrowChar( (wxListLineData*)node->Data(), event.ShiftDown() ); | |
1524 | break; | |
1525 | } | |
1526 | case WXK_LEFT: | |
1527 | { | |
1528 | if (!(m_mode & wxLC_REPORT)) | |
1529 | { | |
1530 | wxNode *node = m_lines.Member( m_current ); | |
1531 | for (int i = 0; i <m_visibleLines; i++) if (node->Previous()) node = node->Previous(); | |
1532 | if (node) OnArrowChar( (wxListLineData*)node->Data(), event.ShiftDown() ); | |
1533 | } | |
1534 | break; | |
1535 | } | |
1536 | case WXK_RIGHT: | |
1537 | { | |
1538 | if (!(m_mode & wxLC_REPORT)) | |
1539 | { | |
1540 | wxNode *node = m_lines.Member( m_current ); | |
1541 | for (int i = 0; i <m_visibleLines; i++) if (node->Next()) node = node->Next(); | |
1542 | if (node) OnArrowChar( (wxListLineData*)node->Data(), event.ShiftDown() ); | |
1543 | } | |
1544 | break; | |
1545 | } | |
1546 | case WXK_SPACE: | |
1547 | { | |
1548 | m_current->ReverseHilight(); | |
1549 | RefreshLine( m_current ); | |
1550 | break; | |
1551 | } | |
1552 | case WXK_INSERT: | |
1553 | { | |
1554 | if (!(m_mode & wxLC_SINGLE_SEL)) | |
1555 | { | |
1556 | wxListLineData *oldCurrent = m_current; | |
1557 | m_current->ReverseHilight(); | |
1558 | wxNode *node = m_lines.Member( m_current )->Next(); | |
1559 | if (node) m_current = (wxListLineData*)node->Data(); | |
1560 | MoveToFocus(); | |
1561 | RefreshLine( oldCurrent ); | |
1562 | RefreshLine( m_current ); | |
1563 | UnfocusLine( oldCurrent ); | |
1564 | FocusLine( m_current ); | |
1565 | } | |
1566 | break; | |
1567 | } | |
1568 | case WXK_RETURN: | |
1569 | case WXK_EXECUTE: | |
1570 | { | |
1571 | wxListEvent le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED, GetParent()->GetId() ); | |
1572 | le.SetEventObject( GetParent() ); | |
1573 | le.m_itemIndex = GetIndexOfLine( m_current ); | |
1574 | m_current->GetItem( 0, le.m_item ); | |
1575 | GetParent()->GetEventHandler()->ProcessEvent( le ); | |
1576 | break; | |
1577 | } | |
1578 | default: | |
1579 | { | |
1580 | event.Skip(); | |
1581 | return; | |
1582 | } | |
e1e955e1 | 1583 | } |
51cc4dad | 1584 | m_usedKeys = TRUE; |
e1e955e1 | 1585 | } |
c801d85f KB |
1586 | |
1587 | void wxListMainWindow::OnSetFocus( wxFocusEvent &WXUNUSED(event) ) | |
1588 | { | |
63852e78 RR |
1589 | m_hasFocus = TRUE; |
1590 | RefreshLine( m_current ); | |
bd8289c1 | 1591 | |
63852e78 | 1592 | if (!GetParent()) return; |
bd8289c1 | 1593 | |
63852e78 RR |
1594 | wxFocusEvent event( wxEVT_SET_FOCUS, GetParent()->GetId() ); |
1595 | event.SetEventObject( GetParent() ); | |
1596 | GetParent()->GetEventHandler()->ProcessEvent( event ); | |
e1e955e1 | 1597 | } |
c801d85f KB |
1598 | |
1599 | void wxListMainWindow::OnKillFocus( wxFocusEvent &WXUNUSED(event) ) | |
1600 | { | |
63852e78 RR |
1601 | m_hasFocus = FALSE; |
1602 | RefreshLine( m_current ); | |
e1e955e1 | 1603 | } |
c801d85f KB |
1604 | |
1605 | void wxListMainWindow::OnSize( wxSizeEvent &WXUNUSED(event) ) | |
1606 | { | |
1607 | /* | |
1608 | We don't even allow the wxScrolledWindow::AdjustScrollbars() call | |
63852e78 | 1609 | |
c801d85f | 1610 | */ |
e1e955e1 | 1611 | } |
c801d85f | 1612 | |
1e6d9499 | 1613 | void wxListMainWindow::DrawImage( int index, wxDC *dc, int x, int y ) |
c801d85f | 1614 | { |
63852e78 RR |
1615 | if ((m_mode & wxLC_ICON) && (m_normal_image_list)) |
1616 | { | |
1617 | m_normal_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT ); | |
1618 | return; | |
1619 | } | |
1620 | if ((m_mode & wxLC_SMALL_ICON) && (m_small_image_list)) | |
1621 | { | |
1622 | m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT ); | |
1623 | } | |
1624 | if ((m_mode & wxLC_REPORT) && (m_small_image_list)) | |
1625 | { | |
1626 | m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT ); | |
1627 | return; | |
1628 | } | |
e1e955e1 | 1629 | } |
c801d85f KB |
1630 | |
1631 | void wxListMainWindow::GetImageSize( int index, int &width, int &height ) | |
1632 | { | |
63852e78 RR |
1633 | if ((m_mode & wxLC_ICON) && (m_normal_image_list)) |
1634 | { | |
1635 | m_normal_image_list->GetSize( index, width, height ); | |
1636 | return; | |
1637 | } | |
1638 | if ((m_mode & wxLC_SMALL_ICON) && (m_small_image_list)) | |
1639 | { | |
1640 | m_small_image_list->GetSize( index, width, height ); | |
1641 | return; | |
1642 | } | |
1643 | if ((m_mode & wxLC_REPORT) && (m_small_image_list)) | |
1644 | { | |
1645 | m_small_image_list->GetSize( index, width, height ); | |
1646 | return; | |
1647 | } | |
1648 | width = 0; | |
1649 | height = 0; | |
e1e955e1 | 1650 | } |
c801d85f KB |
1651 | |
1652 | int wxListMainWindow::GetTextLength( wxString &s ) | |
1653 | { | |
1e6d9499 | 1654 | wxClientDC dc( this ); |
139adb6a RR |
1655 | long lw = 0; |
1656 | long lh = 0; | |
1657 | dc.GetTextExtent( s, &lw, &lh ); | |
1658 | return lw + 6; | |
e1e955e1 | 1659 | } |
c801d85f KB |
1660 | |
1661 | int wxListMainWindow::GetIndexOfLine( const wxListLineData *line ) | |
1662 | { | |
139adb6a RR |
1663 | int i = 0; |
1664 | wxNode *node = m_lines.First(); | |
1665 | while (node) | |
1666 | { | |
1667 | if (line == (wxListLineData*)node->Data()) return i; | |
1668 | i++; | |
1669 | node = node->Next(); | |
1670 | } | |
1671 | return -1; | |
e1e955e1 | 1672 | } |
c801d85f | 1673 | |
debe6624 | 1674 | void wxListMainWindow::SetImageList( wxImageList *imageList, int which ) |
c801d85f | 1675 | { |
139adb6a RR |
1676 | m_dirty = TRUE; |
1677 | if (which == wxIMAGE_LIST_NORMAL) m_normal_image_list = imageList; | |
1678 | if (which == wxIMAGE_LIST_SMALL) m_small_image_list = imageList; | |
e1e955e1 | 1679 | } |
c801d85f | 1680 | |
debe6624 | 1681 | void wxListMainWindow::SetItemSpacing( int spacing, bool isSmall ) |
c801d85f | 1682 | { |
139adb6a RR |
1683 | m_dirty = TRUE; |
1684 | if (isSmall) | |
1685 | { | |
1686 | m_small_spacing = spacing; | |
1687 | } | |
1688 | else | |
1689 | { | |
1690 | m_normal_spacing = spacing; | |
1691 | } | |
e1e955e1 | 1692 | } |
c801d85f | 1693 | |
debe6624 | 1694 | int wxListMainWindow::GetItemSpacing( bool isSmall ) |
c801d85f | 1695 | { |
139adb6a | 1696 | if (isSmall) return m_small_spacing; else return m_normal_spacing; |
e1e955e1 | 1697 | } |
c801d85f | 1698 | |
debe6624 | 1699 | void wxListMainWindow::SetColumn( int col, wxListItem &item ) |
c801d85f | 1700 | { |
63852e78 RR |
1701 | m_dirty = TRUE; |
1702 | wxNode *node = m_columns.Nth( col ); | |
1703 | if (node) | |
1704 | { | |
1705 | if (item.m_width == wxLIST_AUTOSIZE_USEHEADER) item.m_width = GetTextLength( item.m_text )+7; | |
1706 | wxListHeaderData *column = (wxListHeaderData*)node->Data(); | |
1707 | column->SetItem( item ); | |
1708 | } | |
1709 | wxListCtrl *lc = (wxListCtrl*) GetParent(); | |
1710 | if (lc->m_headerWin) lc->m_headerWin->Refresh(); | |
e1e955e1 | 1711 | } |
c801d85f | 1712 | |
debe6624 | 1713 | void wxListMainWindow::SetColumnWidth( int col, int width ) |
c801d85f | 1714 | { |
63852e78 | 1715 | if (!(m_mode & wxLC_REPORT)) return; |
0208334d | 1716 | |
63852e78 | 1717 | m_dirty = TRUE; |
bd8289c1 | 1718 | |
0180dad6 RR |
1719 | wxNode *node = (wxNode*) NULL; |
1720 | ||
1721 | if (width == wxLIST_AUTOSIZE_USEHEADER) width = 80; | |
1722 | if (width == wxLIST_AUTOSIZE) | |
1723 | { | |
1724 | wxClientDC dc(this); | |
1725 | dc.SetFont( GetFont() ); | |
1726 | int max = 10; | |
1727 | node = m_lines.First(); | |
1728 | while (node) | |
1729 | { | |
1730 | wxListLineData *line = (wxListLineData*)node->Data(); | |
1731 | wxNode *n = line->m_items.Nth( col ); | |
1732 | if (n) | |
1733 | { | |
1734 | wxListItemData *item = (wxListItemData*)n->Data(); | |
1735 | int current = 0, ix = 0, iy = 0; | |
1736 | long lx = 0, ly = 0; | |
1737 | if (item->HasImage()) | |
1738 | { | |
1739 | GetImageSize( item->GetImage(), ix, iy ); | |
1740 | current = ix + 5; | |
1741 | } | |
1742 | if (item->HasText()) | |
1743 | { | |
1744 | wxString str; | |
1745 | item->GetText( str ); | |
1746 | dc.GetTextExtent( str, &lx, &ly ); | |
1747 | current += lx; | |
1748 | } | |
1749 | if (current > max) max = current; | |
1750 | } | |
1751 | node = node->Next(); | |
1752 | } | |
1753 | width = max+10; | |
1754 | } | |
1755 | ||
1756 | node = m_columns.Nth( col ); | |
63852e78 RR |
1757 | if (node) |
1758 | { | |
1759 | wxListHeaderData *column = (wxListHeaderData*)node->Data(); | |
1760 | column->SetWidth( width ); | |
1761 | } | |
bd8289c1 | 1762 | |
63852e78 RR |
1763 | node = m_lines.First(); |
1764 | while (node) | |
0208334d | 1765 | { |
63852e78 RR |
1766 | wxListLineData *line = (wxListLineData*)node->Data(); |
1767 | wxNode *n = line->m_items.Nth( col ); | |
1768 | if (n) | |
1769 | { | |
1770 | wxListItemData *item = (wxListItemData*)n->Data(); | |
1771 | item->SetSize( width, -1 ); | |
1772 | } | |
1773 | node = node->Next(); | |
0208334d | 1774 | } |
bd8289c1 | 1775 | |
63852e78 RR |
1776 | wxListCtrl *lc = (wxListCtrl*) GetParent(); |
1777 | if (lc->m_headerWin) lc->m_headerWin->Refresh(); | |
e1e955e1 | 1778 | } |
c801d85f | 1779 | |
debe6624 | 1780 | void wxListMainWindow::GetColumn( int col, wxListItem &item ) |
c801d85f | 1781 | { |
63852e78 RR |
1782 | wxNode *node = m_columns.Nth( col ); |
1783 | if (node) | |
1784 | { | |
1785 | wxListHeaderData *column = (wxListHeaderData*)node->Data(); | |
1786 | column->GetItem( item ); | |
1787 | } | |
1788 | else | |
1789 | { | |
1790 | item.m_format = 0; | |
1791 | item.m_width = 0; | |
1792 | item.m_text = ""; | |
1793 | item.m_image = 0; | |
1794 | item.m_data = 0; | |
1795 | } | |
e1e955e1 | 1796 | } |
c801d85f | 1797 | |
bd8289c1 | 1798 | int wxListMainWindow::GetColumnWidth( int col ) |
c801d85f | 1799 | { |
92976ab6 RR |
1800 | wxNode *node = m_columns.Nth( col ); |
1801 | if (node) | |
1802 | { | |
1803 | wxListHeaderData *column = (wxListHeaderData*)node->Data(); | |
1804 | return column->GetWidth(); | |
1805 | } | |
1806 | else | |
1807 | { | |
1808 | return 0; | |
1809 | } | |
e1e955e1 | 1810 | } |
c801d85f | 1811 | |
e179bd65 | 1812 | int wxListMainWindow::GetColumnCount() |
c801d85f | 1813 | { |
92976ab6 | 1814 | return m_columns.Number(); |
e1e955e1 | 1815 | } |
c801d85f | 1816 | |
e179bd65 | 1817 | int wxListMainWindow::GetCountPerPage() |
c801d85f | 1818 | { |
92976ab6 | 1819 | return m_visibleLines; |
e1e955e1 | 1820 | } |
c801d85f KB |
1821 | |
1822 | void wxListMainWindow::SetItem( wxListItem &item ) | |
1823 | { | |
92976ab6 RR |
1824 | m_dirty = TRUE; |
1825 | wxNode *node = m_lines.Nth( item.m_itemId ); | |
1826 | if (node) | |
1827 | { | |
1828 | wxListLineData *line = (wxListLineData*)node->Data(); | |
1829 | if (m_mode & wxLC_REPORT) item.m_width = GetColumnWidth( item.m_col )-3; | |
1830 | line->SetItem( item.m_col, item ); | |
1831 | } | |
e1e955e1 | 1832 | } |
c801d85f | 1833 | |
debe6624 | 1834 | void wxListMainWindow::SetItemState( long item, long state, long stateMask ) |
c801d85f | 1835 | { |
92976ab6 | 1836 | // m_dirty = TRUE; no recalcs needed |
bd8289c1 | 1837 | |
92976ab6 | 1838 | wxListLineData *oldCurrent = m_current; |
bd8289c1 | 1839 | |
92976ab6 | 1840 | if (stateMask & wxLIST_STATE_FOCUSED) |
c801d85f | 1841 | { |
92976ab6 RR |
1842 | wxNode *node = m_lines.Nth( item ); |
1843 | if (node) | |
1844 | { | |
1845 | wxListLineData *line = (wxListLineData*)node->Data(); | |
1846 | UnfocusLine( m_current ); | |
1847 | m_current = line; | |
1848 | FocusLine( m_current ); | |
1849 | RefreshLine( m_current ); | |
00a39542 | 1850 | if (oldCurrent) RefreshLine( oldCurrent ); |
92976ab6 | 1851 | } |
e1e955e1 | 1852 | } |
bd8289c1 | 1853 | |
92976ab6 | 1854 | if (stateMask & wxLIST_STATE_SELECTED) |
c801d85f | 1855 | { |
92976ab6 RR |
1856 | bool on = state & wxLIST_STATE_SELECTED; |
1857 | if (!on && (m_mode & wxLC_SINGLE_SEL)) return; | |
1858 | ||
1859 | wxNode *node = m_lines.Nth( item ); | |
1860 | if (node) | |
1861 | { | |
1862 | wxListLineData *line = (wxListLineData*)node->Data(); | |
1863 | if (m_mode & wxLC_SINGLE_SEL) | |
1864 | { | |
1865 | UnfocusLine( m_current ); | |
1866 | m_current = line; | |
1867 | FocusLine( m_current ); | |
00a39542 | 1868 | if (oldCurrent) oldCurrent->Hilight( FALSE ); |
92976ab6 | 1869 | RefreshLine( m_current ); |
00a39542 | 1870 | if (oldCurrent) RefreshLine( oldCurrent ); |
92976ab6 RR |
1871 | } |
1872 | bool on = state & wxLIST_STATE_SELECTED; | |
139adb6a RR |
1873 | if (on != line->IsHilighted()) |
1874 | { | |
1875 | line->Hilight( on ); | |
1876 | RefreshLine( line ); | |
1877 | } | |
92976ab6 | 1878 | } |
e1e955e1 | 1879 | } |
e1e955e1 | 1880 | } |
c801d85f | 1881 | |
debe6624 | 1882 | int wxListMainWindow::GetItemState( long item, long stateMask ) |
c801d85f | 1883 | { |
92976ab6 RR |
1884 | int ret = wxLIST_STATE_DONTCARE; |
1885 | if (stateMask & wxLIST_STATE_FOCUSED) | |
c801d85f | 1886 | { |
92976ab6 RR |
1887 | wxNode *node = m_lines.Nth( item ); |
1888 | if (node) | |
1889 | { | |
1890 | wxListLineData *line = (wxListLineData*)node->Data(); | |
1891 | if (line == m_current) ret |= wxLIST_STATE_FOCUSED; | |
1892 | } | |
e1e955e1 | 1893 | } |
92976ab6 | 1894 | if (stateMask & wxLIST_STATE_SELECTED) |
c801d85f | 1895 | { |
92976ab6 RR |
1896 | wxNode *node = m_lines.Nth( item ); |
1897 | if (node) | |
1898 | { | |
1899 | wxListLineData *line = (wxListLineData*)node->Data(); | |
1900 | if (line->IsHilighted()) ret |= wxLIST_STATE_FOCUSED; | |
1901 | } | |
e1e955e1 | 1902 | } |
92976ab6 | 1903 | return ret; |
e1e955e1 | 1904 | } |
c801d85f KB |
1905 | |
1906 | void wxListMainWindow::GetItem( wxListItem &item ) | |
1907 | { | |
92976ab6 RR |
1908 | wxNode *node = m_lines.Nth( item.m_itemId ); |
1909 | if (node) | |
1910 | { | |
1911 | wxListLineData *line = (wxListLineData*)node->Data(); | |
1912 | line->GetItem( item.m_col, item ); | |
1913 | } | |
1914 | else | |
1915 | { | |
1916 | item.m_mask = 0; | |
1917 | item.m_text = ""; | |
1918 | item.m_image = 0; | |
1919 | item.m_data = 0; | |
1920 | } | |
e1e955e1 | 1921 | } |
c801d85f | 1922 | |
e179bd65 | 1923 | int wxListMainWindow::GetItemCount() |
c801d85f | 1924 | { |
92976ab6 | 1925 | return m_lines.Number(); |
e1e955e1 | 1926 | } |
c801d85f | 1927 | |
0a240683 | 1928 | void wxListMainWindow::GetItemRect( long index, wxRect &rect ) |
c801d85f | 1929 | { |
92976ab6 RR |
1930 | wxNode *node = m_lines.Nth( index ); |
1931 | if (node) | |
1932 | { | |
1933 | wxListLineData *line = (wxListLineData*)node->Data(); | |
1934 | line->GetRect( rect ); | |
1935 | } | |
1936 | else | |
1937 | { | |
1938 | rect.x = 0; | |
1939 | rect.y = 0; | |
1940 | rect.width = 0; | |
1941 | rect.height = 0; | |
1942 | } | |
e1e955e1 | 1943 | } |
c801d85f | 1944 | |
e3e65dac RR |
1945 | bool wxListMainWindow::GetItemPosition(long item, wxPoint& pos) |
1946 | { | |
92976ab6 RR |
1947 | wxNode *node = m_lines.Nth( item ); |
1948 | if (node) | |
1949 | { | |
0a240683 | 1950 | wxRect rect; |
92976ab6 RR |
1951 | wxListLineData *line = (wxListLineData*)node->Data(); |
1952 | line->GetRect( rect ); | |
1953 | pos.x = rect.x; | |
1954 | pos.y = rect.y; | |
1955 | } | |
1956 | else | |
1957 | { | |
1958 | pos.x = 0; | |
1959 | pos.y = 0; | |
1960 | } | |
1961 | return TRUE; | |
e1e955e1 | 1962 | } |
e3e65dac | 1963 | |
e179bd65 | 1964 | int wxListMainWindow::GetSelectedItemCount() |
c801d85f | 1965 | { |
92976ab6 RR |
1966 | int ret = 0; |
1967 | wxNode *node = m_lines.First(); | |
1968 | while (node) | |
1969 | { | |
1970 | wxListLineData *line = (wxListLineData*)node->Data(); | |
1971 | if (line->IsHilighted()) ret++; | |
1972 | node = node->Next(); | |
1973 | } | |
1974 | return ret; | |
e1e955e1 | 1975 | } |
c801d85f | 1976 | |
debe6624 | 1977 | void wxListMainWindow::SetMode( long mode ) |
c801d85f | 1978 | { |
92976ab6 RR |
1979 | m_dirty = TRUE; |
1980 | m_mode = mode; | |
bd8289c1 | 1981 | |
92976ab6 | 1982 | DeleteEverything(); |
bd8289c1 | 1983 | |
92976ab6 RR |
1984 | if (m_mode & wxLC_REPORT) |
1985 | { | |
1986 | m_xScroll = 0; | |
1987 | m_yScroll = 15; | |
1988 | } | |
1989 | else | |
1990 | { | |
1991 | m_xScroll = 15; | |
1992 | m_yScroll = 0; | |
1993 | } | |
e1e955e1 | 1994 | } |
c801d85f | 1995 | |
e179bd65 | 1996 | long wxListMainWindow::GetMode() const |
c801d85f | 1997 | { |
63852e78 | 1998 | return m_mode; |
e1e955e1 | 1999 | } |
c801d85f | 2000 | |
e179bd65 | 2001 | void wxListMainWindow::CalculatePositions() |
c801d85f | 2002 | { |
92976ab6 | 2003 | if (!m_lines.First()) return; |
e487524e | 2004 | |
1e6d9499 | 2005 | wxClientDC dc( this ); |
92976ab6 | 2006 | dc.SetFont( GetFont() ); |
c801d85f | 2007 | |
92976ab6 RR |
2008 | int iconSpacing = 0; |
2009 | if (m_mode & wxLC_ICON) iconSpacing = m_normal_spacing; | |
2010 | if (m_mode & wxLC_SMALL_ICON) iconSpacing = m_small_spacing; | |
e487524e | 2011 | |
92976ab6 RR |
2012 | // we take the first line (which also can be an icon or |
2013 | // an a text item in wxLC_ICON and wxLC_LIST modes) to | |
2014 | // measure the size of the line | |
e487524e | 2015 | |
92976ab6 RR |
2016 | int lineWidth = 0; |
2017 | int lineHeight = 0; | |
2018 | int lineSpacing = 0; | |
c801d85f | 2019 | |
92976ab6 RR |
2020 | wxListLineData *line = (wxListLineData*)m_lines.First()->Data(); |
2021 | line->CalculateSize( &dc, iconSpacing ); | |
2022 | int dummy = 0; | |
2023 | line->GetSize( dummy, lineSpacing ); | |
2024 | lineSpacing += 4; | |
bd8289c1 | 2025 | |
92976ab6 RR |
2026 | int clientWidth = 0; |
2027 | int clientHeight = 0; | |
bd8289c1 | 2028 | |
92976ab6 | 2029 | if (m_mode & wxLC_REPORT) |
c801d85f | 2030 | { |
92976ab6 RR |
2031 | int x = 4; |
2032 | int y = 1; | |
2033 | int entireHeight = m_lines.Number() * lineSpacing + 2; | |
2034 | int scroll_pos = GetScrollPos( wxVERTICAL ); | |
8b53e5a2 | 2035 | SetScrollbars( m_xScroll, m_yScroll, 0, (entireHeight+15) / m_yScroll, 0, scroll_pos, TRUE ); |
92976ab6 RR |
2036 | GetClientSize( &clientWidth, &clientHeight ); |
2037 | ||
2038 | wxNode* node = m_lines.First(); | |
2039 | while (node) | |
2040 | { | |
2041 | wxListLineData *line = (wxListLineData*)node->Data(); | |
2042 | line->CalculateSize( &dc, iconSpacing ); | |
2043 | line->SetPosition( &dc, x, y, clientWidth ); | |
2044 | int col_x = 2; | |
2045 | for (int i = 0; i < GetColumnCount(); i++) | |
2046 | { | |
2047 | line->SetColumnPosition( i, col_x ); | |
2048 | col_x += GetColumnWidth( i ); | |
2049 | } | |
2050 | y += lineSpacing; // one pixel blank line between items | |
2051 | node = node->Next(); | |
2052 | } | |
139adb6a | 2053 | m_visibleLines = clientHeight / lineSpacing; |
e1e955e1 | 2054 | } |
92976ab6 RR |
2055 | else |
2056 | { | |
2057 | // at first we try without any scrollbar. if the items don't | |
2058 | // fit into the window, we recalculate after subtracting an | |
2059 | // approximated 15 pt for the horizontal scrollbar | |
e487524e | 2060 | |
92976ab6 RR |
2061 | GetSize( &clientWidth, &clientHeight ); |
2062 | clientHeight -= 4; // sunken frame | |
bd8289c1 | 2063 | |
92976ab6 | 2064 | int entireWidth = 0; |
bd8289c1 | 2065 | |
92976ab6 | 2066 | for (int tries = 0; tries < 2; tries++) |
e487524e | 2067 | { |
92976ab6 RR |
2068 | entireWidth = 0; |
2069 | int x = 5; // painting is done at x-2 | |
2070 | int y = 5; // painting is done at y-2 | |
2071 | int maxWidth = 0; | |
2072 | wxNode *node = m_lines.First(); | |
2073 | while (node) | |
2074 | { | |
2075 | wxListLineData *line = (wxListLineData*)node->Data(); | |
2076 | line->CalculateSize( &dc, iconSpacing ); | |
2077 | line->SetPosition( &dc, x, y, clientWidth ); | |
2078 | line->GetSize( lineWidth, lineHeight ); | |
2079 | if (lineWidth > maxWidth) maxWidth = lineWidth; | |
2080 | y += lineSpacing; | |
8b53e5a2 | 2081 | if (y+lineSpacing-6 >= clientHeight) // -6 for earlier "line breaking" |
92976ab6 RR |
2082 | { |
2083 | y = 5; | |
8b53e5a2 RR |
2084 | x += maxWidth+6; |
2085 | entireWidth += maxWidth+6; | |
92976ab6 RR |
2086 | maxWidth = 0; |
2087 | } | |
2088 | node = node->Next(); | |
2089 | if (!node) entireWidth += maxWidth; | |
2090 | if ((tries == 0) && (entireWidth > clientWidth)) | |
2091 | { | |
2092 | clientHeight -= 15; // scrollbar height | |
2093 | break; | |
2094 | } | |
2095 | if (!node) tries = 1; // everything fits, no second try required | |
2096 | } | |
e487524e | 2097 | } |
8b53e5a2 | 2098 | m_visibleLines = (clientHeight+6) / (lineSpacing); // +6 for earlier "line breaking" |
92976ab6 RR |
2099 | |
2100 | int scroll_pos = GetScrollPos( wxHORIZONTAL ); | |
2101 | SetScrollbars( m_xScroll, m_yScroll, (entireWidth+15) / m_xScroll, 0, scroll_pos, 0, TRUE ); | |
e1e955e1 | 2102 | } |
e1e955e1 | 2103 | } |
c801d85f KB |
2104 | |
2105 | void wxListMainWindow::RealizeChanges( void ) | |
2106 | { | |
92976ab6 RR |
2107 | if (!m_current) |
2108 | { | |
2109 | wxNode *node = m_lines.First(); | |
2110 | if (node) m_current = (wxListLineData*)node->Data(); | |
2111 | } | |
2112 | if (m_current) | |
2113 | { | |
2114 | FocusLine( m_current ); | |
2115 | if (m_mode & wxLC_SINGLE_SEL) m_current->Hilight( TRUE ); | |
2116 | } | |
e1e955e1 | 2117 | } |
c801d85f | 2118 | |
debe6624 | 2119 | long wxListMainWindow::GetNextItem( long item, int WXUNUSED(geometry), int state ) |
c801d85f | 2120 | { |
63852e78 RR |
2121 | long ret = 0; |
2122 | if (item > 0) ret = item; | |
d9081042 | 2123 | if(ret >= GetItemCount()) return -1; |
63852e78 RR |
2124 | wxNode *node = m_lines.Nth( ret ); |
2125 | while (node) | |
2126 | { | |
2127 | wxListLineData *line = (wxListLineData*)node->Data(); | |
2128 | if ((state & wxLIST_STATE_FOCUSED) && (line == m_current)) return ret; | |
2129 | if ((state & wxLIST_STATE_SELECTED) && (line->IsHilighted())) return ret; | |
2130 | if (!state) return ret; | |
2131 | ret++; | |
2132 | node = node->Next(); | |
2133 | } | |
2134 | return -1; | |
e1e955e1 | 2135 | } |
c801d85f | 2136 | |
debe6624 | 2137 | void wxListMainWindow::DeleteItem( long index ) |
c801d85f | 2138 | { |
63852e78 RR |
2139 | m_dirty = TRUE; |
2140 | wxNode *node = m_lines.Nth( index ); | |
2141 | if (node) | |
2142 | { | |
2143 | wxListLineData *line = (wxListLineData*)node->Data(); | |
2144 | if (m_current == line) m_current = (wxListLineData *) NULL; | |
2145 | DeleteLine( line ); | |
2146 | m_lines.DeleteNode( node ); | |
2147 | } | |
e1e955e1 | 2148 | } |
c801d85f | 2149 | |
debe6624 | 2150 | void wxListMainWindow::DeleteColumn( int col ) |
c801d85f | 2151 | { |
5b077d48 | 2152 | wxCHECK_RET( col < (int)m_columns.GetCount(), |
87138c52 | 2153 | _T("attempting to delete inexistent column in wxListView") ); |
bd8289c1 | 2154 | |
5b077d48 RR |
2155 | m_dirty = TRUE; |
2156 | wxNode *node = m_columns.Nth( col ); | |
2157 | if (node) m_columns.DeleteNode( node ); | |
e1e955e1 | 2158 | } |
c801d85f KB |
2159 | |
2160 | void wxListMainWindow::DeleteAllItems( void ) | |
2161 | { | |
5b077d48 RR |
2162 | m_dirty = TRUE; |
2163 | m_current = (wxListLineData *) NULL; | |
2164 | wxNode *node = m_lines.First(); | |
2165 | while (node) | |
2166 | { | |
2167 | wxListLineData *line = (wxListLineData*)node->Data(); | |
2168 | DeleteLine( line ); | |
2169 | node = node->Next(); | |
2170 | } | |
2171 | m_lines.Clear(); | |
e1e955e1 | 2172 | } |
c801d85f KB |
2173 | |
2174 | void wxListMainWindow::DeleteEverything( void ) | |
2175 | { | |
5b077d48 RR |
2176 | m_dirty = TRUE; |
2177 | m_current = (wxListLineData *) NULL; | |
2178 | wxNode *node = m_lines.First(); | |
2179 | while (node) | |
2180 | { | |
2181 | wxListLineData *line = (wxListLineData*)node->Data(); | |
2182 | DeleteLine( line ); | |
2183 | node = node->Next(); | |
2184 | } | |
2185 | m_lines.Clear(); | |
2186 | m_current = (wxListLineData *) NULL; | |
2187 | m_columns.Clear(); | |
e1e955e1 | 2188 | } |
c801d85f | 2189 | |
debe6624 | 2190 | void wxListMainWindow::EnsureVisible( long index ) |
c801d85f | 2191 | { |
5b077d48 RR |
2192 | wxListLineData *oldCurrent = m_current; |
2193 | m_current = (wxListLineData *) NULL; | |
2194 | int i = index; | |
2195 | wxNode *node = m_lines.Nth( i ); | |
2196 | if (node) m_current = (wxListLineData*)node->Data(); | |
2197 | if (m_current) MoveToFocus(); | |
2198 | m_current = oldCurrent; | |
e1e955e1 | 2199 | } |
c801d85f | 2200 | |
debe6624 | 2201 | long wxListMainWindow::FindItem(long start, const wxString& str, bool WXUNUSED(partial) ) |
c801d85f | 2202 | { |
5b077d48 RR |
2203 | long pos = start; |
2204 | wxString tmp = str; | |
2205 | if (pos < 0) pos = 0; | |
2206 | wxNode *node = m_lines.Nth( pos ); | |
2207 | while (node) | |
2208 | { | |
2209 | wxListLineData *line = (wxListLineData*)node->Data(); | |
2210 | wxString s = ""; | |
2211 | line->GetText( 0, s ); | |
2212 | if (s == tmp) return pos; | |
2213 | node = node->Next(); | |
2214 | pos++; | |
2215 | } | |
2216 | return -1; | |
e1e955e1 | 2217 | } |
c801d85f | 2218 | |
debe6624 | 2219 | long wxListMainWindow::FindItem(long start, long data) |
c801d85f | 2220 | { |
5b077d48 RR |
2221 | long pos = start; |
2222 | if (pos < 0) pos = 0; | |
2223 | wxNode *node = m_lines.Nth( pos ); | |
2224 | while (node) | |
2225 | { | |
2226 | wxListLineData *line = (wxListLineData*)node->Data(); | |
2227 | wxListItem item; | |
2228 | line->GetItem( 0, item ); | |
2229 | if (item.m_data == data) return pos; | |
2230 | node = node->Next(); | |
2231 | pos++; | |
2232 | } | |
2233 | return -1; | |
e1e955e1 | 2234 | } |
c801d85f | 2235 | |
debe6624 | 2236 | long wxListMainWindow::HitTest( int x, int y, int &flags ) |
c801d85f | 2237 | { |
5b077d48 RR |
2238 | wxNode *node = m_lines.First(); |
2239 | int count = 0; | |
2240 | while (node) | |
c801d85f | 2241 | { |
5b077d48 RR |
2242 | wxListLineData *line = (wxListLineData*)node->Data(); |
2243 | long ret = line->IsHit( x, y ); | |
2244 | if (ret & flags) | |
2245 | { | |
2246 | flags = ret; | |
2247 | return count; | |
2248 | } | |
2249 | node = node->Next(); | |
2250 | count++; | |
e1e955e1 | 2251 | } |
5b077d48 | 2252 | return -1; |
e1e955e1 | 2253 | } |
c801d85f KB |
2254 | |
2255 | void wxListMainWindow::InsertItem( wxListItem &item ) | |
2256 | { | |
5b077d48 RR |
2257 | m_dirty = TRUE; |
2258 | int mode = 0; | |
2259 | if (m_mode & wxLC_REPORT) mode = wxLC_REPORT; | |
2260 | else if (m_mode & wxLC_LIST) mode = wxLC_LIST; | |
2261 | else if (m_mode & wxLC_ICON) mode = wxLC_ICON; | |
2262 | else if (m_mode & wxLC_SMALL_ICON) mode = wxLC_ICON; // no typo | |
2263 | ||
2264 | wxListLineData *line = new wxListLineData( this, mode, m_hilightBrush ); | |
2265 | ||
2266 | if (m_mode & wxLC_REPORT) | |
2267 | { | |
2268 | line->InitItems( GetColumnCount() ); | |
2269 | item.m_width = GetColumnWidth( 0 )-3; | |
2270 | } | |
2271 | else | |
2272 | { | |
2273 | line->InitItems( 1 ); | |
2274 | } | |
2275 | ||
2276 | line->SetItem( 0, item ); | |
2277 | if ((item.m_itemId >= 0) && (item.m_itemId < (int)m_lines.GetCount())) | |
2278 | { | |
2279 | wxNode *node = m_lines.Nth( item.m_itemId ); | |
2280 | if (node) m_lines.Insert( node, line ); | |
2281 | } | |
2282 | else | |
2283 | { | |
2284 | m_lines.Append( line ); | |
2285 | } | |
e1e955e1 | 2286 | } |
c801d85f | 2287 | |
debe6624 | 2288 | void wxListMainWindow::InsertColumn( long col, wxListItem &item ) |
c801d85f | 2289 | { |
5b077d48 RR |
2290 | m_dirty = TRUE; |
2291 | if (m_mode & wxLC_REPORT) | |
3db7be80 | 2292 | { |
5b077d48 RR |
2293 | if (item.m_width == wxLIST_AUTOSIZE_USEHEADER) item.m_width = GetTextLength( item.m_text ); |
2294 | wxListHeaderData *column = new wxListHeaderData( item ); | |
2295 | if ((col >= 0) && (col < (int)m_columns.GetCount())) | |
2296 | { | |
2297 | wxNode *node = m_columns.Nth( col ); | |
2298 | if (node) | |
2299 | m_columns.Insert( node, column ); | |
2300 | } | |
2301 | else | |
2302 | { | |
2303 | m_columns.Append( column ); | |
2304 | } | |
3db7be80 | 2305 | } |
e1e955e1 | 2306 | } |
c801d85f KB |
2307 | |
2308 | wxListCtrlCompare list_ctrl_compare_func_2; | |
2309 | long list_ctrl_compare_data; | |
2310 | ||
2311 | int list_ctrl_compare_func_1( const void *arg1, const void *arg2 ) | |
2312 | { | |
5b077d48 RR |
2313 | wxListLineData *line1 = *((wxListLineData**)arg1); |
2314 | wxListLineData *line2 = *((wxListLineData**)arg2); | |
2315 | wxListItem item; | |
2316 | line1->GetItem( 0, item ); | |
2317 | long data1 = item.m_data; | |
2318 | line2->GetItem( 0, item ); | |
2319 | long data2 = item.m_data; | |
2320 | return list_ctrl_compare_func_2( data1, data2, list_ctrl_compare_data ); | |
e1e955e1 | 2321 | } |
c801d85f KB |
2322 | |
2323 | void wxListMainWindow::SortItems( wxListCtrlCompare fn, long data ) | |
2324 | { | |
5b077d48 RR |
2325 | list_ctrl_compare_func_2 = fn; |
2326 | list_ctrl_compare_data = data; | |
2327 | m_lines.Sort( list_ctrl_compare_func_1 ); | |
e1e955e1 | 2328 | } |
c801d85f | 2329 | |
c801d85f KB |
2330 | // ------------------------------------------------------------------------------------- |
2331 | // wxListItem | |
2332 | // ------------------------------------------------------------------------------------- | |
2333 | ||
2334 | IMPLEMENT_DYNAMIC_CLASS(wxListItem, wxObject) | |
2335 | ||
2336 | wxListItem::wxListItem(void) | |
2337 | { | |
63852e78 RR |
2338 | m_mask = 0; |
2339 | m_itemId = 0; | |
2340 | m_col = 0; | |
2341 | m_state = 0; | |
2342 | m_stateMask = 0; | |
2343 | m_image = 0; | |
2344 | m_data = 0; | |
2345 | m_format = wxLIST_FORMAT_CENTRE; | |
2346 | m_width = 0; | |
2347 | m_colour = wxBLACK; | |
c801d85f KB |
2348 | } |
2349 | ||
2350 | // ------------------------------------------------------------------------------------- | |
2351 | // wxListEvent | |
2352 | // ------------------------------------------------------------------------------------- | |
2353 | ||
92976ab6 | 2354 | IMPLEMENT_DYNAMIC_CLASS(wxListEvent, wxNotifyEvent) |
c801d85f | 2355 | |
8f79098a | 2356 | wxListEvent::wxListEvent( wxEventType commandType, int id ): |
92976ab6 | 2357 | wxNotifyEvent( commandType, id ) |
c801d85f | 2358 | { |
5b077d48 RR |
2359 | m_code = 0; |
2360 | m_itemIndex = 0; | |
2361 | m_oldItemIndex = 0; | |
2362 | m_col = 0; | |
2363 | m_cancelled = FALSE; | |
2364 | m_pointDrag.x = 0; | |
2365 | m_pointDrag.y = 0; | |
e1e955e1 | 2366 | } |
c801d85f KB |
2367 | |
2368 | // ------------------------------------------------------------------------------------- | |
2369 | // wxListCtrl | |
2370 | // ------------------------------------------------------------------------------------- | |
2371 | ||
2372 | IMPLEMENT_DYNAMIC_CLASS(wxListCtrl, wxControl) | |
2373 | ||
2374 | BEGIN_EVENT_TABLE(wxListCtrl,wxControl) | |
2375 | EVT_SIZE (wxListCtrl::OnSize) | |
53010e52 | 2376 | EVT_IDLE (wxListCtrl::OnIdle) |
c801d85f KB |
2377 | END_EVENT_TABLE() |
2378 | ||
2379 | wxListCtrl::wxListCtrl(void) | |
2380 | { | |
5b077d48 RR |
2381 | m_imageListNormal = (wxImageList *) NULL; |
2382 | m_imageListSmall = (wxImageList *) NULL; | |
2383 | m_imageListState = (wxImageList *) NULL; | |
2384 | m_mainWin = (wxListMainWindow*) NULL; | |
2385 | m_headerWin = (wxListHeaderWindow*) NULL; | |
c801d85f KB |
2386 | } |
2387 | ||
c801d85f KB |
2388 | wxListCtrl::~wxListCtrl(void) |
2389 | { | |
2390 | } | |
2391 | ||
bd8289c1 | 2392 | bool wxListCtrl::Create( wxWindow *parent, wxWindowID id, |
debe6624 | 2393 | const wxPoint &pos, const wxSize &size, |
bd8289c1 | 2394 | long style, const wxValidator &validator, |
32e9da8b | 2395 | const wxString &name ) |
c801d85f | 2396 | { |
5b077d48 RR |
2397 | m_imageListNormal = (wxImageList *) NULL; |
2398 | m_imageListSmall = (wxImageList *) NULL; | |
2399 | m_imageListState = (wxImageList *) NULL; | |
2400 | m_mainWin = (wxListMainWindow*) NULL; | |
2401 | m_headerWin = (wxListHeaderWindow*) NULL; | |
bd8289c1 | 2402 | |
5b077d48 | 2403 | long s = style; |
bd8289c1 | 2404 | |
5b077d48 RR |
2405 | if ((s & wxLC_REPORT == 0) && |
2406 | (s & wxLC_LIST == 0) && | |
2407 | (s & wxLC_ICON == 0)) | |
2408 | { | |
2409 | s = s | wxLC_LIST; | |
2410 | } | |
bd8289c1 | 2411 | |
5b077d48 | 2412 | bool ret = wxControl::Create( parent, id, pos, size, s, name ); |
bd8289c1 | 2413 | |
ce4169a4 | 2414 | #if wxUSE_VALIDATORS |
5b077d48 | 2415 | SetValidator( validator ); |
ce4169a4 | 2416 | #endif |
907789a0 | 2417 | |
5b077d48 | 2418 | if (s & wxSUNKEN_BORDER) s -= wxSUNKEN_BORDER; |
bd8289c1 | 2419 | |
5b077d48 | 2420 | m_mainWin = new wxListMainWindow( this, -1, wxPoint(0,0), size, s ); |
bd8289c1 | 2421 | |
f03fc89f | 2422 | if (HasFlag(wxLC_REPORT)) |
5b077d48 RR |
2423 | m_headerWin = new wxListHeaderWindow( this, -1, m_mainWin, wxPoint(0,0), wxSize(size.x,23), wxTAB_TRAVERSAL ); |
2424 | else | |
2425 | m_headerWin = (wxListHeaderWindow *) NULL; | |
bd8289c1 | 2426 | |
58dea4b0 RR |
2427 | SetBackgroundColour( *wxWHITE ); |
2428 | ||
5b077d48 | 2429 | return ret; |
e1e955e1 | 2430 | } |
c801d85f KB |
2431 | |
2432 | void wxListCtrl::OnSize( wxSizeEvent &WXUNUSED(event) ) | |
2433 | { | |
5b077d48 | 2434 | /* handled in OnIdle */ |
bd8289c1 | 2435 | |
5b077d48 | 2436 | if (m_mainWin) m_mainWin->m_dirty = TRUE; |
e1e955e1 | 2437 | } |
c801d85f | 2438 | |
debe6624 | 2439 | void wxListCtrl::SetSingleStyle( long style, bool add ) |
c801d85f | 2440 | { |
f03fc89f | 2441 | long flag = GetWindowStyle(); |
bd8289c1 | 2442 | |
5b077d48 RR |
2443 | if (add) |
2444 | { | |
2445 | if (style & wxLC_MASK_TYPE) flag = flag & ~wxLC_MASK_TYPE; | |
2446 | if (style & wxLC_MASK_ALIGN) flag = flag & ~wxLC_MASK_ALIGN; | |
2447 | if (style & wxLC_MASK_SORT) flag = flag & ~wxLC_MASK_SORT; | |
2448 | } | |
c801d85f | 2449 | |
5b077d48 RR |
2450 | if (add) |
2451 | { | |
2452 | flag |= style; | |
2453 | } | |
2454 | else | |
2455 | { | |
2456 | if (flag & style) flag -= style; | |
2457 | } | |
bd8289c1 | 2458 | |
5b077d48 | 2459 | SetWindowStyleFlag( flag ); |
e1e955e1 | 2460 | } |
c801d85f | 2461 | |
debe6624 | 2462 | void wxListCtrl::SetWindowStyleFlag( long flag ) |
c801d85f | 2463 | { |
121a3581 RR |
2464 | if (m_mainWin) |
2465 | { | |
2466 | m_mainWin->DeleteEverything(); | |
c801d85f | 2467 | |
121a3581 RR |
2468 | int width = 0; |
2469 | int height = 0; | |
2470 | GetClientSize( &width, &height ); | |
c801d85f | 2471 | |
121a3581 | 2472 | m_mainWin->SetMode( flag ); |
bd8289c1 | 2473 | |
121a3581 | 2474 | if (flag & wxLC_REPORT) |
5b077d48 | 2475 | { |
121a3581 | 2476 | if (!HasFlag(wxLC_REPORT)) |
5b077d48 | 2477 | { |
121a3581 RR |
2478 | if (!m_headerWin) |
2479 | { | |
2480 | m_headerWin = new wxListHeaderWindow( this, -1, m_mainWin, | |
2481 | wxPoint(0,0), wxSize(width,23), wxTAB_TRAVERSAL ); | |
2482 | } | |
2483 | else | |
2484 | { | |
2485 | m_headerWin->Show( TRUE ); | |
2486 | } | |
5b077d48 RR |
2487 | } |
2488 | } | |
121a3581 | 2489 | else |
5b077d48 | 2490 | { |
121a3581 RR |
2491 | if (HasFlag(wxLC_REPORT)) |
2492 | { | |
2493 | m_headerWin->Show( FALSE ); | |
2494 | } | |
2495 | } | |
e1e955e1 | 2496 | } |
121a3581 | 2497 | |
5b077d48 | 2498 | wxWindow::SetWindowStyleFlag( flag ); |
e1e955e1 | 2499 | } |
c801d85f | 2500 | |
e487524e | 2501 | bool wxListCtrl::GetColumn(int col, wxListItem &item) const |
c801d85f | 2502 | { |
5b077d48 RR |
2503 | m_mainWin->GetColumn( col, item ); |
2504 | return TRUE; | |
e1e955e1 | 2505 | } |
c801d85f | 2506 | |
debe6624 | 2507 | bool wxListCtrl::SetColumn( int col, wxListItem& item ) |
c801d85f | 2508 | { |
5b077d48 RR |
2509 | m_mainWin->SetColumn( col, item ); |
2510 | return TRUE; | |
e1e955e1 | 2511 | } |
c801d85f | 2512 | |
e487524e | 2513 | int wxListCtrl::GetColumnWidth( int col ) const |
c801d85f | 2514 | { |
5b077d48 | 2515 | return m_mainWin->GetColumnWidth( col ); |
e1e955e1 | 2516 | } |
c801d85f | 2517 | |
debe6624 | 2518 | bool wxListCtrl::SetColumnWidth( int col, int width ) |
c801d85f | 2519 | { |
5b077d48 RR |
2520 | m_mainWin->SetColumnWidth( col, width ); |
2521 | return TRUE; | |
e1e955e1 | 2522 | } |
c801d85f | 2523 | |
e487524e | 2524 | int wxListCtrl::GetCountPerPage(void) const |
c801d85f KB |
2525 | { |
2526 | return m_mainWin->GetCountPerPage(); // different from Windows ? | |
e1e955e1 | 2527 | } |
c801d85f | 2528 | |
e487524e | 2529 | bool wxListCtrl::GetItem( wxListItem &info ) const |
c801d85f | 2530 | { |
5b077d48 RR |
2531 | m_mainWin->GetItem( info ); |
2532 | return TRUE; | |
e1e955e1 | 2533 | } |
c801d85f KB |
2534 | |
2535 | bool wxListCtrl::SetItem( wxListItem &info ) | |
2536 | { | |
5b077d48 RR |
2537 | m_mainWin->SetItem( info ); |
2538 | return TRUE; | |
e1e955e1 | 2539 | } |
c801d85f | 2540 | |
debe6624 | 2541 | long wxListCtrl::SetItem( long index, int col, const wxString& label, int imageId ) |
c801d85f | 2542 | { |
5b077d48 RR |
2543 | wxListItem info; |
2544 | info.m_text = label; | |
2545 | info.m_mask = wxLIST_MASK_TEXT; | |
2546 | info.m_itemId = index; | |
2547 | info.m_col = col; | |
2548 | if ( imageId > -1 ) | |
2549 | { | |
2550 | info.m_image = imageId; | |
2551 | info.m_mask |= wxLIST_MASK_IMAGE; | |
2552 | }; | |
2553 | m_mainWin->SetItem(info); | |
2554 | return TRUE; | |
e1e955e1 | 2555 | } |
c801d85f | 2556 | |
e487524e | 2557 | int wxListCtrl::GetItemState( long item, long stateMask ) const |
c801d85f | 2558 | { |
5b077d48 | 2559 | return m_mainWin->GetItemState( item, stateMask ); |
e1e955e1 | 2560 | } |
c801d85f | 2561 | |
debe6624 | 2562 | bool wxListCtrl::SetItemState( long item, long state, long stateMask ) |
c801d85f | 2563 | { |
5b077d48 RR |
2564 | m_mainWin->SetItemState( item, state, stateMask ); |
2565 | return TRUE; | |
e1e955e1 | 2566 | } |
c801d85f | 2567 | |
debe6624 | 2568 | bool wxListCtrl::SetItemImage( long item, int image, int WXUNUSED(selImage) ) |
c801d85f | 2569 | { |
5b077d48 RR |
2570 | wxListItem info; |
2571 | info.m_image = image; | |
2572 | info.m_mask = wxLIST_MASK_IMAGE; | |
2573 | info.m_itemId = item; | |
2574 | m_mainWin->SetItem( info ); | |
2575 | return TRUE; | |
e1e955e1 | 2576 | } |
c801d85f | 2577 | |
e487524e | 2578 | wxString wxListCtrl::GetItemText( long item ) const |
c801d85f | 2579 | { |
5b077d48 RR |
2580 | wxListItem info; |
2581 | info.m_itemId = item; | |
2582 | m_mainWin->GetItem( info ); | |
2583 | return info.m_text; | |
e1e955e1 | 2584 | } |
c801d85f | 2585 | |
debe6624 | 2586 | void wxListCtrl::SetItemText( long item, const wxString &str ) |
c801d85f | 2587 | { |
5b077d48 RR |
2588 | wxListItem info; |
2589 | info.m_mask = wxLIST_MASK_TEXT; | |
2590 | info.m_itemId = item; | |
2591 | info.m_text = str; | |
2592 | m_mainWin->SetItem( info ); | |
e1e955e1 | 2593 | } |
c801d85f | 2594 | |
e487524e | 2595 | long wxListCtrl::GetItemData( long item ) const |
c801d85f | 2596 | { |
5b077d48 RR |
2597 | wxListItem info; |
2598 | info.m_itemId = item; | |
2599 | m_mainWin->GetItem( info ); | |
2600 | return info.m_data; | |
e1e955e1 | 2601 | } |
c801d85f | 2602 | |
debe6624 | 2603 | bool wxListCtrl::SetItemData( long item, long data ) |
c801d85f | 2604 | { |
5b077d48 RR |
2605 | wxListItem info; |
2606 | info.m_mask = wxLIST_MASK_DATA; | |
2607 | info.m_itemId = item; | |
2608 | info.m_data = data; | |
2609 | m_mainWin->SetItem( info ); | |
2610 | return TRUE; | |
e1e955e1 | 2611 | } |
c801d85f | 2612 | |
0a240683 | 2613 | bool wxListCtrl::GetItemRect( long item, wxRect &rect, int WXUNUSED(code) ) const |
c801d85f | 2614 | { |
5b077d48 RR |
2615 | m_mainWin->GetItemRect( item, rect ); |
2616 | return TRUE; | |
e1e955e1 | 2617 | } |
c801d85f | 2618 | |
e487524e | 2619 | bool wxListCtrl::GetItemPosition( long item, wxPoint& pos ) const |
c801d85f | 2620 | { |
5b077d48 RR |
2621 | m_mainWin->GetItemPosition( item, pos ); |
2622 | return TRUE; | |
e1e955e1 | 2623 | } |
c801d85f | 2624 | |
debe6624 | 2625 | bool wxListCtrl::SetItemPosition( long WXUNUSED(item), const wxPoint& WXUNUSED(pos) ) |
c801d85f | 2626 | { |
5b077d48 | 2627 | return 0; |
e1e955e1 | 2628 | } |
c801d85f | 2629 | |
e487524e | 2630 | int wxListCtrl::GetItemCount(void) const |
c801d85f | 2631 | { |
5b077d48 | 2632 | return m_mainWin->GetItemCount(); |
e1e955e1 | 2633 | } |
c801d85f | 2634 | |
92976ab6 RR |
2635 | int wxListCtrl::GetColumnCount(void) const |
2636 | { | |
5b077d48 | 2637 | return m_mainWin->GetColumnCount(); |
92976ab6 RR |
2638 | } |
2639 | ||
33d0b396 RR |
2640 | void wxListCtrl::SetItemSpacing( int spacing, bool isSmall ) |
2641 | { | |
5b077d48 | 2642 | m_mainWin->SetItemSpacing( spacing, isSmall ); |
e1e955e1 | 2643 | } |
33d0b396 | 2644 | |
e487524e | 2645 | int wxListCtrl::GetItemSpacing( bool isSmall ) const |
c801d85f | 2646 | { |
5b077d48 | 2647 | return m_mainWin->GetItemSpacing( isSmall ); |
e1e955e1 | 2648 | } |
c801d85f | 2649 | |
e487524e | 2650 | int wxListCtrl::GetSelectedItemCount(void) const |
c801d85f | 2651 | { |
5b077d48 | 2652 | return m_mainWin->GetSelectedItemCount(); |
e1e955e1 | 2653 | } |
c801d85f KB |
2654 | |
2655 | /* | |
2656 | wxColour wxListCtrl::GetTextColour(void) const | |
2657 | { | |
e1e955e1 | 2658 | } |
c801d85f KB |
2659 | |
2660 | void wxListCtrl::SetTextColour(const wxColour& WXUNUSED(col)) | |
2661 | { | |
e1e955e1 | 2662 | } |
c801d85f KB |
2663 | */ |
2664 | ||
e487524e | 2665 | long wxListCtrl::GetTopItem(void) const |
c801d85f | 2666 | { |
5b077d48 | 2667 | return 0; |
e1e955e1 | 2668 | } |
c801d85f | 2669 | |
6de97a3b | 2670 | long wxListCtrl::GetNextItem( long item, int geom, int state ) const |
c801d85f | 2671 | { |
5b077d48 | 2672 | return m_mainWin->GetNextItem( item, geom, state ); |
e1e955e1 | 2673 | } |
c801d85f | 2674 | |
e487524e | 2675 | wxImageList *wxListCtrl::GetImageList(int which) const |
c801d85f | 2676 | { |
5b077d48 RR |
2677 | if (which == wxIMAGE_LIST_NORMAL) |
2678 | { | |
2679 | return m_imageListNormal; | |
2680 | } | |
2681 | else if (which == wxIMAGE_LIST_SMALL) | |
2682 | { | |
2683 | return m_imageListSmall; | |
2684 | } | |
2685 | else if (which == wxIMAGE_LIST_STATE) | |
2686 | { | |
2687 | return m_imageListState; | |
2688 | } | |
2689 | return (wxImageList *) NULL; | |
e1e955e1 | 2690 | } |
c801d85f | 2691 | |
debe6624 | 2692 | void wxListCtrl::SetImageList( wxImageList *imageList, int which ) |
c801d85f | 2693 | { |
5b077d48 | 2694 | m_mainWin->SetImageList( imageList, which ); |
e1e955e1 | 2695 | } |
c801d85f | 2696 | |
debe6624 | 2697 | bool wxListCtrl::Arrange( int WXUNUSED(flag) ) |
c801d85f | 2698 | { |
5b077d48 | 2699 | return 0; |
e1e955e1 | 2700 | } |
c801d85f | 2701 | |
debe6624 | 2702 | bool wxListCtrl::DeleteItem( long item ) |
c801d85f | 2703 | { |
5b077d48 RR |
2704 | m_mainWin->DeleteItem( item ); |
2705 | return TRUE; | |
e1e955e1 | 2706 | } |
c801d85f KB |
2707 | |
2708 | bool wxListCtrl::DeleteAllItems(void) | |
2709 | { | |
5b077d48 RR |
2710 | m_mainWin->DeleteAllItems(); |
2711 | return TRUE; | |
e1e955e1 | 2712 | } |
c801d85f | 2713 | |
4f22cf8d | 2714 | bool wxListCtrl::DeleteAllColumns() |
bd8289c1 VZ |
2715 | { |
2716 | for ( size_t n = 0; n < m_mainWin->m_columns.GetCount(); n++ ) | |
2717 | DeleteColumn(n); | |
4f22cf8d | 2718 | |
5b077d48 | 2719 | return TRUE; |
4f22cf8d RR |
2720 | } |
2721 | ||
2722 | void wxListCtrl::ClearAll() | |
2723 | { | |
5b077d48 | 2724 | m_mainWin->DeleteEverything(); |
bd8289c1 VZ |
2725 | } |
2726 | ||
debe6624 | 2727 | bool wxListCtrl::DeleteColumn( int col ) |
c801d85f | 2728 | { |
5b077d48 RR |
2729 | m_mainWin->DeleteColumn( col ); |
2730 | return TRUE; | |
e1e955e1 | 2731 | } |
c801d85f | 2732 | |
e179bd65 | 2733 | void wxListCtrl::Edit( long item ) |
c801d85f | 2734 | { |
e179bd65 | 2735 | m_mainWin->Edit( item ); |
e1e955e1 | 2736 | } |
c801d85f | 2737 | |
debe6624 | 2738 | bool wxListCtrl::EnsureVisible( long item ) |
c801d85f | 2739 | { |
5b077d48 RR |
2740 | m_mainWin->EnsureVisible( item ); |
2741 | return TRUE; | |
e1e955e1 | 2742 | } |
c801d85f | 2743 | |
debe6624 | 2744 | long wxListCtrl::FindItem( long start, const wxString& str, bool partial ) |
c801d85f | 2745 | { |
5b077d48 | 2746 | return m_mainWin->FindItem( start, str, partial ); |
e1e955e1 | 2747 | } |
c801d85f | 2748 | |
debe6624 | 2749 | long wxListCtrl::FindItem( long start, long data ) |
c801d85f | 2750 | { |
5b077d48 | 2751 | return m_mainWin->FindItem( start, data ); |
e1e955e1 | 2752 | } |
c801d85f | 2753 | |
bd8289c1 | 2754 | long wxListCtrl::FindItem( long WXUNUSED(start), const wxPoint& WXUNUSED(pt), |
debe6624 | 2755 | int WXUNUSED(direction)) |
c801d85f | 2756 | { |
5b077d48 | 2757 | return 0; |
e1e955e1 | 2758 | } |
c801d85f KB |
2759 | |
2760 | long wxListCtrl::HitTest( const wxPoint &point, int &flags ) | |
2761 | { | |
5b077d48 | 2762 | return m_mainWin->HitTest( (int)point.x, (int)point.y, flags ); |
e1e955e1 | 2763 | } |
c801d85f KB |
2764 | |
2765 | long wxListCtrl::InsertItem( wxListItem& info ) | |
2766 | { | |
5b077d48 RR |
2767 | m_mainWin->InsertItem( info ); |
2768 | return 0; | |
e1e955e1 | 2769 | } |
c801d85f | 2770 | |
debe6624 | 2771 | long wxListCtrl::InsertItem( long index, const wxString &label ) |
c801d85f | 2772 | { |
51cc4dad RR |
2773 | wxListItem info; |
2774 | info.m_text = label; | |
2775 | info.m_mask = wxLIST_MASK_TEXT; | |
2776 | info.m_itemId = index; | |
2777 | return InsertItem( info ); | |
e1e955e1 | 2778 | } |
c801d85f | 2779 | |
debe6624 | 2780 | long wxListCtrl::InsertItem( long index, int imageIndex ) |
c801d85f | 2781 | { |
51cc4dad RR |
2782 | wxListItem info; |
2783 | info.m_mask = wxLIST_MASK_IMAGE; | |
2784 | info.m_image = imageIndex; | |
2785 | info.m_itemId = index; | |
2786 | return InsertItem( info ); | |
e1e955e1 | 2787 | } |
c801d85f | 2788 | |
debe6624 | 2789 | long wxListCtrl::InsertItem( long index, const wxString &label, int imageIndex ) |
c801d85f | 2790 | { |
51cc4dad RR |
2791 | wxListItem info; |
2792 | info.m_text = label; | |
2793 | info.m_image = imageIndex; | |
2794 | info.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_IMAGE; | |
2795 | info.m_itemId = index; | |
2796 | return InsertItem( info ); | |
e1e955e1 | 2797 | } |
c801d85f | 2798 | |
debe6624 | 2799 | long wxListCtrl::InsertColumn( long col, wxListItem &item ) |
c801d85f | 2800 | { |
51cc4dad RR |
2801 | m_mainWin->InsertColumn( col, item ); |
2802 | return 0; | |
e1e955e1 | 2803 | } |
c801d85f | 2804 | |
debe6624 JS |
2805 | long wxListCtrl::InsertColumn( long col, const wxString &heading, |
2806 | int format, int width ) | |
c801d85f | 2807 | { |
51cc4dad RR |
2808 | wxListItem item; |
2809 | item.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_FORMAT; | |
2810 | item.m_text = heading; | |
2811 | if (width >= -2) | |
2812 | { | |
2813 | item.m_mask |= wxLIST_MASK_WIDTH; | |
2814 | item.m_width = width; | |
2815 | } | |
2816 | item.m_format = format; | |
c801d85f | 2817 | |
51cc4dad | 2818 | return InsertColumn( col, item ); |
e1e955e1 | 2819 | } |
c801d85f | 2820 | |
debe6624 | 2821 | bool wxListCtrl::ScrollList( int WXUNUSED(dx), int WXUNUSED(dy) ) |
c801d85f | 2822 | { |
51cc4dad | 2823 | return 0; |
e1e955e1 | 2824 | } |
c801d85f KB |
2825 | |
2826 | // Sort items. | |
2827 | // fn is a function which takes 3 long arguments: item1, item2, data. | |
2828 | // item1 is the long data associated with a first item (NOT the index). | |
2829 | // item2 is the long data associated with a second item (NOT the index). | |
2830 | // data is the same value as passed to SortItems. | |
2831 | // The return value is a negative number if the first item should precede the second | |
2832 | // item, a positive number of the second item should precede the first, | |
2833 | // or zero if the two items are equivalent. | |
2834 | // data is arbitrary data to be passed to the sort function. | |
2835 | ||
2836 | bool wxListCtrl::SortItems( wxListCtrlCompare fn, long data ) | |
2837 | { | |
51cc4dad RR |
2838 | m_mainWin->SortItems( fn, data ); |
2839 | return TRUE; | |
e1e955e1 | 2840 | } |
c801d85f | 2841 | |
e3e65dac | 2842 | void wxListCtrl::OnIdle( wxIdleEvent &WXUNUSED(event) ) |
53010e52 | 2843 | { |
51cc4dad | 2844 | if (!m_mainWin->m_dirty) return; |
53010e52 | 2845 | |
51cc4dad RR |
2846 | int cw = 0; |
2847 | int ch = 0; | |
2848 | GetClientSize( &cw, &ch ); | |
bd8289c1 | 2849 | |
51cc4dad RR |
2850 | int x = 0; |
2851 | int y = 0; | |
2852 | int w = 0; | |
2853 | int h = 0; | |
bd8289c1 | 2854 | |
f03fc89f | 2855 | if (HasFlag(wxLC_REPORT)) |
51cc4dad RR |
2856 | { |
2857 | m_headerWin->GetPosition( &x, &y ); | |
2858 | m_headerWin->GetSize( &w, &h ); | |
2859 | if ((x != 0) || (y != 0) || (w != cw) || (h != 23)) | |
2860 | m_headerWin->SetSize( 0, 0, cw, 23 ); | |
2861 | ||
2862 | m_mainWin->GetPosition( &x, &y ); | |
2863 | m_mainWin->GetSize( &w, &h ); | |
2864 | if ((x != 0) || (y != 24) || (w != cw) || (h != ch-24)) | |
2865 | m_mainWin->SetSize( 0, 24, cw, ch-24 ); | |
2866 | } | |
2867 | else | |
2868 | { | |
2869 | m_mainWin->GetPosition( &x, &y ); | |
2870 | m_mainWin->GetSize( &w, &h ); | |
2871 | if ((x != 0) || (y != 24) || (w != cw) || (h != ch)) | |
2872 | m_mainWin->SetSize( 0, 0, cw, ch ); | |
2873 | } | |
bd8289c1 | 2874 | |
51cc4dad RR |
2875 | m_mainWin->CalculatePositions(); |
2876 | m_mainWin->RealizeChanges(); | |
2877 | m_mainWin->m_dirty = FALSE; | |
2878 | m_mainWin->Refresh(); | |
e1e955e1 | 2879 | } |
53010e52 | 2880 | |
f03fc89f | 2881 | bool wxListCtrl::SetBackgroundColour( const wxColour &colour ) |
bd8289c1 | 2882 | { |
f03fc89f VZ |
2883 | if ( !wxWindow::SetBackgroundColour( colour ) ) |
2884 | return FALSE; | |
58dea4b0 | 2885 | |
51cc4dad RR |
2886 | if (m_mainWin) |
2887 | { | |
2888 | m_mainWin->SetBackgroundColour( colour ); | |
2889 | m_mainWin->m_dirty = TRUE; | |
2890 | } | |
2891 | ||
2892 | if (m_headerWin) | |
2893 | { | |
cfb50f14 | 2894 | // m_headerWin->SetBackgroundColour( colour ); |
51cc4dad | 2895 | } |
f03fc89f VZ |
2896 | |
2897 | return TRUE; | |
e4d06860 RR |
2898 | } |
2899 | ||
f03fc89f | 2900 | bool wxListCtrl::SetForegroundColour( const wxColour &colour ) |
bd8289c1 | 2901 | { |
f03fc89f VZ |
2902 | if ( !wxWindow::SetForegroundColour( colour ) ) |
2903 | return FALSE; | |
58dea4b0 | 2904 | |
51cc4dad RR |
2905 | if (m_mainWin) |
2906 | { | |
2907 | m_mainWin->SetForegroundColour( colour ); | |
2908 | m_mainWin->m_dirty = TRUE; | |
2909 | } | |
2910 | ||
2911 | if (m_headerWin) | |
2912 | { | |
2913 | m_headerWin->SetForegroundColour( colour ); | |
2914 | } | |
f03fc89f VZ |
2915 | |
2916 | return TRUE; | |
e4d06860 | 2917 | } |
bd8289c1 | 2918 | |
f03fc89f | 2919 | bool wxListCtrl::SetFont( const wxFont &font ) |
bd8289c1 | 2920 | { |
f03fc89f VZ |
2921 | if ( !wxWindow::SetFont( font ) ) |
2922 | return FALSE; | |
58dea4b0 | 2923 | |
51cc4dad RR |
2924 | if (m_mainWin) |
2925 | { | |
2926 | m_mainWin->SetFont( font ); | |
2927 | m_mainWin->m_dirty = TRUE; | |
2928 | } | |
2929 | ||
2930 | if (m_headerWin) | |
2931 | { | |
2932 | m_headerWin->SetFont( font ); | |
2933 | } | |
f03fc89f VZ |
2934 | |
2935 | return TRUE; | |
e4d06860 | 2936 | } |
c801d85f | 2937 |