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