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