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