]> git.saurik.com Git - wxWidgets.git/blame - src/generic/listctrl.cpp
Added wxHelpControllerHelpProvider, added DisplayContextPopup, DisplayTextPopup
[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__
510fc784
RR
11 #pragma implementation "listctrl.h"
12 #pragma implementation "listctrlbase.h"
c801d85f
KB
13#endif
14
1e6d9499
JS
15// For compilers that support precompilation, includes "wx.h".
16#include "wx/wxprec.h"
17
18#ifdef __BORLANDC__
19#pragma hdrstop
20#endif
21
0208334d
RR
22#include "wx/dcscreen.h"
23#include "wx/app.h"
02527779 24#include "wx/listctrl.h"
f60d0f94 25#include "wx/generic/imaglist.h"
f6bcfd97 26#include "wx/dynarray.h"
c801d85f 27
7c74e7fe 28#ifndef wxUSE_GENERIC_LIST_EXTENSIONS
d6d26e04 29#define wxUSE_GENERIC_LIST_EXTENSIONS 1
7c74e7fe
SC
30#endif
31
efbb7287
VZ
32// ============================================================================
33// private classes
34// ============================================================================
35
36//-----------------------------------------------------------------------------
37// wxListItemData (internal)
38//-----------------------------------------------------------------------------
39
40class WXDLLEXPORT wxListItemData : public wxObject
41{
42public:
43 wxString m_text;
44 int m_image;
45 long m_data;
46 int m_xpos,m_ypos;
47 int m_width,m_height;
48
49 wxListItemAttr *m_attr;
50
51public:
52 wxListItemData();
53 ~wxListItemData() { delete m_attr; }
54
55 wxListItemData( const wxListItem &info );
56 void SetItem( const wxListItem &info );
57 void SetText( const wxString &s );
58 void SetImage( int image );
59 void SetData( long data );
60 void SetPosition( int x, int y );
61 void SetSize( int width, int height );
62 bool HasImage() const;
63 bool HasText() const;
64 bool IsHit( int x, int y ) const;
65 void GetText( wxString &s );
66 const wxString& GetText() { return m_text; }
67 int GetX( void ) const;
68 int GetY( void ) const;
69 int GetWidth() const;
70 int GetHeight() const;
71 int GetImage() const;
72 void GetItem( wxListItem &info ) const;
73
74 wxListItemAttr *GetAttributes() const { return m_attr; }
75
76private:
77 DECLARE_DYNAMIC_CLASS(wxListItemData);
78};
79
80//-----------------------------------------------------------------------------
81// wxListHeaderData (internal)
82//-----------------------------------------------------------------------------
83
84class WXDLLEXPORT wxListHeaderData : public wxObject
85{
86protected:
87 long m_mask;
88 int m_image;
89 wxString m_text;
90 int m_format;
91 int m_width;
92 int m_xpos,m_ypos;
93 int m_height;
94
95public:
96 wxListHeaderData();
97 wxListHeaderData( const wxListItem &info );
98 void SetItem( const wxListItem &item );
99 void SetPosition( int x, int y );
100 void SetWidth( int w );
101 void SetFormat( int format );
102 void SetHeight( int h );
103 bool HasImage() const;
104 bool HasText() const;
105 bool IsHit( int x, int y ) const;
106 void GetItem( wxListItem &item );
107 void GetText( wxString &s );
108 int GetImage() const;
109 int GetWidth() const;
110 int GetFormat() const;
f6bcfd97 111
efbb7287
VZ
112private:
113 DECLARE_DYNAMIC_CLASS(wxListHeaderData);
114};
115
116//-----------------------------------------------------------------------------
117// wxListLineData (internal)
118//-----------------------------------------------------------------------------
119
120class WXDLLEXPORT wxListLineData : public wxObject
121{
122public:
123 wxList m_items;
124 wxRect m_bound_all;
125 wxRect m_bound_label;
126 wxRect m_bound_icon;
127 wxRect m_bound_hilight;
128 int m_mode;
129 bool m_hilighted;
130 wxBrush *m_hilightBrush;
131 int m_spacing;
132 wxListMainWindow *m_owner;
133
134 void DoDraw( wxDC *dc, bool hilight, bool paintBG );
135
136public:
137 wxListLineData() {}
138 wxListLineData( wxListMainWindow *owner, int mode, wxBrush *hilightBrush );
139 void CalculateSize( wxDC *dc, int spacing );
140 void SetPosition( wxDC *dc, int x, int y, int window_width );
141 void SetColumnPosition( int index, int x );
142 void GetSize( int &width, int &height );
143 void GetExtent( int &x, int &y, int &width, int &height );
144 void GetLabelExtent( int &x, int &y, int &width, int &height );
145 long IsHit( int x, int y );
146 void InitItems( int num );
147 void SetItem( int index, const wxListItem &info );
148 void GetItem( int index, wxListItem &info );
149 void GetText( int index, wxString &s );
150 void SetText( int index, const wxString s );
151 int GetImage( int index );
152 void GetRect( wxRect &rect );
153 void Hilight( bool on );
154 void ReverseHilight();
155 void DrawRubberBand( wxDC *dc, bool on );
156 void Draw( wxDC *dc );
157 bool IsInRect( int x, int y, const wxRect &rect );
158 bool IsHilighted();
159 void AssignRect( wxRect &dest, int x, int y, int width, int height );
160 void AssignRect( wxRect &dest, const wxRect &source );
f6bcfd97 161
efbb7287
VZ
162private:
163 void SetAttributes(wxDC *dc,
164 const wxListItemAttr *attr,
165 const wxColour& colText, const wxFont& font,
166 bool hilight);
167
168 DECLARE_DYNAMIC_CLASS(wxListLineData);
169};
170
f6bcfd97
BP
171
172WX_DECLARE_EXPORTED_OBJARRAY(wxListLineData, wxListLineDataArray);
173#include "wx/arrimpl.cpp"
174WX_DEFINE_OBJARRAY(wxListLineDataArray);
175
efbb7287
VZ
176//-----------------------------------------------------------------------------
177// wxListHeaderWindow (internal)
178//-----------------------------------------------------------------------------
179
180class WXDLLEXPORT wxListHeaderWindow : public wxWindow
181{
182protected:
183 wxListMainWindow *m_owner;
184 wxCursor *m_currentCursor;
185 wxCursor *m_resizeCursor;
186 bool m_isDragging;
f6bcfd97
BP
187
188 // column being resized
189 int m_column;
190
191 // divider line position in logical (unscrolled) coords
192 int m_currentX;
193
194 // minimal position beyond which the divider line can't be dragged in
195 // logical coords
196 int m_minX;
efbb7287
VZ
197
198public:
199 wxListHeaderWindow();
f6bcfd97
BP
200 virtual ~wxListHeaderWindow();
201
202 wxListHeaderWindow( wxWindow *win,
203 wxWindowID id,
204 wxListMainWindow *owner,
205 const wxPoint &pos = wxDefaultPosition,
206 const wxSize &size = wxDefaultSize,
207 long style = 0,
208 const wxString &name = "wxlistctrlcolumntitles" );
209
efbb7287 210 void DoDrawRect( wxDC *dc, int x, int y, int w, int h );
efbb7287 211 void DrawCurrent();
f6bcfd97
BP
212 void AdjustDC(wxDC& dc);
213
214 void OnPaint( wxPaintEvent &event );
efbb7287
VZ
215 void OnMouse( wxMouseEvent &event );
216 void OnSetFocus( wxFocusEvent &event );
217
f6bcfd97
BP
218 // needs refresh
219 bool m_dirty;
220
efbb7287
VZ
221private:
222 DECLARE_DYNAMIC_CLASS(wxListHeaderWindow)
223 DECLARE_EVENT_TABLE()
224};
225
226//-----------------------------------------------------------------------------
227// wxListRenameTimer (internal)
228//-----------------------------------------------------------------------------
229
230class WXDLLEXPORT wxListRenameTimer: public wxTimer
231{
232private:
233 wxListMainWindow *m_owner;
234
235public:
236 wxListRenameTimer( wxListMainWindow *owner );
237 void Notify();
238};
239
240//-----------------------------------------------------------------------------
241// wxListTextCtrl (internal)
242//-----------------------------------------------------------------------------
243
244class WXDLLEXPORT wxListTextCtrl: public wxTextCtrl
245{
246private:
247 bool *m_accept;
248 wxString *m_res;
249 wxListMainWindow *m_owner;
250 wxString m_startValue;
251
252public:
253 wxListTextCtrl() {}
254 wxListTextCtrl( wxWindow *parent, const wxWindowID id,
255 bool *accept, wxString *res, wxListMainWindow *owner,
256 const wxString &value = "",
257 const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize,
258 int style = 0,
259 const wxValidator& validator = wxDefaultValidator,
809934d2 260 const wxString &name = "listctrltextctrl" );
efbb7287
VZ
261 void OnChar( wxKeyEvent &event );
262 void OnKillFocus( wxFocusEvent &event );
263
264private:
265 DECLARE_DYNAMIC_CLASS(wxListTextCtrl);
266 DECLARE_EVENT_TABLE()
267};
268
269//-----------------------------------------------------------------------------
270// wxListMainWindow (internal)
271//-----------------------------------------------------------------------------
272
273class WXDLLEXPORT wxListMainWindow: public wxScrolledWindow
274{
275public:
276 long m_mode;
f6bcfd97 277 wxListLineDataArray m_lines;
efbb7287
VZ
278 wxList m_columns;
279 wxListLineData *m_current;
280 wxListLineData *m_currentEdit;
281 int m_visibleLines;
282 wxBrush *m_hilightBrush;
283 wxColour *m_hilightColour;
284 int m_xScroll,m_yScroll;
285 bool m_dirty;
286 wxImageList *m_small_image_list;
287 wxImageList *m_normal_image_list;
288 int m_small_spacing;
289 int m_normal_spacing;
290 bool m_hasFocus;
291 bool m_usedKeys;
292 bool m_lastOnSame;
293 wxTimer *m_renameTimer;
294 bool m_renameAccept;
295 wxString m_renameRes;
296 bool m_isCreated;
297 int m_dragCount;
298 wxPoint m_dragStart;
299
300 // for double click logic
301 wxListLineData *m_lineLastClicked,
302 *m_lineBeforeLastClicked;
303
304public:
305 wxListMainWindow();
306 wxListMainWindow( wxWindow *parent, wxWindowID id,
307 const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize,
809934d2 308 long style = 0, const wxString &name = "listctrlmainwindow" );
efbb7287
VZ
309 ~wxListMainWindow();
310 void RefreshLine( wxListLineData *line );
311 void OnPaint( wxPaintEvent &event );
312 void HilightAll( bool on );
313 void SendNotify( wxListLineData *line, wxEventType command );
314 void FocusLine( wxListLineData *line );
315 void UnfocusLine( wxListLineData *line );
316 void SelectLine( wxListLineData *line );
317 void DeselectLine( wxListLineData *line );
318 void DeleteLine( wxListLineData *line );
319
320 void EditLabel( long item );
321 void Edit( long item ) { EditLabel(item); } // deprecated
322 void OnRenameTimer();
323 void OnRenameAccept();
324
325 void OnMouse( wxMouseEvent &event );
326 void MoveToFocus();
327 void OnArrowChar( wxListLineData *newCurrent, bool shiftDown );
328 void OnChar( wxKeyEvent &event );
329 void OnKeyDown( wxKeyEvent &event );
330 void OnSetFocus( wxFocusEvent &event );
331 void OnKillFocus( wxFocusEvent &event );
332 void OnSize( wxSizeEvent &event );
333 void OnScroll(wxScrollWinEvent& event) ;
f6bcfd97 334
efbb7287
VZ
335 void DrawImage( int index, wxDC *dc, int x, int y );
336 void GetImageSize( int index, int &width, int &height );
337 int GetIndexOfLine( const wxListLineData *line );
338 int GetTextLength( wxString &s ); // should be const
339
340 void SetImageList( wxImageList *imageList, int which );
341 void SetItemSpacing( int spacing, bool isSmall = FALSE );
342 int GetItemSpacing( bool isSmall = FALSE );
343 void SetColumn( int col, wxListItem &item );
344 void SetColumnWidth( int col, int width );
345 void GetColumn( int col, wxListItem &item );
346 int GetColumnWidth( int vol );
347 int GetColumnCount();
348 int GetCountPerPage();
349 void SetItem( wxListItem &item );
350 void GetItem( wxListItem &item );
351 void SetItemState( long item, long state, long stateMask );
352 int GetItemState( long item, long stateMask );
353 int GetItemCount();
354 void GetItemRect( long index, wxRect &rect );
355 bool GetItemPosition( long item, wxPoint& pos );
356 int GetSelectedItemCount();
357 void SetMode( long mode );
358 long GetMode() const;
359 void CalculatePositions();
360 void RealizeChanges();
361 long GetNextItem( long item, int geometry, int state );
362 void DeleteItem( long index );
363 void DeleteAllItems();
364 void DeleteColumn( int col );
365 void DeleteEverything();
366 void EnsureVisible( long index );
367 long FindItem( long start, const wxString& str, bool partial = FALSE );
368 long FindItem( long start, long data);
369 long HitTest( int x, int y, int &flags );
370 void InsertItem( wxListItem &item );
371// void AddItem( wxListItem &item );
372 void InsertColumn( long col, wxListItem &item );
373// void AddColumn( wxListItem &item );
374 void SortItems( wxListCtrlCompare fn, long data );
375
376private:
377 DECLARE_DYNAMIC_CLASS(wxListMainWindow);
378 DECLARE_EVENT_TABLE()
379};
380
381// ============================================================================
382// implementation
383// ============================================================================
384
c801d85f
KB
385//-----------------------------------------------------------------------------
386// wxListItemData
387//-----------------------------------------------------------------------------
388
389IMPLEMENT_DYNAMIC_CLASS(wxListItemData,wxObject);
390
fd9811b1 391wxListItemData::wxListItemData()
c801d85f 392{
92976ab6
RR
393 m_image = -1;
394 m_data = 0;
395 m_xpos = 0;
396 m_ypos = 0;
397 m_width = 0;
398 m_height = 0;
0530737d 399 m_attr = NULL;
e1e955e1 400}
c801d85f
KB
401
402wxListItemData::wxListItemData( const wxListItem &info )
403{
92976ab6
RR
404 m_image = -1;
405 m_data = 0;
0530737d
VZ
406 m_attr = NULL;
407
92976ab6 408 SetItem( info );
e1e955e1 409}
c801d85f
KB
410
411void wxListItemData::SetItem( const wxListItem &info )
412{
92976ab6
RR
413 if (info.m_mask & wxLIST_MASK_TEXT) m_text = info.m_text;
414 if (info.m_mask & wxLIST_MASK_IMAGE) m_image = info.m_image;
415 if (info.m_mask & wxLIST_MASK_DATA) m_data = info.m_data;
0530737d
VZ
416
417 if ( info.HasAttributes() )
418 {
419 if ( m_attr )
420 *m_attr = *info.GetAttributes();
421 else
422 m_attr = new wxListItemAttr(*info.GetAttributes());
423 }
424
92976ab6
RR
425 m_xpos = 0;
426 m_ypos = 0;
427 m_width = info.m_width;
428 m_height = 0;
e1e955e1 429}
c801d85f
KB
430
431void wxListItemData::SetText( const wxString &s )
432{
92976ab6 433 m_text = s;
e1e955e1 434}
c801d85f 435
debe6624 436void wxListItemData::SetImage( int image )
c801d85f 437{
92976ab6 438 m_image = image;
e1e955e1 439}
c801d85f 440
debe6624 441void wxListItemData::SetData( long data )
c801d85f 442{
92976ab6 443 m_data = data;
e1e955e1 444}
c801d85f 445
debe6624 446void wxListItemData::SetPosition( int x, int y )
c801d85f 447{
92976ab6
RR
448 m_xpos = x;
449 m_ypos = y;
e1e955e1 450}
c801d85f 451
1e6d9499 452void wxListItemData::SetSize( int width, int height )
c801d85f 453{
92976ab6
RR
454 if (width != -1) m_width = width;
455 if (height != -1) m_height = height;
e1e955e1 456}
c801d85f 457
fd9811b1 458bool wxListItemData::HasImage() const
c801d85f 459{
92976ab6 460 return (m_image >= 0);
e1e955e1 461}
c801d85f 462
fd9811b1 463bool wxListItemData::HasText() const
c801d85f 464{
92976ab6 465 return (!m_text.IsNull());
e1e955e1 466}
c801d85f 467
debe6624 468bool wxListItemData::IsHit( int x, int y ) const
c801d85f 469{
92976ab6 470 return ((x >= m_xpos) && (x <= m_xpos+m_width) && (y >= m_ypos) && (y <= m_ypos+m_height));
e1e955e1 471}
c801d85f
KB
472
473void wxListItemData::GetText( wxString &s )
474{
92976ab6 475 s = m_text;
e1e955e1 476}
c801d85f 477
fd9811b1 478int wxListItemData::GetX() const
c801d85f 479{
92976ab6 480 return m_xpos;
e1e955e1 481}
c801d85f 482
fd9811b1 483int wxListItemData::GetY() const
c801d85f 484{
92976ab6 485 return m_ypos;
e1e955e1 486}
c801d85f 487
fd9811b1 488int wxListItemData::GetWidth() const
c801d85f 489{
92976ab6 490 return m_width;
e1e955e1 491}
c801d85f 492
fd9811b1 493int wxListItemData::GetHeight() const
c801d85f 494{
92976ab6 495 return m_height;
e1e955e1 496}
c801d85f 497
fd9811b1 498int wxListItemData::GetImage() const
c801d85f 499{
92976ab6 500 return m_image;
e1e955e1 501}
c801d85f 502
0530737d 503void wxListItemData::GetItem( wxListItem &info ) const
c801d85f 504{
92976ab6
RR
505 info.m_text = m_text;
506 info.m_image = m_image;
507 info.m_data = m_data;
c801d85f 508
0530737d
VZ
509 if ( m_attr )
510 {
511 if ( m_attr->HasTextColour() )
512 info.SetTextColour(m_attr->GetTextColour());
513 if ( m_attr->HasBackgroundColour() )
514 info.SetBackgroundColour(m_attr->GetBackgroundColour());
515 if ( m_attr->HasFont() )
516 info.SetFont(m_attr->GetFont());
517 }
e1e955e1 518}
c801d85f
KB
519
520//-----------------------------------------------------------------------------
521// wxListHeaderData
522//-----------------------------------------------------------------------------
523
524IMPLEMENT_DYNAMIC_CLASS(wxListHeaderData,wxObject);
525
fd9811b1 526wxListHeaderData::wxListHeaderData()
c801d85f 527{
92976ab6
RR
528 m_mask = 0;
529 m_image = 0;
530 m_format = 0;
531 m_width = 0;
532 m_xpos = 0;
533 m_ypos = 0;
534 m_height = 0;
e1e955e1 535}
c801d85f
KB
536
537wxListHeaderData::wxListHeaderData( const wxListItem &item )
538{
92976ab6
RR
539 SetItem( item );
540 m_xpos = 0;
541 m_ypos = 0;
542 m_height = 0;
e1e955e1 543}
c801d85f
KB
544
545void wxListHeaderData::SetItem( const wxListItem &item )
546{
92976ab6
RR
547 m_mask = item.m_mask;
548 m_text = item.m_text;
549 m_image = item.m_image;
550 m_format = item.m_format;
551 m_width = item.m_width;
552 if (m_width < 0) m_width = 80;
553 if (m_width < 6) m_width = 6;
e1e955e1 554}
c801d85f 555
debe6624 556void wxListHeaderData::SetPosition( int x, int y )
c801d85f 557{
92976ab6
RR
558 m_xpos = x;
559 m_ypos = y;
e1e955e1 560}
c801d85f 561
debe6624 562void wxListHeaderData::SetHeight( int h )
c801d85f 563{
92976ab6 564 m_height = h;
e1e955e1 565}
c801d85f 566
debe6624 567void wxListHeaderData::SetWidth( int w )
c801d85f 568{
92976ab6
RR
569 m_width = w;
570 if (m_width < 0) m_width = 80;
571 if (m_width < 6) m_width = 6;
e1e955e1 572}
c801d85f 573
debe6624 574void wxListHeaderData::SetFormat( int format )
c801d85f 575{
92976ab6 576 m_format = format;
e1e955e1 577}
c801d85f 578
fd9811b1 579bool wxListHeaderData::HasImage() const
c801d85f 580{
92976ab6 581 return (m_image != 0);
e1e955e1 582}
c801d85f 583
fd9811b1 584bool wxListHeaderData::HasText() const
c801d85f 585{
92976ab6 586 return (m_text.Length() > 0);
e1e955e1 587}
c801d85f
KB
588
589bool wxListHeaderData::IsHit( int x, int y ) const
590{
92976ab6 591 return ((x >= m_xpos) && (x <= m_xpos+m_width) && (y >= m_ypos) && (y <= m_ypos+m_height));
e1e955e1 592}
c801d85f
KB
593
594void wxListHeaderData::GetItem( wxListItem &item )
595{
92976ab6
RR
596 item.m_mask = m_mask;
597 item.m_text = m_text;
598 item.m_image = m_image;
599 item.m_format = m_format;
600 item.m_width = m_width;
e1e955e1 601}
c801d85f
KB
602
603void wxListHeaderData::GetText( wxString &s )
604{
92976ab6 605 s = m_text;
e1e955e1 606}
c801d85f 607
fd9811b1 608int wxListHeaderData::GetImage() const
c801d85f 609{
92976ab6 610 return m_image;
e1e955e1 611}
c801d85f 612
fd9811b1 613int wxListHeaderData::GetWidth() const
c801d85f 614{
92976ab6 615 return m_width;
e1e955e1 616}
c801d85f 617
fd9811b1 618int wxListHeaderData::GetFormat() const
c801d85f 619{
92976ab6 620 return m_format;
e1e955e1 621}
c801d85f
KB
622
623//-----------------------------------------------------------------------------
624// wxListLineData
625//-----------------------------------------------------------------------------
626
627IMPLEMENT_DYNAMIC_CLASS(wxListLineData,wxObject);
628
debe6624 629wxListLineData::wxListLineData( wxListMainWindow *owner, int mode, wxBrush *hilightBrush )
c801d85f 630{
92976ab6
RR
631 m_mode = mode;
632 m_hilighted = FALSE;
633 m_owner = owner;
634 m_hilightBrush = hilightBrush;
635 m_items.DeleteContents( TRUE );
636 m_spacing = 0;
e1e955e1 637}
c801d85f 638
1e6d9499 639void wxListLineData::CalculateSize( wxDC *dc, int spacing )
c801d85f 640{
92976ab6
RR
641 m_spacing = spacing;
642 switch (m_mode)
c801d85f 643 {
92976ab6
RR
644 case wxLC_ICON:
645 {
646 m_bound_all.width = m_spacing;
92976ab6
RR
647 wxNode *node = m_items.First();
648 if (node)
649 {
650 wxListItemData *item = (wxListItemData*)node->Data();
0530737d 651 wxString s = item->GetText();
5d25c050 652 if (s.IsEmpty()) s = wxT("H");
13111b2a 653 wxCoord lw,lh;
92976ab6 654 dc->GetTextExtent( s, &lw, &lh );
5d25c050
RR
655 if (lh < 15) lh = 15;
656 lw += 4;
657 lh += 3;
f6bcfd97 658
5d25c050 659 m_bound_all.height = m_spacing+lh;
92976ab6 660 if (lw > m_spacing) m_bound_all.width = lw;
5d25c050
RR
661 m_bound_label.width = lw;
662 m_bound_label.height = lh;
f6bcfd97 663
5d25c050
RR
664 if (item->HasImage())
665 {
666 int w = 0;
667 int h = 0;
668 m_owner->GetImageSize( item->GetImage(), w, h );
669 m_bound_icon.width = w + 8;
670 m_bound_icon.height = h + 8;
f6bcfd97
BP
671
672 if ( m_bound_icon.width > m_bound_all.width )
673 m_bound_all.width = m_bound_icon.width;
674 if ( h + lh > m_bound_all.height - 4 )
675 m_bound_all.height = h + lh + 4;
5d25c050 676 }
f6bcfd97 677
5d25c050
RR
678 if (!item->HasText())
679 {
680 m_bound_hilight.width = m_bound_icon.width;
681 m_bound_hilight.height = m_bound_icon.height;
682 }
683 else
684 {
685 m_bound_hilight.width = m_bound_label.width;
686 m_bound_hilight.height = m_bound_label.height;
687 }
92976ab6
RR
688 }
689 break;
690 }
691 case wxLC_LIST:
692 {
693 wxNode *node = m_items.First();
694 if (node)
695 {
696 wxListItemData *item = (wxListItemData*)node->Data();
f6bcfd97 697
0530737d 698 wxString s = item->GetText();
5d25c050 699 if (s.IsEmpty()) s = wxT("H");
13111b2a 700 wxCoord lw,lh;
92976ab6 701 dc->GetTextExtent( s, &lw, &lh );
5d25c050
RR
702 if (lh < 15) lh = 15;
703 lw += 4;
704 lh += 3;
705 m_bound_label.width = lw;
706 m_bound_label.height = lh;
f6bcfd97 707
92976ab6
RR
708 m_bound_all.width = lw;
709 m_bound_all.height = lh;
f6bcfd97 710
0b855868
RR
711 if (item->HasImage())
712 {
5dd26b08
JS
713 int w = 0;
714 int h = 0;
0b855868 715 m_owner->GetImageSize( item->GetImage(), w, h );
5d25c050
RR
716 m_bound_icon.width = w;
717 m_bound_icon.height = h;
f6bcfd97 718
bffa1c77
VZ
719 m_bound_all.width += 4 + w;
720 if (h > m_bound_all.height) m_bound_all.height = h;
721 }
f6bcfd97 722
5d25c050
RR
723 m_bound_hilight.width = m_bound_all.width;
724 m_bound_hilight.height = m_bound_all.height;
92976ab6
RR
725 }
726 break;
727 }
728 case wxLC_REPORT:
729 {
730 m_bound_all.width = 0;
731 m_bound_all.height = 0;
732 wxNode *node = m_items.First();
efad36b8
RR
733 if (node)
734 {
735 wxListItemData *item = (wxListItemData*)node->Data();
736 if (item->HasImage())
737 {
738 int w = 0;
739 int h = 0;
740 m_owner->GetImageSize( item->GetImage(), w, h );
741 m_bound_icon.width = w;
742 m_bound_icon.height = h;
743 }
744 else
745 {
746 m_bound_icon.width = 0;
747 m_bound_icon.height = 0;
748 }
749 }
92976ab6
RR
750 while (node)
751 {
752 wxListItemData *item = (wxListItemData*)node->Data();
5d25c050
RR
753 wxString s = item->GetText();
754 if (s.IsEmpty()) s = wxT("H");
13111b2a 755 wxCoord lw,lh;
7c74e7fe 756 dc->GetTextExtent( s, &lw, &lh );
40c70187 757 if (lh < 15) lh = 15;
5d25c050
RR
758 lw += 4;
759 lh += 3;
f6bcfd97 760
92976ab6 761 item->SetSize( item->GetWidth(), lh );
7c74e7fe 762 m_bound_all.width += lw;
92976ab6
RR
763 m_bound_all.height = lh;
764 node = node->Next();
765 }
766 break;
767 }
e1e955e1 768 }
e1e955e1 769}
c801d85f 770
bc1dcfc1
VZ
771void wxListLineData::SetPosition( wxDC * WXUNUSED(dc),
772 int x, int y, int window_width )
c801d85f 773{
0b855868
RR
774 m_bound_all.x = x;
775 m_bound_all.y = y;
776 switch (m_mode)
777 {
778 case wxLC_ICON:
c801d85f 779 {
0b855868
RR
780 wxNode *node = m_items.First();
781 if (node)
782 {
783 wxListItemData *item = (wxListItemData*)node->Data();
784 if (item->HasImage())
785 {
f6bcfd97
BP
786 m_bound_icon.x = m_bound_all.x + 4
787 + (m_spacing - m_bound_icon.width)/2;
5d25c050 788 m_bound_icon.y = m_bound_all.y + 4;
0b855868
RR
789 }
790 if (item->HasText())
791 {
0b855868 792 if (m_bound_all.width > m_spacing)
5d25c050 793 m_bound_label.x = m_bound_all.x + 2;
0b855868 794 else
5d25c050
RR
795 m_bound_label.x = m_bound_all.x + 2 + (m_spacing/2) - (m_bound_label.width/2);
796 m_bound_label.y = m_bound_all.y + m_bound_all.height + 2 - m_bound_label.height;
797 m_bound_hilight.x = m_bound_label.x - 2;
798 m_bound_hilight.y = m_bound_label.y - 2;
799 }
800 else
801 {
802 m_bound_hilight.x = m_bound_icon.x - 4;
803 m_bound_hilight.y = m_bound_icon.y - 4;
0b855868
RR
804 }
805 }
806 break;
e1e955e1 807 }
0b855868 808 case wxLC_LIST:
c801d85f 809 {
5d25c050
RR
810 m_bound_hilight.x = m_bound_all.x;
811 m_bound_hilight.y = m_bound_all.y;
812 m_bound_label.y = m_bound_all.y + 2;
0b855868
RR
813 wxNode *node = m_items.First();
814 if (node)
815 {
816 wxListItemData *item = (wxListItemData*)node->Data();
817 if (item->HasImage())
bffa1c77 818 {
0b855868
RR
819 m_bound_icon.x = m_bound_all.x + 2;
820 m_bound_icon.y = m_bound_all.y + 2;
5d25c050
RR
821 m_bound_label.x = m_bound_all.x + 6 + m_bound_icon.width;
822 }
823 else
824 {
825 m_bound_label.x = m_bound_all.x + 2;
bffa1c77
VZ
826 }
827 }
0b855868
RR
828 break;
829 }
830 case wxLC_REPORT:
831 {
0b855868 832 m_bound_all.x = 0;
0b855868
RR
833 m_bound_all.width = window_width;
834 AssignRect( m_bound_hilight, m_bound_all );
5d25c050
RR
835 m_bound_label.x = m_bound_all.x + 2;
836 m_bound_label.y = m_bound_all.y + 2;
0b855868
RR
837 wxNode *node = m_items.First();
838 if (node)
839 {
840 wxListItemData *item = (wxListItemData*)node->Data();
bffa1c77
VZ
841 if (item->HasImage())
842 {
0b855868
RR
843 m_bound_icon.x = m_bound_all.x + 2;
844 m_bound_icon.y = m_bound_all.y + 2;
5d25c050 845 m_bound_label.x += 4 + m_bound_icon.width;
bffa1c77
VZ
846 }
847 }
0b855868 848 break;
e1e955e1 849 }
e1e955e1 850 }
e1e955e1 851}
c801d85f 852
debe6624 853void wxListLineData::SetColumnPosition( int index, int x )
c801d85f 854{
6f2a55e3 855 wxNode *node = m_items.Nth( (size_t)index );
92976ab6
RR
856 if (node)
857 {
858 wxListItemData *item = (wxListItemData*)node->Data();
859 item->SetPosition( x, m_bound_all.y+1 );
860 }
e1e955e1 861}
c801d85f
KB
862
863void wxListLineData::GetSize( int &width, int &height )
864{
139adb6a
RR
865 width = m_bound_all.width;
866 height = m_bound_all.height;
e1e955e1 867}
c801d85f
KB
868
869void wxListLineData::GetExtent( int &x, int &y, int &width, int &height )
870{
139adb6a
RR
871 x = m_bound_all.x;
872 y = m_bound_all.y;
873 width = m_bound_all.width;
874 height = m_bound_all.height;
e1e955e1 875}
c801d85f
KB
876
877void wxListLineData::GetLabelExtent( int &x, int &y, int &width, int &height )
878{
139adb6a
RR
879 x = m_bound_label.x;
880 y = m_bound_label.y;
881 width = m_bound_label.width;
882 height = m_bound_label.height;
e1e955e1 883}
c801d85f 884
0a240683 885void wxListLineData::GetRect( wxRect &rect )
c801d85f 886{
139adb6a 887 AssignRect( rect, m_bound_all );
e1e955e1 888}
c801d85f 889
debe6624 890long wxListLineData::IsHit( int x, int y )
c801d85f 891{
139adb6a
RR
892 wxNode *node = m_items.First();
893 if (node)
894 {
895 wxListItemData *item = (wxListItemData*)node->Data();
896 if (item->HasImage() && IsInRect( x, y, m_bound_icon )) return wxLIST_HITTEST_ONITEMICON;
897 if (item->HasText() && IsInRect( x, y, m_bound_label )) return wxLIST_HITTEST_ONITEMLABEL;
898// if (!(item->HasImage() || item->HasText())) return 0;
899 }
900 // if there is no icon or text = empty
901 if (IsInRect( x, y, m_bound_all )) return wxLIST_HITTEST_ONITEMICON;
902 return 0;
e1e955e1 903}
c801d85f 904
debe6624 905void wxListLineData::InitItems( int num )
c801d85f 906{
139adb6a 907 for (int i = 0; i < num; i++) m_items.Append( new wxListItemData() );
e1e955e1 908}
c801d85f 909
debe6624 910void wxListLineData::SetItem( int index, const wxListItem &info )
c801d85f 911{
139adb6a
RR
912 wxNode *node = m_items.Nth( index );
913 if (node)
914 {
915 wxListItemData *item = (wxListItemData*)node->Data();
916 item->SetItem( info );
917 }
e1e955e1 918}
c801d85f 919
1e6d9499 920void wxListLineData::GetItem( int index, wxListItem &info )
c801d85f 921{
139adb6a
RR
922 int i = index;
923 wxNode *node = m_items.Nth( i );
924 if (node)
925 {
926 wxListItemData *item = (wxListItemData*)node->Data();
927 item->GetItem( info );
928 }
e1e955e1 929}
c801d85f 930
debe6624 931void wxListLineData::GetText( int index, wxString &s )
c801d85f 932{
139adb6a
RR
933 int i = index;
934 wxNode *node = m_items.Nth( i );
935 s = "";
936 if (node)
937 {
938 wxListItemData *item = (wxListItemData*)node->Data();
939 item->GetText( s );
940 }
e1e955e1 941}
c801d85f 942
debe6624 943void wxListLineData::SetText( int index, const wxString s )
c801d85f 944{
139adb6a
RR
945 int i = index;
946 wxNode *node = m_items.Nth( i );
947 if (node)
948 {
949 wxListItemData *item = (wxListItemData*)node->Data();
950 item->SetText( s );
951 }
e1e955e1 952}
c801d85f 953
debe6624 954int wxListLineData::GetImage( int index )
c801d85f 955{
139adb6a
RR
956 int i = index;
957 wxNode *node = m_items.Nth( i );
958 if (node)
959 {
960 wxListItemData *item = (wxListItemData*)node->Data();
961 return item->GetImage();
962 }
963 return -1;
e1e955e1 964}
c801d85f 965
0530737d
VZ
966void wxListLineData::SetAttributes(wxDC *dc,
967 const wxListItemAttr *attr,
968 const wxColour& colText,
470caaf9
VZ
969 const wxFont& font,
970 bool hilight)
0530737d 971{
470caaf9
VZ
972 // don't use foregroud colour for drawing highlighted items - this might
973 // make them completely invisible (and there is no way to do bit
974 // arithmetics on wxColour, unfortunately)
975 if ( !hilight && attr && attr->HasTextColour() )
0530737d
VZ
976 {
977 dc->SetTextForeground(attr->GetTextColour());
978 }
979 else
980 {
981 dc->SetTextForeground(colText);
982 }
983
984 if ( attr && attr->HasFont() )
985 {
986 dc->SetFont(attr->GetFont());
987 }
988 else
989 {
990 dc->SetFont(font);
991 }
992}
993
1e6d9499 994void wxListLineData::DoDraw( wxDC *dc, bool hilight, bool paintBG )
c801d85f 995{
e06b9569
JS
996 int dev_x = 0;
997 int dev_y = 0;
3d2d8da1
RR
998 m_owner->CalcScrolledPosition( m_bound_all.x, m_bound_all.y, &dev_x, &dev_y );
999 wxCoord dev_w = m_bound_all.width;
1000 wxCoord dev_h = m_bound_all.height;
004fd0c8 1001
139adb6a 1002 if (!m_owner->IsExposed( dev_x, dev_y, dev_w, dev_h ))
139adb6a 1003 return;
bd8289c1 1004
0530737d
VZ
1005 wxWindow *listctrl = m_owner->GetParent();
1006
1007 // default foreground colour
1008 wxColour colText;
1009 if ( hilight )
1010 {
1011 colText = wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT );
1012 }
1013 else
1014 {
1015 colText = listctrl->GetForegroundColour();
1016 }
1017
1018 // default font
1019 wxFont font = listctrl->GetFont();
1020
1021 // VZ: currently we set the colours/fonts only once, but like this (i.e.
1022 // using SetAttributes() inside the loop), it will be trivial to
1023 // customize the subitems (in report mode) too.
1024 wxListItemData *item = (wxListItemData*)m_items.First()->Data();
1025 wxListItemAttr *attr = item->GetAttributes();
470caaf9 1026 SetAttributes(dc, attr, colText, font, hilight);
0530737d
VZ
1027
1028 bool hasBgCol = attr && attr->HasBackgroundColour();
1029 if ( paintBG || hasBgCol )
c801d85f 1030 {
63852e78
RR
1031 if (hilight)
1032 {
1033 dc->SetBrush( * m_hilightBrush );
63852e78
RR
1034 }
1035 else
1036 {
0530737d
VZ
1037 if ( hasBgCol )
1038 dc->SetBrush(wxBrush(attr->GetBackgroundColour(), wxSOLID));
1039 else
1040 dc->SetBrush( * wxWHITE_BRUSH );
63852e78 1041 }
0530737d
VZ
1042
1043 dc->SetPen( * wxTRANSPARENT_PEN );
63852e78
RR
1044 dc->DrawRectangle( m_bound_hilight.x, m_bound_hilight.y,
1045 m_bound_hilight.width, m_bound_hilight.height );
e1e955e1 1046 }
004fd0c8 1047
63852e78 1048 if (m_mode == wxLC_REPORT)
c801d85f 1049 {
63852e78
RR
1050 wxNode *node = m_items.First();
1051 while (node)
1052 {
1053 wxListItemData *item = (wxListItemData*)node->Data();
63852e78
RR
1054 int x = item->GetX();
1055 if (item->HasImage())
1056 {
1057 int y = 0;
1058 m_owner->DrawImage( item->GetImage(), dc, x, item->GetY() );
1059 m_owner->GetImageSize( item->GetImage(), x, y );
1060 x += item->GetX() + 5;
1061 }
40c70187 1062 dc->SetClippingRegion( item->GetX(), item->GetY(), item->GetWidth()-3, item->GetHeight() );
63852e78
RR
1063 if (item->HasText())
1064 {
40c70187 1065 dc->DrawText( item->GetText(), x, item->GetY()+1 );
63852e78
RR
1066 }
1067 dc->DestroyClippingRegion();
1068 node = node->Next();
1069 }
e1e955e1 1070 }
63852e78 1071 else
c801d85f 1072 {
63852e78
RR
1073 wxNode *node = m_items.First();
1074 if (node)
1075 {
1076 wxListItemData *item = (wxListItemData*)node->Data();
1077 if (item->HasImage())
1078 {
1079 m_owner->DrawImage( item->GetImage(), dc, m_bound_icon.x, m_bound_icon.y );
1080 }
1081 if (item->HasText())
1082 {
0530737d 1083 dc->DrawText( item->GetText(), m_bound_label.x, m_bound_label.y );
63852e78
RR
1084 }
1085 }
e1e955e1 1086 }
e1e955e1 1087}
c801d85f 1088
debe6624 1089void wxListLineData::Hilight( bool on )
c801d85f 1090{
63852e78 1091 if (on == m_hilighted) return;
6e228e42 1092 m_hilighted = on;
63852e78
RR
1093 if (on)
1094 m_owner->SelectLine( this );
1095 else
1096 m_owner->DeselectLine( this );
e1e955e1 1097}
c801d85f
KB
1098
1099void wxListLineData::ReverseHilight( void )
1100{
63852e78
RR
1101 m_hilighted = !m_hilighted;
1102 if (m_hilighted)
1103 m_owner->SelectLine( this );
1104 else
1105 m_owner->DeselectLine( this );
e1e955e1 1106}
c801d85f 1107
1e6d9499 1108void wxListLineData::DrawRubberBand( wxDC *dc, bool on )
c801d85f 1109{
63852e78
RR
1110 if (on)
1111 {
1112 dc->SetPen( * wxBLACK_PEN );
1113 dc->SetBrush( * wxTRANSPARENT_BRUSH );
1114 dc->DrawRectangle( m_bound_hilight.x, m_bound_hilight.y,
1115 m_bound_hilight.width, m_bound_hilight.height );
1116 }
e1e955e1 1117}
c801d85f 1118
1e6d9499 1119void wxListLineData::Draw( wxDC *dc )
c801d85f 1120{
63852e78 1121 DoDraw( dc, m_hilighted, m_hilighted );
e1e955e1 1122}
c801d85f 1123
0a240683 1124bool wxListLineData::IsInRect( int x, int y, const wxRect &rect )
c801d85f 1125{
004fd0c8 1126 return ((x >= rect.x) && (x <= rect.x+rect.width) &&
63852e78 1127 (y >= rect.y) && (y <= rect.y+rect.height));
e1e955e1 1128}
c801d85f
KB
1129
1130bool wxListLineData::IsHilighted( void )
1131{
63852e78 1132 return m_hilighted;
e1e955e1 1133}
c801d85f 1134
0a240683 1135void wxListLineData::AssignRect( wxRect &dest, int x, int y, int width, int height )
c801d85f 1136{
63852e78
RR
1137 dest.x = x;
1138 dest.y = y;
1139 dest.width = width;
1140 dest.height = height;
e1e955e1 1141}
c801d85f 1142
0a240683 1143void wxListLineData::AssignRect( wxRect &dest, const wxRect &source )
c801d85f 1144{
63852e78
RR
1145 dest.x = source.x;
1146 dest.y = source.y;
1147 dest.width = source.width;
1148 dest.height = source.height;
e1e955e1 1149}
c801d85f
KB
1150
1151//-----------------------------------------------------------------------------
1152// wxListHeaderWindow
1153//-----------------------------------------------------------------------------
1154
1155IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow,wxWindow);
1156
1157BEGIN_EVENT_TABLE(wxListHeaderWindow,wxWindow)
63852e78
RR
1158 EVT_PAINT (wxListHeaderWindow::OnPaint)
1159 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse)
1160 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus)
c801d85f
KB
1161END_EVENT_TABLE()
1162
1163wxListHeaderWindow::wxListHeaderWindow( void )
1164{
63852e78
RR
1165 m_owner = (wxListMainWindow *) NULL;
1166 m_currentCursor = (wxCursor *) NULL;
1167 m_resizeCursor = (wxCursor *) NULL;
cfb50f14 1168 m_isDragging = FALSE;
e1e955e1 1169}
c801d85f 1170
bd8289c1 1171wxListHeaderWindow::wxListHeaderWindow( wxWindow *win, wxWindowID id, wxListMainWindow *owner,
debe6624
JS
1172 const wxPoint &pos, const wxSize &size,
1173 long style, const wxString &name ) :
c801d85f
KB
1174 wxWindow( win, id, pos, size, style, name )
1175{
63852e78 1176 m_owner = owner;
c801d85f 1177// m_currentCursor = wxSTANDARD_CURSOR;
63852e78
RR
1178 m_currentCursor = (wxCursor *) NULL;
1179 m_resizeCursor = new wxCursor( wxCURSOR_SIZEWE );
cfb50f14 1180 m_isDragging = FALSE;
f6bcfd97
BP
1181 m_dirty = FALSE;
1182
cfb50f14 1183 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE ) );
e1e955e1 1184}
c801d85f 1185
a367b9b3
JS
1186wxListHeaderWindow::~wxListHeaderWindow( void )
1187{
63852e78 1188 delete m_resizeCursor;
a367b9b3
JS
1189}
1190
1e6d9499 1191void wxListHeaderWindow::DoDrawRect( wxDC *dc, int x, int y, int w, int h )
c801d85f 1192{
63852e78 1193 const int m_corner = 1;
c801d85f 1194
63852e78 1195 dc->SetBrush( *wxTRANSPARENT_BRUSH );
c801d85f 1196
63852e78
RR
1197 dc->SetPen( *wxBLACK_PEN );
1198 dc->DrawLine( x+w-m_corner+1, y, x+w, y+h ); // right (outer)
17867d61 1199 dc->DrawRectangle( x, y+h, w+1, 1 ); // bottom (outer)
bd8289c1 1200
63852e78 1201 wxPen pen( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNSHADOW ), 1, wxSOLID );
004fd0c8 1202
63852e78
RR
1203 dc->SetPen( pen );
1204 dc->DrawLine( x+w-m_corner, y, x+w-1, y+h ); // right (inner)
1205 dc->DrawRectangle( x+1, y+h-1, w-2, 1 ); // bottom (inner)
bd8289c1 1206
63852e78
RR
1207 dc->SetPen( *wxWHITE_PEN );
1208 dc->DrawRectangle( x, y, w-m_corner+1, 1 ); // top (outer)
1209 dc->DrawRectangle( x, y, 1, h ); // left (outer)
1210 dc->DrawLine( x, y+h-1, x+1, y+h-1 );
1211 dc->DrawLine( x+w-1, y, x+w-1, y+1 );
e1e955e1 1212}
c801d85f 1213
f6bcfd97
BP
1214// shift the DC origin to match the position of the main window horz
1215// scrollbar: this allows us to always use logical coords
1216void wxListHeaderWindow::AdjustDC(wxDC& dc)
1217{
1218#if wxUSE_GENERIC_LIST_EXTENSIONS
1219 int xpix;
1220 m_owner->GetScrollPixelsPerUnit( &xpix, NULL );
1221
1222 int x;
1223 m_owner->GetViewStart( &x, NULL );
1224
1225 // account for the horz scrollbar offset
1226 dc.SetDeviceOrigin( -x * xpix, 0 );
1227#endif // wxUSE_GENERIC_LIST_EXTENSIONS
1228}
1229
c801d85f
KB
1230void wxListHeaderWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
1231{
63852e78
RR
1232 wxPaintDC dc( this );
1233 PrepareDC( dc );
f6bcfd97 1234 AdjustDC( dc );
bffa1c77 1235
63852e78 1236 dc.BeginDrawing();
bd8289c1 1237
63852e78 1238 dc.SetFont( GetFont() );
bd8289c1 1239
f6bcfd97
BP
1240 // width and height of the entire header window
1241 int w, h;
63852e78 1242 GetClientSize( &w, &h );
f6bcfd97
BP
1243#if wxUSE_GENERIC_LIST_EXTENSIONS
1244 m_owner->CalcUnscrolledPosition(w, 0, &w, NULL);
1245#endif // wxUSE_GENERIC_LIST_EXTENSIONS
c801d85f 1246
f60d0f94 1247 dc.SetBackgroundMode(wxTRANSPARENT);
70846f0a
VZ
1248
1249 // do *not* use the listctrl colour for headers - one day we will have a
1250 // function to set it separately
37d403aa
JS
1251 //dc.SetTextForeground( *wxBLACK );
1252 dc.SetTextForeground(wxSystemSettings::GetSystemColour( wxSYS_COLOUR_WINDOWTEXT ));
c801d85f 1253
f6bcfd97
BP
1254 int x = 1; // left of the header rect
1255 const int y = 1; // top
63852e78
RR
1256 int numColumns = m_owner->GetColumnCount();
1257 wxListItem item;
1258 for (int i = 0; i < numColumns; i++)
1259 {
1260 m_owner->GetColumn( i, item );
f6bcfd97
BP
1261 int wCol = item.m_width;
1262 int cw = wCol - 2; // the width of the rect to draw
1263
1264 int xEnd = x + wCol;
1265
1266 // VZ: no, draw it normally - this is better now as we allow resizing
1267 // of the last column as well
1268#if 0
1269 // let the last column occupy all available space
1270 if ( i == numColumns - 1 )
470caaf9 1271 cw = w-x-1;
f6bcfd97
BP
1272#endif // 0
1273
63852e78 1274 dc.SetPen( *wxWHITE_PEN );
c801d85f 1275
63852e78 1276 DoDrawRect( &dc, x, y, cw, h-2 );
40c70187 1277 dc.SetClippingRegion( x, y, cw-5, h-4 );
63852e78 1278 dc.DrawText( item.m_text, x+4, y+3 );
40c70187 1279 dc.DestroyClippingRegion();
f6bcfd97
BP
1280 x += wCol;
1281
1282 if (xEnd > w+5)
1283 break;
63852e78
RR
1284 }
1285 dc.EndDrawing();
e1e955e1 1286}
c801d85f 1287
0208334d
RR
1288void wxListHeaderWindow::DrawCurrent()
1289{
63852e78
RR
1290 int x1 = m_currentX;
1291 int y1 = 0;
f6bcfd97
BP
1292 ClientToScreen( &x1, &y1 );
1293
63852e78
RR
1294 int x2 = m_currentX-1;
1295 int y2 = 0;
f6bcfd97 1296 m_owner->GetClientSize( NULL, &y2 );
63852e78 1297 m_owner->ClientToScreen( &x2, &y2 );
0208334d 1298
63852e78 1299 wxScreenDC dc;
3c679789 1300 dc.SetLogicalFunction( wxINVERT );
63852e78
RR
1301 dc.SetPen( wxPen( *wxBLACK, 2, wxSOLID ) );
1302 dc.SetBrush( *wxTRANSPARENT_BRUSH );
0208334d 1303
f6bcfd97
BP
1304 AdjustDC(dc);
1305
63852e78 1306 dc.DrawLine( x1, y1, x2, y2 );
0208334d 1307
63852e78 1308 dc.SetLogicalFunction( wxCOPY );
0208334d 1309
63852e78
RR
1310 dc.SetPen( wxNullPen );
1311 dc.SetBrush( wxNullBrush );
0208334d
RR
1312}
1313
c801d85f
KB
1314void wxListHeaderWindow::OnMouse( wxMouseEvent &event )
1315{
f6bcfd97
BP
1316 // we want to work with logical coords
1317#if wxUSE_GENERIC_LIST_EXTENSIONS
3ca6a5f0
BP
1318 int x;
1319 m_owner->CalcUnscrolledPosition(event.GetX(), 0, &x, NULL);
f6bcfd97
BP
1320#else // !wxUSE_GENERIC_LIST_EXTENSIONS
1321 int x = event.GetX();
f6bcfd97 1322#endif // wxUSE_GENERIC_LIST_EXTENSIONS
3ca6a5f0 1323 int y = event.GetY();
f6bcfd97 1324
cfb50f14 1325 if (m_isDragging)
0208334d 1326 {
f6bcfd97
BP
1327 // we don't draw the line beyond our window, but we allow dragging it
1328 // there
1329 int w = 0;
1330 GetClientSize( &w, NULL );
1331#if wxUSE_GENERIC_LIST_EXTENSIONS
1332 m_owner->CalcUnscrolledPosition(w, 0, &w, NULL);
1333#endif // wxUSE_GENERIC_LIST_EXTENSIONS
1334 w -= 6;
1335
1336 // erase the line if it was drawn
1337 if ( m_currentX < w )
1338 DrawCurrent();
1339
63852e78
RR
1340 if (event.ButtonUp())
1341 {
1342 ReleaseMouse();
cfb50f14 1343 m_isDragging = FALSE;
f6bcfd97
BP
1344 m_dirty = TRUE;
1345 m_owner->SetColumnWidth( m_column, m_currentX - m_minX );
63852e78
RR
1346 }
1347 else
1348 {
f6bcfd97 1349 if (x > m_minX + 7)
63852e78
RR
1350 m_currentX = x;
1351 else
f6bcfd97 1352 m_currentX = m_minX + 7;
bd8289c1 1353
f6bcfd97
BP
1354 // draw in the new location
1355 if ( m_currentX < w )
1356 DrawCurrent();
bffa1c77 1357 }
0208334d 1358 }
f6bcfd97 1359 else // not dragging
c801d85f 1360 {
f6bcfd97
BP
1361 m_minX = 0;
1362 bool hit_border = FALSE;
1363
1364 // end of the current column
1365 int xpos = 0;
1366
1367 // find the column where this event occured
1368 int countCol = m_owner->GetColumnCount();
1369 for (int j = 0; j < countCol; j++)
bffa1c77 1370 {
f6bcfd97
BP
1371 xpos += m_owner->GetColumnWidth( j );
1372 m_column = j;
1373
1374 if ( (abs(x-xpos) < 3) && (y < 22) )
1375 {
1376 // near the column border
1377 hit_border = TRUE;
1378 break;
1379 }
1380
1381 if ( x < xpos )
1382 {
1383 // inside the column
1384 break;
1385 }
1386
1387 m_minX = xpos;
bffa1c77 1388 }
63852e78 1389
f6bcfd97 1390 if (event.LeftDown())
63852e78 1391 {
f6bcfd97
BP
1392 if (hit_border)
1393 {
1394 m_isDragging = TRUE;
1395 m_currentX = x;
1396 DrawCurrent();
1397 CaptureMouse();
1398 }
1399 else
1400 {
1401 wxWindow *parent = GetParent();
1402 wxListEvent le( wxEVT_COMMAND_LIST_COL_CLICK, parent->GetId() );
1403 le.SetEventObject( parent );
1404 le.m_col = m_column;
1405 parent->GetEventHandler()->ProcessEvent( le );
1406 }
63852e78 1407 }
f6bcfd97 1408 else if (event.Moving())
63852e78 1409 {
f6bcfd97
BP
1410 bool setCursor;
1411 if (hit_border)
1412 {
1413 setCursor = m_currentCursor == wxSTANDARD_CURSOR;
1414 m_currentCursor = m_resizeCursor;
1415 }
1416 else
1417 {
1418 setCursor = m_currentCursor != wxSTANDARD_CURSOR;
1419 m_currentCursor = wxSTANDARD_CURSOR;
1420 }
1421
1422 if ( setCursor )
1423 SetCursor(*m_currentCursor);
63852e78 1424 }
e1e955e1 1425 }
e1e955e1 1426}
c801d85f
KB
1427
1428void wxListHeaderWindow::OnSetFocus( wxFocusEvent &WXUNUSED(event) )
1429{
63852e78 1430 m_owner->SetFocus();
e1e955e1 1431}
c801d85f
KB
1432
1433//-----------------------------------------------------------------------------
1434// wxListRenameTimer (internal)
1435//-----------------------------------------------------------------------------
1436
bd8289c1
VZ
1437wxListRenameTimer::wxListRenameTimer( wxListMainWindow *owner )
1438{
63852e78 1439 m_owner = owner;
e1e955e1 1440}
c801d85f 1441
bd8289c1
VZ
1442void wxListRenameTimer::Notify()
1443{
63852e78 1444 m_owner->OnRenameTimer();
e1e955e1 1445}
c801d85f 1446
ee7ee469
RR
1447//-----------------------------------------------------------------------------
1448// wxListTextCtrl (internal)
1449//-----------------------------------------------------------------------------
1450
1451IMPLEMENT_DYNAMIC_CLASS(wxListTextCtrl,wxTextCtrl);
bd8289c1 1452
ee7ee469 1453BEGIN_EVENT_TABLE(wxListTextCtrl,wxTextCtrl)
63852e78
RR
1454 EVT_CHAR (wxListTextCtrl::OnChar)
1455 EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus)
ee7ee469
RR
1456END_EVENT_TABLE()
1457
674ac8b9
VZ
1458wxListTextCtrl::wxListTextCtrl( wxWindow *parent,
1459 const wxWindowID id,
1460 bool *accept,
1461 wxString *res,
1462 wxListMainWindow *owner,
1463 const wxString &value,
1464 const wxPoint &pos,
1465 const wxSize &size,
1466 int style,
1467 const wxValidator& validator,
1468 const wxString &name )
1469 : wxTextCtrl( parent, id, value, pos, size, style, validator, name )
ee7ee469 1470{
63852e78
RR
1471 m_res = res;
1472 m_accept = accept;
1473 m_owner = owner;
5f1ea0ee
RR
1474 (*m_accept) = FALSE;
1475 (*m_res) = "";
1476 m_startValue = value;
ee7ee469
RR
1477}
1478
1479void wxListTextCtrl::OnChar( wxKeyEvent &event )
1480{
63852e78
RR
1481 if (event.m_keyCode == WXK_RETURN)
1482 {
1483 (*m_accept) = TRUE;
1484 (*m_res) = GetValue();
f6bcfd97 1485
bce1406b
RR
1486 if (!wxPendingDelete.Member(this))
1487 wxPendingDelete.Append(this);
1488
1489 if ((*m_accept) && ((*m_res) != m_startValue))
1490 m_owner->OnRenameAccept();
f6bcfd97 1491
63852e78
RR
1492 return;
1493 }
1494 if (event.m_keyCode == WXK_ESCAPE)
1495 {
1496 (*m_accept) = FALSE;
1497 (*m_res) = "";
f6bcfd97 1498
bce1406b
RR
1499 if (!wxPendingDelete.Member(this))
1500 wxPendingDelete.Append(this);
f6bcfd97 1501
63852e78
RR
1502 return;
1503 }
f6bcfd97 1504
63852e78
RR
1505 event.Skip();
1506}
1507
1508void wxListTextCtrl::OnKillFocus( wxFocusEvent &WXUNUSED(event) )
1509{
bce1406b
RR
1510 if (!wxPendingDelete.Member(this))
1511 wxPendingDelete.Append(this);
004fd0c8 1512
5f1ea0ee
RR
1513 if ((*m_accept) && ((*m_res) != m_startValue))
1514 m_owner->OnRenameAccept();
ee7ee469
RR
1515}
1516
c801d85f
KB
1517//-----------------------------------------------------------------------------
1518// wxListMainWindow
1519//-----------------------------------------------------------------------------
1520
1521IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow,wxScrolledWindow);
bd8289c1 1522
c801d85f
KB
1523BEGIN_EVENT_TABLE(wxListMainWindow,wxScrolledWindow)
1524 EVT_PAINT (wxListMainWindow::OnPaint)
1525 EVT_SIZE (wxListMainWindow::OnSize)
1526 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse)
1527 EVT_CHAR (wxListMainWindow::OnChar)
3dfb93fd 1528 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown)
c801d85f
KB
1529 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus)
1530 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus)
2fa7c206 1531 EVT_SCROLLWIN (wxListMainWindow::OnScroll)
c801d85f
KB
1532END_EVENT_TABLE()
1533
fd9811b1 1534wxListMainWindow::wxListMainWindow()
c801d85f 1535{
139adb6a 1536 m_mode = 0;
139adb6a
RR
1537 m_columns.DeleteContents( TRUE );
1538 m_current = (wxListLineData *) NULL;
1539 m_visibleLines = 0;
1540 m_hilightBrush = (wxBrush *) NULL;
1541 m_xScroll = 0;
1542 m_yScroll = 0;
1543 m_dirty = TRUE;
1544 m_small_image_list = (wxImageList *) NULL;
1545 m_normal_image_list = (wxImageList *) NULL;
1546 m_small_spacing = 30;
1547 m_normal_spacing = 40;
1548 m_hasFocus = FALSE;
1549 m_usedKeys = TRUE;
1550 m_lastOnSame = FALSE;
1551 m_renameTimer = new wxListRenameTimer( this );
1552 m_isCreated = FALSE;
1553 m_dragCount = 0;
efbb7287
VZ
1554
1555 m_lineLastClicked =
1556 m_lineBeforeLastClicked = (wxListLineData *)NULL;
e1e955e1 1557}
c801d85f 1558
bd8289c1 1559wxListMainWindow::wxListMainWindow( wxWindow *parent, wxWindowID id,
c801d85f 1560 const wxPoint &pos, const wxSize &size,
debe6624 1561 long style, const wxString &name ) :
a367b9b3 1562 wxScrolledWindow( parent, id, pos, size, style|wxHSCROLL|wxVSCROLL, name )
c801d85f 1563{
139adb6a 1564 m_mode = style;
139adb6a
RR
1565 m_columns.DeleteContents( TRUE );
1566 m_current = (wxListLineData *) NULL;
1567 m_dirty = TRUE;
1568 m_visibleLines = 0;
1569 m_hilightBrush = new wxBrush( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT), wxSOLID );
1570 m_small_image_list = (wxImageList *) NULL;
1571 m_normal_image_list = (wxImageList *) NULL;
1572 m_small_spacing = 30;
1573 m_normal_spacing = 40;
1574 m_hasFocus = FALSE;
1575 m_dragCount = 0;
1576 m_isCreated = FALSE;
1577 wxSize sz = size;
1578 sz.y = 25;
bd8289c1 1579
139adb6a
RR
1580 if (m_mode & wxLC_REPORT)
1581 {
7c74e7fe
SC
1582#if wxUSE_GENERIC_LIST_EXTENSIONS
1583 m_xScroll = 15;
1584#else
139adb6a 1585 m_xScroll = 0;
7c74e7fe 1586#endif
139adb6a
RR
1587 m_yScroll = 15;
1588 }
1589 else
1590 {
1591 m_xScroll = 15;
1592 m_yScroll = 0;
1593 }
1594 SetScrollbars( m_xScroll, m_yScroll, 0, 0, 0, 0 );
bd8289c1 1595
139adb6a
RR
1596 m_usedKeys = TRUE;
1597 m_lastOnSame = FALSE;
1598 m_renameTimer = new wxListRenameTimer( this );
1599 m_renameAccept = FALSE;
c801d85f 1600
91fc2bdc 1601 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_LISTBOX ) );
e1e955e1 1602}
c801d85f 1603
fd9811b1 1604wxListMainWindow::~wxListMainWindow()
c801d85f 1605{
12c1b46a
RR
1606 DeleteEverything();
1607
139adb6a 1608 if (m_hilightBrush) delete m_hilightBrush;
004fd0c8 1609
139adb6a 1610 delete m_renameTimer;
e1e955e1 1611}
c801d85f
KB
1612
1613void wxListMainWindow::RefreshLine( wxListLineData *line )
1614{
e6527f9d 1615 if (m_dirty) return;
25e3a937 1616
3d2d8da1 1617 if (!line) return;
f6bcfd97 1618
139adb6a
RR
1619 int x = 0;
1620 int y = 0;
1621 int w = 0;
1622 int h = 0;
3d2d8da1
RR
1623 line->GetExtent( x, y, w, h );
1624 CalcScrolledPosition( x, y, &x, &y );
1625 wxRect rect( x, y, w, h );
1626 Refresh( TRUE, &rect );
e1e955e1 1627}
c801d85f
KB
1628
1629void wxListMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
1630{
f60d0f94
JS
1631 // Note: a wxPaintDC must be constructed even if no drawing is
1632 // done (a Windows requirement).
1633 wxPaintDC dc( this );
1634 PrepareDC( dc );
1635
139adb6a 1636 if (m_dirty) return;
004fd0c8 1637
139adb6a 1638 if (m_lines.GetCount() == 0) return;
bd8289c1 1639
139adb6a 1640 dc.BeginDrawing();
c801d85f 1641
139adb6a 1642 dc.SetFont( GetFont() );
004fd0c8 1643
139adb6a
RR
1644 if (m_mode & wxLC_REPORT)
1645 {
206b0a67
JS
1646 wxPen pen(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DLIGHT), 1, wxSOLID);
1647 dc.SetPen(pen);
1648 dc.SetBrush(* wxTRANSPARENT_BRUSH);
1649
1650 wxSize clientSize = GetClientSize();
1651 wxRect itemRect;
1652
139adb6a 1653 int lineSpacing = 0;
f6bcfd97 1654 wxListLineData *line = &m_lines[0];
139adb6a
RR
1655 int dummy = 0;
1656 line->GetSize( dummy, lineSpacing );
1657 lineSpacing += 1;
bffa1c77 1658
139adb6a 1659 int y_s = m_yScroll*GetScrollPos( wxVERTICAL );
bffa1c77 1660
f6bcfd97
BP
1661 size_t i_to = y_s / lineSpacing + m_visibleLines+2;
1662 if (i_to >= m_lines.GetCount()) i_to = m_lines.GetCount();
206b0a67
JS
1663 size_t i;
1664 for (i = y_s / lineSpacing; i < i_to; i++)
bffa1c77 1665 {
f6bcfd97 1666 m_lines[i].Draw( &dc );
206b0a67
JS
1667 // Draw horizontal rule if required
1668 if (GetWindowStyle() & wxLC_HRULES)
1669 dc.DrawLine(0, i*lineSpacing, clientSize.x, i*lineSpacing);
bffa1c77 1670 }
206b0a67
JS
1671
1672 // Draw last horizontal rule
1673 if ((i > (size_t) (y_s / lineSpacing)) && (GetWindowStyle() & wxLC_HRULES))
1674 dc.DrawLine(0, i*lineSpacing, clientSize.x, i*lineSpacing);
1675
1676 // Draw vertical rules if required
1677 if ((GetWindowStyle() & wxLC_VRULES) && (GetItemCount() > 0))
1678 {
1679 int col = 0;
1680 wxRect firstItemRect;
1681 wxRect lastItemRect;
1682 GetItemRect(0, firstItemRect);
1683 GetItemRect(GetItemCount() - 1, lastItemRect);
1684 int x = firstItemRect.GetX();
1685 for (col = 0; col < GetColumnCount(); col++)
1686 {
1687 int colWidth = GetColumnWidth(col);
1688 x += colWidth ;
1689 dc.DrawLine(x, firstItemRect.GetY() - 1, x, lastItemRect.GetBottom() + 1);
1690 }
1691 }
139adb6a
RR
1692 }
1693 else
1694 {
f6bcfd97
BP
1695 for (size_t i = 0; i < m_lines.GetCount(); i++)
1696 m_lines[i].Draw( &dc );
139adb6a 1697 }
004fd0c8 1698
139adb6a 1699 if (m_current) m_current->DrawRubberBand( &dc, m_hasFocus );
c801d85f 1700
139adb6a 1701 dc.EndDrawing();
e1e955e1 1702}
c801d85f 1703
debe6624 1704void wxListMainWindow::HilightAll( bool on )
c801d85f 1705{
f6bcfd97 1706 for (size_t i = 0; i < m_lines.GetCount(); i++)
c801d85f 1707 {
f6bcfd97 1708 wxListLineData *line = &m_lines[i];
139adb6a
RR
1709 if (line->IsHilighted() != on)
1710 {
1711 line->Hilight( on );
1712 RefreshLine( line );
1713 }
e1e955e1 1714 }
e1e955e1 1715}
c801d85f 1716
7798a18e 1717void wxListMainWindow::SendNotify( wxListLineData *line, wxEventType command )
c801d85f 1718{
139adb6a
RR
1719 wxListEvent le( command, GetParent()->GetId() );
1720 le.SetEventObject( GetParent() );
1721 le.m_itemIndex = GetIndexOfLine( line );
1722 line->GetItem( 0, le.m_item );
6e228e42
RR
1723 GetParent()->GetEventHandler()->ProcessEvent( le );
1724// GetParent()->GetEventHandler()->AddPendingEvent( le );
e1e955e1 1725}
c801d85f
KB
1726
1727void wxListMainWindow::FocusLine( wxListLineData *WXUNUSED(line) )
1728{
1729// SendNotify( line, wxEVT_COMMAND_LIST_ITEM_FOCUSSED );
e1e955e1 1730}
c801d85f
KB
1731
1732void wxListMainWindow::UnfocusLine( wxListLineData *WXUNUSED(line) )
1733{
1734// SendNotify( line, wxEVT_COMMAND_LIST_ITEM_UNFOCUSSED );
e1e955e1 1735}
c801d85f
KB
1736
1737void wxListMainWindow::SelectLine( wxListLineData *line )
1738{
139adb6a 1739 SendNotify( line, wxEVT_COMMAND_LIST_ITEM_SELECTED );
e1e955e1 1740}
c801d85f
KB
1741
1742void wxListMainWindow::DeselectLine( wxListLineData *line )
1743{
139adb6a 1744 SendNotify( line, wxEVT_COMMAND_LIST_ITEM_DESELECTED );
e1e955e1 1745}
c801d85f
KB
1746
1747void wxListMainWindow::DeleteLine( wxListLineData *line )
1748{
139adb6a 1749 SendNotify( line, wxEVT_COMMAND_LIST_DELETE_ITEM );
e1e955e1 1750}
c801d85f 1751
e179bd65 1752/* *** */
ee7ee469 1753
5f1ea0ee 1754void wxListMainWindow::EditLabel( long item )
c801d85f 1755{
3e1c4e00 1756 wxCHECK_RET( ((size_t)item < m_lines.GetCount()),
f6bcfd97 1757 wxT("wrong index in wxListCtrl::Edit()") );
004fd0c8 1758
f6bcfd97 1759 m_currentEdit = &m_lines[(size_t)item];
e179bd65 1760
fd9811b1 1761 wxListEvent le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT, GetParent()->GetId() );
139adb6a 1762 le.SetEventObject( GetParent() );
e179bd65
RR
1763 le.m_itemIndex = GetIndexOfLine( m_currentEdit );
1764 m_currentEdit->GetItem( 0, le.m_item );
139adb6a 1765 GetParent()->GetEventHandler()->ProcessEvent( le );
004fd0c8 1766
86f975a8 1767 if (!le.IsAllowed())
5f1ea0ee 1768 return;
004fd0c8 1769
dc6c62a9
RR
1770 // We have to call this here because the label in
1771 // question might just have been added and no screen
1772 // update taken place.
1773 if (m_dirty) wxYield();
1774
92976ab6 1775 wxString s;
e179bd65 1776 m_currentEdit->GetText( 0, s );
92976ab6
RR
1777 int x = 0;
1778 int y = 0;
1779 int w = 0;
1780 int h = 0;
e179bd65 1781 m_currentEdit->GetLabelExtent( x, y, w, h );
004fd0c8 1782
92976ab6
RR
1783 wxClientDC dc(this);
1784 PrepareDC( dc );
1785 x = dc.LogicalToDeviceX( x );
1786 y = dc.LogicalToDeviceY( y );
bd8289c1 1787
92976ab6
RR
1788 wxListTextCtrl *text = new wxListTextCtrl(
1789 this, -1, &m_renameAccept, &m_renameRes, this, s, wxPoint(x-4,y-4), wxSize(w+11,h+8) );
1790 text->SetFocus();
e1e955e1 1791}
c801d85f 1792
e179bd65
RR
1793void wxListMainWindow::OnRenameTimer()
1794{
223d09f6 1795 wxCHECK_RET( m_current, wxT("invalid m_current") );
004fd0c8 1796
f6bcfd97 1797 Edit( m_lines.Index( *m_current ) );
e179bd65
RR
1798}
1799
c801d85f
KB
1800void wxListMainWindow::OnRenameAccept()
1801{
e179bd65
RR
1802 wxListEvent le( wxEVT_COMMAND_LIST_END_LABEL_EDIT, GetParent()->GetId() );
1803 le.SetEventObject( GetParent() );
1804 le.m_itemIndex = GetIndexOfLine( m_currentEdit );
1805 m_currentEdit->GetItem( 0, le.m_item );
1806 le.m_item.m_text = m_renameRes;
1807 GetParent()->GetEventHandler()->ProcessEvent( le );
004fd0c8 1808
e179bd65 1809 if (!le.IsAllowed()) return;
004fd0c8 1810
5f1ea0ee
RR
1811 wxListItem info;
1812 info.m_mask = wxLIST_MASK_TEXT;
1813 info.m_itemId = le.m_itemIndex;
1814 info.m_text = m_renameRes;
aaa37c0d 1815 info.SetTextColour(le.m_item.GetTextColour());
5f1ea0ee 1816 SetItem( info );
e1e955e1 1817}
c801d85f
KB
1818
1819void wxListMainWindow::OnMouse( wxMouseEvent &event )
1820{
3e1c4e00 1821 event.SetEventObject( GetParent() );
92976ab6 1822 if (GetParent()->GetEventHandler()->ProcessEvent( event)) return;
e3e65dac 1823
92976ab6
RR
1824 if (!m_current) return;
1825 if (m_dirty) return;
0b855868 1826 if ( !(event.Dragging() || event.ButtonDown() || event.LeftUp() || event.ButtonDClick()) ) return;
c801d85f 1827
aaef15bf
RR
1828 int x = event.GetX();
1829 int y = event.GetY();
1830 CalcUnscrolledPosition( x, y, &x, &y );
004fd0c8 1831
51cc4dad 1832 /* Did we actually hit an item ? */
92976ab6 1833 long hitResult = 0;
92976ab6 1834 wxListLineData *line = (wxListLineData *) NULL;
f6bcfd97 1835 for (size_t i = 0; i < m_lines.GetCount(); i++)
92976ab6 1836 {
f6bcfd97 1837 line = &m_lines[i];
92976ab6
RR
1838 hitResult = line->IsHit( x, y );
1839 if (hitResult) break;
1840 line = (wxListLineData *) NULL;
92976ab6 1841 }
bd8289c1 1842
fd9811b1 1843 if (event.Dragging())
92976ab6 1844 {
fd9811b1 1845 if (m_dragCount == 0)
bffa1c77
VZ
1846 m_dragStart = wxPoint(x,y);
1847
fd9811b1 1848 m_dragCount++;
bffa1c77
VZ
1849
1850 if (m_dragCount != 3) return;
1851
1852 int command = wxEVT_COMMAND_LIST_BEGIN_DRAG;
1853 if (event.RightIsDown()) command = wxEVT_COMMAND_LIST_BEGIN_RDRAG;
1854
fd9811b1 1855 wxListEvent le( command, GetParent()->GetId() );
92976ab6 1856 le.SetEventObject( GetParent() );
bffa1c77
VZ
1857 le.m_pointDrag = m_dragStart;
1858 GetParent()->GetEventHandler()->ProcessEvent( le );
1859
1860 return;
92976ab6 1861 }
fd9811b1
RR
1862 else
1863 {
1864 m_dragCount = 0;
1865 }
bd8289c1 1866
92976ab6 1867 if (!line) return;
bd8289c1 1868
efbb7287 1869 bool forceClick = FALSE;
92976ab6
RR
1870 if (event.ButtonDClick())
1871 {
92976ab6 1872 m_renameTimer->Stop();
efbb7287
VZ
1873 m_lastOnSame = FALSE;
1874
1875 if ( line == m_lineBeforeLastClicked )
1876 {
1877 m_usedKeys = FALSE;
004fd0c8 1878
efbb7287 1879 SendNotify( line, wxEVT_COMMAND_LIST_ITEM_ACTIVATED );
004fd0c8 1880
efbb7287
VZ
1881 return;
1882 }
1883 else
1884 {
1885 // the first click was on another item, so don't interpret this as
1886 // a double click, but as a simple click instead
1887 forceClick = TRUE;
1888 }
92976ab6 1889 }
bd8289c1 1890
92976ab6 1891 if (event.LeftUp() && m_lastOnSame)
c801d85f 1892 {
92976ab6
RR
1893 m_usedKeys = FALSE;
1894 if ((line == m_current) &&
1895 (hitResult == wxLIST_HITTEST_ONITEMLABEL) &&
1896 (m_mode & wxLC_EDIT_LABELS) )
1897 {
1898 m_renameTimer->Start( 100, TRUE );
1899 }
1900 m_lastOnSame = FALSE;
1901 return;
e1e955e1 1902 }
bd8289c1 1903
92976ab6 1904 if (event.RightDown())
b204641e 1905 {
92976ab6
RR
1906 SendNotify( line, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK );
1907 return;
b204641e 1908 }
004fd0c8 1909
92976ab6 1910 if (event.MiddleDown())
b204641e 1911 {
92976ab6
RR
1912 SendNotify( line, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK );
1913 return;
1914 }
004fd0c8 1915
efbb7287 1916 if ( event.LeftDown() || forceClick )
92976ab6 1917 {
efbb7287
VZ
1918 m_lineBeforeLastClicked = m_lineLastClicked;
1919 m_lineLastClicked = line;
1920
92976ab6
RR
1921 m_usedKeys = FALSE;
1922 wxListLineData *oldCurrent = m_current;
1923 if (m_mode & wxLC_SINGLE_SEL)
b204641e 1924 {
92976ab6
RR
1925 m_current = line;
1926 HilightAll( FALSE );
1927 m_current->ReverseHilight();
1928 RefreshLine( m_current );
e1e955e1 1929 }
92976ab6 1930 else
b204641e 1931 {
473d087e 1932 if (event.ControlDown())
92976ab6
RR
1933 {
1934 m_current = line;
1935 m_current->ReverseHilight();
1936 RefreshLine( m_current );
1937 }
473d087e 1938 else if (event.ShiftDown())
92976ab6 1939 {
f6bcfd97 1940 size_t j;
3e1c4e00 1941
92976ab6 1942 m_current = line;
bffa1c77 1943
92976ab6 1944 int numOfCurrent = -1;
f6bcfd97 1945 for (j = 0; j < m_lines.GetCount(); j++)
92976ab6 1946 {
f6bcfd97 1947 wxListLineData *test_line = &m_lines[j];
92976ab6
RR
1948 numOfCurrent++;
1949 if (test_line == oldCurrent) break;
92976ab6 1950 }
bffa1c77 1951
92976ab6 1952 int numOfLine = -1;
f6bcfd97
BP
1953
1954 for (j = 0; j < m_lines.GetCount(); j++)
92976ab6 1955 {
f6bcfd97 1956 wxListLineData *test_line = &m_lines[j];
92976ab6
RR
1957 numOfLine++;
1958 if (test_line == line) break;
92976ab6
RR
1959 }
1960
1961 if (numOfLine < numOfCurrent)
004fd0c8 1962 {
bffa1c77
VZ
1963 int i = numOfLine;
1964 numOfLine = numOfCurrent;
1965 numOfCurrent = i;
1966 }
1967
92976ab6
RR
1968 for (int i = 0; i <= numOfLine-numOfCurrent; i++)
1969 {
f6bcfd97 1970 wxListLineData *test_line= &m_lines[numOfCurrent + i];
92976ab6
RR
1971 test_line->Hilight(TRUE);
1972 RefreshLine( test_line );
92976ab6
RR
1973 }
1974 }
1975 else
1976 {
1977 m_current = line;
1978 HilightAll( FALSE );
1979 m_current->ReverseHilight();
1980 RefreshLine( m_current );
1981 }
e1e955e1 1982 }
92976ab6
RR
1983 if (m_current != oldCurrent)
1984 {
1985 RefreshLine( oldCurrent );
1986 UnfocusLine( oldCurrent );
1987 FocusLine( m_current );
1988 }
efbb7287
VZ
1989
1990 // forceClick is only set if the previous click was on another item
1991 m_lastOnSame = !forceClick && (m_current == oldCurrent);
1992
92976ab6 1993 return;
e1e955e1 1994 }
e1e955e1 1995}
c801d85f 1996
e179bd65 1997void wxListMainWindow::MoveToFocus()
c801d85f 1998{
92976ab6 1999 if (!m_current) return;
004fd0c8 2000
cf3da716
RR
2001 int item_x = 0;
2002 int item_y = 0;
2003 int item_w = 0;
2004 int item_h = 0;
2005 m_current->GetExtent( item_x, item_y, item_w, item_h );
2006
2007 int client_w = 0;
2008 int client_h = 0;
2009 GetClientSize( &client_w, &client_h );
f6bcfd97 2010
cf3da716
RR
2011 int view_x = m_xScroll*GetScrollPos( wxHORIZONTAL );
2012 int view_y = m_yScroll*GetScrollPos( wxVERTICAL );
004fd0c8 2013
92976ab6
RR
2014 if (m_mode & wxLC_REPORT)
2015 {
f6bcfd97
BP
2016 if (item_y-5 < view_y )
2017 Scroll( -1, (item_y-5)/m_yScroll );
2018 if (item_y+item_h+5 > view_y+client_h)
cf3da716 2019 Scroll( -1, (item_y+item_h-client_h+15)/m_yScroll );
92976ab6
RR
2020 }
2021 else
2022 {
f6bcfd97 2023 if (item_x-view_x < 5)
cf3da716 2024 Scroll( (item_x-5)/m_xScroll, -1 );
f6bcfd97 2025 if (item_x+item_w-5 > view_x+client_w)
cf3da716 2026 Scroll( (item_x+item_w-client_w+15)/m_xScroll, -1 );
92976ab6 2027 }
e1e955e1 2028}
c801d85f
KB
2029
2030void wxListMainWindow::OnArrowChar( wxListLineData *newCurrent, bool shiftDown )
2031{
92976ab6
RR
2032 if ((m_mode & wxLC_SINGLE_SEL) || (m_usedKeys == FALSE)) m_current->Hilight( FALSE );
2033 wxListLineData *oldCurrent = m_current;
2034 m_current = newCurrent;
92976ab6
RR
2035 if (shiftDown || (m_mode & wxLC_SINGLE_SEL)) m_current->Hilight( TRUE );
2036 RefreshLine( m_current );
2037 RefreshLine( oldCurrent );
2038 FocusLine( m_current );
2039 UnfocusLine( oldCurrent );
cf3da716 2040 MoveToFocus();
e1e955e1 2041}
c801d85f 2042
3dfb93fd
RR
2043void wxListMainWindow::OnKeyDown( wxKeyEvent &event )
2044{
2045 wxWindow *parent = GetParent();
004fd0c8 2046
3dfb93fd
RR
2047 /* we propagate the key event up */
2048 wxKeyEvent ke( wxEVT_KEY_DOWN );
2049 ke.m_shiftDown = event.m_shiftDown;
2050 ke.m_controlDown = event.m_controlDown;
2051 ke.m_altDown = event.m_altDown;
2052 ke.m_metaDown = event.m_metaDown;
2053 ke.m_keyCode = event.m_keyCode;
2054 ke.m_x = event.m_x;
2055 ke.m_y = event.m_y;
2056 ke.SetEventObject( parent );
2057 if (parent->GetEventHandler()->ProcessEvent( ke )) return;
004fd0c8 2058
3dfb93fd
RR
2059 event.Skip();
2060}
004fd0c8 2061
c801d85f
KB
2062void wxListMainWindow::OnChar( wxKeyEvent &event )
2063{
51cc4dad 2064 wxWindow *parent = GetParent();
004fd0c8 2065
51cc4dad 2066 /* we send a list_key event up */
f6bcfd97
BP
2067 if ( m_current )
2068 {
2069 wxListEvent le( wxEVT_COMMAND_LIST_KEY_DOWN, GetParent()->GetId() );
2070 le.m_itemIndex = GetIndexOfLine( m_current );
2071 m_current->GetItem( 0, le.m_item );
2072 le.m_code = (int)event.KeyCode();
2073 le.SetEventObject( parent );
2074 parent->GetEventHandler()->ProcessEvent( le );
2075 }
51cc4dad 2076
3dfb93fd
RR
2077 /* we propagate the char event up */
2078 wxKeyEvent ke( wxEVT_CHAR );
51cc4dad
RR
2079 ke.m_shiftDown = event.m_shiftDown;
2080 ke.m_controlDown = event.m_controlDown;
2081 ke.m_altDown = event.m_altDown;
2082 ke.m_metaDown = event.m_metaDown;
2083 ke.m_keyCode = event.m_keyCode;
2084 ke.m_x = event.m_x;
2085 ke.m_y = event.m_y;
2086 ke.SetEventObject( parent );
2087 if (parent->GetEventHandler()->ProcessEvent( ke )) return;
004fd0c8 2088
012a03e0
RR
2089 if (event.KeyCode() == WXK_TAB)
2090 {
2091 wxNavigationKeyEvent nevent;
c5145d41 2092 nevent.SetWindowChange( event.ControlDown() );
012a03e0 2093 nevent.SetDirection( !event.ShiftDown() );
8253c7fd 2094 nevent.SetEventObject( GetParent()->GetParent() );
012a03e0 2095 nevent.SetCurrentFocus( m_parent );
8253c7fd 2096 if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent )) return;
012a03e0 2097 }
004fd0c8 2098
51cc4dad
RR
2099 /* no item -> nothing to do */
2100 if (!m_current)
c801d85f 2101 {
51cc4dad
RR
2102 event.Skip();
2103 return;
e1e955e1 2104 }
51cc4dad
RR
2105
2106 switch (event.KeyCode())
c801d85f 2107 {
51cc4dad
RR
2108 case WXK_UP:
2109 {
f6bcfd97
BP
2110 int index = m_lines.Index(*m_current);
2111 if (index != wxNOT_FOUND && index > 0)
2112 OnArrowChar( &m_lines[index-1], event.ShiftDown() );
51cc4dad
RR
2113 break;
2114 }
2115 case WXK_DOWN:
2116 {
f6bcfd97
BP
2117 int index = m_lines.Index(*m_current);
2118 if (index != wxNOT_FOUND && (size_t)index < m_lines.GetCount()-1)
2119 OnArrowChar( &m_lines[index+1], event.ShiftDown() );
51cc4dad
RR
2120 break;
2121 }
2122 case WXK_END:
2123 {
f6bcfd97
BP
2124 if (!m_lines.IsEmpty())
2125 OnArrowChar( &m_lines.Last(), event.ShiftDown() );
51cc4dad
RR
2126 break;
2127 }
2128 case WXK_HOME:
2129 {
f6bcfd97
BP
2130 if (!m_lines.IsEmpty())
2131 OnArrowChar( &m_lines[0], event.ShiftDown() );
51cc4dad
RR
2132 break;
2133 }
2134 case WXK_PRIOR:
2135 {
2136 int steps = 0;
f6bcfd97 2137 int index = m_lines.Index(*m_current);
004fd0c8 2138 if (m_mode & wxLC_REPORT)
bffa1c77
VZ
2139 {
2140 steps = m_visibleLines-1;
2141 }
51cc4dad
RR
2142 else
2143 {
f6bcfd97
BP
2144 steps = index % m_visibleLines;
2145 }
2146 if (index != wxNOT_FOUND)
2147 {
2148 index -= steps;
3e1c4e00 2149 if (index < 0) index = 0;
f6bcfd97 2150 OnArrowChar( &m_lines[index], event.ShiftDown() );
51cc4dad 2151 }
51cc4dad
RR
2152 break;
2153 }
2154 case WXK_NEXT:
2155 {
2156 int steps = 0;
f6bcfd97 2157 int index = m_lines.Index(*m_current);
004fd0c8 2158 if (m_mode & wxLC_REPORT)
bffa1c77
VZ
2159 {
2160 steps = m_visibleLines-1;
2161 }
51cc4dad
RR
2162 else
2163 {
f6bcfd97
BP
2164 steps = m_visibleLines-(index % m_visibleLines)-1;
2165 }
2166
2167 if (index != wxNOT_FOUND)
2168 {
2169 index += steps;
3e1c4e00 2170 if ((size_t)index >= m_lines.GetCount())
f6bcfd97
BP
2171 index = m_lines.GetCount()-1;
2172 OnArrowChar( &m_lines[index], event.ShiftDown() );
51cc4dad 2173 }
51cc4dad
RR
2174 break;
2175 }
2176 case WXK_LEFT:
2177 {
2178 if (!(m_mode & wxLC_REPORT))
2179 {
f6bcfd97
BP
2180 int index = m_lines.Index(*m_current);
2181 if (index != wxNOT_FOUND)
2182 {
2183 index -= m_visibleLines;
2184 if (index < 0) index = 0;
2185 OnArrowChar( &m_lines[index], event.ShiftDown() );
2186 }
51cc4dad
RR
2187 }
2188 break;
2189 }
2190 case WXK_RIGHT:
2191 {
2192 if (!(m_mode & wxLC_REPORT))
2193 {
f6bcfd97
BP
2194 int index = m_lines.Index(*m_current);
2195 if (index != wxNOT_FOUND)
2196 {
2197 index += m_visibleLines;
3e1c4e00 2198 if ((size_t)index >= m_lines.GetCount())
f6bcfd97
BP
2199 index = m_lines.GetCount()-1;
2200 OnArrowChar( &m_lines[index], event.ShiftDown() );
2201 }
51cc4dad
RR
2202 }
2203 break;
2204 }
2205 case WXK_SPACE:
2206 {
33d0e17c
RR
2207 if (m_mode & wxLC_SINGLE_SEL)
2208 {
2209 wxListEvent le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED, GetParent()->GetId() );
2210 le.SetEventObject( GetParent() );
2211 le.m_itemIndex = GetIndexOfLine( m_current );
2212 m_current->GetItem( 0, le.m_item );
2213 GetParent()->GetEventHandler()->ProcessEvent( le );
2214 }
2215 else
2216 {
2217 m_current->ReverseHilight();
2218 RefreshLine( m_current );
2219 }
51cc4dad
RR
2220 break;
2221 }
2222 case WXK_INSERT:
2223 {
2224 if (!(m_mode & wxLC_SINGLE_SEL))
2225 {
2226 wxListLineData *oldCurrent = m_current;
2227 m_current->ReverseHilight();
f6bcfd97
BP
2228 int index = m_lines.Index( *m_current ) + 1;
2229 if ( (size_t)index < m_lines.GetCount() )
2230 m_current = &m_lines[index];
51cc4dad
RR
2231 RefreshLine( oldCurrent );
2232 RefreshLine( m_current );
2233 UnfocusLine( oldCurrent );
2234 FocusLine( m_current );
cf3da716 2235 MoveToFocus();
51cc4dad
RR
2236 }
2237 break;
2238 }
2239 case WXK_RETURN:
2240 case WXK_EXECUTE:
2241 {
2242 wxListEvent le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED, GetParent()->GetId() );
2243 le.SetEventObject( GetParent() );
2244 le.m_itemIndex = GetIndexOfLine( m_current );
2245 m_current->GetItem( 0, le.m_item );
2246 GetParent()->GetEventHandler()->ProcessEvent( le );
2247 break;
2248 }
2249 default:
2250 {
2251 event.Skip();
2252 return;
2253 }
e1e955e1 2254 }
51cc4dad 2255 m_usedKeys = TRUE;
e1e955e1 2256}
c801d85f 2257
cae5359f
RR
2258#ifdef __WXGTK__
2259extern wxWindow *g_focusWindow;
2260#endif
2261
c801d85f
KB
2262void wxListMainWindow::OnSetFocus( wxFocusEvent &WXUNUSED(event) )
2263{
63852e78
RR
2264 m_hasFocus = TRUE;
2265 RefreshLine( m_current );
bd8289c1 2266
63852e78 2267 if (!GetParent()) return;
004fd0c8 2268
cae5359f
RR
2269#ifdef __WXGTK__
2270 g_focusWindow = GetParent();
2271#endif
bd8289c1 2272
63852e78
RR
2273 wxFocusEvent event( wxEVT_SET_FOCUS, GetParent()->GetId() );
2274 event.SetEventObject( GetParent() );
2275 GetParent()->GetEventHandler()->ProcessEvent( event );
e1e955e1 2276}
c801d85f
KB
2277
2278void wxListMainWindow::OnKillFocus( wxFocusEvent &WXUNUSED(event) )
2279{
63852e78
RR
2280 m_hasFocus = FALSE;
2281 RefreshLine( m_current );
e1e955e1 2282}
c801d85f
KB
2283
2284void wxListMainWindow::OnSize( wxSizeEvent &WXUNUSED(event) )
2285{
2286/*
2287 We don't even allow the wxScrolledWindow::AdjustScrollbars() call
004fd0c8 2288
c801d85f 2289*/
2035e10e 2290 m_dirty = TRUE;
e1e955e1 2291}
c801d85f 2292
1e6d9499 2293void wxListMainWindow::DrawImage( int index, wxDC *dc, int x, int y )
c801d85f 2294{
63852e78
RR
2295 if ((m_mode & wxLC_ICON) && (m_normal_image_list))
2296 {
2297 m_normal_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT );
2298 return;
2299 }
2300 if ((m_mode & wxLC_SMALL_ICON) && (m_small_image_list))
2301 {
2302 m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT );
2303 }
0b855868
RR
2304 if ((m_mode & wxLC_LIST) && (m_small_image_list))
2305 {
2306 m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT );
2307 }
63852e78
RR
2308 if ((m_mode & wxLC_REPORT) && (m_small_image_list))
2309 {
2310 m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT );
2311 return;
2312 }
e1e955e1 2313}
c801d85f
KB
2314
2315void wxListMainWindow::GetImageSize( int index, int &width, int &height )
2316{
63852e78
RR
2317 if ((m_mode & wxLC_ICON) && (m_normal_image_list))
2318 {
2319 m_normal_image_list->GetSize( index, width, height );
2320 return;
2321 }
2322 if ((m_mode & wxLC_SMALL_ICON) && (m_small_image_list))
2323 {
2324 m_small_image_list->GetSize( index, width, height );
2325 return;
2326 }
0b855868
RR
2327 if ((m_mode & wxLC_LIST) && (m_small_image_list))
2328 {
2329 m_small_image_list->GetSize( index, width, height );
2330 return;
2331 }
63852e78
RR
2332 if ((m_mode & wxLC_REPORT) && (m_small_image_list))
2333 {
2334 m_small_image_list->GetSize( index, width, height );
2335 return;
2336 }
2337 width = 0;
2338 height = 0;
e1e955e1 2339}
c801d85f
KB
2340
2341int wxListMainWindow::GetTextLength( wxString &s )
2342{
1e6d9499 2343 wxClientDC dc( this );
13111b2a
VZ
2344 wxCoord lw = 0;
2345 wxCoord lh = 0;
139adb6a
RR
2346 dc.GetTextExtent( s, &lw, &lh );
2347 return lw + 6;
e1e955e1 2348}
c801d85f
KB
2349
2350int wxListMainWindow::GetIndexOfLine( const wxListLineData *line )
2351{
f6bcfd97
BP
2352 int i = m_lines.Index(*line);
2353 if (i == wxNOT_FOUND) return -1;
2354 else return i;
e1e955e1 2355}
c801d85f 2356
debe6624 2357void wxListMainWindow::SetImageList( wxImageList *imageList, int which )
c801d85f 2358{
139adb6a 2359 m_dirty = TRUE;
f6bcfd97
BP
2360
2361 // calc the spacing from the icon size
2362 int width = 0,
2363 height = 0;
2364 if ((imageList) && (imageList->GetImageCount()) )
2365 {
2366 imageList->GetSize(0, width, height);
2367 }
2368
2369 if (which == wxIMAGE_LIST_NORMAL)
2370 {
2371 m_normal_image_list = imageList;
2372 m_normal_spacing = width + 8;
2373 }
2374
2375 if (which == wxIMAGE_LIST_SMALL)
2376 {
2377 m_small_image_list = imageList;
2378 m_small_spacing = width + 14;
2379 }
e1e955e1 2380}
c801d85f 2381
debe6624 2382void wxListMainWindow::SetItemSpacing( int spacing, bool isSmall )
c801d85f 2383{
139adb6a
RR
2384 m_dirty = TRUE;
2385 if (isSmall)
2386 {
2387 m_small_spacing = spacing;
2388 }
2389 else
2390 {
2391 m_normal_spacing = spacing;
2392 }
e1e955e1 2393}
c801d85f 2394
debe6624 2395int wxListMainWindow::GetItemSpacing( bool isSmall )
c801d85f 2396{
f6bcfd97 2397 return isSmall ? m_small_spacing : m_normal_spacing;
e1e955e1 2398}
c801d85f 2399
debe6624 2400void wxListMainWindow::SetColumn( int col, wxListItem &item )
c801d85f 2401{
63852e78
RR
2402 m_dirty = TRUE;
2403 wxNode *node = m_columns.Nth( col );
2404 if (node)
2405 {
2406 if (item.m_width == wxLIST_AUTOSIZE_USEHEADER) item.m_width = GetTextLength( item.m_text )+7;
2407 wxListHeaderData *column = (wxListHeaderData*)node->Data();
2408 column->SetItem( item );
2409 }
f6bcfd97
BP
2410
2411 wxListHeaderWindow *headerWin = ((wxListCtrl*) GetParent())->m_headerWin;
2412 if ( headerWin )
2413 headerWin->m_dirty = TRUE;
e1e955e1 2414}
c801d85f 2415
debe6624 2416void wxListMainWindow::SetColumnWidth( int col, int width )
c801d85f 2417{
f6bcfd97
BP
2418 wxCHECK_RET( m_mode & wxLC_REPORT,
2419 _T("SetColumnWidth() can only be called in report mode.") );
0208334d 2420
63852e78 2421 m_dirty = TRUE;
bd8289c1 2422
0180dad6
RR
2423 wxNode *node = (wxNode*) NULL;
2424
f6bcfd97
BP
2425 if (width == wxLIST_AUTOSIZE_USEHEADER)
2426 {
2427 // TODO do use the header
2428 width = 80;
2429 }
2430 else if (width == wxLIST_AUTOSIZE)
0180dad6
RR
2431 {
2432 wxClientDC dc(this);
2433 dc.SetFont( GetFont() );
2434 int max = 10;
3e1c4e00 2435
f6bcfd97 2436 for (size_t i = 0; i < m_lines.GetCount(); i++)
0180dad6 2437 {
f6bcfd97 2438 wxListLineData *line = &m_lines[i];
0180dad6
RR
2439 wxNode *n = line->m_items.Nth( col );
2440 if (n)
2441 {
2442 wxListItemData *item = (wxListItemData*)n->Data();
bffa1c77 2443 int current = 0, ix = 0, iy = 0;
13111b2a 2444 wxCoord lx = 0, ly = 0;
bffa1c77
VZ
2445 if (item->HasImage())
2446 {
0180dad6 2447 GetImageSize( item->GetImage(), ix, iy );
bffa1c77
VZ
2448 current = ix + 5;
2449 }
2450 if (item->HasText())
2451 {
2452 wxString str;
2453 item->GetText( str );
2454 dc.GetTextExtent( str, &lx, &ly );
2455 current += lx;
2456 }
2457 if (current > max) max = current;
0180dad6 2458 }
0180dad6 2459 }
bffa1c77 2460 width = max+10;
0180dad6
RR
2461 }
2462
2463 node = m_columns.Nth( col );
63852e78
RR
2464 if (node)
2465 {
2466 wxListHeaderData *column = (wxListHeaderData*)node->Data();
2467 column->SetWidth( width );
2468 }
bd8289c1 2469
f6bcfd97 2470 for (size_t i = 0; i < m_lines.GetCount(); i++)
0208334d 2471 {
f6bcfd97 2472 wxListLineData *line = &m_lines[i];
63852e78
RR
2473 wxNode *n = line->m_items.Nth( col );
2474 if (n)
2475 {
2476 wxListItemData *item = (wxListItemData*)n->Data();
2477 item->SetSize( width, -1 );
2478 }
0208334d 2479 }
bd8289c1 2480
f6bcfd97
BP
2481 wxListHeaderWindow *headerWin = ((wxListCtrl*) GetParent())->m_headerWin;
2482 if ( headerWin )
2483 headerWin->m_dirty = TRUE;
e1e955e1 2484}
c801d85f 2485
debe6624 2486void wxListMainWindow::GetColumn( int col, wxListItem &item )
c801d85f 2487{
63852e78
RR
2488 wxNode *node = m_columns.Nth( col );
2489 if (node)
2490 {
2491 wxListHeaderData *column = (wxListHeaderData*)node->Data();
2492 column->GetItem( item );
2493 }
2494 else
2495 {
2496 item.m_format = 0;
2497 item.m_width = 0;
2498 item.m_text = "";
2499 item.m_image = 0;
2500 item.m_data = 0;
2501 }
e1e955e1 2502}
c801d85f 2503
bd8289c1 2504int wxListMainWindow::GetColumnWidth( int col )
c801d85f 2505{
92976ab6
RR
2506 wxNode *node = m_columns.Nth( col );
2507 if (node)
2508 {
2509 wxListHeaderData *column = (wxListHeaderData*)node->Data();
2510 return column->GetWidth();
2511 }
2512 else
2513 {
004fd0c8 2514 return 0;
92976ab6 2515 }
e1e955e1 2516}
c801d85f 2517
e179bd65 2518int wxListMainWindow::GetColumnCount()
c801d85f 2519{
92976ab6 2520 return m_columns.Number();
e1e955e1 2521}
c801d85f 2522
e179bd65 2523int wxListMainWindow::GetCountPerPage()
c801d85f 2524{
92976ab6 2525 return m_visibleLines;
e1e955e1 2526}
c801d85f
KB
2527
2528void wxListMainWindow::SetItem( wxListItem &item )
2529{
92976ab6 2530 m_dirty = TRUE;
f6bcfd97 2531 if (item.m_itemId >= 0 && (size_t)item.m_itemId < m_lines.GetCount())
92976ab6 2532 {
f6bcfd97 2533 wxListLineData *line = &m_lines[(size_t)item.m_itemId];
92976ab6
RR
2534 if (m_mode & wxLC_REPORT) item.m_width = GetColumnWidth( item.m_col )-3;
2535 line->SetItem( item.m_col, item );
2536 }
e1e955e1 2537}
c801d85f 2538
debe6624 2539void wxListMainWindow::SetItemState( long item, long state, long stateMask )
c801d85f 2540{
92976ab6 2541 // m_dirty = TRUE; no recalcs needed
bd8289c1 2542
92976ab6 2543 wxListLineData *oldCurrent = m_current;
bd8289c1 2544
92976ab6 2545 if (stateMask & wxLIST_STATE_FOCUSED)
c801d85f 2546 {
f6bcfd97 2547 if (item >= 0 && (size_t)item < m_lines.GetCount())
92976ab6 2548 {
f6bcfd97 2549 wxListLineData *line = &m_lines[(size_t)item];
92976ab6
RR
2550 UnfocusLine( m_current );
2551 m_current = line;
2552 FocusLine( m_current );
4aefa363 2553 if ((m_mode & wxLC_SINGLE_SEL) && oldCurrent) oldCurrent->Hilight( FALSE );
92976ab6 2554 RefreshLine( m_current );
00a39542 2555 if (oldCurrent) RefreshLine( oldCurrent );
92976ab6 2556 }
e1e955e1 2557 }
bd8289c1 2558
92976ab6 2559 if (stateMask & wxLIST_STATE_SELECTED)
c801d85f 2560 {
6f2a55e3 2561 bool on = (state & wxLIST_STATE_SELECTED) != 0;
92976ab6
RR
2562 if (!on && (m_mode & wxLC_SINGLE_SEL)) return;
2563
f6bcfd97 2564 if (item >= 0 && (size_t)item < m_lines.GetCount())
92976ab6 2565 {
f6bcfd97 2566 wxListLineData *line = &m_lines[(size_t)item];
92976ab6
RR
2567 if (m_mode & wxLC_SINGLE_SEL)
2568 {
2569 UnfocusLine( m_current );
2570 m_current = line;
2571 FocusLine( m_current );
00a39542 2572 if (oldCurrent) oldCurrent->Hilight( FALSE );
92976ab6 2573 RefreshLine( m_current );
00a39542 2574 if (oldCurrent) RefreshLine( oldCurrent );
92976ab6 2575 }
6f2a55e3 2576 bool on = (state & wxLIST_STATE_SELECTED) != 0;
bffa1c77
VZ
2577 if (on != line->IsHilighted())
2578 {
139adb6a
RR
2579 line->Hilight( on );
2580 RefreshLine( line );
bffa1c77 2581 }
92976ab6 2582 }
e1e955e1 2583 }
e1e955e1 2584}
c801d85f 2585
debe6624 2586int wxListMainWindow::GetItemState( long item, long stateMask )
c801d85f 2587{
92976ab6
RR
2588 int ret = wxLIST_STATE_DONTCARE;
2589 if (stateMask & wxLIST_STATE_FOCUSED)
c801d85f 2590 {
f6bcfd97 2591 if (item >= 0 && (size_t)item < m_lines.GetCount())
92976ab6 2592 {
f6bcfd97 2593 wxListLineData *line = &m_lines[(size_t)item];
92976ab6
RR
2594 if (line == m_current) ret |= wxLIST_STATE_FOCUSED;
2595 }
e1e955e1 2596 }
92976ab6 2597 if (stateMask & wxLIST_STATE_SELECTED)
c801d85f 2598 {
f6bcfd97 2599 if (item >= 0 && (size_t)item < m_lines.GetCount())
92976ab6 2600 {
f6bcfd97 2601 wxListLineData *line = &m_lines[(size_t)item];
92976ab6
RR
2602 if (line->IsHilighted()) ret |= wxLIST_STATE_FOCUSED;
2603 }
e1e955e1 2604 }
92976ab6 2605 return ret;
e1e955e1 2606}
c801d85f
KB
2607
2608void wxListMainWindow::GetItem( wxListItem &item )
2609{
f6bcfd97 2610 if (item.m_itemId >= 0 && (size_t)item.m_itemId < m_lines.GetCount())
92976ab6 2611 {
f6bcfd97 2612 wxListLineData *line = &m_lines[(size_t)item.m_itemId];
92976ab6
RR
2613 line->GetItem( item.m_col, item );
2614 }
2615 else
2616 {
2617 item.m_mask = 0;
2618 item.m_text = "";
2619 item.m_image = 0;
2620 item.m_data = 0;
2621 }
e1e955e1 2622}
c801d85f 2623
e179bd65 2624int wxListMainWindow::GetItemCount()
c801d85f 2625{
f6bcfd97 2626 return m_lines.GetCount();
e1e955e1 2627}
c801d85f 2628
0a240683 2629void wxListMainWindow::GetItemRect( long index, wxRect &rect )
c801d85f 2630{
f6bcfd97 2631 if (index >= 0 && (size_t)index < m_lines.GetCount())
92976ab6 2632 {
f6bcfd97 2633 m_lines[(size_t)index].GetRect( rect );
92976ab6
RR
2634 }
2635 else
2636 {
2637 rect.x = 0;
2638 rect.y = 0;
2639 rect.width = 0;
2640 rect.height = 0;
2641 }
e1e955e1 2642}
c801d85f 2643
e3e65dac
RR
2644bool wxListMainWindow::GetItemPosition(long item, wxPoint& pos)
2645{
f6bcfd97 2646 if (item >= 0 && (size_t)item < m_lines.GetCount())
92976ab6 2647 {
0a240683 2648 wxRect rect;
f6bcfd97 2649 m_lines[(size_t)item].GetRect( rect );
92976ab6
RR
2650 pos.x = rect.x;
2651 pos.y = rect.y;
2652 }
2653 else
2654 {
2655 pos.x = 0;
2656 pos.y = 0;
2657 }
2658 return TRUE;
e1e955e1 2659}
e3e65dac 2660
e179bd65 2661int wxListMainWindow::GetSelectedItemCount()
c801d85f 2662{
92976ab6 2663 int ret = 0;
f6bcfd97 2664 for (size_t i = 0; i < m_lines.GetCount(); i++)
92976ab6 2665 {
f6bcfd97 2666 if (m_lines[i].IsHilighted()) ret++;
92976ab6
RR
2667 }
2668 return ret;
e1e955e1 2669}
c801d85f 2670
debe6624 2671void wxListMainWindow::SetMode( long mode )
c801d85f 2672{
92976ab6
RR
2673 m_dirty = TRUE;
2674 m_mode = mode;
bd8289c1 2675
92976ab6 2676 DeleteEverything();
bd8289c1 2677
92976ab6
RR
2678 if (m_mode & wxLC_REPORT)
2679 {
7c74e7fe
SC
2680#if wxUSE_GENERIC_LIST_EXTENSIONS
2681 m_xScroll = 15;
2682#else
92976ab6 2683 m_xScroll = 0;
7c74e7fe 2684#endif
92976ab6
RR
2685 m_yScroll = 15;
2686 }
2687 else
2688 {
2689 m_xScroll = 15;
2690 m_yScroll = 0;
2691 }
e1e955e1 2692}
c801d85f 2693
e179bd65 2694long wxListMainWindow::GetMode() const
c801d85f 2695{
63852e78 2696 return m_mode;
e1e955e1 2697}
c801d85f 2698
e179bd65 2699void wxListMainWindow::CalculatePositions()
c801d85f 2700{
f6bcfd97 2701 if (m_lines.IsEmpty()) return;
e487524e 2702
1e6d9499 2703 wxClientDC dc( this );
92976ab6 2704 dc.SetFont( GetFont() );
c801d85f 2705
92976ab6
RR
2706 int iconSpacing = 0;
2707 if (m_mode & wxLC_ICON) iconSpacing = m_normal_spacing;
2708 if (m_mode & wxLC_SMALL_ICON) iconSpacing = m_small_spacing;
004fd0c8 2709
92976ab6
RR
2710 // we take the first line (which also can be an icon or
2711 // an a text item in wxLC_ICON and wxLC_LIST modes) to
2712 // measure the size of the line
004fd0c8 2713
92976ab6
RR
2714 int lineWidth = 0;
2715 int lineHeight = 0;
2716 int lineSpacing = 0;
c801d85f 2717
f6bcfd97 2718 wxListLineData *line = &m_lines[0];
92976ab6
RR
2719 line->CalculateSize( &dc, iconSpacing );
2720 int dummy = 0;
2721 line->GetSize( dummy, lineSpacing );
5d25c050 2722 lineSpacing += 1;
bd8289c1 2723
92976ab6
RR
2724 int clientWidth = 0;
2725 int clientHeight = 0;
bd8289c1 2726
92976ab6 2727 if (m_mode & wxLC_REPORT)
c801d85f 2728 {
92976ab6
RR
2729 int x = 4;
2730 int y = 1;
f6bcfd97 2731 int entireHeight = m_lines.GetCount() * lineSpacing + 2;
92976ab6 2732 int scroll_pos = GetScrollPos( wxVERTICAL );
7c74e7fe 2733#if wxUSE_GENERIC_LIST_EXTENSIONS
7c0ea335 2734 int x_scroll_pos = GetScrollPos( wxHORIZONTAL );
7c74e7fe 2735#else
8b53e5a2 2736 SetScrollbars( m_xScroll, m_yScroll, 0, (entireHeight+15) / m_yScroll, 0, scroll_pos, TRUE );
7c74e7fe 2737#endif
92976ab6
RR
2738 GetClientSize( &clientWidth, &clientHeight );
2739
7c74e7fe 2740 int entireWidth = 0 ;
f6bcfd97 2741 for (size_t j = 0; j < m_lines.GetCount(); j++)
92976ab6 2742 {
f6bcfd97 2743 wxListLineData *line = &m_lines[j];
92976ab6
RR
2744 line->CalculateSize( &dc, iconSpacing );
2745 line->SetPosition( &dc, x, y, clientWidth );
2746 int col_x = 2;
2747 for (int i = 0; i < GetColumnCount(); i++)
2748 {
2749 line->SetColumnPosition( i, col_x );
2750 col_x += GetColumnWidth( i );
2751 }
7c74e7fe
SC
2752 entireWidth = wxMax( entireWidth , col_x ) ;
2753#if wxUSE_GENERIC_LIST_EXTENSIONS
2754 line->SetPosition( &dc, x, y, col_x );
2755#endif
92976ab6 2756 y += lineSpacing; // one pixel blank line between items
92976ab6 2757 }
bffa1c77 2758 m_visibleLines = clientHeight / lineSpacing;
7c74e7fe 2759#if wxUSE_GENERIC_LIST_EXTENSIONS
bffa1c77 2760 SetScrollbars( m_xScroll, m_yScroll, entireWidth / m_xScroll , (entireHeight+15) / m_yScroll, x_scroll_pos , scroll_pos, TRUE );
7c74e7fe 2761#endif
e1e955e1 2762 }
92976ab6
RR
2763 else
2764 {
2765 // at first we try without any scrollbar. if the items don't
2766 // fit into the window, we recalculate after subtracting an
2767 // approximated 15 pt for the horizontal scrollbar
004fd0c8 2768
92976ab6 2769 GetSize( &clientWidth, &clientHeight );
bffa1c77 2770 clientHeight -= 4; // sunken frame
bd8289c1 2771
92976ab6 2772 int entireWidth = 0;
bd8289c1 2773
92976ab6 2774 for (int tries = 0; tries < 2; tries++)
e487524e 2775 {
92976ab6 2776 entireWidth = 0;
5d25c050
RR
2777 int x = 2;
2778 int y = 2;
92976ab6 2779 int maxWidth = 0;
0b855868 2780 m_visibleLines = 0;
bffa1c77 2781 int m_currentVisibleLines = 0;
f6bcfd97 2782 for (size_t i = 0; i < m_lines.GetCount(); i++)
92976ab6 2783 {
bffa1c77 2784 m_currentVisibleLines++;
f6bcfd97 2785 wxListLineData *line = &m_lines[i];
92976ab6
RR
2786 line->CalculateSize( &dc, iconSpacing );
2787 line->SetPosition( &dc, x, y, clientWidth );
2788 line->GetSize( lineWidth, lineHeight );
2789 if (lineWidth > maxWidth) maxWidth = lineWidth;
2790 y += lineSpacing;
bffa1c77
VZ
2791 if (m_currentVisibleLines > m_visibleLines)
2792 m_visibleLines = m_currentVisibleLines;
8b53e5a2 2793 if (y+lineSpacing-6 >= clientHeight) // -6 for earlier "line breaking"
92976ab6 2794 {
bffa1c77 2795 m_currentVisibleLines = 0;
e1208c31 2796 y = 2;
8b53e5a2
RR
2797 x += maxWidth+6;
2798 entireWidth += maxWidth+6;
92976ab6
RR
2799 maxWidth = 0;
2800 }
f6bcfd97 2801 if (i == m_lines.GetCount()-1) entireWidth += maxWidth;
92976ab6
RR
2802 if ((tries == 0) && (entireWidth > clientWidth))
2803 {
2804 clientHeight -= 15; // scrollbar height
0b855868 2805 m_visibleLines = 0;
bffa1c77 2806 m_currentVisibleLines = 0;
92976ab6
RR
2807 break;
2808 }
f6bcfd97 2809 if (i == m_lines.GetCount()-1) tries = 1; // everything fits, no second try required
92976ab6 2810 }
e487524e 2811 }
bffa1c77 2812
92976ab6
RR
2813 int scroll_pos = GetScrollPos( wxHORIZONTAL );
2814 SetScrollbars( m_xScroll, m_yScroll, (entireWidth+15) / m_xScroll, 0, scroll_pos, 0, TRUE );
e1e955e1 2815 }
e1e955e1 2816}
c801d85f 2817
f6bcfd97 2818void wxListMainWindow::RealizeChanges()
c801d85f 2819{
92976ab6
RR
2820 if (!m_current)
2821 {
f6bcfd97
BP
2822 if (!m_lines.IsEmpty())
2823 m_current = &m_lines[0];
92976ab6
RR
2824 }
2825 if (m_current)
2826 {
2827 FocusLine( m_current );
f6bcfd97
BP
2828 // TODO: MSW doesn't automatically hilight the
2829 // first item.
2830 // if (m_mode & wxLC_SINGLE_SEL) m_current->Hilight( TRUE );
92976ab6 2831 }
e1e955e1 2832}
c801d85f 2833
19695fbd
VZ
2834long wxListMainWindow::GetNextItem( long item,
2835 int WXUNUSED(geometry),
2836 int state )
c801d85f 2837{
d1022fd6
VZ
2838 long ret = item,
2839 max = GetItemCount();
2840 wxCHECK_MSG( (ret == -1) || (ret < max), -1,
13771c08 2841 _T("invalid listctrl index in GetNextItem()") );
19695fbd
VZ
2842
2843 // notice that we start with the next item (or the first one if item == -1)
2844 // and this is intentional to allow writing a simple loop to iterate over
2845 // all selected items
d1022fd6
VZ
2846 ret++;
2847 if ( ret == max )
2848 {
2849 // this is not an error because the index was ok initially, just no
2850 // such item
2851 return -1;
2852 }
2853
f6bcfd97 2854 for (size_t i = (size_t)ret; i < m_lines.GetCount(); i++)
63852e78 2855 {
f6bcfd97 2856 wxListLineData *line = &m_lines[i];
19695fbd
VZ
2857 if ((state & wxLIST_STATE_FOCUSED) && (line == m_current))
2858 return ret;
2859 if ((state & wxLIST_STATE_SELECTED) && (line->IsHilighted()))
2860 return ret;
2861 if (!state)
2862 return ret;
63852e78 2863 ret++;
63852e78 2864 }
19695fbd 2865
63852e78 2866 return -1;
e1e955e1 2867}
c801d85f 2868
debe6624 2869void wxListMainWindow::DeleteItem( long index )
c801d85f 2870{
63852e78 2871 m_dirty = TRUE;
f6bcfd97 2872 if (index >= 0 && (size_t)index < m_lines.GetCount())
63852e78 2873 {
f6bcfd97 2874 wxListLineData *line = &m_lines[(size_t)index];
63852e78
RR
2875 if (m_current == line) m_current = (wxListLineData *) NULL;
2876 DeleteLine( line );
f6bcfd97 2877 m_lines.RemoveAt( (size_t)index );
63852e78 2878 }
e1e955e1 2879}
c801d85f 2880
debe6624 2881void wxListMainWindow::DeleteColumn( int col )
c801d85f 2882{
5b077d48 2883 wxCHECK_RET( col < (int)m_columns.GetCount(),
223d09f6 2884 wxT("attempting to delete inexistent column in wxListView") );
bd8289c1 2885
5b077d48
RR
2886 m_dirty = TRUE;
2887 wxNode *node = m_columns.Nth( col );
2888 if (node) m_columns.DeleteNode( node );
e1e955e1 2889}
c801d85f 2890
12c1b46a 2891void wxListMainWindow::DeleteAllItems()
c801d85f 2892{
5b077d48
RR
2893 m_dirty = TRUE;
2894 m_current = (wxListLineData *) NULL;
7c0ea335
VZ
2895
2896 // to make the deletion of all items faster, we don't send the
2897 // notifications in this case: this is compatible with wxMSW and
2898 // documented in DeleteAllItems() description
bffa1c77 2899
12c1b46a
RR
2900 wxListEvent event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS, GetParent()->GetId() );
2901 event.SetEventObject( GetParent() );
2902 GetParent()->GetEventHandler()->ProcessEvent( event );
7c0ea335 2903
5b077d48 2904 m_lines.Clear();
e1e955e1 2905}
c801d85f 2906
12c1b46a 2907void wxListMainWindow::DeleteEverything()
c801d85f 2908{
12c1b46a 2909 DeleteAllItems();
f6bcfd97 2910
5b077d48 2911 m_columns.Clear();
e1e955e1 2912}
c801d85f 2913
debe6624 2914void wxListMainWindow::EnsureVisible( long index )
c801d85f 2915{
dc6c62a9
RR
2916 // We have to call this here because the label in
2917 // question might just have been added and no screen
2918 // update taken place.
2919 if (m_dirty) wxYield();
2920
5b077d48
RR
2921 wxListLineData *oldCurrent = m_current;
2922 m_current = (wxListLineData *) NULL;
f6bcfd97
BP
2923 if (index >= 0 && (size_t)index < m_lines.GetCount())
2924 m_current = &m_lines[(size_t)index];
5b077d48
RR
2925 if (m_current) MoveToFocus();
2926 m_current = oldCurrent;
e1e955e1 2927}
c801d85f 2928
debe6624 2929long wxListMainWindow::FindItem(long start, const wxString& str, bool WXUNUSED(partial) )
c801d85f 2930{
5b077d48
RR
2931 long pos = start;
2932 wxString tmp = str;
2933 if (pos < 0) pos = 0;
3ca6a5f0 2934 for (size_t i = (size_t)pos; i < m_lines.GetCount(); i++)
5b077d48 2935 {
f6bcfd97 2936 wxListLineData *line = &m_lines[i];
5b077d48
RR
2937 wxString s = "";
2938 line->GetText( 0, s );
2939 if (s == tmp) return pos;
5b077d48
RR
2940 pos++;
2941 }
2942 return -1;
e1e955e1 2943}
c801d85f 2944
debe6624 2945long wxListMainWindow::FindItem(long start, long data)
c801d85f 2946{
5b077d48
RR
2947 long pos = start;
2948 if (pos < 0) pos = 0;
3ca6a5f0 2949 for (size_t i = (size_t)pos; i < m_lines.GetCount(); i++)
5b077d48 2950 {
f6bcfd97 2951 wxListLineData *line = &m_lines[i];
5b077d48
RR
2952 wxListItem item;
2953 line->GetItem( 0, item );
2954 if (item.m_data == data) return pos;
5b077d48
RR
2955 pos++;
2956 }
2957 return -1;
e1e955e1 2958}
c801d85f 2959
debe6624 2960long wxListMainWindow::HitTest( int x, int y, int &flags )
c801d85f 2961{
aaef15bf 2962 CalcUnscrolledPosition( x, y, &x, &y );
e8741cca 2963
5b077d48 2964 int count = 0;
f6bcfd97 2965 for (size_t i = 0; i < m_lines.GetCount(); i++)
c801d85f 2966 {
f6bcfd97 2967 wxListLineData *line = &m_lines[i];
aaef15bf 2968 long ret = line->IsHit( x, y );
5b077d48
RR
2969 if (ret & flags)
2970 {
6f2a55e3 2971 flags = (int)ret;
5b077d48
RR
2972 return count;
2973 }
5b077d48 2974 count++;
e1e955e1 2975 }
5b077d48 2976 return -1;
e1e955e1 2977}
c801d85f
KB
2978
2979void wxListMainWindow::InsertItem( wxListItem &item )
2980{
5b077d48
RR
2981 m_dirty = TRUE;
2982 int mode = 0;
2983 if (m_mode & wxLC_REPORT) mode = wxLC_REPORT;
2984 else if (m_mode & wxLC_LIST) mode = wxLC_LIST;
2985 else if (m_mode & wxLC_ICON) mode = wxLC_ICON;
2986 else if (m_mode & wxLC_SMALL_ICON) mode = wxLC_ICON; // no typo
004fd0c8 2987
5b077d48 2988 wxListLineData *line = new wxListLineData( this, mode, m_hilightBrush );
004fd0c8 2989
5b077d48
RR
2990 if (m_mode & wxLC_REPORT)
2991 {
2992 line->InitItems( GetColumnCount() );
2993 item.m_width = GetColumnWidth( 0 )-3;
2994 }
2995 else
2996 {
2997 line->InitItems( 1 );
2998 }
004fd0c8 2999
5b077d48 3000 line->SetItem( 0, item );
f6bcfd97 3001 if ((item.m_itemId >= 0) && ((size_t)item.m_itemId < m_lines.GetCount()))
5b077d48 3002 {
f6bcfd97 3003 m_lines.Insert( line, (size_t)item.m_itemId );
5b077d48
RR
3004 }
3005 else
3006 {
f6bcfd97 3007 m_lines.Add( line );
3e1c4e00 3008 item.m_itemId = m_lines.GetCount();
5b077d48 3009 }
e1e955e1 3010}
c801d85f 3011
debe6624 3012void wxListMainWindow::InsertColumn( long col, wxListItem &item )
c801d85f 3013{
5b077d48
RR
3014 m_dirty = TRUE;
3015 if (m_mode & wxLC_REPORT)
3db7be80 3016 {
5b077d48
RR
3017 if (item.m_width == wxLIST_AUTOSIZE_USEHEADER) item.m_width = GetTextLength( item.m_text );
3018 wxListHeaderData *column = new wxListHeaderData( item );
3019 if ((col >= 0) && (col < (int)m_columns.GetCount()))
3020 {
6f2a55e3 3021 wxNode *node = m_columns.Nth( (size_t)col );
5b077d48
RR
3022 if (node)
3023 m_columns.Insert( node, column );
3024 }
3025 else
3026 {
3027 m_columns.Append( column );
3028 }
3db7be80 3029 }
e1e955e1 3030}
c801d85f
KB
3031
3032wxListCtrlCompare list_ctrl_compare_func_2;
3033long list_ctrl_compare_data;
3034
f6bcfd97 3035int LINKAGEMODE list_ctrl_compare_func_1( wxListLineData **arg1, wxListLineData **arg2 )
c801d85f 3036{
f6bcfd97
BP
3037 wxListLineData *line1 = *arg1;
3038 wxListLineData *line2 = *arg2;
5b077d48
RR
3039 wxListItem item;
3040 line1->GetItem( 0, item );
3041 long data1 = item.m_data;
3042 line2->GetItem( 0, item );
3043 long data2 = item.m_data;
3044 return list_ctrl_compare_func_2( data1, data2, list_ctrl_compare_data );
e1e955e1 3045}
c801d85f
KB
3046
3047void wxListMainWindow::SortItems( wxListCtrlCompare fn, long data )
3048{
5b077d48
RR
3049 list_ctrl_compare_func_2 = fn;
3050 list_ctrl_compare_data = data;
3051 m_lines.Sort( list_ctrl_compare_func_1 );
af7c1052 3052 m_dirty = TRUE;
e1e955e1 3053}
c801d85f 3054
7c74e7fe
SC
3055void wxListMainWindow::OnScroll(wxScrollWinEvent& event)
3056{
bffa1c77 3057 wxScrolledWindow::OnScroll( event ) ;
7c74e7fe
SC
3058#if wxUSE_GENERIC_LIST_EXTENSIONS
3059
3060 if (event.GetOrientation() == wxHORIZONTAL && ( m_mode & wxLC_REPORT ))
3061 {
bffa1c77
VZ
3062 wxListCtrl* lc = wxDynamicCast( GetParent() , wxListCtrl ) ;
3063 if ( lc )
3064 {
3065 lc->m_headerWin->Refresh() ;
7c74e7fe 3066#ifdef __WXMAC__
bffa1c77 3067 lc->m_headerWin->MacUpdateImmediately() ;
7c74e7fe 3068#endif
bffa1c77 3069 }
7c74e7fe
SC
3070 }
3071#endif
3072}
3073
c801d85f
KB
3074// -------------------------------------------------------------------------------------
3075// wxListItem
3076// -------------------------------------------------------------------------------------
3077
3078IMPLEMENT_DYNAMIC_CLASS(wxListItem, wxObject)
3079
fd9811b1 3080wxListItem::wxListItem()
c801d85f 3081{
63852e78
RR
3082 m_mask = 0;
3083 m_itemId = 0;
3084 m_col = 0;
3085 m_state = 0;
3086 m_stateMask = 0;
3087 m_image = 0;
3088 m_data = 0;
3089 m_format = wxLIST_FORMAT_CENTRE;
3090 m_width = 0;
aaa37c0d
VZ
3091
3092 m_attr = NULL;
c801d85f
KB
3093}
3094
9b00bb16
RR
3095void wxListItem::Clear()
3096{
3097 m_mask = 0;
3098 m_itemId = 0;
3099 m_col = 0;
3100 m_state = 0;
3101 m_stateMask = 0;
3102 m_image = 0;
3103 m_data = 0;
3104 m_format = wxLIST_FORMAT_CENTRE;
3105 m_width = 0;
3106 m_text = wxEmptyString;
3107
3108 if (m_attr) delete m_attr;
3109 m_attr = NULL;
3110}
3111
3112void wxListItem::ClearAttributes()
3113{
3114 if (m_attr) delete m_attr;
3115 m_attr = NULL;
3116}
3117
c801d85f
KB
3118// -------------------------------------------------------------------------------------
3119// wxListEvent
3120// -------------------------------------------------------------------------------------
3121
92976ab6 3122IMPLEMENT_DYNAMIC_CLASS(wxListEvent, wxNotifyEvent)
c801d85f 3123
8f79098a 3124wxListEvent::wxListEvent( wxEventType commandType, int id ):
92976ab6 3125 wxNotifyEvent( commandType, id )
c801d85f 3126{
5b077d48
RR
3127 m_code = 0;
3128 m_itemIndex = 0;
3129 m_oldItemIndex = 0;
3130 m_col = 0;
3131 m_cancelled = FALSE;
3132 m_pointDrag.x = 0;
3133 m_pointDrag.y = 0;
e1e955e1 3134}
c801d85f 3135
72a7edf0
RR
3136void wxListEvent::CopyObject(wxObject& object_dest) const
3137{
3138 wxListEvent *obj = (wxListEvent *)&object_dest;
3139
3140 wxNotifyEvent::CopyObject(object_dest);
3141
3142 obj->m_code = m_code;
3143 obj->m_itemIndex = m_itemIndex;
3144 obj->m_oldItemIndex = m_oldItemIndex;
3145 obj->m_col = m_col;
3146 obj->m_cancelled = m_cancelled;
3147 obj->m_pointDrag = m_pointDrag;
3148 obj->m_item.m_mask = m_item.m_mask;
3149 obj->m_item.m_itemId = m_item.m_itemId;
3150 obj->m_item.m_col = m_item.m_col;
3151 obj->m_item.m_state = m_item.m_state;
3152 obj->m_item.m_stateMask = m_item.m_stateMask;
3153 obj->m_item.m_text = m_item.m_text;
3154 obj->m_item.m_image = m_item.m_image;
3155 obj->m_item.m_data = m_item.m_data;
3156 obj->m_item.m_format = m_item.m_format;
3157 obj->m_item.m_width = m_item.m_width;
aaa37c0d
VZ
3158
3159 if ( m_item.HasAttributes() )
3160 {
3161 obj->m_item.SetTextColour(m_item.GetTextColour());
3162 }
72a7edf0
RR
3163}
3164
c801d85f
KB
3165// -------------------------------------------------------------------------------------
3166// wxListCtrl
3167// -------------------------------------------------------------------------------------
3168
3169IMPLEMENT_DYNAMIC_CLASS(wxListCtrl, wxControl)
3170
3171BEGIN_EVENT_TABLE(wxListCtrl,wxControl)
3172 EVT_SIZE (wxListCtrl::OnSize)
53010e52 3173 EVT_IDLE (wxListCtrl::OnIdle)
c801d85f
KB
3174END_EVENT_TABLE()
3175
fd9811b1 3176wxListCtrl::wxListCtrl()
c801d85f 3177{
5b077d48
RR
3178 m_imageListNormal = (wxImageList *) NULL;
3179 m_imageListSmall = (wxImageList *) NULL;
3180 m_imageListState = (wxImageList *) NULL;
3181 m_mainWin = (wxListMainWindow*) NULL;
3182 m_headerWin = (wxListHeaderWindow*) NULL;
c801d85f
KB
3183}
3184
fd9811b1 3185wxListCtrl::~wxListCtrl()
c801d85f
KB
3186{
3187}
3188
25e3a937
VZ
3189bool wxListCtrl::Create(wxWindow *parent,
3190 wxWindowID id,
3191 const wxPoint &pos,
3192 const wxSize &size,
3193 long style,
25e3a937 3194 const wxValidator &validator,
25e3a937 3195 const wxString &name)
c801d85f 3196{
5b077d48
RR
3197 m_imageListNormal = (wxImageList *) NULL;
3198 m_imageListSmall = (wxImageList *) NULL;
3199 m_imageListState = (wxImageList *) NULL;
3200 m_mainWin = (wxListMainWindow*) NULL;
3201 m_headerWin = (wxListHeaderWindow*) NULL;
bd8289c1 3202
25e3a937 3203 if ( !(style & (wxLC_REPORT | wxLC_LIST | wxLC_ICON)) )
5b077d48 3204 {
25e3a937 3205 style = style | wxLC_LIST;
5b077d48 3206 }
f6bcfd97 3207
098963c3 3208 bool ret = wxControl::Create( parent, id, pos, size, style, validator, name );
f6bcfd97
BP
3209
3210
25e3a937
VZ
3211 if (style & wxSUNKEN_BORDER)
3212 style -= wxSUNKEN_BORDER;
bd8289c1 3213
25e3a937 3214 m_mainWin = new wxListMainWindow( this, -1, wxPoint(0,0), size, style );
bd8289c1 3215
f03fc89f 3216 if (HasFlag(wxLC_REPORT))
ea451729 3217 {
5b077d48 3218 m_headerWin = new wxListHeaderWindow( this, -1, m_mainWin, wxPoint(0,0), wxSize(size.x,23), wxTAB_TRAVERSAL );
ea451729
RR
3219 if (HasFlag(wxLC_NO_HEADER))
3220 m_headerWin->Show( FALSE );
3221 }
5b077d48 3222 else
ea451729 3223 {
5b077d48 3224 m_headerWin = (wxListHeaderWindow *) NULL;
ea451729 3225 }
bd8289c1 3226
5b077d48 3227 return ret;
e1e955e1 3228}
c801d85f
KB
3229
3230void wxListCtrl::OnSize( wxSizeEvent &WXUNUSED(event) )
3231{
5b077d48 3232 /* handled in OnIdle */
bd8289c1 3233
5b077d48 3234 if (m_mainWin) m_mainWin->m_dirty = TRUE;
e1e955e1 3235}
c801d85f 3236
debe6624 3237void wxListCtrl::SetSingleStyle( long style, bool add )
c801d85f 3238{
f03fc89f 3239 long flag = GetWindowStyle();
bd8289c1 3240
5b077d48
RR
3241 if (add)
3242 {
3243 if (style & wxLC_MASK_TYPE) flag = flag & ~wxLC_MASK_TYPE;
3244 if (style & wxLC_MASK_ALIGN) flag = flag & ~wxLC_MASK_ALIGN;
3245 if (style & wxLC_MASK_SORT) flag = flag & ~wxLC_MASK_SORT;
3246 }
c801d85f 3247
5b077d48
RR
3248 if (add)
3249 {
3250 flag |= style;
3251 }
3252 else
3253 {
3254 if (flag & style) flag -= style;
3255 }
bd8289c1 3256
5b077d48 3257 SetWindowStyleFlag( flag );
e1e955e1 3258}
c801d85f 3259
debe6624 3260void wxListCtrl::SetWindowStyleFlag( long flag )
c801d85f 3261{
121a3581
RR
3262 if (m_mainWin)
3263 {
3264 m_mainWin->DeleteEverything();
c801d85f 3265
121a3581
RR
3266 int width = 0;
3267 int height = 0;
3268 GetClientSize( &width, &height );
c801d85f 3269
121a3581 3270 m_mainWin->SetMode( flag );
bd8289c1 3271
121a3581 3272 if (flag & wxLC_REPORT)
5b077d48 3273 {
121a3581 3274 if (!HasFlag(wxLC_REPORT))
5b077d48 3275 {
121a3581
RR
3276 if (!m_headerWin)
3277 {
004fd0c8 3278 m_headerWin = new wxListHeaderWindow( this, -1, m_mainWin,
bffa1c77
VZ
3279 wxPoint(0,0), wxSize(width,23), wxTAB_TRAVERSAL );
3280 if (HasFlag(wxLC_NO_HEADER))
3281 m_headerWin->Show( FALSE );
121a3581
RR
3282 }
3283 else
004fd0c8 3284 {
bffa1c77
VZ
3285 if (flag & wxLC_NO_HEADER)
3286 m_headerWin->Show( FALSE );
3287 else
8636aed8 3288 m_headerWin->Show( TRUE );
004fd0c8 3289 }
5b077d48
RR
3290 }
3291 }
121a3581 3292 else
5b077d48 3293 {
8636aed8 3294 if (HasFlag(wxLC_REPORT) && !(HasFlag(wxLC_NO_HEADER)))
121a3581
RR
3295 {
3296 m_headerWin->Show( FALSE );
3297 }
bffa1c77 3298 }
e1e955e1 3299 }
004fd0c8 3300
5b077d48 3301 wxWindow::SetWindowStyleFlag( flag );
e1e955e1 3302}
c801d85f 3303
e487524e 3304bool wxListCtrl::GetColumn(int col, wxListItem &item) const
c801d85f 3305{
5b077d48
RR
3306 m_mainWin->GetColumn( col, item );
3307 return TRUE;
e1e955e1 3308}
c801d85f 3309
debe6624 3310bool wxListCtrl::SetColumn( int col, wxListItem& item )
c801d85f 3311{
5b077d48
RR
3312 m_mainWin->SetColumn( col, item );
3313 return TRUE;
e1e955e1 3314}
c801d85f 3315
e487524e 3316int wxListCtrl::GetColumnWidth( int col ) const
c801d85f 3317{
5b077d48 3318 return m_mainWin->GetColumnWidth( col );
e1e955e1 3319}
c801d85f 3320
debe6624 3321bool wxListCtrl::SetColumnWidth( int col, int width )
c801d85f 3322{
5b077d48
RR
3323 m_mainWin->SetColumnWidth( col, width );
3324 return TRUE;
e1e955e1 3325}
c801d85f 3326
fd9811b1 3327int wxListCtrl::GetCountPerPage() const
c801d85f
KB
3328{
3329 return m_mainWin->GetCountPerPage(); // different from Windows ?
e1e955e1 3330}
c801d85f 3331
e487524e 3332bool wxListCtrl::GetItem( wxListItem &info ) const
c801d85f 3333{
5b077d48
RR
3334 m_mainWin->GetItem( info );
3335 return TRUE;
e1e955e1 3336}
c801d85f
KB
3337
3338bool wxListCtrl::SetItem( wxListItem &info )
3339{
5b077d48
RR
3340 m_mainWin->SetItem( info );
3341 return TRUE;
e1e955e1 3342}
c801d85f 3343
debe6624 3344long wxListCtrl::SetItem( long index, int col, const wxString& label, int imageId )
c801d85f 3345{
5b077d48
RR
3346 wxListItem info;
3347 info.m_text = label;
3348 info.m_mask = wxLIST_MASK_TEXT;
3349 info.m_itemId = index;
3350 info.m_col = col;
3351 if ( imageId > -1 )
3352 {
3353 info.m_image = imageId;
3354 info.m_mask |= wxLIST_MASK_IMAGE;
3355 };
3356 m_mainWin->SetItem(info);
3357 return TRUE;
e1e955e1 3358}
c801d85f 3359
e487524e 3360int wxListCtrl::GetItemState( long item, long stateMask ) const
c801d85f 3361{
5b077d48 3362 return m_mainWin->GetItemState( item, stateMask );
e1e955e1 3363}
c801d85f 3364
debe6624 3365bool wxListCtrl::SetItemState( long item, long state, long stateMask )
c801d85f 3366{
5b077d48
RR
3367 m_mainWin->SetItemState( item, state, stateMask );
3368 return TRUE;
e1e955e1 3369}
c801d85f 3370
debe6624 3371bool wxListCtrl::SetItemImage( long item, int image, int WXUNUSED(selImage) )
c801d85f 3372{
5b077d48
RR
3373 wxListItem info;
3374 info.m_image = image;
3375 info.m_mask = wxLIST_MASK_IMAGE;
3376 info.m_itemId = item;
3377 m_mainWin->SetItem( info );
3378 return TRUE;
e1e955e1 3379}
c801d85f 3380
e487524e 3381wxString wxListCtrl::GetItemText( long item ) const
c801d85f 3382{
5b077d48
RR
3383 wxListItem info;
3384 info.m_itemId = item;
3385 m_mainWin->GetItem( info );
3386 return info.m_text;
e1e955e1 3387}
c801d85f 3388
debe6624 3389void wxListCtrl::SetItemText( long item, const wxString &str )
c801d85f 3390{
5b077d48
RR
3391 wxListItem info;
3392 info.m_mask = wxLIST_MASK_TEXT;
3393 info.m_itemId = item;
3394 info.m_text = str;
3395 m_mainWin->SetItem( info );
e1e955e1 3396}
c801d85f 3397
e487524e 3398long wxListCtrl::GetItemData( long item ) const
c801d85f 3399{
5b077d48
RR
3400 wxListItem info;
3401 info.m_itemId = item;
3402 m_mainWin->GetItem( info );
3403 return info.m_data;
e1e955e1 3404}
c801d85f 3405
debe6624 3406bool wxListCtrl::SetItemData( long item, long data )
c801d85f 3407{
5b077d48
RR
3408 wxListItem info;
3409 info.m_mask = wxLIST_MASK_DATA;
3410 info.m_itemId = item;
3411 info.m_data = data;
3412 m_mainWin->SetItem( info );
3413 return TRUE;
e1e955e1 3414}
c801d85f 3415
0a240683 3416bool wxListCtrl::GetItemRect( long item, wxRect &rect, int WXUNUSED(code) ) const
c801d85f 3417{
5b077d48
RR
3418 m_mainWin->GetItemRect( item, rect );
3419 return TRUE;
e1e955e1 3420}
c801d85f 3421
e487524e 3422bool wxListCtrl::GetItemPosition( long item, wxPoint& pos ) const
c801d85f 3423{
5b077d48
RR
3424 m_mainWin->GetItemPosition( item, pos );
3425 return TRUE;
e1e955e1 3426}
c801d85f 3427
debe6624 3428bool wxListCtrl::SetItemPosition( long WXUNUSED(item), const wxPoint& WXUNUSED(pos) )
c801d85f 3429{
5b077d48 3430 return 0;
e1e955e1 3431}
c801d85f 3432
fd9811b1 3433int wxListCtrl::GetItemCount() const
c801d85f 3434{
5b077d48 3435 return m_mainWin->GetItemCount();
e1e955e1 3436}
c801d85f 3437
fd9811b1 3438int wxListCtrl::GetColumnCount() const
92976ab6 3439{
5b077d48 3440 return m_mainWin->GetColumnCount();
92976ab6
RR
3441}
3442
33d0b396
RR
3443void wxListCtrl::SetItemSpacing( int spacing, bool isSmall )
3444{
5b077d48 3445 m_mainWin->SetItemSpacing( spacing, isSmall );
e1e955e1 3446}
33d0b396 3447
e487524e 3448int wxListCtrl::GetItemSpacing( bool isSmall ) const
c801d85f 3449{
5b077d48 3450 return m_mainWin->GetItemSpacing( isSmall );
e1e955e1 3451}
c801d85f 3452
fd9811b1 3453int wxListCtrl::GetSelectedItemCount() const
c801d85f 3454{
5b077d48 3455 return m_mainWin->GetSelectedItemCount();
e1e955e1 3456}
c801d85f 3457
fd9811b1 3458wxColour wxListCtrl::GetTextColour() const
c801d85f 3459{
0530737d 3460 return GetForegroundColour();
e1e955e1 3461}
c801d85f 3462
0530737d 3463void wxListCtrl::SetTextColour(const wxColour& col)
c801d85f 3464{
0530737d 3465 SetForegroundColour(col);
e1e955e1 3466}
c801d85f 3467
fd9811b1 3468long wxListCtrl::GetTopItem() const
c801d85f 3469{
5b077d48 3470 return 0;
e1e955e1 3471}
c801d85f 3472
6de97a3b 3473long wxListCtrl::GetNextItem( long item, int geom, int state ) const
c801d85f 3474{
5b077d48 3475 return m_mainWin->GetNextItem( item, geom, state );
e1e955e1 3476}
c801d85f 3477
e487524e 3478wxImageList *wxListCtrl::GetImageList(int which) const
c801d85f 3479{
5b077d48
RR
3480 if (which == wxIMAGE_LIST_NORMAL)
3481 {
3482 return m_imageListNormal;
3483 }
3484 else if (which == wxIMAGE_LIST_SMALL)
3485 {
3486 return m_imageListSmall;
3487 }
3488 else if (which == wxIMAGE_LIST_STATE)
3489 {
3490 return m_imageListState;
3491 }
3492 return (wxImageList *) NULL;
e1e955e1 3493}
c801d85f 3494
debe6624 3495void wxListCtrl::SetImageList( wxImageList *imageList, int which )
c801d85f 3496{
5b077d48 3497 m_mainWin->SetImageList( imageList, which );
e1e955e1 3498}
c801d85f 3499
debe6624 3500bool wxListCtrl::Arrange( int WXUNUSED(flag) )
c801d85f 3501{
5b077d48 3502 return 0;
e1e955e1 3503}
c801d85f 3504
debe6624 3505bool wxListCtrl::DeleteItem( long item )
c801d85f 3506{
5b077d48
RR
3507 m_mainWin->DeleteItem( item );
3508 return TRUE;
e1e955e1 3509}
c801d85f 3510
fd9811b1 3511bool wxListCtrl::DeleteAllItems()
c801d85f 3512{
5b077d48
RR
3513 m_mainWin->DeleteAllItems();
3514 return TRUE;
e1e955e1 3515}
c801d85f 3516
4f22cf8d 3517bool wxListCtrl::DeleteAllColumns()
bd8289c1
VZ
3518{
3519 for ( size_t n = 0; n < m_mainWin->m_columns.GetCount(); n++ )
3520 DeleteColumn(n);
bffa1c77 3521
5b077d48 3522 return TRUE;
4f22cf8d
RR
3523}
3524
3525void wxListCtrl::ClearAll()
3526{
5b077d48 3527 m_mainWin->DeleteEverything();
bd8289c1
VZ
3528}
3529
debe6624 3530bool wxListCtrl::DeleteColumn( int col )
c801d85f 3531{
5b077d48
RR
3532 m_mainWin->DeleteColumn( col );
3533 return TRUE;
e1e955e1 3534}
c801d85f 3535
e179bd65 3536void wxListCtrl::Edit( long item )
c801d85f 3537{
e179bd65 3538 m_mainWin->Edit( item );
e1e955e1 3539}
c801d85f 3540
debe6624 3541bool wxListCtrl::EnsureVisible( long item )
c801d85f 3542{
5b077d48
RR
3543 m_mainWin->EnsureVisible( item );
3544 return TRUE;
e1e955e1 3545}
c801d85f 3546
debe6624 3547long wxListCtrl::FindItem( long start, const wxString& str, bool partial )
c801d85f 3548{
5b077d48 3549 return m_mainWin->FindItem( start, str, partial );
e1e955e1 3550}
c801d85f 3551
debe6624 3552long wxListCtrl::FindItem( long start, long data )
c801d85f 3553{
5b077d48 3554 return m_mainWin->FindItem( start, data );
e1e955e1 3555}
c801d85f 3556
bd8289c1 3557long wxListCtrl::FindItem( long WXUNUSED(start), const wxPoint& WXUNUSED(pt),
debe6624 3558 int WXUNUSED(direction))
c801d85f 3559{
5b077d48 3560 return 0;
e1e955e1 3561}
c801d85f
KB
3562
3563long wxListCtrl::HitTest( const wxPoint &point, int &flags )
3564{
5b077d48 3565 return m_mainWin->HitTest( (int)point.x, (int)point.y, flags );
e1e955e1 3566}
c801d85f
KB
3567
3568long wxListCtrl::InsertItem( wxListItem& info )
3569{
5b077d48 3570 m_mainWin->InsertItem( info );
2ebcd5f5 3571 return info.m_itemId;
e1e955e1 3572}
c801d85f 3573
debe6624 3574long wxListCtrl::InsertItem( long index, const wxString &label )
c801d85f 3575{
51cc4dad
RR
3576 wxListItem info;
3577 info.m_text = label;
3578 info.m_mask = wxLIST_MASK_TEXT;
3579 info.m_itemId = index;
3580 return InsertItem( info );
e1e955e1 3581}
c801d85f 3582
debe6624 3583long wxListCtrl::InsertItem( long index, int imageIndex )
c801d85f 3584{
51cc4dad
RR
3585 wxListItem info;
3586 info.m_mask = wxLIST_MASK_IMAGE;
3587 info.m_image = imageIndex;
3588 info.m_itemId = index;
3589 return InsertItem( info );
e1e955e1 3590}
c801d85f 3591
debe6624 3592long wxListCtrl::InsertItem( long index, const wxString &label, int imageIndex )
c801d85f 3593{
51cc4dad
RR
3594 wxListItem info;
3595 info.m_text = label;
3596 info.m_image = imageIndex;
3597 info.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_IMAGE;
3598 info.m_itemId = index;
3599 return InsertItem( info );
e1e955e1 3600}
c801d85f 3601
debe6624 3602long wxListCtrl::InsertColumn( long col, wxListItem &item )
c801d85f 3603{
d3e90957 3604 wxASSERT( m_headerWin );
51cc4dad 3605 m_mainWin->InsertColumn( col, item );
d3e90957 3606 m_headerWin->Refresh();
25e3a937 3607
51cc4dad 3608 return 0;
e1e955e1 3609}
c801d85f 3610
debe6624
JS
3611long wxListCtrl::InsertColumn( long col, const wxString &heading,
3612 int format, int width )
c801d85f 3613{
51cc4dad
RR
3614 wxListItem item;
3615 item.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_FORMAT;
3616 item.m_text = heading;
3617 if (width >= -2)
3618 {
3619 item.m_mask |= wxLIST_MASK_WIDTH;
3620 item.m_width = width;
3621 }
3622 item.m_format = format;
c801d85f 3623
51cc4dad 3624 return InsertColumn( col, item );
e1e955e1 3625}
c801d85f 3626
debe6624 3627bool wxListCtrl::ScrollList( int WXUNUSED(dx), int WXUNUSED(dy) )
c801d85f 3628{
51cc4dad 3629 return 0;
e1e955e1 3630}
c801d85f
KB
3631
3632// Sort items.
3633// fn is a function which takes 3 long arguments: item1, item2, data.
3634// item1 is the long data associated with a first item (NOT the index).
3635// item2 is the long data associated with a second item (NOT the index).
3636// data is the same value as passed to SortItems.
3637// The return value is a negative number if the first item should precede the second
3638// item, a positive number of the second item should precede the first,
3639// or zero if the two items are equivalent.
3640// data is arbitrary data to be passed to the sort function.
3641
3642bool wxListCtrl::SortItems( wxListCtrlCompare fn, long data )
3643{
51cc4dad
RR
3644 m_mainWin->SortItems( fn, data );
3645 return TRUE;
e1e955e1 3646}
c801d85f 3647
e3e65dac 3648void wxListCtrl::OnIdle( wxIdleEvent &WXUNUSED(event) )
53010e52 3649{
51cc4dad 3650 if (!m_mainWin->m_dirty) return;
53010e52 3651
51cc4dad
RR
3652 int cw = 0;
3653 int ch = 0;
3654 GetClientSize( &cw, &ch );
bd8289c1 3655
51cc4dad
RR
3656 int x = 0;
3657 int y = 0;
3658 int w = 0;
3659 int h = 0;
bd8289c1 3660
8636aed8 3661 if (HasFlag(wxLC_REPORT) && !HasFlag(wxLC_NO_HEADER))
51cc4dad
RR
3662 {
3663 m_headerWin->GetPosition( &x, &y );
3664 m_headerWin->GetSize( &w, &h );
3665 if ((x != 0) || (y != 0) || (w != cw) || (h != 23))
3666 m_headerWin->SetSize( 0, 0, cw, 23 );
3667
3668 m_mainWin->GetPosition( &x, &y );
3669 m_mainWin->GetSize( &w, &h );
3670 if ((x != 0) || (y != 24) || (w != cw) || (h != ch-24))
3671 m_mainWin->SetSize( 0, 24, cw, ch-24 );
3672 }
3673 else
3674 {
3675 m_mainWin->GetPosition( &x, &y );
3676 m_mainWin->GetSize( &w, &h );
3677 if ((x != 0) || (y != 24) || (w != cw) || (h != ch))
3678 m_mainWin->SetSize( 0, 0, cw, ch );
3679 }
bd8289c1 3680
51cc4dad
RR
3681 m_mainWin->CalculatePositions();
3682 m_mainWin->RealizeChanges();
3683 m_mainWin->m_dirty = FALSE;
3684 m_mainWin->Refresh();
f6bcfd97
BP
3685
3686 if ( m_headerWin && m_headerWin->m_dirty )
3687 {
3688 m_headerWin->m_dirty = FALSE;
3689 m_headerWin->Refresh();
3690 }
e1e955e1 3691}
53010e52 3692
f03fc89f 3693bool wxListCtrl::SetBackgroundColour( const wxColour &colour )
bd8289c1 3694{
51cc4dad
RR
3695 if (m_mainWin)
3696 {
3697 m_mainWin->SetBackgroundColour( colour );
3698 m_mainWin->m_dirty = TRUE;
3699 }
004fd0c8 3700
f03fc89f 3701 return TRUE;
e4d06860
RR
3702}
3703
f03fc89f 3704bool wxListCtrl::SetForegroundColour( const wxColour &colour )
bd8289c1 3705{
f03fc89f
VZ
3706 if ( !wxWindow::SetForegroundColour( colour ) )
3707 return FALSE;
004fd0c8 3708
51cc4dad
RR
3709 if (m_mainWin)
3710 {
3711 m_mainWin->SetForegroundColour( colour );
3712 m_mainWin->m_dirty = TRUE;
3713 }
004fd0c8 3714
51cc4dad
RR
3715 if (m_headerWin)
3716 {
3717 m_headerWin->SetForegroundColour( colour );
3718 }
f03fc89f
VZ
3719
3720 return TRUE;
e4d06860 3721}
bd8289c1 3722
f03fc89f 3723bool wxListCtrl::SetFont( const wxFont &font )
bd8289c1 3724{
f03fc89f
VZ
3725 if ( !wxWindow::SetFont( font ) )
3726 return FALSE;
004fd0c8 3727
51cc4dad
RR
3728 if (m_mainWin)
3729 {
3730 m_mainWin->SetFont( font );
3731 m_mainWin->m_dirty = TRUE;
3732 }
004fd0c8 3733
51cc4dad
RR
3734 if (m_headerWin)
3735 {
3736 m_headerWin->SetFont( font );
3737 }
f03fc89f
VZ
3738
3739 return TRUE;
e4d06860 3740}
c801d85f 3741
efbb7287
VZ
3742#if wxUSE_DRAG_AND_DROP
3743
3744void wxListCtrl::SetDropTarget( wxDropTarget *dropTarget )
3745{
3746 m_mainWin->SetDropTarget( dropTarget );
3747}
3748
3749wxDropTarget *wxListCtrl::GetDropTarget() const
3750{
3751 return m_mainWin->GetDropTarget();
3752}
3753
3754#endif // wxUSE_DRAG_AND_DROP
3755
3756bool wxListCtrl::SetCursor( const wxCursor &cursor )
3757{
3758 return m_mainWin ? m_mainWin->wxWindow::SetCursor(cursor) : FALSE;
3759}
3760
3761wxColour wxListCtrl::GetBackgroundColour() const
3762{
3763 return m_mainWin ? m_mainWin->GetBackgroundColour() : wxColour();
3764}
3765
3766wxColour wxListCtrl::GetForegroundColour() const
3767{
3768 return m_mainWin ? m_mainWin->GetForegroundColour() : wxColour();
3769}
3770
3771bool wxListCtrl::DoPopupMenu( wxMenu *menu, int x, int y )
3772{
3773 return m_mainWin->PopupMenu( menu, x, y );
3774}
3775
3776void wxListCtrl::SetFocus()
3777{
3778 /* The test in window.cpp fails as we are a composite
3779 window, so it checks against "this", but not m_mainWin. */
3780 if ( FindFocus() != this )
3781 m_mainWin->SetFocus();
3782}