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