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