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