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