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