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