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