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